diff --git a/basic/sorting/BubbleSort/README.md b/basic/sorting/BubbleSort/README.md index 06e09dbaccd4c..667dd32c54e39 100644 --- a/basic/sorting/BubbleSort/README.md +++ b/basic/sorting/BubbleSort/README.md @@ -8,6 +8,8 @@ +#### Python3 + ```python def bubbleSort(arr): n = len(arr) @@ -37,6 +39,8 @@ bubbleSort(arr) print(arr) ``` +#### Java + ```java import java.util.Arrays; @@ -69,6 +73,8 @@ public class BubbleSort { } ``` +#### C++ + ```cpp #include #include @@ -97,6 +103,8 @@ int main() { } ``` +#### Go + ```go package main @@ -122,6 +130,8 @@ func main() { } ``` +#### Rust + ```rust fn bubble_sort(nums: &mut Vec) { let n = nums.len(); @@ -143,6 +153,8 @@ fn main() { } ``` +#### JavaScript + ```js function bubbleSort(inputArr) { for (let i = inputArr.length - 1; i > 0; i--) { @@ -168,6 +180,8 @@ const arr = [6, 3, 2, 1, 5]; console.log(bubbleSort(arr)); ``` +#### C# + ```cs using static System.Console; namespace Pro; diff --git a/basic/sorting/HeapSort/README.md b/basic/sorting/HeapSort/README.md index 5a5922307f51f..62e522c5fa57e 100644 --- a/basic/sorting/HeapSort/README.md +++ b/basic/sorting/HeapSort/README.md @@ -73,6 +73,8 @@ for (int i = n / 2; i > 0; --i) { ### **Python3** +#### Python3 + ```python n, m = list(map(int, input().split(" "))) h = [0] + list(map(int, input().split(" "))) @@ -112,6 +114,8 @@ print(' '.join(list(map(str, res)))) ### **Java** +#### Java + ```java import java.util.Scanner; @@ -167,6 +171,8 @@ public class Main { ### **Rust** +#### Rust + ```rust use std::io; @@ -232,6 +238,8 @@ fn main() -> io::Result<()> { ### **Go** +#### Go + ```go package main @@ -294,6 +302,8 @@ func main() { +#### Python3 + ```python n, m = list(map(int, input().split(" "))) h = [0] + list(map(int, input().split(" "))) @@ -331,6 +341,8 @@ for i in range(m): print(' '.join(list(map(str, res)))) ``` +#### Java + ```java import java.util.Scanner; @@ -384,6 +396,8 @@ public class Main { } ``` +#### Go + ```go package main @@ -438,6 +452,8 @@ func main() { } ``` +#### Rust + ```rust use std::io; diff --git a/basic/sorting/InsertionSort/README.md b/basic/sorting/InsertionSort/README.md index 43f0583e731d2..3f969bf210c4b 100644 --- a/basic/sorting/InsertionSort/README.md +++ b/basic/sorting/InsertionSort/README.md @@ -17,6 +17,8 @@ +#### Python3 + ```python def insertion_sort(array): for i in range(len(array)): @@ -34,6 +36,8 @@ array = [10, 17, 50, 7, 30, 24, 27, 45, 15, 5, 36, 21] print(insertion_sort(array)) ``` +#### Java + ```java import java.util.Arrays; @@ -57,6 +61,8 @@ public class InsertionSort { } ``` +#### C++ + ```cpp #include #include @@ -96,6 +102,8 @@ int main() { } ``` +#### Go + ```go package main @@ -118,6 +126,8 @@ func main() { } ``` +#### Rust + ```rust fn insertion_sort(nums: &mut Vec) { let n = nums.len(); @@ -139,6 +149,8 @@ fn main() { } ``` +#### JavaScript + ```js function insertionSort(inputArr) { let len = inputArr.length; @@ -158,6 +170,8 @@ let arr = [6, 3, 2, 1, 5]; console.log(insertionSort(arr)); ``` +#### C# + ```cs using System.Diagnostics; using static System.Console; diff --git a/basic/sorting/MergeSort/README.md b/basic/sorting/MergeSort/README.md index 6d374e821028b..34934e70e4948 100644 --- a/basic/sorting/MergeSort/README.md +++ b/basic/sorting/MergeSort/README.md @@ -73,6 +73,8 @@ void mergeSort(int[] nums, int left, int right) { +#### Python3 + ```python N = int(input()) nums = list(map(int, input().split())) @@ -110,6 +112,8 @@ merge_sort(nums, 0, N - 1) print(' '.join(list(map(str, nums)))) ``` +#### Java + ```java import java.util.Scanner; @@ -157,6 +161,8 @@ public class Main { } ``` +#### C++ + ```cpp #include @@ -194,6 +200,8 @@ int main() { } ``` +#### Go + ```go package main @@ -246,6 +254,8 @@ func main() { } ``` +#### Rust + ```rust use std::io; @@ -306,6 +316,8 @@ fn main() -> io::Result<()> { } ``` +#### JavaScript + ```js var buf = ''; diff --git a/basic/sorting/QuickSort/README.md b/basic/sorting/QuickSort/README.md index 0f1be738fb103..e17d4acb80f5a 100644 --- a/basic/sorting/QuickSort/README.md +++ b/basic/sorting/QuickSort/README.md @@ -66,6 +66,8 @@ void quickSort(int[] nums, int left, int right) { +#### Python3 + ```python N = int(input()) nums = list(map(int, input().split())) @@ -95,6 +97,8 @@ quick_sort(nums, 0, N - 1) print(' '.join(list(map(str, nums)))) ``` +#### Java + ```java import java.util.Scanner; @@ -135,6 +139,8 @@ public class Main { } ``` +#### C++ + ```cpp #include @@ -169,6 +175,8 @@ int main() { } ``` +#### Go + ```go package main @@ -217,6 +225,8 @@ func main() { } ``` +#### Rust + ```rust use rand::Rng; // 0.7.2 use std::io; @@ -271,6 +281,8 @@ fn main() -> io::Result<()> { } ``` +#### JavaScript + ```js var buf = ''; diff --git a/basic/sorting/SelectionSort/README.md b/basic/sorting/SelectionSort/README.md index 3093e08c33f78..6a5de354b9dfb 100644 --- a/basic/sorting/SelectionSort/README.md +++ b/basic/sorting/SelectionSort/README.md @@ -6,6 +6,8 @@ +#### Python3 + ```python def selection_sort(arr): n = len(arr) @@ -22,6 +24,8 @@ selection_sort(arr) print(arr) ``` +#### Java + ```java import java.util.Arrays; @@ -53,6 +57,8 @@ public class SelectionSort { } ``` +#### C++ + ```cpp #include #include @@ -91,6 +97,8 @@ int main(void) { } ``` +#### Go + ```go package main @@ -115,6 +123,8 @@ func main() { } ``` +#### Rust + ```rust fn selection_sort(nums: &mut Vec) { let n = nums.len(); @@ -138,6 +148,8 @@ fn main() { } ``` +#### JavaScript + ```js function selectionSort(inputArr) { let len = inputArr.length; @@ -159,6 +171,8 @@ let arr = [6, 3, 2, 1, 5]; console.log(selectionSort(arr)); ``` +#### C# + ```cs using static System.Console; namespace Pro; diff --git a/basic/sorting/ShellSort/README.md b/basic/sorting/ShellSort/README.md index 70e890b1d01aa..13f129323f351 100644 --- a/basic/sorting/ShellSort/README.md +++ b/basic/sorting/ShellSort/README.md @@ -11,6 +11,8 @@ +#### Java + ```java import java.util.Arrays; @@ -39,6 +41,8 @@ public class ShellSort { } ``` +#### Go + ```go package main @@ -64,6 +68,8 @@ func main() { } ``` +#### Rust + ```rust fn shell_sort(nums: &mut Vec) { let n = nums.len(); @@ -89,6 +95,8 @@ fn main() { } ``` +#### JavaScript + ```js function shellSort(arr) { var len = arr.length; diff --git a/lcci/01.01.Is Unique/README.md b/lcci/01.01.Is Unique/README.md index e7ea4011b05db..e8f0aafbf7165 100644 --- a/lcci/01.01.Is Unique/README.md +++ b/lcci/01.01.Is Unique/README.md @@ -50,6 +50,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/01.01.Is%20Unique/REA +#### Python3 + ```python class Solution: def isUnique(self, astr: str) -> bool: @@ -62,6 +64,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isUnique(String astr) { @@ -78,6 +82,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -95,6 +101,8 @@ public: }; ``` +#### Go + ```go func isUnique(astr string) bool { mask := 0 @@ -109,6 +117,8 @@ func isUnique(astr string) bool { } ``` +#### TypeScript + ```ts function isUnique(astr: string): boolean { let mask = 0; @@ -123,6 +133,8 @@ function isUnique(astr: string): boolean { } ``` +#### JavaScript + ```js /** * @param {string} astr @@ -141,6 +153,8 @@ var isUnique = function (astr) { }; ``` +#### Swift + ```swift class Solution { func isUnique(_ astr: String) -> Bool { diff --git a/lcci/01.01.Is Unique/README_EN.md b/lcci/01.01.Is Unique/README_EN.md index fa57e84ad5c99..86501a1e6e8e5 100644 --- a/lcci/01.01.Is Unique/README_EN.md +++ b/lcci/01.01.Is Unique/README_EN.md @@ -58,6 +58,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string. The space +#### Python3 + ```python class Solution: def isUnique(self, astr: str) -> bool: @@ -70,6 +72,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isUnique(String astr) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -103,6 +109,8 @@ public: }; ``` +#### Go + ```go func isUnique(astr string) bool { mask := 0 @@ -117,6 +125,8 @@ func isUnique(astr string) bool { } ``` +#### TypeScript + ```ts function isUnique(astr: string): boolean { let mask = 0; @@ -131,6 +141,8 @@ function isUnique(astr: string): boolean { } ``` +#### JavaScript + ```js /** * @param {string} astr @@ -149,6 +161,8 @@ var isUnique = function (astr) { }; ``` +#### Swift + ```swift class Solution { func isUnique(_ astr: String) -> Bool { diff --git a/lcci/01.02.Check Permutation/README.md b/lcci/01.02.Check Permutation/README.md index 551906fa771d7..db958faa9953e 100644 --- a/lcci/01.02.Check Permutation/README.md +++ b/lcci/01.02.Check Permutation/README.md @@ -57,12 +57,16 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/01.02.Check%20Permuta +#### Python3 + ```python class Solution: def CheckPermutation(self, s1: str, s2: str) -> bool: return Counter(s1) == Counter(s2) ``` +#### Java + ```java class Solution { public boolean CheckPermutation(String s1, String s2) { @@ -83,6 +87,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -97,6 +103,8 @@ public: }; ``` +#### Go + ```go func CheckPermutation(s1 string, s2 string) bool { if len(s1) != len(s2) { @@ -116,6 +124,8 @@ func CheckPermutation(s1 string, s2 string) bool { } ``` +#### TypeScript + ```ts function CheckPermutation(s1: string, s2: string): boolean { const n = s1.length; @@ -137,6 +147,8 @@ function CheckPermutation(s1: string, s2: string): boolean { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { @@ -158,6 +170,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s1 @@ -183,6 +197,8 @@ var CheckPermutation = function (s1, s2) { }; ``` +#### Swift + ```swift class Solution { func CheckPermutation(_ s1: String, _ s2: String) -> Bool { @@ -224,12 +240,16 @@ class Solution { +#### Python3 + ```python class Solution: def CheckPermutation(self, s1: str, s2: str) -> bool: return sorted(s1) == sorted(s2) ``` +#### Java + ```java class Solution { public boolean CheckPermutation(String s1, String s2) { @@ -242,6 +262,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -253,6 +275,8 @@ public: }; ``` +#### Go + ```go func CheckPermutation(s1 string, s2 string) bool { cs1, cs2 := []byte(s1), []byte(s2) @@ -262,12 +286,16 @@ func CheckPermutation(s1 string, s2 string) bool { } ``` +#### TypeScript + ```ts function CheckPermutation(s1: string, s2: string): boolean { return [...s1].sort().join('') === [...s2].sort().join(''); } ``` +#### Rust + ```rust impl Solution { pub fn check_permutation(s1: String, s2: String) -> bool { diff --git a/lcci/01.02.Check Permutation/README_EN.md b/lcci/01.02.Check Permutation/README_EN.md index ba48ed6e0530f..c18cd58477e8d 100644 --- a/lcci/01.02.Check Permutation/README_EN.md +++ b/lcci/01.02.Check Permutation/README_EN.md @@ -64,12 +64,16 @@ The time complexity is $O(n)$, and the space complexity is $O(C)$. Here, $n$ is +#### Python3 + ```python class Solution: def CheckPermutation(self, s1: str, s2: str) -> bool: return Counter(s1) == Counter(s2) ``` +#### Java + ```java class Solution { public boolean CheckPermutation(String s1, String s2) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -104,6 +110,8 @@ public: }; ``` +#### Go + ```go func CheckPermutation(s1 string, s2 string) bool { if len(s1) != len(s2) { @@ -123,6 +131,8 @@ func CheckPermutation(s1 string, s2 string) bool { } ``` +#### TypeScript + ```ts function CheckPermutation(s1: string, s2: string): boolean { const n = s1.length; @@ -144,6 +154,8 @@ function CheckPermutation(s1: string, s2: string): boolean { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { @@ -165,6 +177,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s1 @@ -190,6 +204,8 @@ var CheckPermutation = function (s1, s2) { }; ``` +#### Swift + ```swift class Solution { func CheckPermutation(_ s1: String, _ s2: String) -> Bool { @@ -231,12 +247,16 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def CheckPermutation(self, s1: str, s2: str) -> bool: return sorted(s1) == sorted(s2) ``` +#### Java + ```java class Solution { public boolean CheckPermutation(String s1, String s2) { @@ -249,6 +269,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -260,6 +282,8 @@ public: }; ``` +#### Go + ```go func CheckPermutation(s1 string, s2 string) bool { cs1, cs2 := []byte(s1), []byte(s2) @@ -269,12 +293,16 @@ func CheckPermutation(s1 string, s2 string) bool { } ``` +#### TypeScript + ```ts function CheckPermutation(s1: string, s2: string): boolean { return [...s1].sort().join('') === [...s2].sort().join(''); } ``` +#### Rust + ```rust impl Solution { pub fn check_permutation(s1: String, s2: String) -> bool { diff --git a/lcci/01.03.String to URL/README.md b/lcci/01.03.String to URL/README.md index 77eecac6625b3..fd68643cbc456 100644 --- a/lcci/01.03.String to URL/README.md +++ b/lcci/01.03.String to URL/README.md @@ -48,18 +48,24 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/01.03.String%20to%20U +#### Python3 + ```python class Solution: def replaceSpaces(self, S: str, length: int) -> str: return S[:length].replace(' ', '%20') ``` +#### TypeScript + ```ts function replaceSpaces(S: string, length: number): string { return S.slice(0, length).replace(/\s/g, '%20'); } ``` +#### Rust + ```rust impl Solution { pub fn replace_spaces(s: String, length: i32) -> String { @@ -68,6 +74,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} S @@ -79,6 +87,8 @@ var replaceSpaces = function (S, length) { }; ``` +#### Swift + ```swift class Solution { func replaceSpaces(_ S: String, _ length: Int) -> String { @@ -112,12 +122,16 @@ class Solution { +#### Python3 + ```python class Solution: def replaceSpaces(self, S: str, length: int) -> str: return ''.join(['%20' if c == ' ' else c for c in S[:length]]) ``` +#### Java + ```java class Solution { public String replaceSpaces(String S, int length) { @@ -137,6 +151,8 @@ class Solution { } ``` +#### Go + ```go func replaceSpaces(S string, length int) string { // return url.PathEscape(S[:length]) @@ -157,6 +173,8 @@ func replaceSpaces(S string, length int) string { } ``` +#### Rust + ```rust impl Solution { pub fn replace_spaces(s: String, length: i32) -> String { diff --git a/lcci/01.03.String to URL/README_EN.md b/lcci/01.03.String to URL/README_EN.md index 8ee4782aaaa0a..12c5ecc5fb171 100644 --- a/lcci/01.03.String to URL/README_EN.md +++ b/lcci/01.03.String to URL/README_EN.md @@ -62,18 +62,24 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def replaceSpaces(self, S: str, length: int) -> str: return S[:length].replace(' ', '%20') ``` +#### TypeScript + ```ts function replaceSpaces(S: string, length: number): string { return S.slice(0, length).replace(/\s/g, '%20'); } ``` +#### Rust + ```rust impl Solution { pub fn replace_spaces(s: String, length: i32) -> String { @@ -82,6 +88,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} S @@ -93,6 +101,8 @@ var replaceSpaces = function (S, length) { }; ``` +#### Swift + ```swift class Solution { func replaceSpaces(_ S: String, _ length: Int) -> String { @@ -126,12 +136,16 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def replaceSpaces(self, S: str, length: int) -> str: return ''.join(['%20' if c == ' ' else c for c in S[:length]]) ``` +#### Java + ```java class Solution { public String replaceSpaces(String S, int length) { @@ -151,6 +165,8 @@ class Solution { } ``` +#### Go + ```go func replaceSpaces(S string, length int) string { // return url.PathEscape(S[:length]) @@ -171,6 +187,8 @@ func replaceSpaces(S string, length int) string { } ``` +#### Rust + ```rust impl Solution { pub fn replace_spaces(s: String, length: i32) -> String { diff --git a/lcci/01.04.Palindrome Permutation/README.md b/lcci/01.04.Palindrome Permutation/README.md index 6a9e36986bb89..689ccb5841266 100644 --- a/lcci/01.04.Palindrome Permutation/README.md +++ b/lcci/01.04.Palindrome Permutation/README.md @@ -44,6 +44,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/01.04.Palindrome%20Pe +#### Python3 + ```python class Solution: def canPermutePalindrome(self, s: str) -> bool: @@ -51,6 +53,8 @@ class Solution: return sum(v & 1 for v in cnt.values()) < 2 ``` +#### Java + ```java class Solution { public boolean canPermutePalindrome(String s) { @@ -67,6 +71,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -84,6 +90,8 @@ public: }; ``` +#### Go + ```go func canPermutePalindrome(s string) bool { vis := map[rune]bool{} @@ -101,6 +109,8 @@ func canPermutePalindrome(s string) bool { } ``` +#### TypeScript + ```ts function canPermutePalindrome(s: string): boolean { const set = new Set(); @@ -115,6 +125,8 @@ function canPermutePalindrome(s: string): boolean { } ``` +#### Rust + ```rust use std::collections::HashSet; @@ -133,6 +145,8 @@ impl Solution { } ``` +#### Swift + ```swift class Solution { func canPermutePalindrome(_ s: String) -> Bool { @@ -167,6 +181,8 @@ class Solution { +#### Python3 + ```python class Solution: def canPermutePalindrome(self, s: str) -> bool: @@ -179,6 +195,8 @@ class Solution: return len(vis) < 2 ``` +#### Java + ```java class Solution { public boolean canPermutePalindrome(String s) { @@ -194,6 +212,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/lcci/01.04.Palindrome Permutation/README_EN.md b/lcci/01.04.Palindrome Permutation/README_EN.md index 971b46c4729d5..e942aadc8b522 100644 --- a/lcci/01.04.Palindrome Permutation/README_EN.md +++ b/lcci/01.04.Palindrome Permutation/README_EN.md @@ -42,6 +42,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def canPermutePalindrome(self, s: str) -> bool: @@ -49,6 +51,8 @@ class Solution: return sum(v & 1 for v in cnt.values()) < 2 ``` +#### Java + ```java class Solution { public boolean canPermutePalindrome(String s) { @@ -65,6 +69,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -82,6 +88,8 @@ public: }; ``` +#### Go + ```go func canPermutePalindrome(s string) bool { vis := map[rune]bool{} @@ -99,6 +107,8 @@ func canPermutePalindrome(s string) bool { } ``` +#### TypeScript + ```ts function canPermutePalindrome(s: string): boolean { const set = new Set(); @@ -113,6 +123,8 @@ function canPermutePalindrome(s: string): boolean { } ``` +#### Rust + ```rust use std::collections::HashSet; @@ -131,6 +143,8 @@ impl Solution { } ``` +#### Swift + ```swift class Solution { func canPermutePalindrome(_ s: String) -> Bool { @@ -165,6 +179,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def canPermutePalindrome(self, s: str) -> bool: @@ -177,6 +193,8 @@ class Solution: return len(vis) < 2 ``` +#### Java + ```java class Solution { public boolean canPermutePalindrome(String s) { @@ -192,6 +210,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/lcci/01.05.One Away/README.md b/lcci/01.05.One Away/README.md index c3ad2375beca4..471c6c5f9190c 100644 --- a/lcci/01.05.One Away/README.md +++ b/lcci/01.05.One Away/README.md @@ -55,6 +55,8 @@ second = "pal" +#### Python3 + ```python class Solution: def oneEditAway(self, first: str, second: str) -> bool: @@ -75,6 +77,8 @@ class Solution: return cnt < 2 ``` +#### Java + ```java class Solution { public boolean oneEditAway(String first, String second) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func oneEditAway(first string, second string) bool { m, n := len(first), len(second) @@ -173,6 +181,8 @@ func oneEditAway(first string, second string) bool { } ``` +#### TypeScript + ```ts function oneEditAway(first: string, second: string): boolean { let m: number = first.length; @@ -207,6 +217,8 @@ function oneEditAway(first: string, second: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn one_edit_away(first: String, second: String) -> bool { @@ -236,6 +248,8 @@ impl Solution { } ``` +#### Swift + ```swift class Solution { func oneEditAway(_ first: String, _ second: String) -> Bool { diff --git a/lcci/01.05.One Away/README_EN.md b/lcci/01.05.One Away/README_EN.md index c2146280b0bf1..a0703be7fa38b 100644 --- a/lcci/01.05.One Away/README_EN.md +++ b/lcci/01.05.One Away/README_EN.md @@ -64,6 +64,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string. The space +#### Python3 + ```python class Solution: def oneEditAway(self, first: str, second: str) -> bool: @@ -84,6 +86,8 @@ class Solution: return cnt < 2 ``` +#### Java + ```java class Solution { public boolean oneEditAway(String first, String second) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func oneEditAway(first string, second string) bool { m, n := len(first), len(second) @@ -182,6 +190,8 @@ func oneEditAway(first string, second string) bool { } ``` +#### TypeScript + ```ts function oneEditAway(first: string, second: string): boolean { let m: number = first.length; @@ -216,6 +226,8 @@ function oneEditAway(first: string, second: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn one_edit_away(first: String, second: String) -> bool { @@ -245,6 +257,8 @@ impl Solution { } ``` +#### Swift + ```swift class Solution { func oneEditAway(_ first: String, _ second: String) -> Bool { diff --git a/lcci/01.06.Compress String/README.md b/lcci/01.06.Compress String/README.md index 1dd276978100a..829eb7d532a86 100644 --- a/lcci/01.06.Compress String/README.md +++ b/lcci/01.06.Compress String/README.md @@ -53,6 +53,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/01.06.Compress%20Stri +#### Python3 + ```python class Solution: def compressString(self, S: str) -> str: @@ -60,6 +62,8 @@ class Solution: return min(S, t, key=len) ``` +#### Python3 + ```python class Solution: def compressString(self, S: str) -> str: @@ -74,6 +78,8 @@ class Solution: return min(S, "".join(t), key=len) ``` +#### Java + ```java class Solution { public String compressString(String S) { @@ -93,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +121,8 @@ public: }; ``` +#### Go + ```go func compressString(S string) string { n := len(S) @@ -133,6 +143,8 @@ func compressString(S string) string { } ``` +#### Rust + ```rust impl Solution { pub fn compress_string(s: String) -> String { @@ -160,6 +172,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} S @@ -180,6 +194,8 @@ var compressString = function (S) { }; ``` +#### Swift + ```swift class Solution { func compressString(_ S: String) -> String { diff --git a/lcci/01.06.Compress String/README_EN.md b/lcci/01.06.Compress String/README_EN.md index 47eb8ec2f5b1c..10346e225a81c 100644 --- a/lcci/01.06.Compress String/README_EN.md +++ b/lcci/01.06.Compress String/README_EN.md @@ -60,6 +60,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def compressString(self, S: str) -> str: @@ -67,6 +69,8 @@ class Solution: return min(S, t, key=len) ``` +#### Python3 + ```python class Solution: def compressString(self, S: str) -> str: @@ -81,6 +85,8 @@ class Solution: return min(S, "".join(t), key=len) ``` +#### Java + ```java class Solution { public String compressString(String S) { @@ -100,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +128,8 @@ public: }; ``` +#### Go + ```go func compressString(S string) string { n := len(S) @@ -140,6 +150,8 @@ func compressString(S string) string { } ``` +#### Rust + ```rust impl Solution { pub fn compress_string(s: String) -> String { @@ -167,6 +179,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} S @@ -187,6 +201,8 @@ var compressString = function (S) { }; ``` +#### Swift + ```swift class Solution { func compressString(_ S: String) -> String { diff --git a/lcci/01.07.Rotate Matrix/README.md b/lcci/01.07.Rotate Matrix/README.md index 25bf0ada99dd9..2d6b196c90198 100644 --- a/lcci/01.07.Rotate Matrix/README.md +++ b/lcci/01.07.Rotate Matrix/README.md @@ -72,6 +72,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/01.07.Rotate%20Matrix +#### Python3 + ```python class Solution: def rotate(self, matrix: List[List[int]]) -> None: @@ -84,6 +86,8 @@ class Solution: matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] ``` +#### Java + ```java class Solution { public void rotate(int[][] matrix) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func rotate(matrix [][]int) { n := len(matrix) @@ -141,6 +149,8 @@ func rotate(matrix [][]int) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify matrix in-place instead. @@ -157,6 +167,8 @@ function rotate(matrix: number[][]): void { } ``` +#### Rust + ```rust impl Solution { pub fn rotate(matrix: &mut Vec>) { @@ -179,6 +191,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix @@ -194,6 +208,8 @@ var rotate = function (matrix) { }; ``` +#### C# + ```cs public class Solution { public void Rotate(int[][] matrix) { @@ -216,6 +232,8 @@ public class Solution { } ``` +#### Swift + ```swift class Solution { func rotate(_ matrix: inout [[Int]]) { diff --git a/lcci/01.07.Rotate Matrix/README_EN.md b/lcci/01.07.Rotate Matrix/README_EN.md index b391c78045e0a..f093f2a013175 100644 --- a/lcci/01.07.Rotate Matrix/README_EN.md +++ b/lcci/01.07.Rotate Matrix/README_EN.md @@ -102,6 +102,8 @@ The time complexity is $O(n^2)$, where $n$ is the side length of the matrix. The +#### Python3 + ```python class Solution: def rotate(self, matrix: List[List[int]]) -> None: @@ -114,6 +116,8 @@ class Solution: matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] ``` +#### Java + ```java class Solution { public void rotate(int[][] matrix) { @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func rotate(matrix [][]int) { n := len(matrix) @@ -171,6 +179,8 @@ func rotate(matrix [][]int) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify matrix in-place instead. @@ -187,6 +197,8 @@ function rotate(matrix: number[][]): void { } ``` +#### Rust + ```rust impl Solution { pub fn rotate(matrix: &mut Vec>) { @@ -209,6 +221,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix @@ -224,6 +238,8 @@ var rotate = function (matrix) { }; ``` +#### C# + ```cs public class Solution { public void Rotate(int[][] matrix) { @@ -246,6 +262,8 @@ public class Solution { } ``` +#### Swift + ```swift class Solution { func rotate(_ matrix: inout [[Int]]) { diff --git a/lcci/01.08.Zero Matrix/README.md b/lcci/01.08.Zero Matrix/README.md index 3456a29e3a99e..aa718b9f73fc8 100644 --- a/lcci/01.08.Zero Matrix/README.md +++ b/lcci/01.08.Zero Matrix/README.md @@ -66,6 +66,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/01.08.Zero%20Matrix/R +#### Python3 + ```python class Solution: def setZeroes(self, matrix: List[List[int]]) -> None: @@ -82,6 +84,8 @@ class Solution: matrix[i][j] = 0 ``` +#### Java + ```java class Solution { public void setZeroes(int[][] matrix) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func setZeroes(matrix [][]int) { m, n := len(matrix), len(matrix[0]) @@ -156,6 +164,8 @@ func setZeroes(matrix [][]int) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify matrix in-place instead. @@ -183,6 +193,8 @@ function setZeroes(matrix: number[][]): void { } ``` +#### Rust + ```rust impl Solution { pub fn set_zeroes(matrix: &mut Vec>) { @@ -209,6 +221,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix @@ -237,6 +251,8 @@ var setZeroes = function (matrix) { }; ``` +#### C + ```c void setZeroes(int** matrix, int matrixSize, int* matrixColSize) { int m = matrixSize; @@ -265,6 +281,8 @@ void setZeroes(int** matrix, int matrixSize, int* matrixColSize) { } ``` +#### Swift + ```swift class Solution { func setZeroes(_ matrix: inout [[Int]]) { @@ -310,6 +328,8 @@ class Solution { +#### Python3 + ```python class Solution: def setZeroes(self, matrix: List[List[int]]) -> None: @@ -332,6 +352,8 @@ class Solution: matrix[i][0] = 0 ``` +#### Java + ```java class Solution { public void setZeroes(int[][] matrix) { @@ -378,6 +400,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -425,6 +449,8 @@ public: }; ``` +#### Go + ```go func setZeroes(matrix [][]int) { m, n := len(matrix), len(matrix[0]) @@ -468,6 +494,8 @@ func setZeroes(matrix [][]int) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify matrix in-place instead. @@ -517,6 +545,8 @@ function setZeroes(matrix: number[][]): void { } ``` +#### Rust + ```rust impl Solution { pub fn set_zeroes(matrix: &mut Vec>) { @@ -571,6 +601,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix @@ -615,6 +647,8 @@ var setZeroes = function (matrix) { }; ``` +#### C + ```c void setZeroes(int** matrix, int matrixSize, int* matrixColSize) { int m = matrixSize; diff --git a/lcci/01.08.Zero Matrix/README_EN.md b/lcci/01.08.Zero Matrix/README_EN.md index 7ac8c849b05fd..76481ce6b1413 100644 --- a/lcci/01.08.Zero Matrix/README_EN.md +++ b/lcci/01.08.Zero Matrix/README_EN.md @@ -94,6 +94,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m + n)$. +#### Python3 + ```python class Solution: def setZeroes(self, matrix: List[List[int]]) -> None: @@ -110,6 +112,8 @@ class Solution: matrix[i][j] = 0 ``` +#### Java + ```java class Solution { public void setZeroes(int[][] matrix) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func setZeroes(matrix [][]int) { m, n := len(matrix), len(matrix[0]) @@ -184,6 +192,8 @@ func setZeroes(matrix [][]int) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify matrix in-place instead. @@ -211,6 +221,8 @@ function setZeroes(matrix: number[][]): void { } ``` +#### Rust + ```rust impl Solution { pub fn set_zeroes(matrix: &mut Vec>) { @@ -237,6 +249,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix @@ -265,6 +279,8 @@ var setZeroes = function (matrix) { }; ``` +#### C + ```c void setZeroes(int** matrix, int matrixSize, int* matrixColSize) { int m = matrixSize; @@ -293,6 +309,8 @@ void setZeroes(int** matrix, int matrixSize, int* matrixColSize) { } ``` +#### Swift + ```swift class Solution { func setZeroes(_ matrix: inout [[Int]]) { @@ -338,6 +356,8 @@ The time complexity is $O(m \times n)$, where $m$ and $n$ are the number of rows +#### Python3 + ```python class Solution: def setZeroes(self, matrix: List[List[int]]) -> None: @@ -360,6 +380,8 @@ class Solution: matrix[i][0] = 0 ``` +#### Java + ```java class Solution { public void setZeroes(int[][] matrix) { @@ -406,6 +428,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -453,6 +477,8 @@ public: }; ``` +#### Go + ```go func setZeroes(matrix [][]int) { m, n := len(matrix), len(matrix[0]) @@ -496,6 +522,8 @@ func setZeroes(matrix [][]int) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify matrix in-place instead. @@ -545,6 +573,8 @@ function setZeroes(matrix: number[][]): void { } ``` +#### Rust + ```rust impl Solution { pub fn set_zeroes(matrix: &mut Vec>) { @@ -599,6 +629,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix @@ -643,6 +675,8 @@ var setZeroes = function (matrix) { }; ``` +#### C + ```c void setZeroes(int** matrix, int matrixSize, int* matrixColSize) { int m = matrixSize; diff --git a/lcci/01.09.String Rotation/README.md b/lcci/01.09.String Rotation/README.md index 5066593ac0596..94c2dba7267a9 100644 --- a/lcci/01.09.String Rotation/README.md +++ b/lcci/01.09.String Rotation/README.md @@ -72,12 +72,16 @@ s1 + s1 = "abaaba" +#### Python3 + ```python class Solution: def isFlipedString(self, s1: str, s2: str) -> bool: return len(s1) == len(s2) and s2 in s1 * 2 ``` +#### Java + ```java class Solution { public boolean isFlipedString(String s1, String s2) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -95,18 +101,24 @@ public: }; ``` +#### Go + ```go func isFlipedString(s1 string, s2 string) bool { return len(s1) == len(s2) && strings.Contains(s1+s1, s2) } ``` +#### TypeScript + ```ts function isFlipedString(s1: string, s2: string): boolean { return s1.length === s2.length && (s2 + s2).indexOf(s1) !== -1; } ``` +#### Rust + ```rust impl Solution { pub fn is_fliped_string(s1: String, s2: String) -> bool { @@ -115,6 +127,8 @@ impl Solution { } ``` +#### Swift + ```swift class Solution { func isFlippedString(_ s1: String, _ s2: String) -> Bool { diff --git a/lcci/01.09.String Rotation/README_EN.md b/lcci/01.09.String Rotation/README_EN.md index 142c48d83768b..3989a3824c40a 100644 --- a/lcci/01.09.String Rotation/README_EN.md +++ b/lcci/01.09.String Rotation/README_EN.md @@ -73,12 +73,16 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def isFlipedString(self, s1: str, s2: str) -> bool: return len(s1) == len(s2) and s2 in s1 * 2 ``` +#### Java + ```java class Solution { public boolean isFlipedString(String s1, String s2) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -96,18 +102,24 @@ public: }; ``` +#### Go + ```go func isFlipedString(s1 string, s2 string) bool { return len(s1) == len(s2) && strings.Contains(s1+s1, s2) } ``` +#### TypeScript + ```ts function isFlipedString(s1: string, s2: string): boolean { return s1.length === s2.length && (s2 + s2).indexOf(s1) !== -1; } ``` +#### Rust + ```rust impl Solution { pub fn is_fliped_string(s1: String, s2: String) -> bool { @@ -116,6 +128,8 @@ impl Solution { } ``` +#### Swift + ```swift class Solution { func isFlippedString(_ s1: String, _ s2: String) -> Bool { diff --git a/lcci/02.01.Remove Duplicate Node/README.md b/lcci/02.01.Remove Duplicate Node/README.md index 456d9aba9f664..2ae25301c15f6 100644 --- a/lcci/02.01.Remove Duplicate Node/README.md +++ b/lcci/02.01.Remove Duplicate Node/README.md @@ -61,6 +61,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/02.01.Remove%20Duplic +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -82,6 +84,8 @@ class Solution: return head ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -157,6 +165,8 @@ func removeDuplicateNodes(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -185,6 +195,8 @@ function removeDuplicateNodes(head: ListNode | null): ListNode | null { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -224,6 +236,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -251,6 +265,8 @@ var removeDuplicateNodes = function (head) { }; ``` +#### Swift + ```swift /** * Definition for singly-linked list. diff --git a/lcci/02.01.Remove Duplicate Node/README_EN.md b/lcci/02.01.Remove Duplicate Node/README_EN.md index d84864ddd41f5..d155fd3e4e551 100644 --- a/lcci/02.01.Remove Duplicate Node/README_EN.md +++ b/lcci/02.01.Remove Duplicate Node/README_EN.md @@ -67,6 +67,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -88,6 +90,8 @@ class Solution: return head ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -163,6 +171,8 @@ func removeDuplicateNodes(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -191,6 +201,8 @@ function removeDuplicateNodes(head: ListNode | null): ListNode | null { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -230,6 +242,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -257,6 +271,8 @@ var removeDuplicateNodes = function (head) { }; ``` +#### Swift + ```swift /** * Definition for singly-linked list. diff --git a/lcci/02.02.Kth Node From End of List/README.md b/lcci/02.02.Kth Node From End of List/README.md index e010d644aedfb..3d10483e2a0e6 100644 --- a/lcci/02.02.Kth Node From End of List/README.md +++ b/lcci/02.02.Kth Node From End of List/README.md @@ -41,6 +41,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/02.02.Kth%20Node%20Fr +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -60,6 +62,8 @@ class Solution: return slow.val ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -131,6 +139,8 @@ func kthToLast(head *ListNode, k int) int { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -157,6 +167,8 @@ function kthToLast(head: ListNode | null, k: number): number { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -190,6 +202,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -216,6 +230,8 @@ var kthToLast = function (head, k) { }; ``` +#### Swift + ```swift /** * Definition for singly-linked list. diff --git a/lcci/02.02.Kth Node From End of List/README_EN.md b/lcci/02.02.Kth Node From End of List/README_EN.md index 3d7c39ca06ff3..3ad666e90fc46 100644 --- a/lcci/02.02.Kth Node From End of List/README_EN.md +++ b/lcci/02.02.Kth Node From End of List/README_EN.md @@ -44,6 +44,8 @@ The time complexity is $O(n)$, where $n$ is the length of the list. The space co +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -63,6 +65,8 @@ class Solution: return slow.val ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -134,6 +142,8 @@ func kthToLast(head *ListNode, k int) int { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -160,6 +170,8 @@ function kthToLast(head: ListNode | null, k: number): number { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -193,6 +205,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -219,6 +233,8 @@ var kthToLast = function (head, k) { }; ``` +#### Swift + ```swift /** * Definition for singly-linked list. diff --git a/lcci/02.03.Delete Middle Node/README.md b/lcci/02.03.Delete Middle Node/README.md index d3db6133858c0..f364e78673c15 100644 --- a/lcci/02.03.Delete Middle Node/README.md +++ b/lcci/02.03.Delete Middle Node/README.md @@ -45,6 +45,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/02.03.Delete%20Middle +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -59,6 +61,8 @@ class Solution: node.next = node.next.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -76,6 +80,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -94,6 +100,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -108,6 +116,8 @@ func deleteNode(node *ListNode) { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -126,6 +136,8 @@ var deleteNode = function (node) { }; ``` +#### Swift + ```swift /** * public class ListNode { diff --git a/lcci/02.03.Delete Middle Node/README_EN.md b/lcci/02.03.Delete Middle Node/README_EN.md index cf247020d12c2..20edd71820a18 100644 --- a/lcci/02.03.Delete Middle Node/README_EN.md +++ b/lcci/02.03.Delete Middle Node/README_EN.md @@ -42,6 +42,8 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -56,6 +58,8 @@ class Solution: node.next = node.next.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -73,6 +77,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -91,6 +97,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -105,6 +113,8 @@ func deleteNode(node *ListNode) { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -123,6 +133,8 @@ var deleteNode = function (node) { }; ``` +#### Swift + ```swift /** * public class ListNode { diff --git a/lcci/02.04.Partition List/README.md b/lcci/02.04.Partition List/README.md index 55ec6cf9cf7e8..0295f353a03a7 100644 --- a/lcci/02.04.Partition List/README.md +++ b/lcci/02.04.Partition List/README.md @@ -68,6 +68,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/02.04.Partition%20Lis +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -93,6 +95,8 @@ class Solution: return left.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -182,6 +190,8 @@ func partition(head *ListNode, x int) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -213,6 +223,8 @@ function partition(head: ListNode | null, x: number): ListNode | null { } ``` +#### Swift + ```swift /** public class ListNode { * var val: Int diff --git a/lcci/02.04.Partition List/README_EN.md b/lcci/02.04.Partition List/README_EN.md index 46a0ba4d366e2..21aaa81ed857d 100644 --- a/lcci/02.04.Partition List/README_EN.md +++ b/lcci/02.04.Partition List/README_EN.md @@ -48,6 +48,8 @@ The time complexity is $O(n)$, where $n$ is the length of the list. The space co +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -73,6 +75,8 @@ class Solution: return left.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -162,6 +170,8 @@ func partition(head *ListNode, x int) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -193,6 +203,8 @@ function partition(head: ListNode | null, x: number): ListNode | null { } ``` +#### Swift + ```swift /** public class ListNode { * var val: Int diff --git a/lcci/02.05.Sum Lists/README.md b/lcci/02.05.Sum Lists/README.md index 6ce8133579ddb..3ce68c29bf90c 100644 --- a/lcci/02.05.Sum Lists/README.md +++ b/lcci/02.05.Sum Lists/README.md @@ -54,6 +54,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/02.05.Sum%20Lists/REA +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -76,6 +78,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -160,6 +168,8 @@ func addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -204,6 +214,8 @@ function addTwoNumbers(l1: ListNode | null, l2: ListNode | null): ListNode | nul } ``` +#### Rust + ```rust impl Solution { pub fn add_two_numbers( @@ -242,6 +254,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -271,6 +285,8 @@ var addTwoNumbers = function (l1, l2) { }; ``` +#### Swift + ```swift /** * Definition for singly-linked list. diff --git a/lcci/02.05.Sum Lists/README_EN.md b/lcci/02.05.Sum Lists/README_EN.md index d535330cc90dd..863acc038358b 100644 --- a/lcci/02.05.Sum Lists/README_EN.md +++ b/lcci/02.05.Sum Lists/README_EN.md @@ -58,6 +58,8 @@ The time complexity is $O(\max(m, n))$, where $m$ and $n$ are the lengths of the +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -80,6 +82,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -164,6 +172,8 @@ func addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -208,6 +218,8 @@ function addTwoNumbers(l1: ListNode | null, l2: ListNode | null): ListNode | nul } ``` +#### Rust + ```rust impl Solution { pub fn add_two_numbers( @@ -246,6 +258,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -275,6 +289,8 @@ var addTwoNumbers = function (l1, l2) { }; ``` +#### Swift + ```swift /** * Definition for singly-linked list. diff --git a/lcci/02.06.Palindrome Linked List/README.md b/lcci/02.06.Palindrome Linked List/README.md index bbbb83137b5b4..7522e99791c51 100644 --- a/lcci/02.06.Palindrome Linked List/README.md +++ b/lcci/02.06.Palindrome Linked List/README.md @@ -55,6 +55,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/02.06.Palindrome%20Li +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -86,6 +88,8 @@ class Solution: return True ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -208,6 +216,8 @@ func isPalindrome(head *ListNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -252,6 +262,8 @@ function isPalindrome(head: ListNode | null): boolean { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -295,6 +307,8 @@ var isPalindrome = function (head) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. @@ -337,6 +351,8 @@ public class Solution { } ``` +#### Swift + ```swift /** * public class ListNode { diff --git a/lcci/02.06.Palindrome Linked List/README_EN.md b/lcci/02.06.Palindrome Linked List/README_EN.md index 8a8e5a3049283..00baf684a1ef3 100644 --- a/lcci/02.06.Palindrome Linked List/README_EN.md +++ b/lcci/02.06.Palindrome Linked List/README_EN.md @@ -64,6 +64,8 @@ The time complexity is $O(n)$, where $n$ is the length of the list. The space co +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -95,6 +97,8 @@ class Solution: return True ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -180,6 +186,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -217,6 +225,8 @@ func isPalindrome(head *ListNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -261,6 +271,8 @@ function isPalindrome(head: ListNode | null): boolean { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -304,6 +316,8 @@ var isPalindrome = function (head) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. @@ -346,6 +360,8 @@ public class Solution { } ``` +#### Swift + ```swift /** * public class ListNode { diff --git a/lcci/02.07.Intersection of Two Linked Lists/README.md b/lcci/02.07.Intersection of Two Linked Lists/README.md index 0c523e093da20..b6643ffd26e08 100644 --- a/lcci/02.07.Intersection of Two Linked Lists/README.md +++ b/lcci/02.07.Intersection of Two Linked Lists/README.md @@ -34,6 +34,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/02.07.Intersection%20 +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -51,6 +53,8 @@ class Solution: return a ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -75,6 +79,8 @@ public class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -97,6 +103,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -123,6 +131,8 @@ func getIntersectionNode(headA, headB *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -147,6 +157,8 @@ function getIntersectionNode(headA: ListNode | null, headB: ListNode | null): Li } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -172,6 +184,8 @@ var getIntersectionNode = function (headA, headB) { }; ``` +#### Swift + ```swift /** * Definition for singly-linked list. diff --git a/lcci/02.07.Intersection of Two Linked Lists/README_EN.md b/lcci/02.07.Intersection of Two Linked Lists/README_EN.md index f000df44ebe2d..ac315b0efb893 100644 --- a/lcci/02.07.Intersection of Two Linked Lists/README_EN.md +++ b/lcci/02.07.Intersection of Two Linked Lists/README_EN.md @@ -73,6 +73,8 @@ The time complexity is $O(m+n)$, where $m$ and $n$ are the lengths of the linked +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -90,6 +92,8 @@ class Solution: return a ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -114,6 +118,8 @@ public class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -162,6 +170,8 @@ func getIntersectionNode(headA, headB *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -186,6 +196,8 @@ function getIntersectionNode(headA: ListNode | null, headB: ListNode | null): Li } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -211,6 +223,8 @@ var getIntersectionNode = function (headA, headB) { }; ``` +#### Swift + ```swift /** * Definition for singly-linked list. diff --git a/lcci/02.08.Linked List Cycle/README_EN.md b/lcci/02.08.Linked List Cycle/README_EN.md index 18b5ee96f043e..575492b63d0a3 100644 --- a/lcci/02.08.Linked List Cycle/README_EN.md +++ b/lcci/02.08.Linked List Cycle/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(n)$, where $n$ is the number of nodes in the linked li +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -128,6 +132,8 @@ public class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -185,6 +193,8 @@ func detectCycle(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -216,6 +226,8 @@ function detectCycle(head: ListNode | null): ListNode | null { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -247,6 +259,8 @@ var detectCycle = function (head) { }; ``` +#### Swift + ```swift /* * public class ListNode { diff --git a/lcci/03.01.Three in One/README.md b/lcci/03.01.Three in One/README.md index 0f578a1eaae73..e9e9bd2ee6f2c 100644 --- a/lcci/03.01.Three in One/README.md +++ b/lcci/03.01.Three in One/README.md @@ -61,6 +61,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/03.01.Three%20in%20On +#### Python3 + ```python class TripleInOne: @@ -96,6 +98,8 @@ class TripleInOne: # param_4 = obj.isEmpty(stackNum) ``` +#### Java + ```java class TripleInOne { private int cap; @@ -140,6 +144,8 @@ class TripleInOne { */ ``` +#### C++ + ```cpp class TripleInOne { public: @@ -186,6 +192,8 @@ private: */ ``` +#### Go + ```go type TripleInOne struct { cap int @@ -232,6 +240,8 @@ func (this *TripleInOne) IsEmpty(stackNum int) bool { */ ``` +#### TypeScript + ```ts class TripleInOne { private cap: number; @@ -279,6 +289,8 @@ class TripleInOne { */ ``` +#### Swift + ```swift class TripleInOne { private var cap: Int diff --git a/lcci/03.01.Three in One/README_EN.md b/lcci/03.01.Three in One/README_EN.md index ddaeaf47b4281..61347236f71d8 100644 --- a/lcci/03.01.Three in One/README_EN.md +++ b/lcci/03.01.Three in One/README_EN.md @@ -76,6 +76,8 @@ In terms of time complexity, the time complexity of each operation is $O(1)$. Th +#### Python3 + ```python class TripleInOne: @@ -111,6 +113,8 @@ class TripleInOne: # param_4 = obj.isEmpty(stackNum) ``` +#### Java + ```java class TripleInOne { private int cap; @@ -155,6 +159,8 @@ class TripleInOne { */ ``` +#### C++ + ```cpp class TripleInOne { public: @@ -201,6 +207,8 @@ private: */ ``` +#### Go + ```go type TripleInOne struct { cap int @@ -247,6 +255,8 @@ func (this *TripleInOne) IsEmpty(stackNum int) bool { */ ``` +#### TypeScript + ```ts class TripleInOne { private cap: number; @@ -294,6 +304,8 @@ class TripleInOne { */ ``` +#### Swift + ```swift class TripleInOne { private var cap: Int diff --git a/lcci/03.02.Min Stack/README.md b/lcci/03.02.Min Stack/README.md index fa2bea3f918bd..45a8d74c4e478 100644 --- a/lcci/03.02.Min Stack/README.md +++ b/lcci/03.02.Min Stack/README.md @@ -35,6 +35,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/03.02.Min%20Stack/REA +#### Python3 + ```python class MinStack: def __init__(self): @@ -67,6 +69,8 @@ class MinStack: # param_4 = obj.getMin() ``` +#### Java + ```java class MinStack { private Deque stk1 = new ArrayDeque<>(); @@ -106,6 +110,8 @@ class MinStack { */ ``` +#### C++ + ```cpp class MinStack { public: @@ -147,6 +153,8 @@ private: */ ``` +#### Go + ```go type MinStack struct { stk1 []int @@ -186,6 +194,8 @@ func (this *MinStack) GetMin() int { */ ``` +#### TypeScript + ```ts class MinStack { stack: number[]; @@ -224,6 +234,8 @@ class MinStack { */ ``` +#### Rust + ```rust use std::collections::VecDeque; struct MinStack { @@ -272,6 +284,8 @@ impl MinStack { */ ``` +#### C# + ```cs public class MinStack { private Stack stk1 = new Stack(); @@ -311,6 +325,8 @@ public class MinStack { */ ``` +#### Swift + ```swift class MinStack { private var stk1: [Int] diff --git a/lcci/03.02.Min Stack/README_EN.md b/lcci/03.02.Min Stack/README_EN.md index c5b13e7138866..0b3e68c2cbfcb 100644 --- a/lcci/03.02.Min Stack/README_EN.md +++ b/lcci/03.02.Min Stack/README_EN.md @@ -55,6 +55,8 @@ For each operation, the time complexity is $O(1)$, and the space complexity is $ +#### Python3 + ```python class MinStack: def __init__(self): @@ -87,6 +89,8 @@ class MinStack: # param_4 = obj.getMin() ``` +#### Java + ```java class MinStack { private Deque stk1 = new ArrayDeque<>(); @@ -126,6 +130,8 @@ class MinStack { */ ``` +#### C++ + ```cpp class MinStack { public: @@ -167,6 +173,8 @@ private: */ ``` +#### Go + ```go type MinStack struct { stk1 []int @@ -206,6 +214,8 @@ func (this *MinStack) GetMin() int { */ ``` +#### TypeScript + ```ts class MinStack { stack: number[]; @@ -244,6 +254,8 @@ class MinStack { */ ``` +#### Rust + ```rust use std::collections::VecDeque; struct MinStack { @@ -292,6 +304,8 @@ impl MinStack { */ ``` +#### C# + ```cs public class MinStack { private Stack stk1 = new Stack(); @@ -331,6 +345,8 @@ public class MinStack { */ ``` +#### Swift + ```swift class MinStack { private var stk1: [Int] diff --git a/lcci/03.03.Stack of Plates/README.md b/lcci/03.03.Stack of Plates/README.md index 2e13c86300a47..f7885e31c348f 100644 --- a/lcci/03.03.Stack of Plates/README.md +++ b/lcci/03.03.Stack of Plates/README.md @@ -49,6 +49,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/03.03.Stack%20of%20Pl +#### Python3 + ```python class StackOfPlates: def __init__(self, cap: int): @@ -81,6 +83,8 @@ class StackOfPlates: # param_3 = obj.popAt(index) ``` +#### Java + ```java class StackOfPlates { private List> stk = new ArrayList<>(); @@ -125,6 +129,8 @@ class StackOfPlates { */ ``` +#### C++ + ```cpp class StackOfPlates { public: @@ -172,6 +178,8 @@ private: */ ``` +#### Go + ```go type StackOfPlates struct { stk [][]int @@ -218,6 +226,8 @@ func (this *StackOfPlates) PopAt(index int) int { */ ``` +#### TypeScript + ```ts class StackOfPlates { private cap: number; @@ -271,6 +281,8 @@ class StackOfPlates { */ ``` +#### Swift + ```swift class StackOfPlates { private var stacks: [[Int]] diff --git a/lcci/03.03.Stack of Plates/README_EN.md b/lcci/03.03.Stack of Plates/README_EN.md index 9fdb975332bbe..b6043a77dbadc 100644 --- a/lcci/03.03.Stack of Plates/README_EN.md +++ b/lcci/03.03.Stack of Plates/README_EN.md @@ -65,6 +65,8 @@ The space complexity is $O(n)$, where $n$ is the number of elements. +#### Python3 + ```python class StackOfPlates: def __init__(self, cap: int): @@ -97,6 +99,8 @@ class StackOfPlates: # param_3 = obj.popAt(index) ``` +#### Java + ```java class StackOfPlates { private List> stk = new ArrayList<>(); @@ -141,6 +145,8 @@ class StackOfPlates { */ ``` +#### C++ + ```cpp class StackOfPlates { public: @@ -188,6 +194,8 @@ private: */ ``` +#### Go + ```go type StackOfPlates struct { stk [][]int @@ -234,6 +242,8 @@ func (this *StackOfPlates) PopAt(index int) int { */ ``` +#### TypeScript + ```ts class StackOfPlates { private cap: number; @@ -287,6 +297,8 @@ class StackOfPlates { */ ``` +#### Swift + ```swift class StackOfPlates { private var stacks: [[Int]] diff --git a/lcci/03.04.Implement Queue using Stacks/README.md b/lcci/03.04.Implement Queue using Stacks/README.md index b3c7d7d1f7bdf..d9334f3e5ad09 100644 --- a/lcci/03.04.Implement Queue using Stacks/README.md +++ b/lcci/03.04.Implement Queue using Stacks/README.md @@ -36,6 +36,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/03.04.Implement%20Que +#### Python3 + ```python class MyQueue: def __init__(self): @@ -70,6 +72,8 @@ class MyQueue: # param_4 = obj.empty() ``` +#### Java + ```java class MyQueue { private Deque stk1 = new ArrayDeque<>(); @@ -115,6 +119,8 @@ class MyQueue { */ ``` +#### C++ + ```cpp class MyQueue { public: @@ -165,6 +171,8 @@ private: */ ``` +#### Go + ```go type MyQueue struct { stk1 []int @@ -214,6 +222,8 @@ func (this *MyQueue) move() { */ ``` +#### TypeScript + ```ts class MyQueue { stk1: number[]; @@ -261,6 +271,8 @@ class MyQueue { */ ``` +#### Rust + ```rust use std::collections::VecDeque; @@ -312,6 +324,8 @@ impl MyQueue { */ ``` +#### Swift + ```swift class MyQueue { private var stk1: [Int] = [] diff --git a/lcci/03.04.Implement Queue using Stacks/README_EN.md b/lcci/03.04.Implement Queue using Stacks/README_EN.md index a8bc4aa75fbdd..3203a0cf45f70 100644 --- a/lcci/03.04.Implement Queue using Stacks/README_EN.md +++ b/lcci/03.04.Implement Queue using Stacks/README_EN.md @@ -68,6 +68,8 @@ When checking whether the queue is empty, we only need to check whether both sta +#### Python3 + ```python class MyQueue: def __init__(self): @@ -102,6 +104,8 @@ class MyQueue: # param_4 = obj.empty() ``` +#### Java + ```java class MyQueue { private Deque stk1 = new ArrayDeque<>(); @@ -147,6 +151,8 @@ class MyQueue { */ ``` +#### C++ + ```cpp class MyQueue { public: @@ -197,6 +203,8 @@ private: */ ``` +#### Go + ```go type MyQueue struct { stk1 []int @@ -246,6 +254,8 @@ func (this *MyQueue) move() { */ ``` +#### TypeScript + ```ts class MyQueue { stk1: number[]; @@ -293,6 +303,8 @@ class MyQueue { */ ``` +#### Rust + ```rust use std::collections::VecDeque; @@ -344,6 +356,8 @@ impl MyQueue { */ ``` +#### Swift + ```swift class MyQueue { private var stk1: [Int] = [] diff --git a/lcci/03.05.Sort of Stacks/README.md b/lcci/03.05.Sort of Stacks/README.md index 8e9ec883549ce..c1a2ee7701534 100644 --- a/lcci/03.05.Sort of Stacks/README.md +++ b/lcci/03.05.Sort of Stacks/README.md @@ -62,6 +62,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/03.05.Sort%20of%20Sta +#### Python3 + ```python class SortedStack: @@ -95,6 +97,8 @@ class SortedStack: # param_4 = obj.isEmpty() ``` +#### Java + ```java class SortedStack { private Deque stk = new ArrayDeque<>(); @@ -138,6 +142,8 @@ class SortedStack { */ ``` +#### C++ + ```cpp class SortedStack { public: @@ -185,6 +191,8 @@ private: */ ``` +#### Go + ```go type SortedStack struct { stk []int @@ -233,6 +241,8 @@ func (this *SortedStack) IsEmpty() bool { */ ``` +#### TypeScript + ```ts class SortedStack { private stk: number[] = []; @@ -274,6 +284,8 @@ class SortedStack { */ ``` +#### Rust + ```rust use std::collections::VecDeque; @@ -327,6 +339,8 @@ impl SortedStack { */ ``` +#### Swift + ```swift class SortedStack { private var stk: [Int] = [] diff --git a/lcci/03.05.Sort of Stacks/README_EN.md b/lcci/03.05.Sort of Stacks/README_EN.md index 95f6cc11a9762..e7070dcb7611c 100644 --- a/lcci/03.05.Sort of Stacks/README_EN.md +++ b/lcci/03.05.Sort of Stacks/README_EN.md @@ -76,6 +76,8 @@ The space complexity is $O(n)$, where $n$ is the number of elements in the stack +#### Python3 + ```python class SortedStack: @@ -109,6 +111,8 @@ class SortedStack: # param_4 = obj.isEmpty() ``` +#### Java + ```java class SortedStack { private Deque stk = new ArrayDeque<>(); @@ -152,6 +156,8 @@ class SortedStack { */ ``` +#### C++ + ```cpp class SortedStack { public: @@ -199,6 +205,8 @@ private: */ ``` +#### Go + ```go type SortedStack struct { stk []int @@ -247,6 +255,8 @@ func (this *SortedStack) IsEmpty() bool { */ ``` +#### TypeScript + ```ts class SortedStack { private stk: number[] = []; @@ -288,6 +298,8 @@ class SortedStack { */ ``` +#### Rust + ```rust use std::collections::VecDeque; @@ -341,6 +353,8 @@ impl SortedStack { */ ``` +#### Swift + ```swift class SortedStack { private var stk: [Int] = [] diff --git a/lcci/03.06.Animal Shelter/README.md b/lcci/03.06.Animal Shelter/README.md index a5890681ef1e2..08d9549b6b479 100644 --- a/lcci/03.06.Animal Shelter/README.md +++ b/lcci/03.06.Animal Shelter/README.md @@ -66,6 +66,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/03.06.Animal%20Shelte +#### Python3 + ```python class AnimalShelf: @@ -96,6 +98,8 @@ class AnimalShelf: # param_4 = obj.dequeueCat() ``` +#### Java + ```java class AnimalShelf { private Deque[] q = new Deque[2]; @@ -134,6 +138,8 @@ class AnimalShelf { */ ``` +#### C++ + ```cpp class AnimalShelf { public: @@ -183,6 +189,8 @@ private: */ ``` +#### Go + ```go type AnimalShelf struct { q [2][]int @@ -231,6 +239,8 @@ func (this *AnimalShelf) DequeueCat() []int { */ ``` +#### TypeScript + ```ts class AnimalShelf { private q: number[][] = [[], []]; @@ -273,6 +283,8 @@ class AnimalShelf { */ ``` +#### Rust + ```rust use std::collections::VecDeque; @@ -329,6 +341,8 @@ impl AnimalShelf { */ ``` +#### Swift + ```swift class AnimalShelf { private var q: [[Int]] = Array(repeating: [], count: 2) diff --git a/lcci/03.06.Animal Shelter/README_EN.md b/lcci/03.06.Animal Shelter/README_EN.md index 0135adc825e6c..1732b08d89c39 100644 --- a/lcci/03.06.Animal Shelter/README_EN.md +++ b/lcci/03.06.Animal Shelter/README_EN.md @@ -80,6 +80,8 @@ The time complexity of the above operations is $O(1)$, and the space complexity +#### Python3 + ```python class AnimalShelf: @@ -110,6 +112,8 @@ class AnimalShelf: # param_4 = obj.dequeueCat() ``` +#### Java + ```java class AnimalShelf { private Deque[] q = new Deque[2]; @@ -148,6 +152,8 @@ class AnimalShelf { */ ``` +#### C++ + ```cpp class AnimalShelf { public: @@ -197,6 +203,8 @@ private: */ ``` +#### Go + ```go type AnimalShelf struct { q [2][]int @@ -245,6 +253,8 @@ func (this *AnimalShelf) DequeueCat() []int { */ ``` +#### TypeScript + ```ts class AnimalShelf { private q: number[][] = [[], []]; @@ -287,6 +297,8 @@ class AnimalShelf { */ ``` +#### Rust + ```rust use std::collections::VecDeque; @@ -343,6 +355,8 @@ impl AnimalShelf { */ ``` +#### Swift + ```swift class AnimalShelf { private var q: [[Int]] = Array(repeating: [], count: 2) diff --git a/lcci/04.01.Route Between Nodes/README.md b/lcci/04.01.Route Between Nodes/README.md index 758d9c3f60d4b..1846da42fc412 100644 --- a/lcci/04.01.Route Between Nodes/README.md +++ b/lcci/04.01.Route Between Nodes/README.md @@ -56,6 +56,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/04.01.Route%20Between +#### Python3 + ```python class Solution: def findWhetherExistsPath( @@ -76,6 +78,8 @@ class Solution: return dfs(start) ``` +#### Java + ```java class Solution { private List[] g; @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func findWhetherExistsPath(n int, graph [][]int, start int, target int) bool { g := make([][]int, n) @@ -167,6 +175,8 @@ func findWhetherExistsPath(n int, graph [][]int, start int, target int) bool { } ``` +#### TypeScript + ```ts function findWhetherExistsPath( n: number, @@ -193,6 +203,8 @@ function findWhetherExistsPath( } ``` +#### Swift + ```swift class Solution { private var g: [[Int]]! @@ -241,6 +253,8 @@ class Solution { +#### Python3 + ```python class Solution: def findWhetherExistsPath( @@ -262,6 +276,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean findWhetherExistsPath(int n, int[][] graph, int start, int target) { @@ -291,6 +307,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -320,6 +338,8 @@ public: }; ``` +#### Go + ```go func findWhetherExistsPath(n int, graph [][]int, start int, target int) bool { g := make([][]int, n) @@ -346,6 +366,8 @@ func findWhetherExistsPath(n int, graph [][]int, start int, target int) bool { } ``` +#### TypeScript + ```ts function findWhetherExistsPath( n: number, diff --git a/lcci/04.01.Route Between Nodes/README_EN.md b/lcci/04.01.Route Between Nodes/README_EN.md index 8b06372b153be..5205c2f35b5a8 100644 --- a/lcci/04.01.Route Between Nodes/README_EN.md +++ b/lcci/04.01.Route Between Nodes/README_EN.md @@ -64,6 +64,8 @@ The time complexity is $O(n + m)$, and the space complexity is $O(n + m)$, where +#### Python3 + ```python class Solution: def findWhetherExistsPath( @@ -84,6 +86,8 @@ class Solution: return dfs(start) ``` +#### Java + ```java class Solution { private List[] g; @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func findWhetherExistsPath(n int, graph [][]int, start int, target int) bool { g := make([][]int, n) @@ -175,6 +183,8 @@ func findWhetherExistsPath(n int, graph [][]int, start int, target int) bool { } ``` +#### TypeScript + ```ts function findWhetherExistsPath( n: number, @@ -201,6 +211,8 @@ function findWhetherExistsPath( } ``` +#### Swift + ```swift class Solution { private var g: [[Int]]! @@ -249,6 +261,8 @@ The time complexity is $O(n + m)$, and the space complexity is $O(n + m)$, where +#### Python3 + ```python class Solution: def findWhetherExistsPath( @@ -270,6 +284,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean findWhetherExistsPath(int n, int[][] graph, int start, int target) { @@ -299,6 +315,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -328,6 +346,8 @@ public: }; ``` +#### Go + ```go func findWhetherExistsPath(n int, graph [][]int, start int, target int) bool { g := make([][]int, n) @@ -354,6 +374,8 @@ func findWhetherExistsPath(n int, graph [][]int, start int, target int) bool { } ``` +#### TypeScript + ```ts function findWhetherExistsPath( n: number, diff --git a/lcci/04.02.Minimum Height Tree/README.md b/lcci/04.02.Minimum Height Tree/README.md index e37849f23f194..7d3becafc1d44 100644 --- a/lcci/04.02.Minimum Height Tree/README.md +++ b/lcci/04.02.Minimum Height Tree/README.md @@ -36,6 +36,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/04.02.Minimum%20Heigh +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -56,6 +58,8 @@ class Solution: return dfs(0, len(nums) - 1) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -132,6 +140,8 @@ func sortedArrayToBST(nums []int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -159,6 +169,8 @@ function sortedArrayToBST(nums: number[]): TreeNode | null { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -202,6 +214,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -227,6 +241,8 @@ var sortedArrayToBST = function (nums) { }; ``` +#### Swift + ```swift /** * class TreeNode { diff --git a/lcci/04.02.Minimum Height Tree/README_EN.md b/lcci/04.02.Minimum Height Tree/README_EN.md index 89c93a93304dc..f0b78ac54426d 100644 --- a/lcci/04.02.Minimum Height Tree/README_EN.md +++ b/lcci/04.02.Minimum Height Tree/README_EN.md @@ -60,6 +60,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -80,6 +82,8 @@ class Solution: return dfs(0, len(nums) - 1) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -156,6 +164,8 @@ func sortedArrayToBST(nums []int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -183,6 +193,8 @@ function sortedArrayToBST(nums: number[]): TreeNode | null { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -226,6 +238,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -251,6 +265,8 @@ var sortedArrayToBST = function (nums) { }; ``` +#### Swift + ```swift /** * class TreeNode { diff --git a/lcci/04.03.List of Depth/README.md b/lcci/04.03.List of Depth/README.md index 2efe453c60571..615480288e257 100644 --- a/lcci/04.03.List of Depth/README.md +++ b/lcci/04.03.List of Depth/README.md @@ -47,6 +47,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/04.03.List%20of%20Dep +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -208,6 +216,8 @@ func listOfDepth(tree *TreeNode) (ans []*ListNode) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -254,6 +264,8 @@ function listOfDepth(tree: TreeNode | null): Array { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -324,6 +336,8 @@ impl Solution { } ``` +#### Swift + ```swift /* class TreeNode { * var val: Int diff --git a/lcci/04.03.List of Depth/README_EN.md b/lcci/04.03.List of Depth/README_EN.md index 3cf03bb913277..daf0f4a791c6e 100644 --- a/lcci/04.03.List of Depth/README_EN.md +++ b/lcci/04.03.List of Depth/README_EN.md @@ -60,6 +60,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -182,6 +188,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -221,6 +229,8 @@ func listOfDepth(tree *TreeNode) (ans []*ListNode) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -267,6 +277,8 @@ function listOfDepth(tree: TreeNode | null): Array { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -337,6 +349,8 @@ impl Solution { } ``` +#### Swift + ```swift /* class TreeNode { * var val: Int diff --git a/lcci/04.04.Check Balance/README.md b/lcci/04.04.Check Balance/README.md index 3d7923e8542e8..68135508df1b2 100644 --- a/lcci/04.04.Check Balance/README.md +++ b/lcci/04.04.Check Balance/README.md @@ -37,6 +37,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/04.04.Check%20Balance +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -59,6 +61,8 @@ class Solution: return dfs(root) >= 0 ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -149,6 +157,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -180,6 +190,8 @@ function isBalanced(root: TreeNode | null): boolean { } ``` +#### Swift + ```swift /* class TreeNode { * var val: Int diff --git a/lcci/04.04.Check Balance/README_EN.md b/lcci/04.04.Check Balance/README_EN.md index 215a6893b31d8..cccad99d6552d 100644 --- a/lcci/04.04.Check Balance/README_EN.md +++ b/lcci/04.04.Check Balance/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -103,6 +105,8 @@ class Solution: return dfs(root) >= 0 ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -193,6 +201,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -224,6 +234,8 @@ function isBalanced(root: TreeNode | null): boolean { } ``` +#### Swift + ```swift /* class TreeNode { * var val: Int diff --git a/lcci/04.05.Legal Binary Search Tree/README.md b/lcci/04.05.Legal Binary Search Tree/README.md index 37f691ecaf297..07ac1398e2aee 100644 --- a/lcci/04.05.Legal Binary Search Tree/README.md +++ b/lcci/04.05.Legal Binary Search Tree/README.md @@ -32,6 +32,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/04.05.Legal%20Binary% +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -56,6 +58,8 @@ class Solution: return dfs(root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -158,6 +166,8 @@ func isValidBST(root *TreeNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -192,6 +202,8 @@ function isValidBST(root: TreeNode | null): boolean { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -235,6 +247,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -267,6 +281,8 @@ var isValidBST = function (root) { }; ``` +#### C# + ```cs /** * Definition for a binary tree node. @@ -304,6 +320,8 @@ public class Solution { } ``` +#### Swift + ```swift /* class TreeNode { * var val: Int diff --git a/lcci/04.05.Legal Binary Search Tree/README_EN.md b/lcci/04.05.Legal Binary Search Tree/README_EN.md index 2a69359ad2f87..7d8bdf3bcb0a2 100644 --- a/lcci/04.05.Legal Binary Search Tree/README_EN.md +++ b/lcci/04.05.Legal Binary Search Tree/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -94,6 +96,8 @@ class Solution: return dfs(root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -196,6 +204,8 @@ func isValidBST(root *TreeNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -230,6 +240,8 @@ function isValidBST(root: TreeNode | null): boolean { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -273,6 +285,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -305,6 +319,8 @@ var isValidBST = function (root) { }; ``` +#### C# + ```cs /** * Definition for a binary tree node. @@ -342,6 +358,8 @@ public class Solution { } ``` +#### Swift + ```swift /* class TreeNode { * var val: Int diff --git a/lcci/04.06.Successor/README.md b/lcci/04.06.Successor/README.md index c06ce49e1ac1d..3de1e7ef889d8 100644 --- a/lcci/04.06.Successor/README.md +++ b/lcci/04.06.Successor/README.md @@ -63,6 +63,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/04.06.Successor/READM +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -159,6 +167,8 @@ func inorderSuccessor(root *TreeNode, p *TreeNode) (ans *TreeNode) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -188,6 +198,8 @@ function inorderSuccessor(root: TreeNode | null, p: TreeNode | null): TreeNode | } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -215,6 +227,8 @@ var inorderSuccessor = function (root, p) { }; ``` +#### Swift + ```swift /* class TreeNode { * var val: Int diff --git a/lcci/04.06.Successor/README_EN.md b/lcci/04.06.Successor/README_EN.md index 70454c2becbf7..a965465400f8f 100644 --- a/lcci/04.06.Successor/README_EN.md +++ b/lcci/04.06.Successor/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(h)$, where $h$ is the height of the binary search tree +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -179,6 +187,8 @@ func inorderSuccessor(root *TreeNode, p *TreeNode) (ans *TreeNode) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -208,6 +218,8 @@ function inorderSuccessor(root: TreeNode | null, p: TreeNode | null): TreeNode | } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -235,6 +247,8 @@ var inorderSuccessor = function (root, p) { }; ``` +#### Swift + ```swift /* class TreeNode { * var val: Int diff --git a/lcci/04.08.First Common Ancestor/README.md b/lcci/04.08.First Common Ancestor/README.md index 02e6ae928b8ad..d7a9fb878e8e4 100644 --- a/lcci/04.08.First Common Ancestor/README.md +++ b/lcci/04.08.First Common Ancestor/README.md @@ -26,6 +26,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/04.08.First%20Common% +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -46,6 +48,8 @@ class Solution: return right if left is None else (left if right is None else root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -68,6 +72,8 @@ class Solution { } ``` +#### Swift + ```swift /* class TreeNode { * var val: Int diff --git a/lcci/04.08.First Common Ancestor/README_EN.md b/lcci/04.08.First Common Ancestor/README_EN.md index 5ab2aa0c3a161..8df95cc286a11 100644 --- a/lcci/04.08.First Common Ancestor/README_EN.md +++ b/lcci/04.08.First Common Ancestor/README_EN.md @@ -73,6 +73,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/04.08.First%20Common% +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -93,6 +95,8 @@ class Solution: return right if left is None else (left if right is None else root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -115,6 +119,8 @@ class Solution { } ``` +#### Swift + ```swift /* class TreeNode { * var val: Int diff --git a/lcci/04.09.BST Sequences/README.md b/lcci/04.09.BST Sequences/README.md index 2197e9b33a583..0465a01b415c4 100644 --- a/lcci/04.09.BST Sequences/README.md +++ b/lcci/04.09.BST Sequences/README.md @@ -36,6 +36,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/04.09.BST%20Sequences +#### Swift + ```swift /* class TreeNode { * var val: Int diff --git a/lcci/04.09.BST Sequences/README_EN.md b/lcci/04.09.BST Sequences/README_EN.md index cb2fa0469de62..224590fbcc8ad 100644 --- a/lcci/04.09.BST Sequences/README_EN.md +++ b/lcci/04.09.BST Sequences/README_EN.md @@ -47,6 +47,8 @@ Given the following tree:

+#### Swift + ```swift /* class TreeNode { * var val: Int diff --git a/lcci/04.10.Check SubTree/README.md b/lcci/04.10.Check SubTree/README.md index 46ecb56ad50ed..814f68f0563bc 100644 --- a/lcci/04.10.Check SubTree/README.md +++ b/lcci/04.10.Check SubTree/README.md @@ -54,6 +54,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/04.10.Check%20SubTree +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -81,6 +83,8 @@ class Solution: return self.checkSubTree(t1.left, t2) or self.checkSubTree(t1.right, t2) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -187,6 +195,8 @@ func checkSubTree(t1 *TreeNode, t2 *TreeNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -225,6 +235,8 @@ function checkSubTree(t1: TreeNode | null, t2: TreeNode | null): boolean { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -282,6 +294,8 @@ impl Solution { } ``` +#### Swift + ```swift /* class TreeNode { * var val: Int diff --git a/lcci/04.10.Check SubTree/README_EN.md b/lcci/04.10.Check SubTree/README_EN.md index 5707ea337a38e..0f14c0e64f407 100644 --- a/lcci/04.10.Check SubTree/README_EN.md +++ b/lcci/04.10.Check SubTree/README_EN.md @@ -62,6 +62,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$. Where $n$ i +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -89,6 +91,8 @@ class Solution: return self.checkSubTree(t1.left, t2) or self.checkSubTree(t1.right, t2) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -195,6 +203,8 @@ func checkSubTree(t1 *TreeNode, t2 *TreeNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -233,6 +243,8 @@ function checkSubTree(t1: TreeNode | null, t2: TreeNode | null): boolean { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -290,6 +302,8 @@ impl Solution { } ``` +#### Swift + ```swift /* class TreeNode { * var val: Int diff --git a/lcci/04.12.Paths with Sum/README.md b/lcci/04.12.Paths with Sum/README.md index 9c3433036066e..011af3a4cc8b7 100644 --- a/lcci/04.12.Paths with Sum/README.md +++ b/lcci/04.12.Paths with Sum/README.md @@ -65,6 +65,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/04.12.Paths%20with%20 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -91,6 +93,8 @@ class Solution: return dfs(root, 0) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -186,6 +194,8 @@ func pathSum(root *TreeNode, sum int) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -220,6 +230,8 @@ function pathSum(root: TreeNode | null, sum: number): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -270,6 +282,8 @@ impl Solution { } ``` +#### Swift + ```swift /* class TreeNode { * var val: Int diff --git a/lcci/04.12.Paths with Sum/README_EN.md b/lcci/04.12.Paths with Sum/README_EN.md index 26bc94d5cecf7..aa65137b0d795 100644 --- a/lcci/04.12.Paths with Sum/README_EN.md +++ b/lcci/04.12.Paths with Sum/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -104,6 +106,8 @@ class Solution: return dfs(root, 0) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -199,6 +207,8 @@ func pathSum(root *TreeNode, sum int) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -233,6 +243,8 @@ function pathSum(root: TreeNode | null, sum: number): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -283,6 +295,8 @@ impl Solution { } ``` +#### Swift + ```swift /* class TreeNode { * var val: Int diff --git a/lcci/05.01.Insert Into Bits/README.md b/lcci/05.01.Insert Into Bits/README.md index 8b7c617edc2bb..02752bbb7e216 100644 --- a/lcci/05.01.Insert Into Bits/README.md +++ b/lcci/05.01.Insert Into Bits/README.md @@ -44,6 +44,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/05.01.Insert%20Into%2 +#### Python3 + ```python class Solution: def insertBits(self, N: int, M: int, i: int, j: int) -> int: @@ -52,6 +54,8 @@ class Solution: return N | M << i ``` +#### Java + ```java class Solution { public int insertBits(int N, int M, int i, int j) { @@ -63,6 +67,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -75,6 +81,8 @@ public: }; ``` +#### Go + ```go func insertBits(N int, M int, i int, j int) int { for k := i; k <= j; k++ { @@ -84,6 +92,8 @@ func insertBits(N int, M int, i int, j int) int { } ``` +#### TypeScript + ```ts function insertBits(N: number, M: number, i: number, j: number): number { for (let k = i; k <= j; ++k) { @@ -93,6 +103,8 @@ function insertBits(N: number, M: number, i: number, j: number): number { } ``` +#### Swift + ```swift class Solution { func insertBits(_ N: Int, _ M: Int, _ i: Int, _ j: Int) -> Int { diff --git a/lcci/05.01.Insert Into Bits/README_EN.md b/lcci/05.01.Insert Into Bits/README_EN.md index d30fe3e501bac..c84f6346a3377 100644 --- a/lcci/05.01.Insert Into Bits/README_EN.md +++ b/lcci/05.01.Insert Into Bits/README_EN.md @@ -46,6 +46,8 @@ The time complexity is $O(\log n)$, where $n$ is the size of $N$. The space comp +#### Python3 + ```python class Solution: def insertBits(self, N: int, M: int, i: int, j: int) -> int: @@ -54,6 +56,8 @@ class Solution: return N | M << i ``` +#### Java + ```java class Solution { public int insertBits(int N, int M, int i, int j) { @@ -65,6 +69,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -77,6 +83,8 @@ public: }; ``` +#### Go + ```go func insertBits(N int, M int, i int, j int) int { for k := i; k <= j; k++ { @@ -86,6 +94,8 @@ func insertBits(N int, M int, i int, j int) int { } ``` +#### TypeScript + ```ts function insertBits(N: number, M: number, i: number, j: number): number { for (let k = i; k <= j; ++k) { @@ -95,6 +105,8 @@ function insertBits(N: number, M: number, i: number, j: number): number { } ``` +#### Swift + ```swift class Solution { func insertBits(_ N: Int, _ M: Int, _ i: Int, _ j: Int) -> Int { diff --git a/lcci/05.02.Binary Number to String/README.md b/lcci/05.02.Binary Number to String/README.md index bd9c38cb999e9..e65e49dbeebdc 100644 --- a/lcci/05.02.Binary Number to String/README.md +++ b/lcci/05.02.Binary Number to String/README.md @@ -59,6 +59,8 @@ $$ +#### Python3 + ```python class Solution: def printBin(self, num: float) -> str: @@ -71,6 +73,8 @@ class Solution: return 'ERROR' if num else ans ``` +#### Java + ```java class Solution { public String printBin(double num) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -102,6 +108,8 @@ public: }; ``` +#### Go + ```go func printBin(num float64) string { ans := &strings.Builder{} @@ -119,6 +127,8 @@ func printBin(num float64) string { } ``` +#### Swift + ```swift class Solution { func printBin(_ num: Double) -> String { diff --git a/lcci/05.02.Binary Number to String/README_EN.md b/lcci/05.02.Binary Number to String/README_EN.md index cdc421a10a220..c54d0c6cad2b3 100644 --- a/lcci/05.02.Binary Number to String/README_EN.md +++ b/lcci/05.02.Binary Number to String/README_EN.md @@ -68,6 +68,8 @@ The time complexity is $O(C)$, and the space complexity is $O(C)$. Here, $C$ is +#### Python3 + ```python class Solution: def printBin(self, num: float) -> str: @@ -80,6 +82,8 @@ class Solution: return 'ERROR' if num else ans ``` +#### Java + ```java class Solution { public String printBin(double num) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func printBin(num float64) string { ans := &strings.Builder{} @@ -128,6 +136,8 @@ func printBin(num float64) string { } ``` +#### Swift + ```swift class Solution { func printBin(_ num: Double) -> String { diff --git a/lcci/05.03.Reverse Bits/README.md b/lcci/05.03.Reverse Bits/README.md index 6a1892163908b..cbec7bc2a611d 100644 --- a/lcci/05.03.Reverse Bits/README.md +++ b/lcci/05.03.Reverse Bits/README.md @@ -40,6 +40,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/05.03.Reverse%20Bits/ +#### Python3 + ```python class Solution: def reverseBits(self, num: int) -> int: @@ -53,6 +55,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int reverseBits(int num) { @@ -70,6 +74,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -88,6 +94,8 @@ public: }; ``` +#### Go + ```go func reverseBits(num int) (ans int) { var cnt, j int @@ -103,6 +111,8 @@ func reverseBits(num int) (ans int) { } ``` +#### TypeScript + ```ts function reverseBits(num: number): number { let ans = 0; @@ -118,6 +128,8 @@ function reverseBits(num: number): number { } ``` +#### Swift + ```swift class Solution { func reverseBits(_ num: Int) -> Int { diff --git a/lcci/05.03.Reverse Bits/README_EN.md b/lcci/05.03.Reverse Bits/README_EN.md index ed2ac9f5b81ac..eb68a91114262 100644 --- a/lcci/05.03.Reverse Bits/README_EN.md +++ b/lcci/05.03.Reverse Bits/README_EN.md @@ -48,6 +48,8 @@ The time complexity is $O(\log M)$, and the space complexity is $O(1)$. Here, $M +#### Python3 + ```python class Solution: def reverseBits(self, num: int) -> int: @@ -61,6 +63,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int reverseBits(int num) { @@ -78,6 +82,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -96,6 +102,8 @@ public: }; ``` +#### Go + ```go func reverseBits(num int) (ans int) { var cnt, j int @@ -111,6 +119,8 @@ func reverseBits(num int) (ans int) { } ``` +#### TypeScript + ```ts function reverseBits(num: number): number { let ans = 0; @@ -126,6 +136,8 @@ function reverseBits(num: number): number { } ``` +#### Swift + ```swift class Solution { func reverseBits(_ num: Int) -> Int { diff --git a/lcci/05.04.Closed Number/README.md b/lcci/05.04.Closed Number/README.md index d80f420b6dcb8..7bb1260799586 100644 --- a/lcci/05.04.Closed Number/README.md +++ b/lcci/05.04.Closed Number/README.md @@ -53,6 +53,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/05.04.Closed%20Number +#### Python3 + ```python class Solution: def findClosedNumbers(self, num: int) -> List[int]: @@ -79,6 +81,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] findClosedNumbers(int num) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func findClosedNumbers(num int) []int { ans := []int{-1, -1} @@ -183,6 +191,8 @@ func findClosedNumbers(num int) []int { } ``` +#### TypeScript + ```ts function findClosedNumbers(num: number): number[] { const ans: number[] = [-1, -1]; @@ -216,6 +226,8 @@ function findClosedNumbers(num: number): number[] { } ``` +#### Swift + ```swift class Solution { func findClosedNumbers(_ num: Int) -> [Int] { diff --git a/lcci/05.04.Closed Number/README_EN.md b/lcci/05.04.Closed Number/README_EN.md index 4c48db1d1a6c2..c237a12aa7c3b 100644 --- a/lcci/05.04.Closed Number/README_EN.md +++ b/lcci/05.04.Closed Number/README_EN.md @@ -59,6 +59,8 @@ The time complexity is $O(\log n)$, where $n$ is the size of $num$. The space co +#### Python3 + ```python class Solution: def findClosedNumbers(self, num: int) -> List[int]: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] findClosedNumbers(int num) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func findClosedNumbers(num int) []int { ans := []int{-1, -1} @@ -189,6 +197,8 @@ func findClosedNumbers(num int) []int { } ``` +#### TypeScript + ```ts function findClosedNumbers(num: number): number[] { const ans: number[] = [-1, -1]; @@ -222,6 +232,8 @@ function findClosedNumbers(num: number): number[] { } ``` +#### Swift + ```swift class Solution { func findClosedNumbers(_ num: Int) -> [Int] { diff --git a/lcci/05.06.Convert Integer/README.md b/lcci/05.06.Convert Integer/README.md index 9a2fefc4fddbc..40b607d746147 100644 --- a/lcci/05.06.Convert Integer/README.md +++ b/lcci/05.06.Convert Integer/README.md @@ -50,6 +50,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/05.06.Convert%20Integ +#### Python3 + ```python class Solution: def convertInteger(self, A: int, B: int) -> int: @@ -58,6 +60,8 @@ class Solution: return (A ^ B).bit_count() ``` +#### Java + ```java class Solution { public int convertInteger(int A, int B) { @@ -66,6 +70,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -76,12 +82,16 @@ public: }; ``` +#### Go + ```go func convertInteger(A int, B int) int { return bits.OnesCount32(uint32(A ^ B)) } ``` +#### TypeScript + ```ts function convertInteger(A: number, B: number): number { let res = 0; @@ -96,6 +106,8 @@ function convertInteger(A: number, B: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn convert_integer(a: i32, b: i32) -> i32 { @@ -104,6 +116,8 @@ impl Solution { } ``` +#### Swift + ```swift class Solution { func convertInteger(_ A: Int, _ B: Int) -> Int { diff --git a/lcci/05.06.Convert Integer/README_EN.md b/lcci/05.06.Convert Integer/README_EN.md index 03d05c26a4a5e..3df91731cea2a 100644 --- a/lcci/05.06.Convert Integer/README_EN.md +++ b/lcci/05.06.Convert Integer/README_EN.md @@ -68,6 +68,8 @@ The time complexity is $O(\log n)$, where $n$ is the maximum value of A and B. T +#### Python3 + ```python class Solution: def convertInteger(self, A: int, B: int) -> int: @@ -76,6 +78,8 @@ class Solution: return (A ^ B).bit_count() ``` +#### Java + ```java class Solution { public int convertInteger(int A, int B) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -94,12 +100,16 @@ public: }; ``` +#### Go + ```go func convertInteger(A int, B int) int { return bits.OnesCount32(uint32(A ^ B)) } ``` +#### TypeScript + ```ts function convertInteger(A: number, B: number): number { let res = 0; @@ -114,6 +124,8 @@ function convertInteger(A: number, B: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn convert_integer(a: i32, b: i32) -> i32 { @@ -122,6 +134,8 @@ impl Solution { } ``` +#### Swift + ```swift class Solution { func convertInteger(_ A: Int, _ B: Int) -> Int { diff --git a/lcci/05.07.Exchange/README.md b/lcci/05.07.Exchange/README.md index e7e7421ef6c97..ea45ce6241d41 100644 --- a/lcci/05.07.Exchange/README.md +++ b/lcci/05.07.Exchange/README.md @@ -50,12 +50,16 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/05.07.Exchange/README +#### Python3 + ```python class Solution: def exchangeBits(self, num: int) -> int: return ((num & 0x55555555) << 1) | ((num & 0xAAAAAAAA) >> 1) ``` +#### Java + ```java class Solution { public int exchangeBits(int num) { @@ -64,6 +68,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -73,18 +79,24 @@ public: }; ``` +#### Go + ```go func exchangeBits(num int) int { return ((num & 0x55555555) << 1) | (num&0xaaaaaaaa)>>1 } ``` +#### TypeScript + ```ts function exchangeBits(num: number): number { return ((num & 0x55555555) << 1) | ((num & 0xaaaaaaaa) >>> 1); } ``` +#### Rust + ```rust impl Solution { pub fn exchange_bits(num: i32) -> i32 { @@ -94,6 +106,8 @@ impl Solution { } ``` +#### Swift + ```swift class Solution { func exchangeBits(_ num: Int) -> Int { diff --git a/lcci/05.07.Exchange/README_EN.md b/lcci/05.07.Exchange/README_EN.md index a547725c4888b..8b8d849ac6817 100644 --- a/lcci/05.07.Exchange/README_EN.md +++ b/lcci/05.07.Exchange/README_EN.md @@ -57,12 +57,16 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def exchangeBits(self, num: int) -> int: return ((num & 0x55555555) << 1) | ((num & 0xAAAAAAAA) >> 1) ``` +#### Java + ```java class Solution { public int exchangeBits(int num) { @@ -71,6 +75,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -80,18 +86,24 @@ public: }; ``` +#### Go + ```go func exchangeBits(num int) int { return ((num & 0x55555555) << 1) | (num&0xaaaaaaaa)>>1 } ``` +#### TypeScript + ```ts function exchangeBits(num: number): number { return ((num & 0x55555555) << 1) | ((num & 0xaaaaaaaa) >>> 1); } ``` +#### Rust + ```rust impl Solution { pub fn exchange_bits(num: i32) -> i32 { @@ -101,6 +113,8 @@ impl Solution { } ``` +#### Swift + ```swift class Solution { func exchangeBits(_ num: Int) -> Int { diff --git a/lcci/05.08.Draw Line/README.md b/lcci/05.08.Draw Line/README.md index 6c3718916482e..f467f9482fc40 100644 --- a/lcci/05.08.Draw Line/README.md +++ b/lcci/05.08.Draw Line/README.md @@ -44,6 +44,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/05.08.Draw%20Line/REA +#### Python3 + ```python class Solution: def drawLine(self, length: int, w: int, x1: int, x2: int, y: int) -> List[int]: @@ -57,6 +59,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] drawLine(int length, int w, int x1, int x2, int y) { @@ -73,6 +77,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/lcci/05.08.Draw Line/README_EN.md b/lcci/05.08.Draw Line/README_EN.md index 7244d03ebee3b..9d1ff63a0076f 100644 --- a/lcci/05.08.Draw Line/README_EN.md +++ b/lcci/05.08.Draw Line/README_EN.md @@ -53,6 +53,8 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def drawLine(self, length: int, w: int, x1: int, x2: int, y: int) -> List[int]: @@ -66,6 +68,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] drawLine(int length, int w, int x1, int x2, int y) { @@ -82,6 +86,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/lcci/08.01.Three Steps Problem/README.md b/lcci/08.01.Three Steps Problem/README.md index 892a670937eb9..421461ed9d774 100644 --- a/lcci/08.01.Three Steps Problem/README.md +++ b/lcci/08.01.Three Steps Problem/README.md @@ -55,6 +55,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/08.01.Three%20Steps%2 +#### Python3 + ```python class Solution: def waysToStep(self, n: int) -> int: @@ -65,6 +67,8 @@ class Solution: return a ``` +#### Java + ```java class Solution { public int waysToStep(int n) { @@ -81,6 +85,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -98,6 +104,8 @@ public: }; ``` +#### Go + ```go func waysToStep(n int) int { const mod int = 1e9 + 7 @@ -109,6 +117,8 @@ func waysToStep(n int) int { } ``` +#### Rust + ```rust impl Solution { pub fn ways_to_step(n: i32) -> i32 { @@ -125,6 +135,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -140,6 +152,8 @@ var waysToStep = function (n) { }; ``` +#### C + ```c int waysToStep(int n) { const int mod = 1e9 + 7; @@ -154,6 +168,8 @@ int waysToStep(int n) { } ``` +#### Swift + ```swift class Solution { func waysToStep(_ n: Int) -> Int { @@ -208,6 +224,8 @@ $$ +#### Python3 + ```python class Solution: def waysToStep(self, n: int) -> int: @@ -237,6 +255,8 @@ class Solution: return sum(pow(a, n - 4)[0]) % mod ``` +#### Python3 + ```python import numpy as np @@ -257,6 +277,8 @@ class Solution: return res.sum() % mod ``` +#### Java + ```java class Solution { private final int mod = (int) 1e9 + 7; @@ -301,6 +323,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -347,6 +371,8 @@ private: }; ``` +#### Go + ```go const mod = 1e9 + 7 @@ -391,6 +417,8 @@ func pow(a [][]int, n int) [][]int { } ``` +#### JavaScript + ```js /** * @param {number} n diff --git a/lcci/08.01.Three Steps Problem/README_EN.md b/lcci/08.01.Three Steps Problem/README_EN.md index e3aeb6156a89a..93d93478b8bef 100644 --- a/lcci/08.01.Three Steps Problem/README_EN.md +++ b/lcci/08.01.Three Steps Problem/README_EN.md @@ -58,6 +58,8 @@ The time complexity is $O(n)$, where $n$ is the given integer. The space complex +#### Python3 + ```python class Solution: def waysToStep(self, n: int) -> int: @@ -68,6 +70,8 @@ class Solution: return a ``` +#### Java + ```java class Solution { public int waysToStep(int n) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,6 +107,8 @@ public: }; ``` +#### Go + ```go func waysToStep(n int) int { const mod int = 1e9 + 7 @@ -112,6 +120,8 @@ func waysToStep(n int) int { } ``` +#### Rust + ```rust impl Solution { pub fn ways_to_step(n: i32) -> i32 { @@ -128,6 +138,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -143,6 +155,8 @@ var waysToStep = function (n) { }; ``` +#### C + ```c int waysToStep(int n) { const int mod = 1e9 + 7; @@ -157,6 +171,8 @@ int waysToStep(int n) { } ``` +#### Swift + ```swift class Solution { func waysToStep(_ n: Int) -> Int { @@ -211,6 +227,8 @@ The time complexity is $O(\log n)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def waysToStep(self, n: int) -> int: @@ -240,6 +258,8 @@ class Solution: return sum(pow(a, n - 4)[0]) % mod ``` +#### Python3 + ```python import numpy as np @@ -260,6 +280,8 @@ class Solution: return res.sum() % mod ``` +#### Java + ```java class Solution { private final int mod = (int) 1e9 + 7; @@ -304,6 +326,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -350,6 +374,8 @@ private: }; ``` +#### Go + ```go const mod = 1e9 + 7 @@ -394,6 +420,8 @@ func pow(a [][]int, n int) [][]int { } ``` +#### JavaScript + ```js /** * @param {number} n diff --git a/lcci/08.02.Robot in a Grid/README.md b/lcci/08.02.Robot in a Grid/README.md index c97f2fbecad98..a13e2f594e13c 100644 --- a/lcci/08.02.Robot in a Grid/README.md +++ b/lcci/08.02.Robot in a Grid/README.md @@ -47,6 +47,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/08.02.Robot%20in%20a% +#### Python3 + ```python class Solution: def pathWithObstacles(self, obstacleGrid: List[List[int]]) -> List[List[int]]: @@ -65,6 +67,8 @@ class Solution: return ans if dfs(0, 0) else [] ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func pathWithObstacles(obstacleGrid [][]int) [][]int { m, n := len(obstacleGrid), len(obstacleGrid[0]) @@ -142,6 +150,8 @@ func pathWithObstacles(obstacleGrid [][]int) [][]int { } ``` +#### TypeScript + ```ts function pathWithObstacles(obstacleGrid: number[][]): number[][] { const m = obstacleGrid.length; @@ -166,6 +176,8 @@ function pathWithObstacles(obstacleGrid: number[][]): number[][] { } ``` +#### Rust + ```rust impl Solution { fn dfs(grid: &mut Vec>, path: &mut Vec>, i: usize, j: usize) -> bool { @@ -195,6 +207,8 @@ impl Solution { } ``` +#### Swift + ```swift class Solution { private var ans = [[Int]]() diff --git a/lcci/08.02.Robot in a Grid/README_EN.md b/lcci/08.02.Robot in a Grid/README_EN.md index 7e43f02412b44..07603c08178fc 100644 --- a/lcci/08.02.Robot in a Grid/README_EN.md +++ b/lcci/08.02.Robot in a Grid/README_EN.md @@ -56,6 +56,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def pathWithObstacles(self, obstacleGrid: List[List[int]]) -> List[List[int]]: @@ -74,6 +76,8 @@ class Solution: return ans if dfs(0, 0) else [] ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func pathWithObstacles(obstacleGrid [][]int) [][]int { m, n := len(obstacleGrid), len(obstacleGrid[0]) @@ -151,6 +159,8 @@ func pathWithObstacles(obstacleGrid [][]int) [][]int { } ``` +#### TypeScript + ```ts function pathWithObstacles(obstacleGrid: number[][]): number[][] { const m = obstacleGrid.length; @@ -175,6 +185,8 @@ function pathWithObstacles(obstacleGrid: number[][]): number[][] { } ``` +#### Rust + ```rust impl Solution { fn dfs(grid: &mut Vec>, path: &mut Vec>, i: usize, j: usize) -> bool { @@ -204,6 +216,8 @@ impl Solution { } ``` +#### Swift + ```swift class Solution { private var ans = [[Int]]() diff --git a/lcci/08.03.Magic Index/README.md b/lcci/08.03.Magic Index/README.md index 9f677282e10bb..cab927034e5ea 100644 --- a/lcci/08.03.Magic Index/README.md +++ b/lcci/08.03.Magic Index/README.md @@ -54,6 +54,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/08.03.Magic%20Index/R +#### Python3 + ```python class Solution: def findMagicIndex(self, nums: List[int]) -> int: @@ -71,6 +73,8 @@ class Solution: return dfs(0, len(nums) - 1) ``` +#### Java + ```java class Solution { public int findMagicIndex(int[] nums) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func findMagicIndex(nums []int) int { var dfs func(i, j int) int @@ -137,6 +145,8 @@ func findMagicIndex(nums []int) int { } ``` +#### TypeScript + ```ts function findMagicIndex(nums: number[]): number { const dfs = (i: number, j: number): number => { @@ -157,6 +167,8 @@ function findMagicIndex(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { fn dfs(nums: &Vec, i: usize, j: usize) -> i32 { @@ -182,6 +194,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -206,6 +220,8 @@ var findMagicIndex = function (nums) { }; ``` +#### Swift + ```swift class Solution { func findMagicIndex(_ nums: [Int]) -> Int { diff --git a/lcci/08.03.Magic Index/README_EN.md b/lcci/08.03.Magic Index/README_EN.md index 20ebc175c3db9..f2378b50c0365 100644 --- a/lcci/08.03.Magic Index/README_EN.md +++ b/lcci/08.03.Magic Index/README_EN.md @@ -61,6 +61,8 @@ In the worst case, the time complexity is $O(n)$, and the space complexity is $O +#### Python3 + ```python class Solution: def findMagicIndex(self, nums: List[int]) -> int: @@ -78,6 +80,8 @@ class Solution: return dfs(0, len(nums) - 1) ``` +#### Java + ```java class Solution { public int findMagicIndex(int[] nums) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func findMagicIndex(nums []int) int { var dfs func(i, j int) int @@ -144,6 +152,8 @@ func findMagicIndex(nums []int) int { } ``` +#### TypeScript + ```ts function findMagicIndex(nums: number[]): number { const dfs = (i: number, j: number): number => { @@ -164,6 +174,8 @@ function findMagicIndex(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { fn dfs(nums: &Vec, i: usize, j: usize) -> i32 { @@ -189,6 +201,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -213,6 +227,8 @@ var findMagicIndex = function (nums) { }; ``` +#### Swift + ```swift class Solution { func findMagicIndex(_ nums: [Int]) -> Int { diff --git a/lcci/08.04.Power Set/README.md b/lcci/08.04.Power Set/README.md index 4dd2d14feed6b..3d158833ea132 100644 --- a/lcci/08.04.Power Set/README.md +++ b/lcci/08.04.Power Set/README.md @@ -50,6 +50,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/08.04.Power%20Set/REA +#### Python3 + ```python class Solution: def subsets(self, nums: List[int]) -> List[List[int]]: @@ -67,6 +69,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func subsets(nums []int) [][]int { var ans [][]int @@ -134,6 +142,8 @@ func subsets(nums []int) [][]int { } ``` +#### TypeScript + ```ts function subsets(nums: number[]): number[][] { const res = [[]]; @@ -146,6 +156,8 @@ function subsets(nums: number[]): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn subsets(nums: Vec) -> Vec> { @@ -161,6 +173,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -184,6 +198,8 @@ function dfs(nums, depth, prev, res) { } ``` +#### Swift + ```swift class Solution { private var ans = [[Int]]() @@ -224,6 +240,8 @@ class Solution { +#### Python3 + ```python class Solution: def subsets(self, nums: List[int]) -> List[List[int]]: @@ -237,6 +255,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> subsets(int[] nums) { @@ -256,6 +276,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -277,6 +299,8 @@ public: }; ``` +#### Go + ```go func subsets(nums []int) [][]int { var ans [][]int @@ -294,6 +318,8 @@ func subsets(nums []int) [][]int { } ``` +#### TypeScript + ```ts function subsets(nums: number[]): number[][] { const n = nums.length; @@ -314,6 +340,8 @@ function subsets(nums: number[]): number[][] { } ``` +#### Rust + ```rust impl Solution { fn dfs(nums: &Vec, i: usize, res: &mut Vec>, list: &mut Vec) { diff --git a/lcci/08.04.Power Set/README_EN.md b/lcci/08.04.Power Set/README_EN.md index fd8d7666f0328..bce77529749ec 100644 --- a/lcci/08.04.Power Set/README_EN.md +++ b/lcci/08.04.Power Set/README_EN.md @@ -64,6 +64,8 @@ The time complexity is $O(n \times 2^n)$, and the space complexity is $O(n)$. He +#### Python3 + ```python class Solution: def subsets(self, nums: List[int]) -> List[List[int]]: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func subsets(nums []int) [][]int { var ans [][]int @@ -148,6 +156,8 @@ func subsets(nums []int) [][]int { } ``` +#### TypeScript + ```ts function subsets(nums: number[]): number[][] { const res = [[]]; @@ -160,6 +170,8 @@ function subsets(nums: number[]): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn subsets(nums: Vec) -> Vec> { @@ -175,6 +187,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -198,6 +212,8 @@ function dfs(nums, depth, prev, res) { } ``` +#### Swift + ```swift class Solution { private var ans = [[Int]]() @@ -238,6 +254,8 @@ The time complexity is $O(n \times 2^n)$, and the space complexity is $O(n)$. He +#### Python3 + ```python class Solution: def subsets(self, nums: List[int]) -> List[List[int]]: @@ -251,6 +269,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> subsets(int[] nums) { @@ -270,6 +290,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -291,6 +313,8 @@ public: }; ``` +#### Go + ```go func subsets(nums []int) [][]int { var ans [][]int @@ -308,6 +332,8 @@ func subsets(nums []int) [][]int { } ``` +#### TypeScript + ```ts function subsets(nums: number[]): number[][] { const n = nums.length; @@ -328,6 +354,8 @@ function subsets(nums: number[]): number[][] { } ``` +#### Rust + ```rust impl Solution { fn dfs(nums: &Vec, i: usize, res: &mut Vec>, list: &mut Vec) { diff --git a/lcci/08.05.Recursive Mulitply/README.md b/lcci/08.05.Recursive Mulitply/README.md index 4a6c46995d827..3400e8743a13b 100644 --- a/lcci/08.05.Recursive Mulitply/README.md +++ b/lcci/08.05.Recursive Mulitply/README.md @@ -46,6 +46,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/08.05.Recursive%20Mul +#### Python3 + ```python class Solution: def multiply(self, A: int, B: int) -> int: @@ -56,6 +58,8 @@ class Solution: return self.multiply(A, B >> 1) << 1 ``` +#### Java + ```java class Solution { public int multiply(int A, int B) { @@ -70,6 +74,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -85,6 +91,8 @@ public: }; ``` +#### Go + ```go func multiply(A int, B int) int { if B == 1 { @@ -97,6 +105,8 @@ func multiply(A int, B int) int { } ``` +#### TypeScript + ```ts function multiply(A: number, B: number): number { if (B === 1) { @@ -109,6 +119,8 @@ function multiply(A: number, B: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn multiply(a: i32, b: i32) -> i32 { @@ -123,6 +135,8 @@ impl Solution { } ``` +#### Swift + ```swift class Solution { func multiply(_ A: Int, _ B: Int) -> Int { diff --git a/lcci/08.05.Recursive Mulitply/README_EN.md b/lcci/08.05.Recursive Mulitply/README_EN.md index ca4c7a1b95414..54fa023d7a968 100644 --- a/lcci/08.05.Recursive Mulitply/README_EN.md +++ b/lcci/08.05.Recursive Mulitply/README_EN.md @@ -52,6 +52,8 @@ The time complexity is $O(\log n)$, and the space complexity is $O(\log n)$. Her +#### Python3 + ```python class Solution: def multiply(self, A: int, B: int) -> int: @@ -62,6 +64,8 @@ class Solution: return self.multiply(A, B >> 1) << 1 ``` +#### Java + ```java class Solution { public int multiply(int A, int B) { @@ -76,6 +80,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -91,6 +97,8 @@ public: }; ``` +#### Go + ```go func multiply(A int, B int) int { if B == 1 { @@ -103,6 +111,8 @@ func multiply(A int, B int) int { } ``` +#### TypeScript + ```ts function multiply(A: number, B: number): number { if (B === 1) { @@ -115,6 +125,8 @@ function multiply(A: number, B: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn multiply(a: i32, b: i32) -> i32 { @@ -129,6 +141,8 @@ impl Solution { } ``` +#### Swift + ```swift class Solution { func multiply(_ A: Int, _ B: Int) -> Int { diff --git a/lcci/08.06.Hanota/README.md b/lcci/08.06.Hanota/README.md index 655f5fc296e37..04efe8940d384 100644 --- a/lcci/08.06.Hanota/README.md +++ b/lcci/08.06.Hanota/README.md @@ -49,6 +49,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/08.06.Hanota/README.m +#### Python3 + ```python class Solution: def hanota(self, A: List[int], B: List[int], C: List[int]) -> None: @@ -63,6 +65,8 @@ class Solution: dfs(len(A), A, B, C) ``` +#### Java + ```java class Solution { public void hanota(List A, List B, List C) { @@ -81,6 +85,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,6 +107,8 @@ public: }; ``` +#### Go + ```go func hanota(A []int, B []int, C []int) []int { var dfs func(n int, a, b, c *[]int) @@ -120,6 +128,8 @@ func hanota(A []int, B []int, C []int) []int { } ``` +#### TypeScript + ```ts /** Do not return anything, modify C in-place instead. @@ -138,6 +148,8 @@ function hanota(A: number[], B: number[], C: number[]): void { } ``` +#### Swift + ```swift class Solution { func hanota(_ A: inout [Int], _ B: inout [Int], _ C: inout [Int]) { @@ -182,6 +194,8 @@ class Solution { +#### Python3 + ```python class Solution: def hanota(self, A: List[int], B: List[int], C: List[int]) -> None: @@ -196,6 +210,8 @@ class Solution: stk.append((n - 1, a, c, b)) ``` +#### Java + ```java class Solution { public void hanota(List A, List B, List C) { @@ -233,6 +249,8 @@ class Task { } ``` +#### C++ + ```cpp struct Task { int n; @@ -262,6 +280,8 @@ public: }; ``` +#### Go + ```go func hanota(A []int, B []int, C []int) []int { stk := []Task{{len(A), &A, &B, &C}} @@ -286,6 +306,8 @@ type Task struct { } ``` +#### TypeScript + ```ts /** Do not return anything, modify C in-place instead. diff --git a/lcci/08.06.Hanota/README_EN.md b/lcci/08.06.Hanota/README_EN.md index 89b44eb40005a..6d4243950efb0 100644 --- a/lcci/08.06.Hanota/README_EN.md +++ b/lcci/08.06.Hanota/README_EN.md @@ -56,6 +56,8 @@ The time complexity is $O(2^n)$, and the space complexity is $O(n)$. Here, $n$ i +#### Python3 + ```python class Solution: def hanota(self, A: List[int], B: List[int], C: List[int]) -> None: @@ -70,6 +72,8 @@ class Solution: dfs(len(A), A, B, C) ``` +#### Java + ```java class Solution { public void hanota(List A, List B, List C) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func hanota(A []int, B []int, C []int) []int { var dfs func(n int, a, b, c *[]int) @@ -127,6 +135,8 @@ func hanota(A []int, B []int, C []int) []int { } ``` +#### TypeScript + ```ts /** Do not return anything, modify C in-place instead. @@ -145,6 +155,8 @@ function hanota(A: number[], B: number[], C: number[]): void { } ``` +#### Swift + ```swift class Solution { func hanota(_ A: inout [Int], _ B: inout [Int], _ C: inout [Int]) { @@ -189,6 +201,8 @@ The time complexity is $O(2^n)$, and the space complexity is $O(n)$. Here, $n$ i +#### Python3 + ```python class Solution: def hanota(self, A: List[int], B: List[int], C: List[int]) -> None: @@ -203,6 +217,8 @@ class Solution: stk.append((n - 1, a, c, b)) ``` +#### Java + ```java class Solution { public void hanota(List A, List B, List C) { @@ -240,6 +256,8 @@ class Task { } ``` +#### C++ + ```cpp struct Task { int n; @@ -269,6 +287,8 @@ public: }; ``` +#### Go + ```go func hanota(A []int, B []int, C []int) []int { stk := []Task{{len(A), &A, &B, &C}} @@ -293,6 +313,8 @@ type Task struct { } ``` +#### TypeScript + ```ts /** Do not return anything, modify C in-place instead. diff --git a/lcci/08.07.Permutation I/README.md b/lcci/08.07.Permutation I/README.md index ddbbf5bf17eff..34a783fde5bac 100644 --- a/lcci/08.07.Permutation I/README.md +++ b/lcci/08.07.Permutation I/README.md @@ -51,6 +51,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/08.07.Permutation%20I +#### Python3 + ```python class Solution: def permutation(self, S: str) -> List[str]: @@ -75,6 +77,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private char[] s; @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func permutation(S string) (ans []string) { t := []byte{} @@ -163,6 +171,8 @@ func permutation(S string) (ans []string) { } ``` +#### TypeScript + ```ts function permutation(S: string): string[] { const n = S.length; @@ -190,6 +200,8 @@ function permutation(S: string): string[] { } ``` +#### JavaScript + ```js /** * @param {string} S @@ -221,6 +233,8 @@ var permutation = function (S) { }; ``` +#### Swift + ```swift class Solution { private var s: [Character] = [] diff --git a/lcci/08.07.Permutation I/README_EN.md b/lcci/08.07.Permutation I/README_EN.md index 99a66119532b0..fee5a04b2e71d 100644 --- a/lcci/08.07.Permutation I/README_EN.md +++ b/lcci/08.07.Permutation I/README_EN.md @@ -57,6 +57,8 @@ The time complexity is $O(n \times n!)$, where $n$ is the length of the string. +#### Python3 + ```python class Solution: def permutation(self, S: str) -> List[str]: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private char[] s; @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func permutation(S string) (ans []string) { t := []byte{} @@ -169,6 +177,8 @@ func permutation(S string) (ans []string) { } ``` +#### TypeScript + ```ts function permutation(S: string): string[] { const n = S.length; @@ -196,6 +206,8 @@ function permutation(S: string): string[] { } ``` +#### JavaScript + ```js /** * @param {string} S @@ -227,6 +239,8 @@ var permutation = function (S) { }; ``` +#### Swift + ```swift class Solution { private var s: [Character] = [] diff --git a/lcci/08.08.Permutation II/README.md b/lcci/08.08.Permutation II/README.md index 2e931fc0a7bd4..90b72d44fb2f1 100644 --- a/lcci/08.08.Permutation II/README.md +++ b/lcci/08.08.Permutation II/README.md @@ -50,6 +50,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/08.08.Permutation%20I +#### Python3 + ```python class Solution: def permutation(self, S: str) -> List[str]: @@ -74,6 +76,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func permutation(S string) (ans []string) { cs := []byte(S) @@ -171,6 +179,8 @@ func permutation(S string) (ans []string) { } ``` +#### TypeScript + ```ts function permutation(S: string): string[] { const cs: string[] = S.split('').sort(); @@ -199,6 +209,8 @@ function permutation(S: string): string[] { } ``` +#### JavaScript + ```js /** * @param {string} S @@ -231,6 +243,8 @@ var permutation = function (S) { }; ``` +#### Swift + ```swift class Solution { private var n: Int = 0 diff --git a/lcci/08.08.Permutation II/README_EN.md b/lcci/08.08.Permutation II/README_EN.md index df0cf919b181e..d2d10fe8e2414 100644 --- a/lcci/08.08.Permutation II/README_EN.md +++ b/lcci/08.08.Permutation II/README_EN.md @@ -58,6 +58,8 @@ The time complexity is $O(n \times n!)$, and the space complexity is $O(n)$. Her +#### Python3 + ```python class Solution: def permutation(self, S: str) -> List[str]: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func permutation(S string) (ans []string) { cs := []byte(S) @@ -179,6 +187,8 @@ func permutation(S string) (ans []string) { } ``` +#### TypeScript + ```ts function permutation(S: string): string[] { const cs: string[] = S.split('').sort(); @@ -207,6 +217,8 @@ function permutation(S: string): string[] { } ``` +#### JavaScript + ```js /** * @param {string} S @@ -239,6 +251,8 @@ var permutation = function (S) { }; ``` +#### Swift + ```swift class Solution { private var n: Int = 0 diff --git a/lcci/08.09.Bracket/README.md b/lcci/08.09.Bracket/README.md index 2867c6611b92d..6e4a46e5769b9 100644 --- a/lcci/08.09.Bracket/README.md +++ b/lcci/08.09.Bracket/README.md @@ -51,6 +51,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/08.09.Bracket/README. +#### Python3 + ```python class Solution: def generateParenthesis(self, n: int) -> List[str]: @@ -68,6 +70,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List ans = new ArrayList<>(); @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func generateParenthesis(n int) []string { ans := []string{} @@ -134,6 +142,8 @@ func generateParenthesis(n int) []string { } ``` +#### TypeScript + ```ts function generateParenthesis(n: number): string[] { function dfs(l, r, t) { @@ -153,6 +163,8 @@ function generateParenthesis(n: number): string[] { } ``` +#### Rust + ```rust impl Solution { fn dfs(left: i32, right: i32, s: &mut String, res: &mut Vec) { @@ -180,6 +192,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -203,6 +217,8 @@ var generateParenthesis = function (n) { }; ``` +#### Swift + ```swift class Solution { private var ans: [String] = [] diff --git a/lcci/08.09.Bracket/README_EN.md b/lcci/08.09.Bracket/README_EN.md index 346812aef2c47..295bd24efe68f 100644 --- a/lcci/08.09.Bracket/README_EN.md +++ b/lcci/08.09.Bracket/README_EN.md @@ -59,6 +59,8 @@ The time complexity is $O(2^{n\times 2} \times n)$, and the space complexity is +#### Python3 + ```python class Solution: def generateParenthesis(self, n: int) -> List[str]: @@ -76,6 +78,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List ans = new ArrayList<>(); @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func generateParenthesis(n int) []string { ans := []string{} @@ -142,6 +150,8 @@ func generateParenthesis(n int) []string { } ``` +#### TypeScript + ```ts function generateParenthesis(n: number): string[] { function dfs(l, r, t) { @@ -161,6 +171,8 @@ function generateParenthesis(n: number): string[] { } ``` +#### Rust + ```rust impl Solution { fn dfs(left: i32, right: i32, s: &mut String, res: &mut Vec) { @@ -188,6 +200,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -211,6 +225,8 @@ var generateParenthesis = function (n) { }; ``` +#### Swift + ```swift class Solution { private var ans: [String] = [] diff --git a/lcci/08.10.Color Fill/README.md b/lcci/08.10.Color Fill/README.md index 21a0d7920210c..d500fcab5b29e 100644 --- a/lcci/08.10.Color Fill/README.md +++ b/lcci/08.10.Color Fill/README.md @@ -52,6 +52,8 @@ sr = 1, sc = 1, newColor = 2 +#### Python3 + ```python class Solution: def floodFill( @@ -76,6 +78,8 @@ class Solution: return image ``` +#### Java + ```java class Solution { private int[] dirs = {-1, 0, 1, 0, -1}; @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func floodFill(image [][]int, sr int, sc int, newColor int) [][]int { oc := image[sr][sc] @@ -146,6 +154,8 @@ func floodFill(image [][]int, sr int, sc int, newColor int) [][]int { } ``` +#### TypeScript + ```ts function floodFill(image: number[][], sr: number, sc: number, newColor: number): number[][] { const dfs = (i: number, j: number): void => { @@ -172,6 +182,8 @@ function floodFill(image: number[][], sr: number, sc: number, newColor: number): } ``` +#### Rust + ```rust impl Solution { fn dfs(i: usize, j: usize, target: i32, new_color: i32, image: &mut Vec>) { @@ -205,6 +217,8 @@ impl Solution { } ``` +#### Swift + ```swift class Solution { private var dirs = [-1, 0, 1, 0, -1] @@ -246,6 +260,8 @@ class Solution { +#### Python3 + ```python class Solution: def floodFill( @@ -267,6 +283,8 @@ class Solution: return image ``` +#### Java + ```java class Solution { public int[][] floodFill(int[][] image, int sr, int sc, int newColor) { @@ -295,6 +313,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -322,6 +342,8 @@ public: }; ``` +#### Go + ```go func floodFill(image [][]int, sr int, sc int, newColor int) [][]int { if image[sr][sc] == newColor { @@ -346,6 +368,8 @@ func floodFill(image [][]int, sr int, sc int, newColor int) [][]int { } ``` +#### TypeScript + ```ts function floodFill(image: number[][], sr: number, sc: number, newColor: number): number[][] { if (image[sr][sc] === newColor) { diff --git a/lcci/08.10.Color Fill/README_EN.md b/lcci/08.10.Color Fill/README_EN.md index 5f42b53f4527f..ec9be4429271c 100644 --- a/lcci/08.10.Color Fill/README_EN.md +++ b/lcci/08.10.Color Fill/README_EN.md @@ -60,6 +60,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def floodFill( @@ -84,6 +86,8 @@ class Solution: return image ``` +#### Java + ```java class Solution { private int[] dirs = {-1, 0, 1, 0, -1}; @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func floodFill(image [][]int, sr int, sc int, newColor int) [][]int { oc := image[sr][sc] @@ -154,6 +162,8 @@ func floodFill(image [][]int, sr int, sc int, newColor int) [][]int { } ``` +#### TypeScript + ```ts function floodFill(image: number[][], sr: number, sc: number, newColor: number): number[][] { const dfs = (i: number, j: number): void => { @@ -180,6 +190,8 @@ function floodFill(image: number[][], sr: number, sc: number, newColor: number): } ``` +#### Rust + ```rust impl Solution { fn dfs(i: usize, j: usize, target: i32, new_color: i32, image: &mut Vec>) { @@ -213,6 +225,8 @@ impl Solution { } ``` +#### Swift + ```swift class Solution { private var dirs = [-1, 0, 1, 0, -1] @@ -254,6 +268,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def floodFill( @@ -275,6 +291,8 @@ class Solution: return image ``` +#### Java + ```java class Solution { public int[][] floodFill(int[][] image, int sr, int sc, int newColor) { @@ -303,6 +321,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -330,6 +350,8 @@ public: }; ``` +#### Go + ```go func floodFill(image [][]int, sr int, sc int, newColor int) [][]int { if image[sr][sc] == newColor { @@ -354,6 +376,8 @@ func floodFill(image [][]int, sr int, sc int, newColor int) [][]int { } ``` +#### TypeScript + ```ts function floodFill(image: number[][], sr: number, sc: number, newColor: number): number[][] { if (image[sr][sc] === newColor) { diff --git a/lcci/08.11.Coin/README.md b/lcci/08.11.Coin/README.md index 546e5d81c2bdc..66b7fb350e3da 100644 --- a/lcci/08.11.Coin/README.md +++ b/lcci/08.11.Coin/README.md @@ -78,6 +78,8 @@ $$ +#### Python3 + ```python class Solution: def waysToChange(self, n: int) -> int: @@ -93,6 +95,8 @@ class Solution: return f[-1][n] ``` +#### Java + ```java class Solution { public int waysToChange(int n) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func waysToChange(n int) int { const mod int = 1e9 + 7 @@ -156,6 +164,8 @@ func waysToChange(n int) int { } ``` +#### TypeScript + ```ts function waysToChange(n: number): number { const mod = 10 ** 9 + 7; @@ -174,6 +184,8 @@ function waysToChange(n: number): number { } ``` +#### Swift + ```swift class Solution { func waysToChange(_ n: Int) -> Int { @@ -207,6 +219,8 @@ class Solution { +#### Python3 + ```python class Solution: def waysToChange(self, n: int) -> int: @@ -219,6 +233,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int waysToChange(int n) { @@ -236,6 +252,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -255,6 +273,8 @@ public: }; ``` +#### Go + ```go func waysToChange(n int) int { const mod int = 1e9 + 7 @@ -270,6 +290,8 @@ func waysToChange(n int) int { } ``` +#### TypeScript + ```ts function waysToChange(n: number): number { const mod = 10 ** 9 + 7; diff --git a/lcci/08.11.Coin/README_EN.md b/lcci/08.11.Coin/README_EN.md index f959382a71a09..2723728769cfb 100644 --- a/lcci/08.11.Coin/README_EN.md +++ b/lcci/08.11.Coin/README_EN.md @@ -91,6 +91,8 @@ The time complexity is $O(C \times n)$, and the space complexity is $O(C \times +#### Python3 + ```python class Solution: def waysToChange(self, n: int) -> int: @@ -106,6 +108,8 @@ class Solution: return f[-1][n] ``` +#### Java + ```java class Solution { public int waysToChange(int n) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func waysToChange(n int) int { const mod int = 1e9 + 7 @@ -169,6 +177,8 @@ func waysToChange(n int) int { } ``` +#### TypeScript + ```ts function waysToChange(n: number): number { const mod = 10 ** 9 + 7; @@ -187,6 +197,8 @@ function waysToChange(n: number): number { } ``` +#### Swift + ```swift class Solution { func waysToChange(_ n: Int) -> Int { @@ -220,6 +232,8 @@ We notice that the calculation of $f[i][j]$ is only related to $f[i−1][..]$. T +#### Python3 + ```python class Solution: def waysToChange(self, n: int) -> int: @@ -232,6 +246,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int waysToChange(int n) { @@ -249,6 +265,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -268,6 +286,8 @@ public: }; ``` +#### Go + ```go func waysToChange(n int) int { const mod int = 1e9 + 7 @@ -283,6 +303,8 @@ func waysToChange(n int) int { } ``` +#### TypeScript + ```ts function waysToChange(n: number): number { const mod = 10 ** 9 + 7; diff --git a/lcci/08.12.Eight Queens/README.md b/lcci/08.12.Eight Queens/README.md index b3b80d4580434..40aea759ca671 100644 --- a/lcci/08.12.Eight Queens/README.md +++ b/lcci/08.12.Eight Queens/README.md @@ -58,6 +58,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/08.12.Eight%20Queens/ +#### Python3 + ```python class Solution: def solveNQueens(self, n: int) -> List[List[str]]: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func solveNQueens(n int) (ans [][]string) { col := make([]int, n) @@ -193,6 +201,8 @@ func solveNQueens(n int) (ans [][]string) { } ``` +#### TypeScript + ```ts function solveNQueens(n: number): string[][] { const col: number[] = Array(n).fill(0); @@ -220,6 +230,8 @@ function solveNQueens(n: number): string[][] { } ``` +#### C# + ```cs public class Solution { private int n; @@ -259,6 +271,8 @@ public class Solution { } ``` +#### Swift + ```swift class Solution { private var ans: [[String]] = [] diff --git a/lcci/08.12.Eight Queens/README_EN.md b/lcci/08.12.Eight Queens/README_EN.md index 9fd549cb8356e..79e8fa1769f8d 100644 --- a/lcci/08.12.Eight Queens/README_EN.md +++ b/lcci/08.12.Eight Queens/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(n^2 \times n!)$, and the space complexity is $O(n)$. H +#### Python3 + ```python class Solution: def solveNQueens(self, n: int) -> List[List[str]]: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go func solveNQueens(n int) (ans [][]string) { col := make([]int, n) @@ -209,6 +217,8 @@ func solveNQueens(n int) (ans [][]string) { } ``` +#### TypeScript + ```ts function solveNQueens(n: number): string[][] { const col: number[] = Array(n).fill(0); @@ -236,6 +246,8 @@ function solveNQueens(n: number): string[][] { } ``` +#### C# + ```cs public class Solution { private int n; @@ -275,6 +287,8 @@ public class Solution { } ``` +#### Swift + ```swift class Solution { private var ans: [[String]] = [] diff --git a/lcci/08.13.Pile Box/README.md b/lcci/08.13.Pile Box/README.md index b21ff7e0afbf4..06420bdf43f82 100644 --- a/lcci/08.13.Pile Box/README.md +++ b/lcci/08.13.Pile Box/README.md @@ -47,6 +47,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/08.13.Pile%20Box/READ +#### Python3 + ```python class Solution: def pileBox(self, box: List[List[int]]) -> int: @@ -61,6 +63,8 @@ class Solution: return max(f) ``` +#### Java + ```java class Solution { public int pileBox(int[][] box) { @@ -82,6 +86,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func pileBox(box [][]int) int { sort.Slice(box, func(i, j int) bool { @@ -125,6 +133,8 @@ func pileBox(box [][]int) int { } ``` +#### TypeScript + ```ts function pileBox(box: number[][]): number { box.sort((a, b) => (a[0] === b[0] ? b[1] - a[1] : a[0] - b[0])); @@ -144,6 +154,8 @@ function pileBox(box: number[][]): number { } ``` +#### Swift + ```swift class Solution { func pileBox(_ box: [[Int]]) -> Int { diff --git a/lcci/08.13.Pile Box/README_EN.md b/lcci/08.13.Pile Box/README_EN.md index 4533a278bc32c..1134427558558 100644 --- a/lcci/08.13.Pile Box/README_EN.md +++ b/lcci/08.13.Pile Box/README_EN.md @@ -55,6 +55,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$. Here, $n$ i +#### Python3 + ```python class Solution: def pileBox(self, box: List[List[int]]) -> int: @@ -69,6 +71,8 @@ class Solution: return max(f) ``` +#### Java + ```java class Solution { public int pileBox(int[][] box) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func pileBox(box [][]int) int { sort.Slice(box, func(i, j int) bool { @@ -133,6 +141,8 @@ func pileBox(box [][]int) int { } ``` +#### TypeScript + ```ts function pileBox(box: number[][]): number { box.sort((a, b) => (a[0] === b[0] ? b[1] - a[1] : a[0] - b[0])); @@ -152,6 +162,8 @@ function pileBox(box: number[][]): number { } ``` +#### Swift + ```swift class Solution { func pileBox(_ box: [[Int]]) -> Int { diff --git a/lcci/08.14.Boolean Evaluation/README.md b/lcci/08.14.Boolean Evaluation/README.md index 13d81cd01e872..7be5a05182a85 100644 --- a/lcci/08.14.Boolean Evaluation/README.md +++ b/lcci/08.14.Boolean Evaluation/README.md @@ -48,6 +48,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/08.14.Boolean%20Evalu +#### Python3 + ```python class Solution: def countEval(self, s: str, result: int) -> int: @@ -75,6 +77,8 @@ class Solution: return ans[result] if 0 <= result < 2 else 0 ``` +#### Java + ```java class Solution { private Map memo; @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func countEval(s string, result int) int { memo := map[string][]int{} @@ -203,6 +211,8 @@ func countEval(s string, result int) int { } ``` +#### Swift + ```swift class Solution { private var memo = [String: [Int]]() diff --git a/lcci/08.14.Boolean Evaluation/README_EN.md b/lcci/08.14.Boolean Evaluation/README_EN.md index b6716e98f9df5..ea02db7cbc036 100644 --- a/lcci/08.14.Boolean Evaluation/README_EN.md +++ b/lcci/08.14.Boolean Evaluation/README_EN.md @@ -60,6 +60,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/08.14.Boolean%20Evalu +#### Python3 + ```python class Solution: def countEval(self, s: str, result: int) -> int: @@ -87,6 +89,8 @@ class Solution: return ans[result] if 0 <= result < 2 else 0 ``` +#### Java + ```java class Solution { private Map memo; @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go func countEval(s string, result int) int { memo := map[string][]int{} @@ -215,6 +223,8 @@ func countEval(s string, result int) int { } ``` +#### Swift + ```swift class Solution { private var memo = [String: [Int]]() diff --git a/lcci/10.01.Sorted Merge/README.md b/lcci/10.01.Sorted Merge/README.md index ca4b516acdd63..2a80ac4dffb00 100644 --- a/lcci/10.01.Sorted Merge/README.md +++ b/lcci/10.01.Sorted Merge/README.md @@ -46,6 +46,8 @@ B = [2,5,6], n = 3 +#### Python3 + ```python class Solution: def merge(self, A: List[int], m: int, B: List[int], n: int) -> None: @@ -59,6 +61,8 @@ class Solution: j -= 1 ``` +#### Java + ```java class Solution { public void merge(int[] A, int m, int[] B, int n) { @@ -74,6 +78,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -90,6 +96,8 @@ public: }; ``` +#### Go + ```go func merge(A []int, m int, B []int, n int) { i, j := m-1, n-1 @@ -105,6 +113,8 @@ func merge(A []int, m int, B []int, n int) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify A in-place instead. @@ -121,6 +131,8 @@ function merge(A: number[], m: number, B: number[], n: number): void { } ``` +#### Rust + ```rust impl Solution { pub fn merge(a: &mut Vec, m: i32, b: &mut Vec, n: i32) { @@ -138,6 +150,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} A @@ -158,6 +172,8 @@ var merge = function (A, m, B, n) { }; ``` +#### Swift + ```swift class Solution { func merge(_ A: inout [Int], _ m: Int, _ B: [Int], _ n: Int) { diff --git a/lcci/10.01.Sorted Merge/README_EN.md b/lcci/10.01.Sorted Merge/README_EN.md index c86e7cf9a93a9..6b4b13b2c4d80 100644 --- a/lcci/10.01.Sorted Merge/README_EN.md +++ b/lcci/10.01.Sorted Merge/README_EN.md @@ -46,6 +46,8 @@ The time complexity is $O(m + n)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def merge(self, A: List[int], m: int, B: List[int], n: int) -> None: @@ -59,6 +61,8 @@ class Solution: j -= 1 ``` +#### Java + ```java class Solution { public void merge(int[] A, int m, int[] B, int n) { @@ -74,6 +78,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -90,6 +96,8 @@ public: }; ``` +#### Go + ```go func merge(A []int, m int, B []int, n int) { i, j := m-1, n-1 @@ -105,6 +113,8 @@ func merge(A []int, m int, B []int, n int) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify A in-place instead. @@ -121,6 +131,8 @@ function merge(A: number[], m: number, B: number[], n: number): void { } ``` +#### Rust + ```rust impl Solution { pub fn merge(a: &mut Vec, m: i32, b: &mut Vec, n: i32) { @@ -138,6 +150,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} A @@ -158,6 +172,8 @@ var merge = function (A, m, B, n) { }; ``` +#### Swift + ```swift class Solution { func merge(_ A: inout [Int], _ m: Int, _ B: [Int], _ n: Int) { diff --git a/lcci/10.02.Group Anagrams/README.md b/lcci/10.02.Group Anagrams/README.md index a0c7ee16ad373..d40d684d17dcb 100644 --- a/lcci/10.02.Group Anagrams/README.md +++ b/lcci/10.02.Group Anagrams/README.md @@ -61,6 +61,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/10.02.Group%20Anagram +#### Python3 + ```python class Solution: def groupAnagrams(self, strs: List[str]) -> List[List[str]]: @@ -71,6 +73,8 @@ class Solution: return list(d.values()) ``` +#### Java + ```java class Solution { public List> groupAnagrams(String[] strs) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -103,6 +109,8 @@ public: }; ``` +#### Go + ```go func groupAnagrams(strs []string) (ans [][]string) { d := map[string][]string{} @@ -119,6 +127,8 @@ func groupAnagrams(strs []string) (ans [][]string) { } ``` +#### TypeScript + ```ts function groupAnagrams(strs: string[]): string[][] { const d: Map = new Map(); @@ -133,6 +143,8 @@ function groupAnagrams(strs: string[]): string[][] { } ``` +#### Swift + ```swift class Solution { func groupAnagrams(_ strs: [String]) -> [[String]] { @@ -160,6 +172,8 @@ class Solution { +#### Python3 + ```python class Solution: def groupAnagrams(self, strs: List[str]) -> List[List[str]]: @@ -172,6 +186,8 @@ class Solution: return list(d.values()) ``` +#### Java + ```java class Solution { public List> groupAnagrams(String[] strs) { @@ -195,6 +211,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -219,6 +237,8 @@ public: }; ``` +#### Go + ```go func groupAnagrams(strs []string) (ans [][]string) { d := map[[26]int][]string{} diff --git a/lcci/10.02.Group Anagrams/README_EN.md b/lcci/10.02.Group Anagrams/README_EN.md index 075bd7d9b8147..65e2091069536 100644 --- a/lcci/10.02.Group Anagrams/README_EN.md +++ b/lcci/10.02.Group Anagrams/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n\times k\times \log k)$, where $n$ and $k$ are the le +#### Python3 + ```python class Solution: def groupAnagrams(self, strs: List[str]) -> List[List[str]]: @@ -79,6 +81,8 @@ class Solution: return list(d.values()) ``` +#### Java + ```java class Solution { public List> groupAnagrams(String[] strs) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func groupAnagrams(strs []string) (ans [][]string) { d := map[string][]string{} @@ -127,6 +135,8 @@ func groupAnagrams(strs []string) (ans [][]string) { } ``` +#### TypeScript + ```ts function groupAnagrams(strs: string[]): string[][] { const d: Map = new Map(); @@ -141,6 +151,8 @@ function groupAnagrams(strs: string[]): string[][] { } ``` +#### Swift + ```swift class Solution { func groupAnagrams(_ strs: [String]) -> [[String]] { @@ -168,6 +180,8 @@ The time complexity is $O(n\times (k + C))$. Where $n$ and $k$ are the length of +#### Python3 + ```python class Solution: def groupAnagrams(self, strs: List[str]) -> List[List[str]]: @@ -180,6 +194,8 @@ class Solution: return list(d.values()) ``` +#### Java + ```java class Solution { public List> groupAnagrams(String[] strs) { @@ -203,6 +219,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -227,6 +245,8 @@ public: }; ``` +#### Go + ```go func groupAnagrams(strs []string) (ans [][]string) { d := map[[26]int][]string{} diff --git a/lcci/10.03.Search Rotate Array/README.md b/lcci/10.03.Search Rotate Array/README.md index 47eb5d20f3441..a80c36a16293b 100644 --- a/lcci/10.03.Search Rotate Array/README.md +++ b/lcci/10.03.Search Rotate Array/README.md @@ -56,6 +56,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/10.03.Search%20Rotate +#### Python3 + ```python class Solution: def search(self, arr: List[int], target: int) -> int: @@ -79,6 +81,8 @@ class Solution: return l if arr[l] == target else -1 ``` +#### Java + ```java class Solution { public int search(int[] arr, int target) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func search(arr []int, target int) int { l, r := 0, len(arr)-1 @@ -171,6 +179,8 @@ func search(arr []int, target int) int { } ``` +#### TypeScript + ```ts function search(arr: number[], target: number): number { let [l, r] = [0, arr.length - 1]; @@ -199,6 +209,8 @@ function search(arr: number[], target: number): number { } ``` +#### Swift + ```swift class Solution { func search(_ arr: [Int], _ target: Int) -> Int { diff --git a/lcci/10.03.Search Rotate Array/README_EN.md b/lcci/10.03.Search Rotate Array/README_EN.md index d66ce882a9031..5c48384c9e9dd 100644 --- a/lcci/10.03.Search Rotate Array/README_EN.md +++ b/lcci/10.03.Search Rotate Array/README_EN.md @@ -64,6 +64,8 @@ Similar problems: +#### Python3 + ```python class Solution: def search(self, arr: List[int], target: int) -> int: @@ -87,6 +89,8 @@ class Solution: return l if arr[l] == target else -1 ``` +#### Java + ```java class Solution { public int search(int[] arr, int target) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func search(arr []int, target int) int { l, r := 0, len(arr)-1 @@ -179,6 +187,8 @@ func search(arr []int, target int) int { } ``` +#### TypeScript + ```ts function search(arr: number[], target: number): number { let [l, r] = [0, arr.length - 1]; @@ -207,6 +217,8 @@ function search(arr: number[], target: number): number { } ``` +#### Swift + ```swift class Solution { func search(_ arr: [Int], _ target: Int) -> Int { diff --git a/lcci/10.05.Sparse Array Search/README.md b/lcci/10.05.Sparse Array Search/README.md index 16faabebae118..8680cb3ebb659 100644 --- a/lcci/10.05.Sparse Array Search/README.md +++ b/lcci/10.05.Sparse Array Search/README.md @@ -54,6 +54,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/10.05.Sparse%20Array% +#### Python3 + ```python class Solution: def findString(self, words: List[str], s: str) -> int: @@ -71,6 +73,8 @@ class Solution: return dfs(0, len(words) - 1) ``` +#### Java + ```java class Solution { public int findString(String[] words, String s) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func findString(words []string, s string) int { var dfs func(i, j int) int @@ -137,6 +145,8 @@ func findString(words []string, s string) int { } ``` +#### TypeScript + ```ts function findString(words: string[], s: string): number { const dfs = (i: number, j: number): number => { @@ -157,6 +167,8 @@ function findString(words: string[], s: string): number { } ``` +#### Swift + ```swift class Solution { func findString(_ words: [String], _ s: String) -> Int { diff --git a/lcci/10.05.Sparse Array Search/README_EN.md b/lcci/10.05.Sparse Array Search/README_EN.md index ac75ef6420f7c..f85641d1e3205 100644 --- a/lcci/10.05.Sparse Array Search/README_EN.md +++ b/lcci/10.05.Sparse Array Search/README_EN.md @@ -61,6 +61,8 @@ In the worst case, the time complexity is $O(n \times m)$, and the space complex +#### Python3 + ```python class Solution: def findString(self, words: List[str], s: str) -> int: @@ -78,6 +80,8 @@ class Solution: return dfs(0, len(words) - 1) ``` +#### Java + ```java class Solution { public int findString(String[] words, String s) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func findString(words []string, s string) int { var dfs func(i, j int) int @@ -144,6 +152,8 @@ func findString(words []string, s string) int { } ``` +#### TypeScript + ```ts function findString(words: string[], s: string): number { const dfs = (i: number, j: number): number => { @@ -164,6 +174,8 @@ function findString(words: string[], s: string): number { } ``` +#### Swift + ```swift class Solution { func findString(_ words: [String], _ s: String) -> Int { diff --git a/lcci/10.09.Sorted Matrix Search/README.md b/lcci/10.09.Sorted Matrix Search/README.md index be0f6feac2a78..f1678a642d65f 100644 --- a/lcci/10.09.Sorted Matrix Search/README.md +++ b/lcci/10.09.Sorted Matrix Search/README.md @@ -49,6 +49,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/10.09.Sorted%20Matrix +#### Python3 + ```python class Solution: def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: @@ -59,6 +61,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean searchMatrix(int[][] matrix, int target) { @@ -73,6 +77,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -88,6 +94,8 @@ public: }; ``` +#### Go + ```go func searchMatrix(matrix [][]int, target int) bool { for _, row := range matrix { @@ -100,6 +108,8 @@ func searchMatrix(matrix [][]int, target int) bool { } ``` +#### TypeScript + ```ts function searchMatrix(matrix: number[][], target: number): boolean { const n = matrix[0].length; @@ -122,6 +132,8 @@ function searchMatrix(matrix: number[][], target: number): boolean { } ``` +#### Rust + ```rust use std::cmp::Ordering; @@ -149,6 +161,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix @@ -176,6 +190,8 @@ var searchMatrix = function (matrix, target) { }; ``` +#### C# + ```cs public class Solution { public bool SearchMatrix(int[][] matrix, int target) { @@ -190,6 +206,8 @@ public class Solution { } ``` +#### Swift + ```swift class Solution { func searchMatrix(_ matrix: [[Int]], _ target: Int) -> Bool { @@ -241,6 +259,8 @@ class Solution { +#### Python3 + ```python class Solution: def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: @@ -258,6 +278,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean searchMatrix(int[][] matrix, int target) { @@ -281,6 +303,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -305,6 +329,8 @@ public: }; ``` +#### Go + ```go func searchMatrix(matrix [][]int, target int) bool { if len(matrix) == 0 { @@ -326,6 +352,8 @@ func searchMatrix(matrix [][]int, target int) bool { } ``` +#### TypeScript + ```ts function searchMatrix(matrix: number[][], target: number): boolean { if (matrix.length === 0) { @@ -347,6 +375,8 @@ function searchMatrix(matrix: number[][], target: number): boolean { } ``` +#### C# + ```cs public class Solution { public bool SearchMatrix(int[][] matrix, int target) { diff --git a/lcci/10.09.Sorted Matrix Search/README_EN.md b/lcci/10.09.Sorted Matrix Search/README_EN.md index 53db16d144955..737900835597c 100644 --- a/lcci/10.09.Sorted Matrix Search/README_EN.md +++ b/lcci/10.09.Sorted Matrix Search/README_EN.md @@ -58,6 +58,8 @@ The time complexity is $O(m \times \log n)$, where $m$ and $n$ are the number of +#### Python3 + ```python class Solution: def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: @@ -68,6 +70,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean searchMatrix(int[][] matrix, int target) { @@ -82,6 +86,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -97,6 +103,8 @@ public: }; ``` +#### Go + ```go func searchMatrix(matrix [][]int, target int) bool { for _, row := range matrix { @@ -109,6 +117,8 @@ func searchMatrix(matrix [][]int, target int) bool { } ``` +#### TypeScript + ```ts function searchMatrix(matrix: number[][], target: number): boolean { const n = matrix[0].length; @@ -131,6 +141,8 @@ function searchMatrix(matrix: number[][], target: number): boolean { } ``` +#### Rust + ```rust use std::cmp::Ordering; @@ -158,6 +170,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix @@ -185,6 +199,8 @@ var searchMatrix = function (matrix, target) { }; ``` +#### C# + ```cs public class Solution { public bool SearchMatrix(int[][] matrix, int target) { @@ -199,6 +215,8 @@ public class Solution { } ``` +#### Swift + ```swift class Solution { func searchMatrix(_ matrix: [[Int]], _ target: Int) -> Bool { @@ -250,6 +268,8 @@ The time complexity is $O(m + n)$, where $m$ and $n$ are the number of rows and +#### Python3 + ```python class Solution: def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: @@ -267,6 +287,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean searchMatrix(int[][] matrix, int target) { @@ -290,6 +312,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -314,6 +338,8 @@ public: }; ``` +#### Go + ```go func searchMatrix(matrix [][]int, target int) bool { if len(matrix) == 0 { @@ -335,6 +361,8 @@ func searchMatrix(matrix [][]int, target int) bool { } ``` +#### TypeScript + ```ts function searchMatrix(matrix: number[][], target: number): boolean { if (matrix.length === 0) { @@ -356,6 +384,8 @@ function searchMatrix(matrix: number[][], target: number): boolean { } ``` +#### C# + ```cs public class Solution { public bool SearchMatrix(int[][] matrix, int target) { diff --git a/lcci/10.10.Rank from Stream/README.md b/lcci/10.10.Rank from Stream/README.md index 558af39d732b2..15bc77ffb2ad1 100644 --- a/lcci/10.10.Rank from Stream/README.md +++ b/lcci/10.10.Rank from Stream/README.md @@ -54,6 +54,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/10.10.Rank%20from%20S +#### Python3 + ```python class BinaryIndexedTree: __slots__ = "n", "c" @@ -93,6 +95,8 @@ class StreamRank: # param_2 = obj.getRankOfNumber(x) ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -142,6 +146,8 @@ class StreamRank { */ ``` +#### C++ + ```cpp class BinaryIndexedTree { private: @@ -193,6 +199,8 @@ private: */ ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -241,6 +249,8 @@ func (this *StreamRank) GetRankOfNumber(x int) int { */ ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; @@ -288,6 +298,8 @@ class StreamRank { */ ``` +#### Swift + ```swift class BinaryIndexedTree { private var n: Int diff --git a/lcci/10.10.Rank from Stream/README_EN.md b/lcci/10.10.Rank from Stream/README_EN.md index b0e334f79ae33..ce6ca713c59b3 100644 --- a/lcci/10.10.Rank from Stream/README_EN.md +++ b/lcci/10.10.Rank from Stream/README_EN.md @@ -57,6 +57,8 @@ In terms of time complexity, both the update and query operations of the Binary +#### Python3 + ```python class BinaryIndexedTree: __slots__ = "n", "c" @@ -96,6 +98,8 @@ class StreamRank: # param_2 = obj.getRankOfNumber(x) ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -145,6 +149,8 @@ class StreamRank { */ ``` +#### C++ + ```cpp class BinaryIndexedTree { private: @@ -196,6 +202,8 @@ private: */ ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -244,6 +252,8 @@ func (this *StreamRank) GetRankOfNumber(x int) int { */ ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; @@ -291,6 +301,8 @@ class StreamRank { */ ``` +#### Swift + ```swift class BinaryIndexedTree { private var n: Int diff --git a/lcci/10.11.Peaks and Valleys/README.md b/lcci/10.11.Peaks and Valleys/README.md index 68d92525fb306..507000cd6c420 100644 --- a/lcci/10.11.Peaks and Valleys/README.md +++ b/lcci/10.11.Peaks and Valleys/README.md @@ -38,6 +38,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/10.11.Peaks%20and%20V +#### Python3 + ```python class Solution: def wiggleSort(self, nums: List[int]) -> None: @@ -46,6 +48,8 @@ class Solution: nums[i : i + 2] = nums[i : i + 2][::-1] ``` +#### Java + ```java class Solution { public void wiggleSort(int[] nums) { @@ -60,6 +64,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -73,6 +79,8 @@ public: }; ``` +#### Go + ```go func wiggleSort(nums []int) { sort.Ints(nums) @@ -82,6 +90,8 @@ func wiggleSort(nums []int) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify nums in-place instead. @@ -95,6 +105,8 @@ function wiggleSort(nums: number[]): void { } ``` +#### Swift + ```swift class Solution { func wiggleSort(_ nums: inout [Int]) { diff --git a/lcci/10.11.Peaks and Valleys/README_EN.md b/lcci/10.11.Peaks and Valleys/README_EN.md index 5c1f476c4a93f..2c60312b8bc49 100644 --- a/lcci/10.11.Peaks and Valleys/README_EN.md +++ b/lcci/10.11.Peaks and Valleys/README_EN.md @@ -42,6 +42,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def wiggleSort(self, nums: List[int]) -> None: @@ -50,6 +52,8 @@ class Solution: nums[i : i + 2] = nums[i : i + 2][::-1] ``` +#### Java + ```java class Solution { public void wiggleSort(int[] nums) { @@ -64,6 +68,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -77,6 +83,8 @@ public: }; ``` +#### Go + ```go func wiggleSort(nums []int) { sort.Ints(nums) @@ -86,6 +94,8 @@ func wiggleSort(nums []int) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify nums in-place instead. @@ -99,6 +109,8 @@ function wiggleSort(nums: number[]): void { } ``` +#### Swift + ```swift class Solution { func wiggleSort(_ nums: inout [Int]) { diff --git a/lcci/16.01.Swap Numbers/README.md b/lcci/16.01.Swap Numbers/README.md index 97f130d6a5336..c73ff5d154929 100644 --- a/lcci/16.01.Swap Numbers/README.md +++ b/lcci/16.01.Swap Numbers/README.md @@ -52,6 +52,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/16.01.Swap%20Numbers/ +#### Python3 + ```python class Solution: def swapNumbers(self, numbers: List[int]) -> List[int]: @@ -61,6 +63,8 @@ class Solution: return numbers ``` +#### Java + ```java class Solution { public int[] swapNumbers(int[] numbers) { @@ -72,6 +76,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -84,6 +90,8 @@ public: }; ``` +#### Go + ```go func swapNumbers(numbers []int) []int { numbers[0] ^= numbers[1] @@ -93,6 +101,8 @@ func swapNumbers(numbers []int) []int { } ``` +#### TypeScript + ```ts function swapNumbers(numbers: number[]): number[] { numbers[0] ^= numbers[1]; @@ -102,6 +112,8 @@ function swapNumbers(numbers: number[]): number[] { } ``` +#### Swift + ```swift class Solution { func swapNumbers(_ numbers: [Int]) -> [Int] { diff --git a/lcci/16.01.Swap Numbers/README_EN.md b/lcci/16.01.Swap Numbers/README_EN.md index 5655fa14d5e04..a788f3f19812c 100644 --- a/lcci/16.01.Swap Numbers/README_EN.md +++ b/lcci/16.01.Swap Numbers/README_EN.md @@ -60,6 +60,8 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def swapNumbers(self, numbers: List[int]) -> List[int]: @@ -69,6 +71,8 @@ class Solution: return numbers ``` +#### Java + ```java class Solution { public int[] swapNumbers(int[] numbers) { @@ -80,6 +84,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -92,6 +98,8 @@ public: }; ``` +#### Go + ```go func swapNumbers(numbers []int) []int { numbers[0] ^= numbers[1] @@ -101,6 +109,8 @@ func swapNumbers(numbers []int) []int { } ``` +#### TypeScript + ```ts function swapNumbers(numbers: number[]): number[] { numbers[0] ^= numbers[1]; @@ -110,6 +120,8 @@ function swapNumbers(numbers: number[]): number[] { } ``` +#### Swift + ```swift class Solution { func swapNumbers(_ numbers: [Int]) -> [Int] { diff --git a/lcci/16.02.Words Frequency/README.md b/lcci/16.02.Words Frequency/README.md index 4b449bf8adcba..96046d7d1dd37 100644 --- a/lcci/16.02.Words Frequency/README.md +++ b/lcci/16.02.Words Frequency/README.md @@ -52,6 +52,8 @@ wordsFrequency.get("pen"); //返回1 +#### Python3 + ```python class WordsFrequency: def __init__(self, book: List[str]): @@ -66,6 +68,8 @@ class WordsFrequency: # param_1 = obj.get(word) ``` +#### Java + ```java class WordsFrequency { private Map cnt = new HashMap<>(); @@ -88,6 +92,8 @@ class WordsFrequency { */ ``` +#### C++ + ```cpp class WordsFrequency { public: @@ -112,6 +118,8 @@ private: */ ``` +#### Go + ```go type WordsFrequency struct { cnt map[string]int @@ -136,6 +144,8 @@ func (this *WordsFrequency) Get(word string) int { */ ``` +#### TypeScript + ```ts class WordsFrequency { private cnt: Map; @@ -160,6 +170,8 @@ class WordsFrequency { */ ``` +#### Rust + ```rust use std::collections::HashMap; struct WordsFrequency { @@ -189,6 +201,8 @@ impl WordsFrequency { */ ``` +#### JavaScript + ```js /** * @param {string[]} book @@ -215,6 +229,8 @@ WordsFrequency.prototype.get = function (word) { */ ``` +#### Swift + ```swift class WordsFrequency { private var cnt: [String: Int] = [:] diff --git a/lcci/16.02.Words Frequency/README_EN.md b/lcci/16.02.Words Frequency/README_EN.md index 7fd1383e59b7c..91b1267402184 100644 --- a/lcci/16.02.Words Frequency/README_EN.md +++ b/lcci/16.02.Words Frequency/README_EN.md @@ -66,6 +66,8 @@ In terms of time complexity, the time complexity of initializing the hash table +#### Python3 + ```python class WordsFrequency: def __init__(self, book: List[str]): @@ -80,6 +82,8 @@ class WordsFrequency: # param_1 = obj.get(word) ``` +#### Java + ```java class WordsFrequency { private Map cnt = new HashMap<>(); @@ -102,6 +106,8 @@ class WordsFrequency { */ ``` +#### C++ + ```cpp class WordsFrequency { public: @@ -126,6 +132,8 @@ private: */ ``` +#### Go + ```go type WordsFrequency struct { cnt map[string]int @@ -150,6 +158,8 @@ func (this *WordsFrequency) Get(word string) int { */ ``` +#### TypeScript + ```ts class WordsFrequency { private cnt: Map; @@ -174,6 +184,8 @@ class WordsFrequency { */ ``` +#### Rust + ```rust use std::collections::HashMap; struct WordsFrequency { @@ -203,6 +215,8 @@ impl WordsFrequency { */ ``` +#### JavaScript + ```js /** * @param {string[]} book @@ -229,6 +243,8 @@ WordsFrequency.prototype.get = function (word) { */ ``` +#### Swift + ```swift class WordsFrequency { private var cnt: [String: Int] = [:] diff --git a/lcci/16.04.Tic-Tac-Toe/README.md b/lcci/16.04.Tic-Tac-Toe/README.md index c875a7da17378..14030b4c9b70a 100644 --- a/lcci/16.04.Tic-Tac-Toe/README.md +++ b/lcci/16.04.Tic-Tac-Toe/README.md @@ -63,6 +63,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/16.04.Tic-Tac-Toe/REA +#### Python3 + ```python class Solution: def tictactoe(self, board: List[str]) -> str: @@ -93,6 +95,8 @@ class Solution: return 'Pending' if has_empty_grid else 'Draw' ``` +#### Java + ```java class Solution { public String tictactoe(String[] board) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func tictactoe(board []string) string { n := len(board) @@ -206,6 +214,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function tictactoe(board: string[]): string { const n = board.length; @@ -243,6 +253,8 @@ function tictactoe(board: string[]): string { } ``` +#### Swift + ```swift class Solution { func tictactoe(_ board: [String]) -> String { diff --git a/lcci/16.04.Tic-Tac-Toe/README_EN.md b/lcci/16.04.Tic-Tac-Toe/README_EN.md index 03a6014775e7d..081de2dbdc2d3 100644 --- a/lcci/16.04.Tic-Tac-Toe/README_EN.md +++ b/lcci/16.04.Tic-Tac-Toe/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$, where $n$ i +#### Python3 + ```python class Solution: def tictactoe(self, board: List[str]) -> str: @@ -107,6 +109,8 @@ class Solution: return 'Pending' if has_empty_grid else 'Draw' ``` +#### Java + ```java class Solution { public String tictactoe(String[] board) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go func tictactoe(board []string) string { n := len(board) @@ -220,6 +228,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function tictactoe(board: string[]): string { const n = board.length; @@ -257,6 +267,8 @@ function tictactoe(board: string[]): string { } ``` +#### Swift + ```swift class Solution { func tictactoe(_ board: [String]) -> String { diff --git a/lcci/16.05.Factorial Zeros/README.md b/lcci/16.05.Factorial Zeros/README.md index 45e61b9b99d0d..6c21b9b64c6c4 100644 --- a/lcci/16.05.Factorial Zeros/README.md +++ b/lcci/16.05.Factorial Zeros/README.md @@ -46,6 +46,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/16.05.Factorial%20Zer +#### Python3 + ```python class Solution: def trailingZeroes(self, n: int) -> int: @@ -56,6 +58,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int trailingZeroes(int n) { @@ -69,6 +73,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -83,6 +89,8 @@ public: }; ``` +#### Go + ```go func trailingZeroes(n int) int { ans := 0 @@ -94,6 +102,8 @@ func trailingZeroes(n int) int { } ``` +#### TypeScript + ```ts function trailingZeroes(n: number): number { let ans = 0; @@ -105,6 +115,8 @@ function trailingZeroes(n: number): number { } ``` +#### Swift + ```swift class Solution { func trailingZeroes(_ n: Int) -> Int { diff --git a/lcci/16.05.Factorial Zeros/README_EN.md b/lcci/16.05.Factorial Zeros/README_EN.md index 922166ef65d3b..0e26a6c7ac7c9 100644 --- a/lcci/16.05.Factorial Zeros/README_EN.md +++ b/lcci/16.05.Factorial Zeros/README_EN.md @@ -56,6 +56,8 @@ The time complexity is $O(\log n)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def trailingZeroes(self, n: int) -> int: @@ -66,6 +68,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int trailingZeroes(int n) { @@ -79,6 +83,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -93,6 +99,8 @@ public: }; ``` +#### Go + ```go func trailingZeroes(n int) int { ans := 0 @@ -104,6 +112,8 @@ func trailingZeroes(n int) int { } ``` +#### TypeScript + ```ts function trailingZeroes(n: number): number { let ans = 0; @@ -115,6 +125,8 @@ function trailingZeroes(n: number): number { } ``` +#### Swift + ```swift class Solution { func trailingZeroes(_ n: Int) -> Int { diff --git a/lcci/16.06.Smallest Difference/README.md b/lcci/16.06.Smallest Difference/README.md index 19aeb81a5d9b4..4f6a5d6510376 100644 --- a/lcci/16.06.Smallest Difference/README.md +++ b/lcci/16.06.Smallest Difference/README.md @@ -40,6 +40,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/16.06.Smallest%20Diff +#### Python3 + ```python class Solution: def smallestDifference(self, a: List[int], b: List[int]) -> int: @@ -55,6 +57,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int smallestDifference(int[] a, int[] b) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func smallestDifference(a []int, b []int) int { sort.Ints(b) @@ -124,6 +132,8 @@ func smallestDifference(a []int, b []int) int { } ``` +#### TypeScript + ```ts function smallestDifference(a: number[], b: number[]): number { b.sort((a, b) => a - b); @@ -153,6 +163,8 @@ function smallestDifference(a: number[], b: number[]): number { } ``` +#### Swift + ```swift class Solution { func smallestDifference(_ a: [Int], _ b: [Int]) -> Int { @@ -202,6 +214,8 @@ class Solution { +#### Python3 + ```python class Solution: def smallestDifference(self, a: List[int], b: List[int]) -> int: @@ -218,6 +232,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int smallestDifference(int[] a, int[] b) { @@ -238,6 +254,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -259,6 +277,8 @@ public: }; ``` +#### Go + ```go func smallestDifference(a []int, b []int) int { sort.Ints(a) @@ -284,6 +304,8 @@ func abs(a int) int { } ``` +#### TypeScript + ```ts function smallestDifference(a: number[], b: number[]): number { a.sort((a, b) => a - b); diff --git a/lcci/16.06.Smallest Difference/README_EN.md b/lcci/16.06.Smallest Difference/README_EN.md index 6d1cc0cf12433..b9126e42d1c2c 100644 --- a/lcci/16.06.Smallest Difference/README_EN.md +++ b/lcci/16.06.Smallest Difference/README_EN.md @@ -48,6 +48,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def smallestDifference(self, a: List[int], b: List[int]) -> int: @@ -63,6 +65,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int smallestDifference(int[] a, int[] b) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func smallestDifference(a []int, b []int) int { sort.Ints(b) @@ -132,6 +140,8 @@ func smallestDifference(a []int, b []int) int { } ``` +#### TypeScript + ```ts function smallestDifference(a: number[], b: number[]): number { b.sort((a, b) => a - b); @@ -161,6 +171,8 @@ function smallestDifference(a: number[], b: number[]): number { } ``` +#### Swift + ```swift class Solution { func smallestDifference(_ a: [Int], _ b: [Int]) -> Int { @@ -210,6 +222,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def smallestDifference(self, a: List[int], b: List[int]) -> int: @@ -226,6 +240,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int smallestDifference(int[] a, int[] b) { @@ -246,6 +262,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -267,6 +285,8 @@ public: }; ``` +#### Go + ```go func smallestDifference(a []int, b []int) int { sort.Ints(a) @@ -292,6 +312,8 @@ func abs(a int) int { } ``` +#### TypeScript + ```ts function smallestDifference(a: number[], b: number[]): number { a.sort((a, b) => a - b); diff --git a/lcci/16.07.Maximum/README.md b/lcci/16.07.Maximum/README.md index 8ac924d4c9fcf..f31968c9dcd92 100644 --- a/lcci/16.07.Maximum/README.md +++ b/lcci/16.07.Maximum/README.md @@ -36,6 +36,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/16.07.Maximum/README. +#### Python3 + ```python class Solution: def maximum(self, a: int, b: int) -> int: @@ -43,6 +45,8 @@ class Solution: return a * (k ^ 1) + b * k ``` +#### Java + ```java class Solution { public int maximum(int a, int b) { @@ -52,6 +56,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -62,6 +68,8 @@ public: }; ``` +#### Go + ```go func maximum(a int, b int) int { k := (a - b) >> 63 & 1 @@ -69,6 +77,8 @@ func maximum(a int, b int) int { } ``` +#### TypeScript + ```ts function maximum(a: number, b: number): number { const k: number = Number(((BigInt(a) - BigInt(b)) >> BigInt(63)) & BigInt(1)); @@ -76,6 +86,8 @@ function maximum(a: number, b: number): number { } ``` +#### Swift + ```swift class Solution { func maximum(_ a: Int, _ b: Int) -> Int { diff --git a/lcci/16.07.Maximum/README_EN.md b/lcci/16.07.Maximum/README_EN.md index f06ddd98b4f73..7834f91564349 100644 --- a/lcci/16.07.Maximum/README_EN.md +++ b/lcci/16.07.Maximum/README_EN.md @@ -40,6 +40,8 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def maximum(self, a: int, b: int) -> int: @@ -47,6 +49,8 @@ class Solution: return a * (k ^ 1) + b * k ``` +#### Java + ```java class Solution { public int maximum(int a, int b) { @@ -56,6 +60,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -66,6 +72,8 @@ public: }; ``` +#### Go + ```go func maximum(a int, b int) int { k := (a - b) >> 63 & 1 @@ -73,6 +81,8 @@ func maximum(a int, b int) int { } ``` +#### TypeScript + ```ts function maximum(a: number, b: number): number { const k: number = Number(((BigInt(a) - BigInt(b)) >> BigInt(63)) & BigInt(1)); @@ -80,6 +90,8 @@ function maximum(a: number, b: number): number { } ``` +#### Swift + ```swift class Solution { func maximum(_ a: Int, _ b: Int) -> Int { diff --git a/lcci/16.10.Living People/README.md b/lcci/16.10.Living People/README.md index 38370e6212fe3..6ddcf2a02d402 100644 --- a/lcci/16.10.Living People/README.md +++ b/lcci/16.10.Living People/README.md @@ -47,6 +47,8 @@ death = {1948, 1951, 2000} +#### Python3 + ```python class Solution: def maxAliveYear(self, birth: List[int], death: List[int]) -> int: @@ -65,6 +67,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxAliveYear(int[] birth, int[] death) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func maxAliveYear(birth []int, death []int) (ans int) { base := 1900 @@ -138,6 +146,8 @@ func maxAliveYear(birth []int, death []int) (ans int) { } ``` +#### TypeScript + ```ts function maxAliveYear(birth: number[], death: number[]): number { const base = 1900; @@ -160,6 +170,8 @@ function maxAliveYear(birth: number[], death: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_alive_year(birth: Vec, death: Vec) -> i32 { @@ -185,6 +197,8 @@ impl Solution { } ``` +#### Swift + ```swift class Solution { func maxAliveYear(_ birth: [Int], _ death: [Int]) -> Int { diff --git a/lcci/16.10.Living People/README_EN.md b/lcci/16.10.Living People/README_EN.md index 7ee6f94753314..e2b59d6036a92 100644 --- a/lcci/16.10.Living People/README_EN.md +++ b/lcci/16.10.Living People/README_EN.md @@ -57,6 +57,8 @@ The time complexity is $O(n)$, and the space complexity is $O(C)$. Here, $n$ is +#### Python3 + ```python class Solution: def maxAliveYear(self, birth: List[int], death: List[int]) -> int: @@ -75,6 +77,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxAliveYear(int[] birth, int[] death) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func maxAliveYear(birth []int, death []int) (ans int) { base := 1900 @@ -148,6 +156,8 @@ func maxAliveYear(birth []int, death []int) (ans int) { } ``` +#### TypeScript + ```ts function maxAliveYear(birth: number[], death: number[]): number { const base = 1900; @@ -170,6 +180,8 @@ function maxAliveYear(birth: number[], death: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_alive_year(birth: Vec, death: Vec) -> i32 { @@ -195,6 +207,8 @@ impl Solution { } ``` +#### Swift + ```swift class Solution { func maxAliveYear(_ birth: [Int], _ death: [Int]) -> Int { diff --git a/lcci/16.11.Diving Board/README.md b/lcci/16.11.Diving Board/README.md index f741478f2fe4a..7b14f08132e68 100644 --- a/lcci/16.11.Diving Board/README.md +++ b/lcci/16.11.Diving Board/README.md @@ -47,6 +47,8 @@ k = 3 +#### Python3 + ```python class Solution: def divingBoard(self, shorter: int, longer: int, k: int) -> List[int]: @@ -60,6 +62,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] divingBoard(int shorter, int longer, int k) { @@ -78,6 +82,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -92,6 +98,8 @@ public: }; ``` +#### Go + ```go func divingBoard(shorter int, longer int, k int) []int { if k == 0 { @@ -108,6 +116,8 @@ func divingBoard(shorter int, longer int, k int) []int { } ``` +#### TypeScript + ```ts function divingBoard(shorter: number, longer: number, k: number): number[] { if (k === 0) { @@ -124,6 +134,8 @@ function divingBoard(shorter: number, longer: number, k: number): number[] { } ``` +#### Swift + ```swift class Solution { func divingBoard(_ shorter: Int, _ longer: Int, _ k: Int) -> [Int] { diff --git a/lcci/16.11.Diving Board/README_EN.md b/lcci/16.11.Diving Board/README_EN.md index 9b981842a4e68..e6ae95ecbbf12 100644 --- a/lcci/16.11.Diving Board/README_EN.md +++ b/lcci/16.11.Diving Board/README_EN.md @@ -59,6 +59,8 @@ The time complexity is $O(k)$, where $k$ is the number of boards. Ignoring the s +#### Python3 + ```python class Solution: def divingBoard(self, shorter: int, longer: int, k: int) -> List[int]: @@ -72,6 +74,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] divingBoard(int shorter, int longer, int k) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -104,6 +110,8 @@ public: }; ``` +#### Go + ```go func divingBoard(shorter int, longer int, k int) []int { if k == 0 { @@ -120,6 +128,8 @@ func divingBoard(shorter int, longer int, k int) []int { } ``` +#### TypeScript + ```ts function divingBoard(shorter: number, longer: number, k: number): number[] { if (k === 0) { @@ -136,6 +146,8 @@ function divingBoard(shorter: number, longer: number, k: number): number[] { } ``` +#### Swift + ```swift class Solution { func divingBoard(_ shorter: Int, _ longer: Int, _ k: Int) -> [Int] { diff --git a/lcci/16.13.Bisect Squares/README.md b/lcci/16.13.Bisect Squares/README.md index 60183ecb292ff..01aabba2261b7 100644 --- a/lcci/16.13.Bisect Squares/README.md +++ b/lcci/16.13.Bisect Squares/README.md @@ -51,6 +51,8 @@ square2 = {0, -1, 2} +#### Python3 + ```python class Solution: def cutSquares(self, square1: List[int], square2: List[int]) -> List[float]: @@ -77,6 +79,8 @@ class Solution: return [x3, y3, x4, y4] ``` +#### Java + ```java class Solution { public double[] cutSquares(int[] square1, int[] square2) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func cutSquares(square1 []int, square2 []int) []float64 { x1, y1 := float64(square1[0])+float64(square1[2])/2, float64(square1[1])+float64(square1[2])/2 @@ -176,6 +184,8 @@ func cutSquares(square1 []int, square2 []int) []float64 { } ``` +#### TypeScript + ```ts function cutSquares(square1: number[], square2: number[]): number[] { const x1 = square1[0] + square1[2] / 2; @@ -208,6 +218,8 @@ function cutSquares(square1: number[], square2: number[]): number[] { } ``` +#### Swift + ```swift class Solution { func cutSquares(_ square1: [Int], _ square2: [Int]) -> [Double] { diff --git a/lcci/16.13.Bisect Squares/README_EN.md b/lcci/16.13.Bisect Squares/README_EN.md index 8f646ca7adba5..434d35b707dfc 100644 --- a/lcci/16.13.Bisect Squares/README_EN.md +++ b/lcci/16.13.Bisect Squares/README_EN.md @@ -58,6 +58,8 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def cutSquares(self, square1: List[int], square2: List[int]) -> List[float]: @@ -84,6 +86,8 @@ class Solution: return [x3, y3, x4, y4] ``` +#### Java + ```java class Solution { public double[] cutSquares(int[] square1, int[] square2) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func cutSquares(square1 []int, square2 []int) []float64 { x1, y1 := float64(square1[0])+float64(square1[2])/2, float64(square1[1])+float64(square1[2])/2 @@ -183,6 +191,8 @@ func cutSquares(square1 []int, square2 []int) []float64 { } ``` +#### TypeScript + ```ts function cutSquares(square1: number[], square2: number[]): number[] { const x1 = square1[0] + square1[2] / 2; @@ -215,6 +225,8 @@ function cutSquares(square1: number[], square2: number[]): number[] { } ``` +#### Swift + ```swift class Solution { func cutSquares(_ square1: [Int], _ square2: [Int]) -> [Double] { diff --git a/lcci/16.14.Best Line/README.md b/lcci/16.14.Best Line/README.md index 057333c8b3ae5..62e7064c65c56 100644 --- a/lcci/16.14.Best Line/README.md +++ b/lcci/16.14.Best Line/README.md @@ -41,6 +41,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/16.14.Best%20Line/REA +#### Python3 + ```python class Solution: def bestLine(self, points: List[List[int]]) -> List[int]: @@ -62,6 +64,8 @@ class Solution: return [x, y] ``` +#### Java + ```java class Solution { public int[] bestLine(int[][] points) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func bestLine(points [][]int) []int { n := len(points) @@ -151,6 +159,8 @@ func bestLine(points [][]int) []int { } ``` +#### Swift + ```swift class Solution { func bestLine(_ points: [[Int]]) -> [Int] { @@ -202,6 +212,8 @@ class Solution { +#### Python3 + ```python class Solution: def bestLine(self, points: List[List[int]]) -> List[int]: @@ -225,6 +237,8 @@ class Solution: return [x, y] ``` +#### Java + ```java class Solution { public int[] bestLine(int[][] points) { @@ -259,6 +273,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -290,6 +306,8 @@ public: }; ``` +#### Go + ```go func bestLine(points [][]int) []int { n := len(points) diff --git a/lcci/16.14.Best Line/README_EN.md b/lcci/16.14.Best Line/README_EN.md index aac195fab8812..53acd6abd42a2 100644 --- a/lcci/16.14.Best Line/README_EN.md +++ b/lcci/16.14.Best Line/README_EN.md @@ -46,6 +46,8 @@ The time complexity is $O(n^3)$, and the space complexity is $O(1)$. Here, $n$ i +#### Python3 + ```python class Solution: def bestLine(self, points: List[List[int]]) -> List[int]: @@ -67,6 +69,8 @@ class Solution: return [x, y] ``` +#### Java + ```java class Solution { public int[] bestLine(int[][] points) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func bestLine(points [][]int) []int { n := len(points) @@ -156,6 +164,8 @@ func bestLine(points [][]int) []int { } ``` +#### Swift + ```swift class Solution { func bestLine(_ points: [[Int]]) -> [Int] { @@ -203,6 +213,8 @@ The time complexity is $O(n^2 \times \log m)$, and the space complexity is $O(n) +#### Python3 + ```python class Solution: def bestLine(self, points: List[List[int]]) -> List[int]: @@ -226,6 +238,8 @@ class Solution: return [x, y] ``` +#### Java + ```java class Solution { public int[] bestLine(int[][] points) { @@ -260,6 +274,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -291,6 +307,8 @@ public: }; ``` +#### Go + ```go func bestLine(points [][]int) []int { n := len(points) diff --git a/lcci/16.15.Master Mind/README.md b/lcci/16.15.Master Mind/README.md index 4c91527cbb1bb..7f1809906d2e7 100644 --- a/lcci/16.15.Master Mind/README.md +++ b/lcci/16.15.Master Mind/README.md @@ -44,6 +44,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/16.15.Master%20Mind/R +#### Python3 + ```python class Solution: def masterMind(self, solution: str, guess: str) -> List[int]: @@ -52,6 +54,8 @@ class Solution: return [x, y - x] ``` +#### Java + ```java class Solution { public int[] masterMind(String solution, String guess) { @@ -72,6 +76,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -90,6 +96,8 @@ public: }; ``` +#### Go + ```go func masterMind(solution string, guess string) []int { var x, y int @@ -110,6 +118,8 @@ func masterMind(solution string, guess string) []int { } ``` +#### JavaScript + ```js /** * @param {string} solution @@ -135,6 +145,8 @@ var masterMind = function (solution, guess) { }; ``` +#### Swift + ```swift class Solution { func masterMind(_ solution: String, _ guess: String) -> [Int] { diff --git a/lcci/16.15.Master Mind/README_EN.md b/lcci/16.15.Master Mind/README_EN.md index d7a80f1ff47bb..540452da456e4 100644 --- a/lcci/16.15.Master Mind/README_EN.md +++ b/lcci/16.15.Master Mind/README_EN.md @@ -52,6 +52,8 @@ The time complexity is $O(C)$, and the space complexity is $O(C)$. Here, $C=4$ f +#### Python3 + ```python class Solution: def masterMind(self, solution: str, guess: str) -> List[int]: @@ -60,6 +62,8 @@ class Solution: return [x, y - x] ``` +#### Java + ```java class Solution { public int[] masterMind(String solution, String guess) { @@ -80,6 +84,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -98,6 +104,8 @@ public: }; ``` +#### Go + ```go func masterMind(solution string, guess string) []int { var x, y int @@ -118,6 +126,8 @@ func masterMind(solution string, guess string) []int { } ``` +#### JavaScript + ```js /** * @param {string} solution @@ -143,6 +153,8 @@ var masterMind = function (solution, guess) { }; ``` +#### Swift + ```swift class Solution { func masterMind(_ solution: String, _ guess: String) -> [Int] { diff --git a/lcci/16.16.Sub Sort/README.md b/lcci/16.16.Sub Sort/README.md index 4453caf9a613c..3c50c224ffa77 100644 --- a/lcci/16.16.Sub Sort/README.md +++ b/lcci/16.16.Sub Sort/README.md @@ -42,6 +42,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/16.16.Sub%20Sort/READ +#### Python3 + ```python class Solution: def subSort(self, array: List[int]) -> List[int]: @@ -61,6 +63,8 @@ class Solution: return [left, right] ``` +#### Java + ```java class Solution { public int[] subSort(int[] array) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func subSort(array []int) []int { n := len(array) @@ -135,6 +143,8 @@ func subSort(array []int) []int { } ``` +#### TypeScript + ```ts function subSort(array: number[]): number[] { const n = array.length; @@ -158,6 +168,8 @@ function subSort(array: number[]): number[] { } ``` +#### Swift + ```swift class Solution { func subSort(_ array: [Int]) -> [Int] { diff --git a/lcci/16.16.Sub Sort/README_EN.md b/lcci/16.16.Sub Sort/README_EN.md index b235ea8b5c56f..46bc5feaf8d39 100644 --- a/lcci/16.16.Sub Sort/README_EN.md +++ b/lcci/16.16.Sub Sort/README_EN.md @@ -47,6 +47,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $array$. The +#### Python3 + ```python class Solution: def subSort(self, array: List[int]) -> List[int]: @@ -66,6 +68,8 @@ class Solution: return [left, right] ``` +#### Java + ```java class Solution { public int[] subSort(int[] array) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func subSort(array []int) []int { n := len(array) @@ -140,6 +148,8 @@ func subSort(array []int) []int { } ``` +#### TypeScript + ```ts function subSort(array: number[]): number[] { const n = array.length; @@ -163,6 +173,8 @@ function subSort(array: number[]): number[] { } ``` +#### Swift + ```swift class Solution { func subSort(_ array: [Int]) -> [Int] { diff --git a/lcci/16.17.Contiguous Sequence/README.md b/lcci/16.17.Contiguous Sequence/README.md index b99e31b9438a5..654b1462ed592 100644 --- a/lcci/16.17.Contiguous Sequence/README.md +++ b/lcci/16.17.Contiguous Sequence/README.md @@ -51,6 +51,8 @@ $$ +#### Python3 + ```python class Solution: def maxSubArray(self, nums: List[int]) -> int: @@ -61,6 +63,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxSubArray(int[] nums) { @@ -74,6 +78,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -88,6 +94,8 @@ public: }; ``` +#### Go + ```go func maxSubArray(nums []int) int { ans, f := math.MinInt32, math.MinInt32 @@ -99,6 +107,8 @@ func maxSubArray(nums []int) int { } ``` +#### TypeScript + ```ts function maxSubArray(nums: number[]): number { let [ans, f] = [-Infinity, -Infinity]; @@ -110,6 +120,8 @@ function maxSubArray(nums: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -125,6 +137,8 @@ var maxSubArray = function (nums) { }; ``` +#### Swift + ```swift class Solution { func maxSubArray(_ nums: [Int]) -> Int { diff --git a/lcci/16.17.Contiguous Sequence/README_EN.md b/lcci/16.17.Contiguous Sequence/README_EN.md index cdcb3bcf4f5ba..cb6d2a9acaf0a 100644 --- a/lcci/16.17.Contiguous Sequence/README_EN.md +++ b/lcci/16.17.Contiguous Sequence/README_EN.md @@ -64,6 +64,8 @@ We notice that $f[i]$ only depends on $f[i-1]$, so we can use a variable $f$ to +#### Python3 + ```python class Solution: def maxSubArray(self, nums: List[int]) -> int: @@ -74,6 +76,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxSubArray(int[] nums) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,6 +107,8 @@ public: }; ``` +#### Go + ```go func maxSubArray(nums []int) int { ans, f := math.MinInt32, math.MinInt32 @@ -112,6 +120,8 @@ func maxSubArray(nums []int) int { } ``` +#### TypeScript + ```ts function maxSubArray(nums: number[]): number { let [ans, f] = [-Infinity, -Infinity]; @@ -123,6 +133,8 @@ function maxSubArray(nums: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -138,6 +150,8 @@ var maxSubArray = function (nums) { }; ``` +#### Swift + ```swift class Solution { func maxSubArray(_ nums: [Int]) -> Int { diff --git a/lcci/16.18.Pattern Matching/README.md b/lcci/16.18.Pattern Matching/README.md index 34e10dda102ff..7c787b8fdd114 100644 --- a/lcci/16.18.Pattern Matching/README.md +++ b/lcci/16.18.Pattern Matching/README.md @@ -59,6 +59,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/16.18.Pattern%20Match +#### Python3 + ```python class Solution: def patternMatching(self, pattern: str, value: str) -> bool: @@ -94,6 +96,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { private String pattern; @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -209,6 +215,8 @@ public: }; ``` +#### Go + ```go func patternMatching(pattern string, value string) bool { cnt := [2]int{} @@ -257,6 +265,8 @@ func patternMatching(pattern string, value string) bool { } ``` +#### TypeScript + ```ts function patternMatching(pattern: string, value: string): boolean { const cnt: number[] = [0, 0]; @@ -304,6 +314,8 @@ function patternMatching(pattern: string, value: string): boolean { } ``` +#### Swift + ```swift class Solution { private var pattern: String = "" diff --git a/lcci/16.18.Pattern Matching/README_EN.md b/lcci/16.18.Pattern Matching/README_EN.md index 4ce63cf4a8c47..5289c97fb75c0 100644 --- a/lcci/16.18.Pattern Matching/README_EN.md +++ b/lcci/16.18.Pattern Matching/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$. Here, $n$ i +#### Python3 + ```python class Solution: def patternMatching(self, pattern: str, value: str) -> bool: @@ -111,6 +113,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { private String pattern; @@ -167,6 +171,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -226,6 +232,8 @@ public: }; ``` +#### Go + ```go func patternMatching(pattern string, value string) bool { cnt := [2]int{} @@ -274,6 +282,8 @@ func patternMatching(pattern string, value string) bool { } ``` +#### TypeScript + ```ts function patternMatching(pattern: string, value: string): boolean { const cnt: number[] = [0, 0]; @@ -321,6 +331,8 @@ function patternMatching(pattern: string, value: string): boolean { } ``` +#### Swift + ```swift class Solution { private var pattern: String = "" diff --git a/lcci/16.19.Pond Sizes/README.md b/lcci/16.19.Pond Sizes/README.md index 11cdf1514a376..66599a5437997 100644 --- a/lcci/16.19.Pond Sizes/README.md +++ b/lcci/16.19.Pond Sizes/README.md @@ -49,6 +49,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/16.19.Pond%20Sizes/RE +#### Python3 + ```python class Solution: def pondSizes(self, land: List[List[int]]) -> List[int]: @@ -65,6 +67,8 @@ class Solution: return sorted(dfs(i, j) for i in range(m) for j in range(n) if land[i][j] == 0) ``` +#### Java + ```java class Solution { private int m; @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func pondSizes(land [][]int) (ans []int) { m, n := len(land), len(land[0]) @@ -160,6 +168,8 @@ func pondSizes(land [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function pondSizes(land: number[][]): number[] { const m = land.length; @@ -189,6 +199,8 @@ function pondSizes(land: number[][]): number[] { } ``` +#### Swift + ```swift class Solution { private var m: Int = 0 diff --git a/lcci/16.19.Pond Sizes/README_EN.md b/lcci/16.19.Pond Sizes/README_EN.md index 156f6f269fd02..3f8fdacf45a15 100644 --- a/lcci/16.19.Pond Sizes/README_EN.md +++ b/lcci/16.19.Pond Sizes/README_EN.md @@ -63,6 +63,8 @@ The time complexity is $O(m \times n \times \log (m \times n))$, and the space c +#### Python3 + ```python class Solution: def pondSizes(self, land: List[List[int]]) -> List[int]: @@ -79,6 +81,8 @@ class Solution: return sorted(dfs(i, j) for i in range(m) for j in range(n) if land[i][j] == 0) ``` +#### Java + ```java class Solution { private int m; @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func pondSizes(land [][]int) (ans []int) { m, n := len(land), len(land[0]) @@ -174,6 +182,8 @@ func pondSizes(land [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function pondSizes(land: number[][]): number[] { const m = land.length; @@ -203,6 +213,8 @@ function pondSizes(land: number[][]): number[] { } ``` +#### Swift + ```swift class Solution { private var m: Int = 0 diff --git a/lcci/16.20.T9/README.md b/lcci/16.20.T9/README.md index b26b0a961c227..7f268be4c6e0e 100644 --- a/lcci/16.20.T9/README.md +++ b/lcci/16.20.T9/README.md @@ -47,6 +47,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/16.20.T9/README.md +#### Python3 + ```python class Solution: def getValidT9Words(self, num: str, words: List[str]) -> List[str]: @@ -57,6 +59,8 @@ class Solution: return [w for w in words if check(w)] ``` +#### Python3 + ```python class Solution: def getValidT9Words(self, num: str, words: List[str]) -> List[str]: @@ -64,6 +68,8 @@ class Solution: return [w for w in words if w.translate(trans) == num] ``` +#### Java + ```java class Solution { public List getValidT9Words(String num, String[] words) { @@ -91,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +126,8 @@ public: }; ``` +#### Go + ```go func getValidT9Words(num string, words []string) (ans []string) { s := "22233344455566677778889999" @@ -141,6 +151,8 @@ func getValidT9Words(num string, words []string) (ans []string) { } ``` +#### TypeScript + ```ts function getValidT9Words(num: string, words: string[]): string[] { const s = '22233344455566677778889999'; @@ -166,6 +178,8 @@ function getValidT9Words(num: string, words: string[]): string[] { } ``` +#### Swift + ```swift class Solution { func getValidT9Words(_ num: String, _ words: [String]) -> [String] { diff --git a/lcci/16.20.T9/README_EN.md b/lcci/16.20.T9/README_EN.md index 51dee3b912ad0..628ee5cc43918 100644 --- a/lcci/16.20.T9/README_EN.md +++ b/lcci/16.20.T9/README_EN.md @@ -55,6 +55,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(C)$. Here +#### Python3 + ```python class Solution: def getValidT9Words(self, num: str, words: List[str]) -> List[str]: @@ -65,6 +67,8 @@ class Solution: return [w for w in words if check(w)] ``` +#### Python3 + ```python class Solution: def getValidT9Words(self, num: str, words: List[str]) -> List[str]: @@ -72,6 +76,8 @@ class Solution: return [w for w in words if w.translate(trans) == num] ``` +#### Java + ```java class Solution { public List getValidT9Words(String num, String[] words) { @@ -99,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +134,8 @@ public: }; ``` +#### Go + ```go func getValidT9Words(num string, words []string) (ans []string) { s := "22233344455566677778889999" @@ -149,6 +159,8 @@ func getValidT9Words(num string, words []string) (ans []string) { } ``` +#### TypeScript + ```ts function getValidT9Words(num: string, words: string[]): string[] { const s = '22233344455566677778889999'; @@ -174,6 +186,8 @@ function getValidT9Words(num: string, words: string[]): string[] { } ``` +#### Swift + ```swift class Solution { func getValidT9Words(_ num: String, _ words: [String]) -> [String] { diff --git a/lcci/16.21.Sum Swap/README.md b/lcci/16.21.Sum Swap/README.md index 996c132b90b29..69fca06983e38 100644 --- a/lcci/16.21.Sum Swap/README.md +++ b/lcci/16.21.Sum Swap/README.md @@ -51,6 +51,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/16.21.Sum%20Swap/READ +#### Python3 + ```python class Solution: def findSwapValues(self, array1: List[int], array2: List[int]) -> List[int]: @@ -65,6 +67,8 @@ class Solution: return [] ``` +#### Java + ```java class Solution { public int[] findSwapValues(int[] array1, int[] array2) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func findSwapValues(array1 []int, array2 []int) []int { s1, s2 := 0, 0 @@ -141,6 +149,8 @@ func findSwapValues(array1 []int, array2 []int) []int { } ``` +#### TypeScript + ```ts function findSwapValues(array1: number[], array2: number[]): number[] { const s1 = array1.reduce((a, b) => a + b, 0); @@ -161,6 +171,8 @@ function findSwapValues(array1: number[], array2: number[]): number[] { } ``` +#### Swift + ```swift class Solution { func findSwapValues(_ array1: [Int], _ array2: [Int]) -> [Int] { diff --git a/lcci/16.21.Sum Swap/README_EN.md b/lcci/16.21.Sum Swap/README_EN.md index b19bf3c1ec57f..a5a1dd5ef8f3c 100644 --- a/lcci/16.21.Sum Swap/README_EN.md +++ b/lcci/16.21.Sum Swap/README_EN.md @@ -58,6 +58,8 @@ The time complexity is $O(m + n)$, and the space complexity is $O(n)$. Here, $m$ +#### Python3 + ```python class Solution: def findSwapValues(self, array1: List[int], array2: List[int]) -> List[int]: @@ -72,6 +74,8 @@ class Solution: return [] ``` +#### Java + ```java class Solution { public int[] findSwapValues(int[] array1, int[] array2) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func findSwapValues(array1 []int, array2 []int) []int { s1, s2 := 0, 0 @@ -148,6 +156,8 @@ func findSwapValues(array1 []int, array2 []int) []int { } ``` +#### TypeScript + ```ts function findSwapValues(array1: number[], array2: number[]): number[] { const s1 = array1.reduce((a, b) => a + b, 0); @@ -168,6 +178,8 @@ function findSwapValues(array1: number[], array2: number[]): number[] { } ``` +#### Swift + ```swift class Solution { func findSwapValues(_ array1: [Int], _ array2: [Int]) -> [Int] { diff --git a/lcci/16.22.Langtons Ant/README.md b/lcci/16.22.Langtons Ant/README.md index 0b357c3b8595c..62cb459c87180 100644 --- a/lcci/16.22.Langtons Ant/README.md +++ b/lcci/16.22.Langtons Ant/README.md @@ -63,6 +63,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/16.22.Langtons%20Ant/ +#### Python3 + ```python class Solution: def printKMoves(self, K: int) -> List[str]: @@ -93,6 +95,8 @@ class Solution: return ["".join(row) for row in g] ``` +#### Java + ```java class Solution { public List printKMoves(int K) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go func printKMoves(K int) []string { var x1, y1, x2, y2, x, y, p int @@ -218,6 +226,8 @@ func printKMoves(K int) []string { } ``` +#### Swift + ```swift class Solution { func printKMoves(_ K: Int) -> [String] { diff --git a/lcci/16.22.Langtons Ant/README_EN.md b/lcci/16.22.Langtons Ant/README_EN.md index 6a07d11045596..f1f998d73735e 100644 --- a/lcci/16.22.Langtons Ant/README_EN.md +++ b/lcci/16.22.Langtons Ant/README_EN.md @@ -85,6 +85,8 @@ The time complexity is $O(K)$, and the space complexity is $O(K)$. Where $K$ is +#### Python3 + ```python class Solution: def printKMoves(self, K: int) -> List[str]: @@ -115,6 +117,8 @@ class Solution: return ["".join(row) for row in g] ``` +#### Java + ```java class Solution { public List printKMoves(int K) { @@ -159,6 +163,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -195,6 +201,8 @@ public: }; ``` +#### Go + ```go func printKMoves(K int) []string { var x1, y1, x2, y2, x, y, p int @@ -240,6 +248,8 @@ func printKMoves(K int) []string { } ``` +#### Swift + ```swift class Solution { func printKMoves(_ K: Int) -> [String] { diff --git a/lcci/16.24.Pairs With Sum/README.md b/lcci/16.24.Pairs With Sum/README.md index 2a25112df483c..ef77ccc0aad41 100644 --- a/lcci/16.24.Pairs With Sum/README.md +++ b/lcci/16.24.Pairs With Sum/README.md @@ -44,6 +44,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/16.24.Pairs%20With%20 +#### Python3 + ```python class Solution: def pairSums(self, nums: List[int], target: int) -> List[List[int]]: @@ -59,6 +61,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> pairSums(int[] nums, int target) { @@ -80,6 +84,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -100,6 +106,8 @@ public: }; ``` +#### Go + ```go func pairSums(nums []int, target int) (ans [][]int) { cnt := map[int]int{} @@ -116,6 +124,8 @@ func pairSums(nums []int, target int) (ans [][]int) { } ``` +#### TypeScript + ```ts function pairSums(nums: number[], target: number): number[][] { const cnt = new Map(); @@ -138,6 +148,8 @@ function pairSums(nums: number[], target: number): number[][] { } ``` +#### Swift + ```swift class Solution { func pairSums(_ nums: [Int], _ target: Int) -> [[Int]] { diff --git a/lcci/16.24.Pairs With Sum/README_EN.md b/lcci/16.24.Pairs With Sum/README_EN.md index 4e844281dc4b6..d66fbeb683167 100644 --- a/lcci/16.24.Pairs With Sum/README_EN.md +++ b/lcci/16.24.Pairs With Sum/README_EN.md @@ -50,6 +50,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def pairSums(self, nums: List[int], target: int) -> List[List[int]]: @@ -65,6 +67,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> pairSums(int[] nums, int target) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func pairSums(nums []int, target int) (ans [][]int) { cnt := map[int]int{} @@ -122,6 +130,8 @@ func pairSums(nums []int, target int) (ans [][]int) { } ``` +#### TypeScript + ```ts function pairSums(nums: number[], target: number): number[][] { const cnt = new Map(); @@ -144,6 +154,8 @@ function pairSums(nums: number[], target: number): number[][] { } ``` +#### Swift + ```swift class Solution { func pairSums(_ nums: [Int], _ target: Int) -> [[Int]] { diff --git a/lcci/16.25.LRU Cache/README.md b/lcci/16.25.LRU Cache/README.md index 135c23da7b6ba..68f73a60b87bf 100644 --- a/lcci/16.25.LRU Cache/README.md +++ b/lcci/16.25.LRU Cache/README.md @@ -57,6 +57,8 @@ cache.get(4); // 返回 4 +#### Python3 + ```python class Node: def __init__(self, key=0, val=0): @@ -124,6 +126,8 @@ class LRUCache: # obj.put(key,value) ``` +#### Java + ```java class Node { int key; @@ -212,6 +216,8 @@ class LRUCache { */ ``` +#### C++ + ```cpp struct Node { int k; @@ -306,6 +312,8 @@ private: */ ``` +#### Go + ```go type node struct { key, val int @@ -377,6 +385,8 @@ func (this *LRUCache) pushFront(n *node) { } ``` +#### TypeScript + ```ts class LRUCache { capacity: number; @@ -413,6 +423,8 @@ class LRUCache { */ ``` +#### Rust + ```rust use std::cell::RefCell; use std::collections::HashMap; @@ -544,6 +556,8 @@ impl LRUCache { */ ``` +#### C# + ```cs public class LRUCache { class Node { @@ -623,6 +637,8 @@ public class LRUCache { */ ``` +#### Swift + ```swift class Node { var key: Int diff --git a/lcci/16.25.LRU Cache/README_EN.md b/lcci/16.25.LRU Cache/README_EN.md index 2e8d8d803e504..11e480ea76183 100644 --- a/lcci/16.25.LRU Cache/README_EN.md +++ b/lcci/16.25.LRU Cache/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(1)$, and the space complexity is $O(\text{capacity})$. +#### Python3 + ```python class Node: def __init__(self, key=0, val=0): @@ -138,6 +140,8 @@ class LRUCache: # obj.put(key,value) ``` +#### Java + ```java class Node { int key; @@ -226,6 +230,8 @@ class LRUCache { */ ``` +#### C++ + ```cpp struct Node { int k; @@ -320,6 +326,8 @@ private: */ ``` +#### Go + ```go type node struct { key, val int @@ -391,6 +399,8 @@ func (this *LRUCache) pushFront(n *node) { } ``` +#### TypeScript + ```ts class LRUCache { capacity: number; @@ -427,6 +437,8 @@ class LRUCache { */ ``` +#### Rust + ```rust use std::cell::RefCell; use std::collections::HashMap; @@ -558,6 +570,8 @@ impl LRUCache { */ ``` +#### C# + ```cs public class LRUCache { class Node { @@ -637,6 +651,8 @@ public class LRUCache { */ ``` +#### Swift + ```swift class Node { var key: Int diff --git a/lcci/16.26.Calculator/README.md b/lcci/16.26.Calculator/README.md index dfd063fa7896d..e022010f5d781 100644 --- a/lcci/16.26.Calculator/README.md +++ b/lcci/16.26.Calculator/README.md @@ -49,6 +49,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/16.26.Calculator/READ +#### Python3 + ```python class Solution: def calculate(self, s: str) -> int: @@ -74,6 +76,8 @@ class Solution: return sum(stk) ``` +#### Java + ```java class Solution { public int calculate(String s) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func calculate(s string) (ans int) { n := len(s) @@ -179,6 +187,8 @@ func calculate(s string) (ans int) { } ``` +#### TypeScript + ```ts function calculate(s: string): number { const n = s.length; @@ -211,6 +221,8 @@ function calculate(s: string): number { } ``` +#### Swift + ```swift class Solution { func calculate(_ s: String) -> Int { diff --git a/lcci/16.26.Calculator/README_EN.md b/lcci/16.26.Calculator/README_EN.md index b5ca11f70a408..f25242db32248 100644 --- a/lcci/16.26.Calculator/README_EN.md +++ b/lcci/16.26.Calculator/README_EN.md @@ -61,6 +61,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def calculate(self, s: str) -> int: @@ -86,6 +88,8 @@ class Solution: return sum(stk) ``` +#### Java + ```java class Solution { public int calculate(String s) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func calculate(s string) (ans int) { n := len(s) @@ -191,6 +199,8 @@ func calculate(s string) (ans int) { } ``` +#### TypeScript + ```ts function calculate(s: string): number { const n = s.length; @@ -223,6 +233,8 @@ function calculate(s: string): number { } ``` +#### Swift + ```swift class Solution { func calculate(_ s: String) -> Int { diff --git a/lcci/17.01.Add Without Plus/README.md b/lcci/17.01.Add Without Plus/README.md index 816e7992c1dd1..469ed43fffa66 100644 --- a/lcci/17.01.Add Without Plus/README.md +++ b/lcci/17.01.Add Without Plus/README.md @@ -40,6 +40,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.01.Add%20Without%2 +#### Java + ```java class Solution { public int add(int a, int b) { @@ -55,6 +57,8 @@ class Solution { } ``` +#### Swift + ```swift class Solution { func add(_ a: Int, _ b: Int) -> Int { diff --git a/lcci/17.01.Add Without Plus/README_EN.md b/lcci/17.01.Add Without Plus/README_EN.md index 178e042c6e117..b15687a7891a3 100644 --- a/lcci/17.01.Add Without Plus/README_EN.md +++ b/lcci/17.01.Add Without Plus/README_EN.md @@ -43,6 +43,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.01.Add%20Without%2 +#### Java + ```java class Solution { public int add(int a, int b) { @@ -58,6 +60,8 @@ class Solution { } ``` +#### Swift + ```swift class Solution { func add(_ a: Int, _ b: Int) -> Int { diff --git a/lcci/17.04.Missing Number/README.md b/lcci/17.04.Missing Number/README.md index a6048b1b544bc..2428ce6142b9e 100644 --- a/lcci/17.04.Missing Number/README.md +++ b/lcci/17.04.Missing Number/README.md @@ -47,6 +47,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.04.Missing%20Numbe +#### Python3 + ```python class Solution: def missingNumber(self, nums: List[int]) -> int: @@ -57,6 +59,8 @@ class Solution: return len(nums) ``` +#### Java + ```java class Solution { public int missingNumber(int[] nums) { @@ -72,6 +76,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -88,6 +94,8 @@ public: }; ``` +#### Go + ```go func missingNumber(nums []int) int { sort.Ints(nums) @@ -100,6 +108,8 @@ func missingNumber(nums []int) int { } ``` +#### Rust + ```rust impl Solution { pub fn missing_number(mut nums: Vec) -> i32 { @@ -115,6 +125,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -132,6 +144,8 @@ var missingNumber = function (nums) { }; ``` +#### Swift + ```swift class Solution { func missingNumber(_ nums: [Int]) -> Int { @@ -160,12 +174,16 @@ class Solution { +#### Python3 + ```python class Solution: def missingNumber(self, nums: List[int]) -> int: return sum(range(len(nums) + 1)) - sum(nums) ``` +#### Java + ```java class Solution { public int missingNumber(int[] nums) { @@ -179,6 +197,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -193,6 +213,8 @@ public: }; ``` +#### Go + ```go func missingNumber(nums []int) (ans int) { ans = len(nums) @@ -203,6 +225,8 @@ func missingNumber(nums []int) (ans int) { } ``` +#### Rust + ```rust impl Solution { pub fn missing_number(nums: Vec) -> i32 { @@ -222,6 +246,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -237,6 +263,8 @@ var missingNumber = function (nums) { }; ``` +#### Swift + ```swift class Solution { func missingNumber(_ nums: [Int]) -> Int { @@ -260,6 +288,8 @@ class Solution { +#### Python3 + ```python class Solution: def missingNumber(self, nums: List[int]) -> int: @@ -269,6 +299,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int missingNumber(int[] nums) { @@ -281,6 +313,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -294,6 +328,8 @@ public: }; ``` +#### Go + ```go func missingNumber(nums []int) (ans int) { for i, x := range nums { @@ -303,6 +339,8 @@ func missingNumber(nums []int) (ans int) { } ``` +#### Rust + ```rust impl Solution { pub fn missing_number(nums: Vec) -> i32 { @@ -316,6 +354,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/lcci/17.04.Missing Number/README_EN.md b/lcci/17.04.Missing Number/README_EN.md index 38f81c1710695..dcfba18b1ccb4 100644 --- a/lcci/17.04.Missing Number/README_EN.md +++ b/lcci/17.04.Missing Number/README_EN.md @@ -48,6 +48,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.04.Missing%20Numbe +#### Python3 + ```python class Solution: def missingNumber(self, nums: List[int]) -> int: @@ -58,6 +60,8 @@ class Solution: return len(nums) ``` +#### Java + ```java class Solution { public int missingNumber(int[] nums) { @@ -73,6 +77,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -89,6 +95,8 @@ public: }; ``` +#### Go + ```go func missingNumber(nums []int) int { sort.Ints(nums) @@ -101,6 +109,8 @@ func missingNumber(nums []int) int { } ``` +#### Rust + ```rust impl Solution { pub fn missing_number(mut nums: Vec) -> i32 { @@ -116,6 +126,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -133,6 +145,8 @@ var missingNumber = function (nums) { }; ``` +#### Swift + ```swift class Solution { func missingNumber(_ nums: [Int]) -> Int { @@ -157,12 +171,16 @@ class Solution { +#### Python3 + ```python class Solution: def missingNumber(self, nums: List[int]) -> int: return sum(range(len(nums) + 1)) - sum(nums) ``` +#### Java + ```java class Solution { public int missingNumber(int[] nums) { @@ -176,6 +194,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -190,6 +210,8 @@ public: }; ``` +#### Go + ```go func missingNumber(nums []int) (ans int) { ans = len(nums) @@ -200,6 +222,8 @@ func missingNumber(nums []int) (ans int) { } ``` +#### Rust + ```rust impl Solution { pub fn missing_number(nums: Vec) -> i32 { @@ -219,6 +243,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -234,6 +260,8 @@ var missingNumber = function (nums) { }; ``` +#### Swift + ```swift class Solution { func missingNumber(_ nums: [Int]) -> Int { @@ -253,6 +281,8 @@ class Solution { +#### Python3 + ```python class Solution: def missingNumber(self, nums: List[int]) -> int: @@ -262,6 +292,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int missingNumber(int[] nums) { @@ -274,6 +306,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -287,6 +321,8 @@ public: }; ``` +#### Go + ```go func missingNumber(nums []int) (ans int) { for i, x := range nums { @@ -296,6 +332,8 @@ func missingNumber(nums []int) (ans int) { } ``` +#### Rust + ```rust impl Solution { pub fn missing_number(nums: Vec) -> i32 { @@ -309,6 +347,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/lcci/17.05.Find Longest Subarray/README.md b/lcci/17.05.Find Longest Subarray/README.md index 076a25212cd65..34cd108dd4e9b 100644 --- a/lcci/17.05.Find Longest Subarray/README.md +++ b/lcci/17.05.Find Longest Subarray/README.md @@ -61,6 +61,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.05.Find%20Longest% +#### Python3 + ```python class Solution: def findLongestSubarray(self, array: List[str]) -> List[str]: @@ -77,6 +79,8 @@ class Solution: return array[k : k + mx] ``` +#### Java + ```java class Solution { public String[] findLongestSubarray(String[] array) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func findLongestSubarray(array []string) []string { vis := map[int]int{0: -1} @@ -148,6 +156,8 @@ func findLongestSubarray(array []string) []string { } ``` +#### TypeScript + ```ts function findLongestSubarray(array: string[]): string[] { const vis = new Map(); @@ -171,6 +181,8 @@ function findLongestSubarray(array: string[]): string[] { } ``` +#### Swift + ```swift class Solution { func findLongestSubarray(_ array: [String]) -> [String] { diff --git a/lcci/17.05.Find Longest Subarray/README_EN.md b/lcci/17.05.Find Longest Subarray/README_EN.md index 4964a67ed6185..f5592ba586ae8 100644 --- a/lcci/17.05.Find Longest Subarray/README_EN.md +++ b/lcci/17.05.Find Longest Subarray/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def findLongestSubarray(self, array: List[str]) -> List[str]: @@ -87,6 +89,8 @@ class Solution: return array[k : k + mx] ``` +#### Java + ```java class Solution { public String[] findLongestSubarray(String[] array) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func findLongestSubarray(array []string) []string { vis := map[int]int{0: -1} @@ -158,6 +166,8 @@ func findLongestSubarray(array []string) []string { } ``` +#### TypeScript + ```ts function findLongestSubarray(array: string[]): string[] { const vis = new Map(); @@ -181,6 +191,8 @@ function findLongestSubarray(array: string[]): string[] { } ``` +#### Swift + ```swift class Solution { func findLongestSubarray(_ array: [String]) -> [String] { diff --git a/lcci/17.06.Number Of 2s In Range/README.md b/lcci/17.06.Number Of 2s In Range/README.md index 09b1ef0def116..1a8145049ef9f 100644 --- a/lcci/17.06.Number Of 2s In Range/README.md +++ b/lcci/17.06.Number Of 2s In Range/README.md @@ -65,6 +65,8 @@ $$ +#### Python3 + ```python class Solution: def numberOf2sInRange(self, n: int) -> int: @@ -87,6 +89,8 @@ class Solution: return dfs(l, 0, True) ``` +#### Java + ```java class Solution { private int[] a = new int[12]; @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func numberOf2sInRange(n int) int { a := make([]int, 12) @@ -205,6 +213,8 @@ func numberOf2sInRange(n int) int { } ``` +#### Swift + ```swift class Solution { private var a = [Int](repeating: 0, count: 12) diff --git a/lcci/17.06.Number Of 2s In Range/README_EN.md b/lcci/17.06.Number Of 2s In Range/README_EN.md index 7b2c0b40bb79f..ecafbe3f10e8d 100644 --- a/lcci/17.06.Number Of 2s In Range/README_EN.md +++ b/lcci/17.06.Number Of 2s In Range/README_EN.md @@ -70,6 +70,8 @@ Similar problems: +#### Python3 + ```python class Solution: def numberOf2sInRange(self, n: int) -> int: @@ -92,6 +94,8 @@ class Solution: return dfs(l, 0, True) ``` +#### Java + ```java class Solution { private int[] a = new int[12]; @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func numberOf2sInRange(n int) int { a := make([]int, 12) @@ -210,6 +218,8 @@ func numberOf2sInRange(n int) int { } ``` +#### Swift + ```swift class Solution { private var a = [Int](repeating: 0, count: 12) diff --git a/lcci/17.07.Baby Names/README.md b/lcci/17.07.Baby Names/README.md index 8dedd1ca47940..e2ae4ace0fc86 100644 --- a/lcci/17.07.Baby Names/README.md +++ b/lcci/17.07.Baby Names/README.md @@ -47,6 +47,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.07.Baby%20Names/RE +#### Python3 + ```python class Solution: def trulyMostPopular(self, names: List[str], synonyms: List[str]) -> List[str]: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private Map> g = new HashMap<>(); @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func trulyMostPopular(names []string, synonyms []string) (ans []string) { g := map[string][]string{} @@ -227,6 +235,8 @@ func trulyMostPopular(names []string, synonyms []string) (ans []string) { } ``` +#### TypeScript + ```ts function trulyMostPopular(names: string[], synonyms: string[]): string[] { const map = new Map(); @@ -258,6 +268,8 @@ function trulyMostPopular(names: string[], synonyms: string[]): string[] { } ``` +#### Swift + ```swift class Solution { private var graph = [String: [String]]() diff --git a/lcci/17.07.Baby Names/README_EN.md b/lcci/17.07.Baby Names/README_EN.md index 9b561e7d77ebb..a74f1e5fc229d 100644 --- a/lcci/17.07.Baby Names/README_EN.md +++ b/lcci/17.07.Baby Names/README_EN.md @@ -48,6 +48,8 @@ The time complexity is $O(n + m)$, and the space complexity is $O(n + m)$. Where +#### Python3 + ```python class Solution: def trulyMostPopular(self, names: List[str], synonyms: List[str]) -> List[str]: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private Map> g = new HashMap<>(); @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -182,6 +188,8 @@ public: }; ``` +#### Go + ```go func trulyMostPopular(names []string, synonyms []string) (ans []string) { g := map[string][]string{} @@ -228,6 +236,8 @@ func trulyMostPopular(names []string, synonyms []string) (ans []string) { } ``` +#### TypeScript + ```ts function trulyMostPopular(names: string[], synonyms: string[]): string[] { const map = new Map(); @@ -259,6 +269,8 @@ function trulyMostPopular(names: string[], synonyms: string[]): string[] { } ``` +#### Swift + ```swift class Solution { private var graph = [String: [String]]() diff --git a/lcci/17.08.Circus Tower/README.md b/lcci/17.08.Circus Tower/README.md index 960e191ab3daf..8ddcf3f528408 100644 --- a/lcci/17.08.Circus Tower/README.md +++ b/lcci/17.08.Circus Tower/README.md @@ -40,6 +40,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.08.Circus%20Tower/ +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -75,6 +77,8 @@ class Solution: return ans ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -191,6 +197,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -251,6 +259,8 @@ func bestSeqAtIndex(height []int, weight []int) int { } ``` +#### Swift + ```swift class BinaryIndexedTree { private var n: Int diff --git a/lcci/17.08.Circus Tower/README_EN.md b/lcci/17.08.Circus Tower/README_EN.md index 6631db764bb1c..8fd1a5b415fc2 100644 --- a/lcci/17.08.Circus Tower/README_EN.md +++ b/lcci/17.08.Circus Tower/README_EN.md @@ -45,6 +45,8 @@ The space complexity is $O(n)$, where $n$ is the number of people. +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -196,6 +202,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -256,6 +264,8 @@ func bestSeqAtIndex(height []int, weight []int) int { } ``` +#### Swift + ```swift class BinaryIndexedTree { private var n: Int diff --git a/lcci/17.09.Get Kth Magic Number/README.md b/lcci/17.09.Get Kth Magic Number/README.md index 056ca0eb86c5d..e371a07596055 100644 --- a/lcci/17.09.Get Kth Magic Number/README.md +++ b/lcci/17.09.Get Kth Magic Number/README.md @@ -36,6 +36,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.09.Get%20Kth%20Mag +#### Python3 + ```python class Solution: def getKthMagicNumber(self, k: int) -> int: @@ -50,6 +52,8 @@ class Solution: return h[0] ``` +#### Java + ```java class Solution { private static final int[] FACTORS = new int[] {3, 5, 7}; @@ -75,6 +79,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,6 +107,8 @@ public: }; ``` +#### Go + ```go func getKthMagicNumber(k int) int { q := hp{[]int{1}} @@ -129,6 +137,8 @@ func (h *hp) Pop() any { } ``` +#### TypeScript + ```ts function getKthMagicNumber(k: number): number { const dp = [1]; @@ -153,6 +163,8 @@ function getKthMagicNumber(k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn get_kth_magic_number(k: i32) -> i32 { @@ -180,6 +192,8 @@ impl Solution { } ``` +#### C + ```c #define min(a, b) (((a) < (b)) ? (a) : (b)) @@ -209,6 +223,8 @@ int getKthMagicNumber(int k) { } ``` +#### Swift + ```swift class Solution { private let factors = [3, 5, 7] @@ -255,6 +271,8 @@ class Solution { +#### Python3 + ```python class Solution: def getKthMagicNumber(self, k: int) -> int: @@ -273,6 +291,8 @@ class Solution: return dp[k] ``` +#### Java + ```java class Solution { public int getKthMagicNumber(int k) { @@ -298,6 +318,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -323,6 +345,8 @@ public: }; ``` +#### Go + ```go func getKthMagicNumber(k int) int { dp := make([]int, k+1) diff --git a/lcci/17.09.Get Kth Magic Number/README_EN.md b/lcci/17.09.Get Kth Magic Number/README_EN.md index b2abf23aee769..a2e451172c0f1 100644 --- a/lcci/17.09.Get Kth Magic Number/README_EN.md +++ b/lcci/17.09.Get Kth Magic Number/README_EN.md @@ -32,6 +32,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.09.Get%20Kth%20Mag +#### Python3 + ```python class Solution: def getKthMagicNumber(self, k: int) -> int: @@ -46,6 +48,8 @@ class Solution: return h[0] ``` +#### Java + ```java class Solution { private static final int[] FACTORS = new int[] {3, 5, 7}; @@ -71,6 +75,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -97,6 +103,8 @@ public: }; ``` +#### Go + ```go func getKthMagicNumber(k int) int { q := hp{[]int{1}} @@ -125,6 +133,8 @@ func (h *hp) Pop() any { } ``` +#### TypeScript + ```ts function getKthMagicNumber(k: number): number { const dp = [1]; @@ -149,6 +159,8 @@ function getKthMagicNumber(k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn get_kth_magic_number(k: i32) -> i32 { @@ -176,6 +188,8 @@ impl Solution { } ``` +#### C + ```c #define min(a, b) (((a) < (b)) ? (a) : (b)) @@ -205,6 +219,8 @@ int getKthMagicNumber(int k) { } ``` +#### Swift + ```swift class Solution { private let factors = [3, 5, 7] @@ -241,6 +257,8 @@ class Solution { +#### Python3 + ```python class Solution: def getKthMagicNumber(self, k: int) -> int: @@ -259,6 +277,8 @@ class Solution: return dp[k] ``` +#### Java + ```java class Solution { public int getKthMagicNumber(int k) { @@ -284,6 +304,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -309,6 +331,8 @@ public: }; ``` +#### Go + ```go func getKthMagicNumber(k int) int { dp := make([]int, k+1) diff --git a/lcci/17.10.Find Majority Element/README.md b/lcci/17.10.Find Majority Element/README.md index 2068759ac8f1e..2f135f584ff41 100644 --- a/lcci/17.10.Find Majority Element/README.md +++ b/lcci/17.10.Find Majority Element/README.md @@ -62,6 +62,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.10.Find%20Majority +#### Python3 + ```python class Solution: def majorityElement(self, nums: List[int]) -> int: @@ -74,6 +76,8 @@ class Solution: return m if nums.count(m) > len(nums) // 2 else -1 ``` +#### Java + ```java class Solution { public int majorityElement(int[] nums) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func majorityElement(nums []int) int { cnt, m := 0, 0 @@ -142,6 +150,8 @@ func majorityElement(nums []int) int { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -168,6 +178,8 @@ var majorityElement = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int MajorityElement(int[] nums) { @@ -197,6 +209,8 @@ public class Solution { } ``` +#### Swift + ```swift class Solution { func majorityElement(_ nums: [Int]) -> Int { diff --git a/lcci/17.10.Find Majority Element/README_EN.md b/lcci/17.10.Find Majority Element/README_EN.md index b7edb47766472..78a4b029f2cb8 100644 --- a/lcci/17.10.Find Majority Element/README_EN.md +++ b/lcci/17.10.Find Majority Element/README_EN.md @@ -56,6 +56,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.10.Find%20Majority +#### Python3 + ```python class Solution: def majorityElement(self, nums: List[int]) -> int: @@ -68,6 +70,8 @@ class Solution: return m if nums.count(m) > len(nums) // 2 else -1 ``` +#### Java + ```java class Solution { public int majorityElement(int[] nums) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func majorityElement(nums []int) int { cnt, m := 0, 0 @@ -136,6 +144,8 @@ func majorityElement(nums []int) int { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -162,6 +172,8 @@ var majorityElement = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int MajorityElement(int[] nums) { @@ -191,6 +203,8 @@ public class Solution { } ``` +#### Swift + ```swift class Solution { func majorityElement(_ nums: [Int]) -> Int { diff --git a/lcci/17.11.Find Closest/README.md b/lcci/17.11.Find Closest/README.md index 26fe5a11b750d..a3175596b5ca2 100644 --- a/lcci/17.11.Find Closest/README.md +++ b/lcci/17.11.Find Closest/README.md @@ -45,6 +45,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.11.Find%20Closest/ +#### Python3 + ```python class Solution: def findClosest(self, words: List[str], word1: str, word2: str) -> int: @@ -59,6 +61,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findClosest(String[] words, String word1, String word2) { @@ -77,6 +81,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -97,6 +103,8 @@ public: }; ``` +#### Go + ```go func findClosest(words []string, word1 string, word2 string) int { const inf int = 1 << 29 @@ -113,6 +121,8 @@ func findClosest(words []string, word1 string, word2 string) int { } ``` +#### TypeScript + ```ts function findClosest(words: string[], word1: string, word2: string): number { let [i, j, ans] = [Infinity, -Infinity, Infinity]; @@ -128,6 +138,8 @@ function findClosest(words: string[], word1: string, word2: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_closest(words: Vec, word1: String, word2: String) -> i32 { @@ -150,6 +162,8 @@ impl Solution { } ``` +#### Swift + ```swift class Solution { func findClosest(_ words: [String], _ word1: String, _ word2: String) -> Int { @@ -192,6 +206,8 @@ class Solution { +#### Python3 + ```python class Solution: def findClosest(self, words: List[str], word1: str, word2: str) -> int: @@ -210,6 +226,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findClosest(String[] words, String word1, String word2) { @@ -234,6 +252,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -259,6 +279,8 @@ public: }; ``` +#### Go + ```go func findClosest(words []string, word1 string, word2 string) int { d := map[string][]int{} @@ -283,6 +305,8 @@ func findClosest(words []string, word1 string, word2 string) int { } ``` +#### TypeScript + ```ts function findClosest(words: string[], word1: string, word2: string): number { const d: Map = new Map(); diff --git a/lcci/17.11.Find Closest/README_EN.md b/lcci/17.11.Find Closest/README_EN.md index 93bb431c2b3ee..740311454901a 100644 --- a/lcci/17.11.Find Closest/README_EN.md +++ b/lcci/17.11.Find Closest/README_EN.md @@ -48,6 +48,8 @@ The time complexity is $O(n)$, where $n$ is the number of words in the text file +#### Python3 + ```python class Solution: def findClosest(self, words: List[str], word1: str, word2: str) -> int: @@ -62,6 +64,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findClosest(String[] words, String word1, String word2) { @@ -80,6 +84,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -100,6 +106,8 @@ public: }; ``` +#### Go + ```go func findClosest(words []string, word1 string, word2 string) int { const inf int = 1 << 29 @@ -116,6 +124,8 @@ func findClosest(words []string, word1 string, word2 string) int { } ``` +#### TypeScript + ```ts function findClosest(words: string[], word1: string, word2: string): number { let [i, j, ans] = [Infinity, -Infinity, Infinity]; @@ -131,6 +141,8 @@ function findClosest(words: string[], word1: string, word2: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_closest(words: Vec, word1: String, word2: String) -> i32 { @@ -153,6 +165,8 @@ impl Solution { } ``` +#### Swift + ```swift class Solution { func findClosest(_ words: [String], _ word1: String, _ word2: String) -> Int { @@ -195,6 +209,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def findClosest(self, words: List[str], word1: str, word2: str) -> int: @@ -213,6 +229,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findClosest(String[] words, String word1, String word2) { @@ -237,6 +255,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -262,6 +282,8 @@ public: }; ``` +#### Go + ```go func findClosest(words []string, word1 string, word2 string) int { d := map[string][]int{} @@ -286,6 +308,8 @@ func findClosest(words []string, word1 string, word2 string) int { } ``` +#### TypeScript + ```ts function findClosest(words: string[], word1: string, word2: string): number { const d: Map = new Map(); diff --git a/lcci/17.12.BiNode/README.md b/lcci/17.12.BiNode/README.md index 937d8fae18580..5de418f544c70 100644 --- a/lcci/17.12.BiNode/README.md +++ b/lcci/17.12.BiNode/README.md @@ -50,6 +50,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.12.BiNode/README.m +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -77,6 +79,8 @@ class Solution: return dummy.right ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -170,6 +178,8 @@ func convertBiNode(root *TreeNode) *TreeNode { } ``` +#### JavaScript + ```js const convertBiNode = root => { const dfs = root => { diff --git a/lcci/17.12.BiNode/README_EN.md b/lcci/17.12.BiNode/README_EN.md index c7fa5da0fcb16..44db3ef177d33 100644 --- a/lcci/17.12.BiNode/README_EN.md +++ b/lcci/17.12.BiNode/README_EN.md @@ -48,6 +48,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.12.BiNode/README_E +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -75,6 +77,8 @@ class Solution: return dummy.right ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -168,6 +176,8 @@ func convertBiNode(root *TreeNode) *TreeNode { } ``` +#### JavaScript + ```js const convertBiNode = root => { const dfs = root => { diff --git a/lcci/17.13.Re-Space/README.md b/lcci/17.13.Re-Space/README.md index 2ce510955b7ce..4e74315168efa 100644 --- a/lcci/17.13.Re-Space/README.md +++ b/lcci/17.13.Re-Space/README.md @@ -47,6 +47,8 @@ sentence = "jesslookedjustliketimherbrother" +#### Python3 + ```python class Solution: def respace(self, dictionary: List[str], sentence: str) -> int: @@ -61,6 +63,8 @@ class Solution: return dp[-1] ``` +#### Java + ```java class Solution { public int respace(String[] dictionary, String sentence) { @@ -80,6 +84,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -100,6 +106,8 @@ public: }; ``` +#### Go + ```go func respace(dictionary []string, sentence string) int { s := map[string]bool{} @@ -120,6 +128,8 @@ func respace(dictionary []string, sentence string) int { } ``` +#### Swift + ```swift class TrieNode { var children: [TrieNode?] = Array(repeating: nil, count: 26) diff --git a/lcci/17.13.Re-Space/README_EN.md b/lcci/17.13.Re-Space/README_EN.md index 4d83a5dd9c5fb..75f3ca3c62f26 100644 --- a/lcci/17.13.Re-Space/README_EN.md +++ b/lcci/17.13.Re-Space/README_EN.md @@ -54,6 +54,8 @@ sentence = "jesslookedjustliketimherbrother" +#### Python3 + ```python class Solution: def respace(self, dictionary: List[str], sentence: str) -> int: @@ -68,6 +70,8 @@ class Solution: return dp[-1] ``` +#### Java + ```java class Solution { public int respace(String[] dictionary, String sentence) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func respace(dictionary []string, sentence string) int { s := map[string]bool{} @@ -127,6 +135,8 @@ func respace(dictionary []string, sentence string) int { } ``` +#### Swift + ```swift class TrieNode { var children: [TrieNode?] = Array(repeating: nil, count: 26) diff --git a/lcci/17.14.Smallest K/README.md b/lcci/17.14.Smallest K/README.md index ec2df13e71788..2c402107c0c43 100644 --- a/lcci/17.14.Smallest K/README.md +++ b/lcci/17.14.Smallest K/README.md @@ -39,12 +39,16 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.14.Smallest%20K/RE +#### Python3 + ```python class Solution: def smallestK(self, arr: List[int], k: int) -> List[int]: return sorted(arr)[:k] ``` +#### Java + ```java class Solution { public int[] smallestK(int[] arr, int k) { @@ -58,6 +62,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -72,6 +78,8 @@ public: }; ``` +#### Go + ```go func smallestK(arr []int, k int) []int { sort.Ints(arr) @@ -83,6 +91,8 @@ func smallestK(arr []int, k int) []int { } ``` +#### Swift + ```swift class Solution { func smallestK(_ arr: [Int], _ k: Int) -> [Int] { @@ -109,6 +119,8 @@ class Solution { +#### Python3 + ```python class Solution: def smallestK(self, arr: List[int], k: int) -> List[int]: @@ -120,6 +132,8 @@ class Solution: return [-v for v in h] ``` +#### Java + ```java class Solution { public int[] smallestK(int[] arr, int k) { @@ -140,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +177,8 @@ public: }; ``` +#### Go + ```go func smallestK(arr []int, k int) []int { q := hp{} diff --git a/lcci/17.14.Smallest K/README_EN.md b/lcci/17.14.Smallest K/README_EN.md index 7fb1da91169cb..c34daf8e12ab1 100644 --- a/lcci/17.14.Smallest K/README_EN.md +++ b/lcci/17.14.Smallest K/README_EN.md @@ -39,12 +39,16 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.14.Smallest%20K/RE +#### Python3 + ```python class Solution: def smallestK(self, arr: List[int], k: int) -> List[int]: return sorted(arr)[:k] ``` +#### Java + ```java class Solution { public int[] smallestK(int[] arr, int k) { @@ -58,6 +62,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -72,6 +78,8 @@ public: }; ``` +#### Go + ```go func smallestK(arr []int, k int) []int { sort.Ints(arr) @@ -83,6 +91,8 @@ func smallestK(arr []int, k int) []int { } ``` +#### Swift + ```swift class Solution { func smallestK(_ arr: [Int], _ k: Int) -> [Int] { @@ -103,6 +113,8 @@ class Solution { +#### Python3 + ```python class Solution: def smallestK(self, arr: List[int], k: int) -> List[int]: @@ -114,6 +126,8 @@ class Solution: return [-v for v in h] ``` +#### Java + ```java class Solution { public int[] smallestK(int[] arr, int k) { @@ -134,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +171,8 @@ public: }; ``` +#### Go + ```go func smallestK(arr []int, k int) []int { q := hp{} diff --git a/lcci/17.15.Longest Word/README.md b/lcci/17.15.Longest Word/README.md index d1123e0736604..a9840705c9c6a 100644 --- a/lcci/17.15.Longest Word/README.md +++ b/lcci/17.15.Longest Word/README.md @@ -36,6 +36,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.15.Longest%20Word/ +#### Python3 + ```python class Trie: def __init__(self): @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Trie { Trie[] children = new Trie[26]; @@ -147,6 +151,8 @@ class Solution { } ``` +#### Go + ```go type Trie struct { children [26]*Trie @@ -212,6 +218,8 @@ func longestWord(words []string) string { } ``` +#### Swift + ```swift class Trie { var children = [Trie?](repeating: nil, count: 26) diff --git a/lcci/17.15.Longest Word/README_EN.md b/lcci/17.15.Longest Word/README_EN.md index fa339920b2f71..7d5dcf7f14dec 100644 --- a/lcci/17.15.Longest Word/README_EN.md +++ b/lcci/17.15.Longest Word/README_EN.md @@ -45,6 +45,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.15.Longest%20Word/ +#### Python3 + ```python class Trie: def __init__(self): @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Trie { Trie[] children = new Trie[26]; @@ -156,6 +160,8 @@ class Solution { } ``` +#### Go + ```go type Trie struct { children [26]*Trie @@ -221,6 +227,8 @@ func longestWord(words []string) string { } ``` +#### Swift + ```swift class Trie { var children = [Trie?](repeating: nil, count: 26) diff --git a/lcci/17.16.The Masseuse/README.md b/lcci/17.16.The Masseuse/README.md index da59857ee2eeb..77381b986b5f1 100644 --- a/lcci/17.16.The Masseuse/README.md +++ b/lcci/17.16.The Masseuse/README.md @@ -68,6 +68,8 @@ $$ +#### Python3 + ```python class Solution: def massage(self, nums: List[int]) -> int: @@ -77,6 +79,8 @@ class Solution: return max(f, g) ``` +#### Java + ```java class Solution { public int massage(int[] nums) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func massage(nums []int) int { f, g := 0, 0 @@ -118,6 +126,8 @@ func massage(nums []int) int { } ``` +#### TypeScript + ```ts function massage(nums: number[]): number { let f = 0, @@ -132,6 +142,8 @@ function massage(nums: number[]): number { } ``` +#### Swift + ```swift class Solution { func massage(_ nums: [Int]) -> Int { diff --git a/lcci/17.16.The Masseuse/README_EN.md b/lcci/17.16.The Masseuse/README_EN.md index 7d610aab3e408..3cd144a22a3a8 100644 --- a/lcci/17.16.The Masseuse/README_EN.md +++ b/lcci/17.16.The Masseuse/README_EN.md @@ -66,6 +66,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.16.The%20Masseuse/ +#### Python3 + ```python class Solution: def massage(self, nums: List[int]) -> int: @@ -75,6 +77,8 @@ class Solution: return max(f, g) ``` +#### Java + ```java class Solution { public int massage(int[] nums) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func massage(nums []int) int { f, g := 0, 0 @@ -116,6 +124,8 @@ func massage(nums []int) int { } ``` +#### TypeScript + ```ts function massage(nums: number[]): number { let f = 0, @@ -130,6 +140,8 @@ function massage(nums: number[]): number { } ``` +#### Swift + ```swift class Solution { func massage(_ nums: [Int]) -> Int { diff --git a/lcci/17.17.Multi Search/README.md b/lcci/17.17.Multi Search/README.md index f102467480e66..55074dc86014c 100644 --- a/lcci/17.17.Multi Search/README.md +++ b/lcci/17.17.Multi Search/README.md @@ -44,6 +44,8 @@ smalls = ["is","ppi","hi","sis","i& +#### Python3 + ```python class Trie: def __init__(self): @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] multiSearch(String big, String[] smalls) { @@ -152,6 +156,8 @@ class Trie { } ``` +#### C++ + ```cpp class Trie { private: @@ -203,6 +209,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [26]*Trie @@ -259,6 +267,8 @@ func multiSearch(big string, smalls []string) [][]int { } ``` +#### Swift + ```swift class TrieNode { var idx: Int diff --git a/lcci/17.17.Multi Search/README_EN.md b/lcci/17.17.Multi Search/README_EN.md index 16b4657050d04..66fb57196e0a8 100644 --- a/lcci/17.17.Multi Search/README_EN.md +++ b/lcci/17.17.Multi Search/README_EN.md @@ -50,6 +50,8 @@ smalls = ["is","ppi","hi","sis","i& +#### Python3 + ```python class Trie: def __init__(self): @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] multiSearch(String big, String[] smalls) { @@ -158,6 +162,8 @@ class Trie { } ``` +#### C++ + ```cpp class Trie { private: @@ -209,6 +215,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [26]*Trie @@ -265,6 +273,8 @@ func multiSearch(big string, smalls []string) [][]int { } ``` +#### Swift + ```swift class TrieNode { var idx: Int diff --git a/lcci/17.18.Shortest Supersequence/README.md b/lcci/17.18.Shortest Supersequence/README.md index 4414966df71db..49364c92666d3 100644 --- a/lcci/17.18.Shortest Supersequence/README.md +++ b/lcci/17.18.Shortest Supersequence/README.md @@ -48,6 +48,8 @@ small = [4] +#### Python3 + ```python class Solution: def shortestSeq(self, big: List[int], small: List[int]) -> List[int]: @@ -69,6 +71,8 @@ class Solution: return [] if k < 0 else [k, k + mi - 1] ``` +#### Java + ```java class Solution { public int[] shortestSeq(int[] big, int[] small) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func shortestSeq(big []int, small []int) []int { cnt := len(small) @@ -168,6 +176,8 @@ func shortestSeq(big []int, small []int) []int { } ``` +#### TypeScript + ```ts function shortestSeq(big: number[], small: number[]): number[] { let cnt = small.length; @@ -199,6 +209,8 @@ function shortestSeq(big: number[], small: number[]): number[] { } ``` +#### Swift + ```swift class Solution { func shortestSeq(_ big: [Int], _ small: [Int]) -> [Int] { diff --git a/lcci/17.18.Shortest Supersequence/README_EN.md b/lcci/17.18.Shortest Supersequence/README_EN.md index c71e2d7086a07..d4227da6318b2 100644 --- a/lcci/17.18.Shortest Supersequence/README_EN.md +++ b/lcci/17.18.Shortest Supersequence/README_EN.md @@ -54,6 +54,8 @@ small = [4] +#### Python3 + ```python class Solution: def shortestSeq(self, big: List[int], small: List[int]) -> List[int]: @@ -75,6 +77,8 @@ class Solution: return [] if k < 0 else [k, k + mi - 1] ``` +#### Java + ```java class Solution { public int[] shortestSeq(int[] big, int[] small) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func shortestSeq(big []int, small []int) []int { cnt := len(small) @@ -174,6 +182,8 @@ func shortestSeq(big []int, small []int) []int { } ``` +#### TypeScript + ```ts function shortestSeq(big: number[], small: number[]): number[] { let cnt = small.length; @@ -205,6 +215,8 @@ function shortestSeq(big: number[], small: number[]): number[] { } ``` +#### Swift + ```swift class Solution { func shortestSeq(_ big: [Int], _ small: [Int]) -> [Int] { diff --git a/lcci/17.19.Missing Two/README.md b/lcci/17.19.Missing Two/README.md index c8b3e66ca8fb0..2f1362302e780 100644 --- a/lcci/17.19.Missing Two/README.md +++ b/lcci/17.19.Missing Two/README.md @@ -56,6 +56,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.19.Missing%20Two/R +#### Python3 + ```python class Solution: def missingTwo(self, nums: List[int]) -> List[int]: @@ -78,6 +80,8 @@ class Solution: return [a, b] ``` +#### Java + ```java class Solution { public int[] missingTwo(int[] nums) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func missingTwo(nums []int) []int { n := len(nums) + 2 @@ -155,6 +163,8 @@ func missingTwo(nums []int) []int { } ``` +#### Swift + ```swift class Solution { func missingTwo(_ nums: [Int]) -> [Int] { diff --git a/lcci/17.19.Missing Two/README_EN.md b/lcci/17.19.Missing Two/README_EN.md index 33650bf0f6cf2..f109366a6a356 100644 --- a/lcci/17.19.Missing Two/README_EN.md +++ b/lcci/17.19.Missing Two/README_EN.md @@ -50,6 +50,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.19.Missing%20Two/R +#### Python3 + ```python class Solution: def missingTwo(self, nums: List[int]) -> List[int]: @@ -72,6 +74,8 @@ class Solution: return [a, b] ``` +#### Java + ```java class Solution { public int[] missingTwo(int[] nums) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func missingTwo(nums []int) []int { n := len(nums) + 2 @@ -149,6 +157,8 @@ func missingTwo(nums []int) []int { } ``` +#### Swift + ```swift class Solution { func missingTwo(_ nums: [Int]) -> [Int] { diff --git a/lcci/17.20.Continuous Median/README.md b/lcci/17.20.Continuous Median/README.md index baf454a1728a7..b3074347e30ca 100644 --- a/lcci/17.20.Continuous Median/README.md +++ b/lcci/17.20.Continuous Median/README.md @@ -60,6 +60,8 @@ findMedian() -> 2 +#### Python3 + ```python class MedianFinder: def __init__(self): @@ -87,6 +89,8 @@ class MedianFinder: # param_2 = obj.findMedian() ``` +#### Java + ```java class MedianFinder { private PriorityQueue q1 = new PriorityQueue<>(); @@ -120,6 +124,8 @@ class MedianFinder { */ ``` +#### C++ + ```cpp class MedianFinder { public: @@ -157,6 +163,8 @@ private: */ ``` +#### Go + ```go type MedianFinder struct { q1 hp @@ -202,6 +210,8 @@ func (h *hp) Pop() any { } ``` +#### Swift + ```swift class MedianFinder { private var minHeap = Heap(sort: <) diff --git a/lcci/17.20.Continuous Median/README_EN.md b/lcci/17.20.Continuous Median/README_EN.md index b355748a76f49..9fa0d7acfba2a 100644 --- a/lcci/17.20.Continuous Median/README_EN.md +++ b/lcci/17.20.Continuous Median/README_EN.md @@ -57,6 +57,8 @@ findMedian() -> 2 +#### Python3 + ```python class MedianFinder: def __init__(self): @@ -84,6 +86,8 @@ class MedianFinder: # param_2 = obj.findMedian() ``` +#### Java + ```java class MedianFinder { private PriorityQueue q1 = new PriorityQueue<>(); @@ -117,6 +121,8 @@ class MedianFinder { */ ``` +#### C++ + ```cpp class MedianFinder { public: @@ -154,6 +160,8 @@ private: */ ``` +#### Go + ```go type MedianFinder struct { q1 hp @@ -199,6 +207,8 @@ func (h *hp) Pop() any { } ``` +#### Swift + ```swift class MedianFinder { private var minHeap = Heap(sort: <) diff --git a/lcci/17.21.Volume of Histogram/README.md b/lcci/17.21.Volume of Histogram/README.md index 4e89ab76bdec8..4b5c85827fcca 100644 --- a/lcci/17.21.Volume of Histogram/README.md +++ b/lcci/17.21.Volume of Histogram/README.md @@ -43,6 +43,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.21.Volume%20of%20H +#### Python3 + ```python class Solution: def trap(self, height: List[int]) -> int: @@ -57,6 +59,8 @@ class Solution: return sum(min(l, r) - h for l, r, h in zip(left, right, height)) ``` +#### Java + ```java class Solution { public int trap(int[] height) { @@ -81,6 +85,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func trap(height []int) (ans int) { n := len(height) @@ -125,6 +133,8 @@ func trap(height []int) (ans int) { } ``` +#### TypeScript + ```ts function trap(height: number[]): number { const n = height.length; @@ -145,6 +155,8 @@ function trap(height: number[]): number { } ``` +#### C# + ```cs public class Solution { public int Trap(int[] height) { @@ -169,6 +181,8 @@ public class Solution { } ``` +#### Swift + ```swift class Solution { func trap(_ height: [Int]) -> Int { diff --git a/lcci/17.21.Volume of Histogram/README_EN.md b/lcci/17.21.Volume of Histogram/README_EN.md index 26cc4e879f911..44b2af3f2c812 100644 --- a/lcci/17.21.Volume of Histogram/README_EN.md +++ b/lcci/17.21.Volume of Histogram/README_EN.md @@ -38,6 +38,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.21.Volume%20of%20H +#### Python3 + ```python class Solution: def trap(self, height: List[int]) -> int: @@ -52,6 +54,8 @@ class Solution: return sum(min(l, r) - h for l, r, h in zip(left, right, height)) ``` +#### Java + ```java class Solution { public int trap(int[] height) { @@ -76,6 +80,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -100,6 +106,8 @@ public: }; ``` +#### Go + ```go func trap(height []int) (ans int) { n := len(height) @@ -120,6 +128,8 @@ func trap(height []int) (ans int) { } ``` +#### TypeScript + ```ts function trap(height: number[]): number { const n = height.length; @@ -140,6 +150,8 @@ function trap(height: number[]): number { } ``` +#### C# + ```cs public class Solution { public int Trap(int[] height) { @@ -164,6 +176,8 @@ public class Solution { } ``` +#### Swift + ```swift class Solution { func trap(_ height: [Int]) -> Int { diff --git a/lcci/17.22.Word Transformer/README.md b/lcci/17.22.Word Transformer/README.md index 1ecee62c17601..3955d805a6aed 100644 --- a/lcci/17.22.Word Transformer/README.md +++ b/lcci/17.22.Word Transformer/README.md @@ -62,6 +62,8 @@ wordList = ["hot","dot","dog","lot",&quo +#### Python3 + ```python class Solution: def findLadders( @@ -87,6 +89,8 @@ class Solution: return ans if dfs(beginWord) else [] ``` +#### Java + ```java class Solution { private List ans = new ArrayList<>(); @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -187,6 +193,8 @@ private: }; ``` +#### Go + ```go func findLadders(beginWord string, endWord string, wordList []string) []string { ans := []string{beginWord} @@ -227,6 +235,8 @@ func findLadders(beginWord string, endWord string, wordList []string) []string { } ``` +#### TypeScript + ```ts function findLadders(beginWord: string, endWord: string, wordList: string[]): string[] { const ans: string[] = [beginWord]; @@ -264,6 +274,8 @@ function findLadders(beginWord: string, endWord: string, wordList: string[]): st } ``` +#### Swift + ```swift class Solution { private var ans: [String] = [] diff --git a/lcci/17.22.Word Transformer/README_EN.md b/lcci/17.22.Word Transformer/README_EN.md index 0e784e552c83d..78c1ecfa99be6 100644 --- a/lcci/17.22.Word Transformer/README_EN.md +++ b/lcci/17.22.Word Transformer/README_EN.md @@ -80,6 +80,8 @@ Finally, we call `dfs(beginWord)`. If `True` is returned, the conversion is succ +#### Python3 + ```python class Solution: def findLadders( @@ -105,6 +107,8 @@ class Solution: return ans if dfs(beginWord) else [] ``` +#### Java + ```java class Solution { private List ans = new ArrayList<>(); @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -205,6 +211,8 @@ private: }; ``` +#### Go + ```go func findLadders(beginWord string, endWord string, wordList []string) []string { ans := []string{beginWord} @@ -245,6 +253,8 @@ func findLadders(beginWord string, endWord string, wordList []string) []string { } ``` +#### TypeScript + ```ts function findLadders(beginWord: string, endWord: string, wordList: string[]): string[] { const ans: string[] = [beginWord]; @@ -282,6 +292,8 @@ function findLadders(beginWord: string, endWord: string, wordList: string[]): st } ``` +#### Swift + ```swift class Solution { private var ans: [String] = [] diff --git a/lcci/17.23.Max Black Square/README.md b/lcci/17.23.Max Black Square/README.md index 9d693211b640a..a109449e1845d 100644 --- a/lcci/17.23.Max Black Square/README.md +++ b/lcci/17.23.Max Black Square/README.md @@ -82,6 +82,8 @@ $$ +#### Python3 + ```python class Solution: def findSquare(self, matrix: List[List[int]]) -> List[int]: @@ -106,6 +108,8 @@ class Solution: return [] ``` +#### Java + ```java class Solution { public int[] findSquare(int[][] matrix) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go func findSquare(matrix [][]int) []int { n := len(matrix) @@ -201,6 +209,8 @@ func findSquare(matrix [][]int) []int { } ``` +#### TypeScript + ```ts function findSquare(matrix: number[][]): number[] { const n = matrix.length; @@ -232,6 +242,8 @@ function findSquare(matrix: number[][]): number[] { } ``` +#### Swift + ```swift class Solution { func findSquare(_ matrix: [[Int]]) -> [Int] { diff --git a/lcci/17.23.Max Black Square/README_EN.md b/lcci/17.23.Max Black Square/README_EN.md index 6148644f1ebd5..48576e74b7c08 100644 --- a/lcci/17.23.Max Black Square/README_EN.md +++ b/lcci/17.23.Max Black Square/README_EN.md @@ -69,6 +69,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.23.Max%20Black%20S +#### Python3 + ```python class Solution: def findSquare(self, matrix: List[List[int]]) -> List[int]: @@ -93,6 +95,8 @@ class Solution: return [] ``` +#### Java + ```java class Solution { public int[] findSquare(int[][] matrix) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func findSquare(matrix [][]int) []int { n := len(matrix) @@ -188,6 +196,8 @@ func findSquare(matrix [][]int) []int { } ``` +#### TypeScript + ```ts function findSquare(matrix: number[][]): number[] { const n = matrix.length; @@ -219,6 +229,8 @@ function findSquare(matrix: number[][]): number[] { } ``` +#### Swift + ```swift class Solution { func findSquare(_ matrix: [[Int]]) -> [Int] { diff --git a/lcci/17.24.Max Submatrix/README.md b/lcci/17.24.Max Submatrix/README.md index d9546f9ba637e..403b9d8950f4e 100644 --- a/lcci/17.24.Max Submatrix/README.md +++ b/lcci/17.24.Max Submatrix/README.md @@ -46,6 +46,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.24.Max%20Submatrix +#### Python3 + ```python class Solution: def getMaxMatrix(self, matrix: List[List[int]]) -> List[int]: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] getMaxMatrix(int[][] matrix) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func getMaxMatrix(matrix [][]int) []int { m, n := len(matrix), len(matrix[0]) @@ -197,6 +205,8 @@ func getMaxMatrix(matrix [][]int) []int { } ``` +#### Swift + ```swift class Solution { func getMaxMatrix(_ matrix: [[Int]]) -> [Int] { diff --git a/lcci/17.24.Max Submatrix/README_EN.md b/lcci/17.24.Max Submatrix/README_EN.md index 4f8dcec810d86..b869d41fd51cf 100644 --- a/lcci/17.24.Max Submatrix/README_EN.md +++ b/lcci/17.24.Max Submatrix/README_EN.md @@ -52,6 +52,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.24.Max%20Submatrix +#### Python3 + ```python class Solution: def getMaxMatrix(self, matrix: List[List[int]]) -> List[int]: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] getMaxMatrix(int[][] matrix) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func getMaxMatrix(matrix [][]int) []int { m, n := len(matrix), len(matrix[0]) @@ -203,6 +211,8 @@ func getMaxMatrix(matrix [][]int) []int { } ``` +#### Swift + ```swift class Solution { func getMaxMatrix(_ matrix: [[Int]]) -> [Int] { diff --git a/lcci/17.25.Word Rectangle/README.md b/lcci/17.25.Word Rectangle/README.md index df2b4e5f65d3a..5669b8df47131 100644 --- a/lcci/17.25.Word Rectangle/README.md +++ b/lcci/17.25.Word Rectangle/README.md @@ -50,6 +50,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.25.Word%20Rectangl +#### Python3 + ```python class Trie: def __init__(self): @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java class Trie { Trie[] children = new Trie[26]; @@ -195,6 +199,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -279,6 +285,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [26]*Trie @@ -355,6 +363,8 @@ func maxRectangle(words []string) (ans []string) { } ``` +#### Swift + ```swift class Trie { var children = [Trie?](repeating: nil, count: 26) diff --git a/lcci/17.25.Word Rectangle/README_EN.md b/lcci/17.25.Word Rectangle/README_EN.md index 1f26d5dd27b6a..2fb90d5edb957 100644 --- a/lcci/17.25.Word Rectangle/README_EN.md +++ b/lcci/17.25.Word Rectangle/README_EN.md @@ -57,6 +57,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.25.Word%20Rectangl +#### Python3 + ```python class Trie: def __init__(self): @@ -122,6 +124,8 @@ class Solution: return ans ``` +#### Java + ```java class Trie { Trie[] children = new Trie[26]; @@ -202,6 +206,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -286,6 +292,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [26]*Trie @@ -362,6 +370,8 @@ func maxRectangle(words []string) (ans []string) { } ``` +#### Swift + ```swift class Trie { var children = [Trie?](repeating: nil, count: 26) diff --git a/lcci/17.26.Sparse Similarity/README.md b/lcci/17.26.Sparse Similarity/README.md index efb91e7e1f936..9c7984a2fa4b7 100644 --- a/lcci/17.26.Sparse Similarity/README.md +++ b/lcci/17.26.Sparse Similarity/README.md @@ -53,6 +53,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.26.Sparse%20Simila +#### Python3 + ```python class Solution: def computeSimilarities(self, docs: List[List[int]]) -> List[str]: @@ -75,6 +77,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List computeSimilarities(int[][] docs) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp using pii = pair; @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func computeSimilarities(docs [][]int) []string { d := map[int][]int{} diff --git a/lcci/17.26.Sparse Similarity/README_EN.md b/lcci/17.26.Sparse Similarity/README_EN.md index dc3a78a393c5a..0361ace0f2672 100644 --- a/lcci/17.26.Sparse Similarity/README_EN.md +++ b/lcci/17.26.Sparse Similarity/README_EN.md @@ -62,6 +62,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/17.26.Sparse%20Simila +#### Python3 + ```python class Solution: def computeSimilarities(self, docs: List[List[int]]) -> List[str]: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List computeSimilarities(int[][] docs) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp using pii = pair; @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func computeSimilarities(docs [][]int) []string { d := map[int][]int{} diff --git "a/lcof/\351\235\242\350\257\225\351\242\23003. \346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23003. \346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227/README.md" index 3062b92beec61..c48b91b76c102 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23003. \346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23003. \346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227/README.md" @@ -44,6 +44,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def findRepeatNumber(self, nums: List[int]) -> int: @@ -52,6 +54,8 @@ class Solution: return a ``` +#### Java + ```java class Solution { public int findRepeatNumber(int[] nums) { @@ -65,6 +69,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -79,6 +85,8 @@ public: }; ``` +#### Go + ```go func findRepeatNumber(nums []int) int { sort.Ints(nums) @@ -90,6 +98,8 @@ func findRepeatNumber(nums []int) int { } ``` +#### TypeScript + ```ts function findRepeatNumber(nums: number[]): number { for (let i = 0; ; ++i) { @@ -104,6 +114,8 @@ function findRepeatNumber(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_repeat_number(mut nums: Vec) -> i32 { @@ -121,6 +133,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -139,6 +153,8 @@ var findRepeatNumber = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int FindRepeatNumber(int[] nums) { @@ -157,6 +173,8 @@ public class Solution { } ``` +#### Kotlin + ```kotlin class Solution { fun findRepeatNumber(nums: IntArray): Int { @@ -193,6 +211,8 @@ class Solution { +#### Python3 + ```python class Solution: def findRepeatNumber(self, nums: List[int]) -> int: @@ -203,6 +223,8 @@ class Solution: vis.add(v) ``` +#### Java + ```java class Solution { public int findRepeatNumber(int[] nums) { @@ -216,6 +238,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -231,6 +255,8 @@ public: }; ``` +#### Go + ```go func findRepeatNumber(nums []int) int { vis := map[int]bool{} @@ -257,6 +283,8 @@ func findRepeatNumber(nums []int) int { +#### Python3 + ```python class Solution: def findRepeatNumber(self, nums: List[int]) -> int: @@ -268,6 +296,8 @@ class Solution: v = nums[i] ``` +#### Java + ```java class Solution { public int findRepeatNumber(int[] nums) { @@ -286,6 +316,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -303,6 +335,8 @@ public: }; ``` +#### Go + ```go func findRepeatNumber(nums []int) int { for i := 0; ; i++ { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23004. \344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23004. \344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/README.md" index 86198af6c5cb5..b4f0908d07b36 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23004. \344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23004. \344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/README.md" @@ -62,6 +62,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def findNumberIn2DArray(self, matrix: List[List[int]], target: int) -> bool: @@ -72,6 +74,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean findNumberIn2DArray(int[][] matrix, int target) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,6 +107,8 @@ public: }; ``` +#### Go + ```go func findNumberIn2DArray(matrix [][]int, target int) bool { for _, row := range matrix { @@ -113,6 +121,8 @@ func findNumberIn2DArray(matrix [][]int, target int) bool { } ``` +#### TypeScript + ```ts function findNumberIn2DArray(matrix: number[][], target: number): boolean { if (matrix.length == 0 || matrix[0].length == 0) { @@ -134,6 +144,8 @@ function findNumberIn2DArray(matrix: number[][], target: number): boolean { } ``` +#### Rust + ```rust use std::cmp::Ordering; impl Solution { @@ -161,6 +173,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix @@ -187,6 +201,8 @@ var findNumberIn2DArray = function (matrix, target) { }; ``` +#### C# + ```cs public class Solution { public bool FindNumberIn2DArray(int[][] matrix, int target) { @@ -228,6 +244,8 @@ public class Solution { +#### Python3 + ```python class Solution: def findNumberIn2DArray(self, matrix: List[List[int]], target: int) -> bool: @@ -245,6 +263,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean findNumberIn2DArray(int[][] matrix, int target) { @@ -267,6 +287,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -290,6 +312,8 @@ public: }; ``` +#### Go + ```go func findNumberIn2DArray(matrix [][]int, target int) bool { if len(matrix) == 0 { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23005. \346\233\277\346\215\242\347\251\272\346\240\274/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23005. \346\233\277\346\215\242\347\251\272\346\240\274/README.md" index 7858ce8bde4e3..3552a95538d74 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23005. \346\233\277\346\215\242\347\251\272\346\240\274/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23005. \346\233\277\346\215\242\347\251\272\346\240\274/README.md" @@ -41,12 +41,16 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def replaceSpace(self, s: str) -> str: return s.replace(' ', '%20') ``` +#### Java + ```java class Solution { public String replaceSpace(String s) { @@ -55,6 +59,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -71,18 +77,24 @@ public: }; ``` +#### Go + ```go func replaceSpace(s string) string { return strings.Replace(s, " ", "%20", -1) } ``` +#### TypeScript + ```ts function replaceSpace(s: string): string { return s.replace(/\s/g, '%20'); } ``` +#### Rust + ```rust impl Solution { pub fn replace_space(s: String) -> String { @@ -91,6 +103,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -101,6 +115,8 @@ var replaceSpace = function (s) { }; ``` +#### C# + ```cs public class Solution { public string ReplaceSpace(string s) { @@ -109,6 +125,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** @@ -143,6 +161,8 @@ class Solution { +#### Python3 + ```python class Solution: def replaceSpace(self, s: str) -> str: @@ -152,6 +172,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String replaceSpace(String s) { @@ -164,6 +186,8 @@ class Solution { } ``` +#### Go + ```go func replaceSpace(s string) string { ans := strings.Builder{} @@ -178,6 +202,8 @@ func replaceSpace(s string) string { } ``` +#### TypeScript + ```ts function replaceSpace(s: string): string { const strArr = []; @@ -188,6 +214,8 @@ function replaceSpace(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn replace_space(s: String) -> String { @@ -204,6 +232,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -214,6 +244,8 @@ var replaceSpace = function (s) { }; ``` +#### C# + ```cs public class Solution { public string ReplaceSpace(string s) { @@ -240,6 +272,8 @@ public class Solution { +#### JavaScript + ```js /** * @param {string} s diff --git "a/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/README.md" index 42b50ae3c3dc7..bfa8e8184131e 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/README.md" @@ -41,6 +41,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -58,6 +60,8 @@ class Solution: return ans[::-1] ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -82,6 +86,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -102,6 +108,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -121,6 +129,8 @@ func reversePrint(head *ListNode) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -143,6 +153,8 @@ function reversePrint(head: ListNode | null): number[] { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -174,6 +186,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -195,6 +209,8 @@ var reversePrint = function (head) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. @@ -231,6 +247,8 @@ var reversePrint = function (head) { +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -248,6 +266,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -274,6 +294,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -296,6 +318,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -314,6 +338,8 @@ func reversePrint(head *ListNode) (ans []int) { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -352,6 +378,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. diff --git "a/lcof/\351\235\242\350\257\225\351\242\23007. \351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23007. \351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/README.md" index 1f1f2f97d1031..d7ae1aa3cb80c 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23007. \351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23007. \351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/README.md" @@ -64,6 +64,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -89,6 +91,8 @@ class Solution: return dfs(0, 0, len(preorder)) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -192,6 +200,8 @@ func buildTree(preorder []int, inorder []int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -228,6 +238,8 @@ function buildTree(preorder: number[], inorder: number[]): TreeNode | null { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -276,6 +288,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -310,6 +324,8 @@ var buildTree = function (preorder, inorder) { }; ``` +#### C# + ```cs /** * Definition for a binary tree node. @@ -344,6 +360,8 @@ public class Solution { +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git "a/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/README.md" index b77ec1da1ff5a..be00711a0bbf9 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/README.md" @@ -57,6 +57,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class CQueue: def __init__(self): @@ -79,6 +81,8 @@ class CQueue: # param_2 = obj.deleteHead() ``` +#### Java + ```java class CQueue { private Deque stk1 = new ArrayDeque<>(); @@ -109,6 +113,8 @@ class CQueue { */ ``` +#### C++ + ```cpp class CQueue { public: @@ -146,6 +152,8 @@ private: */ ``` +#### Go + ```go type CQueue struct { stk1, stk2 []int @@ -182,6 +190,8 @@ func (this *CQueue) DeleteHead() int { */ ``` +#### TypeScript + ```ts class CQueue { private stk1: number[]; @@ -214,6 +224,8 @@ class CQueue { */ ``` +#### Rust + ```rust struct CQueue { s1: Vec, @@ -255,6 +267,8 @@ impl CQueue { */ ``` +#### JavaScript + ```js var CQueue = function () { this.stk1 = []; @@ -289,6 +303,8 @@ CQueue.prototype.deleteHead = function () { */ ``` +#### C# + ```cs public class CQueue { private Stack stk1 = new Stack(); diff --git "a/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/README.md" index e4579605027ef..7d38e46f39ac0 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/README.md" @@ -60,6 +60,8 @@ F(N) = F(N - 1) + F(N - 2), 其中 N > 1. +#### Python3 + ```python class Solution: def fib(self, n: int) -> int: @@ -69,6 +71,8 @@ class Solution: return a ``` +#### Java + ```java class Solution { public int fib(int n) { @@ -83,6 +87,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -98,6 +104,8 @@ public: }; ``` +#### Go + ```go func fib(n int) int { a, b := 0, 1 @@ -108,6 +116,8 @@ func fib(n int) int { } ``` +#### TypeScript + ```ts function fib(n: number): number { let a: number = 0, @@ -120,6 +130,8 @@ function fib(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn fib(n: i32) -> i32 { @@ -132,6 +144,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -147,6 +161,8 @@ var fib = function (n) { }; ``` +#### C# + ```cs public class Solution { public int Fib(int n) { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23010- II. \351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23010- II. \351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/README.md" index 96e87f80406ed..f28acba85bfa2 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23010- II. \351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23010- II. \351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/README.md" @@ -59,6 +59,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def numWays(self, n: int) -> int: @@ -68,6 +70,8 @@ class Solution: return a ``` +#### Java + ```java class Solution { public int numWays(int n) { @@ -82,6 +86,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -97,6 +103,8 @@ public: }; ``` +#### Go + ```go func numWays(n int) int { a, b := 1, 1 @@ -107,6 +115,8 @@ func numWays(n int) int { } ``` +#### TypeScript + ```ts function numWays(n: number): number { let a = 0; @@ -118,6 +128,8 @@ function numWays(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn num_ways(n: i32) -> i32 { @@ -130,6 +142,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -144,6 +158,8 @@ var numWays = function (n) { }; ``` +#### C# + ```cs public class Solution { public int NumWays(int n) { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23011. \346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23011. \346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227/README.md" index ea14870f02d1e..2f94ffeb0654b 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23011. \346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23011. \346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227/README.md" @@ -56,6 +56,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def minArray(self, numbers: List[int]) -> int: @@ -71,6 +73,8 @@ class Solution: return numbers[l] ``` +#### Java + ```java class Solution { public int minArray(int[] numbers) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func minArray(numbers []int) int { l, r := 0, len(numbers)-1 @@ -127,6 +135,8 @@ func minArray(numbers []int) int { } ``` +#### Rust + ```rust impl Solution { pub fn min_array(numbers: Vec) -> i32 { @@ -151,6 +161,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} numbers @@ -173,6 +185,8 @@ var minArray = function (numbers) { }; ``` +#### C# + ```cs public class Solution { public int MinArray(int[] numbers) { @@ -202,6 +216,8 @@ public class Solution { +#### Python3 + ```python class Solution: def minArray(self, numbers: List[int]) -> int: @@ -219,6 +235,8 @@ class Solution: return numbers[l] ``` +#### Java + ```java class Solution { public int minArray(int[] numbers) { @@ -241,6 +259,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -264,6 +284,8 @@ public: }; ``` +#### Go + ```go func minArray(numbers []int) int { l, r := 0, len(numbers)-1 @@ -284,6 +306,8 @@ func minArray(numbers []int) int { } ``` +#### Rust + ```rust impl Solution { pub fn min_array(numbers: Vec) -> i32 { @@ -311,6 +335,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} numbers @@ -336,6 +362,8 @@ var minArray = function (numbers) { }; ``` +#### C# + ```cs public class Solution { public int MinArray(int[] numbers) { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/README.md" index cc74cf66322f2..f664835e0af45 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/README.md" @@ -74,6 +74,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def exist(self, board: List[List[str]], word: str) -> bool: @@ -92,6 +94,8 @@ class Solution: return any(dfs(i, j, 0) for i in range(m) for j in range(n)) ``` +#### Java + ```java class Solution { private char[][] board; @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go func exist(board [][]byte, word string) bool { m, n := len(board), len(board[0]) @@ -197,6 +205,8 @@ func exist(board [][]byte, word string) bool { } ``` +#### TypeScript + ```ts function exist(board: string[][], word: string): boolean { const m = board.length; @@ -227,6 +237,8 @@ function exist(board: string[][], word: string): boolean { } ``` +#### Rust + ```rust impl Solution { fn dfs( @@ -273,6 +285,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {character[][]} board @@ -309,6 +323,8 @@ var exist = function (board, word) { }; ``` +#### C# + ```cs public class Solution { private char[][] board; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23013. \346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23013. \346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/README.md" index b4b67d6afee48..23012d40d2e97 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23013. \346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23013. \346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/README.md" @@ -51,6 +51,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def movingCount(self, m: int, n: int, k: int) -> int: @@ -77,6 +79,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private boolean[][] vis; @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func movingCount(m int, n int, k int) int { vis := make([][]bool, m) @@ -165,6 +173,8 @@ func movingCount(m int, n int, k int) int { } ``` +#### TypeScript + ```ts function movingCount(m: number, n: number, k: number): number { const set = new Set(); @@ -187,6 +197,8 @@ function movingCount(m: number, n: number, k: number): number { } ``` +#### Rust + ```rust use std::collections::{ HashSet, VecDeque }; impl Solution { @@ -217,6 +229,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} m @@ -242,6 +256,8 @@ var movingCount = function (m, n, k) { }; ``` +#### C# + ```cs public class Solution { public int MovingCount(int m, int n, int k) { @@ -269,6 +285,8 @@ public class Solution { +#### Python3 + ```python class Solution: def movingCount(self, m: int, n: int, k: int) -> int: @@ -289,6 +307,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private boolean[][] vis; @@ -314,6 +334,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -339,6 +361,8 @@ public: }; ``` +#### Go + ```go func movingCount(m int, n int, k int) (ans int) { f := func(x int) (s int) { @@ -369,6 +393,8 @@ func movingCount(m int, n int, k int) (ans int) { } ``` +#### Rust + ```rust impl Solution { fn dfs(sign: &mut Vec>, k: usize, i: usize, j: usize) -> i32 { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23014- I. \345\211\252\347\273\263\345\255\220/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23014- I. \345\211\252\347\273\263\345\255\220/README.md" index 70c4f61568753..82dc195744012 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23014- I. \345\211\252\347\273\263\345\255\220/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23014- I. \345\211\252\347\273\263\345\255\220/README.md" @@ -54,6 +54,8 @@ $$ +#### Python3 + ```python class Solution: def cuttingRope(self, n: int) -> int: @@ -64,6 +66,8 @@ class Solution: return dp[n] ``` +#### Java + ```java class Solution { public int cuttingRope(int n) { @@ -79,6 +83,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -95,6 +101,8 @@ public: }; ``` +#### Go + ```go func cuttingRope(n int) int { dp := make([]int, n+1) @@ -108,6 +116,8 @@ func cuttingRope(n int) int { } ``` +#### TypeScript + ```ts function cuttingRope(n: number): number { if (n < 4) { @@ -124,6 +134,8 @@ function cuttingRope(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn cutting_rope(n: i32) -> i32 { @@ -136,6 +148,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -156,6 +170,8 @@ var cuttingRope = function (n) { }; ``` +#### C# + ```cs public class Solution { public int CuttingRope(int n) { @@ -187,6 +203,8 @@ public class Solution { +#### Python3 + ```python class Solution: def cuttingRope(self, n: int) -> int: @@ -199,6 +217,8 @@ class Solution: return pow(3, n // 3) * 2 ``` +#### Java + ```java class Solution { public int cuttingRope(int n) { @@ -216,6 +236,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -234,6 +256,8 @@ public: }; ``` +#### Go + ```go func cuttingRope(n int) int { if n < 4 { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23014- II. \345\211\252\347\273\263\345\255\220 II/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23014- II. \345\211\252\347\273\263\345\255\220 II/README.md" index 4f85ffd2ec236..67dabbe6f5408 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23014- II. \345\211\252\347\273\263\345\255\220 II/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23014- II. \345\211\252\347\273\263\345\255\220 II/README.md" @@ -54,6 +54,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def cuttingRope(self, n: int) -> int: @@ -67,6 +69,8 @@ class Solution: return pow(3, n // 3, mod) * 2 % mod ``` +#### Java + ```java class Solution { private final int mod = (int) 1e9 + 7; @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func cuttingRope(n int) int { if n < 4 { @@ -152,6 +160,8 @@ func cuttingRope(n int) int { } ``` +#### Rust + ```rust impl Solution { pub fn cutting_rope(mut n: i32) -> i32 { @@ -168,6 +178,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -199,6 +211,8 @@ var cuttingRope = function (n) { }; ``` +#### C# + ```cs public class Solution { public int CuttingRope(int n) { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23015. \344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23015. \344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260/README.md" index 2d0681dc10521..95b67801c3b94 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23015. \344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23015. \344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260/README.md" @@ -76,12 +76,16 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def hammingWeight(self, n: int) -> int: return n.bit_count() ``` +#### Java + ```java public class Solution { // you need to treat n as an unsigned value @@ -96,6 +100,8 @@ public class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func hammingWeight(num uint32) (ans int) { for num != 0 { @@ -120,6 +128,8 @@ func hammingWeight(num uint32) (ans int) { } ``` +#### JavaScript + ```js /** * @param {number} n - a positive integer @@ -135,6 +145,8 @@ var hammingWeight = function (n) { }; ``` +#### C# + ```cs public class Solution { public int HammingWeight(uint n) { @@ -158,6 +170,8 @@ public class Solution { +#### Python3 + ```python class Solution: def hammingWeight(self, n: int) -> int: @@ -168,6 +182,8 @@ class Solution: return ans ``` +#### Java + ```java public class Solution { // you need to treat n as an unsigned value @@ -182,6 +198,8 @@ public class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -196,6 +214,8 @@ public: }; ``` +#### Go + ```go func hammingWeight(num uint32) (ans int) { for num != 0 { @@ -216,6 +236,8 @@ func hammingWeight(num uint32) (ans int) { +#### Python3 + ```python class Solution: def hammingWeight(self, n: int) -> int: diff --git "a/lcof/\351\235\242\350\257\225\351\242\23016. \346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23016. \346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/README.md" index 92588fa8cc04a..1808d49592873 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23016. \346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23016. \346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/README.md" @@ -64,6 +64,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def myPow(self, x: float, n: int) -> float: @@ -79,6 +81,8 @@ class Solution: return qpow(x, n) if n >= 0 else 1 / qpow(x, -n) ``` +#### Java + ```java class Solution { public double myPow(double x, int n) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func myPow(x float64, n int) float64 { qpow := func(a float64, n int) float64 { @@ -136,6 +144,8 @@ func myPow(x float64, n int) float64 { } ``` +#### TypeScript + ```ts function myPow(x: number, n: number): number { const qpow = (a: number, n: number): number => { @@ -152,6 +162,8 @@ function myPow(x: number, n: number): number { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -181,6 +193,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} x @@ -202,6 +216,8 @@ var myPow = function (x, n) { }; ``` +#### C# + ```cs public class Solution { public double MyPow(double x, int n) { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23017. \346\211\223\345\215\260\344\273\2161\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23017. \346\211\223\345\215\260\344\273\2161\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260/README.md" index 71fc0fefc2eb6..263db1db585bd 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23017. \346\211\223\345\215\260\344\273\2161\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23017. \346\211\223\345\215\260\344\273\2161\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260/README.md" @@ -45,6 +45,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def printNumbers(self, n: int) -> List[int]: @@ -69,6 +71,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] printNumbers(int n) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func printNumbers(n int) []int { n = int(math.Pow(10, float64(n))) - 1 @@ -173,6 +181,8 @@ func print(n int) []string { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -187,6 +197,8 @@ var printNumbers = function (n) { }; ``` +#### C# + ```cs public class Solution { public int[] PrintNumbers(int n) { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23018. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23018. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/README.md" index ec8ffb1dd2ecb..41be8be5e9e37 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23018. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23018. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/README.md" @@ -59,6 +59,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -76,6 +78,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -143,6 +151,8 @@ func deleteNode(head *ListNode, val int) *ListNode { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -175,6 +185,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -200,6 +212,8 @@ var deleteNode = function (head, val) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. diff --git "a/lcof/\351\235\242\350\257\225\351\242\23019. \346\255\243\345\210\231\350\241\250\350\276\276\345\274\217\345\214\271\351\205\215/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23019. \346\255\243\345\210\231\350\241\250\350\276\276\345\274\217\345\214\271\351\205\215/README.md" index c3b17044e54ba..f1a510583f5fb 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23019. \346\255\243\345\210\231\350\241\250\350\276\276\345\274\217\345\214\271\351\205\215/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23019. \346\255\243\345\210\231\350\241\250\350\276\276\345\274\217\345\214\271\351\205\215/README.md" @@ -86,6 +86,8 @@ p = "mis*is*p*." +#### Python3 + ```python class Solution: def isMatch(self, s: str, p: str) -> bool: @@ -103,6 +105,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private Boolean[][] f; @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go func isMatch(s string, p string) bool { m, n := len(s), len(p) @@ -199,6 +207,8 @@ func isMatch(s string, p string) bool { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -231,6 +241,8 @@ var isMatch = function (s, p) { }; ``` +#### C# + ```cs public class Solution { private string s; @@ -290,6 +302,8 @@ public class Solution { +#### Python3 + ```python class Solution: def isMatch(self, s: str, p: str) -> bool: @@ -307,6 +321,8 @@ class Solution: return f[m][n] ``` +#### Java + ```java class Solution { public boolean isMatch(String s, String p) { @@ -331,6 +347,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -356,6 +374,8 @@ public: }; ``` +#### Go + ```go func isMatch(s string, p string) bool { m, n := len(s), len(p) @@ -380,6 +400,8 @@ func isMatch(s string, p string) bool { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -407,6 +429,8 @@ var isMatch = function (s, p) { }; ``` +#### C# + ```cs public class Solution { public bool IsMatch(string s, string p) { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23020. \350\241\250\347\244\272\346\225\260\345\200\274\347\232\204\345\255\227\347\254\246\344\270\262/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23020. \350\241\250\347\244\272\346\225\260\345\200\274\347\232\204\345\255\227\347\254\246\344\270\262/README.md" index 73a739a2c4fac..77c6e13277a5c 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23020. \350\241\250\347\244\272\346\225\260\345\200\274\347\232\204\345\255\227\347\254\246\344\270\262/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23020. \350\241\250\347\244\272\346\225\260\345\200\274\347\232\204\345\255\227\347\254\246\344\270\262/README.md" @@ -123,6 +123,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def isNumber(self, s: str) -> bool: @@ -154,6 +156,8 @@ class Solution: return digit ``` +#### Java + ```java class Solution { public boolean isNumber(String s) { @@ -198,6 +202,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -240,6 +246,8 @@ public: }; ``` +#### Go + ```go func isNumber(s string) bool { i, j := 0, len(s)-1 @@ -278,6 +286,8 @@ func isNumber(s string) bool { } ``` +#### C# + ```cs public class Solution { public bool IsNumber(string s) { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23021. \350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23021. \350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242/README.md" index 45edb581972bb..82bd886900fb0 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23021. \350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23021. \350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242/README.md" @@ -48,6 +48,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def exchange(self, nums: List[int]) -> List[int]: @@ -59,6 +61,8 @@ class Solution: return nums ``` +#### Java + ```java class Solution { public int[] exchange(int[] nums) { @@ -75,6 +79,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -90,6 +96,8 @@ public: }; ``` +#### Go + ```go func exchange(nums []int) []int { j := 0 @@ -103,6 +111,8 @@ func exchange(nums []int) []int { } ``` +#### TypeScript + ```ts function exchange(nums: number[]): number[] { let j = 0; @@ -117,6 +127,8 @@ function exchange(nums: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn exchange(mut nums: Vec) -> Vec { @@ -132,6 +144,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -150,6 +164,8 @@ var exchange = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int[] Exchange(int[] nums) { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23022. \351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23022. \351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271/README.md" index b7cec862d8029..01b493c023c0a 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23022. \351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23022. \351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271/README.md" @@ -41,6 +41,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -59,6 +61,8 @@ class Solution: return slow ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -83,6 +87,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -128,6 +136,8 @@ func getKthFromEnd(head *ListNode, k int) *ListNode { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -161,6 +171,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -188,6 +200,8 @@ var getKthFromEnd = function (head, k) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. diff --git "a/lcof/\351\235\242\350\257\225\351\242\23024. \345\217\215\350\275\254\351\223\276\350\241\250/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23024. \345\217\215\350\275\254\351\223\276\350\241\250/README.md" index bb682f1185f39..eb47b51e25097 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23024. \345\217\215\350\275\254\351\223\276\350\241\250/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23024. \345\217\215\350\275\254\351\223\276\350\241\250/README.md" @@ -45,6 +45,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -65,6 +67,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -135,6 +143,8 @@ func reverseList(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -161,6 +171,8 @@ function reverseList(head: ListNode | null): ListNode | null { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -193,6 +205,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -218,6 +232,8 @@ var reverseList = function (head) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. @@ -256,6 +272,8 @@ public class Solution { +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -274,6 +292,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -296,6 +316,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -319,6 +341,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -338,6 +362,8 @@ func reverseList(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -362,6 +388,8 @@ function reverseList(head: ListNode | null): ListNode | null { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -385,6 +413,8 @@ var reverseList = function (head) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. diff --git "a/lcof/\351\235\242\350\257\225\351\242\23025. \345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23025. \345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250/README.md" index 1140ecabde6c4..d33eeadb54e40 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23025. \345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23025. \345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250/README.md" @@ -43,6 +43,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -66,6 +68,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -155,6 +163,8 @@ func mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -186,6 +196,8 @@ function mergeTwoLists(l1: ListNode | null, l2: ListNode | null): ListNode | nul } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -235,6 +247,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -266,6 +280,8 @@ var mergeTwoLists = function (l1, l2) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. @@ -314,6 +330,8 @@ public class Solution { +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -334,6 +352,8 @@ class Solution: return l2 ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -362,6 +382,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -391,6 +413,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -416,6 +440,8 @@ func mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -442,6 +468,8 @@ function mergeTwoLists(l1: ListNode | null, l2: ListNode | null): ListNode | nul } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -482,6 +510,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -509,6 +539,8 @@ var mergeTwoLists = function (l1, l2) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. diff --git "a/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/README.md" index c334a95c9662b..84e16d479c851 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/README.md" @@ -56,6 +56,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -81,6 +83,8 @@ class Solution: return self.isSubStructure(A.left, B) or self.isSubStructure(A.right, B) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -163,6 +171,8 @@ func isSubStructure(A *TreeNode, B *TreeNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -195,6 +205,8 @@ function isSubStructure(A: TreeNode | null, B: TreeNode | null): boolean { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -251,6 +263,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -281,6 +295,8 @@ var isSubStructure = function (A, B) { }; ``` +#### C# + ```cs /** * Definition for a binary tree node. diff --git "a/lcof/\351\235\242\350\257\225\351\242\23027. \344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23027. \344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/README.md" index aedf7ac2a1d0e..3777ac1f3556e 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23027. \344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23027. \344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/README.md" @@ -59,6 +59,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -78,6 +80,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -147,6 +155,8 @@ func mirrorTree(root *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -175,6 +185,8 @@ function mirrorTree(root: TreeNode | null): TreeNode | null { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -215,6 +227,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -240,6 +254,8 @@ var mirrorTree = function (root) { }; ``` +#### C# + ```cs /** * Definition for a binary tree node. @@ -275,6 +291,8 @@ public class Solution { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: diff --git "a/lcof/\351\235\242\350\257\225\351\242\23028. \345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23028. \345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221/README.md" index 910e8d93acff5..dd282178ab3ba 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23028. \345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23028. \345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221/README.md" @@ -71,6 +71,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -92,6 +94,8 @@ class Solution: return dfs(root, root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -170,6 +178,8 @@ func isSymmetric(root *TreeNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -199,6 +209,8 @@ function isSymmetric(root: TreeNode | null): boolean { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -239,6 +251,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -265,6 +279,8 @@ var isSymmetric = function (root) { }; ``` +#### C# + ```cs /** * Definition for a binary tree node. diff --git "a/lcof/\351\235\242\350\257\225\351\242\23029. \351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23029. \351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265/README.md" index 929cdce9d9f7a..c91788e2f795f 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23029. \351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23029. \351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265/README.md" @@ -53,6 +53,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def spiralOrder(self, matrix: List[List[int]]) -> List[int]: @@ -74,6 +76,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] spiralOrder(int[][] matrix) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func spiralOrder(matrix [][]int) []int { if len(matrix) == 0 || len(matrix[0]) == 0 { @@ -159,6 +167,8 @@ func spiralOrder(matrix [][]int) []int { } ``` +#### TypeScript + ```ts var spiralOrder = (matrix: number[][]): number[] => { let ans: number[] = []; @@ -185,6 +195,8 @@ var spiralOrder = (matrix: number[][]): number[] => { }; ``` +#### Rust + ```rust impl Solution { pub fn spiral_order(matrix: Vec>) -> Vec { @@ -233,6 +245,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix @@ -267,6 +281,8 @@ var spiralOrder = function (matrix) { }; ``` +#### C# + ```cs public class Solution { public int[] SpiralOrder(int[][] matrix) { @@ -324,6 +340,8 @@ public class Solution { +#### Python3 + ```python class Solution: def spiralOrder(self, matrix: List[List[int]]) -> List[int]: @@ -342,6 +360,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] spiralOrder(int[][] matrix) { @@ -377,6 +397,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -404,6 +426,8 @@ public: }; ``` +#### Go + ```go func spiralOrder(matrix [][]int) []int { if len(matrix) == 0 || len(matrix[0]) == 0 { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23030. \345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23030. \345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/README.md" index f548c50e64696..c0920da92f184 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23030. \345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23030. \345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/README.md" @@ -57,6 +57,8 @@ minStack.min(); --> 返回 -2. +#### Python3 + ```python class MinStack: def __init__(self): @@ -90,6 +92,8 @@ class MinStack: +#### Java + ```java class MinStack { private Deque stk1 = new ArrayDeque<>(); @@ -131,6 +135,8 @@ class MinStack { ### **C++** +#### C++ + ```cpp class MinStack { public: @@ -174,6 +180,8 @@ private: ### **Go** +#### Go + ```go type MinStack struct { stk1 []int @@ -215,6 +223,8 @@ func (this *MinStack) GetMin() int { ### **TypeScript** +#### TypeScript + ```ts class MinStack { stack: number[]; @@ -255,6 +265,8 @@ class MinStack { ### **Rust** +#### Rust + ```rust use std::collections::VecDeque; struct MinStack { @@ -305,6 +317,8 @@ impl MinStack { ### **C#** +#### C# + ```cs public class MinStack { private Stack stk1 = new Stack(); @@ -364,6 +378,8 @@ public class MinStack { +#### Python3 + ```python class MinStack: def __init__(self): @@ -393,6 +409,8 @@ class MinStack: # param_4 = obj.getMin() ``` +#### Java + ```java class MinStack { private Deque stk1 = new ArrayDeque<>(); @@ -432,6 +450,8 @@ class MinStack { */ ``` +#### C++ + ```cpp class MinStack { public: @@ -473,6 +493,8 @@ private: */ ``` +#### Go + ```go type MinStack struct { stk1 []int @@ -512,6 +534,8 @@ func (this *MinStack) GetMin() int { */ ``` +#### TypeScript + ```ts class MinStack { stack: number[]; @@ -550,6 +574,8 @@ class MinStack { */ ``` +#### Rust + ```rust use std::collections::VecDeque; struct MinStack { @@ -598,6 +624,8 @@ impl MinStack { */ ``` +#### JavaScript + ```js /** * initialize your data structure here. @@ -651,6 +679,8 @@ MinStack.prototype.min = function () { */ ``` +#### C# + ```cs public class MinStack { private Stack stk1 = new Stack(); diff --git "a/lcof/\351\235\242\350\257\225\351\242\23031. \346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23031. \346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227/README.md" index a157007e7f45b..b79a3701dc30c 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23031. \346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23031. \346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227/README.md" @@ -60,6 +60,8 @@ push(5), pop() -> 5, pop() -> 3, pop() -> 2, pop() -> 1 +#### Python3 + ```python class Solution: def validateStackSequences(self, pushed: List[int], popped: List[int]) -> bool: @@ -72,6 +74,8 @@ class Solution: return j == len(pushed) ``` +#### Java + ```java class Solution { public boolean validateStackSequences(int[] pushed, int[] popped) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func validateStackSequences(pushed []int, popped []int) bool { stk := []int{} @@ -122,6 +130,8 @@ func validateStackSequences(pushed []int, popped []int) bool { } ``` +#### TypeScript + ```ts function validateStackSequences(pushed: number[], popped: number[]): boolean { const stk = []; @@ -137,6 +147,8 @@ function validateStackSequences(pushed: number[], popped: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn validate_stack_sequences(pushed: Vec, popped: Vec) -> bool { @@ -154,6 +166,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} pushed @@ -174,6 +188,8 @@ var validateStackSequences = function (pushed, popped) { }; ``` +#### C# + ```cs public class Solution { public bool ValidateStackSequences(int[] pushed, int[] popped) { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23032 - I. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23032 - I. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/README.md" index 1b73f52ccc63f..cb59cd46a82cd 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23032 - I. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23032 - I. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/README.md" @@ -53,6 +53,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -79,6 +81,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -185,6 +193,8 @@ func levelOrder(root *TreeNode) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -216,6 +226,8 @@ function levelOrder(root: TreeNode | null): number[] { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -260,6 +272,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -290,6 +304,8 @@ var levelOrder = function (root) { }; ``` +#### C# + ```cs /** * Definition for a binary tree node. diff --git "a/lcof/\351\235\242\350\257\225\351\242\23032 - II. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221 II/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23032 - II. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221 II/README.md" index a84eaa9c6af87..5abd0fc0fdcb3 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23032 - II. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221 II/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23032 - II. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221 II/README.md" @@ -64,6 +64,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -194,6 +202,8 @@ func levelOrder(root *TreeNode) (ans [][]int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -230,6 +240,8 @@ function levelOrder(root: TreeNode | null): number[][] { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -281,6 +293,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -313,6 +327,8 @@ var levelOrder = function (root) { }; ``` +#### C# + ```cs /** * Definition for a binary tree node. diff --git "a/lcof/\351\235\242\350\257\225\351\242\23032 - III. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221 III/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23032 - III. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221 III/README.md" index 5d238f2d5d32c..4ab03e4237ee2 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23032 - III. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221 III/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23032 - III. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221 III/README.md" @@ -57,6 +57,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -205,6 +213,8 @@ func levelOrder(root *TreeNode) (ans [][]int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -243,6 +253,8 @@ function levelOrder(root: TreeNode | null): number[][] { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -299,6 +311,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -334,6 +348,8 @@ var levelOrder = function (root) { }; ``` +#### C# + ```cs /** * Definition for a binary tree node. diff --git "a/lcof/\351\235\242\350\257\225\351\242\23033. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23033. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227/README.md" index eb80df2e3a572..c7999fe246a86 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23033. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23033. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227/README.md" @@ -56,6 +56,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def verifyPostorder(self, postorder: List[int]) -> bool: @@ -73,6 +75,8 @@ class Solution: return dfs(0, len(postorder) - 1) ``` +#### Java + ```java class Solution { private int[] postorder; @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func verifyPostorder(postorder []int) bool { var dfs func(l, r int) bool @@ -149,6 +157,8 @@ func verifyPostorder(postorder []int) bool { } ``` +#### TypeScript + ```ts function verifyPostorder(postorder: number[]): boolean { const dfs = (l: number, r: number): boolean => { @@ -171,6 +181,8 @@ function verifyPostorder(postorder: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { fn dfs(start: usize, end: usize, max_val: i32, postorder: &Vec) -> bool { @@ -199,6 +211,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} postorder @@ -225,6 +239,8 @@ var verifyPostorder = function (postorder) { }; ``` +#### C# + ```cs public class Solution { private int[] postorder; @@ -280,6 +296,8 @@ public class Solution { +#### Python3 + ```python class Solution: def verifyPostorder(self, postorder: List[int]) -> bool: @@ -294,6 +312,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean verifyPostorder(int[] postorder) { @@ -314,6 +334,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -336,6 +358,8 @@ public: }; ``` +#### Go + ```go func verifyPostorder(postorder []int) bool { mx := 1 << 30 @@ -355,6 +379,8 @@ func verifyPostorder(postorder []int) bool { } ``` +#### TypeScript + ```ts function verifyPostorder(postorder: number[]): boolean { let mx = 1 << 30; @@ -373,6 +399,8 @@ function verifyPostorder(postorder: number[]): boolean { } ``` +#### JavaScript + ```js /** * @param {number[]} postorder diff --git "a/lcof/\351\235\242\350\257\225\351\242\23034. \344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23034. \344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204/README.md" index 3116d476bd1c4..0736d354d4db4 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23034. \344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23034. \344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204/README.md" @@ -69,6 +69,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -202,6 +210,8 @@ func pathSum(root *TreeNode, target int) (ans [][]int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -241,6 +251,8 @@ function pathSum(root: TreeNode | null, target: number): number[][] { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -290,6 +302,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -325,6 +339,8 @@ var pathSum = function (root, target) { }; ``` +#### C# + ```cs /** * Definition for a binary tree node. @@ -374,6 +390,8 @@ public class Solution { +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git "a/lcof/\351\235\242\350\257\225\351\242\23035. \345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23035. \345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266/README.md" index e5c1013dcf009..9f0560bf463b7 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23035. \345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23035. \345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266/README.md" @@ -79,6 +79,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python """ # Definition for a Node. @@ -109,6 +111,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /* // Definition for a Node. @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -209,6 +217,8 @@ func copyRandomList(head *Node) *Node { } ``` +#### JavaScript + ```js /** * // Definition for a Node. @@ -241,6 +251,8 @@ var copyRandomList = function (head) { }; ``` +#### C# + ```cs /* // Definition for a Node. @@ -295,6 +307,8 @@ public class Solution { +#### Python3 + ```python """ # Definition for a Node. @@ -332,6 +346,8 @@ class Solution: return ans ``` +#### Java + ```java /* // Definition for a Node. @@ -375,6 +391,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -421,6 +439,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -457,6 +477,8 @@ func copyRandomList(head *Node) *Node { } ``` +#### JavaScript + ```js /** * // Definition for a Node. @@ -497,6 +519,8 @@ var copyRandomList = function (head) { }; ``` +#### C# + ```cs /* // Definition for a Node. diff --git "a/lcof/\351\235\242\350\257\225\351\242\23036. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23036. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250/README.md" index 1fda83f158a89..181e2fc01e3d5 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23036. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23036. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250/README.md" @@ -58,6 +58,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python """ # Definition for a Node. @@ -93,6 +95,8 @@ class Solution: return head ``` +#### Java + ```java /* // Definition for a Node. @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -200,6 +206,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -237,6 +245,8 @@ func treeToDoublyList(root *Node) *Node { } ``` +#### JavaScript + ```js /** * // Definition for a Node. @@ -277,6 +287,8 @@ var treeToDoublyList = function (root) { }; ``` +#### C# + ```cs /* // Definition for a Node. diff --git "a/lcof/\351\235\242\350\257\225\351\242\23037. \345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23037. \345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221/README.md" index 7ce89c9c994ee..f92093504146b 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23037. \345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23037. \345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221/README.md" @@ -47,6 +47,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode(object): @@ -107,6 +109,8 @@ class Codec: # codec.deserialize(codec.serialize(root)) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -172,6 +176,8 @@ public class Codec { // codec.deserialize(codec.serialize(root)); ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -239,6 +245,8 @@ public: // codec.deserialize(codec.serialize(root)); ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -313,6 +321,8 @@ func (this *Codec) deserialize(data string) *TreeNode { */ ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -378,6 +388,8 @@ var deserialize = function (data) { */ ``` +#### C# + ```cs /** * Definition for a binary tree node. @@ -446,6 +458,8 @@ public class Codec { +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -499,6 +513,8 @@ public: // codec.deserialize(codec.serialize(root)); ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -564,6 +580,8 @@ var deserialize = function (data) { +#### C++ + ```cpp /** * Definition for a binary tree node. diff --git "a/lcof/\351\235\242\350\257\225\351\242\23038. \345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23038. \345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227/README.md" index ab09bfdb67a17..99dca7b2cf85d 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23038. \345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23038. \345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227/README.md" @@ -55,6 +55,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def permutation(self, s: str) -> List[str]: @@ -76,6 +78,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List ans = new ArrayList<>(); @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func permutation(s string) (ans []string) { cs := []byte(s) @@ -160,6 +168,8 @@ func permutation(s string) (ans []string) { } ``` +#### TypeScript + ```ts function permutation(s: string): string[] { const n = s.length; @@ -182,6 +192,8 @@ function permutation(s: string): string[] { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -210,6 +222,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -239,6 +253,8 @@ var permutation = function (s) { }; ``` +#### C# + ```cs public class Solution { private char[] cs; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23039. \346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23039. \346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227/README.md" index 07c9b0ad8ce4d..dcdb05749243a 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23039. \346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23039. \346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227/README.md" @@ -59,6 +59,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def majorityElement(self, nums: List[int]) -> int: @@ -71,6 +73,8 @@ class Solution: return m ``` +#### Java + ```java class Solution { public int majorityElement(int[] nums) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func majorityElement(nums []int) int { cnt, m := 0, 0 @@ -123,6 +131,8 @@ func majorityElement(nums []int) int { } ``` +#### Rust + ```rust impl Solution { pub fn majority_element(nums: Vec) -> i32 { @@ -141,6 +151,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -161,6 +173,8 @@ var majorityElement = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int MajorityElement(int[] nums) { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/README.md" index 44e303b0cf788..b5a7a183bb539 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/README.md" @@ -50,6 +50,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def getLeastNumbers(self, arr: List[int], k: int) -> List[int]: @@ -57,6 +59,8 @@ class Solution: return arr[:k] ``` +#### Java + ```java class Solution { public int[] getLeastNumbers(int[] arr, int k) { @@ -70,6 +74,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -80,6 +86,8 @@ public: }; ``` +#### Go + ```go func getLeastNumbers(arr []int, k int) []int { sort.Ints(arr) @@ -87,6 +95,8 @@ func getLeastNumbers(arr []int, k int) []int { } ``` +#### TypeScript + ```ts function getLeastNumbers(arr: number[], k: number): number[] { let start = 0; @@ -114,6 +124,8 @@ function getLeastNumbers(arr: number[], k: number): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn get_least_numbers(mut arr: Vec, k: i32) -> Vec { @@ -142,6 +154,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} arr @@ -183,6 +197,8 @@ var getLeastNumbers = function (arr, k) { }; ``` +#### C# + ```cs public class Solution { public int[] GetLeastNumbers(int[] arr, int k) { @@ -208,6 +224,8 @@ public class Solution { +#### Python3 + ```python class Solution: def getLeastNumbers(self, arr: List[int], k: int) -> List[int]: @@ -219,6 +237,8 @@ class Solution: return [-x for x in h] ``` +#### Java + ```java class Solution { public int[] getLeastNumbers(int[] arr, int k) { @@ -238,6 +258,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -259,6 +281,8 @@ public: }; ``` +#### Go + ```go func getLeastNumbers(arr []int, k int) (ans []int) { q := hp{} @@ -302,6 +326,8 @@ func (h *hp) pop() int { return heap.Pop(h).(int) } +#### Python3 + ```python class Solution: def getLeastNumbers(self, arr: List[int], k: int) -> List[int]: @@ -324,6 +350,8 @@ class Solution: return arr if k == n else quick_sort(0, n - 1) ``` +#### Java + ```java class Solution { private int[] arr; @@ -365,6 +393,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -395,6 +425,8 @@ public: }; ``` +#### Go + ```go func getLeastNumbers(arr []int, k int) []int { n := len(arr) diff --git "a/lcof/\351\235\242\350\257\225\351\242\23041. \346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23041. \346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260/README.md" index cd8182c44f7e5..6ae0884ee404b 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23041. \346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23041. \346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260/README.md" @@ -70,6 +70,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class MedianFinder: def __init__(self): @@ -97,6 +99,8 @@ class MedianFinder: # param_2 = obj.findMedian() ``` +#### Java + ```java class MedianFinder { private PriorityQueue q1 = new PriorityQueue<>(); @@ -132,6 +136,8 @@ class MedianFinder { */ ``` +#### C++ + ```cpp class MedianFinder { public: @@ -171,6 +177,8 @@ private: */ ``` +#### Go + ```go type MedianFinder struct { q1, q2 hp @@ -217,6 +225,8 @@ func (h *hp) Pop() any { */ ``` +#### TypeScript + ```ts class MedianFinder { private nums: number[]; @@ -258,6 +268,8 @@ class MedianFinder { */ ``` +#### Rust + ```rust struct MedianFinder { nums: Vec, @@ -302,6 +314,8 @@ impl MedianFinder { */ ``` +#### JavaScript + ```js /** * initialize your data structure here. @@ -337,6 +351,8 @@ MedianFinder.prototype.findMedian = function () { }; ``` +#### C# + ```cs public class MedianFinder { private List nums; @@ -406,6 +422,8 @@ public class MedianFinder { +#### Python3 + ```python from sortedcontainers import SortedList diff --git "a/lcof/\351\235\242\350\257\225\351\242\23042. \350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23042. \350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214/README.md" index e954994e53d7b..369dc1ba61592 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23042. \350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23042. \350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214/README.md" @@ -69,6 +69,8 @@ $$ +#### Python3 + ```python class Solution: def maxSubArray(self, nums: List[int]) -> int: @@ -79,6 +81,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxSubArray(int[] nums) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func maxSubArray(nums []int) int { ans, f := -1000000000, 0 @@ -119,6 +127,8 @@ func maxSubArray(nums []int) int { } ``` +#### TypeScript + ```ts function maxSubArray(nums: number[]): number { let res = nums[0]; @@ -130,6 +140,8 @@ function maxSubArray(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_sub_array(mut nums: Vec) -> i32 { @@ -143,6 +155,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -159,6 +173,8 @@ var maxSubArray = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int MaxSubArray(int[] nums) { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23043. 1\357\275\236n\346\225\264\346\225\260\344\270\2551\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23043. 1\357\275\236n\346\225\264\346\225\260\344\270\2551\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/README.md" index 8fd85c8fd5679..269738e9bd030 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23043. 1\357\275\236n\346\225\264\346\225\260\344\270\2551\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23043. 1\357\275\236n\346\225\264\346\225\260\344\270\2551\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/README.md" @@ -87,6 +87,8 @@ $$ +#### Python3 + ```python class Solution: def countDigitOne(self, n: int) -> int: @@ -107,6 +109,8 @@ class Solution: return dfs(len(a) - 1, 0, True) ``` +#### Java + ```java class Solution { private int[] a = new int[12]; @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func countDigitOne(n int) int { a := [12]int{} @@ -208,6 +216,8 @@ func countDigitOne(n int) int { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -236,6 +246,8 @@ var countDigitOne = function (n) { }; ``` +#### C# + ```cs public class Solution { public int CountDigitOne(int n) { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23044. \346\225\260\345\255\227\345\272\217\345\210\227\344\270\255\346\237\220\344\270\200\344\275\215\347\232\204\346\225\260\345\255\227/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23044. \346\225\260\345\255\227\345\272\217\345\210\227\344\270\255\346\237\220\344\270\200\344\275\215\347\232\204\346\225\260\345\255\227/README.md" index f93a9779f7a75..64ddca1e68cd6 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23044. \346\225\260\345\255\227\345\272\217\345\210\227\344\270\255\346\237\220\344\270\200\344\275\215\347\232\204\346\225\260\345\255\227/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23044. \346\225\260\345\255\227\345\272\217\345\210\227\344\270\255\346\237\220\344\270\200\344\275\215\347\232\204\346\225\260\345\255\227/README.md" @@ -59,6 +59,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def findNthDigit(self, n: int) -> int: @@ -72,6 +74,8 @@ class Solution: return int(str(num)[idx]) ``` +#### Java + ```java class Solution { public int findNthDigit(int n) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func findNthDigit(n int) int { k, cnt := 1, 9 @@ -119,6 +127,8 @@ func findNthDigit(n int) int { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -138,6 +148,8 @@ var findNthDigit = function (n) { }; ``` +#### C# + ```cs public class Solution { public int FindNthDigit(int n) { @@ -164,6 +176,8 @@ public class Solution { +#### Python3 + ```python class Solution: def findNthDigit(self, n: int) -> int: @@ -179,6 +193,8 @@ class Solution: return int(str(x)[n % k]) ``` +#### Java + ```java class Solution { public int findNthDigit(int n) { @@ -198,6 +214,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -218,6 +236,8 @@ public: }; ``` +#### Go + ```go func findNthDigit(n int) int { if n < 10 { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23045. \346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23045. \346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260/README.md" index 58462ad7a60b5..fab74aa17bb60 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23045. \346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23045. \346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260/README.md" @@ -55,6 +55,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def minNumber(self, nums: List[int]) -> str: @@ -67,6 +69,8 @@ class Solution: return "".join(ans) ``` +#### Java + ```java class Solution { public String minNumber(int[] nums) { @@ -79,6 +83,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -99,6 +105,8 @@ public: }; ``` +#### Go + ```go func minNumber(nums []int) string { arr := []string{} @@ -110,12 +118,16 @@ func minNumber(nums []int) string { } ``` +#### TypeScript + ```ts function minNumber(nums: number[]): string { return nums.sort((a, b) => Number(`${a}${b}`) - Number(`${b}${a}`)).join(''); } ``` +#### Rust + ```rust impl Solution { pub fn min_number(mut nums: Vec) -> String { @@ -127,6 +139,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -142,6 +156,8 @@ var minNumber = function (nums) { }; ``` +#### C# + ```cs public class Solution { public string MinNumber(int[] nums) { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23046. \346\212\212\346\225\260\345\255\227\347\277\273\350\257\221\346\210\220\345\255\227\347\254\246\344\270\262/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23046. \346\212\212\346\225\260\345\255\227\347\277\273\350\257\221\346\210\220\345\255\227\347\254\246\344\270\262/README.md" index fdff487e0819b..bc4507327b5fb 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23046. \346\212\212\346\225\260\345\255\227\347\277\273\350\257\221\346\210\220\345\255\227\347\254\246\344\270\262/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23046. \346\212\212\346\225\260\345\255\227\347\277\273\350\257\221\346\210\220\345\255\227\347\254\246\344\270\262/README.md" @@ -53,6 +53,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def translateNum(self, num: int) -> int: @@ -70,6 +72,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private int n; @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func translateNum(num int) int { s := strconv.Itoa(num) @@ -148,6 +156,8 @@ func translateNum(num int) int { } ``` +#### TypeScript + ```ts function translateNum(num: number): number { const s = num.toString(); @@ -171,6 +181,8 @@ function translateNum(num: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn translate_num(num: i32) -> i32 { @@ -190,6 +202,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} num @@ -217,6 +231,8 @@ var translateNum = function (num) { }; ``` +#### C# + ```cs public class Solution { public int TranslateNum(int num) { @@ -256,6 +272,8 @@ public class Solution { +#### Python3 + ```python class Solution: def translateNum(self, num: int) -> int: @@ -270,6 +288,8 @@ class Solution: return b ``` +#### Java + ```java class Solution { public int translateNum(int num) { @@ -289,6 +309,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -309,6 +331,8 @@ public: }; ``` +#### Go + ```go func translateNum(num int) int { s := strconv.Itoa(num) @@ -325,6 +349,8 @@ func translateNum(num int) int { } ``` +#### TypeScript + ```ts function translateNum(num: number): number { const s = num.toString(); @@ -343,6 +369,8 @@ function translateNum(num: number): number { } ``` +#### Rust + ```rust impl Solution { fn dfs(s: &String, i: usize, res: &mut i32) { @@ -366,6 +394,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} num diff --git "a/lcof/\351\235\242\350\257\225\351\242\23047. \347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23047. \347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274/README.md" index fa063be79f863..c0fa9ad135a9f 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23047. \347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23047. \347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274/README.md" @@ -58,6 +58,8 @@ $$ +#### Python3 + ```python class Solution: def maxValue(self, grid: List[List[int]]) -> int: @@ -69,6 +71,8 @@ class Solution: return f[m][n] ``` +#### Java + ```java class Solution { public int maxValue(int[][] grid) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -100,6 +106,8 @@ public: }; ``` +#### Go + ```go func maxValue(grid [][]int) int { m, n := len(grid), len(grid[0]) @@ -116,6 +124,8 @@ func maxValue(grid [][]int) int { } ``` +#### TypeScript + ```ts function maxValue(grid: number[][]): number { const m = grid.length; @@ -130,6 +140,8 @@ function maxValue(grid: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_value(mut grid: Vec>) -> i32 { @@ -151,6 +163,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} grid @@ -169,6 +183,8 @@ var maxValue = function (grid) { }; ``` +#### C# + ```cs public class Solution { public int MaxValue(int[][] grid) { @@ -194,6 +210,8 @@ public class Solution { +#### Python3 + ```python class Solution: def maxValue(self, grid: List[List[int]]) -> int: @@ -205,6 +223,8 @@ class Solution: return f[m & 1][n] ``` +#### Java + ```java class Solution { public int maxValue(int[][] grid) { @@ -220,6 +240,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -236,6 +258,8 @@ public: }; ``` +#### Go + ```go func maxValue(grid [][]int) int { m, n := len(grid), len(grid[0]) @@ -252,6 +276,8 @@ func maxValue(grid [][]int) int { } ``` +#### TypeScript + ```ts function maxValue(grid: number[][]): number { const m = grid.length; @@ -266,6 +292,8 @@ function maxValue(grid: number[][]): number { } ``` +#### JavaScript + ```js /** * @param {number[][]} grid diff --git "a/lcof/\351\235\242\350\257\225\351\242\23048. \346\234\200\351\225\277\344\270\215\345\220\253\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23048. \346\234\200\351\225\277\344\270\215\345\220\253\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262/README.md" index 2533d516fae47..02c373e77e5ee 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23048. \346\234\200\351\225\277\344\270\215\345\220\253\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23048. \346\234\200\351\225\277\344\270\215\345\220\253\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262/README.md" @@ -66,6 +66,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def lengthOfLongestSubstring(self, s: str) -> int: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int lengthOfLongestSubstring(String s) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func lengthOfLongestSubstring(s string) (ans int) { vis := map[byte]bool{} @@ -131,6 +139,8 @@ func lengthOfLongestSubstring(s string) (ans int) { } ``` +#### TypeScript + ```ts function lengthOfLongestSubstring(s: string): number { let ans = 0; @@ -146,6 +156,8 @@ function lengthOfLongestSubstring(s: string): number { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -168,6 +180,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -187,6 +201,8 @@ var lengthOfLongestSubstring = function (s) { }; ``` +#### C# + ```cs public class Solution { public int LengthOfLongestSubstring(string s) { @@ -214,6 +230,8 @@ public class Solution { +#### Python3 + ```python class Solution: def lengthOfLongestSubstring(self, s: str) -> int: @@ -228,6 +246,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int lengthOfLongestSubstring(String s) { @@ -247,6 +267,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -266,6 +288,8 @@ public: }; ``` +#### Go + ```go func lengthOfLongestSubstring(s string) (ans int) { ss := make([]bool, 128) @@ -282,6 +306,8 @@ func lengthOfLongestSubstring(s string) (ans int) { } ``` +#### TypeScript + ```ts function lengthOfLongestSubstring(s: string): number { let ans = 0; @@ -298,6 +324,8 @@ function lengthOfLongestSubstring(s: string): number { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23049. \344\270\221\346\225\260/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23049. \344\270\221\346\225\260/README.md" index acba587cfe504..935a6b06b2899 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23049. \344\270\221\346\225\260/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23049. \344\270\221\346\225\260/README.md" @@ -45,6 +45,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def nthUglyNumber(self, n: int) -> int: @@ -61,6 +63,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int nthUglyNumber(int n) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func nthUglyNumber(n int) int { h := IntHeap([]int{1}) @@ -146,6 +154,8 @@ func (h *IntHeap) Pop() any { } ``` +#### Rust + ```rust impl Solution { pub fn nth_ugly_number(n: i32) -> i32 { @@ -175,6 +185,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -199,6 +211,8 @@ var nthUglyNumber = function (n) { }; ``` +#### C# + ```cs public class Solution { public int NthUglyNumber(int n) { @@ -243,6 +257,8 @@ public class Solution { +#### Python3 + ```python class Solution: def nthUglyNumber(self, n: int) -> int: @@ -260,6 +276,8 @@ class Solution: return dp[-1] ``` +#### Java + ```java class Solution { public int nthUglyNumber(int n) { @@ -278,6 +296,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -297,6 +317,8 @@ public: }; ``` +#### Go + ```go func nthUglyNumber(n int) int { dp := make([]int, n) diff --git "a/lcof/\351\235\242\350\257\225\351\242\23050. \347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23050. \347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/README.md" index d99097dc4ec5b..78cf97b3cc117 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23050. \347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23050. \347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/README.md" @@ -48,6 +48,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def firstUniqChar(self, s: str) -> str: @@ -58,6 +60,8 @@ class Solution: return " " ``` +#### Java + ```java class Solution { public char firstUniqChar(String s) { @@ -76,6 +80,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -94,6 +100,8 @@ public: }; ``` +#### Go + ```go func firstUniqChar(s string) byte { cnt := [26]int{} @@ -109,6 +117,8 @@ func firstUniqChar(s string) byte { } ``` +#### TypeScript + ```ts function firstUniqChar(s: string): string { const map = new Map(); @@ -124,6 +134,8 @@ function firstUniqChar(s: string): string { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { @@ -142,6 +154,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -161,6 +175,8 @@ var firstUniqChar = function (s) { }; ``` +#### C# + ```cs public class Solution { public char FirstUniqChar(string s) { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23051. \346\225\260\347\273\204\344\270\255\347\232\204\351\200\206\345\272\217\345\257\271/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23051. \346\225\260\347\273\204\344\270\255\347\232\204\351\200\206\345\272\217\345\257\271/README.md" index 908350aa66c87..12f5176d38895 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23051. \346\225\260\347\273\204\344\270\255\347\232\204\351\200\206\345\272\217\345\257\271/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23051. \346\225\260\347\273\204\344\270\255\347\232\204\351\200\206\345\272\217\345\257\271/README.md" @@ -41,6 +41,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def reversePairs(self, nums: List[int]) -> int: @@ -67,6 +69,8 @@ class Solution: return merge_sort(0, len(nums) - 1) ``` +#### Java + ```java class Solution { private int[] nums; @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func reversePairs(nums []int) int { n := len(nums) @@ -185,6 +193,8 @@ func reversePairs(nums []int) int { } ``` +#### TypeScript + ```ts function reversePairs(nums: number[]): number { const mergeSort = (l: number, r: number): number => { @@ -219,6 +229,8 @@ function reversePairs(nums: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -257,6 +269,8 @@ var reversePairs = function (nums) { }; ``` +#### C# + ```cs public class Solution { private int[] nums; @@ -321,6 +335,8 @@ public class Solution { +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -353,6 +369,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int reversePairs(int[] nums) { @@ -403,6 +421,8 @@ class BinaryIndexedTree { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -448,6 +468,8 @@ public: }; ``` +#### Go + ```go func reversePairs(nums []int) (ans int) { s := map[int]bool{} diff --git "a/lcof/\351\235\242\350\257\225\351\242\23052. \344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23052. \344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271/README.md" index 6265c3619fc0f..00166de622f77 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23052. \344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23052. \344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271/README.md" @@ -80,6 +80,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -97,6 +99,8 @@ class Solution: return a ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -169,6 +177,8 @@ func getIntersectionNode(headA, headB *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -193,6 +203,8 @@ function getIntersectionNode(headA: ListNode | null, headB: ListNode | null): Li } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -218,6 +230,8 @@ var getIntersectionNode = function (headA, headB) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. diff --git "a/lcof/\351\235\242\350\257\225\351\242\23053 - I. \345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\346\225\260\345\255\227 I/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23053 - I. \345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\346\225\260\345\255\227 I/README.md" index a7b57407e527a..23ab5c1b6bdbb 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23053 - I. \345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\346\225\260\345\255\227 I/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23053 - I. \345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\346\225\260\345\255\227 I/README.md" @@ -56,6 +56,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def search(self, nums: List[int], target: int) -> int: @@ -64,6 +66,8 @@ class Solution: return r - l ``` +#### Java + ```java class Solution { public int search(int[] nums, int target) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -98,6 +104,8 @@ public: }; ``` +#### Go + ```go func search(nums []int, target int) int { l := sort.Search(len(nums), func(i int) bool { return nums[i] >= target }) @@ -106,6 +114,8 @@ func search(nums []int, target int) int { } ``` +#### Rust + ```rust impl Solution { pub fn search(nums: Vec, target: i32) -> i32 { @@ -127,6 +137,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -153,6 +165,8 @@ var search = function (nums, target) { }; ``` +#### C# + ```cs public class Solution { public int Search(int[] nums, int target) { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23053 - II. 0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23053 - II. 0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227/README.md" index 5ebd38d3bbebc..37d5ef58fb1ee 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23053 - II. 0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23053 - II. 0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227/README.md" @@ -50,6 +50,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def missingNumber(self, nums: List[int]) -> int: @@ -63,6 +65,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { public int missingNumber(int[] nums) { @@ -80,6 +84,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -98,6 +104,8 @@ public: }; ``` +#### Go + ```go func missingNumber(nums []int) int { l, r := 0, len(nums) @@ -113,6 +121,8 @@ func missingNumber(nums []int) int { } ``` +#### Rust + ```rust impl Solution { pub fn missing_number(nums: Vec) -> i32 { @@ -130,6 +140,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -150,6 +162,8 @@ var missingNumber = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int MissingNumber(int[] nums) { @@ -177,6 +191,8 @@ public class Solution { +#### Rust + ```rust impl Solution { pub fn missing_number(nums: Vec) -> i32 { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23054. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23054. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271/README.md" index e4da69c063f08..c0cbd61793288 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23054. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23054. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271/README.md" @@ -64,6 +64,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -180,6 +188,8 @@ func kthLargest(root *TreeNode, k int) (ans int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -213,6 +223,8 @@ function kthLargest(root: TreeNode | null, k: number): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -252,6 +264,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -282,6 +296,8 @@ var kthLargest = function (root, k) { }; ``` +#### C# + ```cs /** * Definition for a binary tree node. @@ -325,6 +341,8 @@ public class Solution { +#### Go + ```go /** * Definition for a binary tree node. diff --git "a/lcof/\351\235\242\350\257\225\351\242\23055 - I. \344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23055 - I. \344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/README.md" index a5cc95766de74..280c8f2da197d 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23055 - I. \344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23055 - I. \344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/README.md" @@ -50,6 +50,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -66,6 +68,8 @@ class Solution: return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right)) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -128,6 +136,8 @@ func maxDepth(root *TreeNode) int { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -164,6 +174,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -184,6 +196,8 @@ var maxDepth = function (root) { }; ``` +#### C# + ```cs /** * Definition for a binary tree node. @@ -214,6 +228,8 @@ public class Solution { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: diff --git "a/lcof/\351\235\242\350\257\225\351\242\23055 - II. \345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23055 - II. \345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/README.md" index d72ae100caa6f..656700fec7dba 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23055 - II. \345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23055 - II. \345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/README.md" @@ -80,6 +80,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -102,6 +104,8 @@ class Solution: return dfs(root) != -1 ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -192,6 +200,8 @@ func abs(x int) int { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -238,6 +248,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -266,6 +278,8 @@ var isBalanced = function (root) { }; ``` +#### C# + ```cs /** * Definition for a binary tree node. @@ -305,6 +319,8 @@ public class Solution { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: diff --git "a/lcof/\351\235\242\350\257\225\351\242\23056 - I. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23056 - I. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/README.md" index 2e32982b505c5..ad48541cad39b 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23056 - I. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23056 - I. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/README.md" @@ -55,6 +55,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def singleNumbers(self, nums: List[int]) -> List[int]: @@ -68,6 +70,8 @@ class Solution: return [a, b] ``` +#### Java + ```java class Solution { public int[] singleNumbers(int[] nums) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func singleNumbers(nums []int) []int { xs := 0 @@ -127,6 +135,8 @@ func singleNumbers(nums []int) []int { } ``` +#### TypeScript + ```ts function singleNumbers(nums: number[]): number[] { let xs = 0; @@ -145,6 +155,8 @@ function singleNumbers(nums: number[]): number[] { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -167,6 +179,8 @@ var singleNumbers = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int[] SingleNumbers(int[] nums) { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23056 - II. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260 II/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23056 - II. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260 II/README.md" index b5a637f8c07ee..4bc932c2cc16c 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23056 - II. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260 II/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23056 - II. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260 II/README.md" @@ -52,6 +52,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def singleNumber(self, nums: List[int]) -> int: @@ -63,6 +65,8 @@ class Solution: return sum(1 << i for i in range(32) if cnt[i] % 3) ``` +#### Java + ```java class Solution { public int singleNumber(int[] nums) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func singleNumber(nums []int) (ans int) { cnt := [32]int{} @@ -124,6 +132,8 @@ func singleNumber(nums []int) (ans int) { } ``` +#### Rust + ```rust impl Solution { pub fn single_number(nums: Vec) -> i32 { @@ -143,6 +153,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -166,6 +178,8 @@ var singleNumber = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int SingleNumber(int[] nums) { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23057 - II. \345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23057 - II. \345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227/README.md" index b7c524c9bc46e..7929eb5b73509 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23057 - II. \345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23057 - II. \345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227/README.md" @@ -58,6 +58,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def findContinuousSequence(self, target: int) -> List[List[int]]: @@ -75,6 +77,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] findContinuousSequence(int target) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func findContinuousSequence(target int) (ans [][]int) { l, r := 1, 2 @@ -146,6 +154,8 @@ func findContinuousSequence(target int) (ans [][]int) { } ``` +#### JavaScript + ```js /** * @param {number} target @@ -174,6 +184,8 @@ var findContinuousSequence = function (target) { }; ``` +#### C# + ```cs public class Solution { public int[][] FindContinuousSequence(int target) { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23057. \345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23057. \345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227/README.md" index d482828d6661a..f12d498bd1af7 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23057. \345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23057. \345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227/README.md" @@ -47,6 +47,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 ### **Python3** +#### Python3 + ```python class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: @@ -62,6 +64,8 @@ class Solution: ### **Java** +#### Java + ```java class Solution { public int[] twoSum(int[] nums, int target) { @@ -82,6 +86,8 @@ class Solution { ### **C++** +#### C++ + ```cpp class Solution { public: @@ -103,6 +109,8 @@ public: ### **Go** +#### Go + ```go func twoSum(nums []int, target int) []int { l, r := 0, len(nums)-1 @@ -121,6 +129,8 @@ func twoSum(nums []int, target int) []int { ### **JavaScript** +#### JavaScript + ```js /** * @param {number[]} nums @@ -145,6 +155,8 @@ var twoSum = function (nums, target) { ### **TypeScript** +#### TypeScript + ```ts function twoSum(nums: number[], target: number): number[] { let l = 0; @@ -162,6 +174,8 @@ function twoSum(nums: number[], target: number): number[] { ### **Rust** +#### Rust + ```rust use std::cmp::Ordering; @@ -188,6 +202,8 @@ impl Solution { ### **C#** +#### C# + ```cs public class Solution { public int[] TwoSum(int[] nums, int target) { @@ -226,6 +242,8 @@ public class Solution { +#### Python3 + ```python class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: @@ -239,6 +257,8 @@ class Solution: l += 1 ``` +#### Java + ```java class Solution { public int[] twoSum(int[] nums, int target) { @@ -257,6 +277,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -276,6 +298,8 @@ public: }; ``` +#### Go + ```go func twoSum(nums []int, target int) []int { l, r := 0, len(nums)-1 @@ -292,6 +316,8 @@ func twoSum(nums []int, target int) []int { } ``` +#### TypeScript + ```ts function twoSum(nums: number[], target: number): number[] { let l = 0; @@ -307,6 +333,8 @@ function twoSum(nums: number[], target: number): number[] { } ``` +#### Rust + ```rust use std::cmp::Ordering; @@ -331,6 +359,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -353,6 +383,8 @@ var twoSum = function (nums, target) { }; ``` +#### C# + ```cs public class Solution { public int[] TwoSum(int[] nums, int target) { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23058 - I. \347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23058 - I. \347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217/README.md" index 6798538363544..74cba777d6b6d 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23058 - I. \347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23058 - I. \347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217/README.md" @@ -64,12 +64,16 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def reverseWords(self, s: str) -> str: return " ".join(s.strip().split()[::-1]) ``` +#### Java + ```java class Solution { public String reverseWords(String s) { @@ -85,6 +89,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func reverseWords(s string) string { s = strings.Trim(s, " ") @@ -129,12 +137,16 @@ func reverseWords(s string) string { } ``` +#### TypeScript + ```ts function reverseWords(s: string): string { return s.trim().split(/\s+/).reverse().join(' '); } ``` +#### Rust + ```rust impl Solution { pub fn reverse_words(mut s: String) -> String { @@ -149,6 +161,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -163,6 +177,8 @@ var reverseWords = function (s) { }; ``` +#### C# + ```cs public class Solution { public string ReverseWords(string s) { @@ -195,6 +211,8 @@ public class Solution { +#### TypeScript + ```ts function reverseWords(s: string): string { s = s.trim(); @@ -215,6 +233,8 @@ function reverseWords(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn reverse_words(s: String) -> String { @@ -237,6 +257,8 @@ impl Solution { +#### Rust + ```rust impl Solution { pub fn reverse_words(s: String) -> String { @@ -255,6 +277,8 @@ impl Solution { +#### Rust + ```rust impl Solution { pub fn reverse_words(mut s: String) -> String { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23058 - II. \345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23058 - II. \345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/README.md" index 43b44d48d43f7..763d8821f9130 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23058 - II. \345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23058 - II. \345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/README.md" @@ -50,12 +50,16 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def reverseLeftWords(self, s: str, n: int) -> str: return s[n:] + s[:n] ``` +#### Java + ```java class Solution { public String reverseLeftWords(String s, int n) { @@ -64,6 +68,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -73,12 +79,16 @@ public: }; ``` +#### Go + ```go func reverseLeftWords(s string, n int) string { return s[n:] + s[:n] } ``` +#### Rust + ```rust impl Solution { pub fn reverse_left_words(s: String, n: i32) -> String { @@ -88,6 +98,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -99,6 +111,8 @@ var reverseLeftWords = function (s, n) { }; ``` +#### C# + ```cs public class Solution { public string ReverseLeftWords(string s, int n) { @@ -117,6 +131,8 @@ public class Solution { +#### C++ + ```cpp class Solution { public: diff --git "a/lcof/\351\235\242\350\257\225\351\242\23059 - I. \346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\346\234\200\345\244\247\345\200\274/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23059 - I. \346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\346\234\200\345\244\247\345\200\274/README.md" index 4d91e0a77eb3d..dc8c30bb4b3ac 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23059 - I. \346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\346\234\200\345\244\247\345\200\274/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23059 - I. \346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\346\234\200\345\244\247\345\200\274/README.md" @@ -62,6 +62,8 @@ for i in range(n): +#### Python3 + ```python class Solution: def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] maxSlidingWindow(int[] nums, int k) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func maxSlidingWindow(nums []int, k int) (ans []int) { q := []int{} @@ -144,6 +152,8 @@ func maxSlidingWindow(nums []int, k int) (ans []int) { } ``` +#### TypeScript + ```ts function maxSlidingWindow(nums: number[], k: number): number[] { const q: number[] = []; @@ -165,6 +175,8 @@ function maxSlidingWindow(nums: number[], k: number): number[] { } ``` +#### Rust + ```rust use std::collections::VecDeque; impl Solution { @@ -190,6 +202,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -216,6 +230,8 @@ var maxSlidingWindow = function (nums, k) { }; ``` +#### C# + ```cs public class Solution { public int[] MaxSlidingWindow(int[] nums, int k) { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23059 - II. \351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23059 - II. \351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/README.md" index d849057232873..836c6955dc90f 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23059 - II. \351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23059 - II. \351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/README.md" @@ -61,6 +61,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class MaxQueue: def __init__(self): @@ -92,6 +94,8 @@ class MaxQueue: # param_3 = obj.pop_front() ``` +#### Java + ```java class MaxQueue { private Deque q1 = new ArrayDeque<>(); @@ -133,6 +137,8 @@ class MaxQueue { */ ``` +#### C++ + ```cpp class MaxQueue { public: @@ -177,6 +183,8 @@ private: */ ``` +#### Go + ```go type MaxQueue struct { q1, q2 []int @@ -222,6 +230,8 @@ func (this *MaxQueue) Pop_front() int { */ ``` +#### TypeScript + ```ts class MaxQueue { private queue: number[]; @@ -262,6 +272,8 @@ class MaxQueue { */ ``` +#### Rust + ```rust use std::collections::VecDeque; struct MaxQueue { @@ -312,6 +324,8 @@ impl MaxQueue { */ ``` +#### JavaScript + ```js var MaxQueue = function () { this.q1 = []; @@ -360,6 +374,8 @@ MaxQueue.prototype.pop_front = function () { */ ``` +#### C# + ```cs public class MaxQueue { LinkedList mvq; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23060. n\344\270\252\351\252\260\345\255\220\347\232\204\347\202\271\346\225\260/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23060. n\344\270\252\351\252\260\345\255\220\347\232\204\347\202\271\346\225\260/README.md" index cfad0b2272bc9..9d5b1d571b45e 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23060. n\344\270\252\351\252\260\345\255\220\347\232\204\347\202\271\346\225\260/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23060. n\344\270\252\351\252\260\345\255\220\347\232\204\347\202\271\346\225\260/README.md" @@ -61,6 +61,8 @@ $$ +#### Python3 + ```python class Solution: def dicesProbability(self, n: int) -> List[float]: @@ -76,6 +78,8 @@ class Solution: return [f[n][i] / m for i in range(n, 6 * n + 1)] ``` +#### Java + ```java class Solution { public double[] dicesProbability(int n) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func dicesProbability(n int) (ans []float64) { f := make([][]int, n+1) @@ -156,6 +164,8 @@ func dicesProbability(n int) (ans []float64) { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -184,6 +194,8 @@ var dicesProbability = function (n) { }; ``` +#### C# + ```cs public class Solution { public double[] DicesProbability(int n) { @@ -216,6 +228,8 @@ public class Solution { +#### Python3 + ```python class Solution: def dicesProbability(self, n: int) -> List[float]: @@ -231,6 +245,8 @@ class Solution: return [f[j] / m for j in range(n, 6 * n + 1)] ``` +#### Go + ```go func dicesProbability(n int) []float64 { dp := make([]float64, 7) diff --git "a/lcof/\351\235\242\350\257\225\351\242\23061. \346\211\221\345\205\213\347\211\214\344\270\255\347\232\204\351\241\272\345\255\220/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23061. \346\211\221\345\205\213\347\211\214\344\270\255\347\232\204\351\241\272\345\255\220/README.md" index c888621a4739c..3ff3d4efee8c2 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23061. \346\211\221\345\205\213\347\211\214\344\270\255\347\232\204\351\241\272\345\255\220/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23061. \346\211\221\345\205\213\347\211\214\344\270\255\347\232\204\351\241\272\345\255\220/README.md" @@ -57,6 +57,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def isStraight(self, nums: List[int]) -> bool: @@ -73,6 +75,8 @@ class Solution: return mx - mi <= 4 ``` +#### Java + ```java class Solution { public boolean isStraight(int[] nums) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func isStraight(nums []int) bool { vis := map[int]bool{} @@ -135,6 +143,8 @@ func isStraight(nums []int) bool { } ``` +#### TypeScript + ```ts function isStraight(nums: number[]): boolean { nums.sort((a, b) => a - b); @@ -150,6 +160,8 @@ function isStraight(nums: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn is_straight(mut nums: Vec) -> bool { @@ -167,6 +179,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -191,6 +205,8 @@ var isStraight = function (nums) { }; ``` +#### C# + ```cs public class Solution { public bool IsStraight(int[] nums) { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23062. \345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23062. \345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227/README.md" index d88ff0d0b7e10..0f0b6c9a4656e 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23062. \345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23062. \345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227/README.md" @@ -63,6 +63,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def lastRemaining(self, n: int, m: int) -> int: @@ -75,6 +77,8 @@ class Solution: return f(n, m) ``` +#### Java + ```java class Solution { public int lastRemaining(int n, int m) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func lastRemaining(n int, m int) int { var f func(n, m int) int @@ -122,6 +130,8 @@ func lastRemaining(n int, m int) int { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -137,6 +147,8 @@ var lastRemaining = function (n, m) { }; ``` +#### C# + ```cs public class Solution { public int LastRemaining(int n, int m) { @@ -159,6 +171,8 @@ public class Solution { +#### Python3 + ```python class Solution: def lastRemaining(self, n: int, m: int) -> int: @@ -168,6 +182,8 @@ class Solution: return f ``` +#### Java + ```java class Solution { public int lastRemaining(int n, int m) { @@ -180,6 +196,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -193,6 +211,8 @@ public: }; ``` +#### Go + ```go func lastRemaining(n int, m int) int { f := 0 diff --git "a/lcof/\351\235\242\350\257\225\351\242\23063. \350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23063. \350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246/README.md" index bb75daf4b0794..548bf95dd890a 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23063. \350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23063. \350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246/README.md" @@ -54,6 +54,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def maxProfit(self, prices: List[int]) -> int: @@ -64,6 +66,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxProfit(int[] prices) { @@ -77,6 +81,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -91,6 +97,8 @@ public: }; ``` +#### Go + ```go func maxProfit(prices []int) (ans int) { mi := 1 << 30 @@ -102,6 +110,8 @@ func maxProfit(prices []int) (ans int) { } ``` +#### TypeScript + ```ts function maxProfit(prices: number[]): number { let res = 0; @@ -114,6 +124,8 @@ function maxProfit(prices: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_profit(prices: Vec) -> i32 { @@ -128,6 +140,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} prices @@ -144,6 +158,8 @@ var maxProfit = function (prices) { }; ``` +#### C# + ```cs public class Solution { public int MaxProfit(int[] prices) { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/README.md" index 3f2234cdaee10..abb3d16bae1f6 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/README.md" @@ -46,12 +46,16 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def sumNums(self, n: int) -> int: return n and (n + self.sumNums(n - 1)) ``` +#### Java + ```java class Solution { public int sumNums(int n) { @@ -62,6 +66,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -72,6 +78,8 @@ public: }; ``` +#### Go + ```go func sumNums(n int) int { s := 0 @@ -85,12 +93,16 @@ func sumNums(n int) int { } ``` +#### TypeScript + ```ts var sumNums = function (n: number): number { return n && n + sumNums(n - 1); }; ``` +#### Rust + ```rust impl Solution { pub fn sum_nums(mut n: i32) -> i32 { @@ -106,6 +118,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -116,6 +130,8 @@ var sumNums = function (n) { }; ``` +#### C# + ```cs public class Solution { public int result; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23065. \344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23065. \344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/README.md" index ee61fa2967d22..8e5ac6922ce09 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23065. \344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23065. \344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/README.md" @@ -60,6 +60,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def add(self, a: int, b: int) -> int: @@ -70,6 +72,8 @@ class Solution: return a if a < 0x80000000 else ~(a ^ 0xFFFFFFFF) ``` +#### Java + ```java class Solution { public int add(int a, int b) { @@ -83,6 +87,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -97,6 +103,8 @@ public: }; ``` +#### Go + ```go func add(a int, b int) int { if b == 0 { @@ -106,6 +114,8 @@ func add(a int, b int) int { } ``` +#### TypeScript + ```ts function add(a: number, b: number): number { while (b) { @@ -117,6 +127,8 @@ function add(a: number, b: number): number { } ``` +#### JavaScript + ```js /** * @param {number} a @@ -131,6 +143,8 @@ var add = function (a, b) { }; ``` +#### C# + ```cs public class Solution { public int Add(int a, int b) { @@ -155,6 +169,8 @@ public class Solution { +#### Java + ```java class Solution { public int add(int a, int b) { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23066. \346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23066. \346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204/README.md" index 622f376cfea52..57c7b1ca3c6b7 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23066. \346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23066. \346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204/README.md" @@ -51,6 +51,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def constructArr(self, a: List[int]) -> List[int]: @@ -66,6 +68,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] constructArr(int[] a) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -103,6 +109,8 @@ public: }; ``` +#### Go + ```go func constructArr(a []int) []int { n := len(a) @@ -119,6 +127,8 @@ func constructArr(a []int) []int { } ``` +#### TypeScript + ```ts function constructArr(a: number[]): number[] { const n = a.length; @@ -135,6 +145,8 @@ function constructArr(a: number[]): number[] { } ``` +#### JavaScript + ```js /** * @param {number[]} a @@ -155,6 +167,8 @@ var constructArr = function (a) { }; ``` +#### C# + ```cs public class Solution { public int[] ConstructArr(int[] a) { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23067. \346\212\212\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\210\220\346\225\264\346\225\260/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23067. \346\212\212\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\210\220\346\225\264\346\225\260/README.md" index 0c29844fa3724..4688aa27dc263 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23067. \346\212\212\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\210\220\346\225\264\346\225\260/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23067. \346\212\212\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\210\220\346\225\264\346\225\260/README.md" @@ -80,6 +80,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python class Solution: def strToInt(self, str: str) -> int: @@ -111,6 +113,8 @@ class Solution: return sign * res ``` +#### Java + ```java class Solution { public int strToInt(String str) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### Go + ```go func strToInt(str string) int { n, sign, i, x := len(str), 1, 0, 0 @@ -186,6 +192,8 @@ func strToInt(str string) int { } ``` +#### JavaScript + ```js /** * @param {string} str @@ -213,6 +221,8 @@ var strToInt = function (str) { }; ``` +#### C# + ```cs public class Solution { public int StrToInt(string str) { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23068 - I. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23068 - I. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/README.md" index f25c5705aa7f1..b2c0307251537 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23068 - I. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23068 - I. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/README.md" @@ -60,6 +60,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -82,6 +84,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -152,6 +160,8 @@ func lowestCommonAncestor(root, p, q *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -184,6 +194,8 @@ function lowestCommonAncestor( } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -232,6 +244,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -266,6 +280,8 @@ var lowestCommonAncestor = function (root, p, q) { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -286,6 +302,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -309,6 +327,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -335,6 +355,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -358,6 +380,8 @@ func lowestCommonAncestor(root, p, q *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git "a/lcof/\351\235\242\350\257\225\351\242\23068 - II. \344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23068 - II. \344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/README.md" index 6579fb8cd9115..826848ea79387 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23068 - II. \344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23068 - II. \344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/README.md" @@ -72,6 +72,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -96,6 +98,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func lowestCommonAncestor(root, p, q *TreeNode) *TreeNode { if root == nil || root == p || root == q { @@ -170,6 +178,8 @@ func lowestCommonAncestor(root, p, q *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -207,6 +217,8 @@ function lowestCommonAncestor( } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -257,6 +269,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 001. \346\225\264\346\225\260\351\231\244\346\263\225/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 001. \346\225\264\346\225\260\351\231\244\346\263\225/README.md" index 1f790e890ce10..a3fd364995bde 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 001. \346\225\264\346\225\260\351\231\244\346\263\225/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 001. \346\225\264\346\225\260\351\231\244\346\263\225/README.md" @@ -82,6 +82,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def divide(self, a: int, b: int) -> int: @@ -104,6 +106,8 @@ class Solution: return ans if sign else -ans ``` +#### Java + ```java class Solution { public int divide(int a, int b) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func divide(a int, b int) int { if b == 1 { @@ -197,6 +205,8 @@ func divide(a int, b int) int { } ``` +#### TypeScript + ```ts function divide(a: number, b: number): number { if (b === 1) { @@ -228,6 +238,8 @@ function divide(a: number, b: number): number { } ``` +#### C# + ```cs public class Solution { public int Divide(int a, int b) { diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 002. \344\272\214\350\277\233\345\210\266\345\212\240\346\263\225/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 002. \344\272\214\350\277\233\345\210\266\345\212\240\346\263\225/README.md" index 66db83a18b5b0..2ba8943f6c7e1 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 002. \344\272\214\350\277\233\345\210\266\345\212\240\346\263\225/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 002. \344\272\214\350\277\233\345\210\266\345\212\240\346\263\225/README.md" @@ -57,12 +57,16 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def addBinary(self, a: str, b: str) -> str: return bin(int(a, 2) + int(b, 2))[2:] ``` +#### Java + ```java class Solution { public String addBinary(String a, String b) { @@ -78,6 +82,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -95,6 +101,8 @@ public: }; ``` +#### Go + ```go func addBinary(a string, b string) string { i, j := len(a)-1, len(b)-1 @@ -116,12 +124,16 @@ func addBinary(a string, b string) string { } ``` +#### TypeScript + ```ts function addBinary(a: string, b: string): string { return (BigInt('0b' + a) + BigInt('0b' + b)).toString(2); } ``` +#### Rust + ```rust impl Solution { pub fn add_binary(a: String, b: String) -> String { @@ -148,6 +160,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public string AddBinary(string a, string b) { @@ -177,6 +191,8 @@ public class Solution { +#### Python3 + ```python class Solution: def addBinary(self, a: str, b: str) -> str: @@ -190,6 +206,8 @@ class Solution: return ''.join(ans[::-1]) ``` +#### TypeScript + ```ts function addBinary(a: string, b: string): string { let i = a.length - 1; diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 003. \345\211\215 n \344\270\252\346\225\260\345\255\227\344\272\214\350\277\233\345\210\266\344\270\255 1 \347\232\204\344\270\252\346\225\260/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 003. \345\211\215 n \344\270\252\346\225\260\345\255\227\344\272\214\350\277\233\345\210\266\344\270\255 1 \347\232\204\344\270\252\346\225\260/README.md" index ca02529e4d890..502146f5e392d 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 003. \345\211\215 n \344\270\252\346\225\260\345\255\227\344\272\214\350\277\233\345\210\266\344\270\255 1 \347\232\204\344\270\252\346\225\260/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 003. \345\211\215 n \344\270\252\346\225\260\345\255\227\344\272\214\350\277\233\345\210\266\344\270\255 1 \347\232\204\344\270\252\346\225\260/README.md" @@ -80,6 +80,8 @@ $$ +#### Python3 + ```python class Solution: def countBits(self, n: int) -> List[int]: @@ -89,6 +91,8 @@ class Solution: return f ``` +#### Java + ```java class Solution { public int[] countBits(int n) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func countBits(n int) []int { f := make([]int, n+1) @@ -124,6 +132,8 @@ func countBits(n int) []int { } ``` +#### TypeScript + ```ts function countBits(n: number): number[] { const f: number[] = Array(n + 1).fill(0); diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 004. \345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 004. \345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227/README.md" index ad2b6854158b0..70f3bc69553fd 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 004. \345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 004. \345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227/README.md" @@ -61,6 +61,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def singleNumber(self, nums: List[int]) -> int: @@ -75,6 +77,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int singleNumber(int[] nums) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func singleNumber(nums []int) int { var ans int32 @@ -125,6 +133,8 @@ func singleNumber(nums []int) int { } ``` +#### TypeScript + ```ts function singleNumber(nums: number[]): number { let ans = 0; diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 005. \345\215\225\350\257\215\351\225\277\345\272\246\347\232\204\346\234\200\345\244\247\344\271\230\347\247\257/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 005. \345\215\225\350\257\215\351\225\277\345\272\246\347\232\204\346\234\200\345\244\247\344\271\230\347\247\257/README.md" index ee875a85c7ef6..02217ef72fa10 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 005. \345\215\225\350\257\215\351\225\277\345\272\246\347\232\204\346\234\200\345\244\247\344\271\230\347\247\257/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 005. \345\215\225\350\257\215\351\225\277\345\272\246\347\232\204\346\234\200\345\244\247\344\271\230\347\247\257/README.md" @@ -67,6 +67,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def maxProduct(self, words: List[str]) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxProduct(String[] words) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func maxProduct(words []string) (ans int) { n := len(words) @@ -150,6 +158,8 @@ func maxProduct(words []string) (ans int) { } ``` +#### TypeScript + ```ts function maxProduct(words: string[]): number { const n = words.length; diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 006. \346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\344\270\244\344\270\252\346\225\260\345\255\227\344\271\213\345\222\214/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 006. \346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\344\270\244\344\270\252\346\225\260\345\255\227\344\271\213\345\222\214/README.md" index b70d23300b748..dbe3f30ab2409 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 006. \346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\344\270\244\344\270\252\346\225\260\345\255\227\344\271\213\345\222\214/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 006. \346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\344\270\244\344\270\252\346\225\260\345\255\227\344\271\213\345\222\214/README.md" @@ -71,6 +71,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def twoSum(self, numbers: List[int], target: int) -> List[int]: @@ -82,6 +84,8 @@ class Solution: return [i, j] ``` +#### Java + ```java class Solution { public int[] twoSum(int[] numbers, int target) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func twoSum(numbers []int, target int) []int { for i, n := 0, len(numbers); ; i++ { @@ -131,6 +139,8 @@ func twoSum(numbers []int, target int) []int { } ``` +#### TypeScript + ```ts function twoSum(numbers: number[], target: number): number[] { const n = numbers.length; @@ -153,6 +163,8 @@ function twoSum(numbers: number[], target: number): number[] { } ``` +#### Rust + ```rust use std::cmp::Ordering; @@ -193,6 +205,8 @@ impl Solution { +#### Python3 + ```python class Solution: def twoSum(self, numbers: List[int], target: int) -> List[int]: @@ -207,6 +221,8 @@ class Solution: j -= 1 ``` +#### Java + ```java class Solution { public int[] twoSum(int[] numbers, int target) { @@ -225,6 +241,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -244,6 +262,8 @@ public: }; ``` +#### Go + ```go func twoSum(numbers []int, target int) []int { for i, j := 0, len(numbers)-1; ; { @@ -260,6 +280,8 @@ func twoSum(numbers []int, target int) []int { } ``` +#### TypeScript + ```ts function twoSum(numbers: number[], target: number): number[] { for (let i = 0, j = numbers.length - 1; ; ) { @@ -276,6 +298,8 @@ function twoSum(numbers: number[], target: number): number[] { } ``` +#### Rust + ```rust use std::cmp::Ordering; diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 007. \346\225\260\347\273\204\344\270\255\345\222\214\344\270\272 0 \347\232\204\344\270\211\344\270\252\346\225\260/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 007. \346\225\260\347\273\204\344\270\255\345\222\214\344\270\272 0 \347\232\204\344\270\211\344\270\252\346\225\260/README.md" index 524ca70d25028..99cb7fe19aaa7 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 007. \346\225\260\347\273\204\344\270\255\345\222\214\344\270\272 0 \347\232\204\344\270\211\344\270\252\346\225\260/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 007. \346\225\260\347\273\204\344\270\255\345\222\214\344\270\272 0 \347\232\204\344\270\211\344\270\252\346\225\260/README.md" @@ -79,6 +79,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def threeSum(self, nums: List[int]) -> List[List[int]]: @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> threeSum(int[] nums) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func threeSum(nums []int) (ans [][]int) { sort.Ints(nums) @@ -205,6 +213,8 @@ func threeSum(nums []int) (ans [][]int) { } ``` +#### TypeScript + ```ts function threeSum(nums: number[]): number[][] { nums.sort((a, b) => a - b); @@ -237,6 +247,8 @@ function threeSum(nums: number[]): number[][] { } ``` +#### Rust + ```rust use std::cmp::Ordering; @@ -280,6 +292,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -316,6 +330,8 @@ var threeSum = function (nums) { }; ``` +#### C# + ```cs public class Solution { public IList> ThreeSum(int[] nums) { @@ -349,6 +365,8 @@ public class Solution { } ``` +#### Ruby + ```rb # @param {Integer[]} nums # @return {Integer[][]} diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 008. \345\222\214\345\244\247\344\272\216\347\255\211\344\272\216 target \347\232\204\346\234\200\347\237\255\345\255\220\346\225\260\347\273\204/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 008. \345\222\214\345\244\247\344\272\216\347\255\211\344\272\216 target \347\232\204\346\234\200\347\237\255\345\255\220\346\225\260\347\273\204/README.md" index 47afca07897e7..5a5c56cac043a 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 008. \345\222\214\345\244\247\344\272\216\347\255\211\344\272\216 target \347\232\204\346\234\200\347\237\255\345\255\220\346\225\260\347\273\204/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 008. \345\222\214\345\244\247\344\272\216\347\255\211\344\272\216 target \347\232\204\346\234\200\347\237\255\345\255\220\346\225\260\347\273\204/README.md" @@ -77,6 +77,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def minSubArrayLen(self, target: int, nums: List[int]) -> int: @@ -91,6 +93,8 @@ class Solution: return 0 if ans == inf else ans ``` +#### Java + ```java class Solution { public int minSubArrayLen(int target, int[] nums) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func minSubArrayLen(target int, nums []int) int { const inf = 1 << 30 @@ -149,6 +157,8 @@ func minSubArrayLen(target int, nums []int) int { } ``` +#### TypeScript + ```ts function minSubArrayLen(target: number, nums: number[]): number { const n = nums.length; diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 009. \344\271\230\347\247\257\345\260\217\344\272\216 K \347\232\204\345\255\220\346\225\260\347\273\204/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 009. \344\271\230\347\247\257\345\260\217\344\272\216 K \347\232\204\345\255\220\346\225\260\347\273\204/README.md" index 18294496adb4a..ec70e74276af0 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 009. \344\271\230\347\247\257\345\260\217\344\272\216 K \347\232\204\345\255\220\346\225\260\347\273\204/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 009. \344\271\230\347\247\257\345\260\217\344\272\216 K \347\232\204\345\255\220\346\225\260\347\273\204/README.md" @@ -58,6 +58,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def numSubarrayProductLessThanK(self, nums: List[int], k: int) -> int: @@ -72,6 +74,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numSubarrayProductLessThanK(int[] nums, int k) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func numSubarrayProductLessThanK(nums []int, k int) int { s := 1 @@ -123,6 +131,8 @@ func numSubarrayProductLessThanK(nums []int, k int) int { } ``` +#### TypeScript + ```ts function numSubarrayProductLessThanK(nums: number[], k: number): number { let s = 1; diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 010. \345\222\214\344\270\272 k \347\232\204\345\255\220\346\225\260\347\273\204/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 010. \345\222\214\344\270\272 k \347\232\204\345\255\220\346\225\260\347\273\204/README.md" index 051eb58cefc6e..d867da72bb646 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 010. \345\222\214\344\270\272 k \347\232\204\345\255\220\346\225\260\347\273\204/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 010. \345\222\214\344\270\272 k \347\232\204\345\255\220\346\225\260\347\273\204/README.md" @@ -60,6 +60,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def subarraySum(self, nums: List[int], k: int) -> int: @@ -72,6 +74,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int subarraySum(int[] nums, int k) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func subarraySum(nums []int, k int) (ans int) { cnt := map[int]int{0: 1} @@ -118,6 +126,8 @@ func subarraySum(nums []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function subarraySum(nums: number[], k: number): number { const cnt: Map = new Map(); diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 011. 0 \345\222\214 1 \344\270\252\346\225\260\347\233\270\345\220\214\347\232\204\345\255\220\346\225\260\347\273\204/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 011. 0 \345\222\214 1 \344\270\252\346\225\260\347\233\270\345\220\214\347\232\204\345\255\220\346\225\260\347\273\204/README.md" index a7c56fa23175a..9d2dcc6869729 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 011. 0 \345\222\214 1 \344\270\252\346\225\260\347\233\270\345\220\214\347\232\204\345\255\220\346\225\260\347\273\204/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 011. 0 \345\222\214 1 \344\270\252\346\225\260\347\233\270\345\220\214\347\232\204\345\255\220\346\225\260\347\273\204/README.md" @@ -58,6 +58,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def findMaxLength(self, nums: List[int]) -> int: @@ -72,6 +74,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findMaxLength(int[] nums) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func findMaxLength(nums []int) (ans int) { d := map[int]int{0: -1} @@ -132,6 +140,8 @@ func findMaxLength(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function findMaxLength(nums: number[]): number { const d: Map = new Map(); diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 012. \345\267\246\345\217\263\344\270\244\350\276\271\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214\347\233\270\347\255\211/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 012. \345\267\246\345\217\263\344\270\244\350\276\271\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214\347\233\270\347\255\211/README.md" index 84ae23b1ce0dc..46d6f02a41222 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 012. \345\267\246\345\217\263\344\270\244\350\276\271\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214\347\233\270\347\255\211/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 012. \345\267\246\345\217\263\344\270\244\350\276\271\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214\347\233\270\347\255\211/README.md" @@ -86,6 +86,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def pivotIndex(self, nums: List[int]) -> int: @@ -98,6 +100,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int pivotIndex(int[] nums) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func pivotIndex(nums []int) int { left, right := 0, 0 @@ -154,6 +162,8 @@ func pivotIndex(nums []int) int { } ``` +#### TypeScript + ```ts function pivotIndex(nums: number[]): number { let left = 0; @@ -170,6 +180,8 @@ function pivotIndex(nums: number[]): number { } ``` +#### PHP + ```php class Solution { /** @@ -191,6 +203,8 @@ class Solution { } ``` +#### C + ```c int pivotIndex(int* nums, int numsSize) { int left, right; diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 013. \344\272\214\347\273\264\345\255\220\347\237\251\351\230\265\347\232\204\345\222\214/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 013. \344\272\214\347\273\264\345\255\220\347\237\251\351\230\265\347\232\204\345\222\214/README.md" index 3103c91f04306..32ca8a9344f3c 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 013. \344\272\214\347\273\264\345\255\220\347\237\251\351\230\265\347\232\204\345\222\214/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 013. \344\272\214\347\273\264\345\255\220\347\237\251\351\230\265\347\232\204\345\222\214/README.md" @@ -98,6 +98,8 @@ $$ +#### Python3 + ```python class NumMatrix: def __init__(self, matrix: List[List[int]]): @@ -122,6 +124,8 @@ class NumMatrix: # param_1 = obj.sumRegion(row1,col1,row2,col2) ``` +#### Java + ```java class NumMatrix { private int[][] s; @@ -149,6 +153,8 @@ class NumMatrix { */ ``` +#### C++ + ```cpp class NumMatrix { public: @@ -178,6 +184,8 @@ private: */ ``` +#### Go + ```go type NumMatrix struct { s [][]int @@ -208,6 +216,8 @@ func (this *NumMatrix) SumRegion(row1 int, col1 int, row2 int, col2 int) int { */ ``` +#### TypeScript + ```ts class NumMatrix { s: number[][]; diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 014. \345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\217\230\344\275\215\350\257\215/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 014. \345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\217\230\344\275\215\350\257\215/README.md" index cd05d85371fc2..8e5bfb5f876ba 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 014. \345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\217\230\344\275\215\350\257\215/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 014. \345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\217\230\344\275\215\350\257\215/README.md" @@ -65,6 +65,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def checkInclusion(self, s1: str, s2: str) -> bool: @@ -83,6 +85,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean checkInclusion(String s1, String s2) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func checkInclusion(s1 string, s2 string) bool { m, n := len(s1), len(s2) @@ -165,6 +173,8 @@ func checkInclusion(s1 string, s2 string) bool { } ``` +#### TypeScript + ```ts function checkInclusion(s1: string, s2: string): boolean { const m = s1.length; @@ -206,6 +216,8 @@ function checkInclusion(s1: string, s2: string): boolean { +#### Python3 + ```python class Solution: def checkInclusion(self, s1: str, s2: str) -> bool: @@ -236,6 +248,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean checkInclusion(String s1, String s2) { @@ -284,6 +298,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -332,6 +348,8 @@ public: }; ``` +#### Go + ```go func checkInclusion(s1 string, s2 string) bool { m, n := len(s1), len(s2) @@ -376,6 +394,8 @@ func checkInclusion(s1 string, s2 string) bool { } ``` +#### TypeScript + ```ts function checkInclusion(s1: string, s2: string): boolean { const m = s1.length; diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 015. \345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\346\211\200\346\234\211\345\217\230\344\275\215\350\257\215/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 015. \345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\346\211\200\346\234\211\345\217\230\344\275\215\350\257\215/README.md" index e03aebbe20b32..ab169635360f3 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 015. \345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\346\211\200\346\234\211\345\217\230\344\275\215\350\257\215/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 015. \345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\346\211\200\346\234\211\345\217\230\344\275\215\350\257\215/README.md" @@ -71,6 +71,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def findAnagrams(self, s: str, p: str) -> List[int]: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List findAnagrams(String s, String p) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func findAnagrams(s string, p string) (ans []int) { m, n := len(s), len(p) @@ -175,6 +183,8 @@ func findAnagrams(s string, p string) (ans []int) { } ``` +#### TypeScript + ```ts function findAnagrams(s: string, p: string): number[] { const m = s.length; @@ -217,6 +227,8 @@ function findAnagrams(s: string, p: string): number[] { +#### Python3 + ```python class Solution: def findAnagrams(self, s: str, p: str) -> List[int]: @@ -248,6 +260,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List findAnagrams(String s, String p) { @@ -297,6 +311,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -346,6 +362,8 @@ public: }; ``` +#### Go + ```go func findAnagrams(s string, p string) (ans []int) { m, n := len(s), len(p) @@ -390,6 +408,8 @@ func findAnagrams(s string, p string) (ans []int) { } ``` +#### TypeScript + ```ts function findAnagrams(s: string, p: string): number[] { const m = s.length; diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 016. \344\270\215\345\220\253\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\345\255\227\347\254\246\344\270\262/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 016. \344\270\215\345\220\253\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\345\255\227\347\254\246\344\270\262/README.md" index 772785aa1575e..dbfc5a4dbab8b 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 016. \344\270\215\345\220\253\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\345\255\227\347\254\246\344\270\262/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 016. \344\270\215\345\220\253\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\345\255\227\347\254\246\344\270\262/README.md" @@ -76,6 +76,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def lengthOfLongestSubstring(self, s: str) -> int: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int lengthOfLongestSubstring(String s) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func lengthOfLongestSubstring(s string) (ans int) { ss := make([]bool, 128) @@ -144,6 +152,8 @@ func lengthOfLongestSubstring(s string) (ans int) { } ``` +#### TypeScript + ```ts function lengthOfLongestSubstring(s: string): number { let ans = 0; @@ -169,6 +179,8 @@ function lengthOfLongestSubstring(s: string): number { +#### TypeScript + ```ts function lengthOfLongestSubstring(s: string): number { let ans = 0; diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 017. \345\220\253\346\234\211\346\211\200\346\234\211\345\255\227\347\254\246\347\232\204\346\234\200\347\237\255\345\255\227\347\254\246\344\270\262/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 017. \345\220\253\346\234\211\346\211\200\346\234\211\345\255\227\347\254\246\347\232\204\346\234\200\347\237\255\345\255\227\347\254\246\344\270\262/README.md" index 3edacc81a805e..df9b8d62e9749 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 017. \345\220\253\346\234\211\346\211\200\346\234\211\345\255\227\347\254\246\347\232\204\346\234\200\347\237\255\345\255\227\347\254\246\344\270\262/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 017. \345\220\253\346\234\211\346\211\200\346\234\211\345\255\227\347\254\246\347\232\204\346\234\200\347\237\255\345\255\227\347\254\246\344\270\262/README.md" @@ -69,6 +69,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def minWindow(self, s: str, t: str) -> str: @@ -98,6 +100,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public String minWindow(String s, String t) { @@ -136,6 +140,8 @@ class Solution { } ``` +#### Go + ```go func minWindow(s string, t string) string { m, n := len(s), len(t) @@ -186,6 +192,8 @@ func check(need, window map[byte]int) bool { +#### Python3 + ```python class Solution: def minWindow(self, s: str, t: str) -> str: @@ -220,6 +228,8 @@ class Solution: return "" if minLen == inf else s[start : start + minLen] ``` +#### Java + ```java class Solution { public String minWindow(String s, String t) { @@ -267,6 +277,8 @@ class Solution { } ``` +#### Go + ```go func minWindow(s string, t string) string { m, n := len(s), len(t) diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 018. \346\234\211\346\225\210\347\232\204\345\233\236\346\226\207/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 018. \346\234\211\346\225\210\347\232\204\345\233\236\346\226\207/README.md" index f18af7351997d..bb3de48e35f4e 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 018. \346\234\211\346\225\210\347\232\204\345\233\236\346\226\207/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 018. \346\234\211\346\225\210\347\232\204\345\233\236\346\226\207/README.md" @@ -58,6 +58,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def isPalindrome(self, s: str) -> bool: @@ -73,6 +75,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isPalindrome(String s) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func isPalindrome(s string) bool { i, j := 0, len(s)-1 @@ -150,6 +158,8 @@ func isalnum(b byte) bool { } ``` +#### TypeScript + ```ts function isPalindrome(s: string): boolean { const str = s.replace(/[^a-zA-Z0-9]/g, ''); @@ -166,6 +176,8 @@ function isPalindrome(s: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn is_palindrome(s: String) -> bool { diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 019. \346\234\200\345\244\232\345\210\240\351\231\244\344\270\200\344\270\252\345\255\227\347\254\246\345\276\227\345\210\260\345\233\236\346\226\207/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 019. \346\234\200\345\244\232\345\210\240\351\231\244\344\270\200\344\270\252\345\255\227\347\254\246\345\276\227\345\210\260\345\233\236\346\226\207/README.md" index 742f8ea848b8f..c0a79f7477826 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 019. \346\234\200\345\244\232\345\210\240\351\231\244\344\270\200\344\270\252\345\255\227\347\254\246\345\276\227\345\210\260\345\233\236\346\226\207/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 019. \346\234\200\345\244\232\345\210\240\351\231\244\344\270\200\344\270\252\345\255\227\347\254\246\345\276\227\345\210\260\345\233\236\346\226\207/README.md" @@ -66,6 +66,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def validPalindrome(self, s: str) -> bool: @@ -84,6 +86,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { private String s; @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func validPalindrome(s string) bool { check := func(i, j int) bool { @@ -150,6 +158,8 @@ func validPalindrome(s string) bool { } ``` +#### TypeScript + ```ts function validPalindrome(s: string): boolean { const check = (i: number, j: number): boolean => { @@ -169,6 +179,8 @@ function validPalindrome(s: string): boolean { } ``` +#### JavaScript + ```js /** * @param {string} s diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 020. \345\233\236\346\226\207\345\255\220\345\255\227\347\254\246\344\270\262\347\232\204\344\270\252\346\225\260/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 020. \345\233\236\346\226\207\345\255\220\345\255\227\347\254\246\344\270\262\347\232\204\344\270\252\346\225\260/README.md" index 160b5fb5e1109..0fa41766af2f5 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 020. \345\233\236\346\226\207\345\255\220\345\255\227\347\254\246\344\270\262\347\232\204\344\270\252\346\225\260/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 020. \345\233\236\346\226\207\345\255\220\345\255\227\347\254\246\344\270\262\347\232\204\344\270\252\346\225\260/README.md" @@ -59,6 +59,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def countSubstrings(self, s: str) -> int: @@ -75,6 +77,8 @@ class Solution: return sum(f(i, i) + f(i, i + 1) for i in range(n)) ``` +#### Java + ```java class Solution { private String s; @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func countSubstrings(s string) (ans int) { n := len(s) @@ -151,6 +159,8 @@ func countSubstrings(s string) (ans int) { +#### Python3 + ```python class Solution: def countSubstrings(self, s: str) -> int: @@ -170,6 +180,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countSubstrings(String s) { diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 021. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254 n \344\270\252\347\273\223\347\202\271/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 021. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254 n \344\270\252\347\273\223\347\202\271/README.md" index c11a365fc0205..49ef8f9eca0ac 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 021. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254 n \344\270\252\347\273\223\347\202\271/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 021. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254 n \344\270\252\347\273\223\347\202\271/README.md" @@ -67,6 +67,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -86,6 +88,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -169,6 +177,8 @@ func removeNthFromEnd(head *ListNode, n int) *ListNode { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -198,6 +208,8 @@ var removeNthFromEnd = function (head, n) { }; ``` +#### Ruby + ```rb # Definition for singly-linked list. # class ListNode diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 023. \344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\351\207\215\345\220\210\350\212\202\347\202\271/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 023. \344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\351\207\215\345\220\210\350\212\202\347\202\271/README.md" index 779c125679d0d..66c3f5e291e2f 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 023. \344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\351\207\215\345\220\210\350\212\202\347\202\271/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 023. \344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\351\207\215\345\220\210\350\212\202\347\202\271/README.md" @@ -100,6 +100,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -117,6 +119,8 @@ class Solution: return a ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -141,6 +145,8 @@ public class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -189,6 +197,8 @@ func getIntersectionNode(headA, headB *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -213,6 +223,8 @@ function getIntersectionNode(headA: ListNode | null, headB: ListNode | null): Li } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -238,6 +250,8 @@ var getIntersectionNode = function (headA, headB) { }; ``` +#### Swift + ```swift /** * Definition for singly-linked list. diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 024. \345\217\215\350\275\254\351\223\276\350\241\250/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 024. \345\217\215\350\275\254\351\223\276\350\241\250/README.md" index 1d018c97d9856..8966bcff5d8cb 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 024. \345\217\215\350\275\254\351\223\276\350\241\250/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 024. \345\217\215\350\275\254\351\223\276\350\241\250/README.md" @@ -67,6 +67,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -86,6 +88,8 @@ class Solution: return pre ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -156,6 +164,8 @@ func reverseList(head *ListNode) *ListNode { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -180,6 +190,8 @@ var reverseList = function (head) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. @@ -217,6 +229,8 @@ public class Solution { +#### Java + ```java /** * Definition for singly-linked list. diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 025. \351\223\276\350\241\250\344\270\255\347\232\204\344\270\244\346\225\260\347\233\270\345\212\240/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 025. \351\223\276\350\241\250\344\270\255\347\232\204\344\270\244\346\225\260\347\233\270\345\212\240/README.md" index 9f78feac79163..b6ac6e4222aa3 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 025. \351\223\276\350\241\250\344\270\255\347\232\204\344\270\244\346\225\260\347\233\270\345\212\240/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 025. \351\223\276\350\241\250\344\270\255\347\232\204\344\270\244\346\225\260\347\233\270\345\212\240/README.md" @@ -68,6 +68,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -93,6 +95,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 026. \351\207\215\346\216\222\351\223\276\350\241\250/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 026. \351\207\215\346\216\222\351\223\276\350\241\250/README.md" index 05b2bcdfb913f..e7269f27d746e 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 026. \351\207\215\346\216\222\351\223\276\350\241\250/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 026. \351\207\215\346\216\222\351\223\276\350\241\250/README.md" @@ -61,6 +61,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -105,6 +107,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -162,6 +166,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -222,6 +228,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 027. \345\233\236\346\226\207\351\223\276\350\241\250/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 027. \345\233\236\346\226\207\351\223\276\350\241\250/README.md" index ac1c658f20ebf..e9f6d371ff406 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 027. \345\233\236\346\226\207\351\223\276\350\241\250/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 027. \345\233\236\346\226\207\351\223\276\350\241\250/README.md" @@ -61,6 +61,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -86,6 +88,8 @@ class Solution: return True ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -202,6 +210,8 @@ func isPalindrome(head *ListNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -244,6 +254,8 @@ function isPalindrome(head: ListNode | null): boolean { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -286,6 +298,8 @@ var isPalindrome = function (head) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 028. \345\261\225\345\271\263\345\244\232\347\272\247\345\217\214\345\220\221\351\223\276\350\241\250/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 028. \345\261\225\345\271\263\345\244\232\347\272\247\345\217\214\345\220\221\351\223\276\350\241\250/README.md" index 0dd100fa80abe..19759fc442666 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 028. \345\261\225\345\271\263\345\244\232\347\272\247\345\217\214\345\220\221\351\223\276\350\241\250/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 028. \345\261\225\345\271\263\345\244\232\347\272\247\345\217\214\345\220\221\351\223\276\350\241\250/README.md" @@ -111,6 +111,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python """ # Definition for a Node. @@ -148,6 +150,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /* // Definition for a Node. @@ -188,6 +192,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 029. \346\216\222\345\272\217\347\232\204\345\276\252\347\216\257\351\223\276\350\241\250/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 029. \346\216\222\345\272\217\347\232\204\345\276\252\347\216\257\351\223\276\350\241\250/README.md" index 511fbb2d0dddc..dc157d9ffc2e7 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 029. \346\216\222\345\272\217\347\232\204\345\276\252\347\216\257\351\223\276\350\241\250/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 029. \346\216\222\345\272\217\347\232\204\345\276\252\347\216\257\351\223\276\350\241\250/README.md" @@ -73,6 +73,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python """ # Definition for a Node. @@ -106,6 +108,8 @@ class Solution: return head ``` +#### Java + ```java /* // Definition for a Node. @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -192,6 +198,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -220,6 +228,8 @@ func insert(head *Node, x int) *Node { } ``` +#### TypeScript + ```ts /** * Definition for node. diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 030. \346\217\222\345\205\245\343\200\201\345\210\240\351\231\244\345\222\214\351\232\217\346\234\272\350\256\277\351\227\256\351\203\275\346\230\257 O(1) \347\232\204\345\256\271\345\231\250/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 030. \346\217\222\345\205\245\343\200\201\345\210\240\351\231\244\345\222\214\351\232\217\346\234\272\350\256\277\351\227\256\351\203\275\346\230\257 O(1) \347\232\204\345\256\271\345\231\250/README.md" index 4b7579bb98c0c..86add08681ddd 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 030. \346\217\222\345\205\245\343\200\201\345\210\240\351\231\244\345\222\214\351\232\217\346\234\272\350\256\277\351\227\256\351\203\275\346\230\257 O(1) \347\232\204\345\256\271\345\231\250/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 030. \346\217\222\345\205\245\343\200\201\345\210\240\351\231\244\345\222\214\351\232\217\346\234\272\350\256\277\351\227\256\351\203\275\346\230\257 O(1) \347\232\204\345\256\271\345\231\250/README.md" @@ -68,6 +68,8 @@ randomSet.getRandom(); // 由于 2 是集合中唯一的数字,getRandom 总 +#### Python3 + ```python class RandomizedSet: def __init__(self): @@ -114,6 +116,8 @@ class RandomizedSet: # param_3 = obj.getRandom() ``` +#### Java + ```java class RandomizedSet { private final Map m; @@ -166,6 +170,8 @@ class RandomizedSet { */ ``` +#### C++ + ```cpp class RandomizedSet { unordered_map mp; diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 031. \346\234\200\350\277\221\346\234\200\345\260\221\344\275\277\347\224\250\347\274\223\345\255\230/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 031. \346\234\200\350\277\221\346\234\200\345\260\221\344\275\277\347\224\250\347\274\223\345\255\230/README.md" index ba81fa5c0c030..6fb94e385f1e8 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 031. \346\234\200\350\277\221\346\234\200\345\260\221\344\275\277\347\224\250\347\274\223\345\255\230/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 031. \346\234\200\350\277\221\346\234\200\345\260\221\344\275\277\347\224\250\347\274\223\345\255\230/README.md" @@ -87,6 +87,8 @@ lRUCache.get(4); // 返回 4 +#### Python3 + ```python class Node: def __init__(self, key=0, val=0): @@ -154,6 +156,8 @@ class LRUCache: # obj.put(key,value) ``` +#### Java + ```java class Node { int key; @@ -242,6 +246,8 @@ class LRUCache { */ ``` +#### C++ + ```cpp struct Node { int k; @@ -336,6 +342,8 @@ private: */ ``` +#### Go + ```go type node struct { key, val int @@ -407,6 +415,8 @@ func (this *LRUCache) pushFront(n *node) { } ``` +#### TypeScript + ```ts class LRUCache { capacity: number; @@ -443,6 +453,8 @@ class LRUCache { */ ``` +#### Rust + ```rust use std::cell::RefCell; use std::collections::HashMap; @@ -574,6 +586,8 @@ impl LRUCache { */ ``` +#### C# + ```cs public class LRUCache { class Node { diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 032. \346\234\211\346\225\210\347\232\204\345\217\230\344\275\215\350\257\215/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 032. \346\234\211\346\225\210\347\232\204\345\217\230\344\275\215\350\257\215/README.md" index 2581ecadc6edf..aa4bcb0544807 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 032. \346\234\211\346\225\210\347\232\204\345\217\230\344\275\215\350\257\215/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 032. \346\234\211\346\225\210\347\232\204\345\217\230\344\275\215\350\257\215/README.md" @@ -69,6 +69,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def isAnagram(self, s: str, t: str) -> bool: @@ -77,6 +79,8 @@ class Solution: return Counter(s) == Counter(t) ``` +#### Java + ```java class Solution { public boolean isAnagram(String s, String t) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func isAnagram(s string, t string) bool { m, n := len(s), len(t) @@ -144,6 +152,8 @@ func isAnagram(s string, t string) bool { } ``` +#### TypeScript + ```ts function isAnagram(s: string, t: string): boolean { const m = s.length; diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 033. \345\217\230\344\275\215\350\257\215\347\273\204/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 033. \345\217\230\344\275\215\350\257\215\347\273\204/README.md" index eaa2837fa6a6c..c8026953e1527 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 033. \345\217\230\344\275\215\350\257\215\347\273\204/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 033. \345\217\230\344\275\215\350\257\215\347\273\204/README.md" @@ -76,6 +76,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def groupAnagrams(self, strs: List[str]) -> List[List[str]]: @@ -86,6 +88,8 @@ class Solution: return list(d.values()) ``` +#### Java + ```java class Solution { public List> groupAnagrams(String[] strs) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func groupAnagrams(strs []string) (ans [][]string) { d := map[string][]string{} @@ -134,6 +142,8 @@ func groupAnagrams(strs []string) (ans [][]string) { } ``` +#### TypeScript + ```ts function groupAnagrams(strs: string[]): string[][] { const d: Map = new Map(); @@ -162,6 +172,8 @@ function groupAnagrams(strs: string[]): string[][] { +#### Python3 + ```python class Solution: def groupAnagrams(self, strs: List[str]) -> List[List[str]]: @@ -174,6 +186,8 @@ class Solution: return list(d.values()) ``` +#### Java + ```java class Solution { public List> groupAnagrams(String[] strs) { @@ -197,6 +211,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -221,6 +237,8 @@ public: }; ``` +#### Go + ```go func groupAnagrams(strs []string) (ans [][]string) { d := map[[26]int][]string{} diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 034. \345\244\226\346\230\237\350\257\255\350\250\200\346\230\257\345\220\246\346\216\222\345\272\217/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 034. \345\244\226\346\230\237\350\257\255\350\250\200\346\230\257\345\220\246\346\216\222\345\272\217/README.md" index 69c6840418ed1..f57a93736cee3 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 034. \345\244\226\346\230\237\350\257\255\350\250\200\346\230\257\345\220\246\346\216\222\345\272\217/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 034. \345\244\226\346\230\237\350\257\255\350\250\200\346\230\257\345\220\246\346\216\222\345\272\217/README.md" @@ -64,6 +64,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def isAlienSorted(self, words: List[str], order: str) -> bool: @@ -86,6 +88,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isAlienSorted(String[] words, String order) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func isAlienSorted(words []string, order string) bool { index := make(map[byte]int) @@ -167,6 +175,8 @@ func isAlienSorted(words []string, order string) bool { } ``` +#### TypeScript + ```ts function isAlienSorted(words: string[], order: string): boolean { let charMap = new Map(); diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 035. \346\234\200\345\260\217\346\227\266\351\227\264\345\267\256/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 035. \346\234\200\345\260\217\346\227\266\351\227\264\345\267\256/README.md" index ba651433c1aa1..981d1cb6e3ad0 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 035. \346\234\200\345\260\217\346\227\266\351\227\264\345\267\256/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 035. \346\234\200\345\260\217\346\227\266\351\227\264\345\267\256/README.md" @@ -62,6 +62,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def findMinDifference(self, timePoints: List[str]) -> int: @@ -72,6 +74,8 @@ class Solution: return min(b - a for a, b in pairwise(mins)) ``` +#### Java + ```java class Solution { public int findMinDifference(List timePoints) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func findMinDifference(timePoints []string) int { if len(timePoints) > 24*60 { @@ -138,6 +146,8 @@ func findMinDifference(timePoints []string) int { } ``` +#### TypeScript + ```ts function findMinDifference(timePoints: string[]): number { if (timePoints.length > 24 * 60) { diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 036. \345\220\216\347\274\200\350\241\250\350\276\276\345\274\217/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 036. \345\220\216\347\274\200\350\241\250\350\276\276\345\274\217/README.md" index 997e60c417b01..ff26a2361d9f8 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 036. \345\220\216\347\274\200\350\241\250\350\276\276\345\274\217/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 036. \345\220\216\347\274\200\350\241\250\350\276\276\345\274\217/README.md" @@ -98,6 +98,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def evalRPN(self, tokens: List[str]) -> int: @@ -118,6 +120,8 @@ class Solution: return nums[0] ``` +#### Java + ```java class Solution { public int evalRPN(String[] tokens) { @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go func evalRPN(tokens []string) int { // https://github.com/emirpasic/gods#arraystack diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 037. \345\260\217\350\241\214\346\230\237\347\242\260\346\222\236/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 037. \345\260\217\350\241\214\346\230\237\347\242\260\346\222\236/README.md" index e8c54aede73ce..fb3b6354cce33 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 037. \345\260\217\350\241\214\346\230\237\347\242\260\346\222\236/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 037. \345\260\217\350\241\214\346\230\237\347\242\260\346\222\236/README.md" @@ -80,6 +80,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def asteroidCollision(self, asteroids: List[int]) -> List[int]: @@ -97,6 +99,8 @@ class Solution: return stk ``` +#### Java + ```java class Solution { public int[] asteroidCollision(int[] asteroids) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func asteroidCollision(asteroids []int) (stk []int) { for _, x := range asteroids { @@ -164,6 +172,8 @@ func asteroidCollision(asteroids []int) (stk []int) { } ``` +#### TypeScript + ```ts function asteroidCollision(asteroids: number[]): number[] { const stk: number[] = []; @@ -185,6 +195,8 @@ function asteroidCollision(asteroids: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 038. \346\257\217\346\227\245\346\270\251\345\272\246/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 038. \346\257\217\346\227\245\346\270\251\345\272\246/README.md" index 1610997f1fe73..dfda38aee573c 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 038. \346\257\217\346\227\245\346\270\251\345\272\246/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 038. \346\257\217\346\227\245\346\270\251\345\272\246/README.md" @@ -68,6 +68,8 @@ for i in range(n): +#### Python3 + ```python class Solution: def dailyTemperatures(self, temperatures: List[int]) -> List[int]: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] dailyTemperatures(int[] temperatures) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func dailyTemperatures(temperatures []int) []int { ans := make([]int, len(temperatures)) @@ -134,6 +142,8 @@ func dailyTemperatures(temperatures []int) []int { } ``` +#### TypeScript + ```ts function dailyTemperatures(temperatures: number[]): number[] { const n = temperatures.length; @@ -150,6 +160,8 @@ function dailyTemperatures(temperatures: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn daily_temperatures(temperatures: Vec) -> Vec { @@ -178,6 +190,8 @@ impl Solution { +#### Python3 + ```python class Solution: def dailyTemperatures(self, temperatures: List[int]) -> List[int]: @@ -193,6 +207,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] dailyTemperatures(int[] temperatures) { @@ -213,6 +229,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -230,6 +248,8 @@ public: }; ``` +#### Go + ```go func dailyTemperatures(temperatures []int) []int { n := len(temperatures) @@ -248,6 +268,8 @@ func dailyTemperatures(temperatures []int) []int { } ``` +#### TypeScript + ```ts function dailyTemperatures(temperatures: number[]): number[] { const n = temperatures.length; @@ -265,6 +287,8 @@ function dailyTemperatures(temperatures: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn daily_temperatures(temperatures: Vec) -> Vec { diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 039. \347\233\264\346\226\271\345\233\276\346\234\200\345\244\247\347\237\251\345\275\242\351\235\242\347\247\257/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 039. \347\233\264\346\226\271\345\233\276\346\234\200\345\244\247\347\237\251\345\275\242\351\235\242\347\247\257/README.md" index 37dc6ad3a9bef..0f92c4a6a385f 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 039. \347\233\264\346\226\271\345\233\276\346\234\200\345\244\247\347\237\251\345\275\242\351\235\242\347\247\257/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 039. \347\233\264\346\226\271\345\233\276\346\234\200\345\244\247\347\237\251\345\275\242\351\235\242\347\247\257/README.md" @@ -59,6 +59,8 @@ for i in range(n): +#### Python3 + ```python class Solution: def largestRectangleArea(self, heights: List[int]) -> int: @@ -82,6 +84,8 @@ class Solution: return max(x * (r - l - 1) for x, l, r in zip(heights, left, right)) ``` +#### Java + ```java class Solution { public int largestRectangleArea(int[] heights) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func largestRectangleArea(heights []int) (ans int) { n := len(heights) @@ -192,6 +200,8 @@ func largestRectangleArea(heights []int) (ans int) { } ``` +#### TypeScript + ```ts function largestRectangleArea(heights: number[]): number { const n = heights.length; diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 040. \347\237\251\351\230\265\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 040. \347\237\251\351\230\265\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242/README.md" index e3d7ac298a689..5d7912e6036bc 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 040. \347\237\251\351\230\265\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 040. \347\237\251\351\230\265\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242/README.md" @@ -84,6 +84,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def maximalRectangle(self, matrix: List[List[str]]) -> int: @@ -122,6 +124,8 @@ class Solution: return max(h * (right[i] - left[i] - 1) for i, h in enumerate(heights)) ``` +#### Java + ```java class Solution { public int maximalRectangle(String[] matrix) { @@ -165,6 +169,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -199,6 +205,8 @@ public: }; ``` +#### Go + ```go func maximalRectangle(matrix []string) int { if len(matrix) == 0 { @@ -256,6 +264,8 @@ func largestRectangleArea(heights []int) int { +#### C++ + ```cpp class Solution { public: diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 041. \346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\345\271\263\345\235\207\345\200\274/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 041. \346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\345\271\263\345\235\207\345\200\274/README.md" index 41073c4c2a807..2cfa24adecd46 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 041. \346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\345\271\263\345\235\207\345\200\274/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 041. \346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\345\271\263\345\235\207\345\200\274/README.md" @@ -63,6 +63,8 @@ movingAverage.next(5); // 返回 6.0 = (10 + 3 + 5) / 3 +#### Python3 + ```python class MovingAverage: def __init__(self, size: int): @@ -83,6 +85,8 @@ class MovingAverage: # param_1 = obj.next(val) ``` +#### Java + ```java class MovingAverage { private int[] arr; @@ -109,6 +113,8 @@ class MovingAverage { */ ``` +#### C++ + ```cpp class MovingAverage { public: @@ -137,6 +143,8 @@ private: */ ``` +#### Go + ```go type MovingAverage struct { arr []int @@ -174,6 +182,8 @@ func (this *MovingAverage) Next(val int) float64 { +#### Python3 + ```python class MovingAverage: def __init__(self, size: int): @@ -194,6 +204,8 @@ class MovingAverage: # param_1 = obj.next(val) ``` +#### Java + ```java class MovingAverage { private Deque q = new ArrayDeque<>(); @@ -221,6 +233,8 @@ class MovingAverage { */ ``` +#### C++ + ```cpp class MovingAverage { public: @@ -251,6 +265,8 @@ private: */ ``` +#### Go + ```go type MovingAverage struct { q []int diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 042. \346\234\200\350\277\221\350\257\267\346\261\202\346\254\241\346\225\260/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 042. \346\234\200\350\277\221\350\257\267\346\261\202\346\254\241\346\225\260/README.md" index 984d8a5587f78..5d5c5a84345f7 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 042. \346\234\200\350\277\221\350\257\267\346\261\202\346\254\241\346\225\260/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 042. \346\234\200\350\277\221\350\257\267\346\261\202\346\254\241\346\225\260/README.md" @@ -65,6 +65,8 @@ recentCounter.ping(3002); // requests = [1, 100, 3001< +#### Python3 + ```python class RecentCounter: def __init__(self): @@ -82,6 +84,8 @@ class RecentCounter: # param_1 = obj.ping(t) ``` +#### Java + ```java class RecentCounter { private Deque q; @@ -106,6 +110,8 @@ class RecentCounter { */ ``` +#### C++ + ```cpp class RecentCounter { public: @@ -130,6 +136,8 @@ public: */ ``` +#### Go + ```go type RecentCounter struct { q []int @@ -156,6 +164,8 @@ func (this *RecentCounter) Ping(t int) int { */ ``` +#### TypeScript + ```ts class RecentCounter { stack: Array; @@ -177,6 +187,8 @@ class RecentCounter { } ``` +#### JavaScript + ```js var RecentCounter = function () { this.q = []; diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 043. \345\276\200\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\346\267\273\345\212\240\350\212\202\347\202\271/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 043. \345\276\200\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\346\267\273\345\212\240\350\212\202\347\202\271/README.md" index 62999f7887c27..3f6d02b516a05 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 043. \345\276\200\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\346\267\273\345\212\240\350\212\202\347\202\271/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 043. \345\276\200\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\346\267\273\345\212\240\350\212\202\347\202\271/README.md" @@ -72,6 +72,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -113,6 +115,8 @@ class CBTInserter: # param_2 = obj.get_root() ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -174,6 +178,8 @@ class CBTInserter { */ ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -233,6 +239,8 @@ private: */ ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -289,6 +297,8 @@ func (this *CBTInserter) Get_root() *TreeNode { */ ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -348,6 +358,8 @@ class CBTInserter { */ ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 044. \344\272\214\345\217\211\346\240\221\346\257\217\345\261\202\347\232\204\346\234\200\345\244\247\345\200\274/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 044. \344\272\214\345\217\211\346\240\221\346\257\217\345\261\202\347\232\204\346\234\200\345\244\247\345\200\274/README.md" index c341aa9eb0778..4327065e9f0de 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 044. \344\272\214\345\217\211\346\240\221\346\257\217\345\261\202\347\232\204\346\234\200\345\244\247\345\200\274/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 044. \344\272\214\345\217\211\346\240\221\346\257\217\345\261\202\347\232\204\346\234\200\345\244\247\345\200\274/README.md" @@ -87,6 +87,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -113,6 +115,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -156,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -190,6 +196,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 045. \344\272\214\345\217\211\346\240\221\346\234\200\345\272\225\345\261\202\346\234\200\345\267\246\350\276\271\347\232\204\345\200\274/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 045. \344\272\214\345\217\211\346\240\221\346\234\200\345\272\225\345\261\202\346\234\200\345\267\246\350\276\271\347\232\204\345\200\274/README.md" index 32ee02daa8bf0..f595a764c17af 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 045. \344\272\214\345\217\211\346\240\221\346\234\200\345\272\225\345\261\202\346\234\200\345\267\246\350\276\271\347\232\204\345\200\274/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 045. \344\272\214\345\217\211\346\240\221\346\234\200\345\272\225\345\261\202\346\234\200\345\267\246\350\276\271\347\232\204\345\200\274/README.md" @@ -58,6 +58,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 046. \344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\344\276\247\350\247\206\345\233\276/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 046. \344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\344\276\247\350\247\206\345\233\276/README.md" index 32c42edda7a9a..e1b1246dd0e50 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 046. \344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\344\276\247\350\247\206\345\233\276/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 046. \344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\344\276\247\350\247\206\345\233\276/README.md" @@ -61,6 +61,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 047. \344\272\214\345\217\211\346\240\221\345\211\252\346\236\235/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 047. \344\272\214\345\217\211\346\240\221\345\211\252\346\236\235/README.md" index 63af0f6e3316d..4e6ed3f28fb9c 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 047. \344\272\214\345\217\211\346\240\221\345\211\252\346\236\235/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 047. \344\272\214\345\217\211\346\240\221\345\211\252\346\236\235/README.md" @@ -72,6 +72,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -90,6 +92,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -167,6 +175,8 @@ func pruneTree(root *TreeNode) *TreeNode { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 048. \345\272\217\345\210\227\345\214\226\344\270\216\345\217\215\345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 048. \345\272\217\345\210\227\345\214\226\344\270\216\345\217\215\345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221/README.md" index 233009fc46d93..8749d37a5ebae 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 048. \345\272\217\345\210\227\345\214\226\344\270\216\345\217\215\345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 048. \345\272\217\345\210\227\345\214\226\344\270\216\345\217\215\345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221/README.md" @@ -71,6 +71,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode(object): @@ -128,6 +130,8 @@ class Codec: # ans = deser.deserialize(ser.serialize(root)) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -192,6 +196,8 @@ public class Codec { // TreeNode ans = deser.deserialize(ser.serialize(root)); ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -245,6 +251,8 @@ public: // TreeNode* ans = deser.deserialize(ser.serialize(root)); ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 049. \344\273\216\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\347\232\204\350\267\257\345\276\204\346\225\260\345\255\227\344\271\213\345\222\214/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 049. \344\273\216\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\347\232\204\350\267\257\345\276\204\346\225\260\345\255\227\344\271\213\345\222\214/README.md" index 2fbd5789e75fb..97c3c351d6cd9 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 049. \344\273\216\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\347\232\204\350\267\257\345\276\204\346\225\260\345\255\227\344\271\213\345\222\214/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 049. \344\273\216\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\347\232\204\350\267\257\345\276\204\346\225\260\345\255\227\344\271\213\345\222\214/README.md" @@ -75,6 +75,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -95,6 +97,8 @@ class Solution: return dfs(root, 0) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 050. \345\220\221\344\270\213\347\232\204\350\267\257\345\276\204\350\212\202\347\202\271\344\271\213\345\222\214/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 050. \345\220\221\344\270\213\347\232\204\350\267\257\345\276\204\350\212\202\347\202\271\344\271\213\345\222\214/README.md" index c9dc56e4a71fc..627a2e551cf8b 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 050. \345\220\221\344\270\213\347\232\204\350\267\257\345\276\204\350\212\202\347\202\271\344\271\213\345\222\214/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 050. \345\220\221\344\270\213\347\232\204\350\267\257\345\276\204\350\212\202\347\202\271\344\271\213\345\222\214/README.md" @@ -74,6 +74,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -98,6 +100,8 @@ class Solution: return dfs(root, 0) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -197,6 +205,8 @@ func pathSum(root *TreeNode, targetSum int) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 051. \350\212\202\347\202\271\344\271\213\345\222\214\346\234\200\345\244\247\347\232\204\350\267\257\345\276\204/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 051. \350\212\202\347\202\271\344\271\213\345\222\214\346\234\200\345\244\247\347\232\204\350\267\257\345\276\204/README.md" index 171320d41c3f5..b850973fd3069 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 051. \350\212\202\347\202\271\344\271\213\345\222\214\346\234\200\345\244\247\347\232\204\350\267\257\345\276\204/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 051. \350\212\202\347\202\271\344\271\213\345\222\214\346\234\200\345\244\247\347\232\204\350\267\257\345\276\204/README.md" @@ -81,6 +81,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -197,6 +205,8 @@ func maxPathSum(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -228,6 +238,8 @@ function maxPathSum(root: TreeNode | null): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -269,6 +281,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -298,6 +312,8 @@ var maxPathSum = function (root) { }; ``` +#### C# + ```cs /** * Definition for a binary tree node. diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 052. \345\261\225\345\271\263\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 052. \345\261\225\345\271\263\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/README.md" index 76cb0df557547..df64c0c17e332 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 052. \345\261\225\345\271\263\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 052. \345\261\225\345\271\263\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/README.md" @@ -56,6 +56,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -83,6 +85,8 @@ class Solution: return head ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -196,6 +204,8 @@ func increasingBST(root *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -228,6 +238,8 @@ function increasingBST(root: TreeNode | null): TreeNode | null { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -282,6 +294,8 @@ impl Solution { } ``` +#### C + ```c /** * Definition for a binary tree node. @@ -322,6 +336,8 @@ struct TreeNode* increasingBST(struct TreeNode* root) { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -349,6 +365,8 @@ class Solution: return dummy.right ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -388,6 +406,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -421,6 +441,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 053. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\344\270\255\345\272\217\345\220\216\347\273\247/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 053. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\344\270\255\345\272\217\345\220\216\347\273\247/README.md" index d4b7fcf9aade9..e71ad2348788c 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 053. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\344\270\255\345\272\217\345\220\216\347\273\247/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 053. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\344\270\255\345\272\217\345\220\216\347\273\247/README.md" @@ -72,6 +72,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -168,6 +176,8 @@ func inorderSuccessor(root *TreeNode, p *TreeNode) (ans *TreeNode) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 054. \346\211\200\346\234\211\345\244\247\344\272\216\347\255\211\344\272\216\350\212\202\347\202\271\347\232\204\345\200\274\344\271\213\345\222\214/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 054. \346\211\200\346\234\211\345\244\247\344\272\216\347\255\211\344\272\216\350\212\202\347\202\271\347\232\204\345\200\274\344\271\213\345\222\214/README.md" index 97326843b0b3c..b3bb91480d1d8 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 054. \346\211\200\346\234\211\345\244\247\344\272\216\347\255\211\344\272\216\350\212\202\347\202\271\347\232\204\345\200\274\344\271\213\345\222\214/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 054. \346\211\200\346\234\211\345\244\247\344\272\216\347\255\211\344\272\216\350\212\202\347\202\271\347\232\204\345\200\274\344\271\213\345\222\214/README.md" @@ -89,6 +89,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -112,6 +114,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -179,6 +185,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -205,6 +213,8 @@ func convertBST(root *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -236,6 +246,8 @@ function convertBST(root: TreeNode | null): TreeNode | null { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -274,6 +286,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -326,6 +340,8 @@ Morris 遍历无需使用栈,时间复杂度 $O(n)$,空间复杂度为 $O(1) +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -357,6 +373,8 @@ class Solution: return node ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -403,6 +421,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -446,6 +466,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 055. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 055. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/README.md" index 978cc07f152e3..1e89618224d5b 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 055. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 055. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/README.md" @@ -89,6 +89,8 @@ bSTIterator.hasNext(); // 返回 False +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -123,6 +125,8 @@ class BSTIterator: # param_2 = obj.hasNext() ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -172,6 +176,8 @@ class BSTIterator { */ ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -218,6 +224,8 @@ public: */ ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -262,6 +270,8 @@ func (this *BSTIterator) HasNext() bool { */ ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -307,6 +317,8 @@ class BSTIterator { */ ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -371,6 +383,8 @@ impl BSTIterator { */ ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -431,6 +445,8 @@ BSTIterator.prototype.hasNext = function () { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -463,6 +479,8 @@ class BSTIterator: # param_2 = obj.hasNext() ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -509,6 +527,8 @@ class BSTIterator { */ ``` +#### C++ + ```cpp /** * Definition for a binary tree node. diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 056. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\344\270\244\344\270\252\350\212\202\347\202\271\344\271\213\345\222\214/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 056. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\344\270\244\344\270\252\350\212\202\347\202\271\344\271\213\345\222\214/README.md" index 6cbc6d36f1e3b..0a9ec43f73dda 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 056. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\344\270\244\344\270\252\350\212\202\347\202\271\344\271\213\345\222\214/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 056. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\344\270\244\344\270\252\350\212\202\347\202\271\344\271\213\345\222\214/README.md" @@ -56,6 +56,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -77,6 +79,8 @@ class Solution: return find(root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -170,6 +178,8 @@ func findTarget(root *TreeNode, k int) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 057. \345\200\274\345\222\214\344\270\213\346\240\207\344\271\213\345\267\256\351\203\275\345\234\250\347\273\231\345\256\232\347\232\204\350\214\203\345\233\264\345\206\205/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 057. \345\200\274\345\222\214\344\270\213\346\240\207\344\271\213\345\267\256\351\203\275\345\234\250\347\273\231\345\256\232\347\232\204\350\214\203\345\233\264\345\206\205/README.md" index 29eb95f16c65f..74f1f0511ac5d 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 057. \345\200\274\345\222\214\344\270\213\346\240\207\344\271\213\345\267\256\351\203\275\345\234\250\347\273\231\345\256\232\347\232\204\350\214\203\345\233\264\345\206\205/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 057. \345\200\274\345\222\214\344\270\213\346\240\207\344\271\213\345\267\256\351\203\275\345\234\250\347\273\231\345\256\232\347\232\204\350\214\203\345\233\264\345\206\205/README.md" @@ -66,6 +66,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python from sortedcontainers import SortedSet @@ -83,6 +85,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean containsNearbyAlmostDuplicate(int[] nums, int k, int t) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func containsNearbyAlmostDuplicate(nums []int, k int, t int) bool { n := len(nums) @@ -142,6 +150,8 @@ func containsNearbyAlmostDuplicate(nums []int, k int, t int) bool { } ``` +#### TypeScript + ```ts function containsNearbyAlmostDuplicate(nums: number[], k: number, t: number): boolean { const ts = new TreeSet(); diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 058. \346\227\245\347\250\213\350\241\250/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 058. \346\227\245\347\250\213\350\241\250/README.md" index e26dfefcde67e..44344ad0365b6 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 058. \346\227\245\347\250\213\350\241\250/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 058. \346\227\245\347\250\213\350\241\250/README.md" @@ -62,6 +62,8 @@ MyCalendar.book(20, 30); // returns true ,第三个日程安排可以添加到 +#### Python3 + ```python from sortedcontainers import SortedDict @@ -84,6 +86,8 @@ class MyCalendar: # param_1 = obj.book(start,end) ``` +#### Java + ```java import java.util.Map; import java.util.TreeMap; @@ -115,6 +119,8 @@ class MyCalendar { */ ``` +#### Go + ```go type MyCalendar struct { rbt *redblacktree.Tree diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 059. \346\225\260\346\215\256\346\265\201\347\232\204\347\254\254 K \345\244\247\346\225\260\345\200\274/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 059. \346\225\260\346\215\256\346\265\201\347\232\204\347\254\254 K \345\244\247\346\225\260\345\200\274/README.md" index 092d3932e2188..493a1956e73a9 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 059. \346\225\260\346\215\256\346\265\201\347\232\204\347\254\254 K \345\244\247\346\225\260\345\200\274/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 059. \346\225\260\346\215\256\346\265\201\347\232\204\347\254\254 K \345\244\247\346\225\260\345\200\274/README.md" @@ -67,6 +67,8 @@ kthLargest.add(4); // return 8 +#### Python3 + ```python class KthLargest: def __init__(self, k: int, nums: List[int]): @@ -87,6 +89,8 @@ class KthLargest: # param_1 = obj.add(val) ``` +#### Java + ```java class KthLargest { private PriorityQueue q; @@ -116,6 +120,8 @@ class KthLargest { */ ``` +#### C++ + ```cpp class KthLargest { public: @@ -141,6 +147,8 @@ public: */ ``` +#### Go + ```go type KthLargest struct { h *IntHeap diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 060. \345\207\272\347\216\260\351\242\221\347\216\207\346\234\200\351\253\230\347\232\204 k \344\270\252\346\225\260\345\255\227/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 060. \345\207\272\347\216\260\351\242\221\347\216\207\346\234\200\351\253\230\347\232\204 k \344\270\252\346\225\260\345\255\227/README.md" index 258618ba2db4a..bb48542187c42 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 060. \345\207\272\347\216\260\351\242\221\347\216\207\346\234\200\351\253\230\347\232\204 k \344\270\252\346\225\260\345\255\227/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 060. \345\207\272\347\216\260\351\242\221\347\216\207\346\234\200\351\253\230\347\232\204 k \344\270\252\346\225\260\345\255\227/README.md" @@ -60,6 +60,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def topKFrequent(self, nums: List[int], k: int) -> List[int]: @@ -67,6 +69,8 @@ class Solution: return [v[0] for v in cnt.most_common(k)] ``` +#### Java + ```java class Solution { public int[] topKFrequent(int[] nums, int k) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp using pii = pair; @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func topKFrequent(nums []int, k int) []int { cnt := map[int]int{} @@ -139,6 +147,8 @@ func (h *hp) Push(v any) { *h = append(*h, v.(pair)) } func (h *hp) Pop() any { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; return v } ``` +#### TypeScript + ```ts function topKFrequent(nums: number[], k: number): number[] { let hashMap = new Map(); @@ -155,6 +165,8 @@ function topKFrequent(nums: number[], k: number): number[] { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { @@ -196,6 +208,8 @@ impl Solution { +#### Python3 + ```python class Solution: def topKFrequent(self, nums: List[int], k: int) -> List[int]: @@ -208,6 +222,8 @@ class Solution: return [v[1] for v in hp] ``` +#### Java + ```java class Solution { public int[] topKFrequent(int[] nums, int k) { @@ -231,6 +247,8 @@ class Solution { } ``` +#### TypeScript + ```ts function topKFrequent(nums: number[], k: number): number[] { const map = new Map(); diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 061. \345\222\214\346\234\200\345\260\217\347\232\204 k \344\270\252\346\225\260\345\257\271/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 061. \345\222\214\346\234\200\345\260\217\347\232\204 k \344\270\252\346\225\260\345\257\271/README.md" index 9d0c17f8f2c77..15aabddd202fb 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 061. \345\222\214\346\234\200\345\260\217\347\232\204 k \344\270\252\346\225\260\345\257\271/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 061. \345\222\214\346\234\200\345\260\217\347\232\204 k \344\270\252\346\225\260\345\257\271/README.md" @@ -70,6 +70,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def kSmallestPairs( @@ -84,6 +86,8 @@ class Solution: return [p for _, p in hp] ``` +#### Java + ```java class Solution { public List> kSmallestPairs(int[] nums1, int[] nums2, int k) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go type pairHeap [][]int diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 062. \345\256\236\347\216\260\345\211\215\347\274\200\346\240\221/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 062. \345\256\236\347\216\260\345\211\215\347\274\200\346\240\221/README.md" index 8172de6793834..c65ee5b910192 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 062. \345\256\236\347\216\260\345\211\215\347\274\200\346\240\221/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 062. \345\256\236\347\216\260\345\211\215\347\274\200\346\240\221/README.md" @@ -94,6 +94,8 @@ trie.search("app"); // 返回 True +#### Python3 + ```python class Trie: def __init__(self): @@ -134,6 +136,8 @@ class Trie: # param_3 = obj.startsWith(prefix) ``` +#### Java + ```java class Trie { private Trie[] children; @@ -187,6 +191,8 @@ class Trie { */ ``` +#### C++ + ```cpp class Trie { private: @@ -238,6 +244,8 @@ public: */ ``` +#### Go + ```go type Trie struct { children [26]*Trie @@ -291,6 +299,8 @@ func (this *Trie) SearchPrefix(s string) *Trie { */ ``` +#### JavaScript + ```js /** * Initialize your data structure here. @@ -352,6 +362,8 @@ Trie.prototype.startsWith = function (prefix) { */ ``` +#### C# + ```cs public class Trie { bool isEnd; diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 063. \346\233\277\346\215\242\345\215\225\350\257\215/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 063. \346\233\277\346\215\242\345\215\225\350\257\215/README.md" index b4fc661f8c99e..6198c8eca2931 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 063. \346\233\277\346\215\242\345\215\225\350\257\215/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 063. \346\233\277\346\215\242\345\215\225\350\257\215/README.md" @@ -84,6 +84,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def replaceWords(self, dictionary: List[str], sentence: str) -> str: @@ -97,6 +99,8 @@ class Solution: return ' '.join(words) ``` +#### Java + ```java class Solution { public String replaceWords(List dictionary, String sentence) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func replaceWords(dictionary []string, sentence string) string { s := map[string]bool{} @@ -174,6 +182,8 @@ func replaceWords(dictionary []string, sentence string) string { +#### Python3 + ```python class Trie: def __init__(self): @@ -209,6 +219,8 @@ class Solution: return ' '.join(trie.search(v) for v in sentence.split()) ``` +#### Java + ```java class Trie { Trie[] children = new Trie[26]; @@ -257,6 +269,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -305,6 +319,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [26]*Trie diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 064. \347\245\236\345\245\207\347\232\204\345\255\227\345\205\270/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 064. \347\245\236\345\245\207\347\232\204\345\255\227\345\205\270/README.md" index 3f2f0fe80a232..29c7473d49328 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 064. \347\245\236\345\245\207\347\232\204\345\255\227\345\205\270/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 064. \347\245\236\345\245\207\347\232\204\345\255\227\345\205\270/README.md" @@ -76,6 +76,8 @@ magicDictionary.search("leetcoded"); // 返回 False +#### Python3 + ```python class MagicDictionary: def __init__(self): @@ -105,6 +107,8 @@ class MagicDictionary: # param_2 = obj.search(searchWord) ``` +#### Java + ```java class MagicDictionary { private Set words; @@ -156,6 +160,8 @@ class MagicDictionary { */ ``` +#### C++ + ```cpp class MagicDictionary { public: @@ -201,6 +207,8 @@ private: */ ``` +#### Go + ```go type MagicDictionary struct { words map[string]bool diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 065. \346\234\200\347\237\255\347\232\204\345\215\225\350\257\215\347\274\226\347\240\201/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 065. \346\234\200\347\237\255\347\232\204\345\215\225\350\257\215\347\274\226\347\240\201/README.md" index ad4df0267569c..879a1b2817d3f 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 065. \346\234\200\347\237\255\347\232\204\345\215\225\350\257\215\347\274\226\347\240\201/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 065. \346\234\200\347\237\255\347\232\204\345\215\225\350\257\215\347\274\226\347\240\201/README.md" @@ -70,6 +70,8 @@ words[2] = "bell" ,s 开始于 indices[2] = 5 到下一个 '# +#### Python3 + ```python class Trie: def __init__(self) -> None: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Trie { Trie[] children = new Trie[26]; @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp struct Trie { Trie* children[26] = {nullptr}; @@ -176,6 +182,8 @@ private: }; ``` +#### Go + ```go type trie struct { children [26]*trie @@ -220,6 +228,8 @@ func dfs(cur *trie, l int) int { +#### Python3 + ```python class Trie: def __init__(self): @@ -244,6 +254,8 @@ class Solution: return sum(trie.insert(w[::-1]) for w in words) ``` +#### Java + ```java class Trie { Trie[] children = new Trie[26]; @@ -276,6 +288,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -313,6 +327,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [26]*Trie diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 066. \345\215\225\350\257\215\344\271\213\345\222\214/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 066. \345\215\225\350\257\215\344\271\213\345\222\214/README.md" index d4eb2cf22774b..ac892f1b46e05 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 066. \345\215\225\350\257\215\344\271\213\345\222\214/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 066. \345\215\225\350\257\215\344\271\213\345\222\214/README.md" @@ -63,6 +63,8 @@ mapSum.sum("ap"); // return 5 (apple + app = 3 +#### Python3 + ```python class MapSum: def __init__(self): @@ -88,6 +90,8 @@ class MapSum: # param_2 = obj.sum(prefix) ``` +#### Java + ```java class MapSum { private Map data; @@ -121,6 +125,8 @@ class MapSum { */ ``` +#### C++ + ```cpp class MapSum { public: @@ -153,6 +159,8 @@ public: */ ``` +#### Go + ```go type MapSum struct { data map[string]int diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 067. \346\234\200\345\244\247\347\232\204\345\274\202\346\210\226/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 067. \346\234\200\345\244\247\347\232\204\345\274\202\346\210\226/README.md" index c2bdb061d4c87..7594245e1227f 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 067. \346\234\200\345\244\247\347\232\204\345\274\202\346\210\226/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 067. \346\234\200\345\244\247\347\232\204\345\274\202\346\210\226/README.md" @@ -81,6 +81,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def findMaximumXOR(self, nums: List[int]) -> int: @@ -103,6 +105,8 @@ class Solution: return max ``` +#### Java + ```java class Solution { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -180,6 +186,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [26]*Trie @@ -243,6 +251,8 @@ func findMaximumXOR(nums []int) int { +#### Python3 + ```python class Trie: def __init__(self): @@ -278,6 +288,8 @@ class Solution: return max(trie.search(v) for v in nums) ``` +#### Java + ```java class Trie { Trie[] children = new Trie[2]; diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 068. \346\237\245\346\211\276\346\217\222\345\205\245\344\275\215\347\275\256/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 068. \346\237\245\346\211\276\346\217\222\345\205\245\344\275\215\347\275\256/README.md" index 9cb6f5f7b878b..2b1cbbb176a52 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 068. \346\237\245\346\211\276\346\217\222\345\205\245\344\275\215\347\275\256/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 068. \346\237\245\346\211\276\346\217\222\345\205\245\344\275\215\347\275\256/README.md" @@ -77,6 +77,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def searchInsert(self, nums: List[int], target: int) -> int: @@ -90,6 +92,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int searchInsert(int[] nums, int target) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func searchInsert(nums []int, target int) int { left, right := 0, len(nums) @@ -139,6 +147,8 @@ func searchInsert(nums []int, target int) int { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 069. \345\261\261\345\263\260\346\225\260\347\273\204\347\232\204\351\241\266\351\203\250/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 069. \345\261\261\345\263\260\346\225\260\347\273\204\347\232\204\351\241\266\351\203\250/README.md" index 19fa59bd4164b..6cb4dd2436f82 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 069. \345\261\261\345\263\260\346\225\260\347\273\204\347\232\204\351\241\266\351\203\250/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 069. \345\261\261\345\263\260\346\225\260\347\273\204\347\232\204\351\241\266\351\203\250/README.md" @@ -90,6 +90,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def peakIndexInMountainArray(self, arr: List[int]) -> int: @@ -103,6 +105,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int peakIndexInMountainArray(int[] arr) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func peakIndexInMountainArray(arr []int) int { left, right := 1, len(arr)-2 @@ -152,6 +160,8 @@ func peakIndexInMountainArray(arr []int) int { } ``` +#### JavaScript + ```js /** * @param {number[]} arr diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 070. \346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 070. \346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227/README.md" index f10fcc140da56..ed8879be28bf6 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 070. \346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 070. \346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227/README.md" @@ -60,6 +60,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def singleNonDuplicate(self, nums: List[int]) -> int: @@ -74,6 +76,8 @@ class Solution: return nums[left] ``` +#### Java + ```java class Solution { public int singleNonDuplicate(int[] nums) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func singleNonDuplicate(nums []int) int { left, right := 0, len(nums)-1 @@ -125,6 +133,8 @@ func singleNonDuplicate(nums []int) int { } ``` +#### TypeScript + ```ts function singleNonDuplicate(nums: number[]): number { let left = 0, diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 071. \346\214\211\346\235\203\351\207\215\347\224\237\346\210\220\351\232\217\346\234\272\346\225\260/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 071. \346\214\211\346\235\203\351\207\215\347\224\237\346\210\220\351\232\217\346\234\272\346\225\260/README.md" index c3a393ce2ba35..fc2a5d09cc0be 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 071. \346\214\211\346\235\203\351\207\215\347\224\237\346\210\220\351\232\217\346\234\272\346\225\260/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 071. \346\214\211\346\235\203\351\207\215\347\224\237\346\210\220\351\232\217\346\234\272\346\225\260/README.md" @@ -84,6 +84,8 @@ solution.pickIndex(); // 返回 0,返回下标 0,返回该下标概率为 1/ +#### Python3 + ```python class Solution: def __init__(self, w: List[int]): @@ -110,6 +112,8 @@ class Solution: # param_1 = obj.pickIndex() ``` +#### Java + ```java class Solution { private int[] presum; @@ -145,6 +149,8 @@ class Solution { */ ``` +#### C++ + ```cpp class Solution { public: @@ -178,6 +184,8 @@ public: */ ``` +#### Go + ```go type Solution struct { presum []int diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 072. \346\261\202\345\271\263\346\226\271\346\240\271/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 072. \346\261\202\345\271\263\346\226\271\346\240\271/README.md" index 4995f41392486..e5a3f00d1894b 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 072. \346\261\202\345\271\263\346\226\271\346\240\271/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 072. \346\261\202\345\271\263\346\226\271\346\240\271/README.md" @@ -43,6 +43,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def mySqrt(self, x: int) -> int: @@ -57,6 +59,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int mySqrt(int x) { @@ -75,6 +79,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -92,6 +98,8 @@ public: }; ``` +#### Go + ```go func mySqrt(x int) int { left, right := 0, x @@ -107,6 +115,8 @@ func mySqrt(x int) int { } ``` +#### JavaScript + ```js /** * @param {number} x @@ -127,6 +137,8 @@ var mySqrt = function (x) { }; ``` +#### C# + ```cs public class Solution { public int MySqrt(int x) { diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 073. \347\213\222\347\213\222\345\220\203\351\246\231\350\225\211/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 073. \347\213\222\347\213\222\345\220\203\351\246\231\350\225\211/README.md" index 1e9665b6c2b8c..e690c64d1aabe 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 073. \347\213\222\347\213\222\345\220\203\351\246\231\350\225\211/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 073. \347\213\222\347\213\222\345\220\203\351\246\231\350\225\211/README.md" @@ -69,6 +69,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def minEatingSpeed(self, piles: List[int], h: int) -> int: @@ -83,6 +85,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int minEatingSpeed(int[] piles, int h) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func minEatingSpeed(piles []int, h int) int { left, right := 1, slices.Max(piles) @@ -146,6 +154,8 @@ func minEatingSpeed(piles []int, h int) int { } ``` +#### C# + ```cs public class Solution { public int MinEatingSpeed(int[] piles, int h) { diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 074. \345\220\210\345\271\266\345\214\272\351\227\264/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 074. \345\220\210\345\271\266\345\214\272\351\227\264/README.md" index 4879d00981438..85910bed4d7ee 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 074. \345\220\210\345\271\266\345\214\272\351\227\264/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 074. \345\220\210\345\271\266\345\214\272\351\227\264/README.md" @@ -73,6 +73,8 @@ def merge(intervals): +#### Python3 + ```python class Solution: def merge(self, intervals: List[List[int]]) -> List[List[int]]: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] merge(int[][] intervals) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func merge(intervals [][]int) [][]int { sort.Slice(intervals, func(i, j int) bool { @@ -152,6 +160,8 @@ func merge(intervals [][]int) [][]int { } ``` +#### C# + ```cs public class Solution { public int[][] Merge(int[][] intervals) { diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 075. \346\225\260\347\273\204\347\233\270\345\257\271\346\216\222\345\272\217/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 075. \346\225\260\347\273\204\347\233\270\345\257\271\346\216\222\345\272\217/README.md" index ace9ab8ce0a1a..979fe1952d23a 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 075. \346\225\260\347\273\204\347\233\270\345\257\271\346\216\222\345\272\217/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 075. \346\225\260\347\273\204\347\233\270\345\257\271\346\216\222\345\272\217/README.md" @@ -54,6 +54,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def relativeSortArray(self, arr1: List[int], arr2: List[int]) -> List[int]: @@ -62,6 +64,8 @@ class Solution: return arr1 ``` +#### Java + ```java class Solution { public int[] relativeSortArray(int[] arr1, int[] arr2) { @@ -85,6 +89,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -103,6 +109,8 @@ public: }; ``` +#### Go + ```go func relativeSortArray(arr1 []int, arr2 []int) []int { mp := make([]int, 1001) @@ -138,6 +146,8 @@ func relativeSortArray(arr1 []int, arr2 []int) []int { +#### Python3 + ```python class Solution: def relativeSortArray(self, arr1: List[int], arr2: List[int]) -> List[int]: diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 076. \346\225\260\347\273\204\344\270\255\347\232\204\347\254\254 k \345\244\247\347\232\204\346\225\260\345\255\227/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 076. \346\225\260\347\273\204\344\270\255\347\232\204\347\254\254 k \345\244\247\347\232\204\346\225\260\345\255\227/README.md" index 1de846365e4bc..3832f7087e47a 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 076. \346\225\260\347\273\204\344\270\255\347\232\204\347\254\254 k \345\244\247\347\232\204\346\225\260\345\255\227/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 076. \346\225\260\347\273\204\344\270\255\347\232\204\347\254\254 k \345\244\247\347\232\204\346\225\260\345\255\227/README.md" @@ -53,6 +53,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def findKthLargest(self, nums: List[int], k: int) -> int: @@ -80,6 +82,8 @@ class Solution: return quick_sort(0, n - 1, n - k) ``` +#### Java + ```java class Solution { public int findKthLargest(int[] nums, int k) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func findKthLargest(nums []int, k int) int { n := len(nums) diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 077. \351\223\276\350\241\250\346\216\222\345\272\217/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 077. \351\223\276\350\241\250\346\216\222\345\272\217/README.md" index 58f2ceded4203..2cf786ba9d063 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 077. \351\223\276\350\241\250\346\216\222\345\272\217/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 077. \351\223\276\350\241\250\346\216\222\345\272\217/README.md" @@ -70,6 +70,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -100,6 +102,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -226,6 +234,8 @@ func sortList(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -270,6 +280,8 @@ function sortList(head: ListNode | null): ListNode | null { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -313,6 +325,8 @@ var sortList = function (head) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 078. \345\220\210\345\271\266\346\216\222\345\272\217\351\223\276\350\241\250/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 078. \345\220\210\345\271\266\346\216\222\345\272\217\351\223\276\350\241\250/README.md" index f4194aeb631e1..46dda02934b66 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 078. \345\220\210\345\271\266\346\216\222\345\272\217\351\223\276\350\241\250/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 078. \345\220\210\345\271\266\346\216\222\345\272\217\351\223\276\350\241\250/README.md" @@ -73,6 +73,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -103,6 +105,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -185,6 +191,8 @@ private: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -226,6 +234,8 @@ func mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -267,6 +277,8 @@ function mergeTwoLists(l1, l2) { } ``` +#### C# + ```cs /** * Definition for singly-linked list. @@ -310,6 +322,8 @@ public class Solution { } ``` +#### Ruby + ```rb # Definition for singly-linked list. # class ListNode diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 079. \346\211\200\346\234\211\345\255\220\351\233\206/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 079. \346\211\200\346\234\211\345\255\220\351\233\206/README.md" index 579c398d4f94a..f923f68cfd386 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 079. \346\211\200\346\234\211\345\255\220\351\233\206/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 079. \346\211\200\346\234\211\345\255\220\351\233\206/README.md" @@ -55,6 +55,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def subsets(self, nums: List[int]) -> List[List[int]]: @@ -73,6 +75,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public List> subsets(int[] nums) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func subsets(nums []int) [][]int { var res [][]int @@ -138,6 +146,8 @@ func dfs(i int, nums, t []int, res *[][]int) { } ``` +#### TypeScript + ```ts function subsets(nums: number[]): number[][] { const n = nums.length; @@ -155,6 +165,8 @@ function subsets(nums: number[]): number[][] { } ``` +#### Rust + ```rust impl Solution { fn dfs(mut i: usize, t: &mut Vec, ans: &mut Vec>, nums: &Vec) { diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 080. \345\220\253\346\234\211 k \344\270\252\345\205\203\347\264\240\347\232\204\347\273\204\345\220\210/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 080. \345\220\253\346\234\211 k \344\270\252\345\205\203\347\264\240\347\232\204\347\273\204\345\220\210/README.md" index a1e596018b05f..e35ccea2e7284 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 080. \345\220\253\346\234\211 k \344\270\252\345\205\203\347\264\240\347\232\204\347\273\204\345\220\210/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 080. \345\220\253\346\234\211 k \344\270\252\345\205\203\347\264\240\347\232\204\347\273\204\345\220\210/README.md" @@ -58,6 +58,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def combine(self, n: int, k: int) -> List[List[int]]: @@ -76,6 +78,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public List> combine(int n, int k) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func combine(n int, k int) [][]int { var res [][]int diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 081. \345\205\201\350\256\270\351\207\215\345\244\215\351\200\211\346\213\251\345\205\203\347\264\240\347\232\204\347\273\204\345\220\210/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 081. \345\205\201\350\256\270\351\207\215\345\244\215\351\200\211\346\213\251\345\205\203\347\264\240\347\232\204\347\273\204\345\220\210/README.md" index 1dcef51f44306..5ea16337e40df 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 081. \345\205\201\350\256\270\351\207\215\345\244\215\351\200\211\346\213\251\345\205\203\347\264\240\347\232\204\347\273\204\345\220\210/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 081. \345\205\201\350\256\270\351\207\215\345\244\215\351\200\211\346\213\251\345\205\203\347\264\240\347\232\204\347\273\204\345\220\210/README.md" @@ -78,6 +78,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans; @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func combinationSum(candidates []int, target int) [][]int { var ans [][]int @@ -190,6 +198,8 @@ func combinationSum(candidates []int, target int) [][]int { } ``` +#### C# + ```cs using System; using System.Collections.Generic; diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 082. \345\220\253\346\234\211\351\207\215\345\244\215\345\205\203\347\264\240\351\233\206\345\220\210\347\232\204\347\273\204\345\220\210/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 082. \345\220\253\346\234\211\351\207\215\345\244\215\345\205\203\347\264\240\351\233\206\345\220\210\347\232\204\347\273\204\345\220\210/README.md" index 32095304ebb19..eff8b96dd4837 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 082. \345\220\253\346\234\211\351\207\215\345\244\215\345\205\203\347\264\240\351\233\206\345\220\210\347\232\204\347\273\204\345\220\210/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 082. \345\220\253\346\234\211\351\207\215\345\244\215\345\205\203\347\264\240\351\233\206\345\220\210\347\232\204\347\273\204\345\220\210/README.md" @@ -63,6 +63,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def combinationSum2(self, candidates: List[int], target: int) -> List[List[int]]: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans; @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func combinationSum2(candidates []int, target int) [][]int { var ans [][]int @@ -182,6 +190,8 @@ func combinationSum2(candidates []int, target int) [][]int { } ``` +#### C# + ```cs using System; using System.Collections.Generic; diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 083. \346\262\241\346\234\211\351\207\215\345\244\215\345\205\203\347\264\240\351\233\206\345\220\210\347\232\204\345\205\250\346\216\222\345\210\227/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 083. \346\262\241\346\234\211\351\207\215\345\244\215\345\205\203\347\264\240\351\233\206\345\220\210\347\232\204\345\205\250\346\216\222\345\210\227/README.md" index 9955e190977e1..2114fa3d9b8e6 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 083. \346\262\241\346\234\211\351\207\215\345\244\215\345\205\203\347\264\240\351\233\206\345\220\210\347\232\204\345\205\250\346\216\222\345\210\227/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 083. \346\262\241\346\234\211\351\207\215\345\244\215\345\205\203\347\264\240\351\233\206\345\220\210\347\232\204\345\205\250\346\216\222\345\210\227/README.md" @@ -60,6 +60,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def permute(self, nums: List[int]) -> List[List[int]]: @@ -83,6 +85,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public List> permute(int[] nums) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func permute(nums []int) [][]int { n := len(nums) @@ -170,6 +178,8 @@ func dfs(u, n int, nums []int, used []bool, path []int, res *[][]int) { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -201,6 +211,8 @@ function dfs(u, n, nums, used, path, res) { } ``` +#### C# + ```cs using System.Collections.Generic; using System.Linq; diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 084. \345\220\253\346\234\211\351\207\215\345\244\215\345\205\203\347\264\240\351\233\206\345\220\210\347\232\204\345\205\250\346\216\222\345\210\227/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 084. \345\220\253\346\234\211\351\207\215\345\244\215\345\205\203\347\264\240\351\233\206\345\220\210\347\232\204\345\205\250\346\216\222\345\210\227/README.md" index 17abc1ab77d7c..998bcffb292d6 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 084. \345\220\253\346\234\211\351\207\215\345\244\215\345\205\203\347\264\240\351\233\206\345\220\210\347\232\204\345\205\250\346\216\222\345\210\227/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 084. \345\220\253\346\234\211\351\207\215\345\244\215\345\205\203\347\264\240\351\233\206\345\220\210\347\232\204\345\205\250\346\216\222\345\210\227/README.md" @@ -55,6 +55,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def permuteUnique(self, nums: List[int]) -> List[List[int]]: @@ -80,6 +82,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public List> permuteUnique(int[] nums) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func permuteUnique(nums []int) [][]int { n := len(nums) @@ -171,6 +179,8 @@ func dfs(u, n int, nums []int, used []bool, path []int, res *[][]int) { } ``` +#### C# + ```cs using System.Collections.Generic; using System.Linq; diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 085. \347\224\237\346\210\220\345\214\271\351\205\215\347\232\204\346\213\254\345\217\267/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 085. \347\224\237\346\210\220\345\214\271\351\205\215\347\232\204\346\213\254\345\217\267/README.md" index 17d42d71ca580..80e7c55cfd3ff 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 085. \347\224\237\346\210\220\345\214\271\351\205\215\347\232\204\346\213\254\345\217\267/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 085. \347\224\237\346\210\220\345\214\271\351\205\215\347\232\204\346\213\254\345\217\267/README.md" @@ -51,6 +51,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def generateParenthesis(self, n: int) -> List[str]: @@ -68,6 +70,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List generateParenthesis(int n) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func generateParenthesis(n int) []string { var ans []string @@ -132,6 +140,8 @@ func generateParenthesis(n int) []string { } ``` +#### TypeScript + ```ts function generateParenthesis(n: number): string[] { let ans = []; @@ -152,6 +162,8 @@ function generateParenthesis(n: number): string[] { } ``` +#### JavaScript + ```js /** * @param {number} n diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 086. \345\210\206\345\211\262\345\233\236\346\226\207\345\255\220\345\255\227\347\254\246\344\270\262/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 086. \345\210\206\345\211\262\345\233\236\346\226\207\345\255\220\345\255\227\347\254\246\344\270\262/README.md" index a44fe687c27dc..29b5e9db2fcee 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 086. \345\210\206\345\211\262\345\233\236\346\226\207\345\255\220\345\255\227\347\254\246\344\270\262/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 086. \345\210\206\345\211\262\345\233\236\346\226\207\345\255\220\345\255\227\347\254\246\344\270\262/README.md" @@ -70,6 +70,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def partition(self, s: str) -> List[List[str]]: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func partition(s string) (ans [][]string) { n := len(s) @@ -202,6 +210,8 @@ func partition(s string) (ans [][]string) { } ``` +#### TypeScript + ```ts function partition(s: string): string[][] { const n = s.length; @@ -231,6 +241,8 @@ function partition(s: string): string[][] { } ``` +#### C# + ```cs public class Solution { private int n; diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 087. \345\244\215\345\216\237 IP/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 087. \345\244\215\345\216\237 IP/README.md" index 890c11f2570df..68621fb5d7e99 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 087. \345\244\215\345\216\237 IP/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 087. \345\244\215\345\216\237 IP/README.md" @@ -87,6 +87,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def restoreIpAddresses(self, s: str) -> List[str]: @@ -114,6 +116,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -182,6 +188,8 @@ public: }; ``` +#### Go + ```go func restoreIpAddresses(s string) (ans []string) { n := len(s) @@ -211,6 +219,8 @@ func restoreIpAddresses(s string) (ans []string) { } ``` +#### TypeScript + ```ts function restoreIpAddresses(s: string): string[] { const n = s.length; @@ -240,6 +250,8 @@ function restoreIpAddresses(s: string): string[] { } ``` +#### C# + ```cs public class Solution { private IList ans = new List(); diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 088. \347\210\254\346\245\274\346\242\257\347\232\204\346\234\200\345\260\221\346\210\220\346\234\254/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 088. \347\210\254\346\245\274\346\242\257\347\232\204\346\234\200\345\260\221\346\210\220\346\234\254/README.md" index 1a03e8b674b43..e4430696431d1 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 088. \347\210\254\346\245\274\346\242\257\347\232\204\346\234\200\345\260\221\346\210\220\346\234\254/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 088. \347\210\254\346\245\274\346\242\257\347\232\204\346\234\200\345\260\221\346\210\220\346\234\254/README.md" @@ -72,6 +72,8 @@ $$ +#### Python3 + ```python class Solution: def minCostClimbingStairs(self, cost: List[int]) -> int: @@ -82,6 +84,8 @@ class Solution: return dp[-1] ``` +#### Java + ```java class Solution { public int minCostClimbingStairs(int[] cost) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func minCostClimbingStairs(cost []int) int { n := len(cost) @@ -120,6 +128,8 @@ func minCostClimbingStairs(cost []int) int { } ``` +#### TypeScript + ```ts function minCostClimbingStairs(cost: number[]): number { const n = cost.length; @@ -141,6 +151,8 @@ function minCostClimbingStairs(cost: number[]): number { +#### Python3 + ```python class Solution: def minCostClimbingStairs(self, cost: List[int]) -> int: @@ -150,6 +162,8 @@ class Solution: return b ``` +#### Java + ```java class Solution { public int minCostClimbingStairs(int[] cost) { @@ -164,6 +178,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -179,6 +195,8 @@ public: }; ``` +#### Go + ```go func minCostClimbingStairs(cost []int) int { a, b := 0, 0 @@ -189,6 +207,8 @@ func minCostClimbingStairs(cost []int) int { } ``` +#### TypeScript + ```ts function minCostClimbingStairs(cost: number[]): number { let a = 0, diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 089. \346\210\277\345\261\213\345\201\267\347\233\227/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 089. \346\210\277\345\261\213\345\201\267\347\233\227/README.md" index 8d5c72a74997d..95dba6daa7ebc 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 089. \346\210\277\345\261\213\345\201\267\347\233\227/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 089. \346\210\277\345\261\213\345\201\267\347\233\227/README.md" @@ -81,6 +81,8 @@ $$ +#### Python3 + ```python class Solution: def rob(self, nums: List[int]) -> int: @@ -92,6 +94,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int rob(int[] nums) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func rob(nums []int) int { n := len(nums) @@ -134,6 +142,8 @@ func rob(nums []int) int { } ``` +#### TypeScript + ```ts function rob(nums: number[]): number { const n = nums.length; @@ -146,6 +156,8 @@ function rob(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn rob(nums: Vec) -> i32 { @@ -168,6 +180,8 @@ impl Solution { +#### Python3 + ```python class Solution: def rob(self, nums: List[int]) -> int: @@ -177,6 +191,8 @@ class Solution: return max(f, g) ``` +#### Java + ```java class Solution { public int rob(int[] nums) { @@ -191,6 +207,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -206,6 +224,8 @@ public: }; ``` +#### Go + ```go func rob(nums []int) int { f, g := 0, 0 @@ -216,6 +236,8 @@ func rob(nums []int) int { } ``` +#### TypeScript + ```ts function rob(nums: number[]): number { let [f, g] = [0, 0]; diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 090. \347\216\257\345\275\242\346\210\277\345\261\213\345\201\267\347\233\227/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 090. \347\216\257\345\275\242\346\210\277\345\261\213\345\201\267\347\233\227/README.md" index a7c6c952fa70c..cbdde236ac876 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 090. \347\216\257\345\275\242\346\210\277\345\261\213\345\201\267\347\233\227/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 090. \347\216\257\345\275\242\346\210\277\345\261\213\345\201\267\347\233\227/README.md" @@ -67,6 +67,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def rob(self, nums: List[int]) -> int: @@ -81,6 +83,8 @@ class Solution: return max(_rob(nums[1:]), _rob(nums[:-1])) ``` +#### Java + ```java class Solution { public int rob(int[] nums) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func rob(nums []int) int { n := len(nums) @@ -144,6 +152,8 @@ func robRange(nums []int, l, r int) int { } ``` +#### TypeScript + ```ts function rob(nums: number[]): number { const n = nums.length; @@ -161,6 +171,8 @@ function rob(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn rob(nums: Vec) -> i32 { diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 091. \347\262\211\345\210\267\346\210\277\345\255\220/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 091. \347\262\211\345\210\267\346\210\277\345\255\220/README.md" index 20ea967ec252b..f47a979f234bd 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 091. \347\262\211\345\210\267\346\210\277\345\255\220/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 091. \347\262\211\345\210\267\346\210\277\345\255\220/README.md" @@ -62,6 +62,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def minCost(self, costs: List[List[int]]) -> int: @@ -74,6 +76,8 @@ class Solution: return min(r, g, b) ``` +#### Java + ```java class Solution { public int minCost(int[][] costs) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func minCost(costs [][]int) int { r, g, b := 0, 0, 0 @@ -118,6 +126,8 @@ func minCost(costs [][]int) int { } ``` +#### TypeScript + ```ts function minCost(costs: number[][]): number { let [r, g, b] = [0, 0, 0]; @@ -128,6 +138,8 @@ function minCost(costs: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_cost(costs: Vec>) -> i32 { diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 092. \347\277\273\350\275\254\345\255\227\347\254\246/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 092. \347\277\273\350\275\254\345\255\227\347\254\246/README.md" index 8854e1d8e83d3..799a58460f4de 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 092. \347\277\273\350\275\254\345\255\227\347\254\246/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 092. \347\277\273\350\275\254\345\255\227\347\254\246/README.md" @@ -72,6 +72,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def minFlipsMonoIncr(self, s: str) -> int: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minFlipsMonoIncr(String s) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func minFlipsMonoIncr(s string) int { n := len(s) @@ -152,6 +160,8 @@ func minFlipsMonoIncr(s string) int { } ``` +#### TypeScript + ```ts function minFlipsMonoIncr(s: string): number { const n = s.length; diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 093. \346\234\200\351\225\277\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 093. \346\234\200\351\225\277\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/README.md" index a7ad39bea1927..7bece72ba906c 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 093. \346\234\200\351\225\277\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 093. \346\234\200\351\225\277\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/README.md" @@ -68,6 +68,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def lenLongestFibSubseq(self, arr: List[int]) -> int: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int lenLongestFibSubseq(int[] arr) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func lenLongestFibSubseq(arr []int) int { n := len(arr) diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 094. \346\234\200\345\260\221\345\233\236\346\226\207\345\210\206\345\211\262/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 094. \346\234\200\345\260\221\345\233\236\346\226\207\345\210\206\345\211\262/README.md" index 1308836a21c92..3147f7ba4e499 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 094. \346\234\200\345\260\221\345\233\236\346\226\207\345\210\206\345\211\262/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 094. \346\234\200\345\260\221\345\233\236\346\226\207\345\210\206\345\211\262/README.md" @@ -80,6 +80,8 @@ $$ +#### Python3 + ```python class Solution: def minCut(self, s: str) -> int: @@ -96,6 +98,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int minCut(String s) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func minCut(s string) int { n := len(s) @@ -183,6 +191,8 @@ func minCut(s string) int { } ``` +#### TypeScript + ```ts function minCut(s: string): number { const n = s.length; @@ -208,6 +218,8 @@ function minCut(s: string): number { } ``` +#### C# + ```cs public class Solution { public int MinCut(string s) { diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 095. \346\234\200\351\225\277\345\205\254\345\205\261\345\255\220\345\272\217\345\210\227/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 095. \346\234\200\351\225\277\345\205\254\345\205\261\345\255\220\345\272\217\345\210\227/README.md" index b8ca20abfee75..eafbc0baaa62c 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 095. \346\234\200\351\225\277\345\205\254\345\205\261\345\255\220\345\272\217\345\210\227/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 095. \346\234\200\351\225\277\345\205\254\345\205\261\345\255\220\345\272\217\345\210\227/README.md" @@ -84,6 +84,8 @@ $$ +#### Python3 + ```python class Solution: def longestCommonSubsequence(self, text1: str, text2: str) -> int: @@ -98,6 +100,8 @@ class Solution: return f[-1][-1] ``` +#### Java + ```java class Solution { public int longestCommonSubsequence(String text1, String text2) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func longestCommonSubsequence(text1 string, text2 string) int { m, n := len(text1), len(text2) @@ -157,6 +165,8 @@ func longestCommonSubsequence(text1 string, text2 string) int { } ``` +#### TypeScript + ```ts function longestCommonSubsequence(text1: string, text2: string): number { const m = text1.length; @@ -175,6 +185,8 @@ function longestCommonSubsequence(text1: string, text2: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn longest_common_subsequence(text1: String, text2: String) -> i32 { @@ -195,6 +207,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} text1 @@ -218,6 +232,8 @@ var longestCommonSubsequence = function (text1, text2) { }; ``` +#### C# + ```cs public class Solution { public int LongestCommonSubsequence(string text1, string text2) { @@ -237,6 +253,8 @@ public class Solution { } ``` +#### Kotlin + ```kotlin class Solution { fun longestCommonSubsequence(text1: String, text2: String): Int { diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 096. \345\255\227\347\254\246\344\270\262\344\272\244\347\273\207/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 096. \345\255\227\347\254\246\344\270\262\344\272\244\347\273\207/README.md" index ae986736bb6e7..1bdb9ae5b776e 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 096. \345\255\227\347\254\246\344\270\262\344\272\244\347\273\207/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 096. \345\255\227\347\254\246\344\270\262\344\272\244\347\273\207/README.md" @@ -91,6 +91,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def isInterleave(self, s1: str, s2: str, s3: str) -> bool: @@ -111,6 +113,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private Map, Boolean> f = new HashMap<>(); @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -185,6 +191,8 @@ public: }; ``` +#### Go + ```go func isInterleave(s1 string, s2 string, s3 string) bool { m, n := len(s1), len(s2) @@ -209,6 +217,8 @@ func isInterleave(s1 string, s2 string, s3 string) bool { } ``` +#### TypeScript + ```ts function isInterleave(s1: string, s2: string, s3: string): boolean { const m = s1.length; @@ -237,6 +247,8 @@ function isInterleave(s1: string, s2: string, s3: string): boolean { } ``` +#### C# + ```cs public class Solution { private int m; @@ -308,6 +320,8 @@ $$ +#### Python3 + ```python class Solution: def isInterleave(self, s1: str, s2: str, s3: str) -> bool: @@ -326,6 +340,8 @@ class Solution: return f[m][n] ``` +#### Java + ```java class Solution { public boolean isInterleave(String s1, String s2, String s3) { @@ -351,6 +367,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -378,6 +396,8 @@ public: }; ``` +#### Go + ```go func isInterleave(s1 string, s2 string, s3 string) bool { m, n := len(s1), len(s2) @@ -404,6 +424,8 @@ func isInterleave(s1 string, s2 string, s3 string) bool { } ``` +#### TypeScript + ```ts function isInterleave(s1: string, s2: string, s3: string): boolean { const m = s1.length; @@ -428,6 +450,8 @@ function isInterleave(s1: string, s2: string, s3: string): boolean { } ``` +#### C# + ```cs public class Solution { public bool IsInterleave(string s1, string s2, string s3) { @@ -463,6 +487,8 @@ public class Solution { +#### Python3 + ```python class Solution: def isInterleave(self, s1: str, s2: str, s3: str) -> bool: @@ -480,6 +506,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public boolean isInterleave(String s1, String s2, String s3) { @@ -505,6 +533,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -532,6 +562,8 @@ public: }; ``` +#### Go + ```go func isInterleave(s1 string, s2 string, s3 string) bool { m, n := len(s1), len(s2) @@ -555,6 +587,8 @@ func isInterleave(s1 string, s2 string, s3 string) bool { } ``` +#### TypeScript + ```ts function isInterleave(s1: string, s2: string, s3: string): boolean { const m = s1.length; @@ -579,6 +613,8 @@ function isInterleave(s1: string, s2: string, s3: string): boolean { } ``` +#### C# + ```cs public class Solution { public bool IsInterleave(string s1, string s2, string s3) { diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 097. \345\255\220\345\272\217\345\210\227\347\232\204\346\225\260\347\233\256/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 097. \345\255\220\345\272\217\345\210\227\347\232\204\346\225\260\347\233\256/README.md" index 434e795183ad7..b0d69eacdb89f 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 097. \345\255\220\345\272\217\345\210\227\347\232\204\346\225\260\347\233\256/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 097. \345\255\220\345\272\217\345\210\227\347\232\204\346\225\260\347\233\256/README.md" @@ -91,6 +91,8 @@ $$ +#### Python3 + ```python class Solution: def numDistinct(self, s: str, t: str) -> int: @@ -106,6 +108,8 @@ class Solution: return f[m][n] ``` +#### Java + ```java class Solution { public int numDistinct(String s, String t) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func numDistinct(s string, t string) int { m, n := len(s), len(t) @@ -172,6 +180,8 @@ func numDistinct(s string, t string) int { } ``` +#### TypeScript + ```ts function numDistinct(s: string, t: string): number { const m = s.length; @@ -202,6 +212,8 @@ function numDistinct(s: string, t: string): number { +#### Python3 + ```python class Solution: def numDistinct(self, s: str, t: str) -> int: @@ -214,6 +226,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int numDistinct(String s, String t) { @@ -233,6 +247,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -254,6 +270,8 @@ public: }; ``` +#### Go + ```go func numDistinct(s string, t string) int { n := len(t) @@ -270,6 +288,8 @@ func numDistinct(s string, t string) int { } ``` +#### TypeScript + ```ts function numDistinct(s: string, t: string): number { const n = t.length; diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 098. \350\267\257\345\276\204\347\232\204\346\225\260\347\233\256/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 098. \350\267\257\345\276\204\347\232\204\346\225\260\347\233\256/README.md" index 69203592532e6..805e968332fcc 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 098. \350\267\257\345\276\204\347\232\204\346\225\260\347\233\256/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 098. \350\267\257\345\276\204\347\232\204\346\225\260\347\233\256/README.md" @@ -97,6 +97,8 @@ $$ +#### Python3 + ```python class Solution: def uniquePaths(self, m: int, n: int) -> int: @@ -111,6 +113,8 @@ class Solution: return f[-1][-1] ``` +#### Java + ```java class Solution { public int uniquePaths(int m, int n) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func uniquePaths(m int, n int) int { f := make([][]int, m) @@ -173,6 +181,8 @@ func uniquePaths(m int, n int) int { } ``` +#### TypeScript + ```ts function uniquePaths(m: number, n: number): number { const f: number[][] = Array(m) @@ -193,6 +203,8 @@ function uniquePaths(m: number, n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn unique_paths(m: i32, n: i32) -> i32 { @@ -208,6 +220,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} m @@ -243,6 +257,8 @@ var uniquePaths = function (m, n) { +#### Python3 + ```python class Solution: def uniquePaths(self, m: int, n: int) -> int: @@ -253,6 +269,8 @@ class Solution: return f[-1][-1] ``` +#### Java + ```java class Solution { public int uniquePaths(int m, int n) { @@ -270,6 +288,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -285,6 +305,8 @@ public: }; ``` +#### Go + ```go func uniquePaths(m int, n int) int { f := make([][]int, m) @@ -303,6 +325,8 @@ func uniquePaths(m int, n int) int { } ``` +#### TypeScript + ```ts function uniquePaths(m: number, n: number): number { const f: number[][] = Array(m) @@ -317,6 +341,8 @@ function uniquePaths(m: number, n: number): number { } ``` +#### JavaScript + ```js /** * @param {number} m @@ -346,6 +372,8 @@ var uniquePaths = function (m, n) { +#### Python3 + ```python class Solution: def uniquePaths(self, m: int, n: int) -> int: @@ -356,6 +384,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int uniquePaths(int m, int n) { @@ -371,6 +401,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -386,6 +418,8 @@ public: }; ``` +#### Go + ```go func uniquePaths(m int, n int) int { f := make([]int, n+1) @@ -401,6 +435,8 @@ func uniquePaths(m int, n int) int { } ``` +#### TypeScript + ```ts function uniquePaths(m: number, n: number): number { const f: number[] = Array(n).fill(1); @@ -413,6 +449,8 @@ function uniquePaths(m: number, n: number): number { } ``` +#### JavaScript + ```js /** * @param {number} m diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 099. \346\234\200\345\260\217\350\267\257\345\276\204\344\271\213\345\222\214/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 099. \346\234\200\345\260\217\350\267\257\345\276\204\344\271\213\345\222\214/README.md" index 61afc9d56f29b..af4b02afa7ef6 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 099. \346\234\200\345\260\217\350\267\257\345\276\204\344\271\213\345\222\214/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 099. \346\234\200\345\260\217\350\267\257\345\276\204\344\271\213\345\222\214/README.md" @@ -59,6 +59,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def minPathSum(self, grid: List[List[int]]) -> int: @@ -74,6 +76,8 @@ class Solution: return dp[-1][-1] ``` +#### Java + ```java class Solution { public int minPathSum(int[][] grid) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func minPathSum(grid [][]int) int { m, n := len(grid), len(grid[0]) @@ -141,6 +149,8 @@ func minPathSum(grid [][]int) int { } ``` +#### TypeScript + ```ts function minPathSum(grid: number[][]): number { let m = grid.length, @@ -164,6 +174,8 @@ function minPathSum(grid: number[][]): number { } ``` +#### C# + ```cs public class Solution { public int MinPathSum(int[][] grid) { diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 100. \344\270\211\350\247\222\345\275\242\344\270\255\346\234\200\345\260\217\350\267\257\345\276\204\344\271\213\345\222\214/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 100. \344\270\211\350\247\222\345\275\242\344\270\255\346\234\200\345\260\217\350\267\257\345\276\204\344\271\213\345\222\214/README.md" index 62c28385d8db8..ee4cb53c0361f 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 100. \344\270\211\350\247\222\345\275\242\344\270\255\346\234\200\345\260\217\350\267\257\345\276\204\344\271\213\345\222\214/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 100. \344\270\211\350\247\222\345\275\242\344\270\255\346\234\200\345\260\217\350\267\257\345\276\204\344\271\213\345\222\214/README.md" @@ -70,6 +70,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def minimumTotal(self, triangle: List[List[int]]) -> int: @@ -81,6 +83,8 @@ class Solution: return dp[0][0] ``` +#### Java + ```java class Solution { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func minimumTotal(triangle [][]int) int { n := len(triangle) @@ -134,6 +142,8 @@ func minimumTotal(triangle [][]int) int { +#### Python3 + ```python class Solution: def minimumTotal(self, triangle: List[List[int]]) -> int: diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 101. \345\210\206\345\211\262\347\255\211\345\222\214\345\255\220\344\270\262/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 101. \345\210\206\345\211\262\347\255\211\345\222\214\345\255\220\344\270\262/README.md" index 88b9cc018aa36..d18ad79e1d2db 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 101. \345\210\206\345\211\262\347\255\211\345\222\214\345\255\220\344\270\262/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 101. \345\210\206\345\211\262\347\255\211\345\222\214\345\255\220\344\270\262/README.md" @@ -55,6 +55,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def canPartition(self, nums: List[int]) -> bool: @@ -77,6 +79,8 @@ class Solution: return dp[-1][-1] ``` +#### Java + ```java class Solution { public boolean canPartition(int[] nums) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func canPartition(nums []int) bool { s := 0 @@ -158,6 +166,8 @@ func canPartition(nums []int) bool { +#### Python3 + ```python class Solution: def canPartition(self, nums: List[int]) -> bool: @@ -187,6 +197,8 @@ class Solution: +#### Python3 + ```python class Solution: def canPartition(self, nums: List[int]) -> bool: diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 102. \345\212\240\345\207\217\347\232\204\347\233\256\346\240\207\345\200\274/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 102. \345\212\240\345\207\217\347\232\204\347\233\256\346\240\207\345\200\274/README.md" index dc3d85944843c..8c6e72e679a66 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 102. \345\212\240\345\207\217\347\232\204\347\233\256\346\240\207\345\200\274/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 102. \345\212\240\345\207\217\347\232\204\347\233\256\346\240\207\345\200\274/README.md" @@ -68,6 +68,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def findTargetSumWays(self, nums: List[int], target: int) -> int: @@ -85,6 +87,8 @@ class Solution: return dp[n - 1][target + 1000] ``` +#### Java + ```java class Solution { public int findTargetSumWays(int[] nums, int target) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func findTargetSumWays(nums []int, target int) int { if target < -1000 || target > 1000 { @@ -165,6 +173,8 @@ func findTargetSumWays(nums []int, target int) int { +#### Python3 + ```python class Solution: def findTargetSumWays(self, nums: List[int], target: int) -> int: @@ -183,6 +193,8 @@ class Solution: return dp[-1][-1] ``` +#### Java + ```java class Solution { public int findTargetSumWays(int[] nums, int target) { @@ -206,6 +218,8 @@ class Solution { } ``` +#### Go + ```go func findTargetSumWays(nums []int, target int) int { s := 0 @@ -237,6 +251,8 @@ func findTargetSumWays(nums []int, target int) int { +#### Python3 + ```python class Solution: def findTargetSumWays(self, nums: List[int], target: int) -> int: @@ -263,6 +279,8 @@ class Solution: +#### Python3 + ```python class Solution: def findTargetSumWays(self, nums: List[int], target: int) -> int: diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 103. \346\234\200\345\260\221\347\232\204\347\241\254\345\270\201\346\225\260\347\233\256/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 103. \346\234\200\345\260\221\347\232\204\347\241\254\345\270\201\346\225\260\347\233\256/README.md" index 1097167699d5c..96d02c1d78299 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 103. \346\234\200\345\260\221\347\232\204\347\241\254\345\270\201\346\225\260\347\233\256/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 103. \346\234\200\345\260\221\347\232\204\347\241\254\345\270\201\346\225\260\347\233\256/README.md" @@ -75,6 +75,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def coinChange(self, coins: List[int], amount: int) -> int: @@ -86,6 +88,8 @@ class Solution: return -1 if dp[-1] > amount else dp[-1] ``` +#### Java + ```java class Solution { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func coinChange(coins []int, amount int) int { dp := make([]int, amount+1) @@ -141,6 +149,8 @@ func coinChange(coins []int, amount int) int { } ``` +#### JavaScript + ```js /** * @param {number[]} coins @@ -169,6 +179,8 @@ var coinChange = function (coins, amount) { +#### Java + ```java class Solution { @@ -203,6 +215,8 @@ class Solution { +#### Java + ```java class Solution { diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 104. \346\216\222\345\210\227\347\232\204\346\225\260\347\233\256/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 104. \346\216\222\345\210\227\347\232\204\346\225\260\347\233\256/README.md" index cd04be172d3b2..5bae4765fa3e0 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 104. \346\216\222\345\210\227\347\232\204\346\225\260\347\233\256/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 104. \346\216\222\345\210\227\347\232\204\346\225\260\347\233\256/README.md" @@ -70,6 +70,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def combinationSum4(self, nums: List[int], target: int) -> int: @@ -82,6 +84,8 @@ class Solution: return dp[-1] ``` +#### Java + ```java class Solution { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func combinationSum4(nums []int, target int) int { dp := make([]int, target+1) diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 105. \345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 105. \345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257/README.md" index 38a8c41351fa4..fec092604a769 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 105. \345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 105. \345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257/README.md" @@ -63,6 +63,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def maxAreaOfIsland(self, grid: List[List[int]]) -> int: @@ -82,6 +84,8 @@ class Solution: return max(dfs(i, j) for i in range(m) for j in range(n)) ``` +#### Java + ```java class Solution { private int m; @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func maxAreaOfIsland(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -178,6 +186,8 @@ func maxAreaOfIsland(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function maxAreaOfIsland(grid: number[][]): number { const m = grid.length; @@ -207,6 +217,8 @@ function maxAreaOfIsland(grid: number[][]): number { } ``` +#### Rust + ```rust impl Solution { fn dfs(grid: &mut Vec>, i: usize, j: usize) -> i32 { diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 106. \344\272\214\345\210\206\345\233\276/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 106. \344\272\214\345\210\206\345\233\276/README.md" index 5ecbacd4960a4..710a738b34294 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 106. \344\272\214\345\210\206\345\233\276/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 106. \344\272\214\345\210\206\345\233\276/README.md" @@ -74,6 +74,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def isBipartite(self, graph: List[List[int]]) -> bool: @@ -92,6 +94,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { private int[] p; @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func isBipartite(graph [][]int) bool { n := len(graph) diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 107. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\235\347\246\273/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 107. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\235\347\246\273/README.md" index c8ddc11b0e445..7a1840e9e959b 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 107. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\235\347\246\273/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 107. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\235\347\246\273/README.md" @@ -66,6 +66,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def updateMatrix(self, mat: List[List[int]]) -> List[List[int]]: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func updateMatrix(mat [][]int) [][]int { m, n := len(mat), len(mat[0]) diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 108. \345\215\225\350\257\215\346\274\224\345\217\230/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 108. \345\215\225\350\257\215\346\274\224\345\217\230/README.md" index 8b320229bc0b9..12309e85a5a3a 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 108. \345\215\225\350\257\215\346\274\224\345\217\230/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 108. \345\215\225\350\257\215\346\274\224\345\217\230/README.md" @@ -67,6 +67,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def ladderLength(self, beginWord: str, endWord: str, wordList: List[str]) -> int: @@ -94,6 +96,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func ladderLength(beginWord string, endWord string, wordList []string) int { words := make(map[string]bool) diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 109. \345\274\200\345\257\206\347\240\201\351\224\201/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 109. \345\274\200\345\257\206\347\240\201\351\224\201/README.md" index fbc3a580f7674..906d152fed407 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 109. \345\274\200\345\257\206\347\240\201\351\224\201/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 109. \345\274\200\345\257\206\347\240\201\351\224\201/README.md" @@ -82,6 +82,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def openLock(self, deadends: List[str], target: str) -> int: @@ -123,6 +125,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int openLock(String[] deadends, String target) { @@ -180,6 +184,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 110. \346\211\200\346\234\211\350\267\257\345\276\204/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 110. \346\211\200\346\234\211\350\267\257\345\276\204/README.md" index b0a70178165b8..d836612be9356 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 110. \346\211\200\346\234\211\350\267\257\345\276\204/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 110. \346\211\200\346\234\211\350\267\257\345\276\204/README.md" @@ -83,6 +83,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans; @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func allPathsSourceTarget(graph [][]int) [][]int { var path []int diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 111. \350\256\241\347\256\227\351\231\244\346\263\225/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 111. \350\256\241\347\256\227\351\231\244\346\263\225/README.md" index b8f702e43dcdd..50e3b501799b6 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 111. \350\256\241\347\256\227\351\231\244\346\263\225/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 111. \350\256\241\347\256\227\351\231\244\346\263\225/README.md" @@ -76,6 +76,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def calcEquation( @@ -119,6 +121,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { private int[] p; @@ -177,6 +181,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -226,6 +232,8 @@ public: }; ``` +#### Go + ```go var p []int var w []float64 diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 112. \346\234\200\351\225\277\351\200\222\345\242\236\350\267\257\345\276\204/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 112. \346\234\200\351\225\277\351\200\222\345\242\236\350\267\257\345\276\204/README.md" index 435673cd13f5c..4e8337208369c 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 112. \346\234\200\351\225\277\351\200\222\345\242\236\350\267\257\345\276\204/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 112. \346\234\200\351\225\277\351\200\222\345\242\236\350\267\257\345\276\204/README.md" @@ -68,6 +68,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def longestIncreasingPath(self, matrix: List[List[int]]) -> int: @@ -84,6 +86,8 @@ class Solution: return max(dfs(i, j) for i in range(m) for j in range(n)) ``` +#### Java + ```java class Solution { private int[][] memo; @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func longestIncreasingPath(matrix [][]int) int { m, n := len(matrix), len(matrix[0]) diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 113. \350\257\276\347\250\213\351\241\272\345\272\217/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 113. \350\257\276\347\250\213\351\241\272\345\272\217/README.md" index 13672407bb94a..52e72ae62a670 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 113. \350\257\276\347\250\213\351\241\272\345\272\217/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 113. \350\257\276\347\250\213\351\241\272\345\272\217/README.md" @@ -79,6 +79,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def findOrder(self, numCourses: int, prerequisites: List[List[int]]) -> List[int]: @@ -99,6 +101,8 @@ class Solution: return ans if len(ans) == numCourses else [] ``` +#### Java + ```java class Solution { public int[] findOrder(int numCourses, int[][] prerequisites) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func findOrder(numCourses int, prerequisites [][]int) []int { g := make([][]int, numCourses) @@ -199,6 +207,8 @@ func findOrder(numCourses int, prerequisites [][]int) []int { } ``` +#### TypeScript + ```ts function findOrder(numCourses: number, prerequisites: number[][]): number[] { const g: number[][] = Array.from({ length: numCourses }, () => []); @@ -222,6 +232,8 @@ function findOrder(numCourses: number, prerequisites: number[][]): number[] { } ``` +#### C# + ```cs public class Solution { public int[] FindOrder(int numCourses, int[][] prerequisites) { diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 114. \345\244\226\346\230\237\346\226\207\345\255\227\345\205\270/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 114. \345\244\226\346\230\237\346\226\207\345\255\227\345\205\270/README.md" index af323f954e8af..157afc94e0ee0 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 114. \345\244\226\346\230\237\346\226\207\345\255\227\345\205\270/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 114. \345\244\226\346\230\237\346\226\207\345\255\227\345\205\270/README.md" @@ -89,6 +89,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def alienOrder(self, words: List[str]) -> str: @@ -145,6 +147,8 @@ class Solution: return '' if len(ans) < cnt else ''.join(ans) ``` +#### Java + ```java class Solution { @@ -222,6 +226,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 115. \351\207\215\345\273\272\345\272\217\345\210\227/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 115. \351\207\215\345\273\272\345\272\217\345\210\227/README.md" index 41b9e16f4c1e2..3f1b34527a0af 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 115. \351\207\215\345\273\272\345\272\217\345\210\227/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 115. \351\207\215\345\273\272\345\272\217\345\210\227/README.md" @@ -92,6 +92,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def sequenceReconstruction( @@ -115,6 +117,8 @@ class Solution: return len(q) == 0 ``` +#### Java + ```java class Solution { public boolean sequenceReconstruction(int[] nums, List> sequences) { @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -182,6 +188,8 @@ public: }; ``` +#### Go + ```go func sequenceReconstruction(nums []int, sequences [][]int) bool { n := len(nums) @@ -215,6 +223,8 @@ func sequenceReconstruction(nums []int, sequences [][]int) bool { } ``` +#### TypeScript + ```ts function sequenceReconstruction(nums: number[], sequences: number[][]): boolean { const n = nums.length; diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 116. \346\234\213\345\217\213\345\234\210/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 116. \346\234\213\345\217\213\345\234\210/README.md" index af6e9f665bc9f..cdf70fee2963e 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 116. \346\234\213\345\217\213\345\234\210/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 116. \346\234\213\345\217\213\345\234\210/README.md" @@ -66,6 +66,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def findCircleNum(self, isConnected: List[List[int]]) -> int: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[][] isConnected; @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func findCircleNum(isConnected [][]int) int { n := len(isConnected) @@ -243,6 +251,8 @@ d[find(a)] = distance +#### Python3 + ```python class Solution: def findCircleNum(self, isConnected: List[List[int]]) -> int: @@ -260,6 +270,8 @@ class Solution: return sum(i == v for i, v in enumerate(p)) ``` +#### Java + ```java class Solution { private int[] p; @@ -295,6 +307,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -322,6 +336,8 @@ public: }; ``` +#### Go + ```go func findCircleNum(isConnected [][]int) int { n := len(isConnected) diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 117. \347\233\270\344\274\274\347\232\204\345\255\227\347\254\246\344\270\262/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 117. \347\233\270\344\274\274\347\232\204\345\255\227\347\254\246\344\270\262/README.md" index 7010bb325419c..fb2874e52e8d9 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 117. \347\233\270\344\274\274\347\232\204\345\255\227\347\254\246\344\270\262/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 117. \347\233\270\344\274\274\347\232\204\345\255\227\347\254\246\344\270\262/README.md" @@ -62,6 +62,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def numSimilarGroups(self, strs: List[str]) -> int: @@ -79,6 +81,8 @@ class Solution: return sum(i == find(i) for i in range(n)) ``` +#### Java + ```java class Solution { private int[] p; @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func numSimilarGroups(strs []string) int { n := len(strs) diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 118. \345\244\232\344\275\231\347\232\204\350\276\271/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 118. \345\244\232\344\275\231\347\232\204\350\276\271/README.md" index e036ffeaff735..b9dda603f6065 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 118. \345\244\232\344\275\231\347\232\204\350\276\271/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 118. \345\244\232\344\275\231\347\232\204\350\276\271/README.md" @@ -65,6 +65,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def findRedundantConnection(self, edges: List[List[int]]) -> List[int]: @@ -81,6 +83,8 @@ class Solution: return [] ``` +#### Java + ```java class Solution { private int[] p; @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func findRedundantConnection(edges [][]int) []int { p := make([]int, 1010) diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 119. \346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 119. \346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227/README.md" index b8b61920c8923..c38278c1a11ec 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 119. \346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 119. \346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227/README.md" @@ -68,6 +68,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%2 +#### Python3 + ```python class Solution: def longestConsecutive(self, nums: List[int]) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestConsecutive(int[] nums) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func longestConsecutive(nums []int) int { n := len(nums) @@ -159,6 +167,8 @@ func longestConsecutive(nums []int) int { } ``` +#### TypeScript + ```ts function longestConsecutive(nums: number[]): number { const n = nums.length; @@ -182,6 +192,8 @@ function longestConsecutive(nums: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -223,6 +235,8 @@ var longestConsecutive = function (nums) { +#### Python3 + ```python class Solution: def longestConsecutive(self, nums: List[int]) -> int: @@ -237,6 +251,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestConsecutive(int[] nums) { @@ -259,6 +275,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -279,6 +297,8 @@ public: }; ``` +#### Go + ```go func longestConsecutive(nums []int) (ans int) { s := map[int]bool{} @@ -298,6 +318,8 @@ func longestConsecutive(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function longestConsecutive(nums: number[]): number { const s: Set = new Set(nums); @@ -315,6 +337,8 @@ function longestConsecutive(nums: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git "a/lcp/LCP 01. \347\214\234\346\225\260\345\255\227/README.md" "b/lcp/LCP 01. \347\214\234\346\225\260\345\255\227/README.md" index 814015f188506..27eaab2822b7b 100644 --- "a/lcp/LCP 01. \347\214\234\346\225\260\345\255\227/README.md" +++ "b/lcp/LCP 01. \347\214\234\346\225\260\345\255\227/README.md" @@ -56,12 +56,16 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2001.%20%E7%8C%9C% +#### Python3 + ```python class Solution: def game(self, guess: List[int], answer: List[int]) -> int: return sum(a == b for a, b in zip(guess, answer)) ``` +#### Java + ```java class Solution { public int game(int[] guess, int[] answer) { @@ -76,6 +80,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -89,6 +95,8 @@ public: }; ``` +#### Go + ```go func game(guess []int, answer []int) (ans int) { for i, a := range guess { @@ -100,6 +108,8 @@ func game(guess []int, answer []int) (ans int) { } ``` +#### TypeScript + ```ts function game(guess: number[], answer: number[]): number { let ans = 0; @@ -112,6 +122,8 @@ function game(guess: number[], answer: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} guess @@ -129,6 +141,8 @@ var game = function (guess, answer) { }; ``` +#### C + ```c int game(int* guess, int guessSize, int* answer, int answerSize) { int res = 0; @@ -151,6 +165,8 @@ int game(int* guess, int guessSize, int* answer, int answerSize) { +#### TypeScript + ```ts function game(guess: number[], answer: number[]): number { return guess.reduce((acc, cur, index) => (cur === answer[index] ? acc + 1 : acc), 0); diff --git "a/lcp/LCP 02. \345\210\206\345\274\217\345\214\226\347\256\200/README.md" "b/lcp/LCP 02. \345\210\206\345\274\217\345\214\226\347\256\200/README.md" index 980d6db32921a..f2c5e01372cdd 100644 --- "a/lcp/LCP 02. \345\210\206\345\274\217\345\214\226\347\256\200/README.md" +++ "b/lcp/LCP 02. \345\210\206\345\274\217\345\214\226\347\256\200/README.md" @@ -68,6 +68,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2002.%20%E5%88%86% +#### Python3 + ```python class Solution: def fraction(self, cont: List[int]) -> List[int]: @@ -82,6 +84,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private int[] cont; @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func fraction(cont []int) []int { var dfs func(i int) []int @@ -143,6 +151,8 @@ func fraction(cont []int) []int { } ``` +#### TypeScript + ```ts function fraction(cont: number[]): number[] { const dfs = (i: number): number[] => { @@ -161,6 +171,8 @@ function fraction(cont: number[]): number[] { } ``` +#### JavaScript + ```js /** * @param {number[]} cont diff --git "a/lcp/LCP 03. \346\234\272\345\231\250\344\272\272\345\244\247\345\206\222\351\231\251/README.md" "b/lcp/LCP 03. \346\234\272\345\231\250\344\272\272\345\244\247\345\206\222\351\231\251/README.md" index d65630f8e226a..c086edd1b0eb7 100644 --- "a/lcp/LCP 03. \346\234\272\345\231\250\344\272\272\345\244\247\345\206\222\351\231\251/README.md" +++ "b/lcp/LCP 03. \346\234\272\345\231\250\344\272\272\345\244\247\345\206\222\351\231\251/README.md" @@ -76,6 +76,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2003.%20%E6%9C%BA% +#### Python3 + ```python class Solution: def robot(self, command: str, obstacles: List[List[int]], x: int, y: int) -> bool: @@ -100,6 +102,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean robot(String command, int[][] obstacles, int x, int y) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func robot(command string, obstacles [][]int, x int, y int) bool { type pair struct{ i, j int } @@ -196,6 +204,8 @@ func robot(command string, obstacles [][]int, x int, y int) bool { } ``` +#### TypeScript + ```ts function robot(command: string, obstacles: number[][], x: number, y: number): boolean { const f = (i: number, j: number): number => { diff --git "a/lcp/LCP 05. \345\217\221 LeetCoin/README.md" "b/lcp/LCP 05. \345\217\221 LeetCoin/README.md" index e0b1dc50a34ea..6402769f54b27 100644 --- "a/lcp/LCP 05. \345\217\221 LeetCoin/README.md" +++ "b/lcp/LCP 05. \345\217\221 LeetCoin/README.md" @@ -92,6 +92,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2005.%20%E5%8F%91% +#### Python3 + ```python MOD = int(1e9 + 7) @@ -191,6 +193,8 @@ class Solution: return ans ``` +#### Java + ```java class Node { Node left; @@ -325,6 +329,8 @@ class Solution { } ``` +#### C++ + ```cpp const int MOD = 1e9 + 7; diff --git "a/lcp/LCP 06. \346\213\277\347\241\254\345\270\201/README.md" "b/lcp/LCP 06. \346\213\277\347\241\254\345\270\201/README.md" index 41a12cda92634..dcd19d4422cf1 100644 --- "a/lcp/LCP 06. \346\213\277\347\241\254\345\270\201/README.md" +++ "b/lcp/LCP 06. \346\213\277\347\241\254\345\270\201/README.md" @@ -54,12 +54,16 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2006.%20%E6%8B%BF% +#### Python3 + ```python class Solution: def minCount(self, coins: List[int]) -> int: return sum((x + 1) >> 1 for x in coins) ``` +#### Java + ```java class Solution { public int minCount(int[] coins) { @@ -72,6 +76,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -85,6 +91,8 @@ public: }; ``` +#### Go + ```go func minCount(coins []int) (ans int) { for _, x := range coins { @@ -94,6 +102,8 @@ func minCount(coins []int) (ans int) { } ``` +#### TypeScript + ```ts function minCount(coins: number[]): number { let ans = 0; @@ -104,6 +114,8 @@ function minCount(coins: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_count(coins: Vec) -> i32 { @@ -115,6 +127,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** @@ -131,6 +145,8 @@ class Solution { } ``` +#### C + ```c int minCount(int* coins, int coinsSize) { int ans = 0; diff --git "a/lcp/LCP 07. \344\274\240\351\200\222\344\277\241\346\201\257/README.md" "b/lcp/LCP 07. \344\274\240\351\200\222\344\277\241\346\201\257/README.md" index e461f83cd90ee..1703fe246c239 100644 --- "a/lcp/LCP 07. \344\274\240\351\200\222\344\277\241\346\201\257/README.md" +++ "b/lcp/LCP 07. \344\274\240\351\200\222\344\277\241\346\201\257/README.md" @@ -70,6 +70,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2007.%20%E4%BC%A0% +#### Python3 + ```python class Solution: def numWays(self, n: int, relation: List[List[int]], k: int) -> int: @@ -81,6 +83,8 @@ class Solution: return f[-1][-1] ``` +#### Java + ```java class Solution { public int numWays(int n, int[][] relation, int k) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func numWays(n int, relation [][]int, k int) int { f := make([][]int, k+1) @@ -132,6 +140,8 @@ func numWays(n int, relation [][]int, k int) int { } ``` +#### TypeScript + ```ts function numWays(n: number, relation: number[][], k: number): number { const f: number[][] = Array.from({ length: k + 1 }, () => Array(n).fill(0)); @@ -155,6 +165,8 @@ function numWays(n: number, relation: number[][], k: number): number { +#### Python3 + ```python class Solution: def numWays(self, n: int, relation: List[List[int]], k: int) -> int: @@ -167,6 +179,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int numWays(int n, int[][] relation, int k) { @@ -185,6 +199,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -204,6 +220,8 @@ public: }; ``` +#### Go + ```go func numWays(n int, relation [][]int, k int) int { f := make([]int, n) @@ -220,6 +238,8 @@ func numWays(n int, relation [][]int, k int) int { } ``` +#### TypeScript + ```ts function numWays(n: number, relation: number[][], k: number): number { let f: number[] = new Array(n).fill(0); diff --git "a/lcp/LCP 08. \345\211\247\346\203\205\350\247\246\345\217\221\346\227\266\351\227\264/README.md" "b/lcp/LCP 08. \345\211\247\346\203\205\350\247\246\345\217\221\346\227\266\351\227\264/README.md" index b414704cd393c..7f3a754caf57c 100644 --- "a/lcp/LCP 08. \345\211\247\346\203\205\350\247\246\345\217\221\346\227\266\351\227\264/README.md" +++ "b/lcp/LCP 08. \345\211\247\346\203\205\350\247\246\345\217\221\346\227\266\351\227\264/README.md" @@ -74,6 +74,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2008.%20%E5%89%A7% +#### Python3 + ```python class Solution: def getTriggerTime( @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] getTriggerTime(int[][] increase, int[][] requirements) { diff --git "a/lcp/LCP 09. \346\234\200\345\260\217\350\267\263\350\267\203\346\254\241\346\225\260/README.md" "b/lcp/LCP 09. \346\234\200\345\260\217\350\267\263\350\267\203\346\254\241\346\225\260/README.md" index 5c4fa1e7887bb..570853993406f 100644 --- "a/lcp/LCP 09. \346\234\200\345\260\217\350\267\263\350\267\203\346\254\241\346\225\260/README.md" +++ "b/lcp/LCP 09. \346\234\200\345\260\217\350\267\263\350\267\203\346\254\241\346\225\260/README.md" @@ -42,6 +42,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2009.%20%E6%9C%80% +#### Python3 + ```python class Solution: def minJump(self, jump: List[int]) -> int: @@ -65,6 +67,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minJump(int[] jump) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func minJump(jump []int) int { n := len(jump) diff --git "a/lcp/LCP 10. \344\272\214\345\217\211\346\240\221\344\273\273\345\212\241\350\260\203\345\272\246/README.md" "b/lcp/LCP 10. \344\272\214\345\217\211\346\240\221\344\273\273\345\212\241\350\260\203\345\272\246/README.md" index 7642df32f9101..217b12783b14e 100644 --- "a/lcp/LCP 10. \344\272\214\345\217\211\346\240\221\344\273\273\345\212\241\350\260\203\345\272\246/README.md" +++ "b/lcp/LCP 10. \344\272\214\345\217\211\346\240\221\344\273\273\345\212\241\350\260\203\345\272\246/README.md" @@ -68,6 +68,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2010.%20%E4%BA%8C% +#### Python3 + ```python class Solution: def minimalExecTime(self, root: TreeNode) -> float: @@ -81,6 +83,8 @@ class Solution: return dfs(root)[1] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -164,6 +172,8 @@ func minimalExecTime(root *TreeNode) float64 { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git "a/lcp/LCP 11. \346\234\237\346\234\233\344\270\252\346\225\260\347\273\237\350\256\241/README.md" "b/lcp/LCP 11. \346\234\237\346\234\233\344\270\252\346\225\260\347\273\237\350\256\241/README.md" index 06fcb0bdcd9ea..e9159c998fec7 100644 --- "a/lcp/LCP 11. \346\234\237\346\234\233\344\270\252\346\225\260\347\273\237\350\256\241/README.md" +++ "b/lcp/LCP 11. \346\234\237\346\234\233\344\270\252\346\225\260\347\273\237\350\256\241/README.md" @@ -70,12 +70,16 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2011.%20%E6%9C%9F% +#### Python3 + ```python class Solution: def expectNumber(self, scores: List[int]) -> int: return len(set(scores)) ``` +#### Java + ```java class Solution { public int expectNumber(int[] scores) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -98,6 +104,8 @@ public: }; ``` +#### Go + ```go func expectNumber(scores []int) int { s := map[int]struct{}{} @@ -108,6 +116,8 @@ func expectNumber(scores []int) int { } ``` +#### TypeScript + ```ts function expectNumber(scores: number[]): number { const s: Set = new Set(scores); diff --git "a/lcp/LCP 12. \345\260\217\345\274\240\345\210\267\351\242\230\350\256\241\345\210\222/README.md" "b/lcp/LCP 12. \345\260\217\345\274\240\345\210\267\351\242\230\350\256\241\345\210\222/README.md" index 25a3c4e3b7c9f..42804b7024b0b 100644 --- "a/lcp/LCP 12. \345\260\217\345\274\240\345\210\267\351\242\230\350\256\241\345\210\222/README.md" +++ "b/lcp/LCP 12. \345\260\217\345\274\240\345\210\267\351\242\230\350\256\241\345\210\222/README.md" @@ -67,6 +67,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2012.%20%E5%B0%8F% +#### Python3 + ```python class Solution: def minTime(self, time: List[int], m: int) -> int: @@ -84,6 +86,8 @@ class Solution: return bisect_left(range(sum(time)), True, key=check) ``` +#### Java + ```java class Solution { public int minTime(int[] time, int m) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func minTime(time []int, m int) int { right := 0 @@ -176,6 +184,8 @@ func minTime(time []int, m int) int { } ``` +#### TypeScript + ```ts function minTime(time: number[], m: number): number { let left = 0; diff --git "a/lcp/LCP 17. \351\200\237\347\256\227\346\234\272\345\231\250\344\272\272/README.md" "b/lcp/LCP 17. \351\200\237\347\256\227\346\234\272\345\231\250\344\272\272/README.md" index 5237ead43d7e7..ef691e227f58a 100644 --- "a/lcp/LCP 17. \351\200\237\347\256\227\346\234\272\345\231\250\344\272\272/README.md" +++ "b/lcp/LCP 17. \351\200\237\347\256\227\346\234\272\345\231\250\344\272\272/README.md" @@ -52,6 +52,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2017.%20%E9%80%9F% +#### Python3 + ```python class Solution: def calculate(self, s: str) -> int: @@ -64,6 +66,8 @@ class Solution: return x + y ``` +#### Java + ```java class Solution { public int calculate(String s) { @@ -80,6 +84,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -96,6 +102,8 @@ public: }; ``` +#### Go + ```go func calculate(s string) int { x, y := 1, 0 diff --git "a/lcp/LCP 18. \346\227\251\351\244\220\347\273\204\345\220\210/README.md" "b/lcp/LCP 18. \346\227\251\351\244\220\347\273\204\345\220\210/README.md" index 9858be332e87e..c04eb85dcb523 100644 --- "a/lcp/LCP 18. \346\227\251\351\244\220\347\273\204\345\220\210/README.md" +++ "b/lcp/LCP 18. \346\227\251\351\244\220\347\273\204\345\220\210/README.md" @@ -87,6 +87,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2018.%20%E6%97%A9% +#### Python3 + ```python class Solution: def breakfastNumber(self, staple: List[int], drinks: List[int], x: int) -> int: @@ -106,6 +108,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public int breakfastNumber(int[] staple, int[] drinks, int x) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func breakfastNumber(staple []int, drinks []int, x int) int { res, n := 0, len(drinks) diff --git "a/lcp/LCP 19. \347\247\213\345\217\266\346\224\266\350\227\217\351\233\206/README.md" "b/lcp/LCP 19. \347\247\213\345\217\266\346\224\266\350\227\217\351\233\206/README.md" index 20601fa6621b4..5caceb7fe92ad 100644 --- "a/lcp/LCP 19. \347\247\213\345\217\266\346\224\266\350\227\217\351\233\206/README.md" +++ "b/lcp/LCP 19. \347\247\213\345\217\266\346\224\266\350\227\217\351\233\206/README.md" @@ -73,6 +73,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2019.%20%E7%A7%8B% +#### Python3 + ```python class Solution: def minimumOperations(self, leaves: str) -> int: @@ -91,6 +93,8 @@ class Solution: return f[n - 1][2] ``` +#### Java + ```java class Solution { public int minimumOperations(String leaves) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func minimumOperations(leaves string) int { n := len(leaves) @@ -169,6 +177,8 @@ func minimumOperations(leaves string) int { } ``` +#### TypeScript + ```ts function minimumOperations(leaves: string): number { const n = leaves.length; diff --git "a/lcp/LCP 22. \351\273\221\347\231\275\346\226\271\346\240\274\347\224\273/README.md" "b/lcp/LCP 22. \351\273\221\347\231\275\346\226\271\346\240\274\347\224\273/README.md" index 31bebc35fab79..92ac9d2fb7720 100644 --- "a/lcp/LCP 22. \351\273\221\347\231\275\346\226\271\346\240\274\347\224\273/README.md" +++ "b/lcp/LCP 22. \351\273\221\347\231\275\346\226\271\346\240\274\347\224\273/README.md" @@ -66,6 +66,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2022.%20%E9%BB%91% +#### Python3 + ```python class Solution: def paintingPlan(self, n: int, k: int) -> int: @@ -79,6 +81,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int paintingPlan(int n, int k) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func paintingPlan(n int, k int) (ans int) { if k == n*n { @@ -159,6 +167,8 @@ func paintingPlan(n int, k int) (ans int) { } ``` +#### TypeScript + ```ts function paintingPlan(n: number, k: number): number { if (k === n * n) { diff --git "a/lcp/LCP 24. \346\225\260\345\255\227\346\270\270\346\210\217/README.md" "b/lcp/LCP 24. \346\225\260\345\255\227\346\270\270\346\210\217/README.md" index a33cd2e8a44a2..d6f58bdfd0998 100644 --- "a/lcp/LCP 24. \346\225\260\345\255\227\346\270\270\346\210\217/README.md" +++ "b/lcp/LCP 24. \346\225\260\345\255\227\346\270\270\346\210\217/README.md" @@ -84,6 +84,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2024.%20%E6%95%B0% +#### Python3 + ```python class MedianFinder: def __init__(self): @@ -126,6 +128,8 @@ class Solution: return ans ``` +#### Java + ```java class MedianFinder { private PriorityQueue q1 = new PriorityQueue<>(); @@ -179,6 +183,8 @@ class Solution { } ``` +#### C++ + ```cpp class MedianFinder { public: @@ -237,6 +243,8 @@ public: }; ``` +#### Go + ```go func numsGame(nums []int) []int { n := len(nums) diff --git "a/lcp/LCP 28. \351\207\207\350\264\255\346\226\271\346\241\210/README.md" "b/lcp/LCP 28. \351\207\207\350\264\255\346\226\271\346\241\210/README.md" index 9c2da20c3d949..db74c352935f0 100644 --- "a/lcp/LCP 28. \351\207\207\350\264\255\346\226\271\346\241\210/README.md" +++ "b/lcp/LCP 28. \351\207\207\350\264\255\346\226\271\346\241\210/README.md" @@ -50,6 +50,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2028.%20%E9%87%87% +#### Python3 + ```python class Solution: def purchasePlans(self, nums: List[int], target: int) -> int: @@ -65,6 +67,8 @@ class Solution: return res % 1000000007 ``` +#### Java + ```java class Solution { public int purchasePlans(int[] nums, int target) { @@ -83,6 +87,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -99,6 +105,8 @@ public: }; ``` +#### Go + ```go func purchasePlans(nums []int, target int) int { sort.Ints(nums) diff --git "a/lcp/LCP 30. \351\255\224\345\241\224\346\270\270\346\210\217/README.md" "b/lcp/LCP 30. \351\255\224\345\241\224\346\270\270\346\210\217/README.md" index 1da770f92f58f..7a006c4e338b3 100644 --- "a/lcp/LCP 30. \351\255\224\345\241\224\346\270\270\346\210\217/README.md" +++ "b/lcp/LCP 30. \351\255\224\345\241\224\346\270\270\346\210\217/README.md" @@ -60,6 +60,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2030.%20%E9%AD%94% +#### Python3 + ```python class Solution: def magicTower(self, nums: List[int]) -> int: @@ -78,6 +80,8 @@ class Solution: return -1 if blood <= 0 else ans ``` +#### Java + ```java class Solution { public int magicTower(int[] nums) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func magicTower(nums []int) (ans int) { q := hp{} @@ -160,6 +168,8 @@ func (h *hp) Pop() any { } ``` +#### TypeScript + ```ts function magicTower(nums: number[]): number { const q = new MinPriorityQueue(); diff --git "a/lcp/LCP 33. \350\223\204\346\260\264/README.md" "b/lcp/LCP 33. \350\223\204\346\260\264/README.md" index ed4bae2af19a5..6511af87a08b2 100644 --- "a/lcp/LCP 33. \350\223\204\346\260\264/README.md" +++ "b/lcp/LCP 33. \350\223\204\346\260\264/README.md" @@ -65,6 +65,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2033.%20%E8%93%84% +#### Python3 + ```python class Solution: def storeWater(self, bucket: List[int], vat: List[int]) -> int: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int storeWater(int[] bucket, int[] vat) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func storeWater(bucket []int, vat []int) int { mx := slices.Max(vat) @@ -139,6 +147,8 @@ func storeWater(bucket []int, vat []int) int { } ``` +#### TypeScript + ```ts function storeWater(bucket: number[], vat: number[]): number { const mx = Math.max(...vat); diff --git "a/lcp/LCP 34. \344\272\214\345\217\211\346\240\221\346\237\223\350\211\262/README.md" "b/lcp/LCP 34. \344\272\214\345\217\211\346\240\221\346\237\223\350\211\262/README.md" index 129666862b3c5..a4c75c656f380 100644 --- "a/lcp/LCP 34. \344\272\214\345\217\211\346\240\221\346\237\223\350\211\262/README.md" +++ "b/lcp/LCP 34. \344\272\214\345\217\211\346\240\221\346\237\223\350\211\262/README.md" @@ -57,6 +57,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2034.%20%E4%BA%8C% +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -82,6 +84,8 @@ class Solution: return max(dfs(root)) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -182,6 +190,8 @@ func maxValue(root *TreeNode, k int) int { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git "a/lcp/LCP 39. \346\227\240\344\272\272\346\234\272\346\226\271\351\230\265/README.md" "b/lcp/LCP 39. \346\227\240\344\272\272\346\234\272\346\226\271\351\230\265/README.md" index 8cd1a6a68043a..43091ae8772c9 100644 --- "a/lcp/LCP 39. \346\227\240\344\272\272\346\234\272\346\226\271\351\230\265/README.md" +++ "b/lcp/LCP 39. \346\227\240\344\272\272\346\234\272\346\226\271\351\230\265/README.md" @@ -64,6 +64,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2039.%20%E6%97%A0% +#### Python3 + ```python class Solution: def minimumSwitchingTimes( @@ -79,6 +81,8 @@ class Solution: return sum(abs(x) for x in cnt.values()) // 2 ``` +#### Java + ```java class Solution { public int minimumSwitchingTimes(int[][] source, int[][] target) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func minimumSwitchingTimes(source [][]int, target [][]int) (ans int) { cnt := map[int]int{} @@ -148,6 +156,8 @@ func minimumSwitchingTimes(source [][]int, target [][]int) (ans int) { } ``` +#### TypeScript + ```ts function minimumSwitchingTimes(source: number[][], target: number[][]): number { const cnt: Map = new Map(); diff --git "a/lcp/LCP 40. \345\277\203\347\256\227\346\214\221\346\210\230/README.md" "b/lcp/LCP 40. \345\277\203\347\256\227\346\214\221\346\210\230/README.md" index 5c94f1b540e10..f500b965aeff8 100644 --- "a/lcp/LCP 40. \345\277\203\347\256\227\346\214\221\346\210\230/README.md" +++ "b/lcp/LCP 40. \345\277\203\347\256\227\346\214\221\346\210\230/README.md" @@ -52,6 +52,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2040.%20%E5%BF%83% +#### Python3 + ```python class Solution: def maxmiumScore(self, cards: List[int], cnt: int) -> int: @@ -67,6 +69,8 @@ class Solution: return max(ans - a + c, ans - b + d, 0) ``` +#### Java + ```java class Solution { public int maxmiumScore(int[] cards, int cnt) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func maxmiumScore(cards []int, cnt int) int { ans := 0 diff --git "a/lcp/LCP 41. \351\273\221\347\231\275\347\277\273\350\275\254\346\243\213/README.md" "b/lcp/LCP 41. \351\273\221\347\231\275\347\277\273\350\275\254\346\243\213/README.md" index 1a3e4d672c344..c3e7123e60f62 100644 --- "a/lcp/LCP 41. \351\273\221\347\231\275\347\277\273\350\275\254\346\243\213/README.md" +++ "b/lcp/LCP 41. \351\273\221\347\231\275\347\277\273\350\275\254\346\243\213/README.md" @@ -75,6 +75,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2041.%20%E9%BB%91% +#### Python3 + ```python class Solution: def flipChess(self, chessboard: List[str]) -> int: @@ -105,6 +107,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { private int m; @@ -168,6 +172,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -225,6 +231,8 @@ public: }; ``` +#### Go + ```go func flipChess(chessboard []string) (ans int) { m, n := len(chessboard), len(chessboard[0]) diff --git "a/lcp/LCP 44. \345\274\200\345\271\225\345\274\217\347\204\260\347\201\253/README.md" "b/lcp/LCP 44. \345\274\200\345\271\225\345\274\217\347\204\260\347\201\253/README.md" index 4ee059610e41e..7add041f2ff7d 100644 --- "a/lcp/LCP 44. \345\274\200\345\271\225\345\274\217\347\204\260\347\201\253/README.md" +++ "b/lcp/LCP 44. \345\274\200\345\271\225\345\274\217\347\204\260\347\201\253/README.md" @@ -46,6 +46,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2044.%20%E5%BC%80% +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -67,6 +69,8 @@ class Solution: return len(s) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git "a/lcp/LCP 50. \345\256\235\347\237\263\350\241\245\347\273\231/README.md" "b/lcp/LCP 50. \345\256\235\347\237\263\350\241\245\347\273\231/README.md" index 9b3243e6459c4..9dcc177c97925 100644 --- "a/lcp/LCP 50. \345\256\235\347\237\263\350\241\245\347\273\231/README.md" +++ "b/lcp/LCP 50. \345\256\235\347\237\263\350\241\245\347\273\231/README.md" @@ -75,6 +75,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2050.%20%E5%AE%9D% +#### Python3 + ```python class Solution: def giveGem(self, gem: List[int], operations: List[List[int]]) -> int: @@ -85,6 +87,8 @@ class Solution: return max(gem) - min(gem) ``` +#### Java + ```java class Solution { public int giveGem(int[] gem, int[][] operations) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func giveGem(gem []int, operations [][]int) int { for _, op := range operations { @@ -133,6 +141,8 @@ func giveGem(gem []int, operations [][]int) int { } ``` +#### TypeScript + ```ts function giveGem(gem: number[], operations: number[][]): number { for (const [x, y] of operations) { diff --git "a/lcp/LCP 51. \347\203\271\351\245\252\346\226\231\347\220\206/README.md" "b/lcp/LCP 51. \347\203\271\351\245\252\346\226\231\347\220\206/README.md" index a7cedd8a0efce..747f8cd273976 100644 --- "a/lcp/LCP 51. \347\203\271\351\245\252\346\226\231\347\220\206/README.md" +++ "b/lcp/LCP 51. \347\203\271\351\245\252\346\226\231\347\220\206/README.md" @@ -71,6 +71,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2051.%20%E7%83%B9% +#### Python3 + ```python class Solution: def perfectMenu( @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int perfectMenu(int[] materials, int[][] cookbooks, int[][] attribute, int limit) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func perfectMenu(materials []int, cookbooks [][]int, attribute [][]int, limit int) int { n := len(cookbooks) @@ -191,6 +199,8 @@ func perfectMenu(materials []int, cookbooks [][]int, attribute [][]int, limit in } ``` +#### TypeScript + ```ts function perfectMenu( materials: number[], diff --git "a/lcp/LCP 52. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\346\237\223\350\211\262/README.md" "b/lcp/LCP 52. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\346\237\223\350\211\262/README.md" index fccdb9c756977..0acdbbff7b8c7 100644 --- "a/lcp/LCP 52. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\346\237\223\350\211\262/README.md" +++ "b/lcp/LCP 52. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\346\237\223\350\211\262/README.md" @@ -79,6 +79,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2052.%20%E4%BA%8C% +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -110,6 +112,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -222,6 +230,8 @@ func getNumber(root *TreeNode, ops [][]int) (ans int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git "a/lcp/LCP 55. \351\207\207\351\233\206\346\236\234\345\256\236/README.md" "b/lcp/LCP 55. \351\207\207\351\233\206\346\236\234\345\256\236/README.md" index 5cd1feec3ba86..27f4631c9505d 100644 --- "a/lcp/LCP 55. \351\207\207\351\233\206\346\236\234\345\256\236/README.md" +++ "b/lcp/LCP 55. \351\207\207\351\233\206\346\236\234\345\256\236/README.md" @@ -72,6 +72,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2055.%20%E9%87%87% +#### Python3 + ```python class Solution: def getMinimumTime( @@ -80,6 +82,8 @@ class Solution: return sum((num + limit - 1) // limit * time[i] for i, num in fruits) ``` +#### Java + ```java class Solution { public int getMinimumTime(int[] time, int[][] fruits, int limit) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func getMinimumTime(time []int, fruits [][]int, limit int) (ans int) { for _, f := range fruits { @@ -117,6 +125,8 @@ func getMinimumTime(time []int, fruits [][]int, limit int) (ans int) { } ``` +#### TypeScript + ```ts function getMinimumTime(time: number[], fruits: number[][], limit: number): number { let ans = 0; diff --git "a/lcp/LCP 56. \344\277\241\347\211\251\344\274\240\351\200\201/README.md" "b/lcp/LCP 56. \344\277\241\347\211\251\344\274\240\351\200\201/README.md" index 38afefc80f200..b66d379ba9b7d 100644 --- "a/lcp/LCP 56. \344\277\241\347\211\251\344\274\240\351\200\201/README.md" +++ "b/lcp/LCP 56. \344\277\241\347\211\251\344\274\240\351\200\201/README.md" @@ -75,6 +75,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2056.%20%E4%BF%A1% +#### Python3 + ```python class Solution: def conveyorBelt(self, matrix: List[str], start: List[int], end: List[int]) -> int: @@ -100,6 +102,8 @@ class Solution: q.append((x, y)) ``` +#### Java + ```java class Solution { public int conveyorBelt(String[] matrix, int[] start, int[] end) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -179,6 +185,8 @@ public: }; ``` +#### Go + ```go func conveyorBelt(matrix []string, start []int, end []int) int { dirs := [5]int{-1, 0, 1, 0, -1} @@ -224,6 +232,8 @@ func conveyorBelt(matrix []string, start []int, end []int) int { } ``` +#### TypeScript + ```ts function conveyorBelt(matrix: string[], start: number[], end: number[]): number { const dirs = [-1, 0, 1, 0, -1]; diff --git "a/lcp/LCP 61. \346\260\224\346\270\251\345\217\230\345\214\226\350\266\213\345\212\277/README.md" "b/lcp/LCP 61. \346\260\224\346\270\251\345\217\230\345\214\226\350\266\213\345\212\277/README.md" index 3054a56cbc43c..7c60811922218 100644 --- "a/lcp/LCP 61. \346\260\224\346\270\251\345\217\230\345\214\226\350\266\213\345\212\277/README.md" +++ "b/lcp/LCP 61. \346\260\224\346\270\251\345\217\230\345\214\226\350\266\213\345\212\277/README.md" @@ -62,6 +62,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2061.%20%E6%B0%94% +#### Python3 + ```python class Solution: def temperatureTrend(self, temperatureA: List[int], temperatureB: List[int]) -> int: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int temperatureTrend(int[] temperatureA, int[] temperatureB) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func temperatureTrend(temperatureA []int, temperatureB []int) int { ans, f := 0, 0 diff --git "a/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/README.md" "b/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/README.md" index d27c9d1c12d00..348f106b5e995 100644 --- "a/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/README.md" +++ "b/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/README.md" @@ -68,6 +68,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2062.%20%E4%BA%A4% +#### Python3 + ```python class Solution: def transportationHub(self, path: List[List[int]]) -> int: @@ -89,6 +91,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int transportationHub(int[][] path) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func transportationHub(path [][]int) int { ind := [1001]int{} @@ -170,6 +178,8 @@ func transportationHub(path [][]int) int { } ``` +#### TypeScript + ```ts function transportationHub(path: number[][]): number { const ind: number[] = new Array(1001).fill(0); diff --git "a/lcp/LCP 63. \345\274\271\347\217\240\346\270\270\346\210\217/README.md" "b/lcp/LCP 63. \345\274\271\347\217\240\346\270\270\346\210\217/README.md" index 884cabf138037..2d2823b8085a5 100644 --- "a/lcp/LCP 63. \345\274\271\347\217\240\346\270\270\346\210\217/README.md" +++ "b/lcp/LCP 63. \345\274\271\347\217\240\346\270\270\346\210\217/README.md" @@ -84,6 +84,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2063.%20%E5%BC%B9% +#### Python3 + ```python class Solution: def ballGame(self, num: int, plate: List[str]) -> List[List[int]]: @@ -118,6 +120,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private String[] plate; @@ -174,6 +178,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -222,6 +228,8 @@ public: }; ``` +#### Go + ```go func ballGame(num int, plate []string) (ans [][]int) { dirs := [5]int{0, 1, 0, -1, 0} diff --git "a/lcp/LCP 64. \344\272\214\345\217\211\346\240\221\347\201\257\351\245\260/README.md" "b/lcp/LCP 64. \344\272\214\345\217\211\346\240\221\347\201\257\351\245\260/README.md" index ea1d4c7f6c8d8..248022131b176 100644 --- "a/lcp/LCP 64. \344\272\214\345\217\211\346\240\221\347\201\257\351\245\260/README.md" +++ "b/lcp/LCP 64. \344\272\214\345\217\211\346\240\221\347\201\257\351\245\260/README.md" @@ -94,6 +94,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2064.%20%E4%BA%8C% +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -124,6 +126,8 @@ class Solution: return dfs(root)[0] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -172,6 +176,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -213,6 +219,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git "a/lcp/LCP 66. \346\234\200\345\260\217\345\261\225\345\217\260\346\225\260\351\207\217/README.md" "b/lcp/LCP 66. \346\234\200\345\260\217\345\261\225\345\217\260\346\225\260\351\207\217/README.md" index be3884725d96d..b61565afd4889 100644 --- "a/lcp/LCP 66. \346\234\200\345\260\217\345\261\225\345\217\260\346\225\260\351\207\217/README.md" +++ "b/lcp/LCP 66. \346\234\200\345\260\217\345\261\225\345\217\260\346\225\260\351\207\217/README.md" @@ -61,6 +61,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2066.%20%E6%9C%80% +#### Python3 + ```python class Solution: def minNumBooths(self, demand: List[str]) -> int: @@ -77,6 +79,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minNumBooths(String[] demand) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func minNumBooths(demand []string) (ans int) { cnt := [26]int{} diff --git "a/lcp/LCP 67. \350\243\205\351\245\260\346\240\221/README.md" "b/lcp/LCP 67. \350\243\205\351\245\260\346\240\221/README.md" index e07acb1dac4b6..e4d4babb6c862 100644 --- "a/lcp/LCP 67. \350\243\205\351\245\260\346\240\221/README.md" +++ "b/lcp/LCP 67. \350\243\205\351\245\260\346\240\221/README.md" @@ -67,6 +67,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2067.%20%E8%A3%85% +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -89,6 +91,8 @@ class Solution: return dfs(root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git "a/lcp/LCP 68. \347\276\216\350\247\202\347\232\204\350\212\261\346\235\237/README.md" "b/lcp/LCP 68. \347\276\216\350\247\202\347\232\204\350\212\261\346\235\237/README.md" index 732699c5fe43a..dca809e537dc9 100644 --- "a/lcp/LCP 68. \347\276\216\350\247\202\347\232\204\350\212\261\346\235\237/README.md" +++ "b/lcp/LCP 68. \347\276\216\350\247\202\347\232\204\350\212\261\346\235\237/README.md" @@ -66,6 +66,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2068.%20%E7%BE%8E% +#### Python3 + ```python class Solution: def beautifulBouquet(self, flowers: List[int], cnt: int) -> int: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int beautifulBouquet(int[] flowers, int cnt) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func beautifulBouquet(flowers []int, cnt int) (ans int) { mx := slices.Max(flowers) diff --git "a/lcp/LCP 70. \346\262\231\345\234\260\346\262\273\347\220\206/README.md" "b/lcp/LCP 70. \346\262\231\345\234\260\346\262\273\347\220\206/README.md" index 60d238af3f6d3..92170db889c44 100644 --- "a/lcp/LCP 70. \346\262\231\345\234\260\346\262\273\347\220\206/README.md" +++ "b/lcp/LCP 70. \346\262\231\345\234\260\346\262\273\347\220\206/README.md" @@ -73,6 +73,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2070.%20%E6%B2%99% +#### Python3 + ```python class Solution: def sandyLandManagement(self, size: int) -> List[List[int]]: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] sandyLandManagement(int size) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func sandyLandManagement(size int) (ans [][]int) { ans = append(ans, []int{1, 1}) diff --git "a/lcp/LCP 72. \350\241\245\347\273\231\351\251\254\350\275\246/README.md" "b/lcp/LCP 72. \350\241\245\347\273\231\351\251\254\350\275\246/README.md" index dbb06a0d78bcf..0ed36ba14ccb1 100644 --- "a/lcp/LCP 72. \350\241\245\347\273\231\351\251\254\350\275\246/README.md" +++ "b/lcp/LCP 72. \350\241\245\347\273\231\351\251\254\350\275\246/README.md" @@ -57,6 +57,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2072.%20%E8%A1%A5% +#### Python3 + ```python class Solution: def supplyWagon(self, supplies: List[int]) -> List[int]: @@ -82,6 +84,8 @@ class Solution: return supplies ``` +#### Java + ```java class Solution { public int[] supplyWagon(int[] supplies) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func supplyWagon(supplies []int) []int { for h := (len(supplies) + 1) >> 1; h > 0; h-- { @@ -171,6 +179,8 @@ func supplyWagon(supplies []int) []int { } ``` +#### TypeScript + ```ts function supplyWagon(supplies: number[]): number[] { for (let h = (supplies.length + 1) >> 1; h > 0; --h) { diff --git "a/lcp/LCP 77. \347\254\246\346\226\207\345\202\250\345\244\207/README.md" "b/lcp/LCP 77. \347\254\246\346\226\207\345\202\250\345\244\207/README.md" index d2d0c3712db00..e22025fa62b21 100644 --- "a/lcp/LCP 77. \347\254\246\346\226\207\345\202\250\345\244\207/README.md" +++ "b/lcp/LCP 77. \347\254\246\346\226\207\345\202\250\345\244\207/README.md" @@ -56,6 +56,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2077.%20%E7%AC%A6% +#### Python3 + ```python class Solution: def runeReserve(self, runes: List[int]) -> int: @@ -69,6 +71,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int runeReserve(int[] runes) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -104,6 +110,8 @@ public: }; ``` +#### Go + ```go func runeReserve(runes []int) (ans int) { sort.Ints(runes) @@ -119,6 +127,8 @@ func runeReserve(runes []int) (ans int) { } ``` +#### TypeScript + ```ts function runeReserve(runes: number[]): number { runes.sort((a, b) => a - b); diff --git "a/lcp/LCP 78. \345\237\216\345\242\231\351\230\262\347\272\277/README.md" "b/lcp/LCP 78. \345\237\216\345\242\231\351\230\262\347\272\277/README.md" index 517002f0811e7..7762f747189e8 100644 --- "a/lcp/LCP 78. \345\237\216\345\242\231\351\230\262\347\272\277/README.md" +++ "b/lcp/LCP 78. \345\237\216\345\242\231\351\230\262\347\272\277/README.md" @@ -70,6 +70,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2078.%20%E5%9F%8E% +#### Python3 + ```python class Solution: def rampartDefensiveLine(self, rampart: List[List[int]]) -> int: @@ -94,6 +96,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { private int[][] rampart; @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func rampartDefensiveLine(rampart [][]int) int { check := func(w int) bool { @@ -189,6 +197,8 @@ func rampartDefensiveLine(rampart [][]int) int { } ``` +#### TypeScript + ```ts function rampartDefensiveLine(rampart: number[][]): number { const check = (w: number): boolean => { diff --git "a/lcp/LCP 79. \346\217\220\345\217\226\345\222\222\346\226\207/README.md" "b/lcp/LCP 79. \346\217\220\345\217\226\345\222\222\346\226\207/README.md" index 17154e53b260b..3b4f2c3f17dec 100644 --- "a/lcp/LCP 79. \346\217\220\345\217\226\345\222\222\346\226\207/README.md" +++ "b/lcp/LCP 79. \346\217\220\345\217\226\345\222\222\346\226\207/README.md" @@ -58,6 +58,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcp/LCP%2079.%20%E6%8F%90% +#### Python3 + ```python class Solution: def extractMantra(self, matrix: List[str], mantra: str) -> int: @@ -88,6 +90,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int extractMantra(String[] matrix, String mantra) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func extractMantra(matrix []string, mantra string) (ans int) { m, n, l := len(matrix), len(matrix[0]), len(mantra) @@ -202,6 +210,8 @@ func extractMantra(matrix []string, mantra string) (ans int) { } ``` +#### TypeScript + ```ts function extractMantra(matrix: string[], mantra: string): number { const [m, n, l] = [matrix.length, matrix[0].length, mantra.length]; diff --git "a/lcs/LCS 01. \344\270\213\350\275\275\346\217\222\344\273\266/README.md" "b/lcs/LCS 01. \344\270\213\350\275\275\346\217\222\344\273\266/README.md" index 3fee2dfc22a77..9354097174cd6 100644 --- "a/lcs/LCS 01. \344\270\213\350\275\275\346\217\222\344\273\266/README.md" +++ "b/lcs/LCS 01. \344\270\213\350\275\275\346\217\222\344\273\266/README.md" @@ -62,6 +62,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcs/LCS%2001.%20%E4%B8%8B% +#### Python3 + ```python class Solution: def leastMinutes(self, n: int) -> int: @@ -72,6 +74,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int leastMinutes(int n) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -97,6 +103,8 @@ public: }; ``` +#### Go + ```go func leastMinutes(n int) int { ans := 1 @@ -107,6 +115,8 @@ func leastMinutes(n int) int { } ``` +#### TypeScript + ```ts function leastMinutes(n: number): number { let ans = 1; @@ -117,6 +127,8 @@ function leastMinutes(n: number): number { } ``` +#### JavaScript + ```js /** * @param {number} n diff --git "a/lcs/LCS 02. \345\256\214\346\210\220\344\270\200\345\215\212\351\242\230\347\233\256/README.md" "b/lcs/LCS 02. \345\256\214\346\210\220\344\270\200\345\215\212\351\242\230\347\233\256/README.md" index 4c46c08fa23b5..2fd21571d52f7 100644 --- "a/lcs/LCS 02. \345\256\214\346\210\220\344\270\200\345\215\212\351\242\230\347\233\256/README.md" +++ "b/lcs/LCS 02. \345\256\214\346\210\220\344\270\200\345\215\212\351\242\230\347\233\256/README.md" @@ -53,6 +53,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcs/LCS%2002.%20%E5%AE%8C% +#### Python3 + ```python class Solution: def halfQuestions(self, questions: List[int]) -> int: @@ -66,6 +68,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int halfQuestions(int[] questions) { @@ -85,6 +89,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -104,6 +110,8 @@ public: }; ``` +#### Go + ```go func halfQuestions(questions []int) (ans int) { cnt := make([]int, 1010) @@ -120,6 +128,8 @@ func halfQuestions(questions []int) (ans int) { } ``` +#### TypeScript + ```ts function halfQuestions(questions: number[]): number { const cnt = new Array(1010).fill(0); @@ -137,6 +147,8 @@ function halfQuestions(questions: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} questions diff --git "a/lcs/LCS 03. \344\270\273\351\242\230\347\251\272\351\227\264/README.md" "b/lcs/LCS 03. \344\270\273\351\242\230\347\251\272\351\227\264/README.md" index f1b102725df02..f97ab38ba88c6 100644 --- "a/lcs/LCS 03. \344\270\273\351\242\230\347\251\272\351\227\264/README.md" +++ "b/lcs/LCS 03. \344\270\273\351\242\230\347\251\272\351\227\264/README.md" @@ -49,6 +49,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcs/LCS%2003.%20%E4%B8%BB% +#### Python3 + ```python class Solution: def largestArea(self, grid: List[str]) -> int: @@ -84,6 +86,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { private int[] p; @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go func largestArea(grid []string) int { m, n := len(grid), len(grid[0]) @@ -221,6 +229,8 @@ func largestArea(grid []string) int { } ``` +#### JavaScript + ```js /** * @param {string[]} grid diff --git a/solution/0000-0099/0001.Two Sum/README.md b/solution/0000-0099/0001.Two Sum/README.md index c32137478b0ab..41f53671375c1 100644 --- a/solution/0000-0099/0001.Two Sum/README.md +++ b/solution/0000-0099/0001.Two Sum/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: @@ -89,6 +91,8 @@ class Solution: m[x] = i ``` +#### Java + ```java class Solution { public int[] twoSum(int[] nums, int target) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func twoSum(nums []int, target int) []int { m := map[int]int{} @@ -136,6 +144,8 @@ func twoSum(nums []int, target int) []int { } ``` +#### TypeScript + ```ts function twoSum(nums: number[], target: number): number[] { const m: Map = new Map(); @@ -153,6 +163,8 @@ function twoSum(nums: number[], target: number): number[] { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -171,6 +183,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -190,6 +204,8 @@ var twoSum = function (nums, target) { }; ``` +#### C# + ```cs public class Solution { public int[] TwoSum(int[] nums, int target) { @@ -208,6 +224,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** @@ -228,6 +246,8 @@ class Solution { } ``` +#### Scala + ```scala import scala.collection.mutable @@ -246,6 +266,8 @@ object Solution { } ``` +#### Swift + ```swift class Solution { func twoSum(_ nums: [Int], _ target: Int) -> [Int] { @@ -264,6 +286,8 @@ class Solution { } ``` +#### Ruby + ```rb # @param {Integer[]} nums # @param {Integer} target @@ -278,6 +302,8 @@ def two_sum(nums, target) end ``` +#### Nim + ```nim import std/enumerate diff --git a/solution/0000-0099/0001.Two Sum/README_EN.md b/solution/0000-0099/0001.Two Sum/README_EN.md index e54a44270f952..798d0152d3b24 100644 --- a/solution/0000-0099/0001.Two Sum/README_EN.md +++ b/solution/0000-0099/0001.Two Sum/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(n)$ and the space complexity is $O(n)$. Where $n$ is t +#### Python3 + ```python class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: @@ -86,6 +88,8 @@ class Solution: m[x] = i ``` +#### Java + ```java class Solution { public int[] twoSum(int[] nums, int target) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func twoSum(nums []int, target int) []int { m := map[int]int{} @@ -133,6 +141,8 @@ func twoSum(nums []int, target int) []int { } ``` +#### TypeScript + ```ts function twoSum(nums: number[], target: number): number[] { const m: Map = new Map(); @@ -150,6 +160,8 @@ function twoSum(nums: number[], target: number): number[] { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -168,6 +180,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -187,6 +201,8 @@ var twoSum = function (nums, target) { }; ``` +#### C# + ```cs public class Solution { public int[] TwoSum(int[] nums, int target) { @@ -205,6 +221,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** @@ -225,6 +243,8 @@ class Solution { } ``` +#### Scala + ```scala import scala.collection.mutable @@ -243,6 +263,8 @@ object Solution { } ``` +#### Swift + ```swift class Solution { func twoSum(_ nums: [Int], _ target: Int) -> [Int] { @@ -261,6 +283,8 @@ class Solution { } ``` +#### Ruby + ```rb # @param {Integer[]} nums # @param {Integer} target @@ -275,6 +299,8 @@ def two_sum(nums, target) end ``` +#### Nim + ```nim import std/enumerate diff --git a/solution/0000-0099/0002.Add Two Numbers/README.md b/solution/0000-0099/0002.Add Two Numbers/README.md index 2fb63fd9a8121..dc7cbcc5b8fc1 100644 --- a/solution/0000-0099/0002.Add Two Numbers/README.md +++ b/solution/0000-0099/0002.Add Two Numbers/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -98,6 +100,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -191,6 +199,8 @@ func addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -225,6 +235,8 @@ function addTwoNumbers(l1: ListNode | null, l2: ListNode | null): ListNode | nul } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -268,6 +280,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -297,6 +311,8 @@ var addTwoNumbers = function (l1, l2) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. @@ -327,6 +343,8 @@ public class Solution { } ``` +#### PHP + ```php /** * Definition for a singly-linked list. @@ -377,6 +395,8 @@ class Solution { } ``` +#### Swift + ```swift /** * Definition for singly-linked list. @@ -408,6 +428,8 @@ class Solution { } ``` +#### Ruby + ```rb # Definition for singly-linked list. # class ListNode @@ -436,6 +458,8 @@ def add_two_numbers(l1, l2) end ``` +#### Nim + ```nim #[ # Driver code in the solution file diff --git a/solution/0000-0099/0002.Add Two Numbers/README_EN.md b/solution/0000-0099/0002.Add Two Numbers/README_EN.md index 75cc889ad3e23..0692de009adbe 100644 --- a/solution/0000-0099/0002.Add Two Numbers/README_EN.md +++ b/solution/0000-0099/0002.Add Two Numbers/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(\max (m, n))$, where $m$ and $n$ are the lengths of th +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -94,6 +96,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -187,6 +195,8 @@ func addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -221,6 +231,8 @@ function addTwoNumbers(l1: ListNode | null, l2: ListNode | null): ListNode | nul } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -264,6 +276,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -293,6 +307,8 @@ var addTwoNumbers = function (l1, l2) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. @@ -323,6 +339,8 @@ public class Solution { } ``` +#### PHP + ```php /** * Definition for a singly-linked list. @@ -373,6 +391,8 @@ class Solution { } ``` +#### Swift + ```swift /** * Definition for singly-linked list. @@ -404,6 +424,8 @@ class Solution { } ``` +#### Ruby + ```rb # Definition for singly-linked list. # class ListNode @@ -432,6 +454,8 @@ def add_two_numbers(l1, l2) end ``` +#### Nim + ```nim #[ # Driver code in the solution file diff --git a/solution/0000-0099/0003.Longest Substring Without Repeating Characters/README.md b/solution/0000-0099/0003.Longest Substring Without Repeating Characters/README.md index ecebe4c2c2b10..3ccff6d099d5b 100644 --- a/solution/0000-0099/0003.Longest Substring Without Repeating Characters/README.md +++ b/solution/0000-0099/0003.Longest Substring Without Repeating Characters/README.md @@ -85,6 +85,8 @@ for (int i = 0, j = 0; i < n; ++i) { +#### Python3 + ```python class Solution: def lengthOfLongestSubstring(self, s: str) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int lengthOfLongestSubstring(String s) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func lengthOfLongestSubstring(s string) (ans int) { ss := [128]bool{} @@ -150,6 +158,8 @@ func lengthOfLongestSubstring(s string) (ans int) { } ``` +#### TypeScript + ```ts function lengthOfLongestSubstring(s: string): number { let ans = 0; @@ -165,6 +175,8 @@ function lengthOfLongestSubstring(s: string): number { } ``` +#### Rust + ```rust use std::collections::HashSet; @@ -189,6 +201,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -208,6 +222,8 @@ var lengthOfLongestSubstring = function (s) { }; ``` +#### C# + ```cs public class Solution { public int LengthOfLongestSubstring(string s) { @@ -225,6 +241,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** @@ -246,6 +264,8 @@ class Solution { } ``` +#### Swift + ```swift class Solution { func lengthOfLongestSubstring(_ s: String) -> Int { @@ -268,6 +288,8 @@ class Solution { } ``` +#### Nim + ```nim proc lengthOfLongestSubstring(s: string): int = var diff --git a/solution/0000-0099/0003.Longest Substring Without Repeating Characters/README_EN.md b/solution/0000-0099/0003.Longest Substring Without Repeating Characters/README_EN.md index f4bd7fb479124..699444fecaaf9 100644 --- a/solution/0000-0099/0003.Longest Substring Without Repeating Characters/README_EN.md +++ b/solution/0000-0099/0003.Longest Substring Without Repeating Characters/README_EN.md @@ -83,6 +83,8 @@ for (int i = 0, j = 0; i < n; ++i) { +#### Python3 + ```python class Solution: def lengthOfLongestSubstring(self, s: str) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int lengthOfLongestSubstring(String s) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func lengthOfLongestSubstring(s string) (ans int) { ss := [128]bool{} @@ -148,6 +156,8 @@ func lengthOfLongestSubstring(s string) (ans int) { } ``` +#### TypeScript + ```ts function lengthOfLongestSubstring(s: string): number { let ans = 0; @@ -163,6 +173,8 @@ function lengthOfLongestSubstring(s: string): number { } ``` +#### Rust + ```rust use std::collections::HashSet; @@ -187,6 +199,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -206,6 +220,8 @@ var lengthOfLongestSubstring = function (s) { }; ``` +#### C# + ```cs public class Solution { public int LengthOfLongestSubstring(string s) { @@ -223,6 +239,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** @@ -244,6 +262,8 @@ class Solution { } ``` +#### Swift + ```swift class Solution { func lengthOfLongestSubstring(_ s: String) -> Int { @@ -266,6 +286,8 @@ class Solution { } ``` +#### Nim + ```nim proc lengthOfLongestSubstring(s: string): int = var diff --git a/solution/0000-0099/0004.Median of Two Sorted Arrays/README.md b/solution/0000-0099/0004.Median of Two Sorted Arrays/README.md index f4e4124458454..a0c5af52f0caa 100644 --- a/solution/0000-0099/0004.Median of Two Sorted Arrays/README.md +++ b/solution/0000-0099/0004.Median of Two Sorted Arrays/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float: @@ -103,6 +105,8 @@ class Solution: return (a + b) / 2 ``` +#### Java + ```java class Solution { private int m; @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func findMedianSortedArrays(nums1 []int, nums2 []int) float64 { m, n := len(nums1), len(nums2) @@ -197,6 +205,8 @@ func findMedianSortedArrays(nums1 []int, nums2 []int) float64 { } ``` +#### TypeScript + ```ts function findMedianSortedArrays(nums1: number[], nums2: number[]): number { const m = nums1.length; @@ -222,6 +232,8 @@ function findMedianSortedArrays(nums1: number[], nums2: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums1 @@ -252,6 +264,8 @@ var findMedianSortedArrays = function (nums1, nums2) { }; ``` +#### C# + ```cs public class Solution { private int m; @@ -287,6 +301,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** @@ -309,6 +325,8 @@ class Solution { } ``` +#### Nim + ```nim import std/[algorithm, sequtils] diff --git a/solution/0000-0099/0004.Median of Two Sorted Arrays/README_EN.md b/solution/0000-0099/0004.Median of Two Sorted Arrays/README_EN.md index a5091223f0bb5..15b73ee6ff6f0 100644 --- a/solution/0000-0099/0004.Median of Two Sorted Arrays/README_EN.md +++ b/solution/0000-0099/0004.Median of Two Sorted Arrays/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(\log(m + n))$, and the space complexity is $O(\log(m + +#### Python3 + ```python class Solution: def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float: @@ -99,6 +101,8 @@ class Solution: return (a + b) / 2 ``` +#### Java + ```java class Solution { private int m; @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func findMedianSortedArrays(nums1 []int, nums2 []int) float64 { m, n := len(nums1), len(nums2) @@ -193,6 +201,8 @@ func findMedianSortedArrays(nums1 []int, nums2 []int) float64 { } ``` +#### TypeScript + ```ts function findMedianSortedArrays(nums1: number[], nums2: number[]): number { const m = nums1.length; @@ -218,6 +228,8 @@ function findMedianSortedArrays(nums1: number[], nums2: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums1 @@ -248,6 +260,8 @@ var findMedianSortedArrays = function (nums1, nums2) { }; ``` +#### C# + ```cs public class Solution { private int m; @@ -283,6 +297,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** @@ -305,6 +321,8 @@ class Solution { } ``` +#### Nim + ```nim import std/[algorithm, sequtils] diff --git a/solution/0000-0099/0005.Longest Palindromic Substring/README.md b/solution/0000-0099/0005.Longest Palindromic Substring/README.md index 277c8e44a5e91..f3bec1c5b0771 100644 --- a/solution/0000-0099/0005.Longest Palindromic Substring/README.md +++ b/solution/0000-0099/0005.Longest Palindromic Substring/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def longestPalindrome(self, s: str) -> str: @@ -84,6 +86,8 @@ class Solution: return s[k : k + mx] ``` +#### Java + ```java class Solution { public String longestPalindrome(String s) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func longestPalindrome(s string) string { n := len(s) @@ -161,6 +169,8 @@ func longestPalindrome(s string) string { } ``` +#### TypeScript + ```ts function longestPalindrome(s: string): string { const n = s.length; @@ -185,6 +195,8 @@ function longestPalindrome(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn longest_palindrome(s: String) -> String { @@ -207,6 +219,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -235,6 +249,8 @@ var longestPalindrome = function (s) { }; ``` +#### C# + ```cs public class Solution { public string LongestPalindrome(string s) { @@ -263,6 +279,8 @@ public class Solution { } ``` +#### Nim + ```nim import std/sequtils @@ -301,6 +319,8 @@ proc longestPalindrome(s: string): string = +#### Python3 + ```python class Solution: def longestPalindrome(self, s: str) -> str: @@ -321,6 +341,8 @@ class Solution: return s[start : start + mx] ``` +#### Java + ```java class Solution { private String s; @@ -352,6 +374,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -378,6 +402,8 @@ public: }; ``` +#### Go + ```go func longestPalindrome(s string) string { n := len(s) @@ -400,6 +426,8 @@ func longestPalindrome(s string) string { } ``` +#### Rust + ```rust impl Solution { pub fn is_palindrome(s: &str) -> bool { @@ -430,6 +458,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0005.Longest Palindromic Substring/README_EN.md b/solution/0000-0099/0005.Longest Palindromic Substring/README_EN.md index 900d5933b32ed..895bbb34ed3ff 100644 --- a/solution/0000-0099/0005.Longest Palindromic Substring/README_EN.md +++ b/solution/0000-0099/0005.Longest Palindromic Substring/README_EN.md @@ -64,6 +64,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$. Here, $n$ +#### Python3 + ```python class Solution: def longestPalindrome(self, s: str) -> str: @@ -80,6 +82,8 @@ class Solution: return s[k : k + mx] ``` +#### Java + ```java class Solution { public String longestPalindrome(String s) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func longestPalindrome(s string) string { n := len(s) @@ -157,6 +165,8 @@ func longestPalindrome(s string) string { } ``` +#### TypeScript + ```ts function longestPalindrome(s: string): string { const n = s.length; @@ -181,6 +191,8 @@ function longestPalindrome(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn longest_palindrome(s: String) -> String { @@ -203,6 +215,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -231,6 +245,8 @@ var longestPalindrome = function (s) { }; ``` +#### C# + ```cs public class Solution { public string LongestPalindrome(string s) { @@ -259,6 +275,8 @@ public class Solution { } ``` +#### Nim + ```nim import std/sequtils @@ -297,6 +315,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(1)$. Here, $n$ i +#### Python3 + ```python class Solution: def longestPalindrome(self, s: str) -> str: @@ -317,6 +337,8 @@ class Solution: return s[start : start + mx] ``` +#### Java + ```java class Solution { private String s; @@ -348,6 +370,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -374,6 +398,8 @@ public: }; ``` +#### Go + ```go func longestPalindrome(s string) string { n := len(s) @@ -396,6 +422,8 @@ func longestPalindrome(s string) string { } ``` +#### Rust + ```rust impl Solution { pub fn is_palindrome(s: &str) -> bool { @@ -426,6 +454,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0006.Zigzag Conversion/README.md b/solution/0000-0099/0006.Zigzag Conversion/README.md index 2c791a6a52c7f..c12bad03a22aa 100644 --- a/solution/0000-0099/0006.Zigzag Conversion/README.md +++ b/solution/0000-0099/0006.Zigzag Conversion/README.md @@ -86,6 +86,8 @@ P I +#### Python3 + ```python class Solution: def convert(self, s: str, numRows: int) -> str: @@ -101,6 +103,8 @@ class Solution: return ''.join(chain(*g)) ``` +#### Java + ```java class Solution { public String convert(String s, int numRows) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func convert(s string, numRows int) string { if numRows == 1 { @@ -165,6 +173,8 @@ func convert(s string, numRows int) string { } ``` +#### TypeScript + ```ts function convert(s: string, numRows: number): string { if (numRows === 1) { @@ -184,6 +194,8 @@ function convert(s: string, numRows: number): string { } ``` +#### Rust + ```rust impl Solution { pub fn convert(s: String, num_rows: i32) -> String { @@ -214,6 +226,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -238,6 +252,8 @@ var convert = function (s, numRows) { }; ``` +#### C# + ```cs public class Solution { public string Convert(string s, int numRows) { @@ -276,6 +292,8 @@ public class Solution { +#### Python3 + ```python class Solution: def convert(self, s: str, numRows: int) -> str: @@ -295,6 +313,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String convert(String s, int numRows) { @@ -320,6 +340,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -342,6 +364,8 @@ public: }; ``` +#### Go + ```go func convert(s string, numRows int) string { if numRows == 1 { @@ -365,6 +389,8 @@ func convert(s string, numRows int) string { } ``` +#### TypeScript + ```ts function convert(s: string, numRows: number): string { if (numRows === 1) { @@ -388,6 +414,8 @@ function convert(s: string, numRows: number): string { } ``` +#### Rust + ```rust impl Solution { pub fn convert(s: String, num_rows: i32) -> String { @@ -400,6 +428,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -429,6 +459,8 @@ var convert = function (s, numRows) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0006.Zigzag Conversion/README_EN.md b/solution/0000-0099/0006.Zigzag Conversion/README_EN.md index 16ce4b3b8242a..04390da8f24e7 100644 --- a/solution/0000-0099/0006.Zigzag Conversion/README_EN.md +++ b/solution/0000-0099/0006.Zigzag Conversion/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def convert(self, s: str, numRows: int) -> str: @@ -99,6 +101,8 @@ class Solution: return ''.join(chain(*g)) ``` +#### Java + ```java class Solution { public String convert(String s, int numRows) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func convert(s string, numRows int) string { if numRows == 1 { @@ -163,6 +171,8 @@ func convert(s string, numRows int) string { } ``` +#### TypeScript + ```ts function convert(s: string, numRows: number): string { if (numRows === 1) { @@ -182,6 +192,8 @@ function convert(s: string, numRows: number): string { } ``` +#### Rust + ```rust impl Solution { pub fn convert(s: String, num_rows: i32) -> String { @@ -212,6 +224,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -236,6 +250,8 @@ var convert = function (s, numRows) { }; ``` +#### C# + ```cs public class Solution { public string Convert(string s, int numRows) { @@ -274,6 +290,8 @@ public class Solution { +#### Python3 + ```python class Solution: def convert(self, s: str, numRows: int) -> str: @@ -293,6 +311,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String convert(String s, int numRows) { @@ -318,6 +338,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -340,6 +362,8 @@ public: }; ``` +#### Go + ```go func convert(s string, numRows int) string { if numRows == 1 { @@ -363,6 +387,8 @@ func convert(s string, numRows int) string { } ``` +#### TypeScript + ```ts function convert(s: string, numRows: number): string { if (numRows === 1) { @@ -386,6 +412,8 @@ function convert(s: string, numRows: number): string { } ``` +#### Rust + ```rust impl Solution { pub fn convert(s: String, num_rows: i32) -> String { @@ -398,6 +426,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -427,6 +457,8 @@ var convert = function (s, numRows) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0007.Reverse Integer/README.md b/solution/0000-0099/0007.Reverse Integer/README.md index 38fe12b4bf251..2a415a12be25c 100644 --- a/solution/0000-0099/0007.Reverse Integer/README.md +++ b/solution/0000-0099/0007.Reverse Integer/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def reverse(self, x: int) -> int: @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int reverse(int x) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func reverse(x int) (ans int) { for ; x != 0; x /= 10 { @@ -148,6 +156,8 @@ func reverse(x int) (ans int) { } ``` +#### Rust + ```rust impl Solution { pub fn reverse(mut x: i32) -> i32 { @@ -160,6 +170,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} x @@ -179,6 +191,8 @@ var reverse = function (x) { }; ``` +#### C# + ```cs public class Solution { public int Reverse(int x) { @@ -194,6 +208,8 @@ public class Solution { } ``` +#### C + ```c int reverse(int x) { int ans = 0; @@ -207,6 +223,8 @@ int reverse(int x) { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0007.Reverse Integer/README_EN.md b/solution/0000-0099/0007.Reverse Integer/README_EN.md index 5e29c51552330..f4780e71e3874 100644 --- a/solution/0000-0099/0007.Reverse Integer/README_EN.md +++ b/solution/0000-0099/0007.Reverse Integer/README_EN.md @@ -79,6 +79,8 @@ The time complexity is $O(\log |x|)$, where $|x|$ is the absolute value of $x$. +#### Python3 + ```python class Solution: def reverse(self, x: int) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int reverse(int x) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func reverse(x int) (ans int) { for ; x != 0; x /= 10 { @@ -138,6 +146,8 @@ func reverse(x int) (ans int) { } ``` +#### Rust + ```rust impl Solution { pub fn reverse(mut x: i32) -> i32 { @@ -150,6 +160,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} x @@ -169,6 +181,8 @@ var reverse = function (x) { }; ``` +#### C# + ```cs public class Solution { public int Reverse(int x) { @@ -184,6 +198,8 @@ public class Solution { } ``` +#### C + ```c int reverse(int x) { int ans = 0; @@ -197,6 +213,8 @@ int reverse(int x) { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0008.String to Integer (atoi)/README.md b/solution/0000-0099/0008.String to Integer (atoi)/README.md index cf0b9ff5d6052..a1c189c4a6ce7 100644 --- a/solution/0000-0099/0008.String to Integer (atoi)/README.md +++ b/solution/0000-0099/0008.String to Integer (atoi)/README.md @@ -151,6 +151,8 @@ tags: +#### Python3 + ```python class Solution: def myAtoi(self, s: str) -> int: @@ -182,6 +184,8 @@ class Solution: return sign * res ``` +#### Java + ```java class Solution { public int myAtoi(String s) { @@ -210,6 +214,8 @@ class Solution { } ``` +#### Go + ```go func myAtoi(s string) int { i, n := 0, len(s) @@ -248,6 +254,8 @@ func myAtoi(s string) int { } ``` +#### JavaScript + ```js const myAtoi = function (str) { str = str.trim(); @@ -275,6 +283,8 @@ const myAtoi = function (str) { }; ``` +#### C# + ```cs // https://leetcode.com/problems/string-to-integer-atoi/ @@ -324,6 +334,8 @@ public partial class Solution } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0008.String to Integer (atoi)/README_EN.md b/solution/0000-0099/0008.String to Integer (atoi)/README_EN.md index 9da65f92ec995..23069a9df45fe 100644 --- a/solution/0000-0099/0008.String to Integer (atoi)/README_EN.md +++ b/solution/0000-0099/0008.String to Integer (atoi)/README_EN.md @@ -147,6 +147,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string. We only ne +#### Python3 + ```python class Solution: def myAtoi(self, s: str) -> int: @@ -178,6 +180,8 @@ class Solution: return sign * res ``` +#### Java + ```java class Solution { public int myAtoi(String s) { @@ -206,6 +210,8 @@ class Solution { } ``` +#### Go + ```go func myAtoi(s string) int { i, n := 0, len(s) @@ -244,6 +250,8 @@ func myAtoi(s string) int { } ``` +#### JavaScript + ```js const myAtoi = function (str) { str = str.trim(); @@ -271,6 +279,8 @@ const myAtoi = function (str) { }; ``` +#### C# + ```cs // https://leetcode.com/problems/string-to-integer-atoi/ @@ -320,6 +330,8 @@ public partial class Solution } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0009.Palindrome Number/README.md b/solution/0000-0099/0009.Palindrome Number/README.md index 7f9d1404acec0..ad40d6e7dc472 100644 --- a/solution/0000-0099/0009.Palindrome Number/README.md +++ b/solution/0000-0099/0009.Palindrome Number/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def isPalindrome(self, x: int) -> bool: @@ -105,6 +107,8 @@ class Solution: return x in (y, y // 10) ``` +#### Java + ```java class Solution { public boolean isPalindrome(int x) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func isPalindrome(x int) bool { if x < 0 || (x > 0 && x%10 == 0) { @@ -149,6 +157,8 @@ func isPalindrome(x int) bool { } ``` +#### TypeScript + ```ts function isPalindrome(x: number): boolean { if (x < 0 || (x > 0 && x % 10 === 0)) { @@ -162,6 +172,8 @@ function isPalindrome(x: number): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn is_palindrome(x: i32) -> bool { @@ -185,6 +197,8 @@ impl Solution { } ``` +#### Rust + ```rust impl Solution { pub fn is_palindrome(mut x: i32) -> bool { @@ -202,6 +216,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} x @@ -219,6 +235,8 @@ var isPalindrome = function (x) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0009.Palindrome Number/README_EN.md b/solution/0000-0099/0009.Palindrome Number/README_EN.md index 9ba00572cd002..c980324036bf4 100644 --- a/solution/0000-0099/0009.Palindrome Number/README_EN.md +++ b/solution/0000-0099/0009.Palindrome Number/README_EN.md @@ -85,6 +85,8 @@ The time complexity is $O(\log_{10}(n))$, where $n$ is $x$. For each iteration, +#### Python3 + ```python class Solution: def isPalindrome(self, x: int) -> bool: @@ -97,6 +99,8 @@ class Solution: return x in (y, y // 10) ``` +#### Java + ```java class Solution { public boolean isPalindrome(int x) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func isPalindrome(x int) bool { if x < 0 || (x > 0 && x%10 == 0) { @@ -141,6 +149,8 @@ func isPalindrome(x int) bool { } ``` +#### TypeScript + ```ts function isPalindrome(x: number): boolean { if (x < 0 || (x > 0 && x % 10 === 0)) { @@ -154,6 +164,8 @@ function isPalindrome(x: number): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn is_palindrome(x: i32) -> bool { @@ -177,6 +189,8 @@ impl Solution { } ``` +#### Rust + ```rust impl Solution { pub fn is_palindrome(mut x: i32) -> bool { @@ -194,6 +208,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} x @@ -211,6 +227,8 @@ var isPalindrome = function (x) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0010.Regular Expression Matching/README.md b/solution/0000-0099/0010.Regular Expression Matching/README.md index 1b89d6bcfffbb..ff0ce58e0004d 100644 --- a/solution/0000-0099/0010.Regular Expression Matching/README.md +++ b/solution/0000-0099/0010.Regular Expression Matching/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def isMatch(self, s: str, p: str) -> bool: @@ -103,6 +105,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private Boolean[][] f; @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go func isMatch(s string, p string) bool { m, n := len(s), len(p) @@ -199,6 +207,8 @@ func isMatch(s string, p string) bool { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -240,6 +250,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -272,6 +284,8 @@ var isMatch = function (s, p) { }; ``` +#### C# + ```cs public class Solution { private string s; @@ -331,6 +345,8 @@ public class Solution { +#### Python3 + ```python class Solution: def isMatch(self, s: str, p: str) -> bool: @@ -348,6 +364,8 @@ class Solution: return f[m][n] ``` +#### Java + ```java class Solution { public boolean isMatch(String s, String p) { @@ -372,6 +390,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -397,6 +417,8 @@ public: }; ``` +#### Go + ```go func isMatch(s string, p string) bool { m, n := len(s), len(p) @@ -421,6 +443,8 @@ func isMatch(s string, p string) bool { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -448,6 +472,8 @@ var isMatch = function (s, p) { }; ``` +#### C# + ```cs public class Solution { public bool IsMatch(string s, string p) { @@ -471,6 +497,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0010.Regular Expression Matching/README_EN.md b/solution/0000-0099/0010.Regular Expression Matching/README_EN.md index 498e2cce90529..5e56d3f62511b 100644 --- a/solution/0000-0099/0010.Regular Expression Matching/README_EN.md +++ b/solution/0000-0099/0010.Regular Expression Matching/README_EN.md @@ -85,6 +85,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def isMatch(self, s: str, p: str) -> bool: @@ -102,6 +104,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private Boolean[][] f; @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func isMatch(s string, p string) bool { m, n := len(s), len(p) @@ -198,6 +206,8 @@ func isMatch(s string, p string) bool { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -239,6 +249,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -271,6 +283,8 @@ var isMatch = function (s, p) { }; ``` +#### C# + ```cs public class Solution { private string s; @@ -330,6 +344,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def isMatch(self, s: str, p: str) -> bool: @@ -347,6 +363,8 @@ class Solution: return f[m][n] ``` +#### Java + ```java class Solution { public boolean isMatch(String s, String p) { @@ -371,6 +389,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -396,6 +416,8 @@ public: }; ``` +#### Go + ```go func isMatch(s string, p string) bool { m, n := len(s), len(p) @@ -420,6 +442,8 @@ func isMatch(s string, p string) bool { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -447,6 +471,8 @@ var isMatch = function (s, p) { }; ``` +#### C# + ```cs public class Solution { public bool IsMatch(string s, string p) { @@ -470,6 +496,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0011.Container With Most Water/README.md b/solution/0000-0099/0011.Container With Most Water/README.md index 66d733124358e..5a8a3969742f2 100644 --- a/solution/0000-0099/0011.Container With Most Water/README.md +++ b/solution/0000-0099/0011.Container With Most Water/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def maxArea(self, height: List[int]) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxArea(int[] height) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func maxArea(height []int) (ans int) { i, j := 0, len(height)-1 @@ -142,6 +150,8 @@ func maxArea(height []int) (ans int) { } ``` +#### TypeScript + ```ts function maxArea(height: number[]): number { let i = 0; @@ -160,6 +170,8 @@ function maxArea(height: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_area(height: Vec) -> i32 { @@ -179,6 +191,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} height @@ -201,6 +215,8 @@ var maxArea = function (height) { }; ``` +#### C# + ```cs public class Solution { public int MaxArea(int[] height) { @@ -220,6 +236,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0011.Container With Most Water/README_EN.md b/solution/0000-0099/0011.Container With Most Water/README_EN.md index 853e36c33a85e..459c81c5edec6 100644 --- a/solution/0000-0099/0011.Container With Most Water/README_EN.md +++ b/solution/0000-0099/0011.Container With Most Water/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array `height`. Th +#### Python3 + ```python class Solution: def maxArea(self, height: List[int]) -> int: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxArea(int[] height) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func maxArea(height []int) (ans int) { i, j := 0, len(height)-1 @@ -139,6 +147,8 @@ func maxArea(height []int) (ans int) { } ``` +#### TypeScript + ```ts function maxArea(height: number[]): number { let i = 0; @@ -157,6 +167,8 @@ function maxArea(height: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_area(height: Vec) -> i32 { @@ -176,6 +188,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} height @@ -198,6 +212,8 @@ var maxArea = function (height) { }; ``` +#### C# + ```cs public class Solution { public int MaxArea(int[] height) { @@ -217,6 +233,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0012.Integer to Roman/README.md b/solution/0000-0099/0012.Integer to Roman/README.md index 7d044ac88c892..df6c1d76eda54 100644 --- a/solution/0000-0099/0012.Integer to Roman/README.md +++ b/solution/0000-0099/0012.Integer to Roman/README.md @@ -99,6 +99,8 @@ M 1000 +#### Python3 + ```python class Solution: def intToRoman(self, num: int) -> str: @@ -112,6 +114,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String intToRoman(int num) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func intToRoman(num int) string { cs := []string{"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"} @@ -163,6 +171,8 @@ func intToRoman(num int) string { } ``` +#### TypeScript + ```ts function intToRoman(num: number): string { const cs: string[] = ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']; @@ -178,6 +188,8 @@ function intToRoman(num: number): string { } ``` +#### C# + ```cs public class Solution { public string IntToRoman(int num) { @@ -195,6 +207,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0012.Integer to Roman/README_EN.md b/solution/0000-0099/0012.Integer to Roman/README_EN.md index c158c5b964ee5..d6d1ef4e26268 100644 --- a/solution/0000-0099/0012.Integer to Roman/README_EN.md +++ b/solution/0000-0099/0012.Integer to Roman/README_EN.md @@ -141,6 +141,8 @@ The time complexity is $O(m)$, and the space complexity is $O(m)$. Here, $m$ is +#### Python3 + ```python class Solution: def intToRoman(self, num: int) -> str: @@ -154,6 +156,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String intToRoman(int num) { @@ -172,6 +176,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -190,6 +196,8 @@ public: }; ``` +#### Go + ```go func intToRoman(num int) string { cs := []string{"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"} @@ -205,6 +213,8 @@ func intToRoman(num int) string { } ``` +#### TypeScript + ```ts function intToRoman(num: number): string { const cs: string[] = ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']; @@ -220,6 +230,8 @@ function intToRoman(num: number): string { } ``` +#### C# + ```cs public class Solution { public string IntToRoman(int num) { @@ -237,6 +249,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0013.Roman to Integer/README.md b/solution/0000-0099/0013.Roman to Integer/README.md index c2dda5de22b75..f283fcd9bcb39 100644 --- a/solution/0000-0099/0013.Roman to Integer/README.md +++ b/solution/0000-0099/0013.Roman to Integer/README.md @@ -106,6 +106,8 @@ M 1000 +#### Python3 + ```python class Solution: def romanToInt(self, s: str) -> int: @@ -113,6 +115,8 @@ class Solution: return sum((-1 if d[a] < d[b] else 1) * d[a] for a, b in pairwise(s)) + d[s[-1]] ``` +#### Java + ```java class Solution { public int romanToInt(String s) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func romanToInt(s string) (ans int) { d := map[byte]int{'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000} @@ -171,6 +179,8 @@ func romanToInt(s string) (ans int) { } ``` +#### TypeScript + ```ts function romanToInt(s: string): number { const d: Map = new Map([ @@ -191,6 +201,8 @@ function romanToInt(s: string): number { } ``` +#### JavaScript + ```js const romanToInt = function (s) { const d = { @@ -211,6 +223,8 @@ const romanToInt = function (s) { }; ``` +#### C# + ```cs public class Solution { public int RomanToInt(string s) { @@ -232,6 +246,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** @@ -263,6 +279,8 @@ class Solution { } ``` +#### Ruby + ```rb # @param {String} s # @return {Integer} diff --git a/solution/0000-0099/0013.Roman to Integer/README_EN.md b/solution/0000-0099/0013.Roman to Integer/README_EN.md index cc3f038a5ffe0..82dd8a12f725b 100644 --- a/solution/0000-0099/0013.Roman to Integer/README_EN.md +++ b/solution/0000-0099/0013.Roman to Integer/README_EN.md @@ -90,6 +90,8 @@ The time complexity is $O(n)$, and the space complexity is $O(m)$. Here, $n$ and +#### Python3 + ```python class Solution: def romanToInt(self, s: str) -> int: @@ -97,6 +99,8 @@ class Solution: return sum((-1 if d[a] < d[b] else 1) * d[a] for a, b in pairwise(s)) + d[s[-1]] ``` +#### Java + ```java class Solution { public int romanToInt(String s) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func romanToInt(s string) (ans int) { d := map[byte]int{'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000} @@ -155,6 +163,8 @@ func romanToInt(s string) (ans int) { } ``` +#### TypeScript + ```ts function romanToInt(s: string): number { const d: Map = new Map([ @@ -175,6 +185,8 @@ function romanToInt(s: string): number { } ``` +#### JavaScript + ```js const romanToInt = function (s) { const d = { @@ -195,6 +207,8 @@ const romanToInt = function (s) { }; ``` +#### C# + ```cs public class Solution { public int RomanToInt(string s) { @@ -216,6 +230,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** @@ -247,6 +263,8 @@ class Solution { } ``` +#### Ruby + ```rb # @param {String} s # @return {Integer} diff --git a/solution/0000-0099/0014.Longest Common Prefix/README.md b/solution/0000-0099/0014.Longest Common Prefix/README.md index 7e594d391a00e..7ccdfcfc11e67 100644 --- a/solution/0000-0099/0014.Longest Common Prefix/README.md +++ b/solution/0000-0099/0014.Longest Common Prefix/README.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def longestCommonPrefix(self, strs: List[str]) -> str: @@ -73,6 +75,8 @@ class Solution: return strs[0] ``` +#### Java + ```java class Solution { public String longestCommonPrefix(String[] strs) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func longestCommonPrefix(strs []string) string { n := len(strs) @@ -120,6 +128,8 @@ func longestCommonPrefix(strs []string) string { } ``` +#### TypeScript + ```ts function longestCommonPrefix(strs: string[]): string { const len = strs.reduce((r, s) => Math.min(r, s.length), Infinity); @@ -133,6 +143,8 @@ function longestCommonPrefix(strs: string[]): string { } ``` +#### Rust + ```rust impl Solution { pub fn longest_common_prefix(strs: Vec) -> String { @@ -153,6 +165,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string[]} strs @@ -170,6 +184,8 @@ var longestCommonPrefix = function (strs) { }; ``` +#### C# + ```cs public class Solution { public string LongestCommonPrefix(string[] strs) { @@ -186,6 +202,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** @@ -207,6 +225,8 @@ class Solution { } ``` +#### Ruby + ```rb # @param {String[]} strs # @return {String} diff --git a/solution/0000-0099/0014.Longest Common Prefix/README_EN.md b/solution/0000-0099/0014.Longest Common Prefix/README_EN.md index 9e6b2959dde2d..823f95aba280d 100644 --- a/solution/0000-0099/0014.Longest Common Prefix/README_EN.md +++ b/solution/0000-0099/0014.Longest Common Prefix/README_EN.md @@ -62,6 +62,8 @@ The time complexity is $O(n \times m)$, where $n$ and $m$ are the length of the +#### Python3 + ```python class Solution: def longestCommonPrefix(self, strs: List[str]) -> str: @@ -72,6 +74,8 @@ class Solution: return strs[0] ``` +#### Java + ```java class Solution { public String longestCommonPrefix(String[] strs) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func longestCommonPrefix(strs []string) string { n := len(strs) @@ -119,6 +127,8 @@ func longestCommonPrefix(strs []string) string { } ``` +#### TypeScript + ```ts function longestCommonPrefix(strs: string[]): string { const len = strs.reduce((r, s) => Math.min(r, s.length), Infinity); @@ -132,6 +142,8 @@ function longestCommonPrefix(strs: string[]): string { } ``` +#### Rust + ```rust impl Solution { pub fn longest_common_prefix(strs: Vec) -> String { @@ -152,6 +164,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string[]} strs @@ -169,6 +183,8 @@ var longestCommonPrefix = function (strs) { }; ``` +#### C# + ```cs public class Solution { public string LongestCommonPrefix(string[] strs) { @@ -185,6 +201,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** @@ -206,6 +224,8 @@ class Solution { } ``` +#### Ruby + ```rb # @param {String[]} strs # @return {String} diff --git a/solution/0000-0099/0015.3Sum/README.md b/solution/0000-0099/0015.3Sum/README.md index d6aa85b9b7f1c..0d60c80a54ff9 100644 --- a/solution/0000-0099/0015.3Sum/README.md +++ b/solution/0000-0099/0015.3Sum/README.md @@ -96,6 +96,8 @@ nums[0] + nums[3] + nums[4] = (-1) + 2 + (-1) = 0 。 +#### Python3 + ```python class Solution: def threeSum(self, nums: List[int]) -> List[List[int]]: @@ -124,6 +126,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> threeSum(int[] nums) { @@ -157,6 +161,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -191,6 +197,8 @@ public: }; ``` +#### Go + ```go func threeSum(nums []int) (ans [][]int) { sort.Ints(nums) @@ -222,6 +230,8 @@ func threeSum(nums []int) (ans [][]int) { } ``` +#### TypeScript + ```ts function threeSum(nums: number[]): number[][] { nums.sort((a, b) => a - b); @@ -254,6 +264,8 @@ function threeSum(nums: number[]): number[][] { } ``` +#### Rust + ```rust use std::cmp::Ordering; @@ -297,6 +309,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -333,6 +347,8 @@ var threeSum = function (nums) { }; ``` +#### C# + ```cs public class Solution { public IList> ThreeSum(int[] nums) { @@ -366,6 +382,8 @@ public class Solution { } ``` +#### Ruby + ```rb # @param {Integer[]} nums # @return {Integer[][]} @@ -397,6 +415,8 @@ def three_sum(nums) end ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0015.3Sum/README_EN.md b/solution/0000-0099/0015.3Sum/README_EN.md index 20ca919432320..9f84f4eceb78f 100644 --- a/solution/0000-0099/0015.3Sum/README_EN.md +++ b/solution/0000-0099/0015.3Sum/README_EN.md @@ -90,6 +90,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(\log n)$. The $n +#### Python3 + ```python class Solution: def threeSum(self, nums: List[int]) -> List[List[int]]: @@ -118,6 +120,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> threeSum(int[] nums) { @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -185,6 +191,8 @@ public: }; ``` +#### Go + ```go func threeSum(nums []int) (ans [][]int) { sort.Ints(nums) @@ -216,6 +224,8 @@ func threeSum(nums []int) (ans [][]int) { } ``` +#### TypeScript + ```ts function threeSum(nums: number[]): number[][] { nums.sort((a, b) => a - b); @@ -248,6 +258,8 @@ function threeSum(nums: number[]): number[][] { } ``` +#### Rust + ```rust use std::cmp::Ordering; @@ -291,6 +303,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -327,6 +341,8 @@ var threeSum = function (nums) { }; ``` +#### C# + ```cs public class Solution { public IList> ThreeSum(int[] nums) { @@ -360,6 +376,8 @@ public class Solution { } ``` +#### Ruby + ```rb # @param {Integer[]} nums # @return {Integer[][]} @@ -391,6 +409,8 @@ def three_sum(nums) end ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0016.3Sum Closest/README.md b/solution/0000-0099/0016.3Sum Closest/README.md index 8f829ea2ff074..36a0f1a68f585 100644 --- a/solution/0000-0099/0016.3Sum Closest/README.md +++ b/solution/0000-0099/0016.3Sum Closest/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def threeSumClosest(self, nums: List[int], target: int) -> int: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int threeSumClosest(int[] nums, int target) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func threeSumClosest(nums []int, target int) int { sort.Ints(nums) @@ -171,6 +179,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function threeSumClosest(nums: number[], target: number): number { nums.sort((a, b) => a - b); @@ -198,6 +208,8 @@ function threeSumClosest(nums: number[], target: number): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -230,6 +242,8 @@ var threeSumClosest = function (nums, target) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0016.3Sum Closest/README_EN.md b/solution/0000-0099/0016.3Sum Closest/README_EN.md index 5d5766a7c90f3..92375933a0907 100644 --- a/solution/0000-0099/0016.3Sum Closest/README_EN.md +++ b/solution/0000-0099/0016.3Sum Closest/README_EN.md @@ -64,6 +64,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(\log n)$. Here, +#### Python3 + ```python class Solution: def threeSumClosest(self, nums: List[int], target: int) -> int: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int threeSumClosest(int[] nums, int target) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func threeSumClosest(nums []int, target int) int { sort.Ints(nums) @@ -170,6 +178,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function threeSumClosest(nums: number[], target: number): number { nums.sort((a, b) => a - b); @@ -197,6 +207,8 @@ function threeSumClosest(nums: number[], target: number): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -229,6 +241,8 @@ var threeSumClosest = function (nums, target) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0017.Letter Combinations of a Phone Number/README.md b/solution/0000-0099/0017.Letter Combinations of a Phone Number/README.md index bb5e9515355a8..58d325892108f 100644 --- a/solution/0000-0099/0017.Letter Combinations of a Phone Number/README.md +++ b/solution/0000-0099/0017.Letter Combinations of a Phone Number/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def letterCombinations(self, digits: str) -> List[str]: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List letterCombinations(String digits) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func letterCombinations(digits string) []string { ans := []string{} @@ -153,6 +161,8 @@ func letterCombinations(digits string) []string { } ``` +#### TypeScript + ```ts function letterCombinations(digits: string): string[] { if (digits.length == 0) { @@ -174,6 +184,8 @@ function letterCombinations(digits: string): string[] { } ``` +#### Rust + ```rust impl Solution { pub fn letter_combinations(digits: String) -> Vec { @@ -198,6 +210,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} digits @@ -223,6 +237,8 @@ var letterCombinations = function (digits) { }; ``` +#### C# + ```cs public class Solution { public IList LetterCombinations(string digits) { @@ -261,6 +277,8 @@ public class Solution { +#### Python3 + ```python class Solution: def letterCombinations(self, digits: str) -> List[str]: @@ -282,6 +300,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private final String[] d = {"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}; @@ -313,6 +333,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -340,6 +362,8 @@ public: }; ``` +#### Go + ```go func letterCombinations(digits string) (ans []string) { d := []string{"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"} @@ -364,6 +388,8 @@ func letterCombinations(digits string) (ans []string) { } ``` +#### TypeScript + ```ts function letterCombinations(digits: string): string[] { if (digits.length == 0) { @@ -389,6 +415,8 @@ function letterCombinations(digits: string): string[] { } ``` +#### Rust + ```rust impl Solution { pub fn letter_combinations(digits: String) -> Vec { @@ -417,6 +445,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} digits @@ -446,6 +476,8 @@ var letterCombinations = function (digits) { }; ``` +#### C# + ```cs public class Solution { private readonly string[] d = {"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}; @@ -477,6 +509,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0017.Letter Combinations of a Phone Number/README_EN.md b/solution/0000-0099/0017.Letter Combinations of a Phone Number/README_EN.md index d5d3e4e6ab7d5..a15369a5b20c5 100644 --- a/solution/0000-0099/0017.Letter Combinations of a Phone Number/README_EN.md +++ b/solution/0000-0099/0017.Letter Combinations of a Phone Number/README_EN.md @@ -66,6 +66,8 @@ The time complexity is $O(4^n)$, and the space complexity is $O(4^n)$. Here, $n$ +#### Python3 + ```python class Solution: def letterCombinations(self, digits: str) -> List[str]: @@ -79,6 +81,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List letterCombinations(String digits) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func letterCombinations(digits string) []string { ans := []string{} @@ -149,6 +157,8 @@ func letterCombinations(digits string) []string { } ``` +#### TypeScript + ```ts function letterCombinations(digits: string): string[] { if (digits.length == 0) { @@ -170,6 +180,8 @@ function letterCombinations(digits: string): string[] { } ``` +#### Rust + ```rust impl Solution { pub fn letter_combinations(digits: String) -> Vec { @@ -194,6 +206,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} digits @@ -219,6 +233,8 @@ var letterCombinations = function (digits) { }; ``` +#### C# + ```cs public class Solution { public IList LetterCombinations(string digits) { @@ -257,6 +273,8 @@ The time complexity is $O(4^n)$, and the space complexity is $O(n)$. Here, $n$ i +#### Python3 + ```python class Solution: def letterCombinations(self, digits: str) -> List[str]: @@ -278,6 +296,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private final String[] d = {"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}; @@ -309,6 +329,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -336,6 +358,8 @@ public: }; ``` +#### Go + ```go func letterCombinations(digits string) (ans []string) { d := []string{"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"} @@ -360,6 +384,8 @@ func letterCombinations(digits string) (ans []string) { } ``` +#### TypeScript + ```ts function letterCombinations(digits: string): string[] { if (digits.length == 0) { @@ -385,6 +411,8 @@ function letterCombinations(digits: string): string[] { } ``` +#### Rust + ```rust impl Solution { pub fn letter_combinations(digits: String) -> Vec { @@ -413,6 +441,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} digits @@ -442,6 +472,8 @@ var letterCombinations = function (digits) { }; ``` +#### C# + ```cs public class Solution { private readonly string[] d = {"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}; @@ -473,6 +505,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0018.4Sum/README.md b/solution/0000-0099/0018.4Sum/README.md index 49eeb4da00879..3e4d55c93c3fb 100644 --- a/solution/0000-0099/0018.4Sum/README.md +++ b/solution/0000-0099/0018.4Sum/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def fourSum(self, nums: List[int], target: int) -> List[List[int]]: @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> fourSum(int[] nums, int target) { @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go func fourSum(nums []int, target int) (ans [][]int) { n := len(nums) @@ -228,6 +236,8 @@ func fourSum(nums []int, target int) (ans [][]int) { } ``` +#### TypeScript + ```ts function fourSum(nums: number[], target: number): number[][] { const n = nums.length; @@ -267,6 +277,8 @@ function fourSum(nums: number[], target: number): number[][] { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -311,6 +323,8 @@ var fourSum = function (nums, target) { }; ``` +#### C# + ```cs public class Solution { public IList> FourSum(int[] nums, int target) { @@ -352,6 +366,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0018.4Sum/README_EN.md b/solution/0000-0099/0018.4Sum/README_EN.md index 29fc3c134e61f..737466ea8d1c8 100644 --- a/solution/0000-0099/0018.4Sum/README_EN.md +++ b/solution/0000-0099/0018.4Sum/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(n^3)$, and the space complexity is $O(\log n)$. Here, +#### Python3 + ```python class Solution: def fourSum(self, nums: List[int], target: int) -> List[List[int]]: @@ -103,6 +105,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> fourSum(int[] nums, int target) { @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go func fourSum(nums []int, target int) (ans [][]int) { n := len(nums) @@ -226,6 +234,8 @@ func fourSum(nums []int, target int) (ans [][]int) { } ``` +#### TypeScript + ```ts function fourSum(nums: number[], target: number): number[][] { const n = nums.length; @@ -265,6 +275,8 @@ function fourSum(nums: number[], target: number): number[][] { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -309,6 +321,8 @@ var fourSum = function (nums, target) { }; ``` +#### C# + ```cs public class Solution { public IList> FourSum(int[] nums, int target) { @@ -350,6 +364,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0019.Remove Nth Node From End of List/README.md b/solution/0000-0099/0019.Remove Nth Node From End of List/README.md index 59062d1daf17c..310c885f7de9a 100644 --- a/solution/0000-0099/0019.Remove Nth Node From End of List/README.md +++ b/solution/0000-0099/0019.Remove Nth Node From End of List/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -91,6 +93,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -171,6 +179,8 @@ func removeNthFromEnd(head *ListNode, n int) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -200,6 +210,8 @@ function removeNthFromEnd(head: ListNode | null, n: number): ListNode | null { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -235,6 +247,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -264,6 +278,8 @@ var removeNthFromEnd = function (head, n) { }; ``` +#### Ruby + ```rb # Definition for singly-linked list. # class ListNode @@ -292,6 +308,8 @@ def remove_nth_from_end(head, n) end ``` +#### PHP + ```php # Definition for singly-linked list. # class ListNode { diff --git a/solution/0000-0099/0019.Remove Nth Node From End of List/README_EN.md b/solution/0000-0099/0019.Remove Nth Node From End of List/README_EN.md index a8185fa4b6560..c2e89d64db00c 100644 --- a/solution/0000-0099/0019.Remove Nth Node From End of List/README_EN.md +++ b/solution/0000-0099/0019.Remove Nth Node From End of List/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n)$, where $n$ is the length of the linked list. The s +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -88,6 +90,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -168,6 +176,8 @@ func removeNthFromEnd(head *ListNode, n int) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -197,6 +207,8 @@ function removeNthFromEnd(head: ListNode | null, n: number): ListNode | null { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -232,6 +244,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -261,6 +275,8 @@ var removeNthFromEnd = function (head, n) { }; ``` +#### Ruby + ```rb # Definition for singly-linked list. # class ListNode @@ -289,6 +305,8 @@ def remove_nth_from_end(head, n) end ``` +#### PHP + ```php # Definition for singly-linked list. # class ListNode { diff --git a/solution/0000-0099/0020.Valid Parentheses/README.md b/solution/0000-0099/0020.Valid Parentheses/README.md index ab920475436fe..4e6adcb27adec 100644 --- a/solution/0000-0099/0020.Valid Parentheses/README.md +++ b/solution/0000-0099/0020.Valid Parentheses/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def isValid(self, s: str) -> bool: @@ -92,6 +94,8 @@ class Solution: return not stk ``` +#### Java + ```java class Solution { public boolean isValid(String s) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func isValid(s string) bool { stk := []rune{} @@ -154,6 +162,8 @@ func match(l, r rune) bool { } ``` +#### TypeScript + ```ts const map = new Map([ ['(', ')'], @@ -174,6 +184,8 @@ function isValid(s: string): boolean { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -196,6 +208,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -220,6 +234,8 @@ function match(l, r) { } ``` +#### C# + ```cs public class Solution { public bool IsValid(string s) { @@ -240,6 +256,8 @@ public class Solution { } ``` +#### Ruby + ```rb # @param {String} s # @return {Boolean} @@ -265,6 +283,8 @@ def is_valid(s) end ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0020.Valid Parentheses/README_EN.md b/solution/0000-0099/0020.Valid Parentheses/README_EN.md index dfb8415484c84..427aaa6553630 100644 --- a/solution/0000-0099/0020.Valid Parentheses/README_EN.md +++ b/solution/0000-0099/0020.Valid Parentheses/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def isValid(self, s: str) -> bool: @@ -90,6 +92,8 @@ class Solution: return not stk ``` +#### Java + ```java class Solution { public boolean isValid(String s) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func isValid(s string) bool { stk := []rune{} @@ -152,6 +160,8 @@ func match(l, r rune) bool { } ``` +#### TypeScript + ```ts const map = new Map([ ['(', ')'], @@ -172,6 +182,8 @@ function isValid(s: string): boolean { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -194,6 +206,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -218,6 +232,8 @@ function match(l, r) { } ``` +#### C# + ```cs public class Solution { public bool IsValid(string s) { @@ -238,6 +254,8 @@ public class Solution { } ``` +#### Ruby + ```rb # @param {String} s # @return {Boolean} @@ -263,6 +281,8 @@ def is_valid(s) end ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0021.Merge Two Sorted Lists/README.md b/solution/0000-0099/0021.Merge Two Sorted Lists/README.md index aa15dc84aaf3e..f9e7c4440dab9 100644 --- a/solution/0000-0099/0021.Merge Two Sorted Lists/README.md +++ b/solution/0000-0099/0021.Merge Two Sorted Lists/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -89,6 +91,8 @@ class Solution: return list2 ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -171,6 +179,8 @@ func mergeTwoLists(list1 *ListNode, list2 *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -198,6 +208,8 @@ function mergeTwoLists(list1: ListNode | null, list2: ListNode | null): ListNode } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -238,6 +250,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -265,6 +279,8 @@ var mergeTwoLists = function (list1, list2) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. @@ -301,6 +317,8 @@ public class Solution { } ``` +#### Ruby + ```rb # Definition for singly-linked list. # class ListNode @@ -349,6 +367,8 @@ end +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -373,6 +393,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -404,6 +426,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -436,6 +460,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -466,6 +492,8 @@ func mergeTwoLists(list1 *ListNode, list2 *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -497,6 +525,8 @@ function mergeTwoLists(list1: ListNode | null, list2: ListNode | null): ListNode } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -540,6 +570,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -571,6 +603,8 @@ var mergeTwoLists = function (list1, list2) { }; ``` +#### PHP + ```php # Definition for singly-linked list. # class ListNode { diff --git a/solution/0000-0099/0021.Merge Two Sorted Lists/README_EN.md b/solution/0000-0099/0021.Merge Two Sorted Lists/README_EN.md index 458be165c01d8..7f9d8daa39f61 100644 --- a/solution/0000-0099/0021.Merge Two Sorted Lists/README_EN.md +++ b/solution/0000-0099/0021.Merge Two Sorted Lists/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(m + n)$, and the space complexity is $O(m + n)$. Here, +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -91,6 +93,8 @@ class Solution: return list2 ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -173,6 +181,8 @@ func mergeTwoLists(list1 *ListNode, list2 *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -200,6 +210,8 @@ function mergeTwoLists(list1: ListNode | null, list2: ListNode | null): ListNode } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -240,6 +252,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -267,6 +281,8 @@ var mergeTwoLists = function (list1, list2) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. @@ -303,6 +319,8 @@ public class Solution { } ``` +#### Ruby + ```rb # Definition for singly-linked list. # class ListNode @@ -351,6 +369,8 @@ The time complexity is $O(m + n)$, where $m$ and $n$ are the lengths of the two +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -375,6 +395,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -406,6 +428,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -438,6 +462,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -468,6 +494,8 @@ func mergeTwoLists(list1 *ListNode, list2 *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -499,6 +527,8 @@ function mergeTwoLists(list1: ListNode | null, list2: ListNode | null): ListNode } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -542,6 +572,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -573,6 +605,8 @@ var mergeTwoLists = function (list1, list2) { }; ``` +#### PHP + ```php # Definition for singly-linked list. # class ListNode { diff --git a/solution/0000-0099/0022.Generate Parentheses/README.md b/solution/0000-0099/0022.Generate Parentheses/README.md index cccd29d7b8704..ef5af9be22087 100644 --- a/solution/0000-0099/0022.Generate Parentheses/README.md +++ b/solution/0000-0099/0022.Generate Parentheses/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def generateParenthesis(self, n: int) -> List[str]: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List ans = new ArrayList<>(); @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func generateParenthesis(n int) (ans []string) { var dfs func(int, int, string) @@ -146,6 +154,8 @@ func generateParenthesis(n int) (ans []string) { } ``` +#### TypeScript + ```ts function generateParenthesis(n: number): string[] { function dfs(l, r, t) { @@ -165,6 +175,8 @@ function generateParenthesis(n: number): string[] { } ``` +#### Rust + ```rust impl Solution { fn dfs(left: i32, right: i32, s: &mut String, res: &mut Vec) { @@ -192,6 +204,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -225,6 +239,8 @@ var generateParenthesis = function (n) { +#### Rust + ```rust impl Solution { pub fn generate_parenthesis(n: i32) -> Vec { @@ -256,6 +272,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0022.Generate Parentheses/README_EN.md b/solution/0000-0099/0022.Generate Parentheses/README_EN.md index 0016d04ef2549..aea8581904098 100644 --- a/solution/0000-0099/0022.Generate Parentheses/README_EN.md +++ b/solution/0000-0099/0022.Generate Parentheses/README_EN.md @@ -56,6 +56,8 @@ The time complexity is $O(2^{n\times 2} \times n)$, and the space complexity is +#### Python3 + ```python class Solution: def generateParenthesis(self, n: int) -> List[str]: @@ -73,6 +75,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List ans = new ArrayList<>(); @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func generateParenthesis(n int) (ans []string) { var dfs func(int, int, string) @@ -137,6 +145,8 @@ func generateParenthesis(n int) (ans []string) { } ``` +#### TypeScript + ```ts function generateParenthesis(n: number): string[] { function dfs(l, r, t) { @@ -156,6 +166,8 @@ function generateParenthesis(n: number): string[] { } ``` +#### Rust + ```rust impl Solution { fn dfs(left: i32, right: i32, s: &mut String, res: &mut Vec) { @@ -183,6 +195,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -216,6 +230,8 @@ var generateParenthesis = function (n) { +#### Rust + ```rust impl Solution { pub fn generate_parenthesis(n: i32) -> Vec { @@ -247,6 +263,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0023.Merge k Sorted Lists/README.md b/solution/0000-0099/0023.Merge k Sorted Lists/README.md index a30d1dba9bf53..c07f16ad90222 100644 --- a/solution/0000-0099/0023.Merge k Sorted Lists/README.md +++ b/solution/0000-0099/0023.Merge k Sorted Lists/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -99,6 +101,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -207,6 +215,8 @@ func (h *hp) Push(v any) { *h = append(*h, v.(*ListNode)) } func (h *hp) Pop() any { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; return v } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -241,6 +251,8 @@ function mergeKLists(lists: Array): ListNode | null { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -290,6 +302,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -323,6 +337,8 @@ var mergeKLists = function (lists) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. @@ -358,6 +374,8 @@ public class Solution { } ``` +#### PHP + ```php # Definition for singly-linked list. class ListNode { diff --git a/solution/0000-0099/0023.Merge k Sorted Lists/README_EN.md b/solution/0000-0099/0023.Merge k Sorted Lists/README_EN.md index 3faf396f2bafc..c202848462f5a 100644 --- a/solution/0000-0099/0023.Merge k Sorted Lists/README_EN.md +++ b/solution/0000-0099/0023.Merge k Sorted Lists/README_EN.md @@ -79,6 +79,8 @@ The time complexity is $O(n \times \log k)$, and the space complexity is $O(k)$. +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -100,6 +102,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -208,6 +216,8 @@ func (h *hp) Push(v any) { *h = append(*h, v.(*ListNode)) } func (h *hp) Pop() any { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; return v } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -242,6 +252,8 @@ function mergeKLists(lists: Array): ListNode | null { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -291,6 +303,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -324,6 +338,8 @@ var mergeKLists = function (lists) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. @@ -359,6 +375,8 @@ public class Solution { } ``` +#### PHP + ```php # Definition for singly-linked list. class ListNode { diff --git a/solution/0000-0099/0024.Swap Nodes in Pairs/README.md b/solution/0000-0099/0024.Swap Nodes in Pairs/README.md index 837ec9fa47f95..38a1b4904219d 100644 --- a/solution/0000-0099/0024.Swap Nodes in Pairs/README.md +++ b/solution/0000-0099/0024.Swap Nodes in Pairs/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -86,6 +88,8 @@ class Solution: return p ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -157,6 +165,8 @@ func swapPairs(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -182,6 +192,8 @@ function swapPairs(head: ListNode | null): ListNode | null { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -218,6 +230,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -242,6 +256,8 @@ var swapPairs = function (head) { }; ``` +#### Ruby + ```rb # Definition for singly-linked list. # class ListNode @@ -285,6 +301,8 @@ end +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -304,6 +322,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -333,6 +353,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -363,6 +385,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -385,6 +409,8 @@ func swapPairs(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -412,6 +438,8 @@ function swapPairs(head: ListNode | null): ListNode | null { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -438,6 +466,8 @@ var swapPairs = function (head) { }; ``` +#### PHP + ```php # Definition for singly-linked list. # class ListNode { diff --git a/solution/0000-0099/0024.Swap Nodes in Pairs/README_EN.md b/solution/0000-0099/0024.Swap Nodes in Pairs/README_EN.md index 7c60fbcaa1474..9d8f91b526e06 100644 --- a/solution/0000-0099/0024.Swap Nodes in Pairs/README_EN.md +++ b/solution/0000-0099/0024.Swap Nodes in Pairs/README_EN.md @@ -67,6 +67,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -84,6 +86,8 @@ class Solution: return p ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -155,6 +163,8 @@ func swapPairs(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -180,6 +190,8 @@ function swapPairs(head: ListNode | null): ListNode | null { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -216,6 +228,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -240,6 +254,8 @@ var swapPairs = function (head) { }; ``` +#### Ruby + ```rb # Definition for singly-linked list. # class ListNode @@ -283,6 +299,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -302,6 +320,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -331,6 +351,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -361,6 +383,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -383,6 +407,8 @@ func swapPairs(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -410,6 +436,8 @@ function swapPairs(head: ListNode | null): ListNode | null { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -436,6 +464,8 @@ var swapPairs = function (head) { }; ``` +#### PHP + ```php # Definition for singly-linked list. # class ListNode { diff --git a/solution/0000-0099/0025.Reverse Nodes in k-Group/README.md b/solution/0000-0099/0025.Reverse Nodes in k-Group/README.md index cd9e9461f7703..fcdc139163f01 100644 --- a/solution/0000-0099/0025.Reverse Nodes in k-Group/README.md +++ b/solution/0000-0099/0025.Reverse Nodes in k-Group/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -103,6 +105,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -149,6 +153,8 @@ class Solution { } ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -185,6 +191,8 @@ func reverse(start, end *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -236,6 +244,8 @@ function reverse(head: ListNode, tail: ListNode) { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -294,6 +304,8 @@ impl Solution { } ``` +#### C# + ```cs /** * Definition for singly-linked list. @@ -345,6 +357,8 @@ public class Solution { } ``` +#### PHP + ```php # Definition for singly-linked list. # class ListNode { @@ -411,6 +425,8 @@ class Solution { +#### Go + ```go /** * Definition for singly-linked list. @@ -443,6 +459,8 @@ func reverse(start, end *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/0000-0099/0025.Reverse Nodes in k-Group/README_EN.md b/solution/0000-0099/0025.Reverse Nodes in k-Group/README_EN.md index 1be084898a7fe..30abf3f03033f 100644 --- a/solution/0000-0099/0025.Reverse Nodes in k-Group/README_EN.md +++ b/solution/0000-0099/0025.Reverse Nodes in k-Group/README_EN.md @@ -62,6 +62,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -96,6 +98,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -142,6 +146,8 @@ class Solution { } ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -178,6 +184,8 @@ func reverse(start, end *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -229,6 +237,8 @@ function reverse(head: ListNode, tail: ListNode) { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -287,6 +297,8 @@ impl Solution { } ``` +#### C# + ```cs /** * Definition for singly-linked list. @@ -338,6 +350,8 @@ public class Solution { } ``` +#### PHP + ```php # Definition for singly-linked list. # class ListNode { @@ -404,6 +418,8 @@ The time complexity is $O(n)$, and the space complexity is $O(\log_k n)$. Here, +#### Go + ```go /** * Definition for singly-linked list. @@ -436,6 +452,8 @@ func reverse(start, end *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/0000-0099/0026.Remove Duplicates from Sorted Array/README.md b/solution/0000-0099/0026.Remove Duplicates from Sorted Array/README.md index 101f21aad0cc7..dda26e8bdaea5 100644 --- a/solution/0000-0099/0026.Remove Duplicates from Sorted Array/README.md +++ b/solution/0000-0099/0026.Remove Duplicates from Sorted Array/README.md @@ -100,6 +100,8 @@ for (int i = 0; i < k; i++) { +#### Python3 + ```python class Solution: def removeDuplicates(self, nums: List[int]) -> int: @@ -111,6 +113,8 @@ class Solution: return k ``` +#### Java + ```java class Solution { public int removeDuplicates(int[] nums) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func removeDuplicates(nums []int) int { k := 0 @@ -153,6 +161,8 @@ func removeDuplicates(nums []int) int { } ``` +#### TypeScript + ```ts function removeDuplicates(nums: number[]): number { let k: number = 0; @@ -165,6 +175,8 @@ function removeDuplicates(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn remove_duplicates(nums: &mut Vec) -> i32 { @@ -180,6 +192,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -196,6 +210,8 @@ var removeDuplicates = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int RemoveDuplicates(int[] nums) { @@ -210,6 +226,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** @@ -238,6 +256,8 @@ class Solution { +#### C++ + ```cpp class Solution { public: diff --git a/solution/0000-0099/0026.Remove Duplicates from Sorted Array/README_EN.md b/solution/0000-0099/0026.Remove Duplicates from Sorted Array/README_EN.md index 072abbcaf0639..8ac890d1cd1c5 100644 --- a/solution/0000-0099/0026.Remove Duplicates from Sorted Array/README_EN.md +++ b/solution/0000-0099/0026.Remove Duplicates from Sorted Array/README_EN.md @@ -101,6 +101,8 @@ Similar problems: +#### Python3 + ```python class Solution: def removeDuplicates(self, nums: List[int]) -> int: @@ -112,6 +114,8 @@ class Solution: return k ``` +#### Java + ```java class Solution { public int removeDuplicates(int[] nums) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func removeDuplicates(nums []int) int { k := 0 @@ -154,6 +162,8 @@ func removeDuplicates(nums []int) int { } ``` +#### TypeScript + ```ts function removeDuplicates(nums: number[]): number { let k: number = 0; @@ -166,6 +176,8 @@ function removeDuplicates(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn remove_duplicates(nums: &mut Vec) -> i32 { @@ -181,6 +193,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -197,6 +211,8 @@ var removeDuplicates = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int RemoveDuplicates(int[] nums) { @@ -211,6 +227,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** @@ -239,6 +257,8 @@ class Solution { +#### C++ + ```cpp class Solution { public: diff --git a/solution/0000-0099/0027.Remove Element/README.md b/solution/0000-0099/0027.Remove Element/README.md index 10e7fad08f135..501d9e32b15e9 100644 --- a/solution/0000-0099/0027.Remove Element/README.md +++ b/solution/0000-0099/0027.Remove Element/README.md @@ -90,6 +90,8 @@ for (int i = 0; i < len; i++) { +#### Python3 + ```python class Solution: def removeElement(self, nums: List[int], val: int) -> int: @@ -101,6 +103,8 @@ class Solution: return k ``` +#### Java + ```java class Solution { public int removeElement(int[] nums, int val) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func removeElement(nums []int, val int) int { k := 0 @@ -143,6 +151,8 @@ func removeElement(nums []int, val int) int { } ``` +#### TypeScript + ```ts function removeElement(nums: number[], val: number): number { let k: number = 0; @@ -155,6 +165,8 @@ function removeElement(nums: number[], val: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn remove_element(nums: &mut Vec, val: i32) -> i32 { @@ -170,6 +182,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -187,6 +201,8 @@ var removeElement = function (nums, val) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0027.Remove Element/README_EN.md b/solution/0000-0099/0027.Remove Element/README_EN.md index cc3f24f78a42e..e033fd507fbbd 100644 --- a/solution/0000-0099/0027.Remove Element/README_EN.md +++ b/solution/0000-0099/0027.Remove Element/README_EN.md @@ -94,6 +94,8 @@ The time complexity is $O(n)$ and the space complexity is $O(1)$, where $n$ is t +#### Python3 + ```python class Solution: def removeElement(self, nums: List[int], val: int) -> int: @@ -105,6 +107,8 @@ class Solution: return k ``` +#### Java + ```java class Solution { public int removeElement(int[] nums, int val) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func removeElement(nums []int, val int) int { k := 0 @@ -147,6 +155,8 @@ func removeElement(nums []int, val int) int { } ``` +#### TypeScript + ```ts function removeElement(nums: number[], val: number): number { let k: number = 0; @@ -159,6 +169,8 @@ function removeElement(nums: number[], val: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn remove_element(nums: &mut Vec, val: i32) -> i32 { @@ -174,6 +186,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -191,6 +205,8 @@ var removeElement = function (nums, val) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0028.Find the Index of the First Occurrence in a String/README.md b/solution/0000-0099/0028.Find the Index of the First Occurrence in a String/README.md index 49687b4d29486..9e283fccefad5 100644 --- a/solution/0000-0099/0028.Find the Index of the First Occurrence in a String/README.md +++ b/solution/0000-0099/0028.Find the Index of the First Occurrence in a String/README.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def strStr(self, haystack: str, needle: str) -> int: @@ -72,6 +74,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int strStr(String haystack, String needle) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { private: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func strStr(haystack string, needle string) int { n, m := len(haystack), len(needle) @@ -167,6 +175,8 @@ func strStr(haystack string, needle string) int { } ``` +#### TypeScript + ```ts function strStr(haystack: string, needle: string): number { const m = haystack.length; @@ -187,6 +197,8 @@ function strStr(haystack: string, needle: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn str_str(haystack: String, needle: String) -> i32 { @@ -222,6 +234,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} haystack @@ -247,6 +261,8 @@ var strStr = function (haystack, needle) { }; ``` +#### C# + ```cs public class Solution { public int StrStr(string haystack, string needle) { @@ -264,6 +280,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** @@ -301,6 +319,8 @@ class Solution { +#### Go + ```go func strStr(haystack string, needle string) int { n, m := len(haystack), len(needle) @@ -331,6 +351,8 @@ func strStr(haystack string, needle string) int { } ``` +#### TypeScript + ```ts function strStr(haystack: string, needle: string): number { const m = haystack.length; diff --git a/solution/0000-0099/0028.Find the Index of the First Occurrence in a String/README_EN.md b/solution/0000-0099/0028.Find the Index of the First Occurrence in a String/README_EN.md index d6f7d25ffd8ae..56b6f3bd1b84a 100644 --- a/solution/0000-0099/0028.Find the Index of the First Occurrence in a String/README_EN.md +++ b/solution/0000-0099/0028.Find the Index of the First Occurrence in a String/README_EN.md @@ -60,6 +60,8 @@ Assuming the length of the string `haystack` is $n$ and the length of the string +#### Python3 + ```python class Solution: def strStr(self, haystack: str, needle: str) -> int: @@ -70,6 +72,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int strStr(String haystack, String needle) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { private: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func strStr(haystack string, needle string) int { n, m := len(haystack), len(needle) @@ -165,6 +173,8 @@ func strStr(haystack string, needle string) int { } ``` +#### TypeScript + ```ts function strStr(haystack: string, needle: string): number { const m = haystack.length; @@ -185,6 +195,8 @@ function strStr(haystack: string, needle: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn str_str(haystack: String, needle: String) -> i32 { @@ -220,6 +232,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} haystack @@ -245,6 +259,8 @@ var strStr = function (haystack, needle) { }; ``` +#### C# + ```cs public class Solution { public int StrStr(string haystack, string needle) { @@ -262,6 +278,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** @@ -299,6 +317,8 @@ Assuming the length of the string `haystack` is $n$ and the length of the string +#### Go + ```go func strStr(haystack string, needle string) int { n, m := len(haystack), len(needle) @@ -329,6 +349,8 @@ func strStr(haystack string, needle string) int { } ``` +#### TypeScript + ```ts function strStr(haystack: string, needle: string): number { const m = haystack.length; diff --git a/solution/0000-0099/0029.Divide Two Integers/README.md b/solution/0000-0099/0029.Divide Two Integers/README.md index f0a2d9bd10bc0..a3d56bdec2352 100644 --- a/solution/0000-0099/0029.Divide Two Integers/README.md +++ b/solution/0000-0099/0029.Divide Two Integers/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def divide(self, a: int, b: int) -> int: @@ -88,6 +90,8 @@ class Solution: return ans if sign else -ans ``` +#### Java + ```java class Solution { public int divide(int a, int b) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func divide(a int, b int) int { if b == 1 { @@ -181,6 +189,8 @@ func divide(a int, b int) int { } ``` +#### TypeScript + ```ts function divide(a: number, b: number): number { if (b === 1) { @@ -212,6 +222,8 @@ function divide(a: number, b: number): number { } ``` +#### C# + ```cs public class Solution { public int Divide(int a, int b) { @@ -240,6 +252,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0029.Divide Two Integers/README_EN.md b/solution/0000-0099/0029.Divide Two Integers/README_EN.md index f393aaabda541..cb2814dff7d73 100644 --- a/solution/0000-0099/0029.Divide Two Integers/README_EN.md +++ b/solution/0000-0099/0029.Divide Two Integers/README_EN.md @@ -66,6 +66,8 @@ Assuming the dividend is $a$ and the divisor is $b$, the time complexity is $O(\ +#### Python3 + ```python class Solution: def divide(self, a: int, b: int) -> int: @@ -88,6 +90,8 @@ class Solution: return ans if sign else -ans ``` +#### Java + ```java class Solution { public int divide(int a, int b) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func divide(a int, b int) int { if b == 1 { @@ -181,6 +189,8 @@ func divide(a int, b int) int { } ``` +#### TypeScript + ```ts function divide(a: number, b: number): number { if (b === 1) { @@ -212,6 +222,8 @@ function divide(a: number, b: number): number { } ``` +#### C# + ```cs public class Solution { public int Divide(int a, int b) { @@ -240,6 +252,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0030.Substring with Concatenation of All Words/README.md b/solution/0000-0099/0030.Substring with Concatenation of All Words/README.md index d4e2626f7dadb..5d9bfce5f8868 100644 --- a/solution/0000-0099/0030.Substring with Concatenation of All Words/README.md +++ b/solution/0000-0099/0030.Substring with Concatenation of All Words/README.md @@ -90,6 +90,8 @@ s 中没有子串长度为 16 并且等于 words 的任何顺序排列的连接 +#### Python3 + ```python class Solution: def findSubstring(self, s: str, words: List[str]) -> List[int]: @@ -121,6 +123,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List findSubstring(String s, String[] words) { @@ -162,6 +166,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -203,6 +209,8 @@ public: }; ``` +#### Go + ```go func findSubstring(s string, words []string) (ans []int) { cnt := map[string]int{} @@ -237,6 +245,8 @@ func findSubstring(s string, words []string) (ans []int) { } ``` +#### TypeScript + ```ts function findSubstring(s: string, words: string[]): number[] { const cnt: Map = new Map(); @@ -278,6 +288,8 @@ function findSubstring(s: string, words: string[]): number[] { } ``` +#### C# + ```cs public class Solution { public IList FindSubstring(string s, string[] words) { @@ -322,6 +334,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** @@ -388,6 +402,8 @@ class Solution { +#### C++ + ```cpp class Solution { public: diff --git a/solution/0000-0099/0030.Substring with Concatenation of All Words/README_EN.md b/solution/0000-0099/0030.Substring with Concatenation of All Words/README_EN.md index 50c2f4bede7c7..02dffbb52991e 100644 --- a/solution/0000-0099/0030.Substring with Concatenation of All Words/README_EN.md +++ b/solution/0000-0099/0030.Substring with Concatenation of All Words/README_EN.md @@ -96,6 +96,8 @@ The time complexity is $O(m \times k)$, and the space complexity is $O(n \times +#### Python3 + ```python class Solution: def findSubstring(self, s: str, words: List[str]) -> List[int]: @@ -127,6 +129,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List findSubstring(String s, String[] words) { @@ -168,6 +172,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -209,6 +215,8 @@ public: }; ``` +#### Go + ```go func findSubstring(s string, words []string) (ans []int) { cnt := map[string]int{} @@ -243,6 +251,8 @@ func findSubstring(s string, words []string) (ans []int) { } ``` +#### TypeScript + ```ts function findSubstring(s: string, words: string[]): number[] { const cnt: Map = new Map(); @@ -284,6 +294,8 @@ function findSubstring(s: string, words: string[]): number[] { } ``` +#### C# + ```cs public class Solution { public IList FindSubstring(string s, string[] words) { @@ -328,6 +340,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** @@ -394,6 +408,8 @@ class Solution { +#### C++ + ```cpp class Solution { public: diff --git a/solution/0000-0099/0031.Next Permutation/README.md b/solution/0000-0099/0031.Next Permutation/README.md index 256aeafb54055..bc35e97d32a66 100644 --- a/solution/0000-0099/0031.Next Permutation/README.md +++ b/solution/0000-0099/0031.Next Permutation/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def nextPermutation(self, nums: List[int]) -> None: @@ -94,6 +96,8 @@ class Solution: nums[i + 1 :] = nums[i + 1 :][::-1] ``` +#### Java + ```java class Solution { public void nextPermutation(int[] nums) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func nextPermutation(nums []int) { n := len(nums) @@ -168,6 +176,8 @@ func nextPermutation(nums []int) { } ``` +#### TypeScript + ```ts function nextPermutation(nums: number[]): void { const n = nums.length; @@ -189,6 +199,8 @@ function nextPermutation(nums: number[]): void { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -213,6 +225,8 @@ var nextPermutation = function (nums) { }; ``` +#### C# + ```cs public class Solution { public void NextPermutation(int[] nums) { @@ -242,6 +256,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0031.Next Permutation/README_EN.md b/solution/0000-0099/0031.Next Permutation/README_EN.md index 4ce5cf648be59..e68c6c6fefef1 100644 --- a/solution/0000-0099/0031.Next Permutation/README_EN.md +++ b/solution/0000-0099/0031.Next Permutation/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(n)$ and the space complexity is $O(1)$. Where $n$ is t +#### Python3 + ```python class Solution: def nextPermutation(self, nums: List[int]) -> None: @@ -92,6 +94,8 @@ class Solution: nums[i + 1 :] = nums[i + 1 :][::-1] ``` +#### Java + ```java class Solution { public void nextPermutation(int[] nums) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func nextPermutation(nums []int) { n := len(nums) @@ -166,6 +174,8 @@ func nextPermutation(nums []int) { } ``` +#### TypeScript + ```ts function nextPermutation(nums: number[]): void { const n = nums.length; @@ -187,6 +197,8 @@ function nextPermutation(nums: number[]): void { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -211,6 +223,8 @@ var nextPermutation = function (nums) { }; ``` +#### C# + ```cs public class Solution { public void NextPermutation(int[] nums) { @@ -240,6 +254,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0032.Longest Valid Parentheses/README.md b/solution/0000-0099/0032.Longest Valid Parentheses/README.md index d970bf6f45bb1..3e346ace42bb3 100644 --- a/solution/0000-0099/0032.Longest Valid Parentheses/README.md +++ b/solution/0000-0099/0032.Longest Valid Parentheses/README.md @@ -89,6 +89,8 @@ $$ +#### Python3 + ```python class Solution: def longestValidParentheses(self, s: str) -> int: @@ -105,6 +107,8 @@ class Solution: return max(f) ``` +#### Java + ```java class Solution { public int longestValidParentheses(String s) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func longestValidParentheses(s string) int { n := len(s) @@ -170,6 +178,8 @@ func longestValidParentheses(s string) int { } ``` +#### TypeScript + ```ts function longestValidParentheses(s: string): number { const n = s.length; @@ -190,6 +200,8 @@ function longestValidParentheses(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn longest_valid_parentheses(s: String) -> i32 { @@ -226,6 +238,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -250,6 +264,8 @@ var longestValidParentheses = function (s) { }; ``` +#### C# + ```cs public class Solution { public int LongestValidParentheses(string s) { @@ -296,6 +312,8 @@ public class Solution { +#### Python3 + ```python class Solution: def longestValidParentheses(self, s: str) -> int: @@ -313,6 +331,8 @@ class Solution: return ans ``` +#### Go + ```go func longestValidParentheses(s string) int { ans := 0 @@ -335,6 +355,8 @@ func longestValidParentheses(s string) int { } ``` +#### TypeScript + ```ts function longestValidParentheses(s: string): number { let max_length: number = 0; @@ -357,6 +379,8 @@ function longestValidParentheses(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn longest_valid_parentheses(s: String) -> i32 { @@ -379,6 +403,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -403,6 +429,8 @@ var longestValidParentheses = function (s) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0032.Longest Valid Parentheses/README_EN.md b/solution/0000-0099/0032.Longest Valid Parentheses/README_EN.md index 466dea2eead7d..5e644f686b175 100644 --- a/solution/0000-0099/0032.Longest Valid Parentheses/README_EN.md +++ b/solution/0000-0099/0032.Longest Valid Parentheses/README_EN.md @@ -87,6 +87,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python class Solution: def longestValidParentheses(self, s: str) -> int: @@ -103,6 +105,8 @@ class Solution: return max(f) ``` +#### Java + ```java class Solution { public int longestValidParentheses(String s) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func longestValidParentheses(s string) int { n := len(s) @@ -168,6 +176,8 @@ func longestValidParentheses(s string) int { } ``` +#### TypeScript + ```ts function longestValidParentheses(s: string): number { const n = s.length; @@ -188,6 +198,8 @@ function longestValidParentheses(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn longest_valid_parentheses(s: String) -> i32 { @@ -224,6 +236,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -248,6 +262,8 @@ var longestValidParentheses = function (s) { }; ``` +#### C# + ```cs public class Solution { public int LongestValidParentheses(string s) { @@ -295,6 +311,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python class Solution: def longestValidParentheses(self, s: str) -> int: @@ -312,6 +330,8 @@ class Solution: return ans ``` +#### Go + ```go func longestValidParentheses(s string) int { ans := 0 @@ -334,6 +354,8 @@ func longestValidParentheses(s string) int { } ``` +#### TypeScript + ```ts function longestValidParentheses(s: string): number { let max_length: number = 0; @@ -356,6 +378,8 @@ function longestValidParentheses(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn longest_valid_parentheses(s: String) -> i32 { @@ -378,6 +402,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -402,6 +428,8 @@ var longestValidParentheses = function (s) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0033.Search in Rotated Sorted Array/README.md b/solution/0000-0099/0033.Search in Rotated Sorted Array/README.md index 7654078d8dc31..77320242b4963 100644 --- a/solution/0000-0099/0033.Search in Rotated Sorted Array/README.md +++ b/solution/0000-0099/0033.Search in Rotated Sorted Array/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def search(self, nums: List[int], target: int) -> int: @@ -104,6 +106,8 @@ class Solution: return left if nums[left] == target else -1 ``` +#### Java + ```java class Solution { public int search(int[] nums, int target) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func search(nums []int, target int) int { n := len(nums) @@ -182,6 +190,8 @@ func search(nums []int, target int) int { } ``` +#### TypeScript + ```ts function search(nums: number[], target: number): number { const n = nums.length; @@ -207,6 +217,8 @@ function search(nums: number[], target: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn search(nums: Vec, target: i32) -> i32 { @@ -237,6 +249,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -267,6 +281,8 @@ var search = function (nums, target) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0033.Search in Rotated Sorted Array/README_EN.md b/solution/0000-0099/0033.Search in Rotated Sorted Array/README_EN.md index 5b7c296c85b6a..0826fedd5b185 100644 --- a/solution/0000-0099/0033.Search in Rotated Sorted Array/README_EN.md +++ b/solution/0000-0099/0033.Search in Rotated Sorted Array/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(\log n)$, where $n$ is the length of the array $nums$. +#### Python3 + ```python class Solution: def search(self, nums: List[int], target: int) -> int: @@ -92,6 +94,8 @@ class Solution: return left if nums[left] == target else -1 ``` +#### Java + ```java class Solution { public int search(int[] nums, int target) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func search(nums []int, target int) int { n := len(nums) @@ -170,6 +178,8 @@ func search(nums []int, target int) int { } ``` +#### TypeScript + ```ts function search(nums: number[], target: number): number { const n = nums.length; @@ -195,6 +205,8 @@ function search(nums: number[], target: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn search(nums: Vec, target: i32) -> i32 { @@ -225,6 +237,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -255,6 +269,8 @@ var search = function (nums, target) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/README.md b/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/README.md index cb9f24d4c90e1..8c5847c082f52 100644 --- a/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/README.md +++ b/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/README.md @@ -119,6 +119,8 @@ int search(int left, int right) { +#### Python3 + ```python class Solution: def searchRange(self, nums: List[int], target: int) -> List[int]: @@ -127,6 +129,8 @@ class Solution: return [-1, -1] if l == r else [l, r - 1] ``` +#### Java + ```java class Solution { public int[] searchRange(int[] nums, int target) { @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func searchRange(nums []int, target int) []int { l := sort.SearchInts(nums, target) @@ -173,6 +181,8 @@ func searchRange(nums []int, target int) []int { } ``` +#### TypeScript + ```ts function searchRange(nums: number[], target: number): number[] { const search = (x: number): number => { @@ -193,6 +203,8 @@ function searchRange(nums: number[], target: number): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn search_range(nums: Vec, target: i32) -> Vec { @@ -220,6 +232,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -246,6 +260,8 @@ var searchRange = function (nums, target) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/README_EN.md b/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/README_EN.md index 766fbaa51dfd6..e6488c4579ea2 100644 --- a/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/README_EN.md +++ b/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/README_EN.md @@ -109,6 +109,8 @@ Note that the advantage of these two templates is that they always keep the answ +#### Python3 + ```python class Solution: def searchRange(self, nums: List[int], target: int) -> List[int]: @@ -117,6 +119,8 @@ class Solution: return [-1, -1] if l == r else [l, r - 1] ``` +#### Java + ```java class Solution { public int[] searchRange(int[] nums, int target) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func searchRange(nums []int, target int) []int { l := sort.SearchInts(nums, target) @@ -163,6 +171,8 @@ func searchRange(nums []int, target int) []int { } ``` +#### TypeScript + ```ts function searchRange(nums: number[], target: number): number[] { const search = (x: number): number => { @@ -183,6 +193,8 @@ function searchRange(nums: number[], target: number): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn search_range(nums: Vec, target: i32) -> Vec { @@ -210,6 +222,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -236,6 +250,8 @@ var searchRange = function (nums, target) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0035.Search Insert Position/README.md b/solution/0000-0099/0035.Search Insert Position/README.md index adf713e2a81f3..2c01ec64fc9bb 100644 --- a/solution/0000-0099/0035.Search Insert Position/README.md +++ b/solution/0000-0099/0035.Search Insert Position/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def searchInsert(self, nums: List[int], target: int) -> int: @@ -82,6 +84,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int searchInsert(int[] nums, int target) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func searchInsert(nums []int, target int) int { left, right := 0, len(nums) @@ -131,6 +139,8 @@ func searchInsert(nums []int, target int) int { } ``` +#### Rust + ```rust use std::cmp::Ordering; impl Solution { @@ -156,6 +166,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -191,12 +203,16 @@ var searchInsert = function (nums, target) { +#### Python3 + ```python class Solution: def searchInsert(self, nums: List[int], target: int) -> int: return bisect_left(nums, target) ``` +#### Java + ```java class Solution { public int searchInsert(int[] nums, int target) { @@ -206,6 +222,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -215,12 +233,16 @@ public: }; ``` +#### Go + ```go func searchInsert(nums []int, target int) int { return sort.SearchInts(nums, target) } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0035.Search Insert Position/README_EN.md b/solution/0000-0099/0035.Search Insert Position/README_EN.md index 0c4650a8f88ba..38b3f1035fb59 100644 --- a/solution/0000-0099/0035.Search Insert Position/README_EN.md +++ b/solution/0000-0099/0035.Search Insert Position/README_EN.md @@ -67,6 +67,8 @@ The time complexity is $O(\log n)$, and the space complexity is $O(1)$. Here, $n +#### Python3 + ```python class Solution: def searchInsert(self, nums: List[int], target: int) -> int: @@ -80,6 +82,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int searchInsert(int[] nums, int target) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func searchInsert(nums []int, target int) int { left, right := 0, len(nums) @@ -129,6 +137,8 @@ func searchInsert(nums []int, target int) int { } ``` +#### Rust + ```rust use std::cmp::Ordering; impl Solution { @@ -154,6 +164,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -189,12 +201,16 @@ The time complexity is $O(\log n)$, where $n$ is the length of the array $nums$. +#### Python3 + ```python class Solution: def searchInsert(self, nums: List[int], target: int) -> int: return bisect_left(nums, target) ``` +#### Java + ```java class Solution { public int searchInsert(int[] nums, int target) { @@ -204,6 +220,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -213,12 +231,16 @@ public: }; ``` +#### Go + ```go func searchInsert(nums []int, target int) int { return sort.SearchInts(nums, target) } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0036.Valid Sudoku/README.md b/solution/0000-0099/0036.Valid Sudoku/README.md index 081dd5de0911b..6871ce88fc235 100644 --- a/solution/0000-0099/0036.Valid Sudoku/README.md +++ b/solution/0000-0099/0036.Valid Sudoku/README.md @@ -100,6 +100,8 @@ tags: +#### Python3 + ```python class Solution: def isValidSudoku(self, board: List[List[str]]) -> bool: @@ -121,6 +123,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isValidSudoku(char[][] board) { @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func isValidSudoku(board [][]byte) bool { row, col, sub := [9][9]bool{}, [9][9]bool{}, [9][9]bool{} @@ -196,6 +204,8 @@ func isValidSudoku(board [][]byte) bool { } ``` +#### TypeScript + ```ts function isValidSudoku(board: string[][]): boolean { const row: boolean[][] = Array.from({ length: 9 }, () => @@ -226,6 +236,8 @@ function isValidSudoku(board: string[][]): boolean { } ``` +#### JavaScript + ```js /** * @param {character[][]} board @@ -254,6 +266,8 @@ var isValidSudoku = function (board) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0036.Valid Sudoku/README_EN.md b/solution/0000-0099/0036.Valid Sudoku/README_EN.md index 3eb28c196b6c4..8f821a0fe54bb 100644 --- a/solution/0000-0099/0036.Valid Sudoku/README_EN.md +++ b/solution/0000-0099/0036.Valid Sudoku/README_EN.md @@ -96,6 +96,8 @@ The time complexity is $O(C)$ and the space complexity is $O(C)$, where $C$ is t +#### Python3 + ```python class Solution: def isValidSudoku(self, board: List[List[str]]) -> bool: @@ -117,6 +119,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isValidSudoku(char[][] board) { @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go func isValidSudoku(board [][]byte) bool { row, col, sub := [9][9]bool{}, [9][9]bool{}, [9][9]bool{} @@ -192,6 +200,8 @@ func isValidSudoku(board [][]byte) bool { } ``` +#### TypeScript + ```ts function isValidSudoku(board: string[][]): boolean { const row: boolean[][] = Array.from({ length: 9 }, () => @@ -222,6 +232,8 @@ function isValidSudoku(board: string[][]): boolean { } ``` +#### JavaScript + ```js /** * @param {character[][]} board @@ -250,6 +262,8 @@ var isValidSudoku = function (board) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0037.Sudoku Solver/README.md b/solution/0000-0099/0037.Sudoku Solver/README.md index 700605e63114b..cdf7fb0c4fec5 100644 --- a/solution/0000-0099/0037.Sudoku Solver/README.md +++ b/solution/0000-0099/0037.Sudoku Solver/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def solveSudoku(self, board: List[List[str]]) -> None: @@ -109,6 +111,8 @@ class Solution: dfs(0) ``` +#### Java + ```java class Solution { private boolean ok; @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp using pii = pair; @@ -198,6 +204,8 @@ public: }; ``` +#### Go + ```go func solveSudoku(board [][]byte) { var row, col [9][9]bool @@ -237,6 +245,8 @@ func solveSudoku(board [][]byte) { } ``` +#### C# + ```cs public class Solution { public void SolveSudoku(char[][] board) { @@ -371,6 +381,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0037.Sudoku Solver/README_EN.md b/solution/0000-0099/0037.Sudoku Solver/README_EN.md index a8210620522f7..220e08cf5c82b 100644 --- a/solution/0000-0099/0037.Sudoku Solver/README_EN.md +++ b/solution/0000-0099/0037.Sudoku Solver/README_EN.md @@ -68,6 +68,8 @@ The time complexity is $O(9^{81})$, and the space complexity is $O(9^2)$. +#### Python3 + ```python class Solution: def solveSudoku(self, board: List[List[str]]) -> None: @@ -101,6 +103,8 @@ class Solution: dfs(0) ``` +#### Java + ```java class Solution { private boolean ok; @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp using pii = pair; @@ -190,6 +196,8 @@ public: }; ``` +#### Go + ```go func solveSudoku(board [][]byte) { var row, col [9][9]bool @@ -229,6 +237,8 @@ func solveSudoku(board [][]byte) { } ``` +#### C# + ```cs public class Solution { public void SolveSudoku(char[][] board) { @@ -363,6 +373,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0038.Count and Say/README.md b/solution/0000-0099/0038.Count and Say/README.md index bbb97ee67c530..1aad9b2f9d2d2 100644 --- a/solution/0000-0099/0038.Count and Say/README.md +++ b/solution/0000-0099/0038.Count and Say/README.md @@ -89,6 +89,8 @@ countAndSay(4) = 读 "21" = 一 个 2 + 一 个 1 = "12" + "11" = "1211" +#### Python3 + ```python class Solution: def countAndSay(self, n: int) -> str: @@ -107,6 +109,8 @@ class Solution: return s ``` +#### Java + ```java class Solution { public String countAndSay(int n) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func countAndSay(n int) string { s := "1" @@ -171,6 +179,8 @@ func countAndSay(n int) string { } ``` +#### TypeScript + ```ts function countAndSay(n: number): string { let s = '1'; @@ -193,6 +203,8 @@ function countAndSay(n: number): string { } ``` +#### Rust + ```rust use std::iter::once; @@ -217,6 +229,8 @@ impl Solution { } ``` +#### JavaScript + ```js const countAndSay = function (n) { let s = '1'; @@ -240,6 +254,8 @@ const countAndSay = function (n) { }; ``` +#### C# + ```cs using System.Text; public class Solution { @@ -280,6 +296,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0038.Count and Say/README_EN.md b/solution/0000-0099/0038.Count and Say/README_EN.md index ae33d025d85b7..fc75074f1cdd4 100644 --- a/solution/0000-0099/0038.Count and Say/README_EN.md +++ b/solution/0000-0099/0038.Count and Say/README_EN.md @@ -89,6 +89,8 @@ Space Complexity: $O(m)$. +#### Python3 + ```python class Solution: def countAndSay(self, n: int) -> str: @@ -107,6 +109,8 @@ class Solution: return s ``` +#### Java + ```java class Solution { public String countAndSay(int n) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func countAndSay(n int) string { s := "1" @@ -171,6 +179,8 @@ func countAndSay(n int) string { } ``` +#### TypeScript + ```ts function countAndSay(n: number): string { let s = '1'; @@ -193,6 +203,8 @@ function countAndSay(n: number): string { } ``` +#### Rust + ```rust use std::iter::once; @@ -217,6 +229,8 @@ impl Solution { } ``` +#### JavaScript + ```js const countAndSay = function (n) { let s = '1'; @@ -240,6 +254,8 @@ const countAndSay = function (n) { }; ``` +#### C# + ```cs using System.Text; public class Solution { @@ -280,6 +296,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0039.Combination Sum/README.md b/solution/0000-0099/0039.Combination Sum/README.md index 2ec3d2d5f2c9a..175184c930a34 100644 --- a/solution/0000-0099/0039.Combination Sum/README.md +++ b/solution/0000-0099/0039.Combination Sum/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]: @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func combinationSum(candidates []int, target int) (ans [][]int) { sort.Ints(candidates) @@ -187,6 +195,8 @@ func combinationSum(candidates []int, target int) (ans [][]int) { } ``` +#### TypeScript + ```ts function combinationSum(candidates: number[], target: number): number[][] { candidates.sort((a, b) => a - b); @@ -211,6 +221,8 @@ function combinationSum(candidates: number[], target: number): number[][] { } ``` +#### Rust + ```rust impl Solution { fn dfs(i: usize, s: i32, candidates: &Vec, t: &mut Vec, ans: &mut Vec>) { @@ -237,6 +249,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { private List> ans = new List>(); @@ -281,6 +295,8 @@ public class Solution { +#### Python3 + ```python class Solution: def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]: @@ -302,6 +318,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -331,6 +349,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -357,6 +377,8 @@ public: }; ``` +#### Go + ```go func combinationSum(candidates []int, target int) (ans [][]int) { sort.Ints(candidates) @@ -380,6 +402,8 @@ func combinationSum(candidates []int, target int) (ans [][]int) { } ``` +#### TypeScript + ```ts function combinationSum(candidates: number[], target: number): number[][] { candidates.sort((a, b) => a - b); @@ -403,6 +427,8 @@ function combinationSum(candidates: number[], target: number): number[][] { } ``` +#### Rust + ```rust impl Solution { fn dfs(i: usize, s: i32, candidates: &Vec, t: &mut Vec, ans: &mut Vec>) { @@ -428,6 +454,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { private List> ans = new List>(); @@ -457,6 +485,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0039.Combination Sum/README_EN.md b/solution/0000-0099/0039.Combination Sum/README_EN.md index 6bcb4c40b73c8..0f2fb2d2206a0 100644 --- a/solution/0000-0099/0039.Combination Sum/README_EN.md +++ b/solution/0000-0099/0039.Combination Sum/README_EN.md @@ -85,6 +85,8 @@ Similar problems: +#### Python3 + ```python class Solution: def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]: @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func combinationSum(candidates []int, target int) (ans [][]int) { sort.Ints(candidates) @@ -187,6 +195,8 @@ func combinationSum(candidates []int, target int) (ans [][]int) { } ``` +#### TypeScript + ```ts function combinationSum(candidates: number[], target: number): number[][] { candidates.sort((a, b) => a - b); @@ -211,6 +221,8 @@ function combinationSum(candidates: number[], target: number): number[][] { } ``` +#### Rust + ```rust impl Solution { fn dfs(i: usize, s: i32, candidates: &Vec, t: &mut Vec, ans: &mut Vec>) { @@ -237,6 +249,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { private List> ans = new List>(); @@ -281,6 +295,8 @@ The time complexity is $O(2^n \times n)$, and the space complexity is $O(n)$. He +#### Python3 + ```python class Solution: def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]: @@ -302,6 +318,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -331,6 +349,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -357,6 +377,8 @@ public: }; ``` +#### Go + ```go func combinationSum(candidates []int, target int) (ans [][]int) { sort.Ints(candidates) @@ -380,6 +402,8 @@ func combinationSum(candidates []int, target int) (ans [][]int) { } ``` +#### TypeScript + ```ts function combinationSum(candidates: number[], target: number): number[][] { candidates.sort((a, b) => a - b); @@ -403,6 +427,8 @@ function combinationSum(candidates: number[], target: number): number[][] { } ``` +#### Rust + ```rust impl Solution { fn dfs(i: usize, s: i32, candidates: &Vec, t: &mut Vec, ans: &mut Vec>) { @@ -428,6 +454,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { private List> ans = new List>(); @@ -457,6 +485,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0040.Combination Sum II/README.md b/solution/0000-0099/0040.Combination Sum II/README.md index 2169f29d82c13..84e03629da740 100644 --- a/solution/0000-0099/0040.Combination Sum II/README.md +++ b/solution/0000-0099/0040.Combination Sum II/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def combinationSum2(self, candidates: List[int], target: int) -> List[List[int]]: @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func combinationSum2(candidates []int, target int) (ans [][]int) { sort.Ints(candidates) @@ -198,6 +206,8 @@ func combinationSum2(candidates []int, target int) (ans [][]int) { } ``` +#### TypeScript + ```ts function combinationSum2(candidates: number[], target: number): number[][] { candidates.sort((a, b) => a - b); @@ -225,6 +235,8 @@ function combinationSum2(candidates: number[], target: number): number[][] { } ``` +#### Rust + ```rust impl Solution { fn dfs(i: usize, s: i32, candidates: &Vec, t: &mut Vec, ans: &mut Vec>) { @@ -254,6 +266,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} candidates @@ -286,6 +300,8 @@ var combinationSum2 = function (candidates, target) { }; ``` +#### C# + ```cs public class Solution { private List> ans = new List>(); @@ -333,6 +349,8 @@ public class Solution { +#### Python3 + ```python class Solution: def combinationSum2(self, candidates: List[int], target: int) -> List[List[int]]: @@ -357,6 +375,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -390,6 +410,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -420,6 +442,8 @@ public: }; ``` +#### Go + ```go func combinationSum2(candidates []int, target int) (ans [][]int) { sort.Ints(candidates) @@ -447,6 +471,8 @@ func combinationSum2(candidates []int, target int) (ans [][]int) { } ``` +#### TypeScript + ```ts function combinationSum2(candidates: number[], target: number): number[][] { candidates.sort((a, b) => a - b); @@ -474,6 +500,8 @@ function combinationSum2(candidates: number[], target: number): number[][] { } ``` +#### Rust + ```rust impl Solution { fn dfs(mut i: usize, s: i32, candidates: &Vec, t: &mut Vec, ans: &mut Vec>) { @@ -503,6 +531,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} candidates @@ -535,6 +565,8 @@ var combinationSum2 = function (candidates, target) { }; ``` +#### C# + ```cs public class Solution { private List> ans = new List>(); @@ -568,6 +600,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0040.Combination Sum II/README_EN.md b/solution/0000-0099/0040.Combination Sum II/README_EN.md index 46d8cc4f7bdcc..3798e751db409 100644 --- a/solution/0000-0099/0040.Combination Sum II/README_EN.md +++ b/solution/0000-0099/0040.Combination Sum II/README_EN.md @@ -85,6 +85,8 @@ Similar problems: +#### Python3 + ```python class Solution: def combinationSum2(self, candidates: List[int], target: int) -> List[List[int]]: @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func combinationSum2(candidates []int, target int) (ans [][]int) { sort.Ints(candidates) @@ -198,6 +206,8 @@ func combinationSum2(candidates []int, target int) (ans [][]int) { } ``` +#### TypeScript + ```ts function combinationSum2(candidates: number[], target: number): number[][] { candidates.sort((a, b) => a - b); @@ -225,6 +235,8 @@ function combinationSum2(candidates: number[], target: number): number[][] { } ``` +#### Rust + ```rust impl Solution { fn dfs(i: usize, s: i32, candidates: &Vec, t: &mut Vec, ans: &mut Vec>) { @@ -254,6 +266,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} candidates @@ -286,6 +300,8 @@ var combinationSum2 = function (candidates, target) { }; ``` +#### C# + ```cs public class Solution { private List> ans = new List>(); @@ -333,6 +349,8 @@ The time complexity is $O(2^n \times n)$, and the space complexity is $O(n)$. He +#### Python3 + ```python class Solution: def combinationSum2(self, candidates: List[int], target: int) -> List[List[int]]: @@ -357,6 +375,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -390,6 +410,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -420,6 +442,8 @@ public: }; ``` +#### Go + ```go func combinationSum2(candidates []int, target int) (ans [][]int) { sort.Ints(candidates) @@ -447,6 +471,8 @@ func combinationSum2(candidates []int, target int) (ans [][]int) { } ``` +#### TypeScript + ```ts function combinationSum2(candidates: number[], target: number): number[][] { candidates.sort((a, b) => a - b); @@ -474,6 +500,8 @@ function combinationSum2(candidates: number[], target: number): number[][] { } ``` +#### Rust + ```rust impl Solution { fn dfs(mut i: usize, s: i32, candidates: &Vec, t: &mut Vec, ans: &mut Vec>) { @@ -503,6 +531,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} candidates @@ -535,6 +565,8 @@ var combinationSum2 = function (candidates, target) { }; ``` +#### C# + ```cs public class Solution { private List> ans = new List>(); @@ -568,6 +600,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0041.First Missing Positive/README.md b/solution/0000-0099/0041.First Missing Positive/README.md index a1123e0bc954e..b8cfef2dbafee 100644 --- a/solution/0000-0099/0041.First Missing Positive/README.md +++ b/solution/0000-0099/0041.First Missing Positive/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def firstMissingPositive(self, nums: List[int]) -> int: @@ -84,6 +86,8 @@ class Solution: return n + 1 ``` +#### Java + ```java class Solution { public int firstMissingPositive(int[] nums) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func firstMissingPositive(nums []int) int { n := len(nums) @@ -146,6 +154,8 @@ func firstMissingPositive(nums []int) int { } ``` +#### TypeScript + ```ts function firstMissingPositive(nums: number[]): number { const n = nums.length; @@ -164,6 +174,8 @@ function firstMissingPositive(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn first_missing_positive(mut nums: Vec) -> i32 { @@ -188,6 +200,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int FirstMissingPositive(int[] nums) { @@ -213,6 +227,8 @@ public class Solution { } ``` +#### C + ```c int firstMissingPositive(int* nums, int numsSize) { for (int i = 0; i < numsSize; ++i) { @@ -235,6 +251,8 @@ void swap(int* a, int* b) { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0041.First Missing Positive/README_EN.md b/solution/0000-0099/0041.First Missing Positive/README_EN.md index 5b135fb50f20b..2377aa7fb0236 100644 --- a/solution/0000-0099/0041.First Missing Positive/README_EN.md +++ b/solution/0000-0099/0041.First Missing Positive/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def firstMissingPositive(self, nums: List[int]) -> int: @@ -86,6 +88,8 @@ class Solution: return n + 1 ``` +#### Java + ```java class Solution { public int firstMissingPositive(int[] nums) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func firstMissingPositive(nums []int) int { n := len(nums) @@ -148,6 +156,8 @@ func firstMissingPositive(nums []int) int { } ``` +#### TypeScript + ```ts function firstMissingPositive(nums: number[]): number { const n = nums.length; @@ -166,6 +176,8 @@ function firstMissingPositive(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn first_missing_positive(mut nums: Vec) -> i32 { @@ -190,6 +202,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int FirstMissingPositive(int[] nums) { @@ -215,6 +229,8 @@ public class Solution { } ``` +#### C + ```c int firstMissingPositive(int* nums, int numsSize) { for (int i = 0; i < numsSize; ++i) { @@ -237,6 +253,8 @@ void swap(int* a, int* b) { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0042.Trapping Rain Water/README.md b/solution/0000-0099/0042.Trapping Rain Water/README.md index 182e03e6f17fb..8acb22f5eebb5 100644 --- a/solution/0000-0099/0042.Trapping Rain Water/README.md +++ b/solution/0000-0099/0042.Trapping Rain Water/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def trap(self, height: List[int]) -> int: @@ -77,6 +79,8 @@ class Solution: return sum(min(l, r) - h for l, r, h in zip(left, right, height)) ``` +#### Java + ```java class Solution { public int trap(int[] height) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func trap(height []int) (ans int) { n := len(height) @@ -136,6 +144,8 @@ func trap(height []int) (ans int) { } ``` +#### TypeScript + ```ts function trap(height: number[]): number { const n = height.length; @@ -153,6 +163,8 @@ function trap(height: number[]): number { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -182,6 +194,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int Trap(int[] height) { @@ -203,6 +217,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0042.Trapping Rain Water/README_EN.md b/solution/0000-0099/0042.Trapping Rain Water/README_EN.md index 3b8d7e33fe4fd..5ea2e5779ea05 100644 --- a/solution/0000-0099/0042.Trapping Rain Water/README_EN.md +++ b/solution/0000-0099/0042.Trapping Rain Water/README_EN.md @@ -61,6 +61,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def trap(self, height: List[int]) -> int: @@ -73,6 +75,8 @@ class Solution: return sum(min(l, r) - h for l, r, h in zip(left, right, height)) ``` +#### Java + ```java class Solution { public int trap(int[] height) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func trap(height []int) (ans int) { n := len(height) @@ -132,6 +140,8 @@ func trap(height []int) (ans int) { } ``` +#### TypeScript + ```ts function trap(height: number[]): number { const n = height.length; @@ -149,6 +159,8 @@ function trap(height: number[]): number { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -178,6 +190,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int Trap(int[] height) { @@ -199,6 +213,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0043.Multiply Strings/README.md b/solution/0000-0099/0043.Multiply Strings/README.md index 5049dfc18718e..08cfe94a36715 100644 --- a/solution/0000-0099/0043.Multiply Strings/README.md +++ b/solution/0000-0099/0043.Multiply Strings/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def multiply(self, num1: str, num2: str) -> str: @@ -90,6 +92,8 @@ class Solution: return "".join(str(x) for x in arr[i:]) ``` +#### Java + ```java class Solution { public String multiply(String num1, String num2) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func multiply(num1 string, num2 string) string { if num1 == "0" || num2 == "0" { @@ -179,6 +187,8 @@ func multiply(num1 string, num2 string) string { } ``` +#### TypeScript + ```ts function multiply(num1: string, num2: string): string { if (num1 === '0' || num2 === '0') { @@ -206,6 +216,8 @@ function multiply(num1: string, num2: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn multiply(num1: String, num2: String) -> String { @@ -238,6 +250,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public string Multiply(string num1, string num2) { @@ -277,6 +291,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0043.Multiply Strings/README_EN.md b/solution/0000-0099/0043.Multiply Strings/README_EN.md index 650ac3f9d517b..33a9f3536d714 100644 --- a/solution/0000-0099/0043.Multiply Strings/README_EN.md +++ b/solution/0000-0099/0043.Multiply Strings/README_EN.md @@ -64,6 +64,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m + n)$. +#### Python3 + ```python class Solution: def multiply(self, num1: str, num2: str) -> str: @@ -83,6 +85,8 @@ class Solution: return "".join(str(x) for x in arr[i:]) ``` +#### Java + ```java class Solution { public String multiply(String num1, String num2) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func multiply(num1 string, num2 string) string { if num1 == "0" || num2 == "0" { @@ -172,6 +180,8 @@ func multiply(num1 string, num2 string) string { } ``` +#### TypeScript + ```ts function multiply(num1: string, num2: string): string { if (num1 === '0' || num2 === '0') { @@ -199,6 +209,8 @@ function multiply(num1: string, num2: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn multiply(num1: String, num2: String) -> String { @@ -231,6 +243,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public string Multiply(string num1, string num2) { @@ -270,6 +284,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0044.Wildcard Matching/README.md b/solution/0000-0099/0044.Wildcard Matching/README.md index ab856b0a17014..af58b95316fb6 100644 --- a/solution/0000-0099/0044.Wildcard Matching/README.md +++ b/solution/0000-0099/0044.Wildcard Matching/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def isMatch(self, s: str, p: str) -> bool: @@ -106,6 +108,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private Boolean[][] f; @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go func isMatch(s string, p string) bool { m, n := len(s), len(p) @@ -206,6 +214,8 @@ func isMatch(s string, p string) bool { } ``` +#### TypeScript + ```ts function isMatch(s: string, p: string): boolean { const m = s.length; @@ -234,6 +244,8 @@ function isMatch(s: string, p: string): boolean { } ``` +#### C# + ```cs public class Solution { private bool?[,] f; @@ -294,6 +306,8 @@ public class Solution { +#### Python3 + ```python class Solution: def isMatch(self, s: str, p: str) -> bool: @@ -314,6 +328,8 @@ class Solution: return f[m][n] ``` +#### Java + ```java class Solution { public boolean isMatch(String s, String p) { @@ -340,6 +356,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -367,6 +385,8 @@ public: }; ``` +#### Go + ```go func isMatch(s string, p string) bool { m, n := len(s), len(p) @@ -393,6 +413,8 @@ func isMatch(s string, p string) bool { } ``` +#### TypeScript + ```ts function isMatch(s: string, p: string): boolean { const m: number = s.length; @@ -419,6 +441,8 @@ function isMatch(s: string, p: string): boolean { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0044.Wildcard Matching/README_EN.md b/solution/0000-0099/0044.Wildcard Matching/README_EN.md index dedb2872b9360..4bce7a87a5922 100644 --- a/solution/0000-0099/0044.Wildcard Matching/README_EN.md +++ b/solution/0000-0099/0044.Wildcard Matching/README_EN.md @@ -85,6 +85,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def isMatch(self, s: str, p: str) -> bool: @@ -101,6 +103,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private Boolean[][] f; @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func isMatch(s string, p string) bool { m, n := len(s), len(p) @@ -201,6 +209,8 @@ func isMatch(s string, p string) bool { } ``` +#### TypeScript + ```ts function isMatch(s: string, p: string): boolean { const m = s.length; @@ -229,6 +239,8 @@ function isMatch(s: string, p: string): boolean { } ``` +#### C# + ```cs public class Solution { private bool?[,] f; @@ -289,6 +301,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def isMatch(self, s: str, p: str) -> bool: @@ -309,6 +323,8 @@ class Solution: return f[m][n] ``` +#### Java + ```java class Solution { public boolean isMatch(String s, String p) { @@ -335,6 +351,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -362,6 +380,8 @@ public: }; ``` +#### Go + ```go func isMatch(s string, p string) bool { m, n := len(s), len(p) @@ -388,6 +408,8 @@ func isMatch(s string, p string) bool { } ``` +#### TypeScript + ```ts function isMatch(s: string, p: string): boolean { const m: number = s.length; @@ -414,6 +436,8 @@ function isMatch(s: string, p: string): boolean { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0045.Jump Game II/README.md b/solution/0000-0099/0045.Jump Game II/README.md index 8c57bb31c6738..3b89084ddd14a 100644 --- a/solution/0000-0099/0045.Jump Game II/README.md +++ b/solution/0000-0099/0045.Jump Game II/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def jump(self, nums: List[int]) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int jump(int[] nums) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func jump(nums []int) (ans int) { mx, last := 0, 0 @@ -140,6 +148,8 @@ func jump(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function jump(nums: number[]): number { let [ans, mx, last] = [0, 0, 0]; @@ -154,6 +164,8 @@ function jump(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn jump(nums: Vec) -> i32 { @@ -173,6 +185,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int Jump(int[] nums) { @@ -189,6 +203,8 @@ public class Solution { } ``` +#### C + ```c #define min(a, b) a < b ? a : b int jump(int* nums, int numsSize) { @@ -206,6 +222,8 @@ int jump(int* nums, int numsSize) { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0045.Jump Game II/README_EN.md b/solution/0000-0099/0045.Jump Game II/README_EN.md index 10f089170e600..4e1a30891520e 100644 --- a/solution/0000-0099/0045.Jump Game II/README_EN.md +++ b/solution/0000-0099/0045.Jump Game II/README_EN.md @@ -78,6 +78,8 @@ Similar problems: +#### Python3 + ```python class Solution: def jump(self, nums: List[int]) -> int: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int jump(int[] nums) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func jump(nums []int) (ans int) { mx, last := 0, 0 @@ -137,6 +145,8 @@ func jump(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function jump(nums: number[]): number { let [ans, mx, last] = [0, 0, 0]; @@ -151,6 +161,8 @@ function jump(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn jump(nums: Vec) -> i32 { @@ -170,6 +182,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int Jump(int[] nums) { @@ -186,6 +200,8 @@ public class Solution { } ``` +#### C + ```c #define min(a, b) a < b ? a : b int jump(int* nums, int numsSize) { @@ -203,6 +219,8 @@ int jump(int* nums, int numsSize) { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0046.Permutations/README.md b/solution/0000-0099/0046.Permutations/README.md index bf8ec47ff8a65..01cfaefb2f235 100644 --- a/solution/0000-0099/0046.Permutations/README.md +++ b/solution/0000-0099/0046.Permutations/README.md @@ -70,12 +70,16 @@ tags: +#### Python3 + ```python class Solution: def permute(self, nums: List[int]) -> List[List[int]]: return list(permutations(nums)) ``` +#### Python3 + ```python class Solution: def permute(self, nums: List[int]) -> List[List[int]]: @@ -98,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -130,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +166,8 @@ public: }; ``` +#### Go + ```go func permute(nums []int) (ans [][]int) { n := len(nums) @@ -183,6 +193,8 @@ func permute(nums []int) (ans [][]int) { } ``` +#### TypeScript + ```ts function permute(nums: number[]): number[][] { const n = nums.length; @@ -202,6 +214,8 @@ function permute(nums: number[]): number[][] { } ``` +#### Rust + ```rust impl Solution { fn dfs(i: usize, nums: &mut Vec, res: &mut Vec>) { @@ -225,6 +239,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -255,6 +271,8 @@ var permute = function (nums) { }; ``` +#### C# + ```cs public class Solution { public IList> Permute(int[] nums) { diff --git a/solution/0000-0099/0046.Permutations/README_EN.md b/solution/0000-0099/0046.Permutations/README_EN.md index 6395095377887..a49c7aa2567cf 100644 --- a/solution/0000-0099/0046.Permutations/README_EN.md +++ b/solution/0000-0099/0046.Permutations/README_EN.md @@ -57,12 +57,16 @@ Similar problems: +#### Python3 + ```python class Solution: def permute(self, nums: List[int]) -> List[List[int]]: return list(permutations(nums)) ``` +#### Python3 + ```python class Solution: def permute(self, nums: List[int]) -> List[List[int]]: @@ -85,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -117,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +153,8 @@ public: }; ``` +#### Go + ```go func permute(nums []int) (ans [][]int) { n := len(nums) @@ -170,6 +180,8 @@ func permute(nums []int) (ans [][]int) { } ``` +#### TypeScript + ```ts function permute(nums: number[]): number[][] { const n = nums.length; @@ -189,6 +201,8 @@ function permute(nums: number[]): number[][] { } ``` +#### Rust + ```rust impl Solution { fn dfs(i: usize, nums: &mut Vec, res: &mut Vec>) { @@ -212,6 +226,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -242,6 +258,8 @@ var permute = function (nums) { }; ``` +#### C# + ```cs public class Solution { public IList> Permute(int[] nums) { diff --git a/solution/0000-0099/0047.Permutations II/README.md b/solution/0000-0099/0047.Permutations II/README.md index 27ff9014a0fbf..1f70f7bdbd925 100644 --- a/solution/0000-0099/0047.Permutations II/README.md +++ b/solution/0000-0099/0047.Permutations II/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def permuteUnique(self, nums: List[int]) -> List[List[int]]: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func permuteUnique(nums []int) (ans [][]int) { sort.Ints(nums) @@ -187,6 +195,8 @@ func permuteUnique(nums []int) (ans [][]int) { } ``` +#### TypeScript + ```ts function permuteUnique(nums: number[]): number[][] { nums.sort((a, b) => a - b); @@ -214,6 +224,8 @@ function permuteUnique(nums: number[]): number[][] { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -243,6 +255,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { private List> ans = new List>(); diff --git a/solution/0000-0099/0047.Permutations II/README_EN.md b/solution/0000-0099/0047.Permutations II/README_EN.md index e13722faff528..f0beef94ee0a7 100644 --- a/solution/0000-0099/0047.Permutations II/README_EN.md +++ b/solution/0000-0099/0047.Permutations II/README_EN.md @@ -70,6 +70,8 @@ Similar problems: +#### Python3 + ```python class Solution: def permuteUnique(self, nums: List[int]) -> List[List[int]]: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func permuteUnique(nums []int) (ans [][]int) { sort.Ints(nums) @@ -185,6 +193,8 @@ func permuteUnique(nums []int) (ans [][]int) { } ``` +#### TypeScript + ```ts function permuteUnique(nums: number[]): number[][] { nums.sort((a, b) => a - b); @@ -212,6 +222,8 @@ function permuteUnique(nums: number[]): number[][] { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -241,6 +253,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { private List> ans = new List>(); diff --git a/solution/0000-0099/0048.Rotate Image/README.md b/solution/0000-0099/0048.Rotate Image/README.md index e1cdf19859ed2..b9e91ba9da144 100644 --- a/solution/0000-0099/0048.Rotate Image/README.md +++ b/solution/0000-0099/0048.Rotate Image/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def rotate(self, matrix: List[List[int]]) -> None: @@ -78,6 +80,8 @@ class Solution: matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] ``` +#### Java + ```java class Solution { public void rotate(int[][] matrix) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func rotate(matrix [][]int) { n := len(matrix) @@ -135,6 +143,8 @@ func rotate(matrix [][]int) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify matrix in-place instead. @@ -151,6 +161,8 @@ function rotate(matrix: number[][]): void { } ``` +#### Rust + ```rust impl Solution { pub fn rotate(matrix: &mut Vec>) { @@ -173,6 +185,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix @@ -188,6 +202,8 @@ var rotate = function (matrix) { }; ``` +#### C# + ```cs public class Solution { public void Rotate(int[][] matrix) { diff --git a/solution/0000-0099/0048.Rotate Image/README_EN.md b/solution/0000-0099/0048.Rotate Image/README_EN.md index 4402fed087300..afa7215e405b8 100644 --- a/solution/0000-0099/0048.Rotate Image/README_EN.md +++ b/solution/0000-0099/0048.Rotate Image/README_EN.md @@ -62,6 +62,8 @@ The time complexity is $O(n^2)$, where $n$ is the side length of the matrix. The +#### Python3 + ```python class Solution: def rotate(self, matrix: List[List[int]]) -> None: @@ -74,6 +76,8 @@ class Solution: matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] ``` +#### Java + ```java class Solution { public void rotate(int[][] matrix) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func rotate(matrix [][]int) { n := len(matrix) @@ -131,6 +139,8 @@ func rotate(matrix [][]int) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify matrix in-place instead. @@ -147,6 +157,8 @@ function rotate(matrix: number[][]): void { } ``` +#### Rust + ```rust impl Solution { pub fn rotate(matrix: &mut Vec>) { @@ -169,6 +181,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix @@ -184,6 +198,8 @@ var rotate = function (matrix) { }; ``` +#### C# + ```cs public class Solution { public void Rotate(int[][] matrix) { diff --git a/solution/0000-0099/0049.Group Anagrams/README.md b/solution/0000-0099/0049.Group Anagrams/README.md index 83c5df6fb5489..9767b3ebee38f 100644 --- a/solution/0000-0099/0049.Group Anagrams/README.md +++ b/solution/0000-0099/0049.Group Anagrams/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def groupAnagrams(self, strs: List[str]) -> List[List[str]]: @@ -90,6 +92,8 @@ class Solution: return list(d.values()) ``` +#### Java + ```java class Solution { public List> groupAnagrams(String[] strs) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func groupAnagrams(strs []string) (ans [][]string) { d := map[string][]string{} @@ -138,6 +146,8 @@ func groupAnagrams(strs []string) (ans [][]string) { } ``` +#### TypeScript + ```ts function groupAnagrams(strs: string[]): string[][] { const d: Map = new Map(); @@ -152,6 +162,8 @@ function groupAnagrams(strs: string[]): string[][] { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -174,6 +186,8 @@ impl Solution { } ``` +#### C# + ```cs using System.Collections.Generic; @@ -246,6 +260,8 @@ public class Solution { +#### Python3 + ```python class Solution: def groupAnagrams(self, strs: List[str]) -> List[List[str]]: @@ -258,6 +274,8 @@ class Solution: return list(d.values()) ``` +#### Java + ```java class Solution { public List> groupAnagrams(String[] strs) { @@ -281,6 +299,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -305,6 +325,8 @@ public: }; ``` +#### Go + ```go func groupAnagrams(strs []string) (ans [][]string) { d := map[[26]int][]string{} @@ -322,6 +344,8 @@ func groupAnagrams(strs []string) (ans [][]string) { } ``` +#### TypeScript + ```ts function groupAnagrams(strs: string[]): string[][] { const map = new Map(); diff --git a/solution/0000-0099/0049.Group Anagrams/README_EN.md b/solution/0000-0099/0049.Group Anagrams/README_EN.md index a5b7b64ee9600..2f82a01e52cca 100644 --- a/solution/0000-0099/0049.Group Anagrams/README_EN.md +++ b/solution/0000-0099/0049.Group Anagrams/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n\times k\times \log k)$, where $n$ and $k$ are the le +#### Python3 + ```python class Solution: def groupAnagrams(self, strs: List[str]) -> List[List[str]]: @@ -79,6 +81,8 @@ class Solution: return list(d.values()) ``` +#### Java + ```java class Solution { public List> groupAnagrams(String[] strs) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func groupAnagrams(strs []string) (ans [][]string) { d := map[string][]string{} @@ -127,6 +135,8 @@ func groupAnagrams(strs []string) (ans [][]string) { } ``` +#### TypeScript + ```ts function groupAnagrams(strs: string[]): string[][] { const d: Map = new Map(); @@ -141,6 +151,8 @@ function groupAnagrams(strs: string[]): string[][] { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -163,6 +175,8 @@ impl Solution { } ``` +#### C# + ```cs using System.Collections.Generic; @@ -235,6 +249,8 @@ The time complexity is $O(n\times (k + C))$, where $n$ and $k$ are the lengths o +#### Python3 + ```python class Solution: def groupAnagrams(self, strs: List[str]) -> List[List[str]]: @@ -247,6 +263,8 @@ class Solution: return list(d.values()) ``` +#### Java + ```java class Solution { public List> groupAnagrams(String[] strs) { @@ -270,6 +288,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -294,6 +314,8 @@ public: }; ``` +#### Go + ```go func groupAnagrams(strs []string) (ans [][]string) { d := map[[26]int][]string{} @@ -311,6 +333,8 @@ func groupAnagrams(strs []string) (ans [][]string) { } ``` +#### TypeScript + ```ts function groupAnagrams(strs: string[]): string[][] { const map = new Map(); diff --git a/solution/0000-0099/0050.Pow(x, n)/README.md b/solution/0000-0099/0050.Pow(x, n)/README.md index 6b1681d5f3fca..b8cc883f1ad0a 100644 --- a/solution/0000-0099/0050.Pow(x, n)/README.md +++ b/solution/0000-0099/0050.Pow(x, n)/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def myPow(self, x: float, n: int) -> float: @@ -84,6 +86,8 @@ class Solution: return qpow(x, n) if n >= 0 else 1 / qpow(x, -n) ``` +#### Java + ```java class Solution { public double myPow(double x, int n) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func myPow(x float64, n int) float64 { qpow := func(a float64, n int) float64 { @@ -141,6 +149,8 @@ func myPow(x float64, n int) float64 { } ``` +#### TypeScript + ```ts function myPow(x: number, n: number): number { const qpow = (a: number, n: number): number => { @@ -157,6 +167,8 @@ function myPow(x: number, n: number): number { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -186,6 +198,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} x @@ -207,6 +221,8 @@ var myPow = function (x, n) { }; ``` +#### C# + ```cs public class Solution { public double MyPow(double x, int n) { diff --git a/solution/0000-0099/0050.Pow(x, n)/README_EN.md b/solution/0000-0099/0050.Pow(x, n)/README_EN.md index 872715392cbcb..13e6ef41bc23f 100644 --- a/solution/0000-0099/0050.Pow(x, n)/README_EN.md +++ b/solution/0000-0099/0050.Pow(x, n)/README_EN.md @@ -67,6 +67,8 @@ The time complexity is $O(\log n)$, and the space complexity is $O(1)$. Here, $n +#### Python3 + ```python class Solution: def myPow(self, x: float, n: int) -> float: @@ -82,6 +84,8 @@ class Solution: return qpow(x, n) if n >= 0 else 1 / qpow(x, -n) ``` +#### Java + ```java class Solution { public double myPow(double x, int n) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func myPow(x float64, n int) float64 { qpow := func(a float64, n int) float64 { @@ -139,6 +147,8 @@ func myPow(x float64, n int) float64 { } ``` +#### TypeScript + ```ts function myPow(x: number, n: number): number { const qpow = (a: number, n: number): number => { @@ -155,6 +165,8 @@ function myPow(x: number, n: number): number { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -184,6 +196,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} x @@ -205,6 +219,8 @@ var myPow = function (x, n) { }; ``` +#### C# + ```cs public class Solution { public double MyPow(double x, int n) { diff --git a/solution/0000-0099/0051.N-Queens/README.md b/solution/0000-0099/0051.N-Queens/README.md index c37ce5299b778..ae33005ec06f3 100644 --- a/solution/0000-0099/0051.N-Queens/README.md +++ b/solution/0000-0099/0051.N-Queens/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def solveNQueens(self, n: int) -> List[List[str]]: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func solveNQueens(n int) (ans [][]string) { col := make([]int, n) @@ -211,6 +219,8 @@ func solveNQueens(n int) (ans [][]string) { } ``` +#### TypeScript + ```ts function solveNQueens(n: number): string[][] { const col: number[] = Array(n).fill(0); @@ -238,6 +248,8 @@ function solveNQueens(n: number): string[][] { } ``` +#### C# + ```cs public class Solution { private int n; diff --git a/solution/0000-0099/0051.N-Queens/README_EN.md b/solution/0000-0099/0051.N-Queens/README_EN.md index 407321b525210..b6e887eb3709f 100644 --- a/solution/0000-0099/0051.N-Queens/README_EN.md +++ b/solution/0000-0099/0051.N-Queens/README_EN.md @@ -68,6 +68,8 @@ The time complexity is $O(n^2 \times n!)$, and the space complexity is $O(n)$. H +#### Python3 + ```python class Solution: def solveNQueens(self, n: int) -> List[List[str]]: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go func solveNQueens(n int) (ans [][]string) { col := make([]int, n) @@ -203,6 +211,8 @@ func solveNQueens(n int) (ans [][]string) { } ``` +#### TypeScript + ```ts function solveNQueens(n: number): string[][] { const col: number[] = Array(n).fill(0); @@ -230,6 +240,8 @@ function solveNQueens(n: number): string[][] { } ``` +#### C# + ```cs public class Solution { private int n; diff --git a/solution/0000-0099/0052.N-Queens II/README.md b/solution/0000-0099/0052.N-Queens II/README.md index 69799957ba0c7..f78b7ece53879 100644 --- a/solution/0000-0099/0052.N-Queens II/README.md +++ b/solution/0000-0099/0052.N-Queens II/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def totalNQueens(self, n: int) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func totalNQueens(n int) (ans int) { cols := [10]bool{} @@ -184,6 +192,8 @@ func totalNQueens(n int) (ans int) { } ``` +#### TypeScript + ```ts function totalNQueens(n: number): number { const cols: boolean[] = Array(10).fill(false); @@ -210,6 +220,8 @@ function totalNQueens(n: number): number { } ``` +#### C# + ```cs public class Solution { public int TotalNQueens(int n) { diff --git a/solution/0000-0099/0052.N-Queens II/README_EN.md b/solution/0000-0099/0052.N-Queens II/README_EN.md index 406d97a53d423..58e24c33a6dfb 100644 --- a/solution/0000-0099/0052.N-Queens II/README_EN.md +++ b/solution/0000-0099/0052.N-Queens II/README_EN.md @@ -65,6 +65,8 @@ The time complexity is $O(n!)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def totalNQueens(self, n: int) -> int: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func totalNQueens(n int) (ans int) { cols := [10]bool{} @@ -178,6 +186,8 @@ func totalNQueens(n int) (ans int) { } ``` +#### TypeScript + ```ts function totalNQueens(n: number): number { const cols: boolean[] = Array(10).fill(false); @@ -204,6 +214,8 @@ function totalNQueens(n: number): number { } ``` +#### C# + ```cs public class Solution { public int TotalNQueens(int n) { diff --git a/solution/0000-0099/0053.Maximum Subarray/README.md b/solution/0000-0099/0053.Maximum Subarray/README.md index 75e0d231132bc..a2cdc37fc575c 100644 --- a/solution/0000-0099/0053.Maximum Subarray/README.md +++ b/solution/0000-0099/0053.Maximum Subarray/README.md @@ -87,6 +87,8 @@ $$ +#### Python3 + ```python class Solution: def maxSubArray(self, nums: List[int]) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxSubArray(int[] nums) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func maxSubArray(nums []int) int { ans, f := nums[0], nums[0] @@ -135,6 +143,8 @@ func maxSubArray(nums []int) int { } ``` +#### TypeScript + ```ts function maxSubArray(nums: number[]): number { let [ans, f] = [nums[0], nums[0]]; @@ -146,6 +156,8 @@ function maxSubArray(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_sub_array(nums: Vec) -> i32 { @@ -161,6 +173,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -176,6 +190,8 @@ var maxSubArray = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int MaxSubArray(int[] nums) { @@ -199,6 +215,8 @@ public class Solution { +#### Python3 + ```python class Solution: def maxSubArray(self, nums: List[int]) -> int: @@ -226,6 +244,8 @@ class Solution: return maxSub(nums, left, right) ``` +#### Java + ```java class Solution { public int maxSubArray(int[] nums) { diff --git a/solution/0000-0099/0053.Maximum Subarray/README_EN.md b/solution/0000-0099/0053.Maximum Subarray/README_EN.md index 2cda45ce4de73..81e71ba9450e3 100644 --- a/solution/0000-0099/0053.Maximum Subarray/README_EN.md +++ b/solution/0000-0099/0053.Maximum Subarray/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. We o +#### Python3 + ```python class Solution: def maxSubArray(self, nums: List[int]) -> int: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxSubArray(int[] nums) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func maxSubArray(nums []int) int { ans, f := nums[0], nums[0] @@ -132,6 +140,8 @@ func maxSubArray(nums []int) int { } ``` +#### TypeScript + ```ts function maxSubArray(nums: number[]): number { let [ans, f] = [nums[0], nums[0]]; @@ -143,6 +153,8 @@ function maxSubArray(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_sub_array(nums: Vec) -> i32 { @@ -158,6 +170,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -173,6 +187,8 @@ var maxSubArray = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int MaxSubArray(int[] nums) { @@ -196,6 +212,8 @@ public class Solution { +#### Python3 + ```python class Solution: def maxSubArray(self, nums: List[int]) -> int: @@ -223,6 +241,8 @@ class Solution: return maxSub(nums, left, right) ``` +#### Java + ```java class Solution { public int maxSubArray(int[] nums) { diff --git a/solution/0000-0099/0054.Spiral Matrix/README.md b/solution/0000-0099/0054.Spiral Matrix/README.md index 128694984f531..8518d2f75f7cb 100644 --- a/solution/0000-0099/0054.Spiral Matrix/README.md +++ b/solution/0000-0099/0054.Spiral Matrix/README.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def spiralOrder(self, matrix: List[List[int]]) -> List[int]: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List spiralOrder(int[][] matrix) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func spiralOrder(matrix [][]int) (ans []int) { m, n := len(matrix), len(matrix[0]) @@ -152,6 +160,8 @@ func spiralOrder(matrix [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function spiralOrder(matrix: number[][]): number[] { const m = matrix.length; @@ -174,6 +184,8 @@ function spiralOrder(matrix: number[][]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn spiral_order(matrix: Vec>) -> Vec { @@ -212,6 +224,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix @@ -238,6 +252,8 @@ var spiralOrder = function (matrix) { }; ``` +#### C# + ```cs public class Solution { public IList SpiralOrder(int[][] matrix) { @@ -274,6 +290,8 @@ public class Solution { +#### Python3 + ```python class Solution: def spiralOrder(self, matrix: List[List[int]]) -> List[int]: @@ -295,6 +313,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List spiralOrder(int[][] matrix) { @@ -321,6 +341,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -348,6 +370,8 @@ public: }; ``` +#### Go + ```go func spiralOrder(matrix [][]int) (ans []int) { m, n := len(matrix), len(matrix[0]) @@ -370,6 +394,8 @@ func spiralOrder(matrix [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function spiralOrder(matrix: number[][]): number[] { const m = matrix.length; @@ -396,6 +422,8 @@ function spiralOrder(matrix: number[][]): number[] { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix @@ -426,6 +454,8 @@ var spiralOrder = function (matrix) { }; ``` +#### C# + ```cs public class Solution { public IList SpiralOrder(int[][] matrix) { @@ -462,6 +492,8 @@ public class Solution { +#### Python3 + ```python class Solution: def spiralOrder(self, matrix: List[List[int]]) -> List[int]: @@ -483,6 +515,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List spiralOrder(int[][] matrix) { @@ -514,6 +548,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -544,6 +580,8 @@ public: }; ``` +#### Go + ```go func spiralOrder(matrix [][]int) (ans []int) { m, n := len(matrix), len(matrix[0]) @@ -570,6 +608,8 @@ func spiralOrder(matrix [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function spiralOrder(matrix: number[][]): number[] { const m = matrix.length; @@ -603,6 +643,8 @@ function spiralOrder(matrix: number[][]): number[] { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix @@ -640,6 +682,8 @@ var spiralOrder = function (matrix) { }; ``` +#### C# + ```cs public class Solution { public IList SpiralOrder(int[][] matrix) { diff --git a/solution/0000-0099/0054.Spiral Matrix/README_EN.md b/solution/0000-0099/0054.Spiral Matrix/README_EN.md index c81ecf627ba14..4cd50bbb1e344 100644 --- a/solution/0000-0099/0054.Spiral Matrix/README_EN.md +++ b/solution/0000-0099/0054.Spiral Matrix/README_EN.md @@ -61,6 +61,8 @@ For visited elements, we can also add a constant $300$ to their values, so we do +#### Python3 + ```python class Solution: def spiralOrder(self, matrix: List[List[int]]) -> List[int]: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List spiralOrder(int[][] matrix) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func spiralOrder(matrix [][]int) (ans []int) { m, n := len(matrix), len(matrix[0]) @@ -150,6 +158,8 @@ func spiralOrder(matrix [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function spiralOrder(matrix: number[][]): number[] { const m = matrix.length; @@ -172,6 +182,8 @@ function spiralOrder(matrix: number[][]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn spiral_order(matrix: Vec>) -> Vec { @@ -210,6 +222,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix @@ -236,6 +250,8 @@ var spiralOrder = function (matrix) { }; ``` +#### C# + ```cs public class Solution { public IList SpiralOrder(int[][] matrix) { @@ -272,6 +288,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(1)$. Here +#### Python3 + ```python class Solution: def spiralOrder(self, matrix: List[List[int]]) -> List[int]: @@ -293,6 +311,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List spiralOrder(int[][] matrix) { @@ -319,6 +339,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -346,6 +368,8 @@ public: }; ``` +#### Go + ```go func spiralOrder(matrix [][]int) (ans []int) { m, n := len(matrix), len(matrix[0]) @@ -368,6 +392,8 @@ func spiralOrder(matrix [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function spiralOrder(matrix: number[][]): number[] { const m = matrix.length; @@ -394,6 +420,8 @@ function spiralOrder(matrix: number[][]): number[] { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix @@ -424,6 +452,8 @@ var spiralOrder = function (matrix) { }; ``` +#### C# + ```cs public class Solution { public IList SpiralOrder(int[][] matrix) { @@ -460,6 +490,8 @@ public class Solution { +#### Python3 + ```python class Solution: def spiralOrder(self, matrix: List[List[int]]) -> List[int]: @@ -481,6 +513,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List spiralOrder(int[][] matrix) { @@ -512,6 +546,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -542,6 +578,8 @@ public: }; ``` +#### Go + ```go func spiralOrder(matrix [][]int) (ans []int) { m, n := len(matrix), len(matrix[0]) @@ -568,6 +606,8 @@ func spiralOrder(matrix [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function spiralOrder(matrix: number[][]): number[] { const m = matrix.length; @@ -601,6 +641,8 @@ function spiralOrder(matrix: number[][]): number[] { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix @@ -638,6 +680,8 @@ var spiralOrder = function (matrix) { }; ``` +#### C# + ```cs public class Solution { public IList SpiralOrder(int[][] matrix) { diff --git a/solution/0000-0099/0055.Jump Game/README.md b/solution/0000-0099/0055.Jump Game/README.md index 2aec648b94595..3428ee59ec1df 100644 --- a/solution/0000-0099/0055.Jump Game/README.md +++ b/solution/0000-0099/0055.Jump Game/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def canJump(self, nums: List[int]) -> bool: @@ -84,6 +86,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean canJump(int[] nums) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func canJump(nums []int) bool { mx := 0 @@ -128,6 +136,8 @@ func canJump(nums []int) bool { } ``` +#### TypeScript + ```ts function canJump(nums: number[]): boolean { let mx: number = 0; @@ -141,6 +151,8 @@ function canJump(nums: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -160,6 +172,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -177,6 +191,8 @@ var canJump = function (nums) { }; ``` +#### C# + ```cs public class Solution { public bool CanJump(int[] nums) { diff --git a/solution/0000-0099/0055.Jump Game/README_EN.md b/solution/0000-0099/0055.Jump Game/README_EN.md index 292fd4725384c..b4615666e474b 100644 --- a/solution/0000-0099/0055.Jump Game/README_EN.md +++ b/solution/0000-0099/0055.Jump Game/README_EN.md @@ -71,6 +71,8 @@ Similar problems: +#### Python3 + ```python class Solution: def canJump(self, nums: List[int]) -> bool: @@ -82,6 +84,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean canJump(int[] nums) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func canJump(nums []int) bool { mx := 0 @@ -126,6 +134,8 @@ func canJump(nums []int) bool { } ``` +#### TypeScript + ```ts function canJump(nums: number[]): boolean { let mx: number = 0; @@ -139,6 +149,8 @@ function canJump(nums: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -158,6 +170,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -175,6 +189,8 @@ var canJump = function (nums) { }; ``` +#### C# + ```cs public class Solution { public bool CanJump(int[] nums) { diff --git a/solution/0000-0099/0056.Merge Intervals/README.md b/solution/0000-0099/0056.Merge Intervals/README.md index 97f50f9c3c196..1aba55b7eb691 100644 --- a/solution/0000-0099/0056.Merge Intervals/README.md +++ b/solution/0000-0099/0056.Merge Intervals/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def merge(self, intervals: List[List[int]]) -> List[List[int]]: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] merge(int[][] intervals) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func merge(intervals [][]int) (ans [][]int) { sort.Slice(intervals, func(i, j int) bool { @@ -148,6 +156,8 @@ func merge(intervals [][]int) (ans [][]int) { } ``` +#### TypeScript + ```ts function merge(intervals: number[][]): number[][] { intervals.sort((a, b) => a[0] - b[0]); @@ -166,6 +176,8 @@ function merge(intervals: number[][]): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn merge(mut intervals: Vec>) -> Vec> { @@ -188,6 +200,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int[][] Merge(int[][] intervals) { @@ -219,6 +233,8 @@ public class Solution { +#### Python3 + ```python class Solution: def merge(self, intervals: List[List[int]]) -> List[List[int]]: @@ -232,6 +248,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] merge(int[][] intervals) { @@ -251,6 +269,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -270,6 +290,8 @@ public: }; ``` +#### Go + ```go func merge(intervals [][]int) (ans [][]int) { sort.Slice(intervals, func(i, j int) bool { return intervals[i][0] < intervals[j][0] }) @@ -285,6 +307,8 @@ func merge(intervals [][]int) (ans [][]int) { } ``` +#### TypeScript + ```ts function merge(intervals: number[][]): number[][] { intervals.sort((a, b) => a[0] - b[0]); @@ -300,6 +324,8 @@ function merge(intervals: number[][]): number[][] { } ``` +#### C# + ```cs public class Solution { public int[][] Merge(int[][] intervals) { @@ -328,6 +354,8 @@ public class Solution { +#### TypeScript + ```ts function merge(intervals: number[][]): number[][] { intervals.sort((a, b) => a[0] - b[0]); diff --git a/solution/0000-0099/0056.Merge Intervals/README_EN.md b/solution/0000-0099/0056.Merge Intervals/README_EN.md index 06b85ed4dca94..b9054ffdc18c5 100644 --- a/solution/0000-0099/0056.Merge Intervals/README_EN.md +++ b/solution/0000-0099/0056.Merge Intervals/README_EN.md @@ -68,6 +68,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def merge(self, intervals: List[List[int]]) -> List[List[int]]: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] merge(int[][] intervals) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func merge(intervals [][]int) (ans [][]int) { sort.Slice(intervals, func(i, j int) bool { @@ -147,6 +155,8 @@ func merge(intervals [][]int) (ans [][]int) { } ``` +#### TypeScript + ```ts function merge(intervals: number[][]): number[][] { intervals.sort((a, b) => a[0] - b[0]); @@ -165,6 +175,8 @@ function merge(intervals: number[][]): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn merge(mut intervals: Vec>) -> Vec> { @@ -187,6 +199,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int[][] Merge(int[][] intervals) { @@ -218,6 +232,8 @@ public class Solution { +#### Python3 + ```python class Solution: def merge(self, intervals: List[List[int]]) -> List[List[int]]: @@ -231,6 +247,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] merge(int[][] intervals) { @@ -250,6 +268,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -269,6 +289,8 @@ public: }; ``` +#### Go + ```go func merge(intervals [][]int) (ans [][]int) { sort.Slice(intervals, func(i, j int) bool { return intervals[i][0] < intervals[j][0] }) @@ -284,6 +306,8 @@ func merge(intervals [][]int) (ans [][]int) { } ``` +#### TypeScript + ```ts function merge(intervals: number[][]): number[][] { intervals.sort((a, b) => a[0] - b[0]); @@ -299,6 +323,8 @@ function merge(intervals: number[][]): number[][] { } ``` +#### C# + ```cs public class Solution { public int[][] Merge(int[][] intervals) { @@ -327,6 +353,8 @@ public class Solution { +#### TypeScript + ```ts function merge(intervals: number[][]): number[][] { intervals.sort((a, b) => a[0] - b[0]); diff --git a/solution/0000-0099/0057.Insert Interval/README.md b/solution/0000-0099/0057.Insert Interval/README.md index 44193ec11f32f..a96e528f13e66 100644 --- a/solution/0000-0099/0057.Insert Interval/README.md +++ b/solution/0000-0099/0057.Insert Interval/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def insert( @@ -87,6 +89,8 @@ class Solution: return merge(intervals) ``` +#### Java + ```java class Solution { public int[][] insert(int[][] intervals, int[] newInterval) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func insert(intervals [][]int, newInterval []int) [][]int { merge := func(intervals [][]int) (ans [][]int) { @@ -158,6 +166,8 @@ func insert(intervals [][]int, newInterval []int) [][]int { } ``` +#### TypeScript + ```ts function insert(intervals: number[][], newInterval: number[]): number[][] { const merge = (intervals: number[][]): number[][] => { @@ -178,6 +188,8 @@ function insert(intervals: number[][], newInterval: number[]): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn insert(intervals: Vec>, new_interval: Vec) -> Vec> { @@ -206,6 +218,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int[][] Insert(int[][] intervals, int[] newInterval) { @@ -253,6 +267,8 @@ public class Solution { +#### Python3 + ```python class Solution: def insert( @@ -277,6 +293,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] insert(int[][] intervals, int[] newInterval) { @@ -306,6 +324,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -336,6 +356,8 @@ public: }; ``` +#### Go + ```go func insert(intervals [][]int, newInterval []int) (ans [][]int) { st, ed := newInterval[0], newInterval[1] @@ -362,6 +384,8 @@ func insert(intervals [][]int, newInterval []int) (ans [][]int) { } ``` +#### TypeScript + ```ts function insert(intervals: number[][], newInterval: number[]): number[][] { let [st, ed] = newInterval; @@ -388,6 +412,8 @@ function insert(intervals: number[][], newInterval: number[]): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn insert(intervals: Vec>, new_interval: Vec) -> Vec> { @@ -419,6 +445,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int[][] Insert(int[][] intervals, int[] newInterval) { diff --git a/solution/0000-0099/0057.Insert Interval/README_EN.md b/solution/0000-0099/0057.Insert Interval/README_EN.md index 55b301d7c8c2f..adeec13dea511 100644 --- a/solution/0000-0099/0057.Insert Interval/README_EN.md +++ b/solution/0000-0099/0057.Insert Interval/README_EN.md @@ -66,6 +66,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def insert( @@ -85,6 +87,8 @@ class Solution: return merge(intervals) ``` +#### Java + ```java class Solution { public int[][] insert(int[][] intervals, int[] newInterval) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func insert(intervals [][]int, newInterval []int) [][]int { merge := func(intervals [][]int) (ans [][]int) { @@ -156,6 +164,8 @@ func insert(intervals [][]int, newInterval []int) [][]int { } ``` +#### TypeScript + ```ts function insert(intervals: number[][], newInterval: number[]): number[][] { const merge = (intervals: number[][]): number[][] => { @@ -176,6 +186,8 @@ function insert(intervals: number[][], newInterval: number[]): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn insert(intervals: Vec>, new_interval: Vec) -> Vec> { @@ -204,6 +216,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int[][] Insert(int[][] intervals, int[] newInterval) { @@ -251,6 +265,8 @@ The time complexity is $O(n)$, where $n$ is the number of intervals. Ignoring th +#### Python3 + ```python class Solution: def insert( @@ -275,6 +291,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] insert(int[][] intervals, int[] newInterval) { @@ -304,6 +322,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -334,6 +354,8 @@ public: }; ``` +#### Go + ```go func insert(intervals [][]int, newInterval []int) (ans [][]int) { st, ed := newInterval[0], newInterval[1] @@ -360,6 +382,8 @@ func insert(intervals [][]int, newInterval []int) (ans [][]int) { } ``` +#### TypeScript + ```ts function insert(intervals: number[][], newInterval: number[]): number[][] { let [st, ed] = newInterval; @@ -386,6 +410,8 @@ function insert(intervals: number[][], newInterval: number[]): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn insert(intervals: Vec>, new_interval: Vec) -> Vec> { @@ -417,6 +443,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int[][] Insert(int[][] intervals, int[] newInterval) { diff --git a/solution/0000-0099/0058.Length of Last Word/README.md b/solution/0000-0099/0058.Length of Last Word/README.md index 305240f313fd0..cce44837ebe0f 100644 --- a/solution/0000-0099/0058.Length of Last Word/README.md +++ b/solution/0000-0099/0058.Length of Last Word/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def lengthOfLastWord(self, s: str) -> int: @@ -82,6 +84,8 @@ class Solution: return i - j ``` +#### Java + ```java class Solution { public int lengthOfLastWord(String s) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func lengthOfLastWord(s string) int { i := len(s) - 1 @@ -129,6 +137,8 @@ func lengthOfLastWord(s string) int { } ``` +#### TypeScript + ```ts function lengthOfLastWord(s: string): number { let i = s.length - 1; @@ -143,6 +153,8 @@ function lengthOfLastWord(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn length_of_last_word(s: String) -> i32 { @@ -158,6 +170,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -176,6 +190,8 @@ var lengthOfLastWord = function (s) { }; ``` +#### C# + ```cs public class Solution { public int LengthOfLastWord(string s) { @@ -192,6 +208,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0058.Length of Last Word/README_EN.md b/solution/0000-0099/0058.Length of Last Word/README_EN.md index 9c0963dbf496f..36e3d9f44c5a5 100644 --- a/solution/0000-0099/0058.Length of Last Word/README_EN.md +++ b/solution/0000-0099/0058.Length of Last Word/README_EN.md @@ -68,6 +68,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string $s$. The sp +#### Python3 + ```python class Solution: def lengthOfLastWord(self, s: str) -> int: @@ -80,6 +82,8 @@ class Solution: return i - j ``` +#### Java + ```java class Solution { public int lengthOfLastWord(String s) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func lengthOfLastWord(s string) int { i := len(s) - 1 @@ -127,6 +135,8 @@ func lengthOfLastWord(s string) int { } ``` +#### TypeScript + ```ts function lengthOfLastWord(s: string): number { let i = s.length - 1; @@ -141,6 +151,8 @@ function lengthOfLastWord(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn length_of_last_word(s: String) -> i32 { @@ -156,6 +168,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -174,6 +188,8 @@ var lengthOfLastWord = function (s) { }; ``` +#### C# + ```cs public class Solution { public int LengthOfLastWord(string s) { @@ -190,6 +206,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0059.Spiral Matrix II/README.md b/solution/0000-0099/0059.Spiral Matrix II/README.md index 4e89d3a6305c2..b4e551233beb0 100644 --- a/solution/0000-0099/0059.Spiral Matrix II/README.md +++ b/solution/0000-0099/0059.Spiral Matrix II/README.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def generateMatrix(self, n: int) -> List[List[int]]: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] generateMatrix(int n) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func generateMatrix(n int) [][]int { ans := make([][]int, n) @@ -143,6 +151,8 @@ func generateMatrix(n int) [][]int { } ``` +#### TypeScript + ```ts function generateMatrix(n: number): number[][] { let ans = Array.from({ length: n }, v => new Array(n)); @@ -168,6 +178,8 @@ function generateMatrix(n: number): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn generate_matrix(n: i32) -> Vec> { @@ -200,6 +212,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -237,6 +251,8 @@ var generateMatrix = function (n) { +#### TypeScript + ```ts function generateMatrix(n: number): number[][] { const res = new Array(n).fill(0).map(() => new Array(n).fill(0)); diff --git a/solution/0000-0099/0059.Spiral Matrix II/README_EN.md b/solution/0000-0099/0059.Spiral Matrix II/README_EN.md index cb885073117d4..6268f4b14494e 100644 --- a/solution/0000-0099/0059.Spiral Matrix II/README_EN.md +++ b/solution/0000-0099/0059.Spiral Matrix II/README_EN.md @@ -60,6 +60,8 @@ The time complexity is $O(n^2)$, where $n$ is the side length of the matrix. Ign +#### Python3 + ```python class Solution: def generateMatrix(self, n: int) -> List[List[int]]: @@ -76,6 +78,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] generateMatrix(int n) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func generateMatrix(n int) [][]int { ans := make([][]int, n) @@ -141,6 +149,8 @@ func generateMatrix(n int) [][]int { } ``` +#### TypeScript + ```ts function generateMatrix(n: number): number[][] { let ans = Array.from({ length: n }, v => new Array(n)); @@ -166,6 +176,8 @@ function generateMatrix(n: number): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn generate_matrix(n: i32) -> Vec> { @@ -198,6 +210,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -235,6 +249,8 @@ var generateMatrix = function (n) { +#### TypeScript + ```ts function generateMatrix(n: number): number[][] { const res = new Array(n).fill(0).map(() => new Array(n).fill(0)); diff --git a/solution/0000-0099/0060.Permutation Sequence/README.md b/solution/0000-0099/0060.Permutation Sequence/README.md index 4efb2564f796f..0a68e9dad8553 100644 --- a/solution/0000-0099/0060.Permutation Sequence/README.md +++ b/solution/0000-0099/0060.Permutation Sequence/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def getPermutation(self, n: int, k: int) -> str: @@ -102,6 +104,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String getPermutation(int n, int k) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func getPermutation(n int, k int) string { ans := make([]byte, n) @@ -179,6 +187,8 @@ func getPermutation(n int, k int) string { } ``` +#### Rust + ```rust impl Solution { pub fn get_permutation(n: i32, k: i32) -> String { @@ -211,6 +221,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public string GetPermutation(int n, int k) { @@ -238,6 +250,8 @@ public class Solution { } ``` +#### TypeScript + ```ts function getPermutation(n: number, k: number): string { let ans = ''; diff --git a/solution/0000-0099/0060.Permutation Sequence/README_EN.md b/solution/0000-0099/0060.Permutation Sequence/README_EN.md index 07d0e984d6714..e3483705919ca 100644 --- a/solution/0000-0099/0060.Permutation Sequence/README_EN.md +++ b/solution/0000-0099/0060.Permutation Sequence/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def getPermutation(self, n: int, k: int) -> str: @@ -89,6 +91,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String getPermutation(int n, int k) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func getPermutation(n int, k int) string { ans := make([]byte, n) @@ -166,6 +174,8 @@ func getPermutation(n int, k int) string { } ``` +#### Rust + ```rust impl Solution { pub fn get_permutation(n: i32, k: i32) -> String { @@ -198,6 +208,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public string GetPermutation(int n, int k) { @@ -225,6 +237,8 @@ public class Solution { } ``` +#### TypeScript + ```ts function getPermutation(n: number, k: number): string { let ans = ''; diff --git a/solution/0000-0099/0061.Rotate List/README.md b/solution/0000-0099/0061.Rotate List/README.md index 3bbe23224fffa..d0a047ff33fec 100644 --- a/solution/0000-0099/0061.Rotate List/README.md +++ b/solution/0000-0099/0061.Rotate List/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -182,6 +188,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -219,6 +227,8 @@ func rotateRight(head *ListNode, k int) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -262,6 +272,8 @@ function rotateRight(head: ListNode | null, k: number): ListNode | null { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -313,6 +325,8 @@ impl Solution { } ``` +#### C# + ```cs /** * Definition for singly-linked list. diff --git a/solution/0000-0099/0061.Rotate List/README_EN.md b/solution/0000-0099/0061.Rotate List/README_EN.md index e7eb8f79790bd..f185d6b0e1c0e 100644 --- a/solution/0000-0099/0061.Rotate List/README_EN.md +++ b/solution/0000-0099/0061.Rotate List/README_EN.md @@ -65,6 +65,8 @@ The time complexity is $O(n)$, where $n$ is the number of nodes in the linked li +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -180,6 +186,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -217,6 +225,8 @@ func rotateRight(head *ListNode, k int) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -260,6 +270,8 @@ function rotateRight(head: ListNode | null, k: number): ListNode | null { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -311,6 +323,8 @@ impl Solution { } ``` +#### C# + ```cs /** * Definition for singly-linked list. diff --git a/solution/0000-0099/0062.Unique Paths/README.md b/solution/0000-0099/0062.Unique Paths/README.md index 8fa5178fc3d38..5f4413661b48a 100644 --- a/solution/0000-0099/0062.Unique Paths/README.md +++ b/solution/0000-0099/0062.Unique Paths/README.md @@ -98,6 +98,8 @@ $$ +#### Python3 + ```python class Solution: def uniquePaths(self, m: int, n: int) -> int: @@ -112,6 +114,8 @@ class Solution: return f[-1][-1] ``` +#### Java + ```java class Solution { public int uniquePaths(int m, int n) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func uniquePaths(m int, n int) int { f := make([][]int, m) @@ -174,6 +182,8 @@ func uniquePaths(m int, n int) int { } ``` +#### TypeScript + ```ts function uniquePaths(m: number, n: number): number { const f: number[][] = Array(m) @@ -194,6 +204,8 @@ function uniquePaths(m: number, n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn unique_paths(m: i32, n: i32) -> i32 { @@ -209,6 +221,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} m @@ -244,6 +258,8 @@ var uniquePaths = function (m, n) { +#### Python3 + ```python class Solution: def uniquePaths(self, m: int, n: int) -> int: @@ -254,6 +270,8 @@ class Solution: return f[-1][-1] ``` +#### Java + ```java class Solution { public int uniquePaths(int m, int n) { @@ -271,6 +289,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -286,6 +306,8 @@ public: }; ``` +#### Go + ```go func uniquePaths(m int, n int) int { f := make([][]int, m) @@ -304,6 +326,8 @@ func uniquePaths(m int, n int) int { } ``` +#### TypeScript + ```ts function uniquePaths(m: number, n: number): number { const f: number[][] = Array(m) @@ -318,6 +342,8 @@ function uniquePaths(m: number, n: number): number { } ``` +#### JavaScript + ```js /** * @param {number} m @@ -347,6 +373,8 @@ var uniquePaths = function (m, n) { +#### Python3 + ```python class Solution: def uniquePaths(self, m: int, n: int) -> int: @@ -357,6 +385,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int uniquePaths(int m, int n) { @@ -372,6 +402,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -387,6 +419,8 @@ public: }; ``` +#### Go + ```go func uniquePaths(m int, n int) int { f := make([]int, n+1) @@ -402,6 +436,8 @@ func uniquePaths(m int, n int) int { } ``` +#### TypeScript + ```ts function uniquePaths(m: number, n: number): number { const f: number[] = Array(n).fill(1); @@ -414,6 +450,8 @@ function uniquePaths(m: number, n: number): number { } ``` +#### JavaScript + ```js /** * @param {number} m diff --git a/solution/0000-0099/0062.Unique Paths/README_EN.md b/solution/0000-0099/0062.Unique Paths/README_EN.md index 76b7d3831350d..2c2321c934c29 100644 --- a/solution/0000-0099/0062.Unique Paths/README_EN.md +++ b/solution/0000-0099/0062.Unique Paths/README_EN.md @@ -82,6 +82,8 @@ We notice that $f[i][j]$ is only related to $f[i - 1][j]$ and $f[i][j - 1]$, so +#### Python3 + ```python class Solution: def uniquePaths(self, m: int, n: int) -> int: @@ -96,6 +98,8 @@ class Solution: return f[-1][-1] ``` +#### Java + ```java class Solution { public int uniquePaths(int m, int n) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func uniquePaths(m int, n int) int { f := make([][]int, m) @@ -158,6 +166,8 @@ func uniquePaths(m int, n int) int { } ``` +#### TypeScript + ```ts function uniquePaths(m: number, n: number): number { const f: number[][] = Array(m) @@ -178,6 +188,8 @@ function uniquePaths(m: number, n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn unique_paths(m: i32, n: i32) -> i32 { @@ -193,6 +205,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} m @@ -228,6 +242,8 @@ var uniquePaths = function (m, n) { +#### Python3 + ```python class Solution: def uniquePaths(self, m: int, n: int) -> int: @@ -238,6 +254,8 @@ class Solution: return f[-1][-1] ``` +#### Java + ```java class Solution { public int uniquePaths(int m, int n) { @@ -255,6 +273,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -270,6 +290,8 @@ public: }; ``` +#### Go + ```go func uniquePaths(m int, n int) int { f := make([][]int, m) @@ -288,6 +310,8 @@ func uniquePaths(m int, n int) int { } ``` +#### TypeScript + ```ts function uniquePaths(m: number, n: number): number { const f: number[][] = Array(m) @@ -302,6 +326,8 @@ function uniquePaths(m: number, n: number): number { } ``` +#### JavaScript + ```js /** * @param {number} m @@ -331,6 +357,8 @@ var uniquePaths = function (m, n) { +#### Python3 + ```python class Solution: def uniquePaths(self, m: int, n: int) -> int: @@ -341,6 +369,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int uniquePaths(int m, int n) { @@ -356,6 +386,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -371,6 +403,8 @@ public: }; ``` +#### Go + ```go func uniquePaths(m int, n int) int { f := make([]int, n+1) @@ -386,6 +420,8 @@ func uniquePaths(m int, n int) int { } ``` +#### TypeScript + ```ts function uniquePaths(m: number, n: number): number { const f: number[] = Array(n).fill(1); @@ -398,6 +434,8 @@ function uniquePaths(m: number, n: number): number { } ``` +#### JavaScript + ```js /** * @param {number} m diff --git a/solution/0000-0099/0063.Unique Paths II/README.md b/solution/0000-0099/0063.Unique Paths II/README.md index 0d682d9acf54f..bd6743990bcb9 100644 --- a/solution/0000-0099/0063.Unique Paths II/README.md +++ b/solution/0000-0099/0063.Unique Paths II/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int: @@ -94,6 +96,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private Integer[][] f; @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func uniquePathsWithObstacles(obstacleGrid [][]int) int { m, n := len(obstacleGrid), len(obstacleGrid[0]) @@ -175,6 +183,8 @@ func uniquePathsWithObstacles(obstacleGrid [][]int) int { } ``` +#### TypeScript + ```ts function uniquePathsWithObstacles(obstacleGrid: number[][]): number { const m = obstacleGrid.length; @@ -217,6 +227,8 @@ function uniquePathsWithObstacles(obstacleGrid: number[][]): number { +#### Python3 + ```python class Solution: def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int: @@ -237,6 +249,8 @@ class Solution: return f[-1][-1] ``` +#### Java + ```java class Solution { public int uniquePathsWithObstacles(int[][] obstacleGrid) { @@ -260,6 +274,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -284,6 +300,8 @@ public: }; ``` +#### Go + ```go func uniquePathsWithObstacles(obstacleGrid [][]int) int { m, n := len(obstacleGrid), len(obstacleGrid[0]) @@ -308,6 +326,8 @@ func uniquePathsWithObstacles(obstacleGrid [][]int) int { } ``` +#### TypeScript + ```ts function uniquePathsWithObstacles(obstacleGrid: number[][]): number { const m = obstacleGrid.length; @@ -337,6 +357,8 @@ function uniquePathsWithObstacles(obstacleGrid: number[][]): number { } ``` +#### TypeScript + ```ts function uniquePathsWithObstacles(obstacleGrid: number[][]): number { const m = obstacleGrid.length; @@ -358,6 +380,8 @@ function uniquePathsWithObstacles(obstacleGrid: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn unique_paths_with_obstacles(obstacle_grid: Vec>) -> i32 { diff --git a/solution/0000-0099/0063.Unique Paths II/README_EN.md b/solution/0000-0099/0063.Unique Paths II/README_EN.md index 7c1896efea877..9ea8e7ff71466 100644 --- a/solution/0000-0099/0063.Unique Paths II/README_EN.md +++ b/solution/0000-0099/0063.Unique Paths II/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int: @@ -92,6 +94,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private Integer[][] f; @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func uniquePathsWithObstacles(obstacleGrid [][]int) int { m, n := len(obstacleGrid), len(obstacleGrid[0]) @@ -173,6 +181,8 @@ func uniquePathsWithObstacles(obstacleGrid [][]int) int { } ``` +#### TypeScript + ```ts function uniquePathsWithObstacles(obstacleGrid: number[][]): number { const m = obstacleGrid.length; @@ -215,6 +225,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int: @@ -235,6 +247,8 @@ class Solution: return f[-1][-1] ``` +#### Java + ```java class Solution { public int uniquePathsWithObstacles(int[][] obstacleGrid) { @@ -258,6 +272,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -282,6 +298,8 @@ public: }; ``` +#### Go + ```go func uniquePathsWithObstacles(obstacleGrid [][]int) int { m, n := len(obstacleGrid), len(obstacleGrid[0]) @@ -306,6 +324,8 @@ func uniquePathsWithObstacles(obstacleGrid [][]int) int { } ``` +#### TypeScript + ```ts function uniquePathsWithObstacles(obstacleGrid: number[][]): number { const m = obstacleGrid.length; @@ -335,6 +355,8 @@ function uniquePathsWithObstacles(obstacleGrid: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn unique_paths_with_obstacles(obstacle_grid: Vec>) -> i32 { diff --git a/solution/0000-0099/0064.Minimum Path Sum/README.md b/solution/0000-0099/0064.Minimum Path Sum/README.md index 95492c716cce2..65f3ae1240cfc 100644 --- a/solution/0000-0099/0064.Minimum Path Sum/README.md +++ b/solution/0000-0099/0064.Minimum Path Sum/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def minPathSum(self, grid: List[List[int]]) -> int: @@ -88,6 +90,8 @@ class Solution: return f[-1][-1] ``` +#### Java + ```java class Solution { public int minPathSum(int[][] grid) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func minPathSum(grid [][]int) int { m, n := len(grid), len(grid[0]) @@ -156,6 +164,8 @@ func minPathSum(grid [][]int) int { } ``` +#### TypeScript + ```ts function minPathSum(grid: number[][]): number { const m = grid.length; @@ -179,6 +189,8 @@ function minPathSum(grid: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_path_sum(mut grid: Vec>) -> i32 { @@ -200,6 +212,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} grid @@ -227,6 +241,8 @@ var minPathSum = function (grid) { }; ``` +#### C# + ```cs public class Solution { public int MinPathSum(int[][] grid) { diff --git a/solution/0000-0099/0064.Minimum Path Sum/README_EN.md b/solution/0000-0099/0064.Minimum Path Sum/README_EN.md index 4fe8ec68c1923..ce84b74681558 100644 --- a/solution/0000-0099/0064.Minimum Path Sum/README_EN.md +++ b/solution/0000-0099/0064.Minimum Path Sum/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def minPathSum(self, grid: List[List[int]]) -> int: @@ -86,6 +88,8 @@ class Solution: return f[-1][-1] ``` +#### Java + ```java class Solution { public int minPathSum(int[][] grid) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func minPathSum(grid [][]int) int { m, n := len(grid), len(grid[0]) @@ -154,6 +162,8 @@ func minPathSum(grid [][]int) int { } ``` +#### TypeScript + ```ts function minPathSum(grid: number[][]): number { const m = grid.length; @@ -177,6 +187,8 @@ function minPathSum(grid: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_path_sum(mut grid: Vec>) -> i32 { @@ -198,6 +210,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} grid @@ -225,6 +239,8 @@ var minPathSum = function (grid) { }; ``` +#### C# + ```cs public class Solution { public int MinPathSum(int[][] grid) { diff --git a/solution/0000-0099/0065.Valid Number/README.md b/solution/0000-0099/0065.Valid Number/README.md index 8c48986af34cf..aec9076596a9f 100644 --- a/solution/0000-0099/0065.Valid Number/README.md +++ b/solution/0000-0099/0065.Valid Number/README.md @@ -107,6 +107,8 @@ tags: +#### Python3 + ```python class Solution: def isNumber(self, s: str) -> bool: @@ -139,6 +141,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isNumber(String s) { @@ -180,6 +184,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -208,6 +214,8 @@ public: }; ``` +#### Go + ```go func isNumber(s string) bool { i, n := 0, len(s) @@ -246,6 +254,8 @@ func isNumber(s string) bool { } ``` +#### Rust + ```rust impl Solution { pub fn is_number(s: String) -> bool { @@ -306,6 +316,8 @@ impl Solution { } ``` +#### C# + ```cs using System.Text.RegularExpressions; diff --git a/solution/0000-0099/0065.Valid Number/README_EN.md b/solution/0000-0099/0065.Valid Number/README_EN.md index e0cda62014848..434aa0a18abee 100644 --- a/solution/0000-0099/0065.Valid Number/README_EN.md +++ b/solution/0000-0099/0065.Valid Number/README_EN.md @@ -100,6 +100,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is +#### Python3 + ```python class Solution: def isNumber(self, s: str) -> bool: @@ -132,6 +134,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isNumber(String s) { @@ -173,6 +177,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -201,6 +207,8 @@ public: }; ``` +#### Go + ```go func isNumber(s string) bool { i, n := 0, len(s) @@ -239,6 +247,8 @@ func isNumber(s string) bool { } ``` +#### Rust + ```rust impl Solution { pub fn is_number(s: String) -> bool { @@ -299,6 +309,8 @@ impl Solution { } ``` +#### C# + ```cs using System.Text.RegularExpressions; diff --git a/solution/0000-0099/0066.Plus One/README.md b/solution/0000-0099/0066.Plus One/README.md index 272c4000fa9f8..8e92d53e6c143 100644 --- a/solution/0000-0099/0066.Plus One/README.md +++ b/solution/0000-0099/0066.Plus One/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def plusOne(self, digits: List[int]) -> List[int]: @@ -83,6 +85,8 @@ class Solution: return [1] + digits ``` +#### Java + ```java class Solution { public int[] plusOne(int[] digits) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func plusOne(digits []int) []int { n := len(digits) @@ -130,6 +138,8 @@ func plusOne(digits []int) []int { } ``` +#### TypeScript + ```ts function plusOne(digits: number[]): number[] { const n = digits.length; @@ -143,6 +153,8 @@ function plusOne(digits: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn plus_one(mut digits: Vec) -> Vec { @@ -160,6 +172,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} digits diff --git a/solution/0000-0099/0066.Plus One/README_EN.md b/solution/0000-0099/0066.Plus One/README_EN.md index 40d39febbf1a1..f2c963bc7ea00 100644 --- a/solution/0000-0099/0066.Plus One/README_EN.md +++ b/solution/0000-0099/0066.Plus One/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. Ignoring th +#### Python3 + ```python class Solution: def plusOne(self, digits: List[int]) -> List[int]: @@ -87,6 +89,8 @@ class Solution: return [1] + digits ``` +#### Java + ```java class Solution { public int[] plusOne(int[] digits) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func plusOne(digits []int) []int { n := len(digits) @@ -134,6 +142,8 @@ func plusOne(digits []int) []int { } ``` +#### TypeScript + ```ts function plusOne(digits: number[]): number[] { const n = digits.length; @@ -147,6 +157,8 @@ function plusOne(digits: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn plus_one(mut digits: Vec) -> Vec { @@ -164,6 +176,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} digits diff --git a/solution/0000-0099/0067.Add Binary/README.md b/solution/0000-0099/0067.Add Binary/README.md index f2fd8a0c387ae..14887b1d9590f 100644 --- a/solution/0000-0099/0067.Add Binary/README.md +++ b/solution/0000-0099/0067.Add Binary/README.md @@ -59,12 +59,16 @@ tags: +#### Python3 + ```python class Solution: def addBinary(self, a: str, b: str) -> str: return bin(int(a, 2) + int(b, 2))[2:] ``` +#### Java + ```java class Solution { public String addBinary(String a, String b) { @@ -80,6 +84,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -97,6 +103,8 @@ public: }; ``` +#### Go + ```go func addBinary(a string, b string) string { i, j := len(a)-1, len(b)-1 @@ -118,12 +126,16 @@ func addBinary(a string, b string) string { } ``` +#### TypeScript + ```ts function addBinary(a: string, b: string): string { return (BigInt('0b' + a) + BigInt('0b' + b)).toString(2); } ``` +#### Rust + ```rust impl Solution { pub fn add_binary(a: String, b: String) -> String { @@ -150,6 +162,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public string AddBinary(string a, string b) { @@ -179,6 +193,8 @@ public class Solution { +#### Python3 + ```python class Solution: def addBinary(self, a: str, b: str) -> str: @@ -192,6 +208,8 @@ class Solution: return ''.join(ans[::-1]) ``` +#### TypeScript + ```ts function addBinary(a: string, b: string): string { let i = a.length - 1; diff --git a/solution/0000-0099/0067.Add Binary/README_EN.md b/solution/0000-0099/0067.Add Binary/README_EN.md index cf018665a8f5a..f3fa6dca896dd 100644 --- a/solution/0000-0099/0067.Add Binary/README_EN.md +++ b/solution/0000-0099/0067.Add Binary/README_EN.md @@ -52,12 +52,16 @@ The time complexity is $O(\max(m, n))$, where $m$ and $n$ are the lengths of str +#### Python3 + ```python class Solution: def addBinary(self, a: str, b: str) -> str: return bin(int(a, 2) + int(b, 2))[2:] ``` +#### Java + ```java class Solution { public String addBinary(String a, String b) { @@ -73,6 +77,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -90,6 +96,8 @@ public: }; ``` +#### Go + ```go func addBinary(a string, b string) string { i, j := len(a)-1, len(b)-1 @@ -111,12 +119,16 @@ func addBinary(a string, b string) string { } ``` +#### TypeScript + ```ts function addBinary(a: string, b: string): string { return (BigInt('0b' + a) + BigInt('0b' + b)).toString(2); } ``` +#### Rust + ```rust impl Solution { pub fn add_binary(a: String, b: String) -> String { @@ -143,6 +155,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public string AddBinary(string a, string b) { @@ -172,6 +186,8 @@ public class Solution { +#### Python3 + ```python class Solution: def addBinary(self, a: str, b: str) -> str: @@ -185,6 +201,8 @@ class Solution: return ''.join(ans[::-1]) ``` +#### TypeScript + ```ts function addBinary(a: string, b: string): string { let i = a.length - 1; diff --git a/solution/0000-0099/0068.Text Justification/README.md b/solution/0000-0099/0068.Text Justification/README.md index a38a117a606fd..e7d285defab67 100644 --- a/solution/0000-0099/0068.Text Justification/README.md +++ b/solution/0000-0099/0068.Text Justification/README.md @@ -104,6 +104,8 @@ tags: +#### Python3 + ```python class Solution: def fullJustify(self, words: List[str], maxWidth: int) -> List[str]: @@ -134,6 +136,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List fullJustify(String[] words, int maxWidth) { @@ -169,6 +173,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -206,6 +212,8 @@ public: }; ``` +#### Go + ```go func fullJustify(words []string, maxWidth int) (ans []string) { for i, n := 0, len(words); i < n; { @@ -241,6 +249,8 @@ func fullJustify(words []string, maxWidth int) (ans []string) { } ``` +#### TypeScript + ```ts function fullJustify(words: string[], maxWidth: number): string[] { const ans: string[] = []; @@ -272,6 +282,8 @@ function fullJustify(words: string[], maxWidth: number): string[] { } ``` +#### C# + ```cs public class Solution { public IList FullJustify(string[] words, int maxWidth) { diff --git a/solution/0000-0099/0068.Text Justification/README_EN.md b/solution/0000-0099/0068.Text Justification/README_EN.md index 40f90722a7f7c..a95ee13808e7e 100644 --- a/solution/0000-0099/0068.Text Justification/README_EN.md +++ b/solution/0000-0099/0068.Text Justification/README_EN.md @@ -98,6 +98,8 @@ The time complexity is $O(L)$, and the space complexity is $O(L)$. Here, $L$ is +#### Python3 + ```python class Solution: def fullJustify(self, words: List[str], maxWidth: int) -> List[str]: @@ -128,6 +130,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List fullJustify(String[] words, int maxWidth) { @@ -163,6 +167,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -200,6 +206,8 @@ public: }; ``` +#### Go + ```go func fullJustify(words []string, maxWidth int) (ans []string) { for i, n := 0, len(words); i < n; { @@ -235,6 +243,8 @@ func fullJustify(words []string, maxWidth int) (ans []string) { } ``` +#### TypeScript + ```ts function fullJustify(words: string[], maxWidth: number): string[] { const ans: string[] = []; @@ -266,6 +276,8 @@ function fullJustify(words: string[], maxWidth: number): string[] { } ``` +#### C# + ```cs public class Solution { public IList FullJustify(string[] words, int maxWidth) { diff --git a/solution/0000-0099/0069.Sqrt(x)/README.md b/solution/0000-0099/0069.Sqrt(x)/README.md index f3423db4e2e35..d7a7a6ea05aa7 100644 --- a/solution/0000-0099/0069.Sqrt(x)/README.md +++ b/solution/0000-0099/0069.Sqrt(x)/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def mySqrt(self, x: int) -> int: @@ -79,6 +81,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { public int mySqrt(int x) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,12 +120,16 @@ public: }; ``` +#### Go + ```go func mySqrt(x int) int { return sort.Search(x+1, func(i int) bool { return i*i > x }) - 1 } ``` +#### Rust + ```rust impl Solution { pub fn my_sqrt(x: i32) -> i32 { @@ -141,6 +151,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} x @@ -160,6 +172,8 @@ var mySqrt = function (x) { }; ``` +#### C# + ```cs public class Solution { public int MySqrt(int x) { diff --git a/solution/0000-0099/0069.Sqrt(x)/README_EN.md b/solution/0000-0099/0069.Sqrt(x)/README_EN.md index 909c23ccdcc3f..9ad8f54472a03 100644 --- a/solution/0000-0099/0069.Sqrt(x)/README_EN.md +++ b/solution/0000-0099/0069.Sqrt(x)/README_EN.md @@ -67,6 +67,8 @@ The time complexity is $O(\log x)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def mySqrt(self, x: int) -> int: @@ -80,6 +82,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { public int mySqrt(int x) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,12 +121,16 @@ public: }; ``` +#### Go + ```go func mySqrt(x int) int { return sort.Search(x+1, func(i int) bool { return i*i > x }) - 1 } ``` +#### Rust + ```rust impl Solution { pub fn my_sqrt(x: i32) -> i32 { @@ -142,6 +152,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} x @@ -161,6 +173,8 @@ var mySqrt = function (x) { }; ``` +#### C# + ```cs public class Solution { public int MySqrt(int x) { diff --git a/solution/0000-0099/0070.Climbing Stairs/README.md b/solution/0000-0099/0070.Climbing Stairs/README.md index 1b9dd175f4c6f..e2c20cd366603 100644 --- a/solution/0000-0099/0070.Climbing Stairs/README.md +++ b/solution/0000-0099/0070.Climbing Stairs/README.md @@ -76,6 +76,8 @@ $$ +#### Python3 + ```python class Solution: def climbStairs(self, n: int) -> int: @@ -85,6 +87,8 @@ class Solution: return b ``` +#### Java + ```java class Solution { public int climbStairs(int n) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func climbStairs(n int) int { a, b := 0, 1 @@ -124,6 +132,8 @@ func climbStairs(n int) int { } ``` +#### TypeScript + ```ts function climbStairs(n: number): number { let p = 1; @@ -135,6 +145,8 @@ function climbStairs(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn climb_stairs(n: i32) -> i32 { @@ -149,6 +161,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -166,6 +180,8 @@ var climbStairs = function (n) { }; ``` +#### PHP + ```php class Solution { /** @@ -233,6 +249,8 @@ $$ +#### Python3 + ```python class Solution: def climbStairs(self, n: int) -> int: @@ -258,6 +276,8 @@ class Solution: return pow(a, n - 1)[0][0] ``` +#### Java + ```java class Solution { private final int[][] a = {{1, 1}, {1, 0}}; @@ -293,6 +313,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -329,6 +351,8 @@ private: }; ``` +#### Go + ```go type matrix [2][2]int @@ -362,6 +386,8 @@ func pow(a matrix, n int) matrix { } ``` +#### TypeScript + ```ts function climbStairs(n: number): number { const a = [ @@ -402,6 +428,8 @@ function pow(a: number[][], n: number): number[][] { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -456,6 +484,8 @@ function pow(a, n) { +#### Python3 + ```python import numpy as np diff --git a/solution/0000-0099/0070.Climbing Stairs/README_EN.md b/solution/0000-0099/0070.Climbing Stairs/README_EN.md index 4ec3a7376c132..855bc87fbc9d9 100644 --- a/solution/0000-0099/0070.Climbing Stairs/README_EN.md +++ b/solution/0000-0099/0070.Climbing Stairs/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def climbStairs(self, n: int) -> int: @@ -84,6 +86,8 @@ class Solution: return b ``` +#### Java + ```java class Solution { public int climbStairs(int n) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func climbStairs(n int) int { a, b := 0, 1 @@ -123,6 +131,8 @@ func climbStairs(n int) int { } ``` +#### TypeScript + ```ts function climbStairs(n: number): number { let p = 1; @@ -134,6 +144,8 @@ function climbStairs(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn climb_stairs(n: i32) -> i32 { @@ -148,6 +160,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -165,6 +179,8 @@ var climbStairs = function (n) { }; ``` +#### PHP + ```php class Solution { /** @@ -232,6 +248,8 @@ The time complexity is $O(\log n)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def climbStairs(self, n: int) -> int: @@ -257,6 +275,8 @@ class Solution: return pow(a, n - 1)[0][0] ``` +#### Java + ```java class Solution { private final int[][] a = {{1, 1}, {1, 0}}; @@ -292,6 +312,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -328,6 +350,8 @@ private: }; ``` +#### Go + ```go type matrix [2][2]int @@ -361,6 +385,8 @@ func pow(a matrix, n int) matrix { } ``` +#### TypeScript + ```ts function climbStairs(n: number): number { const a = [ @@ -401,6 +427,8 @@ function pow(a: number[][], n: number): number[][] { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -455,6 +483,8 @@ function pow(a, n) { +#### Python3 + ```python import numpy as np diff --git a/solution/0000-0099/0071.Simplify Path/README.md b/solution/0000-0099/0071.Simplify Path/README.md index 99cb3e826a5dd..4ea9bfda09e25 100644 --- a/solution/0000-0099/0071.Simplify Path/README.md +++ b/solution/0000-0099/0071.Simplify Path/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class Solution: def simplifyPath(self, path: str) -> str: @@ -109,6 +111,8 @@ class Solution: return '/' + '/'.join(stk) ``` +#### Java + ```java class Solution { public String simplifyPath(String path) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func simplifyPath(path string) string { var stk []string @@ -178,6 +186,8 @@ func simplifyPath(path string) string { } ``` +#### TypeScript + ```ts function simplifyPath(path: string): string { const stk: string[] = []; @@ -197,6 +207,8 @@ function simplifyPath(path: string): string { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -227,6 +239,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public string SimplifyPath(string path) { @@ -262,6 +276,8 @@ public class Solution { +#### Go + ```go func simplifyPath(path string) string { return filepath.Clean(path) diff --git a/solution/0000-0099/0071.Simplify Path/README_EN.md b/solution/0000-0099/0071.Simplify Path/README_EN.md index 8af0983727fca..9d900204626dd 100644 --- a/solution/0000-0099/0071.Simplify Path/README_EN.md +++ b/solution/0000-0099/0071.Simplify Path/README_EN.md @@ -124,6 +124,8 @@ The time complexity is $O(n)$ and the space complexity is $O(n)$, where $n$ is t +#### Python3 + ```python class Solution: def simplifyPath(self, path: str) -> str: @@ -139,6 +141,8 @@ class Solution: return '/' + '/'.join(stk) ``` +#### Java + ```java class Solution { public String simplifyPath(String path) { @@ -158,6 +162,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -189,6 +195,8 @@ public: }; ``` +#### Go + ```go func simplifyPath(path string) string { var stk []string @@ -208,6 +216,8 @@ func simplifyPath(path string) string { } ``` +#### TypeScript + ```ts function simplifyPath(path: string): string { const stk: string[] = []; @@ -227,6 +237,8 @@ function simplifyPath(path: string): string { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -257,6 +269,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public string SimplifyPath(string path) { @@ -292,6 +306,8 @@ public class Solution { +#### Go + ```go func simplifyPath(path string) string { return filepath.Clean(path) diff --git a/solution/0000-0099/0072.Edit Distance/README.md b/solution/0000-0099/0072.Edit Distance/README.md index 3a5bb695de5f6..404004165ea29 100644 --- a/solution/0000-0099/0072.Edit Distance/README.md +++ b/solution/0000-0099/0072.Edit Distance/README.md @@ -94,6 +94,8 @@ $$ +#### Python3 + ```python class Solution: def minDistance(self, word1: str, word2: str) -> int: @@ -111,6 +113,8 @@ class Solution: return f[m][n] ``` +#### Java + ```java class Solution { public int minDistance(String word1, String word2) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func minDistance(word1 string, word2 string) int { m, n := len(word1), len(word2) @@ -182,6 +190,8 @@ func minDistance(word1 string, word2 string) int { } ``` +#### TypeScript + ```ts function minDistance(word1: string, word2: string): number { const m = word1.length; @@ -206,6 +216,8 @@ function minDistance(word1: string, word2: string): number { } ``` +#### JavaScript + ```js /** * @param {string} word1 diff --git a/solution/0000-0099/0072.Edit Distance/README_EN.md b/solution/0000-0099/0072.Edit Distance/README_EN.md index 173ef991dfc48..cbac236faf701 100644 --- a/solution/0000-0099/0072.Edit Distance/README_EN.md +++ b/solution/0000-0099/0072.Edit Distance/README_EN.md @@ -92,6 +92,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def minDistance(self, word1: str, word2: str) -> int: @@ -109,6 +111,8 @@ class Solution: return f[m][n] ``` +#### Java + ```java class Solution { public int minDistance(String word1, String word2) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func minDistance(word1 string, word2 string) int { m, n := len(word1), len(word2) @@ -180,6 +188,8 @@ func minDistance(word1 string, word2 string) int { } ``` +#### TypeScript + ```ts function minDistance(word1: string, word2: string): number { const m = word1.length; @@ -204,6 +214,8 @@ function minDistance(word1: string, word2: string): number { } ``` +#### JavaScript + ```js /** * @param {string} word1 diff --git a/solution/0000-0099/0073.Set Matrix Zeroes/README.md b/solution/0000-0099/0073.Set Matrix Zeroes/README.md index e6718c93e0c05..06ebcdd85d874 100644 --- a/solution/0000-0099/0073.Set Matrix Zeroes/README.md +++ b/solution/0000-0099/0073.Set Matrix Zeroes/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def setZeroes(self, matrix: List[List[int]]) -> None: @@ -92,6 +94,8 @@ class Solution: matrix[i][j] = 0 ``` +#### Java + ```java class Solution { public void setZeroes(int[][] matrix) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func setZeroes(matrix [][]int) { m, n := len(matrix), len(matrix[0]) @@ -166,6 +174,8 @@ func setZeroes(matrix [][]int) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify matrix in-place instead. @@ -193,6 +203,8 @@ function setZeroes(matrix: number[][]): void { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix @@ -221,6 +233,8 @@ var setZeroes = function (matrix) { }; ``` +#### C# + ```cs public class Solution { public void SetZeroes(int[][] matrix) { @@ -261,6 +275,8 @@ public class Solution { +#### Python3 + ```python class Solution: def setZeroes(self, matrix: List[List[int]]) -> None: @@ -283,6 +299,8 @@ class Solution: matrix[i][0] = 0 ``` +#### Java + ```java class Solution { public void setZeroes(int[][] matrix) { @@ -329,6 +347,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -376,6 +396,8 @@ public: }; ``` +#### Go + ```go func setZeroes(matrix [][]int) { m, n := len(matrix), len(matrix[0]) @@ -419,6 +441,8 @@ func setZeroes(matrix [][]int) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify matrix in-place instead. @@ -454,6 +478,8 @@ function setZeroes(matrix: number[][]): void { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix @@ -498,6 +524,8 @@ var setZeroes = function (matrix) { }; ``` +#### C# + ```cs public class Solution { public void SetZeroes(int[][] matrix) { diff --git a/solution/0000-0099/0073.Set Matrix Zeroes/README_EN.md b/solution/0000-0099/0073.Set Matrix Zeroes/README_EN.md index 77a156a36f142..2585078f01d16 100644 --- a/solution/0000-0099/0073.Set Matrix Zeroes/README_EN.md +++ b/solution/0000-0099/0073.Set Matrix Zeroes/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(m\times n)$, and the space complexity is $O(m+n)$. Whe +#### Python3 + ```python class Solution: def setZeroes(self, matrix: List[List[int]]) -> None: @@ -88,6 +90,8 @@ class Solution: matrix[i][j] = 0 ``` +#### Java + ```java class Solution { public void setZeroes(int[][] matrix) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func setZeroes(matrix [][]int) { m, n := len(matrix), len(matrix[0]) @@ -162,6 +170,8 @@ func setZeroes(matrix [][]int) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify matrix in-place instead. @@ -189,6 +199,8 @@ function setZeroes(matrix: number[][]): void { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix @@ -217,6 +229,8 @@ var setZeroes = function (matrix) { }; ``` +#### C# + ```cs public class Solution { public void SetZeroes(int[][] matrix) { @@ -257,6 +271,8 @@ The time complexity is $O(m\times n)$, and the space complexity is $O(1)$. Where +#### Python3 + ```python class Solution: def setZeroes(self, matrix: List[List[int]]) -> None: @@ -279,6 +295,8 @@ class Solution: matrix[i][0] = 0 ``` +#### Java + ```java class Solution { public void setZeroes(int[][] matrix) { @@ -325,6 +343,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -372,6 +392,8 @@ public: }; ``` +#### Go + ```go func setZeroes(matrix [][]int) { m, n := len(matrix), len(matrix[0]) @@ -415,6 +437,8 @@ func setZeroes(matrix [][]int) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify matrix in-place instead. @@ -450,6 +474,8 @@ function setZeroes(matrix: number[][]): void { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix @@ -494,6 +520,8 @@ var setZeroes = function (matrix) { }; ``` +#### C# + ```cs public class Solution { public void SetZeroes(int[][] matrix) { diff --git a/solution/0000-0099/0074.Search a 2D Matrix/README.md b/solution/0000-0099/0074.Search a 2D Matrix/README.md index 19eb5dc10af63..0d7a2e3c3e9ec 100644 --- a/solution/0000-0099/0074.Search a 2D Matrix/README.md +++ b/solution/0000-0099/0074.Search a 2D Matrix/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: @@ -83,6 +85,8 @@ class Solution: return matrix[left // n][left % n] == target ``` +#### Java + ```java class Solution { public boolean searchMatrix(int[][] matrix, int target) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func searchMatrix(matrix [][]int, target int) bool { m, n := len(matrix), len(matrix[0]) @@ -139,6 +147,8 @@ func searchMatrix(matrix [][]int, target int) bool { } ``` +#### TypeScript + ```ts function searchMatrix(matrix: number[][], target: number): boolean { const m = matrix.length; @@ -163,6 +173,8 @@ function searchMatrix(matrix: number[][], target: number): boolean { } ``` +#### Rust + ```rust use std::cmp::Ordering; impl Solution { @@ -189,6 +201,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix @@ -234,6 +248,8 @@ var searchMatrix = function (matrix, target) { +#### Python3 + ```python class Solution: def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: @@ -249,6 +265,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean searchMatrix(int[][] matrix, int target) { @@ -268,6 +286,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -285,6 +305,8 @@ public: }; ``` +#### Go + ```go func searchMatrix(matrix [][]int, target int) bool { m, n := len(matrix), len(matrix[0]) @@ -302,6 +324,8 @@ func searchMatrix(matrix [][]int, target int) bool { } ``` +#### Rust + ```rust use std::cmp::Ordering; impl Solution { @@ -331,6 +355,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix diff --git a/solution/0000-0099/0074.Search a 2D Matrix/README_EN.md b/solution/0000-0099/0074.Search a 2D Matrix/README_EN.md index bd0746b909ae4..51cd28dbfea6d 100644 --- a/solution/0000-0099/0074.Search a 2D Matrix/README_EN.md +++ b/solution/0000-0099/0074.Search a 2D Matrix/README_EN.md @@ -68,6 +68,8 @@ The time complexity is $O(\log(m \times n))$, where $m$ and $n$ are the number o +#### Python3 + ```python class Solution: def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: @@ -83,6 +85,8 @@ class Solution: return matrix[left // n][left % n] == target ``` +#### Java + ```java class Solution { public boolean searchMatrix(int[][] matrix, int target) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func searchMatrix(matrix [][]int, target int) bool { m, n := len(matrix), len(matrix[0]) @@ -139,6 +147,8 @@ func searchMatrix(matrix [][]int, target int) bool { } ``` +#### TypeScript + ```ts function searchMatrix(matrix: number[][], target: number): boolean { const m = matrix.length; @@ -163,6 +173,8 @@ function searchMatrix(matrix: number[][], target: number): boolean { } ``` +#### Rust + ```rust use std::cmp::Ordering; impl Solution { @@ -189,6 +201,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix @@ -234,6 +248,8 @@ The time complexity is $O(m + n)$, where $m$ and $n$ are the number of rows and +#### Python3 + ```python class Solution: def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: @@ -249,6 +265,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean searchMatrix(int[][] matrix, int target) { @@ -268,6 +286,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -285,6 +305,8 @@ public: }; ``` +#### Go + ```go func searchMatrix(matrix [][]int, target int) bool { m, n := len(matrix), len(matrix[0]) @@ -302,6 +324,8 @@ func searchMatrix(matrix [][]int, target int) bool { } ``` +#### Rust + ```rust use std::cmp::Ordering; impl Solution { @@ -331,6 +355,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix diff --git a/solution/0000-0099/0075.Sort Colors/README.md b/solution/0000-0099/0075.Sort Colors/README.md index 94140ce7a011a..3cdb264d2e73e 100644 --- a/solution/0000-0099/0075.Sort Colors/README.md +++ b/solution/0000-0099/0075.Sort Colors/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def sortColors(self, nums: List[int]) -> None: @@ -99,6 +101,8 @@ class Solution: k += 1 ``` +#### Java + ```java class Solution { public void sortColors(int[] nums) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func sortColors(nums []int) { i, j, k := -1, len(nums), 0 @@ -158,6 +166,8 @@ func sortColors(nums []int) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify nums in-place instead. @@ -181,6 +191,8 @@ function sortColors(nums: number[]): void { } ``` +#### Rust + ```rust impl Solution { pub fn sort_colors(nums: &mut Vec) { @@ -203,6 +215,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public void SortColors(int[] nums) { diff --git a/solution/0000-0099/0075.Sort Colors/README_EN.md b/solution/0000-0099/0075.Sort Colors/README_EN.md index 27e72a3d8b591..4909d6373dae9 100644 --- a/solution/0000-0099/0075.Sort Colors/README_EN.md +++ b/solution/0000-0099/0075.Sort Colors/README_EN.md @@ -73,6 +73,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. Only one tr +#### Python3 + ```python class Solution: def sortColors(self, nums: List[int]) -> None: @@ -89,6 +91,8 @@ class Solution: k += 1 ``` +#### Java + ```java class Solution { public void sortColors(int[] nums) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func sortColors(nums []int) { i, j, k := -1, len(nums), 0 @@ -148,6 +156,8 @@ func sortColors(nums []int) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify nums in-place instead. @@ -171,6 +181,8 @@ function sortColors(nums: number[]): void { } ``` +#### Rust + ```rust impl Solution { pub fn sort_colors(nums: &mut Vec) { @@ -193,6 +205,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public void SortColors(int[] nums) { diff --git a/solution/0000-0099/0076.Minimum Window Substring/README.md b/solution/0000-0099/0076.Minimum Window Substring/README.md index b0c87e175ea83..e85a839437257 100644 --- a/solution/0000-0099/0076.Minimum Window Substring/README.md +++ b/solution/0000-0099/0076.Minimum Window Substring/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def minWindow(self, s: str, t: str) -> str: @@ -110,6 +112,8 @@ class Solution: return '' if k < 0 else s[k : k + mi] ``` +#### Java + ```java class Solution { public String minWindow(String s, String t) { @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go func minWindow(s string, t string) string { need := [128]int{} @@ -205,6 +213,8 @@ func minWindow(s string, t string) string { } ``` +#### TypeScript + ```ts function minWindow(s: string, t: string): string { const need: number[] = new Array(128).fill(0); @@ -236,6 +246,8 @@ function minWindow(s: string, t: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn min_window(s: String, t: String) -> String { @@ -272,6 +284,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public string MinWindow(string s, string t) { diff --git a/solution/0000-0099/0076.Minimum Window Substring/README_EN.md b/solution/0000-0099/0076.Minimum Window Substring/README_EN.md index 6a2f6d5002059..4f6a128dc9b0c 100644 --- a/solution/0000-0099/0076.Minimum Window Substring/README_EN.md +++ b/solution/0000-0099/0076.Minimum Window Substring/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(m + n)$, and the space complexity is $O(C)$. Here, $m$ +#### Python3 + ```python class Solution: def minWindow(self, s: str, t: str) -> str: @@ -102,6 +104,8 @@ class Solution: return '' if k < 0 else s[k : k + mi] ``` +#### Java + ```java class Solution { public String minWindow(String s, String t) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func minWindow(s string, t string) string { need := [128]int{} @@ -197,6 +205,8 @@ func minWindow(s string, t string) string { } ``` +#### TypeScript + ```ts function minWindow(s: string, t: string): string { const need: number[] = new Array(128).fill(0); @@ -228,6 +238,8 @@ function minWindow(s: string, t: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn min_window(s: String, t: String) -> String { @@ -264,6 +276,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public string MinWindow(string s, string t) { diff --git a/solution/0000-0099/0077.Combinations/README.md b/solution/0000-0099/0077.Combinations/README.md index 9755bd69840ce..24489ba852dda 100644 --- a/solution/0000-0099/0077.Combinations/README.md +++ b/solution/0000-0099/0077.Combinations/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def combine(self, n: int, k: int) -> List[List[int]]: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func combine(n int, k int) (ans [][]int) { t := []int{} @@ -178,6 +186,8 @@ func combine(n int, k int) (ans [][]int) { } ``` +#### TypeScript + ```ts function combine(n: number, k: number): number[][] { const ans: number[][] = []; @@ -200,6 +210,8 @@ function combine(n: number, k: number): number[][] { } ``` +#### Rust + ```rust impl Solution { fn dfs(i: i32, n: i32, k: i32, t: &mut Vec, ans: &mut Vec>) { @@ -224,6 +236,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { private List> ans = new List>(); @@ -264,6 +278,8 @@ public class Solution { +#### Python3 + ```python class Solution: def combine(self, n: int, k: int) -> List[List[int]]: @@ -284,6 +300,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -315,6 +333,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -341,6 +361,8 @@ public: }; ``` +#### Go + ```go func combine(n int, k int) (ans [][]int) { t := []int{} @@ -364,6 +386,8 @@ func combine(n int, k int) (ans [][]int) { } ``` +#### TypeScript + ```ts function combine(n: number, k: number): number[][] { const ans: number[][] = []; @@ -387,6 +411,8 @@ function combine(n: number, k: number): number[][] { } ``` +#### Rust + ```rust impl Solution { fn dfs(i: i32, n: i32, k: i32, t: &mut Vec, ans: &mut Vec>) { @@ -412,6 +438,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { private List> ans = new List>(); diff --git a/solution/0000-0099/0077.Combinations/README_EN.md b/solution/0000-0099/0077.Combinations/README_EN.md index eb52f5a986caf..73c7f5ecdff1c 100644 --- a/solution/0000-0099/0077.Combinations/README_EN.md +++ b/solution/0000-0099/0077.Combinations/README_EN.md @@ -76,6 +76,8 @@ Similar problems: +#### Python3 + ```python class Solution: def combine(self, n: int, k: int) -> List[List[int]]: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func combine(n int, k int) (ans [][]int) { t := []int{} @@ -173,6 +181,8 @@ func combine(n int, k int) (ans [][]int) { } ``` +#### TypeScript + ```ts function combine(n: number, k: number): number[][] { const ans: number[][] = []; @@ -195,6 +205,8 @@ function combine(n: number, k: number): number[][] { } ``` +#### Rust + ```rust impl Solution { fn dfs(i: i32, n: i32, k: i32, t: &mut Vec, ans: &mut Vec>) { @@ -219,6 +231,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { private List> ans = new List>(); @@ -259,6 +273,8 @@ public class Solution { +#### Python3 + ```python class Solution: def combine(self, n: int, k: int) -> List[List[int]]: @@ -279,6 +295,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -310,6 +328,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -336,6 +356,8 @@ public: }; ``` +#### Go + ```go func combine(n int, k int) (ans [][]int) { t := []int{} @@ -359,6 +381,8 @@ func combine(n int, k int) (ans [][]int) { } ``` +#### TypeScript + ```ts function combine(n: number, k: number): number[][] { const ans: number[][] = []; @@ -382,6 +406,8 @@ function combine(n: number, k: number): number[][] { } ``` +#### Rust + ```rust impl Solution { fn dfs(i: i32, n: i32, k: i32, t: &mut Vec, ans: &mut Vec>) { @@ -407,6 +433,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { private List> ans = new List>(); diff --git a/solution/0000-0099/0078.Subsets/README.md b/solution/0000-0099/0078.Subsets/README.md index 32717d73ba56e..5ca822064af4f 100644 --- a/solution/0000-0099/0078.Subsets/README.md +++ b/solution/0000-0099/0078.Subsets/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def subsets(self, nums: List[int]) -> List[List[int]]: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func subsets(nums []int) (ans [][]int) { t := []int{} @@ -151,6 +159,8 @@ func subsets(nums []int) (ans [][]int) { } ``` +#### TypeScript + ```ts function subsets(nums: number[]): number[][] { const ans: number[][] = []; @@ -170,6 +180,8 @@ function subsets(nums: number[]): number[][] { } ``` +#### Rust + ```rust impl Solution { fn dfs(i: usize, t: &mut Vec, res: &mut Vec>, nums: &Vec) { @@ -207,6 +219,8 @@ impl Solution { +#### Python3 + ```python class Solution: def subsets(self, nums: List[int]) -> List[List[int]]: @@ -217,6 +231,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> subsets(int[] nums) { @@ -236,6 +252,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -256,6 +274,8 @@ public: }; ``` +#### Go + ```go func subsets(nums []int) (ans [][]int) { n := len(nums) @@ -272,6 +292,8 @@ func subsets(nums []int) (ans [][]int) { } ``` +#### TypeScript + ```ts function subsets(nums: number[]): number[][] { const n = nums.length; diff --git a/solution/0000-0099/0078.Subsets/README_EN.md b/solution/0000-0099/0078.Subsets/README_EN.md index 369ec72ce03d6..29cc0451aa660 100644 --- a/solution/0000-0099/0078.Subsets/README_EN.md +++ b/solution/0000-0099/0078.Subsets/README_EN.md @@ -65,6 +65,8 @@ The time complexity is $O(n \times 2^n)$, and the space complexity is $O(n)$. He +#### Python3 + ```python class Solution: def subsets(self, nums: List[int]) -> List[List[int]]: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func subsets(nums []int) (ans [][]int) { t := []int{} @@ -149,6 +157,8 @@ func subsets(nums []int) (ans [][]int) { } ``` +#### TypeScript + ```ts function subsets(nums: number[]): number[][] { const ans: number[][] = []; @@ -168,6 +178,8 @@ function subsets(nums: number[]): number[][] { } ``` +#### Rust + ```rust impl Solution { fn dfs(i: usize, t: &mut Vec, res: &mut Vec>, nums: &Vec) { @@ -205,6 +217,8 @@ The time complexity is $O(n \times 2^n)$, and the space complexity is $O(n)$. He +#### Python3 + ```python class Solution: def subsets(self, nums: List[int]) -> List[List[int]]: @@ -215,6 +229,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> subsets(int[] nums) { @@ -234,6 +250,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -254,6 +272,8 @@ public: }; ``` +#### Go + ```go func subsets(nums []int) (ans [][]int) { n := len(nums) @@ -270,6 +290,8 @@ func subsets(nums []int) (ans [][]int) { } ``` +#### TypeScript + ```ts function subsets(nums: number[]): number[][] { const n = nums.length; diff --git a/solution/0000-0099/0079.Word Search/README.md b/solution/0000-0099/0079.Word Search/README.md index e6541adf4a147..9c98571dd64fc 100644 --- a/solution/0000-0099/0079.Word Search/README.md +++ b/solution/0000-0099/0079.Word Search/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def exist(self, board: List[List[str]], word: str) -> bool: @@ -106,6 +108,8 @@ class Solution: return any(dfs(i, j, 0) for i in range(m) for j in range(n)) ``` +#### Java + ```java class Solution { private int m; @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go func exist(board [][]byte, word string) bool { m, n := len(board), len(board[0]) @@ -220,6 +228,8 @@ func exist(board [][]byte, word string) bool { } ``` +#### TypeScript + ```ts function exist(board: string[][], word: string): boolean { const [m, n] = [board.length, board[0].length]; @@ -254,6 +264,8 @@ function exist(board: string[][], word: string): boolean { } ``` +#### Rust + ```rust impl Solution { fn dfs( @@ -309,6 +321,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { private int m; diff --git a/solution/0000-0099/0079.Word Search/README_EN.md b/solution/0000-0099/0079.Word Search/README_EN.md index 6a8f2627b5521..997bd0986d218 100644 --- a/solution/0000-0099/0079.Word Search/README_EN.md +++ b/solution/0000-0099/0079.Word Search/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(m \times n \times 3^k)$, and the space complexity is $ +#### Python3 + ```python class Solution: def exist(self, board: List[List[str]], word: str) -> bool: @@ -103,6 +105,8 @@ class Solution: return any(dfs(i, j, 0) for i in range(m) for j in range(n)) ``` +#### Java + ```java class Solution { private int m; @@ -147,6 +151,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -183,6 +189,8 @@ public: }; ``` +#### Go + ```go func exist(board [][]byte, word string) bool { m, n := len(board), len(board[0]) @@ -217,6 +225,8 @@ func exist(board [][]byte, word string) bool { } ``` +#### TypeScript + ```ts function exist(board: string[][], word: string): boolean { const [m, n] = [board.length, board[0].length]; @@ -251,6 +261,8 @@ function exist(board: string[][], word: string): boolean { } ``` +#### Rust + ```rust impl Solution { fn dfs( @@ -306,6 +318,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { private int m; diff --git a/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/README.md b/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/README.md index 0fdfa04f7fd91..753401baf32db 100644 --- a/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/README.md +++ b/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/README.md @@ -99,6 +99,8 @@ for (int i = 0; i < len; i++) { +#### Python3 + ```python class Solution: def removeDuplicates(self, nums: List[int]) -> int: @@ -110,6 +112,8 @@ class Solution: return k ``` +#### Java + ```java class Solution { public int removeDuplicates(int[] nums) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func removeDuplicates(nums []int) int { k := 0 @@ -152,6 +160,8 @@ func removeDuplicates(nums []int) int { } ``` +#### TypeScript + ```ts function removeDuplicates(nums: number[]): number { let k = 0; @@ -164,6 +174,8 @@ function removeDuplicates(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn remove_duplicates(nums: &mut Vec) -> i32 { @@ -179,6 +191,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -195,6 +209,8 @@ var removeDuplicates = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int RemoveDuplicates(int[] nums) { diff --git a/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/README_EN.md b/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/README_EN.md index 0c590b192c1e5..a1caa73032e2d 100644 --- a/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/README_EN.md +++ b/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/README_EN.md @@ -100,6 +100,8 @@ Similar problems: +#### Python3 + ```python class Solution: def removeDuplicates(self, nums: List[int]) -> int: @@ -111,6 +113,8 @@ class Solution: return k ``` +#### Java + ```java class Solution { public int removeDuplicates(int[] nums) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func removeDuplicates(nums []int) int { k := 0 @@ -153,6 +161,8 @@ func removeDuplicates(nums []int) int { } ``` +#### TypeScript + ```ts function removeDuplicates(nums: number[]): number { let k = 0; @@ -165,6 +175,8 @@ function removeDuplicates(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn remove_duplicates(nums: &mut Vec) -> i32 { @@ -180,6 +192,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -196,6 +210,8 @@ var removeDuplicates = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int RemoveDuplicates(int[] nums) { diff --git a/solution/0000-0099/0081.Search in Rotated Sorted Array II/README.md b/solution/0000-0099/0081.Search in Rotated Sorted Array II/README.md index 225920b84f3ed..189edea62a5b5 100644 --- a/solution/0000-0099/0081.Search in Rotated Sorted Array II/README.md +++ b/solution/0000-0099/0081.Search in Rotated Sorted Array II/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def search(self, nums: List[int], target: int) -> bool: @@ -106,6 +108,8 @@ class Solution: return nums[l] == target ``` +#### Java + ```java class Solution { public boolean search(int[] nums, int target) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func search(nums []int, target int) bool { l, r := 0, len(nums)-1 @@ -186,6 +194,8 @@ func search(nums []int, target int) bool { } ``` +#### TypeScript + ```ts function search(nums: number[], target: number): boolean { let [l, r] = [0, nums.length - 1]; diff --git a/solution/0000-0099/0081.Search in Rotated Sorted Array II/README_EN.md b/solution/0000-0099/0081.Search in Rotated Sorted Array II/README_EN.md index 4f6f0c6d33692..2e7c9c971a319 100644 --- a/solution/0000-0099/0081.Search in Rotated Sorted Array II/README_EN.md +++ b/solution/0000-0099/0081.Search in Rotated Sorted Array II/README_EN.md @@ -68,6 +68,8 @@ The time complexity is approximately $O(\log n)$, and the space complexity is $O +#### Python3 + ```python class Solution: def search(self, nums: List[int], target: int) -> bool: @@ -90,6 +92,8 @@ class Solution: return nums[l] == target ``` +#### Java + ```java class Solution { public boolean search(int[] nums, int target) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func search(nums []int, target int) bool { l, r := 0, len(nums)-1 @@ -170,6 +178,8 @@ func search(nums []int, target int) bool { } ``` +#### TypeScript + ```ts function search(nums: number[], target: number): boolean { let [l, r] = [0, nums.length - 1]; diff --git a/solution/0000-0099/0082.Remove Duplicates from Sorted List II/README.md b/solution/0000-0099/0082.Remove Duplicates from Sorted List II/README.md index 7b218a15fa00f..adeafadeb5124 100644 --- a/solution/0000-0099/0082.Remove Duplicates from Sorted List II/README.md +++ b/solution/0000-0099/0082.Remove Duplicates from Sorted List II/README.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -84,6 +86,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -175,6 +183,8 @@ func deleteDuplicates(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -207,6 +217,8 @@ function deleteDuplicates(head: ListNode | null): ListNode | null { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -245,6 +257,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -276,6 +290,8 @@ var deleteDuplicates = function (head) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. diff --git a/solution/0000-0099/0082.Remove Duplicates from Sorted List II/README_EN.md b/solution/0000-0099/0082.Remove Duplicates from Sorted List II/README_EN.md index c69145b8c4a94..5c7002394b7af 100644 --- a/solution/0000-0099/0082.Remove Duplicates from Sorted List II/README_EN.md +++ b/solution/0000-0099/0082.Remove Duplicates from Sorted List II/README_EN.md @@ -61,6 +61,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -82,6 +84,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -173,6 +181,8 @@ func deleteDuplicates(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -205,6 +215,8 @@ function deleteDuplicates(head: ListNode | null): ListNode | null { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -243,6 +255,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -274,6 +288,8 @@ var deleteDuplicates = function (head) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. diff --git a/solution/0000-0099/0083.Remove Duplicates from Sorted List/README.md b/solution/0000-0099/0083.Remove Duplicates from Sorted List/README.md index c71aa4178a809..99e6509ada5c6 100644 --- a/solution/0000-0099/0083.Remove Duplicates from Sorted List/README.md +++ b/solution/0000-0099/0083.Remove Duplicates from Sorted List/README.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -77,6 +79,8 @@ class Solution: return head ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -151,6 +159,8 @@ func deleteDuplicates(head *ListNode) *ListNode { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -186,6 +196,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -211,6 +223,8 @@ var deleteDuplicates = function (head) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. diff --git a/solution/0000-0099/0083.Remove Duplicates from Sorted List/README_EN.md b/solution/0000-0099/0083.Remove Duplicates from Sorted List/README_EN.md index c27d1a642c1a9..53404fd394aac 100644 --- a/solution/0000-0099/0083.Remove Duplicates from Sorted List/README_EN.md +++ b/solution/0000-0099/0083.Remove Duplicates from Sorted List/README_EN.md @@ -58,6 +58,8 @@ The time complexity is $O(n)$, where $n$ is the length of the linked list. The s +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -75,6 +77,8 @@ class Solution: return head ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -149,6 +157,8 @@ func deleteDuplicates(head *ListNode) *ListNode { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -184,6 +194,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -209,6 +221,8 @@ var deleteDuplicates = function (head) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. diff --git a/solution/0000-0099/0084.Largest Rectangle in Histogram/README.md b/solution/0000-0099/0084.Largest Rectangle in Histogram/README.md index 4082bc6706be1..53deb961f2ed0 100644 --- a/solution/0000-0099/0084.Largest Rectangle in Histogram/README.md +++ b/solution/0000-0099/0084.Largest Rectangle in Histogram/README.md @@ -75,6 +75,8 @@ for i in range(n): +#### Python3 + ```python class Solution: def largestRectangleArea(self, heights: List[int]) -> int: @@ -92,6 +94,8 @@ class Solution: return max(h * (right[i] - left[i] - 1) for i, h in enumerate(heights)) ``` +#### Java + ```java class Solution { public int largestRectangleArea(int[] heights) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func largestRectangleArea(heights []int) int { res, n := 0, len(heights) @@ -165,6 +173,8 @@ func largestRectangleArea(heights []int) int { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -213,6 +223,8 @@ impl Solution { } ``` +#### C# + ```cs using System; using System.Collections.Generic; @@ -253,6 +265,8 @@ public class Solution { +#### Python3 + ```python class Solution: def largestRectangleArea(self, heights: List[int]) -> int: diff --git a/solution/0000-0099/0084.Largest Rectangle in Histogram/README_EN.md b/solution/0000-0099/0084.Largest Rectangle in Histogram/README_EN.md index b5aca65bea39d..650ab8eb26347 100644 --- a/solution/0000-0099/0084.Largest Rectangle in Histogram/README_EN.md +++ b/solution/0000-0099/0084.Largest Rectangle in Histogram/README_EN.md @@ -69,6 +69,8 @@ for i in range(n): +#### Python3 + ```python class Solution: def largestRectangleArea(self, heights: List[int]) -> int: @@ -86,6 +88,8 @@ class Solution: return max(h * (right[i] - left[i] - 1) for i, h in enumerate(heights)) ``` +#### Java + ```java class Solution { public int largestRectangleArea(int[] heights) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func largestRectangleArea(heights []int) int { res, n := 0, len(heights) @@ -159,6 +167,8 @@ func largestRectangleArea(heights []int) int { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -207,6 +217,8 @@ impl Solution { } ``` +#### C# + ```cs using System; using System.Collections.Generic; @@ -247,6 +259,8 @@ public class Solution { +#### Python3 + ```python class Solution: def largestRectangleArea(self, heights: List[int]) -> int: diff --git a/solution/0000-0099/0085.Maximal Rectangle/README.md b/solution/0000-0099/0085.Maximal Rectangle/README.md index f1582078fe3d0..8f7d6760b3a36 100644 --- a/solution/0000-0099/0085.Maximal Rectangle/README.md +++ b/solution/0000-0099/0085.Maximal Rectangle/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def maximalRectangle(self, matrix: List[List[str]]) -> int: @@ -107,6 +109,8 @@ class Solution: return max(h * (right[i] - left[i] - 1) for i, h in enumerate(heights)) ``` +#### Java + ```java class Solution { public int maximalRectangle(char[][] matrix) { @@ -147,6 +151,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go func maximalRectangle(matrix [][]byte) int { n := len(matrix[0]) @@ -230,6 +238,8 @@ func largestRectangleArea(heights []int) int { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -308,6 +318,8 @@ impl Solution { } ``` +#### C# + ```cs using System; using System.Collections.Generic; diff --git a/solution/0000-0099/0085.Maximal Rectangle/README_EN.md b/solution/0000-0099/0085.Maximal Rectangle/README_EN.md index 8c93dd8a8d59d..fe4f912260354 100644 --- a/solution/0000-0099/0085.Maximal Rectangle/README_EN.md +++ b/solution/0000-0099/0085.Maximal Rectangle/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(m \times n)$, where $m$ represents the number of rows +#### Python3 + ```python class Solution: def maximalRectangle(self, matrix: List[List[str]]) -> int: @@ -105,6 +107,8 @@ class Solution: return max(h * (right[i] - left[i] - 1) for i, h in enumerate(heights)) ``` +#### Java + ```java class Solution { public int maximalRectangle(char[][] matrix) { @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -184,6 +190,8 @@ public: }; ``` +#### Go + ```go func maximalRectangle(matrix [][]byte) int { n := len(matrix[0]) @@ -228,6 +236,8 @@ func largestRectangleArea(heights []int) int { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -306,6 +316,8 @@ impl Solution { } ``` +#### C# + ```cs using System; using System.Collections.Generic; diff --git a/solution/0000-0099/0086.Partition List/README.md b/solution/0000-0099/0086.Partition List/README.md index b5aafb4603415..3bf0d42492bbf 100644 --- a/solution/0000-0099/0086.Partition List/README.md +++ b/solution/0000-0099/0086.Partition List/README.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -84,6 +86,8 @@ class Solution: return d1.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -179,6 +187,8 @@ func partition(head *ListNode, x int) *ListNode { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -218,6 +228,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. diff --git a/solution/0000-0099/0086.Partition List/README_EN.md b/solution/0000-0099/0086.Partition List/README_EN.md index 8e0d70018be63..a44e7933ee2f6 100644 --- a/solution/0000-0099/0086.Partition List/README_EN.md +++ b/solution/0000-0099/0086.Partition List/README_EN.md @@ -59,6 +59,8 @@ The time complexity is $O(n)$, where $n$ is the length of the original linked li +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -82,6 +84,8 @@ class Solution: return d1.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -177,6 +185,8 @@ func partition(head *ListNode, x int) *ListNode { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -216,6 +226,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. diff --git a/solution/0000-0099/0087.Scramble String/README.md b/solution/0000-0099/0087.Scramble String/README.md index 6dca4ebdad73c..fb2f7e37bc09a 100644 --- a/solution/0000-0099/0087.Scramble String/README.md +++ b/solution/0000-0099/0087.Scramble String/README.md @@ -97,6 +97,8 @@ tags: +#### Python3 + ```python class Solution: def isScramble(self, s1: str, s2: str) -> bool: @@ -114,6 +116,8 @@ class Solution: return dfs(0, 0, len(s1)) ``` +#### Java + ```java class Solution { private Boolean[][][] f; @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go func isScramble(s1 string, s2 string) bool { n := len(s1) @@ -208,6 +216,8 @@ func isScramble(s1 string, s2 string) bool { } ``` +#### TypeScript + ```ts function isScramble(s1: string, s2: string): boolean { const n = s1.length; @@ -235,6 +245,8 @@ function isScramble(s1: string, s2: string): boolean { } ``` +#### C# + ```cs public class Solution { private string s1; @@ -292,6 +304,8 @@ public class Solution { +#### Python3 + ```python class Solution: def isScramble(self, s1: str, s2: str) -> bool: @@ -313,6 +327,8 @@ class Solution: return f[0][0][n] ``` +#### Java + ```java class Solution { public boolean isScramble(String s1, String s2) { @@ -344,6 +360,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -377,6 +395,8 @@ public: }; ``` +#### Go + ```go func isScramble(s1 string, s2 string) bool { n := len(s1) @@ -404,6 +424,8 @@ func isScramble(s1 string, s2 string) bool { } ``` +#### TypeScript + ```ts function isScramble(s1: string, s2: string): boolean { const n = s1.length; @@ -435,6 +457,8 @@ function isScramble(s1: string, s2: string): boolean { } ``` +#### C# + ```cs public class Solution { public bool IsScramble(string s1, string s2) { diff --git a/solution/0000-0099/0087.Scramble String/README_EN.md b/solution/0000-0099/0087.Scramble String/README_EN.md index 915e776cd0f33..52a35aedfc45c 100644 --- a/solution/0000-0099/0087.Scramble String/README_EN.md +++ b/solution/0000-0099/0087.Scramble String/README_EN.md @@ -95,6 +95,8 @@ The time complexity is $O(n^4)$, and the space complexity is $O(n^3)$. Where $n$ +#### Python3 + ```python class Solution: def isScramble(self, s1: str, s2: str) -> bool: @@ -112,6 +114,8 @@ class Solution: return dfs(0, 0, len(s1)) ``` +#### Java + ```java class Solution { private Boolean[][][] f; @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go func isScramble(s1 string, s2 string) bool { n := len(s1) @@ -206,6 +214,8 @@ func isScramble(s1 string, s2 string) bool { } ``` +#### TypeScript + ```ts function isScramble(s1: string, s2: string): boolean { const n = s1.length; @@ -233,6 +243,8 @@ function isScramble(s1: string, s2: string): boolean { } ``` +#### C# + ```cs public class Solution { private string s1; @@ -290,6 +302,8 @@ The time complexity is $O(n^4)$, and the space complexity is $O(n^3)$. Where $n$ +#### Python3 + ```python class Solution: def isScramble(self, s1: str, s2: str) -> bool: @@ -311,6 +325,8 @@ class Solution: return f[0][0][n] ``` +#### Java + ```java class Solution { public boolean isScramble(String s1, String s2) { @@ -342,6 +358,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -375,6 +393,8 @@ public: }; ``` +#### Go + ```go func isScramble(s1 string, s2 string) bool { n := len(s1) @@ -402,6 +422,8 @@ func isScramble(s1 string, s2 string) bool { } ``` +#### TypeScript + ```ts function isScramble(s1: string, s2: string): boolean { const n = s1.length; @@ -433,6 +455,8 @@ function isScramble(s1: string, s2: string): boolean { } ``` +#### C# + ```cs public class Solution { public bool IsScramble(string s1, string s2) { diff --git a/solution/0000-0099/0088.Merge Sorted Array/README.md b/solution/0000-0099/0088.Merge Sorted Array/README.md index 02b7da244ab13..ee0526712f66b 100644 --- a/solution/0000-0099/0088.Merge Sorted Array/README.md +++ b/solution/0000-0099/0088.Merge Sorted Array/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None: @@ -101,6 +103,8 @@ class Solution: k -= 1 ``` +#### Java + ```java class Solution { public void merge(int[] nums1, int m, int[] nums2, int n) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func merge(nums1 []int, m int, nums2 []int, n int) { for i, j, k := m-1, n-1, m+n-1; j >= 0; k-- { @@ -136,6 +144,8 @@ func merge(nums1 []int, m int, nums2 []int, n int) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify nums1 in-place instead. @@ -147,6 +157,8 @@ function merge(nums1: number[], m: number, nums2: number[], n: number): void { } ``` +#### TypeScript + ```ts /** Do not return anything, modify nums1 in-place instead. @@ -159,6 +171,8 @@ function merge(nums1: number[], m: number, nums2: number[], n: number): void { } ``` +#### Rust + ```rust impl Solution { pub fn merge(nums1: &mut Vec, m: i32, nums2: &mut Vec, n: i32) { @@ -188,6 +202,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums1 @@ -203,6 +219,8 @@ var merge = function (nums1, m, nums2, n) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0088.Merge Sorted Array/README_EN.md b/solution/0000-0099/0088.Merge Sorted Array/README_EN.md index e237d3d2faf43..75284b1fbf7b8 100644 --- a/solution/0000-0099/0088.Merge Sorted Array/README_EN.md +++ b/solution/0000-0099/0088.Merge Sorted Array/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(m + n)$, where $m$ and $n$ are the lengths of two arra +#### Python3 + ```python class Solution: def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None: @@ -98,6 +100,8 @@ class Solution: k -= 1 ``` +#### Java + ```java class Solution { public void merge(int[] nums1, int m, int[] nums2, int n) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func merge(nums1 []int, m int, nums2 []int, n int) { for i, j, k := m-1, n-1, m+n-1; j >= 0; k-- { @@ -133,6 +141,8 @@ func merge(nums1 []int, m int, nums2 []int, n int) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify nums1 in-place instead. @@ -144,6 +154,8 @@ function merge(nums1: number[], m: number, nums2: number[], n: number): void { } ``` +#### TypeScript + ```ts /** Do not return anything, modify nums1 in-place instead. @@ -156,6 +168,8 @@ function merge(nums1: number[], m: number, nums2: number[], n: number): void { } ``` +#### Rust + ```rust impl Solution { pub fn merge(nums1: &mut Vec, m: i32, nums2: &mut Vec, n: i32) { @@ -185,6 +199,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums1 @@ -200,6 +216,8 @@ var merge = function (nums1, m, nums2, n) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0000-0099/0089.Gray Code/README.md b/solution/0000-0099/0089.Gray Code/README.md index 8d86bd9771f3d..40732432a6d34 100644 --- a/solution/0000-0099/0089.Gray Code/README.md +++ b/solution/0000-0099/0089.Gray Code/README.md @@ -93,12 +93,16 @@ int gray(x) { +#### Python3 + ```python class Solution: def grayCode(self, n: int) -> List[int]: return [i ^ (i >> 1) for i in range(1 << n)] ``` +#### Java + ```java class Solution { public List grayCode(int n) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func grayCode(n int) (ans []int) { for i := 0; i < 1< +#### Python3 + ```python class Solution: def grayCode(self, n: int) -> List[int]: return [i ^ (i >> 1) for i in range(1 << n)] ``` +#### Java + ```java class Solution { public List grayCode(int n) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func grayCode(n int) (ans []int) { for i := 0; i < 1< +#### Python3 + ```python class Solution: def subsetsWithDup(self, nums: List[int]) -> List[List[int]]: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func subsetsWithDup(nums []int) (ans [][]int) { sort.Ints(nums) @@ -174,6 +182,8 @@ func subsetsWithDup(nums []int) (ans [][]int) { } ``` +#### TypeScript + ```ts function subsetsWithDup(nums: number[]): number[][] { nums.sort((a, b) => a - b); @@ -198,6 +208,8 @@ function subsetsWithDup(nums: number[]): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn subsets_with_dup(nums: Vec) -> Vec> { @@ -245,6 +257,8 @@ impl Solution { +#### Python3 + ```python class Solution: def subsetsWithDup(self, nums: List[int]) -> List[List[int]]: @@ -265,6 +279,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> subsetsWithDup(int[] nums) { @@ -292,6 +308,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -320,6 +338,8 @@ public: }; ``` +#### Go + ```go func subsetsWithDup(nums []int) (ans [][]int) { sort.Ints(nums) @@ -344,6 +364,8 @@ func subsetsWithDup(nums []int) (ans [][]int) { } ``` +#### TypeScript + ```ts function subsetsWithDup(nums: number[]): number[][] { nums.sort((a, b) => a - b); @@ -369,6 +391,8 @@ function subsetsWithDup(nums: number[]): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn subsets_with_dup(nums: Vec) -> Vec> { diff --git a/solution/0000-0099/0090.Subsets II/README_EN.md b/solution/0000-0099/0090.Subsets II/README_EN.md index 329b2d9791834..23b33b1caaa0d 100644 --- a/solution/0000-0099/0090.Subsets II/README_EN.md +++ b/solution/0000-0099/0090.Subsets II/README_EN.md @@ -60,6 +60,8 @@ The time complexity is $O(n \times 2^n)$, and the space complexity is $O(n)$. He +#### Python3 + ```python class Solution: def subsetsWithDup(self, nums: List[int]) -> List[List[int]]: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func subsetsWithDup(nums []int) (ans [][]int) { sort.Ints(nums) @@ -161,6 +169,8 @@ func subsetsWithDup(nums []int) (ans [][]int) { } ``` +#### TypeScript + ```ts function subsetsWithDup(nums: number[]): number[][] { nums.sort((a, b) => a - b); @@ -185,6 +195,8 @@ function subsetsWithDup(nums: number[]): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn subsets_with_dup(nums: Vec) -> Vec> { @@ -232,6 +244,8 @@ The time complexity is $O(n \times 2^n)$, and the space complexity is $O(n)$. He +#### Python3 + ```python class Solution: def subsetsWithDup(self, nums: List[int]) -> List[List[int]]: @@ -252,6 +266,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> subsetsWithDup(int[] nums) { @@ -279,6 +295,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -307,6 +325,8 @@ public: }; ``` +#### Go + ```go func subsetsWithDup(nums []int) (ans [][]int) { sort.Ints(nums) @@ -331,6 +351,8 @@ func subsetsWithDup(nums []int) (ans [][]int) { } ``` +#### TypeScript + ```ts function subsetsWithDup(nums: number[]): number[][] { nums.sort((a, b) => a - b); @@ -356,6 +378,8 @@ function subsetsWithDup(nums: number[]): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn subsets_with_dup(nums: Vec) -> Vec> { diff --git a/solution/0000-0099/0091.Decode Ways/README.md b/solution/0000-0099/0091.Decode Ways/README.md index 39c6b9cacaeaf..4f263c0409f85 100644 --- a/solution/0000-0099/0091.Decode Ways/README.md +++ b/solution/0000-0099/0091.Decode Ways/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def numDecodings(self, s: str) -> int: @@ -105,6 +107,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int numDecodings(String s) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func numDecodings(s string) int { n := len(s) @@ -162,6 +170,8 @@ func numDecodings(s string) int { } ``` +#### TypeScript + ```ts function numDecodings(s: string): number { const n = s.length; @@ -179,6 +189,8 @@ function numDecodings(s: string): number { } ``` +#### C# + ```cs public class Solution { public int NumDecodings(string s) { @@ -204,6 +216,8 @@ public class Solution { +#### Python3 + ```python class Solution: def numDecodings(self, s: str) -> int: @@ -216,6 +230,8 @@ class Solution: return g ``` +#### Java + ```java class Solution { public int numDecodings(String s) { @@ -234,6 +250,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -253,6 +271,8 @@ public: }; ``` +#### Go + ```go func numDecodings(s string) int { n := len(s) @@ -271,6 +291,8 @@ func numDecodings(s string) int { } ``` +#### TypeScript + ```ts function numDecodings(s: string): number { const n = s.length; @@ -286,6 +308,8 @@ function numDecodings(s: string): number { } ``` +#### C# + ```cs public class Solution { public int NumDecodings(string s) { diff --git a/solution/0000-0099/0091.Decode Ways/README_EN.md b/solution/0000-0099/0091.Decode Ways/README_EN.md index 58400026d58fe..aa4494f022832 100644 --- a/solution/0000-0099/0091.Decode Ways/README_EN.md +++ b/solution/0000-0099/0091.Decode Ways/README_EN.md @@ -91,6 +91,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def numDecodings(self, s: str) -> int: @@ -104,6 +106,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int numDecodings(String s) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func numDecodings(s string) int { n := len(s) @@ -161,6 +169,8 @@ func numDecodings(s string) int { } ``` +#### TypeScript + ```ts function numDecodings(s: string): number { const n = s.length; @@ -178,6 +188,8 @@ function numDecodings(s: string): number { } ``` +#### C# + ```cs public class Solution { public int NumDecodings(string s) { @@ -203,6 +215,8 @@ We notice that the state $f[i]$ is only related to the states $f[i-1]$ and $f[i- +#### Python3 + ```python class Solution: def numDecodings(self, s: str) -> int: @@ -215,6 +229,8 @@ class Solution: return g ``` +#### Java + ```java class Solution { public int numDecodings(String s) { @@ -233,6 +249,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -252,6 +270,8 @@ public: }; ``` +#### Go + ```go func numDecodings(s string) int { n := len(s) @@ -270,6 +290,8 @@ func numDecodings(s string) int { } ``` +#### TypeScript + ```ts function numDecodings(s: string): number { const n = s.length; @@ -285,6 +307,8 @@ function numDecodings(s: string): number { } ``` +#### C# + ```cs public class Solution { public int NumDecodings(string s) { diff --git a/solution/0000-0099/0092.Reverse Linked List II/README.md b/solution/0000-0099/0092.Reverse Linked List II/README.md index fd2c091f25e19..167ad9ea49943 100644 --- a/solution/0000-0099/0092.Reverse Linked List II/README.md +++ b/solution/0000-0099/0092.Reverse Linked List II/README.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -90,6 +92,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -195,6 +203,8 @@ func reverseBetween(head *ListNode, left int, right int) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -235,6 +245,8 @@ function reverseBetween(head: ListNode | null, left: number, right: number): Lis } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -279,6 +291,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -317,6 +331,8 @@ var reverseBetween = function (head, left, right) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. diff --git a/solution/0000-0099/0092.Reverse Linked List II/README_EN.md b/solution/0000-0099/0092.Reverse Linked List II/README_EN.md index fabcb8d1285fb..a734f08ee2c3c 100644 --- a/solution/0000-0099/0092.Reverse Linked List II/README_EN.md +++ b/solution/0000-0099/0092.Reverse Linked List II/README_EN.md @@ -60,6 +60,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -87,6 +89,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -192,6 +200,8 @@ func reverseBetween(head *ListNode, left int, right int) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -232,6 +242,8 @@ function reverseBetween(head: ListNode | null, left: number, right: number): Lis } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -276,6 +288,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -314,6 +328,8 @@ var reverseBetween = function (head, left, right) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. diff --git a/solution/0000-0099/0093.Restore IP Addresses/README.md b/solution/0000-0099/0093.Restore IP Addresses/README.md index 7f28a080fad82..4abf5aeb5fef1 100644 --- a/solution/0000-0099/0093.Restore IP Addresses/README.md +++ b/solution/0000-0099/0093.Restore IP Addresses/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def restoreIpAddresses(self, s: str) -> List[str]: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go func restoreIpAddresses(s string) (ans []string) { n := len(s) @@ -201,6 +209,8 @@ func restoreIpAddresses(s string) (ans []string) { } ``` +#### TypeScript + ```ts function restoreIpAddresses(s: string): string[] { const n = s.length; @@ -230,6 +240,8 @@ function restoreIpAddresses(s: string): string[] { } ``` +#### C# + ```cs public class Solution { private IList ans = new List(); diff --git a/solution/0000-0099/0093.Restore IP Addresses/README_EN.md b/solution/0000-0099/0093.Restore IP Addresses/README_EN.md index 55bff3143865e..7119d50da6444 100644 --- a/solution/0000-0099/0093.Restore IP Addresses/README_EN.md +++ b/solution/0000-0099/0093.Restore IP Addresses/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(n \times 3^4)$, and the space complexity is $O(n)$. He +#### Python3 + ```python class Solution: def restoreIpAddresses(self, s: str) -> List[str]: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go func restoreIpAddresses(s string) (ans []string) { n := len(s) @@ -199,6 +207,8 @@ func restoreIpAddresses(s string) (ans []string) { } ``` +#### TypeScript + ```ts function restoreIpAddresses(s: string): string[] { const n = s.length; @@ -228,6 +238,8 @@ function restoreIpAddresses(s: string): string[] { } ``` +#### C# + ```cs public class Solution { private IList ans = new List(); diff --git a/solution/0000-0099/0094.Binary Tree Inorder Traversal/README.md b/solution/0000-0099/0094.Binary Tree Inorder Traversal/README.md index 9b9af723bc619..e975066143786 100644 --- a/solution/0000-0099/0094.Binary Tree Inorder Traversal/README.md +++ b/solution/0000-0099/0094.Binary Tree Inorder Traversal/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -181,6 +189,8 @@ func inorderTraversal(root *TreeNode) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -211,6 +221,8 @@ function inorderTraversal(root: TreeNode | null): number[] { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -251,6 +263,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -298,6 +312,8 @@ var inorderTraversal = function (root) { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -319,6 +335,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -354,6 +372,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -387,6 +407,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -413,6 +435,8 @@ func inorderTraversal(root *TreeNode) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -445,6 +469,8 @@ function inorderTraversal(root: TreeNode | null): number[] { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -487,6 +513,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -539,6 +567,8 @@ Morris 遍历无需使用栈,空间复杂度为 $O(1)$。核心思想是: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -567,6 +597,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -610,6 +642,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -650,6 +684,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -683,6 +719,8 @@ func inorderTraversal(root *TreeNode) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -723,6 +761,8 @@ function inorderTraversal(root: TreeNode | null): number[] { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0000-0099/0094.Binary Tree Inorder Traversal/README_EN.md b/solution/0000-0099/0094.Binary Tree Inorder Traversal/README_EN.md index a0aec7b253512..9207f973f223f 100644 --- a/solution/0000-0099/0094.Binary Tree Inorder Traversal/README_EN.md +++ b/solution/0000-0099/0094.Binary Tree Inorder Traversal/README_EN.md @@ -68,6 +68,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -178,6 +186,8 @@ func inorderTraversal(root *TreeNode) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -208,6 +218,8 @@ function inorderTraversal(root: TreeNode | null): number[] { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -248,6 +260,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -295,6 +309,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -316,6 +332,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -351,6 +369,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -384,6 +404,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -410,6 +432,8 @@ func inorderTraversal(root *TreeNode) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -442,6 +466,8 @@ function inorderTraversal(root: TreeNode | null): number[] { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -484,6 +510,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -536,6 +564,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -564,6 +594,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -607,6 +639,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -647,6 +681,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -680,6 +716,8 @@ func inorderTraversal(root *TreeNode) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -720,6 +758,8 @@ function inorderTraversal(root: TreeNode | null): number[] { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0000-0099/0095.Unique Binary Search Trees II/README.md b/solution/0000-0099/0095.Unique Binary Search Trees II/README.md index 583664f6cb7b8..9e90e8f8a1d5a 100644 --- a/solution/0000-0099/0095.Unique Binary Search Trees II/README.md +++ b/solution/0000-0099/0095.Unique Binary Search Trees II/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -93,6 +95,8 @@ class Solution: return dfs(1, n) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -201,6 +209,8 @@ func generateTrees(n int) []*TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -237,6 +247,8 @@ function generateTrees(n: number): Array { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/0000-0099/0095.Unique Binary Search Trees II/README_EN.md b/solution/0000-0099/0095.Unique Binary Search Trees II/README_EN.md index 385598984020f..2211d9e750623 100644 --- a/solution/0000-0099/0095.Unique Binary Search Trees II/README_EN.md +++ b/solution/0000-0099/0095.Unique Binary Search Trees II/README_EN.md @@ -63,6 +63,8 @@ The time complexity is $O(n \times G(n))$, and the space complexity is $O(n \tim +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -87,6 +89,8 @@ class Solution: return dfs(1, n) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -195,6 +203,8 @@ func generateTrees(n int) []*TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -231,6 +241,8 @@ function generateTrees(n: number): Array { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/0000-0099/0096.Unique Binary Search Trees/README.md b/solution/0000-0099/0096.Unique Binary Search Trees/README.md index e1c3c43d2827b..2858187f87995 100644 --- a/solution/0000-0099/0096.Unique Binary Search Trees/README.md +++ b/solution/0000-0099/0096.Unique Binary Search Trees/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def numTrees(self, n: int) -> int: @@ -74,6 +76,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int numTrees(int n) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func numTrees(n int) int { f := make([]int, n+1) @@ -118,6 +126,8 @@ func numTrees(n int) int { } ``` +#### TypeScript + ```ts function numTrees(n: number): number { const f: number[] = Array(n + 1).fill(0); @@ -131,6 +141,8 @@ function numTrees(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn num_trees(n: i32) -> i32 { @@ -147,6 +159,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int NumTrees(int n) { diff --git a/solution/0000-0099/0096.Unique Binary Search Trees/README_EN.md b/solution/0000-0099/0096.Unique Binary Search Trees/README_EN.md index a63e0a8bba10e..a0b87705ea1e6 100644 --- a/solution/0000-0099/0096.Unique Binary Search Trees/README_EN.md +++ b/solution/0000-0099/0096.Unique Binary Search Trees/README_EN.md @@ -62,6 +62,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def numTrees(self, n: int) -> int: @@ -72,6 +74,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int numTrees(int n) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -103,6 +109,8 @@ public: }; ``` +#### Go + ```go func numTrees(n int) int { f := make([]int, n+1) @@ -116,6 +124,8 @@ func numTrees(n int) int { } ``` +#### TypeScript + ```ts function numTrees(n: number): number { const f: number[] = Array(n + 1).fill(0); @@ -129,6 +139,8 @@ function numTrees(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn num_trees(n: i32) -> i32 { @@ -145,6 +157,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int NumTrees(int n) { diff --git a/solution/0000-0099/0097.Interleaving String/README.md b/solution/0000-0099/0097.Interleaving String/README.md index 7782a6bee9512..2b7b2430e5c21 100644 --- a/solution/0000-0099/0097.Interleaving String/README.md +++ b/solution/0000-0099/0097.Interleaving String/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python class Solution: def isInterleave(self, s1: str, s2: str, s3: str) -> bool: @@ -115,6 +117,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private Map, Boolean> f = new HashMap<>(); @@ -158,6 +162,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -189,6 +195,8 @@ public: }; ``` +#### Go + ```go func isInterleave(s1 string, s2 string, s3 string) bool { m, n := len(s1), len(s2) @@ -213,6 +221,8 @@ func isInterleave(s1 string, s2 string, s3 string) bool { } ``` +#### TypeScript + ```ts function isInterleave(s1: string, s2: string, s3: string): boolean { const m = s1.length; @@ -241,6 +251,8 @@ function isInterleave(s1: string, s2: string, s3: string): boolean { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -309,6 +321,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { private int m; @@ -378,6 +392,8 @@ $$ +#### Python3 + ```python class Solution: def isInterleave(self, s1: str, s2: str, s3: str) -> bool: @@ -396,6 +412,8 @@ class Solution: return f[m][n] ``` +#### Java + ```java class Solution { public boolean isInterleave(String s1, String s2, String s3) { @@ -421,6 +439,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -448,6 +468,8 @@ public: }; ``` +#### Go + ```go func isInterleave(s1 string, s2 string, s3 string) bool { m, n := len(s1), len(s2) @@ -474,6 +496,8 @@ func isInterleave(s1 string, s2 string, s3 string) bool { } ``` +#### TypeScript + ```ts function isInterleave(s1: string, s2: string, s3: string): boolean { const m = s1.length; @@ -498,6 +522,8 @@ function isInterleave(s1: string, s2: string, s3: string): boolean { } ``` +#### C# + ```cs public class Solution { public bool IsInterleave(string s1, string s2, string s3) { @@ -529,6 +555,8 @@ public class Solution { +#### Python3 + ```python class Solution: def isInterleave(self, s1: str, s2: str, s3: str) -> bool: @@ -546,6 +574,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public boolean isInterleave(String s1, String s2, String s3) { @@ -571,6 +601,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -598,6 +630,8 @@ public: }; ``` +#### Go + ```go func isInterleave(s1 string, s2 string, s3 string) bool { m, n := len(s1), len(s2) @@ -621,6 +655,8 @@ func isInterleave(s1 string, s2 string, s3 string) bool { } ``` +#### TypeScript + ```ts function isInterleave(s1: string, s2: string, s3: string): boolean { const m = s1.length; @@ -645,6 +681,8 @@ function isInterleave(s1: string, s2: string, s3: string): boolean { } ``` +#### C# + ```cs public class Solution { public bool IsInterleave(string s1, string s2, string s3) { diff --git a/solution/0000-0099/0097.Interleaving String/README_EN.md b/solution/0000-0099/0097.Interleaving String/README_EN.md index 7049d64f28cd4..acb6a5f016607 100644 --- a/solution/0000-0099/0097.Interleaving String/README_EN.md +++ b/solution/0000-0099/0097.Interleaving String/README_EN.md @@ -97,6 +97,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def isInterleave(self, s1: str, s2: str, s3: str) -> bool: @@ -117,6 +119,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private Map, Boolean> f = new HashMap<>(); @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -191,6 +197,8 @@ public: }; ``` +#### Go + ```go func isInterleave(s1 string, s2 string, s3 string) bool { m, n := len(s1), len(s2) @@ -215,6 +223,8 @@ func isInterleave(s1 string, s2 string, s3 string) bool { } ``` +#### TypeScript + ```ts function isInterleave(s1: string, s2: string, s3: string): boolean { const m = s1.length; @@ -243,6 +253,8 @@ function isInterleave(s1: string, s2: string, s3: string): boolean { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -311,6 +323,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { private int m; @@ -380,6 +394,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def isInterleave(self, s1: str, s2: str, s3: str) -> bool: @@ -398,6 +414,8 @@ class Solution: return f[m][n] ``` +#### Java + ```java class Solution { public boolean isInterleave(String s1, String s2, String s3) { @@ -423,6 +441,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -450,6 +470,8 @@ public: }; ``` +#### Go + ```go func isInterleave(s1 string, s2 string, s3 string) bool { m, n := len(s1), len(s2) @@ -476,6 +498,8 @@ func isInterleave(s1 string, s2 string, s3 string) bool { } ``` +#### TypeScript + ```ts function isInterleave(s1: string, s2: string, s3: string): boolean { const m = s1.length; @@ -500,6 +524,8 @@ function isInterleave(s1: string, s2: string, s3: string): boolean { } ``` +#### C# + ```cs public class Solution { public bool IsInterleave(string s1, string s2, string s3) { @@ -531,6 +557,8 @@ We notice that the state $f[i][j]$ is only related to the states $f[i - 1][j]$, +#### Python3 + ```python class Solution: def isInterleave(self, s1: str, s2: str, s3: str) -> bool: @@ -548,6 +576,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public boolean isInterleave(String s1, String s2, String s3) { @@ -573,6 +603,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -600,6 +632,8 @@ public: }; ``` +#### Go + ```go func isInterleave(s1 string, s2 string, s3 string) bool { m, n := len(s1), len(s2) @@ -623,6 +657,8 @@ func isInterleave(s1 string, s2 string, s3 string) bool { } ``` +#### TypeScript + ```ts function isInterleave(s1: string, s2: string, s3: string): boolean { const m = s1.length; @@ -647,6 +683,8 @@ function isInterleave(s1: string, s2: string, s3: string): boolean { } ``` +#### C# + ```cs public class Solution { public bool IsInterleave(string s1, string s2, string s3) { diff --git a/solution/0000-0099/0098.Validate Binary Search Tree/README.md b/solution/0000-0099/0098.Validate Binary Search Tree/README.md index f6f2647614dbc..c1b350c8aba60 100644 --- a/solution/0000-0099/0098.Validate Binary Search Tree/README.md +++ b/solution/0000-0099/0098.Validate Binary Search Tree/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -95,6 +97,8 @@ class Solution: return dfs(root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -197,6 +205,8 @@ func isValidBST(root *TreeNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -231,6 +241,8 @@ function isValidBST(root: TreeNode | null): boolean { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -274,6 +286,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -306,6 +320,8 @@ var isValidBST = function (root) { }; ``` +#### C# + ```cs /** * Definition for a binary tree node. diff --git a/solution/0000-0099/0098.Validate Binary Search Tree/README_EN.md b/solution/0000-0099/0098.Validate Binary Search Tree/README_EN.md index 19d2d610eb9c7..cddfa5502d578 100644 --- a/solution/0000-0099/0098.Validate Binary Search Tree/README_EN.md +++ b/solution/0000-0099/0098.Validate Binary Search Tree/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -93,6 +95,8 @@ class Solution: return dfs(root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -195,6 +203,8 @@ func isValidBST(root *TreeNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -229,6 +239,8 @@ function isValidBST(root: TreeNode | null): boolean { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -272,6 +284,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -304,6 +318,8 @@ var isValidBST = function (root) { }; ``` +#### C# + ```cs /** * Definition for a binary tree node. diff --git a/solution/0000-0099/0099.Recover Binary Search Tree/README.md b/solution/0000-0099/0099.Recover Binary Search Tree/README.md index 7f1cbaefd9306..06136214db6aa 100644 --- a/solution/0000-0099/0099.Recover Binary Search Tree/README.md +++ b/solution/0000-0099/0099.Recover Binary Search Tree/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -95,6 +97,8 @@ class Solution: first.val, second.val = second.val, first.val ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -205,6 +213,8 @@ func recoverTree(root *TreeNode) { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -243,6 +253,8 @@ var recoverTree = function (root) { }; ``` +#### C# + ```cs /** * Definition for a binary tree node. diff --git a/solution/0000-0099/0099.Recover Binary Search Tree/README_EN.md b/solution/0000-0099/0099.Recover Binary Search Tree/README_EN.md index 83d05234a3b9a..313f45f5cb8ca 100644 --- a/solution/0000-0099/0099.Recover Binary Search Tree/README_EN.md +++ b/solution/0000-0099/0099.Recover Binary Search Tree/README_EN.md @@ -63,6 +63,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -93,6 +95,8 @@ class Solution: first.val, second.val = second.val, first.val ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -203,6 +211,8 @@ func recoverTree(root *TreeNode) { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -241,6 +251,8 @@ var recoverTree = function (root) { }; ``` +#### C# + ```cs /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0100.Same Tree/README.md b/solution/0100-0199/0100.Same Tree/README.md index 435a9348f508c..84e9014b184e4 100644 --- a/solution/0100-0199/0100.Same Tree/README.md +++ b/solution/0100-0199/0100.Same Tree/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -87,6 +89,8 @@ class Solution: return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -154,6 +162,8 @@ func isSameTree(p *TreeNode, q *TreeNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -180,6 +190,8 @@ function isSameTree(p: TreeNode | null, q: TreeNode | null): boolean { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -223,6 +235,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -246,6 +260,8 @@ var isSameTree = function (p, q) { }; ``` +#### PHP + ```php /** * Definition for a binary tree node. @@ -297,6 +313,8 @@ class Solution { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -330,6 +348,8 @@ class Solution: return True ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -386,6 +406,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -429,6 +451,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -474,6 +498,8 @@ func isSameTree(p *TreeNode, q *TreeNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -528,6 +554,8 @@ function isSameTree(p: TreeNode | null, q: TreeNode | null): boolean { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/0100-0199/0100.Same Tree/README_EN.md b/solution/0100-0199/0100.Same Tree/README_EN.md index bdf181b529d1e..104e6b3e64ec1 100644 --- a/solution/0100-0199/0100.Same Tree/README_EN.md +++ b/solution/0100-0199/0100.Same Tree/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(\min(m, n))$, and the space complexity is $O(\min(m, n +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -85,6 +87,8 @@ class Solution: return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -152,6 +160,8 @@ func isSameTree(p *TreeNode, q *TreeNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -178,6 +188,8 @@ function isSameTree(p: TreeNode | null, q: TreeNode | null): boolean { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -221,6 +233,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -244,6 +258,8 @@ var isSameTree = function (p, q) { }; ``` +#### PHP + ```php /** * Definition for a binary tree node. @@ -295,6 +311,8 @@ The time complexity is $O(\min(m, n))$, and the space complexity is $O(\min(m, n +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -328,6 +346,8 @@ class Solution: return True ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -384,6 +404,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -427,6 +449,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -472,6 +496,8 @@ func isSameTree(p *TreeNode, q *TreeNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -526,6 +552,8 @@ function isSameTree(p: TreeNode | null, q: TreeNode | null): boolean { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/0100-0199/0101.Symmetric Tree/README.md b/solution/0100-0199/0101.Symmetric Tree/README.md index 5cb1fc2dad951..92b7e874e3fa0 100644 --- a/solution/0100-0199/0101.Symmetric Tree/README.md +++ b/solution/0100-0199/0101.Symmetric Tree/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -89,6 +91,8 @@ class Solution: return dfs(root, root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -171,6 +179,8 @@ func isSymmetric(root *TreeNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -201,6 +211,8 @@ function isSymmetric(root: TreeNode | null): boolean { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -244,6 +256,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -277,6 +291,8 @@ var isSymmetric = function (root) { +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/0100-0199/0101.Symmetric Tree/README_EN.md b/solution/0100-0199/0101.Symmetric Tree/README_EN.md index 81f1826455f84..a1a2981119196 100644 --- a/solution/0100-0199/0101.Symmetric Tree/README_EN.md +++ b/solution/0100-0199/0101.Symmetric Tree/README_EN.md @@ -67,6 +67,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -86,6 +88,8 @@ class Solution: return dfs(root, root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -168,6 +176,8 @@ func isSymmetric(root *TreeNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -198,6 +208,8 @@ function isSymmetric(root: TreeNode | null): boolean { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -241,6 +253,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -274,6 +288,8 @@ var isSymmetric = function (root) { +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/0100-0199/0102.Binary Tree Level Order Traversal/README.md b/solution/0100-0199/0102.Binary Tree Level Order Traversal/README.md index 05f3953b3e1b6..0f9f0f4417653 100644 --- a/solution/0100-0199/0102.Binary Tree Level Order Traversal/README.md +++ b/solution/0100-0199/0102.Binary Tree Level Order Traversal/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -178,6 +184,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -211,6 +219,8 @@ func levelOrder(root *TreeNode) (ans [][]int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -247,6 +257,8 @@ function levelOrder(root: TreeNode | null): number[][] { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -297,6 +309,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0102.Binary Tree Level Order Traversal/README_EN.md b/solution/0100-0199/0102.Binary Tree Level Order Traversal/README_EN.md index feaa4f4e0567c..04c98c7768841 100644 --- a/solution/0100-0199/0102.Binary Tree Level Order Traversal/README_EN.md +++ b/solution/0100-0199/0102.Binary Tree Level Order Traversal/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -209,6 +217,8 @@ func levelOrder(root *TreeNode) (ans [][]int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -245,6 +255,8 @@ function levelOrder(root: TreeNode | null): number[][] { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -295,6 +307,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/README.md b/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/README.md index 0d6b245691865..e4c96fa886dc1 100644 --- a/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/README.md +++ b/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -228,6 +236,8 @@ func zigzagLevelOrder(root *TreeNode) (ans [][]int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -266,6 +276,8 @@ function zigzagLevelOrder(root: TreeNode | null): number[][] { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -321,6 +333,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/README_EN.md b/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/README_EN.md index 397b96a547b78..404d591105702 100644 --- a/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/README_EN.md +++ b/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/README_EN.md @@ -64,6 +64,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -226,6 +234,8 @@ func zigzagLevelOrder(root *TreeNode) (ans [][]int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -264,6 +274,8 @@ function zigzagLevelOrder(root: TreeNode | null): number[][] { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -319,6 +331,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0104.Maximum Depth of Binary Tree/README.md b/solution/0100-0199/0104.Maximum Depth of Binary Tree/README.md index 5c38a6cde06fe..093f56b86abeb 100644 --- a/solution/0100-0199/0104.Maximum Depth of Binary Tree/README.md +++ b/solution/0100-0199/0104.Maximum Depth of Binary Tree/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -81,6 +83,8 @@ class Solution: return 1 + max(l, r) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -149,6 +157,8 @@ func maxDepth(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -172,6 +182,8 @@ function maxDepth(root: TreeNode | null): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -208,6 +220,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -229,6 +243,8 @@ var maxDepth = function (root) { }; ``` +#### C + ```c /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0104.Maximum Depth of Binary Tree/README_EN.md b/solution/0100-0199/0104.Maximum Depth of Binary Tree/README_EN.md index 02e9cc24956ce..3ca6261284815 100644 --- a/solution/0100-0199/0104.Maximum Depth of Binary Tree/README_EN.md +++ b/solution/0100-0199/0104.Maximum Depth of Binary Tree/README_EN.md @@ -60,6 +60,8 @@ The time complexity is $O(n)$, where $n$ is the number of nodes in the binary tr +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -75,6 +77,8 @@ class Solution: return 1 + max(l, r) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -143,6 +151,8 @@ func maxDepth(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -166,6 +176,8 @@ function maxDepth(root: TreeNode | null): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -202,6 +214,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -223,6 +237,8 @@ var maxDepth = function (root) { }; ``` +#### C + ```c /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README.md b/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README.md index 4f5ea9b0e2799..9ecc27bf0f14c 100644 --- a/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README.md +++ b/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -99,6 +101,8 @@ class Solution: return dfs(0, 0, len(preorder)) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -205,6 +213,8 @@ func buildTree(preorder []int, inorder []int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -240,6 +250,8 @@ function buildTree(preorder: number[], inorder: number[]): TreeNode | null { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -291,6 +303,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -331,6 +345,8 @@ var buildTree = function (preorder, inorder) { +#### Python3 + ```python class Solution: def getBinaryTrees(self, preOrder: List[int], inOrder: List[int]) -> List[TreeNode]: @@ -352,6 +368,8 @@ class Solution: return dfs(0, 0, len(preOrder)) ``` +#### Java + ```java class Solution { private List preorder; @@ -387,6 +405,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * struct TreeNode { @@ -432,6 +452,8 @@ public: }; ``` +#### Go + ```go func getBinaryTrees(preOrder []int, inOrder []int) []*TreeNode { n := len(preOrder) diff --git a/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README_EN.md b/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README_EN.md index 94aa976c1fb86..54321baf38ff8 100644 --- a/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README_EN.md +++ b/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -97,6 +99,8 @@ class Solution: return dfs(0, 0, len(preorder)) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -203,6 +211,8 @@ func buildTree(preorder []int, inorder []int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -238,6 +248,8 @@ function buildTree(preorder: number[], inorder: number[]): TreeNode | null { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -289,6 +301,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -329,6 +343,8 @@ If the node values given in the problem have duplicates, then we only need to re +#### Python3 + ```python class Solution: def getBinaryTrees(self, preOrder: List[int], inOrder: List[int]) -> List[TreeNode]: @@ -350,6 +366,8 @@ class Solution: return dfs(0, 0, len(preOrder)) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -392,6 +410,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * struct TreeNode { @@ -437,6 +457,8 @@ public: }; ``` +#### Go + ```go func getBinaryTrees(preOrder []int, inOrder []int) []*TreeNode { n := len(preOrder) diff --git a/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/README.md b/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/README.md index 45ff9647516e5..77e52a945c1f9 100644 --- a/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/README.md +++ b/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -94,6 +96,8 @@ class Solution: return dfs(0, 0, len(inorder)) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -200,6 +208,8 @@ func buildTree(inorder []int, postorder []int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -235,6 +245,8 @@ function buildTree(inorder: number[], postorder: number[]): TreeNode | null { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/README_EN.md b/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/README_EN.md index 2482a954efd0d..81107a19be9a2 100644 --- a/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/README_EN.md +++ b/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -92,6 +94,8 @@ class Solution: return dfs(0, 0, len(inorder)) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -198,6 +206,8 @@ func buildTree(inorder []int, postorder []int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -233,6 +243,8 @@ function buildTree(inorder: number[], postorder: number[]): TreeNode | null { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/0100-0199/0107.Binary Tree Level Order Traversal II/README.md b/solution/0100-0199/0107.Binary Tree Level Order Traversal II/README.md index 332a2ffab0163..171152f8d5908 100644 --- a/solution/0100-0199/0107.Binary Tree Level Order Traversal II/README.md +++ b/solution/0100-0199/0107.Binary Tree Level Order Traversal II/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -97,6 +99,8 @@ class Solution: return ans[::-1] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -217,6 +225,8 @@ func levelOrderBottom(root *TreeNode) (ans [][]int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -253,6 +263,8 @@ function levelOrderBottom(root: TreeNode | null): number[][] { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -302,6 +314,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0107.Binary Tree Level Order Traversal II/README_EN.md b/solution/0100-0199/0107.Binary Tree Level Order Traversal II/README_EN.md index e50837b0d4fac..b5c011d166276 100644 --- a/solution/0100-0199/0107.Binary Tree Level Order Traversal II/README_EN.md +++ b/solution/0100-0199/0107.Binary Tree Level Order Traversal II/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -95,6 +97,8 @@ class Solution: return ans[::-1] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -179,6 +185,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -215,6 +223,8 @@ func levelOrderBottom(root *TreeNode) (ans [][]int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -251,6 +261,8 @@ function levelOrderBottom(root: TreeNode | null): number[][] { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -300,6 +312,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/README.md b/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/README.md index f68954b80fb33..0c24207a12625 100644 --- a/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/README.md +++ b/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -95,6 +97,8 @@ class Solution: return dfs(0, len(nums) - 1) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -183,6 +191,8 @@ func sortedArrayToBST(nums []int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -212,6 +222,8 @@ function sortedArrayToBST(nums: number[]): TreeNode | null { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -256,6 +268,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/README_EN.md b/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/README_EN.md index 61d86989c3f13..f9bf795abc8d4 100644 --- a/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/README_EN.md +++ b/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/README_EN.md @@ -73,6 +73,8 @@ The time complexity is $O(n)$, and the space complexity is $O(\log n)$. Here, $n +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -93,6 +95,8 @@ class Solution: return dfs(0, len(nums) - 1) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -181,6 +189,8 @@ func sortedArrayToBST(nums []int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -210,6 +220,8 @@ function sortedArrayToBST(nums: number[]): TreeNode | null { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -254,6 +266,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/README.md b/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/README.md index d06d5dbf9c7e4..46772892185d2 100644 --- a/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/README.md +++ b/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/README.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -89,6 +91,8 @@ class Solution: return buildBST(nums, 0, len(nums) - 1) ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -183,6 +189,8 @@ private: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -221,6 +229,8 @@ func buildBST(nums []int, start, end int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -271,6 +281,8 @@ function sortedListToBST(head: ListNode | null): TreeNode | null { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -337,6 +349,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -377,6 +391,8 @@ var sortedListToBST = function (head) { }; ``` +#### C + ```c /** * Definition for singly-linked list. diff --git a/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/README_EN.md b/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/README_EN.md index 29027e5993e04..c8fb7cd4117dd 100644 --- a/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/README_EN.md +++ b/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/README_EN.md @@ -56,6 +56,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -85,6 +87,8 @@ class Solution: return buildBST(nums, 0, len(nums) - 1) ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -179,6 +185,8 @@ private: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -217,6 +225,8 @@ func buildBST(nums []int, start, end int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -267,6 +277,8 @@ function sortedListToBST(head: ListNode | null): TreeNode | null { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -333,6 +345,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -373,6 +387,8 @@ var sortedListToBST = function (head) { }; ``` +#### C + ```c /** * Definition for singly-linked list. diff --git a/solution/0100-0199/0110.Balanced Binary Tree/README.md b/solution/0100-0199/0110.Balanced Binary Tree/README.md index 44d3c014ec6be..7fa4333c75669 100644 --- a/solution/0100-0199/0110.Balanced Binary Tree/README.md +++ b/solution/0100-0199/0110.Balanced Binary Tree/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -91,6 +93,8 @@ class Solution: return height(root) >= 0 ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -192,6 +200,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -223,6 +233,8 @@ function isBalanced(root: TreeNode | null): boolean { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -264,6 +276,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0110.Balanced Binary Tree/README_EN.md b/solution/0100-0199/0110.Balanced Binary Tree/README_EN.md index 0aadf75d7fb17..b5731ec81a100 100644 --- a/solution/0100-0199/0110.Balanced Binary Tree/README_EN.md +++ b/solution/0100-0199/0110.Balanced Binary Tree/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -89,6 +91,8 @@ class Solution: return height(root) >= 0 ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -190,6 +198,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -221,6 +231,8 @@ function isBalanced(root: TreeNode | null): boolean { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -262,6 +274,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0111.Minimum Depth of Binary Tree/README.md b/solution/0100-0199/0111.Minimum Depth of Binary Tree/README.md index 4604110bd3318..49077759f2de0 100644 --- a/solution/0100-0199/0111.Minimum Depth of Binary Tree/README.md +++ b/solution/0100-0199/0111.Minimum Depth of Binary Tree/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -82,6 +84,8 @@ class Solution: return 1 + min(self.minDepth(root.left), self.minDepth(root.right)) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -166,6 +174,8 @@ func minDepth(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -196,6 +206,8 @@ function minDepth(root: TreeNode | null): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -238,6 +250,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -265,6 +279,8 @@ var minDepth = function (root) { }; ``` +#### C + ```c /** * Definition for a binary tree node. @@ -307,6 +323,8 @@ int minDepth(struct TreeNode* root) { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -332,6 +350,8 @@ class Solution: q.append(node.right) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -375,6 +395,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -415,6 +437,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -448,6 +472,8 @@ func minDepth(root *TreeNode) (ans int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -487,6 +513,8 @@ function minDepth(root: TreeNode | null): number { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0111.Minimum Depth of Binary Tree/README_EN.md b/solution/0100-0199/0111.Minimum Depth of Binary Tree/README_EN.md index 39a00f802b533..773a44580087d 100644 --- a/solution/0100-0199/0111.Minimum Depth of Binary Tree/README_EN.md +++ b/solution/0100-0199/0111.Minimum Depth of Binary Tree/README_EN.md @@ -62,6 +62,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -80,6 +82,8 @@ class Solution: return 1 + min(self.minDepth(root.left), self.minDepth(root.right)) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -164,6 +172,8 @@ func minDepth(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -194,6 +204,8 @@ function minDepth(root: TreeNode | null): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -236,6 +248,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -263,6 +277,8 @@ var minDepth = function (root) { }; ``` +#### C + ```c /** * Definition for a binary tree node. @@ -305,6 +321,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -330,6 +348,8 @@ class Solution: q.append(node.right) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -373,6 +393,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -413,6 +435,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -446,6 +470,8 @@ func minDepth(root *TreeNode) (ans int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -485,6 +511,8 @@ function minDepth(root: TreeNode | null): number { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0112.Path Sum/README.md b/solution/0100-0199/0112.Path Sum/README.md index 47665be01c1d5..19bff0caed7c8 100644 --- a/solution/0100-0199/0112.Path Sum/README.md +++ b/solution/0100-0199/0112.Path Sum/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -95,6 +97,8 @@ class Solution: return dfs(root, 0) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -180,6 +188,8 @@ func hasPathSum(root *TreeNode, targetSum int) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -207,6 +217,8 @@ function hasPathSum(root: TreeNode | null, targetSum: number): boolean { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -247,6 +259,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0112.Path Sum/README_EN.md b/solution/0100-0199/0112.Path Sum/README_EN.md index 4c1fa26edd6e8..6d8424fb74661 100644 --- a/solution/0100-0199/0112.Path Sum/README_EN.md +++ b/solution/0100-0199/0112.Path Sum/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(n)$, where $n$ is the number of nodes in the binary tr +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -94,6 +96,8 @@ class Solution: return dfs(root, 0) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -179,6 +187,8 @@ func hasPathSum(root *TreeNode, targetSum int) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -206,6 +216,8 @@ function hasPathSum(root: TreeNode | null, targetSum: number): boolean { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -246,6 +258,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0113.Path Sum II/README.md b/solution/0100-0199/0113.Path Sum II/README.md index cec00a28ac991..9ef212230829e 100644 --- a/solution/0100-0199/0113.Path Sum II/README.md +++ b/solution/0100-0199/0113.Path Sum II/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -203,6 +211,8 @@ func pathSum(root *TreeNode, targetSum int) (ans [][]int) { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -260,6 +270,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0113.Path Sum II/README_EN.md b/solution/0100-0199/0113.Path Sum II/README_EN.md index d690ad4fb39e3..cf3e3d87250f3 100644 --- a/solution/0100-0199/0113.Path Sum II/README_EN.md +++ b/solution/0100-0199/0113.Path Sum II/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(n^2)$, where $n$ is the number of nodes in the binary +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -200,6 +208,8 @@ func pathSum(root *TreeNode, targetSum int) (ans [][]int) { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -257,6 +267,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0114.Flatten Binary Tree to Linked List/README.md b/solution/0100-0199/0114.Flatten Binary Tree to Linked List/README.md index d40047174110b..bc9ad8d7cb7a0 100644 --- a/solution/0100-0199/0114.Flatten Binary Tree to Linked List/README.md +++ b/solution/0100-0199/0114.Flatten Binary Tree to Linked List/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -102,6 +104,8 @@ class Solution: root = root.right ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -197,6 +205,8 @@ func flatten(root *TreeNode) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -231,6 +241,8 @@ function flatten(root: TreeNode | null): void { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -286,6 +298,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -325,6 +339,8 @@ var flatten = function (root) { +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0114.Flatten Binary Tree to Linked List/README_EN.md b/solution/0100-0199/0114.Flatten Binary Tree to Linked List/README_EN.md index 632b69926ec64..9d5d23b05f3b7 100644 --- a/solution/0100-0199/0114.Flatten Binary Tree to Linked List/README_EN.md +++ b/solution/0100-0199/0114.Flatten Binary Tree to Linked List/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(n)$, where $n$ is the number of nodes in the tree. The +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -99,6 +101,8 @@ class Solution: root = root.right ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -194,6 +202,8 @@ func flatten(root *TreeNode) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -228,6 +238,8 @@ function flatten(root: TreeNode | null): void { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -283,6 +295,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -322,6 +336,8 @@ var flatten = function (root) { +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0115.Distinct Subsequences/README.md b/solution/0100-0199/0115.Distinct Subsequences/README.md index dc184c8785a07..b83f98dc83184 100644 --- a/solution/0100-0199/0115.Distinct Subsequences/README.md +++ b/solution/0100-0199/0115.Distinct Subsequences/README.md @@ -89,6 +89,8 @@ $$ +#### Python3 + ```python class Solution: def numDistinct(self, s: str, t: str) -> int: @@ -104,6 +106,8 @@ class Solution: return f[m][n] ``` +#### Java + ```java class Solution { public int numDistinct(String s, String t) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func numDistinct(s string, t string) int { m, n := len(s), len(t) @@ -170,6 +178,8 @@ func numDistinct(s string, t string) int { } ``` +#### TypeScript + ```ts function numDistinct(s: string, t: string): number { const m = s.length; @@ -190,6 +200,8 @@ function numDistinct(s: string, t: string): number { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -229,6 +241,8 @@ impl Solution { +#### Python3 + ```python class Solution: def numDistinct(self, s: str, t: str) -> int: @@ -241,6 +255,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int numDistinct(String s, String t) { @@ -260,6 +276,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -281,6 +299,8 @@ public: }; ``` +#### Go + ```go func numDistinct(s string, t string) int { n := len(t) @@ -297,6 +317,8 @@ func numDistinct(s string, t string) int { } ``` +#### TypeScript + ```ts function numDistinct(s: string, t: string): number { const n = t.length; diff --git a/solution/0100-0199/0115.Distinct Subsequences/README_EN.md b/solution/0100-0199/0115.Distinct Subsequences/README_EN.md index 16e2def2c7403..68c97f3564e30 100644 --- a/solution/0100-0199/0115.Distinct Subsequences/README_EN.md +++ b/solution/0100-0199/0115.Distinct Subsequences/README_EN.md @@ -89,6 +89,8 @@ We notice that the calculation of $f[i][j]$ is only related to $f[i-1][..]$. The +#### Python3 + ```python class Solution: def numDistinct(self, s: str, t: str) -> int: @@ -104,6 +106,8 @@ class Solution: return f[m][n] ``` +#### Java + ```java class Solution { public int numDistinct(String s, String t) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func numDistinct(s string, t string) int { m, n := len(s), len(t) @@ -170,6 +178,8 @@ func numDistinct(s string, t string) int { } ``` +#### TypeScript + ```ts function numDistinct(s: string, t: string): number { const m = s.length; @@ -190,6 +200,8 @@ function numDistinct(s: string, t: string): number { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -229,6 +241,8 @@ impl Solution { +#### Python3 + ```python class Solution: def numDistinct(self, s: str, t: str) -> int: @@ -241,6 +255,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int numDistinct(String s, String t) { @@ -260,6 +276,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -281,6 +299,8 @@ public: }; ``` +#### Go + ```go func numDistinct(s string, t string) int { n := len(t) @@ -297,6 +317,8 @@ func numDistinct(s string, t string) int { } ``` +#### TypeScript + ```ts function numDistinct(s: string, t: string): number { const n = t.length; diff --git a/solution/0100-0199/0116.Populating Next Right Pointers in Each Node/README.md b/solution/0100-0199/0116.Populating Next Right Pointers in Each Node/README.md index 5aa51b7be3bca..c0dcf3037f6d9 100644 --- a/solution/0100-0199/0116.Populating Next Right Pointers in Each Node/README.md +++ b/solution/0100-0199/0116.Populating Next Right Pointers in Each Node/README.md @@ -87,6 +87,8 @@ struct Node { +#### Python3 + ```python """ # Definition for a Node. @@ -118,6 +120,8 @@ class Solution: return root ``` +#### Java + ```java /* // Definition for a Node. @@ -170,6 +174,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -218,6 +224,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -255,6 +263,8 @@ func connect(root *Node) *Node { } ``` +#### TypeScript + ```ts /** * Definition for Node. @@ -303,6 +313,8 @@ function connect(root: Node | null): Node | null { +#### Python3 + ```python """ # Definition for a Node. @@ -330,6 +342,8 @@ class Solution: return root ``` +#### Java + ```java /* // Definition for a Node. @@ -374,6 +388,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -413,6 +429,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -442,6 +460,8 @@ func connect(root *Node) *Node { } ``` +#### TypeScript + ```ts /** * Definition for Node. diff --git a/solution/0100-0199/0116.Populating Next Right Pointers in Each Node/README_EN.md b/solution/0100-0199/0116.Populating Next Right Pointers in Each Node/README_EN.md index b4a23d0ff0151..30c441eb92cdc 100644 --- a/solution/0100-0199/0116.Populating Next Right Pointers in Each Node/README_EN.md +++ b/solution/0100-0199/0116.Populating Next Right Pointers in Each Node/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python """ # Definition for a Node. @@ -112,6 +114,8 @@ class Solution: return root ``` +#### Java + ```java /* // Definition for a Node. @@ -164,6 +168,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -212,6 +218,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -249,6 +257,8 @@ func connect(root *Node) *Node { } ``` +#### TypeScript + ```ts /** * Definition for Node. @@ -297,6 +307,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python """ # Definition for a Node. @@ -324,6 +336,8 @@ class Solution: return root ``` +#### Java + ```java /* // Definition for a Node. @@ -368,6 +382,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -407,6 +423,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -436,6 +454,8 @@ func connect(root *Node) *Node { } ``` +#### TypeScript + ```ts /** * Definition for Node. diff --git a/solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/README.md b/solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/README.md index f5cd85bf5e6d8..7ea4dc4badcf5 100644 --- a/solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/README.md +++ b/solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/README.md @@ -83,6 +83,8 @@ struct Node { +#### Python3 + ```python """ # Definition for a Node. @@ -114,6 +116,8 @@ class Solution: return root ``` +#### Java + ```java /* // Definition for a Node. @@ -166,6 +170,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -214,6 +220,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -251,6 +259,8 @@ func connect(root *Node) *Node { } ``` +#### TypeScript + ```ts /** * Definition for Node. @@ -291,6 +301,8 @@ function connect(root: Node | null): Node | null { } ``` +#### C# + ```cs /* // Definition for a Node. @@ -359,6 +371,8 @@ public class Solution { +#### Python3 + ```python """ # Definition for a Node. @@ -393,6 +407,8 @@ class Solution: return root ``` +#### Java + ```java /* // Definition for a Node. @@ -450,6 +466,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -501,6 +519,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -540,6 +560,8 @@ func connect(root *Node) *Node { } ``` +#### TypeScript + ```ts /** * Definition for Node. @@ -583,6 +605,8 @@ function connect(root: Node | null): Node | null { } ``` +#### C# + ```cs /* // Definition for a Node. diff --git a/solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/README_EN.md b/solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/README_EN.md index 211f7e670163f..a7373f198dc44 100644 --- a/solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/README_EN.md +++ b/solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python """ # Definition for a Node. @@ -112,6 +114,8 @@ class Solution: return root ``` +#### Java + ```java /* // Definition for a Node. @@ -164,6 +168,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -212,6 +218,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -249,6 +257,8 @@ func connect(root *Node) *Node { } ``` +#### TypeScript + ```ts /** * Definition for Node. @@ -289,6 +299,8 @@ function connect(root: Node | null): Node | null { } ``` +#### C# + ```cs /* // Definition for a Node. @@ -357,6 +369,8 @@ The time complexity is $O(n)$, where $n$ is the number of nodes in the binary tr +#### Python3 + ```python """ # Definition for a Node. @@ -391,6 +405,8 @@ class Solution: return root ``` +#### Java + ```java /* // Definition for a Node. @@ -448,6 +464,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -499,6 +517,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -538,6 +558,8 @@ func connect(root *Node) *Node { } ``` +#### TypeScript + ```ts /** * Definition for Node. @@ -581,6 +603,8 @@ function connect(root: Node | null): Node | null { } ``` +#### C# + ```cs /* // Definition for a Node. diff --git a/solution/0100-0199/0118.Pascal's Triangle/README.md b/solution/0100-0199/0118.Pascal's Triangle/README.md index 710598994f056..fd03f8d453b2d 100644 --- a/solution/0100-0199/0118.Pascal's Triangle/README.md +++ b/solution/0100-0199/0118.Pascal's Triangle/README.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def generate(self, numRows: int) -> List[List[int]]: @@ -71,6 +73,8 @@ class Solution: return f ``` +#### Java + ```java class Solution { public List> generate(int numRows) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func generate(numRows int) [][]int { f := [][]int{[]int{1}} @@ -125,6 +133,8 @@ func generate(numRows int) [][]int { } ``` +#### TypeScript + ```ts function generate(numRows: number): number[][] { const f: number[][] = [[1]]; @@ -140,6 +150,8 @@ function generate(numRows: number): number[][] { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -161,6 +173,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} numRows diff --git a/solution/0100-0199/0118.Pascal's Triangle/README_EN.md b/solution/0100-0199/0118.Pascal's Triangle/README_EN.md index c28ef819cfa84..f98f9bb00258a 100644 --- a/solution/0100-0199/0118.Pascal's Triangle/README_EN.md +++ b/solution/0100-0199/0118.Pascal's Triangle/README_EN.md @@ -50,6 +50,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$. Here, $n$ +#### Python3 + ```python class Solution: def generate(self, numRows: int) -> List[List[int]]: @@ -60,6 +62,8 @@ class Solution: return f ``` +#### Java + ```java class Solution { public List> generate(int numRows) { @@ -79,6 +83,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -99,6 +105,8 @@ public: }; ``` +#### Go + ```go func generate(numRows int) [][]int { f := [][]int{[]int{1}} @@ -114,6 +122,8 @@ func generate(numRows int) [][]int { } ``` +#### TypeScript + ```ts function generate(numRows: number): number[][] { const f: number[][] = [[1]]; @@ -129,6 +139,8 @@ function generate(numRows: number): number[][] { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -150,6 +162,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} numRows diff --git a/solution/0100-0199/0119.Pascal's Triangle II/README.md b/solution/0100-0199/0119.Pascal's Triangle II/README.md index 5d34645f6fb3c..5009baf0ed36d 100644 --- a/solution/0100-0199/0119.Pascal's Triangle II/README.md +++ b/solution/0100-0199/0119.Pascal's Triangle II/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def getRow(self, rowIndex: int) -> List[int]: @@ -88,6 +90,8 @@ class Solution: return f ``` +#### Java + ```java class Solution { public List getRow(int rowIndex) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func getRow(rowIndex int) []int { f := make([]int, rowIndex+1) @@ -135,6 +143,8 @@ func getRow(rowIndex int) []int { } ``` +#### TypeScript + ```ts function getRow(rowIndex: number): number[] { const f: number[] = Array(rowIndex + 1).fill(1); @@ -147,6 +157,8 @@ function getRow(rowIndex: number): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn get_row(row_index: i32) -> Vec { diff --git a/solution/0100-0199/0119.Pascal's Triangle II/README_EN.md b/solution/0100-0199/0119.Pascal's Triangle II/README_EN.md index 86eff74d24949..625760e327d21 100644 --- a/solution/0100-0199/0119.Pascal's Triangle II/README_EN.md +++ b/solution/0100-0199/0119.Pascal's Triangle II/README_EN.md @@ -60,6 +60,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$. Here, $n$ i +#### Python3 + ```python class Solution: def getRow(self, rowIndex: int) -> List[int]: @@ -70,6 +72,8 @@ class Solution: return f ``` +#### Java + ```java class Solution { public List getRow(int rowIndex) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -102,6 +108,8 @@ public: }; ``` +#### Go + ```go func getRow(rowIndex int) []int { f := make([]int, rowIndex+1) @@ -117,6 +125,8 @@ func getRow(rowIndex int) []int { } ``` +#### TypeScript + ```ts function getRow(rowIndex: number): number[] { const f: number[] = Array(rowIndex + 1).fill(1); @@ -129,6 +139,8 @@ function getRow(rowIndex: number): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn get_row(row_index: i32) -> Vec { diff --git a/solution/0100-0199/0120.Triangle/README.md b/solution/0100-0199/0120.Triangle/README.md index f7d63923c53e3..732aadca5a4fd 100644 --- a/solution/0100-0199/0120.Triangle/README.md +++ b/solution/0100-0199/0120.Triangle/README.md @@ -86,6 +86,8 @@ $$ +#### Python3 + ```python class Solution: def minimumTotal(self, triangle: List[List[int]]) -> int: @@ -97,6 +99,8 @@ class Solution: return f[0][0] ``` +#### Java + ```java class Solution { public int minimumTotal(List> triangle) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func minimumTotal(triangle [][]int) int { n := len(triangle) @@ -142,6 +150,8 @@ func minimumTotal(triangle [][]int) int { } ``` +#### TypeScript + ```ts function minimumTotal(triangle: number[][]): number { const n = triangle.length; @@ -155,6 +165,8 @@ function minimumTotal(triangle: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn minimum_total(triangle: Vec>) -> i32 { @@ -180,6 +192,8 @@ impl Solution { +#### Python3 + ```python class Solution: def minimumTotal(self, triangle: List[List[int]]) -> int: @@ -191,6 +205,8 @@ class Solution: return f[0] ``` +#### Java + ```java class Solution { public int minimumTotal(List> triangle) { @@ -206,6 +222,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -220,6 +238,8 @@ public: }; ``` +#### Go + ```go func minimumTotal(triangle [][]int) int { for i := len(triangle) - 2; i >= 0; i-- { @@ -231,6 +251,8 @@ func minimumTotal(triangle [][]int) int { } ``` +#### TypeScript + ```ts function minimumTotal(triangle: number[][]): number { for (let i = triangle.length - 2; ~i; --i) { @@ -242,6 +264,8 @@ function minimumTotal(triangle: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn minimum_total(triangle: Vec>) -> i32 { @@ -266,6 +290,8 @@ impl Solution { +#### Python3 + ```python class Solution: def minimumTotal(self, triangle: List[List[int]]) -> int: diff --git a/solution/0100-0199/0120.Triangle/README_EN.md b/solution/0100-0199/0120.Triangle/README_EN.md index 6fa3394cf9775..29ff0a93f9e00 100644 --- a/solution/0100-0199/0120.Triangle/README_EN.md +++ b/solution/0100-0199/0120.Triangle/README_EN.md @@ -79,6 +79,8 @@ Furthermore, we can directly reuse the `triangle` as the `f` array, so there is +#### Python3 + ```python class Solution: def minimumTotal(self, triangle: List[List[int]]) -> int: @@ -90,6 +92,8 @@ class Solution: return f[0][0] ``` +#### Java + ```java class Solution { public int minimumTotal(List> triangle) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func minimumTotal(triangle [][]int) int { n := len(triangle) @@ -135,6 +143,8 @@ func minimumTotal(triangle [][]int) int { } ``` +#### TypeScript + ```ts function minimumTotal(triangle: number[][]): number { const n = triangle.length; @@ -148,6 +158,8 @@ function minimumTotal(triangle: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn minimum_total(triangle: Vec>) -> i32 { @@ -173,6 +185,8 @@ impl Solution { +#### Python3 + ```python class Solution: def minimumTotal(self, triangle: List[List[int]]) -> int: @@ -184,6 +198,8 @@ class Solution: return f[0] ``` +#### Java + ```java class Solution { public int minimumTotal(List> triangle) { @@ -199,6 +215,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -213,6 +231,8 @@ public: }; ``` +#### Go + ```go func minimumTotal(triangle [][]int) int { for i := len(triangle) - 2; i >= 0; i-- { @@ -224,6 +244,8 @@ func minimumTotal(triangle [][]int) int { } ``` +#### TypeScript + ```ts function minimumTotal(triangle: number[][]): number { for (let i = triangle.length - 2; ~i; --i) { @@ -235,6 +257,8 @@ function minimumTotal(triangle: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn minimum_total(triangle: Vec>) -> i32 { @@ -259,6 +283,8 @@ impl Solution { +#### Python3 + ```python class Solution: def minimumTotal(self, triangle: List[List[int]]) -> int: diff --git a/solution/0100-0199/0121.Best Time to Buy and Sell Stock/README.md b/solution/0100-0199/0121.Best Time to Buy and Sell Stock/README.md index bd8b2eb3f260b..be87561b79f96 100644 --- a/solution/0100-0199/0121.Best Time to Buy and Sell Stock/README.md +++ b/solution/0100-0199/0121.Best Time to Buy and Sell Stock/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def maxProfit(self, prices: List[int]) -> int: @@ -79,6 +81,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxProfit(int[] prices) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func maxProfit(prices []int) (ans int) { mi := prices[0] @@ -117,6 +125,8 @@ func maxProfit(prices []int) (ans int) { } ``` +#### TypeScript + ```ts function maxProfit(prices: number[]): number { let ans = 0; @@ -129,6 +139,8 @@ function maxProfit(prices: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_profit(prices: Vec) -> i32 { @@ -143,6 +155,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} prices @@ -159,6 +173,8 @@ var maxProfit = function (prices) { }; ``` +#### C# + ```cs public class Solution { public int MaxProfit(int[] prices) { @@ -172,6 +188,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0100-0199/0121.Best Time to Buy and Sell Stock/README_EN.md b/solution/0100-0199/0121.Best Time to Buy and Sell Stock/README_EN.md index 420e8ae8b8200..0422ffacb6964 100644 --- a/solution/0100-0199/0121.Best Time to Buy and Sell Stock/README_EN.md +++ b/solution/0100-0199/0121.Best Time to Buy and Sell Stock/README_EN.md @@ -67,6 +67,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def maxProfit(self, prices: List[int]) -> int: @@ -77,6 +79,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxProfit(int[] prices) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -104,6 +110,8 @@ public: }; ``` +#### Go + ```go func maxProfit(prices []int) (ans int) { mi := prices[0] @@ -115,6 +123,8 @@ func maxProfit(prices []int) (ans int) { } ``` +#### TypeScript + ```ts function maxProfit(prices: number[]): number { let ans = 0; @@ -127,6 +137,8 @@ function maxProfit(prices: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_profit(prices: Vec) -> i32 { @@ -141,6 +153,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} prices @@ -157,6 +171,8 @@ var maxProfit = function (prices) { }; ``` +#### C# + ```cs public class Solution { public int MaxProfit(int[] prices) { @@ -170,6 +186,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/README.md b/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/README.md index 19c973599d386..cdd785fc5b755 100644 --- a/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/README.md +++ b/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/README.md @@ -73,12 +73,16 @@ tags: +#### Python3 + ```python class Solution: def maxProfit(self, prices: List[int]) -> int: return sum(max(0, b - a) for a, b in pairwise(prices)) ``` +#### Java + ```java class Solution { public int maxProfit(int[] prices) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -102,6 +108,8 @@ public: }; ``` +#### Go + ```go func maxProfit(prices []int) (ans int) { for i, v := range prices[1:] { @@ -114,6 +122,8 @@ func maxProfit(prices []int) (ans int) { } ``` +#### TypeScript + ```ts function maxProfit(prices: number[]): number { let ans = 0; @@ -124,6 +134,8 @@ function maxProfit(prices: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_profit(prices: Vec) -> i32 { @@ -136,6 +148,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} prices @@ -150,6 +164,8 @@ var maxProfit = function (prices) { }; ``` +#### C# + ```cs public class Solution { public int MaxProfit(int[] prices) { @@ -191,6 +207,8 @@ $$ +#### Python3 + ```python class Solution: def maxProfit(self, prices: List[int]) -> int: @@ -203,6 +221,8 @@ class Solution: return f[n - 1][1] ``` +#### Java + ```java class Solution { public int maxProfit(int[] prices) { @@ -218,6 +238,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -235,6 +257,8 @@ public: }; ``` +#### Go + ```go func maxProfit(prices []int) int { n := len(prices) @@ -248,6 +272,8 @@ func maxProfit(prices []int) int { } ``` +#### C# + ```cs public class Solution { public int MaxProfit(int[] prices) { @@ -276,6 +302,8 @@ public class Solution { +#### Python3 + ```python class Solution: def maxProfit(self, prices: List[int]) -> int: @@ -289,6 +317,8 @@ class Solution: return f[1] ``` +#### Java + ```java class Solution { public int maxProfit(int[] prices) { @@ -305,6 +335,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -322,6 +354,8 @@ public: }; ``` +#### Go + ```go func maxProfit(prices []int) int { n := len(prices) diff --git a/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/README_EN.md b/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/README_EN.md index d22fd4770b2ad..fb75e3167f6aa 100644 --- a/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/README_EN.md +++ b/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/README_EN.md @@ -74,12 +74,16 @@ The time complexity is $O(n)$, where $n$ is the length of the `prices` array. Th +#### Python3 + ```python class Solution: def maxProfit(self, prices: List[int]) -> int: return sum(max(0, b - a) for a, b in pairwise(prices)) ``` +#### Java + ```java class Solution { public int maxProfit(int[] prices) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -103,6 +109,8 @@ public: }; ``` +#### Go + ```go func maxProfit(prices []int) (ans int) { for i, v := range prices[1:] { @@ -115,6 +123,8 @@ func maxProfit(prices []int) (ans int) { } ``` +#### TypeScript + ```ts function maxProfit(prices: number[]): number { let ans = 0; @@ -125,6 +135,8 @@ function maxProfit(prices: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_profit(prices: Vec) -> i32 { @@ -137,6 +149,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} prices @@ -151,6 +165,8 @@ var maxProfit = function (prices) { }; ``` +#### C# + ```cs public class Solution { public int MaxProfit(int[] prices) { @@ -192,6 +208,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def maxProfit(self, prices: List[int]) -> int: @@ -204,6 +222,8 @@ class Solution: return f[n - 1][1] ``` +#### Java + ```java class Solution { public int maxProfit(int[] prices) { @@ -219,6 +239,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -236,6 +258,8 @@ public: }; ``` +#### Go + ```go func maxProfit(prices []int) int { n := len(prices) @@ -249,6 +273,8 @@ func maxProfit(prices []int) int { } ``` +#### C# + ```cs public class Solution { public int MaxProfit(int[] prices) { @@ -277,6 +303,8 @@ The time complexity is $O(n)$, where $n$ is the length of the `prices` array. Th +#### Python3 + ```python class Solution: def maxProfit(self, prices: List[int]) -> int: @@ -290,6 +318,8 @@ class Solution: return f[1] ``` +#### Java + ```java class Solution { public int maxProfit(int[] prices) { @@ -306,6 +336,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -323,6 +355,8 @@ public: }; ``` +#### Go + ```go func maxProfit(prices []int) int { n := len(prices) diff --git a/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/README.md b/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/README.md index 9635bfa7252da..5ba2210539f67 100644 --- a/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/README.md +++ b/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def maxProfit(self, prices: List[int]) -> int: @@ -102,6 +104,8 @@ class Solution: return f4 ``` +#### Java + ```java class Solution { public int maxProfit(int[] prices) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func maxProfit(prices []int) int { f1, f2, f3, f4 := -prices[0], 0, -prices[0], 0 @@ -147,6 +155,8 @@ func maxProfit(prices []int) int { } ``` +#### TypeScript + ```ts function maxProfit(prices: number[]): number { let [f1, f2, f3, f4] = [-prices[0], 0, -prices[0], 0]; @@ -160,6 +170,8 @@ function maxProfit(prices: number[]): number { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -182,6 +194,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int MaxProfit(int[] prices) { diff --git a/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/README_EN.md b/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/README_EN.md index 097ecbfd6e763..8699a4a161f75 100644 --- a/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/README_EN.md +++ b/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(n)$, where $n$ is the length of the `prices` array. Th +#### Python3 + ```python class Solution: def maxProfit(self, prices: List[int]) -> int: @@ -93,6 +95,8 @@ class Solution: return f4 ``` +#### Java + ```java class Solution { public int maxProfit(int[] prices) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func maxProfit(prices []int) int { f1, f2, f3, f4 := -prices[0], 0, -prices[0], 0 @@ -138,6 +146,8 @@ func maxProfit(prices []int) int { } ``` +#### TypeScript + ```ts function maxProfit(prices: number[]): number { let [f1, f2, f3, f4] = [-prices[0], 0, -prices[0], 0]; @@ -151,6 +161,8 @@ function maxProfit(prices: number[]): number { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -173,6 +185,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int MaxProfit(int[] prices) { diff --git a/solution/0100-0199/0124.Binary Tree Maximum Path Sum/README.md b/solution/0100-0199/0124.Binary Tree Maximum Path Sum/README.md index 5eb7f3be013e5..0f080cd3e1810 100644 --- a/solution/0100-0199/0124.Binary Tree Maximum Path Sum/README.md +++ b/solution/0100-0199/0124.Binary Tree Maximum Path Sum/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -197,6 +205,8 @@ func maxPathSum(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -228,6 +238,8 @@ function maxPathSum(root: TreeNode | null): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -269,6 +281,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -298,6 +312,8 @@ var maxPathSum = function (root) { }; ``` +#### C# + ```cs /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0124.Binary Tree Maximum Path Sum/README_EN.md b/solution/0100-0199/0124.Binary Tree Maximum Path Sum/README_EN.md index 9de83283d02ce..ff1ea56cab05c 100644 --- a/solution/0100-0199/0124.Binary Tree Maximum Path Sum/README_EN.md +++ b/solution/0100-0199/0124.Binary Tree Maximum Path Sum/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -103,6 +105,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -196,6 +204,8 @@ func maxPathSum(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -227,6 +237,8 @@ function maxPathSum(root: TreeNode | null): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -268,6 +280,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -297,6 +311,8 @@ var maxPathSum = function (root) { }; ``` +#### C# + ```cs /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0125.Valid Palindrome/README.md b/solution/0100-0199/0125.Valid Palindrome/README.md index 078106b193e95..7e33e18f767d6 100644 --- a/solution/0100-0199/0125.Valid Palindrome/README.md +++ b/solution/0100-0199/0125.Valid Palindrome/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def isPalindrome(self, s: str) -> bool: @@ -96,6 +98,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isPalindrome(String s) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func isPalindrome(s string) bool { i, j := 0, len(s)-1 @@ -168,6 +176,8 @@ func tolower(ch byte) byte { } ``` +#### TypeScript + ```ts function isPalindrome(s: string): boolean { let i = 0; @@ -188,6 +198,8 @@ function isPalindrome(s: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn is_palindrome(s: String) -> bool { @@ -215,6 +227,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -239,6 +253,8 @@ var isPalindrome = function (s) { }; ``` +#### C# + ```cs public class Solution { public bool IsPalindrome(string s) { @@ -257,6 +273,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0100-0199/0125.Valid Palindrome/README_EN.md b/solution/0100-0199/0125.Valid Palindrome/README_EN.md index 19a03c7f466f7..79ecce67332ea 100644 --- a/solution/0100-0199/0125.Valid Palindrome/README_EN.md +++ b/solution/0100-0199/0125.Valid Palindrome/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string $s$. The sp +#### Python3 + ```python class Solution: def isPalindrome(self, s: str) -> bool: @@ -92,6 +94,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isPalindrome(String s) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func isPalindrome(s string) bool { i, j := 0, len(s)-1 @@ -164,6 +172,8 @@ func tolower(ch byte) byte { } ``` +#### TypeScript + ```ts function isPalindrome(s: string): boolean { let i = 0; @@ -184,6 +194,8 @@ function isPalindrome(s: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn is_palindrome(s: String) -> bool { @@ -211,6 +223,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -235,6 +249,8 @@ var isPalindrome = function (s) { }; ``` +#### C# + ```cs public class Solution { public bool IsPalindrome(string s) { @@ -253,6 +269,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0100-0199/0126.Word Ladder II/README.md b/solution/0100-0199/0126.Word Ladder II/README.md index 5e1a2cb5f921f..37711c8797631 100644 --- a/solution/0100-0199/0126.Word Ladder II/README.md +++ b/solution/0100-0199/0126.Word Ladder II/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def findLadders( @@ -128,6 +130,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans; @@ -197,6 +201,8 @@ class Solution { } ``` +#### Go + ```go func findLadders(beginWord string, endWord string, wordList []string) [][]string { var ans [][]string diff --git a/solution/0100-0199/0126.Word Ladder II/README_EN.md b/solution/0100-0199/0126.Word Ladder II/README_EN.md index 9547afa0ca898..25409b72c8ff6 100644 --- a/solution/0100-0199/0126.Word Ladder II/README_EN.md +++ b/solution/0100-0199/0126.Word Ladder II/README_EN.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def findLadders( @@ -123,6 +125,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans; @@ -192,6 +196,8 @@ class Solution { } ``` +#### Go + ```go func findLadders(beginWord string, endWord string, wordList []string) [][]string { var ans [][]string diff --git a/solution/0100-0199/0127.Word Ladder/README.md b/solution/0100-0199/0127.Word Ladder/README.md index b6c65452b60f9..6551ffc89ddb6 100644 --- a/solution/0100-0199/0127.Word Ladder/README.md +++ b/solution/0100-0199/0127.Word Ladder/README.md @@ -102,6 +102,8 @@ def extend(m1, m2, q): +#### Python3 + ```python class Solution: def ladderLength(self, beginWord: str, endWord: str, wordList: List[str]) -> int: @@ -128,6 +130,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { public int ladderLength(String beginWord, String endWord, List wordList) { @@ -163,6 +167,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go func ladderLength(beginWord string, endWord string, wordList []string) int { words := make(map[string]bool) @@ -229,6 +237,8 @@ func ladderLength(beginWord string, endWord string, wordList []string) int { } ``` +#### C# + ```cs using System.Collections; using System.Collections.Generic; @@ -310,6 +320,8 @@ public class Solution { +#### Python3 + ```python class Solution: def ladderLength(self, beginWord: str, endWord: str, wordList: List[str]) -> int: @@ -344,6 +356,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { private Set words; @@ -397,6 +411,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -438,6 +454,8 @@ public: }; ``` +#### Go + ```go func ladderLength(beginWord string, endWord string, wordList []string) int { words := make(map[string]bool) diff --git a/solution/0100-0199/0127.Word Ladder/README_EN.md b/solution/0100-0199/0127.Word Ladder/README_EN.md index ff2f1a1966720..db2d6c3b46c5a 100644 --- a/solution/0100-0199/0127.Word Ladder/README_EN.md +++ b/solution/0100-0199/0127.Word Ladder/README_EN.md @@ -102,6 +102,8 @@ def extend(m1, m2, q): +#### Python3 + ```python class Solution: def ladderLength(self, beginWord: str, endWord: str, wordList: List[str]) -> int: @@ -128,6 +130,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { public int ladderLength(String beginWord, String endWord, List wordList) { @@ -163,6 +167,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go func ladderLength(beginWord string, endWord string, wordList []string) int { words := make(map[string]bool) @@ -229,6 +237,8 @@ func ladderLength(beginWord string, endWord string, wordList []string) int { } ``` +#### C# + ```cs using System.Collections; using System.Collections.Generic; @@ -310,6 +320,8 @@ public class Solution { +#### Python3 + ```python class Solution: def ladderLength(self, beginWord: str, endWord: str, wordList: List[str]) -> int: @@ -344,6 +356,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { private Set words; @@ -397,6 +411,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -438,6 +454,8 @@ public: }; ``` +#### Go + ```go func ladderLength(beginWord string, endWord string, wordList []string) int { words := make(map[string]bool) diff --git a/solution/0100-0199/0128.Longest Consecutive Sequence/README.md b/solution/0100-0199/0128.Longest Consecutive Sequence/README.md index 4d0645079cb47..56b5db7e564f2 100644 --- a/solution/0100-0199/0128.Longest Consecutive Sequence/README.md +++ b/solution/0100-0199/0128.Longest Consecutive Sequence/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def longestConsecutive(self, nums: List[int]) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestConsecutive(int[] nums) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func longestConsecutive(nums []int) int { n := len(nums) @@ -160,6 +168,8 @@ func longestConsecutive(nums []int) int { } ``` +#### TypeScript + ```ts function longestConsecutive(nums: number[]): number { const n = nums.length; @@ -183,6 +193,8 @@ function longestConsecutive(nums: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashSet; @@ -214,6 +226,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -255,6 +269,8 @@ var longestConsecutive = function (nums) { +#### Python3 + ```python class Solution: def longestConsecutive(self, nums: List[int]) -> int: @@ -269,6 +285,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestConsecutive(int[] nums) { @@ -291,6 +309,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -311,6 +331,8 @@ public: }; ``` +#### Go + ```go func longestConsecutive(nums []int) (ans int) { s := map[int]bool{} @@ -330,6 +352,8 @@ func longestConsecutive(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function longestConsecutive(nums: number[]): number { const s: Set = new Set(nums); @@ -347,6 +371,8 @@ function longestConsecutive(nums: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0100-0199/0128.Longest Consecutive Sequence/README_EN.md b/solution/0100-0199/0128.Longest Consecutive Sequence/README_EN.md index f3a5b0cbe1f15..4666536ca47ba 100644 --- a/solution/0100-0199/0128.Longest Consecutive Sequence/README_EN.md +++ b/solution/0100-0199/0128.Longest Consecutive Sequence/README_EN.md @@ -68,6 +68,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def longestConsecutive(self, nums: List[int]) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestConsecutive(int[] nums) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func longestConsecutive(nums []int) int { n := len(nums) @@ -159,6 +167,8 @@ func longestConsecutive(nums []int) int { } ``` +#### TypeScript + ```ts function longestConsecutive(nums: number[]): number { const n = nums.length; @@ -182,6 +192,8 @@ function longestConsecutive(nums: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashSet; @@ -213,6 +225,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -254,6 +268,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def longestConsecutive(self, nums: List[int]) -> int: @@ -268,6 +284,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestConsecutive(int[] nums) { @@ -290,6 +308,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -310,6 +330,8 @@ public: }; ``` +#### Go + ```go func longestConsecutive(nums []int) (ans int) { s := map[int]bool{} @@ -329,6 +351,8 @@ func longestConsecutive(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function longestConsecutive(nums: number[]): number { const s: Set = new Set(nums); @@ -346,6 +370,8 @@ function longestConsecutive(nums: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0100-0199/0129.Sum Root to Leaf Numbers/README.md b/solution/0100-0199/0129.Sum Root to Leaf Numbers/README.md index 6d65b91433fc2..47d1c5a5da7b9 100644 --- a/solution/0100-0199/0129.Sum Root to Leaf Numbers/README.md +++ b/solution/0100-0199/0129.Sum Root to Leaf Numbers/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -109,6 +111,8 @@ class Solution: return dfs(root, 0) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -194,6 +202,8 @@ func sumNumbers(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -220,6 +230,8 @@ function sumNumbers(root: TreeNode | null): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -260,6 +272,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -284,6 +298,8 @@ var sumNumbers = function (root) { }; ``` +#### C + ```c /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0129.Sum Root to Leaf Numbers/README_EN.md b/solution/0100-0199/0129.Sum Root to Leaf Numbers/README_EN.md index 147c6d057f6df..8de2f6e3f32d1 100644 --- a/solution/0100-0199/0129.Sum Root to Leaf Numbers/README_EN.md +++ b/solution/0100-0199/0129.Sum Root to Leaf Numbers/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n)$, and the space complexity is $O(\log n)$. Here, $n +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -104,6 +106,8 @@ class Solution: return dfs(root, 0) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -189,6 +197,8 @@ func sumNumbers(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -215,6 +225,8 @@ function sumNumbers(root: TreeNode | null): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -255,6 +267,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -279,6 +293,8 @@ var sumNumbers = function (root) { }; ``` +#### C + ```c /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0130.Surrounded Regions/README.md b/solution/0100-0199/0130.Surrounded Regions/README.md index 9bac553f4668d..fe9b7fb6a4b2d 100644 --- a/solution/0100-0199/0130.Surrounded Regions/README.md +++ b/solution/0100-0199/0130.Surrounded Regions/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def solve(self, board: List[List[str]]) -> None: @@ -98,6 +100,8 @@ class Solution: board[i][j] = "X" ``` +#### Java + ```java class Solution { private final int[] dirs = {-1, 0, 1, 0, -1}; @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go func solve(board [][]byte) { m, n := len(board), len(board[0]) @@ -210,6 +218,8 @@ func solve(board [][]byte) { } ``` +#### TypeScript + ```ts function solve(board: string[][]): void { const m = board.length; @@ -244,6 +254,8 @@ function solve(board: string[][]): void { } ``` +#### Rust + ```rust impl Solution { pub fn solve(board: &mut Vec>) { @@ -296,6 +308,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { private readonly int[] dirs = {-1, 0, 1, 0, -1}; @@ -356,6 +370,8 @@ public class Solution { +#### Python3 + ```python class Solution: def solve(self, board: List[List[str]]) -> None: @@ -382,6 +398,8 @@ class Solution: board[i][j] = "X" ``` +#### Java + ```java class Solution { private int[] p; @@ -429,6 +447,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -468,6 +488,8 @@ public: }; ``` +#### Go + ```go func solve(board [][]byte) { m, n := len(board), len(board[0]) @@ -509,6 +531,8 @@ func solve(board [][]byte) { } ``` +#### TypeScript + ```ts function solve(board: string[][]): void { const m = board.length; diff --git a/solution/0100-0199/0130.Surrounded Regions/README_EN.md b/solution/0100-0199/0130.Surrounded Regions/README_EN.md index b6bdb2986d1a4..c89451fa7d638 100644 --- a/solution/0100-0199/0130.Surrounded Regions/README_EN.md +++ b/solution/0100-0199/0130.Surrounded Regions/README_EN.md @@ -73,6 +73,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def solve(self, board: List[List[str]]) -> None: @@ -98,6 +100,8 @@ class Solution: board[i][j] = "X" ``` +#### Java + ```java class Solution { private final int[] dirs = {-1, 0, 1, 0, -1}; @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go func solve(board [][]byte) { m, n := len(board), len(board[0]) @@ -210,6 +218,8 @@ func solve(board [][]byte) { } ``` +#### TypeScript + ```ts function solve(board: string[][]): void { const m = board.length; @@ -244,6 +254,8 @@ function solve(board: string[][]): void { } ``` +#### Rust + ```rust impl Solution { pub fn solve(board: &mut Vec>) { @@ -296,6 +308,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { private readonly int[] dirs = {-1, 0, 1, 0, -1}; @@ -356,6 +370,8 @@ The time complexity is $O(m \times n \times \alpha(m \times n))$, and the space +#### Python3 + ```python class Solution: def solve(self, board: List[List[str]]) -> None: @@ -382,6 +398,8 @@ class Solution: board[i][j] = "X" ``` +#### Java + ```java class Solution { private int[] p; @@ -429,6 +447,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -468,6 +488,8 @@ public: }; ``` +#### Go + ```go func solve(board [][]byte) { m, n := len(board), len(board[0]) @@ -509,6 +531,8 @@ func solve(board [][]byte) { } ``` +#### TypeScript + ```ts function solve(board: string[][]): void { const m = board.length; diff --git a/solution/0100-0199/0131.Palindrome Partitioning/README.md b/solution/0100-0199/0131.Palindrome Partitioning/README.md index 1ed8dc4b99b58..c07a31dee3ed0 100644 --- a/solution/0100-0199/0131.Palindrome Partitioning/README.md +++ b/solution/0100-0199/0131.Palindrome Partitioning/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def partition(self, s: str) -> List[List[str]]: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func partition(s string) (ans [][]string) { n := len(s) @@ -197,6 +205,8 @@ func partition(s string) (ans [][]string) { } ``` +#### TypeScript + ```ts function partition(s: string): string[][] { const n = s.length; @@ -226,6 +236,8 @@ function partition(s: string): string[][] { } ``` +#### C# + ```cs public class Solution { private int n; diff --git a/solution/0100-0199/0131.Palindrome Partitioning/README_EN.md b/solution/0100-0199/0131.Palindrome Partitioning/README_EN.md index 26ccb6182c13d..07f5778b09663 100644 --- a/solution/0100-0199/0131.Palindrome Partitioning/README_EN.md +++ b/solution/0100-0199/0131.Palindrome Partitioning/README_EN.md @@ -46,6 +46,8 @@ tags: +#### Python3 + ```python class Solution: def partition(self, s: str) -> List[List[str]]: @@ -70,6 +72,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func partition(s string) (ans [][]string) { n := len(s) @@ -178,6 +186,8 @@ func partition(s string) (ans [][]string) { } ``` +#### TypeScript + ```ts function partition(s: string): string[][] { const n = s.length; @@ -207,6 +217,8 @@ function partition(s: string): string[][] { } ``` +#### C# + ```cs public class Solution { private int n; diff --git a/solution/0100-0199/0132.Palindrome Partitioning II/README.md b/solution/0100-0199/0132.Palindrome Partitioning II/README.md index 68b50b50cfa38..90bde0e1186f3 100644 --- a/solution/0100-0199/0132.Palindrome Partitioning II/README.md +++ b/solution/0100-0199/0132.Palindrome Partitioning II/README.md @@ -82,6 +82,8 @@ $$ +#### Python3 + ```python class Solution: def minCut(self, s: str) -> int: @@ -98,6 +100,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int minCut(String s) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func minCut(s string) int { n := len(s) @@ -185,6 +193,8 @@ func minCut(s string) int { } ``` +#### TypeScript + ```ts function minCut(s: string): number { const n = s.length; @@ -210,6 +220,8 @@ function minCut(s: string): number { } ``` +#### C# + ```cs public class Solution { public int MinCut(string s) { diff --git a/solution/0100-0199/0132.Palindrome Partitioning II/README_EN.md b/solution/0100-0199/0132.Palindrome Partitioning II/README_EN.md index 2d8e7dd6c600d..59ba4c4109bcb 100644 --- a/solution/0100-0199/0132.Palindrome Partitioning II/README_EN.md +++ b/solution/0100-0199/0132.Palindrome Partitioning II/README_EN.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def minCut(self, s: str) -> int: @@ -78,6 +80,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int minCut(String s) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func minCut(s string) int { n := len(s) @@ -165,6 +173,8 @@ func minCut(s string) int { } ``` +#### TypeScript + ```ts function minCut(s: string): number { const n = s.length; @@ -190,6 +200,8 @@ function minCut(s: string): number { } ``` +#### C# + ```cs public class Solution { public int MinCut(string s) { diff --git a/solution/0100-0199/0133.Clone Graph/README.md b/solution/0100-0199/0133.Clone Graph/README.md index 0424232a979b7..68bcd02dffc94 100644 --- a/solution/0100-0199/0133.Clone Graph/README.md +++ b/solution/0100-0199/0133.Clone Graph/README.md @@ -96,6 +96,8 @@ class Node { +#### Python3 + ```python """ # Definition for a Node. @@ -124,6 +126,8 @@ class Solution: return clone(node) ``` +#### Java + ```java /* // Definition for a Node. @@ -165,6 +169,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -203,6 +209,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -234,6 +242,8 @@ func cloneGraph(node *Node) *Node { } ``` +#### TypeScript + ```ts /** * Definition for Node. @@ -269,6 +279,8 @@ function cloneGraph(node: Node | null): Node | null { } ``` +#### C# + ```cs using System.Collections.Generic; diff --git a/solution/0100-0199/0133.Clone Graph/README_EN.md b/solution/0100-0199/0133.Clone Graph/README_EN.md index 45d98fc854f9a..f64c6ebb729bf 100644 --- a/solution/0100-0199/0133.Clone Graph/README_EN.md +++ b/solution/0100-0199/0133.Clone Graph/README_EN.md @@ -92,6 +92,8 @@ class Node { +#### Python3 + ```python """ # Definition for a Node. @@ -120,6 +122,8 @@ class Solution: return clone(node) ``` +#### Java + ```java /* // Definition for a Node. @@ -161,6 +165,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -199,6 +205,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -230,6 +238,8 @@ func cloneGraph(node *Node) *Node { } ``` +#### TypeScript + ```ts /** * Definition for Node. @@ -265,6 +275,8 @@ function cloneGraph(node: Node | null): Node | null { } ``` +#### C# + ```cs using System.Collections.Generic; diff --git a/solution/0100-0199/0134.Gas Station/README.md b/solution/0100-0199/0134.Gas Station/README.md index 01b9b9628b56a..3ae6856d3f254 100644 --- a/solution/0100-0199/0134.Gas Station/README.md +++ b/solution/0100-0199/0134.Gas Station/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def canCompleteCircuit(self, gas: List[int], cost: List[int]) -> int: @@ -98,6 +100,8 @@ class Solution: return -1 if s < 0 else i ``` +#### Java + ```java class Solution { public int canCompleteCircuit(int[] gas, int[] cost) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func canCompleteCircuit(gas []int, cost []int) int { n := len(gas) @@ -163,6 +171,8 @@ func canCompleteCircuit(gas []int, cost []int) int { } ``` +#### TypeScript + ```ts function canCompleteCircuit(gas: number[], cost: number[]): number { const n = gas.length; @@ -184,6 +194,8 @@ function canCompleteCircuit(gas: number[], cost: number[]): number { } ``` +#### C# + ```cs public class Solution { public int CanCompleteCircuit(int[] gas, int[] cost) { diff --git a/solution/0100-0199/0134.Gas Station/README_EN.md b/solution/0100-0199/0134.Gas Station/README_EN.md index d62fe4d20eab7..33105cc79f9c8 100644 --- a/solution/0100-0199/0134.Gas Station/README_EN.md +++ b/solution/0100-0199/0134.Gas Station/README_EN.md @@ -72,6 +72,8 @@ Therefore, you can't travel around the circuit once no matter where you star +#### Python3 + ```python class Solution: def canCompleteCircuit(self, gas: List[int], cost: List[int]) -> int: @@ -89,6 +91,8 @@ class Solution: return -1 if s < 0 else i ``` +#### Java + ```java class Solution { public int canCompleteCircuit(int[] gas, int[] cost) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func canCompleteCircuit(gas []int, cost []int) int { n := len(gas) @@ -154,6 +162,8 @@ func canCompleteCircuit(gas []int, cost []int) int { } ``` +#### TypeScript + ```ts function canCompleteCircuit(gas: number[], cost: number[]): number { const n = gas.length; @@ -175,6 +185,8 @@ function canCompleteCircuit(gas: number[], cost: number[]): number { } ``` +#### C# + ```cs public class Solution { public int CanCompleteCircuit(int[] gas, int[] cost) { diff --git a/solution/0100-0199/0135.Candy/README.md b/solution/0100-0199/0135.Candy/README.md index 7c863ac092281..4b8fd0ef26673 100644 --- a/solution/0100-0199/0135.Candy/README.md +++ b/solution/0100-0199/0135.Candy/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def candy(self, ratings: List[int]) -> int: @@ -89,6 +91,8 @@ class Solution: return sum(max(a, b) for a, b in zip(left, right)) ``` +#### Java + ```java class Solution { public int candy(int[] ratings) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func candy(ratings []int) int { n := len(ratings) @@ -170,6 +178,8 @@ func candy(ratings []int) int { } ``` +#### TypeScript + ```ts function candy(ratings: number[]): number { const n = ratings.length; @@ -193,6 +203,8 @@ function candy(ratings: number[]): number { } ``` +#### C# + ```cs public class Solution { public int Candy(int[] ratings) { @@ -230,6 +242,8 @@ public class Solution { +#### Java + ```java class Solution { public int candy(int[] ratings) { diff --git a/solution/0100-0199/0135.Candy/README_EN.md b/solution/0100-0199/0135.Candy/README_EN.md index 6cc0d701c79f6..a37b9e3a1bdb1 100644 --- a/solution/0100-0199/0135.Candy/README_EN.md +++ b/solution/0100-0199/0135.Candy/README_EN.md @@ -73,6 +73,8 @@ Time complexity $O(n)$, space complexity $O(n)$. Where $n$ is the length of the +#### Python3 + ```python class Solution: def candy(self, ratings: List[int]) -> int: @@ -88,6 +90,8 @@ class Solution: return sum(max(a, b) for a, b in zip(left, right)) ``` +#### Java + ```java class Solution { public int candy(int[] ratings) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func candy(ratings []int) int { n := len(ratings) @@ -169,6 +177,8 @@ func candy(ratings []int) int { } ``` +#### TypeScript + ```ts function candy(ratings: number[]): number { const n = ratings.length; @@ -192,6 +202,8 @@ function candy(ratings: number[]): number { } ``` +#### C# + ```cs public class Solution { public int Candy(int[] ratings) { @@ -229,6 +241,8 @@ public class Solution { +#### Java + ```java class Solution { public int candy(int[] ratings) { diff --git a/solution/0100-0199/0136.Single Number/README.md b/solution/0100-0199/0136.Single Number/README.md index 1b3a07971b756..b4ae7241ceeab 100644 --- a/solution/0100-0199/0136.Single Number/README.md +++ b/solution/0100-0199/0136.Single Number/README.md @@ -77,12 +77,16 @@ tags: +#### Python3 + ```python class Solution: def singleNumber(self, nums: List[int]) -> int: return reduce(xor, nums) ``` +#### Java + ```java class Solution { public int singleNumber(int[] nums) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func singleNumber(nums []int) (ans int) { for _, v := range nums { @@ -117,12 +125,16 @@ func singleNumber(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function singleNumber(nums: number[]): number { return nums.reduce((r, v) => r ^ v); } ``` +#### Rust + ```rust impl Solution { pub fn single_number(nums: Vec) -> i32 { @@ -133,6 +145,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -143,6 +157,8 @@ var singleNumber = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int SingleNumber(int[] nums) { @@ -151,6 +167,8 @@ public class Solution { } ``` +#### C + ```c int singleNumber(int* nums, int numsSize) { int ans = 0; @@ -161,6 +179,8 @@ int singleNumber(int* nums, int numsSize) { } ``` +#### Swift + ```swift class Solution { func singleNumber(_ nums: [Int]) -> Int { @@ -179,6 +199,8 @@ class Solution { +#### Java + ```java class Solution { public int singleNumber(int[] nums) { diff --git a/solution/0100-0199/0136.Single Number/README_EN.md b/solution/0100-0199/0136.Single Number/README_EN.md index 668935bd2e867..352f5b64edf00 100644 --- a/solution/0100-0199/0136.Single Number/README_EN.md +++ b/solution/0100-0199/0136.Single Number/README_EN.md @@ -60,12 +60,16 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def singleNumber(self, nums: List[int]) -> int: return reduce(xor, nums) ``` +#### Java + ```java class Solution { public int singleNumber(int[] nums) { @@ -78,6 +82,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -91,6 +97,8 @@ public: }; ``` +#### Go + ```go func singleNumber(nums []int) (ans int) { for _, v := range nums { @@ -100,12 +108,16 @@ func singleNumber(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function singleNumber(nums: number[]): number { return nums.reduce((r, v) => r ^ v); } ``` +#### Rust + ```rust impl Solution { pub fn single_number(nums: Vec) -> i32 { @@ -116,6 +128,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -126,6 +140,8 @@ var singleNumber = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int SingleNumber(int[] nums) { @@ -134,6 +150,8 @@ public class Solution { } ``` +#### C + ```c int singleNumber(int* nums, int numsSize) { int ans = 0; @@ -144,6 +162,8 @@ int singleNumber(int* nums, int numsSize) { } ``` +#### Swift + ```swift class Solution { func singleNumber(_ nums: [Int]) -> Int { @@ -162,6 +182,8 @@ class Solution { +#### Java + ```java class Solution { public int singleNumber(int[] nums) { diff --git a/solution/0100-0199/0137.Single Number II/README.md b/solution/0100-0199/0137.Single Number II/README.md index 927929c456625..53d35d1faa2fa 100644 --- a/solution/0100-0199/0137.Single Number II/README.md +++ b/solution/0100-0199/0137.Single Number II/README.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def singleNumber(self, nums: List[int]) -> int: @@ -75,6 +77,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int singleNumber(int[] nums) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func singleNumber(nums []int) int { ans := int32(0) @@ -125,6 +133,8 @@ func singleNumber(nums []int) int { } ``` +#### TypeScript + ```ts function singleNumber(nums: number[]): number { let ans = 0; @@ -136,6 +146,8 @@ function singleNumber(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn single_number(nums: Vec) -> i32 { @@ -152,6 +164,8 @@ impl Solution { } ``` +#### C + ```c int singleNumber(int* nums, int numsSize) { int ans = 0; @@ -168,6 +182,8 @@ int singleNumber(int* nums, int numsSize) { } ``` +#### Swift + ```swift class Solution { func singleNumber(_ nums: [Int]) -> Int { @@ -228,6 +244,8 @@ $$ +#### Python3 + ```python class Solution: def singleNumber(self, nums: List[int]) -> int: @@ -239,6 +257,8 @@ class Solution: return b ``` +#### Java + ```java class Solution { public int singleNumber(int[] nums) { @@ -254,6 +274,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -270,6 +292,8 @@ public: }; ``` +#### Go + ```go func singleNumber(nums []int) int { a, b := 0, 0 @@ -282,6 +306,8 @@ func singleNumber(nums []int) int { } ``` +#### TypeScript + ```ts function singleNumber(nums: number[]): number { let a = 0; @@ -296,6 +322,8 @@ function singleNumber(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn single_number(nums: Vec) -> i32 { diff --git a/solution/0100-0199/0137.Single Number II/README_EN.md b/solution/0100-0199/0137.Single Number II/README_EN.md index 8569f74d0c28b..03357aad9c4e0 100644 --- a/solution/0100-0199/0137.Single Number II/README_EN.md +++ b/solution/0100-0199/0137.Single Number II/README_EN.md @@ -52,6 +52,8 @@ The time complexity is $O(n \times \log M)$, where $n$ and $M$ are the length of +#### Python3 + ```python class Solution: def singleNumber(self, nums: List[int]) -> int: @@ -66,6 +68,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int singleNumber(int[] nums) { @@ -83,6 +87,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,6 +107,8 @@ public: }; ``` +#### Go + ```go func singleNumber(nums []int) int { ans := int32(0) @@ -116,6 +124,8 @@ func singleNumber(nums []int) int { } ``` +#### TypeScript + ```ts function singleNumber(nums: number[]): number { let ans = 0; @@ -127,6 +137,8 @@ function singleNumber(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn single_number(nums: Vec) -> i32 { @@ -143,6 +155,8 @@ impl Solution { } ``` +#### C + ```c int singleNumber(int* nums, int numsSize) { int ans = 0; @@ -159,6 +173,8 @@ int singleNumber(int* nums, int numsSize) { } ``` +#### Swift + ```swift class Solution { func singleNumber(_ nums: [Int]) -> Int { @@ -219,6 +235,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def singleNumber(self, nums: List[int]) -> int: @@ -230,6 +248,8 @@ class Solution: return b ``` +#### Java + ```java class Solution { public int singleNumber(int[] nums) { @@ -245,6 +265,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -261,6 +283,8 @@ public: }; ``` +#### Go + ```go func singleNumber(nums []int) int { a, b := 0, 0 @@ -273,6 +297,8 @@ func singleNumber(nums []int) int { } ``` +#### TypeScript + ```ts function singleNumber(nums: number[]): number { let a = 0; @@ -287,6 +313,8 @@ function singleNumber(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn single_number(nums: Vec) -> i32 { diff --git a/solution/0100-0199/0138.Copy List with Random Pointer/README.md b/solution/0100-0199/0138.Copy List with Random Pointer/README.md index 859266cf5e213..2c258d03c23a2 100644 --- a/solution/0100-0199/0138.Copy List with Random Pointer/README.md +++ b/solution/0100-0199/0138.Copy List with Random Pointer/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python """ # Definition for a Node. @@ -121,6 +123,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /* // Definition for a Node. @@ -156,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -221,6 +229,8 @@ func copyRandomList(head *Node) *Node { } ``` +#### TypeScript + ```ts /** * Definition for Node. @@ -253,6 +263,8 @@ function copyRandomList(head: Node | null): Node | null { } ``` +#### JavaScript + ```js /** * // Definition for a Node. @@ -285,6 +297,8 @@ var copyRandomList = function (head) { }; ``` +#### C# + ```cs /* // Definition for a Node. @@ -339,6 +353,8 @@ public class Solution { +#### Python3 + ```python """ # Definition for a Node. @@ -376,6 +392,8 @@ class Solution: return ans ``` +#### Java + ```java /* // Definition for a Node. @@ -419,6 +437,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -465,6 +485,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -501,6 +523,8 @@ func copyRandomList(head *Node) *Node { } ``` +#### JavaScript + ```js /** * // Definition for a Node. @@ -541,6 +565,8 @@ var copyRandomList = function (head) { }; ``` +#### C# + ```cs /* // Definition for a Node. diff --git a/solution/0100-0199/0138.Copy List with Random Pointer/README_EN.md b/solution/0100-0199/0138.Copy List with Random Pointer/README_EN.md index f3ecd4123facb..00d08b60ccb7e 100644 --- a/solution/0100-0199/0138.Copy List with Random Pointer/README_EN.md +++ b/solution/0100-0199/0138.Copy List with Random Pointer/README_EN.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python """ # Definition for a Node. @@ -107,6 +109,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /* // Definition for a Node. @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -179,6 +185,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -207,6 +215,8 @@ func copyRandomList(head *Node) *Node { } ``` +#### TypeScript + ```ts /** * Definition for Node. @@ -239,6 +249,8 @@ function copyRandomList(head: Node | null): Node | null { } ``` +#### JavaScript + ```js /** * // Definition for a Node. @@ -271,6 +283,8 @@ var copyRandomList = function (head) { }; ``` +#### C# + ```cs /* // Definition for a Node. @@ -317,6 +331,8 @@ public class Solution { +#### Python3 + ```python """ # Definition for a Node. @@ -354,6 +370,8 @@ class Solution: return ans ``` +#### Java + ```java /* // Definition for a Node. @@ -397,6 +415,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -443,6 +463,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -479,6 +501,8 @@ func copyRandomList(head *Node) *Node { } ``` +#### JavaScript + ```js /** * // Definition for a Node. @@ -519,6 +543,8 @@ var copyRandomList = function (head) { }; ``` +#### C# + ```cs /* // Definition for a Node. diff --git a/solution/0100-0199/0139.Word Break/README.md b/solution/0100-0199/0139.Word Break/README.md index cb694cd18db2b..8cae1cbec9f72 100644 --- a/solution/0100-0199/0139.Word Break/README.md +++ b/solution/0100-0199/0139.Word Break/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def wordBreak(self, s: str, wordDict: List[str]) -> bool: @@ -90,6 +92,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public boolean wordBreak(String s, List wordDict) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func wordBreak(s string, wordDict []string) bool { words := map[string]bool{} @@ -153,6 +161,8 @@ func wordBreak(s string, wordDict []string) bool { } ``` +#### TypeScript + ```ts function wordBreak(s: string, wordDict: string[]): boolean { const words = new Set(wordDict); @@ -171,6 +181,8 @@ function wordBreak(s: string, wordDict: string[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn word_break(s: String, word_dict: Vec) -> bool { @@ -187,6 +199,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public bool WordBreak(string s, IList wordDict) { @@ -225,6 +239,8 @@ public class Solution { +#### Python3 + ```python class Trie: def __init__(self): @@ -262,6 +278,8 @@ class Solution: return f[0] ``` +#### Java + ```java class Solution { public boolean wordBreak(String s, List wordDict) { @@ -308,6 +326,8 @@ class Trie { } ``` +#### C++ + ```cpp class Trie { public: @@ -357,6 +377,8 @@ public: }; ``` +#### Go + ```go type trie struct { children [26]*trie @@ -405,6 +427,8 @@ func wordBreak(s string, wordDict []string) bool { } ``` +#### TypeScript + ```ts function wordBreak(s: string, wordDict: string[]): boolean { const trie = new Trie(); @@ -454,6 +478,8 @@ class Trie { } ``` +#### C# + ```cs public class Solution { public bool WordBreak(string s, IList wordDict) { diff --git a/solution/0100-0199/0139.Word Break/README_EN.md b/solution/0100-0199/0139.Word Break/README_EN.md index f6686e5bf9ddf..03ec094d8f5cc 100644 --- a/solution/0100-0199/0139.Word Break/README_EN.md +++ b/solution/0100-0199/0139.Word Break/README_EN.md @@ -71,6 +71,8 @@ Note that you are allowed to reuse a dictionary word. +#### Python3 + ```python class Solution: def wordBreak(self, s: str, wordDict: List[str]) -> bool: @@ -82,6 +84,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public boolean wordBreak(String s, List wordDict) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func wordBreak(s string, wordDict []string) bool { words := map[string]bool{} @@ -145,6 +153,8 @@ func wordBreak(s string, wordDict []string) bool { } ``` +#### TypeScript + ```ts function wordBreak(s: string, wordDict: string[]): boolean { const words = new Set(wordDict); @@ -163,6 +173,8 @@ function wordBreak(s: string, wordDict: string[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn word_break(s: String, word_dict: Vec) -> bool { @@ -179,6 +191,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public bool WordBreak(string s, IList wordDict) { @@ -209,6 +223,8 @@ public class Solution { +#### Python3 + ```python class Trie: def __init__(self): @@ -246,6 +262,8 @@ class Solution: return f[0] ``` +#### Java + ```java class Solution { public boolean wordBreak(String s, List wordDict) { @@ -292,6 +310,8 @@ class Trie { } ``` +#### C++ + ```cpp class Trie { public: @@ -341,6 +361,8 @@ public: }; ``` +#### Go + ```go type trie struct { children [26]*trie @@ -389,6 +411,8 @@ func wordBreak(s string, wordDict []string) bool { } ``` +#### TypeScript + ```ts function wordBreak(s: string, wordDict: string[]): boolean { const trie = new Trie(); @@ -438,6 +462,8 @@ class Trie { } ``` +#### C# + ```cs public class Solution { public bool WordBreak(string s, IList wordDict) { diff --git a/solution/0100-0199/0140.Word Break II/README.md b/solution/0100-0199/0140.Word Break II/README.md index 8f7bfec199bb0..efcd2e8186d4b 100644 --- a/solution/0100-0199/0140.Word Break II/README.md +++ b/solution/0100-0199/0140.Word Break II/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Trie: def __init__(self): @@ -118,6 +120,8 @@ class Solution: return [' '.join(v) for v in ans] ``` +#### Java + ```java class Trie { Trie[] children = new Trie[26]; @@ -178,6 +182,8 @@ class Solution { } ``` +#### Go + ```go type Trie struct { children [26]*Trie @@ -241,6 +247,8 @@ func wordBreak(s string, wordDict []string) []string { } ``` +#### C# + ```cs using System; using System.Collections.Generic; diff --git a/solution/0100-0199/0140.Word Break II/README_EN.md b/solution/0100-0199/0140.Word Break II/README_EN.md index 8b04169a78a4a..942d4d39b3d77 100644 --- a/solution/0100-0199/0140.Word Break II/README_EN.md +++ b/solution/0100-0199/0140.Word Break II/README_EN.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Trie: def __init__(self): @@ -115,6 +117,8 @@ class Solution: return [' '.join(v) for v in ans] ``` +#### Java + ```java class Trie { Trie[] children = new Trie[26]; @@ -175,6 +179,8 @@ class Solution { } ``` +#### Go + ```go type Trie struct { children [26]*Trie @@ -238,6 +244,8 @@ func wordBreak(s string, wordDict []string) []string { } ``` +#### C# + ```cs using System; using System.Collections.Generic; diff --git a/solution/0100-0199/0141.Linked List Cycle/README.md b/solution/0100-0199/0141.Linked List Cycle/README.md index fe6a2511fb89e..4cd616d0d3c09 100644 --- a/solution/0100-0199/0141.Linked List Cycle/README.md +++ b/solution/0100-0199/0141.Linked List Cycle/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -103,6 +105,8 @@ class Solution: return False ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -128,6 +132,8 @@ public class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -172,6 +180,8 @@ func hasCycle(head *ListNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -213,6 +223,8 @@ function hasCycle(head: ListNode | null): boolean { +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -231,6 +243,8 @@ class Solution: return False ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -259,6 +273,8 @@ public class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -285,6 +301,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -305,6 +323,8 @@ func hasCycle(head *ListNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -332,6 +352,8 @@ function hasCycle(head: ListNode | null): boolean { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -359,6 +381,8 @@ var hasCycle = function (head) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. diff --git a/solution/0100-0199/0141.Linked List Cycle/README_EN.md b/solution/0100-0199/0141.Linked List Cycle/README_EN.md index b5369bc01afd7..bc6ba355985b0 100644 --- a/solution/0100-0199/0141.Linked List Cycle/README_EN.md +++ b/solution/0100-0199/0141.Linked List Cycle/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -94,6 +96,8 @@ class Solution: return False ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -119,6 +123,8 @@ public class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -163,6 +171,8 @@ func hasCycle(head *ListNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -204,6 +214,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$, where $n$ is +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -222,6 +234,8 @@ class Solution: return False ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -250,6 +264,8 @@ public class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -276,6 +292,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -296,6 +314,8 @@ func hasCycle(head *ListNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -323,6 +343,8 @@ function hasCycle(head: ListNode | null): boolean { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -350,6 +372,8 @@ var hasCycle = function (head) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. diff --git a/solution/0100-0199/0142.Linked List Cycle II/README.md b/solution/0100-0199/0142.Linked List Cycle II/README.md index a126eec06c621..0c96084e4e220 100644 --- a/solution/0100-0199/0142.Linked List Cycle II/README.md +++ b/solution/0100-0199/0142.Linked List Cycle II/README.md @@ -101,6 +101,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -123,6 +125,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -155,6 +159,8 @@ public class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -212,6 +220,8 @@ func detectCycle(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -243,6 +253,8 @@ function detectCycle(head: ListNode | null): ListNode | null { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. diff --git a/solution/0100-0199/0142.Linked List Cycle II/README_EN.md b/solution/0100-0199/0142.Linked List Cycle II/README_EN.md index caaeaeb26db64..c6adb0a7ee764 100644 --- a/solution/0100-0199/0142.Linked List Cycle II/README_EN.md +++ b/solution/0100-0199/0142.Linked List Cycle II/README_EN.md @@ -89,6 +89,8 @@ The time complexity is $O(n)$, where $n$ is the number of nodes in the linked li +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -111,6 +113,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -143,6 +147,8 @@ public class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -200,6 +208,8 @@ func detectCycle(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -231,6 +241,8 @@ function detectCycle(head: ListNode | null): ListNode | null { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. diff --git a/solution/0100-0199/0143.Reorder List/README.md b/solution/0100-0199/0143.Reorder List/README.md index e669972985bac..5a56d5a810b6d 100644 --- a/solution/0100-0199/0143.Reorder List/README.md +++ b/solution/0100-0199/0143.Reorder List/README.md @@ -73,6 +73,8 @@ L0 → Ln → L1 → Ln - 1 → L +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -108,6 +110,8 @@ class Solution: cur, pre = pre.next, t ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -155,6 +159,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -204,6 +210,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -243,6 +251,8 @@ func reorderList(head *ListNode) { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -286,6 +296,8 @@ function reorderList(head: ListNode | null): void { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -324,6 +336,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -371,6 +385,8 @@ var reorderList = function (head) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. diff --git a/solution/0100-0199/0143.Reorder List/README_EN.md b/solution/0100-0199/0143.Reorder List/README_EN.md index 098d5caa35b2f..fbd8b31c664ee 100644 --- a/solution/0100-0199/0143.Reorder List/README_EN.md +++ b/solution/0100-0199/0143.Reorder List/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n)$, where $n$ is the length of the linked list. The s +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -100,6 +102,8 @@ class Solution: cur, pre = pre.next, t ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -220,6 +228,8 @@ func reorderList(head *ListNode) { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -262,6 +272,8 @@ function reorderList(head: ListNode | null): void { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -300,6 +312,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -342,6 +356,8 @@ var reorderList = function (head) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. diff --git a/solution/0100-0199/0144.Binary Tree Preorder Traversal/README.md b/solution/0100-0199/0144.Binary Tree Preorder Traversal/README.md index b7f2f7b740daf..70e91affc866e 100644 --- a/solution/0100-0199/0144.Binary Tree Preorder Traversal/README.md +++ b/solution/0100-0199/0144.Binary Tree Preorder Traversal/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -195,6 +203,8 @@ func preorderTraversal(root *TreeNode) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -225,6 +235,8 @@ function preorderTraversal(root: TreeNode | null): number[] { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -286,6 +298,8 @@ impl Solution { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -309,6 +323,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -348,6 +364,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -385,6 +403,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -414,6 +434,8 @@ func preorderTraversal(root *TreeNode) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -467,6 +489,8 @@ Morris 遍历无需使用栈,空间复杂度为 $O(1)$。核心思想是: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -495,6 +519,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -538,6 +564,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -578,6 +606,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -611,6 +641,8 @@ func preorderTraversal(root *TreeNode) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0144.Binary Tree Preorder Traversal/README_EN.md b/solution/0100-0199/0144.Binary Tree Preorder Traversal/README_EN.md index 01d6d489d2e88..d341cafdf76a8 100644 --- a/solution/0100-0199/0144.Binary Tree Preorder Traversal/README_EN.md +++ b/solution/0100-0199/0144.Binary Tree Preorder Traversal/README_EN.md @@ -68,6 +68,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -178,6 +186,8 @@ func preorderTraversal(root *TreeNode) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -208,6 +218,8 @@ function preorderTraversal(root: TreeNode | null): number[] { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -269,6 +281,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -292,6 +306,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -331,6 +347,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -368,6 +386,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -397,6 +417,8 @@ func preorderTraversal(root *TreeNode) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -450,6 +472,8 @@ The time complexity is $O(n)$, where $n$ is the number of nodes in the binary tr +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -478,6 +502,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -521,6 +547,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -561,6 +589,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -594,6 +624,8 @@ func preorderTraversal(root *TreeNode) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0145.Binary Tree Postorder Traversal/README.md b/solution/0100-0199/0145.Binary Tree Postorder Traversal/README.md index 1b39d8bc71a8d..d3f64ff95c979 100644 --- a/solution/0100-0199/0145.Binary Tree Postorder Traversal/README.md +++ b/solution/0100-0199/0145.Binary Tree Postorder Traversal/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -181,6 +189,8 @@ func postorderTraversal(root *TreeNode) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -211,6 +221,8 @@ function postorderTraversal(root: TreeNode | null): number[] { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -274,6 +286,8 @@ impl Solution { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -297,6 +311,8 @@ class Solution: return ans[::-1] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -336,6 +352,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -374,6 +392,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -406,6 +426,8 @@ func postorderTraversal(root *TreeNode) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -463,6 +485,8 @@ Morris 遍历无需使用栈,空间复杂度为 $O(1)$。核心思想是: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -491,6 +515,8 @@ class Solution: return ans[::-1] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -534,6 +560,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -575,6 +603,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -608,6 +638,8 @@ func postorderTraversal(root *TreeNode) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0145.Binary Tree Postorder Traversal/README_EN.md b/solution/0100-0199/0145.Binary Tree Postorder Traversal/README_EN.md index 9335e2a2ec552..075415be54b20 100644 --- a/solution/0100-0199/0145.Binary Tree Postorder Traversal/README_EN.md +++ b/solution/0100-0199/0145.Binary Tree Postorder Traversal/README_EN.md @@ -68,6 +68,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -178,6 +186,8 @@ func postorderTraversal(root *TreeNode) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -208,6 +218,8 @@ function postorderTraversal(root: TreeNode | null): number[] { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -271,6 +283,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -294,6 +308,8 @@ class Solution: return ans[::-1] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -333,6 +349,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -371,6 +389,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -403,6 +423,8 @@ func postorderTraversal(root *TreeNode) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -460,6 +482,8 @@ The time complexity is $O(n)$, where $n$ is the number of nodes in the binary tr +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -488,6 +512,8 @@ class Solution: return ans[::-1] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -531,6 +557,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -572,6 +600,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -605,6 +635,8 @@ func postorderTraversal(root *TreeNode) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0146.LRU Cache/README.md b/solution/0100-0199/0146.LRU Cache/README.md index 8e15434aa1c26..a5bf52d5e73f2 100644 --- a/solution/0100-0199/0146.LRU Cache/README.md +++ b/solution/0100-0199/0146.LRU Cache/README.md @@ -91,6 +91,8 @@ lRUCache.get(4); // 返回 4 +#### Python3 + ```python class Node: def __init__(self, key=0, val=0): @@ -158,6 +160,8 @@ class LRUCache: # obj.put(key,value) ``` +#### Java + ```java class Node { int key; @@ -246,6 +250,8 @@ class LRUCache { */ ``` +#### C++ + ```cpp struct Node { int k; @@ -340,6 +346,8 @@ private: */ ``` +#### Go + ```go type node struct { key, val int @@ -411,6 +419,8 @@ func (this *LRUCache) pushFront(n *node) { } ``` +#### TypeScript + ```ts class LRUCache { capacity: number; @@ -447,6 +457,8 @@ class LRUCache { */ ``` +#### Rust + ```rust use std::cell::RefCell; use std::collections::HashMap; @@ -578,6 +590,8 @@ impl LRUCache { */ ``` +#### C# + ```cs public class LRUCache { class Node { diff --git a/solution/0100-0199/0146.LRU Cache/README_EN.md b/solution/0100-0199/0146.LRU Cache/README_EN.md index 3f4bfadaae910..ce8f5ab122de7 100644 --- a/solution/0100-0199/0146.LRU Cache/README_EN.md +++ b/solution/0100-0199/0146.LRU Cache/README_EN.md @@ -85,6 +85,8 @@ The time complexity is $O(1)$, and the space complexity is $O(\text{capacity})$. +#### Python3 + ```python class Node: def __init__(self, key=0, val=0): @@ -152,6 +154,8 @@ class LRUCache: # obj.put(key,value) ``` +#### Java + ```java class Node { int key; @@ -240,6 +244,8 @@ class LRUCache { */ ``` +#### C++ + ```cpp struct Node { int k; @@ -334,6 +340,8 @@ private: */ ``` +#### Go + ```go type node struct { key, val int @@ -405,6 +413,8 @@ func (this *LRUCache) pushFront(n *node) { } ``` +#### TypeScript + ```ts class LRUCache { capacity: number; @@ -441,6 +451,8 @@ class LRUCache { */ ``` +#### Rust + ```rust use std::cell::RefCell; use std::collections::HashMap; @@ -572,6 +584,8 @@ impl LRUCache { */ ``` +#### C# + ```cs public class LRUCache { class Node { diff --git a/solution/0100-0199/0147.Insertion Sort List/README.md b/solution/0100-0199/0147.Insertion Sort List/README.md index c123d9e29d3d2..f70899b2e4c3b 100644 --- a/solution/0100-0199/0147.Insertion Sort List/README.md +++ b/solution/0100-0199/0147.Insertion Sort List/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -99,6 +101,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -138,6 +142,8 @@ class Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. diff --git a/solution/0100-0199/0147.Insertion Sort List/README_EN.md b/solution/0100-0199/0147.Insertion Sort List/README_EN.md index 7c22af1cbdf81..7fc22c79e3e08 100644 --- a/solution/0100-0199/0147.Insertion Sort List/README_EN.md +++ b/solution/0100-0199/0147.Insertion Sort List/README_EN.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -89,6 +91,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -128,6 +132,8 @@ class Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. diff --git a/solution/0100-0199/0148.Sort List/README.md b/solution/0100-0199/0148.Sort List/README.md index 442905f802778..cf886e6900730 100644 --- a/solution/0100-0199/0148.Sort List/README.md +++ b/solution/0100-0199/0148.Sort List/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -101,6 +103,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -187,6 +193,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -227,6 +235,8 @@ func sortList(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -271,6 +281,8 @@ function sortList(head: ListNode | null): ListNode | null { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -330,6 +342,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -373,6 +387,8 @@ var sortList = function (head) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. diff --git a/solution/0100-0199/0148.Sort List/README_EN.md b/solution/0100-0199/0148.Sort List/README_EN.md index 95d828b7b5f0e..f6811cf00d549 100644 --- a/solution/0100-0199/0148.Sort List/README_EN.md +++ b/solution/0100-0199/0148.Sort List/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -95,6 +97,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -221,6 +229,8 @@ func sortList(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -265,6 +275,8 @@ function sortList(head: ListNode | null): ListNode | null { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -324,6 +336,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -367,6 +381,8 @@ var sortList = function (head) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. diff --git a/solution/0100-0199/0149.Max Points on a Line/README.md b/solution/0100-0199/0149.Max Points on a Line/README.md index 0e3105126ef6d..ff779d21a9857 100644 --- a/solution/0100-0199/0149.Max Points on a Line/README.md +++ b/solution/0100-0199/0149.Max Points on a Line/README.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def maxPoints(self, points: List[List[int]]) -> int: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxPoints(int[][] points) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func maxPoints(points [][]int) int { n := len(points) @@ -158,6 +166,8 @@ func maxPoints(points [][]int) int { } ``` +#### C# + ```cs public class Solution { public int MaxPoints(int[][] points) { @@ -204,6 +214,8 @@ public class Solution { +#### Python3 + ```python class Solution: def maxPoints(self, points: List[List[int]]) -> int: @@ -225,6 +237,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxPoints(int[][] points) { @@ -251,6 +265,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -277,6 +293,8 @@ public: }; ``` +#### Go + ```go func maxPoints(points [][]int) int { n := len(points) diff --git a/solution/0100-0199/0149.Max Points on a Line/README_EN.md b/solution/0100-0199/0149.Max Points on a Line/README_EN.md index 958fa4c1e9718..38b841013cd42 100644 --- a/solution/0100-0199/0149.Max Points on a Line/README_EN.md +++ b/solution/0100-0199/0149.Max Points on a Line/README_EN.md @@ -56,6 +56,8 @@ tags: +#### Python3 + ```python class Solution: def maxPoints(self, points: List[List[int]]) -> int: @@ -75,6 +77,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxPoints(int[][] points) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func maxPoints(points [][]int) int { n := len(points) @@ -152,6 +160,8 @@ func maxPoints(points [][]int) int { } ``` +#### C# + ```cs public class Solution { public int MaxPoints(int[][] points) { @@ -190,6 +200,8 @@ public class Solution { +#### Python3 + ```python class Solution: def maxPoints(self, points: List[List[int]]) -> int: @@ -211,6 +223,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxPoints(int[][] points) { @@ -237,6 +251,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -263,6 +279,8 @@ public: }; ``` +#### Go + ```go func maxPoints(points [][]int) int { n := len(points) diff --git a/solution/0100-0199/0150.Evaluate Reverse Polish Notation/README.md b/solution/0100-0199/0150.Evaluate Reverse Polish Notation/README.md index 9a3c152680169..8ab9da8808f36 100644 --- a/solution/0100-0199/0150.Evaluate Reverse Polish Notation/README.md +++ b/solution/0100-0199/0150.Evaluate Reverse Polish Notation/README.md @@ -102,6 +102,8 @@ tags: +#### Python3 + ```python import operator @@ -123,6 +125,8 @@ class Solution: return s[0] ``` +#### Java + ```java class Solution { public int evalRPN(String[] tokens) { @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -182,6 +188,8 @@ public: }; ``` +#### Go + ```go func evalRPN(tokens []string) int { // https://github.com/emirpasic/gods#arraystack @@ -214,6 +222,8 @@ func popInt(stack *arraystack.Stack) int { } ``` +#### TypeScript + ```ts function evalRPN(tokens: string[]): number { const stack = []; @@ -243,6 +253,8 @@ function evalRPN(tokens: string[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn eval_rpn(tokens: Vec) -> i32 { @@ -268,6 +280,8 @@ impl Solution { } ``` +#### C# + ```cs using System.Collections.Generic; @@ -311,6 +325,8 @@ public class Solution { +#### Python3 + ```python class Solution: def evalRPN(self, tokens: List[str]) -> int: diff --git a/solution/0100-0199/0150.Evaluate Reverse Polish Notation/README_EN.md b/solution/0100-0199/0150.Evaluate Reverse Polish Notation/README_EN.md index 85a8ac1cd5fdb..04f770d5acabe 100644 --- a/solution/0100-0199/0150.Evaluate Reverse Polish Notation/README_EN.md +++ b/solution/0100-0199/0150.Evaluate Reverse Polish Notation/README_EN.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python import operator @@ -103,6 +105,8 @@ class Solution: return s[0] ``` +#### Java + ```java class Solution { public int evalRPN(String[] tokens) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func evalRPN(tokens []string) int { // https://github.com/emirpasic/gods#arraystack @@ -194,6 +202,8 @@ func popInt(stack *arraystack.Stack) int { } ``` +#### TypeScript + ```ts function evalRPN(tokens: string[]): number { const stack = []; @@ -223,6 +233,8 @@ function evalRPN(tokens: string[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn eval_rpn(tokens: Vec) -> i32 { @@ -248,6 +260,8 @@ impl Solution { } ``` +#### C# + ```cs using System.Collections.Generic; @@ -291,6 +305,8 @@ public class Solution { +#### Python3 + ```python class Solution: def evalRPN(self, tokens: List[str]) -> int: diff --git a/solution/0100-0199/0151.Reverse Words in a String/README.md b/solution/0100-0199/0151.Reverse Words in a String/README.md index ddd55bbe47c4e..331a9809651f6 100644 --- a/solution/0100-0199/0151.Reverse Words in a String/README.md +++ b/solution/0100-0199/0151.Reverse Words in a String/README.md @@ -81,12 +81,16 @@ tags: +#### Python3 + ```python class Solution: def reverseWords(self, s: str) -> str: return ' '.join(reversed(s.split())) ``` +#### Java + ```java class Solution { public String reverseWords(String s) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func reverseWords(s string) string { words := strings.Split(s, " ") @@ -140,12 +148,16 @@ func reverseWords(s string) string { } ``` +#### TypeScript + ```ts function reverseWords(s: string): string { return s.trim().split(/\s+/).reverse().join(' '); } ``` +#### Rust + ```rust impl Solution { pub fn reverse_words(s: String) -> String { @@ -154,6 +166,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public string ReverseWords(string s) { @@ -176,6 +190,8 @@ public class Solution { +#### Python3 + ```python class Solution: def reverseWords(self, s: str) -> str: @@ -193,6 +209,8 @@ class Solution: return ' '.join(ans[::-1]) ``` +#### Java + ```java class Solution { public String reverseWords(String s) { diff --git a/solution/0100-0199/0151.Reverse Words in a String/README_EN.md b/solution/0100-0199/0151.Reverse Words in a String/README_EN.md index 1c2bbbbf0bc16..9b57630e98af2 100644 --- a/solution/0100-0199/0151.Reverse Words in a String/README_EN.md +++ b/solution/0100-0199/0151.Reverse Words in a String/README_EN.md @@ -75,12 +75,16 @@ Time complexity $O(n)$, space complexity $O(n)$, where $n$ is the length of the +#### Python3 + ```python class Solution: def reverseWords(self, s: str) -> str: return ' '.join(reversed(s.split())) ``` +#### Java + ```java class Solution { public String reverseWords(String s) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func reverseWords(s string) string { words := strings.Split(s, " ") @@ -134,12 +142,16 @@ func reverseWords(s string) string { } ``` +#### TypeScript + ```ts function reverseWords(s: string): string { return s.trim().split(/\s+/).reverse().join(' '); } ``` +#### Rust + ```rust impl Solution { pub fn reverse_words(s: String) -> String { @@ -148,6 +160,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public string ReverseWords(string s) { @@ -170,6 +184,8 @@ Time complexity $O(n)$, space complexity $O(n)$, where $n$ is the length of the +#### Python3 + ```python class Solution: def reverseWords(self, s: str) -> str: @@ -187,6 +203,8 @@ class Solution: return ' '.join(ans[::-1]) ``` +#### Java + ```java class Solution { public String reverseWords(String s) { diff --git a/solution/0100-0199/0152.Maximum Product Subarray/README.md b/solution/0100-0199/0152.Maximum Product Subarray/README.md index 1e854ce31ab4c..8cd48fcd84d88 100644 --- a/solution/0100-0199/0152.Maximum Product Subarray/README.md +++ b/solution/0100-0199/0152.Maximum Product Subarray/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def maxProduct(self, nums: List[int]) -> int: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxProduct(int[] nums) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func maxProduct(nums []int) int { f, g, ans := nums[0], nums[0], nums[0] @@ -122,6 +130,8 @@ func maxProduct(nums []int) int { } ``` +#### TypeScript + ```ts function maxProduct(nums: number[]): number { let [f, g, ans] = [nums[0], nums[0], nums[0]]; @@ -135,6 +145,8 @@ function maxProduct(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_product(nums: Vec) -> i32 { @@ -152,6 +164,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -169,6 +183,8 @@ var maxProduct = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int MaxProduct(int[] nums) { diff --git a/solution/0100-0199/0152.Maximum Product Subarray/README_EN.md b/solution/0100-0199/0152.Maximum Product Subarray/README_EN.md index f7ab4c0ad6821..0052ed728a9bd 100644 --- a/solution/0100-0199/0152.Maximum Product Subarray/README_EN.md +++ b/solution/0100-0199/0152.Maximum Product Subarray/README_EN.md @@ -57,6 +57,8 @@ tags: +#### Python3 + ```python class Solution: def maxProduct(self, nums: List[int]) -> int: @@ -69,6 +71,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxProduct(int[] nums) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -100,6 +106,8 @@ public: }; ``` +#### Go + ```go func maxProduct(nums []int) int { f, g, ans := nums[0], nums[0], nums[0] @@ -113,6 +121,8 @@ func maxProduct(nums []int) int { } ``` +#### TypeScript + ```ts function maxProduct(nums: number[]): number { let [f, g, ans] = [nums[0], nums[0], nums[0]]; @@ -126,6 +136,8 @@ function maxProduct(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_product(nums: Vec) -> i32 { @@ -143,6 +155,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -160,6 +174,8 @@ var maxProduct = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int MaxProduct(int[] nums) { diff --git a/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/README.md b/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/README.md index 63362d4a1afd0..ad17f35382f1d 100644 --- a/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/README.md +++ b/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def findMin(self, nums: List[int]) -> int: @@ -103,6 +105,8 @@ class Solution: return nums[left] ``` +#### Java + ```java class Solution { public int findMin(int[] nums) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func findMin(nums []int) int { n := len(nums) @@ -162,6 +170,8 @@ func findMin(nums []int) int { } ``` +#### TypeScript + ```ts function findMin(nums: number[]): number { let left = 0; @@ -178,6 +188,8 @@ function findMin(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_min(nums: Vec) -> i32 { @@ -196,6 +208,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/README_EN.md b/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/README_EN.md index 26a5613f192c4..84260d337acec 100644 --- a/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/README_EN.md +++ b/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/README_EN.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def findMin(self, nums: List[int]) -> int: @@ -91,6 +93,8 @@ class Solution: return nums[left] ``` +#### Java + ```java class Solution { public int findMin(int[] nums) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func findMin(nums []int) int { n := len(nums) @@ -150,6 +158,8 @@ func findMin(nums []int) int { } ``` +#### TypeScript + ```ts function findMin(nums: number[]): number { let left = 0; @@ -166,6 +176,8 @@ function findMin(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_min(nums: Vec) -> i32 { @@ -184,6 +196,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0100-0199/0154.Find Minimum in Rotated Sorted Array II/README.md b/solution/0100-0199/0154.Find Minimum in Rotated Sorted Array II/README.md index bad2c82c887d3..d1814ecc2b8ce 100644 --- a/solution/0100-0199/0154.Find Minimum in Rotated Sorted Array II/README.md +++ b/solution/0100-0199/0154.Find Minimum in Rotated Sorted Array II/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def findMin(self, nums: List[int]) -> int: @@ -92,6 +94,8 @@ class Solution: return nums[left] ``` +#### Java + ```java class Solution { public int findMin(int[] nums) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func findMin(nums []int) int { left, right := 0, len(nums)-1 @@ -147,6 +155,8 @@ func findMin(nums []int) int { } ``` +#### TypeScript + ```ts function findMin(nums: number[]): number { let left = 0, @@ -165,6 +175,8 @@ function findMin(nums: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0100-0199/0154.Find Minimum in Rotated Sorted Array II/README_EN.md b/solution/0100-0199/0154.Find Minimum in Rotated Sorted Array II/README_EN.md index 361fe58f422bd..687165b5002df 100644 --- a/solution/0100-0199/0154.Find Minimum in Rotated Sorted Array II/README_EN.md +++ b/solution/0100-0199/0154.Find Minimum in Rotated Sorted Array II/README_EN.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def findMin(self, nums: List[int]) -> int: @@ -78,6 +80,8 @@ class Solution: return nums[left] ``` +#### Java + ```java class Solution { public int findMin(int[] nums) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func findMin(nums []int) int { left, right := 0, len(nums)-1 @@ -133,6 +141,8 @@ func findMin(nums []int) int { } ``` +#### TypeScript + ```ts function findMin(nums: number[]): number { let left = 0, @@ -151,6 +161,8 @@ function findMin(nums: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0100-0199/0155.Min Stack/README.md b/solution/0100-0199/0155.Min Stack/README.md index 1be8ca301428b..bcd38445f1b9a 100644 --- a/solution/0100-0199/0155.Min Stack/README.md +++ b/solution/0100-0199/0155.Min Stack/README.md @@ -81,6 +81,8 @@ minStack.getMin(); --> 返回 -2. +#### Python3 + ```python class MinStack: def __init__(self): @@ -110,6 +112,8 @@ class MinStack: # param_4 = obj.getMin() ``` +#### Java + ```java class MinStack { private Deque stk1 = new ArrayDeque<>(); @@ -148,6 +152,8 @@ class MinStack { */ ``` +#### C++ + ```cpp class MinStack { public: @@ -188,6 +194,8 @@ private: */ ``` +#### Go + ```go type MinStack struct { stk1 []int @@ -226,6 +234,8 @@ func (this *MinStack) GetMin() int { */ ``` +#### TypeScript + ```ts class MinStack { stk1: number[]; @@ -265,6 +275,8 @@ class MinStack { */ ``` +#### Rust + ```rust use std::collections::VecDeque; struct MinStack { @@ -312,6 +324,8 @@ impl MinStack { */ ``` +#### JavaScript + ```js var MinStack = function () { this.stk1 = []; @@ -359,6 +373,8 @@ MinStack.prototype.getMin = function () { */ ``` +#### C# + ```cs public class MinStack { private Stack stk1 = new Stack(); diff --git a/solution/0100-0199/0155.Min Stack/README_EN.md b/solution/0100-0199/0155.Min Stack/README_EN.md index 08aa2122eee64..1695dd1060207 100644 --- a/solution/0100-0199/0155.Min Stack/README_EN.md +++ b/solution/0100-0199/0155.Min Stack/README_EN.md @@ -72,6 +72,8 @@ minStack.getMin(); // return -2 +#### Python3 + ```python class MinStack: def __init__(self): @@ -101,6 +103,8 @@ class MinStack: # param_4 = obj.getMin() ``` +#### Java + ```java class MinStack { private Deque stk1 = new ArrayDeque<>(); @@ -139,6 +143,8 @@ class MinStack { */ ``` +#### C++ + ```cpp class MinStack { public: @@ -179,6 +185,8 @@ private: */ ``` +#### Go + ```go type MinStack struct { stk1 []int @@ -217,6 +225,8 @@ func (this *MinStack) GetMin() int { */ ``` +#### TypeScript + ```ts class MinStack { stk1: number[]; @@ -256,6 +266,8 @@ class MinStack { */ ``` +#### Rust + ```rust use std::collections::VecDeque; struct MinStack { @@ -303,6 +315,8 @@ impl MinStack { */ ``` +#### JavaScript + ```js var MinStack = function () { this.stk1 = []; @@ -350,6 +364,8 @@ MinStack.prototype.getMin = function () { */ ``` +#### C# + ```cs public class MinStack { private Stack stk1 = new Stack(); diff --git a/solution/0100-0199/0156.Binary Tree Upside Down/README.md b/solution/0100-0199/0156.Binary Tree Upside Down/README.md index 6cdcd39f3f851..859ff7c6dd82c 100644 --- a/solution/0100-0199/0156.Binary Tree Upside Down/README.md +++ b/solution/0100-0199/0156.Binary Tree Upside Down/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -103,6 +105,8 @@ class Solution: return new_root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0156.Binary Tree Upside Down/README_EN.md b/solution/0100-0199/0156.Binary Tree Upside Down/README_EN.md index e30803cfce3ec..9af8ebdd2a101 100644 --- a/solution/0100-0199/0156.Binary Tree Upside Down/README_EN.md +++ b/solution/0100-0199/0156.Binary Tree Upside Down/README_EN.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -91,6 +93,8 @@ class Solution: return new_root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0157.Read N Characters Given Read4/README.md b/solution/0100-0199/0157.Read N Characters Given Read4/README.md index 0d00f08c99924..7dd73a26c96de 100644 --- a/solution/0100-0199/0157.Read N Characters Given Read4/README.md +++ b/solution/0100-0199/0157.Read N Characters Given Read4/README.md @@ -113,6 +113,8 @@ read4(buf4); // read4 返回 0。现在 buf = "",fp 指向文件末 +#### Python3 + ```python """ The read4 API is already defined for you. @@ -150,6 +152,8 @@ class Solution: return i ``` +#### Java + ```java /** * The read4 API is defined in the parent class Reader4. @@ -179,6 +183,8 @@ public class Solution extends Reader4 { } ``` +#### C++ + ```cpp /** * The read4 API is defined in the parent class Reader4. @@ -209,6 +215,8 @@ public: }; ``` +#### Go + ```go /** * The read4 API is already defined for you. diff --git a/solution/0100-0199/0157.Read N Characters Given Read4/README_EN.md b/solution/0100-0199/0157.Read N Characters Given Read4/README_EN.md index dbf24e5540a1c..a778fc050bb6f 100644 --- a/solution/0100-0199/0157.Read N Characters Given Read4/README_EN.md +++ b/solution/0100-0199/0157.Read N Characters Given Read4/README_EN.md @@ -117,6 +117,8 @@ Note that "abc" is the file's content, not buf. buf is the destina +#### Python3 + ```python """ The read4 API is already defined for you. @@ -154,6 +156,8 @@ class Solution: return i ``` +#### Java + ```java /** * The read4 API is defined in the parent class Reader4. @@ -183,6 +187,8 @@ public class Solution extends Reader4 { } ``` +#### C++ + ```cpp /** * The read4 API is defined in the parent class Reader4. @@ -213,6 +219,8 @@ public: }; ``` +#### Go + ```go /** * The read4 API is already defined for you. diff --git a/solution/0100-0199/0158.Read N Characters Given read4 II - Call Multiple Times/README.md b/solution/0100-0199/0158.Read N Characters Given read4 II - Call Multiple Times/README.md index 51fdd1208ac72..883ee95957290 100644 --- a/solution/0100-0199/0158.Read N Characters Given read4 II - Call Multiple Times/README.md +++ b/solution/0100-0199/0158.Read N Characters Given read4 II - Call Multiple Times/README.md @@ -124,6 +124,8 @@ sol.read (buf, 1); // 我们已经到达文件的末尾,不能读取更多的 +#### Python3 + ```python # The read4 API is already defined for you. # def read4(buf4: List[str]) -> int: @@ -149,6 +151,8 @@ class Solution: return j ``` +#### Java + ```java /** * The read4 API is defined in the parent class Reader4. @@ -184,6 +188,8 @@ public class Solution extends Reader4 { } ``` +#### C++ + ```cpp /** * The read4 API is defined in the parent class Reader4. @@ -217,6 +223,8 @@ private: }; ``` +#### Go + ```go /** * The read4 API is already defined for you. diff --git a/solution/0100-0199/0158.Read N Characters Given read4 II - Call Multiple Times/README_EN.md b/solution/0100-0199/0158.Read N Characters Given read4 II - Call Multiple Times/README_EN.md index d9533a505f7e2..11e47d19d1ff9 100644 --- a/solution/0100-0199/0158.Read N Characters Given read4 II - Call Multiple Times/README_EN.md +++ b/solution/0100-0199/0158.Read N Characters Given read4 II - Call Multiple Times/README_EN.md @@ -121,6 +121,8 @@ sol.read(buf, 1); // We have reached the end of file, no more characters can be +#### Python3 + ```python # The read4 API is already defined for you. # def read4(buf4: List[str]) -> int: @@ -146,6 +148,8 @@ class Solution: return j ``` +#### Java + ```java /** * The read4 API is defined in the parent class Reader4. @@ -181,6 +185,8 @@ public class Solution extends Reader4 { } ``` +#### C++ + ```cpp /** * The read4 API is defined in the parent class Reader4. @@ -214,6 +220,8 @@ private: }; ``` +#### Go + ```go /** * The read4 API is already defined for you. diff --git a/solution/0100-0199/0159.Longest Substring with At Most Two Distinct Characters/README.md b/solution/0100-0199/0159.Longest Substring with At Most Two Distinct Characters/README.md index 9541e3f982e72..c0bb065a7d150 100644 --- a/solution/0100-0199/0159.Longest Substring with At Most Two Distinct Characters/README.md +++ b/solution/0100-0199/0159.Longest Substring with At Most Two Distinct Characters/README.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def lengthOfLongestSubstringTwoDistinct(self, s: str) -> int: @@ -77,6 +79,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int lengthOfLongestSubstringTwoDistinct(String s) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func lengthOfLongestSubstringTwoDistinct(s string) (ans int) { cnt := map[byte]int{} diff --git a/solution/0100-0199/0159.Longest Substring with At Most Two Distinct Characters/README_EN.md b/solution/0100-0199/0159.Longest Substring with At Most Two Distinct Characters/README_EN.md index 374d23714e914..8cf7ce13171e0 100644 --- a/solution/0100-0199/0159.Longest Substring with At Most Two Distinct Characters/README_EN.md +++ b/solution/0100-0199/0159.Longest Substring with At Most Two Distinct Characters/README_EN.md @@ -55,6 +55,8 @@ tags: +#### Python3 + ```python class Solution: def lengthOfLongestSubstringTwoDistinct(self, s: str) -> int: @@ -71,6 +73,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int lengthOfLongestSubstringTwoDistinct(String s) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func lengthOfLongestSubstringTwoDistinct(s string) (ans int) { cnt := map[byte]int{} diff --git a/solution/0100-0199/0160.Intersection of Two Linked Lists/README.md b/solution/0100-0199/0160.Intersection of Two Linked Lists/README.md index efac848e6dfcc..67d33e6d8ba49 100644 --- a/solution/0100-0199/0160.Intersection of Two Linked Lists/README.md +++ b/solution/0100-0199/0160.Intersection of Two Linked Lists/README.md @@ -120,6 +120,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -137,6 +139,8 @@ class Solution: return a ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -161,6 +165,8 @@ public class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -183,6 +189,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -209,6 +217,8 @@ func getIntersectionNode(headA, headB *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -233,6 +243,8 @@ function getIntersectionNode(headA: ListNode | null, headB: ListNode | null): Li } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -258,6 +270,8 @@ var getIntersectionNode = function (headA, headB) { }; ``` +#### Swift + ```swift /** * Definition for singly-linked list. diff --git a/solution/0100-0199/0160.Intersection of Two Linked Lists/README_EN.md b/solution/0100-0199/0160.Intersection of Two Linked Lists/README_EN.md index d20f4cd098fe0..4235f19e56ec8 100644 --- a/solution/0100-0199/0160.Intersection of Two Linked Lists/README_EN.md +++ b/solution/0100-0199/0160.Intersection of Two Linked Lists/README_EN.md @@ -104,6 +104,8 @@ The time complexity is $O(m+n)$, where $m$ and $n$ are the lengths of the linked +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -121,6 +123,8 @@ class Solution: return a ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -145,6 +149,8 @@ public class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -193,6 +201,8 @@ func getIntersectionNode(headA, headB *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -217,6 +227,8 @@ function getIntersectionNode(headA: ListNode | null, headB: ListNode | null): Li } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -242,6 +254,8 @@ var getIntersectionNode = function (headA, headB) { }; ``` +#### Swift + ```swift /** * Definition for singly-linked list. diff --git a/solution/0100-0199/0161.One Edit Distance/README.md b/solution/0100-0199/0161.One Edit Distance/README.md index 3badd798fd0c6..88a1b2d902f78 100644 --- a/solution/0100-0199/0161.One Edit Distance/README.md +++ b/solution/0100-0199/0161.One Edit Distance/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def isOneEditDistance(self, s: str, t: str) -> bool: @@ -90,6 +92,8 @@ class Solution: return m == n + 1 ``` +#### Java + ```java class Solution { public boolean isOneEditDistance(String s, String t) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func isOneEditDistance(s string, t string) bool { m, n := len(s), len(t) @@ -152,6 +160,8 @@ func isOneEditDistance(s string, t string) bool { } ``` +#### TypeScript + ```ts function isOneEditDistance(s: string, t: string): boolean { const [m, n] = [s.length, t.length]; diff --git a/solution/0100-0199/0161.One Edit Distance/README_EN.md b/solution/0100-0199/0161.One Edit Distance/README_EN.md index cb093602379b3..8732b7ddfea38 100644 --- a/solution/0100-0199/0161.One Edit Distance/README_EN.md +++ b/solution/0100-0199/0161.One Edit Distance/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(m)$, where $m$ is the length of string $s$. The space +#### Python3 + ```python class Solution: def isOneEditDistance(self, s: str, t: str) -> bool: @@ -89,6 +91,8 @@ class Solution: return m == n + 1 ``` +#### Java + ```java class Solution { public boolean isOneEditDistance(String s, String t) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func isOneEditDistance(s string, t string) bool { m, n := len(s), len(t) @@ -151,6 +159,8 @@ func isOneEditDistance(s string, t string) bool { } ``` +#### TypeScript + ```ts function isOneEditDistance(s: string, t: string): boolean { const [m, n] = [s.length, t.length]; diff --git a/solution/0100-0199/0162.Find Peak Element/README.md b/solution/0100-0199/0162.Find Peak Element/README.md index aaab6904e58fc..ceb8522d43546 100644 --- a/solution/0100-0199/0162.Find Peak Element/README.md +++ b/solution/0100-0199/0162.Find Peak Element/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def findPeakElement(self, nums: List[int]) -> int: @@ -84,6 +86,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int findPeakElement(int[] nums) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func findPeakElement(nums []int) int { left, right := 0, len(nums)-1 @@ -134,6 +142,8 @@ func findPeakElement(nums []int) int { } ``` +#### TypeScript + ```ts function findPeakElement(nums: number[]): number { let [left, right] = [0, nums.length - 1]; diff --git a/solution/0100-0199/0162.Find Peak Element/README_EN.md b/solution/0100-0199/0162.Find Peak Element/README_EN.md index 5e807c309066b..e927a9fc15a9f 100644 --- a/solution/0100-0199/0162.Find Peak Element/README_EN.md +++ b/solution/0100-0199/0162.Find Peak Element/README_EN.md @@ -67,6 +67,8 @@ The time complexity is $O(\log n)$, where $n$ is the length of the array $nums$. +#### Python3 + ```python class Solution: def findPeakElement(self, nums: List[int]) -> int: @@ -80,6 +82,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int findPeakElement(int[] nums) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func findPeakElement(nums []int) int { left, right := 0, len(nums)-1 @@ -130,6 +138,8 @@ func findPeakElement(nums []int) int { } ``` +#### TypeScript + ```ts function findPeakElement(nums: number[]): number { let [left, right] = [0, nums.length - 1]; diff --git a/solution/0100-0199/0163.Missing Ranges/README.md b/solution/0100-0199/0163.Missing Ranges/README.md index 7d91a5cb1af1f..ac9d8983f2e2f 100644 --- a/solution/0100-0199/0163.Missing Ranges/README.md +++ b/solution/0100-0199/0163.Missing Ranges/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def findMissingRanges( @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> findMissingRanges(int[] nums, int lower, int upper) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func findMissingRanges(nums []int, lower int, upper int) (ans [][]int) { n := len(nums) @@ -155,6 +163,8 @@ func findMissingRanges(nums []int, lower int, upper int) (ans [][]int) { } ``` +#### TypeScript + ```ts function findMissingRanges(nums: number[], lower: number, upper: number): number[][] { const n = nums.length; diff --git a/solution/0100-0199/0163.Missing Ranges/README_EN.md b/solution/0100-0199/0163.Missing Ranges/README_EN.md index 4539a01680a4d..75956aaf17952 100644 --- a/solution/0100-0199/0163.Missing Ranges/README_EN.md +++ b/solution/0100-0199/0163.Missing Ranges/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. Igno +#### Python3 + ```python class Solution: def findMissingRanges( @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> findMissingRanges(int[] nums, int lower, int upper) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func findMissingRanges(nums []int, lower int, upper int) (ans [][]int) { n := len(nums) @@ -158,6 +166,8 @@ func findMissingRanges(nums []int, lower int, upper int) (ans [][]int) { } ``` +#### TypeScript + ```ts function findMissingRanges(nums: number[], lower: number, upper: number): number[][] { const n = nums.length; diff --git a/solution/0100-0199/0164.Maximum Gap/README.md b/solution/0100-0199/0164.Maximum Gap/README.md index aea51f40afaa3..3a505a5481019 100644 --- a/solution/0100-0199/0164.Maximum Gap/README.md +++ b/solution/0100-0199/0164.Maximum Gap/README.md @@ -74,6 +74,8 @@ $$ +#### Python3 + ```python class Solution: def maximumGap(self, nums: List[int]) -> int: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumGap(int[] nums) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp using pii = pair; @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func maximumGap(nums []int) int { n := len(nums) @@ -207,6 +215,8 @@ func maximumGap(nums []int) int { } ``` +#### C# + ```cs using System; using System.Linq; diff --git a/solution/0100-0199/0164.Maximum Gap/README_EN.md b/solution/0100-0199/0164.Maximum Gap/README_EN.md index 0bb7458dd448e..9349ece793474 100644 --- a/solution/0100-0199/0164.Maximum Gap/README_EN.md +++ b/solution/0100-0199/0164.Maximum Gap/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(m)$, where $m$ is the length of string $s$. The space +#### Python3 + ```python class Solution: def maximumGap(self, nums: List[int]) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumGap(int[] nums) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp using pii = pair; @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func maximumGap(nums []int) int { n := len(nums) @@ -204,6 +212,8 @@ func maximumGap(nums []int) int { } ``` +#### C# + ```cs using System; using System.Linq; diff --git a/solution/0100-0199/0165.Compare Version Numbers/README.md b/solution/0100-0199/0165.Compare Version Numbers/README.md index 0bca5f612bdc2..31ee59fcf8b39 100644 --- a/solution/0100-0199/0165.Compare Version Numbers/README.md +++ b/solution/0100-0199/0165.Compare Version Numbers/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class Solution: def compareVersion(self, version1: str, version2: str) -> int: @@ -113,6 +115,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { public int compareVersion(String version1, String version2) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func compareVersion(version1 string, version2 string) int { m, n := len(version1), len(version2) @@ -180,6 +188,8 @@ func compareVersion(version1 string, version2 string) int { } ``` +#### TypeScript + ```ts function compareVersion(version1: string, version2: string): number { const v1 = version1.split('.'); @@ -197,6 +207,8 @@ function compareVersion(version1: string, version2: string): number { } ``` +#### C# + ```cs public class Solution { public int CompareVersion(string version1, string version2) { diff --git a/solution/0100-0199/0165.Compare Version Numbers/README_EN.md b/solution/0100-0199/0165.Compare Version Numbers/README_EN.md index 5e7c824714920..b723357069164 100644 --- a/solution/0100-0199/0165.Compare Version Numbers/README_EN.md +++ b/solution/0100-0199/0165.Compare Version Numbers/README_EN.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def compareVersion(self, version1: str, version2: str) -> int: @@ -105,6 +107,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { public int compareVersion(String version1, String version2) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func compareVersion(version1 string, version2 string) int { m, n := len(version1), len(version2) @@ -172,6 +180,8 @@ func compareVersion(version1 string, version2 string) int { } ``` +#### TypeScript + ```ts function compareVersion(version1: string, version2: string): number { const v1 = version1.split('.'); @@ -189,6 +199,8 @@ function compareVersion(version1: string, version2: string): number { } ``` +#### C# + ```cs public class Solution { public int CompareVersion(string version1, string version2) { diff --git a/solution/0100-0199/0166.Fraction to Recurring Decimal/README.md b/solution/0100-0199/0166.Fraction to Recurring Decimal/README.md index 7c108b0eef149..bf98e9ad90c86 100644 --- a/solution/0100-0199/0166.Fraction to Recurring Decimal/README.md +++ b/solution/0100-0199/0166.Fraction to Recurring Decimal/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def fractionToDecimal(self, numerator: int, denominator: int) -> str: @@ -110,6 +112,8 @@ class Solution: return "".join(ans) ``` +#### Java + ```java class Solution { public String fractionToDecimal(int numerator, int denominator) { @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -179,6 +185,8 @@ public: }; ``` +#### Go + ```go func fractionToDecimal(numerator int, denominator int) string { if numerator == 0 { @@ -220,6 +228,8 @@ func abs(x int64) int64 { } ``` +#### TypeScript + ```ts function fractionToDecimal(numerator: number, denominator: number): string { if (numerator === 0) { @@ -252,6 +262,8 @@ function fractionToDecimal(numerator: number, denominator: number): string { } ``` +#### C# + ```cs public class Solution { public string FractionToDecimal(int numerator, int denominator) { diff --git a/solution/0100-0199/0166.Fraction to Recurring Decimal/README_EN.md b/solution/0100-0199/0166.Fraction to Recurring Decimal/README_EN.md index e5315a6399cfd..acf8ab93d3724 100644 --- a/solution/0100-0199/0166.Fraction to Recurring Decimal/README_EN.md +++ b/solution/0100-0199/0166.Fraction to Recurring Decimal/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(l)$, and the space complexity is $O(l)$, where $l$ is +#### Python3 + ```python class Solution: def fractionToDecimal(self, numerator: int, denominator: int) -> str: @@ -108,6 +110,8 @@ class Solution: return "".join(ans) ``` +#### Java + ```java class Solution { public String fractionToDecimal(int numerator, int denominator) { @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go func fractionToDecimal(numerator int, denominator int) string { if numerator == 0 { @@ -218,6 +226,8 @@ func abs(x int64) int64 { } ``` +#### TypeScript + ```ts function fractionToDecimal(numerator: number, denominator: number): string { if (numerator === 0) { @@ -250,6 +260,8 @@ function fractionToDecimal(numerator: number, denominator: number): string { } ``` +#### C# + ```cs public class Solution { public string FractionToDecimal(int numerator, int denominator) { diff --git a/solution/0100-0199/0167.Two Sum II - Input Array Is Sorted/README.md b/solution/0100-0199/0167.Two Sum II - Input Array Is Sorted/README.md index 9d78fff40435f..e8101561ddd6b 100644 --- a/solution/0100-0199/0167.Two Sum II - Input Array Is Sorted/README.md +++ b/solution/0100-0199/0167.Two Sum II - Input Array Is Sorted/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def twoSum(self, numbers: List[int], target: int) -> List[int]: @@ -86,6 +88,8 @@ class Solution: return [i + 1, j + 1] ``` +#### Java + ```java class Solution { public int[] twoSum(int[] numbers, int target) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func twoSum(numbers []int, target int) []int { for i, n := 0, len(numbers); ; i++ { @@ -135,6 +143,8 @@ func twoSum(numbers []int, target int) []int { } ``` +#### TypeScript + ```ts function twoSum(numbers: number[], target: number): number[] { const n = numbers.length; @@ -157,6 +167,8 @@ function twoSum(numbers: number[], target: number): number[] { } ``` +#### Rust + ```rust use std::cmp::Ordering; @@ -183,6 +195,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} numbers @@ -224,6 +238,8 @@ var twoSum = function (numbers, target) { +#### Python3 + ```python class Solution: def twoSum(self, numbers: List[int], target: int) -> List[int]: @@ -238,6 +254,8 @@ class Solution: j -= 1 ``` +#### Java + ```java class Solution { public int[] twoSum(int[] numbers, int target) { @@ -256,6 +274,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -275,6 +295,8 @@ public: }; ``` +#### Go + ```go func twoSum(numbers []int, target int) []int { for i, j := 0, len(numbers)-1; ; { @@ -291,6 +313,8 @@ func twoSum(numbers []int, target int) []int { } ``` +#### TypeScript + ```ts function twoSum(numbers: number[], target: number): number[] { for (let i = 0, j = numbers.length - 1; ; ) { @@ -307,6 +331,8 @@ function twoSum(numbers: number[], target: number): number[] { } ``` +#### JavaScript + ```js /** * @param {number[]} numbers diff --git a/solution/0100-0199/0167.Two Sum II - Input Array Is Sorted/README_EN.md b/solution/0100-0199/0167.Two Sum II - Input Array Is Sorted/README_EN.md index b93dea7cb16e9..b5c8ba694a2b1 100644 --- a/solution/0100-0199/0167.Two Sum II - Input Array Is Sorted/README_EN.md +++ b/solution/0100-0199/0167.Two Sum II - Input Array Is Sorted/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(n \times \log n)$, where $n$ is the length of the arra +#### Python3 + ```python class Solution: def twoSum(self, numbers: List[int], target: int) -> List[int]: @@ -87,6 +89,8 @@ class Solution: return [i + 1, j + 1] ``` +#### Java + ```java class Solution { public int[] twoSum(int[] numbers, int target) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func twoSum(numbers []int, target int) []int { for i, n := 0, len(numbers); ; i++ { @@ -136,6 +144,8 @@ func twoSum(numbers []int, target int) []int { } ``` +#### TypeScript + ```ts function twoSum(numbers: number[], target: number): number[] { const n = numbers.length; @@ -158,6 +168,8 @@ function twoSum(numbers: number[], target: number): number[] { } ``` +#### Rust + ```rust use std::cmp::Ordering; @@ -184,6 +196,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} numbers @@ -225,6 +239,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array `numbers`. T +#### Python3 + ```python class Solution: def twoSum(self, numbers: List[int], target: int) -> List[int]: @@ -239,6 +255,8 @@ class Solution: j -= 1 ``` +#### Java + ```java class Solution { public int[] twoSum(int[] numbers, int target) { @@ -257,6 +275,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -276,6 +296,8 @@ public: }; ``` +#### Go + ```go func twoSum(numbers []int, target int) []int { for i, j := 0, len(numbers)-1; ; { @@ -292,6 +314,8 @@ func twoSum(numbers []int, target int) []int { } ``` +#### TypeScript + ```ts function twoSum(numbers: number[], target: number): number[] { for (let i = 0, j = numbers.length - 1; ; ) { @@ -308,6 +332,8 @@ function twoSum(numbers: number[], target: number): number[] { } ``` +#### JavaScript + ```js /** * @param {number[]} numbers diff --git a/solution/0100-0199/0168.Excel Sheet Column Title/README.md b/solution/0100-0199/0168.Excel Sheet Column Title/README.md index c542b47cd1587..532e5d275af34 100644 --- a/solution/0100-0199/0168.Excel Sheet Column Title/README.md +++ b/solution/0100-0199/0168.Excel Sheet Column Title/README.md @@ -80,6 +80,8 @@ AB -> 28 +#### Python3 + ```python class Solution: def convertToTitle(self, columnNumber: int) -> str: @@ -91,6 +93,8 @@ class Solution: return ''.join(res[::-1]) ``` +#### Java + ```java class Solution { public String convertToTitle(int columnNumber) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### Go + ```go func convertToTitle(columnNumber int) string { res := []rune{} @@ -117,6 +123,8 @@ func convertToTitle(columnNumber int) string { } ``` +#### TypeScript + ```ts function convertToTitle(columnNumber: number): string { let res: string[] = []; @@ -130,6 +138,8 @@ function convertToTitle(columnNumber: number): string { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -154,6 +164,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public string ConvertToTitle(int columnNumber) { diff --git a/solution/0100-0199/0168.Excel Sheet Column Title/README_EN.md b/solution/0100-0199/0168.Excel Sheet Column Title/README_EN.md index 42ece9cc7ae44..e9ddee46e92c4 100644 --- a/solution/0100-0199/0168.Excel Sheet Column Title/README_EN.md +++ b/solution/0100-0199/0168.Excel Sheet Column Title/README_EN.md @@ -71,6 +71,8 @@ AB -> 28 +#### Python3 + ```python class Solution: def convertToTitle(self, columnNumber: int) -> str: @@ -82,6 +84,8 @@ class Solution: return ''.join(res[::-1]) ``` +#### Java + ```java class Solution { public String convertToTitle(int columnNumber) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### Go + ```go func convertToTitle(columnNumber int) string { res := []rune{} @@ -108,6 +114,8 @@ func convertToTitle(columnNumber int) string { } ``` +#### TypeScript + ```ts function convertToTitle(columnNumber: number): string { let res: string[] = []; @@ -121,6 +129,8 @@ function convertToTitle(columnNumber: number): string { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -145,6 +155,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public string ConvertToTitle(int columnNumber) { diff --git a/solution/0100-0199/0169.Majority Element/README.md b/solution/0100-0199/0169.Majority Element/README.md index d74d0660cf4c4..5c93a60b7e2e7 100644 --- a/solution/0100-0199/0169.Majority Element/README.md +++ b/solution/0100-0199/0169.Majority Element/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def majorityElement(self, nums: List[int]) -> int: @@ -85,6 +87,8 @@ class Solution: return m ``` +#### Java + ```java class Solution { public int majorityElement(int[] nums) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func majorityElement(nums []int) int { var cnt, m int @@ -138,6 +146,8 @@ func majorityElement(nums []int) int { } ``` +#### TypeScript + ```ts function majorityElement(nums: number[]): number { let cnt: number = 0; @@ -154,6 +164,8 @@ function majorityElement(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn majority_element(nums: Vec) -> i32 { @@ -172,6 +184,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -192,6 +206,8 @@ var majorityElement = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int MajorityElement(int[] nums) { @@ -209,6 +225,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0100-0199/0169.Majority Element/README_EN.md b/solution/0100-0199/0169.Majority Element/README_EN.md index c6ac7aa3bbd3e..b871a1cef51c8 100644 --- a/solution/0100-0199/0169.Majority Element/README_EN.md +++ b/solution/0100-0199/0169.Majority Element/README_EN.md @@ -65,6 +65,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def majorityElement(self, nums: List[int]) -> int: @@ -77,6 +79,8 @@ class Solution: return m ``` +#### Java + ```java class Solution { public int majorityElement(int[] nums) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func majorityElement(nums []int) int { var cnt, m int @@ -130,6 +138,8 @@ func majorityElement(nums []int) int { } ``` +#### TypeScript + ```ts function majorityElement(nums: number[]): number { let cnt: number = 0; @@ -146,6 +156,8 @@ function majorityElement(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn majority_element(nums: Vec) -> i32 { @@ -164,6 +176,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -184,6 +198,8 @@ var majorityElement = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int MajorityElement(int[] nums) { @@ -201,6 +217,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0100-0199/0170.Two Sum III - Data structure design/README.md b/solution/0100-0199/0170.Two Sum III - Data structure design/README.md index c541ecb99ddc5..b18008487be88 100644 --- a/solution/0100-0199/0170.Two Sum III - Data structure design/README.md +++ b/solution/0100-0199/0170.Two Sum III - Data structure design/README.md @@ -82,6 +82,8 @@ twoSum.find(7); // 没有两个整数加起来等于 7 ,返回 false +#### Python3 + ```python class TwoSum: @@ -105,6 +107,8 @@ class TwoSum: # param_2 = obj.find(value) ``` +#### Java + ```java class TwoSum { private Map cnt = new HashMap<>(); @@ -136,6 +140,8 @@ class TwoSum { */ ``` +#### C++ + ```cpp class TwoSum { public: @@ -168,6 +174,8 @@ private: */ ``` +#### Go + ```go type TwoSum struct { cnt map[int]int @@ -199,6 +207,8 @@ func (this *TwoSum) Find(value int) bool { */ ``` +#### TypeScript + ```ts class TwoSum { private cnt: Map = new Map(); diff --git a/solution/0100-0199/0170.Two Sum III - Data structure design/README_EN.md b/solution/0100-0199/0170.Two Sum III - Data structure design/README_EN.md index e5f3c7da51f03..81efef8d15e13 100644 --- a/solution/0100-0199/0170.Two Sum III - Data structure design/README_EN.md +++ b/solution/0100-0199/0170.Two Sum III - Data structure design/README_EN.md @@ -81,6 +81,8 @@ Space complexity is $O(n)$, where $n$ is the size of the hash table `cnt`. +#### Python3 + ```python class TwoSum: @@ -104,6 +106,8 @@ class TwoSum: # param_2 = obj.find(value) ``` +#### Java + ```java class TwoSum { private Map cnt = new HashMap<>(); @@ -135,6 +139,8 @@ class TwoSum { */ ``` +#### C++ + ```cpp class TwoSum { public: @@ -167,6 +173,8 @@ private: */ ``` +#### Go + ```go type TwoSum struct { cnt map[int]int @@ -198,6 +206,8 @@ func (this *TwoSum) Find(value int) bool { */ ``` +#### TypeScript + ```ts class TwoSum { private cnt: Map = new Map(); diff --git a/solution/0100-0199/0171.Excel Sheet Column Number/README.md b/solution/0100-0199/0171.Excel Sheet Column Number/README.md index 7d752182fe98d..95d11b17a2d79 100644 --- a/solution/0100-0199/0171.Excel Sheet Column Number/README.md +++ b/solution/0100-0199/0171.Excel Sheet Column Number/README.md @@ -79,6 +79,8 @@ Excel 表格中的列名称是一种 26 进制的表示方法。例如,"AB" +#### Python3 + ```python class Solution: def titleToNumber(self, columnTitle: str) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int titleToNumber(String columnTitle) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func titleToNumber(columnTitle string) (ans int) { for _, c := range columnTitle { @@ -122,6 +130,8 @@ func titleToNumber(columnTitle string) (ans int) { } ``` +#### TypeScript + ```ts function titleToNumber(columnTitle: string): number { let ans: number = 0; @@ -132,6 +142,8 @@ function titleToNumber(columnTitle: string): number { } ``` +#### C# + ```cs public class Solution { public int TitleToNumber(string columnTitle) { diff --git a/solution/0100-0199/0171.Excel Sheet Column Number/README_EN.md b/solution/0100-0199/0171.Excel Sheet Column Number/README_EN.md index b80a725d3ac58..c147495c945a9 100644 --- a/solution/0100-0199/0171.Excel Sheet Column Number/README_EN.md +++ b/solution/0100-0199/0171.Excel Sheet Column Number/README_EN.md @@ -79,6 +79,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string `columnTitl +#### Python3 + ```python class Solution: def titleToNumber(self, columnTitle: str) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int titleToNumber(String columnTitle) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func titleToNumber(columnTitle string) (ans int) { for _, c := range columnTitle { @@ -122,6 +130,8 @@ func titleToNumber(columnTitle string) (ans int) { } ``` +#### TypeScript + ```ts function titleToNumber(columnTitle: string): number { let ans: number = 0; @@ -132,6 +142,8 @@ function titleToNumber(columnTitle: string): number { } ``` +#### C# + ```cs public class Solution { public int TitleToNumber(string columnTitle) { diff --git a/solution/0100-0199/0172.Factorial Trailing Zeroes/README.md b/solution/0100-0199/0172.Factorial Trailing Zeroes/README.md index 9978dd0b006f7..09cb06df91376 100644 --- a/solution/0100-0199/0172.Factorial Trailing Zeroes/README.md +++ b/solution/0100-0199/0172.Factorial Trailing Zeroes/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def trailingZeroes(self, n: int) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int trailingZeroes(int n) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func trailingZeroes(n int) int { ans := 0 @@ -126,6 +134,8 @@ func trailingZeroes(n int) int { } ``` +#### TypeScript + ```ts function trailingZeroes(n: number): number { let ans = 0; diff --git a/solution/0100-0199/0172.Factorial Trailing Zeroes/README_EN.md b/solution/0100-0199/0172.Factorial Trailing Zeroes/README_EN.md index 873aa40cedef3..63b9001ae44eb 100644 --- a/solution/0100-0199/0172.Factorial Trailing Zeroes/README_EN.md +++ b/solution/0100-0199/0172.Factorial Trailing Zeroes/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(\log n)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def trailingZeroes(self, n: int) -> int: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int trailingZeroes(int n) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func trailingZeroes(n int) int { ans := 0 @@ -123,6 +131,8 @@ func trailingZeroes(n int) int { } ``` +#### TypeScript + ```ts function trailingZeroes(n: number): number { let ans = 0; diff --git a/solution/0100-0199/0173.Binary Search Tree Iterator/README.md b/solution/0100-0199/0173.Binary Search Tree Iterator/README.md index 31592f9dbf8b2..b6f13f2d53221 100644 --- a/solution/0100-0199/0173.Binary Search Tree Iterator/README.md +++ b/solution/0100-0199/0173.Binary Search Tree Iterator/README.md @@ -94,6 +94,8 @@ bSTIterator.hasNext(); // 返回 False +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -128,6 +130,8 @@ class BSTIterator: # param_2 = obj.hasNext() ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -177,6 +181,8 @@ class BSTIterator { */ ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -223,6 +229,8 @@ public: */ ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -267,6 +275,8 @@ func (this *BSTIterator) HasNext() bool { */ ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -318,6 +328,8 @@ class BSTIterator { */ ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -383,6 +395,8 @@ impl BSTIterator { */ ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -443,6 +457,8 @@ BSTIterator.prototype.hasNext = function () { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -475,6 +491,8 @@ class BSTIterator: # param_2 = obj.hasNext() ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -521,6 +539,8 @@ class BSTIterator { */ ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -565,6 +585,8 @@ public: */ ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -620,6 +642,8 @@ class BSTIterator { */ ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/0100-0199/0173.Binary Search Tree Iterator/README_EN.md b/solution/0100-0199/0173.Binary Search Tree Iterator/README_EN.md index be0eb27cd43b3..d78520b80b348 100644 --- a/solution/0100-0199/0173.Binary Search Tree Iterator/README_EN.md +++ b/solution/0100-0199/0173.Binary Search Tree Iterator/README_EN.md @@ -83,6 +83,8 @@ bSTIterator.hasNext(); // return False +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -117,6 +119,8 @@ class BSTIterator: # param_2 = obj.hasNext() ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -166,6 +170,8 @@ class BSTIterator { */ ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -212,6 +218,8 @@ public: */ ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -256,6 +264,8 @@ func (this *BSTIterator) HasNext() bool { */ ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -307,6 +317,8 @@ class BSTIterator { */ ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -372,6 +384,8 @@ impl BSTIterator { */ ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -428,6 +442,8 @@ BSTIterator.prototype.hasNext = function () { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -460,6 +476,8 @@ class BSTIterator: # param_2 = obj.hasNext() ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -506,6 +524,8 @@ class BSTIterator { */ ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -550,6 +570,8 @@ public: */ ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -605,6 +627,8 @@ class BSTIterator { */ ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/0100-0199/0174.Dungeon Game/README.md b/solution/0100-0199/0174.Dungeon Game/README.md index 4a8d3a730ab49..a69a32c5d07ad 100644 --- a/solution/0100-0199/0174.Dungeon Game/README.md +++ b/solution/0100-0199/0174.Dungeon Game/README.md @@ -87,6 +87,8 @@ $$ +#### Python3 + ```python class Solution: def calculateMinimumHP(self, dungeon: List[List[int]]) -> int: @@ -99,6 +101,8 @@ class Solution: return dp[0][0] ``` +#### Java + ```java class Solution { public int calculateMinimumHP(int[][] dungeon) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func calculateMinimumHP(dungeon [][]int) int { m, n := len(dungeon), len(dungeon[0]) @@ -156,6 +164,8 @@ func calculateMinimumHP(dungeon [][]int) int { } ``` +#### C# + ```cs public class Solution { public int CalculateMinimumHP(int[][] dungeon) { diff --git a/solution/0100-0199/0174.Dungeon Game/README_EN.md b/solution/0100-0199/0174.Dungeon Game/README_EN.md index 7469f1908e168..773e98df9dd3c 100644 --- a/solution/0100-0199/0174.Dungeon Game/README_EN.md +++ b/solution/0100-0199/0174.Dungeon Game/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def calculateMinimumHP(self, dungeon: List[List[int]]) -> int: @@ -88,6 +90,8 @@ class Solution: return dp[0][0] ``` +#### Java + ```java class Solution { public int calculateMinimumHP(int[][] dungeon) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func calculateMinimumHP(dungeon [][]int) int { m, n := len(dungeon), len(dungeon[0]) @@ -145,6 +153,8 @@ func calculateMinimumHP(dungeon [][]int) int { } ``` +#### C# + ```cs public class Solution { public int CalculateMinimumHP(int[][] dungeon) { diff --git a/solution/0100-0199/0175.Combine Two Tables/README.md b/solution/0100-0199/0175.Combine Two Tables/README.md index 454b9cebbe627..79f907ea652ab 100644 --- a/solution/0100-0199/0175.Combine Two Tables/README.md +++ b/solution/0100-0199/0175.Combine Two Tables/README.md @@ -98,6 +98,8 @@ addressId = 1 包含了 personId = 2 的地址信息。 +#### Python3 + ```python import pandas as pd @@ -108,6 +110,8 @@ def combine_two_tables(person: pd.DataFrame, address: pd.DataFrame) -> pd.DataFr ] ``` +#### MySQL + ```sql # Write your MySQL query statement below SELECT firstName, lastName, city, state diff --git a/solution/0100-0199/0175.Combine Two Tables/README_EN.md b/solution/0100-0199/0175.Combine Two Tables/README_EN.md index db162e8a9d83e..830d01f13504d 100644 --- a/solution/0100-0199/0175.Combine Two Tables/README_EN.md +++ b/solution/0100-0199/0175.Combine Two Tables/README_EN.md @@ -98,6 +98,8 @@ We can use a left join to join the `Person` table with the `Address` table on th +#### Python3 + ```python import pandas as pd @@ -108,6 +110,8 @@ def combine_two_tables(person: pd.DataFrame, address: pd.DataFrame) -> pd.DataFr ] ``` +#### MySQL + ```sql # Write your MySQL query statement below SELECT firstName, lastName, city, state diff --git a/solution/0100-0199/0176.Second Highest Salary/README.md b/solution/0100-0199/0176.Second Highest Salary/README.md index e81acdca11102..7e2f110891385 100644 --- a/solution/0100-0199/0176.Second Highest Salary/README.md +++ b/solution/0100-0199/0176.Second Highest Salary/README.md @@ -91,6 +91,8 @@ Employee 表: +#### Python3 + ```python import pandas as pd @@ -114,6 +116,8 @@ def second_highest_salary(employee: pd.DataFrame) -> pd.DataFrame: return result_df ``` +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -137,6 +141,8 @@ SELECT +#### MySQL + ```sql # Write your MySQL query statement below SELECT MAX(salary) AS SecondHighestSalary @@ -156,6 +162,8 @@ WHERE salary < (SELECT MAX(salary) FROM Employee); +#### MySQL + ```sql # Write your MySQL query statement below WITH T AS (SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS rk FROM Employee) diff --git a/solution/0100-0199/0176.Second Highest Salary/README_EN.md b/solution/0100-0199/0176.Second Highest Salary/README_EN.md index 4e3709888813a..dc497121217dd 100644 --- a/solution/0100-0199/0176.Second Highest Salary/README_EN.md +++ b/solution/0100-0199/0176.Second Highest Salary/README_EN.md @@ -84,6 +84,8 @@ Employee table: +#### Python3 + ```python import pandas as pd @@ -107,6 +109,8 @@ def second_highest_salary(employee: pd.DataFrame) -> pd.DataFrame: return result_df ``` +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -128,6 +132,8 @@ SELECT +#### MySQL + ```sql # Write your MySQL query statement below SELECT MAX(salary) AS SecondHighestSalary @@ -145,6 +151,8 @@ WHERE salary < (SELECT MAX(salary) FROM Employee); +#### MySQL + ```sql # Write your MySQL query statement below WITH T AS (SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS rk FROM Employee) diff --git a/solution/0100-0199/0177.Nth Highest Salary/README.md b/solution/0100-0199/0177.Nth Highest Salary/README.md index 6c165481f74c2..a454acc7fb208 100644 --- a/solution/0100-0199/0177.Nth Highest Salary/README.md +++ b/solution/0100-0199/0177.Nth Highest Salary/README.md @@ -88,6 +88,8 @@ n = 2 +#### Python3 + ```python import pandas as pd @@ -101,6 +103,8 @@ def nth_highest_salary(employee: pd.DataFrame, N: int) -> pd.DataFrame: return pd.DataFrame([salary], columns=[f"getNthHighestSalary({N})"]) ``` +#### MySQL + ```sql CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT BEGIN diff --git a/solution/0100-0199/0177.Nth Highest Salary/README_EN.md b/solution/0100-0199/0177.Nth Highest Salary/README_EN.md index 8c57f1d993800..37c056f9d75ef 100644 --- a/solution/0100-0199/0177.Nth Highest Salary/README_EN.md +++ b/solution/0100-0199/0177.Nth Highest Salary/README_EN.md @@ -86,6 +86,8 @@ n = 2 +#### Python3 + ```python import pandas as pd @@ -99,6 +101,8 @@ def nth_highest_salary(employee: pd.DataFrame, N: int) -> pd.DataFrame: return pd.DataFrame([salary], columns=[f"getNthHighestSalary({N})"]) ``` +#### MySQL + ```sql CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT BEGIN diff --git a/solution/0100-0199/0178.Rank Scores/README.md b/solution/0100-0199/0178.Rank Scores/README.md index 1e495c29c316c..01e49defdf490 100644 --- a/solution/0100-0199/0178.Rank Scores/README.md +++ b/solution/0100-0199/0178.Rank Scores/README.md @@ -98,6 +98,8 @@ DENSE_RANK() OVER ( +#### Python3 + ```python import pandas as pd @@ -112,6 +114,8 @@ def order_scores(scores: pd.DataFrame) -> pd.DataFrame: return result_df ``` +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -132,6 +136,8 @@ MySQL 8 开始才提供了 `ROW_NUMBER()`,`RANK()`,`DENSE_RANK()` 等[窗口 +#### MySQL + ```sql SELECT Score, diff --git a/solution/0100-0199/0178.Rank Scores/README_EN.md b/solution/0100-0199/0178.Rank Scores/README_EN.md index a1ab9ed2db5e9..0b2a8402c94be 100644 --- a/solution/0100-0199/0178.Rank Scores/README_EN.md +++ b/solution/0100-0199/0178.Rank Scores/README_EN.md @@ -82,6 +82,8 @@ Scores table: +#### Python3 + ```python import pandas as pd @@ -96,6 +98,8 @@ def order_scores(scores: pd.DataFrame) -> pd.DataFrame: return result_df ``` +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -114,6 +118,8 @@ FROM Scores; +#### MySQL + ```sql SELECT Score, diff --git a/solution/0100-0199/0179.Largest Number/README.md b/solution/0100-0199/0179.Largest Number/README.md index 599f389413f4c..e99edd8a8d578 100644 --- a/solution/0100-0199/0179.Largest Number/README.md +++ b/solution/0100-0199/0179.Largest Number/README.md @@ -59,6 +59,8 @@ tags: +#### Python3 + ```python class Solution: def largestNumber(self, nums: List[int]) -> str: @@ -67,6 +69,8 @@ class Solution: return "0" if nums[0] == "0" else "".join(nums) ``` +#### Java + ```java class Solution { public String largestNumber(int[] nums) { @@ -83,6 +87,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -100,6 +106,8 @@ public: }; ``` +#### Go + ```go func largestNumber(nums []int) string { vs := make([]string, len(nums)) @@ -116,6 +124,8 @@ func largestNumber(nums []int) string { } ``` +#### C# + ```cs using System; using System.Globalization; diff --git a/solution/0100-0199/0179.Largest Number/README_EN.md b/solution/0100-0199/0179.Largest Number/README_EN.md index 01a32040d48ba..f8a1a3697882b 100644 --- a/solution/0100-0199/0179.Largest Number/README_EN.md +++ b/solution/0100-0199/0179.Largest Number/README_EN.md @@ -56,6 +56,8 @@ tags: +#### Python3 + ```python class Solution: def largestNumber(self, nums: List[int]) -> str: @@ -64,6 +66,8 @@ class Solution: return "0" if nums[0] == "0" else "".join(nums) ``` +#### Java + ```java class Solution { public String largestNumber(int[] nums) { @@ -80,6 +84,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -97,6 +103,8 @@ public: }; ``` +#### Go + ```go func largestNumber(nums []int) string { vs := make([]string, len(nums)) @@ -113,6 +121,8 @@ func largestNumber(nums []int) string { } ``` +#### C# + ```cs using System; using System.Globalization; diff --git a/solution/0100-0199/0180.Consecutive Numbers/README.md b/solution/0100-0199/0180.Consecutive Numbers/README.md index ed86b5814df02..fd0c50993e64d 100644 --- a/solution/0100-0199/0180.Consecutive Numbers/README.md +++ b/solution/0100-0199/0180.Consecutive Numbers/README.md @@ -77,6 +77,8 @@ Result 表: +#### Python3 + ```python import pandas as pd @@ -93,6 +95,8 @@ def consecutive_numbers(logs: pd.DataFrame) -> pd.DataFrame: ) ``` +#### MySQL + ```sql # Write your MySQL query statement below SELECT DISTINCT l2.num AS ConsecutiveNums @@ -116,6 +120,8 @@ FROM +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -141,6 +147,8 @@ WHERE a = num AND b = num; +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0100-0199/0180.Consecutive Numbers/README_EN.md b/solution/0100-0199/0180.Consecutive Numbers/README_EN.md index 6c87e91b2e43c..e9deb142b83ba 100644 --- a/solution/0100-0199/0180.Consecutive Numbers/README_EN.md +++ b/solution/0100-0199/0180.Consecutive Numbers/README_EN.md @@ -77,6 +77,8 @@ First, we perform a self-join with the condition `l1.num = l2.num` and `l1.id = +#### Python3 + ```python import pandas as pd @@ -93,6 +95,8 @@ def consecutive_numbers(logs: pd.DataFrame) -> pd.DataFrame: ) ``` +#### MySQL + ```sql # Write your MySQL query statement below SELECT DISTINCT l2.num AS ConsecutiveNums @@ -116,6 +120,8 @@ We can also group the numbers by using the `IF` function to determine whether th +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -141,6 +147,8 @@ WHERE a = num AND b = num; +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0100-0199/0181.Employees Earning More Than Their Managers/README.md b/solution/0100-0199/0181.Employees Earning More Than Their Managers/README.md index 0df6fd603941c..3b482f41a59b9 100644 --- a/solution/0100-0199/0181.Employees Earning More Than Their Managers/README.md +++ b/solution/0100-0199/0181.Employees Earning More Than Their Managers/README.md @@ -72,6 +72,8 @@ Employee 表: +#### Python3 + ```python import pandas as pd @@ -83,6 +85,8 @@ def find_employees(employee: pd.DataFrame) -> pd.DataFrame: return pd.DataFrame({"Employee": emp}) ``` +#### MySQL + ```sql SELECT Name AS Employee FROM Employee AS Curr @@ -104,6 +108,8 @@ WHERE +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/0100-0199/0181.Employees Earning More Than Their Managers/README_EN.md b/solution/0100-0199/0181.Employees Earning More Than Their Managers/README_EN.md index 90d3b1728eed4..60ad47ffbcc60 100644 --- a/solution/0100-0199/0181.Employees Earning More Than Their Managers/README_EN.md +++ b/solution/0100-0199/0181.Employees Earning More Than Their Managers/README_EN.md @@ -72,6 +72,8 @@ Employee table: +#### Python3 + ```python import pandas as pd @@ -83,6 +85,8 @@ def find_employees(employee: pd.DataFrame) -> pd.DataFrame: return pd.DataFrame({"Employee": emp}) ``` +#### MySQL + ```sql SELECT Name AS Employee FROM Employee AS Curr @@ -104,6 +108,8 @@ WHERE +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/0100-0199/0182.Duplicate Emails/README.md b/solution/0100-0199/0182.Duplicate Emails/README.md index f66a1d61e19a7..7a9b5bff551e6 100644 --- a/solution/0100-0199/0182.Duplicate Emails/README.md +++ b/solution/0100-0199/0182.Duplicate Emails/README.md @@ -73,6 +73,8 @@ Person 表: +#### Python3 + ```python import pandas as pd @@ -85,6 +87,8 @@ def duplicate_emails(person: pd.DataFrame) -> pd.DataFrame: return results.drop_duplicates() ``` +#### MySQL + ```sql # Write your MySQL query statement below SELECT email @@ -105,6 +109,8 @@ HAVING COUNT(1) > 1; +#### MySQL + ```sql SELECT DISTINCT p1.email FROM diff --git a/solution/0100-0199/0182.Duplicate Emails/README_EN.md b/solution/0100-0199/0182.Duplicate Emails/README_EN.md index 7781c2a5f60cd..147ebd7dfe8ba 100644 --- a/solution/0100-0199/0182.Duplicate Emails/README_EN.md +++ b/solution/0100-0199/0182.Duplicate Emails/README_EN.md @@ -71,6 +71,8 @@ We can use the `GROUP BY` statement to group the data by the `email` field, and +#### Python3 + ```python import pandas as pd @@ -83,6 +85,8 @@ def duplicate_emails(person: pd.DataFrame) -> pd.DataFrame: return results.drop_duplicates() ``` +#### MySQL + ```sql # Write your MySQL query statement below SELECT email @@ -103,6 +107,8 @@ We can use a self-join to join the `Person` table with itself, and then filter o +#### MySQL + ```sql SELECT DISTINCT p1.email FROM diff --git a/solution/0100-0199/0183.Customers Who Never Order/README.md b/solution/0100-0199/0183.Customers Who Never Order/README.md index a26281d00e500..10ea6765bb25a 100644 --- a/solution/0100-0199/0183.Customers Who Never Order/README.md +++ b/solution/0100-0199/0183.Customers Who Never Order/README.md @@ -91,6 +91,8 @@ Orders table: +#### Python3 + ```python import pandas as pd @@ -105,6 +107,8 @@ def find_customers(customers: pd.DataFrame, orders: pd.DataFrame) -> pd.DataFram return df ``` +#### MySQL + ```sql # Write your MySQL query statement below SELECT name AS Customers @@ -128,6 +132,8 @@ WHERE +#### MySQL + ```sql # Write your MySQL query statement below SELECT name AS Customers diff --git a/solution/0100-0199/0183.Customers Who Never Order/README_EN.md b/solution/0100-0199/0183.Customers Who Never Order/README_EN.md index b1819f18124a8..e76969e46a4ea 100644 --- a/solution/0100-0199/0183.Customers Who Never Order/README_EN.md +++ b/solution/0100-0199/0183.Customers Who Never Order/README_EN.md @@ -95,6 +95,8 @@ List all customer IDs of existing orders, and use `NOT IN` to find customers who +#### Python3 + ```python import pandas as pd @@ -109,6 +111,8 @@ def find_customers(customers: pd.DataFrame, orders: pd.DataFrame) -> pd.DataFram return df ``` +#### MySQL + ```sql # Write your MySQL query statement below SELECT name AS Customers @@ -132,6 +136,8 @@ Use `LEFT JOIN` to join the tables and return the data where `CustomerId` is `NU +#### MySQL + ```sql # Write your MySQL query statement below SELECT name AS Customers diff --git a/solution/0100-0199/0184.Department Highest Salary/README.md b/solution/0100-0199/0184.Department Highest Salary/README.md index ab0c187f9aeb7..f22679744afbb 100644 --- a/solution/0100-0199/0184.Department Highest Salary/README.md +++ b/solution/0100-0199/0184.Department Highest Salary/README.md @@ -98,6 +98,8 @@ Department 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT d.name AS department, e.name AS employee, salary @@ -124,6 +126,8 @@ WHERE +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0100-0199/0184.Department Highest Salary/README_EN.md b/solution/0100-0199/0184.Department Highest Salary/README_EN.md index c734d5368160b..68aad979846ff 100644 --- a/solution/0100-0199/0184.Department Highest Salary/README_EN.md +++ b/solution/0100-0199/0184.Department Highest Salary/README_EN.md @@ -100,6 +100,8 @@ We can use an equi-join to join the `Employee` table and the `Department` table +#### MySQL + ```sql # Write your MySQL query statement below SELECT d.name AS department, e.name AS employee, salary @@ -126,6 +128,8 @@ We can use an equi-join to join the `Employee` table and the `Department` table +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0100-0199/0185.Department Top Three Salaries/README.md b/solution/0100-0199/0185.Department Top Three Salaries/README.md index da277975ac742..ef1e039e943f9 100644 --- a/solution/0100-0199/0185.Department Top Three Salaries/README.md +++ b/solution/0100-0199/0185.Department Top Three Salaries/README.md @@ -114,6 +114,8 @@ Department 表: +#### Python3 + ```python import pandas as pd @@ -137,6 +139,8 @@ def top_three_salaries( )[["Department", "Employee", "Salary"]] ``` +#### MySQL + ```sql SELECT Department.NAME AS Department, @@ -165,6 +169,8 @@ WHERE +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0100-0199/0185.Department Top Three Salaries/README_EN.md b/solution/0100-0199/0185.Department Top Three Salaries/README_EN.md index 782ee2a71f867..7dd424a7acf28 100644 --- a/solution/0100-0199/0185.Department Top Three Salaries/README_EN.md +++ b/solution/0100-0199/0185.Department Top Three Salaries/README_EN.md @@ -114,6 +114,8 @@ In the Sales department: +#### Python3 + ```python import pandas as pd @@ -137,6 +139,8 @@ def top_three_salaries( )[["Department", "Employee", "Salary"]] ``` +#### MySQL + ```sql SELECT Department.NAME AS Department, @@ -165,6 +169,8 @@ WHERE +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0100-0199/0186.Reverse Words in a String II/README.md b/solution/0100-0199/0186.Reverse Words in a String II/README.md index 7cb4f9330c5ff..bb5cb4eac334d 100644 --- a/solution/0100-0199/0186.Reverse Words in a String II/README.md +++ b/solution/0100-0199/0186.Reverse Words in a String II/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def reverseWords(self, s: List[str]) -> None: @@ -87,6 +89,8 @@ class Solution: reverse(0, n - 1) ``` +#### Java + ```java class Solution { public void reverseWords(char[] s) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func reverseWords(s []byte) { reverse := func(i, j int) { @@ -155,6 +163,8 @@ func reverseWords(s []byte) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify s in-place instead. diff --git a/solution/0100-0199/0186.Reverse Words in a String II/README_EN.md b/solution/0100-0199/0186.Reverse Words in a String II/README_EN.md index 3647421054a9d..39d40e2b8a690 100644 --- a/solution/0100-0199/0186.Reverse Words in a String II/README_EN.md +++ b/solution/0100-0199/0186.Reverse Words in a String II/README_EN.md @@ -56,6 +56,8 @@ The time complexity is $O(n)$, where $n$ is the length of the character array $s +#### Python3 + ```python class Solution: def reverseWords(self, s: List[str]) -> None: @@ -74,6 +76,8 @@ class Solution: reverse(0, n - 1) ``` +#### Java + ```java class Solution { public void reverseWords(char[] s) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func reverseWords(s []byte) { reverse := func(i, j int) { @@ -142,6 +150,8 @@ func reverseWords(s []byte) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify s in-place instead. diff --git a/solution/0100-0199/0187.Repeated DNA Sequences/README.md b/solution/0100-0199/0187.Repeated DNA Sequences/README.md index 3146fa000717f..f1e60dd2fc046 100644 --- a/solution/0100-0199/0187.Repeated DNA Sequences/README.md +++ b/solution/0100-0199/0187.Repeated DNA Sequences/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def findRepeatedDnaSequences(self, s: str) -> List[str]: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List findRepeatedDnaSequences(String s) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func findRepeatedDnaSequences(s string) (ans []string) { cnt := map[string]int{} @@ -134,6 +142,8 @@ func findRepeatedDnaSequences(s string) (ans []string) { } ``` +#### TypeScript + ```ts function findRepeatedDnaSequences(s: string): string[] { const n = s.length; @@ -150,6 +160,8 @@ function findRepeatedDnaSequences(s: string): string[] { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -173,6 +185,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -192,6 +206,8 @@ var findRepeatedDnaSequences = function (s) { }; ``` +#### C# + ```cs public class Solution { public IList FindRepeatedDnaSequences(string s) { @@ -225,6 +241,8 @@ public class Solution { +#### Go + ```go func findRepeatedDnaSequences(s string) []string { hashCode := map[byte]int{'A': 0, 'C': 1, 'G': 2, 'T': 3} diff --git a/solution/0100-0199/0187.Repeated DNA Sequences/README_EN.md b/solution/0100-0199/0187.Repeated DNA Sequences/README_EN.md index 7e6542550a893..9f78b38d510dc 100644 --- a/solution/0100-0199/0187.Repeated DNA Sequences/README_EN.md +++ b/solution/0100-0199/0187.Repeated DNA Sequences/README_EN.md @@ -65,6 +65,8 @@ The time complexity is $O(n \times 10)$, and the space complexity is $O(n \times +#### Python3 + ```python class Solution: def findRepeatedDnaSequences(self, s: str) -> List[str]: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List findRepeatedDnaSequences(String s) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func findRepeatedDnaSequences(s string) (ans []string) { cnt := map[string]int{} @@ -125,6 +133,8 @@ func findRepeatedDnaSequences(s string) (ans []string) { } ``` +#### TypeScript + ```ts function findRepeatedDnaSequences(s: string): string[] { const n = s.length; @@ -141,6 +151,8 @@ function findRepeatedDnaSequences(s: string): string[] { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -164,6 +176,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -183,6 +197,8 @@ var findRepeatedDnaSequences = function (s) { }; ``` +#### C# + ```cs public class Solution { public IList FindRepeatedDnaSequences(string s) { @@ -216,6 +232,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Go + ```go func findRepeatedDnaSequences(s string) []string { hashCode := map[byte]int{'A': 0, 'C': 1, 'G': 2, 'T': 3} diff --git a/solution/0100-0199/0188.Best Time to Buy and Sell Stock IV/README.md b/solution/0100-0199/0188.Best Time to Buy and Sell Stock IV/README.md index e229bcbb38533..64877a4442c15 100644 --- a/solution/0100-0199/0188.Best Time to Buy and Sell Stock IV/README.md +++ b/solution/0100-0199/0188.Best Time to Buy and Sell Stock IV/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def maxProfit(self, k: int, prices: List[int]) -> int: @@ -92,6 +94,8 @@ class Solution: return dfs(0, k, 0) ``` +#### Java + ```java class Solution { private Integer[][][] f; @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func maxProfit(k int, prices []int) int { n := len(prices) @@ -181,6 +189,8 @@ func maxProfit(k int, prices []int) int { } ``` +#### TypeScript + ```ts function maxProfit(k: number, prices: number[]): number { const n = prices.length; @@ -206,6 +216,8 @@ function maxProfit(k: number, prices: number[]): number { } ``` +#### C# + ```cs public class Solution { private int[,,] f; @@ -278,6 +290,8 @@ $$ +#### Python3 + ```python class Solution: def maxProfit(self, k: int, prices: List[int]) -> int: @@ -292,6 +306,8 @@ class Solution: return f[n - 1][k][0] ``` +#### Java + ```java class Solution { public int maxProfit(int k, int[] prices) { @@ -311,6 +327,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -332,6 +350,8 @@ public: }; ``` +#### Go + ```go func maxProfit(k int, prices []int) int { n := len(prices) @@ -352,6 +372,8 @@ func maxProfit(k int, prices []int) int { } ``` +#### TypeScript + ```ts function maxProfit(k: number, prices: number[]): number { const n = prices.length; @@ -371,6 +393,8 @@ function maxProfit(k: number, prices: number[]): number { } ``` +#### C# + ```cs public class Solution { public int MaxProfit(int k, int[] prices) { @@ -400,6 +424,8 @@ public class Solution { +#### Python3 + ```python class Solution: def maxProfit(self, k: int, prices: List[int]) -> int: @@ -413,6 +439,8 @@ class Solution: return f[k][0] ``` +#### Java + ```java class Solution { public int maxProfit(int k, int[] prices) { @@ -432,6 +460,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -453,6 +483,8 @@ public: }; ``` +#### Go + ```go func maxProfit(k int, prices []int) int { f := make([][2]int, k+1) @@ -469,6 +501,8 @@ func maxProfit(k int, prices []int) int { } ``` +#### TypeScript + ```ts function maxProfit(k: number, prices: number[]): number { const f = Array.from({ length: k + 1 }, () => Array.from({ length: 2 }, () => 0)); @@ -485,6 +519,8 @@ function maxProfit(k: number, prices: number[]): number { } ``` +#### C# + ```cs public class Solution { public int MaxProfit(int k, int[] prices) { diff --git a/solution/0100-0199/0188.Best Time to Buy and Sell Stock IV/README_EN.md b/solution/0100-0199/0188.Best Time to Buy and Sell Stock IV/README_EN.md index f4d4731cfbb0a..52265403773df 100644 --- a/solution/0100-0199/0188.Best Time to Buy and Sell Stock IV/README_EN.md +++ b/solution/0100-0199/0188.Best Time to Buy and Sell Stock IV/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(n \times k)$, and the space complexity is $O(n \times +#### Python3 + ```python class Solution: def maxProfit(self, k: int, prices: List[int]) -> int: @@ -91,6 +93,8 @@ class Solution: return dfs(0, k, 0) ``` +#### Java + ```java class Solution { private Integer[][][] f; @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func maxProfit(k int, prices []int) int { n := len(prices) @@ -180,6 +188,8 @@ func maxProfit(k int, prices []int) int { } ``` +#### TypeScript + ```ts function maxProfit(k: number, prices: number[]): number { const n = prices.length; @@ -205,6 +215,8 @@ function maxProfit(k: number, prices: number[]): number { } ``` +#### C# + ```cs public class Solution { private int[,,] f; @@ -277,6 +289,8 @@ We notice that the state $f[i][]$ only depends on the state $f[i - 1][]$, so we +#### Python3 + ```python class Solution: def maxProfit(self, k: int, prices: List[int]) -> int: @@ -291,6 +305,8 @@ class Solution: return f[n - 1][k][0] ``` +#### Java + ```java class Solution { public int maxProfit(int k, int[] prices) { @@ -310,6 +326,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -331,6 +349,8 @@ public: }; ``` +#### Go + ```go func maxProfit(k int, prices []int) int { n := len(prices) @@ -351,6 +371,8 @@ func maxProfit(k int, prices []int) int { } ``` +#### TypeScript + ```ts function maxProfit(k: number, prices: number[]): number { const n = prices.length; @@ -370,6 +392,8 @@ function maxProfit(k: number, prices: number[]): number { } ``` +#### C# + ```cs public class Solution { public int MaxProfit(int k, int[] prices) { @@ -399,6 +423,8 @@ public class Solution { +#### Python3 + ```python class Solution: def maxProfit(self, k: int, prices: List[int]) -> int: @@ -412,6 +438,8 @@ class Solution: return f[k][0] ``` +#### Java + ```java class Solution { public int maxProfit(int k, int[] prices) { @@ -431,6 +459,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -452,6 +482,8 @@ public: }; ``` +#### Go + ```go func maxProfit(k int, prices []int) int { f := make([][2]int, k+1) @@ -468,6 +500,8 @@ func maxProfit(k int, prices []int) int { } ``` +#### TypeScript + ```ts function maxProfit(k: number, prices: number[]): number { const f = Array.from({ length: k + 1 }, () => Array.from({ length: 2 }, () => 0)); @@ -484,6 +518,8 @@ function maxProfit(k: number, prices: number[]): number { } ``` +#### C# + ```cs public class Solution { public int MaxProfit(int k, int[] prices) { diff --git a/solution/0100-0199/0189.Rotate Array/README.md b/solution/0100-0199/0189.Rotate Array/README.md index c750525d5feb7..0a4691e77372a 100644 --- a/solution/0100-0199/0189.Rotate Array/README.md +++ b/solution/0100-0199/0189.Rotate Array/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def rotate(self, nums: List[int], k: int) -> None: @@ -102,6 +104,8 @@ class Solution: reverse(k, n - 1) ``` +#### Java + ```java class Solution { private int[] nums; @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func rotate(nums []int, k int) { n := len(nums) @@ -153,6 +161,8 @@ func rotate(nums []int, k int) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify nums in-place instead. @@ -173,6 +183,8 @@ function rotate(nums: number[], k: number): void { } ``` +#### Rust + ```rust impl Solution { pub fn rotate(nums: &mut Vec, k: i32) { @@ -185,6 +197,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -205,6 +219,8 @@ var rotate = function (nums, k) { }; ``` +#### C# + ```cs public class Solution { private int[] nums; @@ -238,6 +254,8 @@ public class Solution { +#### Python3 + ```python class Solution: def rotate(self, nums: List[int], k: int) -> None: diff --git a/solution/0100-0199/0189.Rotate Array/README_EN.md b/solution/0100-0199/0189.Rotate Array/README_EN.md index 2ddbd884eb727..0ef0680cd0580 100644 --- a/solution/0100-0199/0189.Rotate Array/README_EN.md +++ b/solution/0100-0199/0189.Rotate Array/README_EN.md @@ -85,6 +85,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def rotate(self, nums: List[int], k: int) -> None: @@ -100,6 +102,8 @@ class Solution: reverse(k, n - 1) ``` +#### Java + ```java class Solution { private int[] nums; @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func rotate(nums []int, k int) { n := len(nums) @@ -151,6 +159,8 @@ func rotate(nums []int, k int) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify nums in-place instead. @@ -171,6 +181,8 @@ function rotate(nums: number[], k: number): void { } ``` +#### Rust + ```rust impl Solution { pub fn rotate(nums: &mut Vec, k: i32) { @@ -183,6 +195,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -203,6 +217,8 @@ var rotate = function (nums, k) { }; ``` +#### C# + ```cs public class Solution { private int[] nums; @@ -236,6 +252,8 @@ public class Solution { +#### Python3 + ```python class Solution: def rotate(self, nums: List[int], k: int) -> None: diff --git a/solution/0100-0199/0190.Reverse Bits/README.md b/solution/0100-0199/0190.Reverse Bits/README.md index a8f6dda4eb951..e151edf982a68 100644 --- a/solution/0100-0199/0190.Reverse Bits/README.md +++ b/solution/0100-0199/0190.Reverse Bits/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def reverseBits(self, n: int) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java public class Solution { // you need treat n as an unsigned value @@ -96,6 +100,8 @@ public class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func reverseBits(n uint32) (ans uint32) { for i := 0; i < 32; i++ { @@ -120,6 +128,8 @@ func reverseBits(n uint32) (ans uint32) { } ``` +#### Rust + ```rust impl Solution { pub fn reverse_bits(mut n: u32) -> u32 { @@ -133,6 +143,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} n - a positive integer diff --git a/solution/0100-0199/0190.Reverse Bits/README_EN.md b/solution/0100-0199/0190.Reverse Bits/README_EN.md index c3d2422900ac0..c9cb6f63778a4 100644 --- a/solution/0100-0199/0190.Reverse Bits/README_EN.md +++ b/solution/0100-0199/0190.Reverse Bits/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(\log n)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def reverseBits(self, n: int) -> int: @@ -79,6 +81,8 @@ class Solution: return ans ``` +#### Java + ```java public class Solution { // you need treat n as an unsigned value @@ -93,6 +97,8 @@ public class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func reverseBits(n uint32) (ans uint32) { for i := 0; i < 32; i++ { @@ -117,6 +125,8 @@ func reverseBits(n uint32) (ans uint32) { } ``` +#### Rust + ```rust impl Solution { pub fn reverse_bits(mut n: u32) -> u32 { @@ -130,6 +140,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} n - a positive integer diff --git a/solution/0100-0199/0191.Number of 1 Bits/README.md b/solution/0100-0199/0191.Number of 1 Bits/README.md index 1ae6763809302..63318ed0affe2 100644 --- a/solution/0100-0199/0191.Number of 1 Bits/README.md +++ b/solution/0100-0199/0191.Number of 1 Bits/README.md @@ -96,6 +96,8 @@ HAMMING-WEIGHT(n) +#### Python3 + ```python class Solution: def hammingWeight(self, n: int) -> int: @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java public class Solution { // you need to treat n as an unsigned value @@ -120,6 +124,8 @@ public class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func hammingWeight(num uint32) int { ans := 0 @@ -145,6 +153,8 @@ func hammingWeight(num uint32) int { } ``` +#### TypeScript + ```ts function hammingWeight(n: number): number { let ans: number = 0; @@ -156,6 +166,8 @@ function hammingWeight(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn hammingWeight(n: u32) -> i32 { @@ -164,6 +176,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} n - a positive integer @@ -179,6 +193,8 @@ var hammingWeight = function (n) { }; ``` +#### C + ```c int hammingWeight(uint32_t n) { int ans = 0; @@ -204,6 +220,8 @@ int hammingWeight(uint32_t n) { +#### Python3 + ```python class Solution: def hammingWeight(self, n: int) -> int: @@ -214,6 +232,8 @@ class Solution: return ans ``` +#### Java + ```java public class Solution { // you need to treat n as an unsigned value @@ -228,6 +248,8 @@ public class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -242,6 +264,8 @@ public: }; ``` +#### Go + ```go func hammingWeight(num uint32) int { ans := 0 @@ -253,6 +277,8 @@ func hammingWeight(num uint32) int { } ``` +#### Rust + ```rust impl Solution { pub fn hammingWeight(mut n: u32) -> i32 { diff --git a/solution/0100-0199/0191.Number of 1 Bits/README_EN.md b/solution/0100-0199/0191.Number of 1 Bits/README_EN.md index 0aac9a7793ba7..72cc09656abc0 100644 --- a/solution/0100-0199/0191.Number of 1 Bits/README_EN.md +++ b/solution/0100-0199/0191.Number of 1 Bits/README_EN.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def hammingWeight(self, n: int) -> int: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java public class Solution { // you need to treat n as an unsigned value @@ -100,6 +104,8 @@ public class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func hammingWeight(num uint32) int { ans := 0 @@ -125,6 +133,8 @@ func hammingWeight(num uint32) int { } ``` +#### TypeScript + ```ts function hammingWeight(n: number): number { let ans: number = 0; @@ -136,6 +146,8 @@ function hammingWeight(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn hammingWeight(n: u32) -> i32 { @@ -144,6 +156,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} n - a positive integer @@ -159,6 +173,8 @@ var hammingWeight = function (n) { }; ``` +#### C + ```c int hammingWeight(uint32_t n) { int ans = 0; @@ -180,6 +196,8 @@ int hammingWeight(uint32_t n) { +#### Python3 + ```python class Solution: def hammingWeight(self, n: int) -> int: @@ -190,6 +208,8 @@ class Solution: return ans ``` +#### Java + ```java public class Solution { // you need to treat n as an unsigned value @@ -204,6 +224,8 @@ public class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -218,6 +240,8 @@ public: }; ``` +#### Go + ```go func hammingWeight(num uint32) int { ans := 0 @@ -229,6 +253,8 @@ func hammingWeight(num uint32) int { } ``` +#### Rust + ```rust impl Solution { pub fn hammingWeight(mut n: u32) -> i32 { diff --git a/solution/0100-0199/0192.Word Frequency/README.md b/solution/0100-0199/0192.Word Frequency/README.md index 4534beb066582..b73e14dcc749b 100644 --- a/solution/0100-0199/0192.Word Frequency/README.md +++ b/solution/0100-0199/0192.Word Frequency/README.md @@ -61,6 +61,8 @@ day 1 +#### Shell + ```bash # Read from the file words.txt and output the word frequency list to stdout. cat words.txt | tr -s ' ' '\n' | sort | uniq -c | sort -nr | awk '{print $2, $1}' diff --git a/solution/0100-0199/0192.Word Frequency/README_EN.md b/solution/0100-0199/0192.Word Frequency/README_EN.md index db68b41452208..946fd458d48c3 100644 --- a/solution/0100-0199/0192.Word Frequency/README_EN.md +++ b/solution/0100-0199/0192.Word Frequency/README_EN.md @@ -61,6 +61,8 @@ day 1 +#### Shell + ```bash # Read from the file words.txt and output the word frequency list to stdout. cat words.txt | tr -s ' ' '\n' | sort | uniq -c | sort -nr | awk '{print $2, $1}' diff --git a/solution/0100-0199/0193.Valid Phone Numbers/README.md b/solution/0100-0199/0193.Valid Phone Numbers/README.md index 6272d8150cdaf..819f8d240f5e1 100644 --- a/solution/0100-0199/0193.Valid Phone Numbers/README.md +++ b/solution/0100-0199/0193.Valid Phone Numbers/README.md @@ -51,6 +51,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/0100-0199/0193.Va +#### Shell + ```bash # Read from the file file.txt and output all valid phone numbers to stdout. awk '/^([0-9]{3}-|\([0-9]{3}\) )[0-9]{3}-[0-9]{4}$/' file.txt diff --git a/solution/0100-0199/0193.Valid Phone Numbers/README_EN.md b/solution/0100-0199/0193.Valid Phone Numbers/README_EN.md index bea8cf4f9e5d0..2ab5c57af97eb 100644 --- a/solution/0100-0199/0193.Valid Phone Numbers/README_EN.md +++ b/solution/0100-0199/0193.Valid Phone Numbers/README_EN.md @@ -49,6 +49,8 @@ tags: +#### Shell + ```bash # Read from the file file.txt and output all valid phone numbers to stdout. awk '/^([0-9]{3}-|\([0-9]{3}\) )[0-9]{3}-[0-9]{4}$/' file.txt diff --git a/solution/0100-0199/0194.Transpose File/README.md b/solution/0100-0199/0194.Transpose File/README.md index d48562b98654c..90293ccffbeb2 100644 --- a/solution/0100-0199/0194.Transpose File/README.md +++ b/solution/0100-0199/0194.Transpose File/README.md @@ -49,6 +49,8 @@ age 21 30 +#### Shell + ```bash # Read from the file file.txt and print its transposed content to stdout. awk ' diff --git a/solution/0100-0199/0194.Transpose File/README_EN.md b/solution/0100-0199/0194.Transpose File/README_EN.md index ae99d6223be1d..77a647c0486ed 100644 --- a/solution/0100-0199/0194.Transpose File/README_EN.md +++ b/solution/0100-0199/0194.Transpose File/README_EN.md @@ -47,6 +47,8 @@ age 21 30 +#### Shell + ```bash # Read from the file file.txt and print its transposed content to stdout. awk ' diff --git a/solution/0100-0199/0195.Tenth Line/README.md b/solution/0100-0199/0195.Tenth Line/README.md index a8d77db95ca5f..54d3accff9727 100644 --- a/solution/0100-0199/0195.Tenth Line/README.md +++ b/solution/0100-0199/0195.Tenth Line/README.md @@ -53,6 +53,8 @@ Line 10 +#### Shell + ```bash # Read from the file file.txt and output the tenth line to stdout. sed -n 10p file.txt diff --git a/solution/0100-0199/0195.Tenth Line/README_EN.md b/solution/0100-0199/0195.Tenth Line/README_EN.md index 5d85571d6d3c7..69bdfb2395242 100644 --- a/solution/0100-0199/0195.Tenth Line/README_EN.md +++ b/solution/0100-0199/0195.Tenth Line/README_EN.md @@ -70,6 +70,8 @@ Line 10 +#### Shell + ```bash # Read from the file file.txt and output the tenth line to stdout. sed -n 10p file.txt diff --git a/solution/0100-0199/0196.Delete Duplicate Emails/README.md b/solution/0100-0199/0196.Delete Duplicate Emails/README.md index c90513ac1ff3e..50358dc0c67c0 100644 --- a/solution/0100-0199/0196.Delete Duplicate Emails/README.md +++ b/solution/0100-0199/0196.Delete Duplicate Emails/README.md @@ -74,6 +74,8 @@ Person 表: +#### Python3 + ```python import pandas as pd @@ -86,6 +88,8 @@ def delete_duplicate_emails(person: pd.DataFrame) -> None: person.drop_duplicates(subset="email", keep="first", inplace=True) ``` +#### MySQL + ```sql # Write your MySQL query statement below DELETE FROM Person @@ -102,6 +106,8 @@ WHERE id NOT IN (SELECT MIN(id) FROM (SELECT * FROM Person) AS p GROUP BY email) +#### MySQL + ```sql # Write your MySQL query statement below DELETE FROM Person @@ -132,6 +138,8 @@ WHERE +#### MySQL + ```sql DELETE p2 FROM diff --git a/solution/0100-0199/0196.Delete Duplicate Emails/README_EN.md b/solution/0100-0199/0196.Delete Duplicate Emails/README_EN.md index 960245ea41d3f..0de68a515520e 100644 --- a/solution/0100-0199/0196.Delete Duplicate Emails/README_EN.md +++ b/solution/0100-0199/0196.Delete Duplicate Emails/README_EN.md @@ -74,6 +74,8 @@ Person table: +#### Python3 + ```python import pandas as pd @@ -86,6 +88,8 @@ def delete_duplicate_emails(person: pd.DataFrame) -> None: person.drop_duplicates(subset="email", keep="first", inplace=True) ``` +#### MySQL + ```sql # Write your MySQL query statement below DELETE FROM Person @@ -102,6 +106,8 @@ WHERE id NOT IN (SELECT MIN(id) FROM (SELECT * FROM Person) AS p GROUP BY email) +#### MySQL + ```sql # Write your MySQL query statement below DELETE FROM Person @@ -132,6 +138,8 @@ WHERE +#### MySQL + ```sql DELETE p2 FROM diff --git a/solution/0100-0199/0197.Rising Temperature/README.md b/solution/0100-0199/0197.Rising Temperature/README.md index 2f7d4fca962e4..a308430bdad8d 100644 --- a/solution/0100-0199/0197.Rising Temperature/README.md +++ b/solution/0100-0199/0197.Rising Temperature/README.md @@ -80,6 +80,8 @@ Weather 表: +#### Python3 + ```python import pandas as pd @@ -91,6 +93,8 @@ def rising_temperature(weather: pd.DataFrame) -> pd.DataFrame: ][["id"]] ``` +#### MySQL + ```sql # Write your MySQL query statement below SELECT w1.id @@ -110,6 +114,8 @@ FROM +#### MySQL + ```sql # Write your MySQL query statement below SELECT w1.id diff --git a/solution/0100-0199/0197.Rising Temperature/README_EN.md b/solution/0100-0199/0197.Rising Temperature/README_EN.md index a7efeb26954a2..5902232ce59ae 100644 --- a/solution/0100-0199/0197.Rising Temperature/README_EN.md +++ b/solution/0100-0199/0197.Rising Temperature/README_EN.md @@ -77,6 +77,8 @@ We can use self-join to compare each row in the `Weather` table with its previou +#### Python3 + ```python import pandas as pd @@ -88,6 +90,8 @@ def rising_temperature(weather: pd.DataFrame) -> pd.DataFrame: ][["id"]] ``` +#### MySQL + ```sql # Write your MySQL query statement below SELECT w1.id @@ -107,6 +111,8 @@ FROM +#### MySQL + ```sql # Write your MySQL query statement below SELECT w1.id diff --git a/solution/0100-0199/0198.House Robber/README.md b/solution/0100-0199/0198.House Robber/README.md index cd8a83838e1fd..4d73fb4757472 100644 --- a/solution/0100-0199/0198.House Robber/README.md +++ b/solution/0100-0199/0198.House Robber/README.md @@ -83,6 +83,8 @@ $$ +#### Python3 + ```python class Solution: def rob(self, nums: List[int]) -> int: @@ -94,6 +96,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int rob(int[] nums) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func rob(nums []int) int { n := len(nums) @@ -136,6 +144,8 @@ func rob(nums []int) int { } ``` +#### TypeScript + ```ts function rob(nums: number[]): number { const n = nums.length; @@ -148,6 +158,8 @@ function rob(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn rob(nums: Vec) -> i32 { @@ -170,6 +182,8 @@ impl Solution { +#### Python3 + ```python class Solution: def rob(self, nums: List[int]) -> int: @@ -179,6 +193,8 @@ class Solution: return max(f, g) ``` +#### Java + ```java class Solution { public int rob(int[] nums) { @@ -193,6 +209,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -208,6 +226,8 @@ public: }; ``` +#### Go + ```go func rob(nums []int) int { f, g := 0, 0 @@ -218,6 +238,8 @@ func rob(nums []int) int { } ``` +#### TypeScript + ```ts function rob(nums: number[]): number { let [f, g] = [0, 0]; diff --git a/solution/0100-0199/0198.House Robber/README_EN.md b/solution/0100-0199/0198.House Robber/README_EN.md index f024e589af708..25eb527115e3c 100644 --- a/solution/0100-0199/0198.House Robber/README_EN.md +++ b/solution/0100-0199/0198.House Robber/README_EN.md @@ -58,6 +58,8 @@ Total amount you can rob = 2 + 9 + 1 = 12. +#### Python3 + ```python class Solution: def rob(self, nums: List[int]) -> int: @@ -69,6 +71,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int rob(int[] nums) { @@ -83,6 +87,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -99,6 +105,8 @@ public: }; ``` +#### Go + ```go func rob(nums []int) int { n := len(nums) @@ -111,6 +119,8 @@ func rob(nums []int) int { } ``` +#### TypeScript + ```ts function rob(nums: number[]): number { const n = nums.length; @@ -123,6 +133,8 @@ function rob(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn rob(nums: Vec) -> i32 { @@ -145,6 +157,8 @@ impl Solution { +#### Python3 + ```python class Solution: def rob(self, nums: List[int]) -> int: @@ -154,6 +168,8 @@ class Solution: return max(f, g) ``` +#### Java + ```java class Solution { public int rob(int[] nums) { @@ -168,6 +184,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -183,6 +201,8 @@ public: }; ``` +#### Go + ```go func rob(nums []int) int { f, g := 0, 0 @@ -193,6 +213,8 @@ func rob(nums []int) int { } ``` +#### TypeScript + ```ts function rob(nums: number[]): number { let [f, g] = [0, 0]; diff --git a/solution/0100-0199/0199.Binary Tree Right Side View/README.md b/solution/0100-0199/0199.Binary Tree Right Side View/README.md index 4ee393b1b479f..34da011565c23 100644 --- a/solution/0100-0199/0199.Binary Tree Right Side View/README.md +++ b/solution/0100-0199/0199.Binary Tree Right Side View/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -203,6 +211,8 @@ func rightSideView(root *TreeNode) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -241,6 +251,8 @@ function rightSideView(root: TreeNode | null): number[] { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -305,6 +317,8 @@ impl Solution { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -327,6 +341,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -364,6 +380,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -396,6 +414,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -422,6 +442,8 @@ func rightSideView(root *TreeNode) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0100-0199/0199.Binary Tree Right Side View/README_EN.md b/solution/0100-0199/0199.Binary Tree Right Side View/README_EN.md index 38f70da2855dc..3b89f57b7b8ce 100644 --- a/solution/0100-0199/0199.Binary Tree Right Side View/README_EN.md +++ b/solution/0100-0199/0199.Binary Tree Right Side View/README_EN.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -195,6 +203,8 @@ func rightSideView(root *TreeNode) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -233,6 +243,8 @@ function rightSideView(root: TreeNode | null): number[] { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -293,6 +305,8 @@ impl Solution { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -315,6 +329,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -352,6 +368,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -384,6 +402,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -410,6 +430,8 @@ func rightSideView(root *TreeNode) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0200-0299/0200.Number of Islands/README.md b/solution/0200-0299/0200.Number of Islands/README.md index 9cc634b3bce79..634d42f1eb971 100644 --- a/solution/0200-0299/0200.Number of Islands/README.md +++ b/solution/0200-0299/0200.Number of Islands/README.md @@ -79,6 +79,8 @@ Flood fill 算法是从一个区域中提取若干个连通的点与其他相邻 +#### Python3 + ```python class Solution: def numIslands(self, grid: List[List[str]]) -> int: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private char[][] grid; @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go func numIslands(grid [][]byte) int { m, n := len(grid), len(grid[0]) @@ -193,6 +201,8 @@ func numIslands(grid [][]byte) int { } ``` +#### TypeScript + ```ts function numIslands(grid: string[][]): number { const m = grid.length; @@ -221,6 +231,8 @@ function numIslands(grid: string[][]): number { } ``` +#### Rust + ```rust const DIRS: [i32; 5] = [-1, 0, 1, 0, -1]; @@ -258,6 +270,8 @@ impl Solution { } ``` +#### C# + ```cs using System; using System.Collections.Generic; @@ -348,6 +362,8 @@ def union(a, b): +#### Python3 + ```python class Solution: def numIslands(self, grid: List[List[str]]) -> int: @@ -373,6 +389,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private char[][] grid; @@ -415,6 +433,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -454,6 +474,8 @@ public: }; ``` +#### Go + ```go func numIslands(grid [][]byte) int { m, n := len(grid), len(grid[0]) @@ -486,6 +508,8 @@ func numIslands(grid [][]byte) int { } ``` +#### TypeScript + ```ts function numIslands(grid: string[][]): number { const m = grid.length; @@ -519,6 +543,8 @@ function numIslands(grid: string[][]): number { } ``` +#### Rust + ```rust use std::collections::VecDeque; @@ -573,6 +599,8 @@ impl Solution { +#### Python3 + ```python class Solution: def numIslands(self, grid: List[List[str]]) -> int: @@ -598,6 +626,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { private int[] p; @@ -643,6 +673,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -682,6 +714,8 @@ public: }; ``` +#### Go + ```go func numIslands(grid [][]byte) int { m, n := len(grid), len(grid[0]) @@ -721,6 +755,8 @@ func numIslands(grid [][]byte) int { } ``` +#### TypeScript + ```ts function numIslands(grid: string[][]): number { const m = grid.length; @@ -761,6 +797,8 @@ function numIslands(grid: string[][]): number { } ``` +#### Rust + ```rust const DIRS: [usize; 3] = [1, 0, 1]; diff --git a/solution/0200-0299/0200.Number of Islands/README_EN.md b/solution/0200-0299/0200.Number of Islands/README_EN.md index 7adb1a849d6d0..e2efa41f09937 100644 --- a/solution/0200-0299/0200.Number of Islands/README_EN.md +++ b/solution/0200-0299/0200.Number of Islands/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def numIslands(self, grid: List[List[str]]) -> int: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private char[][] grid; @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func numIslands(grid [][]byte) int { m, n := len(grid), len(grid[0]) @@ -183,6 +191,8 @@ func numIslands(grid [][]byte) int { } ``` +#### TypeScript + ```ts function numIslands(grid: string[][]): number { const m = grid.length; @@ -211,6 +221,8 @@ function numIslands(grid: string[][]): number { } ``` +#### Rust + ```rust const DIRS: [i32; 5] = [-1, 0, 1, 0, -1]; @@ -248,6 +260,8 @@ impl Solution { } ``` +#### C# + ```cs using System; using System.Collections.Generic; @@ -301,6 +315,8 @@ public class Solution { +#### Python3 + ```python class Solution: def numIslands(self, grid: List[List[str]]) -> int: @@ -326,6 +342,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private char[][] grid; @@ -368,6 +386,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -407,6 +427,8 @@ public: }; ``` +#### Go + ```go func numIslands(grid [][]byte) int { m, n := len(grid), len(grid[0]) @@ -439,6 +461,8 @@ func numIslands(grid [][]byte) int { } ``` +#### TypeScript + ```ts function numIslands(grid: string[][]): number { const m = grid.length; @@ -472,6 +496,8 @@ function numIslands(grid: string[][]): number { } ``` +#### Rust + ```rust use std::collections::VecDeque; @@ -526,6 +552,8 @@ impl Solution { +#### Python3 + ```python class Solution: def numIslands(self, grid: List[List[str]]) -> int: @@ -551,6 +579,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { private int[] p; @@ -596,6 +626,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -635,6 +667,8 @@ public: }; ``` +#### Go + ```go func numIslands(grid [][]byte) int { m, n := len(grid), len(grid[0]) @@ -674,6 +708,8 @@ func numIslands(grid [][]byte) int { } ``` +#### TypeScript + ```ts function numIslands(grid: string[][]): number { const m = grid.length; @@ -714,6 +750,8 @@ function numIslands(grid: string[][]): number { } ``` +#### Rust + ```rust const DIRS: [usize; 3] = [1, 0, 1]; diff --git a/solution/0200-0299/0201.Bitwise AND of Numbers Range/README.md b/solution/0200-0299/0201.Bitwise AND of Numbers Range/README.md index 06810c44e1c40..e66b0da9b8c22 100644 --- a/solution/0200-0299/0201.Bitwise AND of Numbers Range/README.md +++ b/solution/0200-0299/0201.Bitwise AND of Numbers Range/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def rangeBitwiseAnd(self, left: int, right: int) -> int: @@ -73,6 +75,8 @@ class Solution: return right ``` +#### Java + ```java class Solution { public int rangeBitwiseAnd(int left, int right) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -96,6 +102,8 @@ public: }; ``` +#### Go + ```go func rangeBitwiseAnd(left int, right int) int { for left < right { @@ -105,6 +113,8 @@ func rangeBitwiseAnd(left int, right int) int { } ``` +#### JavaScript + ```js /** * @param {number} left @@ -119,6 +129,8 @@ var rangeBitwiseAnd = function (left, right) { }; ``` +#### C# + ```cs public class Solution { public int RangeBitwiseAnd(int left, int right) { diff --git a/solution/0200-0299/0201.Bitwise AND of Numbers Range/README_EN.md b/solution/0200-0299/0201.Bitwise AND of Numbers Range/README_EN.md index 79fa53deca2a3..a6bf3eac1713b 100644 --- a/solution/0200-0299/0201.Bitwise AND of Numbers Range/README_EN.md +++ b/solution/0200-0299/0201.Bitwise AND of Numbers Range/README_EN.md @@ -57,6 +57,8 @@ tags: +#### Python3 + ```python class Solution: def rangeBitwiseAnd(self, left: int, right: int) -> int: @@ -65,6 +67,8 @@ class Solution: return right ``` +#### Java + ```java class Solution { public int rangeBitwiseAnd(int left, int right) { @@ -76,6 +80,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -88,6 +94,8 @@ public: }; ``` +#### Go + ```go func rangeBitwiseAnd(left int, right int) int { for left < right { @@ -97,6 +105,8 @@ func rangeBitwiseAnd(left int, right int) int { } ``` +#### JavaScript + ```js /** * @param {number} left @@ -111,6 +121,8 @@ var rangeBitwiseAnd = function (left, right) { }; ``` +#### C# + ```cs public class Solution { public int RangeBitwiseAnd(int left, int right) { diff --git a/solution/0200-0299/0202.Happy Number/README.md b/solution/0200-0299/0202.Happy Number/README.md index b115e2146290c..933bee431158e 100644 --- a/solution/0200-0299/0202.Happy Number/README.md +++ b/solution/0200-0299/0202.Happy Number/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def isHappy(self, n: int) -> bool: @@ -87,6 +89,8 @@ class Solution: return n == 1 ``` +#### Java + ```java class Solution { public boolean isHappy(int n) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func isHappy(n int) bool { vis := map[int]bool{} @@ -138,6 +146,8 @@ func isHappy(n int) bool { } ``` +#### TypeScript + ```ts function isHappy(n: number): boolean { const getNext = (n: number) => { @@ -161,6 +171,8 @@ function isHappy(n: number): boolean { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -188,6 +200,8 @@ impl Solution { } ``` +#### C + ```c int getNext(int n) { int res = 0; @@ -225,6 +239,8 @@ bool isHappy(int n) { +#### Python3 + ```python class Solution: def isHappy(self, n: int) -> bool: @@ -241,6 +257,8 @@ class Solution: return slow == 1 ``` +#### Java + ```java class Solution { public boolean isHappy(int n) { @@ -262,6 +280,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -283,6 +303,8 @@ public: }; ``` +#### Go + ```go func isHappy(n int) bool { next := func(x int) (y int) { @@ -300,6 +322,8 @@ func isHappy(n int) bool { } ``` +#### TypeScript + ```ts function isHappy(n: number): boolean { const getNext = (n: number) => { @@ -321,6 +345,8 @@ function isHappy(n: number): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn is_happy(n: i32) -> bool { diff --git a/solution/0200-0299/0202.Happy Number/README_EN.md b/solution/0200-0299/0202.Happy Number/README_EN.md index c9b90f38db3a5..d80d4e508fe3a 100644 --- a/solution/0200-0299/0202.Happy Number/README_EN.md +++ b/solution/0200-0299/0202.Happy Number/README_EN.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def isHappy(self, n: int) -> bool: @@ -81,6 +83,8 @@ class Solution: return n == 1 ``` +#### Java + ```java class Solution { public boolean isHappy(int n) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func isHappy(n int) bool { vis := map[int]bool{} @@ -132,6 +140,8 @@ func isHappy(n int) bool { } ``` +#### TypeScript + ```ts function isHappy(n: number): boolean { const getNext = (n: number) => { @@ -155,6 +165,8 @@ function isHappy(n: number): boolean { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -182,6 +194,8 @@ impl Solution { } ``` +#### C + ```c int getNext(int n) { int res = 0; @@ -213,6 +227,8 @@ bool isHappy(int n) { +#### Python3 + ```python class Solution: def isHappy(self, n: int) -> bool: @@ -229,6 +245,8 @@ class Solution: return slow == 1 ``` +#### Java + ```java class Solution { public boolean isHappy(int n) { @@ -250,6 +268,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -271,6 +291,8 @@ public: }; ``` +#### Go + ```go func isHappy(n int) bool { next := func(x int) (y int) { @@ -288,6 +310,8 @@ func isHappy(n int) bool { } ``` +#### TypeScript + ```ts function isHappy(n: number): boolean { const getNext = (n: number) => { @@ -309,6 +333,8 @@ function isHappy(n: number): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn is_happy(n: i32) -> bool { diff --git a/solution/0200-0299/0203.Remove Linked List Elements/README.md b/solution/0200-0299/0203.Remove Linked List Elements/README.md index 361b9bcae183b..d9eb8dc18ec33 100644 --- a/solution/0200-0299/0203.Remove Linked List Elements/README.md +++ b/solution/0200-0299/0203.Remove Linked List Elements/README.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -80,6 +82,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func removeElements(head *ListNode, val int) *ListNode { dummy := new(ListNode) @@ -141,6 +149,8 @@ func removeElements(head *ListNode, val int) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -168,6 +178,8 @@ function removeElements(head: ListNode | null, val: number): ListNode | null { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -202,6 +214,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public ListNode RemoveElements(ListNode head, int val) { diff --git a/solution/0200-0299/0203.Remove Linked List Elements/README_EN.md b/solution/0200-0299/0203.Remove Linked List Elements/README_EN.md index f63fbebdd314e..1874bca6a18be 100644 --- a/solution/0200-0299/0203.Remove Linked List Elements/README_EN.md +++ b/solution/0200-0299/0203.Remove Linked List Elements/README_EN.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -78,6 +80,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func removeElements(head *ListNode, val int) *ListNode { dummy := new(ListNode) @@ -139,6 +147,8 @@ func removeElements(head *ListNode, val int) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -166,6 +176,8 @@ function removeElements(head: ListNode | null, val: number): ListNode | null { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -200,6 +212,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public ListNode RemoveElements(ListNode head, int val) { diff --git a/solution/0200-0299/0204.Count Primes/README.md b/solution/0200-0299/0204.Count Primes/README.md index 928f1f95d3535..3fcd5211a28ef 100644 --- a/solution/0200-0299/0204.Count Primes/README.md +++ b/solution/0200-0299/0204.Count Primes/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def countPrimes(self, n: int) -> int: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countPrimes(int n) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func countPrimes(n int) int { primes := make([]bool, n) @@ -139,6 +147,8 @@ func countPrimes(n int) int { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -159,6 +169,8 @@ var countPrimes = function (n) { }; ``` +#### C# + ```cs public class Solution { public int CountPrimes(int n) { diff --git a/solution/0200-0299/0204.Count Primes/README_EN.md b/solution/0200-0299/0204.Count Primes/README_EN.md index 3fb5c1f403184..aa2dac96308b0 100644 --- a/solution/0200-0299/0204.Count Primes/README_EN.md +++ b/solution/0200-0299/0204.Count Primes/README_EN.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def countPrimes(self, n: int) -> int: @@ -74,6 +76,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countPrimes(int n) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func countPrimes(n int) int { primes := make([]bool, n) @@ -129,6 +137,8 @@ func countPrimes(n int) int { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -149,6 +159,8 @@ var countPrimes = function (n) { }; ``` +#### C# + ```cs public class Solution { public int CountPrimes(int n) { diff --git a/solution/0200-0299/0205.Isomorphic Strings/README.md b/solution/0200-0299/0205.Isomorphic Strings/README.md index aa0828225c9f0..048017ac98bd0 100644 --- a/solution/0200-0299/0205.Isomorphic Strings/README.md +++ b/solution/0200-0299/0205.Isomorphic Strings/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def isIsomorphic(self, s: str, t: str) -> bool: @@ -85,6 +87,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isIsomorphic(String s, String t) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func isIsomorphic(s string, t string) bool { d1 := [256]int{} @@ -141,6 +149,8 @@ func isIsomorphic(s string, t string) bool { } ``` +#### TypeScript + ```ts function isIsomorphic(s: string, t: string): boolean { const d1: number[] = new Array(256).fill(0); @@ -158,6 +168,8 @@ function isIsomorphic(s: string, t: string): boolean { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { @@ -182,6 +194,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public bool IsIsomorphic(string s, string t) { @@ -211,6 +225,8 @@ public class Solution { +#### Python3 + ```python class Solution: def isIsomorphic(self, s: str, t: str) -> bool: @@ -223,6 +239,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isIsomorphic(String s, String t) { diff --git a/solution/0200-0299/0205.Isomorphic Strings/README_EN.md b/solution/0200-0299/0205.Isomorphic Strings/README_EN.md index 9a919977ae03f..0b05304ac08f9 100644 --- a/solution/0200-0299/0205.Isomorphic Strings/README_EN.md +++ b/solution/0200-0299/0205.Isomorphic Strings/README_EN.md @@ -59,6 +59,8 @@ The time complexity is $O(n)$ and the space complexity is $O(C)$. Where $n$ is t +#### Python3 + ```python class Solution: def isIsomorphic(self, s: str, t: str) -> bool: @@ -72,6 +74,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isIsomorphic(String s, String t) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func isIsomorphic(s string, t string) bool { d1 := [256]int{} @@ -128,6 +136,8 @@ func isIsomorphic(s string, t string) bool { } ``` +#### TypeScript + ```ts function isIsomorphic(s: string, t: string): boolean { const d1: number[] = new Array(256).fill(0); @@ -145,6 +155,8 @@ function isIsomorphic(s: string, t: string): boolean { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { @@ -169,6 +181,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public bool IsIsomorphic(string s, string t) { @@ -198,6 +212,8 @@ public class Solution { +#### Python3 + ```python class Solution: def isIsomorphic(self, s: str, t: str) -> bool: @@ -210,6 +226,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isIsomorphic(String s, String t) { diff --git a/solution/0200-0299/0206.Reverse Linked List/README.md b/solution/0200-0299/0206.Reverse Linked List/README.md index 9993eddfedd0f..13c9e67956f8a 100644 --- a/solution/0200-0299/0206.Reverse Linked List/README.md +++ b/solution/0200-0299/0206.Reverse Linked List/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -91,6 +93,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -165,6 +173,8 @@ func reverseList(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -193,6 +203,8 @@ function reverseList(head: ListNode | null): ListNode | null { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -224,6 +236,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -249,6 +263,8 @@ var reverseList = function (head) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. @@ -290,6 +306,8 @@ public class Solution { +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -306,6 +324,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -330,6 +350,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -353,6 +375,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -372,6 +396,8 @@ func reverseList(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -403,6 +429,8 @@ function reverseList(head: ListNode | null): ListNode | null { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] diff --git a/solution/0200-0299/0206.Reverse Linked List/README_EN.md b/solution/0200-0299/0206.Reverse Linked List/README_EN.md index b82ccb9b3f62a..6ef93b442d5a7 100644 --- a/solution/0200-0299/0206.Reverse Linked List/README_EN.md +++ b/solution/0200-0299/0206.Reverse Linked List/README_EN.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -80,6 +82,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -154,6 +162,8 @@ func reverseList(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -182,6 +192,8 @@ function reverseList(head: ListNode | null): ListNode | null { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -213,6 +225,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -238,6 +252,8 @@ var reverseList = function (head) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. @@ -275,6 +291,8 @@ public class Solution { +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -291,6 +309,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -315,6 +335,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -338,6 +360,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -357,6 +381,8 @@ func reverseList(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -388,6 +414,8 @@ function reverseList(head: ListNode | null): ListNode | null { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] diff --git a/solution/0200-0299/0207.Course Schedule/README.md b/solution/0200-0299/0207.Course Schedule/README.md index df22b38a676a9..109baf1ef298c 100644 --- a/solution/0200-0299/0207.Course Schedule/README.md +++ b/solution/0200-0299/0207.Course Schedule/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool: @@ -95,6 +97,8 @@ class Solution: return cnt == numCourses ``` +#### Java + ```java class Solution { public boolean canFinish(int numCourses, int[][] prerequisites) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func canFinish(numCourses int, prerequisites [][]int) bool { g := make([][]int, numCourses) @@ -191,6 +199,8 @@ func canFinish(numCourses int, prerequisites [][]int) bool { } ``` +#### TypeScript + ```ts function canFinish(numCourses: number, prerequisites: number[][]): boolean { const g: number[][] = new Array(numCourses).fill(0).map(() => []); @@ -219,6 +229,8 @@ function canFinish(numCourses: number, prerequisites: number[][]): boolean { } ``` +#### Rust + ```rust use std::collections::VecDeque; @@ -269,6 +281,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public bool CanFinish(int numCourses, int[][] prerequisites) { diff --git a/solution/0200-0299/0207.Course Schedule/README_EN.md b/solution/0200-0299/0207.Course Schedule/README_EN.md index accfcf8fc2722..174efc4c382b6 100644 --- a/solution/0200-0299/0207.Course Schedule/README_EN.md +++ b/solution/0200-0299/0207.Course Schedule/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(n + m)$, and the space complexity is $O(n + m)$. Here, +#### Python3 + ```python class Solution: def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool: @@ -95,6 +97,8 @@ class Solution: return cnt == numCourses ``` +#### Java + ```java class Solution { public boolean canFinish(int numCourses, int[][] prerequisites) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func canFinish(numCourses int, prerequisites [][]int) bool { g := make([][]int, numCourses) @@ -191,6 +199,8 @@ func canFinish(numCourses int, prerequisites [][]int) bool { } ``` +#### TypeScript + ```ts function canFinish(numCourses: number, prerequisites: number[][]): boolean { const g: number[][] = new Array(numCourses).fill(0).map(() => []); @@ -219,6 +229,8 @@ function canFinish(numCourses: number, prerequisites: number[][]): boolean { } ``` +#### Rust + ```rust use std::collections::VecDeque; @@ -269,6 +281,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public bool CanFinish(int numCourses, int[][] prerequisites) { diff --git a/solution/0200-0299/0208.Implement Trie (Prefix Tree)/README.md b/solution/0200-0299/0208.Implement Trie (Prefix Tree)/README.md index 79398fe96610d..5f6842ce356b7 100644 --- a/solution/0200-0299/0208.Implement Trie (Prefix Tree)/README.md +++ b/solution/0200-0299/0208.Implement Trie (Prefix Tree)/README.md @@ -96,6 +96,8 @@ trie.search("app"); // 返回 True +#### Python3 + ```python class Trie: def __init__(self): @@ -136,6 +138,8 @@ class Trie: # param_3 = obj.startsWith(prefix) ``` +#### Java + ```java class Trie { private Trie[] children; @@ -189,6 +193,8 @@ class Trie { */ ``` +#### C++ + ```cpp class Trie { private: @@ -240,6 +246,8 @@ public: */ ``` +#### Go + ```go type Trie struct { children [26]*Trie @@ -293,6 +301,8 @@ func (this *Trie) SearchPrefix(s string) *Trie { */ ``` +#### TypeScript + ```ts class TrieNode { children; @@ -342,6 +352,8 @@ class Trie { } ``` +#### Rust + ```rust use std::{ rc::Rc, cell::RefCell, collections::HashMap }; @@ -436,6 +448,8 @@ impl Trie { } ``` +#### JavaScript + ```js /** * Initialize your data structure here. @@ -497,6 +511,8 @@ Trie.prototype.startsWith = function (prefix) { */ ``` +#### C# + ```cs public class Trie { bool isEnd; diff --git a/solution/0200-0299/0208.Implement Trie (Prefix Tree)/README_EN.md b/solution/0200-0299/0208.Implement Trie (Prefix Tree)/README_EN.md index dcb96eca18e9a..769b54431e8cb 100644 --- a/solution/0200-0299/0208.Implement Trie (Prefix Tree)/README_EN.md +++ b/solution/0200-0299/0208.Implement Trie (Prefix Tree)/README_EN.md @@ -69,6 +69,8 @@ trie.search("app"); // return True +#### Python3 + ```python class Trie: def __init__(self): @@ -109,6 +111,8 @@ class Trie: # param_3 = obj.startsWith(prefix) ``` +#### Java + ```java class Trie { private Trie[] children; @@ -162,6 +166,8 @@ class Trie { */ ``` +#### C++ + ```cpp class Trie { private: @@ -213,6 +219,8 @@ public: */ ``` +#### Go + ```go type Trie struct { children [26]*Trie @@ -266,6 +274,8 @@ func (this *Trie) SearchPrefix(s string) *Trie { */ ``` +#### TypeScript + ```ts class TrieNode { children; @@ -315,6 +325,8 @@ class Trie { } ``` +#### Rust + ```rust use std::{ rc::Rc, cell::RefCell, collections::HashMap }; @@ -409,6 +421,8 @@ impl Trie { } ``` +#### JavaScript + ```js /** * Initialize your data structure here. @@ -470,6 +484,8 @@ Trie.prototype.startsWith = function (prefix) { */ ``` +#### C# + ```cs public class Trie { bool isEnd; diff --git a/solution/0200-0299/0209.Minimum Size Subarray Sum/README.md b/solution/0200-0299/0209.Minimum Size Subarray Sum/README.md index da2952d371eba..9d0a0172b005d 100644 --- a/solution/0200-0299/0209.Minimum Size Subarray Sum/README.md +++ b/solution/0200-0299/0209.Minimum Size Subarray Sum/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def minSubArrayLen(self, target: int, nums: List[int]) -> int: @@ -96,6 +98,8 @@ class Solution: return ans if ans <= n else 0 ``` +#### Java + ```java class Solution { public int minSubArrayLen(int target, int[] nums) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func minSubArrayLen(target int, nums []int) int { n := len(nums) @@ -171,6 +179,8 @@ func minSubArrayLen(target int, nums []int) int { } ``` +#### TypeScript + ```ts function minSubArrayLen(target: number, nums: number[]): number { const n = nums.length; @@ -202,6 +212,8 @@ function minSubArrayLen(target: number, nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_sub_array_len(target: i32, nums: Vec) -> i32 { @@ -226,6 +238,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int MinSubArrayLen(int target, int[] nums) { @@ -262,6 +276,8 @@ public class Solution { +#### Python3 + ```python class Solution: def minSubArrayLen(self, target: int, nums: List[int]) -> int: @@ -277,6 +293,8 @@ class Solution: return ans if ans <= n else 0 ``` +#### Java + ```java class Solution { public int minSubArrayLen(int target, int[] nums) { @@ -295,6 +313,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -314,6 +334,8 @@ public: }; ``` +#### Go + ```go func minSubArrayLen(target int, nums []int) int { n := len(nums) @@ -334,6 +356,8 @@ func minSubArrayLen(target int, nums []int) int { } ``` +#### TypeScript + ```ts function minSubArrayLen(target: number, nums: number[]): number { const n = nums.length; diff --git a/solution/0200-0299/0209.Minimum Size Subarray Sum/README_EN.md b/solution/0200-0299/0209.Minimum Size Subarray Sum/README_EN.md index 98e0e85e0e184..f540fa51066b5 100644 --- a/solution/0200-0299/0209.Minimum Size Subarray Sum/README_EN.md +++ b/solution/0200-0299/0209.Minimum Size Subarray Sum/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def minSubArrayLen(self, target: int, nums: List[int]) -> int: @@ -87,6 +89,8 @@ class Solution: return ans if ans <= n else 0 ``` +#### Java + ```java class Solution { public int minSubArrayLen(int target, int[] nums) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func minSubArrayLen(target int, nums []int) int { n := len(nums) @@ -162,6 +170,8 @@ func minSubArrayLen(target int, nums []int) int { } ``` +#### TypeScript + ```ts function minSubArrayLen(target: number, nums: number[]): number { const n = nums.length; @@ -193,6 +203,8 @@ function minSubArrayLen(target: number, nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_sub_array_len(target: i32, nums: Vec) -> i32 { @@ -217,6 +229,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int MinSubArrayLen(int target, int[] nums) { @@ -253,6 +267,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is +#### Python3 + ```python class Solution: def minSubArrayLen(self, target: int, nums: List[int]) -> int: @@ -268,6 +284,8 @@ class Solution: return ans if ans <= n else 0 ``` +#### Java + ```java class Solution { public int minSubArrayLen(int target, int[] nums) { @@ -286,6 +304,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -305,6 +325,8 @@ public: }; ``` +#### Go + ```go func minSubArrayLen(target int, nums []int) int { n := len(nums) @@ -325,6 +347,8 @@ func minSubArrayLen(target int, nums []int) int { } ``` +#### TypeScript + ```ts function minSubArrayLen(target: number, nums: number[]): number { const n = nums.length; diff --git a/solution/0200-0299/0210.Course Schedule II/README.md b/solution/0200-0299/0210.Course Schedule II/README.md index 2926b45e27743..ccd6ce8102bf0 100644 --- a/solution/0200-0299/0210.Course Schedule II/README.md +++ b/solution/0200-0299/0210.Course Schedule II/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def findOrder(self, numCourses: int, prerequisites: List[List[int]]) -> List[int]: @@ -105,6 +107,8 @@ class Solution: return ans if len(ans) == numCourses else [] ``` +#### Java + ```java class Solution { public int[] findOrder(int numCourses, int[][] prerequisites) { @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func findOrder(numCourses int, prerequisites [][]int) []int { g := make([][]int, numCourses) @@ -205,6 +213,8 @@ func findOrder(numCourses int, prerequisites [][]int) []int { } ``` +#### TypeScript + ```ts function findOrder(numCourses: number, prerequisites: number[][]): number[] { const g: number[][] = Array.from({ length: numCourses }, () => []); @@ -233,6 +243,8 @@ function findOrder(numCourses: number, prerequisites: number[][]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn find_order(num_courses: i32, prerequisites: Vec>) -> Vec { @@ -274,6 +286,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int[] FindOrder(int numCourses, int[][] prerequisites) { diff --git a/solution/0200-0299/0210.Course Schedule II/README_EN.md b/solution/0200-0299/0210.Course Schedule II/README_EN.md index a7e1a7a0712ab..b901fcaed5f17 100644 --- a/solution/0200-0299/0210.Course Schedule II/README_EN.md +++ b/solution/0200-0299/0210.Course Schedule II/README_EN.md @@ -74,6 +74,8 @@ So one correct course order is [0,1,2,3]. Another correct ordering is [0,2,1,3]. +#### Python3 + ```python class Solution: def findOrder(self, numCourses: int, prerequisites: List[List[int]]) -> List[int]: @@ -94,6 +96,8 @@ class Solution: return ans if len(ans) == numCourses else [] ``` +#### Java + ```java class Solution { public int[] findOrder(int numCourses, int[][] prerequisites) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func findOrder(numCourses int, prerequisites [][]int) []int { g := make([][]int, numCourses) @@ -194,6 +202,8 @@ func findOrder(numCourses int, prerequisites [][]int) []int { } ``` +#### TypeScript + ```ts function findOrder(numCourses: number, prerequisites: number[][]): number[] { const g: number[][] = Array.from({ length: numCourses }, () => []); @@ -222,6 +232,8 @@ function findOrder(numCourses: number, prerequisites: number[][]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn find_order(num_courses: i32, prerequisites: Vec>) -> Vec { @@ -263,6 +275,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int[] FindOrder(int numCourses, int[][] prerequisites) { diff --git a/solution/0200-0299/0211.Design Add and Search Words Data Structure/README.md b/solution/0200-0299/0211.Design Add and Search Words Data Structure/README.md index 1222e71444c02..244a9222c2276 100644 --- a/solution/0200-0299/0211.Design Add and Search Words Data Structure/README.md +++ b/solution/0200-0299/0211.Design Add and Search Words Data Structure/README.md @@ -72,6 +72,8 @@ wordDictionary.search("b.."); // 返回 True +#### Python3 + ```python class Trie: def __init__(self): @@ -116,6 +118,8 @@ class WordDictionary: # param_2 = obj.search(word) ``` +#### Java + ```java class Trie { Trie[] children = new Trie[26]; @@ -175,6 +179,8 @@ class WordDictionary { */ ``` +#### C++ + ```cpp class trie { public: @@ -245,6 +251,8 @@ private: */ ``` +#### Go + ```go type WordDictionary struct { root *trie @@ -310,6 +318,8 @@ func (t *trie) insert(word string) { */ ``` +#### C# + ```cs using System.Collections.Generic; using System.Linq; diff --git a/solution/0200-0299/0211.Design Add and Search Words Data Structure/README_EN.md b/solution/0200-0299/0211.Design Add and Search Words Data Structure/README_EN.md index fe4c77ddfb192..ef5391b84b3da 100644 --- a/solution/0200-0299/0211.Design Add and Search Words Data Structure/README_EN.md +++ b/solution/0200-0299/0211.Design Add and Search Words Data Structure/README_EN.md @@ -71,6 +71,8 @@ wordDictionary.search("b.."); // return True +#### Python3 + ```python class Trie: def __init__(self): @@ -115,6 +117,8 @@ class WordDictionary: # param_2 = obj.search(word) ``` +#### Java + ```java class Trie { Trie[] children = new Trie[26]; @@ -174,6 +178,8 @@ class WordDictionary { */ ``` +#### C++ + ```cpp class trie { public: @@ -244,6 +250,8 @@ private: */ ``` +#### Go + ```go type WordDictionary struct { root *trie @@ -309,6 +317,8 @@ func (t *trie) insert(word string) { */ ``` +#### C# + ```cs using System.Collections.Generic; using System.Linq; diff --git a/solution/0200-0299/0212.Word Search II/README.md b/solution/0200-0299/0212.Word Search II/README.md index cc4de89a6bed4..d770c28ed895d 100644 --- a/solution/0200-0299/0212.Word Search II/README.md +++ b/solution/0200-0299/0212.Word Search II/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Trie: def __init__(self): @@ -118,6 +120,8 @@ class Solution: return ans ``` +#### Java + ```java class Trie { Trie[] children = new Trie[26]; @@ -181,6 +185,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -246,6 +252,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [26]*Trie @@ -304,6 +312,8 @@ func findWords(board [][]byte, words []string) (ans []string) { } ``` +#### TypeScript + ```ts class Trie { children: Trie[]; diff --git a/solution/0200-0299/0212.Word Search II/README_EN.md b/solution/0200-0299/0212.Word Search II/README_EN.md index 96b4fa1c27321..a98ea6d04c415 100644 --- a/solution/0200-0299/0212.Word Search II/README_EN.md +++ b/solution/0200-0299/0212.Word Search II/README_EN.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Trie: def __init__(self): @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Trie { Trie[] children = new Trie[26]; @@ -171,6 +175,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -236,6 +242,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [26]*Trie @@ -294,6 +302,8 @@ func findWords(board [][]byte, words []string) (ans []string) { } ``` +#### TypeScript + ```ts class Trie { children: Trie[]; diff --git a/solution/0200-0299/0213.House Robber II/README.md b/solution/0200-0299/0213.House Robber II/README.md index 050ebe3dca2bd..b7bae0b12b3c2 100644 --- a/solution/0200-0299/0213.House Robber II/README.md +++ b/solution/0200-0299/0213.House Robber II/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def rob(self, nums: List[int]) -> int: @@ -83,6 +85,8 @@ class Solution: return max(_rob(nums[1:]), _rob(nums[:-1])) ``` +#### Java + ```java class Solution { public int rob(int[] nums) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func rob(nums []int) int { n := len(nums) @@ -146,6 +154,8 @@ func robRange(nums []int, l, r int) int { } ``` +#### TypeScript + ```ts function rob(nums: number[]): number { const n = nums.length; @@ -163,6 +173,8 @@ function rob(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn rob(nums: Vec) -> i32 { diff --git a/solution/0200-0299/0213.House Robber II/README_EN.md b/solution/0200-0299/0213.House Robber II/README_EN.md index 039cfac56cd6b..38f8941ca5531 100644 --- a/solution/0200-0299/0213.House Robber II/README_EN.md +++ b/solution/0200-0299/0213.House Robber II/README_EN.md @@ -68,6 +68,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def rob(self, nums: List[int]) -> int: @@ -82,6 +84,8 @@ class Solution: return max(_rob(nums[1:]), _rob(nums[:-1])) ``` +#### Java + ```java class Solution { public int rob(int[] nums) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func rob(nums []int) int { n := len(nums) @@ -145,6 +153,8 @@ func robRange(nums []int, l, r int) int { } ``` +#### TypeScript + ```ts function rob(nums: number[]): number { const n = nums.length; @@ -162,6 +172,8 @@ function rob(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn rob(nums: Vec) -> i32 { diff --git a/solution/0200-0299/0214.Shortest Palindrome/README.md b/solution/0200-0299/0214.Shortest Palindrome/README.md index fc8932c006303..d79f1e47c941f 100644 --- a/solution/0200-0299/0214.Shortest Palindrome/README.md +++ b/solution/0200-0299/0214.Shortest Palindrome/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def shortestPalindrome(self, s: str) -> str: @@ -86,6 +88,8 @@ class Solution: return s if idx == n else s[idx:][::-1] + s ``` +#### Java + ```java class Solution { public String shortestPalindrome(String s) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp typedef unsigned long long ull; @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func shortestPalindrome(s string) string { n := len(s) @@ -164,6 +172,8 @@ func shortestPalindrome(s string) string { } ``` +#### Rust + ```rust impl Solution { pub fn shortest_palindrome(s: String) -> String { @@ -188,6 +198,8 @@ impl Solution { } ``` +#### C# + ```cs // https://leetcode.com/problems/shortest-palindrome/ diff --git a/solution/0200-0299/0214.Shortest Palindrome/README_EN.md b/solution/0200-0299/0214.Shortest Palindrome/README_EN.md index 50018edca3247..eb80912e1c16c 100644 --- a/solution/0200-0299/0214.Shortest Palindrome/README_EN.md +++ b/solution/0200-0299/0214.Shortest Palindrome/README_EN.md @@ -49,6 +49,8 @@ tags: +#### Python3 + ```python class Solution: def shortestPalindrome(self, s: str) -> str: @@ -67,6 +69,8 @@ class Solution: return s if idx == n else s[idx:][::-1] + s ``` +#### Java + ```java class Solution { public String shortestPalindrome(String s) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp typedef unsigned long long ull; @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func shortestPalindrome(s string) string { n := len(s) @@ -145,6 +153,8 @@ func shortestPalindrome(s string) string { } ``` +#### Rust + ```rust impl Solution { pub fn shortest_palindrome(s: String) -> String { @@ -169,6 +179,8 @@ impl Solution { } ``` +#### C# + ```cs // https://leetcode.com/problems/shortest-palindrome/ diff --git a/solution/0200-0299/0215.Kth Largest Element in an Array/README.md b/solution/0200-0299/0215.Kth Largest Element in an Array/README.md index e552327f0622d..2c0da0b1d20a7 100644 --- a/solution/0200-0299/0215.Kth Largest Element in an Array/README.md +++ b/solution/0200-0299/0215.Kth Largest Element in an Array/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def findKthLargest(self, nums: List[int], k: int) -> int: @@ -91,6 +93,8 @@ class Solution: return quick_sort(0, n - 1, n - k) ``` +#### Java + ```java class Solution { public int findKthLargest(int[] nums, int k) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func findKthLargest(nums []int, k int) int { n := len(nums) @@ -183,6 +191,8 @@ func quickSort(nums []int, left, right, k int) int { } ``` +#### TypeScript + ```ts function findKthLargest(nums: number[], k: number): number { const n = nums.length; @@ -212,6 +222,8 @@ function findKthLargest(nums: number[], k: number): number { } ``` +#### Rust + ```rust use rand::Rng; @@ -260,6 +272,8 @@ impl Solution { +#### Rust + ```rust use rand::Rng; diff --git a/solution/0200-0299/0215.Kth Largest Element in an Array/README_EN.md b/solution/0200-0299/0215.Kth Largest Element in an Array/README_EN.md index d661d989ea7ef..0c7baa96018a3 100644 --- a/solution/0200-0299/0215.Kth Largest Element in an Array/README_EN.md +++ b/solution/0200-0299/0215.Kth Largest Element in an Array/README_EN.md @@ -56,6 +56,8 @@ The time complexity is $O(n \times \log n)$, where $n$ is the length of the arra +#### Python3 + ```python class Solution: def findKthLargest(self, nums: List[int], k: int) -> int: @@ -83,6 +85,8 @@ class Solution: return quick_sort(0, n - 1, n - k) ``` +#### Java + ```java class Solution { public int findKthLargest(int[] nums, int k) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func findKthLargest(nums []int, k int) int { n := len(nums) @@ -175,6 +183,8 @@ func quickSort(nums []int, left, right, k int) int { } ``` +#### TypeScript + ```ts function findKthLargest(nums: number[], k: number): number { const n = nums.length; @@ -204,6 +214,8 @@ function findKthLargest(nums: number[], k: number): number { } ``` +#### Rust + ```rust use rand::Rng; @@ -252,6 +264,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. +#### Rust + ```rust use rand::Rng; diff --git a/solution/0200-0299/0216.Combination Sum III/README.md b/solution/0200-0299/0216.Combination Sum III/README.md index 746ff984c02f8..008f507bc638b 100644 --- a/solution/0200-0299/0216.Combination Sum III/README.md +++ b/solution/0200-0299/0216.Combination Sum III/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def combinationSum3(self, k: int, n: int) -> List[List[int]]: @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func combinationSum3(k int, n int) (ans [][]int) { t := []int{} @@ -188,6 +196,8 @@ func combinationSum3(k int, n int) (ans [][]int) { } ``` +#### TypeScript + ```ts function combinationSum3(k: number, n: number): number[][] { const ans: number[][] = []; @@ -212,6 +222,8 @@ function combinationSum3(k: number, n: number): number[][] { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -251,6 +263,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { private List> ans = new List>(); @@ -295,6 +309,8 @@ public class Solution { +#### Python3 + ```python class Solution: def combinationSum3(self, k: int, n: int) -> List[List[int]]: @@ -316,6 +332,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -347,6 +365,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -375,6 +395,8 @@ public: }; ``` +#### Go + ```go func combinationSum3(k int, n int) (ans [][]int) { t := []int{} @@ -400,6 +422,8 @@ func combinationSum3(k int, n int) (ans [][]int) { } ``` +#### TypeScript + ```ts function combinationSum3(k: number, n: number): number[][] { const ans: number[][] = []; @@ -425,6 +449,8 @@ function combinationSum3(k: number, n: number): number[][] { } ``` +#### C# + ```cs public class Solution { private List> ans = new List>(); @@ -478,6 +504,8 @@ public class Solution { +#### Python3 + ```python class Solution: def combinationSum3(self, k: int, n: int) -> List[List[int]]: @@ -490,6 +518,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> combinationSum3(int k, int n) { @@ -514,6 +544,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -539,6 +571,8 @@ public: }; ``` +#### Go + ```go func combinationSum3(k int, n int) (ans [][]int) { for mask := 0; mask < 1<<9; mask++ { @@ -560,6 +594,8 @@ func combinationSum3(k int, n int) (ans [][]int) { } ``` +#### TypeScript + ```ts function combinationSum3(k: number, n: number): number[][] { const ans: number[][] = []; @@ -591,6 +627,8 @@ function bitCount(i: number): number { } ``` +#### C# + ```cs public class Solution { public IList> CombinationSum3(int k, int n) { diff --git a/solution/0200-0299/0216.Combination Sum III/README_EN.md b/solution/0200-0299/0216.Combination Sum III/README_EN.md index 14177415a5210..afec40aff3180 100644 --- a/solution/0200-0299/0216.Combination Sum III/README_EN.md +++ b/solution/0200-0299/0216.Combination Sum III/README_EN.md @@ -85,6 +85,8 @@ Approach One: +#### Python3 + ```python class Solution: def combinationSum3(self, k: int, n: int) -> List[List[int]]: @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func combinationSum3(k int, n int) (ans [][]int) { t := []int{} @@ -187,6 +195,8 @@ func combinationSum3(k int, n int) (ans [][]int) { } ``` +#### TypeScript + ```ts function combinationSum3(k: number, n: number): number[][] { const ans: number[][] = []; @@ -211,6 +221,8 @@ function combinationSum3(k: number, n: number): number[][] { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -250,6 +262,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { private List> ans = new List>(); @@ -294,6 +308,8 @@ The time complexity is $(C_{9}^k \times k)$, and the space complexity is $O(k)$. +#### Python3 + ```python class Solution: def combinationSum3(self, k: int, n: int) -> List[List[int]]: @@ -315,6 +331,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans = new ArrayList<>(); @@ -346,6 +364,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -374,6 +394,8 @@ public: }; ``` +#### Go + ```go func combinationSum3(k int, n int) (ans [][]int) { t := []int{} @@ -399,6 +421,8 @@ func combinationSum3(k int, n int) (ans [][]int) { } ``` +#### TypeScript + ```ts function combinationSum3(k: number, n: number): number[][] { const ans: number[][] = []; @@ -424,6 +448,8 @@ function combinationSum3(k: number, n: number): number[][] { } ``` +#### C# + ```cs public class Solution { private List> ans = new List>(); @@ -477,6 +503,8 @@ Similar problems: +#### Python3 + ```python class Solution: def combinationSum3(self, k: int, n: int) -> List[List[int]]: @@ -489,6 +517,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> combinationSum3(int k, int n) { @@ -513,6 +543,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -538,6 +570,8 @@ public: }; ``` +#### Go + ```go func combinationSum3(k int, n int) (ans [][]int) { for mask := 0; mask < 1<<9; mask++ { @@ -559,6 +593,8 @@ func combinationSum3(k int, n int) (ans [][]int) { } ``` +#### TypeScript + ```ts function combinationSum3(k: number, n: number): number[][] { const ans: number[][] = []; @@ -590,6 +626,8 @@ function bitCount(i: number): number { } ``` +#### C# + ```cs public class Solution { public IList> CombinationSum3(int k, int n) { diff --git a/solution/0200-0299/0217.Contains Duplicate/README.md b/solution/0200-0299/0217.Contains Duplicate/README.md index db42a761f90b7..34c6038c0e33f 100644 --- a/solution/0200-0299/0217.Contains Duplicate/README.md +++ b/solution/0200-0299/0217.Contains Duplicate/README.md @@ -67,12 +67,16 @@ tags: +#### Python3 + ```python class Solution: def containsDuplicate(self, nums: List[int]) -> bool: return any(a == b for a, b in pairwise(sorted(nums))) ``` +#### Java + ```java class Solution { public boolean containsDuplicate(int[] nums) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -102,6 +108,8 @@ public: }; ``` +#### Go + ```go func containsDuplicate(nums []int) bool { sort.Ints(nums) @@ -114,6 +122,8 @@ func containsDuplicate(nums []int) bool { } ``` +#### TypeScript + ```ts function containsDuplicate(nums: number[]): boolean { nums.sort((a, b) => a - b); @@ -127,6 +137,8 @@ function containsDuplicate(nums: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn contains_duplicate(mut nums: Vec) -> bool { @@ -142,6 +154,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -152,6 +166,8 @@ var containsDuplicate = function (nums) { }; ``` +#### C# + ```cs public class Solution { public bool ContainsDuplicate(int[] nums) { @@ -160,6 +176,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** @@ -173,6 +191,8 @@ class Solution { } ``` +#### C + ```c int cmp(const void* a, const void* b) { return *(int*) a - *(int*) b; @@ -203,12 +223,16 @@ bool containsDuplicate(int* nums, int numsSize) { +#### Python3 + ```python class Solution: def containsDuplicate(self, nums: List[int]) -> bool: return len(set(nums)) < len(nums) ``` +#### Java + ```java class Solution { public boolean containsDuplicate(int[] nums) { @@ -223,6 +247,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -233,6 +259,8 @@ public: }; ``` +#### Go + ```go func containsDuplicate(nums []int) bool { s := map[int]bool{} @@ -246,12 +274,16 @@ func containsDuplicate(nums []int) bool { } ``` +#### TypeScript + ```ts function containsDuplicate(nums: number[]): boolean { return new Set(nums).size !== nums.length; } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { diff --git a/solution/0200-0299/0217.Contains Duplicate/README_EN.md b/solution/0200-0299/0217.Contains Duplicate/README_EN.md index aeb942fb1c7ab..96e6ab2776a6e 100644 --- a/solution/0200-0299/0217.Contains Duplicate/README_EN.md +++ b/solution/0200-0299/0217.Contains Duplicate/README_EN.md @@ -57,12 +57,16 @@ The time complexity is $O(n \times \log n)$, where $n$ is the length of the arra +#### Python3 + ```python class Solution: def containsDuplicate(self, nums: List[int]) -> bool: return any(a == b for a, b in pairwise(sorted(nums))) ``` +#### Java + ```java class Solution { public boolean containsDuplicate(int[] nums) { @@ -77,6 +81,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -92,6 +98,8 @@ public: }; ``` +#### Go + ```go func containsDuplicate(nums []int) bool { sort.Ints(nums) @@ -104,6 +112,8 @@ func containsDuplicate(nums []int) bool { } ``` +#### TypeScript + ```ts function containsDuplicate(nums: number[]): boolean { nums.sort((a, b) => a - b); @@ -117,6 +127,8 @@ function containsDuplicate(nums: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn contains_duplicate(mut nums: Vec) -> bool { @@ -132,6 +144,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -142,6 +156,8 @@ var containsDuplicate = function (nums) { }; ``` +#### C# + ```cs public class Solution { public bool ContainsDuplicate(int[] nums) { @@ -150,6 +166,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** @@ -163,6 +181,8 @@ class Solution { } ``` +#### C + ```c int cmp(const void* a, const void* b) { return *(int*) a - *(int*) b; @@ -193,12 +213,16 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python class Solution: def containsDuplicate(self, nums: List[int]) -> bool: return len(set(nums)) < len(nums) ``` +#### Java + ```java class Solution { public boolean containsDuplicate(int[] nums) { @@ -213,6 +237,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -223,6 +249,8 @@ public: }; ``` +#### Go + ```go func containsDuplicate(nums []int) bool { s := map[int]bool{} @@ -236,12 +264,16 @@ func containsDuplicate(nums []int) bool { } ``` +#### TypeScript + ```ts function containsDuplicate(nums: number[]): boolean { return new Set(nums).size !== nums.length; } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { diff --git a/solution/0200-0299/0218.The Skyline Problem/README.md b/solution/0200-0299/0218.The Skyline Problem/README.md index 109fd4a0c666a..d832a71506142 100644 --- a/solution/0200-0299/0218.The Skyline Problem/README.md +++ b/solution/0200-0299/0218.The Skyline Problem/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python from queue import PriorityQueue @@ -105,6 +107,8 @@ class Solution: return skys ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +148,8 @@ public: }; ``` +#### Go + ```go type Matrix struct{ left, right, height int } type Queue []Matrix @@ -192,6 +198,8 @@ func getSkyline(buildings [][]int) [][]int { } ``` +#### Rust + ```rust impl Solution { pub fn get_skyline(buildings: Vec>) -> Vec> { diff --git a/solution/0200-0299/0218.The Skyline Problem/README_EN.md b/solution/0200-0299/0218.The Skyline Problem/README_EN.md index 748bc72ef2f8c..9ee3d32874311 100644 --- a/solution/0200-0299/0218.The Skyline Problem/README_EN.md +++ b/solution/0200-0299/0218.The Skyline Problem/README_EN.md @@ -76,6 +76,8 @@ Figure B shows the skyline formed by those buildings. The red points in figure B +#### Python3 + ```python from queue import PriorityQueue @@ -102,6 +104,8 @@ class Solution: return skys ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +145,8 @@ public: }; ``` +#### Go + ```go type Matrix struct{ left, right, height int } type Queue []Matrix @@ -189,6 +195,8 @@ func getSkyline(buildings [][]int) [][]int { } ``` +#### Rust + ```rust impl Solution { pub fn get_skyline(buildings: Vec>) -> Vec> { diff --git a/solution/0200-0299/0219.Contains Duplicate II/README.md b/solution/0200-0299/0219.Contains Duplicate II/README.md index 1ae4dc00c5273..e52457fe70649 100644 --- a/solution/0200-0299/0219.Contains Duplicate II/README.md +++ b/solution/0200-0299/0219.Contains Duplicate II/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool: @@ -81,6 +83,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean containsNearbyDuplicate(int[] nums, int k) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func containsNearbyDuplicate(nums []int, k int) bool { d := map[int]int{} @@ -125,6 +133,8 @@ func containsNearbyDuplicate(nums []int, k int) bool { } ``` +#### TypeScript + ```ts function containsNearbyDuplicate(nums: number[], k: number): boolean { const d: Map = new Map(); @@ -138,6 +148,8 @@ function containsNearbyDuplicate(nums: number[], k: number): boolean { } ``` +#### C# + ```cs public class Solution { public bool ContainsNearbyDuplicate(int[] nums, int k) { @@ -153,6 +165,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0200-0299/0219.Contains Duplicate II/README_EN.md b/solution/0200-0299/0219.Contains Duplicate II/README_EN.md index 467370a3288b2..41cff32cb8e68 100644 --- a/solution/0200-0299/0219.Contains Duplicate II/README_EN.md +++ b/solution/0200-0299/0219.Contains Duplicate II/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n)$ and the space complexity is $O(n)$. Here $n$ is th +#### Python3 + ```python class Solution: def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool: @@ -80,6 +82,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean containsNearbyDuplicate(int[] nums, int k) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func containsNearbyDuplicate(nums []int, k int) bool { d := map[int]int{} @@ -124,6 +132,8 @@ func containsNearbyDuplicate(nums []int, k int) bool { } ``` +#### TypeScript + ```ts function containsNearbyDuplicate(nums: number[], k: number): boolean { const d: Map = new Map(); @@ -137,6 +147,8 @@ function containsNearbyDuplicate(nums: number[], k: number): boolean { } ``` +#### C# + ```cs public class Solution { public bool ContainsNearbyDuplicate(int[] nums, int k) { @@ -152,6 +164,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0200-0299/0220.Contains Duplicate III/README.md b/solution/0200-0299/0220.Contains Duplicate III/README.md index 94ffc82c46dbd..2f84e722b2274 100644 --- a/solution/0200-0299/0220.Contains Duplicate III/README.md +++ b/solution/0200-0299/0220.Contains Duplicate III/README.md @@ -81,6 +81,8 @@ abs(nums[i] - nums[j]) <= valueDiff --> abs(1 - 1) <= 0 +#### Python3 + ```python from sortedcontainers import SortedSet @@ -100,6 +102,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean containsNearbyAlmostDuplicate(int[] nums, int indexDiff, int valueDiff) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func containsNearbyAlmostDuplicate(nums []int, k int, t int) bool { n := len(nums) @@ -159,6 +167,8 @@ func containsNearbyAlmostDuplicate(nums []int, k int, t int) bool { } ``` +#### TypeScript + ```ts function containsNearbyAlmostDuplicate( nums: number[], @@ -820,6 +830,8 @@ class TreeMultiSet { } ``` +#### C# + ```cs public class Solution { public bool ContainsNearbyAlmostDuplicate(int[] nums, int k, int t) { diff --git a/solution/0200-0299/0220.Contains Duplicate III/README_EN.md b/solution/0200-0299/0220.Contains Duplicate III/README_EN.md index e0ca9e177dbf5..847747f02a0b6 100644 --- a/solution/0200-0299/0220.Contains Duplicate III/README_EN.md +++ b/solution/0200-0299/0220.Contains Duplicate III/README_EN.md @@ -79,6 +79,8 @@ The time complexity is $O(n \times \log k)$, where $n$ is the length of the arra +#### Python3 + ```python from sortedcontainers import SortedSet @@ -98,6 +100,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean containsNearbyAlmostDuplicate(int[] nums, int indexDiff, int valueDiff) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func containsNearbyAlmostDuplicate(nums []int, k int, t int) bool { n := len(nums) @@ -157,6 +165,8 @@ func containsNearbyAlmostDuplicate(nums []int, k int, t int) bool { } ``` +#### TypeScript + ```ts function containsNearbyAlmostDuplicate( nums: number[], @@ -818,6 +828,8 @@ class TreeMultiSet { } ``` +#### C# + ```cs public class Solution { public bool ContainsNearbyAlmostDuplicate(int[] nums, int k, int t) { diff --git a/solution/0200-0299/0221.Maximal Square/README.md b/solution/0200-0299/0221.Maximal Square/README.md index 49e8958f012f6..908e41eea3d34 100644 --- a/solution/0200-0299/0221.Maximal Square/README.md +++ b/solution/0200-0299/0221.Maximal Square/README.md @@ -78,6 +78,8 @@ $$ +#### Python3 + ```python class Solution: def maximalSquare(self, matrix: List[List[str]]) -> int: @@ -92,6 +94,8 @@ class Solution: return mx * mx ``` +#### Java + ```java class Solution { public int maximalSquare(char[][] matrix) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func maximalSquare(matrix [][]byte) int { m, n := len(matrix), len(matrix[0]) @@ -151,6 +159,8 @@ func maximalSquare(matrix [][]byte) int { } ``` +#### C# + ```cs public class Solution { public int MaximalSquare(char[][] matrix) { diff --git a/solution/0200-0299/0221.Maximal Square/README_EN.md b/solution/0200-0299/0221.Maximal Square/README_EN.md index f823731ada1ae..0c7a2f3e01338 100644 --- a/solution/0200-0299/0221.Maximal Square/README_EN.md +++ b/solution/0200-0299/0221.Maximal Square/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(m\times n)$, and the space complexity is $O(m\times n) +#### Python3 + ```python class Solution: def maximalSquare(self, matrix: List[List[str]]) -> int: @@ -90,6 +92,8 @@ class Solution: return mx * mx ``` +#### Java + ```java class Solution { public int maximalSquare(char[][] matrix) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func maximalSquare(matrix [][]byte) int { m, n := len(matrix), len(matrix[0]) @@ -149,6 +157,8 @@ func maximalSquare(matrix [][]byte) int { } ``` +#### C# + ```cs public class Solution { public int MaximalSquare(char[][] matrix) { diff --git a/solution/0200-0299/0222.Count Complete Tree Nodes/README.md b/solution/0200-0299/0222.Count Complete Tree Nodes/README.md index d4448369731e6..74868bd90f5df 100644 --- a/solution/0200-0299/0222.Count Complete Tree Nodes/README.md +++ b/solution/0200-0299/0222.Count Complete Tree Nodes/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -88,6 +90,8 @@ class Solution: return 1 + self.countNodes(root.left) + self.countNodes(root.right) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -154,6 +162,8 @@ func countNodes(root *TreeNode) int { } ``` +#### Rust + ```rust use std::cell::RefCell; use std::rc::Rc; @@ -180,6 +190,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -201,6 +213,8 @@ var countNodes = function (root) { }; ``` +#### C# + ```cs /** * Definition for a binary tree node. @@ -248,6 +262,8 @@ public class Solution { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -272,6 +288,8 @@ class Solution: return (1 << right) + self.countNodes(root.left) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -311,6 +329,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -347,6 +367,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -375,6 +397,8 @@ func depth(root *TreeNode) (d int) { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -408,6 +432,8 @@ var countNodes = function (root) { }; ``` +#### C# + ```cs /** * Definition for a binary tree node. diff --git a/solution/0200-0299/0222.Count Complete Tree Nodes/README_EN.md b/solution/0200-0299/0222.Count Complete Tree Nodes/README_EN.md index 2ed635bb2d07b..abc917a879b3e 100644 --- a/solution/0200-0299/0222.Count Complete Tree Nodes/README_EN.md +++ b/solution/0200-0299/0222.Count Complete Tree Nodes/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -84,6 +86,8 @@ class Solution: return 1 + self.countNodes(root.left) + self.countNodes(root.right) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -150,6 +158,8 @@ func countNodes(root *TreeNode) int { } ``` +#### Rust + ```rust use std::cell::RefCell; use std::rc::Rc; @@ -176,6 +186,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -197,6 +209,8 @@ var countNodes = function (root) { }; ``` +#### C# + ```cs /** * Definition for a binary tree node. @@ -244,6 +258,8 @@ The time complexity is $O(\log^2 n)$. +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -268,6 +284,8 @@ class Solution: return (1 << right) + self.countNodes(root.left) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -307,6 +325,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -343,6 +363,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -371,6 +393,8 @@ func depth(root *TreeNode) (d int) { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -404,6 +428,8 @@ var countNodes = function (root) { }; ``` +#### C# + ```cs /** * Definition for a binary tree node. diff --git a/solution/0200-0299/0223.Rectangle Area/README.md b/solution/0200-0299/0223.Rectangle Area/README.md index bc5bafeb185ab..d959060fbfc6a 100644 --- a/solution/0200-0299/0223.Rectangle Area/README.md +++ b/solution/0200-0299/0223.Rectangle Area/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def computeArea( @@ -86,6 +88,8 @@ class Solution: return a + b - max(height, 0) * max(width, 0) ``` +#### Java + ```java class Solution { public int computeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func computeArea(ax1 int, ay1 int, ax2 int, ay2 int, bx1 int, by1 int, bx2 int, by2 int) int { a := (ax2 - ax1) * (ay2 - ay1) @@ -121,6 +129,8 @@ func computeArea(ax1 int, ay1 int, ax2 int, ay2 int, bx1 int, by1 int, bx2 int, } ``` +#### TypeScript + ```ts function computeArea( ax1: number, @@ -140,6 +150,8 @@ function computeArea( } ``` +#### C# + ```cs public class Solution { public int ComputeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2) { diff --git a/solution/0200-0299/0223.Rectangle Area/README_EN.md b/solution/0200-0299/0223.Rectangle Area/README_EN.md index c99c8ce795a7a..cb4b55235be53 100644 --- a/solution/0200-0299/0223.Rectangle Area/README_EN.md +++ b/solution/0200-0299/0223.Rectangle Area/README_EN.md @@ -62,6 +62,8 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def computeArea( @@ -82,6 +84,8 @@ class Solution: return a + b - max(height, 0) * max(width, 0) ``` +#### Java + ```java class Solution { public int computeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func computeArea(ax1 int, ay1 int, ax2 int, ay2 int, bx1 int, by1 int, bx2 int, by2 int) int { a := (ax2 - ax1) * (ay2 - ay1) @@ -117,6 +125,8 @@ func computeArea(ax1 int, ay1 int, ax2 int, ay2 int, bx1 int, by1 int, bx2 int, } ``` +#### TypeScript + ```ts function computeArea( ax1: number, @@ -136,6 +146,8 @@ function computeArea( } ``` +#### C# + ```cs public class Solution { public int ComputeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2) { diff --git a/solution/0200-0299/0224.Basic Calculator/README.md b/solution/0200-0299/0224.Basic Calculator/README.md index c9130b8d34c9d..4596122dbb21d 100644 --- a/solution/0200-0299/0224.Basic Calculator/README.md +++ b/solution/0200-0299/0224.Basic Calculator/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def calculate(self, s: str) -> int: @@ -113,6 +115,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int calculate(String s) { @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -187,6 +193,8 @@ public: }; ``` +#### Go + ```go func calculate(s string) (ans int) { stk := []int{} @@ -222,6 +230,8 @@ func calculate(s string) (ans int) { } ``` +#### TypeScript + ```ts function calculate(s: string): number { const stk: number[] = []; @@ -258,6 +268,8 @@ function calculate(s: string): number { } ``` +#### C# + ```cs public class Solution { public int Calculate(string s) { diff --git a/solution/0200-0299/0224.Basic Calculator/README_EN.md b/solution/0200-0299/0224.Basic Calculator/README_EN.md index 68586ea575b48..4adb98caf2e3c 100644 --- a/solution/0200-0299/0224.Basic Calculator/README_EN.md +++ b/solution/0200-0299/0224.Basic Calculator/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python class Solution: def calculate(self, s: str) -> int: @@ -111,6 +113,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int calculate(String s) { @@ -147,6 +151,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -185,6 +191,8 @@ public: }; ``` +#### Go + ```go func calculate(s string) (ans int) { stk := []int{} @@ -220,6 +228,8 @@ func calculate(s string) (ans int) { } ``` +#### TypeScript + ```ts function calculate(s: string): number { const stk: number[] = []; @@ -256,6 +266,8 @@ function calculate(s: string): number { } ``` +#### C# + ```cs public class Solution { public int Calculate(string s) { diff --git a/solution/0200-0299/0225.Implement Stack using Queues/README.md b/solution/0200-0299/0225.Implement Stack using Queues/README.md index 707b576b0f7ef..025dd7f130705 100644 --- a/solution/0200-0299/0225.Implement Stack using Queues/README.md +++ b/solution/0200-0299/0225.Implement Stack using Queues/README.md @@ -91,6 +91,8 @@ myStack.empty(); // 返回 False +#### Python3 + ```python class MyStack: def __init__(self): @@ -121,6 +123,8 @@ class MyStack: # param_4 = obj.empty() ``` +#### Java + ```java import java.util.Deque; @@ -164,6 +168,8 @@ class MyStack { */ ``` +#### C++ + ```cpp class MyStack { public: @@ -208,6 +214,8 @@ private: */ ``` +#### Go + ```go type MyStack struct { q1 []int @@ -251,6 +259,8 @@ func (this *MyStack) Empty() bool { */ ``` +#### TypeScript + ```ts class MyStack { q1: number[] = []; @@ -289,6 +299,8 @@ class MyStack { */ ``` +#### Rust + ```rust use std::collections::VecDeque; diff --git a/solution/0200-0299/0225.Implement Stack using Queues/README_EN.md b/solution/0200-0299/0225.Implement Stack using Queues/README_EN.md index b87cea52398e9..bbe6a4bd2753b 100644 --- a/solution/0200-0299/0225.Implement Stack using Queues/README_EN.md +++ b/solution/0200-0299/0225.Implement Stack using Queues/README_EN.md @@ -86,6 +86,8 @@ The space complexity is $O(n)$, where $n$ is the number of elements in the stack +#### Python3 + ```python class MyStack: def __init__(self): @@ -116,6 +118,8 @@ class MyStack: # param_4 = obj.empty() ``` +#### Java + ```java import java.util.Deque; @@ -159,6 +163,8 @@ class MyStack { */ ``` +#### C++ + ```cpp class MyStack { public: @@ -203,6 +209,8 @@ private: */ ``` +#### Go + ```go type MyStack struct { q1 []int @@ -246,6 +254,8 @@ func (this *MyStack) Empty() bool { */ ``` +#### TypeScript + ```ts class MyStack { q1: number[] = []; @@ -284,6 +294,8 @@ class MyStack { */ ``` +#### Rust + ```rust use std::collections::VecDeque; diff --git a/solution/0200-0299/0226.Invert Binary Tree/README.md b/solution/0200-0299/0226.Invert Binary Tree/README.md index 6783b1d89cc6c..22288dbdecb38 100644 --- a/solution/0200-0299/0226.Invert Binary Tree/README.md +++ b/solution/0200-0299/0226.Invert Binary Tree/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -91,6 +93,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -179,6 +187,8 @@ func invertTree(root *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -208,6 +218,8 @@ function invertTree(root: TreeNode | null): TreeNode | null { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -249,6 +261,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -286,6 +300,8 @@ var invertTree = function (root) { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -302,6 +318,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -332,6 +350,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -359,6 +379,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -378,6 +400,8 @@ func invertTree(root *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -405,6 +429,8 @@ function invertTree(root: TreeNode | null): TreeNode | null { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0200-0299/0226.Invert Binary Tree/README_EN.md b/solution/0200-0299/0226.Invert Binary Tree/README_EN.md index 67a564aaac546..123dd9e82957b 100644 --- a/solution/0200-0299/0226.Invert Binary Tree/README_EN.md +++ b/solution/0200-0299/0226.Invert Binary Tree/README_EN.md @@ -65,6 +65,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -85,6 +87,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -173,6 +181,8 @@ func invertTree(root *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -202,6 +212,8 @@ function invertTree(root: TreeNode | null): TreeNode | null { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -243,6 +255,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -280,6 +294,8 @@ var invertTree = function (root) { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -296,6 +312,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -326,6 +344,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -353,6 +373,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -372,6 +394,8 @@ func invertTree(root *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -399,6 +423,8 @@ function invertTree(root: TreeNode | null): TreeNode | null { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0200-0299/0227.Basic Calculator II/README.md b/solution/0200-0299/0227.Basic Calculator II/README.md index db4d33e69b73c..2fb4013ebab4f 100644 --- a/solution/0200-0299/0227.Basic Calculator II/README.md +++ b/solution/0200-0299/0227.Basic Calculator II/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def calculate(self, s: str) -> int: @@ -105,6 +107,8 @@ class Solution: return sum(stk) ``` +#### Java + ```java class Solution { public int calculate(String s) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go func calculate(s string) int { sign := '+' @@ -210,6 +218,8 @@ func calculate(s string) int { } ``` +#### C# + ```cs using System.Collections.Generic; using System.Linq; diff --git a/solution/0200-0299/0227.Basic Calculator II/README_EN.md b/solution/0200-0299/0227.Basic Calculator II/README_EN.md index e3e78b8a8f49e..61b13e04b2682 100644 --- a/solution/0200-0299/0227.Basic Calculator II/README_EN.md +++ b/solution/0200-0299/0227.Basic Calculator II/README_EN.md @@ -68,6 +68,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python class Solution: def calculate(self, s: str) -> int: @@ -92,6 +94,8 @@ class Solution: return sum(stk) ``` +#### Java + ```java class Solution { public int calculate(String s) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func calculate(s string) int { sign := '+' @@ -197,6 +205,8 @@ func calculate(s string) int { } ``` +#### C# + ```cs using System.Collections.Generic; using System.Linq; diff --git a/solution/0200-0299/0228.Summary Ranges/README.md b/solution/0200-0299/0228.Summary Ranges/README.md index a4ab134137927..6316c2eb42888 100644 --- a/solution/0200-0299/0228.Summary Ranges/README.md +++ b/solution/0200-0299/0228.Summary Ranges/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def summaryRanges(self, nums: List[int]) -> List[str]: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List summaryRanges(int[] nums) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func summaryRanges(nums []int) (ans []string) { f := func(i, j int) string { @@ -156,6 +164,8 @@ func summaryRanges(nums []int) (ans []string) { } ``` +#### TypeScript + ```ts function summaryRanges(nums: number[]): string[] { const f = (i: number, j: number): string => { @@ -174,6 +184,8 @@ function summaryRanges(nums: number[]): string[] { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -214,6 +226,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public IList SummaryRanges(int[] nums) { diff --git a/solution/0200-0299/0228.Summary Ranges/README_EN.md b/solution/0200-0299/0228.Summary Ranges/README_EN.md index 19145ce364a64..c11ab81f24810 100644 --- a/solution/0200-0299/0228.Summary Ranges/README_EN.md +++ b/solution/0200-0299/0228.Summary Ranges/README_EN.md @@ -79,6 +79,8 @@ Time complexity $O(n)$, where $n$ is the length of the array. Space complexity $ +#### Python3 + ```python class Solution: def summaryRanges(self, nums: List[int]) -> List[str]: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List summaryRanges(int[] nums) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func summaryRanges(nums []int) (ans []string) { f := func(i, j int) string { @@ -156,6 +164,8 @@ func summaryRanges(nums []int) (ans []string) { } ``` +#### TypeScript + ```ts function summaryRanges(nums: number[]): string[] { const f = (i: number, j: number): string => { @@ -174,6 +184,8 @@ function summaryRanges(nums: number[]): string[] { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -214,6 +226,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public IList SummaryRanges(int[] nums) { diff --git a/solution/0200-0299/0229.Majority Element II/README.md b/solution/0200-0299/0229.Majority Element II/README.md index 47ff82f916a3f..671dcca5aec66 100644 --- a/solution/0200-0299/0229.Majority Element II/README.md +++ b/solution/0200-0299/0229.Majority Element II/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def majorityElement(self, nums: List[int]) -> List[int]: @@ -84,6 +86,8 @@ class Solution: return [m for m in [m1, m2] if nums.count(m) > len(nums) // 3] ``` +#### Java + ```java class Solution { public List majorityElement(int[] nums) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func majorityElement(nums []int) []int { var n1, n2 int @@ -192,6 +200,8 @@ func majorityElement(nums []int) []int { } ``` +#### C# + ```cs public class Solution { public IList MajorityElement(int[] nums) { @@ -231,6 +241,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0200-0299/0229.Majority Element II/README_EN.md b/solution/0200-0299/0229.Majority Element II/README_EN.md index f5c9bc8f1c4d7..128628da9b55e 100644 --- a/solution/0200-0299/0229.Majority Element II/README_EN.md +++ b/solution/0200-0299/0229.Majority Element II/README_EN.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def majorityElement(self, nums: List[int]) -> List[int]: @@ -83,6 +85,8 @@ class Solution: return [m for m in [m1, m2] if nums.count(m) > len(nums) // 3] ``` +#### Java + ```java class Solution { public List majorityElement(int[] nums) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func majorityElement(nums []int) []int { var n1, n2 int @@ -191,6 +199,8 @@ func majorityElement(nums []int) []int { } ``` +#### C# + ```cs public class Solution { public IList MajorityElement(int[] nums) { @@ -230,6 +240,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0200-0299/0230.Kth Smallest Element in a BST/README.md b/solution/0200-0299/0230.Kth Smallest Element in a BST/README.md index 2553dcd6d062d..1280d7c978211 100644 --- a/solution/0200-0299/0230.Kth Smallest Element in a BST/README.md +++ b/solution/0200-0299/0230.Kth Smallest Element in a BST/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -87,6 +89,8 @@ class Solution: root = root.right ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -184,6 +192,8 @@ func kthSmallest(root *TreeNode, k int) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -219,6 +229,8 @@ function kthSmallest(root: TreeNode | null, k: number): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -275,6 +287,8 @@ impl Solution { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -316,6 +330,8 @@ class Solution: return bst.kthSmallest(k) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -376,6 +392,8 @@ class BST { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -430,6 +448,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0200-0299/0230.Kth Smallest Element in a BST/README_EN.md b/solution/0200-0299/0230.Kth Smallest Element in a BST/README_EN.md index ff4907756141d..a77e519a41a4a 100644 --- a/solution/0200-0299/0230.Kth Smallest Element in a BST/README_EN.md +++ b/solution/0200-0299/0230.Kth Smallest Element in a BST/README_EN.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -80,6 +82,8 @@ class Solution: root = root.right ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -177,6 +185,8 @@ func kthSmallest(root *TreeNode, k int) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -212,6 +222,8 @@ function kthSmallest(root: TreeNode | null, k: number): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -264,6 +276,8 @@ impl Solution { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -305,6 +319,8 @@ class Solution: return bst.kthSmallest(k) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -365,6 +381,8 @@ class BST { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -419,6 +437,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0200-0299/0231.Power of Two/README.md b/solution/0200-0299/0231.Power of Two/README.md index 1859dbce233b2..123794f747746 100644 --- a/solution/0200-0299/0231.Power of Two/README.md +++ b/solution/0200-0299/0231.Power of Two/README.md @@ -71,12 +71,16 @@ $\texttt{n\&(n-1)}$ 可将最后一个二进制形式的 $n$ 的最后一位 $1$ +#### Python3 + ```python class Solution: def isPowerOfTwo(self, n: int) -> bool: return n > 0 and (n & (n - 1)) == 0 ``` +#### Java + ```java class Solution { public boolean isPowerOfTwo(int n) { @@ -85,6 +89,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -94,18 +100,24 @@ public: }; ``` +#### Go + ```go func isPowerOfTwo(n int) bool { return n > 0 && (n&(n-1)) == 0 } ``` +#### TypeScript + ```ts function isPowerOfTwo(n: number): boolean { return n > 0 && (n & (n - 1)) === 0; } ``` +#### JavaScript + ```js /** * @param {number} n @@ -130,12 +142,16 @@ $\texttt{n\&(-n)}$ 可以得到 $n$ 的最后一位 $1$ 表示的十进制数, +#### Python3 + ```python class Solution: def isPowerOfTwo(self, n: int) -> bool: return n > 0 and n == n & (-n) ``` +#### Java + ```java class Solution { public boolean isPowerOfTwo(int n) { @@ -144,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,18 +171,24 @@ public: }; ``` +#### Go + ```go func isPowerOfTwo(n int) bool { return n > 0 && n == (n&(-n)) } ``` +#### TypeScript + ```ts function isPowerOfTwo(n: number): boolean { return n > 0 && (n & (n - 1)) === 0; } ``` +#### JavaScript + ```js /** * @param {number} n diff --git a/solution/0200-0299/0231.Power of Two/README_EN.md b/solution/0200-0299/0231.Power of Two/README_EN.md index 6a2b5c8ca76d4..53b22983ca354 100644 --- a/solution/0200-0299/0231.Power of Two/README_EN.md +++ b/solution/0200-0299/0231.Power of Two/README_EN.md @@ -66,12 +66,16 @@ tags: +#### Python3 + ```python class Solution: def isPowerOfTwo(self, n: int) -> bool: return n > 0 and (n & (n - 1)) == 0 ``` +#### Java + ```java class Solution { public boolean isPowerOfTwo(int n) { @@ -80,6 +84,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -89,18 +95,24 @@ public: }; ``` +#### Go + ```go func isPowerOfTwo(n int) bool { return n > 0 && (n&(n-1)) == 0 } ``` +#### TypeScript + ```ts function isPowerOfTwo(n: number): boolean { return n > 0 && (n & (n - 1)) === 0; } ``` +#### JavaScript + ```js /** * @param {number} n @@ -121,12 +133,16 @@ var isPowerOfTwo = function (n) { +#### Python3 + ```python class Solution: def isPowerOfTwo(self, n: int) -> bool: return n > 0 and n == n & (-n) ``` +#### Java + ```java class Solution { public boolean isPowerOfTwo(int n) { @@ -135,6 +151,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,18 +162,24 @@ public: }; ``` +#### Go + ```go func isPowerOfTwo(n int) bool { return n > 0 && n == (n&(-n)) } ``` +#### TypeScript + ```ts function isPowerOfTwo(n: number): boolean { return n > 0 && (n & (n - 1)) === 0; } ``` +#### JavaScript + ```js /** * @param {number} n diff --git a/solution/0200-0299/0232.Implement Queue using Stacks/README.md b/solution/0200-0299/0232.Implement Queue using Stacks/README.md index c351e7ed8142c..7ebcdb3ffad05 100644 --- a/solution/0200-0299/0232.Implement Queue using Stacks/README.md +++ b/solution/0200-0299/0232.Implement Queue using Stacks/README.md @@ -97,6 +97,8 @@ myQueue.empty(); // return false +#### Python3 + ```python class MyQueue: def __init__(self): @@ -131,6 +133,8 @@ class MyQueue: # param_4 = obj.empty() ``` +#### Java + ```java class MyQueue { private Deque stk1 = new ArrayDeque<>(); @@ -176,6 +180,8 @@ class MyQueue { */ ``` +#### C++ + ```cpp class MyQueue { public: @@ -226,6 +232,8 @@ private: */ ``` +#### Go + ```go type MyQueue struct { stk1 []int @@ -275,6 +283,8 @@ func (this *MyQueue) move() { */ ``` +#### TypeScript + ```ts class MyQueue { stk1: number[]; @@ -322,6 +332,8 @@ class MyQueue { */ ``` +#### Rust + ```rust use std::collections::VecDeque; diff --git a/solution/0200-0299/0232.Implement Queue using Stacks/README_EN.md b/solution/0200-0299/0232.Implement Queue using Stacks/README_EN.md index ad6f12693701b..fab409a98d5fc 100644 --- a/solution/0200-0299/0232.Implement Queue using Stacks/README_EN.md +++ b/solution/0200-0299/0232.Implement Queue using Stacks/README_EN.md @@ -87,6 +87,8 @@ When checking whether the queue is empty, we only need to check whether both sta +#### Python3 + ```python class MyQueue: def __init__(self): @@ -121,6 +123,8 @@ class MyQueue: # param_4 = obj.empty() ``` +#### Java + ```java class MyQueue { private Deque stk1 = new ArrayDeque<>(); @@ -166,6 +170,8 @@ class MyQueue { */ ``` +#### C++ + ```cpp class MyQueue { public: @@ -216,6 +222,8 @@ private: */ ``` +#### Go + ```go type MyQueue struct { stk1 []int @@ -265,6 +273,8 @@ func (this *MyQueue) move() { */ ``` +#### TypeScript + ```ts class MyQueue { stk1: number[]; @@ -312,6 +322,8 @@ class MyQueue { */ ``` +#### Rust + ```rust use std::collections::VecDeque; diff --git a/solution/0200-0299/0233.Number of Digit One/README.md b/solution/0200-0299/0233.Number of Digit One/README.md index 9513f19757e92..b19b463b2cd70 100644 --- a/solution/0200-0299/0233.Number of Digit One/README.md +++ b/solution/0200-0299/0233.Number of Digit One/README.md @@ -90,6 +90,8 @@ $$ +#### Python3 + ```python class Solution: def countDigitOne(self, n: int) -> int: @@ -112,6 +114,8 @@ class Solution: return dfs(l, 0, True) ``` +#### Java + ```java class Solution { private int[] a = new int[12]; @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -185,6 +191,8 @@ public: }; ``` +#### Go + ```go func countDigitOne(n int) int { a := make([]int, 12) @@ -230,6 +238,8 @@ func countDigitOne(n int) int { } ``` +#### C# + ```cs public class Solution { public int CountDigitOne(int n) { diff --git a/solution/0200-0299/0233.Number of Digit One/README_EN.md b/solution/0200-0299/0233.Number of Digit One/README_EN.md index 9506d9a880feb..f5bfe5b0ec3e0 100644 --- a/solution/0200-0299/0233.Number of Digit One/README_EN.md +++ b/solution/0200-0299/0233.Number of Digit One/README_EN.md @@ -52,6 +52,8 @@ tags: +#### Python3 + ```python class Solution: def countDigitOne(self, n: int) -> int: @@ -74,6 +76,8 @@ class Solution: return dfs(l, 0, True) ``` +#### Java + ```java class Solution { private int[] a = new int[12]; @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func countDigitOne(n int) int { a := make([]int, 12) @@ -192,6 +200,8 @@ func countDigitOne(n int) int { } ``` +#### C# + ```cs public class Solution { public int CountDigitOne(int n) { diff --git a/solution/0200-0299/0234.Palindrome Linked List/README.md b/solution/0200-0299/0234.Palindrome Linked List/README.md index 1a13f16e9f20b..c6ae9c84a2c3b 100644 --- a/solution/0200-0299/0234.Palindrome Linked List/README.md +++ b/solution/0200-0299/0234.Palindrome Linked List/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -87,6 +89,8 @@ class Solution: return True ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -196,6 +204,8 @@ func isPalindrome(head *ListNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -234,6 +244,8 @@ function isPalindrome(head: ListNode | null): boolean { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -273,6 +285,8 @@ var isPalindrome = function (head) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. diff --git a/solution/0200-0299/0234.Palindrome Linked List/README_EN.md b/solution/0200-0299/0234.Palindrome Linked List/README_EN.md index 4b19b3d1b7bea..579cc97d75c93 100644 --- a/solution/0200-0299/0234.Palindrome Linked List/README_EN.md +++ b/solution/0200-0299/0234.Palindrome Linked List/README_EN.md @@ -57,6 +57,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -80,6 +82,8 @@ class Solution: return True ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -189,6 +197,8 @@ func isPalindrome(head *ListNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -227,6 +237,8 @@ function isPalindrome(head: ListNode | null): boolean { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -266,6 +278,8 @@ var isPalindrome = function (head) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. diff --git a/solution/0200-0299/0235.Lowest Common Ancestor of a Binary Search Tree/README.md b/solution/0200-0299/0235.Lowest Common Ancestor of a Binary Search Tree/README.md index 1a2dc86b79371..31998e5c3308e 100644 --- a/solution/0200-0299/0235.Lowest Common Ancestor of a Binary Search Tree/README.md +++ b/solution/0200-0299/0235.Lowest Common Ancestor of a Binary Search Tree/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -91,6 +93,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -167,6 +175,8 @@ func lowestCommonAncestor(root, p, q *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -209,6 +219,8 @@ function lowestCommonAncestor( +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -229,6 +241,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -253,6 +267,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -278,6 +294,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -299,6 +317,8 @@ func lowestCommonAncestor(root, p, q *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0200-0299/0235.Lowest Common Ancestor of a Binary Search Tree/README_EN.md b/solution/0200-0299/0235.Lowest Common Ancestor of a Binary Search Tree/README_EN.md index d1ccd80fb6bfb..9e5d7066ef095 100644 --- a/solution/0200-0299/0235.Lowest Common Ancestor of a Binary Search Tree/README_EN.md +++ b/solution/0200-0299/0235.Lowest Common Ancestor of a Binary Search Tree/README_EN.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -90,6 +92,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -166,6 +174,8 @@ func lowestCommonAncestor(root, p, q *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -208,6 +218,8 @@ function lowestCommonAncestor( +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -228,6 +240,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -252,6 +266,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -277,6 +293,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -298,6 +316,8 @@ func lowestCommonAncestor(root, p, q *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0200-0299/0236.Lowest Common Ancestor of a Binary Tree/README.md b/solution/0200-0299/0236.Lowest Common Ancestor of a Binary Tree/README.md index 75bfa7390251f..d58c4b9bd3c6d 100644 --- a/solution/0200-0299/0236.Lowest Common Ancestor of a Binary Tree/README.md +++ b/solution/0200-0299/0236.Lowest Common Ancestor of a Binary Tree/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -97,6 +99,8 @@ class Solution: return root if left and right else (left or right) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -173,6 +181,8 @@ func lowestCommonAncestor(root, p, q *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -202,6 +212,8 @@ function lowestCommonAncestor( } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -253,6 +265,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0200-0299/0236.Lowest Common Ancestor of a Binary Tree/README_EN.md b/solution/0200-0299/0236.Lowest Common Ancestor of a Binary Tree/README_EN.md index 04c29174e0643..af6711a273066 100644 --- a/solution/0200-0299/0236.Lowest Common Ancestor of a Binary Tree/README_EN.md +++ b/solution/0200-0299/0236.Lowest Common Ancestor of a Binary Tree/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -95,6 +97,8 @@ class Solution: return root if left and right else (left or right) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -171,6 +179,8 @@ func lowestCommonAncestor(root, p, q *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -200,6 +210,8 @@ function lowestCommonAncestor( } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -251,6 +263,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0200-0299/0237.Delete Node in a Linked List/README.md b/solution/0200-0299/0237.Delete Node in a Linked List/README.md index 11c08bf4f33f5..2510b306096a9 100644 --- a/solution/0200-0299/0237.Delete Node in a Linked List/README.md +++ b/solution/0200-0299/0237.Delete Node in a Linked List/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -99,6 +101,8 @@ class Solution: node.next = node.next.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -148,6 +156,8 @@ func deleteNode(node *ListNode) { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -170,6 +180,8 @@ function deleteNode(node: ListNode | null): void { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -188,6 +200,8 @@ var deleteNode = function (node) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. @@ -205,6 +219,8 @@ public class Solution { } ``` +#### C + ```c /** * Definition for singly-linked list. diff --git a/solution/0200-0299/0237.Delete Node in a Linked List/README_EN.md b/solution/0200-0299/0237.Delete Node in a Linked List/README_EN.md index e701f60a8ee1c..4945ae23bb757 100644 --- a/solution/0200-0299/0237.Delete Node in a Linked List/README_EN.md +++ b/solution/0200-0299/0237.Delete Node in a Linked List/README_EN.md @@ -80,6 +80,8 @@ Time complexity $O(1)$, space complexity $O(1)$. +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -98,6 +100,8 @@ class Solution: node.next = node.next.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -147,6 +155,8 @@ func deleteNode(node *ListNode) { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -169,6 +179,8 @@ function deleteNode(node: ListNode | null): void { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -187,6 +199,8 @@ var deleteNode = function (node) { }; ``` +#### C# + ```cs /** * Definition for singly-linked list. @@ -204,6 +218,8 @@ public class Solution { } ``` +#### C + ```c /** * Definition for singly-linked list. diff --git a/solution/0200-0299/0238.Product of Array Except Self/README.md b/solution/0200-0299/0238.Product of Array Except Self/README.md index d3158d980da08..a30b7000a034c 100644 --- a/solution/0200-0299/0238.Product of Array Except Self/README.md +++ b/solution/0200-0299/0238.Product of Array Except Self/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def productExceptSelf(self, nums: List[int]) -> List[int]: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] productExceptSelf(int[] nums) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func productExceptSelf(nums []int) []int { n := len(nums) @@ -142,6 +150,8 @@ func productExceptSelf(nums []int) []int { } ``` +#### TypeScript + ```ts function productExceptSelf(nums: number[]): number[] { const n = nums.length; @@ -158,6 +168,8 @@ function productExceptSelf(nums: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn product_except_self(nums: Vec) -> Vec { @@ -176,6 +188,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -196,6 +210,8 @@ var productExceptSelf = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int[] ProductExceptSelf(int[] nums) { @@ -214,6 +230,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** @@ -246,6 +264,8 @@ class Solution { +#### TypeScript + ```ts function productExceptSelf(nums: number[]): number[] { return nums.map((_, i) => nums.reduce((pre, val, j) => pre * (i === j ? 1 : val), 1)); diff --git a/solution/0200-0299/0238.Product of Array Except Self/README_EN.md b/solution/0200-0299/0238.Product of Array Except Self/README_EN.md index 04b44f6d1e4a7..646950a83f675 100644 --- a/solution/0200-0299/0238.Product of Array Except Self/README_EN.md +++ b/solution/0200-0299/0238.Product of Array Except Self/README_EN.md @@ -63,6 +63,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array `nums`. Igno +#### Python3 + ```python class Solution: def productExceptSelf(self, nums: List[int]) -> List[int]: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] productExceptSelf(int[] nums) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func productExceptSelf(nums []int) []int { n := len(nums) @@ -132,6 +140,8 @@ func productExceptSelf(nums []int) []int { } ``` +#### TypeScript + ```ts function productExceptSelf(nums: number[]): number[] { const n = nums.length; @@ -148,6 +158,8 @@ function productExceptSelf(nums: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn product_except_self(nums: Vec) -> Vec { @@ -166,6 +178,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -186,6 +200,8 @@ var productExceptSelf = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int[] ProductExceptSelf(int[] nums) { @@ -204,6 +220,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** @@ -236,6 +254,8 @@ class Solution { +#### TypeScript + ```ts function productExceptSelf(nums: number[]): number[] { return nums.map((_, i) => nums.reduce((pre, val, j) => pre * (i === j ? 1 : val), 1)); diff --git a/solution/0200-0299/0239.Sliding Window Maximum/README.md b/solution/0200-0299/0239.Sliding Window Maximum/README.md index 10ba103f150c4..fed5907c2b121 100644 --- a/solution/0200-0299/0239.Sliding Window Maximum/README.md +++ b/solution/0200-0299/0239.Sliding Window Maximum/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] maxSlidingWindow(int[] nums, int k) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func maxSlidingWindow(nums []int, k int) (ans []int) { q := hp{} @@ -163,6 +171,8 @@ func (h *hp) Push(v any) { *h = append(*h, v.(pair)) } func (h *hp) Pop() any { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; return v } ``` +#### Rust + ```rust use std::collections::VecDeque; @@ -197,6 +207,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -222,6 +234,8 @@ var maxSlidingWindow = function (nums, k) { }; ``` +#### C# + ```cs using System.Collections.Generic; @@ -276,6 +290,8 @@ for i in range(n): +#### Python3 + ```python class Solution: def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]: @@ -292,6 +308,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] maxSlidingWindow(int[] nums, int k) { @@ -315,6 +333,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -338,6 +358,8 @@ public: }; ``` +#### Go + ```go func maxSlidingWindow(nums []int, k int) (ans []int) { q := []int{} diff --git a/solution/0200-0299/0239.Sliding Window Maximum/README_EN.md b/solution/0200-0299/0239.Sliding Window Maximum/README_EN.md index cf6ae4156ac3e..9825d89ad0e11 100644 --- a/solution/0200-0299/0239.Sliding Window Maximum/README_EN.md +++ b/solution/0200-0299/0239.Sliding Window Maximum/README_EN.md @@ -67,6 +67,8 @@ Window position Max +#### Python3 + ```python class Solution: def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] maxSlidingWindow(int[] nums, int k) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func maxSlidingWindow(nums []int, k int) (ans []int) { q := hp{} @@ -155,6 +163,8 @@ func (h *hp) Push(v any) { *h = append(*h, v.(pair)) } func (h *hp) Pop() any { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; return v } ``` +#### Rust + ```rust use std::collections::VecDeque; @@ -189,6 +199,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -214,6 +226,8 @@ var maxSlidingWindow = function (nums, k) { }; ``` +#### C# + ```cs using System.Collections.Generic; @@ -253,6 +267,8 @@ public class Solution { +#### Python3 + ```python class Solution: def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]: @@ -269,6 +285,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] maxSlidingWindow(int[] nums, int k) { @@ -292,6 +310,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -315,6 +335,8 @@ public: }; ``` +#### Go + ```go func maxSlidingWindow(nums []int, k int) (ans []int) { q := []int{} diff --git a/solution/0200-0299/0240.Search a 2D Matrix II/README.md b/solution/0200-0299/0240.Search a 2D Matrix II/README.md index 2eaeff6962ae0..278faf4bff982 100644 --- a/solution/0200-0299/0240.Search a 2D Matrix II/README.md +++ b/solution/0200-0299/0240.Search a 2D Matrix II/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: @@ -82,6 +84,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean searchMatrix(int[][] matrix, int target) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func searchMatrix(matrix [][]int, target int) bool { for _, row := range matrix { @@ -123,6 +131,8 @@ func searchMatrix(matrix [][]int, target int) bool { } ``` +#### TypeScript + ```ts function searchMatrix(matrix: number[][], target: number): boolean { const n = matrix[0].length; @@ -145,6 +155,8 @@ function searchMatrix(matrix: number[][], target: number): boolean { } ``` +#### Rust + ```rust use std::cmp::Ordering; @@ -172,6 +184,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix @@ -199,6 +213,8 @@ var searchMatrix = function (matrix, target) { }; ``` +#### C# + ```cs public class Solution { public bool SearchMatrix(int[][] matrix, int target) { @@ -233,6 +249,8 @@ public class Solution { +#### Python3 + ```python class Solution: def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: @@ -248,6 +266,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean searchMatrix(int[][] matrix, int target) { @@ -268,6 +288,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -289,6 +311,8 @@ public: }; ``` +#### Go + ```go func searchMatrix(matrix [][]int, target int) bool { m, n := len(matrix), len(matrix[0]) @@ -307,6 +331,8 @@ func searchMatrix(matrix [][]int, target int) bool { } ``` +#### TypeScript + ```ts function searchMatrix(matrix: number[][], target: number): boolean { const [m, n] = [matrix.length, matrix[0].length]; @@ -325,6 +351,8 @@ function searchMatrix(matrix: number[][], target: number): boolean { } ``` +#### C# + ```cs public class Solution { public bool SearchMatrix(int[][] matrix, int target) { diff --git a/solution/0200-0299/0240.Search a 2D Matrix II/README_EN.md b/solution/0200-0299/0240.Search a 2D Matrix II/README_EN.md index 40dd4a6d5a8df..1f1f8a46be5ef 100644 --- a/solution/0200-0299/0240.Search a 2D Matrix II/README_EN.md +++ b/solution/0200-0299/0240.Search a 2D Matrix II/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(m \times \log n)$, where $m$ and $n$ are the number of +#### Python3 + ```python class Solution: def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: @@ -80,6 +82,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean searchMatrix(int[][] matrix, int target) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func searchMatrix(matrix [][]int, target int) bool { for _, row := range matrix { @@ -121,6 +129,8 @@ func searchMatrix(matrix [][]int, target int) bool { } ``` +#### TypeScript + ```ts function searchMatrix(matrix: number[][], target: number): boolean { const n = matrix[0].length; @@ -143,6 +153,8 @@ function searchMatrix(matrix: number[][], target: number): boolean { } ``` +#### Rust + ```rust use std::cmp::Ordering; @@ -170,6 +182,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix @@ -197,6 +211,8 @@ var searchMatrix = function (matrix, target) { }; ``` +#### C# + ```cs public class Solution { public bool SearchMatrix(int[][] matrix, int target) { @@ -231,6 +247,8 @@ The time complexity is $O(m + n)$, where $m$ and $n$ are the number of rows and +#### Python3 + ```python class Solution: def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: @@ -246,6 +264,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean searchMatrix(int[][] matrix, int target) { @@ -266,6 +286,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -287,6 +309,8 @@ public: }; ``` +#### Go + ```go func searchMatrix(matrix [][]int, target int) bool { m, n := len(matrix), len(matrix[0]) @@ -305,6 +329,8 @@ func searchMatrix(matrix [][]int, target int) bool { } ``` +#### TypeScript + ```ts function searchMatrix(matrix: number[][], target: number): boolean { const [m, n] = [matrix.length, matrix[0].length]; @@ -323,6 +349,8 @@ function searchMatrix(matrix: number[][], target: number): boolean { } ``` +#### C# + ```cs public class Solution { public bool SearchMatrix(int[][] matrix, int target) { diff --git a/solution/0200-0299/0241.Different Ways to Add Parentheses/README.md b/solution/0200-0299/0241.Different Ways to Add Parentheses/README.md index 3a9cbbbc4867a..1df2c504fbd90 100644 --- a/solution/0200-0299/0241.Different Ways to Add Parentheses/README.md +++ b/solution/0200-0299/0241.Different Ways to Add Parentheses/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def diffWaysToCompute(self, expression: str) -> List[int]: @@ -93,6 +95,8 @@ class Solution: return dfs(expression) ``` +#### Java + ```java class Solution { private static Map> memo = new HashMap<>(); @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -172,6 +178,8 @@ private: }; ``` +#### Go + ```go var memo = map[string][]int{} @@ -209,6 +217,8 @@ func dfs(exp string) []int { } ``` +#### C# + ```cs using System.Collections.Generic; diff --git a/solution/0200-0299/0241.Different Ways to Add Parentheses/README_EN.md b/solution/0200-0299/0241.Different Ways to Add Parentheses/README_EN.md index 3d885ddd23a0d..894e83e1a5bd3 100644 --- a/solution/0200-0299/0241.Different Ways to Add Parentheses/README_EN.md +++ b/solution/0200-0299/0241.Different Ways to Add Parentheses/README_EN.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def diffWaysToCompute(self, expression: str) -> List[int]: @@ -91,6 +93,8 @@ class Solution: return dfs(expression) ``` +#### Java + ```java class Solution { private static Map> memo = new HashMap<>(); @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -170,6 +176,8 @@ private: }; ``` +#### Go + ```go var memo = map[string][]int{} @@ -207,6 +215,8 @@ func dfs(exp string) []int { } ``` +#### C# + ```cs using System.Collections.Generic; diff --git a/solution/0200-0299/0242.Valid Anagram/README.md b/solution/0200-0299/0242.Valid Anagram/README.md index 899e585e5cc5c..45b5a4d81a9c8 100644 --- a/solution/0200-0299/0242.Valid Anagram/README.md +++ b/solution/0200-0299/0242.Valid Anagram/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def isAnagram(self, s: str, t: str) -> bool: @@ -79,6 +81,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isAnagram(String s, String t) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func isAnagram(s string, t string) bool { if len(s) != len(t) { @@ -136,6 +144,8 @@ func isAnagram(s string, t string) bool { } ``` +#### TypeScript + ```ts function isAnagram(s: string, t: string): boolean { if (s.length !== t.length) { @@ -150,6 +160,8 @@ function isAnagram(s: string, t: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn is_anagram(s: String, t: String) -> bool { @@ -172,6 +184,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -191,6 +205,8 @@ var isAnagram = function (s, t) { }; ``` +#### C# + ```cs public class Solution { public bool IsAnagram(string s, string t) { @@ -207,6 +223,8 @@ public class Solution { } ``` +#### C + ```c int cmp(const void* a, const void* b) { return *(char*) a - *(char*) b; @@ -234,12 +252,16 @@ bool isAnagram(char* s, char* t) { +#### Python3 + ```python class Solution: def isAnagram(self, s: str, t: str) -> bool: return Counter(s) == Counter(t) ``` +#### Rust + ```rust impl Solution { pub fn is_anagram(s: String, t: String) -> bool { @@ -259,6 +281,8 @@ impl Solution { } ``` +#### C + ```c bool isAnagram(char* s, char* t) { int n = strlen(s); diff --git a/solution/0200-0299/0242.Valid Anagram/README_EN.md b/solution/0200-0299/0242.Valid Anagram/README_EN.md index 5c0f755257243..69e35ae8d1379 100644 --- a/solution/0200-0299/0242.Valid Anagram/README_EN.md +++ b/solution/0200-0299/0242.Valid Anagram/README_EN.md @@ -57,6 +57,8 @@ The time complexity is $O(n)$, the space complexity is $O(C)$, where $n$ is the +#### Python3 + ```python class Solution: def isAnagram(self, s: str, t: str) -> bool: @@ -70,6 +72,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isAnagram(String s, String t) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func isAnagram(s string, t string) bool { if len(s) != len(t) { @@ -127,6 +135,8 @@ func isAnagram(s string, t string) bool { } ``` +#### TypeScript + ```ts function isAnagram(s: string, t: string): boolean { if (s.length !== t.length) { @@ -141,6 +151,8 @@ function isAnagram(s: string, t: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn is_anagram(s: String, t: String) -> bool { @@ -163,6 +175,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -182,6 +196,8 @@ var isAnagram = function (s, t) { }; ``` +#### C# + ```cs public class Solution { public bool IsAnagram(string s, string t) { @@ -198,6 +214,8 @@ public class Solution { } ``` +#### C + ```c int cmp(const void* a, const void* b) { return *(char*) a - *(char*) b; @@ -225,12 +243,16 @@ bool isAnagram(char* s, char* t) { +#### Python3 + ```python class Solution: def isAnagram(self, s: str, t: str) -> bool: return Counter(s) == Counter(t) ``` +#### Rust + ```rust impl Solution { pub fn is_anagram(s: String, t: String) -> bool { @@ -250,6 +272,8 @@ impl Solution { } ``` +#### C + ```c bool isAnagram(char* s, char* t) { int n = strlen(s); diff --git a/solution/0200-0299/0243.Shortest Word Distance/README.md b/solution/0200-0299/0243.Shortest Word Distance/README.md index 79183f19262fb..70e90be338667 100644 --- a/solution/0200-0299/0243.Shortest Word Distance/README.md +++ b/solution/0200-0299/0243.Shortest Word Distance/README.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def shortestDistance(self, wordsDict: List[str], word1: str, word2: str) -> int: @@ -75,6 +77,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int shortestDistance(String[] wordsDict, String word1, String word2) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func shortestDistance(wordsDict []string, word1 string, word2 string) int { ans := 0x3f3f3f3f diff --git a/solution/0200-0299/0243.Shortest Word Distance/README_EN.md b/solution/0200-0299/0243.Shortest Word Distance/README_EN.md index ad515bc17079c..65c754bebd969 100644 --- a/solution/0200-0299/0243.Shortest Word Distance/README_EN.md +++ b/solution/0200-0299/0243.Shortest Word Distance/README_EN.md @@ -55,6 +55,8 @@ tags: +#### Python3 + ```python class Solution: def shortestDistance(self, wordsDict: List[str], word1: str, word2: str) -> int: @@ -70,6 +72,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int shortestDistance(String[] wordsDict, String word1, String word2) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func shortestDistance(wordsDict []string, word1 string, word2 string) int { ans := 0x3f3f3f3f diff --git a/solution/0200-0299/0244.Shortest Word Distance II/README.md b/solution/0200-0299/0244.Shortest Word Distance II/README.md index 562afcd544a76..bb158399083ec 100644 --- a/solution/0200-0299/0244.Shortest Word Distance II/README.md +++ b/solution/0200-0299/0244.Shortest Word Distance II/README.md @@ -72,6 +72,8 @@ wordDistance.shortest("makes", "coding"); // 返回 1 +#### Python3 + ```python class WordDistance: def __init__(self, wordsDict: List[str]): @@ -97,6 +99,8 @@ class WordDistance: # param_1 = obj.shortest(word1,word2) ``` +#### Java + ```java class WordDistance { private Map> d = new HashMap<>(); @@ -130,6 +134,8 @@ class WordDistance { */ ``` +#### C++ + ```cpp class WordDistance { public: @@ -165,6 +171,8 @@ private: */ ``` +#### Go + ```go type WordDistance struct { d map[string][]int diff --git a/solution/0200-0299/0244.Shortest Word Distance II/README_EN.md b/solution/0200-0299/0244.Shortest Word Distance II/README_EN.md index 2c21d172da99a..3711188dc13e9 100644 --- a/solution/0200-0299/0244.Shortest Word Distance II/README_EN.md +++ b/solution/0200-0299/0244.Shortest Word Distance II/README_EN.md @@ -67,6 +67,8 @@ wordDistance.shortest("makes", "coding"); // return 1 +#### Python3 + ```python class WordDistance: def __init__(self, wordsDict: List[str]): @@ -92,6 +94,8 @@ class WordDistance: # param_1 = obj.shortest(word1,word2) ``` +#### Java + ```java class WordDistance { private Map> d = new HashMap<>(); @@ -125,6 +129,8 @@ class WordDistance { */ ``` +#### C++ + ```cpp class WordDistance { public: @@ -160,6 +166,8 @@ private: */ ``` +#### Go + ```go type WordDistance struct { d map[string][]int diff --git a/solution/0200-0299/0245.Shortest Word Distance III/README.md b/solution/0200-0299/0245.Shortest Word Distance III/README.md index 613ce915076de..51d9475fc32ee 100644 --- a/solution/0200-0299/0245.Shortest Word Distance III/README.md +++ b/solution/0200-0299/0245.Shortest Word Distance III/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def shortestWordDistance(self, wordsDict: List[str], word1: str, word2: str) -> int: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int shortestWordDistance(String[] wordsDict, String word1, String word2) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func shortestWordDistance(wordsDict []string, word1 string, word2 string) int { ans := len(wordsDict) diff --git a/solution/0200-0299/0245.Shortest Word Distance III/README_EN.md b/solution/0200-0299/0245.Shortest Word Distance III/README_EN.md index 5a2a69d9d7818..72ab891b39ce6 100644 --- a/solution/0200-0299/0245.Shortest Word Distance III/README_EN.md +++ b/solution/0200-0299/0245.Shortest Word Distance III/README_EN.md @@ -49,6 +49,8 @@ tags: +#### Python3 + ```python class Solution: def shortestWordDistance(self, wordsDict: List[str], word1: str, word2: str) -> int: @@ -72,6 +74,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int shortestWordDistance(String[] wordsDict, String word1, String word2) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func shortestWordDistance(wordsDict []string, word1 string, word2 string) int { ans := len(wordsDict) diff --git a/solution/0200-0299/0246.Strobogrammatic Number/README.md b/solution/0200-0299/0246.Strobogrammatic Number/README.md index 847259b786b86..dd775a3fe9907 100644 --- a/solution/0200-0299/0246.Strobogrammatic Number/README.md +++ b/solution/0200-0299/0246.Strobogrammatic Number/README.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def isStrobogrammatic(self, num: str) -> bool: @@ -75,6 +77,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isStrobogrammatic(String num) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func isStrobogrammatic(num string) bool { d := []int{0, 1, -1, -1, -1, -1, 9, -1, 8, 6} diff --git a/solution/0200-0299/0246.Strobogrammatic Number/README_EN.md b/solution/0200-0299/0246.Strobogrammatic Number/README_EN.md index 88708678c3383..c6a3632e4f01f 100644 --- a/solution/0200-0299/0246.Strobogrammatic Number/README_EN.md +++ b/solution/0200-0299/0246.Strobogrammatic Number/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string. The space +#### Python3 + ```python class Solution: def isStrobogrammatic(self, num: str) -> bool: @@ -82,6 +84,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isStrobogrammatic(String num) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func isStrobogrammatic(num string) bool { d := []int{0, 1, -1, -1, -1, -1, 9, -1, 8, 6} diff --git a/solution/0200-0299/0247.Strobogrammatic Number II/README.md b/solution/0200-0299/0247.Strobogrammatic Number II/README.md index 3656a56c505b6..3d2c1acf2f11c 100644 --- a/solution/0200-0299/0247.Strobogrammatic Number II/README.md +++ b/solution/0200-0299/0247.Strobogrammatic Number II/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def findStrobogrammatic(self, n: int) -> List[str]: @@ -92,6 +94,8 @@ class Solution: return dfs(n) ``` +#### Java + ```java class Solution { private static final int[][] PAIRS = {{1, 1}, {8, 8}, {6, 9}, {9, 6}}; @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func findStrobogrammatic(n int) []string { var dfs func(int) []string diff --git a/solution/0200-0299/0247.Strobogrammatic Number II/README_EN.md b/solution/0200-0299/0247.Strobogrammatic Number II/README_EN.md index 5e0bde6815daa..8faf5934e302d 100644 --- a/solution/0200-0299/0247.Strobogrammatic Number II/README_EN.md +++ b/solution/0200-0299/0247.Strobogrammatic Number II/README_EN.md @@ -65,6 +65,8 @@ Similar problems: +#### Python3 + ```python class Solution: def findStrobogrammatic(self, n: int) -> List[str]: @@ -84,6 +86,8 @@ class Solution: return dfs(n) ``` +#### Java + ```java class Solution { private static final int[][] PAIRS = {{1, 1}, {8, 8}, {6, 9}, {9, 6}}; @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func findStrobogrammatic(n int) []string { var dfs func(int) []string diff --git a/solution/0200-0299/0248.Strobogrammatic Number III/README.md b/solution/0200-0299/0248.Strobogrammatic Number III/README.md index bac42a2dd9ac5..055506c3b4d14 100644 --- a/solution/0200-0299/0248.Strobogrammatic Number III/README.md +++ b/solution/0200-0299/0248.Strobogrammatic Number III/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def strobogrammaticInRange(self, low: str, high: str) -> int: @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int[][] PAIRS = {{1, 1}, {8, 8}, {6, 9}, {9, 6}}; @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -184,6 +190,8 @@ public: }; ``` +#### Go + ```go func strobogrammaticInRange(low string, high string) int { n := 0 diff --git a/solution/0200-0299/0248.Strobogrammatic Number III/README_EN.md b/solution/0200-0299/0248.Strobogrammatic Number III/README_EN.md index 59838d441a0cf..22288186deabe 100644 --- a/solution/0200-0299/0248.Strobogrammatic Number III/README_EN.md +++ b/solution/0200-0299/0248.Strobogrammatic Number III/README_EN.md @@ -70,6 +70,8 @@ Similar problems: +#### Python3 + ```python class Solution: def strobogrammaticInRange(self, low: str, high: str) -> int: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int[][] PAIRS = {{1, 1}, {8, 8}, {6, 9}, {9, 6}}; @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go func strobogrammaticInRange(low string, high string) int { n := 0 diff --git a/solution/0200-0299/0249.Group Shifted Strings/README.md b/solution/0200-0299/0249.Group Shifted Strings/README.md index 105454f9b9ca9..1e93be07a78e5 100644 --- a/solution/0200-0299/0249.Group Shifted Strings/README.md +++ b/solution/0200-0299/0249.Group Shifted Strings/README.md @@ -56,6 +56,8 @@ tags: +#### Python3 + ```python class Solution: def groupStrings(self, strings: List[str]) -> List[List[str]]: @@ -72,6 +74,8 @@ class Solution: return list(g.values()) ``` +#### Java + ```java class Solution { public List> groupStrings(String[] strings) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func groupStrings(strings []string) [][]string { g := make(map[string][]string) diff --git a/solution/0200-0299/0249.Group Shifted Strings/README_EN.md b/solution/0200-0299/0249.Group Shifted Strings/README_EN.md index fb798039da47a..00c36408c6461 100644 --- a/solution/0200-0299/0249.Group Shifted Strings/README_EN.md +++ b/solution/0200-0299/0249.Group Shifted Strings/README_EN.md @@ -67,6 +67,8 @@ The time complexity is $O(L)$ and the space complexity is $O(L)$, where $L$ is t +#### Python3 + ```python class Solution: def groupStrings(self, strings: List[str]) -> List[List[str]]: @@ -83,6 +85,8 @@ class Solution: return list(g.values()) ``` +#### Java + ```java class Solution { public List> groupStrings(String[] strings) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func groupStrings(strings []string) [][]string { g := make(map[string][]string) diff --git a/solution/0200-0299/0250.Count Univalue Subtrees/README.md b/solution/0200-0299/0250.Count Univalue Subtrees/README.md index 8b33796c75821..5bb0e0bde10be 100644 --- a/solution/0200-0299/0250.Count Univalue Subtrees/README.md +++ b/solution/0200-0299/0250.Count Univalue Subtrees/README.md @@ -57,6 +57,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -201,6 +209,8 @@ func countUnivalSubtrees(root *TreeNode) (ans int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -241,6 +251,8 @@ function countUnivalSubtrees(root: TreeNode | null): number { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0200-0299/0250.Count Univalue Subtrees/README_EN.md b/solution/0200-0299/0250.Count Univalue Subtrees/README_EN.md index 780a3cac94b50..f3f93d84aea69 100644 --- a/solution/0200-0299/0250.Count Univalue Subtrees/README_EN.md +++ b/solution/0200-0299/0250.Count Univalue Subtrees/README_EN.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -206,6 +214,8 @@ func countUnivalSubtrees(root *TreeNode) (ans int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -246,6 +256,8 @@ function countUnivalSubtrees(root: TreeNode | null): number { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0200-0299/0251.Flatten 2D Vector/README.md b/solution/0200-0299/0251.Flatten 2D Vector/README.md index 0b422895a3b74..fa3c2b976b810 100644 --- a/solution/0200-0299/0251.Flatten 2D Vector/README.md +++ b/solution/0200-0299/0251.Flatten 2D Vector/README.md @@ -70,6 +70,8 @@ iterator.hasNext(); // 返回 false +#### Python3 + ```python class Vector2D: def __init__(self, vec: List[List[int]]): @@ -99,6 +101,8 @@ class Vector2D: # param_2 = obj.hasNext() ``` +#### Java + ```java class Vector2D { private int i; @@ -135,6 +139,8 @@ class Vector2D { */ ``` +#### C++ + ```cpp class Vector2D { public: @@ -173,6 +179,8 @@ private: */ ``` +#### Go + ```go type Vector2D struct { i, j int @@ -210,6 +218,8 @@ func (this *Vector2D) forward() { */ ``` +#### TypeScript + ```ts class Vector2D { i: number; diff --git a/solution/0200-0299/0251.Flatten 2D Vector/README_EN.md b/solution/0200-0299/0251.Flatten 2D Vector/README_EN.md index 613e1d6fcfc3a..3ae581e7d5928 100644 --- a/solution/0200-0299/0251.Flatten 2D Vector/README_EN.md +++ b/solution/0200-0299/0251.Flatten 2D Vector/README_EN.md @@ -73,6 +73,8 @@ vector2D.hasNext(); // return False +#### Python3 + ```python class Vector2D: def __init__(self, vec: List[List[int]]): @@ -102,6 +104,8 @@ class Vector2D: # param_2 = obj.hasNext() ``` +#### Java + ```java class Vector2D { private int i; @@ -138,6 +142,8 @@ class Vector2D { */ ``` +#### C++ + ```cpp class Vector2D { public: @@ -176,6 +182,8 @@ private: */ ``` +#### Go + ```go type Vector2D struct { i, j int @@ -213,6 +221,8 @@ func (this *Vector2D) forward() { */ ``` +#### TypeScript + ```ts class Vector2D { i: number; diff --git a/solution/0200-0299/0252.Meeting Rooms/README.md b/solution/0200-0299/0252.Meeting Rooms/README.md index e851d9dfb7be0..fedda275b8ca1 100644 --- a/solution/0200-0299/0252.Meeting Rooms/README.md +++ b/solution/0200-0299/0252.Meeting Rooms/README.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def canAttendMeetings(self, intervals: List[List[int]]) -> bool: @@ -68,6 +70,8 @@ class Solution: return all(a[1] <= b[0] for a, b in pairwise(intervals)) ``` +#### Java + ```java class Solution { public boolean canAttendMeetings(int[][] intervals) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,6 +107,8 @@ public: }; ``` +#### Go + ```go func canAttendMeetings(intervals [][]int) bool { sort.Slice(intervals, func(i, j int) bool { @@ -115,6 +123,8 @@ func canAttendMeetings(intervals [][]int) bool { } ``` +#### TypeScript + ```ts function canAttendMeetings(intervals: number[][]): boolean { intervals.sort((a, b) => a[0] - b[0]); @@ -127,6 +137,8 @@ function canAttendMeetings(intervals: number[][]): boolean { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/0200-0299/0252.Meeting Rooms/README_EN.md b/solution/0200-0299/0252.Meeting Rooms/README_EN.md index f489d3172c34b..696d1785ead4a 100644 --- a/solution/0200-0299/0252.Meeting Rooms/README_EN.md +++ b/solution/0200-0299/0252.Meeting Rooms/README_EN.md @@ -46,6 +46,8 @@ tags: +#### Python3 + ```python class Solution: def canAttendMeetings(self, intervals: List[List[int]]) -> bool: @@ -53,6 +55,8 @@ class Solution: return all(a[1] <= b[0] for a, b in pairwise(intervals)) ``` +#### Java + ```java class Solution { public boolean canAttendMeetings(int[][] intervals) { @@ -69,6 +73,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -86,6 +92,8 @@ public: }; ``` +#### Go + ```go func canAttendMeetings(intervals [][]int) bool { sort.Slice(intervals, func(i, j int) bool { @@ -100,6 +108,8 @@ func canAttendMeetings(intervals [][]int) bool { } ``` +#### TypeScript + ```ts function canAttendMeetings(intervals: number[][]): boolean { intervals.sort((a, b) => a[0] - b[0]); @@ -112,6 +122,8 @@ function canAttendMeetings(intervals: number[][]): boolean { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/0200-0299/0253.Meeting Rooms II/README.md b/solution/0200-0299/0253.Meeting Rooms II/README.md index 69c4e37e0e790..f1ab17fff9b2f 100644 --- a/solution/0200-0299/0253.Meeting Rooms II/README.md +++ b/solution/0200-0299/0253.Meeting Rooms II/README.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python class Solution: def minMeetingRooms(self, intervals: List[List[int]]) -> int: @@ -68,6 +70,8 @@ class Solution: return max(accumulate(delta)) ``` +#### Java + ```java class Solution { public int minMeetingRooms(int[][] intervals) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func minMeetingRooms(intervals [][]int) int { n := 1000010 @@ -120,6 +128,8 @@ func minMeetingRooms(intervals [][]int) int { } ``` +#### Rust + ```rust use std::{ collections::BinaryHeap, cmp::Reverse }; diff --git a/solution/0200-0299/0253.Meeting Rooms II/README_EN.md b/solution/0200-0299/0253.Meeting Rooms II/README_EN.md index 862391691f1f5..3fcbd368dc4dd 100644 --- a/solution/0200-0299/0253.Meeting Rooms II/README_EN.md +++ b/solution/0200-0299/0253.Meeting Rooms II/README_EN.md @@ -49,6 +49,8 @@ tags: +#### Python3 + ```python class Solution: def minMeetingRooms(self, intervals: List[List[int]]) -> int: @@ -59,6 +61,8 @@ class Solution: return max(accumulate(delta)) ``` +#### Java + ```java class Solution { public int minMeetingRooms(int[][] intervals) { @@ -78,6 +82,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -96,6 +102,8 @@ public: }; ``` +#### Go + ```go func minMeetingRooms(intervals [][]int) int { n := 1000010 @@ -111,6 +119,8 @@ func minMeetingRooms(intervals [][]int) int { } ``` +#### Rust + ```rust use std::{ collections::BinaryHeap, cmp::Reverse }; diff --git a/solution/0200-0299/0254.Factor Combinations/README.md b/solution/0200-0299/0254.Factor Combinations/README.md index daa8c5e4ad2ec..a4afeff023661 100644 --- a/solution/0200-0299/0254.Factor Combinations/README.md +++ b/solution/0200-0299/0254.Factor Combinations/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def getFactors(self, n: int) -> List[List[int]]: @@ -103,6 +105,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List t = new ArrayList<>(); @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func getFactors(n int) [][]int { t := []int{} diff --git a/solution/0200-0299/0254.Factor Combinations/README_EN.md b/solution/0200-0299/0254.Factor Combinations/README_EN.md index b3acf4f981e70..238efabc61413 100644 --- a/solution/0200-0299/0254.Factor Combinations/README_EN.md +++ b/solution/0200-0299/0254.Factor Combinations/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def getFactors(self, n: int) -> List[List[int]]: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List t = new ArrayList<>(); @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func getFactors(n int) [][]int { t := []int{} diff --git a/solution/0200-0299/0255.Verify Preorder Sequence in Binary Search Tree/README.md b/solution/0200-0299/0255.Verify Preorder Sequence in Binary Search Tree/README.md index f3d0bcb82eaf0..0c119896d24e0 100644 --- a/solution/0200-0299/0255.Verify Preorder Sequence in Binary Search Tree/README.md +++ b/solution/0200-0299/0255.Verify Preorder Sequence in Binary Search Tree/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def verifyPreorder(self, preorder: List[int]) -> bool: @@ -78,6 +80,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean verifyPreorder(int[] preorder) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func verifyPreorder(preorder []int) bool { var stk []int diff --git a/solution/0200-0299/0255.Verify Preorder Sequence in Binary Search Tree/README_EN.md b/solution/0200-0299/0255.Verify Preorder Sequence in Binary Search Tree/README_EN.md index 5c0e56afa0a83..8dec3e7050e81 100644 --- a/solution/0200-0299/0255.Verify Preorder Sequence in Binary Search Tree/README_EN.md +++ b/solution/0200-0299/0255.Verify Preorder Sequence in Binary Search Tree/README_EN.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def verifyPreorder(self, preorder: List[int]) -> bool: @@ -75,6 +77,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean verifyPreorder(int[] preorder) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func verifyPreorder(preorder []int) bool { var stk []int diff --git a/solution/0200-0299/0256.Paint House/README.md b/solution/0200-0299/0256.Paint House/README.md index 3e732237c6890..6b75dcd2483ff 100644 --- a/solution/0200-0299/0256.Paint House/README.md +++ b/solution/0200-0299/0256.Paint House/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def minCost(self, costs: List[List[int]]) -> int: @@ -75,6 +77,8 @@ class Solution: return min(a, b, c) ``` +#### Java + ```java class Solution { public int minCost(int[][] costs) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func minCost(costs [][]int) int { r, g, b := 0, 0, 0 @@ -119,6 +127,8 @@ func minCost(costs [][]int) int { } ``` +#### JavaScript + ```js /** * @param {number[][]} costs diff --git a/solution/0200-0299/0256.Paint House/README_EN.md b/solution/0200-0299/0256.Paint House/README_EN.md index 49c125c5e3ada..caf967bc63e43 100644 --- a/solution/0200-0299/0256.Paint House/README_EN.md +++ b/solution/0200-0299/0256.Paint House/README_EN.md @@ -64,6 +64,8 @@ Minimum cost: 2 + 5 + 3 = 10. +#### Python3 + ```python class Solution: def minCost(self, costs: List[List[int]]) -> int: @@ -73,6 +75,8 @@ class Solution: return min(a, b, c) ``` +#### Java + ```java class Solution { public int minCost(int[][] costs) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -104,6 +110,8 @@ public: }; ``` +#### Go + ```go func minCost(costs [][]int) int { r, g, b := 0, 0, 0 @@ -117,6 +125,8 @@ func minCost(costs [][]int) int { } ``` +#### JavaScript + ```js /** * @param {number[][]} costs diff --git a/solution/0200-0299/0257.Binary Tree Paths/README.md b/solution/0200-0299/0257.Binary Tree Paths/README.md index d473b7d32a765..bc77ea83db24a 100644 --- a/solution/0200-0299/0257.Binary Tree Paths/README.md +++ b/solution/0200-0299/0257.Binary Tree Paths/README.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -206,6 +214,8 @@ func binaryTreePaths(root *TreeNode) (ans []string) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0200-0299/0257.Binary Tree Paths/README_EN.md b/solution/0200-0299/0257.Binary Tree Paths/README_EN.md index f7f646b4e9213..5815ea69ee308 100644 --- a/solution/0200-0299/0257.Binary Tree Paths/README_EN.md +++ b/solution/0200-0299/0257.Binary Tree Paths/README_EN.md @@ -57,6 +57,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -201,6 +209,8 @@ func binaryTreePaths(root *TreeNode) (ans []string) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0200-0299/0258.Add Digits/README.md b/solution/0200-0299/0258.Add Digits/README.md index 4e302847e3132..43a0111dc4244 100644 --- a/solution/0200-0299/0258.Add Digits/README.md +++ b/solution/0200-0299/0258.Add Digits/README.md @@ -61,12 +61,16 @@ tags: +#### Python3 + ```python class Solution: def addDigits(self, num: int) -> int: return 0 if num == 0 else (num - 1) % 9 + 1 ``` +#### Java + ```java class Solution { public int addDigits(int num) { @@ -75,6 +79,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -84,6 +90,8 @@ public: }; ``` +#### Go + ```go func addDigits(num int) int { if num == 0 { @@ -93,6 +101,8 @@ func addDigits(num int) int { } ``` +#### Rust + ```rust impl Solution { pub fn add_digits(num: i32) -> i32 { @@ -120,6 +130,8 @@ impl Solution { +#### Rust + ```rust impl Solution { pub fn add_digits(mut num: i32) -> i32 { diff --git a/solution/0200-0299/0258.Add Digits/README_EN.md b/solution/0200-0299/0258.Add Digits/README_EN.md index 1c8348fbdf920..6f649af24c7e0 100644 --- a/solution/0200-0299/0258.Add Digits/README_EN.md +++ b/solution/0200-0299/0258.Add Digits/README_EN.md @@ -59,12 +59,16 @@ Since 2 has only one digit, return it. +#### Python3 + ```python class Solution: def addDigits(self, num: int) -> int: return 0 if num == 0 else (num - 1) % 9 + 1 ``` +#### Java + ```java class Solution { public int addDigits(int num) { @@ -73,6 +77,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -82,6 +88,8 @@ public: }; ``` +#### Go + ```go func addDigits(num int) int { if num == 0 { @@ -91,6 +99,8 @@ func addDigits(num int) int { } ``` +#### Rust + ```rust impl Solution { pub fn add_digits(num: i32) -> i32 { @@ -118,6 +128,8 @@ impl Solution { +#### Rust + ```rust impl Solution { pub fn add_digits(mut num: i32) -> i32 { diff --git a/solution/0200-0299/0259.3Sum Smaller/README.md b/solution/0200-0299/0259.3Sum Smaller/README.md index 8c64371e4e1a2..9bbaa54c31f96 100644 --- a/solution/0200-0299/0259.3Sum Smaller/README.md +++ b/solution/0200-0299/0259.3Sum Smaller/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def threeSumSmaller(self, nums: List[int], target: int) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int threeSumSmaller(int[] nums, int target) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func threeSumSmaller(nums []int, target int) int { sort.Ints(nums) @@ -149,6 +157,8 @@ func threeSumSmaller(nums []int, target int) int { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0200-0299/0259.3Sum Smaller/README_EN.md b/solution/0200-0299/0259.3Sum Smaller/README_EN.md index c7b20ecee35b6..856672af53dba 100644 --- a/solution/0200-0299/0259.3Sum Smaller/README_EN.md +++ b/solution/0200-0299/0259.3Sum Smaller/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def threeSumSmaller(self, nums: List[int], target: int) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int threeSumSmaller(int[] nums, int target) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func threeSumSmaller(nums []int, target int) int { sort.Ints(nums) @@ -148,6 +156,8 @@ func threeSumSmaller(nums []int, target int) int { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0200-0299/0260.Single Number III/README.md b/solution/0200-0299/0260.Single Number III/README.md index 0650e5b985a8f..c3a3cff649bd9 100644 --- a/solution/0200-0299/0260.Single Number III/README.md +++ b/solution/0200-0299/0260.Single Number III/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def singleNumber(self, nums: List[int]) -> List[int]: @@ -91,6 +93,8 @@ class Solution: return [a, b] ``` +#### Java + ```java class Solution { public int[] singleNumber(int[] nums) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func singleNumber(nums []int) []int { xs := 0 @@ -150,6 +158,8 @@ func singleNumber(nums []int) []int { } ``` +#### TypeScript + ```ts function singleNumber(nums: number[]): number[] { const xs = nums.reduce((a, b) => a ^ b); @@ -165,6 +175,8 @@ function singleNumber(nums: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn single_number(nums: Vec) -> Vec { @@ -182,6 +194,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -201,6 +215,8 @@ var singleNumber = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int[] SingleNumber(int[] nums) { diff --git a/solution/0200-0299/0260.Single Number III/README_EN.md b/solution/0200-0299/0260.Single Number III/README_EN.md index 5c2f1104a6725..a5208fc56eca8 100644 --- a/solution/0200-0299/0260.Single Number III/README_EN.md +++ b/solution/0200-0299/0260.Single Number III/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def singleNumber(self, nums: List[int]) -> List[int]: @@ -89,6 +91,8 @@ class Solution: return [a, b] ``` +#### Java + ```java class Solution { public int[] singleNumber(int[] nums) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func singleNumber(nums []int) []int { xs := 0 @@ -148,6 +156,8 @@ func singleNumber(nums []int) []int { } ``` +#### TypeScript + ```ts function singleNumber(nums: number[]): number[] { const xs = nums.reduce((a, b) => a ^ b); @@ -163,6 +173,8 @@ function singleNumber(nums: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn single_number(nums: Vec) -> Vec { @@ -180,6 +192,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -199,6 +213,8 @@ var singleNumber = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int[] SingleNumber(int[] nums) { diff --git a/solution/0200-0299/0261.Graph Valid Tree/README.md b/solution/0200-0299/0261.Graph Valid Tree/README.md index 248ba46251229..0df011ef85710 100644 --- a/solution/0200-0299/0261.Graph Valid Tree/README.md +++ b/solution/0200-0299/0261.Graph Valid Tree/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def validTree(self, n: int, edges: List[List[int]]) -> bool: @@ -91,6 +93,8 @@ class Solution: return n == 1 ``` +#### Java + ```java class Solution { private int[] p; @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func validTree(n int, edges [][]int) bool { p := make([]int, n) @@ -170,6 +178,8 @@ func validTree(n int, edges [][]int) bool { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -211,6 +221,8 @@ var validTree = function (n, edges) { +#### Python3 + ```python class Solution: def validTree(self, n: int, edges: List[List[int]]) -> bool: @@ -231,6 +243,8 @@ class Solution: return len(vis) == n ``` +#### Java + ```java class Solution { private List[] g; @@ -262,6 +276,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -291,6 +307,8 @@ public: }; ``` +#### Go + ```go func validTree(n int, edges [][]int) bool { if len(edges) != n-1 { @@ -318,6 +336,8 @@ func validTree(n int, edges [][]int) bool { } ``` +#### JavaScript + ```js /** * @param {number} n diff --git a/solution/0200-0299/0261.Graph Valid Tree/README_EN.md b/solution/0200-0299/0261.Graph Valid Tree/README_EN.md index 92bd8bffd040b..8473b425d4b46 100644 --- a/solution/0200-0299/0261.Graph Valid Tree/README_EN.md +++ b/solution/0200-0299/0261.Graph Valid Tree/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$, +#### Python3 + ```python class Solution: def validTree(self, n: int, edges: List[List[int]]) -> bool: @@ -87,6 +89,8 @@ class Solution: return n == 1 ``` +#### Java + ```java class Solution { public: @@ -112,6 +116,8 @@ public: }; ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func validTree(n int, edges [][]int) bool { p := make([]int, n) @@ -161,6 +169,8 @@ func validTree(n int, edges [][]int) bool { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -202,6 +212,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python class Solution: def validTree(self, n: int, edges: List[List[int]]) -> bool: @@ -222,6 +234,8 @@ class Solution: return len(vis) == n ``` +#### Java + ```java class Solution { private List[] g; @@ -253,6 +267,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -282,6 +298,8 @@ public: }; ``` +#### Go + ```go func validTree(n int, edges [][]int) bool { if len(edges) != n-1 { @@ -309,6 +327,8 @@ func validTree(n int, edges [][]int) bool { } ``` +#### JavaScript + ```js /** * @param {number} n diff --git a/solution/0200-0299/0262.Trips and Users/README.md b/solution/0200-0299/0262.Trips and Users/README.md index 737bbe309821e..e888c1cfeef50 100644 --- a/solution/0200-0299/0262.Trips and Users/README.md +++ b/solution/0200-0299/0262.Trips and Users/README.md @@ -139,6 +139,8 @@ Users 表: +#### Python3 + ```python import pandas as pd @@ -185,6 +187,8 @@ def trips_and_users(trips: pd.DataFrame, users: pd.DataFrame) -> pd.DataFrame: return df[["Day", "Cancellation Rate"]] ``` +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/0200-0299/0262.Trips and Users/README_EN.md b/solution/0200-0299/0262.Trips and Users/README_EN.md index e289693baf550..11be7ae0283dc 100644 --- a/solution/0200-0299/0262.Trips and Users/README_EN.md +++ b/solution/0200-0299/0262.Trips and Users/README_EN.md @@ -130,6 +130,8 @@ On 2013-10-03: +#### Python3 + ```python import pandas as pd @@ -176,6 +178,8 @@ def trips_and_users(trips: pd.DataFrame, users: pd.DataFrame) -> pd.DataFrame: return df[["Day", "Cancellation Rate"]] ``` +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/0200-0299/0263.Ugly Number/README.md b/solution/0200-0299/0263.Ugly Number/README.md index fbacc2fee6983..a176580cfc1d2 100644 --- a/solution/0200-0299/0263.Ugly Number/README.md +++ b/solution/0200-0299/0263.Ugly Number/README.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def isUgly(self, n: int) -> bool: @@ -73,6 +75,8 @@ class Solution: return n == 1 ``` +#### Java + ```java class Solution { public boolean isUgly(int n) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func isUgly(n int) bool { if n < 1 { @@ -124,6 +132,8 @@ func isUgly(n int) bool { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -144,6 +154,8 @@ var isUgly = function (n) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0200-0299/0263.Ugly Number/README_EN.md b/solution/0200-0299/0263.Ugly Number/README_EN.md index fd55b92453555..12fa9d2cf7a9f 100644 --- a/solution/0200-0299/0263.Ugly Number/README_EN.md +++ b/solution/0200-0299/0263.Ugly Number/README_EN.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def isUgly(self, n: int) -> bool: @@ -73,6 +75,8 @@ class Solution: return n == 1 ``` +#### Java + ```java class Solution { public boolean isUgly(int n) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func isUgly(n int) bool { if n < 1 { @@ -124,6 +132,8 @@ func isUgly(n int) bool { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -144,6 +154,8 @@ var isUgly = function (n) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0200-0299/0264.Ugly Number II/README.md b/solution/0200-0299/0264.Ugly Number II/README.md index a7f7bd6790faf..b9df3cc5789ca 100644 --- a/solution/0200-0299/0264.Ugly Number II/README.md +++ b/solution/0200-0299/0264.Ugly Number II/README.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def nthUglyNumber(self, n: int) -> int: @@ -79,6 +81,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int nthUglyNumber(int n) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func nthUglyNumber(n int) int { h := IntHeap([]int{1}) @@ -164,6 +172,8 @@ func (h *IntHeap) Pop() any { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -188,6 +198,8 @@ var nthUglyNumber = function (n) { }; ``` +#### C# + ```cs public class Solution { public int NthUglyNumber(int n) { @@ -232,6 +244,8 @@ public class Solution { +#### Python3 + ```python class Solution: def nthUglyNumber(self, n: int) -> int: @@ -249,6 +263,8 @@ class Solution: return dp[-1] ``` +#### Java + ```java class Solution { public int nthUglyNumber(int n) { @@ -267,6 +283,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -286,6 +304,8 @@ public: }; ``` +#### Go + ```go func nthUglyNumber(n int) int { dp := make([]int, n) diff --git a/solution/0200-0299/0264.Ugly Number II/README_EN.md b/solution/0200-0299/0264.Ugly Number II/README_EN.md index 719790370eae3..33525039ba7c1 100644 --- a/solution/0200-0299/0264.Ugly Number II/README_EN.md +++ b/solution/0200-0299/0264.Ugly Number II/README_EN.md @@ -57,6 +57,8 @@ tags: +#### Python3 + ```python class Solution: def nthUglyNumber(self, n: int) -> int: @@ -73,6 +75,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int nthUglyNumber(int n) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func nthUglyNumber(n int) int { h := IntHeap([]int{1}) @@ -158,6 +166,8 @@ func (h *IntHeap) Pop() any { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -182,6 +192,8 @@ var nthUglyNumber = function (n) { }; ``` +#### C# + ```cs public class Solution { public int NthUglyNumber(int n) { @@ -216,6 +228,8 @@ public class Solution { +#### Python3 + ```python class Solution: def nthUglyNumber(self, n: int) -> int: @@ -233,6 +247,8 @@ class Solution: return dp[-1] ``` +#### Java + ```java class Solution { public int nthUglyNumber(int n) { @@ -251,6 +267,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -270,6 +288,8 @@ public: }; ``` +#### Go + ```go func nthUglyNumber(n int) int { dp := make([]int, n) diff --git a/solution/0200-0299/0265.Paint House II/README.md b/solution/0200-0299/0265.Paint House II/README.md index 033d91b49629b..6bead8b5c6c4e 100644 --- a/solution/0200-0299/0265.Paint House II/README.md +++ b/solution/0200-0299/0265.Paint House II/README.md @@ -83,6 +83,8 @@ $$ +#### Python3 + ```python class Solution: def minCostII(self, costs: List[List[int]]) -> int: @@ -97,6 +99,8 @@ class Solution: return min(f) ``` +#### Java + ```java class Solution { public int minCostII(int[][] costs) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func minCostII(costs [][]int) int { n, k := len(costs), len(costs[0]) diff --git a/solution/0200-0299/0265.Paint House II/README_EN.md b/solution/0200-0299/0265.Paint House II/README_EN.md index 43b46cecced3b..31f245c907079 100644 --- a/solution/0200-0299/0265.Paint House II/README_EN.md +++ b/solution/0200-0299/0265.Paint House II/README_EN.md @@ -69,6 +69,8 @@ Or paint house 0 into color 2, paint house 1 into color 0. Minimum cost: 3 + 2 = +#### Python3 + ```python class Solution: def minCostII(self, costs: List[List[int]]) -> int: @@ -83,6 +85,8 @@ class Solution: return min(f) ``` +#### Java + ```java class Solution { public int minCostII(int[][] costs) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func minCostII(costs [][]int) int { n, k := len(costs), len(costs[0]) diff --git a/solution/0200-0299/0266.Palindrome Permutation/README.md b/solution/0200-0299/0266.Palindrome Permutation/README.md index a80890ad277ee..b1181c7a2fe31 100644 --- a/solution/0200-0299/0266.Palindrome Permutation/README.md +++ b/solution/0200-0299/0266.Palindrome Permutation/README.md @@ -66,12 +66,16 @@ tags: +#### Python3 + ```python class Solution: def canPermutePalindrome(self, s: str) -> bool: return sum(v & 1 for v in Counter(s).values()) < 2 ``` +#### Java + ```java class Solution { public boolean canPermutePalindrome(String s) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func canPermutePalindrome(s string) bool { cnt := [26]int{} @@ -119,6 +127,8 @@ func canPermutePalindrome(s string) bool { } ``` +#### TypeScript + ```ts function canPermutePalindrome(s: string): boolean { const cnt: number[] = new Array(26).fill(0); @@ -129,6 +139,8 @@ function canPermutePalindrome(s: string): boolean { } ``` +#### JavaScript + ```js /** * @param {string} s diff --git a/solution/0200-0299/0266.Palindrome Permutation/README_EN.md b/solution/0200-0299/0266.Palindrome Permutation/README_EN.md index 0d1204c70aeb3..927d690bcf32e 100644 --- a/solution/0200-0299/0266.Palindrome Permutation/README_EN.md +++ b/solution/0200-0299/0266.Palindrome Permutation/README_EN.md @@ -60,12 +60,16 @@ tags: +#### Python3 + ```python class Solution: def canPermutePalindrome(self, s: str) -> bool: return sum(v & 1 for v in Counter(s).values()) < 2 ``` +#### Java + ```java class Solution { public boolean canPermutePalindrome(String s) { @@ -82,6 +86,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -99,6 +105,8 @@ public: }; ``` +#### Go + ```go func canPermutePalindrome(s string) bool { cnt := [26]int{} @@ -113,6 +121,8 @@ func canPermutePalindrome(s string) bool { } ``` +#### TypeScript + ```ts function canPermutePalindrome(s: string): boolean { const cnt: number[] = new Array(26).fill(0); @@ -123,6 +133,8 @@ function canPermutePalindrome(s: string): boolean { } ``` +#### JavaScript + ```js /** * @param {string} s diff --git a/solution/0200-0299/0267.Palindrome Permutation II/README.md b/solution/0200-0299/0267.Palindrome Permutation II/README.md index 65439d5efa46b..85addd7a48036 100644 --- a/solution/0200-0299/0267.Palindrome Permutation II/README.md +++ b/solution/0200-0299/0267.Palindrome Permutation II/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def generatePalindromes(self, s: str) -> List[str]: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List ans = new ArrayList<>(); @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go func generatePalindromes(s string) []string { cnt := map[byte]int{} diff --git a/solution/0200-0299/0267.Palindrome Permutation II/README_EN.md b/solution/0200-0299/0267.Palindrome Permutation II/README_EN.md index aa9a7a7d4aae0..91a0c4978a7ae 100644 --- a/solution/0200-0299/0267.Palindrome Permutation II/README_EN.md +++ b/solution/0200-0299/0267.Palindrome Permutation II/README_EN.md @@ -48,6 +48,8 @@ tags: +#### Python3 + ```python class Solution: def generatePalindromes(self, s: str) -> List[str]: @@ -74,6 +76,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List ans = new ArrayList<>(); @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func generatePalindromes(s string) []string { cnt := map[byte]int{} diff --git a/solution/0200-0299/0268.Missing Number/README.md b/solution/0200-0299/0268.Missing Number/README.md index 21df910dca44d..c6210da2536fe 100644 --- a/solution/0200-0299/0268.Missing Number/README.md +++ b/solution/0200-0299/0268.Missing Number/README.md @@ -90,12 +90,16 @@ tags: +#### Python3 + ```python class Solution: def missingNumber(self, nums: List[int]) -> int: return reduce(xor, (i ^ v for i, v in enumerate(nums, 1))) ``` +#### Java + ```java class Solution { public int missingNumber(int[] nums) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func missingNumber(nums []int) (ans int) { n := len(nums) @@ -134,6 +142,8 @@ func missingNumber(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function missingNumber(nums: number[]): number { const n = nums.length; @@ -145,6 +155,8 @@ function missingNumber(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn missing_number(nums: Vec) -> i32 { @@ -158,6 +170,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -173,6 +187,8 @@ var missingNumber = function (nums) { }; ``` +#### PHP + ```php class Solution { /** @@ -204,6 +220,8 @@ class Solution { +#### Python3 + ```python class Solution: def missingNumber(self, nums: List[int]) -> int: @@ -211,6 +229,8 @@ class Solution: return (1 + n) * n // 2 - sum(nums) ``` +#### Java + ```java class Solution { public int missingNumber(int[] nums) { @@ -224,6 +244,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -234,6 +256,8 @@ public: }; ``` +#### Go + ```go func missingNumber(nums []int) (ans int) { n := len(nums) @@ -245,6 +269,8 @@ func missingNumber(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function missingNumber(nums: number[]): number { const n = nums.length; @@ -256,6 +282,8 @@ function missingNumber(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn missing_number(nums: Vec) -> i32 { @@ -269,6 +297,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0200-0299/0268.Missing Number/README_EN.md b/solution/0200-0299/0268.Missing Number/README_EN.md index 24ef004b5aa77..7aaf9530eab9a 100644 --- a/solution/0200-0299/0268.Missing Number/README_EN.md +++ b/solution/0200-0299/0268.Missing Number/README_EN.md @@ -80,12 +80,16 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def missingNumber(self, nums: List[int]) -> int: return reduce(xor, (i ^ v for i, v in enumerate(nums, 1))) ``` +#### Java + ```java class Solution { public int missingNumber(int[] nums) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func missingNumber(nums []int) (ans int) { n := len(nums) @@ -124,6 +132,8 @@ func missingNumber(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function missingNumber(nums: number[]): number { const n = nums.length; @@ -135,6 +145,8 @@ function missingNumber(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn missing_number(nums: Vec) -> i32 { @@ -148,6 +160,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -163,6 +177,8 @@ var missingNumber = function (nums) { }; ``` +#### PHP + ```php class Solution { /** @@ -194,6 +210,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def missingNumber(self, nums: List[int]) -> int: @@ -201,6 +219,8 @@ class Solution: return (1 + n) * n // 2 - sum(nums) ``` +#### Java + ```java class Solution { public int missingNumber(int[] nums) { @@ -214,6 +234,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -224,6 +246,8 @@ public: }; ``` +#### Go + ```go func missingNumber(nums []int) (ans int) { n := len(nums) @@ -235,6 +259,8 @@ func missingNumber(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function missingNumber(nums: number[]): number { const n = nums.length; @@ -246,6 +272,8 @@ function missingNumber(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn missing_number(nums: Vec) -> i32 { @@ -259,6 +287,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0200-0299/0269.Alien Dictionary/README.md b/solution/0200-0299/0269.Alien Dictionary/README.md index 2e439ab231f50..b1185f65b06a0 100644 --- a/solution/0200-0299/0269.Alien Dictionary/README.md +++ b/solution/0200-0299/0269.Alien Dictionary/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def alienOrder(self, words: List[str]) -> str: @@ -146,6 +148,8 @@ class Solution: return '' if len(ans) < cnt else ''.join(ans) ``` +#### Java + ```java class Solution { @@ -223,6 +227,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/0200-0299/0269.Alien Dictionary/README_EN.md b/solution/0200-0299/0269.Alien Dictionary/README_EN.md index b17d639ee05f4..9677cf9f30970 100644 --- a/solution/0200-0299/0269.Alien Dictionary/README_EN.md +++ b/solution/0200-0299/0269.Alien Dictionary/README_EN.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def alienOrder(self, words: List[str]) -> str: @@ -127,6 +129,8 @@ class Solution: return '' if len(ans) < cnt else ''.join(ans) ``` +#### Java + ```java class Solution { @@ -204,6 +208,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/0200-0299/0270.Closest Binary Search Tree Value/README.md b/solution/0200-0299/0270.Closest Binary Search Tree Value/README.md index 3c3ffe6a33dec..bc47d1744dfbb 100644 --- a/solution/0200-0299/0270.Closest Binary Search Tree Value/README.md +++ b/solution/0200-0299/0270.Closest Binary Search Tree Value/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -196,6 +204,8 @@ func closestValue(root *TreeNode, target float64) int { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -246,6 +256,8 @@ var closestValue = function (root, target) { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -268,6 +280,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -305,6 +319,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -339,6 +355,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -367,6 +385,8 @@ func closestValue(root *TreeNode, target float64) int { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0200-0299/0270.Closest Binary Search Tree Value/README_EN.md b/solution/0200-0299/0270.Closest Binary Search Tree Value/README_EN.md index 2a454f8aae343..b346034a95a69 100644 --- a/solution/0200-0299/0270.Closest Binary Search Tree Value/README_EN.md +++ b/solution/0200-0299/0270.Closest Binary Search Tree Value/README_EN.md @@ -56,6 +56,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -188,6 +196,8 @@ func closestValue(root *TreeNode, target float64) int { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -232,6 +242,8 @@ var closestValue = function (root, target) { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -254,6 +266,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -291,6 +305,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -325,6 +341,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -353,6 +371,8 @@ func closestValue(root *TreeNode, target float64) int { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0200-0299/0271.Encode and Decode Strings/README.md b/solution/0200-0299/0271.Encode and Decode Strings/README.md index adc74d28936e0..9cc79cdfed43a 100644 --- a/solution/0200-0299/0271.Encode and Decode Strings/README.md +++ b/solution/0200-0299/0271.Encode and Decode Strings/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Codec: def encode(self, strs: List[str]) -> str: @@ -99,6 +101,8 @@ class Codec: # codec.decode(codec.encode(strs)) ``` +#### Java + ```java public class Codec { @@ -129,6 +133,8 @@ public class Codec { // codec.decode(codec.encode(strs)); ``` +#### C++ + ```cpp class Codec { public: @@ -163,6 +169,8 @@ public: // codec.decode(codec.encode(strs)); ``` +#### Go + ```go type Codec struct { } diff --git a/solution/0200-0299/0271.Encode and Decode Strings/README_EN.md b/solution/0200-0299/0271.Encode and Decode Strings/README_EN.md index afe815c65e06b..f7b4593a0c282 100644 --- a/solution/0200-0299/0271.Encode and Decode Strings/README_EN.md +++ b/solution/0200-0299/0271.Encode and Decode Strings/README_EN.md @@ -107,6 +107,8 @@ The time complexity is $O(n)$. +#### Python3 + ```python class Codec: def encode(self, strs: List[str]) -> str: @@ -133,6 +135,8 @@ class Codec: # codec.decode(codec.encode(strs)) ``` +#### Java + ```java public class Codec { @@ -163,6 +167,8 @@ public class Codec { // codec.decode(codec.encode(strs)); ``` +#### C++ + ```cpp class Codec { public: @@ -197,6 +203,8 @@ public: // codec.decode(codec.encode(strs)); ``` +#### Go + ```go type Codec struct { } diff --git a/solution/0200-0299/0272.Closest Binary Search Tree Value II/README.md b/solution/0200-0299/0272.Closest Binary Search Tree Value II/README.md index c75e630ed270d..d3f0bdd2724f2 100644 --- a/solution/0200-0299/0272.Closest Binary Search Tree Value II/README.md +++ b/solution/0200-0299/0272.Closest Binary Search Tree Value II/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -95,6 +97,8 @@ class Solution: return list(q) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -189,6 +195,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0200-0299/0272.Closest Binary Search Tree Value II/README_EN.md b/solution/0200-0299/0272.Closest Binary Search Tree Value II/README_EN.md index 1e0734004afa1..449589e27f9db 100644 --- a/solution/0200-0299/0272.Closest Binary Search Tree Value II/README_EN.md +++ b/solution/0200-0299/0272.Closest Binary Search Tree Value II/README_EN.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -91,6 +93,8 @@ class Solution: return list(q) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -185,6 +191,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0200-0299/0273.Integer to English Words/README.md b/solution/0200-0299/0273.Integer to English Words/README.md index 07c5d31a2c272..54a28c8948824 100644 --- a/solution/0200-0299/0273.Integer to English Words/README.md +++ b/solution/0200-0299/0273.Integer to English Words/README.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def numberToWords(self, num: int) -> str: @@ -125,6 +127,8 @@ class Solution: return ''.join(res).strip() ``` +#### Java + ```java class Solution { private static Map map; @@ -199,6 +203,8 @@ class Solution { } ``` +#### C# + ```cs using System.Collections.Generic; using System.Linq; @@ -300,6 +306,8 @@ public class Solution { +#### Java + ```java class Solution { private String[] lt20 = {"", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", diff --git a/solution/0200-0299/0273.Integer to English Words/README_EN.md b/solution/0200-0299/0273.Integer to English Words/README_EN.md index 8eaebe2196418..51615ba7e4a7a 100644 --- a/solution/0200-0299/0273.Integer to English Words/README_EN.md +++ b/solution/0200-0299/0273.Integer to English Words/README_EN.md @@ -59,6 +59,8 @@ tags: +#### Python3 + ```python class Solution: def numberToWords(self, num: int) -> str: @@ -123,6 +125,8 @@ class Solution: return ''.join(res).strip() ``` +#### Java + ```java class Solution { private static Map map; @@ -197,6 +201,8 @@ class Solution { } ``` +#### C# + ```cs using System.Collections.Generic; using System.Linq; @@ -298,6 +304,8 @@ public class Solution { +#### Java + ```java class Solution { private String[] lt20 = {"", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", diff --git a/solution/0200-0299/0274.H-Index/README.md b/solution/0200-0299/0274.H-Index/README.md index e52e862e405d2..5d232fc47fc68 100644 --- a/solution/0200-0299/0274.H-Index/README.md +++ b/solution/0200-0299/0274.H-Index/README.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def hIndex(self, citations: List[int]) -> int: @@ -73,6 +75,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { public int hIndex(int[] citations) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -103,6 +109,8 @@ public: }; ``` +#### Go + ```go func hIndex(citations []int) int { sort.Ints(citations) @@ -116,6 +124,8 @@ func hIndex(citations []int) int { } ``` +#### TypeScript + ```ts function hIndex(citations: number[]): number { citations.sort((a, b) => b - a); @@ -128,6 +138,8 @@ function hIndex(citations: number[]): number { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -164,6 +176,8 @@ impl Solution { +#### Python3 + ```python class Solution: def hIndex(self, citations: List[int]) -> int: @@ -178,6 +192,8 @@ class Solution: return h ``` +#### Java + ```java class Solution { public int hIndex(int[] citations) { @@ -196,6 +212,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -216,6 +234,8 @@ public: }; ``` +#### Go + ```go func hIndex(citations []int) int { n := len(citations) @@ -232,6 +252,8 @@ func hIndex(citations []int) int { } ``` +#### TypeScript + ```ts function hIndex(citations: number[]): number { const n: number = citations.length; @@ -264,6 +286,8 @@ function hIndex(citations: number[]): number { +#### Python3 + ```python class Solution: def hIndex(self, citations: List[int]) -> int: @@ -277,6 +301,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { public int hIndex(int[] citations) { @@ -300,6 +326,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -324,6 +352,8 @@ public: }; ``` +#### Go + ```go func hIndex(citations []int) int { l, r := 0, len(citations) @@ -345,6 +375,8 @@ func hIndex(citations []int) int { } ``` +#### TypeScript + ```ts function hIndex(citations: number[]): number { let l = 0; diff --git a/solution/0200-0299/0274.H-Index/README_EN.md b/solution/0200-0299/0274.H-Index/README_EN.md index d9f0a311911cb..d4b6562d38384 100644 --- a/solution/0200-0299/0274.H-Index/README_EN.md +++ b/solution/0200-0299/0274.H-Index/README_EN.md @@ -62,6 +62,8 @@ Time complexity $O(n \times \log n)$, space complexity $O(\log n)$. Here $n$ is +#### Python3 + ```python class Solution: def hIndex(self, citations: List[int]) -> int: @@ -72,6 +74,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { public int hIndex(int[] citations) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -102,6 +108,8 @@ public: }; ``` +#### Go + ```go func hIndex(citations []int) int { sort.Ints(citations) @@ -115,6 +123,8 @@ func hIndex(citations []int) int { } ``` +#### TypeScript + ```ts function hIndex(citations: number[]): number { citations.sort((a, b) => b - a); @@ -127,6 +137,8 @@ function hIndex(citations: number[]): number { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -163,6 +175,8 @@ Time complexity $O(n)$, space complexity $O(n)$. Here $n$ is the length of the a +#### Python3 + ```python class Solution: def hIndex(self, citations: List[int]) -> int: @@ -177,6 +191,8 @@ class Solution: return h ``` +#### Java + ```java class Solution { public int hIndex(int[] citations) { @@ -195,6 +211,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -215,6 +233,8 @@ public: }; ``` +#### Go + ```go func hIndex(citations []int) int { n := len(citations) @@ -231,6 +251,8 @@ func hIndex(citations []int) int { } ``` +#### TypeScript + ```ts function hIndex(citations: number[]): number { const n: number = citations.length; @@ -263,6 +285,8 @@ Time complexity $O(n \times \log n)$, where $n$ is the length of array `citation +#### Python3 + ```python class Solution: def hIndex(self, citations: List[int]) -> int: @@ -276,6 +300,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { public int hIndex(int[] citations) { @@ -299,6 +325,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -323,6 +351,8 @@ public: }; ``` +#### Go + ```go func hIndex(citations []int) int { l, r := 0, len(citations) @@ -344,6 +374,8 @@ func hIndex(citations []int) int { } ``` +#### TypeScript + ```ts function hIndex(citations: number[]): number { let l = 0; diff --git a/solution/0200-0299/0275.H-Index II/README.md b/solution/0200-0299/0275.H-Index II/README.md index 9a2774e744f9c..546a3242358e5 100644 --- a/solution/0200-0299/0275.H-Index II/README.md +++ b/solution/0200-0299/0275.H-Index II/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def hIndex(self, citations: List[int]) -> int: @@ -81,6 +83,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int hIndex(int[] citations) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func hIndex(citations []int) int { n := len(citations) @@ -133,6 +141,8 @@ func hIndex(citations []int) int { } ``` +#### TypeScript + ```ts function hIndex(citations: number[]): number { const n = citations.length; @@ -150,6 +160,8 @@ function hIndex(citations: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn h_index(citations: Vec) -> i32 { @@ -168,6 +180,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int HIndex(int[] citations) { diff --git a/solution/0200-0299/0275.H-Index II/README_EN.md b/solution/0200-0299/0275.H-Index II/README_EN.md index bf4b710c83d54..e8247fe65c36e 100644 --- a/solution/0200-0299/0275.H-Index II/README_EN.md +++ b/solution/0200-0299/0275.H-Index II/README_EN.md @@ -66,6 +66,8 @@ The time complexity is $O(\log n)$, where $n$ is the length of the array $citati +#### Python3 + ```python class Solution: def hIndex(self, citations: List[int]) -> int: @@ -80,6 +82,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int hIndex(int[] citations) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func hIndex(citations []int) int { n := len(citations) @@ -132,6 +140,8 @@ func hIndex(citations []int) int { } ``` +#### TypeScript + ```ts function hIndex(citations: number[]): number { const n = citations.length; @@ -149,6 +159,8 @@ function hIndex(citations: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn h_index(citations: Vec) -> i32 { @@ -167,6 +179,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int HIndex(int[] citations) { diff --git a/solution/0200-0299/0276.Paint Fence/README.md b/solution/0200-0299/0276.Paint Fence/README.md index c1645ef2e8984..fd7571e05e50c 100644 --- a/solution/0200-0299/0276.Paint Fence/README.md +++ b/solution/0200-0299/0276.Paint Fence/README.md @@ -84,6 +84,8 @@ $$ +#### Python3 + ```python class Solution: def numWays(self, n: int, k: int) -> int: @@ -96,6 +98,8 @@ class Solution: return f[-1] + g[-1] ``` +#### Java + ```java class Solution { public int numWays(int n, int k) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func numWays(n int, k int) int { f := make([]int, n) @@ -140,6 +148,8 @@ func numWays(n int, k int) int { } ``` +#### TypeScript + ```ts function numWays(n: number, k: number): number { const f: number[] = Array(n).fill(0); @@ -165,6 +175,8 @@ function numWays(n: number, k: number): number { +#### Python3 + ```python class Solution: def numWays(self, n: int, k: int) -> int: @@ -176,6 +188,8 @@ class Solution: return f + g ``` +#### Java + ```java class Solution { public int numWays(int n, int k) { @@ -190,6 +204,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -205,6 +221,8 @@ public: }; ``` +#### Go + ```go func numWays(n int, k int) int { f, g := k, 0 @@ -215,6 +233,8 @@ func numWays(n int, k int) int { } ``` +#### TypeScript + ```ts function numWays(n: number, k: number): number { let [f, g] = [k, 0]; diff --git a/solution/0200-0299/0276.Paint Fence/README_EN.md b/solution/0200-0299/0276.Paint Fence/README_EN.md index 8ff373e151767..b65fc8dff5276 100644 --- a/solution/0200-0299/0276.Paint Fence/README_EN.md +++ b/solution/0200-0299/0276.Paint Fence/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(n)$ and the space complexity is $O(n)$, where $n$ is t +#### Python3 + ```python class Solution: def numWays(self, n: int, k: int) -> int: @@ -95,6 +97,8 @@ class Solution: return f[-1] + g[-1] ``` +#### Java + ```java class Solution { public int numWays(int n, int k) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func numWays(n int, k int) int { f := make([]int, n) @@ -139,6 +147,8 @@ func numWays(n int, k int) int { } ``` +#### TypeScript + ```ts function numWays(n: number, k: number): number { const f: number[] = Array(n).fill(0); @@ -164,6 +174,8 @@ We notice that $f[i]$ and $g[i]$ are only related to $f[i - 1]$ and $g[i - 1]$. +#### Python3 + ```python class Solution: def numWays(self, n: int, k: int) -> int: @@ -175,6 +187,8 @@ class Solution: return f + g ``` +#### Java + ```java class Solution { public int numWays(int n, int k) { @@ -189,6 +203,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -204,6 +220,8 @@ public: }; ``` +#### Go + ```go func numWays(n int, k int) int { f, g := k, 0 @@ -214,6 +232,8 @@ func numWays(n int, k int) int { } ``` +#### TypeScript + ```ts function numWays(n: number, k: number): number { let [f, g] = [k, 0]; diff --git a/solution/0200-0299/0277.Find the Celebrity/README.md b/solution/0200-0299/0277.Find the Celebrity/README.md index faee11b486366..501457473064d 100644 --- a/solution/0200-0299/0277.Find the Celebrity/README.md +++ b/solution/0200-0299/0277.Find the Celebrity/README.md @@ -120,6 +120,8 @@ ans = 6 +#### Python3 + ```python # The knows API is already defined for you. # return a bool, whether a knows b @@ -139,6 +141,8 @@ class Solution: return ans ``` +#### Java + ```java /* The knows API is defined in the parent class Relation. boolean knows(int a, int b); */ @@ -163,6 +167,8 @@ public class Solution extends Relation { } ``` +#### C++ + ```cpp /* The knows API is defined for you. bool knows(int a, int b); */ @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go /** * The knows API is already defined for you. diff --git a/solution/0200-0299/0277.Find the Celebrity/README_EN.md b/solution/0200-0299/0277.Find the Celebrity/README_EN.md index d9b7652928612..56be8c2410d0a 100644 --- a/solution/0200-0299/0277.Find the Celebrity/README_EN.md +++ b/solution/0200-0299/0277.Find the Celebrity/README_EN.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python # The knows API is already defined for you. # return a bool, whether a knows b @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java /* The knows API is defined in the parent class Relation. boolean knows(int a, int b); */ @@ -109,6 +113,8 @@ public class Solution extends Relation { } ``` +#### C++ + ```cpp /* The knows API is defined for you. bool knows(int a, int b); */ @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go /** * The knows API is already defined for you. diff --git a/solution/0200-0299/0278.First Bad Version/README.md b/solution/0200-0299/0278.First Bad Version/README.md index 1d064dfb2d64e..31757964b01fc 100644 --- a/solution/0200-0299/0278.First Bad Version/README.md +++ b/solution/0200-0299/0278.First Bad Version/README.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python # The isBadVersion API is already defined for you. # @param version, an integer @@ -84,6 +86,8 @@ class Solution: return left ``` +#### Java + ```java /* The isBadVersion API is defined in the parent class VersionControl. boolean isBadVersion(int version); */ @@ -104,6 +108,8 @@ public class Solution extends VersionControl { } ``` +#### C++ + ```cpp // The API isBadVersion is defined for you. // bool isBadVersion(int version); @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go /** * Forward declaration of isBadVersion API. @@ -148,6 +156,8 @@ func firstBadVersion(n int) int { } ``` +#### Rust + ```rust // The API isBadVersion is defined for you. // isBadVersion(version:i32)-> bool; @@ -170,6 +180,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for isBadVersion() diff --git a/solution/0200-0299/0278.First Bad Version/README_EN.md b/solution/0200-0299/0278.First Bad Version/README_EN.md index 3002983138b3e..5608efe4d2f33 100644 --- a/solution/0200-0299/0278.First Bad Version/README_EN.md +++ b/solution/0200-0299/0278.First Bad Version/README_EN.md @@ -60,6 +60,8 @@ Then 4 is the first bad version. +#### Python3 + ```python # The isBadVersion API is already defined for you. # @param version, an integer @@ -83,6 +85,8 @@ class Solution: return left ``` +#### Java + ```java /* The isBadVersion API is defined in the parent class VersionControl. boolean isBadVersion(int version); */ @@ -103,6 +107,8 @@ public class Solution extends VersionControl { } ``` +#### C++ + ```cpp // The API isBadVersion is defined for you. // bool isBadVersion(int version); @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go /** * Forward declaration of isBadVersion API. @@ -147,6 +155,8 @@ func firstBadVersion(n int) int { } ``` +#### Rust + ```rust // The API isBadVersion is defined for you. // isBadVersion(version:i32)-> bool; @@ -169,6 +179,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for isBadVersion() diff --git a/solution/0200-0299/0279.Perfect Squares/README.md b/solution/0200-0299/0279.Perfect Squares/README.md index bfca4bfbc967f..5b6e5e08daf40 100644 --- a/solution/0200-0299/0279.Perfect Squares/README.md +++ b/solution/0200-0299/0279.Perfect Squares/README.md @@ -88,6 +88,8 @@ $$ +#### Python3 + ```python class Solution: def numSquares(self, n: int) -> int: @@ -102,6 +104,8 @@ class Solution: return f[m][n] ``` +#### Java + ```java class Solution { public int numSquares(int n) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func numSquares(n int) int { m := int(math.Sqrt(float64(n))) @@ -169,6 +177,8 @@ func numSquares(n int) int { } ``` +#### TypeScript + ```ts function numSquares(n: number): number { const m = Math.floor(Math.sqrt(n)); @@ -188,6 +198,8 @@ function numSquares(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn num_squares(n: i32) -> i32 { @@ -217,6 +229,8 @@ impl Solution { +#### Python3 + ```python class Solution: def numSquares(self, n: int) -> int: @@ -228,6 +242,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int numSquares(int n) { @@ -245,6 +261,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -263,6 +281,8 @@ public: }; ``` +#### Go + ```go func numSquares(n int) int { m := int(math.Sqrt(float64(n))) @@ -280,6 +300,8 @@ func numSquares(n int) int { } ``` +#### TypeScript + ```ts function numSquares(n: number): number { const m = Math.floor(Math.sqrt(n)); @@ -294,6 +316,8 @@ function numSquares(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn num_squares(n: i32) -> i32 { diff --git a/solution/0200-0299/0279.Perfect Squares/README_EN.md b/solution/0200-0299/0279.Perfect Squares/README_EN.md index de37f5e2fbcb0..ef0dd6874a600 100644 --- a/solution/0200-0299/0279.Perfect Squares/README_EN.md +++ b/solution/0200-0299/0279.Perfect Squares/README_EN.md @@ -56,6 +56,8 @@ tags: +#### Python3 + ```python class Solution: def numSquares(self, n: int) -> int: @@ -70,6 +72,8 @@ class Solution: return f[m][n] ``` +#### Java + ```java class Solution { public int numSquares(int n) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func numSquares(n int) int { m := int(math.Sqrt(float64(n))) @@ -137,6 +145,8 @@ func numSquares(n int) int { } ``` +#### TypeScript + ```ts function numSquares(n: number): number { const m = Math.floor(Math.sqrt(n)); @@ -156,6 +166,8 @@ function numSquares(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn num_squares(n: i32) -> i32 { @@ -185,6 +197,8 @@ impl Solution { +#### Python3 + ```python class Solution: def numSquares(self, n: int) -> int: @@ -196,6 +210,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int numSquares(int n) { @@ -213,6 +229,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -231,6 +249,8 @@ public: }; ``` +#### Go + ```go func numSquares(n int) int { m := int(math.Sqrt(float64(n))) @@ -248,6 +268,8 @@ func numSquares(n int) int { } ``` +#### TypeScript + ```ts function numSquares(n: number): number { const m = Math.floor(Math.sqrt(n)); @@ -262,6 +284,8 @@ function numSquares(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn num_squares(n: i32) -> i32 { diff --git a/solution/0200-0299/0280.Wiggle Sort/README.md b/solution/0200-0299/0280.Wiggle Sort/README.md index 3041db7ca7730..1bdc59392d5e5 100644 --- a/solution/0200-0299/0280.Wiggle Sort/README.md +++ b/solution/0200-0299/0280.Wiggle Sort/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def wiggleSort(self, nums: List[int]) -> None: @@ -79,6 +81,8 @@ class Solution: nums[i], nums[i - 1] = nums[i - 1], nums[i] ``` +#### Java + ```java class Solution { public void wiggleSort(int[] nums) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func wiggleSort(nums []int) { for i := 1; i < len(nums); i++ { diff --git a/solution/0200-0299/0280.Wiggle Sort/README_EN.md b/solution/0200-0299/0280.Wiggle Sort/README_EN.md index 92b4ef6b84301..7002977a14566 100644 --- a/solution/0200-0299/0280.Wiggle Sort/README_EN.md +++ b/solution/0200-0299/0280.Wiggle Sort/README_EN.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def wiggleSort(self, nums: List[int]) -> None: @@ -73,6 +75,8 @@ class Solution: nums[i], nums[i - 1] = nums[i - 1], nums[i] ``` +#### Java + ```java class Solution { public void wiggleSort(int[] nums) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -104,6 +110,8 @@ public: }; ``` +#### Go + ```go func wiggleSort(nums []int) { for i := 1; i < len(nums); i++ { diff --git a/solution/0200-0299/0281.Zigzag Iterator/README.md b/solution/0200-0299/0281.Zigzag Iterator/README.md index c6ebe42516c66..05f05571fd019 100644 --- a/solution/0200-0299/0281.Zigzag Iterator/README.md +++ b/solution/0200-0299/0281.Zigzag Iterator/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class ZigzagIterator: def __init__(self, v1: List[int], v2: List[int]): @@ -101,6 +103,8 @@ class ZigzagIterator: # while i.hasNext(): v.append(i.next()) ``` +#### Java + ```java public class ZigzagIterator { private int cur; @@ -145,6 +149,8 @@ public class ZigzagIterator { */ ``` +#### Rust + ```rust struct ZigzagIterator { v1: Vec, diff --git a/solution/0200-0299/0281.Zigzag Iterator/README_EN.md b/solution/0200-0299/0281.Zigzag Iterator/README_EN.md index 5ea0e5c73f793..577e8df1e3bd6 100644 --- a/solution/0200-0299/0281.Zigzag Iterator/README_EN.md +++ b/solution/0200-0299/0281.Zigzag Iterator/README_EN.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class ZigzagIterator: def __init__(self, v1: List[int], v2: List[int]): @@ -115,6 +117,8 @@ class ZigzagIterator: # while i.hasNext(): v.append(i.next()) ``` +#### Java + ```java public class ZigzagIterator { private int cur; @@ -159,6 +163,8 @@ public class ZigzagIterator { */ ``` +#### Rust + ```rust struct ZigzagIterator { v1: Vec, diff --git a/solution/0200-0299/0282.Expression Add Operators/README.md b/solution/0200-0299/0282.Expression Add Operators/README.md index cc96c82cd98b9..7c63777b267a2 100644 --- a/solution/0200-0299/0282.Expression Add Operators/README.md +++ b/solution/0200-0299/0282.Expression Add Operators/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def addOperators(self, num: str, target: int) -> List[str]: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List ans; @@ -134,6 +138,8 @@ class Solution { } ``` +#### C# + ```cs using System; using System.Collections.Generic; diff --git a/solution/0200-0299/0282.Expression Add Operators/README_EN.md b/solution/0200-0299/0282.Expression Add Operators/README_EN.md index 18bab6c71ce91..083949924e34b 100644 --- a/solution/0200-0299/0282.Expression Add Operators/README_EN.md +++ b/solution/0200-0299/0282.Expression Add Operators/README_EN.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def addOperators(self, num: str, target: int) -> List[str]: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List ans; @@ -132,6 +136,8 @@ class Solution { } ``` +#### C# + ```cs using System; using System.Collections.Generic; diff --git a/solution/0200-0299/0283.Move Zeroes/README.md b/solution/0200-0299/0283.Move Zeroes/README.md index 830e1b40baf3e..29e49073078f2 100644 --- a/solution/0200-0299/0283.Move Zeroes/README.md +++ b/solution/0200-0299/0283.Move Zeroes/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def moveZeroes(self, nums: List[int]) -> None: @@ -76,6 +78,8 @@ class Solution: nums[i], nums[j] = nums[j], nums[i] ``` +#### Java + ```java class Solution { public void moveZeroes(int[] nums) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func moveZeroes(nums []int) { i := -1 @@ -117,6 +125,8 @@ func moveZeroes(nums []int) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify nums in-place instead. @@ -135,6 +145,8 @@ function moveZeroes(nums: number[]): void { } ``` +#### Rust + ```rust impl Solution { pub fn move_zeroes(nums: &mut Vec) { @@ -152,6 +164,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -169,6 +183,8 @@ var moveZeroes = function (nums) { }; ``` +#### C + ```c void moveZeroes(int* nums, int numsSize) { int i = 0; diff --git a/solution/0200-0299/0283.Move Zeroes/README_EN.md b/solution/0200-0299/0283.Move Zeroes/README_EN.md index dfafdd65f19b6..6645c203bfb99 100644 --- a/solution/0200-0299/0283.Move Zeroes/README_EN.md +++ b/solution/0200-0299/0283.Move Zeroes/README_EN.md @@ -56,6 +56,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def moveZeroes(self, nums: List[int]) -> None: @@ -66,6 +68,8 @@ class Solution: nums[i], nums[j] = nums[j], nums[i] ``` +#### Java + ```java class Solution { public void moveZeroes(int[] nums) { @@ -81,6 +85,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -95,6 +101,8 @@ public: }; ``` +#### Go + ```go func moveZeroes(nums []int) { i := -1 @@ -107,6 +115,8 @@ func moveZeroes(nums []int) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify nums in-place instead. @@ -125,6 +135,8 @@ function moveZeroes(nums: number[]): void { } ``` +#### Rust + ```rust impl Solution { pub fn move_zeroes(nums: &mut Vec) { @@ -142,6 +154,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -159,6 +173,8 @@ var moveZeroes = function (nums) { }; ``` +#### C + ```c void moveZeroes(int* nums, int numsSize) { int i = 0; diff --git a/solution/0200-0299/0284.Peeking Iterator/README.md b/solution/0200-0299/0284.Peeking Iterator/README.md index 69b99297cb6f4..a9948638ade8a 100644 --- a/solution/0200-0299/0284.Peeking Iterator/README.md +++ b/solution/0200-0299/0284.Peeking Iterator/README.md @@ -76,6 +76,8 @@ peekingIterator.hasNext(); // 返回 False +#### Python3 + ```python # Below is the interface for Iterator, which is already defined for you. # @@ -144,6 +146,8 @@ class PeekingIterator: # iter.next() # Should return the same value as [val]. ``` +#### Java + ```java // Java Iterator interface reference: // https://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html @@ -187,6 +191,8 @@ class PeekingIterator implements Iterator { } ``` +#### C++ + ```cpp /* * Below is the interface for Iterator, which is already defined for you. @@ -244,6 +250,8 @@ private: }; ``` +#### Go + ```go /* Below is the interface for Iterator, which is already defined for you. * diff --git a/solution/0200-0299/0284.Peeking Iterator/README_EN.md b/solution/0200-0299/0284.Peeking Iterator/README_EN.md index c0a29f47d5846..3ce8751536d86 100644 --- a/solution/0200-0299/0284.Peeking Iterator/README_EN.md +++ b/solution/0200-0299/0284.Peeking Iterator/README_EN.md @@ -73,6 +73,8 @@ peekingIterator.hasNext(); // return False +#### Python3 + ```python # Below is the interface for Iterator, which is already defined for you. # @@ -141,6 +143,8 @@ class PeekingIterator: # iter.next() # Should return the same value as [val]. ``` +#### Java + ```java // Java Iterator interface reference: // https://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html @@ -184,6 +188,8 @@ class PeekingIterator implements Iterator { } ``` +#### C++ + ```cpp /* * Below is the interface for Iterator, which is already defined for you. @@ -241,6 +247,8 @@ private: }; ``` +#### Go + ```go /* Below is the interface for Iterator, which is already defined for you. * diff --git a/solution/0200-0299/0285.Inorder Successor in BST/README.md b/solution/0200-0299/0285.Inorder Successor in BST/README.md index 5682f356ac64a..4729357bcecb3 100644 --- a/solution/0200-0299/0285.Inorder Successor in BST/README.md +++ b/solution/0200-0299/0285.Inorder Successor in BST/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -172,6 +180,8 @@ func inorderSuccessor(root *TreeNode, p *TreeNode) (ans *TreeNode) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -201,6 +211,8 @@ function inorderSuccessor(root: TreeNode | null, p: TreeNode | null): TreeNode | } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0200-0299/0285.Inorder Successor in BST/README_EN.md b/solution/0200-0299/0285.Inorder Successor in BST/README_EN.md index 07dab43bb6295..825c587282b27 100644 --- a/solution/0200-0299/0285.Inorder Successor in BST/README_EN.md +++ b/solution/0200-0299/0285.Inorder Successor in BST/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(h)$, where $h$ is the height of the binary search tree +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -166,6 +174,8 @@ func inorderSuccessor(root *TreeNode, p *TreeNode) (ans *TreeNode) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -195,6 +205,8 @@ function inorderSuccessor(root: TreeNode | null, p: TreeNode | null): TreeNode | } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0200-0299/0286.Walls and Gates/README.md b/solution/0200-0299/0286.Walls and Gates/README.md index dca53a66c6225..8a56280078cec 100644 --- a/solution/0200-0299/0286.Walls and Gates/README.md +++ b/solution/0200-0299/0286.Walls and Gates/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def wallsAndGates(self, rooms: List[List[int]]) -> None: @@ -100,6 +102,8 @@ class Solution: q.append((x, y)) ``` +#### Java + ```java class Solution { public void wallsAndGates(int[][] rooms) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func wallsAndGates(rooms [][]int) { m, n := len(rooms), len(rooms[0]) diff --git a/solution/0200-0299/0286.Walls and Gates/README_EN.md b/solution/0200-0299/0286.Walls and Gates/README_EN.md index ffb789994f065..967d3a43853c6 100644 --- a/solution/0200-0299/0286.Walls and Gates/README_EN.md +++ b/solution/0200-0299/0286.Walls and Gates/README_EN.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def wallsAndGates(self, rooms: List[List[int]]) -> None: @@ -84,6 +86,8 @@ class Solution: q.append((x, y)) ``` +#### Java + ```java class Solution { public void wallsAndGates(int[][] rooms) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func wallsAndGates(rooms [][]int) { m, n := len(rooms), len(rooms[0]) diff --git a/solution/0200-0299/0287.Find the Duplicate Number/README.md b/solution/0200-0299/0287.Find the Duplicate Number/README.md index 3de770ac360ef..35ad64919c062 100644 --- a/solution/0200-0299/0287.Find the Duplicate Number/README.md +++ b/solution/0200-0299/0287.Find the Duplicate Number/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def findDuplicate(self, nums: List[int]) -> int: @@ -95,6 +97,8 @@ class Solution: return bisect_left(range(len(nums)), True, key=f) ``` +#### Java + ```java class Solution { public int findDuplicate(int[] nums) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func findDuplicate(nums []int) int { return sort.Search(len(nums), func(x int) bool { @@ -154,6 +162,8 @@ func findDuplicate(nums []int) int { } ``` +#### TypeScript + ```ts function findDuplicate(nums: number[]): number { let l = 0; @@ -176,6 +186,8 @@ function findDuplicate(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -201,6 +213,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0200-0299/0287.Find the Duplicate Number/README_EN.md b/solution/0200-0299/0287.Find the Duplicate Number/README_EN.md index f883fbecae4e1..74262e1a59e36 100644 --- a/solution/0200-0299/0287.Find the Duplicate Number/README_EN.md +++ b/solution/0200-0299/0287.Find the Duplicate Number/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(n \times \log n)$, where $n$ is the length of the arra +#### Python3 + ```python class Solution: def findDuplicate(self, nums: List[int]) -> int: @@ -89,6 +91,8 @@ class Solution: return bisect_left(range(len(nums)), True, key=f) ``` +#### Java + ```java class Solution { public int findDuplicate(int[] nums) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func findDuplicate(nums []int) int { return sort.Search(len(nums), func(x int) bool { @@ -148,6 +156,8 @@ func findDuplicate(nums []int) int { } ``` +#### TypeScript + ```ts function findDuplicate(nums: number[]): number { let l = 0; @@ -170,6 +180,8 @@ function findDuplicate(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -195,6 +207,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0200-0299/0288.Unique Word Abbreviation/README.md b/solution/0200-0299/0288.Unique Word Abbreviation/README.md index a3601ece59521..5a61c02863c33 100644 --- a/solution/0200-0299/0288.Unique Word Abbreviation/README.md +++ b/solution/0200-0299/0288.Unique Word Abbreviation/README.md @@ -94,6 +94,8 @@ validWordAbbr.isUnique("cake"); // 返回 true,因为 "cake" 已经存在于 +#### Python3 + ```python class ValidWordAbbr: def __init__(self, dictionary: List[str]): @@ -114,6 +116,8 @@ class ValidWordAbbr: # param_1 = obj.isUnique(word) ``` +#### Java + ```java class ValidWordAbbr { private Map> d = new HashMap<>(); @@ -142,6 +146,8 @@ class ValidWordAbbr { */ ``` +#### C++ + ```cpp class ValidWordAbbr { public: @@ -172,6 +178,8 @@ private: */ ``` +#### Go + ```go type ValidWordAbbr struct { d map[string]map[string]bool @@ -209,6 +217,8 @@ func abbr(s string) string { */ ``` +#### TypeScript + ```ts class ValidWordAbbr { private d: Map> = new Map(); diff --git a/solution/0200-0299/0288.Unique Word Abbreviation/README_EN.md b/solution/0200-0299/0288.Unique Word Abbreviation/README_EN.md index e3036af088491..da84fcc581fd9 100644 --- a/solution/0200-0299/0288.Unique Word Abbreviation/README_EN.md +++ b/solution/0200-0299/0288.Unique Word Abbreviation/README_EN.md @@ -90,6 +90,8 @@ In terms of time complexity, the time complexity of initializing the hash table +#### Python3 + ```python class ValidWordAbbr: def __init__(self, dictionary: List[str]): @@ -110,6 +112,8 @@ class ValidWordAbbr: # param_1 = obj.isUnique(word) ``` +#### Java + ```java class ValidWordAbbr { private Map> d = new HashMap<>(); @@ -138,6 +142,8 @@ class ValidWordAbbr { */ ``` +#### C++ + ```cpp class ValidWordAbbr { public: @@ -168,6 +174,8 @@ private: */ ``` +#### Go + ```go type ValidWordAbbr struct { d map[string]map[string]bool @@ -205,6 +213,8 @@ func abbr(s string) string { */ ``` +#### TypeScript + ```ts class ValidWordAbbr { private d: Map> = new Map(); diff --git a/solution/0200-0299/0289.Game of Life/README.md b/solution/0200-0299/0289.Game of Life/README.md index 061cc03f7df7d..7e527d059a3e0 100644 --- a/solution/0200-0299/0289.Game of Life/README.md +++ b/solution/0200-0299/0289.Game of Life/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def gameOfLife(self, board: List[List[int]]) -> None: @@ -108,6 +110,8 @@ class Solution: board[i][j] = 1 ``` +#### Java + ```java class Solution { public void gameOfLife(int[][] board) { @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -179,6 +185,8 @@ public: }; ``` +#### Go + ```go func gameOfLife(board [][]int) { m, n := len(board), len(board[0]) @@ -213,6 +221,8 @@ func gameOfLife(board [][]int) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify board in-place instead. @@ -251,6 +261,8 @@ function gameOfLife(board: number[][]): void { } ``` +#### Rust + ```rust const DIR: [(i32, i32); 8] = [ (-1, 0), @@ -309,6 +321,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public void GameOfLife(int[][] board) { diff --git a/solution/0200-0299/0289.Game of Life/README_EN.md b/solution/0200-0299/0289.Game of Life/README_EN.md index 881d63c3e6476..9baa60944727a 100644 --- a/solution/0200-0299/0289.Game of Life/README_EN.md +++ b/solution/0200-0299/0289.Game of Life/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(m \times n)$, where $m$ and $n$ are the number of rows +#### Python3 + ```python class Solution: def gameOfLife(self, board: List[List[int]]) -> None: @@ -105,6 +107,8 @@ class Solution: board[i][j] = 1 ``` +#### Java + ```java class Solution { public void gameOfLife(int[][] board) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go func gameOfLife(board [][]int) { m, n := len(board), len(board[0]) @@ -210,6 +218,8 @@ func gameOfLife(board [][]int) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify board in-place instead. @@ -248,6 +258,8 @@ function gameOfLife(board: number[][]): void { } ``` +#### Rust + ```rust const DIR: [(i32, i32); 8] = [ (-1, 0), @@ -306,6 +318,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public void GameOfLife(int[][] board) { diff --git a/solution/0200-0299/0290.Word Pattern/README.md b/solution/0200-0299/0290.Word Pattern/README.md index 42f87fc97a939..8c1aaaa462f76 100644 --- a/solution/0200-0299/0290.Word Pattern/README.md +++ b/solution/0200-0299/0290.Word Pattern/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def wordPattern(self, pattern: str, s: str) -> bool: @@ -88,6 +90,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean wordPattern(String pattern, String s) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func wordPattern(pattern string, s string) bool { ws := strings.Split(s, " ") @@ -162,6 +170,8 @@ func wordPattern(pattern string, s string) bool { } ``` +#### TypeScript + ```ts function wordPattern(pattern: string, s: string): boolean { const ws = s.split(' '); @@ -186,6 +196,8 @@ function wordPattern(pattern: string, s: string): boolean { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -217,6 +229,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public bool WordPattern(string pattern, string s) { diff --git a/solution/0200-0299/0290.Word Pattern/README_EN.md b/solution/0200-0299/0290.Word Pattern/README_EN.md index 39d2d66bd8dff..b04624d9d6ea3 100644 --- a/solution/0200-0299/0290.Word Pattern/README_EN.md +++ b/solution/0200-0299/0290.Word Pattern/README_EN.md @@ -73,6 +73,8 @@ The time complexity is $O(m + n)$ and the space complexity is $O(m + n)$. Here $ +#### Python3 + ```python class Solution: def wordPattern(self, pattern: str, s: str) -> bool: @@ -89,6 +91,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean wordPattern(String pattern, String s) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func wordPattern(pattern string, s string) bool { ws := strings.Split(s, " ") @@ -163,6 +171,8 @@ func wordPattern(pattern string, s string) bool { } ``` +#### TypeScript + ```ts function wordPattern(pattern: string, s: string): boolean { const ws = s.split(' '); @@ -187,6 +197,8 @@ function wordPattern(pattern: string, s: string): boolean { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -218,6 +230,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public bool WordPattern(string pattern, string s) { diff --git a/solution/0200-0299/0291.Word Pattern II/README.md b/solution/0200-0299/0291.Word Pattern II/README.md index a79a12293f42d..83782e3348245 100644 --- a/solution/0200-0299/0291.Word Pattern II/README.md +++ b/solution/0200-0299/0291.Word Pattern II/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def wordPatternMatch(self, pattern: str, s: str) -> bool: @@ -96,6 +98,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private Set vis; @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go func wordPatternMatch(pattern string, s string) bool { m, n := len(pattern), len(s) diff --git a/solution/0200-0299/0291.Word Pattern II/README_EN.md b/solution/0200-0299/0291.Word Pattern II/README_EN.md index e98b46c0c7d89..60337860508e4 100644 --- a/solution/0200-0299/0291.Word Pattern II/README_EN.md +++ b/solution/0200-0299/0291.Word Pattern II/README_EN.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def wordPatternMatch(self, pattern: str, s: str) -> bool: @@ -94,6 +96,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private Set vis; @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go func wordPatternMatch(pattern string, s string) bool { m, n := len(pattern), len(s) diff --git a/solution/0200-0299/0292.Nim Game/README.md b/solution/0200-0299/0292.Nim Game/README.md index e80af1d5c4e9c..0384d43a0b622 100644 --- a/solution/0200-0299/0292.Nim Game/README.md +++ b/solution/0200-0299/0292.Nim Game/README.md @@ -88,12 +88,16 @@ tags: +#### Python3 + ```python class Solution: def canWinNim(self, n: int) -> bool: return n % 4 != 0 ``` +#### Java + ```java class Solution { public boolean canWinNim(int n) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,18 +117,24 @@ public: }; ``` +#### Go + ```go func canWinNim(n int) bool { return n%4 != 0 } ``` +#### TypeScript + ```ts function canWinNim(n: number): boolean { return n % 4 != 0; } ``` +#### Rust + ```rust impl Solution { pub fn can_win_nim(n: i32) -> bool { diff --git a/solution/0200-0299/0292.Nim Game/README_EN.md b/solution/0200-0299/0292.Nim Game/README_EN.md index 102c9c34d003e..466846ea05cac 100644 --- a/solution/0200-0299/0292.Nim Game/README_EN.md +++ b/solution/0200-0299/0292.Nim Game/README_EN.md @@ -86,12 +86,16 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def canWinNim(self, n: int) -> bool: return n % 4 != 0 ``` +#### Java + ```java class Solution { public boolean canWinNim(int n) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,18 +115,24 @@ public: }; ``` +#### Go + ```go func canWinNim(n int) bool { return n%4 != 0 } ``` +#### TypeScript + ```ts function canWinNim(n: number): boolean { return n % 4 != 0; } ``` +#### Rust + ```rust impl Solution { pub fn can_win_nim(n: i32) -> bool { diff --git a/solution/0200-0299/0293.Flip Game/README.md b/solution/0200-0299/0293.Flip Game/README.md index 4655bd8495696..fc08a90cec290 100644 --- a/solution/0200-0299/0293.Flip Game/README.md +++ b/solution/0200-0299/0293.Flip Game/README.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def generatePossibleNextMoves(self, currentState: str) -> List[str]: @@ -76,6 +78,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List generatePossibleNextMoves(String currentState) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func generatePossibleNextMoves(currentState string) (ans []string) { s := []byte(currentState) @@ -126,6 +134,8 @@ func generatePossibleNextMoves(currentState string) (ans []string) { } ``` +#### TypeScript + ```ts function generatePossibleNextMoves(currentState: string): string[] { const s = currentState.split(''); diff --git a/solution/0200-0299/0293.Flip Game/README_EN.md b/solution/0200-0299/0293.Flip Game/README_EN.md index c77201d0d308b..0d0140c582caf 100644 --- a/solution/0200-0299/0293.Flip Game/README_EN.md +++ b/solution/0200-0299/0293.Flip Game/README_EN.md @@ -61,6 +61,8 @@ The time complexity is $O(n^2)$, where $n$ is the length of the string. Ignoring +#### Python3 + ```python class Solution: def generatePossibleNextMoves(self, currentState: str) -> List[str]: @@ -74,6 +76,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List generatePossibleNextMoves(String currentState) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func generatePossibleNextMoves(currentState string) (ans []string) { s := []byte(currentState) @@ -124,6 +132,8 @@ func generatePossibleNextMoves(currentState string) (ans []string) { } ``` +#### TypeScript + ```ts function generatePossibleNextMoves(currentState: string): string[] { const s = currentState.split(''); diff --git a/solution/0200-0299/0294.Flip Game II/README.md b/solution/0200-0299/0294.Flip Game II/README.md index 657cd2cf0fd31..1ffe153c17e55 100644 --- a/solution/0200-0299/0294.Flip Game II/README.md +++ b/solution/0200-0299/0294.Flip Game II/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def canWin(self, currentState: str) -> bool: @@ -84,6 +86,8 @@ class Solution: return dfs(mask) ``` +#### Java + ```java class Solution { private int n; @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func canWin(currentState string) bool { n := len(currentState) @@ -217,6 +225,8 @@ SG 数有如下性质: +#### Python3 + ```python class Solution: def canWin(self, currentState: str) -> bool: @@ -245,6 +255,8 @@ class Solution: return ans > 0 ``` +#### Java + ```java class Solution { private int n; @@ -286,6 +298,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -315,6 +329,8 @@ public: }; ``` +#### Go + ```go func canWin(currentState string) bool { n := len(currentState) diff --git a/solution/0200-0299/0294.Flip Game II/README_EN.md b/solution/0200-0299/0294.Flip Game II/README_EN.md index 81584a70e4fd2..eeb28e03f994e 100644 --- a/solution/0200-0299/0294.Flip Game II/README_EN.md +++ b/solution/0200-0299/0294.Flip Game II/README_EN.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def canWin(self, currentState: str) -> bool: @@ -83,6 +85,8 @@ class Solution: return dfs(mask) ``` +#### Java + ```java class Solution { private int n; @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func canWin(currentState string) bool { n := len(currentState) @@ -191,6 +199,8 @@ func canWin(currentState string) bool { +#### Python3 + ```python class Solution: def canWin(self, currentState: str) -> bool: @@ -219,6 +229,8 @@ class Solution: return ans > 0 ``` +#### Java + ```java class Solution { private int n; @@ -260,6 +272,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -289,6 +303,8 @@ public: }; ``` +#### Go + ```go func canWin(currentState string) bool { n := len(currentState) diff --git a/solution/0200-0299/0295.Find Median from Data Stream/README.md b/solution/0200-0299/0295.Find Median from Data Stream/README.md index 29f1442670401..bc5968be0dbf6 100644 --- a/solution/0200-0299/0295.Find Median from Data Stream/README.md +++ b/solution/0200-0299/0295.Find Median from Data Stream/README.md @@ -86,6 +86,8 @@ medianFinder.findMedian(); // return 2.0 +#### Python3 + ```python class MedianFinder: def __init__(self): @@ -113,6 +115,8 @@ class MedianFinder: # param_2 = obj.findMedian() ``` +#### Java + ```java class MedianFinder { private PriorityQueue q1 = new PriorityQueue<>(); @@ -146,6 +150,8 @@ class MedianFinder { */ ``` +#### C++ + ```cpp class MedianFinder { public: @@ -183,6 +189,8 @@ private: */ ``` +#### Go + ```go type MedianFinder struct { q1 hp @@ -228,6 +236,8 @@ func (h *hp) Pop() any { } ``` +#### TypeScript + ```ts class MedianFinder { private nums: number[]; @@ -269,6 +279,8 @@ class MedianFinder { */ ``` +#### Rust + ```rust struct MedianFinder { nums: Vec, @@ -313,6 +325,8 @@ impl MedianFinder { */ ``` +#### JavaScript + ```js /** * initialize your data structure here. @@ -348,6 +362,8 @@ MedianFinder.prototype.findMedian = function () { }; ``` +#### C# + ```cs public class MedianFinder { private List nums; diff --git a/solution/0200-0299/0295.Find Median from Data Stream/README_EN.md b/solution/0200-0299/0295.Find Median from Data Stream/README_EN.md index a001d0f2a4b56..fb466d3f535c4 100644 --- a/solution/0200-0299/0295.Find Median from Data Stream/README_EN.md +++ b/solution/0200-0299/0295.Find Median from Data Stream/README_EN.md @@ -81,6 +81,8 @@ medianFinder.findMedian(); // return 2.0 +#### Python3 + ```python class MedianFinder: def __init__(self): @@ -108,6 +110,8 @@ class MedianFinder: # param_2 = obj.findMedian() ``` +#### Java + ```java class MedianFinder { private PriorityQueue q1 = new PriorityQueue<>(); @@ -141,6 +145,8 @@ class MedianFinder { */ ``` +#### C++ + ```cpp class MedianFinder { public: @@ -178,6 +184,8 @@ private: */ ``` +#### Go + ```go type MedianFinder struct { q1 hp @@ -223,6 +231,8 @@ func (h *hp) Pop() any { } ``` +#### TypeScript + ```ts class MedianFinder { private nums: number[]; @@ -264,6 +274,8 @@ class MedianFinder { */ ``` +#### Rust + ```rust struct MedianFinder { nums: Vec, @@ -308,6 +320,8 @@ impl MedianFinder { */ ``` +#### JavaScript + ```js /** * initialize your data structure here. @@ -343,6 +357,8 @@ MedianFinder.prototype.findMedian = function () { }; ``` +#### C# + ```cs public class MedianFinder { private List nums; diff --git a/solution/0200-0299/0296.Best Meeting Point/README.md b/solution/0200-0299/0296.Best Meeting Point/README.md index 1e87620d167f9..1996e999e77ee 100644 --- a/solution/0200-0299/0296.Best Meeting Point/README.md +++ b/solution/0200-0299/0296.Best Meeting Point/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def minTotalDistance(self, grid: List[List[int]]) -> int: @@ -96,6 +98,8 @@ class Solution: return f(rows, i) + f(cols, j) ``` +#### Java + ```java class Solution { public int minTotalDistance(int[][] grid) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func minTotalDistance(grid [][]int) int { rows, cols := []int{}, []int{} @@ -188,6 +196,8 @@ func abs(x int) int { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/0200-0299/0296.Best Meeting Point/README_EN.md b/solution/0200-0299/0296.Best Meeting Point/README_EN.md index c794b7f76834c..b51994ccb726f 100644 --- a/solution/0200-0299/0296.Best Meeting Point/README_EN.md +++ b/solution/0200-0299/0296.Best Meeting Point/README_EN.md @@ -64,6 +64,8 @@ So return 6. +#### Python3 + ```python class Solution: def minTotalDistance(self, grid: List[List[int]]) -> int: @@ -82,6 +84,8 @@ class Solution: return f(rows, i) + f(cols, j) ``` +#### Java + ```java class Solution { public int minTotalDistance(int[][] grid) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func minTotalDistance(grid [][]int) int { rows, cols := []int{}, []int{} @@ -174,6 +182,8 @@ func abs(x int) int { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/0200-0299/0297.Serialize and Deserialize Binary Tree/README.md b/solution/0200-0299/0297.Serialize and Deserialize Binary Tree/README.md index b757a4418513d..76dc6b6cb769f 100644 --- a/solution/0200-0299/0297.Serialize and Deserialize Binary Tree/README.md +++ b/solution/0200-0299/0297.Serialize and Deserialize Binary Tree/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode(object): @@ -133,6 +135,8 @@ class Codec: # ans = deser.deserialize(ser.serialize(root)) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -197,6 +201,8 @@ public class Codec { // TreeNode ans = deser.deserialize(ser.serialize(root)); ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -250,6 +256,8 @@ public: // TreeNode* ans = deser.deserialize(ser.serialize(root)); ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -285,6 +293,8 @@ function deserialize(data: string): TreeNode | null { */ ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -357,6 +367,8 @@ impl Codec { */ ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -428,6 +440,8 @@ const rdeserialize = dataList => { +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0200-0299/0297.Serialize and Deserialize Binary Tree/README_EN.md b/solution/0200-0299/0297.Serialize and Deserialize Binary Tree/README_EN.md index cb39b2f71afd4..0bd06ee42ce40 100644 --- a/solution/0200-0299/0297.Serialize and Deserialize Binary Tree/README_EN.md +++ b/solution/0200-0299/0297.Serialize and Deserialize Binary Tree/README_EN.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode(object): @@ -117,6 +119,8 @@ class Codec: # ans = deser.deserialize(ser.serialize(root)) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -181,6 +185,8 @@ public class Codec { // TreeNode ans = deser.deserialize(ser.serialize(root)); ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -234,6 +240,8 @@ public: // TreeNode* ans = deser.deserialize(ser.serialize(root)); ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -269,6 +277,8 @@ function deserialize(data: string): TreeNode | null { */ ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -341,6 +351,8 @@ impl Codec { */ ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -412,6 +424,8 @@ const rdeserialize = dataList => { +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0200-0299/0298.Binary Tree Longest Consecutive Sequence/README.md b/solution/0200-0299/0298.Binary Tree Longest Consecutive Sequence/README.md index 544b6dfb28a88..13816e5cc01f6 100644 --- a/solution/0200-0299/0298.Binary Tree Longest Consecutive Sequence/README.md +++ b/solution/0200-0299/0298.Binary Tree Longest Consecutive Sequence/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -213,6 +221,8 @@ func longestConsecutive(root *TreeNode) (ans int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0200-0299/0298.Binary Tree Longest Consecutive Sequence/README_EN.md b/solution/0200-0299/0298.Binary Tree Longest Consecutive Sequence/README_EN.md index f403d468eef6f..45c48cda069e7 100644 --- a/solution/0200-0299/0298.Binary Tree Longest Consecutive Sequence/README_EN.md +++ b/solution/0200-0299/0298.Binary Tree Longest Consecutive Sequence/README_EN.md @@ -59,6 +59,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -200,6 +208,8 @@ func longestConsecutive(root *TreeNode) (ans int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0200-0299/0299.Bulls and Cows/README.md b/solution/0200-0299/0299.Bulls and Cows/README.md index ce1e324869e65..c935d7282a84b 100644 --- a/solution/0200-0299/0299.Bulls and Cows/README.md +++ b/solution/0200-0299/0299.Bulls and Cows/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def getHint(self, secret: str, guess: str) -> str: @@ -101,6 +103,8 @@ class Solution: return f"{x}A{y}B" ``` +#### Java + ```java class Solution { public String getHint(String secret, String guess) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func getHint(secret string, guess string) string { x, y := 0, 0 @@ -170,6 +178,8 @@ func getHint(secret string, guess string) string { } ``` +#### TypeScript + ```ts function getHint(secret: string, guess: string): string { const cnt1: number[] = Array(10).fill(0); @@ -191,6 +201,8 @@ function getHint(secret: string, guess: string): string { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0200-0299/0299.Bulls and Cows/README_EN.md b/solution/0200-0299/0299.Bulls and Cows/README_EN.md index 0f38d8000b5e5..055125ac160ab 100644 --- a/solution/0200-0299/0299.Bulls and Cows/README_EN.md +++ b/solution/0200-0299/0299.Bulls and Cows/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(n)$, where $n$ is the length of the secret number and +#### Python3 + ```python class Solution: def getHint(self, secret: str, guess: str) -> str: @@ -98,6 +100,8 @@ class Solution: return f"{x}A{y}B" ``` +#### Java + ```java class Solution { public String getHint(String secret, String guess) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func getHint(secret string, guess string) string { x, y := 0, 0 @@ -167,6 +175,8 @@ func getHint(secret string, guess string) string { } ``` +#### TypeScript + ```ts function getHint(secret: string, guess: string): string { const cnt1: number[] = Array(10).fill(0); @@ -188,6 +198,8 @@ function getHint(secret: string, guess: string): string { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0300-0399/0300.Longest Increasing Subsequence/README.md b/solution/0300-0399/0300.Longest Increasing Subsequence/README.md index 9fd9da724bff1..2036fe9b5040a 100644 --- a/solution/0300-0399/0300.Longest Increasing Subsequence/README.md +++ b/solution/0300-0399/0300.Longest Increasing Subsequence/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def lengthOfLIS(self, nums: List[int]) -> int: @@ -92,6 +94,8 @@ class Solution: return max(f) ``` +#### Java + ```java class Solution { public int lengthOfLIS(int[] nums) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func lengthOfLIS(nums []int) int { n := len(nums) @@ -150,6 +158,8 @@ func lengthOfLIS(nums []int) int { } ``` +#### TypeScript + ```ts function lengthOfLIS(nums: number[]): number { const n = nums.length; @@ -165,6 +175,8 @@ function lengthOfLIS(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn length_of_lis(nums: Vec) -> i32 { @@ -200,6 +212,8 @@ impl Solution { +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n: int): @@ -231,6 +245,8 @@ class Solution: return tree.query(m) ``` +#### Java + ```java class Solution { public int lengthOfLIS(int[] nums) { @@ -293,6 +309,8 @@ class BinaryIndexedTree { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -338,6 +356,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -386,6 +406,8 @@ func lengthOfLIS(nums []int) int { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; diff --git a/solution/0300-0399/0300.Longest Increasing Subsequence/README_EN.md b/solution/0300-0399/0300.Longest Increasing Subsequence/README_EN.md index 025f47e193cf9..f6fd4ff1fb179 100644 --- a/solution/0300-0399/0300.Longest Increasing Subsequence/README_EN.md +++ b/solution/0300-0399/0300.Longest Increasing Subsequence/README_EN.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def lengthOfLIS(self, nums: List[int]) -> int: @@ -76,6 +78,8 @@ class Solution: return max(f) ``` +#### Java + ```java class Solution { public int lengthOfLIS(int[] nums) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func lengthOfLIS(nums []int) int { n := len(nums) @@ -134,6 +142,8 @@ func lengthOfLIS(nums []int) int { } ``` +#### TypeScript + ```ts function lengthOfLIS(nums: number[]): number { const n = nums.length; @@ -149,6 +159,8 @@ function lengthOfLIS(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn length_of_lis(nums: Vec) -> i32 { @@ -176,6 +188,8 @@ impl Solution { +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n: int): @@ -207,6 +221,8 @@ class Solution: return tree.query(m) ``` +#### Java + ```java class Solution { public int lengthOfLIS(int[] nums) { @@ -269,6 +285,8 @@ class BinaryIndexedTree { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -314,6 +332,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -362,6 +382,8 @@ func lengthOfLIS(nums []int) int { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; diff --git a/solution/0300-0399/0301.Remove Invalid Parentheses/README.md b/solution/0300-0399/0301.Remove Invalid Parentheses/README.md index b6bee8d53fac4..d8c59e4f78f87 100644 --- a/solution/0300-0399/0301.Remove Invalid Parentheses/README.md +++ b/solution/0300-0399/0301.Remove Invalid Parentheses/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def removeInvalidParentheses(self, s: str) -> List[str]: @@ -119,6 +121,8 @@ class Solution: return list(ans) ``` +#### Java + ```java class Solution { private String s; @@ -168,6 +172,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -213,6 +219,8 @@ public: }; ``` +#### Go + ```go func removeInvalidParentheses(s string) []string { vis := map[string]bool{} diff --git a/solution/0300-0399/0301.Remove Invalid Parentheses/README_EN.md b/solution/0300-0399/0301.Remove Invalid Parentheses/README_EN.md index 105d12797142d..eca424c2bde69 100644 --- a/solution/0300-0399/0301.Remove Invalid Parentheses/README_EN.md +++ b/solution/0300-0399/0301.Remove Invalid Parentheses/README_EN.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def removeInvalidParentheses(self, s: str) -> List[str]: @@ -94,6 +96,8 @@ class Solution: return list(ans) ``` +#### Java + ```java class Solution { private String s; @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go func removeInvalidParentheses(s string) []string { vis := map[string]bool{} diff --git a/solution/0300-0399/0302.Smallest Rectangle Enclosing Black Pixels/README.md b/solution/0300-0399/0302.Smallest Rectangle Enclosing Black Pixels/README.md index 960a046d36c77..1e297a15af433 100644 --- a/solution/0300-0399/0302.Smallest Rectangle Enclosing Black Pixels/README.md +++ b/solution/0300-0399/0302.Smallest Rectangle Enclosing Black Pixels/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def minArea(self, image: List[List[str]], x: int, y: int) -> int: @@ -122,6 +124,8 @@ class Solution: return (d - u + 1) * (r - l + 1) ``` +#### Java + ```java class Solution { @@ -191,6 +195,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -248,6 +254,8 @@ public: }; ``` +#### Go + ```go func minArea(image [][]byte, x int, y int) int { m, n := len(image), len(image[0]) diff --git a/solution/0300-0399/0302.Smallest Rectangle Enclosing Black Pixels/README_EN.md b/solution/0300-0399/0302.Smallest Rectangle Enclosing Black Pixels/README_EN.md index c3405d2d80014..e49622a26ceda 100644 --- a/solution/0300-0399/0302.Smallest Rectangle Enclosing Black Pixels/README_EN.md +++ b/solution/0300-0399/0302.Smallest Rectangle Enclosing Black Pixels/README_EN.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def minArea(self, image: List[List[str]], x: int, y: int) -> int: @@ -118,6 +120,8 @@ class Solution: return (d - u + 1) * (r - l + 1) ``` +#### Java + ```java class Solution { @@ -187,6 +191,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -244,6 +250,8 @@ public: }; ``` +#### Go + ```go func minArea(image [][]byte, x int, y int) int { m, n := len(image), len(image[0]) diff --git a/solution/0300-0399/0303.Range Sum Query - Immutable/README.md b/solution/0300-0399/0303.Range Sum Query - Immutable/README.md index f452b55c44bdc..7b6a1591a8a99 100644 --- a/solution/0300-0399/0303.Range Sum Query - Immutable/README.md +++ b/solution/0300-0399/0303.Range Sum Query - Immutable/README.md @@ -74,6 +74,8 @@ numArray.sumRange(0, 5); // return -3 ((-2) + 0 + 3 + (-5) + 2 + (-1)) +#### Python3 + ```python class NumArray: def __init__(self, nums: List[int]): @@ -88,6 +90,8 @@ class NumArray: # param_1 = obj.sumRange(left,right) ``` +#### Java + ```java class NumArray { private int[] s; @@ -112,6 +116,8 @@ class NumArray { */ ``` +#### C++ + ```cpp class NumArray { public: @@ -138,6 +144,8 @@ private: */ ``` +#### Go + ```go type NumArray struct { s []int @@ -163,6 +171,8 @@ func (this *NumArray) SumRange(left int, right int) int { */ ``` +#### TypeScript + ```ts class NumArray { private s: number[]; @@ -187,6 +197,8 @@ class NumArray { */ ``` +#### Rust + ```rust struct NumArray { s: Vec, @@ -216,6 +228,8 @@ impl NumArray { */ ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -244,6 +258,8 @@ NumArray.prototype.sumRange = function (left, right) { */ ``` +#### PHP + ```php class NumArray { /** @@ -273,6 +289,8 @@ class NumArray { */ ``` +#### C + ```c typedef struct { int* s; diff --git a/solution/0300-0399/0303.Range Sum Query - Immutable/README_EN.md b/solution/0300-0399/0303.Range Sum Query - Immutable/README_EN.md index 7c755ced04664..ebec301258068 100644 --- a/solution/0300-0399/0303.Range Sum Query - Immutable/README_EN.md +++ b/solution/0300-0399/0303.Range Sum Query - Immutable/README_EN.md @@ -72,6 +72,8 @@ The time complexity for initializing the prefix sum array $s$ is $O(n)$, and the +#### Python3 + ```python class NumArray: def __init__(self, nums: List[int]): @@ -86,6 +88,8 @@ class NumArray: # param_1 = obj.sumRange(left,right) ``` +#### Java + ```java class NumArray { private int[] s; @@ -110,6 +114,8 @@ class NumArray { */ ``` +#### C++ + ```cpp class NumArray { public: @@ -136,6 +142,8 @@ private: */ ``` +#### Go + ```go type NumArray struct { s []int @@ -161,6 +169,8 @@ func (this *NumArray) SumRange(left int, right int) int { */ ``` +#### TypeScript + ```ts class NumArray { private s: number[]; @@ -185,6 +195,8 @@ class NumArray { */ ``` +#### Rust + ```rust struct NumArray { s: Vec, @@ -214,6 +226,8 @@ impl NumArray { */ ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -242,6 +256,8 @@ NumArray.prototype.sumRange = function (left, right) { */ ``` +#### PHP + ```php class NumArray { /** @@ -271,6 +287,8 @@ class NumArray { */ ``` +#### C + ```c typedef struct { int* s; diff --git a/solution/0300-0399/0304.Range Sum Query 2D - Immutable/README.md b/solution/0300-0399/0304.Range Sum Query 2D - Immutable/README.md index c1853823587c8..40ef16469c03f 100644 --- a/solution/0300-0399/0304.Range Sum Query 2D - Immutable/README.md +++ b/solution/0300-0399/0304.Range Sum Query 2D - Immutable/README.md @@ -92,6 +92,8 @@ $$ +#### Python3 + ```python class NumMatrix: def __init__(self, matrix: List[List[int]]): @@ -117,6 +119,8 @@ class NumMatrix: # param_1 = obj.sumRegion(row1,col1,row2,col2) ``` +#### Java + ```java class NumMatrix { private int[][] s; @@ -143,6 +147,8 @@ class NumMatrix { */ ``` +#### C++ + ```cpp class NumMatrix { public: @@ -170,6 +176,8 @@ public: */ ``` +#### Go + ```go type NumMatrix struct { s [][]int @@ -200,6 +208,8 @@ func (this *NumMatrix) SumRegion(row1 int, col1 int, row2 int, col2 int) int { */ ``` +#### TypeScript + ```ts class NumMatrix { private s: number[][]; @@ -233,6 +243,8 @@ class NumMatrix { */ ``` +#### Rust + ```rust /** @@ -297,6 +309,8 @@ impl NumMatrix { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix diff --git a/solution/0300-0399/0304.Range Sum Query 2D - Immutable/README_EN.md b/solution/0300-0399/0304.Range Sum Query 2D - Immutable/README_EN.md index e2ee9d71d8420..ad1dfbf7f8d5e 100644 --- a/solution/0300-0399/0304.Range Sum Query 2D - Immutable/README_EN.md +++ b/solution/0300-0399/0304.Range Sum Query 2D - Immutable/README_EN.md @@ -91,6 +91,8 @@ The time complexity for initializing is $O(m \times n)$, and the time complexity +#### Python3 + ```python class NumMatrix: def __init__(self, matrix: List[List[int]]): @@ -116,6 +118,8 @@ class NumMatrix: # param_1 = obj.sumRegion(row1,col1,row2,col2) ``` +#### Java + ```java class NumMatrix { private int[][] s; @@ -142,6 +146,8 @@ class NumMatrix { */ ``` +#### C++ + ```cpp class NumMatrix { public: @@ -169,6 +175,8 @@ public: */ ``` +#### Go + ```go type NumMatrix struct { s [][]int @@ -199,6 +207,8 @@ func (this *NumMatrix) SumRegion(row1 int, col1 int, row2 int, col2 int) int { */ ``` +#### TypeScript + ```ts class NumMatrix { private s: number[][]; @@ -232,6 +242,8 @@ class NumMatrix { */ ``` +#### Rust + ```rust /** * Your NumMatrix object will be instantiated and called as such: @@ -295,6 +307,8 @@ impl NumMatrix { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix diff --git a/solution/0300-0399/0305.Number of Islands II/README.md b/solution/0300-0399/0305.Number of Islands II/README.md index 3cf7fdbf87ac6..b8099434094cd 100644 --- a/solution/0300-0399/0305.Number of Islands II/README.md +++ b/solution/0300-0399/0305.Number of Islands II/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class UnionFind: def __init__(self, n: int): @@ -129,6 +131,8 @@ class Solution: return ans ``` +#### Java + ```java class UnionFind { private final int[] p; @@ -195,6 +199,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -260,6 +266,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p, size []int @@ -325,6 +333,8 @@ func numIslands2(m int, n int, positions [][]int) (ans []int) { } ``` +#### TypeScript + ```ts class UnionFind { p: number[]; diff --git a/solution/0300-0399/0305.Number of Islands II/README_EN.md b/solution/0300-0399/0305.Number of Islands II/README_EN.md index 37de8207a65b0..015aaa8407495 100644 --- a/solution/0300-0399/0305.Number of Islands II/README_EN.md +++ b/solution/0300-0399/0305.Number of Islands II/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(k \times \alpha(m \times n))$ or $O(k \times \log(m \t +#### Python3 + ```python class UnionFind: def __init__(self, n: int): @@ -127,6 +129,8 @@ class Solution: return ans ``` +#### Java + ```java class UnionFind { private final int[] p; @@ -193,6 +197,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -258,6 +264,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p, size []int @@ -323,6 +331,8 @@ func numIslands2(m int, n int, positions [][]int) (ans []int) { } ``` +#### TypeScript + ```ts class UnionFind { p: number[]; diff --git a/solution/0300-0399/0306.Additive Number/README.md b/solution/0300-0399/0306.Additive Number/README.md index 449f1242110fe..c97246ab26233 100644 --- a/solution/0300-0399/0306.Additive Number/README.md +++ b/solution/0300-0399/0306.Additive Number/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def isAdditiveNumber(self, num: str) -> bool: @@ -91,6 +93,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean isAdditiveNumber(String num) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func isAdditiveNumber(num string) bool { n := len(num) diff --git a/solution/0300-0399/0306.Additive Number/README_EN.md b/solution/0300-0399/0306.Additive Number/README_EN.md index f2d8fa728ce96..757503224b148 100644 --- a/solution/0300-0399/0306.Additive Number/README_EN.md +++ b/solution/0300-0399/0306.Additive Number/README_EN.md @@ -67,6 +67,8 @@ The additive sequence is: 1, 99, 100, 199.  +#### Python3 + ```python class Solution: def isAdditiveNumber(self, num: str) -> bool: @@ -93,6 +95,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean isAdditiveNumber(String num) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func isAdditiveNumber(num string) bool { n := len(num) diff --git a/solution/0300-0399/0307.Range Sum Query - Mutable/README.md b/solution/0300-0399/0307.Range Sum Query - Mutable/README.md index 01f07dd400cbb..73f33a3388a62 100644 --- a/solution/0300-0399/0307.Range Sum Query - Mutable/README.md +++ b/solution/0300-0399/0307.Range Sum Query - Mutable/README.md @@ -92,6 +92,8 @@ numArray.sumRange(0, 2); // 返回 1 + 2 + 5 = 8 +#### Python3 + ```python class BinaryIndexedTree: __slots__ = ["n", "c"] @@ -135,6 +137,8 @@ class NumArray: # param_2 = obj.sumRange(left,right) ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -191,6 +195,8 @@ class NumArray { */ ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -246,6 +252,8 @@ public: */ ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -299,6 +307,8 @@ func (t *NumArray) SumRange(left int, right int) int { */ ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; @@ -355,6 +365,8 @@ class NumArray { */ ``` +#### C# + ```cs class BinaryIndexedTree { private int n; @@ -430,6 +442,8 @@ public class NumArray { +#### Python3 + ```python class Node: __slots__ = ["l", "r", "v"] @@ -502,6 +516,8 @@ class NumArray: # param_2 = obj.sumRange(left,right) ``` +#### Java + ```java class Node { int l; @@ -594,6 +610,8 @@ class NumArray { */ ``` +#### C++ + ```cpp class Node { public: @@ -680,6 +698,8 @@ public: */ ``` +#### Go + ```go type Node struct { l, r, v int @@ -774,6 +794,8 @@ func (this *NumArray) SumRange(left int, right int) int { */ ``` +#### TypeScript + ```ts class Node { l: number; @@ -866,6 +888,8 @@ class NumArray { */ ``` +#### C# + ```cs public class Node { public int l; diff --git a/solution/0300-0399/0307.Range Sum Query - Mutable/README_EN.md b/solution/0300-0399/0307.Range Sum Query - Mutable/README_EN.md index f4adda679ce2e..380df451ebaaf 100644 --- a/solution/0300-0399/0307.Range Sum Query - Mutable/README_EN.md +++ b/solution/0300-0399/0307.Range Sum Query - Mutable/README_EN.md @@ -73,6 +73,8 @@ numArray.sumRange(0, 2); // return 1 + 2 + 5 = 8 +#### Python3 + ```python class BinaryIndexedTree: __slots__ = ["n", "c"] @@ -116,6 +118,8 @@ class NumArray: # param_2 = obj.sumRange(left,right) ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -172,6 +176,8 @@ class NumArray { */ ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -227,6 +233,8 @@ public: */ ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -280,6 +288,8 @@ func (t *NumArray) SumRange(left int, right int) int { */ ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; @@ -336,6 +346,8 @@ class NumArray { */ ``` +#### C# + ```cs class BinaryIndexedTree { private int n; @@ -402,6 +414,8 @@ public class NumArray { +#### Python3 + ```python class Node: __slots__ = ["l", "r", "v"] @@ -474,6 +488,8 @@ class NumArray: # param_2 = obj.sumRange(left,right) ``` +#### Java + ```java class Node { int l; @@ -566,6 +582,8 @@ class NumArray { */ ``` +#### C++ + ```cpp class Node { public: @@ -652,6 +670,8 @@ public: */ ``` +#### Go + ```go type Node struct { l, r, v int @@ -746,6 +766,8 @@ func (this *NumArray) SumRange(left int, right int) int { */ ``` +#### TypeScript + ```ts class Node { l: number; @@ -838,6 +860,8 @@ class NumArray { */ ``` +#### C# + ```cs public class Node { public int l; diff --git a/solution/0300-0399/0308.Range Sum Query 2D - Mutable/README.md b/solution/0300-0399/0308.Range Sum Query 2D - Mutable/README.md index ce5b40bd334fc..54fffba910dfb 100644 --- a/solution/0300-0399/0308.Range Sum Query 2D - Mutable/README.md +++ b/solution/0300-0399/0308.Range Sum Query 2D - Mutable/README.md @@ -90,6 +90,8 @@ numMatrix.sumRegion(2, 1, 4, 3); // 返回 10 (即,右侧红色矩形的和) +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -141,6 +143,8 @@ class NumMatrix: # param_2 = obj.sumRegion(row1,col1,row2,col2) ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -212,6 +216,8 @@ class NumMatrix { */ ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -282,6 +288,8 @@ public: */ ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -370,6 +378,8 @@ func (this *NumMatrix) SumRegion(row1 int, col1 int, row2 int, col2 int) int { +#### Python3 + ```python class Node: def __init__(self): @@ -443,6 +453,8 @@ class NumMatrix: # param_2 = obj.sumRegion(row1,col1,row2,col2) ``` +#### Java + ```java class Node { int l; @@ -545,6 +557,8 @@ class NumMatrix { */ ``` +#### C++ + ```cpp class Node { public: diff --git a/solution/0300-0399/0308.Range Sum Query 2D - Mutable/README_EN.md b/solution/0300-0399/0308.Range Sum Query 2D - Mutable/README_EN.md index 1d0ff72035dc7..26394577f46b0 100644 --- a/solution/0300-0399/0308.Range Sum Query 2D - Mutable/README_EN.md +++ b/solution/0300-0399/0308.Range Sum Query 2D - Mutable/README_EN.md @@ -79,6 +79,8 @@ numMatrix.sumRegion(2, 1, 4, 3); // return 10 (i.e. sum of the right red rectang +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -130,6 +132,8 @@ class NumMatrix: # param_2 = obj.sumRegion(row1,col1,row2,col2) ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -201,6 +205,8 @@ class NumMatrix { */ ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -271,6 +277,8 @@ public: */ ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -352,6 +360,8 @@ func (this *NumMatrix) SumRegion(row1 int, col1 int, row2 int, col2 int) int { +#### Python3 + ```python class Node: def __init__(self): @@ -425,6 +435,8 @@ class NumMatrix: # param_2 = obj.sumRegion(row1,col1,row2,col2) ``` +#### Java + ```java class Node { int l; @@ -527,6 +539,8 @@ class NumMatrix { */ ``` +#### C++ + ```cpp class Node { public: diff --git a/solution/0300-0399/0309.Best Time to Buy and Sell Stock with Cooldown/README.md b/solution/0300-0399/0309.Best Time to Buy and Sell Stock with Cooldown/README.md index e36e77ad3974e..62fe89e92d444 100644 --- a/solution/0300-0399/0309.Best Time to Buy and Sell Stock with Cooldown/README.md +++ b/solution/0300-0399/0309.Best Time to Buy and Sell Stock with Cooldown/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def maxProfit(self, prices: List[int]) -> int: @@ -93,6 +95,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private int[] prices; @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func maxProfit(prices []int) int { n := len(prices) @@ -177,6 +185,8 @@ func maxProfit(prices []int) int { } ``` +#### TypeScript + ```ts function maxProfit(prices: number[]): number { const n = prices.length; @@ -220,6 +230,8 @@ function maxProfit(prices: number[]): number { +#### Python3 + ```python class Solution: def maxProfit(self, prices: List[int]) -> int: @@ -232,6 +244,8 @@ class Solution: return f[n - 1][0] ``` +#### Java + ```java class Solution { public int maxProfit(int[] prices) { @@ -247,6 +261,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -264,6 +280,8 @@ public: }; ``` +#### Go + ```go func maxProfit(prices []int) int { n := len(prices) @@ -281,6 +299,8 @@ func maxProfit(prices []int) int { } ``` +#### TypeScript + ```ts function maxProfit(prices: number[]): number { const n = prices.length; @@ -304,6 +324,8 @@ function maxProfit(prices: number[]): number { +#### Python3 + ```python class Solution: def maxProfit(self, prices: List[int]) -> int: @@ -313,6 +335,8 @@ class Solution: return f0 ``` +#### Java + ```java class Solution { public int maxProfit(int[] prices) { @@ -328,6 +352,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -344,6 +370,8 @@ public: }; ``` +#### Go + ```go func maxProfit(prices []int) int { f, f0, f1 := 0, 0, -prices[0] @@ -354,6 +382,8 @@ func maxProfit(prices []int) int { } ``` +#### TypeScript + ```ts function maxProfit(prices: number[]): number { let [f, f0, f1] = [0, 0, -prices[0]]; diff --git a/solution/0300-0399/0309.Best Time to Buy and Sell Stock with Cooldown/README_EN.md b/solution/0300-0399/0309.Best Time to Buy and Sell Stock with Cooldown/README_EN.md index 70e8a38cc7966..126d7dfb256f5 100644 --- a/solution/0300-0399/0309.Best Time to Buy and Sell Stock with Cooldown/README_EN.md +++ b/solution/0300-0399/0309.Best Time to Buy and Sell Stock with Cooldown/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python class Solution: def maxProfit(self, prices: List[int]) -> int: @@ -92,6 +94,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private int[] prices; @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func maxProfit(prices []int) int { n := len(prices) @@ -176,6 +184,8 @@ func maxProfit(prices []int) int { } ``` +#### TypeScript + ```ts function maxProfit(prices: number[]): number { const n = prices.length; @@ -219,6 +229,8 @@ We notice that the transition of state $f[i][]$ is only related to $f[i - 1][]$ +#### Python3 + ```python class Solution: def maxProfit(self, prices: List[int]) -> int: @@ -231,6 +243,8 @@ class Solution: return f[n - 1][0] ``` +#### Java + ```java class Solution { public int maxProfit(int[] prices) { @@ -246,6 +260,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -263,6 +279,8 @@ public: }; ``` +#### Go + ```go func maxProfit(prices []int) int { n := len(prices) @@ -280,6 +298,8 @@ func maxProfit(prices []int) int { } ``` +#### TypeScript + ```ts function maxProfit(prices: number[]): number { const n = prices.length; @@ -303,6 +323,8 @@ function maxProfit(prices: number[]): number { +#### Python3 + ```python class Solution: def maxProfit(self, prices: List[int]) -> int: @@ -312,6 +334,8 @@ class Solution: return f0 ``` +#### Java + ```java class Solution { public int maxProfit(int[] prices) { @@ -327,6 +351,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -343,6 +369,8 @@ public: }; ``` +#### Go + ```go func maxProfit(prices []int) int { f, f0, f1 := 0, 0, -prices[0] @@ -353,6 +381,8 @@ func maxProfit(prices []int) int { } ``` +#### TypeScript + ```ts function maxProfit(prices: number[]): number { let [f, f0, f1] = [0, 0, -prices[0]]; diff --git a/solution/0300-0399/0310.Minimum Height Trees/README.md b/solution/0300-0399/0310.Minimum Height Trees/README.md index 08cdfa1c297e5..bd50fb657b545 100644 --- a/solution/0300-0399/0310.Minimum Height Trees/README.md +++ b/solution/0300-0399/0310.Minimum Height Trees/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def findMinHeightTrees(self, n: int, edges: List[List[int]]) -> List[int]: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List findMinHeightTrees(int n, int[][] edges) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -183,6 +189,8 @@ public: }; ``` +#### Go + ```go func findMinHeightTrees(n int, edges [][]int) (ans []int) { if n == 1 { @@ -221,6 +229,8 @@ func findMinHeightTrees(n int, edges [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function findMinHeightTrees(n: number, edges: number[][]): number[] { if (n === 1) { diff --git a/solution/0300-0399/0310.Minimum Height Trees/README_EN.md b/solution/0300-0399/0310.Minimum Height Trees/README_EN.md index f9ecfbe1b55c4..27b8d2a20cb5b 100644 --- a/solution/0300-0399/0310.Minimum Height Trees/README_EN.md +++ b/solution/0300-0399/0310.Minimum Height Trees/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(n)$ and the space complexity is $O(n)$, where $n$ is t +#### Python3 + ```python class Solution: def findMinHeightTrees(self, n: int, edges: List[List[int]]) -> List[int]: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List findMinHeightTrees(int n, int[][] edges) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -178,6 +184,8 @@ public: }; ``` +#### Go + ```go func findMinHeightTrees(n int, edges [][]int) (ans []int) { if n == 1 { @@ -216,6 +224,8 @@ func findMinHeightTrees(n int, edges [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function findMinHeightTrees(n: number, edges: number[][]): number[] { if (n === 1) { diff --git a/solution/0300-0399/0311.Sparse Matrix Multiplication/README.md b/solution/0300-0399/0311.Sparse Matrix Multiplication/README.md index f4dadf3b33288..4fcc8167ca2ef 100644 --- a/solution/0300-0399/0311.Sparse Matrix Multiplication/README.md +++ b/solution/0300-0399/0311.Sparse Matrix Multiplication/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def multiply(self, mat1: List[List[int]], mat2: List[List[int]]) -> List[List[int]]: @@ -76,6 +78,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] multiply(int[][] mat1, int[][] mat2) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func multiply(mat1 [][]int, mat2 [][]int) [][]int { m, n := len(mat1), len(mat2[0]) @@ -129,6 +137,8 @@ func multiply(mat1 [][]int, mat2 [][]int) [][]int { } ``` +#### TypeScript + ```ts function multiply(mat1: number[][], mat2: number[][]): number[][] { const [m, n] = [mat1.length, mat2[0].length]; @@ -160,6 +170,8 @@ function multiply(mat1: number[][], mat2: number[][]): number[][] { +#### Python3 + ```python class Solution: def multiply(self, mat1: List[List[int]], mat2: List[List[int]]) -> List[List[int]]: @@ -182,6 +194,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] multiply(int[][] mat1, int[][] mat2) { @@ -217,6 +231,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -249,6 +265,8 @@ public: }; ``` +#### Go + ```go func multiply(mat1 [][]int, mat2 [][]int) [][]int { m, n := len(mat1), len(mat2[0]) @@ -283,6 +301,8 @@ func multiply(mat1 [][]int, mat2 [][]int) [][]int { } ``` +#### TypeScript + ```ts function multiply(mat1: number[][], mat2: number[][]): number[][] { const [m, n] = [mat1.length, mat2[0].length]; diff --git a/solution/0300-0399/0311.Sparse Matrix Multiplication/README_EN.md b/solution/0300-0399/0311.Sparse Matrix Multiplication/README_EN.md index d1caad983dd46..0dddfdc5677d3 100644 --- a/solution/0300-0399/0311.Sparse Matrix Multiplication/README_EN.md +++ b/solution/0300-0399/0311.Sparse Matrix Multiplication/README_EN.md @@ -60,6 +60,8 @@ The time complexity is $O(m \times n \times k)$, and the space complexity is $O( +#### Python3 + ```python class Solution: def multiply(self, mat1: List[List[int]], mat2: List[List[int]]) -> List[List[int]]: @@ -72,6 +74,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] multiply(int[][] mat1, int[][] mat2) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func multiply(mat1 [][]int, mat2 [][]int) [][]int { m, n := len(mat1), len(mat2[0]) @@ -125,6 +133,8 @@ func multiply(mat1 [][]int, mat2 [][]int) [][]int { } ``` +#### TypeScript + ```ts function multiply(mat1: number[][], mat2: number[][]): number[][] { const [m, n] = [mat1.length, mat2[0].length]; @@ -156,6 +166,8 @@ The time complexity is $O(m \times n \times k)$, and the space complexity is $O( +#### Python3 + ```python class Solution: def multiply(self, mat1: List[List[int]], mat2: List[List[int]]) -> List[List[int]]: @@ -178,6 +190,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] multiply(int[][] mat1, int[][] mat2) { @@ -213,6 +227,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -245,6 +261,8 @@ public: }; ``` +#### Go + ```go func multiply(mat1 [][]int, mat2 [][]int) [][]int { m, n := len(mat1), len(mat2[0]) @@ -279,6 +297,8 @@ func multiply(mat1 [][]int, mat2 [][]int) [][]int { } ``` +#### TypeScript + ```ts function multiply(mat1: number[][], mat2: number[][]): number[][] { const [m, n] = [mat1.length, mat2[0].length]; diff --git a/solution/0300-0399/0312.Burst Balloons/README.md b/solution/0300-0399/0312.Burst Balloons/README.md index 51571f2f03fb9..b4f8a51486134 100644 --- a/solution/0300-0399/0312.Burst Balloons/README.md +++ b/solution/0300-0399/0312.Burst Balloons/README.md @@ -60,6 +60,8 @@ coins = 3*1*5 + 3*5*8 + 1*3*8 + 1*8*1 = 167 +#### Python3 + ```python class Solution: def maxCoins(self, nums: List[int]) -> int: @@ -76,6 +78,8 @@ class Solution: return dp[0][-1] ``` +#### Java + ```java class Solution { public int maxCoins(int[] nums) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func maxCoins(nums []int) int { vals := make([]int, len(nums)+2) @@ -144,6 +152,8 @@ func maxCoins(nums []int) int { } ``` +#### TypeScript + ```ts function maxCoins(nums: number[]): number { let n = nums.length; diff --git a/solution/0300-0399/0312.Burst Balloons/README_EN.md b/solution/0300-0399/0312.Burst Balloons/README_EN.md index 93cdf979825f5..3bcbe1d91bc22 100644 --- a/solution/0300-0399/0312.Burst Balloons/README_EN.md +++ b/solution/0300-0399/0312.Burst Balloons/README_EN.md @@ -59,6 +59,8 @@ coins = 3*1*5 + 3*5*8 + 1*3*8 + 1*8*1 = 167 +#### Python3 + ```python class Solution: def maxCoins(self, nums: List[int]) -> int: @@ -75,6 +77,8 @@ class Solution: return dp[0][-1] ``` +#### Java + ```java class Solution { public int maxCoins(int[] nums) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func maxCoins(nums []int) int { vals := make([]int, len(nums)+2) @@ -143,6 +151,8 @@ func maxCoins(nums []int) int { } ``` +#### TypeScript + ```ts function maxCoins(nums: number[]): number { let n = nums.length; diff --git a/solution/0300-0399/0313.Super Ugly Number/README.md b/solution/0300-0399/0313.Super Ugly Number/README.md index 314edc2c1bcbb..00139657ee44a 100644 --- a/solution/0300-0399/0313.Super Ugly Number/README.md +++ b/solution/0300-0399/0313.Super Ugly Number/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def nthSuperUglyNumber(self, n: int, primes: List[int]) -> int: @@ -93,6 +95,8 @@ class Solution: return x ``` +#### Java + ```java class Solution { public int nthSuperUglyNumber(int n, int[] primes) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func nthSuperUglyNumber(n int, primes []int) (x int) { q := hp{[]int{1}} @@ -181,6 +189,8 @@ func (h *hp) Pop() any { +#### Go + ```go type Ugly struct{ value, prime, index int } type Queue []Ugly diff --git a/solution/0300-0399/0313.Super Ugly Number/README_EN.md b/solution/0300-0399/0313.Super Ugly Number/README_EN.md index ad835f095838a..b0452b17f9f33 100644 --- a/solution/0300-0399/0313.Super Ugly Number/README_EN.md +++ b/solution/0300-0399/0313.Super Ugly Number/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n \times m \times \log (n \times m))$, and the space c +#### Python3 + ```python class Solution: def nthSuperUglyNumber(self, n: int, primes: List[int]) -> int: @@ -86,6 +88,8 @@ class Solution: return x ``` +#### Java + ```java class Solution { public int nthSuperUglyNumber(int n, int[] primes) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func nthSuperUglyNumber(n int, primes []int) (x int) { q := hp{[]int{1}} @@ -174,6 +182,8 @@ func (h *hp) Pop() any { +#### Go + ```go type Ugly struct{ value, prime, index int } type Queue []Ugly diff --git a/solution/0300-0399/0314.Binary Tree Vertical Order Traversal/README.md b/solution/0300-0399/0314.Binary Tree Vertical Order Traversal/README.md index 187d90fb38f53..41c5cbcc5ea7d 100644 --- a/solution/0300-0399/0314.Binary Tree Vertical Order Traversal/README.md +++ b/solution/0300-0399/0314.Binary Tree Vertical Order Traversal/README.md @@ -71,6 +71,8 @@ DFS 遍历二叉树,记录每个节点的值、深度,以及横向的偏移 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -183,6 +189,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -237,6 +245,8 @@ func verticalOrder(root *TreeNode) [][]int { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -261,6 +271,8 @@ class Solution: return [v for _, v in sorted(d.items())] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -305,6 +317,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -343,6 +357,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0300-0399/0314.Binary Tree Vertical Order Traversal/README_EN.md b/solution/0300-0399/0314.Binary Tree Vertical Order Traversal/README_EN.md index 5d5e1fd7432a1..2d9746559e7df 100644 --- a/solution/0300-0399/0314.Binary Tree Vertical Order Traversal/README_EN.md +++ b/solution/0300-0399/0314.Binary Tree Vertical Order Traversal/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n\log \log n)$, and the space complexity is $O(n)$. Wh +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -235,6 +243,8 @@ The time complexity is $O(n\log n)$, and the space complexity is $O(n)$. Where $ +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -259,6 +269,8 @@ class Solution: return [v for _, v in sorted(d.items())] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -303,6 +315,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -341,6 +355,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0300-0399/0315.Count of Smaller Numbers After Self/README.md b/solution/0300-0399/0315.Count of Smaller Numbers After Self/README.md index aec76fc4bb828..e9de6060a497c 100644 --- a/solution/0300-0399/0315.Count of Smaller Numbers After Self/README.md +++ b/solution/0300-0399/0315.Count of Smaller Numbers After Self/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -120,6 +122,8 @@ class Solution: return ans[::-1] ``` +#### Java + ```java class Solution { public List countSmaller(int[] nums) { @@ -176,6 +180,8 @@ class BinaryIndexedTree { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -228,6 +234,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -301,6 +309,8 @@ func countSmaller(nums []int) []int { +#### Python3 + ```python class Node: def __init__(self): @@ -362,6 +372,8 @@ class Solution: return ans[::-1] ``` +#### Java + ```java class Solution { public List countSmaller(int[] nums) { @@ -450,6 +462,8 @@ class SegmentTree { } ``` +#### C++ + ```cpp class Node { public: @@ -525,6 +539,8 @@ public: }; ``` +#### Go + ```go type Pair struct { val int diff --git a/solution/0300-0399/0315.Count of Smaller Numbers After Self/README_EN.md b/solution/0300-0399/0315.Count of Smaller Numbers After Self/README_EN.md index 4a9c134e0c3df..37954710272a2 100644 --- a/solution/0300-0399/0315.Count of Smaller Numbers After Self/README_EN.md +++ b/solution/0300-0399/0315.Count of Smaller Numbers After Self/README_EN.md @@ -69,6 +69,8 @@ To the right of 1 there is 0 smaller element. +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -105,6 +107,8 @@ class Solution: return ans[::-1] ``` +#### Java + ```java class Solution { public List countSmaller(int[] nums) { @@ -161,6 +165,8 @@ class BinaryIndexedTree { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -213,6 +219,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -279,6 +287,8 @@ func countSmaller(nums []int) []int { +#### Python3 + ```python class Node: def __init__(self): @@ -340,6 +350,8 @@ class Solution: return ans[::-1] ``` +#### Java + ```java class Solution { public List countSmaller(int[] nums) { @@ -428,6 +440,8 @@ class SegmentTree { } ``` +#### C++ + ```cpp class Node { public: @@ -503,6 +517,8 @@ public: }; ``` +#### Go + ```go type Pair struct { val int diff --git a/solution/0300-0399/0316.Remove Duplicate Letters/README.md b/solution/0300-0399/0316.Remove Duplicate Letters/README.md index a772f509fbd3a..11c6bf02b1f3c 100644 --- a/solution/0300-0399/0316.Remove Duplicate Letters/README.md +++ b/solution/0300-0399/0316.Remove Duplicate Letters/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def removeDuplicateLetters(self, s: str) -> str: @@ -83,6 +85,8 @@ class Solution: return ''.join(stk) ``` +#### Java + ```java class Solution { public String removeDuplicateLetters(String s) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func removeDuplicateLetters(s string) string { last := make([]int, 26) @@ -174,6 +182,8 @@ func removeDuplicateLetters(s string) string { +#### Python3 + ```python class Solution: def removeDuplicateLetters(self, s: str) -> str: @@ -196,6 +206,8 @@ class Solution: return ''.join(stack) ``` +#### Go + ```go func removeDuplicateLetters(s string) string { count, in_stack, stack := make([]int, 128), make([]bool, 128), make([]rune, 0) diff --git a/solution/0300-0399/0316.Remove Duplicate Letters/README_EN.md b/solution/0300-0399/0316.Remove Duplicate Letters/README_EN.md index a2adcca55e3d2..fa32141999094 100644 --- a/solution/0300-0399/0316.Remove Duplicate Letters/README_EN.md +++ b/solution/0300-0399/0316.Remove Duplicate Letters/README_EN.md @@ -65,6 +65,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def removeDuplicateLetters(self, s: str) -> str: @@ -81,6 +83,8 @@ class Solution: return ''.join(stk) ``` +#### Java + ```java class Solution { public String removeDuplicateLetters(String s) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func removeDuplicateLetters(s string) string { last := make([]int, 26) @@ -172,6 +180,8 @@ func removeDuplicateLetters(s string) string { +#### Python3 + ```python class Solution: def removeDuplicateLetters(self, s: str) -> str: @@ -194,6 +204,8 @@ class Solution: return ''.join(stack) ``` +#### Go + ```go func removeDuplicateLetters(s string) string { count, in_stack, stack := make([]int, 128), make([]bool, 128), make([]rune, 0) diff --git a/solution/0300-0399/0317.Shortest Distance from All Buildings/README.md b/solution/0300-0399/0317.Shortest Distance from All Buildings/README.md index b5e84ac581974..a41c44f4a91dc 100644 --- a/solution/0300-0399/0317.Shortest Distance from All Buildings/README.md +++ b/solution/0300-0399/0317.Shortest Distance from All Buildings/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def shortestDistance(self, grid: List[List[int]]) -> int: @@ -123,6 +125,8 @@ class Solution: return -1 if ans == inf else ans ``` +#### Java + ```java class Solution { public int shortestDistance(int[][] grid) { @@ -173,6 +177,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -222,6 +228,8 @@ public: }; ``` +#### Go + ```go func shortestDistance(grid [][]int) int { m, n := len(grid), len(grid[0]) diff --git a/solution/0300-0399/0317.Shortest Distance from All Buildings/README_EN.md b/solution/0300-0399/0317.Shortest Distance from All Buildings/README_EN.md index 73f971ce93206..816bbabef6c3d 100644 --- a/solution/0300-0399/0317.Shortest Distance from All Buildings/README_EN.md +++ b/solution/0300-0399/0317.Shortest Distance from All Buildings/README_EN.md @@ -80,6 +80,8 @@ So return 7. +#### Python3 + ```python class Solution: def shortestDistance(self, grid: List[List[int]]) -> int: @@ -119,6 +121,8 @@ class Solution: return -1 if ans == inf else ans ``` +#### Java + ```java class Solution { public int shortestDistance(int[][] grid) { @@ -169,6 +173,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -218,6 +224,8 @@ public: }; ``` +#### Go + ```go func shortestDistance(grid [][]int) int { m, n := len(grid), len(grid[0]) diff --git a/solution/0300-0399/0318.Maximum Product of Word Lengths/README.md b/solution/0300-0399/0318.Maximum Product of Word Lengths/README.md index 6d1ebdd00249c..b63878b483c28 100644 --- a/solution/0300-0399/0318.Maximum Product of Word Lengths/README.md +++ b/solution/0300-0399/0318.Maximum Product of Word Lengths/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def maxProduct(self, words: List[str]) -> int: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxProduct(String[] words) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func maxProduct(words []string) (ans int) { n := len(words) @@ -148,6 +156,8 @@ func maxProduct(words []string) (ans int) { } ``` +#### TypeScript + ```ts function maxProduct(words: string[]): number { const n = words.length; @@ -177,6 +187,8 @@ function maxProduct(words: string[]): number { +#### Python3 + ```python class Solution: def maxProduct(self, words: List[str]) -> int: @@ -194,6 +206,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxProduct(String[] words) { @@ -218,6 +232,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -242,6 +258,8 @@ public: }; ``` +#### Go + ```go func maxProduct(words []string) (ans int) { mask := map[int]int{} @@ -262,6 +280,8 @@ func maxProduct(words []string) (ans int) { } ``` +#### TypeScript + ```ts function maxProduct(words: string[]): number { const mask: Map = new Map(); diff --git a/solution/0300-0399/0318.Maximum Product of Word Lengths/README_EN.md b/solution/0300-0399/0318.Maximum Product of Word Lengths/README_EN.md index 94eae8ef05f72..2e331f403ad8a 100644 --- a/solution/0300-0399/0318.Maximum Product of Word Lengths/README_EN.md +++ b/solution/0300-0399/0318.Maximum Product of Word Lengths/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(n^2 + L)$, and the space complexity is $O(n)$. Here, $ +#### Python3 + ```python class Solution: def maxProduct(self, words: List[str]) -> int: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxProduct(String[] words) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func maxProduct(words []string) (ans int) { n := len(words) @@ -148,6 +156,8 @@ func maxProduct(words []string) (ans int) { } ``` +#### TypeScript + ```ts function maxProduct(words: string[]): number { const n = words.length; @@ -177,6 +187,8 @@ function maxProduct(words: string[]): number { +#### Python3 + ```python class Solution: def maxProduct(self, words: List[str]) -> int: @@ -194,6 +206,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxProduct(String[] words) { @@ -218,6 +232,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -242,6 +258,8 @@ public: }; ``` +#### Go + ```go func maxProduct(words []string) (ans int) { mask := map[int]int{} @@ -262,6 +280,8 @@ func maxProduct(words []string) (ans int) { } ``` +#### TypeScript + ```ts function maxProduct(words: string[]): number { const mask: Map = new Map(); diff --git a/solution/0300-0399/0319.Bulb Switcher/README.md b/solution/0300-0399/0319.Bulb Switcher/README.md index d576a2ca88065..7d56ab90c3cc7 100644 --- a/solution/0300-0399/0319.Bulb Switcher/README.md +++ b/solution/0300-0399/0319.Bulb Switcher/README.md @@ -87,12 +87,16 @@ tags: +#### Python3 + ```python class Solution: def bulbSwitch(self, n: int) -> int: return int(sqrt(n)) ``` +#### Java + ```java class Solution { public int bulbSwitch(int n) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,12 +116,16 @@ public: }; ``` +#### Go + ```go func bulbSwitch(n int) int { return int(math.Sqrt(float64(n))) } ``` +#### TypeScript + ```ts function bulbSwitch(n: number): number { return Math.floor(Math.sqrt(n)); diff --git a/solution/0300-0399/0319.Bulb Switcher/README_EN.md b/solution/0300-0399/0319.Bulb Switcher/README_EN.md index d706254602e7f..01c84728d6c8e 100644 --- a/solution/0300-0399/0319.Bulb Switcher/README_EN.md +++ b/solution/0300-0399/0319.Bulb Switcher/README_EN.md @@ -80,12 +80,16 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def bulbSwitch(self, n: int) -> int: return int(sqrt(n)) ``` +#### Java + ```java class Solution { public int bulbSwitch(int n) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -103,12 +109,16 @@ public: }; ``` +#### Go + ```go func bulbSwitch(n int) int { return int(math.Sqrt(float64(n))) } ``` +#### TypeScript + ```ts function bulbSwitch(n: number): number { return Math.floor(Math.sqrt(n)); diff --git a/solution/0300-0399/0320.Generalized Abbreviation/README.md b/solution/0300-0399/0320.Generalized Abbreviation/README.md index ac04e9b91a726..aceb58a6f2ecf 100644 --- a/solution/0300-0399/0320.Generalized Abbreviation/README.md +++ b/solution/0300-0399/0320.Generalized Abbreviation/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def generateAbbreviations(self, word: str) -> List[str]: @@ -106,6 +108,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private String word; @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func generateAbbreviations(word string) []string { n := len(word) @@ -189,6 +197,8 @@ func generateAbbreviations(word string) []string { } ``` +#### TypeScript + ```ts function generateAbbreviations(word: string): string[] { const n = word.length; @@ -225,6 +235,8 @@ function generateAbbreviations(word: string): string[] { +#### Python3 + ```python class Solution: def generateAbbreviations(self, word: str) -> List[str]: @@ -247,6 +259,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List generateAbbreviations(String word) { @@ -276,6 +290,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -306,6 +322,8 @@ public: }; ``` +#### Go + ```go func generateAbbreviations(word string) (ans []string) { n := len(word) diff --git a/solution/0300-0399/0320.Generalized Abbreviation/README_EN.md b/solution/0300-0399/0320.Generalized Abbreviation/README_EN.md index 82f467528deaf..cda1aa4df8ba7 100644 --- a/solution/0300-0399/0320.Generalized Abbreviation/README_EN.md +++ b/solution/0300-0399/0320.Generalized Abbreviation/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(n \times 2^n)$, and the space complexity is $O(n)$. Wh +#### Python3 + ```python class Solution: def generateAbbreviations(self, word: str) -> List[str]: @@ -97,6 +99,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private String word; @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func generateAbbreviations(word string) []string { n := len(word) @@ -180,6 +188,8 @@ func generateAbbreviations(word string) []string { } ``` +#### TypeScript + ```ts function generateAbbreviations(word: string): string[] { const n = word.length; @@ -216,6 +226,8 @@ The time complexity is $O(n \times 2^n)$, and the space complexity is $O(n)$. Wh +#### Python3 + ```python class Solution: def generateAbbreviations(self, word: str) -> List[str]: @@ -238,6 +250,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List generateAbbreviations(String word) { @@ -267,6 +281,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -297,6 +313,8 @@ public: }; ``` +#### Go + ```go func generateAbbreviations(word string) (ans []string) { n := len(word) diff --git a/solution/0300-0399/0321.Create Maximum Number/README.md b/solution/0300-0399/0321.Create Maximum Number/README.md index 63a6983a0abe1..82953eeb31d8a 100644 --- a/solution/0300-0399/0321.Create Maximum Number/README.md +++ b/solution/0300-0399/0321.Create Maximum Number/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def maxNumber(self, nums1: List[int], nums2: List[int], k: int) -> List[int]: @@ -134,6 +136,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] maxNumber(int[] nums1, int[] nums2, int k) { @@ -202,6 +206,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -270,6 +276,8 @@ public: }; ``` +#### Go + ```go func maxNumber(nums1 []int, nums2 []int, k int) []int { m, n := len(nums1), len(nums2) @@ -340,6 +348,8 @@ func maxNumber(nums1 []int, nums2 []int, k int) []int { } ``` +#### TypeScript + ```ts function maxNumber(nums1: number[], nums2: number[], k: number): number[] { const m = nums1.length; diff --git a/solution/0300-0399/0321.Create Maximum Number/README_EN.md b/solution/0300-0399/0321.Create Maximum Number/README_EN.md index 0161cf5311252..16861b6a2efce 100644 --- a/solution/0300-0399/0321.Create Maximum Number/README_EN.md +++ b/solution/0300-0399/0321.Create Maximum Number/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def maxNumber(self, nums1: List[int], nums2: List[int], k: int) -> List[int]: @@ -124,6 +126,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] maxNumber(int[] nums1, int[] nums2, int k) { @@ -192,6 +196,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -260,6 +266,8 @@ public: }; ``` +#### Go + ```go func maxNumber(nums1 []int, nums2 []int, k int) []int { m, n := len(nums1), len(nums2) @@ -330,6 +338,8 @@ func maxNumber(nums1 []int, nums2 []int, k int) []int { } ``` +#### TypeScript + ```ts function maxNumber(nums1: number[], nums2: number[], k: number): number[] { const m = nums1.length; diff --git a/solution/0300-0399/0322.Coin Change/README.md b/solution/0300-0399/0322.Coin Change/README.md index b3085c5663aea..06d99fa365cdd 100644 --- a/solution/0300-0399/0322.Coin Change/README.md +++ b/solution/0300-0399/0322.Coin Change/README.md @@ -92,6 +92,8 @@ $$ +#### Python3 + ```python class Solution: def coinChange(self, coins: List[int], amount: int) -> int: @@ -106,6 +108,8 @@ class Solution: return -1 if f[m][n] >= inf else f[m][n] ``` +#### Java + ```java class Solution { public int coinChange(int[] coins, int amount) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func coinChange(coins []int, amount int) int { m, n := len(coins), amount @@ -178,6 +186,8 @@ func coinChange(coins []int, amount int) int { } ``` +#### TypeScript + ```ts function coinChange(coins: number[], amount: number): number { const m = coins.length; @@ -198,6 +208,8 @@ function coinChange(coins: number[], amount: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn coin_change(coins: Vec, amount: i32) -> i32 { @@ -218,6 +230,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} coins @@ -253,6 +267,8 @@ var coinChange = function (coins, amount) { +#### Python3 + ```python class Solution: def coinChange(self, coins: List[int], amount: int) -> int: @@ -264,6 +280,8 @@ class Solution: return -1 if f[n] >= inf else f[n] ``` +#### Java + ```java class Solution { public int coinChange(int[] coins, int amount) { @@ -282,6 +300,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -300,6 +320,8 @@ public: }; ``` +#### Go + ```go func coinChange(coins []int, amount int) int { n := amount @@ -320,6 +342,8 @@ func coinChange(coins []int, amount int) int { } ``` +#### TypeScript + ```ts function coinChange(coins: number[], amount: number): number { const n = amount; @@ -334,6 +358,8 @@ function coinChange(coins: number[], amount: number): number { } ``` +#### JavaScript + ```js /** * @param {number[]} coins diff --git a/solution/0300-0399/0322.Coin Change/README_EN.md b/solution/0300-0399/0322.Coin Change/README_EN.md index 5c5718b85e624..def97af1e8b03 100644 --- a/solution/0300-0399/0322.Coin Change/README_EN.md +++ b/solution/0300-0399/0322.Coin Change/README_EN.md @@ -92,6 +92,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def coinChange(self, coins: List[int], amount: int) -> int: @@ -106,6 +108,8 @@ class Solution: return -1 if f[m][n] >= inf else f[m][n] ``` +#### Java + ```java class Solution { public int coinChange(int[] coins, int amount) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func coinChange(coins []int, amount int) int { m, n := len(coins), amount @@ -178,6 +186,8 @@ func coinChange(coins []int, amount int) int { } ``` +#### TypeScript + ```ts function coinChange(coins: number[], amount: number): number { const m = coins.length; @@ -198,6 +208,8 @@ function coinChange(coins: number[], amount: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn coin_change(coins: Vec, amount: i32) -> i32 { @@ -218,6 +230,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} coins @@ -253,6 +267,8 @@ Similar problems: +#### Python3 + ```python class Solution: def coinChange(self, coins: List[int], amount: int) -> int: @@ -264,6 +280,8 @@ class Solution: return -1 if f[n] >= inf else f[n] ``` +#### Java + ```java class Solution { public int coinChange(int[] coins, int amount) { @@ -282,6 +300,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -300,6 +320,8 @@ public: }; ``` +#### Go + ```go func coinChange(coins []int, amount int) int { n := amount @@ -320,6 +342,8 @@ func coinChange(coins []int, amount int) int { } ``` +#### TypeScript + ```ts function coinChange(coins: number[], amount: number): number { const n = amount; @@ -334,6 +358,8 @@ function coinChange(coins: number[], amount: number): number { } ``` +#### JavaScript + ```js /** * @param {number[]} coins diff --git a/solution/0300-0399/0323.Number of Connected Components in an Undirected Graph/README.md b/solution/0300-0399/0323.Number of Connected Components in an Undirected Graph/README.md index da0294c293728..99abe76a1f440 100644 --- a/solution/0300-0399/0323.Number of Connected Components in an Undirected Graph/README.md +++ b/solution/0300-0399/0323.Number of Connected Components in an Undirected Graph/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def countComponents(self, n: int, edges: List[List[int]]) -> int: @@ -90,6 +92,8 @@ class Solution: return sum(dfs(i) for i in range(n)) ``` +#### Java + ```java class Solution { private List[] g; @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func countComponents(n int, edges [][]int) (ans int) { g := make([][]int, n) @@ -181,6 +189,8 @@ func countComponents(n int, edges [][]int) (ans int) { } ``` +#### TypeScript + ```ts function countComponents(n: number, edges: number[][]): number { const g: number[][] = Array.from({ length: n }, () => []); @@ -203,6 +213,8 @@ function countComponents(n: number, edges: number[][]): number { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -248,6 +260,8 @@ var countComponents = function (n, edges) { +#### Python3 + ```python class UnionFind: def __init__(self, n): @@ -280,6 +294,8 @@ class Solution: return n ``` +#### Java + ```java class UnionFind { private final int[] p; @@ -328,6 +344,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -375,6 +393,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p, size []int @@ -423,6 +443,8 @@ func countComponents(n int, edges [][]int) int { } ``` +#### TypeScript + ```ts class UnionFind { p: number[]; diff --git a/solution/0300-0399/0323.Number of Connected Components in an Undirected Graph/README_EN.md b/solution/0300-0399/0323.Number of Connected Components in an Undirected Graph/README_EN.md index d3b278eed66d3..ff24fe2827192 100644 --- a/solution/0300-0399/0323.Number of Connected Components in an Undirected Graph/README_EN.md +++ b/solution/0300-0399/0323.Number of Connected Components in an Undirected Graph/README_EN.md @@ -66,6 +66,8 @@ The time complexity is $O(n + m)$, and the space complexity is $O(n + m)$. Where +#### Python3 + ```python class Solution: def countComponents(self, n: int, edges: List[List[int]]) -> int: @@ -85,6 +87,8 @@ class Solution: return sum(dfs(i) for i in range(n)) ``` +#### Java + ```java class Solution { private List[] g; @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func countComponents(n int, edges [][]int) (ans int) { g := make([][]int, n) @@ -176,6 +184,8 @@ func countComponents(n int, edges [][]int) (ans int) { } ``` +#### TypeScript + ```ts function countComponents(n: number, edges: number[][]): number { const g: number[][] = Array.from({ length: n }, () => []); @@ -198,6 +208,8 @@ function countComponents(n: number, edges: number[][]): number { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -243,6 +255,8 @@ The time complexity is $O(n + m \times \alpha(n))$, and the space complexity is +#### Python3 + ```python class UnionFind: def __init__(self, n): @@ -275,6 +289,8 @@ class Solution: return n ``` +#### Java + ```java class UnionFind { private final int[] p; @@ -323,6 +339,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -370,6 +388,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p, size []int @@ -418,6 +438,8 @@ func countComponents(n int, edges [][]int) int { } ``` +#### TypeScript + ```ts class UnionFind { p: number[]; diff --git a/solution/0300-0399/0324.Wiggle Sort II/README.md b/solution/0300-0399/0324.Wiggle Sort II/README.md index ea1165740975c..02c9e49398d0e 100644 --- a/solution/0300-0399/0324.Wiggle Sort II/README.md +++ b/solution/0300-0399/0324.Wiggle Sort II/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def wiggleSort(self, nums: List[int]) -> None: @@ -82,6 +84,8 @@ class Solution: j -= 1 ``` +#### Java + ```java class Solution { public void wiggleSort(int[] nums) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func wiggleSort(nums []int) { n := len(nums) @@ -137,6 +145,8 @@ func wiggleSort(nums []int) { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -176,6 +186,8 @@ var wiggleSort = function (nums) { +#### Python3 + ```python class Solution: def wiggleSort(self, nums: List[int]) -> None: @@ -199,6 +211,8 @@ class Solution: bucket[j] -= 1 ``` +#### Java + ```java class Solution { public void wiggleSort(int[] nums) { @@ -226,6 +240,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -248,6 +264,8 @@ public: }; ``` +#### Go + ```go func wiggleSort(nums []int) { bucket := make([]int, 5001) diff --git a/solution/0300-0399/0324.Wiggle Sort II/README_EN.md b/solution/0300-0399/0324.Wiggle Sort II/README_EN.md index 6562109016d2b..ce53c9498216d 100644 --- a/solution/0300-0399/0324.Wiggle Sort II/README_EN.md +++ b/solution/0300-0399/0324.Wiggle Sort II/README_EN.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def wiggleSort(self, nums: List[int]) -> None: @@ -79,6 +81,8 @@ class Solution: j -= 1 ``` +#### Java + ```java class Solution { public void wiggleSort(int[] nums) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func wiggleSort(nums []int) { n := len(nums) @@ -134,6 +142,8 @@ func wiggleSort(nums []int) { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -173,6 +183,8 @@ var wiggleSort = function (nums) { +#### Python3 + ```python class Solution: def wiggleSort(self, nums: List[int]) -> None: @@ -196,6 +208,8 @@ class Solution: bucket[j] -= 1 ``` +#### Java + ```java class Solution { public void wiggleSort(int[] nums) { @@ -223,6 +237,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -245,6 +261,8 @@ public: }; ``` +#### Go + ```go func wiggleSort(nums []int) { bucket := make([]int, 5001) diff --git a/solution/0300-0399/0325.Maximum Size Subarray Sum Equals k/README.md b/solution/0300-0399/0325.Maximum Size Subarray Sum Equals k/README.md index b019732fe68af..128bebe51d7b5 100644 --- a/solution/0300-0399/0325.Maximum Size Subarray Sum Equals k/README.md +++ b/solution/0300-0399/0325.Maximum Size Subarray Sum Equals k/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def maxSubArrayLen(self, nums: List[int], k: int) -> int: @@ -79,6 +81,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxSubArrayLen(int[] nums, int k) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func maxSubArrayLen(nums []int, k int) (ans int) { d := map[int]int{0: -1} @@ -134,6 +142,8 @@ func maxSubArrayLen(nums []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function maxSubArrayLen(nums: number[], k: number): number { const d: Map = new Map(); diff --git a/solution/0300-0399/0325.Maximum Size Subarray Sum Equals k/README_EN.md b/solution/0300-0399/0325.Maximum Size Subarray Sum Equals k/README_EN.md index a4cf314d49f0b..faa73742e4b73 100644 --- a/solution/0300-0399/0325.Maximum Size Subarray Sum Equals k/README_EN.md +++ b/solution/0300-0399/0325.Maximum Size Subarray Sum Equals k/README_EN.md @@ -56,6 +56,8 @@ tags: +#### Python3 + ```python class Solution: def maxSubArrayLen(self, nums: List[int], k: int) -> int: @@ -70,6 +72,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxSubArrayLen(int[] nums, int k) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func maxSubArrayLen(nums []int, k int) (ans int) { d := map[int]int{0: -1} @@ -125,6 +133,8 @@ func maxSubArrayLen(nums []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function maxSubArrayLen(nums: number[], k: number): number { const d: Map = new Map(); diff --git a/solution/0300-0399/0326.Power of Three/README.md b/solution/0300-0399/0326.Power of Three/README.md index 8ff2bea275447..22c533c88f604 100644 --- a/solution/0300-0399/0326.Power of Three/README.md +++ b/solution/0300-0399/0326.Power of Three/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def isPowerOfThree(self, n: int) -> bool: @@ -87,6 +89,8 @@ class Solution: return n == 1 ``` +#### Java + ```java class Solution { public boolean isPowerOfThree(int n) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func isPowerOfThree(n int) bool { for n > 2 { @@ -128,12 +136,16 @@ func isPowerOfThree(n int) bool { } ``` +#### TypeScript + ```ts function isPowerOfThree(n: number): boolean { return n > 0 && 1162261467 % n == 0; } ``` +#### JavaScript + ```js /** * @param {number} n @@ -158,12 +170,16 @@ var isPowerOfThree = function (n) { +#### Python3 + ```python class Solution: def isPowerOfThree(self, n: int) -> bool: return n > 0 and 1162261467 % n == 0 ``` +#### Java + ```java class Solution { public boolean isPowerOfThree(int n) { @@ -172,6 +188,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +199,8 @@ public: }; ``` +#### Go + ```go func isPowerOfThree(n int) bool { return n > 0 && 1162261467%n == 0 diff --git a/solution/0300-0399/0326.Power of Three/README_EN.md b/solution/0300-0399/0326.Power of Three/README_EN.md index 50df55b4b4893..094641c44352c 100644 --- a/solution/0300-0399/0326.Power of Three/README_EN.md +++ b/solution/0300-0399/0326.Power of Three/README_EN.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def isPowerOfThree(self, n: int) -> bool: @@ -76,6 +78,8 @@ class Solution: return n == 1 ``` +#### Java + ```java class Solution { public boolean isPowerOfThree(int n) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func isPowerOfThree(n int) bool { for n > 2 { @@ -117,12 +125,16 @@ func isPowerOfThree(n int) bool { } ``` +#### TypeScript + ```ts function isPowerOfThree(n: number): boolean { return n > 0 && 1162261467 % n == 0; } ``` +#### JavaScript + ```js /** * @param {number} n @@ -143,12 +155,16 @@ var isPowerOfThree = function (n) { +#### Python3 + ```python class Solution: def isPowerOfThree(self, n: int) -> bool: return n > 0 and 1162261467 % n == 0 ``` +#### Java + ```java class Solution { public boolean isPowerOfThree(int n) { @@ -157,6 +173,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +184,8 @@ public: }; ``` +#### Go + ```go func isPowerOfThree(n int) bool { return n > 0 && 1162261467%n == 0 diff --git a/solution/0300-0399/0327.Count of Range Sum/README.md b/solution/0300-0399/0327.Count of Range Sum/README.md index 9c47dfaaa9027..96fc6230106c9 100644 --- a/solution/0300-0399/0327.Count of Range Sum/README.md +++ b/solution/0300-0399/0327.Count of Range Sum/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -177,6 +181,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -236,6 +242,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -295,6 +303,8 @@ func countRangeSum(nums []int, lower int, upper int) (ans int) { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; diff --git a/solution/0300-0399/0327.Count of Range Sum/README_EN.md b/solution/0300-0399/0327.Count of Range Sum/README_EN.md index ef91ddf8d5325..64342ac10fc38 100644 --- a/solution/0300-0399/0327.Count of Range Sum/README_EN.md +++ b/solution/0300-0399/0327.Count of Range Sum/README_EN.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -168,6 +172,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -227,6 +233,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -286,6 +294,8 @@ func countRangeSum(nums []int, lower int, upper int) (ans int) { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; diff --git a/solution/0300-0399/0328.Odd Even Linked List/README.md b/solution/0300-0399/0328.Odd Even Linked List/README.md index 9a0731308a1ac..ecec1ac6f1cf8 100644 --- a/solution/0300-0399/0328.Odd Even Linked List/README.md +++ b/solution/0300-0399/0328.Odd Even Linked List/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -91,6 +93,8 @@ class Solution: return head ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -177,6 +185,8 @@ func oddEvenList(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/0300-0399/0328.Odd Even Linked List/README_EN.md b/solution/0300-0399/0328.Odd Even Linked List/README_EN.md index f756fc33a7c02..601b597978eac 100644 --- a/solution/0300-0399/0328.Odd Even Linked List/README_EN.md +++ b/solution/0300-0399/0328.Odd Even Linked List/README_EN.md @@ -65,6 +65,8 @@ The time complexity is $O(n)$, where $n$ is the length of the list, and we need +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -86,6 +88,8 @@ class Solution: return head ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -172,6 +180,8 @@ func oddEvenList(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/0300-0399/0329.Longest Increasing Path in a Matrix/README.md b/solution/0300-0399/0329.Longest Increasing Path in a Matrix/README.md index 618eed5570c96..f708a287687af 100644 --- a/solution/0300-0399/0329.Longest Increasing Path in a Matrix/README.md +++ b/solution/0300-0399/0329.Longest Increasing Path in a Matrix/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def longestIncreasingPath(self, matrix: List[List[int]]) -> int: @@ -101,6 +103,8 @@ class Solution: return max(dfs(i, j) for i in range(m) for j in range(n)) ``` +#### Java + ```java class Solution { private int m; @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go func longestIncreasingPath(matrix [][]int) (ans int) { m, n := len(matrix), len(matrix[0]) @@ -203,6 +211,8 @@ func longestIncreasingPath(matrix [][]int) (ans int) { } ``` +#### TypeScript + ```ts function longestIncreasingPath(matrix: number[][]): number { const m = matrix.length; diff --git a/solution/0300-0399/0329.Longest Increasing Path in a Matrix/README_EN.md b/solution/0300-0399/0329.Longest Increasing Path in a Matrix/README_EN.md index ff910570a7d72..2478f6667bbd5 100644 --- a/solution/0300-0399/0329.Longest Increasing Path in a Matrix/README_EN.md +++ b/solution/0300-0399/0329.Longest Increasing Path in a Matrix/README_EN.md @@ -84,6 +84,8 @@ Similar problems: +#### Python3 + ```python class Solution: def longestIncreasingPath(self, matrix: List[List[int]]) -> int: @@ -100,6 +102,8 @@ class Solution: return max(dfs(i, j) for i in range(m) for j in range(n)) ``` +#### Java + ```java class Solution { private int m; @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func longestIncreasingPath(matrix [][]int) (ans int) { m, n := len(matrix), len(matrix[0]) @@ -202,6 +210,8 @@ func longestIncreasingPath(matrix [][]int) (ans int) { } ``` +#### TypeScript + ```ts function longestIncreasingPath(matrix: number[][]): number { const m = matrix.length; diff --git a/solution/0300-0399/0330.Patching Array/README.md b/solution/0300-0399/0330.Patching Array/README.md index 3068a74f763cc..c02a745135432 100644 --- a/solution/0300-0399/0330.Patching Array/README.md +++ b/solution/0300-0399/0330.Patching Array/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def minPatches(self, nums: List[int], n: int) -> int: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minPatches(int[] nums, int n) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func minPatches(nums []int, n int) (ans int) { x := 1 @@ -157,6 +165,8 @@ func minPatches(nums []int, n int) (ans int) { } ``` +#### TypeScript + ```ts function minPatches(nums: number[], n: number): number { let x = 1; diff --git a/solution/0300-0399/0330.Patching Array/README_EN.md b/solution/0300-0399/0330.Patching Array/README_EN.md index 6f1c2b0302cb8..8320fdf952286 100644 --- a/solution/0300-0399/0330.Patching Array/README_EN.md +++ b/solution/0300-0399/0330.Patching Array/README_EN.md @@ -88,6 +88,8 @@ The time complexity is $O(m + \log n)$, where $m$ is the length of the array $nu +#### Python3 + ```python class Solution: def minPatches(self, nums: List[int], n: int) -> int: @@ -103,6 +105,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minPatches(int[] nums, int n) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func minPatches(nums []int, n int) (ans int) { x := 1 @@ -156,6 +164,8 @@ func minPatches(nums []int, n int) (ans int) { } ``` +#### TypeScript + ```ts function minPatches(nums: number[], n: number): number { let x = 1; diff --git a/solution/0300-0399/0331.Verify Preorder Serialization of a Binary Tree/README.md b/solution/0300-0399/0331.Verify Preorder Serialization of a Binary Tree/README.md index 6afdd36dc58f0..39ad0420f661f 100644 --- a/solution/0300-0399/0331.Verify Preorder Serialization of a Binary Tree/README.md +++ b/solution/0300-0399/0331.Verify Preorder Serialization of a Binary Tree/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def isValidSerialization(self, preorder: str) -> bool: @@ -96,6 +98,8 @@ class Solution: return len(stk) == 1 and stk[0] == "#" ``` +#### Java + ```java class Solution { public boolean isValidSerialization(String preorder) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func isValidSerialization(preorder string) bool { stk := []string{} @@ -150,6 +158,8 @@ func isValidSerialization(preorder string) bool { } ``` +#### TypeScript + ```ts function isValidSerialization(preorder: string): boolean { const stk: string[] = []; diff --git a/solution/0300-0399/0331.Verify Preorder Serialization of a Binary Tree/README_EN.md b/solution/0300-0399/0331.Verify Preorder Serialization of a Binary Tree/README_EN.md index b9a8c99a5653c..ef1a54bc8014f 100644 --- a/solution/0300-0399/0331.Verify Preorder Serialization of a Binary Tree/README_EN.md +++ b/solution/0300-0399/0331.Verify Preorder Serialization of a Binary Tree/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n)$ and the space complexity is $O(n)$, where $n$ is t +#### Python3 + ```python class Solution: def isValidSerialization(self, preorder: str) -> bool: @@ -82,6 +84,8 @@ class Solution: return len(stk) == 1 and stk[0] == "#" ``` +#### Java + ```java class Solution { public boolean isValidSerialization(String preorder) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func isValidSerialization(preorder string) bool { stk := []string{} @@ -136,6 +144,8 @@ func isValidSerialization(preorder string) bool { } ``` +#### TypeScript + ```ts function isValidSerialization(preorder: string): boolean { const stk: string[] = []; diff --git a/solution/0300-0399/0332.Reconstruct Itinerary/README.md b/solution/0300-0399/0332.Reconstruct Itinerary/README.md index fa10be2e39491..f14fd8ac83b8b 100644 --- a/solution/0300-0399/0332.Reconstruct Itinerary/README.md +++ b/solution/0300-0399/0332.Reconstruct Itinerary/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def findItinerary(self, tickets: List[List[str]]) -> List[str]: @@ -88,6 +90,8 @@ class Solution: return itinerary[::-1] ``` +#### Java + ```java class Solution { void dfs(Map> adjLists, List ans, String curr) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/0300-0399/0332.Reconstruct Itinerary/README_EN.md b/solution/0300-0399/0332.Reconstruct Itinerary/README_EN.md index 224379b693abe..bb688d0f1adab 100644 --- a/solution/0300-0399/0332.Reconstruct Itinerary/README_EN.md +++ b/solution/0300-0399/0332.Reconstruct Itinerary/README_EN.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def findItinerary(self, tickets: List[List[str]]) -> List[str]: @@ -86,6 +88,8 @@ class Solution: return itinerary[::-1] ``` +#### Java + ```java class Solution { void dfs(Map> adjLists, List ans, String curr) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/0300-0399/0333.Largest BST Subtree/README.md b/solution/0300-0399/0333.Largest BST Subtree/README.md index f2ca6068c9760..6224e0e6e6394 100644 --- a/solution/0300-0399/0333.Largest BST Subtree/README.md +++ b/solution/0300-0399/0333.Largest BST Subtree/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0300-0399/0333.Largest BST Subtree/README_EN.md b/solution/0300-0399/0333.Largest BST Subtree/README_EN.md index 069f0b77145e3..4d127e2d4c8ea 100644 --- a/solution/0300-0399/0333.Largest BST Subtree/README_EN.md +++ b/solution/0300-0399/0333.Largest BST Subtree/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0300-0399/0334.Increasing Triplet Subsequence/README.md b/solution/0300-0399/0334.Increasing Triplet Subsequence/README.md index a9f9b89421894..c8fe3bab25557 100644 --- a/solution/0300-0399/0334.Increasing Triplet Subsequence/README.md +++ b/solution/0300-0399/0334.Increasing Triplet Subsequence/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def increasingTriplet(self, nums: List[int]) -> bool: @@ -83,6 +85,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean increasingTriplet(int[] nums) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func increasingTriplet(nums []int) bool { min, mid := math.MaxInt32, math.MaxInt32 @@ -141,6 +149,8 @@ func increasingTriplet(nums []int) bool { } ``` +#### TypeScript + ```ts function increasingTriplet(nums: number[]): boolean { let n = nums.length; @@ -160,6 +170,8 @@ function increasingTriplet(nums: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn increasing_triplet(nums: Vec) -> bool { @@ -193,6 +205,8 @@ impl Solution { +#### Java + ```java class Solution { public boolean increasingTriplet(int[] nums) { diff --git a/solution/0300-0399/0334.Increasing Triplet Subsequence/README_EN.md b/solution/0300-0399/0334.Increasing Triplet Subsequence/README_EN.md index 780928e1bbd5c..4fedd2f3f52b2 100644 --- a/solution/0300-0399/0334.Increasing Triplet Subsequence/README_EN.md +++ b/solution/0300-0399/0334.Increasing Triplet Subsequence/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def increasingTriplet(self, nums: List[int]) -> bool: @@ -79,6 +81,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean increasingTriplet(int[] nums) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func increasingTriplet(nums []int) bool { min, mid := math.MaxInt32, math.MaxInt32 @@ -137,6 +145,8 @@ func increasingTriplet(nums []int) bool { } ``` +#### TypeScript + ```ts function increasingTriplet(nums: number[]): boolean { let n = nums.length; @@ -156,6 +166,8 @@ function increasingTriplet(nums: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn increasing_triplet(nums: Vec) -> bool { @@ -189,6 +201,8 @@ impl Solution { +#### Java + ```java class Solution { public boolean increasingTriplet(int[] nums) { diff --git a/solution/0300-0399/0335.Self Crossing/README.md b/solution/0300-0399/0335.Self Crossing/README.md index 573f18e2a2c52..a78963f20151c 100644 --- a/solution/0300-0399/0335.Self Crossing/README.md +++ b/solution/0300-0399/0335.Self Crossing/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def isSelfCrossing(self, distance: List[int]) -> bool: @@ -85,6 +87,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean isSelfCrossing(int[] distance) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func isSelfCrossing(distance []int) bool { d := distance @@ -139,6 +147,8 @@ func isSelfCrossing(distance []int) bool { } ``` +#### C# + ```cs public class Solution { public bool IsSelfCrossing(int[] x) { diff --git a/solution/0300-0399/0335.Self Crossing/README_EN.md b/solution/0300-0399/0335.Self Crossing/README_EN.md index 14f3822b95690..9352d6df37e6e 100644 --- a/solution/0300-0399/0335.Self Crossing/README_EN.md +++ b/solution/0300-0399/0335.Self Crossing/README_EN.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def isSelfCrossing(self, distance: List[int]) -> bool: @@ -87,6 +89,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean isSelfCrossing(int[] distance) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func isSelfCrossing(distance []int) bool { d := distance @@ -141,6 +149,8 @@ func isSelfCrossing(distance []int) bool { } ``` +#### C# + ```cs public class Solution { public bool IsSelfCrossing(int[] x) { diff --git a/solution/0300-0399/0336.Palindrome Pairs/README.md b/solution/0300-0399/0336.Palindrome Pairs/README.md index d140433578afd..7b63cc40ba440 100644 --- a/solution/0300-0399/0336.Palindrome Pairs/README.md +++ b/solution/0300-0399/0336.Palindrome Pairs/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def palindromePairs(self, words: List[str]) -> List[List[int]]: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int BASE = 131; @@ -148,6 +152,8 @@ class Solution { } ``` +#### Go + ```go func palindromePairs(words []string) [][]int { base := 131 @@ -189,6 +195,8 @@ func palindromePairs(words []string) [][]int { } ``` +#### C# + ```cs using System.Collections.Generic; using System.Linq; @@ -252,6 +260,8 @@ public class Solution { +#### Java + ```java class Trie { Trie[] children = new Trie[26]; diff --git a/solution/0300-0399/0336.Palindrome Pairs/README_EN.md b/solution/0300-0399/0336.Palindrome Pairs/README_EN.md index c9a31616fd9c0..9479c24564fc0 100644 --- a/solution/0300-0399/0336.Palindrome Pairs/README_EN.md +++ b/solution/0300-0399/0336.Palindrome Pairs/README_EN.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def palindromePairs(self, words: List[str]) -> List[List[int]]: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int BASE = 131; @@ -140,6 +144,8 @@ class Solution { } ``` +#### Go + ```go func palindromePairs(words []string) [][]int { base := 131 @@ -181,6 +187,8 @@ func palindromePairs(words []string) [][]int { } ``` +#### C# + ```cs using System.Collections.Generic; using System.Linq; @@ -244,6 +252,8 @@ public class Solution { +#### Java + ```java class Trie { Trie[] children = new Trie[26]; diff --git a/solution/0300-0399/0337.House Robber III/README.md b/solution/0300-0399/0337.House Robber III/README.md index a5ecea2289bc1..b2e44076475b9 100644 --- a/solution/0300-0399/0337.House Robber III/README.md +++ b/solution/0300-0399/0337.House Robber III/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -101,6 +103,8 @@ class Solution: return max(dfs(root)) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -187,6 +195,8 @@ func rob(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0300-0399/0337.House Robber III/README_EN.md b/solution/0300-0399/0337.House Robber III/README_EN.md index ad047244e0b8a..437792cbec367 100644 --- a/solution/0300-0399/0337.House Robber III/README_EN.md +++ b/solution/0300-0399/0337.House Robber III/README_EN.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -79,6 +81,8 @@ class Solution: return max(dfs(root)) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -165,6 +173,8 @@ func rob(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0300-0399/0338.Counting Bits/README.md b/solution/0300-0399/0338.Counting Bits/README.md index f7d3ac572076b..9a81e7663965e 100644 --- a/solution/0300-0399/0338.Counting Bits/README.md +++ b/solution/0300-0399/0338.Counting Bits/README.md @@ -81,12 +81,16 @@ tags: +#### Python3 + ```python class Solution: def countBits(self, n: int) -> List[int]: return [i.bit_count() for i in range(n + 1)] ``` +#### Java + ```java class Solution { public int[] countBits(int n) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func countBits(n int) []int { ans := make([]int, n+1) @@ -122,6 +130,8 @@ func countBits(n int) []int { } ``` +#### TypeScript + ```ts function countBits(n: number): number[] { const ans: number[] = Array(n + 1).fill(0); @@ -157,6 +167,8 @@ function bitCount(n: number): number { +#### Python3 + ```python class Solution: def countBits(self, n: int) -> List[int]: @@ -166,6 +178,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] countBits(int n) { @@ -178,6 +192,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -191,6 +207,8 @@ public: }; ``` +#### Go + ```go func countBits(n int) []int { ans := make([]int, n+1) @@ -201,6 +219,8 @@ func countBits(n int) []int { } ``` +#### TypeScript + ```ts function countBits(n: number): number[] { const ans: number[] = Array(n + 1).fill(0); diff --git a/solution/0300-0399/0338.Counting Bits/README_EN.md b/solution/0300-0399/0338.Counting Bits/README_EN.md index 2010087babf28..c6b7502f1dabe 100644 --- a/solution/0300-0399/0338.Counting Bits/README_EN.md +++ b/solution/0300-0399/0338.Counting Bits/README_EN.md @@ -70,12 +70,16 @@ tags: +#### Python3 + ```python class Solution: def countBits(self, n: int) -> List[int]: return [i.bit_count() for i in range(n + 1)] ``` +#### Java + ```java class Solution { public int[] countBits(int n) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,6 +107,8 @@ public: }; ``` +#### Go + ```go func countBits(n int) []int { ans := make([]int, n+1) @@ -111,6 +119,8 @@ func countBits(n int) []int { } ``` +#### TypeScript + ```ts function countBits(n: number): number[] { const ans: number[] = Array(n + 1).fill(0); @@ -140,6 +150,8 @@ function bitCount(n: number): number { +#### Python3 + ```python class Solution: def countBits(self, n: int) -> List[int]: @@ -149,6 +161,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] countBits(int n) { @@ -161,6 +175,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +190,8 @@ public: }; ``` +#### Go + ```go func countBits(n int) []int { ans := make([]int, n+1) @@ -184,6 +202,8 @@ func countBits(n int) []int { } ``` +#### TypeScript + ```ts function countBits(n: number): number[] { const ans: number[] = Array(n + 1).fill(0); diff --git a/solution/0300-0399/0339.Nested List Weight Sum/README.md b/solution/0300-0399/0339.Nested List Weight Sum/README.md index 6ef46a7e98c90..1aa94ef755025 100644 --- a/solution/0300-0399/0339.Nested List Weight Sum/README.md +++ b/solution/0300-0399/0339.Nested List Weight Sum/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python # """ # This is the interface that allows for creating nested lists. @@ -125,6 +127,8 @@ class Solution: return dfs(nestedList, 1) ``` +#### Java + ```java /** * // This is the interface that allows for creating nested lists. @@ -173,6 +177,8 @@ class Solution { } ``` +#### JavaScript + ```js /** * // This is the interface that allows for creating nested lists. diff --git a/solution/0300-0399/0339.Nested List Weight Sum/README_EN.md b/solution/0300-0399/0339.Nested List Weight Sum/README_EN.md index ce80940320a09..a12228e264c89 100644 --- a/solution/0300-0399/0339.Nested List Weight Sum/README_EN.md +++ b/solution/0300-0399/0339.Nested List Weight Sum/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python # """ # This is the interface that allows for creating nested lists. @@ -122,6 +124,8 @@ class Solution: return dfs(nestedList, 1) ``` +#### Java + ```java /** * // This is the interface that allows for creating nested lists. @@ -170,6 +174,8 @@ class Solution { } ``` +#### JavaScript + ```js /** * // This is the interface that allows for creating nested lists. diff --git a/solution/0300-0399/0340.Longest Substring with At Most K Distinct Characters/README.md b/solution/0300-0399/0340.Longest Substring with At Most K Distinct Characters/README.md index 0905eab8b17e4..fa9134aadaf49 100644 --- a/solution/0300-0399/0340.Longest Substring with At Most K Distinct Characters/README.md +++ b/solution/0300-0399/0340.Longest Substring with At Most K Distinct Characters/README.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def lengthOfLongestSubstringKDistinct(self, s: str, k: int) -> int: @@ -79,6 +81,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int lengthOfLongestSubstringKDistinct(String s, int k) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func lengthOfLongestSubstringKDistinct(s string, k int) (ans int) { cnt := map[byte]int{} diff --git a/solution/0300-0399/0340.Longest Substring with At Most K Distinct Characters/README_EN.md b/solution/0300-0399/0340.Longest Substring with At Most K Distinct Characters/README_EN.md index eb526498dca3e..04562983b147c 100644 --- a/solution/0300-0399/0340.Longest Substring with At Most K Distinct Characters/README_EN.md +++ b/solution/0300-0399/0340.Longest Substring with At Most K Distinct Characters/README_EN.md @@ -54,6 +54,8 @@ tags: +#### Python3 + ```python class Solution: def lengthOfLongestSubstringKDistinct(self, s: str, k: int) -> int: @@ -71,6 +73,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int lengthOfLongestSubstringKDistinct(String s, int k) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func lengthOfLongestSubstringKDistinct(s string, k int) (ans int) { cnt := map[byte]int{} diff --git a/solution/0300-0399/0341.Flatten Nested List Iterator/README.md b/solution/0300-0399/0341.Flatten Nested List Iterator/README.md index a002f53b84326..bf48ea54955e6 100644 --- a/solution/0300-0399/0341.Flatten Nested List Iterator/README.md +++ b/solution/0300-0399/0341.Flatten Nested List Iterator/README.md @@ -80,6 +80,8 @@ return res +#### Python3 + ```python # """ # This is the interface that allows for creating nested lists. @@ -131,6 +133,8 @@ class NestedIterator: # while i.hasNext(): v.append(i.next()) ``` +#### Java + ```java /** * // This is the interface that allows for creating nested lists. @@ -189,6 +193,8 @@ public class NestedIterator implements Iterator { */ ``` +#### C++ + ```cpp /** * // This is the interface that allows for creating nested lists. @@ -244,6 +250,8 @@ private: */ ``` +#### Go + ```go /** * // This is the interface that allows for creating nested lists. @@ -303,6 +311,8 @@ func (this *NestedIterator) HasNext() bool { } ``` +#### TypeScript + ```ts /** * // This is the interface that allows for creating nested lists. @@ -380,6 +390,8 @@ class NestedIterator { */ ``` +#### Rust + ```rust // #[derive(Debug, PartialEq, Eq)] // pub enum NestedInteger { @@ -443,6 +455,8 @@ impl NestedIterator { +#### Go + ```go /** * // This is the interface that allows for creating nested lists. diff --git a/solution/0300-0399/0341.Flatten Nested List Iterator/README_EN.md b/solution/0300-0399/0341.Flatten Nested List Iterator/README_EN.md index 9859315efcd99..7da1e49366927 100644 --- a/solution/0300-0399/0341.Flatten Nested List Iterator/README_EN.md +++ b/solution/0300-0399/0341.Flatten Nested List Iterator/README_EN.md @@ -78,6 +78,8 @@ return res +#### Python3 + ```python # """ # This is the interface that allows for creating nested lists. @@ -129,6 +131,8 @@ class NestedIterator: # while i.hasNext(): v.append(i.next()) ``` +#### Java + ```java /** * // This is the interface that allows for creating nested lists. @@ -187,6 +191,8 @@ public class NestedIterator implements Iterator { */ ``` +#### C++ + ```cpp /** * // This is the interface that allows for creating nested lists. @@ -242,6 +248,8 @@ private: */ ``` +#### Go + ```go /** * // This is the interface that allows for creating nested lists. @@ -301,6 +309,8 @@ func (this *NestedIterator) HasNext() bool { } ``` +#### TypeScript + ```ts /** * // This is the interface that allows for creating nested lists. @@ -378,6 +388,8 @@ class NestedIterator { */ ``` +#### Rust + ```rust // #[derive(Debug, PartialEq, Eq)] // pub enum NestedInteger { @@ -439,6 +451,8 @@ impl NestedIterator { +#### Go + ```go /** * // This is the interface that allows for creating nested lists. diff --git a/solution/0300-0399/0342.Power of Four/README.md b/solution/0300-0399/0342.Power of Four/README.md index 181ffe2b86924..b4e3a97f5cbb0 100644 --- a/solution/0300-0399/0342.Power of Four/README.md +++ b/solution/0300-0399/0342.Power of Four/README.md @@ -67,12 +67,16 @@ tags: +#### Python3 + ```python class Solution: def isPowerOfFour(self, n: int) -> bool: return n > 0 and (n & (n - 1)) == 0 and (n & 0xAAAAAAAA) == 0 ``` +#### Java + ```java class Solution { public boolean isPowerOfFour(int n) { @@ -81,6 +85,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -90,18 +96,24 @@ public: }; ``` +#### Go + ```go func isPowerOfFour(n int) bool { return n > 0 && (n&(n-1)) == 0 && (n&0xaaaaaaaa) == 0 } ``` +#### TypeScript + ```ts function isPowerOfFour(n: number): boolean { return n > 0 && (n & (n - 1)) == 0 && (n & 0xaaaaaaaa) == 0; } ``` +#### JavaScript + ```js /** * @param {number} n diff --git a/solution/0300-0399/0342.Power of Four/README_EN.md b/solution/0300-0399/0342.Power of Four/README_EN.md index d8824c028118c..785bb147db19d 100644 --- a/solution/0300-0399/0342.Power of Four/README_EN.md +++ b/solution/0300-0399/0342.Power of Four/README_EN.md @@ -53,12 +53,16 @@ tags: +#### Python3 + ```python class Solution: def isPowerOfFour(self, n: int) -> bool: return n > 0 and (n & (n - 1)) == 0 and (n & 0xAAAAAAAA) == 0 ``` +#### Java + ```java class Solution { public boolean isPowerOfFour(int n) { @@ -67,6 +71,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -76,18 +82,24 @@ public: }; ``` +#### Go + ```go func isPowerOfFour(n int) bool { return n > 0 && (n&(n-1)) == 0 && (n&0xaaaaaaaa) == 0 } ``` +#### TypeScript + ```ts function isPowerOfFour(n: number): boolean { return n > 0 && (n & (n - 1)) == 0 && (n & 0xaaaaaaaa) == 0; } ``` +#### JavaScript + ```js /** * @param {number} n diff --git a/solution/0300-0399/0343.Integer Break/README.md b/solution/0300-0399/0343.Integer Break/README.md index b58307f4ca292..e85a34a05c96c 100644 --- a/solution/0300-0399/0343.Integer Break/README.md +++ b/solution/0300-0399/0343.Integer Break/README.md @@ -65,6 +65,8 @@ $$ +#### Python3 + ```python class Solution: def integerBreak(self, n: int) -> int: @@ -75,6 +77,8 @@ class Solution: return dp[n] ``` +#### Java + ```java class Solution { public int integerBreak(int n) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func integerBreak(n int) int { dp := make([]int, n+1) @@ -119,6 +127,8 @@ func integerBreak(n int) int { } ``` +#### TypeScript + ```ts function integerBreak(n: number): number { let dp = new Array(n + 1).fill(1); @@ -131,6 +141,8 @@ function integerBreak(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn integer_break(n: i32) -> i32 { @@ -143,6 +155,8 @@ impl Solution { } ``` +#### C + ```c int integerBreak(int n) { if (n < 4) { @@ -167,6 +181,8 @@ int integerBreak(int n) { +#### Python3 + ```python class Solution: def integerBreak(self, n: int) -> int: @@ -179,6 +195,8 @@ class Solution: return pow(3, n // 3) * 2 ``` +#### Java + ```java class Solution { public int integerBreak(int n) { @@ -196,6 +214,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -214,6 +234,8 @@ public: }; ``` +#### Go + ```go func integerBreak(n int) int { if n < 4 { @@ -229,6 +251,8 @@ func integerBreak(n int) int { } ``` +#### TypeScript + ```ts function integerBreak(n: number): number { if (n < 4) { diff --git a/solution/0300-0399/0343.Integer Break/README_EN.md b/solution/0300-0399/0343.Integer Break/README_EN.md index 32765b3eb6298..c5da4dcec24a9 100644 --- a/solution/0300-0399/0343.Integer Break/README_EN.md +++ b/solution/0300-0399/0343.Integer Break/README_EN.md @@ -55,6 +55,8 @@ tags: +#### Python3 + ```python class Solution: def integerBreak(self, n: int) -> int: @@ -65,6 +67,8 @@ class Solution: return dp[n] ``` +#### Java + ```java class Solution { public int integerBreak(int n) { @@ -80,6 +84,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -96,6 +102,8 @@ public: }; ``` +#### Go + ```go func integerBreak(n int) int { dp := make([]int, n+1) @@ -109,6 +117,8 @@ func integerBreak(n int) int { } ``` +#### TypeScript + ```ts function integerBreak(n: number): number { let dp = new Array(n + 1).fill(1); @@ -121,6 +131,8 @@ function integerBreak(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn integer_break(n: i32) -> i32 { @@ -133,6 +145,8 @@ impl Solution { } ``` +#### C + ```c int integerBreak(int n) { if (n < 4) { @@ -153,6 +167,8 @@ int integerBreak(int n) { +#### Python3 + ```python class Solution: def integerBreak(self, n: int) -> int: @@ -165,6 +181,8 @@ class Solution: return pow(3, n // 3) * 2 ``` +#### Java + ```java class Solution { public int integerBreak(int n) { @@ -182,6 +200,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -200,6 +220,8 @@ public: }; ``` +#### Go + ```go func integerBreak(n int) int { if n < 4 { @@ -215,6 +237,8 @@ func integerBreak(n int) int { } ``` +#### TypeScript + ```ts function integerBreak(n: number): number { if (n < 4) { diff --git a/solution/0300-0399/0344.Reverse String/README.md b/solution/0300-0399/0344.Reverse String/README.md index 10e1e0b1e1625..28ea079c92c71 100644 --- a/solution/0300-0399/0344.Reverse String/README.md +++ b/solution/0300-0399/0344.Reverse String/README.md @@ -59,6 +59,8 @@ tags: +#### Python3 + ```python class Solution: def reverseString(self, s: List[str]) -> None: @@ -68,6 +70,8 @@ class Solution: i, j = i + 1, j - 1 ``` +#### Java + ```java class Solution { public void reverseString(char[] s) { @@ -80,6 +84,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -91,6 +97,8 @@ public: }; ``` +#### Go + ```go func reverseString(s []byte) { for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 { @@ -99,6 +107,8 @@ func reverseString(s []byte) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify s in-place instead. @@ -110,6 +120,8 @@ function reverseString(s: string[]): void { } ``` +#### Rust + ```rust impl Solution { pub fn reverse_string(s: &mut Vec) { @@ -124,6 +136,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {character[]} s @@ -146,12 +160,16 @@ var reverseString = function (s) { +#### Python3 + ```python class Solution: def reverseString(self, s: List[str]) -> None: s[:] = s[::-1] ``` +#### TypeScript + ```ts /** Do not return anything, modify s in-place instead. diff --git a/solution/0300-0399/0344.Reverse String/README_EN.md b/solution/0300-0399/0344.Reverse String/README_EN.md index c21bf89059cef..9e80a9bffb774 100644 --- a/solution/0300-0399/0344.Reverse String/README_EN.md +++ b/solution/0300-0399/0344.Reverse String/README_EN.md @@ -47,6 +47,8 @@ tags: +#### Python3 + ```python class Solution: def reverseString(self, s: List[str]) -> None: @@ -56,6 +58,8 @@ class Solution: i, j = i + 1, j - 1 ``` +#### Java + ```java class Solution { public void reverseString(char[] s) { @@ -68,6 +72,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -79,6 +85,8 @@ public: }; ``` +#### Go + ```go func reverseString(s []byte) { for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 { @@ -87,6 +95,8 @@ func reverseString(s []byte) { } ``` +#### TypeScript + ```ts /** Do not return anything, modify s in-place instead. @@ -98,6 +108,8 @@ function reverseString(s: string[]): void { } ``` +#### Rust + ```rust impl Solution { pub fn reverse_string(s: &mut Vec) { @@ -112,6 +124,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {character[]} s @@ -134,12 +148,16 @@ var reverseString = function (s) { +#### Python3 + ```python class Solution: def reverseString(self, s: List[str]) -> None: s[:] = s[::-1] ``` +#### TypeScript + ```ts /** Do not return anything, modify s in-place instead. diff --git a/solution/0300-0399/0345.Reverse Vowels of a String/README.md b/solution/0300-0399/0345.Reverse Vowels of a String/README.md index 49a45198dd99d..de8ae1619cd66 100644 --- a/solution/0300-0399/0345.Reverse Vowels of a String/README.md +++ b/solution/0300-0399/0345.Reverse Vowels of a String/README.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def reverseVowels(self, s: str) -> str: @@ -78,6 +80,8 @@ class Solution: return "".join(cs) ``` +#### Java + ```java class Solution { public String reverseVowels(String s) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func reverseVowels(s string) string { vowels := [128]bool{} @@ -157,6 +165,8 @@ func reverseVowels(s string) string { } ``` +#### TypeScript + ```ts function reverseVowels(s: string): string { const vowels = new Set(['a', 'e', 'i', 'o', 'u']); @@ -174,6 +184,8 @@ function reverseVowels(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn reverse_vowels(s: String) -> String { diff --git a/solution/0300-0399/0345.Reverse Vowels of a String/README_EN.md b/solution/0300-0399/0345.Reverse Vowels of a String/README_EN.md index 415a76751bfc7..edc8d3e819807 100644 --- a/solution/0300-0399/0345.Reverse Vowels of a String/README_EN.md +++ b/solution/0300-0399/0345.Reverse Vowels of a String/README_EN.md @@ -47,6 +47,8 @@ tags: +#### Python3 + ```python class Solution: def reverseVowels(self, s: str) -> str: @@ -64,6 +66,8 @@ class Solution: return "".join(cs) ``` +#### Java + ```java class Solution { public String reverseVowels(String s) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func reverseVowels(s string) string { vowels := [128]bool{} @@ -143,6 +151,8 @@ func reverseVowels(s string) string { } ``` +#### TypeScript + ```ts function reverseVowels(s: string): string { const vowels = new Set(['a', 'e', 'i', 'o', 'u']); @@ -160,6 +170,8 @@ function reverseVowels(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn reverse_vowels(s: String) -> String { diff --git a/solution/0300-0399/0346.Moving Average from Data Stream/README.md b/solution/0300-0399/0346.Moving Average from Data Stream/README.md index d5c501e85bcd3..efb6c61d85aec 100644 --- a/solution/0300-0399/0346.Moving Average from Data Stream/README.md +++ b/solution/0300-0399/0346.Moving Average from Data Stream/README.md @@ -67,6 +67,8 @@ movingAverage.next(5); // 返回 6.0 = (10 + 3 + 5) / 3 +#### Python3 + ```python class MovingAverage: def __init__(self, size: int): @@ -87,6 +89,8 @@ class MovingAverage: # param_1 = obj.next(val) ``` +#### Java + ```java class MovingAverage { private int[] arr; @@ -113,6 +117,8 @@ class MovingAverage { */ ``` +#### C++ + ```cpp class MovingAverage { public: @@ -141,6 +147,8 @@ private: */ ``` +#### Go + ```go type MovingAverage struct { arr []int @@ -178,6 +186,8 @@ func (this *MovingAverage) Next(val int) float64 { +#### Python3 + ```python class MovingAverage: def __init__(self, size: int): @@ -198,6 +208,8 @@ class MovingAverage: # param_1 = obj.next(val) ``` +#### Java + ```java class MovingAverage { private Deque q = new ArrayDeque<>(); @@ -225,6 +237,8 @@ class MovingAverage { */ ``` +#### C++ + ```cpp class MovingAverage { public: @@ -255,6 +269,8 @@ private: */ ``` +#### Go + ```go type MovingAverage struct { q []int diff --git a/solution/0300-0399/0346.Moving Average from Data Stream/README_EN.md b/solution/0300-0399/0346.Moving Average from Data Stream/README_EN.md index 14480c3a794eb..e6c04298ab273 100644 --- a/solution/0300-0399/0346.Moving Average from Data Stream/README_EN.md +++ b/solution/0300-0399/0346.Moving Average from Data Stream/README_EN.md @@ -65,6 +65,8 @@ movingAverage.next(5); // return 6.0 = (10 + 3 + 5) / 3 +#### Python3 + ```python class MovingAverage: def __init__(self, size: int): @@ -85,6 +87,8 @@ class MovingAverage: # param_1 = obj.next(val) ``` +#### Java + ```java class MovingAverage { private int[] arr; @@ -111,6 +115,8 @@ class MovingAverage { */ ``` +#### C++ + ```cpp class MovingAverage { public: @@ -139,6 +145,8 @@ private: */ ``` +#### Go + ```go type MovingAverage struct { arr []int @@ -176,6 +184,8 @@ func (this *MovingAverage) Next(val int) float64 { +#### Python3 + ```python class MovingAverage: def __init__(self, size: int): @@ -196,6 +206,8 @@ class MovingAverage: # param_1 = obj.next(val) ``` +#### Java + ```java class MovingAverage { private Deque q = new ArrayDeque<>(); @@ -223,6 +235,8 @@ class MovingAverage { */ ``` +#### C++ + ```cpp class MovingAverage { public: @@ -253,6 +267,8 @@ private: */ ``` +#### Go + ```go type MovingAverage struct { q []int diff --git a/solution/0300-0399/0347.Top K Frequent Elements/README.md b/solution/0300-0399/0347.Top K Frequent Elements/README.md index bbb5ce645c4fe..b8421d7368cba 100644 --- a/solution/0300-0399/0347.Top K Frequent Elements/README.md +++ b/solution/0300-0399/0347.Top K Frequent Elements/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def topKFrequent(self, nums: List[int], k: int) -> List[int]: @@ -75,6 +77,8 @@ class Solution: return [v[0] for v in cnt.most_common(k)] ``` +#### Java + ```java class Solution { public int[] topKFrequent(int[] nums, int k) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp using pii = pair; @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func topKFrequent(nums []int, k int) []int { cnt := map[int]int{} @@ -147,6 +155,8 @@ func (h *hp) Push(v any) { *h = append(*h, v.(pair)) } func (h *hp) Pop() any { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; return v } ``` +#### TypeScript + ```ts function topKFrequent(nums: number[], k: number): number[] { let hashMap = new Map(); @@ -163,6 +173,8 @@ function topKFrequent(nums: number[], k: number): number[] { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { @@ -204,6 +216,8 @@ impl Solution { +#### Python3 + ```python class Solution: def topKFrequent(self, nums: List[int], k: int) -> List[int]: @@ -216,6 +230,8 @@ class Solution: return [v[1] for v in hp] ``` +#### Java + ```java class Solution { public int[] topKFrequent(int[] nums, int k) { @@ -239,6 +255,8 @@ class Solution { } ``` +#### TypeScript + ```ts function topKFrequent(nums: number[], k: number): number[] { const map = new Map(); diff --git a/solution/0300-0399/0347.Top K Frequent Elements/README_EN.md b/solution/0300-0399/0347.Top K Frequent Elements/README_EN.md index 594e657f1204a..11e80c6b8e2d5 100644 --- a/solution/0300-0399/0347.Top K Frequent Elements/README_EN.md +++ b/solution/0300-0399/0347.Top K Frequent Elements/README_EN.md @@ -56,6 +56,8 @@ tags: +#### Python3 + ```python class Solution: def topKFrequent(self, nums: List[int], k: int) -> List[int]: @@ -63,6 +65,8 @@ class Solution: return [v[0] for v in cnt.most_common(k)] ``` +#### Java + ```java class Solution { public int[] topKFrequent(int[] nums, int k) { @@ -80,6 +84,8 @@ class Solution { } ``` +#### C++ + ```cpp using pii = pair; @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func topKFrequent(nums []int, k int) []int { cnt := map[int]int{} @@ -135,6 +143,8 @@ func (h *hp) Push(v any) { *h = append(*h, v.(pair)) } func (h *hp) Pop() any { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; return v } ``` +#### TypeScript + ```ts function topKFrequent(nums: number[], k: number): number[] { let hashMap = new Map(); @@ -151,6 +161,8 @@ function topKFrequent(nums: number[], k: number): number[] { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { @@ -192,6 +204,8 @@ impl Solution { +#### Python3 + ```python class Solution: def topKFrequent(self, nums: List[int], k: int) -> List[int]: @@ -204,6 +218,8 @@ class Solution: return [v[1] for v in hp] ``` +#### Java + ```java class Solution { public int[] topKFrequent(int[] nums, int k) { @@ -227,6 +243,8 @@ class Solution { } ``` +#### TypeScript + ```ts function topKFrequent(nums: number[], k: number): number[] { const map = new Map(); diff --git a/solution/0300-0399/0348.Design Tic-Tac-Toe/README.md b/solution/0300-0399/0348.Design Tic-Tac-Toe/README.md index 933fd6593fbe9..788c3393a8a9c 100644 --- a/solution/0300-0399/0348.Design Tic-Tac-Toe/README.md +++ b/solution/0300-0399/0348.Design Tic-Tac-Toe/README.md @@ -89,6 +89,8 @@ toe.move(2, 1, 1); -> 函数返回 1 (此时,玩家 1 赢得了该场比赛 +#### Python3 + ```python class TicTacToe: def __init__(self, n: int): @@ -131,6 +133,8 @@ class TicTacToe: # param_1 = obj.move(row,col,player) ``` +#### Java + ```java class TicTacToe { private int n; diff --git a/solution/0300-0399/0348.Design Tic-Tac-Toe/README_EN.md b/solution/0300-0399/0348.Design Tic-Tac-Toe/README_EN.md index 2e541ef4eb9f9..5245605846eac 100644 --- a/solution/0300-0399/0348.Design Tic-Tac-Toe/README_EN.md +++ b/solution/0300-0399/0348.Design Tic-Tac-Toe/README_EN.md @@ -114,6 +114,8 @@ ticTacToe.move(2, 1, 1); // return 1 (player 1 wins) +#### Python3 + ```python class TicTacToe: def __init__(self, n: int): @@ -156,6 +158,8 @@ class TicTacToe: # param_1 = obj.move(row,col,player) ``` +#### Java + ```java class TicTacToe { private int n; diff --git a/solution/0300-0399/0349.Intersection of Two Arrays/README.md b/solution/0300-0399/0349.Intersection of Two Arrays/README.md index 8cf041769e2bb..7c30b676c89a4 100644 --- a/solution/0300-0399/0349.Intersection of Two Arrays/README.md +++ b/solution/0300-0399/0349.Intersection of Two Arrays/README.md @@ -64,12 +64,16 @@ tags: +#### Python3 + ```python class Solution: def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]: return list(set(nums1) & set(nums2)) ``` +#### Java + ```java class Solution { public int[] intersection(int[] nums1, int[] nums2) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func intersection(nums1 []int, nums2 []int) (ans []int) { s := [1001]bool{} @@ -126,6 +134,8 @@ func intersection(nums1 []int, nums2 []int) (ans []int) { } ``` +#### JavaScript + ```js /** * @param {number[]} nums1 @@ -148,6 +158,8 @@ var intersection = function (nums1, nums2) { }; ``` +#### C# + ```cs public class Solution { public int[] Intersection(int[] nums1, int[] nums2) { @@ -164,6 +176,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** @@ -198,6 +212,8 @@ class Solution { +#### JavaScript + ```js /** * @param {number[]} nums1 diff --git a/solution/0300-0399/0349.Intersection of Two Arrays/README_EN.md b/solution/0300-0399/0349.Intersection of Two Arrays/README_EN.md index 32c808b94a21a..5b781abce29c9 100644 --- a/solution/0300-0399/0349.Intersection of Two Arrays/README_EN.md +++ b/solution/0300-0399/0349.Intersection of Two Arrays/README_EN.md @@ -56,12 +56,16 @@ tags: +#### Python3 + ```python class Solution: def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]: return list(set(nums1) & set(nums2)) ``` +#### Java + ```java class Solution { public int[] intersection(int[] nums1, int[] nums2) { @@ -81,6 +85,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -102,6 +108,8 @@ public: }; ``` +#### Go + ```go func intersection(nums1 []int, nums2 []int) (ans []int) { s := [1001]bool{} @@ -118,6 +126,8 @@ func intersection(nums1 []int, nums2 []int) (ans []int) { } ``` +#### JavaScript + ```js /** * @param {number[]} nums1 @@ -140,6 +150,8 @@ var intersection = function (nums1, nums2) { }; ``` +#### C# + ```cs public class Solution { public int[] Intersection(int[] nums1, int[] nums2) { @@ -156,6 +168,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** @@ -190,6 +204,8 @@ class Solution { +#### JavaScript + ```js /** * @param {number[]} nums1 diff --git a/solution/0300-0399/0350.Intersection of Two Arrays II/README.md b/solution/0300-0399/0350.Intersection of Two Arrays II/README.md index 3727fa7edda8c..9c98b16525bb8 100644 --- a/solution/0300-0399/0350.Intersection of Two Arrays II/README.md +++ b/solution/0300-0399/0350.Intersection of Two Arrays II/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]: @@ -78,6 +80,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public int[] intersect(int[] nums1, int[] nums2) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func intersect(nums1 []int, nums2 []int) []int { counter := make(map[int]int) @@ -136,6 +144,8 @@ func intersect(nums1 []int, nums2 []int) []int { } ``` +#### TypeScript + ```ts function intersect(nums1: number[], nums2: number[]): number[] { const map = new Map(); @@ -154,6 +164,8 @@ function intersect(nums1: number[], nums2: number[]): number[] { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { @@ -175,6 +187,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums1 @@ -197,6 +211,8 @@ var intersect = function (nums1, nums2) { }; ``` +#### C# + ```cs public class Solution { public int[] Intersect(int[] nums1, int[] nums2) { @@ -228,6 +244,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0300-0399/0350.Intersection of Two Arrays II/README_EN.md b/solution/0300-0399/0350.Intersection of Two Arrays II/README_EN.md index e7b3f01119e8c..c09bd53cd6f6e 100644 --- a/solution/0300-0399/0350.Intersection of Two Arrays II/README_EN.md +++ b/solution/0300-0399/0350.Intersection of Two Arrays II/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]: @@ -77,6 +79,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public int[] intersect(int[] nums1, int[] nums2) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func intersect(nums1 []int, nums2 []int) []int { counter := make(map[int]int) @@ -135,6 +143,8 @@ func intersect(nums1 []int, nums2 []int) []int { } ``` +#### TypeScript + ```ts function intersect(nums1: number[], nums2: number[]): number[] { const map = new Map(); @@ -153,6 +163,8 @@ function intersect(nums1: number[], nums2: number[]): number[] { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { @@ -174,6 +186,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums1 @@ -196,6 +210,8 @@ var intersect = function (nums1, nums2) { }; ``` +#### C# + ```cs public class Solution { public int[] Intersect(int[] nums1, int[] nums2) { @@ -227,6 +243,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0300-0399/0351.Android Unlock Patterns/README.md b/solution/0300-0399/0351.Android Unlock Patterns/README.md index f4080ce61848a..6a1eda45b9ea3 100644 --- a/solution/0300-0399/0351.Android Unlock Patterns/README.md +++ b/solution/0300-0399/0351.Android Unlock Patterns/README.md @@ -106,6 +106,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfPatterns(self, m: int, n: int) -> int: @@ -134,6 +136,8 @@ class Solution: return dfs(1) * 4 + dfs(2) * 4 + dfs(5) ``` +#### Java + ```java class Solution { private int m; @@ -173,6 +177,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -211,6 +217,8 @@ public: }; ``` +#### Go + ```go func numberOfPatterns(m int, n int) int { cross := [10][10]int{} @@ -254,6 +262,8 @@ func numberOfPatterns(m int, n int) int { } ``` +#### TypeScript + ```ts function numberOfPatterns(m: number, n: number): number { const cross: number[][] = Array(10) diff --git a/solution/0300-0399/0351.Android Unlock Patterns/README_EN.md b/solution/0300-0399/0351.Android Unlock Patterns/README_EN.md index d33245279d621..2085706cc930f 100644 --- a/solution/0300-0399/0351.Android Unlock Patterns/README_EN.md +++ b/solution/0300-0399/0351.Android Unlock Patterns/README_EN.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfPatterns(self, m: int, n: int) -> int: @@ -106,6 +108,8 @@ class Solution: return dfs(1) * 4 + dfs(2) * 4 + dfs(5) ``` +#### Java + ```java class Solution { private int m; @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -183,6 +189,8 @@ public: }; ``` +#### Go + ```go func numberOfPatterns(m int, n int) int { cross := [10][10]int{} @@ -226,6 +234,8 @@ func numberOfPatterns(m int, n int) int { } ``` +#### TypeScript + ```ts function numberOfPatterns(m: number, n: number): number { const cross: number[][] = Array(10) diff --git a/solution/0300-0399/0352.Data Stream as Disjoint Intervals/README.md b/solution/0300-0399/0352.Data Stream as Disjoint Intervals/README.md index 145b891dcc3ea..5e2f868f6579d 100644 --- a/solution/0300-0399/0352.Data Stream as Disjoint Intervals/README.md +++ b/solution/0300-0399/0352.Data Stream as Disjoint Intervals/README.md @@ -80,6 +80,8 @@ summaryRanges.getIntervals(); // 返回 [[1, 3], [6, 7]] +#### Python3 + ```python from sortedcontainers import SortedDict @@ -119,6 +121,8 @@ class SummaryRanges: # # param_2 = obj.getIntervals() ``` +#### Java + ```java class SummaryRanges { private TreeMap mp; @@ -160,6 +164,8 @@ class SummaryRanges { */ ``` +#### C++ + ```cpp class SummaryRanges { private: diff --git a/solution/0300-0399/0352.Data Stream as Disjoint Intervals/README_EN.md b/solution/0300-0399/0352.Data Stream as Disjoint Intervals/README_EN.md index 024be83276260..4564125c8466d 100644 --- a/solution/0300-0399/0352.Data Stream as Disjoint Intervals/README_EN.md +++ b/solution/0300-0399/0352.Data Stream as Disjoint Intervals/README_EN.md @@ -74,6 +74,8 @@ summaryRanges.getIntervals(); // return [[1, 3], [6, 7]] +#### Python3 + ```python from sortedcontainers import SortedDict @@ -113,6 +115,8 @@ class SummaryRanges: # # param_2 = obj.getIntervals() ``` +#### Java + ```java class SummaryRanges { private TreeMap mp; @@ -154,6 +158,8 @@ class SummaryRanges { */ ``` +#### C++ + ```cpp class SummaryRanges { private: diff --git a/solution/0300-0399/0353.Design Snake Game/README.md b/solution/0300-0399/0353.Design Snake Game/README.md index 172f219c0e90b..b55589bcc4e45 100644 --- a/solution/0300-0399/0353.Design Snake Game/README.md +++ b/solution/0300-0399/0353.Design Snake Game/README.md @@ -99,6 +99,8 @@ snakeGame.move("U"); // 返回 -1 ,蛇与边界相撞,游戏结束 +#### Python3 + ```python class SnakeGame: def __init__(self, width: int, height: int, food: List[List[int]]): @@ -145,6 +147,8 @@ class SnakeGame: # param_1 = obj.move(direction) ``` +#### Java + ```java class SnakeGame { private int m; @@ -207,6 +211,8 @@ class SnakeGame { */ ``` +#### C++ + ```cpp class SnakeGame { public: @@ -274,6 +280,8 @@ private: */ ``` +#### Go + ```go type SnakeGame struct { m int @@ -332,6 +340,8 @@ func (this *SnakeGame) Move(direction string) int { */ ``` +#### TypeScript + ```ts class SnakeGame { private m: number; diff --git a/solution/0300-0399/0353.Design Snake Game/README_EN.md b/solution/0300-0399/0353.Design Snake Game/README_EN.md index 8c7cd027f1167..e721d98b8ad85 100644 --- a/solution/0300-0399/0353.Design Snake Game/README_EN.md +++ b/solution/0300-0399/0353.Design Snake Game/README_EN.md @@ -84,6 +84,8 @@ snakeGame.move("U"); // return -1, game over because snake collides wi +#### Python3 + ```python class SnakeGame: def __init__(self, width: int, height: int, food: List[List[int]]): @@ -130,6 +132,8 @@ class SnakeGame: # param_1 = obj.move(direction) ``` +#### Java + ```java class SnakeGame { private int m; @@ -192,6 +196,8 @@ class SnakeGame { */ ``` +#### C++ + ```cpp class SnakeGame { public: @@ -259,6 +265,8 @@ private: */ ``` +#### Go + ```go type SnakeGame struct { m int @@ -317,6 +325,8 @@ func (this *SnakeGame) Move(direction string) int { */ ``` +#### TypeScript + ```ts class SnakeGame { private m: number; diff --git a/solution/0300-0399/0354.Russian Doll Envelopes/README.md b/solution/0300-0399/0354.Russian Doll Envelopes/README.md index 3e496308d9273..5b6a6318c51c0 100644 --- a/solution/0300-0399/0354.Russian Doll Envelopes/README.md +++ b/solution/0300-0399/0354.Russian Doll Envelopes/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def maxEnvelopes(self, envelopes: List[List[int]]) -> int: @@ -80,6 +82,8 @@ class Solution: return len(d) ``` +#### Java + ```java class Solution { public int maxEnvelopes(int[][] envelopes) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func maxEnvelopes(envelopes [][]int) int { sort.Slice(envelopes, func(i, j int) bool { diff --git a/solution/0300-0399/0354.Russian Doll Envelopes/README_EN.md b/solution/0300-0399/0354.Russian Doll Envelopes/README_EN.md index 9ae274a4560b0..5b0b9660ee708 100644 --- a/solution/0300-0399/0354.Russian Doll Envelopes/README_EN.md +++ b/solution/0300-0399/0354.Russian Doll Envelopes/README_EN.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def maxEnvelopes(self, envelopes: List[List[int]]) -> int: @@ -78,6 +80,8 @@ class Solution: return len(d) ``` +#### Java + ```java class Solution { public int maxEnvelopes(int[][] envelopes) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func maxEnvelopes(envelopes [][]int) int { sort.Slice(envelopes, func(i, j int) bool { diff --git a/solution/0300-0399/0355.Design Twitter/README.md b/solution/0300-0399/0355.Design Twitter/README.md index 8b9936824f1e4..700cde607be10 100644 --- a/solution/0300-0399/0355.Design Twitter/README.md +++ b/solution/0300-0399/0355.Design Twitter/README.md @@ -73,6 +73,8 @@ twitter.getNewsFeed(1); // 用户 1 获取推文应当返回一个列表,其 +#### Python3 + ```python class Twitter: def __init__(self): @@ -126,6 +128,8 @@ class Twitter: # obj.unfollow(followerId,followeeId) ``` +#### Java + ```java class Twitter { private Map> userTweets; diff --git a/solution/0300-0399/0355.Design Twitter/README_EN.md b/solution/0300-0399/0355.Design Twitter/README_EN.md index 182ba7a94569c..fc90741122dcf 100644 --- a/solution/0300-0399/0355.Design Twitter/README_EN.md +++ b/solution/0300-0399/0355.Design Twitter/README_EN.md @@ -72,6 +72,8 @@ twitter.getNewsFeed(1); // User 1's news feed should return a list with 1 t +#### Python3 + ```python class Twitter: def __init__(self): @@ -125,6 +127,8 @@ class Twitter: # obj.unfollow(followerId,followeeId) ``` +#### Java + ```java class Twitter { private Map> userTweets; diff --git a/solution/0300-0399/0356.Line Reflection/README.md b/solution/0300-0399/0356.Line Reflection/README.md index 086063424f5ce..8d78e5c8468be 100644 --- a/solution/0300-0399/0356.Line Reflection/README.md +++ b/solution/0300-0399/0356.Line Reflection/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def isReflected(self, points: List[List[int]]) -> bool: @@ -82,6 +84,8 @@ class Solution: return all((s - x, y) in point_set for x, y in points) ``` +#### Java + ```java class Solution { public boolean isReflected(int[][] points) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func isReflected(points [][]int) bool { const inf = 1 << 30 diff --git a/solution/0300-0399/0356.Line Reflection/README_EN.md b/solution/0300-0399/0356.Line Reflection/README_EN.md index eb1defc71a6aa..aee5e4e81b88e 100644 --- a/solution/0300-0399/0356.Line Reflection/README_EN.md +++ b/solution/0300-0399/0356.Line Reflection/README_EN.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def isReflected(self, points: List[List[int]]) -> bool: @@ -76,6 +78,8 @@ class Solution: return all((s - x, y) in point_set for x, y in points) ``` +#### Java + ```java class Solution { public boolean isReflected(int[][] points) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func isReflected(points [][]int) bool { const inf = 1 << 30 diff --git a/solution/0300-0399/0357.Count Numbers with Unique Digits/README.md b/solution/0300-0399/0357.Count Numbers with Unique Digits/README.md index 3ceaf1c4d2685..438b25f5fc0fa 100644 --- a/solution/0300-0399/0357.Count Numbers with Unique Digits/README.md +++ b/solution/0300-0399/0357.Count Numbers with Unique Digits/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def countNumbersWithUniqueDigits(self, n: int) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countNumbersWithUniqueDigits(int n) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func countNumbersWithUniqueDigits(n int) int { if n == 0 { @@ -178,6 +186,8 @@ $$ +#### Python3 + ```python class Solution: def countNumbersWithUniqueDigits(self, n: int) -> int: @@ -198,6 +208,8 @@ class Solution: return dfs(n, 0, True) ``` +#### Java + ```java class Solution { private int[][] dp = new int[10][1 << 11]; @@ -235,6 +247,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -269,6 +283,8 @@ public: }; ``` +#### Go + ```go func countNumbersWithUniqueDigits(n int) int { dp := make([][]int, 10) diff --git a/solution/0300-0399/0357.Count Numbers with Unique Digits/README_EN.md b/solution/0300-0399/0357.Count Numbers with Unique Digits/README_EN.md index 50003a4985fc6..20f6e0226e6e3 100644 --- a/solution/0300-0399/0357.Count Numbers with Unique Digits/README_EN.md +++ b/solution/0300-0399/0357.Count Numbers with Unique Digits/README_EN.md @@ -53,6 +53,8 @@ tags: +#### Python3 + ```python class Solution: def countNumbersWithUniqueDigits(self, n: int) -> int: @@ -67,6 +69,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countNumbersWithUniqueDigits(int n) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -102,6 +108,8 @@ public: }; ``` +#### Go + ```go func countNumbersWithUniqueDigits(n int) int { if n == 0 { @@ -129,6 +137,8 @@ func countNumbersWithUniqueDigits(n int) int { +#### Python3 + ```python class Solution: def countNumbersWithUniqueDigits(self, n: int) -> int: @@ -149,6 +159,8 @@ class Solution: return dfs(n, 0, True) ``` +#### Java + ```java class Solution { private int[][] dp = new int[10][1 << 11]; @@ -186,6 +198,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -220,6 +234,8 @@ public: }; ``` +#### Go + ```go func countNumbersWithUniqueDigits(n int) int { dp := make([][]int, 10) diff --git a/solution/0300-0399/0358.Rearrange String k Distance Apart/README.md b/solution/0300-0399/0358.Rearrange String k Distance Apart/README.md index 33b0750b68292..55366afd9dd02 100644 --- a/solution/0300-0399/0358.Rearrange String k Distance Apart/README.md +++ b/solution/0300-0399/0358.Rearrange String k Distance Apart/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def rearrangeString(self, s: str, k: int) -> str: @@ -100,6 +102,8 @@ class Solution: return "" if len(ans) != len(s) else "".join(ans) ``` +#### Java + ```java class Solution { public String rearrangeString(String s, int k) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func rearrangeString(s string, k int) string { cnt := map[byte]int{} diff --git a/solution/0300-0399/0358.Rearrange String k Distance Apart/README_EN.md b/solution/0300-0399/0358.Rearrange String k Distance Apart/README_EN.md index 69aa10a190d4d..e07f9869ecae5 100644 --- a/solution/0300-0399/0358.Rearrange String k Distance Apart/README_EN.md +++ b/solution/0300-0399/0358.Rearrange String k Distance Apart/README_EN.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def rearrangeString(self, s: str, k: int) -> str: @@ -86,6 +88,8 @@ class Solution: return "" if len(ans) != len(s) else "".join(ans) ``` +#### Java + ```java class Solution { public String rearrangeString(String s, int k) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func rearrangeString(s string, k int) string { cnt := map[byte]int{} diff --git a/solution/0300-0399/0359.Logger Rate Limiter/README.md b/solution/0300-0399/0359.Logger Rate Limiter/README.md index 17e3e51553895..863840fa2e499 100644 --- a/solution/0300-0399/0359.Logger Rate Limiter/README.md +++ b/solution/0300-0399/0359.Logger Rate Limiter/README.md @@ -71,6 +71,8 @@ logger.shouldPrintMessage(11, "foo"); // 11 >= 11 ,返回 true ,下一次 "f +#### Python3 + ```python class Logger: def __init__(self): @@ -97,6 +99,8 @@ class Logger: # param_1 = obj.shouldPrintMessage(timestamp,message) ``` +#### Java + ```java class Logger { @@ -129,6 +133,8 @@ class Logger { */ ``` +#### JavaScript + ```js /** * Initialize your data structure here. diff --git a/solution/0300-0399/0359.Logger Rate Limiter/README_EN.md b/solution/0300-0399/0359.Logger Rate Limiter/README_EN.md index ed2acbdd68f3f..2c8b6b0213308 100644 --- a/solution/0300-0399/0359.Logger Rate Limiter/README_EN.md +++ b/solution/0300-0399/0359.Logger Rate Limiter/README_EN.md @@ -69,6 +69,8 @@ logger.shouldPrintMessage(11, "foo"); // 11 >= 11, return true, nex +#### Python3 + ```python class Logger: def __init__(self): @@ -95,6 +97,8 @@ class Logger: # param_1 = obj.shouldPrintMessage(timestamp,message) ``` +#### Java + ```java class Logger { @@ -127,6 +131,8 @@ class Logger { */ ``` +#### JavaScript + ```js /** * Initialize your data structure here. diff --git a/solution/0300-0399/0360.Sort Transformed Array/README.md b/solution/0300-0399/0360.Sort Transformed Array/README.md index 15c663c43d51b..85361f93c7cf3 100644 --- a/solution/0300-0399/0360.Sort Transformed Array/README.md +++ b/solution/0300-0399/0360.Sort Transformed Array/README.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def sortTransformedArray( @@ -93,6 +95,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public int[] sortTransformedArray(int[] nums, int a, int b, int c) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func sortTransformedArray(nums []int, a int, b int, c int) []int { n := len(nums) diff --git a/solution/0300-0399/0360.Sort Transformed Array/README_EN.md b/solution/0300-0399/0360.Sort Transformed Array/README_EN.md index a339939353bcb..9f4d054ccf088 100644 --- a/solution/0300-0399/0360.Sort Transformed Array/README_EN.md +++ b/solution/0300-0399/0360.Sort Transformed Array/README_EN.md @@ -51,6 +51,8 @@ tags: +#### Python3 + ```python class Solution: def sortTransformedArray( @@ -83,6 +85,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public int[] sortTransformedArray(int[] nums, int a, int b, int c) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func sortTransformedArray(nums []int, a int, b int, c int) []int { n := len(nums) diff --git a/solution/0300-0399/0361.Bomb Enemy/README.md b/solution/0300-0399/0361.Bomb Enemy/README.md index 410bc5e078dec..28566258c0156 100644 --- a/solution/0300-0399/0361.Bomb Enemy/README.md +++ b/solution/0300-0399/0361.Bomb Enemy/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def maxKilledEnemies(self, grid: List[List[str]]) -> int: @@ -108,6 +110,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public int maxKilledEnemies(char[][] grid) { @@ -167,6 +171,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -220,6 +226,8 @@ public: }; ``` +#### Go + ```go func maxKilledEnemies(grid [][]byte) int { m, n := len(grid), len(grid[0]) diff --git a/solution/0300-0399/0361.Bomb Enemy/README_EN.md b/solution/0300-0399/0361.Bomb Enemy/README_EN.md index ace48c19ae815..fef14d96e5af9 100644 --- a/solution/0300-0399/0361.Bomb Enemy/README_EN.md +++ b/solution/0300-0399/0361.Bomb Enemy/README_EN.md @@ -57,6 +57,8 @@ tags: +#### Python3 + ```python class Solution: def maxKilledEnemies(self, grid: List[List[str]]) -> int: @@ -98,6 +100,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public int maxKilledEnemies(char[][] grid) { @@ -157,6 +161,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -210,6 +216,8 @@ public: }; ``` +#### Go + ```go func maxKilledEnemies(grid [][]byte) int { m, n := len(grid), len(grid[0]) diff --git a/solution/0300-0399/0362.Design Hit Counter/README.md b/solution/0300-0399/0362.Design Hit Counter/README.md index 20fc18758ad97..8b7dc45795fa3 100644 --- a/solution/0300-0399/0362.Design Hit Counter/README.md +++ b/solution/0300-0399/0362.Design Hit Counter/README.md @@ -78,6 +78,8 @@ counter.getHits(301); // 在时刻 301 统计过去 5 分钟内的敲击次数 +#### Python3 + ```python class HitCounter: def __init__(self): @@ -107,6 +109,8 @@ class HitCounter: # param_2 = obj.getHits(timestamp) ``` +#### Java + ```java class HitCounter { @@ -148,6 +152,8 @@ class HitCounter { */ ``` +#### Rust + ```rust use std::{ collections::BinaryHeap, cmp::Reverse }; diff --git a/solution/0300-0399/0362.Design Hit Counter/README_EN.md b/solution/0300-0399/0362.Design Hit Counter/README_EN.md index 7a45eb7f18ac1..4d2ea674fb8c7 100644 --- a/solution/0300-0399/0362.Design Hit Counter/README_EN.md +++ b/solution/0300-0399/0362.Design Hit Counter/README_EN.md @@ -75,6 +75,8 @@ hitCounter.getHits(301); // get hits at timestamp 301, return 3. +#### Python3 + ```python class HitCounter: def __init__(self): @@ -104,6 +106,8 @@ class HitCounter: # param_2 = obj.getHits(timestamp) ``` +#### Java + ```java class HitCounter { @@ -145,6 +149,8 @@ class HitCounter { */ ``` +#### Rust + ```rust use std::{ collections::BinaryHeap, cmp::Reverse }; diff --git a/solution/0300-0399/0363.Max Sum of Rectangle No Larger Than K/README.md b/solution/0300-0399/0363.Max Sum of Rectangle No Larger Than K/README.md index ae50343415c10..dda2cb4308245 100644 --- a/solution/0300-0399/0363.Max Sum of Rectangle No Larger Than K/README.md +++ b/solution/0300-0399/0363.Max Sum of Rectangle No Larger Than K/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python from sortedcontainers import SortedSet @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxSumSubmatrix(int[][] matrix, int k) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func maxSumSubmatrix(matrix [][]int, k int) int { m, n := len(matrix), len(matrix[0]) @@ -187,6 +195,8 @@ func maxSumSubmatrix(matrix [][]int, k int) int { } ``` +#### TypeScript + ```ts function maxSumSubmatrix(matrix: number[][], k: number): number { const m = matrix.length; diff --git a/solution/0300-0399/0363.Max Sum of Rectangle No Larger Than K/README_EN.md b/solution/0300-0399/0363.Max Sum of Rectangle No Larger Than K/README_EN.md index f0750f66c7b8b..88c8e562b3209 100644 --- a/solution/0300-0399/0363.Max Sum of Rectangle No Larger Than K/README_EN.md +++ b/solution/0300-0399/0363.Max Sum of Rectangle No Larger Than K/README_EN.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python from sortedcontainers import SortedSet @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxSumSubmatrix(int[][] matrix, int k) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func maxSumSubmatrix(matrix [][]int, k int) int { m, n := len(matrix), len(matrix[0]) @@ -178,6 +186,8 @@ func maxSumSubmatrix(matrix [][]int, k int) int { } ``` +#### TypeScript + ```ts function maxSumSubmatrix(matrix: number[][], k: number): number { const m = matrix.length; diff --git a/solution/0300-0399/0364.Nested List Weight Sum II/README.md b/solution/0300-0399/0364.Nested List Weight Sum II/README.md index 5280bbb2ff30e..97722ef3318f0 100644 --- a/solution/0300-0399/0364.Nested List Weight Sum II/README.md +++ b/solution/0300-0399/0364.Nested List Weight Sum II/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python # """ # This is the interface that allows for creating nested lists. @@ -132,6 +134,8 @@ class Solution: return dfs(nestedList, depth) ``` +#### Java + ```java /** * // This is the interface that allows for creating nested lists. @@ -192,6 +196,8 @@ class Solution { } ``` +#### JavaScript + ```js /** * // This is the interface that allows for creating nested lists. diff --git a/solution/0300-0399/0364.Nested List Weight Sum II/README_EN.md b/solution/0300-0399/0364.Nested List Weight Sum II/README_EN.md index 9c70f5ecbbd45..affa7b248b19c 100644 --- a/solution/0300-0399/0364.Nested List Weight Sum II/README_EN.md +++ b/solution/0300-0399/0364.Nested List Weight Sum II/README_EN.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python # """ # This is the interface that allows for creating nested lists. @@ -130,6 +132,8 @@ class Solution: return dfs(nestedList, depth) ``` +#### Java + ```java /** * // This is the interface that allows for creating nested lists. @@ -190,6 +194,8 @@ class Solution { } ``` +#### JavaScript + ```js /** * // This is the interface that allows for creating nested lists. diff --git a/solution/0300-0399/0365.Water and Jug Problem/README.md b/solution/0300-0399/0365.Water and Jug Problem/README.md index e772c940f0eae..34a6f348b1e28 100644 --- a/solution/0300-0399/0365.Water and Jug Problem/README.md +++ b/solution/0300-0399/0365.Water and Jug Problem/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def canMeasureWater(self, x: int, y: int, z: int) -> bool: @@ -112,6 +114,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private Set vis = new HashSet<>(); @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -180,6 +186,8 @@ public: }; ``` +#### Go + ```go func canMeasureWater(x int, y int, z int) bool { type pair struct{ x, y int } diff --git a/solution/0300-0399/0365.Water and Jug Problem/README_EN.md b/solution/0300-0399/0365.Water and Jug Problem/README_EN.md index 0cd041afa02b2..06521e451b6e8 100644 --- a/solution/0300-0399/0365.Water and Jug Problem/README_EN.md +++ b/solution/0300-0399/0365.Water and Jug Problem/README_EN.md @@ -101,6 +101,8 @@ The time complexity is $O(x + y)$, and the space complexity is $O(x + y)$. Here, +#### Python3 + ```python class Solution: def canMeasureWater(self, x: int, y: int, z: int) -> bool: @@ -120,6 +122,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private Set vis = new HashSet<>(); @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go func canMeasureWater(x int, y int, z int) bool { type pair struct{ x, y int } diff --git a/solution/0300-0399/0366.Find Leaves of Binary Tree/README.md b/solution/0300-0399/0366.Find Leaves of Binary Tree/README.md index 37677820604a6..4df82ea3c34e7 100644 --- a/solution/0300-0399/0366.Find Leaves of Binary Tree/README.md +++ b/solution/0300-0399/0366.Find Leaves of Binary Tree/README.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -93,6 +95,8 @@ class Solution: return res ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -179,6 +185,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0300-0399/0366.Find Leaves of Binary Tree/README_EN.md b/solution/0300-0399/0366.Find Leaves of Binary Tree/README_EN.md index e1e210c3f83bc..b99f43ce50654 100644 --- a/solution/0300-0399/0366.Find Leaves of Binary Tree/README_EN.md +++ b/solution/0300-0399/0366.Find Leaves of Binary Tree/README_EN.md @@ -61,6 +61,8 @@ Explanation: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -91,6 +93,8 @@ class Solution: return res ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0300-0399/0367.Valid Perfect Square/README.md b/solution/0300-0399/0367.Valid Perfect Square/README.md index ad406844926ed..fbb0841074883 100644 --- a/solution/0300-0399/0367.Valid Perfect Square/README.md +++ b/solution/0300-0399/0367.Valid Perfect Square/README.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def isPerfectSquare(self, num: int) -> bool: @@ -76,6 +78,8 @@ class Solution: return left * left == num ``` +#### Java + ```java class Solution { public boolean isPerfectSquare(int num) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func isPerfectSquare(num int) bool { left, right := 1, num @@ -125,6 +133,8 @@ func isPerfectSquare(num int) bool { } ``` +#### TypeScript + ```ts function isPerfectSquare(num: number): boolean { let left = 1; @@ -141,6 +151,8 @@ function isPerfectSquare(num: number): boolean { } ``` +#### Rust + ```rust use std::cmp::Ordering; impl Solution { @@ -181,6 +193,8 @@ impl Solution { +#### Python3 + ```python class Solution: def isPerfectSquare(self, num: int) -> bool: @@ -191,6 +205,8 @@ class Solution: return num == 0 ``` +#### Java + ```java class Solution { public boolean isPerfectSquare(int num) { @@ -202,6 +218,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -212,6 +230,8 @@ public: }; ``` +#### Go + ```go func isPerfectSquare(num int) bool { for i := 1; num > 0; i += 2 { @@ -221,6 +241,8 @@ func isPerfectSquare(num int) bool { } ``` +#### TypeScript + ```ts function isPerfectSquare(num: number): boolean { let i = 1; @@ -232,6 +254,8 @@ function isPerfectSquare(num: number): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn is_perfect_square(mut num: i32) -> bool { diff --git a/solution/0300-0399/0367.Valid Perfect Square/README_EN.md b/solution/0300-0399/0367.Valid Perfect Square/README_EN.md index 81c3d6685061f..e45e691062d37 100644 --- a/solution/0300-0399/0367.Valid Perfect Square/README_EN.md +++ b/solution/0300-0399/0367.Valid Perfect Square/README_EN.md @@ -57,6 +57,8 @@ tags: +#### Python3 + ```python class Solution: def isPerfectSquare(self, num: int) -> bool: @@ -70,6 +72,8 @@ class Solution: return left * left == num ``` +#### Java + ```java class Solution { public boolean isPerfectSquare(int num) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -104,6 +110,8 @@ public: }; ``` +#### Go + ```go func isPerfectSquare(num int) bool { left, right := 1, num @@ -119,6 +127,8 @@ func isPerfectSquare(num int) bool { } ``` +#### TypeScript + ```ts function isPerfectSquare(num: number): boolean { let left = 1; @@ -135,6 +145,8 @@ function isPerfectSquare(num: number): boolean { } ``` +#### Rust + ```rust use std::cmp::Ordering; impl Solution { @@ -184,6 +196,8 @@ so 1+3+...+(2n-1) = (2n-1 + 1)n/2 = n² +#### Python3 + ```python class Solution: def isPerfectSquare(self, num: int) -> bool: @@ -194,6 +208,8 @@ class Solution: return num == 0 ``` +#### Java + ```java class Solution { public boolean isPerfectSquare(int num) { @@ -205,6 +221,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -215,6 +233,8 @@ public: }; ``` +#### Go + ```go func isPerfectSquare(num int) bool { for i := 1; num > 0; i += 2 { @@ -224,6 +244,8 @@ func isPerfectSquare(num int) bool { } ``` +#### TypeScript + ```ts function isPerfectSquare(num: number): boolean { let i = 1; @@ -235,6 +257,8 @@ function isPerfectSquare(num: number): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn is_perfect_square(mut num: i32) -> bool { diff --git a/solution/0300-0399/0368.Largest Divisible Subset/README.md b/solution/0300-0399/0368.Largest Divisible Subset/README.md index c0e94c95719a8..b3d3b284eedf3 100644 --- a/solution/0300-0399/0368.Largest Divisible Subset/README.md +++ b/solution/0300-0399/0368.Largest Divisible Subset/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def largestDivisibleSubset(self, nums: List[int]) -> List[int]: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List largestDivisibleSubset(int[] nums) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func largestDivisibleSubset(nums []int) (ans []int) { sort.Ints(nums) diff --git a/solution/0300-0399/0368.Largest Divisible Subset/README_EN.md b/solution/0300-0399/0368.Largest Divisible Subset/README_EN.md index a269f75bca87c..dc4c6e2a9992c 100644 --- a/solution/0300-0399/0368.Largest Divisible Subset/README_EN.md +++ b/solution/0300-0399/0368.Largest Divisible Subset/README_EN.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def largestDivisibleSubset(self, nums: List[int]) -> List[int]: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List largestDivisibleSubset(int[] nums) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func largestDivisibleSubset(nums []int) (ans []int) { sort.Ints(nums) diff --git a/solution/0300-0399/0369.Plus One Linked List/README.md b/solution/0300-0399/0369.Plus One Linked List/README.md index 5ad9da461327e..95eebe6928d74 100644 --- a/solution/0300-0399/0369.Plus One Linked List/README.md +++ b/solution/0300-0399/0369.Plus One Linked List/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -89,6 +91,8 @@ class Solution: return dummy if dummy.val else dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. diff --git a/solution/0300-0399/0369.Plus One Linked List/README_EN.md b/solution/0300-0399/0369.Plus One Linked List/README_EN.md index 9f92670af9a97..e56316d0e35b6 100644 --- a/solution/0300-0399/0369.Plus One Linked List/README_EN.md +++ b/solution/0300-0399/0369.Plus One Linked List/README_EN.md @@ -48,6 +48,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -70,6 +72,8 @@ class Solution: return dummy if dummy.val else dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. diff --git a/solution/0300-0399/0370.Range Addition/README.md b/solution/0300-0399/0370.Range Addition/README.md index a5ba15247b180..107a47d8f9599 100644 --- a/solution/0300-0399/0370.Range Addition/README.md +++ b/solution/0300-0399/0370.Range Addition/README.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def getModifiedArray(self, length: int, updates: List[List[int]]) -> List[int]: @@ -71,6 +73,8 @@ class Solution: return list(accumulate(d)) ``` +#### Java + ```java class Solution { public int[] getModifiedArray(int length, int[][] updates) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func getModifiedArray(length int, updates [][]int) []int { d := make([]int, length) @@ -123,6 +131,8 @@ func getModifiedArray(length int, updates [][]int) []int { } ``` +#### JavaScript + ```js /** * @param {number} length @@ -163,6 +173,8 @@ var getModifiedArray = function (length, updates) { +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -195,6 +207,8 @@ class Solution: return [tree.query(i + 1) for i in range(length)] ``` +#### Java + ```java class Solution { public int[] getModifiedArray(int length, int[][] updates) { @@ -243,6 +257,8 @@ class BinaryIndexedTree { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -290,6 +306,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int diff --git a/solution/0300-0399/0370.Range Addition/README_EN.md b/solution/0300-0399/0370.Range Addition/README_EN.md index 806d87bff78be..2c25b07ab487c 100644 --- a/solution/0300-0399/0370.Range Addition/README_EN.md +++ b/solution/0300-0399/0370.Range Addition/README_EN.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python class Solution: def getModifiedArray(self, length: int, updates: List[List[int]]) -> List[int]: @@ -69,6 +71,8 @@ class Solution: return list(accumulate(d)) ``` +#### Java + ```java class Solution { public int[] getModifiedArray(int length, int[][] updates) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -104,6 +110,8 @@ public: }; ``` +#### Go + ```go func getModifiedArray(length int, updates [][]int) []int { d := make([]int, length) @@ -121,6 +129,8 @@ func getModifiedArray(length int, updates [][]int) []int { } ``` +#### JavaScript + ```js /** * @param {number} length @@ -152,6 +162,8 @@ var getModifiedArray = function (length, updates) { +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -184,6 +196,8 @@ class Solution: return [tree.query(i + 1) for i in range(length)] ``` +#### Java + ```java class Solution { public int[] getModifiedArray(int length, int[][] updates) { @@ -232,6 +246,8 @@ class BinaryIndexedTree { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -279,6 +295,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int diff --git a/solution/0300-0399/0371.Sum of Two Integers/README.md b/solution/0300-0399/0371.Sum of Two Integers/README.md index 5d4c7465bef36..a81ffce15ffc1 100644 --- a/solution/0300-0399/0371.Sum of Two Integers/README.md +++ b/solution/0300-0399/0371.Sum of Two Integers/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def getSum(self, a: int, b: int) -> int: @@ -81,6 +83,8 @@ class Solution: return a if a < 0x80000000 else ~(a ^ 0xFFFFFFFF) ``` +#### Java + ```java class Solution { public int getSum(int a, int b) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -103,6 +109,8 @@ public: }; ``` +#### Go + ```go func getSum(a int, b int) int { for b != 0 { diff --git a/solution/0300-0399/0371.Sum of Two Integers/README_EN.md b/solution/0300-0399/0371.Sum of Two Integers/README_EN.md index a7db39839d2fa..4363d55bec98f 100644 --- a/solution/0300-0399/0371.Sum of Two Integers/README_EN.md +++ b/solution/0300-0399/0371.Sum of Two Integers/README_EN.md @@ -44,6 +44,8 @@ tags: +#### Python3 + ```python class Solution: def getSum(self, a: int, b: int) -> int: @@ -54,6 +56,8 @@ class Solution: return a if a < 0x80000000 else ~(a ^ 0xFFFFFFFF) ``` +#### Java + ```java class Solution { public int getSum(int a, int b) { @@ -62,6 +66,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -76,6 +82,8 @@ public: }; ``` +#### Go + ```go func getSum(a int, b int) int { for b != 0 { diff --git a/solution/0300-0399/0372.Super Pow/README.md b/solution/0300-0399/0372.Super Pow/README.md index 5448bb54bd366..57d9c0d816638 100644 --- a/solution/0300-0399/0372.Super Pow/README.md +++ b/solution/0300-0399/0372.Super Pow/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def superPow(self, a: int, b: List[int]) -> int: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private final int mod = 1337; @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func superPow(a int, b []int) int { const mod int = 1337 @@ -163,6 +171,8 @@ func superPow(a int, b []int) int { } ``` +#### TypeScript + ```ts function superPow(a: number, b: number[]): number { let ans = 1; diff --git a/solution/0300-0399/0372.Super Pow/README_EN.md b/solution/0300-0399/0372.Super Pow/README_EN.md index 5dd8cb6f9d1d0..24301541e285c 100644 --- a/solution/0300-0399/0372.Super Pow/README_EN.md +++ b/solution/0300-0399/0372.Super Pow/README_EN.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def superPow(self, a: int, b: List[int]) -> int: @@ -72,6 +74,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private final int mod = 1337; @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func superPow(a int, b []int) int { const mod int = 1337 @@ -146,6 +154,8 @@ func superPow(a int, b []int) int { } ``` +#### TypeScript + ```ts function superPow(a: number, b: number[]): number { let ans = 1; diff --git a/solution/0300-0399/0373.Find K Pairs with Smallest Sums/README.md b/solution/0300-0399/0373.Find K Pairs with Smallest Sums/README.md index caf5a66f9e11f..e0e2b0d5d28ef 100644 --- a/solution/0300-0399/0373.Find K Pairs with Smallest Sums/README.md +++ b/solution/0300-0399/0373.Find K Pairs with Smallest Sums/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def kSmallestPairs( @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> kSmallestPairs(int[] nums1, int[] nums2, int k) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func kSmallestPairs(nums1, nums2 []int, k int) (ans [][]int) { m, n := len(nums1), len(nums2) diff --git a/solution/0300-0399/0373.Find K Pairs with Smallest Sums/README_EN.md b/solution/0300-0399/0373.Find K Pairs with Smallest Sums/README_EN.md index 87581d997a223..0cde29140f92a 100644 --- a/solution/0300-0399/0373.Find K Pairs with Smallest Sums/README_EN.md +++ b/solution/0300-0399/0373.Find K Pairs with Smallest Sums/README_EN.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def kSmallestPairs( @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> kSmallestPairs(int[] nums1, int[] nums2, int k) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func kSmallestPairs(nums1, nums2 []int, k int) (ans [][]int) { m, n := len(nums1), len(nums2) diff --git a/solution/0300-0399/0374.Guess Number Higher or Lower/README.md b/solution/0300-0399/0374.Guess Number Higher or Lower/README.md index ce098054621f3..dd8062593cac3 100644 --- a/solution/0300-0399/0374.Guess Number Higher or Lower/README.md +++ b/solution/0300-0399/0374.Guess Number Higher or Lower/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python # The guess API is already defined for you. # @param num, your guess @@ -106,6 +108,8 @@ class Solution: return left ``` +#### Java + ```java /** * Forward declaration of guess API. @@ -132,6 +136,8 @@ public class Solution extends GuessGame { } ``` +#### C++ + ```cpp /** * Forward declaration of guess API. @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go /** * Forward declaration of guess API. @@ -183,6 +191,8 @@ func guessNumber(n int) int { } ``` +#### TypeScript + ```ts /** * Forward declaration of guess API. @@ -208,6 +218,8 @@ function guessNumber(n: number): number { } ``` +#### Rust + ```rust /** @@ -241,6 +253,8 @@ impl Solution { } ``` +#### C# + ```cs /** * Forward declaration of guess API. @@ -277,6 +291,8 @@ public class Solution : GuessGame { +#### Python3 + ```python # The guess API is already defined for you. # @param num, your guess @@ -291,6 +307,8 @@ class Solution: return bisect.bisect(range(1, n + 1), 0, key=lambda x: -guess(x)) ``` +#### Go + ```go /** * Forward declaration of guess API. diff --git a/solution/0300-0399/0374.Guess Number Higher or Lower/README_EN.md b/solution/0300-0399/0374.Guess Number Higher or Lower/README_EN.md index ad8895e34267f..a319fe2848b66 100644 --- a/solution/0300-0399/0374.Guess Number Higher or Lower/README_EN.md +++ b/solution/0300-0399/0374.Guess Number Higher or Lower/README_EN.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python # The guess API is already defined for you. # @param num, your guess @@ -92,6 +94,8 @@ class Solution: return left ``` +#### Java + ```java /** * Forward declaration of guess API. @@ -118,6 +122,8 @@ public class Solution extends GuessGame { } ``` +#### C++ + ```cpp /** * Forward declaration of guess API. @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go /** * Forward declaration of guess API. @@ -169,6 +177,8 @@ func guessNumber(n int) int { } ``` +#### TypeScript + ```ts /** * Forward declaration of guess API. @@ -194,6 +204,8 @@ function guessNumber(n: number): number { } ``` +#### Rust + ```rust /** * Forward declaration of guess API. @@ -226,6 +238,8 @@ impl Solution { } ``` +#### C# + ```cs /** * Forward declaration of guess API. @@ -262,6 +276,8 @@ public class Solution : GuessGame { +#### Python3 + ```python # The guess API is already defined for you. # @param num, your guess @@ -276,6 +292,8 @@ class Solution: return bisect.bisect(range(1, n + 1), 0, key=lambda x: -guess(x)) ``` +#### Go + ```go /** * Forward declaration of guess API. diff --git a/solution/0300-0399/0375.Guess Number Higher or Lower II/README.md b/solution/0300-0399/0375.Guess Number Higher or Lower II/README.md index ee1e69a98c044..2188a0a1c5f4d 100644 --- a/solution/0300-0399/0375.Guess Number Higher or Lower II/README.md +++ b/solution/0300-0399/0375.Guess Number Higher or Lower II/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class Solution: def getMoneyAmount(self, n: int) -> int: @@ -108,6 +110,8 @@ class Solution: return dp[1][n] ``` +#### Java + ```java class Solution { public int getMoneyAmount(int n) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func getMoneyAmount(n int) int { dp := make([][]int, n+10) diff --git a/solution/0300-0399/0375.Guess Number Higher or Lower II/README_EN.md b/solution/0300-0399/0375.Guess Number Higher or Lower II/README_EN.md index 51eb704227928..48bd4546a173b 100644 --- a/solution/0300-0399/0375.Guess Number Higher or Lower II/README_EN.md +++ b/solution/0300-0399/0375.Guess Number Higher or Lower II/README_EN.md @@ -92,6 +92,8 @@ The worst case is that you pay $1. +#### Python3 + ```python class Solution: def getMoneyAmount(self, n: int) -> int: @@ -106,6 +108,8 @@ class Solution: return dp[1][n] ``` +#### Java + ```java class Solution { public int getMoneyAmount(int n) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func getMoneyAmount(n int) int { dp := make([][]int, n+10) diff --git a/solution/0300-0399/0376.Wiggle Subsequence/README.md b/solution/0300-0399/0376.Wiggle Subsequence/README.md index 86db024b97ce3..8a555a50904fb 100644 --- a/solution/0300-0399/0376.Wiggle Subsequence/README.md +++ b/solution/0300-0399/0376.Wiggle Subsequence/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def wiggleMaxLength(self, nums: List[int]) -> int: @@ -92,6 +94,8 @@ class Solution: return max(up, down) ``` +#### Java + ```java class Solution { public int wiggleMaxLength(int[] nums) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func wiggleMaxLength(nums []int) int { up, down := 1, 1 @@ -139,6 +147,8 @@ func wiggleMaxLength(nums []int) int { } ``` +#### TypeScript + ```ts function wiggleMaxLength(nums: number[]): number { let up = 1, diff --git a/solution/0300-0399/0376.Wiggle Subsequence/README_EN.md b/solution/0300-0399/0376.Wiggle Subsequence/README_EN.md index 2554ca6160012..3326f86ee786c 100644 --- a/solution/0300-0399/0376.Wiggle Subsequence/README_EN.md +++ b/solution/0300-0399/0376.Wiggle Subsequence/README_EN.md @@ -75,6 +75,8 @@ One is [1, 17, 10, 13, 10, 16, 8] with differences (16, -7, 3, -3, 6, -8). +#### Python3 + ```python class Solution: def wiggleMaxLength(self, nums: List[int]) -> int: @@ -87,6 +89,8 @@ class Solution: return max(up, down) ``` +#### Java + ```java class Solution { public int wiggleMaxLength(int[] nums) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func wiggleMaxLength(nums []int) int { up, down := 1, 1 @@ -134,6 +142,8 @@ func wiggleMaxLength(nums []int) int { } ``` +#### TypeScript + ```ts function wiggleMaxLength(nums: number[]): number { let up = 1, diff --git a/solution/0300-0399/0377.Combination Sum IV/README.md b/solution/0300-0399/0377.Combination Sum IV/README.md index 93d989557e644..bba5a459c17f4 100644 --- a/solution/0300-0399/0377.Combination Sum IV/README.md +++ b/solution/0300-0399/0377.Combination Sum IV/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def combinationSum4(self, nums: List[int], target: int) -> int: @@ -91,6 +93,8 @@ class Solution: return f[target] ``` +#### Java + ```java class Solution { public int combinationSum4(int[] nums, int target) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func combinationSum4(nums []int, target int) int { f := make([]int, target+1) @@ -142,6 +150,8 @@ func combinationSum4(nums []int, target int) int { } ``` +#### TypeScript + ```ts function combinationSum4(nums: number[], target: number): number { const f: number[] = Array(target + 1).fill(0); @@ -157,6 +167,8 @@ function combinationSum4(nums: number[], target: number): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -177,6 +189,8 @@ var combinationSum4 = function (nums, target) { }; ``` +#### C# + ```cs public class Solution { public int CombinationSum4(int[] nums, int target) { diff --git a/solution/0300-0399/0377.Combination Sum IV/README_EN.md b/solution/0300-0399/0377.Combination Sum IV/README_EN.md index ad436605778a9..45c9e0af65701 100644 --- a/solution/0300-0399/0377.Combination Sum IV/README_EN.md +++ b/solution/0300-0399/0377.Combination Sum IV/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n \times target)$, and the space complexity is $O(targ +#### Python3 + ```python class Solution: def combinationSum4(self, nums: List[int], target: int) -> int: @@ -88,6 +90,8 @@ class Solution: return f[target] ``` +#### Java + ```java class Solution { public int combinationSum4(int[] nums, int target) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func combinationSum4(nums []int, target int) int { f := make([]int, target+1) @@ -139,6 +147,8 @@ func combinationSum4(nums []int, target int) int { } ``` +#### TypeScript + ```ts function combinationSum4(nums: number[], target: number): number { const f: number[] = Array(target + 1).fill(0); @@ -154,6 +164,8 @@ function combinationSum4(nums: number[], target: number): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -174,6 +186,8 @@ var combinationSum4 = function (nums, target) { }; ``` +#### C# + ```cs public class Solution { public int CombinationSum4(int[] nums, int target) { diff --git a/solution/0300-0399/0378.Kth Smallest Element in a Sorted Matrix/README.md b/solution/0300-0399/0378.Kth Smallest Element in a Sorted Matrix/README.md index f636fbb4849e4..b1c3f40a96ffc 100644 --- a/solution/0300-0399/0378.Kth Smallest Element in a Sorted Matrix/README.md +++ b/solution/0300-0399/0378.Kth Smallest Element in a Sorted Matrix/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def kthSmallest(self, matrix: List[List[int]], k: int) -> int: @@ -99,6 +101,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int kthSmallest(int[][] matrix, int k) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ private: }; ``` +#### Go + ```go func kthSmallest(matrix [][]int, k int) int { n := len(matrix) diff --git a/solution/0300-0399/0378.Kth Smallest Element in a Sorted Matrix/README_EN.md b/solution/0300-0399/0378.Kth Smallest Element in a Sorted Matrix/README_EN.md index b315afc2de647..40b0b1da86476 100644 --- a/solution/0300-0399/0378.Kth Smallest Element in a Sorted Matrix/README_EN.md +++ b/solution/0300-0399/0378.Kth Smallest Element in a Sorted Matrix/README_EN.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def kthSmallest(self, matrix: List[List[int]], k: int) -> int: @@ -96,6 +98,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int kthSmallest(int[][] matrix, int k) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ private: }; ``` +#### Go + ```go func kthSmallest(matrix [][]int, k int) int { n := len(matrix) diff --git a/solution/0300-0399/0379.Design Phone Directory/README.md b/solution/0300-0399/0379.Design Phone Directory/README.md index 2f42bbc258e0f..f553a7940cdf3 100644 --- a/solution/0300-0399/0379.Design Phone Directory/README.md +++ b/solution/0300-0399/0379.Design Phone Directory/README.md @@ -77,6 +77,8 @@ directory.check(2); +#### Python3 + ```python class PhoneDirectory: def __init__(self, maxNumbers: int): @@ -117,6 +119,8 @@ class PhoneDirectory: # obj.release(number) ``` +#### Java + ```java class PhoneDirectory { diff --git a/solution/0300-0399/0379.Design Phone Directory/README_EN.md b/solution/0300-0399/0379.Design Phone Directory/README_EN.md index f39f854193780..0e45d26b81770 100644 --- a/solution/0300-0399/0379.Design Phone Directory/README_EN.md +++ b/solution/0300-0399/0379.Design Phone Directory/README_EN.md @@ -71,6 +71,8 @@ phoneDirectory.check(2); // Number 2 is available again, return true. +#### Python3 + ```python class PhoneDirectory: def __init__(self, maxNumbers: int): @@ -111,6 +113,8 @@ class PhoneDirectory: # obj.release(number) ``` +#### Java + ```java class PhoneDirectory { diff --git a/solution/0300-0399/0380.Insert Delete GetRandom O(1)/README.md b/solution/0300-0399/0380.Insert Delete GetRandom O(1)/README.md index 25fa7d1918a5b..621d6f7163aaa 100644 --- a/solution/0300-0399/0380.Insert Delete GetRandom O(1)/README.md +++ b/solution/0300-0399/0380.Insert Delete GetRandom O(1)/README.md @@ -87,6 +87,8 @@ randomizedSet.getRandom(); // 由于 2 是集合中唯一的数字,getRandom +#### Python3 + ```python class RandomizedSet: def __init__(self): @@ -121,6 +123,8 @@ class RandomizedSet: # param_3 = obj.getRandom() ``` +#### Java + ```java class RandomizedSet { private Map d = new HashMap<>(); @@ -165,6 +169,8 @@ class RandomizedSet { */ ``` +#### C++ + ```cpp class RandomizedSet { public: @@ -210,6 +216,8 @@ private: */ ``` +#### Go + ```go type RandomizedSet struct { d map[int]int @@ -254,6 +262,8 @@ func (this *RandomizedSet) GetRandom() int { */ ``` +#### TypeScript + ```ts class RandomizedSet { private d: Map = new Map(); @@ -296,6 +306,8 @@ class RandomizedSet { */ ``` +#### Rust + ```rust use std::collections::HashSet; use rand::Rng; @@ -336,6 +348,8 @@ impl RandomizedSet { */ ``` +#### C# + ```cs public class RandomizedSet { private Dictionary d = new Dictionary(); diff --git a/solution/0300-0399/0380.Insert Delete GetRandom O(1)/README_EN.md b/solution/0300-0399/0380.Insert Delete GetRandom O(1)/README_EN.md index 1140989ec948c..2cb88f5a3acc7 100644 --- a/solution/0300-0399/0380.Insert Delete GetRandom O(1)/README_EN.md +++ b/solution/0300-0399/0380.Insert Delete GetRandom O(1)/README_EN.md @@ -81,6 +81,8 @@ Time complexity $O(1)$, space complexity $O(n)$, where $n$ is the number of elem +#### Python3 + ```python class RandomizedSet: def __init__(self): @@ -115,6 +117,8 @@ class RandomizedSet: # param_3 = obj.getRandom() ``` +#### Java + ```java class RandomizedSet { private Map d = new HashMap<>(); @@ -159,6 +163,8 @@ class RandomizedSet { */ ``` +#### C++ + ```cpp class RandomizedSet { public: @@ -204,6 +210,8 @@ private: */ ``` +#### Go + ```go type RandomizedSet struct { d map[int]int @@ -248,6 +256,8 @@ func (this *RandomizedSet) GetRandom() int { */ ``` +#### TypeScript + ```ts class RandomizedSet { private d: Map = new Map(); @@ -290,6 +300,8 @@ class RandomizedSet { */ ``` +#### Rust + ```rust use std::collections::HashSet; use rand::Rng; @@ -330,6 +342,8 @@ impl RandomizedSet { */ ``` +#### C# + ```cs public class RandomizedSet { private Dictionary d = new Dictionary(); diff --git a/solution/0300-0399/0381.Insert Delete GetRandom O(1) - Duplicates allowed/README.md b/solution/0300-0399/0381.Insert Delete GetRandom O(1) - Duplicates allowed/README.md index a0b7bdd884141..9fc58c162d70f 100644 --- a/solution/0300-0399/0381.Insert Delete GetRandom O(1) - Duplicates allowed/README.md +++ b/solution/0300-0399/0381.Insert Delete GetRandom O(1) - Duplicates allowed/README.md @@ -81,6 +81,8 @@ collection.getRandom(); // getRandom 应该返回 1 或 2,两者的可能性 +#### Python3 + ```python class RandomizedCollection: def __init__(self): @@ -136,6 +138,8 @@ class RandomizedCollection: # param_3 = obj.getRandom() ``` +#### Java + ```java class RandomizedCollection { private Map> m; diff --git a/solution/0300-0399/0381.Insert Delete GetRandom O(1) - Duplicates allowed/README_EN.md b/solution/0300-0399/0381.Insert Delete GetRandom O(1) - Duplicates allowed/README_EN.md index 10dbc3355dbfe..a6aeebacef5d7 100644 --- a/solution/0300-0399/0381.Insert Delete GetRandom O(1) - Duplicates allowed/README_EN.md +++ b/solution/0300-0399/0381.Insert Delete GetRandom O(1) - Duplicates allowed/README_EN.md @@ -80,6 +80,8 @@ randomizedCollection.getRandom(); // getRandom should return 1 or 2, both equall +#### Python3 + ```python class RandomizedCollection: def __init__(self): @@ -135,6 +137,8 @@ class RandomizedCollection: # param_3 = obj.getRandom() ``` +#### Java + ```java class RandomizedCollection { private Map> m; diff --git a/solution/0300-0399/0382.Linked List Random Node/README.md b/solution/0300-0399/0382.Linked List Random Node/README.md index cf1e18e14de0c..9282542806014 100644 --- a/solution/0300-0399/0382.Linked List Random Node/README.md +++ b/solution/0300-0399/0382.Linked List Random Node/README.md @@ -77,6 +77,8 @@ solution.getRandom(); // 返回 3 +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -104,6 +106,8 @@ class Solution: # param_1 = obj.getRandom() ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -143,6 +147,8 @@ class Solution { */ ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -180,6 +186,8 @@ public: */ ``` +#### Go + ```go /** * Definition for singly-linked list. diff --git a/solution/0300-0399/0382.Linked List Random Node/README_EN.md b/solution/0300-0399/0382.Linked List Random Node/README_EN.md index 87babd689b126..53e24a456f614 100644 --- a/solution/0300-0399/0382.Linked List Random Node/README_EN.md +++ b/solution/0300-0399/0382.Linked List Random Node/README_EN.md @@ -76,6 +76,8 @@ solution.getRandom(); // return 3 +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -103,6 +105,8 @@ class Solution: # param_1 = obj.getRandom() ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -142,6 +146,8 @@ class Solution { */ ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -179,6 +185,8 @@ public: */ ``` +#### Go + ```go /** * Definition for singly-linked list. diff --git a/solution/0300-0399/0383.Ransom Note/README.md b/solution/0300-0399/0383.Ransom Note/README.md index 952cd43281943..6f4a76eedc806 100644 --- a/solution/0300-0399/0383.Ransom Note/README.md +++ b/solution/0300-0399/0383.Ransom Note/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def canConstruct(self, ransomNote: str, magazine: str) -> bool: @@ -83,6 +85,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean canConstruct(String ransomNote, String magazine) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func canConstruct(ransomNote string, magazine string) bool { cnt := [26]int{} @@ -134,6 +142,8 @@ func canConstruct(ransomNote string, magazine string) bool { } ``` +#### TypeScript + ```ts function canConstruct(ransomNote: string, magazine: string): boolean { const cnt: number[] = Array(26).fill(0); @@ -149,6 +159,8 @@ function canConstruct(ransomNote: string, magazine: string): boolean { } ``` +#### C# + ```cs public class Solution { public bool CanConstruct(string ransomNote, string magazine) { @@ -166,6 +178,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0300-0399/0383.Ransom Note/README_EN.md b/solution/0300-0399/0383.Ransom Note/README_EN.md index c8229f394f471..2c7abf39298c4 100644 --- a/solution/0300-0399/0383.Ransom Note/README_EN.md +++ b/solution/0300-0399/0383.Ransom Note/README_EN.md @@ -57,6 +57,8 @@ The time complexity is $O(m + n)$, and the space complexity is $O(C)$. Where $m$ +#### Python3 + ```python class Solution: def canConstruct(self, ransomNote: str, magazine: str) -> bool: @@ -68,6 +70,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean canConstruct(String ransomNote, String magazine) { @@ -85,6 +89,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -103,6 +109,8 @@ public: }; ``` +#### Go + ```go func canConstruct(ransomNote string, magazine string) bool { cnt := [26]int{} @@ -119,6 +127,8 @@ func canConstruct(ransomNote string, magazine string) bool { } ``` +#### TypeScript + ```ts function canConstruct(ransomNote: string, magazine: string): boolean { const cnt: number[] = Array(26).fill(0); @@ -134,6 +144,8 @@ function canConstruct(ransomNote: string, magazine: string): boolean { } ``` +#### C# + ```cs public class Solution { public bool CanConstruct(string ransomNote, string magazine) { @@ -151,6 +163,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0300-0399/0384.Shuffle an Array/README.md b/solution/0300-0399/0384.Shuffle an Array/README.md index 48d4791764595..c5561d3663bb4 100644 --- a/solution/0300-0399/0384.Shuffle an Array/README.md +++ b/solution/0300-0399/0384.Shuffle an Array/README.md @@ -67,6 +67,8 @@ solution.shuffle(); // 随机返回数组 [1, 2, 3] 打乱后的结果。例 +#### Python3 + ```python class Solution: def __init__(self, nums: List[int]): @@ -90,6 +92,8 @@ class Solution: # param_2 = obj.shuffle() ``` +#### Java + ```java class Solution { private int[] nums; @@ -129,6 +133,8 @@ class Solution { */ ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: */ ``` +#### Go + ```go type Solution struct { nums, original []int @@ -194,6 +202,8 @@ func (this *Solution) Shuffle() []int { */ ``` +#### TypeScript + ```ts class Solution { private nums: number[]; @@ -225,6 +235,8 @@ class Solution { */ ``` +#### Rust + ```rust use rand::Rng; struct Solution { @@ -261,6 +273,8 @@ impl Solution { */ ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0300-0399/0384.Shuffle an Array/README_EN.md b/solution/0300-0399/0384.Shuffle an Array/README_EN.md index a3592a57c04d4..52d74efef5ffb 100644 --- a/solution/0300-0399/0384.Shuffle an Array/README_EN.md +++ b/solution/0300-0399/0384.Shuffle an Array/README_EN.md @@ -68,6 +68,8 @@ solution.shuffle(); // Returns the random shuffling of array [1,2,3]. Example +#### Python3 + ```python class Solution: def __init__(self, nums: List[int]): @@ -91,6 +93,8 @@ class Solution: # param_2 = obj.shuffle() ``` +#### Java + ```java class Solution { private int[] nums; @@ -130,6 +134,8 @@ class Solution { */ ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: */ ``` +#### Go + ```go type Solution struct { nums, original []int @@ -195,6 +203,8 @@ func (this *Solution) Shuffle() []int { */ ``` +#### TypeScript + ```ts class Solution { private nums: number[]; @@ -226,6 +236,8 @@ class Solution { */ ``` +#### Rust + ```rust use rand::Rng; struct Solution { @@ -262,6 +274,8 @@ impl Solution { */ ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0300-0399/0385.Mini Parser/README.md b/solution/0300-0399/0385.Mini Parser/README.md index ffa75acd595d5..c2cc77947635d 100644 --- a/solution/0300-0399/0385.Mini Parser/README.md +++ b/solution/0300-0399/0385.Mini Parser/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python # """ # This is the interface that allows for creating nested lists. @@ -134,6 +136,8 @@ class Solution: return ans ``` +#### Java + ```java /** * // This is the interface that allows for creating nested lists. @@ -188,6 +192,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * // This is the interface that allows for creating nested lists. @@ -244,6 +250,8 @@ public: }; ``` +#### Go + ```go /** * // This is the interface that allows for creating nested lists. @@ -295,6 +303,8 @@ func deserialize(s string) *NestedInteger { } ``` +#### TypeScript + ```ts /** * // This is the interface that allows for creating nested lists. @@ -381,6 +391,8 @@ function deserialize(s: string): NestedInteger { +#### Python3 + ```python # """ # This is the interface that allows for creating nested lists. @@ -448,6 +460,8 @@ class Solution: return stk.pop() ``` +#### Java + ```java /** * // This is the interface that allows for creating nested lists. @@ -513,6 +527,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * // This is the interface that allows for creating nested lists. @@ -580,6 +596,8 @@ public: }; ``` +#### Go + ```go /** * // This is the interface that allows for creating nested lists. @@ -645,6 +663,8 @@ func deserialize(s string) *NestedInteger { } ``` +#### TypeScript + ```ts /** * // This is the interface that allows for creating nested lists. diff --git a/solution/0300-0399/0385.Mini Parser/README_EN.md b/solution/0300-0399/0385.Mini Parser/README_EN.md index ef2ee78accfba..c093b62e7d4d4 100644 --- a/solution/0300-0399/0385.Mini Parser/README_EN.md +++ b/solution/0300-0399/0385.Mini Parser/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python # """ # This is the interface that allows for creating nested lists. @@ -132,6 +134,8 @@ class Solution: return ans ``` +#### Java + ```java /** * // This is the interface that allows for creating nested lists. @@ -186,6 +190,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * // This is the interface that allows for creating nested lists. @@ -242,6 +248,8 @@ public: }; ``` +#### Go + ```go /** * // This is the interface that allows for creating nested lists. @@ -293,6 +301,8 @@ func deserialize(s string) *NestedInteger { } ``` +#### TypeScript + ```ts /** * // This is the interface that allows for creating nested lists. @@ -379,6 +389,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python # """ # This is the interface that allows for creating nested lists. @@ -446,6 +458,8 @@ class Solution: return stk.pop() ``` +#### Java + ```java /** * // This is the interface that allows for creating nested lists. @@ -511,6 +525,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * // This is the interface that allows for creating nested lists. @@ -578,6 +594,8 @@ public: }; ``` +#### Go + ```go /** * // This is the interface that allows for creating nested lists. @@ -643,6 +661,8 @@ func deserialize(s string) *NestedInteger { } ``` +#### TypeScript + ```ts /** * // This is the interface that allows for creating nested lists. diff --git a/solution/0300-0399/0386.Lexicographical Numbers/README.md b/solution/0300-0399/0386.Lexicographical Numbers/README.md index e14a7e1ac41af..6b75dc161a0cb 100644 --- a/solution/0300-0399/0386.Lexicographical Numbers/README.md +++ b/solution/0300-0399/0386.Lexicographical Numbers/README.md @@ -55,6 +55,8 @@ tags: +#### Python3 + ```python class Solution: def lexicalOrder(self, n: int) -> List[int]: @@ -71,6 +73,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List lexicalOrder(int n) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func lexicalOrder(n int) []int { var ans []int @@ -130,6 +138,8 @@ func lexicalOrder(n int) []int { } ``` +#### Rust + ```rust impl Solution { fn dfs(mut num: i32, n: i32, res: &mut Vec) { @@ -152,6 +162,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -185,6 +197,8 @@ var lexicalOrder = function (n) { +#### Java + ```java class Solution { public List lexicalOrder(int n) { @@ -206,6 +220,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -226,6 +242,8 @@ public: }; ``` +#### Go + ```go func lexicalOrder(n int) []int { var ans []int diff --git a/solution/0300-0399/0386.Lexicographical Numbers/README_EN.md b/solution/0300-0399/0386.Lexicographical Numbers/README_EN.md index 3489d75994ae6..c9f25bca6a202 100644 --- a/solution/0300-0399/0386.Lexicographical Numbers/README_EN.md +++ b/solution/0300-0399/0386.Lexicographical Numbers/README_EN.md @@ -46,6 +46,8 @@ tags: +#### Python3 + ```python class Solution: def lexicalOrder(self, n: int) -> List[int]: @@ -62,6 +64,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List lexicalOrder(int n) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,6 +107,8 @@ public: }; ``` +#### Go + ```go func lexicalOrder(n int) []int { var ans []int @@ -121,6 +129,8 @@ func lexicalOrder(n int) []int { } ``` +#### Rust + ```rust impl Solution { fn dfs(mut num: i32, n: i32, res: &mut Vec) { @@ -143,6 +153,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -176,6 +188,8 @@ var lexicalOrder = function (n) { +#### Java + ```java class Solution { public List lexicalOrder(int n) { @@ -197,6 +211,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -217,6 +233,8 @@ public: }; ``` +#### Go + ```go func lexicalOrder(n int) []int { var ans []int diff --git a/solution/0300-0399/0387.First Unique Character in a String/README.md b/solution/0300-0399/0387.First Unique Character in a String/README.md index 5744a90f3418b..eb945630e5bfe 100644 --- a/solution/0300-0399/0387.First Unique Character in a String/README.md +++ b/solution/0300-0399/0387.First Unique Character in a String/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def firstUniqChar(self, s: str) -> int: @@ -81,6 +83,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int firstUniqChar(String s) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func firstUniqChar(s string) int { cnt := [26]int{} @@ -133,6 +141,8 @@ func firstUniqChar(s string) int { } ``` +#### TypeScript + ```ts function firstUniqChar(s: string): number { const cnt = new Array(26).fill(0); @@ -148,6 +158,8 @@ function firstUniqChar(s: string): number { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -167,6 +179,8 @@ var firstUniqChar = function (s) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0300-0399/0387.First Unique Character in a String/README_EN.md b/solution/0300-0399/0387.First Unique Character in a String/README_EN.md index 8eee6042f9797..741838efba85c 100644 --- a/solution/0300-0399/0387.First Unique Character in a String/README_EN.md +++ b/solution/0300-0399/0387.First Unique Character in a String/README_EN.md @@ -50,6 +50,8 @@ tags: +#### Python3 + ```python class Solution: def firstUniqChar(self, s: str) -> int: @@ -60,6 +62,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int firstUniqChar(String s) { @@ -78,6 +82,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -97,6 +103,8 @@ public: }; ``` +#### Go + ```go func firstUniqChar(s string) int { cnt := [26]int{} @@ -112,6 +120,8 @@ func firstUniqChar(s string) int { } ``` +#### TypeScript + ```ts function firstUniqChar(s: string): number { const cnt = new Array(26).fill(0); @@ -127,6 +137,8 @@ function firstUniqChar(s: string): number { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -146,6 +158,8 @@ var firstUniqChar = function (s) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0300-0399/0388.Longest Absolute File Path/README.md b/solution/0300-0399/0388.Longest Absolute File Path/README.md index 7dc95513b3591..ee6925be8c553 100644 --- a/solution/0300-0399/0388.Longest Absolute File Path/README.md +++ b/solution/0300-0399/0388.Longest Absolute File Path/README.md @@ -97,6 +97,8 @@ dir +#### Python3 + ```python class Solution: def lengthLongestPath(self, input: str) -> int: @@ -134,6 +136,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int lengthLongestPath(String input) { @@ -179,6 +183,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -224,6 +230,8 @@ public: }; ``` +#### Go + ```go func lengthLongestPath(input string) int { i, n := 0, len(input) diff --git a/solution/0300-0399/0388.Longest Absolute File Path/README_EN.md b/solution/0300-0399/0388.Longest Absolute File Path/README_EN.md index 4ff4ca624f625..66a3f77f31bbf 100644 --- a/solution/0300-0399/0388.Longest Absolute File Path/README_EN.md +++ b/solution/0300-0399/0388.Longest Absolute File Path/README_EN.md @@ -91,6 +91,8 @@ We return 32 since it is the longest absolute path to a file. +#### Python3 + ```python class Solution: def lengthLongestPath(self, input: str) -> int: @@ -128,6 +130,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int lengthLongestPath(String input) { @@ -173,6 +177,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -218,6 +224,8 @@ public: }; ``` +#### Go + ```go func lengthLongestPath(input string) int { i, n := 0, len(input) diff --git a/solution/0300-0399/0389.Find the Difference/README.md b/solution/0300-0399/0389.Find the Difference/README.md index bd298f43537bd..7a15713a50f81 100644 --- a/solution/0300-0399/0389.Find the Difference/README.md +++ b/solution/0300-0399/0389.Find the Difference/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def findTheDifference(self, s: str, t: str) -> str: @@ -76,6 +78,8 @@ class Solution: return c ``` +#### Java + ```java class Solution { public char findTheDifference(String s, String t) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func findTheDifference(s, t string) byte { cnt := [26]int{} @@ -126,6 +134,8 @@ func findTheDifference(s, t string) byte { } ``` +#### TypeScript + ```ts function findTheDifference(s: string, t: string): string { const cnt: number[] = Array(26).fill(0); @@ -143,6 +153,8 @@ function findTheDifference(s: string, t: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn find_the_difference(s: String, t: String) -> char { @@ -168,6 +180,8 @@ impl Solution { } ``` +#### C + ```c char findTheDifference(char* s, char* t) { int n = strlen(s); @@ -199,6 +213,8 @@ char findTheDifference(char* s, char* t) { +#### Python3 + ```python class Solution: def findTheDifference(self, s: str, t: str) -> str: @@ -207,6 +223,8 @@ class Solution: return chr(b - a) ``` +#### Java + ```java class Solution { public char findTheDifference(String s, String t) { @@ -222,6 +240,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -238,6 +258,8 @@ public: }; ``` +#### Go + ```go func findTheDifference(s string, t string) byte { ss := 0 @@ -251,6 +273,8 @@ func findTheDifference(s string, t string) byte { } ``` +#### TypeScript + ```ts function findTheDifference(s: string, t: string): string { return String.fromCharCode( @@ -260,6 +284,8 @@ function findTheDifference(s: string, t: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn find_the_difference(s: String, t: String) -> char { @@ -275,6 +301,8 @@ impl Solution { } ``` +#### C + ```c char findTheDifference(char* s, char* t) { int n = strlen(s); diff --git a/solution/0300-0399/0389.Find the Difference/README_EN.md b/solution/0300-0399/0389.Find the Difference/README_EN.md index 99acc06f11188..a0ea9e6a8e1fa 100644 --- a/solution/0300-0399/0389.Find the Difference/README_EN.md +++ b/solution/0300-0399/0389.Find the Difference/README_EN.md @@ -64,6 +64,8 @@ The time complexity is $O(n)$, and the space complexity is $O(|\Sigma|)$, where +#### Python3 + ```python class Solution: def findTheDifference(self, s: str, t: str) -> str: @@ -74,6 +76,8 @@ class Solution: return c ``` +#### Java + ```java class Solution { public char findTheDifference(String s, String t) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func findTheDifference(s, t string) byte { cnt := [26]int{} @@ -124,6 +132,8 @@ func findTheDifference(s, t string) byte { } ``` +#### TypeScript + ```ts function findTheDifference(s: string, t: string): string { const cnt: number[] = Array(26).fill(0); @@ -141,6 +151,8 @@ function findTheDifference(s: string, t: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn find_the_difference(s: String, t: String) -> char { @@ -166,6 +178,8 @@ impl Solution { } ``` +#### C + ```c char findTheDifference(char* s, char* t) { int n = strlen(s); @@ -197,6 +211,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string. The space +#### Python3 + ```python class Solution: def findTheDifference(self, s: str, t: str) -> str: @@ -205,6 +221,8 @@ class Solution: return chr(b - a) ``` +#### Java + ```java class Solution { public char findTheDifference(String s, String t) { @@ -220,6 +238,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -236,6 +256,8 @@ public: }; ``` +#### Go + ```go func findTheDifference(s string, t string) byte { ss := 0 @@ -249,6 +271,8 @@ func findTheDifference(s string, t string) byte { } ``` +#### TypeScript + ```ts function findTheDifference(s: string, t: string): string { return String.fromCharCode( @@ -258,6 +282,8 @@ function findTheDifference(s: string, t: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn find_the_difference(s: String, t: String) -> char { @@ -273,6 +299,8 @@ impl Solution { } ``` +#### C + ```c char findTheDifference(char* s, char* t) { int n = strlen(s); diff --git a/solution/0300-0399/0390.Elimination Game/README.md b/solution/0300-0399/0390.Elimination Game/README.md index 2c01167e2551a..812e7a84652e9 100644 --- a/solution/0300-0399/0390.Elimination Game/README.md +++ b/solution/0300-0399/0390.Elimination Game/README.md @@ -70,6 +70,8 @@ arr = [6] +#### Python3 + ```python class Solution: def lastRemaining(self, n: int) -> int: @@ -90,6 +92,8 @@ class Solution: return a1 ``` +#### Java + ```java class Solution { public int lastRemaining(int n) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func lastRemaining(n int) int { a1, an, step := 1, n, 1 diff --git a/solution/0300-0399/0390.Elimination Game/README_EN.md b/solution/0300-0399/0390.Elimination Game/README_EN.md index bb7d8eeac6123..330da5fb1fdd9 100644 --- a/solution/0300-0399/0390.Elimination Game/README_EN.md +++ b/solution/0300-0399/0390.Elimination Game/README_EN.md @@ -64,6 +64,8 @@ arr = [6] +#### Python3 + ```python class Solution: def lastRemaining(self, n: int) -> int: @@ -84,6 +86,8 @@ class Solution: return a1 ``` +#### Java + ```java class Solution { public int lastRemaining(int n) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func lastRemaining(n int) int { a1, an, step := 1, n, 1 diff --git a/solution/0300-0399/0391.Perfect Rectangle/README.md b/solution/0300-0399/0391.Perfect Rectangle/README.md index e08b1343d69c8..c69b02149e247 100644 --- a/solution/0300-0399/0391.Perfect Rectangle/README.md +++ b/solution/0300-0399/0391.Perfect Rectangle/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def isRectangleCover(self, rectangles: List[List[int]]) -> bool: @@ -99,6 +101,8 @@ class Solution: return all(c == 2 or c == 4 for c in cnt.values()) ``` +#### Java + ```java class Solution { public boolean isRectangleCover(int[][] rectangles) { @@ -166,6 +170,8 @@ class Solution { } ``` +#### C++ + ```cpp #include using namespace std; @@ -210,6 +216,8 @@ public: }; ``` +#### Go + ```go type pair struct { first int diff --git a/solution/0300-0399/0391.Perfect Rectangle/README_EN.md b/solution/0300-0399/0391.Perfect Rectangle/README_EN.md index a3bfc82d8d927..f10a51d190283 100644 --- a/solution/0300-0399/0391.Perfect Rectangle/README_EN.md +++ b/solution/0300-0399/0391.Perfect Rectangle/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def isRectangleCover(self, rectangles: List[List[int]]) -> bool: @@ -100,6 +102,8 @@ class Solution: return all(c == 2 or c == 4 for c in cnt.values()) ``` +#### Java + ```java class Solution { public boolean isRectangleCover(int[][] rectangles) { @@ -167,6 +171,8 @@ class Solution { } ``` +#### C++ + ```cpp #include using namespace std; @@ -211,6 +217,8 @@ public: }; ``` +#### Go + ```go type pair struct { first int diff --git a/solution/0300-0399/0392.Is Subsequence/README.md b/solution/0300-0399/0392.Is Subsequence/README.md index 68e0dd0b8ebc3..9d2e276bdf42b 100644 --- a/solution/0300-0399/0392.Is Subsequence/README.md +++ b/solution/0300-0399/0392.Is Subsequence/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def isSubsequence(self, s: str, t: str) -> bool: @@ -81,6 +83,8 @@ class Solution: return i == len(s) ``` +#### Java + ```java class Solution { public boolean isSubsequence(String s, String t) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func isSubsequence(s string, t string) bool { i, j, m, n := 0, 0, len(s), len(t) @@ -126,6 +134,8 @@ func isSubsequence(s string, t string) bool { } ``` +#### TypeScript + ```ts function isSubsequence(s: string, t: string): boolean { const m = s.length; @@ -140,6 +150,8 @@ function isSubsequence(s: string, t: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn is_subsequence(s: String, t: String) -> bool { @@ -160,6 +172,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public bool IsSubsequence(string s, string t) { @@ -175,6 +189,8 @@ public class Solution { } ``` +#### C + ```c bool isSubsequence(char* s, char* t) { int m = strlen(s); diff --git a/solution/0300-0399/0392.Is Subsequence/README_EN.md b/solution/0300-0399/0392.Is Subsequence/README_EN.md index 7e2b2c2029228..e712cbe07188e 100644 --- a/solution/0300-0399/0392.Is Subsequence/README_EN.md +++ b/solution/0300-0399/0392.Is Subsequence/README_EN.md @@ -56,6 +56,8 @@ The time complexity is $O(m + n)$, where $m$ and $n$ are the lengths of the stri +#### Python3 + ```python class Solution: def isSubsequence(self, s: str, t: str) -> bool: @@ -67,6 +69,8 @@ class Solution: return i == len(s) ``` +#### Java + ```java class Solution { public boolean isSubsequence(String s, String t) { @@ -83,6 +87,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -99,6 +105,8 @@ public: }; ``` +#### Go + ```go func isSubsequence(s string, t string) bool { i, j, m, n := 0, 0, len(s), len(t) @@ -112,6 +120,8 @@ func isSubsequence(s string, t string) bool { } ``` +#### TypeScript + ```ts function isSubsequence(s: string, t: string): boolean { const m = s.length; @@ -126,6 +136,8 @@ function isSubsequence(s: string, t: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn is_subsequence(s: String, t: String) -> bool { @@ -146,6 +158,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public bool IsSubsequence(string s, string t) { @@ -161,6 +175,8 @@ public class Solution { } ``` +#### C + ```c bool isSubsequence(char* s, char* t) { int m = strlen(s); diff --git a/solution/0300-0399/0393.UTF-8 Validation/README.md b/solution/0300-0399/0393.UTF-8 Validation/README.md index efa0a415da18b..a5b2847436c4c 100644 --- a/solution/0300-0399/0393.UTF-8 Validation/README.md +++ b/solution/0300-0399/0393.UTF-8 Validation/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def validUtf8(self, data: List[int]) -> bool: @@ -105,6 +107,8 @@ class Solution: return n == 0 ``` +#### Java + ```java class Solution { public boolean validUtf8(int[] data) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func validUtf8(data []int) bool { n := 0 diff --git a/solution/0300-0399/0393.UTF-8 Validation/README_EN.md b/solution/0300-0399/0393.UTF-8 Validation/README_EN.md index b7213c3f37e04..aaa12b6136e93 100644 --- a/solution/0300-0399/0393.UTF-8 Validation/README_EN.md +++ b/solution/0300-0399/0393.UTF-8 Validation/README_EN.md @@ -81,6 +81,8 @@ But the second continuation byte does not start with 10, so it is invalid. +#### Python3 + ```python class Solution: def validUtf8(self, data: List[int]) -> bool: @@ -103,6 +105,8 @@ class Solution: return n == 0 ``` +#### Java + ```java class Solution { public boolean validUtf8(int[] data) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func validUtf8(data []int) bool { n := 0 diff --git a/solution/0300-0399/0394.Decode String/README.md b/solution/0300-0399/0394.Decode String/README.md index b239ed2353fc5..0cbd5f13b03b2 100644 --- a/solution/0300-0399/0394.Decode String/README.md +++ b/solution/0300-0399/0394.Decode String/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def decodeString(self, s: str) -> str: @@ -96,6 +98,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public String decodeString(String s) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### TypeScript + ```ts function decodeString(s: string): string { let ans = ''; diff --git a/solution/0300-0399/0394.Decode String/README_EN.md b/solution/0300-0399/0394.Decode String/README_EN.md index 88bdcdf8386a4..5a64b91b643b6 100644 --- a/solution/0300-0399/0394.Decode String/README_EN.md +++ b/solution/0300-0399/0394.Decode String/README_EN.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def decodeString(self, s: str) -> str: @@ -87,6 +89,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public String decodeString(String s) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### TypeScript + ```ts function decodeString(s: string): string { let ans = ''; diff --git a/solution/0300-0399/0395.Longest Substring with At Least K Repeating Characters/README.md b/solution/0300-0399/0395.Longest Substring with At Least K Repeating Characters/README.md index f1d066d6e9dd6..89d6ba501b1e9 100644 --- a/solution/0300-0399/0395.Longest Substring with At Least K Repeating Characters/README.md +++ b/solution/0300-0399/0395.Longest Substring with At Least K Repeating Characters/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def longestSubstring(self, s: str, k: int) -> int: @@ -90,6 +92,8 @@ class Solution: return dfs(0, len(s) - 1) ``` +#### Java + ```java class Solution { private String s; @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func longestSubstring(s string, k int) int { var dfs func(l, r int) int diff --git a/solution/0300-0399/0395.Longest Substring with At Least K Repeating Characters/README_EN.md b/solution/0300-0399/0395.Longest Substring with At Least K Repeating Characters/README_EN.md index e1314061d346c..290380348a7ab 100644 --- a/solution/0300-0399/0395.Longest Substring with At Least K Repeating Characters/README_EN.md +++ b/solution/0300-0399/0395.Longest Substring with At Least K Repeating Characters/README_EN.md @@ -59,6 +59,8 @@ tags: +#### Python3 + ```python class Solution: def longestSubstring(self, s: str, k: int) -> int: @@ -85,6 +87,8 @@ class Solution: return dfs(0, len(s) - 1) ``` +#### Java + ```java class Solution { private String s; @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go func longestSubstring(s string, k int) int { var dfs func(l, r int) int diff --git a/solution/0300-0399/0396.Rotate Function/README.md b/solution/0300-0399/0396.Rotate Function/README.md index d62e9f98d918d..50e04fd76ed10 100644 --- a/solution/0300-0399/0396.Rotate Function/README.md +++ b/solution/0300-0399/0396.Rotate Function/README.md @@ -72,6 +72,8 @@ F(3) = (0 * 3) + (1 * 2) + (2 * 6) + (3 * 4) = 0 + 2 + 12 + 12 = 26 +#### Python3 + ```python class Solution: def maxRotateFunction(self, nums: List[int]) -> int: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxRotateFunction(int[] nums) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func maxRotateFunction(nums []int) int { f, s, n := 0, 0, len(nums) @@ -141,6 +149,8 @@ func maxRotateFunction(nums []int) int { } ``` +#### TypeScript + ```ts function maxRotateFunction(nums: number[]): number { const n = nums.length; @@ -155,6 +165,8 @@ function maxRotateFunction(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_rotate_function(nums: Vec) -> i32 { diff --git a/solution/0300-0399/0396.Rotate Function/README_EN.md b/solution/0300-0399/0396.Rotate Function/README_EN.md index d0e6a6fdcd159..974fb594ffee4 100644 --- a/solution/0300-0399/0396.Rotate Function/README_EN.md +++ b/solution/0300-0399/0396.Rotate Function/README_EN.md @@ -70,6 +70,8 @@ So the maximum value of F(0), F(1), F(2), F(3) is F(3) = 26. +#### Python3 + ```python class Solution: def maxRotateFunction(self, nums: List[int]) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxRotateFunction(int[] nums) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func maxRotateFunction(nums []int) int { f, s, n := 0, 0, len(nums) @@ -139,6 +147,8 @@ func maxRotateFunction(nums []int) int { } ``` +#### TypeScript + ```ts function maxRotateFunction(nums: number[]): number { const n = nums.length; @@ -153,6 +163,8 @@ function maxRotateFunction(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_rotate_function(nums: Vec) -> i32 { diff --git a/solution/0300-0399/0397.Integer Replacement/README.md b/solution/0300-0399/0397.Integer Replacement/README.md index bb6dc137d4746..0ad50888bff81 100644 --- a/solution/0300-0399/0397.Integer Replacement/README.md +++ b/solution/0300-0399/0397.Integer Replacement/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def integerReplacement(self, n: int) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int integerReplacement(int n) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func integerReplacement(n int) int { ans := 0 diff --git a/solution/0300-0399/0397.Integer Replacement/README_EN.md b/solution/0300-0399/0397.Integer Replacement/README_EN.md index 32a404d289b4f..cd7ed9d694418 100644 --- a/solution/0300-0399/0397.Integer Replacement/README_EN.md +++ b/solution/0300-0399/0397.Integer Replacement/README_EN.md @@ -70,6 +70,8 @@ or 7 -> 6 -> 3 -> 2 -> 1 +#### Python3 + ```python class Solution: def integerReplacement(self, n: int) -> int: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int integerReplacement(int n) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func integerReplacement(n int) int { ans := 0 diff --git a/solution/0300-0399/0398.Random Pick Index/README.md b/solution/0300-0399/0398.Random Pick Index/README.md index 652e5e88547e9..91b43bf940334 100644 --- a/solution/0300-0399/0398.Random Pick Index/README.md +++ b/solution/0300-0399/0398.Random Pick Index/README.md @@ -75,6 +75,8 @@ solution.pick(3); // 随机返回索引 2, 3 或者 4 之一。每个索引的 +#### Python3 + ```python class Solution: def __init__(self, nums: List[int]): @@ -96,6 +98,8 @@ class Solution: # param_1 = obj.pick(target) ``` +#### Java + ```java class Solution { private int[] nums; @@ -127,6 +131,8 @@ class Solution { */ ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: */ ``` +#### Go + ```go type Solution struct { nums []int diff --git a/solution/0300-0399/0398.Random Pick Index/README_EN.md b/solution/0300-0399/0398.Random Pick Index/README_EN.md index 0dac6e70cb28a..9232ed0fa1e8d 100644 --- a/solution/0300-0399/0398.Random Pick Index/README_EN.md +++ b/solution/0300-0399/0398.Random Pick Index/README_EN.md @@ -65,6 +65,8 @@ solution.pick(3); // It should return either index 2, 3, or 4 randomly. Each ind +#### Python3 + ```python class Solution: def __init__(self, nums: List[int]): @@ -86,6 +88,8 @@ class Solution: # param_1 = obj.pick(target) ``` +#### Java + ```java class Solution { private int[] nums; @@ -117,6 +121,8 @@ class Solution { */ ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: */ ``` +#### Go + ```go type Solution struct { nums []int diff --git a/solution/0300-0399/0399.Evaluate Division/README.md b/solution/0300-0399/0399.Evaluate Division/README.md index 95622ed84ae3c..a7946e9f7c761 100644 --- a/solution/0300-0399/0399.Evaluate Division/README.md +++ b/solution/0300-0399/0399.Evaluate Division/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def calcEquation( @@ -113,6 +115,8 @@ class Solution: ] ``` +#### Java + ```java class Solution { private Map p; @@ -161,6 +165,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -203,6 +209,8 @@ public: }; ``` +#### Go + ```go func calcEquation(equations [][]string, values []float64, queries [][]string) []float64 { p := make(map[string]string) @@ -245,6 +253,8 @@ func calcEquation(equations [][]string, values []float64, queries [][]string) [] } ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/0300-0399/0399.Evaluate Division/README_EN.md b/solution/0300-0399/0399.Evaluate Division/README_EN.md index 8b557bab84e9c..6d4bc666b9d59 100644 --- a/solution/0300-0399/0399.Evaluate Division/README_EN.md +++ b/solution/0300-0399/0399.Evaluate Division/README_EN.md @@ -82,6 +82,8 @@ note: x is undefined => -1.0 +#### Python3 + ```python class Solution: def calcEquation( @@ -111,6 +113,8 @@ class Solution: ] ``` +#### Java + ```java class Solution { private Map p; @@ -159,6 +163,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -201,6 +207,8 @@ public: }; ``` +#### Go + ```go func calcEquation(equations [][]string, values []float64, queries [][]string) []float64 { p := make(map[string]string) @@ -243,6 +251,8 @@ func calcEquation(equations [][]string, values []float64, queries [][]string) [] } ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/0400-0499/0400.Nth Digit/README.md b/solution/0400-0499/0400.Nth Digit/README.md index 6ed2844ed774c..52c30ea069a92 100644 --- a/solution/0400-0499/0400.Nth Digit/README.md +++ b/solution/0400-0499/0400.Nth Digit/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def findNthDigit(self, n: int) -> int: @@ -77,6 +79,8 @@ class Solution: return int(str(num)[idx]) ``` +#### Java + ```java class Solution { public int findNthDigit(int n) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func findNthDigit(n int) int { k, cnt := 1, 9 @@ -124,6 +132,8 @@ func findNthDigit(n int) int { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -143,6 +153,8 @@ var findNthDigit = function (n) { }; ``` +#### C# + ```cs public class Solution { public int FindNthDigit(int n) { diff --git a/solution/0400-0499/0400.Nth Digit/README_EN.md b/solution/0400-0499/0400.Nth Digit/README_EN.md index 13882fb652365..87f7da467980e 100644 --- a/solution/0400-0499/0400.Nth Digit/README_EN.md +++ b/solution/0400-0499/0400.Nth Digit/README_EN.md @@ -52,6 +52,8 @@ tags: +#### Python3 + ```python class Solution: def findNthDigit(self, n: int) -> int: @@ -65,6 +67,8 @@ class Solution: return int(str(num)[idx]) ``` +#### Java + ```java class Solution { public int findNthDigit(int n) { @@ -81,6 +85,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -98,6 +104,8 @@ public: }; ``` +#### Go + ```go func findNthDigit(n int) int { k, cnt := 1, 9 @@ -112,6 +120,8 @@ func findNthDigit(n int) int { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -131,6 +141,8 @@ var findNthDigit = function (n) { }; ``` +#### C# + ```cs public class Solution { public int FindNthDigit(int n) { diff --git a/solution/0400-0499/0401.Binary Watch/README.md b/solution/0400-0499/0401.Binary Watch/README.md index b1c9acbe6dc80..5bc0557a8626a 100644 --- a/solution/0400-0499/0401.Binary Watch/README.md +++ b/solution/0400-0499/0401.Binary Watch/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def readBinaryWatch(self, turnedOn: int) -> List[str]: @@ -88,6 +90,8 @@ class Solution: ] ``` +#### Java + ```java class Solution { public List readBinaryWatch(int turnedOn) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func readBinaryWatch(turnedOn int) []string { var ans []string @@ -135,6 +143,8 @@ func readBinaryWatch(turnedOn int) []string { } ``` +#### TypeScript + ```ts function readBinaryWatch(turnedOn: number): string[] { if (turnedOn === 0) { @@ -169,6 +179,8 @@ function readBinaryWatch(turnedOn: number): string[] { } ``` +#### Rust + ```rust impl Solution { fn create_time(bit_arr: &[bool; 10]) -> (i32, i32) { @@ -230,6 +242,8 @@ impl Solution { +#### Python3 + ```python class Solution: def readBinaryWatch(self, turnedOn: int) -> List[str]: @@ -241,6 +255,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List readBinaryWatch(int turnedOn) { @@ -256,6 +272,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -272,6 +290,8 @@ public: }; ``` +#### Go + ```go func readBinaryWatch(turnedOn int) []string { var ans []string diff --git a/solution/0400-0499/0401.Binary Watch/README_EN.md b/solution/0400-0499/0401.Binary Watch/README_EN.md index 083c3374c045a..8053916897dc5 100644 --- a/solution/0400-0499/0401.Binary Watch/README_EN.md +++ b/solution/0400-0499/0401.Binary Watch/README_EN.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def readBinaryWatch(self, turnedOn: int) -> List[str]: @@ -75,6 +77,8 @@ class Solution: ] ``` +#### Java + ```java class Solution { public List readBinaryWatch(int turnedOn) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func readBinaryWatch(turnedOn int) []string { var ans []string @@ -122,6 +130,8 @@ func readBinaryWatch(turnedOn int) []string { } ``` +#### TypeScript + ```ts function readBinaryWatch(turnedOn: number): string[] { if (turnedOn === 0) { @@ -156,6 +166,8 @@ function readBinaryWatch(turnedOn: number): string[] { } ``` +#### Rust + ```rust impl Solution { fn create_time(bit_arr: &[bool; 10]) -> (i32, i32) { @@ -215,6 +227,8 @@ impl Solution { +#### Python3 + ```python class Solution: def readBinaryWatch(self, turnedOn: int) -> List[str]: @@ -226,6 +240,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List readBinaryWatch(int turnedOn) { @@ -241,6 +257,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -257,6 +275,8 @@ public: }; ``` +#### Go + ```go func readBinaryWatch(turnedOn int) []string { var ans []string diff --git a/solution/0400-0499/0402.Remove K Digits/README.md b/solution/0400-0499/0402.Remove K Digits/README.md index 1c3cf4abad99f..2c15085dcce2a 100644 --- a/solution/0400-0499/0402.Remove K Digits/README.md +++ b/solution/0400-0499/0402.Remove K Digits/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def removeKdigits(self, num: str, k: int) -> str: @@ -90,6 +92,8 @@ class Solution: return ''.join(stk[:remain]).lstrip('0') or '0' ``` +#### Java + ```java class Solution { public String removeKdigits(String num, int k) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func removeKdigits(num string, k int) string { stk, remain := make([]byte, 0), len(num)-k @@ -158,6 +166,8 @@ func removeKdigits(num string, k int) string { } ``` +#### TypeScript + ```ts function removeKdigits(num: string, k: number): string { const stk: string[] = []; diff --git a/solution/0400-0499/0402.Remove K Digits/README_EN.md b/solution/0400-0499/0402.Remove K Digits/README_EN.md index ceda4de0d5da4..34e515e7550d8 100644 --- a/solution/0400-0499/0402.Remove K Digits/README_EN.md +++ b/solution/0400-0499/0402.Remove K Digits/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def removeKdigits(self, num: str, k: int) -> str: @@ -78,6 +80,8 @@ class Solution: return ''.join(stk[:remain]).lstrip('0') or '0' ``` +#### Java + ```java class Solution { public String removeKdigits(String num, int k) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func removeKdigits(num string, k int) string { stk, remain := make([]byte, 0), len(num)-k @@ -146,6 +154,8 @@ func removeKdigits(num string, k int) string { } ``` +#### TypeScript + ```ts function removeKdigits(num: string, k: number): string { const stk: string[] = []; diff --git a/solution/0400-0499/0403.Frog Jump/README.md b/solution/0400-0499/0403.Frog Jump/README.md index d96aaf1f04973..f9bf769208d60 100644 --- a/solution/0400-0499/0403.Frog Jump/README.md +++ b/solution/0400-0499/0403.Frog Jump/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def canCross(self, stones: List[int]) -> bool: @@ -91,6 +93,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private Boolean[][] f; @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func canCross(stones []int) bool { n := len(stones) @@ -195,6 +203,8 @@ func canCross(stones []int) bool { } ``` +#### TypeScript + ```ts function canCross(stones: number[]): boolean { const n = stones.length; @@ -225,6 +235,8 @@ function canCross(stones: number[]): boolean { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -294,6 +306,8 @@ impl Solution { +#### Python3 + ```python class Solution: def canCross(self, stones: List[int]) -> bool: @@ -311,6 +325,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean canCross(int[] stones) { @@ -334,6 +350,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -359,6 +377,8 @@ public: }; ``` +#### Go + ```go func canCross(stones []int) bool { n := len(stones) @@ -383,6 +403,8 @@ func canCross(stones []int) bool { } ``` +#### TypeScript + ```ts function canCross(stones: number[]): boolean { const n = stones.length; @@ -404,6 +426,8 @@ function canCross(stones: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/0400-0499/0403.Frog Jump/README_EN.md b/solution/0400-0499/0403.Frog Jump/README_EN.md index ed4695cba7f2b..25e9151741b0a 100644 --- a/solution/0400-0499/0403.Frog Jump/README_EN.md +++ b/solution/0400-0499/0403.Frog Jump/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$. Where $n$ +#### Python3 + ```python class Solution: def canCross(self, stones: List[int]) -> bool: @@ -91,6 +93,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private Boolean[][] f; @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func canCross(stones []int) bool { n := len(stones) @@ -195,6 +203,8 @@ func canCross(stones []int) bool { } ``` +#### TypeScript + ```ts function canCross(stones: number[]): boolean { const n = stones.length; @@ -225,6 +235,8 @@ function canCross(stones: number[]): boolean { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -294,6 +306,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$. Where $n$ +#### Python3 + ```python class Solution: def canCross(self, stones: List[int]) -> bool: @@ -311,6 +325,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean canCross(int[] stones) { @@ -334,6 +350,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -359,6 +377,8 @@ public: }; ``` +#### Go + ```go func canCross(stones []int) bool { n := len(stones) @@ -383,6 +403,8 @@ func canCross(stones []int) bool { } ``` +#### TypeScript + ```ts function canCross(stones: number[]): boolean { const n = stones.length; @@ -404,6 +426,8 @@ function canCross(stones: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/0400-0499/0404.Sum of Left Leaves/README.md b/solution/0400-0499/0404.Sum of Left Leaves/README.md index a95e4ab319be5..c5d8fb0fc7558 100644 --- a/solution/0400-0499/0404.Sum of Left Leaves/README.md +++ b/solution/0400-0499/0404.Sum of Left Leaves/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -179,6 +187,8 @@ func sumOfLeftLeaves(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -210,6 +220,8 @@ function sumOfLeftLeaves(root: TreeNode | null): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -254,6 +266,8 @@ impl Solution { } ``` +#### C + ```c /** * Definition for a binary tree node. @@ -302,6 +316,8 @@ int sumOfLeftLeaves(struct TreeNode* root) { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -327,6 +343,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -369,6 +387,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -407,6 +427,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -439,6 +461,8 @@ func sumOfLeftLeaves(root *TreeNode) (ans int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0400-0499/0404.Sum of Left Leaves/README_EN.md b/solution/0400-0499/0404.Sum of Left Leaves/README_EN.md index 61b51733d25c3..133d94716f9e6 100644 --- a/solution/0400-0499/0404.Sum of Left Leaves/README_EN.md +++ b/solution/0400-0499/0404.Sum of Left Leaves/README_EN.md @@ -65,6 +65,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -175,6 +183,8 @@ func sumOfLeftLeaves(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -206,6 +216,8 @@ function sumOfLeftLeaves(root: TreeNode | null): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -250,6 +262,8 @@ impl Solution { } ``` +#### C + ```c /** * Definition for a binary tree node. @@ -298,6 +312,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -323,6 +339,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -365,6 +383,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -403,6 +423,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -435,6 +457,8 @@ func sumOfLeftLeaves(root *TreeNode) (ans int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0400-0499/0405.Convert a Number to Hexadecimal/README.md b/solution/0400-0499/0405.Convert a Number to Hexadecimal/README.md index 92cf83ce4dfcd..c7f9afcc8cf45 100644 --- a/solution/0400-0499/0405.Convert a Number to Hexadecimal/README.md +++ b/solution/0400-0499/0405.Convert a Number to Hexadecimal/README.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python class Solution: def toHex(self, num: int) -> str: @@ -72,6 +74,8 @@ class Solution: return ''.join(s) ``` +#### Java + ```java class Solution { public String toHex(int num) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func toHex(num int) string { if num == 0 { @@ -143,6 +151,8 @@ func toHex(num int) string { +#### Java + ```java class Solution { public String toHex(int num) { diff --git a/solution/0400-0499/0405.Convert a Number to Hexadecimal/README_EN.md b/solution/0400-0499/0405.Convert a Number to Hexadecimal/README_EN.md index 1fec77506f618..9a0da594eaf8e 100644 --- a/solution/0400-0499/0405.Convert a Number to Hexadecimal/README_EN.md +++ b/solution/0400-0499/0405.Convert a Number to Hexadecimal/README_EN.md @@ -48,6 +48,8 @@ tags: +#### Python3 + ```python class Solution: def toHex(self, num: int) -> str: @@ -62,6 +64,8 @@ class Solution: return ''.join(s) ``` +#### Java + ```java class Solution { public String toHex(int num) { @@ -83,6 +87,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,6 +107,8 @@ public: }; ``` +#### Go + ```go func toHex(num int) string { if num == 0 { @@ -133,6 +141,8 @@ func toHex(num int) string { +#### Java + ```java class Solution { public String toHex(int num) { diff --git a/solution/0400-0499/0406.Queue Reconstruction by Height/README.md b/solution/0400-0499/0406.Queue Reconstruction by Height/README.md index 83dc0fc0a5c7e..e9f0e7702e758 100644 --- a/solution/0400-0499/0406.Queue Reconstruction by Height/README.md +++ b/solution/0400-0499/0406.Queue Reconstruction by Height/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] reconstructQueue(int[][] people) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func reconstructQueue(people [][]int) [][]int { sort.Slice(people, func(i, j int) bool { diff --git a/solution/0400-0499/0406.Queue Reconstruction by Height/README_EN.md b/solution/0400-0499/0406.Queue Reconstruction by Height/README_EN.md index c31b266d66148..c47caef80a02a 100644 --- a/solution/0400-0499/0406.Queue Reconstruction by Height/README_EN.md +++ b/solution/0400-0499/0406.Queue Reconstruction by Height/README_EN.md @@ -66,6 +66,8 @@ Hence [[5,0],[7,0],[5,2],[6,1],[4,4],[7,1]] is the reconstructed queue. +#### Python3 + ```python class Solution: def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]: @@ -76,6 +78,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] reconstructQueue(int[][] people) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -104,6 +110,8 @@ public: }; ``` +#### Go + ```go func reconstructQueue(people [][]int) [][]int { sort.Slice(people, func(i, j int) bool { diff --git a/solution/0400-0499/0407.Trapping Rain Water II/README.md b/solution/0400-0499/0407.Trapping Rain Water II/README.md index 1ba56b763806a..33514ac2eecc6 100644 --- a/solution/0400-0499/0407.Trapping Rain Water II/README.md +++ b/solution/0400-0499/0407.Trapping Rain Water II/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def trapRainWater(self, heightMap: List[List[int]]) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int trapRainWater(int[][] heightMap) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func trapRainWater(heightMap [][]int) (ans int) { m, n := len(heightMap), len(heightMap[0]) diff --git a/solution/0400-0499/0407.Trapping Rain Water II/README_EN.md b/solution/0400-0499/0407.Trapping Rain Water II/README_EN.md index 63ab177b50f83..c6635c7681d44 100644 --- a/solution/0400-0499/0407.Trapping Rain Water II/README_EN.md +++ b/solution/0400-0499/0407.Trapping Rain Water II/README_EN.md @@ -59,6 +59,8 @@ The total volume of water trapped is 4. +#### Python3 + ```python class Solution: def trapRainWater(self, heightMap: List[List[int]]) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int trapRainWater(int[][] heightMap) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func trapRainWater(heightMap [][]int) (ans int) { m, n := len(heightMap), len(heightMap[0]) diff --git a/solution/0400-0499/0408.Valid Word Abbreviation/README.md b/solution/0400-0499/0408.Valid Word Abbreviation/README.md index 4246d77ad6b85..923aab876c57a 100644 --- a/solution/0400-0499/0408.Valid Word Abbreviation/README.md +++ b/solution/0400-0499/0408.Valid Word Abbreviation/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python class Solution: def validWordAbbreviation(self, word: str, abbr: str) -> bool: @@ -115,6 +117,8 @@ class Solution: return i + x == m and j == n ``` +#### Java + ```java class Solution { public boolean validWordAbbreviation(String word, String abbr) { @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func validWordAbbreviation(word string, abbr string) bool { m, n := len(word), len(abbr) @@ -190,6 +198,8 @@ func validWordAbbreviation(word string, abbr string) bool { } ``` +#### TypeScript + ```ts function validWordAbbreviation(word: string, abbr: string): boolean { const [m, n] = [word.length, abbr.length]; diff --git a/solution/0400-0499/0408.Valid Word Abbreviation/README_EN.md b/solution/0400-0499/0408.Valid Word Abbreviation/README_EN.md index e77617e62c471..7877960c1a095 100644 --- a/solution/0400-0499/0408.Valid Word Abbreviation/README_EN.md +++ b/solution/0400-0499/0408.Valid Word Abbreviation/README_EN.md @@ -95,6 +95,8 @@ The time complexity is $O(m + n)$, where $m$ and $n$ are the lengths of the stri +#### Python3 + ```python class Solution: def validWordAbbreviation(self, word: str, abbr: str) -> bool: @@ -115,6 +117,8 @@ class Solution: return i + x == m and j == n ``` +#### Java + ```java class Solution { public boolean validWordAbbreviation(String word, String abbr) { @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func validWordAbbreviation(word string, abbr string) bool { m, n := len(word), len(abbr) @@ -190,6 +198,8 @@ func validWordAbbreviation(word string, abbr string) bool { } ``` +#### TypeScript + ```ts function validWordAbbreviation(word: string, abbr: string): boolean { const [m, n] = [word.length, abbr.length]; diff --git a/solution/0400-0499/0409.Longest Palindrome/README.md b/solution/0400-0499/0409.Longest Palindrome/README.md index ba99c9095615e..413071ce40fe0 100644 --- a/solution/0400-0499/0409.Longest Palindrome/README.md +++ b/solution/0400-0499/0409.Longest Palindrome/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def longestPalindrome(self, s: str) -> int: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestPalindrome(String s) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func longestPalindrome(s string) (ans int) { cnt := [128]int{} @@ -141,6 +149,8 @@ func longestPalindrome(s string) (ans int) { } ``` +#### TypeScript + ```ts function longestPalindrome(s: string): number { let n = s.length; @@ -157,6 +167,8 @@ function longestPalindrome(s: string): number { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -190,6 +202,8 @@ impl Solution { +#### TypeScript + ```ts function longestPalindrome(s: string): number { const map = new Map(); diff --git a/solution/0400-0499/0409.Longest Palindrome/README_EN.md b/solution/0400-0499/0409.Longest Palindrome/README_EN.md index cf2955fe91314..4a3d28f612ccb 100644 --- a/solution/0400-0499/0409.Longest Palindrome/README_EN.md +++ b/solution/0400-0499/0409.Longest Palindrome/README_EN.md @@ -67,6 +67,8 @@ The time complexity is $O(n)$, and the space complexity is $O(C)$. Here, $n$ is +#### Python3 + ```python class Solution: def longestPalindrome(self, s: str) -> int: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestPalindrome(String s) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func longestPalindrome(s string) (ans int) { cnt := [128]int{} @@ -133,6 +141,8 @@ func longestPalindrome(s string) (ans int) { } ``` +#### TypeScript + ```ts function longestPalindrome(s: string): number { let n = s.length; @@ -149,6 +159,8 @@ function longestPalindrome(s: string): number { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -182,6 +194,8 @@ impl Solution { +#### TypeScript + ```ts function longestPalindrome(s: string): number { const map = new Map(); diff --git a/solution/0400-0499/0410.Split Array Largest Sum/README.md b/solution/0400-0499/0410.Split Array Largest Sum/README.md index c23a0446eb0a8..90692f74edf19 100644 --- a/solution/0400-0499/0410.Split Array Largest Sum/README.md +++ b/solution/0400-0499/0410.Split Array Largest Sum/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def splitArray(self, nums: List[int], k: int) -> int: @@ -94,6 +96,8 @@ class Solution: return left + bisect_left(range(left, right + 1), True, key=check) ``` +#### Java + ```java class Solution { public int splitArray(int[] nums, int k) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func splitArray(nums []int, k int) int { left, right := 0, 0 @@ -182,6 +190,8 @@ func splitArray(nums []int, k int) int { } ``` +#### TypeScript + ```ts function splitArray(nums: number[], k: number): number { let left = 0; diff --git a/solution/0400-0499/0410.Split Array Largest Sum/README_EN.md b/solution/0400-0499/0410.Split Array Largest Sum/README_EN.md index 243c73a52e188..77d8d7308ba3e 100644 --- a/solution/0400-0499/0410.Split Array Largest Sum/README_EN.md +++ b/solution/0400-0499/0410.Split Array Largest Sum/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(n \times \log m)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def splitArray(self, nums: List[int], k: int) -> int: @@ -88,6 +90,8 @@ class Solution: return left + bisect_left(range(left, right + 1), True, key=check) ``` +#### Java + ```java class Solution { public int splitArray(int[] nums, int k) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func splitArray(nums []int, k int) int { left, right := 0, 0 @@ -176,6 +184,8 @@ func splitArray(nums []int, k int) int { } ``` +#### TypeScript + ```ts function splitArray(nums: number[], k: number): number { let left = 0; diff --git a/solution/0400-0499/0411.Minimum Unique Word Abbreviation/README.md b/solution/0400-0499/0411.Minimum Unique Word Abbreviation/README.md index e6b1afc7391f2..2b12c0afd2c64 100644 --- a/solution/0400-0499/0411.Minimum Unique Word Abbreviation/README.md +++ b/solution/0400-0499/0411.Minimum Unique Word Abbreviation/README.md @@ -84,18 +84,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/0400-0499/0411.Minimum Unique Word Abbreviation/README_EN.md b/solution/0400-0499/0411.Minimum Unique Word Abbreviation/README_EN.md index 5004f7a289716..b212be8d5b140 100644 --- a/solution/0400-0499/0411.Minimum Unique Word Abbreviation/README_EN.md +++ b/solution/0400-0499/0411.Minimum Unique Word Abbreviation/README_EN.md @@ -81,18 +81,26 @@ Since none of them are abbreviations of words in the dictionary, returning any o +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/0400-0499/0412.Fizz Buzz/README.md b/solution/0400-0499/0412.Fizz Buzz/README.md index 29bf2f4e92ce0..79138b9b875bc 100644 --- a/solution/0400-0499/0412.Fizz Buzz/README.md +++ b/solution/0400-0499/0412.Fizz Buzz/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def fizzBuzz(self, n: int) -> List[str]: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List fizzBuzz(int n) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func fizzBuzz(n int) []string { var ans []string @@ -142,6 +150,8 @@ func fizzBuzz(n int) []string { } ``` +#### JavaScript + ```js const fizzBuzz = function (n) { let arr = []; @@ -155,6 +165,8 @@ const fizzBuzz = function (n) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0400-0499/0412.Fizz Buzz/README_EN.md b/solution/0400-0499/0412.Fizz Buzz/README_EN.md index a540c6b901e66..06e315a49b9e9 100644 --- a/solution/0400-0499/0412.Fizz Buzz/README_EN.md +++ b/solution/0400-0499/0412.Fizz Buzz/README_EN.md @@ -55,6 +55,8 @@ tags: +#### Python3 + ```python class Solution: def fizzBuzz(self, n: int) -> List[str]: @@ -71,6 +73,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List fizzBuzz(int n) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func fizzBuzz(n int) []string { var ans []string @@ -130,6 +138,8 @@ func fizzBuzz(n int) []string { } ``` +#### JavaScript + ```js const fizzBuzz = function (n) { let arr = []; @@ -143,6 +153,8 @@ const fizzBuzz = function (n) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0400-0499/0413.Arithmetic Slices/README.md b/solution/0400-0499/0413.Arithmetic Slices/README.md index f3f1f053878f7..b1b0d653e7489 100644 --- a/solution/0400-0499/0413.Arithmetic Slices/README.md +++ b/solution/0400-0499/0413.Arithmetic Slices/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfArithmeticSlices(self, nums: List[int]) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numberOfArithmeticSlices(int[] nums) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func numberOfArithmeticSlices(nums []int) (ans int) { cnt, d := 0, 3000 @@ -153,6 +161,8 @@ func numberOfArithmeticSlices(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function numberOfArithmeticSlices(nums: number[]): number { let ans = 0; @@ -183,6 +193,8 @@ function numberOfArithmeticSlices(nums: number[]): number { +#### Python3 + ```python class Solution: def numberOfArithmeticSlices(self, nums: List[int]) -> int: diff --git a/solution/0400-0499/0413.Arithmetic Slices/README_EN.md b/solution/0400-0499/0413.Arithmetic Slices/README_EN.md index b082c30abf93a..33091be4eafb2 100644 --- a/solution/0400-0499/0413.Arithmetic Slices/README_EN.md +++ b/solution/0400-0499/0413.Arithmetic Slices/README_EN.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfArithmeticSlices(self, nums: List[int]) -> int: @@ -76,6 +78,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numberOfArithmeticSlices(int[] nums) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func numberOfArithmeticSlices(nums []int) (ans int) { cnt, d := 0, 3000 @@ -132,6 +140,8 @@ func numberOfArithmeticSlices(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function numberOfArithmeticSlices(nums: number[]): number { let ans = 0; @@ -162,6 +172,8 @@ function numberOfArithmeticSlices(nums: number[]): number { +#### Python3 + ```python class Solution: def numberOfArithmeticSlices(self, nums: List[int]) -> int: diff --git a/solution/0400-0499/0414.Third Maximum Number/README.md b/solution/0400-0499/0414.Third Maximum Number/README.md index 4cae05fac67f1..6cf326dfc12bc 100644 --- a/solution/0400-0499/0414.Third Maximum Number/README.md +++ b/solution/0400-0499/0414.Third Maximum Number/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def thirdMax(self, nums: List[int]) -> int: @@ -83,6 +85,8 @@ class Solution: return m3 if m3 != -inf else m1 ``` +#### Java + ```java class Solution { public int thirdMax(int[] nums) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func thirdMax(nums []int) int { m1, m2, m3 := math.MinInt64, math.MinInt64, math.MinInt64 diff --git a/solution/0400-0499/0414.Third Maximum Number/README_EN.md b/solution/0400-0499/0414.Third Maximum Number/README_EN.md index 763c54270e001..1fe8d1a9a6ec0 100644 --- a/solution/0400-0499/0414.Third Maximum Number/README_EN.md +++ b/solution/0400-0499/0414.Third Maximum Number/README_EN.md @@ -74,6 +74,8 @@ The third distinct maximum is 1. +#### Python3 + ```python class Solution: def thirdMax(self, nums: List[int]) -> int: @@ -90,6 +92,8 @@ class Solution: return m3 if m3 != -inf else m1 ``` +#### Java + ```java class Solution { public int thirdMax(int[] nums) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func thirdMax(nums []int) int { m1, m2, m3 := math.MinInt64, math.MinInt64, math.MinInt64 diff --git a/solution/0400-0499/0415.Add Strings/README.md b/solution/0400-0499/0415.Add Strings/README.md index fe1cfecd0a4a7..b52f6e92bae39 100644 --- a/solution/0400-0499/0415.Add Strings/README.md +++ b/solution/0400-0499/0415.Add Strings/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def addStrings(self, num1: str, num2: str) -> str: @@ -109,6 +111,8 @@ class Solution: return ''.join(ans[::-1]) ``` +#### Java + ```java class Solution { public String addStrings(String num1, String num2) { @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -192,6 +198,8 @@ public: }; ``` +#### Go + ```go func addStrings(num1 string, num2 string) string { i, j := len(num1)-1, len(num2)-1 @@ -245,6 +253,8 @@ func subStrings(num1 string, num2 string) string { } ``` +#### TypeScript + ```ts function addStrings(num1: string, num2: string): string { let i = num1.length - 1; @@ -286,6 +296,8 @@ function subStrings(num1: string, num2: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn add_strings(num1: String, num2: String) -> String { @@ -312,6 +324,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} num1 diff --git a/solution/0400-0499/0415.Add Strings/README_EN.md b/solution/0400-0499/0415.Add Strings/README_EN.md index e80a05f211a12..6baa8822775c0 100644 --- a/solution/0400-0499/0415.Add Strings/README_EN.md +++ b/solution/0400-0499/0415.Add Strings/README_EN.md @@ -71,6 +71,8 @@ The following code also implements string subtraction, refer to the `subStrings( +#### Python3 + ```python class Solution: def addStrings(self, num1: str, num2: str) -> str: @@ -105,6 +107,8 @@ class Solution: return ''.join(ans[::-1]) ``` +#### Java + ```java class Solution { public String addStrings(String num1, String num2) { @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go func addStrings(num1 string, num2 string) string { i, j := len(num1)-1, len(num2)-1 @@ -241,6 +249,8 @@ func subStrings(num1 string, num2 string) string { } ``` +#### TypeScript + ```ts function addStrings(num1: string, num2: string): string { let i = num1.length - 1; @@ -282,6 +292,8 @@ function subStrings(num1: string, num2: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn add_strings(num1: String, num2: String) -> String { @@ -308,6 +320,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} num1 diff --git a/solution/0400-0499/0416.Partition Equal Subset Sum/README.md b/solution/0400-0499/0416.Partition Equal Subset Sum/README.md index 483bb88a158f4..6aefd86541a21 100644 --- a/solution/0400-0499/0416.Partition Equal Subset Sum/README.md +++ b/solution/0400-0499/0416.Partition Equal Subset Sum/README.md @@ -71,6 +71,8 @@ $$ +#### Python3 + ```python class Solution: def canPartition(self, nums: List[int]) -> bool: @@ -86,6 +88,8 @@ class Solution: return f[n][m] ``` +#### Java + ```java class Solution { public boolean canPartition(int[] nums) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func canPartition(nums []int) bool { s := 0 @@ -161,6 +169,8 @@ func canPartition(nums []int) bool { } ``` +#### TypeScript + ```ts function canPartition(nums: number[]): boolean { const s = nums.reduce((a, b) => a + b, 0); @@ -183,6 +193,8 @@ function canPartition(nums: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -219,6 +231,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -255,6 +269,8 @@ var canPartition = function (nums) { +#### Python3 + ```python class Solution: def canPartition(self, nums: List[int]) -> bool: @@ -268,6 +284,8 @@ class Solution: return f[m] ``` +#### Java + ```java class Solution { public boolean canPartition(int[] nums) { @@ -292,6 +310,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -314,6 +334,8 @@ public: }; ``` +#### Go + ```go func canPartition(nums []int) bool { s := 0 @@ -335,6 +357,8 @@ func canPartition(nums []int) bool { } ``` +#### TypeScript + ```ts function canPartition(nums: number[]): boolean { const s = nums.reduce((a, b) => a + b, 0); @@ -353,6 +377,8 @@ function canPartition(nums: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -389,6 +415,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0400-0499/0416.Partition Equal Subset Sum/README_EN.md b/solution/0400-0499/0416.Partition Equal Subset Sum/README_EN.md index 9f5ae1cea5676..c73d9f767e0eb 100644 --- a/solution/0400-0499/0416.Partition Equal Subset Sum/README_EN.md +++ b/solution/0400-0499/0416.Partition Equal Subset Sum/README_EN.md @@ -54,6 +54,8 @@ tags: +#### Python3 + ```python class Solution: def canPartition(self, nums: List[int]) -> bool: @@ -69,6 +71,8 @@ class Solution: return f[n][m] ``` +#### Java + ```java class Solution { public boolean canPartition(int[] nums) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func canPartition(nums []int) bool { s := 0 @@ -144,6 +152,8 @@ func canPartition(nums []int) bool { } ``` +#### TypeScript + ```ts function canPartition(nums: number[]): boolean { const s = nums.reduce((a, b) => a + b, 0); @@ -166,6 +176,8 @@ function canPartition(nums: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -202,6 +214,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -238,6 +252,8 @@ var canPartition = function (nums) { +#### Python3 + ```python class Solution: def canPartition(self, nums: List[int]) -> bool: @@ -251,6 +267,8 @@ class Solution: return f[m] ``` +#### Java + ```java class Solution { public boolean canPartition(int[] nums) { @@ -275,6 +293,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -297,6 +317,8 @@ public: }; ``` +#### Go + ```go func canPartition(nums []int) bool { s := 0 @@ -318,6 +340,8 @@ func canPartition(nums []int) bool { } ``` +#### TypeScript + ```ts function canPartition(nums: number[]): boolean { const s = nums.reduce((a, b) => a + b, 0); @@ -336,6 +360,8 @@ function canPartition(nums: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -372,6 +398,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0400-0499/0417.Pacific Atlantic Water Flow/README.md b/solution/0400-0499/0417.Pacific Atlantic Water Flow/README.md index f9699f657a696..5e130a9b25d93 100644 --- a/solution/0400-0499/0417.Pacific Atlantic Water Flow/README.md +++ b/solution/0400-0499/0417.Pacific Atlantic Water Flow/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def pacificAtlantic(self, heights: List[List[int]]) -> List[List[int]]: @@ -106,6 +108,8 @@ class Solution: ] ``` +#### Java + ```java class Solution { private int[][] heights; @@ -166,6 +170,8 @@ class Solution { } ``` +#### C++ + ```cpp typedef pair pii; @@ -229,6 +235,8 @@ public: }; ``` +#### Go + ```go func pacificAtlantic(heights [][]int) [][]int { m, n := len(heights), len(heights[0]) @@ -279,6 +287,8 @@ func pacificAtlantic(heights [][]int) [][]int { } ``` +#### TypeScript + ```ts function pacificAtlantic(heights: number[][]): number[][] { const m = heights.length; diff --git a/solution/0400-0499/0417.Pacific Atlantic Water Flow/README_EN.md b/solution/0400-0499/0417.Pacific Atlantic Water Flow/README_EN.md index cf73f256462b3..ef8d5a3664fb5 100644 --- a/solution/0400-0499/0417.Pacific Atlantic Water Flow/README_EN.md +++ b/solution/0400-0499/0417.Pacific Atlantic Water Flow/README_EN.md @@ -79,6 +79,8 @@ Note that there are other possible paths for these cells to flow to the Pacific +#### Python3 + ```python class Solution: def pacificAtlantic(self, heights: List[List[int]]) -> List[List[int]]: @@ -119,6 +121,8 @@ class Solution: ] ``` +#### Java + ```java class Solution { private int[][] heights; @@ -179,6 +183,8 @@ class Solution { } ``` +#### C++ + ```cpp typedef pair pii; @@ -242,6 +248,8 @@ public: }; ``` +#### Go + ```go func pacificAtlantic(heights [][]int) [][]int { m, n := len(heights), len(heights[0]) @@ -292,6 +300,8 @@ func pacificAtlantic(heights [][]int) [][]int { } ``` +#### TypeScript + ```ts function pacificAtlantic(heights: number[][]): number[][] { const m = heights.length; diff --git a/solution/0400-0499/0418.Sentence Screen Fitting/README.md b/solution/0400-0499/0418.Sentence Screen Fitting/README.md index 75a44d6f266cc..98249f3e78e13 100644 --- a/solution/0400-0499/0418.Sentence Screen Fitting/README.md +++ b/solution/0400-0499/0418.Sentence Screen Fitting/README.md @@ -95,6 +95,8 @@ had-- +#### Python3 + ```python class Solution: def wordsTyping(self, sentence: List[str], rows: int, cols: int) -> int: @@ -110,6 +112,8 @@ class Solution: return cur // m ``` +#### Java + ```java class Solution { public int wordsTyping(String[] sentence, int rows, int cols) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func wordsTyping(sentence []string, rows int, cols int) int { s := strings.Join(sentence, " ") + " " @@ -176,6 +184,8 @@ func wordsTyping(sentence []string, rows int, cols int) int { } ``` +#### TypeScript + ```ts function wordsTyping(sentence: string[], rows: number, cols: number): number { const s = sentence.join(' ') + ' '; diff --git a/solution/0400-0499/0418.Sentence Screen Fitting/README_EN.md b/solution/0400-0499/0418.Sentence Screen Fitting/README_EN.md index 15894ac5ac759..c9fade7465537 100644 --- a/solution/0400-0499/0418.Sentence Screen Fitting/README_EN.md +++ b/solution/0400-0499/0418.Sentence Screen Fitting/README_EN.md @@ -79,6 +79,8 @@ The character '-' signifies an empty space on the screen. +#### Python3 + ```python class Solution: def wordsTyping(self, sentence: List[str], rows: int, cols: int) -> int: @@ -94,6 +96,8 @@ class Solution: return cur // m ``` +#### Java + ```java class Solution { public int wordsTyping(String[] sentence, int rows, int cols) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func wordsTyping(sentence []string, rows int, cols int) int { s := strings.Join(sentence, " ") + " " @@ -160,6 +168,8 @@ func wordsTyping(sentence []string, rows int, cols int) int { } ``` +#### TypeScript + ```ts function wordsTyping(sentence: string[], rows: number, cols: number): number { const s = sentence.join(' ') + ' '; diff --git a/solution/0400-0499/0419.Battleships in a Board/README.md b/solution/0400-0499/0419.Battleships in a Board/README.md index 0d5c55f51155c..5814909da689b 100644 --- a/solution/0400-0499/0419.Battleships in a Board/README.md +++ b/solution/0400-0499/0419.Battleships in a Board/README.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def countBattleships(self, board: List[List[str]]) -> int: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countBattleships(char[][] board) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func countBattleships(board [][]byte) int { m, n := len(board), len(board[0]) diff --git a/solution/0400-0499/0419.Battleships in a Board/README_EN.md b/solution/0400-0499/0419.Battleships in a Board/README_EN.md index bffb57b395910..a6bc06b1bc111 100644 --- a/solution/0400-0499/0419.Battleships in a Board/README_EN.md +++ b/solution/0400-0499/0419.Battleships in a Board/README_EN.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def countBattleships(self, board: List[List[str]]) -> int: @@ -77,6 +79,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countBattleships(char[][] board) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func countBattleships(board [][]byte) int { m, n := len(board), len(board[0]) diff --git a/solution/0400-0499/0420.Strong Password Checker/README.md b/solution/0400-0499/0420.Strong Password Checker/README.md index 30d4667c4fe1a..9c36109439157 100644 --- a/solution/0400-0499/0420.Strong Password Checker/README.md +++ b/solution/0400-0499/0420.Strong Password Checker/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def strongPasswordChecker(self, password: str) -> int: @@ -141,6 +143,8 @@ class Solution: return n - 20 + max(replace, 3 - types) ``` +#### Java + ```java class Solution { public int strongPasswordChecker(String password) { @@ -223,6 +227,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/0400-0499/0420.Strong Password Checker/README_EN.md b/solution/0400-0499/0420.Strong Password Checker/README_EN.md index 671c09097d286..6ec8b28cf1700 100644 --- a/solution/0400-0499/0420.Strong Password Checker/README_EN.md +++ b/solution/0400-0499/0420.Strong Password Checker/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def strongPasswordChecker(self, password: str) -> int: @@ -128,6 +130,8 @@ class Solution: return n - 20 + max(replace, 3 - types) ``` +#### Java + ```java class Solution { public int strongPasswordChecker(String password) { @@ -210,6 +214,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/0400-0499/0421.Maximum XOR of Two Numbers in an Array/README.md b/solution/0400-0499/0421.Maximum XOR of Two Numbers in an Array/README.md index d3a66586948b9..d8f63db9a5414 100644 --- a/solution/0400-0499/0421.Maximum XOR of Two Numbers in an Array/README.md +++ b/solution/0400-0499/0421.Maximum XOR of Two Numbers in an Array/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Trie: __slots__ = ("children",) @@ -104,6 +106,8 @@ class Solution: return max(trie.search(x) for x in nums) ``` +#### Java + ```java class Trie { private Trie[] children = new Trie[2]; @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -200,6 +206,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [2]*Trie @@ -245,6 +253,8 @@ func findMaximumXOR(nums []int) (ans int) { } ``` +#### Rust + ```rust struct Trie { children: [Option>; 2], diff --git a/solution/0400-0499/0421.Maximum XOR of Two Numbers in an Array/README_EN.md b/solution/0400-0499/0421.Maximum XOR of Two Numbers in an Array/README_EN.md index e03dbbc44b2f0..89ac0847ffef9 100644 --- a/solution/0400-0499/0421.Maximum XOR of Two Numbers in an Array/README_EN.md +++ b/solution/0400-0499/0421.Maximum XOR of Two Numbers in an Array/README_EN.md @@ -55,6 +55,8 @@ tags: +#### Python3 + ```python class Trie: __slots__ = ("children",) @@ -91,6 +93,8 @@ class Solution: return max(trie.search(x) for x in nums) ``` +#### Java + ```java class Trie { private Trie[] children = new Trie[2]; @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -187,6 +193,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [2]*Trie @@ -232,6 +240,8 @@ func findMaximumXOR(nums []int) (ans int) { } ``` +#### Rust + ```rust struct Trie { children: [Option>; 2], diff --git a/solution/0400-0499/0422.Valid Word Square/README.md b/solution/0400-0499/0422.Valid Word Square/README.md index 70640ec7f5829..6ab8c928f59b6 100644 --- a/solution/0400-0499/0422.Valid Word Square/README.md +++ b/solution/0400-0499/0422.Valid Word Square/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def validWordSquare(self, words: List[str]) -> bool: @@ -98,6 +100,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean validWordSquare(List words) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func validWordSquare(words []string) bool { m := len(words) @@ -150,6 +158,8 @@ func validWordSquare(words []string) bool { } ``` +#### TypeScript + ```ts function validWordSquare(words: string[]): boolean { const m = words.length; @@ -175,6 +185,8 @@ function validWordSquare(words: string[]): boolean { +#### Python3 + ```python class Solution: def validWordSquare(self, words: List[str]) -> bool: diff --git a/solution/0400-0499/0422.Valid Word Square/README_EN.md b/solution/0400-0499/0422.Valid Word Square/README_EN.md index 7c18668eeb574..7eced53e9b452 100644 --- a/solution/0400-0499/0422.Valid Word Square/README_EN.md +++ b/solution/0400-0499/0422.Valid Word Square/README_EN.md @@ -77,6 +77,8 @@ Therefore, it is NOT a valid word square. +#### Python3 + ```python class Solution: def validWordSquare(self, words: List[str]) -> bool: @@ -90,6 +92,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean validWordSquare(List words) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func validWordSquare(words []string) bool { m := len(words) @@ -142,6 +150,8 @@ func validWordSquare(words []string) bool { } ``` +#### TypeScript + ```ts function validWordSquare(words: string[]): boolean { const m = words.length; @@ -167,6 +177,8 @@ function validWordSquare(words: string[]): boolean { +#### Python3 + ```python class Solution: def validWordSquare(self, words: List[str]) -> bool: diff --git a/solution/0400-0499/0423.Reconstruct Original Digits from English/README.md b/solution/0400-0499/0423.Reconstruct Original Digits from English/README.md index 4cdb9a1839f53..21bcd223c8957 100644 --- a/solution/0400-0499/0423.Reconstruct Original Digits from English/README.md +++ b/solution/0400-0499/0423.Reconstruct Original Digits from English/README.md @@ -56,6 +56,8 @@ tags: +#### Python3 + ```python class Solution: def originalDigits(self, s: str) -> str: @@ -78,6 +80,8 @@ class Solution: return ''.join(cnt[i] * str(i) for i in range(10)) ``` +#### Java + ```java class Solution { public String originalDigits(String s) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func originalDigits(s string) string { counter := make([]int, 26) diff --git a/solution/0400-0499/0423.Reconstruct Original Digits from English/README_EN.md b/solution/0400-0499/0423.Reconstruct Original Digits from English/README_EN.md index 4f85901bccca3..394866f868787 100644 --- a/solution/0400-0499/0423.Reconstruct Original Digits from English/README_EN.md +++ b/solution/0400-0499/0423.Reconstruct Original Digits from English/README_EN.md @@ -47,6 +47,8 @@ tags: +#### Python3 + ```python class Solution: def originalDigits(self, s: str) -> str: @@ -69,6 +71,8 @@ class Solution: return ''.join(cnt[i] * str(i) for i in range(10)) ``` +#### Java + ```java class Solution { public String originalDigits(String s) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func originalDigits(s string) string { counter := make([]int, 26) diff --git a/solution/0400-0499/0424.Longest Repeating Character Replacement/README.md b/solution/0400-0499/0424.Longest Repeating Character Replacement/README.md index 0437d1cf5e086..d5091aad4c8ac 100644 --- a/solution/0400-0499/0424.Longest Repeating Character Replacement/README.md +++ b/solution/0400-0499/0424.Longest Repeating Character Replacement/README.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def characterReplacement(self, s: str, k: int) -> int: @@ -78,6 +80,8 @@ class Solution: return i - j ``` +#### Java + ```java class Solution { public int characterReplacement(String s, int k) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func characterReplacement(s string, k int) int { counter := make([]int, 26) diff --git a/solution/0400-0499/0424.Longest Repeating Character Replacement/README_EN.md b/solution/0400-0499/0424.Longest Repeating Character Replacement/README_EN.md index 558cfcccdbff7..b2a55c131b57d 100644 --- a/solution/0400-0499/0424.Longest Repeating Character Replacement/README_EN.md +++ b/solution/0400-0499/0424.Longest Repeating Character Replacement/README_EN.md @@ -59,6 +59,8 @@ There may exists other ways to achieve this answer too. +#### Python3 + ```python class Solution: def characterReplacement(self, s: str, k: int) -> int: @@ -74,6 +76,8 @@ class Solution: return i - j ``` +#### Java + ```java class Solution { public int characterReplacement(String s, int k) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func characterReplacement(s string, k int) int { counter := make([]int, 26) diff --git a/solution/0400-0499/0425.Word Squares/README.md b/solution/0400-0499/0425.Word Squares/README.md index a3ae0a86e621b..1bbbf4055e496 100644 --- a/solution/0400-0499/0425.Word Squares/README.md +++ b/solution/0400-0499/0425.Word Squares/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Trie: def __init__(self): @@ -123,6 +125,8 @@ class Solution: return ans ``` +#### Java + ```java class Trie { Trie[] children = new Trie[26]; @@ -193,6 +197,8 @@ class Solution { } ``` +#### Go + ```go type Trie struct { children [26]*Trie diff --git a/solution/0400-0499/0425.Word Squares/README_EN.md b/solution/0400-0499/0425.Word Squares/README_EN.md index 8f16f4d460812..bb05ef668f894 100644 --- a/solution/0400-0499/0425.Word Squares/README_EN.md +++ b/solution/0400-0499/0425.Word Squares/README_EN.md @@ -67,6 +67,8 @@ The output consists of two word squares. The order of output does not matter (ju +#### Python3 + ```python class Trie: def __init__(self): @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java class Trie { Trie[] children = new Trie[26]; @@ -185,6 +189,8 @@ class Solution { } ``` +#### Go + ```go type Trie struct { children [26]*Trie diff --git a/solution/0400-0499/0426.Convert Binary Search Tree to Sorted Doubly Linked List/README.md b/solution/0400-0499/0426.Convert Binary Search Tree to Sorted Doubly Linked List/README.md index 158a82d41899f..55384020a4c62 100644 --- a/solution/0400-0499/0426.Convert Binary Search Tree to Sorted Doubly Linked List/README.md +++ b/solution/0400-0499/0426.Convert Binary Search Tree to Sorted Doubly Linked List/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python """ # Definition for a Node. @@ -120,6 +122,8 @@ class Solution: return head ``` +#### Java + ```java /* // Definition for a Node. @@ -175,6 +179,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -229,6 +235,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -267,6 +275,8 @@ func treeToDoublyList(root *Node) *Node { } ``` +#### JavaScript + ```js /** * // Definition for a Node. diff --git a/solution/0400-0499/0426.Convert Binary Search Tree to Sorted Doubly Linked List/README_EN.md b/solution/0400-0499/0426.Convert Binary Search Tree to Sorted Doubly Linked List/README_EN.md index effce0bdb16c2..f6dc4704c4065 100644 --- a/solution/0400-0499/0426.Convert Binary Search Tree to Sorted Doubly Linked List/README_EN.md +++ b/solution/0400-0499/0426.Convert Binary Search Tree to Sorted Doubly Linked List/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python """ # Definition for a Node. @@ -104,6 +106,8 @@ class Solution: return head ``` +#### Java + ```java /* // Definition for a Node. @@ -159,6 +163,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -213,6 +219,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -251,6 +259,8 @@ func treeToDoublyList(root *Node) *Node { } ``` +#### JavaScript + ```js /** * // Definition for a Node. diff --git a/solution/0400-0499/0427.Construct Quad Tree/README.md b/solution/0400-0499/0427.Construct Quad Tree/README.md index 79c38dd9c63ef..561c58bac14f4 100644 --- a/solution/0400-0499/0427.Construct Quad Tree/README.md +++ b/solution/0400-0499/0427.Construct Quad Tree/README.md @@ -109,6 +109,8 @@ DFS 递归遍历 grid,先判断 grid 是否为叶子节点,是则返回叶 +#### Python3 + ```python """ # Definition for a QuadTree node. @@ -146,6 +148,8 @@ class Solution: return dfs(0, 0, len(grid) - 1, len(grid[0]) - 1) ``` +#### Java + ```java /* // Definition for a QuadTree node. @@ -214,6 +218,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a QuadTree node. @@ -284,6 +290,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a QuadTree node. diff --git a/solution/0400-0499/0427.Construct Quad Tree/README_EN.md b/solution/0400-0499/0427.Construct Quad Tree/README_EN.md index 8f1510a5fcbc4..c520c5dca0ee3 100644 --- a/solution/0400-0499/0427.Construct Quad Tree/README_EN.md +++ b/solution/0400-0499/0427.Construct Quad Tree/README_EN.md @@ -101,6 +101,8 @@ Explanation is shown in the photo below: +#### Python3 + ```python """ # Definition for a QuadTree node. @@ -138,6 +140,8 @@ class Solution: return dfs(0, 0, len(grid) - 1, len(grid[0]) - 1) ``` +#### Java + ```java /* // Definition for a QuadTree node. @@ -206,6 +210,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a QuadTree node. @@ -276,6 +282,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a QuadTree node. diff --git a/solution/0400-0499/0428.Serialize and Deserialize N-ary Tree/README.md b/solution/0400-0499/0428.Serialize and Deserialize N-ary Tree/README.md index 27f76fb390af8..61e8aa13931f1 100644 --- a/solution/0400-0499/0428.Serialize and Deserialize N-ary Tree/README.md +++ b/solution/0400-0499/0428.Serialize and Deserialize N-ary Tree/README.md @@ -85,18 +85,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/0400-0499/0428.Serialize and Deserialize N-ary Tree/README_EN.md b/solution/0400-0499/0428.Serialize and Deserialize N-ary Tree/README_EN.md index e3e5f7afd1b78..de230e581670e 100644 --- a/solution/0400-0499/0428.Serialize and Deserialize N-ary Tree/README_EN.md +++ b/solution/0400-0499/0428.Serialize and Deserialize N-ary Tree/README_EN.md @@ -79,18 +79,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/0400-0499/0429.N-ary Tree Level Order Traversal/README.md b/solution/0400-0499/0429.N-ary Tree Level Order Traversal/README.md index 7e528d04c06bf..c8d97b4228f51 100644 --- a/solution/0400-0499/0429.N-ary Tree Level Order Traversal/README.md +++ b/solution/0400-0499/0429.N-ary Tree Level Order Traversal/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python """ # Definition for a Node. @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java /* // Definition for a Node. @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -218,6 +226,8 @@ func levelOrder(root *Node) (ans [][]int) { } ``` +#### TypeScript + ```ts /** * Definition for node. @@ -275,6 +285,8 @@ function levelOrder(root: Node | null): number[][] { +#### Python3 + ```python """ # Definition for a Node. @@ -301,6 +313,8 @@ class Solution: return ans ``` +#### Java + ```java /* // Definition for a Node. @@ -344,6 +358,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -387,6 +403,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -415,6 +433,8 @@ func levelOrder(root *Node) (ans [][]int) { } ``` +#### TypeScript + ```ts /** * Definition for node. diff --git a/solution/0400-0499/0429.N-ary Tree Level Order Traversal/README_EN.md b/solution/0400-0499/0429.N-ary Tree Level Order Traversal/README_EN.md index eab1dc664e7e8..847e70dd72926 100644 --- a/solution/0400-0499/0429.N-ary Tree Level Order Traversal/README_EN.md +++ b/solution/0400-0499/0429.N-ary Tree Level Order Traversal/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python """ # Definition for a Node. @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java /* // Definition for a Node. @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -216,6 +224,8 @@ func levelOrder(root *Node) (ans [][]int) { } ``` +#### TypeScript + ```ts /** * Definition for node. @@ -273,6 +283,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python """ # Definition for a Node. @@ -299,6 +311,8 @@ class Solution: return ans ``` +#### Java + ```java /* // Definition for a Node. @@ -342,6 +356,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -385,6 +401,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -413,6 +431,8 @@ func levelOrder(root *Node) (ans [][]int) { } ``` +#### TypeScript + ```ts /** * Definition for node. diff --git a/solution/0400-0499/0430.Flatten a Multilevel Doubly Linked List/README.md b/solution/0400-0499/0430.Flatten a Multilevel Doubly Linked List/README.md index 0c8260aabb7f5..222fc687b1c09 100644 --- a/solution/0400-0499/0430.Flatten a Multilevel Doubly Linked List/README.md +++ b/solution/0400-0499/0430.Flatten a Multilevel Doubly Linked List/README.md @@ -115,6 +115,8 @@ tags: +#### Python3 + ```python """ # Definition for a Node. @@ -148,6 +150,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /* // Definition for a Node. @@ -186,6 +190,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. diff --git a/solution/0400-0499/0430.Flatten a Multilevel Doubly Linked List/README_EN.md b/solution/0400-0499/0430.Flatten a Multilevel Doubly Linked List/README_EN.md index 30618d9736114..b242cc3af6a69 100644 --- a/solution/0400-0499/0430.Flatten a Multilevel Doubly Linked List/README_EN.md +++ b/solution/0400-0499/0430.Flatten a Multilevel Doubly Linked List/README_EN.md @@ -107,6 +107,8 @@ After flattening the multilevel linked list it becomes: +#### Python3 + ```python """ # Definition for a Node. @@ -140,6 +142,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /* // Definition for a Node. @@ -178,6 +182,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. diff --git a/solution/0400-0499/0431.Encode N-ary Tree to Binary Tree/README.md b/solution/0400-0499/0431.Encode N-ary Tree to Binary Tree/README.md index 952e21e5c712d..891dc6e22048d 100644 --- a/solution/0400-0499/0431.Encode N-ary Tree to Binary Tree/README.md +++ b/solution/0400-0499/0431.Encode N-ary Tree to Binary Tree/README.md @@ -49,18 +49,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/0400-0499/0431.Encode N-ary Tree to Binary Tree/README_EN.md b/solution/0400-0499/0431.Encode N-ary Tree to Binary Tree/README_EN.md index b4ff58c663bca..38050a0c67a53 100644 --- a/solution/0400-0499/0431.Encode N-ary Tree to Binary Tree/README_EN.md +++ b/solution/0400-0499/0431.Encode N-ary Tree to Binary Tree/README_EN.md @@ -65,18 +65,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/0400-0499/0432.All O`one Data Structure/README.md b/solution/0400-0499/0432.All O`one Data Structure/README.md index db576ac34ff29..cc440fa13a10f 100644 --- a/solution/0400-0499/0432.All O`one Data Structure/README.md +++ b/solution/0400-0499/0432.All O`one Data Structure/README.md @@ -76,6 +76,8 @@ allOne.getMinKey(); // 返回 "leet" +#### Python3 + ```python class Node: def __init__(self, key='', cnt=0): @@ -154,6 +156,8 @@ class AllOne: # param_4 = obj.getMinKey() ``` +#### Java + ```java class AllOne { Node root = new Node(); diff --git a/solution/0400-0499/0432.All O`one Data Structure/README_EN.md b/solution/0400-0499/0432.All O`one Data Structure/README_EN.md index d277fb420f720..22e9777ee79f0 100644 --- a/solution/0400-0499/0432.All O`one Data Structure/README_EN.md +++ b/solution/0400-0499/0432.All O`one Data Structure/README_EN.md @@ -74,6 +74,8 @@ allOne.getMinKey(); // return "leet" +#### Python3 + ```python class Node: def __init__(self, key='', cnt=0): @@ -152,6 +154,8 @@ class AllOne: # param_4 = obj.getMinKey() ``` +#### Java + ```java class AllOne { Node root = new Node(); diff --git a/solution/0400-0499/0433.Minimum Genetic Mutation/README.md b/solution/0400-0499/0433.Minimum Genetic Mutation/README.md index 73a8071da0b31..84664ab386a65 100644 --- a/solution/0400-0499/0433.Minimum Genetic Mutation/README.md +++ b/solution/0400-0499/0433.Minimum Genetic Mutation/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def minMutation(self, start: str, end: str, bank: List[str]) -> int: @@ -96,6 +98,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minMutation(String start, String end, String[] bank) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go func minMutation(start string, end string, bank []string) int { s := make(map[string]bool) @@ -203,6 +211,8 @@ func minMutation(start string, end string, bank []string) int { } ``` +#### TypeScript + ```ts function minMutation(start: string, end: string, bank: string[]): number { const queue = [start]; @@ -234,6 +244,8 @@ function minMutation(start: string, end: string, bank: string[]): number { } ``` +#### Rust + ```rust use std::collections::VecDeque; impl Solution { @@ -279,6 +291,8 @@ impl Solution { +#### Python3 + ```python class Solution: def minMutation(self, start: str, end: str, bank: List[str]) -> int: @@ -301,6 +315,8 @@ class Solution: return -1 if ans == inf else ans ``` +#### Java + ```java class Solution { private int ans; @@ -339,6 +355,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -373,6 +391,8 @@ public: }; ``` +#### Go + ```go func minMutation(start string, end string, bank []string) int { s := make(map[string]bool) diff --git a/solution/0400-0499/0433.Minimum Genetic Mutation/README_EN.md b/solution/0400-0499/0433.Minimum Genetic Mutation/README_EN.md index 6ce5066578f51..cd77bc658210d 100644 --- a/solution/0400-0499/0433.Minimum Genetic Mutation/README_EN.md +++ b/solution/0400-0499/0433.Minimum Genetic Mutation/README_EN.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def minMutation(self, start: str, end: str, bank: List[str]) -> int: @@ -85,6 +87,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minMutation(String start, String end, String[] bank) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func minMutation(start string, end string, bank []string) int { s := make(map[string]bool) @@ -192,6 +200,8 @@ func minMutation(start string, end string, bank []string) int { } ``` +#### TypeScript + ```ts function minMutation(start: string, end: string, bank: string[]): number { const queue = [start]; @@ -223,6 +233,8 @@ function minMutation(start: string, end: string, bank: string[]): number { } ``` +#### Rust + ```rust use std::collections::VecDeque; impl Solution { @@ -268,6 +280,8 @@ impl Solution { +#### Python3 + ```python class Solution: def minMutation(self, start: str, end: str, bank: List[str]) -> int: @@ -290,6 +304,8 @@ class Solution: return -1 if ans == inf else ans ``` +#### Java + ```java class Solution { private int ans; @@ -328,6 +344,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -362,6 +380,8 @@ public: }; ``` +#### Go + ```go func minMutation(start string, end string, bank []string) int { s := make(map[string]bool) diff --git a/solution/0400-0499/0434.Number of Segments in a String/README.md b/solution/0400-0499/0434.Number of Segments in a String/README.md index f147221a370b5..bb68680de4334 100644 --- a/solution/0400-0499/0434.Number of Segments in a String/README.md +++ b/solution/0400-0499/0434.Number of Segments in a String/README.md @@ -41,12 +41,16 @@ tags: +#### Python3 + ```python class Solution: def countSegments(self, s: str) -> int: return len(s.split()) ``` +#### Java + ```java class Solution { public int countSegments(String s) { @@ -61,6 +65,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -73,6 +79,8 @@ public: }; ``` +#### Go + ```go func countSegments(s string) int { ans := 0 @@ -85,6 +93,8 @@ func countSegments(s string) int { } ``` +#### PHP + ```php class Solution { /** @@ -118,6 +128,8 @@ class Solution { +#### Python3 + ```python class Solution: def countSegments(self, s: str) -> int: @@ -128,6 +140,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countSegments(String s) { @@ -142,6 +156,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +173,8 @@ public: }; ``` +#### Go + ```go func countSegments(s string) int { ans := 0 diff --git a/solution/0400-0499/0434.Number of Segments in a String/README_EN.md b/solution/0400-0499/0434.Number of Segments in a String/README_EN.md index 20a1915752760..becc602f25288 100644 --- a/solution/0400-0499/0434.Number of Segments in a String/README_EN.md +++ b/solution/0400-0499/0434.Number of Segments in a String/README_EN.md @@ -55,12 +55,16 @@ tags: +#### Python3 + ```python class Solution: def countSegments(self, s: str) -> int: return len(s.split()) ``` +#### Java + ```java class Solution { public int countSegments(String s) { @@ -75,6 +79,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -87,6 +93,8 @@ public: }; ``` +#### Go + ```go func countSegments(s string) int { ans := 0 @@ -99,6 +107,8 @@ func countSegments(s string) int { } ``` +#### PHP + ```php class Solution { /** @@ -128,6 +138,8 @@ class Solution { +#### Python3 + ```python class Solution: def countSegments(self, s: str) -> int: @@ -138,6 +150,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countSegments(String s) { @@ -152,6 +166,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +183,8 @@ public: }; ``` +#### Go + ```go func countSegments(s string) int { ans := 0 diff --git a/solution/0400-0499/0435.Non-overlapping Intervals/README.md b/solution/0400-0499/0435.Non-overlapping Intervals/README.md index 7e782f7d1a7d0..d43bb0288a93a 100644 --- a/solution/0400-0499/0435.Non-overlapping Intervals/README.md +++ b/solution/0400-0499/0435.Non-overlapping Intervals/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int eraseOverlapIntervals(int[][] intervals) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func eraseOverlapIntervals(intervals [][]int) int { sort.Slice(intervals, func(i, j int) bool { @@ -133,6 +141,8 @@ func eraseOverlapIntervals(intervals [][]int) int { } ``` +#### TypeScript + ```ts function eraseOverlapIntervals(intervals: number[][]): number { intervals.sort((a, b) => a[1] - b[1]); @@ -169,6 +179,8 @@ function eraseOverlapIntervals(intervals: number[][]): number { +#### Python3 + ```python class Solution: def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int: @@ -183,6 +195,8 @@ class Solution: return len(intervals) - len(d) ``` +#### Java + ```java class Solution { public int eraseOverlapIntervals(int[][] intervals) { diff --git a/solution/0400-0499/0435.Non-overlapping Intervals/README_EN.md b/solution/0400-0499/0435.Non-overlapping Intervals/README_EN.md index db90b5800fcb2..4ae623ca167ee 100644 --- a/solution/0400-0499/0435.Non-overlapping Intervals/README_EN.md +++ b/solution/0400-0499/0435.Non-overlapping Intervals/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int eraseOverlapIntervals(int[][] intervals) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func eraseOverlapIntervals(intervals [][]int) int { sort.Slice(intervals, func(i, j int) bool { @@ -129,6 +137,8 @@ func eraseOverlapIntervals(intervals [][]int) int { } ``` +#### TypeScript + ```ts function eraseOverlapIntervals(intervals: number[][]): number { intervals.sort((a, b) => a[1] - b[1]); @@ -156,6 +166,8 @@ function eraseOverlapIntervals(intervals: number[][]): number { +#### Python3 + ```python class Solution: def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int: @@ -170,6 +182,8 @@ class Solution: return len(intervals) - len(d) ``` +#### Java + ```java class Solution { public int eraseOverlapIntervals(int[][] intervals) { diff --git a/solution/0400-0499/0436.Find Right Interval/README.md b/solution/0400-0499/0436.Find Right Interval/README.md index ecc786da764da..880cdf33da7a9 100644 --- a/solution/0400-0499/0436.Find Right Interval/README.md +++ b/solution/0400-0499/0436.Find Right Interval/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def findRightInterval(self, intervals: List[List[int]]) -> List[int]: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] findRightInterval(int[][] intervals) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func findRightInterval(intervals [][]int) []int { n := len(intervals) @@ -178,6 +186,8 @@ func findRightInterval(intervals [][]int) []int { } ``` +#### TypeScript + ```ts function findRightInterval(intervals: number[][]): number[] { const n = intervals.length; diff --git a/solution/0400-0499/0436.Find Right Interval/README_EN.md b/solution/0400-0499/0436.Find Right Interval/README_EN.md index 6f07dd8d7aa76..ffed5e3affe65 100644 --- a/solution/0400-0499/0436.Find Right Interval/README_EN.md +++ b/solution/0400-0499/0436.Find Right Interval/README_EN.md @@ -72,6 +72,8 @@ The right interval for [2,3] is [3,4] since start2 = 3 is the smalles +#### Python3 + ```python class Solution: def findRightInterval(self, intervals: List[List[int]]) -> List[int]: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] findRightInterval(int[][] intervals) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func findRightInterval(intervals [][]int) []int { n := len(intervals) @@ -177,6 +185,8 @@ func findRightInterval(intervals [][]int) []int { } ``` +#### TypeScript + ```ts function findRightInterval(intervals: number[][]): number[] { const n = intervals.length; diff --git a/solution/0400-0499/0437.Path Sum III/README.md b/solution/0400-0499/0437.Path Sum III/README.md index 5dfee125eb615..193150e562e0f 100644 --- a/solution/0400-0499/0437.Path Sum III/README.md +++ b/solution/0400-0499/0437.Path Sum III/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -101,6 +103,8 @@ class Solution: return dfs(root, 0) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -200,6 +208,8 @@ func pathSum(root *TreeNode, targetSum int) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0400-0499/0437.Path Sum III/README_EN.md b/solution/0400-0499/0437.Path Sum III/README_EN.md index 49935f1552161..ebb80e36b0158 100644 --- a/solution/0400-0499/0437.Path Sum III/README_EN.md +++ b/solution/0400-0499/0437.Path Sum III/README_EN.md @@ -57,6 +57,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -81,6 +83,8 @@ class Solution: return dfs(root, 0) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -180,6 +188,8 @@ func pathSum(root *TreeNode, targetSum int) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0400-0499/0438.Find All Anagrams in a String/README.md b/solution/0400-0499/0438.Find All Anagrams in a String/README.md index ed97cd31d3d08..2110c185a9f5f 100644 --- a/solution/0400-0499/0438.Find All Anagrams in a String/README.md +++ b/solution/0400-0499/0438.Find All Anagrams in a String/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def findAnagrams(self, s: str, p: str) -> List[int]: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List findAnagrams(String s, String p) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func findAnagrams(s string, p string) (ans []int) { m, n := len(s), len(p) @@ -171,6 +179,8 @@ func findAnagrams(s string, p string) (ans []int) { } ``` +#### TypeScript + ```ts function findAnagrams(s: string, p: string): number[] { const m = s.length; @@ -199,6 +209,8 @@ function findAnagrams(s: string, p: string): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn find_anagrams(s: String, p: String) -> Vec { @@ -229,6 +241,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public IList FindAnagrams(string s, string p) { @@ -271,6 +285,8 @@ public class Solution { +#### Python3 + ```python class Solution: def findAnagrams(self, s: str, p: str) -> List[int]: @@ -291,6 +307,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List findAnagrams(String s, String p) { @@ -319,6 +337,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -348,6 +368,8 @@ public: }; ``` +#### Go + ```go func findAnagrams(s string, p string) (ans []int) { m, n := len(s), len(p) @@ -374,6 +396,8 @@ func findAnagrams(s string, p string) (ans []int) { } ``` +#### TypeScript + ```ts function findAnagrams(s: string, p: string): number[] { const m = s.length; diff --git a/solution/0400-0499/0438.Find All Anagrams in a String/README_EN.md b/solution/0400-0499/0438.Find All Anagrams in a String/README_EN.md index 3448e0659ccfd..a84b5a544ec49 100644 --- a/solution/0400-0499/0438.Find All Anagrams in a String/README_EN.md +++ b/solution/0400-0499/0438.Find All Anagrams in a String/README_EN.md @@ -62,6 +62,8 @@ The substring with start index = 2 is "ab", which is an anagram of &qu +#### Python3 + ```python class Solution: def findAnagrams(self, s: str, p: str) -> List[int]: @@ -79,6 +81,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List findAnagrams(String s, String p) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func findAnagrams(s string, p string) (ans []int) { m, n := len(s), len(p) @@ -161,6 +169,8 @@ func findAnagrams(s string, p string) (ans []int) { } ``` +#### TypeScript + ```ts function findAnagrams(s: string, p: string): number[] { const m = s.length; @@ -189,6 +199,8 @@ function findAnagrams(s: string, p: string): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn find_anagrams(s: String, p: String) -> Vec { @@ -219,6 +231,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public IList FindAnagrams(string s, string p) { @@ -257,6 +271,8 @@ public class Solution { +#### Python3 + ```python class Solution: def findAnagrams(self, s: str, p: str) -> List[int]: @@ -277,6 +293,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List findAnagrams(String s, String p) { @@ -305,6 +323,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -334,6 +354,8 @@ public: }; ``` +#### Go + ```go func findAnagrams(s string, p string) (ans []int) { m, n := len(s), len(p) @@ -360,6 +382,8 @@ func findAnagrams(s string, p string) (ans []int) { } ``` +#### TypeScript + ```ts function findAnagrams(s: string, p: string): number[] { const m = s.length; diff --git a/solution/0400-0499/0439.Ternary Expression Parser/README.md b/solution/0400-0499/0439.Ternary Expression Parser/README.md index d186011701647..e5c925743752d 100644 --- a/solution/0400-0499/0439.Ternary Expression Parser/README.md +++ b/solution/0400-0499/0439.Ternary Expression Parser/README.md @@ -84,6 +84,8 @@ or "(F ? 1 : (T ? 4 : 5))" --> "(T ? 4 : 5)" --> "4" +#### Python3 + ```python class Solution: def parseTernary(self, expression: str) -> str: @@ -108,6 +110,8 @@ class Solution: return stk[0] ``` +#### Java + ```java class Solution { public String parseTernary(String expression) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func parseTernary(expression string) string { stk := []byte{} diff --git a/solution/0400-0499/0439.Ternary Expression Parser/README_EN.md b/solution/0400-0499/0439.Ternary Expression Parser/README_EN.md index 0d532670d13f4..05b7ab65a0575 100644 --- a/solution/0400-0499/0439.Ternary Expression Parser/README_EN.md +++ b/solution/0400-0499/0439.Ternary Expression Parser/README_EN.md @@ -72,6 +72,8 @@ or "(F ? 1 : (T ? 4 : 5))" --> "(T ? 4 : 5)" --> " +#### Python3 + ```python class Solution: def parseTernary(self, expression: str) -> str: @@ -96,6 +98,8 @@ class Solution: return stk[0] ``` +#### Java + ```java class Solution { public String parseTernary(String expression) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func parseTernary(expression string) string { stk := []byte{} diff --git a/solution/0400-0499/0440.K-th Smallest in Lexicographical Order/README.md b/solution/0400-0499/0440.K-th Smallest in Lexicographical Order/README.md index 60b9afd514a6c..26787290a8f05 100644 --- a/solution/0400-0499/0440.K-th Smallest in Lexicographical Order/README.md +++ b/solution/0400-0499/0440.K-th Smallest in Lexicographical Order/README.md @@ -53,6 +53,8 @@ tags: +#### Python3 + ```python class Solution: def findKthNumber(self, n: int, k: int) -> int: @@ -76,6 +78,8 @@ class Solution: return curr ``` +#### Java + ```java class Solution { private int n; @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func findKthNumber(n int, k int) int { count := func(curr int) int { diff --git a/solution/0400-0499/0440.K-th Smallest in Lexicographical Order/README_EN.md b/solution/0400-0499/0440.K-th Smallest in Lexicographical Order/README_EN.md index b52ea258ef760..f8c7bc38a68b3 100644 --- a/solution/0400-0499/0440.K-th Smallest in Lexicographical Order/README_EN.md +++ b/solution/0400-0499/0440.K-th Smallest in Lexicographical Order/README_EN.md @@ -51,6 +51,8 @@ tags: +#### Python3 + ```python class Solution: def findKthNumber(self, n: int, k: int) -> int: @@ -74,6 +76,8 @@ class Solution: return curr ``` +#### Java + ```java class Solution { private int n; @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func findKthNumber(n int, k int) int { count := func(curr int) int { diff --git a/solution/0400-0499/0441.Arranging Coins/README.md b/solution/0400-0499/0441.Arranging Coins/README.md index 394f28812bc73..da40b540e8e3a 100644 --- a/solution/0400-0499/0441.Arranging Coins/README.md +++ b/solution/0400-0499/0441.Arranging Coins/README.md @@ -63,12 +63,16 @@ tags: +#### Python3 + ```python class Solution: def arrangeCoins(self, n: int) -> int: return int(math.sqrt(2) * math.sqrt(n + 0.125) - 0.5) ``` +#### Java + ```java class Solution { public int arrangeCoins(int n) { @@ -77,6 +81,8 @@ class Solution { } ``` +#### C++ + ```cpp using LL = long; @@ -97,6 +103,8 @@ public: }; ``` +#### Go + ```go func arrangeCoins(n int) int { left, right := 1, n @@ -122,6 +130,8 @@ func arrangeCoins(n int) int { +#### Python3 + ```python class Solution: def arrangeCoins(self, n: int) -> int: @@ -135,6 +145,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int arrangeCoins(int n) { diff --git a/solution/0400-0499/0441.Arranging Coins/README_EN.md b/solution/0400-0499/0441.Arranging Coins/README_EN.md index 74f96fd34f631..3e3092c2e19d8 100644 --- a/solution/0400-0499/0441.Arranging Coins/README_EN.md +++ b/solution/0400-0499/0441.Arranging Coins/README_EN.md @@ -55,12 +55,16 @@ tags: +#### Python3 + ```python class Solution: def arrangeCoins(self, n: int) -> int: return int(math.sqrt(2) * math.sqrt(n + 0.125) - 0.5) ``` +#### Java + ```java class Solution { public int arrangeCoins(int n) { @@ -69,6 +73,8 @@ class Solution { } ``` +#### C++ + ```cpp using LL = long; @@ -89,6 +95,8 @@ public: }; ``` +#### Go + ```go func arrangeCoins(n int) int { left, right := 1, n @@ -114,6 +122,8 @@ func arrangeCoins(n int) int { +#### Python3 + ```python class Solution: def arrangeCoins(self, n: int) -> int: @@ -127,6 +137,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int arrangeCoins(int n) { diff --git a/solution/0400-0499/0442.Find All Duplicates in an Array/README.md b/solution/0400-0499/0442.Find All Duplicates in an Array/README.md index 027db98b21c03..1486960699bcd 100644 --- a/solution/0400-0499/0442.Find All Duplicates in an Array/README.md +++ b/solution/0400-0499/0442.Find All Duplicates in an Array/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def findDuplicates(self, nums: List[int]) -> List[int]: @@ -74,6 +76,8 @@ class Solution: return [v for i, v in enumerate(nums) if v != i + 1] ``` +#### Java + ```java class Solution { public List findDuplicates(int[] nums) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func findDuplicates(nums []int) []int { for i := range nums { diff --git a/solution/0400-0499/0442.Find All Duplicates in an Array/README_EN.md b/solution/0400-0499/0442.Find All Duplicates in an Array/README_EN.md index ad386d09c3ab1..361061fbb722e 100644 --- a/solution/0400-0499/0442.Find All Duplicates in an Array/README_EN.md +++ b/solution/0400-0499/0442.Find All Duplicates in an Array/README_EN.md @@ -52,6 +52,8 @@ tags: +#### Python3 + ```python class Solution: def findDuplicates(self, nums: List[int]) -> List[int]: @@ -61,6 +63,8 @@ class Solution: return [v for i, v in enumerate(nums) if v != i + 1] ``` +#### Java + ```java class Solution { public List findDuplicates(int[] nums) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func findDuplicates(nums []int) []int { for i := range nums { diff --git a/solution/0400-0499/0443.String Compression/README.md b/solution/0400-0499/0443.String Compression/README.md index b8367a2882822..b6c7c79e30629 100644 --- a/solution/0400-0499/0443.String Compression/README.md +++ b/solution/0400-0499/0443.String Compression/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def compress(self, chars: List[str]) -> int: @@ -96,6 +98,8 @@ class Solution: return k ``` +#### Java + ```java class Solution { public int compress(char[] chars) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func compress(chars []byte) int { i, k, n := 0, 0, len(chars) @@ -162,6 +170,8 @@ func compress(chars []byte) int { } ``` +#### Rust + ```rust impl Solution { pub fn compress(chars: &mut Vec) -> i32 { diff --git a/solution/0400-0499/0443.String Compression/README_EN.md b/solution/0400-0499/0443.String Compression/README_EN.md index 2ea5567e06287..f0f5292bde31d 100644 --- a/solution/0400-0499/0443.String Compression/README_EN.md +++ b/solution/0400-0499/0443.String Compression/README_EN.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def compress(self, chars: List[str]) -> int: @@ -93,6 +95,8 @@ class Solution: return k ``` +#### Java + ```java class Solution { public int compress(char[] chars) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func compress(chars []byte) int { i, k, n := 0, 0, len(chars) @@ -159,6 +167,8 @@ func compress(chars []byte) int { } ``` +#### Rust + ```rust impl Solution { pub fn compress(chars: &mut Vec) -> i32 { diff --git a/solution/0400-0499/0444.Sequence Reconstruction/README.md b/solution/0400-0499/0444.Sequence Reconstruction/README.md index 0555f1615a099..6529ccf26273c 100644 --- a/solution/0400-0499/0444.Sequence Reconstruction/README.md +++ b/solution/0400-0499/0444.Sequence Reconstruction/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python class Solution: def sequenceReconstruction( @@ -118,6 +120,8 @@ class Solution: return len(q) == 0 ``` +#### Java + ```java class Solution { public boolean sequenceReconstruction(int[] nums, List> sequences) { @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -185,6 +191,8 @@ public: }; ``` +#### Go + ```go func sequenceReconstruction(nums []int, sequences [][]int) bool { n := len(nums) @@ -218,6 +226,8 @@ func sequenceReconstruction(nums []int, sequences [][]int) bool { } ``` +#### TypeScript + ```ts function sequenceReconstruction(nums: number[], sequences: number[][]): boolean { const n = nums.length; diff --git a/solution/0400-0499/0444.Sequence Reconstruction/README_EN.md b/solution/0400-0499/0444.Sequence Reconstruction/README_EN.md index 816caa3445c15..1ef1d94f45f51 100644 --- a/solution/0400-0499/0444.Sequence Reconstruction/README_EN.md +++ b/solution/0400-0499/0444.Sequence Reconstruction/README_EN.md @@ -96,6 +96,8 @@ The time complexity is $O(n + m)$, and the space complexity is $O(n + m)$. Where +#### Python3 + ```python class Solution: def sequenceReconstruction( @@ -119,6 +121,8 @@ class Solution: return len(q) == 0 ``` +#### Java + ```java class Solution { public boolean sequenceReconstruction(int[] nums, List> sequences) { @@ -152,6 +156,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go func sequenceReconstruction(nums []int, sequences [][]int) bool { n := len(nums) @@ -219,6 +227,8 @@ func sequenceReconstruction(nums []int, sequences [][]int) bool { } ``` +#### TypeScript + ```ts function sequenceReconstruction(nums: number[], sequences: number[][]): boolean { const n = nums.length; diff --git a/solution/0400-0499/0445.Add Two Numbers II/README.md b/solution/0400-0499/0445.Add Two Numbers II/README.md index fe9159766ee63..03c4de4b63dce 100644 --- a/solution/0400-0499/0445.Add Two Numbers II/README.md +++ b/solution/0400-0499/0445.Add Two Numbers II/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -101,6 +103,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -214,6 +222,8 @@ func addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -249,6 +259,8 @@ function addTwoNumbers(l1: ListNode | null, l2: ListNode | null): ListNode | nul } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -323,6 +335,8 @@ impl Solution { +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] diff --git a/solution/0400-0499/0445.Add Two Numbers II/README_EN.md b/solution/0400-0499/0445.Add Two Numbers II/README_EN.md index ec6bd71c1ceb5..9b019b5ce48ed 100644 --- a/solution/0400-0499/0445.Add Two Numbers II/README_EN.md +++ b/solution/0400-0499/0445.Add Two Numbers II/README_EN.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -94,6 +96,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -207,6 +215,8 @@ func addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -242,6 +252,8 @@ function addTwoNumbers(l1: ListNode | null, l2: ListNode | null): ListNode | nul } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -308,6 +320,8 @@ impl Solution { +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] diff --git a/solution/0400-0499/0446.Arithmetic Slices II - Subsequence/README.md b/solution/0400-0499/0446.Arithmetic Slices II - Subsequence/README.md index b64fb62b1eaea..6a98055ceda46 100644 --- a/solution/0400-0499/0446.Arithmetic Slices II - Subsequence/README.md +++ b/solution/0400-0499/0446.Arithmetic Slices II - Subsequence/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfArithmeticSlices(self, nums: List[int]) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numberOfArithmeticSlices(int[] nums) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func numberOfArithmeticSlices(nums []int) (ans int) { f := make([]map[int]int, len(nums)) @@ -157,6 +165,8 @@ func numberOfArithmeticSlices(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function numberOfArithmeticSlices(nums: number[]): number { const n = nums.length; diff --git a/solution/0400-0499/0446.Arithmetic Slices II - Subsequence/README_EN.md b/solution/0400-0499/0446.Arithmetic Slices II - Subsequence/README_EN.md index 37523017a8441..75bfd8117179e 100644 --- a/solution/0400-0499/0446.Arithmetic Slices II - Subsequence/README_EN.md +++ b/solution/0400-0499/0446.Arithmetic Slices II - Subsequence/README_EN.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfArithmeticSlices(self, nums: List[int]) -> int: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numberOfArithmeticSlices(int[] nums) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func numberOfArithmeticSlices(nums []int) (ans int) { f := make([]map[int]int, len(nums)) @@ -147,6 +155,8 @@ func numberOfArithmeticSlices(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function numberOfArithmeticSlices(nums: number[]): number { const n = nums.length; diff --git a/solution/0400-0499/0447.Number of Boomerangs/README.md b/solution/0400-0499/0447.Number of Boomerangs/README.md index d614dc42a064e..5a82d83210bd7 100644 --- a/solution/0400-0499/0447.Number of Boomerangs/README.md +++ b/solution/0400-0499/0447.Number of Boomerangs/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfBoomerangs(self, points: List[List[int]]) -> int: @@ -86,6 +88,8 @@ class Solution: return ans << 1 ``` +#### Java + ```java class Solution { public int numberOfBoomerangs(int[][] points) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func numberOfBoomerangs(points [][]int) (ans int) { for _, p1 := range points { @@ -136,6 +144,8 @@ func numberOfBoomerangs(points [][]int) (ans int) { } ``` +#### TypeScript + ```ts function numberOfBoomerangs(points: number[][]): number { let ans = 0; @@ -161,6 +171,8 @@ function numberOfBoomerangs(points: number[][]): number { +#### Python3 + ```python class Solution: def numberOfBoomerangs(self, points: List[List[int]]) -> int: @@ -174,6 +186,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numberOfBoomerangs(int[][] points) { @@ -193,6 +207,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -213,6 +229,8 @@ public: }; ``` +#### Go + ```go func numberOfBoomerangs(points [][]int) (ans int) { for _, p1 := range points { @@ -229,6 +247,8 @@ func numberOfBoomerangs(points [][]int) (ans int) { } ``` +#### TypeScript + ```ts function numberOfBoomerangs(points: number[][]): number { let ans = 0; diff --git a/solution/0400-0499/0447.Number of Boomerangs/README_EN.md b/solution/0400-0499/0447.Number of Boomerangs/README_EN.md index 620fe565c6a3f..214cf809b8945 100644 --- a/solution/0400-0499/0447.Number of Boomerangs/README_EN.md +++ b/solution/0400-0499/0447.Number of Boomerangs/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$, where $n$ i +#### Python3 + ```python class Solution: def numberOfBoomerangs(self, points: List[List[int]]) -> int: @@ -85,6 +87,8 @@ class Solution: return ans << 1 ``` +#### Java + ```java class Solution { public int numberOfBoomerangs(int[][] points) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func numberOfBoomerangs(points [][]int) (ans int) { for _, p1 := range points { @@ -135,6 +143,8 @@ func numberOfBoomerangs(points [][]int) (ans int) { } ``` +#### TypeScript + ```ts function numberOfBoomerangs(points: number[][]): number { let ans = 0; @@ -160,6 +170,8 @@ function numberOfBoomerangs(points: number[][]): number { +#### Python3 + ```python class Solution: def numberOfBoomerangs(self, points: List[List[int]]) -> int: @@ -173,6 +185,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numberOfBoomerangs(int[][] points) { @@ -192,6 +206,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -212,6 +228,8 @@ public: }; ``` +#### Go + ```go func numberOfBoomerangs(points [][]int) (ans int) { for _, p1 := range points { @@ -228,6 +246,8 @@ func numberOfBoomerangs(points [][]int) (ans int) { } ``` +#### TypeScript + ```ts function numberOfBoomerangs(points: number[][]): number { let ans = 0; diff --git a/solution/0400-0499/0448.Find All Numbers Disappeared in an Array/README.md b/solution/0400-0499/0448.Find All Numbers Disappeared in an Array/README.md index e4690c54f416c..037580eb4c95f 100644 --- a/solution/0400-0499/0448.Find All Numbers Disappeared in an Array/README.md +++ b/solution/0400-0499/0448.Find All Numbers Disappeared in an Array/README.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def findDisappearedNumbers(self, nums: List[int]) -> List[int]: @@ -68,6 +70,8 @@ class Solution: return [x for x in range(1, len(nums) + 1) if x not in s] ``` +#### Java + ```java class Solution { public List findDisappearedNumbers(int[] nums) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func findDisappearedNumbers(nums []int) (ans []int) { n := len(nums) @@ -124,6 +132,8 @@ func findDisappearedNumbers(nums []int) (ans []int) { } ``` +#### TypeScript + ```ts function findDisappearedNumbers(nums: number[]): number[] { const n = nums.length; @@ -157,6 +167,8 @@ function findDisappearedNumbers(nums: number[]): number[] { +#### Python3 + ```python class Solution: def findDisappearedNumbers(self, nums: List[int]) -> List[int]: @@ -167,6 +179,8 @@ class Solution: return [i + 1 for i in range(len(nums)) if nums[i] > 0] ``` +#### Java + ```java class Solution { public List findDisappearedNumbers(int[] nums) { @@ -188,6 +202,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -210,6 +226,8 @@ public: }; ``` +#### Go + ```go func findDisappearedNumbers(nums []int) (ans []int) { n := len(nums) @@ -235,6 +253,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function findDisappearedNumbers(nums: number[]): number[] { const n = nums.length; diff --git a/solution/0400-0499/0448.Find All Numbers Disappeared in an Array/README_EN.md b/solution/0400-0499/0448.Find All Numbers Disappeared in an Array/README_EN.md index fb800c627e53b..b5bd4e7aaf3f7 100644 --- a/solution/0400-0499/0448.Find All Numbers Disappeared in an Array/README_EN.md +++ b/solution/0400-0499/0448.Find All Numbers Disappeared in an Array/README_EN.md @@ -49,6 +49,8 @@ tags: +#### Python3 + ```python class Solution: def findDisappearedNumbers(self, nums: List[int]) -> List[int]: @@ -56,6 +58,8 @@ class Solution: return [x for x in range(1, len(nums) + 1) if x not in s] ``` +#### Java + ```java class Solution { public List findDisappearedNumbers(int[] nums) { @@ -75,6 +79,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -96,6 +102,8 @@ public: }; ``` +#### Go + ```go func findDisappearedNumbers(nums []int) (ans []int) { n := len(nums) @@ -112,6 +120,8 @@ func findDisappearedNumbers(nums []int) (ans []int) { } ``` +#### TypeScript + ```ts function findDisappearedNumbers(nums: number[]): number[] { const n = nums.length; @@ -139,6 +149,8 @@ function findDisappearedNumbers(nums: number[]): number[] { +#### Python3 + ```python class Solution: def findDisappearedNumbers(self, nums: List[int]) -> List[int]: @@ -149,6 +161,8 @@ class Solution: return [i + 1 for i in range(len(nums)) if nums[i] > 0] ``` +#### Java + ```java class Solution { public List findDisappearedNumbers(int[] nums) { @@ -170,6 +184,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -192,6 +208,8 @@ public: }; ``` +#### Go + ```go func findDisappearedNumbers(nums []int) (ans []int) { n := len(nums) @@ -217,6 +235,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function findDisappearedNumbers(nums: number[]): number[] { const n = nums.length; diff --git a/solution/0400-0499/0449.Serialize and Deserialize BST/README.md b/solution/0400-0499/0449.Serialize and Deserialize BST/README.md index 4084efc81b3d7..f7362ddd0f68f 100644 --- a/solution/0400-0499/0449.Serialize and Deserialize BST/README.md +++ b/solution/0400-0499/0449.Serialize and Deserialize BST/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -122,6 +124,8 @@ class Codec: # return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -187,6 +191,8 @@ public class Codec { // return ans; ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -257,6 +263,8 @@ public: // return ans; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0400-0499/0449.Serialize and Deserialize BST/README_EN.md b/solution/0400-0499/0449.Serialize and Deserialize BST/README_EN.md index 41affc86d1a8c..bca245fda3392 100644 --- a/solution/0400-0499/0449.Serialize and Deserialize BST/README_EN.md +++ b/solution/0400-0499/0449.Serialize and Deserialize BST/README_EN.md @@ -55,6 +55,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -107,6 +109,8 @@ class Codec: # return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -172,6 +176,8 @@ public class Codec { // return ans; ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -242,6 +248,8 @@ public: // return ans; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0400-0499/0450.Delete Node in a BST/README.md b/solution/0400-0499/0450.Delete Node in a BST/README.md index 9b77aebb9df9b..12cacb8772735 100644 --- a/solution/0400-0499/0450.Delete Node in a BST/README.md +++ b/solution/0400-0499/0450.Delete Node in a BST/README.md @@ -100,6 +100,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -129,6 +131,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -175,6 +179,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -210,6 +216,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -247,6 +255,8 @@ func deleteNode(root *TreeNode, key int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -295,6 +305,8 @@ function deleteNode(root: TreeNode | null, key: number): TreeNode | null { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/0400-0499/0450.Delete Node in a BST/README_EN.md b/solution/0400-0499/0450.Delete Node in a BST/README_EN.md index a684e33eb9ec5..58ed29b310782 100644 --- a/solution/0400-0499/0450.Delete Node in a BST/README_EN.md +++ b/solution/0400-0499/0450.Delete Node in a BST/README_EN.md @@ -78,6 +78,8 @@ Please notice that another valid answer is [5,2,6,null,4,null,7] and it's al +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -107,6 +109,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -153,6 +157,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -225,6 +233,8 @@ func deleteNode(root *TreeNode, key int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -273,6 +283,8 @@ function deleteNode(root: TreeNode | null, key: number): TreeNode | null { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/0400-0499/0451.Sort Characters By Frequency/README.md b/solution/0400-0499/0451.Sort Characters By Frequency/README.md index 469df18ab1f6f..aafb28f4cfe41 100644 --- a/solution/0400-0499/0451.Sort Characters By Frequency/README.md +++ b/solution/0400-0499/0451.Sort Characters By Frequency/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def frequencySort(self, s: str) -> str: @@ -84,6 +86,8 @@ class Solution: return ''.join(c * v for c, v in sorted(cnt.items(), key=lambda x: -x[1])) ``` +#### Java + ```java class Solution { public String frequencySort(String s) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func frequencySort(s string) string { cnt := map[byte]int{} @@ -147,6 +155,8 @@ func frequencySort(s string) string { } ``` +#### TypeScript + ```ts function frequencySort(s: string): string { const cnt: Map = new Map(); @@ -162,6 +172,8 @@ function frequencySort(s: string): string { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { @@ -179,6 +191,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0400-0499/0451.Sort Characters By Frequency/README_EN.md b/solution/0400-0499/0451.Sort Characters By Frequency/README_EN.md index 250092e50637e..220845820ddcf 100644 --- a/solution/0400-0499/0451.Sort Characters By Frequency/README_EN.md +++ b/solution/0400-0499/0451.Sort Characters By Frequency/README_EN.md @@ -71,6 +71,8 @@ Note that 'A' and 'a' are treated as two different characters. +#### Python3 + ```python class Solution: def frequencySort(self, s: str) -> str: @@ -78,6 +80,8 @@ class Solution: return ''.join(c * v for c, v in sorted(cnt.items(), key=lambda x: -x[1])) ``` +#### Java + ```java class Solution { public String frequencySort(String s) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func frequencySort(s string) string { cnt := map[byte]int{} @@ -141,6 +149,8 @@ func frequencySort(s string) string { } ``` +#### TypeScript + ```ts function frequencySort(s: string): string { const cnt: Map = new Map(); @@ -156,6 +166,8 @@ function frequencySort(s: string): string { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { @@ -173,6 +185,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0400-0499/0452.Minimum Number of Arrows to Burst Balloons/README.md b/solution/0400-0499/0452.Minimum Number of Arrows to Burst Balloons/README.md index 4af0254f27800..090d26c92c71a 100644 --- a/solution/0400-0499/0452.Minimum Number of Arrows to Burst Balloons/README.md +++ b/solution/0400-0499/0452.Minimum Number of Arrows to Burst Balloons/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def findMinArrowShots(self, points: List[List[int]]) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findMinArrowShots(int[][] points) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func findMinArrowShots(points [][]int) (ans int) { sort.Slice(points, func(i, j int) bool { return points[i][1] < points[j][1] }) @@ -148,6 +156,8 @@ func findMinArrowShots(points [][]int) (ans int) { } ``` +#### TypeScript + ```ts function findMinArrowShots(points: number[][]): number { points.sort((a, b) => a[1] - b[1]); @@ -163,6 +173,8 @@ function findMinArrowShots(points: number[][]): number { } ``` +#### C# + ```cs public class Solution { public int FindMinArrowShots(int[][] points) { diff --git a/solution/0400-0499/0452.Minimum Number of Arrows to Burst Balloons/README_EN.md b/solution/0400-0499/0452.Minimum Number of Arrows to Burst Balloons/README_EN.md index 6725a055abb5c..953219ecfe638 100644 --- a/solution/0400-0499/0452.Minimum Number of Arrows to Burst Balloons/README_EN.md +++ b/solution/0400-0499/0452.Minimum Number of Arrows to Burst Balloons/README_EN.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def findMinArrowShots(self, points: List[List[int]]) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findMinArrowShots(int[][] points) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func findMinArrowShots(points [][]int) (ans int) { sort.Slice(points, func(i, j int) bool { return points[i][1] < points[j][1] }) @@ -138,6 +146,8 @@ func findMinArrowShots(points [][]int) (ans int) { } ``` +#### TypeScript + ```ts function findMinArrowShots(points: number[][]): number { points.sort((a, b) => a[1] - b[1]); @@ -153,6 +163,8 @@ function findMinArrowShots(points: number[][]): number { } ``` +#### C# + ```cs public class Solution { public int FindMinArrowShots(int[][] points) { diff --git a/solution/0400-0499/0453.Minimum Moves to Equal Array Elements/README.md b/solution/0400-0499/0453.Minimum Moves to Equal Array Elements/README.md index 95ffa10a1c818..1c4889b25db7b 100644 --- a/solution/0400-0499/0453.Minimum Moves to Equal Array Elements/README.md +++ b/solution/0400-0499/0453.Minimum Moves to Equal Array Elements/README.md @@ -84,12 +84,16 @@ $$ +#### Python3 + ```python class Solution: def minMoves(self, nums: List[int]) -> int: return sum(nums) - min(nums) * len(nums) ``` +#### Java + ```java class Solution { public int minMoves(int[] nums) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func minMoves(nums []int) int { mi := 1 << 30 @@ -127,6 +135,8 @@ func minMoves(nums []int) int { } ``` +#### TypeScript + ```ts function minMoves(nums: number[]): number { let mi = 1 << 30; @@ -149,6 +159,8 @@ function minMoves(nums: number[]): number { +#### Java + ```java class Solution { public int minMoves(int[] nums) { diff --git a/solution/0400-0499/0453.Minimum Moves to Equal Array Elements/README_EN.md b/solution/0400-0499/0453.Minimum Moves to Equal Array Elements/README_EN.md index ae8bfeeefff73..f2e6d325c882f 100644 --- a/solution/0400-0499/0453.Minimum Moves to Equal Array Elements/README_EN.md +++ b/solution/0400-0499/0453.Minimum Moves to Equal Array Elements/README_EN.md @@ -58,12 +58,16 @@ tags: +#### Python3 + ```python class Solution: def minMoves(self, nums: List[int]) -> int: return sum(nums) - min(nums) * len(nums) ``` +#### Java + ```java class Solution { public int minMoves(int[] nums) { @@ -72,6 +76,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -87,6 +93,8 @@ public: }; ``` +#### Go + ```go func minMoves(nums []int) int { mi := 1 << 30 @@ -101,6 +109,8 @@ func minMoves(nums []int) int { } ``` +#### TypeScript + ```ts function minMoves(nums: number[]): number { let mi = 1 << 30; @@ -123,6 +133,8 @@ function minMoves(nums: number[]): number { +#### Java + ```java class Solution { public int minMoves(int[] nums) { diff --git a/solution/0400-0499/0454.4Sum II/README.md b/solution/0400-0499/0454.4Sum II/README.md index adfae0e57dc09..339135516fcd6 100644 --- a/solution/0400-0499/0454.4Sum II/README.md +++ b/solution/0400-0499/0454.4Sum II/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def fourSumCount( @@ -82,6 +84,8 @@ class Solution: return sum(cnt[-(c + d)] for c in nums3 for d in nums4) ``` +#### Java + ```java class Solution { public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func fourSumCount(nums1 []int, nums2 []int, nums3 []int, nums4 []int) (ans int) { cnt := map[int]int{} @@ -140,6 +148,8 @@ func fourSumCount(nums1 []int, nums2 []int, nums3 []int, nums4 []int) (ans int) } ``` +#### TypeScript + ```ts function fourSumCount(nums1: number[], nums2: number[], nums3: number[], nums4: number[]): number { const cnt: Map = new Map(); diff --git a/solution/0400-0499/0454.4Sum II/README_EN.md b/solution/0400-0499/0454.4Sum II/README_EN.md index 6c7d87885b720..ad41470fc8000 100644 --- a/solution/0400-0499/0454.4Sum II/README_EN.md +++ b/solution/0400-0499/0454.4Sum II/README_EN.md @@ -67,6 +67,8 @@ Time complexity $O(n^2)$, Space complexity $O(n^2)$. +#### Python3 + ```python class Solution: def fourSumCount( @@ -76,6 +78,8 @@ class Solution: return sum(cnt[-(c + d)] for c in nums3 for d in nums4) ``` +#### Java + ```java class Solution { public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func fourSumCount(nums1 []int, nums2 []int, nums3 []int, nums4 []int) (ans int) { cnt := map[int]int{} @@ -134,6 +142,8 @@ func fourSumCount(nums1 []int, nums2 []int, nums3 []int, nums4 []int) (ans int) } ``` +#### TypeScript + ```ts function fourSumCount(nums1: number[], nums2: number[], nums3: number[], nums4: number[]): number { const cnt: Map = new Map(); diff --git a/solution/0400-0499/0455.Assign Cookies/README.md b/solution/0400-0499/0455.Assign Cookies/README.md index 19bcb832fb43a..94e99259c1f2b 100644 --- a/solution/0400-0499/0455.Assign Cookies/README.md +++ b/solution/0400-0499/0455.Assign Cookies/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def findContentChildren(self, g: List[int], s: List[int]) -> int: @@ -92,6 +94,8 @@ class Solution: return len(g) ``` +#### Java + ```java class Solution { public int findContentChildren(int[] g, int[] s) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func findContentChildren(g []int, s []int) int { sort.Ints(g) @@ -150,6 +158,8 @@ func findContentChildren(g []int, s []int) int { } ``` +#### TypeScript + ```ts function findContentChildren(g: number[], s: number[]): number { g.sort((a, b) => a - b); @@ -168,6 +178,8 @@ function findContentChildren(g: number[], s: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} g diff --git a/solution/0400-0499/0455.Assign Cookies/README_EN.md b/solution/0400-0499/0455.Assign Cookies/README_EN.md index 4cce2f36fa197..73ccf248e3e9f 100644 --- a/solution/0400-0499/0455.Assign Cookies/README_EN.md +++ b/solution/0400-0499/0455.Assign Cookies/README_EN.md @@ -63,6 +63,8 @@ You need to output 2. +#### Python3 + ```python class Solution: def findContentChildren(self, g: List[int], s: List[int]) -> int: @@ -78,6 +80,8 @@ class Solution: return len(g) ``` +#### Java + ```java class Solution { public int findContentChildren(int[] g, int[] s) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func findContentChildren(g []int, s []int) int { sort.Ints(g) @@ -136,6 +144,8 @@ func findContentChildren(g []int, s []int) int { } ``` +#### TypeScript + ```ts function findContentChildren(g: number[], s: number[]): number { g.sort((a, b) => a - b); @@ -154,6 +164,8 @@ function findContentChildren(g: number[], s: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} g diff --git a/solution/0400-0499/0456.132 Pattern/README.md b/solution/0400-0499/0456.132 Pattern/README.md index 62edc208435fe..c8c5c762f3394 100644 --- a/solution/0400-0499/0456.132 Pattern/README.md +++ b/solution/0400-0499/0456.132 Pattern/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def find132pattern(self, nums: List[int]) -> bool: @@ -92,6 +94,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean find132pattern(int[] nums) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func find132pattern(nums []int) bool { vk := -(1 << 30) @@ -150,6 +158,8 @@ func find132pattern(nums []int) bool { } ``` +#### TypeScript + ```ts function find132pattern(nums: number[]): boolean { let vk = -Infinity; @@ -167,6 +177,8 @@ function find132pattern(nums: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn find132pattern(nums: Vec) -> bool { @@ -205,6 +217,8 @@ impl Solution { +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -241,6 +255,8 @@ class Solution: return False ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -309,6 +325,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -364,6 +382,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -420,6 +440,8 @@ func find132pattern(nums []int) bool { } ``` +#### TypeScript + ```ts class BinaryIndextedTree { n: number; diff --git a/solution/0400-0499/0456.132 Pattern/README_EN.md b/solution/0400-0499/0456.132 Pattern/README_EN.md index 1392f725049f0..b973d31038a9e 100644 --- a/solution/0400-0499/0456.132 Pattern/README_EN.md +++ b/solution/0400-0499/0456.132 Pattern/README_EN.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def find132pattern(self, nums: List[int]) -> bool: @@ -82,6 +84,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean find132pattern(int[] nums) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func find132pattern(nums []int) bool { vk := -(1 << 30) @@ -140,6 +148,8 @@ func find132pattern(nums []int) bool { } ``` +#### TypeScript + ```ts function find132pattern(nums: number[]): boolean { let vk = -Infinity; @@ -157,6 +167,8 @@ function find132pattern(nums: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn find132pattern(nums: Vec) -> bool { @@ -187,6 +199,8 @@ impl Solution { +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -223,6 +237,8 @@ class Solution: return False ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -291,6 +307,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -346,6 +364,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -402,6 +422,8 @@ func find132pattern(nums []int) bool { } ``` +#### TypeScript + ```ts class BinaryIndextedTree { n: number; diff --git a/solution/0400-0499/0457.Circular Array Loop/README.md b/solution/0400-0499/0457.Circular Array Loop/README.md index 0e16617be7a89..b8e08f322019b 100644 --- a/solution/0400-0499/0457.Circular Array Loop/README.md +++ b/solution/0400-0499/0457.Circular Array Loop/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def circularArrayLoop(self, nums: List[int]) -> bool: @@ -112,6 +114,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { private int n; @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -182,6 +188,8 @@ public: }; ``` +#### Go + ```go func circularArrayLoop(nums []int) bool { for i, num := range nums { diff --git a/solution/0400-0499/0457.Circular Array Loop/README_EN.md b/solution/0400-0499/0457.Circular Array Loop/README_EN.md index ac0f447fad953..31dc31c37f72c 100644 --- a/solution/0400-0499/0457.Circular Array Loop/README_EN.md +++ b/solution/0400-0499/0457.Circular Array Loop/README_EN.md @@ -88,6 +88,8 @@ We can see the cycle 3 --> 4 --> 3 --> ..., and all of its nodes are wh +#### Python3 + ```python class Solution: def circularArrayLoop(self, nums: List[int]) -> bool: @@ -113,6 +115,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { private int n; @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -183,6 +189,8 @@ public: }; ``` +#### Go + ```go func circularArrayLoop(nums []int) bool { for i, num := range nums { diff --git a/solution/0400-0499/0458.Poor Pigs/README.md b/solution/0400-0499/0458.Poor Pigs/README.md index 90ed0fd67bc0c..aa03269deeeb3 100644 --- a/solution/0400-0499/0458.Poor Pigs/README.md +++ b/solution/0400-0499/0458.Poor Pigs/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def poorPigs(self, buckets: int, minutesToDie: int, minutesToTest: int) -> int: @@ -85,6 +87,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public int poorPigs(int buckets, int minutesToDie, int minutesToTest) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func poorPigs(buckets int, minutesToDie int, minutesToTest int) int { base := minutesToTest/minutesToDie + 1 diff --git a/solution/0400-0499/0458.Poor Pigs/README_EN.md b/solution/0400-0499/0458.Poor Pigs/README_EN.md index 3e382888ab3d7..7179590e6c7ac 100644 --- a/solution/0400-0499/0458.Poor Pigs/README_EN.md +++ b/solution/0400-0499/0458.Poor Pigs/README_EN.md @@ -78,6 +78,8 @@ At time 30, one of the two pigs must die, and the poisonous bucket is the one it +#### Python3 + ```python class Solution: def poorPigs(self, buckets: int, minutesToDie: int, minutesToTest: int) -> int: @@ -89,6 +91,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public int poorPigs(int buckets, int minutesToDie, int minutesToTest) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func poorPigs(buckets int, minutesToDie int, minutesToTest int) int { base := minutesToTest/minutesToDie + 1 diff --git a/solution/0400-0499/0459.Repeated Substring Pattern/README.md b/solution/0400-0499/0459.Repeated Substring Pattern/README.md index 00cc7368e867b..cd3b2ad9c8bb8 100644 --- a/solution/0400-0499/0459.Repeated Substring Pattern/README.md +++ b/solution/0400-0499/0459.Repeated Substring Pattern/README.md @@ -71,12 +71,16 @@ tags: +#### Python3 + ```python class Solution: def repeatedSubstringPattern(self, s: str) -> bool: return (s + s).index(s, 1) < len(s) ``` +#### Java + ```java class Solution { public boolean repeatedSubstringPattern(String s) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -95,18 +101,24 @@ public: }; ``` +#### Go + ```go func repeatedSubstringPattern(s string) bool { return strings.Index(s[1:]+s, s) < len(s)-1 } ``` +#### TypeScript + ```ts function repeatedSubstringPattern(s: string): boolean { return (s + s).slice(1, (s.length << 1) - 1).includes(s); } ``` +#### Rust + ```rust impl Solution { pub fn repeated_substring_pattern(s: String) -> bool { @@ -125,6 +137,8 @@ impl Solution { +#### TypeScript + ```ts function repeatedSubstringPattern(s: string): boolean { const n = s.length; diff --git a/solution/0400-0499/0459.Repeated Substring Pattern/README_EN.md b/solution/0400-0499/0459.Repeated Substring Pattern/README_EN.md index 7ed76748dc746..796b58a2b53c5 100644 --- a/solution/0400-0499/0459.Repeated Substring Pattern/README_EN.md +++ b/solution/0400-0499/0459.Repeated Substring Pattern/README_EN.md @@ -61,12 +61,16 @@ tags: +#### Python3 + ```python class Solution: def repeatedSubstringPattern(self, s: str) -> bool: return (s + s).index(s, 1) < len(s) ``` +#### Java + ```java class Solution { public boolean repeatedSubstringPattern(String s) { @@ -76,6 +80,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -85,18 +91,24 @@ public: }; ``` +#### Go + ```go func repeatedSubstringPattern(s string) bool { return strings.Index(s[1:]+s, s) < len(s)-1 } ``` +#### TypeScript + ```ts function repeatedSubstringPattern(s: string): boolean { return (s + s).slice(1, (s.length << 1) - 1).includes(s); } ``` +#### Rust + ```rust impl Solution { pub fn repeated_substring_pattern(s: String) -> bool { @@ -115,6 +127,8 @@ impl Solution { +#### TypeScript + ```ts function repeatedSubstringPattern(s: string): boolean { const n = s.length; diff --git a/solution/0400-0499/0460.LFU Cache/README.md b/solution/0400-0499/0460.LFU Cache/README.md index 7a96455cd89ca..5045318b4b8ea 100644 --- a/solution/0400-0499/0460.LFU Cache/README.md +++ b/solution/0400-0499/0460.LFU Cache/README.md @@ -109,6 +109,8 @@ lfu.get(4); // 返回 4 +#### Python3 + ```python class Node: def __init__(self, key: int, value: int) -> None: @@ -200,6 +202,8 @@ class LFUCache: # obj.put(key,value) ``` +#### Java + ```java class LFUCache { @@ -319,6 +323,8 @@ class LFUCache { } ``` +#### C++ + ```cpp class Node { public: @@ -443,6 +449,8 @@ private: */ ``` +#### Go + ```go type LFUCache struct { cache map[int]*node @@ -566,6 +574,8 @@ func (l *list) empty() bool { } ``` +#### Rust + ```rust use std::cell::RefCell; use std::collections::HashMap; diff --git a/solution/0400-0499/0460.LFU Cache/README_EN.md b/solution/0400-0499/0460.LFU Cache/README_EN.md index 24eadd1d68bbd..5b397a8c2442d 100644 --- a/solution/0400-0499/0460.LFU Cache/README_EN.md +++ b/solution/0400-0499/0460.LFU Cache/README_EN.md @@ -90,6 +90,8 @@ lfu.get(4); // return 4 +#### Python3 + ```python class Node: def __init__(self, key: int, value: int) -> None: @@ -181,6 +183,8 @@ class LFUCache: # obj.put(key,value) ``` +#### Java + ```java class LFUCache { @@ -300,6 +304,8 @@ class LFUCache { } ``` +#### C++ + ```cpp class Node { public: @@ -424,6 +430,8 @@ private: */ ``` +#### Go + ```go type LFUCache struct { cache map[int]*node @@ -547,6 +555,8 @@ func (l *list) empty() bool { } ``` +#### Rust + ```rust use std::cell::RefCell; use std::collections::HashMap; diff --git a/solution/0400-0499/0461.Hamming Distance/README.md b/solution/0400-0499/0461.Hamming Distance/README.md index 0289887842ba9..d268e3be87916 100644 --- a/solution/0400-0499/0461.Hamming Distance/README.md +++ b/solution/0400-0499/0461.Hamming Distance/README.md @@ -63,12 +63,16 @@ tags: +#### Python3 + ```python class Solution: def hammingDistance(self, x: int, y: int) -> int: return (x ^ y).bit_count() ``` +#### Java + ```java class Solution { public int hammingDistance(int x, int y) { @@ -77,6 +81,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -86,12 +92,16 @@ public: }; ``` +#### Go + ```go func hammingDistance(x int, y int) int { return bits.OnesCount(uint(x ^ y)) } ``` +#### TypeScript + ```ts function hammingDistance(x: number, y: number): number { x ^= y; @@ -104,6 +114,8 @@ function hammingDistance(x: number, y: number): number { } ``` +#### JavaScript + ```js /** * @param {number} x diff --git a/solution/0400-0499/0461.Hamming Distance/README_EN.md b/solution/0400-0499/0461.Hamming Distance/README_EN.md index 1b4e27b8218d9..27f2362cc77bb 100644 --- a/solution/0400-0499/0461.Hamming Distance/README_EN.md +++ b/solution/0400-0499/0461.Hamming Distance/README_EN.md @@ -57,12 +57,16 @@ The above arrows point to positions where the corresponding bits are different. +#### Python3 + ```python class Solution: def hammingDistance(self, x: int, y: int) -> int: return (x ^ y).bit_count() ``` +#### Java + ```java class Solution { public int hammingDistance(int x, int y) { @@ -71,6 +75,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -80,12 +86,16 @@ public: }; ``` +#### Go + ```go func hammingDistance(x int, y int) int { return bits.OnesCount(uint(x ^ y)) } ``` +#### TypeScript + ```ts function hammingDistance(x: number, y: number): number { x ^= y; @@ -98,6 +108,8 @@ function hammingDistance(x: number, y: number): number { } ``` +#### JavaScript + ```js /** * @param {number} x diff --git a/solution/0400-0499/0462.Minimum Moves to Equal Array Elements II/README.md b/solution/0400-0499/0462.Minimum Moves to Equal Array Elements II/README.md index 6ef3efaaafb93..aff81a7ec304a 100644 --- a/solution/0400-0499/0462.Minimum Moves to Equal Array Elements II/README.md +++ b/solution/0400-0499/0462.Minimum Moves to Equal Array Elements II/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def minMoves2(self, nums: List[int]) -> int: @@ -86,6 +88,8 @@ class Solution: return sum(abs(v - k) for v in nums) ``` +#### Java + ```java class Solution { public int minMoves2(int[] nums) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func minMoves2(nums []int) int { sort.Ints(nums) @@ -132,6 +140,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function minMoves2(nums: number[]): number { nums.sort((a, b) => a - b); @@ -140,6 +150,8 @@ function minMoves2(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_moves2(mut nums: Vec) -> i32 { @@ -168,6 +180,8 @@ impl Solution { +#### Python3 + ```python class Solution: def minMoves2(self, nums: List[int]) -> int: diff --git a/solution/0400-0499/0462.Minimum Moves to Equal Array Elements II/README_EN.md b/solution/0400-0499/0462.Minimum Moves to Equal Array Elements II/README_EN.md index 2146f3518a299..30f763d29f493 100644 --- a/solution/0400-0499/0462.Minimum Moves to Equal Array Elements II/README_EN.md +++ b/solution/0400-0499/0462.Minimum Moves to Equal Array Elements II/README_EN.md @@ -61,6 +61,8 @@ Only two moves are needed (remember each move increments or decrements one eleme +#### Python3 + ```python class Solution: def minMoves2(self, nums: List[int]) -> int: @@ -69,6 +71,8 @@ class Solution: return sum(abs(v - k) for v in nums) ``` +#### Java + ```java class Solution { public int minMoves2(int[] nums) { @@ -83,6 +87,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -96,6 +102,8 @@ public: }; ``` +#### Go + ```go func minMoves2(nums []int) int { sort.Ints(nums) @@ -115,6 +123,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function minMoves2(nums: number[]): number { nums.sort((a, b) => a - b); @@ -123,6 +133,8 @@ function minMoves2(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_moves2(mut nums: Vec) -> i32 { @@ -147,6 +159,8 @@ impl Solution { +#### Python3 + ```python class Solution: def minMoves2(self, nums: List[int]) -> int: diff --git a/solution/0400-0499/0463.Island Perimeter/README.md b/solution/0400-0499/0463.Island Perimeter/README.md index 6f391282ae312..ac72b24fe069a 100644 --- a/solution/0400-0499/0463.Island Perimeter/README.md +++ b/solution/0400-0499/0463.Island Perimeter/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def islandPerimeter(self, grid: List[List[int]]) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int islandPerimeter(int[][] grid) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func islandPerimeter(grid [][]int) int { m, n := len(grid), len(grid[0]) @@ -152,6 +160,8 @@ func islandPerimeter(grid [][]int) int { } ``` +#### TypeScript + ```ts function islandPerimeter(grid: number[][]): number { let m = grid.length, diff --git a/solution/0400-0499/0463.Island Perimeter/README_EN.md b/solution/0400-0499/0463.Island Perimeter/README_EN.md index fb37c07cb2b91..a062de544072c 100644 --- a/solution/0400-0499/0463.Island Perimeter/README_EN.md +++ b/solution/0400-0499/0463.Island Perimeter/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def islandPerimeter(self, grid: List[List[int]]) -> int: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int islandPerimeter(int[][] grid) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func islandPerimeter(grid [][]int) int { m, n := len(grid), len(grid[0]) @@ -150,6 +158,8 @@ func islandPerimeter(grid [][]int) int { } ``` +#### TypeScript + ```ts function islandPerimeter(grid: number[][]): number { let m = grid.length, diff --git a/solution/0400-0499/0464.Can I Win/README.md b/solution/0400-0499/0464.Can I Win/README.md index be47dcb0935c7..93478495b4db4 100644 --- a/solution/0400-0499/0464.Can I Win/README.md +++ b/solution/0400-0499/0464.Can I Win/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def canIWin(self, maxChoosableInteger: int, desiredTotal: int) -> bool: @@ -95,6 +97,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private Map memo = new HashMap<>(); @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func canIWin(maxChoosableInteger int, desiredTotal int) bool { s := (1 + maxChoosableInteger) * maxChoosableInteger / 2 diff --git a/solution/0400-0499/0464.Can I Win/README_EN.md b/solution/0400-0499/0464.Can I Win/README_EN.md index a0b33c2642f4b..32cc45e5d458b 100644 --- a/solution/0400-0499/0464.Can I Win/README_EN.md +++ b/solution/0400-0499/0464.Can I Win/README_EN.md @@ -75,6 +75,8 @@ Same with other integers chosen by the first player, the second player will alwa +#### Python3 + ```python class Solution: def canIWin(self, maxChoosableInteger: int, desiredTotal: int) -> bool: @@ -93,6 +95,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private Map memo = new HashMap<>(); @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func canIWin(maxChoosableInteger int, desiredTotal int) bool { s := (1 + maxChoosableInteger) * maxChoosableInteger / 2 diff --git a/solution/0400-0499/0465.Optimal Account Balancing/README.md b/solution/0400-0499/0465.Optimal Account Balancing/README.md index 348ef25639748..a7c0bd5cea51b 100644 --- a/solution/0400-0499/0465.Optimal Account Balancing/README.md +++ b/solution/0400-0499/0465.Optimal Account Balancing/README.md @@ -92,6 +92,8 @@ $$ +#### Python3 + ```python class Solution: def minTransfers(self, transactions: List[List[int]]) -> int: @@ -117,6 +119,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int minTransfers(int[][] transactions) { @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -192,6 +198,8 @@ public: }; ``` +#### Go + ```go func minTransfers(transactions [][]int) int { g := [12]int{} @@ -226,6 +234,8 @@ func minTransfers(transactions [][]int) int { } ``` +#### TypeScript + ```ts function minTransfers(transactions: number[][]): number { const g: number[] = new Array(12).fill(0); diff --git a/solution/0400-0499/0465.Optimal Account Balancing/README_EN.md b/solution/0400-0499/0465.Optimal Account Balancing/README_EN.md index a2d4209773068..4b30ebf380c75 100644 --- a/solution/0400-0499/0465.Optimal Account Balancing/README_EN.md +++ b/solution/0400-0499/0465.Optimal Account Balancing/README_EN.md @@ -70,6 +70,8 @@ Therefore, person #1 only need to give person #0 $4, and all debt is settled. +#### Python3 + ```python class Solution: def minTransfers(self, transactions: List[List[int]]) -> int: @@ -95,6 +97,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int minTransfers(int[][] transactions) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go func minTransfers(transactions [][]int) int { g := [12]int{} @@ -204,6 +212,8 @@ func minTransfers(transactions [][]int) int { } ``` +#### TypeScript + ```ts function minTransfers(transactions: number[][]): number { const g: number[] = new Array(12).fill(0); diff --git a/solution/0400-0499/0466.Count The Repetitions/README.md b/solution/0400-0499/0466.Count The Repetitions/README.md index b0bc87579c042..d9cf5eae66984 100644 --- a/solution/0400-0499/0466.Count The Repetitions/README.md +++ b/solution/0400-0499/0466.Count The Repetitions/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def getMaxRepetitions(self, s1: str, n1: int, s2: str, n2: int) -> int: @@ -101,6 +103,8 @@ class Solution: return ans // n2 ``` +#### Java + ```java class Solution { public int getMaxRepetitions(String s1, int n1, String s2, int n2) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func getMaxRepetitions(s1 string, n1 int, s2 string, n2 int) (ans int) { n := len(s2) @@ -185,6 +193,8 @@ func getMaxRepetitions(s1 string, n1 int, s2 string, n2 int) (ans int) { } ``` +#### TypeScript + ```ts function getMaxRepetitions(s1: string, n1: number, s2: string, n2: number): number { const n = s2.length; diff --git a/solution/0400-0499/0466.Count The Repetitions/README_EN.md b/solution/0400-0499/0466.Count The Repetitions/README_EN.md index 03dd1df5f28d2..87c29125602ba 100644 --- a/solution/0400-0499/0466.Count The Repetitions/README_EN.md +++ b/solution/0400-0499/0466.Count The Repetitions/README_EN.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def getMaxRepetitions(self, s1: str, n1: int, s2: str, n2: int) -> int: @@ -84,6 +86,8 @@ class Solution: return ans // n2 ``` +#### Java + ```java class Solution { public int getMaxRepetitions(String s1, int n1, String s2, int n2) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func getMaxRepetitions(s1 string, n1 int, s2 string, n2 int) (ans int) { n := len(s2) @@ -168,6 +176,8 @@ func getMaxRepetitions(s1 string, n1 int, s2 string, n2 int) (ans int) { } ``` +#### TypeScript + ```ts function getMaxRepetitions(s1: string, n1: number, s2: string, n2: number): number { const n = s2.length; diff --git a/solution/0400-0499/0467.Unique Substrings in Wraparound String/README.md b/solution/0400-0499/0467.Unique Substrings in Wraparound String/README.md index f262a053c857e..bf851c54a078f 100644 --- a/solution/0400-0499/0467.Unique Substrings in Wraparound String/README.md +++ b/solution/0400-0499/0467.Unique Substrings in Wraparound String/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def findSubstringInWraproundString(self, p: str) -> int: @@ -91,6 +93,8 @@ class Solution: return sum(dp) ``` +#### Java + ```java class Solution { public int findSubstringInWraproundString(String p) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func findSubstringInWraproundString(p string) int { dp := make([]int, 26) @@ -156,6 +164,8 @@ func findSubstringInWraproundString(p string) int { } ``` +#### TypeScript + ```ts function findSubstringInWraproundString(p: string): number { const n = p.length; @@ -175,6 +185,8 @@ function findSubstringInWraproundString(p: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_substring_in_wrapround_string(p: String) -> i32 { diff --git a/solution/0400-0499/0467.Unique Substrings in Wraparound String/README_EN.md b/solution/0400-0499/0467.Unique Substrings in Wraparound String/README_EN.md index a8cc7949a81bd..09d14ba251d80 100644 --- a/solution/0400-0499/0467.Unique Substrings in Wraparound String/README_EN.md +++ b/solution/0400-0499/0467.Unique Substrings in Wraparound String/README_EN.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def findSubstringInWraproundString(self, p: str) -> int: @@ -83,6 +85,8 @@ class Solution: return sum(dp) ``` +#### Java + ```java class Solution { public int findSubstringInWraproundString(String p) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func findSubstringInWraproundString(p string) int { dp := make([]int, 26) @@ -148,6 +156,8 @@ func findSubstringInWraproundString(p string) int { } ``` +#### TypeScript + ```ts function findSubstringInWraproundString(p: string): number { const n = p.length; @@ -167,6 +177,8 @@ function findSubstringInWraproundString(p: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_substring_in_wrapround_string(p: String) -> i32 { diff --git a/solution/0400-0499/0468.Validate IP Address/README.md b/solution/0400-0499/0468.Validate IP Address/README.md index 60b019934908e..e211b9105f3d5 100644 --- a/solution/0400-0499/0468.Validate IP Address/README.md +++ b/solution/0400-0499/0468.Validate IP Address/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def validIPAddress(self, IP: str) -> str: @@ -104,6 +106,8 @@ class Solution: return "Neither" ``` +#### TypeScript + ```ts function validIPAddress(queryIP: string): string { const isIPv4 = () => { @@ -147,6 +151,8 @@ function validIPAddress(queryIP: string): string { } ``` +#### Rust + ```rust impl Solution { fn is_IPv4(s: &String) -> bool { diff --git a/solution/0400-0499/0468.Validate IP Address/README_EN.md b/solution/0400-0499/0468.Validate IP Address/README_EN.md index c86cd118f25f9..de521f555771a 100644 --- a/solution/0400-0499/0468.Validate IP Address/README_EN.md +++ b/solution/0400-0499/0468.Validate IP Address/README_EN.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def validIPAddress(self, IP: str) -> str: @@ -102,6 +104,8 @@ class Solution: return "Neither" ``` +#### TypeScript + ```ts function validIPAddress(queryIP: string): string { const isIPv4 = () => { @@ -145,6 +149,8 @@ function validIPAddress(queryIP: string): string { } ``` +#### Rust + ```rust impl Solution { fn is_IPv4(s: &String) -> bool { diff --git a/solution/0400-0499/0469.Convex Polygon/README.md b/solution/0400-0499/0469.Convex Polygon/README.md index 8d4f0119e78e5..3cce1a62fd37a 100644 --- a/solution/0400-0499/0469.Convex Polygon/README.md +++ b/solution/0400-0499/0469.Convex Polygon/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def isConvex(self, points: List[List[int]]) -> bool: @@ -88,6 +90,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isConvex(List> points) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func isConvex(points [][]int) bool { n := len(points) diff --git a/solution/0400-0499/0469.Convex Polygon/README_EN.md b/solution/0400-0499/0469.Convex Polygon/README_EN.md index 6ab25f7bc74bf..84fe8882220c3 100644 --- a/solution/0400-0499/0469.Convex Polygon/README_EN.md +++ b/solution/0400-0499/0469.Convex Polygon/README_EN.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python class Solution: def isConvex(self, points: List[List[int]]) -> bool: @@ -76,6 +78,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isConvex(List> points) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func isConvex(points [][]int) bool { n := len(points) diff --git a/solution/0400-0499/0470.Implement Rand10() Using Rand7()/README.md b/solution/0400-0499/0470.Implement Rand10() Using Rand7()/README.md index 3beb6db5d3623..0368ce5f82aec 100644 --- a/solution/0400-0499/0470.Implement Rand10() Using Rand7()/README.md +++ b/solution/0400-0499/0470.Implement Rand10() Using Rand7()/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python # The rand7() API is already defined for you. # def rand7(): @@ -105,6 +107,8 @@ class Solution: return x % 10 + 1 ``` +#### Java + ```java /** * The rand7() API is already defined in the parent class SolBase. @@ -125,6 +129,8 @@ class Solution extends SolBase { } ``` +#### C++ + ```cpp // The rand7() API is already defined for you. // int rand7(); @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func rand10() int { for { @@ -158,6 +166,8 @@ func rand10() int { } ``` +#### TypeScript + ```ts /** * The rand7() API is already defined for you. @@ -177,6 +187,8 @@ function rand10(): number { } ``` +#### Rust + ```rust /** diff --git a/solution/0400-0499/0470.Implement Rand10() Using Rand7()/README_EN.md b/solution/0400-0499/0470.Implement Rand10() Using Rand7()/README_EN.md index 20e2470502057..b0e5d0adfe752 100644 --- a/solution/0400-0499/0470.Implement Rand10() Using Rand7()/README_EN.md +++ b/solution/0400-0499/0470.Implement Rand10() Using Rand7()/README_EN.md @@ -59,6 +59,8 @@ tags: +#### Python3 + ```python # The rand7() API is already defined for you. # def rand7(): @@ -78,6 +80,8 @@ class Solution: return x % 10 + 1 ``` +#### Java + ```java /** * The rand7() API is already defined in the parent class SolBase. @@ -98,6 +102,8 @@ class Solution extends SolBase { } ``` +#### C++ + ```cpp // The rand7() API is already defined for you. // int rand7(); @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func rand10() int { for { @@ -131,6 +139,8 @@ func rand10() int { } ``` +#### TypeScript + ```ts /** * The rand7() API is already defined for you. @@ -150,6 +160,8 @@ function rand10(): number { } ``` +#### Rust + ```rust /** * The rand7() API is already defined for you. diff --git a/solution/0400-0499/0471.Encode String with Shortest Length/README.md b/solution/0400-0499/0471.Encode String with Shortest Length/README.md index cf809ac3742b0..cd383d1064e2a 100644 --- a/solution/0400-0499/0471.Encode String with Shortest Length/README.md +++ b/solution/0400-0499/0471.Encode String with Shortest Length/README.md @@ -99,6 +99,8 @@ tags: +#### Python3 + ```python class Solution: def encode(self, s: str) -> str: @@ -125,6 +127,8 @@ class Solution: return f[0][-1] ``` +#### Java + ```java class Solution { private String s; @@ -165,6 +169,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -203,6 +209,8 @@ public: }; ``` +#### Go + ```go func encode(s string) string { n := len(s) @@ -239,6 +247,8 @@ func encode(s string) string { } ``` +#### TypeScript + ```ts function encode(s: string): string { const n = s.length; diff --git a/solution/0400-0499/0471.Encode String with Shortest Length/README_EN.md b/solution/0400-0499/0471.Encode String with Shortest Length/README_EN.md index 5f762c7ed60e7..c6d6ed1f32fae 100644 --- a/solution/0400-0499/0471.Encode String with Shortest Length/README_EN.md +++ b/solution/0400-0499/0471.Encode String with Shortest Length/README_EN.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def encode(self, s: str) -> str: @@ -92,6 +94,8 @@ class Solution: return f[0][-1] ``` +#### Java + ```java class Solution { private String s; @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go func encode(s string) string { n := len(s) @@ -206,6 +214,8 @@ func encode(s string) string { } ``` +#### TypeScript + ```ts function encode(s: string): string { const n = s.length; diff --git a/solution/0400-0499/0472.Concatenated Words/README.md b/solution/0400-0499/0472.Concatenated Words/README.md index 10c1d748a1274..c487d2cb51c56 100644 --- a/solution/0400-0499/0472.Concatenated Words/README.md +++ b/solution/0400-0499/0472.Concatenated Words/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Trie: def __init__(self): @@ -121,6 +123,8 @@ class Solution: return ans ``` +#### Java + ```java class Trie { Trie[] children = new Trie[26]; @@ -175,6 +179,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -227,6 +233,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [26]*Trie diff --git a/solution/0400-0499/0472.Concatenated Words/README_EN.md b/solution/0400-0499/0472.Concatenated Words/README_EN.md index eb882c614645e..64039ca4901b3 100644 --- a/solution/0400-0499/0472.Concatenated Words/README_EN.md +++ b/solution/0400-0499/0472.Concatenated Words/README_EN.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Trie: def __init__(self): @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Trie { Trie[] children = new Trie[26]; @@ -158,6 +162,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -210,6 +216,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [26]*Trie diff --git a/solution/0400-0499/0473.Matchsticks to Square/README.md b/solution/0400-0499/0473.Matchsticks to Square/README.md index 327f08a6ff1e4..1cf06d9ecb2d2 100644 --- a/solution/0400-0499/0473.Matchsticks to Square/README.md +++ b/solution/0400-0499/0473.Matchsticks to Square/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def makesquare(self, matchsticks: List[int]) -> bool: @@ -92,6 +94,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { public boolean makesquare(int[] matchsticks) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func makesquare(matchsticks []int) bool { s := 0 @@ -189,6 +197,8 @@ func makesquare(matchsticks []int) bool { } ``` +#### Rust + ```rust impl Solution { pub fn makesquare(matchsticks: Vec) -> bool { @@ -242,6 +252,8 @@ impl Solution { +#### Python3 + ```python class Solution: def makesquare(self, matchsticks: List[int]) -> bool: diff --git a/solution/0400-0499/0473.Matchsticks to Square/README_EN.md b/solution/0400-0499/0473.Matchsticks to Square/README_EN.md index 541e4a0c8cc3a..d354ed3737b0a 100644 --- a/solution/0400-0499/0473.Matchsticks to Square/README_EN.md +++ b/solution/0400-0499/0473.Matchsticks to Square/README_EN.md @@ -59,6 +59,8 @@ tags: +#### Python3 + ```python class Solution: def makesquare(self, matchsticks: List[int]) -> bool: @@ -82,6 +84,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { public boolean makesquare(int[] matchsticks) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func makesquare(matchsticks []int) bool { s := 0 @@ -179,6 +187,8 @@ func makesquare(matchsticks []int) bool { } ``` +#### Rust + ```rust impl Solution { pub fn makesquare(matchsticks: Vec) -> bool { @@ -223,6 +233,8 @@ impl Solution { +#### Python3 + ```python class Solution: def makesquare(self, matchsticks: List[int]) -> bool: diff --git a/solution/0400-0499/0474.Ones and Zeroes/README.md b/solution/0400-0499/0474.Ones and Zeroes/README.md index de0740dc03d77..ab93b2b70ac7d 100644 --- a/solution/0400-0499/0474.Ones and Zeroes/README.md +++ b/solution/0400-0499/0474.Ones and Zeroes/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def findMaxForm(self, strs: List[str], m: int, n: int) -> int: @@ -96,6 +98,8 @@ class Solution: return f[sz][m][n] ``` +#### Java + ```java class Solution { public int findMaxForm(String[] strs, int m, int n) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func findMaxForm(strs []string, m int, n int) int { sz := len(strs) @@ -183,6 +191,8 @@ func count(s string) (int, int) { } ``` +#### TypeScript + ```ts function findMaxForm(strs: string[], m: number, n: number): number { const sz = strs.length; @@ -221,6 +231,8 @@ function findMaxForm(strs: string[], m: number, n: number): number { +#### Python3 + ```python class Solution: def findMaxForm(self, strs: List[str], m: int, n: int) -> int: @@ -233,6 +245,8 @@ class Solution: return f[m][n] ``` +#### Java + ```java class Solution { public int findMaxForm(String[] strs, int m, int n) { @@ -258,6 +272,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -282,6 +298,8 @@ public: }; ``` +#### Go + ```go func findMaxForm(strs []string, m int, n int) int { f := make([][]int, m+1) @@ -305,6 +323,8 @@ func count(s string) (int, int) { } ``` +#### TypeScript + ```ts function findMaxForm(strs: string[], m: number, n: number): number { const f = Array.from({ length: m + 1 }, () => Array.from({ length: n + 1 }, () => 0)); diff --git a/solution/0400-0499/0474.Ones and Zeroes/README_EN.md b/solution/0400-0499/0474.Ones and Zeroes/README_EN.md index fd0abd8392b48..8e6f9112a9049 100644 --- a/solution/0400-0499/0474.Ones and Zeroes/README_EN.md +++ b/solution/0400-0499/0474.Ones and Zeroes/README_EN.md @@ -63,6 +63,8 @@ Other valid but smaller subsets include {"0001", "1"} and {& +#### Python3 + ```python class Solution: def findMaxForm(self, strs: List[str], m: int, n: int) -> int: @@ -78,6 +80,8 @@ class Solution: return f[sz][m][n] ``` +#### Java + ```java class Solution { public int findMaxForm(String[] strs, int m, int n) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func findMaxForm(strs []string, m int, n int) int { sz := len(strs) @@ -165,6 +173,8 @@ func count(s string) (int, int) { } ``` +#### TypeScript + ```ts function findMaxForm(strs: string[], m: number, n: number): number { const sz = strs.length; @@ -203,6 +213,8 @@ function findMaxForm(strs: string[], m: number, n: number): number { +#### Python3 + ```python class Solution: def findMaxForm(self, strs: List[str], m: int, n: int) -> int: @@ -215,6 +227,8 @@ class Solution: return f[m][n] ``` +#### Java + ```java class Solution { public int findMaxForm(String[] strs, int m, int n) { @@ -240,6 +254,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -264,6 +280,8 @@ public: }; ``` +#### Go + ```go func findMaxForm(strs []string, m int, n int) int { f := make([][]int, m+1) @@ -287,6 +305,8 @@ func count(s string) (int, int) { } ``` +#### TypeScript + ```ts function findMaxForm(strs: string[], m: number, n: number): number { const f = Array.from({ length: m + 1 }, () => Array.from({ length: n + 1 }, () => 0)); diff --git a/solution/0400-0499/0475.Heaters/README.md b/solution/0400-0499/0475.Heaters/README.md index b083fd33abe2e..3e65d7ef620b9 100644 --- a/solution/0400-0499/0475.Heaters/README.md +++ b/solution/0400-0499/0475.Heaters/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def findRadius(self, houses: List[int], heaters: List[int]) -> int: @@ -103,6 +105,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int findRadius(int[] houses, int[] heaters) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func findRadius(houses []int, heaters []int) int { sort.Ints(houses) @@ -194,6 +202,8 @@ func findRadius(houses []int, heaters []int) int { } ``` +#### TypeScript + ```ts function findRadius(houses: number[], heaters: number[]): number { houses.sort((a, b) => a - b); diff --git a/solution/0400-0499/0475.Heaters/README_EN.md b/solution/0400-0499/0475.Heaters/README_EN.md index 5d8926f0d73c1..518ecb9eb8201 100644 --- a/solution/0400-0499/0475.Heaters/README_EN.md +++ b/solution/0400-0499/0475.Heaters/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def findRadius(self, houses: List[int], heaters: List[int]) -> int: @@ -101,6 +103,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int findRadius(int[] houses, int[] heaters) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func findRadius(houses []int, heaters []int) int { sort.Ints(houses) @@ -192,6 +200,8 @@ func findRadius(houses []int, heaters []int) int { } ``` +#### TypeScript + ```ts function findRadius(houses: number[], heaters: number[]): number { houses.sort((a, b) => a - b); diff --git a/solution/0400-0499/0476.Number Complement/README.md b/solution/0400-0499/0476.Number Complement/README.md index 72841b7f35db8..ef94361032a12 100644 --- a/solution/0400-0499/0476.Number Complement/README.md +++ b/solution/0400-0499/0476.Number Complement/README.md @@ -77,12 +77,16 @@ tags: +#### Python3 + ```python class Solution: def findComplement(self, num: int) -> int: return num ^ ((1 << num.bit_length()) - 1) ``` +#### Java + ```java class Solution { public int findComplement(int num) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -100,12 +106,16 @@ public: }; ``` +#### Go + ```go func findComplement(num int) int { return num ^ ((1 << bits.Len(uint(num))) - 1) } ``` +#### TypeScript + ```ts function findComplement(num: number): number { return num ^ (2 ** num.toString(2).length - 1); diff --git a/solution/0400-0499/0476.Number Complement/README_EN.md b/solution/0400-0499/0476.Number Complement/README_EN.md index acc1a2dcb5733..ea786621d6a48 100644 --- a/solution/0400-0499/0476.Number Complement/README_EN.md +++ b/solution/0400-0499/0476.Number Complement/README_EN.md @@ -71,12 +71,16 @@ The time complexity is $O(\log \text{num})$, where $\text{num}$ is the input int +#### Python3 + ```python class Solution: def findComplement(self, num: int) -> int: return num ^ ((1 << num.bit_length()) - 1) ``` +#### Java + ```java class Solution { public int findComplement(int num) { @@ -85,6 +89,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -94,12 +100,16 @@ public: }; ``` +#### Go + ```go func findComplement(num int) int { return num ^ ((1 << bits.Len(uint(num))) - 1) } ``` +#### TypeScript + ```ts function findComplement(num: number): number { return num ^ (2 ** num.toString(2).length - 1); diff --git a/solution/0400-0499/0477.Total Hamming Distance/README.md b/solution/0400-0499/0477.Total Hamming Distance/README.md index 010f8d541dc41..bc16763c67c0c 100644 --- a/solution/0400-0499/0477.Total Hamming Distance/README.md +++ b/solution/0400-0499/0477.Total Hamming Distance/README.md @@ -65,6 +65,8 @@ HammingDistance(4, 14) + HammingDistance(4, 2) + HammingDistance(14, 2) = 2 + 2 +#### Python3 + ```python class Solution: def totalHammingDistance(self, nums: List[int]) -> int: @@ -76,6 +78,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int totalHammingDistance(int[] nums) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func totalHammingDistance(nums []int) (ans int) { for i := 0; i < 32; i++ { @@ -125,6 +133,8 @@ func totalHammingDistance(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function totalHammingDistance(nums: number[]): number { let ans = 0; @@ -137,6 +147,8 @@ function totalHammingDistance(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn total_hamming_distance(nums: Vec) -> i32 { diff --git a/solution/0400-0499/0477.Total Hamming Distance/README_EN.md b/solution/0400-0499/0477.Total Hamming Distance/README_EN.md index 754d089d3463f..c503707788cfb 100644 --- a/solution/0400-0499/0477.Total Hamming Distance/README_EN.md +++ b/solution/0400-0499/0477.Total Hamming Distance/README_EN.md @@ -64,6 +64,8 @@ The time complexity is $O(n \times \log M)$, where $n$ and $M$ are the length of +#### Python3 + ```python class Solution: def totalHammingDistance(self, nums: List[int]) -> int: @@ -75,6 +77,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int totalHammingDistance(int[] nums) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func totalHammingDistance(nums []int) (ans int) { for i := 0; i < 32; i++ { @@ -124,6 +132,8 @@ func totalHammingDistance(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function totalHammingDistance(nums: number[]): number { let ans = 0; @@ -136,6 +146,8 @@ function totalHammingDistance(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn total_hamming_distance(nums: Vec) -> i32 { diff --git a/solution/0400-0499/0478.Generate Random Point in a Circle/README.md b/solution/0400-0499/0478.Generate Random Point in a Circle/README.md index 347f351c24915..05ef69196b367 100644 --- a/solution/0400-0499/0478.Generate Random Point in a Circle/README.md +++ b/solution/0400-0499/0478.Generate Random Point in a Circle/README.md @@ -63,6 +63,8 @@ solution.randPoint ();//返回[0.36572,0.17248] +#### Python3 + ```python class Solution: def __init__(self, radius: float, x_center: float, y_center: float): diff --git a/solution/0400-0499/0478.Generate Random Point in a Circle/README_EN.md b/solution/0400-0499/0478.Generate Random Point in a Circle/README_EN.md index 4c77454d9cd4b..83c9194055c41 100644 --- a/solution/0400-0499/0478.Generate Random Point in a Circle/README_EN.md +++ b/solution/0400-0499/0478.Generate Random Point in a Circle/README_EN.md @@ -64,6 +64,8 @@ solution.randPoint(); // return [0.36572, 0.17248] +#### Python3 + ```python class Solution: def __init__(self, radius: float, x_center: float, y_center: float): diff --git a/solution/0400-0499/0479.Largest Palindrome Product/README.md b/solution/0400-0499/0479.Largest Palindrome Product/README.md index 98b5176c1aa39..aca1a42d6e3d9 100644 --- a/solution/0400-0499/0479.Largest Palindrome Product/README.md +++ b/solution/0400-0499/0479.Largest Palindrome Product/README.md @@ -53,6 +53,8 @@ tags: +#### Python3 + ```python class Solution: def largestPalindrome(self, n: int) -> int: @@ -70,6 +72,8 @@ class Solution: return 9 ``` +#### Java + ```java class Solution { public int largestPalindrome(int n) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func largestPalindrome(n int) int { mx := int(math.Pow10(n)) - 1 diff --git a/solution/0400-0499/0479.Largest Palindrome Product/README_EN.md b/solution/0400-0499/0479.Largest Palindrome Product/README_EN.md index 0571a5fbdf88e..431eec357327f 100644 --- a/solution/0400-0499/0479.Largest Palindrome Product/README_EN.md +++ b/solution/0400-0499/0479.Largest Palindrome Product/README_EN.md @@ -51,6 +51,8 @@ Explanation: 99 x 91 = 9009, 9009 % 1337 = 987 +#### Python3 + ```python class Solution: def largestPalindrome(self, n: int) -> int: @@ -68,6 +70,8 @@ class Solution: return 9 ``` +#### Java + ```java class Solution { public int largestPalindrome(int n) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func largestPalindrome(n int) int { mx := int(math.Pow10(n)) - 1 diff --git a/solution/0400-0499/0480.Sliding Window Median/README.md b/solution/0400-0499/0480.Sliding Window Median/README.md index 458e81c84ecf0..c20104e9a6835 100644 --- a/solution/0400-0499/0480.Sliding Window Median/README.md +++ b/solution/0400-0499/0480.Sliding Window Median/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class MedianFinder: def __init__(self, k: int): @@ -158,6 +160,8 @@ class Solution: return ans ``` +#### Java + ```java class MedianFinder { private PriorityQueue small = new PriorityQueue<>(Comparator.reverseOrder()); @@ -245,6 +249,8 @@ class Solution { } ``` +#### C++ + ```cpp class MedianFinder { public: @@ -336,6 +342,8 @@ public: }; ``` +#### Go + ```go type MedianFinder struct { small hp diff --git a/solution/0400-0499/0480.Sliding Window Median/README_EN.md b/solution/0400-0499/0480.Sliding Window Median/README_EN.md index f52b860f33864..ccb7d96d9ecc3 100644 --- a/solution/0400-0499/0480.Sliding Window Median/README_EN.md +++ b/solution/0400-0499/0480.Sliding Window Median/README_EN.md @@ -72,6 +72,8 @@ Window position Median +#### Python3 + ```python class MedianFinder: def __init__(self, k: int): @@ -140,6 +142,8 @@ class Solution: return ans ``` +#### Java + ```java class MedianFinder { private PriorityQueue small = new PriorityQueue<>(Comparator.reverseOrder()); @@ -227,6 +231,8 @@ class Solution { } ``` +#### C++ + ```cpp class MedianFinder { public: @@ -318,6 +324,8 @@ public: }; ``` +#### Go + ```go type MedianFinder struct { small hp diff --git a/solution/0400-0499/0481.Magical String/README.md b/solution/0400-0499/0481.Magical String/README.md index 3b2a90b4063c6..fb789de3668b5 100644 --- a/solution/0400-0499/0481.Magical String/README.md +++ b/solution/0400-0499/0481.Magical String/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class Solution: def magicalString(self, n: int) -> int: @@ -108,6 +110,8 @@ class Solution: return s[:n].count(1) ``` +#### Java + ```java class Solution { public int magicalString(int n) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func magicalString(n int) (ans int) { s := []int{1, 2, 2} @@ -166,6 +174,8 @@ func magicalString(n int) (ans int) { } ``` +#### TypeScript + ```ts function magicalString(n: number): number { const cs = [...'1221121']; @@ -182,6 +192,8 @@ function magicalString(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn magical_string(n: i32) -> i32 { diff --git a/solution/0400-0499/0481.Magical String/README_EN.md b/solution/0400-0499/0481.Magical String/README_EN.md index 9e2c8ab634658..e901590d1b25d 100644 --- a/solution/0400-0499/0481.Magical String/README_EN.md +++ b/solution/0400-0499/0481.Magical String/README_EN.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def magicalString(self, n: int) -> int: @@ -74,6 +76,8 @@ class Solution: return s[:n].count(1) ``` +#### Java + ```java class Solution { public int magicalString(int n) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func magicalString(n int) (ans int) { s := []int{1, 2, 2} @@ -132,6 +140,8 @@ func magicalString(n int) (ans int) { } ``` +#### TypeScript + ```ts function magicalString(n: number): number { const cs = [...'1221121']; @@ -148,6 +158,8 @@ function magicalString(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn magical_string(n: i32) -> i32 { diff --git a/solution/0400-0499/0482.License Key Formatting/README.md b/solution/0400-0499/0482.License Key Formatting/README.md index 42008f43dc73f..b1fe1afd64be4 100644 --- a/solution/0400-0499/0482.License Key Formatting/README.md +++ b/solution/0400-0499/0482.License Key Formatting/README.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def licenseKeyFormatting(self, s: str, k: int) -> str: @@ -79,6 +81,8 @@ class Solution: return ''.join(res) ``` +#### Java + ```java class Solution { public String licenseKeyFormatting(String s, int k) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func licenseKeyFormatting(s string, k int) string { s = strings.ReplaceAll(s, "-", "") diff --git a/solution/0400-0499/0482.License Key Formatting/README_EN.md b/solution/0400-0499/0482.License Key Formatting/README_EN.md index c0cb05a26b48c..c8e3938a49aa5 100644 --- a/solution/0400-0499/0482.License Key Formatting/README_EN.md +++ b/solution/0400-0499/0482.License Key Formatting/README_EN.md @@ -59,6 +59,8 @@ Note that the two extra dashes are not needed and can be removed. +#### Python3 + ```python class Solution: def licenseKeyFormatting(self, s: str, k: int) -> str: @@ -77,6 +79,8 @@ class Solution: return ''.join(res) ``` +#### Java + ```java class Solution { public String licenseKeyFormatting(String s, int k) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func licenseKeyFormatting(s string, k int) string { s = strings.ReplaceAll(s, "-", "") diff --git a/solution/0400-0499/0483.Smallest Good Base/README.md b/solution/0400-0499/0483.Smallest Good Base/README.md index 8c7280c4f64d2..d85138b581e43 100644 --- a/solution/0400-0499/0483.Smallest Good Base/README.md +++ b/solution/0400-0499/0483.Smallest Good Base/README.md @@ -175,6 +175,8 @@ $$ +#### Python3 + ```python class Solution: def smallestGoodBase(self, n: str) -> str: @@ -199,6 +201,8 @@ class Solution: return str(num - 1) ``` +#### Java + ```java class Solution { public String smallestGoodBase(String n) { @@ -243,6 +247,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/0400-0499/0483.Smallest Good Base/README_EN.md b/solution/0400-0499/0483.Smallest Good Base/README_EN.md index 2f8b6441c1fce..dce5cf928b26a 100644 --- a/solution/0400-0499/0483.Smallest Good Base/README_EN.md +++ b/solution/0400-0499/0483.Smallest Good Base/README_EN.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def smallestGoodBase(self, n: str) -> str: @@ -88,6 +90,8 @@ class Solution: return str(num - 1) ``` +#### Java + ```java class Solution { public String smallestGoodBase(String n) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/0400-0499/0484.Find Permutation/README.md b/solution/0400-0499/0484.Find Permutation/README.md index 7c5409b5ac142..c6d9b28233bfa 100644 --- a/solution/0400-0499/0484.Find Permutation/README.md +++ b/solution/0400-0499/0484.Find Permutation/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def findPermutation(self, s: str) -> List[int]: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] findPermutation(String s) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func findPermutation(s string) []int { n := len(s) diff --git a/solution/0400-0499/0484.Find Permutation/README_EN.md b/solution/0400-0499/0484.Find Permutation/README_EN.md index 2104212b9cfff..74e07297e9e05 100644 --- a/solution/0400-0499/0484.Find Permutation/README_EN.md +++ b/solution/0400-0499/0484.Find Permutation/README_EN.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def findPermutation(self, s: str) -> List[int]: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] findPermutation(String s) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func findPermutation(s string) []int { n := len(s) diff --git a/solution/0400-0499/0485.Max Consecutive Ones/README.md b/solution/0400-0499/0485.Max Consecutive Ones/README.md index 52ccb450f49a1..4246519b860bc 100644 --- a/solution/0400-0499/0485.Max Consecutive Ones/README.md +++ b/solution/0400-0499/0485.Max Consecutive Ones/README.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python class Solution: def findMaxConsecutiveOnes(self, nums: List[int]) -> int: @@ -71,6 +73,8 @@ class Solution: return max(ans, cnt) ``` +#### Java + ```java class Solution { public int findMaxConsecutiveOnes(int[] nums) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func findMaxConsecutiveOnes(nums []int) int { ans, cnt := 0, 0 @@ -121,6 +129,8 @@ func findMaxConsecutiveOnes(nums []int) int { } ``` +#### TypeScript + ```ts function findMaxConsecutiveOnes(nums: number[]): number { let res = 0; @@ -137,6 +147,8 @@ function findMaxConsecutiveOnes(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_max_consecutive_ones(nums: Vec) -> i32 { @@ -155,6 +167,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -175,6 +189,8 @@ var findMaxConsecutiveOnes = function (nums) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0400-0499/0485.Max Consecutive Ones/README_EN.md b/solution/0400-0499/0485.Max Consecutive Ones/README_EN.md index 1b7d5bda347fd..d40464c7e9a6e 100644 --- a/solution/0400-0499/0485.Max Consecutive Ones/README_EN.md +++ b/solution/0400-0499/0485.Max Consecutive Ones/README_EN.md @@ -52,6 +52,8 @@ tags: +#### Python3 + ```python class Solution: def findMaxConsecutiveOnes(self, nums: List[int]) -> int: @@ -65,6 +67,8 @@ class Solution: return max(ans, cnt) ``` +#### Java + ```java class Solution { public int findMaxConsecutiveOnes(int[] nums) { @@ -82,6 +86,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -100,6 +106,8 @@ public: }; ``` +#### Go + ```go func findMaxConsecutiveOnes(nums []int) int { ans, cnt := 0, 0 @@ -115,6 +123,8 @@ func findMaxConsecutiveOnes(nums []int) int { } ``` +#### TypeScript + ```ts function findMaxConsecutiveOnes(nums: number[]): number { let res = 0; @@ -131,6 +141,8 @@ function findMaxConsecutiveOnes(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_max_consecutive_ones(nums: Vec) -> i32 { @@ -149,6 +161,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -169,6 +183,8 @@ var findMaxConsecutiveOnes = function (nums) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0400-0499/0486.Predict the Winner/README.md b/solution/0400-0499/0486.Predict the Winner/README.md index 2fdc8205af655..c4dac150e8457 100644 --- a/solution/0400-0499/0486.Predict the Winner/README.md +++ b/solution/0400-0499/0486.Predict the Winner/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def PredictTheWinner(self, nums: List[int]) -> bool: @@ -90,6 +92,8 @@ class Solution: return dfs(0, len(nums) - 1) >= 0 ``` +#### Java + ```java class Solution { private int[] nums; @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func PredictTheWinner(nums []int) bool { n := len(nums) @@ -156,6 +164,8 @@ func PredictTheWinner(nums []int) bool { } ``` +#### TypeScript + ```ts function PredictTheWinner(nums: number[]): boolean { const n = nums.length; @@ -173,6 +183,8 @@ function PredictTheWinner(nums: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -231,6 +243,8 @@ impl Solution { +#### Python3 + ```python class Solution: def PredictTheWinner(self, nums: List[int]) -> bool: @@ -244,6 +258,8 @@ class Solution: return f[0][n - 1] >= 0 ``` +#### Java + ```java class Solution { public boolean PredictTheWinner(int[] nums) { @@ -262,6 +278,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -282,6 +300,8 @@ public: }; ``` +#### Go + ```go func PredictTheWinner(nums []int) bool { n := len(nums) @@ -299,6 +319,8 @@ func PredictTheWinner(nums []int) bool { } ``` +#### TypeScript + ```ts function PredictTheWinner(nums: number[]): boolean { const n = nums.length; diff --git a/solution/0400-0499/0486.Predict the Winner/README_EN.md b/solution/0400-0499/0486.Predict the Winner/README_EN.md index 3767be391becd..e0d3fe922375a 100644 --- a/solution/0400-0499/0486.Predict the Winner/README_EN.md +++ b/solution/0400-0499/0486.Predict the Winner/README_EN.md @@ -65,6 +65,8 @@ Finally, player 1 has more score (234) than player 2 (12), so you need to return +#### Python3 + ```python class Solution: def PredictTheWinner(self, nums: List[int]) -> bool: @@ -77,6 +79,8 @@ class Solution: return dfs(0, len(nums) - 1) >= 0 ``` +#### Java + ```java class Solution { private int[] nums; @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func PredictTheWinner(nums []int) bool { n := len(nums) @@ -143,6 +151,8 @@ func PredictTheWinner(nums []int) bool { } ``` +#### TypeScript + ```ts function PredictTheWinner(nums: number[]): boolean { const n = nums.length; @@ -160,6 +170,8 @@ function PredictTheWinner(nums: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -199,6 +211,8 @@ impl Solution { +#### Python3 + ```python class Solution: def PredictTheWinner(self, nums: List[int]) -> bool: @@ -212,6 +226,8 @@ class Solution: return f[0][n - 1] >= 0 ``` +#### Java + ```java class Solution { public boolean PredictTheWinner(int[] nums) { @@ -230,6 +246,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -250,6 +268,8 @@ public: }; ``` +#### Go + ```go func PredictTheWinner(nums []int) bool { n := len(nums) @@ -267,6 +287,8 @@ func PredictTheWinner(nums []int) bool { } ``` +#### TypeScript + ```ts function PredictTheWinner(nums: number[]): boolean { const n = nums.length; diff --git a/solution/0400-0499/0487.Max Consecutive Ones II/README.md b/solution/0400-0499/0487.Max Consecutive Ones II/README.md index 06fb54f5a4346..acefa23ae20ff 100644 --- a/solution/0400-0499/0487.Max Consecutive Ones II/README.md +++ b/solution/0400-0499/0487.Max Consecutive Ones II/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def findMaxConsecutiveOnes(self, nums: List[int]) -> int: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findMaxConsecutiveOnes(int[] nums) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func findMaxConsecutiveOnes(nums []int) int { n := len(nums) @@ -224,6 +232,8 @@ func findMaxConsecutiveOnes(nums []int) int { +#### Python3 + ```python class Solution: def findMaxConsecutiveOnes(self, nums: List[int]) -> int: @@ -240,6 +250,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findMaxConsecutiveOnes(int[] nums) { @@ -261,6 +273,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -283,6 +297,8 @@ public: }; ``` +#### Go + ```go func findMaxConsecutiveOnes(nums []int) int { ans := 1 @@ -313,6 +329,8 @@ func findMaxConsecutiveOnes(nums []int) int { +#### Python3 + ```python class Solution: def findMaxConsecutiveOnes(self, nums: List[int]) -> int: @@ -329,6 +347,8 @@ class Solution: return r - l ``` +#### Java + ```java class Solution { public int findMaxConsecutiveOnes(int[] nums) { @@ -347,6 +367,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -366,6 +388,8 @@ public: }; ``` +#### Go + ```go func findMaxConsecutiveOnes(nums []int) int { l, r := 0, 0 diff --git a/solution/0400-0499/0487.Max Consecutive Ones II/README_EN.md b/solution/0400-0499/0487.Max Consecutive Ones II/README_EN.md index 3f27e1fbeb72a..7d66452586c03 100644 --- a/solution/0400-0499/0487.Max Consecutive Ones II/README_EN.md +++ b/solution/0400-0499/0487.Max Consecutive Ones II/README_EN.md @@ -64,6 +64,8 @@ The max number of consecutive ones is 4. +#### Python3 + ```python class Solution: def findMaxConsecutiveOnes(self, nums: List[int]) -> int: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findMaxConsecutiveOnes(int[] nums) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func findMaxConsecutiveOnes(nums []int) int { n := len(nums) @@ -201,6 +209,8 @@ func findMaxConsecutiveOnes(nums []int) int { +#### Python3 + ```python class Solution: def findMaxConsecutiveOnes(self, nums: List[int]) -> int: @@ -217,6 +227,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findMaxConsecutiveOnes(int[] nums) { @@ -238,6 +250,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -260,6 +274,8 @@ public: }; ``` +#### Go + ```go func findMaxConsecutiveOnes(nums []int) int { ans := 1 @@ -290,6 +306,8 @@ func findMaxConsecutiveOnes(nums []int) int { +#### Python3 + ```python class Solution: def findMaxConsecutiveOnes(self, nums: List[int]) -> int: @@ -306,6 +324,8 @@ class Solution: return r - l ``` +#### Java + ```java class Solution { public int findMaxConsecutiveOnes(int[] nums) { @@ -324,6 +344,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -343,6 +365,8 @@ public: }; ``` +#### Go + ```go func findMaxConsecutiveOnes(nums []int) int { l, r := 0, 0 diff --git a/solution/0400-0499/0488.Zuma Game/README.md b/solution/0400-0499/0488.Zuma Game/README.md index 40c16f5c51628..b7060b371e083 100644 --- a/solution/0400-0499/0488.Zuma Game/README.md +++ b/solution/0400-0499/0488.Zuma Game/README.md @@ -106,6 +106,8 @@ tags: +#### Python3 + ```python class Solution: def findMinStep(self, board: str, hand: str) -> int: @@ -134,6 +136,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int findMinStep(String board, String hand) { diff --git a/solution/0400-0499/0488.Zuma Game/README_EN.md b/solution/0400-0499/0488.Zuma Game/README_EN.md index 92a6f443203ab..7a827b31a3f0e 100644 --- a/solution/0400-0499/0488.Zuma Game/README_EN.md +++ b/solution/0400-0499/0488.Zuma Game/README_EN.md @@ -92,6 +92,8 @@ There are still balls remaining on the board, and you are out of balls to insert +#### Python3 + ```python class Solution: def findMinStep(self, board: str, hand: str) -> int: @@ -120,6 +122,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int findMinStep(String board, String hand) { diff --git a/solution/0400-0499/0489.Robot Room Cleaner/README.md b/solution/0400-0499/0489.Robot Room Cleaner/README.md index fe8b4fd1a2aa4..21fd350602fde 100644 --- a/solution/0400-0499/0489.Robot Room Cleaner/README.md +++ b/solution/0400-0499/0489.Robot Room Cleaner/README.md @@ -105,6 +105,8 @@ interface Robot { +#### Python3 + ```python # """ # This is the robot's control interface. @@ -166,6 +168,8 @@ class Solution: dfs(0, 0, 0) ``` +#### Java + ```java /** * // This is the robot's control interface. @@ -215,6 +219,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * // This is the robot's control interface. @@ -262,6 +268,8 @@ public: }; ``` +#### Go + ```go /** * // This is the robot's control interface. @@ -307,6 +315,8 @@ func cleanRoom(robot *Robot) { } ``` +#### TypeScript + ```ts /** * class Robot { diff --git a/solution/0400-0499/0489.Robot Room Cleaner/README_EN.md b/solution/0400-0499/0489.Robot Room Cleaner/README_EN.md index 0ef8ac85d7d30..f4a717f5fdd7c 100644 --- a/solution/0400-0499/0489.Robot Room Cleaner/README_EN.md +++ b/solution/0400-0499/0489.Robot Room Cleaner/README_EN.md @@ -95,6 +95,8 @@ From the top left corner, its position is one row below and three columns right. +#### Python3 + ```python # """ # This is the robot's control interface. @@ -156,6 +158,8 @@ class Solution: dfs(0, 0, 0) ``` +#### Java + ```java /** * // This is the robot's control interface. @@ -205,6 +209,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * // This is the robot's control interface. @@ -252,6 +258,8 @@ public: }; ``` +#### Go + ```go /** * // This is the robot's control interface. @@ -297,6 +305,8 @@ func cleanRoom(robot *Robot) { } ``` +#### TypeScript + ```ts /** * class Robot { diff --git a/solution/0400-0499/0490.The Maze/README.md b/solution/0400-0499/0490.The Maze/README.md index 739cf8c3a0178..982e0298eb0c6 100644 --- a/solution/0400-0499/0490.The Maze/README.md +++ b/solution/0400-0499/0490.The Maze/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def hasPath( @@ -106,6 +108,8 @@ class Solution: return vis[destination[0]][destination[1]] ``` +#### Java + ```java class Solution { private boolean[][] vis; @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -183,6 +189,8 @@ public: }; ``` +#### Go + ```go func hasPath(maze [][]int, start []int, destination []int) bool { m, n := len(maze), len(maze[0]) @@ -225,6 +233,8 @@ func hasPath(maze [][]int, start []int, destination []int) bool { +#### Python3 + ```python class Solution: def hasPath( @@ -248,6 +258,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean hasPath(int[][] maze, int[] start, int[] destination) { @@ -283,6 +295,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -316,6 +330,8 @@ public: }; ``` +#### Go + ```go func hasPath(maze [][]int, start []int, destination []int) bool { m, n := len(maze), len(maze[0]) diff --git a/solution/0400-0499/0490.The Maze/README_EN.md b/solution/0400-0499/0490.The Maze/README_EN.md index d2d3ae22f6282..856f07c599629 100644 --- a/solution/0400-0499/0490.The Maze/README_EN.md +++ b/solution/0400-0499/0490.The Maze/README_EN.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def hasPath( @@ -98,6 +100,8 @@ class Solution: return vis[destination[0]][destination[1]] ``` +#### Java + ```java class Solution { private boolean[][] vis; @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go func hasPath(maze [][]int, start []int, destination []int) bool { m, n := len(maze), len(maze[0]) @@ -217,6 +225,8 @@ func hasPath(maze [][]int, start []int, destination []int) bool { +#### Python3 + ```python class Solution: def hasPath( @@ -240,6 +250,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean hasPath(int[][] maze, int[] start, int[] destination) { @@ -275,6 +287,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -308,6 +322,8 @@ public: }; ``` +#### Go + ```go func hasPath(maze [][]int, start []int, destination []int) bool { m, n := len(maze), len(maze[0]) diff --git a/solution/0400-0499/0491.Non-decreasing Subsequences/README.md b/solution/0400-0499/0491.Non-decreasing Subsequences/README.md index 04890f15fecb4..7af1d627a2f4e 100644 --- a/solution/0400-0499/0491.Non-decreasing Subsequences/README.md +++ b/solution/0400-0499/0491.Non-decreasing Subsequences/README.md @@ -63,6 +63,8 @@ DFS 递归枚举每个数字选中或不选中,这里需要满足两个条件 +#### Python3 + ```python class Solution: def findSubsequences(self, nums: List[int]) -> List[List[int]]: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] nums; @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func findSubsequences(nums []int) [][]int { var ans [][]int diff --git a/solution/0400-0499/0491.Non-decreasing Subsequences/README_EN.md b/solution/0400-0499/0491.Non-decreasing Subsequences/README_EN.md index d57646460de12..f39288f1ca4fd 100644 --- a/solution/0400-0499/0491.Non-decreasing Subsequences/README_EN.md +++ b/solution/0400-0499/0491.Non-decreasing Subsequences/README_EN.md @@ -54,6 +54,8 @@ tags: +#### Python3 + ```python class Solution: def findSubsequences(self, nums: List[int]) -> List[List[int]]: @@ -74,6 +76,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] nums; @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func findSubsequences(nums []int) [][]int { var ans [][]int diff --git a/solution/0400-0499/0492.Construct the Rectangle/README.md b/solution/0400-0499/0492.Construct the Rectangle/README.md index c0bd906845ec6..e06078df3dc8f 100644 --- a/solution/0400-0499/0492.Construct the Rectangle/README.md +++ b/solution/0400-0499/0492.Construct the Rectangle/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def constructRectangle(self, area: int) -> List[int]: @@ -77,6 +79,8 @@ class Solution: return [area // w, w] ``` +#### Java + ```java class Solution { public int[] constructRectangle(int area) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -100,6 +106,8 @@ public: }; ``` +#### Go + ```go func constructRectangle(area int) []int { w := int(math.Sqrt(float64(area))) diff --git a/solution/0400-0499/0492.Construct the Rectangle/README_EN.md b/solution/0400-0499/0492.Construct the Rectangle/README_EN.md index 7920e37adb0c3..98f61cdff5d0d 100644 --- a/solution/0400-0499/0492.Construct the Rectangle/README_EN.md +++ b/solution/0400-0499/0492.Construct the Rectangle/README_EN.md @@ -67,6 +67,8 @@ But according to requirement 2, [1,4] is illegal; according to requirement 3, [ +#### Python3 + ```python class Solution: def constructRectangle(self, area: int) -> List[int]: @@ -76,6 +78,8 @@ class Solution: return [area // w, w] ``` +#### Java + ```java class Solution { public int[] constructRectangle(int area) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -99,6 +105,8 @@ public: }; ``` +#### Go + ```go func constructRectangle(area int) []int { w := int(math.Sqrt(float64(area))) diff --git a/solution/0400-0499/0493.Reverse Pairs/README.md b/solution/0400-0499/0493.Reverse Pairs/README.md index 117ff49473acf..5c375c0f84d38 100644 --- a/solution/0400-0499/0493.Reverse Pairs/README.md +++ b/solution/0400-0499/0493.Reverse Pairs/README.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def reversePairs(self, nums: List[int]) -> int: @@ -93,6 +95,8 @@ class Solution: return merge_sort(0, len(nums) - 1) ``` +#### Java + ```java class Solution { private int[] nums; @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -189,6 +195,8 @@ public: }; ``` +#### Go + ```go func reversePairs(nums []int) int { n := len(nums) @@ -257,6 +265,8 @@ func reversePairs(nums []int) int { +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -296,6 +306,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int reversePairs(int[] nums) { @@ -351,6 +363,8 @@ class BinaryIndexedTree { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -404,6 +418,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -477,6 +493,8 @@ func reversePairs(nums []int) int { +#### Python3 + ```python class Node: def __init__(self): @@ -542,6 +560,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int reversePairs(int[] nums) { @@ -629,6 +649,8 @@ class SegmentTree { } ``` +#### C++ + ```cpp class Node { public: diff --git a/solution/0400-0499/0493.Reverse Pairs/README_EN.md b/solution/0400-0499/0493.Reverse Pairs/README_EN.md index fa1803e78081c..ca350b514e834 100644 --- a/solution/0400-0499/0493.Reverse Pairs/README_EN.md +++ b/solution/0400-0499/0493.Reverse Pairs/README_EN.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def reversePairs(self, nums: List[int]) -> int: @@ -103,6 +105,8 @@ class Solution: return merge_sort(0, len(nums) - 1) ``` +#### Java + ```java class Solution { private int[] nums; @@ -153,6 +157,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -199,6 +205,8 @@ public: }; ``` +#### Go + ```go func reversePairs(nums []int) int { n := len(nums) @@ -254,6 +262,8 @@ func reversePairs(nums []int) int { +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -293,6 +303,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int reversePairs(int[] nums) { @@ -348,6 +360,8 @@ class BinaryIndexedTree { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -401,6 +415,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -467,6 +483,8 @@ func reversePairs(nums []int) int { +#### Python3 + ```python class Node: def __init__(self): @@ -532,6 +550,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int reversePairs(int[] nums) { @@ -619,6 +639,8 @@ class SegmentTree { } ``` +#### C++ + ```cpp class Node { public: diff --git a/solution/0400-0499/0494.Target Sum/README.md b/solution/0400-0499/0494.Target Sum/README.md index aaad73c8edee8..2d1ae7f9d5841 100644 --- a/solution/0400-0499/0494.Target Sum/README.md +++ b/solution/0400-0499/0494.Target Sum/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def findTargetSumWays(self, nums: List[int], target: int) -> int: @@ -94,6 +96,8 @@ class Solution: return dp[-1][-1] ``` +#### Java + ```java class Solution { public int findTargetSumWays(int[] nums, int target) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func findTargetSumWays(nums []int, target int) int { s := 0 @@ -168,6 +176,8 @@ func findTargetSumWays(nums []int, target int) int { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -207,6 +217,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -244,6 +256,8 @@ var findTargetSumWays = function (nums, target) { +#### Python3 + ```python class Solution: def findTargetSumWays(self, nums: List[int], target: int) -> int: @@ -259,6 +273,8 @@ class Solution: return dp[-1] ``` +#### Java + ```java class Solution { public int findTargetSumWays(int[] nums, int target) { @@ -282,6 +298,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -299,6 +317,8 @@ public: }; ``` +#### Go + ```go func findTargetSumWays(nums []int, target int) int { s := 0 @@ -320,6 +340,8 @@ func findTargetSumWays(nums []int, target int) int { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -362,6 +384,8 @@ impl Solution { +#### Python3 + ```python class Solution: def findTargetSumWays(self, nums: List[int], target: int) -> int: diff --git a/solution/0400-0499/0494.Target Sum/README_EN.md b/solution/0400-0499/0494.Target Sum/README_EN.md index 3033d3df07281..4ebe6d0754338 100644 --- a/solution/0400-0499/0494.Target Sum/README_EN.md +++ b/solution/0400-0499/0494.Target Sum/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def findTargetSumWays(self, nums: List[int], target: int) -> int: @@ -86,6 +88,8 @@ class Solution: return dp[-1][-1] ``` +#### Java + ```java class Solution { public int findTargetSumWays(int[] nums, int target) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func findTargetSumWays(nums []int, target int) int { s := 0 @@ -160,6 +168,8 @@ func findTargetSumWays(nums []int, target int) int { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -199,6 +209,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -236,6 +248,8 @@ var findTargetSumWays = function (nums, target) { +#### Python3 + ```python class Solution: def findTargetSumWays(self, nums: List[int], target: int) -> int: @@ -251,6 +265,8 @@ class Solution: return dp[-1] ``` +#### Java + ```java class Solution { public int findTargetSumWays(int[] nums, int target) { @@ -274,6 +290,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -291,6 +309,8 @@ public: }; ``` +#### Go + ```go func findTargetSumWays(nums []int, target int) int { s := 0 @@ -312,6 +332,8 @@ func findTargetSumWays(nums []int, target int) int { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -354,6 +376,8 @@ impl Solution { +#### Python3 + ```python class Solution: def findTargetSumWays(self, nums: List[int], target: int) -> int: diff --git a/solution/0400-0499/0495.Teemo Attacking/README.md b/solution/0400-0499/0495.Teemo Attacking/README.md index 3898e31f059fe..7f352aa5314a5 100644 --- a/solution/0400-0499/0495.Teemo Attacking/README.md +++ b/solution/0400-0499/0495.Teemo Attacking/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def findPoisonedDuration(self, timeSeries: List[int], duration: int) -> int: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findPoisonedDuration(int[] timeSeries, int duration) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func findPoisonedDuration(timeSeries []int, duration int) (ans int) { ans = duration @@ -121,6 +129,8 @@ func findPoisonedDuration(timeSeries []int, duration int) (ans int) { } ``` +#### TypeScript + ```ts function findPoisonedDuration(timeSeries: number[], duration: number): number { const n = timeSeries.length; @@ -132,6 +142,8 @@ function findPoisonedDuration(timeSeries: number[], duration: number): number { } ``` +#### C# + ```cs public class Solution { public int FindPoisonedDuration(int[] timeSeries, int duration) { diff --git a/solution/0400-0499/0495.Teemo Attacking/README_EN.md b/solution/0400-0499/0495.Teemo Attacking/README_EN.md index 07df4457c2558..bc71b544a3e79 100644 --- a/solution/0400-0499/0495.Teemo Attacking/README_EN.md +++ b/solution/0400-0499/0495.Teemo Attacking/README_EN.md @@ -64,6 +64,8 @@ Ashe is poisoned for seconds 1, 2, and 3, which is 3 seconds in total. +#### Python3 + ```python class Solution: def findPoisonedDuration(self, timeSeries: List[int], duration: int) -> int: @@ -73,6 +75,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findPoisonedDuration(int[] timeSeries, int duration) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -100,6 +106,8 @@ public: }; ``` +#### Go + ```go func findPoisonedDuration(timeSeries []int, duration int) (ans int) { ans = duration @@ -110,6 +118,8 @@ func findPoisonedDuration(timeSeries []int, duration int) (ans int) { } ``` +#### TypeScript + ```ts function findPoisonedDuration(timeSeries: number[], duration: number): number { const n = timeSeries.length; @@ -121,6 +131,8 @@ function findPoisonedDuration(timeSeries: number[], duration: number): number { } ``` +#### C# + ```cs public class Solution { public int FindPoisonedDuration(int[] timeSeries, int duration) { diff --git a/solution/0400-0499/0496.Next Greater Element I/README.md b/solution/0400-0499/0496.Next Greater Element I/README.md index f49e12a1446a0..88ce5651baae0 100644 --- a/solution/0400-0499/0496.Next Greater Element I/README.md +++ b/solution/0400-0499/0496.Next Greater Element I/README.md @@ -88,6 +88,8 @@ for i in range(n): +#### Python3 + ```python class Solution: def nextGreaterElement(self, nums1: List[int], nums2: List[int]) -> List[int]: @@ -100,6 +102,8 @@ class Solution: return [m.get(v, -1) for v in nums1] ``` +#### Java + ```java class Solution { public int[] nextGreaterElement(int[] nums1, int[] nums2) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func nextGreaterElement(nums1 []int, nums2 []int) []int { stk := []int{} @@ -164,6 +172,8 @@ func nextGreaterElement(nums1 []int, nums2 []int) []int { } ``` +#### TypeScript + ```ts function nextGreaterElement(nums1: number[], nums2: number[]): number[] { const map = new Map(); @@ -178,6 +188,8 @@ function nextGreaterElement(nums1: number[], nums2: number[]): number[] { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -199,6 +211,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums1 @@ -228,6 +242,8 @@ var nextGreaterElement = function (nums1, nums2) { +#### Python3 + ```python class Solution: def nextGreaterElement(self, nums1: List[int], nums2: List[int]) -> List[int]: @@ -242,6 +258,8 @@ class Solution: return [m.get(x, -1) for x in nums1] ``` +#### Java + ```java class Solution { public int[] nextGreaterElement(int[] nums1, int[] nums2) { @@ -266,6 +284,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -284,6 +304,8 @@ public: }; ``` +#### Go + ```go func nextGreaterElement(nums1 []int, nums2 []int) []int { stk := []int{} @@ -309,6 +331,8 @@ func nextGreaterElement(nums1 []int, nums2 []int) []int { } ``` +#### Rust + ```rust impl Solution { pub fn next_greater_element(nums1: Vec, nums2: Vec) -> Vec { @@ -331,6 +355,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums1 diff --git a/solution/0400-0499/0496.Next Greater Element I/README_EN.md b/solution/0400-0499/0496.Next Greater Element I/README_EN.md index 0b83d4094f244..13c6f1706675b 100644 --- a/solution/0400-0499/0496.Next Greater Element I/README_EN.md +++ b/solution/0400-0499/0496.Next Greater Element I/README_EN.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def nextGreaterElement(self, nums1: List[int], nums2: List[int]) -> List[int]: @@ -84,6 +86,8 @@ class Solution: return [m.get(v, -1) for v in nums1] ``` +#### Java + ```java class Solution { public int[] nextGreaterElement(int[] nums1, int[] nums2) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func nextGreaterElement(nums1 []int, nums2 []int) []int { stk := []int{} @@ -148,6 +156,8 @@ func nextGreaterElement(nums1 []int, nums2 []int) []int { } ``` +#### TypeScript + ```ts function nextGreaterElement(nums1: number[], nums2: number[]): number[] { const map = new Map(); @@ -162,6 +172,8 @@ function nextGreaterElement(nums1: number[], nums2: number[]): number[] { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -183,6 +195,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums1 @@ -212,6 +226,8 @@ var nextGreaterElement = function (nums1, nums2) { +#### Python3 + ```python class Solution: def nextGreaterElement(self, nums1: List[int], nums2: List[int]) -> List[int]: @@ -226,6 +242,8 @@ class Solution: return [m.get(x, -1) for x in nums1] ``` +#### Java + ```java class Solution { public int[] nextGreaterElement(int[] nums1, int[] nums2) { @@ -250,6 +268,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -268,6 +288,8 @@ public: }; ``` +#### Go + ```go func nextGreaterElement(nums1 []int, nums2 []int) []int { stk := []int{} @@ -293,6 +315,8 @@ func nextGreaterElement(nums1 []int, nums2 []int) []int { } ``` +#### Rust + ```rust impl Solution { pub fn next_greater_element(nums1: Vec, nums2: Vec) -> Vec { @@ -315,6 +339,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums1 diff --git a/solution/0400-0499/0497.Random Point in Non-overlapping Rectangles/README.md b/solution/0400-0499/0497.Random Point in Non-overlapping Rectangles/README.md index 7d78a3e09f047..9511088fae34e 100644 --- a/solution/0400-0499/0497.Random Point in Non-overlapping Rectangles/README.md +++ b/solution/0400-0499/0497.Random Point in Non-overlapping Rectangles/README.md @@ -86,6 +86,8 @@ solution.pick(); // 返回 [0, 0] +#### Python3 + ```python class Solution: def __init__(self, rects: List[List[int]]): @@ -106,6 +108,8 @@ class Solution: # param_1 = obj.pick() ``` +#### Java + ```java class Solution { private int[] s; @@ -146,6 +150,8 @@ class Solution { */ ``` +#### C++ + ```cpp class Solution { public: @@ -178,6 +184,8 @@ public: */ ``` +#### Go + ```go type Solution struct { s []int diff --git a/solution/0400-0499/0497.Random Point in Non-overlapping Rectangles/README_EN.md b/solution/0400-0499/0497.Random Point in Non-overlapping Rectangles/README_EN.md index fa4fb2942193e..dc0593697d299 100644 --- a/solution/0400-0499/0497.Random Point in Non-overlapping Rectangles/README_EN.md +++ b/solution/0400-0499/0497.Random Point in Non-overlapping Rectangles/README_EN.md @@ -79,6 +79,8 @@ solution.pick(); // return [0, 0] +#### Python3 + ```python class Solution: def __init__(self, rects: List[List[int]]): @@ -99,6 +101,8 @@ class Solution: # param_1 = obj.pick() ``` +#### Java + ```java class Solution { private int[] s; @@ -139,6 +143,8 @@ class Solution { */ ``` +#### C++ + ```cpp class Solution { public: @@ -171,6 +177,8 @@ public: */ ``` +#### Go + ```go type Solution struct { s []int diff --git a/solution/0400-0499/0498.Diagonal Traverse/README.md b/solution/0400-0499/0498.Diagonal Traverse/README.md index d09f4bdad3bf7..128a2b752bccf 100644 --- a/solution/0400-0499/0498.Diagonal Traverse/README.md +++ b/solution/0400-0499/0498.Diagonal Traverse/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def findDiagonalOrder(self, mat: List[List[int]]) -> List[int]: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] findDiagonalOrder(int[][] mat) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func findDiagonalOrder(mat [][]int) []int { m, n := len(mat), len(mat[0]) @@ -162,6 +170,8 @@ func findDiagonalOrder(mat [][]int) []int { } ``` +#### TypeScript + ```ts function findDiagonalOrder(mat: number[][]): number[] { const res = []; @@ -200,6 +210,8 @@ function findDiagonalOrder(mat: number[][]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn find_diagonal_order(mat: Vec>) -> Vec { diff --git a/solution/0400-0499/0498.Diagonal Traverse/README_EN.md b/solution/0400-0499/0498.Diagonal Traverse/README_EN.md index f3d078838df50..1621a1184a63e 100644 --- a/solution/0400-0499/0498.Diagonal Traverse/README_EN.md +++ b/solution/0400-0499/0498.Diagonal Traverse/README_EN.md @@ -56,6 +56,8 @@ tags: +#### Python3 + ```python class Solution: def findDiagonalOrder(self, mat: List[List[int]]) -> List[int]: @@ -75,6 +77,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] findDiagonalOrder(int[][] mat) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func findDiagonalOrder(mat [][]int) []int { m, n := len(mat), len(mat[0]) @@ -154,6 +162,8 @@ func findDiagonalOrder(mat [][]int) []int { } ``` +#### TypeScript + ```ts function findDiagonalOrder(mat: number[][]): number[] { const res = []; @@ -192,6 +202,8 @@ function findDiagonalOrder(mat: number[][]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn find_diagonal_order(mat: Vec>) -> Vec { diff --git a/solution/0400-0499/0499.The Maze III/README.md b/solution/0400-0499/0499.The Maze III/README.md index e6d20ee44f9b2..65546e7027af0 100644 --- a/solution/0400-0499/0499.The Maze III/README.md +++ b/solution/0400-0499/0499.The Maze III/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def findShortestWay( @@ -128,6 +130,8 @@ class Solution: return path[rh][ch] or 'impossible' ``` +#### Java + ```java class Solution { public String findShortestWay(int[][] maze, int[] ball, int[] hole) { @@ -174,6 +178,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -214,6 +220,8 @@ public: }; ``` +#### Go + ```go import "math" diff --git a/solution/0400-0499/0499.The Maze III/README_EN.md b/solution/0400-0499/0499.The Maze III/README_EN.md index 9a064b440153b..b1f7423cdc14e 100644 --- a/solution/0400-0499/0499.The Maze III/README_EN.md +++ b/solution/0400-0499/0499.The Maze III/README_EN.md @@ -86,6 +86,8 @@ Both ways have shortest distance 6, but the first way is lexicographically small +#### Python3 + ```python class Solution: def findShortestWay( @@ -121,6 +123,8 @@ class Solution: return path[rh][ch] or 'impossible' ``` +#### Java + ```java class Solution { public String findShortestWay(int[][] maze, int[] ball, int[] hole) { @@ -167,6 +171,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -207,6 +213,8 @@ public: }; ``` +#### Go + ```go import "math" diff --git a/solution/0500-0599/0500.Keyboard Row/README.md b/solution/0500-0599/0500.Keyboard Row/README.md index 84c7d7f83acb4..d8b6ea018687d 100644 --- a/solution/0500-0599/0500.Keyboard Row/README.md +++ b/solution/0500-0599/0500.Keyboard Row/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def findWords(self, words: List[str]) -> List[str]: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String[] findWords(String[] words) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func findWords(words []string) (ans []string) { s := "12210111011122000010020202" @@ -159,6 +167,8 @@ func findWords(words []string) (ans []string) { } ``` +#### TypeScript + ```ts function findWords(words: string[]): string[] { const s = '12210111011122000010020202'; @@ -181,6 +191,8 @@ function findWords(words: string[]): string[] { } ``` +#### C# + ```cs public class Solution { public string[] FindWords(string[] words) { @@ -214,6 +226,8 @@ public class Solution { +#### Python3 + ```python class Solution: def findWords(self, words: List[str]) -> List[str]: diff --git a/solution/0500-0599/0500.Keyboard Row/README_EN.md b/solution/0500-0599/0500.Keyboard Row/README_EN.md index fd3325c130d7f..2053e2602ab8e 100644 --- a/solution/0500-0599/0500.Keyboard Row/README_EN.md +++ b/solution/0500-0599/0500.Keyboard Row/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def findWords(self, words: List[str]) -> List[str]: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String[] findWords(String[] words) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func findWords(words []string) (ans []string) { s := "12210111011122000010020202" @@ -151,6 +159,8 @@ func findWords(words []string) (ans []string) { } ``` +#### TypeScript + ```ts function findWords(words: string[]): string[] { const s = '12210111011122000010020202'; @@ -173,6 +183,8 @@ function findWords(words: string[]): string[] { } ``` +#### C# + ```cs public class Solution { public string[] FindWords(string[] words) { @@ -206,6 +218,8 @@ public class Solution { +#### Python3 + ```python class Solution: def findWords(self, words: List[str]) -> List[str]: diff --git a/solution/0500-0599/0501.Find Mode in Binary Search Tree/README.md b/solution/0500-0599/0501.Find Mode in Binary Search Tree/README.md index ea506fd4a6fbf..86dfa37ca211c 100644 --- a/solution/0500-0599/0501.Find Mode in Binary Search Tree/README.md +++ b/solution/0500-0599/0501.Find Mode in Binary Search Tree/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -189,6 +195,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -227,6 +235,8 @@ func findMode(root *TreeNode) []int { } ``` +#### C# + ```cs public class Solution { private int mx; diff --git a/solution/0500-0599/0501.Find Mode in Binary Search Tree/README_EN.md b/solution/0500-0599/0501.Find Mode in Binary Search Tree/README_EN.md index 39b173acb1645..2a775e97894a4 100644 --- a/solution/0500-0599/0501.Find Mode in Binary Search Tree/README_EN.md +++ b/solution/0500-0599/0501.Find Mode in Binary Search Tree/README_EN.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -147,6 +151,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -224,6 +232,8 @@ func findMode(root *TreeNode) []int { } ``` +#### C# + ```cs public class Solution { private int mx; diff --git a/solution/0500-0599/0502.IPO/README.md b/solution/0500-0599/0502.IPO/README.md index f9a84164231ad..5b4803ec7ad46 100644 --- a/solution/0500-0599/0502.IPO/README.md +++ b/solution/0500-0599/0502.IPO/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def findMaximizedCapital( @@ -97,6 +99,8 @@ class Solution: return w ``` +#### Java + ```java class Solution { public int findMaximizedCapital(int k, int w, int[] profits, int[] capital) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp using pii = pair; @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func findMaximizedCapital(k int, w int, profits []int, capital []int) int { q1 := hp2{} diff --git a/solution/0500-0599/0502.IPO/README_EN.md b/solution/0500-0599/0502.IPO/README_EN.md index f6f2d8fd4f977..1c72a1323c5b3 100644 --- a/solution/0500-0599/0502.IPO/README_EN.md +++ b/solution/0500-0599/0502.IPO/README_EN.md @@ -72,6 +72,8 @@ Therefore, output the final maximized capital, which is 0 + 1 + 3 = 4. +#### Python3 + ```python class Solution: def findMaximizedCapital( @@ -90,6 +92,8 @@ class Solution: return w ``` +#### Java + ```java class Solution { public int findMaximizedCapital(int k, int w, int[] profits, int[] capital) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp using pii = pair; @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func findMaximizedCapital(k int, w int, profits []int, capital []int) int { q1 := hp2{} diff --git a/solution/0500-0599/0503.Next Greater Element II/README.md b/solution/0500-0599/0503.Next Greater Element II/README.md index 0a614beda3630..e507faa0ee70f 100644 --- a/solution/0500-0599/0503.Next Greater Element II/README.md +++ b/solution/0500-0599/0503.Next Greater Element II/README.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def nextGreaterElements(self, nums: List[int]) -> List[int]: @@ -73,6 +75,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] nextGreaterElements(int[] nums) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func nextGreaterElements(nums []int) []int { n := len(nums) @@ -129,6 +137,8 @@ func nextGreaterElements(nums []int) []int { } ``` +#### TypeScript + ```ts function nextGreaterElements(nums: number[]): number[] { const stack: number[] = [], @@ -146,6 +156,8 @@ function nextGreaterElements(nums: number[]): number[] { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -176,6 +188,8 @@ var nextGreaterElements = function (nums) { +#### Python3 + ```python class Solution: def nextGreaterElements(self, nums: List[int]) -> List[int]: @@ -192,6 +206,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] nextGreaterElements(int[] nums) { @@ -214,6 +230,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -232,6 +250,8 @@ public: }; ``` +#### Go + ```go func nextGreaterElements(nums []int) []int { n := len(nums) @@ -254,6 +274,8 @@ func nextGreaterElements(nums []int) []int { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0500-0599/0503.Next Greater Element II/README_EN.md b/solution/0500-0599/0503.Next Greater Element II/README_EN.md index 52d3f83f1e5ea..e54488003551a 100644 --- a/solution/0500-0599/0503.Next Greater Element II/README_EN.md +++ b/solution/0500-0599/0503.Next Greater Element II/README_EN.md @@ -58,6 +58,8 @@ The second 1's next greater number needs to search circularly, which is also +#### Python3 + ```python class Solution: def nextGreaterElements(self, nums: List[int]) -> List[int]: @@ -71,6 +73,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] nextGreaterElements(int[] nums) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func nextGreaterElements(nums []int) []int { n := len(nums) @@ -127,6 +135,8 @@ func nextGreaterElements(nums []int) []int { } ``` +#### TypeScript + ```ts function nextGreaterElements(nums: number[]): number[] { const stack: number[] = [], @@ -144,6 +154,8 @@ function nextGreaterElements(nums: number[]): number[] { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -174,6 +186,8 @@ var nextGreaterElements = function (nums) { +#### Python3 + ```python class Solution: def nextGreaterElements(self, nums: List[int]) -> List[int]: @@ -190,6 +204,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] nextGreaterElements(int[] nums) { @@ -212,6 +228,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -230,6 +248,8 @@ public: }; ``` +#### Go + ```go func nextGreaterElements(nums []int) []int { n := len(nums) @@ -252,6 +272,8 @@ func nextGreaterElements(nums []int) []int { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0500-0599/0504.Base 7/README.md b/solution/0500-0599/0504.Base 7/README.md index 572da0c5ab048..1e955a5f67ddb 100644 --- a/solution/0500-0599/0504.Base 7/README.md +++ b/solution/0500-0599/0504.Base 7/README.md @@ -56,6 +56,8 @@ tags: +#### Python3 + ```python class Solution: def convertToBase7(self, num: int) -> str: @@ -70,6 +72,8 @@ class Solution: return ''.join(ans[::-1]) ``` +#### Java + ```java class Solution { public String convertToBase7(int num) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func convertToBase7(num int) string { if num == 0 { @@ -122,6 +130,8 @@ func convertToBase7(num int) string { } ``` +#### TypeScript + ```ts function convertToBase7(num: number): string { if (num == 0) { @@ -141,6 +151,8 @@ function convertToBase7(num: number): string { } ``` +#### Rust + ```rust impl Solution { pub fn convert_to_base7(mut num: i32) -> String { diff --git a/solution/0500-0599/0504.Base 7/README_EN.md b/solution/0500-0599/0504.Base 7/README_EN.md index 02c82e4d5eb6c..c769e0816a5eb 100644 --- a/solution/0500-0599/0504.Base 7/README_EN.md +++ b/solution/0500-0599/0504.Base 7/README_EN.md @@ -43,6 +43,8 @@ tags: +#### Python3 + ```python class Solution: def convertToBase7(self, num: int) -> str: @@ -57,6 +59,8 @@ class Solution: return ''.join(ans[::-1]) ``` +#### Java + ```java class Solution { public String convertToBase7(int num) { @@ -76,6 +80,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -92,6 +98,8 @@ public: }; ``` +#### Go + ```go func convertToBase7(num int) string { if num == 0 { @@ -109,6 +117,8 @@ func convertToBase7(num int) string { } ``` +#### TypeScript + ```ts function convertToBase7(num: number): string { if (num == 0) { @@ -128,6 +138,8 @@ function convertToBase7(num: number): string { } ``` +#### Rust + ```rust impl Solution { pub fn convert_to_base7(mut num: i32) -> String { diff --git a/solution/0500-0599/0505.The Maze II/README.md b/solution/0500-0599/0505.The Maze II/README.md index 1732fbcd17eb7..b0d6661e5415e 100644 --- a/solution/0500-0599/0505.The Maze II/README.md +++ b/solution/0500-0599/0505.The Maze II/README.md @@ -98,6 +98,8 @@ tags: +#### Python3 + ```python class Solution: def shortestDistance( @@ -122,6 +124,8 @@ class Solution: return -1 if dist[di][dj] == inf else dist[di][dj] ``` +#### Java + ```java class Solution { public int shortestDistance(int[][] maze, int[] start, int[] destination) { @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -195,6 +201,8 @@ public: }; ``` +#### Go + ```go func shortestDistance(maze [][]int, start []int, destination []int) int { m, n := len(maze), len(maze[0]) @@ -233,6 +241,8 @@ func shortestDistance(maze [][]int, start []int, destination []int) int { } ``` +#### TypeScript + ```ts function shortestDistance(maze: number[][], start: number[], destination: number[]): number { const m = maze.length; diff --git a/solution/0500-0599/0505.The Maze II/README_EN.md b/solution/0500-0599/0505.The Maze II/README_EN.md index 3e97b0f01025b..10b656b08e90e 100644 --- a/solution/0500-0599/0505.The Maze II/README_EN.md +++ b/solution/0500-0599/0505.The Maze II/README_EN.md @@ -81,6 +81,8 @@ The length of the path is 1 + 1 + 3 + 1 + 2 + 2 + 2 = 12. +#### Python3 + ```python class Solution: def shortestDistance( @@ -105,6 +107,8 @@ class Solution: return -1 if dist[di][dj] == inf else dist[di][dj] ``` +#### Java + ```java class Solution { public int shortestDistance(int[][] maze, int[] start, int[] destination) { @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -178,6 +184,8 @@ public: }; ``` +#### Go + ```go func shortestDistance(maze [][]int, start []int, destination []int) int { m, n := len(maze), len(maze[0]) @@ -216,6 +224,8 @@ func shortestDistance(maze [][]int, start []int, destination []int) int { } ``` +#### TypeScript + ```ts function shortestDistance(maze: number[][], start: number[], destination: number[]): number { const m = maze.length; diff --git a/solution/0500-0599/0506.Relative Ranks/README.md b/solution/0500-0599/0506.Relative Ranks/README.md index 6ac598b498385..e1dda68c7a730 100644 --- a/solution/0500-0599/0506.Relative Ranks/README.md +++ b/solution/0500-0599/0506.Relative Ranks/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def findRelativeRanks(self, score: List[int]) -> List[str]: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String[] findRelativeRanks(int[] score) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func findRelativeRanks(score []int) []string { n := len(score) diff --git a/solution/0500-0599/0506.Relative Ranks/README_EN.md b/solution/0500-0599/0506.Relative Ranks/README_EN.md index 505556938f461..f5f734129431c 100644 --- a/solution/0500-0599/0506.Relative Ranks/README_EN.md +++ b/solution/0500-0599/0506.Relative Ranks/README_EN.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def findRelativeRanks(self, score: List[int]) -> List[str]: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String[] findRelativeRanks(int[] score) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func findRelativeRanks(score []int) []string { n := len(score) diff --git a/solution/0500-0599/0507.Perfect Number/README.md b/solution/0500-0599/0507.Perfect Number/README.md index 288ddc680632f..fadd7253711bb 100644 --- a/solution/0500-0599/0507.Perfect Number/README.md +++ b/solution/0500-0599/0507.Perfect Number/README.md @@ -55,6 +55,8 @@ tags: +#### Python3 + ```python class Solution: def checkPerfectNumber(self, num: int) -> bool: @@ -70,6 +72,8 @@ class Solution: return s == num ``` +#### Java + ```java class Solution { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func checkPerfectNumber(num int) bool { if num == 1 { diff --git a/solution/0500-0599/0507.Perfect Number/README_EN.md b/solution/0500-0599/0507.Perfect Number/README_EN.md index c7b8ccd089fdb..faedef371c6a7 100644 --- a/solution/0500-0599/0507.Perfect Number/README_EN.md +++ b/solution/0500-0599/0507.Perfect Number/README_EN.md @@ -54,6 +54,8 @@ tags: +#### Python3 + ```python class Solution: def checkPerfectNumber(self, num: int) -> bool: @@ -69,6 +71,8 @@ class Solution: return s == num ``` +#### Java + ```java class Solution { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func checkPerfectNumber(num int) bool { if num == 1 { diff --git a/solution/0500-0599/0508.Most Frequent Subtree Sum/README.md b/solution/0500-0599/0508.Most Frequent Subtree Sum/README.md index 58f5b45d977e1..454b3fae6673c 100644 --- a/solution/0500-0599/0508.Most Frequent Subtree Sum/README.md +++ b/solution/0500-0599/0508.Most Frequent Subtree Sum/README.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -85,6 +87,8 @@ class Solution: return [k for k, v in counter.items() if v == mx] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -206,6 +214,8 @@ func findFrequentTreeSum(root *TreeNode) []int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -245,6 +255,8 @@ function findFrequentTreeSum(root: TreeNode | null): number[] { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/0500-0599/0508.Most Frequent Subtree Sum/README_EN.md b/solution/0500-0599/0508.Most Frequent Subtree Sum/README_EN.md index d0b0ee711925b..686f1c832f87f 100644 --- a/solution/0500-0599/0508.Most Frequent Subtree Sum/README_EN.md +++ b/solution/0500-0599/0508.Most Frequent Subtree Sum/README_EN.md @@ -56,6 +56,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -79,6 +81,8 @@ class Solution: return [k for k, v in counter.items() if v == mx] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -200,6 +208,8 @@ func findFrequentTreeSum(root *TreeNode) []int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -239,6 +249,8 @@ function findFrequentTreeSum(root: TreeNode | null): number[] { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/0500-0599/0509.Fibonacci Number/README.md b/solution/0500-0599/0509.Fibonacci Number/README.md index 94a11291813e3..55d97ea37ff03 100644 --- a/solution/0500-0599/0509.Fibonacci Number/README.md +++ b/solution/0500-0599/0509.Fibonacci Number/README.md @@ -72,6 +72,8 @@ F(n) = F(n - 1) + F(n - 2),其中 n > 1 +#### Python3 + ```python class Solution: def fib(self, n: int) -> int: @@ -81,6 +83,8 @@ class Solution: return a ``` +#### Java + ```java class Solution { public int fib(int n) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func fib(n int) int { a, b := 0, 1 @@ -120,6 +128,8 @@ func fib(n int) int { } ``` +#### TypeScript + ```ts function fib(n: number): number { let a = 0; @@ -131,6 +141,8 @@ function fib(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn fib(n: i32) -> i32 { @@ -146,6 +158,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -163,6 +177,8 @@ var fib = function (n) { }; ``` +#### PHP + ```php class Solution { /** @@ -192,6 +208,8 @@ class Solution { +#### TypeScript + ```ts function fib(n: number): number { if (n < 2) { @@ -201,6 +219,8 @@ function fib(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn fib(n: i32) -> i32 { diff --git a/solution/0500-0599/0509.Fibonacci Number/README_EN.md b/solution/0500-0599/0509.Fibonacci Number/README_EN.md index ce0fc35df9861..a9f6ba3b33252 100644 --- a/solution/0500-0599/0509.Fibonacci Number/README_EN.md +++ b/solution/0500-0599/0509.Fibonacci Number/README_EN.md @@ -70,6 +70,8 @@ F(n) = F(n - 1) + F(n - 2), for n > 1. +#### Python3 + ```python class Solution: def fib(self, n: int) -> int: @@ -79,6 +81,8 @@ class Solution: return a ``` +#### Java + ```java class Solution { public int fib(int n) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func fib(n int) int { a, b := 0, 1 @@ -118,6 +126,8 @@ func fib(n int) int { } ``` +#### TypeScript + ```ts function fib(n: number): number { let a = 0; @@ -129,6 +139,8 @@ function fib(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn fib(n: i32) -> i32 { @@ -144,6 +156,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -161,6 +175,8 @@ var fib = function (n) { }; ``` +#### PHP + ```php class Solution { /** @@ -190,6 +206,8 @@ class Solution { +#### TypeScript + ```ts function fib(n: number): number { if (n < 2) { @@ -199,6 +217,8 @@ function fib(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn fib(n: i32) -> i32 { diff --git a/solution/0500-0599/0510.Inorder Successor in BST II/README.md b/solution/0500-0599/0510.Inorder Successor in BST II/README.md index 11952e25501ed..6e74874de06a8 100644 --- a/solution/0500-0599/0510.Inorder Successor in BST II/README.md +++ b/solution/0500-0599/0510.Inorder Successor in BST II/README.md @@ -109,6 +109,8 @@ class Node { +#### Python3 + ```python """ # Definition for a Node. @@ -132,6 +134,8 @@ class Solution: return node.parent ``` +#### Java + ```java /* // Definition for a Node. @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -190,6 +196,8 @@ public: }; ``` +#### Go + ```go /** * Definition for Node. @@ -216,6 +224,8 @@ func inorderSuccessor(node *Node) *Node { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -248,6 +258,8 @@ function inorderSuccessor(node: Node | null): Node | null { } ``` +#### JavaScript + ```js /** * // Definition for a Node. diff --git a/solution/0500-0599/0510.Inorder Successor in BST II/README_EN.md b/solution/0500-0599/0510.Inorder Successor in BST II/README_EN.md index 677174403cbcd..459d97d659fc5 100644 --- a/solution/0500-0599/0510.Inorder Successor in BST II/README_EN.md +++ b/solution/0500-0599/0510.Inorder Successor in BST II/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(h)$, where $h$ is the height of the binary tree. The s +#### Python3 + ```python """ # Definition for a Node. @@ -101,6 +103,8 @@ class Solution: return node.parent ``` +#### Java + ```java /* // Definition for a Node. @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go /** * Definition for Node. @@ -185,6 +193,8 @@ func inorderSuccessor(node *Node) *Node { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -217,6 +227,8 @@ function inorderSuccessor(node: Node | null): Node | null { } ``` +#### JavaScript + ```js /** * // Definition for a Node. diff --git a/solution/0500-0599/0511.Game Play Analysis I/README.md b/solution/0500-0599/0511.Game Play Analysis I/README.md index c503034f32b91..9b414caa8b6ed 100644 --- a/solution/0500-0599/0511.Game Play Analysis I/README.md +++ b/solution/0500-0599/0511.Game Play Analysis I/README.md @@ -72,6 +72,8 @@ Result 表: +#### Python3 + ```python import pandas as pd @@ -84,6 +86,8 @@ def game_analysis(activity: pd.DataFrame) -> pd.DataFrame: ) ``` +#### MySQL + ```sql # Write your MySQL query statement below SELECT player_id, MIN(event_date) AS first_login diff --git a/solution/0500-0599/0511.Game Play Analysis I/README_EN.md b/solution/0500-0599/0511.Game Play Analysis I/README_EN.md index 073aff0897bf3..a31b6bb2cc1a0 100644 --- a/solution/0500-0599/0511.Game Play Analysis I/README_EN.md +++ b/solution/0500-0599/0511.Game Play Analysis I/README_EN.md @@ -77,6 +77,8 @@ We can use `GROUP BY` to group the `player_id` and then take the minimum `event_ +#### Python3 + ```python import pandas as pd @@ -89,6 +91,8 @@ def game_analysis(activity: pd.DataFrame) -> pd.DataFrame: ) ``` +#### MySQL + ```sql # Write your MySQL query statement below SELECT player_id, MIN(event_date) AS first_login diff --git a/solution/0500-0599/0512.Game Play Analysis II/README.md b/solution/0500-0599/0512.Game Play Analysis II/README.md index d64249cb3c001..84a56c77f74b4 100644 --- a/solution/0500-0599/0512.Game Play Analysis II/README.md +++ b/solution/0500-0599/0512.Game Play Analysis II/README.md @@ -73,6 +73,8 @@ Activity table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -101,6 +103,8 @@ WHERE +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0500-0599/0512.Game Play Analysis II/README_EN.md b/solution/0500-0599/0512.Game Play Analysis II/README_EN.md index ac9e9fa8308f4..d1e8ea82b1f1c 100644 --- a/solution/0500-0599/0512.Game Play Analysis II/README_EN.md +++ b/solution/0500-0599/0512.Game Play Analysis II/README_EN.md @@ -77,6 +77,8 @@ We can use `GROUP BY` and `MIN` functions to find the first login date for each +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -105,6 +107,8 @@ We can use the window function `rank()`, which assigns a rank to each login date +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0500-0599/0513.Find Bottom Left Tree Value/README.md b/solution/0500-0599/0513.Find Bottom Left Tree Value/README.md index db91dfa9b1acc..34d9260518256 100644 --- a/solution/0500-0599/0513.Find Bottom Left Tree Value/README.md +++ b/solution/0500-0599/0513.Find Bottom Left Tree Value/README.md @@ -64,6 +64,8 @@ BFS 找最后一层第一个节点。 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -184,6 +192,8 @@ func findBottomLeftValue(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -218,6 +228,8 @@ function findBottomLeftValue(root: TreeNode | null): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -275,6 +287,8 @@ DFS 先序遍历,找深度最大的,且第一次被遍历到的节点。 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -299,6 +313,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -338,6 +354,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -371,6 +389,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -399,6 +419,8 @@ func findBottomLeftValue(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -434,6 +456,8 @@ function findBottomLeftValue(root: TreeNode | null): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/0500-0599/0513.Find Bottom Left Tree Value/README_EN.md b/solution/0500-0599/0513.Find Bottom Left Tree Value/README_EN.md index fc5822e1f42b2..e7e6642153d09 100644 --- a/solution/0500-0599/0513.Find Bottom Left Tree Value/README_EN.md +++ b/solution/0500-0599/0513.Find Bottom Left Tree Value/README_EN.md @@ -54,6 +54,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -76,6 +78,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -174,6 +182,8 @@ func findBottomLeftValue(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -208,6 +218,8 @@ function findBottomLeftValue(root: TreeNode | null): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -263,6 +275,8 @@ impl Solution { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -287,6 +301,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -326,6 +342,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -359,6 +377,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -387,6 +407,8 @@ func findBottomLeftValue(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -422,6 +444,8 @@ function findBottomLeftValue(root: TreeNode | null): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/0500-0599/0514.Freedom Trail/README.md b/solution/0500-0599/0514.Freedom Trail/README.md index 3259715c716d0..cbf5121cede7e 100644 --- a/solution/0500-0599/0514.Freedom Trail/README.md +++ b/solution/0500-0599/0514.Freedom Trail/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def findRotateSteps(self, ring: str, key: str) -> int: @@ -108,6 +110,8 @@ class Solution: return min(f[-1][j] for j in pos[key[-1]]) ``` +#### Java + ```java class Solution { public int findRotateSteps(String ring, String key) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go func findRotateSteps(ring string, key string) int { m, n := len(key), len(ring) @@ -211,6 +219,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function findRotateSteps(ring: string, key: string): number { const m: number = key.length; diff --git a/solution/0500-0599/0514.Freedom Trail/README_EN.md b/solution/0500-0599/0514.Freedom Trail/README_EN.md index 1d8de73150618..fa2703896e2d1 100644 --- a/solution/0500-0599/0514.Freedom Trail/README_EN.md +++ b/solution/0500-0599/0514.Freedom Trail/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(m \times n^2)$, and the space complexity is $O(m \time +#### Python3 + ```python class Solution: def findRotateSteps(self, ring: str, key: str) -> int: @@ -102,6 +104,8 @@ class Solution: return min(f[-1][j] for j in pos[key[-1]]) ``` +#### Java + ```java class Solution { public int findRotateSteps(String ring, String key) { @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go func findRotateSteps(ring string, key string) int { m, n := len(key), len(ring) @@ -205,6 +213,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function findRotateSteps(ring: string, key: string): number { const m: number = key.length; diff --git a/solution/0500-0599/0515.Find Largest Value in Each Tree Row/README.md b/solution/0500-0599/0515.Find Largest Value in Each Tree Row/README.md index d75089cf73486..776d503ff16ae 100644 --- a/solution/0500-0599/0515.Find Largest Value in Each Tree Row/README.md +++ b/solution/0500-0599/0515.Find Largest Value in Each Tree Row/README.md @@ -62,6 +62,8 @@ BFS 找每一层最大的节点值。 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -199,6 +207,8 @@ func largestValues(root *TreeNode) []int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -235,6 +245,8 @@ function largestValues(root: TreeNode | null): number[] { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -296,6 +308,8 @@ DFS 先序遍历,找每个深度最大的节点值。 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -320,6 +334,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -359,6 +375,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -392,6 +410,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -421,6 +441,8 @@ func largestValues(root *TreeNode) []int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -456,6 +478,8 @@ function largestValues(root: TreeNode | null): number[] { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/0500-0599/0515.Find Largest Value in Each Tree Row/README_EN.md b/solution/0500-0599/0515.Find Largest Value in Each Tree Row/README_EN.md index 50d105f6442c0..2f21077f1b987 100644 --- a/solution/0500-0599/0515.Find Largest Value in Each Tree Row/README_EN.md +++ b/solution/0500-0599/0515.Find Largest Value in Each Tree Row/README_EN.md @@ -54,6 +54,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -191,6 +199,8 @@ func largestValues(root *TreeNode) []int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -227,6 +237,8 @@ function largestValues(root: TreeNode | null): number[] { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -286,6 +298,8 @@ impl Solution { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -310,6 +324,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -349,6 +365,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -382,6 +400,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -411,6 +431,8 @@ func largestValues(root *TreeNode) []int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -446,6 +468,8 @@ function largestValues(root: TreeNode | null): number[] { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/0500-0599/0516.Longest Palindromic Subsequence/README.md b/solution/0500-0599/0516.Longest Palindromic Subsequence/README.md index 0084ca90888ba..05faae737b682 100644 --- a/solution/0500-0599/0516.Longest Palindromic Subsequence/README.md +++ b/solution/0500-0599/0516.Longest Palindromic Subsequence/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def longestPalindromeSubseq(self, s: str) -> int: @@ -84,6 +86,8 @@ class Solution: return f[0][-1] ``` +#### Java + ```java class Solution { public int longestPalindromeSubseq(String s) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func longestPalindromeSubseq(s string) int { n := len(s) @@ -151,6 +159,8 @@ func longestPalindromeSubseq(s string) int { } ``` +#### TypeScript + ```ts function longestPalindromeSubseq(s: string): number { const n = s.length; diff --git a/solution/0500-0599/0516.Longest Palindromic Subsequence/README_EN.md b/solution/0500-0599/0516.Longest Palindromic Subsequence/README_EN.md index 6c2ff49d8aeb7..3e2c74b664728 100644 --- a/solution/0500-0599/0516.Longest Palindromic Subsequence/README_EN.md +++ b/solution/0500-0599/0516.Longest Palindromic Subsequence/README_EN.md @@ -66,6 +66,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$. Where $n$ +#### Python3 + ```python class Solution: def longestPalindromeSubseq(self, s: str) -> int: @@ -82,6 +84,8 @@ class Solution: return f[0][-1] ``` +#### Java + ```java class Solution { public int longestPalindromeSubseq(String s) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func longestPalindromeSubseq(s string) int { n := len(s) @@ -149,6 +157,8 @@ func longestPalindromeSubseq(s string) int { } ``` +#### TypeScript + ```ts function longestPalindromeSubseq(s: string): number { const n = s.length; diff --git a/solution/0500-0599/0517.Super Washing Machines/README.md b/solution/0500-0599/0517.Super Washing Machines/README.md index 9c027a660bbdd..059d32586a40b 100644 --- a/solution/0500-0599/0517.Super Washing Machines/README.md +++ b/solution/0500-0599/0517.Super Washing Machines/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def findMinMoves(self, machines: List[int]) -> int: @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findMinMoves(int[] machines) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func findMinMoves(machines []int) (ans int) { n := len(machines) @@ -181,6 +189,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function findMinMoves(machines: number[]): number { const n = machines.length; diff --git a/solution/0500-0599/0517.Super Washing Machines/README_EN.md b/solution/0500-0599/0517.Super Washing Machines/README_EN.md index 0c90ef1558246..3952e5cc518ca 100644 --- a/solution/0500-0599/0517.Super Washing Machines/README_EN.md +++ b/solution/0500-0599/0517.Super Washing Machines/README_EN.md @@ -90,6 +90,8 @@ The time complexity is $O(n)$, where $n$ is the number of washing machines. The +#### Python3 + ```python class Solution: def findMinMoves(self, machines: List[int]) -> int: @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findMinMoves(int[] machines) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func findMinMoves(machines []int) (ans int) { n := len(machines) @@ -179,6 +187,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function findMinMoves(machines: number[]): number { const n = machines.length; diff --git a/solution/0500-0599/0518.Coin Change II/README.md b/solution/0500-0599/0518.Coin Change II/README.md index 5b047ea0e6749..5213954b46376 100644 --- a/solution/0500-0599/0518.Coin Change II/README.md +++ b/solution/0500-0599/0518.Coin Change II/README.md @@ -104,6 +104,8 @@ $$ +#### Python3 + ```python class Solution: def change(self, amount: int, coins: List[int]) -> int: @@ -118,6 +120,8 @@ class Solution: return f[m][n] ``` +#### Java + ```java class Solution { public int change(int amount, int[] coins) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func change(amount int, coins []int) int { m, n := len(coins), amount @@ -178,6 +186,8 @@ func change(amount int, coins []int) int { } ``` +#### TypeScript + ```ts function change(amount: number, coins: number[]): number { const [m, n] = [coins.length, amount]; @@ -201,6 +211,8 @@ function change(amount: number, coins: number[]): number { +#### Python3 + ```python class Solution: def change(self, amount: int, coins: List[int]) -> int: @@ -212,6 +224,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int change(int amount, int[] coins) { @@ -228,6 +242,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -246,6 +262,8 @@ public: }; ``` +#### Go + ```go func change(amount int, coins []int) int { n := amount @@ -260,6 +278,8 @@ func change(amount int, coins []int) int { } ``` +#### TypeScript + ```ts function change(amount: number, coins: number[]): number { const n = amount; diff --git a/solution/0500-0599/0518.Coin Change II/README_EN.md b/solution/0500-0599/0518.Coin Change II/README_EN.md index 849fbe8111780..ba98ccd5e1be1 100644 --- a/solution/0500-0599/0518.Coin Change II/README_EN.md +++ b/solution/0500-0599/0518.Coin Change II/README_EN.md @@ -99,6 +99,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def change(self, amount: int, coins: List[int]) -> int: @@ -113,6 +115,8 @@ class Solution: return f[m][n] ``` +#### Java + ```java class Solution { public int change(int amount, int[] coins) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func change(amount int, coins []int) int { m, n := len(coins), amount @@ -173,6 +181,8 @@ func change(amount int, coins []int) int { } ``` +#### TypeScript + ```ts function change(amount: number, coins: number[]): number { const [m, n] = [coins.length, amount]; @@ -196,6 +206,8 @@ We notice that $f[i][j]$ is only related to $f[i - 1][j]$ and $f[i][j - x]$. The +#### Python3 + ```python class Solution: def change(self, amount: int, coins: List[int]) -> int: @@ -207,6 +219,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int change(int amount, int[] coins) { @@ -223,6 +237,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -241,6 +257,8 @@ public: }; ``` +#### Go + ```go func change(amount int, coins []int) int { n := amount @@ -255,6 +273,8 @@ func change(amount int, coins []int) int { } ``` +#### TypeScript + ```ts function change(amount: number, coins: number[]): number { const n = amount; diff --git a/solution/0500-0599/0519.Random Flip Matrix/README.md b/solution/0500-0599/0519.Random Flip Matrix/README.md index 89480c44e54a4..b4f377628fd2b 100644 --- a/solution/0500-0599/0519.Random Flip Matrix/README.md +++ b/solution/0500-0599/0519.Random Flip Matrix/README.md @@ -70,6 +70,8 @@ solution.flip(); // 返回 [2, 0],此时返回 [0,0]、[1,0] 和 [2,0] 的概 +#### Python3 + ```python class Solution: def __init__(self, m: int, n: int): @@ -96,6 +98,8 @@ class Solution: # obj.reset() ``` +#### Java + ```java class Solution { private int m; diff --git a/solution/0500-0599/0519.Random Flip Matrix/README_EN.md b/solution/0500-0599/0519.Random Flip Matrix/README_EN.md index 63947579e2923..5b95574c3d16f 100644 --- a/solution/0500-0599/0519.Random Flip Matrix/README_EN.md +++ b/solution/0500-0599/0519.Random Flip Matrix/README_EN.md @@ -69,6 +69,8 @@ solution.flip(); // return [2, 0], [0,0], [1,0], and [2,0] should be equally li +#### Python3 + ```python class Solution: def __init__(self, m: int, n: int): @@ -95,6 +97,8 @@ class Solution: # obj.reset() ``` +#### Java + ```java class Solution { private int m; diff --git a/solution/0500-0599/0520.Detect Capital/README.md b/solution/0500-0599/0520.Detect Capital/README.md index 52831c176a6eb..b97c875d43010 100644 --- a/solution/0500-0599/0520.Detect Capital/README.md +++ b/solution/0500-0599/0520.Detect Capital/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def detectCapitalUse(self, word: str) -> bool: @@ -76,6 +78,8 @@ class Solution: return cnt == 0 or cnt == len(word) or (cnt == 1 and word[0].isupper()) ``` +#### Java + ```java class Solution { public boolean detectCapitalUse(String word) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,6 +107,8 @@ public: }; ``` +#### Go + ```go func detectCapitalUse(word string) bool { cnt := 0 @@ -113,6 +121,8 @@ func detectCapitalUse(word string) bool { } ``` +#### TypeScript + ```ts function detectCapitalUse(word: string): boolean { const cnt = word.split('').reduce((acc, c) => acc + (c === c.toUpperCase() ? 1 : 0), 0); diff --git a/solution/0500-0599/0520.Detect Capital/README_EN.md b/solution/0500-0599/0520.Detect Capital/README_EN.md index 4f2cf8a8f2512..c3dcd886cafa9 100644 --- a/solution/0500-0599/0520.Detect Capital/README_EN.md +++ b/solution/0500-0599/0520.Detect Capital/README_EN.md @@ -60,6 +60,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string `word`. The +#### Python3 + ```python class Solution: def detectCapitalUse(self, word: str) -> bool: @@ -67,6 +69,8 @@ class Solution: return cnt == 0 or cnt == len(word) or (cnt == 1 and word[0].isupper()) ``` +#### Java + ```java class Solution { public boolean detectCapitalUse(String word) { @@ -82,6 +86,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -92,6 +98,8 @@ public: }; ``` +#### Go + ```go func detectCapitalUse(word string) bool { cnt := 0 @@ -104,6 +112,8 @@ func detectCapitalUse(word string) bool { } ``` +#### TypeScript + ```ts function detectCapitalUse(word: string): boolean { const cnt = word.split('').reduce((acc, c) => acc + (c === c.toUpperCase() ? 1 : 0), 0); diff --git a/solution/0500-0599/0521.Longest Uncommon Subsequence I/README.md b/solution/0500-0599/0521.Longest Uncommon Subsequence I/README.md index d0f41a5cb73dd..51c52e939cf4e 100644 --- a/solution/0500-0599/0521.Longest Uncommon Subsequence I/README.md +++ b/solution/0500-0599/0521.Longest Uncommon Subsequence I/README.md @@ -70,12 +70,16 @@ tags: +#### Python3 + ```python class Solution: def findLUSlength(self, a: str, b: str) -> int: return -1 if a == b else max(len(a), len(b)) ``` +#### Java + ```java class Solution { public int findLUSlength(String a, String b) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -93,6 +99,8 @@ public: }; ``` +#### Go + ```go func findLUSlength(a string, b string) int { if a == b { @@ -105,12 +113,16 @@ func findLUSlength(a string, b string) int { } ``` +#### TypeScript + ```ts function findLUSlength(a: string, b: string): number { return a != b ? Math.max(a.length, b.length) : -1; } ``` +#### Rust + ```rust impl Solution { pub fn find_lu_slength(a: String, b: String) -> i32 { diff --git a/solution/0500-0599/0521.Longest Uncommon Subsequence I/README_EN.md b/solution/0500-0599/0521.Longest Uncommon Subsequence I/README_EN.md index ee7ab6e1f566e..adf088dfbfa6d 100644 --- a/solution/0500-0599/0521.Longest Uncommon Subsequence I/README_EN.md +++ b/solution/0500-0599/0521.Longest Uncommon Subsequence I/README_EN.md @@ -64,12 +64,16 @@ Note that "cdc" is also a longest uncommon subsequence. +#### Python3 + ```python class Solution: def findLUSlength(self, a: str, b: str) -> int: return -1 if a == b else max(len(a), len(b)) ``` +#### Java + ```java class Solution { public int findLUSlength(String a, String b) { @@ -78,6 +82,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -87,6 +93,8 @@ public: }; ``` +#### Go + ```go func findLUSlength(a string, b string) int { if a == b { @@ -99,12 +107,16 @@ func findLUSlength(a string, b string) int { } ``` +#### TypeScript + ```ts function findLUSlength(a: string, b: string): number { return a != b ? Math.max(a.length, b.length) : -1; } ``` +#### Rust + ```rust impl Solution { pub fn find_lu_slength(a: String, b: String) -> i32 { diff --git a/solution/0500-0599/0522.Longest Uncommon Subsequence II/README.md b/solution/0500-0599/0522.Longest Uncommon Subsequence II/README.md index cb52ea096dec5..4a26eb738656e 100644 --- a/solution/0500-0599/0522.Longest Uncommon Subsequence II/README.md +++ b/solution/0500-0599/0522.Longest Uncommon Subsequence II/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def findLUSlength(self, strs: List[str]) -> int: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findLUSlength(String[] strs) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func findLUSlength(strs []string) int { check := func(a, b string) bool { diff --git a/solution/0500-0599/0522.Longest Uncommon Subsequence II/README_EN.md b/solution/0500-0599/0522.Longest Uncommon Subsequence II/README_EN.md index 1e316ed1f69ea..1ac3630d2c25f 100644 --- a/solution/0500-0599/0522.Longest Uncommon Subsequence II/README_EN.md +++ b/solution/0500-0599/0522.Longest Uncommon Subsequence II/README_EN.md @@ -57,6 +57,8 @@ tags: +#### Python3 + ```python class Solution: def findLUSlength(self, strs: List[str]) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findLUSlength(String[] strs) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func findLUSlength(strs []string) int { check := func(a, b string) bool { diff --git a/solution/0500-0599/0523.Continuous Subarray Sum/README.md b/solution/0500-0599/0523.Continuous Subarray Sum/README.md index cec5583bae6ad..65f1abf3f688c 100644 --- a/solution/0500-0599/0523.Continuous Subarray Sum/README.md +++ b/solution/0500-0599/0523.Continuous Subarray Sum/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def checkSubarraySum(self, nums: List[int], k: int) -> bool: @@ -91,6 +93,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean checkSubarraySum(int[] nums, int k) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func checkSubarraySum(nums []int, k int) bool { mp := map[int]int{0: -1} diff --git a/solution/0500-0599/0523.Continuous Subarray Sum/README_EN.md b/solution/0500-0599/0523.Continuous Subarray Sum/README_EN.md index 9cedb4979416f..e289831c32368 100644 --- a/solution/0500-0599/0523.Continuous Subarray Sum/README_EN.md +++ b/solution/0500-0599/0523.Continuous Subarray Sum/README_EN.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def checkSubarraySum(self, nums: List[int], k: int) -> bool: @@ -95,6 +97,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean checkSubarraySum(int[] nums, int k) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func checkSubarraySum(nums []int, k int) bool { mp := map[int]int{0: -1} diff --git a/solution/0500-0599/0524.Longest Word in Dictionary through Deleting/README.md b/solution/0500-0599/0524.Longest Word in Dictionary through Deleting/README.md index 668ec3ce33b7f..72961426f104f 100644 --- a/solution/0500-0599/0524.Longest Word in Dictionary through Deleting/README.md +++ b/solution/0500-0599/0524.Longest Word in Dictionary through Deleting/README.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def findLongestWord(self, s: str, dictionary: List[str]) -> str: @@ -79,6 +81,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String findLongestWord(String s, List dictionary) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func findLongestWord(s string, dictionary []string) string { ans := "" @@ -153,6 +161,8 @@ func findLongestWord(s string, dictionary []string) string { } ``` +#### TypeScript + ```ts function findLongestWord(s: string, dictionary: string[]): string { dictionary.sort((a, b) => { @@ -183,6 +193,8 @@ function findLongestWord(s: string, dictionary: string[]): string { } ``` +#### Rust + ```rust impl Solution { pub fn find_longest_word(s: String, mut dictionary: Vec) -> String { diff --git a/solution/0500-0599/0524.Longest Word in Dictionary through Deleting/README_EN.md b/solution/0500-0599/0524.Longest Word in Dictionary through Deleting/README_EN.md index 6c27c20521ebd..a898a3e11e628 100644 --- a/solution/0500-0599/0524.Longest Word in Dictionary through Deleting/README_EN.md +++ b/solution/0500-0599/0524.Longest Word in Dictionary through Deleting/README_EN.md @@ -56,6 +56,8 @@ tags: +#### Python3 + ```python class Solution: def findLongestWord(self, s: str, dictionary: List[str]) -> str: @@ -75,6 +77,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String findLongestWord(String s, List dictionary) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func findLongestWord(s string, dictionary []string) string { ans := "" @@ -149,6 +157,8 @@ func findLongestWord(s string, dictionary []string) string { } ``` +#### TypeScript + ```ts function findLongestWord(s: string, dictionary: string[]): string { dictionary.sort((a, b) => { @@ -179,6 +189,8 @@ function findLongestWord(s: string, dictionary: string[]): string { } ``` +#### Rust + ```rust impl Solution { pub fn find_longest_word(s: String, mut dictionary: Vec) -> String { diff --git a/solution/0500-0599/0525.Contiguous Array/README.md b/solution/0500-0599/0525.Contiguous Array/README.md index c0cd30fef4bbe..fc82eb988e6f8 100644 --- a/solution/0500-0599/0525.Contiguous Array/README.md +++ b/solution/0500-0599/0525.Contiguous Array/README.md @@ -55,6 +55,8 @@ tags: +#### Python3 + ```python class Solution: def findMaxLength(self, nums: List[int]) -> int: @@ -69,6 +71,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findMaxLength(int[] nums) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func findMaxLength(nums []int) int { mp := map[int]int{0: -1} @@ -126,6 +134,8 @@ func findMaxLength(nums []int) int { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0500-0599/0525.Contiguous Array/README_EN.md b/solution/0500-0599/0525.Contiguous Array/README_EN.md index b980e3aa63980..88760dd852a7c 100644 --- a/solution/0500-0599/0525.Contiguous Array/README_EN.md +++ b/solution/0500-0599/0525.Contiguous Array/README_EN.md @@ -55,6 +55,8 @@ tags: +#### Python3 + ```python class Solution: def findMaxLength(self, nums: List[int]) -> int: @@ -69,6 +71,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findMaxLength(int[] nums) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func findMaxLength(nums []int) int { mp := map[int]int{0: -1} @@ -126,6 +134,8 @@ func findMaxLength(nums []int) int { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0500-0599/0526.Beautiful Arrangement/README.md b/solution/0500-0599/0526.Beautiful Arrangement/README.md index f99f0099a89d4..4c64e08af4de4 100644 --- a/solution/0500-0599/0526.Beautiful Arrangement/README.md +++ b/solution/0500-0599/0526.Beautiful Arrangement/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def countArrangement(self, n: int) -> int: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func countArrangement(n int) int { ans := 0 @@ -207,6 +215,8 @@ func countArrangement(n int) int { } ``` +#### TypeScript + ```ts function countArrangement(n: number): number { const vis = new Array(n + 1).fill(0); @@ -238,6 +248,8 @@ function countArrangement(n: number): number { } ``` +#### Rust + ```rust impl Solution { fn dfs(i: usize, n: usize, mat: &Vec>, vis: &mut Vec, res: &mut i32) { @@ -283,6 +295,8 @@ impl Solution { +#### Java + ```java class Solution { public int countArrangement(int N) { diff --git a/solution/0500-0599/0526.Beautiful Arrangement/README_EN.md b/solution/0500-0599/0526.Beautiful Arrangement/README_EN.md index 8385d2a1e649c..bf265ee58143c 100644 --- a/solution/0500-0599/0526.Beautiful Arrangement/README_EN.md +++ b/solution/0500-0599/0526.Beautiful Arrangement/README_EN.md @@ -68,6 +68,8 @@ The second beautiful arrangement is [2,1]: +#### Python3 + ```python class Solution: def countArrangement(self, n: int) -> int: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go func countArrangement(n int) int { ans := 0 @@ -205,6 +213,8 @@ func countArrangement(n int) int { } ``` +#### TypeScript + ```ts function countArrangement(n: number): number { const vis = new Array(n + 1).fill(0); @@ -236,6 +246,8 @@ function countArrangement(n: number): number { } ``` +#### Rust + ```rust impl Solution { fn dfs(i: usize, n: usize, mat: &Vec>, vis: &mut Vec, res: &mut i32) { @@ -281,6 +293,8 @@ impl Solution { +#### Java + ```java class Solution { public int countArrangement(int N) { diff --git a/solution/0500-0599/0527.Word Abbreviation/README.md b/solution/0500-0599/0527.Word Abbreviation/README.md index 77c27fc9af2b8..5649fb2f76b8f 100644 --- a/solution/0500-0599/0527.Word Abbreviation/README.md +++ b/solution/0500-0599/0527.Word Abbreviation/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Trie: __slots__ = ["children", "cnt"] @@ -126,6 +128,8 @@ class Solution: return ans ``` +#### Java + ```java class Trie { private final Trie[] children = new Trie[26]; @@ -178,6 +182,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -242,6 +248,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [26]*Trie @@ -300,6 +308,8 @@ func wordsAbbreviation(words []string) (ans []string) { } ``` +#### TypeScript + ```ts class Trie { private children: Trie[] = Array(26); diff --git a/solution/0500-0599/0527.Word Abbreviation/README_EN.md b/solution/0500-0599/0527.Word Abbreviation/README_EN.md index 0647b20239db5..da01c4a0cc147 100644 --- a/solution/0500-0599/0527.Word Abbreviation/README_EN.md +++ b/solution/0500-0599/0527.Word Abbreviation/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(L)$, and the space complexity is $O(L)$. Here, $L$ is +#### Python3 + ```python class Trie: __slots__ = ["children", "cnt"] @@ -126,6 +128,8 @@ class Solution: return ans ``` +#### Java + ```java class Trie { private final Trie[] children = new Trie[26]; @@ -178,6 +182,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -242,6 +248,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [26]*Trie @@ -300,6 +308,8 @@ func wordsAbbreviation(words []string) (ans []string) { } ``` +#### TypeScript + ```ts class Trie { private children: Trie[] = Array(26); diff --git a/solution/0500-0599/0528.Random Pick with Weight/README.md b/solution/0500-0599/0528.Random Pick with Weight/README.md index f1e8f9b025ed9..35c34f90782aa 100644 --- a/solution/0500-0599/0528.Random Pick with Weight/README.md +++ b/solution/0500-0599/0528.Random Pick with Weight/README.md @@ -91,6 +91,8 @@ solution.pickIndex(); // 返回 0,返回下标 0,返回该下标概率为 1/ +#### Python3 + ```python class Solution: def __init__(self, w: List[int]): @@ -115,6 +117,8 @@ class Solution: # param_1 = obj.pickIndex() ``` +#### Java + ```java class Solution { private int[] s; @@ -150,6 +154,8 @@ class Solution { */ ``` +#### C++ + ```cpp class Solution { public: @@ -183,6 +189,8 @@ public: */ ``` +#### Go + ```go type Solution struct { s []int @@ -219,6 +227,8 @@ func (this *Solution) PickIndex() int { */ ``` +#### Rust + ```rust use rand::{ thread_rng, Rng }; @@ -260,6 +270,8 @@ impl Solution { */ ``` +#### JavaScript + ```js /** * @param {number[]} w diff --git a/solution/0500-0599/0528.Random Pick with Weight/README_EN.md b/solution/0500-0599/0528.Random Pick with Weight/README_EN.md index c8d03f3c185be..6187ce9867120 100644 --- a/solution/0500-0599/0528.Random Pick with Weight/README_EN.md +++ b/solution/0500-0599/0528.Random Pick with Weight/README_EN.md @@ -90,6 +90,8 @@ and so on. +#### Python3 + ```python class Solution: def __init__(self, w: List[int]): @@ -114,6 +116,8 @@ class Solution: # param_1 = obj.pickIndex() ``` +#### Java + ```java class Solution { private int[] s; @@ -149,6 +153,8 @@ class Solution { */ ``` +#### C++ + ```cpp class Solution { public: @@ -182,6 +188,8 @@ public: */ ``` +#### Go + ```go type Solution struct { s []int @@ -218,6 +226,8 @@ func (this *Solution) PickIndex() int { */ ``` +#### Rust + ```rust use rand::{ thread_rng, Rng }; @@ -259,6 +269,8 @@ impl Solution { */ ``` +#### JavaScript + ```js /** * @param {number[]} w diff --git a/solution/0500-0599/0529.Minesweeper/README.md b/solution/0500-0599/0529.Minesweeper/README.md index fac39777cab38..b80274977e7b1 100644 --- a/solution/0500-0599/0529.Minesweeper/README.md +++ b/solution/0500-0599/0529.Minesweeper/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def updateBoard(self, board: List[List[str]], click: List[int]) -> List[List[str]]: @@ -114,6 +116,8 @@ class Solution: return board ``` +#### Java + ```java class Solution { private char[][] board; @@ -158,6 +162,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -198,6 +204,8 @@ public: }; ``` +#### Go + ```go func updateBoard(board [][]byte, click []int) [][]byte { m, n := len(board), len(board[0]) @@ -236,6 +244,8 @@ func updateBoard(board [][]byte, click []int) [][]byte { } ``` +#### TypeScript + ```ts function updateBoard(board: string[][], click: number[]): string[][] { const m = board.length; diff --git a/solution/0500-0599/0529.Minesweeper/README_EN.md b/solution/0500-0599/0529.Minesweeper/README_EN.md index 6612c11d2f69b..9dcbfce488f41 100644 --- a/solution/0500-0599/0529.Minesweeper/README_EN.md +++ b/solution/0500-0599/0529.Minesweeper/README_EN.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def updateBoard(self, board: List[List[str]], click: List[int]) -> List[List[str]]: @@ -108,6 +110,8 @@ class Solution: return board ``` +#### Java + ```java class Solution { private char[][] board; @@ -152,6 +156,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -192,6 +198,8 @@ public: }; ``` +#### Go + ```go func updateBoard(board [][]byte, click []int) [][]byte { m, n := len(board), len(board[0]) @@ -230,6 +238,8 @@ func updateBoard(board [][]byte, click []int) [][]byte { } ``` +#### TypeScript + ```ts function updateBoard(board: string[][], click: number[]): string[][] { const m = board.length; diff --git a/solution/0500-0599/0530.Minimum Absolute Difference in BST/README.md b/solution/0500-0599/0530.Minimum Absolute Difference in BST/README.md index 44ed2e0ed08df..43fd8fa1c8d1f 100644 --- a/solution/0500-0599/0530.Minimum Absolute Difference in BST/README.md +++ b/solution/0500-0599/0530.Minimum Absolute Difference in BST/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -196,6 +204,8 @@ func abs(x int) int { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/0500-0599/0530.Minimum Absolute Difference in BST/README_EN.md b/solution/0500-0599/0530.Minimum Absolute Difference in BST/README_EN.md index 3e41a6ce4a307..4fa626743de1d 100644 --- a/solution/0500-0599/0530.Minimum Absolute Difference in BST/README_EN.md +++ b/solution/0500-0599/0530.Minimum Absolute Difference in BST/README_EN.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -189,6 +197,8 @@ func abs(x int) int { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/0500-0599/0531.Lonely Pixel I/README.md b/solution/0500-0599/0531.Lonely Pixel I/README.md index 0ead0ec49c478..721e6ec10641f 100644 --- a/solution/0500-0599/0531.Lonely Pixel I/README.md +++ b/solution/0500-0599/0531.Lonely Pixel I/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def findLonelyPixel(self, picture: List[List[str]]) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findLonelyPixel(char[][] picture) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func findLonelyPixel(picture [][]byte) (ans int) { rows := make([]int, len(picture)) @@ -160,6 +168,8 @@ func findLonelyPixel(picture [][]byte) (ans int) { } ``` +#### TypeScript + ```ts function findLonelyPixel(picture: string[][]): number { const m = picture.length; diff --git a/solution/0500-0599/0531.Lonely Pixel I/README_EN.md b/solution/0500-0599/0531.Lonely Pixel I/README_EN.md index 14b8f2438f40b..38ec51ab8291b 100644 --- a/solution/0500-0599/0531.Lonely Pixel I/README_EN.md +++ b/solution/0500-0599/0531.Lonely Pixel I/README_EN.md @@ -62,6 +62,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m + n)$, +#### Python3 + ```python class Solution: def findLonelyPixel(self, picture: List[List[str]]) -> int: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findLonelyPixel(char[][] picture) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func findLonelyPixel(picture [][]byte) (ans int) { rows := make([]int, len(picture)) @@ -158,6 +166,8 @@ func findLonelyPixel(picture [][]byte) (ans int) { } ``` +#### TypeScript + ```ts function findLonelyPixel(picture: string[][]): number { const m = picture.length; diff --git a/solution/0500-0599/0532.K-diff Pairs in an Array/README.md b/solution/0500-0599/0532.K-diff Pairs in an Array/README.md index b8a76a9609324..6ec116976d429 100644 --- a/solution/0500-0599/0532.K-diff Pairs in an Array/README.md +++ b/solution/0500-0599/0532.K-diff Pairs in an Array/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def findPairs(self, nums: List[int], k: int) -> int: @@ -98,6 +100,8 @@ class Solution: return len(ans) ``` +#### Java + ```java class Solution { public int findPairs(int[] nums, int k) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func findPairs(nums []int, k int) int { vis := map[int]bool{} @@ -150,6 +158,8 @@ func findPairs(nums []int, k int) int { } ``` +#### Rust + ```rust impl Solution { pub fn find_pairs(mut nums: Vec, k: i32) -> i32 { diff --git a/solution/0500-0599/0532.K-diff Pairs in an Array/README_EN.md b/solution/0500-0599/0532.K-diff Pairs in an Array/README_EN.md index dc8ea02dd0eca..df31876b15ab2 100644 --- a/solution/0500-0599/0532.K-diff Pairs in an Array/README_EN.md +++ b/solution/0500-0599/0532.K-diff Pairs in an Array/README_EN.md @@ -77,6 +77,8 @@ Although we have two 1s in the input, we should only return the number of +#### Python3 + ```python class Solution: def findPairs(self, nums: List[int], k: int) -> int: @@ -90,6 +92,8 @@ class Solution: return len(ans) ``` +#### Java + ```java class Solution { public int findPairs(int[] nums, int k) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func findPairs(nums []int, k int) int { vis := map[int]bool{} @@ -142,6 +150,8 @@ func findPairs(nums []int, k int) int { } ``` +#### Rust + ```rust impl Solution { pub fn find_pairs(mut nums: Vec, k: i32) -> i32 { diff --git a/solution/0500-0599/0533.Lonely Pixel II/README.md b/solution/0500-0599/0533.Lonely Pixel II/README.md index bf501e230f4d5..77f8f9305c6b4 100644 --- a/solution/0500-0599/0533.Lonely Pixel II/README.md +++ b/solution/0500-0599/0533.Lonely Pixel II/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def findBlackPixel(self, picture: List[List[str]], target: int) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findBlackPixel(char[][] picture, int target) { @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -178,6 +184,8 @@ public: }; ``` +#### Go + ```go func findBlackPixel(picture [][]byte, target int) (ans int) { m := len(picture) @@ -213,6 +221,8 @@ func findBlackPixel(picture [][]byte, target int) (ans int) { } ``` +#### TypeScript + ```ts function findBlackPixel(picture: string[][], target: number): number { const m: number = picture.length; diff --git a/solution/0500-0599/0533.Lonely Pixel II/README_EN.md b/solution/0500-0599/0533.Lonely Pixel II/README_EN.md index f34b38028fd27..9e1e876575efc 100644 --- a/solution/0500-0599/0533.Lonely Pixel II/README_EN.md +++ b/solution/0500-0599/0533.Lonely Pixel II/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(m \times n^2)$, and the space complexity is $O(m \time +#### Python3 + ```python class Solution: def findBlackPixel(self, picture: List[List[str]], target: int) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findBlackPixel(char[][] picture, int target) { @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go func findBlackPixel(picture [][]byte, target int) (ans int) { m := len(picture) @@ -211,6 +219,8 @@ func findBlackPixel(picture [][]byte, target int) (ans int) { } ``` +#### TypeScript + ```ts function findBlackPixel(picture: string[][], target: number): number { const m: number = picture.length; diff --git a/solution/0500-0599/0534.Game Play Analysis III/README.md b/solution/0500-0599/0534.Game Play Analysis III/README.md index bf27943a0d30c..f0c6540b1073f 100644 --- a/solution/0500-0599/0534.Game Play Analysis III/README.md +++ b/solution/0500-0599/0534.Game Play Analysis III/README.md @@ -84,6 +84,8 @@ Activity table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -108,6 +110,8 @@ FROM Activity; +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -131,6 +135,8 @@ GROUP BY 1, 2; +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/0500-0599/0534.Game Play Analysis III/README_EN.md b/solution/0500-0599/0534.Game Play Analysis III/README_EN.md index 32e9ce13e8132..a725f1d5f7770 100644 --- a/solution/0500-0599/0534.Game Play Analysis III/README_EN.md +++ b/solution/0500-0599/0534.Game Play Analysis III/README_EN.md @@ -83,6 +83,8 @@ We can use the window function `SUM() OVER()` to group by `player_id`, sort by ` +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -107,6 +109,8 @@ We can also use a self-join to join the `Activity` table with itself on the cond +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -130,6 +134,8 @@ GROUP BY 1, 2; +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/0500-0599/0535.Encode and Decode TinyURL/README.md b/solution/0500-0599/0535.Encode and Decode TinyURL/README.md index 4ef65532b1cad..9538bf04f7bbe 100644 --- a/solution/0500-0599/0535.Encode and Decode TinyURL/README.md +++ b/solution/0500-0599/0535.Encode and Decode TinyURL/README.md @@ -68,6 +68,8 @@ string ans = obj.decode(tiny); // 返回解密后得到的原本的 URL 。 +#### Python3 + ```python class Codec: def __init__(self): @@ -92,6 +94,8 @@ class Codec: # codec.decode(codec.encode(url)) ``` +#### Java + ```java public class Codec { private Map m = new HashMap<>(); @@ -117,6 +121,8 @@ public class Codec { // codec.decode(codec.encode(url)); ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ private: // solution.decode(solution.encode(url)); ``` +#### Go + ```go type Codec struct { m map[int]string diff --git a/solution/0500-0599/0535.Encode and Decode TinyURL/README_EN.md b/solution/0500-0599/0535.Encode and Decode TinyURL/README_EN.md index 6510dc18122eb..d79e9887f65a6 100644 --- a/solution/0500-0599/0535.Encode and Decode TinyURL/README_EN.md +++ b/solution/0500-0599/0535.Encode and Decode TinyURL/README_EN.md @@ -64,6 +64,8 @@ string ans = obj.decode(tiny); // returns the original url after decoding it. +#### Python3 + ```python class Codec: def __init__(self): @@ -88,6 +90,8 @@ class Codec: # codec.decode(codec.encode(url)) ``` +#### Java + ```java public class Codec { private Map m = new HashMap<>(); @@ -113,6 +117,8 @@ public class Codec { // codec.decode(codec.encode(url)); ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ private: // solution.decode(solution.encode(url)); ``` +#### Go + ```go type Codec struct { m map[int]string diff --git a/solution/0500-0599/0536.Construct Binary Tree from String/README.md b/solution/0500-0599/0536.Construct Binary Tree from String/README.md index 9da32d2ac47e6..ec92b1806ac94 100644 --- a/solution/0500-0599/0536.Construct Binary Tree from String/README.md +++ b/solution/0500-0599/0536.Construct Binary Tree from String/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -102,6 +104,8 @@ class Solution: return dfs(s) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -197,6 +203,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0500-0599/0536.Construct Binary Tree from String/README_EN.md b/solution/0500-0599/0536.Construct Binary Tree from String/README_EN.md index 76e9508a7b782..f16b44ac7eaa9 100644 --- a/solution/0500-0599/0536.Construct Binary Tree from String/README_EN.md +++ b/solution/0500-0599/0536.Construct Binary Tree from String/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -99,6 +101,8 @@ class Solution: return dfs(s) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -194,6 +200,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0500-0599/0537.Complex Number Multiplication/README.md b/solution/0500-0599/0537.Complex Number Multiplication/README.md index 15ab1487225c2..c14888e5658fa 100644 --- a/solution/0500-0599/0537.Complex Number Multiplication/README.md +++ b/solution/0500-0599/0537.Complex Number Multiplication/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def complexNumberMultiply(self, num1: str, num2: str) -> str: @@ -72,6 +74,8 @@ class Solution: return f'{a * c - b * d}+{a * d + c * b}i' ``` +#### Java + ```java class Solution { public String complexNumberMultiply(String num1, String num2) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -98,6 +104,8 @@ public: }; ``` +#### Go + ```go func complexNumberMultiply(num1, num2 string) string { parse := func(num string) (a, b int) { @@ -112,6 +120,8 @@ func complexNumberMultiply(num1, num2 string) string { } ``` +#### TypeScript + ```ts function complexNumberMultiply(num1: string, num2: string): string { let arr1 = num1.split('+'), diff --git a/solution/0500-0599/0537.Complex Number Multiplication/README_EN.md b/solution/0500-0599/0537.Complex Number Multiplication/README_EN.md index 2153d5211bbc5..0a60653680fb9 100644 --- a/solution/0500-0599/0537.Complex Number Multiplication/README_EN.md +++ b/solution/0500-0599/0537.Complex Number Multiplication/README_EN.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def complexNumberMultiply(self, num1: str, num2: str) -> str: @@ -70,6 +72,8 @@ class Solution: return f'{a * c - b * d}+{a * d + c * b}i' ``` +#### Java + ```java class Solution { public String complexNumberMultiply(String num1, String num2) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -96,6 +102,8 @@ public: }; ``` +#### Go + ```go func complexNumberMultiply(num1, num2 string) string { parse := func(num string) (a, b int) { @@ -110,6 +118,8 @@ func complexNumberMultiply(num1, num2 string) string { } ``` +#### TypeScript + ```ts function complexNumberMultiply(num1: string, num2: string): string { let arr1 = num1.split('+'), diff --git a/solution/0500-0599/0538.Convert BST to Greater Tree/README.md b/solution/0500-0599/0538.Convert BST to Greater Tree/README.md index 43ff84e75aa80..c529c18f920b6 100644 --- a/solution/0500-0599/0538.Convert BST to Greater Tree/README.md +++ b/solution/0500-0599/0538.Convert BST to Greater Tree/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -107,6 +109,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -200,6 +208,8 @@ func convertBST(root *TreeNode) *TreeNode { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -252,6 +262,8 @@ Morris 遍历无需使用栈,时间复杂度 $O(n)$,空间复杂度为 $O(1) +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -283,6 +295,8 @@ class Solution: return node ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -329,6 +343,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -372,6 +388,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0500-0599/0538.Convert BST to Greater Tree/README_EN.md b/solution/0500-0599/0538.Convert BST to Greater Tree/README_EN.md index a55cb39f81c46..0e7b261f6ee8b 100644 --- a/solution/0500-0599/0538.Convert BST to Greater Tree/README_EN.md +++ b/solution/0500-0599/0538.Convert BST to Greater Tree/README_EN.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -90,6 +92,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -183,6 +191,8 @@ func convertBST(root *TreeNode) *TreeNode { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -222,6 +232,8 @@ var convertBST = function (root) { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -253,6 +265,8 @@ class Solution: return node ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -299,6 +313,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -342,6 +358,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0500-0599/0539.Minimum Time Difference/README.md b/solution/0500-0599/0539.Minimum Time Difference/README.md index 5215b1bf85c64..6dea371ff17d3 100644 --- a/solution/0500-0599/0539.Minimum Time Difference/README.md +++ b/solution/0500-0599/0539.Minimum Time Difference/README.md @@ -56,6 +56,8 @@ tags: +#### Python3 + ```python class Solution: def findMinDifference(self, timePoints: List[str]) -> int: @@ -69,6 +71,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public int findMinDifference(List timePoints) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func findMinDifference(timePoints []string) int { if len(timePoints) > 24*60 { @@ -132,6 +140,8 @@ func findMinDifference(timePoints []string) int { } ``` +#### TypeScript + ```ts function findMinDifference(timePoints: string[]): number { const mins = timePoints diff --git a/solution/0500-0599/0539.Minimum Time Difference/README_EN.md b/solution/0500-0599/0539.Minimum Time Difference/README_EN.md index 3ee468c10ddea..a3ca55d412ea3 100644 --- a/solution/0500-0599/0539.Minimum Time Difference/README_EN.md +++ b/solution/0500-0599/0539.Minimum Time Difference/README_EN.md @@ -47,6 +47,8 @@ Given a list of 24-hour clock time points in "HH:MM" +#### Python3 + ```python class Solution: def findMinDifference(self, timePoints: List[str]) -> int: @@ -60,6 +62,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public int findMinDifference(List timePoints) { @@ -82,6 +86,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,6 +107,8 @@ public: }; ``` +#### Go + ```go func findMinDifference(timePoints []string) int { if len(timePoints) > 24*60 { @@ -123,6 +131,8 @@ func findMinDifference(timePoints []string) int { } ``` +#### TypeScript + ```ts function findMinDifference(timePoints: string[]): number { const mins = timePoints diff --git a/solution/0500-0599/0540.Single Element in a Sorted Array/README.md b/solution/0500-0599/0540.Single Element in a Sorted Array/README.md index eeda2fd1aeab4..a547c11b30901 100644 --- a/solution/0500-0599/0540.Single Element in a Sorted Array/README.md +++ b/solution/0500-0599/0540.Single Element in a Sorted Array/README.md @@ -96,6 +96,8 @@ return nums[l] +#### Python3 + ```python class Solution: def singleNonDuplicate(self, nums: List[int]) -> int: @@ -110,6 +112,8 @@ class Solution: return nums[left] ``` +#### Java + ```java class Solution { public int singleNonDuplicate(int[] nums) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func singleNonDuplicate(nums []int) int { left, right := 0, len(nums)-1 @@ -161,6 +169,8 @@ func singleNonDuplicate(nums []int) int { } ``` +#### TypeScript + ```ts function singleNonDuplicate(nums: number[]): number { let left = 0, @@ -177,6 +187,8 @@ function singleNonDuplicate(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn single_non_duplicate(nums: Vec) -> i32 { @@ -195,6 +207,8 @@ impl Solution { } ``` +#### C + ```c int singleNonDuplicate(int* nums, int numsSize) { int left = 0; diff --git a/solution/0500-0599/0540.Single Element in a Sorted Array/README_EN.md b/solution/0500-0599/0540.Single Element in a Sorted Array/README_EN.md index bc04f1f993cd0..4098085e35066 100644 --- a/solution/0500-0599/0540.Single Element in a Sorted Array/README_EN.md +++ b/solution/0500-0599/0540.Single Element in a Sorted Array/README_EN.md @@ -49,6 +49,8 @@ tags: +#### Python3 + ```python class Solution: def singleNonDuplicate(self, nums: List[int]) -> int: @@ -63,6 +65,8 @@ class Solution: return nums[left] ``` +#### Java + ```java class Solution { public int singleNonDuplicate(int[] nums) { @@ -82,6 +86,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -99,6 +105,8 @@ public: }; ``` +#### Go + ```go func singleNonDuplicate(nums []int) int { left, right := 0, len(nums)-1 @@ -114,6 +122,8 @@ func singleNonDuplicate(nums []int) int { } ``` +#### TypeScript + ```ts function singleNonDuplicate(nums: number[]): number { let left = 0, @@ -130,6 +140,8 @@ function singleNonDuplicate(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn single_non_duplicate(nums: Vec) -> i32 { @@ -148,6 +160,8 @@ impl Solution { } ``` +#### C + ```c int singleNonDuplicate(int* nums, int numsSize) { int left = 0; diff --git a/solution/0500-0599/0541.Reverse String II/README.md b/solution/0500-0599/0541.Reverse String II/README.md index 55bea9892c823..a6a3dfbada4da 100644 --- a/solution/0500-0599/0541.Reverse String II/README.md +++ b/solution/0500-0599/0541.Reverse String II/README.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def reverseStr(self, s: str, k: int) -> str: @@ -69,6 +71,8 @@ class Solution: return ''.join(t) ``` +#### Java + ```java class Solution { public String reverseStr(String s, int k) { @@ -85,6 +89,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -97,6 +103,8 @@ public: }; ``` +#### Go + ```go func reverseStr(s string, k int) string { t := []byte(s) diff --git a/solution/0500-0599/0541.Reverse String II/README_EN.md b/solution/0500-0599/0541.Reverse String II/README_EN.md index f2d8bb47c90d4..5923f43e1fe5b 100644 --- a/solution/0500-0599/0541.Reverse String II/README_EN.md +++ b/solution/0500-0599/0541.Reverse String II/README_EN.md @@ -48,6 +48,8 @@ tags: +#### Python3 + ```python class Solution: def reverseStr(self, s: str, k: int) -> str: @@ -57,6 +59,8 @@ class Solution: return ''.join(t) ``` +#### Java + ```java class Solution { public String reverseStr(String s, int k) { @@ -73,6 +77,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -85,6 +91,8 @@ public: }; ``` +#### Go + ```go func reverseStr(s string, k int) string { t := []byte(s) diff --git a/solution/0500-0599/0542.01 Matrix/README.md b/solution/0500-0599/0542.01 Matrix/README.md index 961ae31ecde49..533ea1862d60e 100644 --- a/solution/0500-0599/0542.01 Matrix/README.md +++ b/solution/0500-0599/0542.01 Matrix/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def updateMatrix(self, mat: List[List[int]]) -> List[List[int]]: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] updateMatrix(int[][] mat) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func updateMatrix(mat [][]int) [][]int { m, n := len(mat), len(mat[0]) @@ -195,6 +203,8 @@ func updateMatrix(mat [][]int) [][]int { } ``` +#### TypeScript + ```ts function updateMatrix(mat: number[][]): number[][] { const [m, n] = [mat.length, mat[0].length]; @@ -223,6 +233,8 @@ function updateMatrix(mat: number[][]): number[][] { } ``` +#### Rust + ```rust use std::collections::VecDeque; diff --git a/solution/0500-0599/0542.01 Matrix/README_EN.md b/solution/0500-0599/0542.01 Matrix/README_EN.md index 37833ae46f3f0..b8101a8467405 100644 --- a/solution/0500-0599/0542.01 Matrix/README_EN.md +++ b/solution/0500-0599/0542.01 Matrix/README_EN.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def updateMatrix(self, mat: List[List[int]]) -> List[List[int]]: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] updateMatrix(int[][] mat) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func updateMatrix(mat [][]int) [][]int { m, n := len(mat), len(mat[0]) @@ -185,6 +193,8 @@ func updateMatrix(mat [][]int) [][]int { } ``` +#### TypeScript + ```ts function updateMatrix(mat: number[][]): number[][] { const [m, n] = [mat.length, mat[0].length]; @@ -213,6 +223,8 @@ function updateMatrix(mat: number[][]): number[][] { } ``` +#### Rust + ```rust use std::collections::VecDeque; diff --git a/solution/0500-0599/0543.Diameter of Binary Tree/README.md b/solution/0500-0599/0543.Diameter of Binary Tree/README.md index 757016d93820c..51d31a944f111 100644 --- a/solution/0500-0599/0543.Diameter of Binary Tree/README.md +++ b/solution/0500-0599/0543.Diameter of Binary Tree/README.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -176,6 +184,8 @@ func diameterOfBinaryTree(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -208,6 +218,8 @@ function diameterOfBinaryTree(root: TreeNode | null): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -249,6 +261,8 @@ impl Solution { } ``` +#### C + ```c /** * Definition for a binary tree node. @@ -288,6 +302,8 @@ int diameterOfBinaryTree(struct TreeNode* root) { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: diff --git a/solution/0500-0599/0543.Diameter of Binary Tree/README_EN.md b/solution/0500-0599/0543.Diameter of Binary Tree/README_EN.md index 5ca88c0362092..7270f596278e5 100644 --- a/solution/0500-0599/0543.Diameter of Binary Tree/README_EN.md +++ b/solution/0500-0599/0543.Diameter of Binary Tree/README_EN.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -174,6 +182,8 @@ func diameterOfBinaryTree(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -206,6 +216,8 @@ function diameterOfBinaryTree(root: TreeNode | null): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -247,6 +259,8 @@ impl Solution { } ``` +#### C + ```c /** * Definition for a binary tree node. @@ -286,6 +300,8 @@ int diameterOfBinaryTree(struct TreeNode* root) { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: diff --git a/solution/0500-0599/0544.Output Contest Matches/README.md b/solution/0500-0599/0544.Output Contest Matches/README.md index 0546bf4807137..75765760356ee 100644 --- a/solution/0500-0599/0544.Output Contest Matches/README.md +++ b/solution/0500-0599/0544.Output Contest Matches/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def findContestMatch(self, n: int) -> str: @@ -86,6 +88,8 @@ class Solution: return team[0] ``` +#### Java + ```java class Solution { public String findContestMatch(int n) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func findContestMatch(n int) string { team := make([]string, n) diff --git a/solution/0500-0599/0544.Output Contest Matches/README_EN.md b/solution/0500-0599/0544.Output Contest Matches/README_EN.md index 96a0464ca68f1..f0a08ac564d7d 100644 --- a/solution/0500-0599/0544.Output Contest Matches/README_EN.md +++ b/solution/0500-0599/0544.Output Contest Matches/README_EN.md @@ -68,6 +68,8 @@ Since the third round will generate the final winner, you need to output the ans +#### Python3 + ```python class Solution: def findContestMatch(self, n: int) -> str: @@ -79,6 +81,8 @@ class Solution: return team[0] ``` +#### Java + ```java class Solution { public String findContestMatch(int n) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func findContestMatch(n int) string { team := make([]string, n) diff --git a/solution/0500-0599/0545.Boundary of Binary Tree/README.md b/solution/0500-0599/0545.Boundary of Binary Tree/README.md index 298550202a4db..2abe265cb2a51 100644 --- a/solution/0500-0599/0545.Boundary of Binary Tree/README.md +++ b/solution/0500-0599/0545.Boundary of Binary Tree/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -130,6 +132,8 @@ class Solution: return node and node.left is None and node.right is None ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -208,6 +212,8 @@ class Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0500-0599/0545.Boundary of Binary Tree/README_EN.md b/solution/0500-0599/0545.Boundary of Binary Tree/README_EN.md index bd351012d404f..efad223d37c23 100644 --- a/solution/0500-0599/0545.Boundary of Binary Tree/README_EN.md +++ b/solution/0500-0599/0545.Boundary of Binary Tree/README_EN.md @@ -81,6 +81,8 @@ Concatenating everything results in [1] + [2] + [4,7,8,9,10] + [6,3] = [1,2,4,7, +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -133,6 +135,8 @@ class Solution: return node and node.left is None and node.right is None ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -211,6 +215,8 @@ class Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0500-0599/0546.Remove Boxes/README.md b/solution/0500-0599/0546.Remove Boxes/README.md index 6a2074dd20237..aa3241a14f521 100644 --- a/solution/0500-0599/0546.Remove Boxes/README.md +++ b/solution/0500-0599/0546.Remove Boxes/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def removeBoxes(self, boxes: List[int]) -> int: @@ -103,6 +105,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[][][] f; @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go func removeBoxes(boxes []int) int { n := len(boxes) diff --git a/solution/0500-0599/0546.Remove Boxes/README_EN.md b/solution/0500-0599/0546.Remove Boxes/README_EN.md index 3ba69bb2277c4..c47de184eb357 100644 --- a/solution/0500-0599/0546.Remove Boxes/README_EN.md +++ b/solution/0500-0599/0546.Remove Boxes/README_EN.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def removeBoxes(self, boxes: List[int]) -> int: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[][][] f; @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func removeBoxes(boxes []int) int { n := len(boxes) diff --git a/solution/0500-0599/0547.Number of Provinces/README.md b/solution/0500-0599/0547.Number of Provinces/README.md index 9cd838be0a1b5..b386ad074240f 100644 --- a/solution/0500-0599/0547.Number of Provinces/README.md +++ b/solution/0500-0599/0547.Number of Provinces/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def findCircleNum(self, isConnected: List[List[int]]) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[][] g; @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func findCircleNum(isConnected [][]int) (ans int) { n := len(isConnected) @@ -177,6 +185,8 @@ func findCircleNum(isConnected [][]int) (ans int) { } ``` +#### TypeScript + ```ts function findCircleNum(isConnected: number[][]): number { const n = isConnected.length; @@ -200,6 +210,8 @@ function findCircleNum(isConnected: number[][]): number { } ``` +#### Rust + ```rust impl Solution { fn dfs(is_connected: &mut Vec>, vis: &mut Vec, i: usize) { @@ -246,6 +258,8 @@ impl Solution { +#### Python3 + ```python class Solution: def findCircleNum(self, isConnected: List[List[int]]) -> int: @@ -267,6 +281,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] p; @@ -301,6 +317,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -331,6 +349,8 @@ public: }; ``` +#### Go + ```go func findCircleNum(isConnected [][]int) (ans int) { n := len(isConnected) @@ -361,6 +381,8 @@ func findCircleNum(isConnected [][]int) (ans int) { } ``` +#### TypeScript + ```ts function findCircleNum(isConnected: number[][]): number { const n = isConnected.length; diff --git a/solution/0500-0599/0547.Number of Provinces/README_EN.md b/solution/0500-0599/0547.Number of Provinces/README_EN.md index 9765982c41bfa..40eac94422c1e 100644 --- a/solution/0500-0599/0547.Number of Provinces/README_EN.md +++ b/solution/0500-0599/0547.Number of Provinces/README_EN.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def findCircleNum(self, isConnected: List[List[int]]) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[][] g; @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func findCircleNum(isConnected [][]int) (ans int) { n := len(isConnected) @@ -163,6 +171,8 @@ func findCircleNum(isConnected [][]int) (ans int) { } ``` +#### TypeScript + ```ts function findCircleNum(isConnected: number[][]): number { const n = isConnected.length; @@ -186,6 +196,8 @@ function findCircleNum(isConnected: number[][]): number { } ``` +#### Rust + ```rust impl Solution { fn dfs(is_connected: &mut Vec>, vis: &mut Vec, i: usize) { @@ -224,6 +236,8 @@ impl Solution { +#### Python3 + ```python class Solution: def findCircleNum(self, isConnected: List[List[int]]) -> int: @@ -245,6 +259,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] p; @@ -279,6 +295,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -309,6 +327,8 @@ public: }; ``` +#### Go + ```go func findCircleNum(isConnected [][]int) (ans int) { n := len(isConnected) @@ -339,6 +359,8 @@ func findCircleNum(isConnected [][]int) (ans int) { } ``` +#### TypeScript + ```ts function findCircleNum(isConnected: number[][]): number { const n = isConnected.length; diff --git a/solution/0500-0599/0548.Split Array with Equal Sum/README.md b/solution/0500-0599/0548.Split Array with Equal Sum/README.md index 07e7376cfc601..4bf9bc3976877 100644 --- a/solution/0500-0599/0548.Split Array with Equal Sum/README.md +++ b/solution/0500-0599/0548.Split Array with Equal Sum/README.md @@ -79,6 +79,8 @@ sum(k + 1, n - 1) = sum(6, 6) = 1 +#### Python3 + ```python class Solution: def splitArray(self, nums: List[int]) -> bool: @@ -97,6 +99,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean splitArray(int[] nums) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func splitArray(nums []int) bool { n := len(nums) diff --git a/solution/0500-0599/0548.Split Array with Equal Sum/README_EN.md b/solution/0500-0599/0548.Split Array with Equal Sum/README_EN.md index 27e9604e5e3ee..f13c6827898c9 100644 --- a/solution/0500-0599/0548.Split Array with Equal Sum/README_EN.md +++ b/solution/0500-0599/0548.Split Array with Equal Sum/README_EN.md @@ -65,6 +65,8 @@ sum(k + 1, n - 1) = sum(6, 6) = 1 +#### Python3 + ```python class Solution: def splitArray(self, nums: List[int]) -> bool: @@ -83,6 +85,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean splitArray(int[] nums) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func splitArray(nums []int) bool { n := len(nums) diff --git a/solution/0500-0599/0549.Binary Tree Longest Consecutive Sequence II/README.md b/solution/0500-0599/0549.Binary Tree Longest Consecutive Sequence II/README.md index 182d307406c4e..af176b43d295b 100644 --- a/solution/0500-0599/0549.Binary Tree Longest Consecutive Sequence II/README.md +++ b/solution/0500-0599/0549.Binary Tree Longest Consecutive Sequence II/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -158,6 +162,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -199,6 +205,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0500-0599/0549.Binary Tree Longest Consecutive Sequence II/README_EN.md b/solution/0500-0599/0549.Binary Tree Longest Consecutive Sequence II/README_EN.md index 1c53cbc1b9fc5..9286593fdc5d1 100644 --- a/solution/0500-0599/0549.Binary Tree Longest Consecutive Sequence II/README_EN.md +++ b/solution/0500-0599/0549.Binary Tree Longest Consecutive Sequence II/README_EN.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -192,6 +198,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0500-0599/0550.Game Play Analysis IV/README.md b/solution/0500-0599/0550.Game Play Analysis IV/README.md index 256556086d433..d2b243f6a0b59 100644 --- a/solution/0500-0599/0550.Game Play Analysis IV/README.md +++ b/solution/0500-0599/0550.Game Play Analysis IV/README.md @@ -76,6 +76,8 @@ Activity table: +#### Python3 + ```python import pandas as pd @@ -91,6 +93,8 @@ def gameplay_analysis(activity: pd.DataFrame) -> pd.DataFrame: ) ``` +#### MySQL + ```sql # Write your MySQL query statement below SELECT ROUND(AVG(b.event_date IS NOT NULL), 2) AS fraction @@ -116,6 +120,8 @@ FROM +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0500-0599/0550.Game Play Analysis IV/README_EN.md b/solution/0500-0599/0550.Game Play Analysis IV/README_EN.md index 440db1243c0e9..75774152565b6 100644 --- a/solution/0500-0599/0550.Game Play Analysis IV/README_EN.md +++ b/solution/0500-0599/0550.Game Play Analysis IV/README_EN.md @@ -75,6 +75,8 @@ We can first find the first login date of each player, and then perform a left j +#### Python3 + ```python import pandas as pd @@ -90,6 +92,8 @@ def gameplay_analysis(activity: pd.DataFrame) -> pd.DataFrame: ) ``` +#### MySQL + ```sql # Write your MySQL query statement below SELECT ROUND(AVG(b.event_date IS NOT NULL), 2) AS fraction @@ -115,6 +119,8 @@ We can use the `LEAD` window function to get the next login date of each player. +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0500-0599/0551.Student Attendance Record I/README.md b/solution/0500-0599/0551.Student Attendance Record I/README.md index e68e8b271b9c1..e79c74a4757ae 100644 --- a/solution/0500-0599/0551.Student Attendance Record I/README.md +++ b/solution/0500-0599/0551.Student Attendance Record I/README.md @@ -74,12 +74,16 @@ tags: +#### Python3 + ```python class Solution: def checkRecord(self, s: str) -> bool: return s.count('A') < 2 and 'LLL' not in s ``` +#### Java + ```java class Solution { public boolean checkRecord(String s) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -97,12 +103,16 @@ public: }; ``` +#### Go + ```go func checkRecord(s string) bool { return strings.Count(s, "A") < 2 && !strings.Contains(s, "LLL") } ``` +#### TypeScript + ```ts function checkRecord(s: string): boolean { return s.indexOf('A') === s.lastIndexOf('A') && s.indexOf('LLL') === -1; diff --git a/solution/0500-0599/0551.Student Attendance Record I/README_EN.md b/solution/0500-0599/0551.Student Attendance Record I/README_EN.md index cc1abe8abfdd7..4e24fc6315937 100644 --- a/solution/0500-0599/0551.Student Attendance Record I/README_EN.md +++ b/solution/0500-0599/0551.Student Attendance Record I/README_EN.md @@ -68,12 +68,16 @@ tags: +#### Python3 + ```python class Solution: def checkRecord(self, s: str) -> bool: return s.count('A') < 2 and 'LLL' not in s ``` +#### Java + ```java class Solution { public boolean checkRecord(String s) { @@ -82,6 +86,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -91,12 +97,16 @@ public: }; ``` +#### Go + ```go func checkRecord(s string) bool { return strings.Count(s, "A") < 2 && !strings.Contains(s, "LLL") } ``` +#### TypeScript + ```ts function checkRecord(s: string): boolean { return s.indexOf('A') === s.lastIndexOf('A') && s.indexOf('LLL') === -1; diff --git a/solution/0500-0599/0552.Student Attendance Record II/README.md b/solution/0500-0599/0552.Student Attendance Record II/README.md index 0ec029d39a6e9..d6de11d585520 100644 --- a/solution/0500-0599/0552.Student Attendance Record II/README.md +++ b/solution/0500-0599/0552.Student Attendance Record II/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def checkRecord(self, n: int) -> int: @@ -114,6 +116,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private final int mod = (int) 1e9 + 7; @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp int f[100010][2][3]; const int mod = 1e9 + 7; @@ -179,6 +185,8 @@ private: }; ``` +#### Go + ```go func checkRecord(n int) int { f := make([][][]int, n) @@ -232,6 +240,8 @@ func checkRecord(n int) int { +#### Python3 + ```python class Solution: def checkRecord(self, n: int) -> int: @@ -262,6 +272,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int MOD = 1000000007; @@ -298,6 +310,8 @@ class Solution { } ``` +#### C++ + ```cpp constexpr int MOD = 1e9 + 7; @@ -334,6 +348,8 @@ public: }; ``` +#### Go + ```go const _mod int = 1e9 + 7 diff --git a/solution/0500-0599/0552.Student Attendance Record II/README_EN.md b/solution/0500-0599/0552.Student Attendance Record II/README_EN.md index 603fc7907b3d8..ea40097f1e719 100644 --- a/solution/0500-0599/0552.Student Attendance Record II/README_EN.md +++ b/solution/0500-0599/0552.Student Attendance Record II/README_EN.md @@ -75,6 +75,8 @@ Only "AA" is not eligible because there are 2 absences (there need to +#### Python3 + ```python class Solution: def checkRecord(self, n: int) -> int: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private final int mod = (int) 1e9 + 7; @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp int f[100010][2][3]; const int mod = 1e9 + 7; @@ -161,6 +167,8 @@ private: }; ``` +#### Go + ```go func checkRecord(n int) int { f := make([][][]int, n) @@ -206,6 +214,8 @@ func checkRecord(n int) int { +#### Python3 + ```python class Solution: def checkRecord(self, n: int) -> int: @@ -236,6 +246,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int MOD = 1000000007; @@ -272,6 +284,8 @@ class Solution { } ``` +#### C++ + ```cpp constexpr int MOD = 1e9 + 7; @@ -308,6 +322,8 @@ public: }; ``` +#### Go + ```go const _mod int = 1e9 + 7 diff --git a/solution/0500-0599/0553.Optimal Division/README.md b/solution/0500-0599/0553.Optimal Division/README.md index ad24109ff4d7a..12f5ca390f051 100644 --- a/solution/0500-0599/0553.Optimal Division/README.md +++ b/solution/0500-0599/0553.Optimal Division/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def optimalDivision(self, nums: List[int]) -> str: @@ -90,6 +92,8 @@ class Solution: return f'{nums[0]}/({"/".join(map(str, nums[1:]))})' ``` +#### Java + ```java class Solution { public String optimalDivision(int[] nums) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func optimalDivision(nums []int) string { n := len(nums) @@ -145,6 +153,8 @@ func optimalDivision(nums []int) string { } ``` +#### TypeScript + ```ts function optimalDivision(nums: number[]): string { const n = nums.length; @@ -157,6 +167,8 @@ function optimalDivision(nums: number[]): string { } ``` +#### Rust + ```rust impl Solution { pub fn optimal_division(nums: Vec) -> String { diff --git a/solution/0500-0599/0553.Optimal Division/README_EN.md b/solution/0500-0599/0553.Optimal Division/README_EN.md index 776aed6643757..33fb325d1654f 100644 --- a/solution/0500-0599/0553.Optimal Division/README_EN.md +++ b/solution/0500-0599/0553.Optimal Division/README_EN.md @@ -74,6 +74,8 @@ It can be shown that after trying all possibilities, we cannot get an expression +#### Python3 + ```python class Solution: def optimalDivision(self, nums: List[int]) -> str: @@ -85,6 +87,8 @@ class Solution: return f'{nums[0]}/({"/".join(map(str, nums[1:]))})' ``` +#### Java + ```java class Solution { public String optimalDivision(int[] nums) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func optimalDivision(nums []int) string { n := len(nums) @@ -140,6 +148,8 @@ func optimalDivision(nums []int) string { } ``` +#### TypeScript + ```ts function optimalDivision(nums: number[]): string { const n = nums.length; @@ -152,6 +162,8 @@ function optimalDivision(nums: number[]): string { } ``` +#### Rust + ```rust impl Solution { pub fn optimal_division(nums: Vec) -> String { diff --git a/solution/0500-0599/0554.Brick Wall/README.md b/solution/0500-0599/0554.Brick Wall/README.md index aa6ac9c7b1a1c..9721672166d43 100644 --- a/solution/0500-0599/0554.Brick Wall/README.md +++ b/solution/0500-0599/0554.Brick Wall/README.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def leastBricks(self, wall: List[List[int]]) -> int: @@ -74,6 +76,8 @@ class Solution: return len(wall) - cnt[max(cnt, key=cnt.get)] ``` +#### Java + ```java class Solution { public int leastBricks(List> wall) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### Go + ```go func leastBricks(wall [][]int) int { cnt := make(map[int]int) @@ -111,6 +117,8 @@ func leastBricks(wall [][]int) int { } ``` +#### JavaScript + ```js /** * @param {number[][]} wall diff --git a/solution/0500-0599/0554.Brick Wall/README_EN.md b/solution/0500-0599/0554.Brick Wall/README_EN.md index 6b8231907312f..41253ff148ab2 100644 --- a/solution/0500-0599/0554.Brick Wall/README_EN.md +++ b/solution/0500-0599/0554.Brick Wall/README_EN.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def leastBricks(self, wall: List[List[int]]) -> int: @@ -74,6 +76,8 @@ class Solution: return len(wall) - cnt[max(cnt, key=cnt.get)] ``` +#### Java + ```java class Solution { public int leastBricks(List> wall) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### Go + ```go func leastBricks(wall [][]int) int { cnt := make(map[int]int) @@ -111,6 +117,8 @@ func leastBricks(wall [][]int) int { } ``` +#### JavaScript + ```js /** * @param {number[][]} wall diff --git a/solution/0500-0599/0555.Split Concatenated Strings/README.md b/solution/0500-0599/0555.Split Concatenated Strings/README.md index 7a8546c457097..8ab1dcb4eb954 100644 --- a/solution/0500-0599/0555.Split Concatenated Strings/README.md +++ b/solution/0500-0599/0555.Split Concatenated Strings/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def splitLoopedString(self, strs: List[str]) -> str: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String splitLoopedString(String[] strs) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func splitLoopedString(strs []string) (ans string) { for i, s := range strs { diff --git a/solution/0500-0599/0555.Split Concatenated Strings/README_EN.md b/solution/0500-0599/0555.Split Concatenated Strings/README_EN.md index 725a28cb6277f..1045aaa0f3373 100644 --- a/solution/0500-0599/0555.Split Concatenated Strings/README_EN.md +++ b/solution/0500-0599/0555.Split Concatenated Strings/README_EN.md @@ -68,6 +68,8 @@ The answer string came from the fourth looped one, where you could cut from the +#### Python3 + ```python class Solution: def splitLoopedString(self, strs: List[str]) -> str: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String splitLoopedString(String[] strs) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go func splitLoopedString(strs []string) (ans string) { for i, s := range strs { diff --git a/solution/0500-0599/0556.Next Greater Element III/README.md b/solution/0500-0599/0556.Next Greater Element III/README.md index dbc71d0cc2e1f..0b64db9a57d67 100644 --- a/solution/0500-0599/0556.Next Greater Element III/README.md +++ b/solution/0500-0599/0556.Next Greater Element III/README.md @@ -56,6 +56,8 @@ tags: +#### Python3 + ```python class Solution: def nextGreaterElement(self, n: int) -> int: @@ -74,6 +76,8 @@ class Solution: return -1 if ans > 2**31 - 1 else ans ``` +#### Java + ```java class Solution { public int nextGreaterElement(int n) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func nextGreaterElement(n int) int { s := []byte(strconv.Itoa(n)) diff --git a/solution/0500-0599/0556.Next Greater Element III/README_EN.md b/solution/0500-0599/0556.Next Greater Element III/README_EN.md index 7881d1bb2622c..b45b0a602e104 100644 --- a/solution/0500-0599/0556.Next Greater Element III/README_EN.md +++ b/solution/0500-0599/0556.Next Greater Element III/README_EN.md @@ -47,6 +47,8 @@ tags: +#### Python3 + ```python class Solution: def nextGreaterElement(self, n: int) -> int: @@ -65,6 +67,8 @@ class Solution: return -1 if ans > 2**31 - 1 else ans ``` +#### Java + ```java class Solution { public int nextGreaterElement(int n) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func nextGreaterElement(n int) int { s := []byte(strconv.Itoa(n)) diff --git a/solution/0500-0599/0557.Reverse Words in a String III/README.md b/solution/0500-0599/0557.Reverse Words in a String III/README.md index 1a08f8bfa71a2..3a813faa30db1 100644 --- a/solution/0500-0599/0557.Reverse Words in a String III/README.md +++ b/solution/0500-0599/0557.Reverse Words in a String III/README.md @@ -57,12 +57,16 @@ tags: +#### Python3 + ```python class Solution: def reverseWords(self, s: str) -> str: return ' '.join([t[::-1] for t in s.split(' ')]) ``` +#### Java + ```java class Solution { public String reverseWords(String s) { @@ -78,6 +82,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -94,6 +100,8 @@ public: }; ``` +#### Go + ```go func reverseWords(s string) string { t := []byte(s) @@ -111,6 +119,8 @@ func reverseWords(s string) string { } ``` +#### TypeScript + ```ts function reverseWords(s: string): string { return s @@ -126,6 +136,8 @@ function reverseWords(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn reverse_words(s: String) -> String { @@ -137,6 +149,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0500-0599/0557.Reverse Words in a String III/README_EN.md b/solution/0500-0599/0557.Reverse Words in a String III/README_EN.md index 97d3961952df6..a98096a9cc6d0 100644 --- a/solution/0500-0599/0557.Reverse Words in a String III/README_EN.md +++ b/solution/0500-0599/0557.Reverse Words in a String III/README_EN.md @@ -55,12 +55,16 @@ tags: +#### Python3 + ```python class Solution: def reverseWords(self, s: str) -> str: return ' '.join([t[::-1] for t in s.split(' ')]) ``` +#### Java + ```java class Solution { public String reverseWords(String s) { @@ -76,6 +80,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -92,6 +98,8 @@ public: }; ``` +#### Go + ```go func reverseWords(s string) string { t := []byte(s) @@ -109,6 +117,8 @@ func reverseWords(s string) string { } ``` +#### TypeScript + ```ts function reverseWords(s: string): string { return s @@ -124,6 +134,8 @@ function reverseWords(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn reverse_words(s: String) -> String { @@ -135,6 +147,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0500-0599/0558.Logical OR of Two Binary Grids Represented as Quad-Trees/README.md b/solution/0500-0599/0558.Logical OR of Two Binary Grids Represented as Quad-Trees/README.md index 3c60b20c4b2b6..77b49d5f8bd0b 100644 --- a/solution/0500-0599/0558.Logical OR of Two Binary Grids Represented as Quad-Trees/README.md +++ b/solution/0500-0599/0558.Logical OR of Two Binary Grids Represented as Quad-Trees/README.md @@ -131,6 +131,8 @@ class Node { +#### Python3 + ```python """ # Definition for a QuadTree node. @@ -178,6 +180,8 @@ class Solution: return dfs(quadTree1, quadTree2) ``` +#### Java + ```java /* // Definition for a QuadTree node. @@ -230,6 +234,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a QuadTree node. @@ -294,6 +300,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a QuadTree node. diff --git a/solution/0500-0599/0558.Logical OR of Two Binary Grids Represented as Quad-Trees/README_EN.md b/solution/0500-0599/0558.Logical OR of Two Binary Grids Represented as Quad-Trees/README_EN.md index b4cb9cbf31991..e53a669c863b3 100644 --- a/solution/0500-0599/0558.Logical OR of Two Binary Grids Represented as Quad-Trees/README_EN.md +++ b/solution/0500-0599/0558.Logical OR of Two Binary Grids Represented as Quad-Trees/README_EN.md @@ -100,6 +100,8 @@ The resulting matrix is of size 1*1 with also zero. +#### Python3 + ```python """ # Definition for a QuadTree node. @@ -147,6 +149,8 @@ class Solution: return dfs(quadTree1, quadTree2) ``` +#### Java + ```java /* // Definition for a QuadTree node. @@ -199,6 +203,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a QuadTree node. @@ -263,6 +269,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a QuadTree node. diff --git a/solution/0500-0599/0559.Maximum Depth of N-ary Tree/README.md b/solution/0500-0599/0559.Maximum Depth of N-ary Tree/README.md index fb5a801a5516b..2e62530b63567 100644 --- a/solution/0500-0599/0559.Maximum Depth of N-ary Tree/README.md +++ b/solution/0500-0599/0559.Maximum Depth of N-ary Tree/README.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python """ # Definition for a Node. @@ -80,6 +82,8 @@ class Solution: return 1 + max([self.maxDepth(child) for child in root.children], default=0) ``` +#### Java + ```java /* // Definition for a Node. @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. diff --git a/solution/0500-0599/0559.Maximum Depth of N-ary Tree/README_EN.md b/solution/0500-0599/0559.Maximum Depth of N-ary Tree/README_EN.md index 7a0b8cb56215f..e22ba845c876f 100644 --- a/solution/0500-0599/0559.Maximum Depth of N-ary Tree/README_EN.md +++ b/solution/0500-0599/0559.Maximum Depth of N-ary Tree/README_EN.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python """ # Definition for a Node. @@ -78,6 +80,8 @@ class Solution: return 1 + max([self.maxDepth(child) for child in root.children], default=0) ``` +#### Java + ```java /* // Definition for a Node. @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. diff --git a/solution/0500-0599/0560.Subarray Sum Equals K/README.md b/solution/0500-0599/0560.Subarray Sum Equals K/README.md index cc2c5641f6981..2b2f7d4f4a3d2 100644 --- a/solution/0500-0599/0560.Subarray Sum Equals K/README.md +++ b/solution/0500-0599/0560.Subarray Sum Equals K/README.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python class Solution: def subarraySum(self, nums: List[int], k: int) -> int: @@ -70,6 +72,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int subarraySum(int[] nums, int k) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -103,6 +109,8 @@ public: }; ``` +#### Go + ```go func subarraySum(nums []int, k int) int { counter := map[int]int{0: 1} @@ -116,6 +124,8 @@ func subarraySum(nums []int, k int) int { } ``` +#### TypeScript + ```ts function subarraySum(nums: number[], k: number): number { let ans = 0, @@ -131,6 +141,8 @@ function subarraySum(nums: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn subarray_sum(mut nums: Vec, k: i32) -> i32 { @@ -163,6 +175,8 @@ impl Solution { +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/0500-0599/0560.Subarray Sum Equals K/README_EN.md b/solution/0500-0599/0560.Subarray Sum Equals K/README_EN.md index e542ebed3e14f..438e96d7c055c 100644 --- a/solution/0500-0599/0560.Subarray Sum Equals K/README_EN.md +++ b/solution/0500-0599/0560.Subarray Sum Equals K/README_EN.md @@ -49,6 +49,8 @@ tags: +#### Python3 + ```python class Solution: def subarraySum(self, nums: List[int], k: int) -> int: @@ -61,6 +63,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int subarraySum(int[] nums, int k) { @@ -77,6 +81,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -94,6 +100,8 @@ public: }; ``` +#### Go + ```go func subarraySum(nums []int, k int) int { counter := map[int]int{0: 1} @@ -107,6 +115,8 @@ func subarraySum(nums []int, k int) int { } ``` +#### TypeScript + ```ts function subarraySum(nums: number[], k: number): number { let ans = 0, @@ -122,6 +132,8 @@ function subarraySum(nums: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn subarray_sum(mut nums: Vec, k: i32) -> i32 { @@ -154,6 +166,8 @@ impl Solution { +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/0500-0599/0561.Array Partition/README.md b/solution/0500-0599/0561.Array Partition/README.md index 2d09fe2fb0f38..8461970b214e6 100644 --- a/solution/0500-0599/0561.Array Partition/README.md +++ b/solution/0500-0599/0561.Array Partition/README.md @@ -66,12 +66,16 @@ tags: +#### Python3 + ```python class Solution: def arrayPairSum(self, nums: List[int]) -> int: return sum(sorted(nums)[::2]) ``` +#### Java + ```java class Solution { public int arrayPairSum(int[] nums) { @@ -85,6 +89,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -97,6 +103,8 @@ public: }; ``` +#### Go + ```go func arrayPairSum(nums []int) int { sort.Ints(nums) @@ -108,6 +116,8 @@ func arrayPairSum(nums []int) int { } ``` +#### Rust + ```rust impl Solution { pub fn array_pair_sum(mut nums: Vec) -> i32 { @@ -124,6 +134,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0500-0599/0561.Array Partition/README_EN.md b/solution/0500-0599/0561.Array Partition/README_EN.md index 44af1686e2352..8c913c344047e 100644 --- a/solution/0500-0599/0561.Array Partition/README_EN.md +++ b/solution/0500-0599/0561.Array Partition/README_EN.md @@ -60,12 +60,16 @@ So the maximum possible sum is 4. +#### Python3 + ```python class Solution: def arrayPairSum(self, nums: List[int]) -> int: return sum(sorted(nums)[::2]) ``` +#### Java + ```java class Solution { public int arrayPairSum(int[] nums) { @@ -79,6 +83,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -91,6 +97,8 @@ public: }; ``` +#### Go + ```go func arrayPairSum(nums []int) int { sort.Ints(nums) @@ -102,6 +110,8 @@ func arrayPairSum(nums []int) int { } ``` +#### Rust + ```rust impl Solution { pub fn array_pair_sum(mut nums: Vec) -> i32 { @@ -118,6 +128,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0500-0599/0562.Longest Line of Consecutive One in Matrix/README.md b/solution/0500-0599/0562.Longest Line of Consecutive One in Matrix/README.md index f471b689077cb..752d109dd4be2 100644 --- a/solution/0500-0599/0562.Longest Line of Consecutive One in Matrix/README.md +++ b/solution/0500-0599/0562.Longest Line of Consecutive One in Matrix/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def longestLine(self, mat: List[List[int]]) -> int: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestLine(int[][] mat) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func longestLine(mat [][]int) (ans int) { m, n := len(mat), len(mat[0]) diff --git a/solution/0500-0599/0562.Longest Line of Consecutive One in Matrix/README_EN.md b/solution/0500-0599/0562.Longest Line of Consecutive One in Matrix/README_EN.md index f24efb4382505..1de17cddf10cb 100644 --- a/solution/0500-0599/0562.Longest Line of Consecutive One in Matrix/README_EN.md +++ b/solution/0500-0599/0562.Longest Line of Consecutive One in Matrix/README_EN.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python class Solution: def longestLine(self, mat: List[List[int]]) -> int: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestLine(int[][] mat) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func longestLine(mat [][]int) (ans int) { m, n := len(mat), len(mat[0]) diff --git a/solution/0500-0599/0563.Binary Tree Tilt/README.md b/solution/0500-0599/0563.Binary Tree Tilt/README.md index 51a41ac8bbef6..dc1ff5a05ab75 100644 --- a/solution/0500-0599/0563.Binary Tree Tilt/README.md +++ b/solution/0500-0599/0563.Binary Tree Tilt/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -103,6 +105,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0500-0599/0563.Binary Tree Tilt/README_EN.md b/solution/0500-0599/0563.Binary Tree Tilt/README_EN.md index ae19aca4cbcf6..ac323a07bd1f4 100644 --- a/solution/0500-0599/0563.Binary Tree Tilt/README_EN.md +++ b/solution/0500-0599/0563.Binary Tree Tilt/README_EN.md @@ -75,6 +75,8 @@ Sum of every tilt : 0 + 0 + 0 + 2 + 7 + 6 = 15 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0500-0599/0564.Find the Closest Palindrome/README.md b/solution/0500-0599/0564.Find the Closest Palindrome/README.md index cc92926603d63..123515afac70c 100644 --- a/solution/0500-0599/0564.Find the Closest Palindrome/README.md +++ b/solution/0500-0599/0564.Find the Closest Palindrome/README.md @@ -59,6 +59,8 @@ tags: +#### Python3 + ```python class Solution: def nearestPalindromic(self, n: str) -> str: @@ -85,6 +87,8 @@ class Solution: return str(ans) ``` +#### Java + ```java class Solution { public String nearestPalindromic(String n) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func nearestPalindromic(n string) string { l := len(n) diff --git a/solution/0500-0599/0564.Find the Closest Palindrome/README_EN.md b/solution/0500-0599/0564.Find the Closest Palindrome/README_EN.md index c937fe631797e..2fdebc09b7c24 100644 --- a/solution/0500-0599/0564.Find the Closest Palindrome/README_EN.md +++ b/solution/0500-0599/0564.Find the Closest Palindrome/README_EN.md @@ -57,6 +57,8 @@ tags: +#### Python3 + ```python class Solution: def nearestPalindromic(self, n: str) -> str: @@ -83,6 +85,8 @@ class Solution: return str(ans) ``` +#### Java + ```java class Solution { public String nearestPalindromic(String n) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func nearestPalindromic(n string) string { l := len(n) diff --git a/solution/0500-0599/0565.Array Nesting/README.md b/solution/0500-0599/0565.Array Nesting/README.md index 85ff8279e0be4..9bd6ca1612d4b 100644 --- a/solution/0500-0599/0565.Array Nesting/README.md +++ b/solution/0500-0599/0565.Array Nesting/README.md @@ -59,6 +59,8 @@ S[0] = {A[0], A[5], A[6], A[2]} = {5, 6, 2, 0} +#### Python3 + ```python class Solution: def arrayNesting(self, nums: List[int]) -> int: @@ -78,6 +80,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public int arrayNesting(int[] nums) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func arrayNesting(nums []int) int { n := len(nums) @@ -163,6 +171,8 @@ func arrayNesting(nums []int) int { +#### Python3 + ```python class Solution: def arrayNesting(self, nums: List[int]) -> int: @@ -178,6 +188,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int arrayNesting(int[] nums) { @@ -198,6 +210,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -219,6 +233,8 @@ public: }; ``` +#### Go + ```go func arrayNesting(nums []int) int { ans, n := 0, len(nums) diff --git a/solution/0500-0599/0565.Array Nesting/README_EN.md b/solution/0500-0599/0565.Array Nesting/README_EN.md index a78d982be4ad4..cdc49ffc973e2 100644 --- a/solution/0500-0599/0565.Array Nesting/README_EN.md +++ b/solution/0500-0599/0565.Array Nesting/README_EN.md @@ -67,6 +67,8 @@ s[0] = {nums[0], nums[5], nums[6], nums[2]} = {5, 6, 2, 0} +#### Python3 + ```python class Solution: def arrayNesting(self, nums: List[int]) -> int: @@ -86,6 +88,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public int arrayNesting(int[] nums) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func arrayNesting(nums []int) int { n := len(nums) @@ -167,6 +175,8 @@ func arrayNesting(nums []int) int { +#### Python3 + ```python class Solution: def arrayNesting(self, nums: List[int]) -> int: @@ -182,6 +192,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int arrayNesting(int[] nums) { @@ -202,6 +214,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -223,6 +237,8 @@ public: }; ``` +#### Go + ```go func arrayNesting(nums []int) int { ans, n := 0, len(nums) diff --git a/solution/0500-0599/0566.Reshape the Matrix/README.md b/solution/0500-0599/0566.Reshape the Matrix/README.md index 947399a381820..244961adf748f 100644 --- a/solution/0500-0599/0566.Reshape the Matrix/README.md +++ b/solution/0500-0599/0566.Reshape the Matrix/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def matrixReshape(self, mat: List[List[int]], r: int, c: int) -> List[List[int]]: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] matrixReshape(int[][] mat, int r, int c) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func matrixReshape(mat [][]int, r int, c int) [][]int { m, n := len(mat), len(mat[0]) @@ -134,6 +142,8 @@ func matrixReshape(mat [][]int, r int, c int) [][]int { } ``` +#### TypeScript + ```ts function matrixReshape(mat: number[][], r: number, c: number): number[][] { let m = mat.length, @@ -151,6 +161,8 @@ function matrixReshape(mat: number[][], r: number, c: number): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn matrix_reshape(mat: Vec>, r: i32, c: i32) -> Vec> { @@ -184,6 +196,8 @@ impl Solution { } ``` +#### C + ```c /** * Return an array of arrays of size *returnSize. @@ -220,6 +234,8 @@ int** matrixReshape(int** mat, int matSize, int* matColSize, int r, int c, int* +#### TypeScript + ```ts function matrixReshape(mat: number[][], r: number, c: number): number[][] { const m = mat.length; diff --git a/solution/0500-0599/0566.Reshape the Matrix/README_EN.md b/solution/0500-0599/0566.Reshape the Matrix/README_EN.md index c198f7cb09861..fa4bc220d8cd8 100644 --- a/solution/0500-0599/0566.Reshape the Matrix/README_EN.md +++ b/solution/0500-0599/0566.Reshape the Matrix/README_EN.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def matrixReshape(self, mat: List[List[int]], r: int, c: int) -> List[List[int]]: @@ -74,6 +76,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] matrixReshape(int[][] mat, int r, int c) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func matrixReshape(mat [][]int, r int, c int) [][]int { m, n := len(mat), len(mat[0]) @@ -124,6 +132,8 @@ func matrixReshape(mat [][]int, r int, c int) [][]int { } ``` +#### TypeScript + ```ts function matrixReshape(mat: number[][], r: number, c: number): number[][] { let m = mat.length, @@ -141,6 +151,8 @@ function matrixReshape(mat: number[][], r: number, c: number): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn matrix_reshape(mat: Vec>, r: i32, c: i32) -> Vec> { @@ -174,6 +186,8 @@ impl Solution { } ``` +#### C + ```c /** * Return an array of arrays of size *returnSize. @@ -210,6 +224,8 @@ int** matrixReshape(int** mat, int matSize, int* matColSize, int r, int c, int* +#### TypeScript + ```ts function matrixReshape(mat: number[][], r: number, c: number): number[][] { const m = mat.length; diff --git a/solution/0500-0599/0567.Permutation in String/README.md b/solution/0500-0599/0567.Permutation in String/README.md index 8d38f1674fca6..5220856ba65d6 100644 --- a/solution/0500-0599/0567.Permutation in String/README.md +++ b/solution/0500-0599/0567.Permutation in String/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def checkInclusion(self, s1: str, s2: str) -> bool: @@ -83,6 +85,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean checkInclusion(String s1, String s2) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func checkInclusion(s1 string, s2 string) bool { n, m := len(s1), len(s2) @@ -166,6 +174,8 @@ func checkInclusion(s1 string, s2 string) bool { } ``` +#### TypeScript + ```ts function checkInclusion(s1: string, s2: string): boolean { // 滑动窗口方案 @@ -212,6 +222,8 @@ function checkInclusion(s1: string, s2: string): boolean { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -275,6 +287,8 @@ impl Solution { +#### Python3 + ```python class Solution: def checkInclusion(self, s1: str, s2: str) -> bool: @@ -308,6 +322,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean checkInclusion(String s1, String s2) { @@ -354,6 +370,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -400,6 +418,8 @@ public: }; ``` +#### Go + ```go func checkInclusion(s1 string, s2 string) bool { n, m := len(s1), len(s2) @@ -454,6 +474,8 @@ func checkInclusion(s1 string, s2 string) bool { +#### Go + ```go func checkInclusion(s1 string, s2 string) bool { need, window := make(map[byte]int), make(map[byte]int) diff --git a/solution/0500-0599/0567.Permutation in String/README_EN.md b/solution/0500-0599/0567.Permutation in String/README_EN.md index 360fe0a65ccd8..c1b2e53496686 100644 --- a/solution/0500-0599/0567.Permutation in String/README_EN.md +++ b/solution/0500-0599/0567.Permutation in String/README_EN.md @@ -57,6 +57,8 @@ tags: +#### Python3 + ```python class Solution: def checkInclusion(self, s1: str, s2: str) -> bool: @@ -73,6 +75,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean checkInclusion(String s1, String s2) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func checkInclusion(s1 string, s2 string) bool { n, m := len(s1), len(s2) @@ -156,6 +164,8 @@ func checkInclusion(s1 string, s2 string) bool { } ``` +#### TypeScript + ```ts function checkInclusion(s1: string, s2: string): boolean { // 滑动窗口方案 @@ -202,6 +212,8 @@ function checkInclusion(s1: string, s2: string): boolean { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -261,6 +273,8 @@ impl Solution { +#### Python3 + ```python class Solution: def checkInclusion(self, s1: str, s2: str) -> bool: @@ -294,6 +308,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean checkInclusion(String s1, String s2) { @@ -340,6 +356,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -386,6 +404,8 @@ public: }; ``` +#### Go + ```go func checkInclusion(s1 string, s2 string) bool { n, m := len(s1), len(s2) @@ -440,6 +460,8 @@ func checkInclusion(s1 string, s2 string) bool { +#### Go + ```go func checkInclusion(s1 string, s2 string) bool { need, window := make(map[byte]int), make(map[byte]int) diff --git a/solution/0500-0599/0568.Maximum Vacation Days/README.md b/solution/0500-0599/0568.Maximum Vacation Days/README.md index ffa280c8fb114..0b759e9bf93c8 100644 --- a/solution/0500-0599/0568.Maximum Vacation Days/README.md +++ b/solution/0500-0599/0568.Maximum Vacation Days/README.md @@ -106,6 +106,8 @@ Ans = 7 + 7 + 7 = 21 +#### Python3 + ```python class Solution: def maxVacationDays(self, flights: List[List[int]], days: List[List[int]]) -> int: @@ -123,6 +125,8 @@ class Solution: return max(f[-1][j] for j in range(n)) ``` +#### Java + ```java class Solution { public int maxVacationDays(int[][] flights, int[][] days) { @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -183,6 +189,8 @@ public: }; ``` +#### Go + ```go func maxVacationDays(flights [][]int, days [][]int) (ans int) { n, K := len(flights), len(days[0]) diff --git a/solution/0500-0599/0568.Maximum Vacation Days/README_EN.md b/solution/0500-0599/0568.Maximum Vacation Days/README_EN.md index 2279cad9ac453..03606fb98ba45 100644 --- a/solution/0500-0599/0568.Maximum Vacation Days/README_EN.md +++ b/solution/0500-0599/0568.Maximum Vacation Days/README_EN.md @@ -97,6 +97,8 @@ Ans = 7 + 7 + 7 = 21 +#### Python3 + ```python class Solution: def maxVacationDays(self, flights: List[List[int]], days: List[List[int]]) -> int: @@ -114,6 +116,8 @@ class Solution: return max(f[-1][j] for j in range(n)) ``` +#### Java + ```java class Solution { public int maxVacationDays(int[][] flights, int[][] days) { @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func maxVacationDays(flights [][]int, days [][]int) (ans int) { n, K := len(flights), len(days[0]) diff --git a/solution/0500-0599/0569.Median Employee Salary/README.md b/solution/0500-0599/0569.Median Employee Salary/README.md index f91d0698c7e3d..a4ac20b3d2157 100644 --- a/solution/0500-0599/0569.Median Employee Salary/README.md +++ b/solution/0500-0599/0569.Median Employee Salary/README.md @@ -92,6 +92,8 @@ Employee 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0500-0599/0569.Median Employee Salary/README_EN.md b/solution/0500-0599/0569.Median Employee Salary/README_EN.md index afc9cba60bcea..18a6743e3f9b3 100644 --- a/solution/0500-0599/0569.Median Employee Salary/README_EN.md +++ b/solution/0500-0599/0569.Median Employee Salary/README_EN.md @@ -123,6 +123,8 @@ For company C, the rows sorted are as follows: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0500-0599/0570.Managers with at Least 5 Direct Reports/README.md b/solution/0500-0599/0570.Managers with at Least 5 Direct Reports/README.md index 17ee8440e7f87..49a7631d5f5de 100644 --- a/solution/0500-0599/0570.Managers with at Least 5 Direct Reports/README.md +++ b/solution/0500-0599/0570.Managers with at Least 5 Direct Reports/README.md @@ -77,6 +77,8 @@ Employee 表: +#### Python3 + ```python import pandas as pd @@ -101,6 +103,8 @@ def find_managers(employee: pd.DataFrame) -> pd.DataFrame: return result ``` +#### MySQL + ```sql # Write your MySQL query statement below SELECT name diff --git a/solution/0500-0599/0570.Managers with at Least 5 Direct Reports/README_EN.md b/solution/0500-0599/0570.Managers with at Least 5 Direct Reports/README_EN.md index 983ddc1d5c66b..c1c695aa0033b 100644 --- a/solution/0500-0599/0570.Managers with at Least 5 Direct Reports/README_EN.md +++ b/solution/0500-0599/0570.Managers with at Least 5 Direct Reports/README_EN.md @@ -77,6 +77,8 @@ We can first count the number of direct subordinates for each manager, and then +#### Python3 + ```python import pandas as pd @@ -101,6 +103,8 @@ def find_managers(employee: pd.DataFrame) -> pd.DataFrame: return result ``` +#### MySQL + ```sql # Write your MySQL query statement below SELECT name diff --git a/solution/0500-0599/0571.Find Median Given Frequency of Numbers/README.md b/solution/0500-0599/0571.Find Median Given Frequency of Numbers/README.md index 9b5defed347c6..96d073ea6215f 100644 --- a/solution/0500-0599/0571.Find Median Given Frequency of Numbers/README.md +++ b/solution/0500-0599/0571.Find Median Given Frequency of Numbers/README.md @@ -76,6 +76,8 @@ Numbers 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0500-0599/0571.Find Median Given Frequency of Numbers/README_EN.md b/solution/0500-0599/0571.Find Median Given Frequency of Numbers/README_EN.md index 4bacceb2a1f99..4c0bdd9d3241c 100644 --- a/solution/0500-0599/0571.Find Median Given Frequency of Numbers/README_EN.md +++ b/solution/0500-0599/0571.Find Median Given Frequency of Numbers/README_EN.md @@ -71,6 +71,8 @@ If we decompress the Numbers table, we will get [0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 2 +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0500-0599/0572.Subtree of Another Tree/README.md b/solution/0500-0599/0572.Subtree of Another Tree/README.md index 90f7d43549413..6c85faedc9b6a 100644 --- a/solution/0500-0599/0572.Subtree of Another Tree/README.md +++ b/solution/0500-0599/0572.Subtree of Another Tree/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -94,6 +96,8 @@ class Solution: ) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -186,6 +194,8 @@ func isSubtree(root *TreeNode, subRoot *TreeNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -219,6 +229,8 @@ function isSubtree(root: TreeNode | null, subRoot: TreeNode | null): boolean { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -276,6 +288,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0500-0599/0572.Subtree of Another Tree/README_EN.md b/solution/0500-0599/0572.Subtree of Another Tree/README_EN.md index 057123e6626de..17c1f8eecad78 100644 --- a/solution/0500-0599/0572.Subtree of Another Tree/README_EN.md +++ b/solution/0500-0599/0572.Subtree of Another Tree/README_EN.md @@ -59,6 +59,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -88,6 +90,8 @@ class Solution: ) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -180,6 +188,8 @@ func isSubtree(root *TreeNode, subRoot *TreeNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -213,6 +223,8 @@ function isSubtree(root: TreeNode | null, subRoot: TreeNode | null): boolean { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -270,6 +282,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0500-0599/0573.Squirrel Simulation/README.md b/solution/0500-0599/0573.Squirrel Simulation/README.md index 2c1f80d277560..a3530da45971c 100644 --- a/solution/0500-0599/0573.Squirrel Simulation/README.md +++ b/solution/0500-0599/0573.Squirrel Simulation/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def minDistance( @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minDistance(int height, int width, int[] tree, int[] squirrel, int[][] nuts) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func minDistance(height int, width int, tree []int, squirrel []int, nuts [][]int) int { f := func(a, b []int) int { diff --git a/solution/0500-0599/0573.Squirrel Simulation/README_EN.md b/solution/0500-0599/0573.Squirrel Simulation/README_EN.md index be192f5954225..dfadb00d58c65 100644 --- a/solution/0500-0599/0573.Squirrel Simulation/README_EN.md +++ b/solution/0500-0599/0573.Squirrel Simulation/README_EN.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def minDistance( @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minDistance(int height, int width, int[] tree, int[] squirrel, int[][] nuts) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func minDistance(height int, width int, tree []int, squirrel []int, nuts [][]int) int { f := func(a, b []int) int { diff --git a/solution/0500-0599/0574.Winning Candidate/README.md b/solution/0500-0599/0574.Winning Candidate/README.md index 7ec36b4e3f01d..b4a66650826a4 100644 --- a/solution/0500-0599/0574.Winning Candidate/README.md +++ b/solution/0500-0599/0574.Winning Candidate/README.md @@ -97,6 +97,8 @@ Vote table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -123,6 +125,8 @@ FROM +#### MySQL + ```sql # Write your MySQL query statement below SELECT name diff --git a/solution/0500-0599/0574.Winning Candidate/README_EN.md b/solution/0500-0599/0574.Winning Candidate/README_EN.md index acbbd0a774066..1912b6ff2fb38 100644 --- a/solution/0500-0599/0574.Winning Candidate/README_EN.md +++ b/solution/0500-0599/0574.Winning Candidate/README_EN.md @@ -99,6 +99,8 @@ The winner is candidate B. +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -125,6 +127,8 @@ FROM +#### MySQL + ```sql # Write your MySQL query statement below SELECT name diff --git a/solution/0500-0599/0575.Distribute Candies/README.md b/solution/0500-0599/0575.Distribute Candies/README.md index ae1073e2a3237..7a8493b9438a7 100644 --- a/solution/0500-0599/0575.Distribute Candies/README.md +++ b/solution/0500-0599/0575.Distribute Candies/README.md @@ -70,12 +70,16 @@ tags: +#### Python3 + ```python class Solution: def distributeCandies(self, candyType: List[int]) -> int: return min(len(candyType) >> 1, len(set(candyType))) ``` +#### Java + ```java class Solution { public int distributeCandies(int[] candyType) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -99,6 +105,8 @@ public: }; ``` +#### Go + ```go func distributeCandies(candyType []int) int { s := hashset.New() diff --git a/solution/0500-0599/0575.Distribute Candies/README_EN.md b/solution/0500-0599/0575.Distribute Candies/README_EN.md index 8b6dd0f766c48..de3c6104847b8 100644 --- a/solution/0500-0599/0575.Distribute Candies/README_EN.md +++ b/solution/0500-0599/0575.Distribute Candies/README_EN.md @@ -68,12 +68,16 @@ tags: +#### Python3 + ```python class Solution: def distributeCandies(self, candyType: List[int]) -> int: return min(len(candyType) >> 1, len(set(candyType))) ``` +#### Java + ```java class Solution { public int distributeCandies(int[] candyType) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -97,6 +103,8 @@ public: }; ``` +#### Go + ```go func distributeCandies(candyType []int) int { s := hashset.New() diff --git a/solution/0500-0599/0576.Out of Boundary Paths/README.md b/solution/0500-0599/0576.Out of Boundary Paths/README.md index fd102750aaa6b..d601637a01028 100644 --- a/solution/0500-0599/0576.Out of Boundary Paths/README.md +++ b/solution/0500-0599/0576.Out of Boundary Paths/README.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def findPaths( @@ -83,6 +85,8 @@ class Solution: return dfs(startRow, startColumn, maxMove) ``` +#### Java + ```java class Solution { private int m; @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func findPaths(m int, n int, maxMove int, startRow int, startColumn int) int { f := make([][][]int, m+1) @@ -206,6 +214,8 @@ func findPaths(m int, n int, maxMove int, startRow int, startColumn int) int { +#### Java + ```java class Solution { public int findPaths(int m, int n, int N, int i, int j) { diff --git a/solution/0500-0599/0576.Out of Boundary Paths/README_EN.md b/solution/0500-0599/0576.Out of Boundary Paths/README_EN.md index 0ea777ab3cf39..0bfcd2f4f2243 100644 --- a/solution/0500-0599/0576.Out of Boundary Paths/README_EN.md +++ b/solution/0500-0599/0576.Out of Boundary Paths/README_EN.md @@ -55,6 +55,8 @@ tags: +#### Python3 + ```python class Solution: def findPaths( @@ -77,6 +79,8 @@ class Solution: return dfs(startRow, startColumn, maxMove) ``` +#### Java + ```java class Solution { private int m; @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func findPaths(m int, n int, maxMove int, startRow int, startColumn int) int { f := make([][][]int, m+1) @@ -200,6 +208,8 @@ func findPaths(m int, n int, maxMove int, startRow int, startColumn int) int { +#### Java + ```java class Solution { public int findPaths(int m, int n, int N, int i, int j) { diff --git a/solution/0500-0599/0577.Employee Bonus/README.md b/solution/0500-0599/0577.Employee Bonus/README.md index 38f9b03614c9f..9d332503083dd 100644 --- a/solution/0500-0599/0577.Employee Bonus/README.md +++ b/solution/0500-0599/0577.Employee Bonus/README.md @@ -98,6 +98,8 @@ Bonus table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT name, bonus diff --git a/solution/0500-0599/0577.Employee Bonus/README_EN.md b/solution/0500-0599/0577.Employee Bonus/README_EN.md index 2b148bc049def..a5d1db9f9c38d 100644 --- a/solution/0500-0599/0577.Employee Bonus/README_EN.md +++ b/solution/0500-0599/0577.Employee Bonus/README_EN.md @@ -98,6 +98,8 @@ We can use a left join to join the `Employee` table and the `Bonus` table on `em +#### MySQL + ```sql # Write your MySQL query statement below SELECT name, bonus diff --git a/solution/0500-0599/0578.Get Highest Answer Rate Question/README.md b/solution/0500-0599/0578.Get Highest Answer Rate Question/README.md index 075c10070b79d..6f3e146b4c68f 100644 --- a/solution/0500-0599/0578.Get Highest Answer Rate Question/README.md +++ b/solution/0500-0599/0578.Get Highest Answer Rate Question/README.md @@ -84,6 +84,8 @@ SurveyLog table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT question_id AS survey_log @@ -103,6 +105,8 @@ LIMIT 1; +#### MySQL + ```sql WITH T AS ( diff --git a/solution/0500-0599/0578.Get Highest Answer Rate Question/README_EN.md b/solution/0500-0599/0578.Get Highest Answer Rate Question/README_EN.md index cbb1475b44c10..05a93484f97ac 100644 --- a/solution/0500-0599/0578.Get Highest Answer Rate Question/README_EN.md +++ b/solution/0500-0599/0578.Get Highest Answer Rate Question/README_EN.md @@ -79,6 +79,8 @@ Question 285 has the highest answer rate. +#### MySQL + ```sql # Write your MySQL query statement below SELECT question_id AS survey_log @@ -98,6 +100,8 @@ LIMIT 1; +#### MySQL + ```sql WITH T AS ( diff --git a/solution/0500-0599/0579.Find Cumulative Salary of an Employee/README.md b/solution/0500-0599/0579.Find Cumulative Salary of an Employee/README.md index d21ac534645f4..3b4d0201bd9aa 100644 --- a/solution/0500-0599/0579.Find Cumulative Salary of an Employee/README.md +++ b/solution/0500-0599/0579.Find Cumulative Salary of an Employee/README.md @@ -128,6 +128,8 @@ Employee table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -160,6 +162,8 @@ ORDER BY id, month DESC; +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0500-0599/0579.Find Cumulative Salary of an Employee/README_EN.md b/solution/0500-0599/0579.Find Cumulative Salary of an Employee/README_EN.md index e9ce14fd6443d..dab9969fd7842 100644 --- a/solution/0500-0599/0579.Find Cumulative Salary of an Employee/README_EN.md +++ b/solution/0500-0599/0579.Find Cumulative Salary of an Employee/README_EN.md @@ -128,6 +128,8 @@ So the cumulative salary summary for this employee is: +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -160,6 +162,8 @@ ORDER BY id, month DESC; +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0500-0599/0580.Count Student Number in Departments/README.md b/solution/0500-0599/0580.Count Student Number in Departments/README.md index a2a3638d4378f..2fd24d63a0571 100644 --- a/solution/0500-0599/0580.Count Student Number in Departments/README.md +++ b/solution/0500-0599/0580.Count Student Number in Departments/README.md @@ -97,6 +97,8 @@ Department 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT dept_name, COUNT(student_id) AS student_number diff --git a/solution/0500-0599/0580.Count Student Number in Departments/README_EN.md b/solution/0500-0599/0580.Count Student Number in Departments/README_EN.md index 3d036bbcbd0c4..8422293a61732 100644 --- a/solution/0500-0599/0580.Count Student Number in Departments/README_EN.md +++ b/solution/0500-0599/0580.Count Student Number in Departments/README_EN.md @@ -98,6 +98,8 @@ We can use a left join to join the `Department` table and the `Student` table on +#### MySQL + ```sql # Write your MySQL query statement below SELECT dept_name, COUNT(student_id) AS student_number diff --git a/solution/0500-0599/0581.Shortest Unsorted Continuous Subarray/README.md b/solution/0500-0599/0581.Shortest Unsorted Continuous Subarray/README.md index 4a45576ab5726..6d3765e61f6cb 100644 --- a/solution/0500-0599/0581.Shortest Unsorted Continuous Subarray/README.md +++ b/solution/0500-0599/0581.Shortest Unsorted Continuous Subarray/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def findUnsortedSubarray(self, nums: List[int]) -> int: @@ -92,6 +94,8 @@ class Solution: return r - l + 1 ``` +#### Java + ```java class Solution { public int findUnsortedSubarray(int[] nums) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func findUnsortedSubarray(nums []int) int { arr := make([]int, len(nums)) @@ -143,6 +151,8 @@ func findUnsortedSubarray(nums []int) int { } ``` +#### TypeScript + ```ts function findUnsortedSubarray(nums: number[]): number { const arr = [...nums]; @@ -158,6 +168,8 @@ function findUnsortedSubarray(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_unsorted_subarray(nums: Vec) -> i32 { @@ -205,6 +217,8 @@ impl Solution { +#### Python3 + ```python class Solution: def findUnsortedSubarray(self, nums: List[int]) -> int: @@ -223,6 +237,8 @@ class Solution: return 0 if r == -1 else r - l + 1 ``` +#### Java + ```java class Solution { public int findUnsortedSubarray(int[] nums) { @@ -247,6 +263,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -272,6 +290,8 @@ public: }; ``` +#### Go + ```go func findUnsortedSubarray(nums []int) int { const inf = 1 << 30 @@ -297,6 +317,8 @@ func findUnsortedSubarray(nums []int) int { } ``` +#### TypeScript + ```ts function findUnsortedSubarray(nums: number[]): number { let [l, r] = [-1, -1]; diff --git a/solution/0500-0599/0581.Shortest Unsorted Continuous Subarray/README_EN.md b/solution/0500-0599/0581.Shortest Unsorted Continuous Subarray/README_EN.md index 21a2e69023df1..75d9d3a8fd1b0 100644 --- a/solution/0500-0599/0581.Shortest Unsorted Continuous Subarray/README_EN.md +++ b/solution/0500-0599/0581.Shortest Unsorted Continuous Subarray/README_EN.md @@ -73,6 +73,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def findUnsortedSubarray(self, nums: List[int]) -> int: @@ -85,6 +87,8 @@ class Solution: return r - l + 1 ``` +#### Java + ```java class Solution { public int findUnsortedSubarray(int[] nums) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func findUnsortedSubarray(nums []int) int { arr := make([]int, len(nums)) @@ -136,6 +144,8 @@ func findUnsortedSubarray(nums []int) int { } ``` +#### TypeScript + ```ts function findUnsortedSubarray(nums: number[]): number { const arr = [...nums]; @@ -151,6 +161,8 @@ function findUnsortedSubarray(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_unsorted_subarray(nums: Vec) -> i32 { @@ -198,6 +210,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is +#### Python3 + ```python class Solution: def findUnsortedSubarray(self, nums: List[int]) -> int: @@ -216,6 +230,8 @@ class Solution: return 0 if r == -1 else r - l + 1 ``` +#### Java + ```java class Solution { public int findUnsortedSubarray(int[] nums) { @@ -240,6 +256,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -265,6 +283,8 @@ public: }; ``` +#### Go + ```go func findUnsortedSubarray(nums []int) int { const inf = 1 << 30 @@ -290,6 +310,8 @@ func findUnsortedSubarray(nums []int) int { } ``` +#### TypeScript + ```ts function findUnsortedSubarray(nums: number[]): number { let [l, r] = [-1, -1]; diff --git a/solution/0500-0599/0582.Kill Process/README.md b/solution/0500-0599/0582.Kill Process/README.md index d98688caba4be..c4e4ad9da1ef8 100644 --- a/solution/0500-0599/0582.Kill Process/README.md +++ b/solution/0500-0599/0582.Kill Process/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def killProcess(self, pid: List[int], ppid: List[int], kill: int) -> List[int]: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private Map> g = new HashMap<>(); @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func killProcess(pid []int, ppid []int, kill int) (ans []int) { g := map[int][]int{} @@ -152,6 +160,8 @@ func killProcess(pid []int, ppid []int, kill int) (ans []int) { } ``` +#### TypeScript + ```ts function killProcess(pid: number[], ppid: number[], kill: number): number[] { const g: Map = new Map(); @@ -173,6 +183,8 @@ function killProcess(pid: number[], ppid: number[], kill: number): number[] { } ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/0500-0599/0582.Kill Process/README_EN.md b/solution/0500-0599/0582.Kill Process/README_EN.md index 0b4fe0ce6b1e6..41513a4f1385e 100644 --- a/solution/0500-0599/0582.Kill Process/README_EN.md +++ b/solution/0500-0599/0582.Kill Process/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def killProcess(self, pid: List[int], ppid: List[int], kill: int) -> List[int]: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private Map> g = new HashMap<>(); @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func killProcess(pid []int, ppid []int, kill int) (ans []int) { g := map[int][]int{} @@ -151,6 +159,8 @@ func killProcess(pid []int, ppid []int, kill int) (ans []int) { } ``` +#### TypeScript + ```ts function killProcess(pid: number[], ppid: number[], kill: number): number[] { const g: Map = new Map(); @@ -172,6 +182,8 @@ function killProcess(pid: number[], ppid: number[], kill: number): number[] { } ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/0500-0599/0583.Delete Operation for Two Strings/README.md b/solution/0500-0599/0583.Delete Operation for Two Strings/README.md index 24f4c4dcf23af..c54ea51fb9191 100644 --- a/solution/0500-0599/0583.Delete Operation for Two Strings/README.md +++ b/solution/0500-0599/0583.Delete Operation for Two Strings/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def minDistance(self, word1: str, word2: str) -> int: @@ -82,6 +84,8 @@ class Solution: return dp[-1][-1] ``` +#### Java + ```java class Solution { public int minDistance(String word1, String word2) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func minDistance(word1 string, word2 string) int { m, n := len(word1), len(word2) @@ -152,6 +160,8 @@ func minDistance(word1 string, word2 string) int { } ``` +#### TypeScript + ```ts function minDistance(word1: string, word2: string): number { const m = word1.length; @@ -171,6 +181,8 @@ function minDistance(word1: string, word2: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_distance(word1: String, word2: String) -> i32 { diff --git a/solution/0500-0599/0583.Delete Operation for Two Strings/README_EN.md b/solution/0500-0599/0583.Delete Operation for Two Strings/README_EN.md index 336e4de953931..7cab7574fb2eb 100644 --- a/solution/0500-0599/0583.Delete Operation for Two Strings/README_EN.md +++ b/solution/0500-0599/0583.Delete Operation for Two Strings/README_EN.md @@ -55,6 +55,8 @@ tags: +#### Python3 + ```python class Solution: def minDistance(self, word1: str, word2: str) -> int: @@ -73,6 +75,8 @@ class Solution: return dp[-1][-1] ``` +#### Java + ```java class Solution { public int minDistance(String word1, String word2) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func minDistance(word1 string, word2 string) int { m, n := len(word1), len(word2) @@ -143,6 +151,8 @@ func minDistance(word1 string, word2 string) int { } ``` +#### TypeScript + ```ts function minDistance(word1: string, word2: string): number { const m = word1.length; @@ -162,6 +172,8 @@ function minDistance(word1: string, word2: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_distance(word1: String, word2: String) -> i32 { diff --git a/solution/0500-0599/0584.Find Customer Referee/README.md b/solution/0500-0599/0584.Find Customer Referee/README.md index 1105a2336ccb1..5c2a099a2d835 100644 --- a/solution/0500-0599/0584.Find Customer Referee/README.md +++ b/solution/0500-0599/0584.Find Customer Referee/README.md @@ -74,6 +74,8 @@ Customer 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT name diff --git a/solution/0500-0599/0584.Find Customer Referee/README_EN.md b/solution/0500-0599/0584.Find Customer Referee/README_EN.md index 9713f74489c37..d6810684bb34e 100644 --- a/solution/0500-0599/0584.Find Customer Referee/README_EN.md +++ b/solution/0500-0599/0584.Find Customer Referee/README_EN.md @@ -77,6 +77,8 @@ We can directly filter out the customer names whose `referee_id` is not `2`. Not +#### MySQL + ```sql # Write your MySQL query statement below SELECT name diff --git a/solution/0500-0599/0585.Investments in 2016/README.md b/solution/0500-0599/0585.Investments in 2016/README.md index d8c369cd53b8f..ffd07b934cd50 100644 --- a/solution/0500-0599/0585.Investments in 2016/README.md +++ b/solution/0500-0599/0585.Investments in 2016/README.md @@ -90,6 +90,8 @@ tiv_2015 值为 10 与第三条和第四条记录相同,且其位置是唯一 +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0500-0599/0585.Investments in 2016/README_EN.md b/solution/0500-0599/0585.Investments in 2016/README_EN.md index 484a550354405..6358fce005e44 100644 --- a/solution/0500-0599/0585.Investments in 2016/README_EN.md +++ b/solution/0500-0599/0585.Investments in 2016/README_EN.md @@ -87,6 +87,8 @@ So, the result is the sum of tiv_2016 of the first and last record, which is 45. +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0500-0599/0586.Customer Placing the Largest Number of Orders/README.md b/solution/0500-0599/0586.Customer Placing the Largest Number of Orders/README.md index 46737967db648..19e2c3f544955 100644 --- a/solution/0500-0599/0586.Customer Placing the Largest Number of Orders/README.md +++ b/solution/0500-0599/0586.Customer Placing the Largest Number of Orders/README.md @@ -79,6 +79,8 @@ customer_number 为 '3' 的顾客有两个订单,比顾客 '1' 或者 '2' 都 +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -99,6 +101,8 @@ LIMIT 1; +#### MySQL + ```sql /* Write your T-SQL query statement below */ SELECT TOP 1 diff --git a/solution/0500-0599/0586.Customer Placing the Largest Number of Orders/README_EN.md b/solution/0500-0599/0586.Customer Placing the Largest Number of Orders/README_EN.md index ab7767ca4c850..85aa59921c7cb 100644 --- a/solution/0500-0599/0586.Customer Placing the Largest Number of Orders/README_EN.md +++ b/solution/0500-0599/0586.Customer Placing the Largest Number of Orders/README_EN.md @@ -77,6 +77,8 @@ We can use `GROUP BY` to group the data by `customer_number`, and then sort the +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -97,6 +99,8 @@ LIMIT 1; +#### MySQL + ```sql /* Write your T-SQL query statement below */ SELECT TOP 1 diff --git a/solution/0500-0599/0587.Erect the Fence/README.md b/solution/0500-0599/0587.Erect the Fence/README.md index 0032cc6690fd2..a57d4a5fe5c92 100644 --- a/solution/0500-0599/0587.Erect the Fence/README.md +++ b/solution/0500-0599/0587.Erect the Fence/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def outerTrees(self, trees: List[List[int]]) -> List[List[int]]: @@ -108,6 +110,8 @@ class Solution: return [trees[i] for i in stk] ``` +#### Java + ```java class Solution { public int[][] outerTrees(int[][] trees) { @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func outerTrees(trees [][]int) [][]int { n := len(trees) diff --git a/solution/0500-0599/0587.Erect the Fence/README_EN.md b/solution/0500-0599/0587.Erect the Fence/README_EN.md index d5d2c690d5f28..296e0881ae358 100644 --- a/solution/0500-0599/0587.Erect the Fence/README_EN.md +++ b/solution/0500-0599/0587.Erect the Fence/README_EN.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def outerTrees(self, trees: List[List[int]]) -> List[List[int]]: @@ -90,6 +92,8 @@ class Solution: return [trees[i] for i in stk] ``` +#### Java + ```java class Solution { public int[][] outerTrees(int[][] trees) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func outerTrees(trees [][]int) [][]int { n := len(trees) diff --git a/solution/0500-0599/0588.Design In-Memory File System/README.md b/solution/0500-0599/0588.Design In-Memory File System/README.md index 3a81bfde2e08a..5d26f3be1525d 100644 --- a/solution/0500-0599/0588.Design In-Memory File System/README.md +++ b/solution/0500-0599/0588.Design In-Memory File System/README.md @@ -92,6 +92,8 @@ fileSystem.readContentFromFile("/a/b/c/d"); // 返回 "hello" +#### Python3 + ```python class Trie: def __init__(self): @@ -156,6 +158,8 @@ class FileSystem: # param_4 = obj.readContentFromFile(filePath) ``` +#### Java + ```java class Trie { String name; @@ -242,6 +246,8 @@ class FileSystem { */ ``` +#### Go + ```go type Trie struct { name string diff --git a/solution/0500-0599/0588.Design In-Memory File System/README_EN.md b/solution/0500-0599/0588.Design In-Memory File System/README_EN.md index 6343931b3e2f0..786d2cf8b8c43 100644 --- a/solution/0500-0599/0588.Design In-Memory File System/README_EN.md +++ b/solution/0500-0599/0588.Design In-Memory File System/README_EN.md @@ -83,6 +83,8 @@ fileSystem.readContentFromFile("/a/b/c/d"); // return "hello" +#### Python3 + ```python class Trie: def __init__(self): @@ -147,6 +149,8 @@ class FileSystem: # param_4 = obj.readContentFromFile(filePath) ``` +#### Java + ```java class Trie { String name; @@ -233,6 +237,8 @@ class FileSystem { */ ``` +#### Go + ```go type Trie struct { name string diff --git a/solution/0500-0599/0589.N-ary Tree Preorder Traversal/README.md b/solution/0500-0599/0589.N-ary Tree Preorder Traversal/README.md index e5b2f72f626b9..58eaaf5c12817 100644 --- a/solution/0500-0599/0589.N-ary Tree Preorder Traversal/README.md +++ b/solution/0500-0599/0589.N-ary Tree Preorder Traversal/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python """ # Definition for a Node. @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java /* // Definition for a Node. @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -198,6 +206,8 @@ func preorder(root *Node) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for node. @@ -227,6 +237,8 @@ function preorder(root: Node | null): number[] { } ``` +#### C + ```c /** * Definition for a Node. @@ -275,6 +287,8 @@ int* preorder(struct Node* root, int* returnSize) { +#### Python3 + ```python """ # Definition for a Node. @@ -299,6 +313,8 @@ class Solution: return ans ``` +#### Java + ```java /* // Definition for a Node. @@ -340,6 +356,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -380,6 +398,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -407,6 +427,8 @@ func preorder(root *Node) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for node. diff --git a/solution/0500-0599/0589.N-ary Tree Preorder Traversal/README_EN.md b/solution/0500-0599/0589.N-ary Tree Preorder Traversal/README_EN.md index 42a5b74fa2d0b..4dc651fa4d5ff 100644 --- a/solution/0500-0599/0589.N-ary Tree Preorder Traversal/README_EN.md +++ b/solution/0500-0599/0589.N-ary Tree Preorder Traversal/README_EN.md @@ -67,6 +67,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python """ # Definition for a Node. @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java /* // Definition for a Node. @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -196,6 +204,8 @@ func preorder(root *Node) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for node. @@ -225,6 +235,8 @@ function preorder(root: Node | null): number[] { } ``` +#### C + ```c /** * Definition for a Node. @@ -273,6 +285,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python """ # Definition for a Node. @@ -297,6 +311,8 @@ class Solution: return ans ``` +#### Java + ```java /* // Definition for a Node. @@ -338,6 +354,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -378,6 +396,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -405,6 +425,8 @@ func preorder(root *Node) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for node. diff --git a/solution/0500-0599/0590.N-ary Tree Postorder Traversal/README.md b/solution/0500-0599/0590.N-ary Tree Postorder Traversal/README.md index 846875296d9fa..afb0e50c1a650 100644 --- a/solution/0500-0599/0590.N-ary Tree Postorder Traversal/README.md +++ b/solution/0500-0599/0590.N-ary Tree Postorder Traversal/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python """ # Definition for a Node. @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java /* // Definition for a Node. @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -199,6 +207,8 @@ func postorder(root *Node) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for node. @@ -244,6 +254,8 @@ function postorder(root: Node | null): number[] { +#### Python3 + ```python """ # Definition for a Node. @@ -268,6 +280,8 @@ class Solution: return ans[::-1] ``` +#### Java + ```java /* // Definition for a Node. @@ -308,6 +322,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -351,6 +367,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -378,6 +396,8 @@ func postorder(root *Node) []int { } ``` +#### TypeScript + ```ts /** * Definition for node. diff --git a/solution/0500-0599/0590.N-ary Tree Postorder Traversal/README_EN.md b/solution/0500-0599/0590.N-ary Tree Postorder Traversal/README_EN.md index 72960ad7eff8e..02bbbdf62f1f5 100644 --- a/solution/0500-0599/0590.N-ary Tree Postorder Traversal/README_EN.md +++ b/solution/0500-0599/0590.N-ary Tree Postorder Traversal/README_EN.md @@ -63,6 +63,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python """ # Definition for a Node. @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java /* // Definition for a Node. @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -192,6 +200,8 @@ func postorder(root *Node) (ans []int) { } ``` +#### TypeScript + ```ts /** * Definition for node. @@ -237,6 +247,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python """ # Definition for a Node. @@ -261,6 +273,8 @@ class Solution: return ans[::-1] ``` +#### Java + ```java /* // Definition for a Node. @@ -301,6 +315,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -344,6 +360,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -371,6 +389,8 @@ func postorder(root *Node) []int { } ``` +#### TypeScript + ```ts /** * Definition for node. diff --git a/solution/0500-0599/0591.Tag Validator/README.md b/solution/0500-0599/0591.Tag Validator/README.md index 6376130c9b3cb..35352cae1442d 100644 --- a/solution/0500-0599/0591.Tag Validator/README.md +++ b/solution/0500-0599/0591.Tag Validator/README.md @@ -112,6 +112,8 @@ cdata "<![CDATA[<div>]>]]>]] +#### Python3 + ```python class Solution: def isValid(self, code: str) -> bool: @@ -149,6 +151,8 @@ class Solution: return not stk ``` +#### Java + ```java class Solution { public boolean isValid(String code) { @@ -204,6 +208,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -245,6 +251,8 @@ public: }; ``` +#### Go + ```go func isValid(code string) bool { var stk []string @@ -305,6 +313,8 @@ func check(tag string) bool { } ``` +#### Rust + ```rust impl Solution { pub fn is_valid(code: String) -> bool { diff --git a/solution/0500-0599/0591.Tag Validator/README_EN.md b/solution/0500-0599/0591.Tag Validator/README_EN.md index 587cac6f08237..39948b2a2fbc3 100644 --- a/solution/0500-0599/0591.Tag Validator/README_EN.md +++ b/solution/0500-0599/0591.Tag Validator/README_EN.md @@ -88,6 +88,8 @@ The reason why cdata is NOT "<![CDATA[<div>]>]]>]]>&qu +#### Python3 + ```python class Solution: def isValid(self, code: str) -> bool: @@ -125,6 +127,8 @@ class Solution: return not stk ``` +#### Java + ```java class Solution { public boolean isValid(String code) { @@ -180,6 +184,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -221,6 +227,8 @@ public: }; ``` +#### Go + ```go func isValid(code string) bool { var stk []string @@ -281,6 +289,8 @@ func check(tag string) bool { } ``` +#### Rust + ```rust impl Solution { pub fn is_valid(code: String) -> bool { diff --git a/solution/0500-0599/0592.Fraction Addition and Subtraction/README.md b/solution/0500-0599/0592.Fraction Addition and Subtraction/README.md index 7957239046249..9f6eccb8bf0d6 100644 --- a/solution/0500-0599/0592.Fraction Addition and Subtraction/README.md +++ b/solution/0500-0599/0592.Fraction Addition and Subtraction/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def fractionAddition(self, expression: str) -> str: @@ -90,6 +92,8 @@ class Solution: return f'{x}/{y}' ``` +#### Java + ```java class Solution { public String fractionAddition(String expression) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### Go + ```go func fractionAddition(expression string) string { x, y := 0, 6*7*8*9*10 diff --git a/solution/0500-0599/0592.Fraction Addition and Subtraction/README_EN.md b/solution/0500-0599/0592.Fraction Addition and Subtraction/README_EN.md index 39cbbcc2c8ba3..f2217c40bb8c9 100644 --- a/solution/0500-0599/0592.Fraction Addition and Subtraction/README_EN.md +++ b/solution/0500-0599/0592.Fraction Addition and Subtraction/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def fractionAddition(self, expression: str) -> str: @@ -88,6 +90,8 @@ class Solution: return f'{x}/{y}' ``` +#### Java + ```java class Solution { public String fractionAddition(String expression) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### Go + ```go func fractionAddition(expression string) string { x, y := 0, 6*7*8*9*10 diff --git a/solution/0500-0599/0593.Valid Square/README.md b/solution/0500-0599/0593.Valid Square/README.md index 35a867b39066f..1b818e3a203d9 100644 --- a/solution/0500-0599/0593.Valid Square/README.md +++ b/solution/0500-0599/0593.Valid Square/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def validSquare( @@ -95,6 +97,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public boolean validSquare(int[] p1, int[] p2, int[] p3, int[] p4) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func validSquare(p1 []int, p2 []int, p3 []int, p4 []int) bool { check := func(a, b, c []int) bool { diff --git a/solution/0500-0599/0593.Valid Square/README_EN.md b/solution/0500-0599/0593.Valid Square/README_EN.md index 02affc8bd81ce..4d8c5e722d04d 100644 --- a/solution/0500-0599/0593.Valid Square/README_EN.md +++ b/solution/0500-0599/0593.Valid Square/README_EN.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def validSquare( @@ -89,6 +91,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public boolean validSquare(int[] p1, int[] p2, int[] p3, int[] p4) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func validSquare(p1 []int, p2 []int, p3 []int, p4 []int) bool { check := func(a, b, c []int) bool { diff --git a/solution/0500-0599/0594.Longest Harmonious Subsequence/README.md b/solution/0500-0599/0594.Longest Harmonious Subsequence/README.md index 17951c58ed9aa..5c238cfba4ce9 100644 --- a/solution/0500-0599/0594.Longest Harmonious Subsequence/README.md +++ b/solution/0500-0599/0594.Longest Harmonious Subsequence/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def findLHS(self, nums: List[int]) -> int: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findLHS(int[] nums) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func findLHS(nums []int) int { counter := make(map[int]int) @@ -143,6 +151,8 @@ func findLHS(nums []int) int { +#### Python3 + ```python class Solution: def findLHS(self, nums: List[int]) -> int: diff --git a/solution/0500-0599/0594.Longest Harmonious Subsequence/README_EN.md b/solution/0500-0599/0594.Longest Harmonious Subsequence/README_EN.md index 21b05d709663d..25b7790c83187 100644 --- a/solution/0500-0599/0594.Longest Harmonious Subsequence/README_EN.md +++ b/solution/0500-0599/0594.Longest Harmonious Subsequence/README_EN.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def findLHS(self, nums: List[int]) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findLHS(int[] nums) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func findLHS(nums []int) int { counter := make(map[int]int) @@ -156,6 +164,8 @@ func findLHS(nums []int) int { +#### Python3 + ```python class Solution: def findLHS(self, nums: List[int]) -> int: diff --git a/solution/0500-0599/0595.Big Countries/README.md b/solution/0500-0599/0595.Big Countries/README.md index ca624145084b3..797a8360b9a47 100644 --- a/solution/0500-0599/0595.Big Countries/README.md +++ b/solution/0500-0599/0595.Big Countries/README.md @@ -90,6 +90,8 @@ World 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT name, population, area @@ -109,6 +111,8 @@ WHERE area >= 3000000 OR population >= 25000000; +#### MySQL + ```sql # Write your MySQL query statement below SELECT name, population, area diff --git a/solution/0500-0599/0595.Big Countries/README_EN.md b/solution/0500-0599/0595.Big Countries/README_EN.md index 475e3063d6333..a0392e2949cd1 100644 --- a/solution/0500-0599/0595.Big Countries/README_EN.md +++ b/solution/0500-0599/0595.Big Countries/README_EN.md @@ -81,6 +81,8 @@ World table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT name, population, area @@ -98,6 +100,8 @@ WHERE area >= 3000000 OR population >= 25000000; +#### MySQL + ```sql # Write your MySQL query statement below SELECT name, population, area diff --git a/solution/0500-0599/0596.Classes More Than 5 Students/README.md b/solution/0500-0599/0596.Classes More Than 5 Students/README.md index 4aeec2c58c9e9..a3dd5fbb0deef 100644 --- a/solution/0500-0599/0596.Classes More Than 5 Students/README.md +++ b/solution/0500-0599/0596.Classes More Than 5 Students/README.md @@ -81,6 +81,8 @@ Courses table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT class diff --git a/solution/0500-0599/0596.Classes More Than 5 Students/README_EN.md b/solution/0500-0599/0596.Classes More Than 5 Students/README_EN.md index d60dc5eb3fcd5..e7cb16cd2f521 100644 --- a/solution/0500-0599/0596.Classes More Than 5 Students/README_EN.md +++ b/solution/0500-0599/0596.Classes More Than 5 Students/README_EN.md @@ -81,6 +81,8 @@ We can use the `GROUP BY` statement to group by class and then use the `HAVING` +#### MySQL + ```sql # Write your MySQL query statement below SELECT class diff --git a/solution/0500-0599/0597.Friend Requests I Overall Acceptance Rate/README.md b/solution/0500-0599/0597.Friend Requests I Overall Acceptance Rate/README.md index 1795929b62e73..f177cb6c0c1d6 100644 --- a/solution/0500-0599/0597.Friend Requests I Overall Acceptance Rate/README.md +++ b/solution/0500-0599/0597.Friend Requests I Overall Acceptance Rate/README.md @@ -113,6 +113,8 @@ RequestAccepted 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/0500-0599/0597.Friend Requests I Overall Acceptance Rate/README_EN.md b/solution/0500-0599/0597.Friend Requests I Overall Acceptance Rate/README_EN.md index 6cb3bf7533af5..b8221ae8bde72 100644 --- a/solution/0500-0599/0597.Friend Requests I Overall Acceptance Rate/README_EN.md +++ b/solution/0500-0599/0597.Friend Requests I Overall Acceptance Rate/README_EN.md @@ -113,6 +113,8 @@ There are 4 unique accepted requests, and there are 5 requests in total. So the +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/0500-0599/0598.Range Addition II/README.md b/solution/0500-0599/0598.Range Addition II/README.md index a898b3a36bd43..4031844398e52 100644 --- a/solution/0500-0599/0598.Range Addition II/README.md +++ b/solution/0500-0599/0598.Range Addition II/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int: @@ -80,6 +82,8 @@ class Solution: return m * n ``` +#### Java + ```java class Solution { public int maxCount(int m, int n, int[][] ops) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func maxCount(m int, n int, ops [][]int) int { for _, op := range ops { diff --git a/solution/0500-0599/0598.Range Addition II/README_EN.md b/solution/0500-0599/0598.Range Addition II/README_EN.md index 94f6334cd425f..fd5e5237b9517 100644 --- a/solution/0500-0599/0598.Range Addition II/README_EN.md +++ b/solution/0500-0599/0598.Range Addition II/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int: @@ -74,6 +76,8 @@ class Solution: return m * n ``` +#### Java + ```java class Solution { public int maxCount(int m, int n, int[][] ops) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -99,6 +105,8 @@ public: }; ``` +#### Go + ```go func maxCount(m int, n int, ops [][]int) int { for _, op := range ops { diff --git a/solution/0500-0599/0599.Minimum Index Sum of Two Lists/README.md b/solution/0500-0599/0599.Minimum Index Sum of Two Lists/README.md index adb81b625b9f4..cf8f47108d48b 100644 --- a/solution/0500-0599/0599.Minimum Index Sum of Two Lists/README.md +++ b/solution/0500-0599/0599.Minimum Index Sum of Two Lists/README.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def findRestaurant(self, list1: List[str], list2: List[str]) -> List[str]: @@ -79,6 +81,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func findRestaurant(list1 []string, list2 []string) []string { mp := make(map[string]int) @@ -154,6 +162,8 @@ func findRestaurant(list1 []string, list2 []string) []string { } ``` +#### TypeScript + ```ts function findRestaurant(list1: string[], list2: string[]): string[] { let minI = Infinity; @@ -175,6 +185,8 @@ function findRestaurant(list1: string[], list2: string[]): string[] { } ``` +#### Rust + ```rust use std::collections::HashMap; use std::iter::FromIterator; @@ -214,6 +226,8 @@ impl Solution { +#### C++ + ```cpp func findRestaurant(list1[] string, list2[] string)[] string { mp:= make(map[string]int) diff --git a/solution/0500-0599/0599.Minimum Index Sum of Two Lists/README_EN.md b/solution/0500-0599/0599.Minimum Index Sum of Two Lists/README_EN.md index 76b20cc0f303b..e5d2eb10a265c 100644 --- a/solution/0500-0599/0599.Minimum Index Sum of Two Lists/README_EN.md +++ b/solution/0500-0599/0599.Minimum Index Sum of Two Lists/README_EN.md @@ -77,6 +77,8 @@ The strings with the least index sum are "sad" and "happy". +#### Python3 + ```python class Solution: def findRestaurant(self, list1: List[str], list2: List[str]) -> List[str]: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func findRestaurant(list1 []string, list2 []string) []string { mp := make(map[string]int) @@ -169,6 +177,8 @@ func findRestaurant(list1 []string, list2 []string) []string { } ``` +#### TypeScript + ```ts function findRestaurant(list1: string[], list2: string[]): string[] { let minI = Infinity; @@ -190,6 +200,8 @@ function findRestaurant(list1: string[], list2: string[]): string[] { } ``` +#### Rust + ```rust use std::collections::HashMap; use std::iter::FromIterator; @@ -229,6 +241,8 @@ impl Solution { +#### C++ + ```cpp func findRestaurant(list1[] string, list2[] string)[] string { mp:= make(map[string]int) diff --git a/solution/0600-0699/0600.Non-negative Integers without Consecutive Ones/README.md b/solution/0600-0699/0600.Non-negative Integers without Consecutive Ones/README.md index 428bf175ee893..f5b4eb13f60b6 100644 --- a/solution/0600-0699/0600.Non-negative Integers without Consecutive Ones/README.md +++ b/solution/0600-0699/0600.Non-negative Integers without Consecutive Ones/README.md @@ -103,6 +103,8 @@ $$ +#### Python3 + ```python class Solution: def findIntegers(self, n: int) -> int: @@ -127,6 +129,8 @@ class Solution: return dfs(l, 0, True) ``` +#### Java + ```java class Solution { private int[] a = new int[33]; @@ -166,6 +170,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -204,6 +210,8 @@ public: }; ``` +#### Go + ```go func findIntegers(n int) int { a := make([]int, 33) diff --git a/solution/0600-0699/0600.Non-negative Integers without Consecutive Ones/README_EN.md b/solution/0600-0699/0600.Non-negative Integers without Consecutive Ones/README_EN.md index fc25109c659cf..73100c20f7d2d 100644 --- a/solution/0600-0699/0600.Non-negative Integers without Consecutive Ones/README_EN.md +++ b/solution/0600-0699/0600.Non-negative Integers without Consecutive Ones/README_EN.md @@ -66,6 +66,8 @@ Among them, only integer 3 disobeys the rule (two consecutive ones) and the othe +#### Python3 + ```python class Solution: def findIntegers(self, n: int) -> int: @@ -90,6 +92,8 @@ class Solution: return dfs(l, 0, True) ``` +#### Java + ```java class Solution { private int[] a = new int[33]; @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func findIntegers(n int) int { a := make([]int, 33) diff --git a/solution/0600-0699/0601.Human Traffic of Stadium/README.md b/solution/0600-0699/0601.Human Traffic of Stadium/README.md index 9a39e02216626..a953a7078da04 100644 --- a/solution/0600-0699/0601.Human Traffic of Stadium/README.md +++ b/solution/0600-0699/0601.Human Traffic of Stadium/README.md @@ -82,6 +82,8 @@ id 为 5、6、7、8 的四行 id 连续,并且每行都有 >= 100 +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0600-0699/0601.Human Traffic of Stadium/README_EN.md b/solution/0600-0699/0601.Human Traffic of Stadium/README_EN.md index 5e9ce5fb20c38..dc36ad8762022 100644 --- a/solution/0600-0699/0601.Human Traffic of Stadium/README_EN.md +++ b/solution/0600-0699/0601.Human Traffic of Stadium/README_EN.md @@ -81,6 +81,8 @@ The rows with ids 2 and 3 are not included because we need at least three consec +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0600-0699/0602.Friend Requests II Who Has the Most Friends/README.md b/solution/0600-0699/0602.Friend Requests II Who Has the Most Friends/README.md index 8d1bf6eb4851d..efac808b08dbd 100644 --- a/solution/0600-0699/0602.Friend Requests II Who Has the Most Friends/README.md +++ b/solution/0600-0699/0602.Friend Requests II Who Has the Most Friends/README.md @@ -80,6 +80,8 @@ RequestAccepted 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0600-0699/0602.Friend Requests II Who Has the Most Friends/README_EN.md b/solution/0600-0699/0602.Friend Requests II Who Has the Most Friends/README_EN.md index 933703a845fb5..b6211218ca5a5 100644 --- a/solution/0600-0699/0602.Friend Requests II Who Has the Most Friends/README_EN.md +++ b/solution/0600-0699/0602.Friend Requests II Who Has the Most Friends/README_EN.md @@ -75,6 +75,8 @@ The person with id 3 is a friend of people 1, 2, and 4, so he has three friends +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0600-0699/0603.Consecutive Available Seats/README.md b/solution/0600-0699/0603.Consecutive Available Seats/README.md index 231daadb930b9..7f8068a6fc019 100644 --- a/solution/0600-0699/0603.Consecutive Available Seats/README.md +++ b/solution/0600-0699/0603.Consecutive Available Seats/README.md @@ -76,6 +76,8 @@ Cinema 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT DISTINCT a.seat_id @@ -97,6 +99,8 @@ ORDER BY 1; +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -122,6 +126,8 @@ WHERE a = 2 OR b = 2; +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0600-0699/0603.Consecutive Available Seats/README_EN.md b/solution/0600-0699/0603.Consecutive Available Seats/README_EN.md index ea11475749528..5f346895831b0 100644 --- a/solution/0600-0699/0603.Consecutive Available Seats/README_EN.md +++ b/solution/0600-0699/0603.Consecutive Available Seats/README_EN.md @@ -76,6 +76,8 @@ We can use a self-join to join the `Seat` table with itself, and then filter out +#### MySQL + ```sql # Write your MySQL query statement below SELECT DISTINCT a.seat_id @@ -97,6 +99,8 @@ We can use the `LAG` and `LEAD` functions (or `SUM() OVER(ROWS BETWEEN 1 PRECEDI +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -122,6 +126,8 @@ WHERE a = 2 OR b = 2; +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0600-0699/0604.Design Compressed String Iterator/README.md b/solution/0600-0699/0604.Design Compressed String Iterator/README.md index 8d42658f3113f..9d8866ead6b51 100644 --- a/solution/0600-0699/0604.Design Compressed String Iterator/README.md +++ b/solution/0600-0699/0604.Design Compressed String Iterator/README.md @@ -78,6 +78,8 @@ stringIterator.hasNext(); // 返回 True +#### Python3 + ```python class StringIterator: def __init__(self, compressedString: str): @@ -113,6 +115,8 @@ class StringIterator: # param_2 = obj.hasNext() ``` +#### Java + ```java class StringIterator { private List d = new ArrayList<>(); @@ -165,6 +169,8 @@ class Node { */ ``` +#### C++ + ```cpp class StringIterator { public: @@ -207,6 +213,8 @@ private: */ ``` +#### Go + ```go type pair struct { c byte diff --git a/solution/0600-0699/0604.Design Compressed String Iterator/README_EN.md b/solution/0600-0699/0604.Design Compressed String Iterator/README_EN.md index 6d95482fd1ea9..cc5512a0be612 100644 --- a/solution/0600-0699/0604.Design Compressed String Iterator/README_EN.md +++ b/solution/0600-0699/0604.Design Compressed String Iterator/README_EN.md @@ -71,6 +71,8 @@ stringIterator.hasNext(); // return True +#### Python3 + ```python class StringIterator: def __init__(self, compressedString: str): @@ -106,6 +108,8 @@ class StringIterator: # param_2 = obj.hasNext() ``` +#### Java + ```java class StringIterator { private List d = new ArrayList<>(); @@ -158,6 +162,8 @@ class Node { */ ``` +#### C++ + ```cpp class StringIterator { public: @@ -200,6 +206,8 @@ private: */ ``` +#### Go + ```go type pair struct { c byte diff --git a/solution/0600-0699/0605.Can Place Flowers/README.md b/solution/0600-0699/0605.Can Place Flowers/README.md index 662dbc38de465..d7f6e4799c901 100644 --- a/solution/0600-0699/0605.Can Place Flowers/README.md +++ b/solution/0600-0699/0605.Can Place Flowers/README.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def canPlaceFlowers(self, flowerbed: List[int], n: int) -> bool: @@ -73,6 +75,8 @@ class Solution: return n <= 0 ``` +#### Java + ```java class Solution { public boolean canPlaceFlowers(int[] flowerbed, int n) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func canPlaceFlowers(flowerbed []int, n int) bool { m := len(flowerbed) @@ -128,6 +136,8 @@ func canPlaceFlowers(flowerbed []int, n int) bool { } ``` +#### TypeScript + ```ts function canPlaceFlowers(flowerbed: number[], n: number): boolean { const m = flowerbed.length; @@ -143,6 +153,8 @@ function canPlaceFlowers(flowerbed: number[], n: number): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn can_place_flowers(flowerbed: Vec, n: i32) -> bool { @@ -162,6 +174,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0600-0699/0605.Can Place Flowers/README_EN.md b/solution/0600-0699/0605.Can Place Flowers/README_EN.md index d088fb6b638d0..732a1b334405f 100644 --- a/solution/0600-0699/0605.Can Place Flowers/README_EN.md +++ b/solution/0600-0699/0605.Can Place Flowers/README_EN.md @@ -53,6 +53,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $flowerbed$. +#### Python3 + ```python class Solution: def canPlaceFlowers(self, flowerbed: List[int], n: int) -> bool: @@ -64,6 +66,8 @@ class Solution: return n <= 0 ``` +#### Java + ```java class Solution { public boolean canPlaceFlowers(int[] flowerbed, int n) { @@ -81,6 +85,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -99,6 +105,8 @@ public: }; ``` +#### Go + ```go func canPlaceFlowers(flowerbed []int, n int) bool { m := len(flowerbed) @@ -119,6 +127,8 @@ func canPlaceFlowers(flowerbed []int, n int) bool { } ``` +#### TypeScript + ```ts function canPlaceFlowers(flowerbed: number[], n: number): boolean { const m = flowerbed.length; @@ -134,6 +144,8 @@ function canPlaceFlowers(flowerbed: number[], n: number): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn can_place_flowers(flowerbed: Vec, n: i32) -> bool { @@ -153,6 +165,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0600-0699/0606.Construct String from Binary Tree/README.md b/solution/0600-0699/0606.Construct String from Binary Tree/README.md index bbfeb305df9d1..55d21a92b6e8d 100644 --- a/solution/0600-0699/0606.Construct String from Binary Tree/README.md +++ b/solution/0600-0699/0606.Construct String from Binary Tree/README.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -84,6 +86,8 @@ class Solution: return dfs(root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -162,6 +170,8 @@ func tree2str(root *TreeNode) string { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -190,6 +200,8 @@ function tree2str(root: TreeNode | null): string { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/0600-0699/0606.Construct String from Binary Tree/README_EN.md b/solution/0600-0699/0606.Construct String from Binary Tree/README_EN.md index 422f7318ed12b..2732890125d8a 100644 --- a/solution/0600-0699/0606.Construct String from Binary Tree/README_EN.md +++ b/solution/0600-0699/0606.Construct String from Binary Tree/README_EN.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -97,6 +99,8 @@ class Solution: return dfs(root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -175,6 +183,8 @@ func tree2str(root *TreeNode) string { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -203,6 +213,8 @@ function tree2str(root: TreeNode | null): string { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/0600-0699/0607.Sales Person/README.md b/solution/0600-0699/0607.Sales Person/README.md index 6c41789913309..8e59c6b4f4ab8 100644 --- a/solution/0600-0699/0607.Sales Person/README.md +++ b/solution/0600-0699/0607.Sales Person/README.md @@ -134,6 +134,8 @@ Orders 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT s.name diff --git a/solution/0600-0699/0607.Sales Person/README_EN.md b/solution/0600-0699/0607.Sales Person/README_EN.md index 15120485705fb..de69c7b177168 100644 --- a/solution/0600-0699/0607.Sales Person/README_EN.md +++ b/solution/0600-0699/0607.Sales Person/README_EN.md @@ -133,6 +133,8 @@ We can use a left join to join the `SalesPerson` table with the `Orders` table o +#### MySQL + ```sql # Write your MySQL query statement below SELECT s.name diff --git a/solution/0600-0699/0608.Tree Node/README.md b/solution/0600-0699/0608.Tree Node/README.md index cbce3537c3327..be3cea39ad54f 100644 --- a/solution/0600-0699/0608.Tree Node/README.md +++ b/solution/0600-0699/0608.Tree Node/README.md @@ -113,6 +113,8 @@ Tree table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/0600-0699/0608.Tree Node/README_EN.md b/solution/0600-0699/0608.Tree Node/README_EN.md index 8240587bff0a4..e297ff967f37e 100644 --- a/solution/0600-0699/0608.Tree Node/README_EN.md +++ b/solution/0600-0699/0608.Tree Node/README_EN.md @@ -112,6 +112,8 @@ We can use the `CASE WHEN` conditional statement to determine the type of each n +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/0600-0699/0609.Find Duplicate File in System/README.md b/solution/0600-0699/0609.Find Duplicate File in System/README.md index 5aea117004a4b..f00e6ca3df278 100644 --- a/solution/0600-0699/0609.Find Duplicate File in System/README.md +++ b/solution/0600-0699/0609.Find Duplicate File in System/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python class Solution: def findDuplicate(self, paths: List[str]) -> List[List[str]]: @@ -108,6 +110,8 @@ class Solution: return [v for v in d.values() if len(v) > 1] ``` +#### Java + ```java class Solution { public List> findDuplicate(String[] paths) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func findDuplicate(paths []string) [][]string { d := map[string][]string{} @@ -189,6 +197,8 @@ func findDuplicate(paths []string) [][]string { } ``` +#### TypeScript + ```ts function findDuplicate(paths: string[]): string[][] { const d = new Map(); diff --git a/solution/0600-0699/0609.Find Duplicate File in System/README_EN.md b/solution/0600-0699/0609.Find Duplicate File in System/README_EN.md index 4058828889d7a..382e305e871f9 100644 --- a/solution/0600-0699/0609.Find Duplicate File in System/README_EN.md +++ b/solution/0600-0699/0609.Find Duplicate File in System/README_EN.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def findDuplicate(self, paths: List[str]) -> List[List[str]]: @@ -90,6 +92,8 @@ class Solution: return [v for v in d.values() if len(v) > 1] ``` +#### Java + ```java class Solution { public List> findDuplicate(String[] paths) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func findDuplicate(paths []string) [][]string { d := map[string][]string{} @@ -171,6 +179,8 @@ func findDuplicate(paths []string) [][]string { } ``` +#### TypeScript + ```ts function findDuplicate(paths: string[]): string[][] { const d = new Map(); diff --git a/solution/0600-0699/0610.Triangle Judgement/README.md b/solution/0600-0699/0610.Triangle Judgement/README.md index 2a4f7767e46be..8ea271efc123f 100644 --- a/solution/0600-0699/0610.Triangle Judgement/README.md +++ b/solution/0600-0699/0610.Triangle Judgement/README.md @@ -71,6 +71,8 @@ Triangle 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/0600-0699/0610.Triangle Judgement/README_EN.md b/solution/0600-0699/0610.Triangle Judgement/README_EN.md index 490b85334126f..8e580d31c0ede 100644 --- a/solution/0600-0699/0610.Triangle Judgement/README_EN.md +++ b/solution/0600-0699/0610.Triangle Judgement/README_EN.md @@ -71,6 +71,8 @@ The condition for whether three sides can form a triangle is that the sum of any +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/0600-0699/0611.Valid Triangle Number/README.md b/solution/0600-0699/0611.Valid Triangle Number/README.md index 512a345cc6fda..b0a4484b8ecd2 100644 --- a/solution/0600-0699/0611.Valid Triangle Number/README.md +++ b/solution/0600-0699/0611.Valid Triangle Number/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def triangleNumber(self, nums: List[int]) -> int: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int triangleNumber(int[] nums) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func triangleNumber(nums []int) int { sort.Ints(nums) @@ -141,6 +149,8 @@ func triangleNumber(nums []int) int { } ``` +#### TypeScript + ```ts function triangleNumber(nums: number[]): number { nums.sort((a, b) => a - b); @@ -162,6 +172,8 @@ function triangleNumber(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn triangle_number(mut nums: Vec) -> i32 { @@ -195,6 +207,8 @@ impl Solution { +#### Java + ```java class Solution { public int triangleNumber(int[] nums) { diff --git a/solution/0600-0699/0611.Valid Triangle Number/README_EN.md b/solution/0600-0699/0611.Valid Triangle Number/README_EN.md index 226edd75ca517..282cd1ec4a45c 100644 --- a/solution/0600-0699/0611.Valid Triangle Number/README_EN.md +++ b/solution/0600-0699/0611.Valid Triangle Number/README_EN.md @@ -59,6 +59,8 @@ tags: +#### Python3 + ```python class Solution: def triangleNumber(self, nums: List[int]) -> int: @@ -71,6 +73,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int triangleNumber(int[] nums) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func triangleNumber(nums []int) int { sort.Ints(nums) @@ -132,6 +140,8 @@ func triangleNumber(nums []int) int { } ``` +#### TypeScript + ```ts function triangleNumber(nums: number[]): number { nums.sort((a, b) => a - b); @@ -153,6 +163,8 @@ function triangleNumber(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn triangle_number(mut nums: Vec) -> i32 { @@ -186,6 +198,8 @@ impl Solution { +#### Java + ```java class Solution { public int triangleNumber(int[] nums) { diff --git a/solution/0600-0699/0612.Shortest Distance in a Plane/README.md b/solution/0600-0699/0612.Shortest Distance in a Plane/README.md index 6e3e68264ba03..182c011b626a4 100644 --- a/solution/0600-0699/0612.Shortest Distance in a Plane/README.md +++ b/solution/0600-0699/0612.Shortest Distance in a Plane/README.md @@ -76,6 +76,8 @@ Point2D table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT ROUND(SQRT(POW(p1.x - p2.x, 2) + POW(p1.y - p2.y, 2)), 2) AS shortest diff --git a/solution/0600-0699/0612.Shortest Distance in a Plane/README_EN.md b/solution/0600-0699/0612.Shortest Distance in a Plane/README_EN.md index b707844ee9842..e0fc668e7eb9d 100644 --- a/solution/0600-0699/0612.Shortest Distance in a Plane/README_EN.md +++ b/solution/0600-0699/0612.Shortest Distance in a Plane/README_EN.md @@ -69,6 +69,8 @@ Point2D table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT ROUND(SQRT(POW(p1.x - p2.x, 2) + POW(p1.y - p2.y, 2)), 2) AS shortest diff --git a/solution/0600-0699/0613.Shortest Distance in a Line/README.md b/solution/0600-0699/0613.Shortest Distance in a Line/README.md index 333e241f3c13c..976108fea4ca7 100644 --- a/solution/0600-0699/0613.Shortest Distance in a Line/README.md +++ b/solution/0600-0699/0613.Shortest Distance in a Line/README.md @@ -73,6 +73,8 @@ Point 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT MIN(p2.x - p1.x) AS shortest @@ -93,6 +95,8 @@ FROM +#### MySQL + ```sql # Write your MySQL query statement below SELECT x - LAG(x) OVER (ORDER BY x) AS shortest diff --git a/solution/0600-0699/0613.Shortest Distance in a Line/README_EN.md b/solution/0600-0699/0613.Shortest Distance in a Line/README_EN.md index 7e22170b34581..1354196984ab5 100644 --- a/solution/0600-0699/0613.Shortest Distance in a Line/README_EN.md +++ b/solution/0600-0699/0613.Shortest Distance in a Line/README_EN.md @@ -71,6 +71,8 @@ We can use a self-join to join each point in the table with the larger points, a +#### MySQL + ```sql # Write your MySQL query statement below SELECT MIN(p2.x - p1.x) AS shortest @@ -91,6 +93,8 @@ We can use a window function to sort the points in the table by their $x$ values +#### MySQL + ```sql # Write your MySQL query statement below SELECT x - LAG(x) OVER (ORDER BY x) AS shortest diff --git a/solution/0600-0699/0614.Second Degree Follower/README.md b/solution/0600-0699/0614.Second Degree Follower/README.md index d1fff2ab617d7..2b2afe78b2b48 100644 --- a/solution/0600-0699/0614.Second Degree Follower/README.md +++ b/solution/0600-0699/0614.Second Degree Follower/README.md @@ -82,6 +82,8 @@ Follow table: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0600-0699/0614.Second Degree Follower/README_EN.md b/solution/0600-0699/0614.Second Degree Follower/README_EN.md index d1e835ba177ed..3cc844537f110 100644 --- a/solution/0600-0699/0614.Second Degree Follower/README_EN.md +++ b/solution/0600-0699/0614.Second Degree Follower/README_EN.md @@ -82,6 +82,8 @@ User Alice has 1 follower. Alice is not a second-degree follower because she doe +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0600-0699/0615.Average Salary Departments VS Company/README.md b/solution/0600-0699/0615.Average Salary Departments VS Company/README.md index 4e65feb939a50..251010d6e521b 100644 --- a/solution/0600-0699/0615.Average Salary Departments VS Company/README.md +++ b/solution/0600-0699/0615.Average Salary Departments VS Company/README.md @@ -104,6 +104,8 @@ Employee 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -138,6 +140,8 @@ FROM t; +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0600-0699/0615.Average Salary Departments VS Company/README_EN.md b/solution/0600-0699/0615.Average Salary Departments VS Company/README_EN.md index 1d0ee1b23d684..56eb784a95671 100644 --- a/solution/0600-0699/0615.Average Salary Departments VS Company/README_EN.md +++ b/solution/0600-0699/0615.Average Salary Departments VS Company/README_EN.md @@ -106,6 +106,8 @@ With he same formula for the average salary comparison in February, the result i +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -140,6 +142,8 @@ FROM t; +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0600-0699/0616.Add Bold Tag in String/README.md b/solution/0600-0699/0616.Add Bold Tag in String/README.md index 2632bfb6a0e20..e0ab5ef0f6faf 100644 --- a/solution/0600-0699/0616.Add Bold Tag in String/README.md +++ b/solution/0600-0699/0616.Add Bold Tag in String/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Trie: def __init__(self): @@ -150,6 +152,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Trie { Trie[] children = new Trie[128]; @@ -227,6 +231,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -296,6 +302,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [128]*Trie diff --git a/solution/0600-0699/0616.Add Bold Tag in String/README_EN.md b/solution/0600-0699/0616.Add Bold Tag in String/README_EN.md index a63f78f53d1ad..46ddc02925e25 100644 --- a/solution/0600-0699/0616.Add Bold Tag in String/README_EN.md +++ b/solution/0600-0699/0616.Add Bold Tag in String/README_EN.md @@ -78,6 +78,8 @@ Since now the four <b>'s are consecutive, we merge them: "<b&g +#### Python3 + ```python class Trie: def __init__(self): @@ -140,6 +142,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Trie { Trie[] children = new Trie[128]; @@ -217,6 +221,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -286,6 +292,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [128]*Trie diff --git a/solution/0600-0699/0617.Merge Two Binary Trees/README.md b/solution/0600-0699/0617.Merge Two Binary Trees/README.md index 4ac9d8d310924..d71072df468f4 100644 --- a/solution/0600-0699/0617.Merge Two Binary Trees/README.md +++ b/solution/0600-0699/0617.Merge Two Binary Trees/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -90,6 +92,8 @@ class Solution: return node ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -170,6 +178,8 @@ func mergeTrees(root1 *TreeNode, root2 *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -195,6 +205,8 @@ function mergeTrees(root1: TreeNode | null, root2: TreeNode | null): TreeNode | } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -240,6 +252,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0600-0699/0617.Merge Two Binary Trees/README_EN.md b/solution/0600-0699/0617.Merge Two Binary Trees/README_EN.md index a092591be3aae..00d4fa85b0d31 100644 --- a/solution/0600-0699/0617.Merge Two Binary Trees/README_EN.md +++ b/solution/0600-0699/0617.Merge Two Binary Trees/README_EN.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -81,6 +83,8 @@ class Solution: return node ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -161,6 +169,8 @@ func mergeTrees(root1 *TreeNode, root2 *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -186,6 +196,8 @@ function mergeTrees(root1: TreeNode | null, root2: TreeNode | null): TreeNode | } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -231,6 +243,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0600-0699/0618.Students Report By Geography/README.md b/solution/0600-0699/0618.Students Report By Geography/README.md index 7783975483285..1a8ad66785e93 100644 --- a/solution/0600-0699/0618.Students Report By Geography/README.md +++ b/solution/0600-0699/0618.Students Report By Geography/README.md @@ -78,6 +78,8 @@ Student table: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0600-0699/0618.Students Report By Geography/README_EN.md b/solution/0600-0699/0618.Students Report By Geography/README_EN.md index 9bb478c601c86..f928597a913c9 100644 --- a/solution/0600-0699/0618.Students Report By Geography/README_EN.md +++ b/solution/0600-0699/0618.Students Report By Geography/README_EN.md @@ -75,6 +75,8 @@ Student table: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/0600-0699/0619.Biggest Single Number/README.md b/solution/0600-0699/0619.Biggest Single Number/README.md index 971ed1c815ff0..2d9c4449d4f9d 100644 --- a/solution/0600-0699/0619.Biggest Single Number/README.md +++ b/solution/0600-0699/0619.Biggest Single Number/README.md @@ -109,6 +109,8 @@ MyNumbers table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT MAX(num) AS num @@ -133,6 +135,8 @@ FROM +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/0600-0699/0619.Biggest Single Number/README_EN.md b/solution/0600-0699/0619.Biggest Single Number/README_EN.md index 3466bf0abee2d..aeac7bd0d0b2e 100644 --- a/solution/0600-0699/0619.Biggest Single Number/README_EN.md +++ b/solution/0600-0699/0619.Biggest Single Number/README_EN.md @@ -101,6 +101,8 @@ We can first group the `MyNumbers` table by `num` and count the number of occurr +#### MySQL + ```sql # Write your MySQL query statement below SELECT MAX(num) AS num @@ -125,6 +127,8 @@ Similar to Solution 1, we can first group the `MyNumbers` table by `num` and cou +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/0600-0699/0620.Not Boring Movies/README.md b/solution/0600-0699/0620.Not Boring Movies/README.md index 01ff3ae332702..f3a13010f2ff9 100644 --- a/solution/0600-0699/0620.Not Boring Movies/README.md +++ b/solution/0600-0699/0620.Not Boring Movies/README.md @@ -78,6 +78,8 @@ id 是该表的主键(具有唯一值的列)。 +#### MySQL + ```sql # Write your MySQL query statement below SELECT * diff --git a/solution/0600-0699/0620.Not Boring Movies/README_EN.md b/solution/0600-0699/0620.Not Boring Movies/README_EN.md index 74acc2f4c7ab4..7619033b3bc70 100644 --- a/solution/0600-0699/0620.Not Boring Movies/README_EN.md +++ b/solution/0600-0699/0620.Not Boring Movies/README_EN.md @@ -78,6 +78,8 @@ We can use the `WHERE` clause to filter out the records where `description` is n +#### MySQL + ```sql # Write your MySQL query statement below SELECT * diff --git a/solution/0600-0699/0621.Task Scheduler/README.md b/solution/0600-0699/0621.Task Scheduler/README.md index f9dfb57ecf2c7..9325761c007c1 100644 --- a/solution/0600-0699/0621.Task Scheduler/README.md +++ b/solution/0600-0699/0621.Task Scheduler/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def leastInterval(self, tasks: List[str], n: int) -> int: @@ -94,6 +96,8 @@ class Solution: return max(len(tasks), (x - 1) * (n + 1) + s) ``` +#### Java + ```java class Solution { public int leastInterval(char[] tasks, int n) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func leastInterval(tasks []byte, n int) int { cnt := make([]int, 26) @@ -154,6 +162,8 @@ func leastInterval(tasks []byte, n int) int { } ``` +#### C# + ```cs public class Solution { public int LeastInterval(char[] tasks, int n) { diff --git a/solution/0600-0699/0621.Task Scheduler/README_EN.md b/solution/0600-0699/0621.Task Scheduler/README_EN.md index baf35c4cdfea3..e8e4c04e7d937 100644 --- a/solution/0600-0699/0621.Task Scheduler/README_EN.md +++ b/solution/0600-0699/0621.Task Scheduler/README_EN.md @@ -126,6 +126,8 @@ font-size: 0.85rem; +#### Python3 + ```python class Solution: def leastInterval(self, tasks: List[str], n: int) -> int: @@ -135,6 +137,8 @@ class Solution: return max(len(tasks), (x - 1) * (n + 1) + s) ``` +#### Java + ```java class Solution { public int leastInterval(char[] tasks, int n) { @@ -156,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go func leastInterval(tasks []byte, n int) int { cnt := make([]int, 26) @@ -195,6 +203,8 @@ func leastInterval(tasks []byte, n int) int { } ``` +#### C# + ```cs public class Solution { public int LeastInterval(char[] tasks, int n) { diff --git a/solution/0600-0699/0622.Design Circular Queue/README.md b/solution/0600-0699/0622.Design Circular Queue/README.md index 76ea2968b94b9..145098c1cca8f 100644 --- a/solution/0600-0699/0622.Design Circular Queue/README.md +++ b/solution/0600-0699/0622.Design Circular Queue/README.md @@ -70,6 +70,8 @@ circularQueue.Rear();  // 返回 4 +#### Python3 + ```python class MyCircularQueue: def __init__(self, k: int): @@ -119,6 +121,8 @@ class MyCircularQueue: # param_6 = obj.isFull() ``` +#### Java + ```java class MyCircularQueue { private int[] q; @@ -186,6 +190,8 @@ class MyCircularQueue { */ ``` +#### C++ + ```cpp class MyCircularQueue { private: @@ -248,6 +254,8 @@ public: */ ``` +#### Go + ```go type MyCircularQueue struct { front int @@ -315,6 +323,8 @@ func (this *MyCircularQueue) IsFull() bool { */ ``` +#### TypeScript + ```ts class MyCircularQueue { private queue: number[]; @@ -381,6 +391,8 @@ class MyCircularQueue { */ ``` +#### Rust + ```rust struct MyCircularQueue { queue: Vec, diff --git a/solution/0600-0699/0622.Design Circular Queue/README_EN.md b/solution/0600-0699/0622.Design Circular Queue/README_EN.md index 68a2837f0dd98..6bd85a9a93241 100644 --- a/solution/0600-0699/0622.Design Circular Queue/README_EN.md +++ b/solution/0600-0699/0622.Design Circular Queue/README_EN.md @@ -79,6 +79,8 @@ myCircularQueue.Rear(); // return 4 +#### Python3 + ```python class MyCircularQueue: def __init__(self, k: int): @@ -128,6 +130,8 @@ class MyCircularQueue: # param_6 = obj.isFull() ``` +#### Java + ```java class MyCircularQueue { private int[] q; @@ -195,6 +199,8 @@ class MyCircularQueue { */ ``` +#### C++ + ```cpp class MyCircularQueue { private: @@ -257,6 +263,8 @@ public: */ ``` +#### Go + ```go type MyCircularQueue struct { front int @@ -324,6 +332,8 @@ func (this *MyCircularQueue) IsFull() bool { */ ``` +#### TypeScript + ```ts class MyCircularQueue { private queue: number[]; @@ -390,6 +400,8 @@ class MyCircularQueue { */ ``` +#### Rust + ```rust struct MyCircularQueue { queue: Vec, diff --git a/solution/0600-0699/0623.Add One Row to Tree/README.md b/solution/0600-0699/0623.Add One Row to Tree/README.md index 4da84c29d70e6..a4188c8d626e9 100644 --- a/solution/0600-0699/0623.Add One Row to Tree/README.md +++ b/solution/0600-0699/0623.Add One Row to Tree/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -100,6 +102,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -147,6 +151,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -187,6 +193,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -218,6 +226,8 @@ func addOneRow(root *TreeNode, val int, depth int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -264,6 +274,8 @@ function addOneRow(root: TreeNode | null, val: number, depth: number): TreeNode +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -293,6 +305,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -338,6 +352,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -374,6 +390,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -410,6 +428,8 @@ func addOneRow(root *TreeNode, val int, depth int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0600-0699/0623.Add One Row to Tree/README_EN.md b/solution/0600-0699/0623.Add One Row to Tree/README_EN.md index ed5f7904fb79d..21bdfb8646fa1 100644 --- a/solution/0600-0699/0623.Add One Row to Tree/README_EN.md +++ b/solution/0600-0699/0623.Add One Row to Tree/README_EN.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -95,6 +97,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -182,6 +188,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -213,6 +221,8 @@ func addOneRow(root *TreeNode, val int, depth int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -259,6 +269,8 @@ function addOneRow(root: TreeNode | null, val: number, depth: number): TreeNode +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -288,6 +300,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -333,6 +347,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -369,6 +385,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -405,6 +423,8 @@ func addOneRow(root *TreeNode, val int, depth int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0600-0699/0624.Maximum Distance in Arrays/README.md b/solution/0600-0699/0624.Maximum Distance in Arrays/README.md index 5a4835dead3aa..a91d9c27f85f9 100644 --- a/solution/0600-0699/0624.Maximum Distance in Arrays/README.md +++ b/solution/0600-0699/0624.Maximum Distance in Arrays/README.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python class Solution: def maxDistance(self, arrays: List[List[int]]) -> int: @@ -71,6 +73,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxDistance(List> arrays) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func maxDistance(arrays [][]int) (ans int) { mi, mx := arrays[0][0], arrays[0][len(arrays[0])-1] diff --git a/solution/0600-0699/0624.Maximum Distance in Arrays/README_EN.md b/solution/0600-0699/0624.Maximum Distance in Arrays/README_EN.md index 12f0251cd04cf..3b6e64bee5aae 100644 --- a/solution/0600-0699/0624.Maximum Distance in Arrays/README_EN.md +++ b/solution/0600-0699/0624.Maximum Distance in Arrays/README_EN.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def maxDistance(self, arrays: List[List[int]]) -> int: @@ -74,6 +76,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxDistance(List> arrays) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func maxDistance(arrays [][]int) (ans int) { mi, mx := arrays[0][0], arrays[0][len(arrays[0])-1] diff --git a/solution/0600-0699/0625.Minimum Factorization/README.md b/solution/0600-0699/0625.Minimum Factorization/README.md index 45d28081d4728..cf9172c696562 100644 --- a/solution/0600-0699/0625.Minimum Factorization/README.md +++ b/solution/0600-0699/0625.Minimum Factorization/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def smallestFactorization(self, num: int) -> int: @@ -79,6 +81,8 @@ class Solution: return ans if num < 2 and ans <= 2**31 - 1 else 0 ``` +#### Java + ```java class Solution { public int smallestFactorization(int num) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func smallestFactorization(num int) int { if num < 2 { diff --git a/solution/0600-0699/0625.Minimum Factorization/README_EN.md b/solution/0600-0699/0625.Minimum Factorization/README_EN.md index 0622d7a1ba2db..c06de8f21d86e 100644 --- a/solution/0600-0699/0625.Minimum Factorization/README_EN.md +++ b/solution/0600-0699/0625.Minimum Factorization/README_EN.md @@ -44,6 +44,8 @@ tags: +#### Python3 + ```python class Solution: def smallestFactorization(self, num: int) -> int: @@ -58,6 +60,8 @@ class Solution: return ans if num < 2 and ans <= 2**31 - 1 else 0 ``` +#### Java + ```java class Solution { public int smallestFactorization(int num) { @@ -79,6 +83,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,6 +107,8 @@ public: }; ``` +#### Go + ```go func smallestFactorization(num int) int { if num < 2 { diff --git a/solution/0600-0699/0626.Exchange Seats/README.md b/solution/0600-0699/0626.Exchange Seats/README.md index dd7e5edabe319..5cae44413126e 100644 --- a/solution/0600-0699/0626.Exchange Seats/README.md +++ b/solution/0600-0699/0626.Exchange Seats/README.md @@ -77,6 +77,8 @@ Seat 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT s1.id, COALESCE(s2.student, s1.student) AS student @@ -96,6 +98,8 @@ ORDER BY 1; +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -122,6 +126,8 @@ ORDER BY 1; +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -140,6 +146,8 @@ FROM Seat; +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/0600-0699/0626.Exchange Seats/README_EN.md b/solution/0600-0699/0626.Exchange Seats/README_EN.md index ac9fbaf2fd242..d3e57efc6fcf7 100644 --- a/solution/0600-0699/0626.Exchange Seats/README_EN.md +++ b/solution/0600-0699/0626.Exchange Seats/README_EN.md @@ -77,6 +77,8 @@ Note that if the number of students is odd, there is no need to change the last +#### MySQL + ```sql # Write your MySQL query statement below SELECT s1.id, COALESCE(s2.student, s1.student) AS student @@ -96,6 +98,8 @@ ORDER BY 1; +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -122,6 +126,8 @@ ORDER BY 1; +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -140,6 +146,8 @@ FROM Seat; +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/0600-0699/0627.Swap Salary/README.md b/solution/0600-0699/0627.Swap Salary/README.md index 2c692c456c5c0..e5bc267b208bd 100644 --- a/solution/0600-0699/0627.Swap Salary/README.md +++ b/solution/0600-0699/0627.Swap Salary/README.md @@ -82,6 +82,8 @@ Salary 表: +#### MySQL + ```sql UPDATE salary SET sex = CASE sex @@ -100,6 +102,8 @@ END; +#### MySQL + ```sql # Write your MySQL query statement below UPDATE Salary diff --git a/solution/0600-0699/0627.Swap Salary/README_EN.md b/solution/0600-0699/0627.Swap Salary/README_EN.md index 650bcc81f35fb..48bf39566df35 100644 --- a/solution/0600-0699/0627.Swap Salary/README_EN.md +++ b/solution/0600-0699/0627.Swap Salary/README_EN.md @@ -78,6 +78,8 @@ Salary table: +#### MySQL + ```sql UPDATE salary SET sex = CASE sex @@ -96,6 +98,8 @@ END; +#### MySQL + ```sql # Write your MySQL query statement below UPDATE Salary diff --git a/solution/0600-0699/0628.Maximum Product of Three Numbers/README.md b/solution/0600-0699/0628.Maximum Product of Three Numbers/README.md index 65e0adc217b39..9a5241f911850 100644 --- a/solution/0600-0699/0628.Maximum Product of Three Numbers/README.md +++ b/solution/0600-0699/0628.Maximum Product of Three Numbers/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def maximumProduct(self, nums: List[int]) -> int: @@ -80,6 +82,8 @@ class Solution: return max(a, b) ``` +#### Java + ```java class Solution { public int maximumProduct(int[] nums) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func maximumProduct(nums []int) int { sort.Ints(nums) @@ -118,6 +126,8 @@ func maximumProduct(nums []int) int { } ``` +#### TypeScript + ```ts function maximumProduct(nums: number[]): number { nums.sort((a, b) => a - b); @@ -144,6 +154,8 @@ function maximumProduct(nums: number[]): number { +#### Python3 + ```python class Solution: def maximumProduct(self, nums: List[int]) -> int: @@ -152,6 +164,8 @@ class Solution: return max(top3[0] * top3[1] * top3[2], top3[0] * bottom2[0] * bottom2[1]) ``` +#### Java + ```java class Solution { public int maximumProduct(int[] nums) { @@ -181,6 +195,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -211,6 +227,8 @@ public: }; ``` +#### Go + ```go func maximumProduct(nums []int) int { const inf = 1 << 30 @@ -234,6 +252,8 @@ func maximumProduct(nums []int) int { } ``` +#### TypeScript + ```ts function maximumProduct(nums: number[]): number { const inf = 1 << 30; diff --git a/solution/0600-0699/0628.Maximum Product of Three Numbers/README_EN.md b/solution/0600-0699/0628.Maximum Product of Three Numbers/README_EN.md index e13ab6c0eb85a..1dc90552924b4 100644 --- a/solution/0600-0699/0628.Maximum Product of Three Numbers/README_EN.md +++ b/solution/0600-0699/0628.Maximum Product of Three Numbers/README_EN.md @@ -49,6 +49,8 @@ tags: +#### Python3 + ```python class Solution: def maximumProduct(self, nums: List[int]) -> int: @@ -58,6 +60,8 @@ class Solution: return max(a, b) ``` +#### Java + ```java class Solution { public int maximumProduct(int[] nums) { @@ -70,6 +74,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -83,6 +89,8 @@ public: }; ``` +#### Go + ```go func maximumProduct(nums []int) int { sort.Ints(nums) @@ -96,6 +104,8 @@ func maximumProduct(nums []int) int { } ``` +#### TypeScript + ```ts function maximumProduct(nums: number[]): number { nums.sort((a, b) => a - b); @@ -116,6 +126,8 @@ function maximumProduct(nums: number[]): number { +#### Python3 + ```python class Solution: def maximumProduct(self, nums: List[int]) -> int: @@ -124,6 +136,8 @@ class Solution: return max(top3[0] * top3[1] * top3[2], top3[0] * bottom2[0] * bottom2[1]) ``` +#### Java + ```java class Solution { public int maximumProduct(int[] nums) { @@ -153,6 +167,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -183,6 +199,8 @@ public: }; ``` +#### Go + ```go func maximumProduct(nums []int) int { const inf = 1 << 30 @@ -206,6 +224,8 @@ func maximumProduct(nums []int) int { } ``` +#### TypeScript + ```ts function maximumProduct(nums: number[]): number { const inf = 1 << 30; diff --git a/solution/0600-0699/0629.K Inverse Pairs Array/README.md b/solution/0600-0699/0629.K Inverse Pairs Array/README.md index e8caabdabf8b4..42c298d7b8c6e 100644 --- a/solution/0600-0699/0629.K Inverse Pairs Array/README.md +++ b/solution/0600-0699/0629.K Inverse Pairs Array/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def kInversePairs(self, n: int, k: int) -> int: @@ -91,6 +93,8 @@ class Solution: return f[k] ``` +#### Java + ```java class Solution { public int kInversePairs(int n, int k) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func kInversePairs(n int, k int) int { f := make([]int, k+1) @@ -158,6 +166,8 @@ func kInversePairs(n int, k int) int { } ``` +#### TypeScript + ```ts function kInversePairs(n: number, k: number): number { const f: number[] = new Array(k + 1).fill(0); diff --git a/solution/0600-0699/0629.K Inverse Pairs Array/README_EN.md b/solution/0600-0699/0629.K Inverse Pairs Array/README_EN.md index 2888780bda7a1..c8eec2c12a9bb 100644 --- a/solution/0600-0699/0629.K Inverse Pairs Array/README_EN.md +++ b/solution/0600-0699/0629.K Inverse Pairs Array/README_EN.md @@ -55,6 +55,8 @@ tags: +#### Python3 + ```python class Solution: def kInversePairs(self, n: int, k: int) -> int: @@ -69,6 +71,8 @@ class Solution: return f[k] ``` +#### Java + ```java class Solution { public int kInversePairs(int n, int k) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func kInversePairs(n int, k int) int { f := make([]int, k+1) @@ -136,6 +144,8 @@ func kInversePairs(n int, k int) int { } ``` +#### TypeScript + ```ts function kInversePairs(n: number, k: number): number { const f: number[] = new Array(k + 1).fill(0); diff --git a/solution/0600-0699/0630.Course Schedule III/README.md b/solution/0600-0699/0630.Course Schedule III/README.md index 56483eda6a731..6375a17781381 100644 --- a/solution/0600-0699/0630.Course Schedule III/README.md +++ b/solution/0600-0699/0630.Course Schedule III/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def scheduleCourse(self, courses: List[List[int]]) -> int: @@ -94,6 +96,8 @@ class Solution: return len(pq) ``` +#### Java + ```java class Solution { public int scheduleCourse(int[][] courses) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func scheduleCourse(courses [][]int) int { sort.Slice(courses, func(i, j int) bool { return courses[i][1] < courses[j][1] }) @@ -166,6 +174,8 @@ func (h *hp) push(v int) { heap.Push(h, v) } func (h *hp) pop() int { return heap.Pop(h).(int) } ``` +#### TypeScript + ```ts function scheduleCourse(courses: number[][]): number { courses.sort((a, b) => a[1] - b[1]); diff --git a/solution/0600-0699/0630.Course Schedule III/README_EN.md b/solution/0600-0699/0630.Course Schedule III/README_EN.md index 4ec1cdb99e4ff..635e4695af275 100644 --- a/solution/0600-0699/0630.Course Schedule III/README_EN.md +++ b/solution/0600-0699/0630.Course Schedule III/README_EN.md @@ -71,6 +71,8 @@ The 4th course cannot be taken now, since you will finish it on the 3 +#### Python3 + ```python class Solution: def scheduleCourse(self, courses: List[List[int]]) -> int: @@ -85,6 +87,8 @@ class Solution: return len(pq) ``` +#### Java + ```java class Solution { public int scheduleCourse(int[][] courses) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func scheduleCourse(courses [][]int) int { sort.Slice(courses, func(i, j int) bool { return courses[i][1] < courses[j][1] }) @@ -157,6 +165,8 @@ func (h *hp) push(v int) { heap.Push(h, v) } func (h *hp) pop() int { return heap.Pop(h).(int) } ``` +#### TypeScript + ```ts function scheduleCourse(courses: number[][]): number { courses.sort((a, b) => a[1] - b[1]); diff --git a/solution/0600-0699/0631.Design Excel Sum Formula/README.md b/solution/0600-0699/0631.Design Excel Sum Formula/README.md index ca88028d675df..5559a4feeaeec 100644 --- a/solution/0600-0699/0631.Design Excel Sum Formula/README.md +++ b/solution/0600-0699/0631.Design Excel Sum Formula/README.md @@ -115,18 +115,26 @@ excel.get(3, "C"); // 返回 6 +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/0600-0699/0631.Design Excel Sum Formula/README_EN.md b/solution/0600-0699/0631.Design Excel Sum Formula/README_EN.md index e3acef8df7024..cd7ce68ca40f6 100644 --- a/solution/0600-0699/0631.Design Excel Sum Formula/README_EN.md +++ b/solution/0600-0699/0631.Design Excel Sum Formula/README_EN.md @@ -112,18 +112,26 @@ excel.get(3, "C"); // return 6 +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/0600-0699/0632.Smallest Range Covering Elements from K Lists/README.md b/solution/0600-0699/0632.Smallest Range Covering Elements from K Lists/README.md index cc9d9e1d8795e..205eb1341a136 100644 --- a/solution/0600-0699/0632.Smallest Range Covering Elements from K Lists/README.md +++ b/solution/0600-0699/0632.Smallest Range Covering Elements from K Lists/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def smallestRange(self, nums: List[List[int]]) -> List[int]: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] smallestRange(List> nums) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -182,6 +188,8 @@ public: }; ``` +#### Go + ```go func smallestRange(nums [][]int) []int { t := [][]int{} @@ -214,6 +222,8 @@ func smallestRange(nums [][]int) []int { } ``` +#### Rust + ```rust impl Solution { pub fn smallest_range(nums: Vec>) -> Vec { diff --git a/solution/0600-0699/0632.Smallest Range Covering Elements from K Lists/README_EN.md b/solution/0600-0699/0632.Smallest Range Covering Elements from K Lists/README_EN.md index 87c8c9a6f9f0c..9ef1d2309b078 100644 --- a/solution/0600-0699/0632.Smallest Range Covering Elements from K Lists/README_EN.md +++ b/solution/0600-0699/0632.Smallest Range Covering Elements from K Lists/README_EN.md @@ -65,6 +65,8 @@ List 3: [5, 18, 22, 30], 22 is in range [20,24]. +#### Python3 + ```python class Solution: def smallestRange(self, nums: List[List[int]]) -> List[int]: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] smallestRange(List> nums) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go func smallestRange(nums [][]int) []int { t := [][]int{} @@ -202,6 +210,8 @@ func smallestRange(nums [][]int) []int { } ``` +#### Rust + ```rust impl Solution { pub fn smallest_range(nums: Vec>) -> Vec { diff --git a/solution/0600-0699/0633.Sum of Square Numbers/README.md b/solution/0600-0699/0633.Sum of Square Numbers/README.md index 6aa8760cfe794..83336bc2d3ce8 100644 --- a/solution/0600-0699/0633.Sum of Square Numbers/README.md +++ b/solution/0600-0699/0633.Sum of Square Numbers/README.md @@ -59,6 +59,8 @@ tags: +#### Python3 + ```python class Solution: def judgeSquareSum(self, c: int) -> bool: @@ -74,6 +76,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean judgeSquareSum(int c) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func judgeSquareSum(c int) bool { a, b := 0, int(math.Sqrt(float64(c))) @@ -133,6 +141,8 @@ func judgeSquareSum(c int) bool { } ``` +#### TypeScript + ```ts function judgeSquareSum(c: number): boolean { let [a, b] = [0, Math.floor(Math.sqrt(c))]; @@ -151,6 +161,8 @@ function judgeSquareSum(c: number): boolean { } ``` +#### Rust + ```rust use std::cmp::Ordering; diff --git a/solution/0600-0699/0633.Sum of Square Numbers/README_EN.md b/solution/0600-0699/0633.Sum of Square Numbers/README_EN.md index 07b859738d02b..2fa651879c40f 100644 --- a/solution/0600-0699/0633.Sum of Square Numbers/README_EN.md +++ b/solution/0600-0699/0633.Sum of Square Numbers/README_EN.md @@ -57,6 +57,8 @@ The time complexity is $O(\sqrt{c})$, where $c$ is the given non-negative intege +#### Python3 + ```python class Solution: def judgeSquareSum(self, c: int) -> bool: @@ -72,6 +74,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean judgeSquareSum(int c) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func judgeSquareSum(c int) bool { a, b := 0, int(math.Sqrt(float64(c))) @@ -131,6 +139,8 @@ func judgeSquareSum(c int) bool { } ``` +#### TypeScript + ```ts function judgeSquareSum(c: number): boolean { let [a, b] = [0, Math.floor(Math.sqrt(c))]; @@ -149,6 +159,8 @@ function judgeSquareSum(c: number): boolean { } ``` +#### Rust + ```rust use std::cmp::Ordering; diff --git a/solution/0600-0699/0634.Find the Derangement of An Array/README.md b/solution/0600-0699/0634.Find the Derangement of An Array/README.md index 0122a82dfb601..b143a8adc9bf7 100644 --- a/solution/0600-0699/0634.Find the Derangement of An Array/README.md +++ b/solution/0600-0699/0634.Find the Derangement of An Array/README.md @@ -73,6 +73,8 @@ $$ +#### Python3 + ```python class Solution: def findDerangement(self, n: int) -> int: @@ -83,6 +85,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int findDerangement(int n) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func findDerangement(n int) int { f := make([]int, n+1) @@ -137,6 +145,8 @@ func findDerangement(n int) int { +#### Python3 + ```python class Solution: def findDerangement(self, n: int) -> int: @@ -147,6 +157,8 @@ class Solution: return b ``` +#### Java + ```java class Solution { public int findDerangement(int n) { @@ -162,6 +174,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -178,6 +192,8 @@ public: }; ``` +#### Go + ```go func findDerangement(n int) int { a, b := 1, 0 diff --git a/solution/0600-0699/0634.Find the Derangement of An Array/README_EN.md b/solution/0600-0699/0634.Find the Derangement of An Array/README_EN.md index 6adcfc5114c2b..c46550c74ab15 100644 --- a/solution/0600-0699/0634.Find the Derangement of An Array/README_EN.md +++ b/solution/0600-0699/0634.Find the Derangement of An Array/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def findDerangement(self, n: int) -> int: @@ -81,6 +83,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int findDerangement(int n) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func findDerangement(n int) int { f := make([]int, n+1) @@ -135,6 +143,8 @@ We notice that the state transition equation only relates to $f[i - 1]$ and $f[i +#### Python3 + ```python class Solution: def findDerangement(self, n: int) -> int: @@ -145,6 +155,8 @@ class Solution: return b ``` +#### Java + ```java class Solution { public int findDerangement(int n) { @@ -160,6 +172,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +190,8 @@ public: }; ``` +#### Go + ```go func findDerangement(n int) int { a, b := 1, 0 diff --git a/solution/0600-0699/0635.Design Log Storage System/README.md b/solution/0600-0699/0635.Design Log Storage System/README.md index ff5787f2b1f01..1a735c2765de4 100644 --- a/solution/0600-0699/0635.Design Log Storage System/README.md +++ b/solution/0600-0699/0635.Design Log Storage System/README.md @@ -82,6 +82,8 @@ logSystem.retrieve("2016:01:01:01:01:01", "2017:01:01:23:00:00", "Hour"); +#### Python3 + ```python class LogSystem: def __init__(self): @@ -109,6 +111,8 @@ class LogSystem: # param_2 = obj.retrieve(start,end,granularity) ``` +#### Java + ```java class LogSystem { private List logs = new ArrayList<>(); @@ -160,6 +164,8 @@ class Log { */ ``` +#### C++ + ```cpp class LogSystem { public: @@ -203,6 +209,8 @@ private: */ ``` +#### Go + ```go type LogSystem struct { logs []pair diff --git a/solution/0600-0699/0635.Design Log Storage System/README_EN.md b/solution/0600-0699/0635.Design Log Storage System/README_EN.md index 3e05af7962f29..9fd2bf55cd5e6 100644 --- a/solution/0600-0699/0635.Design Log Storage System/README_EN.md +++ b/solution/0600-0699/0635.Design Log Storage System/README_EN.md @@ -81,6 +81,8 @@ In terms of time complexity, the time complexity of the `put()` method is $O(1)$ +#### Python3 + ```python class LogSystem: def __init__(self): @@ -108,6 +110,8 @@ class LogSystem: # param_2 = obj.retrieve(start,end,granularity) ``` +#### Java + ```java class LogSystem { private List logs = new ArrayList<>(); @@ -159,6 +163,8 @@ class Log { */ ``` +#### C++ + ```cpp class LogSystem { public: @@ -202,6 +208,8 @@ private: */ ``` +#### Go + ```go type LogSystem struct { logs []pair diff --git a/solution/0600-0699/0636.Exclusive Time of Functions/README.md b/solution/0600-0699/0636.Exclusive Time of Functions/README.md index c970a992535e1..75c3e690c3aa9 100644 --- a/solution/0600-0699/0636.Exclusive Time of Functions/README.md +++ b/solution/0600-0699/0636.Exclusive Time of Functions/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def exclusiveTime(self, n: int, logs: List[str]) -> List[int]: @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] exclusiveTime(int n, List logs) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go func exclusiveTime(n int, logs []string) []int { ans := make([]int, n) @@ -195,6 +203,8 @@ func exclusiveTime(n int, logs []string) []int { } ``` +#### TypeScript + ```ts function exclusiveTime(n: number, logs: string[]): number[] { const res = new Array(n).fill(0); diff --git a/solution/0600-0699/0636.Exclusive Time of Functions/README_EN.md b/solution/0600-0699/0636.Exclusive Time of Functions/README_EN.md index b3e6ab4d6cb3f..7c47b8d81f79c 100644 --- a/solution/0600-0699/0636.Exclusive Time of Functions/README_EN.md +++ b/solution/0600-0699/0636.Exclusive Time of Functions/README_EN.md @@ -91,6 +91,8 @@ So function 0 spends 2 + 4 + 1 = 7 units of total time executing, and function 1 +#### Python3 + ```python class Solution: def exclusiveTime(self, n: int, logs: List[str]) -> List[int]: @@ -113,6 +115,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] exclusiveTime(int n, List logs) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func exclusiveTime(n int, logs []string) []int { ans := make([]int, n) @@ -193,6 +201,8 @@ func exclusiveTime(n int, logs []string) []int { } ``` +#### TypeScript + ```ts function exclusiveTime(n: number, logs: string[]): number[] { const res = new Array(n).fill(0); diff --git a/solution/0600-0699/0637.Average of Levels in Binary Tree/README.md b/solution/0600-0699/0637.Average of Levels in Binary Tree/README.md index 23713b53a91ef..3709783744053 100644 --- a/solution/0600-0699/0637.Average of Levels in Binary Tree/README.md +++ b/solution/0600-0699/0637.Average of Levels in Binary Tree/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -195,6 +203,8 @@ func averageOfLevels(root *TreeNode) []float64 { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -246,6 +256,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -291,6 +303,8 @@ var averageOfLevels = function (root) { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -316,6 +330,8 @@ class Solution: return [a / b for a, b in s] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -362,6 +378,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -406,6 +424,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -442,6 +462,8 @@ func averageOfLevels(root *TreeNode) []float64 { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0600-0699/0637.Average of Levels in Binary Tree/README_EN.md b/solution/0600-0699/0637.Average of Levels in Binary Tree/README_EN.md index f8fa3bd84dec6..f86b9ced17929 100644 --- a/solution/0600-0699/0637.Average of Levels in Binary Tree/README_EN.md +++ b/solution/0600-0699/0637.Average of Levels in Binary Tree/README_EN.md @@ -56,6 +56,8 @@ Hence return [3, 14.5, 11]. +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -187,6 +195,8 @@ func averageOfLevels(root *TreeNode) []float64 { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -238,6 +248,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -283,6 +295,8 @@ var averageOfLevels = function (root) { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -308,6 +322,8 @@ class Solution: return [a / b for a, b in s] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -354,6 +370,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -398,6 +416,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -434,6 +454,8 @@ func averageOfLevels(root *TreeNode) []float64 { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0600-0699/0638.Shopping Offers/README.md b/solution/0600-0699/0638.Shopping Offers/README.md index 71a6190b21c60..b868682141790 100644 --- a/solution/0600-0699/0638.Shopping Offers/README.md +++ b/solution/0600-0699/0638.Shopping Offers/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def shoppingOffers( @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int shoppingOffers( @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func shoppingOffers(price []int, special [][]int, needs []int) int { total := func(price, needs []int) int { diff --git a/solution/0600-0699/0638.Shopping Offers/README_EN.md b/solution/0600-0699/0638.Shopping Offers/README_EN.md index 03236b742de9b..4178b57604475 100644 --- a/solution/0600-0699/0638.Shopping Offers/README_EN.md +++ b/solution/0600-0699/0638.Shopping Offers/README_EN.md @@ -74,6 +74,8 @@ You cannot add more items, though only $9 for 2A ,2B and 1C. +#### Python3 + ```python class Solution: def shoppingOffers( @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int shoppingOffers( @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func shoppingOffers(price []int, special [][]int, needs []int) int { total := func(price, needs []int) int { diff --git a/solution/0600-0699/0639.Decode Ways II/README.md b/solution/0600-0699/0639.Decode Ways II/README.md index 2e93f462746e5..20a7dc129311f 100644 --- a/solution/0600-0699/0639.Decode Ways II/README.md +++ b/solution/0600-0699/0639.Decode Ways II/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def numDecodings(self, s: str) -> int: @@ -133,6 +135,8 @@ class Solution: return c ``` +#### Java + ```java class Solution { @@ -184,6 +188,8 @@ class Solution { } ``` +#### Go + ```go const mod int = 1e9 + 7 diff --git a/solution/0600-0699/0639.Decode Ways II/README_EN.md b/solution/0600-0699/0639.Decode Ways II/README_EN.md index 311e9e1d1163c..ee140b91ed4fc 100644 --- a/solution/0600-0699/0639.Decode Ways II/README_EN.md +++ b/solution/0600-0699/0639.Decode Ways II/README_EN.md @@ -90,6 +90,8 @@ Hence, there are a total of (6 * 2) + (3 * 1) = 12 + 3 = 15 ways to decode " +#### Python3 + ```python class Solution: def numDecodings(self, s: str) -> int: @@ -132,6 +134,8 @@ class Solution: return c ``` +#### Java + ```java class Solution { @@ -183,6 +187,8 @@ class Solution { } ``` +#### Go + ```go const mod int = 1e9 + 7 diff --git a/solution/0600-0699/0640.Solve the Equation/README.md b/solution/0600-0699/0640.Solve the Equation/README.md index d03739fec241f..57cafdd7edc65 100644 --- a/solution/0600-0699/0640.Solve the Equation/README.md +++ b/solution/0600-0699/0640.Solve the Equation/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def solveEquation(self, equation: str) -> str: @@ -108,6 +110,8 @@ class Solution: return f'x={(y2 - y1) // (x1 - x2)}' ``` +#### Java + ```java class Solution { public String solveEquation(String equation) { @@ -147,6 +151,8 @@ class Solution { } ``` +#### Go + ```go func solveEquation(equation string) string { f := func(s string) []int { @@ -196,6 +202,8 @@ func solveEquation(equation string) string { } ``` +#### TypeScript + ```ts function solveEquation(equation: string): string { const [left, right] = equation.split('='); diff --git a/solution/0600-0699/0640.Solve the Equation/README_EN.md b/solution/0600-0699/0640.Solve the Equation/README_EN.md index 791f230ca72c7..1fb40d5a987b2 100644 --- a/solution/0600-0699/0640.Solve the Equation/README_EN.md +++ b/solution/0600-0699/0640.Solve the Equation/README_EN.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def solveEquation(self, equation: str) -> str: @@ -93,6 +95,8 @@ class Solution: return f'x={(y2 - y1) // (x1 - x2)}' ``` +#### Java + ```java class Solution { public String solveEquation(String equation) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### Go + ```go func solveEquation(equation string) string { f := func(s string) []int { @@ -181,6 +187,8 @@ func solveEquation(equation string) string { } ``` +#### TypeScript + ```ts function solveEquation(equation: string): string { const [left, right] = equation.split('='); diff --git a/solution/0600-0699/0641.Design Circular Deque/README.md b/solution/0600-0699/0641.Design Circular Deque/README.md index afe1841139510..3ea4114727864 100644 --- a/solution/0600-0699/0641.Design Circular Deque/README.md +++ b/solution/0600-0699/0641.Design Circular Deque/README.md @@ -90,6 +90,8 @@ circularDeque.getFront(); // 返回 4 +#### Python3 + ```python class MyCircularDeque: def __init__(self, k: int): @@ -185,6 +187,8 @@ class MyCircularDeque: # param_8 = obj.isFull() ``` +#### Java + ```java class MyCircularDeque { private int[] q; @@ -283,6 +287,8 @@ class MyCircularDeque { */ ``` +#### C++ + ```cpp class MyCircularDeque { public: @@ -366,6 +372,8 @@ public: */ ``` +#### Go + ```go type MyCircularDeque struct { q []int @@ -454,6 +462,8 @@ func (this *MyCircularDeque) IsFull() bool { */ ``` +#### TypeScript + ```ts class MyCircularDeque { private vals: number[]; diff --git a/solution/0600-0699/0641.Design Circular Deque/README_EN.md b/solution/0600-0699/0641.Design Circular Deque/README_EN.md index dca5b69c87b72..9cbe8d7a07512 100644 --- a/solution/0600-0699/0641.Design Circular Deque/README_EN.md +++ b/solution/0600-0699/0641.Design Circular Deque/README_EN.md @@ -77,6 +77,8 @@ myCircularDeque.getFront(); // return 4 +#### Python3 + ```python class MyCircularDeque: def __init__(self, k: int): @@ -172,6 +174,8 @@ class MyCircularDeque: # param_8 = obj.isFull() ``` +#### Java + ```java class MyCircularDeque { private int[] q; @@ -270,6 +274,8 @@ class MyCircularDeque { */ ``` +#### C++ + ```cpp class MyCircularDeque { public: @@ -353,6 +359,8 @@ public: */ ``` +#### Go + ```go type MyCircularDeque struct { q []int @@ -441,6 +449,8 @@ func (this *MyCircularDeque) IsFull() bool { */ ``` +#### TypeScript + ```ts class MyCircularDeque { private vals: number[]; diff --git a/solution/0600-0699/0642.Design Search Autocomplete System/README.md b/solution/0600-0699/0642.Design Search Autocomplete System/README.md index 8c43ed80e523b..3afce9550dbb4 100644 --- a/solution/0600-0699/0642.Design Search Autocomplete System/README.md +++ b/solution/0600-0699/0642.Design Search Autocomplete System/README.md @@ -92,6 +92,8 @@ obj.input("#"); // return []. The user finished the input, the sentence "i a" sh +#### Python3 + ```python class Trie: def __init__(self): @@ -156,6 +158,8 @@ class AutocompleteSystem: # param_1 = obj.input(c) ``` +#### Java + ```java class Trie { Trie[] children = new Trie[27]; diff --git a/solution/0600-0699/0642.Design Search Autocomplete System/README_EN.md b/solution/0600-0699/0642.Design Search Autocomplete System/README_EN.md index 0e5c0393c6232..b1c22de7dffea 100644 --- a/solution/0600-0699/0642.Design Search Autocomplete System/README_EN.md +++ b/solution/0600-0699/0642.Design Search Autocomplete System/README_EN.md @@ -90,6 +90,8 @@ obj.input("#"); // return []. The user finished the input, the sentenc +#### Python3 + ```python class Trie: def __init__(self): @@ -154,6 +156,8 @@ class AutocompleteSystem: # param_1 = obj.input(c) ``` +#### Java + ```java class Trie { Trie[] children = new Trie[27]; diff --git a/solution/0600-0699/0643.Maximum Average Subarray I/README.md b/solution/0600-0699/0643.Maximum Average Subarray I/README.md index d4d087bb2fdf8..b24844c03a889 100644 --- a/solution/0600-0699/0643.Maximum Average Subarray I/README.md +++ b/solution/0600-0699/0643.Maximum Average Subarray I/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def findMaxAverage(self, nums: List[int], k: int) -> float: @@ -74,6 +76,8 @@ class Solution: return ans / k ``` +#### Java + ```java class Solution { public double findMaxAverage(int[] nums, int k) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func findMaxAverage(nums []int, k int) float64 { s := 0 @@ -121,6 +129,8 @@ func findMaxAverage(nums []int, k int) float64 { } ``` +#### TypeScript + ```ts function findMaxAverage(nums: number[], k: number): number { let s = 0; @@ -136,6 +146,8 @@ function findMaxAverage(nums: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_max_average(nums: Vec, k: i32) -> f64 { @@ -152,6 +164,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0600-0699/0643.Maximum Average Subarray I/README_EN.md b/solution/0600-0699/0643.Maximum Average Subarray I/README_EN.md index 1998778b37fde..42ef9e7260cdd 100644 --- a/solution/0600-0699/0643.Maximum Average Subarray I/README_EN.md +++ b/solution/0600-0699/0643.Maximum Average Subarray I/README_EN.md @@ -60,6 +60,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def findMaxAverage(self, nums: List[int], k: int) -> float: @@ -70,6 +72,8 @@ class Solution: return ans / k ``` +#### Java + ```java class Solution { public double findMaxAverage(int[] nums, int k) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -102,6 +108,8 @@ public: }; ``` +#### Go + ```go func findMaxAverage(nums []int, k int) float64 { s := 0 @@ -117,6 +125,8 @@ func findMaxAverage(nums []int, k int) float64 { } ``` +#### TypeScript + ```ts function findMaxAverage(nums: number[], k: number): number { let s = 0; @@ -132,6 +142,8 @@ function findMaxAverage(nums: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_max_average(nums: Vec, k: i32) -> f64 { @@ -148,6 +160,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0600-0699/0644.Maximum Average Subarray II/README.md b/solution/0600-0699/0644.Maximum Average Subarray II/README.md index 6519caab7ccc5..3e971e8d3137e 100644 --- a/solution/0600-0699/0644.Maximum Average Subarray II/README.md +++ b/solution/0600-0699/0644.Maximum Average Subarray II/README.md @@ -98,6 +98,8 @@ $$ +#### Python3 + ```python class Solution: def findMaxAverage(self, nums: List[int], k: int) -> float: @@ -125,6 +127,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { public double findMaxAverage(int[] nums, int k) { @@ -168,6 +172,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -208,6 +214,8 @@ public: }; ``` +#### Go + ```go func findMaxAverage(nums []int, k int) float64 { eps := 1e-5 @@ -245,6 +253,8 @@ func findMaxAverage(nums []int, k int) float64 { } ``` +#### TypeScript + ```ts function findMaxAverage(nums: number[], k: number): number { const eps = 1e-5; diff --git a/solution/0600-0699/0644.Maximum Average Subarray II/README_EN.md b/solution/0600-0699/0644.Maximum Average Subarray II/README_EN.md index 1161b6e8568e5..e83657be1da01 100644 --- a/solution/0600-0699/0644.Maximum Average Subarray II/README_EN.md +++ b/solution/0600-0699/0644.Maximum Average Subarray II/README_EN.md @@ -96,6 +96,8 @@ The time complexity is $O(n \times \log M)$, where $n$ and $M$ are the length of +#### Python3 + ```python class Solution: def findMaxAverage(self, nums: List[int], k: int) -> float: @@ -123,6 +125,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { public double findMaxAverage(int[] nums, int k) { @@ -166,6 +170,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -206,6 +212,8 @@ public: }; ``` +#### Go + ```go func findMaxAverage(nums []int, k int) float64 { eps := 1e-5 @@ -243,6 +251,8 @@ func findMaxAverage(nums []int, k int) float64 { } ``` +#### TypeScript + ```ts function findMaxAverage(nums: number[], k: number): number { const eps = 1e-5; diff --git a/solution/0600-0699/0645.Set Mismatch/README.md b/solution/0600-0699/0645.Set Mismatch/README.md index e4768bec61d06..8d964455d6425 100644 --- a/solution/0600-0699/0645.Set Mismatch/README.md +++ b/solution/0600-0699/0645.Set Mismatch/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def findErrorNums(self, nums: List[int]) -> List[int]: @@ -76,6 +78,8 @@ class Solution: return [s - s2, s1 - s2] ``` +#### Java + ```java class Solution { public int[] findErrorNums(int[] nums) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func findErrorNums(nums []int) []int { n := len(nums) @@ -129,6 +137,8 @@ func findErrorNums(nums []int) []int { } ``` +#### TypeScript + ```ts function findErrorNums(nums: number[]): number[] { const n = nums.length; @@ -139,6 +149,8 @@ function findErrorNums(nums: number[]): number[] { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -168,6 +180,8 @@ impl Solution { +#### Python3 + ```python class Solution: def findErrorNums(self, nums: List[int]) -> List[int]: @@ -182,6 +196,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] findErrorNums(int[] nums) { @@ -204,6 +220,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -226,6 +244,8 @@ public: }; ``` +#### Go + ```go func findErrorNums(nums []int) []int { n := len(nums) @@ -245,6 +265,8 @@ func findErrorNums(nums []int) []int { } ``` +#### TypeScript + ```ts function findErrorNums(nums: number[]): number[] { const n = nums.length; @@ -265,6 +287,8 @@ function findErrorNums(nums: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn find_error_nums(nums: Vec) -> Vec { @@ -311,6 +335,8 @@ impl Solution { +#### Python3 + ```python class Solution: def findErrorNums(self, nums: List[int]) -> List[int]: @@ -331,6 +357,8 @@ class Solution: return [b, a] ``` +#### Java + ```java class Solution { public int[] findErrorNums(int[] nums) { @@ -360,6 +388,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -390,6 +420,8 @@ public: }; ``` +#### Go + ```go func findErrorNums(nums []int) []int { xs := 0 @@ -416,6 +448,8 @@ func findErrorNums(nums []int) []int { } ``` +#### TypeScript + ```ts function findErrorNums(nums: number[]): number[] { const n = nums.length; diff --git a/solution/0600-0699/0645.Set Mismatch/README_EN.md b/solution/0600-0699/0645.Set Mismatch/README_EN.md index bd285e4ffb433..ed22e4abc0388 100644 --- a/solution/0600-0699/0645.Set Mismatch/README_EN.md +++ b/solution/0600-0699/0645.Set Mismatch/README_EN.md @@ -57,6 +57,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python class Solution: def findErrorNums(self, nums: List[int]) -> List[int]: @@ -67,6 +69,8 @@ class Solution: return [s - s2, s1 - s2] ``` +#### Java + ```java class Solution { public int[] findErrorNums(int[] nums) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -103,6 +109,8 @@ public: }; ``` +#### Go + ```go func findErrorNums(nums []int) []int { n := len(nums) @@ -120,6 +128,8 @@ func findErrorNums(nums []int) []int { } ``` +#### TypeScript + ```ts function findErrorNums(nums: number[]): number[] { const n = nums.length; @@ -130,6 +140,8 @@ function findErrorNums(nums: number[]): number[] { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -159,6 +171,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python class Solution: def findErrorNums(self, nums: List[int]) -> List[int]: @@ -173,6 +187,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] findErrorNums(int[] nums) { @@ -195,6 +211,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -217,6 +235,8 @@ public: }; ``` +#### Go + ```go func findErrorNums(nums []int) []int { n := len(nums) @@ -236,6 +256,8 @@ func findErrorNums(nums []int) []int { } ``` +#### TypeScript + ```ts function findErrorNums(nums: number[]): number[] { const n = nums.length; @@ -256,6 +278,8 @@ function findErrorNums(nums: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn find_error_nums(nums: Vec) -> Vec { @@ -302,6 +326,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def findErrorNums(self, nums: List[int]) -> List[int]: @@ -322,6 +348,8 @@ class Solution: return [b, a] ``` +#### Java + ```java class Solution { public int[] findErrorNums(int[] nums) { @@ -351,6 +379,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -381,6 +411,8 @@ public: }; ``` +#### Go + ```go func findErrorNums(nums []int) []int { xs := 0 @@ -407,6 +439,8 @@ func findErrorNums(nums []int) []int { } ``` +#### TypeScript + ```ts function findErrorNums(nums: number[]): number[] { const n = nums.length; diff --git a/solution/0600-0699/0646.Maximum Length of Pair Chain/README.md b/solution/0600-0699/0646.Maximum Length of Pair Chain/README.md index 098aa7b52ba87..35fe08f8b231e 100644 --- a/solution/0600-0699/0646.Maximum Length of Pair Chain/README.md +++ b/solution/0600-0699/0646.Maximum Length of Pair Chain/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def findLongestChain(self, pairs: List[List[int]]) -> int: @@ -80,6 +82,8 @@ class Solution: return max(dp) ``` +#### Java + ```java class Solution { public int findLongestChain(int[][] pairs) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func findLongestChain(pairs [][]int) int { sort.Slice(pairs, func(i, j int) bool { @@ -145,6 +153,8 @@ func findLongestChain(pairs [][]int) int { } ``` +#### TypeScript + ```ts function findLongestChain(pairs: number[][]): number { pairs.sort((a, b) => a[0] - b[0]); @@ -161,6 +171,8 @@ function findLongestChain(pairs: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_longest_chain(mut pairs: Vec>) -> i32 { @@ -193,6 +205,8 @@ impl Solution { +#### Python3 + ```python class Solution: def findLongestChain(self, pairs: List[List[int]]) -> int: @@ -204,6 +218,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findLongestChain(int[][] pairs) { @@ -221,6 +237,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -240,6 +258,8 @@ public: }; ``` +#### Go + ```go func findLongestChain(pairs [][]int) int { sort.Slice(pairs, func(i, j int) bool { @@ -256,6 +276,8 @@ func findLongestChain(pairs [][]int) int { } ``` +#### TypeScript + ```ts function findLongestChain(pairs: number[][]): number { pairs.sort((a, b) => a[1] - b[1]); @@ -271,6 +293,8 @@ function findLongestChain(pairs: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_longest_chain(mut pairs: Vec>) -> i32 { diff --git a/solution/0600-0699/0646.Maximum Length of Pair Chain/README_EN.md b/solution/0600-0699/0646.Maximum Length of Pair Chain/README_EN.md index 00d06661797af..fecadc1d4bd31 100644 --- a/solution/0600-0699/0646.Maximum Length of Pair Chain/README_EN.md +++ b/solution/0600-0699/0646.Maximum Length of Pair Chain/README_EN.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def findLongestChain(self, pairs: List[List[int]]) -> int: @@ -75,6 +77,8 @@ class Solution: return max(dp) ``` +#### Java + ```java class Solution { public int findLongestChain(int[][] pairs) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func findLongestChain(pairs [][]int) int { sort.Slice(pairs, func(i, j int) bool { @@ -140,6 +148,8 @@ func findLongestChain(pairs [][]int) int { } ``` +#### TypeScript + ```ts function findLongestChain(pairs: number[][]): number { pairs.sort((a, b) => a[0] - b[0]); @@ -156,6 +166,8 @@ function findLongestChain(pairs: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_longest_chain(mut pairs: Vec>) -> i32 { @@ -184,6 +196,8 @@ impl Solution { +#### Python3 + ```python class Solution: def findLongestChain(self, pairs: List[List[int]]) -> int: @@ -195,6 +209,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findLongestChain(int[][] pairs) { @@ -212,6 +228,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -231,6 +249,8 @@ public: }; ``` +#### Go + ```go func findLongestChain(pairs [][]int) int { sort.Slice(pairs, func(i, j int) bool { @@ -247,6 +267,8 @@ func findLongestChain(pairs [][]int) int { } ``` +#### TypeScript + ```ts function findLongestChain(pairs: number[][]): number { pairs.sort((a, b) => a[1] - b[1]); @@ -262,6 +284,8 @@ function findLongestChain(pairs: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_longest_chain(mut pairs: Vec>) -> i32 { diff --git a/solution/0600-0699/0647.Palindromic Substrings/README.md b/solution/0600-0699/0647.Palindromic Substrings/README.md index d8a3ce7ae28b1..404db50562ab7 100644 --- a/solution/0600-0699/0647.Palindromic Substrings/README.md +++ b/solution/0600-0699/0647.Palindromic Substrings/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def countSubstrings(self, s: str) -> int: @@ -76,6 +78,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countSubstrings(String s) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func countSubstrings(s string) int { ans, n := 0, len(s) @@ -127,6 +135,8 @@ func countSubstrings(s string) int { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -162,6 +172,8 @@ var countSubstrings = function (s) { +#### Python3 + ```python class Solution: def countSubstrings(self, s: str) -> int: @@ -181,6 +193,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countSubstrings(String s) { diff --git a/solution/0600-0699/0647.Palindromic Substrings/README_EN.md b/solution/0600-0699/0647.Palindromic Substrings/README_EN.md index df85e6f84cc26..3ed7a61228e9a 100644 --- a/solution/0600-0699/0647.Palindromic Substrings/README_EN.md +++ b/solution/0600-0699/0647.Palindromic Substrings/README_EN.md @@ -59,6 +59,8 @@ tags: +#### Python3 + ```python class Solution: def countSubstrings(self, s: str) -> int: @@ -71,6 +73,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countSubstrings(String s) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func countSubstrings(s string) int { ans, n := 0, len(s) @@ -122,6 +130,8 @@ func countSubstrings(s string) int { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -153,6 +163,8 @@ var countSubstrings = function (s) { +#### Python3 + ```python class Solution: def countSubstrings(self, s: str) -> int: @@ -172,6 +184,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countSubstrings(String s) { diff --git a/solution/0600-0699/0648.Replace Words/README.md b/solution/0600-0699/0648.Replace Words/README.md index 2ba18484f85ab..457845d77a9cc 100644 --- a/solution/0600-0699/0648.Replace Words/README.md +++ b/solution/0600-0699/0648.Replace Words/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Trie: def __init__(self): @@ -117,6 +119,8 @@ class Solution: return " ".join(ans) ``` +#### Java + ```java class Solution { public String replaceWords(List dictionary, String sentence) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { private: @@ -197,6 +203,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [26]*Trie @@ -252,6 +260,8 @@ func replaceWords(dictionary []string, sentence string) string { } ``` +#### TypeScript + ```ts class Trie { private children: Trie[]; @@ -315,6 +325,8 @@ function replaceWords(dictionary: string[], sentence: string): string { +#### Java + ```java class Trie { private Trie[] children = new Trie[26]; diff --git a/solution/0600-0699/0648.Replace Words/README_EN.md b/solution/0600-0699/0648.Replace Words/README_EN.md index 26ac0fabe0dc4..d55cb01f50ab2 100644 --- a/solution/0600-0699/0648.Replace Words/README_EN.md +++ b/solution/0600-0699/0648.Replace Words/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Trie: def __init__(self): @@ -104,6 +106,8 @@ class Solution: return " ".join(ans) ``` +#### Java + ```java class Solution { public String replaceWords(List dictionary, String sentence) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { private: @@ -184,6 +190,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [26]*Trie @@ -239,6 +247,8 @@ func replaceWords(dictionary []string, sentence string) string { } ``` +#### TypeScript + ```ts class Trie { private children: Trie[]; @@ -302,6 +312,8 @@ function replaceWords(dictionary: string[], sentence: string): string { +#### Java + ```java class Trie { private Trie[] children = new Trie[26]; diff --git a/solution/0600-0699/0649.Dota2 Senate/README.md b/solution/0600-0699/0649.Dota2 Senate/README.md index a9dc3e7f151a0..bbf2122da4f40 100644 --- a/solution/0600-0699/0649.Dota2 Senate/README.md +++ b/solution/0600-0699/0649.Dota2 Senate/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def predictPartyVictory(self, senate: str) -> str: @@ -108,6 +110,8 @@ class Solution: return "Radiant" if qr else "Dire" ``` +#### Java + ```java class Solution { public String predictPartyVictory(String senate) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func predictPartyVictory(senate string) string { n := len(senate) @@ -193,6 +201,8 @@ func predictPartyVictory(senate string) string { } ``` +#### TypeScript + ```ts function predictPartyVictory(senate: string): string { const n = senate.length; @@ -218,6 +228,8 @@ function predictPartyVictory(senate: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn predict_party_victory(senate: String) -> String { diff --git a/solution/0600-0699/0649.Dota2 Senate/README_EN.md b/solution/0600-0699/0649.Dota2 Senate/README_EN.md index 49172e4a77529..41046b7247300 100644 --- a/solution/0600-0699/0649.Dota2 Senate/README_EN.md +++ b/solution/0600-0699/0649.Dota2 Senate/README_EN.md @@ -76,6 +76,8 @@ And in round 2, the third senator can just announce the victory since he is the +#### Python3 + ```python class Solution: def predictPartyVictory(self, senate: str) -> str: @@ -97,6 +99,8 @@ class Solution: return "Radiant" if qr else "Dire" ``` +#### Java + ```java class Solution { public String predictPartyVictory(String senate) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func predictPartyVictory(senate string) string { n := len(senate) @@ -182,6 +190,8 @@ func predictPartyVictory(senate string) string { } ``` +#### TypeScript + ```ts function predictPartyVictory(senate: string): string { const n = senate.length; @@ -207,6 +217,8 @@ function predictPartyVictory(senate: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn predict_party_victory(senate: String) -> String { diff --git a/solution/0600-0699/0650.2 Keys Keyboard/README.md b/solution/0600-0699/0650.2 Keys Keyboard/README.md index a690cda91f456..ba78770327fee 100644 --- a/solution/0600-0699/0650.2 Keys Keyboard/README.md +++ b/solution/0600-0699/0650.2 Keys Keyboard/README.md @@ -75,6 +75,8 @@ $$ +#### Python3 + ```python class Solution: def minSteps(self, n: int) -> int: @@ -92,6 +94,8 @@ class Solution: return dfs(n) ``` +#### Java + ```java class Solution { private int[] f; @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func minSteps(n int) int { f := make([]int, n+1) @@ -190,6 +198,8 @@ $$ +#### Python3 + ```python class Solution: def minSteps(self, n: int) -> int: @@ -204,6 +214,8 @@ class Solution: return dp[-1] ``` +#### Java + ```java class Solution { public int minSteps(int n) { @@ -224,6 +236,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -243,6 +257,8 @@ public: }; ``` +#### Go + ```go func minSteps(n int) int { dp := make([]int, n+1) @@ -271,6 +287,8 @@ func minSteps(n int) int { +#### Java + ```java class Solution { public int minSteps(int n) { diff --git a/solution/0600-0699/0650.2 Keys Keyboard/README_EN.md b/solution/0600-0699/0650.2 Keys Keyboard/README_EN.md index f3ee2fea1947c..e7bb4600ebb1f 100644 --- a/solution/0600-0699/0650.2 Keys Keyboard/README_EN.md +++ b/solution/0600-0699/0650.2 Keys Keyboard/README_EN.md @@ -62,6 +62,8 @@ In step 3, we use Paste operation to get 'AAA'. +#### Python3 + ```python class Solution: def minSteps(self, n: int) -> int: @@ -79,6 +81,8 @@ class Solution: return dfs(n) ``` +#### Java + ```java class Solution { private int[] f; @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func minSteps(n int) int { f := make([]int, n+1) @@ -169,6 +177,8 @@ func minSteps(n int) int { +#### Python3 + ```python class Solution: def minSteps(self, n: int) -> int: @@ -183,6 +193,8 @@ class Solution: return dp[-1] ``` +#### Java + ```java class Solution { public int minSteps(int n) { @@ -203,6 +215,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -222,6 +236,8 @@ public: }; ``` +#### Go + ```go func minSteps(n int) int { dp := make([]int, n+1) @@ -250,6 +266,8 @@ func minSteps(n int) int { +#### Java + ```java class Solution { public int minSteps(int n) { diff --git a/solution/0600-0699/0651.4 Keys Keyboard/README.md b/solution/0600-0699/0651.4 Keys Keyboard/README.md index 75a7cfe3dd508..6b57bc0b29360 100644 --- a/solution/0600-0699/0651.4 Keys Keyboard/README.md +++ b/solution/0600-0699/0651.4 Keys Keyboard/README.md @@ -77,6 +77,8 @@ A, A, A, Ctrl A, Ctrl C, Ctrl V, Ctrl V +#### Python3 + ```python class Solution: def maxA(self, n: int) -> int: @@ -87,6 +89,8 @@ class Solution: return dp[-1] ``` +#### Java + ```java class Solution { public int maxA(int n) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func maxA(n int) int { dp := make([]int, n+1) diff --git a/solution/0600-0699/0651.4 Keys Keyboard/README_EN.md b/solution/0600-0699/0651.4 Keys Keyboard/README_EN.md index 25905e355ab45..4049e5da2f963 100644 --- a/solution/0600-0699/0651.4 Keys Keyboard/README_EN.md +++ b/solution/0600-0699/0651.4 Keys Keyboard/README_EN.md @@ -64,6 +64,8 @@ A, A, A, Ctrl A, Ctrl C, Ctrl V, Ctrl V +#### Python3 + ```python class Solution: def maxA(self, n: int) -> int: @@ -74,6 +76,8 @@ class Solution: return dp[-1] ``` +#### Java + ```java class Solution { public int maxA(int n) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func maxA(n int) int { dp := make([]int, n+1) diff --git a/solution/0600-0699/0652.Find Duplicate Subtrees/README.md b/solution/0600-0699/0652.Find Duplicate Subtrees/README.md index 094cf8a42292a..bd67f9da71917 100644 --- a/solution/0600-0699/0652.Find Duplicate Subtrees/README.md +++ b/solution/0600-0699/0652.Find Duplicate Subtrees/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -200,6 +208,8 @@ func findDuplicateSubtrees(root *TreeNode) []*TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -235,6 +245,8 @@ function findDuplicateSubtrees(root: TreeNode | null): Array { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/0600-0699/0652.Find Duplicate Subtrees/README_EN.md b/solution/0600-0699/0652.Find Duplicate Subtrees/README_EN.md index 37b416c7f870d..f1b4cfb8eb1f5 100644 --- a/solution/0600-0699/0652.Find Duplicate Subtrees/README_EN.md +++ b/solution/0600-0699/0652.Find Duplicate Subtrees/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -193,6 +201,8 @@ func findDuplicateSubtrees(root *TreeNode) []*TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -228,6 +238,8 @@ function findDuplicateSubtrees(root: TreeNode | null): Array { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/0600-0699/0653.Two Sum IV - Input is a BST/README.md b/solution/0600-0699/0653.Two Sum IV - Input is a BST/README.md index 954e6364d18b4..fb2fd72db6565 100644 --- a/solution/0600-0699/0653.Two Sum IV - Input is a BST/README.md +++ b/solution/0600-0699/0653.Two Sum IV - Input is a BST/README.md @@ -65,6 +65,8 @@ DFS 遍历二叉搜索树,对于每个节点,判断 `k - node.val` 是否在 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -86,6 +88,8 @@ class Solution: return dfs(root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -182,6 +190,8 @@ func findTarget(root *TreeNode, k int) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -213,6 +223,8 @@ function findTarget(root: TreeNode | null, k: number): boolean { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -270,6 +282,8 @@ impl Solution { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -294,6 +308,8 @@ class Solution: return False ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -335,6 +351,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -373,6 +391,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -405,6 +425,8 @@ func findTarget(root *TreeNode, k int) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0600-0699/0653.Two Sum IV - Input is a BST/README_EN.md b/solution/0600-0699/0653.Two Sum IV - Input is a BST/README_EN.md index 8420b5bb76a46..5f6d06b123768 100644 --- a/solution/0600-0699/0653.Two Sum IV - Input is a BST/README_EN.md +++ b/solution/0600-0699/0653.Two Sum IV - Input is a BST/README_EN.md @@ -59,6 +59,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -80,6 +82,8 @@ class Solution: return dfs(root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -176,6 +184,8 @@ func findTarget(root *TreeNode, k int) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -207,6 +217,8 @@ function findTarget(root: TreeNode | null, k: number): boolean { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -260,6 +272,8 @@ impl Solution { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -284,6 +298,8 @@ class Solution: return False ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -325,6 +341,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -363,6 +381,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -395,6 +415,8 @@ func findTarget(root *TreeNode, k int) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0600-0699/0654.Maximum Binary Tree/README.md b/solution/0600-0699/0654.Maximum Binary Tree/README.md index a681f938e1e26..85db495986032 100644 --- a/solution/0600-0699/0654.Maximum Binary Tree/README.md +++ b/solution/0600-0699/0654.Maximum Binary Tree/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -103,6 +105,8 @@ class Solution: return dfs(nums) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -179,6 +185,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -209,6 +217,8 @@ func constructMaximumBinaryTree(nums []int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -238,6 +248,8 @@ function constructMaximumBinaryTree(nums: number[]): TreeNode | null { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -289,6 +301,8 @@ impl Solution { } ``` +#### C + ```c /** * Definition for a binary tree node. @@ -337,6 +351,8 @@ struct TreeNode* constructMaximumBinaryTree(int* nums, int numsSize) { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -399,6 +415,8 @@ class SegmentTree: self.tr[u].v = max(self.tr[u << 1].v, self.tr[u << 1 | 1].v) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -496,6 +514,8 @@ class SegmentTree { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -581,6 +601,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -687,6 +709,8 @@ func (t *segmentTree) pushup(u int) { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -709,6 +733,8 @@ class Solution: return stk[0] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -745,6 +771,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -782,6 +810,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0600-0699/0654.Maximum Binary Tree/README_EN.md b/solution/0600-0699/0654.Maximum Binary Tree/README_EN.md index 2f6faab6cf3c2..30734631efa03 100644 --- a/solution/0600-0699/0654.Maximum Binary Tree/README_EN.md +++ b/solution/0600-0699/0654.Maximum Binary Tree/README_EN.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -97,6 +99,8 @@ class Solution: return dfs(nums) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -203,6 +211,8 @@ func constructMaximumBinaryTree(nums []int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -232,6 +242,8 @@ function constructMaximumBinaryTree(nums: number[]): TreeNode | null { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -283,6 +295,8 @@ impl Solution { } ``` +#### C + ```c /** * Definition for a binary tree node. @@ -327,6 +341,8 @@ struct TreeNode* constructMaximumBinaryTree(int* nums, int numsSize) { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -389,6 +405,8 @@ class SegmentTree: self.tr[u].v = max(self.tr[u << 1].v, self.tr[u << 1 | 1].v) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -486,6 +504,8 @@ class SegmentTree { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -571,6 +591,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -665,6 +687,8 @@ func (t *segmentTree) pushup(u int) { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -687,6 +711,8 @@ class Solution: return stk[0] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -723,6 +749,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -760,6 +788,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0600-0699/0655.Print Binary Tree/README.md b/solution/0600-0699/0655.Print Binary Tree/README.md index 48e090623cffd..a0d3651fe1095 100644 --- a/solution/0600-0699/0655.Print Binary Tree/README.md +++ b/solution/0600-0699/0655.Print Binary Tree/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -109,6 +111,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -159,6 +163,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -195,6 +201,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -236,6 +244,8 @@ func printTree(root *TreeNode) [][]string { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -277,6 +287,8 @@ function printTree(root: TreeNode | null): string[][] { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -350,6 +362,8 @@ impl Solution { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -386,6 +400,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -464,6 +480,8 @@ class Tuple { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -513,6 +531,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0600-0699/0655.Print Binary Tree/README_EN.md b/solution/0600-0699/0655.Print Binary Tree/README_EN.md index fbbdd79d3922e..22b67b58120fc 100644 --- a/solution/0600-0699/0655.Print Binary Tree/README_EN.md +++ b/solution/0600-0699/0655.Print Binary Tree/README_EN.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -185,6 +191,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -226,6 +234,8 @@ func printTree(root *TreeNode) [][]string { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -267,6 +277,8 @@ function printTree(root: TreeNode | null): string[][] { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -334,6 +346,8 @@ impl Solution { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -370,6 +384,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -448,6 +464,8 @@ class Tuple { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -497,6 +515,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0600-0699/0656.Coin Path/README.md b/solution/0600-0699/0656.Coin Path/README.md index 096e1b57e0e40..9727f5ec753b3 100644 --- a/solution/0600-0699/0656.Coin Path/README.md +++ b/solution/0600-0699/0656.Coin Path/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def cheapestJump(self, coins: List[int], maxJump: int) -> List[int]: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List cheapestJump(int[] coins, int maxJump) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func cheapestJump(coins []int, maxJump int) (ans []int) { n := len(coins) @@ -197,6 +205,8 @@ func cheapestJump(coins []int, maxJump int) (ans []int) { } ``` +#### TypeScript + ```ts function cheapestJump(coins: number[], maxJump: number): number[] { const n = coins.length; diff --git a/solution/0600-0699/0656.Coin Path/README_EN.md b/solution/0600-0699/0656.Coin Path/README_EN.md index 01b3b0cd3aff7..450a63fc9f35a 100644 --- a/solution/0600-0699/0656.Coin Path/README_EN.md +++ b/solution/0600-0699/0656.Coin Path/README_EN.md @@ -53,6 +53,8 @@ tags: +#### Python3 + ```python class Solution: def cheapestJump(self, coins: List[int], maxJump: int) -> List[int]: @@ -77,6 +79,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List cheapestJump(int[] coins, int maxJump) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func cheapestJump(coins []int, maxJump int) (ans []int) { n := len(coins) @@ -178,6 +186,8 @@ func cheapestJump(coins []int, maxJump int) (ans []int) { } ``` +#### TypeScript + ```ts function cheapestJump(coins: number[], maxJump: number): number[] { const n = coins.length; diff --git a/solution/0600-0699/0657.Robot Return to Origin/README.md b/solution/0600-0699/0657.Robot Return to Origin/README.md index c6926250ae2d8..448f42a1a382b 100644 --- a/solution/0600-0699/0657.Robot Return to Origin/README.md +++ b/solution/0600-0699/0657.Robot Return to Origin/README.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def judgeCircle(self, moves: str) -> bool: @@ -76,6 +78,8 @@ class Solution: return x == 0 and y == 0 ``` +#### Java + ```java class Solution { public boolean judgeCircle(String moves) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### TypeScript + ```ts function judgeCircle(moves: string): boolean { let x = 0, diff --git a/solution/0600-0699/0657.Robot Return to Origin/README_EN.md b/solution/0600-0699/0657.Robot Return to Origin/README_EN.md index be865351669b2..64ea40b8c8cb6 100644 --- a/solution/0600-0699/0657.Robot Return to Origin/README_EN.md +++ b/solution/0600-0699/0657.Robot Return to Origin/README_EN.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def judgeCircle(self, moves: str) -> bool: @@ -76,6 +78,8 @@ class Solution: return x == 0 and y == 0 ``` +#### Java + ```java class Solution { public boolean judgeCircle(String moves) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### TypeScript + ```ts function judgeCircle(moves: string): boolean { let x = 0, diff --git a/solution/0600-0699/0658.Find K Closest Elements/README.md b/solution/0600-0699/0658.Find K Closest Elements/README.md index c2fc088557ca2..f46a0e55dec25 100644 --- a/solution/0600-0699/0658.Find K Closest Elements/README.md +++ b/solution/0600-0699/0658.Find K Closest Elements/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def findClosestElements(self, arr: List[int], k: int, x: int) -> List[int]: @@ -78,6 +80,8 @@ class Solution: return sorted(arr[:k]) ``` +#### Java + ```java class Solution { public List findClosestElements(int[] arr, int k, int x) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp int target; @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func findClosestElements(arr []int, k int, x int) []int { sort.Slice(arr, func(i, j int) bool { @@ -137,6 +145,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function findClosestElements(arr: number[], k: number, x: number): number[] { let l = 0; @@ -152,6 +162,8 @@ function findClosestElements(arr: number[], k: number, x: number): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn find_closest_elements(arr: Vec, k: i32, x: i32) -> Vec { @@ -186,6 +198,8 @@ impl Solution { +#### Python3 + ```python class Solution: def findClosestElements(self, arr: List[int], k: int, x: int) -> List[int]: @@ -198,6 +212,8 @@ class Solution: return arr[l:r] ``` +#### Java + ```java class Solution { public List findClosestElements(int[] arr, int k, int x) { @@ -218,6 +234,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -235,6 +253,8 @@ public: }; ``` +#### Go + ```go func findClosestElements(arr []int, k int, x int) []int { l, r := 0, len(arr) @@ -249,6 +269,8 @@ func findClosestElements(arr []int, k int, x int) []int { } ``` +#### TypeScript + ```ts function findClosestElements(arr: number[], k: number, x: number): number[] { let left = 0; @@ -265,6 +287,8 @@ function findClosestElements(arr: number[], k: number, x: number): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn find_closest_elements(arr: Vec, k: i32, x: i32) -> Vec { @@ -299,6 +323,8 @@ impl Solution { +#### Python3 + ```python class Solution: def findClosestElements(self, arr: List[int], k: int, x: int) -> List[int]: @@ -312,6 +338,8 @@ class Solution: return arr[left : left + k] ``` +#### Java + ```java class Solution { public List findClosestElements(int[] arr, int k, int x) { @@ -334,6 +362,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -351,6 +381,8 @@ public: }; ``` +#### Go + ```go func findClosestElements(arr []int, k int, x int) []int { left, right := 0, len(arr)-k diff --git a/solution/0600-0699/0658.Find K Closest Elements/README_EN.md b/solution/0600-0699/0658.Find K Closest Elements/README_EN.md index 2906f417c8f1a..c13f2d13fe326 100644 --- a/solution/0600-0699/0658.Find K Closest Elements/README_EN.md +++ b/solution/0600-0699/0658.Find K Closest Elements/README_EN.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python class Solution: def findClosestElements(self, arr: List[int], k: int, x: int) -> List[int]: @@ -65,6 +67,8 @@ class Solution: return sorted(arr[:k]) ``` +#### Java + ```java class Solution { public List findClosestElements(int[] arr, int k, int x) { @@ -82,6 +86,8 @@ class Solution { } ``` +#### C++ + ```cpp int target; @@ -102,6 +108,8 @@ public: }; ``` +#### Go + ```go func findClosestElements(arr []int, k int, x int) []int { sort.Slice(arr, func(i, j int) bool { @@ -124,6 +132,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function findClosestElements(arr: number[], k: number, x: number): number[] { let l = 0; @@ -139,6 +149,8 @@ function findClosestElements(arr: number[], k: number, x: number): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn find_closest_elements(arr: Vec, k: i32, x: i32) -> Vec { @@ -167,6 +179,8 @@ impl Solution { +#### Python3 + ```python class Solution: def findClosestElements(self, arr: List[int], k: int, x: int) -> List[int]: @@ -179,6 +193,8 @@ class Solution: return arr[l:r] ``` +#### Java + ```java class Solution { public List findClosestElements(int[] arr, int k, int x) { @@ -199,6 +215,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -216,6 +234,8 @@ public: }; ``` +#### Go + ```go func findClosestElements(arr []int, k int, x int) []int { l, r := 0, len(arr) @@ -230,6 +250,8 @@ func findClosestElements(arr []int, k int, x int) []int { } ``` +#### TypeScript + ```ts function findClosestElements(arr: number[], k: number, x: number): number[] { let left = 0; @@ -246,6 +268,8 @@ function findClosestElements(arr: number[], k: number, x: number): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn find_closest_elements(arr: Vec, k: i32, x: i32) -> Vec { @@ -276,6 +300,8 @@ impl Solution { +#### Python3 + ```python class Solution: def findClosestElements(self, arr: List[int], k: int, x: int) -> List[int]: @@ -289,6 +315,8 @@ class Solution: return arr[left : left + k] ``` +#### Java + ```java class Solution { public List findClosestElements(int[] arr, int k, int x) { @@ -311,6 +339,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -328,6 +358,8 @@ public: }; ``` +#### Go + ```go func findClosestElements(arr []int, k int, x int) []int { left, right := 0, len(arr)-k diff --git a/solution/0600-0699/0659.Split Array into Consecutive Subsequences/README.md b/solution/0600-0699/0659.Split Array into Consecutive Subsequences/README.md index a7037e74ede7c..677e4c30c514c 100644 --- a/solution/0600-0699/0659.Split Array into Consecutive Subsequences/README.md +++ b/solution/0600-0699/0659.Split Array into Consecutive Subsequences/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class Solution: def isPossible(self, nums: List[int]) -> bool: @@ -106,6 +108,8 @@ class Solution: return all(not v or v and v[0] > 2 for v in d.values()) ``` +#### Java + ```java class Solution { public boolean isPossible(int[] nums) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func isPossible(nums []int) bool { d := map[int]*hp{} diff --git a/solution/0600-0699/0659.Split Array into Consecutive Subsequences/README_EN.md b/solution/0600-0699/0659.Split Array into Consecutive Subsequences/README_EN.md index af4d118ef31b7..a64ea888e7c97 100644 --- a/solution/0600-0699/0659.Split Array into Consecutive Subsequences/README_EN.md +++ b/solution/0600-0699/0659.Split Array into Consecutive Subsequences/README_EN.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def isPossible(self, nums: List[int]) -> bool: @@ -92,6 +94,8 @@ class Solution: return all(not v or v and v[0] > 2 for v in d.values()) ``` +#### Java + ```java class Solution { public boolean isPossible(int[] nums) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func isPossible(nums []int) bool { d := map[int]*hp{} diff --git a/solution/0600-0699/0660.Remove 9/README.md b/solution/0600-0699/0660.Remove 9/README.md index 4f30c95547f7c..a5487e0efde99 100644 --- a/solution/0600-0699/0660.Remove 9/README.md +++ b/solution/0600-0699/0660.Remove 9/README.md @@ -56,18 +56,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/0600-0699/0660.Remove 9/README_EN.md b/solution/0600-0699/0660.Remove 9/README_EN.md index 42a5e6ccdb7ac..4a6416af1520d 100644 --- a/solution/0600-0699/0660.Remove 9/README_EN.md +++ b/solution/0600-0699/0660.Remove 9/README_EN.md @@ -54,18 +54,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/0600-0699/0661.Image Smoother/README.md b/solution/0600-0699/0661.Image Smoother/README.md index c2f000dc95680..68355b904f910 100644 --- a/solution/0600-0699/0661.Image Smoother/README.md +++ b/solution/0600-0699/0661.Image Smoother/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def imageSmoother(self, img: List[List[int]]) -> List[List[int]]: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] imageSmoother(int[][] img) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func imageSmoother(img [][]int) [][]int { m, n := len(img), len(img[0]) @@ -164,6 +172,8 @@ func imageSmoother(img [][]int) [][]int { } ``` +#### TypeScript + ```ts function imageSmoother(img: number[][]): number[][] { const m = img.length; @@ -199,6 +209,8 @@ function imageSmoother(img: number[][]): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn image_smoother(img: Vec>) -> Vec> { diff --git a/solution/0600-0699/0661.Image Smoother/README_EN.md b/solution/0600-0699/0661.Image Smoother/README_EN.md index 129a3380ca88a..d1d41ca38a53f 100644 --- a/solution/0600-0699/0661.Image Smoother/README_EN.md +++ b/solution/0600-0699/0661.Image Smoother/README_EN.md @@ -64,6 +64,8 @@ For the point (1,1): floor((50+200+200+200+200+100+100+100+100)/9) = floor(138.8 +#### Python3 + ```python class Solution: def imageSmoother(self, img: List[List[int]]) -> List[List[int]]: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] imageSmoother(int[][] img) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func imageSmoother(img [][]int) [][]int { m, n := len(img), len(img[0]) @@ -154,6 +162,8 @@ func imageSmoother(img [][]int) [][]int { } ``` +#### TypeScript + ```ts function imageSmoother(img: number[][]): number[][] { const m = img.length; @@ -189,6 +199,8 @@ function imageSmoother(img: number[][]): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn image_smoother(img: Vec>) -> Vec> { diff --git a/solution/0600-0699/0662.Maximum Width of Binary Tree/README.md b/solution/0600-0699/0662.Maximum Width of Binary Tree/README.md index 4ec444391541f..f88427fd70e42 100644 --- a/solution/0600-0699/0662.Maximum Width of Binary Tree/README.md +++ b/solution/0600-0699/0662.Maximum Width of Binary Tree/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -230,6 +238,8 @@ type pair struct { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -256,6 +266,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -296,6 +308,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -332,6 +346,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0600-0699/0662.Maximum Width of Binary Tree/README_EN.md b/solution/0600-0699/0662.Maximum Width of Binary Tree/README_EN.md index c77a57892d423..d2794cdd2c906 100644 --- a/solution/0600-0699/0662.Maximum Width of Binary Tree/README_EN.md +++ b/solution/0600-0699/0662.Maximum Width of Binary Tree/README_EN.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -212,6 +220,8 @@ type pair struct { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -238,6 +248,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -278,6 +290,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -314,6 +328,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0600-0699/0663.Equal Tree Partition/README.md b/solution/0600-0699/0663.Equal Tree Partition/README.md index 93ad8442b430b..258401316e6ca 100644 --- a/solution/0600-0699/0663.Equal Tree Partition/README.md +++ b/solution/0600-0699/0663.Equal Tree Partition/README.md @@ -56,6 +56,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -80,6 +82,8 @@ class Solution: return s // 2 in seen ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0600-0699/0663.Equal Tree Partition/README_EN.md b/solution/0600-0699/0663.Equal Tree Partition/README_EN.md index a5524a3177d06..3be03677efe36 100644 --- a/solution/0600-0699/0663.Equal Tree Partition/README_EN.md +++ b/solution/0600-0699/0663.Equal Tree Partition/README_EN.md @@ -54,6 +54,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -78,6 +80,8 @@ class Solution: return s // 2 in seen ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0600-0699/0664.Strange Printer/README.md b/solution/0600-0699/0664.Strange Printer/README.md index ea4defd7a526b..fdbc2fa97358f 100644 --- a/solution/0600-0699/0664.Strange Printer/README.md +++ b/solution/0600-0699/0664.Strange Printer/README.md @@ -79,6 +79,8 @@ $$ +#### Python3 + ```python class Solution: def strangePrinter(self, s: str) -> int: @@ -95,6 +97,8 @@ class Solution: return f[0][-1] ``` +#### Java + ```java class Solution { public int strangePrinter(String s) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func strangePrinter(s string) int { n := len(s) @@ -171,6 +179,8 @@ func strangePrinter(s string) int { } ``` +#### TypeScript + ```ts function strangePrinter(s: string): number { const n = s.length; diff --git a/solution/0600-0699/0664.Strange Printer/README_EN.md b/solution/0600-0699/0664.Strange Printer/README_EN.md index 3a61b11ffcf89..fa77002259dd1 100644 --- a/solution/0600-0699/0664.Strange Printer/README_EN.md +++ b/solution/0600-0699/0664.Strange Printer/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n^3)$ and the space complexity is $O(n^2)$. Where $n$ +#### Python3 + ```python class Solution: def strangePrinter(self, s: str) -> int: @@ -94,6 +96,8 @@ class Solution: return f[0][-1] ``` +#### Java + ```java class Solution { public int strangePrinter(String s) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func strangePrinter(s string) int { n := len(s) @@ -170,6 +178,8 @@ func strangePrinter(s string) int { } ``` +#### TypeScript + ```ts function strangePrinter(s: string): number { const n = s.length; diff --git a/solution/0600-0699/0665.Non-decreasing Array/README.md b/solution/0600-0699/0665.Non-decreasing Array/README.md index 714168d1f6b73..4d480314c4040 100644 --- a/solution/0600-0699/0665.Non-decreasing Array/README.md +++ b/solution/0600-0699/0665.Non-decreasing Array/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def checkPossibility(self, nums: List[int]) -> bool: @@ -85,6 +87,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean checkPossibility(int[] nums) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func checkPossibility(nums []int) bool { isSorted := func(nums []int) bool { @@ -162,6 +170,8 @@ func checkPossibility(nums []int) bool { } ``` +#### TypeScript + ```ts function checkPossibility(nums: number[]): boolean { const isSorted = (nums: number[]) => { diff --git a/solution/0600-0699/0665.Non-decreasing Array/README_EN.md b/solution/0600-0699/0665.Non-decreasing Array/README_EN.md index 2ff46a19141bb..5650f43839548 100644 --- a/solution/0600-0699/0665.Non-decreasing Array/README_EN.md +++ b/solution/0600-0699/0665.Non-decreasing Array/README_EN.md @@ -56,6 +56,8 @@ tags: +#### Python3 + ```python class Solution: def checkPossibility(self, nums: List[int]) -> bool: @@ -74,6 +76,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean checkPossibility(int[] nums) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func checkPossibility(nums []int) bool { isSorted := func(nums []int) bool { @@ -151,6 +159,8 @@ func checkPossibility(nums []int) bool { } ``` +#### TypeScript + ```ts function checkPossibility(nums: number[]): boolean { const isSorted = (nums: number[]) => { diff --git a/solution/0600-0699/0666.Path Sum IV/README.md b/solution/0600-0699/0666.Path Sum IV/README.md index 1f56a2e2a9af4..8ab55a4749184 100644 --- a/solution/0600-0699/0666.Path Sum IV/README.md +++ b/solution/0600-0699/0666.Path Sum IV/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def pathSum(self, nums: List[int]) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int ans; @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func pathSum(nums []int) int { ans := 0 diff --git a/solution/0600-0699/0666.Path Sum IV/README_EN.md b/solution/0600-0699/0666.Path Sum IV/README_EN.md index dbe024a7f67ea..a4596f1ebefdb 100644 --- a/solution/0600-0699/0666.Path Sum IV/README_EN.md +++ b/solution/0600-0699/0666.Path Sum IV/README_EN.md @@ -70,6 +70,8 @@ The path sum is (3 + 1) = 4. +#### Python3 + ```python class Solution: def pathSum(self, nums: List[int]) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int ans; @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func pathSum(nums []int) int { ans := 0 diff --git a/solution/0600-0699/0667.Beautiful Arrangement II/README.md b/solution/0600-0699/0667.Beautiful Arrangement II/README.md index ad5400fcfc264..d3cd6b14f39e7 100644 --- a/solution/0600-0699/0667.Beautiful Arrangement II/README.md +++ b/solution/0600-0699/0667.Beautiful Arrangement II/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def constructArray(self, n: int, k: int) -> List[int]: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] constructArray(int n, int k) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func constructArray(n int, k int) []int { l, r := 1, n @@ -148,6 +156,8 @@ func constructArray(n int, k int) []int { } ``` +#### TypeScript + ```ts function constructArray(n: number, k: number): number[] { let l = 1; diff --git a/solution/0600-0699/0667.Beautiful Arrangement II/README_EN.md b/solution/0600-0699/0667.Beautiful Arrangement II/README_EN.md index 121e26b7bd5f3..52bb2555758f1 100644 --- a/solution/0600-0699/0667.Beautiful Arrangement II/README_EN.md +++ b/solution/0600-0699/0667.Beautiful Arrangement II/README_EN.md @@ -59,6 +59,8 @@ Explanation: The [1,3,2] has three different positive integers ranging from 1 to +#### Python3 + ```python class Solution: def constructArray(self, n: int, k: int) -> List[int]: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] constructArray(int n, int k) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func constructArray(n int, k int) []int { l, r := 1, n @@ -140,6 +148,8 @@ func constructArray(n int, k int) []int { } ``` +#### TypeScript + ```ts function constructArray(n: number, k: number): number[] { let l = 1; diff --git a/solution/0600-0699/0668.Kth Smallest Number in Multiplication Table/README.md b/solution/0600-0699/0668.Kth Smallest Number in Multiplication Table/README.md index 0c53909057c09..c6d8968092171 100644 --- a/solution/0600-0699/0668.Kth Smallest Number in Multiplication Table/README.md +++ b/solution/0600-0699/0668.Kth Smallest Number in Multiplication Table/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def findKthNumber(self, m: int, n: int, k: int) -> int: @@ -84,6 +86,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int findKthNumber(int m, int n, int k) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func findKthNumber(m int, n int, k int) int { left, right := 1, m*n diff --git a/solution/0600-0699/0668.Kth Smallest Number in Multiplication Table/README_EN.md b/solution/0600-0699/0668.Kth Smallest Number in Multiplication Table/README_EN.md index f0196990c83cb..651c18e5766ba 100644 --- a/solution/0600-0699/0668.Kth Smallest Number in Multiplication Table/README_EN.md +++ b/solution/0600-0699/0668.Kth Smallest Number in Multiplication Table/README_EN.md @@ -56,6 +56,8 @@ tags: +#### Python3 + ```python class Solution: def findKthNumber(self, m: int, n: int, k: int) -> int: @@ -72,6 +74,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int findKthNumber(int m, int n, int k) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func findKthNumber(m int, n int, k int) int { left, right := 1, m*n diff --git a/solution/0600-0699/0669.Trim a Binary Search Tree/README.md b/solution/0600-0699/0669.Trim a Binary Search Tree/README.md index c9e5998c3f404..18d33162cff80 100644 --- a/solution/0600-0699/0669.Trim a Binary Search Tree/README.md +++ b/solution/0600-0699/0669.Trim a Binary Search Tree/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -96,6 +98,8 @@ class Solution: return dfs(root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -180,6 +188,8 @@ func trimBST(root *TreeNode, low int, high int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -212,6 +222,8 @@ function trimBST(root: TreeNode | null, low: number, high: number): TreeNode | n } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -258,6 +270,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -292,6 +306,8 @@ var trimBST = function (root, low, high) { }; ``` +#### C + ```c /** * Definition for a binary tree node. @@ -342,6 +358,8 @@ struct TreeNode* trimBST(struct TreeNode* root, int low, int high) { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -372,6 +390,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -417,6 +437,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -459,6 +481,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -499,6 +523,8 @@ func trimBST(root *TreeNode, low int, high int) *TreeNode { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0600-0699/0669.Trim a Binary Search Tree/README_EN.md b/solution/0600-0699/0669.Trim a Binary Search Tree/README_EN.md index 8b23d4c567125..701fbc6c38941 100644 --- a/solution/0600-0699/0669.Trim a Binary Search Tree/README_EN.md +++ b/solution/0600-0699/0669.Trim a Binary Search Tree/README_EN.md @@ -59,6 +59,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -84,6 +86,8 @@ class Solution: return dfs(root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -168,6 +176,8 @@ func trimBST(root *TreeNode, low int, high int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -200,6 +210,8 @@ function trimBST(root: TreeNode | null, low: number, high: number): TreeNode | n } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -246,6 +258,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -280,6 +294,8 @@ var trimBST = function (root, low, high) { }; ``` +#### C + ```c /** * Definition for a binary tree node. @@ -316,6 +332,8 @@ struct TreeNode* trimBST(struct TreeNode* root, int low, int high) { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -346,6 +364,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -391,6 +411,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -433,6 +455,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -473,6 +497,8 @@ func trimBST(root *TreeNode, low int, high int) *TreeNode { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0600-0699/0670.Maximum Swap/README.md b/solution/0600-0699/0670.Maximum Swap/README.md index fb04e88fe3740..bdd3bdd7d42a4 100644 --- a/solution/0600-0699/0670.Maximum Swap/README.md +++ b/solution/0600-0699/0670.Maximum Swap/README.md @@ -59,6 +59,8 @@ tags: +#### Python3 + ```python class Solution: def maximumSwap(self, num: int) -> int: @@ -75,6 +77,8 @@ class Solution: return int(''.join(s)) ``` +#### Java + ```java class Solution { public int maximumSwap(int num) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func maximumSwap(num int) int { s := []byte(strconv.Itoa(num)) @@ -152,6 +160,8 @@ func maximumSwap(num int) int { } ``` +#### TypeScript + ```ts function maximumSwap(num: number): number { const list = new Array(); @@ -181,6 +191,8 @@ function maximumSwap(num: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn maximum_swap(mut num: i32) -> i32 { diff --git a/solution/0600-0699/0670.Maximum Swap/README_EN.md b/solution/0600-0699/0670.Maximum Swap/README_EN.md index 9e353d09a7855..8f722d5214098 100644 --- a/solution/0600-0699/0670.Maximum Swap/README_EN.md +++ b/solution/0600-0699/0670.Maximum Swap/README_EN.md @@ -63,6 +63,8 @@ The time complexity is $O(\log M)$, and the space complexity is $O(\log M)$. Her +#### Python3 + ```python class Solution: def maximumSwap(self, num: int) -> int: @@ -79,6 +81,8 @@ class Solution: return int(''.join(s)) ``` +#### Java + ```java class Solution { public int maximumSwap(int num) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func maximumSwap(num int) int { s := []byte(strconv.Itoa(num)) @@ -156,6 +164,8 @@ func maximumSwap(num int) int { } ``` +#### TypeScript + ```ts function maximumSwap(num: number): number { const list = new Array(); @@ -185,6 +195,8 @@ function maximumSwap(num: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn maximum_swap(mut num: i32) -> i32 { diff --git a/solution/0600-0699/0671.Second Minimum Node In a Binary Tree/README.md b/solution/0600-0699/0671.Second Minimum Node In a Binary Tree/README.md index 0a17077c6effb..c1d699876b3a8 100644 --- a/solution/0600-0699/0671.Second Minimum Node In a Binary Tree/README.md +++ b/solution/0600-0699/0671.Second Minimum Node In a Binary Tree/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -185,6 +193,8 @@ func findSecondMinimumValue(root *TreeNode) int { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0600-0699/0671.Second Minimum Node In a Binary Tree/README_EN.md b/solution/0600-0699/0671.Second Minimum Node In a Binary Tree/README_EN.md index 3b5b9b8f2f81b..5d309f5e9c4e4 100644 --- a/solution/0600-0699/0671.Second Minimum Node In a Binary Tree/README_EN.md +++ b/solution/0600-0699/0671.Second Minimum Node In a Binary Tree/README_EN.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -179,6 +187,8 @@ func findSecondMinimumValue(root *TreeNode) int { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0600-0699/0672.Bulb Switcher II/README.md b/solution/0600-0699/0672.Bulb Switcher II/README.md index b33fb5856c4c9..40f91fcf6aefb 100644 --- a/solution/0600-0699/0672.Bulb Switcher II/README.md +++ b/solution/0600-0699/0672.Bulb Switcher II/README.md @@ -98,6 +98,8 @@ tags: +#### Python3 + ```python class Solution: def flipLights(self, n: int, presses: int) -> int: @@ -117,6 +119,8 @@ class Solution: return len(vis) ``` +#### Java + ```java class Solution { public int flipLights(int n, int presses) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func flipLights(n int, presses int) int { if n > 6 { diff --git a/solution/0600-0699/0672.Bulb Switcher II/README_EN.md b/solution/0600-0699/0672.Bulb Switcher II/README_EN.md index 470def5962bd8..4f59bbde6c299 100644 --- a/solution/0600-0699/0672.Bulb Switcher II/README_EN.md +++ b/solution/0600-0699/0672.Bulb Switcher II/README_EN.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def flipLights(self, n: int, presses: int) -> int: @@ -103,6 +105,8 @@ class Solution: return len(vis) ``` +#### Java + ```java class Solution { public int flipLights(int n, int presses) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func flipLights(n int, presses int) int { if n > 6 { diff --git a/solution/0600-0699/0673.Number of Longest Increasing Subsequence/README.md b/solution/0600-0699/0673.Number of Longest Increasing Subsequence/README.md index 9f0799d8a1804..edf25909c0d58 100644 --- a/solution/0600-0699/0673.Number of Longest Increasing Subsequence/README.md +++ b/solution/0600-0699/0673.Number of Longest Increasing Subsequence/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def findNumberOfLIS(self, nums: List[int]) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findNumberOfLIS(int[] nums) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func findNumberOfLIS(nums []int) (ans int) { n, mx := len(nums), 0 @@ -183,6 +191,8 @@ func findNumberOfLIS(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function findNumberOfLIS(nums: number[]): number { const n = nums.length; @@ -211,6 +221,8 @@ function findNumberOfLIS(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_number_of_lis(nums: Vec) -> i32 { @@ -256,6 +268,8 @@ impl Solution { +#### Python3 + ```python class BinaryIndexedTree: __slots__ = ["n", "c", "d"] @@ -298,6 +312,8 @@ class Solution: return tree.query(m)[1] ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -356,6 +372,8 @@ public class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { private: @@ -415,6 +433,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -472,6 +492,8 @@ func findNumberOfLIS(nums []int) int { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; @@ -538,6 +560,8 @@ function findNumberOfLIS(nums: number[]): number { } ``` +#### Rust + ```rust struct BinaryIndexedTree { n: usize, diff --git a/solution/0600-0699/0673.Number of Longest Increasing Subsequence/README_EN.md b/solution/0600-0699/0673.Number of Longest Increasing Subsequence/README_EN.md index 4394d4e54f87e..4ed3e06931683 100644 --- a/solution/0600-0699/0673.Number of Longest Increasing Subsequence/README_EN.md +++ b/solution/0600-0699/0673.Number of Longest Increasing Subsequence/README_EN.md @@ -66,6 +66,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$. Here, $n$ i +#### Python3 + ```python class Solution: def findNumberOfLIS(self, nums: List[int]) -> int: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findNumberOfLIS(int[] nums) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func findNumberOfLIS(nums []int) (ans int) { n, mx := len(nums), 0 @@ -179,6 +187,8 @@ func findNumberOfLIS(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function findNumberOfLIS(nums: number[]): number { const n = nums.length; @@ -207,6 +217,8 @@ function findNumberOfLIS(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_number_of_lis(nums: Vec) -> i32 { @@ -252,6 +264,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class BinaryIndexedTree: __slots__ = ["n", "c", "d"] @@ -294,6 +308,8 @@ class Solution: return tree.query(m)[1] ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -352,6 +368,8 @@ public class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { private: @@ -411,6 +429,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -468,6 +488,8 @@ func findNumberOfLIS(nums []int) int { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; @@ -534,6 +556,8 @@ function findNumberOfLIS(nums: number[]): number { } ``` +#### Rust + ```rust struct BinaryIndexedTree { n: usize, diff --git a/solution/0600-0699/0674.Longest Continuous Increasing Subsequence/README.md b/solution/0600-0699/0674.Longest Continuous Increasing Subsequence/README.md index 3d8b9bf7c6c6a..76fca6f2acfc5 100644 --- a/solution/0600-0699/0674.Longest Continuous Increasing Subsequence/README.md +++ b/solution/0600-0699/0674.Longest Continuous Increasing Subsequence/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def findLengthOfLCIS(self, nums: List[int]) -> int: @@ -79,6 +81,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findLengthOfLCIS(int[] nums) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func findLengthOfLCIS(nums []int) int { ans, cnt := 1, 1 @@ -127,6 +135,8 @@ func findLengthOfLCIS(nums []int) int { } ``` +#### TypeScript + ```ts function findLengthOfLCIS(nums: number[]): number { let [ans, cnt] = [1, 1]; @@ -141,6 +151,8 @@ function findLengthOfLCIS(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_length_of_lcis(nums: Vec) -> i32 { @@ -159,6 +171,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** @@ -194,6 +208,8 @@ class Solution { +#### Python3 + ```python class Solution: def findLengthOfLCIS(self, nums: List[int]) -> int: @@ -208,6 +224,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findLengthOfLCIS(int[] nums) { @@ -226,6 +244,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -245,6 +265,8 @@ public: }; ``` +#### Go + ```go func findLengthOfLCIS(nums []int) int { ans := 1 @@ -261,6 +283,8 @@ func findLengthOfLCIS(nums []int) int { } ``` +#### TypeScript + ```ts function findLengthOfLCIS(nums: number[]): number { let ans = 1; @@ -277,6 +301,8 @@ function findLengthOfLCIS(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_length_of_lcis(nums: Vec) -> i32 { @@ -296,6 +322,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0600-0699/0674.Longest Continuous Increasing Subsequence/README_EN.md b/solution/0600-0699/0674.Longest Continuous Increasing Subsequence/README_EN.md index 438cf9db0997e..e491cb9cc7ad1 100644 --- a/solution/0600-0699/0674.Longest Continuous Increasing Subsequence/README_EN.md +++ b/solution/0600-0699/0674.Longest Continuous Increasing Subsequence/README_EN.md @@ -66,6 +66,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def findLengthOfLCIS(self, nums: List[int]) -> int: @@ -79,6 +81,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findLengthOfLCIS(int[] nums) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func findLengthOfLCIS(nums []int) int { ans, cnt := 1, 1 @@ -127,6 +135,8 @@ func findLengthOfLCIS(nums []int) int { } ``` +#### TypeScript + ```ts function findLengthOfLCIS(nums: number[]): number { let [ans, cnt] = [1, 1]; @@ -141,6 +151,8 @@ function findLengthOfLCIS(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_length_of_lcis(nums: Vec) -> i32 { @@ -159,6 +171,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** @@ -194,6 +208,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def findLengthOfLCIS(self, nums: List[int]) -> int: @@ -208,6 +224,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findLengthOfLCIS(int[] nums) { @@ -226,6 +244,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -245,6 +265,8 @@ public: }; ``` +#### Go + ```go func findLengthOfLCIS(nums []int) int { ans := 1 @@ -261,6 +283,8 @@ func findLengthOfLCIS(nums []int) int { } ``` +#### TypeScript + ```ts function findLengthOfLCIS(nums: number[]): number { let ans = 1; @@ -277,6 +301,8 @@ function findLengthOfLCIS(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_length_of_lcis(nums: Vec) -> i32 { @@ -296,6 +322,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0600-0699/0675.Cut Off Trees for Golf Event/README.md b/solution/0600-0699/0675.Cut Off Trees for Golf Event/README.md index 964d99b6f387a..798fadfe8ec0c 100644 --- a/solution/0600-0699/0675.Cut Off Trees for Golf Event/README.md +++ b/solution/0600-0699/0675.Cut Off Trees for Golf Event/README.md @@ -94,6 +94,8 @@ A\* 算法主要思想如下: +#### Python3 + ```python class Solution: def cutOffTree(self, forest: List[List[int]]) -> int: @@ -132,6 +134,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] dist = new int[3600]; @@ -201,6 +205,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -259,6 +265,8 @@ public: }; ``` +#### Go + ```go var dirs = [][]int{{-1, 0}, {1, 0}, {0, -1}, {0, 1}} @@ -322,6 +330,8 @@ func cutOffTree(forest [][]int) int { } ``` +#### Rust + ```rust use std::collections::HashSet; use std::collections::VecDeque; diff --git a/solution/0600-0699/0675.Cut Off Trees for Golf Event/README_EN.md b/solution/0600-0699/0675.Cut Off Trees for Golf Event/README_EN.md index 38ec133acfb47..52c4f244b40a4 100644 --- a/solution/0600-0699/0675.Cut Off Trees for Golf Event/README_EN.md +++ b/solution/0600-0699/0675.Cut Off Trees for Golf Event/README_EN.md @@ -82,6 +82,8 @@ Note that you can cut off the first tree at (0, 0) before making any steps. +#### Python3 + ```python class Solution: def cutOffTree(self, forest: List[List[int]]) -> int: @@ -120,6 +122,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] dist = new int[3600]; @@ -189,6 +193,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -247,6 +253,8 @@ public: }; ``` +#### Go + ```go var dirs = [][]int{{-1, 0}, {1, 0}, {0, -1}, {0, 1}} @@ -310,6 +318,8 @@ func cutOffTree(forest [][]int) int { } ``` +#### Rust + ```rust use std::collections::HashSet; use std::collections::VecDeque; diff --git a/solution/0600-0699/0676.Implement Magic Dictionary/README.md b/solution/0600-0699/0676.Implement Magic Dictionary/README.md index e2f21e98c56ea..8abea45fcbd62 100644 --- a/solution/0600-0699/0676.Implement Magic Dictionary/README.md +++ b/solution/0600-0699/0676.Implement Magic Dictionary/README.md @@ -85,6 +85,8 @@ magicDictionary.search("leetcoded"); // 返回 False +#### Python3 + ```python class Trie: __slots__ = ["children", "is_end"] @@ -132,6 +134,8 @@ class MagicDictionary: # param_2 = obj.search(searchWord) ``` +#### Java + ```java class Trie { private Trie[] children = new Trie[26]; @@ -201,6 +205,8 @@ class MagicDictionary { */ ``` +#### C++ + ```cpp class Trie { private: @@ -276,6 +282,8 @@ private: */ ``` +#### Go + ```go type Trie struct { children [26]*Trie @@ -346,6 +354,8 @@ func (md *MagicDictionary) Search(searchWord string) bool { */ ``` +#### TypeScript + ```ts class Trie { private children: Trie[] = Array(26).fill(null); @@ -413,6 +423,8 @@ class MagicDictionary { */ ``` +#### Rust + ```rust use std::collections::HashMap; @@ -510,6 +522,8 @@ impl MagicDictionary { +#### Python3 + ```python class Trie: __slots__ = ["children", "is_end"] diff --git a/solution/0600-0699/0676.Implement Magic Dictionary/README_EN.md b/solution/0600-0699/0676.Implement Magic Dictionary/README_EN.md index cc5877890d555..46c9eed17813d 100644 --- a/solution/0600-0699/0676.Implement Magic Dictionary/README_EN.md +++ b/solution/0600-0699/0676.Implement Magic Dictionary/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n \times l + q \times l \times |\Sigma|)$, and the spa +#### Python3 + ```python class Trie: __slots__ = ["children", "is_end"] @@ -124,6 +126,8 @@ class MagicDictionary: # param_2 = obj.search(searchWord) ``` +#### Java + ```java class Trie { private Trie[] children = new Trie[26]; @@ -193,6 +197,8 @@ class MagicDictionary { */ ``` +#### C++ + ```cpp class Trie { private: @@ -268,6 +274,8 @@ private: */ ``` +#### Go + ```go type Trie struct { children [26]*Trie @@ -338,6 +346,8 @@ func (md *MagicDictionary) Search(searchWord string) bool { */ ``` +#### TypeScript + ```ts class Trie { private children: Trie[] = Array(26).fill(null); @@ -405,6 +415,8 @@ class MagicDictionary { */ ``` +#### Rust + ```rust use std::collections::HashMap; @@ -502,6 +514,8 @@ impl MagicDictionary { +#### Python3 + ```python class Trie: __slots__ = ["children", "is_end"] diff --git a/solution/0600-0699/0677.Map Sum Pairs/README.md b/solution/0600-0699/0677.Map Sum Pairs/README.md index 9f862eb475e61..3d87dc6955cc0 100644 --- a/solution/0600-0699/0677.Map Sum Pairs/README.md +++ b/solution/0600-0699/0677.Map Sum Pairs/README.md @@ -87,6 +87,8 @@ mapSum.sum("ap"); // 返回 5 (apple + app = 3 + 2 = 5) +#### Python3 + ```python class Trie: def __init__(self): @@ -132,6 +134,8 @@ class MapSum: # param_2 = obj.sum(prefix) ``` +#### Java + ```java class Trie { private Trie[] children = new Trie[26]; @@ -188,6 +192,8 @@ class MapSum { */ ``` +#### C++ + ```cpp class Trie { public: @@ -252,6 +258,8 @@ private: */ ``` +#### Go + ```go type trie struct { children [26]*trie @@ -307,6 +315,8 @@ func (this *MapSum) Sum(prefix string) int { */ ``` +#### TypeScript + ```ts class Trie { children: Trie[]; diff --git a/solution/0600-0699/0677.Map Sum Pairs/README_EN.md b/solution/0600-0699/0677.Map Sum Pairs/README_EN.md index 96d1d35a38228..6ca47cee79f59 100644 --- a/solution/0600-0699/0677.Map Sum Pairs/README_EN.md +++ b/solution/0600-0699/0677.Map Sum Pairs/README_EN.md @@ -72,6 +72,8 @@ mapSum.sum("ap"); // return 5 (apple + app = 3 +#### Python3 + ```python class Trie: def __init__(self): @@ -117,6 +119,8 @@ class MapSum: # param_2 = obj.sum(prefix) ``` +#### Java + ```java class Trie { private Trie[] children = new Trie[26]; @@ -173,6 +177,8 @@ class MapSum { */ ``` +#### C++ + ```cpp class Trie { public: @@ -237,6 +243,8 @@ private: */ ``` +#### Go + ```go type trie struct { children [26]*trie @@ -292,6 +300,8 @@ func (this *MapSum) Sum(prefix string) int { */ ``` +#### TypeScript + ```ts class Trie { children: Trie[]; diff --git a/solution/0600-0699/0678.Valid Parenthesis String/README.md b/solution/0600-0699/0678.Valid Parenthesis String/README.md index f05ab12bafdc1..22487c45f1176 100644 --- a/solution/0600-0699/0678.Valid Parenthesis String/README.md +++ b/solution/0600-0699/0678.Valid Parenthesis String/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def checkValidString(self, s: str) -> bool: @@ -102,6 +104,8 @@ class Solution: return dp[0][-1] ``` +#### Java + ```java class Solution { public boolean checkValidString(String s) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func checkValidString(s string) bool { n := len(s) @@ -187,6 +195,8 @@ func checkValidString(s string) bool { +#### Python3 + ```python class Solution: def checkValidString(self, s: str) -> bool: @@ -209,6 +219,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean checkValidString(String s) { @@ -238,6 +250,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -267,6 +281,8 @@ public: }; ``` +#### Go + ```go func checkValidString(s string) bool { x := 0 diff --git a/solution/0600-0699/0678.Valid Parenthesis String/README_EN.md b/solution/0600-0699/0678.Valid Parenthesis String/README_EN.md index 8f3a51ede880e..69173242f7d96 100644 --- a/solution/0600-0699/0678.Valid Parenthesis String/README_EN.md +++ b/solution/0600-0699/0678.Valid Parenthesis String/README_EN.md @@ -67,6 +67,8 @@ Let `dp[i][j]` be true if and only if the interval `s[i], s[i+1], ..., s[j]` can +#### Python3 + ```python class Solution: def checkValidString(self, s: str) -> bool: @@ -85,6 +87,8 @@ class Solution: return dp[0][-1] ``` +#### Java + ```java class Solution { public boolean checkValidString(String s) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func checkValidString(s string) bool { n := len(s) @@ -167,6 +175,8 @@ Scan twice, first from left to right to make sure that each of the closing brack +#### Python3 + ```python class Solution: def checkValidString(self, s: str) -> bool: @@ -189,6 +199,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean checkValidString(String s) { @@ -218,6 +230,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -247,6 +261,8 @@ public: }; ``` +#### Go + ```go func checkValidString(s string) bool { x := 0 diff --git a/solution/0600-0699/0679.24 Game/README.md b/solution/0600-0699/0679.24 Game/README.md index 407526e453069..35866f6441268 100644 --- a/solution/0600-0699/0679.24 Game/README.md +++ b/solution/0600-0699/0679.24 Game/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def judgePoint24(self, cards: List[int]) -> bool: @@ -123,6 +125,8 @@ class Solution: return dfs(nums) ``` +#### Java + ```java class Solution { private final char[] ops = {'+', '-', '*', '/'}; @@ -182,6 +186,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -243,6 +249,8 @@ private: }; ``` +#### Go + ```go func judgePoint24(cards []int) bool { ops := [4]rune{'+', '-', '*', '/'} @@ -296,6 +304,8 @@ func judgePoint24(cards []int) bool { } ``` +#### TypeScript + ```ts function judgePoint24(cards: number[]): boolean { const ops: string[] = ['+', '-', '*', '/']; diff --git a/solution/0600-0699/0679.24 Game/README_EN.md b/solution/0600-0699/0679.24 Game/README_EN.md index ee5d9cde8e8ec..ec8201e1b0381 100644 --- a/solution/0600-0699/0679.24 Game/README_EN.md +++ b/solution/0600-0699/0679.24 Game/README_EN.md @@ -86,6 +86,8 @@ If none of the enumerated cases return $true$, we return $false$. +#### Python3 + ```python class Solution: def judgePoint24(self, cards: List[int]) -> bool: @@ -121,6 +123,8 @@ class Solution: return dfs(nums) ``` +#### Java + ```java class Solution { private final char[] ops = {'+', '-', '*', '/'}; @@ -180,6 +184,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -241,6 +247,8 @@ private: }; ``` +#### Go + ```go func judgePoint24(cards []int) bool { ops := [4]rune{'+', '-', '*', '/'} @@ -294,6 +302,8 @@ func judgePoint24(cards []int) bool { } ``` +#### TypeScript + ```ts function judgePoint24(cards: number[]): boolean { const ops: string[] = ['+', '-', '*', '/']; diff --git a/solution/0600-0699/0680.Valid Palindrome II/README.md b/solution/0600-0699/0680.Valid Palindrome II/README.md index c4d9d77313c4e..b651d09244914 100644 --- a/solution/0600-0699/0680.Valid Palindrome II/README.md +++ b/solution/0600-0699/0680.Valid Palindrome II/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def validPalindrome(self, s: str) -> bool: @@ -88,6 +90,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean validPalindrome(String s) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func validPalindrome(s string) bool { check := func(i, j int) bool { @@ -152,6 +160,8 @@ func validPalindrome(s string) bool { } ``` +#### TypeScript + ```ts function validPalindrome(s: string): boolean { for (let i: number = 0, j = s.length - 1; i < j; ++i, --j) { @@ -172,6 +182,8 @@ function isPalinddrome(s: string): boolean { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -195,6 +207,8 @@ var validPalindrome = function (s) { }; ``` +#### C# + ```cs public class Solution { public bool ValidPalindrome(string s) { diff --git a/solution/0600-0699/0680.Valid Palindrome II/README_EN.md b/solution/0600-0699/0680.Valid Palindrome II/README_EN.md index b46a3e939122e..81e3c902dc8f9 100644 --- a/solution/0600-0699/0680.Valid Palindrome II/README_EN.md +++ b/solution/0600-0699/0680.Valid Palindrome II/README_EN.md @@ -67,6 +67,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string $s$. The sp +#### Python3 + ```python class Solution: def validPalindrome(self, s: str) -> bool: @@ -85,6 +87,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean validPalindrome(String s) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func validPalindrome(s string) bool { check := func(i, j int) bool { @@ -149,6 +157,8 @@ func validPalindrome(s string) bool { } ``` +#### TypeScript + ```ts function validPalindrome(s: string): boolean { for (let i: number = 0, j = s.length - 1; i < j; ++i, --j) { @@ -169,6 +179,8 @@ function isPalinddrome(s: string): boolean { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -192,6 +204,8 @@ var validPalindrome = function (s) { }; ``` +#### C# + ```cs public class Solution { public bool ValidPalindrome(string s) { diff --git a/solution/0600-0699/0681.Next Closest Time/README.md b/solution/0600-0699/0681.Next Closest Time/README.md index ae9eab56878a2..95150e87fbd26 100644 --- a/solution/0600-0699/0681.Next Closest Time/README.md +++ b/solution/0600-0699/0681.Next Closest Time/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def nextClosestTime(self, time: str) -> str: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int t; diff --git a/solution/0600-0699/0681.Next Closest Time/README_EN.md b/solution/0600-0699/0681.Next Closest Time/README_EN.md index 2cefe1bd9b2b2..d15a7beaddb8c 100644 --- a/solution/0600-0699/0681.Next Closest Time/README_EN.md +++ b/solution/0600-0699/0681.Next Closest Time/README_EN.md @@ -62,6 +62,8 @@ It may be assumed that the returned time is next day's time since it is smal +#### Python3 + ```python class Solution: def nextClosestTime(self, time: str) -> str: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int t; diff --git a/solution/0600-0699/0682.Baseball Game/README.md b/solution/0600-0699/0682.Baseball Game/README.md index ee2955eab7abe..307c7ac214555 100644 --- a/solution/0600-0699/0682.Baseball Game/README.md +++ b/solution/0600-0699/0682.Baseball Game/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def calPoints(self, ops: List[str]) -> int: @@ -108,6 +110,8 @@ class Solution: return sum(stk) ``` +#### Java + ```java class Solution { public int calPoints(String[] ops) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func calPoints(ops []string) int { var stk []int @@ -179,6 +187,8 @@ func calPoints(ops []string) int { } ``` +#### TypeScript + ```ts function calPoints(ops: string[]): number { const stack = []; @@ -198,6 +208,8 @@ function calPoints(ops: string[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn cal_points(ops: Vec) -> i32 { diff --git a/solution/0600-0699/0682.Baseball Game/README_EN.md b/solution/0600-0699/0682.Baseball Game/README_EN.md index f90039a4d9440..2f043c4daa95d 100644 --- a/solution/0600-0699/0682.Baseball Game/README_EN.md +++ b/solution/0600-0699/0682.Baseball Game/README_EN.md @@ -114,6 +114,8 @@ Since the record is empty, the total sum is 0. +#### Python3 + ```python class Solution: def calPoints(self, ops: List[str]) -> int: @@ -130,6 +132,8 @@ class Solution: return sum(stk) ``` +#### Java + ```java class Solution { public int calPoints(String[] ops) { @@ -153,6 +157,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go func calPoints(ops []string) int { var stk []int @@ -201,6 +209,8 @@ func calPoints(ops []string) int { } ``` +#### TypeScript + ```ts function calPoints(ops: string[]): number { const stack = []; @@ -220,6 +230,8 @@ function calPoints(ops: string[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn cal_points(ops: Vec) -> i32 { diff --git a/solution/0600-0699/0683.K Empty Slots/README.md b/solution/0600-0699/0683.K Empty Slots/README.md index 6b6a707170311..3e15824e340a5 100644 --- a/solution/0600-0699/0683.K Empty Slots/README.md +++ b/solution/0600-0699/0683.K Empty Slots/README.md @@ -73,6 +73,8 @@ bulbs = [1,3,2],k = 1 +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -109,6 +111,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int kEmptySlots(int[] bulbs, int k) { @@ -157,6 +161,8 @@ class BinaryIndexedTree { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -207,6 +213,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -252,6 +260,8 @@ func kEmptySlots(bulbs []int, k int) int { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; diff --git a/solution/0600-0699/0683.K Empty Slots/README_EN.md b/solution/0600-0699/0683.K Empty Slots/README_EN.md index b2620a256a576..5a47fcc2b298d 100644 --- a/solution/0600-0699/0683.K Empty Slots/README_EN.md +++ b/solution/0600-0699/0683.K Empty Slots/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n \times \log n)$ and the space complexity is $O(n)$, +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -105,6 +107,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int kEmptySlots(int[] bulbs, int k) { @@ -153,6 +157,8 @@ class BinaryIndexedTree { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -203,6 +209,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -248,6 +256,8 @@ func kEmptySlots(bulbs []int, k int) int { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; diff --git a/solution/0600-0699/0684.Redundant Connection/README.md b/solution/0600-0699/0684.Redundant Connection/README.md index 35a08d8ea2a49..0b7f73fb63d3b 100644 --- a/solution/0600-0699/0684.Redundant Connection/README.md +++ b/solution/0600-0699/0684.Redundant Connection/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def findRedundantConnection(self, edges: List[List[int]]) -> List[int]: @@ -85,6 +87,8 @@ class Solution: return [] ``` +#### Java + ```java class Solution { private int[] p; @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func findRedundantConnection(edges [][]int) []int { p := make([]int, 1010) @@ -160,6 +168,8 @@ func findRedundantConnection(edges [][]int) []int { } ``` +#### JavaScript + ```js /** * @param {number[][]} edges diff --git a/solution/0600-0699/0684.Redundant Connection/README_EN.md b/solution/0600-0699/0684.Redundant Connection/README_EN.md index 0e419a21d8755..be2170623ceb9 100644 --- a/solution/0600-0699/0684.Redundant Connection/README_EN.md +++ b/solution/0600-0699/0684.Redundant Connection/README_EN.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def findRedundantConnection(self, edges: List[List[int]]) -> List[int]: @@ -79,6 +81,8 @@ class Solution: return [] ``` +#### Java + ```java class Solution { private int[] p; @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func findRedundantConnection(edges [][]int) []int { p := make([]int, 1010) @@ -154,6 +162,8 @@ func findRedundantConnection(edges [][]int) []int { } ``` +#### JavaScript + ```js /** * @param {number[][]} edges diff --git a/solution/0600-0699/0685.Redundant Connection II/README.md b/solution/0600-0699/0685.Redundant Connection II/README.md index 3d55b22b2a7b6..3de822d55dfba 100644 --- a/solution/0600-0699/0685.Redundant Connection II/README.md +++ b/solution/0600-0699/0685.Redundant Connection II/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class UnionFind: def __init__(self, n): @@ -108,6 +110,8 @@ class Solution: return edges[conflict] ``` +#### Java + ```java class Solution { public int[] findRedundantDirectedConnection(int[][] edges) { @@ -172,6 +176,8 @@ class UnionFind { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -223,6 +229,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p []int diff --git a/solution/0600-0699/0685.Redundant Connection II/README_EN.md b/solution/0600-0699/0685.Redundant Connection II/README_EN.md index 020a57b624330..b4b0ef32b5248 100644 --- a/solution/0600-0699/0685.Redundant Connection II/README_EN.md +++ b/solution/0600-0699/0685.Redundant Connection II/README_EN.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class UnionFind: def __init__(self, n): @@ -103,6 +105,8 @@ class Solution: return edges[conflict] ``` +#### Java + ```java class Solution { public int[] findRedundantDirectedConnection(int[][] edges) { @@ -167,6 +171,8 @@ class UnionFind { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -218,6 +224,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p []int diff --git a/solution/0600-0699/0686.Repeated String Match/README.md b/solution/0600-0699/0686.Repeated String Match/README.md index 49ef0a0367c64..630a2ca46699f 100644 --- a/solution/0600-0699/0686.Repeated String Match/README.md +++ b/solution/0600-0699/0686.Repeated String Match/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def repeatedStringMatch(self, a: str, b: str) -> int: @@ -82,6 +84,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int repeatedStringMatch(String a, String b) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func repeatedStringMatch(a string, b string) int { m, n := len(a), len(b) @@ -134,6 +142,8 @@ func repeatedStringMatch(a string, b string) int { } ``` +#### TypeScript + ```ts function repeatedStringMatch(a: string, b: string): number { const m: number = a.length, diff --git a/solution/0600-0699/0686.Repeated String Match/README_EN.md b/solution/0600-0699/0686.Repeated String Match/README_EN.md index f2d0d5e3335fa..df3f0effe928a 100644 --- a/solution/0600-0699/0686.Repeated String Match/README_EN.md +++ b/solution/0600-0699/0686.Repeated String Match/README_EN.md @@ -55,6 +55,8 @@ tags: +#### Python3 + ```python class Solution: def repeatedStringMatch(self, a: str, b: str) -> int: @@ -69,6 +71,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int repeatedStringMatch(String a, String b) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func repeatedStringMatch(a string, b string) int { m, n := len(a), len(b) @@ -121,6 +129,8 @@ func repeatedStringMatch(a string, b string) int { } ``` +#### TypeScript + ```ts function repeatedStringMatch(a: string, b: string): number { const m: number = a.length, diff --git a/solution/0600-0699/0687.Longest Univalue Path/README.md b/solution/0600-0699/0687.Longest Univalue Path/README.md index eab98c50d937d..2b03c5365c4da 100644 --- a/solution/0600-0699/0687.Longest Univalue Path/README.md +++ b/solution/0600-0699/0687.Longest Univalue Path/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -197,6 +205,8 @@ func longestUnivaluePath(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -238,6 +248,8 @@ function longestUnivaluePath(root: TreeNode | null): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -287,6 +299,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -318,6 +332,8 @@ var longestUnivaluePath = function (root) { }; ``` +#### C + ```c /** * Definition for a binary tree node. diff --git a/solution/0600-0699/0687.Longest Univalue Path/README_EN.md b/solution/0600-0699/0687.Longest Univalue Path/README_EN.md index 9d94948b873cf..4879faaaee3e6 100644 --- a/solution/0600-0699/0687.Longest Univalue Path/README_EN.md +++ b/solution/0600-0699/0687.Longest Univalue Path/README_EN.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -189,6 +197,8 @@ func longestUnivaluePath(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -230,6 +240,8 @@ function longestUnivaluePath(root: TreeNode | null): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -279,6 +291,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -310,6 +324,8 @@ var longestUnivaluePath = function (root) { }; ``` +#### C + ```c /** * Definition for a binary tree node. diff --git a/solution/0600-0699/0688.Knight Probability in Chessboard/README.md b/solution/0600-0699/0688.Knight Probability in Chessboard/README.md index 7ddf44c2ea6ef..866d19677ca63 100644 --- a/solution/0600-0699/0688.Knight Probability in Chessboard/README.md +++ b/solution/0600-0699/0688.Knight Probability in Chessboard/README.md @@ -83,6 +83,8 @@ $$ +#### Python3 + ```python class Solution: def knightProbability(self, n: int, k: int, row: int, column: int) -> float: @@ -100,6 +102,8 @@ class Solution: return f[k][row][column] ``` +#### Java + ```java class Solution { public double knightProbability(int n, int k, int row, int column) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func knightProbability(n int, k int, row int, column int) float64 { f := make([][][]float64, k+1) @@ -185,6 +193,8 @@ func knightProbability(n int, k int, row int, column int) float64 { } ``` +#### TypeScript + ```ts function knightProbability(n: number, k: number, row: number, column: number): number { const f = new Array(k + 1) @@ -213,6 +223,8 @@ function knightProbability(n: number, k: number, row: number, column: number): n } ``` +#### Rust + ```rust const DIR: [(i32, i32); 8] = [ (-2, -1), diff --git a/solution/0600-0699/0688.Knight Probability in Chessboard/README_EN.md b/solution/0600-0699/0688.Knight Probability in Chessboard/README_EN.md index 3f151dcdf7166..8d4f097a06cda 100644 --- a/solution/0600-0699/0688.Knight Probability in Chessboard/README_EN.md +++ b/solution/0600-0699/0688.Knight Probability in Chessboard/README_EN.md @@ -79,6 +79,8 @@ The time complexity is $O(k \times n^2)$, and the space complexity is $O(k \time +#### Python3 + ```python class Solution: def knightProbability(self, n: int, k: int, row: int, column: int) -> float: @@ -96,6 +98,8 @@ class Solution: return f[k][row][column] ``` +#### Java + ```java class Solution { public double knightProbability(int n, int k, int row, int column) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func knightProbability(n int, k int, row int, column int) float64 { f := make([][][]float64, k+1) @@ -181,6 +189,8 @@ func knightProbability(n int, k int, row int, column int) float64 { } ``` +#### TypeScript + ```ts function knightProbability(n: number, k: number, row: number, column: number): number { const f = new Array(k + 1) @@ -209,6 +219,8 @@ function knightProbability(n: number, k: number, row: number, column: number): n } ``` +#### Rust + ```rust const DIR: [(i32, i32); 8] = [ (-2, -1), diff --git a/solution/0600-0699/0689.Maximum Sum of 3 Non-Overlapping Subarrays/README.md b/solution/0600-0699/0689.Maximum Sum of 3 Non-Overlapping Subarrays/README.md index 94c3d06ef5b4f..3a918077a444e 100644 --- a/solution/0600-0699/0689.Maximum Sum of 3 Non-Overlapping Subarrays/README.md +++ b/solution/0600-0699/0689.Maximum Sum of 3 Non-Overlapping Subarrays/README.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def maxSumOfThreeSubarrays(self, nums: List[int], k: int) -> List[int]: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] maxSumOfThreeSubarrays(int[] nums, int k) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func maxSumOfThreeSubarrays(nums []int, k int) []int { ans := make([]int, 3) @@ -194,6 +202,8 @@ func maxSumOfThreeSubarrays(nums []int, k int) []int { } ``` +#### TypeScript + ```ts function maxSumOfThreeSubarrays(nums: number[], k: number): number[] { const n: number = nums.length; @@ -263,6 +273,8 @@ function maxSumOfThreeSubarrays(nums: number[], k: number): number[] { +#### Python3 + ```python class Solution: def maxSumOfThreeSubarrays(self, nums: List[int], k: int) -> List[int]: @@ -293,6 +305,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] maxSumOfThreeSubarrays(int[] nums, int k) { @@ -336,6 +350,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -385,6 +401,8 @@ public: }; ``` +#### Go + ```go func maxSumOfThreeSubarrays(nums []int, k int) (ans []int) { n := len(nums) diff --git a/solution/0600-0699/0689.Maximum Sum of 3 Non-Overlapping Subarrays/README_EN.md b/solution/0600-0699/0689.Maximum Sum of 3 Non-Overlapping Subarrays/README_EN.md index 0ae48892e7ce0..46990928d3e2b 100644 --- a/solution/0600-0699/0689.Maximum Sum of 3 Non-Overlapping Subarrays/README_EN.md +++ b/solution/0600-0699/0689.Maximum Sum of 3 Non-Overlapping Subarrays/README_EN.md @@ -61,6 +61,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def maxSumOfThreeSubarrays(self, nums: List[int], k: int) -> List[int]: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] maxSumOfThreeSubarrays(int[] nums, int k) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func maxSumOfThreeSubarrays(nums []int, k int) []int { ans := make([]int, 3) @@ -192,6 +200,8 @@ func maxSumOfThreeSubarrays(nums []int, k int) []int { } ``` +#### TypeScript + ```ts function maxSumOfThreeSubarrays(nums: number[], k: number): number[] { const n: number = nums.length; @@ -261,6 +271,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def maxSumOfThreeSubarrays(self, nums: List[int], k: int) -> List[int]: @@ -291,6 +303,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] maxSumOfThreeSubarrays(int[] nums, int k) { @@ -334,6 +348,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -383,6 +399,8 @@ public: }; ``` +#### Go + ```go func maxSumOfThreeSubarrays(nums []int, k int) (ans []int) { n := len(nums) diff --git a/solution/0600-0699/0690.Employee Importance/README.md b/solution/0600-0699/0690.Employee Importance/README.md index 5755cc5db513b..078686f2c5266 100644 --- a/solution/0600-0699/0690.Employee Importance/README.md +++ b/solution/0600-0699/0690.Employee Importance/README.md @@ -56,6 +56,8 @@ tags: +#### Python3 + ```python """ # Definition for Employee. @@ -81,6 +83,8 @@ class Solution: return dfs(id) ``` +#### Java + ```java /* // Definition for Employee. @@ -113,6 +117,8 @@ class Solution { } ``` +#### JavaScript + ```js /** * Definition for Employee. diff --git a/solution/0600-0699/0690.Employee Importance/README_EN.md b/solution/0600-0699/0690.Employee Importance/README_EN.md index d4b9167243c96..b6bc497fc7426 100644 --- a/solution/0600-0699/0690.Employee Importance/README_EN.md +++ b/solution/0600-0699/0690.Employee Importance/README_EN.md @@ -74,6 +74,8 @@ Thus, the total importance value of employee 5 is -3. +#### Python3 + ```python """ # Definition for Employee. @@ -99,6 +101,8 @@ class Solution: return dfs(id) ``` +#### Java + ```java /* // Definition for Employee. @@ -131,6 +135,8 @@ class Solution { } ``` +#### JavaScript + ```js /** * Definition for Employee. diff --git a/solution/0600-0699/0691.Stickers to Spell Word/README.md b/solution/0600-0699/0691.Stickers to Spell Word/README.md index f86e59009fa44..ebf65ba77fbd3 100644 --- a/solution/0600-0699/0691.Stickers to Spell Word/README.md +++ b/solution/0600-0699/0691.Stickers to Spell Word/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def minStickers(self, stickers: List[str], target: str) -> int: @@ -98,6 +100,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minStickers(String[] stickers, String target) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go func minStickers(stickers []string, target string) int { q := []int{0} @@ -216,6 +224,8 @@ func minStickers(stickers []string, target string) int { } ``` +#### Rust + ```rust use std::collections::{ HashSet, VecDeque }; diff --git a/solution/0600-0699/0691.Stickers to Spell Word/README_EN.md b/solution/0600-0699/0691.Stickers to Spell Word/README_EN.md index 4d53c82b177bb..989b15e07db15 100644 --- a/solution/0600-0699/0691.Stickers to Spell Word/README_EN.md +++ b/solution/0600-0699/0691.Stickers to Spell Word/README_EN.md @@ -71,6 +71,8 @@ We cannot form the target "basicbasic" from cutting letters from the g +#### Python3 + ```python class Solution: def minStickers(self, stickers: List[str], target: str) -> int: @@ -98,6 +100,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minStickers(String[] stickers, String target) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go func minStickers(stickers []string, target string) int { q := []int{0} @@ -216,6 +224,8 @@ func minStickers(stickers []string, target string) int { } ``` +#### Rust + ```rust use std::collections::{ HashSet, VecDeque }; diff --git a/solution/0600-0699/0692.Top K Frequent Words/README.md b/solution/0600-0699/0692.Top K Frequent Words/README.md index d6329dfadc0e8..2aac58f80280f 100644 --- a/solution/0600-0699/0692.Top K Frequent Words/README.md +++ b/solution/0600-0699/0692.Top K Frequent Words/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def topKFrequent(self, words: List[str], k: int) -> List[str]: @@ -78,6 +80,8 @@ class Solution: return sorted(cnt, key=lambda x: (-cnt[x], x))[:k] ``` +#### Java + ```java class Solution { public List topKFrequent(String[] words, int k) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func topKFrequent(words []string, k int) []string { cnt := map[string]int{} diff --git a/solution/0600-0699/0692.Top K Frequent Words/README_EN.md b/solution/0600-0699/0692.Top K Frequent Words/README_EN.md index f63d6e12ef5da..8a85971974a4e 100644 --- a/solution/0600-0699/0692.Top K Frequent Words/README_EN.md +++ b/solution/0600-0699/0692.Top K Frequent Words/README_EN.md @@ -67,6 +67,8 @@ Note that "i" comes before "love" due to a lower alphabetica +#### Python3 + ```python class Solution: def topKFrequent(self, words: List[str], k: int) -> List[str]: @@ -74,6 +76,8 @@ class Solution: return sorted(cnt, key=lambda x: (-cnt[x], x))[:k] ``` +#### Java + ```java class Solution { public List topKFrequent(String[] words, int k) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func topKFrequent(words []string, k int) []string { cnt := map[string]int{} diff --git a/solution/0600-0699/0693.Binary Number with Alternating Bits/README.md b/solution/0600-0699/0693.Binary Number with Alternating Bits/README.md index 600f13177b62a..fb99c50abc98f 100644 --- a/solution/0600-0699/0693.Binary Number with Alternating Bits/README.md +++ b/solution/0600-0699/0693.Binary Number with Alternating Bits/README.md @@ -62,6 +62,8 @@ n 循环右移直至为 0,依次检测 n 的二进制位是否交替出现。 +#### Python3 + ```python class Solution: def hasAlternatingBits(self, n: int) -> bool: @@ -75,6 +77,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean hasAlternatingBits(int n) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func hasAlternatingBits(n int) bool { prev := -1 @@ -123,6 +131,8 @@ func hasAlternatingBits(n int) bool { } ``` +#### Rust + ```rust impl Solution { pub fn has_alternating_bits(mut n: i32) -> bool { @@ -155,6 +165,8 @@ impl Solution { +#### Python3 + ```python class Solution: def hasAlternatingBits(self, n: int) -> bool: @@ -162,6 +174,8 @@ class Solution: return (n & (n + 1)) == 0 ``` +#### Java + ```java class Solution { public boolean hasAlternatingBits(int n) { @@ -171,6 +185,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +197,8 @@ public: }; ``` +#### Go + ```go func hasAlternatingBits(n int) bool { n ^= (n >> 1) @@ -188,6 +206,8 @@ func hasAlternatingBits(n int) bool { } ``` +#### Rust + ```rust impl Solution { pub fn has_alternating_bits(n: i32) -> bool { diff --git a/solution/0600-0699/0693.Binary Number with Alternating Bits/README_EN.md b/solution/0600-0699/0693.Binary Number with Alternating Bits/README_EN.md index 009608198ece6..204daa667db6e 100644 --- a/solution/0600-0699/0693.Binary Number with Alternating Bits/README_EN.md +++ b/solution/0600-0699/0693.Binary Number with Alternating Bits/README_EN.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python class Solution: def hasAlternatingBits(self, n: int) -> bool: @@ -71,6 +73,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean hasAlternatingBits(int n) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -104,6 +110,8 @@ public: }; ``` +#### Go + ```go func hasAlternatingBits(n int) bool { prev := -1 @@ -119,6 +127,8 @@ func hasAlternatingBits(n int) bool { } ``` +#### Rust + ```rust impl Solution { pub fn has_alternating_bits(mut n: i32) -> bool { @@ -147,6 +157,8 @@ impl Solution { +#### Python3 + ```python class Solution: def hasAlternatingBits(self, n: int) -> bool: @@ -154,6 +166,8 @@ class Solution: return (n & (n + 1)) == 0 ``` +#### Java + ```java class Solution { public boolean hasAlternatingBits(int n) { @@ -163,6 +177,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -173,6 +189,8 @@ public: }; ``` +#### Go + ```go func hasAlternatingBits(n int) bool { n ^= (n >> 1) @@ -180,6 +198,8 @@ func hasAlternatingBits(n int) bool { } ``` +#### Rust + ```rust impl Solution { pub fn has_alternating_bits(n: i32) -> bool { diff --git a/solution/0600-0699/0694.Number of Distinct Islands/README.md b/solution/0600-0699/0694.Number of Distinct Islands/README.md index 07d5e1c7841e1..ccf03706439a1 100644 --- a/solution/0600-0699/0694.Number of Distinct Islands/README.md +++ b/solution/0600-0699/0694.Number of Distinct Islands/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def numDistinctIslands(self, grid: List[List[int]]) -> int: @@ -93,6 +95,8 @@ class Solution: return len(paths) ``` +#### Java + ```java class Solution { private int m; @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func numDistinctIslands(grid [][]int) int { m, n := len(grid), len(grid[0]) @@ -199,6 +207,8 @@ func numDistinctIslands(grid [][]int) int { } ``` +#### TypeScript + ```ts function numDistinctIslands(grid: number[][]): number { const m = grid.length; diff --git a/solution/0600-0699/0694.Number of Distinct Islands/README_EN.md b/solution/0600-0699/0694.Number of Distinct Islands/README_EN.md index 66f8d84933ef1..8ee087bb8e62e 100644 --- a/solution/0600-0699/0694.Number of Distinct Islands/README_EN.md +++ b/solution/0600-0699/0694.Number of Distinct Islands/README_EN.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def numDistinctIslands(self, grid: List[List[int]]) -> int: @@ -86,6 +88,8 @@ class Solution: return len(paths) ``` +#### Java + ```java class Solution { private int m; @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func numDistinctIslands(grid [][]int) int { m, n := len(grid), len(grid[0]) @@ -192,6 +200,8 @@ func numDistinctIslands(grid [][]int) int { } ``` +#### TypeScript + ```ts function numDistinctIslands(grid: number[][]): number { const m = grid.length; diff --git a/solution/0600-0699/0695.Max Area of Island/README.md b/solution/0600-0699/0695.Max Area of Island/README.md index 5860d76fe4584..1c60c4dbdbddb 100644 --- a/solution/0600-0699/0695.Max Area of Island/README.md +++ b/solution/0600-0699/0695.Max Area of Island/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def maxAreaOfIsland(self, grid: List[List[int]]) -> int: @@ -89,6 +91,8 @@ class Solution: return max(dfs(i, j) for i in range(m) for j in range(n)) ``` +#### Java + ```java class Solution { private int m; @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func maxAreaOfIsland(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -185,6 +193,8 @@ func maxAreaOfIsland(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function maxAreaOfIsland(grid: number[][]): number { const m = grid.length; @@ -214,6 +224,8 @@ function maxAreaOfIsland(grid: number[][]): number { } ``` +#### Rust + ```rust impl Solution { fn dfs(grid: &mut Vec>, i: usize, j: usize) -> i32 { diff --git a/solution/0600-0699/0695.Max Area of Island/README_EN.md b/solution/0600-0699/0695.Max Area of Island/README_EN.md index 053c704e1a38c..6077e828a445f 100644 --- a/solution/0600-0699/0695.Max Area of Island/README_EN.md +++ b/solution/0600-0699/0695.Max Area of Island/README_EN.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def maxAreaOfIsland(self, grid: List[List[int]]) -> int: @@ -81,6 +83,8 @@ class Solution: return max(dfs(i, j) for i in range(m) for j in range(n)) ``` +#### Java + ```java class Solution { private int m; @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func maxAreaOfIsland(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -177,6 +185,8 @@ func maxAreaOfIsland(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function maxAreaOfIsland(grid: number[][]): number { const m = grid.length; @@ -206,6 +216,8 @@ function maxAreaOfIsland(grid: number[][]): number { } ``` +#### Rust + ```rust impl Solution { fn dfs(grid: &mut Vec>, i: usize, j: usize) -> i32 { diff --git a/solution/0600-0699/0696.Count Binary Substrings/README.md b/solution/0600-0699/0696.Count Binary Substrings/README.md index 1efd625dc86b9..d5416a01d588a 100644 --- a/solution/0600-0699/0696.Count Binary Substrings/README.md +++ b/solution/0600-0699/0696.Count Binary Substrings/README.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python class Solution: def countBinarySubstrings(self, s: str) -> int: @@ -76,6 +78,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countBinarySubstrings(String s) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func countBinarySubstrings(s string) int { i, n := 0, len(s) diff --git a/solution/0600-0699/0696.Count Binary Substrings/README_EN.md b/solution/0600-0699/0696.Count Binary Substrings/README_EN.md index c53e9c2322da5..9d8b007e3303b 100644 --- a/solution/0600-0699/0696.Count Binary Substrings/README_EN.md +++ b/solution/0600-0699/0696.Count Binary Substrings/README_EN.md @@ -58,6 +58,8 @@ Also, "00110011" is not a valid substring because all the 0's (and +#### Python3 + ```python class Solution: def countBinarySubstrings(self, s: str) -> int: @@ -76,6 +78,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countBinarySubstrings(String s) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func countBinarySubstrings(s string) int { i, n := 0, len(s) diff --git a/solution/0600-0699/0697.Degree of an Array/README.md b/solution/0600-0699/0697.Degree of an Array/README.md index a2b8f985fe9e2..672c354dffda7 100644 --- a/solution/0600-0699/0697.Degree of an Array/README.md +++ b/solution/0600-0699/0697.Degree of an Array/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def findShortestSubArray(self, nums: List[int]) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findShortestSubArray(int[] nums) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func findShortestSubArray(nums []int) int { cnt := map[int]int{} @@ -186,6 +194,8 @@ func findShortestSubArray(nums []int) int { +#### Go + ```go func findShortestSubArray(nums []int) (ans int) { ans = 50000 diff --git a/solution/0600-0699/0697.Degree of an Array/README_EN.md b/solution/0600-0699/0697.Degree of an Array/README_EN.md index 00581c90386a2..48397e1b9e399 100644 --- a/solution/0600-0699/0697.Degree of an Array/README_EN.md +++ b/solution/0600-0699/0697.Degree of an Array/README_EN.md @@ -62,6 +62,8 @@ So [2,2,3,1,4,2] is the shortest subarray, therefore returning 6. +#### Python3 + ```python class Solution: def findShortestSubArray(self, nums: List[int]) -> int: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findShortestSubArray(int[] nums) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func findShortestSubArray(nums []int) int { cnt := map[int]int{} @@ -180,6 +188,8 @@ func findShortestSubArray(nums []int) int { +#### Go + ```go func findShortestSubArray(nums []int) (ans int) { ans = 50000 diff --git a/solution/0600-0699/0698.Partition to K Equal Sum Subsets/README.md b/solution/0600-0699/0698.Partition to K Equal Sum Subsets/README.md index 3d7f52fa72e0c..2f3ce15234dbe 100644 --- a/solution/0600-0699/0698.Partition to K Equal Sum Subsets/README.md +++ b/solution/0600-0699/0698.Partition to K Equal Sum Subsets/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def canPartitionKSubsets(self, nums: List[int], k: int) -> bool: @@ -89,6 +91,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private int[] nums; @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func canPartitionKSubsets(nums []int, k int) bool { s := 0 @@ -198,6 +206,8 @@ func canPartitionKSubsets(nums []int, k int) bool { } ``` +#### TypeScript + ```ts function canPartitionKSubsets(nums: number[], k: number): boolean { let s = nums.reduce((a, b) => a + b); @@ -255,6 +265,8 @@ function canPartitionKSubsets(nums: number[], k: number): boolean { +#### Python3 + ```python class Solution: def canPartitionKSubsets(self, nums: List[int], k: int) -> bool: @@ -279,6 +291,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private int[] f; @@ -326,6 +340,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -367,6 +383,8 @@ public: }; ``` +#### Go + ```go func canPartitionKSubsets(nums []int, k int) bool { s := 0 @@ -430,6 +448,8 @@ func canPartitionKSubsets(nums []int, k int) bool { +#### Python3 + ```python class Solution: def canPartitionKSubsets(self, nums: List[int], k: int) -> bool: @@ -455,6 +475,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public boolean canPartitionKSubsets(int[] nums, int k) { @@ -490,6 +512,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -525,6 +549,8 @@ public: }; ``` +#### Go + ```go func canPartitionKSubsets(nums []int, k int) bool { s := 0 diff --git a/solution/0600-0699/0698.Partition to K Equal Sum Subsets/README_EN.md b/solution/0600-0699/0698.Partition to K Equal Sum Subsets/README_EN.md index 7cc3cb85e7c3c..0904227f64a6a 100644 --- a/solution/0600-0699/0698.Partition to K Equal Sum Subsets/README_EN.md +++ b/solution/0600-0699/0698.Partition to K Equal Sum Subsets/README_EN.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python class Solution: def canPartitionKSubsets(self, nums: List[int], k: int) -> bool: @@ -81,6 +83,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private int[] nums; @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func canPartitionKSubsets(nums []int, k int) bool { s := 0 @@ -190,6 +198,8 @@ func canPartitionKSubsets(nums []int, k int) bool { } ``` +#### TypeScript + ```ts function canPartitionKSubsets(nums: number[], k: number): boolean { let s = nums.reduce((a, b) => a + b); @@ -230,6 +240,8 @@ function canPartitionKSubsets(nums: number[], k: number): boolean { +#### Python3 + ```python class Solution: def canPartitionKSubsets(self, nums: List[int], k: int) -> bool: @@ -254,6 +266,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private int[] f; @@ -301,6 +315,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -342,6 +358,8 @@ public: }; ``` +#### Go + ```go func canPartitionKSubsets(nums []int, k int) bool { s := 0 @@ -395,6 +413,8 @@ func canPartitionKSubsets(nums []int, k int) bool { +#### Python3 + ```python class Solution: def canPartitionKSubsets(self, nums: List[int], k: int) -> bool: @@ -420,6 +440,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public boolean canPartitionKSubsets(int[] nums, int k) { @@ -455,6 +477,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -490,6 +514,8 @@ public: }; ``` +#### Go + ```go func canPartitionKSubsets(nums []int, k int) bool { s := 0 diff --git a/solution/0600-0699/0699.Falling Squares/README.md b/solution/0600-0699/0699.Falling Squares/README.md index 9674de4d1dde8..b8fbd264d825b 100644 --- a/solution/0600-0699/0699.Falling Squares/README.md +++ b/solution/0600-0699/0699.Falling Squares/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Node: def __init__(self, l, r): @@ -165,6 +167,8 @@ class Solution: return ans ``` +#### Java + ```java class Node { Node left; @@ -271,6 +275,8 @@ class Solution { } ``` +#### C++ + ```cpp class Node { public: @@ -368,6 +374,8 @@ public: }; ``` +#### Go + ```go type node struct { left *node diff --git a/solution/0600-0699/0699.Falling Squares/README_EN.md b/solution/0600-0699/0699.Falling Squares/README_EN.md index 9bcfe560d64b0..a53d60a7a7b27 100644 --- a/solution/0600-0699/0699.Falling Squares/README_EN.md +++ b/solution/0600-0699/0699.Falling Squares/README_EN.md @@ -72,6 +72,8 @@ Note that square 2 only brushes the right side of square 1, which does not count +#### Python3 + ```python class Node: def __init__(self, l, r): @@ -149,6 +151,8 @@ class Solution: return ans ``` +#### Java + ```java class Node { Node left; @@ -255,6 +259,8 @@ class Solution { } ``` +#### C++ + ```cpp class Node { public: @@ -352,6 +358,8 @@ public: }; ``` +#### Go + ```go type node struct { left *node diff --git a/solution/0700-0799/0700.Search in a Binary Search Tree/README.md b/solution/0700-0799/0700.Search in a Binary Search Tree/README.md index d6f8f61886a6d..958511ec505d5 100644 --- a/solution/0700-0799/0700.Search in a Binary Search Tree/README.md +++ b/solution/0700-0799/0700.Search in a Binary Search Tree/README.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -79,6 +81,8 @@ class Solution: ) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0700-0799/0700.Search in a Binary Search Tree/README_EN.md b/solution/0700-0799/0700.Search in a Binary Search Tree/README_EN.md index ab1832615c226..fb6fa50215c75 100644 --- a/solution/0700-0799/0700.Search in a Binary Search Tree/README_EN.md +++ b/solution/0700-0799/0700.Search in a Binary Search Tree/README_EN.md @@ -57,6 +57,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -75,6 +77,8 @@ class Solution: ) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0700-0799/0701.Insert into a Binary Search Tree/README.md b/solution/0700-0799/0701.Insert into a Binary Search Tree/README.md index 1b8df4e2946e1..6801df9d91ca1 100644 --- a/solution/0700-0799/0701.Insert into a Binary Search Tree/README.md +++ b/solution/0700-0799/0701.Insert into a Binary Search Tree/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -90,6 +92,8 @@ class Solution: return dfs(root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0700-0799/0701.Insert into a Binary Search Tree/README_EN.md b/solution/0700-0799/0701.Insert into a Binary Search Tree/README_EN.md index 5e454a27fa797..e5c90a97e2a12 100644 --- a/solution/0700-0799/0701.Insert into a Binary Search Tree/README_EN.md +++ b/solution/0700-0799/0701.Insert into a Binary Search Tree/README_EN.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -88,6 +90,8 @@ class Solution: return dfs(root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0700-0799/0702.Search in a Sorted Array of Unknown Size/README.md b/solution/0700-0799/0702.Search in a Sorted Array of Unknown Size/README.md index b5ff244f99c36..517ed49c129b5 100644 --- a/solution/0700-0799/0702.Search in a Sorted Array of Unknown Size/README.md +++ b/solution/0700-0799/0702.Search in a Sorted Array of Unknown Size/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python # """ # This is ArrayReader's API interface. @@ -100,6 +102,8 @@ class Solution: return left if reader.get(left) == target else -1 ``` +#### Java + ```java /** * // This is ArrayReader's API interface. @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * // This is the ArrayReader's API interface. @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go /** * // This is the ArrayReader's API interface. diff --git a/solution/0700-0799/0702.Search in a Sorted Array of Unknown Size/README_EN.md b/solution/0700-0799/0702.Search in a Sorted Array of Unknown Size/README_EN.md index e47b67ce1f807..405d0dbe8ce2e 100644 --- a/solution/0700-0799/0702.Search in a Sorted Array of Unknown Size/README_EN.md +++ b/solution/0700-0799/0702.Search in a Sorted Array of Unknown Size/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python # """ # This is ArrayReader's API interface. @@ -95,6 +97,8 @@ class Solution: return left if reader.get(left) == target else -1 ``` +#### Java + ```java /** * // This is ArrayReader's API interface. @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * // This is the ArrayReader's API interface. @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go /** * // This is the ArrayReader's API interface. diff --git a/solution/0700-0799/0703.Kth Largest Element in a Stream/README.md b/solution/0700-0799/0703.Kth Largest Element in a Stream/README.md index d748746772eb9..a3bfc1571e398 100644 --- a/solution/0700-0799/0703.Kth Largest Element in a Stream/README.md +++ b/solution/0700-0799/0703.Kth Largest Element in a Stream/README.md @@ -72,6 +72,8 @@ kthLargest.add(4); // return 8 +#### Python3 + ```python class KthLargest: def __init__(self, k: int, nums: List[int]): @@ -92,6 +94,8 @@ class KthLargest: # param_1 = obj.add(val) ``` +#### Java + ```java class KthLargest { private PriorityQueue q; @@ -121,6 +125,8 @@ class KthLargest { */ ``` +#### C++ + ```cpp class KthLargest { public: @@ -146,6 +152,8 @@ public: */ ``` +#### Go + ```go type KthLargest struct { h *IntHeap @@ -222,6 +230,8 @@ func (h *IntHeap) Top() int { */ ``` +#### JavaScript + ```js /** * @param {number} k diff --git a/solution/0700-0799/0703.Kth Largest Element in a Stream/README_EN.md b/solution/0700-0799/0703.Kth Largest Element in a Stream/README_EN.md index f90411bc72e59..731b7c4eaa78f 100644 --- a/solution/0700-0799/0703.Kth Largest Element in a Stream/README_EN.md +++ b/solution/0700-0799/0703.Kth Largest Element in a Stream/README_EN.md @@ -71,6 +71,8 @@ kthLargest.add(4); // return 8 +#### Python3 + ```python class KthLargest: def __init__(self, k: int, nums: List[int]): @@ -91,6 +93,8 @@ class KthLargest: # param_1 = obj.add(val) ``` +#### Java + ```java class KthLargest { private PriorityQueue q; @@ -120,6 +124,8 @@ class KthLargest { */ ``` +#### C++ + ```cpp class KthLargest { public: @@ -145,6 +151,8 @@ public: */ ``` +#### Go + ```go type KthLargest struct { h *IntHeap @@ -221,6 +229,8 @@ func (h *IntHeap) Top() int { */ ``` +#### JavaScript + ```js /** * @param {number} k diff --git a/solution/0700-0799/0704.Binary Search/README.md b/solution/0700-0799/0704.Binary Search/README.md index 1daf3dc60adc7..6dcbef5abfeb6 100644 --- a/solution/0700-0799/0704.Binary Search/README.md +++ b/solution/0700-0799/0704.Binary Search/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def search(self, nums: List[int], target: int) -> int: @@ -78,6 +80,8 @@ class Solution: return left if nums[left] == target else -1 ``` +#### Java + ```java class Solution { public int search(int[] nums, int target) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func search(nums []int, target int) int { left, right := 0, len(nums)-1 @@ -130,6 +138,8 @@ func search(nums []int, target int) int { } ``` +#### Rust + ```rust use std::cmp::Ordering; @@ -156,6 +166,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -177,6 +189,8 @@ var search = function (nums, target) { }; ``` +#### C# + ```cs public class Solution { public int Search(int[] nums, int target) { diff --git a/solution/0700-0799/0704.Binary Search/README_EN.md b/solution/0700-0799/0704.Binary Search/README_EN.md index 7c0487dfa35c9..603270896d0b5 100644 --- a/solution/0700-0799/0704.Binary Search/README_EN.md +++ b/solution/0700-0799/0704.Binary Search/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(\log n)$, where $n$ is the length of the array $nums$. +#### Python3 + ```python class Solution: def search(self, nums: List[int], target: int) -> int: @@ -82,6 +84,8 @@ class Solution: return left if nums[left] == target else -1 ``` +#### Java + ```java class Solution { public int search(int[] nums, int target) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func search(nums []int, target int) int { left, right := 0, len(nums)-1 @@ -134,6 +142,8 @@ func search(nums []int, target int) int { } ``` +#### Rust + ```rust use std::cmp::Ordering; @@ -160,6 +170,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -181,6 +193,8 @@ var search = function (nums, target) { }; ``` +#### C# + ```cs public class Solution { public int Search(int[] nums, int target) { diff --git a/solution/0700-0799/0705.Design HashSet/README.md b/solution/0700-0799/0705.Design HashSet/README.md index 1267c3c67e27a..6612722177e17 100644 --- a/solution/0700-0799/0705.Design HashSet/README.md +++ b/solution/0700-0799/0705.Design HashSet/README.md @@ -76,6 +76,8 @@ myHashSet.contains(2); // 返回 False ,(已移除) +#### Python3 + ```python class MyHashSet: def __init__(self): @@ -98,6 +100,8 @@ class MyHashSet: # param_3 = obj.contains(key) ``` +#### Java + ```java class MyHashSet { private boolean[] data = new boolean[1000001]; @@ -127,6 +131,8 @@ class MyHashSet { */ ``` +#### C++ + ```cpp class MyHashSet { public: @@ -158,6 +164,8 @@ public: */ ``` +#### Go + ```go type MyHashSet struct { data []bool @@ -189,6 +197,8 @@ func (this *MyHashSet) Contains(key int) bool { */ ``` +#### TypeScript + ```ts class MyHashSet { data: Array; @@ -230,6 +240,8 @@ class MyHashSet { +#### Python3 + ```python class MyHashSet: def __init__(self): @@ -263,6 +275,8 @@ class MyHashSet: # param_3 = obj.contains(key) ``` +#### Java + ```java class MyHashSet { private static final int SIZE = 1000; @@ -317,6 +331,8 @@ class MyHashSet { */ ``` +#### C++ + ```cpp class MyHashSet { private: @@ -368,6 +384,8 @@ public: */ ``` +#### Go + ```go type MyHashSet struct { data []list.List diff --git a/solution/0700-0799/0705.Design HashSet/README_EN.md b/solution/0700-0799/0705.Design HashSet/README_EN.md index c2ddf886df3fc..93643c0395fdd 100644 --- a/solution/0700-0799/0705.Design HashSet/README_EN.md +++ b/solution/0700-0799/0705.Design HashSet/README_EN.md @@ -69,6 +69,8 @@ myHashSet.contains(2); // return False, (already removed) +#### Python3 + ```python class MyHashSet: def __init__(self): @@ -91,6 +93,8 @@ class MyHashSet: # param_3 = obj.contains(key) ``` +#### Java + ```java class MyHashSet { private boolean[] data = new boolean[1000001]; @@ -120,6 +124,8 @@ class MyHashSet { */ ``` +#### C++ + ```cpp class MyHashSet { public: @@ -151,6 +157,8 @@ public: */ ``` +#### Go + ```go type MyHashSet struct { data []bool @@ -182,6 +190,8 @@ func (this *MyHashSet) Contains(key int) bool { */ ``` +#### TypeScript + ```ts class MyHashSet { data: Array; @@ -221,6 +231,8 @@ class MyHashSet { +#### Python3 + ```python class MyHashSet: def __init__(self): @@ -254,6 +266,8 @@ class MyHashSet: # param_3 = obj.contains(key) ``` +#### Java + ```java class MyHashSet { private static final int SIZE = 1000; @@ -308,6 +322,8 @@ class MyHashSet { */ ``` +#### C++ + ```cpp class MyHashSet { private: @@ -359,6 +375,8 @@ public: */ ``` +#### Go + ```go type MyHashSet struct { data []list.List diff --git a/solution/0700-0799/0706.Design HashMap/README.md b/solution/0700-0799/0706.Design HashMap/README.md index 09cc3e9a0daeb..934ace5ef67bf 100644 --- a/solution/0700-0799/0706.Design HashMap/README.md +++ b/solution/0700-0799/0706.Design HashMap/README.md @@ -79,6 +79,8 @@ myHashMap.get(2); // 返回 -1(未找到),myHashMap 现在为 [[1,1]] +#### Python3 + ```python class MyHashMap: def __init__(self): @@ -101,6 +103,8 @@ class MyHashMap: # obj.remove(key) ``` +#### Java + ```java class MyHashMap { private int[] data = new int[1000001]; @@ -131,6 +135,8 @@ class MyHashMap { */ ``` +#### C++ + ```cpp class MyHashMap { public: @@ -162,6 +168,8 @@ public: */ ``` +#### Go + ```go type MyHashMap struct { data []int @@ -196,6 +204,8 @@ func (this *MyHashMap) Remove(key int) { */ ``` +#### TypeScript + ```ts class MyHashMap { data: Array; diff --git a/solution/0700-0799/0706.Design HashMap/README_EN.md b/solution/0700-0799/0706.Design HashMap/README_EN.md index 8023f5036f193..4ad9a1237f8b8 100644 --- a/solution/0700-0799/0706.Design HashMap/README_EN.md +++ b/solution/0700-0799/0706.Design HashMap/README_EN.md @@ -71,6 +71,8 @@ myHashMap.get(2); // return -1 (i.e., not found), The map is now [[1,1]] +#### Python3 + ```python class MyHashMap: def __init__(self): @@ -93,6 +95,8 @@ class MyHashMap: # obj.remove(key) ``` +#### Java + ```java class MyHashMap { private int[] data = new int[1000001]; @@ -123,6 +127,8 @@ class MyHashMap { */ ``` +#### C++ + ```cpp class MyHashMap { public: @@ -154,6 +160,8 @@ public: */ ``` +#### Go + ```go type MyHashMap struct { data []int @@ -188,6 +196,8 @@ func (this *MyHashMap) Remove(key int) { */ ``` +#### TypeScript + ```ts class MyHashMap { data: Array; diff --git a/solution/0700-0799/0707.Design Linked List/README.md b/solution/0700-0799/0707.Design Linked List/README.md index 71ae36007ad11..7afafe73df2d7 100644 --- a/solution/0700-0799/0707.Design Linked List/README.md +++ b/solution/0700-0799/0707.Design Linked List/README.md @@ -89,6 +89,8 @@ myLinkedList.get(1); // 返回 3 +#### Python3 + ```python class MyLinkedList: def __init__(self): @@ -139,6 +141,8 @@ class MyLinkedList: # obj.deleteAtIndex(index) ``` +#### Java + ```java class MyLinkedList { private ListNode dummy = new ListNode(); @@ -204,6 +208,8 @@ class MyLinkedList { */ ``` +#### C++ + ```cpp class MyLinkedList { private: @@ -271,6 +277,8 @@ public: */ ``` +#### Go + ```go type MyLinkedList struct { dummy *ListNode @@ -337,6 +345,8 @@ func (this *MyLinkedList) DeleteAtIndex(index int) { */ ``` +#### TypeScript + ```ts class LinkNode { public val: number; @@ -435,6 +445,8 @@ class MyLinkedList { */ ``` +#### Rust + ```rust #[derive(Default)] struct MyLinkedList { @@ -563,6 +575,8 @@ impl MyLinkedList { +#### Python3 + ```python class MyLinkedList: def __init__(self): @@ -627,6 +641,8 @@ class MyLinkedList: # obj.deleteAtIndex(index) ``` +#### Java + ```java class MyLinkedList { private int[] e = new int[1010]; @@ -706,6 +722,8 @@ class MyLinkedList { */ ``` +#### C++ + ```cpp class MyLinkedList { private: @@ -784,6 +802,8 @@ public: */ ``` +#### Go + ```go type MyLinkedList struct { e []int @@ -868,6 +888,8 @@ func (this *MyLinkedList) DeleteAtIndex(index int) { */ ``` +#### TypeScript + ```ts class MyLinkedList { e: Array; diff --git a/solution/0700-0799/0707.Design Linked List/README_EN.md b/solution/0700-0799/0707.Design Linked List/README_EN.md index b68d4aad3eb5d..5832a2aaa27bf 100644 --- a/solution/0700-0799/0707.Design Linked List/README_EN.md +++ b/solution/0700-0799/0707.Design Linked List/README_EN.md @@ -71,6 +71,8 @@ myLinkedList.get(1); // return 3 +#### Python3 + ```python class MyLinkedList: def __init__(self): @@ -121,6 +123,8 @@ class MyLinkedList: # obj.deleteAtIndex(index) ``` +#### Java + ```java class MyLinkedList { private ListNode dummy = new ListNode(); @@ -186,6 +190,8 @@ class MyLinkedList { */ ``` +#### C++ + ```cpp class MyLinkedList { private: @@ -253,6 +259,8 @@ public: */ ``` +#### Go + ```go type MyLinkedList struct { dummy *ListNode @@ -319,6 +327,8 @@ func (this *MyLinkedList) DeleteAtIndex(index int) { */ ``` +#### TypeScript + ```ts class LinkNode { public val: number; @@ -417,6 +427,8 @@ class MyLinkedList { */ ``` +#### Rust + ```rust #[derive(Default)] struct MyLinkedList { @@ -531,6 +543,8 @@ impl MyLinkedList { +#### Python3 + ```python class MyLinkedList: def __init__(self): @@ -595,6 +609,8 @@ class MyLinkedList: # obj.deleteAtIndex(index) ``` +#### Java + ```java class MyLinkedList { private int[] e = new int[1010]; @@ -674,6 +690,8 @@ class MyLinkedList { */ ``` +#### C++ + ```cpp class MyLinkedList { private: @@ -752,6 +770,8 @@ public: */ ``` +#### Go + ```go type MyLinkedList struct { e []int @@ -836,6 +856,8 @@ func (this *MyLinkedList) DeleteAtIndex(index int) { */ ``` +#### TypeScript + ```ts class MyLinkedList { e: Array; diff --git a/solution/0700-0799/0708.Insert into a Sorted Circular Linked List/README.md b/solution/0700-0799/0708.Insert into a Sorted Circular Linked List/README.md index 2f21d8bc2a0f6..9a28fda61f49d 100644 --- a/solution/0700-0799/0708.Insert into a Sorted Circular Linked List/README.md +++ b/solution/0700-0799/0708.Insert into a Sorted Circular Linked List/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python """ # Definition for a Node. @@ -99,6 +101,8 @@ class Solution: return head ``` +#### Java + ```java /* // Definition for a Node. @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -185,6 +191,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. diff --git a/solution/0700-0799/0708.Insert into a Sorted Circular Linked List/README_EN.md b/solution/0700-0799/0708.Insert into a Sorted Circular Linked List/README_EN.md index c447871493385..12b4d176b9af3 100644 --- a/solution/0700-0799/0708.Insert into a Sorted Circular Linked List/README_EN.md +++ b/solution/0700-0799/0708.Insert into a Sorted Circular Linked List/README_EN.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python """ # Definition for a Node. @@ -96,6 +98,8 @@ class Solution: return head ``` +#### Java + ```java /* // Definition for a Node. @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -182,6 +188,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. diff --git a/solution/0700-0799/0709.To Lower Case/README.md b/solution/0700-0799/0709.To Lower Case/README.md index b0303b47a8df7..ee862fa89988d 100644 --- a/solution/0700-0799/0709.To Lower Case/README.md +++ b/solution/0700-0799/0709.To Lower Case/README.md @@ -64,12 +64,16 @@ tags: +#### Python3 + ```python class Solution: def toLowerCase(self, s: str) -> str: return "".join([chr(ord(c) | 32) if c.isupper() else c for c in s]) ``` +#### Java + ```java class Solution { public String toLowerCase(String s) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -98,6 +104,8 @@ public: }; ``` +#### Go + ```go func toLowerCase(s string) string { cs := []byte(s) @@ -110,12 +118,16 @@ func toLowerCase(s string) string { } ``` +#### TypeScript + ```ts function toLowerCase(s: string): string { return s.toLowerCase(); } ``` +#### Rust + ```rust impl Solution { pub fn to_lower_case(s: String) -> String { @@ -124,6 +136,8 @@ impl Solution { } ``` +#### C + ```c char* toLowerCase(char* s) { int n = strlen(s); @@ -146,12 +160,16 @@ char* toLowerCase(char* s) { +#### TypeScript + ```ts function toLowerCase(s: string): string { return [...s].map(c => String.fromCharCode(c.charCodeAt(0) | 32)).join(''); } ``` +#### Rust + ```rust impl Solution { pub fn to_lower_case(s: String) -> String { diff --git a/solution/0700-0799/0709.To Lower Case/README_EN.md b/solution/0700-0799/0709.To Lower Case/README_EN.md index ebf7056e65399..de446955835d5 100644 --- a/solution/0700-0799/0709.To Lower Case/README_EN.md +++ b/solution/0700-0799/0709.To Lower Case/README_EN.md @@ -58,12 +58,16 @@ tags: +#### Python3 + ```python class Solution: def toLowerCase(self, s: str) -> str: return "".join([chr(ord(c) | 32) if c.isupper() else c for c in s]) ``` +#### Java + ```java class Solution { public String toLowerCase(String s) { @@ -78,6 +82,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -92,6 +98,8 @@ public: }; ``` +#### Go + ```go func toLowerCase(s string) string { cs := []byte(s) @@ -104,12 +112,16 @@ func toLowerCase(s string) string { } ``` +#### TypeScript + ```ts function toLowerCase(s: string): string { return s.toLowerCase(); } ``` +#### Rust + ```rust impl Solution { pub fn to_lower_case(s: String) -> String { @@ -118,6 +130,8 @@ impl Solution { } ``` +#### C + ```c char* toLowerCase(char* s) { int n = strlen(s); @@ -140,12 +154,16 @@ char* toLowerCase(char* s) { +#### TypeScript + ```ts function toLowerCase(s: string): string { return [...s].map(c => String.fromCharCode(c.charCodeAt(0) | 32)).join(''); } ``` +#### Rust + ```rust impl Solution { pub fn to_lower_case(s: String) -> String { diff --git a/solution/0700-0799/0710.Random Pick with Blacklist/README.md b/solution/0700-0799/0710.Random Pick with Blacklist/README.md index 8d6468ce981dd..28f0cfde392da 100644 --- a/solution/0700-0799/0710.Random Pick with Blacklist/README.md +++ b/solution/0700-0799/0710.Random Pick with Blacklist/README.md @@ -77,6 +77,8 @@ solution.pick(); // 返回 4 +#### Python3 + ```python class Solution: def __init__(self, n: int, blacklist: List[int]): @@ -101,6 +103,8 @@ class Solution: # param_1 = obj.pick() ``` +#### Java + ```java class Solution { private Map d = new HashMap<>(); @@ -137,6 +141,8 @@ class Solution { */ ``` +#### C++ + ```cpp class Solution { public: @@ -168,6 +174,8 @@ public: */ ``` +#### Go + ```go type Solution struct { d map[int]int diff --git a/solution/0700-0799/0710.Random Pick with Blacklist/README_EN.md b/solution/0700-0799/0710.Random Pick with Blacklist/README_EN.md index f0192f508cbef..45180723c524a 100644 --- a/solution/0700-0799/0710.Random Pick with Blacklist/README_EN.md +++ b/solution/0700-0799/0710.Random Pick with Blacklist/README_EN.md @@ -75,6 +75,8 @@ solution.pick(); // return 4 +#### Python3 + ```python class Solution: def __init__(self, n: int, blacklist: List[int]): @@ -99,6 +101,8 @@ class Solution: # param_1 = obj.pick() ``` +#### Java + ```java class Solution { private Map d = new HashMap<>(); @@ -135,6 +139,8 @@ class Solution { */ ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +172,8 @@ public: */ ``` +#### Go + ```go type Solution struct { d map[int]int diff --git a/solution/0700-0799/0711.Number of Distinct Islands II/README.md b/solution/0700-0799/0711.Number of Distinct Islands II/README.md index 3984e4645fd05..b308fc032d531 100644 --- a/solution/0700-0799/0711.Number of Distinct Islands II/README.md +++ b/solution/0700-0799/0711.Number of Distinct Islands II/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def numDistinctIslands2(self, grid: List[List[int]]) -> int: @@ -109,6 +111,8 @@ class Solution: return len(s) ``` +#### Java + ```java class Solution { private int m; @@ -205,6 +209,8 @@ class Solution { } ``` +#### C++ + ```cpp typedef pair PII; diff --git a/solution/0700-0799/0711.Number of Distinct Islands II/README_EN.md b/solution/0700-0799/0711.Number of Distinct Islands II/README_EN.md index 73d4cbd4b24e2..8bb7e339d96e6 100644 --- a/solution/0700-0799/0711.Number of Distinct Islands II/README_EN.md +++ b/solution/0700-0799/0711.Number of Distinct Islands II/README_EN.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def numDistinctIslands2(self, grid: List[List[int]]) -> int: @@ -103,6 +105,8 @@ class Solution: return len(s) ``` +#### Java + ```java class Solution { private int m; @@ -199,6 +203,8 @@ class Solution { } ``` +#### C++ + ```cpp typedef pair PII; diff --git a/solution/0700-0799/0712.Minimum ASCII Delete Sum for Two Strings/README.md b/solution/0700-0799/0712.Minimum ASCII Delete Sum for Two Strings/README.md index 14ccb15c136bf..c49ae19a0d7ea 100644 --- a/solution/0700-0799/0712.Minimum ASCII Delete Sum for Two Strings/README.md +++ b/solution/0700-0799/0712.Minimum ASCII Delete Sum for Two Strings/README.md @@ -83,6 +83,8 @@ $$ +#### Python3 + ```python class Solution: def minimumDeleteSum(self, s1: str, s2: str) -> int: @@ -103,6 +105,8 @@ class Solution: return f[m][n] ``` +#### Java + ```java class Solution { public int minimumDeleteSum(String s1, String s2) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func minimumDeleteSum(s1 string, s2 string) int { m, n := len(s1), len(s2) @@ -182,6 +190,8 @@ func minimumDeleteSum(s1 string, s2 string) int { } ``` +#### TypeScript + ```ts function minimumDeleteSum(s1: string, s2: string): number { const m = s1.length; @@ -209,6 +219,8 @@ function minimumDeleteSum(s1: string, s2: string): number { } ``` +#### JavaScript + ```js /** * @param {string} s1 diff --git a/solution/0700-0799/0712.Minimum ASCII Delete Sum for Two Strings/README_EN.md b/solution/0700-0799/0712.Minimum ASCII Delete Sum for Two Strings/README_EN.md index 29da3a1c192a6..239f87b90442c 100644 --- a/solution/0700-0799/0712.Minimum ASCII Delete Sum for Two Strings/README_EN.md +++ b/solution/0700-0799/0712.Minimum ASCII Delete Sum for Two Strings/README_EN.md @@ -60,6 +60,8 @@ If instead we turned both strings into "lee" or "eet", we wo +#### Python3 + ```python class Solution: def minimumDeleteSum(self, s1: str, s2: str) -> int: @@ -80,6 +82,8 @@ class Solution: return f[m][n] ``` +#### Java + ```java class Solution { public int minimumDeleteSum(String s1, String s2) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func minimumDeleteSum(s1 string, s2 string) int { m, n := len(s1), len(s2) @@ -159,6 +167,8 @@ func minimumDeleteSum(s1 string, s2 string) int { } ``` +#### TypeScript + ```ts function minimumDeleteSum(s1: string, s2: string): number { const m = s1.length; @@ -186,6 +196,8 @@ function minimumDeleteSum(s1: string, s2: string): number { } ``` +#### JavaScript + ```js /** * @param {string} s1 diff --git a/solution/0700-0799/0713.Subarray Product Less Than K/README.md b/solution/0700-0799/0713.Subarray Product Less Than K/README.md index 975df5a55d6af..1aff3142d5dbc 100644 --- a/solution/0700-0799/0713.Subarray Product Less Than K/README.md +++ b/solution/0700-0799/0713.Subarray Product Less Than K/README.md @@ -75,6 +75,8 @@ for (int i = 0, j = 0; i < n; ++i) { +#### Python3 + ```python class Solution: def numSubarrayProductLessThanK(self, nums: List[int], k: int) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numSubarrayProductLessThanK(int[] nums, int k) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func numSubarrayProductLessThanK(nums []int, k int) int { ans := 0 @@ -133,6 +141,8 @@ func numSubarrayProductLessThanK(nums []int, k int) int { } ``` +#### TypeScript + ```ts function numSubarrayProductLessThanK(nums: number[], k: number): number { let ans = 0; @@ -147,6 +157,8 @@ function numSubarrayProductLessThanK(nums: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn num_subarray_product_less_than_k(nums: Vec, k: i32) -> i32 { @@ -172,6 +184,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0700-0799/0713.Subarray Product Less Than K/README_EN.md b/solution/0700-0799/0713.Subarray Product Less Than K/README_EN.md index 313020751e831..6e1615a8c6577 100644 --- a/solution/0700-0799/0713.Subarray Product Less Than K/README_EN.md +++ b/solution/0700-0799/0713.Subarray Product Less Than K/README_EN.md @@ -56,6 +56,8 @@ Note that [10, 5, 2] is not included as the product of 100 is not strictly less +#### Python3 + ```python class Solution: def numSubarrayProductLessThanK(self, nums: List[int], k: int) -> int: @@ -69,6 +71,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numSubarrayProductLessThanK(int[] nums, int k) { @@ -85,6 +89,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -100,6 +106,8 @@ public: }; ``` +#### Go + ```go func numSubarrayProductLessThanK(nums []int, k int) int { ans := 0 @@ -114,6 +122,8 @@ func numSubarrayProductLessThanK(nums []int, k int) int { } ``` +#### TypeScript + ```ts function numSubarrayProductLessThanK(nums: number[], k: number): number { let ans = 0; @@ -128,6 +138,8 @@ function numSubarrayProductLessThanK(nums: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn num_subarray_product_less_than_k(nums: Vec, k: i32) -> i32 { @@ -153,6 +165,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0700-0799/0714.Best Time to Buy and Sell Stock with Transaction Fee/README.md b/solution/0700-0799/0714.Best Time to Buy and Sell Stock with Transaction Fee/README.md index bf70040600adf..de3f5bfe6b160 100644 --- a/solution/0700-0799/0714.Best Time to Buy and Sell Stock with Transaction Fee/README.md +++ b/solution/0700-0799/0714.Best Time to Buy and Sell Stock with Transaction Fee/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def maxProfit(self, prices: List[int], fee: int) -> int: @@ -98,6 +100,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private Integer[][] f; @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func maxProfit(prices []int, fee int) int { n := len(prices) @@ -184,6 +192,8 @@ func maxProfit(prices []int, fee int) int { } ``` +#### TypeScript + ```ts function maxProfit(prices: number[], fee: number): number { const n = prices.length; @@ -225,6 +235,8 @@ function maxProfit(prices: number[], fee: number): number { +#### Python3 + ```python class Solution: def maxProfit(self, prices: List[int], fee: int) -> int: @@ -237,6 +249,8 @@ class Solution: return f[n - 1][0] ``` +#### Java + ```java class Solution { public int maxProfit(int[] prices, int fee) { @@ -252,6 +266,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -269,6 +285,8 @@ public: }; ``` +#### Go + ```go func maxProfit(prices []int, fee int) int { n := len(prices) @@ -282,6 +300,8 @@ func maxProfit(prices []int, fee int) int { } ``` +#### TypeScript + ```ts function maxProfit(prices: number[], fee: number): number { const n = prices.length; @@ -305,6 +325,8 @@ function maxProfit(prices: number[], fee: number): number { +#### Python3 + ```python class Solution: def maxProfit(self, prices: List[int], fee: int) -> int: @@ -314,6 +336,8 @@ class Solution: return f0 ``` +#### Java + ```java class Solution { public int maxProfit(int[] prices, int fee) { @@ -328,6 +352,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -343,6 +369,8 @@ public: }; ``` +#### Go + ```go func maxProfit(prices []int, fee int) int { f0, f1 := 0, -prices[0] @@ -353,6 +381,8 @@ func maxProfit(prices []int, fee int) int { } ``` +#### TypeScript + ```ts function maxProfit(prices: number[], fee: number): number { const n = prices.length; diff --git a/solution/0700-0799/0714.Best Time to Buy and Sell Stock with Transaction Fee/README_EN.md b/solution/0700-0799/0714.Best Time to Buy and Sell Stock with Transaction Fee/README_EN.md index 4fe4ab582095b..b6cb08430308f 100644 --- a/solution/0700-0799/0714.Best Time to Buy and Sell Stock with Transaction Fee/README_EN.md +++ b/solution/0700-0799/0714.Best Time to Buy and Sell Stock with Transaction Fee/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def maxProfit(self, prices: List[int], fee: int) -> int: @@ -100,6 +102,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private Integer[][] f; @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func maxProfit(prices []int, fee int) int { n := len(prices) @@ -186,6 +194,8 @@ func maxProfit(prices []int, fee int) int { } ``` +#### TypeScript + ```ts function maxProfit(prices: number[], fee: number): number { const n = prices.length; @@ -227,6 +237,8 @@ We notice that the transition of the state $f[i][]$ only depends on $f[i - 1][]$ +#### Python3 + ```python class Solution: def maxProfit(self, prices: List[int], fee: int) -> int: @@ -239,6 +251,8 @@ class Solution: return f[n - 1][0] ``` +#### Java + ```java class Solution { public int maxProfit(int[] prices, int fee) { @@ -254,6 +268,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -271,6 +287,8 @@ public: }; ``` +#### Go + ```go func maxProfit(prices []int, fee int) int { n := len(prices) @@ -284,6 +302,8 @@ func maxProfit(prices []int, fee int) int { } ``` +#### TypeScript + ```ts function maxProfit(prices: number[], fee: number): number { const n = prices.length; @@ -307,6 +327,8 @@ function maxProfit(prices: number[], fee: number): number { +#### Python3 + ```python class Solution: def maxProfit(self, prices: List[int], fee: int) -> int: @@ -316,6 +338,8 @@ class Solution: return f0 ``` +#### Java + ```java class Solution { public int maxProfit(int[] prices, int fee) { @@ -330,6 +354,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -345,6 +371,8 @@ public: }; ``` +#### Go + ```go func maxProfit(prices []int, fee int) int { f0, f1 := 0, -prices[0] @@ -355,6 +383,8 @@ func maxProfit(prices []int, fee int) int { } ``` +#### TypeScript + ```ts function maxProfit(prices: number[], fee: number): number { const n = prices.length; diff --git a/solution/0700-0799/0715.Range Module/README.md b/solution/0700-0799/0715.Range Module/README.md index eca788d8b15c1..a295004f0f5f7 100644 --- a/solution/0700-0799/0715.Range Module/README.md +++ b/solution/0700-0799/0715.Range Module/README.md @@ -83,6 +83,8 @@ rangeModule.queryRange(16, 17); 返回 true (尽管执行了删除操作,区 +#### Python3 + ```python class Node: __slots__ = ['left', 'right', 'add', 'v'] @@ -169,6 +171,8 @@ class RangeModule: # obj.removeRange(left,right) ``` +#### Java + ```java class Node { Node left; @@ -273,6 +277,8 @@ class RangeModule { */ ``` +#### C++ + ```cpp template class CachedObj { @@ -400,6 +406,8 @@ public: */ ``` +#### Go + ```go const N int = 1e9 @@ -504,6 +512,8 @@ func (this *RangeModule) RemoveRange(left int, right int) { */ ``` +#### TypeScript + ```ts class Node { left: Node | null; diff --git a/solution/0700-0799/0715.Range Module/README_EN.md b/solution/0700-0799/0715.Range Module/README_EN.md index 31a99d331faa8..44d9c974009fe 100644 --- a/solution/0700-0799/0715.Range Module/README_EN.md +++ b/solution/0700-0799/0715.Range Module/README_EN.md @@ -81,6 +81,8 @@ In terms of time complexity, the time complexity of each operation is $O(\log n) +#### Python3 + ```python class Node: __slots__ = ['left', 'right', 'add', 'v'] @@ -167,6 +169,8 @@ class RangeModule: # obj.removeRange(left,right) ``` +#### Java + ```java class Node { Node left; @@ -271,6 +275,8 @@ class RangeModule { */ ``` +#### C++ + ```cpp template class CachedObj { @@ -398,6 +404,8 @@ public: */ ``` +#### Go + ```go const N int = 1e9 @@ -502,6 +510,8 @@ func (this *RangeModule) RemoveRange(left int, right int) { */ ``` +#### TypeScript + ```ts class Node { left: Node | null; diff --git a/solution/0700-0799/0716.Max Stack/README.md b/solution/0700-0799/0716.Max Stack/README.md index eef3cf6b716ee..ac66bac91f6f8 100644 --- a/solution/0700-0799/0716.Max Stack/README.md +++ b/solution/0700-0799/0716.Max Stack/README.md @@ -95,6 +95,8 @@ stk.top(); // 返回 5,[5] - 栈没有改变 +#### Python3 + ```python from sortedcontainers import SortedList @@ -169,6 +171,8 @@ class MaxStack: # param_5 = obj.popMax() ``` +#### Java + ```java class Node { public int val; @@ -268,6 +272,8 @@ class MaxStack { */ ``` +#### C++ + ```cpp class MaxStack { public: diff --git a/solution/0700-0799/0716.Max Stack/README_EN.md b/solution/0700-0799/0716.Max Stack/README_EN.md index 6877f81244ff0..126d4b2525861 100644 --- a/solution/0700-0799/0716.Max Stack/README_EN.md +++ b/solution/0700-0799/0716.Max Stack/README_EN.md @@ -77,6 +77,8 @@ stk.top(); // return 5, [5] the stack did not change +#### Python3 + ```python from sortedcontainers import SortedList @@ -151,6 +153,8 @@ class MaxStack: # param_5 = obj.popMax() ``` +#### Java + ```java class Node { public int val; @@ -250,6 +254,8 @@ class MaxStack { */ ``` +#### C++ + ```cpp class MaxStack { public: diff --git a/solution/0700-0799/0717.1-bit and 2-bit Characters/README.md b/solution/0700-0799/0717.1-bit and 2-bit Characters/README.md index 53fccf73fdcf9..0f600671cf068 100644 --- a/solution/0700-0799/0717.1-bit and 2-bit Characters/README.md +++ b/solution/0700-0799/0717.1-bit and 2-bit Characters/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def isOneBitCharacter(self, bits: List[int]) -> bool: @@ -73,6 +75,8 @@ class Solution: return i == n - 1 ``` +#### Java + ```java class Solution { public boolean isOneBitCharacter(int[] bits) { @@ -85,6 +89,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -96,6 +102,8 @@ public: }; ``` +#### Go + ```go func isOneBitCharacter(bits []int) bool { i, n := 0, len(bits) @@ -106,6 +114,8 @@ func isOneBitCharacter(bits []int) bool { } ``` +#### JavaScript + ```js /** * @param {number[]} bits diff --git a/solution/0700-0799/0717.1-bit and 2-bit Characters/README_EN.md b/solution/0700-0799/0717.1-bit and 2-bit Characters/README_EN.md index fac7638312340..6410e3ded0e5b 100644 --- a/solution/0700-0799/0717.1-bit and 2-bit Characters/README_EN.md +++ b/solution/0700-0799/0717.1-bit and 2-bit Characters/README_EN.md @@ -62,6 +62,8 @@ So the last character is not one-bit character. +#### Python3 + ```python class Solution: def isOneBitCharacter(self, bits: List[int]) -> bool: @@ -71,6 +73,8 @@ class Solution: return i == n - 1 ``` +#### Java + ```java class Solution { public boolean isOneBitCharacter(int[] bits) { @@ -83,6 +87,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -94,6 +100,8 @@ public: }; ``` +#### Go + ```go func isOneBitCharacter(bits []int) bool { i, n := 0, len(bits) @@ -104,6 +112,8 @@ func isOneBitCharacter(bits []int) bool { } ``` +#### JavaScript + ```js /** * @param {number[]} bits diff --git a/solution/0700-0799/0718.Maximum Length of Repeated Subarray/README.md b/solution/0700-0799/0718.Maximum Length of Repeated Subarray/README.md index d5e6574a39fb5..28f65f4f8d3d2 100644 --- a/solution/0700-0799/0718.Maximum Length of Repeated Subarray/README.md +++ b/solution/0700-0799/0718.Maximum Length of Repeated Subarray/README.md @@ -73,6 +73,8 @@ $$ +#### Python3 + ```python class Solution: def findLength(self, nums1: List[int], nums2: List[int]) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findLength(int[] nums1, int[] nums2) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func findLength(nums1 []int, nums2 []int) (ans int) { m, n := len(nums1), len(nums2) @@ -148,6 +156,8 @@ func findLength(nums1 []int, nums2 []int) (ans int) { } ``` +#### TypeScript + ```ts function findLength(nums1: number[], nums2: number[]): number { const m = nums1.length; @@ -166,6 +176,8 @@ function findLength(nums1: number[], nums2: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums1 diff --git a/solution/0700-0799/0718.Maximum Length of Repeated Subarray/README_EN.md b/solution/0700-0799/0718.Maximum Length of Repeated Subarray/README_EN.md index 62bee687383e2..ff04b3b6ec02d 100644 --- a/solution/0700-0799/0718.Maximum Length of Repeated Subarray/README_EN.md +++ b/solution/0700-0799/0718.Maximum Length of Repeated Subarray/README_EN.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python class Solution: def findLength(self, nums1: List[int], nums2: List[int]) -> int: @@ -72,6 +74,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findLength(int[] nums1, int[] nums2) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func findLength(nums1 []int, nums2 []int) (ans int) { m, n := len(nums1), len(nums2) @@ -133,6 +141,8 @@ func findLength(nums1 []int, nums2 []int) (ans int) { } ``` +#### TypeScript + ```ts function findLength(nums1: number[], nums2: number[]): number { const m = nums1.length; @@ -151,6 +161,8 @@ function findLength(nums1: number[], nums2: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums1 diff --git a/solution/0700-0799/0719.Find K-th Smallest Pair Distance/README.md b/solution/0700-0799/0719.Find K-th Smallest Pair Distance/README.md index bbbc8b8d3abe1..67b38127c0a8a 100644 --- a/solution/0700-0799/0719.Find K-th Smallest Pair Distance/README.md +++ b/solution/0700-0799/0719.Find K-th Smallest Pair Distance/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def smallestDistancePair(self, nums: List[int], k: int) -> int: @@ -91,6 +93,8 @@ class Solution: return bisect_left(range(nums[-1] - nums[0]), k, key=count) ``` +#### Java + ```java class Solution { public int smallestDistancePair(int[] nums, int k) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func smallestDistancePair(nums []int, k int) int { sort.Ints(nums) @@ -189,6 +197,8 @@ func smallestDistancePair(nums []int, k int) int { } ``` +#### TypeScript + ```ts function smallestDistancePair(nums: number[], k: number): number { nums.sort((a, b) => a - b); diff --git a/solution/0700-0799/0719.Find K-th Smallest Pair Distance/README_EN.md b/solution/0700-0799/0719.Find K-th Smallest Pair Distance/README_EN.md index 89387f889a684..d09dbe355c366 100644 --- a/solution/0700-0799/0719.Find K-th Smallest Pair Distance/README_EN.md +++ b/solution/0700-0799/0719.Find K-th Smallest Pair Distance/README_EN.md @@ -70,6 +70,8 @@ Then the 1st smallest distance pair is (1,1), and its distance is 0. +#### Python3 + ```python class Solution: def smallestDistancePair(self, nums: List[int], k: int) -> int: @@ -85,6 +87,8 @@ class Solution: return bisect_left(range(nums[-1] - nums[0]), k, key=count) ``` +#### Java + ```java class Solution { public int smallestDistancePair(int[] nums, int k) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func smallestDistancePair(nums []int, k int) int { sort.Ints(nums) @@ -183,6 +191,8 @@ func smallestDistancePair(nums []int, k int) int { } ``` +#### TypeScript + ```ts function smallestDistancePair(nums: number[], k: number): number { nums.sort((a, b) => a - b); diff --git a/solution/0700-0799/0720.Longest Word in Dictionary/README.md b/solution/0700-0799/0720.Longest Word in Dictionary/README.md index 1bd5ae85cb44f..9e22d310677f5 100644 --- a/solution/0700-0799/0720.Longest Word in Dictionary/README.md +++ b/solution/0700-0799/0720.Longest Word in Dictionary/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def longestWord(self, words: List[str]) -> str: @@ -79,6 +81,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private Set s; @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func longestWord(words []string) string { s := make(map[string]bool) @@ -171,6 +179,8 @@ func longestWord(words []string) string { } ``` +#### TypeScript + ```ts function longestWord(words: string[]): string { words.sort((a, b) => { @@ -197,6 +207,8 @@ function longestWord(words: string[]): string { } ``` +#### Rust + ```rust impl Solution { pub fn longest_word(mut words: Vec) -> String { diff --git a/solution/0700-0799/0720.Longest Word in Dictionary/README_EN.md b/solution/0700-0799/0720.Longest Word in Dictionary/README_EN.md index 66c51077745fa..886cf6301b6d7 100644 --- a/solution/0700-0799/0720.Longest Word in Dictionary/README_EN.md +++ b/solution/0700-0799/0720.Longest Word in Dictionary/README_EN.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def longestWord(self, words: List[str]) -> str: @@ -77,6 +79,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private Set s; @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func longestWord(words []string) string { s := make(map[string]bool) @@ -169,6 +177,8 @@ func longestWord(words []string) string { } ``` +#### TypeScript + ```ts function longestWord(words: string[]): string { words.sort((a, b) => { @@ -195,6 +205,8 @@ function longestWord(words: string[]): string { } ``` +#### Rust + ```rust impl Solution { pub fn longest_word(mut words: Vec) -> String { diff --git a/solution/0700-0799/0721.Accounts Merge/README.md b/solution/0700-0799/0721.Accounts Merge/README.md index 316b1a4a03cdc..973a93b4613b9 100644 --- a/solution/0700-0799/0721.Accounts Merge/README.md +++ b/solution/0700-0799/0721.Accounts Merge/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def accountsMerge(self, accounts: List[List[str]]) -> List[List[str]]: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] p; @@ -153,6 +157,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/0700-0799/0721.Accounts Merge/README_EN.md b/solution/0700-0799/0721.Accounts Merge/README_EN.md index 47889ece6e22d..52a0a59655224 100644 --- a/solution/0700-0799/0721.Accounts Merge/README_EN.md +++ b/solution/0700-0799/0721.Accounts Merge/README_EN.md @@ -69,6 +69,8 @@ We could return these lists in any order, for example the answer [['Mary' +#### Python3 + ```python class Solution: def accountsMerge(self, accounts: List[List[str]]) -> List[List[str]]: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] p; @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/0700-0799/0722.Remove Comments/README.md b/solution/0700-0799/0722.Remove Comments/README.md index 0726630991f15..144b3f2264ef8 100644 --- a/solution/0700-0799/0722.Remove Comments/README.md +++ b/solution/0700-0799/0722.Remove Comments/README.md @@ -120,6 +120,8 @@ a = b + c; +#### Python3 + ```python class Solution: def removeComments(self, source: List[str]) -> List[str]: @@ -148,6 +150,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List removeComments(String[] source) { @@ -183,6 +187,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -219,6 +225,8 @@ public: }; ``` +#### Go + ```go func removeComments(source []string) (ans []string) { t := []byte{} @@ -251,6 +259,8 @@ func removeComments(source []string) (ans []string) { } ``` +#### TypeScript + ```ts function removeComments(source: string[]): string[] { const ans: string[] = []; @@ -284,6 +294,8 @@ function removeComments(source: string[]): string[] { } ``` +#### Rust + ```rust impl Solution { pub fn remove_comments(source: Vec) -> Vec { diff --git a/solution/0700-0799/0722.Remove Comments/README_EN.md b/solution/0700-0799/0722.Remove Comments/README_EN.md index 3959bc9d432a2..9d1a77e0b19a7 100644 --- a/solution/0700-0799/0722.Remove Comments/README_EN.md +++ b/solution/0700-0799/0722.Remove Comments/README_EN.md @@ -106,6 +106,8 @@ a = b + c; +#### Python3 + ```python class Solution: def removeComments(self, source: List[str]) -> List[str]: @@ -134,6 +136,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List removeComments(String[] source) { @@ -169,6 +173,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -205,6 +211,8 @@ public: }; ``` +#### Go + ```go func removeComments(source []string) (ans []string) { t := []byte{} @@ -237,6 +245,8 @@ func removeComments(source []string) (ans []string) { } ``` +#### TypeScript + ```ts function removeComments(source: string[]): string[] { const ans: string[] = []; @@ -270,6 +280,8 @@ function removeComments(source: string[]): string[] { } ``` +#### Rust + ```rust impl Solution { pub fn remove_comments(source: Vec) -> Vec { diff --git a/solution/0700-0799/0723.Candy Crush/README.md b/solution/0700-0799/0723.Candy Crush/README.md index 2c97317a5e9db..0f192402f72e8 100644 --- a/solution/0700-0799/0723.Candy Crush/README.md +++ b/solution/0700-0799/0723.Candy Crush/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def candyCrush(self, board: List[List[int]]) -> List[List[int]]: @@ -117,6 +119,8 @@ class Solution: return board ``` +#### Java + ```java class Solution { public int[][] candyCrush(int[][] board) { @@ -163,6 +167,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -208,6 +214,8 @@ public: }; ``` +#### Go + ```go func candyCrush(board [][]int) [][]int { m, n := len(board), len(board[0]) diff --git a/solution/0700-0799/0723.Candy Crush/README_EN.md b/solution/0700-0799/0723.Candy Crush/README_EN.md index fc79688e6ea75..ecf1d5548c52a 100644 --- a/solution/0700-0799/0723.Candy Crush/README_EN.md +++ b/solution/0700-0799/0723.Candy Crush/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def candyCrush(self, board: List[List[int]]) -> List[List[int]]: @@ -111,6 +113,8 @@ class Solution: return board ``` +#### Java + ```java class Solution { public int[][] candyCrush(int[][] board) { @@ -157,6 +161,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -202,6 +208,8 @@ public: }; ``` +#### Go + ```go func candyCrush(board [][]int) [][]int { m, n := len(board), len(board[0]) diff --git a/solution/0700-0799/0724.Find Pivot Index/README.md b/solution/0700-0799/0724.Find Pivot Index/README.md index a645f10002f41..ab2819c3fa462 100644 --- a/solution/0700-0799/0724.Find Pivot Index/README.md +++ b/solution/0700-0799/0724.Find Pivot Index/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def pivotIndex(self, nums: List[int]) -> int: @@ -104,6 +106,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int pivotIndex(int[] nums) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func pivotIndex(nums []int) int { var left, right int @@ -154,6 +162,8 @@ func pivotIndex(nums []int) int { } ``` +#### TypeScript + ```ts function pivotIndex(nums: number[]): number { let left = 0, @@ -169,6 +179,8 @@ function pivotIndex(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn pivot_index(nums: Vec) -> i32 { @@ -185,6 +197,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0700-0799/0724.Find Pivot Index/README_EN.md b/solution/0700-0799/0724.Find Pivot Index/README_EN.md index 7051160278706..e9fb09d3d9383 100644 --- a/solution/0700-0799/0724.Find Pivot Index/README_EN.md +++ b/solution/0700-0799/0724.Find Pivot Index/README_EN.md @@ -77,6 +77,8 @@ Right sum = nums[1] + nums[2] = 1 + -1 = 0 +#### Python3 + ```python class Solution: def pivotIndex(self, nums: List[int]) -> int: @@ -89,6 +91,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int pivotIndex(int[] nums) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func pivotIndex(nums []int) int { var left, right int @@ -139,6 +147,8 @@ func pivotIndex(nums []int) int { } ``` +#### TypeScript + ```ts function pivotIndex(nums: number[]): number { let left = 0, @@ -154,6 +164,8 @@ function pivotIndex(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn pivot_index(nums: Vec) -> i32 { @@ -170,6 +182,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0700-0799/0725.Split Linked List in Parts/README.md b/solution/0700-0799/0725.Split Linked List in Parts/README.md index f009d66689c8c..2c69b564ce9ee 100644 --- a/solution/0700-0799/0725.Split Linked List in Parts/README.md +++ b/solution/0700-0799/0725.Split Linked List in Parts/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -92,6 +94,8 @@ class Solution: return res ``` +#### Java + ```java /** * Definition for singly-linked list. diff --git a/solution/0700-0799/0725.Split Linked List in Parts/README_EN.md b/solution/0700-0799/0725.Split Linked List in Parts/README_EN.md index d0ba85ab82d4c..cb2023eec5412 100644 --- a/solution/0700-0799/0725.Split Linked List in Parts/README_EN.md +++ b/solution/0700-0799/0725.Split Linked List in Parts/README_EN.md @@ -63,6 +63,8 @@ The input has been split into consecutive parts with size difference at most 1, +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -91,6 +93,8 @@ class Solution: return res ``` +#### Java + ```java /** * Definition for singly-linked list. diff --git a/solution/0700-0799/0726.Number of Atoms/README.md b/solution/0700-0799/0726.Number of Atoms/README.md index 15fb68afb4027..d7d1da455232e 100644 --- a/solution/0700-0799/0726.Number of Atoms/README.md +++ b/solution/0700-0799/0726.Number of Atoms/README.md @@ -89,18 +89,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/0700-0799/0726.Number of Atoms/README_EN.md b/solution/0700-0799/0726.Number of Atoms/README_EN.md index 57f7ef70bcd11..641c1face2c92 100644 --- a/solution/0700-0799/0726.Number of Atoms/README_EN.md +++ b/solution/0700-0799/0726.Number of Atoms/README_EN.md @@ -89,18 +89,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/0700-0799/0727.Minimum Window Subsequence/README.md b/solution/0700-0799/0727.Minimum Window Subsequence/README.md index f3b6a96a230c9..da3875ac1a869 100644 --- a/solution/0700-0799/0727.Minimum Window Subsequence/README.md +++ b/solution/0700-0799/0727.Minimum Window Subsequence/README.md @@ -69,6 +69,8 @@ $$ +#### Python3 + ```python class Solution: def minWindow(self, s1: str, s2: str) -> str: @@ -90,6 +92,8 @@ class Solution: return "" if k > m else s1[p : p + k] ``` +#### Java + ```java class Solution { public String minWindow(String s1, String s2) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func minWindow(s1 string, s2 string) string { m, n := len(s1), len(s2) @@ -187,6 +195,8 @@ func minWindow(s1 string, s2 string) string { } ``` +#### TypeScript + ```ts function minWindow(s1: string, s2: string): string { const m = s1.length; diff --git a/solution/0700-0799/0727.Minimum Window Subsequence/README_EN.md b/solution/0700-0799/0727.Minimum Window Subsequence/README_EN.md index fd6abe2004512..844bccf6cddef 100644 --- a/solution/0700-0799/0727.Minimum Window Subsequence/README_EN.md +++ b/solution/0700-0799/0727.Minimum Window Subsequence/README_EN.md @@ -59,6 +59,8 @@ tags: +#### Python3 + ```python class Solution: def minWindow(self, s1: str, s2: str) -> str: @@ -80,6 +82,8 @@ class Solution: return "" if k > m else s1[p : p + k] ``` +#### Java + ```java class Solution { public String minWindow(String s1, String s2) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func minWindow(s1 string, s2 string) string { m, n := len(s1), len(s2) @@ -177,6 +185,8 @@ func minWindow(s1 string, s2 string) string { } ``` +#### TypeScript + ```ts function minWindow(s1: string, s2: string): string { const m = s1.length; diff --git a/solution/0700-0799/0728.Self Dividing Numbers/README.md b/solution/0700-0799/0728.Self Dividing Numbers/README.md index 6a738d571e4e0..88c682fe4d3af 100644 --- a/solution/0700-0799/0728.Self Dividing Numbers/README.md +++ b/solution/0700-0799/0728.Self Dividing Numbers/README.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def selfDividingNumbers(self, left: int, right: int) -> List[int]: @@ -70,6 +72,8 @@ class Solution: ] ``` +#### Java + ```java class Solution { public List selfDividingNumbers(int left, int right) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func selfDividingNumbers(left int, right int) []int { check := func(num int) bool { @@ -137,6 +145,8 @@ func selfDividingNumbers(left int, right int) []int { } ``` +#### Rust + ```rust impl Solution { pub fn self_dividing_numbers(left: i32, right: i32) -> Vec { diff --git a/solution/0700-0799/0728.Self Dividing Numbers/README_EN.md b/solution/0700-0799/0728.Self Dividing Numbers/README_EN.md index 4b69dad316f78..c110120d19ed1 100644 --- a/solution/0700-0799/0728.Self Dividing Numbers/README_EN.md +++ b/solution/0700-0799/0728.Self Dividing Numbers/README_EN.md @@ -51,6 +51,8 @@ tags: +#### Python3 + ```python class Solution: def selfDividingNumbers(self, left: int, right: int) -> List[int]: @@ -61,6 +63,8 @@ class Solution: ] ``` +#### Java + ```java class Solution { public List selfDividingNumbers(int left, int right) { @@ -85,6 +89,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func selfDividingNumbers(left int, right int) []int { check := func(num int) bool { @@ -128,6 +136,8 @@ func selfDividingNumbers(left int, right int) []int { } ``` +#### Rust + ```rust impl Solution { pub fn self_dividing_numbers(left: i32, right: i32) -> Vec { diff --git a/solution/0700-0799/0729.My Calendar I/README.md b/solution/0700-0799/0729.My Calendar I/README.md index 672e53f4e1335..aa069a1332b1b 100644 --- a/solution/0700-0799/0729.My Calendar I/README.md +++ b/solution/0700-0799/0729.My Calendar I/README.md @@ -68,6 +68,8 @@ myCalendar.book(20, 30); // return True ,这个日程安排可以添加到日 +#### Python3 + ```python from sortedcontainers import SortedDict @@ -89,6 +91,8 @@ class MyCalendar: # param_1 = obj.book(start,end) ``` +#### Java + ```java import java.util.Map; import java.util.TreeMap; @@ -120,6 +124,8 @@ class MyCalendar { */ ``` +#### C++ + ```cpp class MyCalendar { public: @@ -151,6 +157,8 @@ public: */ ``` +#### Go + ```go type MyCalendar struct { rbt *redblacktree.Tree @@ -180,6 +188,8 @@ func (this *MyCalendar) Book(start int, end int) bool { */ ``` +#### TypeScript + ```ts class MyCalendar { private calendar: number[][]; @@ -207,6 +217,8 @@ class MyCalendar { */ ``` +#### Rust + ```rust use std::collections::BTreeMap; diff --git a/solution/0700-0799/0729.My Calendar I/README_EN.md b/solution/0700-0799/0729.My Calendar I/README_EN.md index 6d86824d12d2e..61bb6eee5dac7 100644 --- a/solution/0700-0799/0729.My Calendar I/README_EN.md +++ b/solution/0700-0799/0729.My Calendar I/README_EN.md @@ -66,6 +66,8 @@ myCalendar.book(20, 30); // return True, The event can be booked, as the first e +#### Python3 + ```python from sortedcontainers import SortedDict @@ -87,6 +89,8 @@ class MyCalendar: # param_1 = obj.book(start,end) ``` +#### Java + ```java import java.util.Map; import java.util.TreeMap; @@ -118,6 +122,8 @@ class MyCalendar { */ ``` +#### C++ + ```cpp class MyCalendar { public: @@ -149,6 +155,8 @@ public: */ ``` +#### Go + ```go type MyCalendar struct { rbt *redblacktree.Tree @@ -178,6 +186,8 @@ func (this *MyCalendar) Book(start int, end int) bool { */ ``` +#### TypeScript + ```ts class MyCalendar { private calendar: number[][]; @@ -205,6 +215,8 @@ class MyCalendar { */ ``` +#### Rust + ```rust use std::collections::BTreeMap; diff --git a/solution/0700-0799/0730.Count Different Palindromic Subsequences/README.md b/solution/0700-0799/0730.Count Different Palindromic Subsequences/README.md index 07ce1c375dcbb..96030731fdf1e 100644 --- a/solution/0700-0799/0730.Count Different Palindromic Subsequences/README.md +++ b/solution/0700-0799/0730.Count Different Palindromic Subsequences/README.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def countPalindromicSubsequences(self, s: str) -> int: @@ -87,6 +89,8 @@ class Solution: return sum(dp[0][-1]) % mod ``` +#### Java + ```java class Solution { private final int MOD = (int) 1e9 + 7; @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func countPalindromicSubsequences(s string) int { mod := int(1e9) + 7 diff --git a/solution/0700-0799/0730.Count Different Palindromic Subsequences/README_EN.md b/solution/0700-0799/0730.Count Different Palindromic Subsequences/README_EN.md index 17d8856351f15..e760f06f0ee58 100644 --- a/solution/0700-0799/0730.Count Different Palindromic Subsequences/README_EN.md +++ b/solution/0700-0799/0730.Count Different Palindromic Subsequences/README_EN.md @@ -61,6 +61,8 @@ Note that 'bcb' is counted only once, even though it occurs twice. +#### Python3 + ```python class Solution: def countPalindromicSubsequences(self, s: str) -> int: @@ -85,6 +87,8 @@ class Solution: return sum(dp[0][-1]) % mod ``` +#### Java + ```java class Solution { private final int MOD = (int) 1e9 + 7; @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func countPalindromicSubsequences(s string) int { mod := int(1e9) + 7 diff --git a/solution/0700-0799/0731.My Calendar II/README.md b/solution/0700-0799/0731.My Calendar II/README.md index f914e1b431a9c..cfdfbbe0079cc 100644 --- a/solution/0700-0799/0731.My Calendar II/README.md +++ b/solution/0700-0799/0731.My Calendar II/README.md @@ -71,6 +71,8 @@ MyCalendar.book(25, 55); // returns true +#### Python3 + ```python from sortedcontainers import SortedDict @@ -97,6 +99,8 @@ class MyCalendarTwo: # param_1 = obj.book(start,end) ``` +#### Java + ```java class MyCalendarTwo { private Map tm = new TreeMap<>(); @@ -127,6 +131,8 @@ class MyCalendarTwo { */ ``` +#### C++ + ```cpp class MyCalendarTwo { public: @@ -158,6 +164,8 @@ public: */ ``` +#### Go + ```go type MyCalendarTwo struct { *redblacktree.Tree @@ -223,6 +231,8 @@ func (this *MyCalendarTwo) Book(start int, end int) bool { +#### Python3 + ```python class Node: def __init__(self, l, r): @@ -302,6 +312,8 @@ class MyCalendarTwo: # param_1 = obj.book(start,end) ``` +#### Java + ```java class Node { Node left; @@ -413,6 +425,8 @@ class MyCalendarTwo { */ ``` +#### C++ + ```cpp class Node { public: @@ -513,6 +527,8 @@ public: */ ``` +#### Go + ```go type node struct { left *node diff --git a/solution/0700-0799/0731.My Calendar II/README_EN.md b/solution/0700-0799/0731.My Calendar II/README_EN.md index 887eb8981c36e..b2a41a32fe0b6 100644 --- a/solution/0700-0799/0731.My Calendar II/README_EN.md +++ b/solution/0700-0799/0731.My Calendar II/README_EN.md @@ -70,6 +70,8 @@ myCalendarTwo.book(25, 55); // return True, The event can be booked, as the time +#### Python3 + ```python from sortedcontainers import SortedDict @@ -96,6 +98,8 @@ class MyCalendarTwo: # param_1 = obj.book(start,end) ``` +#### Java + ```java class MyCalendarTwo { private Map tm = new TreeMap<>(); @@ -126,6 +130,8 @@ class MyCalendarTwo { */ ``` +#### C++ + ```cpp class MyCalendarTwo { public: @@ -157,6 +163,8 @@ public: */ ``` +#### Go + ```go type MyCalendarTwo struct { *redblacktree.Tree @@ -206,6 +214,8 @@ func (this *MyCalendarTwo) Book(start int, end int) bool { +#### Python3 + ```python class Node: def __init__(self, l, r): @@ -285,6 +295,8 @@ class MyCalendarTwo: # param_1 = obj.book(start,end) ``` +#### Java + ```java class Node { Node left; @@ -396,6 +408,8 @@ class MyCalendarTwo { */ ``` +#### C++ + ```cpp class Node { public: @@ -496,6 +510,8 @@ public: */ ``` +#### Go + ```go type node struct { left *node diff --git a/solution/0700-0799/0732.My Calendar III/README.md b/solution/0700-0799/0732.My Calendar III/README.md index 63c4df411a202..751d2fe396037 100644 --- a/solution/0700-0799/0732.My Calendar III/README.md +++ b/solution/0700-0799/0732.My Calendar III/README.md @@ -86,6 +86,8 @@ myCalendarThree.book(25, 55); // 返回 3 +#### Python3 + ```python class Node: def __init__(self, l, r): @@ -163,6 +165,8 @@ class MyCalendarThree: # param_1 = obj.book(start,end) ``` +#### Java + ```java class Node { Node left; @@ -271,6 +275,8 @@ class MyCalendarThree { */ ``` +#### C++ + ```cpp class Node { public: @@ -371,6 +377,8 @@ public: */ ``` +#### Go + ```go type node struct { left *node diff --git a/solution/0700-0799/0732.My Calendar III/README_EN.md b/solution/0700-0799/0732.My Calendar III/README_EN.md index 8f07af3873e41..2234dec69656b 100644 --- a/solution/0700-0799/0732.My Calendar III/README_EN.md +++ b/solution/0700-0799/0732.My Calendar III/README_EN.md @@ -69,6 +69,8 @@ myCalendarThree.book(25, 55); // return 3 +#### Python3 + ```python class Node: def __init__(self, l, r): @@ -146,6 +148,8 @@ class MyCalendarThree: # param_1 = obj.book(start,end) ``` +#### Java + ```java class Node { Node left; @@ -254,6 +258,8 @@ class MyCalendarThree { */ ``` +#### C++ + ```cpp class Node { public: @@ -354,6 +360,8 @@ public: */ ``` +#### Go + ```go type node struct { left *node diff --git a/solution/0700-0799/0733.Flood Fill/README.md b/solution/0700-0799/0733.Flood Fill/README.md index e83cc027c7380..795669a4dc2c3 100644 --- a/solution/0700-0799/0733.Flood Fill/README.md +++ b/solution/0700-0799/0733.Flood Fill/README.md @@ -76,6 +76,8 @@ Flood fill 算法是从一个区域中提取若干个连通的点与其他相邻 +#### Python3 + ```python class Solution: def floodFill( @@ -100,6 +102,8 @@ class Solution: return image ``` +#### Java + ```java class Solution { private int[] dirs = {-1, 0, 1, 0, -1}; @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func floodFill(image [][]int, sr int, sc int, color int) [][]int { oc := image[sr][sc] @@ -170,6 +178,8 @@ func floodFill(image [][]int, sr int, sc int, color int) [][]int { } ``` +#### TypeScript + ```ts function floodFill(image: number[][], sr: number, sc: number, newColor: number): number[][] { const m = image.length; @@ -197,6 +207,8 @@ function floodFill(image: number[][], sr: number, sc: number, newColor: number): } ``` +#### Rust + ```rust impl Solution { fn dfs(image: &mut Vec>, sr: i32, sc: i32, new_color: i32, target: i32) { @@ -234,6 +246,8 @@ impl Solution { +#### Python3 + ```python class Solution: def floodFill( @@ -255,6 +269,8 @@ class Solution: return image ``` +#### Java + ```java class Solution { public int[][] floodFill(int[][] image, int sr, int sc, int color) { @@ -283,6 +299,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -310,6 +328,8 @@ public: }; ``` +#### Go + ```go func floodFill(image [][]int, sr int, sc int, color int) [][]int { if image[sr][sc] == color { diff --git a/solution/0700-0799/0733.Flood Fill/README_EN.md b/solution/0700-0799/0733.Flood Fill/README_EN.md index 03968b098f7e5..a2bdb133ce1e0 100644 --- a/solution/0700-0799/0733.Flood Fill/README_EN.md +++ b/solution/0700-0799/0733.Flood Fill/README_EN.md @@ -67,6 +67,8 @@ Note the bottom corner is not colored 2, because it is not 4-directionally conne +#### Python3 + ```python class Solution: def floodFill( @@ -91,6 +93,8 @@ class Solution: return image ``` +#### Java + ```java class Solution { private int[] dirs = {-1, 0, 1, 0, -1}; @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func floodFill(image [][]int, sr int, sc int, color int) [][]int { oc := image[sr][sc] @@ -161,6 +169,8 @@ func floodFill(image [][]int, sr int, sc int, color int) [][]int { } ``` +#### TypeScript + ```ts function floodFill(image: number[][], sr: number, sc: number, newColor: number): number[][] { const m = image.length; @@ -188,6 +198,8 @@ function floodFill(image: number[][], sr: number, sc: number, newColor: number): } ``` +#### Rust + ```rust impl Solution { fn dfs(image: &mut Vec>, sr: i32, sc: i32, new_color: i32, target: i32) { @@ -225,6 +237,8 @@ impl Solution { +#### Python3 + ```python class Solution: def floodFill( @@ -246,6 +260,8 @@ class Solution: return image ``` +#### Java + ```java class Solution { public int[][] floodFill(int[][] image, int sr, int sc, int color) { @@ -274,6 +290,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -301,6 +319,8 @@ public: }; ``` +#### Go + ```go func floodFill(image [][]int, sr int, sc int, color int) [][]int { if image[sr][sc] == color { diff --git a/solution/0700-0799/0734.Sentence Similarity/README.md b/solution/0700-0799/0734.Sentence Similarity/README.md index ef0366946447e..3b4e81a365722 100644 --- a/solution/0700-0799/0734.Sentence Similarity/README.md +++ b/solution/0700-0799/0734.Sentence Similarity/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def areSentencesSimilar( @@ -95,6 +97,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public boolean areSentencesSimilar( @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func areSentencesSimilar(sentence1 []string, sentence2 []string, similarPairs [][]string) bool { if len(sentence1) != len(sentence2) { diff --git a/solution/0700-0799/0734.Sentence Similarity/README_EN.md b/solution/0700-0799/0734.Sentence Similarity/README_EN.md index b4b1e930696be..103b71f1f898b 100644 --- a/solution/0700-0799/0734.Sentence Similarity/README_EN.md +++ b/solution/0700-0799/0734.Sentence Similarity/README_EN.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def areSentencesSimilar( @@ -95,6 +97,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public boolean areSentencesSimilar( @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func areSentencesSimilar(sentence1 []string, sentence2 []string, similarPairs [][]string) bool { if len(sentence1) != len(sentence2) { diff --git a/solution/0700-0799/0735.Asteroid Collision/README.md b/solution/0700-0799/0735.Asteroid Collision/README.md index 2a6238f415130..77ce18a38fe78 100644 --- a/solution/0700-0799/0735.Asteroid Collision/README.md +++ b/solution/0700-0799/0735.Asteroid Collision/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def asteroidCollision(self, asteroids: List[int]) -> List[int]: @@ -93,6 +95,8 @@ class Solution: return stk ``` +#### Java + ```java class Solution { public int[] asteroidCollision(int[] asteroids) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func asteroidCollision(asteroids []int) (stk []int) { for _, x := range asteroids { @@ -160,6 +168,8 @@ func asteroidCollision(asteroids []int) (stk []int) { } ``` +#### TypeScript + ```ts function asteroidCollision(asteroids: number[]): number[] { const stk: number[] = []; @@ -181,6 +191,8 @@ function asteroidCollision(asteroids: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/0700-0799/0735.Asteroid Collision/README_EN.md b/solution/0700-0799/0735.Asteroid Collision/README_EN.md index 8b1324f976f1e..e3baa97cce2ab 100644 --- a/solution/0700-0799/0735.Asteroid Collision/README_EN.md +++ b/solution/0700-0799/0735.Asteroid Collision/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def asteroidCollision(self, asteroids: List[int]) -> List[int]: @@ -94,6 +96,8 @@ class Solution: return stk ``` +#### Java + ```java class Solution { public int[] asteroidCollision(int[] asteroids) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func asteroidCollision(asteroids []int) (stk []int) { for _, x := range asteroids { @@ -161,6 +169,8 @@ func asteroidCollision(asteroids []int) (stk []int) { } ``` +#### TypeScript + ```ts function asteroidCollision(asteroids: number[]): number[] { const stk: number[] = []; @@ -182,6 +192,8 @@ function asteroidCollision(asteroids: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/0700-0799/0736.Parse Lisp Expression/README.md b/solution/0700-0799/0736.Parse Lisp Expression/README.md index 421daf51f4109..1fa277a282b78 100644 --- a/solution/0700-0799/0736.Parse Lisp Expression/README.md +++ b/solution/0700-0799/0736.Parse Lisp Expression/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def evaluate(self, expression: str) -> int: @@ -145,6 +147,8 @@ class Solution: return eval() ``` +#### Java + ```java class Solution { private int i; @@ -221,6 +225,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -289,6 +295,8 @@ public: }; ``` +#### Go + ```go func evaluate(expression string) int { i, n := 0, len(expression) diff --git a/solution/0700-0799/0736.Parse Lisp Expression/README_EN.md b/solution/0700-0799/0736.Parse Lisp Expression/README_EN.md index 272d87f2918db..93c08e0daee56 100644 --- a/solution/0700-0799/0736.Parse Lisp Expression/README_EN.md +++ b/solution/0700-0799/0736.Parse Lisp Expression/README_EN.md @@ -82,6 +82,8 @@ The second (add x y) evaluates as 3+2 = 5. +#### Python3 + ```python class Solution: def evaluate(self, expression: str) -> int: @@ -140,6 +142,8 @@ class Solution: return eval() ``` +#### Java + ```java class Solution { private int i; @@ -216,6 +220,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -284,6 +290,8 @@ public: }; ``` +#### Go + ```go func evaluate(expression string) int { i, n := 0, len(expression) diff --git a/solution/0700-0799/0737.Sentence Similarity II/README.md b/solution/0700-0799/0737.Sentence Similarity II/README.md index aae83c0ce8d98..cdcff4c75a678 100644 --- a/solution/0700-0799/0737.Sentence Similarity II/README.md +++ b/solution/0700-0799/0737.Sentence Similarity II/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def areSentencesSimilarTwo( @@ -124,6 +126,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { private int[] p; @@ -171,6 +175,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -209,6 +215,8 @@ public: }; ``` +#### Go + ```go var p []int diff --git a/solution/0700-0799/0737.Sentence Similarity II/README_EN.md b/solution/0700-0799/0737.Sentence Similarity II/README_EN.md index d4f502d29cb1f..df8713ef75673 100644 --- a/solution/0700-0799/0737.Sentence Similarity II/README_EN.md +++ b/solution/0700-0799/0737.Sentence Similarity II/README_EN.md @@ -84,6 +84,8 @@ Since "leetcode is similar to "onepiece" and the first two words +#### Python3 + ```python class Solution: def areSentencesSimilarTwo( @@ -122,6 +124,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { private int[] p; @@ -169,6 +173,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -207,6 +213,8 @@ public: }; ``` +#### Go + ```go var p []int diff --git a/solution/0700-0799/0738.Monotone Increasing Digits/README.md b/solution/0700-0799/0738.Monotone Increasing Digits/README.md index b0ebdd40416cd..539c0d75d085e 100644 --- a/solution/0700-0799/0738.Monotone Increasing Digits/README.md +++ b/solution/0700-0799/0738.Monotone Increasing Digits/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def monotoneIncreasingDigits(self, n: int) -> int: @@ -88,6 +90,8 @@ class Solution: return int(''.join(s)) ``` +#### Java + ```java class Solution { public int monotoneIncreasingDigits(int n) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func monotoneIncreasingDigits(n int) int { s := []byte(strconv.Itoa(n)) diff --git a/solution/0700-0799/0738.Monotone Increasing Digits/README_EN.md b/solution/0700-0799/0738.Monotone Increasing Digits/README_EN.md index 0df8f8ee470ee..26f2defd2ab42 100644 --- a/solution/0700-0799/0738.Monotone Increasing Digits/README_EN.md +++ b/solution/0700-0799/0738.Monotone Increasing Digits/README_EN.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def monotoneIncreasingDigits(self, n: int) -> int: @@ -78,6 +80,8 @@ class Solution: return int(''.join(s)) ``` +#### Java + ```java class Solution { public int monotoneIncreasingDigits(int n) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func monotoneIncreasingDigits(n int) int { s := []byte(strconv.Itoa(n)) diff --git a/solution/0700-0799/0739.Daily Temperatures/README.md b/solution/0700-0799/0739.Daily Temperatures/README.md index 71bdcce03620b..6c609aa713a4b 100644 --- a/solution/0700-0799/0739.Daily Temperatures/README.md +++ b/solution/0700-0799/0739.Daily Temperatures/README.md @@ -77,6 +77,8 @@ for i in range(n): +#### Python3 + ```python class Solution: def dailyTemperatures(self, temperatures: List[int]) -> List[int]: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] dailyTemperatures(int[] temperatures) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func dailyTemperatures(temperatures []int) []int { ans := make([]int, len(temperatures)) @@ -143,6 +151,8 @@ func dailyTemperatures(temperatures []int) []int { } ``` +#### TypeScript + ```ts function dailyTemperatures(temperatures: number[]): number[] { const n = temperatures.length; @@ -161,6 +171,8 @@ function dailyTemperatures(temperatures: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn daily_temperatures(temperatures: Vec) -> Vec { @@ -179,6 +191,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} temperatures @@ -211,6 +225,8 @@ var dailyTemperatures = function (temperatures) { +#### Python3 + ```python class Solution: def dailyTemperatures(self, temperatures: List[int]) -> List[int]: @@ -226,6 +242,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] dailyTemperatures(int[] temperatures) { @@ -246,6 +264,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -263,6 +283,8 @@ public: }; ``` +#### Go + ```go func dailyTemperatures(temperatures []int) []int { n := len(temperatures) diff --git a/solution/0700-0799/0739.Daily Temperatures/README_EN.md b/solution/0700-0799/0739.Daily Temperatures/README_EN.md index dde5741c4d315..c6cea8007e95e 100644 --- a/solution/0700-0799/0739.Daily Temperatures/README_EN.md +++ b/solution/0700-0799/0739.Daily Temperatures/README_EN.md @@ -49,6 +49,8 @@ tags: +#### Python3 + ```python class Solution: def dailyTemperatures(self, temperatures: List[int]) -> List[int]: @@ -62,6 +64,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] dailyTemperatures(int[] temperatures) { @@ -80,6 +84,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -99,6 +105,8 @@ public: }; ``` +#### Go + ```go func dailyTemperatures(temperatures []int) []int { ans := make([]int, len(temperatures)) @@ -115,6 +123,8 @@ func dailyTemperatures(temperatures []int) []int { } ``` +#### TypeScript + ```ts function dailyTemperatures(temperatures: number[]): number[] { const n = temperatures.length; @@ -133,6 +143,8 @@ function dailyTemperatures(temperatures: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn daily_temperatures(temperatures: Vec) -> Vec { @@ -151,6 +163,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} temperatures @@ -183,6 +197,8 @@ var dailyTemperatures = function (temperatures) { +#### Python3 + ```python class Solution: def dailyTemperatures(self, temperatures: List[int]) -> List[int]: @@ -198,6 +214,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] dailyTemperatures(int[] temperatures) { @@ -218,6 +236,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -235,6 +255,8 @@ public: }; ``` +#### Go + ```go func dailyTemperatures(temperatures []int) []int { n := len(temperatures) diff --git a/solution/0700-0799/0740.Delete and Earn/README.md b/solution/0700-0799/0740.Delete and Earn/README.md index f40694bab100d..174b6fb91878f 100644 --- a/solution/0700-0799/0740.Delete and Earn/README.md +++ b/solution/0700-0799/0740.Delete and Earn/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def deleteAndEarn(self, nums: List[int]) -> int: @@ -84,6 +86,8 @@ class Solution: return second ``` +#### Java + ```java class Solution { public int deleteAndEarn(int[] nums) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func deleteAndEarn(nums []int) int { diff --git a/solution/0700-0799/0740.Delete and Earn/README_EN.md b/solution/0700-0799/0740.Delete and Earn/README_EN.md index 92ddb31d473e2..aaa5a8a2fc0d7 100644 --- a/solution/0700-0799/0740.Delete and Earn/README_EN.md +++ b/solution/0700-0799/0740.Delete and Earn/README_EN.md @@ -67,6 +67,8 @@ You earn a total of 9 points. +#### Python3 + ```python class Solution: def deleteAndEarn(self, nums: List[int]) -> int: @@ -85,6 +87,8 @@ class Solution: return second ``` +#### Java + ```java class Solution { public int deleteAndEarn(int[] nums) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func deleteAndEarn(nums []int) int { diff --git a/solution/0700-0799/0741.Cherry Pickup/README.md b/solution/0700-0799/0741.Cherry Pickup/README.md index d34926fd666c6..0bff316501c6f 100644 --- a/solution/0700-0799/0741.Cherry Pickup/README.md +++ b/solution/0700-0799/0741.Cherry Pickup/README.md @@ -92,6 +92,8 @@ $$ +#### Python3 + ```python class Solution: def cherryPickup(self, grid: List[List[int]]) -> int: @@ -119,6 +121,8 @@ class Solution: return max(0, f[-1][-1][-1]) ``` +#### Java + ```java class Solution { public int cherryPickup(int[][] grid) { @@ -153,6 +157,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go func cherryPickup(grid [][]int) int { n := len(grid) @@ -223,6 +231,8 @@ func cherryPickup(grid [][]int) int { } ``` +#### TypeScript + ```ts function cherryPickup(grid: number[][]): number { const n: number = grid.length; @@ -259,6 +269,8 @@ function cherryPickup(grid: number[][]): number { } ``` +#### JavaScript + ```js /** * @param {number[][]} grid diff --git a/solution/0700-0799/0741.Cherry Pickup/README_EN.md b/solution/0700-0799/0741.Cherry Pickup/README_EN.md index ab0daf7624842..ba067707a319c 100644 --- a/solution/0700-0799/0741.Cherry Pickup/README_EN.md +++ b/solution/0700-0799/0741.Cherry Pickup/README_EN.md @@ -90,6 +90,8 @@ The time complexity is $O(n^3)$, and the space complexity is $O(n^3)$. Where $n$ +#### Python3 + ```python class Solution: def cherryPickup(self, grid: List[List[int]]) -> int: @@ -117,6 +119,8 @@ class Solution: return max(0, f[-1][-1][-1]) ``` +#### Java + ```java class Solution { public int cherryPickup(int[][] grid) { @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -184,6 +190,8 @@ public: }; ``` +#### Go + ```go func cherryPickup(grid [][]int) int { n := len(grid) @@ -221,6 +229,8 @@ func cherryPickup(grid [][]int) int { } ``` +#### TypeScript + ```ts function cherryPickup(grid: number[][]): number { const n: number = grid.length; @@ -257,6 +267,8 @@ function cherryPickup(grid: number[][]): number { } ``` +#### JavaScript + ```js /** * @param {number[][]} grid diff --git a/solution/0700-0799/0742.Closest Leaf in a Binary Tree/README.md b/solution/0700-0799/0742.Closest Leaf in a Binary Tree/README.md index 760b3a818289a..8e72074ea87a1 100644 --- a/solution/0700-0799/0742.Closest Leaf in a Binary Tree/README.md +++ b/solution/0700-0799/0742.Closest Leaf in a Binary Tree/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -111,6 +113,8 @@ class Solution: q.append(nxt) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -167,6 +171,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -220,6 +226,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0700-0799/0742.Closest Leaf in a Binary Tree/README_EN.md b/solution/0700-0799/0742.Closest Leaf in a Binary Tree/README_EN.md index 5e456b0e6b7b4..c16a27ab3535b 100644 --- a/solution/0700-0799/0742.Closest Leaf in a Binary Tree/README_EN.md +++ b/solution/0700-0799/0742.Closest Leaf in a Binary Tree/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -103,6 +105,8 @@ class Solution: q.append(nxt) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -159,6 +163,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -212,6 +218,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0700-0799/0743.Network Delay Time/README.md b/solution/0700-0799/0743.Network Delay Time/README.md index 2e3f64ff7c42f..3590db1d02302 100644 --- a/solution/0700-0799/0743.Network Delay Time/README.md +++ b/solution/0700-0799/0743.Network Delay Time/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def networkDelayTime(self, times: List[List[int]], n: int, k: int) -> int: @@ -99,6 +101,8 @@ class Solution: return -1 if ans == INF else ans ``` +#### Java + ```java class Solution { private static final int INF = 0x3f3f; @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func networkDelayTime(times [][]int, n int, k int) int { const inf = 0x3f3f @@ -214,6 +222,8 @@ func networkDelayTime(times [][]int, n int, k int) int { +#### Python3 + ```python class Solution: def networkDelayTime(self, times: List[List[int]], n: int, k: int) -> int: @@ -234,6 +244,8 @@ class Solution: return -1 if ans == INF else ans ``` +#### Java + ```java class Solution { private static final int INF = 0x3f3f; @@ -271,6 +283,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -301,6 +315,8 @@ public: }; ``` +#### Go + ```go const Inf = 0x3f3f3f3f @@ -371,6 +387,8 @@ func networkDelayTime(times [][]int, n int, k int) int { +#### Python3 + ```python class Solution: def networkDelayTime(self, times: List[List[int]], n: int, k: int) -> int: @@ -385,6 +403,8 @@ class Solution: return -1 if ans == INF else ans ``` +#### Java + ```java class Solution { private static final int INF = 0x3f3f; @@ -410,6 +430,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -431,6 +453,8 @@ public: }; ``` +#### Go + ```go func networkDelayTime(times [][]int, n int, k int) int { const inf = 0x3f3f @@ -465,6 +489,8 @@ func networkDelayTime(times [][]int, n int, k int) int { +#### Python3 + ```python class Solution: def networkDelayTime(self, times: List[List[int]], n: int, k: int) -> int: @@ -491,6 +517,8 @@ class Solution: return -1 if ans == INF else ans ``` +#### Java + ```java class Solution { private static final int INF = 0x3f3f; @@ -535,6 +563,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -573,6 +603,8 @@ public: }; ``` +#### Go + ```go func networkDelayTime(times [][]int, n int, k int) int { const inf = 0x3f3f diff --git a/solution/0700-0799/0743.Network Delay Time/README_EN.md b/solution/0700-0799/0743.Network Delay Time/README_EN.md index 39f6663bbc8be..7b3c47657d4e5 100644 --- a/solution/0700-0799/0743.Network Delay Time/README_EN.md +++ b/solution/0700-0799/0743.Network Delay Time/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def networkDelayTime(self, times: List[List[int]], n: int, k: int) -> int: @@ -91,6 +93,8 @@ class Solution: return -1 if ans == INF else ans ``` +#### Java + ```java class Solution { private static final int INF = 0x3f3f; @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func networkDelayTime(times [][]int, n int, k int) int { const inf = 0x3f3f @@ -204,6 +212,8 @@ func networkDelayTime(times [][]int, n int, k int) int { +#### Python3 + ```python class Solution: def networkDelayTime(self, times: List[List[int]], n: int, k: int) -> int: @@ -224,6 +234,8 @@ class Solution: return -1 if ans == INF else ans ``` +#### Java + ```java class Solution { private static final int INF = 0x3f3f; @@ -261,6 +273,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -291,6 +305,8 @@ public: }; ``` +#### Go + ```go const Inf = 0x3f3f3f3f @@ -359,6 +375,8 @@ func networkDelayTime(times [][]int, n int, k int) int { +#### Python3 + ```python class Solution: def networkDelayTime(self, times: List[List[int]], n: int, k: int) -> int: @@ -373,6 +391,8 @@ class Solution: return -1 if ans == INF else ans ``` +#### Java + ```java class Solution { private static final int INF = 0x3f3f; @@ -398,6 +418,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -419,6 +441,8 @@ public: }; ``` +#### Go + ```go func networkDelayTime(times [][]int, n int, k int) int { const inf = 0x3f3f @@ -453,6 +477,8 @@ func networkDelayTime(times [][]int, n int, k int) int { +#### Python3 + ```python class Solution: def networkDelayTime(self, times: List[List[int]], n: int, k: int) -> int: @@ -479,6 +505,8 @@ class Solution: return -1 if ans == INF else ans ``` +#### Java + ```java class Solution { private static final int INF = 0x3f3f; @@ -523,6 +551,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -561,6 +591,8 @@ public: }; ``` +#### Go + ```go func networkDelayTime(times [][]int, n int, k int) int { const inf = 0x3f3f diff --git a/solution/0700-0799/0744.Find Smallest Letter Greater Than Target/README.md b/solution/0700-0799/0744.Find Smallest Letter Greater Than Target/README.md index 5609e48d0fed4..2102e01230162 100644 --- a/solution/0700-0799/0744.Find Smallest Letter Greater Than Target/README.md +++ b/solution/0700-0799/0744.Find Smallest Letter Greater Than Target/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def nextGreatestLetter(self, letters: List[str], target: str) -> str: @@ -81,6 +83,8 @@ class Solution: return letters[i % len(letters)] ``` +#### Java + ```java class Solution { public char nextGreatestLetter(char[] letters, char target) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,6 +107,8 @@ public: }; ``` +#### Go + ```go func nextGreatestLetter(letters []byte, target byte) byte { i := sort.Search(len(letters), func(i int) bool { return letters[i] > target }) @@ -108,6 +116,8 @@ func nextGreatestLetter(letters []byte, target byte) byte { } ``` +#### TypeScript + ```ts function nextGreatestLetter(letters: string[], target: string): string { let [l, r] = [0, letters.length]; @@ -123,6 +133,8 @@ function nextGreatestLetter(letters: string[], target: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn next_greatest_letter(letters: Vec, target: char) -> char { @@ -141,6 +153,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0700-0799/0744.Find Smallest Letter Greater Than Target/README_EN.md b/solution/0700-0799/0744.Find Smallest Letter Greater Than Target/README_EN.md index 59d3850cebb97..dcf32c88a0947 100644 --- a/solution/0700-0799/0744.Find Smallest Letter Greater Than Target/README_EN.md +++ b/solution/0700-0799/0744.Find Smallest Letter Greater Than Target/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(\log n)$, where $n$ is the length of `letters`. The sp +#### Python3 + ```python class Solution: def nextGreatestLetter(self, letters: List[str], target: str) -> str: @@ -82,6 +84,8 @@ class Solution: return letters[i % len(letters)] ``` +#### Java + ```java class Solution { public char nextGreatestLetter(char[] letters, char target) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -102,6 +108,8 @@ public: }; ``` +#### Go + ```go func nextGreatestLetter(letters []byte, target byte) byte { i := sort.Search(len(letters), func(i int) bool { return letters[i] > target }) @@ -109,6 +117,8 @@ func nextGreatestLetter(letters []byte, target byte) byte { } ``` +#### TypeScript + ```ts function nextGreatestLetter(letters: string[], target: string): string { let [l, r] = [0, letters.length]; @@ -124,6 +134,8 @@ function nextGreatestLetter(letters: string[], target: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn next_greatest_letter(letters: Vec, target: char) -> char { @@ -142,6 +154,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0700-0799/0745.Prefix and Suffix Search/README.md b/solution/0700-0799/0745.Prefix and Suffix Search/README.md index 1e72294a2dc37..25b3a0d97f2f8 100644 --- a/solution/0700-0799/0745.Prefix and Suffix Search/README.md +++ b/solution/0700-0799/0745.Prefix and Suffix Search/README.md @@ -68,6 +68,8 @@ wordFilter.f("a", "e"); // 返回 0 ,因为下标为 0 的单词:前缀 pref +#### Python3 + ```python class WordFilter: def __init__(self, words: List[str]): @@ -89,6 +91,8 @@ class WordFilter: # param_1 = obj.f(pref,suff) ``` +#### Java + ```java class WordFilter { private Map d = new HashMap<>(); @@ -119,6 +123,8 @@ class WordFilter { */ ``` +#### C++ + ```cpp class WordFilter { public: @@ -152,6 +158,8 @@ public: */ ``` +#### Go + ```go type WordFilter struct { d map[string]int @@ -196,6 +204,8 @@ func (this *WordFilter) F(pref string, suff string) int { +#### Python3 + ```python class Trie: def __init__(self): @@ -250,6 +260,8 @@ class WordFilter: # param_1 = obj.f(pref,suff) ``` +#### Java + ```java class Trie { Trie[] children = new Trie[26]; @@ -322,6 +334,8 @@ class WordFilter { */ ``` +#### Go + ```go type Trie struct { children [26]*Trie diff --git a/solution/0700-0799/0745.Prefix and Suffix Search/README_EN.md b/solution/0700-0799/0745.Prefix and Suffix Search/README_EN.md index 1e05781e31124..b8c26a1c0f00c 100644 --- a/solution/0700-0799/0745.Prefix and Suffix Search/README_EN.md +++ b/solution/0700-0799/0745.Prefix and Suffix Search/README_EN.md @@ -64,6 +64,8 @@ wordFilter.f("a", "e"); // return 0, because the word at ind +#### Python3 + ```python class WordFilter: def __init__(self, words: List[str]): @@ -85,6 +87,8 @@ class WordFilter: # param_1 = obj.f(pref,suff) ``` +#### Java + ```java class WordFilter { private Map d = new HashMap<>(); @@ -115,6 +119,8 @@ class WordFilter { */ ``` +#### C++ + ```cpp class WordFilter { public: @@ -148,6 +154,8 @@ public: */ ``` +#### Go + ```go type WordFilter struct { d map[string]int @@ -192,6 +200,8 @@ func (this *WordFilter) F(pref string, suff string) int { +#### Python3 + ```python class Trie: def __init__(self): @@ -246,6 +256,8 @@ class WordFilter: # param_1 = obj.f(pref,suff) ``` +#### Java + ```java class Trie { Trie[] children = new Trie[26]; @@ -318,6 +330,8 @@ class WordFilter { */ ``` +#### Go + ```go type Trie struct { children [26]*Trie diff --git a/solution/0700-0799/0746.Min Cost Climbing Stairs/README.md b/solution/0700-0799/0746.Min Cost Climbing Stairs/README.md index be7dc90ab98d6..26266f0960f81 100644 --- a/solution/0700-0799/0746.Min Cost Climbing Stairs/README.md +++ b/solution/0700-0799/0746.Min Cost Climbing Stairs/README.md @@ -83,6 +83,8 @@ $$ +#### Python3 + ```python class Solution: def minCostClimbingStairs(self, cost: List[int]) -> int: @@ -93,6 +95,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int minCostClimbingStairs(int[] cost) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func minCostClimbingStairs(cost []int) int { n := len(cost) @@ -131,6 +139,8 @@ func minCostClimbingStairs(cost []int) int { } ``` +#### TypeScript + ```ts function minCostClimbingStairs(cost: number[]): number { const n = cost.length; @@ -142,6 +152,8 @@ function minCostClimbingStairs(cost: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_cost_climbing_stairs(cost: Vec) -> i32 { @@ -165,6 +177,8 @@ impl Solution { +#### Python3 + ```python class Solution: def minCostClimbingStairs(self, cost: List[int]) -> int: @@ -174,6 +188,8 @@ class Solution: return g ``` +#### Java + ```java class Solution { public int minCostClimbingStairs(int[] cost) { @@ -188,6 +204,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -203,6 +221,8 @@ public: }; ``` +#### Go + ```go func minCostClimbingStairs(cost []int) int { var f, g int @@ -213,6 +233,8 @@ func minCostClimbingStairs(cost []int) int { } ``` +#### TypeScript + ```ts function minCostClimbingStairs(cost: number[]): number { let a = 0, @@ -224,6 +246,8 @@ function minCostClimbingStairs(cost: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_cost_climbing_stairs(cost: Vec) -> i32 { diff --git a/solution/0700-0799/0746.Min Cost Climbing Stairs/README_EN.md b/solution/0700-0799/0746.Min Cost Climbing Stairs/README_EN.md index 4834ca570ee4a..fb3ea3a8a0f35 100644 --- a/solution/0700-0799/0746.Min Cost Climbing Stairs/README_EN.md +++ b/solution/0700-0799/0746.Min Cost Climbing Stairs/README_EN.md @@ -81,6 +81,8 @@ We notice that $f[i]$ in the state transition equation is only related to $f[i - +#### Python3 + ```python class Solution: def minCostClimbingStairs(self, cost: List[int]) -> int: @@ -91,6 +93,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int minCostClimbingStairs(int[] cost) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func minCostClimbingStairs(cost []int) int { n := len(cost) @@ -129,6 +137,8 @@ func minCostClimbingStairs(cost []int) int { } ``` +#### TypeScript + ```ts function minCostClimbingStairs(cost: number[]): number { const n = cost.length; @@ -140,6 +150,8 @@ function minCostClimbingStairs(cost: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_cost_climbing_stairs(cost: Vec) -> i32 { @@ -163,6 +175,8 @@ impl Solution { +#### Python3 + ```python class Solution: def minCostClimbingStairs(self, cost: List[int]) -> int: @@ -172,6 +186,8 @@ class Solution: return g ``` +#### Java + ```java class Solution { public int minCostClimbingStairs(int[] cost) { @@ -186,6 +202,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -201,6 +219,8 @@ public: }; ``` +#### Go + ```go func minCostClimbingStairs(cost []int) int { var f, g int @@ -211,6 +231,8 @@ func minCostClimbingStairs(cost []int) int { } ``` +#### TypeScript + ```ts function minCostClimbingStairs(cost: number[]): number { let a = 0, @@ -222,6 +244,8 @@ function minCostClimbingStairs(cost: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_cost_climbing_stairs(cost: Vec) -> i32 { diff --git a/solution/0700-0799/0747.Largest Number At Least Twice of Others/README.md b/solution/0700-0799/0747.Largest Number At Least Twice of Others/README.md index cb23c6c5907d3..8ebcc2f2fe5a0 100644 --- a/solution/0700-0799/0747.Largest Number At Least Twice of Others/README.md +++ b/solution/0700-0799/0747.Largest Number At Least Twice of Others/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def dominantIndex(self, nums: List[int]) -> int: @@ -72,6 +74,8 @@ class Solution: return nums.index(x) if x >= 2 * y else -1 ``` +#### Java + ```java class Solution { public int dominantIndex(int[] nums) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func dominantIndex(nums []int) int { k := 0 @@ -130,6 +138,8 @@ func dominantIndex(nums []int) int { } ``` +#### TypeScript + ```ts function dominantIndex(nums: number[]): number { let k = 0; @@ -147,6 +157,8 @@ function dominantIndex(nums: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0700-0799/0747.Largest Number At Least Twice of Others/README_EN.md b/solution/0700-0799/0747.Largest Number At Least Twice of Others/README_EN.md index b67c9682eca72..9caf3796cc67a 100644 --- a/solution/0700-0799/0747.Largest Number At Least Twice of Others/README_EN.md +++ b/solution/0700-0799/0747.Largest Number At Least Twice of Others/README_EN.md @@ -65,6 +65,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def dominantIndex(self, nums: List[int]) -> int: @@ -72,6 +74,8 @@ class Solution: return nums.index(x) if x >= 2 * y else -1 ``` +#### Java + ```java class Solution { public int dominantIndex(int[] nums) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func dominantIndex(nums []int) int { k := 0 @@ -130,6 +138,8 @@ func dominantIndex(nums []int) int { } ``` +#### TypeScript + ```ts function dominantIndex(nums: number[]): number { let k = 0; @@ -147,6 +157,8 @@ function dominantIndex(nums: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0700-0799/0748.Shortest Completing Word/README.md b/solution/0700-0799/0748.Shortest Completing Word/README.md index f117874297714..3fb38916a3269 100644 --- a/solution/0700-0799/0748.Shortest Completing Word/README.md +++ b/solution/0700-0799/0748.Shortest Completing Word/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def shortestCompletingWord(self, licensePlate: str, words: List[str]) -> str: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String shortestCompletingWord(String licensePlate, String[] words) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func shortestCompletingWord(licensePlate string, words []string) (ans string) { cnt := [26]int{} @@ -191,6 +199,8 @@ func shortestCompletingWord(licensePlate string, words []string) (ans string) { } ``` +#### TypeScript + ```ts function shortestCompletingWord(licensePlate: string, words: string[]): string { const cnt: number[] = Array(26).fill(0); @@ -224,6 +234,8 @@ function shortestCompletingWord(licensePlate: string, words: string[]): string { } ``` +#### Rust + ```rust impl Solution { pub fn shortest_completing_word(license_plate: String, words: Vec) -> String { diff --git a/solution/0700-0799/0748.Shortest Completing Word/README_EN.md b/solution/0700-0799/0748.Shortest Completing Word/README_EN.md index 39ecd30b4b7d8..73f54b112f8a4 100644 --- a/solution/0700-0799/0748.Shortest Completing Word/README_EN.md +++ b/solution/0700-0799/0748.Shortest Completing Word/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(n \times |\Sigma|)$, and the space complexity is $O(|\ +#### Python3 + ```python class Solution: def shortestCompletingWord(self, licensePlate: str, words: List[str]) -> str: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String shortestCompletingWord(String licensePlate, String[] words) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func shortestCompletingWord(licensePlate string, words []string) (ans string) { cnt := [26]int{} @@ -190,6 +198,8 @@ func shortestCompletingWord(licensePlate string, words []string) (ans string) { } ``` +#### TypeScript + ```ts function shortestCompletingWord(licensePlate: string, words: string[]): string { const cnt: number[] = Array(26).fill(0); @@ -223,6 +233,8 @@ function shortestCompletingWord(licensePlate: string, words: string[]): string { } ``` +#### Rust + ```rust impl Solution { pub fn shortest_completing_word(license_plate: String, words: Vec) -> String { diff --git a/solution/0700-0799/0749.Contain Virus/README.md b/solution/0700-0799/0749.Contain Virus/README.md index 1af9daa692b98..9fe3e49f6cc05 100644 --- a/solution/0700-0799/0749.Contain Virus/README.md +++ b/solution/0700-0799/0749.Contain Virus/README.md @@ -93,6 +93,8 @@ DFS 找到每个病毒区域 `areas[i]`,同时记录每个区域边界节点 ` +#### Python3 + ```python class Solution: def containVirus(self, isInfected: List[List[int]]) -> int: @@ -139,6 +141,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int[] DIRS = {-1, 0, 1, 0, -1}; @@ -232,6 +236,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -320,6 +326,8 @@ public: }; ``` +#### Go + ```go func containVirus(isInfected [][]int) int { m, n := len(isInfected), len(isInfected[0]) diff --git a/solution/0700-0799/0749.Contain Virus/README_EN.md b/solution/0700-0799/0749.Contain Virus/README_EN.md index 83083f4afc57c..6eb9ff5155ad9 100644 --- a/solution/0700-0799/0749.Contain Virus/README_EN.md +++ b/solution/0700-0799/0749.Contain Virus/README_EN.md @@ -79,6 +79,8 @@ Notice that walls are only built on the shared boundary of two different cells. +#### Python3 + ```python class Solution: def containVirus(self, isInfected: List[List[int]]) -> int: @@ -125,6 +127,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int[] DIRS = {-1, 0, 1, 0, -1}; @@ -218,6 +222,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -306,6 +312,8 @@ public: }; ``` +#### Go + ```go func containVirus(isInfected [][]int) int { m, n := len(isInfected), len(isInfected[0]) diff --git a/solution/0700-0799/0750.Number Of Corner Rectangles/README.md b/solution/0700-0799/0750.Number Of Corner Rectangles/README.md index 6f0be71e54904..466e2989dc9f6 100644 --- a/solution/0700-0799/0750.Number Of Corner Rectangles/README.md +++ b/solution/0700-0799/0750.Number Of Corner Rectangles/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def countCornerRectangles(self, grid: List[List[int]]) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countCornerRectangles(int[][] grid) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func countCornerRectangles(grid [][]int) (ans int) { n := len(grid[0]) @@ -169,6 +177,8 @@ func countCornerRectangles(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function countCornerRectangles(grid: number[][]): number { const n = grid[0].length; diff --git a/solution/0700-0799/0750.Number Of Corner Rectangles/README_EN.md b/solution/0700-0799/0750.Number Of Corner Rectangles/README_EN.md index 70fce58bad1ba..da7abc194f79c 100644 --- a/solution/0700-0799/0750.Number Of Corner Rectangles/README_EN.md +++ b/solution/0700-0799/0750.Number Of Corner Rectangles/README_EN.md @@ -73,6 +73,8 @@ The time complexity is $O(m \times n^2)$, and the space complexity is $O(n^2)$. +#### Python3 + ```python class Solution: def countCornerRectangles(self, grid: List[List[int]]) -> int: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countCornerRectangles(int[][] grid) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func countCornerRectangles(grid [][]int) (ans int) { n := len(grid[0]) @@ -159,6 +167,8 @@ func countCornerRectangles(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function countCornerRectangles(grid: number[][]): number { const n = grid[0].length; diff --git a/solution/0700-0799/0751.IP to CIDR/README.md b/solution/0700-0799/0751.IP to CIDR/README.md index 80806be7e3c17..a5b06d5614471 100644 --- a/solution/0700-0799/0751.IP to CIDR/README.md +++ b/solution/0700-0799/0751.IP to CIDR/README.md @@ -86,18 +86,26 @@ CIDR区块“255.0.0.16/32”包含最后一个地址。 +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/0700-0799/0751.IP to CIDR/README_EN.md b/solution/0700-0799/0751.IP to CIDR/README_EN.md index e130b64224a2f..80e9babefdfd5 100644 --- a/solution/0700-0799/0751.IP to CIDR/README_EN.md +++ b/solution/0700-0799/0751.IP to CIDR/README_EN.md @@ -84,18 +84,26 @@ Note that while the CIDR block "255.0.0.0/28" does cover all the addre +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/0700-0799/0752.Open the Lock/README.md b/solution/0700-0799/0752.Open the Lock/README.md index 7ca7eb1c11f80..767954e151497 100644 --- a/solution/0700-0799/0752.Open the Lock/README.md +++ b/solution/0700-0799/0752.Open the Lock/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def openLock(self, deadends: List[str], target: str) -> int: @@ -116,6 +118,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int openLock(String[] deadends, String target) { @@ -164,6 +168,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -206,6 +212,8 @@ public: }; ``` +#### Go + ```go func openLock(deadends []string, target string) int { if target == "0000" { @@ -303,6 +311,8 @@ def extend(m1, m2, q): +#### Python3 + ```python class Solution: def openLock(self, deadends: List[str], target: str) -> int: @@ -348,6 +358,8 @@ class Solution: return bfs() ``` +#### Java + ```java class Solution { private String start; @@ -421,6 +433,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -481,6 +495,8 @@ public: }; ``` +#### Go + ```go func openLock(deadends []string, target string) int { if target == "0000" { @@ -575,6 +591,8 @@ A\* 算法主要思想如下: +#### Python3 + ```python class Solution: def openLock(self, deadends: List[str], target: str) -> int: @@ -621,6 +639,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { private String target; @@ -693,6 +713,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/0700-0799/0752.Open the Lock/README_EN.md b/solution/0700-0799/0752.Open the Lock/README_EN.md index 5c820f23328a3..676fa314a355a 100644 --- a/solution/0700-0799/0752.Open the Lock/README_EN.md +++ b/solution/0700-0799/0752.Open the Lock/README_EN.md @@ -76,6 +76,8 @@ because the wheels of the lock become stuck after the display becomes the dead e +#### Python3 + ```python class Solution: def openLock(self, deadends: List[str], target: str) -> int: @@ -112,6 +114,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int openLock(String[] deadends, String target) { @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -202,6 +208,8 @@ public: }; ``` +#### Go + ```go func openLock(deadends []string, target string) int { if target == "0000" { @@ -265,6 +273,8 @@ func openLock(deadends []string, target string) int { +#### Python3 + ```python class Solution: def openLock(self, deadends: List[str], target: str) -> int: @@ -310,6 +320,8 @@ class Solution: return bfs() ``` +#### Java + ```java class Solution { private String start; @@ -383,6 +395,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -443,6 +457,8 @@ public: }; ``` +#### Go + ```go func openLock(deadends []string, target string) int { if target == "0000" { @@ -529,6 +545,8 @@ func openLock(deadends []string, target string) int { +#### Python3 + ```python class Solution: def openLock(self, deadends: List[str], target: str) -> int: @@ -575,6 +593,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { private String target; @@ -647,6 +667,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/0700-0799/0753.Cracking the Safe/README.md b/solution/0700-0799/0753.Cracking the Safe/README.md index e84a4a6bbfcf0..bcbac1c0841b2 100644 --- a/solution/0700-0799/0753.Cracking the Safe/README.md +++ b/solution/0700-0799/0753.Cracking the Safe/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def crackSafe(self, n: int, k: int) -> str: @@ -108,6 +110,8 @@ class Solution: return "".join(ans) ``` +#### Java + ```java class Solution { private Set vis = new HashSet<>(); @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func crackSafe(n int, k int) string { mod := int(math.Pow(10, float64(n-1))) diff --git a/solution/0700-0799/0753.Cracking the Safe/README_EN.md b/solution/0700-0799/0753.Cracking the Safe/README_EN.md index 5e220f2d8d481..b5a4511d44ef4 100644 --- a/solution/0700-0799/0753.Cracking the Safe/README_EN.md +++ b/solution/0700-0799/0753.Cracking the Safe/README_EN.md @@ -80,6 +80,8 @@ Thus "01100" will unlock the safe. "10011", and "11001& +#### Python3 + ```python class Solution: def crackSafe(self, n: int, k: int) -> str: @@ -100,6 +102,8 @@ class Solution: return "".join(ans) ``` +#### Java + ```java class Solution { private Set vis = new HashSet<>(); @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func crackSafe(n int, k int) string { mod := int(math.Pow(10, float64(n-1))) diff --git a/solution/0700-0799/0754.Reach a Number/README.md b/solution/0700-0799/0754.Reach a Number/README.md index 1b504d7d17f00..b274110d34683 100644 --- a/solution/0700-0799/0754.Reach a Number/README.md +++ b/solution/0700-0799/0754.Reach a Number/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def reachNumber(self, target: int) -> int: @@ -92,6 +94,8 @@ class Solution: s += k ``` +#### Java + ```java class Solution { public int reachNumber(int target) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func reachNumber(target int) int { if target < 0 { @@ -139,6 +147,8 @@ func reachNumber(target int) int { } ``` +#### JavaScript + ```js /** * @param {number} target diff --git a/solution/0700-0799/0754.Reach a Number/README_EN.md b/solution/0700-0799/0754.Reach a Number/README_EN.md index 7d3380f328768..cf6ec0472a6ac 100644 --- a/solution/0700-0799/0754.Reach a Number/README_EN.md +++ b/solution/0700-0799/0754.Reach a Number/README_EN.md @@ -68,6 +68,8 @@ On the 2nd move, we step from 1 to 3 (2 steps). +#### Python3 + ```python class Solution: def reachNumber(self, target: int) -> int: @@ -80,6 +82,8 @@ class Solution: s += k ``` +#### Java + ```java class Solution { public int reachNumber(int target) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func reachNumber(target int) int { if target < 0 { @@ -127,6 +135,8 @@ func reachNumber(target int) int { } ``` +#### JavaScript + ```js /** * @param {number} target diff --git a/solution/0700-0799/0755.Pour Water/README.md b/solution/0700-0799/0755.Pour Water/README.md index e36891c969a38..b31b823035263 100644 --- a/solution/0700-0799/0755.Pour Water/README.md +++ b/solution/0700-0799/0755.Pour Water/README.md @@ -164,6 +164,8 @@ tags: +#### Python3 + ```python class Solution: def pourWater(self, heights: List[int], volume: int, k: int) -> List[int]: @@ -182,6 +184,8 @@ class Solution: return heights ``` +#### Java + ```java class Solution { public int[] pourWater(int[] heights, int volume, int k) { @@ -209,6 +213,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -237,6 +243,8 @@ public: }; ``` +#### Go + ```go func pourWater(heights []int, volume int, k int) []int { for ; volume > 0; volume-- { diff --git a/solution/0700-0799/0755.Pour Water/README_EN.md b/solution/0700-0799/0755.Pour Water/README_EN.md index b9d25056c2977..83b1a995f6135 100644 --- a/solution/0700-0799/0755.Pour Water/README_EN.md +++ b/solution/0700-0799/0755.Pour Water/README_EN.md @@ -84,6 +84,8 @@ Finally, the fourth droplet falls at index k = 3. Since moving left would not ev +#### Python3 + ```python class Solution: def pourWater(self, heights: List[int], volume: int, k: int) -> List[int]: @@ -102,6 +104,8 @@ class Solution: return heights ``` +#### Java + ```java class Solution { public int[] pourWater(int[] heights, int volume, int k) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func pourWater(heights []int, volume int, k int) []int { for ; volume > 0; volume-- { diff --git a/solution/0700-0799/0756.Pyramid Transition Matrix/README.md b/solution/0700-0799/0756.Pyramid Transition Matrix/README.md index 68876cba801b8..41d3596c01883 100644 --- a/solution/0700-0799/0756.Pyramid Transition Matrix/README.md +++ b/solution/0700-0799/0756.Pyramid Transition Matrix/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def pyramidTransition(self, bottom: str, allowed: List[str]) -> bool: @@ -104,6 +106,8 @@ class Solution: return dfs(bottom) ``` +#### Java + ```java class Solution { private int[][] f = new int[7][7]; @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go func pyramidTransition(bottom string, allowed []string) bool { f := make([][]int, 7) diff --git a/solution/0700-0799/0756.Pyramid Transition Matrix/README_EN.md b/solution/0700-0799/0756.Pyramid Transition Matrix/README_EN.md index 7de6086c07588..f35b348f47053 100644 --- a/solution/0700-0799/0756.Pyramid Transition Matrix/README_EN.md +++ b/solution/0700-0799/0756.Pyramid Transition Matrix/README_EN.md @@ -71,6 +71,8 @@ Starting from the bottom (level 4), there are multiple ways to build level 3, bu +#### Python3 + ```python class Solution: def pyramidTransition(self, bottom: str, allowed: List[str]) -> bool: @@ -92,6 +94,8 @@ class Solution: return dfs(bottom) ``` +#### Java + ```java class Solution { private int[][] f = new int[7][7]; @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go func pyramidTransition(bottom string, allowed []string) bool { f := make([][]int, 7) diff --git a/solution/0700-0799/0757.Set Intersection Size At Least Two/README.md b/solution/0700-0799/0757.Set Intersection Size At Least Two/README.md index 2f70354977011..7a6b5a338642a 100644 --- a/solution/0700-0799/0757.Set Intersection Size At Least Two/README.md +++ b/solution/0700-0799/0757.Set Intersection Size At Least Two/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def intersectionSizeTwo(self, intervals: List[List[int]]) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int intersectionSizeTwo(int[][] intervals) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func intersectionSizeTwo(intervals [][]int) int { sort.Slice(intervals, func(i, j int) bool { diff --git a/solution/0700-0799/0757.Set Intersection Size At Least Two/README_EN.md b/solution/0700-0799/0757.Set Intersection Size At Least Two/README_EN.md index 98d3a9ef06d5a..4c36ce0960c78 100644 --- a/solution/0700-0799/0757.Set Intersection Size At Least Two/README_EN.md +++ b/solution/0700-0799/0757.Set Intersection Size At Least Two/README_EN.md @@ -75,6 +75,8 @@ It can be shown that there cannot be any containing array of size 4. +#### Python3 + ```python class Solution: def intersectionSizeTwo(self, intervals: List[List[int]]) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int intersectionSizeTwo(int[][] intervals) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func intersectionSizeTwo(intervals [][]int) int { sort.Slice(intervals, func(i, j int) bool { diff --git a/solution/0700-0799/0758.Bold Words in String/README.md b/solution/0700-0799/0758.Bold Words in String/README.md index c46fc7f630d87..4b6357b9af6aa 100644 --- a/solution/0700-0799/0758.Bold Words in String/README.md +++ b/solution/0700-0799/0758.Bold Words in String/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Trie: def __init__(self): @@ -133,6 +135,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Trie { Trie[] children = new Trie[128]; @@ -210,6 +214,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -279,6 +285,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [128]*Trie diff --git a/solution/0700-0799/0758.Bold Words in String/README_EN.md b/solution/0700-0799/0758.Bold Words in String/README_EN.md index 42b4d23fc28dc..0dc44c2004298 100644 --- a/solution/0700-0799/0758.Bold Words in String/README_EN.md +++ b/solution/0700-0799/0758.Bold Words in String/README_EN.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Trie: def __init__(self): @@ -125,6 +127,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Trie { Trie[] children = new Trie[128]; @@ -202,6 +206,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -271,6 +277,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [128]*Trie diff --git a/solution/0700-0799/0759.Employee Free Time/README.md b/solution/0700-0799/0759.Employee Free Time/README.md index df7e20476cbfa..cf8212b6bb7f5 100644 --- a/solution/0700-0799/0759.Employee Free Time/README.md +++ b/solution/0700-0799/0759.Employee Free Time/README.md @@ -71,18 +71,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/0700-0799/0759.Employee Free Time/README_EN.md b/solution/0700-0799/0759.Employee Free Time/README_EN.md index ac381d49599b0..9543d4e2e9379 100644 --- a/solution/0700-0799/0759.Employee Free Time/README_EN.md +++ b/solution/0700-0799/0759.Employee Free Time/README_EN.md @@ -62,18 +62,26 @@ We discard any intervals that contain inf as they aren't finite. +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/0700-0799/0760.Find Anagram Mappings/README.md b/solution/0700-0799/0760.Find Anagram Mappings/README.md index 0dd09e98752a1..c636f7a9b7bd4 100644 --- a/solution/0700-0799/0760.Find Anagram Mappings/README.md +++ b/solution/0700-0799/0760.Find Anagram Mappings/README.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def anagramMappings(self, nums1: List[int], nums2: List[int]) -> List[int]: @@ -71,6 +73,8 @@ class Solution: return [mapper[num].pop() for num in nums1] ``` +#### Java + ```java class Solution { public int[] anagramMappings(int[] nums1, int[] nums2) { diff --git a/solution/0700-0799/0760.Find Anagram Mappings/README_EN.md b/solution/0700-0799/0760.Find Anagram Mappings/README_EN.md index 6936a8bfa9865..8ee530166f973 100644 --- a/solution/0700-0799/0760.Find Anagram Mappings/README_EN.md +++ b/solution/0700-0799/0760.Find Anagram Mappings/README_EN.md @@ -59,6 +59,8 @@ tags: +#### Python3 + ```python class Solution: def anagramMappings(self, nums1: List[int], nums2: List[int]) -> List[int]: @@ -68,6 +70,8 @@ class Solution: return [mapper[num].pop() for num in nums1] ``` +#### Java + ```java class Solution { public int[] anagramMappings(int[] nums1, int[] nums2) { diff --git a/solution/0700-0799/0761.Special Binary String/README.md b/solution/0700-0799/0761.Special Binary String/README.md index 12a314386552b..a3c759e61c725 100644 --- a/solution/0700-0799/0761.Special Binary String/README.md +++ b/solution/0700-0799/0761.Special Binary String/README.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def makeLargestSpecial(self, s: str) -> str: @@ -81,6 +83,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String makeLargestSpecial(String s) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func makeLargestSpecial(s string) string { if s == "" { diff --git a/solution/0700-0799/0761.Special Binary String/README_EN.md b/solution/0700-0799/0761.Special Binary String/README_EN.md index bbfb585bf8e68..bc9c0b47cfe6b 100644 --- a/solution/0700-0799/0761.Special Binary String/README_EN.md +++ b/solution/0700-0799/0761.Special Binary String/README_EN.md @@ -66,6 +66,8 @@ This is the lexicographically largest string possible after some number of swaps +#### Python3 + ```python class Solution: def makeLargestSpecial(self, s: str) -> str: @@ -84,6 +86,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String makeLargestSpecial(String s) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func makeLargestSpecial(s string) string { if s == "" { diff --git a/solution/0700-0799/0762.Prime Number of Set Bits in Binary Representation/README.md b/solution/0700-0799/0762.Prime Number of Set Bits in Binary Representation/README.md index 9d20b47bc602f..f6fe9c776e0cb 100644 --- a/solution/0700-0799/0762.Prime Number of Set Bits in Binary Representation/README.md +++ b/solution/0700-0799/0762.Prime Number of Set Bits in Binary Representation/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def countPrimeSetBits(self, left: int, right: int) -> int: @@ -87,6 +89,8 @@ class Solution: return sum(i.bit_count() in primes for i in range(left, right + 1)) ``` +#### Java + ```java class Solution { private static Set primes = Set.of(2, 3, 5, 7, 11, 13, 17, 19); @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func countPrimeSetBits(left int, right int) (ans int) { primes := map[int]int{} diff --git a/solution/0700-0799/0762.Prime Number of Set Bits in Binary Representation/README_EN.md b/solution/0700-0799/0762.Prime Number of Set Bits in Binary Representation/README_EN.md index 49377538511a3..de5b70605987e 100644 --- a/solution/0700-0799/0762.Prime Number of Set Bits in Binary Representation/README_EN.md +++ b/solution/0700-0799/0762.Prime Number of Set Bits in Binary Representation/README_EN.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def countPrimeSetBits(self, left: int, right: int) -> int: @@ -80,6 +82,8 @@ class Solution: return sum(i.bit_count() in primes for i in range(left, right + 1)) ``` +#### Java + ```java class Solution { private static Set primes = Set.of(2, 3, 5, 7, 11, 13, 17, 19); @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func countPrimeSetBits(left int, right int) (ans int) { primes := map[int]int{} diff --git a/solution/0700-0799/0763.Partition Labels/README.md b/solution/0700-0799/0763.Partition Labels/README.md index fbfd3ba38a493..2d5e408dd4339 100644 --- a/solution/0700-0799/0763.Partition Labels/README.md +++ b/solution/0700-0799/0763.Partition Labels/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def partitionLabels(self, s: str) -> List[int]: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List partitionLabels(String s) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func partitionLabels(s string) (ans []int) { last := [26]int{} @@ -153,6 +161,8 @@ func partitionLabels(s string) (ans []int) { } ``` +#### TypeScript + ```ts function partitionLabels(s: string): number[] { const last: number[] = Array(26).fill(0); @@ -173,6 +183,8 @@ function partitionLabels(s: string): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn partition_labels(s: String) -> Vec { @@ -197,6 +209,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -221,6 +235,8 @@ var partitionLabels = function (s) { }; ``` +#### C# + ```cs public class Solution { public IList PartitionLabels(string s) { diff --git a/solution/0700-0799/0763.Partition Labels/README_EN.md b/solution/0700-0799/0763.Partition Labels/README_EN.md index 9f9ac412a6b7a..63233742ab709 100644 --- a/solution/0700-0799/0763.Partition Labels/README_EN.md +++ b/solution/0700-0799/0763.Partition Labels/README_EN.md @@ -62,6 +62,8 @@ A partition like "ababcbacadefegde", "hijhklij" is incorrect +#### Python3 + ```python class Solution: def partitionLabels(self, s: str) -> List[int]: @@ -76,6 +78,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List partitionLabels(String s) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func partitionLabels(s string) (ans []int) { last := [26]int{} @@ -139,6 +147,8 @@ func partitionLabels(s string) (ans []int) { } ``` +#### TypeScript + ```ts function partitionLabels(s: string): number[] { const last: number[] = Array(26).fill(0); @@ -159,6 +169,8 @@ function partitionLabels(s: string): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn partition_labels(s: String) -> Vec { @@ -183,6 +195,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -207,6 +221,8 @@ var partitionLabels = function (s) { }; ``` +#### C# + ```cs public class Solution { public IList PartitionLabels(string s) { diff --git a/solution/0700-0799/0764.Largest Plus Sign/README.md b/solution/0700-0799/0764.Largest Plus Sign/README.md index 2305b0fbb31f5..7cade8ab0e59e 100644 --- a/solution/0700-0799/0764.Largest Plus Sign/README.md +++ b/solution/0700-0799/0764.Largest Plus Sign/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def orderOfLargestPlusSign(self, n: int, mines: List[List[int]]) -> int: @@ -92,6 +94,8 @@ class Solution: return max(max(v) for v in dp) ``` +#### Java + ```java class Solution { public int orderOfLargestPlusSign(int n, int[][] mines) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func orderOfLargestPlusSign(n int, mines [][]int) (ans int) { dp := make([][]int, n) diff --git a/solution/0700-0799/0764.Largest Plus Sign/README_EN.md b/solution/0700-0799/0764.Largest Plus Sign/README_EN.md index 499f62c37a427..88fd5dd8cc6c0 100644 --- a/solution/0700-0799/0764.Largest Plus Sign/README_EN.md +++ b/solution/0700-0799/0764.Largest Plus Sign/README_EN.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def orderOfLargestPlusSign(self, n: int, mines: List[List[int]]) -> int: @@ -80,6 +82,8 @@ class Solution: return max(max(v) for v in dp) ``` +#### Java + ```java class Solution { public int orderOfLargestPlusSign(int n, int[][] mines) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func orderOfLargestPlusSign(n int, mines [][]int) (ans int) { dp := make([][]int, n) diff --git a/solution/0700-0799/0765.Couples Holding Hands/README.md b/solution/0700-0799/0765.Couples Holding Hands/README.md index af55564d271e5..b7f19416522bd 100644 --- a/solution/0700-0799/0765.Couples Holding Hands/README.md +++ b/solution/0700-0799/0765.Couples Holding Hands/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def minSwapsCouples(self, row: List[int]) -> int: @@ -92,6 +94,8 @@ class Solution: return n - sum(i == find(i) for i in range(n)) ``` +#### Java + ```java class Solution { private int[] p; @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func minSwapsCouples(row []int) int { n := len(row) >> 1 @@ -178,6 +186,8 @@ func minSwapsCouples(row []int) int { } ``` +#### TypeScript + ```ts function minSwapsCouples(row: number[]): number { const n = row.length >> 1; @@ -205,6 +215,8 @@ function minSwapsCouples(row: number[]): number { } ``` +#### C# + ```cs public class Solution { private int[] p; diff --git a/solution/0700-0799/0765.Couples Holding Hands/README_EN.md b/solution/0700-0799/0765.Couples Holding Hands/README_EN.md index 4eafae875a61e..c90ba1f5741ac 100644 --- a/solution/0700-0799/0765.Couples Holding Hands/README_EN.md +++ b/solution/0700-0799/0765.Couples Holding Hands/README_EN.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def minSwapsCouples(self, row: List[int]) -> int: @@ -80,6 +82,8 @@ class Solution: return n - sum(i == find(i) for i in range(n)) ``` +#### Java + ```java class Solution { private int[] p; @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func minSwapsCouples(row []int) int { n := len(row) >> 1 @@ -166,6 +174,8 @@ func minSwapsCouples(row []int) int { } ``` +#### TypeScript + ```ts function minSwapsCouples(row: number[]): number { const n = row.length >> 1; @@ -193,6 +203,8 @@ function minSwapsCouples(row: number[]): number { } ``` +#### C# + ```cs public class Solution { private int[] p; diff --git a/solution/0700-0799/0766.Toeplitz Matrix/README.md b/solution/0700-0799/0766.Toeplitz Matrix/README.md index 7f8630b1dfab5..8b7e247b86c0c 100644 --- a/solution/0700-0799/0766.Toeplitz Matrix/README.md +++ b/solution/0700-0799/0766.Toeplitz Matrix/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def isToeplitzMatrix(self, matrix: List[List[int]]) -> bool: @@ -87,6 +89,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public boolean isToeplitzMatrix(int[][] matrix) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func isToeplitzMatrix(matrix [][]int) bool { m, n := len(matrix), len(matrix[0]) @@ -134,6 +142,8 @@ func isToeplitzMatrix(matrix [][]int) bool { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix diff --git a/solution/0700-0799/0766.Toeplitz Matrix/README_EN.md b/solution/0700-0799/0766.Toeplitz Matrix/README_EN.md index 1d2305e704821..0de95666d2991 100644 --- a/solution/0700-0799/0766.Toeplitz Matrix/README_EN.md +++ b/solution/0700-0799/0766.Toeplitz Matrix/README_EN.md @@ -70,6 +70,8 @@ The diagonal "[1, 2]" has different elements. +#### Python3 + ```python class Solution: def isToeplitzMatrix(self, matrix: List[List[int]]) -> bool: @@ -81,6 +83,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public boolean isToeplitzMatrix(int[][] matrix) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func isToeplitzMatrix(matrix [][]int) bool { m, n := len(matrix), len(matrix[0]) @@ -128,6 +136,8 @@ func isToeplitzMatrix(matrix [][]int) bool { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix diff --git a/solution/0700-0799/0767.Reorganize String/README.md b/solution/0700-0799/0767.Reorganize String/README.md index 1ecca9abe7ff7..deb441754d75a 100644 --- a/solution/0700-0799/0767.Reorganize String/README.md +++ b/solution/0700-0799/0767.Reorganize String/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def reorganizeString(self, s: str) -> str: @@ -86,6 +88,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String reorganizeString(String s) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func reorganizeString(s string) string { cnt := make([]int, 26) @@ -199,6 +207,8 @@ func reorganizeString(s string) string { } ``` +#### Rust + ```rust use std::collections::{ HashMap, BinaryHeap, VecDeque }; @@ -273,6 +283,8 @@ impl Solution { +#### Python3 + ```python class Solution: def reorganizeString(self, s: str) -> str: @@ -295,6 +307,8 @@ class Solution: return "" if len(ans) != len(s) else "".join(ans) ``` +#### Java + ```java class Solution { public String reorganizeString(String s) { @@ -332,6 +346,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -364,6 +380,8 @@ public: }; ``` +#### Go + ```go func reorganizeString(s string) string { return rearrangeString(s, 2) diff --git a/solution/0700-0799/0767.Reorganize String/README_EN.md b/solution/0700-0799/0767.Reorganize String/README_EN.md index 5c5f48ce8b5bc..060cba2333358 100644 --- a/solution/0700-0799/0767.Reorganize String/README_EN.md +++ b/solution/0700-0799/0767.Reorganize String/README_EN.md @@ -51,6 +51,8 @@ tags: +#### Python3 + ```python class Solution: def reorganizeString(self, s: str) -> str: @@ -71,6 +73,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String reorganizeString(String s) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func reorganizeString(s string) string { cnt := make([]int, 26) @@ -184,6 +192,8 @@ func reorganizeString(s string) string { } ``` +#### Rust + ```rust use std::collections::{ HashMap, BinaryHeap, VecDeque }; @@ -245,6 +255,8 @@ impl Solution { +#### Python3 + ```python class Solution: def reorganizeString(self, s: str) -> str: @@ -267,6 +279,8 @@ class Solution: return "" if len(ans) != len(s) else "".join(ans) ``` +#### Java + ```java class Solution { public String reorganizeString(String s) { @@ -304,6 +318,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -336,6 +352,8 @@ public: }; ``` +#### Go + ```go func reorganizeString(s string) string { return rearrangeString(s, 2) diff --git a/solution/0700-0799/0768.Max Chunks To Make Sorted II/README.md b/solution/0700-0799/0768.Max Chunks To Make Sorted II/README.md index d5f400b43b8e7..6c5c2d0506e65 100644 --- a/solution/0700-0799/0768.Max Chunks To Make Sorted II/README.md +++ b/solution/0700-0799/0768.Max Chunks To Make Sorted II/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def maxChunksToSorted(self, arr: List[int]) -> int: @@ -85,6 +87,8 @@ class Solution: return len(stk) ``` +#### Java + ```java class Solution { public int maxChunksToSorted(int[] arr) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func maxChunksToSorted(arr []int) int { var stk []int @@ -144,6 +152,8 @@ func maxChunksToSorted(arr []int) int { } ``` +#### TypeScript + ```ts function maxChunksToSorted(arr: number[]): number { const stack = []; @@ -162,6 +172,8 @@ function maxChunksToSorted(arr: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_chunks_to_sorted(arr: Vec) -> i32 { diff --git a/solution/0700-0799/0768.Max Chunks To Make Sorted II/README_EN.md b/solution/0700-0799/0768.Max Chunks To Make Sorted II/README_EN.md index 7207a5eab7d87..baa0ed6f9b2c1 100644 --- a/solution/0700-0799/0768.Max Chunks To Make Sorted II/README_EN.md +++ b/solution/0700-0799/0768.Max Chunks To Make Sorted II/README_EN.md @@ -65,6 +65,8 @@ However, splitting into [2, 1], [3], [4], [4] is the highest number of chunks po +#### Python3 + ```python class Solution: def maxChunksToSorted(self, arr: List[int]) -> int: @@ -80,6 +82,8 @@ class Solution: return len(stk) ``` +#### Java + ```java class Solution { public int maxChunksToSorted(int[] arr) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func maxChunksToSorted(arr []int) int { var stk []int @@ -139,6 +147,8 @@ func maxChunksToSorted(arr []int) int { } ``` +#### TypeScript + ```ts function maxChunksToSorted(arr: number[]): number { const stack = []; @@ -157,6 +167,8 @@ function maxChunksToSorted(arr: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_chunks_to_sorted(arr: Vec) -> i32 { diff --git a/solution/0700-0799/0769.Max Chunks To Make Sorted/README.md b/solution/0700-0799/0769.Max Chunks To Make Sorted/README.md index 4f49a8b7294f8..fd02bac2fc375 100644 --- a/solution/0700-0799/0769.Max Chunks To Make Sorted/README.md +++ b/solution/0700-0799/0769.Max Chunks To Make Sorted/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def maxChunksToSorted(self, arr: List[int]) -> int: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxChunksToSorted(int[] arr) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func maxChunksToSorted(arr []int) int { ans, mx := 0, 0 @@ -127,6 +135,8 @@ func maxChunksToSorted(arr []int) int { } ``` +#### TypeScript + ```ts function maxChunksToSorted(arr: number[]): number { const n = arr.length; @@ -142,6 +152,8 @@ function maxChunksToSorted(arr: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_chunks_to_sorted(arr: Vec) -> i32 { @@ -158,6 +170,8 @@ impl Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) @@ -192,6 +206,8 @@ int maxChunksToSorted(int* arr, int arrSize) { +#### Python3 + ```python class Solution: def maxChunksToSorted(self, arr: List[int]) -> int: @@ -207,6 +223,8 @@ class Solution: return len(stk) ``` +#### Java + ```java class Solution { public int maxChunksToSorted(int[] arr) { @@ -227,6 +245,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -249,6 +269,8 @@ public: }; ``` +#### Go + ```go func maxChunksToSorted(arr []int) int { stk := []int{} diff --git a/solution/0700-0799/0769.Max Chunks To Make Sorted/README_EN.md b/solution/0700-0799/0769.Max Chunks To Make Sorted/README_EN.md index 390e7cec1b175..c2d97614d8c40 100644 --- a/solution/0700-0799/0769.Max Chunks To Make Sorted/README_EN.md +++ b/solution/0700-0799/0769.Max Chunks To Make Sorted/README_EN.md @@ -67,6 +67,8 @@ However, splitting into [1, 0], [2], [3], [4] is the highest number of chunks po +#### Python3 + ```python class Solution: def maxChunksToSorted(self, arr: List[int]) -> int: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxChunksToSorted(int[] arr) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func maxChunksToSorted(arr []int) int { ans, mx := 0, 0 @@ -120,6 +128,8 @@ func maxChunksToSorted(arr []int) int { } ``` +#### TypeScript + ```ts function maxChunksToSorted(arr: number[]): number { const n = arr.length; @@ -135,6 +145,8 @@ function maxChunksToSorted(arr: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_chunks_to_sorted(arr: Vec) -> i32 { @@ -151,6 +163,8 @@ impl Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) @@ -177,6 +191,8 @@ int maxChunksToSorted(int* arr, int arrSize) { +#### Python3 + ```python class Solution: def maxChunksToSorted(self, arr: List[int]) -> int: @@ -192,6 +208,8 @@ class Solution: return len(stk) ``` +#### Java + ```java class Solution { public int maxChunksToSorted(int[] arr) { @@ -212,6 +230,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -234,6 +254,8 @@ public: }; ``` +#### Go + ```go func maxChunksToSorted(arr []int) int { stk := []int{} diff --git a/solution/0700-0799/0770.Basic Calculator IV/README.md b/solution/0700-0799/0770.Basic Calculator IV/README.md index 26d7e2a14efe6..31fe8f7cd897d 100644 --- a/solution/0700-0799/0770.Basic Calculator IV/README.md +++ b/solution/0700-0799/0770.Basic Calculator IV/README.md @@ -108,18 +108,26 @@ evalvars = ["e", "temperature"], evalints = [1, 12] +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/0700-0799/0770.Basic Calculator IV/README_EN.md b/solution/0700-0799/0770.Basic Calculator IV/README_EN.md index a379bed1b28da..78103fef3261c 100644 --- a/solution/0700-0799/0770.Basic Calculator IV/README_EN.md +++ b/solution/0700-0799/0770.Basic Calculator IV/README_EN.md @@ -105,18 +105,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/0700-0799/0771.Jewels and Stones/README.md b/solution/0700-0799/0771.Jewels and Stones/README.md index 2adb56597bd0c..21ca8afb9b473 100644 --- a/solution/0700-0799/0771.Jewels and Stones/README.md +++ b/solution/0700-0799/0771.Jewels and Stones/README.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def numJewelsInStones(self, jewels: str, stones: str) -> int: @@ -68,6 +70,8 @@ class Solution: return sum(c in s for c in stones) ``` +#### Java + ```java class Solution { public int numJewelsInStones(String jewels, String stones) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -97,6 +103,8 @@ public: }; ``` +#### Go + ```go func numJewelsInStones(jewels string, stones string) (ans int) { s := [128]int{} @@ -110,6 +118,8 @@ func numJewelsInStones(jewels string, stones string) (ans int) { } ``` +#### TypeScript + ```ts function numJewelsInStones(jewels: string, stones: string): number { const s = new Set([...jewels]); @@ -121,6 +131,8 @@ function numJewelsInStones(jewels: string, stones: string): number { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -137,6 +149,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} jewels @@ -149,6 +163,8 @@ var numJewelsInStones = function (jewels, stones) { }; ``` +#### C + ```c int numJewelsInStones(char* jewels, char* stones) { int set[128] = {0}; diff --git a/solution/0700-0799/0771.Jewels and Stones/README_EN.md b/solution/0700-0799/0771.Jewels and Stones/README_EN.md index 485293dae7509..f9edb1ef77e62 100644 --- a/solution/0700-0799/0771.Jewels and Stones/README_EN.md +++ b/solution/0700-0799/0771.Jewels and Stones/README_EN.md @@ -48,6 +48,8 @@ tags: +#### Python3 + ```python class Solution: def numJewelsInStones(self, jewels: str, stones: str) -> int: @@ -55,6 +57,8 @@ class Solution: return sum(c in s for c in stones) ``` +#### Java + ```java class Solution { public int numJewelsInStones(String jewels, String stones) { @@ -71,6 +75,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -84,6 +90,8 @@ public: }; ``` +#### Go + ```go func numJewelsInStones(jewels string, stones string) (ans int) { s := [128]int{} @@ -97,6 +105,8 @@ func numJewelsInStones(jewels string, stones string) (ans int) { } ``` +#### TypeScript + ```ts function numJewelsInStones(jewels: string, stones: string): number { const s = new Set([...jewels]); @@ -108,6 +118,8 @@ function numJewelsInStones(jewels: string, stones: string): number { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -124,6 +136,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} jewels @@ -136,6 +150,8 @@ var numJewelsInStones = function (jewels, stones) { }; ``` +#### C + ```c int numJewelsInStones(char* jewels, char* stones) { int set[128] = {0}; diff --git a/solution/0700-0799/0772.Basic Calculator III/README.md b/solution/0700-0799/0772.Basic Calculator III/README.md index 176e70a558bdb..74168905b4403 100644 --- a/solution/0700-0799/0772.Basic Calculator III/README.md +++ b/solution/0700-0799/0772.Basic Calculator III/README.md @@ -70,18 +70,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/0700-0799/0772.Basic Calculator III/README_EN.md b/solution/0700-0799/0772.Basic Calculator III/README_EN.md index 379fb230cfc4c..6e5dbf9169bb7 100644 --- a/solution/0700-0799/0772.Basic Calculator III/README_EN.md +++ b/solution/0700-0799/0772.Basic Calculator III/README_EN.md @@ -68,18 +68,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/0700-0799/0773.Sliding Puzzle/README.md b/solution/0700-0799/0773.Sliding Puzzle/README.md index 94d882a7d0a8f..4e70bf616f549 100644 --- a/solution/0700-0799/0773.Sliding Puzzle/README.md +++ b/solution/0700-0799/0773.Sliding Puzzle/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def slidingPuzzle(self, board: List[List[int]]) -> int: @@ -133,6 +135,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { private String[] t = new String[6]; @@ -222,6 +226,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -307,6 +313,8 @@ public: +#### Python3 + ```python class Solution: def slidingPuzzle(self, board: List[List[int]]) -> int: @@ -356,6 +364,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { private int m = 2; @@ -440,6 +450,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/0700-0799/0773.Sliding Puzzle/README_EN.md b/solution/0700-0799/0773.Sliding Puzzle/README_EN.md index 6c36403aaf9b3..389533e755937 100644 --- a/solution/0700-0799/0773.Sliding Puzzle/README_EN.md +++ b/solution/0700-0799/0773.Sliding Puzzle/README_EN.md @@ -76,6 +76,8 @@ After move 5: [[1,2,3],[4,5,0]] +#### Python3 + ```python class Solution: def slidingPuzzle(self, board: List[List[int]]) -> int: @@ -124,6 +126,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { private String[] t = new String[6]; @@ -213,6 +217,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -298,6 +304,8 @@ public: +#### Python3 + ```python class Solution: def slidingPuzzle(self, board: List[List[int]]) -> int: @@ -347,6 +355,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { private int m = 2; @@ -431,6 +441,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/0700-0799/0774.Minimize Max Distance to Gas Station/README.md b/solution/0700-0799/0774.Minimize Max Distance to Gas Station/README.md index 889e7803ae844..7d934d7f750ac 100644 --- a/solution/0700-0799/0774.Minimize Max Distance to Gas Station/README.md +++ b/solution/0700-0799/0774.Minimize Max Distance to Gas Station/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def minmaxGasDist(self, stations: List[int], k: int) -> float: @@ -81,6 +83,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public double minmaxGasDist(int[] stations, int k) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func minmaxGasDist(stations []int, k int) float64 { check := func(x float64) bool { diff --git a/solution/0700-0799/0774.Minimize Max Distance to Gas Station/README_EN.md b/solution/0700-0799/0774.Minimize Max Distance to Gas Station/README_EN.md index 6cd7a3fdb30e3..4ed5cd9da0e19 100644 --- a/solution/0700-0799/0774.Minimize Max Distance to Gas Station/README_EN.md +++ b/solution/0700-0799/0774.Minimize Max Distance to Gas Station/README_EN.md @@ -53,6 +53,8 @@ tags: +#### Python3 + ```python class Solution: def minmaxGasDist(self, stations: List[int], k: int) -> float: @@ -69,6 +71,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public double minmaxGasDist(int[] stations, int k) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func minmaxGasDist(stations []int, k int) float64 { check := func(x float64) bool { diff --git a/solution/0700-0799/0775.Global and Local Inversions/README.md b/solution/0700-0799/0775.Global and Local Inversions/README.md index 779db9447d514..6cddfb06afa32 100644 --- a/solution/0700-0799/0775.Global and Local Inversions/README.md +++ b/solution/0700-0799/0775.Global and Local Inversions/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def isIdealPermutation(self, nums: List[int]) -> bool: @@ -93,6 +95,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isIdealPermutation(int[] nums) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func isIdealPermutation(nums []int) bool { mx := 0 @@ -158,6 +166,8 @@ func isIdealPermutation(nums []int) bool { +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -191,6 +201,8 @@ class Solution: return True ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -233,6 +245,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -277,6 +291,8 @@ public: }; ``` +#### Go + ```go func isIdealPermutation(nums []int) bool { n := len(nums) diff --git a/solution/0700-0799/0775.Global and Local Inversions/README_EN.md b/solution/0700-0799/0775.Global and Local Inversions/README_EN.md index 841f7b6217650..f88921ecbe4ad 100644 --- a/solution/0700-0799/0775.Global and Local Inversions/README_EN.md +++ b/solution/0700-0799/0775.Global and Local Inversions/README_EN.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def isIdealPermutation(self, nums: List[int]) -> bool: @@ -83,6 +85,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isIdealPermutation(int[] nums) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func isIdealPermutation(nums []int) bool { mx := 0 @@ -135,6 +143,8 @@ func isIdealPermutation(nums []int) bool { +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -168,6 +178,8 @@ class Solution: return True ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -210,6 +222,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -254,6 +268,8 @@ public: }; ``` +#### Go + ```go func isIdealPermutation(nums []int) bool { n := len(nums) diff --git a/solution/0700-0799/0776.Split BST/README.md b/solution/0700-0799/0776.Split BST/README.md index 4c541b8bd0436..4826c1221fb23 100644 --- a/solution/0700-0799/0776.Split BST/README.md +++ b/solution/0700-0799/0776.Split BST/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -96,6 +98,8 @@ class Solution: return dfs(root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -204,6 +212,8 @@ func splitBST(root *TreeNode, target int) []*TreeNode { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0700-0799/0776.Split BST/README_EN.md b/solution/0700-0799/0776.Split BST/README_EN.md index f39ac0bb89150..34695357dbe7c 100644 --- a/solution/0700-0799/0776.Split BST/README_EN.md +++ b/solution/0700-0799/0776.Split BST/README_EN.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -84,6 +86,8 @@ class Solution: return dfs(root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -192,6 +200,8 @@ func splitBST(root *TreeNode, target int) []*TreeNode { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0700-0799/0777.Swap Adjacent in LR String/README.md b/solution/0700-0799/0777.Swap Adjacent in LR String/README.md index 10883bc336813..27981084c818c 100644 --- a/solution/0700-0799/0777.Swap Adjacent in LR String/README.md +++ b/solution/0700-0799/0777.Swap Adjacent in LR String/README.md @@ -68,6 +68,8 @@ XRLXXRRLX +#### Python3 + ```python class Solution: def canTransform(self, start: str, end: str) -> bool: @@ -89,6 +91,8 @@ class Solution: i, j = i + 1, j + 1 ``` +#### Java + ```java class Solution { public boolean canTransform(String start, String end) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func canTransform(start string, end string) bool { n := len(start) diff --git a/solution/0700-0799/0777.Swap Adjacent in LR String/README_EN.md b/solution/0700-0799/0777.Swap Adjacent in LR String/README_EN.md index 154cc4d9c2c94..27e0e8b94adb9 100644 --- a/solution/0700-0799/0777.Swap Adjacent in LR String/README_EN.md +++ b/solution/0700-0799/0777.Swap Adjacent in LR String/README_EN.md @@ -59,6 +59,8 @@ XRLXXRRLX +#### Python3 + ```python class Solution: def canTransform(self, start: str, end: str) -> bool: @@ -80,6 +82,8 @@ class Solution: i, j = i + 1, j + 1 ``` +#### Java + ```java class Solution { public boolean canTransform(String start, String end) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func canTransform(start string, end string) bool { n := len(start) diff --git a/solution/0700-0799/0778.Swim in Rising Water/README.md b/solution/0700-0799/0778.Swim in Rising Water/README.md index c8f02aecf9619..00322b6e5efc5 100644 --- a/solution/0700-0799/0778.Swim in Rising Water/README.md +++ b/solution/0700-0799/0778.Swim in Rising Water/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def swimInWater(self, grid: List[List[int]]) -> int: @@ -101,6 +103,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { private int[] p; @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go func swimInWater(grid [][]int) int { n := len(grid) @@ -214,6 +222,8 @@ func swimInWater(grid [][]int) int { } ``` +#### TypeScript + ```ts function swimInWater(grid: number[][]): number { const m = grid.length, @@ -246,6 +256,8 @@ function swimInWater(grid: number[][]): number { } ``` +#### Rust + ```rust const DIR: [(i32, i32); 4] = [ (-1, 0), diff --git a/solution/0700-0799/0778.Swim in Rising Water/README_EN.md b/solution/0700-0799/0778.Swim in Rising Water/README_EN.md index 4808688ad903f..4a960a75f7276 100644 --- a/solution/0700-0799/0778.Swim in Rising Water/README_EN.md +++ b/solution/0700-0799/0778.Swim in Rising Water/README_EN.md @@ -71,6 +71,8 @@ We need to wait until time 16 so that (0, 0) and (4, 4) are connected. +#### Python3 + ```python class Solution: def swimInWater(self, grid: List[List[int]]) -> int: @@ -96,6 +98,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { private int[] p; @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go func swimInWater(grid [][]int) int { n := len(grid) @@ -209,6 +217,8 @@ func swimInWater(grid [][]int) int { } ``` +#### TypeScript + ```ts function swimInWater(grid: number[][]): number { const m = grid.length, @@ -241,6 +251,8 @@ function swimInWater(grid: number[][]): number { } ``` +#### Rust + ```rust const DIR: [(i32, i32); 4] = [ (-1, 0), diff --git a/solution/0700-0799/0779.K-th Symbol in Grammar/README.md b/solution/0700-0799/0779.K-th Symbol in Grammar/README.md index c725ca6072629..567084385dd33 100644 --- a/solution/0700-0799/0779.K-th Symbol in Grammar/README.md +++ b/solution/0700-0799/0779.K-th Symbol in Grammar/README.md @@ -93,6 +93,8 @@ n = 5: 0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0 +#### Python3 + ```python class Solution: def kthGrammar(self, n: int, k: int) -> int: @@ -103,6 +105,8 @@ class Solution: return self.kthGrammar(n - 1, k - (1 << (n - 2))) ^ 1 ``` +#### Java + ```java class Solution { public int kthGrammar(int n, int k) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func kthGrammar(n int, k int) int { if n == 1 { @@ -180,12 +188,16 @@ func kthGrammar(n int, k int) int { +#### Python3 + ```python class Solution: def kthGrammar(self, n: int, k: int) -> int: return (k - 1).bit_count() & 1 ``` +#### Java + ```java class Solution { public int kthGrammar(int n, int k) { @@ -194,6 +206,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -203,6 +217,8 @@ public: }; ``` +#### Go + ```go func kthGrammar(n int, k int) int { return bits.OnesCount(uint(k-1)) & 1 diff --git a/solution/0700-0799/0779.K-th Symbol in Grammar/README_EN.md b/solution/0700-0799/0779.K-th Symbol in Grammar/README_EN.md index 3a7d79018334f..5b1a1fcc188ec 100644 --- a/solution/0700-0799/0779.K-th Symbol in Grammar/README_EN.md +++ b/solution/0700-0799/0779.K-th Symbol in Grammar/README_EN.md @@ -73,6 +73,8 @@ row 2: 01 +#### Python3 + ```python class Solution: def kthGrammar(self, n: int, k: int) -> int: @@ -83,6 +85,8 @@ class Solution: return self.kthGrammar(n - 1, k - (1 << (n - 2))) ^ 1 ``` +#### Java + ```java class Solution { public int kthGrammar(int n, int k) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func kthGrammar(n int, k int) int { if n == 1 { @@ -130,12 +138,16 @@ func kthGrammar(n int, k int) int { +#### Python3 + ```python class Solution: def kthGrammar(self, n: int, k: int) -> int: return (k - 1).bit_count() & 1 ``` +#### Java + ```java class Solution { public int kthGrammar(int n, int k) { @@ -144,6 +156,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +167,8 @@ public: }; ``` +#### Go + ```go func kthGrammar(n int, k int) int { return bits.OnesCount(uint(k-1)) & 1 diff --git a/solution/0700-0799/0780.Reaching Points/README.md b/solution/0700-0799/0780.Reaching Points/README.md index 7600178123d6b..4d5189f3ef997 100644 --- a/solution/0700-0799/0780.Reaching Points/README.md +++ b/solution/0700-0799/0780.Reaching Points/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def reachingPoints(self, sx: int, sy: int, tx: int, ty: int) -> bool: @@ -92,6 +94,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean reachingPoints(int sx, int sy, int tx, int ty) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func reachingPoints(sx int, sy int, tx int, ty int) bool { for tx > sx && ty > sy && tx != ty { diff --git a/solution/0700-0799/0780.Reaching Points/README_EN.md b/solution/0700-0799/0780.Reaching Points/README_EN.md index 6cf53abc198ec..1ad469d1f9685 100644 --- a/solution/0700-0799/0780.Reaching Points/README_EN.md +++ b/solution/0700-0799/0780.Reaching Points/README_EN.md @@ -64,6 +64,8 @@ One series of moves that transforms the starting point to the target is: +#### Python3 + ```python class Solution: def reachingPoints(self, sx: int, sy: int, tx: int, ty: int) -> bool: @@ -81,6 +83,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean reachingPoints(int sx, int sy, int tx, int ty) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func reachingPoints(sx int, sy int, tx int, ty int) bool { for tx > sx && ty > sy && tx != ty { diff --git a/solution/0700-0799/0781.Rabbits in Forest/README.md b/solution/0700-0799/0781.Rabbits in Forest/README.md index da7f678dcf4d5..b1669c7a8f61d 100644 --- a/solution/0700-0799/0781.Rabbits in Forest/README.md +++ b/solution/0700-0799/0781.Rabbits in Forest/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def numRabbits(self, answers: List[int]) -> int: @@ -71,6 +73,8 @@ class Solution: return sum([math.ceil(v / (k + 1)) * (k + 1) for k, v in counter.items()]) ``` +#### Java + ```java class Solution { public int numRabbits(int[] answers) { diff --git a/solution/0700-0799/0781.Rabbits in Forest/README_EN.md b/solution/0700-0799/0781.Rabbits in Forest/README_EN.md index 99859b899a2d2..8b25ad8c980de 100644 --- a/solution/0700-0799/0781.Rabbits in Forest/README_EN.md +++ b/solution/0700-0799/0781.Rabbits in Forest/README_EN.md @@ -62,6 +62,8 @@ The smallest possible number of rabbits in the forest is therefore 5: 3 that ans +#### Python3 + ```python class Solution: def numRabbits(self, answers: List[int]) -> int: @@ -69,6 +71,8 @@ class Solution: return sum([math.ceil(v / (k + 1)) * (k + 1) for k, v in counter.items()]) ``` +#### Java + ```java class Solution { public int numRabbits(int[] answers) { diff --git a/solution/0700-0799/0782.Transform to Chessboard/README.md b/solution/0700-0799/0782.Transform to Chessboard/README.md index 606025b3453e7..3dfccbe0d1153 100644 --- a/solution/0700-0799/0782.Transform to Chessboard/README.md +++ b/solution/0700-0799/0782.Transform to Chessboard/README.md @@ -97,6 +97,8 @@ tags: +#### Python3 + ```python class Solution: def movesToChessboard(self, board: List[List[int]]) -> int: @@ -141,6 +143,8 @@ class Solution: return -1 if t1 == -1 or t2 == -1 else t1 + t2 ``` +#### Java + ```java class Solution { private int n; @@ -198,6 +202,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -245,6 +251,8 @@ public: }; ``` +#### Go + ```go func movesToChessboard(board [][]int) int { n := len(board) diff --git a/solution/0700-0799/0782.Transform to Chessboard/README_EN.md b/solution/0700-0799/0782.Transform to Chessboard/README_EN.md index a627de2cb1ffe..6750bdb4d66bd 100644 --- a/solution/0700-0799/0782.Transform to Chessboard/README_EN.md +++ b/solution/0700-0799/0782.Transform to Chessboard/README_EN.md @@ -72,6 +72,8 @@ The second move swaps the second and third row. +#### Python3 + ```python class Solution: def movesToChessboard(self, board: List[List[int]]) -> int: @@ -116,6 +118,8 @@ class Solution: return -1 if t1 == -1 or t2 == -1 else t1 + t2 ``` +#### Java + ```java class Solution { private int n; @@ -173,6 +177,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -220,6 +226,8 @@ public: }; ``` +#### Go + ```go func movesToChessboard(board [][]int) int { n := len(board) diff --git a/solution/0700-0799/0783.Minimum Distance Between BST Nodes/README.md b/solution/0700-0799/0783.Minimum Distance Between BST Nodes/README.md index 246b6fcc5b1cd..10c0cb8778cbc 100644 --- a/solution/0700-0799/0783.Minimum Distance Between BST Nodes/README.md +++ b/solution/0700-0799/0783.Minimum Distance Between BST Nodes/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -200,6 +208,8 @@ func abs(x int) int { } ``` +#### JavaScript + ```js var minDiffInBST = function (root) { let ans = Number.MAX_SAFE_INTEGER, diff --git a/solution/0700-0799/0783.Minimum Distance Between BST Nodes/README_EN.md b/solution/0700-0799/0783.Minimum Distance Between BST Nodes/README_EN.md index 3535cb0083069..68cccd842c61b 100644 --- a/solution/0700-0799/0783.Minimum Distance Between BST Nodes/README_EN.md +++ b/solution/0700-0799/0783.Minimum Distance Between BST Nodes/README_EN.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -189,6 +197,8 @@ func abs(x int) int { } ``` +#### JavaScript + ```js var minDiffInBST = function (root) { let ans = Number.MAX_SAFE_INTEGER, diff --git a/solution/0700-0799/0784.Letter Case Permutation/README.md b/solution/0700-0799/0784.Letter Case Permutation/README.md index 0e15185199c59..21bb3efd3d638 100644 --- a/solution/0700-0799/0784.Letter Case Permutation/README.md +++ b/solution/0700-0799/0784.Letter Case Permutation/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def letterCasePermutation(self, s: str) -> List[str]: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List ans = new ArrayList<>(); @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func letterCasePermutation(s string) (ans []string) { t := []byte(s) @@ -151,6 +159,8 @@ func letterCasePermutation(s string) (ans []string) { } ``` +#### TypeScript + ```ts function letterCasePermutation(s: string): string[] { const n = s.length; @@ -172,6 +182,8 @@ function letterCasePermutation(s: string): string[] { } ``` +#### Rust + ```rust impl Solution { fn dfs(i: usize, cs: &mut Vec, res: &mut Vec) { @@ -213,6 +225,8 @@ impl Solution { +#### Python3 + ```python class Solution: def letterCasePermutation(self, s: str) -> List[str]: @@ -229,6 +243,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List letterCasePermutation(String s) { @@ -257,6 +273,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -282,6 +300,8 @@ public: }; ``` +#### Go + ```go func letterCasePermutation(s string) (ans []string) { n := 0 diff --git a/solution/0700-0799/0784.Letter Case Permutation/README_EN.md b/solution/0700-0799/0784.Letter Case Permutation/README_EN.md index 16d67ff3241d2..83f31b8877b2d 100644 --- a/solution/0700-0799/0784.Letter Case Permutation/README_EN.md +++ b/solution/0700-0799/0784.Letter Case Permutation/README_EN.md @@ -55,6 +55,8 @@ tags: +#### Python3 + ```python class Solution: def letterCasePermutation(self, s: str) -> List[str]: @@ -73,6 +75,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List ans = new ArrayList<>(); @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func letterCasePermutation(s string) (ans []string) { t := []byte(s) @@ -141,6 +149,8 @@ func letterCasePermutation(s string) (ans []string) { } ``` +#### TypeScript + ```ts function letterCasePermutation(s: string): string[] { const n = s.length; @@ -162,6 +172,8 @@ function letterCasePermutation(s: string): string[] { } ``` +#### Rust + ```rust impl Solution { fn dfs(i: usize, cs: &mut Vec, res: &mut Vec) { @@ -195,6 +207,8 @@ impl Solution { +#### Python3 + ```python class Solution: def letterCasePermutation(self, s: str) -> List[str]: @@ -211,6 +225,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List letterCasePermutation(String s) { @@ -239,6 +255,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -264,6 +282,8 @@ public: }; ``` +#### Go + ```go func letterCasePermutation(s string) (ans []string) { n := 0 diff --git a/solution/0700-0799/0785.Is Graph Bipartite/README.md b/solution/0700-0799/0785.Is Graph Bipartite/README.md index 0336b0ba96531..0bf747f9a685b 100644 --- a/solution/0700-0799/0785.Is Graph Bipartite/README.md +++ b/solution/0700-0799/0785.Is Graph Bipartite/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def isBipartite(self, graph: List[List[int]]) -> bool: @@ -95,6 +97,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { private int[] color; @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func isBipartite(graph [][]int) bool { n := len(graph) @@ -180,6 +188,8 @@ func isBipartite(graph [][]int) bool { } ``` +#### TypeScript + ```ts function isBipartite(graph: number[][]): boolean { const n = graph.length; @@ -209,6 +219,8 @@ function isBipartite(graph: number[][]): boolean { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -323,6 +335,8 @@ d[find(a)] = distance +#### Python3 + ```python class Solution: def isBipartite(self, graph: List[List[int]]) -> bool: @@ -340,6 +354,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { private int[] p; @@ -371,6 +387,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -397,6 +415,8 @@ public: }; ``` +#### Go + ```go func isBipartite(graph [][]int) bool { n := len(graph) @@ -423,6 +443,8 @@ func isBipartite(graph [][]int) bool { } ``` +#### TypeScript + ```ts function isBipartite(graph: number[][]): boolean { const n = graph.length; @@ -448,6 +470,8 @@ function isBipartite(graph: number[][]): boolean { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/0700-0799/0785.Is Graph Bipartite/README_EN.md b/solution/0700-0799/0785.Is Graph Bipartite/README_EN.md index 730c2b35d1b40..e21ddfe52013b 100644 --- a/solution/0700-0799/0785.Is Graph Bipartite/README_EN.md +++ b/solution/0700-0799/0785.Is Graph Bipartite/README_EN.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def isBipartite(self, graph: List[List[int]]) -> bool: @@ -91,6 +93,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { private int[] color; @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func isBipartite(graph [][]int) bool { n := len(graph) @@ -176,6 +184,8 @@ func isBipartite(graph [][]int) bool { } ``` +#### TypeScript + ```ts function isBipartite(graph: number[][]): boolean { const n = graph.length; @@ -205,6 +215,8 @@ function isBipartite(graph: number[][]): boolean { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -254,6 +266,8 @@ impl Solution { +#### Python3 + ```python class Solution: def isBipartite(self, graph: List[List[int]]) -> bool: @@ -271,6 +285,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { private int[] p; @@ -302,6 +318,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -328,6 +346,8 @@ public: }; ``` +#### Go + ```go func isBipartite(graph [][]int) bool { n := len(graph) @@ -354,6 +374,8 @@ func isBipartite(graph [][]int) bool { } ``` +#### TypeScript + ```ts function isBipartite(graph: number[][]): boolean { const n = graph.length; @@ -379,6 +401,8 @@ function isBipartite(graph: number[][]): boolean { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/0700-0799/0786.K-th Smallest Prime Fraction/README.md b/solution/0700-0799/0786.K-th Smallest Prime Fraction/README.md index 6abbf05ceb4c6..712541ebc89ec 100644 --- a/solution/0700-0799/0786.K-th Smallest Prime Fraction/README.md +++ b/solution/0700-0799/0786.K-th Smallest Prime Fraction/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def kthSmallestPrimeFraction(self, arr: List[int], k: int) -> List[int]: @@ -83,6 +85,8 @@ class Solution: return [arr[h[0][1]], arr[h[0][2]]] ``` +#### Java + ```java class Solution { public int[] kthSmallestPrimeFraction(int[] arr, int k) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go type frac struct{ x, y, i, j int } type hp []frac diff --git a/solution/0700-0799/0786.K-th Smallest Prime Fraction/README_EN.md b/solution/0700-0799/0786.K-th Smallest Prime Fraction/README_EN.md index 34d2fe52b8119..6a6f844e06e85 100644 --- a/solution/0700-0799/0786.K-th Smallest Prime Fraction/README_EN.md +++ b/solution/0700-0799/0786.K-th Smallest Prime Fraction/README_EN.md @@ -69,6 +69,8 @@ The third fraction is 2/5. +#### Python3 + ```python class Solution: def kthSmallestPrimeFraction(self, arr: List[int], k: int) -> List[int]: @@ -81,6 +83,8 @@ class Solution: return [arr[h[0][1]], arr[h[0][2]]] ``` +#### Java + ```java class Solution { public int[] kthSmallestPrimeFraction(int[] arr, int k) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go type frac struct{ x, y, i, j int } type hp []frac diff --git a/solution/0700-0799/0787.Cheapest Flights Within K Stops/README.md b/solution/0700-0799/0787.Cheapest Flights Within K Stops/README.md index 21cfee5aa3128..d2247c9c47319 100644 --- a/solution/0700-0799/0787.Cheapest Flights Within K Stops/README.md +++ b/solution/0700-0799/0787.Cheapest Flights Within K Stops/README.md @@ -79,6 +79,8 @@ src = 0, dst = 2, k = 0 +#### Python3 + ```python class Solution: def findCheapestPrice( @@ -94,6 +96,8 @@ class Solution: return -1 if dist[dst] == INF else dist[dst] ``` +#### Java + ```java class Solution { private static final int INF = 0x3f3f3f3f; @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func findCheapestPrice(n int, flights [][]int, src int, dst int, k int) int { const inf = 0x3f3f3f3f @@ -168,6 +176,8 @@ func findCheapestPrice(n int, flights [][]int, src int, dst int, k int) int { +#### Python3 + ```python class Solution: def findCheapestPrice( @@ -192,6 +202,8 @@ class Solution: return -1 if ans >= inf else ans ``` +#### Java + ```java class Solution { private int[][] memo; @@ -236,6 +248,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -268,6 +282,8 @@ public: }; ``` +#### Go + ```go func findCheapestPrice(n int, flights [][]int, src int, dst int, k int) int { n += 10 diff --git a/solution/0700-0799/0787.Cheapest Flights Within K Stops/README_EN.md b/solution/0700-0799/0787.Cheapest Flights Within K Stops/README_EN.md index 8afa6969e5c9a..9c1b03b9e86fd 100644 --- a/solution/0700-0799/0787.Cheapest Flights Within K Stops/README_EN.md +++ b/solution/0700-0799/0787.Cheapest Flights Within K Stops/README_EN.md @@ -82,6 +82,8 @@ The optimal path with no stops from city 0 to 2 is marked in red and has cost 50 +#### Python3 + ```python class Solution: def findCheapestPrice( @@ -97,6 +99,8 @@ class Solution: return -1 if dist[dst] == INF else dist[dst] ``` +#### Java + ```java class Solution { private static final int INF = 0x3f3f3f3f; @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func findCheapestPrice(n int, flights [][]int, src int, dst int, k int) int { const inf = 0x3f3f3f3f @@ -171,6 +179,8 @@ func findCheapestPrice(n int, flights [][]int, src int, dst int, k int) int { +#### Python3 + ```python class Solution: def findCheapestPrice( @@ -195,6 +205,8 @@ class Solution: return -1 if ans >= inf else ans ``` +#### Java + ```java class Solution { private int[][] memo; @@ -239,6 +251,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -271,6 +285,8 @@ public: }; ``` +#### Go + ```go func findCheapestPrice(n int, flights [][]int, src int, dst int, k int) int { n += 10 diff --git a/solution/0700-0799/0788.Rotated Digits/README.md b/solution/0700-0799/0788.Rotated Digits/README.md index d91680ddc7403..a5b0b24187718 100644 --- a/solution/0700-0799/0788.Rotated Digits/README.md +++ b/solution/0700-0799/0788.Rotated Digits/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def rotatedDigits(self, n: int) -> int: @@ -85,6 +87,8 @@ class Solution: return sum(check(i) for i in range(1, n + 1)) ``` +#### Java + ```java class Solution { private int[] d = new int[] {0, 1, 5, -1, -1, 2, 9, -1, 8, 6}; @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func rotatedDigits(n int) int { d := []int{0, 1, 5, -1, -1, 2, 9, -1, 8, 6} @@ -220,6 +228,8 @@ $$ +#### Python3 + ```python class Solution: def rotatedDigits(self, n: int) -> int: @@ -245,6 +255,8 @@ class Solution: return dfs(l, 0, True) ``` +#### Java + ```java class Solution { private int[] a = new int[6]; @@ -287,6 +299,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -328,6 +342,8 @@ public: }; ``` +#### Go + ```go func rotatedDigits(n int) int { a := make([]int, 6) diff --git a/solution/0700-0799/0788.Rotated Digits/README_EN.md b/solution/0700-0799/0788.Rotated Digits/README_EN.md index 93cd538cc9cb2..4c75e42b35b27 100644 --- a/solution/0700-0799/0788.Rotated Digits/README_EN.md +++ b/solution/0700-0799/0788.Rotated Digits/README_EN.md @@ -71,6 +71,8 @@ Note that 1 and 10 are not good numbers, since they remain unchanged after rotat +#### Python3 + ```python class Solution: def rotatedDigits(self, n: int) -> int: @@ -90,6 +92,8 @@ class Solution: return sum(check(i) for i in range(1, n + 1)) ``` +#### Java + ```java class Solution { private int[] d = new int[] {0, 1, 5, -1, -1, 2, 9, -1, 8, 6}; @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func rotatedDigits(n int) int { d := []int{0, 1, 5, -1, -1, 2, 9, -1, 8, 6} @@ -187,6 +195,8 @@ func rotatedDigits(n int) int { +#### Python3 + ```python class Solution: def rotatedDigits(self, n: int) -> int: @@ -212,6 +222,8 @@ class Solution: return dfs(l, 0, True) ``` +#### Java + ```java class Solution { private int[] a = new int[6]; @@ -254,6 +266,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -295,6 +309,8 @@ public: }; ``` +#### Go + ```go func rotatedDigits(n int) int { a := make([]int, 6) diff --git a/solution/0700-0799/0789.Escape The Ghosts/README.md b/solution/0700-0799/0789.Escape The Ghosts/README.md index cd86b8a1e2e46..98fd553d473ca 100644 --- a/solution/0700-0799/0789.Escape The Ghosts/README.md +++ b/solution/0700-0799/0789.Escape The Ghosts/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def escapeGhosts(self, ghosts: List[List[int]], target: List[int]) -> bool: @@ -84,6 +86,8 @@ class Solution: return all(abs(tx - x) + abs(ty - y) > abs(tx) + abs(ty) for x, y in ghosts) ``` +#### Java + ```java class Solution { public boolean escapeGhosts(int[][] ghosts, int[] target) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func escapeGhosts(ghosts [][]int, target []int) bool { tx, ty := target[0], target[1] @@ -135,6 +143,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function escapeGhosts(ghosts: number[][], target: number[]): boolean { const [tx, ty] = target; diff --git a/solution/0700-0799/0789.Escape The Ghosts/README_EN.md b/solution/0700-0799/0789.Escape The Ghosts/README_EN.md index 298ac9462381d..2d48cee18fb1a 100644 --- a/solution/0700-0799/0789.Escape The Ghosts/README_EN.md +++ b/solution/0700-0799/0789.Escape The Ghosts/README_EN.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def escapeGhosts(self, ghosts: List[List[int]], target: List[int]) -> bool: @@ -79,6 +81,8 @@ class Solution: return all(abs(tx - x) + abs(ty - y) > abs(tx) + abs(ty) for x, y in ghosts) ``` +#### Java + ```java class Solution { public boolean escapeGhosts(int[][] ghosts, int[] target) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func escapeGhosts(ghosts [][]int, target []int) bool { tx, ty := target[0], target[1] @@ -130,6 +138,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function escapeGhosts(ghosts: number[][], target: number[]): boolean { const [tx, ty] = target; diff --git a/solution/0700-0799/0790.Domino and Tromino Tiling/README.md b/solution/0700-0799/0790.Domino and Tromino Tiling/README.md index 3aff38dd5452b..91eb9e51d0ee0 100644 --- a/solution/0700-0799/0790.Domino and Tromino Tiling/README.md +++ b/solution/0700-0799/0790.Domino and Tromino Tiling/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def numTilings(self, n: int) -> int: @@ -117,6 +119,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { public int numTilings(int n) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func numTilings(n int) int { f := [4]int{} @@ -182,6 +190,8 @@ func numTilings(n int) int { +#### Python3 + ```python class Solution: def numTilings(self, n: int) -> int: diff --git a/solution/0700-0799/0790.Domino and Tromino Tiling/README_EN.md b/solution/0700-0799/0790.Domino and Tromino Tiling/README_EN.md index b4592bd3a6246..49dcfa9bb1f6f 100644 --- a/solution/0700-0799/0790.Domino and Tromino Tiling/README_EN.md +++ b/solution/0700-0799/0790.Domino and Tromino Tiling/README_EN.md @@ -55,6 +55,8 @@ tags: +#### Python3 + ```python class Solution: def numTilings(self, n: int) -> int: @@ -82,6 +84,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { public int numTilings(int n) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func numTilings(n int) int { f := [4]int{} @@ -147,6 +155,8 @@ func numTilings(n int) int { +#### Python3 + ```python class Solution: def numTilings(self, n: int) -> int: diff --git a/solution/0700-0799/0791.Custom Sort String/README.md b/solution/0700-0799/0791.Custom Sort String/README.md index c414fea544c9c..3df09a7767b67 100644 --- a/solution/0700-0799/0791.Custom Sort String/README.md +++ b/solution/0700-0799/0791.Custom Sort String/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def customSortString(self, order: str, s: str) -> str: @@ -77,6 +79,8 @@ class Solution: return ''.join(sorted(s, key=lambda x: d.get(x, 0))) ``` +#### Java + ```java class Solution { public String customSortString(String order, String s) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func customSortString(order string, s string) string { d := [26]int{} @@ -118,6 +126,8 @@ func customSortString(order string, s string) string { } ``` +#### TypeScript + ```ts function customSortString(order: string, s: string): string { const toIndex = (c: string) => c.charCodeAt(0) - 'a'.charCodeAt(0); @@ -130,6 +140,8 @@ function customSortString(order: string, s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn custom_sort_string(order: String, s: String) -> String { @@ -163,6 +175,8 @@ impl Solution { +#### Python3 + ```python class Solution: def customSortString(self, order: str, s: str) -> str: @@ -176,6 +190,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String customSortString(String order, String s) { @@ -200,6 +216,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -216,6 +234,8 @@ public: }; ``` +#### Go + ```go func customSortString(order string, s string) string { cnt := [26]int{} @@ -238,6 +258,8 @@ func customSortString(order string, s string) string { } ``` +#### TypeScript + ```ts function customSortString(order: string, s: string): string { const toIndex = (c: string) => c.charCodeAt(0) - 'a'.charCodeAt(0); @@ -259,6 +281,8 @@ function customSortString(order: string, s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn custom_sort_string(order: String, s: String) -> String { diff --git a/solution/0700-0799/0791.Custom Sort String/README_EN.md b/solution/0700-0799/0791.Custom Sort String/README_EN.md index 9625a0b5d07fb..752080a108374 100644 --- a/solution/0700-0799/0791.Custom Sort String/README_EN.md +++ b/solution/0700-0799/0791.Custom Sort String/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def customSortString(self, order: str, s: str) -> str: @@ -76,6 +78,8 @@ class Solution: return ''.join(sorted(s, key=lambda x: d.get(x, 0))) ``` +#### Java + ```java class Solution { public String customSortString(String order, String s) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func customSortString(order string, s string) string { d := [26]int{} @@ -117,6 +125,8 @@ func customSortString(order string, s string) string { } ``` +#### TypeScript + ```ts function customSortString(order: string, s: string): string { const toIndex = (c: string) => c.charCodeAt(0) - 'a'.charCodeAt(0); @@ -129,6 +139,8 @@ function customSortString(order: string, s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn custom_sort_string(order: String, s: String) -> String { @@ -156,6 +168,8 @@ impl Solution { +#### Python3 + ```python class Solution: def customSortString(self, order: str, s: str) -> str: @@ -169,6 +183,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String customSortString(String order, String s) { @@ -193,6 +209,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -209,6 +227,8 @@ public: }; ``` +#### Go + ```go func customSortString(order string, s string) string { cnt := [26]int{} @@ -231,6 +251,8 @@ func customSortString(order string, s string) string { } ``` +#### TypeScript + ```ts function customSortString(order: string, s: string): string { const toIndex = (c: string) => c.charCodeAt(0) - 'a'.charCodeAt(0); @@ -252,6 +274,8 @@ function customSortString(order: string, s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn custom_sort_string(order: String, s: String) -> String { diff --git a/solution/0700-0799/0792.Number of Matching Subsequences/README.md b/solution/0700-0799/0792.Number of Matching Subsequences/README.md index b467f392340e2..abb6f030eb3ac 100644 --- a/solution/0700-0799/0792.Number of Matching Subsequences/README.md +++ b/solution/0700-0799/0792.Number of Matching Subsequences/README.md @@ -93,6 +93,8 @@ b: ["bb"] +#### Python3 + ```python class Solution: def numMatchingSubseq(self, s: str, words: List[str]) -> int: @@ -110,6 +112,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numMatchingSubseq(String s, String[] words) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func numMatchingSubseq(s string, words []string) (ans int) { d := [26][]string{} @@ -199,6 +207,8 @@ func numMatchingSubseq(s string, words []string) (ans int) { +#### Python3 + ```python class Solution: def numMatchingSubseq(self, s: str, words: List[str]) -> int: @@ -217,6 +227,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numMatchingSubseq(String s, String[] words) { @@ -243,6 +255,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -266,6 +280,8 @@ public: }; ``` +#### Go + ```go func numMatchingSubseq(s string, words []string) (ans int) { type pair struct{ i, j int } @@ -299,6 +315,8 @@ func numMatchingSubseq(s string, words []string) (ans int) { +#### Python3 + ```python class Solution: def numMatchingSubseq(self, s: str, words: List[str]) -> int: @@ -317,6 +335,8 @@ class Solution: return sum(check(w) for w in words) ``` +#### Java + ```java class Solution { private List[] d = new List[26]; @@ -363,6 +383,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -386,6 +408,8 @@ public: }; ``` +#### Go + ```go func numMatchingSubseq(s string, words []string) (ans int) { d := [26][]int{} diff --git a/solution/0700-0799/0792.Number of Matching Subsequences/README_EN.md b/solution/0700-0799/0792.Number of Matching Subsequences/README_EN.md index 6bcdac139e81e..0f0b155212d86 100644 --- a/solution/0700-0799/0792.Number of Matching Subsequences/README_EN.md +++ b/solution/0700-0799/0792.Number of Matching Subsequences/README_EN.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def numMatchingSubseq(self, s: str, words: List[str]) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numMatchingSubseq(String s, String[] words) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func numMatchingSubseq(s string, words []string) (ans int) { d := [26][]string{} @@ -162,6 +170,8 @@ func numMatchingSubseq(s string, words []string) (ans int) { +#### Python3 + ```python class Solution: def numMatchingSubseq(self, s: str, words: List[str]) -> int: @@ -180,6 +190,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numMatchingSubseq(String s, String[] words) { @@ -206,6 +218,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -229,6 +243,8 @@ public: }; ``` +#### Go + ```go func numMatchingSubseq(s string, words []string) (ans int) { type pair struct{ i, j int } @@ -262,6 +278,8 @@ func numMatchingSubseq(s string, words []string) (ans int) { +#### Python3 + ```python class Solution: def numMatchingSubseq(self, s: str, words: List[str]) -> int: @@ -280,6 +298,8 @@ class Solution: return sum(check(w) for w in words) ``` +#### Java + ```java class Solution { private List[] d = new List[26]; @@ -326,6 +346,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -349,6 +371,8 @@ public: }; ``` +#### Go + ```go func numMatchingSubseq(s string, words []string) (ans int) { d := [26][]int{} diff --git a/solution/0700-0799/0793.Preimage Size of Factorial Zeroes Function/README.md b/solution/0700-0799/0793.Preimage Size of Factorial Zeroes Function/README.md index e686df8b765c8..d76d9f6662b4e 100644 --- a/solution/0700-0799/0793.Preimage Size of Factorial Zeroes Function/README.md +++ b/solution/0700-0799/0793.Preimage Size of Factorial Zeroes Function/README.md @@ -85,6 +85,8 @@ $$ +#### Python3 + ```python class Solution: def preimageSizeFZF(self, k: int) -> int: @@ -99,6 +101,8 @@ class Solution: return g(k + 1) - g(k) ``` +#### Java + ```java class Solution { public int preimageSizeFZF(int k) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func preimageSizeFZF(k int) int { f := func(x int) int { diff --git a/solution/0700-0799/0793.Preimage Size of Factorial Zeroes Function/README_EN.md b/solution/0700-0799/0793.Preimage Size of Factorial Zeroes Function/README_EN.md index 837b853f420ea..b16c90f6427e5 100644 --- a/solution/0700-0799/0793.Preimage Size of Factorial Zeroes Function/README_EN.md +++ b/solution/0700-0799/0793.Preimage Size of Factorial Zeroes Function/README_EN.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def preimageSizeFZF(self, k: int) -> int: @@ -80,6 +82,8 @@ class Solution: return g(k + 1) - g(k) ``` +#### Java + ```java class Solution { public int preimageSizeFZF(int k) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func preimageSizeFZF(k int) int { f := func(x int) int { diff --git a/solution/0700-0799/0794.Valid Tic-Tac-Toe State/README.md b/solution/0700-0799/0794.Valid Tic-Tac-Toe State/README.md index 4fa1b08db6ee5..0b17001bcfa5a 100644 --- a/solution/0700-0799/0794.Valid Tic-Tac-Toe State/README.md +++ b/solution/0700-0799/0794.Valid Tic-Tac-Toe State/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def validTicTacToe(self, board: List[str]) -> bool: @@ -108,6 +110,8 @@ class Solution: return not (win('O') and x != o) ``` +#### Java + ```java class Solution { private String[] board; @@ -153,6 +157,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -179,6 +185,8 @@ public: }; ``` +#### Go + ```go func validTicTacToe(board []string) bool { var x, o int @@ -215,6 +223,8 @@ func validTicTacToe(board []string) bool { } ``` +#### JavaScript + ```js /** * @param {string[]} board diff --git a/solution/0700-0799/0794.Valid Tic-Tac-Toe State/README_EN.md b/solution/0700-0799/0794.Valid Tic-Tac-Toe State/README_EN.md index 7adf34b54a19e..8e804ecf8beb5 100644 --- a/solution/0700-0799/0794.Valid Tic-Tac-Toe State/README_EN.md +++ b/solution/0700-0799/0794.Valid Tic-Tac-Toe State/README_EN.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def validTicTacToe(self, board: List[str]) -> bool: @@ -97,6 +99,8 @@ class Solution: return not (win('O') and x != o) ``` +#### Java + ```java class Solution { private String[] board; @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func validTicTacToe(board []string) bool { var x, o int @@ -204,6 +212,8 @@ func validTicTacToe(board []string) bool { } ``` +#### JavaScript + ```js /** * @param {string[]} board diff --git a/solution/0700-0799/0795.Number of Subarrays with Bounded Maximum/README.md b/solution/0700-0799/0795.Number of Subarrays with Bounded Maximum/README.md index 01249b3bd890b..3e8a49f186c3e 100644 --- a/solution/0700-0799/0795.Number of Subarrays with Bounded Maximum/README.md +++ b/solution/0700-0799/0795.Number of Subarrays with Bounded Maximum/README.md @@ -74,6 +74,8 @@ $$ +#### Python3 + ```python class Solution: def numSubarrayBoundedMax(self, nums: List[int], left: int, right: int) -> int: @@ -87,6 +89,8 @@ class Solution: return f(right) - f(left - 1) ``` +#### Java + ```java class Solution { public int numSubarrayBoundedMax(int[] nums, int left, int right) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func numSubarrayBoundedMax(nums []int, left int, right int) int { f := func(x int) (cnt int) { @@ -158,6 +166,8 @@ func numSubarrayBoundedMax(nums []int, left int, right int) int { +#### Python3 + ```python class Solution: def numSubarrayBoundedMax(self, nums: List[int], left: int, right: int) -> int: @@ -182,6 +192,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public int numSubarrayBoundedMax(int[] nums, int left, int right) { @@ -223,6 +235,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -255,6 +269,8 @@ public: }; ``` +#### Go + ```go func numSubarrayBoundedMax(nums []int, left int, right int) (ans int) { n := len(nums) diff --git a/solution/0700-0799/0795.Number of Subarrays with Bounded Maximum/README_EN.md b/solution/0700-0799/0795.Number of Subarrays with Bounded Maximum/README_EN.md index dadbed5f5d90c..c4767267d5e59 100644 --- a/solution/0700-0799/0795.Number of Subarrays with Bounded Maximum/README_EN.md +++ b/solution/0700-0799/0795.Number of Subarrays with Bounded Maximum/README_EN.md @@ -56,6 +56,8 @@ tags: +#### Python3 + ```python class Solution: def numSubarrayBoundedMax(self, nums: List[int], left: int, right: int) -> int: @@ -69,6 +71,8 @@ class Solution: return f(right) - f(left - 1) ``` +#### Java + ```java class Solution { public int numSubarrayBoundedMax(int[] nums, int left, int right) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -103,6 +109,8 @@ public: }; ``` +#### Go + ```go func numSubarrayBoundedMax(nums []int, left int, right int) int { f := func(x int) (cnt int) { @@ -130,6 +138,8 @@ func numSubarrayBoundedMax(nums []int, left int, right int) int { +#### Python3 + ```python class Solution: def numSubarrayBoundedMax(self, nums: List[int], left: int, right: int) -> int: @@ -154,6 +164,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public int numSubarrayBoundedMax(int[] nums, int left, int right) { @@ -195,6 +207,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -227,6 +241,8 @@ public: }; ``` +#### Go + ```go func numSubarrayBoundedMax(nums []int, left int, right int) (ans int) { n := len(nums) diff --git a/solution/0700-0799/0796.Rotate String/README.md b/solution/0700-0799/0796.Rotate String/README.md index 9110a15a3771b..e68f94d6f55d7 100644 --- a/solution/0700-0799/0796.Rotate String/README.md +++ b/solution/0700-0799/0796.Rotate String/README.md @@ -60,12 +60,16 @@ tags: +#### Python3 + ```python class Solution: def rotateString(self, s: str, goal: str) -> bool: return len(s) == len(goal) and goal in s + s ``` +#### Java + ```java class Solution { public boolean rotateString(String s, String goal) { @@ -74,6 +78,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -83,18 +89,24 @@ public: }; ``` +#### Go + ```go func rotateString(s string, goal string) bool { return len(s) == len(goal) && strings.Contains(s+s, goal) } ``` +#### TypeScript + ```ts function rotateString(s: string, goal: string): boolean { return s.length === goal.length && (goal + goal).includes(s); } ``` +#### Rust + ```rust impl Solution { pub fn rotate_string(s: String, goal: String) -> bool { @@ -103,6 +115,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0700-0799/0796.Rotate String/README_EN.md b/solution/0700-0799/0796.Rotate String/README_EN.md index fc71c945ba67e..37c88137b0790 100644 --- a/solution/0700-0799/0796.Rotate String/README_EN.md +++ b/solution/0700-0799/0796.Rotate String/README_EN.md @@ -51,12 +51,16 @@ tags: +#### Python3 + ```python class Solution: def rotateString(self, s: str, goal: str) -> bool: return len(s) == len(goal) and goal in s + s ``` +#### Java + ```java class Solution { public boolean rotateString(String s, String goal) { @@ -65,6 +69,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -74,18 +80,24 @@ public: }; ``` +#### Go + ```go func rotateString(s string, goal string) bool { return len(s) == len(goal) && strings.Contains(s+s, goal) } ``` +#### TypeScript + ```ts function rotateString(s: string, goal: string): boolean { return s.length === goal.length && (goal + goal).includes(s); } ``` +#### Rust + ```rust impl Solution { pub fn rotate_string(s: String, goal: String) -> bool { @@ -94,6 +106,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0700-0799/0797.All Paths From Source to Target/README.md b/solution/0700-0799/0797.All Paths From Source to Target/README.md index 805ab13bc6936..f8d406b5fa3e5 100644 --- a/solution/0700-0799/0797.All Paths From Source to Target/README.md +++ b/solution/0700-0799/0797.All Paths From Source to Target/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> allPathsSourceTarget(int[][] graph) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func allPathsSourceTarget(graph [][]int) [][]int { var path []int @@ -163,6 +171,8 @@ func allPathsSourceTarget(graph [][]int) [][]int { } ``` +#### Rust + ```rust impl Solution { fn dfs(i: usize, path: &mut Vec, res: &mut Vec>, graph: &Vec>) { @@ -184,6 +194,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} graph @@ -221,6 +233,8 @@ var allPathsSourceTarget = function (graph) { +#### Python3 + ```python class Solution: def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]: @@ -238,6 +252,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans; diff --git a/solution/0700-0799/0797.All Paths From Source to Target/README_EN.md b/solution/0700-0799/0797.All Paths From Source to Target/README_EN.md index 6002b99c68abc..953e36379cc03 100644 --- a/solution/0700-0799/0797.All Paths From Source to Target/README_EN.md +++ b/solution/0700-0799/0797.All Paths From Source to Target/README_EN.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> allPathsSourceTarget(int[][] graph) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func allPathsSourceTarget(graph [][]int) [][]int { var path []int @@ -155,6 +163,8 @@ func allPathsSourceTarget(graph [][]int) [][]int { } ``` +#### Rust + ```rust impl Solution { fn dfs(i: usize, path: &mut Vec, res: &mut Vec>, graph: &Vec>) { @@ -176,6 +186,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} graph @@ -213,6 +225,8 @@ var allPathsSourceTarget = function (graph) { +#### Python3 + ```python class Solution: def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]: @@ -230,6 +244,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List> ans; diff --git a/solution/0700-0799/0798.Smallest Rotation with Highest Score/README.md b/solution/0700-0799/0798.Smallest Rotation with Highest Score/README.md index adb4c4ba98808..49b661e783d4a 100644 --- a/solution/0700-0799/0798.Smallest Rotation with Highest Score/README.md +++ b/solution/0700-0799/0798.Smallest Rotation with Highest Score/README.md @@ -72,6 +72,8 @@ nums 无论怎么变化总是有 3 分。 +#### Python3 + ```python class Solution: def bestRotation(self, nums: List[int]) -> int: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int bestRotation(int[] nums) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func bestRotation(nums []int) int { n := len(nums) diff --git a/solution/0700-0799/0798.Smallest Rotation with Highest Score/README_EN.md b/solution/0700-0799/0798.Smallest Rotation with Highest Score/README_EN.md index a0c2f8719c839..81ba43e673f94 100644 --- a/solution/0700-0799/0798.Smallest Rotation with Highest Score/README_EN.md +++ b/solution/0700-0799/0798.Smallest Rotation with Highest Score/README_EN.md @@ -67,6 +67,8 @@ So we will choose the smallest k, which is 0. +#### Python3 + ```python class Solution: def bestRotation(self, nums: List[int]) -> int: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int bestRotation(int[] nums) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func bestRotation(nums []int) int { n := len(nums) diff --git a/solution/0700-0799/0799.Champagne Tower/README.md b/solution/0700-0799/0799.Champagne Tower/README.md index c2215f74fb4ce..10cd8b98e16a0 100644 --- a/solution/0700-0799/0799.Champagne Tower/README.md +++ b/solution/0700-0799/0799.Champagne Tower/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float: @@ -95,6 +97,8 @@ class Solution: return f[query_row][query_glass] ``` +#### Java + ```java class Solution { public double champagneTower(int poured, int query_row, int query_glass) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func champagneTower(poured int, query_row int, query_glass int) float64 { f := [101][101]float64{} @@ -154,6 +162,8 @@ func champagneTower(poured int, query_row int, query_glass int) float64 { } ``` +#### TypeScript + ```ts function champagneTower(poured: number, query_row: number, query_glass: number): number { let row = [poured]; @@ -171,6 +181,8 @@ function champagneTower(poured: number, query_row: number, query_glass: number): } ``` +#### Rust + ```rust impl Solution { pub fn champagne_tower(poured: i32, query_row: i32, query_glass: i32) -> f64 { @@ -202,6 +214,8 @@ impl Solution { +#### Python3 + ```python class Solution: def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float: @@ -217,6 +231,8 @@ class Solution: return min(1, f[query_glass]) ``` +#### Java + ```java class Solution { public double champagneTower(int poured, int query_row, int query_glass) { @@ -237,6 +253,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -259,6 +277,8 @@ public: }; ``` +#### Go + ```go func champagneTower(poured int, query_row int, query_glass int) float64 { f := []float64{float64(poured)} diff --git a/solution/0700-0799/0799.Champagne Tower/README_EN.md b/solution/0700-0799/0799.Champagne Tower/README_EN.md index 05aaa4ed1d0f1..c04fa21334900 100644 --- a/solution/0700-0799/0799.Champagne Tower/README_EN.md +++ b/solution/0700-0799/0799.Champagne Tower/README_EN.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float: @@ -99,6 +101,8 @@ class Solution: return f[query_row][query_glass] ``` +#### Java + ```java class Solution { public double champagneTower(int poured, int query_row, int query_glass) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func champagneTower(poured int, query_row int, query_glass int) float64 { f := [101][101]float64{} @@ -158,6 +166,8 @@ func champagneTower(poured int, query_row int, query_glass int) float64 { } ``` +#### TypeScript + ```ts function champagneTower(poured: number, query_row: number, query_glass: number): number { let row = [poured]; @@ -175,6 +185,8 @@ function champagneTower(poured: number, query_row: number, query_glass: number): } ``` +#### Rust + ```rust impl Solution { pub fn champagne_tower(poured: i32, query_row: i32, query_glass: i32) -> f64 { @@ -206,6 +218,8 @@ impl Solution { +#### Python3 + ```python class Solution: def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float: @@ -221,6 +235,8 @@ class Solution: return min(1, f[query_glass]) ``` +#### Java + ```java class Solution { public double champagneTower(int poured, int query_row, int query_glass) { @@ -241,6 +257,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -263,6 +281,8 @@ public: }; ``` +#### Go + ```go func champagneTower(poured int, query_row int, query_glass int) float64 { f := []float64{float64(poured)} diff --git a/solution/0800-0899/0800.Similar RGB Color/README.md b/solution/0800-0899/0800.Similar RGB Color/README.md index f477ed48e88c8..415837db64935 100644 --- a/solution/0800-0899/0800.Similar RGB Color/README.md +++ b/solution/0800-0899/0800.Similar RGB Color/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def similarRGB(self, color: str) -> str: @@ -82,6 +84,8 @@ class Solution: return f'#{f(a)}{f(b)}{f(c)}' ``` +#### Java + ```java class Solution { public String similarRGB(String color) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### Go + ```go func similarRGB(color string) string { f := func(x string) string { diff --git a/solution/0800-0899/0800.Similar RGB Color/README_EN.md b/solution/0800-0899/0800.Similar RGB Color/README_EN.md index d7377797e3631..dc93630808eb7 100644 --- a/solution/0800-0899/0800.Similar RGB Color/README_EN.md +++ b/solution/0800-0899/0800.Similar RGB Color/README_EN.md @@ -67,6 +67,8 @@ This is the highest among any shorthand color. +#### Python3 + ```python class Solution: def similarRGB(self, color: str) -> str: @@ -80,6 +82,8 @@ class Solution: return f'#{f(a)}{f(b)}{f(c)}' ``` +#### Java + ```java class Solution { public String similarRGB(String color) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### Go + ```go func similarRGB(color string) string { f := func(x string) string { diff --git a/solution/0800-0899/0801.Minimum Swaps To Make Sequences Increasing/README.md b/solution/0800-0899/0801.Minimum Swaps To Make Sequences Increasing/README.md index c909e15605b2a..88d99c4cc6c2b 100644 --- a/solution/0800-0899/0801.Minimum Swaps To Make Sequences Increasing/README.md +++ b/solution/0800-0899/0801.Minimum Swaps To Make Sequences Increasing/README.md @@ -86,6 +86,8 @@ A = [1, 3, 5, 7] , B = [1, 2, 3, 4] +#### Python3 + ```python class Solution: def minSwap(self, nums1: List[int], nums2: List[int]) -> int: @@ -101,6 +103,8 @@ class Solution: return min(a, b) ``` +#### Java + ```java class Solution { public int minSwap(int[] nums1, int[] nums2) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func minSwap(nums1 []int, nums2 []int) int { a, b, n := 0, 1, len(nums1) diff --git a/solution/0800-0899/0801.Minimum Swaps To Make Sequences Increasing/README_EN.md b/solution/0800-0899/0801.Minimum Swaps To Make Sequences Increasing/README_EN.md index aee5fe903d26a..33d47cfbc5e53 100644 --- a/solution/0800-0899/0801.Minimum Swaps To Make Sequences Increasing/README_EN.md +++ b/solution/0800-0899/0801.Minimum Swaps To Make Sequences Increasing/README_EN.md @@ -65,6 +65,8 @@ which are both strictly increasing. +#### Python3 + ```python class Solution: def minSwap(self, nums1: List[int], nums2: List[int]) -> int: @@ -80,6 +82,8 @@ class Solution: return min(a, b) ``` +#### Java + ```java class Solution { public int minSwap(int[] nums1, int[] nums2) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func minSwap(nums1 []int, nums2 []int) int { a, b, n := 0, 1, len(nums1) diff --git a/solution/0800-0899/0802.Find Eventual Safe States/README.md b/solution/0800-0899/0802.Find Eventual Safe States/README.md index 80398f52c03f2..efac1c82f3f3f 100644 --- a/solution/0800-0899/0802.Find Eventual Safe States/README.md +++ b/solution/0800-0899/0802.Find Eventual Safe States/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def eventualSafeNodes(self, graph: List[List[int]]) -> List[int]: @@ -97,6 +99,8 @@ class Solution: return [i for i, v in enumerate(indeg) if v == 0] ``` +#### Java + ```java class Solution { public List eventualSafeNodes(int[][] graph) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func eventualSafeNodes(graph [][]int) []int { n := len(graph) @@ -195,6 +203,8 @@ func eventualSafeNodes(graph [][]int) []int { } ``` +#### JavaScript + ```js /** * @param {number[][]} graph @@ -248,6 +258,8 @@ var eventualSafeNodes = function (graph) { +#### Python3 + ```python class Solution: def eventualSafeNodes(self, graph: List[List[int]]) -> List[int]: @@ -266,6 +278,8 @@ class Solution: return [i for i in range(n) if dfs(i)] ``` +#### Java + ```java class Solution { private int[] color; @@ -300,6 +314,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -325,6 +341,8 @@ public: }; ``` +#### Go + ```go func eventualSafeNodes(graph [][]int) []int { n := len(graph) @@ -353,6 +371,8 @@ func eventualSafeNodes(graph [][]int) []int { } ``` +#### JavaScript + ```js /** * @param {number[][]} graph diff --git a/solution/0800-0899/0802.Find Eventual Safe States/README_EN.md b/solution/0800-0899/0802.Find Eventual Safe States/README_EN.md index 39d6a58e325bd..274e5ba819082 100644 --- a/solution/0800-0899/0802.Find Eventual Safe States/README_EN.md +++ b/solution/0800-0899/0802.Find Eventual Safe States/README_EN.md @@ -67,6 +67,8 @@ Only node 4 is a terminal node, and every path starting at node 4 leads to node +#### Python3 + ```python class Solution: def eventualSafeNodes(self, graph: List[List[int]]) -> List[int]: @@ -86,6 +88,8 @@ class Solution: return [i for i, v in enumerate(indeg) if v == 0] ``` +#### Java + ```java class Solution { public List eventualSafeNodes(int[][] graph) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func eventualSafeNodes(graph [][]int) []int { n := len(graph) @@ -184,6 +192,8 @@ func eventualSafeNodes(graph [][]int) []int { } ``` +#### JavaScript + ```js /** * @param {number[][]} graph @@ -231,6 +241,8 @@ var eventualSafeNodes = function (graph) { +#### Python3 + ```python class Solution: def eventualSafeNodes(self, graph: List[List[int]]) -> List[int]: @@ -249,6 +261,8 @@ class Solution: return [i for i in range(n) if dfs(i)] ``` +#### Java + ```java class Solution { private int[] color; @@ -283,6 +297,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -308,6 +324,8 @@ public: }; ``` +#### Go + ```go func eventualSafeNodes(graph [][]int) []int { n := len(graph) @@ -336,6 +354,8 @@ func eventualSafeNodes(graph [][]int) []int { } ``` +#### JavaScript + ```js /** * @param {number[][]} graph diff --git a/solution/0800-0899/0803.Bricks Falling When Hit/README.md b/solution/0800-0899/0803.Bricks Falling When Hit/README.md index 640df560e4ed0..2c3704bb91431 100644 --- a/solution/0800-0899/0803.Bricks Falling When Hit/README.md +++ b/solution/0800-0899/0803.Bricks Falling When Hit/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class Solution: def hitBricks(self, grid: List[List[int]], hits: List[List[int]]) -> List[int]: @@ -145,6 +147,8 @@ class Solution: return ans[::-1] ``` +#### Java + ```java class Solution { private int[] p; @@ -230,6 +234,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -293,6 +299,8 @@ public: }; ``` +#### Go + ```go func hitBricks(grid [][]int, hits [][]int) []int { m, n := len(grid), len(grid[0]) diff --git a/solution/0800-0899/0803.Bricks Falling When Hit/README_EN.md b/solution/0800-0899/0803.Bricks Falling When Hit/README_EN.md index 02357ac5944af..54df95eafe98c 100644 --- a/solution/0800-0899/0803.Bricks Falling When Hit/README_EN.md +++ b/solution/0800-0899/0803.Bricks Falling When Hit/README_EN.md @@ -95,6 +95,8 @@ Hence the result is [0,0]. +#### Python3 + ```python class Solution: def hitBricks(self, grid: List[List[int]], hits: List[List[int]]) -> List[int]: @@ -144,6 +146,8 @@ class Solution: return ans[::-1] ``` +#### Java + ```java class Solution { private int[] p; @@ -229,6 +233,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -292,6 +298,8 @@ public: }; ``` +#### Go + ```go func hitBricks(grid [][]int, hits [][]int) []int { m, n := len(grid), len(grid[0]) diff --git a/solution/0800-0899/0804.Unique Morse Code Words/README.md b/solution/0800-0899/0804.Unique Morse Code Words/README.md index 2719073f2e775..131a815ae007c 100644 --- a/solution/0800-0899/0804.Unique Morse Code Words/README.md +++ b/solution/0800-0899/0804.Unique Morse Code Words/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: @@ -122,6 +124,8 @@ class Solution: return len(s) ``` +#### Java + ```java class Solution { public int uniqueMorseRepresentations(String[] words) { @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func uniqueMorseRepresentations(words []string) int { codes := []string{".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", @@ -174,6 +182,8 @@ func uniqueMorseRepresentations(words []string) int { } ``` +#### TypeScript + ```ts const codes = [ '.-', @@ -216,6 +226,8 @@ function uniqueMorseRepresentations(words: string[]): number { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { diff --git a/solution/0800-0899/0804.Unique Morse Code Words/README_EN.md b/solution/0800-0899/0804.Unique Morse Code Words/README_EN.md index 44ff5aa13cc68..3c4a3372fbd07 100644 --- a/solution/0800-0899/0804.Unique Morse Code Words/README_EN.md +++ b/solution/0800-0899/0804.Unique Morse Code Words/README_EN.md @@ -79,6 +79,8 @@ There are 2 different transformations: "--...-." and "--...--.&qu +#### Python3 + ```python class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: @@ -114,6 +116,8 @@ class Solution: return len(s) ``` +#### Java + ```java class Solution { public int uniqueMorseRepresentations(String[] words) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func uniqueMorseRepresentations(words []string) int { codes := []string{".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", @@ -166,6 +174,8 @@ func uniqueMorseRepresentations(words []string) int { } ``` +#### TypeScript + ```ts const codes = [ '.-', @@ -208,6 +218,8 @@ function uniqueMorseRepresentations(words: string[]): number { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { diff --git a/solution/0800-0899/0805.Split Array With Same Average/README.md b/solution/0800-0899/0805.Split Array With Same Average/README.md index aa498d1c03138..490c1b2e655a1 100644 --- a/solution/0800-0899/0805.Split Array With Same Average/README.md +++ b/solution/0800-0899/0805.Split Array With Same Average/README.md @@ -108,6 +108,8 @@ $$ +#### Python3 + ```python class Solution: def splitArraySameAverage(self, nums: List[int]) -> bool: @@ -131,6 +133,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean splitArraySameAverage(int[] nums) { @@ -172,6 +176,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -200,6 +206,8 @@ public: }; ``` +#### Go + ```go func splitArraySameAverage(nums []int) bool { n := len(nums) diff --git a/solution/0800-0899/0805.Split Array With Same Average/README_EN.md b/solution/0800-0899/0805.Split Array With Same Average/README_EN.md index e6188fd43a283..4c18f31072a5e 100644 --- a/solution/0800-0899/0805.Split Array With Same Average/README_EN.md +++ b/solution/0800-0899/0805.Split Array With Same Average/README_EN.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def splitArraySameAverage(self, nums: List[int]) -> bool: @@ -85,6 +87,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean splitArraySameAverage(int[] nums) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func splitArraySameAverage(nums []int) bool { n := len(nums) diff --git a/solution/0800-0899/0806.Number of Lines To Write String/README.md b/solution/0800-0899/0806.Number of Lines To Write String/README.md index c33229e701798..50505ee24af73 100644 --- a/solution/0800-0899/0806.Number of Lines To Write String/README.md +++ b/solution/0800-0899/0806.Number of Lines To Write String/README.md @@ -73,6 +73,8 @@ S = "bbbcccdddaaa" +#### Python3 + ```python class Solution: def numberOfLines(self, widths: List[int], s: str) -> List[int]: @@ -86,6 +88,8 @@ class Solution: return [lines, last] ``` +#### Java + ```java class Solution { public int[] numberOfLines(int[] widths, String s) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func numberOfLines(widths []int, s string) []int { lines, last := 1, 0 @@ -139,6 +147,8 @@ func numberOfLines(widths []int, s string) []int { } ``` +#### TypeScript + ```ts function numberOfLines(widths: number[], s: string): number[] { let [lines, last] = [1, 0]; @@ -155,6 +165,8 @@ function numberOfLines(widths: number[], s: string): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn number_of_lines(widths: Vec, s: String) -> Vec { diff --git a/solution/0800-0899/0806.Number of Lines To Write String/README_EN.md b/solution/0800-0899/0806.Number of Lines To Write String/README_EN.md index 0371fb870b3dc..ae4c049d39062 100644 --- a/solution/0800-0899/0806.Number of Lines To Write String/README_EN.md +++ b/solution/0800-0899/0806.Number of Lines To Write String/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string $s$. The sp +#### Python3 + ```python class Solution: def numberOfLines(self, widths: List[int], s: str) -> List[int]: @@ -91,6 +93,8 @@ class Solution: return [lines, last] ``` +#### Java + ```java class Solution { public int[] numberOfLines(int[] widths, String s) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func numberOfLines(widths []int, s string) []int { lines, last := 1, 0 @@ -144,6 +152,8 @@ func numberOfLines(widths []int, s string) []int { } ``` +#### TypeScript + ```ts function numberOfLines(widths: number[], s: string): number[] { let [lines, last] = [1, 0]; @@ -160,6 +170,8 @@ function numberOfLines(widths: number[], s: string): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn number_of_lines(widths: Vec, s: String) -> Vec { diff --git a/solution/0800-0899/0807.Max Increase to Keep City Skyline/README.md b/solution/0800-0899/0807.Max Increase to Keep City Skyline/README.md index 78c8a1c5bb1a2..e645612b1518e 100644 --- a/solution/0800-0899/0807.Max Increase to Keep City Skyline/README.md +++ b/solution/0800-0899/0807.Max Increase to Keep City Skyline/README.md @@ -71,6 +71,8 @@ gridNew = [ [8, 4, 8, 7], +#### Python3 + ```python class Solution: def maxIncreaseKeepingSkyline(self, grid: List[List[int]]) -> int: @@ -83,6 +85,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public int maxIncreaseKeepingSkyline(int[][] grid) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func maxIncreaseKeepingSkyline(grid [][]int) int { m, n := len(grid), len(grid[0]) @@ -149,6 +157,8 @@ func maxIncreaseKeepingSkyline(grid [][]int) int { } ``` +#### TypeScript + ```ts function maxIncreaseKeepingSkyline(grid: number[][]): number { let rows = grid.map(arr => Math.max(...arr)), diff --git a/solution/0800-0899/0807.Max Increase to Keep City Skyline/README_EN.md b/solution/0800-0899/0807.Max Increase to Keep City Skyline/README_EN.md index 65b47d8c493c4..4c57474d8e768 100644 --- a/solution/0800-0899/0807.Max Increase to Keep City Skyline/README_EN.md +++ b/solution/0800-0899/0807.Max Increase to Keep City Skyline/README_EN.md @@ -69,6 +69,8 @@ gridNew = [ [8, 4, 8, 7], +#### Python3 + ```python class Solution: def maxIncreaseKeepingSkyline(self, grid: List[List[int]]) -> int: @@ -81,6 +83,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public int maxIncreaseKeepingSkyline(int[][] grid) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func maxIncreaseKeepingSkyline(grid [][]int) int { m, n := len(grid), len(grid[0]) @@ -147,6 +155,8 @@ func maxIncreaseKeepingSkyline(grid [][]int) int { } ``` +#### TypeScript + ```ts function maxIncreaseKeepingSkyline(grid: number[][]): number { let rows = grid.map(arr => Math.max(...arr)), diff --git a/solution/0800-0899/0808.Soup Servings/README.md b/solution/0800-0899/0808.Soup Servings/README.md index 0758410303f1b..d6a4fb0c35681 100644 --- a/solution/0800-0899/0808.Soup Servings/README.md +++ b/solution/0800-0899/0808.Soup Servings/README.md @@ -96,6 +96,8 @@ $$ +#### Python3 + ```python class Solution: def soupServings(self, n: int) -> float: @@ -117,6 +119,8 @@ class Solution: return 1 if n > 4800 else dfs((n + 24) // 25, (n + 24) // 25) ``` +#### Java + ```java class Solution { private double[][] f = new double[200][200]; @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func soupServings(n int) float64 { if n > 4800 { @@ -193,6 +201,8 @@ func soupServings(n int) float64 { } ``` +#### TypeScript + ```ts function soupServings(n: number): number { const f = new Array(200).fill(0).map(() => new Array(200).fill(-1)); diff --git a/solution/0800-0899/0808.Soup Servings/README_EN.md b/solution/0800-0899/0808.Soup Servings/README_EN.md index 9c62b36eb7da2..5c3e112d589c3 100644 --- a/solution/0800-0899/0808.Soup Servings/README_EN.md +++ b/solution/0800-0899/0808.Soup Servings/README_EN.md @@ -69,6 +69,8 @@ So the total probability of A becoming empty first plus half the probability tha +#### Python3 + ```python class Solution: def soupServings(self, n: int) -> float: @@ -90,6 +92,8 @@ class Solution: return 1 if n > 4800 else dfs((n + 24) // 25, (n + 24) // 25) ``` +#### Java + ```java class Solution { private double[][] f = new double[200][200]; @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func soupServings(n int) float64 { if n > 4800 { @@ -166,6 +174,8 @@ func soupServings(n int) float64 { } ``` +#### TypeScript + ```ts function soupServings(n: number): number { const f = new Array(200).fill(0).map(() => new Array(200).fill(-1)); diff --git a/solution/0800-0899/0809.Expressive Words/README.md b/solution/0800-0899/0809.Expressive Words/README.md index cd678f6f6690b..f08d616e8e960 100644 --- a/solution/0800-0899/0809.Expressive Words/README.md +++ b/solution/0800-0899/0809.Expressive Words/README.md @@ -72,6 +72,8 @@ words = ["hello", "hi", "helo"] +#### Python3 + ```python class Solution: def expressiveWords(self, s: str, words: List[str]) -> int: @@ -99,6 +101,8 @@ class Solution: return sum(check(s, t) for t in words) ``` +#### Java + ```java class Solution { public int expressiveWords(String s, String[] words) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func expressiveWords(s string, words []string) (ans int) { check := func(s, t string) bool { diff --git a/solution/0800-0899/0809.Expressive Words/README_EN.md b/solution/0800-0899/0809.Expressive Words/README_EN.md index f7674cd84a997..d7d5225c9d0da 100644 --- a/solution/0800-0899/0809.Expressive Words/README_EN.md +++ b/solution/0800-0899/0809.Expressive Words/README_EN.md @@ -72,6 +72,8 @@ We can't extend "helo" to get "heeellooo" because the gr +#### Python3 + ```python class Solution: def expressiveWords(self, s: str, words: List[str]) -> int: @@ -99,6 +101,8 @@ class Solution: return sum(check(s, t) for t in words) ``` +#### Java + ```java class Solution { public int expressiveWords(String s, String[] words) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func expressiveWords(s string, words []string) (ans int) { check := func(s, t string) bool { diff --git a/solution/0800-0899/0810.Chalkboard XOR Game/README.md b/solution/0800-0899/0810.Chalkboard XOR Game/README.md index 32f4b8cc21c48..2f34cfd1417f4 100644 --- a/solution/0800-0899/0810.Chalkboard XOR Game/README.md +++ b/solution/0800-0899/0810.Chalkboard XOR Game/README.md @@ -118,12 +118,16 @@ $$ +#### Python3 + ```python class Solution: def xorGame(self, nums: List[int]) -> bool: return len(nums) % 2 == 0 or reduce(xor, nums) == 0 ``` +#### Java + ```java class Solution { public boolean xorGame(int[] nums) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func xorGame(nums []int) bool { if len(nums)%2 == 0 { diff --git a/solution/0800-0899/0810.Chalkboard XOR Game/README_EN.md b/solution/0800-0899/0810.Chalkboard XOR Game/README_EN.md index 93a8de1143bcb..bd285cf46f7b9 100644 --- a/solution/0800-0899/0810.Chalkboard XOR Game/README_EN.md +++ b/solution/0800-0899/0810.Chalkboard XOR Game/README_EN.md @@ -72,12 +72,16 @@ If Alice erases 2 first, now nums become [1, 1]. The bitwise XOR of all the elem +#### Python3 + ```python class Solution: def xorGame(self, nums: List[int]) -> bool: return len(nums) % 2 == 0 or reduce(xor, nums) == 0 ``` +#### Java + ```java class Solution { public boolean xorGame(int[] nums) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -98,6 +104,8 @@ public: }; ``` +#### Go + ```go func xorGame(nums []int) bool { if len(nums)%2 == 0 { diff --git a/solution/0800-0899/0811.Subdomain Visit Count/README.md b/solution/0800-0899/0811.Subdomain Visit Count/README.md index 21332491e1ac3..15c5c87ef667c 100644 --- a/solution/0800-0899/0811.Subdomain Visit Count/README.md +++ b/solution/0800-0899/0811.Subdomain Visit Count/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def subdomainVisits(self, cpdomains: List[str]) -> List[str]: @@ -90,6 +92,8 @@ class Solution: return [f'{v} {s}' for s, v in cnt.items()] ``` +#### Java + ```java class Solution { public List subdomainVisits(String[] cpdomains) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func subdomainVisits(cpdomains []string) []string { cnt := map[string]int{} diff --git a/solution/0800-0899/0811.Subdomain Visit Count/README_EN.md b/solution/0800-0899/0811.Subdomain Visit Count/README_EN.md index 7a296fc620e58..19ce748797d0f 100644 --- a/solution/0800-0899/0811.Subdomain Visit Count/README_EN.md +++ b/solution/0800-0899/0811.Subdomain Visit Count/README_EN.md @@ -69,6 +69,8 @@ For the subdomains, we will visit "mail.com" 900 + 1 = 901 times, &quo +#### Python3 + ```python class Solution: def subdomainVisits(self, cpdomains: List[str]) -> List[str]: @@ -81,6 +83,8 @@ class Solution: return [f'{v} {s}' for s, v in cnt.items()] ``` +#### Java + ```java class Solution { public List subdomainVisits(String[] cpdomains) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func subdomainVisits(cpdomains []string) []string { cnt := map[string]int{} diff --git a/solution/0800-0899/0812.Largest Triangle Area/README.md b/solution/0800-0899/0812.Largest Triangle Area/README.md index d5f1f55116e1b..f7c8d86fcc96e 100644 --- a/solution/0800-0899/0812.Largest Triangle Area/README.md +++ b/solution/0800-0899/0812.Largest Triangle Area/README.md @@ -57,6 +57,8 @@ tags: +#### Python3 + ```python class Solution: def largestTriangleArea(self, points: List[List[int]]) -> float: @@ -71,6 +73,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public double largestTriangleArea(int[][] points) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func largestTriangleArea(points [][]int) float64 { ans := 0.0 diff --git a/solution/0800-0899/0812.Largest Triangle Area/README_EN.md b/solution/0800-0899/0812.Largest Triangle Area/README_EN.md index 76e1d943c0caa..e91f788e5fca4 100644 --- a/solution/0800-0899/0812.Largest Triangle Area/README_EN.md +++ b/solution/0800-0899/0812.Largest Triangle Area/README_EN.md @@ -55,6 +55,8 @@ tags: +#### Python3 + ```python class Solution: def largestTriangleArea(self, points: List[List[int]]) -> float: @@ -69,6 +71,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public double largestTriangleArea(int[][] points) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func largestTriangleArea(points [][]int) float64 { ans := 0.0 diff --git a/solution/0800-0899/0813.Largest Sum of Averages/README.md b/solution/0800-0899/0813.Largest Sum of Averages/README.md index b69a7635ba4bd..1bf2aa20f8983 100644 --- a/solution/0800-0899/0813.Largest Sum of Averages/README.md +++ b/solution/0800-0899/0813.Largest Sum of Averages/README.md @@ -78,6 +78,8 @@ nums 的最优分组是[9], [1, 2, 3], [9]. 得到的分数是 9 + (1 + 2 + 3) / +#### Python3 + ```python class Solution: def largestSumOfAverages(self, nums: List[int], k: int) -> float: @@ -98,6 +100,8 @@ class Solution: return dfs(0, k) ``` +#### Java + ```java class Solution { private Double[][] f; @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func largestSumOfAverages(nums []int, k int) float64 { n := len(nums) diff --git a/solution/0800-0899/0813.Largest Sum of Averages/README_EN.md b/solution/0800-0899/0813.Largest Sum of Averages/README_EN.md index b5f9fb589eabe..6621ed69ee8fd 100644 --- a/solution/0800-0899/0813.Largest Sum of Averages/README_EN.md +++ b/solution/0800-0899/0813.Largest Sum of Averages/README_EN.md @@ -62,6 +62,8 @@ That partition would lead to a score of 5 + 2 + 6 = 13, which is worse. +#### Python3 + ```python class Solution: def largestSumOfAverages(self, nums: List[int], k: int) -> float: @@ -82,6 +84,8 @@ class Solution: return dfs(0, k) ``` +#### Java + ```java class Solution { private Double[][] f; @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func largestSumOfAverages(nums []int, k int) float64 { n := len(nums) diff --git a/solution/0800-0899/0814.Binary Tree Pruning/README.md b/solution/0800-0899/0814.Binary Tree Pruning/README.md index d235c88221fdb..09c8d959cec78 100644 --- a/solution/0800-0899/0814.Binary Tree Pruning/README.md +++ b/solution/0800-0899/0814.Binary Tree Pruning/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -88,6 +90,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -165,6 +173,8 @@ func pruneTree(root *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -193,6 +203,8 @@ function pruneTree(root: TreeNode | null): TreeNode | null { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -234,6 +246,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0800-0899/0814.Binary Tree Pruning/README_EN.md b/solution/0800-0899/0814.Binary Tree Pruning/README_EN.md index bd392989ded7f..285f9217d38a2 100644 --- a/solution/0800-0899/0814.Binary Tree Pruning/README_EN.md +++ b/solution/0800-0899/0814.Binary Tree Pruning/README_EN.md @@ -65,6 +65,8 @@ The diagram on the right represents the answer. +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -83,6 +85,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -160,6 +168,8 @@ func pruneTree(root *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -188,6 +198,8 @@ function pruneTree(root: TreeNode | null): TreeNode | null { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -229,6 +241,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0800-0899/0815.Bus Routes/README.md b/solution/0800-0899/0815.Bus Routes/README.md index 168e687938c32..cc8396d967a20 100644 --- a/solution/0800-0899/0815.Bus Routes/README.md +++ b/solution/0800-0899/0815.Bus Routes/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def numBusesToDestination( @@ -119,6 +121,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int numBusesToDestination(int[][] routes, int source, int target) { @@ -174,6 +178,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -229,6 +235,8 @@ public: }; ``` +#### Go + ```go func numBusesToDestination(routes [][]int, source int, target int) int { if source == target { @@ -283,6 +291,8 @@ func numBusesToDestination(routes [][]int, source int, target int) int { } ``` +#### C# + ```cs public class Solution { public int NumBusesToDestination(int[][] routes, int source, int target) { diff --git a/solution/0800-0899/0815.Bus Routes/README_EN.md b/solution/0800-0899/0815.Bus Routes/README_EN.md index 5f059e61febb8..ebf250aa838af 100644 --- a/solution/0800-0899/0815.Bus Routes/README_EN.md +++ b/solution/0800-0899/0815.Bus Routes/README_EN.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def numBusesToDestination( @@ -109,6 +111,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int numBusesToDestination(int[][] routes, int source, int target) { @@ -164,6 +168,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -219,6 +225,8 @@ public: }; ``` +#### Go + ```go func numBusesToDestination(routes [][]int, source int, target int) int { if source == target { @@ -273,6 +281,8 @@ func numBusesToDestination(routes [][]int, source int, target int) int { } ``` +#### C# + ```cs public class Solution { public int NumBusesToDestination(int[][] routes, int source, int target) { diff --git a/solution/0800-0899/0816.Ambiguous Coordinates/README.md b/solution/0800-0899/0816.Ambiguous Coordinates/README.md index 31d656b685e85..7c556413ad5fe 100644 --- a/solution/0800-0899/0816.Ambiguous Coordinates/README.md +++ b/solution/0800-0899/0816.Ambiguous Coordinates/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def ambiguousCoordinates(self, s: str) -> List[str]: @@ -102,6 +104,8 @@ class Solution: ] ``` +#### Java + ```java class Solution { public List ambiguousCoordinates(String s) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func ambiguousCoordinates(s string) []string { f := func(i, j int) []string { @@ -193,6 +201,8 @@ func ambiguousCoordinates(s string) []string { } ``` +#### TypeScript + ```ts function ambiguousCoordinates(s: string): string[] { s = s.slice(1, s.length - 1); diff --git a/solution/0800-0899/0816.Ambiguous Coordinates/README_EN.md b/solution/0800-0899/0816.Ambiguous Coordinates/README_EN.md index c8346e6b14361..bec3afd85e30a 100644 --- a/solution/0800-0899/0816.Ambiguous Coordinates/README_EN.md +++ b/solution/0800-0899/0816.Ambiguous Coordinates/README_EN.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def ambiguousCoordinates(self, s: str) -> List[str]: @@ -90,6 +92,8 @@ class Solution: ] ``` +#### Java + ```java class Solution { public List ambiguousCoordinates(String s) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func ambiguousCoordinates(s string) []string { f := func(i, j int) []string { @@ -181,6 +189,8 @@ func ambiguousCoordinates(s string) []string { } ``` +#### TypeScript + ```ts function ambiguousCoordinates(s: string): string[] { s = s.slice(1, s.length - 1); diff --git a/solution/0800-0899/0817.Linked List Components/README.md b/solution/0800-0899/0817.Linked List Components/README.md index 39d5e99743363..0e5c554cbb6c7 100644 --- a/solution/0800-0899/0817.Linked List Components/README.md +++ b/solution/0800-0899/0817.Linked List Components/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -178,6 +186,8 @@ func numComponents(head *ListNode, nums []int) int { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -211,6 +221,8 @@ function numComponents(head: ListNode | null, nums: number[]): number { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -251,6 +263,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. diff --git a/solution/0800-0899/0817.Linked List Components/README_EN.md b/solution/0800-0899/0817.Linked List Components/README_EN.md index b9f7273eed6ef..96ccc51304c52 100644 --- a/solution/0800-0899/0817.Linked List Components/README_EN.md +++ b/solution/0800-0899/0817.Linked List Components/README_EN.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -168,6 +176,8 @@ func numComponents(head *ListNode, nums []int) int { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -201,6 +211,8 @@ function numComponents(head: ListNode | null, nums: number[]): number { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -241,6 +253,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. diff --git a/solution/0800-0899/0818.Race Car/README.md b/solution/0800-0899/0818.Race Car/README.md index 94eef3938a2c1..8b4d5cf2551e4 100644 --- a/solution/0800-0899/0818.Race Car/README.md +++ b/solution/0800-0899/0818.Race Car/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def racecar(self, target: int) -> int: @@ -101,6 +103,8 @@ class Solution: return dp[target] ``` +#### Java + ```java class Solution { public int racecar(int target) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func racecar(target int) int { dp := make([]int, target+1) diff --git a/solution/0800-0899/0818.Race Car/README_EN.md b/solution/0800-0899/0818.Race Car/README_EN.md index 3ac9c2652584f..05b7b0610fbf5 100644 --- a/solution/0800-0899/0818.Race Car/README_EN.md +++ b/solution/0800-0899/0818.Race Car/README_EN.md @@ -77,6 +77,8 @@ Your position goes from 0 --> 1 --> 3 --> 7 --> 7 --> 6. +#### Python3 + ```python class Solution: def racecar(self, target: int) -> int: @@ -92,6 +94,8 @@ class Solution: return dp[target] ``` +#### Java + ```java class Solution { public int racecar(int target) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func racecar(target int) int { dp := make([]int, target+1) diff --git a/solution/0800-0899/0819.Most Common Word/README.md b/solution/0800-0899/0819.Most Common Word/README.md index 9bba48e7ae5f6..5dacf5bc726e9 100644 --- a/solution/0800-0899/0819.Most Common Word/README.md +++ b/solution/0800-0899/0819.Most Common Word/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def mostCommonWord(self, paragraph: str, banned: List[str]) -> str: @@ -77,6 +79,8 @@ class Solution: return next(word for word, _ in p.most_common() if word not in s) ``` +#### Java + ```java import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func mostCommonWord(paragraph string, banned []string) string { s := make(map[string]bool) @@ -173,6 +181,8 @@ func mostCommonWord(paragraph string, banned []string) string { } ``` +#### TypeScript + ```ts function mostCommonWord(paragraph: string, banned: string[]): string { const s = paragraph.toLocaleLowerCase(); @@ -188,6 +198,8 @@ function mostCommonWord(paragraph: string, banned: string[]): string { } ``` +#### Rust + ```rust use std::collections::{ HashMap, HashSet }; impl Solution { diff --git a/solution/0800-0899/0819.Most Common Word/README_EN.md b/solution/0800-0899/0819.Most Common Word/README_EN.md index 6e47e54d34740..2099528c2a25e 100644 --- a/solution/0800-0899/0819.Most Common Word/README_EN.md +++ b/solution/0800-0899/0819.Most Common Word/README_EN.md @@ -65,6 +65,8 @@ and that "hit" isn't the answer even though it occurs more because +#### Python3 + ```python class Solution: def mostCommonWord(self, paragraph: str, banned: List[str]) -> str: @@ -73,6 +75,8 @@ class Solution: return next(word for word, _ in p.most_common() if word not in s) ``` +#### Java + ```java import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func mostCommonWord(paragraph string, banned []string) string { s := make(map[string]bool) @@ -169,6 +177,8 @@ func mostCommonWord(paragraph string, banned []string) string { } ``` +#### TypeScript + ```ts function mostCommonWord(paragraph: string, banned: string[]): string { const s = paragraph.toLocaleLowerCase(); @@ -184,6 +194,8 @@ function mostCommonWord(paragraph: string, banned: string[]): string { } ``` +#### Rust + ```rust use std::collections::{ HashMap, HashSet }; impl Solution { diff --git a/solution/0800-0899/0820.Short Encoding of Words/README.md b/solution/0800-0899/0820.Short Encoding of Words/README.md index 1e2a78b70dfd0..3496ed626c645 100644 --- a/solution/0800-0899/0820.Short Encoding of Words/README.md +++ b/solution/0800-0899/0820.Short Encoding of Words/README.md @@ -74,6 +74,8 @@ words[2] = "bell" ,s 开始于 indices[2] = 5 到下一个 '#' 结束的子字 +#### Python3 + ```python class Trie: def __init__(self) -> None: @@ -103,6 +105,8 @@ class Solution: return ans ``` +#### Java + ```java class Trie { Trie[] children = new Trie[26]; @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp struct Trie { Trie* children[26] = {nullptr}; @@ -180,6 +186,8 @@ private: }; ``` +#### Go + ```go type trie struct { children [26]*trie @@ -224,6 +232,8 @@ func dfs(cur *trie, l int) int { +#### Python3 + ```python class Trie: def __init__(self): @@ -248,6 +258,8 @@ class Solution: return sum(trie.insert(w[::-1]) for w in words) ``` +#### Java + ```java class Trie { Trie[] children = new Trie[26]; @@ -280,6 +292,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -317,6 +331,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [26]*Trie diff --git a/solution/0800-0899/0820.Short Encoding of Words/README_EN.md b/solution/0800-0899/0820.Short Encoding of Words/README_EN.md index 7b1c92e399c63..53bfc521b4c60 100644 --- a/solution/0800-0899/0820.Short Encoding of Words/README_EN.md +++ b/solution/0800-0899/0820.Short Encoding of Words/README_EN.md @@ -68,6 +68,8 @@ words[2] = "bell", the substring of s starting from indices[2] = 5 to +#### Python3 + ```python class Trie: def __init__(self) -> None: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Trie { Trie[] children = new Trie[26]; @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp struct Trie { Trie* children[26] = {nullptr}; @@ -174,6 +180,8 @@ private: }; ``` +#### Go + ```go type trie struct { children [26]*trie @@ -218,6 +226,8 @@ func dfs(cur *trie, l int) int { +#### Python3 + ```python class Trie: def __init__(self): @@ -242,6 +252,8 @@ class Solution: return sum(trie.insert(w[::-1]) for w in words) ``` +#### Java + ```java class Trie { Trie[] children = new Trie[26]; @@ -274,6 +286,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -311,6 +325,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [26]*Trie diff --git a/solution/0800-0899/0821.Shortest Distance to a Character/README.md b/solution/0800-0899/0821.Shortest Distance to a Character/README.md index 5c8b7567641bb..eb457274fbd11 100644 --- a/solution/0800-0899/0821.Shortest Distance to a Character/README.md +++ b/solution/0800-0899/0821.Shortest Distance to a Character/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def shortestToChar(self, s: str, c: str) -> List[int]: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] shortestToChar(String s, char c) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func shortestToChar(s string, c byte) []int { n := len(s) @@ -163,6 +171,8 @@ func shortestToChar(s string, c byte) []int { } ``` +#### TypeScript + ```ts function shortestToChar(s: string, c: string): number[] { const n = s.length; @@ -184,6 +194,8 @@ function shortestToChar(s: string, c: string): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn shortest_to_char(s: String, c: char) -> Vec { diff --git a/solution/0800-0899/0821.Shortest Distance to a Character/README_EN.md b/solution/0800-0899/0821.Shortest Distance to a Character/README_EN.md index 8cc01ec0c498d..ea4c23f2de8c4 100644 --- a/solution/0800-0899/0821.Shortest Distance to a Character/README_EN.md +++ b/solution/0800-0899/0821.Shortest Distance to a Character/README_EN.md @@ -61,6 +61,8 @@ The closest occurrence of 'e' for index 8 is at index 6, so the distance +#### Python3 + ```python class Solution: def shortestToChar(self, s: str, c: str) -> List[int]: @@ -79,6 +81,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] shortestToChar(String s, char c) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func shortestToChar(s string, c byte) []int { n := len(s) @@ -150,6 +158,8 @@ func shortestToChar(s string, c byte) []int { } ``` +#### TypeScript + ```ts function shortestToChar(s: string, c: string): number[] { const n = s.length; @@ -171,6 +181,8 @@ function shortestToChar(s: string, c: string): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn shortest_to_char(s: String, c: char) -> Vec { diff --git a/solution/0800-0899/0822.Card Flipping Game/README.md b/solution/0800-0899/0822.Card Flipping Game/README.md index 77e413a78c269..916b116f05012 100644 --- a/solution/0800-0899/0822.Card Flipping Game/README.md +++ b/solution/0800-0899/0822.Card Flipping Game/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def flipgame(self, fronts: List[int], backs: List[int]) -> int: @@ -85,6 +87,8 @@ class Solution: return min((x for x in chain(fronts, backs) if x not in s), default=0) ``` +#### Java + ```java class Solution { public int flipgame(int[] fronts, int[] backs) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func flipgame(fronts []int, backs []int) int { s := map[int]struct{}{} @@ -161,6 +169,8 @@ func flipgame(fronts []int, backs []int) int { } ``` +#### TypeScript + ```ts function flipgame(fronts: number[], backs: number[]): number { const s: Set = new Set(); @@ -185,6 +195,8 @@ function flipgame(fronts: number[], backs: number[]): number { } ``` +#### C# + ```cs public class Solution { public int Flipgame(int[] fronts, int[] backs) { diff --git a/solution/0800-0899/0822.Card Flipping Game/README_EN.md b/solution/0800-0899/0822.Card Flipping Game/README_EN.md index d00fc3256a2bd..89abfd94a2f80 100644 --- a/solution/0800-0899/0822.Card Flipping Game/README_EN.md +++ b/solution/0800-0899/0822.Card Flipping Game/README_EN.md @@ -63,6 +63,8 @@ There are no good integers no matter how we flip the cards, so we return 0. +#### Python3 + ```python class Solution: def flipgame(self, fronts: List[int], backs: List[int]) -> int: @@ -70,6 +72,8 @@ class Solution: return min((x for x in chain(fronts, backs) if x not in s), default=0) ``` +#### Java + ```java class Solution { public int flipgame(int[] fronts, int[] backs) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func flipgame(fronts []int, backs []int) int { s := map[int]struct{}{} @@ -146,6 +154,8 @@ func flipgame(fronts []int, backs []int) int { } ``` +#### TypeScript + ```ts function flipgame(fronts: number[], backs: number[]): number { const s: Set = new Set(); @@ -170,6 +180,8 @@ function flipgame(fronts: number[], backs: number[]): number { } ``` +#### C# + ```cs public class Solution { public int Flipgame(int[] fronts, int[] backs) { diff --git a/solution/0800-0899/0823.Binary Trees With Factors/README.md b/solution/0800-0899/0823.Binary Trees With Factors/README.md index 924a9cf614abe..f7002c29f9bf8 100644 --- a/solution/0800-0899/0823.Binary Trees With Factors/README.md +++ b/solution/0800-0899/0823.Binary Trees With Factors/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def numFactoredBinaryTrees(self, arr: List[int]) -> int: @@ -83,6 +85,8 @@ class Solution: return sum(f) % mod ``` +#### Java + ```java class Solution { public int numFactoredBinaryTrees(int[] arr) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func numFactoredBinaryTrees(arr []int) int { const mod int = 1e9 + 7 @@ -179,6 +187,8 @@ func numFactoredBinaryTrees(arr []int) int { } ``` +#### TypeScript + ```ts function numFactoredBinaryTrees(arr: number[]): number { const mod = 10 ** 9 + 7; diff --git a/solution/0800-0899/0823.Binary Trees With Factors/README_EN.md b/solution/0800-0899/0823.Binary Trees With Factors/README_EN.md index 8f147bfb4e08a..f628ebb40f5fe 100644 --- a/solution/0800-0899/0823.Binary Trees With Factors/README_EN.md +++ b/solution/0800-0899/0823.Binary Trees With Factors/README_EN.md @@ -59,6 +59,8 @@ tags: +#### Python3 + ```python class Solution: def numFactoredBinaryTrees(self, arr: List[int]) -> int: @@ -75,6 +77,8 @@ class Solution: return sum(f) % mod ``` +#### Java + ```java class Solution { public int numFactoredBinaryTrees(int[] arr) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func numFactoredBinaryTrees(arr []int) int { const mod int = 1e9 + 7 @@ -171,6 +179,8 @@ func numFactoredBinaryTrees(arr []int) int { } ``` +#### TypeScript + ```ts function numFactoredBinaryTrees(arr: number[]): number { const mod = 10 ** 9 + 7; diff --git a/solution/0800-0899/0824.Goat Latin/README.md b/solution/0800-0899/0824.Goat Latin/README.md index bd01a89d97bbb..2499689af0050 100644 --- a/solution/0800-0899/0824.Goat Latin/README.md +++ b/solution/0800-0899/0824.Goat Latin/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def toGoatLatin(self, sentence: str) -> str: @@ -92,6 +94,8 @@ class Solution: return ' '.join(ans) ``` +#### Java + ```java class Solution { public String toGoatLatin(String sentence) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### TypeScript + ```ts function toGoatLatin(sentence: string): string { return sentence @@ -136,6 +142,8 @@ function toGoatLatin(sentence: string): string { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { diff --git a/solution/0800-0899/0824.Goat Latin/README_EN.md b/solution/0800-0899/0824.Goat Latin/README_EN.md index 7f06bc3cc3570..6cd77518220d5 100644 --- a/solution/0800-0899/0824.Goat Latin/README_EN.md +++ b/solution/0800-0899/0824.Goat Latin/README_EN.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def toGoatLatin(self, sentence: str) -> str: @@ -83,6 +85,8 @@ class Solution: return ' '.join(ans) ``` +#### Java + ```java class Solution { public String toGoatLatin(String sentence) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### TypeScript + ```ts function toGoatLatin(sentence: string): string { return sentence @@ -127,6 +133,8 @@ function toGoatLatin(sentence: string): string { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { diff --git a/solution/0800-0899/0825.Friends Of Appropriate Ages/README.md b/solution/0800-0899/0825.Friends Of Appropriate Ages/README.md index d32d5c11f024f..456c7e99695a7 100644 --- a/solution/0800-0899/0825.Friends Of Appropriate Ages/README.md +++ b/solution/0800-0899/0825.Friends Of Appropriate Ages/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def numFriendRequests(self, ages: List[int]) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numFriendRequests(int[] ages) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func numFriendRequests(ages []int) int { counter := make([]int, 121) diff --git a/solution/0800-0899/0825.Friends Of Appropriate Ages/README_EN.md b/solution/0800-0899/0825.Friends Of Appropriate Ages/README_EN.md index b005a729fac95..246df0457f069 100644 --- a/solution/0800-0899/0825.Friends Of Appropriate Ages/README_EN.md +++ b/solution/0800-0899/0825.Friends Of Appropriate Ages/README_EN.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def numFriendRequests(self, ages: List[int]) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numFriendRequests(int[] ages) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func numFriendRequests(ages []int) int { counter := make([]int, 121) diff --git a/solution/0800-0899/0826.Most Profit Assigning Work/README.md b/solution/0800-0899/0826.Most Profit Assigning Work/README.md index 32e27f1a154d2..ac375926f274d 100644 --- a/solution/0800-0899/0826.Most Profit Assigning Work/README.md +++ b/solution/0800-0899/0826.Most Profit Assigning Work/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def maxProfitAssignment( @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxProfitAssignment(int[] difficulty, int[] profit, int[] worker) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func maxProfitAssignment(difficulty []int, profit []int, worker []int) (ans int) { sort.Ints(worker) @@ -159,6 +167,8 @@ func maxProfitAssignment(difficulty []int, profit []int, worker []int) (ans int) } ``` +#### TypeScript + ```ts function maxProfitAssignment(difficulty: number[], profit: number[], worker: number[]): number { const n = profit.length; diff --git a/solution/0800-0899/0826.Most Profit Assigning Work/README_EN.md b/solution/0800-0899/0826.Most Profit Assigning Work/README_EN.md index a26f965bd4c11..6f2f13975e767 100644 --- a/solution/0800-0899/0826.Most Profit Assigning Work/README_EN.md +++ b/solution/0800-0899/0826.Most Profit Assigning Work/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n \times \log n + m \times \log m)$, and the space com +#### Python3 + ```python class Solution: def maxProfitAssignment( @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxProfitAssignment(int[] difficulty, int[] profit, int[] worker) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func maxProfitAssignment(difficulty []int, profit []int, worker []int) (ans int) { sort.Ints(worker) @@ -159,6 +167,8 @@ func maxProfitAssignment(difficulty []int, profit []int, worker []int) (ans int) } ``` +#### TypeScript + ```ts function maxProfitAssignment(difficulty: number[], profit: number[], worker: number[]): number { const n = profit.length; diff --git a/solution/0800-0899/0827.Making A Large Island/README.md b/solution/0800-0899/0827.Making A Large Island/README.md index dfc5b661e1014..5a21b12a12560 100644 --- a/solution/0800-0899/0827.Making A Large Island/README.md +++ b/solution/0800-0899/0827.Making A Large Island/README.md @@ -114,6 +114,8 @@ def union(a, b): +#### Python3 + ```python class Solution: def largestIsland(self, grid: List[List[int]]) -> int: @@ -156,6 +158,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -221,6 +225,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -281,6 +287,8 @@ public: }; ``` +#### Go + ```go func largestIsland(grid [][]int) int { n := len(grid) @@ -339,6 +347,8 @@ func largestIsland(grid [][]int) int { } ``` +#### TypeScript + ```ts function largestIsland(grid: number[][]): number { const n = grid.length; @@ -400,6 +410,8 @@ function largestIsland(grid: number[][]): number { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -499,6 +511,8 @@ impl Solution { +#### Python3 + ```python class Solution: def largestIsland(self, grid: List[List[int]]) -> int: @@ -537,6 +551,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -596,6 +612,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -654,6 +672,8 @@ public: }; ``` +#### Go + ```go func largestIsland(grid [][]int) int { n := len(grid) diff --git a/solution/0800-0899/0827.Making A Large Island/README_EN.md b/solution/0800-0899/0827.Making A Large Island/README_EN.md index 7063e2116b339..304723e9a70c0 100644 --- a/solution/0800-0899/0827.Making A Large Island/README_EN.md +++ b/solution/0800-0899/0827.Making A Large Island/README_EN.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def largestIsland(self, grid: List[List[int]]) -> int: @@ -112,6 +114,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -177,6 +181,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -237,6 +243,8 @@ public: }; ``` +#### Go + ```go func largestIsland(grid [][]int) int { n := len(grid) @@ -295,6 +303,8 @@ func largestIsland(grid [][]int) int { } ``` +#### TypeScript + ```ts function largestIsland(grid: number[][]): number { const n = grid.length; @@ -356,6 +366,8 @@ function largestIsland(grid: number[][]): number { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -447,6 +459,8 @@ impl Solution { +#### Python3 + ```python class Solution: def largestIsland(self, grid: List[List[int]]) -> int: @@ -485,6 +499,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -544,6 +560,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -602,6 +620,8 @@ public: }; ``` +#### Go + ```go func largestIsland(grid [][]int) int { n := len(grid) diff --git a/solution/0800-0899/0828.Count Unique Characters of All Substrings of a Given String/README.md b/solution/0800-0899/0828.Count Unique Characters of All Substrings of a Given String/README.md index 11a6bd87c6693..efeb7bfe3ad2d 100644 --- a/solution/0800-0899/0828.Count Unique Characters of All Substrings of a Given String/README.md +++ b/solution/0800-0899/0828.Count Unique Characters of All Substrings of a Given String/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def uniqueLetterString(self, s: str) -> int: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int uniqueLetterString(String s) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func uniqueLetterString(s string) (ans int) { d := make([][]int, 26) @@ -158,6 +166,8 @@ func uniqueLetterString(s string) (ans int) { } ``` +#### TypeScript + ```ts function uniqueLetterString(s: string): number { const d: number[][] = Array.from({ length: 26 }, () => [-1]); @@ -176,6 +186,8 @@ function uniqueLetterString(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn unique_letter_string(s: String) -> i32 { diff --git a/solution/0800-0899/0828.Count Unique Characters of All Substrings of a Given String/README_EN.md b/solution/0800-0899/0828.Count Unique Characters of All Substrings of a Given String/README_EN.md index 787d4024b1ac7..d5cf709c32ae9 100644 --- a/solution/0800-0899/0828.Count Unique Characters of All Substrings of a Given String/README_EN.md +++ b/solution/0800-0899/0828.Count Unique Characters of All Substrings of a Given String/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def uniqueLetterString(self, s: str) -> int: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int uniqueLetterString(String s) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func uniqueLetterString(s string) (ans int) { d := make([][]int, 26) @@ -158,6 +166,8 @@ func uniqueLetterString(s string) (ans int) { } ``` +#### TypeScript + ```ts function uniqueLetterString(s: string): number { const d: number[][] = Array.from({ length: 26 }, () => [-1]); @@ -176,6 +186,8 @@ function uniqueLetterString(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn unique_letter_string(s: String) -> i32 { diff --git a/solution/0800-0899/0829.Consecutive Numbers Sum/README.md b/solution/0800-0899/0829.Consecutive Numbers Sum/README.md index 6bad74eac9cdc..6a41f2529e51a 100644 --- a/solution/0800-0899/0829.Consecutive Numbers Sum/README.md +++ b/solution/0800-0899/0829.Consecutive Numbers Sum/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def consecutiveNumbersSum(self, n: int) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func consecutiveNumbersSum(n int) int { n <<= 1 diff --git a/solution/0800-0899/0829.Consecutive Numbers Sum/README_EN.md b/solution/0800-0899/0829.Consecutive Numbers Sum/README_EN.md index ed8ec575d9533..7531ec06aeb2c 100644 --- a/solution/0800-0899/0829.Consecutive Numbers Sum/README_EN.md +++ b/solution/0800-0899/0829.Consecutive Numbers Sum/README_EN.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def consecutiveNumbersSum(self, n: int) -> int: @@ -73,6 +75,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func consecutiveNumbersSum(n int) int { n <<= 1 diff --git a/solution/0800-0899/0830.Positions of Large Groups/README.md b/solution/0800-0899/0830.Positions of Large Groups/README.md index 0859942d26577..51b8de3282a0c 100644 --- a/solution/0800-0899/0830.Positions of Large Groups/README.md +++ b/solution/0800-0899/0830.Positions of Large Groups/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def largeGroupPositions(self, s: str) -> List[List[int]]: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> largeGroupPositions(String s) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func largeGroupPositions(s string) [][]int { i, n := 0, len(s) diff --git a/solution/0800-0899/0830.Positions of Large Groups/README_EN.md b/solution/0800-0899/0830.Positions of Large Groups/README_EN.md index 05025f873c334..34473b9fdbac5 100644 --- a/solution/0800-0899/0830.Positions of Large Groups/README_EN.md +++ b/solution/0800-0899/0830.Positions of Large Groups/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def largeGroupPositions(self, s: str) -> List[List[int]]: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> largeGroupPositions(String s) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func largeGroupPositions(s string) [][]int { i, n := 0, len(s) diff --git a/solution/0800-0899/0831.Masking Personal Information/README.md b/solution/0800-0899/0831.Masking Personal Information/README.md index d0023eae2dd3a..6899efc666fdd 100644 --- a/solution/0800-0899/0831.Masking Personal Information/README.md +++ b/solution/0800-0899/0831.Masking Personal Information/README.md @@ -131,6 +131,8 @@ tags: +#### Python3 + ```python class Solution: def maskPII(self, s: str) -> str: @@ -143,6 +145,8 @@ class Solution: return suf if cnt == 0 else f'+{"*" * cnt}-{suf}' ``` +#### Java + ```java class Solution { public String maskPII(String s) { @@ -167,6 +171,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -194,6 +200,8 @@ public: }; ``` +#### Go + ```go func maskPII(s string) string { i := strings.Index(s, "@") @@ -217,6 +225,8 @@ func maskPII(s string) string { } ``` +#### TypeScript + ```ts function maskPII(s: string): string { const i = s.indexOf('@'); diff --git a/solution/0800-0899/0831.Masking Personal Information/README_EN.md b/solution/0800-0899/0831.Masking Personal Information/README_EN.md index ef2fbaafbf731..d90a2967dfcb1 100644 --- a/solution/0800-0899/0831.Masking Personal Information/README_EN.md +++ b/solution/0800-0899/0831.Masking Personal Information/README_EN.md @@ -120,6 +120,8 @@ Thus, the resulting masked number is "***-***-7890". +#### Python3 + ```python class Solution: def maskPII(self, s: str) -> str: @@ -132,6 +134,8 @@ class Solution: return suf if cnt == 0 else f'+{"*" * cnt}-{suf}' ``` +#### Java + ```java class Solution { public String maskPII(String s) { @@ -156,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -183,6 +189,8 @@ public: }; ``` +#### Go + ```go func maskPII(s string) string { i := strings.Index(s, "@") @@ -206,6 +214,8 @@ func maskPII(s string) string { } ``` +#### TypeScript + ```ts function maskPII(s: string): string { const i = s.indexOf('@'); diff --git a/solution/0800-0899/0832.Flipping an Image/README.md b/solution/0800-0899/0832.Flipping an Image/README.md index c3913b5a81815..be1288ef2321c 100644 --- a/solution/0800-0899/0832.Flipping an Image/README.md +++ b/solution/0800-0899/0832.Flipping an Image/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def flipAndInvertImage(self, image: List[List[int]]) -> List[List[int]]: @@ -101,6 +103,8 @@ class Solution: return image ``` +#### Java + ```java class Solution { public int[][] flipAndInvertImage(int[][] image) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func flipAndInvertImage(image [][]int) [][]int { for _, row := range image { @@ -160,6 +168,8 @@ func flipAndInvertImage(image [][]int) [][]int { } ``` +#### JavaScript + ```js /** * @param {number[][]} image diff --git a/solution/0800-0899/0832.Flipping an Image/README_EN.md b/solution/0800-0899/0832.Flipping an Image/README_EN.md index c3b6e7b7d1822..f559c3f8a74de 100644 --- a/solution/0800-0899/0832.Flipping an Image/README_EN.md +++ b/solution/0800-0899/0832.Flipping an Image/README_EN.md @@ -73,6 +73,8 @@ Then invert the image: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]] +#### Python3 + ```python class Solution: def flipAndInvertImage(self, image: List[List[int]]) -> List[List[int]]: @@ -89,6 +91,8 @@ class Solution: return image ``` +#### Java + ```java class Solution { public int[][] flipAndInvertImage(int[][] image) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func flipAndInvertImage(image [][]int) [][]int { for _, row := range image { @@ -148,6 +156,8 @@ func flipAndInvertImage(image [][]int) [][]int { } ``` +#### JavaScript + ```js /** * @param {number[][]} image diff --git a/solution/0800-0899/0833.Find And Replace in String/README.md b/solution/0800-0899/0833.Find And Replace in String/README.md index 788c406c0429b..fe2b0624dbacc 100644 --- a/solution/0800-0899/0833.Find And Replace in String/README.md +++ b/solution/0800-0899/0833.Find And Replace in String/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class Solution: def findReplaceString( @@ -116,6 +118,8 @@ class Solution: return "".join(ans) ``` +#### Java + ```java class Solution { public String findReplaceString(String s, int[] indices, String[] sources, String[] targets) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func findReplaceString(s string, indices []int, sources []string, targets []string) string { n := len(s) @@ -191,6 +199,8 @@ func findReplaceString(s string, indices []int, sources []string, targets []stri } ``` +#### TypeScript + ```ts function findReplaceString( s: string, diff --git a/solution/0800-0899/0833.Find And Replace in String/README_EN.md b/solution/0800-0899/0833.Find And Replace in String/README_EN.md index 4079f6e670226..b6258aeed9e0f 100644 --- a/solution/0800-0899/0833.Find And Replace in String/README_EN.md +++ b/solution/0800-0899/0833.Find And Replace in String/README_EN.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def findReplaceString( @@ -106,6 +108,8 @@ class Solution: return "".join(ans) ``` +#### Java + ```java class Solution { public String findReplaceString(String s, int[] indices, String[] sources, String[] targets) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func findReplaceString(s string, indices []int, sources []string, targets []string) string { n := len(s) @@ -181,6 +189,8 @@ func findReplaceString(s string, indices []int, sources []string, targets []stri } ``` +#### TypeScript + ```ts function findReplaceString( s: string, diff --git a/solution/0800-0899/0834.Sum of Distances in Tree/README.md b/solution/0800-0899/0834.Sum of Distances in Tree/README.md index a721fc539f662..be8eb79cd8615 100644 --- a/solution/0800-0899/0834.Sum of Distances in Tree/README.md +++ b/solution/0800-0899/0834.Sum of Distances in Tree/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def sumOfDistancesInTree(self, n: int, edges: List[List[int]]) -> List[int]: @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -200,6 +206,8 @@ public: }; ``` +#### Go + ```go func sumOfDistancesInTree(n int, edges [][]int) []int { g := make([][]int, n) @@ -236,6 +244,8 @@ func sumOfDistancesInTree(n int, edges [][]int) []int { } ``` +#### TypeScript + ```ts function sumOfDistancesInTree(n: number, edges: number[][]): number[] { const g: number[][] = Array.from({ length: n }, () => []); diff --git a/solution/0800-0899/0834.Sum of Distances in Tree/README_EN.md b/solution/0800-0899/0834.Sum of Distances in Tree/README_EN.md index 93ae359f2b3e1..6182ec5ee7604 100644 --- a/solution/0800-0899/0834.Sum of Distances in Tree/README_EN.md +++ b/solution/0800-0899/0834.Sum of Distances in Tree/README_EN.md @@ -73,6 +73,8 @@ Hence, answer[0] = 8, and so on. +#### Python3 + ```python class Solution: def sumOfDistancesInTree(self, n: int, edges: List[List[int]]) -> List[int]: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -147,6 +151,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -187,6 +193,8 @@ public: }; ``` +#### Go + ```go func sumOfDistancesInTree(n int, edges [][]int) []int { g := make([][]int, n) @@ -223,6 +231,8 @@ func sumOfDistancesInTree(n int, edges [][]int) []int { } ``` +#### TypeScript + ```ts function sumOfDistancesInTree(n: number, edges: number[][]): number[] { const g: number[][] = Array.from({ length: n }, () => []); diff --git a/solution/0800-0899/0835.Image Overlap/README.md b/solution/0800-0899/0835.Image Overlap/README.md index aabbc1e6d61d3..78ddecb75cb53 100644 --- a/solution/0800-0899/0835.Image Overlap/README.md +++ b/solution/0800-0899/0835.Image Overlap/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def largestOverlap(self, img1: List[List[int]], img2: List[List[int]]) -> int: @@ -97,6 +99,8 @@ class Solution: return max(cnt.values()) if cnt else 0 ``` +#### Java + ```java class Solution { public int largestOverlap(int[][] img1, int[][] img2) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func largestOverlap(img1 [][]int, img2 [][]int) (ans int) { type pair struct{ x, y int } @@ -170,6 +178,8 @@ func largestOverlap(img1 [][]int, img2 [][]int) (ans int) { } ``` +#### TypeScript + ```ts function largestOverlap(img1: number[][], img2: number[][]): number { const n = img1.length; diff --git a/solution/0800-0899/0835.Image Overlap/README_EN.md b/solution/0800-0899/0835.Image Overlap/README_EN.md index 4e0575f0ff8ba..b01e099984f5d 100644 --- a/solution/0800-0899/0835.Image Overlap/README_EN.md +++ b/solution/0800-0899/0835.Image Overlap/README_EN.md @@ -72,6 +72,8 @@ The number of positions that have a 1 in both images is 3 (shown in red). +#### Python3 + ```python class Solution: def largestOverlap(self, img1: List[List[int]], img2: List[List[int]]) -> int: @@ -87,6 +89,8 @@ class Solution: return max(cnt.values()) if cnt else 0 ``` +#### Java + ```java class Solution { public int largestOverlap(int[][] img1, int[][] img2) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func largestOverlap(img1 [][]int, img2 [][]int) (ans int) { type pair struct{ x, y int } @@ -160,6 +168,8 @@ func largestOverlap(img1 [][]int, img2 [][]int) (ans int) { } ``` +#### TypeScript + ```ts function largestOverlap(img1: number[][], img2: number[][]): number { const n = img1.length; diff --git a/solution/0800-0899/0836.Rectangle Overlap/README.md b/solution/0800-0899/0836.Rectangle Overlap/README.md index 65e8f6b0035df..d34e09e0cb151 100644 --- a/solution/0800-0899/0836.Rectangle Overlap/README.md +++ b/solution/0800-0899/0836.Rectangle Overlap/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool: @@ -88,6 +90,8 @@ class Solution: return not (y3 >= y2 or y4 <= y1 or x3 >= x2 or x4 <= x1) ``` +#### Java + ```java class Solution { public boolean isRectangleOverlap(int[] rec1, int[] rec2) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func isRectangleOverlap(rec1 []int, rec2 []int) bool { x1, y1, x2, y2 := rec1[0], rec1[1], rec1[2], rec1[3] diff --git a/solution/0800-0899/0836.Rectangle Overlap/README_EN.md b/solution/0800-0899/0836.Rectangle Overlap/README_EN.md index 5bd177f673964..7fb6b6b0558fa 100644 --- a/solution/0800-0899/0836.Rectangle Overlap/README_EN.md +++ b/solution/0800-0899/0836.Rectangle Overlap/README_EN.md @@ -54,6 +54,8 @@ tags: +#### Python3 + ```python class Solution: def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool: @@ -62,6 +64,8 @@ class Solution: return not (y3 >= y2 or y4 <= y1 or x3 >= x2 or x4 <= x1) ``` +#### Java + ```java class Solution { public boolean isRectangleOverlap(int[] rec1, int[] rec2) { @@ -72,6 +76,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -83,6 +89,8 @@ public: }; ``` +#### Go + ```go func isRectangleOverlap(rec1 []int, rec2 []int) bool { x1, y1, x2, y2 := rec1[0], rec1[1], rec1[2], rec1[3] diff --git a/solution/0800-0899/0837.New 21 Game/README.md b/solution/0800-0899/0837.New 21 Game/README.md index 8c595fc35e22d..961cb03d6ed67 100644 --- a/solution/0800-0899/0837.New 21 Game/README.md +++ b/solution/0800-0899/0837.New 21 Game/README.md @@ -146,6 +146,8 @@ $$ +#### Python3 + ```python class Solution: def new21Game(self, n: int, k: int, maxPts: int) -> float: @@ -160,6 +162,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private double[] f; @@ -188,6 +192,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -210,6 +216,8 @@ public: }; ``` +#### Go + ```go func new21Game(n int, k int, maxPts int) float64 { f := make([]float64, k) @@ -234,6 +242,8 @@ func new21Game(n int, k int, maxPts int) float64 { } ``` +#### TypeScript + ```ts function new21Game(n: number, k: number, maxPts: number): number { const f = new Array(k).fill(0); @@ -275,6 +285,8 @@ function new21Game(n: number, k: number, maxPts: number): number { +#### Python3 + ```python class Solution: def new21Game(self, n: int, k: int, maxPts: int) -> float: @@ -287,6 +299,8 @@ class Solution: return f[0] ``` +#### Java + ```java class Solution { public double new21Game(int n, int k, int maxPts) { @@ -306,6 +320,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -327,6 +343,8 @@ public: }; ``` +#### Go + ```go func new21Game(n int, k int, maxPts int) float64 { if k == 0 { @@ -344,6 +362,8 @@ func new21Game(n int, k int, maxPts int) float64 { } ``` +#### TypeScript + ```ts function new21Game(n: number, k: number, maxPts: number): number { if (k === 0) { diff --git a/solution/0800-0899/0837.New 21 Game/README_EN.md b/solution/0800-0899/0837.New 21 Game/README_EN.md index 6d9708f4e3588..1f9a436258897 100644 --- a/solution/0800-0899/0837.New 21 Game/README_EN.md +++ b/solution/0800-0899/0837.New 21 Game/README_EN.md @@ -72,6 +72,8 @@ In 6 out of 10 possibilities, she is at or below 6 points. +#### Python3 + ```python class Solution: def new21Game(self, n: int, k: int, maxPts: int) -> float: @@ -86,6 +88,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private double[] f; @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func new21Game(n int, k int, maxPts int) float64 { f := make([]float64, k) @@ -160,6 +168,8 @@ func new21Game(n int, k int, maxPts int) float64 { } ``` +#### TypeScript + ```ts function new21Game(n: number, k: number, maxPts: number): number { const f = new Array(k).fill(0); @@ -189,6 +199,8 @@ function new21Game(n: number, k: number, maxPts: number): number { +#### Python3 + ```python class Solution: def new21Game(self, n: int, k: int, maxPts: int) -> float: @@ -201,6 +213,8 @@ class Solution: return f[0] ``` +#### Java + ```java class Solution { public double new21Game(int n, int k, int maxPts) { @@ -220,6 +234,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -241,6 +257,8 @@ public: }; ``` +#### Go + ```go func new21Game(n int, k int, maxPts int) float64 { if k == 0 { @@ -258,6 +276,8 @@ func new21Game(n int, k int, maxPts int) float64 { } ``` +#### TypeScript + ```ts function new21Game(n: number, k: number, maxPts: number): number { if (k === 0) { diff --git a/solution/0800-0899/0838.Push Dominoes/README.md b/solution/0800-0899/0838.Push Dominoes/README.md index 54d28ff90a9ee..e6f79c7abba0b 100644 --- a/solution/0800-0899/0838.Push Dominoes/README.md +++ b/solution/0800-0899/0838.Push Dominoes/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def pushDominoes(self, dominoes: str) -> str: @@ -101,6 +103,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String pushDominoes(String dominoes) { @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -184,6 +190,8 @@ public: }; ``` +#### Go + ```go func pushDominoes(dominoes string) string { n := len(dominoes) @@ -229,6 +237,8 @@ func pushDominoes(dominoes string) string { } ``` +#### TypeScript + ```ts function pushDominoes(dominoes: string): string { const n = dominoes.length; diff --git a/solution/0800-0899/0838.Push Dominoes/README_EN.md b/solution/0800-0899/0838.Push Dominoes/README_EN.md index 9c8da9aa17ee4..ce232677d18a7 100644 --- a/solution/0800-0899/0838.Push Dominoes/README_EN.md +++ b/solution/0800-0899/0838.Push Dominoes/README_EN.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def pushDominoes(self, dominoes: str) -> str: @@ -100,6 +102,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String pushDominoes(String dominoes) { @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -183,6 +189,8 @@ public: }; ``` +#### Go + ```go func pushDominoes(dominoes string) string { n := len(dominoes) @@ -228,6 +236,8 @@ func pushDominoes(dominoes string) string { } ``` +#### TypeScript + ```ts function pushDominoes(dominoes: string): string { const n = dominoes.length; diff --git a/solution/0800-0899/0839.Similar String Groups/README.md b/solution/0800-0899/0839.Similar String Groups/README.md index 2df84768175e0..5241ffdb57e6b 100644 --- a/solution/0800-0899/0839.Similar String Groups/README.md +++ b/solution/0800-0899/0839.Similar String Groups/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def numSimilarGroups(self, strs: List[str]) -> int: @@ -83,6 +85,8 @@ class Solution: return sum(i == find(i) for i in range(n)) ``` +#### Java + ```java class Solution { private int[] p; @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func numSimilarGroups(strs []string) int { n := len(strs) diff --git a/solution/0800-0899/0839.Similar String Groups/README_EN.md b/solution/0800-0899/0839.Similar String Groups/README_EN.md index 59baa3b9bf267..2efdadf25323c 100644 --- a/solution/0800-0899/0839.Similar String Groups/README_EN.md +++ b/solution/0800-0899/0839.Similar String Groups/README_EN.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def numSimilarGroups(self, strs: List[str]) -> int: @@ -81,6 +83,8 @@ class Solution: return sum(i == find(i) for i in range(n)) ``` +#### Java + ```java class Solution { private int[] p; @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func numSimilarGroups(strs []string) int { n := len(strs) diff --git a/solution/0800-0899/0840.Magic Squares In Grid/README.md b/solution/0800-0899/0840.Magic Squares In Grid/README.md index 22ce57aa573f7..82b1eca486f5e 100644 --- a/solution/0800-0899/0840.Magic Squares In Grid/README.md +++ b/solution/0800-0899/0840.Magic Squares In Grid/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def numMagicSquaresInside(self, grid: List[List[int]]) -> int: @@ -104,6 +106,8 @@ class Solution: return sum(check(i, j) for i in range(m) for j in range(n)) ``` +#### Java + ```java class Solution { private int m; @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -211,6 +217,8 @@ public: }; ``` +#### Go + ```go func numMagicSquaresInside(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -258,6 +266,8 @@ func numMagicSquaresInside(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function numMagicSquaresInside(grid: number[][]): number { const m = grid.length; diff --git a/solution/0800-0899/0840.Magic Squares In Grid/README_EN.md b/solution/0800-0899/0840.Magic Squares In Grid/README_EN.md index 0f1db016d15c4..e159a7d89cd0a 100644 --- a/solution/0800-0899/0840.Magic Squares In Grid/README_EN.md +++ b/solution/0800-0899/0840.Magic Squares In Grid/README_EN.md @@ -64,6 +64,8 @@ In total, there is only one magic square inside the given grid. +#### Python3 + ```python class Solution: def numMagicSquaresInside(self, grid: List[List[int]]) -> int: @@ -96,6 +98,8 @@ class Solution: return sum(check(i, j) for i in range(m) for j in range(n)) ``` +#### Java + ```java class Solution { private int m; @@ -152,6 +156,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -203,6 +209,8 @@ public: }; ``` +#### Go + ```go func numMagicSquaresInside(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -250,6 +258,8 @@ func numMagicSquaresInside(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function numMagicSquaresInside(grid: number[][]): number { const m = grid.length; diff --git a/solution/0800-0899/0841.Keys and Rooms/README.md b/solution/0800-0899/0841.Keys and Rooms/README.md index e6d9ee06faee7..def2cfc67851f 100644 --- a/solution/0800-0899/0841.Keys and Rooms/README.md +++ b/solution/0800-0899/0841.Keys and Rooms/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def canVisitAllRooms(self, rooms: List[List[int]]) -> bool: @@ -94,6 +96,8 @@ class Solution: return len(vis) == len(rooms) ``` +#### Java + ```java class Solution { private int cnt; @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func canVisitAllRooms(rooms [][]int) bool { n := len(rooms) @@ -165,6 +173,8 @@ func canVisitAllRooms(rooms [][]int) bool { } ``` +#### TypeScript + ```ts function canVisitAllRooms(rooms: number[][]): boolean { const n = rooms.length; @@ -183,6 +193,8 @@ function canVisitAllRooms(rooms: number[][]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn can_visit_all_rooms(rooms: Vec>) -> bool { diff --git a/solution/0800-0899/0841.Keys and Rooms/README_EN.md b/solution/0800-0899/0841.Keys and Rooms/README_EN.md index 3c5f97380c6e7..94526ebee48e8 100644 --- a/solution/0800-0899/0841.Keys and Rooms/README_EN.md +++ b/solution/0800-0899/0841.Keys and Rooms/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(n + m)$, and the space complexity is $O(n)$, where $n$ +#### Python3 + ```python class Solution: def canVisitAllRooms(self, rooms: List[List[int]]) -> bool: @@ -89,6 +91,8 @@ class Solution: return len(vis) == len(rooms) ``` +#### Java + ```java class Solution { private int cnt; @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func canVisitAllRooms(rooms [][]int) bool { n := len(rooms) @@ -160,6 +168,8 @@ func canVisitAllRooms(rooms [][]int) bool { } ``` +#### TypeScript + ```ts function canVisitAllRooms(rooms: number[][]): boolean { const n = rooms.length; @@ -178,6 +188,8 @@ function canVisitAllRooms(rooms: number[][]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn can_visit_all_rooms(rooms: Vec>) -> bool { diff --git a/solution/0800-0899/0842.Split Array into Fibonacci Sequence/README.md b/solution/0800-0899/0842.Split Array into Fibonacci Sequence/README.md index 53ac24994bb4a..5f1c940020cc9 100644 --- a/solution/0800-0899/0842.Split Array into Fibonacci Sequence/README.md +++ b/solution/0800-0899/0842.Split Array into Fibonacci Sequence/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def splitIntoFibonacci(self, num: str) -> List[int]: @@ -111,6 +113,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List ans = new ArrayList<>(); @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -184,6 +190,8 @@ public: }; ``` +#### Go + ```go func splitIntoFibonacci(num string) []int { n := len(num) diff --git a/solution/0800-0899/0842.Split Array into Fibonacci Sequence/README_EN.md b/solution/0800-0899/0842.Split Array into Fibonacci Sequence/README_EN.md index 559ed9e55dd42..85c0c5185c284 100644 --- a/solution/0800-0899/0842.Split Array into Fibonacci Sequence/README_EN.md +++ b/solution/0800-0899/0842.Split Array into Fibonacci Sequence/README_EN.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def splitIntoFibonacci(self, num: str) -> List[int]: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List ans = new ArrayList<>(); @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go func splitIntoFibonacci(num string) []int { n := len(num) diff --git a/solution/0800-0899/0843.Guess the Word/README.md b/solution/0800-0899/0843.Guess the Word/README.md index 1d195e56c207c..bb4a17e2e54ed 100644 --- a/solution/0800-0899/0843.Guess the Word/README.md +++ b/solution/0800-0899/0843.Guess the Word/README.md @@ -87,18 +87,26 @@ master.guess("abcczz") 返回 4 ,因为 "abcczz" 共有 4 个字母匹配。 +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/0800-0899/0843.Guess the Word/README_EN.md b/solution/0800-0899/0843.Guess the Word/README_EN.md index 9fe78543290a1..da6a5a8029c04 100644 --- a/solution/0800-0899/0843.Guess the Word/README_EN.md +++ b/solution/0800-0899/0843.Guess the Word/README_EN.md @@ -85,18 +85,26 @@ We made 5 calls to master.guess, and one of them was the secret, so we pass the +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/0800-0899/0844.Backspace String Compare/README.md b/solution/0800-0899/0844.Backspace String Compare/README.md index 36f5a9f639fe8..0d9e796b102cf 100644 --- a/solution/0800-0899/0844.Backspace String Compare/README.md +++ b/solution/0800-0899/0844.Backspace String Compare/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def backspaceCompare(self, s: str, t: str) -> bool: @@ -115,6 +117,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean backspaceCompare(String s, String t) { @@ -156,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go func backspaceCompare(s string, t string) bool { i, j := len(s)-1, len(t)-1 @@ -232,6 +240,8 @@ func backspaceCompare(s string, t string) bool { } ``` +#### TypeScript + ```ts function backspaceCompare(s: string, t: string): boolean { let i = s.length - 1; @@ -269,6 +279,8 @@ function backspaceCompare(s: string, t: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn backspace_compare(s: String, t: String) -> bool { diff --git a/solution/0800-0899/0844.Backspace String Compare/README_EN.md b/solution/0800-0899/0844.Backspace String Compare/README_EN.md index 22c26c16b1bd4..77f99fcab9978 100644 --- a/solution/0800-0899/0844.Backspace String Compare/README_EN.md +++ b/solution/0800-0899/0844.Backspace String Compare/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def backspaceCompare(self, s: str, t: str) -> bool: @@ -101,6 +103,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean backspaceCompare(String s, String t) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -179,6 +185,8 @@ public: }; ``` +#### Go + ```go func backspaceCompare(s string, t string) bool { i, j := len(s)-1, len(t)-1 @@ -218,6 +226,8 @@ func backspaceCompare(s string, t string) bool { } ``` +#### TypeScript + ```ts function backspaceCompare(s: string, t: string): boolean { let i = s.length - 1; @@ -255,6 +265,8 @@ function backspaceCompare(s: string, t: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn backspace_compare(s: String, t: String) -> bool { diff --git a/solution/0800-0899/0845.Longest Mountain in Array/README.md b/solution/0800-0899/0845.Longest Mountain in Array/README.md index 2874c780e7b16..e24ced29e2ab4 100644 --- a/solution/0800-0899/0845.Longest Mountain in Array/README.md +++ b/solution/0800-0899/0845.Longest Mountain in Array/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def longestMountain(self, arr: List[int]) -> int: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestMountain(int[] arr) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func longestMountain(arr []int) (ans int) { n := len(arr) @@ -196,6 +204,8 @@ func longestMountain(arr []int) (ans int) { +#### Python3 + ```python class Solution: def longestMountain(self, arr: List[int]) -> int: @@ -216,6 +226,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestMountain(int[] arr) { @@ -242,6 +254,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -269,6 +283,8 @@ public: }; ``` +#### Go + ```go func longestMountain(arr []int) (ans int) { n := len(arr) diff --git a/solution/0800-0899/0845.Longest Mountain in Array/README_EN.md b/solution/0800-0899/0845.Longest Mountain in Array/README_EN.md index a34a1bb6cef2b..ad2003fc8e076 100644 --- a/solution/0800-0899/0845.Longest Mountain in Array/README_EN.md +++ b/solution/0800-0899/0845.Longest Mountain in Array/README_EN.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def longestMountain(self, arr: List[int]) -> int: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestMountain(int[] arr) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func longestMountain(arr []int) (ans int) { n := len(arr) @@ -185,6 +193,8 @@ func longestMountain(arr []int) (ans int) { +#### Python3 + ```python class Solution: def longestMountain(self, arr: List[int]) -> int: @@ -205,6 +215,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestMountain(int[] arr) { @@ -231,6 +243,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -258,6 +272,8 @@ public: }; ``` +#### Go + ```go func longestMountain(arr []int) (ans int) { n := len(arr) diff --git a/solution/0800-0899/0846.Hand of Straights/README.md b/solution/0800-0899/0846.Hand of Straights/README.md index fdd1dc0b5035a..95346c2cf10b4 100644 --- a/solution/0800-0899/0846.Hand of Straights/README.md +++ b/solution/0800-0899/0846.Hand of Straights/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def isNStraightHand(self, hand: List[int], groupSize: int) -> bool: @@ -87,6 +89,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isNStraightHand(int[] hand, int groupSize) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func isNStraightHand(hand []int, groupSize int) bool { cnt := map[int]int{} @@ -177,6 +185,8 @@ func isNStraightHand(hand []int, groupSize int) bool { +#### Python3 + ```python from sortedcontainers import SortedDict @@ -203,6 +213,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isNStraightHand(int[] hand, int groupSize) { @@ -231,6 +243,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -253,6 +267,8 @@ public: }; ``` +#### Go + ```go func isNStraightHand(hand []int, groupSize int) bool { if len(hand)%groupSize != 0 { diff --git a/solution/0800-0899/0846.Hand of Straights/README_EN.md b/solution/0800-0899/0846.Hand of Straights/README_EN.md index ff2fd45562ba7..cf05422e5303a 100644 --- a/solution/0800-0899/0846.Hand of Straights/README_EN.md +++ b/solution/0800-0899/0846.Hand of Straights/README_EN.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def isNStraightHand(self, hand: List[int], groupSize: int) -> bool: @@ -78,6 +80,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isNStraightHand(int[] hand, int groupSize) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func isNStraightHand(hand []int, groupSize int) bool { cnt := map[int]int{} @@ -162,6 +170,8 @@ func isNStraightHand(hand []int, groupSize int) bool { +#### Python3 + ```python from sortedcontainers import SortedDict @@ -188,6 +198,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isNStraightHand(int[] hand, int groupSize) { @@ -216,6 +228,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -238,6 +252,8 @@ public: }; ``` +#### Go + ```go func isNStraightHand(hand []int, groupSize int) bool { if len(hand)%groupSize != 0 { diff --git a/solution/0800-0899/0847.Shortest Path Visiting All Nodes/README.md b/solution/0800-0899/0847.Shortest Path Visiting All Nodes/README.md index 1e7e711dcabdc..6d18af34108d4 100644 --- a/solution/0800-0899/0847.Shortest Path Visiting All Nodes/README.md +++ b/solution/0800-0899/0847.Shortest Path Visiting All Nodes/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def shortestPathLength(self, graph: List[List[int]]) -> int: @@ -102,6 +104,8 @@ class Solution: ans += 1 ``` +#### Java + ```java class Solution { public int shortestPathLength(int[][] graph) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func shortestPathLength(graph [][]int) int { n := len(graph) @@ -194,6 +202,8 @@ func shortestPathLength(graph [][]int) int { } ``` +#### TypeScript + ```ts function shortestPathLength(graph: number[][]): number { const n = graph.length; @@ -221,6 +231,8 @@ function shortestPathLength(graph: number[][]): number { } ``` +#### Rust + ```rust use std::collections::VecDeque; @@ -280,6 +292,8 @@ A\* 算法主要思想如下: +#### Python3 + ```python class Solution: def shortestPathLength(self, graph: List[List[int]]) -> int: @@ -305,6 +319,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { private int n; @@ -349,6 +365,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/0800-0899/0847.Shortest Path Visiting All Nodes/README_EN.md b/solution/0800-0899/0847.Shortest Path Visiting All Nodes/README_EN.md index cae35ece972fc..e2eae3f84182e 100644 --- a/solution/0800-0899/0847.Shortest Path Visiting All Nodes/README_EN.md +++ b/solution/0800-0899/0847.Shortest Path Visiting All Nodes/README_EN.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def shortestPathLength(self, graph: List[List[int]]) -> int: @@ -86,6 +88,8 @@ class Solution: ans += 1 ``` +#### Java + ```java class Solution { public int shortestPathLength(int[][] graph) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func shortestPathLength(graph [][]int) int { n := len(graph) @@ -178,6 +186,8 @@ func shortestPathLength(graph [][]int) int { } ``` +#### TypeScript + ```ts function shortestPathLength(graph: number[][]): number { const n = graph.length; @@ -205,6 +215,8 @@ function shortestPathLength(graph: number[][]): number { } ``` +#### Rust + ```rust use std::collections::VecDeque; @@ -252,6 +264,8 @@ impl Solution { +#### Python3 + ```python class Solution: def shortestPathLength(self, graph: List[List[int]]) -> int: @@ -277,6 +291,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { private int n; @@ -321,6 +337,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/0800-0899/0848.Shifting Letters/README.md b/solution/0800-0899/0848.Shifting Letters/README.md index 6b2a4c70b806b..7a47204150a0b 100644 --- a/solution/0800-0899/0848.Shifting Letters/README.md +++ b/solution/0800-0899/0848.Shifting Letters/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def shiftingLetters(self, s: str, shifts: List[int]) -> str: @@ -89,6 +91,8 @@ class Solution: return ''.join(s) ``` +#### Python3 + ```python class Solution: def shiftingLetters(self, s: str, shifts: List[int]) -> str: @@ -110,6 +114,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String shiftingLetters(String s, int[] shifts) { @@ -126,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +150,8 @@ public: }; ``` +#### Go + ```go func shiftingLetters(s string, shifts []int) string { t := 0 diff --git a/solution/0800-0899/0848.Shifting Letters/README_EN.md b/solution/0800-0899/0848.Shifting Letters/README_EN.md index 588da1fcc0736..47a0f2a01423b 100644 --- a/solution/0800-0899/0848.Shifting Letters/README_EN.md +++ b/solution/0800-0899/0848.Shifting Letters/README_EN.md @@ -69,6 +69,8 @@ After shifting the first 3 letters of s by 9, we have "rpl", the answe +#### Python3 + ```python class Solution: def shiftingLetters(self, s: str, shifts: List[int]) -> str: @@ -81,6 +83,8 @@ class Solution: return ''.join(s) ``` +#### Python3 + ```python class Solution: def shiftingLetters(self, s: str, shifts: List[int]) -> str: @@ -102,6 +106,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String shiftingLetters(String s, int[] shifts) { @@ -118,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +142,8 @@ public: }; ``` +#### Go + ```go func shiftingLetters(s string, shifts []int) string { t := 0 diff --git a/solution/0800-0899/0849.Maximize Distance to Closest Person/README.md b/solution/0800-0899/0849.Maximize Distance to Closest Person/README.md index 1969e5f438bb2..6c5b0fc0941ea 100644 --- a/solution/0800-0899/0849.Maximize Distance to Closest Person/README.md +++ b/solution/0800-0899/0849.Maximize Distance to Closest Person/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def maxDistToClosest(self, seats: List[int]) -> int: @@ -98,6 +100,8 @@ class Solution: return max(first, len(seats) - last - 1, d // 2) ``` +#### Java + ```java class Solution { public int maxDistToClosest(int[] seats) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func maxDistToClosest(seats []int) int { first, last := -1, -1 @@ -160,6 +168,8 @@ func maxDistToClosest(seats []int) int { } ``` +#### TypeScript + ```ts function maxDistToClosest(seats: number[]): number { let first = -1, diff --git a/solution/0800-0899/0849.Maximize Distance to Closest Person/README_EN.md b/solution/0800-0899/0849.Maximize Distance to Closest Person/README_EN.md index 834cca80fb10d..70476b9f54f1b 100644 --- a/solution/0800-0899/0849.Maximize Distance to Closest Person/README_EN.md +++ b/solution/0800-0899/0849.Maximize Distance to Closest Person/README_EN.md @@ -73,6 +73,8 @@ This is the maximum distance possible, so the answer is 3. +#### Python3 + ```python class Solution: def maxDistToClosest(self, seats: List[int]) -> int: @@ -88,6 +90,8 @@ class Solution: return max(first, len(seats) - last - 1, d // 2) ``` +#### Java + ```java class Solution { public int maxDistToClosest(int[] seats) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func maxDistToClosest(seats []int) int { first, last := -1, -1 @@ -150,6 +158,8 @@ func maxDistToClosest(seats []int) int { } ``` +#### TypeScript + ```ts function maxDistToClosest(seats: number[]): number { let first = -1, diff --git a/solution/0800-0899/0850.Rectangle Area II/README.md b/solution/0800-0899/0850.Rectangle Area II/README.md index 0a9764ecc2800..7fda1ccbd2c21 100644 --- a/solution/0800-0899/0850.Rectangle Area II/README.md +++ b/solution/0800-0899/0850.Rectangle Area II/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Node: def __init__(self): @@ -148,6 +150,8 @@ class Solution: return ans ``` +#### Java + ```java class Node { int l, r, cnt, length; @@ -247,6 +251,8 @@ class Solution { } ``` +#### C++ + ```cpp class Node { public: @@ -336,6 +342,8 @@ public: }; ``` +#### Go + ```go func rectangleArea(rectangles [][]int) int { var mod int = 1e9 + 7 diff --git a/solution/0800-0899/0850.Rectangle Area II/README_EN.md b/solution/0800-0899/0850.Rectangle Area II/README_EN.md index 9532b0e0e0fab..f40b5143837c2 100644 --- a/solution/0800-0899/0850.Rectangle Area II/README_EN.md +++ b/solution/0800-0899/0850.Rectangle Area II/README_EN.md @@ -65,6 +65,8 @@ From (1,0) to (2,3), all three rectangles overlap. +#### Python3 + ```python class Node: def __init__(self): @@ -132,6 +134,8 @@ class Solution: return ans ``` +#### Java + ```java class Node { int l, r, cnt, length; @@ -231,6 +235,8 @@ class Solution { } ``` +#### C++ + ```cpp class Node { public: @@ -320,6 +326,8 @@ public: }; ``` +#### Go + ```go func rectangleArea(rectangles [][]int) int { var mod int = 1e9 + 7 diff --git a/solution/0800-0899/0851.Loud and Rich/README.md b/solution/0800-0899/0851.Loud and Rich/README.md index 3fd606c2bf0aa..74b73f8c2f4bc 100644 --- a/solution/0800-0899/0851.Loud and Rich/README.md +++ b/solution/0800-0899/0851.Loud and Rich/README.md @@ -82,6 +82,8 @@ answer[7] = 7, +#### Python3 + ```python class Solution: def loudAndRich(self, richer: List[List[int]], quiet: List[int]) -> List[int]: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go func loudAndRich(richer [][]int, quiet []int) []int { n := len(quiet) @@ -204,6 +212,8 @@ func loudAndRich(richer [][]int, quiet []int) []int { } ``` +#### TypeScript + ```ts function loudAndRich(richer: number[][], quiet: number[]): number[] { const n = quiet.length; diff --git a/solution/0800-0899/0851.Loud and Rich/README_EN.md b/solution/0800-0899/0851.Loud and Rich/README_EN.md index 8f63b16504d14..35997e24cdcd9 100644 --- a/solution/0800-0899/0851.Loud and Rich/README_EN.md +++ b/solution/0800-0899/0851.Loud and Rich/README_EN.md @@ -72,6 +72,8 @@ The other answers can be filled out with similar reasoning. +#### Python3 + ```python class Solution: def loudAndRich(self, richer: List[List[int]], quiet: List[int]) -> List[int]: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func loudAndRich(richer [][]int, quiet []int) []int { n := len(quiet) @@ -194,6 +202,8 @@ func loudAndRich(richer [][]int, quiet []int) []int { } ``` +#### TypeScript + ```ts function loudAndRich(richer: number[][], quiet: number[]): number[] { const n = quiet.length; diff --git a/solution/0800-0899/0852.Peak Index in a Mountain Array/README.md b/solution/0800-0899/0852.Peak Index in a Mountain Array/README.md index 75a8bf8c2fcc9..28f69a2c2dc0d 100644 --- a/solution/0800-0899/0852.Peak Index in a Mountain Array/README.md +++ b/solution/0800-0899/0852.Peak Index in a Mountain Array/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def peakIndexInMountainArray(self, arr: List[int]) -> int: @@ -89,6 +91,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int peakIndexInMountainArray(int[] arr) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func peakIndexInMountainArray(arr []int) int { left, right := 1, len(arr)-2 @@ -138,6 +146,8 @@ func peakIndexInMountainArray(arr []int) int { } ``` +#### TypeScript + ```ts function peakIndexInMountainArray(arr: number[]): number { let left = 1, @@ -154,6 +164,8 @@ function peakIndexInMountainArray(arr: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn peak_index_in_mountain_array(arr: Vec) -> i32 { @@ -172,6 +184,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} arr diff --git a/solution/0800-0899/0852.Peak Index in a Mountain Array/README_EN.md b/solution/0800-0899/0852.Peak Index in a Mountain Array/README_EN.md index 4c81cb2810db9..8025b524b0604 100644 --- a/solution/0800-0899/0852.Peak Index in a Mountain Array/README_EN.md +++ b/solution/0800-0899/0852.Peak Index in a Mountain Array/README_EN.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def peakIndexInMountainArray(self, arr: List[int]) -> int: @@ -87,6 +89,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int peakIndexInMountainArray(int[] arr) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func peakIndexInMountainArray(arr []int) int { left, right := 1, len(arr)-2 @@ -136,6 +144,8 @@ func peakIndexInMountainArray(arr []int) int { } ``` +#### TypeScript + ```ts function peakIndexInMountainArray(arr: number[]): number { let left = 1, @@ -152,6 +162,8 @@ function peakIndexInMountainArray(arr: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn peak_index_in_mountain_array(arr: Vec) -> i32 { @@ -170,6 +182,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} arr diff --git a/solution/0800-0899/0853.Car Fleet/README.md b/solution/0800-0899/0853.Car Fleet/README.md index 8eec0ad81c6a8..18b35fe839247 100644 --- a/solution/0800-0899/0853.Car Fleet/README.md +++ b/solution/0800-0899/0853.Car Fleet/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def carFleet(self, target: int, position: List[int], speed: List[int]) -> int: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int carFleet(int target, int[] position, int[] speed) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func carFleet(target int, position []int, speed []int) (ans int) { n := len(position) @@ -171,6 +179,8 @@ func carFleet(target int, position []int, speed []int) (ans int) { } ``` +#### TypeScript + ```ts function carFleet(target: number, position: number[], speed: number[]): number { const n = position.length; diff --git a/solution/0800-0899/0853.Car Fleet/README_EN.md b/solution/0800-0899/0853.Car Fleet/README_EN.md index 819e9bee9d010..37503ca145d06 100644 --- a/solution/0800-0899/0853.Car Fleet/README_EN.md +++ b/solution/0800-0899/0853.Car Fleet/README_EN.md @@ -84,6 +84,8 @@ Then, the fleet (speed 2) and the car starting at 4 (speed 1) become one fleet, +#### Python3 + ```python class Solution: def carFleet(self, target: int, position: List[int], speed: List[int]) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int carFleet(int target, int[] position, int[] speed) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func carFleet(target int, position []int, speed []int) (ans int) { n := len(position) @@ -164,6 +172,8 @@ func carFleet(target int, position []int, speed []int) (ans int) { } ``` +#### TypeScript + ```ts function carFleet(target: number, position: number[], speed: number[]): number { const n = position.length; diff --git a/solution/0800-0899/0854.K-Similar Strings/README.md b/solution/0800-0899/0854.K-Similar Strings/README.md index b55b01439b9ce..901f3eddf2b6e 100644 --- a/solution/0800-0899/0854.K-Similar Strings/README.md +++ b/solution/0800-0899/0854.K-Similar Strings/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def kSimilarity(self, s1: str, s2: str) -> int: @@ -96,6 +98,8 @@ class Solution: ans += 1 ``` +#### Java + ```java class Solution { public int kSimilarity(String s1, String s2) { @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -187,6 +193,8 @@ public: }; ``` +#### Go + ```go func kSimilarity(s1 string, s2 string) int { next := func(s string) []string { @@ -247,6 +255,8 @@ A\* 算法主要步骤如下: +#### Python3 + ```python class Solution: def kSimilarity(self, s1: str, s2: str) -> int: @@ -277,6 +287,8 @@ class Solution: heappush(q, (dist[nxt] + f(nxt), nxt)) ``` +#### Java + ```java class Solution { public int kSimilarity(String s1, String s2) { @@ -334,6 +346,8 @@ class Solution { } ``` +#### C++ + ```cpp using pis = pair; @@ -383,6 +397,8 @@ public: }; ``` +#### Go + ```go func kSimilarity(s1 string, s2 string) int { next := func(s string) []string { diff --git a/solution/0800-0899/0854.K-Similar Strings/README_EN.md b/solution/0800-0899/0854.K-Similar Strings/README_EN.md index 8f51f1e17ee6e..793ae5c5199ba 100644 --- a/solution/0800-0899/0854.K-Similar Strings/README_EN.md +++ b/solution/0800-0899/0854.K-Similar Strings/README_EN.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python class Solution: def kSimilarity(self, s1: str, s2: str) -> int: @@ -86,6 +88,8 @@ class Solution: ans += 1 ``` +#### Java + ```java class Solution { public int kSimilarity(String s1, String s2) { @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go func kSimilarity(s1 string, s2 string) int { next := func(s string) []string { @@ -224,6 +232,8 @@ func kSimilarity(s1 string, s2 string) int { +#### Python3 + ```python class Solution: def kSimilarity(self, s1: str, s2: str) -> int: @@ -254,6 +264,8 @@ class Solution: heappush(q, (dist[nxt] + f(nxt), nxt)) ``` +#### Java + ```java class Solution { public int kSimilarity(String s1, String s2) { @@ -311,6 +323,8 @@ class Solution { } ``` +#### C++ + ```cpp using pis = pair; @@ -360,6 +374,8 @@ public: }; ``` +#### Go + ```go func kSimilarity(s1 string, s2 string) int { next := func(s string) []string { diff --git a/solution/0800-0899/0855.Exam Room/README.md b/solution/0800-0899/0855.Exam Room/README.md index 150b836d90c9c..b7bf963d84345 100644 --- a/solution/0800-0899/0855.Exam Room/README.md +++ b/solution/0800-0899/0855.Exam Room/README.md @@ -66,6 +66,8 @@ seat() -> 5,学生最后坐在 5 号座位上。 +#### Python3 + ```python from sortedcontainers import SortedList @@ -117,6 +119,8 @@ class ExamRoom: # obj.leave(p) ``` +#### Java + ```java class ExamRoom { private TreeSet ts = new TreeSet<>((a, b) -> { @@ -179,6 +183,8 @@ class ExamRoom { */ ``` +#### C++ + ```cpp int N; @@ -251,6 +257,8 @@ private: */ ``` +#### Go + ```go type ExamRoom struct { rbt *redblacktree.Tree diff --git a/solution/0800-0899/0855.Exam Room/README_EN.md b/solution/0800-0899/0855.Exam Room/README_EN.md index 2452880d08e37..832cc86b1d775 100644 --- a/solution/0800-0899/0855.Exam Room/README_EN.md +++ b/solution/0800-0899/0855.Exam Room/README_EN.md @@ -72,6 +72,8 @@ examRoom.seat(); // return 5, the student sits at the last seat number 5. +#### Python3 + ```python from sortedcontainers import SortedList @@ -123,6 +125,8 @@ class ExamRoom: # obj.leave(p) ``` +#### Java + ```java class ExamRoom { private TreeSet ts = new TreeSet<>((a, b) -> { @@ -185,6 +189,8 @@ class ExamRoom { */ ``` +#### C++ + ```cpp int N; @@ -257,6 +263,8 @@ private: */ ``` +#### Go + ```go type ExamRoom struct { rbt *redblacktree.Tree diff --git a/solution/0800-0899/0856.Score of Parentheses/README.md b/solution/0800-0899/0856.Score of Parentheses/README.md index 144f984f9d889..28cf94507b963 100644 --- a/solution/0800-0899/0856.Score of Parentheses/README.md +++ b/solution/0800-0899/0856.Score of Parentheses/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python class Solution: def scoreOfParentheses(self, s: str) -> int: @@ -109,6 +111,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int scoreOfParentheses(String s) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func scoreOfParentheses(s string) int { ans, d := 0, 0 diff --git a/solution/0800-0899/0856.Score of Parentheses/README_EN.md b/solution/0800-0899/0856.Score of Parentheses/README_EN.md index bea10deef5b40..b293781f8a176 100644 --- a/solution/0800-0899/0856.Score of Parentheses/README_EN.md +++ b/solution/0800-0899/0856.Score of Parentheses/README_EN.md @@ -93,6 +93,8 @@ Related problems about parentheses: +#### Python3 + ```python class Solution: def scoreOfParentheses(self, s: str) -> int: @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int scoreOfParentheses(String s) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func scoreOfParentheses(s string) int { ans, d := 0, 0 diff --git a/solution/0800-0899/0857.Minimum Cost to Hire K Workers/README.md b/solution/0800-0899/0857.Minimum Cost to Hire K Workers/README.md index 2c7129d1a76dc..73641cfd875e7 100644 --- a/solution/0800-0899/0857.Minimum Cost to Hire K Workers/README.md +++ b/solution/0800-0899/0857.Minimum Cost to Hire K Workers/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def mincostToHireWorkers( @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public double mincostToHireWorkers(int[] quality, int[] wage, int k) { @@ -133,6 +137,8 @@ class Pair { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func mincostToHireWorkers(quality []int, wage []int, k int) float64 { t := []pair{} diff --git a/solution/0800-0899/0857.Minimum Cost to Hire K Workers/README_EN.md b/solution/0800-0899/0857.Minimum Cost to Hire K Workers/README_EN.md index 3593f1dddf73b..a1218f717f1e0 100644 --- a/solution/0800-0899/0857.Minimum Cost to Hire K Workers/README_EN.md +++ b/solution/0800-0899/0857.Minimum Cost to Hire K Workers/README_EN.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def mincostToHireWorkers( @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public double mincostToHireWorkers(int[] quality, int[] wage, int k) { @@ -118,6 +122,8 @@ class Pair { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func mincostToHireWorkers(quality []int, wage []int, k int) float64 { t := []pair{} diff --git a/solution/0800-0899/0858.Mirror Reflection/README.md b/solution/0800-0899/0858.Mirror Reflection/README.md index 97f75c3b9e446..e45203f27f473 100644 --- a/solution/0800-0899/0858.Mirror Reflection/README.md +++ b/solution/0800-0899/0858.Mirror Reflection/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def mirrorReflection(self, p: int, q: int) -> int: @@ -77,6 +79,8 @@ class Solution: return 0 if p == 1 else 2 ``` +#### Java + ```java class Solution { public int mirrorReflection(int p, int q) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func mirrorReflection(p int, q int) int { g := gcd(p, q) @@ -132,6 +140,8 @@ func gcd(a, b int) int { } ``` +#### TypeScript + ```ts function mirrorReflection(p: number, q: number): number { const g = gcd(p, q); diff --git a/solution/0800-0899/0858.Mirror Reflection/README_EN.md b/solution/0800-0899/0858.Mirror Reflection/README_EN.md index 1ab11544db68c..9496fb9408f3c 100644 --- a/solution/0800-0899/0858.Mirror Reflection/README_EN.md +++ b/solution/0800-0899/0858.Mirror Reflection/README_EN.md @@ -59,6 +59,8 @@ tags: +#### Python3 + ```python class Solution: def mirrorReflection(self, p: int, q: int) -> int: @@ -70,6 +72,8 @@ class Solution: return 0 if p == 1 else 2 ``` +#### Java + ```java class Solution { public int mirrorReflection(int p, int q) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -103,6 +109,8 @@ public: }; ``` +#### Go + ```go func mirrorReflection(p int, q int) int { g := gcd(p, q) @@ -125,6 +133,8 @@ func gcd(a, b int) int { } ``` +#### TypeScript + ```ts function mirrorReflection(p: number, q: number): number { const g = gcd(p, q); diff --git a/solution/0800-0899/0859.Buddy Strings/README.md b/solution/0800-0899/0859.Buddy Strings/README.md index 4081a1d5b7674..c7c955cf40f42 100644 --- a/solution/0800-0899/0859.Buddy Strings/README.md +++ b/solution/0800-0899/0859.Buddy Strings/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def buddyStrings(self, s: str, goal: str) -> bool: @@ -94,6 +96,8 @@ class Solution: return diff == 2 or (diff == 0 and any(v > 1 for v in cnt1.values())) ``` +#### Java + ```java class Solution { public boolean buddyStrings(String s, String goal) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func buddyStrings(s string, goal string) bool { m, n := len(s), len(goal) @@ -179,6 +187,8 @@ func buddyStrings(s string, goal string) bool { } ``` +#### TypeScript + ```ts function buddyStrings(s: string, goal: string): boolean { const m = s.length; diff --git a/solution/0800-0899/0859.Buddy Strings/README_EN.md b/solution/0800-0899/0859.Buddy Strings/README_EN.md index d5d665dd31e3e..59dbb6003a0b3 100644 --- a/solution/0800-0899/0859.Buddy Strings/README_EN.md +++ b/solution/0800-0899/0859.Buddy Strings/README_EN.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def buddyStrings(self, s: str, goal: str) -> bool: @@ -81,6 +83,8 @@ class Solution: return diff == 2 or (diff == 0 and any(v > 1 for v in cnt1.values())) ``` +#### Java + ```java class Solution { public boolean buddyStrings(String s, String goal) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func buddyStrings(s string, goal string) bool { m, n := len(s), len(goal) @@ -166,6 +174,8 @@ func buddyStrings(s string, goal string) bool { } ``` +#### TypeScript + ```ts function buddyStrings(s: string, goal: string): boolean { const m = s.length; diff --git a/solution/0800-0899/0860.Lemonade Change/README.md b/solution/0800-0899/0860.Lemonade Change/README.md index f30b359c3d16b..cb68c6d4b6270 100644 --- a/solution/0800-0899/0860.Lemonade Change/README.md +++ b/solution/0800-0899/0860.Lemonade Change/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def lemonadeChange(self, bills: List[int]) -> bool: @@ -102,6 +104,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean lemonadeChange(int[] bills) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func lemonadeChange(bills []int) bool { five, ten := 0, 0 @@ -184,6 +192,8 @@ func lemonadeChange(bills []int) bool { } ``` +#### TypeScript + ```ts function lemonadeChange(bills: number[]): boolean { let five = 0; @@ -214,6 +224,8 @@ function lemonadeChange(bills: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn lemonade_change(bills: Vec) -> bool { diff --git a/solution/0800-0899/0860.Lemonade Change/README_EN.md b/solution/0800-0899/0860.Lemonade Change/README_EN.md index 053e40c2d2bbe..17803978c4305 100644 --- a/solution/0800-0899/0860.Lemonade Change/README_EN.md +++ b/solution/0800-0899/0860.Lemonade Change/README_EN.md @@ -66,6 +66,8 @@ Since not every customer received the correct change, the answer is false. +#### Python3 + ```python class Solution: def lemonadeChange(self, bills: List[int]) -> bool: @@ -87,6 +89,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean lemonadeChange(int[] bills) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func lemonadeChange(bills []int) bool { five, ten := 0, 0 @@ -169,6 +177,8 @@ func lemonadeChange(bills []int) bool { } ``` +#### TypeScript + ```ts function lemonadeChange(bills: number[]): boolean { let five = 0; @@ -199,6 +209,8 @@ function lemonadeChange(bills: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn lemonade_change(bills: Vec) -> bool { diff --git a/solution/0800-0899/0861.Score After Flipping Matrix/README.md b/solution/0800-0899/0861.Score After Flipping Matrix/README.md index 1dfa949bdc075..f01fe2811fdc9 100644 --- a/solution/0800-0899/0861.Score After Flipping Matrix/README.md +++ b/solution/0800-0899/0861.Score After Flipping Matrix/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def matrixScore(self, grid: List[List[int]]) -> int: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int matrixScore(int[][] grid) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func matrixScore(grid [][]int) int { m, n := len(grid), len(grid[0]) @@ -165,6 +173,8 @@ func matrixScore(grid [][]int) int { } ``` +#### TypeScript + ```ts function matrixScore(grid: number[][]): number { const m = grid.length; @@ -188,6 +198,8 @@ function matrixScore(grid: number[][]): number { } ``` +#### C# + ```cs public class Solution { public int MatrixScore(int[][] grid) { diff --git a/solution/0800-0899/0861.Score After Flipping Matrix/README_EN.md b/solution/0800-0899/0861.Score After Flipping Matrix/README_EN.md index 1687f688cc959..f1c710489306c 100644 --- a/solution/0800-0899/0861.Score After Flipping Matrix/README_EN.md +++ b/solution/0800-0899/0861.Score After Flipping Matrix/README_EN.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def matrixScore(self, grid: List[List[int]]) -> int: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int matrixScore(int[][] grid) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func matrixScore(grid [][]int) int { m, n := len(grid), len(grid[0]) @@ -152,6 +160,8 @@ func matrixScore(grid [][]int) int { } ``` +#### TypeScript + ```ts function matrixScore(grid: number[][]): number { const m = grid.length; @@ -175,6 +185,8 @@ function matrixScore(grid: number[][]): number { } ``` +#### C# + ```cs public class Solution { public int MatrixScore(int[][] grid) { diff --git a/solution/0800-0899/0862.Shortest Subarray with Sum at Least K/README.md b/solution/0800-0899/0862.Shortest Subarray with Sum at Least K/README.md index e542a47c9689a..a00bc5e41f383 100644 --- a/solution/0800-0899/0862.Shortest Subarray with Sum at Least K/README.md +++ b/solution/0800-0899/0862.Shortest Subarray with Sum at Least K/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def shortestSubarray(self, nums: List[int], k: int) -> int: @@ -105,6 +107,8 @@ class Solution: return -1 if ans == inf else ans ``` +#### Java + ```java class Solution { public int shortestSubarray(int[] nums, int k) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func shortestSubarray(nums []int, k int) int { n := len(nums) diff --git a/solution/0800-0899/0862.Shortest Subarray with Sum at Least K/README_EN.md b/solution/0800-0899/0862.Shortest Subarray with Sum at Least K/README_EN.md index f07a4d1e2087c..ca2946575c688 100644 --- a/solution/0800-0899/0862.Shortest Subarray with Sum at Least K/README_EN.md +++ b/solution/0800-0899/0862.Shortest Subarray with Sum at Least K/README_EN.md @@ -56,6 +56,8 @@ tags: +#### Python3 + ```python class Solution: def shortestSubarray(self, nums: List[int], k: int) -> int: @@ -71,6 +73,8 @@ class Solution: return -1 if ans == inf else ans ``` +#### Java + ```java class Solution { public int shortestSubarray(int[] nums, int k) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func shortestSubarray(nums []int, k int) int { n := len(nums) diff --git a/solution/0800-0899/0863.All Nodes Distance K in Binary Tree/README.md b/solution/0800-0899/0863.All Nodes Distance K in Binary Tree/README.md index 9f3c4c665a13e..7a38dfc853aef 100644 --- a/solution/0800-0899/0863.All Nodes Distance K in Binary Tree/README.md +++ b/solution/0800-0899/0863.All Nodes Distance K in Binary Tree/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -113,6 +115,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -162,6 +166,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -205,6 +211,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -257,6 +265,8 @@ func distanceK(root *TreeNode, target *TreeNode, k int) []int { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: diff --git a/solution/0800-0899/0863.All Nodes Distance K in Binary Tree/README_EN.md b/solution/0800-0899/0863.All Nodes Distance K in Binary Tree/README_EN.md index c0fbde2f2df97..d45a7c24a4fda 100644 --- a/solution/0800-0899/0863.All Nodes Distance K in Binary Tree/README_EN.md +++ b/solution/0800-0899/0863.All Nodes Distance K in Binary Tree/README_EN.md @@ -61,6 +61,8 @@ Explanation: The nodes that are a distance 2 from the target node (with value 5) +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -192,6 +198,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -244,6 +252,8 @@ func distanceK(root *TreeNode, target *TreeNode, k int) []int { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: diff --git a/solution/0800-0899/0864.Shortest Path to Get All Keys/README.md b/solution/0800-0899/0864.Shortest Path to Get All Keys/README.md index 1a4f26e47ce0e..765253be9c12a 100644 --- a/solution/0800-0899/0864.Shortest Path to Get All Keys/README.md +++ b/solution/0800-0899/0864.Shortest Path to Get All Keys/README.md @@ -116,6 +116,8 @@ f d c b +#### Python3 + ```python class Solution: def shortestPathAllKeys(self, grid: List[str]) -> int: @@ -162,6 +164,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { private int[] dirs = {-1, 0, 1, 0, -1}; @@ -229,6 +233,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -285,6 +291,8 @@ public: }; ``` +#### Go + ```go func shortestPathAllKeys(grid []string) int { m, n := len(grid), len(grid[0]) diff --git a/solution/0800-0899/0864.Shortest Path to Get All Keys/README_EN.md b/solution/0800-0899/0864.Shortest Path to Get All Keys/README_EN.md index 97401367a19c9..d7e32a882c4ef 100644 --- a/solution/0800-0899/0864.Shortest Path to Get All Keys/README_EN.md +++ b/solution/0800-0899/0864.Shortest Path to Get All Keys/README_EN.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def shortestPathAllKeys(self, grid: List[str]) -> int: @@ -130,6 +132,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { private int[] dirs = {-1, 0, 1, 0, -1}; @@ -197,6 +201,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -253,6 +259,8 @@ public: }; ``` +#### Go + ```go func shortestPathAllKeys(grid []string) int { m, n := len(grid), len(grid[0]) diff --git a/solution/0800-0899/0865.Smallest Subtree with all the Deepest Nodes/README.md b/solution/0800-0899/0865.Smallest Subtree with all the Deepest Nodes/README.md index be69f530c0f49..2dabf1de147f5 100644 --- a/solution/0800-0899/0865.Smallest Subtree with all the Deepest Nodes/README.md +++ b/solution/0800-0899/0865.Smallest Subtree with all the Deepest Nodes/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -104,6 +106,8 @@ class Solution: return dfs(root)[0] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0800-0899/0865.Smallest Subtree with all the Deepest Nodes/README_EN.md b/solution/0800-0899/0865.Smallest Subtree with all the Deepest Nodes/README_EN.md index ae1864004cfdd..20905c011431c 100644 --- a/solution/0800-0899/0865.Smallest Subtree with all the Deepest Nodes/README_EN.md +++ b/solution/0800-0899/0865.Smallest Subtree with all the Deepest Nodes/README_EN.md @@ -77,6 +77,8 @@ Notice that nodes 5, 3 and 2 contain the deepest nodes in the tree but node 2 is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -100,6 +102,8 @@ class Solution: return dfs(root)[0] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0800-0899/0866.Prime Palindrome/README.md b/solution/0800-0899/0866.Prime Palindrome/README.md index a313e5c9a7d30..05a30ea1847b2 100644 --- a/solution/0800-0899/0866.Prime Palindrome/README.md +++ b/solution/0800-0899/0866.Prime Palindrome/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def primePalindrome(self, n: int) -> int: @@ -103,6 +105,8 @@ class Solution: n += 1 ``` +#### Java + ```java class Solution { public int primePalindrome(int n) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go func primePalindrome(n int) int { isPrime := func(x int) bool { diff --git a/solution/0800-0899/0866.Prime Palindrome/README_EN.md b/solution/0800-0899/0866.Prime Palindrome/README_EN.md index fb6b129be464f..5dee903e7266a 100644 --- a/solution/0800-0899/0866.Prime Palindrome/README_EN.md +++ b/solution/0800-0899/0866.Prime Palindrome/README_EN.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def primePalindrome(self, n: int) -> int: @@ -89,6 +91,8 @@ class Solution: n += 1 ``` +#### Java + ```java class Solution { public int primePalindrome(int n) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func primePalindrome(n int) int { isPrime := func(x int) bool { diff --git a/solution/0800-0899/0867.Transpose Matrix/README.md b/solution/0800-0899/0867.Transpose Matrix/README.md index f0d0b42824cd2..eb83135b82ce1 100644 --- a/solution/0800-0899/0867.Transpose Matrix/README.md +++ b/solution/0800-0899/0867.Transpose Matrix/README.md @@ -62,12 +62,16 @@ tags: +#### Python3 + ```python class Solution: def transpose(self, matrix: List[List[int]]) -> List[List[int]]: return list(zip(*matrix)) ``` +#### Java + ```java class Solution { public int[][] transpose(int[][] matrix) { @@ -83,6 +87,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -97,6 +103,8 @@ public: }; ``` +#### Go + ```go func transpose(matrix [][]int) [][]int { m, n := len(matrix), len(matrix[0]) @@ -111,6 +119,8 @@ func transpose(matrix [][]int) [][]int { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix diff --git a/solution/0800-0899/0867.Transpose Matrix/README_EN.md b/solution/0800-0899/0867.Transpose Matrix/README_EN.md index 851f1685097d3..1d26e15fbbb56 100644 --- a/solution/0800-0899/0867.Transpose Matrix/README_EN.md +++ b/solution/0800-0899/0867.Transpose Matrix/README_EN.md @@ -60,12 +60,16 @@ tags: +#### Python3 + ```python class Solution: def transpose(self, matrix: List[List[int]]) -> List[List[int]]: return list(zip(*matrix)) ``` +#### Java + ```java class Solution { public int[][] transpose(int[][] matrix) { @@ -81,6 +85,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -95,6 +101,8 @@ public: }; ``` +#### Go + ```go func transpose(matrix [][]int) [][]int { m, n := len(matrix), len(matrix[0]) @@ -109,6 +117,8 @@ func transpose(matrix [][]int) [][]int { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix diff --git a/solution/0800-0899/0868.Binary Gap/README.md b/solution/0800-0899/0868.Binary Gap/README.md index 6cf6eadef9297..fd7bd56a9c427 100644 --- a/solution/0800-0899/0868.Binary Gap/README.md +++ b/solution/0800-0899/0868.Binary Gap/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def binaryGap(self, n: int) -> int: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int binaryGap(int n) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func binaryGap(n int) int { ans := 0 @@ -133,6 +141,8 @@ func binaryGap(n int) int { } ``` +#### TypeScript + ```ts function binaryGap(n: number): number { let res = 0; @@ -150,6 +160,8 @@ function binaryGap(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn binary_gap(mut n: i32) -> i32 { diff --git a/solution/0800-0899/0868.Binary Gap/README_EN.md b/solution/0800-0899/0868.Binary Gap/README_EN.md index 78a55925ac1fe..6032762513783 100644 --- a/solution/0800-0899/0868.Binary Gap/README_EN.md +++ b/solution/0800-0899/0868.Binary Gap/README_EN.md @@ -67,6 +67,8 @@ There are not any adjacent pairs of 1's in the binary representation of 8, s +#### Python3 + ```python class Solution: def binaryGap(self, n: int) -> int: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int binaryGap(int n) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func binaryGap(n int) int { ans := 0 @@ -128,6 +136,8 @@ func binaryGap(n int) int { } ``` +#### TypeScript + ```ts function binaryGap(n: number): number { let res = 0; @@ -145,6 +155,8 @@ function binaryGap(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn binary_gap(mut n: i32) -> i32 { diff --git a/solution/0800-0899/0869.Reordered Power of 2/README.md b/solution/0800-0899/0869.Reordered Power of 2/README.md index 364f9f002ca1d..7f95d385979ca 100644 --- a/solution/0800-0899/0869.Reordered Power of 2/README.md +++ b/solution/0800-0899/0869.Reordered Power of 2/README.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def reorderedPowerOf2(self, n: int) -> bool: @@ -79,6 +81,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean reorderedPowerOf2(int n) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func reorderedPowerOf2(n int) bool { convert := func(n int) []byte { diff --git a/solution/0800-0899/0869.Reordered Power of 2/README_EN.md b/solution/0800-0899/0869.Reordered Power of 2/README_EN.md index a12eb39cbe8d9..eff1dc9954caf 100644 --- a/solution/0800-0899/0869.Reordered Power of 2/README_EN.md +++ b/solution/0800-0899/0869.Reordered Power of 2/README_EN.md @@ -56,6 +56,8 @@ tags: +#### Python3 + ```python class Solution: def reorderedPowerOf2(self, n: int) -> bool: @@ -74,6 +76,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean reorderedPowerOf2(int n) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func reorderedPowerOf2(n int) bool { convert := func(n int) []byte { diff --git a/solution/0800-0899/0870.Advantage Shuffle/README.md b/solution/0800-0899/0870.Advantage Shuffle/README.md index 0e52f04e695aa..6277e4ab0cb38 100644 --- a/solution/0800-0899/0870.Advantage Shuffle/README.md +++ b/solution/0800-0899/0870.Advantage Shuffle/README.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def advantageCount(self, nums1: List[int], nums2: List[int]) -> List[int]: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] advantageCount(int[] nums1, int[] nums2) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func advantageCount(nums1 []int, nums2 []int) []int { n := len(nums1) @@ -153,6 +161,8 @@ func advantageCount(nums1 []int, nums2 []int) []int { } ``` +#### TypeScript + ```ts function advantageCount(nums1: number[], nums2: number[]): number[] { const n = nums1.length; @@ -176,6 +186,8 @@ function advantageCount(nums1: number[], nums2: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn advantage_count(mut nums1: Vec, nums2: Vec) -> Vec { diff --git a/solution/0800-0899/0870.Advantage Shuffle/README_EN.md b/solution/0800-0899/0870.Advantage Shuffle/README_EN.md index f60a3f4909869..efd7e591b85fa 100644 --- a/solution/0800-0899/0870.Advantage Shuffle/README_EN.md +++ b/solution/0800-0899/0870.Advantage Shuffle/README_EN.md @@ -50,6 +50,8 @@ tags: +#### Python3 + ```python class Solution: def advantageCount(self, nums1: List[int], nums2: List[int]) -> List[int]: @@ -68,6 +70,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] advantageCount(int[] nums1, int[] nums2) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func advantageCount(nums1 []int, nums2 []int) []int { n := len(nums1) @@ -140,6 +148,8 @@ func advantageCount(nums1 []int, nums2 []int) []int { } ``` +#### TypeScript + ```ts function advantageCount(nums1: number[], nums2: number[]): number[] { const n = nums1.length; @@ -163,6 +173,8 @@ function advantageCount(nums1: number[], nums2: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn advantage_count(mut nums1: Vec, nums2: Vec) -> Vec { diff --git a/solution/0800-0899/0871.Minimum Number of Refueling Stops/README.md b/solution/0800-0899/0871.Minimum Number of Refueling Stops/README.md index d18cdd98375a7..d76cf330cb453 100644 --- a/solution/0800-0899/0871.Minimum Number of Refueling Stops/README.md +++ b/solution/0800-0899/0871.Minimum Number of Refueling Stops/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def minRefuelStops( @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minRefuelStops(int target, int startFuel, int[][] stations) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func minRefuelStops(target int, startFuel int, stations [][]int) int { stations = append(stations, []int{target, 0}) diff --git a/solution/0800-0899/0871.Minimum Number of Refueling Stops/README_EN.md b/solution/0800-0899/0871.Minimum Number of Refueling Stops/README_EN.md index 7fdb824a98e95..2c984324fde2f 100644 --- a/solution/0800-0899/0871.Minimum Number of Refueling Stops/README_EN.md +++ b/solution/0800-0899/0871.Minimum Number of Refueling Stops/README_EN.md @@ -78,6 +78,8 @@ We made 2 refueling stops along the way, so we return 2. +#### Python3 + ```python class Solution: def minRefuelStops( @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minRefuelStops(int target, int startFuel, int[][] stations) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func minRefuelStops(target int, startFuel int, stations [][]int) int { stations = append(stations, []int{target, 0}) diff --git a/solution/0800-0899/0872.Leaf-Similar Trees/README.md b/solution/0800-0899/0872.Leaf-Similar Trees/README.md index ea87d26507054..2ae8af0e9cd97 100644 --- a/solution/0800-0899/0872.Leaf-Similar Trees/README.md +++ b/solution/0800-0899/0872.Leaf-Similar Trees/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -87,6 +89,8 @@ class Solution: return dfs(root1) == dfs(root2) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -179,6 +187,8 @@ func leafSimilar(root1 *TreeNode, root2 *TreeNode) bool { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -238,6 +248,8 @@ impl Solution { } ``` +#### JavaScript + ```js var leafSimilar = function (root1, root2) { const dfs = root => { diff --git a/solution/0800-0899/0872.Leaf-Similar Trees/README_EN.md b/solution/0800-0899/0872.Leaf-Similar Trees/README_EN.md index aab3260c0ef6d..398fd54ab8430 100644 --- a/solution/0800-0899/0872.Leaf-Similar Trees/README_EN.md +++ b/solution/0800-0899/0872.Leaf-Similar Trees/README_EN.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -79,6 +81,8 @@ class Solution: return dfs(root1) == dfs(root2) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -171,6 +179,8 @@ func leafSimilar(root1 *TreeNode, root2 *TreeNode) bool { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -230,6 +240,8 @@ impl Solution { } ``` +#### JavaScript + ```js var leafSimilar = function (root1, root2) { const dfs = root => { diff --git a/solution/0800-0899/0873.Length of Longest Fibonacci Subsequence/README.md b/solution/0800-0899/0873.Length of Longest Fibonacci Subsequence/README.md index 749fceab10206..759ea21feabf1 100644 --- a/solution/0800-0899/0873.Length of Longest Fibonacci Subsequence/README.md +++ b/solution/0800-0899/0873.Length of Longest Fibonacci Subsequence/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def lenLongestFibSubseq(self, arr: List[int]) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int lenLongestFibSubseq(int[] arr) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func lenLongestFibSubseq(arr []int) int { n := len(arr) @@ -183,6 +191,8 @@ func lenLongestFibSubseq(arr []int) int { } ``` +#### JavaScript + ```js /** * @param {number[]} arr diff --git a/solution/0800-0899/0873.Length of Longest Fibonacci Subsequence/README_EN.md b/solution/0800-0899/0873.Length of Longest Fibonacci Subsequence/README_EN.md index 5ac40850273bd..eb5974a2fa75f 100644 --- a/solution/0800-0899/0873.Length of Longest Fibonacci Subsequence/README_EN.md +++ b/solution/0800-0899/0873.Length of Longest Fibonacci Subsequence/README_EN.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def lenLongestFibSubseq(self, arr: List[int]) -> int: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int lenLongestFibSubseq(int[] arr) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func lenLongestFibSubseq(arr []int) int { n := len(arr) @@ -171,6 +179,8 @@ func lenLongestFibSubseq(arr []int) int { } ``` +#### JavaScript + ```js /** * @param {number[]} arr diff --git a/solution/0800-0899/0874.Walking Robot Simulation/README.md b/solution/0800-0899/0874.Walking Robot Simulation/README.md index 6832ae5e8c073..b4e18b37d636b 100644 --- a/solution/0800-0899/0874.Walking Robot Simulation/README.md +++ b/solution/0800-0899/0874.Walking Robot Simulation/README.md @@ -129,6 +129,8 @@ tags: +#### Python3 + ```python class Solution: def robotSim(self, commands: List[int], obstacles: List[List[int]]) -> int: @@ -151,6 +153,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int robotSim(int[] commands, int[][] obstacles) { @@ -187,6 +191,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -223,6 +229,8 @@ public: }; ``` +#### Go + ```go func robotSim(commands []int, obstacles [][]int) (ans int) { dirs := [5]int{0, 1, 0, -1, 0} @@ -249,6 +257,8 @@ func robotSim(commands []int, obstacles [][]int) (ans int) { } ``` +#### TypeScript + ```ts function robotSim(commands: number[], obstacles: number[][]): number { const dirs = [0, 1, 0, -1, 0]; diff --git a/solution/0800-0899/0874.Walking Robot Simulation/README_EN.md b/solution/0800-0899/0874.Walking Robot Simulation/README_EN.md index 2f465d9df9899..4654b7e74c697 100644 --- a/solution/0800-0899/0874.Walking Robot Simulation/README_EN.md +++ b/solution/0800-0899/0874.Walking Robot Simulation/README_EN.md @@ -117,6 +117,8 @@ Time complexity is $O(C \times n + m)$, space complexity is $O(m)$. Where $C$ re +#### Python3 + ```python class Solution: def robotSim(self, commands: List[int], obstacles: List[List[int]]) -> int: @@ -139,6 +141,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int robotSim(int[] commands, int[][] obstacles) { @@ -175,6 +179,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -211,6 +217,8 @@ public: }; ``` +#### Go + ```go func robotSim(commands []int, obstacles [][]int) (ans int) { dirs := [5]int{0, 1, 0, -1, 0} @@ -237,6 +245,8 @@ func robotSim(commands []int, obstacles [][]int) (ans int) { } ``` +#### TypeScript + ```ts function robotSim(commands: number[], obstacles: number[][]): number { const dirs = [0, 1, 0, -1, 0]; diff --git a/solution/0800-0899/0875.Koko Eating Bananas/README.md b/solution/0800-0899/0875.Koko Eating Bananas/README.md index d67a52271ce7a..375436e0b4f85 100644 --- a/solution/0800-0899/0875.Koko Eating Bananas/README.md +++ b/solution/0800-0899/0875.Koko Eating Bananas/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def minEatingSpeed(self, piles: List[int], h: int) -> int: @@ -86,6 +88,8 @@ class Solution: return 1 + bisect_left(range(1, max(piles) + 1), True, key=check) ``` +#### Java + ```java class Solution { public int minEatingSpeed(int[] piles, int h) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func minEatingSpeed(piles []int, h int) int { return 1 + sort.Search(slices.Max(piles), func(k int) bool { @@ -142,6 +150,8 @@ func minEatingSpeed(piles []int, h int) int { } ``` +#### TypeScript + ```ts function minEatingSpeed(piles: number[], h: number): number { let [l, r] = [1, Math.max(...piles)]; @@ -158,6 +168,8 @@ function minEatingSpeed(piles: number[], h: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_eating_speed(piles: Vec, h: i32) -> i32 { @@ -180,6 +192,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int MinEatingSpeed(int[] piles, int h) { diff --git a/solution/0800-0899/0875.Koko Eating Bananas/README_EN.md b/solution/0800-0899/0875.Koko Eating Bananas/README_EN.md index 6c3f14f1d801c..13a26d48b3fb0 100644 --- a/solution/0800-0899/0875.Koko Eating Bananas/README_EN.md +++ b/solution/0800-0899/0875.Koko Eating Bananas/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(n \times \log M)$, where $n$ and $M$ are the length an +#### Python3 + ```python class Solution: def minEatingSpeed(self, piles: List[int], h: int) -> int: @@ -81,6 +83,8 @@ class Solution: return 1 + bisect_left(range(1, max(piles) + 1), True, key=check) ``` +#### Java + ```java class Solution { public int minEatingSpeed(int[] piles, int h) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func minEatingSpeed(piles []int, h int) int { return 1 + sort.Search(slices.Max(piles), func(k int) bool { @@ -137,6 +145,8 @@ func minEatingSpeed(piles []int, h int) int { } ``` +#### TypeScript + ```ts function minEatingSpeed(piles: number[], h: number): number { let [l, r] = [1, Math.max(...piles)]; @@ -153,6 +163,8 @@ function minEatingSpeed(piles: number[], h: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_eating_speed(piles: Vec, h: i32) -> i32 { @@ -175,6 +187,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int MinEatingSpeed(int[] piles, int h) { diff --git a/solution/0800-0899/0876.Middle of the Linked List/README.md b/solution/0800-0899/0876.Middle of the Linked List/README.md index 8d1cb3cd7ab46..fef77dcbc2756 100644 --- a/solution/0800-0899/0876.Middle of the Linked List/README.md +++ b/solution/0800-0899/0876.Middle of the Linked List/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -78,6 +80,8 @@ class Solution: return slow ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -142,6 +150,8 @@ func middleNode(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -166,6 +176,8 @@ function middleNode(head: ListNode | null): ListNode | null { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -196,6 +208,8 @@ impl Solution { } ``` +#### PHP + ```php /** * Definition for a singly-linked list. @@ -230,6 +244,8 @@ class Solution { } ``` +#### C + ```c /** * Definition for singly-linked list. diff --git a/solution/0800-0899/0876.Middle of the Linked List/README_EN.md b/solution/0800-0899/0876.Middle of the Linked List/README_EN.md index dfe13514fa7e2..0d8158a344431 100644 --- a/solution/0800-0899/0876.Middle of the Linked List/README_EN.md +++ b/solution/0800-0899/0876.Middle of the Linked List/README_EN.md @@ -56,6 +56,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -70,6 +72,8 @@ class Solution: return slow ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -134,6 +142,8 @@ func middleNode(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -158,6 +168,8 @@ function middleNode(head: ListNode | null): ListNode | null { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -188,6 +200,8 @@ impl Solution { } ``` +#### PHP + ```php /** * Definition for a singly-linked list. @@ -222,6 +236,8 @@ class Solution { } ``` +#### C + ```c /** * Definition for singly-linked list. diff --git a/solution/0800-0899/0877.Stone Game/README.md b/solution/0800-0899/0877.Stone Game/README.md index c4cc7623cd264..81246c25f5d5a 100644 --- a/solution/0800-0899/0877.Stone Game/README.md +++ b/solution/0800-0899/0877.Stone Game/README.md @@ -83,6 +83,8 @@ Alice 先开始,只能拿前 5 颗或后 5 颗石子 。 +#### Python3 + ```python class Solution: def stoneGame(self, piles: List[int]) -> bool: @@ -95,6 +97,8 @@ class Solution: return dfs(0, len(piles) - 1) > 0 ``` +#### Java + ```java class Solution { private int[] piles; @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func stoneGame(piles []int) bool { n := len(piles) @@ -161,6 +169,8 @@ func stoneGame(piles []int) bool { } ``` +#### TypeScript + ```ts function stoneGame(piles: number[]): boolean { const n = piles.length; @@ -207,6 +217,8 @@ function stoneGame(piles: number[]): boolean { +#### Python3 + ```python class Solution: def stoneGame(self, piles: List[int]) -> bool: @@ -220,6 +232,8 @@ class Solution: return f[0][n - 1] > 0 ``` +#### Java + ```java class Solution { public boolean stoneGame(int[] piles) { @@ -238,6 +252,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -258,6 +274,8 @@ public: }; ``` +#### Go + ```go func stoneGame(piles []int) bool { n := len(piles) @@ -275,6 +293,8 @@ func stoneGame(piles []int) bool { } ``` +#### TypeScript + ```ts function stoneGame(piles: number[]): boolean { const n = piles.length; diff --git a/solution/0800-0899/0877.Stone Game/README_EN.md b/solution/0800-0899/0877.Stone Game/README_EN.md index e13e9bf38526c..d5bd40600b136 100644 --- a/solution/0800-0899/0877.Stone Game/README_EN.md +++ b/solution/0800-0899/0877.Stone Game/README_EN.md @@ -68,6 +68,8 @@ This demonstrated that taking the first 5 was a winning move for Alice, so we re +#### Python3 + ```python class Solution: def stoneGame(self, piles: List[int]) -> bool: @@ -80,6 +82,8 @@ class Solution: return dfs(0, len(piles) - 1) > 0 ``` +#### Java + ```java class Solution { private int[] piles; @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func stoneGame(piles []int) bool { n := len(piles) @@ -146,6 +154,8 @@ func stoneGame(piles []int) bool { } ``` +#### TypeScript + ```ts function stoneGame(piles: number[]): boolean { const n = piles.length; @@ -173,6 +183,8 @@ function stoneGame(piles: number[]): boolean { +#### Python3 + ```python class Solution: def stoneGame(self, piles: List[int]) -> bool: @@ -186,6 +198,8 @@ class Solution: return f[0][n - 1] > 0 ``` +#### Java + ```java class Solution { public boolean stoneGame(int[] piles) { @@ -204,6 +218,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -224,6 +240,8 @@ public: }; ``` +#### Go + ```go func stoneGame(piles []int) bool { n := len(piles) @@ -241,6 +259,8 @@ func stoneGame(piles []int) bool { } ``` +#### TypeScript + ```ts function stoneGame(piles: number[]): boolean { const n = piles.length; diff --git a/solution/0800-0899/0878.Nth Magical Number/README.md b/solution/0800-0899/0878.Nth Magical Number/README.md index 90296b43e4240..96b33d7016ed4 100644 --- a/solution/0800-0899/0878.Nth Magical Number/README.md +++ b/solution/0800-0899/0878.Nth Magical Number/README.md @@ -85,6 +85,8 @@ $$ +#### Python3 + ```python class Solution: def nthMagicalNumber(self, n: int, a: int, b: int) -> int: @@ -94,6 +96,8 @@ class Solution: return bisect_left(range(r), x=n, key=lambda x: x // a + x // b - x // c) % mod ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func nthMagicalNumber(n int, a int, b int) int { c := a * b / gcd(a, b) diff --git a/solution/0800-0899/0878.Nth Magical Number/README_EN.md b/solution/0800-0899/0878.Nth Magical Number/README_EN.md index e61bc57345b04..d078837f4a199 100644 --- a/solution/0800-0899/0878.Nth Magical Number/README_EN.md +++ b/solution/0800-0899/0878.Nth Magical Number/README_EN.md @@ -54,6 +54,8 @@ tags: +#### Python3 + ```python class Solution: def nthMagicalNumber(self, n: int, a: int, b: int) -> int: @@ -63,6 +65,8 @@ class Solution: return bisect_left(range(r), x=n, key=lambda x: x // a + x // b - x // c) % mod ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func nthMagicalNumber(n int, a int, b int) int { c := a * b / gcd(a, b) diff --git a/solution/0800-0899/0879.Profitable Schemes/README.md b/solution/0800-0899/0879.Profitable Schemes/README.md index d3a28235c1a11..32dc009425f49 100644 --- a/solution/0800-0899/0879.Profitable Schemes/README.md +++ b/solution/0800-0899/0879.Profitable Schemes/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def profitableSchemes( @@ -100,6 +102,8 @@ class Solution: return dfs(0, 0, 0) ``` +#### Java + ```java class Solution { private Integer[][][] f; @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func profitableSchemes(n int, minProfit int, group []int, profit []int) int { m := len(group) @@ -219,6 +227,8 @@ func profitableSchemes(n int, minProfit int, group []int, profit []int) int { +#### Python3 + ```python class Solution: def profitableSchemes( @@ -238,6 +248,8 @@ class Solution: return f[m][n][minProfit] ``` +#### Java + ```java class Solution { public int profitableSchemes(int n, int minProfit, int[] group, int[] profit) { @@ -265,6 +277,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -291,6 +305,8 @@ public: }; ``` +#### Go + ```go func profitableSchemes(n int, minProfit int, group []int, profit []int) int { m := len(group) diff --git a/solution/0800-0899/0879.Profitable Schemes/README_EN.md b/solution/0800-0899/0879.Profitable Schemes/README_EN.md index d678c6dc36878..e5a7d15bbf023 100644 --- a/solution/0800-0899/0879.Profitable Schemes/README_EN.md +++ b/solution/0800-0899/0879.Profitable Schemes/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(m \times n \times minProfit)$, and th e space complexi +#### Python3 + ```python class Solution: def profitableSchemes( @@ -92,6 +94,8 @@ class Solution: return dfs(0, 0, 0) ``` +#### Java + ```java class Solution { private Integer[][][] f; @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func profitableSchemes(n int, minProfit int, group []int, profit []int) int { m := len(group) @@ -211,6 +219,8 @@ The time complexity is $O(m \times n \times minProfit)$, and the space complexit +#### Python3 + ```python class Solution: def profitableSchemes( @@ -230,6 +240,8 @@ class Solution: return f[m][n][minProfit] ``` +#### Java + ```java class Solution { public int profitableSchemes(int n, int minProfit, int[] group, int[] profit) { @@ -257,6 +269,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -283,6 +297,8 @@ public: }; ``` +#### Go + ```go func profitableSchemes(n int, minProfit int, group []int, profit []int) int { m := len(group) diff --git a/solution/0800-0899/0880.Decoded String at Index/README.md b/solution/0800-0899/0880.Decoded String at Index/README.md index aed3241173a70..1a0b9caff27fc 100644 --- a/solution/0800-0899/0880.Decoded String at Index/README.md +++ b/solution/0800-0899/0880.Decoded String at Index/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def decodeAtIndex(self, s: str, k: int) -> str: @@ -102,6 +104,8 @@ class Solution: m -= 1 ``` +#### Java + ```java class Solution { public String decodeAtIndex(String s, int k) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func decodeAtIndex(s string, k int) string { m := 0 @@ -179,6 +187,8 @@ func decodeAtIndex(s string, k int) string { } ``` +#### TypeScript + ```ts function decodeAtIndex(s: string, k: number): string { let m = 0n; diff --git a/solution/0800-0899/0880.Decoded String at Index/README_EN.md b/solution/0800-0899/0880.Decoded String at Index/README_EN.md index 179bee7a48cbf..77ec186113eb9 100644 --- a/solution/0800-0899/0880.Decoded String at Index/README_EN.md +++ b/solution/0800-0899/0880.Decoded String at Index/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string. The space +#### Python3 + ```python class Solution: def decodeAtIndex(self, s: str, k: int) -> str: @@ -99,6 +101,8 @@ class Solution: m -= 1 ``` +#### Java + ```java class Solution { public String decodeAtIndex(String s, int k) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func decodeAtIndex(s string, k int) string { m := 0 @@ -176,6 +184,8 @@ func decodeAtIndex(s string, k int) string { } ``` +#### TypeScript + ```ts function decodeAtIndex(s: string, k: number): string { let m = 0n; diff --git a/solution/0800-0899/0881.Boats to Save People/README.md b/solution/0800-0899/0881.Boats to Save People/README.md index 531cd5145262a..f2659e04a3d07 100644 --- a/solution/0800-0899/0881.Boats to Save People/README.md +++ b/solution/0800-0899/0881.Boats to Save People/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def numRescueBoats(self, people: List[int], limit: int) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numRescueBoats(int[] people, int limit) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func numRescueBoats(people []int, limit int) int { sort.Ints(people) @@ -134,6 +142,8 @@ func numRescueBoats(people []int, limit int) int { } ``` +#### TypeScript + ```ts function numRescueBoats(people: number[], limit: number): number { people.sort((a, b) => a - b); diff --git a/solution/0800-0899/0881.Boats to Save People/README_EN.md b/solution/0800-0899/0881.Boats to Save People/README_EN.md index c99e2fc1df62e..1e45b205c04c6 100644 --- a/solution/0800-0899/0881.Boats to Save People/README_EN.md +++ b/solution/0800-0899/0881.Boats to Save People/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def numRescueBoats(self, people: List[int], limit: int) -> int: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numRescueBoats(int[] people, int limit) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func numRescueBoats(people []int, limit int) int { sort.Ints(people) @@ -131,6 +139,8 @@ func numRescueBoats(people []int, limit int) int { } ``` +#### TypeScript + ```ts function numRescueBoats(people: number[], limit: number): number { people.sort((a, b) => a - b); diff --git a/solution/0800-0899/0882.Reachable Nodes In Subdivided Graph/README.md b/solution/0800-0899/0882.Reachable Nodes In Subdivided Graph/README.md index d13b5208855d4..c326bfae9cd85 100644 --- a/solution/0800-0899/0882.Reachable Nodes In Subdivided Graph/README.md +++ b/solution/0800-0899/0882.Reachable Nodes In Subdivided Graph/README.md @@ -100,6 +100,8 @@ tags: +#### Python3 + ```python class Solution: def reachableNodes(self, edges: List[List[int]], maxMoves: int, n: int) -> int: @@ -123,6 +125,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int reachableNodes(int[][] edges, int maxMoves, int n) { @@ -166,6 +170,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -205,6 +211,8 @@ public: }; ``` +#### Go + ```go func reachableNodes(edges [][]int, maxMoves int, n int) (ans int) { g := make([][]pair, n) diff --git a/solution/0800-0899/0882.Reachable Nodes In Subdivided Graph/README_EN.md b/solution/0800-0899/0882.Reachable Nodes In Subdivided Graph/README_EN.md index 7b60114aad1f7..340260bf072bf 100644 --- a/solution/0800-0899/0882.Reachable Nodes In Subdivided Graph/README_EN.md +++ b/solution/0800-0899/0882.Reachable Nodes In Subdivided Graph/README_EN.md @@ -76,6 +76,8 @@ The nodes that are reachable are highlighted in yellow. +#### Python3 + ```python class Solution: def reachableNodes(self, edges: List[List[int]], maxMoves: int, n: int) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int reachableNodes(int[][] edges, int maxMoves, int n) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func reachableNodes(edges [][]int, maxMoves int, n int) (ans int) { g := make([][]pair, n) diff --git a/solution/0800-0899/0883.Projection Area of 3D Shapes/README.md b/solution/0800-0899/0883.Projection Area of 3D Shapes/README.md index cdc3eecd8cbcd..2e3ba96914a5e 100644 --- a/solution/0800-0899/0883.Projection Area of 3D Shapes/README.md +++ b/solution/0800-0899/0883.Projection Area of 3D Shapes/README.md @@ -97,6 +97,8 @@ tags: +#### Python3 + ```python class Solution: def projectionArea(self, grid: List[List[int]]) -> int: @@ -106,6 +108,8 @@ class Solution: return xy + yz + zx ``` +#### Java + ```java class Solution { public int projectionArea(int[][] grid) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func projectionArea(grid [][]int) int { xy, yz, zx := 0, 0, 0 @@ -167,6 +175,8 @@ func projectionArea(grid [][]int) int { } ``` +#### TypeScript + ```ts function projectionArea(grid: number[][]): number { const xy: number = grid.flat().filter(v => v > 0).length; @@ -178,6 +188,8 @@ function projectionArea(grid: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn projection_area(grid: Vec>) -> i32 { diff --git a/solution/0800-0899/0883.Projection Area of 3D Shapes/README_EN.md b/solution/0800-0899/0883.Projection Area of 3D Shapes/README_EN.md index 6dfafdd2bb68a..a0252190d2eaf 100644 --- a/solution/0800-0899/0883.Projection Area of 3D Shapes/README_EN.md +++ b/solution/0800-0899/0883.Projection Area of 3D Shapes/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(n^2)$, where $n$ is the side length of the grid `grid` +#### Python3 + ```python class Solution: def projectionArea(self, grid: List[List[int]]) -> int: @@ -90,6 +92,8 @@ class Solution: return xy + yz + zx ``` +#### Java + ```java class Solution { public int projectionArea(int[][] grid) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func projectionArea(grid [][]int) int { xy, yz, zx := 0, 0, 0 @@ -151,6 +159,8 @@ func projectionArea(grid [][]int) int { } ``` +#### TypeScript + ```ts function projectionArea(grid: number[][]): number { const xy: number = grid.flat().filter(v => v > 0).length; @@ -162,6 +172,8 @@ function projectionArea(grid: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn projection_area(grid: Vec>) -> i32 { diff --git a/solution/0800-0899/0884.Uncommon Words from Two Sentences/README.md b/solution/0800-0899/0884.Uncommon Words from Two Sentences/README.md index fde50db724501..5e9167837601e 100644 --- a/solution/0800-0899/0884.Uncommon Words from Two Sentences/README.md +++ b/solution/0800-0899/0884.Uncommon Words from Two Sentences/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def uncommonFromSentences(self, s1: str, s2: str) -> List[str]: @@ -76,6 +78,8 @@ class Solution: return [s for s, v in cnt.items() if v == 1] ``` +#### Java + ```java class Solution { public String[] uncommonFromSentences(String s1, String s2) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func uncommonFromSentences(s1 string, s2 string) (ans []string) { cnt := map[string]int{} @@ -135,6 +143,8 @@ func uncommonFromSentences(s1 string, s2 string) (ans []string) { } ``` +#### TypeScript + ```ts function uncommonFromSentences(s1: string, s2: string): string[] { const cnt: Map = new Map(); @@ -151,6 +161,8 @@ function uncommonFromSentences(s1: string, s2: string): string[] { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -174,6 +186,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s1 diff --git a/solution/0800-0899/0884.Uncommon Words from Two Sentences/README_EN.md b/solution/0800-0899/0884.Uncommon Words from Two Sentences/README_EN.md index 25a06cb574b1e..8c5c9a9410380 100644 --- a/solution/0800-0899/0884.Uncommon Words from Two Sentences/README_EN.md +++ b/solution/0800-0899/0884.Uncommon Words from Two Sentences/README_EN.md @@ -57,6 +57,8 @@ The time complexity is $O(m + n)$, and the space complexity is $O(m + n)$. Here, +#### Python3 + ```python class Solution: def uncommonFromSentences(self, s1: str, s2: str) -> List[str]: @@ -64,6 +66,8 @@ class Solution: return [s for s, v in cnt.items() if v == 1] ``` +#### Java + ```java class Solution { public String[] uncommonFromSentences(String s1, String s2) { @@ -85,6 +89,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func uncommonFromSentences(s1 string, s2 string) (ans []string) { cnt := map[string]int{} @@ -123,6 +131,8 @@ func uncommonFromSentences(s1 string, s2 string) (ans []string) { } ``` +#### TypeScript + ```ts function uncommonFromSentences(s1: string, s2: string): string[] { const cnt: Map = new Map(); @@ -139,6 +149,8 @@ function uncommonFromSentences(s1: string, s2: string): string[] { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -162,6 +174,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s1 diff --git a/solution/0800-0899/0885.Spiral Matrix III/README.md b/solution/0800-0899/0885.Spiral Matrix III/README.md index 58b9665036f93..746fc2d2703ba 100644 --- a/solution/0800-0899/0885.Spiral Matrix III/README.md +++ b/solution/0800-0899/0885.Spiral Matrix III/README.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def spiralMatrixIII( @@ -83,6 +85,8 @@ class Solution: k += 2 ``` +#### Java + ```java class Solution { public int[][] spiralMatrixIII(int rows, int cols, int rStart, int cStart) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func spiralMatrixIII(rows int, cols int, rStart int, cStart int) [][]int { cnt := rows * cols diff --git a/solution/0800-0899/0885.Spiral Matrix III/README_EN.md b/solution/0800-0899/0885.Spiral Matrix III/README_EN.md index 86bdd3e64208b..42e57339a9b0e 100644 --- a/solution/0800-0899/0885.Spiral Matrix III/README_EN.md +++ b/solution/0800-0899/0885.Spiral Matrix III/README_EN.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python class Solution: def spiralMatrixIII( @@ -79,6 +81,8 @@ class Solution: k += 2 ``` +#### Java + ```java class Solution { public int[][] spiralMatrixIII(int rows, int cols, int rStart, int cStart) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func spiralMatrixIII(rows int, cols int, rStart int, cStart int) [][]int { cnt := rows * cols diff --git a/solution/0800-0899/0886.Possible Bipartition/README.md b/solution/0800-0899/0886.Possible Bipartition/README.md index 9dd7d9bd4add7..5f9eaa8799614 100644 --- a/solution/0800-0899/0886.Possible Bipartition/README.md +++ b/solution/0800-0899/0886.Possible Bipartition/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def possibleBipartition(self, n: int, dislikes: List[List[int]]) -> bool: @@ -106,6 +108,8 @@ class Solution: return all(c or dfs(i, 1) for i, c in enumerate(color)) ``` +#### Java + ```java class Solution { private List[] g; @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go func possibleBipartition(n int, dislikes [][]int) bool { g := make([][]int, n) @@ -203,6 +211,8 @@ func possibleBipartition(n int, dislikes [][]int) bool { } ``` +#### TypeScript + ```ts function possibleBipartition(n: number, dislikes: number[][]): boolean { const color = new Array(n + 1).fill(0); @@ -229,6 +239,8 @@ function possibleBipartition(n: number, dislikes: number[][]): boolean { } ``` +#### Rust + ```rust impl Solution { fn dfs(i: usize, v: usize, color: &mut Vec, g: &Vec>) -> bool { @@ -311,6 +323,8 @@ def union(a, b): +#### Python3 + ```python class Solution: def possibleBipartition(self, n: int, dislikes: List[List[int]]) -> bool: @@ -333,6 +347,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { private int[] p; @@ -369,6 +385,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -396,6 +414,8 @@ public: }; ``` +#### Go + ```go func possibleBipartition(n int, dislikes [][]int) bool { p := make([]int, n) diff --git a/solution/0800-0899/0886.Possible Bipartition/README_EN.md b/solution/0800-0899/0886.Possible Bipartition/README_EN.md index 67fcef8503e7b..05f023e95c56f 100644 --- a/solution/0800-0899/0886.Possible Bipartition/README_EN.md +++ b/solution/0800-0899/0886.Possible Bipartition/README_EN.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def possibleBipartition(self, n: int, dislikes: List[List[int]]) -> bool: @@ -82,6 +84,8 @@ class Solution: return all(c or dfs(i, 1) for i, c in enumerate(color)) ``` +#### Java + ```java class Solution { private List[] g; @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func possibleBipartition(n int, dislikes [][]int) bool { g := make([][]int, n) @@ -179,6 +187,8 @@ func possibleBipartition(n int, dislikes [][]int) bool { } ``` +#### TypeScript + ```ts function possibleBipartition(n: number, dislikes: number[][]): boolean { const color = new Array(n + 1).fill(0); @@ -205,6 +215,8 @@ function possibleBipartition(n: number, dislikes: number[][]): boolean { } ``` +#### Rust + ```rust impl Solution { fn dfs(i: usize, v: usize, color: &mut Vec, g: &Vec>) -> bool { @@ -246,6 +258,8 @@ impl Solution { +#### Python3 + ```python class Solution: def possibleBipartition(self, n: int, dislikes: List[List[int]]) -> bool: @@ -268,6 +282,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { private int[] p; @@ -304,6 +320,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -331,6 +349,8 @@ public: }; ``` +#### Go + ```go func possibleBipartition(n int, dislikes [][]int) bool { p := make([]int, n) diff --git a/solution/0800-0899/0887.Super Egg Drop/README.md b/solution/0800-0899/0887.Super Egg Drop/README.md index e31f3e4141a43..3768e9efb584c 100644 --- a/solution/0800-0899/0887.Super Egg Drop/README.md +++ b/solution/0800-0899/0887.Super Egg Drop/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def superEggDrop(self, k: int, n: int) -> int: @@ -111,6 +113,8 @@ class Solution: return dfs(n, k) ``` +#### Java + ```java class Solution { private int[][] f; @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -180,6 +186,8 @@ public: }; ``` +#### Go + ```go func superEggDrop(k int, n int) int { f := make([][]int, n+1) @@ -214,6 +222,8 @@ func superEggDrop(k int, n int) int { } ``` +#### TypeScript + ```ts function superEggDrop(k: number, n: number): number { const f: number[][] = new Array(n + 1).fill(0).map(() => new Array(k + 1).fill(0)); @@ -265,6 +275,8 @@ function superEggDrop(k: number, n: number): number { +#### Python3 + ```python class Solution: def superEggDrop(self, k: int, n: int) -> int: @@ -285,6 +297,8 @@ class Solution: return f[n][k] ``` +#### Java + ```java class Solution { public int superEggDrop(int k, int n) { @@ -313,6 +327,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -343,6 +359,8 @@ public: }; ``` +#### Go + ```go func superEggDrop(k int, n int) int { f := make([][]int, n+1) @@ -371,6 +389,8 @@ func superEggDrop(k int, n int) int { } ``` +#### TypeScript + ```ts function superEggDrop(k: number, n: number): number { const f: number[][] = new Array(n + 1).fill(0).map(() => new Array(k + 1).fill(0)); diff --git a/solution/0800-0899/0887.Super Egg Drop/README_EN.md b/solution/0800-0899/0887.Super Egg Drop/README_EN.md index 4af24bae687e8..42b7cac4045d2 100644 --- a/solution/0800-0899/0887.Super Egg Drop/README_EN.md +++ b/solution/0800-0899/0887.Super Egg Drop/README_EN.md @@ -71,6 +71,8 @@ Hence, we need at minimum 2 moves to determine with certainty what the value of +#### Python3 + ```python class Solution: def superEggDrop(self, k: int, n: int) -> int: @@ -94,6 +96,8 @@ class Solution: return dfs(n, k) ``` +#### Java + ```java class Solution { private int[][] f; @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func superEggDrop(k int, n int) int { f := make([][]int, n+1) @@ -197,6 +205,8 @@ func superEggDrop(k int, n int) int { } ``` +#### TypeScript + ```ts function superEggDrop(k: number, n: number): number { const f: number[][] = new Array(n + 1).fill(0).map(() => new Array(k + 1).fill(0)); @@ -238,6 +248,8 @@ function superEggDrop(k: number, n: number): number { +#### Python3 + ```python class Solution: def superEggDrop(self, k: int, n: int) -> int: @@ -258,6 +270,8 @@ class Solution: return f[n][k] ``` +#### Java + ```java class Solution { public int superEggDrop(int k, int n) { @@ -286,6 +300,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -316,6 +332,8 @@ public: }; ``` +#### Go + ```go func superEggDrop(k int, n int) int { f := make([][]int, n+1) @@ -344,6 +362,8 @@ func superEggDrop(k int, n int) int { } ``` +#### TypeScript + ```ts function superEggDrop(k: number, n: number): number { const f: number[][] = new Array(n + 1).fill(0).map(() => new Array(k + 1).fill(0)); diff --git a/solution/0800-0899/0888.Fair Candy Swap/README.md b/solution/0800-0899/0888.Fair Candy Swap/README.md index faa8fae4547ac..fa6edaf737b7b 100644 --- a/solution/0800-0899/0888.Fair Candy Swap/README.md +++ b/solution/0800-0899/0888.Fair Candy Swap/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def fairCandySwap(self, aliceSizes: List[int], bobSizes: List[int]) -> List[int]: @@ -87,6 +89,8 @@ class Solution: return [a, target] ``` +#### Java + ```java class Solution { public int[] fairCandySwap(int[] aliceSizes, int[] bobSizes) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### TypeScript + ```ts function fairCandySwap(aliceSizes: number[], bobSizes: number[]): number[] { let s1 = aliceSizes.reduce((a, c) => a + c, 0); diff --git a/solution/0800-0899/0888.Fair Candy Swap/README_EN.md b/solution/0800-0899/0888.Fair Candy Swap/README_EN.md index fb9ea27f443a2..b0b81f5669670 100644 --- a/solution/0800-0899/0888.Fair Candy Swap/README_EN.md +++ b/solution/0800-0899/0888.Fair Candy Swap/README_EN.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def fairCandySwap(self, aliceSizes: List[int], bobSizes: List[int]) -> List[int]: @@ -78,6 +80,8 @@ class Solution: return [a, target] ``` +#### Java + ```java class Solution { public int[] fairCandySwap(int[] aliceSizes, int[] bobSizes) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### TypeScript + ```ts function fairCandySwap(aliceSizes: number[], bobSizes: number[]): number[] { let s1 = aliceSizes.reduce((a, c) => a + c, 0); diff --git a/solution/0800-0899/0889.Construct Binary Tree from Preorder and Postorder Traversal/README.md b/solution/0800-0899/0889.Construct Binary Tree from Preorder and Postorder Traversal/README.md index e0d8fb2a90db8..1ed7d76a7c235 100644 --- a/solution/0800-0899/0889.Construct Binary Tree from Preorder and Postorder Traversal/README.md +++ b/solution/0800-0899/0889.Construct Binary Tree from Preorder and Postorder Traversal/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -115,6 +117,8 @@ class Solution: return dfs(0, len(preorder) - 1, 0, len(postorder) - 1) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -199,6 +205,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -232,6 +240,8 @@ func constructFromPrePost(preorder []int, postorder []int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -292,6 +302,8 @@ function constructFromPrePost(preorder: number[], postorder: number[]): TreeNode +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -319,6 +331,8 @@ class Solution: return dfs(0, 0, len(preorder)) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -364,6 +378,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -403,6 +419,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -436,6 +454,8 @@ func constructFromPrePost(preorder []int, postorder []int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0800-0899/0889.Construct Binary Tree from Preorder and Postorder Traversal/README_EN.md b/solution/0800-0899/0889.Construct Binary Tree from Preorder and Postorder Traversal/README_EN.md index c60198804a288..ee593a99ce5b7 100644 --- a/solution/0800-0899/0889.Construct Binary Tree from Preorder and Postorder Traversal/README_EN.md +++ b/solution/0800-0899/0889.Construct Binary Tree from Preorder and Postorder Traversal/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -111,6 +113,8 @@ class Solution: return dfs(0, len(preorder) - 1, 0, len(postorder) - 1) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -156,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -195,6 +201,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -228,6 +236,8 @@ func constructFromPrePost(preorder []int, postorder []int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -288,6 +298,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -315,6 +327,8 @@ class Solution: return dfs(0, 0, len(preorder)) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -360,6 +374,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -399,6 +415,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -432,6 +450,8 @@ func constructFromPrePost(preorder []int, postorder []int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0800-0899/0890.Find and Replace Pattern/README.md b/solution/0800-0899/0890.Find and Replace Pattern/README.md index e91fa76ae9bde..5f350aa59e1d6 100644 --- a/solution/0800-0899/0890.Find and Replace Pattern/README.md +++ b/solution/0800-0899/0890.Find and Replace Pattern/README.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python class Solution: def findAndReplacePattern(self, words: List[str], pattern: str) -> List[str]: @@ -72,6 +74,8 @@ class Solution: return [word for word in words if match(word, pattern)] ``` +#### Java + ```java class Solution { public List findAndReplacePattern(String[] words, String pattern) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func findAndReplacePattern(words []string, pattern string) []string { match := func(s, t string) bool { @@ -146,6 +154,8 @@ func findAndReplacePattern(words []string, pattern string) []string { } ``` +#### TypeScript + ```ts function findAndReplacePattern(words: string[], pattern: string): string[] { return words.filter(word => { @@ -163,6 +173,8 @@ function findAndReplacePattern(words: string[], pattern: string): string[] { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { diff --git a/solution/0800-0899/0890.Find and Replace Pattern/README_EN.md b/solution/0800-0899/0890.Find and Replace Pattern/README_EN.md index 1a2ea5b880a6d..6a8e9f8b8ab11 100644 --- a/solution/0800-0899/0890.Find and Replace Pattern/README_EN.md +++ b/solution/0800-0899/0890.Find and Replace Pattern/README_EN.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def findAndReplacePattern(self, words: List[str], pattern: str) -> List[str]: @@ -75,6 +77,8 @@ class Solution: return [word for word in words if match(word, pattern)] ``` +#### Java + ```java class Solution { public List findAndReplacePattern(String[] words, String pattern) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func findAndReplacePattern(words []string, pattern string) []string { match := func(s, t string) bool { @@ -149,6 +157,8 @@ func findAndReplacePattern(words []string, pattern string) []string { } ``` +#### TypeScript + ```ts function findAndReplacePattern(words: string[], pattern: string): string[] { return words.filter(word => { @@ -166,6 +176,8 @@ function findAndReplacePattern(words: string[], pattern: string): string[] { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { diff --git a/solution/0800-0899/0891.Sum of Subsequence Widths/README.md b/solution/0800-0899/0891.Sum of Subsequence Widths/README.md index 6a413ead63e8f..9e3f092a978c9 100644 --- a/solution/0800-0899/0891.Sum of Subsequence Widths/README.md +++ b/solution/0800-0899/0891.Sum of Subsequence Widths/README.md @@ -110,6 +110,8 @@ $$ +#### Python3 + ```python class Solution: def sumSubseqWidths(self, nums: List[int]) -> int: @@ -122,6 +124,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func sumSubseqWidths(nums []int) (ans int) { const mod int = 1e9 + 7 diff --git a/solution/0800-0899/0891.Sum of Subsequence Widths/README_EN.md b/solution/0800-0899/0891.Sum of Subsequence Widths/README_EN.md index 53f55db4e44f6..8e9919ab7c6ac 100644 --- a/solution/0800-0899/0891.Sum of Subsequence Widths/README_EN.md +++ b/solution/0800-0899/0891.Sum of Subsequence Widths/README_EN.md @@ -60,6 +60,8 @@ The sum of these widths is 6. +#### Python3 + ```python class Solution: def sumSubseqWidths(self, nums: List[int]) -> int: @@ -72,6 +74,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func sumSubseqWidths(nums []int) (ans int) { const mod int = 1e9 + 7 diff --git a/solution/0800-0899/0892.Surface Area of 3D Shapes/README.md b/solution/0800-0899/0892.Surface Area of 3D Shapes/README.md index 58b7f5a054963..da4318348fb80 100644 --- a/solution/0800-0899/0892.Surface Area of 3D Shapes/README.md +++ b/solution/0800-0899/0892.Surface Area of 3D Shapes/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def surfaceArea(self, grid: List[List[int]]) -> int: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int surfaceArea(int[][] grid) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func surfaceArea(grid [][]int) int { ans := 0 diff --git a/solution/0800-0899/0892.Surface Area of 3D Shapes/README_EN.md b/solution/0800-0899/0892.Surface Area of 3D Shapes/README_EN.md index 50471d92f3b2e..25e47e91a7be1 100644 --- a/solution/0800-0899/0892.Surface Area of 3D Shapes/README_EN.md +++ b/solution/0800-0899/0892.Surface Area of 3D Shapes/README_EN.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def surfaceArea(self, grid: List[List[int]]) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int surfaceArea(int[][] grid) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func surfaceArea(grid [][]int) int { ans := 0 diff --git a/solution/0800-0899/0893.Groups of Special-Equivalent Strings/README.md b/solution/0800-0899/0893.Groups of Special-Equivalent Strings/README.md index 1a1343f917c5f..3231949431510 100644 --- a/solution/0800-0899/0893.Groups of Special-Equivalent Strings/README.md +++ b/solution/0800-0899/0893.Groups of Special-Equivalent Strings/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def numSpecialEquivGroups(self, words: List[str]) -> int: @@ -89,6 +91,8 @@ class Solution: return len(s) ``` +#### Java + ```java class Solution { public int numSpecialEquivGroups(String[] words) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func numSpecialEquivGroups(words []string) int { s := map[string]bool{} diff --git a/solution/0800-0899/0893.Groups of Special-Equivalent Strings/README_EN.md b/solution/0800-0899/0893.Groups of Special-Equivalent Strings/README_EN.md index 95433718e6e53..7df7f86f8132a 100644 --- a/solution/0800-0899/0893.Groups of Special-Equivalent Strings/README_EN.md +++ b/solution/0800-0899/0893.Groups of Special-Equivalent Strings/README_EN.md @@ -77,6 +77,8 @@ Note that in particular, "zzxy" is not special equivalent to "zzy +#### Python3 + ```python class Solution: def numSpecialEquivGroups(self, words: List[str]) -> int: @@ -84,6 +86,8 @@ class Solution: return len(s) ``` +#### Java + ```java class Solution { public int numSpecialEquivGroups(String[] words) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func numSpecialEquivGroups(words []string) int { s := map[string]bool{} diff --git a/solution/0800-0899/0894.All Possible Full Binary Trees/README.md b/solution/0800-0899/0894.All Possible Full Binary Trees/README.md index daa616b39c010..ed32137b69d37 100644 --- a/solution/0800-0899/0894.All Possible Full Binary Trees/README.md +++ b/solution/0800-0899/0894.All Possible Full Binary Trees/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -92,6 +94,8 @@ class Solution: return dfs(n) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -211,6 +219,8 @@ func allPossibleFBT(n int) []*TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -251,6 +261,8 @@ function allPossibleFBT(n: number): Array { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -315,6 +327,8 @@ impl Solution { } ``` +#### C# + ```cs /** * Definition for a binary tree node. diff --git a/solution/0800-0899/0894.All Possible Full Binary Trees/README_EN.md b/solution/0800-0899/0894.All Possible Full Binary Trees/README_EN.md index eb7bdf27920d5..99bfc733e512e 100644 --- a/solution/0800-0899/0894.All Possible Full Binary Trees/README_EN.md +++ b/solution/0800-0899/0894.All Possible Full Binary Trees/README_EN.md @@ -66,6 +66,8 @@ The time complexity is $O(\frac{2^n}{\sqrt{n}})$, and the space complexity is $O +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -90,6 +92,8 @@ class Solution: return dfs(n) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -209,6 +217,8 @@ func allPossibleFBT(n int) []*TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -249,6 +259,8 @@ function allPossibleFBT(n: number): Array { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -313,6 +325,8 @@ impl Solution { } ``` +#### C# + ```cs /** * Definition for a binary tree node. diff --git a/solution/0800-0899/0895.Maximum Frequency Stack/README.md b/solution/0800-0899/0895.Maximum Frequency Stack/README.md index ebbea3aa13a6f..d5959e11d2a17 100644 --- a/solution/0800-0899/0895.Maximum Frequency Stack/README.md +++ b/solution/0800-0899/0895.Maximum Frequency Stack/README.md @@ -83,6 +83,8 @@ freqStack.pop ();//返回 4 ,因为 4, 5 和 7 出现频率最高,但 4 是 +#### Python3 + ```python class FreqStack: def __init__(self): @@ -107,6 +109,8 @@ class FreqStack: # param_2 = obj.pop() ``` +#### Java + ```java class FreqStack { private Map cnt = new HashMap<>(); @@ -137,6 +141,8 @@ class FreqStack { */ ``` +#### C++ + ```cpp class FreqStack { public: @@ -169,6 +175,8 @@ private: */ ``` +#### Go + ```go type FreqStack struct { cnt map[int]int @@ -229,6 +237,8 @@ func (h *hp) Pop() any { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; retur +#### Python3 + ```python class FreqStack: def __init__(self): @@ -255,6 +265,8 @@ class FreqStack: # param_2 = obj.pop() ``` +#### Java + ```java class FreqStack { private Map cnt = new HashMap<>(); @@ -289,6 +301,8 @@ class FreqStack { */ ``` +#### C++ + ```cpp class FreqStack { public: @@ -323,6 +337,8 @@ private: */ ``` +#### Go + ```go type FreqStack struct { cnt map[int]int diff --git a/solution/0800-0899/0895.Maximum Frequency Stack/README_EN.md b/solution/0800-0899/0895.Maximum Frequency Stack/README_EN.md index b700c839b015f..ca7336dae3eb8 100644 --- a/solution/0800-0899/0895.Maximum Frequency Stack/README_EN.md +++ b/solution/0800-0899/0895.Maximum Frequency Stack/README_EN.md @@ -84,6 +84,8 @@ When performing a pop operation, we directly pop an element from the priority qu +#### Python3 + ```python class FreqStack: def __init__(self): @@ -108,6 +110,8 @@ class FreqStack: # param_2 = obj.pop() ``` +#### Java + ```java class FreqStack { private Map cnt = new HashMap<>(); @@ -138,6 +142,8 @@ class FreqStack { */ ``` +#### C++ + ```cpp class FreqStack { public: @@ -170,6 +176,8 @@ private: */ ``` +#### Go + ```go type FreqStack struct { cnt map[int]int @@ -230,6 +238,8 @@ When performing a pop operation, we take the list of elements with frequency $mx +#### Python3 + ```python class FreqStack: def __init__(self): @@ -256,6 +266,8 @@ class FreqStack: # param_2 = obj.pop() ``` +#### Java + ```java class FreqStack { private Map cnt = new HashMap<>(); @@ -290,6 +302,8 @@ class FreqStack { */ ``` +#### C++ + ```cpp class FreqStack { public: @@ -324,6 +338,8 @@ private: */ ``` +#### Go + ```go type FreqStack struct { cnt map[int]int diff --git a/solution/0800-0899/0896.Monotonic Array/README.md b/solution/0800-0899/0896.Monotonic Array/README.md index e5996cea7284f..870bdc9755f30 100644 --- a/solution/0800-0899/0896.Monotonic Array/README.md +++ b/solution/0800-0899/0896.Monotonic Array/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def isMonotonic(self, nums: List[int]) -> bool: @@ -81,6 +83,8 @@ class Solution: return asc or desc ``` +#### Java + ```java class Solution { public boolean isMonotonic(int[] nums) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func isMonotonic(nums []int) bool { asc, desc := false, false @@ -137,6 +145,8 @@ func isMonotonic(nums []int) bool { } ``` +#### TypeScript + ```ts function isMonotonic(nums: number[]): boolean { let [asc, desc] = [false, false]; @@ -154,6 +164,8 @@ function isMonotonic(nums: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn is_monotonic(nums: Vec) -> bool { @@ -174,6 +186,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0800-0899/0896.Monotonic Array/README_EN.md b/solution/0800-0899/0896.Monotonic Array/README_EN.md index 667dd9c8ace8f..e5d67db934458 100644 --- a/solution/0800-0899/0896.Monotonic Array/README_EN.md +++ b/solution/0800-0899/0896.Monotonic Array/README_EN.md @@ -68,6 +68,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def isMonotonic(self, nums: List[int]) -> bool: @@ -76,6 +78,8 @@ class Solution: return asc or desc ``` +#### Java + ```java class Solution { public boolean isMonotonic(int[] nums) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func isMonotonic(nums []int) bool { asc, desc := false, false @@ -132,6 +140,8 @@ func isMonotonic(nums []int) bool { } ``` +#### TypeScript + ```ts function isMonotonic(nums: number[]): boolean { let [asc, desc] = [false, false]; @@ -149,6 +159,8 @@ function isMonotonic(nums: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn is_monotonic(nums: Vec) -> bool { @@ -169,6 +181,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0800-0899/0897.Increasing Order Search Tree/README.md b/solution/0800-0899/0897.Increasing Order Search Tree/README.md index 77294a59eb351..a34eb021f7364 100644 --- a/solution/0800-0899/0897.Increasing Order Search Tree/README.md +++ b/solution/0800-0899/0897.Increasing Order Search Tree/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -89,6 +91,8 @@ class Solution: return dummy.right ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -188,6 +196,8 @@ func increasingBST(root *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0800-0899/0897.Increasing Order Search Tree/README_EN.md b/solution/0800-0899/0897.Increasing Order Search Tree/README_EN.md index 581fc0151b725..da635061c08eb 100644 --- a/solution/0800-0899/0897.Increasing Order Search Tree/README_EN.md +++ b/solution/0800-0899/0897.Increasing Order Search Tree/README_EN.md @@ -63,6 +63,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -87,6 +89,8 @@ class Solution: return dummy.right ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -186,6 +194,8 @@ func increasingBST(root *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0800-0899/0898.Bitwise ORs of Subarrays/README.md b/solution/0800-0899/0898.Bitwise ORs of Subarrays/README.md index abf044de70f2e..3c316fed59309 100644 --- a/solution/0800-0899/0898.Bitwise ORs of Subarrays/README.md +++ b/solution/0800-0899/0898.Bitwise ORs of Subarrays/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def subarrayBitwiseORs(self, arr: List[int]) -> int: @@ -95,6 +97,8 @@ class Solution: return len(ans) ``` +#### Java + ```java class Solution { public int subarrayBitwiseORs(int[] arr) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func subarrayBitwiseORs(arr []int) int { ans := map[int]bool{} @@ -152,6 +160,8 @@ func subarrayBitwiseORs(arr []int) int { } ``` +#### TypeScript + ```ts function subarrayBitwiseORs(arr: number[]): number { const s: Set = new Set(); diff --git a/solution/0800-0899/0898.Bitwise ORs of Subarrays/README_EN.md b/solution/0800-0899/0898.Bitwise ORs of Subarrays/README_EN.md index 2e9f8b6fce0c0..23bf9e4ae1c2f 100644 --- a/solution/0800-0899/0898.Bitwise ORs of Subarrays/README_EN.md +++ b/solution/0800-0899/0898.Bitwise ORs of Subarrays/README_EN.md @@ -79,6 +79,8 @@ The time complexity is $O(n \times \log M)$, and the space complexity is $O(n \t +#### Python3 + ```python class Solution: def subarrayBitwiseORs(self, arr: List[int]) -> int: @@ -90,6 +92,8 @@ class Solution: return len(ans) ``` +#### Java + ```java class Solution { public int subarrayBitwiseORs(int[] arr) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func subarrayBitwiseORs(arr []int) int { ans := map[int]bool{} @@ -147,6 +155,8 @@ func subarrayBitwiseORs(arr []int) int { } ``` +#### TypeScript + ```ts function subarrayBitwiseORs(arr: number[]): number { const s: Set = new Set(); diff --git a/solution/0800-0899/0899.Orderly Queue/README.md b/solution/0800-0899/0899.Orderly Queue/README.md index ca021dd20aaad..0bf128cff4cc1 100644 --- a/solution/0800-0899/0899.Orderly Queue/README.md +++ b/solution/0800-0899/0899.Orderly Queue/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def orderlyQueue(self, s: str, k: int) -> str: @@ -83,6 +85,8 @@ class Solution: return "".join(sorted(s)) ``` +#### Java + ```java class Solution { public String orderlyQueue(String s, int k) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func orderlyQueue(s string, k int) string { if k == 1 { @@ -140,6 +148,8 @@ func orderlyQueue(s string, k int) string { } ``` +#### TypeScript + ```ts function orderlyQueue(s: string, k: number): string { if (k > 1) { diff --git a/solution/0800-0899/0899.Orderly Queue/README_EN.md b/solution/0800-0899/0899.Orderly Queue/README_EN.md index cea01f946b9e2..0e7ff0251a845 100644 --- a/solution/0800-0899/0899.Orderly Queue/README_EN.md +++ b/solution/0800-0899/0899.Orderly Queue/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$. Here, $n$ i +#### Python3 + ```python class Solution: def orderlyQueue(self, s: str, k: int) -> str: @@ -81,6 +83,8 @@ class Solution: return "".join(sorted(s)) ``` +#### Java + ```java class Solution { public String orderlyQueue(String s, int k) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func orderlyQueue(s string, k int) string { if k == 1 { @@ -138,6 +146,8 @@ func orderlyQueue(s string, k int) string { } ``` +#### TypeScript + ```ts function orderlyQueue(s: string, k: number): string { if (k > 1) { diff --git a/solution/0900-0999/0900.RLE Iterator/README.md b/solution/0900-0999/0900.RLE Iterator/README.md index 57fb3203b8a0d..7545296e8329a 100644 --- a/solution/0900-0999/0900.RLE Iterator/README.md +++ b/solution/0900-0999/0900.RLE Iterator/README.md @@ -83,6 +83,8 @@ rLEIterator.next(2); // 耗去序列的 2 个项,返回 -1。 这是由于第 +#### Python3 + ```python class RLEIterator: def __init__(self, encoding: List[int]): @@ -107,6 +109,8 @@ class RLEIterator: # param_1 = obj.next(n) ``` +#### Java + ```java class RLEIterator { private int[] encoding; @@ -139,6 +143,8 @@ class RLEIterator { */ ``` +#### C++ + ```cpp class RLEIterator { public: @@ -173,6 +179,8 @@ private: */ ``` +#### Go + ```go type RLEIterator struct { encoding []int @@ -204,6 +212,8 @@ func (this *RLEIterator) Next(n int) int { */ ``` +#### TypeScript + ```ts class RLEIterator { private encoding: number[]; diff --git a/solution/0900-0999/0900.RLE Iterator/README_EN.md b/solution/0900-0999/0900.RLE Iterator/README_EN.md index e536b6b25dc4b..9ff850e95479e 100644 --- a/solution/0900-0999/0900.RLE Iterator/README_EN.md +++ b/solution/0900-0999/0900.RLE Iterator/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n + q)$, and the space complexity is $O(n)$. Here, $n$ +#### Python3 + ```python class RLEIterator: def __init__(self, encoding: List[int]): @@ -106,6 +108,8 @@ class RLEIterator: # param_1 = obj.next(n) ``` +#### Java + ```java class RLEIterator { private int[] encoding; @@ -138,6 +142,8 @@ class RLEIterator { */ ``` +#### C++ + ```cpp class RLEIterator { public: @@ -172,6 +178,8 @@ private: */ ``` +#### Go + ```go type RLEIterator struct { encoding []int @@ -203,6 +211,8 @@ func (this *RLEIterator) Next(n int) int { */ ``` +#### TypeScript + ```ts class RLEIterator { private encoding: number[]; diff --git a/solution/0900-0999/0901.Online Stock Span/README.md b/solution/0900-0999/0901.Online Stock Span/README.md index d8cc9e0ed4a5f..c123087c6253d 100644 --- a/solution/0900-0999/0901.Online Stock Span/README.md +++ b/solution/0900-0999/0901.Online Stock Span/README.md @@ -89,6 +89,8 @@ stockSpanner.next(85); // 返回 6 +#### Python3 + ```python class StockSpanner: def __init__(self): @@ -107,6 +109,8 @@ class StockSpanner: # param_1 = obj.next(price) ``` +#### Java + ```java class StockSpanner { private Deque stk = new ArrayDeque<>(); @@ -131,6 +135,8 @@ class StockSpanner { */ ``` +#### C++ + ```cpp class StockSpanner { public: @@ -158,6 +164,8 @@ private: */ ``` +#### Go + ```go type StockSpanner struct { stk []pair @@ -186,6 +194,8 @@ type pair struct{ price, cnt int } */ ``` +#### TypeScript + ```ts class StockSpanner { private stk: number[][]; @@ -211,6 +221,8 @@ class StockSpanner { */ ``` +#### Rust + ```rust use std::collections::VecDeque; struct StockSpanner { diff --git a/solution/0900-0999/0901.Online Stock Span/README_EN.md b/solution/0900-0999/0901.Online Stock Span/README_EN.md index b75a9f07b935a..17f3649282438 100644 --- a/solution/0900-0999/0901.Online Stock Span/README_EN.md +++ b/solution/0900-0999/0901.Online Stock Span/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class StockSpanner: def __init__(self): @@ -104,6 +106,8 @@ class StockSpanner: # param_1 = obj.next(price) ``` +#### Java + ```java class StockSpanner { private Deque stk = new ArrayDeque<>(); @@ -128,6 +132,8 @@ class StockSpanner { */ ``` +#### C++ + ```cpp class StockSpanner { public: @@ -155,6 +161,8 @@ private: */ ``` +#### Go + ```go type StockSpanner struct { stk []pair @@ -183,6 +191,8 @@ type pair struct{ price, cnt int } */ ``` +#### TypeScript + ```ts class StockSpanner { private stk: number[][]; @@ -208,6 +218,8 @@ class StockSpanner { */ ``` +#### Rust + ```rust use std::collections::VecDeque; struct StockSpanner { diff --git a/solution/0900-0999/0902.Numbers At Most N Given Digit Set/README.md b/solution/0900-0999/0902.Numbers At Most N Given Digit Set/README.md index e221dd813839c..fe475e4769e5f 100644 --- a/solution/0900-0999/0902.Numbers At Most N Given Digit Set/README.md +++ b/solution/0900-0999/0902.Numbers At Most N Given Digit Set/README.md @@ -114,6 +114,8 @@ $$ +#### Python3 + ```python class Solution: def atMostNGivenDigitSet(self, digits: List[str], n: int) -> int: @@ -140,6 +142,8 @@ class Solution: return dfs(l, True, True) ``` +#### Java + ```java class Solution { private int[] a = new int[12]; @@ -185,6 +189,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -229,6 +235,8 @@ public: }; ``` +#### Go + ```go func atMostNGivenDigitSet(digits []string, n int) int { s := map[int]bool{} diff --git a/solution/0900-0999/0902.Numbers At Most N Given Digit Set/README_EN.md b/solution/0900-0999/0902.Numbers At Most N Given Digit Set/README_EN.md index 74cefc0018e07..65c5dc7371fde 100644 --- a/solution/0900-0999/0902.Numbers At Most N Given Digit Set/README_EN.md +++ b/solution/0900-0999/0902.Numbers At Most N Given Digit Set/README_EN.md @@ -112,6 +112,8 @@ Similar problems: +#### Python3 + ```python class Solution: def atMostNGivenDigitSet(self, digits: List[str], n: int) -> int: @@ -138,6 +140,8 @@ class Solution: return dfs(l, True, True) ``` +#### Java + ```java class Solution { private int[] a = new int[12]; @@ -183,6 +187,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -227,6 +233,8 @@ public: }; ``` +#### Go + ```go func atMostNGivenDigitSet(digits []string, n int) int { s := map[int]bool{} diff --git a/solution/0900-0999/0903.Valid Permutations for DI Sequence/README.md b/solution/0900-0999/0903.Valid Permutations for DI Sequence/README.md index f0e0035539a5e..4e2a43d84c982 100644 --- a/solution/0900-0999/0903.Valid Permutations for DI Sequence/README.md +++ b/solution/0900-0999/0903.Valid Permutations for DI Sequence/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def numPermsDISequence(self, s: str) -> int: @@ -108,6 +110,8 @@ class Solution: return sum(f[n][j] for j in range(n + 1)) % mod ``` +#### Java + ```java class Solution { public int numPermsDISequence(String s) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go func numPermsDISequence(s string) (ans int) { const mod = 1e9 + 7 @@ -203,6 +211,8 @@ func numPermsDISequence(s string) (ans int) { } ``` +#### TypeScript + ```ts function numPermsDISequence(s: string): number { const n = s.length; @@ -240,6 +250,8 @@ function numPermsDISequence(s: string): number { +#### Python3 + ```python class Solution: def numPermsDISequence(self, s: str) -> int: @@ -260,6 +272,8 @@ class Solution: return sum(f[n][j] for j in range(n + 1)) % mod ``` +#### Java + ```java class Solution { public int numPermsDISequence(String s) { @@ -290,6 +304,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -322,6 +338,8 @@ public: }; ``` +#### Go + ```go func numPermsDISequence(s string) (ans int) { const mod = 1e9 + 7 @@ -352,6 +370,8 @@ func numPermsDISequence(s string) (ans int) { } ``` +#### TypeScript + ```ts function numPermsDISequence(s: string): number { const n = s.length; @@ -388,6 +408,8 @@ function numPermsDISequence(s: string): number { +#### Python3 + ```python class Solution: def numPermsDISequence(self, s: str) -> int: @@ -409,6 +431,8 @@ class Solution: return sum(f) % mod ``` +#### Java + ```java class Solution { public int numPermsDISequence(String s) { @@ -441,6 +465,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -474,6 +500,8 @@ public: }; ``` +#### Go + ```go func numPermsDISequence(s string) (ans int) { const mod = 1e9 + 7 @@ -503,6 +531,8 @@ func numPermsDISequence(s string) (ans int) { } ``` +#### TypeScript + ```ts function numPermsDISequence(s: string): number { const n = s.length; diff --git a/solution/0900-0999/0903.Valid Permutations for DI Sequence/README_EN.md b/solution/0900-0999/0903.Valid Permutations for DI Sequence/README_EN.md index 06505501f234f..2b1f3a6fe8678 100644 --- a/solution/0900-0999/0903.Valid Permutations for DI Sequence/README_EN.md +++ b/solution/0900-0999/0903.Valid Permutations for DI Sequence/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(n^3)$, and the space complexity is $O(n^2)$. Here, $n$ +#### Python3 + ```python class Solution: def numPermsDISequence(self, s: str) -> int: @@ -105,6 +107,8 @@ class Solution: return sum(f[n][j] for j in range(n + 1)) % mod ``` +#### Java + ```java class Solution { public int numPermsDISequence(String s) { @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go func numPermsDISequence(s string) (ans int) { const mod = 1e9 + 7 @@ -200,6 +208,8 @@ func numPermsDISequence(s string) (ans int) { } ``` +#### TypeScript + ```ts function numPermsDISequence(s: string): number { const n = s.length; @@ -237,6 +247,8 @@ We can optimize the time complexity to $O(n^2)$ using prefix sums. +#### Python3 + ```python class Solution: def numPermsDISequence(self, s: str) -> int: @@ -257,6 +269,8 @@ class Solution: return sum(f[n][j] for j in range(n + 1)) % mod ``` +#### Java + ```java class Solution { public int numPermsDISequence(String s) { @@ -287,6 +301,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -319,6 +335,8 @@ public: }; ``` +#### Go + ```go func numPermsDISequence(s string) (ans int) { const mod = 1e9 + 7 @@ -349,6 +367,8 @@ func numPermsDISequence(s string) (ans int) { } ``` +#### TypeScript + ```ts function numPermsDISequence(s: string): number { const n = s.length; @@ -385,6 +405,8 @@ Additionally, we can optimize the space complexity to $O(n)$ using a rolling arr +#### Python3 + ```python class Solution: def numPermsDISequence(self, s: str) -> int: @@ -406,6 +428,8 @@ class Solution: return sum(f) % mod ``` +#### Java + ```java class Solution { public int numPermsDISequence(String s) { @@ -438,6 +462,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -471,6 +497,8 @@ public: }; ``` +#### Go + ```go func numPermsDISequence(s string) (ans int) { const mod = 1e9 + 7 @@ -500,6 +528,8 @@ func numPermsDISequence(s string) (ans int) { } ``` +#### TypeScript + ```ts function numPermsDISequence(s: string): number { const n = s.length; diff --git a/solution/0900-0999/0904.Fruit Into Baskets/README.md b/solution/0900-0999/0904.Fruit Into Baskets/README.md index 1df53783ca300..c8581b12fc7b1 100644 --- a/solution/0900-0999/0904.Fruit Into Baskets/README.md +++ b/solution/0900-0999/0904.Fruit Into Baskets/README.md @@ -109,6 +109,8 @@ j i +#### Python3 + ```python class Solution: def totalFruit(self, fruits: List[int]) -> int: @@ -126,6 +128,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int totalFruit(int[] fruits) { @@ -147,6 +151,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go func totalFruit(fruits []int) int { cnt := map[int]int{} @@ -188,6 +196,8 @@ func totalFruit(fruits []int) int { } ``` +#### TypeScript + ```ts function totalFruit(fruits: number[]): number { const n = fruits.length; @@ -207,6 +217,8 @@ function totalFruit(fruits: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -252,6 +264,8 @@ impl Solution { +#### Python3 + ```python class Solution: def totalFruit(self, fruits: List[int]) -> int: @@ -268,6 +282,8 @@ class Solution: return len(fruits) - j ``` +#### Java + ```java class Solution { public int totalFruit(int[] fruits) { @@ -287,6 +303,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -307,6 +325,8 @@ public: }; ``` +#### Go + ```go func totalFruit(fruits []int) int { cnt := map[int]int{} @@ -326,6 +346,8 @@ func totalFruit(fruits []int) int { } ``` +#### TypeScript + ```ts function totalFruit(fruits: number[]): number { const n = fruits.length; @@ -345,6 +367,8 @@ function totalFruit(fruits: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/0900-0999/0904.Fruit Into Baskets/README_EN.md b/solution/0900-0999/0904.Fruit Into Baskets/README_EN.md index d7aaee4e5c67a..5763c9610dc03 100644 --- a/solution/0900-0999/0904.Fruit Into Baskets/README_EN.md +++ b/solution/0900-0999/0904.Fruit Into Baskets/README_EN.md @@ -99,6 +99,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is +#### Python3 + ```python class Solution: def totalFruit(self, fruits: List[int]) -> int: @@ -116,6 +118,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int totalFruit(int[] fruits) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func totalFruit(fruits []int) int { cnt := map[int]int{} @@ -178,6 +186,8 @@ func totalFruit(fruits []int) int { } ``` +#### TypeScript + ```ts function totalFruit(fruits: number[]): number { const n = fruits.length; @@ -197,6 +207,8 @@ function totalFruit(fruits: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -242,6 +254,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is +#### Python3 + ```python class Solution: def totalFruit(self, fruits: List[int]) -> int: @@ -258,6 +272,8 @@ class Solution: return len(fruits) - j ``` +#### Java + ```java class Solution { public int totalFruit(int[] fruits) { @@ -277,6 +293,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -297,6 +315,8 @@ public: }; ``` +#### Go + ```go func totalFruit(fruits []int) int { cnt := map[int]int{} @@ -316,6 +336,8 @@ func totalFruit(fruits []int) int { } ``` +#### TypeScript + ```ts function totalFruit(fruits: number[]): number { const n = fruits.length; @@ -335,6 +357,8 @@ function totalFruit(fruits: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/0900-0999/0905.Sort Array By Parity/README.md b/solution/0900-0999/0905.Sort Array By Parity/README.md index cb21d5b1f2e30..020a4e145c82c 100644 --- a/solution/0900-0999/0905.Sort Array By Parity/README.md +++ b/solution/0900-0999/0905.Sort Array By Parity/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def sortArrayByParity(self, nums: List[int]) -> List[int]: @@ -83,6 +85,8 @@ class Solution: return nums ``` +#### Java + ```java class Solution { public int[] sortArrayByParity(int[] nums) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func sortArrayByParity(nums []int) []int { for i, j := 0, len(nums)-1; i < j; { @@ -139,6 +147,8 @@ func sortArrayByParity(nums []int) []int { } ``` +#### TypeScript + ```ts function sortArrayByParity(nums: number[]): number[] { for (let i = 0, j = nums.length - 1; i < j; ) { @@ -156,6 +166,8 @@ function sortArrayByParity(nums: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn sort_array_by_parity(mut nums: Vec) -> Vec { @@ -176,6 +188,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0900-0999/0905.Sort Array By Parity/README_EN.md b/solution/0900-0999/0905.Sort Array By Parity/README_EN.md index a2cf629f5b014..12df66254d1bc 100644 --- a/solution/0900-0999/0905.Sort Array By Parity/README_EN.md +++ b/solution/0900-0999/0905.Sort Array By Parity/README_EN.md @@ -66,6 +66,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def sortArrayByParity(self, nums: List[int]) -> List[int]: @@ -81,6 +83,8 @@ class Solution: return nums ``` +#### Java + ```java class Solution { public int[] sortArrayByParity(int[] nums) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func sortArrayByParity(nums []int) []int { for i, j := 0, len(nums)-1; i < j; { @@ -137,6 +145,8 @@ func sortArrayByParity(nums []int) []int { } ``` +#### TypeScript + ```ts function sortArrayByParity(nums: number[]): number[] { for (let i = 0, j = nums.length - 1; i < j; ) { @@ -154,6 +164,8 @@ function sortArrayByParity(nums: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn sort_array_by_parity(mut nums: Vec) -> Vec { @@ -174,6 +186,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0900-0999/0906.Super Palindromes/README.md b/solution/0900-0999/0906.Super Palindromes/README.md index be5a2dcb085d8..4f24acb28b787 100644 --- a/solution/0900-0999/0906.Super Palindromes/README.md +++ b/solution/0900-0999/0906.Super Palindromes/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python ps = [] for i in range(1, 10**5 + 1): @@ -89,6 +91,8 @@ class Solution: return sum(l <= x <= r and is_palindrome(x) for x in map(lambda x: x * x, ps)) ``` +#### Java + ```java class Solution { private static long[] ps; @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = unsigned long long; @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go var ps [2 * 100000]int64 @@ -210,6 +218,8 @@ func superpalindromesInRange(left string, right string) (ans int) { } ``` +#### TypeScript + ```ts const ps = Array(2e5).fill(0); diff --git a/solution/0900-0999/0906.Super Palindromes/README_EN.md b/solution/0900-0999/0906.Super Palindromes/README_EN.md index c077d4728fdb4..06278797b1d04 100644 --- a/solution/0900-0999/0906.Super Palindromes/README_EN.md +++ b/solution/0900-0999/0906.Super Palindromes/README_EN.md @@ -71,6 +71,8 @@ Similar problems: +#### Python3 + ```python ps = [] for i in range(1, 10**5 + 1): @@ -94,6 +96,8 @@ class Solution: return sum(l <= x <= r and is_palindrome(x) for x in map(lambda x: x * x, ps)) ``` +#### Java + ```java class Solution { private static long[] ps; @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = unsigned long long; @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go var ps [2 * 100000]int64 @@ -215,6 +223,8 @@ func superpalindromesInRange(left string, right string) (ans int) { } ``` +#### TypeScript + ```ts const ps = Array(2e5).fill(0); diff --git a/solution/0900-0999/0907.Sum of Subarray Minimums/README.md b/solution/0900-0999/0907.Sum of Subarray Minimums/README.md index 82119d7e827b9..b653263dd3f32 100644 --- a/solution/0900-0999/0907.Sum of Subarray Minimums/README.md +++ b/solution/0900-0999/0907.Sum of Subarray Minimums/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def sumSubarrayMins(self, arr: List[int]) -> int: @@ -117,6 +119,8 @@ class Solution: return sum((i - left[i]) * (right[i] - i) * v for i, v in enumerate(arr)) % mod ``` +#### Java + ```java class Solution { public int sumSubarrayMins(int[] arr) { @@ -156,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -194,6 +200,8 @@ public: }; ``` +#### Go + ```go func sumSubarrayMins(arr []int) (ans int) { n := len(arr) @@ -232,6 +240,8 @@ func sumSubarrayMins(arr []int) (ans int) { } ``` +#### TypeScript + ```ts function sumSubarrayMins(arr: number[]): number { const n: number = arr.length; @@ -269,6 +279,8 @@ function sumSubarrayMins(arr: number[]): number { } ``` +#### Rust + ```rust use std::collections::VecDeque; diff --git a/solution/0900-0999/0907.Sum of Subarray Minimums/README_EN.md b/solution/0900-0999/0907.Sum of Subarray Minimums/README_EN.md index 3293eda676bd3..dd6b0821740b0 100644 --- a/solution/0900-0999/0907.Sum of Subarray Minimums/README_EN.md +++ b/solution/0900-0999/0907.Sum of Subarray Minimums/README_EN.md @@ -88,6 +88,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python class Solution: def sumSubarrayMins(self, arr: List[int]) -> int: @@ -113,6 +115,8 @@ class Solution: return sum((i - left[i]) * (right[i] - i) * v for i, v in enumerate(arr)) % mod ``` +#### Java + ```java class Solution { public int sumSubarrayMins(int[] arr) { @@ -152,6 +156,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -190,6 +196,8 @@ public: }; ``` +#### Go + ```go func sumSubarrayMins(arr []int) (ans int) { n := len(arr) @@ -228,6 +236,8 @@ func sumSubarrayMins(arr []int) (ans int) { } ``` +#### TypeScript + ```ts function sumSubarrayMins(arr: number[]): number { const n: number = arr.length; @@ -265,6 +275,8 @@ function sumSubarrayMins(arr: number[]): number { } ``` +#### Rust + ```rust use std::collections::VecDeque; diff --git a/solution/0900-0999/0908.Smallest Range I/README.md b/solution/0900-0999/0908.Smallest Range I/README.md index d08b417616835..07ba94945b58b 100644 --- a/solution/0900-0999/0908.Smallest Range I/README.md +++ b/solution/0900-0999/0908.Smallest Range I/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def smallestRangeI(self, nums: List[int], k: int) -> int: @@ -84,6 +86,8 @@ class Solution: return max(0, mx - mi - k * 2) ``` +#### Java + ```java class Solution { public int smallestRangeI(int[] nums, int k) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func smallestRangeI(nums []int, k int) int { mi, mx := slices.Min(nums), slices.Max(nums) @@ -115,6 +123,8 @@ func smallestRangeI(nums []int, k int) int { } ``` +#### TypeScript + ```ts function smallestRangeI(nums: number[], k: number): number { const mx = Math.max(...nums); @@ -123,6 +133,8 @@ function smallestRangeI(nums: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn smallest_range_i(nums: Vec, k: i32) -> i32 { diff --git a/solution/0900-0999/0908.Smallest Range I/README_EN.md b/solution/0900-0999/0908.Smallest Range I/README_EN.md index 3dd1b001491da..25a5eaa82384d 100644 --- a/solution/0900-0999/0908.Smallest Range I/README_EN.md +++ b/solution/0900-0999/0908.Smallest Range I/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array `nums`. The +#### Python3 + ```python class Solution: def smallestRangeI(self, nums: List[int], k: int) -> int: @@ -82,6 +84,8 @@ class Solution: return max(0, mx - mi - k * 2) ``` +#### Java + ```java class Solution { public int smallestRangeI(int[] nums, int k) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func smallestRangeI(nums []int, k int) int { mi, mx := slices.Min(nums), slices.Max(nums) @@ -113,6 +121,8 @@ func smallestRangeI(nums []int, k int) int { } ``` +#### TypeScript + ```ts function smallestRangeI(nums: number[], k: number): number { const mx = Math.max(...nums); @@ -121,6 +131,8 @@ function smallestRangeI(nums: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn smallest_range_i(nums: Vec, k: i32) -> i32 { diff --git a/solution/0900-0999/0909.Snakes and Ladders/README.md b/solution/0900-0999/0909.Snakes and Ladders/README.md index b909eec6815df..04ead417a97b5 100644 --- a/solution/0900-0999/0909.Snakes and Ladders/README.md +++ b/solution/0900-0999/0909.Snakes and Ladders/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def snakesAndLadders(self, board: List[List[int]]) -> int: @@ -119,6 +121,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { private int n; @@ -164,6 +168,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -204,6 +210,8 @@ public: }; ``` +#### Go + ```go func snakesAndLadders(board [][]int) int { n := len(board) diff --git a/solution/0900-0999/0909.Snakes and Ladders/README_EN.md b/solution/0900-0999/0909.Snakes and Ladders/README_EN.md index 29422bb2ff910..52e30c96332a6 100644 --- a/solution/0900-0999/0909.Snakes and Ladders/README_EN.md +++ b/solution/0900-0999/0909.Snakes and Ladders/README_EN.md @@ -86,6 +86,8 @@ This is the lowest possible number of moves to reach the last square, so return +#### Python3 + ```python class Solution: def snakesAndLadders(self, board: List[List[int]]) -> int: @@ -115,6 +117,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { private int n; @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -200,6 +206,8 @@ public: }; ``` +#### Go + ```go func snakesAndLadders(board [][]int) int { n := len(board) diff --git a/solution/0900-0999/0910.Smallest Range II/README.md b/solution/0900-0999/0910.Smallest Range II/README.md index a8c105564cdbc..b2b612f1c240c 100644 --- a/solution/0900-0999/0910.Smallest Range II/README.md +++ b/solution/0900-0999/0910.Smallest Range II/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def smallestRangeII(self, nums: List[int], k: int) -> int: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int smallestRangeII(int[] nums, int k) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func smallestRangeII(nums []int, k int) int { sort.Ints(nums) @@ -141,6 +149,8 @@ func smallestRangeII(nums []int, k int) int { } ``` +#### TypeScript + ```ts function smallestRangeII(nums: number[], k: number): number { nums.sort((a, b) => a - b); diff --git a/solution/0900-0999/0910.Smallest Range II/README_EN.md b/solution/0900-0999/0910.Smallest Range II/README_EN.md index 557a91c010f39..ade3f7c62784b 100644 --- a/solution/0900-0999/0910.Smallest Range II/README_EN.md +++ b/solution/0900-0999/0910.Smallest Range II/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def smallestRangeII(self, nums: List[int], k: int) -> int: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int smallestRangeII(int[] nums, int k) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func smallestRangeII(nums []int, k int) int { sort.Ints(nums) @@ -136,6 +144,8 @@ func smallestRangeII(nums []int, k int) int { } ``` +#### TypeScript + ```ts function smallestRangeII(nums: number[], k: number): number { nums.sort((a, b) => a - b); diff --git a/solution/0900-0999/0911.Online Election/README.md b/solution/0900-0999/0911.Online Election/README.md index 42a66b977f50e..ce78476013089 100644 --- a/solution/0900-0999/0911.Online Election/README.md +++ b/solution/0900-0999/0911.Online Election/README.md @@ -84,6 +84,8 @@ topVotedCandidate.q(8); // 返回 1 +#### Python3 + ```python class TopVotedCandidate: @@ -108,6 +110,8 @@ class TopVotedCandidate: # param_1 = obj.q(t) ``` +#### Java + ```java class TopVotedCandidate { private int[] times; @@ -143,6 +147,8 @@ class TopVotedCandidate { */ ``` +#### C++ + ```cpp class TopVotedCandidate { public: @@ -179,6 +185,8 @@ private: */ ``` +#### Go + ```go type TopVotedCandidate struct { times []int @@ -212,6 +220,8 @@ func (this *TopVotedCandidate) Q(t int) int { */ ``` +#### TypeScript + ```ts class TopVotedCandidate { private times: number[]; diff --git a/solution/0900-0999/0911.Online Election/README_EN.md b/solution/0900-0999/0911.Online Election/README_EN.md index ee56825b56568..dcbc85de8ff2f 100644 --- a/solution/0900-0999/0911.Online Election/README_EN.md +++ b/solution/0900-0999/0911.Online Election/README_EN.md @@ -82,6 +82,8 @@ In terms of time complexity, during initialization, we need $O(n)$ time, and dur +#### Python3 + ```python class TopVotedCandidate: @@ -106,6 +108,8 @@ class TopVotedCandidate: # param_1 = obj.q(t) ``` +#### Java + ```java class TopVotedCandidate { private int[] times; @@ -141,6 +145,8 @@ class TopVotedCandidate { */ ``` +#### C++ + ```cpp class TopVotedCandidate { public: @@ -177,6 +183,8 @@ private: */ ``` +#### Go + ```go type TopVotedCandidate struct { times []int @@ -210,6 +218,8 @@ func (this *TopVotedCandidate) Q(t int) int { */ ``` +#### TypeScript + ```ts class TopVotedCandidate { private times: number[]; diff --git a/solution/0900-0999/0912.Sort an Array/README.md b/solution/0900-0999/0912.Sort an Array/README.md index 99fbdf929cd94..02c18448c8a98 100644 --- a/solution/0900-0999/0912.Sort an Array/README.md +++ b/solution/0900-0999/0912.Sort an Array/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def sortArray(self, nums: List[int]) -> List[int]: @@ -91,6 +93,8 @@ class Solution: return nums ``` +#### Java + ```java class Solution { private int[] nums; @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func sortArray(nums []int) []int { quickSort(nums, 0, len(nums)-1) @@ -186,6 +194,8 @@ func quickSort(nums []int, l, r int) { } ``` +#### TypeScript + ```ts function sortArray(nums: number[]): number[] { function quickSort(l: number, r: number) { @@ -211,6 +221,8 @@ function sortArray(nums: number[]): number[] { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -254,6 +266,8 @@ var sortArray = function (nums) { +#### Python3 + ```python class Solution: def sortArray(self, nums: List[int]) -> List[int]: @@ -283,6 +297,8 @@ class Solution: return nums ``` +#### Java + ```java class Solution { private int[] nums; @@ -320,6 +336,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -356,6 +374,8 @@ public: }; ``` +#### Go + ```go func sortArray(nums []int) []int { mergeSort(nums, 0, len(nums)-1) @@ -395,6 +415,8 @@ func mergeSort(nums []int, l, r int) { } ``` +#### TypeScript + ```ts function sortArray(nums: number[]): number[] { function mergetSort(l: number, r: number) { @@ -429,6 +451,8 @@ function sortArray(nums: number[]): number[] { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -477,6 +501,8 @@ var sortArray = function (nums) { +#### Java + ```java class Solution { private int[] nums; diff --git a/solution/0900-0999/0912.Sort an Array/README_EN.md b/solution/0900-0999/0912.Sort an Array/README_EN.md index b745d56609c17..428a2b45b74a1 100644 --- a/solution/0900-0999/0912.Sort an Array/README_EN.md +++ b/solution/0900-0999/0912.Sort an Array/README_EN.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def sortArray(self, nums: List[int]) -> List[int]: @@ -86,6 +88,8 @@ class Solution: return nums ``` +#### Java + ```java class Solution { private int[] nums; @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func sortArray(nums []int) []int { quickSort(nums, 0, len(nums)-1) @@ -181,6 +189,8 @@ func quickSort(nums []int, l, r int) { } ``` +#### TypeScript + ```ts function sortArray(nums: number[]): number[] { function quickSort(l: number, r: number) { @@ -206,6 +216,8 @@ function sortArray(nums: number[]): number[] { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -245,6 +257,8 @@ var sortArray = function (nums) { +#### Python3 + ```python class Solution: def sortArray(self, nums: List[int]) -> List[int]: @@ -274,6 +288,8 @@ class Solution: return nums ``` +#### Java + ```java class Solution { private int[] nums; @@ -311,6 +327,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -347,6 +365,8 @@ public: }; ``` +#### Go + ```go func sortArray(nums []int) []int { mergeSort(nums, 0, len(nums)-1) @@ -386,6 +406,8 @@ func mergeSort(nums []int, l, r int) { } ``` +#### TypeScript + ```ts function sortArray(nums: number[]): number[] { function mergetSort(l: number, r: number) { @@ -420,6 +442,8 @@ function sortArray(nums: number[]): number[] { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -468,6 +492,8 @@ var sortArray = function (nums) { +#### Java + ```java class Solution { private int[] nums; diff --git a/solution/0900-0999/0913.Cat and Mouse/README.md b/solution/0900-0999/0913.Cat and Mouse/README.md index 29fde0a299310..271e07d016d0e 100644 --- a/solution/0900-0999/0913.Cat and Mouse/README.md +++ b/solution/0900-0999/0913.Cat and Mouse/README.md @@ -108,6 +108,8 @@ tags: +#### Python3 + ```python HOLE, MOUSE_START, CAT_START = 0, 1, 2 MOUSE_TURN, CAT_TURN = 0, 1 @@ -167,6 +169,8 @@ class Solution: return res[MOUSE_START][CAT_START][MOUSE_TURN] ``` +#### Java + ```java class Solution { private int n; @@ -251,6 +255,8 @@ class Solution { } ``` +#### C++ + ```cpp const int HOLE = 0; const int MOUSE_START = 1; @@ -329,6 +335,8 @@ public: }; ``` +#### Go + ```go const ( hole = 0 diff --git a/solution/0900-0999/0913.Cat and Mouse/README_EN.md b/solution/0900-0999/0913.Cat and Mouse/README_EN.md index 3c8b131738a1e..94f09b3ccbac2 100644 --- a/solution/0900-0999/0913.Cat and Mouse/README_EN.md +++ b/solution/0900-0999/0913.Cat and Mouse/README_EN.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python HOLE, MOUSE_START, CAT_START = 0, 1, 2 MOUSE_TURN, CAT_TURN = 0, 1 @@ -143,6 +145,8 @@ class Solution: return res[MOUSE_START][CAT_START][MOUSE_TURN] ``` +#### Java + ```java class Solution { private int n; @@ -227,6 +231,8 @@ class Solution { } ``` +#### C++ + ```cpp const int HOLE = 0; const int MOUSE_START = 1; @@ -305,6 +311,8 @@ public: }; ``` +#### Go + ```go const ( hole = 0 diff --git a/solution/0900-0999/0914.X of a Kind in a Deck of Cards/README.md b/solution/0900-0999/0914.X of a Kind in a Deck of Cards/README.md index d7b43cfe228c5..3535a73ee6119 100644 --- a/solution/0900-0999/0914.X of a Kind in a Deck of Cards/README.md +++ b/solution/0900-0999/0914.X of a Kind in a Deck of Cards/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def hasGroupsSizeX(self, deck: List[int]) -> bool: @@ -80,6 +82,8 @@ class Solution: return reduce(gcd, vals) >= 2 ``` +#### Java + ```java class Solution { public boolean hasGroupsSizeX(int[] deck) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func hasGroupsSizeX(deck []int) bool { cnt := make([]int, 10000) diff --git a/solution/0900-0999/0914.X of a Kind in a Deck of Cards/README_EN.md b/solution/0900-0999/0914.X of a Kind in a Deck of Cards/README_EN.md index c921af905de23..dad44bd775085 100644 --- a/solution/0900-0999/0914.X of a Kind in a Deck of Cards/README_EN.md +++ b/solution/0900-0999/0914.X of a Kind in a Deck of Cards/README_EN.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def hasGroupsSizeX(self, deck: List[int]) -> bool: @@ -73,6 +75,8 @@ class Solution: return reduce(gcd, vals) >= 2 ``` +#### Java + ```java class Solution { public boolean hasGroupsSizeX(int[] deck) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func hasGroupsSizeX(deck []int) bool { cnt := make([]int, 10000) diff --git a/solution/0900-0999/0915.Partition Array into Disjoint Intervals/README.md b/solution/0900-0999/0915.Partition Array into Disjoint Intervals/README.md index c8e1fba1e4b6c..ff850de183fa3 100644 --- a/solution/0900-0999/0915.Partition Array into Disjoint Intervals/README.md +++ b/solution/0900-0999/0915.Partition Array into Disjoint Intervals/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def partitionDisjoint(self, nums: List[int]) -> int: @@ -88,6 +90,8 @@ class Solution: return i ``` +#### Java + ```java class Solution { public int partitionDisjoint(int[] nums) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func partitionDisjoint(nums []int) int { n := len(nums) diff --git a/solution/0900-0999/0915.Partition Array into Disjoint Intervals/README_EN.md b/solution/0900-0999/0915.Partition Array into Disjoint Intervals/README_EN.md index 153e90f8ce814..0bdb63f7cce11 100644 --- a/solution/0900-0999/0915.Partition Array into Disjoint Intervals/README_EN.md +++ b/solution/0900-0999/0915.Partition Array into Disjoint Intervals/README_EN.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def partitionDisjoint(self, nums: List[int]) -> int: @@ -78,6 +80,8 @@ class Solution: return i ``` +#### Java + ```java class Solution { public int partitionDisjoint(int[] nums) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func partitionDisjoint(nums []int) int { n := len(nums) diff --git a/solution/0900-0999/0916.Word Subsets/README.md b/solution/0900-0999/0916.Word Subsets/README.md index 368b7c7cae28b..551a6413d4ffc 100644 --- a/solution/0900-0999/0916.Word Subsets/README.md +++ b/solution/0900-0999/0916.Word Subsets/README.md @@ -97,6 +97,8 @@ tags: +#### Python3 + ```python class Solution: def wordSubsets(self, words1: List[str], words2: List[str]) -> List[str]: @@ -113,6 +115,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List wordSubsets(String[] words1, String[] words2) { @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -185,6 +191,8 @@ public: }; ``` +#### Go + ```go func wordSubsets(words1 []string, words2 []string) (ans []string) { cnt := [26]int{} diff --git a/solution/0900-0999/0916.Word Subsets/README_EN.md b/solution/0900-0999/0916.Word Subsets/README_EN.md index f3c24bfe4a424..9c359b8baa13b 100644 --- a/solution/0900-0999/0916.Word Subsets/README_EN.md +++ b/solution/0900-0999/0916.Word Subsets/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def wordSubsets(self, words1: List[str], words2: List[str]) -> List[str]: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List wordSubsets(String[] words1, String[] words2) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func wordSubsets(words1 []string, words2 []string) (ans []string) { cnt := [26]int{} diff --git a/solution/0900-0999/0917.Reverse Only Letters/README.md b/solution/0900-0999/0917.Reverse Only Letters/README.md index 9b8c613fc92ce..614cbf35a5593 100644 --- a/solution/0900-0999/0917.Reverse Only Letters/README.md +++ b/solution/0900-0999/0917.Reverse Only Letters/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def reverseOnlyLetters(self, s: str) -> str: @@ -98,6 +100,8 @@ class Solution: return "".join(cs) ``` +#### Java + ```java class Solution { public String reverseOnlyLetters(String s) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func reverseOnlyLetters(s string) string { cs := []rune(s) @@ -165,6 +173,8 @@ func reverseOnlyLetters(s string) string { } ``` +#### TypeScript + ```ts function reverseOnlyLetters(s: string): string { const cs = [...s]; @@ -184,6 +194,8 @@ function reverseOnlyLetters(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn reverse_only_letters(s: String) -> String { diff --git a/solution/0900-0999/0917.Reverse Only Letters/README_EN.md b/solution/0900-0999/0917.Reverse Only Letters/README_EN.md index ef8c579d88b88..fccba289768e7 100644 --- a/solution/0900-0999/0917.Reverse Only Letters/README_EN.md +++ b/solution/0900-0999/0917.Reverse Only Letters/README_EN.md @@ -60,6 +60,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python class Solution: def reverseOnlyLetters(self, s: str) -> str: @@ -76,6 +78,8 @@ class Solution: return "".join(cs) ``` +#### Java + ```java class Solution { public String reverseOnlyLetters(String s) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func reverseOnlyLetters(s string) string { cs := []rune(s) @@ -143,6 +151,8 @@ func reverseOnlyLetters(s string) string { } ``` +#### TypeScript + ```ts function reverseOnlyLetters(s: string): string { const cs = [...s]; @@ -162,6 +172,8 @@ function reverseOnlyLetters(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn reverse_only_letters(s: String) -> String { diff --git a/solution/0900-0999/0918.Maximum Sum Circular Subarray/README.md b/solution/0900-0999/0918.Maximum Sum Circular Subarray/README.md index 53356e7e1e3f2..e771ee0a38a92 100644 --- a/solution/0900-0999/0918.Maximum Sum Circular Subarray/README.md +++ b/solution/0900-0999/0918.Maximum Sum Circular Subarray/README.md @@ -97,6 +97,8 @@ tags: +#### Python3 + ```python class Solution: def maxSubarraySumCircular(self, nums: List[int]) -> int: @@ -109,6 +111,8 @@ class Solution: return s1 if s1 <= 0 else max(s1, sum(nums) - s2) ``` +#### Java + ```java class Solution { public int maxSubarraySumCircular(int[] nums) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func maxSubarraySumCircular(nums []int) int { s1, s2, f1, f2, total := nums[0], nums[0], nums[0], nums[0], nums[0] @@ -159,6 +167,8 @@ func maxSubarraySumCircular(nums []int) int { } ``` +#### TypeScript + ```ts function maxSubarraySumCircular(nums: number[]): number { let pre1 = nums[0], @@ -190,6 +200,8 @@ function maxSubarraySumCircular(nums: number[]): number { +#### Python3 + ```python class Solution: def maxSubarraySumCircular(self, nums: List[int]) -> int: @@ -204,6 +216,8 @@ class Solution: return max(ans, s - smi) ``` +#### Java + ```java class Solution { public int maxSubarraySumCircular(int[] nums) { @@ -222,6 +236,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -241,6 +257,8 @@ public: }; ``` +#### Go + ```go func maxSubarraySumCircular(nums []int) int { const inf = 1 << 30 @@ -257,6 +275,8 @@ func maxSubarraySumCircular(nums []int) int { } ``` +#### TypeScript + ```ts function maxSubarraySumCircular(nums: number[]): number { const inf = 1 << 30; diff --git a/solution/0900-0999/0918.Maximum Sum Circular Subarray/README_EN.md b/solution/0900-0999/0918.Maximum Sum Circular Subarray/README_EN.md index a3074646a9fdb..f836ef872bfbf 100644 --- a/solution/0900-0999/0918.Maximum Sum Circular Subarray/README_EN.md +++ b/solution/0900-0999/0918.Maximum Sum Circular Subarray/README_EN.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def maxSubarraySumCircular(self, nums: List[int]) -> int: @@ -82,6 +84,8 @@ class Solution: return s1 if s1 <= 0 else max(s1, sum(nums) - s2) ``` +#### Java + ```java class Solution { public int maxSubarraySumCircular(int[] nums) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func maxSubarraySumCircular(nums []int) int { s1, s2, f1, f2, total := nums[0], nums[0], nums[0], nums[0], nums[0] @@ -132,6 +140,8 @@ func maxSubarraySumCircular(nums []int) int { } ``` +#### TypeScript + ```ts function maxSubarraySumCircular(nums: number[]): number { let pre1 = nums[0], @@ -163,6 +173,8 @@ function maxSubarraySumCircular(nums: number[]): number { +#### Python3 + ```python class Solution: def maxSubarraySumCircular(self, nums: List[int]) -> int: @@ -177,6 +189,8 @@ class Solution: return max(ans, s - smi) ``` +#### Java + ```java class Solution { public int maxSubarraySumCircular(int[] nums) { @@ -195,6 +209,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -214,6 +230,8 @@ public: }; ``` +#### Go + ```go func maxSubarraySumCircular(nums []int) int { const inf = 1 << 30 @@ -230,6 +248,8 @@ func maxSubarraySumCircular(nums []int) int { } ``` +#### TypeScript + ```ts function maxSubarraySumCircular(nums: number[]): number { const inf = 1 << 30; diff --git a/solution/0900-0999/0919.Complete Binary Tree Inserter/README.md b/solution/0900-0999/0919.Complete Binary Tree Inserter/README.md index da57d82033db3..ed07baa43e068 100644 --- a/solution/0900-0999/0919.Complete Binary Tree Inserter/README.md +++ b/solution/0900-0999/0919.Complete Binary Tree Inserter/README.md @@ -83,6 +83,8 @@ cBTInserter.get_root(); // 返回 [1, 2, 3, 4] +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -124,6 +126,8 @@ class CBTInserter: # param_2 = obj.get_root() ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -185,6 +189,8 @@ class CBTInserter { */ ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -244,6 +250,8 @@ private: */ ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -300,6 +308,8 @@ func (this *CBTInserter) Get_root() *TreeNode { */ ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -359,6 +369,8 @@ class CBTInserter { */ ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0900-0999/0919.Complete Binary Tree Inserter/README_EN.md b/solution/0900-0999/0919.Complete Binary Tree Inserter/README_EN.md index 5042bf3af6cd5..4b3b26b819c8f 100644 --- a/solution/0900-0999/0919.Complete Binary Tree Inserter/README_EN.md +++ b/solution/0900-0999/0919.Complete Binary Tree Inserter/README_EN.md @@ -78,6 +78,8 @@ In terms of time complexity, it takes $O(n)$ time for initialization, and the ti +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -119,6 +121,8 @@ class CBTInserter: # param_2 = obj.get_root() ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -180,6 +184,8 @@ class CBTInserter { */ ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -239,6 +245,8 @@ private: */ ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -295,6 +303,8 @@ func (this *CBTInserter) Get_root() *TreeNode { */ ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -354,6 +364,8 @@ class CBTInserter { */ ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/0900-0999/0920.Number of Music Playlists/README.md b/solution/0900-0999/0920.Number of Music Playlists/README.md index 6fb3545071886..70cdde769ef88 100644 --- a/solution/0900-0999/0920.Number of Music Playlists/README.md +++ b/solution/0900-0999/0920.Number of Music Playlists/README.md @@ -89,6 +89,8 @@ $$ +#### Python3 + ```python class Solution: def numMusicPlaylists(self, n: int, goal: int, k: int) -> int: @@ -104,6 +106,8 @@ class Solution: return f[goal][n] ``` +#### Java + ```java class Solution { public int numMusicPlaylists(int n, int goal, int k) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func numMusicPlaylists(n int, goal int, k int) int { const mod = 1e9 + 7 @@ -167,6 +175,8 @@ func numMusicPlaylists(n int, goal int, k int) int { } ``` +#### TypeScript + ```ts function numMusicPlaylists(n: number, goal: number, k: number): number { const mod = 1e9 + 7; @@ -185,6 +195,8 @@ function numMusicPlaylists(n: number, goal: number, k: number): number { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -227,6 +239,8 @@ impl Solution { +#### Python3 + ```python class Solution: def numMusicPlaylists(self, n: int, goal: int, k: int) -> int: @@ -244,6 +258,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int numMusicPlaylists(int n, int goal, int k) { @@ -266,6 +282,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -289,6 +307,8 @@ public: }; ``` +#### Go + ```go func numMusicPlaylists(n int, goal int, k int) int { const mod = 1e9 + 7 @@ -309,6 +329,8 @@ func numMusicPlaylists(n int, goal int, k int) int { } ``` +#### TypeScript + ```ts function numMusicPlaylists(n: number, goal: number, k: number): number { const mod = 1e9 + 7; diff --git a/solution/0900-0999/0920.Number of Music Playlists/README_EN.md b/solution/0900-0999/0920.Number of Music Playlists/README_EN.md index 400edc0e491b2..d2faa909118bc 100644 --- a/solution/0900-0999/0920.Number of Music Playlists/README_EN.md +++ b/solution/0900-0999/0920.Number of Music Playlists/README_EN.md @@ -87,6 +87,8 @@ Notice that $f[i][j]$ only depends on $f[i - 1][j - 1]$ and $f[i - 1][j]$, so we +#### Python3 + ```python class Solution: def numMusicPlaylists(self, n: int, goal: int, k: int) -> int: @@ -102,6 +104,8 @@ class Solution: return f[goal][n] ``` +#### Java + ```java class Solution { public int numMusicPlaylists(int n, int goal, int k) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func numMusicPlaylists(n int, goal int, k int) int { const mod = 1e9 + 7 @@ -165,6 +173,8 @@ func numMusicPlaylists(n int, goal int, k int) int { } ``` +#### TypeScript + ```ts function numMusicPlaylists(n: number, goal: number, k: number): number { const mod = 1e9 + 7; @@ -183,6 +193,8 @@ function numMusicPlaylists(n: number, goal: number, k: number): number { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -225,6 +237,8 @@ impl Solution { +#### Python3 + ```python class Solution: def numMusicPlaylists(self, n: int, goal: int, k: int) -> int: @@ -242,6 +256,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int numMusicPlaylists(int n, int goal, int k) { @@ -264,6 +280,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -287,6 +305,8 @@ public: }; ``` +#### Go + ```go func numMusicPlaylists(n int, goal int, k int) int { const mod = 1e9 + 7 @@ -307,6 +327,8 @@ func numMusicPlaylists(n int, goal int, k int) int { } ``` +#### TypeScript + ```ts function numMusicPlaylists(n: number, goal: number, k: number): number { const mod = 1e9 + 7; diff --git a/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/README.md b/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/README.md index c187286fa04b8..fa02a2e88007a 100644 --- a/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/README.md +++ b/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def minAddToMakeValid(self, s: str) -> int: @@ -92,6 +94,8 @@ class Solution: return len(stk) ``` +#### Java + ```java class Solution { public int minAddToMakeValid(String s) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func minAddToMakeValid(s string) int { stk := []rune{} @@ -138,6 +146,8 @@ func minAddToMakeValid(s string) int { } ``` +#### TypeScript + ```ts function minAddToMakeValid(s: string): number { const stk: string[] = []; @@ -175,6 +185,8 @@ function minAddToMakeValid(s: string): number { +#### Python3 + ```python class Solution: def minAddToMakeValid(self, s: str) -> int: @@ -190,6 +202,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minAddToMakeValid(String s) { @@ -209,6 +223,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -228,6 +244,8 @@ public: }; ``` +#### Go + ```go func minAddToMakeValid(s string) int { ans, cnt := 0, 0 @@ -245,6 +263,8 @@ func minAddToMakeValid(s string) int { } ``` +#### TypeScript + ```ts function minAddToMakeValid(s: string): number { let [ans, cnt] = [0, 0]; diff --git a/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/README_EN.md b/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/README_EN.md index de1c637264ec4..ed2031eba82c5 100644 --- a/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/README_EN.md +++ b/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python class Solution: def minAddToMakeValid(self, s: str) -> int: @@ -90,6 +92,8 @@ class Solution: return len(stk) ``` +#### Java + ```java class Solution { public int minAddToMakeValid(String s) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func minAddToMakeValid(s string) int { stk := []rune{} @@ -136,6 +144,8 @@ func minAddToMakeValid(s string) int { } ``` +#### TypeScript + ```ts function minAddToMakeValid(s: string): number { const stk: string[] = []; @@ -173,6 +183,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$, where $n$ is +#### Python3 + ```python class Solution: def minAddToMakeValid(self, s: str) -> int: @@ -188,6 +200,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minAddToMakeValid(String s) { @@ -207,6 +221,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -226,6 +242,8 @@ public: }; ``` +#### Go + ```go func minAddToMakeValid(s string) int { ans, cnt := 0, 0 @@ -243,6 +261,8 @@ func minAddToMakeValid(s string) int { } ``` +#### TypeScript + ```ts function minAddToMakeValid(s: string): number { let [ans, cnt] = [0, 0]; diff --git a/solution/0900-0999/0922.Sort Array By Parity II/README.md b/solution/0900-0999/0922.Sort Array By Parity II/README.md index 24dbf964b8ede..02336d6b94a1d 100644 --- a/solution/0900-0999/0922.Sort Array By Parity II/README.md +++ b/solution/0900-0999/0922.Sort Array By Parity II/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def sortArrayByParityII(self, nums: List[int]) -> List[int]: @@ -84,6 +86,8 @@ class Solution: return nums ``` +#### Java + ```java class Solution { public int[] sortArrayByParityII(int[] nums) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func sortArrayByParityII(nums []int) []int { for i, j := 0, 1; i < len(nums); i += 2 { @@ -133,6 +141,8 @@ func sortArrayByParityII(nums []int) []int { } ``` +#### TypeScript + ```ts function sortArrayByParityII(nums: number[]): number[] { for (let i = 0, j = 1; i < nums.length; i += 2) { @@ -147,6 +157,8 @@ function sortArrayByParityII(nums: number[]): number[] { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0900-0999/0922.Sort Array By Parity II/README_EN.md b/solution/0900-0999/0922.Sort Array By Parity II/README_EN.md index 9b82e34bea677..6e26f6ac04a9d 100644 --- a/solution/0900-0999/0922.Sort Array By Parity II/README_EN.md +++ b/solution/0900-0999/0922.Sort Array By Parity II/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def sortArrayByParityII(self, nums: List[int]) -> List[int]: @@ -81,6 +83,8 @@ class Solution: return nums ``` +#### Java + ```java class Solution { public int[] sortArrayByParityII(int[] nums) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func sortArrayByParityII(nums []int) []int { for i, j := 0, 1; i < len(nums); i += 2 { @@ -130,6 +138,8 @@ func sortArrayByParityII(nums []int) []int { } ``` +#### TypeScript + ```ts function sortArrayByParityII(nums: number[]): number[] { for (let i = 0, j = 1; i < nums.length; i += 2) { @@ -144,6 +154,8 @@ function sortArrayByParityII(nums: number[]): number[] { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0900-0999/0923.3Sum With Multiplicity/README.md b/solution/0900-0999/0923.3Sum With Multiplicity/README.md index 740bffd85e162..8304f7ca2d34d 100644 --- a/solution/0900-0999/0923.3Sum With Multiplicity/README.md +++ b/solution/0900-0999/0923.3Sum With Multiplicity/README.md @@ -78,6 +78,8 @@ arr[i] = 1, arr[j] = arr[k] = 2 出现 12 次: +#### Python3 + ```python class Solution: def threeSumMulti(self, arr: List[int], target: int) -> int: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int threeSumMulti(int[] arr, int target) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func threeSumMulti(arr []int, target int) (ans int) { const mod int = 1e9 + 7 @@ -160,6 +168,8 @@ func threeSumMulti(arr []int, target int) (ans int) { } ``` +#### TypeScript + ```ts function threeSumMulti(arr: number[], target: number): number { const mod = 10 ** 9 + 7; diff --git a/solution/0900-0999/0923.3Sum With Multiplicity/README_EN.md b/solution/0900-0999/0923.3Sum With Multiplicity/README_EN.md index e6ed9ada67ba2..ffcf9d8e78630 100644 --- a/solution/0900-0999/0923.3Sum With Multiplicity/README_EN.md +++ b/solution/0900-0999/0923.3Sum With Multiplicity/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n^2)$, where $n$ is the length of the array $arr$. The +#### Python3 + ```python class Solution: def threeSumMulti(self, arr: List[int], target: int) -> int: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int threeSumMulti(int[] arr, int target) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func threeSumMulti(arr []int, target int) (ans int) { const mod int = 1e9 + 7 @@ -166,6 +174,8 @@ func threeSumMulti(arr []int, target int) (ans int) { } ``` +#### TypeScript + ```ts function threeSumMulti(arr: number[], target: number): number { const mod = 10 ** 9 + 7; diff --git a/solution/0900-0999/0924.Minimize Malware Spread/README.md b/solution/0900-0999/0924.Minimize Malware Spread/README.md index d5902d16ec512..7acdd81590a16 100644 --- a/solution/0900-0999/0924.Minimize Malware Spread/README.md +++ b/solution/0900-0999/0924.Minimize Malware Spread/README.md @@ -104,6 +104,8 @@ tags: +#### Python3 + ```python class UnionFind: __slots__ = "p", "size" @@ -153,6 +155,8 @@ class Solution: return min(initial) if ans == n else ans ``` +#### Java + ```java class UnionFind { private final int[] p; @@ -228,6 +232,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -299,6 +305,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p, size []int @@ -371,6 +379,8 @@ func minMalwareSpread(graph [][]int, initial []int) int { } ``` +#### TypeScript + ```ts class UnionFind { p: number[]; diff --git a/solution/0900-0999/0924.Minimize Malware Spread/README_EN.md b/solution/0900-0999/0924.Minimize Malware Spread/README_EN.md index deeade3a7b386..844dd762da516 100644 --- a/solution/0900-0999/0924.Minimize Malware Spread/README_EN.md +++ b/solution/0900-0999/0924.Minimize Malware Spread/README_EN.md @@ -87,6 +87,8 @@ The time complexity is $O(n^2 \times \alpha(n))$, and the space complexity is $O +#### Python3 + ```python class UnionFind: __slots__ = "p", "size" @@ -136,6 +138,8 @@ class Solution: return min(initial) if ans == n else ans ``` +#### Java + ```java class UnionFind { private final int[] p; @@ -211,6 +215,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -282,6 +288,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p, size []int @@ -354,6 +362,8 @@ func minMalwareSpread(graph [][]int, initial []int) int { } ``` +#### TypeScript + ```ts class UnionFind { p: number[]; diff --git a/solution/0900-0999/0925.Long Pressed Name/README.md b/solution/0900-0999/0925.Long Pressed Name/README.md index 00f0490d77ab4..1e9efdfebd0f5 100644 --- a/solution/0900-0999/0925.Long Pressed Name/README.md +++ b/solution/0900-0999/0925.Long Pressed Name/README.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python class Solution: def isLongPressedName(self, name: str, typed: str) -> bool: @@ -80,6 +82,8 @@ class Solution: return i == m and j == n ``` +#### Java + ```java class Solution { public boolean isLongPressedName(String name, String typed) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func isLongPressedName(name string, typed string) bool { m, n := len(name), len(typed) diff --git a/solution/0900-0999/0925.Long Pressed Name/README_EN.md b/solution/0900-0999/0925.Long Pressed Name/README_EN.md index 6fd7f64a78e48..e86ae37a0c57e 100644 --- a/solution/0900-0999/0925.Long Pressed Name/README_EN.md +++ b/solution/0900-0999/0925.Long Pressed Name/README_EN.md @@ -56,6 +56,8 @@ tags: +#### Python3 + ```python class Solution: def isLongPressedName(self, name: str, typed: str) -> bool: @@ -78,6 +80,8 @@ class Solution: return i == m and j == n ``` +#### Java + ```java class Solution { public boolean isLongPressedName(String name, String typed) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func isLongPressedName(name string, typed string) bool { m, n := len(name), len(typed) diff --git a/solution/0900-0999/0926.Flip String to Monotone Increasing/README.md b/solution/0900-0999/0926.Flip String to Monotone Increasing/README.md index 47aa590ca3c54..db153d6f3fdc4 100644 --- a/solution/0900-0999/0926.Flip String to Monotone Increasing/README.md +++ b/solution/0900-0999/0926.Flip String to Monotone Increasing/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def minFlipsMonoIncr(self, s: str) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minFlipsMonoIncr(String s) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func minFlipsMonoIncr(s string) int { tot := strings.Count(s, "0") @@ -138,6 +146,8 @@ func minFlipsMonoIncr(s string) int { } ``` +#### TypeScript + ```ts function minFlipsMonoIncr(s: string): number { let tot = 0; @@ -153,6 +163,8 @@ function minFlipsMonoIncr(s: string): number { } ``` +#### JavaScript + ```js /** * @param {string} s diff --git a/solution/0900-0999/0926.Flip String to Monotone Increasing/README_EN.md b/solution/0900-0999/0926.Flip String to Monotone Increasing/README_EN.md index 466df83abfe1e..b420f2bcf9f7b 100644 --- a/solution/0900-0999/0926.Flip String to Monotone Increasing/README_EN.md +++ b/solution/0900-0999/0926.Flip String to Monotone Increasing/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string $s$. The sp +#### Python3 + ```python class Solution: def minFlipsMonoIncr(self, s: str) -> int: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minFlipsMonoIncr(String s) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func minFlipsMonoIncr(s string) int { tot := strings.Count(s, "0") @@ -136,6 +144,8 @@ func minFlipsMonoIncr(s string) int { } ``` +#### TypeScript + ```ts function minFlipsMonoIncr(s: string): number { let tot = 0; @@ -151,6 +161,8 @@ function minFlipsMonoIncr(s: string): number { } ``` +#### JavaScript + ```js /** * @param {string} s diff --git a/solution/0900-0999/0927.Three Equal Parts/README.md b/solution/0900-0999/0927.Three Equal Parts/README.md index aa38f1b7aceb5..d84f3ca4e8bcf 100644 --- a/solution/0900-0999/0927.Three Equal Parts/README.md +++ b/solution/0900-0999/0927.Three Equal Parts/README.md @@ -102,6 +102,8 @@ tags: +#### Python3 + ```python class Solution: def threeEqualParts(self, arr: List[int]) -> List[int]: @@ -125,6 +127,8 @@ class Solution: return [i - 1, j] if k == n else [-1, -1] ``` +#### Java + ```java class Solution { private int[] arr; @@ -163,6 +167,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go func threeEqualParts(arr []int) []int { find := func(x int) int { @@ -222,6 +230,8 @@ func threeEqualParts(arr []int) []int { } ``` +#### JavaScript + ```js /** * @param {number[]} arr diff --git a/solution/0900-0999/0927.Three Equal Parts/README_EN.md b/solution/0900-0999/0927.Three Equal Parts/README_EN.md index bec0e6201eb5c..13e7f5d659714 100644 --- a/solution/0900-0999/0927.Three Equal Parts/README_EN.md +++ b/solution/0900-0999/0927.Three Equal Parts/README_EN.md @@ -89,6 +89,8 @@ Similar problems: +#### Python3 + ```python class Solution: def threeEqualParts(self, arr: List[int]) -> List[int]: @@ -112,6 +114,8 @@ class Solution: return [i - 1, j] if k == n else [-1, -1] ``` +#### Java + ```java class Solution { private int[] arr; @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go func threeEqualParts(arr []int) []int { find := func(x int) int { @@ -209,6 +217,8 @@ func threeEqualParts(arr []int) []int { } ``` +#### JavaScript + ```js /** * @param {number[]} arr diff --git a/solution/0900-0999/0928.Minimize Malware Spread II/README.md b/solution/0900-0999/0928.Minimize Malware Spread II/README.md index ed4b1616cae23..6f3d51c37e29c 100644 --- a/solution/0900-0999/0928.Minimize Malware Spread II/README.md +++ b/solution/0900-0999/0928.Minimize Malware Spread II/README.md @@ -98,6 +98,8 @@ tags: +#### Python3 + ```python class UnionFind: __slots__ = "p", "size" @@ -154,6 +156,8 @@ class Solution: return ans ``` +#### Java + ```java class UnionFind { private final int[] p; @@ -243,6 +247,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -332,6 +338,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p, size []int @@ -420,6 +428,8 @@ func minMalwareSpread(graph [][]int, initial []int) int { } ``` +#### TypeScript + ```ts class UnionFind { p: number[]; diff --git a/solution/0900-0999/0928.Minimize Malware Spread II/README_EN.md b/solution/0900-0999/0928.Minimize Malware Spread II/README_EN.md index 41fcf9b4c6c35..d395269b7927e 100644 --- a/solution/0900-0999/0928.Minimize Malware Spread II/README_EN.md +++ b/solution/0900-0999/0928.Minimize Malware Spread II/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(n^2 \times \alpha(n))$, and the space complexity is $O +#### Python3 + ```python class UnionFind: __slots__ = "p", "size" @@ -137,6 +139,8 @@ class Solution: return ans ``` +#### Java + ```java class UnionFind { private final int[] p; @@ -226,6 +230,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -315,6 +321,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p, size []int @@ -403,6 +411,8 @@ func minMalwareSpread(graph [][]int, initial []int) int { } ``` +#### TypeScript + ```ts class UnionFind { p: number[]; diff --git a/solution/0900-0999/0929.Unique Email Addresses/README.md b/solution/0900-0999/0929.Unique Email Addresses/README.md index 331e949acc0cf..eb071cac86a03 100644 --- a/solution/0900-0999/0929.Unique Email Addresses/README.md +++ b/solution/0900-0999/0929.Unique Email Addresses/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def numUniqueEmails(self, emails: List[str]) -> int: @@ -94,6 +96,8 @@ class Solution: return len(s) ``` +#### Java + ```java class Solution { public int numUniqueEmails(String[] emails) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func numUniqueEmails(emails []string) int { s := map[string]bool{} @@ -147,6 +155,8 @@ func numUniqueEmails(emails []string) int { } ``` +#### TypeScript + ```ts function numUniqueEmails(emails: string[]): number { return new Set( @@ -157,6 +167,8 @@ function numUniqueEmails(emails: string[]): number { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -183,6 +195,8 @@ impl Solution { } ``` +#### JavaScript + ```js const numUniqueEmails2 = function (emails) { const emailFilter = function (str) { diff --git a/solution/0900-0999/0929.Unique Email Addresses/README_EN.md b/solution/0900-0999/0929.Unique Email Addresses/README_EN.md index db7e2429db050..98767c5199865 100644 --- a/solution/0900-0999/0929.Unique Email Addresses/README_EN.md +++ b/solution/0900-0999/0929.Unique Email Addresses/README_EN.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def numUniqueEmails(self, emails: List[str]) -> int: @@ -92,6 +94,8 @@ class Solution: return len(s) ``` +#### Java + ```java class Solution { public int numUniqueEmails(String[] emails) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func numUniqueEmails(emails []string) int { s := map[string]bool{} @@ -145,6 +153,8 @@ func numUniqueEmails(emails []string) int { } ``` +#### TypeScript + ```ts function numUniqueEmails(emails: string[]): number { return new Set( @@ -155,6 +165,8 @@ function numUniqueEmails(emails: string[]): number { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -181,6 +193,8 @@ impl Solution { } ``` +#### JavaScript + ```js const numUniqueEmails2 = function (emails) { const emailFilter = function (str) { diff --git a/solution/0900-0999/0930.Binary Subarrays With Sum/README.md b/solution/0900-0999/0930.Binary Subarrays With Sum/README.md index 59ab1f25d6ff2..9ac30f40cf1d5 100644 --- a/solution/0900-0999/0930.Binary Subarrays With Sum/README.md +++ b/solution/0900-0999/0930.Binary Subarrays With Sum/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def numSubarraysWithSum(self, nums: List[int], goal: int) -> int: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numSubarraysWithSum(int[] nums, int goal) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func numSubarraysWithSum(nums []int, goal int) (ans int) { cnt := map[int]int{0: 1} @@ -132,6 +140,8 @@ func numSubarraysWithSum(nums []int, goal int) (ans int) { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -164,6 +174,8 @@ var numSubarraysWithSum = function (nums, goal) { +#### Python3 + ```python class Solution: def numSubarraysWithSum(self, nums: List[int], goal: int) -> int: @@ -183,6 +195,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numSubarraysWithSum(int[] nums, int goal) { @@ -205,6 +219,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -224,6 +240,8 @@ public: }; ``` +#### Go + ```go func numSubarraysWithSum(nums []int, goal int) int { i1, i2, s1, s2, j, ans, n := 0, 0, 0, 0, 0, 0, len(nums) @@ -245,6 +263,8 @@ func numSubarraysWithSum(nums []int, goal int) int { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0900-0999/0930.Binary Subarrays With Sum/README_EN.md b/solution/0900-0999/0930.Binary Subarrays With Sum/README_EN.md index 3b6bd2cb6930e..1a83755d57b8e 100644 --- a/solution/0900-0999/0930.Binary Subarrays With Sum/README_EN.md +++ b/solution/0900-0999/0930.Binary Subarrays With Sum/README_EN.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def numSubarraysWithSum(self, nums: List[int], goal: int) -> int: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numSubarraysWithSum(int[] nums, int goal) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func numSubarraysWithSum(nums []int, goal int) (ans int) { cnt := map[int]int{0: 1} @@ -142,6 +150,8 @@ func numSubarraysWithSum(nums []int, goal int) (ans int) { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -174,6 +184,8 @@ var numSubarraysWithSum = function (nums, goal) { +#### Python3 + ```python class Solution: def numSubarraysWithSum(self, nums: List[int], goal: int) -> int: @@ -193,6 +205,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numSubarraysWithSum(int[] nums, int goal) { @@ -215,6 +229,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -234,6 +250,8 @@ public: }; ``` +#### Go + ```go func numSubarraysWithSum(nums []int, goal int) int { i1, i2, s1, s2, j, ans, n := 0, 0, 0, 0, 0, 0, len(nums) @@ -255,6 +273,8 @@ func numSubarraysWithSum(nums []int, goal int) int { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0900-0999/0931.Minimum Falling Path Sum/README.md b/solution/0900-0999/0931.Minimum Falling Path Sum/README.md index 5a51a1f8d209f..e014f37cb1c34 100644 --- a/solution/0900-0999/0931.Minimum Falling Path Sum/README.md +++ b/solution/0900-0999/0931.Minimum Falling Path Sum/README.md @@ -76,6 +76,8 @@ $$ +#### Python3 + ```python class Solution: def minFallingPathSum(self, matrix: List[List[int]]) -> int: @@ -90,6 +92,8 @@ class Solution: return min(f) ``` +#### Java + ```java class Solution { public int minFallingPathSum(int[][] matrix) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func minFallingPathSum(matrix [][]int) int { n := len(matrix) @@ -164,6 +172,8 @@ func minFallingPathSum(matrix [][]int) int { } ``` +#### TypeScript + ```ts function minFallingPathSum(matrix: number[][]): number { const n = matrix.length; diff --git a/solution/0900-0999/0931.Minimum Falling Path Sum/README_EN.md b/solution/0900-0999/0931.Minimum Falling Path Sum/README_EN.md index 19dc720fa4f4c..69d3f9ab29292 100644 --- a/solution/0900-0999/0931.Minimum Falling Path Sum/README_EN.md +++ b/solution/0900-0999/0931.Minimum Falling Path Sum/README_EN.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python class Solution: def minFallingPathSum(self, matrix: List[List[int]]) -> int: @@ -72,6 +74,8 @@ class Solution: return min(f) ``` +#### Java + ```java class Solution { public int minFallingPathSum(int[][] matrix) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func minFallingPathSum(matrix [][]int) int { n := len(matrix) @@ -146,6 +154,8 @@ func minFallingPathSum(matrix [][]int) int { } ``` +#### TypeScript + ```ts function minFallingPathSum(matrix: number[][]): number { const n = matrix.length; diff --git a/solution/0900-0999/0932.Beautiful Array/README.md b/solution/0900-0999/0932.Beautiful Array/README.md index 5cba6661f7ccd..70a0b191cdaa7 100644 --- a/solution/0900-0999/0932.Beautiful Array/README.md +++ b/solution/0900-0999/0932.Beautiful Array/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def beautifulArray(self, n: int) -> List[int]: @@ -87,6 +89,8 @@ class Solution: return left + right ``` +#### Java + ```java class Solution { public int[] beautifulArray(int n) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func beautifulArray(n int) []int { if n == 1 { diff --git a/solution/0900-0999/0932.Beautiful Array/README_EN.md b/solution/0900-0999/0932.Beautiful Array/README_EN.md index cee3feb3ac2e4..f2e677751a84a 100644 --- a/solution/0900-0999/0932.Beautiful Array/README_EN.md +++ b/solution/0900-0999/0932.Beautiful Array/README_EN.md @@ -52,6 +52,8 @@ tags: +#### Python3 + ```python class Solution: def beautifulArray(self, n: int) -> List[int]: @@ -64,6 +66,8 @@ class Solution: return left + right ``` +#### Java + ```java class Solution { public int[] beautifulArray(int n) { @@ -85,6 +89,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,6 +107,8 @@ public: }; ``` +#### Go + ```go func beautifulArray(n int) []int { if n == 1 { diff --git a/solution/0900-0999/0933.Number of Recent Calls/README.md b/solution/0900-0999/0933.Number of Recent Calls/README.md index 97a3878df28ba..0f770ef85a90f 100644 --- a/solution/0900-0999/0933.Number of Recent Calls/README.md +++ b/solution/0900-0999/0933.Number of Recent Calls/README.md @@ -74,6 +74,8 @@ recentCounter.ping(3002); // requests = [1, 100, 3001< +#### Python3 + ```python class RecentCounter: def __init__(self): @@ -91,6 +93,8 @@ class RecentCounter: # param_1 = obj.ping(t) ``` +#### Java + ```java class RecentCounter { private int[] s = new int[10010]; @@ -125,6 +129,8 @@ class RecentCounter { */ ``` +#### C++ + ```cpp class RecentCounter { public: @@ -147,6 +153,8 @@ public: */ ``` +#### Go + ```go type RecentCounter struct { q []int @@ -171,6 +179,8 @@ func (this *RecentCounter) Ping(t int) int { */ ``` +#### TypeScript + ```ts class RecentCounter { private queue: number[]; @@ -195,6 +205,8 @@ class RecentCounter { */ ``` +#### Rust + ```rust use std::collections::VecDeque; struct RecentCounter { @@ -229,6 +241,8 @@ impl RecentCounter { */ ``` +#### JavaScript + ```js var RecentCounter = function () { this.q = []; @@ -253,6 +267,8 @@ RecentCounter.prototype.ping = function (t) { */ ``` +#### C# + ```cs public class RecentCounter { private Queue q = new Queue(); @@ -290,6 +306,8 @@ public class RecentCounter { +#### Python3 + ```python class RecentCounter: def __init__(self): @@ -305,6 +323,8 @@ class RecentCounter: # param_1 = obj.ping(t) ``` +#### C++ + ```cpp class RecentCounter { public: @@ -326,6 +346,8 @@ public: */ ``` +#### Go + ```go type RecentCounter struct { s []int diff --git a/solution/0900-0999/0933.Number of Recent Calls/README_EN.md b/solution/0900-0999/0933.Number of Recent Calls/README_EN.md index 56628a3d1cb6c..a379382a28c62 100644 --- a/solution/0900-0999/0933.Number of Recent Calls/README_EN.md +++ b/solution/0900-0999/0933.Number of Recent Calls/README_EN.md @@ -66,6 +66,8 @@ recentCounter.ping(3002); // requests = [1, 100, 3001, 3002 +#### Python3 + ```python class RecentCounter: def __init__(self): @@ -83,6 +85,8 @@ class RecentCounter: # param_1 = obj.ping(t) ``` +#### Java + ```java class RecentCounter { private int[] s = new int[10010]; @@ -117,6 +121,8 @@ class RecentCounter { */ ``` +#### C++ + ```cpp class RecentCounter { public: @@ -139,6 +145,8 @@ public: */ ``` +#### Go + ```go type RecentCounter struct { q []int @@ -163,6 +171,8 @@ func (this *RecentCounter) Ping(t int) int { */ ``` +#### TypeScript + ```ts class RecentCounter { private queue: number[]; @@ -187,6 +197,8 @@ class RecentCounter { */ ``` +#### Rust + ```rust use std::collections::VecDeque; struct RecentCounter { @@ -221,6 +233,8 @@ impl RecentCounter { */ ``` +#### JavaScript + ```js var RecentCounter = function () { this.q = []; @@ -245,6 +259,8 @@ RecentCounter.prototype.ping = function (t) { */ ``` +#### C# + ```cs public class RecentCounter { private Queue q = new Queue(); @@ -280,6 +296,8 @@ public class RecentCounter { +#### Python3 + ```python class RecentCounter: def __init__(self): @@ -295,6 +313,8 @@ class RecentCounter: # param_1 = obj.ping(t) ``` +#### C++ + ```cpp class RecentCounter { public: @@ -316,6 +336,8 @@ public: */ ``` +#### Go + ```go type RecentCounter struct { s []int diff --git a/solution/0900-0999/0934.Shortest Bridge/README.md b/solution/0900-0999/0934.Shortest Bridge/README.md index c215530dde0d6..fd193a587b7b8 100644 --- a/solution/0900-0999/0934.Shortest Bridge/README.md +++ b/solution/0900-0999/0934.Shortest Bridge/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def shortestBridge(self, grid: List[List[int]]) -> int: @@ -114,6 +116,8 @@ class Solution: ans += 1 ``` +#### Java + ```java class Solution { private int[] dirs = {-1, 0, 1, 0, -1}; @@ -167,6 +171,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -216,6 +222,8 @@ public: }; ``` +#### Go + ```go func shortestBridge(grid [][]int) (ans int) { n := len(grid) diff --git a/solution/0900-0999/0934.Shortest Bridge/README_EN.md b/solution/0900-0999/0934.Shortest Bridge/README_EN.md index 4020fe34dd657..ffba8830cfa7d 100644 --- a/solution/0900-0999/0934.Shortest Bridge/README_EN.md +++ b/solution/0900-0999/0934.Shortest Bridge/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def shortestBridge(self, grid: List[List[int]]) -> int: @@ -100,6 +102,8 @@ class Solution: ans += 1 ``` +#### Java + ```java class Solution { private int[] dirs = {-1, 0, 1, 0, -1}; @@ -153,6 +157,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -202,6 +208,8 @@ public: }; ``` +#### Go + ```go func shortestBridge(grid [][]int) (ans int) { n := len(grid) diff --git a/solution/0900-0999/0935.Knight Dialer/README.md b/solution/0900-0999/0935.Knight Dialer/README.md index 6792b25118188..25f26a97b5fa6 100644 --- a/solution/0900-0999/0935.Knight Dialer/README.md +++ b/solution/0900-0999/0935.Knight Dialer/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def knightDialer(self, n: int) -> int: @@ -100,6 +102,8 @@ class Solution: return sum(t) % (10**9 + 7) ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func knightDialer(n int) int { if n == 1 { @@ -195,6 +203,8 @@ func knightDialer(n int) int { } ``` +#### TypeScript + ```ts function knightDialer(n: number): number { const MOD: number = 1e9 + 7; @@ -232,6 +242,8 @@ function knightDialer(n: number): number { } ``` +#### C# + ```cs public class Solution { public int KnightDialer(int n) { diff --git a/solution/0900-0999/0935.Knight Dialer/README_EN.md b/solution/0900-0999/0935.Knight Dialer/README_EN.md index 983e6acce13cf..68d6862f666a8 100644 --- a/solution/0900-0999/0935.Knight Dialer/README_EN.md +++ b/solution/0900-0999/0935.Knight Dialer/README_EN.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def knightDialer(self, n: int) -> int: @@ -91,6 +93,8 @@ class Solution: return sum(t) % (10**9 + 7) ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func knightDialer(n int) int { if n == 1 { @@ -186,6 +194,8 @@ func knightDialer(n int) int { } ``` +#### TypeScript + ```ts function knightDialer(n: number): number { const MOD: number = 1e9 + 7; @@ -223,6 +233,8 @@ function knightDialer(n: number): number { } ``` +#### C# + ```cs public class Solution { public int KnightDialer(int n) { diff --git a/solution/0900-0999/0936.Stamping The Sequence/README.md b/solution/0900-0999/0936.Stamping The Sequence/README.md index 023e96aa27394..4318785adfac9 100644 --- a/solution/0900-0999/0936.Stamping The Sequence/README.md +++ b/solution/0900-0999/0936.Stamping The Sequence/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def movesToStamp(self, stamp: str, target: str) -> List[int]: @@ -117,6 +119,8 @@ class Solution: return ans[::-1] if all(vis) else [] ``` +#### Java + ```java class Solution { public int[] movesToStamp(String stamp, String target) { @@ -164,6 +168,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -211,6 +217,8 @@ public: }; ``` +#### Go + ```go func movesToStamp(stamp string, target string) (ans []int) { m, n := len(stamp), len(target) @@ -261,6 +269,8 @@ func movesToStamp(stamp string, target string) (ans []int) { } ``` +#### TypeScript + ```ts function movesToStamp(stamp: string, target: string): number[] { const m: number = stamp.length; @@ -304,6 +314,8 @@ function movesToStamp(stamp: string, target: string): number[] { } ``` +#### Rust + ```rust use std::collections::VecDeque; diff --git a/solution/0900-0999/0936.Stamping The Sequence/README_EN.md b/solution/0900-0999/0936.Stamping The Sequence/README_EN.md index 9ac7afd22698d..dde2ac7343790 100644 --- a/solution/0900-0999/0936.Stamping The Sequence/README_EN.md +++ b/solution/0900-0999/0936.Stamping The Sequence/README_EN.md @@ -100,6 +100,8 @@ The time complexity is $O(n \times (n - m + 1))$, and the space complexity is $O +#### Python3 + ```python class Solution: def movesToStamp(self, stamp: str, target: str) -> List[int]: @@ -130,6 +132,8 @@ class Solution: return ans[::-1] if all(vis) else [] ``` +#### Java + ```java class Solution { public int[] movesToStamp(String stamp, String target) { @@ -177,6 +181,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -224,6 +230,8 @@ public: }; ``` +#### Go + ```go func movesToStamp(stamp string, target string) (ans []int) { m, n := len(stamp), len(target) @@ -274,6 +282,8 @@ func movesToStamp(stamp string, target string) (ans []int) { } ``` +#### TypeScript + ```ts function movesToStamp(stamp: string, target: string): number[] { const m: number = stamp.length; @@ -317,6 +327,8 @@ function movesToStamp(stamp: string, target: string): number[] { } ``` +#### Rust + ```rust use std::collections::VecDeque; diff --git a/solution/0900-0999/0937.Reorder Data in Log Files/README.md b/solution/0900-0999/0937.Reorder Data in Log Files/README.md index 722950945c806..e583c902fb0f0 100644 --- a/solution/0900-0999/0937.Reorder Data in Log Files/README.md +++ b/solution/0900-0999/0937.Reorder Data in Log Files/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def reorderLogFiles(self, logs: List[str]) -> List[str]: @@ -87,6 +89,8 @@ class Solution: return sorted(logs, key=cmp) ``` +#### Java + ```java class Solution { public String[] reorderLogFiles(String[] logs) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### TypeScript + ```ts function reorderLogFiles(logs: string[]): string[] { const isDigit = (c: string) => c >= '0' && c <= '9'; @@ -136,6 +142,8 @@ function reorderLogFiles(logs: string[]): string[] { } ``` +#### Rust + ```rust impl Solution { pub fn reorder_log_files(mut logs: Vec) -> Vec { diff --git a/solution/0900-0999/0937.Reorder Data in Log Files/README_EN.md b/solution/0900-0999/0937.Reorder Data in Log Files/README_EN.md index 9cb595d09123e..a9ffbad5b75bf 100644 --- a/solution/0900-0999/0937.Reorder Data in Log Files/README_EN.md +++ b/solution/0900-0999/0937.Reorder Data in Log Files/README_EN.md @@ -75,6 +75,8 @@ The digit-logs have a relative order of "dig1 8 1 5 1", "dig2 3 6 +#### Python3 + ```python class Solution: def reorderLogFiles(self, logs: List[str]) -> List[str]: @@ -85,6 +87,8 @@ class Solution: return sorted(logs, key=cmp) ``` +#### Java + ```java class Solution { public String[] reorderLogFiles(String[] logs) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### TypeScript + ```ts function reorderLogFiles(logs: string[]): string[] { const isDigit = (c: string) => c >= '0' && c <= '9'; @@ -134,6 +140,8 @@ function reorderLogFiles(logs: string[]): string[] { } ``` +#### Rust + ```rust impl Solution { pub fn reorder_log_files(mut logs: Vec) -> Vec { diff --git a/solution/0900-0999/0938.Range Sum of BST/README.md b/solution/0900-0999/0938.Range Sum of BST/README.md index 646ccfe54b674..d9d52f079a204 100644 --- a/solution/0900-0999/0938.Range Sum of BST/README.md +++ b/solution/0900-0999/0938.Range Sum of BST/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -93,6 +95,8 @@ class Solution: return dfs(root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -196,6 +204,8 @@ func rangeSumBST(root *TreeNode, low int, high int) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -230,6 +240,8 @@ function rangeSumBST(root: TreeNode | null, low: number, high: number): number { } ``` +#### C# + ```cs /** * Definition for a binary tree node. diff --git a/solution/0900-0999/0938.Range Sum of BST/README_EN.md b/solution/0900-0999/0938.Range Sum of BST/README_EN.md index bb9845bece177..97c4645fbb7c0 100644 --- a/solution/0900-0999/0938.Range Sum of BST/README_EN.md +++ b/solution/0900-0999/0938.Range Sum of BST/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -93,6 +95,8 @@ class Solution: return dfs(root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -196,6 +204,8 @@ func rangeSumBST(root *TreeNode, low int, high int) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -230,6 +240,8 @@ function rangeSumBST(root: TreeNode | null, low: number, high: number): number { } ``` +#### C# + ```cs /** * Definition for a binary tree node. diff --git a/solution/0900-0999/0939.Minimum Area Rectangle/README.md b/solution/0900-0999/0939.Minimum Area Rectangle/README.md index c88977ba79397..7a98ebe927790 100644 --- a/solution/0900-0999/0939.Minimum Area Rectangle/README.md +++ b/solution/0900-0999/0939.Minimum Area Rectangle/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def minAreaRect(self, points: List[List[int]]) -> int: @@ -87,6 +89,8 @@ class Solution: return 0 if ans == inf else ans ``` +#### Java + ```java class Solution { public int minAreaRect(int[][] points) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func minAreaRect(points [][]int) int { d := map[int][]int{} diff --git a/solution/0900-0999/0939.Minimum Area Rectangle/README_EN.md b/solution/0900-0999/0939.Minimum Area Rectangle/README_EN.md index a8cc048ad6737..855417bfd02f0 100644 --- a/solution/0900-0999/0939.Minimum Area Rectangle/README_EN.md +++ b/solution/0900-0999/0939.Minimum Area Rectangle/README_EN.md @@ -59,6 +59,8 @@ tags: +#### Python3 + ```python class Solution: def minAreaRect(self, points: List[List[int]]) -> int: @@ -79,6 +81,8 @@ class Solution: return 0 if ans == inf else ans ``` +#### Java + ```java class Solution { public int minAreaRect(int[][] points) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func minAreaRect(points [][]int) int { d := map[int][]int{} diff --git a/solution/0900-0999/0940.Distinct Subsequences II/README.md b/solution/0900-0999/0940.Distinct Subsequences II/README.md index 981e86c293132..0299e49a63b07 100644 --- a/solution/0900-0999/0940.Distinct Subsequences II/README.md +++ b/solution/0900-0999/0940.Distinct Subsequences II/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def distinctSubseqII(self, s: str) -> int: @@ -96,6 +98,8 @@ class Solution: return sum(dp[-1]) % mod ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func distinctSubseqII(s string) int { const mod int = 1e9 + 7 @@ -155,6 +163,8 @@ func distinctSubseqII(s string) int { } ``` +#### TypeScript + ```ts function distinctSubseqII(s: string): number { const mod = 1e9 + 7; @@ -166,6 +176,8 @@ function distinctSubseqII(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn distinct_subseq_ii(s: String) -> i32 { @@ -191,6 +203,8 @@ impl Solution { } ``` +#### C + ```c int distinctSubseqII(char* s) { int mod = 1e9 + 7; @@ -229,6 +243,8 @@ int distinctSubseqII(char* s) { +#### Python3 + ```python class Solution: def distinctSubseqII(self, s: str) -> int: @@ -240,6 +256,8 @@ class Solution: return sum(dp) % mod ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -258,6 +276,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -277,6 +297,8 @@ public: }; ``` +#### Go + ```go func distinctSubseqII(s string) int { const mod int = 1e9 + 7 @@ -302,6 +324,8 @@ func distinctSubseqII(s string) int { +#### Python3 + ```python class Solution: def distinctSubseqII(self, s: str) -> int: diff --git a/solution/0900-0999/0940.Distinct Subsequences II/README_EN.md b/solution/0900-0999/0940.Distinct Subsequences II/README_EN.md index 629d9704afce6..de839fe25ed8e 100644 --- a/solution/0900-0999/0940.Distinct Subsequences II/README_EN.md +++ b/solution/0900-0999/0940.Distinct Subsequences II/README_EN.md @@ -62,6 +62,8 @@ A subsequence of a string is a new string that is formed from t +#### Python3 + ```python class Solution: def distinctSubseqII(self, s: str) -> int: @@ -78,6 +80,8 @@ class Solution: return sum(dp[-1]) % mod ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func distinctSubseqII(s string) int { const mod int = 1e9 + 7 @@ -137,6 +145,8 @@ func distinctSubseqII(s string) int { } ``` +#### TypeScript + ```ts function distinctSubseqII(s: string): number { const mod = 1e9 + 7; @@ -148,6 +158,8 @@ function distinctSubseqII(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn distinct_subseq_ii(s: String) -> i32 { @@ -173,6 +185,8 @@ impl Solution { } ``` +#### C + ```c int distinctSubseqII(char* s) { int mod = 1e9 + 7; @@ -203,6 +217,8 @@ int distinctSubseqII(char* s) { +#### Python3 + ```python class Solution: def distinctSubseqII(self, s: str) -> int: @@ -214,6 +230,8 @@ class Solution: return sum(dp) % mod ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -232,6 +250,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -251,6 +271,8 @@ public: }; ``` +#### Go + ```go func distinctSubseqII(s string) int { const mod int = 1e9 + 7 @@ -276,6 +298,8 @@ func distinctSubseqII(s string) int { +#### Python3 + ```python class Solution: def distinctSubseqII(self, s: str) -> int: diff --git a/solution/0900-0999/0941.Valid Mountain Array/README.md b/solution/0900-0999/0941.Valid Mountain Array/README.md index 2d21122e125ee..44548511961db 100644 --- a/solution/0900-0999/0941.Valid Mountain Array/README.md +++ b/solution/0900-0999/0941.Valid Mountain Array/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def validMountainArray(self, arr: List[int]) -> bool: @@ -95,6 +97,8 @@ class Solution: return i == j ``` +#### Java + ```java class Solution { public boolean validMountainArray(int[] arr) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func validMountainArray(arr []int) bool { n := len(arr) @@ -151,6 +159,8 @@ func validMountainArray(arr []int) bool { } ``` +#### TypeScript + ```ts function validMountainArray(arr: number[]): boolean { const n = arr.length; diff --git a/solution/0900-0999/0941.Valid Mountain Array/README_EN.md b/solution/0900-0999/0941.Valid Mountain Array/README_EN.md index 35d5ae53d57ee..7519ad2587137 100644 --- a/solution/0900-0999/0941.Valid Mountain Array/README_EN.md +++ b/solution/0900-0999/0941.Valid Mountain Array/README_EN.md @@ -65,6 +65,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def validMountainArray(self, arr: List[int]) -> bool: @@ -79,6 +81,8 @@ class Solution: return i == j ``` +#### Java + ```java class Solution { public boolean validMountainArray(int[] arr) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func validMountainArray(arr []int) bool { n := len(arr) @@ -135,6 +143,8 @@ func validMountainArray(arr []int) bool { } ``` +#### TypeScript + ```ts function validMountainArray(arr: number[]): boolean { const n = arr.length; diff --git a/solution/0900-0999/0942.DI String Match/README.md b/solution/0900-0999/0942.DI String Match/README.md index 158c5e1415974..a526dde247c1a 100644 --- a/solution/0900-0999/0942.DI String Match/README.md +++ b/solution/0900-0999/0942.DI String Match/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def diStringMatch(self, s: str) -> List[int]: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] diStringMatch(String s) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func diStringMatch(s string) []int { n := len(s) @@ -144,6 +152,8 @@ func diStringMatch(s string) []int { } ``` +#### TypeScript + ```ts function diStringMatch(s: string): number[] { const n = s.length; @@ -162,6 +172,8 @@ function diStringMatch(s: string): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn di_string_match(s: String) -> Vec { diff --git a/solution/0900-0999/0942.DI String Match/README_EN.md b/solution/0900-0999/0942.DI String Match/README_EN.md index ef5619279ef39..d90cf2fabc1c2 100644 --- a/solution/0900-0999/0942.DI String Match/README_EN.md +++ b/solution/0900-0999/0942.DI String Match/README_EN.md @@ -57,6 +57,8 @@ tags: +#### Python3 + ```python class Solution: def diStringMatch(self, s: str) -> List[int]: @@ -74,6 +76,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] diStringMatch(String s) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func diStringMatch(s string) []int { n := len(s) @@ -132,6 +140,8 @@ func diStringMatch(s string) []int { } ``` +#### TypeScript + ```ts function diStringMatch(s: string): number[] { const n = s.length; @@ -150,6 +160,8 @@ function diStringMatch(s: string): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn di_string_match(s: String) -> Vec { diff --git a/solution/0900-0999/0943.Find the Shortest Superstring/README.md b/solution/0900-0999/0943.Find the Shortest Superstring/README.md index e80887d218d6e..48de139bec7a8 100644 --- a/solution/0900-0999/0943.Find the Shortest Superstring/README.md +++ b/solution/0900-0999/0943.Find the Shortest Superstring/README.md @@ -74,6 +74,8 @@ $$ +#### Python3 + ```python class Solution: def shortestSuperstring(self, words: List[str]) -> str: @@ -114,6 +116,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String shortestSuperstring(String[] words) { @@ -183,6 +187,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -251,6 +257,8 @@ public: }; ``` +#### Go + ```go func shortestSuperstring(words []string) string { n := len(words) diff --git a/solution/0900-0999/0943.Find the Shortest Superstring/README_EN.md b/solution/0900-0999/0943.Find the Shortest Superstring/README_EN.md index e0e6f8668f08e..d0aee7b67ec15 100644 --- a/solution/0900-0999/0943.Find the Shortest Superstring/README_EN.md +++ b/solution/0900-0999/0943.Find the Shortest Superstring/README_EN.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def shortestSuperstring(self, words: List[str]) -> str: @@ -100,6 +102,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String shortestSuperstring(String[] words) { @@ -169,6 +173,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -237,6 +243,8 @@ public: }; ``` +#### Go + ```go func shortestSuperstring(words []string) string { n := len(words) diff --git a/solution/0900-0999/0944.Delete Columns to Make Sorted/README.md b/solution/0900-0999/0944.Delete Columns to Make Sorted/README.md index 10868b72ae82e..505b8e25c52da 100644 --- a/solution/0900-0999/0944.Delete Columns to Make Sorted/README.md +++ b/solution/0900-0999/0944.Delete Columns to Make Sorted/README.md @@ -88,6 +88,8 @@ cae +#### Python3 + ```python class Solution: def minDeletionSize(self, strs: List[str]) -> int: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minDeletionSize(String[] strs) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func minDeletionSize(strs []string) int { m, n := len(strs[0]), len(strs) @@ -155,6 +163,8 @@ func minDeletionSize(strs []string) int { } ``` +#### Rust + ```rust impl Solution { pub fn min_deletion_size(strs: Vec) -> i32 { diff --git a/solution/0900-0999/0944.Delete Columns to Make Sorted/README_EN.md b/solution/0900-0999/0944.Delete Columns to Make Sorted/README_EN.md index 7f350bf8fa02f..3ac620db5d869 100644 --- a/solution/0900-0999/0944.Delete Columns to Make Sorted/README_EN.md +++ b/solution/0900-0999/0944.Delete Columns to Make Sorted/README_EN.md @@ -91,6 +91,8 @@ All 3 columns are not sorted, so you will delete all 3. +#### Python3 + ```python class Solution: def minDeletionSize(self, strs: List[str]) -> int: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minDeletionSize(String[] strs) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func minDeletionSize(strs []string) int { m, n := len(strs[0]), len(strs) @@ -158,6 +166,8 @@ func minDeletionSize(strs []string) int { } ``` +#### Rust + ```rust impl Solution { pub fn min_deletion_size(strs: Vec) -> i32 { diff --git a/solution/0900-0999/0945.Minimum Increment to Make Array Unique/README.md b/solution/0900-0999/0945.Minimum Increment to Make Array Unique/README.md index 94efc9cc76681..aa793736e3d5b 100644 --- a/solution/0900-0999/0945.Minimum Increment to Make Array Unique/README.md +++ b/solution/0900-0999/0945.Minimum Increment to Make Array Unique/README.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def minIncrementForUnique(self, nums: List[int]) -> int: @@ -76,6 +78,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minIncrementForUnique(int[] nums) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func minIncrementForUnique(nums []int) int { sort.Ints(nums) diff --git a/solution/0900-0999/0945.Minimum Increment to Make Array Unique/README_EN.md b/solution/0900-0999/0945.Minimum Increment to Make Array Unique/README_EN.md index cac907c23db13..12ec668fa0a4c 100644 --- a/solution/0900-0999/0945.Minimum Increment to Make Array Unique/README_EN.md +++ b/solution/0900-0999/0945.Minimum Increment to Make Array Unique/README_EN.md @@ -61,6 +61,8 @@ It can be shown with 5 or less moves that it is impossible for the array to have +#### Python3 + ```python class Solution: def minIncrementForUnique(self, nums: List[int]) -> int: @@ -74,6 +76,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minIncrementForUnique(int[] nums) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func minIncrementForUnique(nums []int) int { sort.Ints(nums) diff --git a/solution/0900-0999/0946.Validate Stack Sequences/README.md b/solution/0900-0999/0946.Validate Stack Sequences/README.md index ef55876abbb22..c43f3658057a7 100644 --- a/solution/0900-0999/0946.Validate Stack Sequences/README.md +++ b/solution/0900-0999/0946.Validate Stack Sequences/README.md @@ -68,6 +68,8 @@ push(5), pop() -> 5, pop() -> 3, pop() -> 2, pop() -> 1 +#### Python3 + ```python class Solution: def validateStackSequences(self, pushed: List[int], popped: List[int]) -> bool: @@ -80,6 +82,8 @@ class Solution: return j == len(pushed) ``` +#### Java + ```java class Solution { public boolean validateStackSequences(int[] pushed, int[] popped) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func validateStackSequences(pushed []int, popped []int) bool { stk := []int{} @@ -130,6 +138,8 @@ func validateStackSequences(pushed []int, popped []int) bool { } ``` +#### TypeScript + ```ts function validateStackSequences(pushed: number[], popped: number[]): boolean { const stk = []; @@ -145,6 +155,8 @@ function validateStackSequences(pushed: number[], popped: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn validate_stack_sequences(pushed: Vec, popped: Vec) -> bool { @@ -162,6 +174,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} pushed @@ -182,6 +196,8 @@ var validateStackSequences = function (pushed, popped) { }; ``` +#### C# + ```cs public class Solution { public bool ValidateStackSequences(int[] pushed, int[] popped) { diff --git a/solution/0900-0999/0946.Validate Stack Sequences/README_EN.md b/solution/0900-0999/0946.Validate Stack Sequences/README_EN.md index ba52fa8f059cb..da4100975da3b 100644 --- a/solution/0900-0999/0946.Validate Stack Sequences/README_EN.md +++ b/solution/0900-0999/0946.Validate Stack Sequences/README_EN.md @@ -62,6 +62,8 @@ pop() -> 5, pop() -> 3, pop() -> 2, pop() -> 1 +#### Python3 + ```python class Solution: def validateStackSequences(self, pushed: List[int], popped: List[int]) -> bool: @@ -74,6 +76,8 @@ class Solution: return j == len(pushed) ``` +#### Java + ```java class Solution { public boolean validateStackSequences(int[] pushed, int[] popped) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func validateStackSequences(pushed []int, popped []int) bool { stk := []int{} @@ -124,6 +132,8 @@ func validateStackSequences(pushed []int, popped []int) bool { } ``` +#### TypeScript + ```ts function validateStackSequences(pushed: number[], popped: number[]): boolean { const stk = []; @@ -139,6 +149,8 @@ function validateStackSequences(pushed: number[], popped: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn validate_stack_sequences(pushed: Vec, popped: Vec) -> bool { @@ -156,6 +168,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} pushed @@ -176,6 +190,8 @@ var validateStackSequences = function (pushed, popped) { }; ``` +#### C# + ```cs public class Solution { public bool ValidateStackSequences(int[] pushed, int[] popped) { diff --git a/solution/0900-0999/0947.Most Stones Removed with Same Row or Column/README.md b/solution/0900-0999/0947.Most Stones Removed with Same Row or Column/README.md index d17f3edf97059..b85e6131df0c1 100644 --- a/solution/0900-0999/0947.Most Stones Removed with Same Row or Column/README.md +++ b/solution/0900-0999/0947.Most Stones Removed with Same Row or Column/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def removeStones(self, stones: List[List[int]]) -> int: @@ -95,6 +97,8 @@ class Solution: return len(stones) - len(s) ``` +#### Java + ```java class Solution { private int[] p; @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func removeStones(stones [][]int) int { n := 10010 diff --git a/solution/0900-0999/0947.Most Stones Removed with Same Row or Column/README_EN.md b/solution/0900-0999/0947.Most Stones Removed with Same Row or Column/README_EN.md index 7e73de34ef9cd..da5f8f7d95fa5 100644 --- a/solution/0900-0999/0947.Most Stones Removed with Same Row or Column/README_EN.md +++ b/solution/0900-0999/0947.Most Stones Removed with Same Row or Column/README_EN.md @@ -79,6 +79,8 @@ Stones [0,0] and [1,1] cannot be removed since they do not share a row/column wi +#### Python3 + ```python class Solution: def removeStones(self, stones: List[List[int]]) -> int: @@ -96,6 +98,8 @@ class Solution: return len(stones) - len(s) ``` +#### Java + ```java class Solution { private int[] p; @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func removeStones(stones [][]int) int { n := 10010 diff --git a/solution/0900-0999/0948.Bag of Tokens/README.md b/solution/0900-0999/0948.Bag of Tokens/README.md index 10b4f8fafa22a..d3eb51ee73f01 100644 --- a/solution/0900-0999/0948.Bag of Tokens/README.md +++ b/solution/0900-0999/0948.Bag of Tokens/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def bagOfTokensScore(self, tokens: List[int], power: int) -> int: @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int bagOfTokensScore(int[] tokens, int power) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func bagOfTokensScore(tokens []int, power int) int { sort.Ints(tokens) diff --git a/solution/0900-0999/0948.Bag of Tokens/README_EN.md b/solution/0900-0999/0948.Bag of Tokens/README_EN.md index fadf11bc30b4e..24ddd7e9ea43a 100644 --- a/solution/0900-0999/0948.Bag of Tokens/README_EN.md +++ b/solution/0900-0999/0948.Bag of Tokens/README_EN.md @@ -135,6 +135,8 @@ tags: +#### Python3 + ```python class Solution: def bagOfTokensScore(self, tokens: List[int], power: int) -> int: @@ -154,6 +156,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int bagOfTokensScore(int[] tokens, int power) { @@ -177,6 +181,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -200,6 +206,8 @@ public: }; ``` +#### Go + ```go func bagOfTokensScore(tokens []int, power int) int { sort.Ints(tokens) diff --git a/solution/0900-0999/0949.Largest Time for Given Digits/README.md b/solution/0900-0999/0949.Largest Time for Given Digits/README.md index 98ce47557f0c3..a6c6088450230 100644 --- a/solution/0900-0999/0949.Largest Time for Given Digits/README.md +++ b/solution/0900-0999/0949.Largest Time for Given Digits/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def largestTimeFromDigits(self, arr: List[int]) -> str: @@ -97,6 +99,8 @@ class Solution: return '' ``` +#### Java + ```java class Solution { public String largestTimeFromDigits(int[] arr) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func largestTimeFromDigits(arr []int) string { ans := -1 @@ -177,6 +185,8 @@ func largestTimeFromDigits(arr []int) string { +#### Python3 + ```python class Solution: def largestTimeFromDigits(self, arr: List[int]) -> str: diff --git a/solution/0900-0999/0949.Largest Time for Given Digits/README_EN.md b/solution/0900-0999/0949.Largest Time for Given Digits/README_EN.md index 6756c306ef294..3e37133c552f9 100644 --- a/solution/0900-0999/0949.Largest Time for Given Digits/README_EN.md +++ b/solution/0900-0999/0949.Largest Time for Given Digits/README_EN.md @@ -59,6 +59,8 @@ tags: +#### Python3 + ```python class Solution: def largestTimeFromDigits(self, arr: List[int]) -> str: @@ -77,6 +79,8 @@ class Solution: return '' ``` +#### Java + ```java class Solution { public String largestTimeFromDigits(int[] arr) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func largestTimeFromDigits(arr []int) string { ans := -1 @@ -157,6 +165,8 @@ func largestTimeFromDigits(arr []int) string { +#### Python3 + ```python class Solution: def largestTimeFromDigits(self, arr: List[int]) -> str: diff --git a/solution/0900-0999/0950.Reveal Cards In Increasing Order/README.md b/solution/0900-0999/0950.Reveal Cards In Increasing Order/README.md index fa57fed6fc88e..2288675d6ff26 100644 --- a/solution/0900-0999/0950.Reveal Cards In Increasing Order/README.md +++ b/solution/0900-0999/0950.Reveal Cards In Increasing Order/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def deckRevealedIncreasing(self, deck: List[int]) -> List[int]: @@ -93,6 +95,8 @@ class Solution: return list(q) ``` +#### Java + ```java class Solution { public int[] deckRevealedIncreasing(int[] deck) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func deckRevealedIncreasing(deck []int) []int { sort.Sort(sort.Reverse(sort.IntSlice(deck))) diff --git a/solution/0900-0999/0950.Reveal Cards In Increasing Order/README_EN.md b/solution/0900-0999/0950.Reveal Cards In Increasing Order/README_EN.md index 09b75ac63a3c9..6d8f397a69aed 100644 --- a/solution/0900-0999/0950.Reveal Cards In Increasing Order/README_EN.md +++ b/solution/0900-0999/0950.Reveal Cards In Increasing Order/README_EN.md @@ -80,6 +80,8 @@ Since all the cards revealed are in increasing order, the answer is correct. +#### Python3 + ```python class Solution: def deckRevealedIncreasing(self, deck: List[int]) -> List[int]: @@ -91,6 +93,8 @@ class Solution: return list(q) ``` +#### Java + ```java class Solution { public int[] deckRevealedIncreasing(int[] deck) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func deckRevealedIncreasing(deck []int) []int { sort.Sort(sort.Reverse(sort.IntSlice(deck))) diff --git a/solution/0900-0999/0951.Flip Equivalent Binary Trees/README.md b/solution/0900-0999/0951.Flip Equivalent Binary Trees/README.md index 958f9ef6bb0dd..c86a9c60d77d3 100644 --- a/solution/0900-0999/0951.Flip Equivalent Binary Trees/README.md +++ b/solution/0900-0999/0951.Flip Equivalent Binary Trees/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -90,6 +92,8 @@ class Solution: return dfs(root1, root2) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0900-0999/0951.Flip Equivalent Binary Trees/README_EN.md b/solution/0900-0999/0951.Flip Equivalent Binary Trees/README_EN.md index 8b200c99fca9e..dcc51a67c5cc1 100644 --- a/solution/0900-0999/0951.Flip Equivalent Binary Trees/README_EN.md +++ b/solution/0900-0999/0951.Flip Equivalent Binary Trees/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -86,6 +88,8 @@ class Solution: return dfs(root1, root2) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0900-0999/0952.Largest Component Size by Common Factor/README.md b/solution/0900-0999/0952.Largest Component Size by Common Factor/README.md index a0cba7250bc85..6a17a9688e8cf 100644 --- a/solution/0900-0999/0952.Largest Component Size by Common Factor/README.md +++ b/solution/0900-0999/0952.Largest Component Size by Common Factor/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class UnionFind: def __init__(self, n): @@ -114,6 +116,8 @@ class Solution: return max(Counter(uf.find(v) for v in nums).values()) ``` +#### Java + ```java class UnionFind { int[] p; @@ -169,6 +173,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -219,6 +225,8 @@ public: }; ``` +#### Go + ```go func largestComponentSize(nums []int) int { m := slices.Max(nums) diff --git a/solution/0900-0999/0952.Largest Component Size by Common Factor/README_EN.md b/solution/0900-0999/0952.Largest Component Size by Common Factor/README_EN.md index 9d19591209d45..331da30efda7a 100644 --- a/solution/0900-0999/0952.Largest Component Size by Common Factor/README_EN.md +++ b/solution/0900-0999/0952.Largest Component Size by Common Factor/README_EN.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class UnionFind: def __init__(self, n): @@ -99,6 +101,8 @@ class Solution: return max(Counter(uf.find(v) for v in nums).values()) ``` +#### Java + ```java class UnionFind { int[] p; @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -204,6 +210,8 @@ public: }; ``` +#### Go + ```go func largestComponentSize(nums []int) int { m := slices.Max(nums) diff --git a/solution/0900-0999/0953.Verifying an Alien Dictionary/README.md b/solution/0900-0999/0953.Verifying an Alien Dictionary/README.md index e6826d08d2898..c3fdce7bf02a6 100644 --- a/solution/0900-0999/0953.Verifying an Alien Dictionary/README.md +++ b/solution/0900-0999/0953.Verifying an Alien Dictionary/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def isAlienSorted(self, words: List[str], order: str) -> bool: @@ -86,6 +88,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isAlienSorted(String[] words, String order) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func isAlienSorted(words []string, order string) bool { m := make([]int, 26) @@ -167,6 +175,8 @@ func isAlienSorted(words []string, order string) bool { } ``` +#### TypeScript + ```ts function isAlienSorted(words: string[], order: string): boolean { const map = new Map(); @@ -196,6 +206,8 @@ function isAlienSorted(words: string[], order: string): boolean { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { @@ -231,6 +243,8 @@ impl Solution { } ``` +#### C + ```c #define min(a, b) (((a) < (b)) ? (a) : (b)) diff --git a/solution/0900-0999/0953.Verifying an Alien Dictionary/README_EN.md b/solution/0900-0999/0953.Verifying an Alien Dictionary/README_EN.md index ef6ce5f3cc2b7..5d957d695254c 100644 --- a/solution/0900-0999/0953.Verifying an Alien Dictionary/README_EN.md +++ b/solution/0900-0999/0953.Verifying an Alien Dictionary/README_EN.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def isAlienSorted(self, words: List[str], order: str) -> bool: @@ -86,6 +88,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isAlienSorted(String[] words, String order) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func isAlienSorted(words []string, order string) bool { m := make([]int, 26) @@ -167,6 +175,8 @@ func isAlienSorted(words []string, order string) bool { } ``` +#### TypeScript + ```ts function isAlienSorted(words: string[], order: string): boolean { const map = new Map(); @@ -196,6 +206,8 @@ function isAlienSorted(words: string[], order: string): boolean { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { @@ -231,6 +243,8 @@ impl Solution { } ``` +#### C + ```c #define min(a, b) (((a) < (b)) ? (a) : (b)) diff --git a/solution/0900-0999/0954.Array of Doubled Pairs/README.md b/solution/0900-0999/0954.Array of Doubled Pairs/README.md index ea3964b7acf39..dee8c33aefafb 100644 --- a/solution/0900-0999/0954.Array of Doubled Pairs/README.md +++ b/solution/0900-0999/0954.Array of Doubled Pairs/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def canReorderDoubled(self, arr: List[int]) -> bool: @@ -78,6 +80,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean canReorderDoubled(int[] arr) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func canReorderDoubled(arr []int) bool { freq := make(map[int]int) diff --git a/solution/0900-0999/0954.Array of Doubled Pairs/README_EN.md b/solution/0900-0999/0954.Array of Doubled Pairs/README_EN.md index 38c850e074ff7..0b87a2963043d 100644 --- a/solution/0900-0999/0954.Array of Doubled Pairs/README_EN.md +++ b/solution/0900-0999/0954.Array of Doubled Pairs/README_EN.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def canReorderDoubled(self, arr: List[int]) -> bool: @@ -76,6 +78,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean canReorderDoubled(int[] arr) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func canReorderDoubled(arr []int) bool { freq := make(map[int]int) diff --git a/solution/0900-0999/0955.Delete Columns to Make Sorted II/README.md b/solution/0900-0999/0955.Delete Columns to Make Sorted II/README.md index 7855bad35ccdf..8251dba9e5625 100644 --- a/solution/0900-0999/0955.Delete Columns to Make Sorted II/README.md +++ b/solution/0900-0999/0955.Delete Columns to Make Sorted II/README.md @@ -83,6 +83,8 @@ strs 的列已经是按字典序排列了,所以我们不需要删除任何东 +#### Java + ```java class Solution { public int minDeletionSize(String[] A) { diff --git a/solution/0900-0999/0955.Delete Columns to Make Sorted II/README_EN.md b/solution/0900-0999/0955.Delete Columns to Make Sorted II/README_EN.md index beaf598b5f3c3..2ea72230eb55e 100644 --- a/solution/0900-0999/0955.Delete Columns to Make Sorted II/README_EN.md +++ b/solution/0900-0999/0955.Delete Columns to Make Sorted II/README_EN.md @@ -77,6 +77,8 @@ i.e., it is NOT necessarily true that (strs[0][0] <= strs[0][1] <= ...) +#### Java + ```java class Solution { public int minDeletionSize(String[] A) { diff --git a/solution/0900-0999/0956.Tallest Billboard/README.md b/solution/0900-0999/0956.Tallest Billboard/README.md index e95c0d56ff429..e745f9a2d9729 100644 --- a/solution/0900-0999/0956.Tallest Billboard/README.md +++ b/solution/0900-0999/0956.Tallest Billboard/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def tallestBillboard(self, rods: List[int]) -> int: @@ -99,6 +101,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private Integer[][] f; @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func tallestBillboard(rods []int) int { s := 0 @@ -195,6 +203,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function tallestBillboard(rods: number[]): number { const s = rods.reduce((a, b) => a + b, 0); @@ -247,6 +257,8 @@ $$ +#### Python3 + ```python class Solution: def tallestBillboard(self, rods: List[int]) -> int: @@ -268,6 +280,8 @@ class Solution: return f[n][0] ``` +#### Java + ```java class Solution { public int tallestBillboard(int[] rods) { @@ -302,6 +316,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -332,6 +348,8 @@ public: }; ``` +#### Go + ```go func tallestBillboard(rods []int) int { n := len(rods) diff --git a/solution/0900-0999/0956.Tallest Billboard/README_EN.md b/solution/0900-0999/0956.Tallest Billboard/README_EN.md index 0e6008d713922..7db2d0c877a50 100644 --- a/solution/0900-0999/0956.Tallest Billboard/README_EN.md +++ b/solution/0900-0999/0956.Tallest Billboard/README_EN.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def tallestBillboard(self, rods: List[int]) -> int: @@ -81,6 +83,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private Integer[][] f; @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func tallestBillboard(rods []int) int { s := 0 @@ -177,6 +185,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function tallestBillboard(rods: number[]): number { const s = rods.reduce((a, b) => a + b, 0); @@ -207,6 +217,8 @@ function tallestBillboard(rods: number[]): number { +#### Python3 + ```python class Solution: def tallestBillboard(self, rods: List[int]) -> int: @@ -228,6 +240,8 @@ class Solution: return f[n][0] ``` +#### Java + ```java class Solution { public int tallestBillboard(int[] rods) { @@ -262,6 +276,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -292,6 +308,8 @@ public: }; ``` +#### Go + ```go func tallestBillboard(rods []int) int { n := len(rods) diff --git a/solution/0900-0999/0957.Prison Cells After N Days/README.md b/solution/0900-0999/0957.Prison Cells After N Days/README.md index 1a8cdd5f165ce..8d6f8eb1a5d17 100644 --- a/solution/0900-0999/0957.Prison Cells After N Days/README.md +++ b/solution/0900-0999/0957.Prison Cells After N Days/README.md @@ -79,18 +79,26 @@ Day 7: [0, 0, 1, 1, 0, 0, 0, 0] +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/0900-0999/0957.Prison Cells After N Days/README_EN.md b/solution/0900-0999/0957.Prison Cells After N Days/README_EN.md index 9a4d08c224da5..7436c4ed29c4b 100644 --- a/solution/0900-0999/0957.Prison Cells After N Days/README_EN.md +++ b/solution/0900-0999/0957.Prison Cells After N Days/README_EN.md @@ -77,18 +77,26 @@ Day 7: [0, 0, 1, 1, 0, 0, 0, 0] +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/0900-0999/0958.Check Completeness of a Binary Tree/README.md b/solution/0900-0999/0958.Check Completeness of a Binary Tree/README.md index 61cba7e150a62..5e3363a304958 100644 --- a/solution/0900-0999/0958.Check Completeness of a Binary Tree/README.md +++ b/solution/0900-0999/0958.Check Completeness of a Binary Tree/README.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -82,6 +84,8 @@ class Solution: return all(node is None for node in q) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0900-0999/0958.Check Completeness of a Binary Tree/README_EN.md b/solution/0900-0999/0958.Check Completeness of a Binary Tree/README_EN.md index 9c1638065517b..f0f0ad658434f 100644 --- a/solution/0900-0999/0958.Check Completeness of a Binary Tree/README_EN.md +++ b/solution/0900-0999/0958.Check Completeness of a Binary Tree/README_EN.md @@ -57,6 +57,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -76,6 +78,8 @@ class Solution: return all(node is None for node in q) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0900-0999/0959.Regions Cut By Slashes/README.md b/solution/0900-0999/0959.Regions Cut By Slashes/README.md index 75412951d5daf..6c7ce33e17e65 100644 --- a/solution/0900-0999/0959.Regions Cut By Slashes/README.md +++ b/solution/0900-0999/0959.Regions Cut By Slashes/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def regionsBySlashes(self, grid: List[str]) -> int: @@ -117,6 +119,8 @@ class Solution: return size ``` +#### Java + ```java class Solution { private int[] p; @@ -174,6 +178,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -222,6 +228,8 @@ public: }; ``` +#### Go + ```go func regionsBySlashes(grid []string) int { n := len(grid) diff --git a/solution/0900-0999/0959.Regions Cut By Slashes/README_EN.md b/solution/0900-0999/0959.Regions Cut By Slashes/README_EN.md index 1c747939082a6..826f54d8a3194 100644 --- a/solution/0900-0999/0959.Regions Cut By Slashes/README_EN.md +++ b/solution/0900-0999/0959.Regions Cut By Slashes/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def regionsBySlashes(self, grid: List[str]) -> int: @@ -107,6 +109,8 @@ class Solution: return size ``` +#### Java + ```java class Solution { private int[] p; @@ -164,6 +168,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -212,6 +218,8 @@ public: }; ``` +#### Go + ```go func regionsBySlashes(grid []string) int { n := len(grid) diff --git a/solution/0900-0999/0960.Delete Columns to Make Sorted III/README.md b/solution/0900-0999/0960.Delete Columns to Make Sorted III/README.md index 18188a4d19d7f..f56f44175d435 100644 --- a/solution/0900-0999/0960.Delete Columns to Make Sorted III/README.md +++ b/solution/0900-0999/0960.Delete Columns to Make Sorted III/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def minDeletionSize(self, strs: List[str]) -> int: @@ -91,6 +93,8 @@ class Solution: return n - max(dp) ``` +#### Java + ```java class Solution { public int minDeletionSize(String[] strs) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func minDeletionSize(strs []string) int { n := len(strs[0]) diff --git a/solution/0900-0999/0960.Delete Columns to Make Sorted III/README_EN.md b/solution/0900-0999/0960.Delete Columns to Make Sorted III/README_EN.md index 8059add56eb8b..a0e4da1b1996d 100644 --- a/solution/0900-0999/0960.Delete Columns to Make Sorted III/README_EN.md +++ b/solution/0900-0999/0960.Delete Columns to Make Sorted III/README_EN.md @@ -76,6 +76,8 @@ Note that strs[0] > strs[1] - the array strs is not necessarily in lexicograp +#### Python3 + ```python class Solution: def minDeletionSize(self, strs: List[str]) -> int: @@ -88,6 +90,8 @@ class Solution: return n - max(dp) ``` +#### Java + ```java class Solution { public int minDeletionSize(String[] strs) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func minDeletionSize(strs []string) int { n := len(strs[0]) diff --git a/solution/0900-0999/0961.N-Repeated Element in Size 2N Array/README.md b/solution/0900-0999/0961.N-Repeated Element in Size 2N Array/README.md index 90ae33f7b6ee1..278e9c78061cf 100644 --- a/solution/0900-0999/0961.N-Repeated Element in Size 2N Array/README.md +++ b/solution/0900-0999/0961.N-Repeated Element in Size 2N Array/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def repeatedNTimes(self, nums: List[int]) -> int: @@ -91,6 +93,8 @@ class Solution: s.add(x) ``` +#### Java + ```java class Solution { public int repeatedNTimes(int[] nums) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func repeatedNTimes(nums []int) int { s := map[int]bool{} @@ -131,6 +139,8 @@ func repeatedNTimes(nums []int) int { } ``` +#### TypeScript + ```ts function repeatedNTimes(nums: number[]): number { const s: Set = new Set(); @@ -143,6 +153,8 @@ function repeatedNTimes(nums: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0900-0999/0961.N-Repeated Element in Size 2N Array/README_EN.md b/solution/0900-0999/0961.N-Repeated Element in Size 2N Array/README_EN.md index 342c8e2f6cc9c..bd29e0e2cd0be 100644 --- a/solution/0900-0999/0961.N-Repeated Element in Size 2N Array/README_EN.md +++ b/solution/0900-0999/0961.N-Repeated Element in Size 2N Array/README_EN.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python class Solution: def repeatedNTimes(self, nums: List[int]) -> int: @@ -68,6 +70,8 @@ class Solution: s.add(x) ``` +#### Java + ```java class Solution { public int repeatedNTimes(int[] nums) { @@ -81,6 +85,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -96,6 +102,8 @@ public: }; ``` +#### Go + ```go func repeatedNTimes(nums []int) int { s := map[int]bool{} @@ -108,6 +116,8 @@ func repeatedNTimes(nums []int) int { } ``` +#### TypeScript + ```ts function repeatedNTimes(nums: number[]): number { const s: Set = new Set(); @@ -120,6 +130,8 @@ function repeatedNTimes(nums: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0900-0999/0962.Maximum Width Ramp/README.md b/solution/0900-0999/0962.Maximum Width Ramp/README.md index 31b0f9755ad17..88d4735aede8d 100644 --- a/solution/0900-0999/0962.Maximum Width Ramp/README.md +++ b/solution/0900-0999/0962.Maximum Width Ramp/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def maxWidthRamp(self, nums: List[int]) -> int: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxWidthRamp(int[] nums) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func maxWidthRamp(nums []int) int { n := len(nums) diff --git a/solution/0900-0999/0962.Maximum Width Ramp/README_EN.md b/solution/0900-0999/0962.Maximum Width Ramp/README_EN.md index f0ef6dc9f24a1..58da0809f55fe 100644 --- a/solution/0900-0999/0962.Maximum Width Ramp/README_EN.md +++ b/solution/0900-0999/0962.Maximum Width Ramp/README_EN.md @@ -57,6 +57,8 @@ tags: +#### Python3 + ```python class Solution: def maxWidthRamp(self, nums: List[int]) -> int: @@ -73,6 +75,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxWidthRamp(int[] nums) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func maxWidthRamp(nums []int) int { n := len(nums) diff --git a/solution/0900-0999/0963.Minimum Area Rectangle II/README.md b/solution/0900-0999/0963.Minimum Area Rectangle II/README.md index 66bd3890c61af..4f23117a1fb07 100644 --- a/solution/0900-0999/0963.Minimum Area Rectangle II/README.md +++ b/solution/0900-0999/0963.Minimum Area Rectangle II/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def minAreaFreeRect(self, points: List[List[int]]) -> float: @@ -113,6 +115,8 @@ class Solution: return 0 if ans == inf else ans ``` +#### Java + ```java class Solution { public double minAreaFreeRect(int[][] points) { @@ -152,6 +156,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -191,6 +197,8 @@ public: }; ``` +#### Go + ```go func minAreaFreeRect(points [][]int) float64 { n := len(points) @@ -230,6 +238,8 @@ func minAreaFreeRect(points [][]int) float64 { } ``` +#### TypeScript + ```ts function minAreaFreeRect(points: number[][]): number { const n = points.length; diff --git a/solution/0900-0999/0963.Minimum Area Rectangle II/README_EN.md b/solution/0900-0999/0963.Minimum Area Rectangle II/README_EN.md index afc570e32e901..7b5cf232735b0 100644 --- a/solution/0900-0999/0963.Minimum Area Rectangle II/README_EN.md +++ b/solution/0900-0999/0963.Minimum Area Rectangle II/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def minAreaFreeRect(self, points: List[List[int]]) -> float: @@ -95,6 +97,8 @@ class Solution: return 0 if ans == inf else ans ``` +#### Java + ```java class Solution { public double minAreaFreeRect(int[][] points) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go func minAreaFreeRect(points [][]int) float64 { n := len(points) @@ -212,6 +220,8 @@ func minAreaFreeRect(points [][]int) float64 { } ``` +#### TypeScript + ```ts function minAreaFreeRect(points: number[][]): number { const n = points.length; diff --git a/solution/0900-0999/0964.Least Operators to Express Number/README.md b/solution/0900-0999/0964.Least Operators to Express Number/README.md index 03f107a26a1ad..a343e91cbe6da 100644 --- a/solution/0900-0999/0964.Least Operators to Express Number/README.md +++ b/solution/0900-0999/0964.Least Operators to Express Number/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def leastOpsExpressTarget(self, x: int, target: int) -> int: @@ -107,6 +109,8 @@ class Solution: return dfs(target) ``` +#### Java + ```java class Solution { private int x; @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go func leastOpsExpressTarget(x int, target int) int { f := map[int]int{} @@ -198,6 +206,8 @@ func leastOpsExpressTarget(x int, target int) int { } ``` +#### TypeScript + ```ts function leastOpsExpressTarget(x: number, target: number): number { const f: Map = new Map(); diff --git a/solution/0900-0999/0964.Least Operators to Express Number/README_EN.md b/solution/0900-0999/0964.Least Operators to Express Number/README_EN.md index 899c9f35e30b5..425102dc6d09d 100644 --- a/solution/0900-0999/0964.Least Operators to Express Number/README_EN.md +++ b/solution/0900-0999/0964.Least Operators to Express Number/README_EN.md @@ -77,6 +77,8 @@ The expression contains 3 operations. +#### Python3 + ```python class Solution: def leastOpsExpressTarget(self, x: int, target: int) -> int: @@ -94,6 +96,8 @@ class Solution: return dfs(target) ``` +#### Java + ```java class Solution { private int x; @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func leastOpsExpressTarget(x int, target int) int { f := map[int]int{} @@ -185,6 +193,8 @@ func leastOpsExpressTarget(x int, target int) int { } ``` +#### TypeScript + ```ts function leastOpsExpressTarget(x: number, target: number): number { const f: Map = new Map(); diff --git a/solution/0900-0999/0965.Univalued Binary Tree/README.md b/solution/0900-0999/0965.Univalued Binary Tree/README.md index 7adbaec31ba1a..f8195bf258489 100644 --- a/solution/0900-0999/0965.Univalued Binary Tree/README.md +++ b/solution/0900-0999/0965.Univalued Binary Tree/README.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -77,6 +79,8 @@ class Solution: return dfs(root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -153,6 +161,8 @@ func isUnivalTree(root *TreeNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -180,6 +190,8 @@ function isUnivalTree(root: TreeNode | null): boolean { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/0900-0999/0965.Univalued Binary Tree/README_EN.md b/solution/0900-0999/0965.Univalued Binary Tree/README_EN.md index 39e0e083a8062..ecffe7c494df0 100644 --- a/solution/0900-0999/0965.Univalued Binary Tree/README_EN.md +++ b/solution/0900-0999/0965.Univalued Binary Tree/README_EN.md @@ -56,6 +56,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -73,6 +75,8 @@ class Solution: return dfs(root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -149,6 +157,8 @@ func isUnivalTree(root *TreeNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -176,6 +186,8 @@ function isUnivalTree(root: TreeNode | null): boolean { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/0900-0999/0966.Vowel Spellchecker/README.md b/solution/0900-0999/0966.Vowel Spellchecker/README.md index 25d6ca4f10817..723a5becb441d 100644 --- a/solution/0900-0999/0966.Vowel Spellchecker/README.md +++ b/solution/0900-0999/0966.Vowel Spellchecker/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python class Solution: def spellchecker(self, wordlist: List[str], queries: List[str]) -> List[str]: @@ -128,6 +130,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String[] spellchecker(String[] wordlist, String[] queries) { @@ -176,6 +180,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -228,6 +234,8 @@ public: }; ``` +#### Go + ```go func spellchecker(wordlist []string, queries []string) (ans []string) { s := map[string]bool{} diff --git a/solution/0900-0999/0966.Vowel Spellchecker/README_EN.md b/solution/0900-0999/0966.Vowel Spellchecker/README_EN.md index 0d969ec1dad3d..5987839c4b1b8 100644 --- a/solution/0900-0999/0966.Vowel Spellchecker/README_EN.md +++ b/solution/0900-0999/0966.Vowel Spellchecker/README_EN.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def spellchecker(self, wordlist: List[str], queries: List[str]) -> List[str]: @@ -112,6 +114,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String[] spellchecker(String[] wordlist, String[] queries) { @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -212,6 +218,8 @@ public: }; ``` +#### Go + ```go func spellchecker(wordlist []string, queries []string) (ans []string) { s := map[string]bool{} diff --git a/solution/0900-0999/0967.Numbers With Same Consecutive Differences/README.md b/solution/0900-0999/0967.Numbers With Same Consecutive Differences/README.md index 7a06d46c6214b..96abb63003f46 100644 --- a/solution/0900-0999/0967.Numbers With Same Consecutive Differences/README.md +++ b/solution/0900-0999/0967.Numbers With Same Consecutive Differences/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def numsSameConsecDiff(self, n: int, k: int) -> List[int]: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] numsSameConsecDiff(int n, int k) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func numsSameConsecDiff(n int, k int) []int { var ans []int diff --git a/solution/0900-0999/0967.Numbers With Same Consecutive Differences/README_EN.md b/solution/0900-0999/0967.Numbers With Same Consecutive Differences/README_EN.md index d47fbdb554547..fa6a8d6bf0c8e 100644 --- a/solution/0900-0999/0967.Numbers With Same Consecutive Differences/README_EN.md +++ b/solution/0900-0999/0967.Numbers With Same Consecutive Differences/README_EN.md @@ -55,6 +55,8 @@ tags: +#### Python3 + ```python class Solution: def numsSameConsecDiff(self, n: int, k: int) -> List[int]: @@ -75,6 +77,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] numsSameConsecDiff(int n, int k) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func numsSameConsecDiff(n int, k int) []int { var ans []int diff --git a/solution/0900-0999/0968.Binary Tree Cameras/README.md b/solution/0900-0999/0968.Binary Tree Cameras/README.md index 3cd48562b917d..f731ce7c0e457 100644 --- a/solution/0900-0999/0968.Binary Tree Cameras/README.md +++ b/solution/0900-0999/0968.Binary Tree Cameras/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -108,6 +110,8 @@ class Solution: return min(a, b) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -208,6 +216,8 @@ func minCameraCover(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0900-0999/0968.Binary Tree Cameras/README_EN.md b/solution/0900-0999/0968.Binary Tree Cameras/README_EN.md index a42ef3c9c9629..95ddedb8a74a5 100644 --- a/solution/0900-0999/0968.Binary Tree Cameras/README_EN.md +++ b/solution/0900-0999/0968.Binary Tree Cameras/README_EN.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -81,6 +83,8 @@ class Solution: return min(a, b) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -181,6 +189,8 @@ func minCameraCover(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0900-0999/0969.Pancake Sorting/README.md b/solution/0900-0999/0969.Pancake Sorting/README.md index 36015c75bd75d..dfb6fa49d3acd 100644 --- a/solution/0900-0999/0969.Pancake Sorting/README.md +++ b/solution/0900-0999/0969.Pancake Sorting/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def pancakeSort(self, arr: List[int]) -> List[int]: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List pancakeSort(int[] arr) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func pancakeSort(arr []int) []int { var ans []int @@ -182,6 +190,8 @@ func pancakeSort(arr []int) []int { } ``` +#### TypeScript + ```ts function pancakeSort(arr: number[]): number[] { let ans = []; @@ -208,6 +218,8 @@ function reverse(nums: Array, end: number): void { } ``` +#### Rust + ```rust impl Solution { pub fn pancake_sort(mut arr: Vec) -> Vec { diff --git a/solution/0900-0999/0969.Pancake Sorting/README_EN.md b/solution/0900-0999/0969.Pancake Sorting/README_EN.md index e68853d30e35f..dd2c1dae1da01 100644 --- a/solution/0900-0999/0969.Pancake Sorting/README_EN.md +++ b/solution/0900-0999/0969.Pancake Sorting/README_EN.md @@ -75,6 +75,8 @@ Note that other answers, such as [3, 3], would also be accepted. +#### Python3 + ```python class Solution: def pancakeSort(self, arr: List[int]) -> List[int]: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List pancakeSort(int[] arr) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func pancakeSort(arr []int) []int { var ans []int @@ -179,6 +187,8 @@ func pancakeSort(arr []int) []int { } ``` +#### TypeScript + ```ts function pancakeSort(arr: number[]): number[] { let ans = []; @@ -205,6 +215,8 @@ function reverse(nums: Array, end: number): void { } ``` +#### Rust + ```rust impl Solution { pub fn pancake_sort(mut arr: Vec) -> Vec { diff --git a/solution/0900-0999/0970.Powerful Integers/README.md b/solution/0900-0999/0970.Powerful Integers/README.md index c2998e4eb69e1..ec1aa27a18ecc 100644 --- a/solution/0900-0999/0970.Powerful Integers/README.md +++ b/solution/0900-0999/0970.Powerful Integers/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def powerfulIntegers(self, x: int, y: int, bound: int) -> List[int]: @@ -94,6 +96,8 @@ class Solution: return list(ans) ``` +#### Java + ```java class Solution { public List powerfulIntegers(int x, int y, int bound) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func powerfulIntegers(x int, y int, bound int) (ans []int) { s := map[int]struct{}{} @@ -156,6 +164,8 @@ func powerfulIntegers(x int, y int, bound int) (ans []int) { } ``` +#### TypeScript + ```ts function powerfulIntegers(x: number, y: number, bound: number): number[] { const ans = new Set(); @@ -174,6 +184,8 @@ function powerfulIntegers(x: number, y: number, bound: number): number[] { } ``` +#### JavaScript + ```js /** * @param {number} x diff --git a/solution/0900-0999/0970.Powerful Integers/README_EN.md b/solution/0900-0999/0970.Powerful Integers/README_EN.md index de66e3b667f2d..b0762380a6ee4 100644 --- a/solution/0900-0999/0970.Powerful Integers/README_EN.md +++ b/solution/0900-0999/0970.Powerful Integers/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(\log^2 bound)$, and the space complexity is $O(\log^2 +#### Python3 + ```python class Solution: def powerfulIntegers(self, x: int, y: int, bound: int) -> List[int]: @@ -93,6 +95,8 @@ class Solution: return list(ans) ``` +#### Java + ```java class Solution { public List powerfulIntegers(int x, int y, int bound) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func powerfulIntegers(x int, y int, bound int) (ans []int) { s := map[int]struct{}{} @@ -155,6 +163,8 @@ func powerfulIntegers(x int, y int, bound int) (ans []int) { } ``` +#### TypeScript + ```ts function powerfulIntegers(x: number, y: number, bound: number): number[] { const ans = new Set(); @@ -173,6 +183,8 @@ function powerfulIntegers(x: number, y: number, bound: number): number[] { } ``` +#### JavaScript + ```js /** * @param {number} x diff --git a/solution/0900-0999/0971.Flip Binary Tree To Match Preorder Traversal/README.md b/solution/0900-0999/0971.Flip Binary Tree To Match Preorder Traversal/README.md index 3b0a88f2e8bdd..04038c4aec64e 100644 --- a/solution/0900-0999/0971.Flip Binary Tree To Match Preorder Traversal/README.md +++ b/solution/0900-0999/0971.Flip Binary Tree To Match Preorder Traversal/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -114,6 +116,8 @@ class Solution: return ans if ok else [-1] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -164,6 +168,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -206,6 +212,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -246,6 +254,8 @@ func flipMatchVoyage(root *TreeNode, voyage []int) []int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0900-0999/0971.Flip Binary Tree To Match Preorder Traversal/README_EN.md b/solution/0900-0999/0971.Flip Binary Tree To Match Preorder Traversal/README_EN.md index af98278f3a62e..8df6528ec2fdd 100644 --- a/solution/0900-0999/0971.Flip Binary Tree To Match Preorder Traversal/README_EN.md +++ b/solution/0900-0999/0971.Flip Binary Tree To Match Preorder Traversal/README_EN.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -104,6 +106,8 @@ class Solution: return ans if ok else [-1] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -196,6 +202,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -236,6 +244,8 @@ func flipMatchVoyage(root *TreeNode, voyage []int) []int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0900-0999/0972.Equal Rational Numbers/README.md b/solution/0900-0999/0972.Equal Rational Numbers/README.md index 5e415758416e0..29aa0d2e7dadb 100644 --- a/solution/0900-0999/0972.Equal Rational Numbers/README.md +++ b/solution/0900-0999/0972.Equal Rational Numbers/README.md @@ -95,18 +95,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/0900-0999/0972.Equal Rational Numbers/README_EN.md b/solution/0900-0999/0972.Equal Rational Numbers/README_EN.md index 6fb8f2d056002..2762ec207384d 100644 --- a/solution/0900-0999/0972.Equal Rational Numbers/README_EN.md +++ b/solution/0900-0999/0972.Equal Rational Numbers/README_EN.md @@ -93,18 +93,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/0900-0999/0973.K Closest Points to Origin/README.md b/solution/0900-0999/0973.K Closest Points to Origin/README.md index 44b547dc80366..d469bd7ba2845 100644 --- a/solution/0900-0999/0973.K Closest Points to Origin/README.md +++ b/solution/0900-0999/0973.K Closest Points to Origin/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def kClosest(self, points: List[List[int]], k: int) -> List[List[int]]: @@ -82,6 +84,8 @@ class Solution: return points[:k] ``` +#### Java + ```java class Solution { public int[][] kClosest(int[][] points, int k) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func kClosest(points [][]int, k int) [][]int { sort.Slice(points, func(i, j int) bool { @@ -117,12 +125,16 @@ func kClosest(points [][]int, k int) [][]int { } ``` +#### TypeScript + ```ts function kClosest(points: number[][], k: number): number[][] { return points.sort((a, b) => a[0] ** 2 + a[1] ** 2 - (b[0] ** 2 + b[1] ** 2)).slice(0, k); } ``` +#### Rust + ```rust impl Solution { pub fn k_closest(mut points: Vec>, k: i32) -> Vec> { diff --git a/solution/0900-0999/0973.K Closest Points to Origin/README_EN.md b/solution/0900-0999/0973.K Closest Points to Origin/README_EN.md index 30e7fbb44621b..3e74b8f6eaa75 100644 --- a/solution/0900-0999/0973.K Closest Points to Origin/README_EN.md +++ b/solution/0900-0999/0973.K Closest Points to Origin/README_EN.md @@ -67,6 +67,8 @@ We only want the closest k = 1 points from the origin, so the answer is just [[- +#### Python3 + ```python class Solution: def kClosest(self, points: List[List[int]], k: int) -> List[List[int]]: @@ -74,6 +76,8 @@ class Solution: return points[:k] ``` +#### Java + ```java class Solution { public int[][] kClosest(int[][] points, int k) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -99,6 +105,8 @@ public: }; ``` +#### Go + ```go func kClosest(points [][]int, k int) [][]int { sort.Slice(points, func(i, j int) bool { @@ -109,12 +117,16 @@ func kClosest(points [][]int, k int) [][]int { } ``` +#### TypeScript + ```ts function kClosest(points: number[][], k: number): number[][] { return points.sort((a, b) => a[0] ** 2 + a[1] ** 2 - (b[0] ** 2 + b[1] ** 2)).slice(0, k); } ``` +#### Rust + ```rust impl Solution { pub fn k_closest(mut points: Vec>, k: i32) -> Vec> { diff --git a/solution/0900-0999/0974.Subarray Sums Divisible by K/README.md b/solution/0900-0999/0974.Subarray Sums Divisible by K/README.md index 76fde106802f6..96ffad06b9d64 100644 --- a/solution/0900-0999/0974.Subarray Sums Divisible by K/README.md +++ b/solution/0900-0999/0974.Subarray Sums Divisible by K/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def subarraysDivByK(self, nums: List[int], k: int) -> int: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int subarraysDivByK(int[] nums, int k) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func subarraysDivByK(nums []int, k int) (ans int) { cnt := map[int]int{0: 1} @@ -129,6 +137,8 @@ func subarraysDivByK(nums []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function subarraysDivByK(nums: number[], k: number): number { const counter = new Map(); diff --git a/solution/0900-0999/0974.Subarray Sums Divisible by K/README_EN.md b/solution/0900-0999/0974.Subarray Sums Divisible by K/README_EN.md index d34eabe93e309..82289e83b4320 100644 --- a/solution/0900-0999/0974.Subarray Sums Divisible by K/README_EN.md +++ b/solution/0900-0999/0974.Subarray Sums Divisible by K/README_EN.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python class Solution: def subarraysDivByK(self, nums: List[int], k: int) -> int: @@ -70,6 +72,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int subarraysDivByK(int[] nums, int k) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,6 +107,8 @@ public: }; ``` +#### Go + ```go func subarraysDivByK(nums []int, k int) (ans int) { cnt := map[int]int{0: 1} @@ -114,6 +122,8 @@ func subarraysDivByK(nums []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function subarraysDivByK(nums: number[], k: number): number { const counter = new Map(); diff --git a/solution/0900-0999/0975.Odd Even Jump/README.md b/solution/0900-0999/0975.Odd Even Jump/README.md index 744f525d22b03..71f1151615bcd 100644 --- a/solution/0900-0999/0975.Odd Even Jump/README.md +++ b/solution/0900-0999/0975.Odd Even Jump/README.md @@ -104,6 +104,8 @@ tags: +#### Python3 + ```python from sortedcontainers import SortedDict @@ -130,6 +132,8 @@ class Solution: return sum(dfs(i, 1) for i in range(n)) ``` +#### Java + ```java class Solution { private int n; @@ -170,6 +174,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -207,6 +213,8 @@ public: }; ``` +#### Go + ```go func oddEvenJumps(arr []int) (ans int) { n := len(arr) diff --git a/solution/0900-0999/0975.Odd Even Jump/README_EN.md b/solution/0900-0999/0975.Odd Even Jump/README_EN.md index 8d4cbea4c2c93..83ef2b86369a4 100644 --- a/solution/0900-0999/0975.Odd Even Jump/README_EN.md +++ b/solution/0900-0999/0975.Odd Even Jump/README_EN.md @@ -95,6 +95,8 @@ number of jumps. +#### Python3 + ```python from sortedcontainers import SortedDict @@ -121,6 +123,8 @@ class Solution: return sum(dfs(i, 1) for i in range(n)) ``` +#### Java + ```java class Solution { private int n; @@ -161,6 +165,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -198,6 +204,8 @@ public: }; ``` +#### Go + ```go func oddEvenJumps(arr []int) (ans int) { n := len(arr) diff --git a/solution/0900-0999/0976.Largest Perimeter Triangle/README.md b/solution/0900-0999/0976.Largest Perimeter Triangle/README.md index e33a994d47351..0365173df3568 100644 --- a/solution/0900-0999/0976.Largest Perimeter Triangle/README.md +++ b/solution/0900-0999/0976.Largest Perimeter Triangle/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def largestPerimeter(self, nums: List[int]) -> int: @@ -83,6 +85,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { public int largestPerimeter(int[] nums) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func largestPerimeter(nums []int) int { sort.Ints(nums) @@ -125,6 +133,8 @@ func largestPerimeter(nums []int) int { } ``` +#### TypeScript + ```ts function largestPerimeter(nums: number[]): number { const n = nums.length; @@ -139,6 +149,8 @@ function largestPerimeter(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn largest_perimeter(mut nums: Vec) -> i32 { @@ -155,6 +167,8 @@ impl Solution { } ``` +#### C + ```c int cmp(const void* a, const void* b) { return *(int*) b - *(int*) a; diff --git a/solution/0900-0999/0976.Largest Perimeter Triangle/README_EN.md b/solution/0900-0999/0976.Largest Perimeter Triangle/README_EN.md index f82f2298a8b4f..7c5d8777f0953 100644 --- a/solution/0900-0999/0976.Largest Perimeter Triangle/README_EN.md +++ b/solution/0900-0999/0976.Largest Perimeter Triangle/README_EN.md @@ -60,6 +60,8 @@ As we cannot use any three side lengths to form a triangle of non-zero area, we +#### Python3 + ```python class Solution: def largestPerimeter(self, nums: List[int]) -> int: @@ -70,6 +72,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { public int largestPerimeter(int[] nums) { @@ -85,6 +89,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -99,6 +105,8 @@ public: }; ``` +#### Go + ```go func largestPerimeter(nums []int) int { sort.Ints(nums) @@ -112,6 +120,8 @@ func largestPerimeter(nums []int) int { } ``` +#### TypeScript + ```ts function largestPerimeter(nums: number[]): number { const n = nums.length; @@ -126,6 +136,8 @@ function largestPerimeter(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn largest_perimeter(mut nums: Vec) -> i32 { @@ -142,6 +154,8 @@ impl Solution { } ``` +#### C + ```c int cmp(const void* a, const void* b) { return *(int*) b - *(int*) a; diff --git a/solution/0900-0999/0977.Squares of a Sorted Array/README.md b/solution/0900-0999/0977.Squares of a Sorted Array/README.md index 00b1e94f345d0..42f2dbbded508 100644 --- a/solution/0900-0999/0977.Squares of a Sorted Array/README.md +++ b/solution/0900-0999/0977.Squares of a Sorted Array/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def sortedSquares(self, nums: List[int]) -> List[int]: @@ -89,6 +91,8 @@ class Solution: return ans[::-1] ``` +#### Java + ```java class Solution { public int[] sortedSquares(int[] nums) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func sortedSquares(nums []int) []int { n := len(nums) @@ -151,6 +159,8 @@ func sortedSquares(nums []int) []int { } ``` +#### Rust + ```rust impl Solution { pub fn sorted_squares(nums: Vec) -> Vec { @@ -173,6 +183,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -195,6 +207,8 @@ var sortedSquares = function (nums) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0900-0999/0977.Squares of a Sorted Array/README_EN.md b/solution/0900-0999/0977.Squares of a Sorted Array/README_EN.md index 38173515da895..6367e8928e2cf 100644 --- a/solution/0900-0999/0977.Squares of a Sorted Array/README_EN.md +++ b/solution/0900-0999/0977.Squares of a Sorted Array/README_EN.md @@ -63,6 +63,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. Igno +#### Python3 + ```python class Solution: def sortedSquares(self, nums: List[int]) -> List[int]: @@ -80,6 +82,8 @@ class Solution: return ans[::-1] ``` +#### Java + ```java class Solution { public int[] sortedSquares(int[] nums) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func sortedSquares(nums []int) []int { n := len(nums) @@ -142,6 +150,8 @@ func sortedSquares(nums []int) []int { } ``` +#### Rust + ```rust impl Solution { pub fn sorted_squares(nums: Vec) -> Vec { @@ -164,6 +174,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -186,6 +198,8 @@ var sortedSquares = function (nums) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/0900-0999/0978.Longest Turbulent Subarray/README.md b/solution/0900-0999/0978.Longest Turbulent Subarray/README.md index da371f47bfa3f..fffb50a605d1e 100644 --- a/solution/0900-0999/0978.Longest Turbulent Subarray/README.md +++ b/solution/0900-0999/0978.Longest Turbulent Subarray/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def maxTurbulenceSize(self, arr: List[int]) -> int: @@ -103,6 +105,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxTurbulenceSize(int[] arr) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func maxTurbulenceSize(arr []int) int { ans, f, g := 1, 1, 1 @@ -154,6 +162,8 @@ func maxTurbulenceSize(arr []int) int { } ``` +#### TypeScript + ```ts function maxTurbulenceSize(arr: number[]): number { let f = 1; diff --git a/solution/0900-0999/0978.Longest Turbulent Subarray/README_EN.md b/solution/0900-0999/0978.Longest Turbulent Subarray/README_EN.md index 6bae769070b56..b07a973fa9ef3 100644 --- a/solution/0900-0999/0978.Longest Turbulent Subarray/README_EN.md +++ b/solution/0900-0999/0978.Longest Turbulent Subarray/README_EN.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def maxTurbulenceSize(self, arr: List[int]) -> int: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxTurbulenceSize(int[] arr) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func maxTurbulenceSize(arr []int) int { ans, f, g := 1, 1, 1 @@ -145,6 +153,8 @@ func maxTurbulenceSize(arr []int) int { } ``` +#### TypeScript + ```ts function maxTurbulenceSize(arr: number[]): number { let f = 1; diff --git a/solution/0900-0999/0979.Distribute Coins in Binary Tree/README.md b/solution/0900-0999/0979.Distribute Coins in Binary Tree/README.md index 6b1caea82269c..3ce789a5c2b57 100644 --- a/solution/0900-0999/0979.Distribute Coins in Binary Tree/README.md +++ b/solution/0900-0999/0979.Distribute Coins in Binary Tree/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -191,6 +199,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0900-0999/0979.Distribute Coins in Binary Tree/README_EN.md b/solution/0900-0999/0979.Distribute Coins in Binary Tree/README_EN.md index 8fe56091321e9..dfdc08081ce08 100644 --- a/solution/0900-0999/0979.Distribute Coins in Binary Tree/README_EN.md +++ b/solution/0900-0999/0979.Distribute Coins in Binary Tree/README_EN.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -181,6 +189,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0900-0999/0980.Unique Paths III/README.md b/solution/0900-0999/0980.Unique Paths III/README.md index c9955c9b89426..73aa3cf4a7017 100644 --- a/solution/0900-0999/0980.Unique Paths III/README.md +++ b/solution/0900-0999/0980.Unique Paths III/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def uniquePathsIII(self, grid: List[List[int]]) -> int: @@ -114,6 +116,8 @@ class Solution: return dfs(*start, 0) ``` +#### Java + ```java class Solution { private int m; @@ -161,6 +165,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -203,6 +209,8 @@ public: }; ``` +#### Go + ```go func uniquePathsIII(grid [][]int) int { m, n := len(grid), len(grid[0]) @@ -244,6 +252,8 @@ func uniquePathsIII(grid [][]int) int { } ``` +#### TypeScript + ```ts function uniquePathsIII(grid: number[][]): number { const m = grid.length; diff --git a/solution/0900-0999/0980.Unique Paths III/README_EN.md b/solution/0900-0999/0980.Unique Paths III/README_EN.md index 7c0c94a471180..9a634a53fbf64 100644 --- a/solution/0900-0999/0980.Unique Paths III/README_EN.md +++ b/solution/0900-0999/0980.Unique Paths III/README_EN.md @@ -96,6 +96,8 @@ The time complexity is $O(3^{m \times n})$, and the space complexity is $O(m \ti +#### Python3 + ```python class Solution: def uniquePathsIII(self, grid: List[List[int]]) -> int: @@ -119,6 +121,8 @@ class Solution: return dfs(*start, 0) ``` +#### Java + ```java class Solution { private int m; @@ -166,6 +170,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -208,6 +214,8 @@ public: }; ``` +#### Go + ```go func uniquePathsIII(grid [][]int) int { m, n := len(grid), len(grid[0]) @@ -249,6 +257,8 @@ func uniquePathsIII(grid [][]int) int { } ``` +#### TypeScript + ```ts function uniquePathsIII(grid: number[][]): number { const m = grid.length; diff --git a/solution/0900-0999/0981.Time Based Key-Value Store/README.md b/solution/0900-0999/0981.Time Based Key-Value Store/README.md index 0c33ad458af14..3cd4f1ae17be5 100644 --- a/solution/0900-0999/0981.Time Based Key-Value Store/README.md +++ b/solution/0900-0999/0981.Time Based Key-Value Store/README.md @@ -77,6 +77,8 @@ timeMap.get("foo", 5); // 返回 "bar2" +#### Python3 + ```python class TimeMap: def __init__(self): @@ -99,6 +101,8 @@ class TimeMap: # param_2 = obj.get(key,timestamp) ``` +#### Java + ```java class TimeMap { private Map> ktv = new HashMap<>(); @@ -128,6 +132,8 @@ class TimeMap { */ ``` +#### C++ + ```cpp class TimeMap { public: @@ -157,6 +163,8 @@ private: */ ``` +#### Go + ```go type TimeMap struct { ktv map[string][]pair diff --git a/solution/0900-0999/0981.Time Based Key-Value Store/README_EN.md b/solution/0900-0999/0981.Time Based Key-Value Store/README_EN.md index 50fdc627fcb1c..86bd946577d56 100644 --- a/solution/0900-0999/0981.Time Based Key-Value Store/README_EN.md +++ b/solution/0900-0999/0981.Time Based Key-Value Store/README_EN.md @@ -70,6 +70,8 @@ timeMap.get("foo", 5); // return "bar2" +#### Python3 + ```python class TimeMap: def __init__(self): @@ -92,6 +94,8 @@ class TimeMap: # param_2 = obj.get(key,timestamp) ``` +#### Java + ```java class TimeMap { private Map> ktv = new HashMap<>(); @@ -121,6 +125,8 @@ class TimeMap { */ ``` +#### C++ + ```cpp class TimeMap { public: @@ -150,6 +156,8 @@ private: */ ``` +#### Go + ```go type TimeMap struct { ktv map[string][]pair diff --git a/solution/0900-0999/0982.Triples with Bitwise AND Equal To Zero/README.md b/solution/0900-0999/0982.Triples with Bitwise AND Equal To Zero/README.md index 0a86c1bf8e87f..7532b1cc81fb2 100644 --- a/solution/0900-0999/0982.Triples with Bitwise AND Equal To Zero/README.md +++ b/solution/0900-0999/0982.Triples with Bitwise AND Equal To Zero/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def countTriplets(self, nums: List[int]) -> int: @@ -91,6 +93,8 @@ class Solution: return sum(v for xy, v in cnt.items() for z in nums if xy & z == 0) ``` +#### Java + ```java class Solution { public int countTriplets(int[] nums) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func countTriplets(nums []int) (ans int) { mx := slices.Max(nums) @@ -162,6 +170,8 @@ func countTriplets(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function countTriplets(nums: number[]): number { const mx = Math.max(...nums); diff --git a/solution/0900-0999/0982.Triples with Bitwise AND Equal To Zero/README_EN.md b/solution/0900-0999/0982.Triples with Bitwise AND Equal To Zero/README_EN.md index 7b7b77192f6ce..fb181a23c91e7 100644 --- a/solution/0900-0999/0982.Triples with Bitwise AND Equal To Zero/README_EN.md +++ b/solution/0900-0999/0982.Triples with Bitwise AND Equal To Zero/README_EN.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def countTriplets(self, nums: List[int]) -> int: @@ -82,6 +84,8 @@ class Solution: return sum(v for xy, v in cnt.items() for z in nums if xy & z == 0) ``` +#### Java + ```java class Solution { public int countTriplets(int[] nums) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func countTriplets(nums []int) (ans int) { mx := slices.Max(nums) @@ -153,6 +161,8 @@ func countTriplets(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function countTriplets(nums: number[]): number { const mx = Math.max(...nums); diff --git a/solution/0900-0999/0983.Minimum Cost For Tickets/README.md b/solution/0900-0999/0983.Minimum Cost For Tickets/README.md index 321c5e759c43b..eaf0c164c0e4d 100644 --- a/solution/0900-0999/0983.Minimum Cost For Tickets/README.md +++ b/solution/0900-0999/0983.Minimum Cost For Tickets/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def mincostTickets(self, days: List[int], costs: List[int]) -> int: @@ -102,6 +104,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private static final int[] T = new int[] {1, 7, 30}; @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -182,6 +188,8 @@ public: }; ``` +#### Go + ```go func mincostTickets(days []int, costs []int) int { t := []int{1, 7, 30} @@ -223,6 +231,8 @@ func lowerBound(arr []int, x int) int { } ``` +#### TypeScript + ```ts function mincostTickets(days: number[], costs: number[]): number { const n = days.length, diff --git a/solution/0900-0999/0983.Minimum Cost For Tickets/README_EN.md b/solution/0900-0999/0983.Minimum Cost For Tickets/README_EN.md index 37d11f50bcbb1..3708098a28c79 100644 --- a/solution/0900-0999/0983.Minimum Cost For Tickets/README_EN.md +++ b/solution/0900-0999/0983.Minimum Cost For Tickets/README_EN.md @@ -80,6 +80,8 @@ In total, you spent $17 and covered all the days of your travel. +#### Python3 + ```python class Solution: def mincostTickets(self, days: List[int], costs: List[int]) -> int: @@ -96,6 +98,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private static final int[] T = new int[] {1, 7, 30}; @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go func mincostTickets(days []int, costs []int) int { t := []int{1, 7, 30} @@ -217,6 +225,8 @@ func lowerBound(arr []int, x int) int { } ``` +#### TypeScript + ```ts function mincostTickets(days: number[], costs: number[]): number { const n = days.length, diff --git a/solution/0900-0999/0984.String Without AAA or BBB/README.md b/solution/0900-0999/0984.String Without AAA or BBB/README.md index a3833675b4752..2d9306c9be7e5 100644 --- a/solution/0900-0999/0984.String Without AAA or BBB/README.md +++ b/solution/0900-0999/0984.String Without AAA or BBB/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def strWithout3a3b(self, a: int, b: int) -> str: @@ -92,6 +94,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String strWithout3a3b(int a, int b) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func strWithout3a3b(a int, b int) string { var ans strings.Builder diff --git a/solution/0900-0999/0984.String Without AAA or BBB/README_EN.md b/solution/0900-0999/0984.String Without AAA or BBB/README_EN.md index d56cbc82d12f4..613318d1fb974 100644 --- a/solution/0900-0999/0984.String Without AAA or BBB/README_EN.md +++ b/solution/0900-0999/0984.String Without AAA or BBB/README_EN.md @@ -59,6 +59,8 @@ tags: +#### Python3 + ```python class Solution: def strWithout3a3b(self, a: int, b: int) -> str: @@ -80,6 +82,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String strWithout3a3b(int a, int b) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func strWithout3a3b(a int, b int) string { var ans strings.Builder diff --git a/solution/0900-0999/0985.Sum of Even Numbers After Queries/README.md b/solution/0900-0999/0985.Sum of Even Numbers After Queries/README.md index d8fcbb775e68c..16cc6bfeaaa40 100644 --- a/solution/0900-0999/0985.Sum of Even Numbers After Queries/README.md +++ b/solution/0900-0999/0985.Sum of Even Numbers After Queries/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def sumEvenAfterQueries( @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] sumEvenAfterQueries(int[] nums, int[][] queries) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func sumEvenAfterQueries(nums []int, queries [][]int) (ans []int) { s := 0 @@ -166,6 +174,8 @@ func sumEvenAfterQueries(nums []int, queries [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function sumEvenAfterQueries(nums: number[], queries: number[][]): number[] { let s = 0; @@ -189,6 +199,8 @@ function sumEvenAfterQueries(nums: number[], queries: number[][]): number[] { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0900-0999/0985.Sum of Even Numbers After Queries/README_EN.md b/solution/0900-0999/0985.Sum of Even Numbers After Queries/README_EN.md index 2cce3c49c8c05..5c08d05855eba 100644 --- a/solution/0900-0999/0985.Sum of Even Numbers After Queries/README_EN.md +++ b/solution/0900-0999/0985.Sum of Even Numbers After Queries/README_EN.md @@ -64,6 +64,8 @@ After adding 2 to nums[3], the array is [-2,-1,3,6], and the sum of even values +#### Python3 + ```python class Solution: def sumEvenAfterQueries( @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] sumEvenAfterQueries(int[] nums, int[][] queries) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func sumEvenAfterQueries(nums []int, queries [][]int) (ans []int) { s := 0 @@ -159,6 +167,8 @@ func sumEvenAfterQueries(nums []int, queries [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function sumEvenAfterQueries(nums: number[], queries: number[][]): number[] { let s = 0; @@ -182,6 +192,8 @@ function sumEvenAfterQueries(nums: number[], queries: number[][]): number[] { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/0900-0999/0986.Interval List Intersections/README.md b/solution/0900-0999/0986.Interval List Intersections/README.md index 6047c52868be4..ff3389b472d2b 100644 --- a/solution/0900-0999/0986.Interval List Intersections/README.md +++ b/solution/0900-0999/0986.Interval List Intersections/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def intervalIntersection( @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] intervalIntersection(int[][] firstList, int[][] secondList) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func intervalIntersection(firstList [][]int, secondList [][]int) [][]int { m, n := len(firstList), len(secondList) @@ -159,6 +167,8 @@ func intervalIntersection(firstList [][]int, secondList [][]int) [][]int { } ``` +#### TypeScript + ```ts function intervalIntersection(firstList: number[][], secondList: number[][]): number[][] { const n = firstList.length; @@ -182,6 +192,8 @@ function intervalIntersection(firstList: number[][], secondList: number[][]): nu } ``` +#### Rust + ```rust impl Solution { pub fn interval_intersection( diff --git a/solution/0900-0999/0986.Interval List Intersections/README_EN.md b/solution/0900-0999/0986.Interval List Intersections/README_EN.md index 03699daeb893a..c3473754cead1 100644 --- a/solution/0900-0999/0986.Interval List Intersections/README_EN.md +++ b/solution/0900-0999/0986.Interval List Intersections/README_EN.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def intervalIntersection( @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] intervalIntersection(int[][] firstList, int[][] secondList) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func intervalIntersection(firstList [][]int, secondList [][]int) [][]int { m, n := len(firstList), len(secondList) @@ -143,6 +151,8 @@ func intervalIntersection(firstList [][]int, secondList [][]int) [][]int { } ``` +#### TypeScript + ```ts function intervalIntersection(firstList: number[][], secondList: number[][]): number[][] { const n = firstList.length; @@ -166,6 +176,8 @@ function intervalIntersection(firstList: number[][], secondList: number[][]): nu } ``` +#### Rust + ```rust impl Solution { pub fn interval_intersection( diff --git a/solution/0900-0999/0987.Vertical Order Traversal of a Binary Tree/README.md b/solution/0900-0999/0987.Vertical Order Traversal of a Binary Tree/README.md index abbbeacafd732..337a8b4dd3878 100644 --- a/solution/0900-0999/0987.Vertical Order Traversal of a Binary Tree/README.md +++ b/solution/0900-0999/0987.Vertical Order Traversal of a Binary Tree/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -120,6 +122,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -175,6 +179,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -215,6 +221,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -253,6 +261,8 @@ func verticalTraversal(root *TreeNode) (ans [][]int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0900-0999/0987.Vertical Order Traversal of a Binary Tree/README_EN.md b/solution/0900-0999/0987.Vertical Order Traversal of a Binary Tree/README_EN.md index 461184cb4249c..db0f5cbf9c704 100644 --- a/solution/0900-0999/0987.Vertical Order Traversal of a Binary Tree/README_EN.md +++ b/solution/0900-0999/0987.Vertical Order Traversal of a Binary Tree/README_EN.md @@ -90,6 +90,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -119,6 +121,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -174,6 +178,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -214,6 +220,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -252,6 +260,8 @@ func verticalTraversal(root *TreeNode) (ans [][]int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0900-0999/0988.Smallest String Starting From Leaf/README.md b/solution/0900-0999/0988.Smallest String Starting From Leaf/README.md index e4f41b3169a34..728e66f88611c 100644 --- a/solution/0900-0999/0988.Smallest String Starting From Leaf/README.md +++ b/solution/0900-0999/0988.Smallest String Starting From Leaf/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -109,6 +111,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -191,6 +197,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0900-0999/0988.Smallest String Starting From Leaf/README_EN.md b/solution/0900-0999/0988.Smallest String Starting From Leaf/README_EN.md index 79dcae1e44004..9807e23115882 100644 --- a/solution/0900-0999/0988.Smallest String Starting From Leaf/README_EN.md +++ b/solution/0900-0999/0988.Smallest String Starting From Leaf/README_EN.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -178,6 +184,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/0900-0999/0989.Add to Array-Form of Integer/README.md b/solution/0900-0999/0989.Add to Array-Form of Integer/README.md index 2c64825a4f6b4..4fd9b4c813827 100644 --- a/solution/0900-0999/0989.Add to Array-Form of Integer/README.md +++ b/solution/0900-0999/0989.Add to Array-Form of Integer/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def addToArrayForm(self, num: List[int], k: int) -> List[int]: @@ -89,6 +91,8 @@ class Solution: return ans[::-1] ``` +#### Java + ```java class Solution { public List addToArrayForm(int[] num, int k) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func addToArrayForm(num []int, k int) []int { i, carry := len(num)-1, 0 @@ -143,6 +151,8 @@ func addToArrayForm(num []int, k int) []int { } ``` +#### TypeScript + ```ts function addToArrayForm(num: number[], k: number): number[] { let arr2 = [...String(k)].map(Number); @@ -159,6 +169,8 @@ function addToArrayForm(num: number[], k: number): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn add_to_array_form(num: Vec, mut k: i32) -> Vec { @@ -191,6 +203,8 @@ impl Solution { +#### TypeScript + ```ts function addToArrayForm(num: number[], k: number): number[] { const n = num.length; diff --git a/solution/0900-0999/0989.Add to Array-Form of Integer/README_EN.md b/solution/0900-0999/0989.Add to Array-Form of Integer/README_EN.md index fcebbd5ad3b12..3e8c25c9fe657 100644 --- a/solution/0900-0999/0989.Add to Array-Form of Integer/README_EN.md +++ b/solution/0900-0999/0989.Add to Array-Form of Integer/README_EN.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def addToArrayForm(self, num: List[int], k: int) -> List[int]: @@ -84,6 +86,8 @@ class Solution: return ans[::-1] ``` +#### Java + ```java class Solution { public List addToArrayForm(int[] num, int k) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func addToArrayForm(num []int, k int) []int { i, carry := len(num)-1, 0 @@ -138,6 +146,8 @@ func addToArrayForm(num []int, k int) []int { } ``` +#### TypeScript + ```ts function addToArrayForm(num: number[], k: number): number[] { let arr2 = [...String(k)].map(Number); @@ -154,6 +164,8 @@ function addToArrayForm(num: number[], k: number): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn add_to_array_form(num: Vec, mut k: i32) -> Vec { @@ -186,6 +198,8 @@ impl Solution { +#### TypeScript + ```ts function addToArrayForm(num: number[], k: number): number[] { const n = num.length; diff --git a/solution/0900-0999/0990.Satisfiability of Equality Equations/README.md b/solution/0900-0999/0990.Satisfiability of Equality Equations/README.md index f523b92f6afa4..96d317269500b 100644 --- a/solution/0900-0999/0990.Satisfiability of Equality Equations/README.md +++ b/solution/0900-0999/0990.Satisfiability of Equality Equations/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def equationsPossible(self, equations: List[str]) -> bool: @@ -102,6 +104,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { private int[] p; @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func equationsPossible(equations []string) bool { p := make([]int, 26) @@ -190,6 +198,8 @@ func equationsPossible(equations []string) bool { } ``` +#### TypeScript + ```ts class UnionFind { private parent: number[]; diff --git a/solution/0900-0999/0990.Satisfiability of Equality Equations/README_EN.md b/solution/0900-0999/0990.Satisfiability of Equality Equations/README_EN.md index eddddbaf3f618..21697c13ea839 100644 --- a/solution/0900-0999/0990.Satisfiability of Equality Equations/README_EN.md +++ b/solution/0900-0999/0990.Satisfiability of Equality Equations/README_EN.md @@ -63,6 +63,8 @@ There is no way to assign the variables to satisfy both equations. +#### Python3 + ```python class Solution: def equationsPossible(self, equations: List[str]) -> bool: @@ -83,6 +85,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { private int[] p; @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func equationsPossible(equations []string) bool { p := make([]int, 26) @@ -171,6 +179,8 @@ func equationsPossible(equations []string) bool { } ``` +#### TypeScript + ```ts class UnionFind { private parent: number[]; diff --git a/solution/0900-0999/0991.Broken Calculator/README.md b/solution/0900-0999/0991.Broken Calculator/README.md index ee4f4e761e724..c87a703ac0728 100644 --- a/solution/0900-0999/0991.Broken Calculator/README.md +++ b/solution/0900-0999/0991.Broken Calculator/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def brokenCalc(self, startValue: int, target: int) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int brokenCalc(int startValue, int target) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func brokenCalc(startValue int, target int) (ans int) { for startValue < target { diff --git a/solution/0900-0999/0991.Broken Calculator/README_EN.md b/solution/0900-0999/0991.Broken Calculator/README_EN.md index 3047108a747d1..c30183b147852 100644 --- a/solution/0900-0999/0991.Broken Calculator/README_EN.md +++ b/solution/0900-0999/0991.Broken Calculator/README_EN.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def brokenCalc(self, startValue: int, target: int) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int brokenCalc(int startValue, int target) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func brokenCalc(startValue int, target int) (ans int) { for startValue < target { diff --git a/solution/0900-0999/0992.Subarrays with K Different Integers/README.md b/solution/0900-0999/0992.Subarrays with K Different Integers/README.md index 1d3a12a7a175b..bc1dd8c70fe9d 100644 --- a/solution/0900-0999/0992.Subarrays with K Different Integers/README.md +++ b/solution/0900-0999/0992.Subarrays with K Different Integers/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def subarraysWithKDistinct(self, nums: List[int], k: int) -> int: @@ -94,6 +96,8 @@ class Solution: return sum(a - b for a, b in zip(f(k - 1), f(k))) ``` +#### Java + ```java class Solution { public int subarraysWithKDistinct(int[] nums, int k) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func subarraysWithKDistinct(nums []int, k int) (ans int) { f := func(k int) []int { diff --git a/solution/0900-0999/0992.Subarrays with K Different Integers/README_EN.md b/solution/0900-0999/0992.Subarrays with K Different Integers/README_EN.md index 876e2820d67a9..611b4f176a089 100644 --- a/solution/0900-0999/0992.Subarrays with K Different Integers/README_EN.md +++ b/solution/0900-0999/0992.Subarrays with K Different Integers/README_EN.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def subarraysWithKDistinct(self, nums: List[int], k: int) -> int: @@ -84,6 +86,8 @@ class Solution: return sum(a - b for a, b in zip(f(k - 1), f(k))) ``` +#### Java + ```java class Solution { public int subarraysWithKDistinct(int[] nums, int k) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func subarraysWithKDistinct(nums []int, k int) (ans int) { f := func(k int) []int { diff --git a/solution/0900-0999/0993.Cousins in Binary Tree/README.md b/solution/0900-0999/0993.Cousins in Binary Tree/README.md index d1143e1ce7000..99b96eb3bc412 100644 --- a/solution/0900-0999/0993.Cousins in Binary Tree/README.md +++ b/solution/0900-0999/0993.Cousins in Binary Tree/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -110,6 +112,8 @@ class Solution: return p1 != p2 and d1 == d2 ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -156,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -199,6 +205,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -234,6 +242,8 @@ func isCousins(root *TreeNode, x int, y int) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -292,6 +302,8 @@ function isCousins(root: TreeNode | null, x: number, y: number): boolean { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -316,6 +328,8 @@ class Solution: return st[0][0] != st[1][0] and st[0][1] == st[1][1] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -361,6 +375,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -399,6 +415,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -429,6 +447,8 @@ func isCousins(root *TreeNode, x int, y int) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0900-0999/0993.Cousins in Binary Tree/README_EN.md b/solution/0900-0999/0993.Cousins in Binary Tree/README_EN.md index ee00057543456..03c4bd2618b99 100644 --- a/solution/0900-0999/0993.Cousins in Binary Tree/README_EN.md +++ b/solution/0900-0999/0993.Cousins in Binary Tree/README_EN.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -96,6 +98,8 @@ class Solution: return p1 != p2 and d1 == d2 ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -185,6 +191,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -220,6 +228,8 @@ func isCousins(root *TreeNode, x int, y int) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -270,6 +280,8 @@ function isCousins(root: TreeNode | null, x: number, y: number): boolean { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -294,6 +306,8 @@ class Solution: return st[0][0] != st[1][0] and st[0][1] == st[1][1] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -339,6 +353,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -377,6 +393,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -407,6 +425,8 @@ func isCousins(root *TreeNode, x int, y int) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0900-0999/0994.Rotting Oranges/README.md b/solution/0900-0999/0994.Rotting Oranges/README.md index 00c570ea98ecb..e074253a68af2 100644 --- a/solution/0900-0999/0994.Rotting Oranges/README.md +++ b/solution/0900-0999/0994.Rotting Oranges/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def orangesRotting(self, grid: List[List[int]]) -> int: @@ -113,6 +115,8 @@ class Solution: return -1 if cnt > 0 else ans ``` +#### Java + ```java class Solution { public int orangesRotting(int[][] grid) { @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -185,6 +191,8 @@ public: }; ``` +#### Go + ```go func orangesRotting(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -221,6 +229,8 @@ func orangesRotting(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function orangesRotting(grid: number[][]): number { const m: number = grid.length; @@ -256,6 +266,8 @@ function orangesRotting(grid: number[][]): number { } ``` +#### Rust + ```rust use std::collections::VecDeque; diff --git a/solution/0900-0999/0994.Rotting Oranges/README_EN.md b/solution/0900-0999/0994.Rotting Oranges/README_EN.md index 4ab7ac3295780..b568baabad481 100644 --- a/solution/0900-0999/0994.Rotting Oranges/README_EN.md +++ b/solution/0900-0999/0994.Rotting Oranges/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def orangesRotting(self, grid: List[List[int]]) -> int: @@ -109,6 +111,8 @@ class Solution: return -1 if cnt > 0 else ans ``` +#### Java + ```java class Solution { public int orangesRotting(int[][] grid) { @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func orangesRotting(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -217,6 +225,8 @@ func orangesRotting(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function orangesRotting(grid: number[][]): number { const m: number = grid.length; @@ -252,6 +262,8 @@ function orangesRotting(grid: number[][]): number { } ``` +#### Rust + ```rust use std::collections::VecDeque; diff --git a/solution/0900-0999/0995.Minimum Number of K Consecutive Bit Flips/README.md b/solution/0900-0999/0995.Minimum Number of K Consecutive Bit Flips/README.md index 65af7d2101a9c..97dab4cef3f03 100644 --- a/solution/0900-0999/0995.Minimum Number of K Consecutive Bit Flips/README.md +++ b/solution/0900-0999/0995.Minimum Number of K Consecutive Bit Flips/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def minKBitFlips(self, nums: List[int], k: int) -> int: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minKBitFlips(int[] nums, int k) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func minKBitFlips(nums []int, k int) int { n := len(nums) @@ -173,6 +181,8 @@ func minKBitFlips(nums []int, k int) int { } ``` +#### TypeScript + ```ts function minKBitFlips(nums: number[], k: number): number { const n = nums.length; @@ -194,6 +204,8 @@ function minKBitFlips(nums: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_k_bit_flips(nums: Vec, k: i32) -> i32 { diff --git a/solution/0900-0999/0995.Minimum Number of K Consecutive Bit Flips/README_EN.md b/solution/0900-0999/0995.Minimum Number of K Consecutive Bit Flips/README_EN.md index fb4aef4d86422..6df5311c19ebb 100644 --- a/solution/0900-0999/0995.Minimum Number of K Consecutive Bit Flips/README_EN.md +++ b/solution/0900-0999/0995.Minimum Number of K Consecutive Bit Flips/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def minKBitFlips(self, nums: List[int], k: int) -> int: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minKBitFlips(int[] nums, int k) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func minKBitFlips(nums []int, k int) int { n := len(nums) @@ -171,6 +179,8 @@ func minKBitFlips(nums []int, k int) int { } ``` +#### TypeScript + ```ts function minKBitFlips(nums: number[], k: number): number { const n = nums.length; @@ -192,6 +202,8 @@ function minKBitFlips(nums: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_k_bit_flips(nums: Vec, k: i32) -> i32 { diff --git a/solution/0900-0999/0996.Number of Squareful Arrays/README.md b/solution/0900-0999/0996.Number of Squareful Arrays/README.md index dc44d9e7650bc..d7a5fe0e50434 100644 --- a/solution/0900-0999/0996.Number of Squareful Arrays/README.md +++ b/solution/0900-0999/0996.Number of Squareful Arrays/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def numSquarefulPerms(self, nums: List[int]) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numSquarefulPerms(int[] nums) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -184,6 +190,8 @@ public: }; ``` +#### Go + ```go func numSquarefulPerms(nums []int) (ans int) { n := len(nums) diff --git a/solution/0900-0999/0996.Number of Squareful Arrays/README_EN.md b/solution/0900-0999/0996.Number of Squareful Arrays/README_EN.md index cc2c153b809a8..9d495c409154a 100644 --- a/solution/0900-0999/0996.Number of Squareful Arrays/README_EN.md +++ b/solution/0900-0999/0996.Number of Squareful Arrays/README_EN.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def numSquarefulPerms(self, nums: List[int]) -> int: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numSquarefulPerms(int[] nums) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go func numSquarefulPerms(nums []int) (ans int) { n := len(nums) diff --git a/solution/0900-0999/0997.Find the Town Judge/README.md b/solution/0900-0999/0997.Find the Town Judge/README.md index 04bd7c37df4e5..6fccaa41ba204 100644 --- a/solution/0900-0999/0997.Find the Town Judge/README.md +++ b/solution/0900-0999/0997.Find the Town Judge/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def findJudge(self, n: int, trust: List[List[int]]) -> int: @@ -100,6 +102,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int findJudge(int n, int[][] trust) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func findJudge(n int, trust [][]int) int { cnt1 := make([]int, n+1) @@ -159,6 +167,8 @@ func findJudge(n int, trust [][]int) int { } ``` +#### TypeScript + ```ts function findJudge(n: number, trust: number[][]): number { const cnt1: number[] = new Array(n + 1).fill(0); @@ -176,6 +186,8 @@ function findJudge(n: number, trust: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_judge(n: i32, trust: Vec>) -> i32 { diff --git a/solution/0900-0999/0997.Find the Town Judge/README_EN.md b/solution/0900-0999/0997.Find the Town Judge/README_EN.md index 5fee8b96d03dd..5f4dbb6b17689 100644 --- a/solution/0900-0999/0997.Find the Town Judge/README_EN.md +++ b/solution/0900-0999/0997.Find the Town Judge/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def findJudge(self, n: int, trust: List[List[int]]) -> int: @@ -98,6 +100,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int findJudge(int n, int[][] trust) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func findJudge(n int, trust [][]int) int { cnt1 := make([]int, n+1) @@ -157,6 +165,8 @@ func findJudge(n int, trust [][]int) int { } ``` +#### TypeScript + ```ts function findJudge(n: number, trust: number[][]): number { const cnt1: number[] = new Array(n + 1).fill(0); @@ -174,6 +184,8 @@ function findJudge(n: number, trust: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_judge(n: i32, trust: Vec>) -> i32 { diff --git a/solution/0900-0999/0998.Maximum Binary Tree II/README.md b/solution/0900-0999/0998.Maximum Binary Tree II/README.md index df8ccb6ddb277..d8ccf1a7d262b 100644 --- a/solution/0900-0999/0998.Maximum Binary Tree II/README.md +++ b/solution/0900-0999/0998.Maximum Binary Tree II/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -111,6 +113,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -178,6 +186,8 @@ func insertIntoMaxTree(root *TreeNode, val int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -202,6 +212,8 @@ function insertIntoMaxTree(root: TreeNode | null, val: number): TreeNode | null } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -248,6 +260,8 @@ impl Solution { } ``` +#### C + ```c /** * Definition for a binary tree node. @@ -287,6 +301,8 @@ struct TreeNode* insertIntoMaxTree(struct TreeNode* root, int val) { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -309,6 +325,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -342,6 +360,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -368,6 +388,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -392,6 +414,8 @@ func insertIntoMaxTree(root *TreeNode, val int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0900-0999/0998.Maximum Binary Tree II/README_EN.md b/solution/0900-0999/0998.Maximum Binary Tree II/README_EN.md index b6cda2f7a9765..10e047f6e4225 100644 --- a/solution/0900-0999/0998.Maximum Binary Tree II/README_EN.md +++ b/solution/0900-0999/0998.Maximum Binary Tree II/README_EN.md @@ -88,6 +88,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -105,6 +107,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -172,6 +180,8 @@ func insertIntoMaxTree(root *TreeNode, val int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -196,6 +206,8 @@ function insertIntoMaxTree(root: TreeNode | null, val: number): TreeNode | null } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -242,6 +254,8 @@ impl Solution { } ``` +#### C + ```c /** * Definition for a binary tree node. @@ -281,6 +295,8 @@ The time complexity is $O(n)$, where $n$ is the number of nodes in the tree. The +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -303,6 +319,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -336,6 +354,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -362,6 +382,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -386,6 +408,8 @@ func insertIntoMaxTree(root *TreeNode, val int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/0900-0999/0999.Available Captures for Rook/README.md b/solution/0900-0999/0999.Available Captures for Rook/README.md index 286d80252861f..43e1a958ef575 100644 --- a/solution/0900-0999/0999.Available Captures for Rook/README.md +++ b/solution/0900-0999/0999.Available Captures for Rook/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def numRookCaptures(self, board: List[List[str]]) -> int: @@ -113,6 +115,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numRookCaptures(char[][] board) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func numRookCaptures(board [][]byte) (ans int) { dirs := [5]int{-1, 0, 1, 0, -1} diff --git a/solution/0900-0999/0999.Available Captures for Rook/README_EN.md b/solution/0900-0999/0999.Available Captures for Rook/README_EN.md index 9aedce8c66a9d..bb7b39a4deaa9 100644 --- a/solution/0900-0999/0999.Available Captures for Rook/README_EN.md +++ b/solution/0900-0999/0999.Available Captures for Rook/README_EN.md @@ -79,6 +79,8 @@ The time complexity is $O(m \times n)$, where $m$ and $n$ are the number of rows +#### Python3 + ```python class Solution: def numRookCaptures(self, board: List[List[str]]) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numRookCaptures(char[][] board) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func numRookCaptures(board [][]byte) (ans int) { dirs := [5]int{-1, 0, 1, 0, -1} diff --git a/solution/1000-1099/1000.Minimum Cost to Merge Stones/README.md b/solution/1000-1099/1000.Minimum Cost to Merge Stones/README.md index f34c4f0154161..1efbe02200a1f 100644 --- a/solution/1000-1099/1000.Minimum Cost to Merge Stones/README.md +++ b/solution/1000-1099/1000.Minimum Cost to Merge Stones/README.md @@ -100,6 +100,8 @@ $$ +#### Python3 + ```python class Solution: def mergeStones(self, stones: List[int], K: int) -> int: @@ -120,6 +122,8 @@ class Solution: return f[1][n][1] ``` +#### Java + ```java class Solution { public int mergeStones(int[] stones, int K) { @@ -157,6 +161,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -191,6 +197,8 @@ public: }; ``` +#### Go + ```go func mergeStones(stones []int, K int) int { n := len(stones) diff --git a/solution/1000-1099/1000.Minimum Cost to Merge Stones/README_EN.md b/solution/1000-1099/1000.Minimum Cost to Merge Stones/README_EN.md index a395f6a04b364..5e4894911bd7c 100644 --- a/solution/1000-1099/1000.Minimum Cost to Merge Stones/README_EN.md +++ b/solution/1000-1099/1000.Minimum Cost to Merge Stones/README_EN.md @@ -78,6 +78,8 @@ The total cost was 25, and this is the minimum possible. +#### Python3 + ```python class Solution: def mergeStones(self, stones: List[int], K: int) -> int: @@ -98,6 +100,8 @@ class Solution: return f[1][n][1] ``` +#### Java + ```java class Solution { public int mergeStones(int[] stones, int K) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go func mergeStones(stones []int, K int) int { n := len(stones) diff --git a/solution/1000-1099/1001.Grid Illumination/README.md b/solution/1000-1099/1001.Grid Illumination/README.md index b9c35734d7382..ade460694bf2e 100644 --- a/solution/1000-1099/1001.Grid Illumination/README.md +++ b/solution/1000-1099/1001.Grid Illumination/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def gridIllumination( @@ -119,6 +121,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -177,6 +181,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -221,6 +227,8 @@ public: }; ``` +#### Go + ```go func gridIllumination(n int, lamps [][]int, queries [][]int) []int { row, col, diag1, diag2 := map[int]int{}, map[int]int{}, map[int]int{}, map[int]int{} @@ -261,6 +269,8 @@ func gridIllumination(n int, lamps [][]int, queries [][]int) []int { } ``` +#### TypeScript + ```ts function gridIllumination(n: number, lamps: number[][], queries: number[][]): number[] { const row = new Map(); diff --git a/solution/1000-1099/1001.Grid Illumination/README_EN.md b/solution/1000-1099/1001.Grid Illumination/README_EN.md index b89bb6ad9ed83..d1c7ce169b8d0 100644 --- a/solution/1000-1099/1001.Grid Illumination/README_EN.md +++ b/solution/1000-1099/1001.Grid Illumination/README_EN.md @@ -79,6 +79,8 @@ The 1st query asks if the lamp at grid[1][0] is illuminated or n +#### Python3 + ```python class Solution: def gridIllumination( @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -164,6 +168,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -208,6 +214,8 @@ public: }; ``` +#### Go + ```go func gridIllumination(n int, lamps [][]int, queries [][]int) []int { row, col, diag1, diag2 := map[int]int{}, map[int]int{}, map[int]int{}, map[int]int{} @@ -248,6 +256,8 @@ func gridIllumination(n int, lamps [][]int, queries [][]int) []int { } ``` +#### TypeScript + ```ts function gridIllumination(n: number, lamps: number[][], queries: number[][]): number[] { const row = new Map(); diff --git a/solution/1000-1099/1002.Find Common Characters/README.md b/solution/1000-1099/1002.Find Common Characters/README.md index 5b2478ff11f89..721a5102d59eb 100644 --- a/solution/1000-1099/1002.Find Common Characters/README.md +++ b/solution/1000-1099/1002.Find Common Characters/README.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def commonChars(self, words: List[str]) -> List[str]: @@ -76,6 +78,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List commonChars(String[] words) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func commonChars(words []string) (ans []string) { cnt := [26]int{} @@ -152,6 +160,8 @@ func commonChars(words []string) (ans []string) { } ``` +#### TypeScript + ```ts function commonChars(words: string[]): string[] { const freq: number[] = new Array(26).fill(10000); diff --git a/solution/1000-1099/1002.Find Common Characters/README_EN.md b/solution/1000-1099/1002.Find Common Characters/README_EN.md index cd16c75c31fc1..31da066e3c5c1 100644 --- a/solution/1000-1099/1002.Find Common Characters/README_EN.md +++ b/solution/1000-1099/1002.Find Common Characters/README_EN.md @@ -49,6 +49,8 @@ tags: +#### Python3 + ```python class Solution: def commonChars(self, words: List[str]) -> List[str]: @@ -63,6 +65,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List commonChars(String[] words) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func commonChars(words []string) (ans []string) { cnt := [26]int{} @@ -139,6 +147,8 @@ func commonChars(words []string) (ans []string) { } ``` +#### TypeScript + ```ts function commonChars(words: string[]): string[] { const freq: number[] = new Array(26).fill(10000); diff --git a/solution/1000-1099/1003.Check If Word Is Valid After Substitutions/README.md b/solution/1000-1099/1003.Check If Word Is Valid After Substitutions/README.md index 66a997d804579..e3b471d11db24 100644 --- a/solution/1000-1099/1003.Check If Word Is Valid After Substitutions/README.md +++ b/solution/1000-1099/1003.Check If Word Is Valid After Substitutions/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def isValid(self, s: str) -> bool: @@ -96,6 +98,8 @@ class Solution: return not t ``` +#### Java + ```java class Solution { public boolean isValid(String s) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func isValid(s string) bool { if len(s)%3 > 0 { @@ -149,6 +157,8 @@ func isValid(s string) bool { } ``` +#### TypeScript + ```ts function isValid(s: string): boolean { if (s.length % 3 !== 0) { diff --git a/solution/1000-1099/1003.Check If Word Is Valid After Substitutions/README_EN.md b/solution/1000-1099/1003.Check If Word Is Valid After Substitutions/README_EN.md index 557fd23a9a179..448573b651d0d 100644 --- a/solution/1000-1099/1003.Check If Word Is Valid After Substitutions/README_EN.md +++ b/solution/1000-1099/1003.Check If Word Is Valid After Substitutions/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(n)$ and the space complexity is $O(n)$. Where $n$ is t +#### Python3 + ```python class Solution: def isValid(self, s: str) -> bool: @@ -96,6 +98,8 @@ class Solution: return not t ``` +#### Java + ```java class Solution { public boolean isValid(String s) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func isValid(s string) bool { if len(s)%3 > 0 { @@ -149,6 +157,8 @@ func isValid(s string) bool { } ``` +#### TypeScript + ```ts function isValid(s: string): boolean { if (s.length % 3 !== 0) { diff --git a/solution/1000-1099/1004.Max Consecutive Ones III/README.md b/solution/1000-1099/1004.Max Consecutive Ones III/README.md index 19a42272d87d6..489ca62e596e3 100644 --- a/solution/1000-1099/1004.Max Consecutive Ones III/README.md +++ b/solution/1000-1099/1004.Max Consecutive Ones III/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def longestOnes(self, nums: List[int], k: int) -> int: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestOnes(int[] nums, int k) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func longestOnes(nums []int, k int) int { ans := 0 @@ -149,6 +157,8 @@ func longestOnes(nums []int, k int) int { } ``` +#### TypeScript + ```ts function longestOnes(nums: number[], k: number): number { const n = nums.length; @@ -186,6 +196,8 @@ function longestOnes(nums: number[], k: number): number { +#### Python3 + ```python class Solution: def longestOnes(self, nums: List[int], k: int) -> int: @@ -201,6 +213,8 @@ class Solution: return r - l ``` +#### Java + ```java class Solution { public int longestOnes(int[] nums, int k) { @@ -218,6 +232,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -232,6 +248,8 @@ public: }; ``` +#### Go + ```go func longestOnes(nums []int, k int) int { l, r := -1, -1 @@ -251,6 +269,8 @@ func longestOnes(nums []int, k int) int { } ``` +#### TypeScript + ```ts function longestOnes(nums: number[], k: number): number { const n = nums.length; @@ -267,6 +287,8 @@ function longestOnes(nums: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn longest_ones(nums: Vec, mut k: i32) -> i32 { diff --git a/solution/1000-1099/1004.Max Consecutive Ones III/README_EN.md b/solution/1000-1099/1004.Max Consecutive Ones III/README_EN.md index 76f6c3257401d..1e7fb9bdd3446 100644 --- a/solution/1000-1099/1004.Max Consecutive Ones III/README_EN.md +++ b/solution/1000-1099/1004.Max Consecutive Ones III/README_EN.md @@ -69,6 +69,8 @@ Similar problems: +#### Python3 + ```python class Solution: def longestOnes(self, nums: List[int], k: int) -> int: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestOnes(int[] nums, int k) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func longestOnes(nums []int, k int) int { ans := 0 @@ -148,6 +156,8 @@ func longestOnes(nums []int, k int) int { } ``` +#### TypeScript + ```ts function longestOnes(nums: number[], k: number): number { const n = nums.length; @@ -185,6 +195,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def longestOnes(self, nums: List[int], k: int) -> int: @@ -200,6 +212,8 @@ class Solution: return r - l ``` +#### Java + ```java class Solution { public int longestOnes(int[] nums, int k) { @@ -217,6 +231,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -231,6 +247,8 @@ public: }; ``` +#### Go + ```go func longestOnes(nums []int, k int) int { l, r := -1, -1 @@ -250,6 +268,8 @@ func longestOnes(nums []int, k int) int { } ``` +#### TypeScript + ```ts function longestOnes(nums: number[], k: number): number { const n = nums.length; @@ -266,6 +286,8 @@ function longestOnes(nums: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn longest_ones(nums: Vec, mut k: i32) -> i32 { diff --git a/solution/1000-1099/1005.Maximize Sum Of Array After K Negations/README.md b/solution/1000-1099/1005.Maximize Sum Of Array After K Negations/README.md index 9bae507981540..271e19bc69d63 100644 --- a/solution/1000-1099/1005.Maximize Sum Of Array After K Negations/README.md +++ b/solution/1000-1099/1005.Maximize Sum Of Array After K Negations/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def largestSumAfterKNegations(self, nums: List[int], k: int) -> int: @@ -107,6 +109,8 @@ class Solution: return sum(x * v for x, v in cnt.items()) ``` +#### Java + ```java class Solution { public int largestSumAfterKNegations(int[] nums, int k) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func largestSumAfterKNegations(nums []int, k int) (ans int) { cnt := map[int]int{} @@ -204,6 +212,8 @@ func largestSumAfterKNegations(nums []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function largestSumAfterKNegations(nums: number[], k: number): number { const cnt: Map = new Map(); diff --git a/solution/1000-1099/1005.Maximize Sum Of Array After K Negations/README_EN.md b/solution/1000-1099/1005.Maximize Sum Of Array After K Negations/README_EN.md index a349e3c5f29a7..6597e0690bc4c 100644 --- a/solution/1000-1099/1005.Maximize Sum Of Array After K Negations/README_EN.md +++ b/solution/1000-1099/1005.Maximize Sum Of Array After K Negations/README_EN.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def largestSumAfterKNegations(self, nums: List[int], k: int) -> int: @@ -95,6 +97,8 @@ class Solution: return sum(x * v for x, v in cnt.items()) ``` +#### Java + ```java class Solution { public int largestSumAfterKNegations(int[] nums, int k) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func largestSumAfterKNegations(nums []int, k int) (ans int) { cnt := map[int]int{} @@ -192,6 +200,8 @@ func largestSumAfterKNegations(nums []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function largestSumAfterKNegations(nums: number[], k: number): number { const cnt: Map = new Map(); diff --git a/solution/1000-1099/1006.Clumsy Factorial/README.md b/solution/1000-1099/1006.Clumsy Factorial/README.md index 48e9e4f8020dc..7c9c15b6d1845 100644 --- a/solution/1000-1099/1006.Clumsy Factorial/README.md +++ b/solution/1000-1099/1006.Clumsy Factorial/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def clumsy(self, N: int) -> int: @@ -83,6 +85,8 @@ class Solution: return sum(s) ``` +#### Java + ```java class Solution { public int clumsy(int N) { diff --git a/solution/1000-1099/1006.Clumsy Factorial/README_EN.md b/solution/1000-1099/1006.Clumsy Factorial/README_EN.md index 9cb7aa3701940..7b00297d44d26 100644 --- a/solution/1000-1099/1006.Clumsy Factorial/README_EN.md +++ b/solution/1000-1099/1006.Clumsy Factorial/README_EN.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def clumsy(self, N: int) -> int: @@ -90,6 +92,8 @@ class Solution: return sum(s) ``` +#### Java + ```java class Solution { public int clumsy(int N) { diff --git a/solution/1000-1099/1007.Minimum Domino Rotations For Equal Row/README.md b/solution/1000-1099/1007.Minimum Domino Rotations For Equal Row/README.md index a55506e65ef60..a8055d4e5e1ae 100644 --- a/solution/1000-1099/1007.Minimum Domino Rotations For Equal Row/README.md +++ b/solution/1000-1099/1007.Minimum Domino Rotations For Equal Row/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def minDominoRotations(self, tops: List[int], bottoms: List[int]) -> int: @@ -93,6 +95,8 @@ class Solution: return -1 if ans == inf else ans ``` +#### Java + ```java class Solution { private int n; @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func minDominoRotations(tops []int, bottoms []int) int { n := len(tops) @@ -170,6 +178,8 @@ func minDominoRotations(tops []int, bottoms []int) int { } ``` +#### TypeScript + ```ts function minDominoRotations(tops: number[], bottoms: number[]): number { const n = tops.length; diff --git a/solution/1000-1099/1007.Minimum Domino Rotations For Equal Row/README_EN.md b/solution/1000-1099/1007.Minimum Domino Rotations For Equal Row/README_EN.md index 87b8f17f54da3..dee8984a30009 100644 --- a/solution/1000-1099/1007.Minimum Domino Rotations For Equal Row/README_EN.md +++ b/solution/1000-1099/1007.Minimum Domino Rotations For Equal Row/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def minDominoRotations(self, tops: List[int], bottoms: List[int]) -> int: @@ -92,6 +94,8 @@ class Solution: return -1 if ans == inf else ans ``` +#### Java + ```java class Solution { private int n; @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func minDominoRotations(tops []int, bottoms []int) int { n := len(tops) @@ -169,6 +177,8 @@ func minDominoRotations(tops []int, bottoms []int) int { } ``` +#### TypeScript + ```ts function minDominoRotations(tops: number[], bottoms: number[]): number { const n = tops.length; diff --git a/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/README.md b/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/README.md index 8d63367ece028..3f4a31b099eba 100644 --- a/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/README.md +++ b/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -98,6 +100,8 @@ class Solution: return dfs(preorder) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -210,6 +218,8 @@ func bstFromPreorder(preorder []int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -247,6 +257,8 @@ function bstFromPreorder(preorder: number[]): TreeNode | null { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/README_EN.md b/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/README_EN.md index 69df9f368968e..a51257309b110 100644 --- a/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/README_EN.md +++ b/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -92,6 +94,8 @@ class Solution: return dfs(preorder) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -204,6 +212,8 @@ func bstFromPreorder(preorder []int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -241,6 +251,8 @@ function bstFromPreorder(preorder: number[]): TreeNode | null { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/1000-1099/1009.Complement of Base 10 Integer/README.md b/solution/1000-1099/1009.Complement of Base 10 Integer/README.md index 49b0f32e9e5de..d1a8fadb62e95 100644 --- a/solution/1000-1099/1009.Complement of Base 10 Integer/README.md +++ b/solution/1000-1099/1009.Complement of Base 10 Integer/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def bitwiseComplement(self, n: int) -> int: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int bitwiseComplement(int n) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func bitwiseComplement(n int) int { if n == 0 { diff --git a/solution/1000-1099/1009.Complement of Base 10 Integer/README_EN.md b/solution/1000-1099/1009.Complement of Base 10 Integer/README_EN.md index d2b0748ec3b0b..beee92dae68bd 100644 --- a/solution/1000-1099/1009.Complement of Base 10 Integer/README_EN.md +++ b/solution/1000-1099/1009.Complement of Base 10 Integer/README_EN.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def bitwiseComplement(self, n: int) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int bitwiseComplement(int n) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func bitwiseComplement(n int) int { if n == 0 { diff --git a/solution/1000-1099/1010.Pairs of Songs With Total Durations Divisible by 60/README.md b/solution/1000-1099/1010.Pairs of Songs With Total Durations Divisible by 60/README.md index 10129982224ec..b82dd2812814f 100644 --- a/solution/1000-1099/1010.Pairs of Songs With Total Durations Divisible by 60/README.md +++ b/solution/1000-1099/1010.Pairs of Songs With Total Durations Divisible by 60/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def numPairsDivisibleBy60(self, time: List[int]) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numPairsDivisibleBy60(int[] time) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func numPairsDivisibleBy60(time []int) (ans int) { cnt := [60]int{} @@ -134,6 +142,8 @@ func numPairsDivisibleBy60(time []int) (ans int) { } ``` +#### TypeScript + ```ts function numPairsDivisibleBy60(time: number[]): number { const cnt: number[] = new Array(60).fill(0); @@ -160,6 +170,8 @@ function numPairsDivisibleBy60(time: number[]): number { +#### Python3 + ```python class Solution: def numPairsDivisibleBy60(self, time: List[int]) -> int: @@ -173,6 +185,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numPairsDivisibleBy60(int[] time) { @@ -189,6 +203,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -206,6 +222,8 @@ public: }; ``` +#### Go + ```go func numPairsDivisibleBy60(time []int) (ans int) { cnt := [60]int{} @@ -219,6 +237,8 @@ func numPairsDivisibleBy60(time []int) (ans int) { } ``` +#### TypeScript + ```ts function numPairsDivisibleBy60(time: number[]): number { const cnt: number[] = new Array(60).fill(0); diff --git a/solution/1000-1099/1010.Pairs of Songs With Total Durations Divisible by 60/README_EN.md b/solution/1000-1099/1010.Pairs of Songs With Total Durations Divisible by 60/README_EN.md index 62caf61adba94..0eff889dd040a 100644 --- a/solution/1000-1099/1010.Pairs of Songs With Total Durations Divisible by 60/README_EN.md +++ b/solution/1000-1099/1010.Pairs of Songs With Total Durations Divisible by 60/README_EN.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def numPairsDivisibleBy60(self, time: List[int]) -> int: @@ -72,6 +74,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numPairsDivisibleBy60(int[] time) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func numPairsDivisibleBy60(time []int) (ans int) { cnt := [60]int{} @@ -124,6 +132,8 @@ func numPairsDivisibleBy60(time []int) (ans int) { } ``` +#### TypeScript + ```ts function numPairsDivisibleBy60(time: number[]): number { const cnt: number[] = new Array(60).fill(0); @@ -150,6 +160,8 @@ function numPairsDivisibleBy60(time: number[]): number { +#### Python3 + ```python class Solution: def numPairsDivisibleBy60(self, time: List[int]) -> int: @@ -163,6 +175,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numPairsDivisibleBy60(int[] time) { @@ -179,6 +193,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -196,6 +212,8 @@ public: }; ``` +#### Go + ```go func numPairsDivisibleBy60(time []int) (ans int) { cnt := [60]int{} @@ -209,6 +227,8 @@ func numPairsDivisibleBy60(time []int) (ans int) { } ``` +#### TypeScript + ```ts function numPairsDivisibleBy60(time: number[]): number { const cnt: number[] = new Array(60).fill(0); diff --git a/solution/1000-1099/1011.Capacity To Ship Packages Within D Days/README.md b/solution/1000-1099/1011.Capacity To Ship Packages Within D Days/README.md index b1ebd684caba1..c2463d26aac26 100644 --- a/solution/1000-1099/1011.Capacity To Ship Packages Within D Days/README.md +++ b/solution/1000-1099/1011.Capacity To Ship Packages Within D Days/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class Solution: def shipWithinDays(self, weights: List[int], days: int) -> int: @@ -110,6 +112,8 @@ class Solution: return left + bisect_left(range(left, right), True, key=check) ``` +#### Java + ```java class Solution { public int shipWithinDays(int[] weights, int days) { @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go func shipWithinDays(weights []int, days int) int { var left, right int @@ -200,6 +208,8 @@ func shipWithinDays(weights []int, days int) int { } ``` +#### TypeScript + ```ts function shipWithinDays(weights: number[], days: number): number { let left = 0; diff --git a/solution/1000-1099/1011.Capacity To Ship Packages Within D Days/README_EN.md b/solution/1000-1099/1011.Capacity To Ship Packages Within D Days/README_EN.md index 9b6dc70e3298b..7a5453ca84296 100644 --- a/solution/1000-1099/1011.Capacity To Ship Packages Within D Days/README_EN.md +++ b/solution/1000-1099/1011.Capacity To Ship Packages Within D Days/README_EN.md @@ -82,6 +82,8 @@ Note that the cargo must be shipped in the order given, so using a ship of capac +#### Python3 + ```python class Solution: def shipWithinDays(self, weights: List[int], days: int) -> int: @@ -98,6 +100,8 @@ class Solution: return left + bisect_left(range(left, right), True, key=check) ``` +#### Java + ```java class Solution { public int shipWithinDays(int[] weights, int days) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func shipWithinDays(weights []int, days int) int { var left, right int @@ -188,6 +196,8 @@ func shipWithinDays(weights []int, days int) int { } ``` +#### TypeScript + ```ts function shipWithinDays(weights: number[], days: number): number { let left = 0; diff --git a/solution/1000-1099/1012.Numbers With Repeated Digits/README.md b/solution/1000-1099/1012.Numbers With Repeated Digits/README.md index 1bd78847e9991..c735405c06e05 100644 --- a/solution/1000-1099/1012.Numbers With Repeated Digits/README.md +++ b/solution/1000-1099/1012.Numbers With Repeated Digits/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python class Solution: def numDupDigitsAtMostN(self, n: int) -> int: @@ -125,6 +127,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numDupDigitsAtMostN(int n) { @@ -168,6 +172,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -211,6 +217,8 @@ public: }; ``` +#### Go + ```go func numDupDigitsAtMostN(n int) int { return n - f(n) @@ -258,6 +266,8 @@ func A(m, n int) int { } ``` +#### TypeScript + ```ts function numDupDigitsAtMostN(n: number): number { return n - f(n); @@ -308,6 +318,8 @@ function f(n: number): number { +#### Python3 + ```python class Solution: def numDupDigitsAtMostN(self, n: int) -> int: @@ -336,6 +348,8 @@ class Solution: return dfs(len(nums) - 1, 0, True, True) ``` +#### Java + ```java class Solution { private int[] nums = new int[11]; @@ -380,6 +394,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -427,6 +443,8 @@ private: }; ``` +#### Go + ```go func numDupDigitsAtMostN(n int) int { return n - f(n) diff --git a/solution/1000-1099/1012.Numbers With Repeated Digits/README_EN.md b/solution/1000-1099/1012.Numbers With Repeated Digits/README_EN.md index 3764500d83257..75d0d1f85a092 100644 --- a/solution/1000-1099/1012.Numbers With Repeated Digits/README_EN.md +++ b/solution/1000-1099/1012.Numbers With Repeated Digits/README_EN.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def numDupDigitsAtMostN(self, n: int) -> int: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numDupDigitsAtMostN(int n) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -178,6 +184,8 @@ public: }; ``` +#### Go + ```go func numDupDigitsAtMostN(n int) int { return n - f(n) @@ -225,6 +233,8 @@ func A(m, n int) int { } ``` +#### TypeScript + ```ts function numDupDigitsAtMostN(n: number): number { return n - f(n); @@ -275,6 +285,8 @@ function f(n: number): number { +#### Python3 + ```python class Solution: def numDupDigitsAtMostN(self, n: int) -> int: @@ -303,6 +315,8 @@ class Solution: return dfs(len(nums) - 1, 0, True, True) ``` +#### Java + ```java class Solution { private int[] nums = new int[11]; @@ -347,6 +361,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -394,6 +410,8 @@ private: }; ``` +#### Go + ```go func numDupDigitsAtMostN(n int) int { return n - f(n) diff --git a/solution/1000-1099/1013.Partition Array Into Three Parts With Equal Sum/README.md b/solution/1000-1099/1013.Partition Array Into Three Parts With Equal Sum/README.md index 7a2a72f84d311..03701c1b6bc04 100644 --- a/solution/1000-1099/1013.Partition Array Into Three Parts With Equal Sum/README.md +++ b/solution/1000-1099/1013.Partition Array Into Three Parts With Equal Sum/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def canThreePartsEqualSum(self, arr: List[int]) -> bool: @@ -94,6 +96,8 @@ class Solution: return i < j - 1 ``` +#### Java + ```java class Solution { public boolean canThreePartsEqualSum(int[] arr) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func canThreePartsEqualSum(arr []int) bool { s := 0 diff --git a/solution/1000-1099/1013.Partition Array Into Three Parts With Equal Sum/README_EN.md b/solution/1000-1099/1013.Partition Array Into Three Parts With Equal Sum/README_EN.md index f56cd07b45f46..11d0de73f21c4 100644 --- a/solution/1000-1099/1013.Partition Array Into Three Parts With Equal Sum/README_EN.md +++ b/solution/1000-1099/1013.Partition Array Into Three Parts With Equal Sum/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def canThreePartsEqualSum(self, arr: List[int]) -> bool: @@ -86,6 +88,8 @@ class Solution: return i < j - 1 ``` +#### Java + ```java class Solution { public boolean canThreePartsEqualSum(int[] arr) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func canThreePartsEqualSum(arr []int) bool { s := 0 diff --git a/solution/1000-1099/1014.Best Sightseeing Pair/README.md b/solution/1000-1099/1014.Best Sightseeing Pair/README.md index 1082bdc9506d5..232e8f6fbdb6c 100644 --- a/solution/1000-1099/1014.Best Sightseeing Pair/README.md +++ b/solution/1000-1099/1014.Best Sightseeing Pair/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def maxScoreSightseeingPair(self, values: List[int]) -> int: @@ -75,6 +77,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxScoreSightseeingPair(int[] values) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -102,6 +108,8 @@ public: }; ``` +#### Go + ```go func maxScoreSightseeingPair(values []int) (ans int) { for j, mx := 1, values[0]; j < len(values); j++ { @@ -112,6 +120,8 @@ func maxScoreSightseeingPair(values []int) (ans int) { } ``` +#### TypeScript + ```ts function maxScoreSightseeingPair(values: number[]): number { let ans = 0; diff --git a/solution/1000-1099/1014.Best Sightseeing Pair/README_EN.md b/solution/1000-1099/1014.Best Sightseeing Pair/README_EN.md index 930ffa290978e..4f78d54948adf 100644 --- a/solution/1000-1099/1014.Best Sightseeing Pair/README_EN.md +++ b/solution/1000-1099/1014.Best Sightseeing Pair/README_EN.md @@ -59,6 +59,8 @@ tags: +#### Python3 + ```python class Solution: def maxScoreSightseeingPair(self, values: List[int]) -> int: @@ -69,6 +71,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxScoreSightseeingPair(int[] values) { @@ -82,6 +86,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -96,6 +102,8 @@ public: }; ``` +#### Go + ```go func maxScoreSightseeingPair(values []int) (ans int) { for j, mx := 1, values[0]; j < len(values); j++ { @@ -106,6 +114,8 @@ func maxScoreSightseeingPair(values []int) (ans int) { } ``` +#### TypeScript + ```ts function maxScoreSightseeingPair(values: number[]): number { let ans = 0; diff --git a/solution/1000-1099/1015.Smallest Integer Divisible by K/README.md b/solution/1000-1099/1015.Smallest Integer Divisible by K/README.md index dc96254507745..c89674bb17a59 100644 --- a/solution/1000-1099/1015.Smallest Integer Divisible by K/README.md +++ b/solution/1000-1099/1015.Smallest Integer Divisible by K/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def smallestRepunitDivByK(self, k: int) -> int: @@ -83,6 +85,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int smallestRepunitDivByK(int k) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func smallestRepunitDivByK(k int) int { n := 1 % k @@ -127,6 +135,8 @@ func smallestRepunitDivByK(k int) int { } ``` +#### TypeScript + ```ts function smallestRepunitDivByK(k: number): number { let n = 1 % k; diff --git a/solution/1000-1099/1015.Smallest Integer Divisible by K/README_EN.md b/solution/1000-1099/1015.Smallest Integer Divisible by K/README_EN.md index 5269b60b06ffc..007d55d9a1e58 100644 --- a/solution/1000-1099/1015.Smallest Integer Divisible by K/README_EN.md +++ b/solution/1000-1099/1015.Smallest Integer Divisible by K/README_EN.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def smallestRepunitDivByK(self, k: int) -> int: @@ -78,6 +80,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int smallestRepunitDivByK(int k) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func smallestRepunitDivByK(k int) int { n := 1 % k @@ -122,6 +130,8 @@ func smallestRepunitDivByK(k int) int { } ``` +#### TypeScript + ```ts function smallestRepunitDivByK(k: number): number { let n = 1 % k; diff --git a/solution/1000-1099/1016.Binary String With Substrings Representing 1 To N/README.md b/solution/1000-1099/1016.Binary String With Substrings Representing 1 To N/README.md index 835ed7929cb57..6e10dcca702e7 100644 --- a/solution/1000-1099/1016.Binary String With Substrings Representing 1 To N/README.md +++ b/solution/1000-1099/1016.Binary String With Substrings Representing 1 To N/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def queryString(self, s: str, n: int) -> bool: @@ -72,6 +74,8 @@ class Solution: return all(bin(i)[2:] in s for i in range(n, n // 2, -1)) ``` +#### Java + ```java class Solution { public boolean queryString(String s, int n) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func queryString(s string, n int) bool { if n > 1000 { @@ -121,6 +129,8 @@ func queryString(s string, n int) bool { } ``` +#### TypeScript + ```ts function queryString(s: string, n: number): boolean { if (n > 1000) { diff --git a/solution/1000-1099/1016.Binary String With Substrings Representing 1 To N/README_EN.md b/solution/1000-1099/1016.Binary String With Substrings Representing 1 To N/README_EN.md index f7d12e7c4389c..6307adf963d65 100644 --- a/solution/1000-1099/1016.Binary String With Substrings Representing 1 To N/README_EN.md +++ b/solution/1000-1099/1016.Binary String With Substrings Representing 1 To N/README_EN.md @@ -49,6 +49,8 @@ tags: +#### Python3 + ```python class Solution: def queryString(self, s: str, n: int) -> bool: @@ -57,6 +59,8 @@ class Solution: return all(bin(i)[2:] in s for i in range(n, n // 2, -1)) ``` +#### Java + ```java class Solution { public boolean queryString(String s, int n) { @@ -73,6 +77,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -92,6 +98,8 @@ public: }; ``` +#### Go + ```go func queryString(s string, n int) bool { if n > 1000 { @@ -106,6 +114,8 @@ func queryString(s string, n int) bool { } ``` +#### TypeScript + ```ts function queryString(s: string, n: number): boolean { if (n > 1000) { diff --git a/solution/1000-1099/1017.Convert to Base -2/README.md b/solution/1000-1099/1017.Convert to Base -2/README.md index 56629c60b3df7..ebaf8ac1058f6 100644 --- a/solution/1000-1099/1017.Convert to Base -2/README.md +++ b/solution/1000-1099/1017.Convert to Base -2/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def baseNeg2(self, n: int) -> str: @@ -92,6 +94,8 @@ class Solution: return ''.join(ans[::-1]) or '0' ``` +#### Java + ```java class Solution { public String baseNeg2(int n) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func baseNeg2(n int) string { if n == 0 { @@ -164,6 +172,8 @@ func baseNeg2(n int) string { } ``` +#### TypeScript + ```ts function baseNeg2(n: number): string { if (n === 0) { @@ -185,6 +195,8 @@ function baseNeg2(n: number): string { } ``` +#### Rust + ```rust impl Solution { pub fn base_neg2(n: i32) -> String { @@ -209,6 +221,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public string BaseNeg2(int n) { diff --git a/solution/1000-1099/1017.Convert to Base -2/README_EN.md b/solution/1000-1099/1017.Convert to Base -2/README_EN.md index 79ab3abf57742..da79e5c45330a 100644 --- a/solution/1000-1099/1017.Convert to Base -2/README_EN.md +++ b/solution/1000-1099/1017.Convert to Base -2/README_EN.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def baseNeg2(self, n: int) -> str: @@ -80,6 +82,8 @@ class Solution: return ''.join(ans[::-1]) or '0' ``` +#### Java + ```java class Solution { public String baseNeg2(int n) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func baseNeg2(n int) string { if n == 0 { @@ -152,6 +160,8 @@ func baseNeg2(n int) string { } ``` +#### TypeScript + ```ts function baseNeg2(n: number): string { if (n === 0) { @@ -173,6 +183,8 @@ function baseNeg2(n: number): string { } ``` +#### Rust + ```rust impl Solution { pub fn base_neg2(n: i32) -> String { @@ -197,6 +209,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public string BaseNeg2(int n) { diff --git a/solution/1000-1099/1018.Binary Prefix Divisible By 5/README.md b/solution/1000-1099/1018.Binary Prefix Divisible By 5/README.md index 233af8b90a193..f8330e91e9eac 100644 --- a/solution/1000-1099/1018.Binary Prefix Divisible By 5/README.md +++ b/solution/1000-1099/1018.Binary Prefix Divisible By 5/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def prefixesDivBy5(self, nums: List[int]) -> List[bool]: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List prefixesDivBy5(int[] nums) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func prefixesDivBy5(nums []int) (ans []bool) { x := 0 @@ -121,6 +129,8 @@ func prefixesDivBy5(nums []int) (ans []bool) { } ``` +#### TypeScript + ```ts function prefixesDivBy5(nums: number[]): boolean[] { const ans: boolean[] = []; diff --git a/solution/1000-1099/1018.Binary Prefix Divisible By 5/README_EN.md b/solution/1000-1099/1018.Binary Prefix Divisible By 5/README_EN.md index d8e3e4122bb98..7acd9a87de2e4 100644 --- a/solution/1000-1099/1018.Binary Prefix Divisible By 5/README_EN.md +++ b/solution/1000-1099/1018.Binary Prefix Divisible By 5/README_EN.md @@ -64,6 +64,8 @@ Only the first number is divisible by 5, so answer[0] is true. +#### Python3 + ```python class Solution: def prefixesDivBy5(self, nums: List[int]) -> List[bool]: @@ -75,6 +77,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List prefixesDivBy5(int[] nums) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -104,6 +110,8 @@ public: }; ``` +#### Go + ```go func prefixesDivBy5(nums []int) (ans []bool) { x := 0 @@ -115,6 +123,8 @@ func prefixesDivBy5(nums []int) (ans []bool) { } ``` +#### TypeScript + ```ts function prefixesDivBy5(nums: number[]): boolean[] { const ans: boolean[] = []; diff --git a/solution/1000-1099/1019.Next Greater Node In Linked List/README.md b/solution/1000-1099/1019.Next Greater Node In Linked List/README.md index 2de7e233131eb..b6ac710243573 100644 --- a/solution/1000-1099/1019.Next Greater Node In Linked List/README.md +++ b/solution/1000-1099/1019.Next Greater Node In Linked List/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -199,6 +207,8 @@ func nextLargerNodes(head *ListNode) []int { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -232,6 +242,8 @@ function nextLargerNodes(head: ListNode | null): number[] { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -276,6 +288,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. diff --git a/solution/1000-1099/1019.Next Greater Node In Linked List/README_EN.md b/solution/1000-1099/1019.Next Greater Node In Linked List/README_EN.md index cf5f0cceedc00..dcb007b8a69e7 100644 --- a/solution/1000-1099/1019.Next Greater Node In Linked List/README_EN.md +++ b/solution/1000-1099/1019.Next Greater Node In Linked List/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -193,6 +201,8 @@ func nextLargerNodes(head *ListNode) []int { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -226,6 +236,8 @@ function nextLargerNodes(head: ListNode | null): number[] { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -270,6 +282,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. diff --git a/solution/1000-1099/1020.Number of Enclaves/README.md b/solution/1000-1099/1020.Number of Enclaves/README.md index 6454cfe51bb40..8e24e63b10f94 100644 --- a/solution/1000-1099/1020.Number of Enclaves/README.md +++ b/solution/1000-1099/1020.Number of Enclaves/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def numEnclaves(self, grid: List[List[int]]) -> int: @@ -90,6 +92,8 @@ class Solution: return sum(v for row in grid for v in row) ``` +#### Java + ```java class Solution { private int m; @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func numEnclaves(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -192,6 +200,8 @@ func numEnclaves(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function numEnclaves(grid: number[][]): number { const m = grid.length; @@ -224,6 +234,8 @@ function numEnclaves(grid: number[][]): number { } ``` +#### Rust + ```rust impl Solution { fn dfs(grid: &mut Vec>, y: usize, x: usize) { @@ -278,6 +290,8 @@ impl Solution { +#### Python3 + ```python class Solution: def numEnclaves(self, grid: List[List[int]]) -> int: @@ -299,6 +313,8 @@ class Solution: return sum(v for row in grid for v in row) ``` +#### Java + ```java class Solution { public int numEnclaves(int[][] grid) { @@ -335,6 +351,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -372,6 +390,8 @@ public: }; ``` +#### Go + ```go func numEnclaves(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -405,6 +425,8 @@ func numEnclaves(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function numEnclaves(grid: number[][]): number { const m = grid.length; @@ -454,6 +476,8 @@ function numEnclaves(grid: number[][]): number { +#### Python3 + ```python class UnionFind: def __init__(self, n): @@ -498,6 +522,8 @@ class Solution: ) ``` +#### Java + ```java class UnionFind { private int[] p; @@ -568,6 +594,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -634,6 +662,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p, size []int diff --git a/solution/1000-1099/1020.Number of Enclaves/README_EN.md b/solution/1000-1099/1020.Number of Enclaves/README_EN.md index 3cf61818949db..c9ebfcd42c8dc 100644 --- a/solution/1000-1099/1020.Number of Enclaves/README_EN.md +++ b/solution/1000-1099/1020.Number of Enclaves/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def numEnclaves(self, grid: List[List[int]]) -> int: @@ -84,6 +86,8 @@ class Solution: return sum(v for row in grid for v in row) ``` +#### Java + ```java class Solution { private int m; @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func numEnclaves(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -186,6 +194,8 @@ func numEnclaves(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function numEnclaves(grid: number[][]): number { const m = grid.length; @@ -218,6 +228,8 @@ function numEnclaves(grid: number[][]): number { } ``` +#### Rust + ```rust impl Solution { fn dfs(grid: &mut Vec>, y: usize, x: usize) { @@ -268,6 +280,8 @@ impl Solution { +#### Python3 + ```python class Solution: def numEnclaves(self, grid: List[List[int]]) -> int: @@ -289,6 +303,8 @@ class Solution: return sum(v for row in grid for v in row) ``` +#### Java + ```java class Solution { public int numEnclaves(int[][] grid) { @@ -325,6 +341,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -362,6 +380,8 @@ public: }; ``` +#### Go + ```go func numEnclaves(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -395,6 +415,8 @@ func numEnclaves(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function numEnclaves(grid: number[][]): number { const m = grid.length; @@ -440,6 +462,8 @@ function numEnclaves(grid: number[][]): number { +#### Python3 + ```python class UnionFind: def __init__(self, n): @@ -484,6 +508,8 @@ class Solution: ) ``` +#### Java + ```java class UnionFind { private int[] p; @@ -554,6 +580,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -620,6 +648,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p, size []int diff --git a/solution/1000-1099/1021.Remove Outermost Parentheses/README.md b/solution/1000-1099/1021.Remove Outermost Parentheses/README.md index f8c17aa3240c7..eb884ee646cc6 100644 --- a/solution/1000-1099/1021.Remove Outermost Parentheses/README.md +++ b/solution/1000-1099/1021.Remove Outermost Parentheses/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def removeOuterParentheses(self, s: str) -> str: @@ -103,6 +105,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String removeOuterParentheses(String s) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func removeOuterParentheses(s string) string { ans := []rune{} @@ -168,6 +176,8 @@ func removeOuterParentheses(s string) string { } ``` +#### TypeScript + ```ts function removeOuterParentheses(s: string): string { let res = ''; @@ -187,6 +197,8 @@ function removeOuterParentheses(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn remove_outer_parentheses(s: String) -> String { @@ -218,6 +230,8 @@ impl Solution { +#### Python3 + ```python class Solution: def removeOuterParentheses(self, s: str) -> str: @@ -233,6 +247,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String removeOuterParentheses(String s) { @@ -255,6 +271,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -277,6 +295,8 @@ public: }; ``` +#### Go + ```go func removeOuterParentheses(s string) string { ans := []rune{} diff --git a/solution/1000-1099/1021.Remove Outermost Parentheses/README_EN.md b/solution/1000-1099/1021.Remove Outermost Parentheses/README_EN.md index 9a47a36fcafd2..05910e12be99e 100644 --- a/solution/1000-1099/1021.Remove Outermost Parentheses/README_EN.md +++ b/solution/1000-1099/1021.Remove Outermost Parentheses/README_EN.md @@ -81,6 +81,8 @@ After removing outer parentheses of each part, this is "" + "&quo +#### Python3 + ```python class Solution: def removeOuterParentheses(self, s: str) -> str: @@ -98,6 +100,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String removeOuterParentheses(String s) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func removeOuterParentheses(s string) string { ans := []rune{} @@ -163,6 +171,8 @@ func removeOuterParentheses(s string) string { } ``` +#### TypeScript + ```ts function removeOuterParentheses(s: string): string { let res = ''; @@ -182,6 +192,8 @@ function removeOuterParentheses(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn remove_outer_parentheses(s: String) -> String { @@ -213,6 +225,8 @@ impl Solution { +#### Python3 + ```python class Solution: def removeOuterParentheses(self, s: str) -> str: @@ -228,6 +242,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String removeOuterParentheses(String s) { @@ -250,6 +266,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -272,6 +290,8 @@ public: }; ``` +#### Go + ```go func removeOuterParentheses(s string) string { ans := []rune{} diff --git a/solution/1000-1099/1022.Sum of Root To Leaf Binary Numbers/README.md b/solution/1000-1099/1022.Sum of Root To Leaf Binary Numbers/README.md index 41ecd4c58c99d..171769a5cf0f7 100644 --- a/solution/1000-1099/1022.Sum of Root To Leaf Binary Numbers/README.md +++ b/solution/1000-1099/1022.Sum of Root To Leaf Binary Numbers/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -95,6 +97,8 @@ class Solution: return dfs(root, 0) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -182,6 +190,8 @@ func sumRootToLeaf(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -213,6 +223,8 @@ function sumRootToLeaf(root: TreeNode | null): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/1000-1099/1022.Sum of Root To Leaf Binary Numbers/README_EN.md b/solution/1000-1099/1022.Sum of Root To Leaf Binary Numbers/README_EN.md index cef38405d63bb..5197eb9345730 100644 --- a/solution/1000-1099/1022.Sum of Root To Leaf Binary Numbers/README_EN.md +++ b/solution/1000-1099/1022.Sum of Root To Leaf Binary Numbers/README_EN.md @@ -73,6 +73,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -93,6 +95,8 @@ class Solution: return dfs(root, 0) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -180,6 +188,8 @@ func sumRootToLeaf(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -211,6 +221,8 @@ function sumRootToLeaf(root: TreeNode | null): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/1000-1099/1023.Camelcase Matching/README.md b/solution/1000-1099/1023.Camelcase Matching/README.md index 26886cf638c77..bdab6cf2fcf19 100644 --- a/solution/1000-1099/1023.Camelcase Matching/README.md +++ b/solution/1000-1099/1023.Camelcase Matching/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def camelMatch(self, queries: List[str], pattern: str) -> List[bool]: @@ -106,6 +108,8 @@ class Solution: return [check(q, pattern) for q in queries] ``` +#### Java + ```java class Solution { public List camelMatch(String[] queries, String pattern) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func camelMatch(queries []string, pattern string) (ans []bool) { check := func(s, t string) bool { @@ -189,6 +197,8 @@ func camelMatch(queries []string, pattern string) (ans []bool) { } ``` +#### TypeScript + ```ts function camelMatch(queries: string[], pattern: string): boolean[] { const check = (s: string, t: string) => { diff --git a/solution/1000-1099/1023.Camelcase Matching/README_EN.md b/solution/1000-1099/1023.Camelcase Matching/README_EN.md index 071d59e121aae..b6da81fc03815 100644 --- a/solution/1000-1099/1023.Camelcase Matching/README_EN.md +++ b/solution/1000-1099/1023.Camelcase Matching/README_EN.md @@ -83,6 +83,8 @@ Time complexity $(n \times m)$, where $n$ and $m$ are the length of the array `q +#### Python3 + ```python class Solution: def camelMatch(self, queries: List[str], pattern: str) -> List[bool]: @@ -102,6 +104,8 @@ class Solution: return [check(q, pattern) for q in queries] ``` +#### Java + ```java class Solution { public List camelMatch(String[] queries, String pattern) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func camelMatch(queries []string, pattern string) (ans []bool) { check := func(s, t string) bool { @@ -185,6 +193,8 @@ func camelMatch(queries []string, pattern string) (ans []bool) { } ``` +#### TypeScript + ```ts function camelMatch(queries: string[], pattern: string): boolean[] { const check = (s: string, t: string) => { diff --git a/solution/1000-1099/1024.Video Stitching/README.md b/solution/1000-1099/1024.Video Stitching/README.md index 5f515035b2916..c1cf8cde5c120 100644 --- a/solution/1000-1099/1024.Video Stitching/README.md +++ b/solution/1000-1099/1024.Video Stitching/README.md @@ -104,6 +104,8 @@ tags: +#### Python3 + ```python class Solution: def videoStitching(self, clips: List[List[int]], time: int) -> int: @@ -122,6 +124,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int videoStitching(int[][] clips, int time) { @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go func videoStitching(clips [][]int, time int) int { last := make([]int, time) diff --git a/solution/1000-1099/1024.Video Stitching/README_EN.md b/solution/1000-1099/1024.Video Stitching/README_EN.md index 7779bb3301980..88fd7f32a1e0d 100644 --- a/solution/1000-1099/1024.Video Stitching/README_EN.md +++ b/solution/1000-1099/1024.Video Stitching/README_EN.md @@ -99,6 +99,8 @@ Similar problems: +#### Python3 + ```python class Solution: def videoStitching(self, clips: List[List[int]], time: int) -> int: @@ -117,6 +119,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int videoStitching(int[][] clips, int time) { @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func videoStitching(clips [][]int, time int) int { last := make([]int, time) diff --git a/solution/1000-1099/1025.Divisor Game/README.md b/solution/1000-1099/1025.Divisor Game/README.md index 900045c077bf1..d80aeeebf070c 100644 --- a/solution/1000-1099/1025.Divisor Game/README.md +++ b/solution/1000-1099/1025.Divisor Game/README.md @@ -92,12 +92,16 @@ tags: +#### Python3 + ```python class Solution: def divisorGame(self, n: int) -> bool: return n % 2 == 0 ``` +#### Java + ```java class Solution { public boolean divisorGame(int n) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,12 +121,16 @@ public: }; ``` +#### Go + ```go func divisorGame(n int) bool { return n%2 == 0 } ``` +#### JavaScript + ```js var divisorGame = function (n) { return n % 2 === 0; diff --git a/solution/1000-1099/1025.Divisor Game/README_EN.md b/solution/1000-1099/1025.Divisor Game/README_EN.md index c338dca51463e..57b67c0184ae7 100644 --- a/solution/1000-1099/1025.Divisor Game/README_EN.md +++ b/solution/1000-1099/1025.Divisor Game/README_EN.md @@ -87,12 +87,16 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def divisorGame(self, n: int) -> bool: return n % 2 == 0 ``` +#### Java + ```java class Solution { public boolean divisorGame(int n) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,12 +116,16 @@ public: }; ``` +#### Go + ```go func divisorGame(n int) bool { return n%2 == 0 } ``` +#### JavaScript + ```js var divisorGame = function (n) { return n % 2 === 0; diff --git a/solution/1000-1099/1026.Maximum Difference Between Node and Ancestor/README.md b/solution/1000-1099/1026.Maximum Difference Between Node and Ancestor/README.md index 721d3b5a59b5a..5700e5a41e219 100644 --- a/solution/1000-1099/1026.Maximum Difference Between Node and Ancestor/README.md +++ b/solution/1000-1099/1026.Maximum Difference Between Node and Ancestor/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -209,6 +217,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -241,6 +251,8 @@ function maxAncestorDiff(root: TreeNode | null): number { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -271,6 +283,8 @@ var maxAncestorDiff = function (root) { }; ``` +#### C# + ```cs /** * Definition for a binary tree node. diff --git a/solution/1000-1099/1026.Maximum Difference Between Node and Ancestor/README_EN.md b/solution/1000-1099/1026.Maximum Difference Between Node and Ancestor/README_EN.md index cfb7d07307364..6f941c1404d59 100644 --- a/solution/1000-1099/1026.Maximum Difference Between Node and Ancestor/README_EN.md +++ b/solution/1000-1099/1026.Maximum Difference Between Node and Ancestor/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -203,6 +211,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -235,6 +245,8 @@ function maxAncestorDiff(root: TreeNode | null): number { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -265,6 +277,8 @@ var maxAncestorDiff = function (root) { }; ``` +#### C# + ```cs /** * Definition for a binary tree node. diff --git a/solution/1000-1099/1027.Longest Arithmetic Subsequence/README.md b/solution/1000-1099/1027.Longest Arithmetic Subsequence/README.md index f3bcc4d51b66c..c04a4f7c19577 100644 --- a/solution/1000-1099/1027.Longest Arithmetic Subsequence/README.md +++ b/solution/1000-1099/1027.Longest Arithmetic Subsequence/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def longestArithSeqLength(self, nums: List[int]) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestArithSeqLength(int[] nums) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func longestArithSeqLength(nums []int) int { n := len(nums) @@ -156,6 +164,8 @@ func longestArithSeqLength(nums []int) int { } ``` +#### TypeScript + ```ts function longestArithSeqLength(nums: number[]): number { const n = nums.length; diff --git a/solution/1000-1099/1027.Longest Arithmetic Subsequence/README_EN.md b/solution/1000-1099/1027.Longest Arithmetic Subsequence/README_EN.md index f10bed2dd9ddf..fda75cd9ff73c 100644 --- a/solution/1000-1099/1027.Longest Arithmetic Subsequence/README_EN.md +++ b/solution/1000-1099/1027.Longest Arithmetic Subsequence/README_EN.md @@ -85,6 +85,8 @@ The time complexity is $O(n \times (d + n))$, and the space complexity is $O(n \ +#### Python3 + ```python class Solution: def longestArithSeqLength(self, nums: List[int]) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestArithSeqLength(int[] nums) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func longestArithSeqLength(nums []int) int { n := len(nums) @@ -156,6 +164,8 @@ func longestArithSeqLength(nums []int) int { } ``` +#### TypeScript + ```ts function longestArithSeqLength(nums: number[]): number { const n = nums.length; diff --git a/solution/1000-1099/1028.Recover a Tree From Preorder Traversal/README.md b/solution/1000-1099/1028.Recover a Tree From Preorder Traversal/README.md index 77e28305270d0..c01aa3ccd27ab 100644 --- a/solution/1000-1099/1028.Recover a Tree From Preorder Traversal/README.md +++ b/solution/1000-1099/1028.Recover a Tree From Preorder Traversal/README.md @@ -74,6 +74,8 @@ tags: +#### C++ + ```cpp /** * Definition for a binary tree node. diff --git a/solution/1000-1099/1028.Recover a Tree From Preorder Traversal/README_EN.md b/solution/1000-1099/1028.Recover a Tree From Preorder Traversal/README_EN.md index 08770a157d29a..206bb9dc34b22 100644 --- a/solution/1000-1099/1028.Recover a Tree From Preorder Traversal/README_EN.md +++ b/solution/1000-1099/1028.Recover a Tree From Preorder Traversal/README_EN.md @@ -69,6 +69,8 @@ tags: +#### C++ + ```cpp /** * Definition for a binary tree node. diff --git a/solution/1000-1099/1029.Two City Scheduling/README.md b/solution/1000-1099/1029.Two City Scheduling/README.md index 8a6df37f86ac9..7475ab9f3f81b 100644 --- a/solution/1000-1099/1029.Two City Scheduling/README.md +++ b/solution/1000-1099/1029.Two City Scheduling/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def twoCitySchedCost(self, costs: List[List[int]]) -> int: @@ -91,6 +93,8 @@ class Solution: return sum(costs[i][0] + costs[i + n][1] for i in range(n)) ``` +#### Java + ```java class Solution { public int twoCitySchedCost(int[][] costs) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func twoCitySchedCost(costs [][]int) (ans int) { sort.Slice(costs, func(i, j int) bool { @@ -135,6 +143,8 @@ func twoCitySchedCost(costs [][]int) (ans int) { } ``` +#### TypeScript + ```ts function twoCitySchedCost(costs: number[][]): number { costs.sort((a, b) => a[0] - a[1] - (b[0] - b[1])); diff --git a/solution/1000-1099/1029.Two City Scheduling/README_EN.md b/solution/1000-1099/1029.Two City Scheduling/README_EN.md index e38d691726ffe..adfd4560ac51a 100644 --- a/solution/1000-1099/1029.Two City Scheduling/README_EN.md +++ b/solution/1000-1099/1029.Two City Scheduling/README_EN.md @@ -73,6 +73,8 @@ The total minimum cost is 10 + 30 + 50 + 20 = 110 to have half the people interv +#### Python3 + ```python class Solution: def twoCitySchedCost(self, costs: List[List[int]]) -> int: @@ -81,6 +83,8 @@ class Solution: return sum(costs[i][0] + costs[i + n][1] for i in range(n)) ``` +#### Java + ```java class Solution { public int twoCitySchedCost(int[][] costs) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func twoCitySchedCost(costs [][]int) (ans int) { sort.Slice(costs, func(i, j int) bool { @@ -125,6 +133,8 @@ func twoCitySchedCost(costs [][]int) (ans int) { } ``` +#### TypeScript + ```ts function twoCitySchedCost(costs: number[][]): number { costs.sort((a, b) => a[0] - a[1] - (b[0] - b[1])); diff --git a/solution/1000-1099/1030.Matrix Cells in Distance Order/README.md b/solution/1000-1099/1030.Matrix Cells in Distance Order/README.md index 74fcd5c08fde7..4fff950b9bf43 100644 --- a/solution/1000-1099/1030.Matrix Cells in Distance Order/README.md +++ b/solution/1000-1099/1030.Matrix Cells in Distance Order/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def allCellsDistOrder( @@ -103,6 +105,8 @@ class Solution: return ans ``` +#### Java + ```java import java.util.Deque; @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func allCellsDistOrder(rows int, cols int, rCenter int, cCenter int) (ans [][]int) { q := [][]int{{rCenter, cCenter}} diff --git a/solution/1000-1099/1030.Matrix Cells in Distance Order/README_EN.md b/solution/1000-1099/1030.Matrix Cells in Distance Order/README_EN.md index ee59cc8a0f10c..2bc0ee8e48d31 100644 --- a/solution/1000-1099/1030.Matrix Cells in Distance Order/README_EN.md +++ b/solution/1000-1099/1030.Matrix Cells in Distance Order/README_EN.md @@ -74,6 +74,8 @@ There are other answers that would also be accepted as correct, such as [[1,2],[ +#### Python3 + ```python class Solution: def allCellsDistOrder( @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java import java.util.Deque; @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func allCellsDistOrder(rows int, cols int, rCenter int, cCenter int) (ans [][]int) { q := [][]int{{rCenter, cCenter}} diff --git a/solution/1000-1099/1031.Maximum Sum of Two Non-Overlapping Subarrays/README.md b/solution/1000-1099/1031.Maximum Sum of Two Non-Overlapping Subarrays/README.md index df6ddd368f6de..3a147ef0257cc 100644 --- a/solution/1000-1099/1031.Maximum Sum of Two Non-Overlapping Subarrays/README.md +++ b/solution/1000-1099/1031.Maximum Sum of Two Non-Overlapping Subarrays/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def maxSumTwoNoOverlap(self, nums: List[int], firstLen: int, secondLen: int) -> int: @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxSumTwoNoOverlap(int[] nums, int firstLen, int secondLen) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func maxSumTwoNoOverlap(nums []int, firstLen int, secondLen int) (ans int) { n := len(nums) diff --git a/solution/1000-1099/1031.Maximum Sum of Two Non-Overlapping Subarrays/README_EN.md b/solution/1000-1099/1031.Maximum Sum of Two Non-Overlapping Subarrays/README_EN.md index e095da9eaeb27..3718c87ac3bb6 100644 --- a/solution/1000-1099/1031.Maximum Sum of Two Non-Overlapping Subarrays/README_EN.md +++ b/solution/1000-1099/1031.Maximum Sum of Two Non-Overlapping Subarrays/README_EN.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def maxSumTwoNoOverlap(self, nums: List[int], firstLen: int, secondLen: int) -> int: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxSumTwoNoOverlap(int[] nums, int firstLen, int secondLen) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func maxSumTwoNoOverlap(nums []int, firstLen int, secondLen int) (ans int) { n := len(nums) diff --git a/solution/1000-1099/1032.Stream of Characters/README.md b/solution/1000-1099/1032.Stream of Characters/README.md index 059974b5fd553..716fe6e52e8ae 100644 --- a/solution/1000-1099/1032.Stream of Characters/README.md +++ b/solution/1000-1099/1032.Stream of Characters/README.md @@ -93,6 +93,8 @@ streamChecker.query("l"); // 返回 True ,因为 'kl' 在 words 中 +#### Python3 + ```python class Trie: def __init__(self): @@ -138,6 +140,8 @@ class StreamChecker: # param_1 = obj.query(letter) ``` +#### Java + ```java class Trie { Trie[] children = new Trie[26]; @@ -194,6 +198,8 @@ class StreamChecker { */ ``` +#### C++ + ```cpp class Trie { public: @@ -257,6 +263,8 @@ public: */ ``` +#### Go + ```go type Trie struct { children [26]*Trie diff --git a/solution/1000-1099/1032.Stream of Characters/README_EN.md b/solution/1000-1099/1032.Stream of Characters/README_EN.md index aa3aa80021acc..a54c0c8768536 100644 --- a/solution/1000-1099/1032.Stream of Characters/README_EN.md +++ b/solution/1000-1099/1032.Stream of Characters/README_EN.md @@ -80,6 +80,8 @@ streamChecker.query("l"); // return True, because 'kl' is in t +#### Python3 + ```python class Trie: def __init__(self): @@ -125,6 +127,8 @@ class StreamChecker: # param_1 = obj.query(letter) ``` +#### Java + ```java class Trie { Trie[] children = new Trie[26]; @@ -181,6 +185,8 @@ class StreamChecker { */ ``` +#### C++ + ```cpp class Trie { public: @@ -244,6 +250,8 @@ public: */ ``` +#### Go + ```go type Trie struct { children [26]*Trie diff --git a/solution/1000-1099/1033.Moving Stones Until Consecutive/README.md b/solution/1000-1099/1033.Moving Stones Until Consecutive/README.md index b74e48984ad4b..5b01ad9e3c84b 100644 --- a/solution/1000-1099/1033.Moving Stones Until Consecutive/README.md +++ b/solution/1000-1099/1033.Moving Stones Until Consecutive/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def numMovesStones(self, a: int, b: int, c: int) -> List[int]: @@ -88,6 +90,8 @@ class Solution: return [mi, mx] ``` +#### Java + ```java class Solution { public int[] numMovesStones(int a, int b, int c) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func numMovesStones(a int, b int, c int) []int { x := min(a, min(b, c)) @@ -138,6 +146,8 @@ func numMovesStones(a int, b int, c int) []int { } ``` +#### TypeScript + ```ts function numMovesStones(a: number, b: number, c: number): number[] { const x = Math.min(a, Math.min(b, c)); diff --git a/solution/1000-1099/1033.Moving Stones Until Consecutive/README_EN.md b/solution/1000-1099/1033.Moving Stones Until Consecutive/README_EN.md index 8409caf7cbd19..b0fa044e017ee 100644 --- a/solution/1000-1099/1033.Moving Stones Until Consecutive/README_EN.md +++ b/solution/1000-1099/1033.Moving Stones Until Consecutive/README_EN.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def numMovesStones(self, a: int, b: int, c: int) -> List[int]: @@ -87,6 +89,8 @@ class Solution: return [mi, mx] ``` +#### Java + ```java class Solution { public int[] numMovesStones(int a, int b, int c) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func numMovesStones(a int, b int, c int) []int { x := min(a, min(b, c)) @@ -137,6 +145,8 @@ func numMovesStones(a int, b int, c int) []int { } ``` +#### TypeScript + ```ts function numMovesStones(a: number, b: number, c: number): number[] { const x = Math.min(a, Math.min(b, c)); diff --git a/solution/1000-1099/1034.Coloring A Border/README.md b/solution/1000-1099/1034.Coloring A Border/README.md index 684d5253d2540..13e488f701ac3 100644 --- a/solution/1000-1099/1034.Coloring A Border/README.md +++ b/solution/1000-1099/1034.Coloring A Border/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def colorBorder( @@ -109,6 +111,8 @@ class Solution: return grid ``` +#### Java + ```java class Solution { private int[][] grid; @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func colorBorder(grid [][]int, row int, col int, color int) [][]int { m, n := len(grid), len(grid[0]) @@ -212,6 +220,8 @@ func colorBorder(grid [][]int, row int, col int, color int) [][]int { } ``` +#### TypeScript + ```ts function colorBorder(grid: number[][], row: number, col: number, color: number): number[][] { const m = grid.length; diff --git a/solution/1000-1099/1034.Coloring A Border/README_EN.md b/solution/1000-1099/1034.Coloring A Border/README_EN.md index 5f722b68e52ad..cb2b4deabbe4e 100644 --- a/solution/1000-1099/1034.Coloring A Border/README_EN.md +++ b/solution/1000-1099/1034.Coloring A Border/README_EN.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def colorBorder( @@ -90,6 +92,8 @@ class Solution: return grid ``` +#### Java + ```java class Solution { private int[][] grid; @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func colorBorder(grid [][]int, row int, col int, color int) [][]int { m, n := len(grid), len(grid[0]) @@ -193,6 +201,8 @@ func colorBorder(grid [][]int, row int, col int, color int) [][]int { } ``` +#### TypeScript + ```ts function colorBorder(grid: number[][], row: number, col: number, color: number): number[][] { const m = grid.length; diff --git a/solution/1000-1099/1035.Uncrossed Lines/README.md b/solution/1000-1099/1035.Uncrossed Lines/README.md index 7c3f33c772ccb..64fcc5e4d6581 100644 --- a/solution/1000-1099/1035.Uncrossed Lines/README.md +++ b/solution/1000-1099/1035.Uncrossed Lines/README.md @@ -95,6 +95,8 @@ $$ +#### Python3 + ```python class Solution: def maxUncrossedLines(self, nums1: List[int], nums2: List[int]) -> int: @@ -109,6 +111,8 @@ class Solution: return dp[m][n] ``` +#### Java + ```java class Solution { public int maxUncrossedLines(int[] nums1, int[] nums2) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func maxUncrossedLines(nums1 []int, nums2 []int) int { m, n := len(nums1), len(nums2) @@ -169,6 +177,8 @@ func maxUncrossedLines(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function maxUncrossedLines(nums1: number[], nums2: number[]): number { const m = nums1.length; diff --git a/solution/1000-1099/1035.Uncrossed Lines/README_EN.md b/solution/1000-1099/1035.Uncrossed Lines/README_EN.md index e5ecc2ff65efc..58d5c1873e5cf 100644 --- a/solution/1000-1099/1035.Uncrossed Lines/README_EN.md +++ b/solution/1000-1099/1035.Uncrossed Lines/README_EN.md @@ -74,6 +74,8 @@ We cannot draw 3 uncrossed lines, because the line from nums1[1] = 4 to nums2[2] +#### Python3 + ```python class Solution: def maxUncrossedLines(self, nums1: List[int], nums2: List[int]) -> int: @@ -88,6 +90,8 @@ class Solution: return dp[m][n] ``` +#### Java + ```java class Solution { public int maxUncrossedLines(int[] nums1, int[] nums2) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func maxUncrossedLines(nums1 []int, nums2 []int) int { m, n := len(nums1), len(nums2) @@ -148,6 +156,8 @@ func maxUncrossedLines(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function maxUncrossedLines(nums1: number[], nums2: number[]): number { const m = nums1.length; diff --git a/solution/1000-1099/1036.Escape a Large Maze/README.md b/solution/1000-1099/1036.Escape a Large Maze/README.md index 2d81e9c807e03..7926a046e6c98 100644 --- a/solution/1000-1099/1036.Escape a Large Maze/README.md +++ b/solution/1000-1099/1036.Escape a Large Maze/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def isEscapePossible( @@ -100,6 +102,8 @@ class Solution: return dfs(source, target, set()) and dfs(target, source, set()) ``` +#### Java + ```java class Solution { private int[][] dirs = new int[][] {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp typedef unsigned long long ULL; @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func isEscapePossible(blocked [][]int, source []int, target []int) bool { const N = 1e6 @@ -199,6 +207,8 @@ func isEscapePossible(blocked [][]int, source []int, target []int) bool { } ``` +#### Rust + ```rust use std::collections::{ HashSet, VecDeque }; diff --git a/solution/1000-1099/1036.Escape a Large Maze/README_EN.md b/solution/1000-1099/1036.Escape a Large Maze/README_EN.md index a3f2c76d4c18e..6f0a221a8dfcc 100644 --- a/solution/1000-1099/1036.Escape a Large Maze/README_EN.md +++ b/solution/1000-1099/1036.Escape a Large Maze/README_EN.md @@ -71,6 +71,8 @@ We cannot move south or west because we cannot go outside of the grid. +#### Python3 + ```python class Solution: def isEscapePossible( @@ -97,6 +99,8 @@ class Solution: return dfs(source, target, set()) and dfs(target, source, set()) ``` +#### Java + ```java class Solution { private int[][] dirs = new int[][] {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp typedef unsigned long long ULL; @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func isEscapePossible(blocked [][]int, source []int, target []int) bool { const N = 1e6 @@ -196,6 +204,8 @@ func isEscapePossible(blocked [][]int, source []int, target []int) bool { } ``` +#### Rust + ```rust use std::collections::{ HashSet, VecDeque }; diff --git a/solution/1000-1099/1037.Valid Boomerang/README.md b/solution/1000-1099/1037.Valid Boomerang/README.md index 8632ce9c7aa53..6cb81f138ab6b 100644 --- a/solution/1000-1099/1037.Valid Boomerang/README.md +++ b/solution/1000-1099/1037.Valid Boomerang/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def isBoomerang(self, points: List[List[int]]) -> bool: @@ -78,6 +80,8 @@ class Solution: return (y2 - y1) * (x3 - x2) != (y3 - y2) * (x2 - x1) ``` +#### Java + ```java class Solution { public boolean isBoomerang(int[][] points) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,6 +107,8 @@ public: }; ``` +#### Go + ```go func isBoomerang(points [][]int) bool { x1, y1 := points[0][0], points[0][1] @@ -110,6 +118,8 @@ func isBoomerang(points [][]int) bool { } ``` +#### TypeScript + ```ts function isBoomerang(points: number[][]): boolean { const [x1, y1] = points[0]; @@ -119,6 +129,8 @@ function isBoomerang(points: number[][]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn is_boomerang(points: Vec>) -> bool { diff --git a/solution/1000-1099/1037.Valid Boomerang/README_EN.md b/solution/1000-1099/1037.Valid Boomerang/README_EN.md index ce5a36527c542..37a8651157d69 100644 --- a/solution/1000-1099/1037.Valid Boomerang/README_EN.md +++ b/solution/1000-1099/1037.Valid Boomerang/README_EN.md @@ -51,6 +51,8 @@ tags: +#### Python3 + ```python class Solution: def isBoomerang(self, points: List[List[int]]) -> bool: @@ -58,6 +60,8 @@ class Solution: return (y2 - y1) * (x3 - x2) != (y3 - y2) * (x2 - x1) ``` +#### Java + ```java class Solution { public boolean isBoomerang(int[][] points) { @@ -69,6 +73,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -81,6 +87,8 @@ public: }; ``` +#### Go + ```go func isBoomerang(points [][]int) bool { x1, y1 := points[0][0], points[0][1] @@ -90,6 +98,8 @@ func isBoomerang(points [][]int) bool { } ``` +#### TypeScript + ```ts function isBoomerang(points: number[][]): boolean { const [x1, y1] = points[0]; @@ -99,6 +109,8 @@ function isBoomerang(points: number[][]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn is_boomerang(points: Vec>) -> bool { diff --git a/solution/1000-1099/1038.Binary Search Tree to Greater Sum Tree/README.md b/solution/1000-1099/1038.Binary Search Tree to Greater Sum Tree/README.md index 7f6b3bb28264a..c9889a1862185 100644 --- a/solution/1000-1099/1038.Binary Search Tree to Greater Sum Tree/README.md +++ b/solution/1000-1099/1038.Binary Search Tree to Greater Sum Tree/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -100,6 +102,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -193,6 +201,8 @@ func bstToGst(root *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -224,6 +234,8 @@ function bstToGst(root: TreeNode | null): TreeNode | null { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -263,6 +275,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -292,6 +306,8 @@ var bstToGst = function (root) { }; ``` +#### C + ```c /** * Definition for a binary tree node. @@ -340,6 +356,8 @@ Morris 遍历无需使用栈,时间复杂度 $O(n)$,空间复杂度为 $O(1) +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -371,6 +389,8 @@ class Solution: return node ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -417,6 +437,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -460,6 +482,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -497,6 +521,8 @@ func bstToGst(root *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -541,6 +567,8 @@ function bstToGst(root: TreeNode | null): TreeNode | null { } ``` +#### C + ```c /** * Definition for a binary tree node. diff --git a/solution/1000-1099/1038.Binary Search Tree to Greater Sum Tree/README_EN.md b/solution/1000-1099/1038.Binary Search Tree to Greater Sum Tree/README_EN.md index ca53ef2eaec82..6d8df92c5bef5 100644 --- a/solution/1000-1099/1038.Binary Search Tree to Greater Sum Tree/README_EN.md +++ b/solution/1000-1099/1038.Binary Search Tree to Greater Sum Tree/README_EN.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -91,6 +93,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -184,6 +192,8 @@ func bstToGst(root *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -215,6 +225,8 @@ function bstToGst(root: TreeNode | null): TreeNode | null { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -254,6 +266,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -283,6 +297,8 @@ var bstToGst = function (root) { }; ``` +#### C + ```c /** * Definition for a binary tree node. @@ -318,6 +334,8 @@ struct TreeNode* bstToGst(struct TreeNode* root) { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -349,6 +367,8 @@ class Solution: return node ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -395,6 +415,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -438,6 +460,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -475,6 +499,8 @@ func bstToGst(root *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -519,6 +545,8 @@ function bstToGst(root: TreeNode | null): TreeNode | null { } ``` +#### C + ```c /** * Definition for a binary tree node. diff --git a/solution/1000-1099/1039.Minimum Score Triangulation of Polygon/README.md b/solution/1000-1099/1039.Minimum Score Triangulation of Polygon/README.md index ffaf1385fb22c..9ed3d3a56d38a 100644 --- a/solution/1000-1099/1039.Minimum Score Triangulation of Polygon/README.md +++ b/solution/1000-1099/1039.Minimum Score Triangulation of Polygon/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def minScoreTriangulation(self, values: List[int]) -> int: @@ -108,6 +110,8 @@ class Solution: return dfs(0, len(values) - 1) ``` +#### Java + ```java class Solution { private int n; @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func minScoreTriangulation(values []int) int { n := len(values) @@ -184,6 +192,8 @@ func minScoreTriangulation(values []int) int { } ``` +#### TypeScript + ```ts function minScoreTriangulation(values: number[]): number { const n = values.length; @@ -247,6 +257,8 @@ $$ +#### Python3 + ```python class Solution: def minScoreTriangulation(self, values: List[int]) -> int: @@ -261,6 +273,8 @@ class Solution: return f[0][-1] ``` +#### Java + ```java class Solution { public int minScoreTriangulation(int[] values) { @@ -280,6 +294,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -300,6 +316,8 @@ public: }; ``` +#### Go + ```go func minScoreTriangulation(values []int) int { n := len(values) @@ -316,6 +334,8 @@ func minScoreTriangulation(values []int) int { } ``` +#### TypeScript + ```ts function minScoreTriangulation(values: number[]): number { const n = values.length; @@ -342,6 +362,8 @@ function minScoreTriangulation(values: number[]): number { +#### Python3 + ```python class Solution: def minScoreTriangulation(self, values: List[int]) -> int: @@ -357,6 +379,8 @@ class Solution: return f[0][-1] ``` +#### Java + ```java class Solution { public int minScoreTriangulation(int[] values) { @@ -377,6 +401,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -398,6 +424,8 @@ public: }; ``` +#### Go + ```go func minScoreTriangulation(values []int) int { n := len(values) @@ -415,6 +443,8 @@ func minScoreTriangulation(values []int) int { } ``` +#### TypeScript + ```ts function minScoreTriangulation(values: number[]): number { const n = values.length; diff --git a/solution/1000-1099/1039.Minimum Score Triangulation of Polygon/README_EN.md b/solution/1000-1099/1039.Minimum Score Triangulation of Polygon/README_EN.md index bad7d3b9cd8dc..34e695ae0722b 100644 --- a/solution/1000-1099/1039.Minimum Score Triangulation of Polygon/README_EN.md +++ b/solution/1000-1099/1039.Minimum Score Triangulation of Polygon/README_EN.md @@ -70,6 +70,8 @@ The minimum score is 144. +#### Python3 + ```python class Solution: def minScoreTriangulation(self, values: List[int]) -> int: @@ -85,6 +87,8 @@ class Solution: return dfs(0, len(values) - 1) ``` +#### Java + ```java class Solution { private int n; @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func minScoreTriangulation(values []int) int { n := len(values) @@ -161,6 +169,8 @@ func minScoreTriangulation(values []int) int { } ``` +#### TypeScript + ```ts function minScoreTriangulation(values: number[]): number { const n = values.length; @@ -193,6 +203,8 @@ function minScoreTriangulation(values: number[]): number { +#### Python3 + ```python class Solution: def minScoreTriangulation(self, values: List[int]) -> int: @@ -207,6 +219,8 @@ class Solution: return f[0][-1] ``` +#### Java + ```java class Solution { public int minScoreTriangulation(int[] values) { @@ -226,6 +240,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -246,6 +262,8 @@ public: }; ``` +#### Go + ```go func minScoreTriangulation(values []int) int { n := len(values) @@ -262,6 +280,8 @@ func minScoreTriangulation(values []int) int { } ``` +#### TypeScript + ```ts function minScoreTriangulation(values: number[]): number { const n = values.length; @@ -288,6 +308,8 @@ function minScoreTriangulation(values: number[]): number { +#### Python3 + ```python class Solution: def minScoreTriangulation(self, values: List[int]) -> int: @@ -303,6 +325,8 @@ class Solution: return f[0][-1] ``` +#### Java + ```java class Solution { public int minScoreTriangulation(int[] values) { @@ -323,6 +347,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -344,6 +370,8 @@ public: }; ``` +#### Go + ```go func minScoreTriangulation(values []int) int { n := len(values) @@ -361,6 +389,8 @@ func minScoreTriangulation(values []int) int { } ``` +#### TypeScript + ```ts function minScoreTriangulation(values: number[]): number { const n = values.length; diff --git a/solution/1000-1099/1040.Moving Stones Until Consecutive II/README.md b/solution/1000-1099/1040.Moving Stones Until Consecutive II/README.md index 19179638514d9..fbab0c0b9799b 100644 --- a/solution/1000-1099/1040.Moving Stones Until Consecutive II/README.md +++ b/solution/1000-1099/1040.Moving Stones Until Consecutive II/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class Solution: def numMovesStonesII(self, stones: List[int]) -> List[int]: @@ -111,6 +113,8 @@ class Solution: return [mi, mx] ``` +#### Java + ```java class Solution { public int[] numMovesStonesII(int[] stones) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func numMovesStonesII(stones []int) []int { sort.Ints(stones) @@ -177,6 +185,8 @@ func numMovesStonesII(stones []int) []int { } ``` +#### TypeScript + ```ts function numMovesStonesII(stones: number[]): number[] { stones.sort((a, b) => a - b); diff --git a/solution/1000-1099/1040.Moving Stones Until Consecutive II/README_EN.md b/solution/1000-1099/1040.Moving Stones Until Consecutive II/README_EN.md index 4bdf05e526a3a..45a632aef298e 100644 --- a/solution/1000-1099/1040.Moving Stones Until Consecutive II/README_EN.md +++ b/solution/1000-1099/1040.Moving Stones Until Consecutive II/README_EN.md @@ -77,6 +77,8 @@ Notice we cannot move 10 -> 2 to finish the game, because that would be an il +#### Python3 + ```python class Solution: def numMovesStonesII(self, stones: List[int]) -> List[int]: @@ -94,6 +96,8 @@ class Solution: return [mi, mx] ``` +#### Java + ```java class Solution { public int[] numMovesStonesII(int[] stones) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func numMovesStonesII(stones []int) []int { sort.Ints(stones) @@ -160,6 +168,8 @@ func numMovesStonesII(stones []int) []int { } ``` +#### TypeScript + ```ts function numMovesStonesII(stones: number[]): number[] { stones.sort((a, b) => a - b); diff --git a/solution/1000-1099/1041.Robot Bounded In Circle/README.md b/solution/1000-1099/1041.Robot Bounded In Circle/README.md index 2d885fb2eb0a4..ebba2ee50f149 100644 --- a/solution/1000-1099/1041.Robot Bounded In Circle/README.md +++ b/solution/1000-1099/1041.Robot Bounded In Circle/README.md @@ -124,6 +124,8 @@ tags: +#### Python3 + ```python class Solution: def isRobotBounded(self, instructions: str) -> bool: @@ -139,6 +141,8 @@ class Solution: return (dist[0] == dist[2] and dist[1] == dist[3]) or k != 0 ``` +#### Java + ```java class Solution { public boolean isRobotBounded(String instructions) { @@ -159,6 +163,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -179,6 +185,8 @@ public: }; ``` +#### Go + ```go func isRobotBounded(instructions string) bool { dist := [4]int{} @@ -196,6 +204,8 @@ func isRobotBounded(instructions string) bool { } ``` +#### TypeScript + ```ts function isRobotBounded(instructions: string): boolean { const dist: number[] = new Array(4).fill(0); diff --git a/solution/1000-1099/1041.Robot Bounded In Circle/README_EN.md b/solution/1000-1099/1041.Robot Bounded In Circle/README_EN.md index c148e11c3bfc3..a33cd28cfc5ff 100644 --- a/solution/1000-1099/1041.Robot Bounded In Circle/README_EN.md +++ b/solution/1000-1099/1041.Robot Bounded In Circle/README_EN.md @@ -106,6 +106,8 @@ Based on that, we return true. +#### Python3 + ```python class Solution: def isRobotBounded(self, instructions: str) -> bool: @@ -121,6 +123,8 @@ class Solution: return (dist[0] == dist[2] and dist[1] == dist[3]) or k != 0 ``` +#### Java + ```java class Solution { public boolean isRobotBounded(String instructions) { @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func isRobotBounded(instructions string) bool { dist := [4]int{} @@ -178,6 +186,8 @@ func isRobotBounded(instructions string) bool { } ``` +#### TypeScript + ```ts function isRobotBounded(instructions: string): boolean { const dist: number[] = new Array(4).fill(0); diff --git a/solution/1000-1099/1042.Flower Planting With No Adjacent/README.md b/solution/1000-1099/1042.Flower Planting With No Adjacent/README.md index 27f4bd6f90782..ee54ba5be9491 100644 --- a/solution/1000-1099/1042.Flower Planting With No Adjacent/README.md +++ b/solution/1000-1099/1042.Flower Planting With No Adjacent/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def gardenNoAdj(self, n: int, paths: List[List[int]]) -> List[int]: @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] gardenNoAdj(int n, int[][] paths) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func gardenNoAdj(n int, paths [][]int) []int { g := make([][]int, n) @@ -188,6 +196,8 @@ func gardenNoAdj(n int, paths [][]int) []int { } ``` +#### TypeScript + ```ts function gardenNoAdj(n: number, paths: number[][]): number[] { const g: number[][] = new Array(n).fill(0).map(() => []); diff --git a/solution/1000-1099/1042.Flower Planting With No Adjacent/README_EN.md b/solution/1000-1099/1042.Flower Planting With No Adjacent/README_EN.md index a606387c45c11..ea2ac2fd5070a 100644 --- a/solution/1000-1099/1042.Flower Planting With No Adjacent/README_EN.md +++ b/solution/1000-1099/1042.Flower Planting With No Adjacent/README_EN.md @@ -77,6 +77,8 @@ Hence, [1,2,3] is a valid answer. Other valid answers include [1,2,4], [1,4,2], +#### Python3 + ```python class Solution: def gardenNoAdj(self, n: int, paths: List[List[int]]) -> List[int]: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] gardenNoAdj(int n, int[][] paths) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func gardenNoAdj(n int, paths [][]int) []int { g := make([][]int, n) @@ -178,6 +186,8 @@ func gardenNoAdj(n int, paths [][]int) []int { } ``` +#### TypeScript + ```ts function gardenNoAdj(n: number, paths: number[][]): number[] { const g: number[][] = new Array(n).fill(0).map(() => []); diff --git a/solution/1000-1099/1043.Partition Array for Maximum Sum/README.md b/solution/1000-1099/1043.Partition Array for Maximum Sum/README.md index d08bbb068aac6..ebec5b810f337 100644 --- a/solution/1000-1099/1043.Partition Array for Maximum Sum/README.md +++ b/solution/1000-1099/1043.Partition Array for Maximum Sum/README.md @@ -80,6 +80,8 @@ $$ +#### Python3 + ```python class Solution: def maxSumAfterPartitioning(self, arr: List[int], k: int) -> int: @@ -93,6 +95,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int maxSumAfterPartitioning(int[] arr, int k) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func maxSumAfterPartitioning(arr []int, k int) int { n := len(arr) @@ -144,6 +152,8 @@ func maxSumAfterPartitioning(arr []int, k int) int { } ``` +#### TypeScript + ```ts function maxSumAfterPartitioning(arr: number[], k: number): number { const n: number = arr.length; diff --git a/solution/1000-1099/1043.Partition Array for Maximum Sum/README_EN.md b/solution/1000-1099/1043.Partition Array for Maximum Sum/README_EN.md index 05199d6e0a91f..5824c1ff403d6 100644 --- a/solution/1000-1099/1043.Partition Array for Maximum Sum/README_EN.md +++ b/solution/1000-1099/1043.Partition Array for Maximum Sum/README_EN.md @@ -79,6 +79,8 @@ The time complexity is $O(n \times k)$, and the space complexity is $O(n)$, wher +#### Python3 + ```python class Solution: def maxSumAfterPartitioning(self, arr: List[int], k: int) -> int: @@ -92,6 +94,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int maxSumAfterPartitioning(int[] arr, int k) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func maxSumAfterPartitioning(arr []int, k int) int { n := len(arr) @@ -143,6 +151,8 @@ func maxSumAfterPartitioning(arr []int, k int) int { } ``` +#### TypeScript + ```ts function maxSumAfterPartitioning(arr: number[], k: number): number { const n: number = arr.length; diff --git a/solution/1000-1099/1044.Longest Duplicate Substring/README.md b/solution/1000-1099/1044.Longest Duplicate Substring/README.md index e9d2acd81792c..976b2aadf6380 100644 --- a/solution/1000-1099/1044.Longest Duplicate Substring/README.md +++ b/solution/1000-1099/1044.Longest Duplicate Substring/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def longestDupSubstring(self, s: str) -> str: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private long[] p; @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp typedef unsigned long long ULL; @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go func longestDupSubstring(s string) string { base, n := 131, len(s) diff --git a/solution/1000-1099/1044.Longest Duplicate Substring/README_EN.md b/solution/1000-1099/1044.Longest Duplicate Substring/README_EN.md index 04b579be11f15..4f2e4d0734189 100644 --- a/solution/1000-1099/1044.Longest Duplicate Substring/README_EN.md +++ b/solution/1000-1099/1044.Longest Duplicate Substring/README_EN.md @@ -53,6 +53,8 @@ tags: +#### Python3 + ```python class Solution: def longestDupSubstring(self, s: str) -> str: @@ -79,6 +81,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private long[] p; @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp typedef unsigned long long ULL; @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func longestDupSubstring(s string) string { base, n := 131, len(s) diff --git a/solution/1000-1099/1045.Customers Who Bought All Products/README.md b/solution/1000-1099/1045.Customers Who Bought All Products/README.md index fbb023ffb6569..00ce6b69d5eef 100644 --- a/solution/1000-1099/1045.Customers Who Bought All Products/README.md +++ b/solution/1000-1099/1045.Customers Who Bought All Products/README.md @@ -95,6 +95,8 @@ Product 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT customer_id diff --git a/solution/1000-1099/1045.Customers Who Bought All Products/README_EN.md b/solution/1000-1099/1045.Customers Who Bought All Products/README_EN.md index dd267a2b7b16a..be4adede3f7f7 100644 --- a/solution/1000-1099/1045.Customers Who Bought All Products/README_EN.md +++ b/solution/1000-1099/1045.Customers Who Bought All Products/README_EN.md @@ -96,6 +96,8 @@ We can group the `Customer` table by `customer_id`, and then use the `HAVING` cl +#### MySQL + ```sql # Write your MySQL query statement below SELECT customer_id diff --git a/solution/1000-1099/1046.Last Stone Weight/README.md b/solution/1000-1099/1046.Last Stone Weight/README.md index e251406f1b483..805d5787cb803 100644 --- a/solution/1000-1099/1046.Last Stone Weight/README.md +++ b/solution/1000-1099/1046.Last Stone Weight/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def lastStoneWeight(self, stones: List[int]) -> int: @@ -80,6 +82,8 @@ class Solution: return 0 if not h else -h[0] ``` +#### Java + ```java class Solution { public int lastStoneWeight(int[] stones) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func lastStoneWeight(stones []int) int { q := &hp{stones} @@ -151,6 +159,8 @@ func (h *hp) push(v int) { heap.Push(h, v) } func (h *hp) pop() int { return heap.Pop(h).(int) } ``` +#### TypeScript + ```ts function lastStoneWeight(stones: number[]): number { const pq = new MaxPriorityQueue(); @@ -168,6 +178,8 @@ function lastStoneWeight(stones: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} stones diff --git a/solution/1000-1099/1046.Last Stone Weight/README_EN.md b/solution/1000-1099/1046.Last Stone Weight/README_EN.md index 74b5e0c178ea6..4cfa4d01b3945 100644 --- a/solution/1000-1099/1046.Last Stone Weight/README_EN.md +++ b/solution/1000-1099/1046.Last Stone Weight/README_EN.md @@ -70,6 +70,8 @@ we combine 1 and 1 to get 0 so the array converts to [1] then that's the val +#### Python3 + ```python class Solution: def lastStoneWeight(self, stones: List[int]) -> int: @@ -82,6 +84,8 @@ class Solution: return 0 if not h else -h[0] ``` +#### Java + ```java class Solution { public int lastStoneWeight(int[] stones) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func lastStoneWeight(stones []int) int { q := &hp{stones} @@ -153,6 +161,8 @@ func (h *hp) push(v int) { heap.Push(h, v) } func (h *hp) pop() int { return heap.Pop(h).(int) } ``` +#### TypeScript + ```ts function lastStoneWeight(stones: number[]): number { const pq = new MaxPriorityQueue(); @@ -170,6 +180,8 @@ function lastStoneWeight(stones: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} stones diff --git a/solution/1000-1099/1047.Remove All Adjacent Duplicates In String/README.md b/solution/1000-1099/1047.Remove All Adjacent Duplicates In String/README.md index 83eff336a8c2f..52a82a4546099 100644 --- a/solution/1000-1099/1047.Remove All Adjacent Duplicates In String/README.md +++ b/solution/1000-1099/1047.Remove All Adjacent Duplicates In String/README.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def removeDuplicates(self, s: str) -> str: @@ -72,6 +74,8 @@ class Solution: return ''.join(stk) ``` +#### Java + ```java class Solution { public String removeDuplicates(String s) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func removeDuplicates(s string) string { stk := []rune{} @@ -119,6 +127,8 @@ func removeDuplicates(s string) string { } ``` +#### Rust + ```rust impl Solution { pub fn remove_duplicates(s: String) -> String { @@ -135,6 +145,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -153,6 +165,8 @@ var removeDuplicates = function (s) { }; ``` +#### C + ```c char* removeDuplicates(char* s) { int n = strlen(s); diff --git a/solution/1000-1099/1047.Remove All Adjacent Duplicates In String/README_EN.md b/solution/1000-1099/1047.Remove All Adjacent Duplicates In String/README_EN.md index 13becec353b67..76903677f0415 100644 --- a/solution/1000-1099/1047.Remove All Adjacent Duplicates In String/README_EN.md +++ b/solution/1000-1099/1047.Remove All Adjacent Duplicates In String/README_EN.md @@ -60,6 +60,8 @@ For example, in "abbaca" we could remove "bb" since the lett +#### Python3 + ```python class Solution: def removeDuplicates(self, s: str) -> str: @@ -72,6 +74,8 @@ class Solution: return ''.join(stk) ``` +#### Java + ```java class Solution { public String removeDuplicates(String s) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func removeDuplicates(s string) string { stk := []rune{} @@ -119,6 +127,8 @@ func removeDuplicates(s string) string { } ``` +#### Rust + ```rust impl Solution { pub fn remove_duplicates(s: String) -> String { @@ -135,6 +145,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -153,6 +165,8 @@ var removeDuplicates = function (s) { }; ``` +#### C + ```c char* removeDuplicates(char* s) { int n = strlen(s); diff --git a/solution/1000-1099/1048.Longest String Chain/README.md b/solution/1000-1099/1048.Longest String Chain/README.md index 1a2cebfa03dfa..90372dadf45dd 100644 --- a/solution/1000-1099/1048.Longest String Chain/README.md +++ b/solution/1000-1099/1048.Longest String Chain/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def longestStrChain(self, words: List[str]) -> int: @@ -107,6 +109,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public int longestStrChain(String[] words) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func longestStrChain(words []string) int { sort.Slice(words, func(i, j int) bool { return len(words[i]) < len(words[j]) }) @@ -166,6 +174,8 @@ func longestStrChain(words []string) int { } ``` +#### TypeScript + ```ts function longestStrChain(words: string[]): number { words.sort((a, b) => a.length - b.length); @@ -184,6 +194,8 @@ function longestStrChain(words: string[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -228,6 +240,8 @@ impl Solution { +#### Python3 + ```python class Solution: def longestStrChain(self, words: List[str]) -> int: diff --git a/solution/1000-1099/1048.Longest String Chain/README_EN.md b/solution/1000-1099/1048.Longest String Chain/README_EN.md index 5d137f348ffc9..5dd4fb465bbc4 100644 --- a/solution/1000-1099/1048.Longest String Chain/README_EN.md +++ b/solution/1000-1099/1048.Longest String Chain/README_EN.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def longestStrChain(self, words: List[str]) -> int: @@ -106,6 +108,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public int longestStrChain(String[] words) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func longestStrChain(words []string) int { sort.Slice(words, func(i, j int) bool { return len(words[i]) < len(words[j]) }) @@ -165,6 +173,8 @@ func longestStrChain(words []string) int { } ``` +#### TypeScript + ```ts function longestStrChain(words: string[]): number { words.sort((a, b) => a.length - b.length); @@ -183,6 +193,8 @@ function longestStrChain(words: string[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -227,6 +239,8 @@ impl Solution { +#### Python3 + ```python class Solution: def longestStrChain(self, words: List[str]) -> int: diff --git a/solution/1000-1099/1049.Last Stone Weight II/README.md b/solution/1000-1099/1049.Last Stone Weight II/README.md index dea1b2539a0fd..f4e967bf9a2fe 100644 --- a/solution/1000-1099/1049.Last Stone Weight II/README.md +++ b/solution/1000-1099/1049.Last Stone Weight II/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def lastStoneWeightII(self, stones: List[int]) -> int: @@ -92,6 +94,8 @@ class Solution: return s - 2 * dp[-1][-1] ``` +#### Java + ```java class Solution { public int lastStoneWeightII(int[] stones) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func lastStoneWeightII(stones []int) int { s := 0 @@ -156,6 +164,8 @@ func lastStoneWeightII(stones []int) int { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -189,6 +199,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} stones @@ -220,6 +232,8 @@ var lastStoneWeightII = function (stones) { +#### Python3 + ```python class Solution: def lastStoneWeightII(self, stones: List[int]) -> int: @@ -232,6 +246,8 @@ class Solution: return s - dp[-1] * 2 ``` +#### Java + ```java class Solution { public int lastStoneWeightII(int[] stones) { @@ -252,6 +268,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -267,6 +285,8 @@ public: }; ``` +#### Go + ```go func lastStoneWeightII(stones []int) int { s := 0 diff --git a/solution/1000-1099/1049.Last Stone Weight II/README_EN.md b/solution/1000-1099/1049.Last Stone Weight II/README_EN.md index 40e164115915f..0eb170351b600 100644 --- a/solution/1000-1099/1049.Last Stone Weight II/README_EN.md +++ b/solution/1000-1099/1049.Last Stone Weight II/README_EN.md @@ -70,6 +70,8 @@ we can combine 1 and 1 to get 0, so the array converts to [1], then that's t +#### Python3 + ```python class Solution: def lastStoneWeightII(self, stones: List[int]) -> int: @@ -86,6 +88,8 @@ class Solution: return s - 2 * dp[-1][-1] ``` +#### Java + ```java class Solution { public int lastStoneWeightII(int[] stones) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func lastStoneWeightII(stones []int) int { s := 0 @@ -150,6 +158,8 @@ func lastStoneWeightII(stones []int) int { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -183,6 +193,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} stones @@ -214,6 +226,8 @@ var lastStoneWeightII = function (stones) { +#### Python3 + ```python class Solution: def lastStoneWeightII(self, stones: List[int]) -> int: @@ -226,6 +240,8 @@ class Solution: return s - dp[-1] * 2 ``` +#### Java + ```java class Solution { public int lastStoneWeightII(int[] stones) { @@ -246,6 +262,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -261,6 +279,8 @@ public: }; ``` +#### Go + ```go func lastStoneWeightII(stones []int) int { s := 0 diff --git a/solution/1000-1099/1050.Actors and Directors Who Cooperated At Least Three Times/README.md b/solution/1000-1099/1050.Actors and Directors Who Cooperated At Least Three Times/README.md index f8bc6c1898e33..da1649fa8e81a 100644 --- a/solution/1000-1099/1050.Actors and Directors Who Cooperated At Least Three Times/README.md +++ b/solution/1000-1099/1050.Actors and Directors Who Cooperated At Least Three Times/README.md @@ -72,6 +72,8 @@ ActorDirector 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT actor_id, director_id diff --git a/solution/1000-1099/1050.Actors and Directors Who Cooperated At Least Three Times/README_EN.md b/solution/1000-1099/1050.Actors and Directors Who Cooperated At Least Three Times/README_EN.md index c33648e326e37..ae1d72122fc94 100644 --- a/solution/1000-1099/1050.Actors and Directors Who Cooperated At Least Three Times/README_EN.md +++ b/solution/1000-1099/1050.Actors and Directors Who Cooperated At Least Three Times/README_EN.md @@ -75,6 +75,8 @@ We can use the `GROUP BY` statement to group the data by the `actor_id` and `dir +#### MySQL + ```sql # Write your MySQL query statement below SELECT actor_id, director_id diff --git a/solution/1000-1099/1051.Height Checker/README.md b/solution/1000-1099/1051.Height Checker/README.md index 78ee88df59f8b..62373d2b8691c 100644 --- a/solution/1000-1099/1051.Height Checker/README.md +++ b/solution/1000-1099/1051.Height Checker/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def heightChecker(self, heights: List[int]) -> int: @@ -90,6 +92,8 @@ class Solution: return sum(a != b for a, b in zip(heights, expected)) ``` +#### Java + ```java class Solution { public int heightChecker(int[] heights) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func heightChecker(heights []int) int { expected := make([]int, len(heights)) @@ -148,6 +156,8 @@ func heightChecker(heights []int) int { +#### Python3 + ```python class Solution: def heightChecker(self, heights: List[int]) -> int: @@ -164,6 +174,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int heightChecker(int[] heights) { @@ -185,6 +197,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -203,6 +217,8 @@ public: }; ``` +#### Go + ```go func heightChecker(heights []int) int { cnt := make([]int, 101) diff --git a/solution/1000-1099/1051.Height Checker/README_EN.md b/solution/1000-1099/1051.Height Checker/README_EN.md index 65eb551ea6069..81ce3c20e19a1 100644 --- a/solution/1000-1099/1051.Height Checker/README_EN.md +++ b/solution/1000-1099/1051.Height Checker/README_EN.md @@ -78,6 +78,8 @@ All indices match. +#### Python3 + ```python class Solution: def heightChecker(self, heights: List[int]) -> int: @@ -85,6 +87,8 @@ class Solution: return sum(a != b for a, b in zip(heights, expected)) ``` +#### Java + ```java class Solution { public int heightChecker(int[] heights) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func heightChecker(heights []int) int { expected := make([]int, len(heights)) @@ -139,6 +147,8 @@ func heightChecker(heights []int) int { +#### Python3 + ```python class Solution: def heightChecker(self, heights: List[int]) -> int: @@ -155,6 +165,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int heightChecker(int[] heights) { @@ -176,6 +188,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -194,6 +208,8 @@ public: }; ``` +#### Go + ```go func heightChecker(heights []int) int { cnt := make([]int, 101) diff --git a/solution/1000-1099/1052.Grumpy Bookstore Owner/README.md b/solution/1000-1099/1052.Grumpy Bookstore Owner/README.md index c61e9c1736815..a2858cd1439ff 100644 --- a/solution/1000-1099/1052.Grumpy Bookstore Owner/README.md +++ b/solution/1000-1099/1052.Grumpy Bookstore Owner/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def maxSatisfied( @@ -87,6 +89,8 @@ class Solution: return sum(c * (g ^ 1) for c, g in zip(customers, grumpy)) + mx ``` +#### Java + ```java class Solution { public int maxSatisfied(int[] customers, int[] grumpy, int minutes) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func maxSatisfied(customers []int, grumpy []int, minutes int) int { var cnt, tot int @@ -150,6 +158,8 @@ func maxSatisfied(customers []int, grumpy []int, minutes int) int { } ``` +#### TypeScript + ```ts function maxSatisfied(customers: number[], grumpy: number[], minutes: number): number { let [cnt, tot] = [0, 0]; @@ -168,6 +178,8 @@ function maxSatisfied(customers: number[], grumpy: number[], minutes: number): n } ``` +#### Rust + ```rust impl Solution { pub fn max_satisfied(customers: Vec, grumpy: Vec, minutes: i32) -> i32 { diff --git a/solution/1000-1099/1052.Grumpy Bookstore Owner/README_EN.md b/solution/1000-1099/1052.Grumpy Bookstore Owner/README_EN.md index 2b71da02ddec3..68a5c920b0c3c 100644 --- a/solution/1000-1099/1052.Grumpy Bookstore Owner/README_EN.md +++ b/solution/1000-1099/1052.Grumpy Bookstore Owner/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array `customers`. +#### Python3 + ```python class Solution: def maxSatisfied( @@ -87,6 +89,8 @@ class Solution: return sum(c * (g ^ 1) for c, g in zip(customers, grumpy)) + mx ``` +#### Java + ```java class Solution { public int maxSatisfied(int[] customers, int[] grumpy, int minutes) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func maxSatisfied(customers []int, grumpy []int, minutes int) int { var cnt, tot int @@ -150,6 +158,8 @@ func maxSatisfied(customers []int, grumpy []int, minutes int) int { } ``` +#### TypeScript + ```ts function maxSatisfied(customers: number[], grumpy: number[], minutes: number): number { let [cnt, tot] = [0, 0]; @@ -168,6 +178,8 @@ function maxSatisfied(customers: number[], grumpy: number[], minutes: number): n } ``` +#### Rust + ```rust impl Solution { pub fn max_satisfied(customers: Vec, grumpy: Vec, minutes: i32) -> i32 { diff --git a/solution/1000-1099/1053.Previous Permutation With One Swap/README.md b/solution/1000-1099/1053.Previous Permutation With One Swap/README.md index 84f075bb890d0..bfda3e5da26a9 100644 --- a/solution/1000-1099/1053.Previous Permutation With One Swap/README.md +++ b/solution/1000-1099/1053.Previous Permutation With One Swap/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def prevPermOpt1(self, arr: List[int]) -> List[int]: @@ -87,6 +89,8 @@ class Solution: return arr ``` +#### Java + ```java class Solution { public int[] prevPermOpt1(int[] arr) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func prevPermOpt1(arr []int) []int { n := len(arr) @@ -145,6 +153,8 @@ func prevPermOpt1(arr []int) []int { } ``` +#### TypeScript + ```ts function prevPermOpt1(arr: number[]): number[] { const n = arr.length; diff --git a/solution/1000-1099/1053.Previous Permutation With One Swap/README_EN.md b/solution/1000-1099/1053.Previous Permutation With One Swap/README_EN.md index c93279da304d6..2dd2aacaf4f08 100644 --- a/solution/1000-1099/1053.Previous Permutation With One Swap/README_EN.md +++ b/solution/1000-1099/1053.Previous Permutation With One Swap/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def prevPermOpt1(self, arr: List[int]) -> List[int]: @@ -85,6 +87,8 @@ class Solution: return arr ``` +#### Java + ```java class Solution { public int[] prevPermOpt1(int[] arr) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func prevPermOpt1(arr []int) []int { n := len(arr) @@ -143,6 +151,8 @@ func prevPermOpt1(arr []int) []int { } ``` +#### TypeScript + ```ts function prevPermOpt1(arr: number[]): number[] { const n = arr.length; diff --git a/solution/1000-1099/1054.Distant Barcodes/README.md b/solution/1000-1099/1054.Distant Barcodes/README.md index 047737dff4530..7c24a1d90cf1f 100644 --- a/solution/1000-1099/1054.Distant Barcodes/README.md +++ b/solution/1000-1099/1054.Distant Barcodes/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def rearrangeBarcodes(self, barcodes: List[int]) -> List[int]: @@ -79,6 +81,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] rearrangeBarcodes(int[] barcodes) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func rearrangeBarcodes(barcodes []int) []int { mx := slices.Max(barcodes) @@ -155,6 +163,8 @@ func rearrangeBarcodes(barcodes []int) []int { } ``` +#### TypeScript + ```ts function rearrangeBarcodes(barcodes: number[]): number[] { const mx = Math.max(...barcodes); diff --git a/solution/1000-1099/1054.Distant Barcodes/README_EN.md b/solution/1000-1099/1054.Distant Barcodes/README_EN.md index f4363f05df1bf..b50fec6470237 100644 --- a/solution/1000-1099/1054.Distant Barcodes/README_EN.md +++ b/solution/1000-1099/1054.Distant Barcodes/README_EN.md @@ -59,6 +59,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(M)$. +#### Python3 + ```python class Solution: def rearrangeBarcodes(self, barcodes: List[int]) -> List[int]: @@ -71,6 +73,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] rearrangeBarcodes(int[] barcodes) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func rearrangeBarcodes(barcodes []int) []int { mx := slices.Max(barcodes) @@ -147,6 +155,8 @@ func rearrangeBarcodes(barcodes []int) []int { } ``` +#### TypeScript + ```ts function rearrangeBarcodes(barcodes: number[]): number[] { const mx = Math.max(...barcodes); diff --git a/solution/1000-1099/1055.Shortest Way to Form String/README.md b/solution/1000-1099/1055.Shortest Way to Form String/README.md index f730e992ccf7b..5758f5ec5725f 100644 --- a/solution/1000-1099/1055.Shortest Way to Form String/README.md +++ b/solution/1000-1099/1055.Shortest Way to Form String/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def shortestWay(self, source: str, target: str) -> int: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int shortestWay(String source, String target) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func shortestWay(source string, target string) int { m, n := len(source), len(target) diff --git a/solution/1000-1099/1055.Shortest Way to Form String/README_EN.md b/solution/1000-1099/1055.Shortest Way to Form String/README_EN.md index dbeac1cafb30f..c15d06aae9335 100644 --- a/solution/1000-1099/1055.Shortest Way to Form String/README_EN.md +++ b/solution/1000-1099/1055.Shortest Way to Form String/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(m \times n)$, where $m$ and $n$ are the lengths of the +#### Python3 + ```python class Solution: def shortestWay(self, source: str, target: str) -> int: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int shortestWay(String source, String target) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func shortestWay(source string, target string) int { m, n := len(source), len(target) diff --git a/solution/1000-1099/1056.Confusing Number/README.md b/solution/1000-1099/1056.Confusing Number/README.md index 1c9000318c7f5..a7b18c9cb6675 100644 --- a/solution/1000-1099/1056.Confusing Number/README.md +++ b/solution/1000-1099/1056.Confusing Number/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def confusingNumber(self, n: int) -> bool: @@ -104,6 +106,8 @@ class Solution: return y != n ``` +#### Java + ```java class Solution { public boolean confusingNumber(int n) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func confusingNumber(n int) bool { d := []int{0, 1, -1, -1, -1, -1, 9, -1, 8, 6} @@ -157,6 +165,8 @@ func confusingNumber(n int) bool { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1000-1099/1056.Confusing Number/README_EN.md b/solution/1000-1099/1056.Confusing Number/README_EN.md index 04c0ea6074d0f..a8741e0cd20ff 100644 --- a/solution/1000-1099/1056.Confusing Number/README_EN.md +++ b/solution/1000-1099/1056.Confusing Number/README_EN.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def confusingNumber(self, n: int) -> bool: @@ -88,6 +90,8 @@ class Solution: return y != n ``` +#### Java + ```java class Solution { public boolean confusingNumber(int n) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func confusingNumber(n int) bool { d := []int{0, 1, -1, -1, -1, -1, 9, -1, 8, 6} @@ -141,6 +149,8 @@ func confusingNumber(n int) bool { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1000-1099/1057.Campus Bikes/README.md b/solution/1000-1099/1057.Campus Bikes/README.md index d75238ecd72f3..9b2487002b8ed 100644 --- a/solution/1000-1099/1057.Campus Bikes/README.md +++ b/solution/1000-1099/1057.Campus Bikes/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def assignBikes( @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] assignBikes(int[][] workers, int[][] bikes) { @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func assignBikes(workers [][]int, bikes [][]int) []int { n, m := len(workers), len(bikes) diff --git a/solution/1000-1099/1057.Campus Bikes/README_EN.md b/solution/1000-1099/1057.Campus Bikes/README_EN.md index 7091256f7037b..fb5f022c138ff 100644 --- a/solution/1000-1099/1057.Campus Bikes/README_EN.md +++ b/solution/1000-1099/1057.Campus Bikes/README_EN.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def assignBikes( @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] assignBikes(int[][] workers, int[][] bikes) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func assignBikes(workers [][]int, bikes [][]int) []int { n, m := len(workers), len(bikes) diff --git a/solution/1000-1099/1058.Minimize Rounding Error to Meet Target/README.md b/solution/1000-1099/1058.Minimize Rounding Error to Meet Target/README.md index 906885c1049cf..473e9190b2267 100644 --- a/solution/1000-1099/1058.Minimize Rounding Error to Meet Target/README.md +++ b/solution/1000-1099/1058.Minimize Rounding Error to Meet Target/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def minimizeError(self, prices: List[str], target: int) -> str: @@ -96,6 +98,8 @@ class Solution: return f'{ans:.3f}' ``` +#### Java + ```java class Solution { public String minimizeError(String[] prices, int target) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func minimizeError(prices []string, target int) string { arr := []float64{} diff --git a/solution/1000-1099/1058.Minimize Rounding Error to Meet Target/README_EN.md b/solution/1000-1099/1058.Minimize Rounding Error to Meet Target/README_EN.md index 73b640ca86372..608f4e6cc9dbf 100644 --- a/solution/1000-1099/1058.Minimize Rounding Error to Meet Target/README_EN.md +++ b/solution/1000-1099/1058.Minimize Rounding Error to Meet Target/README_EN.md @@ -68,6 +68,8 @@ Use Floor, Ceil and Ceil operations to get (0.7 - 0) + (3 - 2.8) + (5 - 4.9) = 0 +#### Python3 + ```python class Solution: def minimizeError(self, prices: List[str], target: int) -> str: @@ -86,6 +88,8 @@ class Solution: return f'{ans:.3f}' ``` +#### Java + ```java class Solution { public String minimizeError(String[] prices, int target) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func minimizeError(prices []string, target int) string { arr := []float64{} diff --git a/solution/1000-1099/1059.All Paths from Source Lead to Destination/README.md b/solution/1000-1099/1059.All Paths from Source Lead to Destination/README.md index e0553ad1baafd..6d1a16a13074b 100644 --- a/solution/1000-1099/1059.All Paths from Source Lead to Destination/README.md +++ b/solution/1000-1099/1059.All Paths from Source Lead to Destination/README.md @@ -98,6 +98,8 @@ tags: +#### Python3 + ```python class Solution: def leadsToDestination( @@ -122,6 +124,8 @@ class Solution: return dfs(source) ``` +#### Java + ```java class Solution { private List[] g; @@ -164,6 +168,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -199,6 +205,8 @@ public: }; ``` +#### Go + ```go func leadsToDestination(n int, edges [][]int, source int, destination int) bool { vis := make([]bool, n) diff --git a/solution/1000-1099/1059.All Paths from Source Lead to Destination/README_EN.md b/solution/1000-1099/1059.All Paths from Source Lead to Destination/README_EN.md index 667482713be95..e5e4345f6d2ef 100644 --- a/solution/1000-1099/1059.All Paths from Source Lead to Destination/README_EN.md +++ b/solution/1000-1099/1059.All Paths from Source Lead to Destination/README_EN.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def leadsToDestination( @@ -98,6 +100,8 @@ class Solution: return dfs(source) ``` +#### Java + ```java class Solution { private List[] g; @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go func leadsToDestination(n int, edges [][]int, source int, destination int) bool { vis := make([]bool, n) diff --git a/solution/1000-1099/1060.Missing Element in Sorted Array/README.md b/solution/1000-1099/1060.Missing Element in Sorted Array/README.md index cb41934a8e776..03c573678a54c 100644 --- a/solution/1000-1099/1060.Missing Element in Sorted Array/README.md +++ b/solution/1000-1099/1060.Missing Element in Sorted Array/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def missingElement(self, nums: List[int], k: int) -> int: @@ -95,6 +97,8 @@ class Solution: return nums[l - 1] + k - missing(l - 1) ``` +#### Java + ```java class Solution { public int missingElement(int[] nums, int k) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func missingElement(nums []int, k int) int { missing := func(i int) int { diff --git a/solution/1000-1099/1060.Missing Element in Sorted Array/README_EN.md b/solution/1000-1099/1060.Missing Element in Sorted Array/README_EN.md index 12a7f28499fc3..92a9436fe4020 100644 --- a/solution/1000-1099/1060.Missing Element in Sorted Array/README_EN.md +++ b/solution/1000-1099/1060.Missing Element in Sorted Array/README_EN.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def missingElement(self, nums: List[int], k: int) -> int: @@ -86,6 +88,8 @@ class Solution: return nums[l - 1] + k - missing(l - 1) ``` +#### Java + ```java class Solution { public int missingElement(int[] nums, int k) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func missingElement(nums []int, k int) int { missing := func(i int) int { diff --git a/solution/1000-1099/1061.Lexicographically Smallest Equivalent String/README.md b/solution/1000-1099/1061.Lexicographically Smallest Equivalent String/README.md index dbf472bc4b024..514efdb001b2d 100644 --- a/solution/1000-1099/1061.Lexicographically Smallest Equivalent String/README.md +++ b/solution/1000-1099/1061.Lexicographically Smallest Equivalent String/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def smallestEquivalentString(self, s1: str, s2: str, baseStr: str) -> str: @@ -108,6 +110,8 @@ class Solution: return ''.join(res) ``` +#### Java + ```java class Solution { private int[] p; @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go var p []int diff --git a/solution/1000-1099/1061.Lexicographically Smallest Equivalent String/README_EN.md b/solution/1000-1099/1061.Lexicographically Smallest Equivalent String/README_EN.md index 3484a0cdd374a..9b73a44e6f5b1 100644 --- a/solution/1000-1099/1061.Lexicographically Smallest Equivalent String/README_EN.md +++ b/solution/1000-1099/1061.Lexicographically Smallest Equivalent String/README_EN.md @@ -84,6 +84,8 @@ So only the second letter 'o' in baseStr is changed to 'd', the +#### Python3 + ```python class Solution: def smallestEquivalentString(self, s1: str, s2: str, baseStr: str) -> str: @@ -109,6 +111,8 @@ class Solution: return ''.join(res) ``` +#### Java + ```java class Solution { private int[] p; @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go var p []int diff --git a/solution/1000-1099/1062.Longest Repeating Substring/README.md b/solution/1000-1099/1062.Longest Repeating Substring/README.md index 6dfec29a82df5..234152076f8c1 100644 --- a/solution/1000-1099/1062.Longest Repeating Substring/README.md +++ b/solution/1000-1099/1062.Longest Repeating Substring/README.md @@ -90,6 +90,8 @@ $$ +#### Python3 + ```python class Solution: def longestRepeatingSubstring(self, s: str) -> int: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestRepeatingSubstring(String s) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func longestRepeatingSubstring(s string) int { n := len(s) diff --git a/solution/1000-1099/1062.Longest Repeating Substring/README_EN.md b/solution/1000-1099/1062.Longest Repeating Substring/README_EN.md index d4d59faf86b6a..c6f581a644da9 100644 --- a/solution/1000-1099/1062.Longest Repeating Substring/README_EN.md +++ b/solution/1000-1099/1062.Longest Repeating Substring/README_EN.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def longestRepeatingSubstring(self, s: str) -> int: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestRepeatingSubstring(String s) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func longestRepeatingSubstring(s string) int { n := len(s) diff --git a/solution/1000-1099/1063.Number of Valid Subarrays/README.md b/solution/1000-1099/1063.Number of Valid Subarrays/README.md index 16bafe0218780..3927da403ce3a 100644 --- a/solution/1000-1099/1063.Number of Valid Subarrays/README.md +++ b/solution/1000-1099/1063.Number of Valid Subarrays/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def validSubarrays(self, nums: List[int]) -> int: @@ -93,6 +95,8 @@ class Solution: return sum(j - i for i, j in enumerate(right)) ``` +#### Java + ```java class Solution { public int validSubarrays(int[] nums) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func validSubarrays(nums []int) (ans int) { n := len(nums) @@ -167,6 +175,8 @@ func validSubarrays(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function validSubarrays(nums: number[]): number { const n = nums.length; @@ -199,6 +209,8 @@ function validSubarrays(nums: number[]): number { +#### Python3 + ```python class Solution: def validSubarrays(self, nums: List[int]) -> int: @@ -213,6 +225,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int validSubarrays(int[] nums) { @@ -232,6 +246,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -251,6 +267,8 @@ public: }; ``` +#### Go + ```go func validSubarrays(nums []int) (ans int) { n := len(nums) @@ -271,6 +289,8 @@ func validSubarrays(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function validSubarrays(nums: number[]): number { const n = nums.length; diff --git a/solution/1000-1099/1063.Number of Valid Subarrays/README_EN.md b/solution/1000-1099/1063.Number of Valid Subarrays/README_EN.md index 0f2794c1f0a17..e809b503ef3ba 100644 --- a/solution/1000-1099/1063.Number of Valid Subarrays/README_EN.md +++ b/solution/1000-1099/1063.Number of Valid Subarrays/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def validSubarrays(self, nums: List[int]) -> int: @@ -80,6 +82,8 @@ class Solution: return sum(j - i for i, j in enumerate(right)) ``` +#### Java + ```java class Solution { public int validSubarrays(int[] nums) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func validSubarrays(nums []int) (ans int) { n := len(nums) @@ -154,6 +162,8 @@ func validSubarrays(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function validSubarrays(nums: number[]): number { const n = nums.length; @@ -186,6 +196,8 @@ function validSubarrays(nums: number[]): number { +#### Python3 + ```python class Solution: def validSubarrays(self, nums: List[int]) -> int: @@ -200,6 +212,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int validSubarrays(int[] nums) { @@ -219,6 +233,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -238,6 +254,8 @@ public: }; ``` +#### Go + ```go func validSubarrays(nums []int) (ans int) { n := len(nums) @@ -258,6 +276,8 @@ func validSubarrays(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function validSubarrays(nums: number[]): number { const n = nums.length; diff --git a/solution/1000-1099/1064.Fixed Point/README.md b/solution/1000-1099/1064.Fixed Point/README.md index 5a59456349669..0eb54961b4487 100644 --- a/solution/1000-1099/1064.Fixed Point/README.md +++ b/solution/1000-1099/1064.Fixed Point/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def fixedPoint(self, arr: List[int]) -> int: @@ -91,6 +93,8 @@ class Solution: return left if arr[left] == left else -1 ``` +#### Java + ```java class Solution { public int fixedPoint(int[] arr) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func fixedPoint(arr []int) int { left, right := 0, len(arr)-1 @@ -144,6 +152,8 @@ func fixedPoint(arr []int) int { } ``` +#### TypeScript + ```ts function fixedPoint(arr: number[]): number { let left = 0; diff --git a/solution/1000-1099/1064.Fixed Point/README_EN.md b/solution/1000-1099/1064.Fixed Point/README_EN.md index 995f28fd28ed8..ce99e13435b28 100644 --- a/solution/1000-1099/1064.Fixed Point/README_EN.md +++ b/solution/1000-1099/1064.Fixed Point/README_EN.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def fixedPoint(self, arr: List[int]) -> int: @@ -77,6 +79,8 @@ class Solution: return left if arr[left] == left else -1 ``` +#### Java + ```java class Solution { public int fixedPoint(int[] arr) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func fixedPoint(arr []int) int { left, right := 0, len(arr)-1 @@ -130,6 +138,8 @@ func fixedPoint(arr []int) int { } ``` +#### TypeScript + ```ts function fixedPoint(arr: number[]): number { let left = 0; diff --git a/solution/1000-1099/1065.Index Pairs of a String/README.md b/solution/1000-1099/1065.Index Pairs of a String/README.md index b70c1c013c90f..343aae9696a08 100644 --- a/solution/1000-1099/1065.Index Pairs of a String/README.md +++ b/solution/1000-1099/1065.Index Pairs of a String/README.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def indexPairs(self, text: str, words: List[str]) -> List[List[int]]: @@ -72,6 +74,8 @@ class Solution: ] ``` +#### Java + ```java class Trie { Trie[] children = new Trie[26]; @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [26]*Trie @@ -219,6 +227,8 @@ func indexPairs(text string, words []string) [][]int { +#### Python3 + ```python class Trie: def __init__(self): diff --git a/solution/1000-1099/1065.Index Pairs of a String/README_EN.md b/solution/1000-1099/1065.Index Pairs of a String/README_EN.md index c7946b7b7259e..cb6005a248dd6 100644 --- a/solution/1000-1099/1065.Index Pairs of a String/README_EN.md +++ b/solution/1000-1099/1065.Index Pairs of a String/README_EN.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def indexPairs(self, text: str, words: List[str]) -> List[List[int]]: @@ -72,6 +74,8 @@ class Solution: ] ``` +#### Java + ```java class Trie { Trie[] children = new Trie[26]; @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [26]*Trie @@ -214,6 +222,8 @@ func indexPairs(text string, words []string) [][]int { +#### Python3 + ```python class Trie: def __init__(self): diff --git a/solution/1000-1099/1066.Campus Bikes II/README.md b/solution/1000-1099/1066.Campus Bikes II/README.md index 42bba1a28e360..3d5d1aae982ae 100644 --- a/solution/1000-1099/1066.Campus Bikes II/README.md +++ b/solution/1000-1099/1066.Campus Bikes II/README.md @@ -97,6 +97,8 @@ $$ +#### Python3 + ```python class Solution: def assignBikes(self, workers: List[List[int]], bikes: List[List[int]]) -> int: @@ -114,6 +116,8 @@ class Solution: return min(f[n]) ``` +#### Java + ```java class Solution { public int assignBikes(int[][] workers, int[][] bikes) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func assignBikes(workers [][]int, bikes [][]int) int { n, m := len(workers), len(bikes) @@ -196,6 +204,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function assignBikes(workers: number[][], bikes: number[][]): number { const n = workers.length; diff --git a/solution/1000-1099/1066.Campus Bikes II/README_EN.md b/solution/1000-1099/1066.Campus Bikes II/README_EN.md index 258b896aaf821..c8a9a13e6d1b7 100644 --- a/solution/1000-1099/1066.Campus Bikes II/README_EN.md +++ b/solution/1000-1099/1066.Campus Bikes II/README_EN.md @@ -79,6 +79,8 @@ We first assign bike 0 to worker 0, then assign bike 1 to worker 1 or worker 2, +#### Python3 + ```python class Solution: def assignBikes(self, workers: List[List[int]], bikes: List[List[int]]) -> int: @@ -96,6 +98,8 @@ class Solution: return min(f[n]) ``` +#### Java + ```java class Solution { public int assignBikes(int[][] workers, int[][] bikes) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func assignBikes(workers [][]int, bikes [][]int) int { n, m := len(workers), len(bikes) @@ -178,6 +186,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function assignBikes(workers: number[][], bikes: number[][]): number { const n = workers.length; diff --git a/solution/1000-1099/1067.Digit Count in Range/README.md b/solution/1000-1099/1067.Digit Count in Range/README.md index 4a694b135e54b..15fcc81dfb633 100644 --- a/solution/1000-1099/1067.Digit Count in Range/README.md +++ b/solution/1000-1099/1067.Digit Count in Range/README.md @@ -88,6 +88,8 @@ $$ +#### Python3 + ```python class Solution: def digitsCount(self, d: int, low: int, high: int) -> int: @@ -116,6 +118,8 @@ class Solution: return dfs(l, 0, True, True) ``` +#### Java + ```java class Solution { private int d; @@ -163,6 +167,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -209,6 +215,8 @@ public: }; ``` +#### Go + ```go func digitsCount(d int, low int, high int) int { f := func(n int) int { diff --git a/solution/1000-1099/1067.Digit Count in Range/README_EN.md b/solution/1000-1099/1067.Digit Count in Range/README_EN.md index 58c425b89d63b..8ed16608541b5 100644 --- a/solution/1000-1099/1067.Digit Count in Range/README_EN.md +++ b/solution/1000-1099/1067.Digit Count in Range/README_EN.md @@ -57,6 +57,8 @@ Note that the digit d = 1 occurs twice in the number 11. +#### Python3 + ```python class Solution: def digitsCount(self, d: int, low: int, high: int) -> int: @@ -85,6 +87,8 @@ class Solution: return dfs(l, 0, True, True) ``` +#### Java + ```java class Solution { private int d; @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -178,6 +184,8 @@ public: }; ``` +#### Go + ```go func digitsCount(d int, low int, high int) int { f := func(n int) int { diff --git a/solution/1000-1099/1068.Product Sales Analysis I/README.md b/solution/1000-1099/1068.Product Sales Analysis I/README.md index 80c6d83e2f47d..d4d78c06da043 100644 --- a/solution/1000-1099/1068.Product Sales Analysis I/README.md +++ b/solution/1000-1099/1068.Product Sales Analysis I/README.md @@ -99,6 +99,8 @@ Product 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT product_name, year, price diff --git a/solution/1000-1099/1068.Product Sales Analysis I/README_EN.md b/solution/1000-1099/1068.Product Sales Analysis I/README_EN.md index 09582bbf214df..db4f432199d26 100644 --- a/solution/1000-1099/1068.Product Sales Analysis I/README_EN.md +++ b/solution/1000-1099/1068.Product Sales Analysis I/README_EN.md @@ -102,6 +102,8 @@ From sale_id = 7, we can conclude that Apple was sold for 9000 in the year 2011. +#### MySQL + ```sql # Write your MySQL query statement below SELECT product_name, year, price diff --git a/solution/1000-1099/1069.Product Sales Analysis II/README.md b/solution/1000-1099/1069.Product Sales Analysis II/README.md index f30da415a89b3..68c9c54bb2893 100644 --- a/solution/1000-1099/1069.Product Sales Analysis II/README.md +++ b/solution/1000-1099/1069.Product Sales Analysis II/README.md @@ -97,6 +97,8 @@ Product 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT product_id, SUM(quantity) AS total_quantity diff --git a/solution/1000-1099/1069.Product Sales Analysis II/README_EN.md b/solution/1000-1099/1069.Product Sales Analysis II/README_EN.md index 2f40553a0a14d..a93ab7ba8dd9c 100644 --- a/solution/1000-1099/1069.Product Sales Analysis II/README_EN.md +++ b/solution/1000-1099/1069.Product Sales Analysis II/README_EN.md @@ -97,6 +97,8 @@ Product table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT product_id, SUM(quantity) AS total_quantity diff --git a/solution/1000-1099/1070.Product Sales Analysis III/README.md b/solution/1000-1099/1070.Product Sales Analysis III/README.md index 640224b603982..9483cf0060929 100644 --- a/solution/1000-1099/1070.Product Sales Analysis III/README.md +++ b/solution/1000-1099/1070.Product Sales Analysis III/README.md @@ -96,6 +96,8 @@ Product 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -124,6 +126,8 @@ WHERE +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1000-1099/1070.Product Sales Analysis III/README_EN.md b/solution/1000-1099/1070.Product Sales Analysis III/README_EN.md index 3a7e9c7b05281..03c8643cae525 100644 --- a/solution/1000-1099/1070.Product Sales Analysis III/README_EN.md +++ b/solution/1000-1099/1070.Product Sales Analysis III/README_EN.md @@ -97,6 +97,8 @@ Product table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -125,6 +127,8 @@ WHERE +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1000-1099/1071.Greatest Common Divisor of Strings/README.md b/solution/1000-1099/1071.Greatest Common Divisor of Strings/README.md index baf63d41dca24..e00d0bfb983ca 100644 --- a/solution/1000-1099/1071.Greatest Common Divisor of Strings/README.md +++ b/solution/1000-1099/1071.Greatest Common Divisor of Strings/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def gcdOfStrings(self, str1: str, str2: str) -> str: @@ -81,6 +83,8 @@ class Solution: return '' ``` +#### Java + ```java class Solution { public String gcdOfStrings(String str1, String str2) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func gcdOfStrings(str1 string, str2 string) string { if str1+str2 != str2+str1 { @@ -125,6 +133,8 @@ func gcd(a, b int) int { } ``` +#### Rust + ```rust impl Solution { pub fn gcd_of_strings(str1: String, str2: String) -> String { @@ -154,6 +164,8 @@ impl Solution { +#### Python3 + ```python class Solution: def gcdOfStrings(self, str1: str, str2: str) -> str: diff --git a/solution/1000-1099/1071.Greatest Common Divisor of Strings/README_EN.md b/solution/1000-1099/1071.Greatest Common Divisor of Strings/README_EN.md index b6586d1d43b94..80719f66d5013 100644 --- a/solution/1000-1099/1071.Greatest Common Divisor of Strings/README_EN.md +++ b/solution/1000-1099/1071.Greatest Common Divisor of Strings/README_EN.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def gcdOfStrings(self, str1: str, str2: str) -> str: @@ -79,6 +81,8 @@ class Solution: return '' ``` +#### Java + ```java class Solution { public String gcdOfStrings(String str1, String str2) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func gcdOfStrings(str1 string, str2 string) string { if str1+str2 != str2+str1 { @@ -123,6 +131,8 @@ func gcd(a, b int) int { } ``` +#### Rust + ```rust impl Solution { pub fn gcd_of_strings(str1: String, str2: String) -> String { @@ -152,6 +162,8 @@ impl Solution { +#### Python3 + ```python class Solution: def gcdOfStrings(self, str1: str, str2: str) -> str: diff --git a/solution/1000-1099/1072.Flip Columns For Maximum Number of Equal Rows/README.md b/solution/1000-1099/1072.Flip Columns For Maximum Number of Equal Rows/README.md index 9a685eac30f14..97378c64e7f1a 100644 --- a/solution/1000-1099/1072.Flip Columns For Maximum Number of Equal Rows/README.md +++ b/solution/1000-1099/1072.Flip Columns For Maximum Number of Equal Rows/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python class Solution: def maxEqualRowsAfterFlips(self, matrix: List[List[int]]) -> int: @@ -105,6 +107,8 @@ class Solution: return max(cnt.values()) ``` +#### Java + ```java class Solution { public int maxEqualRowsAfterFlips(int[][] matrix) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func maxEqualRowsAfterFlips(matrix [][]int) (ans int) { cnt := map[string]int{} @@ -159,6 +167,8 @@ func maxEqualRowsAfterFlips(matrix [][]int) (ans int) { } ``` +#### TypeScript + ```ts function maxEqualRowsAfterFlips(matrix: number[][]): number { const cnt = new Map(); diff --git a/solution/1000-1099/1072.Flip Columns For Maximum Number of Equal Rows/README_EN.md b/solution/1000-1099/1072.Flip Columns For Maximum Number of Equal Rows/README_EN.md index a8a0567351e6d..79f0ea96aa29d 100644 --- a/solution/1000-1099/1072.Flip Columns For Maximum Number of Equal Rows/README_EN.md +++ b/solution/1000-1099/1072.Flip Columns For Maximum Number of Equal Rows/README_EN.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def maxEqualRowsAfterFlips(self, matrix: List[List[int]]) -> int: @@ -81,6 +83,8 @@ class Solution: return max(cnt.values()) ``` +#### Java + ```java class Solution { public int maxEqualRowsAfterFlips(int[][] matrix) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func maxEqualRowsAfterFlips(matrix [][]int) (ans int) { cnt := map[string]int{} @@ -135,6 +143,8 @@ func maxEqualRowsAfterFlips(matrix [][]int) (ans int) { } ``` +#### TypeScript + ```ts function maxEqualRowsAfterFlips(matrix: number[][]): number { const cnt = new Map(); diff --git a/solution/1000-1099/1073.Adding Two Negabinary Numbers/README.md b/solution/1000-1099/1073.Adding Two Negabinary Numbers/README.md index 57f2eeda6142c..f0409db7fefc3 100644 --- a/solution/1000-1099/1073.Adding Two Negabinary Numbers/README.md +++ b/solution/1000-1099/1073.Adding Two Negabinary Numbers/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def addNegabinary(self, arr1: List[int], arr2: List[int]) -> List[int]: @@ -112,6 +114,8 @@ class Solution: return ans[::-1] ``` +#### Java + ```java class Solution { public int[] addNegabinary(int[] arr1, int[] arr2) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go func addNegabinary(arr1 []int, arr2 []int) (ans []int) { i, j := len(arr1)-1, len(arr2)-1 @@ -200,6 +208,8 @@ func addNegabinary(arr1 []int, arr2 []int) (ans []int) { } ``` +#### TypeScript + ```ts function addNegabinary(arr1: number[], arr2: number[]): number[] { let i = arr1.length - 1, @@ -226,6 +236,8 @@ function addNegabinary(arr1: number[], arr2: number[]): number[] { } ``` +#### C# + ```cs public class Solution { public int[] AddNegabinary(int[] arr1, int[] arr2) { diff --git a/solution/1000-1099/1073.Adding Two Negabinary Numbers/README_EN.md b/solution/1000-1099/1073.Adding Two Negabinary Numbers/README_EN.md index ae6a6236a7a8a..163ab98979f0b 100644 --- a/solution/1000-1099/1073.Adding Two Negabinary Numbers/README_EN.md +++ b/solution/1000-1099/1073.Adding Two Negabinary Numbers/README_EN.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def addNegabinary(self, arr1: List[int], arr2: List[int]) -> List[int]: @@ -91,6 +93,8 @@ class Solution: return ans[::-1] ``` +#### Java + ```java class Solution { public int[] addNegabinary(int[] arr1, int[] arr2) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func addNegabinary(arr1 []int, arr2 []int) (ans []int) { i, j := len(arr1)-1, len(arr2)-1 @@ -179,6 +187,8 @@ func addNegabinary(arr1 []int, arr2 []int) (ans []int) { } ``` +#### TypeScript + ```ts function addNegabinary(arr1: number[], arr2: number[]): number[] { let i = arr1.length - 1, @@ -205,6 +215,8 @@ function addNegabinary(arr1: number[], arr2: number[]): number[] { } ``` +#### C# + ```cs public class Solution { public int[] AddNegabinary(int[] arr1, int[] arr2) { diff --git a/solution/1000-1099/1074.Number of Submatrices That Sum to Target/README.md b/solution/1000-1099/1074.Number of Submatrices That Sum to Target/README.md index d583b2691ce1a..7726d819b5c1d 100644 --- a/solution/1000-1099/1074.Number of Submatrices That Sum to Target/README.md +++ b/solution/1000-1099/1074.Number of Submatrices That Sum to Target/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def numSubmatrixSumTarget(self, matrix: List[List[int]], target: int) -> int: @@ -112,6 +114,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numSubmatrixSumTarget(int[][] matrix, int target) { @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go func numSubmatrixSumTarget(matrix [][]int, target int) (ans int) { m, n := len(matrix), len(matrix[0]) @@ -205,6 +213,8 @@ func f(nums []int, target int) (cnt int) { } ``` +#### TypeScript + ```ts function numSubmatrixSumTarget(matrix: number[][], target: number): number { const m = matrix.length; diff --git a/solution/1000-1099/1074.Number of Submatrices That Sum to Target/README_EN.md b/solution/1000-1099/1074.Number of Submatrices That Sum to Target/README_EN.md index d96e8999e150d..ed004a8947fdc 100644 --- a/solution/1000-1099/1074.Number of Submatrices That Sum to Target/README_EN.md +++ b/solution/1000-1099/1074.Number of Submatrices That Sum to Target/README_EN.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def numSubmatrixSumTarget(self, matrix: List[List[int]], target: int) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numSubmatrixSumTarget(int[][] matrix, int target) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func numSubmatrixSumTarget(matrix [][]int, target int) (ans int) { m, n := len(matrix), len(matrix[0]) @@ -188,6 +196,8 @@ func f(nums []int, target int) (cnt int) { } ``` +#### TypeScript + ```ts function numSubmatrixSumTarget(matrix: number[][], target: number): number { const m = matrix.length; diff --git a/solution/1000-1099/1075.Project Employees I/README.md b/solution/1000-1099/1075.Project Employees I/README.md index 1f675d96ad105..03292d45fa1fc 100644 --- a/solution/1000-1099/1075.Project Employees I/README.md +++ b/solution/1000-1099/1075.Project Employees I/README.md @@ -92,6 +92,8 @@ Result 表: +#### MySQL + ```sql # Write your MySQL query statement SELECT project_id, ROUND(AVG(experience_years), 2) AS average_years diff --git a/solution/1000-1099/1075.Project Employees I/README_EN.md b/solution/1000-1099/1075.Project Employees I/README_EN.md index c087ca68b8a63..ce41a60007d7c 100644 --- a/solution/1000-1099/1075.Project Employees I/README_EN.md +++ b/solution/1000-1099/1075.Project Employees I/README_EN.md @@ -98,6 +98,8 @@ Employee table: +#### MySQL + ```sql # Write your MySQL query statement SELECT project_id, ROUND(AVG(experience_years), 2) AS average_years diff --git a/solution/1000-1099/1076.Project Employees II/README.md b/solution/1000-1099/1076.Project Employees II/README.md index c199c4f106ee6..11dc256296137 100644 --- a/solution/1000-1099/1076.Project Employees II/README.md +++ b/solution/1000-1099/1076.Project Employees II/README.md @@ -95,6 +95,8 @@ Employee table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT project_id @@ -118,6 +120,8 @@ HAVING +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1000-1099/1076.Project Employees II/README_EN.md b/solution/1000-1099/1076.Project Employees II/README_EN.md index 86d049f0a64ca..fee75b34bd8d0 100644 --- a/solution/1000-1099/1076.Project Employees II/README_EN.md +++ b/solution/1000-1099/1076.Project Employees II/README_EN.md @@ -97,6 +97,8 @@ Employee table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT project_id @@ -120,6 +122,8 @@ HAVING +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1000-1099/1077.Project Employees III/README.md b/solution/1000-1099/1077.Project Employees III/README.md index 8ed01dbd4b9eb..402fe7fe58a22 100644 --- a/solution/1000-1099/1077.Project Employees III/README.md +++ b/solution/1000-1099/1077.Project Employees III/README.md @@ -100,6 +100,8 @@ Employee 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1000-1099/1077.Project Employees III/README_EN.md b/solution/1000-1099/1077.Project Employees III/README_EN.md index 98ff304a090fc..33969028cdc6e 100644 --- a/solution/1000-1099/1077.Project Employees III/README_EN.md +++ b/solution/1000-1099/1077.Project Employees III/README_EN.md @@ -101,6 +101,8 @@ We can first perform an inner join between the `Project` table and the `Employee +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1000-1099/1078.Occurrences After Bigram/README.md b/solution/1000-1099/1078.Occurrences After Bigram/README.md index c6ee6950506b0..08b432a41fb2a 100644 --- a/solution/1000-1099/1078.Occurrences After Bigram/README.md +++ b/solution/1000-1099/1078.Occurrences After Bigram/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def findOcurrences(self, text: str, first: str, second: str) -> List[str]: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func findOcurrences(text string, first string, second string) (ans []string) { words := strings.Split(text, " ") @@ -129,6 +137,8 @@ func findOcurrences(text string, first string, second string) (ans []string) { } ``` +#### TypeScript + ```ts function findOcurrences(text: string, first: string, second: string): string[] { const words = text.split(' '); 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 daddbdd54b2f6..29a645c50110a 100644 --- a/solution/1000-1099/1078.Occurrences After Bigram/README_EN.md +++ b/solution/1000-1099/1078.Occurrences After Bigram/README_EN.md @@ -51,6 +51,8 @@ tags: +#### Python3 + ```python class Solution: def findOcurrences(self, text: str, first: str, second: str) -> List[str]: @@ -63,6 +65,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { @@ -79,6 +83,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,6 +107,8 @@ public: }; ``` +#### Go + ```go func findOcurrences(text string, first string, second string) (ans []string) { words := strings.Split(text, " ") @@ -114,6 +122,8 @@ func findOcurrences(text string, first string, second string) (ans []string) { } ``` +#### TypeScript + ```ts function findOcurrences(text: string, first: string, second: string): string[] { const words = text.split(' '); diff --git a/solution/1000-1099/1079.Letter Tile Possibilities/README.md b/solution/1000-1099/1079.Letter Tile Possibilities/README.md index 779b14b380cac..5ad82763a5994 100644 --- a/solution/1000-1099/1079.Letter Tile Possibilities/README.md +++ b/solution/1000-1099/1079.Letter Tile Possibilities/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def numTilePossibilities(self, tiles: str) -> int: @@ -92,6 +94,8 @@ class Solution: return dfs(cnt) ``` +#### Java + ```java class Solution { public int numTilePossibilities(String tiles) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func numTilePossibilities(tiles string) int { cnt := [26]int{} @@ -164,6 +172,8 @@ func numTilePossibilities(tiles string) int { } ``` +#### TypeScript + ```ts function numTilePossibilities(tiles: string): number { const cnt: number[] = new Array(26).fill(0); diff --git a/solution/1000-1099/1079.Letter Tile Possibilities/README_EN.md b/solution/1000-1099/1079.Letter Tile Possibilities/README_EN.md index d1294b70c3ac0..40df70447d29d 100644 --- a/solution/1000-1099/1079.Letter Tile Possibilities/README_EN.md +++ b/solution/1000-1099/1079.Letter Tile Possibilities/README_EN.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def numTilePossibilities(self, tiles: str) -> int: @@ -83,6 +85,8 @@ class Solution: return dfs(cnt) ``` +#### Java + ```java class Solution { public int numTilePossibilities(String tiles) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func numTilePossibilities(tiles string) int { cnt := [26]int{} @@ -155,6 +163,8 @@ func numTilePossibilities(tiles string) int { } ``` +#### TypeScript + ```ts function numTilePossibilities(tiles: string): number { const cnt: number[] = new Array(26).fill(0); diff --git a/solution/1000-1099/1080.Insufficient Nodes in Root to Leaf Paths/README.md b/solution/1000-1099/1080.Insufficient Nodes in Root to Leaf Paths/README.md index 748709f71b712..909c9cef69239 100644 --- a/solution/1000-1099/1080.Insufficient Nodes in Root to Leaf Paths/README.md +++ b/solution/1000-1099/1080.Insufficient Nodes in Root to Leaf Paths/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -104,6 +106,8 @@ class Solution: return None if root.left is None and root.right is None else root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -197,6 +205,8 @@ func sufficientSubset(root *TreeNode, limit int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -226,6 +236,8 @@ function sufficientSubset(root: TreeNode | null, limit: number): TreeNode | null } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/1000-1099/1080.Insufficient Nodes in Root to Leaf Paths/README_EN.md b/solution/1000-1099/1080.Insufficient Nodes in Root to Leaf Paths/README_EN.md index 3c6d756683cde..1acd5a64f0af1 100644 --- a/solution/1000-1099/1080.Insufficient Nodes in Root to Leaf Paths/README_EN.md +++ b/solution/1000-1099/1080.Insufficient Nodes in Root to Leaf Paths/README_EN.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -88,6 +90,8 @@ class Solution: return None if root.left is None and root.right is None else root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -181,6 +189,8 @@ func sufficientSubset(root *TreeNode, limit int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -210,6 +220,8 @@ function sufficientSubset(root: TreeNode | null, limit: number): TreeNode | null } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/1000-1099/1081.Smallest Subsequence of Distinct Characters/README.md b/solution/1000-1099/1081.Smallest Subsequence of Distinct Characters/README.md index af52fdc648bfa..b055f060c23ce 100644 --- a/solution/1000-1099/1081.Smallest Subsequence of Distinct Characters/README.md +++ b/solution/1000-1099/1081.Smallest Subsequence of Distinct Characters/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def smallestSubsequence(self, s: str) -> str: @@ -85,6 +87,8 @@ class Solution: return "".join(stk) ``` +#### Java + ```java class Solution { public String smallestSubsequence(String text) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func smallestSubsequence(s string) string { last := make([]int, 26) @@ -161,6 +169,8 @@ func smallestSubsequence(s string) string { } ``` +#### TypeScript + ```ts function smallestSubsequence(s: string): string { const f = (c: string): number => c.charCodeAt(0) - 'a'.charCodeAt(0); @@ -195,6 +205,8 @@ function smallestSubsequence(s: string): string { +#### Java + ```java class Solution { public String smallestSubsequence(String s) { diff --git a/solution/1000-1099/1081.Smallest Subsequence of Distinct Characters/README_EN.md b/solution/1000-1099/1081.Smallest Subsequence of Distinct Characters/README_EN.md index 14e5e2cee7033..6e5951c5842a7 100644 --- a/solution/1000-1099/1081.Smallest Subsequence of Distinct Characters/README_EN.md +++ b/solution/1000-1099/1081.Smallest Subsequence of Distinct Characters/README_EN.md @@ -59,6 +59,8 @@ tags: +#### Python3 + ```python class Solution: def smallestSubsequence(self, s: str) -> str: @@ -75,6 +77,8 @@ class Solution: return "".join(stk) ``` +#### Java + ```java class Solution { public String smallestSubsequence(String text) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func smallestSubsequence(s string) string { last := make([]int, 26) @@ -151,6 +159,8 @@ func smallestSubsequence(s string) string { } ``` +#### TypeScript + ```ts function smallestSubsequence(s: string): string { const f = (c: string): number => c.charCodeAt(0) - 'a'.charCodeAt(0); @@ -185,6 +195,8 @@ function smallestSubsequence(s: string): string { +#### Java + ```java class Solution { public String smallestSubsequence(String s) { diff --git a/solution/1000-1099/1082.Sales Analysis I/README.md b/solution/1000-1099/1082.Sales Analysis I/README.md index b7e561ef9deb0..d047216f3f528 100644 --- a/solution/1000-1099/1082.Sales Analysis I/README.md +++ b/solution/1000-1099/1082.Sales Analysis I/README.md @@ -98,6 +98,8 @@ Product 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT seller_id @@ -121,6 +123,8 @@ HAVING +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1000-1099/1082.Sales Analysis I/README_EN.md b/solution/1000-1099/1082.Sales Analysis I/README_EN.md index fcfe09a971588..417eba6ba3098 100644 --- a/solution/1000-1099/1082.Sales Analysis I/README_EN.md +++ b/solution/1000-1099/1082.Sales Analysis I/README_EN.md @@ -98,6 +98,8 @@ Sales table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT seller_id @@ -121,6 +123,8 @@ HAVING +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1000-1099/1083.Sales Analysis II/README.md b/solution/1000-1099/1083.Sales Analysis II/README.md index a1867fae224d1..4187b01c87b8c 100644 --- a/solution/1000-1099/1083.Sales Analysis II/README.md +++ b/solution/1000-1099/1083.Sales Analysis II/README.md @@ -103,6 +103,8 @@ id 为 1 的买家购买了一部 S8,但是却没有购买 iPhone,而 id 为 +#### MySQL + ```sql # Write your MySQL query statement below SELECT buyer_id diff --git a/solution/1000-1099/1083.Sales Analysis II/README_EN.md b/solution/1000-1099/1083.Sales Analysis II/README_EN.md index c40bc228326f3..02b547c2ca3fb 100644 --- a/solution/1000-1099/1083.Sales Analysis II/README_EN.md +++ b/solution/1000-1099/1083.Sales Analysis II/README_EN.md @@ -99,6 +99,8 @@ Sales table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT buyer_id diff --git a/solution/1000-1099/1084.Sales Analysis III/README.md b/solution/1000-1099/1084.Sales Analysis III/README.md index 0d1d1444ba9f1..aa168f39a8a8a 100644 --- a/solution/1000-1099/1084.Sales Analysis III/README.md +++ b/solution/1000-1099/1084.Sales Analysis III/README.md @@ -103,6 +103,8 @@ id 为 3 的产品在 2019 年春季之后销售。 +#### MySQL + ```sql # Write your MySQL query statement below SELECT product_id, product_name diff --git a/solution/1000-1099/1084.Sales Analysis III/README_EN.md b/solution/1000-1099/1084.Sales Analysis III/README_EN.md index 1eabeb5fb3314..919508b310184 100644 --- a/solution/1000-1099/1084.Sales Analysis III/README_EN.md +++ b/solution/1000-1099/1084.Sales Analysis III/README_EN.md @@ -101,6 +101,8 @@ We return only product 1 as it is the product that was only sold in the spring o +#### MySQL + ```sql # Write your MySQL query statement below SELECT product_id, product_name 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 adef895f8ab2e..3005067ed6950 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 @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def sumOfDigits(self, nums: List[int]) -> int: @@ -79,6 +81,8 @@ class Solution: return s & 1 ^ 1 ``` +#### Java + ```java class Solution { public int sumOfDigits(int[] nums) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func sumOfDigits(nums []int) int { s := 0 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 6d10123b4b1ff..875c7f6979d07 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 @@ -56,6 +56,8 @@ tags: +#### Python3 + ```python class Solution: def sumOfDigits(self, nums: List[int]) -> int: @@ -67,6 +69,8 @@ class Solution: return s & 1 ^ 1 ``` +#### Java + ```java class Solution { public int sumOfDigits(int[] nums) { @@ -83,6 +87,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -97,6 +103,8 @@ public: }; ``` +#### Go + ```go func sumOfDigits(nums []int) int { s := 0 diff --git a/solution/1000-1099/1086.High Five/README.md b/solution/1000-1099/1086.High Five/README.md index 886c2993091fc..6c31d9f1629a7 100644 --- a/solution/1000-1099/1086.High Five/README.md +++ b/solution/1000-1099/1086.High Five/README.md @@ -72,6 +72,8 @@ ID = 2 的学生分数为 93、97、77、100 和 76 。前五科的平均分 (10 +#### Python3 + ```python class Solution: def highFive(self, items: List[List[int]]) -> List[List[int]]: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] highFive(int[][] items) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func highFive(items [][]int) (ans [][]int) { d := make([][]int, 1001) @@ -174,6 +182,8 @@ func highFive(items [][]int) (ans [][]int) { } ``` +#### TypeScript + ```ts function highFive(items: number[][]): number[][] { const d: number[][] = Array(1001) diff --git a/solution/1000-1099/1086.High Five/README_EN.md b/solution/1000-1099/1086.High Five/README_EN.md index 87e126a500aec..952f55d1ffaa4 100644 --- a/solution/1000-1099/1086.High Five/README_EN.md +++ b/solution/1000-1099/1086.High Five/README_EN.md @@ -66,6 +66,8 @@ The student with ID = 2 got scores 93, 97, 77, 100, and 76. Their top five avera +#### Python3 + ```python class Solution: def highFive(self, items: List[List[int]]) -> List[List[int]]: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] highFive(int[][] items) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func highFive(items [][]int) (ans [][]int) { d := make([][]int, 1001) @@ -168,6 +176,8 @@ func highFive(items [][]int) (ans [][]int) { } ``` +#### TypeScript + ```ts function highFive(items: number[][]): number[][] { const d: number[][] = Array(1001) diff --git a/solution/1000-1099/1087.Brace Expansion/README.md b/solution/1000-1099/1087.Brace Expansion/README.md index abe3904382b71..4ae507f4e0af9 100644 --- a/solution/1000-1099/1087.Brace Expansion/README.md +++ b/solution/1000-1099/1087.Brace Expansion/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def expand(self, s: str) -> List[str]: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List ans; diff --git a/solution/1000-1099/1087.Brace Expansion/README_EN.md b/solution/1000-1099/1087.Brace Expansion/README_EN.md index 8c074584411e9..f11b7ffc7aa46 100644 --- a/solution/1000-1099/1087.Brace Expansion/README_EN.md +++ b/solution/1000-1099/1087.Brace Expansion/README_EN.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def expand(self, s: str) -> List[str]: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List ans; diff --git a/solution/1000-1099/1088.Confusing Number II/README.md b/solution/1000-1099/1088.Confusing Number II/README.md index e58f2e1fabd0d..37e061bc73a74 100644 --- a/solution/1000-1099/1088.Confusing Number II/README.md +++ b/solution/1000-1099/1088.Confusing Number II/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class Solution: def confusingNumberII(self, n: int) -> int: @@ -121,6 +123,8 @@ class Solution: return dfs(0, True, 0) ``` +#### Java + ```java class Solution { private final int[] d = {0, 1, -1, -1, -1, -1, 9, -1, 8, 6}; @@ -156,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go func confusingNumberII(n int) int { d := [10]int{0, 1, -1, -1, -1, -1, 9, -1, 8, 6} @@ -223,6 +231,8 @@ func confusingNumberII(n int) int { } ``` +#### TypeScript + ```ts function confusingNumberII(n: number): number { const s = n.toString(); diff --git a/solution/1000-1099/1088.Confusing Number II/README_EN.md b/solution/1000-1099/1088.Confusing Number II/README_EN.md index 0cfee3e3afa4b..563ae7d02d7e5 100644 --- a/solution/1000-1099/1088.Confusing Number II/README_EN.md +++ b/solution/1000-1099/1088.Confusing Number II/README_EN.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def confusingNumberII(self, n: int) -> int: @@ -101,6 +103,8 @@ class Solution: return dfs(0, True, 0) ``` +#### Java + ```java class Solution { private final int[] d = {0, 1, -1, -1, -1, -1, 9, -1, 8, 6}; @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func confusingNumberII(n int) int { d := [10]int{0, 1, -1, -1, -1, -1, 9, -1, 8, 6} @@ -203,6 +211,8 @@ func confusingNumberII(n int) int { } ``` +#### TypeScript + ```ts function confusingNumberII(n: number): number { const s = n.toString(); diff --git a/solution/1000-1099/1089.Duplicate Zeros/README.md b/solution/1000-1099/1089.Duplicate Zeros/README.md index 1391c3053b882..d6210785d1bd0 100644 --- a/solution/1000-1099/1089.Duplicate Zeros/README.md +++ b/solution/1000-1099/1089.Duplicate Zeros/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def duplicateZeros(self, arr: List[int]) -> None: @@ -88,6 +90,8 @@ class Solution: i, j = i - 1, j - 1 ``` +#### Java + ```java class Solution { public void duplicateZeros(int[] arr) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func duplicateZeros(arr []int) { n := len(arr) @@ -165,6 +173,8 @@ func duplicateZeros(arr []int) { } ``` +#### Rust + ```rust impl Solution { pub fn duplicate_zeros(arr: &mut Vec) { @@ -193,6 +203,8 @@ impl Solution { } ``` +#### C + ```c void duplicateZeros(int* arr, int arrSize) { int i = 0; diff --git a/solution/1000-1099/1089.Duplicate Zeros/README_EN.md b/solution/1000-1099/1089.Duplicate Zeros/README_EN.md index 2eb99d1de9cf6..edcf1dcf090de 100644 --- a/solution/1000-1099/1089.Duplicate Zeros/README_EN.md +++ b/solution/1000-1099/1089.Duplicate Zeros/README_EN.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python class Solution: def duplicateZeros(self, arr: List[int]) -> None: @@ -82,6 +84,8 @@ class Solution: i, j = i - 1, j - 1 ``` +#### Java + ```java class Solution { public void duplicateZeros(int[] arr) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func duplicateZeros(arr []int) { n := len(arr) @@ -159,6 +167,8 @@ func duplicateZeros(arr []int) { } ``` +#### Rust + ```rust impl Solution { pub fn duplicate_zeros(arr: &mut Vec) { @@ -187,6 +197,8 @@ impl Solution { } ``` +#### C + ```c void duplicateZeros(int* arr, int arrSize) { int i = 0; diff --git a/solution/1000-1099/1090.Largest Values From Labels/README.md b/solution/1000-1099/1090.Largest Values From Labels/README.md index 990c1afd1b61d..7814a000020f3 100644 --- a/solution/1000-1099/1090.Largest Values From Labels/README.md +++ b/solution/1000-1099/1090.Largest Values From Labels/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def largestValsFromLabels( @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int largestValsFromLabels(int[] values, int[] labels, int numWanted, int useLimit) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func largestValsFromLabels(values []int, labels []int, numWanted int, useLimit int) (ans int) { n := len(values) @@ -177,6 +185,8 @@ func largestValsFromLabels(values []int, labels []int, numWanted int, useLimit i } ``` +#### TypeScript + ```ts function largestValsFromLabels( values: number[], diff --git a/solution/1000-1099/1090.Largest Values From Labels/README_EN.md b/solution/1000-1099/1090.Largest Values From Labels/README_EN.md index 92e10860afa6c..e607199d68dc7 100644 --- a/solution/1000-1099/1090.Largest Values From Labels/README_EN.md +++ b/solution/1000-1099/1090.Largest Values From Labels/README_EN.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def largestValsFromLabels( @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int largestValsFromLabels(int[] values, int[] labels, int numWanted, int useLimit) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func largestValsFromLabels(values []int, labels []int, numWanted int, useLimit int) (ans int) { n := len(values) @@ -167,6 +175,8 @@ func largestValsFromLabels(values []int, labels []int, numWanted int, useLimit i } ``` +#### TypeScript + ```ts function largestValsFromLabels( values: number[], diff --git a/solution/1000-1099/1091.Shortest Path in Binary Matrix/README.md b/solution/1000-1099/1091.Shortest Path in Binary Matrix/README.md index dceb40698451a..2d4812c3ca2d0 100644 --- a/solution/1000-1099/1091.Shortest Path in Binary Matrix/README.md +++ b/solution/1000-1099/1091.Shortest Path in Binary Matrix/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def shortestPathBinaryMatrix(self, grid: List[List[int]]) -> int: @@ -110,6 +112,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int shortestPathBinaryMatrix(int[][] grid) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go func shortestPathBinaryMatrix(grid [][]int) int { if grid[0][0] == 1 { @@ -205,6 +213,8 @@ func shortestPathBinaryMatrix(grid [][]int) int { } ``` +#### TypeScript + ```ts function shortestPathBinaryMatrix(grid: number[][]): number { if (grid[0][0]) { @@ -234,6 +244,8 @@ function shortestPathBinaryMatrix(grid: number[][]): number { } ``` +#### Rust + ```rust use std::collections::VecDeque; impl Solution { diff --git a/solution/1000-1099/1091.Shortest Path in Binary Matrix/README_EN.md b/solution/1000-1099/1091.Shortest Path in Binary Matrix/README_EN.md index b2aad226fab2c..bfd6eb09dd4b1 100644 --- a/solution/1000-1099/1091.Shortest Path in Binary Matrix/README_EN.md +++ b/solution/1000-1099/1091.Shortest Path in Binary Matrix/README_EN.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def shortestPathBinaryMatrix(self, grid: List[List[int]]) -> int: @@ -96,6 +98,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int shortestPathBinaryMatrix(int[][] grid) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func shortestPathBinaryMatrix(grid [][]int) int { if grid[0][0] == 1 { @@ -191,6 +199,8 @@ func shortestPathBinaryMatrix(grid [][]int) int { } ``` +#### TypeScript + ```ts function shortestPathBinaryMatrix(grid: number[][]): number { if (grid[0][0]) { @@ -220,6 +230,8 @@ function shortestPathBinaryMatrix(grid: number[][]): number { } ``` +#### Rust + ```rust use std::collections::VecDeque; impl Solution { diff --git a/solution/1000-1099/1092.Shortest Common Supersequence/README.md b/solution/1000-1099/1092.Shortest Common Supersequence/README.md index 39eb3fbd27e01..059371c6bc367 100644 --- a/solution/1000-1099/1092.Shortest Common Supersequence/README.md +++ b/solution/1000-1099/1092.Shortest Common Supersequence/README.md @@ -100,6 +100,8 @@ ans: c a b a c +#### Python3 + ```python class Solution: def shortestCommonSupersequence(self, str1: str, str2: str) -> str: @@ -133,6 +135,8 @@ class Solution: return ''.join(ans[::-1]) ``` +#### Java + ```java class Solution { public String shortestCommonSupersequence(String str1, String str2) { @@ -170,6 +174,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -206,6 +212,8 @@ public: }; ``` +#### Go + ```go func shortestCommonSupersequence(str1 string, str2 string) string { m, n := len(str1), len(str2) @@ -251,6 +259,8 @@ func shortestCommonSupersequence(str1 string, str2 string) string { } ``` +#### TypeScript + ```ts function shortestCommonSupersequence(str1: string, str2: string): string { const m = str1.length; diff --git a/solution/1000-1099/1092.Shortest Common Supersequence/README_EN.md b/solution/1000-1099/1092.Shortest Common Supersequence/README_EN.md index b4222125972a4..046393cc359af 100644 --- a/solution/1000-1099/1092.Shortest Common Supersequence/README_EN.md +++ b/solution/1000-1099/1092.Shortest Common Supersequence/README_EN.md @@ -60,6 +60,8 @@ The answer provided is the shortest such string that satisfies these properties. +#### Python3 + ```python class Solution: def shortestCommonSupersequence(self, str1: str, str2: str) -> str: @@ -93,6 +95,8 @@ class Solution: return ''.join(ans[::-1]) ``` +#### Java + ```java class Solution { public String shortestCommonSupersequence(String str1, String str2) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go func shortestCommonSupersequence(str1 string, str2 string) string { m, n := len(str1), len(str2) @@ -211,6 +219,8 @@ func shortestCommonSupersequence(str1 string, str2 string) string { } ``` +#### TypeScript + ```ts function shortestCommonSupersequence(str1: string, str2: string): string { const m = str1.length; diff --git a/solution/1000-1099/1093.Statistics from a Large Sample/README.md b/solution/1000-1099/1093.Statistics from a Large Sample/README.md index 370aa7de29778..953e3c0e26873 100644 --- a/solution/1000-1099/1093.Statistics from a Large Sample/README.md +++ b/solution/1000-1099/1093.Statistics from a Large Sample/README.md @@ -109,6 +109,8 @@ tags: +#### Python3 + ```python class Solution: def sampleStats(self, count: List[int]) -> List[float]: @@ -137,6 +139,8 @@ class Solution: return [mi, mx, s / cnt, median, mode] ``` +#### Java + ```java class Solution { private int[] count; @@ -174,6 +178,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -206,6 +212,8 @@ public: }; ``` +#### Go + ```go func sampleStats(count []int) []float64 { find := func(i int) int { @@ -239,6 +247,8 @@ func sampleStats(count []int) []float64 { } ``` +#### TypeScript + ```ts function sampleStats(count: number[]): number[] { const find = (i: number): number => { diff --git a/solution/1000-1099/1093.Statistics from a Large Sample/README_EN.md b/solution/1000-1099/1093.Statistics from a Large Sample/README_EN.md index d9722b6b16770..4b3b714d4cd35 100644 --- a/solution/1000-1099/1093.Statistics from a Large Sample/README_EN.md +++ b/solution/1000-1099/1093.Statistics from a Large Sample/README_EN.md @@ -84,6 +84,8 @@ The mode is 1 as it appears the most in the sample. +#### Python3 + ```python class Solution: def sampleStats(self, count: List[int]) -> List[float]: @@ -112,6 +114,8 @@ class Solution: return [mi, mx, s / cnt, median, mode] ``` +#### Java + ```java class Solution { private int[] count; @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func sampleStats(count []int) []float64 { find := func(i int) int { @@ -214,6 +222,8 @@ func sampleStats(count []int) []float64 { } ``` +#### TypeScript + ```ts function sampleStats(count: number[]): number[] { const find = (i: number): number => { diff --git a/solution/1000-1099/1094.Car Pooling/README.md b/solution/1000-1099/1094.Car Pooling/README.md index 877e2d53a9963..be69ba06407a2 100644 --- a/solution/1000-1099/1094.Car Pooling/README.md +++ b/solution/1000-1099/1094.Car Pooling/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def carPooling(self, trips: List[List[int]], capacity: int) -> bool: @@ -81,6 +83,8 @@ class Solution: return all(s <= capacity for s in accumulate(d)) ``` +#### Java + ```java class Solution { public boolean carPooling(int[][] trips, int capacity) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func carPooling(trips [][]int, capacity int) bool { d := [1001]int{} @@ -143,6 +151,8 @@ func carPooling(trips [][]int, capacity int) bool { } ``` +#### TypeScript + ```ts function carPooling(trips: number[][], capacity: number): boolean { const mx = Math.max(...trips.map(([, , t]) => t)); @@ -162,6 +172,8 @@ function carPooling(trips: number[][], capacity: number): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn car_pooling(trips: Vec>, capacity: i32) -> bool { @@ -186,6 +198,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} trips @@ -210,6 +224,8 @@ var carPooling = function (trips, capacity) { }; ``` +#### C# + ```cs public class Solution { public bool CarPooling(int[][] trips, int capacity) { diff --git a/solution/1000-1099/1094.Car Pooling/README_EN.md b/solution/1000-1099/1094.Car Pooling/README_EN.md index eb8eb68abea92..bb216c1abaf8d 100644 --- a/solution/1000-1099/1094.Car Pooling/README_EN.md +++ b/solution/1000-1099/1094.Car Pooling/README_EN.md @@ -68,6 +68,8 @@ The time complexity is $O(n)$, and the space complexity is $O(M)$. Here, $n$ is +#### Python3 + ```python class Solution: def carPooling(self, trips: List[List[int]], capacity: int) -> bool: @@ -79,6 +81,8 @@ class Solution: return all(s <= capacity for s in accumulate(d)) ``` +#### Java + ```java class Solution { public boolean carPooling(int[][] trips, int capacity) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func carPooling(trips [][]int, capacity int) bool { d := [1001]int{} @@ -141,6 +149,8 @@ func carPooling(trips [][]int, capacity int) bool { } ``` +#### TypeScript + ```ts function carPooling(trips: number[][], capacity: number): boolean { const mx = Math.max(...trips.map(([, , t]) => t)); @@ -160,6 +170,8 @@ function carPooling(trips: number[][], capacity: number): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn car_pooling(trips: Vec>, capacity: i32) -> bool { @@ -184,6 +196,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} trips @@ -208,6 +222,8 @@ var carPooling = function (trips, capacity) { }; ``` +#### C# + ```cs public class Solution { public bool CarPooling(int[][] trips, int capacity) { diff --git a/solution/1000-1099/1095.Find in Mountain Array/README.md b/solution/1000-1099/1095.Find in Mountain Array/README.md index 3a0343d60fd3c..0ddd4e54bd093 100644 --- a/solution/1000-1099/1095.Find in Mountain Array/README.md +++ b/solution/1000-1099/1095.Find in Mountain Array/README.md @@ -100,6 +100,8 @@ tags: +#### Python3 + ```python # """ # This is MountainArray's API interface. @@ -133,6 +135,8 @@ class Solution: return search(l + 1, n - 1, -1) if ans == -1 else ans ``` +#### Java + ```java /** * // This is MountainArray's API interface. @@ -178,6 +182,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * // This is the MountainArray's API interface. @@ -219,6 +225,8 @@ public: }; ``` +#### Go + ```go /** * // This is the MountainArray's API interface. @@ -263,6 +271,8 @@ func findInMountainArray(target int, mountainArr *MountainArray) int { } ``` +#### TypeScript + ```ts /** * // This is the MountainArray's API interface. @@ -302,6 +312,8 @@ function findInMountainArray(target: number, mountainArr: MountainArray) { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/1000-1099/1095.Find in Mountain Array/README_EN.md b/solution/1000-1099/1095.Find in Mountain Array/README_EN.md index 6564dedeecc09..00281eb8a6b06 100644 --- a/solution/1000-1099/1095.Find in Mountain Array/README_EN.md +++ b/solution/1000-1099/1095.Find in Mountain Array/README_EN.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python # """ # This is MountainArray's API interface. @@ -113,6 +115,8 @@ class Solution: return search(l + 1, n - 1, -1) if ans == -1 else ans ``` +#### Java + ```java /** * // This is MountainArray's API interface. @@ -158,6 +162,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * // This is the MountainArray's API interface. @@ -199,6 +205,8 @@ public: }; ``` +#### Go + ```go /** * // This is the MountainArray's API interface. @@ -243,6 +251,8 @@ func findInMountainArray(target int, mountainArr *MountainArray) int { } ``` +#### TypeScript + ```ts /** * // This is the MountainArray's API interface. @@ -282,6 +292,8 @@ function findInMountainArray(target: number, mountainArr: MountainArray) { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/1000-1099/1096.Brace Expansion II/README.md b/solution/1000-1099/1096.Brace Expansion II/README.md index 53d33f6746f93..ab499cc0ed2cf 100644 --- a/solution/1000-1099/1096.Brace Expansion II/README.md +++ b/solution/1000-1099/1096.Brace Expansion II/README.md @@ -103,6 +103,8 @@ tags: +#### Python3 + ```python class Solution: def braceExpansionII(self, expression: str) -> List[str]: @@ -121,6 +123,8 @@ class Solution: return sorted(s) ``` +#### Java + ```java class Solution { private TreeSet s = new TreeSet<>(); @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ private: }; ``` +#### Go + ```go func braceExpansionII(expression string) []string { s := map[string]struct{}{} @@ -201,6 +209,8 @@ func braceExpansionII(expression string) []string { } ``` +#### TypeScript + ```ts function braceExpansionII(expression: string): string[] { const dfs = (exp: string) => { diff --git a/solution/1000-1099/1096.Brace Expansion II/README_EN.md b/solution/1000-1099/1096.Brace Expansion II/README_EN.md index df84cd2a39c96..7334a65cd71c3 100644 --- a/solution/1000-1099/1096.Brace Expansion II/README_EN.md +++ b/solution/1000-1099/1096.Brace Expansion II/README_EN.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def braceExpansionII(self, expression: str) -> List[str]: @@ -109,6 +111,8 @@ class Solution: return sorted(s) ``` +#### Java + ```java class Solution { private TreeSet s = new TreeSet<>(); @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ private: }; ``` +#### Go + ```go func braceExpansionII(expression string) []string { s := map[string]struct{}{} @@ -189,6 +197,8 @@ func braceExpansionII(expression string) []string { } ``` +#### TypeScript + ```ts function braceExpansionII(expression: string): string[] { const dfs = (exp: string) => { diff --git a/solution/1000-1099/1097.Game Play Analysis V/README.md b/solution/1000-1099/1097.Game Play Analysis V/README.md index cb8af2d8bb493..a8f1809da15ad 100644 --- a/solution/1000-1099/1097.Game Play Analysis V/README.md +++ b/solution/1000-1099/1097.Game Play Analysis V/README.md @@ -82,6 +82,8 @@ Activity 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1000-1099/1097.Game Play Analysis V/README_EN.md b/solution/1000-1099/1097.Game Play Analysis V/README_EN.md index 8b3824c06d162..259b68eb9eaa1 100644 --- a/solution/1000-1099/1097.Game Play Analysis V/README_EN.md +++ b/solution/1000-1099/1097.Game Play Analysis V/README_EN.md @@ -81,6 +81,8 @@ Player 2 installed the game on 2017-06-25 but didn't log back in on 2017-06- +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1000-1099/1098.Unpopular Books/README.md b/solution/1000-1099/1098.Unpopular Books/README.md index c1a5dbbbf85c8..bca5341115974 100644 --- a/solution/1000-1099/1098.Unpopular Books/README.md +++ b/solution/1000-1099/1098.Unpopular Books/README.md @@ -100,6 +100,8 @@ Orders 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT book_id, name diff --git a/solution/1000-1099/1098.Unpopular Books/README_EN.md b/solution/1000-1099/1098.Unpopular Books/README_EN.md index 143a629adca0e..7192f5cb083f3 100644 --- a/solution/1000-1099/1098.Unpopular Books/README_EN.md +++ b/solution/1000-1099/1098.Unpopular Books/README_EN.md @@ -101,6 +101,8 @@ Orders table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT book_id, name diff --git a/solution/1000-1099/1099.Two Sum Less Than K/README.md b/solution/1000-1099/1099.Two Sum Less Than K/README.md index af6fac8fa3ac7..ed78364241943 100644 --- a/solution/1000-1099/1099.Two Sum Less Than K/README.md +++ b/solution/1000-1099/1099.Two Sum Less Than K/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def twoSumLessThanK(self, nums: List[int], k: int) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int twoSumLessThanK(int[] nums, int k) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func twoSumLessThanK(nums []int, k int) int { sort.Ints(nums) @@ -142,6 +150,8 @@ func twoSumLessThanK(nums []int, k int) int { } ``` +#### TypeScript + ```ts function twoSumLessThanK(nums: number[], k: number): number { nums.sort((a, b) => a - b); @@ -177,6 +187,8 @@ function twoSumLessThanK(nums: number[], k: number): number { +#### Python3 + ```python class Solution: def twoSumLessThanK(self, nums: List[int], k: int) -> int: @@ -192,6 +204,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int twoSumLessThanK(int[] nums, int k) { @@ -211,6 +225,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -231,6 +247,8 @@ public: }; ``` +#### Go + ```go func twoSumLessThanK(nums []int, k int) int { sort.Ints(nums) diff --git a/solution/1000-1099/1099.Two Sum Less Than K/README_EN.md b/solution/1000-1099/1099.Two Sum Less Than K/README_EN.md index 364b51d3e2013..2d06f18daacc9 100644 --- a/solution/1000-1099/1099.Two Sum Less Than K/README_EN.md +++ b/solution/1000-1099/1099.Two Sum Less Than K/README_EN.md @@ -67,6 +67,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def twoSumLessThanK(self, nums: List[int], k: int) -> int: @@ -79,6 +81,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int twoSumLessThanK(int[] nums, int k) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func twoSumLessThanK(nums []int, k int) int { sort.Ints(nums) @@ -139,6 +147,8 @@ func twoSumLessThanK(nums []int, k int) int { } ``` +#### TypeScript + ```ts function twoSumLessThanK(nums: number[], k: number): number { nums.sort((a, b) => a - b); @@ -174,6 +184,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def twoSumLessThanK(self, nums: List[int], k: int) -> int: @@ -189,6 +201,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int twoSumLessThanK(int[] nums, int k) { @@ -208,6 +222,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -228,6 +244,8 @@ public: }; ``` +#### Go + ```go func twoSumLessThanK(nums []int, k int) int { sort.Ints(nums) diff --git a/solution/1100-1199/1100.Find K-Length Substrings With No Repeated Characters/README.md b/solution/1100-1199/1100.Find K-Length Substrings With No Repeated Characters/README.md index 242d09963b872..1269b1a60f943 100644 --- a/solution/1100-1199/1100.Find K-Length Substrings With No Repeated Characters/README.md +++ b/solution/1100-1199/1100.Find K-Length Substrings With No Repeated Characters/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def numKLenSubstrNoRepeats(self, s: str, k: int) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numKLenSubstrNoRepeats(String s, int k) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func numKLenSubstrNoRepeats(s string, k int) (ans int) { n := len(s) @@ -159,6 +167,8 @@ func numKLenSubstrNoRepeats(s string, k int) (ans int) { } ``` +#### TypeScript + ```ts function numKLenSubstrNoRepeats(s: string, k: number): number { const n = s.length; @@ -182,6 +192,8 @@ function numKLenSubstrNoRepeats(s: string, k: number): number { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1100-1199/1100.Find K-Length Substrings With No Repeated Characters/README_EN.md b/solution/1100-1199/1100.Find K-Length Substrings With No Repeated Characters/README_EN.md index 192cc6ad8aa5d..c7e1c290e9198 100644 --- a/solution/1100-1199/1100.Find K-Length Substrings With No Repeated Characters/README_EN.md +++ b/solution/1100-1199/1100.Find K-Length Substrings With No Repeated Characters/README_EN.md @@ -68,6 +68,8 @@ The time complexity is $O(n)$, and the space complexity is $O(\min(k, |\Sigma|)) +#### Python3 + ```python class Solution: def numKLenSubstrNoRepeats(self, s: str, k: int) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numKLenSubstrNoRepeats(String s, int k) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func numKLenSubstrNoRepeats(s string, k int) (ans int) { n := len(s) @@ -158,6 +166,8 @@ func numKLenSubstrNoRepeats(s string, k int) (ans int) { } ``` +#### TypeScript + ```ts function numKLenSubstrNoRepeats(s: string, k: number): number { const n = s.length; @@ -181,6 +191,8 @@ function numKLenSubstrNoRepeats(s: string, k: number): number { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1100-1199/1101.The Earliest Moment When Everyone Become Friends/README.md b/solution/1100-1199/1101.The Earliest Moment When Everyone Become Friends/README.md index 02f7acf196741..044fad0649c05 100644 --- a/solution/1100-1199/1101.The Earliest Moment When Everyone Become Friends/README.md +++ b/solution/1100-1199/1101.The Earliest Moment When Everyone Become Friends/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def earliestAcq(self, logs: List[List[int]], n: int) -> int: @@ -99,6 +101,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { private int[] p; @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func earliestAcq(logs [][]int, n int) int { sort.Slice(logs, func(i, j int) bool { return logs[i][0] < logs[j][0] }) @@ -186,6 +194,8 @@ func earliestAcq(logs [][]int, n int) int { } ``` +#### TypeScript + ```ts function earliestAcq(logs: number[][], n: number): number { const p: number[] = Array(n) @@ -212,6 +222,8 @@ function earliestAcq(logs: number[][], n: number): number { } ``` +#### Rust + ```rust struct UnionFind { p: Vec, @@ -281,6 +293,8 @@ impl Solution { +#### Python3 + ```python class UnionFind: __slots__ = ('p', 'size') @@ -318,6 +332,8 @@ class Solution: return -1 ``` +#### Java + ```java class UnionFind { private int[] p; @@ -370,6 +386,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -421,6 +439,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p, size []int @@ -474,6 +494,8 @@ func earliestAcq(logs [][]int, n int) int { } ``` +#### TypeScript + ```ts class UnionFind { private p: number[]; diff --git a/solution/1100-1199/1101.The Earliest Moment When Everyone Become Friends/README_EN.md b/solution/1100-1199/1101.The Earliest Moment When Everyone Become Friends/README_EN.md index f4b8d1f064cf6..0741c7b40913e 100644 --- a/solution/1100-1199/1101.The Earliest Moment When Everyone Become Friends/README_EN.md +++ b/solution/1100-1199/1101.The Earliest Moment When Everyone Become Friends/README_EN.md @@ -79,6 +79,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def earliestAcq(self, logs: List[List[int]], n: int) -> int: @@ -98,6 +100,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { private int[] p; @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func earliestAcq(logs [][]int, n int) int { sort.Slice(logs, func(i, j int) bool { return logs[i][0] < logs[j][0] }) @@ -185,6 +193,8 @@ func earliestAcq(logs [][]int, n int) int { } ``` +#### TypeScript + ```ts function earliestAcq(logs: number[][], n: number): number { const p: number[] = Array(n) @@ -211,6 +221,8 @@ function earliestAcq(logs: number[][], n: number): number { } ``` +#### Rust + ```rust struct UnionFind { p: Vec, @@ -280,6 +292,8 @@ impl Solution { +#### Python3 + ```python class UnionFind: __slots__ = ('p', 'size') @@ -317,6 +331,8 @@ class Solution: return -1 ``` +#### Java + ```java class UnionFind { private int[] p; @@ -369,6 +385,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -420,6 +438,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p, size []int @@ -473,6 +493,8 @@ func earliestAcq(logs [][]int, n int) int { } ``` +#### TypeScript + ```ts class UnionFind { private p: number[]; diff --git a/solution/1100-1199/1102.Path With Maximum Minimum Value/README.md b/solution/1100-1199/1102.Path With Maximum Minimum Value/README.md index 8def2813db530..d8352b60cf967 100644 --- a/solution/1100-1199/1102.Path With Maximum Minimum Value/README.md +++ b/solution/1100-1199/1102.Path With Maximum Minimum Value/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def maximumMinimumPath(self, grid: List[List[int]]) -> int: @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] p; @@ -156,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -195,6 +201,8 @@ public: }; ``` +#### Go + ```go func maximumMinimumPath(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -235,6 +243,8 @@ func maximumMinimumPath(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function maximumMinimumPath(grid: number[][]): number { const m = grid.length; @@ -275,6 +285,8 @@ function maximumMinimumPath(grid: number[][]): number { } ``` +#### Rust + ```rust struct UnionFind { p: Vec, @@ -365,6 +377,8 @@ impl Solution { +#### Python3 + ```python class UnionFind: __slots__ = ("p", "size") @@ -411,6 +425,8 @@ class Solution: return ans ``` +#### Java + ```java class UnionFind { private int[] p; @@ -476,6 +492,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -543,6 +561,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p, size []int @@ -609,6 +629,8 @@ func maximumMinimumPath(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts class UnionFind { private p: number[]; diff --git a/solution/1100-1199/1102.Path With Maximum Minimum Value/README_EN.md b/solution/1100-1199/1102.Path With Maximum Minimum Value/README_EN.md index 78f36024a0fe1..dd9b46d23582e 100644 --- a/solution/1100-1199/1102.Path With Maximum Minimum Value/README_EN.md +++ b/solution/1100-1199/1102.Path With Maximum Minimum Value/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(m \times n \times (\log (m \times n) + \alpha(m \times +#### Python3 + ```python class Solution: def maximumMinimumPath(self, grid: List[List[int]]) -> int: @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] p; @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -187,6 +193,8 @@ public: }; ``` +#### Go + ```go func maximumMinimumPath(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -227,6 +235,8 @@ func maximumMinimumPath(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function maximumMinimumPath(grid: number[][]): number { const m = grid.length; @@ -267,6 +277,8 @@ function maximumMinimumPath(grid: number[][]): number { } ``` +#### Rust + ```rust struct UnionFind { p: Vec, @@ -357,6 +369,8 @@ impl Solution { +#### Python3 + ```python class UnionFind: __slots__ = ("p", "size") @@ -403,6 +417,8 @@ class Solution: return ans ``` +#### Java + ```java class UnionFind { private int[] p; @@ -468,6 +484,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -535,6 +553,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p, size []int @@ -601,6 +621,8 @@ func maximumMinimumPath(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts class UnionFind { private p: number[]; diff --git a/solution/1100-1199/1103.Distribute Candies to People/README.md b/solution/1100-1199/1103.Distribute Candies to People/README.md index ac0a2caa75d81..abcb2c413cc02 100644 --- a/solution/1100-1199/1103.Distribute Candies to People/README.md +++ b/solution/1100-1199/1103.Distribute Candies to People/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def distributeCandies(self, candies: int, num_people: int) -> List[int]: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] distributeCandies(int candies, int num_people) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func distributeCandies(candies int, num_people int) []int { ans := make([]int, num_people) @@ -128,6 +136,8 @@ func distributeCandies(candies int, num_people int) []int { } ``` +#### TypeScript + ```ts function distributeCandies(candies: number, num_people: number): number[] { const ans: number[] = Array(num_people).fill(0); diff --git a/solution/1100-1199/1103.Distribute Candies to People/README_EN.md b/solution/1100-1199/1103.Distribute Candies to People/README_EN.md index 1d491a592f9c4..26aeccf723611 100644 --- a/solution/1100-1199/1103.Distribute Candies to People/README_EN.md +++ b/solution/1100-1199/1103.Distribute Candies to People/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(\max(\sqrt{candies}, num\_people))$, and the space com +#### Python3 + ```python class Solution: def distributeCandies(self, candies: int, num_people: int) -> List[int]: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] distributeCandies(int candies, int num_people) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func distributeCandies(candies int, num_people int) []int { ans := make([]int, num_people) @@ -126,6 +134,8 @@ func distributeCandies(candies int, num_people int) []int { } ``` +#### TypeScript + ```ts function distributeCandies(candies: number, num_people: number): number[] { const ans: number[] = Array(num_people).fill(0); diff --git a/solution/1100-1199/1104.Path In Zigzag Labelled Binary Tree/README.md b/solution/1100-1199/1104.Path In Zigzag Labelled Binary Tree/README.md index 4c095e6f12228..0c41c9eb535e0 100644 --- a/solution/1100-1199/1104.Path In Zigzag Labelled Binary Tree/README.md +++ b/solution/1100-1199/1104.Path In Zigzag Labelled Binary Tree/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def pathInZigZagTree(self, label: int) -> List[int]: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List pathInZigZagTree(int label) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func pathInZigZagTree(label int) (ans []int) { x, i := 1, 1 diff --git a/solution/1100-1199/1104.Path In Zigzag Labelled Binary Tree/README_EN.md b/solution/1100-1199/1104.Path In Zigzag Labelled Binary Tree/README_EN.md index f1d2ee98fdd68..779ed71db1b1e 100644 --- a/solution/1100-1199/1104.Path In Zigzag Labelled Binary Tree/README_EN.md +++ b/solution/1100-1199/1104.Path In Zigzag Labelled Binary Tree/README_EN.md @@ -66,6 +66,8 @@ The time complexity is $O(\log n)$, where $n$ is the label of the node. Ignoring +#### Python3 + ```python class Solution: def pathInZigZagTree(self, label: int) -> List[int]: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List pathInZigZagTree(int label) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func pathInZigZagTree(label int) (ans []int) { x, i := 1, 1 diff --git a/solution/1100-1199/1105.Filling Bookcase Shelves/README.md b/solution/1100-1199/1105.Filling Bookcase Shelves/README.md index 3eef758cc6307..f9ed7b9e09d9f 100644 --- a/solution/1100-1199/1105.Filling Bookcase Shelves/README.md +++ b/solution/1100-1199/1105.Filling Bookcase Shelves/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def minHeightShelves(self, books: List[List[int]], shelfWidth: int) -> int: @@ -103,6 +105,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int minHeightShelves(int[][] books, int shelfWidth) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func minHeightShelves(books [][]int, shelfWidth int) int { n := len(books) @@ -169,6 +177,8 @@ func minHeightShelves(books [][]int, shelfWidth int) int { } ``` +#### TypeScript + ```ts function minHeightShelves(books: number[][], shelfWidth: number): number { const n = books.length; @@ -189,6 +199,8 @@ function minHeightShelves(books: number[][], shelfWidth: number): number { } ``` +#### C# + ```cs public class Solution { public int MinHeightShelves(int[][] books, int shelfWidth) { diff --git a/solution/1100-1199/1105.Filling Bookcase Shelves/README_EN.md b/solution/1100-1199/1105.Filling Bookcase Shelves/README_EN.md index 2303e2ddf1377..d5cd895e6ee09 100644 --- a/solution/1100-1199/1105.Filling Bookcase Shelves/README_EN.md +++ b/solution/1100-1199/1105.Filling Bookcase Shelves/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$. Here, $n$ i +#### Python3 + ```python class Solution: def minHeightShelves(self, books: List[List[int]], shelfWidth: int) -> int: @@ -97,6 +99,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int minHeightShelves(int[][] books, int shelfWidth) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func minHeightShelves(books [][]int, shelfWidth int) int { n := len(books) @@ -163,6 +171,8 @@ func minHeightShelves(books [][]int, shelfWidth int) int { } ``` +#### TypeScript + ```ts function minHeightShelves(books: number[][], shelfWidth: number): number { const n = books.length; @@ -183,6 +193,8 @@ function minHeightShelves(books: number[][], shelfWidth: number): number { } ``` +#### C# + ```cs public class Solution { public int MinHeightShelves(int[][] books, int shelfWidth) { diff --git a/solution/1100-1199/1106.Parsing A Boolean Expression/README.md b/solution/1100-1199/1106.Parsing A Boolean Expression/README.md index fe9f80fe32332..205daae213a13 100644 --- a/solution/1100-1199/1106.Parsing A Boolean Expression/README.md +++ b/solution/1100-1199/1106.Parsing A Boolean Expression/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python class Solution: def parseBoolExpr(self, expression: str) -> bool: @@ -119,6 +121,8 @@ class Solution: return stk[0] == 't' ``` +#### Java + ```java class Solution { public boolean parseBoolExpr(String expression) { @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func parseBoolExpr(expression string) bool { stk := []rune{} @@ -203,6 +211,8 @@ func parseBoolExpr(expression string) bool { } ``` +#### TypeScript + ```ts function parseBoolExpr(expression: string): boolean { const expr = expression; @@ -234,6 +244,8 @@ function parseBoolExpr(expression: string): boolean { } ``` +#### Rust + ```rust impl Solution { fn dfs(i: &mut usize, expr: &[u8]) -> Vec { diff --git a/solution/1100-1199/1106.Parsing A Boolean Expression/README_EN.md b/solution/1100-1199/1106.Parsing A Boolean Expression/README_EN.md index 52dc6bb799160..80c5be3a3fa53 100644 --- a/solution/1100-1199/1106.Parsing A Boolean Expression/README_EN.md +++ b/solution/1100-1199/1106.Parsing A Boolean Expression/README_EN.md @@ -93,6 +93,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def parseBoolExpr(self, expression: str) -> bool: @@ -117,6 +119,8 @@ class Solution: return stk[0] == 't' ``` +#### Java + ```java class Solution { public boolean parseBoolExpr(String expression) { @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go func parseBoolExpr(expression string) bool { stk := []rune{} @@ -201,6 +209,8 @@ func parseBoolExpr(expression string) bool { } ``` +#### TypeScript + ```ts function parseBoolExpr(expression: string): boolean { const expr = expression; @@ -232,6 +242,8 @@ function parseBoolExpr(expression: string): boolean { } ``` +#### Rust + ```rust impl Solution { fn dfs(i: &mut usize, expr: &[u8]) -> Vec { diff --git a/solution/1100-1199/1107.New Users Daily Count/README.md b/solution/1100-1199/1107.New Users Daily Count/README.md index 2d471e9d18ca0..8568dc60dab06 100644 --- a/solution/1100-1199/1107.New Users Daily Count/README.md +++ b/solution/1100-1199/1107.New Users Daily Count/README.md @@ -89,6 +89,8 @@ ID 为 5 的用户第一次登陆于 2019-03-01,因此他不算在 2019-06-21 +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1100-1199/1107.New Users Daily Count/README_EN.md b/solution/1100-1199/1107.New Users Daily Count/README_EN.md index d980ffbf3a765..4b7c4364a9e31 100644 --- a/solution/1100-1199/1107.New Users Daily Count/README_EN.md +++ b/solution/1100-1199/1107.New Users Daily Count/README_EN.md @@ -85,6 +85,8 @@ The user with id 5 first logged in on 2019-03-01 so he's not counted on 2019 +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1100-1199/1108.Defanging an IP Address/README.md b/solution/1100-1199/1108.Defanging an IP Address/README.md index 329cee592d20d..f6dbb59312892 100644 --- a/solution/1100-1199/1108.Defanging an IP Address/README.md +++ b/solution/1100-1199/1108.Defanging an IP Address/README.md @@ -58,12 +58,16 @@ tags: +#### Python3 + ```python class Solution: def defangIPaddr(self, address: str) -> str: return address.replace('.', '[.]') ``` +#### Java + ```java class Solution { public String defangIPaddr(String address) { @@ -72,6 +76,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -86,12 +92,16 @@ public: }; ``` +#### Go + ```go func defangIPaddr(address string) string { return strings.Replace(address, ".", "[.]", -1) } ``` +#### TypeScript + ```ts function defangIPaddr(address: string): string { return address.split('.').join('[.]'); diff --git a/solution/1100-1199/1108.Defanging an IP Address/README_EN.md b/solution/1100-1199/1108.Defanging an IP Address/README_EN.md index cd3337bf561c8..537e7be2aa54c 100644 --- a/solution/1100-1199/1108.Defanging an IP Address/README_EN.md +++ b/solution/1100-1199/1108.Defanging an IP Address/README_EN.md @@ -62,12 +62,16 @@ The time complexity is $O(n)$, where $n$ is the length of the string. Ignoring t +#### Python3 + ```python class Solution: def defangIPaddr(self, address: str) -> str: return address.replace('.', '[.]') ``` +#### Java + ```java class Solution { public String defangIPaddr(String address) { @@ -76,6 +80,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -90,12 +96,16 @@ public: }; ``` +#### Go + ```go func defangIPaddr(address string) string { return strings.Replace(address, ".", "[.]", -1) } ``` +#### TypeScript + ```ts function defangIPaddr(address: string): string { return address.split('.').join('[.]'); diff --git a/solution/1100-1199/1109.Corporate Flight Bookings/README.md b/solution/1100-1199/1109.Corporate Flight Bookings/README.md index 9d09eb2a04d01..220cacf362eda 100644 --- a/solution/1100-1199/1109.Corporate Flight Bookings/README.md +++ b/solution/1100-1199/1109.Corporate Flight Bookings/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def corpFlightBookings(self, bookings: List[List[int]], n: int) -> List[int]: @@ -91,6 +93,8 @@ class Solution: return list(accumulate(ans)) ``` +#### Java + ```java class Solution { public int[] corpFlightBookings(int[][] bookings, int n) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func corpFlightBookings(bookings [][]int, n int) []int { ans := make([]int, n) @@ -147,6 +155,8 @@ func corpFlightBookings(bookings [][]int, n int) []int { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -172,6 +182,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} bookings @@ -216,6 +228,8 @@ var corpFlightBookings = function (bookings, n) { +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -244,6 +258,8 @@ class Solution: return [tree.query(i + 1) for i in range(n)] ``` +#### Java + ```java class Solution { public int[] corpFlightBookings(int[][] bookings, int n) { @@ -288,6 +304,8 @@ class BinaryIndexedTree { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -334,6 +352,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int diff --git a/solution/1100-1199/1109.Corporate Flight Bookings/README_EN.md b/solution/1100-1199/1109.Corporate Flight Bookings/README_EN.md index 4330fd8e6da1b..5c789cc6ba513 100644 --- a/solution/1100-1199/1109.Corporate Flight Bookings/README_EN.md +++ b/solution/1100-1199/1109.Corporate Flight Bookings/README_EN.md @@ -79,6 +79,8 @@ The time complexity is $O(n)$, where $n$ is the number of flights. Ignoring the +#### Python3 + ```python class Solution: def corpFlightBookings(self, bookings: List[List[int]], n: int) -> List[int]: @@ -90,6 +92,8 @@ class Solution: return list(accumulate(ans)) ``` +#### Java + ```java class Solution { public int[] corpFlightBookings(int[][] bookings, int n) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func corpFlightBookings(bookings [][]int, n int) []int { ans := make([]int, n) @@ -146,6 +154,8 @@ func corpFlightBookings(bookings [][]int, n int) []int { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -171,6 +181,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} bookings @@ -215,6 +227,8 @@ The time complexity of these two operations is $O(\log n)$. +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -243,6 +257,8 @@ class Solution: return [tree.query(i + 1) for i in range(n)] ``` +#### Java + ```java class Solution { public int[] corpFlightBookings(int[][] bookings, int n) { @@ -287,6 +303,8 @@ class BinaryIndexedTree { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -333,6 +351,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int diff --git a/solution/1100-1199/1110.Delete Nodes And Return Forest/README.md b/solution/1100-1199/1110.Delete Nodes And Return Forest/README.md index bde78d7bbaf79..e48d1ae455c55 100644 --- a/solution/1100-1199/1110.Delete Nodes And Return Forest/README.md +++ b/solution/1100-1199/1110.Delete Nodes And Return Forest/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -158,6 +162,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -204,6 +210,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -243,6 +251,8 @@ func delNodes(root *TreeNode, to_delete []int) (ans []*TreeNode) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/1100-1199/1110.Delete Nodes And Return Forest/README_EN.md b/solution/1100-1199/1110.Delete Nodes And Return Forest/README_EN.md index aa1461abae158..d134bbac3d5fb 100644 --- a/solution/1100-1199/1110.Delete Nodes And Return Forest/README_EN.md +++ b/solution/1100-1199/1110.Delete Nodes And Return Forest/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -200,6 +206,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -239,6 +247,8 @@ func delNodes(root *TreeNode, to_delete []int) (ans []*TreeNode) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/1100-1199/1111.Maximum Nesting Depth of Two Valid Parentheses Strings/README.md b/solution/1100-1199/1111.Maximum Nesting Depth of Two Valid Parentheses Strings/README.md index 855ebec999d86..ead184537a88b 100644 --- a/solution/1100-1199/1111.Maximum Nesting Depth of Two Valid Parentheses Strings/README.md +++ b/solution/1100-1199/1111.Maximum Nesting Depth of Two Valid Parentheses Strings/README.md @@ -111,6 +111,8 @@ tags: +#### Python3 + ```python class Solution: def maxDepthAfterSplit(self, seq: str) -> List[int]: @@ -126,6 +128,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] maxDepthAfterSplit(String seq) { @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func maxDepthAfterSplit(seq string) []int { n := len(seq) @@ -178,6 +186,8 @@ func maxDepthAfterSplit(seq string) []int { } ``` +#### TypeScript + ```ts function maxDepthAfterSplit(seq: string): number[] { const n = seq.length; diff --git a/solution/1100-1199/1111.Maximum Nesting Depth of Two Valid Parentheses Strings/README_EN.md b/solution/1100-1199/1111.Maximum Nesting Depth of Two Valid Parentheses Strings/README_EN.md index a79802e4bead8..f4d4f5e49c794 100644 --- a/solution/1100-1199/1111.Maximum Nesting Depth of Two Valid Parentheses Strings/README_EN.md +++ b/solution/1100-1199/1111.Maximum Nesting Depth of Two Valid Parentheses Strings/README_EN.md @@ -91,6 +91,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string $seq$. Igno +#### Python3 + ```python class Solution: def maxDepthAfterSplit(self, seq: str) -> List[int]: @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] maxDepthAfterSplit(String seq) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func maxDepthAfterSplit(seq string) []int { n := len(seq) @@ -158,6 +166,8 @@ func maxDepthAfterSplit(seq string) []int { } ``` +#### TypeScript + ```ts function maxDepthAfterSplit(seq: string): number[] { const n = seq.length; diff --git a/solution/1100-1199/1112.Highest Grade For Each Student/README.md b/solution/1100-1199/1112.Highest Grade For Each Student/README.md index 55621e80ac420..c7f4d4b34a3f1 100644 --- a/solution/1100-1199/1112.Highest Grade For Each Student/README.md +++ b/solution/1100-1199/1112.Highest Grade For Each Student/README.md @@ -74,6 +74,8 @@ Enrollments 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -104,6 +106,8 @@ ORDER BY student_id; +#### MySQL + ```sql # Write your MySQL query statement below SELECT student_id, MIN(course_id) AS course_id, grade diff --git a/solution/1100-1199/1112.Highest Grade For Each Student/README_EN.md b/solution/1100-1199/1112.Highest Grade For Each Student/README_EN.md index a72cfbcc73fa6..372264caf3c90 100644 --- a/solution/1100-1199/1112.Highest Grade For Each Student/README_EN.md +++ b/solution/1100-1199/1112.Highest Grade For Each Student/README_EN.md @@ -77,6 +77,8 @@ We can use the `RANK() OVER()` window function to sort the grades of each studen +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -107,6 +109,8 @@ We can first query the highest grade of each student, and then query the minimum +#### MySQL + ```sql # Write your MySQL query statement below SELECT student_id, MIN(course_id) AS course_id, grade diff --git a/solution/1100-1199/1113.Reported Posts/README.md b/solution/1100-1199/1113.Reported Posts/README.md index 31dd88d4311cd..ab4307167d836 100644 --- a/solution/1100-1199/1113.Reported Posts/README.md +++ b/solution/1100-1199/1113.Reported Posts/README.md @@ -86,6 +86,8 @@ Actions table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT extra AS report_reason, COUNT(DISTINCT post_id) AS report_count diff --git a/solution/1100-1199/1113.Reported Posts/README_EN.md b/solution/1100-1199/1113.Reported Posts/README_EN.md index 37851a790ac15..c2d0a5aad00c6 100644 --- a/solution/1100-1199/1113.Reported Posts/README_EN.md +++ b/solution/1100-1199/1113.Reported Posts/README_EN.md @@ -85,6 +85,8 @@ Actions table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT extra AS report_reason, COUNT(DISTINCT post_id) AS report_count diff --git a/solution/1100-1199/1114.Print in Order/README.md b/solution/1100-1199/1114.Print in Order/README.md index fef4550eec946..a62581411285d 100644 --- a/solution/1100-1199/1114.Print in Order/README.md +++ b/solution/1100-1199/1114.Print in Order/README.md @@ -91,6 +91,8 @@ public class Foo { +#### Python3 + ```python class Foo: def __init__(self): @@ -113,6 +115,8 @@ class Foo: printThird() ``` +#### Java + ```java class Foo { private Semaphore a = new Semaphore(1); @@ -145,6 +149,8 @@ class Foo { } ``` +#### C++ + ```cpp class Foo { private: @@ -184,6 +190,8 @@ public: +#### Python3 + ```python from threading import Semaphore @@ -213,6 +221,8 @@ class Foo: self.a.release() ``` +#### C++ + ```cpp #include diff --git a/solution/1100-1199/1114.Print in Order/README_EN.md b/solution/1100-1199/1114.Print in Order/README_EN.md index dd890666a299d..a7361b5340d19 100644 --- a/solution/1100-1199/1114.Print in Order/README_EN.md +++ b/solution/1100-1199/1114.Print in Order/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Foo: def __init__(self): @@ -98,6 +100,8 @@ class Foo: printThird() ``` +#### Java + ```java class Foo { private Semaphore a = new Semaphore(1); @@ -130,6 +134,8 @@ class Foo { } ``` +#### C++ + ```cpp class Foo { private: @@ -169,6 +175,8 @@ public: +#### Python3 + ```python from threading import Semaphore @@ -198,6 +206,8 @@ class Foo: self.a.release() ``` +#### C++ + ```cpp #include diff --git a/solution/1100-1199/1115.Print FooBar Alternately/README.md b/solution/1100-1199/1115.Print FooBar Alternately/README.md index 3aef8313b30d2..db37fa24b9b43 100644 --- a/solution/1100-1199/1115.Print FooBar Alternately/README.md +++ b/solution/1100-1199/1115.Print FooBar Alternately/README.md @@ -89,6 +89,8 @@ class FooBar { +#### Python3 + ```python from threading import Semaphore @@ -114,6 +116,8 @@ class FooBar: self.f.release() ``` +#### Java + ```java class FooBar { private int n; @@ -144,6 +148,8 @@ class FooBar { } ``` +#### C++ + ```cpp #include diff --git a/solution/1100-1199/1115.Print FooBar Alternately/README_EN.md b/solution/1100-1199/1115.Print FooBar Alternately/README_EN.md index 58be1e15cbb08..24fe60806f2ec 100644 --- a/solution/1100-1199/1115.Print FooBar Alternately/README_EN.md +++ b/solution/1100-1199/1115.Print FooBar Alternately/README_EN.md @@ -88,6 +88,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. +#### Python3 + ```python from threading import Semaphore @@ -113,6 +115,8 @@ class FooBar: self.f.release() ``` +#### Java + ```java class FooBar { private int n; @@ -143,6 +147,8 @@ class FooBar { } ``` +#### C++ + ```cpp #include diff --git a/solution/1100-1199/1116.Print Zero Even Odd/README.md b/solution/1100-1199/1116.Print Zero Even Odd/README.md index 9166961e09552..e80cec71f6b60 100644 --- a/solution/1100-1199/1116.Print Zero Even Odd/README.md +++ b/solution/1100-1199/1116.Print Zero Even Odd/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python from threading import Semaphore @@ -118,6 +120,8 @@ class ZeroEvenOdd: self.z.release() ``` +#### Java + ```java class ZeroEvenOdd { private int n; @@ -160,6 +164,8 @@ class ZeroEvenOdd { } ``` +#### C++ + ```cpp #include diff --git a/solution/1100-1199/1116.Print Zero Even Odd/README_EN.md b/solution/1100-1199/1116.Print Zero Even Odd/README_EN.md index c63c3c444bb14..a5997cc4b2fb7 100644 --- a/solution/1100-1199/1116.Print Zero Even Odd/README_EN.md +++ b/solution/1100-1199/1116.Print Zero Even Odd/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. +#### Python3 + ```python from threading import Semaphore @@ -118,6 +120,8 @@ class ZeroEvenOdd: self.z.release() ``` +#### Java + ```java class ZeroEvenOdd { private int n; @@ -160,6 +164,8 @@ class ZeroEvenOdd { } ``` +#### C++ + ```cpp #include diff --git a/solution/1100-1199/1117.Building H2O/README.md b/solution/1100-1199/1117.Building H2O/README.md index f866b77e02793..1ad1cd02ccf7b 100644 --- a/solution/1100-1199/1117.Building H2O/README.md +++ b/solution/1100-1199/1117.Building H2O/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python from threading import Semaphore @@ -98,6 +100,8 @@ class H2O: self.h.release(2) ``` +#### Java + ```java class H2O { private Semaphore h = new Semaphore(2); @@ -122,6 +126,8 @@ class H2O { } ``` +#### C++ + ```cpp #include diff --git a/solution/1100-1199/1117.Building H2O/README_EN.md b/solution/1100-1199/1117.Building H2O/README_EN.md index 75a37e2edd701..67c463b6630f5 100644 --- a/solution/1100-1199/1117.Building H2O/README_EN.md +++ b/solution/1100-1199/1117.Building H2O/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python from threading import Semaphore @@ -92,6 +94,8 @@ class H2O: self.h.release(2) ``` +#### Java + ```java class H2O { private Semaphore h = new Semaphore(2); @@ -116,6 +120,8 @@ class H2O { } ``` +#### C++ + ```cpp #include diff --git a/solution/1100-1199/1118.Number of Days in a Month/README.md b/solution/1100-1199/1118.Number of Days in a Month/README.md index 555dcbf8f61ab..76a9e39c4e9eb 100644 --- a/solution/1100-1199/1118.Number of Days in a Month/README.md +++ b/solution/1100-1199/1118.Number of Days in a Month/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfDays(self, year: int, month: int) -> int: @@ -78,6 +80,8 @@ class Solution: return days[month] ``` +#### Java + ```java class Solution { public int numberOfDays(int year, int month) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -99,6 +105,8 @@ public: }; ``` +#### Go + ```go func numberOfDays(year int, month int) int { leap := (year%4 == 0 && year%100 != 0) || (year%400 == 0) @@ -111,6 +119,8 @@ func numberOfDays(year int, month int) int { } ``` +#### TypeScript + ```ts function numberOfDays(year: number, month: number): number { const leap = (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; diff --git a/solution/1100-1199/1118.Number of Days in a Month/README_EN.md b/solution/1100-1199/1118.Number of Days in a Month/README_EN.md index 83de26eb879f4..7fab70b69b123 100644 --- a/solution/1100-1199/1118.Number of Days in a Month/README_EN.md +++ b/solution/1100-1199/1118.Number of Days in a Month/README_EN.md @@ -57,6 +57,8 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def numberOfDays(self, year: int, month: int) -> int: @@ -65,6 +67,8 @@ class Solution: return days[month] ``` +#### Java + ```java class Solution { public int numberOfDays(int year, int month) { @@ -75,6 +79,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -86,6 +92,8 @@ public: }; ``` +#### Go + ```go func numberOfDays(year int, month int) int { leap := (year%4 == 0 && year%100 != 0) || (year%400 == 0) @@ -98,6 +106,8 @@ func numberOfDays(year int, month int) int { } ``` +#### TypeScript + ```ts function numberOfDays(year: number, month: number): number { const leap = (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; diff --git a/solution/1100-1199/1119.Remove Vowels from a String/README.md b/solution/1100-1199/1119.Remove Vowels from a String/README.md index 2860e97a50b19..42a29fa3493a2 100644 --- a/solution/1100-1199/1119.Remove Vowels from a String/README.md +++ b/solution/1100-1199/1119.Remove Vowels from a String/README.md @@ -59,12 +59,16 @@ tags: +#### Python3 + ```python class Solution: def removeVowels(self, s: str) -> str: return "".join(c for c in s if c not in "aeiou") ``` +#### Java + ```java class Solution { public String removeVowels(String s) { @@ -80,6 +84,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -95,6 +101,8 @@ public: }; ``` +#### Go + ```go func removeVowels(s string) string { ans := []rune{} @@ -107,6 +115,8 @@ func removeVowels(s string) string { } ``` +#### TypeScript + ```ts function removeVowels(s: string): string { return s.replace(/[aeiou]/g, ''); diff --git a/solution/1100-1199/1119.Remove Vowels from a String/README_EN.md b/solution/1100-1199/1119.Remove Vowels from a String/README_EN.md index 0b3de6fcdb752..7b2146ca97be9 100644 --- a/solution/1100-1199/1119.Remove Vowels from a String/README_EN.md +++ b/solution/1100-1199/1119.Remove Vowels from a String/README_EN.md @@ -57,12 +57,16 @@ The time complexity is $O(n)$, where $n$ is the length of the string. Ignoring t +#### Python3 + ```python class Solution: def removeVowels(self, s: str) -> str: return "".join(c for c in s if c not in "aeiou") ``` +#### Java + ```java class Solution { public String removeVowels(String s) { @@ -78,6 +82,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -93,6 +99,8 @@ public: }; ``` +#### Go + ```go func removeVowels(s string) string { ans := []rune{} @@ -105,6 +113,8 @@ func removeVowels(s string) string { } ``` +#### TypeScript + ```ts function removeVowels(s: string): string { return s.replace(/[aeiou]/g, ''); diff --git a/solution/1100-1199/1120.Maximum Average Subtree/README.md b/solution/1100-1199/1120.Maximum Average Subtree/README.md index d9d1c2ed3531f..c384c1043fd0c 100644 --- a/solution/1100-1199/1120.Maximum Average Subtree/README.md +++ b/solution/1100-1199/1120.Maximum Average Subtree/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/1100-1199/1120.Maximum Average Subtree/README_EN.md b/solution/1100-1199/1120.Maximum Average Subtree/README_EN.md index d339ef901e68d..8ebfa391c5277 100644 --- a/solution/1100-1199/1120.Maximum Average Subtree/README_EN.md +++ b/solution/1100-1199/1120.Maximum Average Subtree/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -103,6 +105,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/1100-1199/1121.Divide Array Into Increasing Sequences/README.md b/solution/1100-1199/1121.Divide Array Into Increasing Sequences/README.md index b245850f884e3..638536de4c88f 100644 --- a/solution/1100-1199/1121.Divide Array Into Increasing Sequences/README.md +++ b/solution/1100-1199/1121.Divide Array Into Increasing Sequences/README.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def canDivideIntoSubsequences(self, nums: List[int], k: int) -> bool: @@ -70,6 +72,8 @@ class Solution: return mx * k <= len(nums) ``` +#### Java + ```java class Solution { public boolean canDivideIntoSubsequences(int[] nums, int k) { @@ -83,6 +87,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,6 +107,8 @@ public: }; ``` +#### Go + ```go func canDivideIntoSubsequences(nums []int, k int) bool { cnt, a := 0, 0 @@ -128,6 +136,8 @@ func canDivideIntoSubsequences(nums []int, k int) bool { +#### Java + ```java class Solution { public boolean canDivideIntoSubsequences(int[] nums, int k) { diff --git a/solution/1100-1199/1121.Divide Array Into Increasing Sequences/README_EN.md b/solution/1100-1199/1121.Divide Array Into Increasing Sequences/README_EN.md index 24bd31e54e12c..69ac721a07dae 100644 --- a/solution/1100-1199/1121.Divide Array Into Increasing Sequences/README_EN.md +++ b/solution/1100-1199/1121.Divide Array Into Increasing Sequences/README_EN.md @@ -61,6 +61,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is +#### Python3 + ```python class Solution: def canDivideIntoSubsequences(self, nums: List[int], k: int) -> bool: @@ -68,6 +70,8 @@ class Solution: return mx * k <= len(nums) ``` +#### Java + ```java class Solution { public boolean canDivideIntoSubsequences(int[] nums, int k) { @@ -81,6 +85,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -99,6 +105,8 @@ public: }; ``` +#### Go + ```go func canDivideIntoSubsequences(nums []int, k int) bool { cnt, a := 0, 0 @@ -126,6 +134,8 @@ func canDivideIntoSubsequences(nums []int, k int) bool { +#### Java + ```java class Solution { public boolean canDivideIntoSubsequences(int[] nums, int k) { diff --git a/solution/1100-1199/1122.Relative Sort Array/README.md b/solution/1100-1199/1122.Relative Sort Array/README.md index 435237dae4a48..221dfa28c2f08 100644 --- a/solution/1100-1199/1122.Relative Sort Array/README.md +++ b/solution/1100-1199/1122.Relative Sort Array/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def relativeSortArray(self, arr1: List[int], arr2: List[int]) -> List[int]: @@ -73,6 +75,8 @@ class Solution: return sorted(arr1, key=lambda x: pos.get(x, 1000 + x)) ``` +#### Java + ```java class Solution { public int[] relativeSortArray(int[] arr1, int[] arr2) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func relativeSortArray(arr1 []int, arr2 []int) []int { pos := map[int]int{} @@ -139,6 +147,8 @@ func relativeSortArray(arr1 []int, arr2 []int) []int { } ``` +#### TypeScript + ```ts function relativeSortArray(arr1: number[], arr2: number[]): number[] { const pos: Map = new Map(); diff --git a/solution/1100-1199/1122.Relative Sort Array/README_EN.md b/solution/1100-1199/1122.Relative Sort Array/README_EN.md index 04d12598b1162..1ac668b2ef5cd 100644 --- a/solution/1100-1199/1122.Relative Sort Array/README_EN.md +++ b/solution/1100-1199/1122.Relative Sort Array/README_EN.md @@ -64,6 +64,8 @@ The time complexity is $O(n \times \log n + m)$, and the space complexity is $O( +#### Python3 + ```python class Solution: def relativeSortArray(self, arr1: List[int], arr2: List[int]) -> List[int]: @@ -71,6 +73,8 @@ class Solution: return sorted(arr1, key=lambda x: pos.get(x, 1000 + x)) ``` +#### Java + ```java class Solution { public int[] relativeSortArray(int[] arr1, int[] arr2) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func relativeSortArray(arr1 []int, arr2 []int) []int { pos := map[int]int{} @@ -137,6 +145,8 @@ func relativeSortArray(arr1 []int, arr2 []int) []int { } ``` +#### TypeScript + ```ts function relativeSortArray(arr1: number[], arr2: number[]): number[] { const pos: Map = new Map(); diff --git a/solution/1100-1199/1123.Lowest Common Ancestor of Deepest Leaves/README.md b/solution/1100-1199/1123.Lowest Common Ancestor of Deepest Leaves/README.md index 408268a7cca20..fc17eb98f7b14 100644 --- a/solution/1100-1199/1123.Lowest Common Ancestor of Deepest Leaves/README.md +++ b/solution/1100-1199/1123.Lowest Common Ancestor of Deepest Leaves/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -115,6 +117,8 @@ class Solution: return dfs(root)[0] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -189,6 +195,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -223,6 +231,8 @@ func lcaDeepestLeaves(root *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/1100-1199/1123.Lowest Common Ancestor of Deepest Leaves/README_EN.md b/solution/1100-1199/1123.Lowest Common Ancestor of Deepest Leaves/README_EN.md index 7ddd8b26792c0..91f045fc4c941 100644 --- a/solution/1100-1199/1123.Lowest Common Ancestor of Deepest Leaves/README_EN.md +++ b/solution/1100-1199/1123.Lowest Common Ancestor of Deepest Leaves/README_EN.md @@ -89,6 +89,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -112,6 +114,8 @@ class Solution: return dfs(root)[0] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -220,6 +228,8 @@ func lcaDeepestLeaves(root *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/1100-1199/1124.Longest Well-Performing Interval/README.md b/solution/1100-1199/1124.Longest Well-Performing Interval/README.md index e20c748d51f07..09d6c45354825 100644 --- a/solution/1100-1199/1124.Longest Well-Performing Interval/README.md +++ b/solution/1100-1199/1124.Longest Well-Performing Interval/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def longestWPI(self, hours: List[int]) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestWPI(int[] hours) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func longestWPI(hours []int) (ans int) { s := 0 diff --git a/solution/1100-1199/1124.Longest Well-Performing Interval/README_EN.md b/solution/1100-1199/1124.Longest Well-Performing Interval/README_EN.md index b633e8fe408e3..a5e9199e5542d 100644 --- a/solution/1100-1199/1124.Longest Well-Performing Interval/README_EN.md +++ b/solution/1100-1199/1124.Longest Well-Performing Interval/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def longestWPI(self, hours: List[int]) -> int: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestWPI(int[] hours) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func longestWPI(hours []int) (ans int) { s := 0 diff --git a/solution/1100-1199/1125.Smallest Sufficient Team/README.md b/solution/1100-1199/1125.Smallest Sufficient Team/README.md index 97d22811a897d..24dbc0697f0fe 100644 --- a/solution/1100-1199/1125.Smallest Sufficient Team/README.md +++ b/solution/1100-1199/1125.Smallest Sufficient Team/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def smallestSufficientTeam( @@ -124,6 +126,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] smallestSufficientTeam(String[] req_skills, List> people) { @@ -166,6 +170,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -208,6 +214,8 @@ public: }; ``` +#### Go + ```go func smallestSufficientTeam(req_skills []string, people [][]string) (ans []int) { d := map[string]int{} @@ -248,6 +256,8 @@ func smallestSufficientTeam(req_skills []string, people [][]string) (ans []int) } ``` +#### TypeScript + ```ts function smallestSufficientTeam(req_skills: string[], people: string[][]): number[] { const d: Map = new Map(); diff --git a/solution/1100-1199/1125.Smallest Sufficient Team/README_EN.md b/solution/1100-1199/1125.Smallest Sufficient Team/README_EN.md index e8f5d696b842b..2942d826f648b 100644 --- a/solution/1100-1199/1125.Smallest Sufficient Team/README_EN.md +++ b/solution/1100-1199/1125.Smallest Sufficient Team/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(2^m \times n)$, and the space complexity is $O(2^m)$. +#### Python3 + ```python class Solution: def smallestSufficientTeam( @@ -117,6 +119,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] smallestSufficientTeam(String[] req_skills, List> people) { @@ -159,6 +163,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -201,6 +207,8 @@ public: }; ``` +#### Go + ```go func smallestSufficientTeam(req_skills []string, people [][]string) (ans []int) { d := map[string]int{} @@ -241,6 +249,8 @@ func smallestSufficientTeam(req_skills []string, people [][]string) (ans []int) } ``` +#### TypeScript + ```ts function smallestSufficientTeam(req_skills: string[], people: string[][]): number[] { const d: Map = new Map(); diff --git a/solution/1100-1199/1126.Active Businesses/README.md b/solution/1100-1199/1126.Active Businesses/README.md index 14112c04a6dd2..72c5cbaa644b1 100644 --- a/solution/1100-1199/1126.Active Businesses/README.md +++ b/solution/1100-1199/1126.Active Businesses/README.md @@ -83,6 +83,8 @@ id=1 的业务有 7 个 'reviews' 事件(多于 5 个)和 11 个 'ads' 事件( +#### MySQL + ```sql # Write your MySQL query statement below SELECT business_id @@ -111,6 +113,8 @@ HAVING COUNT(1) > 1; +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1100-1199/1126.Active Businesses/README_EN.md b/solution/1100-1199/1126.Active Businesses/README_EN.md index 1579cd252019d..1a3b58a7ea751 100644 --- a/solution/1100-1199/1126.Active Businesses/README_EN.md +++ b/solution/1100-1199/1126.Active Businesses/README_EN.md @@ -81,6 +81,8 @@ The business with id=1 has 7 'reviews' events (more than 5) and 11 ' +#### MySQL + ```sql # Write your MySQL query statement below SELECT business_id @@ -109,6 +111,8 @@ HAVING COUNT(1) > 1; +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1100-1199/1127.User Purchase Platform/README.md b/solution/1100-1199/1127.User Purchase Platform/README.md index 0335c10b4c553..f5cd04978c26d 100644 --- a/solution/1100-1199/1127.User Purchase Platform/README.md +++ b/solution/1100-1199/1127.User Purchase Platform/README.md @@ -81,6 +81,8 @@ Spending table: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1100-1199/1127.User Purchase Platform/README_EN.md b/solution/1100-1199/1127.User Purchase Platform/README_EN.md index cad7931105777..dffd54777051e 100644 --- a/solution/1100-1199/1127.User Purchase Platform/README_EN.md +++ b/solution/1100-1199/1127.User Purchase Platform/README_EN.md @@ -82,6 +82,8 @@ On 2019-07-02, user 2 purchased using mobile only, user 3 purch +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1100-1199/1128.Number of Equivalent Domino Pairs/README.md b/solution/1100-1199/1128.Number of Equivalent Domino Pairs/README.md index 3442cad6f41a9..1929c905a49f2 100644 --- a/solution/1100-1199/1128.Number of Equivalent Domino Pairs/README.md +++ b/solution/1100-1199/1128.Number of Equivalent Domino Pairs/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def numEquivDominoPairs(self, dominoes: List[List[int]]) -> int: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numEquivDominoPairs(int[][] dominoes) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func numEquivDominoPairs(dominoes [][]int) (ans int) { cnt := [100]int{} diff --git a/solution/1100-1199/1128.Number of Equivalent Domino Pairs/README_EN.md b/solution/1100-1199/1128.Number of Equivalent Domino Pairs/README_EN.md index c64b0ebb750e6..5da09e06b223c 100644 --- a/solution/1100-1199/1128.Number of Equivalent Domino Pairs/README_EN.md +++ b/solution/1100-1199/1128.Number of Equivalent Domino Pairs/README_EN.md @@ -64,6 +64,8 @@ The time complexity is $O(n)$, and the space complexity is $O(C)$. Here, $n$ is +#### Python3 + ```python class Solution: def numEquivDominoPairs(self, dominoes: List[List[int]]) -> int: @@ -76,6 +78,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numEquivDominoPairs(int[][] dominoes) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func numEquivDominoPairs(dominoes [][]int) (ans int) { cnt := [100]int{} diff --git a/solution/1100-1199/1129.Shortest Path with Alternating Colors/README.md b/solution/1100-1199/1129.Shortest Path with Alternating Colors/README.md index 03cb7faa6a3c9..165b727003573 100644 --- a/solution/1100-1199/1129.Shortest Path with Alternating Colors/README.md +++ b/solution/1100-1199/1129.Shortest Path with Alternating Colors/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def shortestAlternatingPaths( @@ -114,6 +116,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] shortestAlternatingPaths(int n, int[][] redEdges, int[][] blueEdges) { @@ -156,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -196,6 +202,8 @@ public: }; ``` +#### Go + ```go func shortestAlternatingPaths(n int, redEdges [][]int, blueEdges [][]int) []int { g := [2][][]int{} diff --git a/solution/1100-1199/1129.Shortest Path with Alternating Colors/README_EN.md b/solution/1100-1199/1129.Shortest Path with Alternating Colors/README_EN.md index a0161cad640e1..a2b6eaa73e7e0 100644 --- a/solution/1100-1199/1129.Shortest Path with Alternating Colors/README_EN.md +++ b/solution/1100-1199/1129.Shortest Path with Alternating Colors/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n + m)$, and the space complexity is $O(n + m)$. Here, +#### Python3 + ```python class Solution: def shortestAlternatingPaths( @@ -112,6 +114,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] shortestAlternatingPaths(int n, int[][] redEdges, int[][] blueEdges) { @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -194,6 +200,8 @@ public: }; ``` +#### Go + ```go func shortestAlternatingPaths(n int, redEdges [][]int, blueEdges [][]int) []int { g := [2][][]int{} diff --git a/solution/1100-1199/1130.Minimum Cost Tree From Leaf Values/README.md b/solution/1100-1199/1130.Minimum Cost Tree From Leaf Values/README.md index 69717e5b2dbc0..098e5a5df0d03 100644 --- a/solution/1100-1199/1130.Minimum Cost Tree From Leaf Values/README.md +++ b/solution/1100-1199/1130.Minimum Cost Tree From Leaf Values/README.md @@ -102,6 +102,8 @@ $$ +#### Python3 + ```python class Solution: def mctFromLeafValues(self, arr: List[int]) -> int: @@ -122,6 +124,8 @@ class Solution: return dfs(0, len(arr) - 1)[0] ``` +#### Java + ```java class Solution { private Integer[][] f; @@ -156,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go func mctFromLeafValues(arr []int) int { n := len(arr) @@ -219,6 +227,8 @@ func mctFromLeafValues(arr []int) int { } ``` +#### TypeScript + ```ts function mctFromLeafValues(arr: number[]): number { const n = arr.length; @@ -272,6 +282,8 @@ $$ +#### Python3 + ```python class Solution: def mctFromLeafValues(self, arr: List[int]) -> int: @@ -292,6 +304,8 @@ class Solution: return dfs(0, n - 1) ``` +#### Java + ```java class Solution { public int mctFromLeafValues(int[] arr) { @@ -313,6 +327,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -336,6 +352,8 @@ public: }; ``` +#### Go + ```go func mctFromLeafValues(arr []int) int { n := len(arr) @@ -359,6 +377,8 @@ func mctFromLeafValues(arr []int) int { } ``` +#### TypeScript + ```ts function mctFromLeafValues(arr: number[]): number { const n = arr.length; @@ -388,6 +408,8 @@ function mctFromLeafValues(arr: number[]): number { +#### Python3 + ```python class Solution: def mctFromLeafValues(self, arr: List[int]) -> int: diff --git a/solution/1100-1199/1130.Minimum Cost Tree From Leaf Values/README_EN.md b/solution/1100-1199/1130.Minimum Cost Tree From Leaf Values/README_EN.md index f25c2b01ad9b1..8f9e9930c6536 100644 --- a/solution/1100-1199/1130.Minimum Cost Tree From Leaf Values/README_EN.md +++ b/solution/1100-1199/1130.Minimum Cost Tree From Leaf Values/README_EN.md @@ -101,6 +101,8 @@ The time complexity is $O(n^3)$, and the space complexity is $O(n^2)$. Here, $n$ +#### Python3 + ```python class Solution: def mctFromLeafValues(self, arr: List[int]) -> int: @@ -121,6 +123,8 @@ class Solution: return dfs(0, len(arr) - 1)[0] ``` +#### Java + ```java class Solution { private Integer[][] f; @@ -155,6 +159,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -187,6 +193,8 @@ public: }; ``` +#### Go + ```go func mctFromLeafValues(arr []int) int { n := len(arr) @@ -218,6 +226,8 @@ func mctFromLeafValues(arr []int) int { } ``` +#### TypeScript + ```ts function mctFromLeafValues(arr: number[]): number { const n = arr.length; @@ -271,6 +281,8 @@ The time complexity is $O(n^3)$, and the space complexity is $O(n^2)$. Here, $n$ +#### Python3 + ```python class Solution: def mctFromLeafValues(self, arr: List[int]) -> int: @@ -291,6 +303,8 @@ class Solution: return dfs(0, n - 1) ``` +#### Java + ```java class Solution { public int mctFromLeafValues(int[] arr) { @@ -312,6 +326,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -335,6 +351,8 @@ public: }; ``` +#### Go + ```go func mctFromLeafValues(arr []int) int { n := len(arr) @@ -358,6 +376,8 @@ func mctFromLeafValues(arr []int) int { } ``` +#### TypeScript + ```ts function mctFromLeafValues(arr: number[]): number { const n = arr.length; @@ -387,6 +407,8 @@ function mctFromLeafValues(arr: number[]): number { +#### Python3 + ```python class Solution: def mctFromLeafValues(self, arr: List[int]) -> int: diff --git a/solution/1100-1199/1131.Maximum of Absolute Value Expression/README.md b/solution/1100-1199/1131.Maximum of Absolute Value Expression/README.md index fb3ae68fdb267..4990bc3bf387c 100644 --- a/solution/1100-1199/1131.Maximum of Absolute Value Expression/README.md +++ b/solution/1100-1199/1131.Maximum of Absolute Value Expression/README.md @@ -72,6 +72,8 @@ $$ +#### Python3 + ```python class Solution: def maxAbsValExpr(self, arr1: List[int], arr2: List[int]) -> int: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxAbsValExpr(int[] arr1, int[] arr2) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func maxAbsValExpr(arr1 []int, arr2 []int) int { dirs := [5]int{1, -1, -1, 1, 1} @@ -148,6 +156,8 @@ func maxAbsValExpr(arr1 []int, arr2 []int) int { } ``` +#### TypeScript + ```ts function maxAbsValExpr(arr1: number[], arr2: number[]): number { const dirs = [1, -1, -1, 1, 1]; diff --git a/solution/1100-1199/1131.Maximum of Absolute Value Expression/README_EN.md b/solution/1100-1199/1131.Maximum of Absolute Value Expression/README_EN.md index 85bd31cd26f6b..8aa75c024de6b 100644 --- a/solution/1100-1199/1131.Maximum of Absolute Value Expression/README_EN.md +++ b/solution/1100-1199/1131.Maximum of Absolute Value Expression/README_EN.md @@ -73,6 +73,8 @@ Similar problems: +#### Python3 + ```python class Solution: def maxAbsValExpr(self, arr1: List[int], arr2: List[int]) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxAbsValExpr(int[] arr1, int[] arr2) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func maxAbsValExpr(arr1 []int, arr2 []int) int { dirs := [5]int{1, -1, -1, 1, 1} @@ -149,6 +157,8 @@ func maxAbsValExpr(arr1 []int, arr2 []int) int { } ``` +#### TypeScript + ```ts function maxAbsValExpr(arr1: number[], arr2: number[]): number { const dirs = [1, -1, -1, 1, 1]; diff --git a/solution/1100-1199/1132.Reported Posts II/README.md b/solution/1100-1199/1132.Reported Posts II/README.md index 1af78b53fbc36..548b664041155 100644 --- a/solution/1100-1199/1132.Reported Posts II/README.md +++ b/solution/1100-1199/1132.Reported Posts II/README.md @@ -106,6 +106,8 @@ Removals table: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1100-1199/1132.Reported Posts II/README_EN.md b/solution/1100-1199/1132.Reported Posts II/README_EN.md index 6239171d6bc72..ed8c7206c6581 100644 --- a/solution/1100-1199/1132.Reported Posts II/README_EN.md +++ b/solution/1100-1199/1132.Reported Posts II/README_EN.md @@ -107,6 +107,8 @@ Note that the output is only one number and that we do not care about the remove +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1100-1199/1133.Largest Unique Number/README.md b/solution/1100-1199/1133.Largest Unique Number/README.md index 0350433129b6e..e9d47cec66832 100644 --- a/solution/1100-1199/1133.Largest Unique Number/README.md +++ b/solution/1100-1199/1133.Largest Unique Number/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def largestUniqueNumber(self, nums: List[int]) -> int: @@ -72,6 +74,8 @@ class Solution: return max((x for x, v in cnt.items() if v == 1), default=-1) ``` +#### Java + ```java class Solution { public int largestUniqueNumber(int[] nums) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func largestUniqueNumber(nums []int) int { cnt := [1001]int{} @@ -122,6 +130,8 @@ func largestUniqueNumber(nums []int) int { } ``` +#### TypeScript + ```ts function largestUniqueNumber(nums: number[]): number { const cnt = Array(1001).fill(0); @@ -137,6 +147,8 @@ function largestUniqueNumber(nums: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/1100-1199/1133.Largest Unique Number/README_EN.md b/solution/1100-1199/1133.Largest Unique Number/README_EN.md index c1a5484604339..3ee6d759935af 100644 --- a/solution/1100-1199/1133.Largest Unique Number/README_EN.md +++ b/solution/1100-1199/1133.Largest Unique Number/README_EN.md @@ -60,6 +60,8 @@ The time complexity is $O(n + M)$, and the space complexity is $O(M)$. Here, $n$ +#### Python3 + ```python class Solution: def largestUniqueNumber(self, nums: List[int]) -> int: @@ -67,6 +69,8 @@ class Solution: return max((x for x, v in cnt.items() if v == 1), default=-1) ``` +#### Java + ```java class Solution { public int largestUniqueNumber(int[] nums) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -102,6 +108,8 @@ public: }; ``` +#### Go + ```go func largestUniqueNumber(nums []int) int { cnt := [1001]int{} @@ -117,6 +125,8 @@ func largestUniqueNumber(nums []int) int { } ``` +#### TypeScript + ```ts function largestUniqueNumber(nums: number[]): number { const cnt = Array(1001).fill(0); @@ -132,6 +142,8 @@ function largestUniqueNumber(nums: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/1100-1199/1134.Armstrong Number/README.md b/solution/1100-1199/1134.Armstrong Number/README.md index 2839e8d29048d..982a5420125e7 100644 --- a/solution/1100-1199/1134.Armstrong Number/README.md +++ b/solution/1100-1199/1134.Armstrong Number/README.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def isArmstrong(self, n: int) -> bool: @@ -74,6 +76,8 @@ class Solution: return s == n ``` +#### Java + ```java class Solution { public boolean isArmstrong(int n) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,6 +107,8 @@ public: }; ``` +#### Go + ```go func isArmstrong(n int) bool { k := 0 @@ -115,6 +123,8 @@ func isArmstrong(n int) bool { } ``` +#### TypeScript + ```ts function isArmstrong(n: number): boolean { const k = String(n).length; @@ -126,6 +136,8 @@ function isArmstrong(n: number): boolean { } ``` +#### JavaScript + ```js /** * @param {number} n diff --git a/solution/1100-1199/1134.Armstrong Number/README_EN.md b/solution/1100-1199/1134.Armstrong Number/README_EN.md index 33910e60cdfb8..f3ae54f5cb6a0 100644 --- a/solution/1100-1199/1134.Armstrong Number/README_EN.md +++ b/solution/1100-1199/1134.Armstrong Number/README_EN.md @@ -60,6 +60,8 @@ The time complexity is $O(\log n)$, and the space complexity is $O(\log n)$. Her +#### Python3 + ```python class Solution: def isArmstrong(self, n: int) -> bool: @@ -71,6 +73,8 @@ class Solution: return s == n ``` +#### Java + ```java class Solution { public boolean isArmstrong(int n) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -98,6 +104,8 @@ public: }; ``` +#### Go + ```go func isArmstrong(n int) bool { k := 0 @@ -112,6 +120,8 @@ func isArmstrong(n int) bool { } ``` +#### TypeScript + ```ts function isArmstrong(n: number): boolean { const k = String(n).length; @@ -123,6 +133,8 @@ function isArmstrong(n: number): boolean { } ``` +#### JavaScript + ```js /** * @param {number} n diff --git a/solution/1100-1199/1135.Connecting Cities With Minimum Cost/README.md b/solution/1100-1199/1135.Connecting Cities With Minimum Cost/README.md index 6e713154cd8ba..51a6f57afbfc6 100644 --- a/solution/1100-1199/1135.Connecting Cities With Minimum Cost/README.md +++ b/solution/1100-1199/1135.Connecting Cities With Minimum Cost/README.md @@ -82,6 +82,8 @@ Kruskal 算法的基本思想是,每次从边集中选择一条最小的边, +#### Python3 + ```python class Solution: def minimumCost(self, n: int, connections: List[List[int]]) -> int: @@ -105,6 +107,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { private int[] p; @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go func minimumCost(n int, connections [][]int) (ans int) { p := make([]int, n) @@ -199,6 +207,8 @@ func minimumCost(n int, connections [][]int) (ans int) { } ``` +#### TypeScript + ```ts function minimumCost(n: number, connections: number[][]): number { const p: number[] = Array.from({ length: n }, (_, i) => i); diff --git a/solution/1100-1199/1135.Connecting Cities With Minimum Cost/README_EN.md b/solution/1100-1199/1135.Connecting Cities With Minimum Cost/README_EN.md index 8bfaf034afa42..611af0dc14eb3 100644 --- a/solution/1100-1199/1135.Connecting Cities With Minimum Cost/README_EN.md +++ b/solution/1100-1199/1135.Connecting Cities With Minimum Cost/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(m \times \log m)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def minimumCost(self, n: int, connections: List[List[int]]) -> int: @@ -97,6 +99,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { private int[] p; @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func minimumCost(n int, connections [][]int) (ans int) { p := make([]int, n) @@ -191,6 +199,8 @@ func minimumCost(n int, connections [][]int) (ans int) { } ``` +#### TypeScript + ```ts function minimumCost(n: number, connections: number[][]): number { const p: number[] = Array.from({ length: n }, (_, i) => i); diff --git a/solution/1100-1199/1136.Parallel Courses/README.md b/solution/1100-1199/1136.Parallel Courses/README.md index 6f555b674becb..0d778a1958d53 100644 --- a/solution/1100-1199/1136.Parallel Courses/README.md +++ b/solution/1100-1199/1136.Parallel Courses/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def minimumSemesters(self, n: int, relations: List[List[int]]) -> int: @@ -103,6 +105,8 @@ class Solution: return -1 if n else ans ``` +#### Java + ```java class Solution { public int minimumSemesters(int n, int[][] relations) { @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func minimumSemesters(n int, relations [][]int) (ans int) { g := make([][]int, n) @@ -210,6 +218,8 @@ func minimumSemesters(n int, relations [][]int) (ans int) { } ``` +#### TypeScript + ```ts function minimumSemesters(n: number, relations: number[][]): number { const g: number[][] = Array.from({ length: n }, () => []); diff --git a/solution/1100-1199/1136.Parallel Courses/README_EN.md b/solution/1100-1199/1136.Parallel Courses/README_EN.md index 405269558eee2..ee534887e42f5 100644 --- a/solution/1100-1199/1136.Parallel Courses/README_EN.md +++ b/solution/1100-1199/1136.Parallel Courses/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(n + m)$, and the space complexity is $O(n + m)$. Here, +#### Python3 + ```python class Solution: def minimumSemesters(self, n: int, relations: List[List[int]]) -> int: @@ -95,6 +97,8 @@ class Solution: return -1 if n else ans ``` +#### Java + ```java class Solution { public int minimumSemesters(int n, int[][] relations) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go func minimumSemesters(n int, relations [][]int) (ans int) { g := make([][]int, n) @@ -202,6 +210,8 @@ func minimumSemesters(n int, relations [][]int) (ans int) { } ``` +#### TypeScript + ```ts function minimumSemesters(n: number, relations: number[][]): number { const g: number[][] = Array.from({ length: n }, () => []); diff --git a/solution/1100-1199/1137.N-th Tribonacci Number/README.md b/solution/1100-1199/1137.N-th Tribonacci Number/README.md index d95bf2dd3dfa8..d5239f0d61c35 100644 --- a/solution/1100-1199/1137.N-th Tribonacci Number/README.md +++ b/solution/1100-1199/1137.N-th Tribonacci Number/README.md @@ -70,6 +70,8 @@ T_4 = 1 + 1 + 2 = 4 +#### Python3 + ```python class Solution: def tribonacci(self, n: int) -> int: @@ -79,6 +81,8 @@ class Solution: return a ``` +#### Java + ```java class Solution { public int tribonacci(int n) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func tribonacci(n int) int { a, b, c := 0, 1, 1 @@ -120,6 +128,8 @@ func tribonacci(n int) int { } ``` +#### TypeScript + ```ts function tribonacci(n: number): number { if (n === 0) { @@ -162,6 +172,8 @@ function pow(a: number[][], n: number): number[][] { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -181,6 +193,8 @@ var tribonacci = function (n) { }; ``` +#### PHP + ```php class Solution { /** @@ -236,6 +250,8 @@ $$ +#### Python3 + ```python class Solution: def tribonacci(self, n: int) -> int: @@ -265,6 +281,8 @@ class Solution: return sum(pow(a, n - 3)[0]) ``` +#### Java + ```java class Solution { public int tribonacci(int n) { @@ -310,6 +328,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -354,6 +374,8 @@ private: }; ``` +#### Go + ```go func tribonacci(n int) (ans int) { if n == 0 { @@ -399,6 +421,8 @@ func pow(a [][]int, n int) [][]int { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -455,6 +479,8 @@ function pow(a, n) { +#### Python3 + ```python import numpy as np diff --git a/solution/1100-1199/1137.N-th Tribonacci Number/README_EN.md b/solution/1100-1199/1137.N-th Tribonacci Number/README_EN.md index d6b8fc3682ef8..292e565c0e86d 100644 --- a/solution/1100-1199/1137.N-th Tribonacci Number/README_EN.md +++ b/solution/1100-1199/1137.N-th Tribonacci Number/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is +#### Python3 + ```python class Solution: def tribonacci(self, n: int) -> int: @@ -93,6 +95,8 @@ class Solution: return a ``` +#### Java + ```java class Solution { public int tribonacci(int n) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func tribonacci(n int) int { a, b, c := 0, 1, 1 @@ -134,6 +142,8 @@ func tribonacci(n int) int { } ``` +#### TypeScript + ```ts function tribonacci(n: number): number { if (n === 0) { @@ -176,6 +186,8 @@ function pow(a: number[][], n: number): number[][] { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -195,6 +207,8 @@ var tribonacci = function (n) { }; ``` +#### PHP + ```php class Solution { /** @@ -250,6 +264,8 @@ The time complexity is $O(\log n)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def tribonacci(self, n: int) -> int: @@ -279,6 +295,8 @@ class Solution: return sum(pow(a, n - 3)[0]) ``` +#### Java + ```java class Solution { public int tribonacci(int n) { @@ -324,6 +342,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -368,6 +388,8 @@ private: }; ``` +#### Go + ```go func tribonacci(n int) (ans int) { if n == 0 { @@ -413,6 +435,8 @@ func pow(a [][]int, n int) [][]int { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -469,6 +493,8 @@ function pow(a, n) { +#### Python3 + ```python import numpy as np diff --git a/solution/1100-1199/1138.Alphabet Board Path/README.md b/solution/1100-1199/1138.Alphabet Board Path/README.md index f87d9f5b6c701..4c7e2085fa3c8 100644 --- a/solution/1100-1199/1138.Alphabet Board Path/README.md +++ b/solution/1100-1199/1138.Alphabet Board Path/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def alphabetBoardPath(self, target: str) -> str: @@ -102,6 +104,8 @@ class Solution: return "".join(ans) ``` +#### Java + ```java class Solution { public String alphabetBoardPath(String target) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func alphabetBoardPath(target string) string { ans := []byte{} diff --git a/solution/1100-1199/1138.Alphabet Board Path/README_EN.md b/solution/1100-1199/1138.Alphabet Board Path/README_EN.md index 4ee2f8a3ed2c1..27f26e711961c 100644 --- a/solution/1100-1199/1138.Alphabet Board Path/README_EN.md +++ b/solution/1100-1199/1138.Alphabet Board Path/README_EN.md @@ -87,6 +87,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string target, as +#### Python3 + ```python class Solution: def alphabetBoardPath(self, target: str) -> str: @@ -111,6 +113,8 @@ class Solution: return "".join(ans) ``` +#### Java + ```java class Solution { public String alphabetBoardPath(String target) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func alphabetBoardPath(target string) string { ans := []byte{} diff --git a/solution/1100-1199/1139.Largest 1-Bordered Square/README.md b/solution/1100-1199/1139.Largest 1-Bordered Square/README.md index fdd1488601f56..0f20703564bca 100644 --- a/solution/1100-1199/1139.Largest 1-Bordered Square/README.md +++ b/solution/1100-1199/1139.Largest 1-Bordered Square/README.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def largest1BorderedSquare(self, grid: List[List[int]]) -> int: @@ -86,6 +88,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { public int largest1BorderedSquare(int[][] grid) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func largest1BorderedSquare(grid [][]int) int { m, n := len(grid), len(grid[0]) diff --git a/solution/1100-1199/1139.Largest 1-Bordered Square/README_EN.md b/solution/1100-1199/1139.Largest 1-Bordered Square/README_EN.md index 7042b0ddbb73c..f88d6f213fbf6 100644 --- a/solution/1100-1199/1139.Largest 1-Bordered Square/README_EN.md +++ b/solution/1100-1199/1139.Largest 1-Bordered Square/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(m \times n \times \min(m, n))$, and the space complexi +#### Python3 + ```python class Solution: def largest1BorderedSquare(self, grid: List[List[int]]) -> int: @@ -98,6 +100,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { public int largest1BorderedSquare(int[][] grid) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func largest1BorderedSquare(grid [][]int) int { m, n := len(grid), len(grid[0]) diff --git a/solution/1100-1199/1140.Stone Game II/README.md b/solution/1100-1199/1140.Stone Game II/README.md index 8c7fd93cf700d..84d60a634f76b 100644 --- a/solution/1100-1199/1140.Stone Game II/README.md +++ b/solution/1100-1199/1140.Stone Game II/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def stoneGameII(self, piles: List[int]) -> int: @@ -99,6 +101,8 @@ class Solution: return dfs(0, 1) ``` +#### Java + ```java class Solution { private int[] s; @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func stoneGameII(piles []int) int { n := len(piles) @@ -188,6 +196,8 @@ func stoneGameII(piles []int) int { } ``` +#### TypeScript + ```ts function stoneGameII(piles: number[]): number { const n = piles.length; @@ -223,6 +233,8 @@ function stoneGameII(piles: number[]): number { +#### Python3 + ```python class Solution: def stoneGameII(self, piles: List[int]) -> int: diff --git a/solution/1100-1199/1140.Stone Game II/README_EN.md b/solution/1100-1199/1140.Stone Game II/README_EN.md index 91c61b203c98f..4a3a5d416d9db 100644 --- a/solution/1100-1199/1140.Stone Game II/README_EN.md +++ b/solution/1100-1199/1140.Stone Game II/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(n^3)$, and the space complexity is $O(n^2)$. Here, $n$ +#### Python3 + ```python class Solution: def stoneGameII(self, piles: List[int]) -> int: @@ -97,6 +99,8 @@ class Solution: return dfs(0, 1) ``` +#### Java + ```java class Solution { private int[] s; @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func stoneGameII(piles []int) int { n := len(piles) @@ -186,6 +194,8 @@ func stoneGameII(piles []int) int { } ``` +#### TypeScript + ```ts function stoneGameII(piles: number[]): number { const n = piles.length; @@ -221,6 +231,8 @@ function stoneGameII(piles: number[]): number { +#### Python3 + ```python class Solution: def stoneGameII(self, piles: List[int]) -> int: diff --git a/solution/1100-1199/1141.User Activity for the Past 30 Days I/README.md b/solution/1100-1199/1141.User Activity for the Past 30 Days I/README.md index 603dd431222a4..9da234dfd067b 100644 --- a/solution/1100-1199/1141.User Activity for the Past 30 Days I/README.md +++ b/solution/1100-1199/1141.User Activity for the Past 30 Days I/README.md @@ -84,6 +84,8 @@ Activity table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT activity_date AS day, COUNT(DISTINCT user_id) AS active_users diff --git a/solution/1100-1199/1141.User Activity for the Past 30 Days I/README_EN.md b/solution/1100-1199/1141.User Activity for the Past 30 Days I/README_EN.md index 037c9af1e16e0..c3e9a87bedb93 100644 --- a/solution/1100-1199/1141.User Activity for the Past 30 Days I/README_EN.md +++ b/solution/1100-1199/1141.User Activity for the Past 30 Days I/README_EN.md @@ -82,6 +82,8 @@ Activity table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT activity_date AS day, COUNT(DISTINCT user_id) AS active_users diff --git a/solution/1100-1199/1142.User Activity for the Past 30 Days II/README.md b/solution/1100-1199/1142.User Activity for the Past 30 Days II/README.md index 344677e12d452..ce5c7d674dfdf 100644 --- a/solution/1100-1199/1142.User Activity for the Past 30 Days II/README.md +++ b/solution/1100-1199/1142.User Activity for the Past 30 Days II/README.md @@ -82,6 +82,8 @@ Activity 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -106,6 +108,8 @@ FROM T; +#### MySQL + ```sql SELECT IFNULL( diff --git a/solution/1100-1199/1142.User Activity for the Past 30 Days II/README_EN.md b/solution/1100-1199/1142.User Activity for the Past 30 Days II/README_EN.md index 43df43b674848..db65819c8caab 100644 --- a/solution/1100-1199/1142.User Activity for the Past 30 Days II/README_EN.md +++ b/solution/1100-1199/1142.User Activity for the Past 30 Days II/README_EN.md @@ -82,6 +82,8 @@ Activity table: +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -106,6 +108,8 @@ FROM T; +#### MySQL + ```sql SELECT IFNULL( diff --git a/solution/1100-1199/1143.Longest Common Subsequence/README.md b/solution/1100-1199/1143.Longest Common Subsequence/README.md index 875ac1b31b2ce..344831b704935 100644 --- a/solution/1100-1199/1143.Longest Common Subsequence/README.md +++ b/solution/1100-1199/1143.Longest Common Subsequence/README.md @@ -86,6 +86,8 @@ $$ +#### Python3 + ```python class Solution: def longestCommonSubsequence(self, text1: str, text2: str) -> int: @@ -100,6 +102,8 @@ class Solution: return f[m][n] ``` +#### Java + ```java class Solution { public int longestCommonSubsequence(String text1, String text2) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func longestCommonSubsequence(text1 string, text2 string) int { m, n := len(text1), len(text2) @@ -160,6 +168,8 @@ func longestCommonSubsequence(text1 string, text2 string) int { } ``` +#### TypeScript + ```ts function longestCommonSubsequence(text1: string, text2: string): number { const m = text1.length; @@ -178,6 +188,8 @@ function longestCommonSubsequence(text1: string, text2: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn longest_common_subsequence(text1: String, text2: String) -> i32 { @@ -198,6 +210,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} text1 @@ -221,6 +235,8 @@ var longestCommonSubsequence = function (text1, text2) { }; ``` +#### C# + ```cs public class Solution { public int LongestCommonSubsequence(string text1, string text2) { @@ -240,6 +256,8 @@ public class Solution { } ``` +#### Kotlin + ```kotlin class Solution { fun longestCommonSubsequence(text1: String, text2: String): Int { diff --git a/solution/1100-1199/1143.Longest Common Subsequence/README_EN.md b/solution/1100-1199/1143.Longest Common Subsequence/README_EN.md index 6a669f7912c3a..d546d78b61320 100644 --- a/solution/1100-1199/1143.Longest Common Subsequence/README_EN.md +++ b/solution/1100-1199/1143.Longest Common Subsequence/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def longestCommonSubsequence(self, text1: str, text2: str) -> int: @@ -98,6 +100,8 @@ class Solution: return f[m][n] ``` +#### Java + ```java class Solution { public int longestCommonSubsequence(String text1, String text2) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func longestCommonSubsequence(text1 string, text2 string) int { m, n := len(text1), len(text2) @@ -158,6 +166,8 @@ func longestCommonSubsequence(text1 string, text2 string) int { } ``` +#### TypeScript + ```ts function longestCommonSubsequence(text1: string, text2: string): number { const m = text1.length; @@ -176,6 +186,8 @@ function longestCommonSubsequence(text1: string, text2: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn longest_common_subsequence(text1: String, text2: String) -> i32 { @@ -196,6 +208,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} text1 @@ -219,6 +233,8 @@ var longestCommonSubsequence = function (text1, text2) { }; ``` +#### C# + ```cs public class Solution { public int LongestCommonSubsequence(string text1, string text2) { @@ -238,6 +254,8 @@ public class Solution { } ``` +#### Kotlin + ```kotlin class Solution { fun longestCommonSubsequence(text1: String, text2: String): Int { diff --git a/solution/1100-1199/1144.Decrease Elements To Make Array Zigzag/README.md b/solution/1100-1199/1144.Decrease Elements To Make Array Zigzag/README.md index 809e2a1791bcf..d1ad64c15c633 100644 --- a/solution/1100-1199/1144.Decrease Elements To Make Array Zigzag/README.md +++ b/solution/1100-1199/1144.Decrease Elements To Make Array Zigzag/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def movesToMakeZigzag(self, nums: List[int]) -> int: @@ -84,6 +86,8 @@ class Solution: return min(ans) ``` +#### Java + ```java class Solution { public int movesToMakeZigzag(int[] nums) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func movesToMakeZigzag(nums []int) int { ans := [2]int{} @@ -145,6 +153,8 @@ func movesToMakeZigzag(nums []int) int { } ``` +#### TypeScript + ```ts function movesToMakeZigzag(nums: number[]): number { const ans: number[] = Array(2).fill(0); @@ -165,6 +175,8 @@ function movesToMakeZigzag(nums: number[]): number { } ``` +#### C# + ```cs public class Solution { public int MovesToMakeZigzag(int[] nums) { diff --git a/solution/1100-1199/1144.Decrease Elements To Make Array Zigzag/README_EN.md b/solution/1100-1199/1144.Decrease Elements To Make Array Zigzag/README_EN.md index 2f02fcffcdeb7..733d79252525e 100644 --- a/solution/1100-1199/1144.Decrease Elements To Make Array Zigzag/README_EN.md +++ b/solution/1100-1199/1144.Decrease Elements To Make Array Zigzag/README_EN.md @@ -68,6 +68,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def movesToMakeZigzag(self, nums: List[int]) -> int: @@ -84,6 +86,8 @@ class Solution: return min(ans) ``` +#### Java + ```java class Solution { public int movesToMakeZigzag(int[] nums) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func movesToMakeZigzag(nums []int) int { ans := [2]int{} @@ -145,6 +153,8 @@ func movesToMakeZigzag(nums []int) int { } ``` +#### TypeScript + ```ts function movesToMakeZigzag(nums: number[]): number { const ans: number[] = Array(2).fill(0); @@ -165,6 +175,8 @@ function movesToMakeZigzag(nums: number[]): number { } ``` +#### C# + ```cs public class Solution { public int MovesToMakeZigzag(int[] nums) { diff --git a/solution/1100-1199/1145.Binary Tree Coloring Game/README.md b/solution/1100-1199/1145.Binary Tree Coloring Game/README.md index 3693c5f3f9670..86e33e4010574 100644 --- a/solution/1100-1199/1145.Binary Tree Coloring Game/README.md +++ b/solution/1100-1199/1145.Binary Tree Coloring Game/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -106,6 +108,8 @@ class Solution: return max(l, r, n - l - r - 1) > n // 2 ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -147,6 +151,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -184,6 +190,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -220,6 +228,8 @@ func btreeGameWinningMove(root *TreeNode, n int, x int) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -257,6 +267,8 @@ function btreeGameWinningMove(root: TreeNode | null, n: number, x: number): bool } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/1100-1199/1145.Binary Tree Coloring Game/README_EN.md b/solution/1100-1199/1145.Binary Tree Coloring Game/README_EN.md index 07a52df890617..b3dd3d36e8ba8 100644 --- a/solution/1100-1199/1145.Binary Tree Coloring Game/README_EN.md +++ b/solution/1100-1199/1145.Binary Tree Coloring Game/README_EN.md @@ -73,6 +73,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -97,6 +99,8 @@ class Solution: return max(l, r, n - l - r - 1) > n // 2 ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -211,6 +219,8 @@ func btreeGameWinningMove(root *TreeNode, n int, x int) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -248,6 +258,8 @@ function btreeGameWinningMove(root: TreeNode | null, n: number, x: number): bool } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/1100-1199/1146.Snapshot Array/README.md b/solution/1100-1199/1146.Snapshot Array/README.md index d9fbfc27d300b..5c7ab4602280d 100644 --- a/solution/1100-1199/1146.Snapshot Array/README.md +++ b/solution/1100-1199/1146.Snapshot Array/README.md @@ -76,6 +76,8 @@ snapshotArr.get(0,0); // 获取 snap_id = 0 的快照中 array[0] 的值,返 +#### Python3 + ```python class SnapshotArray: @@ -102,6 +104,8 @@ class SnapshotArray: # param_3 = obj.get(index,snap_id) ``` +#### Java + ```java class SnapshotArray { private List[] arr; @@ -144,6 +148,8 @@ class SnapshotArray { */ ``` +#### C++ + ```cpp class SnapshotArray { public: @@ -178,6 +184,8 @@ private: */ ``` +#### Go + ```go type SnapshotArray struct { arr [][][2]int @@ -214,6 +222,8 @@ func (this *SnapshotArray) Get(index int, snap_id int) int { */ ``` +#### TypeScript + ```ts class SnapshotArray { private arr: [number, number][][]; diff --git a/solution/1100-1199/1146.Snapshot Array/README_EN.md b/solution/1100-1199/1146.Snapshot Array/README_EN.md index a70bb489a8110..4654291c8da26 100644 --- a/solution/1100-1199/1146.Snapshot Array/README_EN.md +++ b/solution/1100-1199/1146.Snapshot Array/README_EN.md @@ -75,6 +75,8 @@ The space complexity is $O(n)$. +#### Python3 + ```python class SnapshotArray: @@ -101,6 +103,8 @@ class SnapshotArray: # param_3 = obj.get(index,snap_id) ``` +#### Java + ```java class SnapshotArray { private List[] arr; @@ -143,6 +147,8 @@ class SnapshotArray { */ ``` +#### C++ + ```cpp class SnapshotArray { public: @@ -177,6 +183,8 @@ private: */ ``` +#### Go + ```go type SnapshotArray struct { arr [][][2]int @@ -213,6 +221,8 @@ func (this *SnapshotArray) Get(index int, snap_id int) int { */ ``` +#### TypeScript + ```ts class SnapshotArray { private arr: [number, number][][]; diff --git a/solution/1100-1199/1147.Longest Chunked Palindrome Decomposition/README.md b/solution/1100-1199/1147.Longest Chunked Palindrome Decomposition/README.md index cfecd3fdfbd98..cd4029c156002 100644 --- a/solution/1100-1199/1147.Longest Chunked Palindrome Decomposition/README.md +++ b/solution/1100-1199/1147.Longest Chunked Palindrome Decomposition/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def longestDecomposition(self, text: str) -> int: @@ -103,6 +105,8 @@ class Solution: return 1 ``` +#### Java + ```java class Solution { public int longestDecomposition(String text) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func longestDecomposition(text string) int { n := len(text) @@ -151,6 +159,8 @@ func longestDecomposition(text string) int { } ``` +#### TypeScript + ```ts function longestDecomposition(text: string): number { const n: number = text.length; @@ -182,6 +192,8 @@ function longestDecomposition(text: string): number { +#### Python3 + ```python class Solution: def longestDecomposition(self, text: str) -> int: @@ -204,6 +216,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestDecomposition(String text) { @@ -238,6 +252,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -272,6 +288,8 @@ public: }; ``` +#### Go + ```go func longestDecomposition(text string) (ans int) { for i, j := 0, len(text)-1; i <= j; { @@ -294,6 +312,8 @@ func longestDecomposition(text string) (ans int) { } ``` +#### TypeScript + ```ts function longestDecomposition(text: string): number { let ans = 0; @@ -327,6 +347,8 @@ function longestDecomposition(text: string): number { +#### Python3 + ```python class Solution: def longestDecomposition(self, text: str) -> int: @@ -362,6 +384,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private long[] h; @@ -404,6 +428,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -446,6 +472,8 @@ public: }; ``` +#### Go + ```go func longestDecomposition(text string) (ans int) { n := len(text) diff --git a/solution/1100-1199/1147.Longest Chunked Palindrome Decomposition/README_EN.md b/solution/1100-1199/1147.Longest Chunked Palindrome Decomposition/README_EN.md index e17f4d97580ce..a9a2ce5a23354 100644 --- a/solution/1100-1199/1147.Longest Chunked Palindrome Decomposition/README_EN.md +++ b/solution/1100-1199/1147.Longest Chunked Palindrome Decomposition/README_EN.md @@ -89,6 +89,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$ or $O(1)$. H +#### Python3 + ```python class Solution: def longestDecomposition(self, text: str) -> int: @@ -101,6 +103,8 @@ class Solution: return 1 ``` +#### Java + ```java class Solution { public int longestDecomposition(String text) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func longestDecomposition(text string) int { n := len(text) @@ -149,6 +157,8 @@ func longestDecomposition(text string) int { } ``` +#### TypeScript + ```ts function longestDecomposition(text: string): number { const n: number = text.length; @@ -180,6 +190,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def longestDecomposition(self, text: str) -> int: @@ -202,6 +214,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestDecomposition(String text) { @@ -236,6 +250,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -270,6 +286,8 @@ public: }; ``` +#### Go + ```go func longestDecomposition(text string) (ans int) { for i, j := 0, len(text)-1; i <= j; { @@ -292,6 +310,8 @@ func longestDecomposition(text string) (ans int) { } ``` +#### TypeScript + ```ts function longestDecomposition(text: string): number { let ans = 0; @@ -325,6 +345,8 @@ function longestDecomposition(text: string): number { +#### Python3 + ```python class Solution: def longestDecomposition(self, text: str) -> int: @@ -360,6 +382,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private long[] h; @@ -402,6 +426,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -444,6 +470,8 @@ public: }; ``` +#### Go + ```go func longestDecomposition(text string) (ans int) { n := len(text) diff --git a/solution/1100-1199/1148.Article Views I/README.md b/solution/1100-1199/1148.Article Views I/README.md index f7004c3482180..aa1dab3504f2d 100644 --- a/solution/1100-1199/1148.Article Views I/README.md +++ b/solution/1100-1199/1148.Article Views I/README.md @@ -80,6 +80,8 @@ Views 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT DISTINCT author_id AS id diff --git a/solution/1100-1199/1148.Article Views I/README_EN.md b/solution/1100-1199/1148.Article Views I/README_EN.md index c8a788ee68e0e..b541e411dcf61 100644 --- a/solution/1100-1199/1148.Article Views I/README_EN.md +++ b/solution/1100-1199/1148.Article Views I/README_EN.md @@ -76,6 +76,8 @@ Views table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT DISTINCT author_id AS id diff --git a/solution/1100-1199/1149.Article Views II/README.md b/solution/1100-1199/1149.Article Views II/README.md index dc0ea55d005d8..f8cc054cf01fd 100644 --- a/solution/1100-1199/1149.Article Views II/README.md +++ b/solution/1100-1199/1149.Article Views II/README.md @@ -79,6 +79,8 @@ Views 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT DISTINCT viewer_id AS id diff --git a/solution/1100-1199/1149.Article Views II/README_EN.md b/solution/1100-1199/1149.Article Views II/README_EN.md index ef3690f0116c8..e1e99e2f03481 100644 --- a/solution/1100-1199/1149.Article Views II/README_EN.md +++ b/solution/1100-1199/1149.Article Views II/README_EN.md @@ -76,6 +76,8 @@ Views table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT DISTINCT viewer_id AS id diff --git a/solution/1100-1199/1150.Check If a Number Is Majority Element in a Sorted Array/README.md b/solution/1100-1199/1150.Check If a Number Is Majority Element in a Sorted Array/README.md index 2ec1253ebec81..37a30c648a2a6 100644 --- a/solution/1100-1199/1150.Check If a Number Is Majority Element in a Sorted Array/README.md +++ b/solution/1100-1199/1150.Check If a Number Is Majority Element in a Sorted Array/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def isMajorityElement(self, nums: List[int], target: int) -> bool: @@ -77,6 +79,8 @@ class Solution: return right - left > len(nums) // 2 ``` +#### Java + ```java class Solution { public boolean isMajorityElement(int[] nums, int target) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func isMajorityElement(nums []int, target int) bool { left := sort.SearchInts(nums, target) @@ -119,6 +127,8 @@ func isMajorityElement(nums []int, target int) bool { } ``` +#### TypeScript + ```ts function isMajorityElement(nums: number[], target: number): boolean { const search = (x: number) => { @@ -154,6 +164,8 @@ function isMajorityElement(nums: number[], target: number): boolean { +#### Python3 + ```python class Solution: def isMajorityElement(self, nums: List[int], target: int) -> bool: @@ -162,6 +174,8 @@ class Solution: return right < len(nums) and nums[right] == target ``` +#### Java + ```java class Solution { public boolean isMajorityElement(int[] nums, int target) { @@ -186,6 +200,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -198,6 +214,8 @@ public: }; ``` +#### Go + ```go func isMajorityElement(nums []int, target int) bool { n := len(nums) @@ -207,6 +225,8 @@ func isMajorityElement(nums []int, target int) bool { } ``` +#### TypeScript + ```ts function isMajorityElement(nums: number[], target: number): boolean { const search = (x: number) => { diff --git a/solution/1100-1199/1150.Check If a Number Is Majority Element in a Sorted Array/README_EN.md b/solution/1100-1199/1150.Check If a Number Is Majority Element in a Sorted Array/README_EN.md index cf45e3c7964fb..7ec97966b7b71 100644 --- a/solution/1100-1199/1150.Check If a Number Is Majority Element in a Sorted Array/README_EN.md +++ b/solution/1100-1199/1150.Check If a Number Is Majority Element in a Sorted Array/README_EN.md @@ -65,6 +65,8 @@ The time complexity is $O(\log n)$, and the space complexity is $O(1)$. Here, $n +#### Python3 + ```python class Solution: def isMajorityElement(self, nums: List[int], target: int) -> bool: @@ -73,6 +75,8 @@ class Solution: return right - left > len(nums) // 2 ``` +#### Java + ```java class Solution { public boolean isMajorityElement(int[] nums, int target) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func isMajorityElement(nums []int, target int) bool { left := sort.SearchInts(nums, target) @@ -115,6 +123,8 @@ func isMajorityElement(nums []int, target int) bool { } ``` +#### TypeScript + ```ts function isMajorityElement(nums: number[], target: number): boolean { const search = (x: number) => { @@ -150,6 +160,8 @@ The time complexity is $O(\log n)$, and the space complexity is $O(1)$. Here, $n +#### Python3 + ```python class Solution: def isMajorityElement(self, nums: List[int], target: int) -> bool: @@ -158,6 +170,8 @@ class Solution: return right < len(nums) and nums[right] == target ``` +#### Java + ```java class Solution { public boolean isMajorityElement(int[] nums, int target) { @@ -182,6 +196,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -194,6 +210,8 @@ public: }; ``` +#### Go + ```go func isMajorityElement(nums []int, target int) bool { n := len(nums) @@ -203,6 +221,8 @@ func isMajorityElement(nums []int, target int) bool { } ``` +#### TypeScript + ```ts function isMajorityElement(nums: number[], target: number): boolean { const search = (x: number) => { diff --git a/solution/1100-1199/1151.Minimum Swaps to Group All 1's Together/README.md b/solution/1100-1199/1151.Minimum Swaps to Group All 1's Together/README.md index 15a0c088aca20..e1dbaf8b3d25f 100644 --- a/solution/1100-1199/1151.Minimum Swaps to Group All 1's Together/README.md +++ b/solution/1100-1199/1151.Minimum Swaps to Group All 1's Together/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def minSwaps(self, data: List[int]) -> int: @@ -95,6 +97,8 @@ class Solution: return k - mx ``` +#### Java + ```java class Solution { public int minSwaps(int[] data) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func minSwaps(data []int) int { k := 0 @@ -160,6 +168,8 @@ func minSwaps(data []int) int { } ``` +#### TypeScript + ```ts function minSwaps(data: number[]): number { const k = data.reduce((acc, cur) => acc + cur, 0); @@ -173,6 +183,8 @@ function minSwaps(data: number[]): number { } ``` +#### C# + ```cs public class Solution { public int MinSwaps(int[] data) { diff --git a/solution/1100-1199/1151.Minimum Swaps to Group All 1's Together/README_EN.md b/solution/1100-1199/1151.Minimum Swaps to Group All 1's Together/README_EN.md index 3e9a864078353..75d489dc525cc 100644 --- a/solution/1100-1199/1151.Minimum Swaps to Group All 1's Together/README_EN.md +++ b/solution/1100-1199/1151.Minimum Swaps to Group All 1's Together/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is +#### Python3 + ```python class Solution: def minSwaps(self, data: List[int]) -> int: @@ -84,6 +86,8 @@ class Solution: return k - mx ``` +#### Java + ```java class Solution { public int minSwaps(int[] data) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func minSwaps(data []int) int { k := 0 @@ -149,6 +157,8 @@ func minSwaps(data []int) int { } ``` +#### TypeScript + ```ts function minSwaps(data: number[]): number { const k = data.reduce((acc, cur) => acc + cur, 0); @@ -162,6 +172,8 @@ function minSwaps(data: number[]): number { } ``` +#### C# + ```cs public class Solution { public int MinSwaps(int[] data) { diff --git a/solution/1100-1199/1152.Analyze User Website Visit Pattern/README.md b/solution/1100-1199/1152.Analyze User Website Visit Pattern/README.md index c59b4773129c7..fb70dbd269d87 100644 --- a/solution/1100-1199/1152.Analyze User Website Visit Pattern/README.md +++ b/solution/1100-1199/1152.Analyze User Website Visit Pattern/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def mostVisitedPattern( @@ -116,6 +118,8 @@ class Solution: return sorted(cnt.items(), key=lambda x: (-x[1], x[0]))[0][0] ``` +#### Java + ```java class Solution { public List mostVisitedPattern(String[] username, int[] timestamp, String[] website) { @@ -171,6 +175,8 @@ class Node { } ``` +#### C++ + ```cpp class Solution { public: @@ -224,6 +230,8 @@ public: }; ``` +#### Go + ```go func mostVisitedPattern(username []string, timestamp []int, website []string) []string { d := map[string][]pair{} diff --git a/solution/1100-1199/1152.Analyze User Website Visit Pattern/README_EN.md b/solution/1100-1199/1152.Analyze User Website Visit Pattern/README_EN.md index 5c329b22dbefc..bc8f7c9ed7aab 100644 --- a/solution/1100-1199/1152.Analyze User Website Visit Pattern/README_EN.md +++ b/solution/1100-1199/1152.Analyze User Website Visit Pattern/README_EN.md @@ -90,6 +90,8 @@ The time complexity is $O(n^3)$, and the space complexity is $O(n^3)$. Here, $n$ +#### Python3 + ```python class Solution: def mostVisitedPattern( @@ -115,6 +117,8 @@ class Solution: return sorted(cnt.items(), key=lambda x: (-x[1], x[0]))[0][0] ``` +#### Java + ```java class Solution { public List mostVisitedPattern(String[] username, int[] timestamp, String[] website) { @@ -170,6 +174,8 @@ class Node { } ``` +#### C++ + ```cpp class Solution { public: @@ -223,6 +229,8 @@ public: }; ``` +#### Go + ```go func mostVisitedPattern(username []string, timestamp []int, website []string) []string { d := map[string][]pair{} diff --git a/solution/1100-1199/1153.String Transforms Into Another String/README.md b/solution/1100-1199/1153.String Transforms Into Another String/README.md index 9b55dd42c9eb2..f2dfb0706cad4 100644 --- a/solution/1100-1199/1153.String Transforms Into Another String/README.md +++ b/solution/1100-1199/1153.String Transforms Into Another String/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def canConvert(self, str1: str, str2: str) -> bool: @@ -88,6 +90,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean canConvert(String str1, String str2) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func canConvert(str1 string, str2 string) bool { if str1 == str2 { @@ -177,6 +185,8 @@ func canConvert(str1 string, str2 string) bool { } ``` +#### TypeScript + ```ts function canConvert(str1: string, str2: string): boolean { if (str1 === str2) { diff --git a/solution/1100-1199/1153.String Transforms Into Another String/README_EN.md b/solution/1100-1199/1153.String Transforms Into Another String/README_EN.md index 3cb9da2b6e15f..01c129fb6f316 100644 --- a/solution/1100-1199/1153.String Transforms Into Another String/README_EN.md +++ b/solution/1100-1199/1153.String Transforms Into Another String/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n)$, and the space complexity is $O(C)$. Here, $n$ is +#### Python3 + ```python class Solution: def canConvert(self, str1: str, str2: str) -> bool: @@ -86,6 +88,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean canConvert(String str1, String str2) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func canConvert(str1 string, str2 string) bool { if str1 == str2 { @@ -175,6 +183,8 @@ func canConvert(str1 string, str2 string) bool { } ``` +#### TypeScript + ```ts function canConvert(str1: string, str2: string): boolean { if (str1 === str2) { diff --git a/solution/1100-1199/1154.Day of the Year/README.md b/solution/1100-1199/1154.Day of the Year/README.md index 93226e91909fd..2270370ffa7e8 100644 --- a/solution/1100-1199/1154.Day of the Year/README.md +++ b/solution/1100-1199/1154.Day of the Year/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def dayOfYear(self, date: str) -> int: @@ -78,6 +80,8 @@ class Solution: return sum(days[: m - 1]) + d ``` +#### Java + ```java class Solution { public int dayOfYear(String date) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func dayOfYear(date string) (ans int) { var y, m, d int @@ -128,6 +136,8 @@ func dayOfYear(date string) (ans int) { } ``` +#### TypeScript + ```ts function dayOfYear(date: string): number { const y = +date.slice(0, 4); @@ -139,6 +149,8 @@ function dayOfYear(date: string): number { } ``` +#### JavaScript + ```js /** * @param {string} date diff --git a/solution/1100-1199/1154.Day of the Year/README_EN.md b/solution/1100-1199/1154.Day of the Year/README_EN.md index a4466c62071e9..644cd2bdfc84b 100644 --- a/solution/1100-1199/1154.Day of the Year/README_EN.md +++ b/solution/1100-1199/1154.Day of the Year/README_EN.md @@ -68,6 +68,8 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def dayOfYear(self, date: str) -> int: @@ -77,6 +79,8 @@ class Solution: return sum(days[: m - 1]) + d ``` +#### Java + ```java class Solution { public int dayOfYear(String date) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func dayOfYear(date string) (ans int) { var y, m, d int @@ -127,6 +135,8 @@ func dayOfYear(date string) (ans int) { } ``` +#### TypeScript + ```ts function dayOfYear(date: string): number { const y = +date.slice(0, 4); @@ -138,6 +148,8 @@ function dayOfYear(date: string): number { } ``` +#### JavaScript + ```js /** * @param {string} date diff --git a/solution/1100-1199/1155.Number of Dice Rolls With Target Sum/README.md b/solution/1100-1199/1155.Number of Dice Rolls With Target Sum/README.md index ea8088209d001..d6d9a5779b5aa 100644 --- a/solution/1100-1199/1155.Number of Dice Rolls With Target Sum/README.md +++ b/solution/1100-1199/1155.Number of Dice Rolls With Target Sum/README.md @@ -84,6 +84,8 @@ $$ +#### Python3 + ```python class Solution: def numRollsToTarget(self, n: int, k: int, target: int) -> int: @@ -97,6 +99,8 @@ class Solution: return f[n][target] ``` +#### Java + ```java class Solution { public int numRollsToTarget(int n, int k, int target) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func numRollsToTarget(n int, k int, target int) int { const mod int = 1e9 + 7 @@ -154,6 +162,8 @@ func numRollsToTarget(n int, k int, target int) int { } ``` +#### TypeScript + ```ts function numRollsToTarget(n: number, k: number, target: number): number { const f = Array.from({ length: n + 1 }, () => Array(target + 1).fill(0)); @@ -170,6 +180,8 @@ function numRollsToTarget(n: number, k: number, target: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn num_rolls_to_target(n: i32, k: i32, target: i32) -> i32 { @@ -203,6 +215,8 @@ impl Solution { +#### Python3 + ```python class Solution: def numRollsToTarget(self, n: int, k: int, target: int) -> int: @@ -217,6 +231,8 @@ class Solution: return f[target] ``` +#### Java + ```java class Solution { public int numRollsToTarget(int n, int k, int target) { @@ -237,6 +253,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -258,6 +276,8 @@ public: }; ``` +#### Go + ```go func numRollsToTarget(n int, k int, target int) int { const mod int = 1e9 + 7 @@ -276,6 +296,8 @@ func numRollsToTarget(n int, k int, target int) int { } ``` +#### TypeScript + ```ts function numRollsToTarget(n: number, k: number, target: number): number { const f = Array(target + 1).fill(0); @@ -294,6 +316,8 @@ function numRollsToTarget(n: number, k: number, target: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn num_rolls_to_target(n: i32, k: i32, target: i32) -> i32 { diff --git a/solution/1100-1199/1155.Number of Dice Rolls With Target Sum/README_EN.md b/solution/1100-1199/1155.Number of Dice Rolls With Target Sum/README_EN.md index 0dadb7880cd75..7d1864d254df0 100644 --- a/solution/1100-1199/1155.Number of Dice Rolls With Target Sum/README_EN.md +++ b/solution/1100-1199/1155.Number of Dice Rolls With Target Sum/README_EN.md @@ -81,6 +81,8 @@ We notice that the state $f[i][j]$ only depends on $f[i-1][]$, so we can use a r +#### Python3 + ```python class Solution: def numRollsToTarget(self, n: int, k: int, target: int) -> int: @@ -94,6 +96,8 @@ class Solution: return f[n][target] ``` +#### Java + ```java class Solution { public int numRollsToTarget(int n, int k, int target) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func numRollsToTarget(n int, k int, target int) int { const mod int = 1e9 + 7 @@ -151,6 +159,8 @@ func numRollsToTarget(n int, k int, target int) int { } ``` +#### TypeScript + ```ts function numRollsToTarget(n: number, k: number, target: number): number { const f = Array.from({ length: n + 1 }, () => Array(target + 1).fill(0)); @@ -167,6 +177,8 @@ function numRollsToTarget(n: number, k: number, target: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn num_rolls_to_target(n: i32, k: i32, target: i32) -> i32 { @@ -200,6 +212,8 @@ impl Solution { +#### Python3 + ```python class Solution: def numRollsToTarget(self, n: int, k: int, target: int) -> int: @@ -214,6 +228,8 @@ class Solution: return f[target] ``` +#### Java + ```java class Solution { public int numRollsToTarget(int n, int k, int target) { @@ -234,6 +250,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -255,6 +273,8 @@ public: }; ``` +#### Go + ```go func numRollsToTarget(n int, k int, target int) int { const mod int = 1e9 + 7 @@ -273,6 +293,8 @@ func numRollsToTarget(n int, k int, target int) int { } ``` +#### TypeScript + ```ts function numRollsToTarget(n: number, k: number, target: number): number { const f = Array(target + 1).fill(0); @@ -291,6 +313,8 @@ function numRollsToTarget(n: number, k: number, target: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn num_rolls_to_target(n: i32, k: i32, target: i32) -> i32 { diff --git a/solution/1100-1199/1156.Swap For Longest Repeated Character Substring/README.md b/solution/1100-1199/1156.Swap For Longest Repeated Character Substring/README.md index 430221f664ba4..fdee2ef646cc5 100644 --- a/solution/1100-1199/1156.Swap For Longest Repeated Character Substring/README.md +++ b/solution/1100-1199/1156.Swap For Longest Repeated Character Substring/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def maxRepOpt1(self, text: str) -> int: @@ -103,6 +105,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxRepOpt1(String text) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func maxRepOpt1(text string) (ans int) { cnt := [26]int{} @@ -184,6 +192,8 @@ func maxRepOpt1(text string) (ans int) { } ``` +#### TypeScript + ```ts function maxRepOpt1(text: string): number { const idx = (c: string) => c.charCodeAt(0) - 'a'.charCodeAt(0); diff --git a/solution/1100-1199/1156.Swap For Longest Repeated Character Substring/README_EN.md b/solution/1100-1199/1156.Swap For Longest Repeated Character Substring/README_EN.md index 513297c5ee669..b3fe67ef254f5 100644 --- a/solution/1100-1199/1156.Swap For Longest Repeated Character Substring/README_EN.md +++ b/solution/1100-1199/1156.Swap For Longest Repeated Character Substring/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(n)$, and the space complexity is $O(C)$. Here, $n$ is +#### Python3 + ```python class Solution: def maxRepOpt1(self, text: str) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxRepOpt1(String text) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func maxRepOpt1(text string) (ans int) { cnt := [26]int{} @@ -176,6 +184,8 @@ func maxRepOpt1(text string) (ans int) { } ``` +#### TypeScript + ```ts function maxRepOpt1(text: string): number { const idx = (c: string) => c.charCodeAt(0) - 'a'.charCodeAt(0); diff --git a/solution/1100-1199/1157.Online Majority Element In Subarray/README.md b/solution/1100-1199/1157.Online Majority Element In Subarray/README.md index 92c337002635f..9f95a3896dd2b 100644 --- a/solution/1100-1199/1157.Online Majority Element In Subarray/README.md +++ b/solution/1100-1199/1157.Online Majority Element In Subarray/README.md @@ -95,6 +95,8 @@ majorityChecker.query(2,3,2); // 返回 2 +#### Python3 + ```python class Node: __slots__ = ("l", "r", "x", "cnt") @@ -170,6 +172,8 @@ class MajorityChecker: # param_1 = obj.query(left,right,threshold) ``` +#### Java + ```java class Node { int l, r; @@ -281,6 +285,8 @@ class MajorityChecker { */ ``` +#### C++ + ```cpp class Node { public: @@ -386,6 +392,8 @@ private: */ ``` +#### Go + ```go type node struct { l, r, x, cnt int diff --git a/solution/1100-1199/1157.Online Majority Element In Subarray/README_EN.md b/solution/1100-1199/1157.Online Majority Element In Subarray/README_EN.md index 7152f37d81766..fa4c12d39b635 100644 --- a/solution/1100-1199/1157.Online Majority Element In Subarray/README_EN.md +++ b/solution/1100-1199/1157.Online Majority Element In Subarray/README_EN.md @@ -93,6 +93,8 @@ In terms of time complexity, the time complexity of the initialization method is +#### Python3 + ```python class Node: __slots__ = ("l", "r", "x", "cnt") @@ -168,6 +170,8 @@ class MajorityChecker: # param_1 = obj.query(left,right,threshold) ``` +#### Java + ```java class Node { int l, r; @@ -279,6 +283,8 @@ class MajorityChecker { */ ``` +#### C++ + ```cpp class Node { public: @@ -384,6 +390,8 @@ private: */ ``` +#### Go + ```go type node struct { l, r, x, cnt int diff --git a/solution/1100-1199/1158.Market Analysis I/README.md b/solution/1100-1199/1158.Market Analysis I/README.md index 2b120602de75b..58e7a65f60df6 100644 --- a/solution/1100-1199/1158.Market Analysis I/README.md +++ b/solution/1100-1199/1158.Market Analysis I/README.md @@ -126,6 +126,8 @@ Items 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -148,6 +150,8 @@ GROUP BY user_id; +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1100-1199/1158.Market Analysis I/README_EN.md b/solution/1100-1199/1158.Market Analysis I/README_EN.md index 76099654d7951..d84fa599f4ea5 100644 --- a/solution/1100-1199/1158.Market Analysis I/README_EN.md +++ b/solution/1100-1199/1158.Market Analysis I/README_EN.md @@ -126,6 +126,8 @@ Items table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -148,6 +150,8 @@ GROUP BY user_id; +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1100-1199/1159.Market Analysis II/README.md b/solution/1100-1199/1159.Market Analysis II/README.md index 5d0d9fde1a55b..a7f4a4318fa38 100644 --- a/solution/1100-1199/1159.Market Analysis II/README.md +++ b/solution/1100-1199/1159.Market Analysis II/README.md @@ -129,6 +129,8 @@ id为 4 的用户的查询结果是 no,因为他卖出的第二件商品的品 +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1100-1199/1159.Market Analysis II/README_EN.md b/solution/1100-1199/1159.Market Analysis II/README_EN.md index 4d75ea1fabbdc..c872d4ca1c499 100644 --- a/solution/1100-1199/1159.Market Analysis II/README_EN.md +++ b/solution/1100-1199/1159.Market Analysis II/README_EN.md @@ -130,6 +130,8 @@ The answer for the user with id 4 is no because the brand of their second sold i +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1100-1199/1160.Find Words That Can Be Formed by Characters/README.md b/solution/1100-1199/1160.Find Words That Can Be Formed by Characters/README.md index 5c12ed3152d00..5f2b6c1281388 100644 --- a/solution/1100-1199/1160.Find Words That Can Be Formed by Characters/README.md +++ b/solution/1100-1199/1160.Find Words That Can Be Formed by Characters/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def countCharacters(self, words: List[str], chars: str) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countCharacters(String[] words, String chars) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func countCharacters(words []string, chars string) (ans int) { cnt := [26]int{} @@ -168,6 +176,8 @@ func countCharacters(words []string, chars string) (ans int) { } ``` +#### TypeScript + ```ts function countCharacters(words: string[], chars: string): number { const idx = (c: string) => c.charCodeAt(0) - 'a'.charCodeAt(0); @@ -193,6 +203,8 @@ function countCharacters(words: string[], chars: string): number { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1100-1199/1160.Find Words That Can Be Formed by Characters/README_EN.md b/solution/1100-1199/1160.Find Words That Can Be Formed by Characters/README_EN.md index 5e9561657f789..bc16f804f49ed 100644 --- a/solution/1100-1199/1160.Find Words That Can Be Formed by Characters/README_EN.md +++ b/solution/1100-1199/1160.Find Words That Can Be Formed by Characters/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(L)$, and the space complexity is $O(C)$. Here, $L$ is +#### Python3 + ```python class Solution: def countCharacters(self, words: List[str], chars: str) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countCharacters(String[] words, String chars) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func countCharacters(words []string, chars string) (ans int) { cnt := [26]int{} @@ -162,6 +170,8 @@ func countCharacters(words []string, chars string) (ans int) { } ``` +#### TypeScript + ```ts function countCharacters(words: string[], chars: string): number { const idx = (c: string) => c.charCodeAt(0) - 'a'.charCodeAt(0); @@ -187,6 +197,8 @@ function countCharacters(words: string[], chars: string): number { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1100-1199/1161.Maximum Level Sum of a Binary Tree/README.md b/solution/1100-1199/1161.Maximum Level Sum of a Binary Tree/README.md index fcbd93ae25830..5f5b910d646be 100644 --- a/solution/1100-1199/1161.Maximum Level Sum of a Binary Tree/README.md +++ b/solution/1100-1199/1161.Maximum Level Sum of a Binary Tree/README.md @@ -71,6 +71,8 @@ BFS 层次遍历,求每一层的节点和,找出节点和最大的层,若 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -218,6 +226,8 @@ func maxLevelSum(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -271,6 +281,8 @@ function maxLevelSum(root: TreeNode | null): number { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -295,6 +307,8 @@ class Solution: return s.index(max(s)) + 1 ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -342,6 +356,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -378,6 +394,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/1100-1199/1161.Maximum Level Sum of a Binary Tree/README_EN.md b/solution/1100-1199/1161.Maximum Level Sum of a Binary Tree/README_EN.md index f0d07c66ca7a8..c557e776aca56 100644 --- a/solution/1100-1199/1161.Maximum Level Sum of a Binary Tree/README_EN.md +++ b/solution/1100-1199/1161.Maximum Level Sum of a Binary Tree/README_EN.md @@ -67,6 +67,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -214,6 +222,8 @@ func maxLevelSum(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -267,6 +277,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -291,6 +303,8 @@ class Solution: return s.index(max(s)) + 1 ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -338,6 +352,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -374,6 +390,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/1100-1199/1162.As Far from Land as Possible/README.md b/solution/1100-1199/1162.As Far from Land as Possible/README.md index 9dd916c676db6..9a798c37c8ef9 100644 --- a/solution/1100-1199/1162.As Far from Land as Possible/README.md +++ b/solution/1100-1199/1162.As Far from Land as Possible/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def maxDistance(self, grid: List[List[int]]) -> int: @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxDistance(int[][] grid) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go func maxDistance(grid [][]int) int { n := len(grid) @@ -211,6 +219,8 @@ func maxDistance(grid [][]int) int { } ``` +#### TypeScript + ```ts function maxDistance(grid: number[][]): number { const n = grid.length; diff --git a/solution/1100-1199/1162.As Far from Land as Possible/README_EN.md b/solution/1100-1199/1162.As Far from Land as Possible/README_EN.md index f124cf8fde33c..055b122431adc 100644 --- a/solution/1100-1199/1162.As Far from Land as Possible/README_EN.md +++ b/solution/1100-1199/1162.As Far from Land as Possible/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$. Here, $n$ +#### Python3 + ```python class Solution: def maxDistance(self, grid: List[List[int]]) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxDistance(int[][] grid) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func maxDistance(grid [][]int) int { n := len(grid) @@ -199,6 +207,8 @@ func maxDistance(grid [][]int) int { } ``` +#### TypeScript + ```ts function maxDistance(grid: number[][]): number { const n = grid.length; diff --git a/solution/1100-1199/1163.Last Substring in Lexicographical Order/README.md b/solution/1100-1199/1163.Last Substring in Lexicographical Order/README.md index 02843f3a15c9e..aad3b0301da28 100644 --- a/solution/1100-1199/1163.Last Substring in Lexicographical Order/README.md +++ b/solution/1100-1199/1163.Last Substring in Lexicographical Order/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def lastSubstring(self, s: str) -> str: @@ -91,6 +93,8 @@ class Solution: return s[i:] ``` +#### Java + ```java class Solution { public String lastSubstring(String s) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func lastSubstring(s string) string { i, n := 0, len(s) @@ -162,6 +170,8 @@ func lastSubstring(s string) string { } ``` +#### TypeScript + ```ts function lastSubstring(s: string): string { const n = s.length; diff --git a/solution/1100-1199/1163.Last Substring in Lexicographical Order/README_EN.md b/solution/1100-1199/1163.Last Substring in Lexicographical Order/README_EN.md index 6fa54056e2dc0..4842580b87966 100644 --- a/solution/1100-1199/1163.Last Substring in Lexicographical Order/README_EN.md +++ b/solution/1100-1199/1163.Last Substring in Lexicographical Order/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(n)$, where $n$ is the length of string $s$. The space +#### Python3 + ```python class Solution: def lastSubstring(self, s: str) -> str: @@ -89,6 +91,8 @@ class Solution: return s[i:] ``` +#### Java + ```java class Solution { public String lastSubstring(String s) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func lastSubstring(s string) string { i, n := 0, len(s) @@ -160,6 +168,8 @@ func lastSubstring(s string) string { } ``` +#### TypeScript + ```ts function lastSubstring(s: string): string { const n = s.length; diff --git a/solution/1100-1199/1164.Product Price at a Given Date/README.md b/solution/1100-1199/1164.Product Price at a Given Date/README.md index 9a0dfe0489fec..7f0478aa0b08d 100644 --- a/solution/1100-1199/1164.Product Price at a Given Date/README.md +++ b/solution/1100-1199/1164.Product Price at a Given Date/README.md @@ -75,6 +75,8 @@ Products 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -106,6 +108,8 @@ FROM +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1100-1199/1164.Product Price at a Given Date/README_EN.md b/solution/1100-1199/1164.Product Price at a Given Date/README_EN.md index 65439ca137c80..9e6ffa8caf273 100644 --- a/solution/1100-1199/1164.Product Price at a Given Date/README_EN.md +++ b/solution/1100-1199/1164.Product Price at a Given Date/README_EN.md @@ -75,6 +75,8 @@ We can use a subquery to find the price of the last price change for each produc +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -106,6 +108,8 @@ FROM +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1100-1199/1165.Single-Row Keyboard/README.md b/solution/1100-1199/1165.Single-Row Keyboard/README.md index bf0e29c648071..8b4af0faeb63a 100644 --- a/solution/1100-1199/1165.Single-Row Keyboard/README.md +++ b/solution/1100-1199/1165.Single-Row Keyboard/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def calculateTime(self, keyboard: str, word: str) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int calculateTime(String keyboard, String word) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func calculateTime(keyboard string, word string) (ans int) { pos := [26]int{} @@ -143,6 +151,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function calculateTime(keyboard: string, word: string): number { const pos: number[] = Array(26).fill(0); diff --git a/solution/1100-1199/1165.Single-Row Keyboard/README_EN.md b/solution/1100-1199/1165.Single-Row Keyboard/README_EN.md index 6d25552bb844d..60ed4ce43d652 100644 --- a/solution/1100-1199/1165.Single-Row Keyboard/README_EN.md +++ b/solution/1100-1199/1165.Single-Row Keyboard/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n)$, and the space complexity is $O(C)$. Here, $n$ is +#### Python3 + ```python class Solution: def calculateTime(self, keyboard: str, word: str) -> int: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int calculateTime(String keyboard, String word) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func calculateTime(keyboard string, word string) (ans int) { pos := [26]int{} @@ -141,6 +149,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function calculateTime(keyboard: string, word: string): number { const pos: number[] = Array(26).fill(0); diff --git a/solution/1100-1199/1166.Design File System/README.md b/solution/1100-1199/1166.Design File System/README.md index 545094872ade0..94ab441029c35 100644 --- a/solution/1100-1199/1166.Design File System/README.md +++ b/solution/1100-1199/1166.Design File System/README.md @@ -101,6 +101,8 @@ fileSystem.get("/c"); // 返回 -1 因为该路径不存在。 +#### Python3 + ```python class Trie: def __init__(self, v: int = -1): @@ -145,6 +147,8 @@ class FileSystem: # param_2 = obj.get(path) ``` +#### Java + ```java class Trie { Map children = new HashMap<>(); @@ -208,6 +212,8 @@ class FileSystem { */ ``` +#### C++ + ```cpp class Trie { public: @@ -286,6 +292,8 @@ private: */ ``` +#### Go + ```go type trie struct { children map[string]*trie @@ -348,6 +356,8 @@ func (this *FileSystem) Get(path string) int { */ ``` +#### TypeScript + ```ts class Trie { children: Map; diff --git a/solution/1100-1199/1166.Design File System/README_EN.md b/solution/1100-1199/1166.Design File System/README_EN.md index 5f3e4e3642cfc..40d4b5d2fa576 100644 --- a/solution/1100-1199/1166.Design File System/README_EN.md +++ b/solution/1100-1199/1166.Design File System/README_EN.md @@ -100,6 +100,8 @@ The total time complexity is $O(\sum_{w \in W}|w|)$, and the total space complex +#### Python3 + ```python class Trie: def __init__(self, v: int = -1): @@ -144,6 +146,8 @@ class FileSystem: # param_2 = obj.get(path) ``` +#### Java + ```java class Trie { Map children = new HashMap<>(); @@ -207,6 +211,8 @@ class FileSystem { */ ``` +#### C++ + ```cpp class Trie { public: @@ -285,6 +291,8 @@ private: */ ``` +#### Go + ```go type trie struct { children map[string]*trie @@ -347,6 +355,8 @@ func (this *FileSystem) Get(path string) int { */ ``` +#### TypeScript + ```ts class Trie { children: Map; diff --git a/solution/1100-1199/1167.Minimum Cost to Connect Sticks/README.md b/solution/1100-1199/1167.Minimum Cost to Connect Sticks/README.md index b05dad8438608..b526c88aba926 100644 --- a/solution/1100-1199/1167.Minimum Cost to Connect Sticks/README.md +++ b/solution/1100-1199/1167.Minimum Cost to Connect Sticks/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def connectSticks(self, sticks: List[int]) -> int: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int connectSticks(int[] sticks) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func connectSticks(sticks []int) (ans int) { hp := &hp{sticks} @@ -161,6 +169,8 @@ func (h *hp) Pop() any { } ``` +#### TypeScript + ```ts function connectSticks(sticks: number[]): number { const pq = new Heap(sticks); diff --git a/solution/1100-1199/1167.Minimum Cost to Connect Sticks/README_EN.md b/solution/1100-1199/1167.Minimum Cost to Connect Sticks/README_EN.md index 195f42f0978b4..e9c27a29c7b0b 100644 --- a/solution/1100-1199/1167.Minimum Cost to Connect Sticks/README_EN.md +++ b/solution/1100-1199/1167.Minimum Cost to Connect Sticks/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def connectSticks(self, sticks: List[int]) -> int: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int connectSticks(int[] sticks) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func connectSticks(sticks []int) (ans int) { hp := &hp{sticks} @@ -159,6 +167,8 @@ func (h *hp) Pop() any { } ``` +#### TypeScript + ```ts function connectSticks(sticks: number[]): number { const pq = new Heap(sticks); diff --git a/solution/1100-1199/1168.Optimize Water Distribution in a Village/README.md b/solution/1100-1199/1168.Optimize Water Distribution in a Village/README.md index c648a3060c352..f542bde81975d 100644 --- a/solution/1100-1199/1168.Optimize Water Distribution in a Village/README.md +++ b/solution/1100-1199/1168.Optimize Water Distribution in a Village/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def minCostToSupplyWater( @@ -117,6 +119,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] p; @@ -155,6 +159,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -190,6 +196,8 @@ public: }; ``` +#### Go + ```go func minCostToSupplyWater(n int, wells []int, pipes [][]int) (ans int) { for i, w := range wells { @@ -224,6 +232,8 @@ func minCostToSupplyWater(n int, wells []int, pipes [][]int) (ans int) { } ``` +#### TypeScript + ```ts function minCostToSupplyWater(n: number, wells: number[], pipes: number[][]): number { for (let i = 0; i < n; ++i) { @@ -256,6 +266,8 @@ function minCostToSupplyWater(n: number, wells: number[], pipes: number[][]): nu } ``` +#### Rust + ```rust struct UnionFind { p: Vec, @@ -329,6 +341,8 @@ impl Solution { +#### Python3 + ```python class UnionFind: __slots__ = ("p", "size") @@ -372,6 +386,8 @@ class Solution: return ans ``` +#### Java + ```java class UnionFind { private int[] p; @@ -432,6 +448,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -491,6 +509,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p, size []int @@ -547,6 +567,8 @@ func minCostToSupplyWater(n int, wells []int, pipes [][]int) (ans int) { } ``` +#### TypeScript + ```ts class UnionFind { private p: number[]; diff --git a/solution/1100-1199/1168.Optimize Water Distribution in a Village/README_EN.md b/solution/1100-1199/1168.Optimize Water Distribution in a Village/README_EN.md index b65adab83adb2..fea4fd7ea6d20 100644 --- a/solution/1100-1199/1168.Optimize Water Distribution in a Village/README_EN.md +++ b/solution/1100-1199/1168.Optimize Water Distribution in a Village/README_EN.md @@ -88,6 +88,8 @@ The time complexity is $O((m + n) \times \log (m + n))$, and the space complexit +#### Python3 + ```python class Solution: def minCostToSupplyWater( @@ -113,6 +115,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] p; @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go func minCostToSupplyWater(n int, wells []int, pipes [][]int) (ans int) { for i, w := range wells { @@ -220,6 +228,8 @@ func minCostToSupplyWater(n int, wells []int, pipes [][]int) (ans int) { } ``` +#### TypeScript + ```ts function minCostToSupplyWater(n: number, wells: number[], pipes: number[][]): number { for (let i = 0; i < n; ++i) { @@ -252,6 +262,8 @@ function minCostToSupplyWater(n: number, wells: number[], pipes: number[][]): nu } ``` +#### Rust + ```rust struct UnionFind { p: Vec, @@ -325,6 +337,8 @@ impl Solution { +#### Python3 + ```python class UnionFind: __slots__ = ("p", "size") @@ -368,6 +382,8 @@ class Solution: return ans ``` +#### Java + ```java class UnionFind { private int[] p; @@ -428,6 +444,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -487,6 +505,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p, size []int @@ -543,6 +563,8 @@ func minCostToSupplyWater(n int, wells []int, pipes [][]int) (ans int) { } ``` +#### TypeScript + ```ts class UnionFind { private p: number[]; diff --git a/solution/1100-1199/1169.Invalid Transactions/README.md b/solution/1100-1199/1169.Invalid Transactions/README.md index 09f993c8f5e21..31b719854b62a 100644 --- a/solution/1100-1199/1169.Invalid Transactions/README.md +++ b/solution/1100-1199/1169.Invalid Transactions/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def invalidTransactions(self, transactions: List[str]) -> List[str]: @@ -105,6 +107,8 @@ class Solution: return [transactions[i] for i in idx] ``` +#### Java + ```java class Solution { public List invalidTransactions(String[] transactions) { @@ -148,6 +152,8 @@ class Item { } ``` +#### C++ + ```cpp class Solution { public: @@ -190,6 +196,8 @@ public: }; ``` +#### Go + ```go func invalidTransactions(transactions []string) (ans []string) { d := map[string][]tuple{} diff --git a/solution/1100-1199/1169.Invalid Transactions/README_EN.md b/solution/1100-1199/1169.Invalid Transactions/README_EN.md index f0ad03f9554fd..b9bb290c3f835 100644 --- a/solution/1100-1199/1169.Invalid Transactions/README_EN.md +++ b/solution/1100-1199/1169.Invalid Transactions/README_EN.md @@ -85,6 +85,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$. Here, $n$ i +#### Python3 + ```python class Solution: def invalidTransactions(self, transactions: List[str]) -> List[str]: @@ -103,6 +105,8 @@ class Solution: return [transactions[i] for i in idx] ``` +#### Java + ```java class Solution { public List invalidTransactions(String[] transactions) { @@ -146,6 +150,8 @@ class Item { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go func invalidTransactions(transactions []string) (ans []string) { d := map[string][]tuple{} diff --git a/solution/1100-1199/1170.Compare Strings by Frequency of the Smallest Character/README.md b/solution/1100-1199/1170.Compare Strings by Frequency of the Smallest Character/README.md index 73c90ac595058..b3a10e4fc8f72 100644 --- a/solution/1100-1199/1170.Compare Strings by Frequency of the Smallest Character/README.md +++ b/solution/1100-1199/1170.Compare Strings by Frequency of the Smallest Character/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def numSmallerByFrequency(self, queries: List[str], words: List[str]) -> List[int]: @@ -89,6 +91,8 @@ class Solution: return [n - bisect_right(nums, f(q)) for q in queries] ``` +#### Java + ```java class Solution { public int[] numSmallerByFrequency(String[] queries, String[] words) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func numSmallerByFrequency(queries []string, words []string) (ans []int) { f := func(s string) int { @@ -191,6 +199,8 @@ func numSmallerByFrequency(queries []string, words []string) (ans []int) { } ``` +#### TypeScript + ```ts function numSmallerByFrequency(queries: string[], words: string[]): number[] { const f = (s: string): number => { diff --git a/solution/1100-1199/1170.Compare Strings by Frequency of the Smallest Character/README_EN.md b/solution/1100-1199/1170.Compare Strings by Frequency of the Smallest Character/README_EN.md index 5adb335d61ac6..f523035c1436f 100644 --- a/solution/1100-1199/1170.Compare Strings by Frequency of the Smallest Character/README_EN.md +++ b/solution/1100-1199/1170.Compare Strings by Frequency of the Smallest Character/README_EN.md @@ -73,6 +73,8 @@ The time complexity is $O((n + q) \times M)$, and the space complexity is $O(n)$ +#### Python3 + ```python class Solution: def numSmallerByFrequency(self, queries: List[str], words: List[str]) -> List[int]: @@ -85,6 +87,8 @@ class Solution: return [n - bisect_right(nums, f(q)) for q in queries] ``` +#### Java + ```java class Solution { public int[] numSmallerByFrequency(String[] queries, String[] words) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func numSmallerByFrequency(queries []string, words []string) (ans []int) { f := func(s string) int { @@ -187,6 +195,8 @@ func numSmallerByFrequency(queries []string, words []string) (ans []int) { } ``` +#### TypeScript + ```ts function numSmallerByFrequency(queries: string[], words: string[]): number[] { const f = (s: string): number => { diff --git a/solution/1100-1199/1171.Remove Zero Sum Consecutive Nodes from Linked List/README.md b/solution/1100-1199/1171.Remove Zero Sum Consecutive Nodes from Linked List/README.md index a67cc79278902..fe236e41ff3bd 100644 --- a/solution/1100-1199/1171.Remove Zero Sum Consecutive Nodes from Linked List/README.md +++ b/solution/1100-1199/1171.Remove Zero Sum Consecutive Nodes from Linked List/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -100,6 +102,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -198,6 +206,8 @@ func removeZeroSumSublists(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -228,6 +238,8 @@ function removeZeroSumSublists(head: ListNode | null): ListNode | null { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] diff --git a/solution/1100-1199/1171.Remove Zero Sum Consecutive Nodes from Linked List/README_EN.md b/solution/1100-1199/1171.Remove Zero Sum Consecutive Nodes from Linked List/README_EN.md index 5e5869b2a3e40..822af562da6a7 100644 --- a/solution/1100-1199/1171.Remove Zero Sum Consecutive Nodes from Linked List/README_EN.md +++ b/solution/1100-1199/1171.Remove Zero Sum Consecutive Nodes from Linked List/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -99,6 +101,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -197,6 +205,8 @@ func removeZeroSumSublists(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -227,6 +237,8 @@ function removeZeroSumSublists(head: ListNode | null): ListNode | null { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] diff --git a/solution/1100-1199/1172.Dinner Plate Stacks/README.md b/solution/1100-1199/1172.Dinner Plate Stacks/README.md index 12d6009abe7d0..fe6494be79d35 100644 --- a/solution/1100-1199/1172.Dinner Plate Stacks/README.md +++ b/solution/1100-1199/1172.Dinner Plate Stacks/README.md @@ -121,6 +121,8 @@ D.pop() // 返回 -1。仍然没有栈。 +#### Python3 + ```python from sortedcontainers import SortedSet @@ -165,6 +167,8 @@ class DinnerPlates: # param_3 = obj.popAtStack(index) ``` +#### Java + ```java class DinnerPlates { private int capacity; @@ -221,6 +225,8 @@ class DinnerPlates { */ ``` +#### C++ + ```cpp class DinnerPlates { public: @@ -280,6 +286,8 @@ private: */ ``` +#### Go + ```go type DinnerPlates struct { capacity int @@ -336,6 +344,8 @@ func (this *DinnerPlates) PopAtStack(index int) int { */ ``` +#### TypeScript + ```ts class DinnerPlates { capacity: number; diff --git a/solution/1100-1199/1172.Dinner Plate Stacks/README_EN.md b/solution/1100-1199/1172.Dinner Plate Stacks/README_EN.md index 641e824b3b6a3..d57e8331e0fc9 100644 --- a/solution/1100-1199/1172.Dinner Plate Stacks/README_EN.md +++ b/solution/1100-1199/1172.Dinner Plate Stacks/README_EN.md @@ -120,6 +120,8 @@ The time complexity is $(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python from sortedcontainers import SortedSet @@ -164,6 +166,8 @@ class DinnerPlates: # param_3 = obj.popAtStack(index) ``` +#### Java + ```java class DinnerPlates { private int capacity; @@ -220,6 +224,8 @@ class DinnerPlates { */ ``` +#### C++ + ```cpp class DinnerPlates { public: @@ -279,6 +285,8 @@ private: */ ``` +#### Go + ```go type DinnerPlates struct { capacity int @@ -335,6 +343,8 @@ func (this *DinnerPlates) PopAtStack(index int) int { */ ``` +#### TypeScript + ```ts class DinnerPlates { capacity: number; diff --git a/solution/1100-1199/1173.Immediate Food Delivery I/README.md b/solution/1100-1199/1173.Immediate Food Delivery I/README.md index 4b1f4b9579019..466de56f3aa70 100644 --- a/solution/1100-1199/1173.Immediate Food Delivery I/README.md +++ b/solution/1100-1199/1173.Immediate Food Delivery I/README.md @@ -76,6 +76,8 @@ Delivery 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1100-1199/1173.Immediate Food Delivery I/README_EN.md b/solution/1100-1199/1173.Immediate Food Delivery I/README_EN.md index 1002a52a6a90a..ce4152a4480d7 100644 --- a/solution/1100-1199/1173.Immediate Food Delivery I/README_EN.md +++ b/solution/1100-1199/1173.Immediate Food Delivery I/README_EN.md @@ -76,6 +76,8 @@ We can use the `sum` function to count the number of instant orders, and then di +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1100-1199/1174.Immediate Food Delivery II/README.md b/solution/1100-1199/1174.Immediate Food Delivery II/README.md index 26534ba5be12c..1b2b792030654 100644 --- a/solution/1100-1199/1174.Immediate Food Delivery II/README.md +++ b/solution/1100-1199/1174.Immediate Food Delivery II/README.md @@ -85,6 +85,8 @@ Delivery 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -110,6 +112,8 @@ WHERE +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1100-1199/1174.Immediate Food Delivery II/README_EN.md b/solution/1100-1199/1174.Immediate Food Delivery II/README_EN.md index d8c45e65b7e16..d49220cd8a91e 100644 --- a/solution/1100-1199/1174.Immediate Food Delivery II/README_EN.md +++ b/solution/1100-1199/1174.Immediate Food Delivery II/README_EN.md @@ -84,6 +84,8 @@ We can use a subquery to first find the first order of each user, and then calcu +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -109,6 +111,8 @@ We can use the `RANK()` window function to rank the orders of each user in ascen +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1100-1199/1175.Prime Arrangements/README.md b/solution/1100-1199/1175.Prime Arrangements/README.md index fab7cbbf665a3..445c71185ba23 100644 --- a/solution/1100-1199/1175.Prime Arrangements/README.md +++ b/solution/1100-1199/1175.Prime Arrangements/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def numPrimeArrangements(self, n: int) -> int: @@ -87,6 +89,8 @@ class Solution: return ans % (10**9 + 7) ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; const int MOD = 1e9 + 7; @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func numPrimeArrangements(n int) int { count := func(n int) int { diff --git a/solution/1100-1199/1175.Prime Arrangements/README_EN.md b/solution/1100-1199/1175.Prime Arrangements/README_EN.md index 370e944df768d..8dcf02151b110 100644 --- a/solution/1100-1199/1175.Prime Arrangements/README_EN.md +++ b/solution/1100-1199/1175.Prime Arrangements/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n \times \log \log n)$. +#### Python3 + ```python class Solution: def numPrimeArrangements(self, n: int) -> int: @@ -87,6 +89,8 @@ class Solution: return ans % (10**9 + 7) ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; const int MOD = 1e9 + 7; @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func numPrimeArrangements(n int) int { count := func(n int) int { diff --git a/solution/1100-1199/1176.Diet Plan Performance/README.md b/solution/1100-1199/1176.Diet Plan Performance/README.md index 55953f5abb339..f75502868bc7d 100644 --- a/solution/1100-1199/1176.Diet Plan Performance/README.md +++ b/solution/1100-1199/1176.Diet Plan Performance/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def dietPlanPerformance( @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int dietPlanPerformance(int[] calories, int k, int lower, int upper) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func dietPlanPerformance(calories []int, k int, lower int, upper int) (ans int) { n := len(calories) @@ -164,6 +172,8 @@ func dietPlanPerformance(calories []int, k int, lower int, upper int) (ans int) } ``` +#### TypeScript + ```ts function dietPlanPerformance(calories: number[], k: number, lower: number, upper: number): number { const n = calories.length; @@ -198,6 +208,8 @@ function dietPlanPerformance(calories: number[], k: number, lower: number, upper +#### Python3 + ```python class Solution: def dietPlanPerformance( @@ -218,6 +230,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int dietPlanPerformance(int[] calories, int k, int lower, int upper) { @@ -244,6 +258,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -269,6 +285,8 @@ public: }; ``` +#### Go + ```go func dietPlanPerformance(calories []int, k int, lower int, upper int) (ans int) { n := len(calories) @@ -293,6 +311,8 @@ func dietPlanPerformance(calories []int, k int, lower int, upper int) (ans int) } ``` +#### TypeScript + ```ts function dietPlanPerformance(calories: number[], k: number, lower: number, upper: number): number { const n = calories.length; diff --git a/solution/1100-1199/1176.Diet Plan Performance/README_EN.md b/solution/1100-1199/1176.Diet Plan Performance/README_EN.md index 6b69e186d9ab7..537572cf908c0 100644 --- a/solution/1100-1199/1176.Diet Plan Performance/README_EN.md +++ b/solution/1100-1199/1176.Diet Plan Performance/README_EN.md @@ -89,6 +89,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def dietPlanPerformance( @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int dietPlanPerformance(int[] calories, int k, int lower, int upper) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func dietPlanPerformance(calories []int, k int, lower int, upper int) (ans int) { n := len(calories) @@ -170,6 +178,8 @@ func dietPlanPerformance(calories []int, k int, lower int, upper int) (ans int) } ``` +#### TypeScript + ```ts function dietPlanPerformance(calories: number[], k: number, lower: number, upper: number): number { const n = calories.length; @@ -204,6 +214,8 @@ The time complexity is $O(n)$, where $n$ is the length of the `calories` array. +#### Python3 + ```python class Solution: def dietPlanPerformance( @@ -224,6 +236,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int dietPlanPerformance(int[] calories, int k, int lower, int upper) { @@ -250,6 +264,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -275,6 +291,8 @@ public: }; ``` +#### Go + ```go func dietPlanPerformance(calories []int, k int, lower int, upper int) (ans int) { n := len(calories) @@ -299,6 +317,8 @@ func dietPlanPerformance(calories []int, k int, lower int, upper int) (ans int) } ``` +#### TypeScript + ```ts function dietPlanPerformance(calories: number[], k: number, lower: number, upper: number): number { const n = calories.length; diff --git a/solution/1100-1199/1177.Can Make Palindrome from Substring/README.md b/solution/1100-1199/1177.Can Make Palindrome from Substring/README.md index c8a14df899975..62a4b2069d678 100644 --- a/solution/1100-1199/1177.Can Make Palindrome from Substring/README.md +++ b/solution/1100-1199/1177.Can Make Palindrome from Substring/README.md @@ -73,6 +73,8 @@ queries[4] : 子串 = "abcda",可以变成回文的 "abcba +#### Python3 + ```python class Solution: def canMakePaliQueries(self, s: str, queries: List[List[int]]) -> List[bool]: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List canMakePaliQueries(String s, int[][] queries) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func canMakePaliQueries(s string, queries [][]int) (ans []bool) { n := len(s) @@ -162,6 +170,8 @@ func canMakePaliQueries(s string, queries [][]int) (ans []bool) { } ``` +#### TypeScript + ```ts function canMakePaliQueries(s: string, queries: number[][]): boolean[] { const n = s.length; diff --git a/solution/1100-1199/1177.Can Make Palindrome from Substring/README_EN.md b/solution/1100-1199/1177.Can Make Palindrome from Substring/README_EN.md index 8ae874a03d303..1e389b0848baa 100644 --- a/solution/1100-1199/1177.Can Make Palindrome from Substring/README_EN.md +++ b/solution/1100-1199/1177.Can Make Palindrome from Substring/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O((n + m) \times C)$, and the space complexity is $O(n \ +#### Python3 + ```python class Solution: def canMakePaliQueries(self, s: str, queries: List[List[int]]) -> List[bool]: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List canMakePaliQueries(String s, int[][] queries) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func canMakePaliQueries(s string, queries [][]int) (ans []bool) { n := len(s) @@ -166,6 +174,8 @@ func canMakePaliQueries(s string, queries [][]int) (ans []bool) { } ``` +#### TypeScript + ```ts function canMakePaliQueries(s: string, queries: number[][]): boolean[] { const n = s.length; diff --git a/solution/1100-1199/1178.Number of Valid Words for Each Puzzle/README.md b/solution/1100-1199/1178.Number of Valid Words for Each Puzzle/README.md index 7d7332f09b608..de7b73e3a5a22 100644 --- a/solution/1100-1199/1178.Number of Valid Words for Each Puzzle/README.md +++ b/solution/1100-1199/1178.Number of Valid Words for Each Puzzle/README.md @@ -85,6 +85,8 @@ puzzles = ["aboveyz","abrodyz","abslute","absoryz","actresz","gaswxyz"] +#### Python3 + ```python class Solution: def findNumOfValidWords(self, words: List[str], puzzles: List[str]) -> List[int]: @@ -109,6 +111,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List findNumOfValidWords(String[] words, String[] puzzles) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go func findNumOfValidWords(words []string, puzzles []string) (ans []int) { cnt := map[int]int{} @@ -199,6 +207,8 @@ func findNumOfValidWords(words []string, puzzles []string) (ans []int) { } ``` +#### TypeScript + ```ts function findNumOfValidWords(words: string[], puzzles: string[]): number[] { const cnt: Map = new Map(); diff --git a/solution/1100-1199/1178.Number of Valid Words for Each Puzzle/README_EN.md b/solution/1100-1199/1178.Number of Valid Words for Each Puzzle/README_EN.md index 7e6dde9f4e9b6..3f752f0aa87ed 100644 --- a/solution/1100-1199/1178.Number of Valid Words for Each Puzzle/README_EN.md +++ b/solution/1100-1199/1178.Number of Valid Words for Each Puzzle/README_EN.md @@ -88,6 +88,8 @@ The time complexity is $O(m \times |w| + n \times 2^{|p|})$, and the space compl +#### Python3 + ```python class Solution: def findNumOfValidWords(self, words: List[str], puzzles: List[str]) -> List[int]: @@ -112,6 +114,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List findNumOfValidWords(String[] words, String[] puzzles) { @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go func findNumOfValidWords(words []string, puzzles []string) (ans []int) { cnt := map[int]int{} @@ -202,6 +210,8 @@ func findNumOfValidWords(words []string, puzzles []string) (ans []int) { } ``` +#### TypeScript + ```ts function findNumOfValidWords(words: string[], puzzles: string[]): number[] { const cnt: Map = new Map(); diff --git a/solution/1100-1199/1179.Reformat Department Table/README.md b/solution/1100-1199/1179.Reformat Department Table/README.md index 5a4080f835c9a..16956d530969e 100644 --- a/solution/1100-1199/1179.Reformat Department Table/README.md +++ b/solution/1100-1199/1179.Reformat Department Table/README.md @@ -76,6 +76,8 @@ Department table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1100-1199/1179.Reformat Department Table/README_EN.md b/solution/1100-1199/1179.Reformat Department Table/README_EN.md index f9eb3c2fd80c2..86468784e378a 100644 --- a/solution/1100-1199/1179.Reformat Department Table/README_EN.md +++ b/solution/1100-1199/1179.Reformat Department Table/README_EN.md @@ -76,6 +76,8 @@ Note that the result table has 13 columns (1 for the department id + 12 for the +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1100-1199/1180.Count Substrings with Only One Distinct Letter/README.md b/solution/1100-1199/1180.Count Substrings with Only One Distinct Letter/README.md index 7e6c02c95e745..de51f7f8ccbd1 100644 --- a/solution/1100-1199/1180.Count Substrings with Only One Distinct Letter/README.md +++ b/solution/1100-1199/1180.Count Substrings with Only One Distinct Letter/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def countLetters(self, s: str) -> int: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countLetters(String s) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func countLetters(s string) int { ans := 0 @@ -128,6 +136,8 @@ func countLetters(s string) int { } ``` +#### TypeScript + ```ts function countLetters(s: string): number { let ans = 0; @@ -155,6 +165,8 @@ function countLetters(s: string): number { +#### Python3 + ```python class Solution: def countLetters(self, s: str) -> int: @@ -171,6 +183,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countLetters(String s) { @@ -190,6 +204,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -210,6 +226,8 @@ public: }; ``` +#### Go + ```go func countLetters(s string) (ans int) { i, n := 0, len(s) diff --git a/solution/1100-1199/1180.Count Substrings with Only One Distinct Letter/README_EN.md b/solution/1100-1199/1180.Count Substrings with Only One Distinct Letter/README_EN.md index 85f04f23e1f13..b36c47f1d920f 100644 --- a/solution/1100-1199/1180.Count Substrings with Only One Distinct Letter/README_EN.md +++ b/solution/1100-1199/1180.Count Substrings with Only One Distinct Letter/README_EN.md @@ -64,6 +64,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string $s$. The sp +#### Python3 + ```python class Solution: def countLetters(self, s: str) -> int: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countLetters(String s) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func countLetters(s string) int { ans := 0 @@ -128,6 +136,8 @@ func countLetters(s string) int { } ``` +#### TypeScript + ```ts function countLetters(s: string): number { let ans = 0; @@ -155,6 +165,8 @@ function countLetters(s: string): number { +#### Python3 + ```python class Solution: def countLetters(self, s: str) -> int: @@ -171,6 +183,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countLetters(String s) { @@ -190,6 +204,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -210,6 +226,8 @@ public: }; ``` +#### Go + ```go func countLetters(s string) (ans int) { i, n := 0, len(s) diff --git a/solution/1100-1199/1181.Before and After Puzzle/README.md b/solution/1100-1199/1181.Before and After Puzzle/README.md index 2bac774a2bf6d..ec5eac0aee5bc 100644 --- a/solution/1100-1199/1181.Before and After Puzzle/README.md +++ b/solution/1100-1199/1181.Before and After Puzzle/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def beforeAndAfterPuzzles(self, phrases: List[str]) -> List[str]: @@ -108,6 +110,8 @@ class Solution: return sorted(set(ans)) ``` +#### Java + ```java class Solution { public List beforeAndAfterPuzzles(String[] phrases) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func beforeAndAfterPuzzles(phrases []string) []string { n := len(phrases) @@ -187,6 +195,8 @@ func beforeAndAfterPuzzles(phrases []string) []string { } ``` +#### TypeScript + ```ts function beforeAndAfterPuzzles(phrases: string[]): string[] { const ps: string[][] = []; diff --git a/solution/1100-1199/1181.Before and After Puzzle/README_EN.md b/solution/1100-1199/1181.Before and After Puzzle/README_EN.md index 5bb051b493f5f..74fb6eead4203 100644 --- a/solution/1100-1199/1181.Before and After Puzzle/README_EN.md +++ b/solution/1100-1199/1181.Before and After Puzzle/README_EN.md @@ -91,6 +91,8 @@ The time complexity is $O(n^2 \times m \times (\log n + \log m))$, and the space +#### Python3 + ```python class Solution: def beforeAndAfterPuzzles(self, phrases: List[str]) -> List[str]: @@ -107,6 +109,8 @@ class Solution: return sorted(set(ans)) ``` +#### Java + ```java class Solution { public List beforeAndAfterPuzzles(String[] phrases) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func beforeAndAfterPuzzles(phrases []string) []string { n := len(phrases) @@ -186,6 +194,8 @@ func beforeAndAfterPuzzles(phrases []string) []string { } ``` +#### TypeScript + ```ts function beforeAndAfterPuzzles(phrases: string[]): string[] { const ps: string[][] = []; diff --git a/solution/1100-1199/1182.Shortest Distance to Target Color/README.md b/solution/1100-1199/1182.Shortest Distance to Target Color/README.md index 0ce89f0cd6fe4..ed2c6db98e2fa 100644 --- a/solution/1100-1199/1182.Shortest Distance to Target Color/README.md +++ b/solution/1100-1199/1182.Shortest Distance to Target Color/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def shortestDistanceColor( @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List shortestDistanceColor(int[] colors, int[][] queries) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func shortestDistanceColor(colors []int, queries [][]int) (ans []int) { n := len(colors) @@ -196,6 +204,8 @@ func shortestDistanceColor(colors []int, queries [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function shortestDistanceColor(colors: number[], queries: number[][]): number[] { const n = colors.length; diff --git a/solution/1100-1199/1182.Shortest Distance to Target Color/README_EN.md b/solution/1100-1199/1182.Shortest Distance to Target Color/README_EN.md index b9d6a06480e70..cb261b9d7a821 100644 --- a/solution/1100-1199/1182.Shortest Distance to Target Color/README_EN.md +++ b/solution/1100-1199/1182.Shortest Distance to Target Color/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def shortestDistanceColor( @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List shortestDistanceColor(int[] colors, int[][] queries) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func shortestDistanceColor(colors []int, queries [][]int) (ans []int) { n := len(colors) @@ -192,6 +200,8 @@ func shortestDistanceColor(colors []int, queries [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function shortestDistanceColor(colors: number[], queries: number[][]): number[] { const n = colors.length; diff --git a/solution/1100-1199/1183.Maximum Number of Ones/README.md b/solution/1100-1199/1183.Maximum Number of Ones/README.md index 2356cad01040f..c0a0be15103ce 100644 --- a/solution/1100-1199/1183.Maximum Number of Ones/README.md +++ b/solution/1100-1199/1183.Maximum Number of Ones/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def maximumNumberOfOnes( @@ -90,6 +92,8 @@ class Solution: return sum(cnt[:maxOnes]) ``` +#### Java + ```java class Solution { public int maximumNumberOfOnes(int width, int height, int sideLength, int maxOnes) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func maximumNumberOfOnes(width int, height int, sideLength int, maxOnes int) int { x := sideLength @@ -152,6 +160,8 @@ func maximumNumberOfOnes(width int, height int, sideLength int, maxOnes int) int } ``` +#### JavaScript + ```js /** * @param {number} width diff --git a/solution/1100-1199/1183.Maximum Number of Ones/README_EN.md b/solution/1100-1199/1183.Maximum Number of Ones/README_EN.md index eada6b93568d6..981c98aca770a 100644 --- a/solution/1100-1199/1183.Maximum Number of Ones/README_EN.md +++ b/solution/1100-1199/1183.Maximum Number of Ones/README_EN.md @@ -73,6 +73,8 @@ The time complexity is $O(m \times n)$, where $m$ and $n$ are the number of rows +#### Python3 + ```python class Solution: def maximumNumberOfOnes( @@ -88,6 +90,8 @@ class Solution: return sum(cnt[:maxOnes]) ``` +#### Java + ```java class Solution { public int maximumNumberOfOnes(int width, int height, int sideLength, int maxOnes) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func maximumNumberOfOnes(width int, height int, sideLength int, maxOnes int) int { x := sideLength @@ -150,6 +158,8 @@ func maximumNumberOfOnes(width int, height int, sideLength int, maxOnes int) int } ``` +#### JavaScript + ```js /** * @param {number} width diff --git a/solution/1100-1199/1184.Distance Between Bus Stops/README.md b/solution/1100-1199/1184.Distance Between Bus Stops/README.md index f2d7737144964..6dab77cd99947 100644 --- a/solution/1100-1199/1184.Distance Between Bus Stops/README.md +++ b/solution/1100-1199/1184.Distance Between Bus Stops/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def distanceBetweenBusStops( @@ -93,6 +95,8 @@ class Solution: return min(a, sum(distance) - a) ``` +#### Java + ```java class Solution { public int distanceBetweenBusStops(int[] distance, int start, int destination) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func distanceBetweenBusStops(distance []int, start int, destination int) int { s := 0 @@ -138,6 +146,8 @@ func distanceBetweenBusStops(distance []int, start int, destination int) int { } ``` +#### TypeScript + ```ts function distanceBetweenBusStops(distance: number[], start: number, destination: number): number { const s = distance.reduce((a, b) => a + b, 0); @@ -151,6 +161,8 @@ function distanceBetweenBusStops(distance: number[], start: number, destination: } ``` +#### JavaScript + ```js /** * @param {number[]} distance diff --git a/solution/1100-1199/1184.Distance Between Bus Stops/README_EN.md b/solution/1100-1199/1184.Distance Between Bus Stops/README_EN.md index f01143c2b6c46..8bea85b087567 100644 --- a/solution/1100-1199/1184.Distance Between Bus Stops/README_EN.md +++ b/solution/1100-1199/1184.Distance Between Bus Stops/README_EN.md @@ -100,6 +100,8 @@ The time complexity is $O(n)$, where $n$ is the number of bus stops. The space c +#### Python3 + ```python class Solution: def distanceBetweenBusStops( @@ -112,6 +114,8 @@ class Solution: return min(a, sum(distance) - a) ``` +#### Java + ```java class Solution { public int distanceBetweenBusStops(int[] distance, int start, int destination) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func distanceBetweenBusStops(distance []int, start int, destination int) int { s := 0 @@ -157,6 +165,8 @@ func distanceBetweenBusStops(distance []int, start int, destination int) int { } ``` +#### TypeScript + ```ts function distanceBetweenBusStops(distance: number[], start: number, destination: number): number { const s = distance.reduce((a, b) => a + b, 0); @@ -170,6 +180,8 @@ function distanceBetweenBusStops(distance: number[], start: number, destination: } ``` +#### JavaScript + ```js /** * @param {number[]} distance diff --git a/solution/1100-1199/1185.Day of the Week/README.md b/solution/1100-1199/1185.Day of the Week/README.md index 8c1c5a20d0492..28156aeb4a3cd 100644 --- a/solution/1100-1199/1185.Day of the Week/README.md +++ b/solution/1100-1199/1185.Day of the Week/README.md @@ -80,12 +80,16 @@ $$ +#### Python3 + ```python class Solution: def dayOfTheWeek(self, day: int, month: int, year: int) -> str: return datetime.date(year, month, day).strftime('%A') ``` +#### Java + ```java import java.util.Calendar; @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func dayOfTheWeek(d int, m int, y int) string { if m < 3 { @@ -132,6 +140,8 @@ func dayOfTheWeek(d int, m int, y int) string { } ``` +#### TypeScript + ```ts function dayOfTheWeek(d: number, m: number, y: number): string { if (m < 3) { @@ -164,6 +174,8 @@ function dayOfTheWeek(d: number, m: number, y: number): string { +#### Python3 + ```python class Solution: def dayOfTheWeek(self, d: int, m: int, y: int) -> str: @@ -184,6 +196,8 @@ class Solution: ][w] ``` +#### Java + ```java class Solution { public String dayOfTheWeek(int d, int m, int y) { diff --git a/solution/1100-1199/1185.Day of the Week/README_EN.md b/solution/1100-1199/1185.Day of the Week/README_EN.md index 7e942f00235b9..f13c9e8985d68 100644 --- a/solution/1100-1199/1185.Day of the Week/README_EN.md +++ b/solution/1100-1199/1185.Day of the Week/README_EN.md @@ -81,12 +81,16 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def dayOfTheWeek(self, day: int, month: int, year: int) -> str: return datetime.date(year, month, day).strftime('%A') ``` +#### Java + ```java import java.util.Calendar; @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func dayOfTheWeek(d int, m int, y int) string { if m < 3 { @@ -133,6 +141,8 @@ func dayOfTheWeek(d int, m int, y int) string { } ``` +#### TypeScript + ```ts function dayOfTheWeek(d: number, m: number, y: number): string { if (m < 3) { @@ -165,6 +175,8 @@ function dayOfTheWeek(d: number, m: number, y: number): string { +#### Python3 + ```python class Solution: def dayOfTheWeek(self, d: int, m: int, y: int) -> str: @@ -185,6 +197,8 @@ class Solution: ][w] ``` +#### Java + ```java class Solution { public String dayOfTheWeek(int d, int m, int y) { diff --git a/solution/1100-1199/1186.Maximum Subarray Sum with One Deletion/README.md b/solution/1100-1199/1186.Maximum Subarray Sum with One Deletion/README.md index e26ff3a9ca7de..b641399ba0f9b 100644 --- a/solution/1100-1199/1186.Maximum Subarray Sum with One Deletion/README.md +++ b/solution/1100-1199/1186.Maximum Subarray Sum with One Deletion/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def maximumSum(self, arr: List[int]) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumSum(int[] arr) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func maximumSum(arr []int) int { n := len(arr) @@ -164,6 +172,8 @@ func maximumSum(arr []int) int { } ``` +#### TypeScript + ```ts function maximumSum(arr: number[]): number { const n = arr.length; diff --git a/solution/1100-1199/1186.Maximum Subarray Sum with One Deletion/README_EN.md b/solution/1100-1199/1186.Maximum Subarray Sum with One Deletion/README_EN.md index 62cbeb978b378..8222a852b50a8 100644 --- a/solution/1100-1199/1186.Maximum Subarray Sum with One Deletion/README_EN.md +++ b/solution/1100-1199/1186.Maximum Subarray Sum with One Deletion/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def maximumSum(self, arr: List[int]) -> int: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumSum(int[] arr) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func maximumSum(arr []int) int { n := len(arr) @@ -160,6 +168,8 @@ func maximumSum(arr []int) int { } ``` +#### TypeScript + ```ts function maximumSum(arr: number[]): number { const n = arr.length; diff --git a/solution/1100-1199/1187.Make Array Strictly Increasing/README.md b/solution/1100-1199/1187.Make Array Strictly Increasing/README.md index 196b593a9727c..71a9f1952b4a0 100644 --- a/solution/1100-1199/1187.Make Array Strictly Increasing/README.md +++ b/solution/1100-1199/1187.Make Array Strictly Increasing/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def makeArrayIncreasing(self, arr1: List[int], arr2: List[int]) -> int: @@ -107,6 +109,8 @@ class Solution: return -1 if f[n - 1] >= inf else f[n - 1] ``` +#### Java + ```java class Solution { public int makeArrayIncreasing(int[] arr1, int[] arr2) { @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -182,6 +188,8 @@ public: }; ``` +#### Go + ```go func makeArrayIncreasing(arr1 []int, arr2 []int) int { sort.Ints(arr2) @@ -220,6 +228,8 @@ func makeArrayIncreasing(arr1 []int, arr2 []int) int { } ``` +#### TypeScript + ```ts function makeArrayIncreasing(arr1: number[], arr2: number[]): number { arr2.sort((a, b) => a - b); @@ -263,6 +273,8 @@ function makeArrayIncreasing(arr1: number[], arr2: number[]): number { } ``` +#### C# + ```cs public class Solution { public int MakeArrayIncreasing(int[] arr1, int[] arr2) { diff --git a/solution/1100-1199/1187.Make Array Strictly Increasing/README_EN.md b/solution/1100-1199/1187.Make Array Strictly Increasing/README_EN.md index 5c16ed932ba93..5cd63850b3610 100644 --- a/solution/1100-1199/1187.Make Array Strictly Increasing/README_EN.md +++ b/solution/1100-1199/1187.Make Array Strictly Increasing/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $(n \times (\log m + \min(m, n)))$, and the space complex +#### Python3 + ```python class Solution: def makeArrayIncreasing(self, arr1: List[int], arr2: List[int]) -> int: @@ -105,6 +107,8 @@ class Solution: return -1 if f[n - 1] >= inf else f[n - 1] ``` +#### Java + ```java class Solution { public int makeArrayIncreasing(int[] arr1, int[] arr2) { @@ -152,6 +156,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -180,6 +186,8 @@ public: }; ``` +#### Go + ```go func makeArrayIncreasing(arr1 []int, arr2 []int) int { sort.Ints(arr2) @@ -218,6 +226,8 @@ func makeArrayIncreasing(arr1 []int, arr2 []int) int { } ``` +#### TypeScript + ```ts function makeArrayIncreasing(arr1: number[], arr2: number[]): number { arr2.sort((a, b) => a - b); @@ -261,6 +271,8 @@ function makeArrayIncreasing(arr1: number[], arr2: number[]): number { } ``` +#### C# + ```cs public class Solution { public int MakeArrayIncreasing(int[] arr1, int[] arr2) { diff --git a/solution/1100-1199/1188.Design Bounded Blocking Queue/README.md b/solution/1100-1199/1188.Design Bounded Blocking Queue/README.md index b3e52857137d4..ab0b6f7fbaa2e 100644 --- a/solution/1100-1199/1188.Design Bounded Blocking Queue/README.md +++ b/solution/1100-1199/1188.Design Bounded Blocking Queue/README.md @@ -114,6 +114,8 @@ queue.size(); // 队列中还有 1 个元素。 +#### Python3 + ```python from threading import Semaphore @@ -139,6 +141,8 @@ class BoundedBlockingQueue(object): return len(self.q) ``` +#### Java + ```java class BoundedBlockingQueue { private Semaphore s1; @@ -169,6 +173,8 @@ class BoundedBlockingQueue { } ``` +#### C++ + ```cpp #include diff --git a/solution/1100-1199/1188.Design Bounded Blocking Queue/README_EN.md b/solution/1100-1199/1188.Design Bounded Blocking Queue/README_EN.md index a91fed5d117b8..c3aa3a242b475 100644 --- a/solution/1100-1199/1188.Design Bounded Blocking Queue/README_EN.md +++ b/solution/1100-1199/1188.Design Bounded Blocking Queue/README_EN.md @@ -110,6 +110,8 @@ Since the number of threads for producer/consumer is greater than 1, we do not k +#### Python3 + ```python from threading import Semaphore @@ -135,6 +137,8 @@ class BoundedBlockingQueue(object): return len(self.q) ``` +#### Java + ```java class BoundedBlockingQueue { private Semaphore s1; @@ -165,6 +169,8 @@ class BoundedBlockingQueue { } ``` +#### C++ + ```cpp #include diff --git a/solution/1100-1199/1189.Maximum Number of Balloons/README.md b/solution/1100-1199/1189.Maximum Number of Balloons/README.md index 37d3e5d5a12fc..f77995c9cc717 100644 --- a/solution/1100-1199/1189.Maximum Number of Balloons/README.md +++ b/solution/1100-1199/1189.Maximum Number of Balloons/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def maxNumberOfBalloons(self, text: str) -> int: @@ -82,6 +84,8 @@ class Solution: return min(cnt[c] for c in 'balon') ``` +#### Java + ```java class Solution { public int maxNumberOfBalloons(String text) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func maxNumberOfBalloons(text string) int { cnt := [26]int{} @@ -138,6 +146,8 @@ func maxNumberOfBalloons(text string) int { } ``` +#### TypeScript + ```ts function maxNumberOfBalloons(text: string): number { const cnt = new Array(26).fill(0); @@ -148,6 +158,8 @@ function maxNumberOfBalloons(text: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_number_of_balloons(text: String) -> i32 { @@ -183,6 +195,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1100-1199/1189.Maximum Number of Balloons/README_EN.md b/solution/1100-1199/1189.Maximum Number of Balloons/README_EN.md index f878f6a0254e6..85429240195ec 100644 --- a/solution/1100-1199/1189.Maximum Number of Balloons/README_EN.md +++ b/solution/1100-1199/1189.Maximum Number of Balloons/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(n)$, and the space complexity is $O(C)$. Here, $n$ is +#### Python3 + ```python class Solution: def maxNumberOfBalloons(self, text: str) -> int: @@ -83,6 +85,8 @@ class Solution: return min(cnt[c] for c in 'balon') ``` +#### Java + ```java class Solution { public int maxNumberOfBalloons(String text) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func maxNumberOfBalloons(text string) int { cnt := [26]int{} @@ -139,6 +147,8 @@ func maxNumberOfBalloons(text string) int { } ``` +#### TypeScript + ```ts function maxNumberOfBalloons(text: string): number { const cnt = new Array(26).fill(0); @@ -149,6 +159,8 @@ function maxNumberOfBalloons(text: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_number_of_balloons(text: String) -> i32 { @@ -184,6 +196,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1100-1199/1190.Reverse Substrings Between Each Pair of Parentheses/README.md b/solution/1100-1199/1190.Reverse Substrings Between Each Pair of Parentheses/README.md index 994f838709343..fc2e0e6677e9d 100644 --- a/solution/1100-1199/1190.Reverse Substrings Between Each Pair of Parentheses/README.md +++ b/solution/1100-1199/1190.Reverse Substrings Between Each Pair of Parentheses/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def reverseParentheses(self, s: str) -> str: @@ -95,6 +97,8 @@ class Solution: return ''.join(stk) ``` +#### Java + ```java class Solution { public String reverseParentheses(String s) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func reverseParentheses(s string) string { stk := []byte{} @@ -169,6 +177,8 @@ func reverseParentheses(s string) string { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -222,6 +232,8 @@ var reverseParentheses = function (s) { +#### Python3 + ```python class Solution: def reverseParentheses(self, s: str) -> str: @@ -246,6 +258,8 @@ class Solution: return ''.join(ans) ``` +#### C++ + ```cpp class Solution { public: @@ -279,6 +293,8 @@ public: }; ``` +#### Go + ```go func reverseParentheses(s string) string { n := len(s) diff --git a/solution/1100-1199/1190.Reverse Substrings Between Each Pair of Parentheses/README_EN.md b/solution/1100-1199/1190.Reverse Substrings Between Each Pair of Parentheses/README_EN.md index 35c29e0121277..c0bbc391d7f41 100644 --- a/solution/1100-1199/1190.Reverse Substrings Between Each Pair of Parentheses/README_EN.md +++ b/solution/1100-1199/1190.Reverse Substrings Between Each Pair of Parentheses/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(n^2)$, where $n$ is the length of the string $s$. +#### Python3 + ```python class Solution: def reverseParentheses(self, s: str) -> str: @@ -88,6 +90,8 @@ class Solution: return ''.join(stk) ``` +#### Java + ```java class Solution { public String reverseParentheses(String s) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func reverseParentheses(s string) string { stk := []byte{} @@ -162,6 +170,8 @@ func reverseParentheses(s string) string { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -215,6 +225,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string $s$. +#### Python3 + ```python class Solution: def reverseParentheses(self, s: str) -> str: @@ -239,6 +251,8 @@ class Solution: return ''.join(ans) ``` +#### C++ + ```cpp class Solution { public: @@ -272,6 +286,8 @@ public: }; ``` +#### Go + ```go func reverseParentheses(s string) string { n := len(s) diff --git a/solution/1100-1199/1191.K-Concatenation Maximum Sum/README.md b/solution/1100-1199/1191.K-Concatenation Maximum Sum/README.md index 238944dae29be..2bf32c691b5e0 100644 --- a/solution/1100-1199/1191.K-Concatenation Maximum Sum/README.md +++ b/solution/1100-1199/1191.K-Concatenation Maximum Sum/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def kConcatenationMaxSum(self, arr: List[int], k: int) -> int: @@ -105,6 +107,8 @@ class Solution: return ans % mod ``` +#### Java + ```java class Solution { public int kConcatenationMaxSum(int[] arr, int k) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func kConcatenationMaxSum(arr []int, k int) int { var s, mxPre, miPre, mxSub int diff --git a/solution/1100-1199/1191.K-Concatenation Maximum Sum/README_EN.md b/solution/1100-1199/1191.K-Concatenation Maximum Sum/README_EN.md index b6ffc170925d8..b97adc9a1af72 100644 --- a/solution/1100-1199/1191.K-Concatenation Maximum Sum/README_EN.md +++ b/solution/1100-1199/1191.K-Concatenation Maximum Sum/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is +#### Python3 + ```python class Solution: def kConcatenationMaxSum(self, arr: List[int], k: int) -> int: @@ -102,6 +104,8 @@ class Solution: return ans % mod ``` +#### Java + ```java class Solution { public int kConcatenationMaxSum(int[] arr, int k) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func kConcatenationMaxSum(arr []int, k int) int { var s, mxPre, miPre, mxSub int diff --git a/solution/1100-1199/1192.Critical Connections in a Network/README.md b/solution/1100-1199/1192.Critical Connections in a Network/README.md index 70629103fb6d9..80b053772c0ef 100644 --- a/solution/1100-1199/1192.Critical Connections in a Network/README.md +++ b/solution/1100-1199/1192.Critical Connections in a Network/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def criticalConnections( @@ -109,6 +111,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int now; @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go func criticalConnections(n int, connections [][]int) (ans [][]int) { now := 0 @@ -223,6 +231,8 @@ func criticalConnections(n int, connections [][]int) (ans [][]int) { } ``` +#### TypeScript + ```ts function criticalConnections(n: number, connections: number[][]): number[][] { let now: number = 0; diff --git a/solution/1100-1199/1192.Critical Connections in a Network/README_EN.md b/solution/1100-1199/1192.Critical Connections in a Network/README_EN.md index 35ef189ad8f7f..d2d9184470a6e 100644 --- a/solution/1100-1199/1192.Critical Connections in a Network/README_EN.md +++ b/solution/1100-1199/1192.Critical Connections in a Network/README_EN.md @@ -73,6 +73,8 @@ There is an algorithm called the Tarjan algorithm for finding "bridges" and "art +#### Python3 + ```python class Solution: def criticalConnections( @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int now; @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -185,6 +191,8 @@ public: }; ``` +#### Go + ```go func criticalConnections(n int, connections [][]int) (ans [][]int) { now := 0 @@ -220,6 +228,8 @@ func criticalConnections(n int, connections [][]int) (ans [][]int) { } ``` +#### TypeScript + ```ts function criticalConnections(n: number, connections: number[][]): number[][] { let now: number = 0; diff --git a/solution/1100-1199/1193.Monthly Transactions I/README.md b/solution/1100-1199/1193.Monthly Transactions I/README.md index 1fe89cbfad696..3595f969fba05 100644 --- a/solution/1100-1199/1193.Monthly Transactions I/README.md +++ b/solution/1100-1199/1193.Monthly Transactions I/README.md @@ -77,6 +77,8 @@ Transactions table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1100-1199/1193.Monthly Transactions I/README_EN.md b/solution/1100-1199/1193.Monthly Transactions I/README_EN.md index 6ee857b568e93..a6b88585c5e74 100644 --- a/solution/1100-1199/1193.Monthly Transactions I/README_EN.md +++ b/solution/1100-1199/1193.Monthly Transactions I/README_EN.md @@ -77,6 +77,8 @@ We can first group by month and country, and then use the `COUNT` and `SUM` func +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1100-1199/1194.Tournament Winners/README.md b/solution/1100-1199/1194.Tournament Winners/README.md index 254794521dc97..00e8fdff77c57 100644 --- a/solution/1100-1199/1194.Tournament Winners/README.md +++ b/solution/1100-1199/1194.Tournament Winners/README.md @@ -106,6 +106,8 @@ Players 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1100-1199/1194.Tournament Winners/README_EN.md b/solution/1100-1199/1194.Tournament Winners/README_EN.md index f2ff20088ead8..d7a80c3a5224b 100644 --- a/solution/1100-1199/1194.Tournament Winners/README_EN.md +++ b/solution/1100-1199/1194.Tournament Winners/README_EN.md @@ -106,6 +106,8 @@ Matches table: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1100-1199/1195.Fizz Buzz Multithreaded/README.md b/solution/1100-1199/1195.Fizz Buzz Multithreaded/README.md index bcab5be8831e7..0aa17c8ef9389 100644 --- a/solution/1100-1199/1195.Fizz Buzz Multithreaded/README.md +++ b/solution/1100-1199/1195.Fizz Buzz Multithreaded/README.md @@ -66,6 +66,8 @@ class FizzBuzz { +#### Java + ```java class FizzBuzz { private int n; @@ -129,6 +131,8 @@ class FizzBuzz { } ``` +#### C++ + ```cpp class FizzBuzz { private: diff --git a/solution/1100-1199/1195.Fizz Buzz Multithreaded/README_EN.md b/solution/1100-1199/1195.Fizz Buzz Multithreaded/README_EN.md index 71dea943b44ee..4f5dadfc94a39 100644 --- a/solution/1100-1199/1195.Fizz Buzz Multithreaded/README_EN.md +++ b/solution/1100-1199/1195.Fizz Buzz Multithreaded/README_EN.md @@ -78,6 +78,8 @@ tags: +#### Java + ```java class FizzBuzz { private int n; @@ -141,6 +143,8 @@ class FizzBuzz { } ``` +#### C++ + ```cpp class FizzBuzz { private: diff --git a/solution/1100-1199/1196.How Many Apples Can You Put into the Basket/README.md b/solution/1100-1199/1196.How Many Apples Can You Put into the Basket/README.md index fff0c1993af37..0dcc00e2fcc70 100644 --- a/solution/1100-1199/1196.How Many Apples Can You Put into the Basket/README.md +++ b/solution/1100-1199/1196.How Many Apples Can You Put into the Basket/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def maxNumberOfApples(self, weight: List[int]) -> int: @@ -79,6 +81,8 @@ class Solution: return len(weight) ``` +#### Java + ```java class Solution { public int maxNumberOfApples(int[] weight) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func maxNumberOfApples(weight []int) int { sort.Ints(weight) @@ -126,6 +134,8 @@ func maxNumberOfApples(weight []int) int { } ``` +#### TypeScript + ```ts function maxNumberOfApples(weight: number[]): number { weight.sort((a, b) => a - b); diff --git a/solution/1100-1199/1196.How Many Apples Can You Put into the Basket/README_EN.md b/solution/1100-1199/1196.How Many Apples Can You Put into the Basket/README_EN.md index 1933454af57fa..0ba32231190dd 100644 --- a/solution/1100-1199/1196.How Many Apples Can You Put into the Basket/README_EN.md +++ b/solution/1100-1199/1196.How Many Apples Can You Put into the Basket/README_EN.md @@ -65,6 +65,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def maxNumberOfApples(self, weight: List[int]) -> int: @@ -77,6 +79,8 @@ class Solution: return len(weight) ``` +#### Java + ```java class Solution { public int maxNumberOfApples(int[] weight) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func maxNumberOfApples(weight []int) int { sort.Ints(weight) @@ -124,6 +132,8 @@ func maxNumberOfApples(weight []int) int { } ``` +#### TypeScript + ```ts function maxNumberOfApples(weight: number[]): number { weight.sort((a, b) => a - b); diff --git a/solution/1100-1199/1197.Minimum Knight Moves/README.md b/solution/1100-1199/1197.Minimum Knight Moves/README.md index cb2ad030cb04c..bb1ede233fe72 100644 --- a/solution/1100-1199/1197.Minimum Knight Moves/README.md +++ b/solution/1100-1199/1197.Minimum Knight Moves/README.md @@ -74,6 +74,8 @@ BFS 最短路模型。本题搜索空间不大,可以直接使用朴素 BFS, +#### Python3 + ```python class Solution: def minKnightMoves(self, x: int, y: int) -> int: @@ -95,6 +97,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minKnightMoves(int x, int y) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func minKnightMoves(x int, y int) int { x, y = x+310, y+310 @@ -191,6 +199,8 @@ func minKnightMoves(x int, y int) int { } ``` +#### Rust + ```rust use std::collections::VecDeque; @@ -273,6 +283,8 @@ impl Solution { +#### Python3 + ```python class Solution: def minKnightMoves(self, x: int, y: int) -> int: @@ -310,6 +322,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { private int n = 700; @@ -360,6 +374,8 @@ class Solution { } ``` +#### C++ + ```cpp typedef pair PII; @@ -406,6 +422,8 @@ public: }; ``` +#### Go + ```go func minKnightMoves(x int, y int) int { if x == 0 && y == 0 { @@ -451,6 +469,8 @@ func minKnightMoves(x int, y int) int { } ``` +#### Rust + ```rust use std::collections::VecDeque; use std::collections::HashMap; diff --git a/solution/1100-1199/1197.Minimum Knight Moves/README_EN.md b/solution/1100-1199/1197.Minimum Knight Moves/README_EN.md index ec068f9890040..8421d24132dcb 100644 --- a/solution/1100-1199/1197.Minimum Knight Moves/README_EN.md +++ b/solution/1100-1199/1197.Minimum Knight Moves/README_EN.md @@ -68,6 +68,8 @@ Bidirectional BFS is a common optimization method for BFS. The main implementati +#### Python3 + ```python class Solution: def minKnightMoves(self, x: int, y: int) -> int: @@ -89,6 +91,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minKnightMoves(int x, int y) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func minKnightMoves(x int, y int) int { x, y = x+310, y+310 @@ -185,6 +193,8 @@ func minKnightMoves(x int, y int) int { } ``` +#### Rust + ```rust use std::collections::VecDeque; @@ -267,6 +277,8 @@ impl Solution { +#### Python3 + ```python class Solution: def minKnightMoves(self, x: int, y: int) -> int: @@ -304,6 +316,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { private int n = 700; @@ -354,6 +368,8 @@ class Solution { } ``` +#### C++ + ```cpp typedef pair PII; @@ -400,6 +416,8 @@ public: }; ``` +#### Go + ```go func minKnightMoves(x int, y int) int { if x == 0 && y == 0 { @@ -445,6 +463,8 @@ func minKnightMoves(x int, y int) int { } ``` +#### Rust + ```rust use std::collections::VecDeque; use std::collections::HashMap; diff --git a/solution/1100-1199/1198.Find Smallest Common Element in All Rows/README.md b/solution/1100-1199/1198.Find Smallest Common Element in All Rows/README.md index 3463f451a26a2..30c71cc7ca01a 100644 --- a/solution/1100-1199/1198.Find Smallest Common Element in All Rows/README.md +++ b/solution/1100-1199/1198.Find Smallest Common Element in All Rows/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def smallestCommonElement(self, mat: List[List[int]]) -> int: @@ -82,6 +84,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int smallestCommonElement(int[][] mat) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func smallestCommonElement(mat [][]int) int { cnt := [10001]int{} @@ -130,6 +138,8 @@ func smallestCommonElement(mat [][]int) int { } ``` +#### TypeScript + ```ts function smallestCommonElement(mat: number[][]): number { const cnt: number[] = new Array(10001).fill(0); diff --git a/solution/1100-1199/1198.Find Smallest Common Element in All Rows/README_EN.md b/solution/1100-1199/1198.Find Smallest Common Element in All Rows/README_EN.md index 4ff39b79719c2..59f1f734b9794 100644 --- a/solution/1100-1199/1198.Find Smallest Common Element in All Rows/README_EN.md +++ b/solution/1100-1199/1198.Find Smallest Common Element in All Rows/README_EN.md @@ -68,6 +68,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(10^4)$. H +#### Python3 + ```python class Solution: def smallestCommonElement(self, mat: List[List[int]]) -> int: @@ -80,6 +82,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int smallestCommonElement(int[][] mat) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func smallestCommonElement(mat [][]int) int { cnt := [10001]int{} @@ -128,6 +136,8 @@ func smallestCommonElement(mat [][]int) int { } ``` +#### TypeScript + ```ts function smallestCommonElement(mat: number[][]): number { const cnt: number[] = new Array(10001).fill(0); diff --git a/solution/1100-1199/1199.Minimum Time to Build Blocks/README.md b/solution/1100-1199/1199.Minimum Time to Build Blocks/README.md index 46716f63ff8db..caa6577b2e902 100644 --- a/solution/1100-1199/1199.Minimum Time to Build Blocks/README.md +++ b/solution/1100-1199/1199.Minimum Time to Build Blocks/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def minBuildTime(self, blocks: List[int], split: int) -> int: @@ -101,6 +103,8 @@ class Solution: return blocks[0] ``` +#### Java + ```java class Solution { public int minBuildTime(int[] blocks, int split) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func minBuildTime(blocks []int, split int) int { q := hp{} @@ -158,6 +166,8 @@ func (h *hp) Pop() any { } ``` +#### TypeScript + ```ts function minBuildTime(blocks: number[], split: number): number { const pq = new MinPriorityQueue(); @@ -172,6 +182,8 @@ function minBuildTime(blocks: number[], split: number): number { } ``` +#### Rust + ```rust use std::collections::BinaryHeap; use std::cmp::Reverse; diff --git a/solution/1100-1199/1199.Minimum Time to Build Blocks/README_EN.md b/solution/1100-1199/1199.Minimum Time to Build Blocks/README_EN.md index 2614974b9f8ce..898fce0d8b6b6 100644 --- a/solution/1100-1199/1199.Minimum Time to Build Blocks/README_EN.md +++ b/solution/1100-1199/1199.Minimum Time to Build Blocks/README_EN.md @@ -89,6 +89,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def minBuildTime(self, blocks: List[int], split: int) -> int: @@ -99,6 +101,8 @@ class Solution: return blocks[0] ``` +#### Java + ```java class Solution { public int minBuildTime(int[] blocks, int split) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func minBuildTime(blocks []int, split int) int { q := hp{} @@ -156,6 +164,8 @@ func (h *hp) Pop() any { } ``` +#### TypeScript + ```ts function minBuildTime(blocks: number[], split: number): number { const pq = new MinPriorityQueue(); @@ -170,6 +180,8 @@ function minBuildTime(blocks: number[], split: number): number { } ``` +#### Rust + ```rust use std::collections::BinaryHeap; use std::cmp::Reverse; diff --git a/solution/1200-1299/1200.Minimum Absolute Difference/README.md b/solution/1200-1299/1200.Minimum Absolute Difference/README.md index d4ecbd2903d0e..60ef6fccb338b 100644 --- a/solution/1200-1299/1200.Minimum Absolute Difference/README.md +++ b/solution/1200-1299/1200.Minimum Absolute Difference/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def minimumAbsDifference(self, arr: List[int]) -> List[List[int]]: @@ -87,6 +89,8 @@ class Solution: return [[a, b] for a, b in pairwise(arr) if b - a == mi] ``` +#### Java + ```java class Solution { public List> minimumAbsDifference(int[] arr) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func minimumAbsDifference(arr []int) (ans [][]int) { sort.Ints(arr) @@ -147,6 +155,8 @@ func minimumAbsDifference(arr []int) (ans [][]int) { } ``` +#### TypeScript + ```ts function minimumAbsDifference(arr: number[]): number[][] { arr.sort((a, b) => a - b); diff --git a/solution/1200-1299/1200.Minimum Absolute Difference/README_EN.md b/solution/1200-1299/1200.Minimum Absolute Difference/README_EN.md index 255e1f10b815f..7da439621a8e4 100644 --- a/solution/1200-1299/1200.Minimum Absolute Difference/README_EN.md +++ b/solution/1200-1299/1200.Minimum Absolute Difference/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def minimumAbsDifference(self, arr: List[int]) -> List[List[int]]: @@ -83,6 +85,8 @@ class Solution: return [[a, b] for a, b in pairwise(arr) if b - a == mi] ``` +#### Java + ```java class Solution { public List> minimumAbsDifference(int[] arr) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func minimumAbsDifference(arr []int) (ans [][]int) { sort.Ints(arr) @@ -143,6 +151,8 @@ func minimumAbsDifference(arr []int) (ans [][]int) { } ``` +#### TypeScript + ```ts function minimumAbsDifference(arr: number[]): number[][] { arr.sort((a, b) => a - b); diff --git a/solution/1200-1299/1201.Ugly Number III/README.md b/solution/1200-1299/1201.Ugly Number III/README.md index 7b7678aaf0d77..a099edf22c601 100644 --- a/solution/1200-1299/1201.Ugly Number III/README.md +++ b/solution/1200-1299/1201.Ugly Number III/README.md @@ -84,6 +84,8 @@ $$ +#### Python3 + ```python class Solution: def nthUglyNumber(self, n: int, a: int, b: int, c: int) -> int: @@ -110,6 +112,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { public int nthUglyNumber(int n, int a, int b, int c) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go func nthUglyNumber(n int, a int, b int, c int) int { ab, bc, ac := lcm(a, b), lcm(b, c), lcm(a, c) @@ -197,6 +205,8 @@ func lcm(a, b int) int { } ``` +#### TypeScript + ```ts function nthUglyNumber(n: number, a: number, b: number, c: number): number { const ab = lcm(BigInt(a), BigInt(b)); diff --git a/solution/1200-1299/1201.Ugly Number III/README_EN.md b/solution/1200-1299/1201.Ugly Number III/README_EN.md index 2ebc14b629465..718ac1b10890c 100644 --- a/solution/1200-1299/1201.Ugly Number III/README_EN.md +++ b/solution/1200-1299/1201.Ugly Number III/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(\log m)$, where $m = 2 \times 10^9$. The space complex +#### Python3 + ```python class Solution: def nthUglyNumber(self, n: int, a: int, b: int, c: int) -> int: @@ -109,6 +111,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { public int nthUglyNumber(int n, int a, int b, int c) { @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func nthUglyNumber(n int, a int, b int, c int) int { ab, bc, ac := lcm(a, b), lcm(b, c), lcm(a, c) @@ -196,6 +204,8 @@ func lcm(a, b int) int { } ``` +#### TypeScript + ```ts function nthUglyNumber(n: number, a: number, b: number, c: number): number { const ab = lcm(BigInt(a), BigInt(b)); diff --git a/solution/1200-1299/1202.Smallest String With Swaps/README.md b/solution/1200-1299/1202.Smallest String With Swaps/README.md index 3ed9b55c2361b..7da5a7e91ece5 100644 --- a/solution/1200-1299/1202.Smallest String With Swaps/README.md +++ b/solution/1200-1299/1202.Smallest String With Swaps/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def smallestStringWithSwaps(self, s: str, pairs: List[List[int]]) -> str: @@ -107,6 +109,8 @@ class Solution: return "".join(d[find(i)].pop() for i in range(n)) ``` +#### Java + ```java class Solution { private int[] p; @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -180,6 +186,8 @@ public: }; ``` +#### Go + ```go func smallestStringWithSwaps(s string, pairs [][]int) string { n := len(s) @@ -216,6 +224,8 @@ func smallestStringWithSwaps(s string, pairs [][]int) string { } ``` +#### TypeScript + ```ts function smallestStringWithSwaps(s: string, pairs: number[][]): string { const n = s.length; @@ -244,6 +254,8 @@ function smallestStringWithSwaps(s: string, pairs: number[][]): string { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/1200-1299/1202.Smallest String With Swaps/README_EN.md b/solution/1200-1299/1202.Smallest String With Swaps/README_EN.md index a71120e72e979..c5c0d305a95db 100644 --- a/solution/1200-1299/1202.Smallest String With Swaps/README_EN.md +++ b/solution/1200-1299/1202.Smallest String With Swaps/README_EN.md @@ -88,6 +88,8 @@ The time complexity is $O(n \times \log n + m \times \alpha(m))$, and the space +#### Python3 + ```python class Solution: def smallestStringWithSwaps(self, s: str, pairs: List[List[int]]) -> str: @@ -108,6 +110,8 @@ class Solution: return "".join(d[find(i)].pop() for i in range(n)) ``` +#### Java + ```java class Solution { private int[] p; @@ -147,6 +151,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func smallestStringWithSwaps(s string, pairs [][]int) string { n := len(s) @@ -217,6 +225,8 @@ func smallestStringWithSwaps(s string, pairs [][]int) string { } ``` +#### TypeScript + ```ts function smallestStringWithSwaps(s: string, pairs: number[][]): string { const n = s.length; @@ -245,6 +255,8 @@ function smallestStringWithSwaps(s: string, pairs: number[][]): string { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/1200-1299/1203.Sort Items by Groups Respecting Dependencies/README.md b/solution/1200-1299/1203.Sort Items by Groups Respecting Dependencies/README.md index f85729ad69d56..c7f16a1b66bf7 100644 --- a/solution/1200-1299/1203.Sort Items by Groups Respecting Dependencies/README.md +++ b/solution/1200-1299/1203.Sort Items by Groups Respecting Dependencies/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def sortItems( @@ -135,6 +137,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] sortItems(int n, int m, int[] group, List> beforeItems) { @@ -206,6 +210,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -273,6 +279,8 @@ public: }; ``` +#### Go + ```go func sortItems(n int, m int, group []int, beforeItems [][]int) []int { idx := m @@ -342,6 +350,8 @@ func sortItems(n int, m int, group []int, beforeItems [][]int) []int { } ``` +#### TypeScript + ```ts function sortItems(n: number, m: number, group: number[], beforeItems: number[][]): number[] { let idx = m; diff --git a/solution/1200-1299/1203.Sort Items by Groups Respecting Dependencies/README_EN.md b/solution/1200-1299/1203.Sort Items by Groups Respecting Dependencies/README_EN.md index 07bba24ff1c97..c21a688148c7b 100644 --- a/solution/1200-1299/1203.Sort Items by Groups Respecting Dependencies/README_EN.md +++ b/solution/1200-1299/1203.Sort Items by Groups Respecting Dependencies/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(n + m)$, and the space complexity is $O(n + m)$. Here, +#### Python3 + ```python class Solution: def sortItems( @@ -133,6 +135,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] sortItems(int n, int m, int[] group, List> beforeItems) { @@ -204,6 +208,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -271,6 +277,8 @@ public: }; ``` +#### Go + ```go func sortItems(n int, m int, group []int, beforeItems [][]int) []int { idx := m @@ -340,6 +348,8 @@ func sortItems(n int, m int, group []int, beforeItems [][]int) []int { } ``` +#### TypeScript + ```ts function sortItems(n: number, m: number, group: number[], beforeItems: number[][]): number[] { let idx = m; diff --git a/solution/1200-1299/1204.Last Person to Fit in the Bus/README.md b/solution/1200-1299/1204.Last Person to Fit in the Bus/README.md index f0d353264c871..75e249adb68fe 100644 --- a/solution/1200-1299/1204.Last Person to Fit in the Bus/README.md +++ b/solution/1200-1299/1204.Last Person to Fit in the Bus/README.md @@ -88,6 +88,8 @@ Queue 表 +#### MySQL + ```sql # Write your MySQL query statement below SELECT a.person_name @@ -111,6 +113,8 @@ LIMIT 1; +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1200-1299/1204.Last Person to Fit in the Bus/README_EN.md b/solution/1200-1299/1204.Last Person to Fit in the Bus/README_EN.md index 9c64c222aa7d8..ec7cc37aada68 100644 --- a/solution/1200-1299/1204.Last Person to Fit in the Bus/README_EN.md +++ b/solution/1200-1299/1204.Last Person to Fit in the Bus/README_EN.md @@ -87,6 +87,8 @@ Queue table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT a.person_name @@ -110,6 +112,8 @@ LIMIT 1; +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1200-1299/1205.Monthly Transactions II/README.md b/solution/1200-1299/1205.Monthly Transactions II/README.md index a181a7b34ed16..85fb0c98af4b9 100644 --- a/solution/1200-1299/1205.Monthly Transactions II/README.md +++ b/solution/1200-1299/1205.Monthly Transactions II/README.md @@ -98,6 +98,8 @@ Chargebacks 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1200-1299/1205.Monthly Transactions II/README_EN.md b/solution/1200-1299/1205.Monthly Transactions II/README_EN.md index 27232546436f3..669a7c33dd951 100644 --- a/solution/1200-1299/1205.Monthly Transactions II/README_EN.md +++ b/solution/1200-1299/1205.Monthly Transactions II/README_EN.md @@ -99,6 +99,8 @@ Chargebacks table: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1200-1299/1206.Design Skiplist/README.md b/solution/1200-1299/1206.Design Skiplist/README.md index 0e4fef764e742..b2c08dd6a9ce7 100644 --- a/solution/1200-1299/1206.Design Skiplist/README.md +++ b/solution/1200-1299/1206.Design Skiplist/README.md @@ -84,6 +84,8 @@ skiplist.search(1); // 返回 false,1 已被擦除 +#### Python3 + ```python class Node: __slots__ = ['val', 'next'] @@ -151,6 +153,8 @@ class Skiplist: # param_3 = obj.erase(num) ``` +#### Java + ```java class Skiplist { private static final int MAX_LEVEL = 32; @@ -238,6 +242,8 @@ class Skiplist { */ ``` +#### C++ + ```cpp struct Node { int val; @@ -317,6 +323,8 @@ public: */ ``` +#### Go + ```go func init() { rand.Seed(time.Now().UnixNano()) } diff --git a/solution/1200-1299/1206.Design Skiplist/README_EN.md b/solution/1200-1299/1206.Design Skiplist/README_EN.md index 8ced5ab96765d..3406f42dfb6a9 100644 --- a/solution/1200-1299/1206.Design Skiplist/README_EN.md +++ b/solution/1200-1299/1206.Design Skiplist/README_EN.md @@ -81,6 +81,8 @@ skiplist.search(1); // return False, 1 has already been erased. +#### Python3 + ```python class Node: __slots__ = ['val', 'next'] @@ -148,6 +150,8 @@ class Skiplist: # param_3 = obj.erase(num) ``` +#### Java + ```java class Skiplist { private static final int MAX_LEVEL = 32; @@ -235,6 +239,8 @@ class Skiplist { */ ``` +#### C++ + ```cpp struct Node { int val; @@ -314,6 +320,8 @@ public: */ ``` +#### Go + ```go func init() { rand.Seed(time.Now().UnixNano()) } diff --git a/solution/1200-1299/1207.Unique Number of Occurrences/README.md b/solution/1200-1299/1207.Unique Number of Occurrences/README.md index 8158c28c7d865..726c5c2fcc85c 100644 --- a/solution/1200-1299/1207.Unique Number of Occurrences/README.md +++ b/solution/1200-1299/1207.Unique Number of Occurrences/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def uniqueOccurrences(self, arr: List[int]) -> bool: @@ -73,6 +75,8 @@ class Solution: return len(set(cnt.values())) == len(cnt) ``` +#### Java + ```java class Solution { public boolean uniqueOccurrences(int[] arr) { @@ -85,6 +89,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func uniqueOccurrences(arr []int) bool { cnt := map[int]int{} @@ -122,6 +130,8 @@ func uniqueOccurrences(arr []int) bool { } ``` +#### TypeScript + ```ts function uniqueOccurrences(arr: number[]): boolean { const cnt: Map = new Map(); diff --git a/solution/1200-1299/1207.Unique Number of Occurrences/README_EN.md b/solution/1200-1299/1207.Unique Number of Occurrences/README_EN.md index fbc9713c1f455..e5b924ff2e773 100644 --- a/solution/1200-1299/1207.Unique Number of Occurrences/README_EN.md +++ b/solution/1200-1299/1207.Unique Number of Occurrences/README_EN.md @@ -65,6 +65,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def uniqueOccurrences(self, arr: List[int]) -> bool: @@ -72,6 +74,8 @@ class Solution: return len(set(cnt.values())) == len(cnt) ``` +#### Java + ```java class Solution { public boolean uniqueOccurrences(int[] arr) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -104,6 +110,8 @@ public: }; ``` +#### Go + ```go func uniqueOccurrences(arr []int) bool { cnt := map[int]int{} @@ -121,6 +129,8 @@ func uniqueOccurrences(arr []int) bool { } ``` +#### TypeScript + ```ts function uniqueOccurrences(arr: number[]): boolean { const cnt: Map = new Map(); diff --git a/solution/1200-1299/1208.Get Equal Substrings Within Budget/README.md b/solution/1200-1299/1208.Get Equal Substrings Within Budget/README.md index 1d67ce2c37286..d0ede68aadf0d 100644 --- a/solution/1200-1299/1208.Get Equal Substrings Within Budget/README.md +++ b/solution/1200-1299/1208.Get Equal Substrings Within Budget/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def equalSubstring(self, s: str, t: str, maxCost: int) -> int: @@ -108,6 +110,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { private int maxCost; @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -179,6 +185,8 @@ public: }; ``` +#### Go + ```go func equalSubstring(s string, t string, maxCost int) int { n := len(s) @@ -230,6 +238,8 @@ func abs(x int) int { +#### Python3 + ```python class Solution: def equalSubstring(self, s: str, t: str, maxCost: int) -> int: @@ -245,6 +255,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int equalSubstring(String s, String t, int maxCost) { @@ -264,6 +276,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -283,6 +297,8 @@ public: }; ``` +#### Go + ```go func equalSubstring(s string, t string, maxCost int) (ans int) { var sum, j int diff --git a/solution/1200-1299/1208.Get Equal Substrings Within Budget/README_EN.md b/solution/1200-1299/1208.Get Equal Substrings Within Budget/README_EN.md index 5cc0a8b5c943b..ee7ed2c0ce415 100644 --- a/solution/1200-1299/1208.Get Equal Substrings Within Budget/README_EN.md +++ b/solution/1200-1299/1208.Get Equal Substrings Within Budget/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def equalSubstring(self, s: str, t: str, maxCost: int) -> int: @@ -105,6 +107,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { private int maxCost; @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go func equalSubstring(s string, t string, maxCost int) int { n := len(s) @@ -227,6 +235,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is +#### Python3 + ```python class Solution: def equalSubstring(self, s: str, t: str, maxCost: int) -> int: @@ -242,6 +252,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int equalSubstring(String s, String t, int maxCost) { @@ -261,6 +273,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -280,6 +294,8 @@ public: }; ``` +#### Go + ```go func equalSubstring(s string, t string, maxCost int) (ans int) { var sum, j int diff --git a/solution/1200-1299/1209.Remove All Adjacent Duplicates in String II/README.md b/solution/1200-1299/1209.Remove All Adjacent Duplicates in String II/README.md index f82e1bad0970f..2800d2e412879 100644 --- a/solution/1200-1299/1209.Remove All Adjacent Duplicates in String II/README.md +++ b/solution/1200-1299/1209.Remove All Adjacent Duplicates in String II/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def removeDuplicates(self, s: str, k: int) -> str: @@ -98,6 +100,8 @@ class Solution: return "".join(ans) ``` +#### Java + ```java class Solution { public String removeDuplicates(String s, int k) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func removeDuplicates(s string, k int) string { stk := []pair{} @@ -188,6 +196,8 @@ type pair struct { +#### Python3 + ```python class Solution: def removeDuplicates(self, s: str, k: int) -> str: diff --git a/solution/1200-1299/1209.Remove All Adjacent Duplicates in String II/README_EN.md b/solution/1200-1299/1209.Remove All Adjacent Duplicates in String II/README_EN.md index 95a2f6bbcb9d1..bda61eb710715 100644 --- a/solution/1200-1299/1209.Remove All Adjacent Duplicates in String II/README_EN.md +++ b/solution/1200-1299/1209.Remove All Adjacent Duplicates in String II/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def removeDuplicates(self, s: str, k: int) -> str: @@ -97,6 +99,8 @@ class Solution: return "".join(ans) ``` +#### Java + ```java class Solution { public String removeDuplicates(String s, int k) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func removeDuplicates(s string, k int) string { stk := []pair{} @@ -187,6 +195,8 @@ type pair struct { +#### Python3 + ```python class Solution: def removeDuplicates(self, s: str, k: int) -> str: diff --git a/solution/1200-1299/1210.Minimum Moves to Reach Target with Rotations/README.md b/solution/1200-1299/1210.Minimum Moves to Reach Target with Rotations/README.md index a64f150001ab0..47197d298a0f2 100644 --- a/solution/1200-1299/1210.Minimum Moves to Reach Target with Rotations/README.md +++ b/solution/1200-1299/1210.Minimum Moves to Reach Target with Rotations/README.md @@ -102,6 +102,8 @@ tags: +#### Python3 + ```python class Solution: def minimumMoves(self, grid: List[List[int]]) -> int: @@ -139,6 +141,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { private int n; @@ -193,6 +197,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -247,6 +253,8 @@ public: }; ``` +#### Go + ```go func minimumMoves(grid [][]int) int { n := len(grid) @@ -300,6 +308,8 @@ func minimumMoves(grid [][]int) int { } ``` +#### TypeScript + ```ts function minimumMoves(grid: number[][]): number { const n = grid.length; @@ -348,6 +358,8 @@ function minimumMoves(grid: number[][]): number { } ``` +#### JavaScript + ```js /** * @param {number[][]} grid diff --git a/solution/1200-1299/1210.Minimum Moves to Reach Target with Rotations/README_EN.md b/solution/1200-1299/1210.Minimum Moves to Reach Target with Rotations/README_EN.md index 6c0a3250c5813..d3b5859f7ac58 100644 --- a/solution/1200-1299/1210.Minimum Moves to Reach Target with Rotations/README_EN.md +++ b/solution/1200-1299/1210.Minimum Moves to Reach Target with Rotations/README_EN.md @@ -100,6 +100,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$. Here, $n$ +#### Python3 + ```python class Solution: def minimumMoves(self, grid: List[List[int]]) -> int: @@ -137,6 +139,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { private int n; @@ -191,6 +195,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -245,6 +251,8 @@ public: }; ``` +#### Go + ```go func minimumMoves(grid [][]int) int { n := len(grid) @@ -298,6 +306,8 @@ func minimumMoves(grid [][]int) int { } ``` +#### TypeScript + ```ts function minimumMoves(grid: number[][]): number { const n = grid.length; @@ -346,6 +356,8 @@ function minimumMoves(grid: number[][]): number { } ``` +#### JavaScript + ```js /** * @param {number[][]} grid diff --git a/solution/1200-1299/1211.Queries Quality and Percentage/README.md b/solution/1200-1299/1211.Queries Quality and Percentage/README.md index 783ab497f9746..c94892bd1498e 100644 --- a/solution/1200-1299/1211.Queries Quality and Percentage/README.md +++ b/solution/1200-1299/1211.Queries Quality and Percentage/README.md @@ -99,6 +99,8 @@ Cat 查询结果的劣质查询百分比为 (1 / 3) * 100 = 33.33 +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -110,6 +112,8 @@ WHERE query_name IS NOT NULL GROUP BY 1; ``` +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1200-1299/1211.Queries Quality and Percentage/README_EN.md b/solution/1200-1299/1211.Queries Quality and Percentage/README_EN.md index f008d146542c5..7375316b324fb 100644 --- a/solution/1200-1299/1211.Queries Quality and Percentage/README_EN.md +++ b/solution/1200-1299/1211.Queries Quality and Percentage/README_EN.md @@ -98,6 +98,8 @@ We can group the query results by `query_name`, and then use the `AVG` and `ROUN +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -109,6 +111,8 @@ WHERE query_name IS NOT NULL GROUP BY 1; ``` +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1200-1299/1212.Team Scores in Football Tournament/README.md b/solution/1200-1299/1212.Team Scores in Football Tournament/README.md index c6d5e786963fc..726983f4e0456 100644 --- a/solution/1200-1299/1212.Team Scores in Football Tournament/README.md +++ b/solution/1200-1299/1212.Team Scores in Football Tournament/README.md @@ -121,6 +121,8 @@ Teams table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1200-1299/1212.Team Scores in Football Tournament/README_EN.md b/solution/1200-1299/1212.Team Scores in Football Tournament/README_EN.md index 7a355aae9c355..a9f56cc9a3129 100644 --- a/solution/1200-1299/1212.Team Scores in Football Tournament/README_EN.md +++ b/solution/1200-1299/1212.Team Scores in Football Tournament/README_EN.md @@ -120,6 +120,8 @@ Finally, we sort the result by points in descending order, and if the points are +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1200-1299/1213.Intersection of Three Sorted Arrays/README.md b/solution/1200-1299/1213.Intersection of Three Sorted Arrays/README.md index 405cb231275fc..58a5890306427 100644 --- a/solution/1200-1299/1213.Intersection of Three Sorted Arrays/README.md +++ b/solution/1200-1299/1213.Intersection of Three Sorted Arrays/README.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def arraysIntersection( @@ -72,6 +74,8 @@ class Solution: return [x for x in arr1 if cnt[x] == 3] ``` +#### Java + ```java class Solution { public List arraysIntersection(int[] arr1, int[] arr2, int[] arr3) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func arraysIntersection(arr1 []int, arr2 []int, arr3 []int) (ans []int) { cnt := [2001]int{} @@ -134,6 +142,8 @@ func arraysIntersection(arr1 []int, arr2 []int, arr3 []int) (ans []int) { } ``` +#### PHP + ```php class Solution { /** @@ -170,6 +180,8 @@ class Solution { +#### Python3 + ```python class Solution: def arraysIntersection( @@ -184,6 +196,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List arraysIntersection(int[] arr1, int[] arr2, int[] arr3) { @@ -200,6 +214,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -217,6 +233,8 @@ public: }; ``` +#### Go + ```go func arraysIntersection(arr1 []int, arr2 []int, arr3 []int) (ans []int) { for _, x := range arr1 { diff --git a/solution/1200-1299/1213.Intersection of Three Sorted Arrays/README_EN.md b/solution/1200-1299/1213.Intersection of Three Sorted Arrays/README_EN.md index eaf6bf093244d..7d7d32d28c3c5 100644 --- a/solution/1200-1299/1213.Intersection of Three Sorted Arrays/README_EN.md +++ b/solution/1200-1299/1213.Intersection of Three Sorted Arrays/README_EN.md @@ -61,6 +61,8 @@ The time complexity is $O(n)$, and the space complexity is $O(m)$. Here, $n$ and +#### Python3 + ```python class Solution: def arraysIntersection( @@ -70,6 +72,8 @@ class Solution: return [x for x in arr1 if cnt[x] == 3] ``` +#### Java + ```java class Solution { public List arraysIntersection(int[] arr1, int[] arr2, int[] arr3) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func arraysIntersection(arr1 []int, arr2 []int, arr3 []int) (ans []int) { cnt := [2001]int{} @@ -132,6 +140,8 @@ func arraysIntersection(arr1 []int, arr2 []int, arr3 []int) (ans []int) { } ``` +#### PHP + ```php class Solution { /** @@ -168,6 +178,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def arraysIntersection( @@ -182,6 +194,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List arraysIntersection(int[] arr1, int[] arr2, int[] arr3) { @@ -198,6 +212,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -215,6 +231,8 @@ public: }; ``` +#### Go + ```go func arraysIntersection(arr1 []int, arr2 []int, arr3 []int) (ans []int) { for _, x := range arr1 { diff --git a/solution/1200-1299/1214.Two Sum BSTs/README.md b/solution/1200-1299/1214.Two Sum BSTs/README.md index 6cb8f67e8bbbe..66f31ae0c3754 100644 --- a/solution/1200-1299/1214.Two Sum BSTs/README.md +++ b/solution/1200-1299/1214.Two Sum BSTs/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -108,6 +110,8 @@ class Solution: return False ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -157,6 +161,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -200,6 +206,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -238,6 +246,8 @@ func twoSumBSTs(root1 *TreeNode, root2 *TreeNode, target int) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/1200-1299/1214.Two Sum BSTs/README_EN.md b/solution/1200-1299/1214.Two Sum BSTs/README_EN.md index afa137a893a4a..1650bf410f147 100644 --- a/solution/1200-1299/1214.Two Sum BSTs/README_EN.md +++ b/solution/1200-1299/1214.Two Sum BSTs/README_EN.md @@ -68,6 +68,8 @@ The time complexity is $O(m + n)$, and the space complexity is $O(m + n)$. Here, +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -101,6 +103,8 @@ class Solution: return False ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -231,6 +239,8 @@ func twoSumBSTs(root1 *TreeNode, root2 *TreeNode, target int) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/1200-1299/1215.Stepping Numbers/README.md b/solution/1200-1299/1215.Stepping Numbers/README.md index 07f3e212cae90..b074b3d0f53ff 100644 --- a/solution/1200-1299/1215.Stepping Numbers/README.md +++ b/solution/1200-1299/1215.Stepping Numbers/README.md @@ -57,6 +57,8 @@ tags: +#### Python3 + ```python class Solution: def countSteppingNumbers(self, low: int, high: int) -> List[int]: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List countSteppingNumbers(int low, int high) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func countSteppingNumbers(low int, high int) []int { ans := []int{} @@ -172,6 +180,8 @@ func countSteppingNumbers(low int, high int) []int { } ``` +#### TypeScript + ```ts function countSteppingNumbers(low: number, high: number): number[] { const ans: number[] = []; diff --git a/solution/1200-1299/1215.Stepping Numbers/README_EN.md b/solution/1200-1299/1215.Stepping Numbers/README_EN.md index 0b8520b28fc67..0480a67192d7a 100644 --- a/solution/1200-1299/1215.Stepping Numbers/README_EN.md +++ b/solution/1200-1299/1215.Stepping Numbers/README_EN.md @@ -65,6 +65,8 @@ The time complexity is $O(10 \times 2^{\log M})$, and the space complexity is $O +#### Python3 + ```python class Solution: def countSteppingNumbers(self, low: int, high: int) -> List[int]: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List countSteppingNumbers(int low, int high) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func countSteppingNumbers(low int, high int) []int { ans := []int{} @@ -180,6 +188,8 @@ func countSteppingNumbers(low int, high int) []int { } ``` +#### TypeScript + ```ts function countSteppingNumbers(low: number, high: number): number[] { const ans: number[] = []; diff --git a/solution/1200-1299/1216.Valid Palindrome III/README.md b/solution/1200-1299/1216.Valid Palindrome III/README.md index 397eee1c2f3b8..30b52e6d455ef 100644 --- a/solution/1200-1299/1216.Valid Palindrome III/README.md +++ b/solution/1200-1299/1216.Valid Palindrome III/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def isValidPalindrome(self, s: str, k: int) -> bool: @@ -90,6 +92,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean isValidPalindrome(String s, int k) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func isValidPalindrome(s string, k int) bool { n := len(s) @@ -166,6 +174,8 @@ func isValidPalindrome(s string, k int) bool { } ``` +#### TypeScript + ```ts function isValidPalindrome(s: string, k: number): boolean { const n = s.length; @@ -189,6 +199,8 @@ function isValidPalindrome(s: string, k: number): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn is_valid_palindrome(s: String, k: i32) -> bool { diff --git a/solution/1200-1299/1216.Valid Palindrome III/README_EN.md b/solution/1200-1299/1216.Valid Palindrome III/README_EN.md index a830b7d4923b5..dbba894276b80 100644 --- a/solution/1200-1299/1216.Valid Palindrome III/README_EN.md +++ b/solution/1200-1299/1216.Valid Palindrome III/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$. Here, $n$ +#### Python3 + ```python class Solution: def isValidPalindrome(self, s: str, k: int) -> bool: @@ -88,6 +90,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean isValidPalindrome(String s, int k) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func isValidPalindrome(s string, k int) bool { n := len(s) @@ -164,6 +172,8 @@ func isValidPalindrome(s string, k int) bool { } ``` +#### TypeScript + ```ts function isValidPalindrome(s: string, k: number): boolean { const n = s.length; @@ -187,6 +197,8 @@ function isValidPalindrome(s: string, k: number): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn is_valid_palindrome(s: String, k: i32) -> bool { diff --git a/solution/1200-1299/1217.Minimum Cost to Move Chips to The Same Position/README.md b/solution/1200-1299/1217.Minimum Cost to Move Chips to The Same Position/README.md index 1565d3bd85fab..a2772d267dc38 100644 --- a/solution/1200-1299/1217.Minimum Cost to Move Chips to The Same Position/README.md +++ b/solution/1200-1299/1217.Minimum Cost to Move Chips to The Same Position/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def minCostToMoveChips(self, position: List[int]) -> int: @@ -95,6 +97,8 @@ class Solution: return min(a, b) ``` +#### Java + ```java class Solution { public int minCostToMoveChips(int[] position) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func minCostToMoveChips(position []int) int { a := 0 @@ -134,6 +142,8 @@ func minCostToMoveChips(position []int) int { } ``` +#### JavaScript + ```js /** * @param {number[]} position diff --git a/solution/1200-1299/1217.Minimum Cost to Move Chips to The Same Position/README_EN.md b/solution/1200-1299/1217.Minimum Cost to Move Chips to The Same Position/README_EN.md index 820fd22b9ce62..8a4a4233da666 100644 --- a/solution/1200-1299/1217.Minimum Cost to Move Chips to The Same Position/README_EN.md +++ b/solution/1200-1299/1217.Minimum Cost to Move Chips to The Same Position/README_EN.md @@ -79,6 +79,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is +#### Python3 + ```python class Solution: def minCostToMoveChips(self, position: List[int]) -> int: @@ -87,6 +89,8 @@ class Solution: return min(a, b) ``` +#### Java + ```java class Solution { public int minCostToMoveChips(int[] position) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func minCostToMoveChips(position []int) int { a := 0 @@ -126,6 +134,8 @@ func minCostToMoveChips(position []int) int { } ``` +#### JavaScript + ```js /** * @param {number[]} position diff --git a/solution/1200-1299/1218.Longest Arithmetic Subsequence of Given Difference/README.md b/solution/1200-1299/1218.Longest Arithmetic Subsequence of Given Difference/README.md index aa1a41e1a3108..fd82a5c13f2c5 100644 --- a/solution/1200-1299/1218.Longest Arithmetic Subsequence of Given Difference/README.md +++ b/solution/1200-1299/1218.Longest Arithmetic Subsequence of Given Difference/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def longestSubsequence(self, arr: List[int], difference: int) -> int: @@ -79,6 +81,8 @@ class Solution: return max(f.values()) ``` +#### Java + ```java class Solution { public int longestSubsequence(int[] arr, int difference) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func longestSubsequence(arr []int, difference int) (ans int) { f := map[int]int{} @@ -119,6 +127,8 @@ func longestSubsequence(arr []int, difference int) (ans int) { } ``` +#### TypeScript + ```ts function longestSubsequence(arr: number[], difference: number): number { const f: Map = new Map(); @@ -129,6 +139,8 @@ function longestSubsequence(arr: number[], difference: number): number { } ``` +#### JavaScript + ```js /** * @param {number[]} arr diff --git a/solution/1200-1299/1218.Longest Arithmetic Subsequence of Given Difference/README_EN.md b/solution/1200-1299/1218.Longest Arithmetic Subsequence of Given Difference/README_EN.md index 166f5777b2634..5f980ac66758e 100644 --- a/solution/1200-1299/1218.Longest Arithmetic Subsequence of Given Difference/README_EN.md +++ b/solution/1200-1299/1218.Longest Arithmetic Subsequence of Given Difference/README_EN.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def longestSubsequence(self, arr: List[int], difference: int) -> int: @@ -75,6 +77,8 @@ class Solution: return max(f.values()) ``` +#### Java + ```java class Solution { public int longestSubsequence(int[] arr, int difference) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -104,6 +110,8 @@ public: }; ``` +#### Go + ```go func longestSubsequence(arr []int, difference int) (ans int) { f := map[int]int{} @@ -115,6 +123,8 @@ func longestSubsequence(arr []int, difference int) (ans int) { } ``` +#### TypeScript + ```ts function longestSubsequence(arr: number[], difference: number): number { const f: Map = new Map(); @@ -125,6 +135,8 @@ function longestSubsequence(arr: number[], difference: number): number { } ``` +#### JavaScript + ```js /** * @param {number[]} arr diff --git a/solution/1200-1299/1219.Path with Maximum Gold/README.md b/solution/1200-1299/1219.Path with Maximum Gold/README.md index 397a5f343f1a3..4439347aff475 100644 --- a/solution/1200-1299/1219.Path with Maximum Gold/README.md +++ b/solution/1200-1299/1219.Path with Maximum Gold/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: @@ -99,6 +101,8 @@ class Solution: return max(dfs(i, j) for i in range(m) for j in range(n)) ``` +#### Java + ```java class Solution { private final int[] dirs = {-1, 0, 1, 0, -1}; @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func getMaximumGold(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -188,6 +196,8 @@ func getMaximumGold(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function getMaximumGold(grid: number[][]): number { const m = grid.length; @@ -212,6 +222,8 @@ function getMaximumGold(grid: number[][]): number { } ``` +#### JavaScript + ```js /** * @param {number[][]} grid diff --git a/solution/1200-1299/1219.Path with Maximum Gold/README_EN.md b/solution/1200-1299/1219.Path with Maximum Gold/README_EN.md index 24ad3624e5e8b..84ec1f5ef8dd5 100644 --- a/solution/1200-1299/1219.Path with Maximum Gold/README_EN.md +++ b/solution/1200-1299/1219.Path with Maximum Gold/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(m \times n \times 3^k)$, where $k$ is the maximum leng +#### Python3 + ```python class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: @@ -101,6 +103,8 @@ class Solution: return max(dfs(i, j) for i in range(m) for j in range(n)) ``` +#### Java + ```java class Solution { private final int[] dirs = {-1, 0, 1, 0, -1}; @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func getMaximumGold(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -190,6 +198,8 @@ func getMaximumGold(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function getMaximumGold(grid: number[][]): number { const m = grid.length; @@ -214,6 +224,8 @@ function getMaximumGold(grid: number[][]): number { } ``` +#### JavaScript + ```js /** * @param {number[][]} grid diff --git a/solution/1200-1299/1220.Count Vowels Permutation/README.md b/solution/1200-1299/1220.Count Vowels Permutation/README.md index e2426c7400cbc..38aa29254f77e 100644 --- a/solution/1200-1299/1220.Count Vowels Permutation/README.md +++ b/solution/1200-1299/1220.Count Vowels Permutation/README.md @@ -109,6 +109,8 @@ $$ +#### Python3 + ```python class Solution: def countVowelPermutation(self, n: int) -> int: @@ -125,6 +127,8 @@ class Solution: return sum(f) % mod ``` +#### Java + ```java class Solution { public int countVowelPermutation(int n) { @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go func countVowelPermutation(n int) (ans int) { const mod int = 1e9 + 7 @@ -193,6 +201,8 @@ func countVowelPermutation(n int) (ans int) { } ``` +#### TypeScript + ```ts function countVowelPermutation(n: number): number { const f: number[] = Array(5).fill(1); @@ -210,6 +220,8 @@ function countVowelPermutation(n: number): number { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -243,6 +255,8 @@ var countVowelPermutation = function (n) { +#### Python3 + ```python class Solution: def countVowelPermutation(self, n: int) -> int: @@ -277,6 +291,8 @@ class Solution: return sum(map(sum, res)) % mod ``` +#### Java + ```java class Solution { private final int mod = (int) 1e9 + 7; @@ -320,6 +336,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -366,6 +384,8 @@ private: }; ``` +#### Go + ```go const mod = 1e9 + 7 @@ -412,6 +432,8 @@ func pow(a [][]int, n int) [][]int { } ``` +#### TypeScript + ```ts const mod = 1e9 + 7; @@ -454,6 +476,8 @@ function pow(a: number[][], n: number): number[][] { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -511,6 +535,8 @@ function pow(a, n) { +#### Python3 + ```python import numpy as np @@ -538,6 +564,8 @@ class Solution: return res.sum() % mod ``` +#### Java + ```java class Solution { public int countVowelPermutation(int n) { diff --git a/solution/1200-1299/1220.Count Vowels Permutation/README_EN.md b/solution/1200-1299/1220.Count Vowels Permutation/README_EN.md index dea067b315233..afdc3e5e9d2f8 100644 --- a/solution/1200-1299/1220.Count Vowels Permutation/README_EN.md +++ b/solution/1200-1299/1220.Count Vowels Permutation/README_EN.md @@ -110,6 +110,8 @@ The time complexity is $O(n)$, and the space complexity is $O(C)$. Here, $n$ is +#### Python3 + ```python class Solution: def countVowelPermutation(self, n: int) -> int: @@ -126,6 +128,8 @@ class Solution: return sum(f) % mod ``` +#### Java + ```java class Solution { public int countVowelPermutation(int n) { @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func countVowelPermutation(n int) (ans int) { const mod int = 1e9 + 7 @@ -194,6 +202,8 @@ func countVowelPermutation(n int) (ans int) { } ``` +#### TypeScript + ```ts function countVowelPermutation(n: number): number { const f: number[] = Array(5).fill(1); @@ -211,6 +221,8 @@ function countVowelPermutation(n: number): number { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -244,6 +256,8 @@ The time complexity is $O(C^3 \times \log n)$, and the space complexity is $O(C^ +#### Python3 + ```python class Solution: def countVowelPermutation(self, n: int) -> int: @@ -278,6 +292,8 @@ class Solution: return sum(map(sum, res)) % mod ``` +#### Java + ```java class Solution { private final int mod = (int) 1e9 + 7; @@ -321,6 +337,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -367,6 +385,8 @@ private: }; ``` +#### Go + ```go const mod = 1e9 + 7 @@ -413,6 +433,8 @@ func pow(a [][]int, n int) [][]int { } ``` +#### TypeScript + ```ts const mod = 1e9 + 7; @@ -455,6 +477,8 @@ function pow(a: number[][], n: number): number[][] { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -512,6 +536,8 @@ function pow(a, n) { +#### Python3 + ```python import numpy as np @@ -539,6 +565,8 @@ class Solution: return res.sum() % mod ``` +#### Java + ```java class Solution { public int countVowelPermutation(int n) { diff --git a/solution/1200-1299/1221.Split a String in Balanced Strings/README.md b/solution/1200-1299/1221.Split a String in Balanced Strings/README.md index 28e1d61fa456c..4181ed3e84564 100644 --- a/solution/1200-1299/1221.Split a String in Balanced Strings/README.md +++ b/solution/1200-1299/1221.Split a String in Balanced Strings/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def balancedStringSplit(self, s: str) -> int: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int balancedStringSplit(String s) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func balancedStringSplit(s string) int { ans, l := 0, 0 @@ -149,6 +157,8 @@ func balancedStringSplit(s string) int { } ``` +#### JavaScript + ```js /** * @param {string} s diff --git a/solution/1200-1299/1221.Split a String in Balanced Strings/README_EN.md b/solution/1200-1299/1221.Split a String in Balanced Strings/README_EN.md index 798339dbc8a11..4f049b51c0d89 100644 --- a/solution/1200-1299/1221.Split a String in Balanced Strings/README_EN.md +++ b/solution/1200-1299/1221.Split a String in Balanced Strings/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is +#### Python3 + ```python class Solution: def balancedStringSplit(self, s: str) -> int: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int balancedStringSplit(String s) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func balancedStringSplit(s string) int { ans, l := 0, 0 @@ -147,6 +155,8 @@ func balancedStringSplit(s string) int { } ``` +#### JavaScript + ```js /** * @param {string} s diff --git a/solution/1200-1299/1222.Queens That Can Attack the King/README.md b/solution/1200-1299/1222.Queens That Can Attack the King/README.md index 2aff46a16f5de..5f7acc80040f0 100644 --- a/solution/1200-1299/1222.Queens That Can Attack the King/README.md +++ b/solution/1200-1299/1222.Queens That Can Attack the King/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def queensAttacktheKing( @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> queensAttacktheKing(int[][] queens, int[] king) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func queensAttacktheKing(queens [][]int, king []int) (ans [][]int) { n := 8 @@ -181,6 +189,8 @@ func queensAttacktheKing(queens [][]int, king []int) (ans [][]int) { } ``` +#### TypeScript + ```ts function queensAttacktheKing(queens: number[][], king: number[]): number[][] { const n = 8; diff --git a/solution/1200-1299/1222.Queens That Can Attack the King/README_EN.md b/solution/1200-1299/1222.Queens That Can Attack the King/README_EN.md index d751fadb033bb..ff926b1fee366 100644 --- a/solution/1200-1299/1222.Queens That Can Attack the King/README_EN.md +++ b/solution/1200-1299/1222.Queens That Can Attack the King/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$. In this p +#### Python3 + ```python class Solution: def queensAttacktheKing( @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> queensAttacktheKing(int[][] queens, int[] king) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func queensAttacktheKing(queens [][]int, king []int) (ans [][]int) { n := 8 @@ -176,6 +184,8 @@ func queensAttacktheKing(queens [][]int, king []int) (ans [][]int) { } ``` +#### TypeScript + ```ts function queensAttacktheKing(queens: number[][], king: number[]): number[][] { const n = 8; diff --git a/solution/1200-1299/1223.Dice Roll Simulation/README.md b/solution/1200-1299/1223.Dice Roll Simulation/README.md index 07d3b1f98f900..cf5974c516460 100644 --- a/solution/1200-1299/1223.Dice Roll Simulation/README.md +++ b/solution/1200-1299/1223.Dice Roll Simulation/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def dieSimulator(self, n: int, rollMax: List[int]) -> int: @@ -97,6 +99,8 @@ class Solution: return dfs(0, 0, 0) ``` +#### Java + ```java class Solution { private Integer[][][] f; @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func dieSimulator(n int, rollMax []int) int { f := make([][7][16]int, n) @@ -213,6 +221,8 @@ $$ +#### Python3 + ```python class Solution: def dieSimulator(self, n: int, rollMax: List[int]) -> int: @@ -235,6 +245,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int dieSimulator(int n, int[] rollMax) { @@ -267,6 +279,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -301,6 +315,8 @@ public: }; ``` +#### Go + ```go func dieSimulator(n int, rollMax []int) (ans int) { f := make([][7][16]int, n+1) diff --git a/solution/1200-1299/1223.Dice Roll Simulation/README_EN.md b/solution/1200-1299/1223.Dice Roll Simulation/README_EN.md index e9506872c9331..009783ec746b6 100644 --- a/solution/1200-1299/1223.Dice Roll Simulation/README_EN.md +++ b/solution/1200-1299/1223.Dice Roll Simulation/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n \times k^2 \times M)$, and the space complexity is $ +#### Python3 + ```python class Solution: def dieSimulator(self, n: int, rollMax: List[int]) -> int: @@ -96,6 +98,8 @@ class Solution: return dfs(0, 0, 0) ``` +#### Java + ```java class Solution { private Integer[][][] f; @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func dieSimulator(n int, rollMax []int) int { f := make([][7][16]int, n) @@ -212,6 +220,8 @@ The time complexity is $O(n \times k^2 \times M)$, and the space complexity is $ +#### Python3 + ```python class Solution: def dieSimulator(self, n: int, rollMax: List[int]) -> int: @@ -234,6 +244,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int dieSimulator(int n, int[] rollMax) { @@ -266,6 +278,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -300,6 +314,8 @@ public: }; ``` +#### Go + ```go func dieSimulator(n int, rollMax []int) (ans int) { f := make([][7][16]int, n+1) diff --git a/solution/1200-1299/1224.Maximum Equal Frequency/README.md b/solution/1200-1299/1224.Maximum Equal Frequency/README.md index 7cbdb890b2397..28462c0e21c96 100644 --- a/solution/1200-1299/1224.Maximum Equal Frequency/README.md +++ b/solution/1200-1299/1224.Maximum Equal Frequency/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def maxEqualFreq(self, nums: List[int]) -> int: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static int[] cnt = new int[100010]; @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func maxEqualFreq(nums []int) int { cnt := map[int]int{} @@ -175,6 +183,8 @@ func maxEqualFreq(nums []int) int { } ``` +#### TypeScript + ```ts function maxEqualFreq(nums: number[]): number { const n = nums.length; diff --git a/solution/1200-1299/1224.Maximum Equal Frequency/README_EN.md b/solution/1200-1299/1224.Maximum Equal Frequency/README_EN.md index 6d205637bf40e..ef60f251d042f 100644 --- a/solution/1200-1299/1224.Maximum Equal Frequency/README_EN.md +++ b/solution/1200-1299/1224.Maximum Equal Frequency/README_EN.md @@ -67,6 +67,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def maxEqualFreq(self, nums: List[int]) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static int[] cnt = new int[100010]; @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func maxEqualFreq(nums []int) int { cnt := map[int]int{} @@ -169,6 +177,8 @@ func maxEqualFreq(nums []int) int { } ``` +#### TypeScript + ```ts function maxEqualFreq(nums: number[]): number { const n = nums.length; diff --git a/solution/1200-1299/1225.Report Contiguous Dates/README.md b/solution/1200-1299/1225.Report Contiguous Dates/README.md index e14dab6bff1d9..ef7d38a027eb5 100644 --- a/solution/1200-1299/1225.Report Contiguous Dates/README.md +++ b/solution/1200-1299/1225.Report Contiguous Dates/README.md @@ -105,6 +105,8 @@ Succeeded table: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1200-1299/1225.Report Contiguous Dates/README_EN.md b/solution/1200-1299/1225.Report Contiguous Dates/README_EN.md index cbbae120b1392..0424c09f72237 100644 --- a/solution/1200-1299/1225.Report Contiguous Dates/README_EN.md +++ b/solution/1200-1299/1225.Report Contiguous Dates/README_EN.md @@ -106,6 +106,8 @@ We can merge the two tables into one table with a field `st` representing the st +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1200-1299/1226.The Dining Philosophers/README.md b/solution/1200-1299/1226.The Dining Philosophers/README.md index 1a0ed9f4d3a46..06b9a798d01a4 100644 --- a/solution/1200-1299/1226.The Dining Philosophers/README.md +++ b/solution/1200-1299/1226.The Dining Philosophers/README.md @@ -76,6 +76,8 @@ output[i] = [a, b, c] (3个整数) +#### C++ + ```cpp class DiningPhilosophers { public: diff --git a/solution/1200-1299/1226.The Dining Philosophers/README_EN.md b/solution/1200-1299/1226.The Dining Philosophers/README_EN.md index b544e00052405..17923fa09ab14 100644 --- a/solution/1200-1299/1226.The Dining Philosophers/README_EN.md +++ b/solution/1200-1299/1226.The Dining Philosophers/README_EN.md @@ -73,6 +73,8 @@ output[i] = [a, b, c] (three integers) +#### C++ + ```cpp class DiningPhilosophers { public: diff --git a/solution/1200-1299/1227.Airplane Seat Assignment Probability/README.md b/solution/1200-1299/1227.Airplane Seat Assignment Probability/README.md index e84d877fd104a..f8c45e54f728d 100644 --- a/solution/1200-1299/1227.Airplane Seat Assignment Probability/README.md +++ b/solution/1200-1299/1227.Airplane Seat Assignment Probability/README.md @@ -144,12 +144,16 @@ $$ +#### Python3 + ```python class Solution: def nthPersonGetsNthSeat(self, n: int) -> float: return 1 if n == 1 else 0.5 ``` +#### Java + ```java class Solution { public double nthPersonGetsNthSeat(int n) { @@ -158,6 +162,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func nthPersonGetsNthSeat(n int) float64 { if n == 1 { diff --git a/solution/1200-1299/1227.Airplane Seat Assignment Probability/README_EN.md b/solution/1200-1299/1227.Airplane Seat Assignment Probability/README_EN.md index aa085209c0faf..599e4ab4240b3 100644 --- a/solution/1200-1299/1227.Airplane Seat Assignment Probability/README_EN.md +++ b/solution/1200-1299/1227.Airplane Seat Assignment Probability/README_EN.md @@ -138,12 +138,16 @@ $$ +#### Python3 + ```python class Solution: def nthPersonGetsNthSeat(self, n: int) -> float: return 1 if n == 1 else 0.5 ``` +#### Java + ```java class Solution { public double nthPersonGetsNthSeat(int n) { @@ -152,6 +156,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func nthPersonGetsNthSeat(n int) float64 { if n == 1 { diff --git a/solution/1200-1299/1228.Missing Number In Arithmetic Progression/README.md b/solution/1200-1299/1228.Missing Number In Arithmetic Progression/README.md index f9faed1fec70d..bb67502177c5b 100644 --- a/solution/1200-1299/1228.Missing Number In Arithmetic Progression/README.md +++ b/solution/1200-1299/1228.Missing Number In Arithmetic Progression/README.md @@ -70,12 +70,16 @@ tags: +#### Python3 + ```python class Solution: def missingNumber(self, arr: List[int]) -> int: return (arr[0] + arr[-1]) * (len(arr) + 1) // 2 - sum(arr) ``` +#### Java + ```java class Solution { public int missingNumber(int[] arr) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -99,6 +105,8 @@ public: }; ``` +#### Go + ```go func missingNumber(arr []int) int { n := len(arr) @@ -122,6 +130,8 @@ func missingNumber(arr []int) int { +#### Python3 + ```python class Solution: def missingNumber(self, arr: List[int]) -> int: @@ -133,6 +143,8 @@ class Solution: return arr[0] ``` +#### Java + ```java class Solution { public int missingNumber(int[] arr) { @@ -148,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/1200-1299/1228.Missing Number In Arithmetic Progression/README_EN.md b/solution/1200-1299/1228.Missing Number In Arithmetic Progression/README_EN.md index 1fd99030ba8a7..024ad2cdec560 100644 --- a/solution/1200-1299/1228.Missing Number In Arithmetic Progression/README_EN.md +++ b/solution/1200-1299/1228.Missing Number In Arithmetic Progression/README_EN.md @@ -68,12 +68,16 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. Where $n$ is +#### Python3 + ```python class Solution: def missingNumber(self, arr: List[int]) -> int: return (arr[0] + arr[-1]) * (len(arr) + 1) // 2 - sum(arr) ``` +#### Java + ```java class Solution { public int missingNumber(int[] arr) { @@ -85,6 +89,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -97,6 +103,8 @@ public: }; ``` +#### Go + ```go func missingNumber(arr []int) int { n := len(arr) @@ -120,6 +128,8 @@ func missingNumber(arr []int) int { +#### Python3 + ```python class Solution: def missingNumber(self, arr: List[int]) -> int: @@ -131,6 +141,8 @@ class Solution: return arr[0] ``` +#### Java + ```java class Solution { public int missingNumber(int[] arr) { @@ -146,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/1200-1299/1229.Meeting Scheduler/README.md b/solution/1200-1299/1229.Meeting Scheduler/README.md index 6bfdeb8f1fc5d..fb7ff61308f40 100644 --- a/solution/1200-1299/1229.Meeting Scheduler/README.md +++ b/solution/1200-1299/1229.Meeting Scheduler/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def minAvailableDuration( @@ -92,6 +94,8 @@ class Solution: return [] ``` +#### Java + ```java class Solution { public List minAvailableDuration(int[][] slots1, int[][] slots2, int duration) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func minAvailableDuration(slots1 [][]int, slots2 [][]int, duration int) []int { sort.Slice(slots1, func(i, j int) bool { return slots1[i][0] < slots1[j][0] }) @@ -162,6 +170,8 @@ func minAvailableDuration(slots1 [][]int, slots2 [][]int, duration int) []int { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/1200-1299/1229.Meeting Scheduler/README_EN.md b/solution/1200-1299/1229.Meeting Scheduler/README_EN.md index a469a609bbfe5..772cf0a23a3e5 100644 --- a/solution/1200-1299/1229.Meeting Scheduler/README_EN.md +++ b/solution/1200-1299/1229.Meeting Scheduler/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(m \times \log m + n \times \log n)$, and the space com +#### Python3 + ```python class Solution: def minAvailableDuration( @@ -90,6 +92,8 @@ class Solution: return [] ``` +#### Java + ```java class Solution { public List minAvailableDuration(int[][] slots1, int[][] slots2, int duration) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func minAvailableDuration(slots1 [][]int, slots2 [][]int, duration int) []int { sort.Slice(slots1, func(i, j int) bool { return slots1[i][0] < slots1[j][0] }) @@ -160,6 +168,8 @@ func minAvailableDuration(slots1 [][]int, slots2 [][]int, duration int) []int { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/1200-1299/1230.Toss Strange Coins/README.md b/solution/1200-1299/1230.Toss Strange Coins/README.md index 2bf047e8f1f0d..a75c1b774be59 100644 --- a/solution/1200-1299/1230.Toss Strange Coins/README.md +++ b/solution/1200-1299/1230.Toss Strange Coins/README.md @@ -77,6 +77,8 @@ $$ +#### Python3 + ```python class Solution: def probabilityOfHeads(self, prob: List[float], target: int) -> float: @@ -91,6 +93,8 @@ class Solution: return f[n][target] ``` +#### Java + ```java class Solution { public double probabilityOfHeads(double[] prob, int target) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func probabilityOfHeads(prob []float64, target int) float64 { n := len(prob) @@ -151,6 +159,8 @@ func probabilityOfHeads(prob []float64, target int) float64 { } ``` +#### TypeScript + ```ts function probabilityOfHeads(prob: number[], target: number): number { const n = prob.length; @@ -178,6 +188,8 @@ function probabilityOfHeads(prob: number[], target: number): number { +#### Python3 + ```python class Solution: def probabilityOfHeads(self, prob: List[float], target: int) -> float: @@ -191,6 +203,8 @@ class Solution: return f[target] ``` +#### Java + ```java class Solution { public double probabilityOfHeads(double[] prob, int target) { @@ -209,6 +223,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -229,6 +245,8 @@ public: }; ``` +#### Go + ```go func probabilityOfHeads(prob []float64, target int) float64 { f := make([]float64, target+1) @@ -245,6 +263,8 @@ func probabilityOfHeads(prob []float64, target int) float64 { } ``` +#### TypeScript + ```ts function probabilityOfHeads(prob: number[], target: number): number { const f = new Array(target + 1).fill(0); diff --git a/solution/1200-1299/1230.Toss Strange Coins/README_EN.md b/solution/1200-1299/1230.Toss Strange Coins/README_EN.md index 1f23ae770fade..a9a5e14a92df5 100644 --- a/solution/1200-1299/1230.Toss Strange Coins/README_EN.md +++ b/solution/1200-1299/1230.Toss Strange Coins/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n \times target)$, and the space complexity is $O(targ +#### Python3 + ```python class Solution: def probabilityOfHeads(self, prob: List[float], target: int) -> float: @@ -84,6 +86,8 @@ class Solution: return f[n][target] ``` +#### Java + ```java class Solution { public double probabilityOfHeads(double[] prob, int target) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func probabilityOfHeads(prob []float64, target int) float64 { n := len(prob) @@ -144,6 +152,8 @@ func probabilityOfHeads(prob []float64, target int) float64 { } ``` +#### TypeScript + ```ts function probabilityOfHeads(prob: number[], target: number): number { const n = prob.length; @@ -171,6 +181,8 @@ function probabilityOfHeads(prob: number[], target: number): number { +#### Python3 + ```python class Solution: def probabilityOfHeads(self, prob: List[float], target: int) -> float: @@ -184,6 +196,8 @@ class Solution: return f[target] ``` +#### Java + ```java class Solution { public double probabilityOfHeads(double[] prob, int target) { @@ -202,6 +216,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -222,6 +238,8 @@ public: }; ``` +#### Go + ```go func probabilityOfHeads(prob []float64, target int) float64 { f := make([]float64, target+1) @@ -238,6 +256,8 @@ func probabilityOfHeads(prob []float64, target int) float64 { } ``` +#### TypeScript + ```ts function probabilityOfHeads(prob: number[], target: number): number { const f = new Array(target + 1).fill(0); diff --git a/solution/1200-1299/1231.Divide Chocolate/README.md b/solution/1200-1299/1231.Divide Chocolate/README.md index 07706a7a53f7e..d3c97c83f4c66 100644 --- a/solution/1200-1299/1231.Divide Chocolate/README.md +++ b/solution/1200-1299/1231.Divide Chocolate/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def maximizeSweetness(self, sweetness: List[int], k: int) -> int: @@ -99,6 +101,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { public int maximizeSweetness(int[] sweetness, int k) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func maximizeSweetness(sweetness []int, k int) int { l, r := 0, 0 @@ -189,6 +197,8 @@ func maximizeSweetness(sweetness []int, k int) int { } ``` +#### TypeScript + ```ts function maximizeSweetness(sweetness: number[], k: number): number { let l = 0; diff --git a/solution/1200-1299/1231.Divide Chocolate/README_EN.md b/solution/1200-1299/1231.Divide Chocolate/README_EN.md index c04c903f11788..81c4e9850eff8 100644 --- a/solution/1200-1299/1231.Divide Chocolate/README_EN.md +++ b/solution/1200-1299/1231.Divide Chocolate/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n \times \log \sum_{i=0}^{n-1} sweetness[i])$, and the +#### Python3 + ```python class Solution: def maximizeSweetness(self, sweetness: List[int], k: int) -> int: @@ -100,6 +102,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { public int maximizeSweetness(int[] sweetness, int k) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func maximizeSweetness(sweetness []int, k int) int { l, r := 0, 0 @@ -190,6 +198,8 @@ func maximizeSweetness(sweetness []int, k int) int { } ``` +#### TypeScript + ```ts function maximizeSweetness(sweetness: number[], k: number): number { let l = 0; diff --git a/solution/1200-1299/1232.Check If It Is a Straight Line/README.md b/solution/1200-1299/1232.Check If It Is a Straight Line/README.md index 4329268eefd2e..0ae1eca23e565 100644 --- a/solution/1200-1299/1232.Check If It Is a Straight Line/README.md +++ b/solution/1200-1299/1232.Check If It Is a Straight Line/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def checkStraightLine(self, coordinates: List[List[int]]) -> bool: @@ -76,6 +78,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean checkStraightLine(int[][] coordinates) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func checkStraightLine(coordinates [][]int) bool { x1, y1 := coordinates[0][0], coordinates[0][1] diff --git a/solution/1200-1299/1232.Check If It Is a Straight Line/README_EN.md b/solution/1200-1299/1232.Check If It Is a Straight Line/README_EN.md index b0c9c6b3dec96..758e76b323730 100644 --- a/solution/1200-1299/1232.Check If It Is a Straight Line/README_EN.md +++ b/solution/1200-1299/1232.Check If It Is a Straight Line/README_EN.md @@ -65,6 +65,8 @@ The time complexity is $O(n)$, where $n$ is the length of the `coordinates` arra +#### Python3 + ```python class Solution: def checkStraightLine(self, coordinates: List[List[int]]) -> bool: @@ -76,6 +78,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean checkStraightLine(int[][] coordinates) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func checkStraightLine(coordinates [][]int) bool { x1, y1 := coordinates[0][0], coordinates[0][1] diff --git a/solution/1200-1299/1233.Remove Sub-Folders from the Filesystem/README.md b/solution/1200-1299/1233.Remove Sub-Folders from the Filesystem/README.md index 045dffceb4995..501c096c3277a 100644 --- a/solution/1200-1299/1233.Remove Sub-Folders from the Filesystem/README.md +++ b/solution/1200-1299/1233.Remove Sub-Folders from the Filesystem/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def removeSubfolders(self, folder: List[str]) -> List[str]: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List removeSubfolders(String[] folder) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func removeSubfolders(folder []string) []string { sort.Strings(folder) @@ -163,6 +171,8 @@ func removeSubfolders(folder []string) []string { +#### Python3 + ```python class Trie: def __init__(self): @@ -199,6 +209,8 @@ class Solution: return [folder[i] for i in trie.search()] ``` +#### Java + ```java class Trie { private Map children = new HashMap<>(); @@ -249,6 +261,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -311,6 +325,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children map[string]*Trie @@ -373,6 +389,8 @@ func removeSubfolders(folder []string) []string { +#### Go + ```go type Trie struct { children map[string]*Trie diff --git a/solution/1200-1299/1233.Remove Sub-Folders from the Filesystem/README_EN.md b/solution/1200-1299/1233.Remove Sub-Folders from the Filesystem/README_EN.md index c0d75371381fc..c66d3b17fff4f 100644 --- a/solution/1200-1299/1233.Remove Sub-Folders from the Filesystem/README_EN.md +++ b/solution/1200-1299/1233.Remove Sub-Folders from the Filesystem/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n \times \log n \times m)$, and the space complexity i +#### Python3 + ```python class Solution: def removeSubfolders(self, folder: List[str]) -> List[str]: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List removeSubfolders(String[] folder) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func removeSubfolders(folder []string) []string { sort.Strings(folder) @@ -162,6 +170,8 @@ The time complexity is $O(n \times m)$, and the space complexity is $O(n \times +#### Python3 + ```python class Trie: def __init__(self): @@ -198,6 +208,8 @@ class Solution: return [folder[i] for i in trie.search()] ``` +#### Java + ```java class Trie { private Map children = new HashMap<>(); @@ -248,6 +260,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -310,6 +324,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children map[string]*Trie @@ -372,6 +388,8 @@ func removeSubfolders(folder []string) []string { +#### Go + ```go type Trie struct { children map[string]*Trie diff --git a/solution/1200-1299/1234.Replace the Substring for Balanced String/README.md b/solution/1200-1299/1234.Replace the Substring for Balanced String/README.md index cc22228135558..9570272ef6064 100644 --- a/solution/1200-1299/1234.Replace the Substring for Balanced String/README.md +++ b/solution/1200-1299/1234.Replace the Substring for Balanced String/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class Solution: def balancedString(self, s: str) -> int: @@ -113,6 +115,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int balancedString(String s) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go func balancedString(s string) int { cnt := [4]int{} diff --git a/solution/1200-1299/1234.Replace the Substring for Balanced String/README_EN.md b/solution/1200-1299/1234.Replace the Substring for Balanced String/README_EN.md index e15a5ca62369a..34306686429dd 100644 --- a/solution/1200-1299/1234.Replace the Substring for Balanced String/README_EN.md +++ b/solution/1200-1299/1234.Replace the Substring for Balanced String/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(n)$, and the space complexity is $O(C)$. Where $n$ is +#### Python3 + ```python class Solution: def balancedString(self, s: str) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int balancedString(String s) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func balancedString(s string) int { cnt := [4]int{} diff --git a/solution/1200-1299/1235.Maximum Profit in Job Scheduling/README.md b/solution/1200-1299/1235.Maximum Profit in Job Scheduling/README.md index 15001fd6a6695..4f89982e89a7b 100644 --- a/solution/1200-1299/1235.Maximum Profit in Job Scheduling/README.md +++ b/solution/1200-1299/1235.Maximum Profit in Job Scheduling/README.md @@ -99,6 +99,8 @@ $$ +#### Python3 + ```python class Solution: def jobScheduling( @@ -117,6 +119,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private int[][] jobs; @@ -163,6 +167,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -187,6 +193,8 @@ public: }; ``` +#### Go + ```go func jobScheduling(startTime []int, endTime []int, profit []int) int { n := len(profit) @@ -214,6 +222,8 @@ func jobScheduling(startTime []int, endTime []int, profit []int) int { } ``` +#### TypeScript + ```ts function jobScheduling(startTime: number[], endTime: number[], profit: number[]): number { const n = startTime.length; @@ -276,6 +286,8 @@ $$ +#### Python3 + ```python class Solution: def jobScheduling( @@ -290,6 +302,8 @@ class Solution: return dp[n] ``` +#### Java + ```java class Solution { public int jobScheduling(int[] startTime, int[] endTime, int[] profit) { @@ -322,6 +336,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -341,6 +357,8 @@ public: }; ``` +#### Go + ```go func jobScheduling(startTime []int, endTime []int, profit []int) int { n := len(profit) @@ -359,6 +377,8 @@ func jobScheduling(startTime []int, endTime []int, profit []int) int { } ``` +#### TypeScript + ```ts function jobScheduling(startTime: number[], endTime: number[], profit: number[]): number { const n = profit.length; diff --git a/solution/1200-1299/1235.Maximum Profit in Job Scheduling/README_EN.md b/solution/1200-1299/1235.Maximum Profit in Job Scheduling/README_EN.md index d178e06264c8b..ba9ee03430293 100644 --- a/solution/1200-1299/1235.Maximum Profit in Job Scheduling/README_EN.md +++ b/solution/1200-1299/1235.Maximum Profit in Job Scheduling/README_EN.md @@ -94,6 +94,8 @@ The time complexity is $O(n \times \log n)$, where $n$ is the number of jobs. +#### Python3 + ```python class Solution: def jobScheduling( @@ -112,6 +114,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private int[][] jobs; @@ -158,6 +162,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -182,6 +188,8 @@ public: }; ``` +#### Go + ```go func jobScheduling(startTime []int, endTime []int, profit []int) int { n := len(profit) @@ -209,6 +217,8 @@ func jobScheduling(startTime []int, endTime []int, profit []int) int { } ``` +#### TypeScript + ```ts function jobScheduling(startTime: number[], endTime: number[], profit: number[]): number { const n = startTime.length; @@ -271,6 +281,8 @@ Similar problems: +#### Python3 + ```python class Solution: def jobScheduling( @@ -285,6 +297,8 @@ class Solution: return dp[n] ``` +#### Java + ```java class Solution { public int jobScheduling(int[] startTime, int[] endTime, int[] profit) { @@ -317,6 +331,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -336,6 +352,8 @@ public: }; ``` +#### Go + ```go func jobScheduling(startTime []int, endTime []int, profit []int) int { n := len(profit) @@ -354,6 +372,8 @@ func jobScheduling(startTime []int, endTime []int, profit []int) int { } ``` +#### TypeScript + ```ts function jobScheduling(startTime: number[], endTime: number[], profit: number[]): number { const n = profit.length; diff --git a/solution/1200-1299/1236.Web Crawler/README.md b/solution/1200-1299/1236.Web Crawler/README.md index db995afce4340..b05b868429e4b 100644 --- a/solution/1200-1299/1236.Web Crawler/README.md +++ b/solution/1200-1299/1236.Web Crawler/README.md @@ -110,6 +110,8 @@ startUrl = "http://news.google.com" +#### Python3 + ```python # """ # This is HtmlParser's API interface. @@ -142,6 +144,8 @@ class Solution: return list(ans) ``` +#### Java + ```java /** * // This is the HtmlParser's API interface. @@ -179,6 +183,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * // This is the HtmlParser's API interface. @@ -220,6 +226,8 @@ public: }; ``` +#### Go + ```go /** * // This is HtmlParser's API interface. diff --git a/solution/1200-1299/1236.Web Crawler/README_EN.md b/solution/1200-1299/1236.Web Crawler/README_EN.md index f467973a4bcb6..b900e154d04ee 100644 --- a/solution/1200-1299/1236.Web Crawler/README_EN.md +++ b/solution/1200-1299/1236.Web Crawler/README_EN.md @@ -112,6 +112,8 @@ startUrl = "http://news.google.com" +#### Python3 + ```python # """ # This is HtmlParser's API interface. @@ -144,6 +146,8 @@ class Solution: return list(ans) ``` +#### Java + ```java /** * // This is the HtmlParser's API interface. @@ -181,6 +185,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * // This is the HtmlParser's API interface. @@ -222,6 +228,8 @@ public: }; ``` +#### Go + ```go /** * // This is HtmlParser's API interface. diff --git a/solution/1200-1299/1237.Find Positive Integer Solution for a Given Equation/README.md b/solution/1200-1299/1237.Find Positive Integer Solution for a Given Equation/README.md index 10be3e2195930..dc00e14e8af08 100644 --- a/solution/1200-1299/1237.Find Positive Integer Solution for a Given Equation/README.md +++ b/solution/1200-1299/1237.Find Positive Integer Solution for a Given Equation/README.md @@ -98,6 +98,8 @@ x=5, y=1 -> f(5, 1) = 5 * 1 = 5 +#### Python3 + ```python """ This is the custom function interface. @@ -123,6 +125,8 @@ class Solution: return ans ``` +#### Java + ```java /* * // This is the custom function interface. @@ -157,6 +161,8 @@ class Solution { } ``` +#### C++ + ```cpp /* * // This is the custom function interface. @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go /** * This is the declaration of customFunction API. @@ -214,6 +222,8 @@ func findSolution(customFunction func(int, int) int, z int) (ans [][]int) { } ``` +#### TypeScript + ```ts /** * // This is the CustomFunction's API interface. @@ -264,6 +274,8 @@ function findSolution(customfunction: CustomFunction, z: number): number[][] { +#### Python3 + ```python """ This is the custom function interface. @@ -293,6 +305,8 @@ class Solution: return ans ``` +#### Java + ```java /* * // This is the custom function interface. @@ -324,6 +338,8 @@ class Solution { } ``` +#### C++ + ```cpp /* * // This is the custom function interface. @@ -357,6 +373,8 @@ public: }; ``` +#### Go + ```go /** * This is the declaration of customFunction API. @@ -384,6 +402,8 @@ func findSolution(customFunction func(int, int) int, z int) (ans [][]int) { } ``` +#### TypeScript + ```ts /** * // This is the CustomFunction's API interface. diff --git a/solution/1200-1299/1237.Find Positive Integer Solution for a Given Equation/README_EN.md b/solution/1200-1299/1237.Find Positive Integer Solution for a Given Equation/README_EN.md index 8837e710e4d46..dda134f739049 100644 --- a/solution/1200-1299/1237.Find Positive Integer Solution for a Given Equation/README_EN.md +++ b/solution/1200-1299/1237.Find Positive Integer Solution for a Given Equation/README_EN.md @@ -98,6 +98,8 @@ The time complexity is $O(n \log n)$, where $n$ is the value of $z$, and the spa +#### Python3 + ```python """ This is the custom function interface. @@ -123,6 +125,8 @@ class Solution: return ans ``` +#### Java + ```java /* * // This is the custom function interface. @@ -157,6 +161,8 @@ class Solution { } ``` +#### C++ + ```cpp /* * // This is the custom function interface. @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go /** * This is the declaration of customFunction API. @@ -214,6 +222,8 @@ func findSolution(customFunction func(int, int) int, z int) (ans [][]int) { } ``` +#### TypeScript + ```ts /** * // This is the CustomFunction's API interface. @@ -264,6 +274,8 @@ The time complexity is $O(n)$, where $n$ is the value of $z$, and the space comp +#### Python3 + ```python """ This is the custom function interface. @@ -293,6 +305,8 @@ class Solution: return ans ``` +#### Java + ```java /* * // This is the custom function interface. @@ -324,6 +338,8 @@ class Solution { } ``` +#### C++ + ```cpp /* * // This is the custom function interface. @@ -357,6 +373,8 @@ public: }; ``` +#### Go + ```go /** * This is the declaration of customFunction API. @@ -384,6 +402,8 @@ func findSolution(customFunction func(int, int) int, z int) (ans [][]int) { } ``` +#### TypeScript + ```ts /** * // This is the CustomFunction's API interface. diff --git a/solution/1200-1299/1238.Circular Permutation in Binary Representation/README.md b/solution/1200-1299/1238.Circular Permutation in Binary Representation/README.md index e84e90a8d697c..d04ee8f5f4e1b 100644 --- a/solution/1200-1299/1238.Circular Permutation in Binary Representation/README.md +++ b/solution/1200-1299/1238.Circular Permutation in Binary Representation/README.md @@ -84,6 +84,8 @@ int gray(x) { +#### Python3 + ```python class Solution: def circularPermutation(self, n: int, start: int) -> List[int]: @@ -92,6 +94,8 @@ class Solution: return g[j:] + g[:j] ``` +#### Java + ```java class Solution { public List circularPermutation(int n, int start) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func circularPermutation(n int, start int) []int { g := make([]int, 1< +#### Python3 + ```python class Solution: def circularPermutation(self, n: int, start: int) -> List[int]: return [i ^ (i >> 1) ^ start for i in range(1 << n)] ``` +#### Java + ```java class Solution { public List circularPermutation(int n, int start) { @@ -191,6 +205,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -204,6 +220,8 @@ public: }; ``` +#### Go + ```go func circularPermutation(n int, start int) (ans []int) { for i := 0; i < 1< +#### Python3 + ```python class Solution: def circularPermutation(self, n: int, start: int) -> List[int]: @@ -108,6 +110,8 @@ class Solution: return g[j:] + g[:j] ``` +#### Java + ```java class Solution { public List circularPermutation(int n, int start) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func circularPermutation(n int, start int) []int { g := make([]int, 1< +#### Python3 + ```python class Solution: def circularPermutation(self, n: int, start: int) -> List[int]: return [i ^ (i >> 1) ^ start for i in range(1 << n)] ``` +#### Java + ```java class Solution { public List circularPermutation(int n, int start) { @@ -207,6 +221,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -220,6 +236,8 @@ public: }; ``` +#### Go + ```go func circularPermutation(n int, start int) (ans []int) { for i := 0; i < 1< +#### Python3 + ```python class Solution: def maxLength(self, arr: List[str]) -> int: @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxLength(List arr) { @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func maxLength(arr []string) (ans int) { masks := []int{0} diff --git a/solution/1200-1299/1239.Maximum Length of a Concatenated String with Unique Characters/README_EN.md b/solution/1200-1299/1239.Maximum Length of a Concatenated String with Unique Characters/README_EN.md index f76a17c3ba19f..dc8597040daba 100644 --- a/solution/1200-1299/1239.Maximum Length of a Concatenated String with Unique Characters/README_EN.md +++ b/solution/1200-1299/1239.Maximum Length of a Concatenated String with Unique Characters/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(2^n + L)$, and the space complexity is $O(2^n)$. Where +#### Python3 + ```python class Solution: def maxLength(self, arr: List[str]) -> int: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxLength(List arr) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go func maxLength(arr []string) (ans int) { masks := []int{0} diff --git a/solution/1200-1299/1240.Tiling a Rectangle with the Fewest Squares/README.md b/solution/1200-1299/1240.Tiling a Rectangle with the Fewest Squares/README.md index 79d7802ed02d3..f78be7f78e372 100644 --- a/solution/1200-1299/1240.Tiling a Rectangle with the Fewest Squares/README.md +++ b/solution/1200-1299/1240.Tiling a Rectangle with the Fewest Squares/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def tilingRectangle(self, n: int, m: int) -> int: @@ -121,6 +123,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -180,6 +184,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -240,6 +246,8 @@ private: }; ``` +#### Go + ```go func tilingRectangle(n int, m int) int { ans := n * m @@ -290,6 +298,8 @@ func tilingRectangle(n int, m int) int { } ``` +#### TypeScript + ```ts function tilingRectangle(n: number, m: number): number { let ans = n * m; @@ -349,6 +359,8 @@ function tilingRectangle(n: number, m: number): number { +#### Python3 + ```python class Solution: def tilingRectangle(self, n: int, m: int) -> int: @@ -389,6 +401,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -450,6 +464,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -512,6 +528,8 @@ private: }; ``` +#### Go + ```go func tilingRectangle(n int, m int) int { ans := n * m @@ -564,6 +582,8 @@ func tilingRectangle(n int, m int) int { } ``` +#### TypeScript + ```ts function tilingRectangle(n: number, m: number): number { let ans = n * m; diff --git a/solution/1200-1299/1240.Tiling a Rectangle with the Fewest Squares/README_EN.md b/solution/1200-1299/1240.Tiling a Rectangle with the Fewest Squares/README_EN.md index 4e3ec0c8e2bfe..a4587d2849cc9 100644 --- a/solution/1200-1299/1240.Tiling a Rectangle with the Fewest Squares/README_EN.md +++ b/solution/1200-1299/1240.Tiling a Rectangle with the Fewest Squares/README_EN.md @@ -76,6 +76,8 @@ Since each position only has two states: filled or not filled, we can use an int +#### Python3 + ```python class Solution: def tilingRectangle(self, n: int, m: int) -> int: @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -174,6 +178,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -234,6 +240,8 @@ private: }; ``` +#### Go + ```go func tilingRectangle(n int, m int) int { ans := n * m @@ -284,6 +292,8 @@ func tilingRectangle(n int, m int) int { } ``` +#### TypeScript + ```ts function tilingRectangle(n: number, m: number): number { let ans = n * m; @@ -343,6 +353,8 @@ function tilingRectangle(n: number, m: number): number { +#### Python3 + ```python class Solution: def tilingRectangle(self, n: int, m: int) -> int: @@ -383,6 +395,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -444,6 +458,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -506,6 +522,8 @@ private: }; ``` +#### Go + ```go func tilingRectangle(n int, m int) int { ans := n * m @@ -558,6 +576,8 @@ func tilingRectangle(n int, m int) int { } ``` +#### TypeScript + ```ts function tilingRectangle(n: number, m: number): number { let ans = n * m; diff --git a/solution/1200-1299/1241.Number of Comments per Post/README.md b/solution/1200-1299/1241.Number of Comments per Post/README.md index 2f2c3ea0b3635..898c72fff8a2b 100644 --- a/solution/1200-1299/1241.Number of Comments per Post/README.md +++ b/solution/1200-1299/1241.Number of Comments per Post/README.md @@ -91,6 +91,8 @@ Submissions table: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1200-1299/1241.Number of Comments per Post/README_EN.md b/solution/1200-1299/1241.Number of Comments per Post/README_EN.md index 4d80423755e9d..eb8171845329a 100644 --- a/solution/1200-1299/1241.Number of Comments per Post/README_EN.md +++ b/solution/1200-1299/1241.Number of Comments per Post/README_EN.md @@ -89,6 +89,8 @@ The comment with id 6 is a comment on a deleted post with id 7 so we ignored it. +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1200-1299/1242.Web Crawler Multithreaded/README.md b/solution/1200-1299/1242.Web Crawler Multithreaded/README.md index c5e216184bdc8..18750701db04a 100644 --- a/solution/1200-1299/1242.Web Crawler Multithreaded/README.md +++ b/solution/1200-1299/1242.Web Crawler Multithreaded/README.md @@ -124,18 +124,26 @@ startUrl = "http://news.google.com" +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1200-1299/1242.Web Crawler Multithreaded/README_EN.md b/solution/1200-1299/1242.Web Crawler Multithreaded/README_EN.md index 4bd73d332f644..367523a8bf757 100644 --- a/solution/1200-1299/1242.Web Crawler Multithreaded/README_EN.md +++ b/solution/1200-1299/1242.Web Crawler Multithreaded/README_EN.md @@ -120,18 +120,26 @@ startUrl = "http://news.google.com" +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1200-1299/1243.Array Transformation/README.md b/solution/1200-1299/1243.Array Transformation/README.md index fd08291eebdc7..d44bb44ebffb8 100644 --- a/solution/1200-1299/1243.Array Transformation/README.md +++ b/solution/1200-1299/1243.Array Transformation/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def transformArray(self, arr: List[int]) -> List[int]: @@ -92,6 +94,8 @@ class Solution: return arr ``` +#### Java + ```java class Solution { public List transformArray(int[] arr) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func transformArray(arr []int) []int { f := true diff --git a/solution/1200-1299/1243.Array Transformation/README_EN.md b/solution/1200-1299/1243.Array Transformation/README_EN.md index 31ab60ee7c0b8..408d6fe5d2387 100644 --- a/solution/1200-1299/1243.Array Transformation/README_EN.md +++ b/solution/1200-1299/1243.Array Transformation/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(n \times m)$, and the space complexity is $O(n)$. Wher +#### Python3 + ```python class Solution: def transformArray(self, arr: List[int]) -> List[int]: @@ -92,6 +94,8 @@ class Solution: return arr ``` +#### Java + ```java class Solution { public List transformArray(int[] arr) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func transformArray(arr []int) []int { f := true diff --git a/solution/1200-1299/1244.Design A Leaderboard/README.md b/solution/1200-1299/1244.Design A Leaderboard/README.md index d33ab89d9ec02..fda2275afdf9d 100644 --- a/solution/1200-1299/1244.Design A Leaderboard/README.md +++ b/solution/1200-1299/1244.Design A Leaderboard/README.md @@ -95,6 +95,8 @@ leaderboard.top(3); // returns 141 = 51 + 51 + 39; +#### Python3 + ```python from sortedcontainers import SortedList @@ -127,6 +129,8 @@ class Leaderboard: # obj.reset(playerId) ``` +#### Java + ```java class Leaderboard { private Map d = new HashMap<>(); @@ -175,6 +179,8 @@ class Leaderboard { */ ``` +#### C++ + ```cpp class Leaderboard { public: @@ -221,6 +227,8 @@ private: */ ``` +#### Rust + ```rust use std::collections::BTreeMap; diff --git a/solution/1200-1299/1244.Design A Leaderboard/README_EN.md b/solution/1200-1299/1244.Design A Leaderboard/README_EN.md index e0ac3960fa05a..2183ec7c5fa6a 100644 --- a/solution/1200-1299/1244.Design A Leaderboard/README_EN.md +++ b/solution/1200-1299/1244.Design A Leaderboard/README_EN.md @@ -84,6 +84,8 @@ The space complexity is $O(n)$, where $n$ is the number of players. +#### Python3 + ```python from sortedcontainers import SortedList @@ -116,6 +118,8 @@ class Leaderboard: # obj.reset(playerId) ``` +#### Java + ```java class Leaderboard { private Map d = new HashMap<>(); @@ -164,6 +168,8 @@ class Leaderboard { */ ``` +#### C++ + ```cpp class Leaderboard { public: @@ -210,6 +216,8 @@ private: */ ``` +#### Rust + ```rust use std::collections::BTreeMap; diff --git a/solution/1200-1299/1245.Tree Diameter/README.md b/solution/1200-1299/1245.Tree Diameter/README.md index 5f6c4ff6353fe..d2971481de5b8 100644 --- a/solution/1200-1299/1245.Tree Diameter/README.md +++ b/solution/1200-1299/1245.Tree Diameter/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def treeDiameter(self, edges: List[List[int]]) -> int: @@ -118,6 +120,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private Map> g; @@ -157,6 +161,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -192,6 +198,8 @@ public: }; ``` +#### Go + ```go func treeDiameter(edges [][]int) int { n := len(edges) diff --git a/solution/1200-1299/1245.Tree Diameter/README_EN.md b/solution/1200-1299/1245.Tree Diameter/README_EN.md index 4f9db1a1face1..0b35f34886d88 100644 --- a/solution/1200-1299/1245.Tree Diameter/README_EN.md +++ b/solution/1200-1299/1245.Tree Diameter/README_EN.md @@ -85,6 +85,8 @@ Similar problems: +#### Python3 + ```python class Solution: def treeDiameter(self, edges: List[List[int]]) -> int: @@ -112,6 +114,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private Map> g; @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go func treeDiameter(edges [][]int) int { n := len(edges) diff --git a/solution/1200-1299/1246.Palindrome Removal/README.md b/solution/1200-1299/1246.Palindrome Removal/README.md index 1e6734ddf27b9..2626a3b59ab2d 100644 --- a/solution/1200-1299/1246.Palindrome Removal/README.md +++ b/solution/1200-1299/1246.Palindrome Removal/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def minimumMoves(self, arr: List[int]) -> int: @@ -88,6 +90,8 @@ class Solution: return f[0][n - 1] ``` +#### Java + ```java class Solution { public int minimumMoves(int[] arr) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func minimumMoves(arr []int) int { n := len(arr) diff --git a/solution/1200-1299/1246.Palindrome Removal/README_EN.md b/solution/1200-1299/1246.Palindrome Removal/README_EN.md index 41e001852eda8..d8f63487348aa 100644 --- a/solution/1200-1299/1246.Palindrome Removal/README_EN.md +++ b/solution/1200-1299/1246.Palindrome Removal/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n^3)$, and the space complexity is $O(n^2)$. Where $n$ +#### Python3 + ```python class Solution: def minimumMoves(self, arr: List[int]) -> int: @@ -88,6 +90,8 @@ class Solution: return f[0][n - 1] ``` +#### Java + ```java class Solution { public int minimumMoves(int[] arr) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func minimumMoves(arr []int) int { n := len(arr) diff --git a/solution/1200-1299/1247.Minimum Swaps to Make Strings Equal/README.md b/solution/1200-1299/1247.Minimum Swaps to Make Strings Equal/README.md index 7bf9b9877f8e2..e16383488a101 100644 --- a/solution/1200-1299/1247.Minimum Swaps to Make Strings Equal/README.md +++ b/solution/1200-1299/1247.Minimum Swaps to Make Strings Equal/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def minimumSwap(self, s1: str, s2: str) -> int: @@ -95,6 +97,8 @@ class Solution: return xy // 2 + yx // 2 + xy % 2 + yx % 2 ``` +#### Java + ```java class Solution { public int minimumSwap(String s1, String s2) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func minimumSwap(s1 string, s2 string) int { xy, yx := 0, 0 @@ -152,6 +160,8 @@ func minimumSwap(s1 string, s2 string) int { } ``` +#### JavaScript + ```js var minimumSwap = function (s1, s2) { let xy = 0, diff --git a/solution/1200-1299/1247.Minimum Swaps to Make Strings Equal/README_EN.md b/solution/1200-1299/1247.Minimum Swaps to Make Strings Equal/README_EN.md index b63e4b1f52977..686cf7e181197 100644 --- a/solution/1200-1299/1247.Minimum Swaps to Make Strings Equal/README_EN.md +++ b/solution/1200-1299/1247.Minimum Swaps to Make Strings Equal/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n)$, where $n$ is the length of the strings $s1$ and $ +#### Python3 + ```python class Solution: def minimumSwap(self, s1: str, s2: str) -> int: @@ -89,6 +91,8 @@ class Solution: return xy // 2 + yx // 2 + xy % 2 + yx % 2 ``` +#### Java + ```java class Solution { public int minimumSwap(String s1, String s2) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func minimumSwap(s1 string, s2 string) int { xy, yx := 0, 0 @@ -146,6 +154,8 @@ func minimumSwap(s1 string, s2 string) int { } ``` +#### JavaScript + ```js var minimumSwap = function (s1, s2) { let xy = 0, diff --git a/solution/1200-1299/1248.Count Number of Nice Subarrays/README.md b/solution/1200-1299/1248.Count Number of Nice Subarrays/README.md index 0f7e4fac601b0..23fc810971705 100644 --- a/solution/1200-1299/1248.Count Number of Nice Subarrays/README.md +++ b/solution/1200-1299/1248.Count Number of Nice Subarrays/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numberOfSubarrays(int[] nums, int k) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func numberOfSubarrays(nums []int, k int) (ans int) { n := len(nums) @@ -142,6 +150,8 @@ func numberOfSubarrays(nums []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function numberOfSubarrays(nums: number[], k: number): number { const n = nums.length; diff --git a/solution/1200-1299/1248.Count Number of Nice Subarrays/README_EN.md b/solution/1200-1299/1248.Count Number of Nice Subarrays/README_EN.md index f73aafe726886..22e3aeaf99854 100644 --- a/solution/1200-1299/1248.Count Number of Nice Subarrays/README_EN.md +++ b/solution/1200-1299/1248.Count Number of Nice Subarrays/README_EN.md @@ -89,6 +89,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numberOfSubarrays(int[] nums, int k) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func numberOfSubarrays(nums []int, k int) (ans int) { n := len(nums) @@ -157,6 +165,8 @@ func numberOfSubarrays(nums []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function numberOfSubarrays(nums: number[], k: number): number { const n = nums.length; diff --git a/solution/1200-1299/1249.Minimum Remove to Make Valid Parentheses/README.md b/solution/1200-1299/1249.Minimum Remove to Make Valid Parentheses/README.md index 76305f72bb4ea..21fe15d59c3ca 100644 --- a/solution/1200-1299/1249.Minimum Remove to Make Valid Parentheses/README.md +++ b/solution/1200-1299/1249.Minimum Remove to Make Valid Parentheses/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def minRemoveToMakeValid(self, s: str) -> str: @@ -112,6 +114,8 @@ class Solution: return ''.join(ans[::-1]) ``` +#### Java + ```java class Solution { public String minRemoveToMakeValid(String s) { @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -180,6 +186,8 @@ public: }; ``` +#### Go + ```go func minRemoveToMakeValid(s string) string { stk := []byte{} @@ -217,6 +225,8 @@ func minRemoveToMakeValid(s string) string { } ``` +#### TypeScript + ```ts function minRemoveToMakeValid(s: string): string { let left = 0; @@ -253,6 +263,8 @@ function minRemoveToMakeValid(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn min_remove_to_make_valid(s: String) -> String { diff --git a/solution/1200-1299/1249.Minimum Remove to Make Valid Parentheses/README_EN.md b/solution/1200-1299/1249.Minimum Remove to Make Valid Parentheses/README_EN.md index 7682728f6aa12..241837a40cdb5 100644 --- a/solution/1200-1299/1249.Minimum Remove to Make Valid Parentheses/README_EN.md +++ b/solution/1200-1299/1249.Minimum Remove to Make Valid Parentheses/README_EN.md @@ -82,6 +82,8 @@ Similar problems: +#### Python3 + ```python class Solution: def minRemoveToMakeValid(self, s: str) -> str: @@ -108,6 +110,8 @@ class Solution: return ''.join(ans[::-1]) ``` +#### Java + ```java class Solution { public String minRemoveToMakeValid(String s) { @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go func minRemoveToMakeValid(s string) string { stk := []byte{} @@ -213,6 +221,8 @@ func minRemoveToMakeValid(s string) string { } ``` +#### TypeScript + ```ts function minRemoveToMakeValid(s: string): string { let left = 0; @@ -249,6 +259,8 @@ function minRemoveToMakeValid(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn min_remove_to_make_valid(s: String) -> String { diff --git a/solution/1200-1299/1250.Check If It Is a Good Array/README.md b/solution/1200-1299/1250.Check If It Is a Good Array/README.md index d20d34b52f1f9..bbd798d2a0927 100644 --- a/solution/1200-1299/1250.Check If It Is a Good Array/README.md +++ b/solution/1200-1299/1250.Check If It Is a Good Array/README.md @@ -77,12 +77,16 @@ tags: +#### Python3 + ```python class Solution: def isGoodArray(self, nums: List[int]) -> bool: return reduce(gcd, nums) == 1 ``` +#### Java + ```java class Solution { public boolean isGoodArray(int[] nums) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func isGoodArray(nums []int) bool { g := 0 diff --git a/solution/1200-1299/1250.Check If It Is a Good Array/README_EN.md b/solution/1200-1299/1250.Check If It Is a Good Array/README_EN.md index 9d3ad2acf769b..10d14d1ed4d3d 100644 --- a/solution/1200-1299/1250.Check If It Is a Good Array/README_EN.md +++ b/solution/1200-1299/1250.Check If It Is a Good Array/README_EN.md @@ -78,12 +78,16 @@ The time complexity is $O(n + \log m)$, and the space complexity is $O(1)$. Wher +#### Python3 + ```python class Solution: def isGoodArray(self, nums: List[int]) -> bool: return reduce(gcd, nums) == 1 ``` +#### Java + ```java class Solution { public boolean isGoodArray(int[] nums) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func isGoodArray(nums []int) bool { g := 0 diff --git a/solution/1200-1299/1251.Average Selling Price/README.md b/solution/1200-1299/1251.Average Selling Price/README.md index ae33dd2a04fb2..aabacf6acf532 100644 --- a/solution/1200-1299/1251.Average Selling Price/README.md +++ b/solution/1200-1299/1251.Average Selling Price/README.md @@ -102,6 +102,8 @@ UnitsSold table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1200-1299/1251.Average Selling Price/README_EN.md b/solution/1200-1299/1251.Average Selling Price/README_EN.md index 00ecb79fb1fa5..99af8bc2cbc5f 100644 --- a/solution/1200-1299/1251.Average Selling Price/README_EN.md +++ b/solution/1200-1299/1251.Average Selling Price/README_EN.md @@ -104,6 +104,8 @@ We can use a left join to join the `Prices` table and the `UnitsSold` table on ` +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1200-1299/1252.Cells with Odd Values in a Matrix/README.md b/solution/1200-1299/1252.Cells with Odd Values in a Matrix/README.md index b5e1d5e9652f3..f78096f57e547 100644 --- a/solution/1200-1299/1252.Cells with Odd Values in a Matrix/README.md +++ b/solution/1200-1299/1252.Cells with Odd Values in a Matrix/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int: @@ -100,6 +102,8 @@ class Solution: return sum(v % 2 for row in g for v in row) ``` +#### Java + ```java class Solution { public int oddCells(int m, int n, int[][] indices) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func oddCells(m int, n int, indices [][]int) int { g := make([][]int, m) @@ -183,6 +191,8 @@ func oddCells(m int, n int, indices [][]int) int { +#### Python3 + ```python class Solution: def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int: @@ -194,6 +204,8 @@ class Solution: return sum((i + j) % 2 for i in row for j in col) ``` +#### Java + ```java class Solution { public int oddCells(int m, int n, int[][] indices) { @@ -215,6 +227,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -234,6 +248,8 @@ public: }; ``` +#### Go + ```go func oddCells(m int, n int, indices [][]int) int { row := make([]int, m) @@ -269,6 +285,8 @@ func oddCells(m int, n int, indices [][]int) int { +#### Python3 + ```python class Solution: def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int: @@ -282,6 +300,8 @@ class Solution: return cnt1 * (n - cnt2) + cnt2 * (m - cnt1) ``` +#### Java + ```java class Solution { public int oddCells(int m, int n, int[][] indices) { @@ -304,6 +324,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -323,6 +345,8 @@ public: }; ``` +#### Go + ```go func oddCells(m int, n int, indices [][]int) int { row := make([]int, m) diff --git a/solution/1200-1299/1252.Cells with Odd Values in a Matrix/README_EN.md b/solution/1200-1299/1252.Cells with Odd Values in a Matrix/README_EN.md index 26d39027f77bd..bf010312726dd 100644 --- a/solution/1200-1299/1252.Cells with Odd Values in a Matrix/README_EN.md +++ b/solution/1200-1299/1252.Cells with Odd Values in a Matrix/README_EN.md @@ -79,6 +79,8 @@ The time complexity is $O(\text{indices.length} \times (m+n) + mn)$, and the spa +#### Python3 + ```python class Solution: def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int: @@ -91,6 +93,8 @@ class Solution: return sum(v % 2 for row in g for v in row) ``` +#### Java + ```java class Solution { public int oddCells(int m, int n, int[][] indices) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func oddCells(m int, n int, indices [][]int) int { g := make([][]int, m) @@ -174,6 +182,8 @@ The time complexity is $O(\text{indices.length} + mn)$, and the space complexity +#### Python3 + ```python class Solution: def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int: @@ -185,6 +195,8 @@ class Solution: return sum((i + j) % 2 for i in row for j in col) ``` +#### Java + ```java class Solution { public int oddCells(int m, int n, int[][] indices) { @@ -206,6 +218,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -225,6 +239,8 @@ public: }; ``` +#### Go + ```go func oddCells(m int, n int, indices [][]int) int { row := make([]int, m) @@ -260,6 +276,8 @@ The time complexity is $O(\text{indices.length} + m + n)$, and the space complex +#### Python3 + ```python class Solution: def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int: @@ -273,6 +291,8 @@ class Solution: return cnt1 * (n - cnt2) + cnt2 * (m - cnt1) ``` +#### Java + ```java class Solution { public int oddCells(int m, int n, int[][] indices) { @@ -295,6 +315,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -314,6 +336,8 @@ public: }; ``` +#### Go + ```go func oddCells(m int, n int, indices [][]int) int { row := make([]int, m) diff --git a/solution/1200-1299/1253.Reconstruct a 2-Row Binary Matrix/README.md b/solution/1200-1299/1253.Reconstruct a 2-Row Binary Matrix/README.md index 3495facad9efb..034f4ad35b929 100644 --- a/solution/1200-1299/1253.Reconstruct a 2-Row Binary Matrix/README.md +++ b/solution/1200-1299/1253.Reconstruct a 2-Row Binary Matrix/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def reconstructMatrix( @@ -112,6 +114,8 @@ class Solution: return ans if lower == upper == 0 else [] ``` +#### Java + ```java class Solution { public List> reconstructMatrix(int upper, int lower, int[] colsum) { @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func reconstructMatrix(upper int, lower int, colsum []int) [][]int { n := len(colsum) @@ -207,6 +215,8 @@ func reconstructMatrix(upper int, lower int, colsum []int) [][]int { } ``` +#### TypeScript + ```ts function reconstructMatrix(upper: number, lower: number, colsum: number[]): number[][] { const n = colsum.length; diff --git a/solution/1200-1299/1253.Reconstruct a 2-Row Binary Matrix/README_EN.md b/solution/1200-1299/1253.Reconstruct a 2-Row Binary Matrix/README_EN.md index bd8842af90b7d..cc53af3be2b14 100644 --- a/solution/1200-1299/1253.Reconstruct a 2-Row Binary Matrix/README_EN.md +++ b/solution/1200-1299/1253.Reconstruct a 2-Row Binary Matrix/README_EN.md @@ -92,6 +92,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $colsum$. Ig +#### Python3 + ```python class Solution: def reconstructMatrix( @@ -115,6 +117,8 @@ class Solution: return ans if lower == upper == 0 else [] ``` +#### Java + ```java class Solution { public List> reconstructMatrix(int upper, int lower, int[] colsum) { @@ -147,6 +151,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go func reconstructMatrix(upper int, lower int, colsum []int) [][]int { n := len(colsum) @@ -210,6 +218,8 @@ func reconstructMatrix(upper int, lower int, colsum []int) [][]int { } ``` +#### TypeScript + ```ts function reconstructMatrix(upper: number, lower: number, colsum: number[]): number[][] { const n = colsum.length; diff --git a/solution/1200-1299/1254.Number of Closed Islands/README.md b/solution/1200-1299/1254.Number of Closed Islands/README.md index cb10ed45ed801..8cd90729dbd83 100644 --- a/solution/1200-1299/1254.Number of Closed Islands/README.md +++ b/solution/1200-1299/1254.Number of Closed Islands/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def closedIsland(self, grid: List[List[int]]) -> int: @@ -102,6 +104,8 @@ class Solution: return sum(grid[i][j] == 0 and dfs(i, j) for i in range(m) for j in range(n)) ``` +#### Java + ```java class Solution { private int m; @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go func closedIsland(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -196,6 +204,8 @@ func closedIsland(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function closedIsland(grid: number[][]): number { const m = grid.length; @@ -224,6 +234,8 @@ function closedIsland(grid: number[][]): number { } ``` +#### C# + ```cs public class Solution { private int m; @@ -280,6 +292,8 @@ public class Solution { +#### Python3 + ```python class UnionFind: def __init__(self, n: int): @@ -322,6 +336,8 @@ class Solution: return ans ``` +#### Java + ```java class UnionFind { private int[] p; @@ -389,6 +405,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -453,6 +471,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p, size []int @@ -517,6 +537,8 @@ func closedIsland(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function closedIsland(grid: number[][]): number { const m = grid.length; @@ -582,6 +604,8 @@ class UnionFind { } ``` +#### C# + ```cs class UnionFind { private int[] p; diff --git a/solution/1200-1299/1254.Number of Closed Islands/README_EN.md b/solution/1200-1299/1254.Number of Closed Islands/README_EN.md index 3f241e94b64fb..fa7658ca551a7 100644 --- a/solution/1200-1299/1254.Number of Closed Islands/README_EN.md +++ b/solution/1200-1299/1254.Number of Closed Islands/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def closedIsland(self, grid: List[List[int]]) -> int: @@ -100,6 +102,8 @@ class Solution: return sum(grid[i][j] == 0 and dfs(i, j) for i in range(m) for j in range(n)) ``` +#### Java + ```java class Solution { private int m; @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func closedIsland(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -194,6 +202,8 @@ func closedIsland(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function closedIsland(grid: number[][]): number { const m = grid.length; @@ -222,6 +232,8 @@ function closedIsland(grid: number[][]): number { } ``` +#### C# + ```cs public class Solution { private int m; @@ -278,6 +290,8 @@ The time complexity is $O(m \times n \times \alpha(m \times n))$, and the space +#### Python3 + ```python class UnionFind: def __init__(self, n: int): @@ -320,6 +334,8 @@ class Solution: return ans ``` +#### Java + ```java class UnionFind { private int[] p; @@ -387,6 +403,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -451,6 +469,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p, size []int @@ -515,6 +535,8 @@ func closedIsland(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function closedIsland(grid: number[][]): number { const m = grid.length; @@ -580,6 +602,8 @@ class UnionFind { } ``` +#### C# + ```cs class UnionFind { private int[] p; diff --git a/solution/1200-1299/1255.Maximum Score Words Formed by Letters/README.md b/solution/1200-1299/1255.Maximum Score Words Formed by Letters/README.md index 6f8ba0fed9367..f31d5a19c4e12 100644 --- a/solution/1200-1299/1255.Maximum Score Words Formed by Letters/README.md +++ b/solution/1200-1299/1255.Maximum Score Words Formed by Letters/README.md @@ -98,6 +98,8 @@ tags: +#### Python3 + ```python class Solution: def maxScoreWords( @@ -114,6 +116,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxScoreWords(String[] words, char[] letters, int[] score) { @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -187,6 +193,8 @@ public: }; ``` +#### Go + ```go func maxScoreWords(words []string, letters []byte, score []int) (ans int) { cnt := [26]int{} diff --git a/solution/1200-1299/1255.Maximum Score Words Formed by Letters/README_EN.md b/solution/1200-1299/1255.Maximum Score Words Formed by Letters/README_EN.md index c2e9650f678f2..14d128823cff3 100644 --- a/solution/1200-1299/1255.Maximum Score Words Formed by Letters/README_EN.md +++ b/solution/1200-1299/1255.Maximum Score Words Formed by Letters/README_EN.md @@ -91,6 +91,8 @@ The time complexity is $(2^n \times n \times M)$, and the space complexity is $O +#### Python3 + ```python class Solution: def maxScoreWords( @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxScoreWords(String[] words, char[] letters, int[] score) { @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -180,6 +186,8 @@ public: }; ``` +#### Go + ```go func maxScoreWords(words []string, letters []byte, score []int) (ans int) { cnt := [26]int{} diff --git a/solution/1200-1299/1256.Encode Number/README.md b/solution/1200-1299/1256.Encode Number/README.md index 519aaef48e888..6c10ebb8183b6 100644 --- a/solution/1200-1299/1256.Encode Number/README.md +++ b/solution/1200-1299/1256.Encode Number/README.md @@ -62,12 +62,16 @@ tags: +#### Python3 + ```python class Solution: def encode(self, num: int) -> str: return bin(num + 1)[3:] ``` +#### Java + ```java class Solution { public String encode(int num) { @@ -76,6 +80,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -91,6 +97,8 @@ public: }; ``` +#### Go + ```go func encode(num int) string { num++ @@ -99,6 +107,8 @@ func encode(num int) string { } ``` +#### TypeScript + ```ts function encode(num: number): string { ++num; diff --git a/solution/1200-1299/1256.Encode Number/README_EN.md b/solution/1200-1299/1256.Encode Number/README_EN.md index c975cefabf9cb..43b8d3ed61ded 100644 --- a/solution/1200-1299/1256.Encode Number/README_EN.md +++ b/solution/1200-1299/1256.Encode Number/README_EN.md @@ -72,12 +72,16 @@ The time complexity is $O(\log n)$, and the space complexity is $O(\log n)$. Whe +#### Python3 + ```python class Solution: def encode(self, num: int) -> str: return bin(num + 1)[3:] ``` +#### Java + ```java class Solution { public String encode(int num) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,6 +107,8 @@ public: }; ``` +#### Go + ```go func encode(num int) string { num++ @@ -109,6 +117,8 @@ func encode(num int) string { } ``` +#### TypeScript + ```ts function encode(num: number): string { ++num; diff --git a/solution/1200-1299/1257.Smallest Common Region/README.md b/solution/1200-1299/1257.Smallest Common Region/README.md index 781721302d1bd..22e842a30b49e 100644 --- a/solution/1200-1299/1257.Smallest Common Region/README.md +++ b/solution/1200-1299/1257.Smallest Common Region/README.md @@ -69,6 +69,8 @@ region2 = "New York" +#### Python3 + ```python class Solution: def findSmallestRegion( @@ -89,6 +91,8 @@ class Solution: return region1 ``` +#### Java + ```java class Solution { public String findSmallestRegion(List> regions, String region1, String region2) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func findSmallestRegion(regions [][]string, region1 string, region2 string) string { m := make(map[string]string) diff --git a/solution/1200-1299/1257.Smallest Common Region/README_EN.md b/solution/1200-1299/1257.Smallest Common Region/README_EN.md index c945f6f6a2043..a0a31909445cb 100644 --- a/solution/1200-1299/1257.Smallest Common Region/README_EN.md +++ b/solution/1200-1299/1257.Smallest Common Region/README_EN.md @@ -76,6 +76,8 @@ region2 = "New York" +#### Python3 + ```python class Solution: def findSmallestRegion( @@ -96,6 +98,8 @@ class Solution: return region1 ``` +#### Java + ```java class Solution { public String findSmallestRegion(List> regions, String region1, String region2) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func findSmallestRegion(regions [][]string, region1 string, region2 string) string { m := make(map[string]string) diff --git a/solution/1200-1299/1258.Synonymous Sentences/README.md b/solution/1200-1299/1258.Synonymous Sentences/README.md index 3840a2ba3f0fe..2b00239e3e600 100644 --- a/solution/1200-1299/1258.Synonymous Sentences/README.md +++ b/solution/1200-1299/1258.Synonymous Sentences/README.md @@ -77,6 +77,8 @@ text = "I am happy today but was sad yesterday" +#### Python3 + ```python class UnionFind: def __init__(self, n): @@ -133,6 +135,8 @@ class Solution: return ans ``` +#### Java + ```java class UnionFind { private int[] p; @@ -225,6 +229,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -323,6 +329,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p, size []int diff --git a/solution/1200-1299/1258.Synonymous Sentences/README_EN.md b/solution/1200-1299/1258.Synonymous Sentences/README_EN.md index b2b49c1cf2a4b..5e6126ae5a0c2 100644 --- a/solution/1200-1299/1258.Synonymous Sentences/README_EN.md +++ b/solution/1200-1299/1258.Synonymous Sentences/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$. Where $n$ i +#### Python3 + ```python class UnionFind: def __init__(self, n): @@ -132,6 +134,8 @@ class Solution: return ans ``` +#### Java + ```java class UnionFind { private int[] p; @@ -224,6 +228,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -322,6 +328,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p, size []int diff --git a/solution/1200-1299/1259.Handshakes That Don't Cross/README.md b/solution/1200-1299/1259.Handshakes That Don't Cross/README.md index 5589c2e6e53bf..30a6f61fd1431 100644 --- a/solution/1200-1299/1259.Handshakes That Don't Cross/README.md +++ b/solution/1200-1299/1259.Handshakes That Don't Cross/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfWays(self, numPeople: int) -> int: @@ -104,6 +106,8 @@ class Solution: return dfs(numPeople) ``` +#### Java + ```java class Solution { private int[] f; @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func numberOfWays(numPeople int) int { const mod int = 1e9 + 7 @@ -177,6 +185,8 @@ func numberOfWays(numPeople int) int { } ``` +#### TypeScript + ```ts function numberOfWays(numPeople: number): number { const mod = 10 ** 9 + 7; diff --git a/solution/1200-1299/1259.Handshakes That Don't Cross/README_EN.md b/solution/1200-1299/1259.Handshakes That Don't Cross/README_EN.md index 4e8c242205258..2c27fbc0356cc 100644 --- a/solution/1200-1299/1259.Handshakes That Don't Cross/README_EN.md +++ b/solution/1200-1299/1259.Handshakes That Don't Cross/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$. Where $n$ i +#### Python3 + ```python class Solution: def numberOfWays(self, numPeople: int) -> int: @@ -88,6 +90,8 @@ class Solution: return dfs(numPeople) ``` +#### Java + ```java class Solution { private int[] f; @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func numberOfWays(numPeople int) int { const mod int = 1e9 + 7 @@ -161,6 +169,8 @@ func numberOfWays(numPeople int) int { } ``` +#### TypeScript + ```ts function numberOfWays(numPeople: number): number { const mod = 10 ** 9 + 7; diff --git a/solution/1200-1299/1260.Shift 2D Grid/README.md b/solution/1200-1299/1260.Shift 2D Grid/README.md index cab4fd3983400..7fd9ccc6ef18b 100644 --- a/solution/1200-1299/1260.Shift 2D Grid/README.md +++ b/solution/1200-1299/1260.Shift 2D Grid/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def shiftGrid(self, grid: List[List[int]], k: int) -> List[List[int]]: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> shiftGrid(int[][] grid, int k) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func shiftGrid(grid [][]int, k int) [][]int { m, n := len(grid), len(grid[0]) @@ -160,6 +168,8 @@ func shiftGrid(grid [][]int, k int) [][]int { } ``` +#### TypeScript + ```ts function shiftGrid(grid: number[][], k: number): number[][] { const [m, n] = [grid.length, grid[0].length]; diff --git a/solution/1200-1299/1260.Shift 2D Grid/README_EN.md b/solution/1200-1299/1260.Shift 2D Grid/README_EN.md index e3953fa68f4be..597c7d991aaaf 100644 --- a/solution/1200-1299/1260.Shift 2D Grid/README_EN.md +++ b/solution/1200-1299/1260.Shift 2D Grid/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(m \times n)$, where $m$ and $n$ are the number of rows +#### Python3 + ```python class Solution: def shiftGrid(self, grid: List[List[int]], k: int) -> List[List[int]]: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> shiftGrid(int[][] grid, int k) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func shiftGrid(grid [][]int, k int) [][]int { m, n := len(grid), len(grid[0]) @@ -154,6 +162,8 @@ func shiftGrid(grid [][]int, k int) [][]int { } ``` +#### TypeScript + ```ts function shiftGrid(grid: number[][], k: number): number[][] { const [m, n] = [grid.length, grid[0].length]; diff --git a/solution/1200-1299/1261.Find Elements in a Contaminated Binary Tree/README.md b/solution/1200-1299/1261.Find Elements in a Contaminated Binary Tree/README.md index d0b8c835f856e..0be6876b67ebf 100644 --- a/solution/1200-1299/1261.Find Elements in a Contaminated Binary Tree/README.md +++ b/solution/1200-1299/1261.Find Elements in a Contaminated Binary Tree/README.md @@ -114,6 +114,8 @@ findElements.find(5); // return True +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -146,6 +148,8 @@ class FindElements: # param_1 = obj.find(target) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -194,6 +198,8 @@ class FindElements { */ ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -240,6 +246,8 @@ private: */ ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -283,6 +291,8 @@ func (this *FindElements) Find(target int) bool { */ ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/1200-1299/1261.Find Elements in a Contaminated Binary Tree/README_EN.md b/solution/1200-1299/1261.Find Elements in a Contaminated Binary Tree/README_EN.md index 71842512589ac..4f59629dab4af 100644 --- a/solution/1200-1299/1261.Find Elements in a Contaminated Binary Tree/README_EN.md +++ b/solution/1200-1299/1261.Find Elements in a Contaminated Binary Tree/README_EN.md @@ -109,6 +109,8 @@ In terms of time complexity, it takes $O(n)$ time to traverse the binary tree du +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -141,6 +143,8 @@ class FindElements: # param_1 = obj.find(target) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -189,6 +193,8 @@ class FindElements { */ ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -235,6 +241,8 @@ private: */ ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -278,6 +286,8 @@ func (this *FindElements) Find(target int) bool { */ ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/1200-1299/1262.Greatest Sum Divisible by Three/README.md b/solution/1200-1299/1262.Greatest Sum Divisible by Three/README.md index ff7909d9884cc..e80e06363efb0 100644 --- a/solution/1200-1299/1262.Greatest Sum Divisible by Three/README.md +++ b/solution/1200-1299/1262.Greatest Sum Divisible by Three/README.md @@ -86,6 +86,8 @@ $$ +#### Python3 + ```python class Solution: def maxSumDivThree(self, nums: List[int]) -> int: @@ -98,6 +100,8 @@ class Solution: return f[n][0] ``` +#### Java + ```java class Solution { public int maxSumDivThree(int[] nums) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func maxSumDivThree(nums []int) int { n := len(nums) @@ -152,6 +160,8 @@ func maxSumDivThree(nums []int) int { } ``` +#### TypeScript + ```ts function maxSumDivThree(nums: number[]): number { const n = nums.length; @@ -180,6 +190,8 @@ function maxSumDivThree(nums: number[]): number { +#### Python3 + ```python class Solution: def maxSumDivThree(self, nums: List[int]) -> int: @@ -192,6 +204,8 @@ class Solution: return f[0] ``` +#### Java + ```java class Solution { public int maxSumDivThree(int[] nums) { @@ -209,6 +223,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -227,6 +243,8 @@ public: }; ``` +#### Go + ```go func maxSumDivThree(nums []int) int { const inf = 1 << 30 @@ -242,6 +260,8 @@ func maxSumDivThree(nums []int) int { } ``` +#### TypeScript + ```ts function maxSumDivThree(nums: number[]): number { const inf = 1 << 30; diff --git a/solution/1200-1299/1262.Greatest Sum Divisible by Three/README_EN.md b/solution/1200-1299/1262.Greatest Sum Divisible by Three/README_EN.md index dba4c3e5ced01..3aaba7ffb3e06 100644 --- a/solution/1200-1299/1262.Greatest Sum Divisible by Three/README_EN.md +++ b/solution/1200-1299/1262.Greatest Sum Divisible by Three/README_EN.md @@ -84,6 +84,8 @@ Note that the value of $f[i][j]$ is only related to $f[i-1][j]$ and $f[i-1][(j-x +#### Python3 + ```python class Solution: def maxSumDivThree(self, nums: List[int]) -> int: @@ -96,6 +98,8 @@ class Solution: return f[n][0] ``` +#### Java + ```java class Solution { public int maxSumDivThree(int[] nums) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func maxSumDivThree(nums []int) int { n := len(nums) @@ -150,6 +158,8 @@ func maxSumDivThree(nums []int) int { } ``` +#### TypeScript + ```ts function maxSumDivThree(nums: number[]): number { const n = nums.length; @@ -178,6 +188,8 @@ function maxSumDivThree(nums: number[]): number { +#### Python3 + ```python class Solution: def maxSumDivThree(self, nums: List[int]) -> int: @@ -190,6 +202,8 @@ class Solution: return f[0] ``` +#### Java + ```java class Solution { public int maxSumDivThree(int[] nums) { @@ -207,6 +221,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -225,6 +241,8 @@ public: }; ``` +#### Go + ```go func maxSumDivThree(nums []int) int { const inf = 1 << 30 @@ -240,6 +258,8 @@ func maxSumDivThree(nums []int) int { } ``` +#### TypeScript + ```ts function maxSumDivThree(nums: number[]): number { const inf = 1 << 30; diff --git a/solution/1200-1299/1263.Minimum Moves to Move a Box to Their Target Location/README.md b/solution/1200-1299/1263.Minimum Moves to Move a Box to Their Target Location/README.md index ff632ac53bc30..76b7f2cad495f 100644 --- a/solution/1200-1299/1263.Minimum Moves to Move a Box to Their Target Location/README.md +++ b/solution/1200-1299/1263.Minimum Moves to Move a Box to Their Target Location/README.md @@ -126,6 +126,8 @@ tags: +#### Python3 + ```python class Solution: def minPushBox(self, grid: List[List[str]]) -> int: @@ -168,6 +170,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { private int m; @@ -236,6 +240,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -294,6 +300,8 @@ public: }; ``` +#### Go + ```go func minPushBox(grid [][]byte) int { m, n := len(grid), len(grid[0]) @@ -350,6 +358,8 @@ func minPushBox(grid [][]byte) int { } ``` +#### TypeScript + ```ts function minPushBox(grid: string[][]): number { const [m, n] = [grid.length, grid[0].length]; diff --git a/solution/1200-1299/1263.Minimum Moves to Move a Box to Their Target Location/README_EN.md b/solution/1200-1299/1263.Minimum Moves to Move a Box to Their Target Location/README_EN.md index 315e265e3024b..5dc21b41b94c8 100644 --- a/solution/1200-1299/1263.Minimum Moves to Move a Box to Their Target Location/README_EN.md +++ b/solution/1200-1299/1263.Minimum Moves to Move a Box to Their Target Location/README_EN.md @@ -122,6 +122,8 @@ The time complexity is $O(m^2 \times n^2)$, and the space complexity is $O(m^2 \ +#### Python3 + ```python class Solution: def minPushBox(self, grid: List[List[str]]) -> int: @@ -164,6 +166,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { private int m; @@ -232,6 +236,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -290,6 +296,8 @@ public: }; ``` +#### Go + ```go func minPushBox(grid [][]byte) int { m, n := len(grid), len(grid[0]) @@ -346,6 +354,8 @@ func minPushBox(grid [][]byte) int { } ``` +#### TypeScript + ```ts function minPushBox(grid: string[][]): number { const [m, n] = [grid.length, grid[0].length]; diff --git a/solution/1200-1299/1264.Page Recommendations/README.md b/solution/1200-1299/1264.Page Recommendations/README.md index 53a1bbeddc9f8..1280861a0574c 100644 --- a/solution/1200-1299/1264.Page Recommendations/README.md +++ b/solution/1200-1299/1264.Page Recommendations/README.md @@ -114,6 +114,8 @@ Likes table: +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -139,6 +141,8 @@ WHERE page_id NOT IN (SELECT page_id FROM Likes WHERE user_id = 1); +#### MySQL + ```sql # Write your MySQL query statement below SELECT DISTINCT page_id AS recommended_page diff --git a/solution/1200-1299/1264.Page Recommendations/README_EN.md b/solution/1200-1299/1264.Page Recommendations/README_EN.md index 0608f1e7e173d..578237e2f6d91 100644 --- a/solution/1200-1299/1264.Page Recommendations/README_EN.md +++ b/solution/1200-1299/1264.Page Recommendations/README_EN.md @@ -112,6 +112,8 @@ First, we query all users who are friends with `user_id = 1` and record them in +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -137,6 +139,8 @@ WHERE page_id NOT IN (SELECT page_id FROM Likes WHERE user_id = 1); +#### MySQL + ```sql # Write your MySQL query statement below SELECT DISTINCT page_id AS recommended_page diff --git a/solution/1200-1299/1265.Print Immutable Linked List in Reverse/README.md b/solution/1200-1299/1265.Print Immutable Linked List in Reverse/README.md index 681a7c147e945..23c76776c24e4 100644 --- a/solution/1200-1299/1265.Print Immutable Linked List in Reverse/README.md +++ b/solution/1200-1299/1265.Print Immutable Linked List in Reverse/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python # """ # This is the ImmutableListNode's API interface. @@ -111,6 +113,8 @@ class Solution: head.printValue() ``` +#### Java + ```java /** * // This is the ImmutableListNode's API interface. @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * // This is the ImmutableListNode's API interface. @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go /* Below is the interface for ImmutableListNode, which is already defined for you. * @@ -177,6 +185,8 @@ func printLinkedListInReverse(head ImmutableListNode) { } ``` +#### TypeScript + ```ts /** * // This is the ImmutableListNode's API interface. @@ -196,6 +206,8 @@ function printLinkedListInReverse(head: ImmutableListNode) { } ``` +#### C# + ```cs /** * // This is the ImmutableListNode's API interface. diff --git a/solution/1200-1299/1265.Print Immutable Linked List in Reverse/README_EN.md b/solution/1200-1299/1265.Print Immutable Linked List in Reverse/README_EN.md index 6f7a5e38fb61a..6a272f13a4330 100644 --- a/solution/1200-1299/1265.Print Immutable Linked List in Reverse/README_EN.md +++ b/solution/1200-1299/1265.Print Immutable Linked List in Reverse/README_EN.md @@ -92,6 +92,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python # """ # This is the ImmutableListNode's API interface. @@ -109,6 +111,8 @@ class Solution: head.printValue() ``` +#### Java + ```java /** * // This is the ImmutableListNode's API interface. @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * // This is the ImmutableListNode's API interface. @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go /* Below is the interface for ImmutableListNode, which is already defined for you. * @@ -175,6 +183,8 @@ func printLinkedListInReverse(head ImmutableListNode) { } ``` +#### TypeScript + ```ts /** * // This is the ImmutableListNode's API interface. @@ -194,6 +204,8 @@ function printLinkedListInReverse(head: ImmutableListNode) { } ``` +#### C# + ```cs /** * // This is the ImmutableListNode's API interface. diff --git a/solution/1200-1299/1266.Minimum Time Visiting All Points/README.md b/solution/1200-1299/1266.Minimum Time Visiting All Points/README.md index f82d823dbd28f..2cde507cca8bd 100644 --- a/solution/1200-1299/1266.Minimum Time Visiting All Points/README.md +++ b/solution/1200-1299/1266.Minimum Time Visiting All Points/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def minTimeToVisitAllPoints(self, points: List[List[int]]) -> int: @@ -94,6 +96,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public int minTimeToVisitAllPoints(int[][] points) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func minTimeToVisitAllPoints(points [][]int) (ans int) { for i, p := range points[1:] { @@ -141,6 +149,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function minTimeToVisitAllPoints(points: number[][]): number { let ans = 0; @@ -153,6 +163,8 @@ function minTimeToVisitAllPoints(points: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_time_to_visit_all_points(points: Vec>) -> i32 { @@ -168,6 +180,8 @@ impl Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) diff --git a/solution/1200-1299/1266.Minimum Time Visiting All Points/README_EN.md b/solution/1200-1299/1266.Minimum Time Visiting All Points/README_EN.md index f55529ae7f141..d73f4a85c8be1 100644 --- a/solution/1200-1299/1266.Minimum Time Visiting All Points/README_EN.md +++ b/solution/1200-1299/1266.Minimum Time Visiting All Points/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n)$, where $n$ is the number of points. The space comp +#### Python3 + ```python class Solution: def minTimeToVisitAllPoints(self, points: List[List[int]]) -> int: @@ -92,6 +94,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public int minTimeToVisitAllPoints(int[][] points) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func minTimeToVisitAllPoints(points [][]int) (ans int) { for i, p := range points[1:] { @@ -139,6 +147,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function minTimeToVisitAllPoints(points: number[][]): number { let ans = 0; @@ -151,6 +161,8 @@ function minTimeToVisitAllPoints(points: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_time_to_visit_all_points(points: Vec>) -> i32 { @@ -166,6 +178,8 @@ impl Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) diff --git a/solution/1200-1299/1267.Count Servers that Communicate/README.md b/solution/1200-1299/1267.Count Servers that Communicate/README.md index bb8e5626c3872..778fb5808af77 100644 --- a/solution/1200-1299/1267.Count Servers that Communicate/README.md +++ b/solution/1200-1299/1267.Count Servers that Communicate/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def countServers(self, grid: List[List[int]]) -> int: @@ -103,6 +105,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public int countServers(int[][] grid) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func countServers(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -178,6 +186,8 @@ func countServers(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function countServers(grid: number[][]): number { const m = grid.length; diff --git a/solution/1200-1299/1267.Count Servers that Communicate/README_EN.md b/solution/1200-1299/1267.Count Servers that Communicate/README_EN.md index 24f22ed03e045..e137c8e6227ba 100644 --- a/solution/1200-1299/1267.Count Servers that Communicate/README_EN.md +++ b/solution/1200-1299/1267.Count Servers that Communicate/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m + n)$. +#### Python3 + ```python class Solution: def countServers(self, grid: List[List[int]]) -> int: @@ -102,6 +104,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public int countServers(int[][] grid) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func countServers(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -177,6 +185,8 @@ func countServers(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function countServers(grid: number[][]): number { const m = grid.length; diff --git a/solution/1200-1299/1268.Search Suggestions System/README.md b/solution/1200-1299/1268.Search Suggestions System/README.md index 4c976d88fd8c7..5ef6041de39e5 100644 --- a/solution/1200-1299/1268.Search Suggestions System/README.md +++ b/solution/1200-1299/1268.Search Suggestions System/README.md @@ -99,6 +99,8 @@ tags: +#### Python3 + ```python class Trie: def __init__(self): @@ -138,6 +140,8 @@ class Solution: return [[products[i] for i in v] for v in trie.search(searchWord)] ``` +#### Java + ```java class Trie { Trie[] children = new Trie[26]; @@ -194,6 +198,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -252,6 +258,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [26]*Trie diff --git a/solution/1200-1299/1268.Search Suggestions System/README_EN.md b/solution/1200-1299/1268.Search Suggestions System/README_EN.md index 6273a081e52f2..1e018587523bb 100644 --- a/solution/1200-1299/1268.Search Suggestions System/README_EN.md +++ b/solution/1200-1299/1268.Search Suggestions System/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(L \times \log n + m)$, and the space complexity is $O( +#### Python3 + ```python class Trie: def __init__(self): @@ -123,6 +125,8 @@ class Solution: return [[products[i] for i in v] for v in trie.search(searchWord)] ``` +#### Java + ```java class Trie { Trie[] children = new Trie[26]; @@ -179,6 +183,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -237,6 +243,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [26]*Trie diff --git a/solution/1200-1299/1269.Number of Ways to Stay in the Same Place After Some Steps/README.md b/solution/1200-1299/1269.Number of Ways to Stay in the Same Place After Some Steps/README.md index c900a01764608..28785d07450e9 100644 --- a/solution/1200-1299/1269.Number of Ways to Stay in the Same Place After Some Steps/README.md +++ b/solution/1200-1299/1269.Number of Ways to Stay in the Same Place After Some Steps/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def numWays(self, steps: int, arrLen: int) -> int: @@ -109,6 +111,8 @@ class Solution: return dfs(0, steps) ``` +#### Java + ```java class Solution { private Integer[][] f; @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func numWays(steps int, arrLen int) int { const mod int = 1e9 + 7 @@ -200,6 +208,8 @@ func numWays(steps int, arrLen int) int { } ``` +#### TypeScript + ```ts function numWays(steps: number, arrLen: number): number { const f = Array.from({ length: steps }, () => Array(steps + 1).fill(-1)); diff --git a/solution/1200-1299/1269.Number of Ways to Stay in the Same Place After Some Steps/README_EN.md b/solution/1200-1299/1269.Number of Ways to Stay in the Same Place After Some Steps/README_EN.md index f091c9680c09f..1a331ce9be2a5 100644 --- a/solution/1200-1299/1269.Number of Ways to Stay in the Same Place After Some Steps/README_EN.md +++ b/solution/1200-1299/1269.Number of Ways to Stay in the Same Place After Some Steps/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(steps \times steps)$, and the space complexity is $O(s +#### Python3 + ```python class Solution: def numWays(self, steps: int, arrLen: int) -> int: @@ -103,6 +105,8 @@ class Solution: return dfs(0, steps) ``` +#### Java + ```java class Solution { private Integer[][] f; @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func numWays(steps int, arrLen int) int { const mod int = 1e9 + 7 @@ -194,6 +202,8 @@ func numWays(steps int, arrLen int) int { } ``` +#### TypeScript + ```ts function numWays(steps: number, arrLen: number): number { const f = Array.from({ length: steps }, () => Array(steps + 1).fill(-1)); diff --git a/solution/1200-1299/1270.All People Report to the Given Manager/README.md b/solution/1200-1299/1270.All People Report to the Given Manager/README.md index a97696f53dccd..24ebae09e8401 100644 --- a/solution/1200-1299/1270.All People Report to the Given Manager/README.md +++ b/solution/1200-1299/1270.All People Report to the Given Manager/README.md @@ -91,6 +91,8 @@ employee_id 是 3, 8 ,9 的职员不会直接或间接的汇报给公司 CEO +#### MySQL + ```sql # Write your MySQL query statement below SELECT e1.employee_id diff --git a/solution/1200-1299/1270.All People Report to the Given Manager/README_EN.md b/solution/1200-1299/1270.All People Report to the Given Manager/README_EN.md index c2c1032d2df82..17bc3a588f25f 100644 --- a/solution/1200-1299/1270.All People Report to the Given Manager/README_EN.md +++ b/solution/1200-1299/1270.All People Report to the Given Manager/README_EN.md @@ -90,6 +90,8 @@ Specifically, we first use a join to find the `manager_id` of the superior manag +#### MySQL + ```sql # Write your MySQL query statement below SELECT e1.employee_id diff --git a/solution/1200-1299/1271.Hexspeak/README.md b/solution/1200-1299/1271.Hexspeak/README.md index 4ec7ab45537de..2310294eeca6c 100644 --- a/solution/1200-1299/1271.Hexspeak/README.md +++ b/solution/1200-1299/1271.Hexspeak/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def toHexspeak(self, num: str) -> str: @@ -72,6 +74,8 @@ class Solution: return t if all(c in s for c in t) else 'ERROR' ``` +#### Java + ```java class Solution { private static final Set S = Set.of('A', 'B', 'C', 'D', 'E', 'F', 'I', 'O'); @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func toHexspeak(num string) string { x, _ := strconv.Atoi(num) diff --git a/solution/1200-1299/1271.Hexspeak/README_EN.md b/solution/1200-1299/1271.Hexspeak/README_EN.md index 45685016e30bc..71773c3fd2ce1 100644 --- a/solution/1200-1299/1271.Hexspeak/README_EN.md +++ b/solution/1200-1299/1271.Hexspeak/README_EN.md @@ -62,6 +62,8 @@ The time complexity is $O(\log n)$, where $n$ is the size of the decimal number +#### Python3 + ```python class Solution: def toHexspeak 🔒(self, num: str) -> str: @@ -70,6 +72,8 @@ class Solution: return t if all(c in s for c in t) else 'ERROR' ``` +#### Java + ```java class Solution { private static final Set S = Set.of('A', 'B', 'C', 'D', 'E', 'F', 'I', 'O'); @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func toHexspeak 🔒(num string) string { x, _ := strconv.Atoi(num) diff --git a/solution/1200-1299/1272.Remove Interval/README.md b/solution/1200-1299/1272.Remove Interval/README.md index 55eda3b00570b..c59f253246b16 100644 --- a/solution/1200-1299/1272.Remove Interval/README.md +++ b/solution/1200-1299/1272.Remove Interval/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def removeInterval( @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> removeInterval(int[][] intervals, int[] toBeRemoved) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func removeInterval(intervals [][]int, toBeRemoved []int) (ans [][]int) { x, y := toBeRemoved[0], toBeRemoved[1] diff --git a/solution/1200-1299/1272.Remove Interval/README_EN.md b/solution/1200-1299/1272.Remove Interval/README_EN.md index fc5d7046c381b..4750560b3673c 100644 --- a/solution/1200-1299/1272.Remove Interval/README_EN.md +++ b/solution/1200-1299/1272.Remove Interval/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(n)$, where $n$ is the length of the interval list. The +#### Python3 + ```python class Solution: def removeInterval( @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> removeInterval(int[][] intervals, int[] toBeRemoved) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func removeInterval(intervals [][]int, toBeRemoved []int) (ans [][]int) { x, y := toBeRemoved[0], toBeRemoved[1] diff --git a/solution/1200-1299/1273.Delete Tree Nodes/README.md b/solution/1200-1299/1273.Delete Tree Nodes/README.md index f251172b95da3..6af9a4d9b4a81 100644 --- a/solution/1200-1299/1273.Delete Tree Nodes/README.md +++ b/solution/1200-1299/1273.Delete Tree Nodes/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def deleteTreeNodes(self, nodes: int, parent: List[int], value: List[int]) -> int: @@ -112,6 +114,8 @@ class Solution: return dfs(0)[1] ``` +#### Java + ```java class Solution { private List[] g; @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func deleteTreeNodes(nodes int, parent []int, value []int) int { g := make([][]int, nodes) diff --git a/solution/1200-1299/1273.Delete Tree Nodes/README_EN.md b/solution/1200-1299/1273.Delete Tree Nodes/README_EN.md index fa1ddd2dd098d..0d8693f5f00f1 100644 --- a/solution/1200-1299/1273.Delete Tree Nodes/README_EN.md +++ b/solution/1200-1299/1273.Delete Tree Nodes/README_EN.md @@ -79,6 +79,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def deleteTreeNodes(self, nodes: int, parent: List[int], value: List[int]) -> int: @@ -98,6 +100,8 @@ class Solution: return dfs(0)[1] ``` +#### Java + ```java class Solution { private List[] g; @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func deleteTreeNodes(nodes int, parent []int, value []int) int { g := make([][]int, nodes) diff --git a/solution/1200-1299/1274.Number of Ships in a Rectangle/README.md b/solution/1200-1299/1274.Number of Ships in a Rectangle/README.md index a9fbd649a0611..e1865aad148d8 100644 --- a/solution/1200-1299/1274.Number of Ships in a Rectangle/README.md +++ b/solution/1200-1299/1274.Number of Ships in a Rectangle/README.md @@ -77,6 +77,8 @@ ships = [[1,1],[2,2],[3,3],[5,5]], topRight = [4,4], bottomLeft = [0,0] +#### Python3 + ```python # """ # This is Sea's API interface. @@ -113,6 +115,8 @@ class Solution: return dfs(topRight, bottomLeft) ``` +#### Java + ```java /** * // This is Sea's API interface. @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * // This is Sea's API interface. @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go /** * // This is Sea's API interface. @@ -212,6 +220,8 @@ func countShips(sea Sea, topRight, bottomLeft []int) int { } ``` +#### TypeScript + ```ts /** * // This is the Sea's API interface. diff --git a/solution/1200-1299/1274.Number of Ships in a Rectangle/README_EN.md b/solution/1200-1299/1274.Number of Ships in a Rectangle/README_EN.md index e583c76410eb2..269b22d426c70 100644 --- a/solution/1200-1299/1274.Number of Ships in a Rectangle/README_EN.md +++ b/solution/1200-1299/1274.Number of Ships in a Rectangle/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(C \times \log \max(m, n))$, and the space complexity i +#### Python3 + ```python # """ # This is Sea's API interface. @@ -107,6 +109,8 @@ class Solution: return dfs(topRight, bottomLeft) ``` +#### Java + ```java /** * // This is Sea's API interface. @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * // This is Sea's API interface. @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go /** * // This is Sea's API interface. @@ -206,6 +214,8 @@ func countShips(sea Sea, topRight, bottomLeft []int) int { } ``` +#### TypeScript + ```ts /** * // This is the Sea's API interface. diff --git a/solution/1200-1299/1275.Find Winner on a Tic Tac Toe Game/README.md b/solution/1200-1299/1275.Find Winner on a Tic Tac Toe Game/README.md index 5d2f6fae41837..deff872c6356f 100644 --- a/solution/1200-1299/1275.Find Winner on a Tic Tac Toe Game/README.md +++ b/solution/1200-1299/1275.Find Winner on a Tic Tac Toe Game/README.md @@ -116,6 +116,8 @@ tags: +#### Python3 + ```python class Solution: def tictactoe(self, moves: List[List[int]]) -> str: @@ -134,6 +136,8 @@ class Solution: return "Draw" if n == 9 else "Pending" ``` +#### Java + ```java class Solution { public String tictactoe(int[][] moves) { @@ -158,6 +162,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -183,6 +189,8 @@ public: }; ``` +#### Go + ```go func tictactoe(moves [][]int) string { n := len(moves) @@ -211,6 +219,8 @@ func tictactoe(moves [][]int) string { } ``` +#### TypeScript + ```ts function tictactoe(moves: number[][]): string { const n = moves.length; diff --git a/solution/1200-1299/1275.Find Winner on a Tic Tac Toe Game/README_EN.md b/solution/1200-1299/1275.Find Winner on a Tic Tac Toe Game/README_EN.md index c3edbd29c6106..47fafd604cc70 100644 --- a/solution/1200-1299/1275.Find Winner on a Tic Tac Toe Game/README_EN.md +++ b/solution/1200-1299/1275.Find Winner on a Tic Tac Toe Game/README_EN.md @@ -90,6 +90,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def tictactoe(self, moves: List[List[int]]) -> str: @@ -108,6 +110,8 @@ class Solution: return "Draw" if n == 9 else "Pending" ``` +#### Java + ```java class Solution { public String tictactoe(int[][] moves) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func tictactoe(moves [][]int) string { n := len(moves) @@ -185,6 +193,8 @@ func tictactoe(moves [][]int) string { } ``` +#### TypeScript + ```ts function tictactoe(moves: number[][]): string { const n = moves.length; diff --git a/solution/1200-1299/1276.Number of Burgers with No Waste of Ingredients/README.md b/solution/1200-1299/1276.Number of Burgers with No Waste of Ingredients/README.md index 06d2ed075dca8..d02a88c19f0f0 100644 --- a/solution/1200-1299/1276.Number of Burgers with No Waste of Ingredients/README.md +++ b/solution/1200-1299/1276.Number of Burgers with No Waste of Ingredients/README.md @@ -107,6 +107,8 @@ $$ +#### Python3 + ```python class Solution: def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]: @@ -116,6 +118,8 @@ class Solution: return [] if k % 2 or y < 0 or x < 0 else [x, y] ``` +#### Java + ```java class Solution { public List numOfBurgers(int tomatoSlices, int cheeseSlices) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func numOfBurgers(tomatoSlices int, cheeseSlices int) []int { k := 4*cheeseSlices - tomatoSlices @@ -151,6 +159,8 @@ func numOfBurgers(tomatoSlices int, cheeseSlices int) []int { } ``` +#### TypeScript + ```ts function numOfBurgers(tomatoSlices: number, cheeseSlices: number): number[] { const k = 4 * cheeseSlices - tomatoSlices; @@ -160,6 +170,8 @@ function numOfBurgers(tomatoSlices: number, cheeseSlices: number): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn num_of_burgers(tomato_slices: i32, cheese_slices: i32) -> Vec { diff --git a/solution/1200-1299/1276.Number of Burgers with No Waste of Ingredients/README_EN.md b/solution/1200-1299/1276.Number of Burgers with No Waste of Ingredients/README_EN.md index 1925263ca5c12..2a8ea982ba58a 100644 --- a/solution/1200-1299/1276.Number of Burgers with No Waste of Ingredients/README_EN.md +++ b/solution/1200-1299/1276.Number of Burgers with No Waste of Ingredients/README_EN.md @@ -92,6 +92,8 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]: @@ -101,6 +103,8 @@ class Solution: return [] if k % 2 or y < 0 or x < 0 else [x, y] ``` +#### Java + ```java class Solution { public List numOfBurgers(int tomatoSlices, int cheeseSlices) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func numOfBurgers(tomatoSlices int, cheeseSlices int) []int { k := 4*cheeseSlices - tomatoSlices @@ -136,6 +144,8 @@ func numOfBurgers(tomatoSlices int, cheeseSlices int) []int { } ``` +#### TypeScript + ```ts function numOfBurgers(tomatoSlices: number, cheeseSlices: number): number[] { const k = 4 * cheeseSlices - tomatoSlices; @@ -145,6 +155,8 @@ function numOfBurgers(tomatoSlices: number, cheeseSlices: number): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn num_of_burgers(tomato_slices: i32, cheese_slices: i32) -> Vec { diff --git a/solution/1200-1299/1277.Count Square Submatrices with All Ones/README.md b/solution/1200-1299/1277.Count Square Submatrices with All Ones/README.md index fdb5a836d1614..9deb5f3c5ecf3 100644 --- a/solution/1200-1299/1277.Count Square Submatrices with All Ones/README.md +++ b/solution/1200-1299/1277.Count Square Submatrices with All Ones/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def countSquares(self, matrix: List[List[int]]) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countSquares(int[][] matrix) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func countSquares(matrix [][]int) int { m, n, ans := len(matrix), len(matrix[0]), 0 diff --git a/solution/1200-1299/1277.Count Square Submatrices with All Ones/README_EN.md b/solution/1200-1299/1277.Count Square Submatrices with All Ones/README_EN.md index 4211d41e33c70..c706d0ad605f1 100644 --- a/solution/1200-1299/1277.Count Square Submatrices with All Ones/README_EN.md +++ b/solution/1200-1299/1277.Count Square Submatrices with All Ones/README_EN.md @@ -75,6 +75,8 @@ Total number of squares = 6 + 1 = 7. +#### Python3 + ```python class Solution: def countSquares(self, matrix: List[List[int]]) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countSquares(int[][] matrix) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func countSquares(matrix [][]int) int { m, n, ans := len(matrix), len(matrix[0]), 0 diff --git a/solution/1200-1299/1278.Palindrome Partitioning III/README.md b/solution/1200-1299/1278.Palindrome Partitioning III/README.md index 524c3eed9d365..668e0adbbea71 100644 --- a/solution/1200-1299/1278.Palindrome Partitioning III/README.md +++ b/solution/1200-1299/1278.Palindrome Partitioning III/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def palindromePartition(self, s: str, k: int) -> int: @@ -99,6 +101,8 @@ class Solution: return f[n][k] ``` +#### Java + ```java class Solution { public int palindromePartition(String s, int k) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func palindromePartition(s string, k int) int { n := len(s) diff --git a/solution/1200-1299/1278.Palindrome Partitioning III/README_EN.md b/solution/1200-1299/1278.Palindrome Partitioning III/README_EN.md index 90e09786c0931..467b764025869 100644 --- a/solution/1200-1299/1278.Palindrome Partitioning III/README_EN.md +++ b/solution/1200-1299/1278.Palindrome Partitioning III/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def palindromePartition(self, s: str, k: int) -> int: @@ -92,6 +94,8 @@ class Solution: return f[n][k] ``` +#### Java + ```java class Solution { public int palindromePartition(String s, int k) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func palindromePartition(s string, k int) int { n := len(s) diff --git a/solution/1200-1299/1279.Traffic Light Controlled Intersection/README.md b/solution/1200-1299/1279.Traffic Light Controlled Intersection/README.md index b596bf8c12965..7cf8f18f4c07b 100644 --- a/solution/1200-1299/1279.Traffic Light Controlled Intersection/README.md +++ b/solution/1200-1299/1279.Traffic Light Controlled Intersection/README.md @@ -101,6 +101,8 @@ tags: +#### Python3 + ```python from threading import Lock @@ -129,6 +131,8 @@ class TrafficLight: self.lock.release() ``` +#### Java + ```java class TrafficLight { private int road = 1; diff --git a/solution/1200-1299/1279.Traffic Light Controlled Intersection/README_EN.md b/solution/1200-1299/1279.Traffic Light Controlled Intersection/README_EN.md index d4b3bd9c30428..4b8e0c8c7e04e 100644 --- a/solution/1200-1299/1279.Traffic Light Controlled Intersection/README_EN.md +++ b/solution/1200-1299/1279.Traffic Light Controlled Intersection/README_EN.md @@ -99,6 +99,8 @@ tags: +#### Python3 + ```python from threading import Lock @@ -127,6 +129,8 @@ class TrafficLight: self.lock.release() ``` +#### Java + ```java class TrafficLight { private int road = 1; diff --git a/solution/1200-1299/1280.Students and Examinations/README.md b/solution/1200-1299/1280.Students and Examinations/README.md index f594b10abe05b..8466a9b6a51df 100644 --- a/solution/1200-1299/1280.Students and Examinations/README.md +++ b/solution/1200-1299/1280.Students and Examinations/README.md @@ -141,6 +141,8 @@ John 参加了数学、物理、编程测试各 1 次。 +#### MySQL + ```sql # Write your MySQL query statement below SELECT student_id, student_name, subject_name, COUNT(e.student_id) AS attended_exams diff --git a/solution/1200-1299/1280.Students and Examinations/README_EN.md b/solution/1200-1299/1280.Students and Examinations/README_EN.md index 6c3a6d87a3ab7..4e28103905be7 100644 --- a/solution/1200-1299/1280.Students and Examinations/README_EN.md +++ b/solution/1200-1299/1280.Students and Examinations/README_EN.md @@ -142,6 +142,8 @@ We can first join the `Students` table and the `Subjects` table to obtain all co +#### MySQL + ```sql # Write your MySQL query statement below SELECT student_id, student_name, subject_name, COUNT(e.student_id) AS attended_exams diff --git a/solution/1200-1299/1281.Subtract the Product and Sum of Digits of an Integer/README.md b/solution/1200-1299/1281.Subtract the Product and Sum of Digits of an Integer/README.md index b0b797b7d1f35..f54f72d213f88 100644 --- a/solution/1200-1299/1281.Subtract the Product and Sum of Digits of an Integer/README.md +++ b/solution/1200-1299/1281.Subtract the Product and Sum of Digits of an Integer/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def subtractProductAndSum(self, n: int) -> int: @@ -79,6 +81,8 @@ class Solution: return x - y ``` +#### Java + ```java class Solution { public int subtractProductAndSum(int n) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func subtractProductAndSum(n int) int { x, y := 1, 0 @@ -120,6 +128,8 @@ func subtractProductAndSum(n int) int { } ``` +#### TypeScript + ```ts function subtractProductAndSum(n: number): number { let [x, y] = [1, 0]; @@ -132,6 +142,8 @@ function subtractProductAndSum(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn subtract_product_and_sum(mut n: i32) -> i32 { @@ -148,6 +160,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int SubtractProductAndSum(int n) { @@ -163,6 +177,8 @@ public class Solution { } ``` +#### C + ```c int subtractProductAndSum(int n) { int x = 1; @@ -186,6 +202,8 @@ int subtractProductAndSum(int n) { +#### Python3 + ```python class Solution: def subtractProductAndSum(self, n: int) -> int: diff --git a/solution/1200-1299/1281.Subtract the Product and Sum of Digits of an Integer/README_EN.md b/solution/1200-1299/1281.Subtract the Product and Sum of Digits of an Integer/README_EN.md index b5e825c66155e..b70f935f3cfce 100644 --- a/solution/1200-1299/1281.Subtract the Product and Sum of Digits of an Integer/README_EN.md +++ b/solution/1200-1299/1281.Subtract the Product and Sum of Digits of an Integer/README_EN.md @@ -68,6 +68,8 @@ The time complexity is $O(\log n)$, where $n$ is the given integer. The space co +#### Python3 + ```python class Solution: def subtractProductAndSum(self, n: int) -> int: @@ -79,6 +81,8 @@ class Solution: return x - y ``` +#### Java + ```java class Solution { public int subtractProductAndSum(int n) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func subtractProductAndSum(n int) int { x, y := 1, 0 @@ -120,6 +128,8 @@ func subtractProductAndSum(n int) int { } ``` +#### TypeScript + ```ts function subtractProductAndSum(n: number): number { let [x, y] = [1, 0]; @@ -132,6 +142,8 @@ function subtractProductAndSum(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn subtract_product_and_sum(mut n: i32) -> i32 { @@ -148,6 +160,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int SubtractProductAndSum(int n) { @@ -163,6 +177,8 @@ public class Solution { } ``` +#### C + ```c int subtractProductAndSum(int n) { int x = 1; @@ -186,6 +202,8 @@ int subtractProductAndSum(int n) { +#### Python3 + ```python class Solution: def subtractProductAndSum(self, n: int) -> int: diff --git a/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/README.md b/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/README.md index 83178ad5c5bc7..f7fac3a3e076b 100644 --- a/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/README.md +++ b/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def groupThePeople(self, groupSizes: List[int]) -> List[List[int]]: @@ -83,6 +85,8 @@ class Solution: return [v[j : j + i] for i, v in g.items() for j in range(0, len(v), i)] ``` +#### Java + ```java class Solution { public List> groupThePeople(int[] groupSizes) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func groupThePeople(groupSizes []int) [][]int { n := len(groupSizes) @@ -142,6 +150,8 @@ func groupThePeople(groupSizes []int) [][]int { } ``` +#### TypeScript + ```ts function groupThePeople(groupSizes: number[]): number[][] { const n: number = groupSizes.length; @@ -164,6 +174,8 @@ function groupThePeople(groupSizes: number[]): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn group_the_people(group_sizes: Vec) -> Vec> { diff --git a/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/README_EN.md b/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/README_EN.md index 4667acc056ec7..31ae0a20bbe60 100644 --- a/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/README_EN.md +++ b/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/README_EN.md @@ -72,6 +72,8 @@ Time complexity is $O(n)$, and space complexity is $O(n)$. Here, $n$ is the leng +#### Python3 + ```python class Solution: def groupThePeople(self, groupSizes: List[int]) -> List[List[int]]: @@ -81,6 +83,8 @@ class Solution: return [v[j : j + i] for i, v in g.items() for j in range(0, len(v), i)] ``` +#### Java + ```java class Solution { public List> groupThePeople(int[] groupSizes) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func groupThePeople(groupSizes []int) [][]int { n := len(groupSizes) @@ -140,6 +148,8 @@ func groupThePeople(groupSizes []int) [][]int { } ``` +#### TypeScript + ```ts function groupThePeople(groupSizes: number[]): number[][] { const n: number = groupSizes.length; @@ -162,6 +172,8 @@ function groupThePeople(groupSizes: number[]): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn group_the_people(group_sizes: Vec) -> Vec> { diff --git a/solution/1200-1299/1283.Find the Smallest Divisor Given a Threshold/README.md b/solution/1200-1299/1283.Find the Smallest Divisor Given a Threshold/README.md index e9266254b0641..2773842cd50b6 100644 --- a/solution/1200-1299/1283.Find the Smallest Divisor Given a Threshold/README.md +++ b/solution/1200-1299/1283.Find the Smallest Divisor Given a Threshold/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def smallestDivisor(self, nums: List[int], threshold: int) -> int: @@ -93,6 +95,8 @@ class Solution: return l ``` +#### Python3 + ```python class Solution: def smallestDivisor(self, nums: List[int], threshold: int) -> int: @@ -103,6 +107,8 @@ class Solution: return bisect_left(range(max(nums)), True, key=f) + 1 ``` +#### Java + ```java class Solution { public int smallestDivisor(int[] nums, int threshold) { @@ -124,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +155,8 @@ public: }; ``` +#### Go + ```go func smallestDivisor(nums []int, threshold int) int { return sort.Search(1000000, func(v int) bool { @@ -160,6 +170,8 @@ func smallestDivisor(nums []int, threshold int) int { } ``` +#### TypeScript + ```ts function smallestDivisor(nums: number[], threshold: number): number { let l = 1; @@ -180,6 +192,8 @@ function smallestDivisor(nums: number[], threshold: number): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -205,6 +219,8 @@ var smallestDivisor = function (nums, threshold) { }; ``` +#### C# + ```cs public class Solution { public int SmallestDivisor(int[] nums, int threshold) { diff --git a/solution/1200-1299/1283.Find the Smallest Divisor Given a Threshold/README_EN.md b/solution/1200-1299/1283.Find the Smallest Divisor Given a Threshold/README_EN.md index 93175d67ebd07..8699548f95875 100644 --- a/solution/1200-1299/1283.Find the Smallest Divisor Given a Threshold/README_EN.md +++ b/solution/1200-1299/1283.Find the Smallest Divisor Given a Threshold/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n \times \log M)$, where $n$ is the length of the arra +#### Python3 + ```python class Solution: def smallestDivisor(self, nums: List[int], threshold: int) -> int: @@ -82,6 +84,8 @@ class Solution: return l ``` +#### Python3 + ```python class Solution: def smallestDivisor(self, nums: List[int], threshold: int) -> int: @@ -92,6 +96,8 @@ class Solution: return bisect_left(range(max(nums)), True, key=f) + 1 ``` +#### Java + ```java class Solution { public int smallestDivisor(int[] nums, int threshold) { @@ -113,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +144,8 @@ public: }; ``` +#### Go + ```go func smallestDivisor(nums []int, threshold int) int { return sort.Search(1000000, func(v int) bool { @@ -149,6 +159,8 @@ func smallestDivisor(nums []int, threshold int) int { } ``` +#### TypeScript + ```ts function smallestDivisor(nums: number[], threshold: number): number { let l = 1; @@ -169,6 +181,8 @@ function smallestDivisor(nums: number[], threshold: number): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -194,6 +208,8 @@ var smallestDivisor = function (nums, threshold) { }; ``` +#### C# + ```cs public class Solution { public int SmallestDivisor(int[] nums, int threshold) { diff --git a/solution/1200-1299/1284.Minimum Number of Flips to Convert Binary Matrix to Zero Matrix/README.md b/solution/1200-1299/1284.Minimum Number of Flips to Convert Binary Matrix to Zero Matrix/README.md index 121dcf5b6bca4..ecadf81af4ae2 100644 --- a/solution/1200-1299/1284.Minimum Number of Flips to Convert Binary Matrix to Zero Matrix/README.md +++ b/solution/1200-1299/1284.Minimum Number of Flips to Convert Binary Matrix to Zero Matrix/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def minFlips(self, mat: List[List[int]]) -> int: @@ -112,6 +114,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minFlips(int[][] mat) { @@ -164,6 +168,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -208,6 +214,8 @@ public: }; ``` +#### Go + ```go func minFlips(mat [][]int) int { m, n := len(mat), len(mat[0]) diff --git a/solution/1200-1299/1284.Minimum Number of Flips to Convert Binary Matrix to Zero Matrix/README_EN.md b/solution/1200-1299/1284.Minimum Number of Flips to Convert Binary Matrix to Zero Matrix/README_EN.md index 14c77854722a7..78e1af96c7ed3 100644 --- a/solution/1200-1299/1284.Minimum Number of Flips to Convert Binary Matrix to Zero Matrix/README_EN.md +++ b/solution/1200-1299/1284.Minimum Number of Flips to Convert Binary Matrix to Zero Matrix/README_EN.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def minFlips(self, mat: List[List[int]]) -> int: @@ -107,6 +109,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minFlips(int[][] mat) { @@ -159,6 +163,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -203,6 +209,8 @@ public: }; ``` +#### Go + ```go func minFlips(mat [][]int) int { m, n := len(mat), len(mat[0]) diff --git a/solution/1200-1299/1285.Find the Start and End Number of Continuous Ranges/README.md b/solution/1200-1299/1285.Find the Start and End Number of Continuous Ranges/README.md index 6a3ad3f28fedf..c1777cdf19a12 100644 --- a/solution/1200-1299/1285.Find the Start and End Number of Continuous Ranges/README.md +++ b/solution/1200-1299/1285.Find the Start and End Number of Continuous Ranges/README.md @@ -86,6 +86,8 @@ Logs 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -116,6 +118,8 @@ GROUP BY pid; +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1200-1299/1285.Find the Start and End Number of Continuous Ranges/README_EN.md b/solution/1200-1299/1285.Find the Start and End Number of Continuous Ranges/README_EN.md index 96a143a90c1c6..20a9b54abd96c 100644 --- a/solution/1200-1299/1285.Find the Start and End Number of Continuous Ranges/README_EN.md +++ b/solution/1200-1299/1285.Find the Start and End Number of Continuous Ranges/README_EN.md @@ -86,6 +86,8 @@ There are two ways to implement grouping: +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -116,6 +118,8 @@ GROUP BY pid; +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1200-1299/1286.Iterator for Combination/README.md b/solution/1200-1299/1286.Iterator for Combination/README.md index 7557fcf44295a..235eec3eceee0 100644 --- a/solution/1200-1299/1286.Iterator for Combination/README.md +++ b/solution/1200-1299/1286.Iterator for Combination/README.md @@ -72,6 +72,8 @@ iterator.hasNext(); // 返回 false +#### Python3 + ```python class CombinationIterator: def __init__(self, characters: str, combinationLength: int): @@ -108,6 +110,8 @@ class CombinationIterator: # param_2 = obj.hasNext() ``` +#### Java + ```java class CombinationIterator { private int n; @@ -155,6 +159,8 @@ class CombinationIterator { */ ``` +#### C++ + ```cpp class CombinationIterator { public: @@ -202,6 +208,8 @@ public: */ ``` +#### Go + ```go type CombinationIterator struct { cs []string @@ -276,6 +284,8 @@ func (this *CombinationIterator) HasNext() bool { +#### Python3 + ```python class CombinationIterator: def __init__(self, characters: str, combinationLength: int): @@ -305,6 +315,8 @@ class CombinationIterator: # param_2 = obj.hasNext() ``` +#### Java + ```java class CombinationIterator { private int curr; @@ -351,6 +363,8 @@ class CombinationIterator { */ ``` +#### C++ + ```cpp class CombinationIterator { public: @@ -393,6 +407,8 @@ public: */ ``` +#### Go + ```go type CombinationIterator struct { curr int diff --git a/solution/1200-1299/1286.Iterator for Combination/README_EN.md b/solution/1200-1299/1286.Iterator for Combination/README_EN.md index 87d7f42953d50..1eef522d0c5b3 100644 --- a/solution/1200-1299/1286.Iterator for Combination/README_EN.md +++ b/solution/1200-1299/1286.Iterator for Combination/README_EN.md @@ -69,6 +69,8 @@ itr.hasNext(); // return False +#### Python3 + ```python class CombinationIterator: def __init__(self, characters: str, combinationLength: int): @@ -105,6 +107,8 @@ class CombinationIterator: # param_2 = obj.hasNext() ``` +#### Java + ```java class CombinationIterator { private int n; @@ -152,6 +156,8 @@ class CombinationIterator { */ ``` +#### C++ + ```cpp class CombinationIterator { public: @@ -199,6 +205,8 @@ public: */ ``` +#### Go + ```go type CombinationIterator struct { cs []string @@ -255,6 +263,8 @@ func (this *CombinationIterator) HasNext() bool { +#### Python3 + ```python class CombinationIterator: def __init__(self, characters: str, combinationLength: int): @@ -284,6 +294,8 @@ class CombinationIterator: # param_2 = obj.hasNext() ``` +#### Java + ```java class CombinationIterator { private int curr; @@ -330,6 +342,8 @@ class CombinationIterator { */ ``` +#### C++ + ```cpp class CombinationIterator { public: @@ -372,6 +386,8 @@ public: */ ``` +#### Go + ```go type CombinationIterator struct { curr int diff --git a/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/README.md b/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/README.md index 5354bdbaf8dd3..98e890f28c840 100644 --- a/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/README.md +++ b/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/README.md @@ -50,6 +50,8 @@ tags: +#### Python3 + ```python class Solution: def findSpecialInteger(self, arr: List[int]) -> int: @@ -60,6 +62,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { public int findSpecialInteger(int[] arr) { @@ -74,6 +78,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -86,6 +92,8 @@ public: }; ``` +#### Go + ```go func findSpecialInteger(arr []int) int { n := len(arr) @@ -98,6 +106,8 @@ func findSpecialInteger(arr []int) int { } ``` +#### JavaScript + ```js /** * @param {number[]} arr @@ -114,6 +124,8 @@ var findSpecialInteger = function (arr) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/README_EN.md b/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/README_EN.md index 160e51a2a4f8b..8bc6454c8459e 100644 --- a/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/README_EN.md +++ b/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/README_EN.md @@ -53,6 +53,8 @@ tags: +#### Python3 + ```python class Solution: def findSpecialInteger(self, arr: List[int]) -> int: @@ -63,6 +65,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { public int findSpecialInteger(int[] arr) { @@ -77,6 +81,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -89,6 +95,8 @@ public: }; ``` +#### Go + ```go func findSpecialInteger(arr []int) int { n := len(arr) @@ -101,6 +109,8 @@ func findSpecialInteger(arr []int) int { } ``` +#### JavaScript + ```js /** * @param {number[]} arr @@ -117,6 +127,8 @@ var findSpecialInteger = function (arr) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1200-1299/1288.Remove Covered Intervals/README.md b/solution/1200-1299/1288.Remove Covered Intervals/README.md index da2894886815c..5d2bc3403b189 100644 --- a/solution/1200-1299/1288.Remove Covered Intervals/README.md +++ b/solution/1200-1299/1288.Remove Covered Intervals/README.md @@ -55,6 +55,8 @@ tags: +#### Python3 + ```python class Solution: def removeCoveredIntervals(self, intervals: List[List[int]]) -> int: @@ -67,6 +69,8 @@ class Solution: return cnt ``` +#### Java + ```java class Solution { public int removeCoveredIntervals(int[][] intervals) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -102,6 +108,8 @@ public: }; ``` +#### Go + ```go func removeCoveredIntervals(intervals [][]int) int { sort.Slice(intervals, func(i, j int) bool { diff --git a/solution/1200-1299/1288.Remove Covered Intervals/README_EN.md b/solution/1200-1299/1288.Remove Covered Intervals/README_EN.md index bb6894c05003a..7542d843ebe4f 100644 --- a/solution/1200-1299/1288.Remove Covered Intervals/README_EN.md +++ b/solution/1200-1299/1288.Remove Covered Intervals/README_EN.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def removeCoveredIntervals(self, intervals: List[List[int]]) -> int: @@ -73,6 +75,8 @@ class Solution: return cnt ``` +#### Java + ```java class Solution { public int removeCoveredIntervals(int[][] intervals) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func removeCoveredIntervals(intervals [][]int) int { sort.Slice(intervals, func(i, j int) bool { diff --git a/solution/1200-1299/1289.Minimum Falling Path Sum II/README.md b/solution/1200-1299/1289.Minimum Falling Path Sum II/README.md index e94dc625e3bdc..783090cd12826 100644 --- a/solution/1200-1299/1289.Minimum Falling Path Sum II/README.md +++ b/solution/1200-1299/1289.Minimum Falling Path Sum II/README.md @@ -82,6 +82,8 @@ $$ +#### Python3 + ```python class Solution: def minFallingPathSum(self, grid: List[List[int]]) -> int: @@ -94,6 +96,8 @@ class Solution: return min(f[n]) ``` +#### Java + ```java class Solution { public int minFallingPathSum(int[][] grid) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func minFallingPathSum(grid [][]int) int { n := len(grid) @@ -181,6 +189,8 @@ func minFallingPathSum(grid [][]int) int { +#### Python3 + ```python class Solution: def minFallingPathSum(self, grid: List[List[int]]) -> int: @@ -201,6 +211,8 @@ class Solution: return f ``` +#### Java + ```java class Solution { public int minFallingPathSum(int[][] grid) { @@ -229,6 +241,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -258,6 +272,8 @@ public: }; ``` +#### Go + ```go func minFallingPathSum(grid [][]int) int { const inf = 1 << 30 diff --git a/solution/1200-1299/1289.Minimum Falling Path Sum II/README_EN.md b/solution/1200-1299/1289.Minimum Falling Path Sum II/README_EN.md index 1350ab734ac5f..a523050532e50 100644 --- a/solution/1200-1299/1289.Minimum Falling Path Sum II/README_EN.md +++ b/solution/1200-1299/1289.Minimum Falling Path Sum II/README_EN.md @@ -64,6 +64,8 @@ The falling path with the smallest sum is [1,5,7], so the answer is 13 +#### Python3 + ```python class Solution: def minFallingPathSum(self, grid: List[List[int]]) -> int: @@ -76,6 +78,8 @@ class Solution: return min(f[n]) ``` +#### Java + ```java class Solution { public int minFallingPathSum(int[][] grid) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func minFallingPathSum(grid [][]int) int { n := len(grid) @@ -163,6 +171,8 @@ func minFallingPathSum(grid [][]int) int { +#### Python3 + ```python class Solution: def minFallingPathSum(self, grid: List[List[int]]) -> int: @@ -183,6 +193,8 @@ class Solution: return f ``` +#### Java + ```java class Solution { public int minFallingPathSum(int[][] grid) { @@ -211,6 +223,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -240,6 +254,8 @@ public: }; ``` +#### Go + ```go func minFallingPathSum(grid [][]int) int { const inf = 1 << 30 diff --git a/solution/1200-1299/1290.Convert Binary Number in a Linked List to Integer/README.md b/solution/1200-1299/1290.Convert Binary Number in a Linked List to Integer/README.md index cead6bdfa93a8..64d18981736ca 100644 --- a/solution/1200-1299/1290.Convert Binary Number in a Linked List to Integer/README.md +++ b/solution/1200-1299/1290.Convert Binary Number in a Linked List to Integer/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -160,6 +168,8 @@ func getDecimalValue(head *ListNode) (ans int) { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -182,6 +192,8 @@ function getDecimalValue(head: ListNode | null): number { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -212,6 +224,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -233,6 +247,8 @@ var getDecimalValue = function (head) { }; ``` +#### PHP + ```php /** * Definition for a singly-linked list. @@ -262,6 +278,8 @@ class Solution { } ``` +#### C + ```c /** * Definition for singly-linked list. diff --git a/solution/1200-1299/1290.Convert Binary Number in a Linked List to Integer/README_EN.md b/solution/1200-1299/1290.Convert Binary Number in a Linked List to Integer/README_EN.md index f68b4b63293e6..3e49f84db6367 100644 --- a/solution/1200-1299/1290.Convert Binary Number in a Linked List to Integer/README_EN.md +++ b/solution/1200-1299/1290.Convert Binary Number in a Linked List to Integer/README_EN.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -75,6 +77,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -136,6 +144,8 @@ func getDecimalValue(head *ListNode) (ans int) { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -158,6 +168,8 @@ function getDecimalValue(head: ListNode | null): number { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -188,6 +200,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * Definition for singly-linked list. @@ -209,6 +223,8 @@ var getDecimalValue = function (head) { }; ``` +#### PHP + ```php /** * Definition for a singly-linked list. @@ -238,6 +254,8 @@ class Solution { } ``` +#### C + ```c /** * Definition for singly-linked list. diff --git a/solution/1200-1299/1291.Sequential Digits/README.md b/solution/1200-1299/1291.Sequential Digits/README.md index 332e48a5ab5bd..5fd9057fcaaa9 100644 --- a/solution/1200-1299/1291.Sequential Digits/README.md +++ b/solution/1200-1299/1291.Sequential Digits/README.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def sequentialDigits(self, low: int, high: int) -> List[int]: @@ -73,6 +75,8 @@ class Solution: return sorted(ans) ``` +#### Java + ```java class Solution { public List sequentialDigits(int low, int high) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func sequentialDigits(low int, high int) (ans []int) { for i := 1; i < 9; i++ { @@ -128,6 +136,8 @@ func sequentialDigits(low int, high int) (ans []int) { } ``` +#### TypeScript + ```ts function sequentialDigits(low: number, high: number): number[] { const ans: number[] = []; diff --git a/solution/1200-1299/1291.Sequential Digits/README_EN.md b/solution/1200-1299/1291.Sequential Digits/README_EN.md index 9cd42fa17e128..f8b17635848e5 100644 --- a/solution/1200-1299/1291.Sequential Digits/README_EN.md +++ b/solution/1200-1299/1291.Sequential Digits/README_EN.md @@ -47,6 +47,8 @@ tags: +#### Python3 + ```python class Solution: def sequentialDigits(self, low: int, high: int) -> List[int]: @@ -60,6 +62,8 @@ class Solution: return sorted(ans) ``` +#### Java + ```java class Solution { public List sequentialDigits(int low, int high) { @@ -79,6 +83,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -99,6 +105,8 @@ public: }; ``` +#### Go + ```go func sequentialDigits(low int, high int) (ans []int) { for i := 1; i < 9; i++ { @@ -115,6 +123,8 @@ func sequentialDigits(low int, high int) (ans []int) { } ``` +#### TypeScript + ```ts function sequentialDigits(low: number, high: number): number[] { const ans: number[] = []; diff --git a/solution/1200-1299/1292.Maximum Side Length of a Square with Sum Less than or Equal to Threshold/README.md b/solution/1200-1299/1292.Maximum Side Length of a Square with Sum Less than or Equal to Threshold/README.md index 56b3b64cf1345..805429a766c3e 100644 --- a/solution/1200-1299/1292.Maximum Side Length of a Square with Sum Less than or Equal to Threshold/README.md +++ b/solution/1200-1299/1292.Maximum Side Length of a Square with Sum Less than or Equal to Threshold/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def maxSideLength(self, mat: List[List[int]], threshold: int) -> int: @@ -97,6 +99,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { private int m; @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go func maxSideLength(mat [][]int, threshold int) int { m, n := len(mat), len(mat[0]) @@ -210,6 +218,8 @@ func maxSideLength(mat [][]int, threshold int) int { } ``` +#### TypeScript + ```ts function maxSideLength(mat: number[][], threshold: number): number { const m = mat.length; diff --git a/solution/1200-1299/1292.Maximum Side Length of a Square with Sum Less than or Equal to Threshold/README_EN.md b/solution/1200-1299/1292.Maximum Side Length of a Square with Sum Less than or Equal to Threshold/README_EN.md index 6692bbbe6df0a..cf29ecd6fed13 100644 --- a/solution/1200-1299/1292.Maximum Side Length of a Square with Sum Less than or Equal to Threshold/README_EN.md +++ b/solution/1200-1299/1292.Maximum Side Length of a Square with Sum Less than or Equal to Threshold/README_EN.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def maxSideLength(self, mat: List[List[int]], threshold: int) -> int: @@ -86,6 +88,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { private int m; @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func maxSideLength(mat [][]int, threshold int) int { m, n := len(mat), len(mat[0]) @@ -199,6 +207,8 @@ func maxSideLength(mat [][]int, threshold int) int { } ``` +#### TypeScript + ```ts function maxSideLength(mat: number[][], threshold: number): number { const m = mat.length; diff --git a/solution/1200-1299/1293.Shortest Path in a Grid with Obstacles Elimination/README.md b/solution/1200-1299/1293.Shortest Path in a Grid with Obstacles Elimination/README.md index 3694f5eb8223c..a235d42f1bd59 100644 --- a/solution/1200-1299/1293.Shortest Path in a Grid with Obstacles Elimination/README.md +++ b/solution/1200-1299/1293.Shortest Path in a Grid with Obstacles Elimination/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def shortestPath(self, grid: List[List[int]], k: int) -> int: @@ -98,6 +100,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int shortestPath(int[][] grid, int k) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -178,6 +184,8 @@ public: }; ``` +#### Go + ```go func shortestPath(grid [][]int, k int) int { m, n := len(grid), len(grid[0]) diff --git a/solution/1200-1299/1293.Shortest Path in a Grid with Obstacles Elimination/README_EN.md b/solution/1200-1299/1293.Shortest Path in a Grid with Obstacles Elimination/README_EN.md index ba964af8b5e07..f26a9577d683d 100644 --- a/solution/1200-1299/1293.Shortest Path in a Grid with Obstacles Elimination/README_EN.md +++ b/solution/1200-1299/1293.Shortest Path in a Grid with Obstacles Elimination/README_EN.md @@ -65,6 +65,8 @@ The shortest path with one obstacle elimination at position (3,2) is 6. Such pat +#### Python3 + ```python class Solution: def shortestPath(self, grid: List[List[int]], k: int) -> int: @@ -92,6 +94,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int shortestPath(int[][] grid, int k) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go func shortestPath(grid [][]int, k int) int { m, n := len(grid), len(grid[0]) diff --git a/solution/1200-1299/1294.Weather Type in Each Country/README.md b/solution/1200-1299/1294.Weather Type in Each Country/README.md index 32d49e6628efe..67e852049720c 100644 --- a/solution/1200-1299/1294.Weather Type in Each Country/README.md +++ b/solution/1200-1299/1294.Weather Type in Each Country/README.md @@ -129,6 +129,8 @@ Morocco 11 月的平均 weather_state 为 (25 + 27 + 31) / 3 = 27.667 所以天 +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1200-1299/1294.Weather Type in Each Country/README_EN.md b/solution/1200-1299/1294.Weather Type in Each Country/README_EN.md index b2008600714d4..6478dd83a0304 100644 --- a/solution/1200-1299/1294.Weather Type in Each Country/README_EN.md +++ b/solution/1200-1299/1294.Weather Type in Each Country/README_EN.md @@ -128,6 +128,8 @@ We know nothing about the average weather_state in Spain in November so we do no +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1200-1299/1295.Find Numbers with Even Number of Digits/README.md b/solution/1200-1299/1295.Find Numbers with Even Number of Digits/README.md index 238c02ff6cfb5..dda13f29c6319 100644 --- a/solution/1200-1299/1295.Find Numbers with Even Number of Digits/README.md +++ b/solution/1200-1299/1295.Find Numbers with Even Number of Digits/README.md @@ -66,12 +66,16 @@ tags: +#### Python3 + ```python class Solution: def findNumbers(self, nums: List[int]) -> int: return sum(len(str(v)) % 2 == 0 for v in nums) ``` +#### Java + ```java class Solution { public int findNumbers(int[] nums) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -99,6 +105,8 @@ public: }; ``` +#### Go + ```go func findNumbers(nums []int) (ans int) { for _, v := range nums { @@ -110,6 +118,8 @@ func findNumbers(nums []int) (ans int) { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/1200-1299/1295.Find Numbers with Even Number of Digits/README_EN.md b/solution/1200-1299/1295.Find Numbers with Even Number of Digits/README_EN.md index b8d4eda6c3c75..9b0c948d902e3 100644 --- a/solution/1200-1299/1295.Find Numbers with Even Number of Digits/README_EN.md +++ b/solution/1200-1299/1295.Find Numbers with Even Number of Digits/README_EN.md @@ -62,12 +62,16 @@ Only 1771 contains an even number of digits. +#### Python3 + ```python class Solution: def findNumbers(self, nums: List[int]) -> int: return sum(len(str(v)) % 2 == 0 for v in nums) ``` +#### Java + ```java class Solution { public int findNumbers(int[] nums) { @@ -82,6 +86,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -95,6 +101,8 @@ public: }; ``` +#### Go + ```go func findNumbers(nums []int) (ans int) { for _, v := range nums { @@ -106,6 +114,8 @@ func findNumbers(nums []int) (ans int) { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/1200-1299/1296.Divide Array in Sets of K Consecutive Numbers/README.md b/solution/1200-1299/1296.Divide Array in Sets of K Consecutive Numbers/README.md index d903db971dec8..5fc673bb188c8 100644 --- a/solution/1200-1299/1296.Divide Array in Sets of K Consecutive Numbers/README.md +++ b/solution/1200-1299/1296.Divide Array in Sets of K Consecutive Numbers/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def isPossibleDivide(self, nums: List[int], k: int) -> bool: @@ -101,6 +103,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isPossibleDivide(int[] nums, int k) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func isPossibleDivide(nums []int, k int) bool { cnt := map[int]int{} @@ -191,6 +199,8 @@ func isPossibleDivide(nums []int, k int) bool { +#### Python3 + ```python from sortedcontainers import SortedDict @@ -217,6 +227,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isPossibleDivide(int[] nums, int k) { @@ -245,6 +257,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -267,6 +281,8 @@ public: }; ``` +#### Go + ```go func isPossibleDivide(nums []int, k int) bool { if len(nums)%k != 0 { diff --git a/solution/1200-1299/1296.Divide Array in Sets of K Consecutive Numbers/README_EN.md b/solution/1200-1299/1296.Divide Array in Sets of K Consecutive Numbers/README_EN.md index 4b8608f6484d4..b6ef314ec2a29 100644 --- a/solution/1200-1299/1296.Divide Array in Sets of K Consecutive Numbers/README_EN.md +++ b/solution/1200-1299/1296.Divide Array in Sets of K Consecutive Numbers/README_EN.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def isPossibleDivide(self, nums: List[int], k: int) -> bool: @@ -86,6 +88,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isPossibleDivide(int[] nums, int k) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func isPossibleDivide(nums []int, k int) bool { cnt := map[int]int{} @@ -170,6 +178,8 @@ func isPossibleDivide(nums []int, k int) bool { +#### Python3 + ```python from sortedcontainers import SortedDict @@ -196,6 +206,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isPossibleDivide(int[] nums, int k) { @@ -224,6 +236,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -246,6 +260,8 @@ public: }; ``` +#### Go + ```go func isPossibleDivide(nums []int, k int) bool { if len(nums)%k != 0 { diff --git a/solution/1200-1299/1297.Maximum Number of Occurrences of a Substring/README.md b/solution/1200-1299/1297.Maximum Number of Occurrences of a Substring/README.md index 0bc1b23cc7c3a..900f63d6ad0c9 100644 --- a/solution/1200-1299/1297.Maximum Number of Occurrences of a Substring/README.md +++ b/solution/1200-1299/1297.Maximum Number of Occurrences of a Substring/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxFreq(String s, int maxLetters, int minSize, int maxSize) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func maxFreq(s string, maxLetters int, minSize int, maxSize int) (ans int) { cnt := map[string]int{} diff --git a/solution/1200-1299/1297.Maximum Number of Occurrences of a Substring/README_EN.md b/solution/1200-1299/1297.Maximum Number of Occurrences of a Substring/README_EN.md index ca1f84cf9ec2b..9a8a00bcdce57 100644 --- a/solution/1200-1299/1297.Maximum Number of Occurrences of a Substring/README_EN.md +++ b/solution/1200-1299/1297.Maximum Number of Occurrences of a Substring/README_EN.md @@ -65,6 +65,8 @@ It satisfies the conditions, 2 unique letters and size 3 (between minSize and ma +#### Python3 + ```python class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: @@ -79,6 +81,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxFreq(String s, int maxLetters, int minSize, int maxSize) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func maxFreq(s string, maxLetters int, minSize int, maxSize int) (ans int) { cnt := map[string]int{} diff --git a/solution/1200-1299/1298.Maximum Candies You Can Get from Boxes/README.md b/solution/1200-1299/1298.Maximum Candies You Can Get from Boxes/README.md index e37f06a5c2761..d974408e38dbb 100644 --- a/solution/1200-1299/1298.Maximum Candies You Can Get from Boxes/README.md +++ b/solution/1200-1299/1298.Maximum Candies You Can Get from Boxes/README.md @@ -103,6 +103,8 @@ tags: +#### Python3 + ```python class Solution: def maxCandies( @@ -135,6 +137,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxCandies( @@ -176,6 +180,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -218,6 +224,8 @@ public: }; ``` +#### Go + ```go func maxCandies(status []int, candies []int, keys [][]int, containedBoxes [][]int, initialBoxes []int) int { ans := 0 diff --git a/solution/1200-1299/1298.Maximum Candies You Can Get from Boxes/README_EN.md b/solution/1200-1299/1298.Maximum Candies You Can Get from Boxes/README_EN.md index 6ab8d1e6e2607..206d86924e214 100644 --- a/solution/1200-1299/1298.Maximum Candies You Can Get from Boxes/README_EN.md +++ b/solution/1200-1299/1298.Maximum Candies You Can Get from Boxes/README_EN.md @@ -83,6 +83,8 @@ The total number of candies will be 6. +#### Python3 + ```python class Solution: def maxCandies( @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxCandies( @@ -156,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -198,6 +204,8 @@ public: }; ``` +#### Go + ```go func maxCandies(status []int, candies []int, keys [][]int, containedBoxes [][]int, initialBoxes []int) int { ans := 0 diff --git a/solution/1200-1299/1299.Replace Elements with Greatest Element on Right Side/README.md b/solution/1200-1299/1299.Replace Elements with Greatest Element on Right Side/README.md index 2236aaec6c83f..19c111f488a6b 100644 --- a/solution/1200-1299/1299.Replace Elements with Greatest Element on Right Side/README.md +++ b/solution/1200-1299/1299.Replace Elements with Greatest Element on Right Side/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def replaceElements(self, arr: List[int]) -> List[int]: @@ -76,6 +78,8 @@ class Solution: return arr ``` +#### Java + ```java class Solution { public int[] replaceElements(int[] arr) { diff --git a/solution/1200-1299/1299.Replace Elements with Greatest Element on Right Side/README_EN.md b/solution/1200-1299/1299.Replace Elements with Greatest Element on Right Side/README_EN.md index 4ca5d649414e4..c6101fce18df1 100644 --- a/solution/1200-1299/1299.Replace Elements with Greatest Element on Right Side/README_EN.md +++ b/solution/1200-1299/1299.Replace Elements with Greatest Element on Right Side/README_EN.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def replaceElements(self, arr: List[int]) -> List[int]: @@ -74,6 +76,8 @@ class Solution: return arr ``` +#### Java + ```java class Solution { public int[] replaceElements(int[] arr) { diff --git a/solution/1300-1399/1300.Sum of Mutated Array Closest to Target/README.md b/solution/1300-1399/1300.Sum of Mutated Array Closest to Target/README.md index 9c1a71ef126ed..7df08c5743ee1 100644 --- a/solution/1300-1399/1300.Sum of Mutated Array Closest to Target/README.md +++ b/solution/1300-1399/1300.Sum of Mutated Array Closest to Target/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def findBestValue(self, arr: List[int], target: int) -> int: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findBestValue(int[] arr, int target) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func findBestValue(arr []int, target int) (ans int) { sort.Ints(arr) diff --git a/solution/1300-1399/1300.Sum of Mutated Array Closest to Target/README_EN.md b/solution/1300-1399/1300.Sum of Mutated Array Closest to Target/README_EN.md index e8bda839daac9..a3b5eca6c9225 100644 --- a/solution/1300-1399/1300.Sum of Mutated Array Closest to Target/README_EN.md +++ b/solution/1300-1399/1300.Sum of Mutated Array Closest to Target/README_EN.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def findBestValue(self, arr: List[int], target: int) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findBestValue(int[] arr, int target) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func findBestValue(arr []int, target int) (ans int) { sort.Ints(arr) diff --git a/solution/1300-1399/1301.Number of Paths with Max Score/README.md b/solution/1300-1399/1301.Number of Paths with Max Score/README.md index 05d0b4d2c40c2..73d62bc046adc 100644 --- a/solution/1300-1399/1301.Number of Paths with Max Score/README.md +++ b/solution/1300-1399/1301.Number of Paths with Max Score/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def pathsWithMaxScore(self, board: List[str]) -> List[int]: @@ -106,6 +108,8 @@ class Solution: return [0, 0] if f[0][0] == -1 else [f[0][0], g[0][0] % mod] ``` +#### Java + ```java class Solution { private List board; @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -207,6 +213,8 @@ public: }; ``` +#### Go + ```go func pathsWithMaxScore(board []string) []int { n := len(board) diff --git a/solution/1300-1399/1301.Number of Paths with Max Score/README_EN.md b/solution/1300-1399/1301.Number of Paths with Max Score/README_EN.md index 900673d0a4d8f..bcba5a16b8d3b 100644 --- a/solution/1300-1399/1301.Number of Paths with Max Score/README_EN.md +++ b/solution/1300-1399/1301.Number of Paths with Max Score/README_EN.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def pathsWithMaxScore(self, board: List[str]) -> List[int]: @@ -97,6 +99,8 @@ class Solution: return [0, 0] if f[0][0] == -1 else [f[0][0], g[0][0] % mod] ``` +#### Java + ```java class Solution { private List board; @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -198,6 +204,8 @@ public: }; ``` +#### Go + ```go func pathsWithMaxScore(board []string) []int { n := len(board) diff --git a/solution/1300-1399/1302.Deepest Leaves Sum/README.md b/solution/1300-1399/1302.Deepest Leaves Sum/README.md index 56912ac5b5fb8..bc34e8755e99e 100644 --- a/solution/1300-1399/1302.Deepest Leaves Sum/README.md +++ b/solution/1300-1399/1302.Deepest Leaves Sum/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -187,6 +195,8 @@ func deepestLeavesSum(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -220,6 +230,8 @@ function deepestLeavesSum(root: TreeNode | null): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -268,6 +280,8 @@ impl Solution { } ``` +#### C + ```c /** * Definition for a binary tree node. @@ -316,6 +330,8 @@ int deepestLeavesSum(struct TreeNode* root) { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -342,6 +358,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -383,6 +401,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -419,6 +439,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -449,6 +471,8 @@ func deepestLeavesSum(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/1300-1399/1302.Deepest Leaves Sum/README_EN.md b/solution/1300-1399/1302.Deepest Leaves Sum/README_EN.md index 9dc01a79695f3..ea9652ff9cbf1 100644 --- a/solution/1300-1399/1302.Deepest Leaves Sum/README_EN.md +++ b/solution/1300-1399/1302.Deepest Leaves Sum/README_EN.md @@ -56,6 +56,8 @@ Given the root of a binary tree, return the sum of values of it +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -179,6 +187,8 @@ func deepestLeavesSum(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -212,6 +222,8 @@ function deepestLeavesSum(root: TreeNode | null): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -260,6 +272,8 @@ impl Solution { } ``` +#### C + ```c /** * Definition for a binary tree node. @@ -306,6 +320,8 @@ int deepestLeavesSum(struct TreeNode* root) { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -332,6 +348,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -373,6 +391,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -409,6 +429,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -439,6 +461,8 @@ func deepestLeavesSum(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/1300-1399/1303.Find the Team Size/README.md b/solution/1300-1399/1303.Find the Team Size/README.md index 3890726eadb8a..86e62ef34710f 100644 --- a/solution/1300-1399/1303.Find the Team Size/README.md +++ b/solution/1300-1399/1303.Find the Team Size/README.md @@ -83,6 +83,8 @@ ID 为 5、6 的员工是 team_id 为 9 的团队的成员。 +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -109,6 +111,8 @@ FROM +#### MySQL + ```sql # Write your MySQL query statement below SELECT e1.employee_id, COUNT(1) AS team_size diff --git a/solution/1300-1399/1303.Find the Team Size/README_EN.md b/solution/1300-1399/1303.Find the Team Size/README_EN.md index 6e6f05eaf67a0..7b2486fe6b0a1 100644 --- a/solution/1300-1399/1303.Find the Team Size/README_EN.md +++ b/solution/1300-1399/1303.Find the Team Size/README_EN.md @@ -82,6 +82,8 @@ We can first count the number of people in each team and record it in the `T` ta +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -108,6 +110,8 @@ We can also use a left join to join the `Employee` table with itself based on `t +#### MySQL + ```sql # Write your MySQL query statement below SELECT e1.employee_id, COUNT(1) AS team_size diff --git a/solution/1300-1399/1304.Find N Unique Integers Sum up to Zero/README.md b/solution/1300-1399/1304.Find N Unique Integers Sum up to Zero/README.md index 22ef40a0b4011..ee0aad236f00a 100644 --- a/solution/1300-1399/1304.Find N Unique Integers Sum up to Zero/README.md +++ b/solution/1300-1399/1304.Find N Unique Integers Sum up to Zero/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def sumZero(self, n: int) -> List[int]: @@ -76,6 +78,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] sumZero(int n) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -103,6 +109,8 @@ public: }; ``` +#### Go + ```go func sumZero(n int) []int { ans := make([]int, n) @@ -115,6 +123,8 @@ func sumZero(n int) []int { } ``` +#### TypeScript + ```ts function sumZero(n: number): number[] { const ans = new Array(n).fill(0); @@ -140,6 +150,8 @@ function sumZero(n: number): number[] { +#### Python3 + ```python class Solution: def sumZero(self, n: int) -> List[int]: @@ -148,6 +160,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] sumZero(int n) { @@ -161,6 +175,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -173,6 +189,8 @@ public: }; ``` +#### Go + ```go func sumZero(n int) []int { ans := make([]int, n) @@ -184,6 +202,8 @@ func sumZero(n int) []int { } ``` +#### TypeScript + ```ts function sumZero(n: number): number[] { const ans = new Array(n).fill(0); diff --git a/solution/1300-1399/1304.Find N Unique Integers Sum up to Zero/README_EN.md b/solution/1300-1399/1304.Find N Unique Integers Sum up to Zero/README_EN.md index ecc91b62d9f48..759e6722c6f8e 100644 --- a/solution/1300-1399/1304.Find N Unique Integers Sum up to Zero/README_EN.md +++ b/solution/1300-1399/1304.Find N Unique Integers Sum up to Zero/README_EN.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def sumZero(self, n: int) -> List[int]: @@ -73,6 +75,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] sumZero(int n) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -100,6 +106,8 @@ public: }; ``` +#### Go + ```go func sumZero(n int) []int { ans := make([]int, n) @@ -112,6 +120,8 @@ func sumZero(n int) []int { } ``` +#### TypeScript + ```ts function sumZero(n: number): number[] { const ans = new Array(n).fill(0); @@ -133,6 +143,8 @@ function sumZero(n: number): number[] { +#### Python3 + ```python class Solution: def sumZero(self, n: int) -> List[int]: @@ -141,6 +153,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] sumZero(int n) { @@ -154,6 +168,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +182,8 @@ public: }; ``` +#### Go + ```go func sumZero(n int) []int { ans := make([]int, n) @@ -177,6 +195,8 @@ func sumZero(n int) []int { } ``` +#### TypeScript + ```ts function sumZero(n: number): number[] { const ans = new Array(n).fill(0); diff --git a/solution/1300-1399/1305.All Elements in Two Binary Search Trees/README.md b/solution/1300-1399/1305.All Elements in Two Binary Search Trees/README.md index 3d81c3c2f47e4..968b49c92d078 100644 --- a/solution/1300-1399/1305.All Elements in Two Binary Search Trees/README.md +++ b/solution/1300-1399/1305.All Elements in Two Binary Search Trees/README.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -103,6 +105,8 @@ class Solution: return merge(t1, t2) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -158,6 +162,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -203,6 +209,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -251,6 +259,8 @@ func getAllElements(root1 *TreeNode, root2 *TreeNode) []int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -295,6 +305,8 @@ function getAllElements(root1: TreeNode | null, root2: TreeNode | null): number[ } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/1300-1399/1305.All Elements in Two Binary Search Trees/README_EN.md b/solution/1300-1399/1305.All Elements in Two Binary Search Trees/README_EN.md index 96ecf913a5c10..1fe1ea8f8e4b3 100644 --- a/solution/1300-1399/1305.All Elements in Two Binary Search Trees/README_EN.md +++ b/solution/1300-1399/1305.All Elements in Two Binary Search Trees/README_EN.md @@ -57,6 +57,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -97,6 +99,8 @@ class Solution: return merge(t1, t2) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -152,6 +156,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -197,6 +203,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -245,6 +253,8 @@ func getAllElements(root1 *TreeNode, root2 *TreeNode) []int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -289,6 +299,8 @@ function getAllElements(root1: TreeNode | null, root2: TreeNode | null): number[ } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/1300-1399/1306.Jump Game III/README.md b/solution/1300-1399/1306.Jump Game III/README.md index 80f768989cc97..f2eeb23eaf36e 100644 --- a/solution/1300-1399/1306.Jump Game III/README.md +++ b/solution/1300-1399/1306.Jump Game III/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def canReach(self, arr: List[int], start: int) -> bool: @@ -100,6 +102,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean canReach(int[] arr, int start) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func canReach(arr []int, start int) bool { q := []int{start} @@ -168,6 +176,8 @@ func canReach(arr []int, start int) bool { } ``` +#### TypeScript + ```ts function canReach(arr: number[], start: number): boolean { const q: number[] = [start]; diff --git a/solution/1300-1399/1306.Jump Game III/README_EN.md b/solution/1300-1399/1306.Jump Game III/README_EN.md index 256bfc13e66bc..d953b2027badf 100644 --- a/solution/1300-1399/1306.Jump Game III/README_EN.md +++ b/solution/1300-1399/1306.Jump Game III/README_EN.md @@ -73,6 +73,8 @@ index 0 -> index 4 -> index 1 -> index 3 +#### Python3 + ```python class Solution: def canReach(self, arr: List[int], start: int) -> bool: @@ -89,6 +91,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean canReach(int[] arr, int start) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func canReach(arr []int, start int) bool { q := []int{start} @@ -157,6 +165,8 @@ func canReach(arr []int, start int) bool { } ``` +#### TypeScript + ```ts function canReach(arr: number[], start: number): boolean { const q: number[] = [start]; diff --git a/solution/1300-1399/1307.Verbal Arithmetic Puzzle/README.md b/solution/1300-1399/1307.Verbal Arithmetic Puzzle/README.md index a242a21010baa..16dcf92e41a56 100644 --- a/solution/1300-1399/1307.Verbal Arithmetic Puzzle/README.md +++ b/solution/1300-1399/1307.Verbal Arithmetic Puzzle/README.md @@ -83,18 +83,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1300-1399/1307.Verbal Arithmetic Puzzle/README_EN.md b/solution/1300-1399/1307.Verbal Arithmetic Puzzle/README_EN.md index 6a4ac9bd01074..5d0c3a32f90ae 100644 --- a/solution/1300-1399/1307.Verbal Arithmetic Puzzle/README_EN.md +++ b/solution/1300-1399/1307.Verbal Arithmetic Puzzle/README_EN.md @@ -80,18 +80,26 @@ Note that two different characters cannot map to the same digit. +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1300-1399/1308.Running Total for Different Genders/README.md b/solution/1300-1399/1308.Running Total for Different Genders/README.md index c006fa605e243..f3647b5196df9 100644 --- a/solution/1300-1399/1308.Running Total for Different Genders/README.md +++ b/solution/1300-1399/1308.Running Total for Different Genders/README.md @@ -99,6 +99,8 @@ Scores表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1300-1399/1308.Running Total for Different Genders/README_EN.md b/solution/1300-1399/1308.Running Total for Different Genders/README_EN.md index 6bf5a31d4a815..0bad38e3837fb 100644 --- a/solution/1300-1399/1308.Running Total for Different Genders/README_EN.md +++ b/solution/1300-1399/1308.Running Total for Different Genders/README_EN.md @@ -99,6 +99,8 @@ The fifth day is 2020-01-07, Bajrang scored 7 points and the total score for the +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1300-1399/1309.Decrypt String from Alphabet to Integer Mapping/README.md b/solution/1300-1399/1309.Decrypt String from Alphabet to Integer Mapping/README.md index 4aa43930a6c7c..c1d3a2ad2757d 100644 --- a/solution/1300-1399/1309.Decrypt String from Alphabet to Integer Mapping/README.md +++ b/solution/1300-1399/1309.Decrypt String from Alphabet to Integer Mapping/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def freqAlphabets(self, s: str) -> str: @@ -84,6 +86,8 @@ class Solution: return ''.join(res) ``` +#### Java + ```java class Solution { public String freqAlphabets(String s) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### TypeScript + ```ts function freqAlphabets(s: string): string { const n = s.length; @@ -125,6 +131,8 @@ function freqAlphabets(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn freq_alphabets(s: String) -> String { @@ -148,6 +156,8 @@ impl Solution { } ``` +#### C + ```c char* freqAlphabets(char* s) { int n = strlen(s); diff --git a/solution/1300-1399/1309.Decrypt String from Alphabet to Integer Mapping/README_EN.md b/solution/1300-1399/1309.Decrypt String from Alphabet to Integer Mapping/README_EN.md index fd446fdca5d29..1a1e65de8e681 100644 --- a/solution/1300-1399/1309.Decrypt String from Alphabet to Integer Mapping/README_EN.md +++ b/solution/1300-1399/1309.Decrypt String from Alphabet to Integer Mapping/README_EN.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def freqAlphabets(self, s: str) -> str: @@ -82,6 +84,8 @@ class Solution: return ''.join(res) ``` +#### Java + ```java class Solution { public String freqAlphabets(String s) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### TypeScript + ```ts function freqAlphabets(s: string): string { const n = s.length; @@ -123,6 +129,8 @@ function freqAlphabets(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn freq_alphabets(s: String) -> String { @@ -146,6 +154,8 @@ impl Solution { } ``` +#### C + ```c char* freqAlphabets(char* s) { int n = strlen(s); diff --git a/solution/1300-1399/1310.XOR Queries of a Subarray/README.md b/solution/1300-1399/1310.XOR Queries of a Subarray/README.md index 2b3f6ecfc5f9a..8a45d8beb1435 100644 --- a/solution/1300-1399/1310.XOR Queries of a Subarray/README.md +++ b/solution/1300-1399/1310.XOR Queries of a Subarray/README.md @@ -88,6 +88,8 @@ $$ +#### Python3 + ```python class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: @@ -95,6 +97,8 @@ class Solution: return [s[r + 1] ^ s[l] for l, r in queries] ``` +#### Java + ```java class Solution { public int[] xorQueries(int[] arr, int[][] queries) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func xorQueries(arr []int, queries [][]int) (ans []int) { n := len(arr) @@ -149,6 +157,8 @@ func xorQueries(arr []int, queries [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function xorQueries(arr: number[], queries: number[][]): number[] { const n = arr.length; @@ -164,6 +174,8 @@ function xorQueries(arr: number[], queries: number[][]): number[] { } ``` +#### JavaScript + ```js /** * @param {number[]} arr diff --git a/solution/1300-1399/1310.XOR Queries of a Subarray/README_EN.md b/solution/1300-1399/1310.XOR Queries of a Subarray/README_EN.md index ee6db3c2c96b3..53b49c510c7e8 100644 --- a/solution/1300-1399/1310.XOR Queries of a Subarray/README_EN.md +++ b/solution/1300-1399/1310.XOR Queries of a Subarray/README_EN.md @@ -72,6 +72,8 @@ The XOR values for queries are: +#### Python3 + ```python class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: @@ -79,6 +81,8 @@ class Solution: return [s[r + 1] ^ s[l] for l, r in queries] ``` +#### Java + ```java class Solution { public int[] xorQueries(int[] arr, int[][] queries) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func xorQueries(arr []int, queries [][]int) (ans []int) { n := len(arr) @@ -133,6 +141,8 @@ func xorQueries(arr []int, queries [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function xorQueries(arr: number[], queries: number[][]): number[] { const n = arr.length; @@ -148,6 +158,8 @@ function xorQueries(arr: number[], queries: number[][]): number[] { } ``` +#### JavaScript + ```js /** * @param {number[]} arr diff --git a/solution/1300-1399/1311.Get Watched Videos by Your Friends/README.md b/solution/1300-1399/1311.Get Watched Videos by Your Friends/README.md index f164ed25fa676..3bc2a6c5382ec 100644 --- a/solution/1300-1399/1311.Get Watched Videos by Your Friends/README.md +++ b/solution/1300-1399/1311.Get Watched Videos by Your Friends/README.md @@ -83,6 +83,8 @@ C -> 2 +#### Python3 + ```python class Solution: def watchedVideosByFriends( @@ -114,6 +116,8 @@ class Solution: return [v[0] for v in videos] ``` +#### Java + ```java class Solution { public List watchedVideosByFriends( diff --git a/solution/1300-1399/1311.Get Watched Videos by Your Friends/README_EN.md b/solution/1300-1399/1311.Get Watched Videos by Your Friends/README_EN.md index 75008a21d4b05..9db5bcfb0808e 100644 --- a/solution/1300-1399/1311.Get Watched Videos by Your Friends/README_EN.md +++ b/solution/1300-1399/1311.Get Watched Videos by Your Friends/README_EN.md @@ -79,6 +79,8 @@ You have id = 0 (green color in the figure) and the only friend of your friends +#### Python3 + ```python class Solution: def watchedVideosByFriends( @@ -110,6 +112,8 @@ class Solution: return [v[0] for v in videos] ``` +#### Java + ```java class Solution { public List watchedVideosByFriends( diff --git a/solution/1300-1399/1312.Minimum Insertion Steps to Make a String Palindrome/README.md b/solution/1300-1399/1312.Minimum Insertion Steps to Make a String Palindrome/README.md index 5f522f35f6b47..49c0a2c40775f 100644 --- a/solution/1300-1399/1312.Minimum Insertion Steps to Make a String Palindrome/README.md +++ b/solution/1300-1399/1312.Minimum Insertion Steps to Make a String Palindrome/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def minInsertions(self, s: str) -> int: @@ -98,6 +100,8 @@ class Solution: return dfs(0, len(s) - 1) ``` +#### Java + ```java class Solution { private Integer[][] f; @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func minInsertions(s string) int { n := len(s) @@ -217,6 +225,8 @@ $$ +#### Python3 + ```python class Solution: def minInsertions(self, s: str) -> int: @@ -231,6 +241,8 @@ class Solution: return f[0][-1] ``` +#### Java + ```java class Solution { public int minInsertions(String s) { @@ -250,6 +262,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -271,6 +285,8 @@ public: }; ``` +#### Go + ```go func minInsertions(s string) int { n := len(s) @@ -301,6 +317,8 @@ func minInsertions(s string) int { +#### Python3 + ```python class Solution: def minInsertions(self, s: str) -> int: @@ -316,6 +334,8 @@ class Solution: return f[0][n - 1] ``` +#### Java + ```java class Solution { public int minInsertions(String s) { @@ -336,6 +356,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -358,6 +380,8 @@ public: }; ``` +#### Go + ```go func minInsertions(s string) int { n := len(s) diff --git a/solution/1300-1399/1312.Minimum Insertion Steps to Make a String Palindrome/README_EN.md b/solution/1300-1399/1312.Minimum Insertion Steps to Make a String Palindrome/README_EN.md index 99f2edff1c603..9954d0d24bd48 100644 --- a/solution/1300-1399/1312.Minimum Insertion Steps to Make a String Palindrome/README_EN.md +++ b/solution/1300-1399/1312.Minimum Insertion Steps to Make a String Palindrome/README_EN.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def minInsertions(self, s: str) -> int: @@ -82,6 +84,8 @@ class Solution: return dfs(0, len(s) - 1) ``` +#### Java + ```java class Solution { private Integer[][] f; @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func minInsertions(s string) int { n := len(s) @@ -180,6 +188,8 @@ func minInsertions(s string) int { +#### Python3 + ```python class Solution: def minInsertions(self, s: str) -> int: @@ -194,6 +204,8 @@ class Solution: return f[0][-1] ``` +#### Java + ```java class Solution { public int minInsertions(String s) { @@ -213,6 +225,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -234,6 +248,8 @@ public: }; ``` +#### Go + ```go func minInsertions(s string) int { n := len(s) @@ -264,6 +280,8 @@ func minInsertions(s string) int { +#### Python3 + ```python class Solution: def minInsertions(self, s: str) -> int: @@ -279,6 +297,8 @@ class Solution: return f[0][n - 1] ``` +#### Java + ```java class Solution { public int minInsertions(String s) { @@ -299,6 +319,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -321,6 +343,8 @@ public: }; ``` +#### Go + ```go func minInsertions(s string) int { n := len(s) diff --git a/solution/1300-1399/1313.Decompress Run-Length Encoded List/README.md b/solution/1300-1399/1313.Decompress Run-Length Encoded List/README.md index 5d84bbf73e34b..91587275b4dae 100644 --- a/solution/1300-1399/1313.Decompress Run-Length Encoded List/README.md +++ b/solution/1300-1399/1313.Decompress Run-Length Encoded List/README.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def decompressRLElist(self, nums: List[int]) -> List[int]: @@ -71,6 +73,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public int[] decompressRLElist(int[] nums) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -104,6 +110,8 @@ public: }; ``` +#### Go + ```go func decompressRLElist(nums []int) []int { var res []int @@ -116,6 +124,8 @@ func decompressRLElist(nums []int) []int { } ``` +#### TypeScript + ```ts function decompressRLElist(nums: number[]): number[] { let n = nums.length >> 1; @@ -129,6 +139,8 @@ function decompressRLElist(nums: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn decompress_rl_elist(nums: Vec) -> Vec { @@ -144,6 +156,8 @@ impl Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). diff --git a/solution/1300-1399/1313.Decompress Run-Length Encoded List/README_EN.md b/solution/1300-1399/1313.Decompress Run-Length Encoded List/README_EN.md index 826605931f128..b27e911e56a5f 100644 --- a/solution/1300-1399/1313.Decompress Run-Length Encoded List/README_EN.md +++ b/solution/1300-1399/1313.Decompress Run-Length Encoded List/README_EN.md @@ -61,6 +61,8 @@ At the end the concatenation [2] + [4,4,4] is [2,4,4,4]. +#### Python3 + ```python class Solution: def decompressRLElist(self, nums: List[int]) -> List[int]: @@ -70,6 +72,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public int[] decompressRLElist(int[] nums) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -103,6 +109,8 @@ public: }; ``` +#### Go + ```go func decompressRLElist(nums []int) []int { var res []int @@ -115,6 +123,8 @@ func decompressRLElist(nums []int) []int { } ``` +#### TypeScript + ```ts function decompressRLElist(nums: number[]): number[] { let n = nums.length >> 1; @@ -128,6 +138,8 @@ function decompressRLElist(nums: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn decompress_rl_elist(nums: Vec) -> Vec { @@ -143,6 +155,8 @@ impl Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). diff --git a/solution/1300-1399/1314.Matrix Block Sum/README.md b/solution/1300-1399/1314.Matrix Block Sum/README.md index 570ef42e6745a..b2d7568124872 100644 --- a/solution/1300-1399/1314.Matrix Block Sum/README.md +++ b/solution/1300-1399/1314.Matrix Block Sum/README.md @@ -83,6 +83,8 @@ $$ +#### Python3 + ```python class Solution: def matrixBlockSum(self, mat: List[List[int]], k: int) -> List[List[int]]: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] matrixBlockSum(int[][] mat, int k) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func matrixBlockSum(mat [][]int, k int) [][]int { m, n := len(mat), len(mat[0]) @@ -190,6 +198,8 @@ func matrixBlockSum(mat [][]int, k int) [][]int { } ``` +#### TypeScript + ```ts function matrixBlockSum(mat: number[][], k: number): number[][] { const m: number = mat.length; diff --git a/solution/1300-1399/1314.Matrix Block Sum/README_EN.md b/solution/1300-1399/1314.Matrix Block Sum/README_EN.md index 7a5b11ce479fb..fd6941cea7ad6 100644 --- a/solution/1300-1399/1314.Matrix Block Sum/README_EN.md +++ b/solution/1300-1399/1314.Matrix Block Sum/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def matrixBlockSum(self, mat: List[List[int]], k: int) -> List[List[int]]: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] matrixBlockSum(int[][] mat, int k) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func matrixBlockSum(mat [][]int, k int) [][]int { m, n := len(mat), len(mat[0]) @@ -188,6 +196,8 @@ func matrixBlockSum(mat [][]int, k int) [][]int { } ``` +#### TypeScript + ```ts function matrixBlockSum(mat: number[][], k: number): number[][] { const m: number = mat.length; diff --git a/solution/1300-1399/1315.Sum of Nodes with Even-Valued Grandparent/README.md b/solution/1300-1399/1315.Sum of Nodes with Even-Valued Grandparent/README.md index 563edce750258..86086b342de51 100644 --- a/solution/1300-1399/1315.Sum of Nodes with Even-Valued Grandparent/README.md +++ b/solution/1300-1399/1315.Sum of Nodes with Even-Valued Grandparent/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -92,6 +94,8 @@ class Solution: return dfs(root, 1) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -196,6 +204,8 @@ func sumEvenGrandparent(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/1300-1399/1315.Sum of Nodes with Even-Valued Grandparent/README_EN.md b/solution/1300-1399/1315.Sum of Nodes with Even-Valued Grandparent/README_EN.md index 2eb48ccf7ff80..45048625fd8a6 100644 --- a/solution/1300-1399/1315.Sum of Nodes with Even-Valued Grandparent/README_EN.md +++ b/solution/1300-1399/1315.Sum of Nodes with Even-Valued Grandparent/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -92,6 +94,8 @@ class Solution: return dfs(root, 1) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -196,6 +204,8 @@ func sumEvenGrandparent(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/1300-1399/1316.Distinct Echo Substrings/README.md b/solution/1300-1399/1316.Distinct Echo Substrings/README.md index b3e2098cdce48..db72eee26fdac 100644 --- a/solution/1300-1399/1316.Distinct Echo Substrings/README.md +++ b/solution/1300-1399/1316.Distinct Echo Substrings/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def distinctEchoSubstrings(self, text: str) -> int: @@ -98,6 +100,8 @@ class Solution: return len(vis) ``` +#### Java + ```java class Solution { private long[] h; @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp typedef unsigned long long ull; @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func distinctEchoSubstrings(text string) int { n := len(text) @@ -197,6 +205,8 @@ func distinctEchoSubstrings(text string) int { } ``` +#### Rust + ```rust use std::collections::HashSet; diff --git a/solution/1300-1399/1316.Distinct Echo Substrings/README_EN.md b/solution/1300-1399/1316.Distinct Echo Substrings/README_EN.md index 1fde19de3f72e..3055f54832f76 100644 --- a/solution/1300-1399/1316.Distinct Echo Substrings/README_EN.md +++ b/solution/1300-1399/1316.Distinct Echo Substrings/README_EN.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python class Solution: def distinctEchoSubstrings(self, text: str) -> int: @@ -84,6 +86,8 @@ class Solution: return len(vis) ``` +#### Java + ```java class Solution { private long[] h; @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp typedef unsigned long long ull; @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func distinctEchoSubstrings(text string) int { n := len(text) @@ -183,6 +191,8 @@ func distinctEchoSubstrings(text string) int { } ``` +#### Rust + ```rust use std::collections::HashSet; diff --git a/solution/1300-1399/1317.Convert Integer to the Sum of Two No-Zero Integers/README.md b/solution/1300-1399/1317.Convert Integer to the Sum of Two No-Zero Integers/README.md index b8d6e746566dd..95a71c37bca2d 100644 --- a/solution/1300-1399/1317.Convert Integer to the Sum of Two No-Zero Integers/README.md +++ b/solution/1300-1399/1317.Convert Integer to the Sum of Two No-Zero Integers/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def getNoZeroIntegers(self, n: int) -> List[int]: @@ -95,6 +97,8 @@ class Solution: return [a, b] ``` +#### Java + ```java class Solution { public int[] getNoZeroIntegers(int n) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func getNoZeroIntegers(n int) []int { for a := 1; ; a++ { @@ -143,6 +151,8 @@ func getNoZeroIntegers(n int) []int { +#### Python3 + ```python class Solution: def getNoZeroIntegers(self, n: int) -> List[int]: @@ -159,6 +169,8 @@ class Solution: return [a, b] ``` +#### Java + ```java class Solution { public int[] getNoZeroIntegers(int n) { @@ -181,6 +193,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -203,6 +217,8 @@ public: }; ``` +#### Go + ```go func getNoZeroIntegers(n int) []int { f := func(x int) bool { diff --git a/solution/1300-1399/1317.Convert Integer to the Sum of Two No-Zero Integers/README_EN.md b/solution/1300-1399/1317.Convert Integer to the Sum of Two No-Zero Integers/README_EN.md index 55a80a8430080..440f2650d8888 100644 --- a/solution/1300-1399/1317.Convert Integer to the Sum of Two No-Zero Integers/README_EN.md +++ b/solution/1300-1399/1317.Convert Integer to the Sum of Two No-Zero Integers/README_EN.md @@ -66,6 +66,8 @@ Note that there are other valid answers as [8, 3] that can be accepted. +#### Python3 + ```python class Solution: def getNoZeroIntegers(self, n: int) -> List[int]: @@ -75,6 +77,8 @@ class Solution: return [a, b] ``` +#### Java + ```java class Solution { public int[] getNoZeroIntegers(int n) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -102,6 +108,8 @@ public: }; ``` +#### Go + ```go func getNoZeroIntegers(n int) []int { for a := 1; ; a++ { @@ -123,6 +131,8 @@ func getNoZeroIntegers(n int) []int { +#### Python3 + ```python class Solution: def getNoZeroIntegers(self, n: int) -> List[int]: @@ -139,6 +149,8 @@ class Solution: return [a, b] ``` +#### Java + ```java class Solution { public int[] getNoZeroIntegers(int n) { @@ -161,6 +173,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -183,6 +197,8 @@ public: }; ``` +#### Go + ```go func getNoZeroIntegers(n int) []int { f := func(x int) bool { diff --git a/solution/1300-1399/1318.Minimum Flips to Make a OR b Equal to c/README.md b/solution/1300-1399/1318.Minimum Flips to Make a OR b Equal to c/README.md index e457f5f444fa8..081282a54edb8 100644 --- a/solution/1300-1399/1318.Minimum Flips to Make a OR b Equal to c/README.md +++ b/solution/1300-1399/1318.Minimum Flips to Make a OR b Equal to c/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def minFlips(self, a: int, b: int, c: int) -> int: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minFlips(int a, int b, int c) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func minFlips(a int, b int, c int) (ans int) { for i := 0; i < 32; i++ { @@ -121,6 +129,8 @@ func minFlips(a int, b int, c int) (ans int) { } ``` +#### TypeScript + ```ts function minFlips(a: number, b: number, c: number): number { let ans = 0; diff --git a/solution/1300-1399/1318.Minimum Flips to Make a OR b Equal to c/README_EN.md b/solution/1300-1399/1318.Minimum Flips to Make a OR b Equal to c/README_EN.md index d09e3f0ffb8b9..5d94e91fb76df 100644 --- a/solution/1300-1399/1318.Minimum Flips to Make a OR b Equal to c/README_EN.md +++ b/solution/1300-1399/1318.Minimum Flips to Make a OR b Equal to c/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(\log M)$, where $M$ is the maximum value of the number +#### Python3 + ```python class Solution: def minFlips(self, a: int, b: int, c: int) -> int: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minFlips(int a, int b, int c) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func minFlips(a int, b int, c int) (ans int) { for i := 0; i < 32; i++ { @@ -135,6 +143,8 @@ func minFlips(a int, b int, c int) (ans int) { } ``` +#### TypeScript + ```ts function minFlips(a: number, b: number, c: number): number { let ans = 0; diff --git a/solution/1300-1399/1319.Number of Operations to Make Network Connected/README.md b/solution/1300-1399/1319.Number of Operations to Make Network Connected/README.md index 62aee5ee5bb24..5902e3c36bb5c 100644 --- a/solution/1300-1399/1319.Number of Operations to Make Network Connected/README.md +++ b/solution/1300-1399/1319.Number of Operations to Make Network Connected/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def makeConnected(self, n: int, connections: List[List[int]]) -> int: @@ -102,6 +104,8 @@ class Solution: return -1 if size - 1 > cnt else size - 1 ``` +#### Java + ```java class Solution { private int[] p; @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func makeConnected(n int, connections [][]int) int { p := make([]int, n) diff --git a/solution/1300-1399/1319.Number of Operations to Make Network Connected/README_EN.md b/solution/1300-1399/1319.Number of Operations to Make Network Connected/README_EN.md index c6358ec752633..9caf24d4e58f9 100644 --- a/solution/1300-1399/1319.Number of Operations to Make Network Connected/README_EN.md +++ b/solution/1300-1399/1319.Number of Operations to Make Network Connected/README_EN.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def makeConnected(self, n: int, connections: List[List[int]]) -> int: @@ -93,6 +95,8 @@ class Solution: return -1 if size - 1 > cnt else size - 1 ``` +#### Java + ```java class Solution { private int[] p; @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func makeConnected(n int, connections [][]int) int { p := make([]int, n) diff --git a/solution/1300-1399/1320.Minimum Distance to Type a Word Using Two Fingers/README.md b/solution/1300-1399/1320.Minimum Distance to Type a Word Using Two Fingers/README.md index 3a5a3d7a5f7c3..bf690e32311f9 100644 --- a/solution/1300-1399/1320.Minimum Distance to Type a Word Using Two Fingers/README.md +++ b/solution/1300-1399/1320.Minimum Distance to Type a Word Using Two Fingers/README.md @@ -102,6 +102,8 @@ tags: +#### Python3 + ```python class Solution: def minimumDistance(self, word: str) -> int: @@ -131,6 +133,8 @@ class Solution: return int(min(a, b)) ``` +#### Java + ```java class Solution { public int minimumDistance(String word) { @@ -178,6 +182,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -221,6 +227,8 @@ public: }; ``` +#### Go + ```go func minimumDistance(word string) int { n := len(word) diff --git a/solution/1300-1399/1320.Minimum Distance to Type a Word Using Two Fingers/README_EN.md b/solution/1300-1399/1320.Minimum Distance to Type a Word Using Two Fingers/README_EN.md index 0c4d5ec94ce7c..059abe5db3119 100644 --- a/solution/1300-1399/1320.Minimum Distance to Type a Word Using Two Fingers/README_EN.md +++ b/solution/1300-1399/1320.Minimum Distance to Type a Word Using Two Fingers/README_EN.md @@ -78,6 +78,8 @@ Total distance = 6 +#### Python3 + ```python class Solution: def minimumDistance(self, word: str) -> int: @@ -107,6 +109,8 @@ class Solution: return int(min(a, b)) ``` +#### Java + ```java class Solution { public int minimumDistance(String word) { @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -197,6 +203,8 @@ public: }; ``` +#### Go + ```go func minimumDistance(word string) int { n := len(word) diff --git a/solution/1300-1399/1321.Restaurant Growth/README.md b/solution/1300-1399/1321.Restaurant Growth/README.md index 78c4b030d9f47..b56b0ee7cde68 100644 --- a/solution/1300-1399/1321.Restaurant Growth/README.md +++ b/solution/1300-1399/1321.Restaurant Growth/README.md @@ -90,6 +90,8 @@ Customer 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -126,6 +128,8 @@ WHERE rk > 6; +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1300-1399/1321.Restaurant Growth/README_EN.md b/solution/1300-1399/1321.Restaurant Growth/README_EN.md index c63629a07345e..afde32686e56c 100644 --- a/solution/1300-1399/1321.Restaurant Growth/README_EN.md +++ b/solution/1300-1399/1321.Restaurant Growth/README_EN.md @@ -90,6 +90,8 @@ Customer table: +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -126,6 +128,8 @@ WHERE rk > 6; +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1300-1399/1322.Ads Performance/README.md b/solution/1300-1399/1322.Ads Performance/README.md index 86d69861b9d8d..ab2f9d87549f6 100644 --- a/solution/1300-1399/1322.Ads Performance/README.md +++ b/solution/1300-1399/1322.Ads Performance/README.md @@ -93,6 +93,8 @@ Ads 表: +#### MySQL + ```sql SELECT ad_id, diff --git a/solution/1300-1399/1322.Ads Performance/README_EN.md b/solution/1300-1399/1322.Ads Performance/README_EN.md index 32983e48e28eb..a0cb4c4fb33a3 100644 --- a/solution/1300-1399/1322.Ads Performance/README_EN.md +++ b/solution/1300-1399/1322.Ads Performance/README_EN.md @@ -90,6 +90,8 @@ Note that we do not care about Ignored Ads. +#### MySQL + ```sql SELECT ad_id, diff --git a/solution/1300-1399/1323.Maximum 69 Number/README.md b/solution/1300-1399/1323.Maximum 69 Number/README.md index 6ccca2c47e354..b3711a9cd6960 100644 --- a/solution/1300-1399/1323.Maximum 69 Number/README.md +++ b/solution/1300-1399/1323.Maximum 69 Number/README.md @@ -74,12 +74,16 @@ tags: +#### Python3 + ```python class Solution: def maximum69Number(self, num: int) -> int: return int(str(num).replace("6", "9", 1)) ``` +#### Java + ```java class Solution { public int maximum69Number(int num) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -104,6 +110,8 @@ public: }; ``` +#### Go + ```go func maximum69Number(num int) int { s := strconv.Itoa(num) @@ -119,12 +127,16 @@ func maximum69Number(num int) int { } ``` +#### TypeScript + ```ts function maximum69Number(num: number): number { return Number((num + '').replace('6', '9')); } ``` +#### Rust + ```rust impl Solution { pub fn maximum69_number(num: i32) -> i32 { @@ -133,6 +145,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** @@ -148,6 +162,8 @@ class Solution { } ``` +#### C + ```c int maximum69Number(int num) { int n = 0; diff --git a/solution/1300-1399/1323.Maximum 69 Number/README_EN.md b/solution/1300-1399/1323.Maximum 69 Number/README_EN.md index bf09b7cb6953c..b255ef148389d 100644 --- a/solution/1300-1399/1323.Maximum 69 Number/README_EN.md +++ b/solution/1300-1399/1323.Maximum 69 Number/README_EN.md @@ -71,12 +71,16 @@ The maximum number is 9969. +#### Python3 + ```python class Solution: def maximum69Number(self, num: int) -> int: return int(str(num).replace("6", "9", 1)) ``` +#### Java + ```java class Solution { public int maximum69Number(int num) { @@ -85,6 +89,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,6 +107,8 @@ public: }; ``` +#### Go + ```go func maximum69Number(num int) int { s := strconv.Itoa(num) @@ -116,12 +124,16 @@ func maximum69Number(num int) int { } ``` +#### TypeScript + ```ts function maximum69Number(num: number): number { return Number((num + '').replace('6', '9')); } ``` +#### Rust + ```rust impl Solution { pub fn maximum69_number(num: i32) -> i32 { @@ -130,6 +142,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** @@ -145,6 +159,8 @@ class Solution { } ``` +#### C + ```c int maximum69Number(int num) { int n = 0; diff --git a/solution/1300-1399/1324.Print Words Vertically/README.md b/solution/1300-1399/1324.Print Words Vertically/README.md index f6dc2d7973a21..24afc20dca6fd 100644 --- a/solution/1300-1399/1324.Print Words Vertically/README.md +++ b/solution/1300-1399/1324.Print Words Vertically/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def printVertically(self, s: str) -> List[str]: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List printVertically(String s) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func printVertically(s string) (ans []string) { words := strings.Split(s, " ") diff --git a/solution/1300-1399/1324.Print Words Vertically/README_EN.md b/solution/1300-1399/1324.Print Words Vertically/README_EN.md index b4643e5711ef5..c86ec25b2c2cb 100644 --- a/solution/1300-1399/1324.Print Words Vertically/README_EN.md +++ b/solution/1300-1399/1324.Print Words Vertically/README_EN.md @@ -98,6 +98,8 @@ Each word would be put on only one column and that in one column there will be o +#### Python3 + ```python class Solution: def printVertically(self, s: str) -> List[str]: @@ -112,6 +114,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List printVertically(String s) { @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func printVertically(s string) (ans []string) { words := strings.Split(s, " ") diff --git a/solution/1300-1399/1325.Delete Leaves With a Given Value/README.md b/solution/1300-1399/1325.Delete Leaves With a Given Value/README.md index b3b54f09efdac..93c75ff6e69f9 100644 --- a/solution/1300-1399/1325.Delete Leaves With a Given Value/README.md +++ b/solution/1300-1399/1325.Delete Leaves With a Given Value/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -115,6 +117,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -196,6 +204,8 @@ func removeLeafNodes(root *TreeNode, target int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/1300-1399/1325.Delete Leaves With a Given Value/README_EN.md b/solution/1300-1399/1325.Delete Leaves With a Given Value/README_EN.md index 8b6c3db9439e8..e791d9ac43dbb 100644 --- a/solution/1300-1399/1325.Delete Leaves With a Given Value/README_EN.md +++ b/solution/1300-1399/1325.Delete Leaves With a Given Value/README_EN.md @@ -73,6 +73,8 @@ After removing, new nodes become leaf nodes with value (target = 2) (Picture in +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -93,6 +95,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -174,6 +182,8 @@ func removeLeafNodes(root *TreeNode, target int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/1300-1399/1326.Minimum Number of Taps to Open to Water a Garden/README.md b/solution/1300-1399/1326.Minimum Number of Taps to Open to Water a Garden/README.md index 1afa26a96c6c0..5184db67f9b87 100644 --- a/solution/1300-1399/1326.Minimum Number of Taps to Open to Water a Garden/README.md +++ b/solution/1300-1399/1326.Minimum Number of Taps to Open to Water a Garden/README.md @@ -100,6 +100,8 @@ tags: +#### Python3 + ```python class Solution: def minTaps(self, n: int, ranges: List[int]) -> int: @@ -119,6 +121,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minTaps(int n, int[] ranges) { @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func minTaps(n int, ranges []int) (ans int) { last := make([]int, n+1) @@ -190,6 +198,8 @@ func minTaps(n int, ranges []int) (ans int) { } ``` +#### TypeScript + ```ts function minTaps(n: number, ranges: number[]): number { const last = new Array(n + 1).fill(0); @@ -215,6 +225,8 @@ function minTaps(n: number, ranges: number[]): number { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/1300-1399/1326.Minimum Number of Taps to Open to Water a Garden/README_EN.md b/solution/1300-1399/1326.Minimum Number of Taps to Open to Water a Garden/README_EN.md index 53bc38c474004..fe40712b4dac8 100644 --- a/solution/1300-1399/1326.Minimum Number of Taps to Open to Water a Garden/README_EN.md +++ b/solution/1300-1399/1326.Minimum Number of Taps to Open to Water a Garden/README_EN.md @@ -70,6 +70,8 @@ Opening Only the second tap will water the whole garden [0,5] +#### Python3 + ```python class Solution: def minTaps(self, n: int, ranges: List[int]) -> int: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minTaps(int n, int[] ranges) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func minTaps(n int, ranges []int) (ans int) { last := make([]int, n+1) @@ -160,6 +168,8 @@ func minTaps(n int, ranges []int) (ans int) { } ``` +#### TypeScript + ```ts function minTaps(n: number, ranges: number[]): number { const last = new Array(n + 1).fill(0); @@ -185,6 +195,8 @@ function minTaps(n: number, ranges: number[]): number { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/1300-1399/1327.List the Products Ordered in a Period/README.md b/solution/1300-1399/1327.List the Products Ordered in a Period/README.md index 2c9b319af4e91..617109b202426 100644 --- a/solution/1300-1399/1327.List the Products Ordered in a Period/README.md +++ b/solution/1300-1399/1327.List the Products Ordered in a Period/README.md @@ -112,6 +112,8 @@ Orders 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT product_name, SUM(unit) AS unit diff --git a/solution/1300-1399/1327.List the Products Ordered in a Period/README_EN.md b/solution/1300-1399/1327.List the Products Ordered in a Period/README_EN.md index 2a7ae5c1550e1..1ffae6ab7b75e 100644 --- a/solution/1300-1399/1327.List the Products Ordered in a Period/README_EN.md +++ b/solution/1300-1399/1327.List the Products Ordered in a Period/README_EN.md @@ -112,6 +112,8 @@ Products with product_id = 5 is ordered in February a total of (50 + 50) = 100. +#### MySQL + ```sql # Write your MySQL query statement below SELECT product_name, SUM(unit) AS unit diff --git a/solution/1300-1399/1328.Break a Palindrome/README.md b/solution/1300-1399/1328.Break a Palindrome/README.md index f813b80063d3f..b76ea6d816308 100644 --- a/solution/1300-1399/1328.Break a Palindrome/README.md +++ b/solution/1300-1399/1328.Break a Palindrome/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def breakPalindrome(self, palindrome: str) -> str: @@ -83,6 +85,8 @@ class Solution: return "".join(s) ``` +#### Java + ```java class Solution { public String breakPalindrome(String palindrome) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func breakPalindrome(palindrome string) string { n := len(palindrome) @@ -147,6 +155,8 @@ func breakPalindrome(palindrome string) string { } ``` +#### TypeScript + ```ts function breakPalindrome(palindrome: string): string { const n = palindrome.length; diff --git a/solution/1300-1399/1328.Break a Palindrome/README_EN.md b/solution/1300-1399/1328.Break a Palindrome/README_EN.md index 9e40e17cb8aae..40fcde7846ad4 100644 --- a/solution/1300-1399/1328.Break a Palindrome/README_EN.md +++ b/solution/1300-1399/1328.Break a Palindrome/README_EN.md @@ -61,6 +61,8 @@ Of all the ways, "aaccba" is the lexicographically smallest. +#### Python3 + ```python class Solution: def breakPalindrome(self, palindrome: str) -> str: @@ -78,6 +80,8 @@ class Solution: return "".join(s) ``` +#### Java + ```java class Solution { public String breakPalindrome(String palindrome) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func breakPalindrome(palindrome string) string { n := len(palindrome) @@ -142,6 +150,8 @@ func breakPalindrome(palindrome string) string { } ``` +#### TypeScript + ```ts function breakPalindrome(palindrome: string): string { const n = palindrome.length; diff --git a/solution/1300-1399/1329.Sort the Matrix Diagonally/README.md b/solution/1300-1399/1329.Sort the Matrix Diagonally/README.md index 49b3bf1ae5262..1b3568086099d 100644 --- a/solution/1300-1399/1329.Sort the Matrix Diagonally/README.md +++ b/solution/1300-1399/1329.Sort the Matrix Diagonally/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def diagonalSort(self, mat: List[List[int]]) -> List[List[int]]: @@ -87,6 +89,8 @@ class Solution: return mat ``` +#### Java + ```java class Solution { public int[][] diagonalSort(int[][] mat) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func diagonalSort(mat [][]int) [][]int { m, n := len(mat), len(mat[0]) @@ -159,6 +167,8 @@ func diagonalSort(mat [][]int) [][]int { } ``` +#### TypeScript + ```ts function diagonalSort(mat: number[][]): number[][] { const [m, n] = [mat.length, mat[0].length]; @@ -180,6 +190,8 @@ function diagonalSort(mat: number[][]): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn diagonal_sort(mut mat: Vec>) -> Vec> { @@ -204,6 +216,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int[][] DiagonalSort(int[][] mat) { diff --git a/solution/1300-1399/1329.Sort the Matrix Diagonally/README_EN.md b/solution/1300-1399/1329.Sort the Matrix Diagonally/README_EN.md index 7240947eb330a..32f27fb62e85d 100644 --- a/solution/1300-1399/1329.Sort the Matrix Diagonally/README_EN.md +++ b/solution/1300-1399/1329.Sort the Matrix Diagonally/README_EN.md @@ -67,6 +67,8 @@ The time complexity is $O(m \times n \times \log \min(m, n))$, and the space com +#### Python3 + ```python class Solution: def diagonalSort(self, mat: List[List[int]]) -> List[List[int]]: @@ -83,6 +85,8 @@ class Solution: return mat ``` +#### Java + ```java class Solution { public int[][] diagonalSort(int[][] mat) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func diagonalSort(mat [][]int) [][]int { m, n := len(mat), len(mat[0]) @@ -155,6 +163,8 @@ func diagonalSort(mat [][]int) [][]int { } ``` +#### TypeScript + ```ts function diagonalSort(mat: number[][]): number[][] { const [m, n] = [mat.length, mat[0].length]; @@ -176,6 +186,8 @@ function diagonalSort(mat: number[][]): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn diagonal_sort(mut mat: Vec>) -> Vec> { @@ -200,6 +212,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int[][] DiagonalSort(int[][] mat) { diff --git a/solution/1300-1399/1330.Reverse Subarray To Maximize Array Value/README.md b/solution/1300-1399/1330.Reverse Subarray To Maximize Array Value/README.md index fed9c4876d19b..c7b95f909d7d2 100644 --- a/solution/1300-1399/1330.Reverse Subarray To Maximize Array Value/README.md +++ b/solution/1300-1399/1330.Reverse Subarray To Maximize Array Value/README.md @@ -105,6 +105,8 @@ $$ +#### Python3 + ```python class Solution: def maxValueAfterReverse(self, nums: List[int]) -> int: @@ -123,6 +125,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxValueAfterReverse(int[] nums) { @@ -156,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go func maxValueAfterReverse(nums []int) int { s, n := 0, len(nums) @@ -226,6 +234,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function maxValueAfterReverse(nums: number[]): number { const n = nums.length; diff --git a/solution/1300-1399/1330.Reverse Subarray To Maximize Array Value/README_EN.md b/solution/1300-1399/1330.Reverse Subarray To Maximize Array Value/README_EN.md index c9fe97aad83ee..d392ca046cf87 100644 --- a/solution/1300-1399/1330.Reverse Subarray To Maximize Array Value/README_EN.md +++ b/solution/1300-1399/1330.Reverse Subarray To Maximize Array Value/README_EN.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def maxValueAfterReverse(self, nums: List[int]) -> int: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxValueAfterReverse(int[] nums) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func maxValueAfterReverse(nums []int) int { s, n := 0, len(nums) @@ -181,6 +189,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function maxValueAfterReverse(nums: number[]): number { const n = nums.length; diff --git a/solution/1300-1399/1331.Rank Transform of an Array/README.md b/solution/1300-1399/1331.Rank Transform of an Array/README.md index 8961344098edf..6b31f108e0dca 100644 --- a/solution/1300-1399/1331.Rank Transform of an Array/README.md +++ b/solution/1300-1399/1331.Rank Transform of an Array/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def arrayRankTransform(self, arr: List[int]) -> List[int]: @@ -83,6 +85,8 @@ class Solution: return [bisect_right(t, x) for x in arr] ``` +#### Java + ```java class Solution { public int[] arrayRankTransform(int[] arr) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func arrayRankTransform(arr []int) (ans []int) { t := make([]int, len(arr)) @@ -140,6 +148,8 @@ func arrayRankTransform(arr []int) (ans []int) { } ``` +#### TypeScript + ```ts function arrayRankTransform(arr: number[]): number[] { const t = [...arr].sort((a, b) => a - b); diff --git a/solution/1300-1399/1331.Rank Transform of an Array/README_EN.md b/solution/1300-1399/1331.Rank Transform of an Array/README_EN.md index f37da095f1473..62948b11bb98b 100644 --- a/solution/1300-1399/1331.Rank Transform of an Array/README_EN.md +++ b/solution/1300-1399/1331.Rank Transform of an Array/README_EN.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def arrayRankTransform(self, arr: List[int]) -> List[int]: @@ -78,6 +80,8 @@ class Solution: return [bisect_right(t, x) for x in arr] ``` +#### Java + ```java class Solution { public int[] arrayRankTransform(int[] arr) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func arrayRankTransform(arr []int) (ans []int) { t := make([]int, len(arr)) @@ -135,6 +143,8 @@ func arrayRankTransform(arr []int) (ans []int) { } ``` +#### TypeScript + ```ts function arrayRankTransform(arr: number[]): number[] { const t = [...arr].sort((a, b) => a - b); diff --git a/solution/1300-1399/1332.Remove Palindromic Subsequences/README.md b/solution/1300-1399/1332.Remove Palindromic Subsequences/README.md index c82640ed174ba..8e3e80c1b5230 100644 --- a/solution/1300-1399/1332.Remove Palindromic Subsequences/README.md +++ b/solution/1300-1399/1332.Remove Palindromic Subsequences/README.md @@ -80,12 +80,16 @@ tags: +#### Python3 + ```python class Solution: def removePalindromeSub(self, s: str) -> int: return 1 if s[::-1] == s else 2 ``` +#### Java + ```java class Solution { public int removePalindromeSub(String s) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func removePalindromeSub(s string) int { for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 { @@ -124,6 +132,8 @@ func removePalindromeSub(s string) int { } ``` +#### TypeScript + ```ts function removePalindromeSub(s: string): number { for (let i = 0, j = s.length - 1; i < j; ++i, --j) { @@ -135,6 +145,8 @@ function removePalindromeSub(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn remove_palindrome_sub(s: String) -> i32 { diff --git a/solution/1300-1399/1332.Remove Palindromic Subsequences/README_EN.md b/solution/1300-1399/1332.Remove Palindromic Subsequences/README_EN.md index af884ee2ee61f..2af38665c596f 100644 --- a/solution/1300-1399/1332.Remove Palindromic Subsequences/README_EN.md +++ b/solution/1300-1399/1332.Remove Palindromic Subsequences/README_EN.md @@ -72,12 +72,16 @@ Remove palindromic subsequence "baab" then "b". +#### Python3 + ```python class Solution: def removePalindromeSub(self, s: str) -> int: return 1 if s[::-1] == s else 2 ``` +#### Java + ```java class Solution { public int removePalindromeSub(String s) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func removePalindromeSub(s string) int { for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 { @@ -116,6 +124,8 @@ func removePalindromeSub(s string) int { } ``` +#### TypeScript + ```ts function removePalindromeSub(s: string): number { for (let i = 0, j = s.length - 1; i < j; ++i, --j) { @@ -127,6 +137,8 @@ function removePalindromeSub(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn remove_palindrome_sub(s: String) -> i32 { diff --git a/solution/1300-1399/1333.Filter Restaurants by Vegan-Friendly, Price and Distance/README.md b/solution/1300-1399/1333.Filter Restaurants by Vegan-Friendly, Price and Distance/README.md index 5eeb134718752..4f486ce5c09a7 100644 --- a/solution/1300-1399/1333.Filter Restaurants by Vegan-Friendly, Price and Distance/README.md +++ b/solution/1300-1399/1333.Filter Restaurants by Vegan-Friendly, Price and Distance/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def filterRestaurants( @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List filterRestaurants( @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func filterRestaurants(restaurants [][]int, veganFriendly int, maxPrice int, maxDistance int) (ans []int) { sort.Slice(restaurants, func(i, j int) bool { @@ -153,6 +161,8 @@ func filterRestaurants(restaurants [][]int, veganFriendly int, maxPrice int, max } ``` +#### TypeScript + ```ts function filterRestaurants( restaurants: number[][], diff --git a/solution/1300-1399/1333.Filter Restaurants by Vegan-Friendly, Price and Distance/README_EN.md b/solution/1300-1399/1333.Filter Restaurants by Vegan-Friendly, Price and Distance/README_EN.md index c21687951ea15..c3e3f19f3458e 100644 --- a/solution/1300-1399/1333.Filter Restaurants by Vegan-Friendly, Price and Distance/README_EN.md +++ b/solution/1300-1399/1333.Filter Restaurants by Vegan-Friendly, Price and Distance/README_EN.md @@ -78,6 +78,8 @@ After filter restaurants with veganFriendly = 1, maxPrice = 50 and maxDistance = +#### Python3 + ```python class Solution: def filterRestaurants( @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List filterRestaurants( @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func filterRestaurants(restaurants [][]int, veganFriendly int, maxPrice int, maxDistance int) (ans []int) { sort.Slice(restaurants, func(i, j int) bool { @@ -150,6 +158,8 @@ func filterRestaurants(restaurants [][]int, veganFriendly int, maxPrice int, max } ``` +#### TypeScript + ```ts function filterRestaurants( restaurants: number[][], diff --git a/solution/1300-1399/1334.Find the City With the Smallest Number of Neighbors at a Threshold Distance/README.md b/solution/1300-1399/1334.Find the City With the Smallest Number of Neighbors at a Threshold Distance/README.md index ab3bbd9f8ab6a..7d594cb0cb7c8 100644 --- a/solution/1300-1399/1334.Find the City With the Smallest Number of Neighbors at a Threshold Distance/README.md +++ b/solution/1300-1399/1334.Find the City With the Smallest Number of Neighbors at a Threshold Distance/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def findTheCity( @@ -119,6 +121,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -180,6 +184,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -223,6 +229,8 @@ public: }; ``` +#### Go + ```go func findTheCity(n int, edges [][]int, distanceThreshold int) int { g := make([][]int, n) @@ -277,6 +285,8 @@ func findTheCity(n int, edges [][]int, distanceThreshold int) int { } ``` +#### TypeScript + ```ts function findTheCity(n: number, edges: number[][], distanceThreshold: number): number { const g: number[][] = Array.from({ length: n }, () => Array(n).fill(Infinity)); @@ -337,6 +347,8 @@ function findTheCity(n: number, edges: number[][], distanceThreshold: number): n +#### Python3 + ```python class Solution: def findTheCity( @@ -362,6 +374,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findTheCity(int n, int[][] edges, int distanceThreshold) { @@ -401,6 +415,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -432,6 +448,8 @@ public: }; ``` +#### Go + ```go func findTheCity(n int, edges [][]int, distanceThreshold int) int { g := make([][]int, n) @@ -474,6 +492,8 @@ func findTheCity(n int, edges [][]int, distanceThreshold int) int { } ``` +#### TypeScript + ```ts function findTheCity(n: number, edges: number[][], distanceThreshold: number): number { const g: number[][] = Array.from({ length: n }, () => Array(n).fill(Infinity)); diff --git a/solution/1300-1399/1334.Find the City With the Smallest Number of Neighbors at a Threshold Distance/README_EN.md b/solution/1300-1399/1334.Find the City With the Smallest Number of Neighbors at a Threshold Distance/README_EN.md index e34702178f3ad..20d960a5eaa5f 100644 --- a/solution/1300-1399/1334.Find the City With the Smallest Number of Neighbors at a Threshold Distance/README_EN.md +++ b/solution/1300-1399/1334.Find the City With the Smallest Number of Neighbors at a Threshold Distance/README_EN.md @@ -78,6 +78,8 @@ The city 0 has 1 neighboring city at a distanceThreshold = 2. +#### Python3 + ```python class Solution: def findTheCity( @@ -109,6 +111,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -170,6 +174,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -213,6 +219,8 @@ public: }; ``` +#### Go + ```go func findTheCity(n int, edges [][]int, distanceThreshold int) int { g := make([][]int, n) @@ -267,6 +275,8 @@ func findTheCity(n int, edges [][]int, distanceThreshold int) int { } ``` +#### TypeScript + ```ts function findTheCity(n: number, edges: number[][], distanceThreshold: number): number { const g: number[][] = Array.from({ length: n }, () => Array(n).fill(Infinity)); @@ -319,6 +329,8 @@ function findTheCity(n: number, edges: number[][], distanceThreshold: number): n +#### Python3 + ```python class Solution: def findTheCity( @@ -344,6 +356,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findTheCity(int n, int[][] edges, int distanceThreshold) { @@ -383,6 +397,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -414,6 +430,8 @@ public: }; ``` +#### Go + ```go func findTheCity(n int, edges [][]int, distanceThreshold int) int { g := make([][]int, n) @@ -456,6 +474,8 @@ func findTheCity(n int, edges [][]int, distanceThreshold int) int { } ``` +#### TypeScript + ```ts function findTheCity(n: number, edges: number[][], distanceThreshold: number): number { const g: number[][] = Array.from({ length: n }, () => Array(n).fill(Infinity)); diff --git a/solution/1300-1399/1335.Minimum Difficulty of a Job Schedule/README.md b/solution/1300-1399/1335.Minimum Difficulty of a Job Schedule/README.md index 2d3aa3efa6ac6..0468a80917854 100644 --- a/solution/1300-1399/1335.Minimum Difficulty of a Job Schedule/README.md +++ b/solution/1300-1399/1335.Minimum Difficulty of a Job Schedule/README.md @@ -98,6 +98,8 @@ $$ +#### Python3 + ```python class Solution: def minDifficulty(self, jobDifficulty: List[int], d: int) -> int: @@ -113,6 +115,8 @@ class Solution: return -1 if f[n][d] >= inf else f[n][d] ``` +#### Java + ```java class Solution { public int minDifficulty(int[] jobDifficulty, int d) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func minDifficulty(jobDifficulty []int, d int) int { n := len(jobDifficulty) @@ -187,6 +195,8 @@ func minDifficulty(jobDifficulty []int, d int) int { } ``` +#### TypeScript + ```ts function minDifficulty(jobDifficulty: number[], d: number): number { const n = jobDifficulty.length; diff --git a/solution/1300-1399/1335.Minimum Difficulty of a Job Schedule/README_EN.md b/solution/1300-1399/1335.Minimum Difficulty of a Job Schedule/README_EN.md index a4ecc7be033d1..2424972f5e799 100644 --- a/solution/1300-1399/1335.Minimum Difficulty of a Job Schedule/README_EN.md +++ b/solution/1300-1399/1335.Minimum Difficulty of a Job Schedule/README_EN.md @@ -85,6 +85,8 @@ The time complexity is $O(n^2 \times d)$, and the space complexity is $O(n \time +#### Python3 + ```python class Solution: def minDifficulty(self, jobDifficulty: List[int], d: int) -> int: @@ -100,6 +102,8 @@ class Solution: return -1 if f[n][d] >= inf else f[n][d] ``` +#### Java + ```java class Solution { public int minDifficulty(int[] jobDifficulty, int d) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func minDifficulty(jobDifficulty []int, d int) int { n := len(jobDifficulty) @@ -174,6 +182,8 @@ func minDifficulty(jobDifficulty []int, d int) int { } ``` +#### TypeScript + ```ts function minDifficulty(jobDifficulty: number[], d: number): number { const n = jobDifficulty.length; diff --git a/solution/1300-1399/1336.Number of Transactions per Visit/README.md b/solution/1300-1399/1336.Number of Transactions per Visit/README.md index bb1dbcef24dc4..7976bea2d1d56 100644 --- a/solution/1300-1399/1336.Number of Transactions per Visit/README.md +++ b/solution/1300-1399/1336.Number of Transactions per Visit/README.md @@ -128,6 +128,8 @@ Visits 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH RECURSIVE diff --git a/solution/1300-1399/1336.Number of Transactions per Visit/README_EN.md b/solution/1300-1399/1336.Number of Transactions per Visit/README_EN.md index d9594451d63cd..80882b4d94431 100644 --- a/solution/1300-1399/1336.Number of Transactions per Visit/README_EN.md +++ b/solution/1300-1399/1336.Number of Transactions per Visit/README_EN.md @@ -125,6 +125,8 @@ Transactions table: +#### MySQL + ```sql # Write your MySQL query statement below WITH RECURSIVE diff --git a/solution/1300-1399/1337.The K Weakest Rows in a Matrix/README.md b/solution/1300-1399/1337.The K Weakest Rows in a Matrix/README.md index 5ba855040766d..a365da4c9d14a 100644 --- a/solution/1300-1399/1337.The K Weakest Rows in a Matrix/README.md +++ b/solution/1300-1399/1337.The K Weakest Rows in a Matrix/README.md @@ -94,6 +94,8 @@ k = 2 +#### Python3 + ```python class Solution: def kWeakestRows(self, mat: List[List[int]], k: int) -> List[int]: @@ -104,6 +106,8 @@ class Solution: return idx[:k] ``` +#### Java + ```java class Solution { public int[] kWeakestRows(int[][] mat, int k) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go func kWeakestRows(mat [][]int, k int) []int { m, n := len(mat), len(mat[0]) @@ -191,6 +199,8 @@ func kWeakestRows(mat [][]int, k int) []int { } ``` +#### TypeScript + ```ts function kWeakestRows(mat: number[][], k: number): number[] { let n = mat.length; diff --git a/solution/1300-1399/1337.The K Weakest Rows in a Matrix/README_EN.md b/solution/1300-1399/1337.The K Weakest Rows in a Matrix/README_EN.md index 8749d65424085..a7b9aae5968fd 100644 --- a/solution/1300-1399/1337.The K Weakest Rows in a Matrix/README_EN.md +++ b/solution/1300-1399/1337.The K Weakest Rows in a Matrix/README_EN.md @@ -95,6 +95,8 @@ The rows ordered from weakest to strongest are [0,2,3,1]. +#### Python3 + ```python class Solution: def kWeakestRows(self, mat: List[List[int]], k: int) -> List[int]: @@ -105,6 +107,8 @@ class Solution: return idx[:k] ``` +#### Java + ```java class Solution { public int[] kWeakestRows(int[][] mat, int k) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func kWeakestRows(mat [][]int, k int) []int { m, n := len(mat), len(mat[0]) @@ -192,6 +200,8 @@ func kWeakestRows(mat [][]int, k int) []int { } ``` +#### TypeScript + ```ts function kWeakestRows(mat: number[][], k: number): number[] { let n = mat.length; diff --git a/solution/1300-1399/1338.Reduce Array Size to The Half/README.md b/solution/1300-1399/1338.Reduce Array Size to The Half/README.md index 2ae332a3abacf..b0b73b6b71b1a 100644 --- a/solution/1300-1399/1338.Reduce Array Size to The Half/README.md +++ b/solution/1300-1399/1338.Reduce Array Size to The Half/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def minSetSize(self, arr: List[int]) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minSetSize(int[] arr) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func minSetSize(arr []int) (ans int) { mx := slices.Max(arr) @@ -157,6 +165,8 @@ func minSetSize(arr []int) (ans int) { } ``` +#### TypeScript + ```ts function minSetSize(arr: number[]): number { const counter = new Map(); diff --git a/solution/1300-1399/1338.Reduce Array Size to The Half/README_EN.md b/solution/1300-1399/1338.Reduce Array Size to The Half/README_EN.md index e8b31517f1331..09b550baa01b3 100644 --- a/solution/1300-1399/1338.Reduce Array Size to The Half/README_EN.md +++ b/solution/1300-1399/1338.Reduce Array Size to The Half/README_EN.md @@ -64,6 +64,8 @@ Choosing set {2,7} is not possible as it will make the new array [3,3,3,3,5,5,5] +#### Python3 + ```python class Solution: def minSetSize(self, arr: List[int]) -> int: @@ -77,6 +79,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minSetSize(int[] arr) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func minSetSize(arr []int) (ans int) { mx := slices.Max(arr) @@ -151,6 +159,8 @@ func minSetSize(arr []int) (ans int) { } ``` +#### TypeScript + ```ts function minSetSize(arr: number[]): number { const counter = new Map(); diff --git a/solution/1300-1399/1339.Maximum Product of Splitted Binary Tree/README.md b/solution/1300-1399/1339.Maximum Product of Splitted Binary Tree/README.md index 7ae1393f7dae1..fe7e6975124a9 100644 --- a/solution/1300-1399/1339.Maximum Product of Splitted Binary Tree/README.md +++ b/solution/1300-1399/1339.Maximum Product of Splitted Binary Tree/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -113,6 +115,8 @@ class Solution: return ans % mod ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -205,6 +211,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -241,6 +249,8 @@ func maxProduct(root *TreeNode) (ans int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/1300-1399/1339.Maximum Product of Splitted Binary Tree/README_EN.md b/solution/1300-1399/1339.Maximum Product of Splitted Binary Tree/README_EN.md index 313530fbde233..ab9e0eb8e5195 100644 --- a/solution/1300-1399/1339.Maximum Product of Splitted Binary Tree/README_EN.md +++ b/solution/1300-1399/1339.Maximum Product of Splitted Binary Tree/README_EN.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -91,6 +93,8 @@ class Solution: return ans % mod ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -183,6 +189,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -219,6 +227,8 @@ func maxProduct(root *TreeNode) (ans int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/1300-1399/1340.Jump Game V/README.md b/solution/1300-1399/1340.Jump Game V/README.md index d7033ff6f77bf..0660b49704759 100644 --- a/solution/1300-1399/1340.Jump Game V/README.md +++ b/solution/1300-1399/1340.Jump Game V/README.md @@ -98,6 +98,8 @@ tags: +#### Python3 + ```python class Solution: def maxJumps(self, arr: List[int], d: int) -> int: @@ -118,6 +120,8 @@ class Solution: return max(dfs(i) for i in range(n)) ``` +#### Java + ```java class Solution { private int n; @@ -159,6 +163,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -194,6 +200,8 @@ public: }; ``` +#### Go + ```go func maxJumps(arr []int, d int) (ans int) { n := len(arr) @@ -246,6 +254,8 @@ func maxJumps(arr []int, d int) (ans int) { +#### Python3 + ```python class Solution: def maxJumps(self, arr: List[int], d: int) -> int: @@ -263,6 +273,8 @@ class Solution: return max(f) ``` +#### Java + ```java class Solution { public int maxJumps(int[] arr, int d) { @@ -295,6 +307,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -323,6 +337,8 @@ public: }; ``` +#### Go + ```go func maxJumps(arr []int, d int) int { n := len(arr) diff --git a/solution/1300-1399/1340.Jump Game V/README_EN.md b/solution/1300-1399/1340.Jump Game V/README_EN.md index bb41301617fa8..96a1c9e3a29e9 100644 --- a/solution/1300-1399/1340.Jump Game V/README_EN.md +++ b/solution/1300-1399/1340.Jump Game V/README_EN.md @@ -79,6 +79,8 @@ Similarly You cannot jump from index 3 to index 2 or index 1. +#### Python3 + ```python class Solution: def maxJumps(self, arr: List[int], d: int) -> int: @@ -99,6 +101,8 @@ class Solution: return max(dfs(i) for i in range(n)) ``` +#### Java + ```java class Solution { private int n; @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go func maxJumps(arr []int, d int) (ans int) { n := len(arr) @@ -217,6 +225,8 @@ func maxJumps(arr []int, d int) (ans int) { +#### Python3 + ```python class Solution: def maxJumps(self, arr: List[int], d: int) -> int: @@ -234,6 +244,8 @@ class Solution: return max(f) ``` +#### Java + ```java class Solution { public int maxJumps(int[] arr, int d) { @@ -266,6 +278,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -294,6 +308,8 @@ public: }; ``` +#### Go + ```go func maxJumps(arr []int, d int) int { n := len(arr) diff --git a/solution/1300-1399/1341.Movie Rating/README.md b/solution/1300-1399/1341.Movie Rating/README.md index be764d912da24..3336ff2b1ee09 100644 --- a/solution/1300-1399/1341.Movie Rating/README.md +++ b/solution/1300-1399/1341.Movie Rating/README.md @@ -132,6 +132,8 @@ Frozen 2 和 Joker 在 2 月的评分都是 3.5,但是 Frozen 2 的字典序 +#### MySQL + ```sql # Write your MySQL query statement below ( diff --git a/solution/1300-1399/1341.Movie Rating/README_EN.md b/solution/1300-1399/1341.Movie Rating/README_EN.md index de141a668b766..2f14e746d8558 100644 --- a/solution/1300-1399/1341.Movie Rating/README_EN.md +++ b/solution/1300-1399/1341.Movie Rating/README_EN.md @@ -130,6 +130,8 @@ Frozen 2 and Joker have a rating average of 3.5 in February but Frozen 2 is smal +#### MySQL + ```sql # Write your MySQL query statement below ( diff --git a/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/README.md b/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/README.md index fd1f1734123ba..5776c31f06168 100644 --- a/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/README.md +++ b/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfSteps(self, num: int) -> int: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func numberOfSteps(num int) int { ans := 0 @@ -127,6 +135,8 @@ func numberOfSteps(num int) int { } ``` +#### TypeScript + ```ts function numberOfSteps(num: number): number { let ans = 0; @@ -138,6 +148,8 @@ function numberOfSteps(num: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn number_of_steps(mut num: i32) -> i32 { @@ -165,6 +177,8 @@ impl Solution { +#### Python3 + ```python class Solution: def numberOfSteps(self, num: int) -> int: @@ -177,6 +191,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { @@ -189,6 +205,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -199,6 +217,8 @@ public: }; ``` +#### Go + ```go func numberOfSteps(num int) int { if num == 0 { @@ -211,6 +231,8 @@ func numberOfSteps(num int) int { } ``` +#### Rust + ```rust impl Solution { pub fn number_of_steps(mut num: i32) -> i32 { diff --git a/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/README_EN.md b/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/README_EN.md index 3a3fe223dc7a5..a0aedc539275c 100644 --- a/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/README_EN.md +++ b/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/README_EN.md @@ -74,6 +74,8 @@ Step 4) 1 is odd; subtract 1 and obtain 0. +#### Python3 + ```python class Solution: def numberOfSteps(self, num: int) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func numberOfSteps(num int) int { ans := 0 @@ -130,6 +138,8 @@ func numberOfSteps(num int) int { } ``` +#### TypeScript + ```ts function numberOfSteps(num: number): number { let ans = 0; @@ -141,6 +151,8 @@ function numberOfSteps(num: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn number_of_steps(mut num: i32) -> i32 { @@ -168,6 +180,8 @@ impl Solution { +#### Python3 + ```python class Solution: def numberOfSteps(self, num: int) -> int: @@ -180,6 +194,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { @@ -192,6 +208,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -202,6 +220,8 @@ public: }; ``` +#### Go + ```go func numberOfSteps(num int) int { if num == 0 { @@ -214,6 +234,8 @@ func numberOfSteps(num int) int { } ``` +#### Rust + ```rust impl Solution { pub fn number_of_steps(mut num: i32) -> i32 { diff --git a/solution/1300-1399/1343.Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold/README.md b/solution/1300-1399/1343.Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold/README.md index b2a4c37e4c428..b0bd6f83b4261 100644 --- a/solution/1300-1399/1343.Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold/README.md +++ b/solution/1300-1399/1343.Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numOfSubarrays(int[] arr, int k, int threshold) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func numOfSubarrays(arr []int, k int, threshold int) (ans int) { threshold *= k @@ -134,6 +142,8 @@ func numOfSubarrays(arr []int, k int, threshold int) (ans int) { } ``` +#### TypeScript + ```ts function numOfSubarrays(arr: number[], k: number, threshold: number): number { threshold *= k; diff --git a/solution/1300-1399/1343.Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold/README_EN.md b/solution/1300-1399/1343.Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold/README_EN.md index 26118d09d25c7..e6194fb250331 100644 --- a/solution/1300-1399/1343.Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold/README_EN.md +++ b/solution/1300-1399/1343.Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold/README_EN.md @@ -64,6 +64,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array `arr`. The s +#### Python3 + ```python class Solution: def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int: @@ -76,6 +78,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numOfSubarrays(int[] arr, int k, int threshold) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func numOfSubarrays(arr []int, k int, threshold int) (ans int) { threshold *= k @@ -130,6 +138,8 @@ func numOfSubarrays(arr []int, k int, threshold int) (ans int) { } ``` +#### TypeScript + ```ts function numOfSubarrays(arr: number[], k: number, threshold: number): number { threshold *= k; diff --git a/solution/1300-1399/1344.Angle Between Hands of a Clock/README.md b/solution/1300-1399/1344.Angle Between Hands of a Clock/README.md index 1370414b3ae86..2f58d2f2932c1 100644 --- a/solution/1300-1399/1344.Angle Between Hands of a Clock/README.md +++ b/solution/1300-1399/1344.Angle Between Hands of a Clock/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def angleClock(self, hour: int, minutes: int) -> float: @@ -91,6 +93,8 @@ class Solution: return min(diff, 360 - diff) ``` +#### Java + ```java class Solution { public double angleClock(int hour, int minutes) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func angleClock(hour int, minutes int) float64 { h := 30*float64(hour) + 0.5*float64(minutes) @@ -123,6 +131,8 @@ func angleClock(hour int, minutes int) float64 { } ``` +#### TypeScript + ```ts function angleClock(hour: number, minutes: number): number { const h = 30 * hour + 0.5 * minutes; diff --git a/solution/1300-1399/1344.Angle Between Hands of a Clock/README_EN.md b/solution/1300-1399/1344.Angle Between Hands of a Clock/README_EN.md index 2416cd1bf483c..a78ebf9cd4e7e 100644 --- a/solution/1300-1399/1344.Angle Between Hands of a Clock/README_EN.md +++ b/solution/1300-1399/1344.Angle Between Hands of a Clock/README_EN.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def angleClock(self, hour: int, minutes: int) -> float: @@ -71,6 +73,8 @@ class Solution: return min(diff, 360 - diff) ``` +#### Java + ```java class Solution { public double angleClock(int hour, int minutes) { @@ -82,6 +86,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -94,6 +100,8 @@ public: }; ``` +#### Go + ```go func angleClock(hour int, minutes int) float64 { h := 30*float64(hour) + 0.5*float64(minutes) @@ -103,6 +111,8 @@ func angleClock(hour int, minutes int) float64 { } ``` +#### TypeScript + ```ts function angleClock(hour: number, minutes: number): number { const h = 30 * hour + 0.5 * minutes; diff --git a/solution/1300-1399/1345.Jump Game IV/README.md b/solution/1300-1399/1345.Jump Game IV/README.md index 5c3781dda1fc0..177724adbd22a 100644 --- a/solution/1300-1399/1345.Jump Game IV/README.md +++ b/solution/1300-1399/1345.Jump Game IV/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def minJumps(self, arr: List[int]) -> int: @@ -107,6 +109,8 @@ class Solution: q.append((i - 1, step)) ``` +#### Java + ```java class Solution { public int minJumps(int[] arr) { @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -189,6 +195,8 @@ public: }; ``` +#### Go + ```go func minJumps(arr []int) int { idx := map[int][]int{} diff --git a/solution/1300-1399/1345.Jump Game IV/README_EN.md b/solution/1300-1399/1345.Jump Game IV/README_EN.md index ce92298aafebe..30c5fc19c6ae5 100644 --- a/solution/1300-1399/1345.Jump Game IV/README_EN.md +++ b/solution/1300-1399/1345.Jump Game IV/README_EN.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def minJumps(self, arr: List[int]) -> int: @@ -104,6 +106,8 @@ class Solution: q.append((i - 1, step)) ``` +#### Java + ```java class Solution { public int minJumps(int[] arr) { @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go func minJumps(arr []int) int { idx := map[int][]int{} diff --git a/solution/1300-1399/1346.Check If N and Its Double Exist/README.md b/solution/1300-1399/1346.Check If N and Its Double Exist/README.md index 763b577f01313..a79dcce3b81ac 100644 --- a/solution/1300-1399/1346.Check If N and Its Double Exist/README.md +++ b/solution/1300-1399/1346.Check If N and Its Double Exist/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def checkIfExist(self, arr: List[int]) -> bool: @@ -93,6 +95,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean checkIfExist(int[] arr) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func checkIfExist(arr []int) bool { s := map[int]bool{} @@ -137,6 +145,8 @@ func checkIfExist(arr []int) bool { } ``` +#### TypeScript + ```ts function checkIfExist(arr: number[]): boolean { const s: Set = new Set(); diff --git a/solution/1300-1399/1346.Check If N and Its Double Exist/README_EN.md b/solution/1300-1399/1346.Check If N and Its Double Exist/README_EN.md index 48aa2be0079a6..92f392f06b575 100644 --- a/solution/1300-1399/1346.Check If N and Its Double Exist/README_EN.md +++ b/solution/1300-1399/1346.Check If N and Its Double Exist/README_EN.md @@ -73,6 +73,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def checkIfExist(self, arr: List[int]) -> bool: @@ -84,6 +86,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean checkIfExist(int[] arr) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func checkIfExist(arr []int) bool { s := map[int]bool{} @@ -128,6 +136,8 @@ func checkIfExist(arr []int) bool { } ``` +#### TypeScript + ```ts function checkIfExist(arr: number[]): boolean { const s: Set = new Set(); diff --git a/solution/1300-1399/1347.Minimum Number of Steps to Make Two Strings Anagram/README.md b/solution/1300-1399/1347.Minimum Number of Steps to Make Two Strings Anagram/README.md index 249b669ecdc02..71f97d27326b4 100644 --- a/solution/1300-1399/1347.Minimum Number of Steps to Make Two Strings Anagram/README.md +++ b/solution/1300-1399/1347.Minimum Number of Steps to Make Two Strings Anagram/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def minSteps(self, s: str, t: str) -> int: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minSteps(String s, String t) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func minSteps(s string, t string) (ans int) { cnt := [26]int{} @@ -147,6 +155,8 @@ func minSteps(s string, t string) (ans int) { } ``` +#### JavaScript + ```js /** * @param {string} s diff --git a/solution/1300-1399/1347.Minimum Number of Steps to Make Two Strings Anagram/README_EN.md b/solution/1300-1399/1347.Minimum Number of Steps to Make Two Strings Anagram/README_EN.md index 5c160b984260e..d773d266cf07b 100644 --- a/solution/1300-1399/1347.Minimum Number of Steps to Make Two Strings Anagram/README_EN.md +++ b/solution/1300-1399/1347.Minimum Number of Steps to Make Two Strings Anagram/README_EN.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def minSteps(self, s: str, t: str) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minSteps(String s, String t) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func minSteps(s string, t string) (ans int) { cnt := [26]int{} @@ -132,6 +140,8 @@ func minSteps(s string, t string) (ans int) { } ``` +#### JavaScript + ```js /** * @param {string} s diff --git a/solution/1300-1399/1348.Tweet Counts Per Frequency/README.md b/solution/1300-1399/1348.Tweet Counts Per Frequency/README.md index ca6c27d209b59..1cac6d0a0dd19 100644 --- a/solution/1300-1399/1348.Tweet Counts Per Frequency/README.md +++ b/solution/1300-1399/1348.Tweet Counts Per Frequency/README.md @@ -101,6 +101,8 @@ tweetCounts.getTweetCountsPerFrequency("hour", "tweet3", 0, 210); // 返 +#### Python3 + ```python from sortedcontainers import SortedList @@ -134,6 +136,8 @@ class TweetCounts: # param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime) ``` +#### Java + ```java class TweetCounts { private Map> data = new HashMap<>(); @@ -177,6 +181,8 @@ class TweetCounts { */ ``` +#### C++ + ```cpp class TweetCounts { public: diff --git a/solution/1300-1399/1348.Tweet Counts Per Frequency/README_EN.md b/solution/1300-1399/1348.Tweet Counts Per Frequency/README_EN.md index 62f202e81d661..8117b556fb3ab 100644 --- a/solution/1300-1399/1348.Tweet Counts Per Frequency/README_EN.md +++ b/solution/1300-1399/1348.Tweet Counts Per Frequency/README_EN.md @@ -89,6 +89,8 @@ tweetCounts.getTweetCountsPerFrequency("hour", "tweet3", 0, +#### Python3 + ```python from sortedcontainers import SortedList @@ -122,6 +124,8 @@ class TweetCounts: # param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime) ``` +#### Java + ```java class TweetCounts { private Map> data = new HashMap<>(); @@ -165,6 +169,8 @@ class TweetCounts { */ ``` +#### C++ + ```cpp class TweetCounts { public: diff --git a/solution/1300-1399/1349.Maximum Students Taking Exam/README.md b/solution/1300-1399/1349.Maximum Students Taking Exam/README.md index b952978433a1c..56ee87c88a20a 100644 --- a/solution/1300-1399/1349.Maximum Students Taking Exam/README.md +++ b/solution/1300-1399/1349.Maximum Students Taking Exam/README.md @@ -105,6 +105,8 @@ tags: +#### Python3 + ```python class Solution: def maxStudents(self, seats: List[List[str]]) -> int: @@ -136,6 +138,8 @@ class Solution: return dfs(ss[0], 0) ``` +#### Java + ```java class Solution { private Integer[][] f; @@ -181,6 +185,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -222,6 +228,8 @@ public: }; ``` +#### Go + ```go func maxStudents(seats [][]byte) int { m, n := len(seats), len(seats[0]) @@ -265,6 +273,8 @@ func maxStudents(seats [][]byte) int { } ``` +#### TypeScript + ```ts function maxStudents(seats: string[][]): number { const m: number = seats.length; diff --git a/solution/1300-1399/1349.Maximum Students Taking Exam/README_EN.md b/solution/1300-1399/1349.Maximum Students Taking Exam/README_EN.md index 4f89e1a60f361..3fe9697c6e577 100644 --- a/solution/1300-1399/1349.Maximum Students Taking Exam/README_EN.md +++ b/solution/1300-1399/1349.Maximum Students Taking Exam/README_EN.md @@ -102,6 +102,8 @@ The time complexity is $O(4^n \times n \times m)$, and the space complexity is $ +#### Python3 + ```python class Solution: def maxStudents(self, seats: List[List[str]]) -> int: @@ -133,6 +135,8 @@ class Solution: return dfs(ss[0], 0) ``` +#### Java + ```java class Solution { private Integer[][] f; @@ -178,6 +182,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -219,6 +225,8 @@ public: }; ``` +#### Go + ```go func maxStudents(seats [][]byte) int { m, n := len(seats), len(seats[0]) @@ -262,6 +270,8 @@ func maxStudents(seats [][]byte) int { } ``` +#### TypeScript + ```ts function maxStudents(seats: string[][]): number { const m: number = seats.length; diff --git a/solution/1300-1399/1350.Students With Invalid Departments/README.md b/solution/1300-1399/1350.Students With Invalid Departments/README.md index 0a4f22941eaf2..3e33c3b4e9060 100644 --- a/solution/1300-1399/1350.Students With Invalid Departments/README.md +++ b/solution/1300-1399/1350.Students With Invalid Departments/README.md @@ -106,6 +106,8 @@ John, Daiana, Steve 和 Jasmine 所在的院系分别是 14, 33, 74 和 77, +#### MySQL + ```sql # Write your MySQL query statement below SELECT id, name @@ -125,6 +127,8 @@ WHERE department_id NOT IN (SELECT id FROM Departments); +#### MySQL + ```sql # Write your MySQL query statement below SELECT s.id, s.name diff --git a/solution/1300-1399/1350.Students With Invalid Departments/README_EN.md b/solution/1300-1399/1350.Students With Invalid Departments/README_EN.md index 2af88d01f993b..171a12151dfbd 100644 --- a/solution/1300-1399/1350.Students With Invalid Departments/README_EN.md +++ b/solution/1300-1399/1350.Students With Invalid Departments/README_EN.md @@ -106,6 +106,8 @@ We can directly use a subquery to find all students who are not in the `Departme +#### MySQL + ```sql # Write your MySQL query statement below SELECT id, name @@ -125,6 +127,8 @@ We can also use a left join to join the `Students` table with the `Departments` +#### MySQL + ```sql # Write your MySQL query statement below SELECT s.id, s.name diff --git a/solution/1300-1399/1351.Count Negative Numbers in a Sorted Matrix/README.md b/solution/1300-1399/1351.Count Negative Numbers in a Sorted Matrix/README.md index 1ba35980c48f0..741d696c541b1 100644 --- a/solution/1300-1399/1351.Count Negative Numbers in a Sorted Matrix/README.md +++ b/solution/1300-1399/1351.Count Negative Numbers in a Sorted Matrix/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def countNegatives(self, grid: List[List[int]]) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countNegatives(int[][] grid) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func countNegatives(grid [][]int) int { m, n := len(grid), len(grid[0]) @@ -139,6 +147,8 @@ func countNegatives(grid [][]int) int { } ``` +#### TypeScript + ```ts function countNegatives(grid: number[][]): number { const m = grid.length, @@ -156,6 +166,8 @@ function countNegatives(grid: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_negatives(grid: Vec>) -> i32 { @@ -179,6 +191,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} grid @@ -216,12 +230,16 @@ var countNegatives = function (grid) { +#### Python3 + ```python class Solution: def countNegatives(self, grid: List[List[int]]) -> int: return sum(bisect_left(row[::-1], 0) for row in grid) ``` +#### Java + ```java class Solution { public int countNegatives(int[][] grid) { @@ -244,6 +262,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -257,6 +277,8 @@ public: }; ``` +#### Go + ```go func countNegatives(grid [][]int) int { ans, n := 0, len(grid[0]) @@ -276,6 +298,8 @@ func countNegatives(grid [][]int) int { } ``` +#### TypeScript + ```ts function countNegatives(grid: number[][]): number { const n = grid[0].length; @@ -297,6 +321,8 @@ function countNegatives(grid: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_negatives(grid: Vec>) -> i32 { @@ -318,6 +344,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} grid diff --git a/solution/1300-1399/1351.Count Negative Numbers in a Sorted Matrix/README_EN.md b/solution/1300-1399/1351.Count Negative Numbers in a Sorted Matrix/README_EN.md index ae39bd5fb7a4e..a000edbd2971a 100644 --- a/solution/1300-1399/1351.Count Negative Numbers in a Sorted Matrix/README_EN.md +++ b/solution/1300-1399/1351.Count Negative Numbers in a Sorted Matrix/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(m + n)$, where $m$ and $n$ are the number of rows and +#### Python3 + ```python class Solution: def countNegatives(self, grid: List[List[int]]) -> int: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countNegatives(int[][] grid) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func countNegatives(grid [][]int) int { m, n := len(grid), len(grid[0]) @@ -136,6 +144,8 @@ func countNegatives(grid [][]int) int { } ``` +#### TypeScript + ```ts function countNegatives(grid: number[][]): number { const m = grid.length, @@ -153,6 +163,8 @@ function countNegatives(grid: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_negatives(grid: Vec>) -> i32 { @@ -176,6 +188,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} grid @@ -213,12 +227,16 @@ The time complexity is $O(m \times \log n)$, where $m$ and $n$ are the number of +#### Python3 + ```python class Solution: def countNegatives(self, grid: List[List[int]]) -> int: return sum(bisect_left(row[::-1], 0) for row in grid) ``` +#### Java + ```java class Solution { public int countNegatives(int[][] grid) { @@ -241,6 +259,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -254,6 +274,8 @@ public: }; ``` +#### Go + ```go func countNegatives(grid [][]int) int { ans, n := 0, len(grid[0]) @@ -273,6 +295,8 @@ func countNegatives(grid [][]int) int { } ``` +#### TypeScript + ```ts function countNegatives(grid: number[][]): number { const n = grid[0].length; @@ -294,6 +318,8 @@ function countNegatives(grid: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_negatives(grid: Vec>) -> i32 { @@ -315,6 +341,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} grid diff --git a/solution/1300-1399/1352.Product of the Last K Numbers/README.md b/solution/1300-1399/1352.Product of the Last K Numbers/README.md index e057aae88e045..4b15e176fc1f5 100644 --- a/solution/1300-1399/1352.Product of the Last K Numbers/README.md +++ b/solution/1300-1399/1352.Product of the Last K Numbers/README.md @@ -92,6 +92,8 @@ productOfNumbers.getProduct(2); // 返回 32 。最后 2 个数字的乘积是 4 +#### Python3 + ```python class ProductOfNumbers: def __init__(self): @@ -113,6 +115,8 @@ class ProductOfNumbers: # param_2 = obj.getProduct(k) ``` +#### Java + ```java class ProductOfNumbers { private List s = new ArrayList<>(); @@ -144,6 +148,8 @@ class ProductOfNumbers { */ ``` +#### C++ + ```cpp class ProductOfNumbers { public: @@ -177,6 +183,8 @@ private: */ ``` +#### Go + ```go type ProductOfNumbers struct { s []int diff --git a/solution/1300-1399/1352.Product of the Last K Numbers/README_EN.md b/solution/1300-1399/1352.Product of the Last K Numbers/README_EN.md index 7eee4337f150d..3c353a001431e 100644 --- a/solution/1300-1399/1352.Product of the Last K Numbers/README_EN.md +++ b/solution/1300-1399/1352.Product of the Last K Numbers/README_EN.md @@ -87,6 +87,8 @@ The time complexity is $O(1)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class ProductOfNumbers: def __init__(self): @@ -108,6 +110,8 @@ class ProductOfNumbers: # param_2 = obj.getProduct(k) ``` +#### Java + ```java class ProductOfNumbers { private List s = new ArrayList<>(); @@ -139,6 +143,8 @@ class ProductOfNumbers { */ ``` +#### C++ + ```cpp class ProductOfNumbers { public: @@ -172,6 +178,8 @@ private: */ ``` +#### Go + ```go type ProductOfNumbers struct { s []int diff --git a/solution/1300-1399/1353.Maximum Number of Events That Can Be Attended/README.md b/solution/1300-1399/1353.Maximum Number of Events That Can Be Attended/README.md index 2e7f4081ba8ef..323ad41373185 100644 --- a/solution/1300-1399/1353.Maximum Number of Events That Can Be Attended/README.md +++ b/solution/1300-1399/1353.Maximum Number of Events That Can Be Attended/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def maxEvents(self, events: List[List[int]]) -> int: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxEvents(int[][] events) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func maxEvents(events [][]int) int { d := map[int][]int{} diff --git a/solution/1300-1399/1353.Maximum Number of Events That Can Be Attended/README_EN.md b/solution/1300-1399/1353.Maximum Number of Events That Can Be Attended/README_EN.md index d933bd4f1c718..42234ff46dddb 100644 --- a/solution/1300-1399/1353.Maximum Number of Events That Can Be Attended/README_EN.md +++ b/solution/1300-1399/1353.Maximum Number of Events That Can Be Attended/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(m \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def maxEvents(self, events: List[List[int]]) -> int: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxEvents(int[][] events) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func maxEvents(events [][]int) int { d := map[int][]int{} diff --git a/solution/1300-1399/1354.Construct Target Array With Multiple Sums/README.md b/solution/1300-1399/1354.Construct Target Array With Multiple Sums/README.md index c71cf1d561347..67cd7338f7ab9 100644 --- a/solution/1300-1399/1354.Construct Target Array With Multiple Sums/README.md +++ b/solution/1300-1399/1354.Construct Target Array With Multiple Sums/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def isPossible(self, target: List[int]) -> bool: @@ -98,6 +100,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isPossible(int[] target) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func isPossible(target []int) bool { pq := &hp{target} @@ -186,6 +194,8 @@ func (hp) Pop() (_ any) { return } func (hp) Push(any) {} ``` +#### TypeScript + ```ts function isPossible(target: number[]): boolean { const pq = new MaxPriorityQueue(); diff --git a/solution/1300-1399/1354.Construct Target Array With Multiple Sums/README_EN.md b/solution/1300-1399/1354.Construct Target Array With Multiple Sums/README_EN.md index b453077d22460..46c3cefe4351d 100644 --- a/solution/1300-1399/1354.Construct Target Array With Multiple Sums/README_EN.md +++ b/solution/1300-1399/1354.Construct Target Array With Multiple Sums/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n \log n)$, and the space complexity is $O(n)$. Where +#### Python3 + ```python class Solution: def isPossible(self, target: List[int]) -> bool: @@ -99,6 +101,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isPossible(int[] target) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func isPossible(target []int) bool { pq := &hp{target} @@ -187,6 +195,8 @@ func (hp) Pop() (_ any) { return } func (hp) Push(any) {} ``` +#### TypeScript + ```ts function isPossible(target: number[]): boolean { const pq = new MaxPriorityQueue(); diff --git a/solution/1300-1399/1355.Activity Participants/README.md b/solution/1300-1399/1355.Activity Participants/README.md index a18ef33106238..417cb20d4ed11 100644 --- a/solution/1300-1399/1355.Activity Participants/README.md +++ b/solution/1300-1399/1355.Activity Participants/README.md @@ -102,6 +102,8 @@ Singing 活动有两个人参加 (Victor J. and Jade W.) +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1300-1399/1355.Activity Participants/README_EN.md b/solution/1300-1399/1355.Activity Participants/README_EN.md index 05d5eb3da3328..dd5352b153b0a 100644 --- a/solution/1300-1399/1355.Activity Participants/README_EN.md +++ b/solution/1300-1399/1355.Activity Participants/README_EN.md @@ -102,6 +102,8 @@ Singing is performed by 2 friends (Victor J. and Jade W.) +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1300-1399/1356.Sort Integers by The Number of 1 Bits/README.md b/solution/1300-1399/1356.Sort Integers by The Number of 1 Bits/README.md index 6a1c6cb77bdb3..8beed503f6ab1 100644 --- a/solution/1300-1399/1356.Sort Integers by The Number of 1 Bits/README.md +++ b/solution/1300-1399/1356.Sort Integers by The Number of 1 Bits/README.md @@ -88,12 +88,16 @@ tags: +#### Python3 + ```python class Solution: def sortByBits(self, arr: List[int]) -> List[int]: return sorted(arr, key=lambda x: (x.bit_count(), x)) ``` +#### Java + ```java class Solution { public int[] sortByBits(int[] arr) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func sortByBits(arr []int) []int { for i, v := range arr { @@ -139,6 +147,8 @@ func sortByBits(arr []int) []int { } ``` +#### TypeScript + ```ts function sortByBits(arr: number[]): number[] { const countOnes = (n: number) => { @@ -153,6 +163,8 @@ function sortByBits(arr: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn sort_by_bits(mut arr: Vec) -> Vec { @@ -168,6 +180,8 @@ impl Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). @@ -208,6 +222,8 @@ int* sortByBits(int* arr, int arrSize, int* returnSize) { +#### Java + ```java class Solution { public int[] sortByBits(int[] arr) { @@ -228,6 +244,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -241,6 +259,8 @@ public: }; ``` +#### Go + ```go func sortByBits(arr []int) []int { sort.Slice(arr, func(i, j int) bool { diff --git a/solution/1300-1399/1356.Sort Integers by The Number of 1 Bits/README_EN.md b/solution/1300-1399/1356.Sort Integers by The Number of 1 Bits/README_EN.md index 0ac3b4d4b8100..d051866d65bc5 100644 --- a/solution/1300-1399/1356.Sort Integers by The Number of 1 Bits/README_EN.md +++ b/solution/1300-1399/1356.Sort Integers by The Number of 1 Bits/README_EN.md @@ -68,12 +68,16 @@ The time complexity is $O(n \log n)$, and the space complexity is $O(n)$. Where +#### Python3 + ```python class Solution: def sortByBits(self, arr: List[int]) -> List[int]: return sorted(arr, key=lambda x: (x.bit_count(), x)) ``` +#### Java + ```java class Solution { public int[] sortByBits(int[] arr) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func sortByBits(arr []int) []int { for i, v := range arr { @@ -119,6 +127,8 @@ func sortByBits(arr []int) []int { } ``` +#### TypeScript + ```ts function sortByBits(arr: number[]): number[] { const countOnes = (n: number) => { @@ -133,6 +143,8 @@ function sortByBits(arr: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn sort_by_bits(mut arr: Vec) -> Vec { @@ -148,6 +160,8 @@ impl Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). @@ -188,6 +202,8 @@ int* sortByBits(int* arr, int arrSize, int* returnSize) { +#### Java + ```java class Solution { public int[] sortByBits(int[] arr) { @@ -208,6 +224,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -221,6 +239,8 @@ public: }; ``` +#### Go + ```go func sortByBits(arr []int) []int { sort.Slice(arr, func(i, j int) bool { diff --git a/solution/1300-1399/1357.Apply Discount Every n Orders/README.md b/solution/1300-1399/1357.Apply Discount Every n Orders/README.md index 843d41d20e3c3..a3440e053f2af 100644 --- a/solution/1300-1399/1357.Apply Discount Every n Orders/README.md +++ b/solution/1300-1399/1357.Apply Discount Every n Orders/README.md @@ -89,6 +89,8 @@ cashier.getBill([2,3,5],[5,3,2]); // 返回 2500.0 +#### Python3 + ```python class Cashier: def __init__(self, n: int, discount: int, products: List[int], prices: List[int]): @@ -112,6 +114,8 @@ class Cashier: # param_1 = obj.getBill(product,amount) ``` +#### Java + ```java class Cashier { private int i; @@ -146,6 +150,8 @@ class Cashier { */ ``` +#### C++ + ```cpp class Cashier { public: @@ -181,6 +187,8 @@ private: */ ``` +#### Go + ```go type Cashier struct { i int diff --git a/solution/1300-1399/1357.Apply Discount Every n Orders/README_EN.md b/solution/1300-1399/1357.Apply Discount Every n Orders/README_EN.md index 22a4a86b94421..59d9f98a35956 100644 --- a/solution/1300-1399/1357.Apply Discount Every n Orders/README_EN.md +++ b/solution/1300-1399/1357.Apply Discount Every n Orders/README_EN.md @@ -93,6 +93,8 @@ The time complexity of initialization is $O(n)$, where $n$ is the number of prod +#### Python3 + ```python class Cashier: def __init__(self, n: int, discount: int, products: List[int], prices: List[int]): @@ -116,6 +118,8 @@ class Cashier: # param_1 = obj.getBill(product,amount) ``` +#### Java + ```java class Cashier { private int i; @@ -150,6 +154,8 @@ class Cashier { */ ``` +#### C++ + ```cpp class Cashier { public: @@ -185,6 +191,8 @@ private: */ ``` +#### Go + ```go type Cashier struct { i int diff --git a/solution/1300-1399/1358.Number of Substrings Containing All Three Characters/README.md b/solution/1300-1399/1358.Number of Substrings Containing All Three Characters/README.md index 095e42d94b7f3..c3273540ae5ed 100644 --- a/solution/1300-1399/1358.Number of Substrings Containing All Three Characters/README.md +++ b/solution/1300-1399/1358.Number of Substrings Containing All Three Characters/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfSubstrings(self, s: str) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numberOfSubstrings(String s) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func numberOfSubstrings(s string) (ans int) { d := [3]int{-1, -1, -1} diff --git a/solution/1300-1399/1358.Number of Substrings Containing All Three Characters/README_EN.md b/solution/1300-1399/1358.Number of Substrings Containing All Three Characters/README_EN.md index dade35c935e96..632a427b53219 100644 --- a/solution/1300-1399/1358.Number of Substrings Containing All Three Characters/README_EN.md +++ b/solution/1300-1399/1358.Number of Substrings Containing All Three Characters/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string $s$. The sp +#### Python3 + ```python class Solution: def numberOfSubstrings(self, s: str) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numberOfSubstrings(String s) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func numberOfSubstrings(s string) (ans int) { d := [3]int{-1, -1, -1} diff --git a/solution/1300-1399/1359.Count All Valid Pickup and Delivery Options/README.md b/solution/1300-1399/1359.Count All Valid Pickup and Delivery Options/README.md index d79df5d1a8730..2e66ce2d0b240 100644 --- a/solution/1300-1399/1359.Count All Valid Pickup and Delivery Options/README.md +++ b/solution/1300-1399/1359.Count All Valid Pickup and Delivery Options/README.md @@ -85,6 +85,8 @@ $$ +#### Python3 + ```python class Solution: def countOrders(self, n: int) -> int: @@ -95,6 +97,8 @@ class Solution: return f ``` +#### Java + ```java class Solution { public int countOrders(int n) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func countOrders(n int) int { const mod = 1e9 + 7 @@ -133,6 +141,8 @@ func countOrders(n int) int { } ``` +#### Rust + ```rust const MOD: i64 = (1e9 as i64) + 7; diff --git a/solution/1300-1399/1359.Count All Valid Pickup and Delivery Options/README_EN.md b/solution/1300-1399/1359.Count All Valid Pickup and Delivery Options/README_EN.md index fcdf3a2c7df08..7d3a5c1df242a 100644 --- a/solution/1300-1399/1359.Count All Valid Pickup and Delivery Options/README_EN.md +++ b/solution/1300-1399/1359.Count All Valid Pickup and Delivery Options/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(n)$, where $n$ is the number of orders. The space comp +#### Python3 + ```python class Solution: def countOrders(self, n: int) -> int: @@ -93,6 +95,8 @@ class Solution: return f ``` +#### Java + ```java class Solution { public int countOrders(int n) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func countOrders(n int) int { const mod = 1e9 + 7 @@ -131,6 +139,8 @@ func countOrders(n int) int { } ``` +#### Rust + ```rust const MOD: i64 = (1e9 as i64) + 7; diff --git a/solution/1300-1399/1360.Number of Days Between Two Dates/README.md b/solution/1300-1399/1360.Number of Days Between Two Dates/README.md index ca57d8cf87322..2d5d543d7309e 100644 --- a/solution/1300-1399/1360.Number of Days Between Two Dates/README.md +++ b/solution/1300-1399/1360.Number of Days Between Two Dates/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def daysBetweenDates(self, date1: str, date2: str) -> int: @@ -101,6 +103,8 @@ class Solution: return abs(calcDays(date1) - calcDays(date2)) ``` +#### Java + ```java class Solution { public int daysBetweenDates(String date1, String date2) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func daysBetweenDates(date1 string, date2 string) int { return abs(calcDays(date1) - calcDays(date2)) @@ -211,6 +219,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function daysBetweenDates(date1: string, date2: string): number { return Math.abs(calcDays(date1) - calcDays(date2)); diff --git a/solution/1300-1399/1360.Number of Days Between Two Dates/README_EN.md b/solution/1300-1399/1360.Number of Days Between Two Dates/README_EN.md index d0b1e31dedbf3..40b0ebfc73c02 100644 --- a/solution/1300-1399/1360.Number of Days Between Two Dates/README_EN.md +++ b/solution/1300-1399/1360.Number of Days Between Two Dates/README_EN.md @@ -58,6 +58,8 @@ The time complexity is $O(y + m)$, where $y$ represents the number of years from +#### Python3 + ```python class Solution: def daysBetweenDates(self, date1: str, date2: str) -> int: @@ -94,6 +96,8 @@ class Solution: return abs(calcDays(date1) - calcDays(date2)) ``` +#### Java + ```java class Solution { public int daysBetweenDates(String date1, String date2) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func daysBetweenDates(date1 string, date2 string) int { return abs(calcDays(date1) - calcDays(date2)) @@ -204,6 +212,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function daysBetweenDates(date1: string, date2: string): number { return Math.abs(calcDays(date1) - calcDays(date2)); diff --git a/solution/1300-1399/1361.Validate Binary Tree Nodes/README.md b/solution/1300-1399/1361.Validate Binary Tree Nodes/README.md index 6c4c3f444aa95..2bbb84454a4ff 100644 --- a/solution/1300-1399/1361.Validate Binary Tree Nodes/README.md +++ b/solution/1300-1399/1361.Validate Binary Tree Nodes/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def validateBinaryTreeNodes( @@ -113,6 +115,8 @@ class Solution: return n == 1 ``` +#### Java + ```java class Solution { private int[] p; @@ -147,6 +151,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go func validateBinaryTreeNodes(n int, leftChild []int, rightChild []int) bool { p := make([]int, n) diff --git a/solution/1300-1399/1361.Validate Binary Tree Nodes/README_EN.md b/solution/1300-1399/1361.Validate Binary Tree Nodes/README_EN.md index a52e7fc3e2de7..30ff7094358aa 100644 --- a/solution/1300-1399/1361.Validate Binary Tree Nodes/README_EN.md +++ b/solution/1300-1399/1361.Validate Binary Tree Nodes/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(n \times \alpha(n))$, and the space complexity is $O(n +#### Python3 + ```python class Solution: def validateBinaryTreeNodes( @@ -103,6 +105,8 @@ class Solution: return n == 1 ``` +#### Java + ```java class Solution { private int[] p; @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func validateBinaryTreeNodes(n int, leftChild []int, rightChild []int) bool { p := make([]int, n) diff --git a/solution/1300-1399/1362.Closest Divisors/README.md b/solution/1300-1399/1362.Closest Divisors/README.md index a5da863cc1352..de16e10039146 100644 --- a/solution/1300-1399/1362.Closest Divisors/README.md +++ b/solution/1300-1399/1362.Closest Divisors/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def closestDivisors(self, num: int) -> List[int]: @@ -85,6 +87,8 @@ class Solution: return a if abs(a[0] - a[1]) < abs(b[0] - b[1]) else b ``` +#### Java + ```java class Solution { public int[] closestDivisors(int num) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func closestDivisors(num int) []int { f := func(x int) []int { diff --git a/solution/1300-1399/1362.Closest Divisors/README_EN.md b/solution/1300-1399/1362.Closest Divisors/README_EN.md index 88d21597d7fa6..2c05a8ca21798 100644 --- a/solution/1300-1399/1362.Closest Divisors/README_EN.md +++ b/solution/1300-1399/1362.Closest Divisors/README_EN.md @@ -68,6 +68,8 @@ The time complexity is $O(\sqrt{num})$, and the space complexity is $O(1)$. Wher +#### Python3 + ```python class Solution: def closestDivisors(self, num: int) -> List[int]: @@ -81,6 +83,8 @@ class Solution: return a if abs(a[0] - a[1]) < abs(b[0] - b[1]) else b ``` +#### Java + ```java class Solution { public int[] closestDivisors(int num) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func closestDivisors(num int) []int { f := func(x int) []int { diff --git a/solution/1300-1399/1363.Largest Multiple of Three/README.md b/solution/1300-1399/1363.Largest Multiple of Three/README.md index 7d418c1beb2f2..c21f245388241 100644 --- a/solution/1300-1399/1363.Largest Multiple of Three/README.md +++ b/solution/1300-1399/1363.Largest Multiple of Three/README.md @@ -87,6 +87,8 @@ $$ +#### Python3 + ```python class Solution: def largestMultipleOfThree(self, digits: List[int]) -> str: @@ -112,6 +114,8 @@ class Solution: return "".join(map(str, arr[i:])) ``` +#### Java + ```java class Solution { public String largestMultipleOfThree(int[] digits) { @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -182,6 +188,8 @@ public: }; ``` +#### Go + ```go func largestMultipleOfThree(digits []int) string { sort.Ints(digits) @@ -219,6 +227,8 @@ func largestMultipleOfThree(digits []int) string { } ``` +#### TypeScript + ```ts function largestMultipleOfThree(digits: number[]): string { digits.sort((a, b) => a - b); diff --git a/solution/1300-1399/1363.Largest Multiple of Three/README_EN.md b/solution/1300-1399/1363.Largest Multiple of Three/README_EN.md index 7caa76d13d4aa..00e6aeabcddbf 100644 --- a/solution/1300-1399/1363.Largest Multiple of Three/README_EN.md +++ b/solution/1300-1399/1363.Largest Multiple of Three/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def largestMultipleOfThree(self, digits: List[int]) -> str: @@ -103,6 +105,8 @@ class Solution: return "".join(map(str, arr[i:])) ``` +#### Java + ```java class Solution { public String largestMultipleOfThree(int[] digits) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go func largestMultipleOfThree(digits []int) string { sort.Ints(digits) @@ -210,6 +218,8 @@ func largestMultipleOfThree(digits []int) string { } ``` +#### TypeScript + ```ts function largestMultipleOfThree(digits: number[]): string { digits.sort((a, b) => a - b); diff --git a/solution/1300-1399/1364.Number of Trusted Contacts of a Customer/README.md b/solution/1300-1399/1364.Number of Trusted Contacts of a Customer/README.md index 6ded833a49b64..1c3d99f661acf 100644 --- a/solution/1300-1399/1364.Number of Trusted Contacts of a Customer/README.md +++ b/solution/1300-1399/1364.Number of Trusted Contacts of a Customer/README.md @@ -143,6 +143,8 @@ John 没有任何联系人。 +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1300-1399/1364.Number of Trusted Contacts of a Customer/README_EN.md b/solution/1300-1399/1364.Number of Trusted Contacts of a Customer/README_EN.md index b6a4b042b82b4..a770a64c74dc9 100644 --- a/solution/1300-1399/1364.Number of Trusted Contacts of a Customer/README_EN.md +++ b/solution/1300-1399/1364.Number of Trusted Contacts of a Customer/README_EN.md @@ -142,6 +142,8 @@ John doesn't have any contacts. +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1300-1399/1365.How Many Numbers Are Smaller Than the Current Number/README.md b/solution/1300-1399/1365.How Many Numbers Are Smaller Than the Current Number/README.md index d27bba61f07a1..cc821d0084660 100644 --- a/solution/1300-1399/1365.How Many Numbers Are Smaller Than the Current Number/README.md +++ b/solution/1300-1399/1365.How Many Numbers Are Smaller Than the Current Number/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def smallerNumbersThanCurrent(self, nums: List[int]) -> List[int]: @@ -85,6 +87,8 @@ class Solution: return [bisect_left(arr, x) for x in nums] ``` +#### Java + ```java class Solution { public int[] smallerNumbersThanCurrent(int[] nums) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func smallerNumbersThanCurrent(nums []int) (ans []int) { arr := make([]int, len(nums)) @@ -137,6 +145,8 @@ func smallerNumbersThanCurrent(nums []int) (ans []int) { } ``` +#### TypeScript + ```ts function smallerNumbersThanCurrent(nums: number[]): number[] { const search = (nums: number[], x: number) => { @@ -174,6 +184,8 @@ function smallerNumbersThanCurrent(nums: number[]): number[] { +#### Python3 + ```python class Solution: def smallerNumbersThanCurrent(self, nums: List[int]) -> List[int]: @@ -184,6 +196,8 @@ class Solution: return [s[x] for x in nums] ``` +#### Java + ```java class Solution { public int[] smallerNumbersThanCurrent(int[] nums) { @@ -204,6 +218,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -224,6 +240,8 @@ public: }; ``` +#### Go + ```go func smallerNumbersThanCurrent(nums []int) (ans []int) { cnt := [102]int{} @@ -240,6 +258,8 @@ func smallerNumbersThanCurrent(nums []int) (ans []int) { } ``` +#### TypeScript + ```ts function smallerNumbersThanCurrent(nums: number[]): number[] { const cnt: number[] = new Array(102).fill(0); diff --git a/solution/1300-1399/1365.How Many Numbers Are Smaller Than the Current Number/README_EN.md b/solution/1300-1399/1365.How Many Numbers Are Smaller Than the Current Number/README_EN.md index 7829eff7185d1..4ecc1d90754da 100644 --- a/solution/1300-1399/1365.How Many Numbers Are Smaller Than the Current Number/README_EN.md +++ b/solution/1300-1399/1365.How Many Numbers Are Smaller Than the Current Number/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def smallerNumbersThanCurrent(self, nums: List[int]) -> List[int]: @@ -84,6 +86,8 @@ class Solution: return [bisect_left(arr, x) for x in nums] ``` +#### Java + ```java class Solution { public int[] smallerNumbersThanCurrent(int[] nums) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func smallerNumbersThanCurrent(nums []int) (ans []int) { arr := make([]int, len(nums)) @@ -136,6 +144,8 @@ func smallerNumbersThanCurrent(nums []int) (ans []int) { } ``` +#### TypeScript + ```ts function smallerNumbersThanCurrent(nums: number[]): number[] { const search = (nums: number[], x: number) => { @@ -173,6 +183,8 @@ The time complexity is $O(n + M)$, and the space complexity is $O(M)$. Where $n$ +#### Python3 + ```python class Solution: def smallerNumbersThanCurrent(self, nums: List[int]) -> List[int]: @@ -183,6 +195,8 @@ class Solution: return [s[x] for x in nums] ``` +#### Java + ```java class Solution { public int[] smallerNumbersThanCurrent(int[] nums) { @@ -203,6 +217,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -223,6 +239,8 @@ public: }; ``` +#### Go + ```go func smallerNumbersThanCurrent(nums []int) (ans []int) { cnt := [102]int{} @@ -239,6 +257,8 @@ func smallerNumbersThanCurrent(nums []int) (ans []int) { } ``` +#### TypeScript + ```ts function smallerNumbersThanCurrent(nums: number[]): number[] { const cnt: number[] = new Array(102).fill(0); diff --git a/solution/1300-1399/1366.Rank Teams by Votes/README.md b/solution/1300-1399/1366.Rank Teams by Votes/README.md index c1690d04da1d0..12e4ff01f93f3 100644 --- a/solution/1300-1399/1366.Rank Teams by Votes/README.md +++ b/solution/1300-1399/1366.Rank Teams by Votes/README.md @@ -106,6 +106,8 @@ C 队获得两票「排位第一」,两票「排位第二」,两票「排位 +#### Python3 + ```python class Solution: def rankTeams(self, votes: List[str]) -> str: @@ -117,6 +119,8 @@ class Solution: return "".join(sorted(votes[0], key=lambda x: (cnt[x], -ord(x)), reverse=True)) ``` +#### Java + ```java class Solution { public String rankTeams(String[] votes) { @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go func rankTeams(votes []string) string { cnt := [26][26]int{} diff --git a/solution/1300-1399/1366.Rank Teams by Votes/README_EN.md b/solution/1300-1399/1366.Rank Teams by Votes/README_EN.md index b02cdfdc20ec9..3491240aa8fea 100644 --- a/solution/1300-1399/1366.Rank Teams by Votes/README_EN.md +++ b/solution/1300-1399/1366.Rank Teams by Votes/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(n^2 \times \log n)$, and the space complexity is $O(n^ +#### Python3 + ```python class Solution: def rankTeams(self, votes: List[str]) -> str: @@ -97,6 +99,8 @@ class Solution: return "".join(sorted(votes[0], key=lambda x: (cnt[x], -ord(x)), reverse=True)) ``` +#### Java + ```java class Solution { public String rankTeams(String[] votes) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func rankTeams(votes []string) string { cnt := [26][26]int{} diff --git a/solution/1300-1399/1367.Linked List in Binary Tree/README.md b/solution/1300-1399/1367.Linked List in Binary Tree/README.md index 15dc5af598716..cae09ba807b9a 100644 --- a/solution/1300-1399/1367.Linked List in Binary Tree/README.md +++ b/solution/1300-1399/1367.Linked List in Binary Tree/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -115,6 +117,8 @@ class Solution: ) ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -161,6 +165,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -204,6 +210,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -238,6 +246,8 @@ func dfs(head *ListNode, root *TreeNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -283,6 +293,8 @@ function isSubPath(head: ListNode | null, root: TreeNode | null): boolean { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] diff --git a/solution/1300-1399/1367.Linked List in Binary Tree/README_EN.md b/solution/1300-1399/1367.Linked List in Binary Tree/README_EN.md index 4ac6ce891203a..031736bd62d77 100644 --- a/solution/1300-1399/1367.Linked List in Binary Tree/README_EN.md +++ b/solution/1300-1399/1367.Linked List in Binary Tree/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$. Where $n$ i +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -116,6 +118,8 @@ class Solution: ) ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -162,6 +166,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -205,6 +211,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -239,6 +247,8 @@ func dfs(head *ListNode, root *TreeNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -284,6 +294,8 @@ function isSubPath(head: ListNode | null, root: TreeNode | null): boolean { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] diff --git a/solution/1300-1399/1368.Minimum Cost to Make at Least One Valid Path in a Grid/README.md b/solution/1300-1399/1368.Minimum Cost to Make at Least One Valid Path in a Grid/README.md index c9cbd1215ce57..4ef1a6b7b9c4c 100644 --- a/solution/1300-1399/1368.Minimum Cost to Make at Least One Valid Path in a Grid/README.md +++ b/solution/1300-1399/1368.Minimum Cost to Make at Least One Valid Path in a Grid/README.md @@ -108,6 +108,8 @@ tags: +#### Python3 + ```python class Solution: def minCost(self, grid: List[List[int]]) -> int: @@ -132,6 +134,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minCost(int[][] grid) { @@ -166,6 +170,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -197,6 +203,8 @@ public: }; ``` +#### Go + ```go func minCost(grid [][]int) int { m, n := len(grid), len(grid[0]) @@ -234,6 +242,8 @@ func minCost(grid [][]int) int { } ``` +#### TypeScript + ```ts function minCost(grid: number[][]): number { const m = grid.length, diff --git a/solution/1300-1399/1368.Minimum Cost to Make at Least One Valid Path in a Grid/README_EN.md b/solution/1300-1399/1368.Minimum Cost to Make at Least One Valid Path in a Grid/README_EN.md index 43219c5f630d0..0c2c20df7515b 100644 --- a/solution/1300-1399/1368.Minimum Cost to Make at Least One Valid Path in a Grid/README_EN.md +++ b/solution/1300-1399/1368.Minimum Cost to Make at Least One Valid Path in a Grid/README_EN.md @@ -92,6 +92,8 @@ In an undirected graph where the edge weights are only 0 and 1, we can use a dou +#### Python3 + ```python class Solution: def minCost(self, grid: List[List[int]]) -> int: @@ -116,6 +118,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minCost(int[][] grid) { @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func minCost(grid [][]int) int { m, n := len(grid), len(grid[0]) @@ -218,6 +226,8 @@ func minCost(grid [][]int) int { } ``` +#### TypeScript + ```ts function minCost(grid: number[][]): number { const m = grid.length, diff --git a/solution/1300-1399/1369.Get the Second Most Recent Activity/README.md b/solution/1300-1399/1369.Get the Second Most Recent Activity/README.md index f2d8ecff46c28..2f1736b7e9049 100644 --- a/solution/1300-1399/1369.Get the Second Most Recent Activity/README.md +++ b/solution/1300-1399/1369.Get the Second Most Recent Activity/README.md @@ -78,6 +78,8 @@ Bob 只有一条记录,我们就取这条记录 +#### MySQL + ```sql SELECT username, diff --git a/solution/1300-1399/1369.Get the Second Most Recent Activity/README_EN.md b/solution/1300-1399/1369.Get the Second Most Recent Activity/README_EN.md index 3c0a9b458e780..768e956fc4157 100644 --- a/solution/1300-1399/1369.Get the Second Most Recent Activity/README_EN.md +++ b/solution/1300-1399/1369.Get the Second Most Recent Activity/README_EN.md @@ -78,6 +78,8 @@ Bob only has one record, we just take that one. +#### MySQL + ```sql SELECT username, diff --git a/solution/1300-1399/1370.Increasing Decreasing String/README.md b/solution/1300-1399/1370.Increasing Decreasing String/README.md index f9a1e0d4dce82..60f35ab663c89 100644 --- a/solution/1300-1399/1370.Increasing Decreasing String/README.md +++ b/solution/1300-1399/1370.Increasing Decreasing String/README.md @@ -99,6 +99,8 @@ tags: +#### Python3 + ```python class Solution: def sortString(self, s: str) -> str: @@ -113,6 +115,8 @@ class Solution: return "".join(ans) ``` +#### Java + ```java class Solution { public String sortString(String s) { @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go func sortString(s string) string { cnt := [26]int{} @@ -195,6 +203,8 @@ func sortString(s string) string { } ``` +#### TypeScript + ```ts function sortString(s: string): string { const cnt: number[] = Array(26).fill(0); @@ -220,6 +230,8 @@ function sortString(s: string): string { } ``` +#### JavaScript + ```js /** * @param {string} s diff --git a/solution/1300-1399/1370.Increasing Decreasing String/README_EN.md b/solution/1300-1399/1370.Increasing Decreasing String/README_EN.md index 275f52616733e..ea3195bf2ad93 100644 --- a/solution/1300-1399/1370.Increasing Decreasing String/README_EN.md +++ b/solution/1300-1399/1370.Increasing Decreasing String/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(n \times |\Sigma|)$, and the space complexity is $O(|\ +#### Python3 + ```python class Solution: def sortString(self, s: str) -> str: @@ -95,6 +97,8 @@ class Solution: return "".join(ans) ``` +#### Java + ```java class Solution { public String sortString(String s) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func sortString(s string) string { cnt := [26]int{} @@ -177,6 +185,8 @@ func sortString(s string) string { } ``` +#### TypeScript + ```ts function sortString(s: string): string { const cnt: number[] = Array(26).fill(0); @@ -202,6 +212,8 @@ function sortString(s: string): string { } ``` +#### JavaScript + ```js /** * @param {string} s diff --git a/solution/1300-1399/1371.Find the Longest Substring Containing Vowels in Even Counts/README.md b/solution/1300-1399/1371.Find the Longest Substring Containing Vowels in Even Counts/README.md index 07114fe489d26..d91b66a87c7c5 100644 --- a/solution/1300-1399/1371.Find the Longest Substring Containing Vowels in Even Counts/README.md +++ b/solution/1300-1399/1371.Find the Longest Substring Containing Vowels in Even Counts/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def findTheLongestSubstring(self, s: str) -> int: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func findTheLongestSubstring(s string) int { pos := make([]int, 32) diff --git a/solution/1300-1399/1371.Find the Longest Substring Containing Vowels in Even Counts/README_EN.md b/solution/1300-1399/1371.Find the Longest Substring Containing Vowels in Even Counts/README_EN.md index a764c38488d4a..6943898887773 100644 --- a/solution/1300-1399/1371.Find the Longest Substring Containing Vowels in Even Counts/README_EN.md +++ b/solution/1300-1399/1371.Find the Longest Substring Containing Vowels in Even Counts/README_EN.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def findTheLongestSubstring(self, s: str) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func findTheLongestSubstring(s string) int { pos := make([]int, 32) diff --git a/solution/1300-1399/1372.Longest ZigZag Path in a Binary Tree/README.md b/solution/1300-1399/1372.Longest ZigZag Path in a Binary Tree/README.md index c1e65190e0544..62dcfcd837081 100644 --- a/solution/1300-1399/1372.Longest ZigZag Path in a Binary Tree/README.md +++ b/solution/1300-1399/1372.Longest ZigZag Path in a Binary Tree/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -103,6 +105,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/1300-1399/1372.Longest ZigZag Path in a Binary Tree/README_EN.md b/solution/1300-1399/1372.Longest ZigZag Path in a Binary Tree/README_EN.md index d4825161092d2..3e95590f449ba 100644 --- a/solution/1300-1399/1372.Longest ZigZag Path in a Binary Tree/README_EN.md +++ b/solution/1300-1399/1372.Longest ZigZag Path in a Binary Tree/README_EN.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/1300-1399/1373.Maximum Sum BST in Binary Tree/README.md b/solution/1300-1399/1373.Maximum Sum BST in Binary Tree/README.md index 944b069aebafd..679f50a3c2a93 100644 --- a/solution/1300-1399/1373.Maximum Sum BST in Binary Tree/README.md +++ b/solution/1300-1399/1373.Maximum Sum BST in Binary Tree/README.md @@ -123,6 +123,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -149,6 +151,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -191,6 +195,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -229,6 +235,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -258,6 +266,8 @@ func maxSumBST(root *TreeNode) (ans int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/1300-1399/1373.Maximum Sum BST in Binary Tree/README_EN.md b/solution/1300-1399/1373.Maximum Sum BST in Binary Tree/README_EN.md index 68d26c43f09d0..15bea428a53b1 100644 --- a/solution/1300-1399/1373.Maximum Sum BST in Binary Tree/README_EN.md +++ b/solution/1300-1399/1373.Maximum Sum BST in Binary Tree/README_EN.md @@ -107,6 +107,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -133,6 +135,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -175,6 +179,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -213,6 +219,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -242,6 +250,8 @@ func maxSumBST(root *TreeNode) (ans int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/1300-1399/1374.Generate a String With Characters That Have Odd Counts/README.md b/solution/1300-1399/1374.Generate a String With Characters That Have Odd Counts/README.md index f839fe740cef5..f3d7e54452bf7 100644 --- a/solution/1300-1399/1374.Generate a String With Characters That Have Odd Counts/README.md +++ b/solution/1300-1399/1374.Generate a String With Characters That Have Odd Counts/README.md @@ -68,12 +68,16 @@ tags: +#### Python3 + ```python class Solution: def generateTheString(self, n: int) -> str: return 'a' * n if n & 1 else 'a' * (n - 1) + 'b' ``` +#### Java + ```java class Solution { public String generateTheString(int n) { @@ -82,6 +86,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -95,6 +101,8 @@ public: }; ``` +#### Go + ```go func generateTheString(n int) string { ans := strings.Repeat("a", n-1) @@ -107,6 +115,8 @@ func generateTheString(n int) string { } ``` +#### TypeScript + ```ts function generateTheString(n: number): string { const ans = Array(n).fill('a'); diff --git a/solution/1300-1399/1374.Generate a String With Characters That Have Odd Counts/README_EN.md b/solution/1300-1399/1374.Generate a String With Characters That Have Odd Counts/README_EN.md index c280d37e7b58c..372152b0d26d0 100644 --- a/solution/1300-1399/1374.Generate a String With Characters That Have Odd Counts/README_EN.md +++ b/solution/1300-1399/1374.Generate a String With Characters That Have Odd Counts/README_EN.md @@ -69,12 +69,16 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def generateTheString(self, n: int) -> str: return 'a' * n if n & 1 else 'a' * (n - 1) + 'b' ``` +#### Java + ```java class Solution { public String generateTheString(int n) { @@ -83,6 +87,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -96,6 +102,8 @@ public: }; ``` +#### Go + ```go func generateTheString(n int) string { ans := strings.Repeat("a", n-1) @@ -108,6 +116,8 @@ func generateTheString(n int) string { } ``` +#### TypeScript + ```ts function generateTheString(n: number): string { const ans = Array(n).fill('a'); diff --git a/solution/1300-1399/1375.Number of Times Binary String Is Prefix-Aligned/README.md b/solution/1300-1399/1375.Number of Times Binary String Is Prefix-Aligned/README.md index 098aff65bcc89..6c252beabd074 100644 --- a/solution/1300-1399/1375.Number of Times Binary String Is Prefix-Aligned/README.md +++ b/solution/1300-1399/1375.Number of Times Binary String Is Prefix-Aligned/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def numTimesAllBlue(self, flips: List[int]) -> int: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numTimesAllBlue(int[] flips) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func numTimesAllBlue(flips []int) (ans int) { mx := 0 @@ -132,6 +140,8 @@ func numTimesAllBlue(flips []int) (ans int) { } ``` +#### TypeScript + ```ts function numTimesAllBlue(flips: number[]): number { let ans = 0; diff --git a/solution/1300-1399/1375.Number of Times Binary String Is Prefix-Aligned/README_EN.md b/solution/1300-1399/1375.Number of Times Binary String Is Prefix-Aligned/README_EN.md index 832ab7885aff3..85728f8ff86c4 100644 --- a/solution/1300-1399/1375.Number of Times Binary String Is Prefix-Aligned/README_EN.md +++ b/solution/1300-1399/1375.Number of Times Binary String Is Prefix-Aligned/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $flips$. The +#### Python3 + ```python class Solution: def numTimesAllBlue(self, flips: List[int]) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numTimesAllBlue(int[] flips) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func numTimesAllBlue(flips []int) (ans int) { mx := 0 @@ -129,6 +137,8 @@ func numTimesAllBlue(flips []int) (ans int) { } ``` +#### TypeScript + ```ts function numTimesAllBlue(flips: number[]): number { let ans = 0; diff --git a/solution/1300-1399/1376.Time Needed to Inform All Employees/README.md b/solution/1300-1399/1376.Time Needed to Inform All Employees/README.md index 7d3db6c61e059..ae55d3babaf8f 100644 --- a/solution/1300-1399/1376.Time Needed to Inform All Employees/README.md +++ b/solution/1300-1399/1376.Time Needed to Inform All Employees/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def numOfMinutes( @@ -102,6 +104,8 @@ class Solution: return dfs(headID) ``` +#### Java + ```java class Solution { private List[] g; @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func numOfMinutes(n int, headID int, manager []int, informTime []int) int { g := make([][]int, n) @@ -170,6 +178,8 @@ func numOfMinutes(n int, headID int, manager []int, informTime []int) int { } ``` +#### TypeScript + ```ts function numOfMinutes(n: number, headID: number, manager: number[], informTime: number[]): number { const g: number[][] = new Array(n).fill(0).map(() => []); @@ -189,6 +199,8 @@ function numOfMinutes(n: number, headID: number, manager: number[], informTime: } ``` +#### C# + ```cs public class Solution { private List[] g; diff --git a/solution/1300-1399/1376.Time Needed to Inform All Employees/README_EN.md b/solution/1300-1399/1376.Time Needed to Inform All Employees/README_EN.md index 29245159993b6..0a11b052cc8fa 100644 --- a/solution/1300-1399/1376.Time Needed to Inform All Employees/README_EN.md +++ b/solution/1300-1399/1376.Time Needed to Inform All Employees/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def numOfMinutes( @@ -98,6 +100,8 @@ class Solution: return dfs(headID) ``` +#### Java + ```java class Solution { private List[] g; @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func numOfMinutes(n int, headID int, manager []int, informTime []int) int { g := make([][]int, n) @@ -166,6 +174,8 @@ func numOfMinutes(n int, headID int, manager []int, informTime []int) int { } ``` +#### TypeScript + ```ts function numOfMinutes(n: number, headID: number, manager: number[], informTime: number[]): number { const g: number[][] = new Array(n).fill(0).map(() => []); @@ -185,6 +195,8 @@ function numOfMinutes(n: number, headID: number, manager: number[], informTime: } ``` +#### C# + ```cs public class Solution { private List[] g; diff --git a/solution/1300-1399/1377.Frog Position After T Seconds/README.md b/solution/1300-1399/1377.Frog Position After T Seconds/README.md index 34a1838a6c9cb..b3db4e14cc39a 100644 --- a/solution/1300-1399/1377.Frog Position After T Seconds/README.md +++ b/solution/1300-1399/1377.Frog Position After T Seconds/README.md @@ -101,6 +101,8 @@ tags: +#### Python3 + ```python class Solution: def frogPosition( @@ -127,6 +129,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { public double frogPosition(int n, int[][] edges, int t, int target) { @@ -163,6 +167,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -198,6 +204,8 @@ public: }; ``` +#### Go + ```go func frogPosition(n int, edges [][]int, t int, target int) float64 { g := make([][]int, n+1) @@ -239,6 +247,8 @@ func frogPosition(n int, edges [][]int, t int, target int) float64 { } ``` +#### TypeScript + ```ts function frogPosition(n: number, edges: number[][], t: number, target: number): number { const g: number[][] = Array.from({ length: n + 1 }, () => []); @@ -268,6 +278,8 @@ function frogPosition(n: number, edges: number[][], t: number, target: number): } ``` +#### C# + ```cs public class Solution { public double FrogPosition(int n, int[][] edges, int t, int target) { diff --git a/solution/1300-1399/1377.Frog Position After T Seconds/README_EN.md b/solution/1300-1399/1377.Frog Position After T Seconds/README_EN.md index 1721e995ba43f..0b91d5bae0679 100644 --- a/solution/1300-1399/1377.Frog Position After T Seconds/README_EN.md +++ b/solution/1300-1399/1377.Frog Position After T Seconds/README_EN.md @@ -83,6 +83,8 @@ At the end of a round of search, we decrease $t$ by $1$, and then continue the n +#### Python3 + ```python class Solution: def frogPosition( @@ -109,6 +111,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { public double frogPosition(int n, int[][] edges, int t, int target) { @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -180,6 +186,8 @@ public: }; ``` +#### Go + ```go func frogPosition(n int, edges [][]int, t int, target int) float64 { g := make([][]int, n+1) @@ -221,6 +229,8 @@ func frogPosition(n int, edges [][]int, t int, target int) float64 { } ``` +#### TypeScript + ```ts function frogPosition(n: number, edges: number[][], t: number, target: number): number { const g: number[][] = Array.from({ length: n + 1 }, () => []); @@ -250,6 +260,8 @@ function frogPosition(n: number, edges: number[][], t: number, target: number): } ``` +#### C# + ```cs public class Solution { public double FrogPosition(int n, int[][] edges, int t, int target) { diff --git a/solution/1300-1399/1378.Replace Employee ID With The Unique Identifier/README.md b/solution/1300-1399/1378.Replace Employee ID With The Unique Identifier/README.md index f0b4db6404f4c..0b3e43923711d 100644 --- a/solution/1300-1399/1378.Replace Employee ID With The Unique Identifier/README.md +++ b/solution/1300-1399/1378.Replace Employee ID With The Unique Identifier/README.md @@ -104,6 +104,8 @@ Jonathan 唯一标识码是 1 。 +#### MySQL + ```sql # Write your MySQL query statement below SELECT unique_id, name diff --git a/solution/1300-1399/1378.Replace Employee ID With The Unique Identifier/README_EN.md b/solution/1300-1399/1378.Replace Employee ID With The Unique Identifier/README_EN.md index 141f27c26072d..0727564436c4b 100644 --- a/solution/1300-1399/1378.Replace Employee ID With The Unique Identifier/README_EN.md +++ b/solution/1300-1399/1378.Replace Employee ID With The Unique Identifier/README_EN.md @@ -102,6 +102,8 @@ The unique ID of Jonathan is 1. +#### MySQL + ```sql # Write your MySQL query statement below SELECT unique_id, name diff --git a/solution/1300-1399/1379.Find a Corresponding Node of a Binary Tree in a Clone of That Tree/README.md b/solution/1300-1399/1379.Find a Corresponding Node of a Binary Tree in a Clone of That Tree/README.md index 1d93f4a76e316..d710f7ba15d23 100644 --- a/solution/1300-1399/1379.Find a Corresponding Node of a Binary Tree in a Clone of That Tree/README.md +++ b/solution/1300-1399/1379.Find a Corresponding Node of a Binary Tree in a Clone of That Tree/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -115,6 +117,8 @@ class Solution: return dfs(original, cloned) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -177,6 +183,8 @@ public: }; ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -210,6 +218,8 @@ function getTargetCopy( } ``` +#### C# + ```cs /** * Definition for a binary tree node. diff --git a/solution/1300-1399/1379.Find a Corresponding Node of a Binary Tree in a Clone of That Tree/README_EN.md b/solution/1300-1399/1379.Find a Corresponding Node of a Binary Tree in a Clone of That Tree/README_EN.md index f3684915d599c..6a73ca4af523e 100644 --- a/solution/1300-1399/1379.Find a Corresponding Node of a Binary Tree in a Clone of That Tree/README_EN.md +++ b/solution/1300-1399/1379.Find a Corresponding Node of a Binary Tree in a Clone of That Tree/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -99,6 +101,8 @@ class Solution: return dfs(original, cloned) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -161,6 +167,8 @@ public: }; ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -194,6 +202,8 @@ function getTargetCopy( } ``` +#### C# + ```cs /** * Definition for a binary tree node. diff --git a/solution/1300-1399/1380.Lucky Numbers in a Matrix/README.md b/solution/1300-1399/1380.Lucky Numbers in a Matrix/README.md index 26d6137661c29..f654912945c9d 100644 --- a/solution/1300-1399/1380.Lucky Numbers in a Matrix/README.md +++ b/solution/1300-1399/1380.Lucky Numbers in a Matrix/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def luckyNumbers(self, matrix: List[List[int]]) -> List[int]: @@ -90,6 +92,8 @@ class Solution: return list(rows & cols) ``` +#### Java + ```java class Solution { public List luckyNumbers(int[][] matrix) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func luckyNumbers(matrix [][]int) (ans []int) { m, n := len(matrix), len(matrix[0]) @@ -168,6 +176,8 @@ func luckyNumbers(matrix [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function luckyNumbers(matrix: number[][]): number[] { const m = matrix.length; @@ -192,6 +202,8 @@ function luckyNumbers(matrix: number[][]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn lucky_numbers(matrix: Vec>) -> Vec { diff --git a/solution/1300-1399/1380.Lucky Numbers in a Matrix/README_EN.md b/solution/1300-1399/1380.Lucky Numbers in a Matrix/README_EN.md index c4404722259c2..208a413bd3fa6 100644 --- a/solution/1300-1399/1380.Lucky Numbers in a Matrix/README_EN.md +++ b/solution/1300-1399/1380.Lucky Numbers in a Matrix/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m + n)$. +#### Python3 + ```python class Solution: def luckyNumbers(self, matrix: List[List[int]]) -> List[int]: @@ -83,6 +85,8 @@ class Solution: return list(rows & cols) ``` +#### Java + ```java class Solution { public List luckyNumbers(int[][] matrix) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func luckyNumbers(matrix [][]int) (ans []int) { m, n := len(matrix), len(matrix[0]) @@ -161,6 +169,8 @@ func luckyNumbers(matrix [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function luckyNumbers(matrix: number[][]): number[] { const m = matrix.length; @@ -185,6 +195,8 @@ function luckyNumbers(matrix: number[][]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn lucky_numbers(matrix: Vec>) -> Vec { diff --git a/solution/1300-1399/1381.Design a Stack With Increment Operation/README.md b/solution/1300-1399/1381.Design a Stack With Increment Operation/README.md index 249cdca9e048f..c3efcbd0afe16 100644 --- a/solution/1300-1399/1381.Design a Stack With Increment Operation/README.md +++ b/solution/1300-1399/1381.Design a Stack With Increment Operation/README.md @@ -87,6 +87,8 @@ stk.pop(); // 返回 -1 --> 栈为空,返回 -1 +#### Python3 + ```python class CustomStack: def __init__(self, maxSize: int): @@ -122,6 +124,8 @@ class CustomStack: # obj.increment(k,val) ``` +#### Java + ```java class CustomStack { private int[] stk; @@ -167,6 +171,8 @@ class CustomStack { */ ``` +#### C++ + ```cpp class CustomStack { public: @@ -215,6 +221,8 @@ private: */ ``` +#### Go + ```go type CustomStack struct { stk []int @@ -261,6 +269,8 @@ func (this *CustomStack) Increment(k int, val int) { */ ``` +#### TypeScript + ```ts class CustomStack { private stk: number[]; diff --git a/solution/1300-1399/1381.Design a Stack With Increment Operation/README_EN.md b/solution/1300-1399/1381.Design a Stack With Increment Operation/README_EN.md index f8806fc04ef43..101d2e86320d0 100644 --- a/solution/1300-1399/1381.Design a Stack With Increment Operation/README_EN.md +++ b/solution/1300-1399/1381.Design a Stack With Increment Operation/README_EN.md @@ -85,6 +85,8 @@ The time complexity is $O(1)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class CustomStack: def __init__(self, maxSize: int): @@ -120,6 +122,8 @@ class CustomStack: # obj.increment(k,val) ``` +#### Java + ```java class CustomStack { private int[] stk; @@ -165,6 +169,8 @@ class CustomStack { */ ``` +#### C++ + ```cpp class CustomStack { public: @@ -213,6 +219,8 @@ private: */ ``` +#### Go + ```go type CustomStack struct { stk []int @@ -259,6 +267,8 @@ func (this *CustomStack) Increment(k int, val int) { */ ``` +#### TypeScript + ```ts class CustomStack { private stk: number[]; diff --git a/solution/1300-1399/1382.Balance a Binary Search Tree/README.md b/solution/1300-1399/1382.Balance a Binary Search Tree/README.md index 1432b37a4a9f7..da1fe6d85127e 100644 --- a/solution/1300-1399/1382.Balance a Binary Search Tree/README.md +++ b/solution/1300-1399/1382.Balance a Binary Search Tree/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -105,6 +107,8 @@ class Solution: return build(0, len(nums) - 1) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -193,6 +199,8 @@ private: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -228,6 +236,8 @@ func balanceBST(root *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/1300-1399/1382.Balance a Binary Search Tree/README_EN.md b/solution/1300-1399/1382.Balance a Binary Search Tree/README_EN.md index d1e9dd435dc73..400cbe99fa2fe 100644 --- a/solution/1300-1399/1382.Balance a Binary Search Tree/README_EN.md +++ b/solution/1300-1399/1382.Balance a Binary Search Tree/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -99,6 +101,8 @@ class Solution: return build(0, len(nums) - 1) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -187,6 +193,8 @@ private: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -222,6 +230,8 @@ func balanceBST(root *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/1300-1399/1383.Maximum Performance of a Team/README.md b/solution/1300-1399/1383.Maximum Performance of a Team/README.md index 4420c5894445a..0bdf6ade7452a 100644 --- a/solution/1300-1399/1383.Maximum Performance of a Team/README.md +++ b/solution/1300-1399/1383.Maximum Performance of a Team/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def maxPerformance( @@ -104,6 +106,8 @@ class Solution: return ans % mod ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func maxPerformance(n int, speed []int, efficiency []int, k int) int { t := make([][]int, n) diff --git a/solution/1300-1399/1383.Maximum Performance of a Team/README_EN.md b/solution/1300-1399/1383.Maximum Performance of a Team/README_EN.md index 21be9771191c7..15f358f9aa255 100644 --- a/solution/1300-1399/1383.Maximum Performance of a Team/README_EN.md +++ b/solution/1300-1399/1383.Maximum Performance of a Team/README_EN.md @@ -76,6 +76,8 @@ We have the maximum performance of the team by selecting engineer 2 (with speed= +#### Python3 + ```python class Solution: def maxPerformance( @@ -94,6 +96,8 @@ class Solution: return ans % mod ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func maxPerformance(n int, speed []int, efficiency []int, k int) int { t := make([][]int, n) diff --git a/solution/1300-1399/1384.Total Sales Amount by Year/README.md b/solution/1300-1399/1384.Total Sales Amount by Year/README.md index 2bc205a47ebc0..d3c614434cad6 100644 --- a/solution/1300-1399/1384.Total Sales Amount by Year/README.md +++ b/solution/1300-1399/1384.Total Sales Amount by Year/README.md @@ -104,6 +104,8 @@ LC Keychain 在 2019-12-01 至 2020-01-31 期间销售,该产品在2019 +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1300-1399/1384.Total Sales Amount by Year/README_EN.md b/solution/1300-1399/1384.Total Sales Amount by Year/README_EN.md index a13703cd61636..d130059f7d8a7 100644 --- a/solution/1300-1399/1384.Total Sales Amount by Year/README_EN.md +++ b/solution/1300-1399/1384.Total Sales Amount by Year/README_EN.md @@ -104,6 +104,8 @@ LC Keychain was sold for the period of 2019-12-01 to 2020-01-31, and there are 3 +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1300-1399/1385.Find the Distance Value Between Two Arrays/README.md b/solution/1300-1399/1385.Find the Distance Value Between Two Arrays/README.md index 8000ccb9053a8..143c3d1ab1a24 100644 --- a/solution/1300-1399/1385.Find the Distance Value Between Two Arrays/README.md +++ b/solution/1300-1399/1385.Find the Distance Value Between Two Arrays/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def findTheDistanceValue(self, arr1: List[int], arr2: List[int], d: int) -> int: @@ -102,6 +104,8 @@ class Solution: return sum(check(a) for a in arr1) ``` +#### Java + ```java class Solution { public int findTheDistanceValue(int[] arr1, int[] arr2, int d) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func findTheDistanceValue(arr1 []int, arr2 []int, d int) (ans int) { sort.Ints(arr2) @@ -161,6 +169,8 @@ func findTheDistanceValue(arr1 []int, arr2 []int, d int) (ans int) { } ``` +#### TypeScript + ```ts function findTheDistanceValue(arr1: number[], arr2: number[], d: number): number { const check = (a: number) => { @@ -187,6 +197,8 @@ function findTheDistanceValue(arr1: number[], arr2: number[], d: number): number } ``` +#### Rust + ```rust impl Solution { pub fn find_the_distance_value(arr1: Vec, mut arr2: Vec, d: i32) -> i32 { diff --git a/solution/1300-1399/1385.Find the Distance Value Between Two Arrays/README_EN.md b/solution/1300-1399/1385.Find the Distance Value Between Two Arrays/README_EN.md index 0efc06cba8998..de07ef80d27ed 100644 --- a/solution/1300-1399/1385.Find the Distance Value Between Two Arrays/README_EN.md +++ b/solution/1300-1399/1385.Find the Distance Value Between Two Arrays/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O((m + n) \times \log n)$, and the space complexity is $ +#### Python3 + ```python class Solution: def findTheDistanceValue(self, arr1: List[int], arr2: List[int], d: int) -> int: @@ -97,6 +99,8 @@ class Solution: return sum(check(a) for a in arr1) ``` +#### Java + ```java class Solution { public int findTheDistanceValue(int[] arr1, int[] arr2, int d) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func findTheDistanceValue(arr1 []int, arr2 []int, d int) (ans int) { sort.Ints(arr2) @@ -156,6 +164,8 @@ func findTheDistanceValue(arr1 []int, arr2 []int, d int) (ans int) { } ``` +#### TypeScript + ```ts function findTheDistanceValue(arr1: number[], arr2: number[], d: number): number { const check = (a: number) => { @@ -182,6 +192,8 @@ function findTheDistanceValue(arr1: number[], arr2: number[], d: number): number } ``` +#### Rust + ```rust impl Solution { pub fn find_the_distance_value(arr1: Vec, mut arr2: Vec, d: i32) -> i32 { diff --git a/solution/1300-1399/1386.Cinema Seat Allocation/README.md b/solution/1300-1399/1386.Cinema Seat Allocation/README.md index 22df8d2fdf6aa..1fbe02fee2d47 100644 --- a/solution/1300-1399/1386.Cinema Seat Allocation/README.md +++ b/solution/1300-1399/1386.Cinema Seat Allocation/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int: @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxNumberOfFamilies(int n, int[][] reservedSeats) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func maxNumberOfFamilies(n int, reservedSeats [][]int) int { d := map[int]int{} @@ -174,6 +182,8 @@ func maxNumberOfFamilies(n int, reservedSeats [][]int) int { } ``` +#### TypeScript + ```ts function maxNumberOfFamilies(n: number, reservedSeats: number[][]): number { const d: Map = new Map(); diff --git a/solution/1300-1399/1386.Cinema Seat Allocation/README_EN.md b/solution/1300-1399/1386.Cinema Seat Allocation/README_EN.md index fa98ebd0a7e5c..97c86c6240dff 100644 --- a/solution/1300-1399/1386.Cinema Seat Allocation/README_EN.md +++ b/solution/1300-1399/1386.Cinema Seat Allocation/README_EN.md @@ -88,6 +88,8 @@ The time complexity is $O(m)$, and the space complexity is $O(m)$. Where $m$ is +#### Python3 + ```python class Solution: def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxNumberOfFamilies(int n, int[][] reservedSeats) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func maxNumberOfFamilies(n int, reservedSeats [][]int) int { d := map[int]int{} @@ -172,6 +180,8 @@ func maxNumberOfFamilies(n int, reservedSeats [][]int) int { } ``` +#### TypeScript + ```ts function maxNumberOfFamilies(n: number, reservedSeats: number[][]): number { const d: Map = new Map(); diff --git a/solution/1300-1399/1387.Sort Integers by The Power Value/README.md b/solution/1300-1399/1387.Sort Integers by The Power Value/README.md index 51097ca39b0c1..a4b39d82ab3b8 100644 --- a/solution/1300-1399/1387.Sort Integers by The Power Value/README.md +++ b/solution/1300-1399/1387.Sort Integers by The Power Value/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python @cache def f(x: int) -> int: @@ -105,6 +107,8 @@ class Solution: return sorted(range(lo, hi + 1), key=f)[k - 1] ``` +#### Java + ```java class Solution { public int getKth(int lo, int hi, int k) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func getKth(lo int, hi int, k int) int { f := func(x int) (ans int) { @@ -192,6 +200,8 @@ func getKth(lo int, hi int, k int) int { } ``` +#### TypeScript + ```ts function getKth(lo: number, hi: number, k: number): number { const f = (x: number): number => { diff --git a/solution/1300-1399/1387.Sort Integers by The Power Value/README_EN.md b/solution/1300-1399/1387.Sort Integers by The Power Value/README_EN.md index 57eec7171fc41..94d8d2ed9d1e2 100644 --- a/solution/1300-1399/1387.Sort Integers by The Power Value/README_EN.md +++ b/solution/1300-1399/1387.Sort Integers by The Power Value/README_EN.md @@ -85,6 +85,8 @@ The time complexity is $O(n \times \log n \times M)$, and the space complexity i +#### Python3 + ```python @cache def f(x: int) -> int: @@ -103,6 +105,8 @@ class Solution: return sorted(range(lo, hi + 1), key=f)[k - 1] ``` +#### Java + ```java class Solution { public int getKth(int lo, int hi, int k) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func getKth(lo int, hi int, k int) int { f := func(x int) (ans int) { @@ -190,6 +198,8 @@ func getKth(lo int, hi int, k int) int { } ``` +#### TypeScript + ```ts function getKth(lo: number, hi: number, k: number): number { const f = (x: number): number => { diff --git a/solution/1300-1399/1388.Pizza With 3n Slices/README.md b/solution/1300-1399/1388.Pizza With 3n Slices/README.md index 5eb6997b00fda..7fd688d2091d2 100644 --- a/solution/1300-1399/1388.Pizza With 3n Slices/README.md +++ b/solution/1300-1399/1388.Pizza With 3n Slices/README.md @@ -103,6 +103,8 @@ $$ +#### Python3 + ```python class Solution: def maxSizeSlices(self, slices: List[int]) -> int: @@ -121,6 +123,8 @@ class Solution: return max(a, b) ``` +#### Java + ```java class Solution { private int n; @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go func maxSizeSlices(slices []int) int { n := len(slices) / 3 @@ -197,6 +205,8 @@ func maxSizeSlices(slices []int) int { } ``` +#### TypeScript + ```ts function maxSizeSlices(slices: number[]): number { const n = Math.floor(slices.length / 3); diff --git a/solution/1300-1399/1388.Pizza With 3n Slices/README_EN.md b/solution/1300-1399/1388.Pizza With 3n Slices/README_EN.md index 2a96591c6dcb6..edc117d919c2b 100644 --- a/solution/1300-1399/1388.Pizza With 3n Slices/README_EN.md +++ b/solution/1300-1399/1388.Pizza With 3n Slices/README_EN.md @@ -95,6 +95,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$. Where $n$ +#### Python3 + ```python class Solution: def maxSizeSlices(self, slices: List[int]) -> int: @@ -113,6 +115,8 @@ class Solution: return max(a, b) ``` +#### Java + ```java class Solution { private int n; @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func maxSizeSlices(slices []int) int { n := len(slices) / 3 @@ -189,6 +197,8 @@ func maxSizeSlices(slices []int) int { } ``` +#### TypeScript + ```ts function maxSizeSlices(slices: number[]): number { const n = Math.floor(slices.length / 3); diff --git a/solution/1300-1399/1389.Create Target Array in the Given Order/README.md b/solution/1300-1399/1389.Create Target Array in the Given Order/README.md index 7ad5414897628..481401f0d3da3 100644 --- a/solution/1300-1399/1389.Create Target Array in the Given Order/README.md +++ b/solution/1300-1399/1389.Create Target Array in the Given Order/README.md @@ -90,6 +90,8 @@ nums index target +#### Python3 + ```python class Solution: def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]: @@ -99,6 +101,8 @@ class Solution: return target ``` +#### Java + ```java class Solution { public int[] createTargetArray(int[] nums, int[] index) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func createTargetArray(nums []int, index []int) []int { target := make([]int, len(nums)) @@ -141,6 +149,8 @@ func createTargetArray(nums []int, index []int) []int { } ``` +#### TypeScript + ```ts function createTargetArray(nums: number[], index: number[]): number[] { const ans: number[] = []; diff --git a/solution/1300-1399/1389.Create Target Array in the Given Order/README_EN.md b/solution/1300-1399/1389.Create Target Array in the Given Order/README_EN.md index 1a39b916cef02..5b4fab837572f 100644 --- a/solution/1300-1399/1389.Create Target Array in the Given Order/README_EN.md +++ b/solution/1300-1399/1389.Create Target Array in the Given Order/README_EN.md @@ -91,6 +91,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$. Where $n$ i +#### Python3 + ```python class Solution: def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]: @@ -100,6 +102,8 @@ class Solution: return target ``` +#### Java + ```java class Solution { public int[] createTargetArray(int[] nums, int[] index) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func createTargetArray(nums []int, index []int) []int { target := make([]int, len(nums)) @@ -142,6 +150,8 @@ func createTargetArray(nums []int, index []int) []int { } ``` +#### TypeScript + ```ts function createTargetArray(nums: number[], index: number[]): number[] { const ans: number[] = []; diff --git a/solution/1300-1399/1390.Four Divisors/README.md b/solution/1300-1399/1390.Four Divisors/README.md index d1160e327e31d..712971a735f5c 100644 --- a/solution/1300-1399/1390.Four Divisors/README.md +++ b/solution/1300-1399/1390.Four Divisors/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def sumFourDivisors(self, nums: List[int]) -> int: @@ -90,6 +92,8 @@ class Solution: return sum(f(x) for x in nums) ``` +#### Java + ```java class Solution { public int sumFourDivisors(int[] nums) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func sumFourDivisors(nums []int) (ans int) { f := func(x int) int { @@ -171,6 +179,8 @@ func sumFourDivisors(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function sumFourDivisors(nums: number[]): number { const f = (x: number): number => { diff --git a/solution/1300-1399/1390.Four Divisors/README_EN.md b/solution/1300-1399/1390.Four Divisors/README_EN.md index 362d95355c710..457c7bf9aa0b0 100644 --- a/solution/1300-1399/1390.Four Divisors/README_EN.md +++ b/solution/1300-1399/1390.Four Divisors/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n \times \sqrt{n})$, where $n$ is the length of the ar +#### Python3 + ```python class Solution: def sumFourDivisors(self, nums: List[int]) -> int: @@ -89,6 +91,8 @@ class Solution: return sum(f(x) for x in nums) ``` +#### Java + ```java class Solution { public int sumFourDivisors(int[] nums) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func sumFourDivisors(nums []int) (ans int) { f := func(x int) int { @@ -170,6 +178,8 @@ func sumFourDivisors(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function sumFourDivisors(nums: number[]): number { const f = (x: number): number => { diff --git a/solution/1300-1399/1391.Check if There is a Valid Path in a Grid/README.md b/solution/1300-1399/1391.Check if There is a Valid Path in a Grid/README.md index 454c2102dd7a6..f023639966d1c 100644 --- a/solution/1300-1399/1391.Check if There is a Valid Path in a Grid/README.md +++ b/solution/1300-1399/1391.Check if There is a Valid Path in a Grid/README.md @@ -101,6 +101,8 @@ tags: +#### Python3 + ```python class Solution: def hasValidPath(self, grid: List[List[int]]) -> bool: @@ -152,6 +154,8 @@ class Solution: return find(0) == find(m * n - 1) ``` +#### Java + ```java class Solution { private int[] p; @@ -227,6 +231,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -291,6 +297,8 @@ public: }; ``` +#### Go + ```go func hasValidPath(grid [][]int) bool { m, n := len(grid), len(grid[0]) diff --git a/solution/1300-1399/1391.Check if There is a Valid Path in a Grid/README_EN.md b/solution/1300-1399/1391.Check if There is a Valid Path in a Grid/README_EN.md index b382cf00055f7..88731f0ab7260 100644 --- a/solution/1300-1399/1391.Check if There is a Valid Path in a Grid/README_EN.md +++ b/solution/1300-1399/1391.Check if There is a Valid Path in a Grid/README_EN.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def hasValidPath(self, grid: List[List[int]]) -> bool: @@ -135,6 +137,8 @@ class Solution: return find(0) == find(m * n - 1) ``` +#### Java + ```java class Solution { private int[] p; @@ -210,6 +214,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -274,6 +280,8 @@ public: }; ``` +#### Go + ```go func hasValidPath(grid [][]int) bool { m, n := len(grid), len(grid[0]) diff --git a/solution/1300-1399/1392.Longest Happy Prefix/README.md b/solution/1300-1399/1392.Longest Happy Prefix/README.md index 9f464e55acb1b..d0e4490cf2cdc 100644 --- a/solution/1300-1399/1392.Longest Happy Prefix/README.md +++ b/solution/1300-1399/1392.Longest Happy Prefix/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def longestPrefix(self, s: str) -> str: @@ -79,6 +81,8 @@ class Solution: return '' ``` +#### Java + ```java class Solution { private long[] p; @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp typedef unsigned long long ULL; @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func longestPrefix(s string) string { base := 131 @@ -155,6 +163,8 @@ func longestPrefix(s string) string { } ``` +#### TypeScript + ```ts function longestPrefix(s: string): string { const n = s.length; @@ -167,6 +177,8 @@ function longestPrefix(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn longest_prefix(s: String) -> String { diff --git a/solution/1300-1399/1392.Longest Happy Prefix/README_EN.md b/solution/1300-1399/1392.Longest Happy Prefix/README_EN.md index 3da0034bf20ee..1cde8157af9b0 100644 --- a/solution/1300-1399/1392.Longest Happy Prefix/README_EN.md +++ b/solution/1300-1399/1392.Longest Happy Prefix/README_EN.md @@ -68,6 +68,8 @@ Except for extremely specially constructed data, the above hash algorithm is unl +#### Python3 + ```python class Solution: def longestPrefix(self, s: str) -> str: @@ -77,6 +79,8 @@ class Solution: return '' ``` +#### Java + ```java class Solution { private long[] p; @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp typedef unsigned long long ULL; @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func longestPrefix(s string) string { base := 131 @@ -153,6 +161,8 @@ func longestPrefix(s string) string { } ``` +#### TypeScript + ```ts function longestPrefix(s: string): string { const n = s.length; @@ -165,6 +175,8 @@ function longestPrefix(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn longest_prefix(s: String) -> String { diff --git a/solution/1300-1399/1393.Capital GainLoss/README.md b/solution/1300-1399/1393.Capital GainLoss/README.md index 8135c3f2cf9e5..c974bf083b3b3 100644 --- a/solution/1300-1399/1393.Capital GainLoss/README.md +++ b/solution/1300-1399/1393.Capital GainLoss/README.md @@ -90,6 +90,8 @@ Corona Masks 股票在第1天以10美元的价格买入,在第3天以1010美 +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1300-1399/1393.Capital GainLoss/README_EN.md b/solution/1300-1399/1393.Capital GainLoss/README_EN.md index 3f466729e4b99..1e2b516a34214 100644 --- a/solution/1300-1399/1393.Capital GainLoss/README_EN.md +++ b/solution/1300-1399/1393.Capital GainLoss/README_EN.md @@ -89,6 +89,8 @@ We use `GROUP BY` to group the buy and sell operations of the same stock, and th +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1300-1399/1394.Find Lucky Integer in an Array/README.md b/solution/1300-1399/1394.Find Lucky Integer in an Array/README.md index f4707bffbe591..d81d2975c0a03 100644 --- a/solution/1300-1399/1394.Find Lucky Integer in an Array/README.md +++ b/solution/1300-1399/1394.Find Lucky Integer in an Array/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def findLucky(self, arr: List[int]) -> int: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findLucky(int[] arr) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func findLucky(arr []int) int { cnt := [510]int{} @@ -152,6 +160,8 @@ func findLucky(arr []int) int { } ``` +#### TypeScript + ```ts function findLucky(arr: number[]): number { const cnt = new Array(510).fill(0); @@ -168,6 +178,8 @@ function findLucky(arr: number[]): number { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1300-1399/1394.Find Lucky Integer in an Array/README_EN.md b/solution/1300-1399/1394.Find Lucky Integer in an Array/README_EN.md index 6e6188f0f7c4b..919629e56d001 100644 --- a/solution/1300-1399/1394.Find Lucky Integer in an Array/README_EN.md +++ b/solution/1300-1399/1394.Find Lucky Integer in an Array/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def findLucky(self, arr: List[int]) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findLucky(int[] arr) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func findLucky(arr []int) int { cnt := [510]int{} @@ -136,6 +144,8 @@ func findLucky(arr []int) int { } ``` +#### TypeScript + ```ts function findLucky(arr: number[]): number { const cnt = new Array(510).fill(0); @@ -152,6 +162,8 @@ function findLucky(arr: number[]): number { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1300-1399/1395.Count Number of Teams/README.md b/solution/1300-1399/1395.Count Number of Teams/README.md index 8e8ceb292b289..bfc85de5e609a 100644 --- a/solution/1300-1399/1395.Count Number of Teams/README.md +++ b/solution/1300-1399/1395.Count Number of Teams/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def numTeams(self, rating: List[int]) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numTeams(int[] rating) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func numTeams(rating []int) (ans int) { n := len(rating) @@ -166,6 +174,8 @@ func numTeams(rating []int) (ans int) { } ``` +#### TypeScript + ```ts function numTeams(rating: number[]): number { let ans = 0; @@ -204,6 +214,8 @@ function numTeams(rating: number[]): number { +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n: int): @@ -245,6 +257,8 @@ class Solution: return ans ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -318,6 +332,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -375,6 +391,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -433,6 +451,8 @@ func numTeams(rating []int) (ans int) { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; diff --git a/solution/1300-1399/1395.Count Number of Teams/README_EN.md b/solution/1300-1399/1395.Count Number of Teams/README_EN.md index 560a0ad320b12..bb1d7b846fc65 100644 --- a/solution/1300-1399/1395.Count Number of Teams/README_EN.md +++ b/solution/1300-1399/1395.Count Number of Teams/README_EN.md @@ -79,6 +79,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(1)$. Where $n$ i +#### Python3 + ```python class Solution: def numTeams(self, rating: List[int]) -> int: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numTeams(int[] rating) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func numTeams(rating []int) (ans int) { n := len(rating) @@ -164,6 +172,8 @@ func numTeams(rating []int) (ans int) { } ``` +#### TypeScript + ```ts function numTeams(rating: number[]): number { let ans = 0; @@ -202,6 +212,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n: int): @@ -243,6 +255,8 @@ class Solution: return ans ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -316,6 +330,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -373,6 +389,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -431,6 +449,8 @@ func numTeams(rating []int) (ans int) { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; diff --git a/solution/1300-1399/1396.Design Underground System/README.md b/solution/1300-1399/1396.Design Underground System/README.md index 5bceb8e2e2e9f..77d6861e719d8 100644 --- a/solution/1300-1399/1396.Design Underground System/README.md +++ b/solution/1300-1399/1396.Design Underground System/README.md @@ -135,6 +135,8 @@ undergroundSystem.getAverageTime("Leyton", "Paradise"); // 返回 6.66667 ,(5 +#### Python3 + ```python class UndergroundSystem: def __init__(self): @@ -161,6 +163,8 @@ class UndergroundSystem: # param_3 = obj.getAverageTime(startStation,endStation) ``` +#### Java + ```java class UndergroundSystem { private Map ts = new HashMap<>(); @@ -199,6 +203,8 @@ class UndergroundSystem { */ ``` +#### C++ + ```cpp class UndergroundSystem { public: @@ -235,6 +241,8 @@ private: */ ``` +#### Go + ```go type UndergroundSystem struct { ts map[int]pair diff --git a/solution/1300-1399/1396.Design Underground System/README_EN.md b/solution/1300-1399/1396.Design Underground System/README_EN.md index 11fe6cc0e20e3..856eb5b08d758 100644 --- a/solution/1300-1399/1396.Design Underground System/README_EN.md +++ b/solution/1300-1399/1396.Design Underground System/README_EN.md @@ -134,6 +134,8 @@ The time complexity is $O(1)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class UndergroundSystem: def __init__(self): @@ -160,6 +162,8 @@ class UndergroundSystem: # param_3 = obj.getAverageTime(startStation,endStation) ``` +#### Java + ```java class UndergroundSystem { private Map ts = new HashMap<>(); @@ -198,6 +202,8 @@ class UndergroundSystem { */ ``` +#### C++ + ```cpp class UndergroundSystem { public: @@ -234,6 +240,8 @@ private: */ ``` +#### Go + ```go type UndergroundSystem struct { ts map[int]pair diff --git a/solution/1300-1399/1397.Find All Good Strings/README.md b/solution/1300-1399/1397.Find All Good Strings/README.md index 7c568ef13f62c..e29ad6bb348d6 100644 --- a/solution/1300-1399/1397.Find All Good Strings/README.md +++ b/solution/1300-1399/1397.Find All Good Strings/README.md @@ -71,18 +71,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1300-1399/1397.Find All Good Strings/README_EN.md b/solution/1300-1399/1397.Find All Good Strings/README_EN.md index bcbb7f2e49cce..1e5c249d1a8ee 100644 --- a/solution/1300-1399/1397.Find All Good Strings/README_EN.md +++ b/solution/1300-1399/1397.Find All Good Strings/README_EN.md @@ -70,18 +70,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1300-1399/1398.Customers Who Bought Products A and B but Not C/README.md b/solution/1300-1399/1398.Customers Who Bought Products A and B but Not C/README.md index e67fc0f14eca0..4a5df7f4cb9e6 100644 --- a/solution/1300-1399/1398.Customers Who Bought Products A and B but Not C/README.md +++ b/solution/1300-1399/1398.Customers Who Bought Products A and B but Not C/README.md @@ -103,6 +103,8 @@ Orders table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT customer_id, customer_name diff --git a/solution/1300-1399/1398.Customers Who Bought Products A and B but Not C/README_EN.md b/solution/1300-1399/1398.Customers Who Bought Products A and B but Not C/README_EN.md index 43bdb83179e8d..c77da5df0902d 100644 --- a/solution/1300-1399/1398.Customers Who Bought Products A and B but Not C/README_EN.md +++ b/solution/1300-1399/1398.Customers Who Bought Products A and B but Not C/README_EN.md @@ -101,6 +101,8 @@ We can use `LEFT JOIN` to join the `Customers` table and the `Orders` table, the +#### MySQL + ```sql # Write your MySQL query statement below SELECT customer_id, customer_name diff --git a/solution/1300-1399/1399.Count Largest Group/README.md b/solution/1300-1399/1399.Count Largest Group/README.md index feccfccdad3cd..ee880ec654ac2 100644 --- a/solution/1300-1399/1399.Count Largest Group/README.md +++ b/solution/1300-1399/1399.Count Largest Group/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def countLargestGroup(self, n: int) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countLargestGroup(int n) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func countLargestGroup(n int) (ans int) { cnt := [40]int{} @@ -165,6 +173,8 @@ func countLargestGroup(n int) (ans int) { } ``` +#### TypeScript + ```ts function countLargestGroup(n: number): number { const cnt: number[] = new Array(40).fill(0); diff --git a/solution/1300-1399/1399.Count Largest Group/README_EN.md b/solution/1300-1399/1399.Count Largest Group/README_EN.md index 85c080c03609a..4b9c648f3b6a5 100644 --- a/solution/1300-1399/1399.Count Largest Group/README_EN.md +++ b/solution/1300-1399/1399.Count Largest Group/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n \times \log M)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def countLargestGroup(self, n: int) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countLargestGroup(int n) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func countLargestGroup(n int) (ans int) { cnt := [40]int{} @@ -156,6 +164,8 @@ func countLargestGroup(n int) (ans int) { } ``` +#### TypeScript + ```ts function countLargestGroup(n: number): number { const cnt: number[] = new Array(40).fill(0); diff --git a/solution/1400-1499/1400.Construct K Palindrome Strings/README.md b/solution/1400-1499/1400.Construct K Palindrome Strings/README.md index 1cd7d654dc1b0..b8ec712c5656a 100644 --- a/solution/1400-1499/1400.Construct K Palindrome Strings/README.md +++ b/solution/1400-1499/1400.Construct K Palindrome Strings/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class Solution: def canConstruct(self, s: str, k: int) -> bool: @@ -103,6 +105,8 @@ class Solution: return sum(v & 1 for v in cnt.values()) <= k ``` +#### Java + ```java class Solution { public boolean canConstruct(String s, int k) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func canConstruct(s string, k int) bool { if len(s) < k { @@ -160,6 +168,8 @@ func canConstruct(s string, k int) bool { } ``` +#### TypeScript + ```ts function canConstruct(s: string, k: number): boolean { if (s.length < k) { diff --git a/solution/1400-1499/1400.Construct K Palindrome Strings/README_EN.md b/solution/1400-1499/1400.Construct K Palindrome Strings/README_EN.md index b4ebafa6c218a..313d410c2b953 100644 --- a/solution/1400-1499/1400.Construct K Palindrome Strings/README_EN.md +++ b/solution/1400-1499/1400.Construct K Palindrome Strings/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(n)$, and the space complexity is $O(C)$. Where $n$ is +#### Python3 + ```python class Solution: def canConstruct(self, s: str, k: int) -> bool: @@ -83,6 +85,8 @@ class Solution: return sum(v & 1 for v in cnt.values()) <= k ``` +#### Java + ```java class Solution { public boolean canConstruct(String s, int k) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func canConstruct(s string, k int) bool { if len(s) < k { @@ -140,6 +148,8 @@ func canConstruct(s string, k int) bool { } ``` +#### TypeScript + ```ts function canConstruct(s: string, k: number): boolean { if (s.length < k) { diff --git a/solution/1400-1499/1401.Circle and Rectangle Overlapping/README.md b/solution/1400-1499/1401.Circle and Rectangle Overlapping/README.md index 235073be26b55..7123356c6c570 100644 --- a/solution/1400-1499/1401.Circle and Rectangle Overlapping/README.md +++ b/solution/1400-1499/1401.Circle and Rectangle Overlapping/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def checkOverlap( @@ -108,6 +110,8 @@ class Solution: return a * a + b * b <= radius * radius ``` +#### Java + ```java class Solution { public boolean checkOverlap( @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func checkOverlap(radius int, xCenter int, yCenter int, x1 int, y1 int, x2 int, y2 int) bool { f := func(i, j, k int) int { @@ -160,6 +168,8 @@ func checkOverlap(radius int, xCenter int, yCenter int, x1 int, y1 int, x2 int, } ``` +#### TypeScript + ```ts function checkOverlap( radius: number, diff --git a/solution/1400-1499/1401.Circle and Rectangle Overlapping/README_EN.md b/solution/1400-1499/1401.Circle and Rectangle Overlapping/README_EN.md index c41c14b4bb770..250062fe958d1 100644 --- a/solution/1400-1499/1401.Circle and Rectangle Overlapping/README_EN.md +++ b/solution/1400-1499/1401.Circle and Rectangle Overlapping/README_EN.md @@ -82,6 +82,8 @@ That is, $a = f(x_1, x_2, xCenter)$, $b = f(y_1, y_2, yCenter)$. If $a^2 + b^2 \ +#### Python3 + ```python class Solution: def checkOverlap( @@ -104,6 +106,8 @@ class Solution: return a * a + b * b <= radius * radius ``` +#### Java + ```java class Solution { public boolean checkOverlap( @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func checkOverlap(radius int, xCenter int, yCenter int, x1 int, y1 int, x2 int, y2 int) bool { f := func(i, j, k int) int { @@ -156,6 +164,8 @@ func checkOverlap(radius int, xCenter int, yCenter int, x1 int, y1 int, x2 int, } ``` +#### TypeScript + ```ts function checkOverlap( radius: number, diff --git a/solution/1400-1499/1402.Reducing Dishes/README.md b/solution/1400-1499/1402.Reducing Dishes/README.md index 4f24383eebdda..34600cef81b19 100644 --- a/solution/1400-1499/1402.Reducing Dishes/README.md +++ b/solution/1400-1499/1402.Reducing Dishes/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def maxSatisfaction(self, satisfaction: List[int]) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxSatisfaction(int[] satisfaction) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func maxSatisfaction(satisfaction []int) (ans int) { sort.Slice(satisfaction, func(i, j int) bool { return satisfaction[i] > satisfaction[j] }) @@ -147,6 +155,8 @@ func maxSatisfaction(satisfaction []int) (ans int) { } ``` +#### TypeScript + ```ts function maxSatisfaction(satisfaction: number[]): number { satisfaction.sort((a, b) => b - a); diff --git a/solution/1400-1499/1402.Reducing Dishes/README_EN.md b/solution/1400-1499/1402.Reducing Dishes/README_EN.md index 0e9fcddac880b..e08a3fcbd9b85 100644 --- a/solution/1400-1499/1402.Reducing Dishes/README_EN.md +++ b/solution/1400-1499/1402.Reducing Dishes/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def maxSatisfaction(self, satisfaction: List[int]) -> int: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxSatisfaction(int[] satisfaction) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func maxSatisfaction(satisfaction []int) (ans int) { sort.Slice(satisfaction, func(i, j int) bool { return satisfaction[i] > satisfaction[j] }) @@ -146,6 +154,8 @@ func maxSatisfaction(satisfaction []int) (ans int) { } ``` +#### TypeScript + ```ts function maxSatisfaction(satisfaction: number[]): number { satisfaction.sort((a, b) => b - a); diff --git a/solution/1400-1499/1403.Minimum Subsequence in Non-Increasing Order/README.md b/solution/1400-1499/1403.Minimum Subsequence in Non-Increasing Order/README.md index 1dd2d6bc0d5bd..996016ecc91b6 100644 --- a/solution/1400-1499/1403.Minimum Subsequence in Non-Increasing Order/README.md +++ b/solution/1400-1499/1403.Minimum Subsequence in Non-Increasing Order/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def minSubsequence(self, nums: List[int]) -> List[int]: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List minSubsequence(int[] nums) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func minSubsequence(nums []int) (ans []int) { sort.Ints(nums) @@ -138,6 +146,8 @@ func minSubsequence(nums []int) (ans []int) { } ``` +#### TypeScript + ```ts function minSubsequence(nums: number[]): number[] { nums.sort((a, b) => b - a); @@ -152,6 +162,8 @@ function minSubsequence(nums: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn min_subsequence(mut nums: Vec) -> Vec { diff --git a/solution/1400-1499/1403.Minimum Subsequence in Non-Increasing Order/README_EN.md b/solution/1400-1499/1403.Minimum Subsequence in Non-Increasing Order/README_EN.md index dee400d82b454..38372718807fb 100644 --- a/solution/1400-1499/1403.Minimum Subsequence in Non-Increasing Order/README_EN.md +++ b/solution/1400-1499/1403.Minimum Subsequence in Non-Increasing Order/README_EN.md @@ -65,6 +65,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def minSubsequence(self, nums: List[int]) -> List[int]: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List minSubsequence(int[] nums) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func minSubsequence(nums []int) (ans []int) { sort.Ints(nums) @@ -134,6 +142,8 @@ func minSubsequence(nums []int) (ans []int) { } ``` +#### TypeScript + ```ts function minSubsequence(nums: number[]): number[] { nums.sort((a, b) => b - a); @@ -148,6 +158,8 @@ function minSubsequence(nums: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn min_subsequence(mut nums: Vec) -> Vec { diff --git a/solution/1400-1499/1404.Number of Steps to Reduce a Number in Binary Representation to One/README.md b/solution/1400-1499/1404.Number of Steps to Reduce a Number in Binary Representation to One/README.md index 038643967457d..e4379933fe814 100644 --- a/solution/1400-1499/1404.Number of Steps to Reduce a Number in Binary Representation to One/README.md +++ b/solution/1400-1499/1404.Number of Steps to Reduce a Number in Binary Representation to One/README.md @@ -85,6 +85,8 @@ Step 1) 2 是偶数,除 2 得到 1 +#### Python3 + ```python class Solution: def numSteps(self, s: str) -> int: @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numSteps(String s) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func numSteps(s string) int { ans := 0 diff --git a/solution/1400-1499/1404.Number of Steps to Reduce a Number in Binary Representation to One/README_EN.md b/solution/1400-1499/1404.Number of Steps to Reduce a Number in Binary Representation to One/README_EN.md index b77d302b876e7..4b36cfced0979 100644 --- a/solution/1400-1499/1404.Number of Steps to Reduce a Number in Binary Representation to One/README_EN.md +++ b/solution/1400-1499/1404.Number of Steps to Reduce a Number in Binary Representation to One/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string $s$. The sp +#### Python3 + ```python class Solution: def numSteps(self, s: str) -> int: @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numSteps(String s) { @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func numSteps(s string) int { ans := 0 diff --git a/solution/1400-1499/1405.Longest Happy String/README.md b/solution/1400-1499/1405.Longest Happy String/README.md index acb9e3fe047a4..5f80fd4e3b5b3 100644 --- a/solution/1400-1499/1405.Longest Happy String/README.md +++ b/solution/1400-1499/1405.Longest Happy String/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def longestDiverseString(self, a: int, b: int, c: int) -> str: @@ -106,6 +108,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String longestDiverseString(int a, int b, int c) { @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go type pair struct { c byte @@ -241,6 +249,8 @@ func longestDiverseString(a int, b int, c int) string { } ``` +#### TypeScript + ```ts function longestDiverseString(a: number, b: number, c: number): string { let ans = []; diff --git a/solution/1400-1499/1405.Longest Happy String/README_EN.md b/solution/1400-1499/1405.Longest Happy String/README_EN.md index aa5f890f8a36a..bb953d2de5d13 100644 --- a/solution/1400-1499/1405.Longest Happy String/README_EN.md +++ b/solution/1400-1499/1405.Longest Happy String/README_EN.md @@ -71,6 +71,8 @@ The greedy strategy is to prioritize the selection of characters with the most r +#### Python3 + ```python class Solution: def longestDiverseString(self, a: int, b: int, c: int) -> str: @@ -103,6 +105,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String longestDiverseString(int a, int b, int c) { @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -185,6 +191,8 @@ public: }; ``` +#### Go + ```go type pair struct { c byte @@ -238,6 +246,8 @@ func longestDiverseString(a int, b int, c int) string { } ``` +#### TypeScript + ```ts function longestDiverseString(a: number, b: number, c: number): string { let ans = []; diff --git a/solution/1400-1499/1406.Stone Game III/README.md b/solution/1400-1499/1406.Stone Game III/README.md index e1f4c87fe37c2..13ab70a0bb769 100644 --- a/solution/1400-1499/1406.Stone Game III/README.md +++ b/solution/1400-1499/1406.Stone Game III/README.md @@ -95,6 +95,8 @@ $$ +#### Python3 + ```python class Solution: def stoneGameIII(self, stoneValue: List[int]) -> str: @@ -117,6 +119,8 @@ class Solution: return 'Alice' if ans > 0 else 'Bob' ``` +#### Java + ```java class Solution { private int[] stoneValue; @@ -152,6 +156,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -182,6 +188,8 @@ public: }; ``` +#### Go + ```go func stoneGameIII(stoneValue []int) string { n := len(stoneValue) @@ -217,6 +225,8 @@ func stoneGameIII(stoneValue []int) string { } ``` +#### TypeScript + ```ts function stoneGameIII(stoneValue: number[]): string { const n = stoneValue.length; diff --git a/solution/1400-1499/1406.Stone Game III/README_EN.md b/solution/1400-1499/1406.Stone Game III/README_EN.md index 99b834819222f..7b80ee92976e3 100644 --- a/solution/1400-1499/1406.Stone Game III/README_EN.md +++ b/solution/1400-1499/1406.Stone Game III/README_EN.md @@ -94,6 +94,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def stoneGameIII(self, stoneValue: List[int]) -> str: @@ -116,6 +118,8 @@ class Solution: return 'Alice' if ans > 0 else 'Bob' ``` +#### Java + ```java class Solution { private int[] stoneValue; @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func stoneGameIII(stoneValue []int) string { n := len(stoneValue) @@ -216,6 +224,8 @@ func stoneGameIII(stoneValue []int) string { } ``` +#### TypeScript + ```ts function stoneGameIII(stoneValue: number[]): string { const n = stoneValue.length; diff --git a/solution/1400-1499/1407.Top Travellers/README.md b/solution/1400-1499/1407.Top Travellers/README.md index 182a5d193f82c..6fa8be586e2d2 100644 --- a/solution/1400-1499/1407.Top Travellers/README.md +++ b/solution/1400-1499/1407.Top Travellers/README.md @@ -115,6 +115,8 @@ Donald 没有任何行程, 他的旅行距离为 0。 +#### MySQL + ```sql # Write your MySQL query statement below SELECT name, IFNULL(SUM(distance), 0) AS travelled_distance diff --git a/solution/1400-1499/1407.Top Travellers/README_EN.md b/solution/1400-1499/1407.Top Travellers/README_EN.md index d594d7a9ccf6b..a5808d4cdddcc 100644 --- a/solution/1400-1499/1407.Top Travellers/README_EN.md +++ b/solution/1400-1499/1407.Top Travellers/README_EN.md @@ -114,6 +114,8 @@ We can use a left join to join the `Users` table with the `Rides` table on the c +#### MySQL + ```sql # Write your MySQL query statement below SELECT name, IFNULL(SUM(distance), 0) AS travelled_distance diff --git a/solution/1400-1499/1408.String Matching in an Array/README.md b/solution/1400-1499/1408.String Matching in an Array/README.md index 1c72f381c0341..e241067294195 100644 --- a/solution/1400-1499/1408.String Matching in an Array/README.md +++ b/solution/1400-1499/1408.String Matching in an Array/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def stringMatching(self, words: List[str]) -> List[str]: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List stringMatching(String[] words) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func stringMatching(words []string) []string { ans := []string{} @@ -137,6 +145,8 @@ func stringMatching(words []string) []string { } ``` +#### TypeScript + ```ts function stringMatching(words: string[]): string[] { const ans: string[] = []; @@ -153,6 +163,8 @@ function stringMatching(words: string[]): string[] { } ``` +#### Rust + ```rust impl Solution { pub fn string_matching(words: Vec) -> Vec { diff --git a/solution/1400-1499/1408.String Matching in an Array/README_EN.md b/solution/1400-1499/1408.String Matching in an Array/README_EN.md index 639765835cea4..7704b5900b4b0 100644 --- a/solution/1400-1499/1408.String Matching in an Array/README_EN.md +++ b/solution/1400-1499/1408.String Matching in an Array/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(n^3)$, and the space complexity is $O(n)$. Where $n$ i +#### Python3 + ```python class Solution: def stringMatching(self, words: List[str]) -> List[str]: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List stringMatching(String[] words) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func stringMatching(words []string) []string { ans := []string{} @@ -136,6 +144,8 @@ func stringMatching(words []string) []string { } ``` +#### TypeScript + ```ts function stringMatching(words: string[]): string[] { const ans: string[] = []; @@ -152,6 +162,8 @@ function stringMatching(words: string[]): string[] { } ``` +#### Rust + ```rust impl Solution { pub fn string_matching(words: Vec) -> Vec { diff --git a/solution/1400-1499/1409.Queries on a Permutation With Key/README.md b/solution/1400-1499/1409.Queries on a Permutation With Key/README.md index 05538c58cf777..9469cb8a0e087 100644 --- a/solution/1400-1499/1409.Queries on a Permutation With Key/README.md +++ b/solution/1400-1499/1409.Queries on a Permutation With Key/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python class Solution: def processQueries(self, queries: List[int], m: int) -> List[int]: @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] processQueries(int[] queries, int m) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func processQueries(queries []int, m int) []int { p := make([]int, m) @@ -185,6 +193,8 @@ func processQueries(queries []int, m int) []int { +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -227,6 +237,8 @@ class Solution: return ans ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -282,6 +294,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -337,6 +351,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int diff --git a/solution/1400-1499/1409.Queries on a Permutation With Key/README_EN.md b/solution/1400-1499/1409.Queries on a Permutation With Key/README_EN.md index c621d499edf2f..d5dcef98d4e93 100644 --- a/solution/1400-1499/1409.Queries on a Permutation With Key/README_EN.md +++ b/solution/1400-1499/1409.Queries on a Permutation With Key/README_EN.md @@ -76,6 +76,8 @@ Therefore, the array containing the result is [2,1,2,1]. +#### Python3 + ```python class Solution: def processQueries(self, queries: List[int], m: int) -> List[int]: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] processQueries(int[] queries, int m) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func processQueries(queries []int, m int) []int { p := make([]int, m) @@ -166,6 +174,8 @@ func processQueries(queries []int, m int) []int { +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -208,6 +218,8 @@ class Solution: return ans ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -263,6 +275,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -318,6 +332,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int diff --git a/solution/1400-1499/1410.HTML Entity Parser/README.md b/solution/1400-1499/1410.HTML Entity Parser/README.md index 535f256d1adee..0afb5b9a3f866 100644 --- a/solution/1400-1499/1410.HTML Entity Parser/README.md +++ b/solution/1400-1499/1410.HTML Entity Parser/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python class Solution: def entityParser(self, text: str) -> str: @@ -121,6 +123,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String entityParser(String text) { @@ -157,6 +161,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -192,6 +198,8 @@ public: }; ``` +#### Go + ```go func entityParser(text string) string { d := map[string]string{ @@ -229,6 +237,8 @@ func entityParser(text string) string { } ``` +#### TypeScript + ```ts function entityParser(text: string): string { const d: Record = { @@ -278,6 +288,8 @@ function entityParser(text: string): string { +#### TypeScript + ```ts function entityParser(text: string): string { const d: { [key: string]: string } = { diff --git a/solution/1400-1499/1410.HTML Entity Parser/README_EN.md b/solution/1400-1499/1410.HTML Entity Parser/README_EN.md index d9bc8ac4cd75a..76753805d7f17 100644 --- a/solution/1400-1499/1410.HTML Entity Parser/README_EN.md +++ b/solution/1400-1499/1410.HTML Entity Parser/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(n \times l)$, and the space complexity is $O(l)$. Here +#### Python3 + ```python class Solution: def entityParser(self, text: str) -> str: @@ -100,6 +102,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String entityParser(String text) { @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func entityParser(text string) string { d := map[string]string{ @@ -208,6 +216,8 @@ func entityParser(text string) string { } ``` +#### TypeScript + ```ts function entityParser(text: string): string { const d: Record = { @@ -257,6 +267,8 @@ function entityParser(text: string): string { +#### TypeScript + ```ts function entityParser(text: string): string { const d: { [key: string]: string } = { diff --git "a/solution/1400-1499/1411.Number of Ways to Paint N \303\227 3 Grid/README.md" "b/solution/1400-1499/1411.Number of Ways to Paint N \303\227 3 Grid/README.md" index b4680712b2891..5b3261fb50fa9 100644 --- "a/solution/1400-1499/1411.Number of Ways to Paint N \303\227 3 Grid/README.md" +++ "b/solution/1400-1499/1411.Number of Ways to Paint N \303\227 3 Grid/README.md" @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def numOfWays(self, n: int) -> int: @@ -99,6 +101,8 @@ class Solution: return (f0 + f1) % mod ``` +#### Java + ```java class Solution { public int numOfWays(int n) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func numOfWays(n int) int { mod := int(1e9) + 7 @@ -148,6 +156,8 @@ func numOfWays(n int) int { } ``` +#### TypeScript + ```ts function numOfWays(n: number): number { const mod: number = 10 ** 9 + 7; @@ -191,6 +201,8 @@ $$ +#### Python3 + ```python class Solution: def numOfWays(self, n: int) -> int: @@ -229,6 +241,8 @@ class Solution: return sum(f) % mod ``` +#### Java + ```java class Solution { public int numOfWays(int n) { @@ -291,6 +305,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -354,6 +370,8 @@ public: }; ``` +#### Go + ```go func numOfWays(n int) (ans int) { f1 := func(x int) bool { @@ -411,6 +429,8 @@ func numOfWays(n int) (ans int) { } ``` +#### TypeScript + ```ts function numOfWays(n: number): number { const f1 = (x: number): boolean => { diff --git "a/solution/1400-1499/1411.Number of Ways to Paint N \303\227 3 Grid/README_EN.md" "b/solution/1400-1499/1411.Number of Ways to Paint N \303\227 3 Grid/README_EN.md" index c50ad18fd57a4..6470c015003ed 100644 --- "a/solution/1400-1499/1411.Number of Ways to Paint N \303\227 3 Grid/README_EN.md" +++ "b/solution/1400-1499/1411.Number of Ways to Paint N \303\227 3 Grid/README_EN.md" @@ -65,6 +65,8 @@ The time complexity is $O(n)$, where $n$ is the number of rows in the grid. The +#### Python3 + ```python class Solution: def numOfWays(self, n: int) -> int: @@ -77,6 +79,8 @@ class Solution: return (f0 + f1) % mod ``` +#### Java + ```java class Solution { public int numOfWays(int n) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func numOfWays(n int) int { mod := int(1e9) + 7 @@ -126,6 +134,8 @@ func numOfWays(n int) int { } ``` +#### TypeScript + ```ts function numOfWays(n: number): number { const mod: number = 10 ** 9 + 7; @@ -169,6 +179,8 @@ The time complexity is $O((m + n) \times 3^{2m})$, and the space complexity is $ +#### Python3 + ```python class Solution: def numOfWays(self, n: int) -> int: @@ -207,6 +219,8 @@ class Solution: return sum(f) % mod ``` +#### Java + ```java class Solution { public int numOfWays(int n) { @@ -269,6 +283,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -332,6 +348,8 @@ public: }; ``` +#### Go + ```go func numOfWays(n int) (ans int) { f1 := func(x int) bool { @@ -389,6 +407,8 @@ func numOfWays(n int) (ans int) { } ``` +#### TypeScript + ```ts function numOfWays(n: number): number { const f1 = (x: number): boolean => { diff --git a/solution/1400-1499/1412.Find the Quiet Students in All Exams/README.md b/solution/1400-1499/1412.Find the Quiet Students in All Exams/README.md index 8bb9ce3139d29..d1f73cc52b5a3 100644 --- a/solution/1400-1499/1412.Find the Quiet Students in All Exams/README.md +++ b/solution/1400-1499/1412.Find the Quiet Students in All Exams/README.md @@ -113,6 +113,8 @@ Exam 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1400-1499/1412.Find the Quiet Students in All Exams/README_EN.md b/solution/1400-1499/1412.Find the Quiet Students in All Exams/README_EN.md index 3395cdeff97dd..a4a1d7cc7a00c 100644 --- a/solution/1400-1499/1412.Find the Quiet Students in All Exams/README_EN.md +++ b/solution/1400-1499/1412.Find the Quiet Students in All Exams/README_EN.md @@ -113,6 +113,8 @@ Next, we can perform an inner join between the table $T$ and the table $Student$ +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1400-1499/1413.Minimum Value to Get Positive Step by Step Sum/README.md b/solution/1400-1499/1413.Minimum Value to Get Positive Step by Step Sum/README.md index 8d0137f96b177..f5c2ca9a7f9ce 100644 --- a/solution/1400-1499/1413.Minimum Value to Get Positive Step by Step Sum/README.md +++ b/solution/1400-1499/1413.Minimum Value to Get Positive Step by Step Sum/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def minStartValue(self, nums: List[int]) -> int: @@ -86,6 +88,8 @@ class Solution: return max(1, 1 - t) ``` +#### Java + ```java class Solution { public int minStartValue(int[] nums) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func minStartValue(nums []int) int { s, t := 0, 10000 @@ -130,6 +138,8 @@ func minStartValue(nums []int) int { } ``` +#### TypeScript + ```ts function minStartValue(nums: number[]): number { let sum = 0; @@ -142,6 +152,8 @@ function minStartValue(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_start_value(nums: Vec) -> i32 { @@ -166,6 +178,8 @@ impl Solution { +#### Python3 + ```python class Solution: def minStartValue(self, nums: List[int]) -> int: diff --git a/solution/1400-1499/1413.Minimum Value to Get Positive Step by Step Sum/README_EN.md b/solution/1400-1499/1413.Minimum Value to Get Positive Step by Step Sum/README_EN.md index 4e339d9cd71cf..6299ba6c0f77c 100644 --- a/solution/1400-1499/1413.Minimum Value to Get Positive Step by Step Sum/README_EN.md +++ b/solution/1400-1499/1413.Minimum Value to Get Positive Step by Step Sum/README_EN.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def minStartValue(self, nums: List[int]) -> int: @@ -84,6 +86,8 @@ class Solution: return max(1, 1 - t) ``` +#### Java + ```java class Solution { public int minStartValue(int[] nums) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func minStartValue(nums []int) int { s, t := 0, 10000 @@ -128,6 +136,8 @@ func minStartValue(nums []int) int { } ``` +#### TypeScript + ```ts function minStartValue(nums: number[]): number { let sum = 0; @@ -140,6 +150,8 @@ function minStartValue(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_start_value(nums: Vec) -> i32 { @@ -164,6 +176,8 @@ impl Solution { +#### Python3 + ```python class Solution: def minStartValue(self, nums: List[int]) -> int: diff --git a/solution/1400-1499/1414.Find the Minimum Number of Fibonacci Numbers Whose Sum Is K/README.md b/solution/1400-1499/1414.Find the Minimum Number of Fibonacci Numbers Whose Sum Is K/README.md index 8c111a644ac29..e315f883107e5 100644 --- a/solution/1400-1499/1414.Find the Minimum Number of Fibonacci Numbers Whose Sum Is K/README.md +++ b/solution/1400-1499/1414.Find the Minimum Number of Fibonacci Numbers Whose Sum Is K/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def findMinFibonacciNumbers(self, k: int) -> int: @@ -86,6 +88,8 @@ class Solution: return dfs(k) ``` +#### Java + ```java class Solution { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func findMinFibonacciNumbers(k int) int { if k < 2 { @@ -131,6 +139,8 @@ func findMinFibonacciNumbers(k int) int { } ``` +#### TypeScript + ```ts const arr = [ 1836311903, 1134903170, 701408733, 433494437, 267914296, 165580141, 102334155, 63245986, @@ -154,6 +164,8 @@ function findMinFibonacciNumbers(k: number): number { } ``` +#### Rust + ```rust const FIB: [i32; 45] = [ 1836311903, 1134903170, 701408733, 433494437, 267914296, 165580141, 102334155, 63245986, diff --git a/solution/1400-1499/1414.Find the Minimum Number of Fibonacci Numbers Whose Sum Is K/README_EN.md b/solution/1400-1499/1414.Find the Minimum Number of Fibonacci Numbers Whose Sum Is K/README_EN.md index ca49f315d8152..cb834d3147016 100644 --- a/solution/1400-1499/1414.Find the Minimum Number of Fibonacci Numbers Whose Sum Is K/README_EN.md +++ b/solution/1400-1499/1414.Find the Minimum Number of Fibonacci Numbers Whose Sum Is K/README_EN.md @@ -71,6 +71,8 @@ For k = 7 we can use 2 + 5 = 7. +#### Python3 + ```python class Solution: def findMinFibonacciNumbers(self, k: int) -> int: @@ -85,6 +87,8 @@ class Solution: return dfs(k) ``` +#### Java + ```java class Solution { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func findMinFibonacciNumbers(k int) int { if k < 2 { @@ -130,6 +138,8 @@ func findMinFibonacciNumbers(k int) int { } ``` +#### TypeScript + ```ts const arr = [ 1836311903, 1134903170, 701408733, 433494437, 267914296, 165580141, 102334155, 63245986, @@ -153,6 +163,8 @@ function findMinFibonacciNumbers(k: number): number { } ``` +#### Rust + ```rust const FIB: [i32; 45] = [ 1836311903, 1134903170, 701408733, 433494437, 267914296, 165580141, 102334155, 63245986, diff --git a/solution/1400-1499/1415.The k-th Lexicographical String of All Happy Strings of Length n/README.md b/solution/1400-1499/1415.The k-th Lexicographical String of All Happy Strings of Length n/README.md index 9a7d4631591e5..4c5f66ab3b634 100644 --- a/solution/1400-1499/1415.The k-th Lexicographical String of All Happy Strings of Length n/README.md +++ b/solution/1400-1499/1415.The k-th Lexicographical String of All Happy Strings of Length n/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def getHappyString(self, n: int, k: int) -> str: @@ -105,6 +107,8 @@ class Solution: return '' if len(ans) < k else ans[k - 1] ``` +#### Java + ```java class Solution { private List ans = new ArrayList<>(); @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/1400-1499/1415.The k-th Lexicographical String of All Happy Strings of Length n/README_EN.md b/solution/1400-1499/1415.The k-th Lexicographical String of All Happy Strings of Length n/README_EN.md index be7a228e4b20a..058a45cf2e8bf 100644 --- a/solution/1400-1499/1415.The k-th Lexicographical String of All Happy Strings of Length n/README_EN.md +++ b/solution/1400-1499/1415.The k-th Lexicographical String of All Happy Strings of Length n/README_EN.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def getHappyString(self, n: int, k: int) -> str: @@ -92,6 +94,8 @@ class Solution: return '' if len(ans) < k else ans[k - 1] ``` +#### Java + ```java class Solution { private List ans = new ArrayList<>(); @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/1400-1499/1416.Restore The Array/README.md b/solution/1400-1499/1416.Restore The Array/README.md index 2b08dfc7ce535..f46a42c66ef65 100644 --- a/solution/1400-1499/1416.Restore The Array/README.md +++ b/solution/1400-1499/1416.Restore The Array/README.md @@ -83,18 +83,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1400-1499/1416.Restore The Array/README_EN.md b/solution/1400-1499/1416.Restore The Array/README_EN.md index 45f47ce29f32b..2ead3293057d6 100644 --- a/solution/1400-1499/1416.Restore The Array/README_EN.md +++ b/solution/1400-1499/1416.Restore The Array/README_EN.md @@ -67,18 +67,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1400-1499/1417.Reformat The String/README.md b/solution/1400-1499/1417.Reformat The String/README.md index 4adefe96b4909..e63c0337bab68 100644 --- a/solution/1400-1499/1417.Reformat The String/README.md +++ b/solution/1400-1499/1417.Reformat The String/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def reformat(self, s: str) -> str: @@ -103,6 +105,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String reformat(String s) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go func reformat(s string) string { a := []byte{} diff --git a/solution/1400-1499/1417.Reformat The String/README_EN.md b/solution/1400-1499/1417.Reformat The String/README_EN.md index bb83709f3a451..bd9c918e25d83 100644 --- a/solution/1400-1499/1417.Reformat The String/README_EN.md +++ b/solution/1400-1499/1417.Reformat The String/README_EN.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def reformat(self, s: str) -> str: @@ -84,6 +86,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String reformat(String s) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func reformat(s string) string { a := []byte{} diff --git a/solution/1400-1499/1418.Display Table of Food Orders in a Restaurant/README.md b/solution/1400-1499/1418.Display Table of Food Orders in a Restaurant/README.md index e26c84d340123..e35ca074730dc 100644 --- a/solution/1400-1499/1418.Display Table of Food Orders in a Restaurant/README.md +++ b/solution/1400-1499/1418.Display Table of Food Orders in a Restaurant/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def displayTable(self, orders: List[List[str]]) -> List[List[str]]: @@ -103,6 +105,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public List> displayTable(List> orders) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go func displayTable(orders [][]string) [][]string { tables := make(map[int]bool) diff --git a/solution/1400-1499/1418.Display Table of Food Orders in a Restaurant/README_EN.md b/solution/1400-1499/1418.Display Table of Food Orders in a Restaurant/README_EN.md index 97493b6669f01..79d27902b765f 100644 --- a/solution/1400-1499/1418.Display Table of Food Orders in a Restaurant/README_EN.md +++ b/solution/1400-1499/1418.Display Table of Food Orders in a Restaurant/README_EN.md @@ -110,6 +110,8 @@ For the table 12: James, Ratesh and Amadeus order "Fried Chicken". +#### Python3 + ```python class Solution: def displayTable(self, orders: List[List[str]]) -> List[List[str]]: @@ -131,6 +133,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public List> displayTable(List> orders) { @@ -167,6 +171,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -205,6 +211,8 @@ public: }; ``` +#### Go + ```go func displayTable(orders [][]string) [][]string { tables := make(map[int]bool) diff --git a/solution/1400-1499/1419.Minimum Number of Frogs Croaking/README.md b/solution/1400-1499/1419.Minimum Number of Frogs Croaking/README.md index 73c33e298b58f..1ca087dba13f9 100644 --- a/solution/1400-1499/1419.Minimum Number of Frogs Croaking/README.md +++ b/solution/1400-1499/1419.Minimum Number of Frogs Croaking/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def minNumberOfFrogs(self, croakOfFrogs: str) -> int: @@ -107,6 +109,8 @@ class Solution: return -1 if x else ans ``` +#### Java + ```java class Solution { public int minNumberOfFrogs(String croakOfFrogs) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func minNumberOfFrogs(croakOfFrogs string) int { n := len(croakOfFrogs) @@ -209,6 +217,8 @@ func minNumberOfFrogs(croakOfFrogs string) int { } ``` +#### TypeScript + ```ts function minNumberOfFrogs(croakOfFrogs: string): number { const n = croakOfFrogs.length; diff --git a/solution/1400-1499/1419.Minimum Number of Frogs Croaking/README_EN.md b/solution/1400-1499/1419.Minimum Number of Frogs Croaking/README_EN.md index 68dca322d3c86..cf174503c6e49 100644 --- a/solution/1400-1499/1419.Minimum Number of Frogs Croaking/README_EN.md +++ b/solution/1400-1499/1419.Minimum Number of Frogs Croaking/README_EN.md @@ -70,6 +70,8 @@ The second frog could yell later "crcoakroak +#### Python3 + ```python class Solution: def minNumberOfFrogs(self, croakOfFrogs: str) -> int: @@ -92,6 +94,8 @@ class Solution: return -1 if x else ans ``` +#### Java + ```java class Solution { public int minNumberOfFrogs(String croakOfFrogs) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func minNumberOfFrogs(croakOfFrogs string) int { n := len(croakOfFrogs) @@ -194,6 +202,8 @@ func minNumberOfFrogs(croakOfFrogs string) int { } ``` +#### TypeScript + ```ts function minNumberOfFrogs(croakOfFrogs: string): number { const n = croakOfFrogs.length; diff --git a/solution/1400-1499/1420.Build Array Where You Can Find The Maximum Exactly K Comparisons/README.md b/solution/1400-1499/1420.Build Array Where You Can Find The Maximum Exactly K Comparisons/README.md index 3d3717545c6e8..b4e49a6530005 100644 --- a/solution/1400-1499/1420.Build Array Where You Can Find The Maximum Exactly K Comparisons/README.md +++ b/solution/1400-1499/1420.Build Array Where You Can Find The Maximum Exactly K Comparisons/README.md @@ -107,6 +107,8 @@ $$ +#### Python3 + ```python class Solution: def numOfArrays(self, n: int, m: int, k: int) -> int: @@ -130,6 +132,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -161,6 +165,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -187,6 +193,8 @@ public: }; ``` +#### Go + ```go func numOfArrays(n int, m int, k int) int { if k == 0 { diff --git a/solution/1400-1499/1420.Build Array Where You Can Find The Maximum Exactly K Comparisons/README_EN.md b/solution/1400-1499/1420.Build Array Where You Can Find The Maximum Exactly K Comparisons/README_EN.md index 1b4b598e00527..a73b1272e1eb0 100644 --- a/solution/1400-1499/1420.Build Array Where You Can Find The Maximum Exactly K Comparisons/README_EN.md +++ b/solution/1400-1499/1420.Build Array Where You Can Find The Maximum Exactly K Comparisons/README_EN.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def numOfArrays(self, n: int, m: int, k: int) -> int: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func numOfArrays(n int, m int, k int) int { if k == 0 { diff --git a/solution/1400-1499/1421.NPV Queries/README.md b/solution/1400-1499/1421.NPV Queries/README.md index bec2179090a2d..f37d0532a27d3 100644 --- a/solution/1400-1499/1421.NPV Queries/README.md +++ b/solution/1400-1499/1421.NPV Queries/README.md @@ -112,6 +112,8 @@ Queries 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT q.*, IFNULL(npv, 0) AS npv diff --git a/solution/1400-1499/1421.NPV Queries/README_EN.md b/solution/1400-1499/1421.NPV Queries/README_EN.md index b4b5ee7c93785..f3964db572970 100644 --- a/solution/1400-1499/1421.NPV Queries/README_EN.md +++ b/solution/1400-1499/1421.NPV Queries/README_EN.md @@ -110,6 +110,8 @@ The npv values of all other queries can be found in the NPV table. +#### MySQL + ```sql # Write your MySQL query statement below SELECT q.*, IFNULL(npv, 0) AS npv diff --git a/solution/1400-1499/1422.Maximum Score After Splitting a String/README.md b/solution/1400-1499/1422.Maximum Score After Splitting a String/README.md index ccf4de7d48eaf..3bbc25b38b792 100644 --- a/solution/1400-1499/1422.Maximum Score After Splitting a String/README.md +++ b/solution/1400-1499/1422.Maximum Score After Splitting a String/README.md @@ -70,12 +70,16 @@ tags: +#### Python3 + ```python class Solution: def maxScore(self, s: str) -> int: return max(s[:i].count('0') + s[i:].count('1') for i in range(1, len(s))) ``` +#### Java + ```java class Solution { public int maxScore(String s) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func maxScore(s string) int { ans := 0 @@ -140,6 +148,8 @@ func maxScore(s string) int { } ``` +#### TypeScript + ```ts function maxScore(s: string): number { const n = s.length; @@ -166,6 +176,8 @@ function maxScore(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_score(s: String) -> i32 { @@ -205,6 +217,8 @@ impl Solution { +#### Python3 + ```python class Solution: def maxScore(self, s: str) -> int: @@ -215,6 +229,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxScore(String s) { @@ -237,6 +253,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -254,6 +272,8 @@ public: }; ``` +#### Go + ```go func maxScore(s string) int { t := 0 diff --git a/solution/1400-1499/1422.Maximum Score After Splitting a String/README_EN.md b/solution/1400-1499/1422.Maximum Score After Splitting a String/README_EN.md index f2227a8af1c2c..835d2d1d96eda 100644 --- a/solution/1400-1499/1422.Maximum Score After Splitting a String/README_EN.md +++ b/solution/1400-1499/1422.Maximum Score After Splitting a String/README_EN.md @@ -71,12 +71,16 @@ left = "01110" and right = "1", score = 2 + 1 = 3 +#### Python3 + ```python class Solution: def maxScore(self, s: str) -> int: return max(s[:i].count('0') + s[i:].count('1') for i in range(1, len(s))) ``` +#### Java + ```java class Solution { public int maxScore(String s) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func maxScore(s string) int { ans := 0 @@ -141,6 +149,8 @@ func maxScore(s string) int { } ``` +#### TypeScript + ```ts function maxScore(s: string): number { const n = s.length; @@ -167,6 +177,8 @@ function maxScore(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_score(s: String) -> i32 { @@ -206,6 +218,8 @@ impl Solution { +#### Python3 + ```python class Solution: def maxScore(self, s: str) -> int: @@ -216,6 +230,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxScore(String s) { @@ -238,6 +254,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -255,6 +273,8 @@ public: }; ``` +#### Go + ```go func maxScore(s string) int { t := 0 diff --git a/solution/1400-1499/1423.Maximum Points You Can Obtain from Cards/README.md b/solution/1400-1499/1423.Maximum Points You Can Obtain from Cards/README.md index 110008fc1c342..2fe8a31ec7f9b 100644 --- a/solution/1400-1499/1423.Maximum Points You Can Obtain from Cards/README.md +++ b/solution/1400-1499/1423.Maximum Points You Can Obtain from Cards/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def maxScore(self, cardPoints: List[int], k: int) -> int: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxScore(int[] cardPoints, int k) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func maxScore(cardPoints []int, k int) int { n := len(cardPoints) @@ -151,6 +159,8 @@ func maxScore(cardPoints []int, k int) int { } ``` +#### TypeScript + ```ts function maxScore(cardPoints: number[], k: number): number { const n = cardPoints.length; @@ -164,6 +174,8 @@ function maxScore(cardPoints: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_score(card_points: Vec, k: i32) -> i32 { @@ -180,6 +192,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} cardPoints @@ -198,6 +212,8 @@ var maxScore = function (cardPoints, k) { }; ``` +#### C# + ```cs public class Solution { public int MaxScore(int[] cardPoints, int k) { @@ -213,6 +229,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** @@ -233,6 +251,8 @@ class Solution { } ``` +#### Scala + ```scala object Solution { def maxScore(cardPoints: Array[Int], k: Int): Int = { @@ -248,6 +268,8 @@ object Solution { } ``` +#### Swift + ```swift class Solution { func maxScore(_ cardPoints: [Int], _ k: Int) -> Int { @@ -263,6 +285,8 @@ class Solution { } ``` +#### Ruby + ```rb # @param {Integer[]} card_points # @param {Integer} k @@ -279,6 +303,8 @@ def max_score(card_points, k) end ``` +#### Kotlin + ```kotlin class Solution { fun maxScore(cardPoints: IntArray, k: Int): Int { @@ -294,6 +320,8 @@ class Solution { } ``` +#### Dart + ```dart class Solution { int maxScore(List cardPoints, int k) { diff --git a/solution/1400-1499/1423.Maximum Points You Can Obtain from Cards/README_EN.md b/solution/1400-1499/1423.Maximum Points You Can Obtain from Cards/README_EN.md index 82c9ea34489b8..3874ca803bb60 100644 --- a/solution/1400-1499/1423.Maximum Points You Can Obtain from Cards/README_EN.md +++ b/solution/1400-1499/1423.Maximum Points You Can Obtain from Cards/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(k)$, where $k$ is the integer given in the problem. Th +#### Python3 + ```python class Solution: def maxScore(self, cardPoints: List[int], k: int) -> int: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxScore(int[] cardPoints, int k) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func maxScore(cardPoints []int, k int) int { n := len(cardPoints) @@ -139,6 +147,8 @@ func maxScore(cardPoints []int, k int) int { } ``` +#### TypeScript + ```ts function maxScore(cardPoints: number[], k: number): number { const n = cardPoints.length; @@ -152,6 +162,8 @@ function maxScore(cardPoints: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_score(card_points: Vec, k: i32) -> i32 { @@ -168,6 +180,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} cardPoints @@ -186,6 +200,8 @@ var maxScore = function (cardPoints, k) { }; ``` +#### C# + ```cs public class Solution { public int MaxScore(int[] cardPoints, int k) { @@ -201,6 +217,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** @@ -221,6 +239,8 @@ class Solution { } ``` +#### Scala + ```scala object Solution { def maxScore(cardPoints: Array[Int], k: Int): Int = { @@ -236,6 +256,8 @@ object Solution { } ``` +#### Swift + ```swift class Solution { func maxScore(_ cardPoints: [Int], _ k: Int) -> Int { @@ -251,6 +273,8 @@ class Solution { } ``` +#### Ruby + ```rb # @param {Integer[]} card_points # @param {Integer} k @@ -267,6 +291,8 @@ def max_score(card_points, k) end ``` +#### Kotlin + ```kotlin class Solution { fun maxScore(cardPoints: IntArray, k: Int): Int { @@ -282,6 +308,8 @@ class Solution { } ``` +#### Dart + ```dart class Solution { int maxScore(List cardPoints, int k) { diff --git a/solution/1400-1499/1424.Diagonal Traverse II/README.md b/solution/1400-1499/1424.Diagonal Traverse II/README.md index ee906378e13b6..48385ce570025 100644 --- a/solution/1400-1499/1424.Diagonal Traverse II/README.md +++ b/solution/1400-1499/1424.Diagonal Traverse II/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def findDiagonalOrder(self, nums: List[List[int]]) -> List[int]: @@ -94,6 +96,8 @@ class Solution: return [v[2] for v in arr] ``` +#### Java + ```java class Solution { public int[] findDiagonalOrder(List> nums) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func findDiagonalOrder(nums [][]int) []int { arr := [][]int{} @@ -155,6 +163,8 @@ func findDiagonalOrder(nums [][]int) []int { } ``` +#### C# + ```cs public class Solution { public int[] FindDiagonalOrder(IList> nums) { diff --git a/solution/1400-1499/1424.Diagonal Traverse II/README_EN.md b/solution/1400-1499/1424.Diagonal Traverse II/README_EN.md index d6eafcc33c0b1..d3001f93376b6 100644 --- a/solution/1400-1499/1424.Diagonal Traverse II/README_EN.md +++ b/solution/1400-1499/1424.Diagonal Traverse II/README_EN.md @@ -57,6 +57,8 @@ tags: +#### Python3 + ```python class Solution: def findDiagonalOrder(self, nums: List[List[int]]) -> List[int]: @@ -68,6 +70,8 @@ class Solution: return [v[2] for v in arr] ``` +#### Java + ```java class Solution { public int[] findDiagonalOrder(List> nums) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func findDiagonalOrder(nums [][]int) []int { arr := [][]int{} @@ -129,6 +137,8 @@ func findDiagonalOrder(nums [][]int) []int { } ``` +#### C# + ```cs public class Solution { public int[] FindDiagonalOrder(IList> nums) { diff --git a/solution/1400-1499/1425.Constrained Subsequence Sum/README.md b/solution/1400-1499/1425.Constrained Subsequence Sum/README.md index eeae31293d750..f96e8760a7d7c 100644 --- a/solution/1400-1499/1425.Constrained Subsequence Sum/README.md +++ b/solution/1400-1499/1425.Constrained Subsequence Sum/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def constrainedSubsetSum(self, nums: List[int], k: int) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int constrainedSubsetSum(int[] nums, int k) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func constrainedSubsetSum(nums []int, k int) int { n := len(nums) diff --git a/solution/1400-1499/1425.Constrained Subsequence Sum/README_EN.md b/solution/1400-1499/1425.Constrained Subsequence Sum/README_EN.md index c5f486747e04b..ba1cc253f1591 100644 --- a/solution/1400-1499/1425.Constrained Subsequence Sum/README_EN.md +++ b/solution/1400-1499/1425.Constrained Subsequence Sum/README_EN.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def constrainedSubsetSum(self, nums: List[int], k: int) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int constrainedSubsetSum(int[] nums, int k) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func constrainedSubsetSum(nums []int, k int) int { n := len(nums) diff --git a/solution/1400-1499/1426.Counting Elements/README.md b/solution/1400-1499/1426.Counting Elements/README.md index 4d1173feb2d22..70a64e2623102 100644 --- a/solution/1400-1499/1426.Counting Elements/README.md +++ b/solution/1400-1499/1426.Counting Elements/README.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def countElements(self, arr: List[int]) -> int: @@ -68,6 +70,8 @@ class Solution: return sum(v for x, v in cnt.items() if cnt[x + 1]) ``` +#### Java + ```java class Solution { public int countElements(int[] arr) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func countElements(arr []int) (ans int) { mx := slices.Max(arr) @@ -121,6 +129,8 @@ func countElements(arr []int) (ans int) { } ``` +#### TypeScript + ```ts function countElements(arr: number[]): number { const mx = Math.max(...arr); @@ -138,6 +148,8 @@ function countElements(arr: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -155,6 +167,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} arr @@ -176,6 +190,8 @@ var countElements = function (arr) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1400-1499/1426.Counting Elements/README_EN.md b/solution/1400-1499/1426.Counting Elements/README_EN.md index 15c7f1f791e20..f9e0a2ca5e8de 100644 --- a/solution/1400-1499/1426.Counting Elements/README_EN.md +++ b/solution/1400-1499/1426.Counting Elements/README_EN.md @@ -58,6 +58,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def countElements(self, arr: List[int]) -> int: @@ -65,6 +67,8 @@ class Solution: return sum(v for x, v in cnt.items() if cnt[x + 1]) ``` +#### Java + ```java class Solution { public int countElements(int[] arr) { @@ -83,6 +87,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -102,6 +108,8 @@ public: }; ``` +#### Go + ```go func countElements(arr []int) (ans int) { mx := slices.Max(arr) @@ -118,6 +126,8 @@ func countElements(arr []int) (ans int) { } ``` +#### TypeScript + ```ts function countElements(arr: number[]): number { const mx = Math.max(...arr); @@ -135,6 +145,8 @@ function countElements(arr: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -152,6 +164,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} arr @@ -173,6 +187,8 @@ var countElements = function (arr) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1400-1499/1427.Perform String Shifts/README.md b/solution/1400-1499/1427.Perform String Shifts/README.md index a20ca4ad3e78f..731108edfe5f0 100644 --- a/solution/1400-1499/1427.Perform String Shifts/README.md +++ b/solution/1400-1499/1427.Perform String Shifts/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def stringShift(self, s: str, shift: List[List[int]]) -> str: @@ -86,6 +88,8 @@ class Solution: return s[-x:] + s[:-x] ``` +#### Java + ```java class Solution { public String stringShift(String s, int[][] shift) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func stringShift(s string, shift [][]int) string { x := 0 @@ -136,6 +144,8 @@ func stringShift(s string, shift [][]int) string { } ``` +#### TypeScript + ```ts function stringShift(s: string, shift: number[][]): string { let x = 0; diff --git a/solution/1400-1499/1427.Perform String Shifts/README_EN.md b/solution/1400-1499/1427.Perform String Shifts/README_EN.md index 9ae92860f0418..4335f544716db 100644 --- a/solution/1400-1499/1427.Perform String Shifts/README_EN.md +++ b/solution/1400-1499/1427.Perform String Shifts/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(n + m)$, where $n$ and $m$ are the lengths of the stri +#### Python3 + ```python class Solution: def stringShift(self, s: str, shift: List[List[int]]) -> str: @@ -84,6 +86,8 @@ class Solution: return s[-x:] + s[:-x] ``` +#### Java + ```java class Solution { public String stringShift(String s, int[][] shift) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func stringShift(s string, shift [][]int) string { x := 0 @@ -134,6 +142,8 @@ func stringShift(s string, shift [][]int) string { } ``` +#### TypeScript + ```ts function stringShift(s: string, shift: number[][]): string { let x = 0; diff --git a/solution/1400-1499/1428.Leftmost Column with at Least a One/README.md b/solution/1400-1499/1428.Leftmost Column with at Least a One/README.md index f8372b97ded28..328f7245f67e7 100644 --- a/solution/1400-1499/1428.Leftmost Column with at Least a One/README.md +++ b/solution/1400-1499/1428.Leftmost Column with at Least a One/README.md @@ -99,6 +99,8 @@ tags: +#### Python3 + ```python # """ # This is BinaryMatrix's API interface. @@ -119,6 +121,8 @@ class Solution: return -1 if ans >= n else ans ``` +#### Java + ```java /** * // This is the BinaryMatrix's API interface. @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * // This is the BinaryMatrix's API interface. @@ -185,6 +191,8 @@ public: }; ``` +#### Go + ```go /** * // This is the BinaryMatrix's API interface. @@ -218,6 +226,8 @@ func leftMostColumnWithOne(binaryMatrix BinaryMatrix) int { } ``` +#### TypeScript + ```ts /** * // This is the BinaryMatrix's API interface. @@ -248,6 +258,8 @@ function leftMostColumnWithOne(binaryMatrix: BinaryMatrix) { } ``` +#### Rust + ```rust /** @@ -289,6 +301,8 @@ impl Solution { } ``` +#### C# + ```cs /** * // This is BinaryMatrix's API interface. diff --git a/solution/1400-1499/1428.Leftmost Column with at Least a One/README_EN.md b/solution/1400-1499/1428.Leftmost Column with at Least a One/README_EN.md index 5ad4aef58eabc..be162687c67f4 100644 --- a/solution/1400-1499/1428.Leftmost Column with at Least a One/README_EN.md +++ b/solution/1400-1499/1428.Leftmost Column with at Least a One/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(m \times \log n)$, where $m$ and $n$ are the number of +#### Python3 + ```python # """ # This is BinaryMatrix's API interface. @@ -101,6 +103,8 @@ class Solution: return -1 if ans >= n else ans ``` +#### Java + ```java /** * // This is the BinaryMatrix's API interface. @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * // This is the BinaryMatrix's API interface. @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go /** * // This is the BinaryMatrix's API interface. @@ -200,6 +208,8 @@ func leftMostColumnWithOne(binaryMatrix BinaryMatrix) int { } ``` +#### TypeScript + ```ts /** * // This is the BinaryMatrix's API interface. @@ -230,6 +240,8 @@ function leftMostColumnWithOne(binaryMatrix: BinaryMatrix) { } ``` +#### Rust + ```rust /** * // This is the BinaryMatrix's API interface. @@ -270,6 +282,8 @@ impl Solution { } ``` +#### C# + ```cs /** * // This is BinaryMatrix's API interface. diff --git a/solution/1400-1499/1429.First Unique Number/README.md b/solution/1400-1499/1429.First Unique Number/README.md index ba2452dd607bf..24d69a6935cb6 100644 --- a/solution/1400-1499/1429.First Unique Number/README.md +++ b/solution/1400-1499/1429.First Unique Number/README.md @@ -114,6 +114,8 @@ firstUnique.showFirstUnique(); // 返回 -1 +#### Python3 + ```python class FirstUnique: def __init__(self, nums: List[int]): @@ -137,6 +139,8 @@ class FirstUnique: # obj.add(value) ``` +#### Java + ```java class FirstUnique { private Map cnt = new HashMap<>(); @@ -175,6 +179,8 @@ class FirstUnique { */ ``` +#### C++ + ```cpp class FirstUnique { public: @@ -208,6 +214,8 @@ private: */ ``` +#### Go + ```go type FirstUnique struct { cnt map[int]int @@ -255,6 +263,8 @@ func (this *FirstUnique) Add(value int) { +#### Python3 + ```python class FirstUnique: def __init__(self, nums: List[int]): @@ -277,6 +287,8 @@ class FirstUnique: # obj.add(value) ``` +#### Java + ```java class FirstUnique { private Map cnt = new HashMap<>(); diff --git a/solution/1400-1499/1429.First Unique Number/README_EN.md b/solution/1400-1499/1429.First Unique Number/README_EN.md index 96cb9727818b9..47d24f92baeb2 100644 --- a/solution/1400-1499/1429.First Unique Number/README_EN.md +++ b/solution/1400-1499/1429.First Unique Number/README_EN.md @@ -104,6 +104,8 @@ firstUnique.showFirstUnique(); // return -1 +#### Python3 + ```python class FirstUnique: def __init__(self, nums: List[int]): @@ -127,6 +129,8 @@ class FirstUnique: # obj.add(value) ``` +#### Java + ```java class FirstUnique { private Map cnt = new HashMap<>(); @@ -165,6 +169,8 @@ class FirstUnique { */ ``` +#### C++ + ```cpp class FirstUnique { public: @@ -198,6 +204,8 @@ private: */ ``` +#### Go + ```go type FirstUnique struct { cnt map[int]int @@ -245,6 +253,8 @@ func (this *FirstUnique) Add(value int) { +#### Python3 + ```python class FirstUnique: def __init__(self, nums: List[int]): @@ -267,6 +277,8 @@ class FirstUnique: # obj.add(value) ``` +#### Java + ```java class FirstUnique { private Map cnt = new HashMap<>(); diff --git a/solution/1400-1499/1430.Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree/README.md b/solution/1400-1499/1430.Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree/README.md index 7d3af7ff9cf4e..191879bbb826c 100644 --- a/solution/1400-1499/1430.Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree/README.md +++ b/solution/1400-1499/1430.Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -104,6 +106,8 @@ class Solution: return dfs(root, 0) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/1400-1499/1430.Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree/README_EN.md b/solution/1400-1499/1430.Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree/README_EN.md index e06ae78906bf6..c2f6ae3f29095 100644 --- a/solution/1400-1499/1430.Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree/README_EN.md +++ b/solution/1400-1499/1430.Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree/README_EN.md @@ -77,6 +77,8 @@ Other valid sequences are: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -96,6 +98,8 @@ class Solution: return dfs(root, 0) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/1400-1499/1431.Kids With the Greatest Number of Candies/README.md b/solution/1400-1499/1431.Kids With the Greatest Number of Candies/README.md index 681f0f26a07d8..188bd54693edf 100644 --- a/solution/1400-1499/1431.Kids With the Greatest Number of Candies/README.md +++ b/solution/1400-1499/1431.Kids With the Greatest Number of Candies/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]: @@ -76,6 +78,8 @@ class Solution: return [candy + extraCandies >= mx for candy in candies] ``` +#### Java + ```java class Solution { public List kidsWithCandies(int[] candies, int extraCandies) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func kidsWithCandies(candies []int, extraCandies int) (ans []bool) { mx := slices.Max(candies) @@ -116,6 +124,8 @@ func kidsWithCandies(candies []int, extraCandies int) (ans []bool) { } ``` +#### TypeScript + ```ts function kidsWithCandies(candies: number[], extraCandies: number): boolean[] { const max = candies.reduce((r, v) => Math.max(r, v)); @@ -123,6 +133,8 @@ function kidsWithCandies(candies: number[], extraCandies: number): boolean[] { } ``` +#### Rust + ```rust impl Solution { pub fn kids_with_candies(candies: Vec, extra_candies: i32) -> Vec { @@ -135,6 +147,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** @@ -153,6 +167,8 @@ class Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) /** diff --git a/solution/1400-1499/1431.Kids With the Greatest Number of Candies/README_EN.md b/solution/1400-1499/1431.Kids With the Greatest Number of Candies/README_EN.md index fc4211beffae7..26a6839370622 100644 --- a/solution/1400-1499/1431.Kids With the Greatest Number of Candies/README_EN.md +++ b/solution/1400-1499/1431.Kids With the Greatest Number of Candies/README_EN.md @@ -74,6 +74,8 @@ Kid 1 will always have the greatest number of candies, even if a different kid i +#### Python3 + ```python class Solution: def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]: @@ -81,6 +83,8 @@ class Solution: return [candy + extraCandies >= mx for candy in candies] ``` +#### Java + ```java class Solution { public List kidsWithCandies(int[] candies, int extraCandies) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func kidsWithCandies(candies []int, extraCandies int) (ans []bool) { mx := slices.Max(candies) @@ -121,6 +129,8 @@ func kidsWithCandies(candies []int, extraCandies int) (ans []bool) { } ``` +#### TypeScript + ```ts function kidsWithCandies(candies: number[], extraCandies: number): boolean[] { const max = candies.reduce((r, v) => Math.max(r, v)); @@ -128,6 +138,8 @@ function kidsWithCandies(candies: number[], extraCandies: number): boolean[] { } ``` +#### Rust + ```rust impl Solution { pub fn kids_with_candies(candies: Vec, extra_candies: i32) -> Vec { @@ -140,6 +152,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** @@ -158,6 +172,8 @@ class Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) /** diff --git a/solution/1400-1499/1432.Max Difference You Can Get From Changing an Integer/README.md b/solution/1400-1499/1432.Max Difference You Can Get From Changing an Integer/README.md index 7ac9527baf914..f27f75f2fd31b 100644 --- a/solution/1400-1499/1432.Max Difference You Can Get From Changing an Integer/README.md +++ b/solution/1400-1499/1432.Max Difference You Can Get From Changing an Integer/README.md @@ -98,6 +98,8 @@ tags: +#### Python3 + ```python class Solution: def maxDiff(self, num: int) -> int: @@ -116,6 +118,8 @@ class Solution: return int(a) - int(b) ``` +#### Java + ```java class Solution { public int maxDiff(int num) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go func maxDiff(num int) int { a, b := num, num diff --git a/solution/1400-1499/1432.Max Difference You Can Get From Changing an Integer/README_EN.md b/solution/1400-1499/1432.Max Difference You Can Get From Changing an Integer/README_EN.md index 7e7da56c9368c..5b5b3188c27dd 100644 --- a/solution/1400-1499/1432.Max Difference You Can Get From Changing an Integer/README_EN.md +++ b/solution/1400-1499/1432.Max Difference You Can Get From Changing an Integer/README_EN.md @@ -70,6 +70,8 @@ We have now a = 9 and b = 1 and max difference = 8 +#### Python3 + ```python class Solution: def maxDiff(self, num: int) -> int: @@ -88,6 +90,8 @@ class Solution: return int(a) - int(b) ``` +#### Java + ```java class Solution { public int maxDiff(int num) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func maxDiff(num int) int { a, b := num, num diff --git a/solution/1400-1499/1433.Check If a String Can Break Another String/README.md b/solution/1400-1499/1433.Check If a String Can Break Another String/README.md index ddefaa71b217f..d0a3eda689215 100644 --- a/solution/1400-1499/1433.Check If a String Can Break Another String/README.md +++ b/solution/1400-1499/1433.Check If a String Can Break Another String/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def checkIfCanBreak(self, s1: str, s2: str) -> bool: @@ -81,6 +83,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public boolean checkIfCanBreak(String s1, String s2) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func checkIfCanBreak(s1 string, s2 string) bool { cs1 := []byte(s1) @@ -140,6 +148,8 @@ func checkIfCanBreak(s1 string, s2 string) bool { } ``` +#### TypeScript + ```ts function checkIfCanBreak(s1: string, s2: string): boolean { const cs1: string[] = Array.from(s1); diff --git a/solution/1400-1499/1433.Check If a String Can Break Another String/README_EN.md b/solution/1400-1499/1433.Check If a String Can Break Another String/README_EN.md index 08f1965b69cba..c099887678255 100644 --- a/solution/1400-1499/1433.Check If a String Can Break Another String/README_EN.md +++ b/solution/1400-1499/1433.Check If a String Can Break Another String/README_EN.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def checkIfCanBreak(self, s1: str, s2: str) -> bool: @@ -78,6 +80,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public boolean checkIfCanBreak(String s1, String s2) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func checkIfCanBreak(s1 string, s2 string) bool { cs1 := []byte(s1) @@ -137,6 +145,8 @@ func checkIfCanBreak(s1 string, s2 string) bool { } ``` +#### TypeScript + ```ts function checkIfCanBreak(s1: string, s2: string): boolean { const cs1: string[] = Array.from(s1); diff --git a/solution/1400-1499/1434.Number of Ways to Wear Different Hats to Each Other/README.md b/solution/1400-1499/1434.Number of Ways to Wear Different Hats to Each Other/README.md index 67721ca667f27..f16df393d7e94 100644 --- a/solution/1400-1499/1434.Number of Ways to Wear Different Hats to Each Other/README.md +++ b/solution/1400-1499/1434.Number of Ways to Wear Different Hats to Each Other/README.md @@ -102,6 +102,8 @@ $$ +#### Python3 + ```python class Solution: def numberWays(self, hats: List[List[int]]) -> int: @@ -123,6 +125,8 @@ class Solution: return f[m][-1] ``` +#### Java + ```java class Solution { public int numberWays(List> hats) { @@ -158,6 +162,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -192,6 +198,8 @@ public: }; ``` +#### Go + ```go func numberWays(hats [][]int) int { n := len(hats) @@ -225,6 +233,8 @@ func numberWays(hats [][]int) int { } ``` +#### TypeScript + ```ts function numberWays(hats: number[][]): number { const n = hats.length; diff --git a/solution/1400-1499/1434.Number of Ways to Wear Different Hats to Each Other/README_EN.md b/solution/1400-1499/1434.Number of Ways to Wear Different Hats to Each Other/README_EN.md index 25b572ae3a5d5..81f3d97a0ab39 100644 --- a/solution/1400-1499/1434.Number of Ways to Wear Different Hats to Each Other/README_EN.md +++ b/solution/1400-1499/1434.Number of Ways to Wear Different Hats to Each Other/README_EN.md @@ -94,6 +94,8 @@ Time complexity $O(m \times 2^n \times n)$, space complexity $O(m \times 2^n)$. +#### Python3 + ```python class Solution: def numberWays(self, hats: List[List[int]]) -> int: @@ -115,6 +117,8 @@ class Solution: return f[m][-1] ``` +#### Java + ```java class Solution { public int numberWays(List> hats) { @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -184,6 +190,8 @@ public: }; ``` +#### Go + ```go func numberWays(hats [][]int) int { n := len(hats) @@ -217,6 +225,8 @@ func numberWays(hats [][]int) int { } ``` +#### TypeScript + ```ts function numberWays(hats: number[][]): number { const n = hats.length; diff --git a/solution/1400-1499/1435.Create a Session Bar Chart/README.md b/solution/1400-1499/1435.Create a Session Bar Chart/README.md index 6d82fe5fddf71..1f9973d3b9163 100644 --- a/solution/1400-1499/1435.Create a Session Bar Chart/README.md +++ b/solution/1400-1499/1435.Create a Session Bar Chart/README.md @@ -81,6 +81,8 @@ Sessions 表: +#### MySQL + ```sql SELECT '[0-5>' AS bin, COUNT(1) AS total FROM Sessions WHERE duration < 300 UNION diff --git a/solution/1400-1499/1435.Create a Session Bar Chart/README_EN.md b/solution/1400-1499/1435.Create a Session Bar Chart/README_EN.md index d0c24c3096dbf..d6a678463c26b 100644 --- a/solution/1400-1499/1435.Create a Session Bar Chart/README_EN.md +++ b/solution/1400-1499/1435.Create a Session Bar Chart/README_EN.md @@ -80,6 +80,8 @@ For session_id 5 has a duration greater than or equal to 15 minutes. +#### MySQL + ```sql SELECT '[0-5>' AS bin, COUNT(1) AS total FROM Sessions WHERE duration < 300 UNION diff --git a/solution/1400-1499/1436.Destination City/README.md b/solution/1400-1499/1436.Destination City/README.md index 4edc6848661a4..436117856461f 100644 --- a/solution/1400-1499/1436.Destination City/README.md +++ b/solution/1400-1499/1436.Destination City/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def destCity(self, paths: List[List[str]]) -> str: @@ -87,6 +89,8 @@ class Solution: return next(b for _, b in paths if b not in s) ``` +#### Java + ```java class Solution { public String destCity(List> paths) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func destCity(paths [][]string) string { s := map[string]bool{} @@ -137,6 +145,8 @@ func destCity(paths [][]string) string { } ``` +#### TypeScript + ```ts function destCity(paths: string[][]): string { const set = new Set(paths.map(([a]) => a)); @@ -149,6 +159,8 @@ function destCity(paths: string[][]): string { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -167,6 +179,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string[][]} paths @@ -186,6 +200,8 @@ var destCity = function (paths) { }; ``` +#### C + ```c char* destCity(char*** paths, int pathsSize, int* pathsColSize) { for (int i = 0; i < pathsSize; i++) { diff --git a/solution/1400-1499/1436.Destination City/README_EN.md b/solution/1400-1499/1436.Destination City/README_EN.md index dff3c9e7e1612..0e9b8f02cbcd6 100644 --- a/solution/1400-1499/1436.Destination City/README_EN.md +++ b/solution/1400-1499/1436.Destination City/README_EN.md @@ -74,6 +74,8 @@ Clearly the destination city is "A". +#### Python3 + ```python class Solution: def destCity(self, paths: List[List[str]]) -> str: @@ -81,6 +83,8 @@ class Solution: return next(b for _, b in paths if b not in s) ``` +#### Java + ```java class Solution { public String destCity(List> paths) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func destCity(paths [][]string) string { s := map[string]bool{} @@ -131,6 +139,8 @@ func destCity(paths [][]string) string { } ``` +#### TypeScript + ```ts function destCity(paths: string[][]): string { const set = new Set(paths.map(([a]) => a)); @@ -143,6 +153,8 @@ function destCity(paths: string[][]): string { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -161,6 +173,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string[][]} paths @@ -180,6 +194,8 @@ var destCity = function (paths) { }; ``` +#### C + ```c char* destCity(char*** paths, int pathsSize, int* pathsColSize) { for (int i = 0; i < pathsSize; i++) { diff --git a/solution/1400-1499/1437.Check If All 1's Are at Least Length K Places Away/README.md b/solution/1400-1499/1437.Check If All 1's Are at Least Length K Places Away/README.md index e18583d76e5e8..5101aa1ecd885 100644 --- a/solution/1400-1499/1437.Check If All 1's Are at Least Length K Places Away/README.md +++ b/solution/1400-1499/1437.Check If All 1's Are at Least Length K Places Away/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def kLengthApart(self, nums: List[int], k: int) -> bool: @@ -88,6 +90,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean kLengthApart(int[] nums, int k) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func kLengthApart(nums []int, k int) bool { j := -(k + 1) @@ -138,6 +146,8 @@ func kLengthApart(nums []int, k int) bool { } ``` +#### TypeScript + ```ts function kLengthApart(nums: number[], k: number): boolean { let j = -(k + 1); diff --git a/solution/1400-1499/1437.Check If All 1's Are at Least Length K Places Away/README_EN.md b/solution/1400-1499/1437.Check If All 1's Are at Least Length K Places Away/README_EN.md index 96eee94e8495e..5feb700b3d2a1 100644 --- a/solution/1400-1499/1437.Check If All 1's Are at Least Length K Places Away/README_EN.md +++ b/solution/1400-1499/1437.Check If All 1's Are at Least Length K Places Away/README_EN.md @@ -56,6 +56,8 @@ tags: +#### Python3 + ```python class Solution: def kLengthApart(self, nums: List[int], k: int) -> bool: @@ -68,6 +70,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean kLengthApart(int[] nums, int k) { @@ -85,6 +89,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -103,6 +109,8 @@ public: }; ``` +#### Go + ```go func kLengthApart(nums []int, k int) bool { j := -(k + 1) @@ -118,6 +126,8 @@ func kLengthApart(nums []int, k int) bool { } ``` +#### TypeScript + ```ts function kLengthApart(nums: number[], k: number): boolean { let j = -(k + 1); diff --git a/solution/1400-1499/1438.Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit/README.md b/solution/1400-1499/1438.Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit/README.md index 1cc9c85a98dd5..02b31b4a8b6d7 100644 --- a/solution/1400-1499/1438.Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit/README.md +++ b/solution/1400-1499/1438.Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python from sortedcontainers import SortedList @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestSubarray(int[] nums, int limit) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func longestSubarray(nums []int, limit int) (ans int) { merge := func(st *redblacktree.Tree[int, int], x, v int) { @@ -161,6 +169,8 @@ func longestSubarray(nums []int, limit int) (ans int) { } ``` +#### TypeScript + ```ts function longestSubarray(nums: number[], limit: number): number { const ts = new TreapMultiSet(); @@ -811,6 +821,8 @@ class TreapMultiSet implements ITreapMultiSet { +#### Python3 + ```python class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: @@ -842,6 +854,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { private int[] nums; @@ -889,6 +903,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -931,6 +947,8 @@ public: }; ``` +#### Go + ```go func longestSubarray(nums []int, limit int) int { l, r := 0, len(nums) @@ -1028,6 +1046,8 @@ func (q Deque) Get(i int) int { } ``` +#### TypeScript + ```ts function longestSubarray(nums: number[], limit: number): number { const n = nums.length; diff --git a/solution/1400-1499/1438.Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit/README_EN.md b/solution/1400-1499/1438.Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit/README_EN.md index 797cb5e9f12c4..4bb1e6cff94f4 100644 --- a/solution/1400-1499/1438.Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit/README_EN.md +++ b/solution/1400-1499/1438.Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit/README_EN.md @@ -79,6 +79,8 @@ Therefore, the size of the longest subarray is 2. +#### Python3 + ```python from sortedcontainers import SortedList @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestSubarray(int[] nums, int limit) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func longestSubarray(nums []int, limit int) (ans int) { merge := func(st *redblacktree.Tree[int, int], x, v int) { @@ -156,6 +164,8 @@ func longestSubarray(nums []int, limit int) (ans int) { } ``` +#### TypeScript + ```ts function longestSubarray(nums: number[], limit: number): number { const ts = new TreapMultiSet(); @@ -806,6 +816,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: @@ -837,6 +849,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { private int[] nums; @@ -884,6 +898,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -926,6 +942,8 @@ public: }; ``` +#### Go + ```go func longestSubarray(nums []int, limit int) int { l, r := 0, len(nums) @@ -1023,6 +1041,8 @@ func (q Deque) Get(i int) int { } ``` +#### TypeScript + ```ts function longestSubarray(nums: number[], limit: number): number { const n = nums.length; diff --git a/solution/1400-1499/1439.Find the Kth Smallest Sum of a Matrix With Sorted Rows/README.md b/solution/1400-1499/1439.Find the Kth Smallest Sum of a Matrix With Sorted Rows/README.md index bdce0f7ce3872..a1c8fe21ff0c1 100644 --- a/solution/1400-1499/1439.Find the Kth Smallest Sum of a Matrix With Sorted Rows/README.md +++ b/solution/1400-1499/1439.Find the Kth Smallest Sum of a Matrix With Sorted Rows/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def kthSmallest(self, mat: List[List[int]], k: int) -> int: @@ -98,6 +100,8 @@ class Solution: return pre[-1] ``` +#### Java + ```java class Solution { public int kthSmallest(int[][] mat, int k) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func kthSmallest(mat [][]int, k int) int { pre := []int{0} @@ -166,6 +174,8 @@ func kthSmallest(mat [][]int, k int) int { } ``` +#### TypeScript + ```ts function kthSmallest(mat: number[][], k: number): number { let pre: number[] = [0]; diff --git a/solution/1400-1499/1439.Find the Kth Smallest Sum of a Matrix With Sorted Rows/README_EN.md b/solution/1400-1499/1439.Find the Kth Smallest Sum of a Matrix With Sorted Rows/README_EN.md index cdee7909646f3..8a9ae83c84984 100644 --- a/solution/1400-1499/1439.Find the Kth Smallest Sum of a Matrix With Sorted Rows/README_EN.md +++ b/solution/1400-1499/1439.Find the Kth Smallest Sum of a Matrix With Sorted Rows/README_EN.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def kthSmallest(self, mat: List[List[int]], k: int) -> int: @@ -84,6 +86,8 @@ class Solution: return pre[-1] ``` +#### Java + ```java class Solution { public int kthSmallest(int[][] mat, int k) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func kthSmallest(mat [][]int, k int) int { pre := []int{0} @@ -152,6 +160,8 @@ func kthSmallest(mat [][]int, k int) int { } ``` +#### TypeScript + ```ts function kthSmallest(mat: number[][], k: number): number { let pre: number[] = [0]; diff --git a/solution/1400-1499/1440.Evaluate Boolean Expression/README.md b/solution/1400-1499/1440.Evaluate Boolean Expression/README.md index 86acc2a2f09e3..8f3e86a3b378d 100644 --- a/solution/1400-1499/1440.Evaluate Boolean Expression/README.md +++ b/solution/1400-1499/1440.Evaluate Boolean Expression/README.md @@ -108,6 +108,8 @@ Expressions 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1400-1499/1440.Evaluate Boolean Expression/README_EN.md b/solution/1400-1499/1440.Evaluate Boolean Expression/README_EN.md index 2ef480ef96422..fbb00a29c40d1 100644 --- a/solution/1400-1499/1440.Evaluate Boolean Expression/README_EN.md +++ b/solution/1400-1499/1440.Evaluate Boolean Expression/README_EN.md @@ -105,6 +105,8 @@ We can associate each row in the `Expressions` table with two rows in the `Varia +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1400-1499/1441.Build an Array With Stack Operations/README.md b/solution/1400-1499/1441.Build an Array With Stack Operations/README.md index 9cee34b63e0c3..bc6a924de5cf5 100644 --- a/solution/1400-1499/1441.Build an Array With Stack Operations/README.md +++ b/solution/1400-1499/1441.Build an Array With Stack Operations/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def buildArray(self, target: List[int], n: int) -> List[str]: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List buildArray(int[] target, int n) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func buildArray(target []int, n int) []string { cur := 0 @@ -153,6 +161,8 @@ func buildArray(target []int, n int) []string { } ``` +#### TypeScript + ```ts function buildArray(target: number[], n: number): string[] { const res = []; @@ -167,6 +177,8 @@ function buildArray(target: number[], n: number): string[] { } ``` +#### Rust + ```rust impl Solution { pub fn build_array(target: Vec, n: i32) -> Vec { @@ -186,6 +198,8 @@ impl Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). diff --git a/solution/1400-1499/1441.Build an Array With Stack Operations/README_EN.md b/solution/1400-1499/1441.Build an Array With Stack Operations/README_EN.md index dda13d6e8c9a8..ef50179b60fb0 100644 --- a/solution/1400-1499/1441.Build an Array With Stack Operations/README_EN.md +++ b/solution/1400-1499/1441.Build an Array With Stack Operations/README_EN.md @@ -97,6 +97,8 @@ The answers that read integer 3 from the stream are not accepted. +#### Python3 + ```python class Solution: def buildArray(self, target: List[int], n: int) -> List[str]: @@ -110,6 +112,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List buildArray(int[] target, int n) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func buildArray(target []int, n int) []string { cur := 0 @@ -159,6 +167,8 @@ func buildArray(target []int, n int) []string { } ``` +#### TypeScript + ```ts function buildArray(target: number[], n: number): string[] { const res = []; @@ -173,6 +183,8 @@ function buildArray(target: number[], n: number): string[] { } ``` +#### Rust + ```rust impl Solution { pub fn build_array(target: Vec, n: i32) -> Vec { @@ -192,6 +204,8 @@ impl Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). diff --git a/solution/1400-1499/1442.Count Triplets That Can Form Two Arrays of Equal XOR/README.md b/solution/1400-1499/1442.Count Triplets That Can Form Two Arrays of Equal XOR/README.md index 7502c70fc85f3..6ab254a66ef70 100644 --- a/solution/1400-1499/1442.Count Triplets That Can Form Two Arrays of Equal XOR/README.md +++ b/solution/1400-1499/1442.Count Triplets That Can Form Two Arrays of Equal XOR/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def countTriplets(self, arr: List[int]) -> int: @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countTriplets(int[] arr) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func countTriplets(arr []int) int { n := len(arr) diff --git a/solution/1400-1499/1442.Count Triplets That Can Form Two Arrays of Equal XOR/README_EN.md b/solution/1400-1499/1442.Count Triplets That Can Form Two Arrays of Equal XOR/README_EN.md index 95666dd80262b..848df5d85c8d1 100644 --- a/solution/1400-1499/1442.Count Triplets That Can Form Two Arrays of Equal XOR/README_EN.md +++ b/solution/1400-1499/1442.Count Triplets That Can Form Two Arrays of Equal XOR/README_EN.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def countTriplets(self, arr: List[int]) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countTriplets(int[] arr) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func countTriplets(arr []int) int { n := len(arr) diff --git a/solution/1400-1499/1443.Minimum Time to Collect All Apples in a Tree/README.md b/solution/1400-1499/1443.Minimum Time to Collect All Apples in a Tree/README.md index 1e9d604a539e5..ab0103a58f31e 100644 --- a/solution/1400-1499/1443.Minimum Time to Collect All Apples in a Tree/README.md +++ b/solution/1400-1499/1443.Minimum Time to Collect All Apples in a Tree/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def minTime(self, n: int, edges: List[List[int]], hasApple: List[bool]) -> int: @@ -98,6 +100,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { public int minTime(int n, int[][] edges, List hasApple) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func minTime(n int, edges [][]int, hasApple []bool) int { vis := make([]bool, n) diff --git a/solution/1400-1499/1443.Minimum Time to Collect All Apples in a Tree/README_EN.md b/solution/1400-1499/1443.Minimum Time to Collect All Apples in a Tree/README_EN.md index 1ab027bd99f20..3dbcdc4ba835e 100644 --- a/solution/1400-1499/1443.Minimum Time to Collect All Apples in a Tree/README_EN.md +++ b/solution/1400-1499/1443.Minimum Time to Collect All Apples in a Tree/README_EN.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def minTime(self, n: int, edges: List[List[int]], hasApple: List[bool]) -> int: @@ -92,6 +94,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { public int minTime(int n, int[][] edges, List hasApple) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func minTime(n int, edges [][]int, hasApple []bool) int { vis := make([]bool, n) diff --git a/solution/1400-1499/1444.Number of Ways of Cutting a Pizza/README.md b/solution/1400-1499/1444.Number of Ways of Cutting a Pizza/README.md index a10bff640120f..015d48774a410 100644 --- a/solution/1400-1499/1444.Number of Ways of Cutting a Pizza/README.md +++ b/solution/1400-1499/1444.Number of Ways of Cutting a Pizza/README.md @@ -95,6 +95,8 @@ $$ +#### Python3 + ```python class Solution: def ways(self, pizza: List[str], k: int) -> int: @@ -120,6 +122,8 @@ class Solution: return dfs(0, 0, k - 1) ``` +#### Java + ```java class Solution { private int m; @@ -165,6 +169,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -204,6 +210,8 @@ public: }; ``` +#### Go + ```go func ways(pizza []string, k int) int { const mod = 1e9 + 7 @@ -259,6 +267,8 @@ func ways(pizza []string, k int) int { } ``` +#### TypeScript + ```ts function ways(pizza: string[], k: number): number { const mod = 1e9 + 7; diff --git a/solution/1400-1499/1444.Number of Ways of Cutting a Pizza/README_EN.md b/solution/1400-1499/1444.Number of Ways of Cutting a Pizza/README_EN.md index 8976f2a5224e9..1907b1f1ffcd6 100644 --- a/solution/1400-1499/1444.Number of Ways of Cutting a Pizza/README_EN.md +++ b/solution/1400-1499/1444.Number of Ways of Cutting a Pizza/README_EN.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def ways(self, pizza: List[str], k: int) -> int: @@ -98,6 +100,8 @@ class Solution: return dfs(0, 0, k - 1) ``` +#### Java + ```java class Solution { private int m; @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -182,6 +188,8 @@ public: }; ``` +#### Go + ```go func ways(pizza []string, k int) int { const mod = 1e9 + 7 @@ -237,6 +245,8 @@ func ways(pizza []string, k int) int { } ``` +#### TypeScript + ```ts function ways(pizza: string[], k: number): number { const mod = 1e9 + 7; diff --git a/solution/1400-1499/1445.Apples & Oranges/README.md b/solution/1400-1499/1445.Apples & Oranges/README.md index 18a1f7a987f59..03b637498d7e9 100644 --- a/solution/1400-1499/1445.Apples & Oranges/README.md +++ b/solution/1400-1499/1445.Apples & Oranges/README.md @@ -85,6 +85,8 @@ Sales 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1400-1499/1445.Apples & Oranges/README_EN.md b/solution/1400-1499/1445.Apples & Oranges/README_EN.md index ea343e86c5e96..2f7ad93c49a31 100644 --- a/solution/1400-1499/1445.Apples & Oranges/README_EN.md +++ b/solution/1400-1499/1445.Apples & Oranges/README_EN.md @@ -84,6 +84,8 @@ We can group the data by date, and then use the `sum` function to calculate the +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1400-1499/1446.Consecutive Characters/README.md b/solution/1400-1499/1446.Consecutive Characters/README.md index 87c78b5628f7b..49c56c0834ab5 100644 --- a/solution/1400-1499/1446.Consecutive Characters/README.md +++ b/solution/1400-1499/1446.Consecutive Characters/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def maxPower(self, s: str) -> int: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxPower(String s) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func maxPower(s string) int { ans, t := 1, 1 @@ -128,6 +136,8 @@ func maxPower(s string) int { } ``` +#### TypeScript + ```ts function maxPower(s: string): number { let ans = 1; diff --git a/solution/1400-1499/1446.Consecutive Characters/README_EN.md b/solution/1400-1499/1446.Consecutive Characters/README_EN.md index ed3143da74e7e..8b138b4558bb4 100644 --- a/solution/1400-1499/1446.Consecutive Characters/README_EN.md +++ b/solution/1400-1499/1446.Consecutive Characters/README_EN.md @@ -57,6 +57,8 @@ tags: +#### Python3 + ```python class Solution: def maxPower(self, s: str) -> int: @@ -70,6 +72,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxPower(String s) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -103,6 +109,8 @@ public: }; ``` +#### Go + ```go func maxPower(s string) int { ans, t := 1, 1 @@ -118,6 +126,8 @@ func maxPower(s string) int { } ``` +#### TypeScript + ```ts function maxPower(s: string): number { let ans = 1; diff --git a/solution/1400-1499/1447.Simplified Fractions/README.md b/solution/1400-1499/1447.Simplified Fractions/README.md index 007705442f7b1..34ce5b978cb5b 100644 --- a/solution/1400-1499/1447.Simplified Fractions/README.md +++ b/solution/1400-1499/1447.Simplified Fractions/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def simplifiedFractions(self, n: int) -> List[str]: @@ -81,6 +83,8 @@ class Solution: ] ``` +#### Java + ```java class Solution { public List simplifiedFractions(int n) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func simplifiedFractions(n int) (ans []string) { for i := 1; i < n; i++ { @@ -138,6 +146,8 @@ func gcd(a, b int) int { } ``` +#### TypeScript + ```ts function simplifiedFractions(n: number): string[] { const ans: string[] = []; @@ -156,6 +166,8 @@ function gcd(a: number, b: number): number { } ``` +#### Rust + ```rust impl Solution { fn gcd(a: i32, b: i32) -> i32 { diff --git a/solution/1400-1499/1447.Simplified Fractions/README_EN.md b/solution/1400-1499/1447.Simplified Fractions/README_EN.md index eaaf95b7bed67..15369afb909a0 100644 --- a/solution/1400-1499/1447.Simplified Fractions/README_EN.md +++ b/solution/1400-1499/1447.Simplified Fractions/README_EN.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def simplifiedFractions(self, n: int) -> List[str]: @@ -74,6 +76,8 @@ class Solution: ] ``` +#### Java + ```java class Solution { public List simplifiedFractions(int n) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func simplifiedFractions(n int) (ans []string) { for i := 1; i < n; i++ { @@ -131,6 +139,8 @@ func gcd(a, b int) int { } ``` +#### TypeScript + ```ts function simplifiedFractions(n: number): string[] { const ans: string[] = []; @@ -149,6 +159,8 @@ function gcd(a: number, b: number): number { } ``` +#### Rust + ```rust impl Solution { fn gcd(a: i32, b: i32) -> i32 { diff --git a/solution/1400-1499/1448.Count Good Nodes in Binary Tree/README.md b/solution/1400-1499/1448.Count Good Nodes in Binary Tree/README.md index 4bd5da3669908..2366c47345bb6 100644 --- a/solution/1400-1499/1448.Count Good Nodes in Binary Tree/README.md +++ b/solution/1400-1499/1448.Count Good Nodes in Binary Tree/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -110,6 +112,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -208,6 +216,8 @@ func goodNodes(root *TreeNode) (ans int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/1400-1499/1448.Count Good Nodes in Binary Tree/README_EN.md b/solution/1400-1499/1448.Count Good Nodes in Binary Tree/README_EN.md index be746f7879903..4a07c72b0b946 100644 --- a/solution/1400-1499/1448.Count Good Nodes in Binary Tree/README_EN.md +++ b/solution/1400-1499/1448.Count Good Nodes in Binary Tree/README_EN.md @@ -91,6 +91,8 @@ Node 3 -> (3,1,3) is the maximum value in the path. +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -153,6 +157,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -213,6 +221,8 @@ func goodNodes(root *TreeNode) (ans int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/1400-1499/1449.Form Largest Integer With Digits That Add up to Target/README.md b/solution/1400-1499/1449.Form Largest Integer With Digits That Add up to Target/README.md index 57c786ae36e3c..ec58e17981fa4 100644 --- a/solution/1400-1499/1449.Form Largest Integer With Digits That Add up to Target/README.md +++ b/solution/1400-1499/1449.Form Largest Integer With Digits That Add up to Target/README.md @@ -108,6 +108,8 @@ tags: +#### Python3 + ```python class Solution: def largestNumber(self, cost: List[int], target: int) -> str: @@ -135,6 +137,8 @@ class Solution: return "".join(ans) ``` +#### Java + ```java class Solution { public String largestNumber(int[] cost, int target) { @@ -174,6 +178,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -211,6 +217,8 @@ public: }; ``` +#### Go + ```go func largestNumber(cost []int, target int) string { const inf = 1 << 30 @@ -252,6 +260,8 @@ func largestNumber(cost []int, target int) string { } ``` +#### TypeScript + ```ts function largestNumber(cost: number[], target: number): string { const inf = 1 << 30; diff --git a/solution/1400-1499/1449.Form Largest Integer With Digits That Add up to Target/README_EN.md b/solution/1400-1499/1449.Form Largest Integer With Digits That Add up to Target/README_EN.md index f4aca92d1fbc2..e9359388264b3 100644 --- a/solution/1400-1499/1449.Form Largest Integer With Digits That Add up to Target/README_EN.md +++ b/solution/1400-1499/1449.Form Largest Integer With Digits That Add up to Target/README_EN.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def largestNumber(self, cost: List[int], target: int) -> str: @@ -109,6 +111,8 @@ class Solution: return "".join(ans) ``` +#### Java + ```java class Solution { public String largestNumber(int[] cost, int target) { @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -185,6 +191,8 @@ public: }; ``` +#### Go + ```go func largestNumber(cost []int, target int) string { const inf = 1 << 30 @@ -226,6 +234,8 @@ func largestNumber(cost []int, target int) string { } ``` +#### TypeScript + ```ts function largestNumber(cost: number[], target: number): string { const inf = 1 << 30; diff --git a/solution/1400-1499/1450.Number of Students Doing Homework at a Given Time/README.md b/solution/1400-1499/1450.Number of Students Doing Homework at a Given Time/README.md index 117a48f91855d..d462d297cb93e 100644 --- a/solution/1400-1499/1450.Number of Students Doing Homework at a Given Time/README.md +++ b/solution/1400-1499/1450.Number of Students Doing Homework at a Given Time/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def busyStudent( @@ -94,6 +96,8 @@ class Solution: return sum(a <= queryTime <= b for a, b in zip(startTime, endTime)) ``` +#### Java + ```java class Solution { public int busyStudent(int[] startTime, int[] endTime, int queryTime) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func busyStudent(startTime []int, endTime []int, queryTime int) int { ans := 0 @@ -134,6 +142,8 @@ func busyStudent(startTime []int, endTime []int, queryTime int) int { } ``` +#### TypeScript + ```ts function busyStudent(startTime: number[], endTime: number[], queryTime: number): number { const n = startTime.length; @@ -147,6 +157,8 @@ function busyStudent(startTime: number[], endTime: number[], queryTime: number): } ``` +#### Rust + ```rust impl Solution { pub fn busy_student(start_time: Vec, end_time: Vec, query_time: i32) -> i32 { @@ -161,6 +173,8 @@ impl Solution { } ``` +#### C + ```c int busyStudent(int* startTime, int startTimeSize, int* endTime, int endTimeSize, int queryTime) { int res = 0; @@ -205,6 +219,8 @@ $$ +#### Python3 + ```python class Solution: def busyStudent( @@ -217,6 +233,8 @@ class Solution: return sum(c[: queryTime + 1]) ``` +#### Java + ```java class Solution { public int busyStudent(int[] startTime, int[] endTime, int queryTime) { @@ -234,6 +252,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -252,6 +272,8 @@ public: }; ``` +#### Go + ```go func busyStudent(startTime []int, endTime []int, queryTime int) int { c := make([]int, 1010) diff --git a/solution/1400-1499/1450.Number of Students Doing Homework at a Given Time/README_EN.md b/solution/1400-1499/1450.Number of Students Doing Homework at a Given Time/README_EN.md index 2c772d770b57d..c6124f38bf493 100644 --- a/solution/1400-1499/1450.Number of Students Doing Homework at a Given Time/README_EN.md +++ b/solution/1400-1499/1450.Number of Students Doing Homework at a Given Time/README_EN.md @@ -64,6 +64,8 @@ The third student started doing homework at time 3 and finished at time 7 and wa +#### Python3 + ```python class Solution: def busyStudent( @@ -72,6 +74,8 @@ class Solution: return sum(a <= queryTime <= b for a, b in zip(startTime, endTime)) ``` +#### Java + ```java class Solution { public int busyStudent(int[] startTime, int[] endTime, int queryTime) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -99,6 +105,8 @@ public: }; ``` +#### Go + ```go func busyStudent(startTime []int, endTime []int, queryTime int) int { ans := 0 @@ -112,6 +120,8 @@ func busyStudent(startTime []int, endTime []int, queryTime int) int { } ``` +#### TypeScript + ```ts function busyStudent(startTime: number[], endTime: number[], queryTime: number): number { const n = startTime.length; @@ -125,6 +135,8 @@ function busyStudent(startTime: number[], endTime: number[], queryTime: number): } ``` +#### Rust + ```rust impl Solution { pub fn busy_student(start_time: Vec, end_time: Vec, query_time: i32) -> i32 { @@ -139,6 +151,8 @@ impl Solution { } ``` +#### C + ```c int busyStudent(int* startTime, int startTimeSize, int* endTime, int endTimeSize, int queryTime) { int res = 0; @@ -161,6 +175,8 @@ int busyStudent(int* startTime, int startTimeSize, int* endTime, int endTimeSize +#### Python3 + ```python class Solution: def busyStudent( @@ -173,6 +189,8 @@ class Solution: return sum(c[: queryTime + 1]) ``` +#### Java + ```java class Solution { public int busyStudent(int[] startTime, int[] endTime, int queryTime) { @@ -190,6 +208,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -208,6 +228,8 @@ public: }; ``` +#### Go + ```go func busyStudent(startTime []int, endTime []int, queryTime int) int { c := make([]int, 1010) diff --git a/solution/1400-1499/1451.Rearrange Words in a Sentence/README.md b/solution/1400-1499/1451.Rearrange Words in a Sentence/README.md index e0f0e47e6a14e..9543d12882cff 100644 --- a/solution/1400-1499/1451.Rearrange Words in a Sentence/README.md +++ b/solution/1400-1499/1451.Rearrange Words in a Sentence/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def arrangeWords(self, text: str) -> str: @@ -93,6 +95,8 @@ class Solution: return " ".join(words) ``` +#### Java + ```java class Solution { public String arrangeWords(String text) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func arrangeWords(text string) string { words := strings.Split(text, " ") @@ -140,6 +148,8 @@ func arrangeWords(text string) string { } ``` +#### TypeScript + ```ts function arrangeWords(text: string): string { let words: string[] = text.split(' '); @@ -150,6 +160,8 @@ function arrangeWords(text: string): string { } ``` +#### JavaScript + ```js /** * @param {string} text @@ -164,6 +176,8 @@ var arrangeWords = function (text) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1400-1499/1451.Rearrange Words in a Sentence/README_EN.md b/solution/1400-1499/1451.Rearrange Words in a Sentence/README_EN.md index 77eeed058e94e..0d236226b6798 100644 --- a/solution/1400-1499/1451.Rearrange Words in a Sentence/README_EN.md +++ b/solution/1400-1499/1451.Rearrange Words in a Sentence/README_EN.md @@ -78,6 +78,8 @@ Output is ordered by length and the new first word starts with capital letter. +#### Python3 + ```python class Solution: def arrangeWords(self, text: str) -> str: @@ -88,6 +90,8 @@ class Solution: return " ".join(words) ``` +#### Java + ```java class Solution { public String arrangeWords(String text) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func arrangeWords(text string) string { words := strings.Split(text, " ") @@ -135,6 +143,8 @@ func arrangeWords(text string) string { } ``` +#### TypeScript + ```ts function arrangeWords(text: string): string { let words: string[] = text.split(' '); @@ -145,6 +155,8 @@ function arrangeWords(text: string): string { } ``` +#### JavaScript + ```js /** * @param {string} text @@ -159,6 +171,8 @@ var arrangeWords = function (text) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1400-1499/1452.People Whose List of Favorite Companies Is Not a Subset of Another List/README.md b/solution/1400-1499/1452.People Whose List of Favorite Companies Is Not a Subset of Another List/README.md index faff00dd76a11..4226d3de2fc6e 100644 --- a/solution/1400-1499/1452.People Whose List of Favorite Companies Is Not a Subset of Another List/README.md +++ b/solution/1400-1499/1452.People Whose List of Favorite Companies Is Not a Subset of Another List/README.md @@ -76,6 +76,8 @@ favoriteCompanies[3]=["google"] 是 favoriteCompanies[0]=["leetco +#### Python3 + ```python class Solution: def peopleIndexes(self, favoriteCompanies: List[List[str]]) -> List[int]: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List peopleIndexes(List> favoriteCompanies) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -190,6 +196,8 @@ public: }; ``` +#### Go + ```go func peopleIndexes(favoriteCompanies [][]string) []int { d := map[string]int{} diff --git a/solution/1400-1499/1452.People Whose List of Favorite Companies Is Not a Subset of Another List/README_EN.md b/solution/1400-1499/1452.People Whose List of Favorite Companies Is Not a Subset of Another List/README_EN.md index ce6b4df481b63..c0566b5a0c31f 100644 --- a/solution/1400-1499/1452.People Whose List of Favorite Companies Is Not a Subset of Another List/README_EN.md +++ b/solution/1400-1499/1452.People Whose List of Favorite Companies Is Not a Subset of Another List/README_EN.md @@ -73,6 +73,8 @@ Other lists of favorite companies are not a subset of another list, therefore, t +#### Python3 + ```python class Solution: def peopleIndexes(self, favoriteCompanies: List[List[str]]) -> List[int]: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List peopleIndexes(List> favoriteCompanies) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -187,6 +193,8 @@ public: }; ``` +#### Go + ```go func peopleIndexes(favoriteCompanies [][]string) []int { d := map[string]int{} diff --git a/solution/1400-1499/1453.Maximum Number of Darts Inside of a Circular Dartboard/README.md b/solution/1400-1499/1453.Maximum Number of Darts Inside of a Circular Dartboard/README.md index b607eb61e9d3a..be513f0e7edff 100644 --- a/solution/1400-1499/1453.Maximum Number of Darts Inside of a Circular Dartboard/README.md +++ b/solution/1400-1499/1453.Maximum Number of Darts Inside of a Circular Dartboard/README.md @@ -66,18 +66,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1400-1499/1453.Maximum Number of Darts Inside of a Circular Dartboard/README_EN.md b/solution/1400-1499/1453.Maximum Number of Darts Inside of a Circular Dartboard/README_EN.md index b55df858beae0..da18bb00e9749 100644 --- a/solution/1400-1499/1453.Maximum Number of Darts Inside of a Circular Dartboard/README_EN.md +++ b/solution/1400-1499/1453.Maximum Number of Darts Inside of a Circular Dartboard/README_EN.md @@ -64,18 +64,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1400-1499/1454.Active Users/README.md b/solution/1400-1499/1454.Active Users/README.md index a933188d2f19d..2e1b05dd6cbc3 100644 --- a/solution/1400-1499/1454.Active Users/README.md +++ b/solution/1400-1499/1454.Active Users/README.md @@ -108,6 +108,8 @@ id = 7 的用户 Jonathon 在不同的 6 天内登录了 7 次, , 6 天中有 5 +#### MySQL + ```sql # Write your MySQL query statement below WITH t AS diff --git a/solution/1400-1499/1454.Active Users/README_EN.md b/solution/1400-1499/1454.Active Users/README_EN.md index 468c98c1b4fb0..a5d1e7008e0a7 100644 --- a/solution/1400-1499/1454.Active Users/README_EN.md +++ b/solution/1400-1499/1454.Active Users/README_EN.md @@ -104,6 +104,8 @@ User Jonathan with id = 7 logged in 7 times in 6 different days, five of them we +#### MySQL + ```sql # Write your MySQL query statement below WITH t AS diff --git a/solution/1400-1499/1455.Check If a Word Occurs As a Prefix of Any Word in a Sentence/README.md b/solution/1400-1499/1455.Check If a Word Occurs As a Prefix of Any Word in a Sentence/README.md index fd230980235c2..62cb63f2eb800 100644 --- a/solution/1400-1499/1455.Check If a Word Occurs As a Prefix of Any Word in a Sentence/README.md +++ b/solution/1400-1499/1455.Check If a Word Occurs As a Prefix of Any Word in a Sentence/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def isPrefixOfWord(self, sentence: str, searchWord: str) -> int: @@ -86,6 +88,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int isPrefixOfWord(String sentence, String searchWord) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func isPrefixOfWord(sentence string, searchWord string) int { for i, s := range strings.Split(sentence, " ") { @@ -127,6 +135,8 @@ func isPrefixOfWord(sentence string, searchWord string) int { } ``` +#### TypeScript + ```ts function isPrefixOfWord(sentence: string, searchWord: string): number { const ss = sentence.split(/\s/); @@ -140,6 +150,8 @@ function isPrefixOfWord(sentence: string, searchWord: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn is_prefix_of_word(sentence: String, search_word: String) -> i32 { @@ -154,6 +166,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1400-1499/1455.Check If a Word Occurs As a Prefix of Any Word in a Sentence/README_EN.md b/solution/1400-1499/1455.Check If a Word Occurs As a Prefix of Any Word in a Sentence/README_EN.md index 7b8d1ef66759f..ff87165460c60 100644 --- a/solution/1400-1499/1455.Check If a Word Occurs As a Prefix of Any Word in a Sentence/README_EN.md +++ b/solution/1400-1499/1455.Check If a Word Occurs As a Prefix of Any Word in a Sentence/README_EN.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def isPrefixOfWord(self, sentence: str, searchWord: str) -> int: @@ -80,6 +82,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int isPrefixOfWord(String sentence, String searchWord) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func isPrefixOfWord(sentence string, searchWord string) int { for i, s := range strings.Split(sentence, " ") { @@ -121,6 +129,8 @@ func isPrefixOfWord(sentence string, searchWord string) int { } ``` +#### TypeScript + ```ts function isPrefixOfWord(sentence: string, searchWord: string): number { const ss = sentence.split(/\s/); @@ -134,6 +144,8 @@ function isPrefixOfWord(sentence: string, searchWord: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn is_prefix_of_word(sentence: String, search_word: String) -> i32 { @@ -148,6 +160,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1400-1499/1456.Maximum Number of Vowels in a Substring of Given Length/README.md b/solution/1400-1499/1456.Maximum Number of Vowels in a Substring of Given Length/README.md index 19808eac62ada..73dab77aa66b1 100644 --- a/solution/1400-1499/1456.Maximum Number of Vowels in a Substring of Given Length/README.md +++ b/solution/1400-1499/1456.Maximum Number of Vowels in a Substring of Given Length/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def maxVowels(self, s: str, k: int) -> int: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxVowels(String s, int k) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func maxVowels(s string, k int) int { isVowel := func(c byte) bool { @@ -171,6 +179,8 @@ func maxVowels(s string, k int) int { } ``` +#### TypeScript + ```ts function maxVowels(s: string, k: number): number { const isVowel = (c: string) => ['a', 'e', 'i', 'o', 'u'].includes(c); @@ -194,6 +204,8 @@ function maxVowels(s: string, k: number): number { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1400-1499/1456.Maximum Number of Vowels in a Substring of Given Length/README_EN.md b/solution/1400-1499/1456.Maximum Number of Vowels in a Substring of Given Length/README_EN.md index 5d0320814978d..0369f8fcec7d6 100644 --- a/solution/1400-1499/1456.Maximum Number of Vowels in a Substring of Given Length/README_EN.md +++ b/solution/1400-1499/1456.Maximum Number of Vowels in a Substring of Given Length/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string $s$. The sp +#### Python3 + ```python class Solution: def maxVowels(self, s: str, k: int) -> int: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxVowels(String s, int k) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func maxVowels(s string, k int) int { isVowel := func(c byte) bool { @@ -157,6 +165,8 @@ func maxVowels(s string, k int) int { } ``` +#### TypeScript + ```ts function maxVowels(s: string, k: number): number { const isVowel = (c: string) => ['a', 'e', 'i', 'o', 'u'].includes(c); @@ -180,6 +190,8 @@ function maxVowels(s: string, k: number): number { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1400-1499/1457.Pseudo-Palindromic Paths in a Binary Tree/README.md b/solution/1400-1499/1457.Pseudo-Palindromic Paths in a Binary Tree/README.md index 831699e8353be..d10383b8d99b4 100644 --- a/solution/1400-1499/1457.Pseudo-Palindromic Paths in a Binary Tree/README.md +++ b/solution/1400-1499/1457.Pseudo-Palindromic Paths in a Binary Tree/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -114,6 +116,8 @@ class Solution: return dfs(root, 0) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -178,6 +184,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -206,6 +214,8 @@ func pseudoPalindromicPaths(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -236,6 +246,8 @@ function pseudoPalindromicPaths(root: TreeNode | null): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/1400-1499/1457.Pseudo-Palindromic Paths in a Binary Tree/README_EN.md b/solution/1400-1499/1457.Pseudo-Palindromic Paths in a Binary Tree/README_EN.md index d934a1dd46440..9ea155e450ad4 100644 --- a/solution/1400-1499/1457.Pseudo-Palindromic Paths in a Binary Tree/README_EN.md +++ b/solution/1400-1499/1457.Pseudo-Palindromic Paths in a Binary Tree/README_EN.md @@ -90,6 +90,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -110,6 +112,8 @@ class Solution: return dfs(root, 0) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -202,6 +210,8 @@ func pseudoPalindromicPaths(root *TreeNode) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -232,6 +242,8 @@ function pseudoPalindromicPaths(root: TreeNode | null): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/1400-1499/1458.Max Dot Product of Two Subsequences/README.md b/solution/1400-1499/1458.Max Dot Product of Two Subsequences/README.md index 19de9e088d83b..70522bad6b603 100644 --- a/solution/1400-1499/1458.Max Dot Product of Two Subsequences/README.md +++ b/solution/1400-1499/1458.Max Dot Product of Two Subsequences/README.md @@ -94,6 +94,8 @@ $$ +#### Python3 + ```python class Solution: def maxDotProduct(self, nums1: List[int], nums2: List[int]) -> int: @@ -106,6 +108,8 @@ class Solution: return dp[-1][-1] ``` +#### Java + ```java class Solution { public int maxDotProduct(int[] nums1, int[] nums2) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func maxDotProduct(nums1 []int, nums2 []int) int { m, n := len(nums1), len(nums2) @@ -165,6 +173,8 @@ func maxDotProduct(nums1 []int, nums2 []int) int { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/1400-1499/1458.Max Dot Product of Two Subsequences/README_EN.md b/solution/1400-1499/1458.Max Dot Product of Two Subsequences/README_EN.md index 9fe504a620d08..319411318266e 100644 --- a/solution/1400-1499/1458.Max Dot Product of Two Subsequences/README_EN.md +++ b/solution/1400-1499/1458.Max Dot Product of Two Subsequences/README_EN.md @@ -68,6 +68,8 @@ Their dot product is -1. +#### Python3 + ```python class Solution: def maxDotProduct(self, nums1: List[int], nums2: List[int]) -> int: @@ -80,6 +82,8 @@ class Solution: return dp[-1][-1] ``` +#### Java + ```java class Solution { public int maxDotProduct(int[] nums1, int[] nums2) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func maxDotProduct(nums1 []int, nums2 []int) int { m, n := len(nums1), len(nums2) @@ -139,6 +147,8 @@ func maxDotProduct(nums1 []int, nums2 []int) int { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/1400-1499/1459.Rectangles Area/README.md b/solution/1400-1499/1459.Rectangles Area/README.md index 1943ef10b45ae..18d10d68880dd 100644 --- a/solution/1400-1499/1459.Rectangles Area/README.md +++ b/solution/1400-1499/1459.Rectangles Area/README.md @@ -83,6 +83,8 @@ p1 = 1 且 p2 = 3 时, 是不可能为矩形的, 面积等于 0 +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1400-1499/1459.Rectangles Area/README_EN.md b/solution/1400-1499/1459.Rectangles Area/README_EN.md index 7c8eb20669aa3..a67fa2c8ffbcb 100644 --- a/solution/1400-1499/1459.Rectangles Area/README_EN.md +++ b/solution/1400-1499/1459.Rectangles Area/README_EN.md @@ -80,6 +80,8 @@ Note that the rectangle formed by p1 = 1 and p2 = 3 is invalid because the area +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1400-1499/1460.Make Two Arrays Equal by Reversing Subarrays/README.md b/solution/1400-1499/1460.Make Two Arrays Equal by Reversing Subarrays/README.md index cc1ecc3b1d7d7..ddfdbf498330a 100644 --- a/solution/1400-1499/1460.Make Two Arrays Equal by Reversing Subarrays/README.md +++ b/solution/1400-1499/1460.Make Two Arrays Equal by Reversing Subarrays/README.md @@ -81,12 +81,16 @@ tags: +#### Python3 + ```python class Solution: def canBeEqual(self, target: List[int], arr: List[int]) -> bool: return sorted(target) == sorted(arr) ``` +#### Java + ```java class Solution { public boolean canBeEqual(int[] target, int[] arr) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func canBeEqual(target []int, arr []int) bool { sort.Ints(target) @@ -116,6 +124,8 @@ func canBeEqual(target []int, arr []int) bool { } ``` +#### TypeScript + ```ts function canBeEqual(target: number[], arr: number[]): boolean { target.sort((a, b) => a - b); @@ -124,6 +134,8 @@ function canBeEqual(target: number[], arr: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn can_be_equal(mut target: Vec, mut arr: Vec) -> bool { @@ -134,6 +146,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** @@ -149,6 +163,8 @@ class Solution { } ``` +#### C + ```c int compare(const void* a, const void* b) { return (*(int*) a - *(int*) b); @@ -182,12 +198,16 @@ bool canBeEqual(int* target, int targetSize, int* arr, int arrSize) { +#### Python3 + ```python class Solution: def canBeEqual(self, target: List[int], arr: List[int]) -> bool: return Counter(target) == Counter(arr) ``` +#### Java + ```java class Solution { public boolean canBeEqual(int[] target, int[] arr) { @@ -204,6 +224,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -221,6 +243,8 @@ public: }; ``` +#### Go + ```go func canBeEqual(target []int, arr []int) bool { cnt1 := make([]int, 1001) @@ -235,6 +259,8 @@ func canBeEqual(target []int, arr []int) bool { } ``` +#### TypeScript + ```ts function canBeEqual(target: number[], arr: number[]): boolean { const n = target.length; @@ -247,6 +273,8 @@ function canBeEqual(target: number[], arr: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn can_be_equal(mut target: Vec, mut arr: Vec) -> bool { diff --git a/solution/1400-1499/1460.Make Two Arrays Equal by Reversing Subarrays/README_EN.md b/solution/1400-1499/1460.Make Two Arrays Equal by Reversing Subarrays/README_EN.md index 4536fa5f00870..a04b2d8cade64 100644 --- a/solution/1400-1499/1460.Make Two Arrays Equal by Reversing Subarrays/README_EN.md +++ b/solution/1400-1499/1460.Make Two Arrays Equal by Reversing Subarrays/README_EN.md @@ -79,12 +79,16 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def canBeEqual(self, target: List[int], arr: List[int]) -> bool: return sorted(target) == sorted(arr) ``` +#### Java + ```java class Solution { public boolean canBeEqual(int[] target, int[] arr) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func canBeEqual(target []int, arr []int) bool { sort.Ints(target) @@ -114,6 +122,8 @@ func canBeEqual(target []int, arr []int) bool { } ``` +#### TypeScript + ```ts function canBeEqual(target: number[], arr: number[]): boolean { target.sort((a, b) => a - b); @@ -122,6 +132,8 @@ function canBeEqual(target: number[], arr: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn can_be_equal(mut target: Vec, mut arr: Vec) -> bool { @@ -132,6 +144,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** @@ -147,6 +161,8 @@ class Solution { } ``` +#### C + ```c int compare(const void* a, const void* b) { return (*(int*) a - *(int*) b); @@ -180,12 +196,16 @@ The time complexity is $O(n + M)$, and the space complexity is $O(M)$. Here, $n$ +#### Python3 + ```python class Solution: def canBeEqual(self, target: List[int], arr: List[int]) -> bool: return Counter(target) == Counter(arr) ``` +#### Java + ```java class Solution { public boolean canBeEqual(int[] target, int[] arr) { @@ -202,6 +222,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -219,6 +241,8 @@ public: }; ``` +#### Go + ```go func canBeEqual(target []int, arr []int) bool { cnt1 := make([]int, 1001) @@ -233,6 +257,8 @@ func canBeEqual(target []int, arr []int) bool { } ``` +#### TypeScript + ```ts function canBeEqual(target: number[], arr: number[]): boolean { const n = target.length; @@ -245,6 +271,8 @@ function canBeEqual(target: number[], arr: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn can_be_equal(mut target: Vec, mut arr: Vec) -> bool { diff --git a/solution/1400-1499/1461.Check If a String Contains All Binary Codes of Size K/README.md b/solution/1400-1499/1461.Check If a String Contains All Binary Codes of Size K/README.md index 2bee027d1891d..4729951172038 100644 --- a/solution/1400-1499/1461.Check If a String Contains All Binary Codes of Size K/README.md +++ b/solution/1400-1499/1461.Check If a String Contains All Binary Codes of Size K/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def hasAllCodes(self, s: str, k: int) -> bool: @@ -81,6 +83,8 @@ class Solution: return len(ss) == 1 << k ``` +#### Java + ```java class Solution { public boolean hasAllCodes(String s, int k) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func hasAllCodes(s string, k int) bool { ss := map[string]bool{} @@ -130,6 +138,8 @@ func hasAllCodes(s string, k int) bool { +#### Python3 + ```python class Solution: def hasAllCodes(self, s: str, k: int) -> bool: @@ -146,6 +156,8 @@ class Solution: return all(v for v in vis) ``` +#### Java + ```java class Solution { public boolean hasAllCodes(String s, int k) { @@ -172,6 +184,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -194,6 +208,8 @@ public: }; ``` +#### Go + ```go func hasAllCodes(s string, k int) bool { n := len(s) diff --git a/solution/1400-1499/1461.Check If a String Contains All Binary Codes of Size K/README_EN.md b/solution/1400-1499/1461.Check If a String Contains All Binary Codes of Size K/README_EN.md index fdaa0f0ca6417..599fbce9fc112 100644 --- a/solution/1400-1499/1461.Check If a String Contains All Binary Codes of Size K/README_EN.md +++ b/solution/1400-1499/1461.Check If a String Contains All Binary Codes of Size K/README_EN.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def hasAllCodes(self, s: str, k: int) -> bool: @@ -75,6 +77,8 @@ class Solution: return len(ss) == 1 << k ``` +#### Java + ```java class Solution { public boolean hasAllCodes(String s, int k) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -100,6 +106,8 @@ public: }; ``` +#### Go + ```go func hasAllCodes(s string, k int) bool { ss := map[string]bool{} @@ -120,6 +128,8 @@ func hasAllCodes(s string, k int) bool { +#### Python3 + ```python class Solution: def hasAllCodes(self, s: str, k: int) -> bool: @@ -136,6 +146,8 @@ class Solution: return all(v for v in vis) ``` +#### Java + ```java class Solution { public boolean hasAllCodes(String s, int k) { @@ -162,6 +174,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -184,6 +198,8 @@ public: }; ``` +#### Go + ```go func hasAllCodes(s string, k int) bool { n := len(s) diff --git a/solution/1400-1499/1462.Course Schedule IV/README.md b/solution/1400-1499/1462.Course Schedule IV/README.md index 9a66061f4c232..d662b1c7ad2f7 100644 --- a/solution/1400-1499/1462.Course Schedule IV/README.md +++ b/solution/1400-1499/1462.Course Schedule IV/README.md @@ -103,6 +103,8 @@ tags: +#### Python3 + ```python class Solution: def checkIfPrerequisite( @@ -119,6 +121,8 @@ class Solution: return [f[a][b] for a, b in queries] ``` +#### Java + ```java class Solution { public List checkIfPrerequisite(int n, int[][] prerequisites, int[][] queries) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func checkIfPrerequisite(n int, prerequisites [][]int, queries [][]int) (ans []bool) { f := make([][]bool, n) @@ -190,6 +198,8 @@ func checkIfPrerequisite(n int, prerequisites [][]int, queries [][]int) (ans []b } ``` +#### TypeScript + ```ts function checkIfPrerequisite(n: number, prerequisites: number[][], queries: number[][]): boolean[] { const f = Array.from({ length: n }, () => Array(n).fill(false)); @@ -227,6 +237,8 @@ function checkIfPrerequisite(n: number, prerequisites: number[][], queries: numb +#### Python3 + ```python class Solution: def checkIfPrerequisite( @@ -251,6 +263,8 @@ class Solution: return [f[a][b] for a, b in queries] ``` +#### Java + ```java class Solution { public List checkIfPrerequisite(int n, int[][] prerequisites, int[][] queries) { @@ -289,6 +303,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -329,6 +345,8 @@ public: }; ``` +#### Go + ```go func checkIfPrerequisite(n int, prerequisites [][]int, queries [][]int) (ans []bool) { f := make([][]bool, n) @@ -369,6 +387,8 @@ func checkIfPrerequisite(n int, prerequisites [][]int, queries [][]int) (ans []b } ``` +#### TypeScript + ```ts function checkIfPrerequisite(n: number, prerequisites: number[][], queries: number[][]): boolean[] { const f = Array.from({ length: n }, () => Array(n).fill(false)); diff --git a/solution/1400-1499/1462.Course Schedule IV/README_EN.md b/solution/1400-1499/1462.Course Schedule IV/README_EN.md index 24e596f7f2fb6..80fff691fe917 100644 --- a/solution/1400-1499/1462.Course Schedule IV/README_EN.md +++ b/solution/1400-1499/1462.Course Schedule IV/README_EN.md @@ -84,6 +84,8 @@ Course 0 is not a prerequisite of course 1, but the opposite is true. +#### Python3 + ```python class Solution: def checkIfPrerequisite( @@ -100,6 +102,8 @@ class Solution: return [f[a][b] for a, b in queries] ``` +#### Java + ```java class Solution { public List checkIfPrerequisite(int n, int[][] prerequisites, int[][] queries) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func checkIfPrerequisite(n int, prerequisites [][]int, queries [][]int) (ans []bool) { f := make([][]bool, n) @@ -171,6 +179,8 @@ func checkIfPrerequisite(n int, prerequisites [][]int, queries [][]int) (ans []b } ``` +#### TypeScript + ```ts function checkIfPrerequisite(n: number, prerequisites: number[][], queries: number[][]): boolean[] { const f = Array.from({ length: n }, () => Array(n).fill(false)); @@ -196,6 +206,8 @@ function checkIfPrerequisite(n: number, prerequisites: number[][], queries: numb +#### Python3 + ```python class Solution: def checkIfPrerequisite( @@ -220,6 +232,8 @@ class Solution: return [f[a][b] for a, b in queries] ``` +#### Java + ```java class Solution { public List checkIfPrerequisite(int n, int[][] prerequisites, int[][] queries) { @@ -258,6 +272,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -298,6 +314,8 @@ public: }; ``` +#### Go + ```go func checkIfPrerequisite(n int, prerequisites [][]int, queries [][]int) (ans []bool) { f := make([][]bool, n) @@ -338,6 +356,8 @@ func checkIfPrerequisite(n int, prerequisites [][]int, queries [][]int) (ans []b } ``` +#### TypeScript + ```ts function checkIfPrerequisite(n: number, prerequisites: number[][], queries: number[][]): boolean[] { const f = Array.from({ length: n }, () => Array(n).fill(false)); diff --git a/solution/1400-1499/1463.Cherry Pickup II/README.md b/solution/1400-1499/1463.Cherry Pickup II/README.md index b443df97da2ba..1c352bf992c97 100644 --- a/solution/1400-1499/1463.Cherry Pickup II/README.md +++ b/solution/1400-1499/1463.Cherry Pickup II/README.md @@ -107,6 +107,8 @@ $$ +#### Python3 + ```python class Solution: def cherryPickup(self, grid: List[List[int]]) -> int: @@ -124,6 +126,8 @@ class Solution: return max(f[-1][j1][j2] for j1, j2 in product(range(n), range(n))) ``` +#### Java + ```java class Solution { public int cherryPickup(int[][] grid) { @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go func cherryPickup(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -231,6 +239,8 @@ func cherryPickup(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function cherryPickup(grid: number[][]): number { const m = grid.length; @@ -269,6 +279,8 @@ function cherryPickup(grid: number[][]): number { +#### Python3 + ```python class Solution: def cherryPickup(self, grid: List[List[int]]) -> int: @@ -288,6 +300,8 @@ class Solution: return max(f[j1][j2] for j1, j2 in product(range(n), range(n))) ``` +#### Java + ```java class Solution { public int cherryPickup(int[][] grid) { @@ -327,6 +341,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -361,6 +377,8 @@ public: }; ``` +#### Go + ```go func cherryPickup(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -400,6 +418,8 @@ func cherryPickup(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function cherryPickup(grid: number[][]): number { const m = grid.length; diff --git a/solution/1400-1499/1463.Cherry Pickup II/README_EN.md b/solution/1400-1499/1463.Cherry Pickup II/README_EN.md index 5477fbc5d16ce..02509b43ef465 100644 --- a/solution/1400-1499/1463.Cherry Pickup II/README_EN.md +++ b/solution/1400-1499/1463.Cherry Pickup II/README_EN.md @@ -96,6 +96,8 @@ The time complexity is $O(m \times n^2)$, and the space complexity is $O(m \time +#### Python3 + ```python class Solution: def cherryPickup(self, grid: List[List[int]]) -> int: @@ -113,6 +115,8 @@ class Solution: return max(f[-1][j1][j2] for j1, j2 in product(range(n), range(n))) ``` +#### Java + ```java class Solution { public int cherryPickup(int[][] grid) { @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -182,6 +188,8 @@ public: }; ``` +#### Go + ```go func cherryPickup(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -220,6 +228,8 @@ func cherryPickup(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function cherryPickup(grid: number[][]): number { const m = grid.length; @@ -258,6 +268,8 @@ Notice that the calculation of $f[i][j_1][j_2]$ is only related to $f[i-1][y_1][ +#### Python3 + ```python class Solution: def cherryPickup(self, grid: List[List[int]]) -> int: @@ -277,6 +289,8 @@ class Solution: return max(f[j1][j2] for j1, j2 in product(range(n), range(n))) ``` +#### Java + ```java class Solution { public int cherryPickup(int[][] grid) { @@ -316,6 +330,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -350,6 +366,8 @@ public: }; ``` +#### Go + ```go func cherryPickup(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -389,6 +407,8 @@ func cherryPickup(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function cherryPickup(grid: number[][]): number { const m = grid.length; diff --git a/solution/1400-1499/1464.Maximum Product of Two Elements in an Array/README.md b/solution/1400-1499/1464.Maximum Product of Two Elements in an Array/README.md index 13c2a71254ba0..d0b9c4a29c18c 100644 --- a/solution/1400-1499/1464.Maximum Product of Two Elements in an Array/README.md +++ b/solution/1400-1499/1464.Maximum Product of Two Elements in an Array/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def maxProduct(self, nums: List[int]) -> int: @@ -79,6 +81,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxProduct(int[] nums) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func maxProduct(nums []int) int { ans := 0 @@ -125,6 +133,8 @@ func maxProduct(nums []int) int { } ``` +#### TypeScript + ```ts function maxProduct(nums: number[]): number { const n = nums.length; @@ -141,6 +151,8 @@ function maxProduct(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_product(nums: Vec) -> i32 { @@ -159,6 +171,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** @@ -181,6 +195,8 @@ class Solution { } ``` +#### C + ```c int maxProduct(int* nums, int numsSize) { int max = 0; @@ -212,6 +228,8 @@ int maxProduct(int* nums, int numsSize) { +#### Python3 + ```python class Solution: def maxProduct(self, nums: List[int]) -> int: @@ -219,6 +237,8 @@ class Solution: return (nums[-1] - 1) * (nums[-2] - 1) ``` +#### Java + ```java class Solution { public int maxProduct(int[] nums) { @@ -229,6 +249,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -239,6 +261,8 @@ public: }; ``` +#### Go + ```go func maxProduct(nums []int) int { sort.Ints(nums) @@ -247,6 +271,8 @@ func maxProduct(nums []int) int { } ``` +#### TypeScript + ```ts function maxProduct(nums: number[]): number { let max = 0; @@ -275,6 +301,8 @@ function maxProduct(nums: number[]): number { +#### Python3 + ```python class Solution: def maxProduct(self, nums: List[int]) -> int: @@ -287,6 +315,8 @@ class Solution: return (a - 1) * (b - 1) ``` +#### Java + ```java class Solution { public int maxProduct(int[] nums) { @@ -304,6 +334,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -322,6 +354,8 @@ public: }; ``` +#### Go + ```go func maxProduct(nums []int) int { a, b := 0, 0 diff --git a/solution/1400-1499/1464.Maximum Product of Two Elements in an Array/README_EN.md b/solution/1400-1499/1464.Maximum Product of Two Elements in an Array/README_EN.md index da1aeaa3aff2a..d134959b7184a 100644 --- a/solution/1400-1499/1464.Maximum Product of Two Elements in an Array/README_EN.md +++ b/solution/1400-1499/1464.Maximum Product of Two Elements in an Array/README_EN.md @@ -64,6 +64,8 @@ Given the array of integers nums, you will choose two different ind +#### Python3 + ```python class Solution: def maxProduct(self, nums: List[int]) -> int: @@ -74,6 +76,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxProduct(int[] nums) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func maxProduct(nums []int) int { ans := 0 @@ -120,6 +128,8 @@ func maxProduct(nums []int) int { } ``` +#### TypeScript + ```ts function maxProduct(nums: number[]): number { const n = nums.length; @@ -136,6 +146,8 @@ function maxProduct(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_product(nums: Vec) -> i32 { @@ -154,6 +166,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** @@ -176,6 +190,8 @@ class Solution { } ``` +#### C + ```c int maxProduct(int* nums, int numsSize) { int max = 0; @@ -203,6 +219,8 @@ int maxProduct(int* nums, int numsSize) { +#### Python3 + ```python class Solution: def maxProduct(self, nums: List[int]) -> int: @@ -210,6 +228,8 @@ class Solution: return (nums[-1] - 1) * (nums[-2] - 1) ``` +#### Java + ```java class Solution { public int maxProduct(int[] nums) { @@ -220,6 +240,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -230,6 +252,8 @@ public: }; ``` +#### Go + ```go func maxProduct(nums []int) int { sort.Ints(nums) @@ -238,6 +262,8 @@ func maxProduct(nums []int) int { } ``` +#### TypeScript + ```ts function maxProduct(nums: number[]): number { let max = 0; @@ -264,6 +290,8 @@ function maxProduct(nums: number[]): number { +#### Python3 + ```python class Solution: def maxProduct(self, nums: List[int]) -> int: @@ -276,6 +304,8 @@ class Solution: return (a - 1) * (b - 1) ``` +#### Java + ```java class Solution { public int maxProduct(int[] nums) { @@ -293,6 +323,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -311,6 +343,8 @@ public: }; ``` +#### Go + ```go func maxProduct(nums []int) int { a, b := 0, 0 diff --git a/solution/1400-1499/1465.Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts/README.md b/solution/1400-1499/1465.Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts/README.md index f8a6b9cfd1c86..e72582a551d8e 100644 --- a/solution/1400-1499/1465.Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts/README.md +++ b/solution/1400-1499/1465.Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def maxArea( @@ -101,6 +103,8 @@ class Solution: return (x * y) % (10**9 + 7) ``` +#### Java + ```java class Solution { public int maxArea(int h, int w, int[] horizontalCuts, int[] verticalCuts) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func maxArea(h int, w int, horizontalCuts []int, verticalCuts []int) int { horizontalCuts = append(horizontalCuts, []int{0, h}...) @@ -163,6 +171,8 @@ func maxArea(h int, w int, horizontalCuts []int, verticalCuts []int) int { } ``` +#### TypeScript + ```ts function maxArea(h: number, w: number, horizontalCuts: number[], verticalCuts: number[]): number { const mod = 1e9 + 7; @@ -181,6 +191,8 @@ function maxArea(h: number, w: number, horizontalCuts: number[], verticalCuts: n } ``` +#### Rust + ```rust impl Solution { pub fn max_area( diff --git a/solution/1400-1499/1465.Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts/README_EN.md b/solution/1400-1499/1465.Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts/README_EN.md index 662b0223be5af..21103fd3cb258 100644 --- a/solution/1400-1499/1465.Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts/README_EN.md +++ b/solution/1400-1499/1465.Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(m\log m + n\log n)$, where $m$ and $n$ are the lengths +#### Python3 + ```python class Solution: def maxArea( @@ -96,6 +98,8 @@ class Solution: return (x * y) % (10**9 + 7) ``` +#### Java + ```java class Solution { public int maxArea(int h, int w, int[] horizontalCuts, int[] verticalCuts) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func maxArea(h int, w int, horizontalCuts []int, verticalCuts []int) int { horizontalCuts = append(horizontalCuts, []int{0, h}...) @@ -158,6 +166,8 @@ func maxArea(h int, w int, horizontalCuts []int, verticalCuts []int) int { } ``` +#### TypeScript + ```ts function maxArea(h: number, w: number, horizontalCuts: number[], verticalCuts: number[]): number { const mod = 1e9 + 7; @@ -176,6 +186,8 @@ function maxArea(h: number, w: number, horizontalCuts: number[], verticalCuts: n } ``` +#### Rust + ```rust impl Solution { pub fn max_area( diff --git a/solution/1400-1499/1466.Reorder Routes to Make All Paths Lead to the City Zero/README.md b/solution/1400-1499/1466.Reorder Routes to Make All Paths Lead to the City Zero/README.md index 79da04fab7dd6..a18469f60ff9c 100644 --- a/solution/1400-1499/1466.Reorder Routes to Make All Paths Lead to the City Zero/README.md +++ b/solution/1400-1499/1466.Reorder Routes to Make All Paths Lead to the City Zero/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def minReorder(self, n: int, connections: List[List[int]]) -> int: @@ -97,6 +99,8 @@ class Solution: return dfs(0, -1) ``` +#### Java + ```java class Solution { private List[] g; @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func minReorder(n int, connections [][]int) int { g := make([][][2]int, n) @@ -170,6 +178,8 @@ func minReorder(n int, connections [][]int) int { } ``` +#### TypeScript + ```ts function minReorder(n: number, connections: number[][]): number { const g: [number, number][][] = Array.from({ length: n }, () => []); @@ -190,6 +200,8 @@ function minReorder(n: number, connections: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_reorder(n: i32, connections: Vec>) -> i32 { diff --git a/solution/1400-1499/1466.Reorder Routes to Make All Paths Lead to the City Zero/README_EN.md b/solution/1400-1499/1466.Reorder Routes to Make All Paths Lead to the City Zero/README_EN.md index cbdaf8e214b27..94ddcfdc94ec1 100644 --- a/solution/1400-1499/1466.Reorder Routes to Make All Paths Lead to the City Zero/README_EN.md +++ b/solution/1400-1499/1466.Reorder Routes to Make All Paths Lead to the City Zero/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def minReorder(self, n: int, connections: List[List[int]]) -> int: @@ -96,6 +98,8 @@ class Solution: return dfs(0, -1) ``` +#### Java + ```java class Solution { private List[] g; @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func minReorder(n int, connections [][]int) int { g := make([][][2]int, n) @@ -169,6 +177,8 @@ func minReorder(n int, connections [][]int) int { } ``` +#### TypeScript + ```ts function minReorder(n: number, connections: number[][]): number { const g: [number, number][][] = Array.from({ length: n }, () => []); @@ -189,6 +199,8 @@ function minReorder(n: number, connections: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_reorder(n: i32, connections: Vec>) -> i32 { diff --git a/solution/1400-1499/1467.Probability of a Two Boxes Having The Same Number of Distinct Balls/README.md b/solution/1400-1499/1467.Probability of a Two Boxes Having The Same Number of Distinct Balls/README.md index 33b7799791486..687781d87a4c3 100644 --- a/solution/1400-1499/1467.Probability of a Two Boxes Having The Same Number of Distinct Balls/README.md +++ b/solution/1400-1499/1467.Probability of a Two Boxes Having The Same Number of Distinct Balls/README.md @@ -101,6 +101,8 @@ tags: +#### Python3 + ```python class Solution: def getProbability(self, balls: List[int]) -> float: @@ -121,6 +123,8 @@ class Solution: return dfs(0, n, 0) / comb(n << 1, n) ``` +#### Java + ```java class Solution { private int n; @@ -169,6 +173,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -209,6 +215,8 @@ public: }; ``` +#### Go + ```go func getProbability(balls []int) float64 { n, mx := 0, 0 @@ -272,6 +280,8 @@ func getProbability(balls []int) float64 { } ``` +#### TypeScript + ```ts function getProbability(balls: number[]): number { const n = balls.reduce((a, b) => a + b, 0) >> 1; diff --git a/solution/1400-1499/1467.Probability of a Two Boxes Having The Same Number of Distinct Balls/README_EN.md b/solution/1400-1499/1467.Probability of a Two Boxes Having The Same Number of Distinct Balls/README_EN.md index 66737101df001..9621c5351f20d 100644 --- a/solution/1400-1499/1467.Probability of a Two Boxes Having The Same Number of Distinct Balls/README_EN.md +++ b/solution/1400-1499/1467.Probability of a Two Boxes Having The Same Number of Distinct Balls/README_EN.md @@ -84,6 +84,8 @@ Probability = 108 / 180 = 0.6 +#### Python3 + ```python class Solution: def getProbability(self, balls: List[int]) -> float: @@ -104,6 +106,8 @@ class Solution: return dfs(0, n, 0) / comb(n << 1, n) ``` +#### Java + ```java class Solution { private int n; @@ -152,6 +156,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -192,6 +198,8 @@ public: }; ``` +#### Go + ```go func getProbability(balls []int) float64 { n, mx := 0, 0 @@ -255,6 +263,8 @@ func getProbability(balls []int) float64 { } ``` +#### TypeScript + ```ts function getProbability(balls: number[]): number { const n = balls.reduce((a, b) => a + b, 0) >> 1; diff --git a/solution/1400-1499/1468.Calculate Salaries/README.md b/solution/1400-1499/1468.Calculate Salaries/README.md index bc73248ac1f5b..d8353c24be287 100644 --- a/solution/1400-1499/1468.Calculate Salaries/README.md +++ b/solution/1400-1499/1468.Calculate Salaries/README.md @@ -100,6 +100,8 @@ Salaries 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1400-1499/1468.Calculate Salaries/README_EN.md b/solution/1400-1499/1468.Calculate Salaries/README_EN.md index e403c9ba6cb91..ef635bc52c2b2 100644 --- a/solution/1400-1499/1468.Calculate Salaries/README_EN.md +++ b/solution/1400-1499/1468.Calculate Salaries/README_EN.md @@ -100,6 +100,8 @@ For example, Salary for Morninngcat (3, 15) after taxes = 7777 - 7777 * (24 / 10 +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1400-1499/1469.Find All The Lonely Nodes/README.md b/solution/1400-1499/1469.Find All The Lonely Nodes/README.md index ab566c8a1867d..96e06fde4b73f 100644 --- a/solution/1400-1499/1469.Find All The Lonely Nodes/README.md +++ b/solution/1400-1499/1469.Find All The Lonely Nodes/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -119,6 +121,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -159,6 +163,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -189,6 +195,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/1400-1499/1469.Find All The Lonely Nodes/README_EN.md b/solution/1400-1499/1469.Find All The Lonely Nodes/README_EN.md index 7b974b0b341f4..d3f68549623b9 100644 --- a/solution/1400-1499/1469.Find All The Lonely Nodes/README_EN.md +++ b/solution/1400-1499/1469.Find All The Lonely Nodes/README_EN.md @@ -71,6 +71,8 @@ All other nodes are lonely. +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/1400-1499/1470.Shuffle the Array/README.md b/solution/1400-1499/1470.Shuffle the Array/README.md index 09d19761dbb71..5eccc5d9fc7b5 100644 --- a/solution/1400-1499/1470.Shuffle the Array/README.md +++ b/solution/1400-1499/1470.Shuffle the Array/README.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def shuffle(self, nums: List[int], n: int) -> List[int]: @@ -73,6 +75,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] shuffle(int[] nums, int n) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -100,6 +106,8 @@ public: }; ``` +#### Go + ```go func shuffle(nums []int, n int) []int { var ans []int @@ -111,6 +119,8 @@ func shuffle(nums []int, n int) []int { } ``` +#### TypeScript + ```ts function shuffle(nums: number[], n: number): number[] { let ans = []; @@ -121,6 +131,8 @@ function shuffle(nums: number[], n: number): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn shuffle(nums: Vec, n: i32) -> Vec { @@ -135,6 +147,8 @@ impl Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). @@ -160,6 +174,8 @@ int* shuffle(int* nums, int numsSize, int n, int* returnSize) { +#### Python3 + ```python class Solution: def shuffle(self, nums: List[int], n: int) -> List[int]: @@ -167,6 +183,8 @@ class Solution: return nums ``` +#### Rust + ```rust impl Solution { pub fn shuffle(mut nums: Vec, n: i32) -> Vec { diff --git a/solution/1400-1499/1470.Shuffle the Array/README_EN.md b/solution/1400-1499/1470.Shuffle the Array/README_EN.md index f8c9188a736a1..9f900c27ae752 100644 --- a/solution/1400-1499/1470.Shuffle the Array/README_EN.md +++ b/solution/1400-1499/1470.Shuffle the Array/README_EN.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def shuffle(self, nums: List[int], n: int) -> List[int]: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] shuffle(int[] nums, int n) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func shuffle(nums []int, n int) []int { var ans []int @@ -128,6 +136,8 @@ func shuffle(nums []int, n int) []int { } ``` +#### TypeScript + ```ts function shuffle(nums: number[], n: number): number[] { let ans = []; @@ -138,6 +148,8 @@ function shuffle(nums: number[], n: number): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn shuffle(nums: Vec, n: i32) -> Vec { @@ -152,6 +164,8 @@ impl Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). @@ -177,6 +191,8 @@ int* shuffle(int* nums, int numsSize, int n, int* returnSize) { +#### Python3 + ```python class Solution: def shuffle(self, nums: List[int], n: int) -> List[int]: @@ -184,6 +200,8 @@ class Solution: return nums ``` +#### Rust + ```rust impl Solution { pub fn shuffle(mut nums: Vec, n: i32) -> Vec { diff --git a/solution/1400-1499/1471.The k Strongest Values in an Array/README.md b/solution/1400-1499/1471.The k Strongest Values in an Array/README.md index 94998978caf7f..aff9091de0ada 100644 --- a/solution/1400-1499/1471.The k Strongest Values in an Array/README.md +++ b/solution/1400-1499/1471.The k Strongest Values in an Array/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class Solution: def getStrongest(self, arr: List[int], k: int) -> List[int]: @@ -105,6 +107,8 @@ class Solution: return arr[:k] ``` +#### Java + ```java class Solution { public int[] getStrongest(int[] arr, int k) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func getStrongest(arr []int, k int) []int { sort.Ints(arr) diff --git a/solution/1400-1499/1471.The k Strongest Values in an Array/README_EN.md b/solution/1400-1499/1471.The k Strongest Values in an Array/README_EN.md index 4b1abd939472a..f4b65f8b482ae 100644 --- a/solution/1400-1499/1471.The k Strongest Values in an Array/README_EN.md +++ b/solution/1400-1499/1471.The k Strongest Values in an Array/README_EN.md @@ -80,6 +80,8 @@ Any permutation of [11,8,6,6,7] is accepted. +#### Python3 + ```python class Solution: def getStrongest(self, arr: List[int], k: int) -> List[int]: @@ -89,6 +91,8 @@ class Solution: return arr[:k] ``` +#### Java + ```java class Solution { public int[] getStrongest(int[] arr, int k) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func getStrongest(arr []int, k int) []int { sort.Ints(arr) diff --git a/solution/1400-1499/1472.Design Browser History/README.md b/solution/1400-1499/1472.Design Browser History/README.md index 6bb22f175fc29..b11b988129cd2 100644 --- a/solution/1400-1499/1472.Design Browser History/README.md +++ b/solution/1400-1499/1472.Design Browser History/README.md @@ -82,6 +82,8 @@ browserHistory.back(7); // 你原本在浏览 "google.com +#### Python3 + ```python class BrowserHistory: def __init__(self, homepage: str): @@ -113,6 +115,8 @@ class BrowserHistory: # param_3 = obj.forward(steps) ``` +#### Java + ```java class BrowserHistory { private Deque stk1 = new ArrayDeque<>(); @@ -151,6 +155,8 @@ class BrowserHistory { */ ``` +#### C++ + ```cpp class BrowserHistory { public: @@ -192,6 +198,8 @@ public: */ ``` +#### Go + ```go type BrowserHistory struct { stk1 []string diff --git a/solution/1400-1499/1472.Design Browser History/README_EN.md b/solution/1400-1499/1472.Design Browser History/README_EN.md index a47537f0fbdc2..6e123e6f91752 100644 --- a/solution/1400-1499/1472.Design Browser History/README_EN.md +++ b/solution/1400-1499/1472.Design Browser History/README_EN.md @@ -79,6 +79,8 @@ browserHistory.back(7); // You are in "google.com", +#### Python3 + ```python class BrowserHistory: def __init__(self, homepage: str): @@ -110,6 +112,8 @@ class BrowserHistory: # param_3 = obj.forward(steps) ``` +#### Java + ```java class BrowserHistory { private Deque stk1 = new ArrayDeque<>(); @@ -148,6 +152,8 @@ class BrowserHistory { */ ``` +#### C++ + ```cpp class BrowserHistory { public: @@ -189,6 +195,8 @@ public: */ ``` +#### Go + ```go type BrowserHistory struct { stk1 []string diff --git a/solution/1400-1499/1473.Paint House III/README.md b/solution/1400-1499/1473.Paint House III/README.md index 8d0662be20fdf..7a79a23cb4795 100644 --- a/solution/1400-1499/1473.Paint House III/README.md +++ b/solution/1400-1499/1473.Paint House III/README.md @@ -113,6 +113,8 @@ $$ +#### Python3 + ```python class Solution: def minCost( @@ -150,6 +152,8 @@ class Solution: return -1 if ans >= inf else ans ``` +#### Java + ```java class Solution { public int minCost(int[] houses, int[][] cost, int m, int n, int target) { @@ -203,6 +207,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -251,6 +257,8 @@ public: }; ``` +#### Go + ```go func minCost(houses []int, cost [][]int, m int, n int, target int) int { f := make([][][]int, m) @@ -308,6 +316,8 @@ func minCost(houses []int, cost [][]int, m int, n int, target int) int { } ``` +#### TypeScript + ```ts function minCost(houses: number[], cost: number[][], m: number, n: number, target: number): number { const inf = 1 << 30; diff --git a/solution/1400-1499/1473.Paint House III/README_EN.md b/solution/1400-1499/1473.Paint House III/README_EN.md index f88ef982909b3..f4a8885ba9e6e 100644 --- a/solution/1400-1499/1473.Paint House III/README_EN.md +++ b/solution/1400-1499/1473.Paint House III/README_EN.md @@ -88,6 +88,8 @@ Cost of paint the first and last house (10 + 1) = 11. +#### Python3 + ```python class Solution: def minCost( @@ -125,6 +127,8 @@ class Solution: return -1 if ans >= inf else ans ``` +#### Java + ```java class Solution { public int minCost(int[] houses, int[][] cost, int m, int n, int target) { @@ -178,6 +182,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -226,6 +232,8 @@ public: }; ``` +#### Go + ```go func minCost(houses []int, cost [][]int, m int, n int, target int) int { f := make([][][]int, m) @@ -283,6 +291,8 @@ func minCost(houses []int, cost [][]int, m int, n int, target int) int { } ``` +#### TypeScript + ```ts function minCost(houses: number[], cost: number[][], m: number, n: number, target: number): number { const inf = 1 << 30; diff --git a/solution/1400-1499/1474.Delete N Nodes After M Nodes of a Linked List/README.md b/solution/1400-1499/1474.Delete N Nodes After M Nodes of a Linked List/README.md index c45a9c12ca080..37cffa6267c27 100644 --- a/solution/1400-1499/1474.Delete N Nodes After M Nodes of a Linked List/README.md +++ b/solution/1400-1499/1474.Delete N Nodes After M Nodes of a Linked List/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -116,6 +118,8 @@ class Solution: return head ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -183,6 +189,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. diff --git a/solution/1400-1499/1474.Delete N Nodes After M Nodes of a Linked List/README_EN.md b/solution/1400-1499/1474.Delete N Nodes After M Nodes of a Linked List/README_EN.md index 70c93ab4cd62e..212b1792bb43e 100644 --- a/solution/1400-1499/1474.Delete N Nodes After M Nodes of a Linked List/README_EN.md +++ b/solution/1400-1499/1474.Delete N Nodes After M Nodes of a Linked List/README_EN.md @@ -71,6 +71,8 @@ Head of the linked list after removing nodes is returned. +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -95,6 +97,8 @@ class Solution: return head ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. diff --git a/solution/1400-1499/1475.Final Prices With a Special Discount in a Shop/README.md b/solution/1400-1499/1475.Final Prices With a Special Discount in a Shop/README.md index 513f76019b095..f04d06a12411b 100644 --- a/solution/1400-1499/1475.Final Prices With a Special Discount in a Shop/README.md +++ b/solution/1400-1499/1475.Final Prices With a Special Discount in a Shop/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def finalPrices(self, prices: List[int]) -> List[int]: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] finalPrices(int[] prices) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func finalPrices(prices []int) []int { n := len(prices) @@ -144,6 +152,8 @@ func finalPrices(prices []int) []int { } ``` +#### TypeScript + ```ts function finalPrices(prices: number[]): number[] { const n = prices.length; @@ -161,6 +171,8 @@ function finalPrices(prices: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn final_prices(prices: Vec) -> Vec { @@ -180,6 +192,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} prices @@ -198,6 +212,8 @@ var finalPrices = function (prices) { }; ``` +#### PHP + ```php class Solution { /** @@ -242,6 +258,8 @@ for i in range(n): +#### Python3 + ```python class Solution: def finalPrices(self, prices: List[int]) -> List[int]: @@ -254,6 +272,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] finalPrices(int[] prices) { @@ -272,6 +292,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -290,6 +312,8 @@ public: }; ``` +#### Go + ```go func finalPrices(prices []int) []int { var stk []int @@ -307,6 +331,8 @@ func finalPrices(prices []int) []int { } ``` +#### TypeScript + ```ts function finalPrices(prices: number[]): number[] { const n = prices.length; @@ -333,6 +359,8 @@ function finalPrices(prices: number[]): number[] { +#### Python3 + ```python class Solution: def finalPrices(self, prices: List[int]) -> List[int]: @@ -347,6 +375,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] finalPrices(int[] prices) { @@ -368,6 +398,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -390,6 +422,8 @@ public: }; ``` +#### Go + ```go func finalPrices(prices []int) []int { stk := []int{} @@ -409,6 +443,8 @@ func finalPrices(prices []int) []int { } ``` +#### TypeScript + ```ts function finalPrices(prices: number[]): number[] { const n = prices.length; diff --git a/solution/1400-1499/1475.Final Prices With a Special Discount in a Shop/README_EN.md b/solution/1400-1499/1475.Final Prices With a Special Discount in a Shop/README_EN.md index ffba37f7d583d..b86dea9c66387 100644 --- a/solution/1400-1499/1475.Final Prices With a Special Discount in a Shop/README_EN.md +++ b/solution/1400-1499/1475.Final Prices With a Special Discount in a Shop/README_EN.md @@ -72,6 +72,8 @@ For items 3 and 4 you will not receive any discount at all. +#### Python3 + ```python class Solution: def finalPrices(self, prices: List[int]) -> List[int]: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] finalPrices(int[] prices) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func finalPrices(prices []int) []int { n := len(prices) @@ -141,6 +149,8 @@ func finalPrices(prices []int) []int { } ``` +#### TypeScript + ```ts function finalPrices(prices: number[]): number[] { const n = prices.length; @@ -158,6 +168,8 @@ function finalPrices(prices: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn final_prices(prices: Vec) -> Vec { @@ -177,6 +189,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} prices @@ -195,6 +209,8 @@ var finalPrices = function (prices) { }; ``` +#### PHP + ```php class Solution { /** @@ -225,6 +241,8 @@ class Solution { +#### Python3 + ```python class Solution: def finalPrices(self, prices: List[int]) -> List[int]: @@ -237,6 +255,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] finalPrices(int[] prices) { @@ -255,6 +275,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -273,6 +295,8 @@ public: }; ``` +#### Go + ```go func finalPrices(prices []int) []int { var stk []int @@ -290,6 +314,8 @@ func finalPrices(prices []int) []int { } ``` +#### TypeScript + ```ts function finalPrices(prices: number[]): number[] { const n = prices.length; @@ -316,6 +342,8 @@ function finalPrices(prices: number[]): number[] { +#### Python3 + ```python class Solution: def finalPrices(self, prices: List[int]) -> List[int]: @@ -330,6 +358,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] finalPrices(int[] prices) { @@ -351,6 +381,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -373,6 +405,8 @@ public: }; ``` +#### Go + ```go func finalPrices(prices []int) []int { stk := []int{} @@ -392,6 +426,8 @@ func finalPrices(prices []int) []int { } ``` +#### TypeScript + ```ts function finalPrices(prices: number[]): number[] { const n = prices.length; diff --git a/solution/1400-1499/1476.Subrectangle Queries/README.md b/solution/1400-1499/1476.Subrectangle Queries/README.md index be657aef25c4c..4ea1b0684ab18 100644 --- a/solution/1400-1499/1476.Subrectangle Queries/README.md +++ b/solution/1400-1499/1476.Subrectangle Queries/README.md @@ -112,6 +112,8 @@ subrectangleQueries.getValue(2, 2); // 返回 20 +#### Python3 + ```python class SubrectangleQueries: def __init__(self, rectangle: List[List[int]]): @@ -136,6 +138,8 @@ class SubrectangleQueries: # param_2 = obj.getValue(row,col) ``` +#### Java + ```java class SubrectangleQueries { private int[][] g; @@ -167,6 +171,8 @@ class SubrectangleQueries { */ ``` +#### C++ + ```cpp class SubrectangleQueries { public: @@ -200,6 +206,8 @@ public: */ ``` +#### Go + ```go type SubrectangleQueries struct { g [][]int @@ -232,6 +240,8 @@ func (this *SubrectangleQueries) GetValue(row int, col int) int { */ ``` +#### TypeScript + ```ts class SubrectangleQueries { g: number[][]; diff --git a/solution/1400-1499/1476.Subrectangle Queries/README_EN.md b/solution/1400-1499/1476.Subrectangle Queries/README_EN.md index 1dd458be3b496..21d9243834c67 100644 --- a/solution/1400-1499/1476.Subrectangle Queries/README_EN.md +++ b/solution/1400-1499/1476.Subrectangle Queries/README_EN.md @@ -112,6 +112,8 @@ subrectangleQueries.getValue(2, 2); // return 20 +#### Python3 + ```python class SubrectangleQueries: def __init__(self, rectangle: List[List[int]]): @@ -136,6 +138,8 @@ class SubrectangleQueries: # param_2 = obj.getValue(row,col) ``` +#### Java + ```java class SubrectangleQueries { private int[][] g; @@ -167,6 +171,8 @@ class SubrectangleQueries { */ ``` +#### C++ + ```cpp class SubrectangleQueries { public: @@ -200,6 +206,8 @@ public: */ ``` +#### Go + ```go type SubrectangleQueries struct { g [][]int @@ -232,6 +240,8 @@ func (this *SubrectangleQueries) GetValue(row int, col int) int { */ ``` +#### TypeScript + ```ts class SubrectangleQueries { g: number[][]; diff --git a/solution/1400-1499/1477.Find Two Non-overlapping Sub-arrays Each With Target Sum/README.md b/solution/1400-1499/1477.Find Two Non-overlapping Sub-arrays Each With Target Sum/README.md index 84a107dfde060..f02ab74dd4299 100644 --- a/solution/1400-1499/1477.Find Two Non-overlapping Sub-arrays Each With Target Sum/README.md +++ b/solution/1400-1499/1477.Find Two Non-overlapping Sub-arrays Each With Target Sum/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: @@ -113,6 +115,8 @@ class Solution: return -1 if ans > n else ans ``` +#### Java + ```java class Solution { public int minSumOfLengths(int[] arr, int target) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go func minSumOfLengths(arr []int, target int) int { d := map[int]int{0: 0} diff --git a/solution/1400-1499/1477.Find Two Non-overlapping Sub-arrays Each With Target Sum/README_EN.md b/solution/1400-1499/1477.Find Two Non-overlapping Sub-arrays Each With Target Sum/README_EN.md index 1750f963adac5..74b866b75256c 100644 --- a/solution/1400-1499/1477.Find Two Non-overlapping Sub-arrays Each With Target Sum/README_EN.md +++ b/solution/1400-1499/1477.Find Two Non-overlapping Sub-arrays Each With Target Sum/README_EN.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: @@ -90,6 +92,8 @@ class Solution: return -1 if ans > n else ans ``` +#### Java + ```java class Solution { public int minSumOfLengths(int[] arr, int target) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func minSumOfLengths(arr []int, target int) int { d := map[int]int{0: 0} diff --git a/solution/1400-1499/1478.Allocate Mailboxes/README.md b/solution/1400-1499/1478.Allocate Mailboxes/README.md index 99f1efe1f2691..fc0bfc8f8c339 100644 --- a/solution/1400-1499/1478.Allocate Mailboxes/README.md +++ b/solution/1400-1499/1478.Allocate Mailboxes/README.md @@ -99,6 +99,8 @@ $$ +#### Python3 + ```python class Solution: def minDistance(self, houses: List[int], k: int) -> int: @@ -117,6 +119,8 @@ class Solution: return f[-1][k] ``` +#### Java + ```java class Solution { public int minDistance(int[] houses, int k) { @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func minDistance(houses []int, k int) int { sort.Ints(houses) diff --git a/solution/1400-1499/1478.Allocate Mailboxes/README_EN.md b/solution/1400-1499/1478.Allocate Mailboxes/README_EN.md index 8dfcb7fef60f3..339356b7ef93b 100644 --- a/solution/1400-1499/1478.Allocate Mailboxes/README_EN.md +++ b/solution/1400-1499/1478.Allocate Mailboxes/README_EN.md @@ -65,6 +65,8 @@ Minimum total distance from each houses to nearest mailboxes is |2-3| + |3-3| + +#### Python3 + ```python class Solution: def minDistance(self, houses: List[int], k: int) -> int: @@ -83,6 +85,8 @@ class Solution: return f[-1][k] ``` +#### Java + ```java class Solution { public int minDistance(int[] houses, int k) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func minDistance(houses []int, k int) int { sort.Ints(houses) diff --git a/solution/1400-1499/1479.Sales by Day of the Week/README.md b/solution/1400-1499/1479.Sales by Day of the Week/README.md index 06b4bf2e24f5d..90380a5e8b2bf 100644 --- a/solution/1400-1499/1479.Sales by Day of the Week/README.md +++ b/solution/1400-1499/1479.Sales by Day of the Week/README.md @@ -118,6 +118,8 @@ Orders 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1400-1499/1479.Sales by Day of the Week/README_EN.md b/solution/1400-1499/1479.Sales by Day of the Week/README_EN.md index 79968a30af52e..e0a51365357d6 100644 --- a/solution/1400-1499/1479.Sales by Day of the Week/README_EN.md +++ b/solution/1400-1499/1479.Sales by Day of the Week/README_EN.md @@ -120,6 +120,8 @@ There are no sales of T-shirts. +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1400-1499/1480.Running Sum of 1d Array/README.md b/solution/1400-1499/1480.Running Sum of 1d Array/README.md index 0721cd13cf2c9..a493a055096c3 100644 --- a/solution/1400-1499/1480.Running Sum of 1d Array/README.md +++ b/solution/1400-1499/1480.Running Sum of 1d Array/README.md @@ -66,12 +66,16 @@ tags: +#### Python3 + ```python class Solution: def runningSum(self, nums: List[int]) -> List[int]: return list(accumulate(nums)) ``` +#### Java + ```java class Solution { public int[] runningSum(int[] nums) { @@ -83,6 +87,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -93,6 +99,8 @@ public: }; ``` +#### Go + ```go func runningSum(nums []int) []int { for i := 1; i < len(nums); i++ { @@ -102,6 +110,8 @@ func runningSum(nums []int) []int { } ``` +#### TypeScript + ```ts function runningSum(nums: number[]): number[] { for (let i = 1; i < nums.length; ++i) { @@ -111,6 +121,8 @@ function runningSum(nums: number[]): number[] { } ``` +#### C# + ```cs public class Solution { public int[] RunningSum(int[] nums) { @@ -122,6 +134,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1400-1499/1480.Running Sum of 1d Array/README_EN.md b/solution/1400-1499/1480.Running Sum of 1d Array/README_EN.md index 4f590f8407558..adf601ac65680 100644 --- a/solution/1400-1499/1480.Running Sum of 1d Array/README_EN.md +++ b/solution/1400-1499/1480.Running Sum of 1d Array/README_EN.md @@ -67,12 +67,16 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def runningSum(self, nums: List[int]) -> List[int]: return list(accumulate(nums)) ``` +#### Java + ```java class Solution { public int[] runningSum(int[] nums) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -94,6 +100,8 @@ public: }; ``` +#### Go + ```go func runningSum(nums []int) []int { for i := 1; i < len(nums); i++ { @@ -103,6 +111,8 @@ func runningSum(nums []int) []int { } ``` +#### TypeScript + ```ts function runningSum(nums: number[]): number[] { for (let i = 1; i < nums.length; ++i) { @@ -112,6 +122,8 @@ function runningSum(nums: number[]): number[] { } ``` +#### C# + ```cs public class Solution { public int[] RunningSum(int[] nums) { @@ -123,6 +135,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1400-1499/1481.Least Number of Unique Integers after K Removals/README.md b/solution/1400-1499/1481.Least Number of Unique Integers after K Removals/README.md index 283ce55433b0e..882fd0c11f691 100644 --- a/solution/1400-1499/1481.Least Number of Unique Integers after K Removals/README.md +++ b/solution/1400-1499/1481.Least Number of Unique Integers after K Removals/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def findLeastNumOfUniqueInts(self, arr: List[int], k: int) -> int: @@ -81,6 +83,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { public int findLeastNumOfUniqueInts(int[] arr, int k) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func findLeastNumOfUniqueInts(arr []int, k int) int { cnt := map[int]int{} @@ -146,6 +154,8 @@ func findLeastNumOfUniqueInts(arr []int, k int) int { } ``` +#### TypeScript + ```ts function findLeastNumOfUniqueInts(arr: number[], k: number): number { const cnt: Map = new Map(); diff --git a/solution/1400-1499/1481.Least Number of Unique Integers after K Removals/README_EN.md b/solution/1400-1499/1481.Least Number of Unique Integers after K Removals/README_EN.md index 87e715cba6487..ff98db3effecf 100644 --- a/solution/1400-1499/1481.Least Number of Unique Integers after K Removals/README_EN.md +++ b/solution/1400-1499/1481.Least Number of Unique Integers after K Removals/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$, +#### Python3 + ```python class Solution: def findLeastNumOfUniqueInts(self, arr: List[int], k: int) -> int: @@ -95,6 +97,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { public int findLeastNumOfUniqueInts(int[] arr, int k) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func findLeastNumOfUniqueInts(arr []int, k int) int { cnt := map[int]int{} @@ -160,6 +168,8 @@ func findLeastNumOfUniqueInts(arr []int, k int) int { } ``` +#### TypeScript + ```ts function findLeastNumOfUniqueInts(arr: number[], k: number): number { const cnt: Map = new Map(); diff --git a/solution/1400-1499/1482.Minimum Number of Days to Make m Bouquets/README.md b/solution/1400-1499/1482.Minimum Number of Days to Make m Bouquets/README.md index a850dabbcb434..366fe481c6cf9 100644 --- a/solution/1400-1499/1482.Minimum Number of Days to Make m Bouquets/README.md +++ b/solution/1400-1499/1482.Minimum Number of Days to Make m Bouquets/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class Solution: def minDays(self, bloomDay: List[int], m: int, k: int) -> int: @@ -119,6 +121,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int minDays(int[] bloomDay, int m, int k) { @@ -156,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -194,6 +200,8 @@ public: }; ``` +#### Go + ```go func minDays(bloomDay []int, m int, k int) int { if m*k > len(bloomDay) { diff --git a/solution/1400-1499/1482.Minimum Number of Days to Make m Bouquets/README_EN.md b/solution/1400-1499/1482.Minimum Number of Days to Make m Bouquets/README_EN.md index c44dffdb59c47..419d1cbfd33e4 100644 --- a/solution/1400-1499/1482.Minimum Number of Days to Make m Bouquets/README_EN.md +++ b/solution/1400-1499/1482.Minimum Number of Days to Make m Bouquets/README_EN.md @@ -82,6 +82,8 @@ It is obvious that we can make two bouquets in different ways. +#### Python3 + ```python class Solution: def minDays(self, bloomDay: List[int], m: int, k: int) -> int: @@ -107,6 +109,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int minDays(int[] bloomDay, int m, int k) { @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -182,6 +188,8 @@ public: }; ``` +#### Go + ```go func minDays(bloomDay []int, m int, k int) int { if m*k > len(bloomDay) { diff --git a/solution/1400-1499/1483.Kth Ancestor of a Tree Node/README.md b/solution/1400-1499/1483.Kth Ancestor of a Tree Node/README.md index 956c234c6b43b..e88d844b5970c 100644 --- a/solution/1400-1499/1483.Kth Ancestor of a Tree Node/README.md +++ b/solution/1400-1499/1483.Kth Ancestor of a Tree Node/README.md @@ -98,6 +98,8 @@ $$ +#### Python3 + ```python class TreeAncestor: def __init__(self, n: int, parent: List[int]): @@ -124,6 +126,8 @@ class TreeAncestor: # param_1 = obj.getKthAncestor(node,k) ``` +#### Java + ```java class TreeAncestor { private int[][] p; @@ -166,6 +170,8 @@ class TreeAncestor { */ ``` +#### C++ + ```cpp class TreeAncestor { public: @@ -207,6 +213,8 @@ private: */ ``` +#### Go + ```go type TreeAncestor struct { p [][18]int @@ -250,6 +258,8 @@ func (this *TreeAncestor) GetKthAncestor(node int, k int) int { */ ``` +#### TypeScript + ```ts class TreeAncestor { private p: number[][]; @@ -290,6 +300,8 @@ class TreeAncestor { */ ``` +#### C# + ```cs public class TreeAncestor { private int[][] p; diff --git a/solution/1400-1499/1483.Kth Ancestor of a Tree Node/README_EN.md b/solution/1400-1499/1483.Kth Ancestor of a Tree Node/README_EN.md index 9c4efb23dbc91..783c562fbf721 100644 --- a/solution/1400-1499/1483.Kth Ancestor of a Tree Node/README_EN.md +++ b/solution/1400-1499/1483.Kth Ancestor of a Tree Node/README_EN.md @@ -92,6 +92,8 @@ Similar problems: +#### Python3 + ```python class TreeAncestor: def __init__(self, n: int, parent: List[int]): @@ -118,6 +120,8 @@ class TreeAncestor: # param_1 = obj.getKthAncestor(node,k) ``` +#### Java + ```java class TreeAncestor { private int[][] p; @@ -160,6 +164,8 @@ class TreeAncestor { */ ``` +#### C++ + ```cpp class TreeAncestor { public: @@ -201,6 +207,8 @@ private: */ ``` +#### Go + ```go type TreeAncestor struct { p [][18]int @@ -244,6 +252,8 @@ func (this *TreeAncestor) GetKthAncestor(node int, k int) int { */ ``` +#### TypeScript + ```ts class TreeAncestor { private p: number[][]; @@ -284,6 +294,8 @@ class TreeAncestor { */ ``` +#### C# + ```cs public class TreeAncestor { private int[][] p; diff --git a/solution/1400-1499/1484.Group Sold Products By The Date/README.md b/solution/1400-1499/1484.Group Sold Products By The Date/README.md index 620621bd7182b..655ccaeb2caf3 100644 --- a/solution/1400-1499/1484.Group Sold Products By The Date/README.md +++ b/solution/1400-1499/1484.Group Sold Products By The Date/README.md @@ -78,6 +78,8 @@ Activities 表: +#### MySQL + ```sql SELECT sell_date, diff --git a/solution/1400-1499/1484.Group Sold Products By The Date/README_EN.md b/solution/1400-1499/1484.Group Sold Products By The Date/README_EN.md index 1284ce1c23e12..65eaa711b3ead 100644 --- a/solution/1400-1499/1484.Group Sold Products By The Date/README_EN.md +++ b/solution/1400-1499/1484.Group Sold Products By The Date/README_EN.md @@ -80,6 +80,8 @@ For 2020-06-02, the Sold item is (Mask), we just return it. +#### MySQL + ```sql SELECT sell_date, diff --git a/solution/1400-1499/1485.Clone Binary Tree With Random Pointer/README.md b/solution/1400-1499/1485.Clone Binary Tree With Random Pointer/README.md index ff27db5c75573..5626004176c01 100644 --- a/solution/1400-1499/1485.Clone Binary Tree With Random Pointer/README.md +++ b/solution/1400-1499/1485.Clone Binary Tree With Random Pointer/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python # Definition for Node. # class Node: @@ -114,6 +116,8 @@ class Solution: return dfs(root) ``` +#### Java + ```java /** * Definition for Node. @@ -158,6 +162,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a Node. @@ -192,6 +198,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. diff --git a/solution/1400-1499/1485.Clone Binary Tree With Random Pointer/README_EN.md b/solution/1400-1499/1485.Clone Binary Tree With Random Pointer/README_EN.md index c7fca8934d3fa..9a35b26a7b4dd 100644 --- a/solution/1400-1499/1485.Clone Binary Tree With Random Pointer/README_EN.md +++ b/solution/1400-1499/1485.Clone Binary Tree With Random Pointer/README_EN.md @@ -78,6 +78,8 @@ The random pointer of node 7 is node 1, so it is represented as [7, 0] where 0 i +#### Python3 + ```python # Definition for Node. # class Node: @@ -106,6 +108,8 @@ class Solution: return dfs(root) ``` +#### Java + ```java /** * Definition for Node. @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a Node. @@ -184,6 +190,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. diff --git a/solution/1400-1499/1486.XOR Operation in an Array/README.md b/solution/1400-1499/1486.XOR Operation in an Array/README.md index 6931ede627bce..a22e2a62d7f0d 100644 --- a/solution/1400-1499/1486.XOR Operation in an Array/README.md +++ b/solution/1400-1499/1486.XOR Operation in an Array/README.md @@ -77,12 +77,16 @@ tags: +#### Python3 + ```python class Solution: def xorOperation(self, n: int, start: int) -> int: return reduce(xor, ((start + 2 * i) for i in range(n))) ``` +#### Java + ```java class Solution { public int xorOperation(int n, int start) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func xorOperation(n int, start int) (ans int) { for i := 0; i < n; i++ { @@ -117,6 +125,8 @@ func xorOperation(n int, start int) (ans int) { } ``` +#### TypeScript + ```ts function xorOperation(n: number, start: number): number { let ans = 0; diff --git a/solution/1400-1499/1486.XOR Operation in an Array/README_EN.md b/solution/1400-1499/1486.XOR Operation in an Array/README_EN.md index f11dd65ac3cc0..92446ffdb060e 100644 --- a/solution/1400-1499/1486.XOR Operation in an Array/README_EN.md +++ b/solution/1400-1499/1486.XOR Operation in an Array/README_EN.md @@ -66,12 +66,16 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def xorOperation(self, n: int, start: int) -> int: return reduce(xor, ((start + 2 * i) for i in range(n))) ``` +#### Java + ```java class Solution { public int xorOperation(int n, int start) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -97,6 +103,8 @@ public: }; ``` +#### Go + ```go func xorOperation(n int, start int) (ans int) { for i := 0; i < n; i++ { @@ -106,6 +114,8 @@ func xorOperation(n int, start int) (ans int) { } ``` +#### TypeScript + ```ts function xorOperation(n: number, start: number): number { let ans = 0; diff --git a/solution/1400-1499/1487.Making File Names Unique/README.md b/solution/1400-1499/1487.Making File Names Unique/README.md index f43215e96802a..a42fb3ac255ab 100644 --- a/solution/1400-1499/1487.Making File Names Unique/README.md +++ b/solution/1400-1499/1487.Making File Names Unique/README.md @@ -104,6 +104,8 @@ tags: +#### Python3 + ```python class Solution: def getFolderNames(self, names: List[str]) -> List[str]: @@ -119,6 +121,8 @@ class Solution: return names ``` +#### Java + ```java class Solution { public String[] getFolderNames(String[] names) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func getFolderNames(names []string) []string { d := map[string]int{} @@ -181,6 +189,8 @@ func getFolderNames(names []string) []string { } ``` +#### TypeScript + ```ts function getFolderNames(names: string[]): string[] { let d: Map = new Map(); diff --git a/solution/1400-1499/1487.Making File Names Unique/README_EN.md b/solution/1400-1499/1487.Making File Names Unique/README_EN.md index b82343e910474..da002d0577b6c 100644 --- a/solution/1400-1499/1487.Making File Names Unique/README_EN.md +++ b/solution/1400-1499/1487.Making File Names Unique/README_EN.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def getFolderNames(self, names: List[str]) -> List[str]: @@ -93,6 +95,8 @@ class Solution: return names ``` +#### Java + ```java class Solution { public String[] getFolderNames(String[] names) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func getFolderNames(names []string) []string { d := map[string]int{} @@ -155,6 +163,8 @@ func getFolderNames(names []string) []string { } ``` +#### TypeScript + ```ts function getFolderNames(names: string[]): string[] { let d: Map = new Map(); diff --git a/solution/1400-1499/1488.Avoid Flood in The City/README.md b/solution/1400-1499/1488.Avoid Flood in The City/README.md index 21c22c8019298..219182f7c88f2 100644 --- a/solution/1400-1499/1488.Avoid Flood in The City/README.md +++ b/solution/1400-1499/1488.Avoid Flood in The City/README.md @@ -107,6 +107,8 @@ tags: +#### Python3 + ```python from sortedcontainers import SortedList @@ -132,6 +134,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] avoidFlood(int[] rains) { @@ -162,6 +166,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -192,6 +198,8 @@ public: }; ``` +#### Go + ```go func avoidFlood(rains []int) []int { n := len(rains) @@ -221,6 +229,8 @@ func avoidFlood(rains []int) []int { } ``` +#### TypeScript + ```ts function avoidFlood(rains: number[]): number[] { const n = rains.length; diff --git a/solution/1400-1499/1488.Avoid Flood in The City/README_EN.md b/solution/1400-1499/1488.Avoid Flood in The City/README_EN.md index c2f486701fdcc..e62ec47805b8e 100644 --- a/solution/1400-1499/1488.Avoid Flood in The City/README_EN.md +++ b/solution/1400-1499/1488.Avoid Flood in The City/README_EN.md @@ -105,6 +105,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python from sortedcontainers import SortedList @@ -130,6 +132,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] avoidFlood(int[] rains) { @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -190,6 +196,8 @@ public: }; ``` +#### Go + ```go func avoidFlood(rains []int) []int { n := len(rains) @@ -219,6 +227,8 @@ func avoidFlood(rains []int) []int { } ``` +#### TypeScript + ```ts function avoidFlood(rains: number[]): number[] { const n = rains.length; diff --git a/solution/1400-1499/1489.Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree/README.md b/solution/1400-1499/1489.Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree/README.md index 1582fb60bf513..d8cfeed6b6f4c 100644 --- a/solution/1400-1499/1489.Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree/README.md +++ b/solution/1400-1499/1489.Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class UnionFind: def __init__(self, n): @@ -121,6 +123,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> findCriticalAndPseudoCriticalEdges(int n, int[][] edges) { @@ -209,6 +213,8 @@ class UnionFind { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -273,6 +279,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p []int diff --git a/solution/1400-1499/1489.Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree/README_EN.md b/solution/1400-1499/1489.Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree/README_EN.md index 7ce3b8acac271..db6236153b2d6 100644 --- a/solution/1400-1499/1489.Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree/README_EN.md +++ b/solution/1400-1499/1489.Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree/README_EN.md @@ -75,6 +75,8 @@ The edges 2, 3, 4, and 5 are only part of some MSTs, therefore they are consider +#### Python3 + ```python class UnionFind: def __init__(self, n): @@ -119,6 +121,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> findCriticalAndPseudoCriticalEdges(int n, int[][] edges) { @@ -207,6 +211,8 @@ class UnionFind { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -271,6 +277,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p []int diff --git a/solution/1400-1499/1490.Clone N-ary Tree/README.md b/solution/1400-1499/1490.Clone N-ary Tree/README.md index 41545c5d44f1a..ea0e4d99798a4 100644 --- a/solution/1400-1499/1490.Clone N-ary Tree/README.md +++ b/solution/1400-1499/1490.Clone N-ary Tree/README.md @@ -81,6 +81,8 @@ class Node { +#### Python3 + ```python """ # Definition for a Node. @@ -99,6 +101,8 @@ class Solution: return Node(root.val, children) ``` +#### Java + ```java /* // Definition for a Node. @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. diff --git a/solution/1400-1499/1490.Clone N-ary Tree/README_EN.md b/solution/1400-1499/1490.Clone N-ary Tree/README_EN.md index ba0be56397d21..9aecf829aba71 100644 --- a/solution/1400-1499/1490.Clone N-ary Tree/README_EN.md +++ b/solution/1400-1499/1490.Clone N-ary Tree/README_EN.md @@ -72,6 +72,8 @@ class Node { +#### Python3 + ```python """ # Definition for a Node. @@ -90,6 +92,8 @@ class Solution: return Node(root.val, children) ``` +#### Java + ```java /* // Definition for a Node. @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. diff --git a/solution/1400-1499/1491.Average Salary Excluding the Minimum and Maximum Salary/README.md b/solution/1400-1499/1491.Average Salary Excluding the Minimum and Maximum Salary/README.md index 98eeaa70cfcfc..61f810c56fac5 100644 --- a/solution/1400-1499/1491.Average Salary Excluding the Minimum and Maximum Salary/README.md +++ b/solution/1400-1499/1491.Average Salary Excluding the Minimum and Maximum Salary/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def average(self, salary: List[int]) -> float: @@ -87,6 +89,8 @@ class Solution: return s / (len(salary) - 2) ``` +#### Java + ```java class Solution { public double average(int[] salary) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func average(salary []int) float64 { s := 0 @@ -134,6 +142,8 @@ func average(salary []int) float64 { } ``` +#### TypeScript + ```ts function average(salary: number[]): number { let max = -Infinity; @@ -148,6 +158,8 @@ function average(salary: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn average(salary: Vec) -> f64 { @@ -165,6 +177,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** @@ -184,6 +198,8 @@ class Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) #define min(a, b) (((a) < (b)) ? (a) : (b)) diff --git a/solution/1400-1499/1491.Average Salary Excluding the Minimum and Maximum Salary/README_EN.md b/solution/1400-1499/1491.Average Salary Excluding the Minimum and Maximum Salary/README_EN.md index bcf440a8859c7..d529b1c6506f5 100644 --- a/solution/1400-1499/1491.Average Salary Excluding the Minimum and Maximum Salary/README_EN.md +++ b/solution/1400-1499/1491.Average Salary Excluding the Minimum and Maximum Salary/README_EN.md @@ -67,6 +67,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array `salary`. Th +#### Python3 + ```python class Solution: def average(self, salary: List[int]) -> float: @@ -74,6 +76,8 @@ class Solution: return s / (len(salary) - 2) ``` +#### Java + ```java class Solution { public double average(int[] salary) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func average(salary []int) float64 { s := 0 @@ -121,6 +129,8 @@ func average(salary []int) float64 { } ``` +#### TypeScript + ```ts function average(salary: number[]): number { let max = -Infinity; @@ -135,6 +145,8 @@ function average(salary: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn average(salary: Vec) -> f64 { @@ -152,6 +164,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** @@ -171,6 +185,8 @@ class Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) #define min(a, b) (((a) < (b)) ? (a) : (b)) diff --git a/solution/1400-1499/1492.The kth Factor of n/README.md b/solution/1400-1499/1492.The kth Factor of n/README.md index 2fcf9091bc8fd..a7a42aa79f9a2 100644 --- a/solution/1400-1499/1492.The kth Factor of n/README.md +++ b/solution/1400-1499/1492.The kth Factor of n/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def kthFactor(self, n: int, k: int) -> int: @@ -90,6 +92,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int kthFactor(int n, int k) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func kthFactor(n int, k int) int { for i := 1; i <= n; i++ { @@ -131,6 +139,8 @@ func kthFactor(n int, k int) int { } ``` +#### TypeScript + ```ts function kthFactor(n: number, k: number): number { for (let i = 1; i <= n; ++i) { @@ -158,6 +168,8 @@ function kthFactor(n: number, k: number): number { +#### Python3 + ```python class Solution: def kthFactor(self, n: int, k: int) -> int: @@ -179,6 +191,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int kthFactor(int n, int k) { @@ -201,6 +215,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -224,6 +240,8 @@ public: }; ``` +#### Go + ```go func kthFactor(n int, k int) int { i := 1 @@ -250,6 +268,8 @@ func kthFactor(n int, k int) int { } ``` +#### TypeScript + ```ts function kthFactor(n: number, k: number): number { let i: number = 1; diff --git a/solution/1400-1499/1492.The kth Factor of n/README_EN.md b/solution/1400-1499/1492.The kth Factor of n/README_EN.md index b9cdf91157801..30bb0ce11d173 100644 --- a/solution/1400-1499/1492.The kth Factor of n/README_EN.md +++ b/solution/1400-1499/1492.The kth Factor of n/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def kthFactor(self, n: int, k: int) -> int: @@ -85,6 +87,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int kthFactor(int n, int k) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func kthFactor(n int, k int) int { for i := 1; i <= n; i++ { @@ -126,6 +134,8 @@ func kthFactor(n int, k int) int { } ``` +#### TypeScript + ```ts function kthFactor(n: number, k: number): number { for (let i = 1; i <= n; ++i) { @@ -153,6 +163,8 @@ The time complexity is $O(\sqrt{n})$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def kthFactor(self, n: int, k: int) -> int: @@ -174,6 +186,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int kthFactor(int n, int k) { @@ -196,6 +210,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -219,6 +235,8 @@ public: }; ``` +#### Go + ```go func kthFactor(n int, k int) int { i := 1 @@ -245,6 +263,8 @@ func kthFactor(n int, k int) int { } ``` +#### TypeScript + ```ts function kthFactor(n: number, k: number): number { let i: number = 1; diff --git a/solution/1400-1499/1493.Longest Subarray of 1's After Deleting One Element/README.md b/solution/1400-1499/1493.Longest Subarray of 1's After Deleting One Element/README.md index 5259d6dd49b7a..ba89373513f3f 100644 --- a/solution/1400-1499/1493.Longest Subarray of 1's After Deleting One Element/README.md +++ b/solution/1400-1499/1493.Longest Subarray of 1's After Deleting One Element/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def longestSubarray(self, nums: List[int]) -> int: @@ -91,6 +93,8 @@ class Solution: return max(left[i] + right[i + 1] for i in range(n)) ``` +#### Java + ```java class Solution { public int longestSubarray(int[] nums) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func longestSubarray(nums []int) (ans int) { n := len(nums) @@ -164,6 +172,8 @@ func longestSubarray(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function longestSubarray(nums: number[]): number { const n = nums.length; @@ -205,6 +215,8 @@ function longestSubarray(nums: number[]): number { +#### Python3 + ```python class Solution: def longestSubarray(self, nums: List[int]) -> int: @@ -219,6 +231,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestSubarray(int[] nums) { @@ -235,6 +249,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -252,6 +268,8 @@ public: }; ``` +#### Go + ```go func longestSubarray(nums []int) (ans int) { cnt, j := 0, 0 @@ -266,6 +284,8 @@ func longestSubarray(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function longestSubarray(nums: number[]): number { let [ans, cnt, j] = [0, 0, 0]; diff --git a/solution/1400-1499/1493.Longest Subarray of 1's After Deleting One Element/README_EN.md b/solution/1400-1499/1493.Longest Subarray of 1's After Deleting One Element/README_EN.md index ecae0254b650c..dded8ae77ffb1 100644 --- a/solution/1400-1499/1493.Longest Subarray of 1's After Deleting One Element/README_EN.md +++ b/solution/1400-1499/1493.Longest Subarray of 1's After Deleting One Element/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def longestSubarray(self, nums: List[int]) -> int: @@ -90,6 +92,8 @@ class Solution: return max(left[i] + right[i + 1] for i in range(n)) ``` +#### Java + ```java class Solution { public int longestSubarray(int[] nums) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func longestSubarray(nums []int) (ans int) { n := len(nums) @@ -163,6 +171,8 @@ func longestSubarray(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function longestSubarray(nums: number[]): number { const n = nums.length; @@ -204,6 +214,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def longestSubarray(self, nums: List[int]) -> int: @@ -218,6 +230,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestSubarray(int[] nums) { @@ -234,6 +248,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -251,6 +267,8 @@ public: }; ``` +#### Go + ```go func longestSubarray(nums []int) (ans int) { cnt, j := 0, 0 @@ -265,6 +283,8 @@ func longestSubarray(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function longestSubarray(nums: number[]): number { let [ans, cnt, j] = [0, 0, 0]; diff --git a/solution/1400-1499/1494.Parallel Courses II/README.md b/solution/1400-1499/1494.Parallel Courses II/README.md index d8903d9aaa6f9..82e42f343449b 100644 --- a/solution/1400-1499/1494.Parallel Courses II/README.md +++ b/solution/1400-1499/1494.Parallel Courses II/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def minNumberOfSemesters(self, n: int, relations: List[List[int]], k: int) -> int: @@ -121,6 +123,8 @@ class Solution: nxt = (nxt - 1) & x ``` +#### Java + ```java class Solution { public int minNumberOfSemesters(int n, int[][] relations, int k) { @@ -164,6 +168,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -209,6 +215,8 @@ public: }; ``` +#### Go + ```go func minNumberOfSemesters(n int, relations [][]int, k int) int { d := make([]int, n+1) diff --git a/solution/1400-1499/1494.Parallel Courses II/README_EN.md b/solution/1400-1499/1494.Parallel Courses II/README_EN.md index 69f112b9cd5ab..523531641180a 100644 --- a/solution/1400-1499/1494.Parallel Courses II/README_EN.md +++ b/solution/1400-1499/1494.Parallel Courses II/README_EN.md @@ -75,6 +75,8 @@ In the fourth semester, you can take course 5. +#### Python3 + ```python class Solution: def minNumberOfSemesters(self, n: int, relations: List[List[int]], k: int) -> int: @@ -105,6 +107,8 @@ class Solution: nxt = (nxt - 1) & x ``` +#### Java + ```java class Solution { public int minNumberOfSemesters(int n, int[][] relations, int k) { @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go func minNumberOfSemesters(n int, relations [][]int, k int) int { d := make([]int, n+1) diff --git a/solution/1400-1499/1495.Friendly Movies Streamed Last Month/README.md b/solution/1400-1499/1495.Friendly Movies Streamed Last Month/README.md index 8ece2b9935bf1..ae0daac99576a 100644 --- a/solution/1400-1499/1495.Friendly Movies Streamed Last Month/README.md +++ b/solution/1400-1499/1495.Friendly Movies Streamed Last Month/README.md @@ -109,6 +109,8 @@ TVProgram 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT DISTINCT title diff --git a/solution/1400-1499/1495.Friendly Movies Streamed Last Month/README_EN.md b/solution/1400-1499/1495.Friendly Movies Streamed Last Month/README_EN.md index f17d2cc216457..9f8c01520af24 100644 --- a/solution/1400-1499/1495.Friendly Movies Streamed Last Month/README_EN.md +++ b/solution/1400-1499/1495.Friendly Movies Streamed Last Month/README_EN.md @@ -109,6 +109,8 @@ We can first use an equi-join to join the two tables based on the `content_id` f +#### MySQL + ```sql # Write your MySQL query statement below SELECT DISTINCT title diff --git a/solution/1400-1499/1496.Path Crossing/README.md b/solution/1400-1499/1496.Path Crossing/README.md index d4754ffd09666..4970fba50e6c6 100644 --- a/solution/1400-1499/1496.Path Crossing/README.md +++ b/solution/1400-1499/1496.Path Crossing/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def isPathCrossing(self, path: str) -> bool: @@ -93,6 +95,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean isPathCrossing(String path) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func isPathCrossing(path string) bool { i, j := 0, 0 @@ -167,6 +175,8 @@ func isPathCrossing(path string) bool { } ``` +#### TypeScript + ```ts function isPathCrossing(path: string): boolean { let [i, j] = [0, 0]; diff --git a/solution/1400-1499/1496.Path Crossing/README_EN.md b/solution/1400-1499/1496.Path Crossing/README_EN.md index 6c8c103ac5d64..63a9d4c0c903f 100644 --- a/solution/1400-1499/1496.Path Crossing/README_EN.md +++ b/solution/1400-1499/1496.Path Crossing/README_EN.md @@ -57,6 +57,8 @@ tags: +#### Python3 + ```python class Solution: def isPathCrossing(self, path: str) -> bool: @@ -78,6 +80,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean isPathCrossing(String path) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func isPathCrossing(path string) bool { i, j := 0, 0 @@ -152,6 +160,8 @@ func isPathCrossing(path string) bool { } ``` +#### TypeScript + ```ts function isPathCrossing(path: string): boolean { let [i, j] = [0, 0]; diff --git a/solution/1400-1499/1497.Check If Array Pairs Are Divisible by k/README.md b/solution/1400-1499/1497.Check If Array Pairs Are Divisible by k/README.md index 604b634aa8292..dc9858b5d49ef 100644 --- a/solution/1400-1499/1497.Check If Array Pairs Are Divisible by k/README.md +++ b/solution/1400-1499/1497.Check If Array Pairs Are Divisible by k/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def canArrange(self, arr: List[int], k: int) -> bool: @@ -87,6 +89,8 @@ class Solution: return cnt[0] % 2 == 0 and all(cnt[i] == cnt[k - i] for i in range(1, k)) ``` +#### Java + ```java class Solution { public boolean canArrange(int[] arr, int k) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func canArrange(arr []int, k int) bool { cnt := make([]int, k) diff --git a/solution/1400-1499/1497.Check If Array Pairs Are Divisible by k/README_EN.md b/solution/1400-1499/1497.Check If Array Pairs Are Divisible by k/README_EN.md index e1f4da8096931..4ea03c3efc755 100644 --- a/solution/1400-1499/1497.Check If Array Pairs Are Divisible by k/README_EN.md +++ b/solution/1400-1499/1497.Check If Array Pairs Are Divisible by k/README_EN.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def canArrange(self, arr: List[int], k: int) -> bool: @@ -79,6 +81,8 @@ class Solution: return cnt[0] % 2 == 0 and all(cnt[i] == cnt[k - i] for i in range(1, k)) ``` +#### Java + ```java class Solution { public boolean canArrange(int[] arr, int k) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func canArrange(arr []int, k int) bool { cnt := make([]int, k) diff --git a/solution/1400-1499/1498.Number of Subsequences That Satisfy the Given Sum Condition/README.md b/solution/1400-1499/1498.Number of Subsequences That Satisfy the Given Sum Condition/README.md index 3d4bf2b4e5c1f..e6ace5471b0df 100644 --- a/solution/1400-1499/1498.Number of Subsequences That Satisfy the Given Sum Condition/README.md +++ b/solution/1400-1499/1498.Number of Subsequences That Satisfy the Given Sum Condition/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def numSubseq(self, nums: List[int], target: int) -> int: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numSubseq(int[] nums, int target) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func numSubseq(nums []int, target int) (ans int) { sort.Ints(nums) diff --git a/solution/1400-1499/1498.Number of Subsequences That Satisfy the Given Sum Condition/README_EN.md b/solution/1400-1499/1498.Number of Subsequences That Satisfy the Given Sum Condition/README_EN.md index c0b8b0ed79df3..82d339744f91b 100644 --- a/solution/1400-1499/1498.Number of Subsequences That Satisfy the Given Sum Condition/README_EN.md +++ b/solution/1400-1499/1498.Number of Subsequences That Satisfy the Given Sum Condition/README_EN.md @@ -75,6 +75,8 @@ Number of valid subsequences (63 - 2 = 61). +#### Python3 + ```python class Solution: def numSubseq(self, nums: List[int], target: int) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numSubseq(int[] nums, int target) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func numSubseq(nums []int, target int) (ans int) { sort.Ints(nums) diff --git a/solution/1400-1499/1499.Max Value of Equation/README.md b/solution/1400-1499/1499.Max Value of Equation/README.md index 5befcbfebaf33..4346fed8a6b03 100644 --- a/solution/1400-1499/1499.Max Value of Equation/README.md +++ b/solution/1400-1499/1499.Max Value of Equation/README.md @@ -85,6 +85,8 @@ $$ +#### Python3 + ```python class Solution: def findMaxValueOfEquation(self, points: List[List[int]], k: int) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findMaxValueOfEquation(int[][] points, int k) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func findMaxValueOfEquation(points [][]int, k int) int { ans := -(1 << 30) @@ -171,6 +179,8 @@ func (h *hp) Push(v any) { *h = append(*h, v.(pair)) } func (h *hp) Pop() any { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; return v } ``` +#### TypeScript + ```ts function findMaxValueOfEquation(points: number[][], k: number): number { let ans = -(1 << 30); @@ -274,6 +284,8 @@ class Heap { +#### Python3 + ```python class Solution: def findMaxValueOfEquation(self, points: List[List[int]], k: int) -> int: @@ -290,6 +302,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findMaxValueOfEquation(int[][] points, int k) { @@ -313,6 +327,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -337,6 +353,8 @@ public: }; ``` +#### Go + ```go func findMaxValueOfEquation(points [][]int, k int) int { ans := -(1 << 30) @@ -358,6 +376,8 @@ func findMaxValueOfEquation(points [][]int, k int) int { } ``` +#### TypeScript + ```ts function findMaxValueOfEquation(points: number[][], k: number): number { let ans = -(1 << 30); diff --git a/solution/1400-1499/1499.Max Value of Equation/README_EN.md b/solution/1400-1499/1499.Max Value of Equation/README_EN.md index 662f5809784cb..70224e7b35c32 100644 --- a/solution/1400-1499/1499.Max Value of Equation/README_EN.md +++ b/solution/1400-1499/1499.Max Value of Equation/README_EN.md @@ -68,6 +68,8 @@ No other pairs satisfy the condition, so we return the max of 4 and 1. +#### Python3 + ```python class Solution: def findMaxValueOfEquation(self, points: List[List[int]], k: int) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findMaxValueOfEquation(int[][] points, int k) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func findMaxValueOfEquation(points [][]int, k int) int { ans := -(1 << 30) @@ -154,6 +162,8 @@ func (h *hp) Push(v any) { *h = append(*h, v.(pair)) } func (h *hp) Pop() any { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; return v } ``` +#### TypeScript + ```ts function findMaxValueOfEquation(points: number[][], k: number): number { let ans = -(1 << 30); @@ -247,6 +257,8 @@ class Heap { +#### Python3 + ```python class Solution: def findMaxValueOfEquation(self, points: List[List[int]], k: int) -> int: @@ -263,6 +275,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findMaxValueOfEquation(int[][] points, int k) { @@ -286,6 +300,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -310,6 +326,8 @@ public: }; ``` +#### Go + ```go func findMaxValueOfEquation(points [][]int, k int) int { ans := -(1 << 30) @@ -331,6 +349,8 @@ func findMaxValueOfEquation(points [][]int, k int) int { } ``` +#### TypeScript + ```ts function findMaxValueOfEquation(points: number[][], k: number): number { let ans = -(1 << 30); diff --git a/solution/1500-1599/1500.Design a File Sharing System/README.md b/solution/1500-1599/1500.Design a File Sharing System/README.md index f1c63c3fcac1b..239a3715ecdfe 100644 --- a/solution/1500-1599/1500.Design a File Sharing System/README.md +++ b/solution/1500-1599/1500.Design a File Sharing System/README.md @@ -103,6 +103,8 @@ fileSharing.join([]); // 一个不拥有任何文件块的用户加入系 +#### Python3 + ```python class FileSharing: def __init__(self, m: int): @@ -143,6 +145,8 @@ class FileSharing: # param_3 = obj.request(userID,chunkID) ``` +#### Java + ```java class FileSharing { private int chunks; diff --git a/solution/1500-1599/1500.Design a File Sharing System/README_EN.md b/solution/1500-1599/1500.Design a File Sharing System/README_EN.md index 169bb80b27b3d..e7b1d7e2175d4 100644 --- a/solution/1500-1599/1500.Design a File Sharing System/README_EN.md +++ b/solution/1500-1599/1500.Design a File Sharing System/README_EN.md @@ -100,6 +100,8 @@ fileSharing.join([]); // A user who doesn't have any chunks joined th +#### Python3 + ```python class FileSharing: def __init__(self, m: int): @@ -140,6 +142,8 @@ class FileSharing: # param_3 = obj.request(userID,chunkID) ``` +#### Java + ```java class FileSharing { private int chunks; diff --git a/solution/1500-1599/1501.Countries You Can Safely Invest In/README.md b/solution/1500-1599/1501.Countries You Can Safely Invest In/README.md index dde8f7b305194..b7f8e5f0f607e 100644 --- a/solution/1500-1599/1501.Countries You Can Safely Invest In/README.md +++ b/solution/1500-1599/1501.Countries You Can Safely Invest In/README.md @@ -140,6 +140,8 @@ Calls 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT country @@ -165,6 +167,8 @@ WHERE duration > (SELECT AVG(duration) FROM Calls); +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1500-1599/1501.Countries You Can Safely Invest In/README_EN.md b/solution/1500-1599/1501.Countries You Can Safely Invest In/README_EN.md index 5e073e0df87da..6b7a62d8d4c9d 100644 --- a/solution/1500-1599/1501.Countries You Can Safely Invest In/README_EN.md +++ b/solution/1500-1599/1501.Countries You Can Safely Invest In/README_EN.md @@ -139,6 +139,8 @@ We can use an equi-join to join the `Person` table and the `Calls` table on the +#### MySQL + ```sql # Write your MySQL query statement below SELECT country @@ -164,6 +166,8 @@ WHERE duration > (SELECT AVG(duration) FROM Calls); +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1500-1599/1502.Can Make Arithmetic Progression From Sequence/README.md b/solution/1500-1599/1502.Can Make Arithmetic Progression From Sequence/README.md index daff1f5956e4e..a81643aedc3a7 100644 --- a/solution/1500-1599/1502.Can Make Arithmetic Progression From Sequence/README.md +++ b/solution/1500-1599/1502.Can Make Arithmetic Progression From Sequence/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def canMakeArithmeticProgression(self, arr: List[int]) -> bool: @@ -72,6 +74,8 @@ class Solution: return all(b - a == d for a, b in pairwise(arr)) ``` +#### Java + ```java class Solution { public boolean canMakeArithmeticProgression(int[] arr) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -103,6 +109,8 @@ public: }; ``` +#### Go + ```go func canMakeArithmeticProgression(arr []int) bool { sort.Ints(arr) @@ -116,6 +124,8 @@ func canMakeArithmeticProgression(arr []int) bool { } ``` +#### TypeScript + ```ts function canMakeArithmeticProgression(arr: number[]): boolean { arr.sort((a, b) => a - b); @@ -129,6 +139,8 @@ function canMakeArithmeticProgression(arr: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn can_make_arithmetic_progression(mut arr: Vec) -> bool { @@ -144,6 +156,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} arr @@ -160,6 +174,8 @@ var canMakeArithmeticProgression = function (arr) { }; ``` +#### C + ```c int cmp(const void* a, const void* b) { return *(int*) a - *(int*) b; @@ -192,6 +208,8 @@ bool canMakeArithmeticProgression(int* arr, int arrSize) { +#### Python3 + ```python class Solution: def canMakeArithmeticProgression(self, arr: List[int]) -> bool: @@ -205,6 +223,8 @@ class Solution: return all(a + d * i in s for i in range(n)) ``` +#### Java + ```java class Solution { public boolean canMakeArithmeticProgression(int[] arr) { @@ -230,6 +250,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -251,6 +273,8 @@ public: }; ``` +#### Go + ```go func canMakeArithmeticProgression(arr []int) bool { a, b := slices.Min(arr), slices.Max(arr) @@ -272,6 +296,8 @@ func canMakeArithmeticProgression(arr []int) bool { } ``` +#### TypeScript + ```ts function canMakeArithmeticProgression(arr: number[]): boolean { const n = arr.length; @@ -299,6 +325,8 @@ function canMakeArithmeticProgression(arr: number[]): boolean { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { diff --git a/solution/1500-1599/1502.Can Make Arithmetic Progression From Sequence/README_EN.md b/solution/1500-1599/1502.Can Make Arithmetic Progression From Sequence/README_EN.md index aa0118154e519..154f8be8eee2e 100644 --- a/solution/1500-1599/1502.Can Make Arithmetic Progression From Sequence/README_EN.md +++ b/solution/1500-1599/1502.Can Make Arithmetic Progression From Sequence/README_EN.md @@ -62,6 +62,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def canMakeArithmeticProgression(self, arr: List[int]) -> bool: @@ -70,6 +72,8 @@ class Solution: return all(b - a == d for a, b in pairwise(arr)) ``` +#### Java + ```java class Solution { public boolean canMakeArithmeticProgression(int[] arr) { @@ -85,6 +89,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,6 +107,8 @@ public: }; ``` +#### Go + ```go func canMakeArithmeticProgression(arr []int) bool { sort.Ints(arr) @@ -114,6 +122,8 @@ func canMakeArithmeticProgression(arr []int) bool { } ``` +#### TypeScript + ```ts function canMakeArithmeticProgression(arr: number[]): boolean { arr.sort((a, b) => a - b); @@ -127,6 +137,8 @@ function canMakeArithmeticProgression(arr: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn can_make_arithmetic_progression(mut arr: Vec) -> bool { @@ -142,6 +154,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} arr @@ -158,6 +172,8 @@ var canMakeArithmeticProgression = function (arr) { }; ``` +#### C + ```c int cmp(const void* a, const void* b) { return *(int*) a - *(int*) b; @@ -190,6 +206,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def canMakeArithmeticProgression(self, arr: List[int]) -> bool: @@ -203,6 +221,8 @@ class Solution: return all(a + d * i in s for i in range(n)) ``` +#### Java + ```java class Solution { public boolean canMakeArithmeticProgression(int[] arr) { @@ -228,6 +248,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -249,6 +271,8 @@ public: }; ``` +#### Go + ```go func canMakeArithmeticProgression(arr []int) bool { a, b := slices.Min(arr), slices.Max(arr) @@ -270,6 +294,8 @@ func canMakeArithmeticProgression(arr []int) bool { } ``` +#### TypeScript + ```ts function canMakeArithmeticProgression(arr: number[]): boolean { const n = arr.length; @@ -297,6 +323,8 @@ function canMakeArithmeticProgression(arr: number[]): boolean { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { diff --git a/solution/1500-1599/1503.Last Moment Before All Ants Fall Out of a Plank/README.md b/solution/1500-1599/1503.Last Moment Before All Ants Fall Out of a Plank/README.md index 0675ed5f1d215..f68792c5f3609 100644 --- a/solution/1500-1599/1503.Last Moment Before All Ants Fall Out of a Plank/README.md +++ b/solution/1500-1599/1503.Last Moment Before All Ants Fall Out of a Plank/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class Solution: def getLastMoment(self, n: int, left: List[int], right: List[int]) -> int: @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int getLastMoment(int n, int[] left, int[] right) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func getLastMoment(n int, left []int, right []int) (ans int) { for _, x := range left { @@ -150,6 +158,8 @@ func getLastMoment(n int, left []int, right []int) (ans int) { } ``` +#### TypeScript + ```ts function getLastMoment(n: number, left: number[], right: number[]): number { let ans = 0; diff --git a/solution/1500-1599/1503.Last Moment Before All Ants Fall Out of a Plank/README_EN.md b/solution/1500-1599/1503.Last Moment Before All Ants Fall Out of a Plank/README_EN.md index fa012a8dde274..b1ff85d2050cc 100644 --- a/solution/1500-1599/1503.Last Moment Before All Ants Fall Out of a Plank/README_EN.md +++ b/solution/1500-1599/1503.Last Moment Before All Ants Fall Out of a Plank/README_EN.md @@ -81,6 +81,8 @@ The last moment when an ant was on the plank is t = 4 seconds. After that, it fa +#### Python3 + ```python class Solution: def getLastMoment(self, n: int, left: List[int], right: List[int]) -> int: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int getLastMoment(int n, int[] left, int[] right) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func getLastMoment(n int, left []int, right []int) (ans int) { for _, x := range left { @@ -135,6 +143,8 @@ func getLastMoment(n int, left []int, right []int) (ans int) { } ``` +#### TypeScript + ```ts function getLastMoment(n: number, left: number[], right: number[]): number { let ans = 0; diff --git a/solution/1500-1599/1504.Count Submatrices With All Ones/README.md b/solution/1500-1599/1504.Count Submatrices With All Ones/README.md index de72bfd1ef144..8d251ec6fb49a 100644 --- a/solution/1500-1599/1504.Count Submatrices With All Ones/README.md +++ b/solution/1500-1599/1504.Count Submatrices With All Ones/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def numSubmat(self, mat: List[List[int]]) -> int: @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numSubmat(int[][] mat) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func numSubmat(mat [][]int) (ans int) { m, n := len(mat), len(mat[0]) diff --git a/solution/1500-1599/1504.Count Submatrices With All Ones/README_EN.md b/solution/1500-1599/1504.Count Submatrices With All Ones/README_EN.md index f8d0b7ad48019..f3a4e8ccd9923 100644 --- a/solution/1500-1599/1504.Count Submatrices With All Ones/README_EN.md +++ b/solution/1500-1599/1504.Count Submatrices With All Ones/README_EN.md @@ -73,6 +73,8 @@ Total number of rectangles = 8 + 5 + 2 + 4 + 2 + 2 + 1 = 24. +#### Python3 + ```python class Solution: def numSubmat(self, mat: List[List[int]]) -> int: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numSubmat(int[][] mat) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func numSubmat(mat [][]int) (ans int) { m, n := len(mat), len(mat[0]) diff --git a/solution/1500-1599/1505.Minimum Possible Integer After at Most K Adjacent Swaps On Digits/README.md b/solution/1500-1599/1505.Minimum Possible Integer After at Most K Adjacent Swaps On Digits/README.md index 340e7dc95ee18..c994abf9a4225 100644 --- a/solution/1500-1599/1505.Minimum Possible Integer After at Most K Adjacent Swaps On Digits/README.md +++ b/solution/1500-1599/1505.Minimum Possible Integer After at Most K Adjacent Swaps On Digits/README.md @@ -112,6 +112,8 @@ tags: +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -158,6 +160,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String minInteger(String num, int k) { @@ -222,6 +226,8 @@ class BinaryIndexedTree { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -282,6 +288,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int diff --git a/solution/1500-1599/1505.Minimum Possible Integer After at Most K Adjacent Swaps On Digits/README_EN.md b/solution/1500-1599/1505.Minimum Possible Integer After at Most K Adjacent Swaps On Digits/README_EN.md index b7d65094094b5..e22b4112c6169 100644 --- a/solution/1500-1599/1505.Minimum Possible Integer After at Most K Adjacent Swaps On Digits/README_EN.md +++ b/solution/1500-1599/1505.Minimum Possible Integer After at Most K Adjacent Swaps On Digits/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -115,6 +117,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String minInteger(String num, int k) { @@ -179,6 +183,8 @@ class BinaryIndexedTree { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -239,6 +245,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int diff --git a/solution/1500-1599/1506.Find Root of N-Ary Tree/README.md b/solution/1500-1599/1506.Find Root of N-Ary Tree/README.md index 81a9a26140625..380148c07739c 100644 --- a/solution/1500-1599/1506.Find Root of N-Ary Tree/README.md +++ b/solution/1500-1599/1506.Find Root of N-Ary Tree/README.md @@ -101,6 +101,8 @@ findRoot 函数应该返回根 Node(1) ,驱动程序代码将序列化它并 +#### Python3 + ```python """ # Definition for a Node. @@ -121,6 +123,8 @@ class Solution: return next(node for node in tree if node.val == x) ``` +#### Java + ```java /* // Definition for a Node. @@ -163,6 +167,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -203,6 +209,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -228,6 +236,8 @@ func findRoot(tree []*Node) *Node { } ``` +#### TypeScript + ```ts /** * Definition for Node. diff --git a/solution/1500-1599/1506.Find Root of N-Ary Tree/README_EN.md b/solution/1500-1599/1506.Find Root of N-Ary Tree/README_EN.md index b0ee8a4bf8b06..879f05fdfc22f 100644 --- a/solution/1500-1599/1506.Find Root of N-Ary Tree/README_EN.md +++ b/solution/1500-1599/1506.Find Root of N-Ary Tree/README_EN.md @@ -89,6 +89,8 @@ The input data and serialized Node(1) are the same, so the test passes. +#### Python3 + ```python """ # Definition for a Node. @@ -109,6 +111,8 @@ class Solution: return next(node for node in tree if node.val == x) ``` +#### Java + ```java /* // Definition for a Node. @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -191,6 +197,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -216,6 +224,8 @@ func findRoot(tree []*Node) *Node { } ``` +#### TypeScript + ```ts /** * Definition for Node. diff --git a/solution/1500-1599/1507.Reformat Date/README.md b/solution/1500-1599/1507.Reformat Date/README.md index f87e50eeb98cf..9481bf634b7f4 100644 --- a/solution/1500-1599/1507.Reformat Date/README.md +++ b/solution/1500-1599/1507.Reformat Date/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def reformatDate(self, date: str) -> str: @@ -87,6 +89,8 @@ class Solution: return "-".join(s) ``` +#### Java + ```java class Solution { public String reformatDate(String date) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func reformatDate(date string) string { s := strings.Split(date, " ") @@ -125,6 +133,8 @@ func reformatDate(date string) string { } ``` +#### TypeScript + ```ts function reformatDate(date: string): string { const s = date.split(' '); @@ -135,6 +145,8 @@ function reformatDate(date: string): string { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1500-1599/1507.Reformat Date/README_EN.md b/solution/1500-1599/1507.Reformat Date/README_EN.md index 3adb1700e0185..19012a9036e07 100644 --- a/solution/1500-1599/1507.Reformat Date/README_EN.md +++ b/solution/1500-1599/1507.Reformat Date/README_EN.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def reformatDate(self, date: str) -> str: @@ -84,6 +86,8 @@ class Solution: return "-".join(s) ``` +#### Java + ```java class Solution { public String reformatDate(String date) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func reformatDate(date string) string { s := strings.Split(date, " ") @@ -122,6 +130,8 @@ func reformatDate(date string) string { } ``` +#### TypeScript + ```ts function reformatDate(date: string): string { const s = date.split(' '); @@ -132,6 +142,8 @@ function reformatDate(date: string): string { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1500-1599/1508.Range Sum of Sorted Subarray Sums/README.md b/solution/1500-1599/1508.Range Sum of Sorted Subarray Sums/README.md index 0f7715f72afac..982021b65e6e2 100644 --- a/solution/1500-1599/1508.Range Sum of Sorted Subarray Sums/README.md +++ b/solution/1500-1599/1508.Range Sum of Sorted Subarray Sums/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: @@ -89,6 +91,8 @@ class Solution: return sum(arr[left - 1 : right]) % mod ``` +#### Java + ```java class Solution { public int rangeSum(int[] nums, int n, int left, int right) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func rangeSum(nums []int, n int, left int, right int) (ans int) { var arr []int diff --git a/solution/1500-1599/1508.Range Sum of Sorted Subarray Sums/README_EN.md b/solution/1500-1599/1508.Range Sum of Sorted Subarray Sums/README_EN.md index 43b2b3798979e..9d2e4df2e3696 100644 --- a/solution/1500-1599/1508.Range Sum of Sorted Subarray Sums/README_EN.md +++ b/solution/1500-1599/1508.Range Sum of Sorted Subarray Sums/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: @@ -83,6 +85,8 @@ class Solution: return sum(arr[left - 1 : right]) % mod ``` +#### Java + ```java class Solution { public int rangeSum(int[] nums, int n, int left, int right) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func rangeSum(nums []int, n int, left int, right int) (ans int) { var arr []int diff --git a/solution/1500-1599/1509.Minimum Difference Between Largest and Smallest Value in Three Moves/README.md b/solution/1500-1599/1509.Minimum Difference Between Largest and Smallest Value in Three Moves/README.md index 09c3ef28b1228..3bc3c905bf23b 100644 --- a/solution/1500-1599/1509.Minimum Difference Between Largest and Smallest Value in Three Moves/README.md +++ b/solution/1500-1599/1509.Minimum Difference Between Largest and Smallest Value in Three Moves/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def minDifference(self, nums: List[int]) -> int: @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minDifference(int[] nums) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func minDifference(nums []int) int { n := len(nums) diff --git a/solution/1500-1599/1509.Minimum Difference Between Largest and Smallest Value in Three Moves/README_EN.md b/solution/1500-1599/1509.Minimum Difference Between Largest and Smallest Value in Three Moves/README_EN.md index 1c4f73ceef190..6a926fc2b28dd 100644 --- a/solution/1500-1599/1509.Minimum Difference Between Largest and Smallest Value in Three Moves/README_EN.md +++ b/solution/1500-1599/1509.Minimum Difference Between Largest and Smallest Value in Three Moves/README_EN.md @@ -81,6 +81,8 @@ After performing 3 moves, the difference between the minimum and maximum is 7 - +#### Python3 + ```python class Solution: def minDifference(self, nums: List[int]) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minDifference(int[] nums) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func minDifference(nums []int) int { n := len(nums) diff --git a/solution/1500-1599/1510.Stone Game IV/README.md b/solution/1500-1599/1510.Stone Game IV/README.md index 51aa979cd32ce..1b8702110aa62 100644 --- a/solution/1500-1599/1510.Stone Game IV/README.md +++ b/solution/1500-1599/1510.Stone Game IV/README.md @@ -98,6 +98,8 @@ tags: +#### Python3 + ```python class Solution: def winnerSquareGame(self, n: int) -> bool: @@ -115,6 +117,8 @@ class Solution: return dfs(n) ``` +#### Java + ```java class Solution { private Boolean[] f; @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func winnerSquareGame(n int) bool { f := make([]int, n+1) @@ -192,6 +200,8 @@ func winnerSquareGame(n int) bool { } ``` +#### TypeScript + ```ts function winnerSquareGame(n: number): boolean { const f: number[] = new Array(n + 1).fill(0); @@ -243,6 +253,8 @@ $$ +#### Python3 + ```python class Solution: def winnerSquareGame(self, n: int) -> bool: @@ -257,6 +269,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public boolean winnerSquareGame(int n) { @@ -274,6 +288,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -293,6 +309,8 @@ public: }; ``` +#### Go + ```go func winnerSquareGame(n int) bool { f := make([]bool, n+1) @@ -308,6 +326,8 @@ func winnerSquareGame(n int) bool { } ``` +#### TypeScript + ```ts function winnerSquareGame(n: number): boolean { const f: boolean[] = new Array(n + 1).fill(false); diff --git a/solution/1500-1599/1510.Stone Game IV/README_EN.md b/solution/1500-1599/1510.Stone Game IV/README_EN.md index 0316db860028d..c1e30d79faf7e 100644 --- a/solution/1500-1599/1510.Stone Game IV/README_EN.md +++ b/solution/1500-1599/1510.Stone Game IV/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def winnerSquareGame(self, n: int) -> bool: @@ -86,6 +88,8 @@ class Solution: return dfs(n) ``` +#### Java + ```java class Solution { private Boolean[] f; @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func winnerSquareGame(n int) bool { f := make([]int, n+1) @@ -163,6 +171,8 @@ func winnerSquareGame(n int) bool { } ``` +#### TypeScript + ```ts function winnerSquareGame(n: number): boolean { const f: number[] = new Array(n + 1).fill(0); @@ -196,6 +206,8 @@ function winnerSquareGame(n: number): boolean { +#### Python3 + ```python class Solution: def winnerSquareGame(self, n: int) -> bool: @@ -210,6 +222,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public boolean winnerSquareGame(int n) { @@ -227,6 +241,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -246,6 +262,8 @@ public: }; ``` +#### Go + ```go func winnerSquareGame(n int) bool { f := make([]bool, n+1) @@ -261,6 +279,8 @@ func winnerSquareGame(n int) bool { } ``` +#### TypeScript + ```ts function winnerSquareGame(n: number): boolean { const f: boolean[] = new Array(n + 1).fill(false); diff --git a/solution/1500-1599/1511.Customer Order Frequency/README.md b/solution/1500-1599/1511.Customer Order Frequency/README.md index 2a8a8b65640ba..bcb7afd9a31e4 100644 --- a/solution/1500-1599/1511.Customer Order Frequency/README.md +++ b/solution/1500-1599/1511.Customer Order Frequency/README.md @@ -132,6 +132,8 @@ Moustafa 在 2020 年 6 月花费了 $110 (10 * 2 + 45 * 2), 在 7 月花费了 +#### MySQL + ```sql # Write your MySQL query statement below SELECT customer_id, name diff --git a/solution/1500-1599/1511.Customer Order Frequency/README_EN.md b/solution/1500-1599/1511.Customer Order Frequency/README_EN.md index d2d775b0f7a55..62887a3c7aee9 100644 --- a/solution/1500-1599/1511.Customer Order Frequency/README_EN.md +++ b/solution/1500-1599/1511.Customer Order Frequency/README_EN.md @@ -134,6 +134,8 @@ We can use the `JOIN` statement to join the `Orders` table and the `Product` tab +#### MySQL + ```sql # Write your MySQL query statement below SELECT customer_id, name diff --git a/solution/1500-1599/1512.Number of Good Pairs/README.md b/solution/1500-1599/1512.Number of Good Pairs/README.md index 3494e1679a792..be1308541d89b 100644 --- a/solution/1500-1599/1512.Number of Good Pairs/README.md +++ b/solution/1500-1599/1512.Number of Good Pairs/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def numIdenticalPairs(self, nums: List[int]) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numIdenticalPairs(int[] nums) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func numIdenticalPairs(nums []int) (ans int) { cnt := [101]int{} @@ -120,6 +128,8 @@ func numIdenticalPairs(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function numIdenticalPairs(nums: number[]): number { const cnt = new Array(101).fill(0); @@ -131,6 +141,8 @@ function numIdenticalPairs(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn num_identical_pairs(nums: Vec) -> i32 { @@ -145,6 +157,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** @@ -165,6 +179,8 @@ class Solution { } ``` +#### C + ```c int numIdenticalPairs(int* nums, int numsSize) { int cnt[101] = {0}; @@ -186,6 +202,8 @@ int numIdenticalPairs(int* nums, int numsSize) { +#### Python3 + ```python class Solution: def numIdenticalPairs(self, nums: List[int]) -> int: @@ -193,6 +211,8 @@ class Solution: return sum(v * (v - 1) for v in cnt.values()) >> 1 ``` +#### Java + ```java class Solution { public int numIdenticalPairs(int[] nums) { @@ -209,6 +229,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -226,6 +248,8 @@ public: }; ``` +#### Go + ```go func numIdenticalPairs(nums []int) (ans int) { cnt := [101]int{} @@ -239,6 +263,8 @@ func numIdenticalPairs(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function numIdenticalPairs(nums: number[]): number { const cnt = new Array(101).fill(0); @@ -253,6 +279,8 @@ function numIdenticalPairs(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn num_identical_pairs(nums: Vec) -> i32 { @@ -269,6 +297,8 @@ impl Solution { } ``` +#### C + ```c int numIdenticalPairs(int* nums, int numsSize) { int cnt[101] = {0}; diff --git a/solution/1500-1599/1512.Number of Good Pairs/README_EN.md b/solution/1500-1599/1512.Number of Good Pairs/README_EN.md index 54be5d678f506..5a33e5d94f4cf 100644 --- a/solution/1500-1599/1512.Number of Good Pairs/README_EN.md +++ b/solution/1500-1599/1512.Number of Good Pairs/README_EN.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def numIdenticalPairs(self, nums: List[int]) -> int: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numIdenticalPairs(int[] nums) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func numIdenticalPairs(nums []int) (ans int) { cnt := [101]int{} @@ -116,6 +124,8 @@ func numIdenticalPairs(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function numIdenticalPairs(nums: number[]): number { const cnt = new Array(101).fill(0); @@ -127,6 +137,8 @@ function numIdenticalPairs(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn num_identical_pairs(nums: Vec) -> i32 { @@ -141,6 +153,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** @@ -161,6 +175,8 @@ class Solution { } ``` +#### C + ```c int numIdenticalPairs(int* nums, int numsSize) { int cnt[101] = {0}; @@ -182,6 +198,8 @@ int numIdenticalPairs(int* nums, int numsSize) { +#### Python3 + ```python class Solution: def numIdenticalPairs(self, nums: List[int]) -> int: @@ -189,6 +207,8 @@ class Solution: return sum(v * (v - 1) for v in cnt.values()) >> 1 ``` +#### Java + ```java class Solution { public int numIdenticalPairs(int[] nums) { @@ -205,6 +225,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -222,6 +244,8 @@ public: }; ``` +#### Go + ```go func numIdenticalPairs(nums []int) (ans int) { cnt := [101]int{} @@ -235,6 +259,8 @@ func numIdenticalPairs(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function numIdenticalPairs(nums: number[]): number { const cnt = new Array(101).fill(0); @@ -249,6 +275,8 @@ function numIdenticalPairs(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn num_identical_pairs(nums: Vec) -> i32 { @@ -265,6 +293,8 @@ impl Solution { } ``` +#### C + ```c int numIdenticalPairs(int* nums, int numsSize) { int cnt[101] = {0}; diff --git a/solution/1500-1599/1513.Number of Substrings With Only 1s/README.md b/solution/1500-1599/1513.Number of Substrings With Only 1s/README.md index 4f73352cf3df3..12df5dee4a649 100644 --- a/solution/1500-1599/1513.Number of Substrings With Only 1s/README.md +++ b/solution/1500-1599/1513.Number of Substrings With Only 1s/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def numSub(self, s: str) -> int: @@ -99,6 +101,8 @@ class Solution: return ans % (10**9 + 7) ``` +#### Java + ```java class Solution { public int numSub(String s) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func numSub(s string) (ans int) { const mod = 1e9 + 7 @@ -144,6 +152,8 @@ func numSub(s string) (ans int) { } ``` +#### TypeScript + ```ts function numSub(s: string): number { const mod = 10 ** 9 + 7; diff --git a/solution/1500-1599/1513.Number of Substrings With Only 1s/README_EN.md b/solution/1500-1599/1513.Number of Substrings With Only 1s/README_EN.md index cc9046b43fd56..6290f4df727b9 100644 --- a/solution/1500-1599/1513.Number of Substrings With Only 1s/README_EN.md +++ b/solution/1500-1599/1513.Number of Substrings With Only 1s/README_EN.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def numSub(self, s: str) -> int: @@ -79,6 +81,8 @@ class Solution: return ans % (10**9 + 7) ``` +#### Java + ```java class Solution { public int numSub(String s) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func numSub(s string) (ans int) { const mod = 1e9 + 7 @@ -124,6 +132,8 @@ func numSub(s string) (ans int) { } ``` +#### TypeScript + ```ts function numSub(s: string): number { const mod = 10 ** 9 + 7; diff --git a/solution/1500-1599/1514.Path with Maximum Probability/README.md b/solution/1500-1599/1514.Path with Maximum Probability/README.md index da4c0722054a3..88b08e481fe02 100644 --- a/solution/1500-1599/1514.Path with Maximum Probability/README.md +++ b/solution/1500-1599/1514.Path with Maximum Probability/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def maxProbability( @@ -111,6 +113,8 @@ class Solution: return d[end] ``` +#### Java + ```java class Solution { public double maxProbability(int n, int[][] edges, double[] succProb, int start, int end) { @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func maxProbability(n int, edges [][]int, succProb []float64, start int, end int) float64 { g := make([][]pair, n) @@ -230,6 +238,8 @@ type pair struct { +#### Python3 + ```python class Solution: def maxProbability( @@ -261,6 +271,8 @@ class Solution: return d[end] ``` +#### Java + ```java class Solution { public double maxProbability(int n, int[][] edges, double[] succProb, int start, int end) { @@ -298,6 +310,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/1500-1599/1514.Path with Maximum Probability/README_EN.md b/solution/1500-1599/1514.Path with Maximum Probability/README_EN.md index 6d21b30727e99..a575f1aa4cb56 100644 --- a/solution/1500-1599/1514.Path with Maximum Probability/README_EN.md +++ b/solution/1500-1599/1514.Path with Maximum Probability/README_EN.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def maxProbability( @@ -110,6 +112,8 @@ class Solution: return d[end] ``` +#### Java + ```java class Solution { public double maxProbability(int n, int[][] edges, double[] succProb, int start, int end) { @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -180,6 +186,8 @@ public: }; ``` +#### Go + ```go func maxProbability(n int, edges [][]int, succProb []float64, start int, end int) float64 { g := make([][]pair, n) @@ -227,6 +235,8 @@ type pair struct { +#### Python3 + ```python class Solution: def maxProbability( @@ -258,6 +268,8 @@ class Solution: return d[end] ``` +#### Java + ```java class Solution { public double maxProbability(int n, int[][] edges, double[] succProb, int start, int end) { @@ -295,6 +307,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/1500-1599/1515.Best Position for a Service Centre/README.md b/solution/1500-1599/1515.Best Position for a Service Centre/README.md index 798b7017a1359..7d82263a8f429 100644 --- a/solution/1500-1599/1515.Best Position for a Service Centre/README.md +++ b/solution/1500-1599/1515.Best Position for a Service Centre/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def getMinDistSum(self, positions: List[List[int]]) -> float: @@ -105,6 +107,8 @@ class Solution: return dist ``` +#### Java + ```java class Solution { public double getMinDistSum(int[][] positions) { @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -178,6 +184,8 @@ public: }; ``` +#### Go + ```go func getMinDistSum(positions [][]int) float64 { n := len(positions) @@ -214,6 +222,8 @@ func getMinDistSum(positions [][]int) float64 { } ``` +#### TypeScript + ```ts function getMinDistSum(positions: number[][]): number { const n = positions.length; diff --git a/solution/1500-1599/1515.Best Position for a Service Centre/README_EN.md b/solution/1500-1599/1515.Best Position for a Service Centre/README_EN.md index a396df17cea1b..48fa1754c83a5 100644 --- a/solution/1500-1599/1515.Best Position for a Service Centre/README_EN.md +++ b/solution/1500-1599/1515.Best Position for a Service Centre/README_EN.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def getMinDistSum(self, positions: List[List[int]]) -> float: @@ -95,6 +97,8 @@ class Solution: return dist ``` +#### Java + ```java class Solution { public double getMinDistSum(int[][] positions) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func getMinDistSum(positions [][]int) float64 { n := len(positions) @@ -204,6 +212,8 @@ func getMinDistSum(positions [][]int) float64 { } ``` +#### TypeScript + ```ts function getMinDistSum(positions: number[][]): number { const n = positions.length; diff --git a/solution/1500-1599/1516.Move Sub-Tree of N-Ary Tree/README.md b/solution/1500-1599/1516.Move Sub-Tree of N-Ary Tree/README.md index 35e937700ac34..f84db1a2762b3 100644 --- a/solution/1500-1599/1516.Move Sub-Tree of N-Ary Tree/README.md +++ b/solution/1500-1599/1516.Move Sub-Tree of N-Ary Tree/README.md @@ -99,18 +99,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1500-1599/1516.Move Sub-Tree of N-Ary Tree/README_EN.md b/solution/1500-1599/1516.Move Sub-Tree of N-Ary Tree/README_EN.md index 778067c4f4fad..e0bb9b5768ef2 100644 --- a/solution/1500-1599/1516.Move Sub-Tree of N-Ary Tree/README_EN.md +++ b/solution/1500-1599/1516.Move Sub-Tree of N-Ary Tree/README_EN.md @@ -89,18 +89,26 @@ Notice that node 4 is the last child of node 1. +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1500-1599/1517.Find Users With Valid E-Mails/README.md b/solution/1500-1599/1517.Find Users With Valid E-Mails/README.md index 7f0a5ebbff32b..ddda78859db1a 100644 --- a/solution/1500-1599/1517.Find Users With Valid E-Mails/README.md +++ b/solution/1500-1599/1517.Find Users With Valid E-Mails/README.md @@ -88,6 +88,8 @@ Users 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT * diff --git a/solution/1500-1599/1517.Find Users With Valid E-Mails/README_EN.md b/solution/1500-1599/1517.Find Users With Valid E-Mails/README_EN.md index ae1cf5a672593..8bf7f75cf573a 100644 --- a/solution/1500-1599/1517.Find Users With Valid E-Mails/README_EN.md +++ b/solution/1500-1599/1517.Find Users With Valid E-Mails/README_EN.md @@ -87,6 +87,8 @@ The mail of user 7 starts with a period. +#### MySQL + ```sql # Write your MySQL query statement below SELECT * diff --git a/solution/1500-1599/1518.Water Bottles/README.md b/solution/1500-1599/1518.Water Bottles/README.md index 7ac6f3692f37b..b6b0f3fb3eed3 100644 --- a/solution/1500-1599/1518.Water Bottles/README.md +++ b/solution/1500-1599/1518.Water Bottles/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def numWaterBottles(self, numBottles: int, numExchange: int) -> int: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numWaterBottles(int numBottles, int numExchange) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func numWaterBottles(numBottles int, numExchange int) int { ans := numBottles @@ -125,6 +133,8 @@ func numWaterBottles(numBottles int, numExchange int) int { } ``` +#### TypeScript + ```ts function numWaterBottles(numBottles: number, numExchange: number): number { let ans = numBottles; @@ -135,6 +145,8 @@ function numWaterBottles(numBottles: number, numExchange: number): number { } ``` +#### JavaScript + ```js /** * @param {number} numBottles @@ -150,6 +162,8 @@ var numWaterBottles = function (numBottles, numExchange) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1500-1599/1518.Water Bottles/README_EN.md b/solution/1500-1599/1518.Water Bottles/README_EN.md index ec9663d8b113c..e1a89c2ee2a0f 100644 --- a/solution/1500-1599/1518.Water Bottles/README_EN.md +++ b/solution/1500-1599/1518.Water Bottles/README_EN.md @@ -62,6 +62,8 @@ Number of water bottles you can drink: 15 + 3 + 1 = 19. +#### Python3 + ```python class Solution: def numWaterBottles(self, numBottles: int, numExchange: int) -> int: @@ -72,6 +74,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numWaterBottles(int numBottles, int numExchange) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -97,6 +103,8 @@ public: }; ``` +#### Go + ```go func numWaterBottles(numBottles int, numExchange int) int { ans := numBottles @@ -107,6 +115,8 @@ func numWaterBottles(numBottles int, numExchange int) int { } ``` +#### TypeScript + ```ts function numWaterBottles(numBottles: number, numExchange: number): number { let ans = numBottles; @@ -117,6 +127,8 @@ function numWaterBottles(numBottles: number, numExchange: number): number { } ``` +#### JavaScript + ```js /** * @param {number} numBottles @@ -132,6 +144,8 @@ var numWaterBottles = function (numBottles, numExchange) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1500-1599/1519.Number of Nodes in the Sub-Tree With the Same Label/README.md b/solution/1500-1599/1519.Number of Nodes in the Sub-Tree With the Same Label/README.md index 69f4df77ea54a..f784147252f0f 100644 --- a/solution/1500-1599/1519.Number of Nodes in the Sub-Tree With the Same Label/README.md +++ b/solution/1500-1599/1519.Number of Nodes in the Sub-Tree With the Same Label/README.md @@ -97,6 +97,8 @@ tags: +#### Python3 + ```python class Solution: def countSubTrees(self, n: int, edges: List[List[int]], labels: str) -> List[int]: @@ -118,6 +120,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -183,6 +189,8 @@ public: }; ``` +#### Go + ```go func countSubTrees(n int, edges [][]int, labels string) []int { g := make([][]int, n) @@ -210,6 +218,8 @@ func countSubTrees(n int, edges [][]int, labels string) []int { } ``` +#### TypeScript + ```ts function countSubTrees(n: number, edges: number[][], labels: string): number[] { const dfs = (i: number, fa: number) => { diff --git a/solution/1500-1599/1519.Number of Nodes in the Sub-Tree With the Same Label/README_EN.md b/solution/1500-1599/1519.Number of Nodes in the Sub-Tree With the Same Label/README_EN.md index d1d6d743d116e..a6dbea7f47377 100644 --- a/solution/1500-1599/1519.Number of Nodes in the Sub-Tree With the Same Label/README_EN.md +++ b/solution/1500-1599/1519.Number of Nodes in the Sub-Tree With the Same Label/README_EN.md @@ -81,6 +81,8 @@ The sub-tree of node 0 contains nodes 0, 1, 2 and 3, all with label 'b', +#### Python3 + ```python class Solution: def countSubTrees(self, n: int, edges: List[List[int]], labels: str) -> List[int]: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func countSubTrees(n int, edges [][]int, labels string) []int { g := make([][]int, n) @@ -194,6 +202,8 @@ func countSubTrees(n int, edges [][]int, labels string) []int { } ``` +#### TypeScript + ```ts function countSubTrees(n: number, edges: number[][], labels: string): number[] { const dfs = (i: number, fa: number) => { diff --git a/solution/1500-1599/1520.Maximum Number of Non-Overlapping Substrings/README.md b/solution/1500-1599/1520.Maximum Number of Non-Overlapping Substrings/README.md index e2fe229a92425..52e16d78b259d 100644 --- a/solution/1500-1599/1520.Maximum Number of Non-Overlapping Substrings/README.md +++ b/solution/1500-1599/1520.Maximum Number of Non-Overlapping Substrings/README.md @@ -76,18 +76,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1500-1599/1520.Maximum Number of Non-Overlapping Substrings/README_EN.md b/solution/1500-1599/1520.Maximum Number of Non-Overlapping Substrings/README_EN.md index 35cf39270e6e3..61d50da1d3ce7 100644 --- a/solution/1500-1599/1520.Maximum Number of Non-Overlapping Substrings/README_EN.md +++ b/solution/1500-1599/1520.Maximum Number of Non-Overlapping Substrings/README_EN.md @@ -74,18 +74,26 @@ If we choose the first string, we cannot choose anything else and we'd get o +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1500-1599/1521.Find a Value of a Mysterious Function Closest to Target/README.md b/solution/1500-1599/1521.Find a Value of a Mysterious Function Closest to Target/README.md index a807983fdfc37..1d9c4dea6cd80 100644 --- a/solution/1500-1599/1521.Find a Value of a Mysterious Function Closest to Target/README.md +++ b/solution/1500-1599/1521.Find a Value of a Mysterious Function Closest to Target/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def closestToTarget(self, arr: List[int], target: int) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int closestToTarget(int[] arr, int target) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func closestToTarget(arr []int, target int) int { ans := abs(arr[0] - target) @@ -158,6 +166,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function closestToTarget(arr: number[], target: number): number { let ans = Math.abs(arr[0] - target); diff --git a/solution/1500-1599/1521.Find a Value of a Mysterious Function Closest to Target/README_EN.md b/solution/1500-1599/1521.Find a Value of a Mysterious Function Closest to Target/README_EN.md index 9f01649b64ac2..69ae6aca41953 100644 --- a/solution/1500-1599/1521.Find a Value of a Mysterious Function Closest to Target/README_EN.md +++ b/solution/1500-1599/1521.Find a Value of a Mysterious Function Closest to Target/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n \times \log M)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def closestToTarget(self, arr: List[int], target: int) -> int: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int closestToTarget(int[] arr, int target) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func closestToTarget(arr []int, target int) int { ans := abs(arr[0] - target) @@ -159,6 +167,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function closestToTarget(arr: number[], target: number): number { let ans = Math.abs(arr[0] - target); diff --git a/solution/1500-1599/1522.Diameter of N-Ary Tree/README.md b/solution/1500-1599/1522.Diameter of N-Ary Tree/README.md index 9049a70bed808..c4545b69482b6 100644 --- a/solution/1500-1599/1522.Diameter of N-Ary Tree/README.md +++ b/solution/1500-1599/1522.Diameter of N-Ary Tree/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python """ # Definition for a Node. @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java /* // Definition for a Node. @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -208,6 +214,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -251,6 +259,8 @@ func diameter(root *Node) int { +#### Python3 + ```python """ # Definition for a Node. @@ -299,6 +309,8 @@ class Solution: return ans ``` +#### Java + ```java /* // Definition for a Node. @@ -370,6 +382,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -431,6 +445,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. diff --git a/solution/1500-1599/1522.Diameter of N-Ary Tree/README_EN.md b/solution/1500-1599/1522.Diameter of N-Ary Tree/README_EN.md index 87b8f0ed784cf..3a8bf47a103bd 100644 --- a/solution/1500-1599/1522.Diameter of N-Ary Tree/README_EN.md +++ b/solution/1500-1599/1522.Diameter of N-Ary Tree/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python """ # Definition for a Node. @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java /* // Definition for a Node. @@ -158,6 +162,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -206,6 +212,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. @@ -249,6 +257,8 @@ func diameter(root *Node) int { +#### Python3 + ```python """ # Definition for a Node. @@ -297,6 +307,8 @@ class Solution: return ans ``` +#### Java + ```java /* // Definition for a Node. @@ -368,6 +380,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -429,6 +443,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a Node. diff --git a/solution/1500-1599/1523.Count Odd Numbers in an Interval Range/README.md b/solution/1500-1599/1523.Count Odd Numbers in an Interval Range/README.md index 15ecb9344ee65..6dbb43e00482c 100644 --- a/solution/1500-1599/1523.Count Odd Numbers in an Interval Range/README.md +++ b/solution/1500-1599/1523.Count Odd Numbers in an Interval Range/README.md @@ -54,12 +54,16 @@ tags: +#### Python3 + ```python class Solution: def countOdds(self, low: int, high: int) -> int: return ((high + 1) >> 1) - (low >> 1) ``` +#### Java + ```java class Solution { public int countOdds(int low, int high) { @@ -68,6 +72,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -77,18 +83,24 @@ public: }; ``` +#### Go + ```go func countOdds(low int, high int) int { return ((high + 1) >> 1) - (low >> 1) } ``` +#### TypeScript + ```ts function countOdds(low: number, high: number): number { return ((high + 1) >> 1) - (low >> 1); } ``` +#### Rust + ```rust impl Solution { pub fn count_odds(low: i32, high: i32) -> i32 { @@ -97,6 +109,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** @@ -110,6 +124,8 @@ class Solution { } ``` +#### C + ```c int countOdds(int low, int high) { return ((high + 1) >> 1) - (low >> 1); diff --git a/solution/1500-1599/1523.Count Odd Numbers in an Interval Range/README_EN.md b/solution/1500-1599/1523.Count Odd Numbers in an Interval Range/README_EN.md index b2f73bc5259c8..03cb439cf8dbc 100644 --- a/solution/1500-1599/1523.Count Odd Numbers in an Interval Range/README_EN.md +++ b/solution/1500-1599/1523.Count Odd Numbers in an Interval Range/README_EN.md @@ -62,12 +62,16 @@ tags: +#### Python3 + ```python class Solution: def countOdds(self, low: int, high: int) -> int: return ((high + 1) >> 1) - (low >> 1) ``` +#### Java + ```java class Solution { public int countOdds(int low, int high) { @@ -76,6 +80,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -85,18 +91,24 @@ public: }; ``` +#### Go + ```go func countOdds(low int, high int) int { return ((high + 1) >> 1) - (low >> 1) } ``` +#### TypeScript + ```ts function countOdds(low: number, high: number): number { return ((high + 1) >> 1) - (low >> 1); } ``` +#### Rust + ```rust impl Solution { pub fn count_odds(low: i32, high: i32) -> i32 { @@ -105,6 +117,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** @@ -118,6 +132,8 @@ class Solution { } ``` +#### C + ```c int countOdds(int low, int high) { return ((high + 1) >> 1) - (low >> 1); diff --git a/solution/1500-1599/1524.Number of Sub-arrays With Odd Sum/README.md b/solution/1500-1599/1524.Number of Sub-arrays With Odd Sum/README.md index 49029574b1bae..97fbd0514a02f 100644 --- a/solution/1500-1599/1524.Number of Sub-arrays With Odd Sum/README.md +++ b/solution/1500-1599/1524.Number of Sub-arrays With Odd Sum/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def numOfSubarrays(self, arr: List[int]) -> int: @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numOfSubarrays(int[] arr) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func numOfSubarrays(arr []int) (ans int) { const mod int = 1e9 + 7 @@ -152,6 +160,8 @@ func numOfSubarrays(arr []int) (ans int) { } ``` +#### TypeScript + ```ts function numOfSubarrays(arr: number[]): number { let ans = 0; diff --git a/solution/1500-1599/1524.Number of Sub-arrays With Odd Sum/README_EN.md b/solution/1500-1599/1524.Number of Sub-arrays With Odd Sum/README_EN.md index 47c890f0dc7ad..5cf6739dc03d8 100644 --- a/solution/1500-1599/1524.Number of Sub-arrays With Odd Sum/README_EN.md +++ b/solution/1500-1599/1524.Number of Sub-arrays With Odd Sum/README_EN.md @@ -71,6 +71,8 @@ All sub-arrays have even sum and the answer is 0. +#### Python3 + ```python class Solution: def numOfSubarrays(self, arr: List[int]) -> int: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numOfSubarrays(int[] arr) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func numOfSubarrays(arr []int) (ans int) { const mod int = 1e9 + 7 @@ -131,6 +139,8 @@ func numOfSubarrays(arr []int) (ans int) { } ``` +#### TypeScript + ```ts function numOfSubarrays(arr: number[]): number { let ans = 0; diff --git a/solution/1500-1599/1525.Number of Good Ways to Split a String/README.md b/solution/1500-1599/1525.Number of Good Ways to Split a String/README.md index f8bc8ebfe1bf9..3e64d50ce6813 100644 --- a/solution/1500-1599/1525.Number of Good Ways to Split a String/README.md +++ b/solution/1500-1599/1525.Number of Good Ways to Split a String/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def numSplits(self, s: str) -> int: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numSplits(String s) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func numSplits(s string) (ans int) { cnt := map[rune]int{} diff --git a/solution/1500-1599/1525.Number of Good Ways to Split a String/README_EN.md b/solution/1500-1599/1525.Number of Good Ways to Split a String/README_EN.md index 374c27ecbd85b..0ee9ed8173275 100644 --- a/solution/1500-1599/1525.Number of Good Ways to Split a String/README_EN.md +++ b/solution/1500-1599/1525.Number of Good Ways to Split a String/README_EN.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def numSplits(self, s: str) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numSplits(String s) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func numSplits(s string) (ans int) { cnt := map[rune]int{} diff --git a/solution/1500-1599/1526.Minimum Number of Increments on Subarrays to Form a Target Array/README.md b/solution/1500-1599/1526.Minimum Number of Increments on Subarrays to Form a Target Array/README.md index a885632c48f93..946a912a6162f 100644 --- a/solution/1500-1599/1526.Minimum Number of Increments on Subarrays to Form a Target Array/README.md +++ b/solution/1500-1599/1526.Minimum Number of Increments on Subarrays to Form a Target Array/README.md @@ -95,12 +95,16 @@ tags: +#### Python3 + ```python class Solution: def minNumberOperations(self, target: List[int]) -> int: return target[0] + sum(max(0, b - a) for a, b in pairwise(target)) ``` +#### Java + ```java class Solution { public int minNumberOperations(int[] target) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func minNumberOperations(target []int) int { f := target[0] @@ -142,6 +150,8 @@ func minNumberOperations(target []int) int { } ``` +#### TypeScript + ```ts function minNumberOperations(target: number[]): number { let f = target[0]; diff --git a/solution/1500-1599/1526.Minimum Number of Increments on Subarrays to Form a Target Array/README_EN.md b/solution/1500-1599/1526.Minimum Number of Increments on Subarrays to Form a Target Array/README_EN.md index 86a4355f07b2a..fe4370612f9d9 100644 --- a/solution/1500-1599/1526.Minimum Number of Increments on Subarrays to Form a Target Array/README_EN.md +++ b/solution/1500-1599/1526.Minimum Number of Increments on Subarrays to Form a Target Array/README_EN.md @@ -77,12 +77,16 @@ tags: +#### Python3 + ```python class Solution: def minNumberOperations(self, target: List[int]) -> int: return target[0] + sum(max(0, b - a) for a, b in pairwise(target)) ``` +#### Java + ```java class Solution { public int minNumberOperations(int[] target) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func minNumberOperations(target []int) int { f := target[0] @@ -124,6 +132,8 @@ func minNumberOperations(target []int) int { } ``` +#### TypeScript + ```ts function minNumberOperations(target: number[]): number { let f = target[0]; diff --git a/solution/1500-1599/1527.Patients With a Condition/README.md b/solution/1500-1599/1527.Patients With a Condition/README.md index 454fe7213bf1e..2c39a2f8b7fb8 100644 --- a/solution/1500-1599/1527.Patients With a Condition/README.md +++ b/solution/1500-1599/1527.Patients With a Condition/README.md @@ -73,6 +73,8 @@ tags: +#### MySQL + ```sql SELECT patient_id, diff --git a/solution/1500-1599/1527.Patients With a Condition/README_EN.md b/solution/1500-1599/1527.Patients With a Condition/README_EN.md index fd3274056c9af..c9c48861cda09 100644 --- a/solution/1500-1599/1527.Patients With a Condition/README_EN.md +++ b/solution/1500-1599/1527.Patients With a Condition/README_EN.md @@ -74,6 +74,8 @@ Patients table: +#### MySQL + ```sql SELECT patient_id, diff --git a/solution/1500-1599/1528.Shuffle String/README.md b/solution/1500-1599/1528.Shuffle String/README.md index 8d5251c028a45..7375a027abcc2 100644 --- a/solution/1500-1599/1528.Shuffle String/README.md +++ b/solution/1500-1599/1528.Shuffle String/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def restoreString(self, s: str, indices: List[int]) -> str: @@ -76,6 +78,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String restoreString(String s, int[] indices) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -103,6 +109,8 @@ public: }; ``` +#### Go + ```go func restoreString(s string, indices []int) string { ans := make([]rune, len(s)) @@ -113,6 +121,8 @@ func restoreString(s string, indices []int) string { } ``` +#### JavaScript + ```js /** * @param {string} s diff --git a/solution/1500-1599/1528.Shuffle String/README_EN.md b/solution/1500-1599/1528.Shuffle String/README_EN.md index 8e421db24ff08..b5e7e6778064f 100644 --- a/solution/1500-1599/1528.Shuffle String/README_EN.md +++ b/solution/1500-1599/1528.Shuffle String/README_EN.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def restoreString(self, s: str, indices: List[int]) -> str: @@ -70,6 +72,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String restoreString(String s, int[] indices) { @@ -83,6 +87,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -97,6 +103,8 @@ public: }; ``` +#### Go + ```go func restoreString(s string, indices []int) string { ans := make([]rune, len(s)) @@ -107,6 +115,8 @@ func restoreString(s string, indices []int) string { } ``` +#### JavaScript + ```js /** * @param {string} s diff --git a/solution/1500-1599/1529.Minimum Suffix Flips/README.md b/solution/1500-1599/1529.Minimum Suffix Flips/README.md index 37b9f185ade56..863f44b03a495 100644 --- a/solution/1500-1599/1529.Minimum Suffix Flips/README.md +++ b/solution/1500-1599/1529.Minimum Suffix Flips/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def minFlips(self, target: str) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minFlips(String target) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func minFlips(target string) int { ans := 0 diff --git a/solution/1500-1599/1529.Minimum Suffix Flips/README_EN.md b/solution/1500-1599/1529.Minimum Suffix Flips/README_EN.md index 0c63610ceca7c..e696a2f4a69e6 100644 --- a/solution/1500-1599/1529.Minimum Suffix Flips/README_EN.md +++ b/solution/1500-1599/1529.Minimum Suffix Flips/README_EN.md @@ -77,6 +77,8 @@ We need at least 3 flip operations to form target. +#### Python3 + ```python class Solution: def minFlips(self, target: str) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minFlips(String target) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func minFlips(target string) int { ans := 0 diff --git a/solution/1500-1599/1530.Number of Good Leaf Nodes Pairs/README.md b/solution/1500-1599/1530.Number of Good Leaf Nodes Pairs/README.md index a9e4540c80d15..1c9be8fd91600 100644 --- a/solution/1500-1599/1530.Number of Good Leaf Nodes Pairs/README.md +++ b/solution/1500-1599/1530.Number of Good Leaf Nodes Pairs/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -128,6 +130,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -178,6 +182,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -221,6 +227,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/1500-1599/1530.Number of Good Leaf Nodes Pairs/README_EN.md b/solution/1500-1599/1530.Number of Good Leaf Nodes Pairs/README_EN.md index 94f7efce95cc4..8f970a762fca7 100644 --- a/solution/1500-1599/1530.Number of Good Leaf Nodes Pairs/README_EN.md +++ b/solution/1500-1599/1530.Number of Good Leaf Nodes Pairs/README_EN.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -103,6 +105,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -153,6 +157,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -196,6 +202,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/1500-1599/1531.String Compression II/README.md b/solution/1500-1599/1531.String Compression II/README.md index 03de0f0bc4960..5e2a928334de5 100644 --- a/solution/1500-1599/1531.String Compression II/README.md +++ b/solution/1500-1599/1531.String Compression II/README.md @@ -69,6 +69,8 @@ tags: +#### Java + ```java class Solution { public int getLengthOfOptimalCompression(String s, int k) { diff --git a/solution/1500-1599/1531.String Compression II/README_EN.md b/solution/1500-1599/1531.String Compression II/README_EN.md index e37598fa8cf9d..8cb051bedba3f 100644 --- a/solution/1500-1599/1531.String Compression II/README_EN.md +++ b/solution/1500-1599/1531.String Compression II/README_EN.md @@ -70,6 +70,8 @@ tags: +#### Java + ```java class Solution { public int getLengthOfOptimalCompression(String s, int k) { diff --git a/solution/1500-1599/1532.The Most Recent Three Orders/README.md b/solution/1500-1599/1532.The Most Recent Three Orders/README.md index 151fd83509d9a..cd7b6d5a74801 100644 --- a/solution/1500-1599/1532.The Most Recent Three Orders/README.md +++ b/solution/1500-1599/1532.The Most Recent Three Orders/README.md @@ -129,6 +129,8 @@ Marwan 只有 1 笔订单。 +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1500-1599/1532.The Most Recent Three Orders/README_EN.md b/solution/1500-1599/1532.The Most Recent Three Orders/README_EN.md index efff20f0d4a92..6b479edbaaf57 100644 --- a/solution/1500-1599/1532.The Most Recent Three Orders/README_EN.md +++ b/solution/1500-1599/1532.The Most Recent Three Orders/README_EN.md @@ -122,6 +122,8 @@ We can use an equi-join to join the `Customers` table and the `Orders` table bas +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1500-1599/1533.Find the Index of the Large Integer/README.md b/solution/1500-1599/1533.Find the Index of the Large Integer/README.md index b4570b3642a9e..cc9db70fc2426 100644 --- a/solution/1500-1599/1533.Find the Index of the Large Integer/README.md +++ b/solution/1500-1599/1533.Find the Index of the Large Integer/README.md @@ -91,6 +91,8 @@ reader.compareSub(4, 4, 5, 5) // 返回 1。因此,可以确定 arr[4] 是数 +#### Python3 + ```python # """ # This is ArrayReader's API interface. @@ -127,6 +129,8 @@ class Solution: return left ``` +#### Java + ```java /** * // This is ArrayReader's API interface. @@ -163,6 +167,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * // This is the ArrayReader's API interface. @@ -201,6 +207,8 @@ public: }; ``` +#### Go + ```go /** * // This is the ArrayReader's API interface. diff --git a/solution/1500-1599/1533.Find the Index of the Large Integer/README_EN.md b/solution/1500-1599/1533.Find the Index of the Large Integer/README_EN.md index 19d99ef96e91f..7cf765d7ea6ff 100644 --- a/solution/1500-1599/1533.Find the Index of the Large Integer/README_EN.md +++ b/solution/1500-1599/1533.Find the Index of the Large Integer/README_EN.md @@ -85,6 +85,8 @@ Notice that we made only 3 calls, so the answer is valid. +#### Python3 + ```python # """ # This is ArrayReader's API interface. @@ -121,6 +123,8 @@ class Solution: return left ``` +#### Java + ```java /** * // This is ArrayReader's API interface. @@ -157,6 +161,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * // This is the ArrayReader's API interface. @@ -195,6 +201,8 @@ public: }; ``` +#### Go + ```go /** * // This is the ArrayReader's API interface. diff --git a/solution/1500-1599/1534.Count Good Triplets/README.md b/solution/1500-1599/1534.Count Good Triplets/README.md index 459b761fff137..8c86246489ee7 100644 --- a/solution/1500-1599/1534.Count Good Triplets/README.md +++ b/solution/1500-1599/1534.Count Good Triplets/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def countGoodTriplets(self, arr: List[int], a: int, b: int, c: int) -> int: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countGoodTriplets(int[] arr, int a, int b, int c) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func countGoodTriplets(arr []int, a int, b int, c int) (ans int) { n := len(arr) diff --git a/solution/1500-1599/1534.Count Good Triplets/README_EN.md b/solution/1500-1599/1534.Count Good Triplets/README_EN.md index 8d0d4c06b9765..2c122dfa156b1 100644 --- a/solution/1500-1599/1534.Count Good Triplets/README_EN.md +++ b/solution/1500-1599/1534.Count Good Triplets/README_EN.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def countGoodTriplets(self, arr: List[int], a: int, b: int, c: int) -> int: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countGoodTriplets(int[] arr, int a, int b, int c) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func countGoodTriplets(arr []int, a int, b int, c int) (ans int) { n := len(arr) diff --git a/solution/1500-1599/1535.Find the Winner of an Array Game/README.md b/solution/1500-1599/1535.Find the Winner of an Array Game/README.md index 177725d2b196c..0c331e14a24fc 100644 --- a/solution/1500-1599/1535.Find the Winner of an Array Game/README.md +++ b/solution/1500-1599/1535.Find the Winner of an Array Game/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def getWinner(self, arr: List[int], k: int) -> int: @@ -98,6 +100,8 @@ class Solution: return mx ``` +#### Java + ```java class Solution { public int getWinner(int[] arr, int k) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func getWinner(arr []int, k int) int { mx, cnt := arr[0], 0 @@ -157,6 +165,8 @@ func getWinner(arr []int, k int) int { } ``` +#### TypeScript + ```ts function getWinner(arr: number[], k: number): number { let mx = arr[0]; @@ -176,6 +186,8 @@ function getWinner(arr: number[], k: number): number { } ``` +#### C# + ```cs public class Solution { public int GetWinner(int[] arr, int k) { diff --git a/solution/1500-1599/1535.Find the Winner of an Array Game/README_EN.md b/solution/1500-1599/1535.Find the Winner of an Array Game/README_EN.md index 48e58b0c07dca..70d73dfe88897 100644 --- a/solution/1500-1599/1535.Find the Winner of an Array Game/README_EN.md +++ b/solution/1500-1599/1535.Find the Winner of an Array Game/README_EN.md @@ -70,6 +70,8 @@ So we can see that 4 rounds will be played and 5 is the winner because it wins 2 +#### Python3 + ```python class Solution: def getWinner(self, arr: List[int], k: int) -> int: @@ -86,6 +88,8 @@ class Solution: return mx ``` +#### Java + ```java class Solution { public int getWinner(int[] arr, int k) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func getWinner(arr []int, k int) int { mx, cnt := arr[0], 0 @@ -145,6 +153,8 @@ func getWinner(arr []int, k int) int { } ``` +#### TypeScript + ```ts function getWinner(arr: number[], k: number): number { let mx = arr[0]; @@ -164,6 +174,8 @@ function getWinner(arr: number[], k: number): number { } ``` +#### C# + ```cs public class Solution { public int GetWinner(int[] arr, int k) { diff --git a/solution/1500-1599/1536.Minimum Swaps to Arrange a Binary Grid/README.md b/solution/1500-1599/1536.Minimum Swaps to Arrange a Binary Grid/README.md index 86e5b8a11eacc..af425a533d310 100644 --- a/solution/1500-1599/1536.Minimum Swaps to Arrange a Binary Grid/README.md +++ b/solution/1500-1599/1536.Minimum Swaps to Arrange a Binary Grid/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def minSwaps(self, grid: List[List[int]]) -> int: @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minSwaps(int[][] grid) { @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -180,6 +186,8 @@ public: }; ``` +#### Go + ```go func minSwaps(grid [][]int) (ans int) { n := len(grid) @@ -215,6 +223,8 @@ func minSwaps(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function minSwaps(grid: number[][]): number { const n = grid.length; diff --git a/solution/1500-1599/1536.Minimum Swaps to Arrange a Binary Grid/README_EN.md b/solution/1500-1599/1536.Minimum Swaps to Arrange a Binary Grid/README_EN.md index 25da008d135cf..b7b3acd737d53 100644 --- a/solution/1500-1599/1536.Minimum Swaps to Arrange a Binary Grid/README_EN.md +++ b/solution/1500-1599/1536.Minimum Swaps to Arrange a Binary Grid/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$. Here, $n$ i +#### Python3 + ```python class Solution: def minSwaps(self, grid: List[List[int]]) -> int: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minSwaps(int[][] grid) { @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func minSwaps(grid [][]int) (ans int) { n := len(grid) @@ -209,6 +217,8 @@ func minSwaps(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function minSwaps(grid: number[][]): number { const n = grid.length; diff --git a/solution/1500-1599/1537.Get the Maximum Score/README.md b/solution/1500-1599/1537.Get the Maximum Score/README.md index a907935a1f2eb..e1c3780e8dcba 100644 --- a/solution/1500-1599/1537.Get the Maximum Score/README.md +++ b/solution/1500-1599/1537.Get the Maximum Score/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def maxSum(self, nums1: List[int], nums2: List[int]) -> int: @@ -114,6 +116,8 @@ class Solution: return max(f, g) % mod ``` +#### Java + ```java class Solution { public int maxSum(int[] nums1, int[] nums2) { @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go func maxSum(nums1 []int, nums2 []int) int { const mod int = 1e9 + 7 @@ -199,6 +207,8 @@ func maxSum(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function maxSum(nums1: number[], nums2: number[]): number { const mod = 1e9 + 7; diff --git a/solution/1500-1599/1537.Get the Maximum Score/README_EN.md b/solution/1500-1599/1537.Get the Maximum Score/README_EN.md index 0f19b3d29b365..7781b8ef2951d 100644 --- a/solution/1500-1599/1537.Get the Maximum Score/README_EN.md +++ b/solution/1500-1599/1537.Get the Maximum Score/README_EN.md @@ -83,6 +83,8 @@ Maximum sum is obtained with the path [6,7,8,9,10]. +#### Python3 + ```python class Solution: def maxSum(self, nums1: List[int], nums2: List[int]) -> int: @@ -110,6 +112,8 @@ class Solution: return max(f, g) % mod ``` +#### Java + ```java class Solution { public int maxSum(int[] nums1, int[] nums2) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func maxSum(nums1 []int, nums2 []int) int { const mod int = 1e9 + 7 @@ -195,6 +203,8 @@ func maxSum(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function maxSum(nums1: number[], nums2: number[]): number { const mod = 1e9 + 7; diff --git a/solution/1500-1599/1538.Guess the Majority in a Hidden Array/README.md b/solution/1500-1599/1538.Guess the Majority in a Hidden Array/README.md index 90f5082cbf129..07aba14af9b01 100644 --- a/solution/1500-1599/1538.Guess the Majority in a Hidden Array/README.md +++ b/solution/1500-1599/1538.Guess the Majority in a Hidden Array/README.md @@ -100,6 +100,8 @@ reader.query(4,5,6,7) // 返回 4,因为 nums[4], nums[5], nums[6], nums[7] +#### Python3 + ```python # """ # This is the ArrayReader's API interface. @@ -152,6 +154,8 @@ class Solution: return 3 if a > b else k ``` +#### Java + ```java /** * // This is the ArrayReader's API interface. @@ -212,6 +216,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * // This is the ArrayReader's API interface. @@ -272,6 +278,8 @@ public: }; ``` +#### Go + ```go /** * // This is the ArrayReader's API interface. @@ -331,6 +339,8 @@ func guessMajority(reader *ArrayReader) int { } ``` +#### TypeScript + ```ts /** * // This is the ArrayReader's API interface. diff --git a/solution/1500-1599/1538.Guess the Majority in a Hidden Array/README_EN.md b/solution/1500-1599/1538.Guess the Majority in a Hidden Array/README_EN.md index ee5838113d5ef..092b305ec2a3f 100644 --- a/solution/1500-1599/1538.Guess the Majority in a Hidden Array/README_EN.md +++ b/solution/1500-1599/1538.Guess the Majority in a Hidden Array/README_EN.md @@ -87,6 +87,8 @@ Index 2, 4, 6, 7 is also a correct answer. +#### Python3 + ```python # """ # This is the ArrayReader's API interface. @@ -139,6 +141,8 @@ class Solution: return 3 if a > b else k ``` +#### Java + ```java /** * // This is the ArrayReader's API interface. @@ -199,6 +203,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * // This is the ArrayReader's API interface. @@ -259,6 +265,8 @@ public: }; ``` +#### Go + ```go /** * // This is the ArrayReader's API interface. @@ -318,6 +326,8 @@ func guessMajority(reader *ArrayReader) int { } ``` +#### TypeScript + ```ts /** * // This is the ArrayReader's API interface. diff --git a/solution/1500-1599/1539.Kth Missing Positive Number/README.md b/solution/1500-1599/1539.Kth Missing Positive Number/README.md index e6a653041e2ba..10b8c79bee47e 100644 --- a/solution/1500-1599/1539.Kth Missing Positive Number/README.md +++ b/solution/1500-1599/1539.Kth Missing Positive Number/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def findKthPositive(self, arr: List[int], k: int) -> int: @@ -83,6 +85,8 @@ class Solution: return arr[left - 1] + k - (arr[left - 1] - (left - 1) - 1) ``` +#### Java + ```java class Solution { public int findKthPositive(int[] arr, int k) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func findKthPositive(arr []int, k int) int { if arr[0] > k { diff --git a/solution/1500-1599/1539.Kth Missing Positive Number/README_EN.md b/solution/1500-1599/1539.Kth Missing Positive Number/README_EN.md index 6f0b3e8e1b3d8..6f9d946e0a8a5 100644 --- a/solution/1500-1599/1539.Kth Missing Positive Number/README_EN.md +++ b/solution/1500-1599/1539.Kth Missing Positive Number/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def findKthPositive(self, arr: List[int], k: int) -> int: @@ -80,6 +82,8 @@ class Solution: return arr[left - 1] + k - (arr[left - 1] - (left - 1) - 1) ``` +#### Java + ```java class Solution { public int findKthPositive(int[] arr, int k) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func findKthPositive(arr []int, k int) int { if arr[0] > k { diff --git a/solution/1500-1599/1540.Can Convert String in K Moves/README.md b/solution/1500-1599/1540.Can Convert String in K Moves/README.md index 69008e9b4f89e..ffb5849361a08 100644 --- a/solution/1500-1599/1540.Can Convert String in K Moves/README.md +++ b/solution/1500-1599/1540.Can Convert String in K Moves/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def canConvertString(self, s: str, t: str, k: int) -> bool: @@ -105,6 +107,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean canConvertString(String s, String t, int k) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func canConvertString(s string, t string, k int) bool { if len(s) != len(t) { diff --git a/solution/1500-1599/1540.Can Convert String in K Moves/README_EN.md b/solution/1500-1599/1540.Can Convert String in K Moves/README_EN.md index de278f3891a73..57f359d874a47 100644 --- a/solution/1500-1599/1540.Can Convert String in K Moves/README_EN.md +++ b/solution/1500-1599/1540.Can Convert String in K Moves/README_EN.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def canConvertString(self, s: str, t: str, k: int) -> bool: @@ -93,6 +95,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean canConvertString(String s, String t, int k) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func canConvertString(s string, t string, k int) bool { if len(s) != len(t) { diff --git a/solution/1500-1599/1541.Minimum Insertions to Balance a Parentheses String/README.md b/solution/1500-1599/1541.Minimum Insertions to Balance a Parentheses String/README.md index cbe0d3aa6f7d7..61b2fc091448f 100644 --- a/solution/1500-1599/1541.Minimum Insertions to Balance a Parentheses String/README.md +++ b/solution/1500-1599/1541.Minimum Insertions to Balance a Parentheses String/README.md @@ -102,6 +102,8 @@ tags: +#### Python3 + ```python class Solution: def minInsertions(self, s: str) -> int: @@ -130,6 +132,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minInsertions(String s) { @@ -157,6 +161,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -185,6 +191,8 @@ public: }; ``` +#### Go + ```go func minInsertions(s string) int { ans, x, n := 0, 0, len(s) diff --git a/solution/1500-1599/1541.Minimum Insertions to Balance a Parentheses String/README_EN.md b/solution/1500-1599/1541.Minimum Insertions to Balance a Parentheses String/README_EN.md index f0c93f7ca53bb..5165f90a40029 100644 --- a/solution/1500-1599/1541.Minimum Insertions to Balance a Parentheses String/README_EN.md +++ b/solution/1500-1599/1541.Minimum Insertions to Balance a Parentheses String/README_EN.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def minInsertions(self, s: str) -> int: @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minInsertions(String s) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func minInsertions(s string) int { ans, x, n := 0, 0, len(s) diff --git a/solution/1500-1599/1542.Find Longest Awesome Substring/README.md b/solution/1500-1599/1542.Find Longest Awesome Substring/README.md index f329e44eb903f..ca26c962d4ffb 100644 --- a/solution/1500-1599/1542.Find Longest Awesome Substring/README.md +++ b/solution/1500-1599/1542.Find Longest Awesome Substring/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def longestAwesome(self, s: str) -> int: @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestAwesome(String s) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func longestAwesome(s string) int { d := [1024]int{} diff --git a/solution/1500-1599/1542.Find Longest Awesome Substring/README_EN.md b/solution/1500-1599/1542.Find Longest Awesome Substring/README_EN.md index 4fb4beadd6745..07d7b0c0e5f7b 100644 --- a/solution/1500-1599/1542.Find Longest Awesome Substring/README_EN.md +++ b/solution/1500-1599/1542.Find Longest Awesome Substring/README_EN.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def longestAwesome(self, s: str) -> int: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestAwesome(String s) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func longestAwesome(s string) int { d := [1024]int{} diff --git a/solution/1500-1599/1543.Fix Product Name Format/README.md b/solution/1500-1599/1543.Fix Product Name Format/README.md index 08bb9faf50ab6..e7d827dc417bc 100644 --- a/solution/1500-1599/1543.Fix Product Name Format/README.md +++ b/solution/1500-1599/1543.Fix Product Name Format/README.md @@ -87,6 +87,8 @@ Sales 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1500-1599/1543.Fix Product Name Format/README_EN.md b/solution/1500-1599/1543.Fix Product Name Format/README_EN.md index 37c14cbbe8888..b1a7abe7274bb 100644 --- a/solution/1500-1599/1543.Fix Product Name Format/README_EN.md +++ b/solution/1500-1599/1543.Fix Product Name Format/README_EN.md @@ -87,6 +87,8 @@ In March, one matryoshka was sold. +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1500-1599/1544.Make The String Great/README.md b/solution/1500-1599/1544.Make The String Great/README.md index 2c11e4816a45d..4032babd0179e 100644 --- a/solution/1500-1599/1544.Make The String Great/README.md +++ b/solution/1500-1599/1544.Make The String Great/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def makeGood(self, s: str) -> str: @@ -94,6 +96,8 @@ class Solution: return "".join(stk) ``` +#### Java + ```java class Solution { public String makeGood(String s) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func makeGood(s string) string { stk := []rune{} diff --git a/solution/1500-1599/1544.Make The String Great/README_EN.md b/solution/1500-1599/1544.Make The String Great/README_EN.md index 9c0d941712124..f517c920776f8 100644 --- a/solution/1500-1599/1544.Make The String Great/README_EN.md +++ b/solution/1500-1599/1544.Make The String Great/README_EN.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def makeGood(self, s: str) -> str: @@ -90,6 +92,8 @@ class Solution: return "".join(stk) ``` +#### Java + ```java class Solution { public String makeGood(String s) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func makeGood(s string) string { stk := []rune{} diff --git a/solution/1500-1599/1545.Find Kth Bit in Nth Binary String/README.md b/solution/1500-1599/1545.Find Kth Bit in Nth Binary String/README.md index 9b1f988045d85..2366c4ac33d88 100644 --- a/solution/1500-1599/1545.Find Kth Bit in Nth Binary String/README.md +++ b/solution/1500-1599/1545.Find Kth Bit in Nth Binary String/README.md @@ -102,6 +102,8 @@ tags: +#### Python3 + ```python class Solution: def findKthBit(self, n: int, k: int) -> str: @@ -118,6 +120,8 @@ class Solution: return str(dfs(n, k)) ``` +#### Java + ```java class Solution { public char findKthBit(int n, int k) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func findKthBit(n int, k int) byte { var dfs func(n, k int) int @@ -182,6 +190,8 @@ func findKthBit(n int, k int) byte { } ``` +#### TypeScript + ```ts function findKthBit(n: number, k: number): string { const dfs = (n: number, k: number): number => { diff --git a/solution/1500-1599/1545.Find Kth Bit in Nth Binary String/README_EN.md b/solution/1500-1599/1545.Find Kth Bit in Nth Binary String/README_EN.md index 3ec4e6669419a..45389ab250a6f 100644 --- a/solution/1500-1599/1545.Find Kth Bit in Nth Binary String/README_EN.md +++ b/solution/1500-1599/1545.Find Kth Bit in Nth Binary String/README_EN.md @@ -88,6 +88,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def findKthBit(self, n: int, k: int) -> str: @@ -104,6 +106,8 @@ class Solution: return str(dfs(n, k)) ``` +#### Java + ```java class Solution { public char findKthBit(int n, int k) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func findKthBit(n int, k int) byte { var dfs func(n, k int) int @@ -168,6 +176,8 @@ func findKthBit(n int, k int) byte { } ``` +#### TypeScript + ```ts function findKthBit(n: number, k: number): string { const dfs = (n: number, k: number): number => { diff --git a/solution/1500-1599/1546.Maximum Number of Non-Overlapping Subarrays With Sum Equals Target/README.md b/solution/1500-1599/1546.Maximum Number of Non-Overlapping Subarrays With Sum Equals Target/README.md index 47b2240060f86..190a23989a128 100644 --- a/solution/1500-1599/1546.Maximum Number of Non-Overlapping Subarrays With Sum Equals Target/README.md +++ b/solution/1500-1599/1546.Maximum Number of Non-Overlapping Subarrays With Sum Equals Target/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def maxNonOverlapping(self, nums: List[int], target: int) -> int: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxNonOverlapping(int[] nums, int target) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func maxNonOverlapping(nums []int, target int) (ans int) { n := len(nums) @@ -161,6 +169,8 @@ func maxNonOverlapping(nums []int, target int) (ans int) { } ``` +#### TypeScript + ```ts function maxNonOverlapping(nums: number[], target: number): number { const n = nums.length; diff --git a/solution/1500-1599/1546.Maximum Number of Non-Overlapping Subarrays With Sum Equals Target/README_EN.md b/solution/1500-1599/1546.Maximum Number of Non-Overlapping Subarrays With Sum Equals Target/README_EN.md index 981571271f83a..c22b9859620a6 100644 --- a/solution/1500-1599/1546.Maximum Number of Non-Overlapping Subarrays With Sum Equals Target/README_EN.md +++ b/solution/1500-1599/1546.Maximum Number of Non-Overlapping Subarrays With Sum Equals Target/README_EN.md @@ -64,6 +64,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def maxNonOverlapping(self, nums: List[int], target: int) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxNonOverlapping(int[] nums, int target) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func maxNonOverlapping(nums []int, target int) (ans int) { n := len(nums) @@ -148,6 +156,8 @@ func maxNonOverlapping(nums []int, target int) (ans int) { } ``` +#### TypeScript + ```ts function maxNonOverlapping(nums: number[], target: number): number { const n = nums.length; diff --git a/solution/1500-1599/1547.Minimum Cost to Cut a Stick/README.md b/solution/1500-1599/1547.Minimum Cost to Cut a Stick/README.md index 8b38ef07d296e..d2fc1c8013a7e 100644 --- a/solution/1500-1599/1547.Minimum Cost to Cut a Stick/README.md +++ b/solution/1500-1599/1547.Minimum Cost to Cut a Stick/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def minCost(self, n: int, cuts: List[int]) -> int: @@ -103,6 +105,8 @@ class Solution: return f[0][-1] ``` +#### Java + ```java class Solution { public int minCost(int n, int[] cuts) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func minCost(n int, cuts []int) int { cuts = append(cuts, []int{0, n}...) @@ -174,6 +182,8 @@ func minCost(n int, cuts []int) int { } ``` +#### TypeScript + ```ts function minCost(n: number, cuts: number[]): number { cuts.push(0); @@ -203,6 +213,8 @@ function minCost(n: number, cuts: number[]): number { +#### Python3 + ```python class Solution: def minCost(self, n: int, cuts: List[int]) -> int: @@ -218,6 +230,8 @@ class Solution: return f[0][-1] ``` +#### Java + ```java class Solution { public int minCost(int n, int[] cuts) { @@ -243,6 +257,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -265,6 +281,8 @@ public: }; ``` +#### Go + ```go func minCost(n int, cuts []int) int { cuts = append(cuts, []int{0, n}...) diff --git a/solution/1500-1599/1547.Minimum Cost to Cut a Stick/README_EN.md b/solution/1500-1599/1547.Minimum Cost to Cut a Stick/README_EN.md index ce4470737209a..435b11224366e 100644 --- a/solution/1500-1599/1547.Minimum Cost to Cut a Stick/README_EN.md +++ b/solution/1500-1599/1547.Minimum Cost to Cut a Stick/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(m^3)$, and the space complexity is $O(m^2)$. Here, $m$ +#### Python3 + ```python class Solution: def minCost(self, n: int, cuts: List[int]) -> int: @@ -98,6 +100,8 @@ class Solution: return f[0][-1] ``` +#### Java + ```java class Solution { public int minCost(int n, int[] cuts) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func minCost(n int, cuts []int) int { cuts = append(cuts, []int{0, n}...) @@ -169,6 +177,8 @@ func minCost(n int, cuts []int) int { } ``` +#### TypeScript + ```ts function minCost(n: number, cuts: number[]): number { cuts.push(0); @@ -198,6 +208,8 @@ function minCost(n: number, cuts: number[]): number { +#### Python3 + ```python class Solution: def minCost(self, n: int, cuts: List[int]) -> int: @@ -213,6 +225,8 @@ class Solution: return f[0][-1] ``` +#### Java + ```java class Solution { public int minCost(int n, int[] cuts) { @@ -238,6 +252,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -260,6 +276,8 @@ public: }; ``` +#### Go + ```go func minCost(n int, cuts []int) int { cuts = append(cuts, []int{0, n}...) diff --git a/solution/1500-1599/1548.The Most Similar Path in a Graph/README.md b/solution/1500-1599/1548.The Most Similar Path in a Graph/README.md index f8fac22d6ff39..d31f9d6b722d3 100644 --- a/solution/1500-1599/1548.The Most Similar Path in a Graph/README.md +++ b/solution/1500-1599/1548.The Most Similar Path in a Graph/README.md @@ -111,6 +111,8 @@ $$ +#### Python3 + ```python class Solution: def mostSimilar( @@ -144,6 +146,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List mostSimilar(int n, int[][] roads, String[] names, String[] targetPath) { @@ -194,6 +198,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -241,6 +247,8 @@ public: }; ``` +#### Go + ```go func mostSimilar(n int, roads [][]int, names []string, targetPath []string) []int { g := make([][]int, n) @@ -298,6 +306,8 @@ func mostSimilar(n int, roads [][]int, names []string, targetPath []string) []in } ``` +#### TypeScript + ```ts function mostSimilar( n: number, diff --git a/solution/1500-1599/1548.The Most Similar Path in a Graph/README_EN.md b/solution/1500-1599/1548.The Most Similar Path in a Graph/README_EN.md index 5309e15682e5c..224cd70028095 100644 --- a/solution/1500-1599/1548.The Most Similar Path in a Graph/README_EN.md +++ b/solution/1500-1599/1548.The Most Similar Path in a Graph/README_EN.md @@ -102,6 +102,8 @@ The time complexity is $O(m \times n^2)$, and the space complexity is $O(m \time +#### Python3 + ```python class Solution: def mostSimilar( @@ -135,6 +137,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List mostSimilar(int n, int[][] roads, String[] names, String[] targetPath) { @@ -185,6 +189,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -232,6 +238,8 @@ public: }; ``` +#### Go + ```go func mostSimilar(n int, roads [][]int, names []string, targetPath []string) []int { g := make([][]int, n) @@ -289,6 +297,8 @@ func mostSimilar(n int, roads [][]int, names []string, targetPath []string) []in } ``` +#### TypeScript + ```ts function mostSimilar( n: number, diff --git a/solution/1500-1599/1549.The Most Recent Orders for Each Product/README.md b/solution/1500-1599/1549.The Most Recent Orders for Each Product/README.md index f2c0fa3e3e098..aae1ff3038958 100644 --- a/solution/1500-1599/1549.The Most Recent Orders for Each Product/README.md +++ b/solution/1500-1599/1549.The Most Recent Orders for Each Product/README.md @@ -137,6 +137,8 @@ hard disk 没有被下单, 我们不把它包含在结果表中. +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1500-1599/1549.The Most Recent Orders for Each Product/README_EN.md b/solution/1500-1599/1549.The Most Recent Orders for Each Product/README_EN.md index b85ae52575fbb..54bffcc2c6b98 100644 --- a/solution/1500-1599/1549.The Most Recent Orders for Each Product/README_EN.md +++ b/solution/1500-1599/1549.The Most Recent Orders for Each Product/README_EN.md @@ -137,6 +137,8 @@ We can use an equi-join to join the `Orders` table and the `Products` table base +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1500-1599/1550.Three Consecutive Odds/README.md b/solution/1500-1599/1550.Three Consecutive Odds/README.md index 69375d1aea82d..7a86894d76374 100644 --- a/solution/1500-1599/1550.Three Consecutive Odds/README.md +++ b/solution/1500-1599/1550.Three Consecutive Odds/README.md @@ -59,6 +59,8 @@ tags: +#### Python3 + ```python class Solution: def threeConsecutiveOdds(self, arr: List[int]) -> bool: @@ -73,6 +75,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean threeConsecutiveOdds(int[] arr) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func threeConsecutiveOdds(arr []int) bool { cnt := 0 @@ -126,6 +134,8 @@ func threeConsecutiveOdds(arr []int) bool { } ``` +#### TypeScript + ```ts function threeConsecutiveOdds(arr: number[]): boolean { let cnt = 0; @@ -153,6 +163,8 @@ function threeConsecutiveOdds(arr: number[]): boolean { +#### Python3 + ```python class Solution: def threeConsecutiveOdds(self, arr: List[int]) -> bool: 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 a3ecadc8cb327..407fbacf7bf52 100644 --- a/solution/1500-1599/1550.Three Consecutive Odds/README_EN.md +++ b/solution/1500-1599/1550.Three Consecutive Odds/README_EN.md @@ -55,6 +55,8 @@ Given an integer array arr, return true if there +#### Python3 + ```python class Solution: def threeConsecutiveOdds(self, arr: List[int]) -> bool: @@ -69,6 +71,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean threeConsecutiveOdds(int[] arr) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func threeConsecutiveOdds(arr []int) bool { cnt := 0 @@ -122,6 +130,8 @@ func threeConsecutiveOdds(arr []int) bool { } ``` +#### TypeScript + ```ts function threeConsecutiveOdds(arr: number[]): boolean { let cnt = 0; @@ -149,6 +159,8 @@ function threeConsecutiveOdds(arr: number[]): boolean { +#### Python3 + ```python class Solution: def threeConsecutiveOdds(self, arr: List[int]) -> bool: diff --git a/solution/1500-1599/1551.Minimum Operations to Make Array Equal/README.md b/solution/1500-1599/1551.Minimum Operations to Make Array Equal/README.md index a11f69f9d1cb0..0ace28808da50 100644 --- a/solution/1500-1599/1551.Minimum Operations to Make Array Equal/README.md +++ b/solution/1500-1599/1551.Minimum Operations to Make Array Equal/README.md @@ -77,12 +77,16 @@ $$ +#### Python3 + ```python class Solution: def minOperations(self, n: int) -> int: return sum(n - (i << 1 | 1) for i in range(n >> 1)) ``` +#### Java + ```java class Solution { public int minOperations(int n) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func minOperations(n int) (ans int) { for i := 0; i < n>>1; i++ { @@ -117,6 +125,8 @@ func minOperations(n int) (ans int) { } ``` +#### TypeScript + ```ts function minOperations(n: number): number { let ans = 0; diff --git a/solution/1500-1599/1551.Minimum Operations to Make Array Equal/README_EN.md b/solution/1500-1599/1551.Minimum Operations to Make Array Equal/README_EN.md index f5083c0c6f1d1..ed538b6acfb0e 100644 --- a/solution/1500-1599/1551.Minimum Operations to Make Array Equal/README_EN.md +++ b/solution/1500-1599/1551.Minimum Operations to Make Array Equal/README_EN.md @@ -77,12 +77,16 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def minOperations(self, n: int) -> int: return sum(n - (i << 1 | 1) for i in range(n >> 1)) ``` +#### Java + ```java class Solution { public int minOperations(int n) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func minOperations(n int) (ans int) { for i := 0; i < n>>1; i++ { @@ -117,6 +125,8 @@ func minOperations(n int) (ans int) { } ``` +#### TypeScript + ```ts function minOperations(n: number): number { let ans = 0; diff --git a/solution/1500-1599/1552.Magnetic Force Between Two Balls/README.md b/solution/1500-1599/1552.Magnetic Force Between Two Balls/README.md index 64207d70637c3..8f6cdee488704 100644 --- a/solution/1500-1599/1552.Magnetic Force Between Two Balls/README.md +++ b/solution/1500-1599/1552.Magnetic Force Between Two Balls/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def maxDistance(self, position: List[int], m: int) -> int: @@ -94,6 +96,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int maxDistance(int[] position, int m) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func maxDistance(position []int, m int) int { sort.Ints(position) @@ -182,6 +190,8 @@ func maxDistance(position []int, m int) int { } ``` +#### JavaScript + ```js /** * @param {number[]} position diff --git a/solution/1500-1599/1552.Magnetic Force Between Two Balls/README_EN.md b/solution/1500-1599/1552.Magnetic Force Between Two Balls/README_EN.md index b4807aa8edc11..5eb75dc4d8110 100644 --- a/solution/1500-1599/1552.Magnetic Force Between Two Balls/README_EN.md +++ b/solution/1500-1599/1552.Magnetic Force Between Two Balls/README_EN.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def maxDistance(self, position: List[int], m: int) -> int: @@ -88,6 +90,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int maxDistance(int[] position, int m) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func maxDistance(position []int, m int) int { sort.Ints(position) @@ -176,6 +184,8 @@ func maxDistance(position []int, m int) int { } ``` +#### JavaScript + ```js /** * @param {number[]} position diff --git a/solution/1500-1599/1553.Minimum Number of Days to Eat N Oranges/README.md b/solution/1500-1599/1553.Minimum Number of Days to Eat N Oranges/README.md index b52cb8f9b9b30..3fb2757a3ce6e 100644 --- a/solution/1500-1599/1553.Minimum Number of Days to Eat N Oranges/README.md +++ b/solution/1500-1599/1553.Minimum Number of Days to Eat N Oranges/README.md @@ -103,6 +103,8 @@ tags: +#### Python3 + ```python class Solution: def minDays(self, n: int) -> int: @@ -115,6 +117,8 @@ class Solution: return dfs(n) ``` +#### Java + ```java class Solution { private Map f = new HashMap<>(); @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func minDays(n int) int { f := map[int]int{0: 0, 1: 1} @@ -176,6 +184,8 @@ func minDays(n int) int { } ``` +#### TypeScript + ```ts function minDays(n: number): number { const f: Record = {}; diff --git a/solution/1500-1599/1553.Minimum Number of Days to Eat N Oranges/README_EN.md b/solution/1500-1599/1553.Minimum Number of Days to Eat N Oranges/README_EN.md index fc81e8af07b43..582129a888dad 100644 --- a/solution/1500-1599/1553.Minimum Number of Days to Eat N Oranges/README_EN.md +++ b/solution/1500-1599/1553.Minimum Number of Days to Eat N Oranges/README_EN.md @@ -91,6 +91,8 @@ The time complexity is $O(\log^2 n)$, and the space complexity is $O(\log^2 n)$. +#### Python3 + ```python class Solution: def minDays(self, n: int) -> int: @@ -103,6 +105,8 @@ class Solution: return dfs(n) ``` +#### Java + ```java class Solution { private Map f = new HashMap<>(); @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func minDays(n int) int { f := map[int]int{0: 0, 1: 1} @@ -164,6 +172,8 @@ func minDays(n int) int { } ``` +#### TypeScript + ```ts function minDays(n: number): number { const f: Record = {}; diff --git a/solution/1500-1599/1554.Strings Differ by One Character/README.md b/solution/1500-1599/1554.Strings Differ by One Character/README.md index 326b64a6262d8..e7707af141c85 100644 --- a/solution/1500-1599/1554.Strings Differ by One Character/README.md +++ b/solution/1500-1599/1554.Strings Differ by One Character/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def differByOne(self, dict: List[str]) -> bool: @@ -85,6 +87,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean differByOne(String[] dict) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func differByOne(dict []string) bool { s := make(map[string]bool) diff --git a/solution/1500-1599/1554.Strings Differ by One Character/README_EN.md b/solution/1500-1599/1554.Strings Differ by One Character/README_EN.md index c3b0331a39ce0..3797db25385bc 100644 --- a/solution/1500-1599/1554.Strings Differ by One Character/README_EN.md +++ b/solution/1500-1599/1554.Strings Differ by One Character/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def differByOne(self, dict: List[str]) -> bool: @@ -82,6 +84,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean differByOne(String[] dict) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func differByOne(dict []string) bool { s := make(map[string]bool) diff --git a/solution/1500-1599/1555.Bank Account Summary/README.md b/solution/1500-1599/1555.Bank Account Summary/README.md index aaf8afeb13eab..1aefb3f162908 100644 --- a/solution/1500-1599/1555.Bank Account Summary/README.md +++ b/solution/1500-1599/1555.Bank Account Summary/README.md @@ -114,6 +114,8 @@ Luis 未收到任何转账信息,额度 = $800 +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1500-1599/1555.Bank Account Summary/README_EN.md b/solution/1500-1599/1555.Bank Account Summary/README_EN.md index 32d164c122c2d..1b93df7495d8e 100644 --- a/solution/1500-1599/1555.Bank Account Summary/README_EN.md +++ b/solution/1500-1599/1555.Bank Account Summary/README_EN.md @@ -114,6 +114,8 @@ Luis did not received any transfer, credit = $800 +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1500-1599/1556.Thousand Separator/README.md b/solution/1500-1599/1556.Thousand Separator/README.md index 943a21c2016c5..8d4dd35da71ac 100644 --- a/solution/1500-1599/1556.Thousand Separator/README.md +++ b/solution/1500-1599/1556.Thousand Separator/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def thousandSeparator(self, n: int) -> str: @@ -85,6 +87,8 @@ class Solution: return ''.join(ans[::-1]) ``` +#### Java + ```java class Solution { public String thousandSeparator(int n) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func thousandSeparator(n int) string { cnt := 0 diff --git a/solution/1500-1599/1556.Thousand Separator/README_EN.md b/solution/1500-1599/1556.Thousand Separator/README_EN.md index c6a9ddb71d7cc..2ce2bebc3d2cf 100644 --- a/solution/1500-1599/1556.Thousand Separator/README_EN.md +++ b/solution/1500-1599/1556.Thousand Separator/README_EN.md @@ -52,6 +52,8 @@ tags: +#### Python3 + ```python class Solution: def thousandSeparator(self, n: int) -> str: @@ -69,6 +71,8 @@ class Solution: return ''.join(ans[::-1]) ``` +#### Java + ```java class Solution { public String thousandSeparator(int n) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func thousandSeparator(n int) string { cnt := 0 diff --git a/solution/1500-1599/1557.Minimum Number of Vertices to Reach All Nodes/README.md b/solution/1500-1599/1557.Minimum Number of Vertices to Reach All Nodes/README.md index 51c7b037d2eeb..c0ba35a90e721 100644 --- a/solution/1500-1599/1557.Minimum Number of Vertices to Reach All Nodes/README.md +++ b/solution/1500-1599/1557.Minimum Number of Vertices to Reach All Nodes/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def findSmallestSetOfVertices(self, n: int, edges: List[List[int]]) -> List[int]: @@ -76,6 +78,8 @@ class Solution: return [i for i in range(n) if cnt[i] == 0] ``` +#### Java + ```java class Solution { public List findSmallestSetOfVertices(int n, List> edges) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func findSmallestSetOfVertices(n int, edges [][]int) (ans []int) { cnt := make([]int, n) @@ -128,6 +136,8 @@ func findSmallestSetOfVertices(n int, edges [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function findSmallestSetOfVertices(n: number, edges: number[][]): number[] { const cnt: number[] = new Array(n).fill(0); @@ -144,6 +154,8 @@ function findSmallestSetOfVertices(n: number, edges: number[][]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn find_smallest_set_of_vertices(n: i32, edges: Vec>) -> Vec { diff --git a/solution/1500-1599/1557.Minimum Number of Vertices to Reach All Nodes/README_EN.md b/solution/1500-1599/1557.Minimum Number of Vertices to Reach All Nodes/README_EN.md index 099a58b0f4702..2f1604f6aede0 100644 --- a/solution/1500-1599/1557.Minimum Number of Vertices to Reach All Nodes/README_EN.md +++ b/solution/1500-1599/1557.Minimum Number of Vertices to Reach All Nodes/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def findSmallestSetOfVertices(self, n: int, edges: List[List[int]]) -> List[int]: @@ -72,6 +74,8 @@ class Solution: return [i for i in range(n) if cnt[i] == 0] ``` +#### Java + ```java class Solution { public List findSmallestSetOfVertices(int n, List> edges) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func findSmallestSetOfVertices(n int, edges [][]int) (ans []int) { cnt := make([]int, n) @@ -124,6 +132,8 @@ func findSmallestSetOfVertices(n int, edges [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function findSmallestSetOfVertices(n: number, edges: number[][]): number[] { const cnt: number[] = new Array(n).fill(0); @@ -140,6 +150,8 @@ function findSmallestSetOfVertices(n: number, edges: number[][]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn find_smallest_set_of_vertices(n: i32, edges: Vec>) -> Vec { diff --git a/solution/1500-1599/1558.Minimum Numbers of Function Calls to Make Target Array/README.md b/solution/1500-1599/1558.Minimum Numbers of Function Calls to Make Target Array/README.md index f5957ac6ef24d..d99edb3aa36ea 100644 --- a/solution/1500-1599/1558.Minimum Numbers of Function Calls to Make Target Array/README.md +++ b/solution/1500-1599/1558.Minimum Numbers of Function Calls to Make Target Array/README.md @@ -92,12 +92,16 @@ tags: +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int]) -> int: return sum(v.bit_count() for v in nums) + max(0, max(nums).bit_length() - 1) ``` +#### Java + ```java class Solution { public int minOperations(int[] nums) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int) int { ans, mx := 0, 0 diff --git a/solution/1500-1599/1558.Minimum Numbers of Function Calls to Make Target Array/README_EN.md b/solution/1500-1599/1558.Minimum Numbers of Function Calls to Make Target Array/README_EN.md index dc5edf103a8e9..d8d6bfab74683 100644 --- a/solution/1500-1599/1558.Minimum Numbers of Function Calls to Make Target Array/README_EN.md +++ b/solution/1500-1599/1558.Minimum Numbers of Function Calls to Make Target Array/README_EN.md @@ -76,12 +76,16 @@ Total of operations: 2 + 1 = 3. +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int]) -> int: return sum(v.bit_count() for v in nums) + max(0, max(nums).bit_length() - 1) ``` +#### Java + ```java class Solution { public int minOperations(int[] nums) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int) int { ans, mx := 0, 0 diff --git a/solution/1500-1599/1559.Detect Cycles in 2D Grid/README.md b/solution/1500-1599/1559.Detect Cycles in 2D Grid/README.md index 4bee4917be0bb..80fa17cbdd788 100644 --- a/solution/1500-1599/1559.Detect Cycles in 2D Grid/README.md +++ b/solution/1500-1599/1559.Detect Cycles in 2D Grid/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def containsCycle(self, grid: List[List[str]]) -> bool: @@ -103,6 +105,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { private int[] p; @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go func containsCycle(grid [][]byte) bool { m, n := len(grid), len(grid[0]) @@ -204,6 +212,8 @@ func containsCycle(grid [][]byte) bool { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -263,6 +273,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {character[][]} grid diff --git a/solution/1500-1599/1559.Detect Cycles in 2D Grid/README_EN.md b/solution/1500-1599/1559.Detect Cycles in 2D Grid/README_EN.md index c250e66994369..a2196440a7991 100644 --- a/solution/1500-1599/1559.Detect Cycles in 2D Grid/README_EN.md +++ b/solution/1500-1599/1559.Detect Cycles in 2D Grid/README_EN.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def containsCycle(self, grid: List[List[str]]) -> bool: @@ -103,6 +105,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { private int[] p; @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go func containsCycle(grid [][]byte) bool { m, n := len(grid), len(grid[0]) @@ -204,6 +212,8 @@ func containsCycle(grid [][]byte) bool { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -263,6 +273,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {character[][]} grid diff --git a/solution/1500-1599/1560.Most Visited Sector in a Circular Track/README.md b/solution/1500-1599/1560.Most Visited Sector in a Circular Track/README.md index 6aa8dbe0344ae..f99453ef12efd 100644 --- a/solution/1500-1599/1560.Most Visited Sector in a Circular Track/README.md +++ b/solution/1500-1599/1560.Most Visited Sector in a Circular Track/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def mostVisited(self, n: int, rounds: List[int]) -> List[int]: @@ -79,6 +81,8 @@ class Solution: return list(range(1, rounds[-1] + 1)) + list(range(rounds[0], n + 1)) ``` +#### Java + ```java class Solution { public List mostVisited(int n, int[] rounds) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func mostVisited(n int, rounds []int) []int { m := len(rounds) - 1 diff --git a/solution/1500-1599/1560.Most Visited Sector in a Circular Track/README_EN.md b/solution/1500-1599/1560.Most Visited Sector in a Circular Track/README_EN.md index ded05b5d60139..0e1ba33cf82ad 100644 --- a/solution/1500-1599/1560.Most Visited Sector in a Circular Track/README_EN.md +++ b/solution/1500-1599/1560.Most Visited Sector in a Circular Track/README_EN.md @@ -70,6 +70,8 @@ We can see that both sectors 1 and 2 are visited twice and they are the most vis +#### Python3 + ```python class Solution: def mostVisited(self, n: int, rounds: List[int]) -> List[int]: @@ -78,6 +80,8 @@ class Solution: return list(range(1, rounds[-1] + 1)) + list(range(rounds[0], n + 1)) ``` +#### Java + ```java class Solution { public List mostVisited(int n, int[] rounds) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func mostVisited(n int, rounds []int) []int { m := len(rounds) - 1 diff --git a/solution/1500-1599/1561.Maximum Number of Coins You Can Get/README.md b/solution/1500-1599/1561.Maximum Number of Coins You Can Get/README.md index f258d7d93fbf5..4addb84130633 100644 --- a/solution/1500-1599/1561.Maximum Number of Coins You Can Get/README.md +++ b/solution/1500-1599/1561.Maximum Number of Coins You Can Get/README.md @@ -82,6 +82,8 @@ Bob 取走最小的 1/3,剩余的硬币堆由 Alice 和我按硬币数从高 +#### Python3 + ```python class Solution: def maxCoins(self, piles: List[int]) -> int: @@ -89,6 +91,8 @@ class Solution: return sum(piles[-2 : len(piles) // 3 - 1 : -2]) ``` +#### Java + ```java class Solution { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func maxCoins(piles []int) int { sort.Ints(piles) @@ -126,6 +134,8 @@ func maxCoins(piles []int) int { } ``` +#### TypeScript + ```ts function maxCoins(piles: number[]): number { piles.sort((a, b) => a - b); @@ -138,6 +148,8 @@ function maxCoins(piles: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_coins(mut piles: Vec) -> i32 { @@ -152,6 +164,8 @@ impl Solution { } ``` +#### C + ```c int cmp(const void* a, const void* b) { return *(int*) a - *(int*) b; diff --git a/solution/1500-1599/1561.Maximum Number of Coins You Can Get/README_EN.md b/solution/1500-1599/1561.Maximum Number of Coins You Can Get/README_EN.md index acb27d0cbdebc..cdae8d6f3af99 100644 --- a/solution/1500-1599/1561.Maximum Number of Coins You Can Get/README_EN.md +++ b/solution/1500-1599/1561.Maximum Number of Coins You Can Get/README_EN.md @@ -81,6 +81,8 @@ On the other hand if we choose this arrangement (1, 2, 8), (2, +#### Python3 + ```python class Solution: def maxCoins(self, piles: List[int]) -> int: @@ -88,6 +90,8 @@ class Solution: return sum(piles[-2 : len(piles) // 3 - 1 : -2]) ``` +#### Java + ```java class Solution { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func maxCoins(piles []int) int { sort.Ints(piles) @@ -125,6 +133,8 @@ func maxCoins(piles []int) int { } ``` +#### TypeScript + ```ts function maxCoins(piles: number[]): number { piles.sort((a, b) => a - b); @@ -137,6 +147,8 @@ function maxCoins(piles: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_coins(mut piles: Vec) -> i32 { @@ -151,6 +163,8 @@ impl Solution { } ``` +#### C + ```c int cmp(const void* a, const void* b) { return *(int*) a - *(int*) b; diff --git a/solution/1500-1599/1562.Find Latest Group of Size M/README.md b/solution/1500-1599/1562.Find Latest Group of Size M/README.md index aec7ad4033fb9..ecbb32c70a1de 100644 --- a/solution/1500-1599/1562.Find Latest Group of Size M/README.md +++ b/solution/1500-1599/1562.Find Latest Group of Size M/README.md @@ -97,6 +97,8 @@ tags: +#### Python3 + ```python class Solution: def findLatestStep(self, arr: List[int], m: int) -> int: @@ -133,6 +135,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] p; @@ -188,6 +192,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -231,6 +237,8 @@ public: }; ``` +#### Go + ```go func findLatestStep(arr []int, m int) int { n := len(arr) @@ -295,6 +303,8 @@ func findLatestStep(arr []int, m int) int { +#### Python3 + ```python class Solution: def findLatestStep(self, arr: List[int], m: int) -> int: @@ -312,6 +322,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findLatestStep(int[] arr, int m) { @@ -335,6 +347,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -354,6 +368,8 @@ public: }; ``` +#### Go + ```go func findLatestStep(arr []int, m int) int { n := len(arr) diff --git a/solution/1500-1599/1562.Find Latest Group of Size M/README_EN.md b/solution/1500-1599/1562.Find Latest Group of Size M/README_EN.md index e96d7c1f9b98e..871c03a645257 100644 --- a/solution/1500-1599/1562.Find Latest Group of Size M/README_EN.md +++ b/solution/1500-1599/1562.Find Latest Group of Size M/README_EN.md @@ -77,6 +77,8 @@ No group of size 2 exists during any step. +#### Python3 + ```python class Solution: def findLatestStep(self, arr: List[int], m: int) -> int: @@ -113,6 +115,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] p; @@ -168,6 +172,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -211,6 +217,8 @@ public: }; ``` +#### Go + ```go func findLatestStep(arr []int, m int) int { n := len(arr) @@ -271,6 +279,8 @@ func findLatestStep(arr []int, m int) int { +#### Python3 + ```python class Solution: def findLatestStep(self, arr: List[int], m: int) -> int: @@ -288,6 +298,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findLatestStep(int[] arr, int m) { @@ -311,6 +323,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -330,6 +344,8 @@ public: }; ``` +#### Go + ```go func findLatestStep(arr []int, m int) int { n := len(arr) diff --git a/solution/1500-1599/1563.Stone Game V/README.md b/solution/1500-1599/1563.Stone Game V/README.md index 2634e4fdc99d9..e3c6f844a667b 100644 --- a/solution/1500-1599/1563.Stone Game V/README.md +++ b/solution/1500-1599/1563.Stone Game V/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def stoneGameV(self, stoneValue: List[int]) -> int: @@ -115,6 +117,8 @@ class Solution: return dfs(0, len(stoneValue) - 1) ``` +#### Java + ```java class Solution { private int n; @@ -164,6 +168,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -209,6 +215,8 @@ public: }; ``` +#### Go + ```go func stoneGameV(stoneValue []int) int { n := len(stoneValue) diff --git a/solution/1500-1599/1563.Stone Game V/README_EN.md b/solution/1500-1599/1563.Stone Game V/README_EN.md index ceee6fe0df1df..4b4ad760021a2 100644 --- a/solution/1500-1599/1563.Stone Game V/README_EN.md +++ b/solution/1500-1599/1563.Stone Game V/README_EN.md @@ -72,6 +72,8 @@ The last round Alice has only one choice to divide the row which is [2], [3]. Bo +#### Python3 + ```python class Solution: def stoneGameV(self, stoneValue: List[int]) -> int: @@ -99,6 +101,8 @@ class Solution: return dfs(0, len(stoneValue) - 1) ``` +#### Java + ```java class Solution { private int n; @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go func stoneGameV(stoneValue []int) int { n := len(stoneValue) diff --git a/solution/1500-1599/1564.Put Boxes Into the Warehouse I/README.md b/solution/1500-1599/1564.Put Boxes Into the Warehouse I/README.md index 1c6715c43cca1..94b19b60dffe5 100644 --- a/solution/1500-1599/1564.Put Boxes Into the Warehouse I/README.md +++ b/solution/1500-1599/1564.Put Boxes Into the Warehouse I/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python class Solution: def maxBoxesInWarehouse(self, boxes: List[int], warehouse: List[int]) -> int: @@ -113,6 +115,8 @@ class Solution: return i ``` +#### Java + ```java class Solution { public int maxBoxesInWarehouse(int[] boxes, int[] warehouse) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go func maxBoxesInWarehouse(boxes []int, warehouse []int) int { n := len(warehouse) @@ -189,6 +197,8 @@ func maxBoxesInWarehouse(boxes []int, warehouse []int) int { } ``` +#### TypeScript + ```ts function maxBoxesInWarehouse(boxes: number[], warehouse: number[]): number { const n = warehouse.length; diff --git a/solution/1500-1599/1564.Put Boxes Into the Warehouse I/README_EN.md b/solution/1500-1599/1564.Put Boxes Into the Warehouse I/README_EN.md index 8b1215aac37a4..27e53fff09811 100644 --- a/solution/1500-1599/1564.Put Boxes Into the Warehouse I/README_EN.md +++ b/solution/1500-1599/1564.Put Boxes Into the Warehouse I/README_EN.md @@ -83,6 +83,8 @@ Swapping the orange and green boxes is also valid, or swapping one of them with +#### Python3 + ```python class Solution: def maxBoxesInWarehouse(self, boxes: List[int], warehouse: List[int]) -> int: @@ -101,6 +103,8 @@ class Solution: return i ``` +#### Java + ```java class Solution { public int maxBoxesInWarehouse(int[] boxes, int[] warehouse) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func maxBoxesInWarehouse(boxes []int, warehouse []int) int { n := len(warehouse) @@ -177,6 +185,8 @@ func maxBoxesInWarehouse(boxes []int, warehouse []int) int { } ``` +#### TypeScript + ```ts function maxBoxesInWarehouse(boxes: number[], warehouse: number[]): number { const n = warehouse.length; diff --git a/solution/1500-1599/1565.Unique Orders and Customers Per Month/README.md b/solution/1500-1599/1565.Unique Orders and Customers Per Month/README.md index fe4ba94c5937d..1cbe5036fd543 100644 --- a/solution/1500-1599/1565.Unique Orders and Customers Per Month/README.md +++ b/solution/1500-1599/1565.Unique Orders and Customers Per Month/README.md @@ -86,6 +86,8 @@ Orders +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1500-1599/1565.Unique Orders and Customers Per Month/README_EN.md b/solution/1500-1599/1565.Unique Orders and Customers Per Month/README_EN.md index 559268b0d335b..fddd57092b387 100644 --- a/solution/1500-1599/1565.Unique Orders and Customers Per Month/README_EN.md +++ b/solution/1500-1599/1565.Unique Orders and Customers Per Month/README_EN.md @@ -86,6 +86,8 @@ In January 2021 we have two orders from 2 different customers, but only one of t +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1500-1599/1566.Detect Pattern of Length M Repeated K or More Times/README.md b/solution/1500-1599/1566.Detect Pattern of Length M Repeated K or More Times/README.md index 9173a87ac8467..d097b9262ad02 100644 --- a/solution/1500-1599/1566.Detect Pattern of Length M Repeated K or More Times/README.md +++ b/solution/1500-1599/1566.Detect Pattern of Length M Repeated K or More Times/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def containsPattern(self, arr: List[int], m: int, k: int) -> bool: @@ -102,6 +104,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean containsPattern(int[] arr, int m, int k) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func containsPattern(arr []int, m int, k int) bool { n := len(arr) @@ -161,6 +169,8 @@ func containsPattern(arr []int, m int, k int) bool { } ``` +#### TypeScript + ```ts function containsPattern(arr: number[], m: number, k: number): boolean { const n = arr.length; diff --git a/solution/1500-1599/1566.Detect Pattern of Length M Repeated K or More Times/README_EN.md b/solution/1500-1599/1566.Detect Pattern of Length M Repeated K or More Times/README_EN.md index 3235b9ddd55bf..22217fd4c41ab 100644 --- a/solution/1500-1599/1566.Detect Pattern of Length M Repeated K or More Times/README_EN.md +++ b/solution/1500-1599/1566.Detect Pattern of Length M Repeated K or More Times/README_EN.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def containsPattern(self, arr: List[int], m: int, k: int) -> bool: @@ -85,6 +87,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean containsPattern(int[] arr, int m, int k) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func containsPattern(arr []int, m int, k int) bool { n := len(arr) @@ -144,6 +152,8 @@ func containsPattern(arr []int, m int, k int) bool { } ``` +#### TypeScript + ```ts function containsPattern(arr: number[], m: number, k: number): boolean { const n = arr.length; diff --git a/solution/1500-1599/1567.Maximum Length of Subarray With Positive Product/README.md b/solution/1500-1599/1567.Maximum Length of Subarray With Positive Product/README.md index b83024f1911f0..b0851027fa1ce 100644 --- a/solution/1500-1599/1567.Maximum Length of Subarray With Positive Product/README.md +++ b/solution/1500-1599/1567.Maximum Length of Subarray With Positive Product/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def getMaxLen(self, nums: List[int]) -> int: @@ -101,6 +103,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public int getMaxLen(int[] nums) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func getMaxLen(nums []int) int { f1, f2 := 0, 0 @@ -187,6 +195,8 @@ func getMaxLen(nums []int) int { } ``` +#### TypeScript + ```ts function getMaxLen(nums: number[]): number { // 连续正数计数n1, 连续负数计数n2 diff --git a/solution/1500-1599/1567.Maximum Length of Subarray With Positive Product/README_EN.md b/solution/1500-1599/1567.Maximum Length of Subarray With Positive Product/README_EN.md index f1ff403fa7534..0a8fa37343e95 100644 --- a/solution/1500-1599/1567.Maximum Length of Subarray With Positive Product/README_EN.md +++ b/solution/1500-1599/1567.Maximum Length of Subarray With Positive Product/README_EN.md @@ -69,6 +69,8 @@ Notice that we cannot include 0 in the subarray since that'll make the produ +#### Python3 + ```python class Solution: def getMaxLen(self, nums: List[int]) -> int: @@ -97,6 +99,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public int getMaxLen(int[] nums) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func getMaxLen(nums []int) int { f1, f2 := 0, 0 @@ -183,6 +191,8 @@ func getMaxLen(nums []int) int { } ``` +#### TypeScript + ```ts function getMaxLen(nums: number[]): number { // 连续正数计数n1, 连续负数计数n2 diff --git a/solution/1500-1599/1568.Minimum Number of Days to Disconnect Island/README.md b/solution/1500-1599/1568.Minimum Number of Days to Disconnect Island/README.md index 66975038733ab..37fc147aeb922 100644 --- a/solution/1500-1599/1568.Minimum Number of Days to Disconnect Island/README.md +++ b/solution/1500-1599/1568.Minimum Number of Days to Disconnect Island/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def minDays(self, grid: List[List[int]]) -> int: @@ -116,6 +118,8 @@ class Solution: return cnt ``` +#### Java + ```java class Solution { private static final int[] DIRS = new int[] {-1, 0, 1, 0, -1}; @@ -176,6 +180,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -233,6 +239,8 @@ public: }; ``` +#### Go + ```go func minDays(grid [][]int) int { m, n := len(grid), len(grid[0]) diff --git a/solution/1500-1599/1568.Minimum Number of Days to Disconnect Island/README_EN.md b/solution/1500-1599/1568.Minimum Number of Days to Disconnect Island/README_EN.md index cab5933c9aa08..76e9a2206e446 100644 --- a/solution/1500-1599/1568.Minimum Number of Days to Disconnect Island/README_EN.md +++ b/solution/1500-1599/1568.Minimum Number of Days to Disconnect Island/README_EN.md @@ -70,6 +70,8 @@ Change land grid[1][1] and grid[0][2] to water and get 2 disconnected island. +#### Python3 + ```python class Solution: def minDays(self, grid: List[List[int]]) -> int: @@ -107,6 +109,8 @@ class Solution: return cnt ``` +#### Java + ```java class Solution { private static final int[] DIRS = new int[] {-1, 0, 1, 0, -1}; @@ -167,6 +171,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -224,6 +230,8 @@ public: }; ``` +#### Go + ```go func minDays(grid [][]int) int { m, n := len(grid), len(grid[0]) diff --git a/solution/1500-1599/1569.Number of Ways to Reorder Array to Get Same BST/README.md b/solution/1500-1599/1569.Number of Ways to Reorder Array to Get Same BST/README.md index 26ccca60ea71b..223ba2eaec855 100644 --- a/solution/1500-1599/1569.Number of Ways to Reorder Array to Get Same BST/README.md +++ b/solution/1500-1599/1569.Number of Ways to Reorder Array to Get Same BST/README.md @@ -108,6 +108,8 @@ $$ +#### Python3 + ```python class Solution: def numOfWays(self, nums: List[int]) -> int: @@ -131,6 +133,8 @@ class Solution: return (dfs(nums) - 1 + mod) % mod ``` +#### Java + ```java class Solution { private int[][] c; @@ -173,6 +177,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -209,6 +215,8 @@ public: }; ``` +#### Go + ```go func numOfWays(nums []int) int { n := len(nums) @@ -245,6 +253,8 @@ func numOfWays(nums []int) int { } ``` +#### TypeScript + ```ts function numOfWays(nums: number[]): number { const n = nums.length; diff --git a/solution/1500-1599/1569.Number of Ways to Reorder Array to Get Same BST/README_EN.md b/solution/1500-1599/1569.Number of Ways to Reorder Array to Get Same BST/README_EN.md index bb9be6e5b96be..b251b113cc112 100644 --- a/solution/1500-1599/1569.Number of Ways to Reorder Array to Get Same BST/README_EN.md +++ b/solution/1500-1599/1569.Number of Ways to Reorder Array to Get Same BST/README_EN.md @@ -102,6 +102,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$. Where $n$ +#### Python3 + ```python class Solution: def numOfWays(self, nums: List[int]) -> int: @@ -125,6 +127,8 @@ class Solution: return (dfs(nums) - 1 + mod) % mod ``` +#### Java + ```java class Solution { private int[][] c; @@ -167,6 +171,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -203,6 +209,8 @@ public: }; ``` +#### Go + ```go func numOfWays(nums []int) int { n := len(nums) @@ -239,6 +247,8 @@ func numOfWays(nums []int) int { } ``` +#### TypeScript + ```ts function numOfWays(nums: number[]): number { const n = nums.length; diff --git a/solution/1500-1599/1570.Dot Product of Two Sparse Vectors/README.md b/solution/1500-1599/1570.Dot Product of Two Sparse Vectors/README.md index 4dea94d9258e3..2a47af11bbc73 100644 --- a/solution/1500-1599/1570.Dot Product of Two Sparse Vectors/README.md +++ b/solution/1500-1599/1570.Dot Product of Two Sparse Vectors/README.md @@ -85,6 +85,8 @@ v1.dotProduct(v2) = 0*0 + 1*0 + 0*0 + 0*0 + 0*2 = 0 +#### Python3 + ```python class SparseVector: def __init__(self, nums: List[int]): @@ -104,6 +106,8 @@ class SparseVector: # ans = v1.dotProduct(v2) ``` +#### Java + ```java class SparseVector { public Map d = new HashMap<>(128); @@ -140,6 +144,8 @@ class SparseVector { // int ans = v1.dotProduct(v2); ``` +#### C++ + ```cpp class SparseVector { public: @@ -176,6 +182,8 @@ public: // int ans = v1.dotProduct(v2); ``` +#### Go + ```go type SparseVector struct { d map[int]int @@ -213,6 +221,8 @@ func (this *SparseVector) dotProduct(vec SparseVector) (ans int) { */ ``` +#### TypeScript + ```ts class SparseVector { d: Map; diff --git a/solution/1500-1599/1570.Dot Product of Two Sparse Vectors/README_EN.md b/solution/1500-1599/1570.Dot Product of Two Sparse Vectors/README_EN.md index 701c9298be4b0..5aa2c99489ba6 100644 --- a/solution/1500-1599/1570.Dot Product of Two Sparse Vectors/README_EN.md +++ b/solution/1500-1599/1570.Dot Product of Two Sparse Vectors/README_EN.md @@ -77,6 +77,8 @@ v1.dotProduct(v2) = 0*0 + 1*0 + 0*0 + 0*0 + 0*2 = 0 +#### Python3 + ```python class SparseVector: def __init__(self, nums: List[int]): @@ -96,6 +98,8 @@ class SparseVector: # ans = v1.dotProduct(v2) ``` +#### Java + ```java class SparseVector { public Map d = new HashMap<>(128); @@ -132,6 +136,8 @@ class SparseVector { // int ans = v1.dotProduct(v2); ``` +#### C++ + ```cpp class SparseVector { public: @@ -168,6 +174,8 @@ public: // int ans = v1.dotProduct(v2); ``` +#### Go + ```go type SparseVector struct { d map[int]int @@ -205,6 +213,8 @@ func (this *SparseVector) dotProduct(vec SparseVector) (ans int) { */ ``` +#### TypeScript + ```ts class SparseVector { d: Map; diff --git a/solution/1500-1599/1571.Warehouse Manager/README.md b/solution/1500-1599/1571.Warehouse Manager/README.md index f7b34e3328c9e..483f01cf10c50 100644 --- a/solution/1500-1599/1571.Warehouse Manager/README.md +++ b/solution/1500-1599/1571.Warehouse Manager/README.md @@ -114,6 +114,8 @@ Id为4的商品(LC-T-Shirt)的存货量为 4x10x20 = 800 +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1500-1599/1571.Warehouse Manager/README_EN.md b/solution/1500-1599/1571.Warehouse Manager/README_EN.md index 2175ef332c82c..fe3ea24eade16 100644 --- a/solution/1500-1599/1571.Warehouse Manager/README_EN.md +++ b/solution/1500-1599/1571.Warehouse Manager/README_EN.md @@ -114,6 +114,8 @@ We can use an inner join to join the `Warehouse` table and the `Products` table +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1500-1599/1572.Matrix Diagonal Sum/README.md b/solution/1500-1599/1572.Matrix Diagonal Sum/README.md index cc43710f6c840..a8d710d4e5073 100644 --- a/solution/1500-1599/1572.Matrix Diagonal Sum/README.md +++ b/solution/1500-1599/1572.Matrix Diagonal Sum/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def diagonalSum(self, mat: List[List[int]]) -> int: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int diagonalSum(int[][] mat) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func diagonalSum(mat [][]int) (ans int) { n := len(mat) @@ -134,6 +142,8 @@ func diagonalSum(mat [][]int) (ans int) { } ``` +#### TypeScript + ```ts function diagonalSum(mat: number[][]): number { let ans = 0; @@ -146,6 +156,8 @@ function diagonalSum(mat: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn diagonal_sum(mat: Vec>) -> i32 { @@ -162,6 +174,8 @@ impl Solution { } ``` +#### C + ```c int diagonalSum(int** mat, int matSize, int* matColSize) { int ans = 0; @@ -185,6 +199,8 @@ int diagonalSum(int** mat, int matSize, int* matColSize) { +#### TypeScript + ```ts function diagonalSum(mat: number[][]): number { const n = mat.length; diff --git a/solution/1500-1599/1572.Matrix Diagonal Sum/README_EN.md b/solution/1500-1599/1572.Matrix Diagonal Sum/README_EN.md index acf04f8c97fd0..1c8c7591c7143 100644 --- a/solution/1500-1599/1572.Matrix Diagonal Sum/README_EN.md +++ b/solution/1500-1599/1572.Matrix Diagonal Sum/README_EN.md @@ -71,6 +71,8 @@ Notice that element mat[1][1] = 5 is counted only once. +#### Python3 + ```python class Solution: def diagonalSum(self, mat: List[List[int]]) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int diagonalSum(int[][] mat) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func diagonalSum(mat [][]int) (ans int) { n := len(mat) @@ -124,6 +132,8 @@ func diagonalSum(mat [][]int) (ans int) { } ``` +#### TypeScript + ```ts function diagonalSum(mat: number[][]): number { let ans = 0; @@ -136,6 +146,8 @@ function diagonalSum(mat: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn diagonal_sum(mat: Vec>) -> i32 { @@ -152,6 +164,8 @@ impl Solution { } ``` +#### C + ```c int diagonalSum(int** mat, int matSize, int* matColSize) { int ans = 0; @@ -175,6 +189,8 @@ int diagonalSum(int** mat, int matSize, int* matColSize) { +#### TypeScript + ```ts function diagonalSum(mat: number[][]): number { const n = mat.length; diff --git a/solution/1500-1599/1573.Number of Ways to Split a String/README.md b/solution/1500-1599/1573.Number of Ways to Split a String/README.md index 48d8b219a3328..b98884df41aeb 100644 --- a/solution/1500-1599/1573.Number of Ways to Split a String/README.md +++ b/solution/1500-1599/1573.Number of Ways to Split a String/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def numWays(self, s: str) -> int: @@ -115,6 +117,8 @@ class Solution: return (i2 - i1) * (j2 - j1) % (10**9 + 7) ``` +#### Java + ```java class Solution { private String s; @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go func numWays(s string) int { cnt := 0 diff --git a/solution/1500-1599/1573.Number of Ways to Split a String/README_EN.md b/solution/1500-1599/1573.Number of Ways to Split a String/README_EN.md index 66d17efcd38af..3daa1af238ca4 100644 --- a/solution/1500-1599/1573.Number of Ways to Split a String/README_EN.md +++ b/solution/1500-1599/1573.Number of Ways to Split a String/README_EN.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def numWays(self, s: str) -> int: @@ -94,6 +96,8 @@ class Solution: return (i2 - i1) * (j2 - j1) % (10**9 + 7) ``` +#### Java + ```java class Solution { private String s; @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func numWays(s string) int { cnt := 0 diff --git a/solution/1500-1599/1574.Shortest Subarray to be Removed to Make Array Sorted/README.md b/solution/1500-1599/1574.Shortest Subarray to be Removed to Make Array Sorted/README.md index e42606b5de3f4..e72ada63b1b4c 100644 --- a/solution/1500-1599/1574.Shortest Subarray to be Removed to Make Array Sorted/README.md +++ b/solution/1500-1599/1574.Shortest Subarray to be Removed to Make Array Sorted/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def findLengthOfShortestSubarray(self, arr: List[int]) -> int: @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findLengthOfShortestSubarray(int[] arr) { @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go func findLengthOfShortestSubarray(arr []int) int { n := len(arr) @@ -212,6 +220,8 @@ func findLengthOfShortestSubarray(arr []int) int { +#### Python3 + ```python class Solution: def findLengthOfShortestSubarray(self, arr: List[int]) -> int: @@ -232,6 +242,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findLengthOfShortestSubarray(int[] arr) { @@ -258,6 +270,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -285,6 +299,8 @@ public: }; ``` +#### Go + ```go func findLengthOfShortestSubarray(arr []int) int { n := len(arr) diff --git a/solution/1500-1599/1574.Shortest Subarray to be Removed to Make Array Sorted/README_EN.md b/solution/1500-1599/1574.Shortest Subarray to be Removed to Make Array Sorted/README_EN.md index af98e14bb660f..ced6c9689c735 100644 --- a/solution/1500-1599/1574.Shortest Subarray to be Removed to Make Array Sorted/README_EN.md +++ b/solution/1500-1599/1574.Shortest Subarray to be Removed to Make Array Sorted/README_EN.md @@ -72,6 +72,8 @@ Another correct solution is to remove the subarray [3,10,4]. +#### Python3 + ```python class Solution: def findLengthOfShortestSubarray(self, arr: List[int]) -> int: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findLengthOfShortestSubarray(int[] arr) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func findLengthOfShortestSubarray(arr []int) int { n := len(arr) @@ -184,6 +192,8 @@ func findLengthOfShortestSubarray(arr []int) int { +#### Python3 + ```python class Solution: def findLengthOfShortestSubarray(self, arr: List[int]) -> int: @@ -204,6 +214,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findLengthOfShortestSubarray(int[] arr) { @@ -230,6 +242,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -257,6 +271,8 @@ public: }; ``` +#### Go + ```go func findLengthOfShortestSubarray(arr []int) int { n := len(arr) diff --git a/solution/1500-1599/1575.Count All Possible Routes/README.md b/solution/1500-1599/1575.Count All Possible Routes/README.md index af529be5c60b3..edda683ba6014 100644 --- a/solution/1500-1599/1575.Count All Possible Routes/README.md +++ b/solution/1500-1599/1575.Count All Possible Routes/README.md @@ -99,6 +99,8 @@ tags: +#### Python3 + ```python class Solution: def countRoutes( @@ -118,6 +120,8 @@ class Solution: return dfs(start, fuel) ``` +#### Java + ```java class Solution { private int[] locations; @@ -152,6 +156,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -180,6 +186,8 @@ public: }; ``` +#### Go + ```go func countRoutes(locations []int, start int, finish int, fuel int) int { n := len(locations) @@ -221,6 +229,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function countRoutes(locations: number[], start: number, finish: number, fuel: number): number { const n = locations.length; @@ -266,6 +276,8 @@ function countRoutes(locations: number[], start: number, finish: number, fuel: n +#### Python3 + ```python class Solution: def countRoutes( @@ -286,6 +298,8 @@ class Solution: return f[start][fuel] ``` +#### Java + ```java class Solution { public int countRoutes(int[] locations, int start, int finish, int fuel) { @@ -309,6 +323,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -334,6 +350,8 @@ public: }; ``` +#### Go + ```go func countRoutes(locations []int, start int, finish int, fuel int) int { n := len(locations) @@ -365,6 +383,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function countRoutes(locations: number[], start: number, finish: number, fuel: number): number { const n = locations.length; diff --git a/solution/1500-1599/1575.Count All Possible Routes/README_EN.md b/solution/1500-1599/1575.Count All Possible Routes/README_EN.md index 95a8ef48a923a..6fb5d4b1b6c18 100644 --- a/solution/1500-1599/1575.Count All Possible Routes/README_EN.md +++ b/solution/1500-1599/1575.Count All Possible Routes/README_EN.md @@ -96,6 +96,8 @@ The time complexity is $O(n^2 \times m)$, and the space complexity is $O(n \time +#### Python3 + ```python class Solution: def countRoutes( @@ -115,6 +117,8 @@ class Solution: return dfs(start, fuel) ``` +#### Java + ```java class Solution { private int[] locations; @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go func countRoutes(locations []int, start int, finish int, fuel int) int { n := len(locations) @@ -218,6 +226,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function countRoutes(locations: number[], start: number, finish: number, fuel: number): number { const n = locations.length; @@ -263,6 +273,8 @@ The time complexity is $O(n^2 \times m)$, and the space complexity is $O(n \time +#### Python3 + ```python class Solution: def countRoutes( @@ -283,6 +295,8 @@ class Solution: return f[start][fuel] ``` +#### Java + ```java class Solution { public int countRoutes(int[] locations, int start, int finish, int fuel) { @@ -306,6 +320,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -331,6 +347,8 @@ public: }; ``` +#### Go + ```go func countRoutes(locations []int, start int, finish int, fuel int) int { n := len(locations) @@ -362,6 +380,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function countRoutes(locations: number[], start: number, finish: number, fuel: number): number { const n = locations.length; diff --git a/solution/1500-1599/1576.Replace All 's to Avoid Consecutive Repeating Characters/README.md b/solution/1500-1599/1576.Replace All 's to Avoid Consecutive Repeating Characters/README.md index b5304808f1750..8ae33cd6bc1f7 100644 --- a/solution/1500-1599/1576.Replace All 's to Avoid Consecutive Repeating Characters/README.md +++ b/solution/1500-1599/1576.Replace All 's to Avoid Consecutive Repeating Characters/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def modifyString(self, s: str) -> str: @@ -87,6 +89,8 @@ class Solution: return "".join(s) ``` +#### Java + ```java class Solution { public String modifyString(String s) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func modifyString(s string) string { n := len(s) @@ -148,6 +156,8 @@ func modifyString(s string) string { } ``` +#### TypeScript + ```ts function modifyString(s: string): string { const cs = s.split(''); diff --git a/solution/1500-1599/1576.Replace All 's to Avoid Consecutive Repeating Characters/README_EN.md b/solution/1500-1599/1576.Replace All 's to Avoid Consecutive Repeating Characters/README_EN.md index e7d0a63f0476f..cdb3f7cc0c702 100644 --- a/solution/1500-1599/1576.Replace All 's to Avoid Consecutive Repeating Characters/README_EN.md +++ b/solution/1500-1599/1576.Replace All 's to Avoid Consecutive Repeating Characters/README_EN.md @@ -59,6 +59,8 @@ tags: +#### Python3 + ```python class Solution: def modifyString(self, s: str) -> str: @@ -74,6 +76,8 @@ class Solution: return "".join(s) ``` +#### Java + ```java class Solution { public String modifyString(String s) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func modifyString(s string) string { n := len(s) @@ -135,6 +143,8 @@ func modifyString(s string) string { } ``` +#### TypeScript + ```ts function modifyString(s: string): string { const cs = s.split(''); diff --git a/solution/1500-1599/1577.Number of Ways Where Square of Number Is Equal to Product of Two Numbers/README.md b/solution/1500-1599/1577.Number of Ways Where Square of Number Is Equal to Product of Two Numbers/README.md index 79b6df50d95c6..07e00f673d930 100644 --- a/solution/1500-1599/1577.Number of Ways Where Square of Number Is Equal to Product of Two Numbers/README.md +++ b/solution/1500-1599/1577.Number of Ways Where Square of Number Is Equal to Product of Two Numbers/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def numTriplets(self, nums1: List[int], nums2: List[int]) -> int: @@ -114,6 +116,8 @@ class Solution: return ans >> 1 ``` +#### Java + ```java class Solution { public int numTriplets(int[] nums1, int[] nums2) { @@ -153,6 +157,8 @@ class Solution { } ``` +#### Go + ```go func numTriplets(nums1 []int, nums2 []int) (ans int) { cnt1 := map[int]int{} diff --git a/solution/1500-1599/1577.Number of Ways Where Square of Number Is Equal to Product of Two Numbers/README_EN.md b/solution/1500-1599/1577.Number of Ways Where Square of Number Is Equal to Product of Two Numbers/README_EN.md index 1b57a9d1d9e32..16a79481b56fa 100644 --- a/solution/1500-1599/1577.Number of Ways Where Square of Number Is Equal to Product of Two Numbers/README_EN.md +++ b/solution/1500-1599/1577.Number of Ways Where Square of Number Is Equal to Product of Two Numbers/README_EN.md @@ -75,6 +75,8 @@ Type 2: (3,0,1). nums2[3]2 = nums1[0] * nums1[1]. +#### Python3 + ```python class Solution: def numTriplets(self, nums1: List[int], nums2: List[int]) -> int: @@ -98,6 +100,8 @@ class Solution: return ans >> 1 ``` +#### Java + ```java class Solution { public int numTriplets(int[] nums1, int[] nums2) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### Go + ```go func numTriplets(nums1 []int, nums2 []int) (ans int) { cnt1 := map[int]int{} diff --git a/solution/1500-1599/1578.Minimum Time to Make Rope Colorful/README.md b/solution/1500-1599/1578.Minimum Time to Make Rope Colorful/README.md index 240690e9ae7d7..a5d4598ad5e19 100644 --- a/solution/1500-1599/1578.Minimum Time to Make Rope Colorful/README.md +++ b/solution/1500-1599/1578.Minimum Time to Make Rope Colorful/README.md @@ -80,6 +80,8 @@ Bob 可以移除下标 2 的蓝色气球。这将花费 3 秒。 +#### Python3 + ```python class Solution: def minCost(self, colors: str, neededTime: List[int]) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minCost(String colors, int[] neededTime) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func minCost(colors string, neededTime []int) (ans int) { n := len(colors) diff --git a/solution/1500-1599/1578.Minimum Time to Make Rope Colorful/README_EN.md b/solution/1500-1599/1578.Minimum Time to Make Rope Colorful/README_EN.md index 9cb99554f3773..68221a9e9ea6d 100644 --- a/solution/1500-1599/1578.Minimum Time to Make Rope Colorful/README_EN.md +++ b/solution/1500-1599/1578.Minimum Time to Make Rope Colorful/README_EN.md @@ -74,6 +74,8 @@ There are no longer two consecutive balloons of the same color. Total time = 1 + +#### Python3 + ```python class Solution: def minCost(self, colors: str, neededTime: List[int]) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minCost(String colors, int[] neededTime) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func minCost(colors string, neededTime []int) (ans int) { n := len(colors) diff --git a/solution/1500-1599/1579.Remove Max Number of Edges to Keep Graph Fully Traversable/README.md b/solution/1500-1599/1579.Remove Max Number of Edges to Keep Graph Fully Traversable/README.md index f31eca1659c92..a0feffe8c2b33 100644 --- a/solution/1500-1599/1579.Remove Max Number of Edges to Keep Graph Fully Traversable/README.md +++ b/solution/1500-1599/1579.Remove Max Number of Edges to Keep Graph Fully Traversable/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class UnionFind: def __init__(self, n): @@ -139,6 +141,8 @@ class Solution: return ans if ufa.cnt == 1 and ufb.cnt == 1 else -1 ``` +#### Java + ```java class UnionFind { private int[] p; @@ -208,6 +212,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -273,6 +279,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p, size []int diff --git a/solution/1500-1599/1579.Remove Max Number of Edges to Keep Graph Fully Traversable/README_EN.md b/solution/1500-1599/1579.Remove Max Number of Edges to Keep Graph Fully Traversable/README_EN.md index 271fa712f02e0..7491a0238ef98 100644 --- a/solution/1500-1599/1579.Remove Max Number of Edges to Keep Graph Fully Traversable/README_EN.md +++ b/solution/1500-1599/1579.Remove Max Number of Edges to Keep Graph Fully Traversable/README_EN.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class UnionFind: def __init__(self, n): @@ -130,6 +132,8 @@ class Solution: return ans if ufa.cnt == 1 and ufb.cnt == 1 else -1 ``` +#### Java + ```java class UnionFind { private int[] p; @@ -199,6 +203,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -264,6 +270,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p, size []int diff --git a/solution/1500-1599/1580.Put Boxes Into the Warehouse II/README.md b/solution/1500-1599/1580.Put Boxes Into the Warehouse II/README.md index 6e5ad732103ac..07c8a68d10649 100644 --- a/solution/1500-1599/1580.Put Boxes Into the Warehouse II/README.md +++ b/solution/1500-1599/1580.Put Boxes Into the Warehouse II/README.md @@ -99,6 +99,8 @@ tags: +#### Python3 + ```python class Solution: def maxBoxesInWarehouse(self, boxes: List[int], warehouse: List[int]) -> int: @@ -124,6 +126,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxBoxesInWarehouse(int[] boxes, int[] warehouse) { @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -196,6 +202,8 @@ public: }; ``` +#### Go + ```go func maxBoxesInWarehouse(boxes []int, warehouse []int) (ans int) { n := len(warehouse) diff --git a/solution/1500-1599/1580.Put Boxes Into the Warehouse II/README_EN.md b/solution/1500-1599/1580.Put Boxes Into the Warehouse II/README_EN.md index 892c88b6d5386..e06af8ced95ab 100644 --- a/solution/1500-1599/1580.Put Boxes Into the Warehouse II/README_EN.md +++ b/solution/1500-1599/1580.Put Boxes Into the Warehouse II/README_EN.md @@ -77,6 +77,8 @@ Other valid solutions are to put the green box in room 2 or to put the orange bo +#### Python3 + ```python class Solution: def maxBoxesInWarehouse(self, boxes: List[int], warehouse: List[int]) -> int: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxBoxesInWarehouse(int[] boxes, int[] warehouse) { @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func maxBoxesInWarehouse(boxes []int, warehouse []int) (ans int) { n := len(warehouse) diff --git a/solution/1500-1599/1581.Customer Who Visited but Did Not Make Any Transactions/README.md b/solution/1500-1599/1581.Customer Who Visited but Did Not Make Any Transactions/README.md index 8f8c3b77267ac..ae5cc9dbedf89 100644 --- a/solution/1500-1599/1581.Customer Who Visited but Did Not Make Any Transactions/README.md +++ b/solution/1500-1599/1581.Customer Who Visited but Did Not Make Any Transactions/README.md @@ -109,6 +109,8 @@ ID = 96 的顾客曾经去过购物中心,并且没有进行任何交易。 +#### MySQL + ```sql # Write your MySQL query statement below SELECT customer_id, COUNT(1) AS count_no_trans @@ -129,6 +131,8 @@ GROUP BY 1; +#### MySQL + ```sql # Write your MySQL query statement below SELECT customer_id, COUNT(1) AS count_no_trans diff --git a/solution/1500-1599/1581.Customer Who Visited but Did Not Make Any Transactions/README_EN.md b/solution/1500-1599/1581.Customer Who Visited but Did Not Make Any Transactions/README_EN.md index bae553f72237a..ee47e6e73b5ce 100644 --- a/solution/1500-1599/1581.Customer Who Visited but Did Not Make Any Transactions/README_EN.md +++ b/solution/1500-1599/1581.Customer Who Visited but Did Not Make Any Transactions/README_EN.md @@ -109,6 +109,8 @@ We can use a subquery to first find all `visit_id`s that have not made any trans +#### MySQL + ```sql # Write your MySQL query statement below SELECT customer_id, COUNT(1) AS count_no_trans @@ -129,6 +131,8 @@ We can also use a left join to join the `Visits` table and the `Transactions` ta +#### MySQL + ```sql # Write your MySQL query statement below SELECT customer_id, COUNT(1) AS count_no_trans diff --git a/solution/1500-1599/1582.Special Positions in a Binary Matrix/README.md b/solution/1500-1599/1582.Special Positions in a Binary Matrix/README.md index 53e61bca8e6c0..72dcb6cb5c41b 100644 --- a/solution/1500-1599/1582.Special Positions in a Binary Matrix/README.md +++ b/solution/1500-1599/1582.Special Positions in a Binary Matrix/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def numSpecial(self, mat: List[List[int]]) -> int: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numSpecial(int[][] mat) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func numSpecial(mat [][]int) int { m, n := len(mat), len(mat[0]) @@ -158,6 +166,8 @@ func numSpecial(mat [][]int) int { } ``` +#### TypeScript + ```ts function numSpecial(mat: number[][]): number { const m = mat.length; @@ -186,6 +196,8 @@ function numSpecial(mat: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn num_special(mat: Vec>) -> i32 { @@ -213,6 +225,8 @@ impl Solution { } ``` +#### C + ```c int numSpecial(int** mat, int matSize, int* matColSize) { int m = matSize; diff --git a/solution/1500-1599/1582.Special Positions in a Binary Matrix/README_EN.md b/solution/1500-1599/1582.Special Positions in a Binary Matrix/README_EN.md index 7aed617349d0a..4fbf0f94ed189 100644 --- a/solution/1500-1599/1582.Special Positions in a Binary Matrix/README_EN.md +++ b/solution/1500-1599/1582.Special Positions in a Binary Matrix/README_EN.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def numSpecial(self, mat: List[List[int]]) -> int: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numSpecial(int[][] mat) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func numSpecial(mat [][]int) int { m, n := len(mat), len(mat[0]) @@ -150,6 +158,8 @@ func numSpecial(mat [][]int) int { } ``` +#### TypeScript + ```ts function numSpecial(mat: number[][]): number { const m = mat.length; @@ -178,6 +188,8 @@ function numSpecial(mat: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn num_special(mat: Vec>) -> i32 { @@ -205,6 +217,8 @@ impl Solution { } ``` +#### C + ```c int numSpecial(int** mat, int matSize, int* matColSize) { int m = matSize; diff --git a/solution/1500-1599/1583.Count Unhappy Friends/README.md b/solution/1500-1599/1583.Count Unhappy Friends/README.md index d32427111db2b..471b49210b8f6 100644 --- a/solution/1500-1599/1583.Count Unhappy Friends/README.md +++ b/solution/1500-1599/1583.Count Unhappy Friends/README.md @@ -103,6 +103,8 @@ tags: +#### Python3 + ```python class Solution: def unhappyFriends( @@ -120,6 +122,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int unhappyFriends(int n, int[][] preferences, int[][] pairs) { @@ -153,6 +157,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -187,6 +193,8 @@ public: }; ``` +#### Go + ```go func unhappyFriends(n int, preferences [][]int, pairs [][]int) (ans int) { d := make([][]int, n) diff --git a/solution/1500-1599/1583.Count Unhappy Friends/README_EN.md b/solution/1500-1599/1583.Count Unhappy Friends/README_EN.md index 00e3b08ade96e..d109b03c35181 100644 --- a/solution/1500-1599/1583.Count Unhappy Friends/README_EN.md +++ b/solution/1500-1599/1583.Count Unhappy Friends/README_EN.md @@ -93,6 +93,8 @@ Friends 0 and 2 are happy. +#### Python3 + ```python class Solution: def unhappyFriends( @@ -110,6 +112,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int unhappyFriends(int n, int[][] preferences, int[][] pairs) { @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go func unhappyFriends(n int, preferences [][]int, pairs [][]int) (ans int) { d := make([][]int, n) diff --git a/solution/1500-1599/1584.Min Cost to Connect All Points/README.md b/solution/1500-1599/1584.Min Cost to Connect All Points/README.md index 704d6640ae1ee..e74af47ac2e75 100644 --- a/solution/1500-1599/1584.Min Cost to Connect All Points/README.md +++ b/solution/1500-1599/1584.Min Cost to Connect All Points/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class Solution: def minCostConnectPoints(self, points: List[List[int]]) -> int: @@ -123,6 +125,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minCostConnectPoints(int[][] points) { @@ -163,6 +167,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -204,6 +210,8 @@ public: }; ``` +#### Go + ```go func minCostConnectPoints(points [][]int) (ans int) { n := len(points) @@ -250,6 +258,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function minCostConnectPoints(points: number[][]): number { const n = points.length; @@ -302,6 +312,8 @@ function minCostConnectPoints(points: number[][]): number { +#### Python3 + ```python class Solution: def minCostConnectPoints(self, points: List[List[int]]) -> int: @@ -331,6 +343,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] p; @@ -374,6 +388,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -410,6 +426,8 @@ public: }; ``` +#### Go + ```go func minCostConnectPoints(points [][]int) int { n := len(points) diff --git a/solution/1500-1599/1584.Min Cost to Connect All Points/README_EN.md b/solution/1500-1599/1584.Min Cost to Connect All Points/README_EN.md index 7aea3315f3f3d..6064f1e5d88a2 100644 --- a/solution/1500-1599/1584.Min Cost to Connect All Points/README_EN.md +++ b/solution/1500-1599/1584.Min Cost to Connect All Points/README_EN.md @@ -65,6 +65,8 @@ Notice that there is a unique path between every pair of points. +#### Python3 + ```python class Solution: def minCostConnectPoints(self, points: List[List[int]]) -> int: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minCostConnectPoints(int[][] points) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go func minCostConnectPoints(points [][]int) (ans int) { n := len(points) @@ -219,6 +227,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function minCostConnectPoints(points: number[][]): number { const n = points.length; @@ -267,6 +277,8 @@ function minCostConnectPoints(points: number[][]): number { +#### Python3 + ```python class Solution: def minCostConnectPoints(self, points: List[List[int]]) -> int: @@ -296,6 +308,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] p; @@ -339,6 +353,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -375,6 +391,8 @@ public: }; ``` +#### Go + ```go func minCostConnectPoints(points [][]int) int { n := len(points) diff --git a/solution/1500-1599/1585.Check If String Is Transformable With Substring Sort Operations/README.md b/solution/1500-1599/1585.Check If String Is Transformable With Substring Sort Operations/README.md index 3975c32f59d88..231ab36607e28 100644 --- a/solution/1500-1599/1585.Check If String Is Transformable With Substring Sort Operations/README.md +++ b/solution/1500-1599/1585.Check If String Is Transformable With Substring Sort Operations/README.md @@ -98,6 +98,8 @@ tags: +#### Python3 + ```python class Solution: def isTransformable(self, s: str, t: str) -> bool: @@ -112,6 +114,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isTransformable(String s, String t) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func isTransformable(s string, t string) bool { pos := [10][]int{} diff --git a/solution/1500-1599/1585.Check If String Is Transformable With Substring Sort Operations/README_EN.md b/solution/1500-1599/1585.Check If String Is Transformable With Substring Sort Operations/README_EN.md index a52200cda39bd..f588d676f6acb 100644 --- a/solution/1500-1599/1585.Check If String Is Transformable With Substring Sort Operations/README_EN.md +++ b/solution/1500-1599/1585.Check If String Is Transformable With Substring Sort Operations/README_EN.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def isTransformable(self, s: str, t: str) -> bool: @@ -97,6 +99,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isTransformable(String s, String t) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func isTransformable(s string, t string) bool { pos := [10][]int{} diff --git a/solution/1500-1599/1586.Binary Search Tree Iterator II/README.md b/solution/1500-1599/1586.Binary Search Tree Iterator II/README.md index d21839d4c585f..d8f6285268145 100644 --- a/solution/1500-1599/1586.Binary Search Tree Iterator II/README.md +++ b/solution/1500-1599/1586.Binary Search Tree Iterator II/README.md @@ -90,6 +90,8 @@ bSTIterator.prev(); // 状态变为 [3, 7, <u>9</u>, 15, 20], 返回 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -134,6 +136,8 @@ class BSTIterator: # param_4 = obj.prev() ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -194,6 +198,8 @@ class BSTIterator { */ ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -254,6 +260,8 @@ private: */ ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -311,6 +319,8 @@ func (this *BSTIterator) Prev() int { */ ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/1500-1599/1586.Binary Search Tree Iterator II/README_EN.md b/solution/1500-1599/1586.Binary Search Tree Iterator II/README_EN.md index 1f38ffa40b212..ca93d236e1bfe 100644 --- a/solution/1500-1599/1586.Binary Search Tree Iterator II/README_EN.md +++ b/solution/1500-1599/1586.Binary Search Tree Iterator II/README_EN.md @@ -90,6 +90,8 @@ In terms of time complexity, initializing the iterator requires $O(n)$ time, whe +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -134,6 +136,8 @@ class BSTIterator: # param_4 = obj.prev() ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -194,6 +198,8 @@ class BSTIterator { */ ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -254,6 +260,8 @@ private: */ ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -311,6 +319,8 @@ func (this *BSTIterator) Prev() int { */ ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/1500-1599/1587.Bank Account Summary II/README.md b/solution/1500-1599/1587.Bank Account Summary II/README.md index 4c33726ab843f..39284e9146e30 100644 --- a/solution/1500-1599/1587.Bank Account Summary II/README.md +++ b/solution/1500-1599/1587.Bank Account Summary II/README.md @@ -108,6 +108,8 @@ Charlie 的余额为(6000 + 6000 - 4000) = 8000. +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1500-1599/1587.Bank Account Summary II/README_EN.md b/solution/1500-1599/1587.Bank Account Summary II/README_EN.md index 69cac899ea235..c66f78e56190d 100644 --- a/solution/1500-1599/1587.Bank Account Summary II/README_EN.md +++ b/solution/1500-1599/1587.Bank Account Summary II/README_EN.md @@ -106,6 +106,8 @@ We can use an equi-join to join the `Users` table and the `Transactions` table o +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1500-1599/1588.Sum of All Odd Length Subarrays/README.md b/solution/1500-1599/1588.Sum of All Odd Length Subarrays/README.md index 833c018fe20a4..d39320ee1a84a 100644 --- a/solution/1500-1599/1588.Sum of All Odd Length Subarrays/README.md +++ b/solution/1500-1599/1588.Sum of All Odd Length Subarrays/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def sumOddLengthSubarrays(self, arr: List[int]) -> int: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int sumOddLengthSubarrays(int[] arr) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func sumOddLengthSubarrays(arr []int) (ans int) { n := len(arr) @@ -156,6 +164,8 @@ func sumOddLengthSubarrays(arr []int) (ans int) { } ``` +#### TypeScript + ```ts function sumOddLengthSubarrays(arr: number[]): number { const n = arr.length; @@ -173,6 +183,8 @@ function sumOddLengthSubarrays(arr: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn sum_odd_length_subarrays(arr: Vec) -> i32 { @@ -192,6 +204,8 @@ impl Solution { } ``` +#### C + ```c int sumOddLengthSubarrays(int* arr, int arrSize) { int ans = 0; diff --git a/solution/1500-1599/1588.Sum of All Odd Length Subarrays/README_EN.md b/solution/1500-1599/1588.Sum of All Odd Length Subarrays/README_EN.md index 6aa0cad069bc2..313c935e50c99 100644 --- a/solution/1500-1599/1588.Sum of All Odd Length Subarrays/README_EN.md +++ b/solution/1500-1599/1588.Sum of All Odd Length Subarrays/README_EN.md @@ -79,6 +79,8 @@ If we add all these together we get 1 + 4 + 2 + 5 + 3 + 7 + 11 + 10 + 15 = 58

+#### Python3 + ```python class Solution: def sumOddLengthSubarrays(self, arr: List[int]) -> int: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int sumOddLengthSubarrays(int[] arr) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func sumOddLengthSubarrays(arr []int) (ans int) { n := len(arr) @@ -147,6 +155,8 @@ func sumOddLengthSubarrays(arr []int) (ans int) { } ``` +#### TypeScript + ```ts function sumOddLengthSubarrays(arr: number[]): number { const n = arr.length; @@ -164,6 +174,8 @@ function sumOddLengthSubarrays(arr: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn sum_odd_length_subarrays(arr: Vec) -> i32 { @@ -183,6 +195,8 @@ impl Solution { } ``` +#### C + ```c int sumOddLengthSubarrays(int* arr, int arrSize) { int ans = 0; diff --git a/solution/1500-1599/1589.Maximum Sum Obtained of Any Permutation/README.md b/solution/1500-1599/1589.Maximum Sum Obtained of Any Permutation/README.md index 86031a0f318d5..17218e00ebb67 100644 --- a/solution/1500-1599/1589.Maximum Sum Obtained of Any Permutation/README.md +++ b/solution/1500-1599/1589.Maximum Sum Obtained of Any Permutation/README.md @@ -84,6 +84,8 @@ requests[1] -> nums[0] + nums[1] = 3 + 5 = 8 +#### Python3 + ```python class Solution: def maxSumRangeQuery(self, nums: List[int], requests: List[List[int]]) -> int: @@ -101,6 +103,8 @@ class Solution: return sum(a * b for a, b in zip(nums, d)) % mod ``` +#### Java + ```java class Solution { public int maxSumRangeQuery(int[] nums, int[][] requests) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func maxSumRangeQuery(nums []int, requests [][]int) (ans int) { n := len(nums) @@ -181,6 +189,8 @@ func maxSumRangeQuery(nums []int, requests [][]int) (ans int) { return ``` +#### TypeScript + ```ts function maxSumRangeQuery(nums: number[], requests: number[][]): number { const n = nums.length; diff --git a/solution/1500-1599/1589.Maximum Sum Obtained of Any Permutation/README_EN.md b/solution/1500-1599/1589.Maximum Sum Obtained of Any Permutation/README_EN.md index e8543eb27afec..8f78ca7adc55d 100644 --- a/solution/1500-1599/1589.Maximum Sum Obtained of Any Permutation/README_EN.md +++ b/solution/1500-1599/1589.Maximum Sum Obtained of Any Permutation/README_EN.md @@ -79,6 +79,8 @@ Total sum: 11 + 8 = 19, which is the best that you can do. +#### Python3 + ```python class Solution: def maxSumRangeQuery(self, nums: List[int], requests: List[List[int]]) -> int: @@ -96,6 +98,8 @@ class Solution: return sum(a * b for a, b in zip(nums, d)) % mod ``` +#### Java + ```java class Solution { public int maxSumRangeQuery(int[] nums, int[][] requests) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func maxSumRangeQuery(nums []int, requests [][]int) (ans int) { n := len(nums) @@ -176,6 +184,8 @@ func maxSumRangeQuery(nums []int, requests [][]int) (ans int) { return ``` +#### TypeScript + ```ts function maxSumRangeQuery(nums: number[], requests: number[][]): number { const n = nums.length; diff --git a/solution/1500-1599/1590.Make Sum Divisible by P/README.md b/solution/1500-1599/1590.Make Sum Divisible by P/README.md index 1bf3b60c55b55..e86b4fe761d74 100644 --- a/solution/1500-1599/1590.Make Sum Divisible by P/README.md +++ b/solution/1500-1599/1590.Make Sum Divisible by P/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class Solution: def minSubarray(self, nums: List[int], p: int) -> int: @@ -112,6 +114,8 @@ class Solution: return -1 if ans == len(nums) else ans ``` +#### Java + ```java class Solution { public int minSubarray(int[] nums, int p) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go func minSubarray(nums []int, p int) int { k := 0 @@ -197,6 +205,8 @@ func minSubarray(nums []int, p int) int { } ``` +#### TypeScript + ```ts function minSubarray(nums: number[], p: number): number { let k = 0; diff --git a/solution/1500-1599/1590.Make Sum Divisible by P/README_EN.md b/solution/1500-1599/1590.Make Sum Divisible by P/README_EN.md index 081061a455c27..643b38f1d2d9e 100644 --- a/solution/1500-1599/1590.Make Sum Divisible by P/README_EN.md +++ b/solution/1500-1599/1590.Make Sum Divisible by P/README_EN.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def minSubarray(self, nums: List[int], p: int) -> int: @@ -88,6 +90,8 @@ class Solution: return -1 if ans == len(nums) else ans ``` +#### Java + ```java class Solution { public int minSubarray(int[] nums, int p) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func minSubarray(nums []int, p int) int { k := 0 @@ -173,6 +181,8 @@ func minSubarray(nums []int, p int) int { } ``` +#### TypeScript + ```ts function minSubarray(nums: number[], p: number): number { let k = 0; diff --git a/solution/1500-1599/1591.Strange Printer II/README.md b/solution/1500-1599/1591.Strange Printer II/README.md index 8ca690f582d70..9cf65091f576c 100644 --- a/solution/1500-1599/1591.Strange Printer II/README.md +++ b/solution/1500-1599/1591.Strange Printer II/README.md @@ -83,18 +83,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1500-1599/1591.Strange Printer II/README_EN.md b/solution/1500-1599/1591.Strange Printer II/README_EN.md index 4462876bbe4cf..b801cb7b55842 100644 --- a/solution/1500-1599/1591.Strange Printer II/README_EN.md +++ b/solution/1500-1599/1591.Strange Printer II/README_EN.md @@ -75,18 +75,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1500-1599/1592.Rearrange Spaces Between Words/README.md b/solution/1500-1599/1592.Rearrange Spaces Between Words/README.md index 2142abb09b6d5..a1e4737e1557b 100644 --- a/solution/1500-1599/1592.Rearrange Spaces Between Words/README.md +++ b/solution/1500-1599/1592.Rearrange Spaces Between Words/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def reorderSpaces(self, text: str) -> str: @@ -93,6 +95,8 @@ class Solution: return (' ' * (cnt // m)).join(words) + ' ' * (cnt % m) ``` +#### Java + ```java class Solution { public String reorderSpaces(String text) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### Go + ```go func reorderSpaces(text string) string { cnt := strings.Count(text, " ") @@ -132,6 +138,8 @@ func reorderSpaces(text string) string { } ``` +#### TypeScript + ```ts function reorderSpaces(text: string): string { let count = 0; @@ -153,6 +161,8 @@ function reorderSpaces(text: string): string { } ``` +#### Rust + ```rust impl Solution { fn create_spaces(n: usize) -> String { diff --git a/solution/1500-1599/1592.Rearrange Spaces Between Words/README_EN.md b/solution/1500-1599/1592.Rearrange Spaces Between Words/README_EN.md index 9db9128b12dbd..5884315d27f16 100644 --- a/solution/1500-1599/1592.Rearrange Spaces Between Words/README_EN.md +++ b/solution/1500-1599/1592.Rearrange Spaces Between Words/README_EN.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def reorderSpaces(self, text: str) -> str: @@ -71,6 +73,8 @@ class Solution: return (' ' * (cnt // m)).join(words) + ' ' * (cnt % m) ``` +#### Java + ```java class Solution { public String reorderSpaces(String text) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### Go + ```go func reorderSpaces(text string) string { cnt := strings.Count(text, " ") @@ -110,6 +116,8 @@ func reorderSpaces(text string) string { } ``` +#### TypeScript + ```ts function reorderSpaces(text: string): string { let count = 0; @@ -131,6 +139,8 @@ function reorderSpaces(text: string): string { } ``` +#### Rust + ```rust impl Solution { fn create_spaces(n: usize) -> String { diff --git a/solution/1500-1599/1593.Split a String Into the Max Number of Unique Substrings/README.md b/solution/1500-1599/1593.Split a String Into the Max Number of Unique Substrings/README.md index 231ed7d0ca43c..f199d46dc3716 100644 --- a/solution/1500-1599/1593.Split a String Into the Max Number of Unique Substrings/README.md +++ b/solution/1500-1599/1593.Split a String Into the Max Number of Unique Substrings/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def maxUniqueSplit(self, s: str) -> int: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private Set vis = new HashSet<>(); @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func maxUniqueSplit(s string) int { ans := 1 diff --git a/solution/1500-1599/1593.Split a String Into the Max Number of Unique Substrings/README_EN.md b/solution/1500-1599/1593.Split a String Into the Max Number of Unique Substrings/README_EN.md index 84cf12c281357..a3b49ca4adb4b 100644 --- a/solution/1500-1599/1593.Split a String Into the Max Number of Unique Substrings/README_EN.md +++ b/solution/1500-1599/1593.Split a String Into the Max Number of Unique Substrings/README_EN.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def maxUniqueSplit(self, s: str) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private Set vis = new HashSet<>(); @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func maxUniqueSplit(s string) int { ans := 1 diff --git a/solution/1500-1599/1594.Maximum Non Negative Product in a Matrix/README.md b/solution/1500-1599/1594.Maximum Non Negative Product in a Matrix/README.md index f5388c79414f6..b99ae8944f329 100644 --- a/solution/1500-1599/1594.Maximum Non Negative Product in a Matrix/README.md +++ b/solution/1500-1599/1594.Maximum Non Negative Product in a Matrix/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def maxProductPath(self, grid: List[List[int]]) -> int: @@ -99,6 +101,8 @@ class Solution: return -1 if ans < 0 else ans % mod ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; const int mod = 1e9 + 7; @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func maxProductPath(grid [][]int) int { m, n := len(grid), len(grid[0]) diff --git a/solution/1500-1599/1594.Maximum Non Negative Product in a Matrix/README_EN.md b/solution/1500-1599/1594.Maximum Non Negative Product in a Matrix/README_EN.md index f6a61977e8c6f..ca4f08d88f035 100644 --- a/solution/1500-1599/1594.Maximum Non Negative Product in a Matrix/README_EN.md +++ b/solution/1500-1599/1594.Maximum Non Negative Product in a Matrix/README_EN.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def maxProductPath(self, grid: List[List[int]]) -> int: @@ -96,6 +98,8 @@ class Solution: return -1 if ans < 0 else ans % mod ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; const int mod = 1e9 + 7; @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func maxProductPath(grid [][]int) int { m, n := len(grid), len(grid[0]) diff --git a/solution/1500-1599/1595.Minimum Cost to Connect Two Groups of Points/README.md b/solution/1500-1599/1595.Minimum Cost to Connect Two Groups of Points/README.md index 8fa59b7db35e3..ebe3c65187d6e 100644 --- a/solution/1500-1599/1595.Minimum Cost to Connect Two Groups of Points/README.md +++ b/solution/1500-1599/1595.Minimum Cost to Connect Two Groups of Points/README.md @@ -107,6 +107,8 @@ $$ +#### Python3 + ```python class Solution: def connectTwoGroups(self, cost: List[List[int]]) -> int: @@ -124,6 +126,8 @@ class Solution: return f[m][-1] ``` +#### Java + ```java class Solution { public int connectTwoGroups(List> cost) { @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go func connectTwoGroups(cost [][]int) int { m, n := len(cost), len(cost[0]) @@ -203,6 +211,8 @@ func connectTwoGroups(cost [][]int) int { } ``` +#### TypeScript + ```ts function connectTwoGroups(cost: number[][]): number { const m = cost.length; @@ -238,6 +248,8 @@ function connectTwoGroups(cost: number[][]): number { +#### Python3 + ```python class Solution: def connectTwoGroups(self, cost: List[List[int]]) -> int: @@ -258,6 +270,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int connectTwoGroups(List> cost) { @@ -286,6 +300,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -313,6 +329,8 @@ public: }; ``` +#### Go + ```go func connectTwoGroups(cost [][]int) int { m, n := len(cost), len(cost[0]) @@ -341,6 +359,8 @@ func connectTwoGroups(cost [][]int) int { } ``` +#### TypeScript + ```ts function connectTwoGroups(cost: number[][]): number { const m = cost.length; diff --git a/solution/1500-1599/1595.Minimum Cost to Connect Two Groups of Points/README_EN.md b/solution/1500-1599/1595.Minimum Cost to Connect Two Groups of Points/README_EN.md index c6683f1185137..7f450b3ba207f 100644 --- a/solution/1500-1599/1595.Minimum Cost to Connect Two Groups of Points/README_EN.md +++ b/solution/1500-1599/1595.Minimum Cost to Connect Two Groups of Points/README_EN.md @@ -82,6 +82,8 @@ Note that there are multiple points connected to point 2 in the first group and +#### Python3 + ```python class Solution: def connectTwoGroups(self, cost: List[List[int]]) -> int: @@ -99,6 +101,8 @@ class Solution: return f[m][-1] ``` +#### Java + ```java class Solution { public int connectTwoGroups(List> cost) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func connectTwoGroups(cost [][]int) int { m, n := len(cost), len(cost[0]) @@ -178,6 +186,8 @@ func connectTwoGroups(cost [][]int) int { } ``` +#### TypeScript + ```ts function connectTwoGroups(cost: number[][]): number { const m = cost.length; @@ -213,6 +223,8 @@ function connectTwoGroups(cost: number[][]): number { +#### Python3 + ```python class Solution: def connectTwoGroups(self, cost: List[List[int]]) -> int: @@ -233,6 +245,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int connectTwoGroups(List> cost) { @@ -261,6 +275,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -288,6 +304,8 @@ public: }; ``` +#### Go + ```go func connectTwoGroups(cost [][]int) int { m, n := len(cost), len(cost[0]) @@ -316,6 +334,8 @@ func connectTwoGroups(cost [][]int) int { } ``` +#### TypeScript + ```ts function connectTwoGroups(cost: number[][]): number { const m = cost.length; diff --git a/solution/1500-1599/1596.The Most Frequently Ordered Products for Each Customer/README.md b/solution/1500-1599/1596.The Most Frequently Ordered Products for Each Customer/README.md index 9145bff018cf0..1dfc9f9cbc08f 100644 --- a/solution/1500-1599/1596.The Most Frequently Ordered Products for Each Customer/README.md +++ b/solution/1500-1599/1596.The Most Frequently Ordered Products for Each Customer/README.md @@ -142,6 +142,8 @@ John (customer 5) 没有订购过商品, 所以我们并没有把 John 包含在 +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1500-1599/1596.The Most Frequently Ordered Products for Each Customer/README_EN.md b/solution/1500-1599/1596.The Most Frequently Ordered Products for Each Customer/README_EN.md index 99284505d0e27..cc52b802859fd 100644 --- a/solution/1500-1599/1596.The Most Frequently Ordered Products for Each Customer/README_EN.md +++ b/solution/1500-1599/1596.The Most Frequently Ordered Products for Each Customer/README_EN.md @@ -142,6 +142,8 @@ We group the `Orders` table by `customer_id` and `product_id`, and then use the +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1500-1599/1597.Build Binary Expression Tree From Infix Expression/README.md b/solution/1500-1599/1597.Build Binary Expression Tree From Infix Expression/README.md index 0bcabc302ed4a..8c754f389706e 100644 --- a/solution/1500-1599/1597.Build Binary Expression Tree From Infix Expression/README.md +++ b/solution/1500-1599/1597.Build Binary Expression Tree From Infix Expression/README.md @@ -81,18 +81,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1500-1599/1597.Build Binary Expression Tree From Infix Expression/README_EN.md b/solution/1500-1599/1597.Build Binary Expression Tree From Infix Expression/README_EN.md index 07e0c0a0d4653..c07b03e29010e 100644 --- a/solution/1500-1599/1597.Build Binary Expression Tree From Infix Expression/README_EN.md +++ b/solution/1500-1599/1597.Build Binary Expression Tree From Infix Expression/README_EN.md @@ -80,18 +80,26 @@ The third tree below is also not valid. Although it produces the same result and +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1500-1599/1598.Crawler Log Folder/README.md b/solution/1500-1599/1598.Crawler Log Folder/README.md index 4edb12ce1dd44..a15b7d479895a 100644 --- a/solution/1500-1599/1598.Crawler Log Folder/README.md +++ b/solution/1500-1599/1598.Crawler Log Folder/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def minOperations(self, logs: List[str]) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minOperations(String[] logs) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func minOperations(logs []string) int { ans := 0 @@ -148,6 +156,8 @@ func minOperations(logs []string) int { } ``` +#### TypeScript + ```ts function minOperations(logs: string[]): number { let depth = 0; @@ -162,6 +172,8 @@ function minOperations(logs: string[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_operations(logs: Vec) -> i32 { @@ -178,6 +190,8 @@ impl Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) diff --git a/solution/1500-1599/1598.Crawler Log Folder/README_EN.md b/solution/1500-1599/1598.Crawler Log Folder/README_EN.md index 3b8a34aa2dfe1..f28ffe2898b97 100644 --- a/solution/1500-1599/1598.Crawler Log Folder/README_EN.md +++ b/solution/1500-1599/1598.Crawler Log Folder/README_EN.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def minOperations(self, logs: List[str]) -> int: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minOperations(String[] logs) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func minOperations(logs []string) int { ans := 0 @@ -145,6 +153,8 @@ func minOperations(logs []string) int { } ``` +#### TypeScript + ```ts function minOperations(logs: string[]): number { let depth = 0; @@ -159,6 +169,8 @@ function minOperations(logs: string[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_operations(logs: Vec) -> i32 { @@ -175,6 +187,8 @@ impl Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) diff --git a/solution/1500-1599/1599.Maximum Profit of Operating a Centennial Wheel/README.md b/solution/1500-1599/1599.Maximum Profit of Operating a Centennial Wheel/README.md index 528f2b0b6d609..de396f21a7638 100644 --- a/solution/1500-1599/1599.Maximum Profit of Operating a Centennial Wheel/README.md +++ b/solution/1500-1599/1599.Maximum Profit of Operating a Centennial Wheel/README.md @@ -97,6 +97,8 @@ tags: +#### Python3 + ```python class Solution: def minOperationsMaxProfit( @@ -118,6 +120,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minOperationsMaxProfit(int[] customers, int boardingCost, int runningCost) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func minOperationsMaxProfit(customers []int, boardingCost int, runningCost int) int { ans := -1 @@ -185,6 +193,8 @@ func minOperationsMaxProfit(customers []int, boardingCost int, runningCost int) } ``` +#### TypeScript + ```ts function minOperationsMaxProfit( customers: number[], @@ -210,6 +220,8 @@ function minOperationsMaxProfit( } ``` +#### Rust + ```rust impl Solution { pub fn min_operations_max_profit( diff --git a/solution/1500-1599/1599.Maximum Profit of Operating a Centennial Wheel/README_EN.md b/solution/1500-1599/1599.Maximum Profit of Operating a Centennial Wheel/README_EN.md index c80ed372cefdd..1b2f7424d2a91 100644 --- a/solution/1500-1599/1599.Maximum Profit of Operating a Centennial Wheel/README_EN.md +++ b/solution/1500-1599/1599.Maximum Profit of Operating a Centennial Wheel/README_EN.md @@ -94,6 +94,8 @@ The time complexity is $O(n)$, where $n$ is the length of the `customers` array. +#### Python3 + ```python class Solution: def minOperationsMaxProfit( @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minOperationsMaxProfit(int[] customers, int boardingCost, int runningCost) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func minOperationsMaxProfit(customers []int, boardingCost int, runningCost int) int { ans := -1 @@ -182,6 +190,8 @@ func minOperationsMaxProfit(customers []int, boardingCost int, runningCost int) } ``` +#### TypeScript + ```ts function minOperationsMaxProfit( customers: number[], @@ -207,6 +217,8 @@ function minOperationsMaxProfit( } ``` +#### Rust + ```rust impl Solution { pub fn min_operations_max_profit( diff --git a/solution/1600-1699/1600.Throne Inheritance/README.md b/solution/1600-1699/1600.Throne Inheritance/README.md index fbd61dc297499..7201f6c20820d 100644 --- a/solution/1600-1699/1600.Throne Inheritance/README.md +++ b/solution/1600-1699/1600.Throne Inheritance/README.md @@ -110,6 +110,8 @@ t.getInheritanceOrder(); // 返回 ["king", "andy", "matthew", "alex", "asha", " +#### Python3 + ```python class ThroneInheritance: @@ -142,6 +144,8 @@ class ThroneInheritance: # param_3 = obj.getInheritanceOrder() ``` +#### Java + ```java class ThroneInheritance { private String king; @@ -186,6 +190,8 @@ class ThroneInheritance { */ ``` +#### C++ + ```cpp class ThroneInheritance { public: @@ -232,6 +238,8 @@ private: */ ``` +#### Go + ```go type ThroneInheritance struct { king string @@ -279,6 +287,8 @@ func (this *ThroneInheritance) GetInheritanceOrder() (ans []string) { */ ``` +#### TypeScript + ```ts class ThroneInheritance { private king: string; @@ -322,6 +332,8 @@ class ThroneInheritance { */ ``` +#### C# + ```cs public class ThroneInheritance { private string king; diff --git a/solution/1600-1699/1600.Throne Inheritance/README_EN.md b/solution/1600-1699/1600.Throne Inheritance/README_EN.md index 05b7ea5d299e9..ecd6dd6e6b36e 100644 --- a/solution/1600-1699/1600.Throne Inheritance/README_EN.md +++ b/solution/1600-1699/1600.Throne Inheritance/README_EN.md @@ -108,6 +108,8 @@ In terms of time complexity, both `birth` and `death` have a time complexity of +#### Python3 + ```python class ThroneInheritance: @@ -140,6 +142,8 @@ class ThroneInheritance: # param_3 = obj.getInheritanceOrder() ``` +#### Java + ```java class ThroneInheritance { private String king; @@ -184,6 +188,8 @@ class ThroneInheritance { */ ``` +#### C++ + ```cpp class ThroneInheritance { public: @@ -230,6 +236,8 @@ private: */ ``` +#### Go + ```go type ThroneInheritance struct { king string @@ -277,6 +285,8 @@ func (this *ThroneInheritance) GetInheritanceOrder() (ans []string) { */ ``` +#### TypeScript + ```ts class ThroneInheritance { private king: string; @@ -320,6 +330,8 @@ class ThroneInheritance { */ ``` +#### C# + ```cs public class ThroneInheritance { private string king; diff --git a/solution/1600-1699/1601.Maximum Number of Achievable Transfer Requests/README.md b/solution/1600-1699/1601.Maximum Number of Achievable Transfer Requests/README.md index 297e71721ffde..3ee58251f8403 100644 --- a/solution/1600-1699/1601.Maximum Number of Achievable Transfer Requests/README.md +++ b/solution/1600-1699/1601.Maximum Number of Achievable Transfer Requests/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def maximumRequests(self, n: int, requests: List[List[int]]) -> int: @@ -111,6 +113,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int m; @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -184,6 +190,8 @@ public: }; ``` +#### Go + ```go func maximumRequests(n int, requests [][]int) (ans int) { m := len(requests) @@ -213,6 +221,8 @@ func maximumRequests(n int, requests [][]int) (ans int) { } ``` +#### TypeScript + ```ts function maximumRequests(n: number, requests: number[][]): number { const m = requests.length; @@ -247,6 +257,8 @@ function bitCount(i: number): number { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -286,6 +298,8 @@ function bitCount(i) { } ``` +#### C# + ```cs public class Solution { private int m; diff --git a/solution/1600-1699/1601.Maximum Number of Achievable Transfer Requests/README_EN.md b/solution/1600-1699/1601.Maximum Number of Achievable Transfer Requests/README_EN.md index b4abb5752797a..a4178ffd34dca 100644 --- a/solution/1600-1699/1601.Maximum Number of Achievable Transfer Requests/README_EN.md +++ b/solution/1600-1699/1601.Maximum Number of Achievable Transfer Requests/README_EN.md @@ -89,6 +89,8 @@ The time complexity is $O(2^m \times (m + n))$, and the space complexity is $O(n +#### Python3 + ```python class Solution: def maximumRequests(self, n: int, requests: List[List[int]]) -> int: @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int m; @@ -147,6 +151,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func maximumRequests(n int, requests [][]int) (ans int) { m := len(requests) @@ -210,6 +218,8 @@ func maximumRequests(n int, requests [][]int) (ans int) { } ``` +#### TypeScript + ```ts function maximumRequests(n: number, requests: number[][]): number { const m = requests.length; @@ -244,6 +254,8 @@ function bitCount(i: number): number { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -283,6 +295,8 @@ function bitCount(i) { } ``` +#### C# + ```cs public class Solution { private int m; diff --git a/solution/1600-1699/1602.Find Nearest Right Node in Binary Tree/README.md b/solution/1600-1699/1602.Find Nearest Right Node in Binary Tree/README.md index ebf4b68b87efc..a10072872c5d9 100644 --- a/solution/1600-1699/1602.Find Nearest Right Node in Binary Tree/README.md +++ b/solution/1600-1699/1602.Find Nearest Right Node in Binary Tree/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -102,6 +104,8 @@ class Solution: q.append(root.right) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -210,6 +218,8 @@ func findNearestRightNode(root *TreeNode, u *TreeNode) *TreeNode { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -258,6 +268,8 @@ DFS 先序遍历二叉树,首次搜索到 $u$ 时,标记目前层数 $d$, +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -286,6 +298,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -331,6 +345,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -369,6 +385,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -402,6 +420,8 @@ func findNearestRightNode(root *TreeNode, u *TreeNode) *TreeNode { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/1600-1699/1602.Find Nearest Right Node in Binary Tree/README_EN.md b/solution/1600-1699/1602.Find Nearest Right Node in Binary Tree/README_EN.md index 00a2a8ed8c340..2e2c4ac5988ef 100644 --- a/solution/1600-1699/1602.Find Nearest Right Node in Binary Tree/README_EN.md +++ b/solution/1600-1699/1602.Find Nearest Right Node in Binary Tree/README_EN.md @@ -61,6 +61,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -82,6 +84,8 @@ class Solution: q.append(root.right) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -190,6 +198,8 @@ func findNearestRightNode(root *TreeNode, u *TreeNode) *TreeNode { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -238,6 +248,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -266,6 +278,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -311,6 +325,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -349,6 +365,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -382,6 +400,8 @@ func findNearestRightNode(root *TreeNode, u *TreeNode) *TreeNode { } ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/1600-1699/1603.Design Parking System/README.md b/solution/1600-1699/1603.Design Parking System/README.md index a51b1df9c2eac..9d5dfa2c081b7 100644 --- a/solution/1600-1699/1603.Design Parking System/README.md +++ b/solution/1600-1699/1603.Design Parking System/README.md @@ -72,6 +72,8 @@ parkingSystem.addCar(1); // 返回 false ,因为没有空的大车位,唯一 +#### Python3 + ```python class ParkingSystem: def __init__(self, big: int, medium: int, small: int): @@ -89,6 +91,8 @@ class ParkingSystem: # param_1 = obj.addCar(carType) ``` +#### Java + ```java class ParkingSystem { private int[] cnt; @@ -113,6 +117,8 @@ class ParkingSystem { */ ``` +#### C++ + ```cpp class ParkingSystem { public: @@ -139,6 +145,8 @@ private: */ ``` +#### Go + ```go type ParkingSystem struct { cnt []int @@ -163,6 +171,8 @@ func (this *ParkingSystem) AddCar(carType int) bool { */ ``` +#### TypeScript + ```ts class ParkingSystem { private count: [number, number, number]; @@ -187,6 +197,8 @@ class ParkingSystem { */ ``` +#### Rust + ```rust struct ParkingSystem { count: [i32; 3], @@ -218,6 +230,8 @@ impl ParkingSystem { */ ``` +#### C# + ```cs public class ParkingSystem { @@ -243,6 +257,8 @@ public class ParkingSystem { */ ``` +#### C + ```c typedef struct { int* count; diff --git a/solution/1600-1699/1603.Design Parking System/README_EN.md b/solution/1600-1699/1603.Design Parking System/README_EN.md index 1f0c0ac7f93e5..24c8d10263240 100644 --- a/solution/1600-1699/1603.Design Parking System/README_EN.md +++ b/solution/1600-1699/1603.Design Parking System/README_EN.md @@ -66,6 +66,8 @@ parkingSystem.addCar(1); // return false because there is no available slot for +#### Python3 + ```python class ParkingSystem: def __init__(self, big: int, medium: int, small: int): @@ -83,6 +85,8 @@ class ParkingSystem: # param_1 = obj.addCar(carType) ``` +#### Java + ```java class ParkingSystem { private int[] cnt; @@ -107,6 +111,8 @@ class ParkingSystem { */ ``` +#### C++ + ```cpp class ParkingSystem { public: @@ -133,6 +139,8 @@ private: */ ``` +#### Go + ```go type ParkingSystem struct { cnt []int @@ -157,6 +165,8 @@ func (this *ParkingSystem) AddCar(carType int) bool { */ ``` +#### TypeScript + ```ts class ParkingSystem { private count: [number, number, number]; @@ -181,6 +191,8 @@ class ParkingSystem { */ ``` +#### Rust + ```rust struct ParkingSystem { count: [i32; 3], @@ -212,6 +224,8 @@ impl ParkingSystem { */ ``` +#### C# + ```cs public class ParkingSystem { @@ -237,6 +251,8 @@ public class ParkingSystem { */ ``` +#### C + ```c typedef struct { int* count; diff --git a/solution/1600-1699/1604.Alert Using Same Key-Card Three or More Times in a One Hour Period/README.md b/solution/1600-1699/1604.Alert Using Same Key-Card Three or More Times in a One Hour Period/README.md index 97ff322f2236f..ff3a9bf6b0e30 100644 --- a/solution/1600-1699/1604.Alert Using Same Key-Card Three or More Times in a One Hour Period/README.md +++ b/solution/1600-1699/1604.Alert Using Same Key-Card Three or More Times in a One Hour Period/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def alertNames(self, keyName: List[str], keyTime: List[str]) -> List[str]: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List alertNames(String[] keyName, String[] keyTime) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func alertNames(keyName []string, keyTime []string) (ans []string) { d := map[string][]int{} @@ -188,6 +196,8 @@ func alertNames(keyName []string, keyTime []string) (ans []string) { } ``` +#### TypeScript + ```ts function alertNames(keyName: string[], keyTime: string[]): string[] { const d: { [name: string]: number[] } = {}; diff --git a/solution/1600-1699/1604.Alert Using Same Key-Card Three or More Times in a One Hour Period/README_EN.md b/solution/1600-1699/1604.Alert Using Same Key-Card Three or More Times in a One Hour Period/README_EN.md index f685d1541c697..fa27069c6bb7e 100644 --- a/solution/1600-1699/1604.Alert Using Same Key-Card Three or More Times in a One Hour Period/README_EN.md +++ b/solution/1600-1699/1604.Alert Using Same Key-Card Three or More Times in a One Hour Period/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def alertNames(self, keyName: List[str], keyTime: List[str]) -> List[str]: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List alertNames(String[] keyName, String[] keyTime) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func alertNames(keyName []string, keyTime []string) (ans []string) { d := map[string][]int{} @@ -186,6 +194,8 @@ func alertNames(keyName []string, keyTime []string) (ans []string) { } ``` +#### TypeScript + ```ts function alertNames(keyName: string[], keyTime: string[]): string[] { const d: { [name: string]: number[] } = {}; diff --git a/solution/1600-1699/1605.Find Valid Matrix Given Row and Column Sums/README.md b/solution/1600-1699/1605.Find Valid Matrix Given Row and Column Sums/README.md index 7210ea4b0e993..8d77c65262d37 100644 --- a/solution/1600-1699/1605.Find Valid Matrix Given Row and Column Sums/README.md +++ b/solution/1600-1699/1605.Find Valid Matrix Given Row and Column Sums/README.md @@ -108,6 +108,8 @@ tags: +#### Python3 + ```python class Solution: def restoreMatrix(self, rowSum: List[int], colSum: List[int]) -> List[List[int]]: @@ -122,6 +124,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] restoreMatrix(int[] rowSum, int[] colSum) { @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func restoreMatrix(rowSum []int, colSum []int) [][]int { m, n := len(rowSum), len(colSum) @@ -179,6 +187,8 @@ func restoreMatrix(rowSum []int, colSum []int) [][]int { } ``` +#### TypeScript + ```ts function restoreMatrix(rowSum: number[], colSum: number[]): number[][] { const m = rowSum.length; @@ -196,6 +206,8 @@ function restoreMatrix(rowSum: number[], colSum: number[]): number[][] { } ``` +#### JavaScript + ```js /** * @param {number[]} rowSum diff --git a/solution/1600-1699/1605.Find Valid Matrix Given Row and Column Sums/README_EN.md b/solution/1600-1699/1605.Find Valid Matrix Given Row and Column Sums/README_EN.md index 2b8a98aebc326..210a059837992 100644 --- a/solution/1600-1699/1605.Find Valid Matrix Given Row and Column Sums/README_EN.md +++ b/solution/1600-1699/1605.Find Valid Matrix Given Row and Column Sums/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def restoreMatrix(self, rowSum: List[int], colSum: List[int]) -> List[List[int]]: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] restoreMatrix(int[] rowSum, int[] colSum) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func restoreMatrix(rowSum []int, colSum []int) [][]int { m, n := len(rowSum), len(colSum) @@ -154,6 +162,8 @@ func restoreMatrix(rowSum []int, colSum []int) [][]int { } ``` +#### TypeScript + ```ts function restoreMatrix(rowSum: number[], colSum: number[]): number[][] { const m = rowSum.length; @@ -171,6 +181,8 @@ function restoreMatrix(rowSum: number[], colSum: number[]): number[][] { } ``` +#### JavaScript + ```js /** * @param {number[]} rowSum diff --git a/solution/1600-1699/1606.Find Servers That Handled Most Number of Requests/README.md b/solution/1600-1699/1606.Find Servers That Handled Most Number of Requests/README.md index 053bc6a2dae74..42fce2a0f0743 100644 --- a/solution/1600-1699/1606.Find Servers That Handled Most Number of Requests/README.md +++ b/solution/1600-1699/1606.Find Servers That Handled Most Number of Requests/README.md @@ -116,6 +116,8 @@ tags: +#### Python3 + ```python from sortedcontainers import SortedList @@ -143,6 +145,8 @@ class Solution: return [i for i, v in enumerate(cnt) if v == mx] ``` +#### Java + ```java class Solution { public List busiestServers(int k, int[] arrival, int[] load) { @@ -184,6 +188,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -216,6 +222,8 @@ public: }; ``` +#### Go + ```go func busiestServers(k int, arrival, load []int) (ans []int) { free := redblacktree.NewWithIntComparator() diff --git a/solution/1600-1699/1606.Find Servers That Handled Most Number of Requests/README_EN.md b/solution/1600-1699/1606.Find Servers That Handled Most Number of Requests/README_EN.md index 25ce69b102de8..e19edfd9efc2e 100644 --- a/solution/1600-1699/1606.Find Servers That Handled Most Number of Requests/README_EN.md +++ b/solution/1600-1699/1606.Find Servers That Handled Most Number of Requests/README_EN.md @@ -88,6 +88,8 @@ Server 0 handled two requests, while servers 1 and 2 handled one request each. H +#### Python3 + ```python from sortedcontainers import SortedList @@ -115,6 +117,8 @@ class Solution: return [i for i, v in enumerate(cnt) if v == mx] ``` +#### Java + ```java class Solution { public List busiestServers(int k, int[] arrival, int[] load) { @@ -156,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go func busiestServers(k int, arrival, load []int) (ans []int) { free := redblacktree.NewWithIntComparator() diff --git a/solution/1600-1699/1607.Sellers With No Sales/README.md b/solution/1600-1699/1607.Sellers With No Sales/README.md index f2115ea457794..2db9e68025ace 100644 --- a/solution/1600-1699/1607.Sellers With No Sales/README.md +++ b/solution/1600-1699/1607.Sellers With No Sales/README.md @@ -126,6 +126,8 @@ Frank 在 2019 年卖出 1 次, 在 2020 年没有卖出。 +#### MySQL + ```sql # Write your MySQL query statement below SELECT seller_name diff --git a/solution/1600-1699/1607.Sellers With No Sales/README_EN.md b/solution/1600-1699/1607.Sellers With No Sales/README_EN.md index 5c1c621679daa..1591c3e0e381d 100644 --- a/solution/1600-1699/1607.Sellers With No Sales/README_EN.md +++ b/solution/1600-1699/1607.Sellers With No Sales/README_EN.md @@ -126,6 +126,8 @@ We can use a left join to join the `Seller` table with the `Orders` table on the +#### MySQL + ```sql # Write your MySQL query statement below SELECT seller_name diff --git a/solution/1600-1699/1608.Special Array With X Elements Greater Than or Equal X/README.md b/solution/1600-1699/1608.Special Array With X Elements Greater Than or Equal X/README.md index 8181bcf17e0ad..698c26894c20b 100644 --- a/solution/1600-1699/1608.Special Array With X Elements Greater Than or Equal X/README.md +++ b/solution/1600-1699/1608.Special Array With X Elements Greater Than or Equal X/README.md @@ -81,6 +81,8 @@ x 不能取更大的值,因为 nums 中只有两个元素。 +#### Python3 + ```python class Solution: def specialArray(self, nums: List[int]) -> int: @@ -91,6 +93,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int specialArray(int[] nums) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func specialArray(nums []int) int { for x := 1; x <= len(nums); x++ { @@ -141,6 +149,8 @@ func specialArray(nums []int) int { } ``` +#### TypeScript + ```ts function specialArray(nums: number[]): number { const n = nums.length; @@ -153,6 +163,8 @@ function specialArray(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn special_array(nums: Vec) -> i32 { @@ -189,6 +201,8 @@ impl Solution { +#### Python3 + ```python class Solution: def specialArray(self, nums: List[int]) -> int: @@ -201,6 +215,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int specialArray(int[] nums) { @@ -226,6 +242,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -241,6 +259,8 @@ public: }; ``` +#### Go + ```go func specialArray(nums []int) int { sort.Ints(nums) @@ -264,6 +284,8 @@ func specialArray(nums []int) int { } ``` +#### TypeScript + ```ts function specialArray(nums: number[]): number { const n = nums.length; @@ -287,6 +309,8 @@ function specialArray(nums: number[]): number { } ``` +#### Rust + ```rust use std::cmp::Ordering; impl Solution { diff --git a/solution/1600-1699/1608.Special Array With X Elements Greater Than or Equal X/README_EN.md b/solution/1600-1699/1608.Special Array With X Elements Greater Than or Equal X/README_EN.md index 7c358fdf162d1..a05c2b6e8ca5a 100644 --- a/solution/1600-1699/1608.Special Array With X Elements Greater Than or Equal X/README_EN.md +++ b/solution/1600-1699/1608.Special Array With X Elements Greater Than or Equal X/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n^2)$, where $n$ is the length of the array. The space +#### Python3 + ```python class Solution: def specialArray(self, nums: List[int]) -> int: @@ -87,6 +89,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int specialArray(int[] nums) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func specialArray(nums []int) int { for x := 1; x <= len(nums); x++ { @@ -137,6 +145,8 @@ func specialArray(nums []int) int { } ``` +#### TypeScript + ```ts function specialArray(nums: number[]): number { const n = nums.length; @@ -149,6 +159,8 @@ function specialArray(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn special_array(nums: Vec) -> i32 { @@ -185,6 +197,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def specialArray(self, nums: List[int]) -> int: @@ -197,6 +211,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int specialArray(int[] nums) { @@ -222,6 +238,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -237,6 +255,8 @@ public: }; ``` +#### Go + ```go func specialArray(nums []int) int { sort.Ints(nums) @@ -260,6 +280,8 @@ func specialArray(nums []int) int { } ``` +#### TypeScript + ```ts function specialArray(nums: number[]): number { const n = nums.length; @@ -283,6 +305,8 @@ function specialArray(nums: number[]): number { } ``` +#### Rust + ```rust use std::cmp::Ordering; impl Solution { diff --git a/solution/1600-1699/1609.Even Odd Tree/README.md b/solution/1600-1699/1609.Even Odd Tree/README.md index 187a08510daf7..629a39ecc6f14 100644 --- a/solution/1600-1699/1609.Even Odd Tree/README.md +++ b/solution/1600-1699/1609.Even Odd Tree/README.md @@ -108,6 +108,8 @@ BFS 逐层遍历,每层按照奇偶性判断,每层的节点值都是偶数 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -136,6 +138,8 @@ class Solution: return True ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -182,6 +186,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -225,6 +231,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -279,6 +287,8 @@ DFS 先序遍历二叉树,同样根据节点所在层的奇偶性判断是否 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -304,6 +314,8 @@ class Solution: return dfs(root, 0) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -345,6 +357,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -383,6 +397,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/1600-1699/1609.Even Odd Tree/README_EN.md b/solution/1600-1699/1609.Even Odd Tree/README_EN.md index 149c6505b99ed..063c7096d39d0 100644 --- a/solution/1600-1699/1609.Even Odd Tree/README_EN.md +++ b/solution/1600-1699/1609.Even Odd Tree/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -114,6 +116,8 @@ class Solution: return True ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -203,6 +209,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -257,6 +265,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -282,6 +292,8 @@ class Solution: return dfs(root, 0) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -323,6 +335,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -361,6 +375,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/1600-1699/1610.Maximum Number of Visible Points/README.md b/solution/1600-1699/1610.Maximum Number of Visible Points/README.md index 8669d1f3c50aa..9aea57052fbeb 100644 --- a/solution/1600-1699/1610.Maximum Number of Visible Points/README.md +++ b/solution/1600-1699/1610.Maximum Number of Visible Points/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def visiblePoints( @@ -104,6 +106,8 @@ class Solution: return mx + same ``` +#### Java + ```java class Solution { public int visiblePoints(List> points, int angle, List location) { @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func visiblePoints(points [][]int, angle int, location []int) int { same := 0 diff --git a/solution/1600-1699/1610.Maximum Number of Visible Points/README_EN.md b/solution/1600-1699/1610.Maximum Number of Visible Points/README_EN.md index 3ca28fb9b5888..ba10d487d3b21 100644 --- a/solution/1600-1699/1610.Maximum Number of Visible Points/README_EN.md +++ b/solution/1600-1699/1610.Maximum Number of Visible Points/README_EN.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def visiblePoints( @@ -103,6 +105,8 @@ class Solution: return mx + same ``` +#### Java + ```java class Solution { public int visiblePoints(List> points, int angle, List location) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func visiblePoints(points [][]int, angle int, location []int) int { same := 0 diff --git a/solution/1600-1699/1611.Minimum One Bit Operations to Make Integers Zero/README.md b/solution/1600-1699/1611.Minimum One Bit Operations to Make Integers Zero/README.md index fadd8211fb079..dd756aaf150e2 100644 --- a/solution/1600-1699/1611.Minimum One Bit Operations to Make Integers Zero/README.md +++ b/solution/1600-1699/1611.Minimum One Bit Operations to Make Integers Zero/README.md @@ -93,6 +93,8 @@ int rev(int x) { +#### Python3 + ```python class Solution: def minimumOneBitOperations(self, n: int) -> int: @@ -103,6 +105,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumOneBitOperations(int n) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func minimumOneBitOperations(n int) (ans int) { for ; n > 0; n >>= 1 { @@ -137,6 +145,8 @@ func minimumOneBitOperations(n int) (ans int) { } ``` +#### TypeScript + ```ts function minimumOneBitOperations(n: number): number { let ans = 0; @@ -157,6 +167,8 @@ function minimumOneBitOperations(n: number): number { +#### Python3 + ```python class Solution: def minimumOneBitOperations(self, n: int) -> int: @@ -165,6 +177,8 @@ class Solution: return n ^ self.minimumOneBitOperations(n >> 1) ``` +#### Java + ```java class Solution { public int minimumOneBitOperations(int n) { @@ -176,6 +190,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +204,8 @@ public: }; ``` +#### Go + ```go func minimumOneBitOperations(n int) int { if n == 0 { @@ -197,6 +215,8 @@ func minimumOneBitOperations(n int) int { } ``` +#### TypeScript + ```ts function minimumOneBitOperations(n: number): number { if (n === 0) { diff --git a/solution/1600-1699/1611.Minimum One Bit Operations to Make Integers Zero/README_EN.md b/solution/1600-1699/1611.Minimum One Bit Operations to Make Integers Zero/README_EN.md index ac8f5b5afafb8..20fdd6eecedb9 100644 --- a/solution/1600-1699/1611.Minimum One Bit Operations to Make Integers Zero/README_EN.md +++ b/solution/1600-1699/1611.Minimum One Bit Operations to Make Integers Zero/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def minimumOneBitOperations(self, n: int) -> int: @@ -79,6 +81,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumOneBitOperations(int n) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -104,6 +110,8 @@ public: }; ``` +#### Go + ```go func minimumOneBitOperations(n int) (ans int) { for ; n > 0; n >>= 1 { @@ -113,6 +121,8 @@ func minimumOneBitOperations(n int) (ans int) { } ``` +#### TypeScript + ```ts function minimumOneBitOperations(n: number): number { let ans = 0; @@ -133,6 +143,8 @@ function minimumOneBitOperations(n: number): number { +#### Python3 + ```python class Solution: def minimumOneBitOperations(self, n: int) -> int: @@ -141,6 +153,8 @@ class Solution: return n ^ self.minimumOneBitOperations(n >> 1) ``` +#### Java + ```java class Solution { public int minimumOneBitOperations(int n) { @@ -152,6 +166,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +180,8 @@ public: }; ``` +#### Go + ```go func minimumOneBitOperations(n int) int { if n == 0 { @@ -173,6 +191,8 @@ func minimumOneBitOperations(n int) int { } ``` +#### TypeScript + ```ts function minimumOneBitOperations(n: number): number { if (n === 0) { diff --git a/solution/1600-1699/1612.Check If Two Expression Trees are Equivalent/README.md b/solution/1600-1699/1612.Check If Two Expression Trees are Equivalent/README.md index 7e5cb195c91ed..2199ea70bd3e9 100644 --- a/solution/1600-1699/1612.Check If Two Expression Trees are Equivalent/README.md +++ b/solution/1600-1699/1612.Check If Two Expression Trees are Equivalent/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class Node(object): @@ -107,6 +109,8 @@ class Solution: return all(x == 0 for x in cnt.values()) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -188,6 +194,8 @@ public: }; ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -235,6 +243,8 @@ var checkEquivalence = function (root1, root2) { +#### Python3 + ```python # Definition for a binary tree node. # class Node(object): @@ -260,6 +270,8 @@ class Solution: return dfs(root1) == dfs(root2) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -308,6 +320,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -345,6 +359,8 @@ public: }; ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/1600-1699/1612.Check If Two Expression Trees are Equivalent/README_EN.md b/solution/1600-1699/1612.Check If Two Expression Trees are Equivalent/README_EN.md index fd7853de4f5b2..900d2ba2ec4b5 100644 --- a/solution/1600-1699/1612.Check If Two Expression Trees are Equivalent/README_EN.md +++ b/solution/1600-1699/1612.Check If Two Expression Trees are Equivalent/README_EN.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class Node(object): @@ -96,6 +98,8 @@ class Solution: return all(x == 0 for x in cnt.values()) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -177,6 +183,8 @@ public: }; ``` +#### JavaScript + ```js /** * Definition for a binary tree node. @@ -224,6 +232,8 @@ var checkEquivalence = function (root1, root2) { +#### Python3 + ```python # Definition for a binary tree node. # class Node(object): @@ -249,6 +259,8 @@ class Solution: return dfs(root1) == dfs(root2) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -297,6 +309,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -334,6 +348,8 @@ public: }; ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/1600-1699/1613.Find the Missing IDs/README.md b/solution/1600-1699/1613.Find the Missing IDs/README.md index 54bb0376f7521..f00735a12d569 100644 --- a/solution/1600-1699/1613.Find the Missing IDs/README.md +++ b/solution/1600-1699/1613.Find the Missing IDs/README.md @@ -75,6 +75,8 @@ Customers 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH RECURSIVE diff --git a/solution/1600-1699/1613.Find the Missing IDs/README_EN.md b/solution/1600-1699/1613.Find the Missing IDs/README_EN.md index 6d064fa448c1a..e688d40a1ab17 100644 --- a/solution/1600-1699/1613.Find the Missing IDs/README_EN.md +++ b/solution/1600-1699/1613.Find the Missing IDs/README_EN.md @@ -73,6 +73,8 @@ The maximum customer_id present in the table is 5, so in the range [1,5], IDs 2 +#### MySQL + ```sql # Write your MySQL query statement below WITH RECURSIVE diff --git a/solution/1600-1699/1614.Maximum Nesting Depth of the Parentheses/README.md b/solution/1600-1699/1614.Maximum Nesting Depth of the Parentheses/README.md index 3e2ff5c4e47f7..772cdacbf8184 100644 --- a/solution/1600-1699/1614.Maximum Nesting Depth of the Parentheses/README.md +++ b/solution/1600-1699/1614.Maximum Nesting Depth of the Parentheses/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def maxDepth(self, s: str) -> int: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxDepth(String s) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func maxDepth(s string) (ans int) { d := 0 @@ -145,6 +153,8 @@ func maxDepth(s string) (ans int) { } ``` +#### TypeScript + ```ts function maxDepth(s: string): number { let ans = 0; @@ -160,6 +170,8 @@ function maxDepth(s: string): number { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -179,6 +191,8 @@ var maxDepth = function (s) { }; ``` +#### C# + ```cs public class Solution { public int MaxDepth(string s) { diff --git a/solution/1600-1699/1614.Maximum Nesting Depth of the Parentheses/README_EN.md b/solution/1600-1699/1614.Maximum Nesting Depth of the Parentheses/README_EN.md index 9cd7e3573febf..e3ee78b0b2e32 100644 --- a/solution/1600-1699/1614.Maximum Nesting Depth of the Parentheses/README_EN.md +++ b/solution/1600-1699/1614.Maximum Nesting Depth of the Parentheses/README_EN.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def maxDepth(self, s: str) -> int: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxDepth(String s) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func maxDepth(s string) (ans int) { d := 0 @@ -135,6 +143,8 @@ func maxDepth(s string) (ans int) { } ``` +#### TypeScript + ```ts function maxDepth(s: string): number { let ans = 0; @@ -150,6 +160,8 @@ function maxDepth(s: string): number { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -169,6 +181,8 @@ var maxDepth = function (s) { }; ``` +#### C# + ```cs public class Solution { public int MaxDepth(string s) { diff --git a/solution/1600-1699/1615.Maximal Network Rank/README.md b/solution/1600-1699/1615.Maximal Network Rank/README.md index da6aa0e8a79f7..b7c57d7f63ae6 100644 --- a/solution/1600-1699/1615.Maximal Network Rank/README.md +++ b/solution/1600-1699/1615.Maximal Network Rank/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def maximalNetworkRank(self, n: int, roads: List[List[int]]) -> int: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximalNetworkRank(int n, int[][] roads) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func maximalNetworkRank(n int, roads [][]int) (ans int) { g := make([][]int, n) @@ -170,6 +178,8 @@ func maximalNetworkRank(n int, roads [][]int) (ans int) { } ``` +#### TypeScript + ```ts function maximalNetworkRank(n: number, roads: number[][]): number { const g: number[][] = Array.from(new Array(n), () => new Array(n).fill(0)); @@ -200,6 +210,8 @@ function maximalNetworkRank(n: number, roads: number[][]): number { +#### Python3 + ```python class Solution: def maximalNetworkRank(self, n: int, roads: List[List[int]]) -> int: diff --git a/solution/1600-1699/1615.Maximal Network Rank/README_EN.md b/solution/1600-1699/1615.Maximal Network Rank/README_EN.md index 1db91a3479208..611ec9f1bd5a7 100644 --- a/solution/1600-1699/1615.Maximal Network Rank/README_EN.md +++ b/solution/1600-1699/1615.Maximal Network Rank/README_EN.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def maximalNetworkRank(self, n: int, roads: List[List[int]]) -> int: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximalNetworkRank(int n, int[][] roads) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func maximalNetworkRank(n int, roads [][]int) (ans int) { g := make([][]int, n) @@ -162,6 +170,8 @@ func maximalNetworkRank(n int, roads [][]int) (ans int) { } ``` +#### TypeScript + ```ts function maximalNetworkRank(n: number, roads: number[][]): number { const g: number[][] = Array.from(new Array(n), () => new Array(n).fill(0)); @@ -192,6 +202,8 @@ function maximalNetworkRank(n: number, roads: number[][]): number { +#### Python3 + ```python class Solution: def maximalNetworkRank(self, n: int, roads: List[List[int]]) -> int: diff --git a/solution/1600-1699/1616.Split Two Strings to Make Palindrome/README.md b/solution/1600-1699/1616.Split Two Strings to Make Palindrome/README.md index b62c2296753fa..e17bd43feada2 100644 --- a/solution/1600-1699/1616.Split Two Strings to Make Palindrome/README.md +++ b/solution/1600-1699/1616.Split Two Strings to Make Palindrome/README.md @@ -85,6 +85,8 @@ bprefix = "jiz", bsuffix = "alu" +#### Python3 + ```python class Solution: def checkPalindromeFormation(self, a: str, b: str) -> bool: @@ -100,6 +102,8 @@ class Solution: return check1(a, b) or check1(b, a) ``` +#### Java + ```java class Solution { public boolean checkPalindromeFormation(String a, String b) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ private: }; ``` +#### Go + ```go func checkPalindromeFormation(a string, b string) bool { return check1(a, b) || check1(b, a) @@ -176,6 +184,8 @@ func check2(a string, i, j int) bool { } ``` +#### TypeScript + ```ts function checkPalindromeFormation(a: string, b: string): boolean { const check1 = (a: string, b: string) => { @@ -199,6 +209,8 @@ function checkPalindromeFormation(a: string, b: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn check_palindrome_formation(a: String, b: String) -> bool { diff --git a/solution/1600-1699/1616.Split Two Strings to Make Palindrome/README_EN.md b/solution/1600-1699/1616.Split Two Strings to Make Palindrome/README_EN.md index 32ce86f07772d..d62a87129ab99 100644 --- a/solution/1600-1699/1616.Split Two Strings to Make Palindrome/README_EN.md +++ b/solution/1600-1699/1616.Split Two Strings to Make Palindrome/README_EN.md @@ -76,6 +76,8 @@ Then, aprefix + bsuffix = "ula" + "alu" +#### Python3 + ```python class Solution: def checkPalindromeFormation(self, a: str, b: str) -> bool: @@ -91,6 +93,8 @@ class Solution: return check1(a, b) or check1(b, a) ``` +#### Java + ```java class Solution { public boolean checkPalindromeFormation(String a, String b) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ private: }; ``` +#### Go + ```go func checkPalindromeFormation(a string, b string) bool { return check1(a, b) || check1(b, a) @@ -167,6 +175,8 @@ func check2(a string, i, j int) bool { } ``` +#### TypeScript + ```ts function checkPalindromeFormation(a: string, b: string): boolean { const check1 = (a: string, b: string) => { @@ -190,6 +200,8 @@ function checkPalindromeFormation(a: string, b: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn check_palindrome_formation(a: String, b: String) -> bool { diff --git a/solution/1600-1699/1617.Count Subtrees With Max Distance Between Cities/README.md b/solution/1600-1699/1617.Count Subtrees With Max Distance Between Cities/README.md index bd27d0c89e349..8a2a14e51c827 100644 --- a/solution/1600-1699/1617.Count Subtrees With Max Distance Between Cities/README.md +++ b/solution/1600-1699/1617.Count Subtrees With Max Distance Between Cities/README.md @@ -103,6 +103,8 @@ tags: +#### Python3 + ```python class Solution: def countSubgraphsForEachDiameter( @@ -137,6 +139,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -186,6 +190,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -230,6 +236,8 @@ public: }; ``` +#### Go + ```go func countSubgraphsForEachDiameter(n int, edges [][]int) []int { g := make([][]int, n) @@ -269,6 +277,8 @@ func countSubgraphsForEachDiameter(n int, edges [][]int) []int { } ``` +#### TypeScript + ```ts function countSubgraphsForEachDiameter(n: number, edges: number[][]): number[] { const g = Array.from({ length: n }, () => []); @@ -342,6 +352,8 @@ function numberOfLeadingZeros(i: number): number { +#### Python3 + ```python class Solution: def countSubgraphsForEachDiameter( @@ -382,6 +394,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -436,6 +450,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -486,6 +502,8 @@ public: }; ``` +#### Go + ```go func countSubgraphsForEachDiameter(n int, edges [][]int) []int { g := make([][]int, n) @@ -533,6 +551,8 @@ func countSubgraphsForEachDiameter(n int, edges [][]int) []int { } ``` +#### TypeScript + ```ts function countSubgraphsForEachDiameter(n: number, edges: number[][]): number[] { const g = Array.from({ length: n }, () => []); diff --git a/solution/1600-1699/1617.Count Subtrees With Max Distance Between Cities/README_EN.md b/solution/1600-1699/1617.Count Subtrees With Max Distance Between Cities/README_EN.md index aef576b50bacb..a39d7dd0a4861 100644 --- a/solution/1600-1699/1617.Count Subtrees With Max Distance Between Cities/README_EN.md +++ b/solution/1600-1699/1617.Count Subtrees With Max Distance Between Cities/README_EN.md @@ -102,6 +102,8 @@ No subtree has two nodes where the max distance between them is 3. +#### Python3 + ```python class Solution: def countSubgraphsForEachDiameter( @@ -136,6 +138,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -185,6 +189,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -229,6 +235,8 @@ public: }; ``` +#### Go + ```go func countSubgraphsForEachDiameter(n int, edges [][]int) []int { g := make([][]int, n) @@ -268,6 +276,8 @@ func countSubgraphsForEachDiameter(n int, edges [][]int) []int { } ``` +#### TypeScript + ```ts function countSubgraphsForEachDiameter(n: number, edges: number[][]): number[] { const g = Array.from({ length: n }, () => []); @@ -341,6 +351,8 @@ function numberOfLeadingZeros(i: number): number { +#### Python3 + ```python class Solution: def countSubgraphsForEachDiameter( @@ -381,6 +393,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -435,6 +449,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -485,6 +501,8 @@ public: }; ``` +#### Go + ```go func countSubgraphsForEachDiameter(n int, edges [][]int) []int { g := make([][]int, n) @@ -532,6 +550,8 @@ func countSubgraphsForEachDiameter(n int, edges [][]int) []int { } ``` +#### TypeScript + ```ts function countSubgraphsForEachDiameter(n: number, edges: number[][]): number[] { const g = Array.from({ length: n }, () => []); diff --git a/solution/1600-1699/1618.Maximum Font to Fit a Sentence in a Screen/README.md b/solution/1600-1699/1618.Maximum Font to Fit a Sentence in a Screen/README.md index 8211ef21aa8e7..f382260fcdc47 100644 --- a/solution/1600-1699/1618.Maximum Font to Fit a Sentence in a Screen/README.md +++ b/solution/1600-1699/1618.Maximum Font to Fit a Sentence in a Screen/README.md @@ -104,6 +104,8 @@ interface FontInfo { +#### Python3 + ```python # """ # This is FontInfo's API interface. @@ -143,6 +145,8 @@ class Solution: return fonts[left] if check(fonts[left]) else -1 ``` +#### Java + ```java /** * // This is the FontInfo's API interface. @@ -181,6 +185,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * // This is the FontInfo's API interface. @@ -219,6 +225,8 @@ public: }; ``` +#### JavaScript + ```js /** * // This is the FontInfo's API interface. diff --git a/solution/1600-1699/1618.Maximum Font to Fit a Sentence in a Screen/README_EN.md b/solution/1600-1699/1618.Maximum Font to Fit a Sentence in a Screen/README_EN.md index 07667ac0c0149..86b831b8cd79f 100644 --- a/solution/1600-1699/1618.Maximum Font to Fit a Sentence in a Screen/README_EN.md +++ b/solution/1600-1699/1618.Maximum Font to Fit a Sentence in a Screen/README_EN.md @@ -125,6 +125,8 @@ interface FontInfo { +#### Python3 + ```python # """ # This is FontInfo's API interface. @@ -164,6 +166,8 @@ class Solution: return fonts[left] if check(fonts[left]) else -1 ``` +#### Java + ```java /** * // This is the FontInfo's API interface. @@ -202,6 +206,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * // This is the FontInfo's API interface. @@ -240,6 +246,8 @@ public: }; ``` +#### JavaScript + ```js /** * // This is the FontInfo's API interface. diff --git a/solution/1600-1699/1619.Mean of Array After Removing Some Elements/README.md b/solution/1600-1699/1619.Mean of Array After Removing Some Elements/README.md index c6868b7596133..9f9f18ff30627 100644 --- a/solution/1600-1699/1619.Mean of Array After Removing Some Elements/README.md +++ b/solution/1600-1699/1619.Mean of Array After Removing Some Elements/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def trimMean(self, arr: List[int]) -> float: @@ -97,6 +99,8 @@ class Solution: return round(sum(t) / len(t), 5) ``` +#### Java + ```java class Solution { public double trimMean(int[] arr) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func trimMean(arr []int) float64 { sort.Ints(arr) @@ -137,6 +145,8 @@ func trimMean(arr []int) float64 { } ``` +#### TypeScript + ```ts function trimMean(arr: number[]): number { arr.sort((a, b) => a - b); @@ -150,6 +160,8 @@ function trimMean(arr: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn trim_mean(mut arr: Vec) -> f64 { diff --git a/solution/1600-1699/1619.Mean of Array After Removing Some Elements/README_EN.md b/solution/1600-1699/1619.Mean of Array After Removing Some Elements/README_EN.md index c43b22cd778a9..fef38534cc933 100644 --- a/solution/1600-1699/1619.Mean of Array After Removing Some Elements/README_EN.md +++ b/solution/1600-1699/1619.Mean of Array After Removing Some Elements/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def trimMean(self, arr: List[int]) -> float: @@ -75,6 +77,8 @@ class Solution: return round(sum(t) / len(t), 5) ``` +#### Java + ```java class Solution { public double trimMean(int[] arr) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -103,6 +109,8 @@ public: }; ``` +#### Go + ```go func trimMean(arr []int) float64 { sort.Ints(arr) @@ -115,6 +123,8 @@ func trimMean(arr []int) float64 { } ``` +#### TypeScript + ```ts function trimMean(arr: number[]): number { arr.sort((a, b) => a - b); @@ -128,6 +138,8 @@ function trimMean(arr: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn trim_mean(mut arr: Vec) -> f64 { diff --git a/solution/1600-1699/1620.Coordinate With Maximum Network Quality/README.md b/solution/1600-1699/1620.Coordinate With Maximum Network Quality/README.md index 3be3abec887d8..53676a4fce467 100644 --- a/solution/1600-1699/1620.Coordinate With Maximum Network Quality/README.md +++ b/solution/1600-1699/1620.Coordinate With Maximum Network Quality/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class Solution: def bestCoordinate(self, towers: List[List[int]], radius: int) -> List[int]: @@ -114,6 +116,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] bestCoordinate(int[][] towers, int radius) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func bestCoordinate(towers [][]int, radius int) []int { ans := []int{0, 0} diff --git a/solution/1600-1699/1620.Coordinate With Maximum Network Quality/README_EN.md b/solution/1600-1699/1620.Coordinate With Maximum Network Quality/README_EN.md index c59261ef0be25..c21a9f819c4d7 100644 --- a/solution/1600-1699/1620.Coordinate With Maximum Network Quality/README_EN.md +++ b/solution/1600-1699/1620.Coordinate With Maximum Network Quality/README_EN.md @@ -89,6 +89,8 @@ No other coordinate has a higher network quality. +#### Python3 + ```python class Solution: def bestCoordinate(self, towers: List[List[int]], radius: int) -> List[int]: @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] bestCoordinate(int[][] towers, int radius) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func bestCoordinate(towers [][]int, radius int) []int { ans := []int{0, 0} diff --git a/solution/1600-1699/1621.Number of Sets of K Non-Overlapping Line Segments/README.md b/solution/1600-1699/1621.Number of Sets of K Non-Overlapping Line Segments/README.md index f8d8074583c4c..7af27e6ae8cd4 100644 --- a/solution/1600-1699/1621.Number of Sets of K Non-Overlapping Line Segments/README.md +++ b/solution/1600-1699/1621.Number of Sets of K Non-Overlapping Line Segments/README.md @@ -107,6 +107,8 @@ $$ +#### Python3 + ```python class Solution: def numberOfSets(self, n: int, k: int) -> int: @@ -126,6 +128,8 @@ class Solution: return (f[-1][-1] + g[-1][-1]) % mod ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -179,6 +185,8 @@ public: }; ``` +#### Go + ```go func numberOfSets(n int, k int) int { f := make([][]int, n+1) @@ -205,6 +213,8 @@ func numberOfSets(n int, k int) int { } ``` +#### TypeScript + ```ts function numberOfSets(n: number, k: number): number { const f = Array.from({ length: n + 1 }, _ => new Array(k + 1).fill(0)); diff --git a/solution/1600-1699/1621.Number of Sets of K Non-Overlapping Line Segments/README_EN.md b/solution/1600-1699/1621.Number of Sets of K Non-Overlapping Line Segments/README_EN.md index a5c74924e3783..a9fb55bad4bab 100644 --- a/solution/1600-1699/1621.Number of Sets of K Non-Overlapping Line Segments/README_EN.md +++ b/solution/1600-1699/1621.Number of Sets of K Non-Overlapping Line Segments/README_EN.md @@ -68,6 +68,8 @@ The image above shows the 5 different ways {(0,2),(2,3)}, {(0,1),(1,3)}, {(0,1), +#### Python3 + ```python class Solution: def numberOfSets(self, n: int, k: int) -> int: @@ -87,6 +89,8 @@ class Solution: return (f[-1][-1] + g[-1][-1]) % mod ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func numberOfSets(n int, k int) int { f := make([][]int, n+1) @@ -166,6 +174,8 @@ func numberOfSets(n int, k int) int { } ``` +#### TypeScript + ```ts function numberOfSets(n: number, k: number): number { const f = Array.from({ length: n + 1 }, _ => new Array(k + 1).fill(0)); diff --git a/solution/1600-1699/1622.Fancy Sequence/README.md b/solution/1600-1699/1622.Fancy Sequence/README.md index 0b1570929ff39..e27cc7ed5225f 100644 --- a/solution/1600-1699/1622.Fancy Sequence/README.md +++ b/solution/1600-1699/1622.Fancy Sequence/README.md @@ -85,6 +85,8 @@ fancy.getIndex(2); // 返回 20 +#### Python3 + ```python MOD = int(1e9 + 7) @@ -200,6 +202,8 @@ class Fancy: # param_4 = obj.getIndex(idx) ``` +#### Java + ```java class Node { Node left; @@ -354,6 +358,8 @@ class Fancy { */ ``` +#### C++ + ```cpp const int MOD = 1e9 + 7; diff --git a/solution/1600-1699/1622.Fancy Sequence/README_EN.md b/solution/1600-1699/1622.Fancy Sequence/README_EN.md index e2501d8a76bdf..37e0de0da3a8c 100644 --- a/solution/1600-1699/1622.Fancy Sequence/README_EN.md +++ b/solution/1600-1699/1622.Fancy Sequence/README_EN.md @@ -76,6 +76,8 @@ fancy.getIndex(2); // return 20 +#### Python3 + ```python MOD = int(1e9 + 7) @@ -191,6 +193,8 @@ class Fancy: # param_4 = obj.getIndex(idx) ``` +#### Java + ```java class Node { Node left; @@ -345,6 +349,8 @@ class Fancy { */ ``` +#### C++ + ```cpp const int MOD = 1e9 + 7; diff --git a/solution/1600-1699/1623.All Valid Triplets That Can Represent a Country/README.md b/solution/1600-1699/1623.All Valid Triplets That Can Represent a Country/README.md index ef1627f76a585..43d1e063aead7 100644 --- a/solution/1600-1699/1623.All Valid Triplets That Can Represent a Country/README.md +++ b/solution/1600-1699/1623.All Valid Triplets That Can Represent a Country/README.md @@ -134,6 +134,8 @@ student_id 是该表具有唯一值的列 +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1600-1699/1623.All Valid Triplets That Can Represent a Country/README_EN.md b/solution/1600-1699/1623.All Valid Triplets That Can Represent a Country/README_EN.md index e57a162622b10..645e804f5f871 100644 --- a/solution/1600-1699/1623.All Valid Triplets That Can Represent a Country/README_EN.md +++ b/solution/1600-1699/1623.All Valid Triplets That Can Represent a Country/README_EN.md @@ -132,6 +132,8 @@ Let us see all the possible triplets. +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1600-1699/1624.Largest Substring Between Two Equal Characters/README.md b/solution/1600-1699/1624.Largest Substring Between Two Equal Characters/README.md index 3c710e5bbeb44..3c0eb84e3dcba 100644 --- a/solution/1600-1699/1624.Largest Substring Between Two Equal Characters/README.md +++ b/solution/1600-1699/1624.Largest Substring Between Two Equal Characters/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def maxLengthBetweenEqualCharacters(self, s: str) -> int: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxLengthBetweenEqualCharacters(String s) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func maxLengthBetweenEqualCharacters(s string) int { d := make([]int, 26) @@ -147,6 +155,8 @@ func maxLengthBetweenEqualCharacters(s string) int { } ``` +#### TypeScript + ```ts function maxLengthBetweenEqualCharacters(s: string): number { const n = s.length; @@ -164,6 +174,8 @@ function maxLengthBetweenEqualCharacters(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_length_between_equal_characters(s: String) -> i32 { @@ -185,6 +197,8 @@ impl Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) diff --git a/solution/1600-1699/1624.Largest Substring Between Two Equal Characters/README_EN.md b/solution/1600-1699/1624.Largest Substring Between Two Equal Characters/README_EN.md index f448a6fcb067c..059ba59ebb9de 100644 --- a/solution/1600-1699/1624.Largest Substring Between Two Equal Characters/README_EN.md +++ b/solution/1600-1699/1624.Largest Substring Between Two Equal Characters/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def maxLengthBetweenEqualCharacters(self, s: str) -> int: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxLengthBetweenEqualCharacters(String s) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func maxLengthBetweenEqualCharacters(s string) int { d := make([]int, 26) @@ -135,6 +143,8 @@ func maxLengthBetweenEqualCharacters(s string) int { } ``` +#### TypeScript + ```ts function maxLengthBetweenEqualCharacters(s: string): number { const n = s.length; @@ -152,6 +162,8 @@ function maxLengthBetweenEqualCharacters(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_length_between_equal_characters(s: String) -> i32 { @@ -173,6 +185,8 @@ impl Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) diff --git a/solution/1600-1699/1625.Lexicographically Smallest String After Applying Operations/README.md b/solution/1600-1699/1625.Lexicographically Smallest String After Applying Operations/README.md index 7bcf31f18b2fa..b627d70c31348 100644 --- a/solution/1600-1699/1625.Lexicographically Smallest String After Applying Operations/README.md +++ b/solution/1600-1699/1625.Lexicographically Smallest String After Applying Operations/README.md @@ -97,6 +97,8 @@ tags: +#### Python3 + ```python class Solution: def findLexSmallestString(self, s: str, a: int, b: int) -> str: @@ -118,6 +120,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String findLexSmallestString(String s, int a, int b) { @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -178,6 +184,8 @@ public: }; ``` +#### Go + ```go func findLexSmallestString(s string, a int, b int) string { q := []string{s} @@ -224,6 +232,8 @@ func findLexSmallestString(s string, a int, b int) string { +#### Python3 + ```python class Solution: def findLexSmallestString(self, s: str, a: int, b: int) -> str: @@ -249,6 +259,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String findLexSmallestString(String s, int a, int b) { @@ -284,6 +296,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -313,6 +327,8 @@ public: }; ``` +#### Go + ```go func findLexSmallestString(s string, a int, b int) string { n := len(s) diff --git a/solution/1600-1699/1625.Lexicographically Smallest String After Applying Operations/README_EN.md b/solution/1600-1699/1625.Lexicographically Smallest String After Applying Operations/README_EN.md index 443e7ef50e9f4..6f4cd47f3bedd 100644 --- a/solution/1600-1699/1625.Lexicographically Smallest String After Applying Operations/README_EN.md +++ b/solution/1600-1699/1625.Lexicographically Smallest String After Applying Operations/README_EN.md @@ -93,6 +93,8 @@ There is no way to obtain a string that is lexicographically smaller than " +#### Python3 + ```python class Solution: def findLexSmallestString(self, s: str, a: int, b: int) -> str: @@ -114,6 +116,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String findLexSmallestString(String s, int a, int b) { @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func findLexSmallestString(s string, a int, b int) string { q := []string{s} @@ -212,6 +220,8 @@ func findLexSmallestString(s string, a int, b int) string { +#### Python3 + ```python class Solution: def findLexSmallestString(self, s: str, a: int, b: int) -> str: @@ -237,6 +247,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String findLexSmallestString(String s, int a, int b) { @@ -272,6 +284,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -301,6 +315,8 @@ public: }; ``` +#### Go + ```go func findLexSmallestString(s string, a int, b int) string { n := len(s) diff --git a/solution/1600-1699/1626.Best Team With No Conflicts/README.md b/solution/1600-1699/1626.Best Team With No Conflicts/README.md index 1f04ab0c69f3d..075cb9b923342 100644 --- a/solution/1600-1699/1626.Best Team With No Conflicts/README.md +++ b/solution/1600-1699/1626.Best Team With No Conflicts/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def bestTeamScore(self, scores: List[int], ages: List[int]) -> int: @@ -95,6 +97,8 @@ class Solution: return max(f) ``` +#### Java + ```java class Solution { public int bestTeamScore(int[] scores, int[] ages) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func bestTeamScore(scores []int, ages []int) int { n := len(ages) @@ -168,6 +176,8 @@ func bestTeamScore(scores []int, ages []int) int { } ``` +#### TypeScript + ```ts function bestTeamScore(scores: number[], ages: number[]): number { const arr = ages.map((age, i) => [age, scores[i]]); @@ -186,6 +196,8 @@ function bestTeamScore(scores: number[], ages: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} scores @@ -227,6 +239,8 @@ var bestTeamScore = function (scores, ages) { +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -255,6 +269,8 @@ class Solution: return tree.query(m) ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -303,6 +319,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -350,6 +368,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int diff --git a/solution/1600-1699/1626.Best Team With No Conflicts/README_EN.md b/solution/1600-1699/1626.Best Team With No Conflicts/README_EN.md index 82ae8de2d11d5..b3f8303bcde6d 100644 --- a/solution/1600-1699/1626.Best Team With No Conflicts/README_EN.md +++ b/solution/1600-1699/1626.Best Team With No Conflicts/README_EN.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def bestTeamScore(self, scores: List[int], ages: List[int]) -> int: @@ -85,6 +87,8 @@ class Solution: return max(f) ``` +#### Java + ```java class Solution { public int bestTeamScore(int[] scores, int[] ages) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func bestTeamScore(scores []int, ages []int) int { n := len(ages) @@ -158,6 +166,8 @@ func bestTeamScore(scores []int, ages []int) int { } ``` +#### TypeScript + ```ts function bestTeamScore(scores: number[], ages: number[]): number { const arr = ages.map((age, i) => [age, scores[i]]); @@ -176,6 +186,8 @@ function bestTeamScore(scores: number[], ages: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} scores @@ -209,6 +221,8 @@ var bestTeamScore = function (scores, ages) { +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -237,6 +251,8 @@ class Solution: return tree.query(m) ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -285,6 +301,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -332,6 +350,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int diff --git a/solution/1600-1699/1627.Graph Connectivity With Threshold/README.md b/solution/1600-1699/1627.Graph Connectivity With Threshold/README.md index 2973bc52e8156..01537f233c273 100644 --- a/solution/1600-1699/1627.Graph Connectivity With Threshold/README.md +++ b/solution/1600-1699/1627.Graph Connectivity With Threshold/README.md @@ -109,6 +109,8 @@ tags: +#### Python3 + ```python class UnionFind: def __init__(self, n): @@ -144,6 +146,8 @@ class Solution: return [uf.find(a) == uf.find(b) for a, b in queries] ``` +#### Java + ```java class UnionFind { private int[] p; @@ -198,6 +202,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -251,6 +257,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p, size []int @@ -303,6 +311,8 @@ func areConnected(n int, threshold int, queries [][]int) []bool { } ``` +#### TypeScript + ```ts class UnionFind { p: number[]; diff --git a/solution/1600-1699/1627.Graph Connectivity With Threshold/README_EN.md b/solution/1600-1699/1627.Graph Connectivity With Threshold/README_EN.md index c17a8c6c67343..363de3097a5a9 100644 --- a/solution/1600-1699/1627.Graph Connectivity With Threshold/README_EN.md +++ b/solution/1600-1699/1627.Graph Connectivity With Threshold/README_EN.md @@ -97,6 +97,8 @@ The time complexity is $O(n \times \log n \times (\alpha(n) + q))$, and the spac +#### Python3 + ```python class UnionFind: def __init__(self, n): @@ -132,6 +134,8 @@ class Solution: return [uf.find(a) == uf.find(b) for a, b in queries] ``` +#### Java + ```java class UnionFind { private int[] p; @@ -186,6 +190,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -239,6 +245,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p, size []int @@ -291,6 +299,8 @@ func areConnected(n int, threshold int, queries [][]int) []bool { } ``` +#### TypeScript + ```ts class UnionFind { p: number[]; diff --git a/solution/1600-1699/1628.Design an Expression Tree With Evaluate Function/README.md b/solution/1600-1699/1628.Design an Expression Tree With Evaluate Function/README.md index 4a3263216e3da..ec3919c0c1466 100644 --- a/solution/1600-1699/1628.Design an Expression Tree With Evaluate Function/README.md +++ b/solution/1600-1699/1628.Design an Expression Tree With Evaluate Function/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python import abc from abc import ABC, abstractmethod @@ -144,6 +146,8 @@ ans = expTree.evaluate(); """ ``` +#### Java + ```java /** * This is the interface for the expression tree Node. @@ -223,6 +227,8 @@ class TreeBuilder { */ ``` +#### C++ + ```cpp /** * This is the interface for the expression tree Node. diff --git a/solution/1600-1699/1628.Design an Expression Tree With Evaluate Function/README_EN.md b/solution/1600-1699/1628.Design an Expression Tree With Evaluate Function/README_EN.md index 295190b8a5e0d..938ba824d3fd7 100644 --- a/solution/1600-1699/1628.Design an Expression Tree With Evaluate Function/README_EN.md +++ b/solution/1600-1699/1628.Design an Expression Tree With Evaluate Function/README_EN.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python import abc from abc import ABC, abstractmethod @@ -138,6 +140,8 @@ ans = expTree.evaluate(); """ ``` +#### Java + ```java /** * This is the interface for the expression tree Node. @@ -217,6 +221,8 @@ class TreeBuilder { */ ``` +#### C++ + ```cpp /** * This is the interface for the expression tree Node. diff --git a/solution/1600-1699/1629.Slowest Key/README.md b/solution/1600-1699/1629.Slowest Key/README.md index 731681599cc77..65c2cc7524e05 100644 --- a/solution/1600-1699/1629.Slowest Key/README.md +++ b/solution/1600-1699/1629.Slowest Key/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def slowestKey(self, releaseTimes: List[int], keysPressed: str) -> str: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public char slowestKey(int[] releaseTimes, String keysPressed) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func slowestKey(releaseTimes []int, keysPressed string) byte { ans := keysPressed[0] diff --git a/solution/1600-1699/1629.Slowest Key/README_EN.md b/solution/1600-1699/1629.Slowest Key/README_EN.md index 3224758f9055a..ff8a043009a0f 100644 --- a/solution/1600-1699/1629.Slowest Key/README_EN.md +++ b/solution/1600-1699/1629.Slowest Key/README_EN.md @@ -79,6 +79,8 @@ The longest of these was the keypress for 'a' with duration 16. +#### Python3 + ```python class Solution: def slowestKey(self, releaseTimes: List[int], keysPressed: str) -> str: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public char slowestKey(int[] releaseTimes, String keysPressed) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func slowestKey(releaseTimes []int, keysPressed string) byte { ans := keysPressed[0] diff --git a/solution/1600-1699/1630.Arithmetic Subarrays/README.md b/solution/1600-1699/1630.Arithmetic Subarrays/README.md index 889df72d3c75b..c58db72f69ba5 100644 --- a/solution/1600-1699/1630.Arithmetic Subarrays/README.md +++ b/solution/1600-1699/1630.Arithmetic Subarrays/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def checkArithmeticSubarrays( @@ -104,6 +106,8 @@ class Solution: return [check(nums, left, right) for left, right in zip(l, r)] ``` +#### Java + ```java class Solution { public List checkArithmeticSubarrays(int[] nums, int[] l, int[] r) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go func checkArithmeticSubarrays(nums []int, l []int, r []int) (ans []bool) { check := func(nums []int, l, r int) bool { @@ -203,6 +211,8 @@ func checkArithmeticSubarrays(nums []int, l []int, r []int) (ans []bool) { } ``` +#### TypeScript + ```ts function checkArithmeticSubarrays(nums: number[], l: number[], r: number[]): boolean[] { const check = (nums: number[], l: number, r: number): boolean => { @@ -234,6 +244,8 @@ function checkArithmeticSubarrays(nums: number[], l: number[], r: number[]): boo } ``` +#### Rust + ```rust impl Solution { pub fn check_arithmetic_subarrays(nums: Vec, l: Vec, r: Vec) -> Vec { @@ -254,6 +266,8 @@ impl Solution { } ``` +#### C# + ```cs class Solution { public bool Check(int[] arr) { diff --git a/solution/1600-1699/1630.Arithmetic Subarrays/README_EN.md b/solution/1600-1699/1630.Arithmetic Subarrays/README_EN.md index 2df1f2de69574..745eb9f5461c3 100644 --- a/solution/1600-1699/1630.Arithmetic Subarrays/README_EN.md +++ b/solution/1600-1699/1630.Arithmetic Subarrays/README_EN.md @@ -79,6 +79,8 @@ In the 2nd query, the subarray is [5,9,3,7]. This can be +#### Python3 + ```python class Solution: def checkArithmeticSubarrays( @@ -94,6 +96,8 @@ class Solution: return [check(nums, left, right) for left, right in zip(l, r)] ``` +#### Java + ```java class Solution { public List checkArithmeticSubarrays(int[] nums, int[] l, int[] r) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func checkArithmeticSubarrays(nums []int, l []int, r []int) (ans []bool) { check := func(nums []int, l, r int) bool { @@ -193,6 +201,8 @@ func checkArithmeticSubarrays(nums []int, l []int, r []int) (ans []bool) { } ``` +#### TypeScript + ```ts function checkArithmeticSubarrays(nums: number[], l: number[], r: number[]): boolean[] { const check = (nums: number[], l: number, r: number): boolean => { @@ -224,6 +234,8 @@ function checkArithmeticSubarrays(nums: number[], l: number[], r: number[]): boo } ``` +#### Rust + ```rust impl Solution { pub fn check_arithmetic_subarrays(nums: Vec, l: Vec, r: Vec) -> Vec { @@ -244,6 +256,8 @@ impl Solution { } ``` +#### C# + ```cs class Solution { public bool Check(int[] arr) { diff --git a/solution/1600-1699/1631.Path With Minimum Effort/README.md b/solution/1600-1699/1631.Path With Minimum Effort/README.md index 09a9f19ca20d1..efa0ea6cf551d 100644 --- a/solution/1600-1699/1631.Path With Minimum Effort/README.md +++ b/solution/1600-1699/1631.Path With Minimum Effort/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class UnionFind: def __init__(self, n): @@ -137,6 +139,8 @@ class Solution: return 0 ``` +#### Java + ```java class UnionFind { private final int[] p; @@ -207,6 +211,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -275,6 +281,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p, size []int @@ -349,6 +357,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts class UnionFind { private p: number[]; @@ -436,6 +446,8 @@ function minimumEffortPath(heights: number[][]): number { +#### Python3 + ```python class Solution: def minimumEffortPath(self, heights: List[List[int]]) -> int: @@ -464,6 +476,8 @@ class Solution: return bisect_left(range(10**6), True, key=check) ``` +#### Java + ```java class Solution { public int minimumEffortPath(int[][] heights) { @@ -506,6 +520,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -547,6 +563,8 @@ public: }; ``` +#### Go + ```go func minimumEffortPath(heights [][]int) int { return sort.Search(1e6, func(h int) bool { @@ -586,6 +604,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function minimumEffortPath(heights: number[][]): number { const check = (h: number): boolean => { @@ -652,6 +672,8 @@ function minimumEffortPath(heights: number[][]): number { +#### Python3 + ```python class Solution: def minimumEffortPath(self, heights: List[List[int]]) -> int: @@ -674,6 +696,8 @@ class Solution: return int(dist[-1][-1]) ``` +#### Java + ```java class Solution { public int minimumEffortPath(int[][] heights) { @@ -705,6 +729,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -737,6 +763,8 @@ public: }; ``` +#### Go + ```go func minimumEffortPath(heights [][]int) int { m, n := len(heights), len(heights[0]) @@ -784,6 +812,8 @@ func (h *hp) Push(v any) { *h = append(*h, v.(tuple)) } func (h *hp) Pop() any { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; return v } ``` +#### TypeScript + ```ts function minimumEffortPath(heights: number[][]): number { const m = heights.length; diff --git a/solution/1600-1699/1631.Path With Minimum Effort/README_EN.md b/solution/1600-1699/1631.Path With Minimum Effort/README_EN.md index bc8cd407965ed..6fd62de6215fe 100644 --- a/solution/1600-1699/1631.Path With Minimum Effort/README_EN.md +++ b/solution/1600-1699/1631.Path With Minimum Effort/README_EN.md @@ -108,6 +108,8 @@ The time complexity is $O(m \times n \times \log(m \times n))$, and the space co +#### Python3 + ```python class UnionFind: def __init__(self, n): @@ -157,6 +159,8 @@ class Solution: return 0 ``` +#### Java + ```java class UnionFind { private final int[] p; @@ -227,6 +231,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -295,6 +301,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p, size []int @@ -369,6 +377,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts class UnionFind { private p: number[]; @@ -456,6 +466,8 @@ The time complexity is $O(m \times n \times \log M)$, and the space complexity i +#### Python3 + ```python class Solution: def minimumEffortPath(self, heights: List[List[int]]) -> int: @@ -484,6 +496,8 @@ class Solution: return bisect_left(range(10**6), True, key=check) ``` +#### Java + ```java class Solution { public int minimumEffortPath(int[][] heights) { @@ -526,6 +540,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -567,6 +583,8 @@ public: }; ``` +#### Go + ```go func minimumEffortPath(heights [][]int) int { return sort.Search(1e6, func(h int) bool { @@ -606,6 +624,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function minimumEffortPath(heights: number[][]): number { const check = (h: number): boolean => { @@ -672,6 +692,8 @@ The time complexity is $O(m \times n \times \log(m \times n))$, and the space co +#### Python3 + ```python class Solution: def minimumEffortPath(self, heights: List[List[int]]) -> int: @@ -694,6 +716,8 @@ class Solution: return int(dist[-1][-1]) ``` +#### Java + ```java class Solution { public int minimumEffortPath(int[][] heights) { @@ -725,6 +749,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -757,6 +783,8 @@ public: }; ``` +#### Go + ```go func minimumEffortPath(heights [][]int) int { m, n := len(heights), len(heights[0]) @@ -804,6 +832,8 @@ func (h *hp) Push(v any) { *h = append(*h, v.(tuple)) } func (h *hp) Pop() any { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; return v } ``` +#### TypeScript + ```ts function minimumEffortPath(heights: number[][]): number { const m = heights.length; diff --git a/solution/1600-1699/1632.Rank Transform of a Matrix/README.md b/solution/1600-1699/1632.Rank Transform of a Matrix/README.md index 98da956ce6232..8ee18ba8b8208 100644 --- a/solution/1600-1699/1632.Rank Transform of a Matrix/README.md +++ b/solution/1600-1699/1632.Rank Transform of a Matrix/README.md @@ -105,6 +105,8 @@ matrix[1][1] 的秩为 3 ,因为 matrix[1][1] > matrix[0][1], matrix[1][1] > +#### Python3 + ```python class UnionFind: def __init__(self, n): @@ -156,6 +158,8 @@ class Solution: return ans ``` +#### Java + ```java class UnionFind { private int[] p; @@ -234,6 +238,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -307,6 +313,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p, size []int diff --git a/solution/1600-1699/1632.Rank Transform of a Matrix/README_EN.md b/solution/1600-1699/1632.Rank Transform of a Matrix/README_EN.md index 8b6c2bd0e4365..10b47ea017e34 100644 --- a/solution/1600-1699/1632.Rank Transform of a Matrix/README_EN.md +++ b/solution/1600-1699/1632.Rank Transform of a Matrix/README_EN.md @@ -88,6 +88,8 @@ The rank of matrix[1][1] is 3 because matrix[1][1] > matrix[0][1], matrix[1][ +#### Python3 + ```python class UnionFind: def __init__(self, n): @@ -139,6 +141,8 @@ class Solution: return ans ``` +#### Java + ```java class UnionFind { private int[] p; @@ -217,6 +221,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -290,6 +296,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p, size []int diff --git a/solution/1600-1699/1633.Percentage of Users Attended a Contest/README.md b/solution/1600-1699/1633.Percentage of Users Attended a Contest/README.md index 187cd6d942595..11b032d45010f 100644 --- a/solution/1600-1699/1633.Percentage of Users Attended a Contest/README.md +++ b/solution/1600-1699/1633.Percentage of Users Attended a Contest/README.md @@ -109,6 +109,8 @@ Bob 注册了 207 赛事,注册率为 ((1/3) * 100) = 33.33% +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1600-1699/1633.Percentage of Users Attended a Contest/README_EN.md b/solution/1600-1699/1633.Percentage of Users Attended a Contest/README_EN.md index cccd1cd722abf..4fcef3f5b9588 100644 --- a/solution/1600-1699/1633.Percentage of Users Attended a Contest/README_EN.md +++ b/solution/1600-1699/1633.Percentage of Users Attended a Contest/README_EN.md @@ -110,6 +110,8 @@ We can group the `Register` table by `contest_id` and count the number of regist +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1600-1699/1634.Add Two Polynomials Represented as Linked Lists/README.md b/solution/1600-1699/1634.Add Two Polynomials Represented as Linked Lists/README.md index 8852ec41aeb32..4f0048b8e3e8a 100644 --- a/solution/1600-1699/1634.Add Two Polynomials Represented as Linked Lists/README.md +++ b/solution/1600-1699/1634.Add Two Polynomials Represented as Linked Lists/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python # Definition for polynomial singly-linked list. # class PolyNode: @@ -127,6 +129,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for polynomial singly-linked list. @@ -175,6 +179,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for polynomial singly-linked list-> @@ -222,6 +228,8 @@ public: }; ``` +#### JavaScript + ```js /** * Definition for polynomial singly-linked list. @@ -264,6 +272,8 @@ var addPoly = function (poly1, poly2) { }; ``` +#### C# + ```cs /** * Definition for polynomial singly-linked list. diff --git a/solution/1600-1699/1634.Add Two Polynomials Represented as Linked Lists/README_EN.md b/solution/1600-1699/1634.Add Two Polynomials Represented as Linked Lists/README_EN.md index cdcdfea714b60..107929af544fa 100644 --- a/solution/1600-1699/1634.Add Two Polynomials Represented as Linked Lists/README_EN.md +++ b/solution/1600-1699/1634.Add Two Polynomials Represented as Linked Lists/README_EN.md @@ -112,6 +112,8 @@ tags: +#### Python3 + ```python # Definition for polynomial singly-linked list. # class PolyNode: @@ -143,6 +145,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for polynomial singly-linked list. @@ -191,6 +195,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for polynomial singly-linked list-> @@ -238,6 +244,8 @@ public: }; ``` +#### JavaScript + ```js /** * Definition for polynomial singly-linked list. @@ -280,6 +288,8 @@ var addPoly = function (poly1, poly2) { }; ``` +#### C# + ```cs /** * Definition for polynomial singly-linked list. diff --git a/solution/1600-1699/1635.Hopper Company Queries I/README.md b/solution/1600-1699/1635.Hopper Company Queries I/README.md index 1ea0b8e759947..856eb172b2b5e 100644 --- a/solution/1600-1699/1635.Hopper Company Queries I/README.md +++ b/solution/1600-1699/1635.Hopper Company Queries I/README.md @@ -172,6 +172,8 @@ ride_id 是该表的主键(具有唯一值的列)。 +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1600-1699/1635.Hopper Company Queries I/README_EN.md b/solution/1600-1699/1635.Hopper Company Queries I/README_EN.md index 60efb70f1a5e6..4eafa058a808d 100644 --- a/solution/1600-1699/1635.Hopper Company Queries I/README_EN.md +++ b/solution/1600-1699/1635.Hopper Company Queries I/README_EN.md @@ -172,6 +172,8 @@ By the end of December --> six active drivers (10, 8, 5, 7, 4, 1) and one acc +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1600-1699/1636.Sort Array by Increasing Frequency/README.md b/solution/1600-1699/1636.Sort Array by Increasing Frequency/README.md index f0eee8a5ebb9c..cdeda872581a1 100644 --- a/solution/1600-1699/1636.Sort Array by Increasing Frequency/README.md +++ b/solution/1600-1699/1636.Sort Array by Increasing Frequency/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def frequencySort(self, nums: List[int]) -> List[int]: @@ -77,6 +79,8 @@ class Solution: return sorted(nums, key=lambda x: (cnt[x], -x)) ``` +#### Java + ```java class Solution { public int[] frequencySort(int[] nums) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func frequencySort(nums []int) []int { cnt := make([]int, 201) @@ -129,6 +137,8 @@ func frequencySort(nums []int) []int { } ``` +#### TypeScript + ```ts function frequencySort(nums: number[]): number[] { const map = new Map(); @@ -139,6 +149,8 @@ function frequencySort(nums: number[]): number[] { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { @@ -159,6 +171,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/1600-1699/1636.Sort Array by Increasing Frequency/README_EN.md b/solution/1600-1699/1636.Sort Array by Increasing Frequency/README_EN.md index ea216e02a82a1..278eb82c5bb04 100644 --- a/solution/1600-1699/1636.Sort Array by Increasing Frequency/README_EN.md +++ b/solution/1600-1699/1636.Sort Array by Increasing Frequency/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def frequencySort(self, nums: List[int]) -> List[int]: @@ -72,6 +74,8 @@ class Solution: return sorted(nums, key=lambda x: (cnt[x], -x)) ``` +#### Java + ```java class Solution { public int[] frequencySort(int[] nums) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func frequencySort(nums []int) []int { cnt := make([]int, 201) @@ -124,6 +132,8 @@ func frequencySort(nums []int) []int { } ``` +#### TypeScript + ```ts function frequencySort(nums: number[]): number[] { const map = new Map(); @@ -134,6 +144,8 @@ function frequencySort(nums: number[]): number[] { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { @@ -154,6 +166,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/1600-1699/1637.Widest Vertical Area Between Two Points Containing No Points/README.md b/solution/1600-1699/1637.Widest Vertical Area Between Two Points Containing No Points/README.md index dcc52de9461d7..18b3db0944493 100644 --- a/solution/1600-1699/1637.Widest Vertical Area Between Two Points Containing No Points/README.md +++ b/solution/1600-1699/1637.Widest Vertical Area Between Two Points Containing No Points/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int: @@ -74,6 +76,8 @@ class Solution: return max(b[0] - a[0] for a, b in pairwise(points)) ``` +#### Java + ```java class Solution { public int maxWidthOfVerticalArea(int[][] points) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,6 +107,8 @@ public: }; ``` +#### Go + ```go func maxWidthOfVerticalArea(points [][]int) (ans int) { sort.Slice(points, func(i, j int) bool { return points[i][0] < points[j][0] }) @@ -111,6 +119,8 @@ func maxWidthOfVerticalArea(points [][]int) (ans int) { } ``` +#### TypeScript + ```ts function maxWidthOfVerticalArea(points: number[][]): number { points.sort((a, b) => a[0] - b[0]); @@ -122,6 +132,8 @@ function maxWidthOfVerticalArea(points: number[][]): number { } ``` +#### JavaScript + ```js /** * @param {number[][]} points @@ -169,6 +181,8 @@ $$ +#### Python3 + ```python class Solution: def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int: @@ -192,6 +206,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxWidthOfVerticalArea(int[][] points) { @@ -232,6 +248,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -267,6 +285,8 @@ public: }; ``` +#### Go + ```go func maxWidthOfVerticalArea(points [][]int) (ans int) { n := len(points) @@ -303,6 +323,8 @@ func maxWidthOfVerticalArea(points [][]int) (ans int) { } ``` +#### TypeScript + ```ts function maxWidthOfVerticalArea(points: number[][]): number { const nums: number[] = points.map(point => point[0]); @@ -335,6 +357,8 @@ function maxWidthOfVerticalArea(points: number[][]): number { } ``` +#### JavaScript + ```js /** * @param {number[][]} points diff --git a/solution/1600-1699/1637.Widest Vertical Area Between Two Points Containing No Points/README_EN.md b/solution/1600-1699/1637.Widest Vertical Area Between Two Points Containing No Points/README_EN.md index 2b37905053f01..b2ce666abb645 100644 --- a/solution/1600-1699/1637.Widest Vertical Area Between Two Points Containing No Points/README_EN.md +++ b/solution/1600-1699/1637.Widest Vertical Area Between Two Points Containing No Points/README_EN.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int: @@ -68,6 +70,8 @@ class Solution: return max(b[0] - a[0] for a, b in pairwise(points)) ``` +#### Java + ```java class Solution { public int maxWidthOfVerticalArea(int[][] points) { @@ -81,6 +85,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -95,6 +101,8 @@ public: }; ``` +#### Go + ```go func maxWidthOfVerticalArea(points [][]int) (ans int) { sort.Slice(points, func(i, j int) bool { return points[i][0] < points[j][0] }) @@ -105,6 +113,8 @@ func maxWidthOfVerticalArea(points [][]int) (ans int) { } ``` +#### TypeScript + ```ts function maxWidthOfVerticalArea(points: number[][]): number { points.sort((a, b) => a[0] - b[0]); @@ -116,6 +126,8 @@ function maxWidthOfVerticalArea(points: number[][]): number { } ``` +#### JavaScript + ```js /** * @param {number[][]} points @@ -143,6 +155,8 @@ var maxWidthOfVerticalArea = function (points) { +#### Python3 + ```python class Solution: def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int: @@ -166,6 +180,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxWidthOfVerticalArea(int[][] points) { @@ -206,6 +222,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -241,6 +259,8 @@ public: }; ``` +#### Go + ```go func maxWidthOfVerticalArea(points [][]int) (ans int) { n := len(points) @@ -277,6 +297,8 @@ func maxWidthOfVerticalArea(points [][]int) (ans int) { } ``` +#### TypeScript + ```ts function maxWidthOfVerticalArea(points: number[][]): number { const nums: number[] = points.map(point => point[0]); @@ -309,6 +331,8 @@ function maxWidthOfVerticalArea(points: number[][]): number { } ``` +#### JavaScript + ```js /** * @param {number[][]} points diff --git a/solution/1600-1699/1638.Count Substrings That Differ by One Character/README.md b/solution/1600-1699/1638.Count Substrings That Differ by One Character/README.md index a34b23d7c57db..ea2ad082ae243 100644 --- a/solution/1600-1699/1638.Count Substrings That Differ by One Character/README.md +++ b/solution/1600-1699/1638.Count Substrings That Differ by One Character/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class Solution: def countSubstrings(self, s: str, t: str) -> int: @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countSubstrings(String s, String t) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func countSubstrings(s string, t string) (ans int) { m, n := len(s), len(t) @@ -202,6 +210,8 @@ func countSubstrings(s string, t string) (ans int) { +#### Python3 + ```python class Solution: def countSubstrings(self, s: str, t: str) -> int: @@ -222,6 +232,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countSubstrings(String s, String t) { @@ -250,6 +262,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -281,6 +295,8 @@ public: }; ``` +#### Go + ```go func countSubstrings(s string, t string) (ans int) { m, n := len(s), len(t) diff --git a/solution/1600-1699/1638.Count Substrings That Differ by One Character/README_EN.md b/solution/1600-1699/1638.Count Substrings That Differ by One Character/README_EN.md index 1b5a31d993c85..a5f65c97d2e07 100644 --- a/solution/1600-1699/1638.Count Substrings That Differ by One Character/README_EN.md +++ b/solution/1600-1699/1638.Count Substrings That Differ by One Character/README_EN.md @@ -74,6 +74,8 @@ The underlined portions are the substrings that are chosen from s and t. +#### Python3 + ```python class Solution: def countSubstrings(self, s: str, t: str) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countSubstrings(String s, String t) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func countSubstrings(s string, t string) (ans int) { m, n := len(s), len(t) @@ -174,6 +182,8 @@ func countSubstrings(s string, t string) (ans int) { +#### Python3 + ```python class Solution: def countSubstrings(self, s: str, t: str) -> int: @@ -194,6 +204,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countSubstrings(String s, String t) { @@ -222,6 +234,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -253,6 +267,8 @@ public: }; ``` +#### Go + ```go func countSubstrings(s string, t string) (ans int) { m, n := len(s), len(t) diff --git a/solution/1600-1699/1639.Number of Ways to Form a Target String Given a Dictionary/README.md b/solution/1600-1699/1639.Number of Ways to Form a Target String Given a Dictionary/README.md index 0cdd80312cc03..41dbc20af648f 100644 --- a/solution/1600-1699/1639.Number of Ways to Form a Target String Given a Dictionary/README.md +++ b/solution/1600-1699/1639.Number of Ways to Form a Target String Given a Dictionary/README.md @@ -115,6 +115,8 @@ tags: +#### Python3 + ```python class Solution: def numWays(self, words: List[str], target: str) -> int: @@ -137,6 +139,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private int m; @@ -178,6 +182,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -211,6 +217,8 @@ public: }; ``` +#### Go + ```go func numWays(words []string, target string) int { m, n := len(target), len(words[0]) @@ -248,6 +256,8 @@ func numWays(words []string, target string) int { } ``` +#### TypeScript + ```ts function numWays(words: string[], target: string): number { const m = target.length; @@ -293,6 +303,8 @@ function numWays(words: string[], target: string): number { +#### Python3 + ```python class Solution: def numWays(self, words: List[str], target: str) -> int: @@ -314,6 +326,8 @@ class Solution: return f[m][n] ``` +#### Java + ```java class Solution { public int numWays(String[] words, String target) { @@ -339,6 +353,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -365,6 +381,8 @@ public: }; ``` +#### Go + ```go func numWays(words []string, target string) int { const mod = 1e9 + 7 diff --git a/solution/1600-1699/1639.Number of Ways to Form a Target String Given a Dictionary/README_EN.md b/solution/1600-1699/1639.Number of Ways to Form a Target String Given a Dictionary/README_EN.md index 024d037ec8331..ecb599d7eb956 100644 --- a/solution/1600-1699/1639.Number of Ways to Form a Target String Given a Dictionary/README_EN.md +++ b/solution/1600-1699/1639.Number of Ways to Form a Target String Given a Dictionary/README_EN.md @@ -97,6 +97,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def numWays(self, words: List[str], target: str) -> int: @@ -119,6 +121,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private int m; @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go func numWays(words []string, target string) int { m, n := len(target), len(words[0]) @@ -230,6 +238,8 @@ func numWays(words []string, target string) int { } ``` +#### TypeScript + ```ts function numWays(words: string[], target: string): number { const m = target.length; @@ -275,6 +285,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def numWays(self, words: List[str], target: str) -> int: @@ -296,6 +308,8 @@ class Solution: return f[m][n] ``` +#### Java + ```java class Solution { public int numWays(String[] words, String target) { @@ -321,6 +335,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -347,6 +363,8 @@ public: }; ``` +#### Go + ```go func numWays(words []string, target string) int { const mod = 1e9 + 7 diff --git a/solution/1600-1699/1640.Check Array Formation Through Concatenation/README.md b/solution/1600-1699/1640.Check Array Formation Through Concatenation/README.md index ba09be78263b0..909077debb3e4 100644 --- a/solution/1600-1699/1640.Check Array Formation Through Concatenation/README.md +++ b/solution/1600-1699/1640.Check Array Formation Through Concatenation/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool: @@ -93,6 +95,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean canFormArray(int[] arr, int[][] pieces) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func canFormArray(arr []int, pieces [][]int) bool { for i := 0; i < len(arr); { @@ -157,6 +165,8 @@ func canFormArray(arr []int, pieces [][]int) bool { } ``` +#### TypeScript + ```ts function canFormArray(arr: number[], pieces: number[][]): boolean { const n = arr.length; @@ -178,6 +188,8 @@ function canFormArray(arr: number[], pieces: number[][]): boolean { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { @@ -208,6 +220,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} arr @@ -252,6 +266,8 @@ var canFormArray = function (arr, pieces) { +#### Python3 + ```python class Solution: def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool: @@ -267,6 +283,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean canFormArray(int[] arr, int[][] pieces) { @@ -289,6 +307,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -312,6 +332,8 @@ public: }; ``` +#### Go + ```go func canFormArray(arr []int, pieces [][]int) bool { d := map[int][]int{} diff --git a/solution/1600-1699/1640.Check Array Formation Through Concatenation/README_EN.md b/solution/1600-1699/1640.Check Array Formation Through Concatenation/README_EN.md index 96d9dc6ba0cae..4ad16f2b36a4d 100644 --- a/solution/1600-1699/1640.Check Array Formation Through Concatenation/README_EN.md +++ b/solution/1600-1699/1640.Check Array Formation Through Concatenation/README_EN.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool: @@ -86,6 +88,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean canFormArray(int[] arr, int[][] pieces) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func canFormArray(arr []int, pieces [][]int) bool { for i := 0; i < len(arr); { @@ -150,6 +158,8 @@ func canFormArray(arr []int, pieces [][]int) bool { } ``` +#### TypeScript + ```ts function canFormArray(arr: number[], pieces: number[][]): boolean { const n = arr.length; @@ -171,6 +181,8 @@ function canFormArray(arr: number[], pieces: number[][]): boolean { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { @@ -201,6 +213,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} arr @@ -237,6 +251,8 @@ var canFormArray = function (arr, pieces) { +#### Python3 + ```python class Solution: def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool: @@ -252,6 +268,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean canFormArray(int[] arr, int[][] pieces) { @@ -274,6 +292,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -297,6 +317,8 @@ public: }; ``` +#### Go + ```go func canFormArray(arr []int, pieces [][]int) bool { d := map[int][]int{} diff --git a/solution/1600-1699/1641.Count Sorted Vowel Strings/README.md b/solution/1600-1699/1641.Count Sorted Vowel Strings/README.md index a96e7ac2e26a0..f5f99638a490b 100644 --- a/solution/1600-1699/1641.Count Sorted Vowel Strings/README.md +++ b/solution/1600-1699/1641.Count Sorted Vowel Strings/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def countVowelStrings(self, n: int) -> int: @@ -90,6 +92,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private Integer[][] f; @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func countVowelStrings(n int) int { f := make([][5]int, n) @@ -179,6 +187,8 @@ func countVowelStrings(n int) int { +#### Python3 + ```python class Solution: def countVowelStrings(self, n: int) -> int: @@ -191,6 +201,8 @@ class Solution: return sum(f) ``` +#### Java + ```java class Solution { public int countVowelStrings(int n) { @@ -207,6 +219,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -224,6 +238,8 @@ public: }; ``` +#### Go + ```go func countVowelStrings(n int) (ans int) { f := [5]int{1, 1, 1, 1, 1} diff --git a/solution/1600-1699/1641.Count Sorted Vowel Strings/README_EN.md b/solution/1600-1699/1641.Count Sorted Vowel Strings/README_EN.md index d7f29821c3fe7..a8867a6687fef 100644 --- a/solution/1600-1699/1641.Count Sorted Vowel Strings/README_EN.md +++ b/solution/1600-1699/1641.Count Sorted Vowel Strings/README_EN.md @@ -67,6 +67,8 @@ Note that "ea" is not a valid string since 'e' comes after  +#### Python3 + ```python class Solution: def countVowelStrings(self, n: int) -> int: @@ -77,6 +79,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private Integer[][] f; @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func countVowelStrings(n int) int { f := make([][5]int, n) @@ -160,6 +168,8 @@ func countVowelStrings(n int) int { +#### Python3 + ```python class Solution: def countVowelStrings(self, n: int) -> int: @@ -172,6 +182,8 @@ class Solution: return sum(f) ``` +#### Java + ```java class Solution { public int countVowelStrings(int n) { @@ -188,6 +200,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -205,6 +219,8 @@ public: }; ``` +#### Go + ```go func countVowelStrings(n int) (ans int) { f := [5]int{1, 1, 1, 1, 1} diff --git a/solution/1600-1699/1642.Furthest Building You Can Reach/README.md b/solution/1600-1699/1642.Furthest Building You Can Reach/README.md index 7abe782a6fe2d..f4fa8bdb1ec99 100644 --- a/solution/1600-1699/1642.Furthest Building You Can Reach/README.md +++ b/solution/1600-1699/1642.Furthest Building You Can Reach/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def furthestBuilding(self, heights: List[int], bricks: int, ladders: int) -> int: @@ -102,6 +104,8 @@ class Solution: return len(heights) - 1 ``` +#### Java + ```java class Solution { public int furthestBuilding(int[] heights, int bricks, int ladders) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func furthestBuilding(heights []int, bricks int, ladders int) int { q := hp{} diff --git a/solution/1600-1699/1642.Furthest Building You Can Reach/README_EN.md b/solution/1600-1699/1642.Furthest Building You Can Reach/README_EN.md index 1db6757cfee85..ed2f4bcd9b7f0 100644 --- a/solution/1600-1699/1642.Furthest Building You Can Reach/README_EN.md +++ b/solution/1600-1699/1642.Furthest Building You Can Reach/README_EN.md @@ -81,6 +81,8 @@ It is impossible to go beyond building 4 because you do not have any more bricks +#### Python3 + ```python class Solution: def furthestBuilding(self, heights: List[int], bricks: int, ladders: int) -> int: @@ -97,6 +99,8 @@ class Solution: return len(heights) - 1 ``` +#### Java + ```java class Solution { public int furthestBuilding(int[] heights, int bricks, int ladders) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func furthestBuilding(heights []int, bricks int, ladders int) int { q := hp{} diff --git a/solution/1600-1699/1643.Kth Smallest Instructions/README.md b/solution/1600-1699/1643.Kth Smallest Instructions/README.md index d333582afc34f..06c1ccd5d4fdd 100644 --- a/solution/1600-1699/1643.Kth Smallest Instructions/README.md +++ b/solution/1600-1699/1643.Kth Smallest Instructions/README.md @@ -102,6 +102,8 @@ tags: +#### Python3 + ```python class Solution: def kthSmallestPath(self, destination: List[int], k: int) -> str: @@ -122,6 +124,8 @@ class Solution: return "".join(ans) ``` +#### Java + ```java class Solution { public String kthSmallestPath(int[] destination, int k) { @@ -156,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -192,6 +198,8 @@ public: }; ``` +#### Go + ```go func kthSmallestPath(destination []int, k int) string { v, h := destination[0], destination[1] diff --git a/solution/1600-1699/1643.Kth Smallest Instructions/README_EN.md b/solution/1600-1699/1643.Kth Smallest Instructions/README_EN.md index 5e08439a29755..d3ab992bfd1d1 100644 --- a/solution/1600-1699/1643.Kth Smallest Instructions/README_EN.md +++ b/solution/1600-1699/1643.Kth Smallest Instructions/README_EN.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def kthSmallestPath(self, destination: List[int], k: int) -> str: @@ -105,6 +107,8 @@ class Solution: return "".join(ans) ``` +#### Java + ```java class Solution { public String kthSmallestPath(int[] destination, int k) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go func kthSmallestPath(destination []int, k int) string { v, h := destination[0], destination[1] diff --git a/solution/1600-1699/1644.Lowest Common Ancestor of a Binary Tree II/README.md b/solution/1600-1699/1644.Lowest Common Ancestor of a Binary Tree II/README.md index 7ce45dfbd2cf9..68ab20d60954e 100644 --- a/solution/1600-1699/1644.Lowest Common Ancestor of a Binary Tree II/README.md +++ b/solution/1600-1699/1644.Lowest Common Ancestor of a Binary Tree II/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -121,6 +123,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -156,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -193,6 +199,8 @@ private: }; ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/1600-1699/1644.Lowest Common Ancestor of a Binary Tree II/README_EN.md b/solution/1600-1699/1644.Lowest Common Ancestor of a Binary Tree II/README_EN.md index 37041fd736139..f65335b121633 100644 --- a/solution/1600-1699/1644.Lowest Common Ancestor of a Binary Tree II/README_EN.md +++ b/solution/1600-1699/1644.Lowest Common Ancestor of a Binary Tree II/README_EN.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -174,6 +180,8 @@ private: }; ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/1600-1699/1645.Hopper Company Queries II/README.md b/solution/1600-1699/1645.Hopper Company Queries II/README.md index 8b4d27d32caf4..6c8f6c4717934 100644 --- a/solution/1600-1699/1645.Hopper Company Queries II/README.md +++ b/solution/1600-1699/1645.Hopper Company Queries II/README.md @@ -181,6 +181,8 @@ ride_id 是该表具有唯一值的列。 +#### MySQL + ```sql # Write your MySQL query statement below WITH RECURSIVE diff --git a/solution/1600-1699/1645.Hopper Company Queries II/README_EN.md b/solution/1600-1699/1645.Hopper Company Queries II/README_EN.md index cda24a0e701d8..83d4ea369a8d3 100644 --- a/solution/1600-1699/1645.Hopper Company Queries II/README_EN.md +++ b/solution/1600-1699/1645.Hopper Company Queries II/README_EN.md @@ -169,6 +169,8 @@ By the end of December --> six active drivers (10, 8, 5, 7, 4, 1) and one acc +#### MySQL + ```sql # Write your MySQL query statement below WITH RECURSIVE diff --git a/solution/1600-1699/1646.Get Maximum in Generated Array/README.md b/solution/1600-1699/1646.Get Maximum in Generated Array/README.md index 928341981ec2f..5643e32812798 100644 --- a/solution/1600-1699/1646.Get Maximum in Generated Array/README.md +++ b/solution/1600-1699/1646.Get Maximum in Generated Array/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def getMaximumGenerated(self, n: int) -> int: @@ -105,6 +107,8 @@ class Solution: return max(nums) ``` +#### Java + ```java class Solution { public int getMaximumGenerated(int n) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func getMaximumGenerated(n int) int { if n < 2 { @@ -157,6 +165,8 @@ func getMaximumGenerated(n int) int { } ``` +#### TypeScript + ```ts function getMaximumGenerated(n: number): number { if (n === 0) { diff --git a/solution/1600-1699/1646.Get Maximum in Generated Array/README_EN.md b/solution/1600-1699/1646.Get Maximum in Generated Array/README_EN.md index d18d113c9e00e..39ea7fdd13765 100644 --- a/solution/1600-1699/1646.Get Maximum in Generated Array/README_EN.md +++ b/solution/1600-1699/1646.Get Maximum in Generated Array/README_EN.md @@ -81,6 +81,8 @@ Hence, nums = [0,1,1,2,1,3,2,3], and the maximum is max(0,1,1,2,1,3,2,3) = 3. +#### Python3 + ```python class Solution: def getMaximumGenerated(self, n: int) -> int: @@ -93,6 +95,8 @@ class Solution: return max(nums) ``` +#### Java + ```java class Solution { public int getMaximumGenerated(int n) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func getMaximumGenerated(n int) int { if n < 2 { @@ -145,6 +153,8 @@ func getMaximumGenerated(n int) int { } ``` +#### TypeScript + ```ts function getMaximumGenerated(n: number): number { if (n === 0) { diff --git a/solution/1600-1699/1647.Minimum Deletions to Make Character Frequencies Unique/README.md b/solution/1600-1699/1647.Minimum Deletions to Make Character Frequencies Unique/README.md index 874df643578a1..32e1f74139c2a 100644 --- a/solution/1600-1699/1647.Minimum Deletions to Make Character Frequencies Unique/README.md +++ b/solution/1600-1699/1647.Minimum Deletions to Make Character Frequencies Unique/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def minDeletions(self, s: str) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minDeletions(String s) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func minDeletions(s string) (ans int) { cnt := make([]int, 26) @@ -155,6 +163,8 @@ func minDeletions(s string) (ans int) { } ``` +#### TypeScript + ```ts function minDeletions(s: string): number { let map = {}; @@ -174,6 +184,8 @@ function minDeletions(s: string): number { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -209,6 +221,8 @@ impl Solution { +#### Python3 + ```python class Solution: def minDeletions(self, s: str) -> int: @@ -222,6 +236,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minDeletions(String s) { @@ -247,6 +263,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -270,6 +288,8 @@ public: }; ``` +#### Go + ```go func minDeletions(s string) (ans int) { cnt := make([]int, 26) diff --git a/solution/1600-1699/1647.Minimum Deletions to Make Character Frequencies Unique/README_EN.md b/solution/1600-1699/1647.Minimum Deletions to Make Character Frequencies Unique/README_EN.md index d82c798c4515e..60e1fb3cf3dcb 100644 --- a/solution/1600-1699/1647.Minimum Deletions to Make Character Frequencies Unique/README_EN.md +++ b/solution/1600-1699/1647.Minimum Deletions to Make Character Frequencies Unique/README_EN.md @@ -71,6 +71,8 @@ Note that we only care about characters that are still in the string at the end +#### Python3 + ```python class Solution: def minDeletions(self, s: str) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minDeletions(String s) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func minDeletions(s string) (ans int) { cnt := make([]int, 26) @@ -143,6 +151,8 @@ func minDeletions(s string) (ans int) { } ``` +#### TypeScript + ```ts function minDeletions(s: string): number { let map = {}; @@ -162,6 +172,8 @@ function minDeletions(s: string): number { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -197,6 +209,8 @@ impl Solution { +#### Python3 + ```python class Solution: def minDeletions(self, s: str) -> int: @@ -210,6 +224,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minDeletions(String s) { @@ -235,6 +251,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -258,6 +276,8 @@ public: }; ``` +#### Go + ```go func minDeletions(s string) (ans int) { cnt := make([]int, 26) diff --git a/solution/1600-1699/1648.Sell Diminishing-Valued Colored Balls/README.md b/solution/1600-1699/1648.Sell Diminishing-Valued Colored Balls/README.md index 9afcbf43ace06..5b626dea56f27 100644 --- a/solution/1600-1699/1648.Sell Diminishing-Valued Colored Balls/README.md +++ b/solution/1600-1699/1648.Sell Diminishing-Valued Colored Balls/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def maxProfit(self, inventory: List[int], orders: int) -> int: @@ -122,6 +124,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -162,6 +166,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -195,6 +201,8 @@ public: }; ``` +#### Go + ```go func maxProfit(inventory []int, orders int) int { var mod int = 1e9 + 7 diff --git a/solution/1600-1699/1648.Sell Diminishing-Valued Colored Balls/README_EN.md b/solution/1600-1699/1648.Sell Diminishing-Valued Colored Balls/README_EN.md index 526556bbe69e3..79ba745d63925 100644 --- a/solution/1600-1699/1648.Sell Diminishing-Valued Colored Balls/README_EN.md +++ b/solution/1600-1699/1648.Sell Diminishing-Valued Colored Balls/README_EN.md @@ -69,6 +69,8 @@ The maximum total value is 3 + 2 + 5 + 4 + 3 + 2 = 19. +#### Python3 + ```python class Solution: def maxProfit(self, inventory: List[int], orders: int) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go func maxProfit(inventory []int, orders int) int { var mod int = 1e9 + 7 diff --git a/solution/1600-1699/1649.Create Sorted Array through Instructions/README.md b/solution/1600-1699/1649.Create Sorted Array through Instructions/README.md index f514cdaf5d8ca..1d1e12a3d4877 100644 --- a/solution/1600-1699/1649.Create Sorted Array through Instructions/README.md +++ b/solution/1600-1699/1649.Create Sorted Array through Instructions/README.md @@ -111,6 +111,8 @@ tags: +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -143,6 +145,8 @@ class Solution: return ans % mod ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -190,6 +194,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -236,6 +242,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -276,6 +284,8 @@ func createSortedArray(instructions []int) (ans int) { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; @@ -337,6 +347,8 @@ function createSortedArray(instructions: number[]): number { +#### Python3 + ```python class Node: def __init__(self): @@ -398,6 +410,8 @@ class Solution: return ans % int((1e9 + 7)) ``` +#### Java + ```java class Solution { public int createSortedArray(int[] instructions) { @@ -479,6 +493,8 @@ class SegmentTree { } ``` +#### C++ + ```cpp class Node { public: diff --git a/solution/1600-1699/1649.Create Sorted Array through Instructions/README_EN.md b/solution/1600-1699/1649.Create Sorted Array through Instructions/README_EN.md index 382af52a91aae..d7708d65d82ee 100644 --- a/solution/1600-1699/1649.Create Sorted Array through Instructions/README_EN.md +++ b/solution/1600-1699/1649.Create Sorted Array through Instructions/README_EN.md @@ -140,6 +140,8 @@ The total cost is 0 + 0 + 0 + 0 + 1 + 0 + 1 + 0 + 2 = 4. +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -172,6 +174,8 @@ class Solution: return ans % mod ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -219,6 +223,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -265,6 +271,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -305,6 +313,8 @@ func createSortedArray(instructions []int) (ans int) { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; @@ -357,6 +367,8 @@ function createSortedArray(instructions: number[]): number { +#### Python3 + ```python class Node: def __init__(self): @@ -418,6 +430,8 @@ class Solution: return ans % int((1e9 + 7)) ``` +#### Java + ```java class Solution { public int createSortedArray(int[] instructions) { @@ -499,6 +513,8 @@ class SegmentTree { } ``` +#### C++ + ```cpp class Node { public: diff --git a/solution/1600-1699/1650.Lowest Common Ancestor of a Binary Tree III/README.md b/solution/1600-1699/1650.Lowest Common Ancestor of a Binary Tree III/README.md index 781c4c5168b8f..f2a3c92e614e6 100644 --- a/solution/1600-1699/1650.Lowest Common Ancestor of a Binary Tree III/README.md +++ b/solution/1600-1699/1650.Lowest Common Ancestor of a Binary Tree III/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python """ # Definition for a Node. @@ -106,6 +108,8 @@ class Solution: return node ``` +#### Java + ```java /* // Definition for a Node. @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go /** * Definition for Node. @@ -184,6 +192,8 @@ func lowestCommonAncestor(p *Node, q *Node) *Node { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -228,6 +238,8 @@ function lowestCommonAncestor(p: Node | null, q: Node | null): Node | null { +#### Python3 + ```python """ # Definition for a Node. @@ -249,6 +261,8 @@ class Solution: return a ``` +#### Java + ```java /* // Definition for a Node. @@ -272,6 +286,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -298,6 +314,8 @@ public: }; ``` +#### Go + ```go /** * Definition for Node. @@ -327,6 +345,8 @@ func lowestCommonAncestor(p *Node, q *Node) *Node { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/1600-1699/1650.Lowest Common Ancestor of a Binary Tree III/README_EN.md b/solution/1600-1699/1650.Lowest Common Ancestor of a Binary Tree III/README_EN.md index 3b800b7dea4e4..215e8eb44ebca 100644 --- a/solution/1600-1699/1650.Lowest Common Ancestor of a Binary Tree III/README_EN.md +++ b/solution/1600-1699/1650.Lowest Common Ancestor of a Binary Tree III/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python """ # Definition for a Node. @@ -108,6 +110,8 @@ class Solution: return node ``` +#### Java + ```java /* // Definition for a Node. @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go /** * Definition for Node. @@ -186,6 +194,8 @@ func lowestCommonAncestor(p *Node, q *Node) *Node { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -230,6 +240,8 @@ The time complexity is $O(n)$, where $n$ is the number of nodes in the binary tr +#### Python3 + ```python """ # Definition for a Node. @@ -251,6 +263,8 @@ class Solution: return a ``` +#### Java + ```java /* // Definition for a Node. @@ -274,6 +288,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node. @@ -300,6 +316,8 @@ public: }; ``` +#### Go + ```go /** * Definition for Node. @@ -329,6 +347,8 @@ func lowestCommonAncestor(p *Node, q *Node) *Node { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/1600-1699/1651.Hopper Company Queries III/README.md b/solution/1600-1699/1651.Hopper Company Queries III/README.md index 1bccd0cb78be3..e1c339f0a5640 100644 --- a/solution/1600-1699/1651.Hopper Company Queries III/README.md +++ b/solution/1600-1699/1651.Hopper Company Queries III/README.md @@ -161,6 +161,8 @@ AcceptedRides table: +#### MySQL + ```sql # Write your MySQL query statement below WITH RECURSIVE diff --git a/solution/1600-1699/1651.Hopper Company Queries III/README_EN.md b/solution/1600-1699/1651.Hopper Company Queries III/README_EN.md index 3fc3d2e9bd17d..5e3e1ca9dad1a 100644 --- a/solution/1600-1699/1651.Hopper Company Queries III/README_EN.md +++ b/solution/1600-1699/1651.Hopper Company Queries III/README_EN.md @@ -165,6 +165,8 @@ By the end of October --> average_ride_distance = (0+163+6)/3=56.33, average_ +#### MySQL + ```sql # Write your MySQL query statement below WITH RECURSIVE diff --git a/solution/1600-1699/1652.Defuse the Bomb/README.md b/solution/1600-1699/1652.Defuse the Bomb/README.md index 7c36620f4a971..2732defc622bf 100644 --- a/solution/1600-1699/1652.Defuse the Bomb/README.md +++ b/solution/1600-1699/1652.Defuse the Bomb/README.md @@ -98,6 +98,8 @@ $$ +#### Python3 + ```python class Solution: def decrypt(self, code: List[int], k: int) -> List[int]: @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] decrypt(int[] code, int k) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func decrypt(code []int, k int) []int { n := len(code) @@ -186,6 +194,8 @@ func decrypt(code []int, k int) []int { } ``` +#### TypeScript + ```ts function decrypt(code: number[], k: number): number[] { const n: number = code.length; @@ -231,6 +241,8 @@ function decrypt(code: number[], k: number): number[] { +#### Python3 + ```python class Solution: def decrypt(self, code: List[int], k: int) -> List[int]: @@ -247,6 +259,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] decrypt(int[] code, int k) { @@ -271,6 +285,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -296,6 +312,8 @@ public: }; ``` +#### Go + ```go func decrypt(code []int, k int) []int { n := len(code) @@ -318,6 +336,8 @@ func decrypt(code []int, k int) []int { } ``` +#### TypeScript + ```ts function decrypt(code: number[], k: number): number[] { const n: number = code.length; diff --git a/solution/1600-1699/1652.Defuse the Bomb/README_EN.md b/solution/1600-1699/1652.Defuse the Bomb/README_EN.md index 8a6023227d420..11bf16f5b60b6 100644 --- a/solution/1600-1699/1652.Defuse the Bomb/README_EN.md +++ b/solution/1600-1699/1652.Defuse the Bomb/README_EN.md @@ -96,6 +96,8 @@ The time complexity is $O(n \times |k|)$, ignoring the space consumption of the +#### Python3 + ```python class Solution: def decrypt(self, code: List[int], k: int) -> List[int]: @@ -113,6 +115,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] decrypt(int[] code, int k) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func decrypt(code []int, k int) []int { n := len(code) @@ -184,6 +192,8 @@ func decrypt(code []int, k int) []int { } ``` +#### TypeScript + ```ts function decrypt(code: number[], k: number): number[] { const n: number = code.length; @@ -229,6 +239,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def decrypt(self, code: List[int], k: int) -> List[int]: @@ -245,6 +257,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] decrypt(int[] code, int k) { @@ -269,6 +283,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -294,6 +310,8 @@ public: }; ``` +#### Go + ```go func decrypt(code []int, k int) []int { n := len(code) @@ -316,6 +334,8 @@ func decrypt(code []int, k int) []int { } ``` +#### TypeScript + ```ts function decrypt(code: number[], k: number): number[] { const n: number = code.length; diff --git a/solution/1600-1699/1653.Minimum Deletions to Make String Balanced/README.md b/solution/1600-1699/1653.Minimum Deletions to Make String Balanced/README.md index 114879da2fb6a..8f7bb20b8ac7a 100644 --- a/solution/1600-1699/1653.Minimum Deletions to Make String Balanced/README.md +++ b/solution/1600-1699/1653.Minimum Deletions to Make String Balanced/README.md @@ -87,6 +87,8 @@ $$ +#### Python3 + ```python class Solution: def minimumDeletions(self, s: str) -> int: @@ -102,6 +104,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int minimumDeletions(String s) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func minimumDeletions(s string) int { n := len(s) @@ -160,6 +168,8 @@ func minimumDeletions(s string) int { } ``` +#### TypeScript + ```ts function minimumDeletions(s: string): number { const n = s.length; @@ -193,6 +203,8 @@ function minimumDeletions(s: string): number { +#### Python3 + ```python class Solution: def minimumDeletions(self, s: str) -> int: @@ -205,6 +217,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumDeletions(String s) { @@ -222,6 +236,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -239,6 +255,8 @@ public: }; ``` +#### Go + ```go func minimumDeletions(s string) int { ans, b := 0, 0 @@ -253,6 +271,8 @@ func minimumDeletions(s string) int { } ``` +#### TypeScript + ```ts function minimumDeletions(s: string): number { const n = s.length; @@ -279,6 +299,8 @@ function minimumDeletions(s: string): number { +#### Python3 + ```python class Solution: def minimumDeletions(self, s: str) -> int: @@ -291,6 +313,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumDeletions(String s) { @@ -312,6 +336,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -328,6 +354,8 @@ public: }; ``` +#### Go + ```go func minimumDeletions(s string) int { lb, ra := 0, strings.Count(s, "a") @@ -347,6 +375,8 @@ func minimumDeletions(s string) int { } ``` +#### TypeScript + ```ts function minimumDeletions(s: string): number { let lb = 0, diff --git a/solution/1600-1699/1653.Minimum Deletions to Make String Balanced/README_EN.md b/solution/1600-1699/1653.Minimum Deletions to Make String Balanced/README_EN.md index cc43fb7127dfe..70df45432b4e7 100644 --- a/solution/1600-1699/1653.Minimum Deletions to Make String Balanced/README_EN.md +++ b/solution/1600-1699/1653.Minimum Deletions to Make String Balanced/README_EN.md @@ -85,6 +85,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string $s$. The sp +#### Python3 + ```python class Solution: def minimumDeletions(self, s: str) -> int: @@ -100,6 +102,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int minimumDeletions(String s) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func minimumDeletions(s string) int { n := len(s) @@ -158,6 +166,8 @@ func minimumDeletions(s string) int { } ``` +#### TypeScript + ```ts function minimumDeletions(s: string): number { const n = s.length; @@ -191,6 +201,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is +#### Python3 + ```python class Solution: def minimumDeletions(self, s: str) -> int: @@ -203,6 +215,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumDeletions(String s) { @@ -220,6 +234,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -237,6 +253,8 @@ public: }; ``` +#### Go + ```go func minimumDeletions(s string) int { ans, b := 0, 0 @@ -251,6 +269,8 @@ func minimumDeletions(s string) int { } ``` +#### TypeScript + ```ts function minimumDeletions(s: string): number { const n = s.length; @@ -277,6 +297,8 @@ function minimumDeletions(s: string): number { +#### Python3 + ```python class Solution: def minimumDeletions(self, s: str) -> int: @@ -289,6 +311,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumDeletions(String s) { @@ -310,6 +334,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -326,6 +352,8 @@ public: }; ``` +#### Go + ```go func minimumDeletions(s string) int { lb, ra := 0, strings.Count(s, "a") @@ -345,6 +373,8 @@ func minimumDeletions(s string) int { } ``` +#### TypeScript + ```ts function minimumDeletions(s: string): number { let lb = 0, diff --git a/solution/1600-1699/1654.Minimum Jumps to Reach Home/README.md b/solution/1600-1699/1654.Minimum Jumps to Reach Home/README.md index 4caf373b00fa5..6b527fc1346d3 100644 --- a/solution/1600-1699/1654.Minimum Jumps to Reach Home/README.md +++ b/solution/1600-1699/1654.Minimum Jumps to Reach Home/README.md @@ -101,6 +101,8 @@ tags: +#### Python3 + ```python class Solution: def minimumJumps(self, forbidden: List[int], a: int, b: int, x: int) -> int: @@ -124,6 +126,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minimumJumps(int[] forbidden, int a, int b, int x) { @@ -163,6 +167,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -198,6 +204,8 @@ public: }; ``` +#### Go + ```go func minimumJumps(forbidden []int, a int, b int, x int) (ans int) { s := map[int]bool{} @@ -233,6 +241,8 @@ func minimumJumps(forbidden []int, a int, b int, x int) (ans int) { } ``` +#### TypeScript + ```ts function minimumJumps(forbidden: number[], a: number, b: number, x: number): number { const s: Set = new Set(forbidden); diff --git a/solution/1600-1699/1654.Minimum Jumps to Reach Home/README_EN.md b/solution/1600-1699/1654.Minimum Jumps to Reach Home/README_EN.md index d9ed246f523a4..2202e5b4a9a47 100644 --- a/solution/1600-1699/1654.Minimum Jumps to Reach Home/README_EN.md +++ b/solution/1600-1699/1654.Minimum Jumps to Reach Home/README_EN.md @@ -99,6 +99,8 @@ The time complexity is $O(M)$, and the space complexity is $O(M)$. Here, $M$ is +#### Python3 + ```python class Solution: def minimumJumps(self, forbidden: List[int], a: int, b: int, x: int) -> int: @@ -122,6 +124,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minimumJumps(int[] forbidden, int a, int b, int x) { @@ -161,6 +165,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -196,6 +202,8 @@ public: }; ``` +#### Go + ```go func minimumJumps(forbidden []int, a int, b int, x int) (ans int) { s := map[int]bool{} @@ -231,6 +239,8 @@ func minimumJumps(forbidden []int, a int, b int, x int) (ans int) { } ``` +#### TypeScript + ```ts function minimumJumps(forbidden: number[], a: number, b: number, x: number): number { const s: Set = new Set(forbidden); diff --git a/solution/1600-1699/1655.Distribute Repeating Integers/README.md b/solution/1600-1699/1655.Distribute Repeating Integers/README.md index 2f322a5a873b7..33c57bc1c5037 100644 --- a/solution/1600-1699/1655.Distribute Repeating Integers/README.md +++ b/solution/1600-1699/1655.Distribute Repeating Integers/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class Solution: def canDistribute(self, nums: List[int], quantity: List[int]) -> bool: @@ -128,6 +130,8 @@ class Solution: return f[-1][-1] ``` +#### Java + ```java class Solution { public boolean canDistribute(int[] nums, int[] quantity) { @@ -176,6 +180,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -226,6 +232,8 @@ public: }; ``` +#### Go + ```go func canDistribute(nums []int, quantity []int) bool { m := len(quantity) @@ -272,6 +280,8 @@ func canDistribute(nums []int, quantity []int) bool { } ``` +#### TypeScript + ```ts function canDistribute(nums: number[], quantity: number[]): boolean { const m = quantity.length; diff --git a/solution/1600-1699/1655.Distribute Repeating Integers/README_EN.md b/solution/1600-1699/1655.Distribute Repeating Integers/README_EN.md index 8d74ad57c1521..e73bfb4b814d1 100644 --- a/solution/1600-1699/1655.Distribute Repeating Integers/README_EN.md +++ b/solution/1600-1699/1655.Distribute Repeating Integers/README_EN.md @@ -94,6 +94,8 @@ The time complexity is `O(n * 3^m)`, and the space complexity is `O(n * 2^m)`. H +#### Python3 + ```python class Solution: def canDistribute(self, nums: List[int], quantity: List[int]) -> bool: @@ -126,6 +128,8 @@ class Solution: return f[-1][-1] ``` +#### Java + ```java class Solution { public boolean canDistribute(int[] nums, int[] quantity) { @@ -174,6 +178,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -224,6 +230,8 @@ public: }; ``` +#### Go + ```go func canDistribute(nums []int, quantity []int) bool { m := len(quantity) @@ -270,6 +278,8 @@ func canDistribute(nums []int, quantity []int) bool { } ``` +#### TypeScript + ```ts function canDistribute(nums: number[], quantity: number[]): boolean { const m = quantity.length; diff --git a/solution/1600-1699/1656.Design an Ordered Stream/README.md b/solution/1600-1699/1656.Design an Ordered Stream/README.md index 6a46f68c9eb9e..831c49b4e8dd7 100644 --- a/solution/1600-1699/1656.Design an Ordered Stream/README.md +++ b/solution/1600-1699/1656.Design an Ordered Stream/README.md @@ -84,6 +84,8 @@ os.insert(4, "ddddd"); // 插入 (4, "ddddd"),返回 ["ddddd", "eeeee"] +#### Python3 + ```python class OrderedStream: def __init__(self, n: int): @@ -104,6 +106,8 @@ class OrderedStream: # param_1 = obj.insert(idKey,value) ``` +#### Java + ```java class OrderedStream { private String[] data; @@ -131,6 +135,8 @@ class OrderedStream { */ ``` +#### C++ + ```cpp class OrderedStream { public: @@ -156,6 +162,8 @@ public: */ ``` +#### Go + ```go type OrderedStream struct { data []string @@ -184,6 +192,8 @@ func (this *OrderedStream) Insert(idKey int, value string) []string { */ ``` +#### TypeScript + ```ts class OrderedStream { private ptr: number; @@ -212,6 +222,8 @@ class OrderedStream { */ ``` +#### Rust + ```rust struct OrderedStream { ptr: usize, diff --git a/solution/1600-1699/1656.Design an Ordered Stream/README_EN.md b/solution/1600-1699/1656.Design an Ordered Stream/README_EN.md index 3794b279d9efc..f41c3070e563d 100644 --- a/solution/1600-1699/1656.Design an Ordered Stream/README_EN.md +++ b/solution/1600-1699/1656.Design an Ordered Stream/README_EN.md @@ -79,6 +79,8 @@ os.insert(4, "ddddd"); // Inserts (4, "ddddd"), returns [&qu +#### Python3 + ```python class OrderedStream: def __init__(self, n: int): @@ -99,6 +101,8 @@ class OrderedStream: # param_1 = obj.insert(idKey,value) ``` +#### Java + ```java class OrderedStream { private String[] data; @@ -126,6 +130,8 @@ class OrderedStream { */ ``` +#### C++ + ```cpp class OrderedStream { public: @@ -151,6 +157,8 @@ public: */ ``` +#### Go + ```go type OrderedStream struct { data []string @@ -179,6 +187,8 @@ func (this *OrderedStream) Insert(idKey int, value string) []string { */ ``` +#### TypeScript + ```ts class OrderedStream { private ptr: number; @@ -207,6 +217,8 @@ class OrderedStream { */ ``` +#### Rust + ```rust struct OrderedStream { ptr: usize, diff --git a/solution/1600-1699/1657.Determine if Two Strings Are Close/README.md b/solution/1600-1699/1657.Determine if Two Strings Are Close/README.md index d4c10c7fe1358..e7d9ac3436080 100644 --- a/solution/1600-1699/1657.Determine if Two Strings Are Close/README.md +++ b/solution/1600-1699/1657.Determine if Two Strings Are Close/README.md @@ -102,6 +102,8 @@ tags: +#### Python3 + ```python class Solution: def closeStrings(self, word1: str, word2: str) -> bool: @@ -111,6 +113,8 @@ class Solution: ) == set(cnt2.keys()) ``` +#### Java + ```java class Solution { public boolean closeStrings(String word1, String word2) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func closeStrings(word1 string, word2 string) bool { cnt1 := make([]int, 26) @@ -177,6 +185,8 @@ func closeStrings(word1 string, word2 string) bool { } ``` +#### TypeScript + ```ts function closeStrings(word1: string, word2: string): boolean { const cnt1 = Array(26).fill(0); @@ -198,6 +208,8 @@ function closeStrings(word1: string, word2: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn close_strings(word1: String, word2: String) -> bool { diff --git a/solution/1600-1699/1657.Determine if Two Strings Are Close/README_EN.md b/solution/1600-1699/1657.Determine if Two Strings Are Close/README_EN.md index aefa589b22f79..ca42fabd4b343 100644 --- a/solution/1600-1699/1657.Determine if Two Strings Are Close/README_EN.md +++ b/solution/1600-1699/1657.Determine if Two Strings Are Close/README_EN.md @@ -103,6 +103,8 @@ The time complexity is $O(m + n + C \times \log C)$, and the space complexity is +#### Python3 + ```python class Solution: def closeStrings(self, word1: str, word2: str) -> bool: @@ -112,6 +114,8 @@ class Solution: ) == set(cnt2.keys()) ``` +#### Java + ```java class Solution { public boolean closeStrings(String word1, String word2) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func closeStrings(word1 string, word2 string) bool { cnt1 := make([]int, 26) @@ -178,6 +186,8 @@ func closeStrings(word1 string, word2 string) bool { } ``` +#### TypeScript + ```ts function closeStrings(word1: string, word2: string): boolean { const cnt1 = Array(26).fill(0); @@ -199,6 +209,8 @@ function closeStrings(word1: string, word2: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn close_strings(word1: String, word2: String) -> bool { diff --git a/solution/1600-1699/1658.Minimum Operations to Reduce X to Zero/README.md b/solution/1600-1699/1658.Minimum Operations to Reduce X to Zero/README.md index 7f7b8baf5c61c..87f8d70d4103f 100644 --- a/solution/1600-1699/1658.Minimum Operations to Reduce X to Zero/README.md +++ b/solution/1600-1699/1658.Minimum Operations to Reduce X to Zero/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int], x: int) -> int: @@ -96,6 +98,8 @@ class Solution: return -1 if mx == -1 else len(nums) - mx ``` +#### Java + ```java class Solution { public int minOperations(int[] nums, int x) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int, x int) int { s := -x @@ -165,6 +173,8 @@ func minOperations(nums []int, x int) int { } ``` +#### TypeScript + ```ts function minOperations(nums: number[], x: number): number { const s = nums.reduce((acc, cur) => acc + cur, -x); @@ -184,6 +194,8 @@ function minOperations(nums: number[], x: number): number { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -232,6 +244,8 @@ impl Solution { +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int], x: int) -> int: @@ -248,6 +262,8 @@ class Solution: return -1 if mx == -1 else len(nums) - mx ``` +#### Java + ```java class Solution { public int minOperations(int[] nums, int x) { @@ -271,6 +287,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -292,6 +310,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int, x int) int { s := -x @@ -315,6 +335,8 @@ func minOperations(nums []int, x int) int { } ``` +#### TypeScript + ```ts function minOperations(nums: number[], x: number): number { const s = nums.reduce((acc, cur) => acc + cur, -x); @@ -333,6 +355,8 @@ function minOperations(nums: number[], x: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_operations(nums: Vec, x: i32) -> i32 { diff --git a/solution/1600-1699/1658.Minimum Operations to Reduce X to Zero/README_EN.md b/solution/1600-1699/1658.Minimum Operations to Reduce X to Zero/README_EN.md index d716f6875f3bc..c6bf59b671343 100644 --- a/solution/1600-1699/1658.Minimum Operations to Reduce X to Zero/README_EN.md +++ b/solution/1600-1699/1658.Minimum Operations to Reduce X to Zero/README_EN.md @@ -79,6 +79,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int], x: int) -> int: @@ -94,6 +96,8 @@ class Solution: return -1 if mx == -1 else len(nums) - mx ``` +#### Java + ```java class Solution { public int minOperations(int[] nums, int x) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int, x int) int { s := -x @@ -163,6 +171,8 @@ func minOperations(nums []int, x int) int { } ``` +#### TypeScript + ```ts function minOperations(nums: number[], x: number): number { const s = nums.reduce((acc, cur) => acc + cur, -x); @@ -182,6 +192,8 @@ function minOperations(nums: number[], x: number): number { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -230,6 +242,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int], x: int) -> int: @@ -246,6 +260,8 @@ class Solution: return -1 if mx == -1 else len(nums) - mx ``` +#### Java + ```java class Solution { public int minOperations(int[] nums, int x) { @@ -269,6 +285,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -290,6 +308,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int, x int) int { s := -x @@ -313,6 +333,8 @@ func minOperations(nums []int, x int) int { } ``` +#### TypeScript + ```ts function minOperations(nums: number[], x: number): number { const s = nums.reduce((acc, cur) => acc + cur, -x); @@ -331,6 +353,8 @@ function minOperations(nums: number[], x: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_operations(nums: Vec, x: i32) -> i32 { diff --git a/solution/1600-1699/1659.Maximize Grid Happiness/README.md b/solution/1600-1699/1659.Maximize Grid Happiness/README.md index 127da088b8df4..f0329c2fd4ae8 100644 --- a/solution/1600-1699/1659.Maximize Grid Happiness/README.md +++ b/solution/1600-1699/1659.Maximize Grid Happiness/README.md @@ -117,6 +117,8 @@ $$ +#### Python3 + ```python class Solution: def getMaxGridHappiness( @@ -161,6 +163,8 @@ class Solution: return dfs(0, 0, introvertsCount, extrovertsCount) ``` +#### Java + ```java class Solution { private int m; @@ -229,6 +233,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -292,6 +298,8 @@ public: }; ``` +#### Go + ```go func getMaxGridHappiness(m int, n int, introvertsCount int, extrovertsCount int) int { mx := int(math.Pow(3, float64(n))) @@ -364,6 +372,8 @@ func getMaxGridHappiness(m int, n int, introvertsCount int, extrovertsCount int) } ``` +#### TypeScript + ```ts function getMaxGridHappiness( m: number, @@ -471,6 +481,8 @@ function getMaxGridHappiness( +#### Python3 + ```python class Solution: def getMaxGridHappiness( @@ -502,6 +514,8 @@ class Solution: return dfs(0, 0, introvertsCount, extrovertsCount) ``` +#### Java + ```java class Solution { private int m; @@ -543,6 +557,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -578,6 +594,8 @@ public: }; ``` +#### Go + ```go func getMaxGridHappiness(m int, n int, introvertsCount int, extrovertsCount int) int { p := int(math.Pow(3, float64(n-1))) @@ -634,6 +652,8 @@ func getMaxGridHappiness(m int, n int, introvertsCount int, extrovertsCount int) } ``` +#### TypeScript + ```ts function getMaxGridHappiness( m: number, diff --git a/solution/1600-1699/1659.Maximize Grid Happiness/README_EN.md b/solution/1600-1699/1659.Maximize Grid Happiness/README_EN.md index 8ff58dc7694ed..3b41c741ad5bf 100644 --- a/solution/1600-1699/1659.Maximize Grid Happiness/README_EN.md +++ b/solution/1600-1699/1659.Maximize Grid Happiness/README_EN.md @@ -115,6 +115,8 @@ The time complexity is $O(3^{2n} \times (m \times ic \times ec + n))$, and the s +#### Python3 + ```python class Solution: def getMaxGridHappiness( @@ -159,6 +161,8 @@ class Solution: return dfs(0, 0, introvertsCount, extrovertsCount) ``` +#### Java + ```java class Solution { private int m; @@ -227,6 +231,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -290,6 +296,8 @@ public: }; ``` +#### Go + ```go func getMaxGridHappiness(m int, n int, introvertsCount int, extrovertsCount int) int { mx := int(math.Pow(3, float64(n))) @@ -362,6 +370,8 @@ func getMaxGridHappiness(m int, n int, introvertsCount int, extrovertsCount int) } ``` +#### TypeScript + ```ts function getMaxGridHappiness( m: number, @@ -469,6 +479,8 @@ The time complexity is $O(3^{n+1} \times m \times n \times ic \times ec)$, and t +#### Python3 + ```python class Solution: def getMaxGridHappiness( @@ -500,6 +512,8 @@ class Solution: return dfs(0, 0, introvertsCount, extrovertsCount) ``` +#### Java + ```java class Solution { private int m; @@ -541,6 +555,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -576,6 +592,8 @@ public: }; ``` +#### Go + ```go func getMaxGridHappiness(m int, n int, introvertsCount int, extrovertsCount int) int { p := int(math.Pow(3, float64(n-1))) @@ -632,6 +650,8 @@ func getMaxGridHappiness(m int, n int, introvertsCount int, extrovertsCount int) } ``` +#### TypeScript + ```ts function getMaxGridHappiness( m: number, diff --git a/solution/1600-1699/1660.Correct a Binary Tree/README.md b/solution/1600-1699/1660.Correct a Binary Tree/README.md index 23970c1e84ec6..d2a6992ed8079 100644 --- a/solution/1600-1699/1660.Correct a Binary Tree/README.md +++ b/solution/1600-1699/1660.Correct a Binary Tree/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -109,6 +111,8 @@ class Solution: return dfs(root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -174,6 +180,8 @@ public: }; ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/1600-1699/1660.Correct a Binary Tree/README_EN.md b/solution/1600-1699/1660.Correct a Binary Tree/README_EN.md index d23f1d435cc08..4c4926392dd0d 100644 --- a/solution/1600-1699/1660.Correct a Binary Tree/README_EN.md +++ b/solution/1600-1699/1660.Correct a Binary Tree/README_EN.md @@ -108,6 +108,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -129,6 +131,8 @@ class Solution: return dfs(root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -164,6 +168,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -194,6 +200,8 @@ public: }; ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/1600-1699/1661.Average Time of Process per Machine/README.md b/solution/1600-1699/1661.Average Time of Process per Machine/README.md index 665fb49342a79..b253b39b588c6 100644 --- a/solution/1600-1699/1661.Average Time of Process per Machine/README.md +++ b/solution/1600-1699/1661.Average Time of Process per Machine/README.md @@ -99,6 +99,8 @@ Activity table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -126,6 +128,8 @@ GROUP BY 1; +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1600-1699/1661.Average Time of Process per Machine/README_EN.md b/solution/1600-1699/1661.Average Time of Process per Machine/README_EN.md index 6847e1347c8a9..2fd729e02ea30 100644 --- a/solution/1600-1699/1661.Average Time of Process per Machine/README_EN.md +++ b/solution/1600-1699/1661.Average Time of Process per Machine/README_EN.md @@ -99,6 +99,8 @@ Note that each machine has $2$ process tasks, so we need to multiply the calcula +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -126,6 +128,8 @@ GROUP BY 1; +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1600-1699/1662.Check If Two String Arrays are Equivalent/README.md b/solution/1600-1699/1662.Check If Two String Arrays are Equivalent/README.md index f90d083923484..d112f3c21f27d 100644 --- a/solution/1600-1699/1662.Check If Two String Arrays are Equivalent/README.md +++ b/solution/1600-1699/1662.Check If Two String Arrays are Equivalent/README.md @@ -74,12 +74,16 @@ word2 表示的字符串为 "a" + "bc" -> "abc" +#### Python3 + ```python class Solution: def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool: return ''.join(word1) == ''.join(word2) ``` +#### Java + ```java class Solution { public boolean arrayStringsAreEqual(String[] word1, String[] word2) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -97,18 +103,24 @@ public: }; ``` +#### Go + ```go func arrayStringsAreEqual(word1 []string, word2 []string) bool { return strings.Join(word1, "") == strings.Join(word2, "") } ``` +#### TypeScript + ```ts function arrayStringsAreEqual(word1: string[], word2: string[]): boolean { return word1.join('') === word2.join(''); } ``` +#### Rust + ```rust impl Solution { pub fn array_strings_are_equal(word1: Vec, word2: Vec) -> bool { @@ -117,6 +129,8 @@ impl Solution { } ``` +#### C + ```c bool arrayStringsAreEqual(char** word1, int word1Size, char** word2, int word2Size) { int i = 0; @@ -161,6 +175,8 @@ bool arrayStringsAreEqual(char** word1, int word1Size, char** word2, int word2Si +#### Python3 + ```python class Solution: def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool: @@ -176,6 +192,8 @@ class Solution: return i == len(word1) and j == len(word2) ``` +#### Java + ```java class Solution { public boolean arrayStringsAreEqual(String[] word1, String[] word2) { @@ -199,6 +217,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -214,6 +234,8 @@ public: }; ``` +#### Go + ```go func arrayStringsAreEqual(word1 []string, word2 []string) bool { var i, j, x, y int @@ -233,6 +255,8 @@ func arrayStringsAreEqual(word1 []string, word2 []string) bool { } ``` +#### TypeScript + ```ts function arrayStringsAreEqual(word1: string[], word2: string[]): boolean { let [i, j, x, y] = [0, 0, 0, 0]; @@ -253,6 +277,8 @@ function arrayStringsAreEqual(word1: string[], word2: string[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn array_strings_are_equal(word1: Vec, word2: Vec) -> bool { diff --git a/solution/1600-1699/1662.Check If Two String Arrays are Equivalent/README_EN.md b/solution/1600-1699/1662.Check If Two String Arrays are Equivalent/README_EN.md index bc4a6c6e12a9f..07bef6918885a 100644 --- a/solution/1600-1699/1662.Check If Two String Arrays are Equivalent/README_EN.md +++ b/solution/1600-1699/1662.Check If Two String Arrays are Equivalent/README_EN.md @@ -72,12 +72,16 @@ The time complexity is $O(m)$, and the space complexity is $O(m)$. Here, $m$ is +#### Python3 + ```python class Solution: def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool: return ''.join(word1) == ''.join(word2) ``` +#### Java + ```java class Solution { public boolean arrayStringsAreEqual(String[] word1, String[] word2) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -95,18 +101,24 @@ public: }; ``` +#### Go + ```go func arrayStringsAreEqual(word1 []string, word2 []string) bool { return strings.Join(word1, "") == strings.Join(word2, "") } ``` +#### TypeScript + ```ts function arrayStringsAreEqual(word1: string[], word2: string[]): boolean { return word1.join('') === word2.join(''); } ``` +#### Rust + ```rust impl Solution { pub fn array_strings_are_equal(word1: Vec, word2: Vec) -> bool { @@ -115,6 +127,8 @@ impl Solution { } ``` +#### C + ```c bool arrayStringsAreEqual(char** word1, int word1Size, char** word2, int word2Size) { int i = 0; @@ -159,6 +173,8 @@ The time complexity is $O(m)$, and the space complexity is $O(1)$. Here, $m$ is +#### Python3 + ```python class Solution: def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool: @@ -174,6 +190,8 @@ class Solution: return i == len(word1) and j == len(word2) ``` +#### Java + ```java class Solution { public boolean arrayStringsAreEqual(String[] word1, String[] word2) { @@ -197,6 +215,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -212,6 +232,8 @@ public: }; ``` +#### Go + ```go func arrayStringsAreEqual(word1 []string, word2 []string) bool { var i, j, x, y int @@ -231,6 +253,8 @@ func arrayStringsAreEqual(word1 []string, word2 []string) bool { } ``` +#### TypeScript + ```ts function arrayStringsAreEqual(word1: string[], word2: string[]): boolean { let [i, j, x, y] = [0, 0, 0, 0]; @@ -251,6 +275,8 @@ function arrayStringsAreEqual(word1: string[], word2: string[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn array_strings_are_equal(word1: Vec, word2: Vec) -> bool { diff --git a/solution/1600-1699/1663.Smallest String With A Given Numeric Value/README.md b/solution/1600-1699/1663.Smallest String With A Given Numeric Value/README.md index c10fc464a53ff..2cc2b3d06f384 100644 --- a/solution/1600-1699/1663.Smallest String With A Given Numeric Value/README.md +++ b/solution/1600-1699/1663.Smallest String With A Given Numeric Value/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def getSmallestString(self, n: int, k: int) -> str: @@ -86,6 +88,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String getSmallestString(int n, int k) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func getSmallestString(n int, k int) string { ans := make([]byte, n) diff --git a/solution/1600-1699/1663.Smallest String With A Given Numeric Value/README_EN.md b/solution/1600-1699/1663.Smallest String With A Given Numeric Value/README_EN.md index 49e8d4a61b80c..b25235d967a86 100644 --- a/solution/1600-1699/1663.Smallest String With A Given Numeric Value/README_EN.md +++ b/solution/1600-1699/1663.Smallest String With A Given Numeric Value/README_EN.md @@ -67,6 +67,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string. Ignoring t +#### Python3 + ```python class Solution: def getSmallestString(self, n: int, k: int) -> str: @@ -80,6 +82,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String getSmallestString(int n, int k) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func getSmallestString(n int, k int) string { ans := make([]byte, n) diff --git a/solution/1600-1699/1664.Ways to Make a Fair Array/README.md b/solution/1600-1699/1664.Ways to Make a Fair Array/README.md index 72d39ef20695f..ee903ee65a79a 100644 --- a/solution/1600-1699/1664.Ways to Make a Fair Array/README.md +++ b/solution/1600-1699/1664.Ways to Make a Fair Array/README.md @@ -97,6 +97,8 @@ tags: +#### Python3 + ```python class Solution: def waysToMakeFair(self, nums: List[int]) -> int: @@ -110,6 +112,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int waysToMakeFair(int[] nums) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func waysToMakeFair(nums []int) (ans int) { var s1, s2, t1, t2 int @@ -184,6 +192,8 @@ func waysToMakeFair(nums []int) (ans int) { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/1600-1699/1664.Ways to Make a Fair Array/README_EN.md b/solution/1600-1699/1664.Ways to Make a Fair Array/README_EN.md index 6611ea0827530..6a9d6677f355c 100644 --- a/solution/1600-1699/1664.Ways to Make a Fair Array/README_EN.md +++ b/solution/1600-1699/1664.Ways to Make a Fair Array/README_EN.md @@ -95,6 +95,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def waysToMakeFair(self, nums: List[int]) -> int: @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int waysToMakeFair(int[] nums) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func waysToMakeFair(nums []int) (ans int) { var s1, s2, t1, t2 int @@ -182,6 +190,8 @@ func waysToMakeFair(nums []int) (ans int) { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/1600-1699/1665.Minimum Initial Energy to Finish Tasks/README.md b/solution/1600-1699/1665.Minimum Initial Energy to Finish Tasks/README.md index c39d209494896..5f9c330dba2c1 100644 --- a/solution/1600-1699/1665.Minimum Initial Energy to Finish Tasks/README.md +++ b/solution/1600-1699/1665.Minimum Initial Energy to Finish Tasks/README.md @@ -115,6 +115,8 @@ $$ +#### Python3 + ```python class Solution: def minimumEffort(self, tasks: List[List[int]]) -> int: @@ -127,6 +129,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumEffort(int[][] tasks) { @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func minimumEffort(tasks [][]int) (ans int) { sort.Slice(tasks, func(i, j int) bool { return tasks[i][0]-tasks[i][1] < tasks[j][0]-tasks[j][1] }) @@ -180,6 +188,8 @@ func minimumEffort(tasks [][]int) (ans int) { } ``` +#### TypeScript + ```ts function minimumEffort(tasks: number[][]): number { tasks.sort((a, b) => a[0] - a[1] - (b[0] - b[1])); diff --git a/solution/1600-1699/1665.Minimum Initial Energy to Finish Tasks/README_EN.md b/solution/1600-1699/1665.Minimum Initial Energy to Finish Tasks/README_EN.md index fdcffbd87a4e2..5943e06726a31 100644 --- a/solution/1600-1699/1665.Minimum Initial Energy to Finish Tasks/README_EN.md +++ b/solution/1600-1699/1665.Minimum Initial Energy to Finish Tasks/README_EN.md @@ -116,6 +116,8 @@ The time complexity is $O(n\times \log n)$, where $n$ is the number of tasks. Ig +#### Python3 + ```python class Solution: def minimumEffort(self, tasks: List[List[int]]) -> int: @@ -128,6 +130,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumEffort(int[][] tasks) { @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func minimumEffort(tasks [][]int) (ans int) { sort.Slice(tasks, func(i, j int) bool { return tasks[i][0]-tasks[i][1] < tasks[j][0]-tasks[j][1] }) @@ -181,6 +189,8 @@ func minimumEffort(tasks [][]int) (ans int) { } ``` +#### TypeScript + ```ts function minimumEffort(tasks: number[][]): number { tasks.sort((a, b) => a[0] - a[1] - (b[0] - b[1])); diff --git a/solution/1600-1699/1666.Change the Root of a Binary Tree/README.md b/solution/1600-1699/1666.Change the Root of a Binary Tree/README.md index 387425ea08dc8..5649a38b4105f 100644 --- a/solution/1600-1699/1666.Change the Root of a Binary Tree/README.md +++ b/solution/1600-1699/1666.Change the Root of a Binary Tree/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python """ # Definition for a Node. @@ -102,6 +104,8 @@ class Solution: return leaf ``` +#### Java + ```java /* // Definition for a Node. @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node-> @@ -176,6 +182,8 @@ public: }; ``` +#### JavaScript + ```js /** * // Definition for a Node. @@ -214,6 +222,8 @@ var flipBinaryTree = function (root, leaf) { }; ``` +#### C# + ```cs /* // Definition for a Node. diff --git a/solution/1600-1699/1666.Change the Root of a Binary Tree/README_EN.md b/solution/1600-1699/1666.Change the Root of a Binary Tree/README_EN.md index a8b00f2a8a44b..9cf85b2f1ad9b 100644 --- a/solution/1600-1699/1666.Change the Root of a Binary Tree/README_EN.md +++ b/solution/1600-1699/1666.Change the Root of a Binary Tree/README_EN.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python """ # Definition for a Node. @@ -98,6 +100,8 @@ class Solution: return leaf ``` +#### Java + ```java /* // Definition for a Node. @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp /* // Definition for a Node-> @@ -172,6 +178,8 @@ public: }; ``` +#### JavaScript + ```js /** * // Definition for a Node. @@ -210,6 +218,8 @@ var flipBinaryTree = function (root, leaf) { }; ``` +#### C# + ```cs /* // Definition for a Node. diff --git a/solution/1600-1699/1667.Fix Names in a Table/README.md b/solution/1600-1699/1667.Fix Names in a Table/README.md index 0c204bebbf7b7..f6292c0ed49aa 100644 --- a/solution/1600-1699/1667.Fix Names in a Table/README.md +++ b/solution/1600-1699/1667.Fix Names in a Table/README.md @@ -68,6 +68,8 @@ Users table: +#### MySQL + ```sql SELECT user_id, @@ -88,6 +90,8 @@ ORDER BY +#### MySQL + ```sql SELECT user_id, diff --git a/solution/1600-1699/1667.Fix Names in a Table/README_EN.md b/solution/1600-1699/1667.Fix Names in a Table/README_EN.md index 4babc10b64ae5..fe38340554020 100644 --- a/solution/1600-1699/1667.Fix Names in a Table/README_EN.md +++ b/solution/1600-1699/1667.Fix Names in a Table/README_EN.md @@ -68,6 +68,8 @@ Users table: +#### MySQL + ```sql SELECT user_id, @@ -88,6 +90,8 @@ ORDER BY +#### MySQL + ```sql SELECT user_id, diff --git a/solution/1600-1699/1668.Maximum Repeating Substring/README.md b/solution/1600-1699/1668.Maximum Repeating Substring/README.md index a1e75de935ac1..899f87ab9566b 100644 --- a/solution/1600-1699/1668.Maximum Repeating Substring/README.md +++ b/solution/1600-1699/1668.Maximum Repeating Substring/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def maxRepeating(self, sequence: str, word: str) -> int: @@ -82,6 +84,8 @@ class Solution: return k ``` +#### Java + ```java class Solution { public int maxRepeating(String sequence, String word) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func maxRepeating(sequence string, word string) int { for k := len(sequence) / len(word); k > 0; k-- { @@ -125,6 +133,8 @@ func maxRepeating(sequence string, word string) int { } ``` +#### TypeScript + ```ts function maxRepeating(sequence: string, word: string): number { let n = sequence.length; @@ -138,6 +148,8 @@ function maxRepeating(sequence: string, word: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_repeating(sequence: String, word: String) -> i32 { @@ -158,6 +170,8 @@ impl Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) diff --git a/solution/1600-1699/1668.Maximum Repeating Substring/README_EN.md b/solution/1600-1699/1668.Maximum Repeating Substring/README_EN.md index 0fd15c68cb550..4df84b87126ed 100644 --- a/solution/1600-1699/1668.Maximum Repeating Substring/README_EN.md +++ b/solution/1600-1699/1668.Maximum Repeating Substring/README_EN.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def maxRepeating(self, sequence: str, word: str) -> int: @@ -76,6 +78,8 @@ class Solution: return k ``` +#### Java + ```java class Solution { public int maxRepeating(String sequence, String word) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func maxRepeating(sequence string, word string) int { for k := len(sequence) / len(word); k > 0; k-- { @@ -119,6 +127,8 @@ func maxRepeating(sequence string, word string) int { } ``` +#### TypeScript + ```ts function maxRepeating(sequence: string, word: string): number { let n = sequence.length; @@ -132,6 +142,8 @@ function maxRepeating(sequence: string, word: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_repeating(sequence: String, word: String) -> i32 { @@ -152,6 +164,8 @@ impl Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) diff --git a/solution/1600-1699/1669.Merge In Between Linked Lists/README.md b/solution/1600-1699/1669.Merge In Between Linked Lists/README.md index 24e1d57cacfcc..6046748d3d890 100644 --- a/solution/1600-1699/1669.Merge In Between Linked Lists/README.md +++ b/solution/1600-1699/1669.Merge In Between Linked Lists/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -97,6 +99,8 @@ class Solution: return list1 ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -186,6 +194,8 @@ func mergeInBetween(list1 *ListNode, a int, b int, list2 *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -223,6 +233,8 @@ function mergeInBetween( } ``` +#### C# + ```cs /** * Definition for singly-linked list. diff --git a/solution/1600-1699/1669.Merge In Between Linked Lists/README_EN.md b/solution/1600-1699/1669.Merge In Between Linked Lists/README_EN.md index 914f63fa58b1c..10138e6bbaeeb 100644 --- a/solution/1600-1699/1669.Merge In Between Linked Lists/README_EN.md +++ b/solution/1600-1699/1669.Merge In Between Linked Lists/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(m + n)$, and the space complexity is $O(1)$. Where $m$ +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -93,6 +95,8 @@ class Solution: return list1 ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -182,6 +190,8 @@ func mergeInBetween(list1 *ListNode, a int, b int, list2 *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -219,6 +229,8 @@ function mergeInBetween( } ``` +#### C# + ```cs /** * Definition for singly-linked list. diff --git a/solution/1600-1699/1670.Design Front Middle Back Queue/README.md b/solution/1600-1699/1670.Design Front Middle Back Queue/README.md index 08767eef3bd0c..5962c7c742ac2 100644 --- a/solution/1600-1699/1670.Design Front Middle Back Queue/README.md +++ b/solution/1600-1699/1670.Design Front Middle Back Queue/README.md @@ -98,6 +98,8 @@ q.popFront(); // 返回 -1 -> [] (队列为空) +#### Python3 + ```python class FrontMiddleBackQueue: def __init__(self): @@ -160,6 +162,8 @@ class FrontMiddleBackQueue: # param_6 = obj.popBack() ``` +#### Java + ```java class FrontMiddleBackQueue { private Deque q1 = new ArrayDeque<>(); @@ -232,6 +236,8 @@ class FrontMiddleBackQueue { */ ``` +#### C++ + ```cpp class FrontMiddleBackQueue { public: @@ -317,6 +323,8 @@ private: */ ``` +#### Go + ```go type FrontMiddleBackQueue struct { q1, q2 Deque @@ -457,6 +465,8 @@ func (q Deque) Get(i int) int { */ ``` +#### TypeScript + ```ts class FrontMiddleBackQueue { private q1: Deque; @@ -628,6 +638,8 @@ class Deque { */ ``` +#### JavaScript + ```js class FrontMiddleBackQueue { constructor() { diff --git a/solution/1600-1699/1670.Design Front Middle Back Queue/README_EN.md b/solution/1600-1699/1670.Design Front Middle Back Queue/README_EN.md index 0c9c5fe82979a..defb56a84c4e8 100644 --- a/solution/1600-1699/1670.Design Front Middle Back Queue/README_EN.md +++ b/solution/1600-1699/1670.Design Front Middle Back Queue/README_EN.md @@ -96,6 +96,8 @@ The time complexity of the above operations is $O(1)$, and the space complexity +#### Python3 + ```python class FrontMiddleBackQueue: def __init__(self): @@ -158,6 +160,8 @@ class FrontMiddleBackQueue: # param_6 = obj.popBack() ``` +#### Java + ```java class FrontMiddleBackQueue { private Deque q1 = new ArrayDeque<>(); @@ -230,6 +234,8 @@ class FrontMiddleBackQueue { */ ``` +#### C++ + ```cpp class FrontMiddleBackQueue { public: @@ -315,6 +321,8 @@ private: */ ``` +#### Go + ```go type FrontMiddleBackQueue struct { q1, q2 Deque @@ -455,6 +463,8 @@ func (q Deque) Get(i int) int { */ ``` +#### TypeScript + ```ts class FrontMiddleBackQueue { private q1: Deque; @@ -626,6 +636,8 @@ class Deque { */ ``` +#### JavaScript + ```js class FrontMiddleBackQueue { constructor() { diff --git a/solution/1600-1699/1671.Minimum Number of Removals to Make Mountain Array/README.md b/solution/1600-1699/1671.Minimum Number of Removals to Make Mountain Array/README.md index 4aa2726182917..2384272688e4c 100644 --- a/solution/1600-1699/1671.Minimum Number of Removals to Make Mountain Array/README.md +++ b/solution/1600-1699/1671.Minimum Number of Removals to Make Mountain Array/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def minimumMountainRemovals(self, nums: List[int]) -> int: @@ -98,6 +100,8 @@ class Solution: return n - max(a + b - 1 for a, b in zip(left, right) if a > 1 and b > 1) ``` +#### Java + ```java class Solution { public int minimumMountainRemovals(int[] nums) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func minimumMountainRemovals(nums []int) int { n := len(nums) @@ -193,6 +201,8 @@ func minimumMountainRemovals(nums []int) int { } ``` +#### TypeScript + ```ts function minimumMountainRemovals(nums: number[]): number { const n = nums.length; @@ -222,6 +232,8 @@ function minimumMountainRemovals(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn minimum_mountain_removals(nums: Vec) -> i32 { diff --git a/solution/1600-1699/1671.Minimum Number of Removals to Make Mountain Array/README_EN.md b/solution/1600-1699/1671.Minimum Number of Removals to Make Mountain Array/README_EN.md index daacfed8aff2f..a01e1f7d14396 100644 --- a/solution/1600-1699/1671.Minimum Number of Removals to Make Mountain Array/README_EN.md +++ b/solution/1600-1699/1671.Minimum Number of Removals to Make Mountain Array/README_EN.md @@ -79,6 +79,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$. Here, $n$ i +#### Python3 + ```python class Solution: def minimumMountainRemovals(self, nums: List[int]) -> int: @@ -96,6 +98,8 @@ class Solution: return n - max(a + b - 1 for a, b in zip(left, right) if a > 1 and b > 1) ``` +#### Java + ```java class Solution { public int minimumMountainRemovals(int[] nums) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func minimumMountainRemovals(nums []int) int { n := len(nums) @@ -191,6 +199,8 @@ func minimumMountainRemovals(nums []int) int { } ``` +#### TypeScript + ```ts function minimumMountainRemovals(nums: number[]): number { const n = nums.length; @@ -220,6 +230,8 @@ function minimumMountainRemovals(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn minimum_mountain_removals(nums: Vec) -> i32 { diff --git a/solution/1600-1699/1672.Richest Customer Wealth/README.md b/solution/1600-1699/1672.Richest Customer Wealth/README.md index a9903a3ab817f..1447af28ba6b8 100644 --- a/solution/1600-1699/1672.Richest Customer Wealth/README.md +++ b/solution/1600-1699/1672.Richest Customer Wealth/README.md @@ -76,12 +76,16 @@ tags: +#### Python3 + ```python class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: return max(sum(v) for v in accounts) ``` +#### Java + ```java class Solution { public int maximumWealth(int[][] accounts) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func maximumWealth(accounts [][]int) int { ans := 0 @@ -128,6 +136,8 @@ func maximumWealth(accounts [][]int) int { } ``` +#### TypeScript + ```ts function maximumWealth(accounts: number[][]): number { return accounts.reduce( @@ -141,6 +151,8 @@ function maximumWealth(accounts: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn maximum_wealth(accounts: Vec>) -> i32 { @@ -153,6 +165,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** @@ -175,6 +189,8 @@ class Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) @@ -191,6 +207,8 @@ int maximumWealth(int** accounts, int accountsSize, int* accountsColSize) { } ``` +#### Kotlin + ```kotlin class Solution { fun maximumWealth(accounts: Array): Int { diff --git a/solution/1600-1699/1672.Richest Customer Wealth/README_EN.md b/solution/1600-1699/1672.Richest Customer Wealth/README_EN.md index 04a2360beb80f..28db0d239dcfe 100644 --- a/solution/1600-1699/1672.Richest Customer Wealth/README_EN.md +++ b/solution/1600-1699/1672.Richest Customer Wealth/README_EN.md @@ -77,12 +77,16 @@ The time complexity is $O(m \times n)$, where $m$ and $n$ are the number of rows +#### Python3 + ```python class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: return max(sum(v) for v in accounts) ``` +#### Java + ```java class Solution { public int maximumWealth(int[][] accounts) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func maximumWealth(accounts [][]int) int { ans := 0 @@ -129,6 +137,8 @@ func maximumWealth(accounts [][]int) int { } ``` +#### TypeScript + ```ts function maximumWealth(accounts: number[][]): number { return accounts.reduce( @@ -142,6 +152,8 @@ function maximumWealth(accounts: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn maximum_wealth(accounts: Vec>) -> i32 { @@ -154,6 +166,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** @@ -176,6 +190,8 @@ class Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) @@ -192,6 +208,8 @@ int maximumWealth(int** accounts, int accountsSize, int* accountsColSize) { } ``` +#### Kotlin + ```kotlin class Solution { fun maximumWealth(accounts: Array): Int { diff --git a/solution/1600-1699/1673.Find the Most Competitive Subsequence/README.md b/solution/1600-1699/1673.Find the Most Competitive Subsequence/README.md index a4c8c3dbe2641..0bf8e9f0c4eec 100644 --- a/solution/1600-1699/1673.Find the Most Competitive Subsequence/README.md +++ b/solution/1600-1699/1673.Find the Most Competitive Subsequence/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def mostCompetitive(self, nums: List[int], k: int) -> List[int]: @@ -83,6 +85,8 @@ class Solution: return stk ``` +#### Java + ```java class Solution { public int[] mostCompetitive(int[] nums, int k) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func mostCompetitive(nums []int, k int) []int { stk := []int{} @@ -140,6 +148,8 @@ func mostCompetitive(nums []int, k int) []int { } ``` +#### TypeScript + ```ts function mostCompetitive(nums: number[], k: number): number[] { const stk: number[] = []; diff --git a/solution/1600-1699/1673.Find the Most Competitive Subsequence/README_EN.md b/solution/1600-1699/1673.Find the Most Competitive Subsequence/README_EN.md index c42d93c1de890..111d058e7b0f3 100644 --- a/solution/1600-1699/1673.Find the Most Competitive Subsequence/README_EN.md +++ b/solution/1600-1699/1673.Find the Most Competitive Subsequence/README_EN.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def mostCompetitive(self, nums: List[int], k: int) -> List[int]: @@ -75,6 +77,8 @@ class Solution: return stk ``` +#### Java + ```java class Solution { public int[] mostCompetitive(int[] nums, int k) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func mostCompetitive(nums []int, k int) []int { stk := []int{} @@ -132,6 +140,8 @@ func mostCompetitive(nums []int, k int) []int { } ``` +#### TypeScript + ```ts function mostCompetitive(nums: number[], k: number): number[] { const stk: number[] = []; diff --git a/solution/1600-1699/1674.Minimum Moves to Make Array Complementary/README.md b/solution/1600-1699/1674.Minimum Moves to Make Array Complementary/README.md index aabd738d5d1b3..1e02b6deb8250 100644 --- a/solution/1600-1699/1674.Minimum Moves to Make Array Complementary/README.md +++ b/solution/1600-1699/1674.Minimum Moves to Make Array Complementary/README.md @@ -100,6 +100,8 @@ nums[3] + nums[0] = 3 + 1 = 4. +#### Python3 + ```python class Solution: def minMoves(self, nums: List[int], limit: int) -> int: @@ -126,6 +128,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minMoves(int[] nums, int limit) { @@ -156,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -187,6 +193,8 @@ public: }; ``` +#### Go + ```go func minMoves(nums []int, limit int) int { d := make([]int, limit*2+2) @@ -213,6 +221,8 @@ func minMoves(nums []int, limit int) int { } ``` +#### TypeScript + ```ts function minMoves(nums: number[], limit: number): number { const n = nums.length; diff --git a/solution/1600-1699/1674.Minimum Moves to Make Array Complementary/README_EN.md b/solution/1600-1699/1674.Minimum Moves to Make Array Complementary/README_EN.md index 0db099273d6c0..e4758d80752a9 100644 --- a/solution/1600-1699/1674.Minimum Moves to Make Array Complementary/README_EN.md +++ b/solution/1600-1699/1674.Minimum Moves to Make Array Complementary/README_EN.md @@ -98,6 +98,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def minMoves(self, nums: List[int], limit: int) -> int: @@ -124,6 +126,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minMoves(int[] nums, int limit) { @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -185,6 +191,8 @@ public: }; ``` +#### Go + ```go func minMoves(nums []int, limit int) int { d := make([]int, limit*2+2) @@ -211,6 +219,8 @@ func minMoves(nums []int, limit int) int { } ``` +#### TypeScript + ```ts function minMoves(nums: number[], limit: number): number { const n = nums.length; diff --git a/solution/1600-1699/1675.Minimize Deviation in Array/README.md b/solution/1600-1699/1675.Minimize Deviation in Array/README.md index 472fde3720bb1..cddebace84b1e 100644 --- a/solution/1600-1699/1675.Minimize Deviation in Array/README.md +++ b/solution/1600-1699/1675.Minimize Deviation in Array/README.md @@ -99,6 +99,8 @@ tags: +#### Python3 + ```python class Solution: def minimumDeviation(self, nums: List[int]) -> int: @@ -119,6 +121,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumDeviation(int[] nums) { @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func minimumDeviation(nums []int) int { q := hp{} diff --git a/solution/1600-1699/1675.Minimize Deviation in Array/README_EN.md b/solution/1600-1699/1675.Minimize Deviation in Array/README_EN.md index ad511a8fbc9fe..7d03461585e16 100644 --- a/solution/1600-1699/1675.Minimize Deviation in Array/README_EN.md +++ b/solution/1600-1699/1675.Minimize Deviation in Array/README_EN.md @@ -97,6 +97,8 @@ The time complexity is $O(n\log n \times \log m)$. Where $n$ and $m$ are the len +#### Python3 + ```python class Solution: def minimumDeviation(self, nums: List[int]) -> int: @@ -117,6 +119,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumDeviation(int[] nums) { @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func minimumDeviation(nums []int) int { q := hp{} diff --git a/solution/1600-1699/1676.Lowest Common Ancestor of a Binary Tree IV/README.md b/solution/1600-1699/1676.Lowest Common Ancestor of a Binary Tree IV/README.md index fc9f5c23c9d2d..e849cbcd0fa4e 100644 --- a/solution/1600-1699/1676.Lowest Common Ancestor of a Binary Tree IV/README.md +++ b/solution/1600-1699/1676.Lowest Common Ancestor of a Binary Tree IV/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -101,6 +103,8 @@ class Solution: return dfs(root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -168,6 +174,8 @@ public: }; ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/1600-1699/1676.Lowest Common Ancestor of a Binary Tree IV/README_EN.md b/solution/1600-1699/1676.Lowest Common Ancestor of a Binary Tree IV/README_EN.md index 6f8099e110b6e..586320c75cc51 100644 --- a/solution/1600-1699/1676.Lowest Common Ancestor of a Binary Tree IV/README_EN.md +++ b/solution/1600-1699/1676.Lowest Common Ancestor of a Binary Tree IV/README_EN.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -95,6 +97,8 @@ class Solution: return dfs(root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -162,6 +168,8 @@ public: }; ``` +#### JavaScript + ```js /** * Definition for a binary tree node. diff --git a/solution/1600-1699/1677.Product's Worth Over Invoices/README.md b/solution/1600-1699/1677.Product's Worth Over Invoices/README.md index 7f7f5bcbdee30..57bb89c0ae5e3 100644 --- a/solution/1600-1699/1677.Product's Worth Over Invoices/README.md +++ b/solution/1600-1699/1677.Product's Worth Over Invoices/README.md @@ -104,6 +104,8 @@ Result 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1600-1699/1677.Product's Worth Over Invoices/README_EN.md b/solution/1600-1699/1677.Product's Worth Over Invoices/README_EN.md index 7267de728d060..14f9fd7f347cc 100644 --- a/solution/1600-1699/1677.Product's Worth Over Invoices/README_EN.md +++ b/solution/1600-1699/1677.Product's Worth Over Invoices/README_EN.md @@ -111,6 +111,8 @@ Invoice table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1600-1699/1678.Goal Parser Interpretation/README.md b/solution/1600-1699/1678.Goal Parser Interpretation/README.md index 28e58789d72e3..160ff24292c43 100644 --- a/solution/1600-1699/1678.Goal Parser Interpretation/README.md +++ b/solution/1600-1699/1678.Goal Parser Interpretation/README.md @@ -70,12 +70,16 @@ G -> G +#### Python3 + ```python class Solution: def interpret(self, command: str) -> str: return command.replace('()', 'o').replace('(al)', 'al') ``` +#### Java + ```java class Solution { public String interpret(String command) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -95,6 +101,8 @@ public: }; ``` +#### Go + ```go func interpret(command string) string { command = strings.ReplaceAll(command, "()", "o") @@ -103,12 +111,16 @@ func interpret(command string) string { } ``` +#### TypeScript + ```ts function interpret(command: string): string { return command.replace(/\(\)/g, 'o').replace(/\(al\)/g, 'al'); } ``` +#### Rust + ```rust impl Solution { pub fn interpret(command: String) -> String { @@ -117,6 +129,8 @@ impl Solution { } ``` +#### C + ```c char* interpret(char* command) { int n = strlen(command); @@ -159,6 +173,8 @@ char* interpret(char* command) { +#### Python3 + ```python class Solution: def interpret(self, command: str) -> str: @@ -171,6 +187,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String interpret(String command) { @@ -188,6 +206,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -205,6 +225,8 @@ public: }; ``` +#### Go + ```go func interpret(command string) string { ans := &strings.Builder{} @@ -223,6 +245,8 @@ func interpret(command string) string { } ``` +#### TypeScript + ```ts function interpret(command: string): string { const n = command.length; @@ -239,6 +263,8 @@ function interpret(command: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn interpret(command: String) -> String { diff --git a/solution/1600-1699/1678.Goal Parser Interpretation/README_EN.md b/solution/1600-1699/1678.Goal Parser Interpretation/README_EN.md index 7197da527ea69..1ac056741f54f 100644 --- a/solution/1600-1699/1678.Goal Parser Interpretation/README_EN.md +++ b/solution/1600-1699/1678.Goal Parser Interpretation/README_EN.md @@ -69,12 +69,16 @@ According to the problem, we only need to replace `"()"` with `'o'` and `"(al)"` +#### Python3 + ```python class Solution: def interpret(self, command: str) -> str: return command.replace('()', 'o').replace('(al)', 'al') ``` +#### Java + ```java class Solution { public String interpret(String command) { @@ -83,6 +87,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -94,6 +100,8 @@ public: }; ``` +#### Go + ```go func interpret(command string) string { command = strings.ReplaceAll(command, "()", "o") @@ -102,12 +110,16 @@ func interpret(command string) string { } ``` +#### TypeScript + ```ts function interpret(command: string): string { return command.replace(/\(\)/g, 'o').replace(/\(al\)/g, 'al'); } ``` +#### Rust + ```rust impl Solution { pub fn interpret(command: String) -> String { @@ -116,6 +128,8 @@ impl Solution { } ``` +#### C + ```c char* interpret(char* command) { int n = strlen(command); @@ -158,6 +172,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def interpret(self, command: str) -> str: @@ -170,6 +186,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String interpret(String command) { @@ -187,6 +205,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -204,6 +224,8 @@ public: }; ``` +#### Go + ```go func interpret(command string) string { ans := &strings.Builder{} @@ -222,6 +244,8 @@ func interpret(command string) string { } ``` +#### TypeScript + ```ts function interpret(command: string): string { const n = command.length; @@ -238,6 +262,8 @@ function interpret(command: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn interpret(command: String) -> String { diff --git a/solution/1600-1699/1679.Max Number of K-Sum Pairs/README.md b/solution/1600-1699/1679.Max Number of K-Sum Pairs/README.md index 4f3ac4273bfcf..f9b6c676e168f 100644 --- a/solution/1600-1699/1679.Max Number of K-Sum Pairs/README.md +++ b/solution/1600-1699/1679.Max Number of K-Sum Pairs/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def maxOperations(self, nums: List[int], k: int) -> int: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxOperations(int[] nums, int k) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func maxOperations(nums []int, k int) int { sort.Ints(nums) @@ -162,6 +170,8 @@ func maxOperations(nums []int, k int) int { } ``` +#### TypeScript + ```ts function maxOperations(nums: number[], k: number): number { const cnt = new Map(); @@ -178,6 +188,8 @@ function maxOperations(nums: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_operations(nums: Vec, k: i32) -> i32 { @@ -222,6 +234,8 @@ impl Solution { +#### Python3 + ```python class Solution: def maxOperations(self, nums: List[int], k: int) -> int: @@ -236,6 +250,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxOperations(int[] nums, int k) { @@ -256,6 +272,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -275,6 +293,8 @@ public: }; ``` +#### Go + ```go func maxOperations(nums []int, k int) (ans int) { cnt := map[int]int{} @@ -290,6 +310,8 @@ func maxOperations(nums []int, k int) (ans int) { } ``` +#### Rust + ```rust impl Solution { pub fn max_operations(nums: Vec, k: i32) -> i32 { diff --git a/solution/1600-1699/1679.Max Number of K-Sum Pairs/README_EN.md b/solution/1600-1699/1679.Max Number of K-Sum Pairs/README_EN.md index 5b0936aa6eac2..0004ea1b5d9af 100644 --- a/solution/1600-1699/1679.Max Number of K-Sum Pairs/README_EN.md +++ b/solution/1600-1699/1679.Max Number of K-Sum Pairs/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def maxOperations(self, nums: List[int], k: int) -> int: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxOperations(int[] nums, int k) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func maxOperations(nums []int, k int) int { sort.Ints(nums) @@ -160,6 +168,8 @@ func maxOperations(nums []int, k int) int { } ``` +#### TypeScript + ```ts function maxOperations(nums: number[], k: number): number { const cnt = new Map(); @@ -176,6 +186,8 @@ function maxOperations(nums: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_operations(nums: Vec, k: i32) -> i32 { @@ -220,6 +232,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def maxOperations(self, nums: List[int], k: int) -> int: @@ -234,6 +248,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxOperations(int[] nums, int k) { @@ -254,6 +270,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -273,6 +291,8 @@ public: }; ``` +#### Go + ```go func maxOperations(nums []int, k int) (ans int) { cnt := map[int]int{} @@ -288,6 +308,8 @@ func maxOperations(nums []int, k int) (ans int) { } ``` +#### Rust + ```rust impl Solution { pub fn max_operations(nums: Vec, k: i32) -> i32 { diff --git a/solution/1600-1699/1680.Concatenation of Consecutive Binary Numbers/README.md b/solution/1600-1699/1680.Concatenation of Consecutive Binary Numbers/README.md index 52ac1907dd4c0..13b5d829c35f2 100644 --- a/solution/1600-1699/1680.Concatenation of Consecutive Binary Numbers/README.md +++ b/solution/1600-1699/1680.Concatenation of Consecutive Binary Numbers/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def concatenatedBinary(self, n: int) -> int: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int concatenatedBinary(int n) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func concatenatedBinary(n int) (ans int) { const mod = 1e9 + 7 @@ -117,6 +125,8 @@ func concatenatedBinary(n int) (ans int) { } ``` +#### TypeScript + ```ts function concatenatedBinary(n: number): number { const mod = BigInt(10 ** 9 + 7); @@ -142,6 +152,8 @@ function concatenatedBinary(n: number): number { +#### Python3 + ```python class Solution: def concatenatedBinary(self, n: int) -> int: @@ -154,6 +166,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int concatenatedBinary(int n) { @@ -171,6 +185,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -189,6 +205,8 @@ public: }; ``` +#### Go + ```go func concatenatedBinary(n int) (ans int) { const mod = 1e9 + 7 diff --git a/solution/1600-1699/1680.Concatenation of Consecutive Binary Numbers/README_EN.md b/solution/1600-1699/1680.Concatenation of Consecutive Binary Numbers/README_EN.md index 848948977d81c..4546f6652f77b 100644 --- a/solution/1600-1699/1680.Concatenation of Consecutive Binary Numbers/README_EN.md +++ b/solution/1600-1699/1680.Concatenation of Consecutive Binary Numbers/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(n)$, where $n$ is the given integer. The space complex +#### Python3 + ```python class Solution: def concatenatedBinary(self, n: int) -> int: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int concatenatedBinary(int n) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func concatenatedBinary(n int) (ans int) { const mod = 1e9 + 7 @@ -118,6 +126,8 @@ func concatenatedBinary(n int) (ans int) { } ``` +#### TypeScript + ```ts function concatenatedBinary(n: number): number { const mod = BigInt(10 ** 9 + 7); @@ -143,6 +153,8 @@ function concatenatedBinary(n: number): number { +#### Python3 + ```python class Solution: def concatenatedBinary(self, n: int) -> int: @@ -155,6 +167,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int concatenatedBinary(int n) { @@ -172,6 +186,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -190,6 +206,8 @@ public: }; ``` +#### Go + ```go func concatenatedBinary(n int) (ans int) { const mod = 1e9 + 7 diff --git a/solution/1600-1699/1681.Minimum Incompatibility/README.md b/solution/1600-1699/1681.Minimum Incompatibility/README.md index 7cabf91422862..e996de164bd73 100644 --- a/solution/1600-1699/1681.Minimum Incompatibility/README.md +++ b/solution/1600-1699/1681.Minimum Incompatibility/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def minimumIncompatibility(self, nums: List[int], k: int) -> int: @@ -132,6 +134,8 @@ class Solution: return f[-1] if f[-1] != inf else -1 ``` +#### Java + ```java class Solution { public int minimumIncompatibility(int[] nums, int k) { @@ -188,6 +192,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -245,6 +251,8 @@ public: }; ``` +#### Go + ```go func minimumIncompatibility(nums []int, k int) int { n := len(nums) @@ -305,6 +313,8 @@ func minimumIncompatibility(nums []int, k int) int { } ``` +#### TypeScript + ```ts function minimumIncompatibility(nums: number[], k: number): number { const n = nums.length; @@ -367,6 +377,8 @@ function bitCount(i: number): number { } ``` +#### C# + ```cs public class Solution { public int MinimumIncompatibility(int[] nums, int k) { @@ -443,6 +455,8 @@ public class Solution { +#### Python3 + ```python class Solution: def minimumIncompatibility(self, nums: List[int], k: int) -> int: diff --git a/solution/1600-1699/1681.Minimum Incompatibility/README_EN.md b/solution/1600-1699/1681.Minimum Incompatibility/README_EN.md index 1dcb5a29480f3..be663193531e4 100644 --- a/solution/1600-1699/1681.Minimum Incompatibility/README_EN.md +++ b/solution/1600-1699/1681.Minimum Incompatibility/README_EN.md @@ -89,6 +89,8 @@ The time complexity is $O(3^n)$, and the space complexity is $O(2^n)$. Here, $n$ +#### Python3 + ```python class Solution: def minimumIncompatibility(self, nums: List[int], k: int) -> int: @@ -130,6 +132,8 @@ class Solution: return f[-1] if f[-1] != inf else -1 ``` +#### Java + ```java class Solution { public int minimumIncompatibility(int[] nums, int k) { @@ -186,6 +190,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -243,6 +249,8 @@ public: }; ``` +#### Go + ```go func minimumIncompatibility(nums []int, k int) int { n := len(nums) @@ -303,6 +311,8 @@ func minimumIncompatibility(nums []int, k int) int { } ``` +#### TypeScript + ```ts function minimumIncompatibility(nums: number[], k: number): number { const n = nums.length; @@ -365,6 +375,8 @@ function bitCount(i: number): number { } ``` +#### C# + ```cs public class Solution { public int MinimumIncompatibility(int[] nums, int k) { @@ -441,6 +453,8 @@ public class Solution { +#### Python3 + ```python class Solution: def minimumIncompatibility(self, nums: List[int], k: int) -> int: diff --git a/solution/1600-1699/1682.Longest Palindromic Subsequence II/README.md b/solution/1600-1699/1682.Longest Palindromic Subsequence II/README.md index 303d9af0892e4..3651a2cff9514 100644 --- a/solution/1600-1699/1682.Longest Palindromic Subsequence II/README.md +++ b/solution/1600-1699/1682.Longest Palindromic Subsequence II/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def longestPalindromeSubseq(self, s: str) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[][][] f; @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func longestPalindromeSubseq(s string) int { n := len(s) diff --git a/solution/1600-1699/1682.Longest Palindromic Subsequence II/README_EN.md b/solution/1600-1699/1682.Longest Palindromic Subsequence II/README_EN.md index 24ce48cc736f6..45226c31aa11c 100644 --- a/solution/1600-1699/1682.Longest Palindromic Subsequence II/README_EN.md +++ b/solution/1600-1699/1682.Longest Palindromic Subsequence II/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n^2 \times C)$. Where $n$ is the length of the string +#### Python3 + ```python class Solution: def longestPalindromeSubseq(self, s: str) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[][][] f; @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func longestPalindromeSubseq(s string) int { n := len(s) diff --git a/solution/1600-1699/1683.Invalid Tweets/README.md b/solution/1600-1699/1683.Invalid Tweets/README.md index a4002aebae0d9..fdecfc9fb2bbe 100644 --- a/solution/1600-1699/1683.Invalid Tweets/README.md +++ b/solution/1600-1699/1683.Invalid Tweets/README.md @@ -77,6 +77,8 @@ Tweets 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1600-1699/1683.Invalid Tweets/README_EN.md b/solution/1600-1699/1683.Invalid Tweets/README_EN.md index 9749ea1a09346..d7a3e7102fc21 100644 --- a/solution/1600-1699/1683.Invalid Tweets/README_EN.md +++ b/solution/1600-1699/1683.Invalid Tweets/README_EN.md @@ -76,6 +76,8 @@ For this problem, we can directly use the `CHAR_LENGTH` function to get the leng +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1600-1699/1684.Count the Number of Consistent Strings/README.md b/solution/1600-1699/1684.Count the Number of Consistent Strings/README.md index 1a2715cbcb2ca..866df5d11f411 100644 --- a/solution/1600-1699/1684.Count the Number of Consistent Strings/README.md +++ b/solution/1600-1699/1684.Count the Number of Consistent Strings/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def countConsistentStrings(self, allowed: str, words: List[str]) -> int: @@ -84,6 +86,8 @@ class Solution: return sum(all(c in s for c in w) for w in words) ``` +#### Java + ```java class Solution { public int countConsistentStrings(String allowed, String[] words) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func countConsistentStrings(allowed string, words []string) (ans int) { s := [26]bool{} @@ -152,6 +160,8 @@ func countConsistentStrings(allowed string, words []string) (ans int) { } ``` +#### TypeScript + ```ts function countConsistentStrings(allowed: string, words: string[]): number { const set = new Set([...allowed]); @@ -169,6 +179,8 @@ function countConsistentStrings(allowed: string, words: string[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_consistent_strings(allowed: String, words: Vec) -> i32 { @@ -191,6 +203,8 @@ impl Solution { } ``` +#### C + ```c int countConsistentStrings(char* allowed, char** words, int wordsSize) { int n = strlen(allowed); @@ -230,6 +244,8 @@ int countConsistentStrings(char* allowed, char** words, int wordsSize) { +#### Python3 + ```python class Solution: def countConsistentStrings(self, allowed: str, words: List[str]) -> int: @@ -240,6 +256,8 @@ class Solution: return sum((mask | f(w)) == mask for w in words) ``` +#### Java + ```java class Solution { public int countConsistentStrings(String allowed, String[] words) { @@ -263,6 +281,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -280,6 +300,8 @@ public: }; ``` +#### Go + ```go func countConsistentStrings(allowed string, words []string) (ans int) { f := func(w string) (mask int) { @@ -299,6 +321,8 @@ func countConsistentStrings(allowed string, words []string) (ans int) { } ``` +#### TypeScript + ```ts function countConsistentStrings(allowed: string, words: string[]): number { const helper = (s: string) => { @@ -319,6 +343,8 @@ function countConsistentStrings(allowed: string, words: string[]): number { } ``` +#### Rust + ```rust impl Solution { fn helper(s: &String) -> i32 { @@ -342,6 +368,8 @@ impl Solution { } ``` +#### C + ```c int helper(char* s) { int res = 0; diff --git a/solution/1600-1699/1684.Count the Number of Consistent Strings/README_EN.md b/solution/1600-1699/1684.Count the Number of Consistent Strings/README_EN.md index a7b6295b8a4bf..bfd62009bf747 100644 --- a/solution/1600-1699/1684.Count the Number of Consistent Strings/README_EN.md +++ b/solution/1600-1699/1684.Count the Number of Consistent Strings/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(m)$, and the space complexity is $O(C)$. Here, $m$ is +#### Python3 + ```python class Solution: def countConsistentStrings(self, allowed: str, words: List[str]) -> int: @@ -82,6 +84,8 @@ class Solution: return sum(all(c in s for c in w) for w in words) ``` +#### Java + ```java class Solution { public int countConsistentStrings(String allowed, String[] words) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func countConsistentStrings(allowed string, words []string) (ans int) { s := [26]bool{} @@ -150,6 +158,8 @@ func countConsistentStrings(allowed string, words []string) (ans int) { } ``` +#### TypeScript + ```ts function countConsistentStrings(allowed: string, words: string[]): number { const set = new Set([...allowed]); @@ -167,6 +177,8 @@ function countConsistentStrings(allowed: string, words: string[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_consistent_strings(allowed: String, words: Vec) -> i32 { @@ -189,6 +201,8 @@ impl Solution { } ``` +#### C + ```c int countConsistentStrings(char* allowed, char** words, int wordsSize) { int n = strlen(allowed); @@ -228,6 +242,8 @@ The time complexity is $O(m)$, where $m$ is the total length of all strings. The +#### Python3 + ```python class Solution: def countConsistentStrings(self, allowed: str, words: List[str]) -> int: @@ -238,6 +254,8 @@ class Solution: return sum((mask | f(w)) == mask for w in words) ``` +#### Java + ```java class Solution { public int countConsistentStrings(String allowed, String[] words) { @@ -261,6 +279,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -278,6 +298,8 @@ public: }; ``` +#### Go + ```go func countConsistentStrings(allowed string, words []string) (ans int) { f := func(w string) (mask int) { @@ -297,6 +319,8 @@ func countConsistentStrings(allowed string, words []string) (ans int) { } ``` +#### TypeScript + ```ts function countConsistentStrings(allowed: string, words: string[]): number { const helper = (s: string) => { @@ -317,6 +341,8 @@ function countConsistentStrings(allowed: string, words: string[]): number { } ``` +#### Rust + ```rust impl Solution { fn helper(s: &String) -> i32 { @@ -340,6 +366,8 @@ impl Solution { } ``` +#### C + ```c int helper(char* s) { int res = 0; diff --git a/solution/1600-1699/1685.Sum of Absolute Differences in a Sorted Array/README.md b/solution/1600-1699/1685.Sum of Absolute Differences in a Sorted Array/README.md index d8a665d5a5c1b..f28625483d839 100644 --- a/solution/1600-1699/1685.Sum of Absolute Differences in a Sorted Array/README.md +++ b/solution/1600-1699/1685.Sum of Absolute Differences in a Sorted Array/README.md @@ -71,6 +71,8 @@ result[2] = |5-2| + |5-3| + |5-5| = 3 + 2 + 0 = 5。 +#### Python3 + ```python class Solution: def getSumAbsoluteDifferences(self, nums: List[int]) -> List[int]: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] getSumAbsoluteDifferences(int[] nums) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func getSumAbsoluteDifferences(nums []int) (ans []int) { var s, t int @@ -135,6 +143,8 @@ func getSumAbsoluteDifferences(nums []int) (ans []int) { } ``` +#### TypeScript + ```ts function getSumAbsoluteDifferences(nums: number[]): number[] { const s = nums.reduce((a, b) => a + b); @@ -150,6 +160,8 @@ function getSumAbsoluteDifferences(nums: number[]): number[] { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -169,6 +181,8 @@ var getSumAbsoluteDifferences = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int[] GetSumAbsoluteDifferences(int[] nums) { diff --git a/solution/1600-1699/1685.Sum of Absolute Differences in a Sorted Array/README_EN.md b/solution/1600-1699/1685.Sum of Absolute Differences in a Sorted Array/README_EN.md index 20735db33e43f..de54145b84ed3 100644 --- a/solution/1600-1699/1685.Sum of Absolute Differences in a Sorted Array/README_EN.md +++ b/solution/1600-1699/1685.Sum of Absolute Differences in a Sorted Array/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def getSumAbsoluteDifferences(self, nums: List[int]) -> List[int]: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] getSumAbsoluteDifferences(int[] nums) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func getSumAbsoluteDifferences(nums []int) (ans []int) { var s, t int @@ -133,6 +141,8 @@ func getSumAbsoluteDifferences(nums []int) (ans []int) { } ``` +#### TypeScript + ```ts function getSumAbsoluteDifferences(nums: number[]): number[] { const s = nums.reduce((a, b) => a + b); @@ -148,6 +158,8 @@ function getSumAbsoluteDifferences(nums: number[]): number[] { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -167,6 +179,8 @@ var getSumAbsoluteDifferences = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int[] GetSumAbsoluteDifferences(int[] nums) { diff --git a/solution/1600-1699/1686.Stone Game VI/README.md b/solution/1600-1699/1686.Stone Game VI/README.md index 24bcbed6c6a90..82defca0f21ec 100644 --- a/solution/1600-1699/1686.Stone Game VI/README.md +++ b/solution/1600-1699/1686.Stone Game VI/README.md @@ -99,6 +99,8 @@ Bob 会获胜。 +#### Python3 + ```python class Solution: def stoneGameVI(self, aliceValues: List[int], bobValues: List[int]) -> int: @@ -113,6 +115,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { public int stoneGameVI(int[] aliceValues, int[] bobValues) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go func stoneGameVI(aliceValues []int, bobValues []int) int { vals := make([][2]int, len(aliceValues)) @@ -192,6 +200,8 @@ func stoneGameVI(aliceValues []int, bobValues []int) int { } ``` +#### TypeScript + ```ts function stoneGameVI(aliceValues: number[], bobValues: number[]): number { const n = aliceValues.length; diff --git a/solution/1600-1699/1686.Stone Game VI/README_EN.md b/solution/1600-1699/1686.Stone Game VI/README_EN.md index 693352cc5a99b..cd8ed9be1220e 100644 --- a/solution/1600-1699/1686.Stone Game VI/README_EN.md +++ b/solution/1600-1699/1686.Stone Game VI/README_EN.md @@ -97,6 +97,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$, +#### Python3 + ```python class Solution: def stoneGameVI(self, aliceValues: List[int], bobValues: List[int]) -> int: @@ -111,6 +113,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { public int stoneGameVI(int[] aliceValues, int[] bobValues) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func stoneGameVI(aliceValues []int, bobValues []int) int { vals := make([][2]int, len(aliceValues)) @@ -190,6 +198,8 @@ func stoneGameVI(aliceValues []int, bobValues []int) int { } ``` +#### TypeScript + ```ts function stoneGameVI(aliceValues: number[], bobValues: number[]): number { const n = aliceValues.length; diff --git a/solution/1600-1699/1687.Delivering Boxes from Storage to Ports/README.md b/solution/1600-1699/1687.Delivering Boxes from Storage to Ports/README.md index 5ceb8df4ff025..652b8db2dea7a 100644 --- a/solution/1600-1699/1687.Delivering Boxes from Storage to Ports/README.md +++ b/solution/1600-1699/1687.Delivering Boxes from Storage to Ports/README.md @@ -140,6 +140,8 @@ $$ +#### Python3 + ```python # 33/39 个通过测试用例,超出时间限制 class Solution: @@ -159,6 +161,8 @@ class Solution: return f[n] ``` +#### Java + ```java // 35/39 个通过测试用例,超出时间限制 class Solution { @@ -188,6 +192,8 @@ class Solution { } ``` +#### C++ + ```cpp // 35/39 个通过测试用例,超出时间限制 class Solution { @@ -217,6 +223,8 @@ public: }; ``` +#### Go + ```go // 35/39 个通过测试用例,超出时间限制 func boxDelivering(boxes [][]int, portsCount int, maxBoxes int, maxWeight int) int { @@ -261,6 +269,8 @@ $$ +#### Python3 + ```python class Solution: def boxDelivering( @@ -284,6 +294,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int boxDelivering(int[][] boxes, int portsCount, int maxBoxes, int maxWeight) { @@ -320,6 +332,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -348,6 +362,8 @@ public: }; ``` +#### Go + ```go func boxDelivering(boxes [][]int, portsCount int, maxBoxes int, maxWeight int) int { n := len(boxes) diff --git a/solution/1600-1699/1687.Delivering Boxes from Storage to Ports/README_EN.md b/solution/1600-1699/1687.Delivering Boxes from Storage to Ports/README_EN.md index 503979d386a24..4307ebf39c334 100644 --- a/solution/1600-1699/1687.Delivering Boxes from Storage to Ports/README_EN.md +++ b/solution/1600-1699/1687.Delivering Boxes from Storage to Ports/README_EN.md @@ -240,6 +240,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def boxDelivering( @@ -263,6 +265,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int boxDelivering(int[][] boxes, int portsCount, int maxBoxes, int maxWeight) { @@ -299,6 +303,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -327,6 +333,8 @@ public: }; ``` +#### Go + ```go func boxDelivering(boxes [][]int, portsCount int, maxBoxes int, maxWeight int) int { n := len(boxes) diff --git a/solution/1600-1699/1688.Count of Matches in Tournament/README.md b/solution/1600-1699/1688.Count of Matches in Tournament/README.md index 2eb570bcab6c9..3ba8920450637 100644 --- a/solution/1600-1699/1688.Count of Matches in Tournament/README.md +++ b/solution/1600-1699/1688.Count of Matches in Tournament/README.md @@ -75,12 +75,16 @@ tags: +#### Python3 + ```python class Solution: def numberOfMatches(self, n: int) -> int: return n - 1 ``` +#### Java + ```java class Solution { public int numberOfMatches(int n) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -98,18 +104,24 @@ public: }; ``` +#### Go + ```go func numberOfMatches(n int) int { return n - 1 } ``` +#### TypeScript + ```ts function numberOfMatches(n: number): number { return n - 1; } ``` +#### JavaScript + ```js /** * @param {number} n diff --git a/solution/1600-1699/1688.Count of Matches in Tournament/README_EN.md b/solution/1600-1699/1688.Count of Matches in Tournament/README_EN.md index 90aa656e1fd28..d0926af8d4867 100644 --- a/solution/1600-1699/1688.Count of Matches in Tournament/README_EN.md +++ b/solution/1600-1699/1688.Count of Matches in Tournament/README_EN.md @@ -75,12 +75,16 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def numberOfMatches(self, n: int) -> int: return n - 1 ``` +#### Java + ```java class Solution { public int numberOfMatches(int n) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -98,18 +104,24 @@ public: }; ``` +#### Go + ```go func numberOfMatches(n int) int { return n - 1 } ``` +#### TypeScript + ```ts function numberOfMatches(n: number): number { return n - 1; } ``` +#### JavaScript + ```js /** * @param {number} n diff --git a/solution/1600-1699/1689.Partitioning Into Minimum Number Of Deci-Binary Numbers/README.md b/solution/1600-1699/1689.Partitioning Into Minimum Number Of Deci-Binary Numbers/README.md index 1f92071e8a20b..4ba2a0e239d36 100644 --- a/solution/1600-1699/1689.Partitioning Into Minimum Number Of Deci-Binary Numbers/README.md +++ b/solution/1600-1699/1689.Partitioning Into Minimum Number Of Deci-Binary Numbers/README.md @@ -68,12 +68,16 @@ tags: +#### Python3 + ```python class Solution: def minPartitions(self, n: str) -> int: return int(max(n)) ``` +#### Java + ```java class Solution { public int minPartitions(String n) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -99,6 +105,8 @@ public: }; ``` +#### Go + ```go func minPartitions(n string) (ans int) { for _, c := range n { @@ -110,12 +118,16 @@ func minPartitions(n string) (ans int) { } ``` +#### TypeScript + ```ts function minPartitions(n: string): number { return Math.max(...n.split('').map(d => parseInt(d))); } ``` +#### Rust + ```rust impl Solution { pub fn min_partitions(n: String) -> i32 { @@ -128,6 +140,8 @@ impl Solution { } ``` +#### C + ```c int minPartitions(char* n) { int ans = 0; diff --git a/solution/1600-1699/1689.Partitioning Into Minimum Number Of Deci-Binary Numbers/README_EN.md b/solution/1600-1699/1689.Partitioning Into Minimum Number Of Deci-Binary Numbers/README_EN.md index b410213ee6723..e42f990c1941e 100644 --- a/solution/1600-1699/1689.Partitioning Into Minimum Number Of Deci-Binary Numbers/README_EN.md +++ b/solution/1600-1699/1689.Partitioning Into Minimum Number Of Deci-Binary Numbers/README_EN.md @@ -69,12 +69,16 @@ The time complexity is $O(n)$, where $n$ is the length of the string. The space +#### Python3 + ```python class Solution: def minPartitions(self, n: str) -> int: return int(max(n)) ``` +#### Java + ```java class Solution { public int minPartitions(String n) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -100,6 +106,8 @@ public: }; ``` +#### Go + ```go func minPartitions(n string) (ans int) { for _, c := range n { @@ -111,12 +119,16 @@ func minPartitions(n string) (ans int) { } ``` +#### TypeScript + ```ts function minPartitions(n: string): number { return Math.max(...n.split('').map(d => parseInt(d))); } ``` +#### Rust + ```rust impl Solution { pub fn min_partitions(n: String) -> i32 { @@ -129,6 +141,8 @@ impl Solution { } ``` +#### C + ```c int minPartitions(char* n) { int ans = 0; diff --git a/solution/1600-1699/1690.Stone Game VII/README.md b/solution/1600-1699/1690.Stone Game VII/README.md index 46dd0d8a2c92c..6269a02053574 100644 --- a/solution/1600-1699/1690.Stone Game VII/README.md +++ b/solution/1600-1699/1690.Stone Game VII/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def stoneGameVII(self, stones: List[int]) -> int: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] s; @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func stoneGameVII(stones []int) int { n := len(stones) @@ -184,6 +192,8 @@ func stoneGameVII(stones []int) int { } ``` +#### TypeScript + ```ts function stoneGameVII(stones: number[]): number { const n = stones.length; @@ -231,6 +241,8 @@ $$ +#### Python3 + ```python class Solution: def stoneGameVII(self, stones: List[int]) -> int: @@ -245,6 +257,8 @@ class Solution: return f[0][-1] ``` +#### Java + ```java class Solution { public int stoneGameVII(int[] stones) { @@ -266,6 +280,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -290,6 +306,8 @@ public: }; ``` +#### Go + ```go func stoneGameVII(stones []int) int { n := len(stones) @@ -310,6 +328,8 @@ func stoneGameVII(stones []int) int { } ``` +#### TypeScript + ```ts function stoneGameVII(stones: number[]): number { const n = stones.length; diff --git a/solution/1600-1699/1690.Stone Game VII/README_EN.md b/solution/1600-1699/1690.Stone Game VII/README_EN.md index 8c1640ed2f18d..269edbe676fbc 100644 --- a/solution/1600-1699/1690.Stone Game VII/README_EN.md +++ b/solution/1600-1699/1690.Stone Game VII/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$. Here, $n$ +#### Python3 + ```python class Solution: def stoneGameVII(self, stones: List[int]) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] s; @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func stoneGameVII(stones []int) int { n := len(stones) @@ -182,6 +190,8 @@ func stoneGameVII(stones []int) int { } ``` +#### TypeScript + ```ts function stoneGameVII(stones: number[]): number { const n = stones.length; @@ -229,6 +239,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$. Here, $n$ +#### Python3 + ```python class Solution: def stoneGameVII(self, stones: List[int]) -> int: @@ -243,6 +255,8 @@ class Solution: return f[0][-1] ``` +#### Java + ```java class Solution { public int stoneGameVII(int[] stones) { @@ -264,6 +278,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -288,6 +304,8 @@ public: }; ``` +#### Go + ```go func stoneGameVII(stones []int) int { n := len(stones) @@ -308,6 +326,8 @@ func stoneGameVII(stones []int) int { } ``` +#### TypeScript + ```ts function stoneGameVII(stones: number[]): number { const n = stones.length; diff --git a/solution/1600-1699/1691.Maximum Height by Stacking Cuboids/README.md b/solution/1600-1699/1691.Maximum Height by Stacking Cuboids/README.md index cc1a9ac7a0c43..4f33395dbff27 100644 --- a/solution/1600-1699/1691.Maximum Height by Stacking Cuboids/README.md +++ b/solution/1600-1699/1691.Maximum Height by Stacking Cuboids/README.md @@ -103,6 +103,8 @@ $$ +#### Python3 + ```python class Solution: def maxHeight(self, cuboids: List[List[int]]) -> int: @@ -119,6 +121,8 @@ class Solution: return max(f) ``` +#### Java + ```java class Solution { public int maxHeight(int[][] cuboids) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func maxHeight(cuboids [][]int) int { for _, c := range cuboids { @@ -188,6 +196,8 @@ func maxHeight(cuboids [][]int) int { } ``` +#### TypeScript + ```ts function maxHeight(cuboids: number[][]): number { for (const c of cuboids) { @@ -215,6 +225,8 @@ function maxHeight(cuboids: number[][]): number { } ``` +#### JavaScript + ```js /** * @param {number[][]} cuboids diff --git a/solution/1600-1699/1691.Maximum Height by Stacking Cuboids/README_EN.md b/solution/1600-1699/1691.Maximum Height by Stacking Cuboids/README_EN.md index 93723039cfbd7..ab60787b03839 100644 --- a/solution/1600-1699/1691.Maximum Height by Stacking Cuboids/README_EN.md +++ b/solution/1600-1699/1691.Maximum Height by Stacking Cuboids/README_EN.md @@ -101,6 +101,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$. Here, $n$ i +#### Python3 + ```python class Solution: def maxHeight(self, cuboids: List[List[int]]) -> int: @@ -117,6 +119,8 @@ class Solution: return max(f) ``` +#### Java + ```java class Solution { public int maxHeight(int[][] cuboids) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func maxHeight(cuboids [][]int) int { for _, c := range cuboids { @@ -186,6 +194,8 @@ func maxHeight(cuboids [][]int) int { } ``` +#### TypeScript + ```ts function maxHeight(cuboids: number[][]): number { for (const c of cuboids) { @@ -213,6 +223,8 @@ function maxHeight(cuboids: number[][]): number { } ``` +#### JavaScript + ```js /** * @param {number[][]} cuboids diff --git a/solution/1600-1699/1692.Count Ways to Distribute Candies/README.md b/solution/1600-1699/1692.Count Ways to Distribute Candies/README.md index e3ef2277a0549..30b61199e0884 100644 --- a/solution/1600-1699/1692.Count Ways to Distribute Candies/README.md +++ b/solution/1600-1699/1692.Count Ways to Distribute Candies/README.md @@ -92,6 +92,8 @@ $$ +#### Python3 + ```python class Solution: def waysToDistribute(self, n: int, k: int) -> int: @@ -104,6 +106,8 @@ class Solution: return f[n][k] ``` +#### Java + ```java class Solution { public int waysToDistribute(int n, int k) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func waysToDistribute(n int, k int) int { f := make([][]int, n+1) @@ -155,6 +163,8 @@ func waysToDistribute(n int, k int) int { } ``` +#### TypeScript + ```ts function waysToDistribute(n: number, k: number): number { const mod = 10 ** 9 + 7; diff --git a/solution/1600-1699/1692.Count Ways to Distribute Candies/README_EN.md b/solution/1600-1699/1692.Count Ways to Distribute Candies/README_EN.md index d525f118dffed..1f7539949dd0e 100644 --- a/solution/1600-1699/1692.Count Ways to Distribute Candies/README_EN.md +++ b/solution/1600-1699/1692.Count Ways to Distribute Candies/README_EN.md @@ -90,6 +90,8 @@ The time complexity is $O(n \times k)$, and the space complexity is $O(n \times +#### Python3 + ```python class Solution: def waysToDistribute(self, n: int, k: int) -> int: @@ -102,6 +104,8 @@ class Solution: return f[n][k] ``` +#### Java + ```java class Solution { public int waysToDistribute(int n, int k) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func waysToDistribute(n int, k int) int { f := make([][]int, n+1) @@ -153,6 +161,8 @@ func waysToDistribute(n int, k int) int { } ``` +#### TypeScript + ```ts function waysToDistribute(n: number, k: number): number { const mod = 10 ** 9 + 7; diff --git a/solution/1600-1699/1693.Daily Leads and Partners/README.md b/solution/1600-1699/1693.Daily Leads and Partners/README.md index 52021fac1a0a2..58ac120ea009a 100644 --- a/solution/1600-1699/1693.Daily Leads and Partners/README.md +++ b/solution/1600-1699/1693.Daily Leads and Partners/README.md @@ -85,6 +85,8 @@ DailySales 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1600-1699/1693.Daily Leads and Partners/README_EN.md b/solution/1600-1699/1693.Daily Leads and Partners/README_EN.md index 8e6512772f9d4..16fcd36c482d3 100644 --- a/solution/1600-1699/1693.Daily Leads and Partners/README_EN.md +++ b/solution/1600-1699/1693.Daily Leads and Partners/README_EN.md @@ -86,6 +86,8 @@ We can use the `GROUP BY` statement to group the data by the `date_id` and `make +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1600-1699/1694.Reformat Phone Number/README.md b/solution/1600-1699/1694.Reformat Phone Number/README.md index c9de9f53425c1..b5f74d3a289d6 100644 --- a/solution/1600-1699/1694.Reformat Phone Number/README.md +++ b/solution/1600-1699/1694.Reformat Phone Number/README.md @@ -115,6 +115,8 @@ tags: +#### Python3 + ```python class Solution: def reformatNumber(self, number: str) -> str: @@ -129,6 +131,8 @@ class Solution: return "-".join(ans) ``` +#### Java + ```java class Solution { public String reformatNumber(String number) { @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func reformatNumber(number string) string { number = strings.ReplaceAll(number, " ", "") @@ -200,6 +208,8 @@ func reformatNumber(number string) string { } ``` +#### TypeScript + ```ts function reformatNumber(number: string): string { const cs = [...number].filter(c => c !== ' ' && c !== '-'); @@ -215,6 +225,8 @@ function reformatNumber(number: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn reformat_number(number: String) -> String { diff --git a/solution/1600-1699/1694.Reformat Phone Number/README_EN.md b/solution/1600-1699/1694.Reformat Phone Number/README_EN.md index 61749075e5232..90608de8f80c8 100644 --- a/solution/1600-1699/1694.Reformat Phone Number/README_EN.md +++ b/solution/1600-1699/1694.Reformat Phone Number/README_EN.md @@ -96,6 +96,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def reformatNumber(self, number: str) -> str: @@ -110,6 +112,8 @@ class Solution: return "-".join(ans) ``` +#### Java + ```java class Solution { public String reformatNumber(String number) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func reformatNumber(number string) string { number = strings.ReplaceAll(number, " ", "") @@ -181,6 +189,8 @@ func reformatNumber(number string) string { } ``` +#### TypeScript + ```ts function reformatNumber(number: string): string { const cs = [...number].filter(c => c !== ' ' && c !== '-'); @@ -196,6 +206,8 @@ function reformatNumber(number: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn reformat_number(number: String) -> String { diff --git a/solution/1600-1699/1695.Maximum Erasure Value/README.md b/solution/1600-1699/1695.Maximum Erasure Value/README.md index a1a77fcbb91ae..890ed06b4617a 100644 --- a/solution/1600-1699/1695.Maximum Erasure Value/README.md +++ b/solution/1600-1699/1695.Maximum Erasure Value/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def maximumUniqueSubarray(self, nums: List[int]) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumUniqueSubarray(int[] nums) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func maximumUniqueSubarray(nums []int) (ans int) { d := [10001]int{} @@ -144,6 +152,8 @@ func maximumUniqueSubarray(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function maximumUniqueSubarray(nums: number[]): number { const m = Math.max(...nums); @@ -181,6 +191,8 @@ function maximumUniqueSubarray(nums: number[]): number { +#### Python3 + ```python class Solution: def maximumUniqueSubarray(self, nums: List[int]) -> int: @@ -198,6 +210,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumUniqueSubarray(int[] nums) { @@ -217,6 +231,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -237,6 +253,8 @@ public: }; ``` +#### Go + ```go func maximumUniqueSubarray(nums []int) (ans int) { vis := map[int]bool{} @@ -255,6 +273,8 @@ func maximumUniqueSubarray(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function maximumUniqueSubarray(nums: number[]): number { const vis: Set = new Set(); diff --git a/solution/1600-1699/1695.Maximum Erasure Value/README_EN.md b/solution/1600-1699/1695.Maximum Erasure Value/README_EN.md index 35ef1cb5ec6fd..4a0e89c95882b 100644 --- a/solution/1600-1699/1695.Maximum Erasure Value/README_EN.md +++ b/solution/1600-1699/1695.Maximum Erasure Value/README_EN.md @@ -67,6 +67,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def maximumUniqueSubarray(self, nums: List[int]) -> int: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumUniqueSubarray(int[] nums) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func maximumUniqueSubarray(nums []int) (ans int) { d := [10001]int{} @@ -142,6 +150,8 @@ func maximumUniqueSubarray(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function maximumUniqueSubarray(nums: number[]): number { const m = Math.max(...nums); @@ -179,6 +189,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def maximumUniqueSubarray(self, nums: List[int]) -> int: @@ -196,6 +208,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumUniqueSubarray(int[] nums) { @@ -215,6 +229,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -235,6 +251,8 @@ public: }; ``` +#### Go + ```go func maximumUniqueSubarray(nums []int) (ans int) { vis := map[int]bool{} @@ -253,6 +271,8 @@ func maximumUniqueSubarray(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function maximumUniqueSubarray(nums: number[]): number { const vis: Set = new Set(); diff --git a/solution/1600-1699/1696.Jump Game VI/README.md b/solution/1600-1699/1696.Jump Game VI/README.md index 52d1c77573f9f..eb1741c1abe33 100644 --- a/solution/1600-1699/1696.Jump Game VI/README.md +++ b/solution/1600-1699/1696.Jump Game VI/README.md @@ -86,6 +86,8 @@ $$ +#### Python3 + ```python class Solution: def maxResult(self, nums: List[int], k: int) -> int: @@ -102,6 +104,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int maxResult(int[] nums, int k) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func maxResult(nums []int, k int) int { n := len(nums) @@ -224,6 +232,8 @@ func (q Deque) Get(i int) int { } ``` +#### TypeScript + ```ts function maxResult(nums: number[], k: number): number { const n = nums.length; diff --git a/solution/1600-1699/1696.Jump Game VI/README_EN.md b/solution/1600-1699/1696.Jump Game VI/README_EN.md index c19538d0f6859..e89272bfdadc0 100644 --- a/solution/1600-1699/1696.Jump Game VI/README_EN.md +++ b/solution/1600-1699/1696.Jump Game VI/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def maxResult(self, nums: List[int], k: int) -> int: @@ -100,6 +102,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int maxResult(int[] nums, int k) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func maxResult(nums []int, k int) int { n := len(nums) @@ -222,6 +230,8 @@ func (q Deque) Get(i int) int { } ``` +#### TypeScript + ```ts function maxResult(nums: number[], k: number): number { const n = nums.length; diff --git a/solution/1600-1699/1697.Checking Existence of Edge Length Limited Paths/README.md b/solution/1600-1699/1697.Checking Existence of Edge Length Limited Paths/README.md index 94f221daca30b..985b091722a28 100644 --- a/solution/1600-1699/1697.Checking Existence of Edge Length Limited Paths/README.md +++ b/solution/1600-1699/1697.Checking Existence of Edge Length Limited Paths/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def distanceLimitedPathsExist( @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] p; @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go func distanceLimitedPathsExist(n int, edgeList [][]int, queries [][]int) []bool { p := make([]int, n) @@ -210,6 +218,8 @@ func distanceLimitedPathsExist(n int, edgeList [][]int, queries [][]int) []bool } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -306,6 +316,8 @@ impl Solution { +#### Python3 + ```python p = list(range(n)) size = [1] * n @@ -325,6 +337,8 @@ def union(a, b): size[pb] += size[pa] ``` +#### Java + ```java int[] p = new int[n]; int[] size = new int[n]; @@ -351,6 +365,8 @@ void union(int a, int b) { } ``` +#### C++ + ```cpp vector p(n); iota(p.begin(), p.end(), 0); @@ -372,6 +388,8 @@ void unite(int a, int b) { } ``` +#### Go + ```go p := make([]int, n) size := make([]int, n) diff --git a/solution/1600-1699/1697.Checking Existence of Edge Length Limited Paths/README_EN.md b/solution/1600-1699/1697.Checking Existence of Edge Length Limited Paths/README_EN.md index 1dcdffd869bcd..312ff274aa889 100644 --- a/solution/1600-1699/1697.Checking Existence of Edge Length Limited Paths/README_EN.md +++ b/solution/1600-1699/1697.Checking Existence of Edge Length Limited Paths/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(m \times \log m + q \times \log q)$, where $m$ and $q$ +#### Python3 + ```python class Solution: def distanceLimitedPathsExist( @@ -103,6 +105,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] p; @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go func distanceLimitedPathsExist(n int, edgeList [][]int, queries [][]int) []bool { p := make([]int, n) @@ -208,6 +216,8 @@ func distanceLimitedPathsExist(n int, edgeList [][]int, queries [][]int) []bool } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -302,6 +312,8 @@ Below is a common template for Union-Find, which needs to be mastered proficient +#### Python3 + ```python p = list(range(n)) size = [1] * n @@ -320,6 +332,8 @@ def union(a, b): size[pb] += size[pa] ``` +#### Java + ```java int[] p = new int[n]; int[] size = new int[n]; @@ -345,6 +359,8 @@ void union(int a, int b) { } ``` +#### C++ + ```cpp vector p(n); iota(p.begin(), p.end(), 0); @@ -365,6 +381,8 @@ void unite(int a, int b) { } ``` +#### Go + ```go p := make([]int, n) size := make([]int, n) diff --git a/solution/1600-1699/1698.Number of Distinct Substrings in a String/README.md b/solution/1600-1699/1698.Number of Distinct Substrings in a String/README.md index 63bb40687c1d7..401cb0165a3e6 100644 --- a/solution/1600-1699/1698.Number of Distinct Substrings in a String/README.md +++ b/solution/1600-1699/1698.Number of Distinct Substrings in a String/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def countDistinct(self, s: str) -> int: @@ -73,6 +75,8 @@ class Solution: return len({s[i:j] for i in range(n) for j in range(i + 1, n + 1)}) ``` +#### Java + ```java class Solution { public int countDistinct(String s) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func countDistinct(s string) int { ss := map[string]struct{}{} @@ -138,6 +146,8 @@ func countDistinct(s string) int { +#### Python3 + ```python class Solution: def countDistinct(self, s: str) -> int: @@ -157,6 +167,8 @@ class Solution: return len(ss) ``` +#### Java + ```java class Solution { public int countDistinct(String s) { @@ -181,6 +193,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -206,6 +220,8 @@ public: }; ``` +#### Go + ```go func countDistinct(s string) int { n := len(s) diff --git a/solution/1600-1699/1698.Number of Distinct Substrings in a String/README_EN.md b/solution/1600-1699/1698.Number of Distinct Substrings in a String/README_EN.md index 64668088d21af..d8392604dfd04 100644 --- a/solution/1600-1699/1698.Number of Distinct Substrings in a String/README_EN.md +++ b/solution/1600-1699/1698.Number of Distinct Substrings in a String/README_EN.md @@ -65,6 +65,8 @@ The time complexity is $O(n^3)$, and the space complexity is $O(n^2)$. Here, $n$ +#### Python3 + ```python class Solution: def countDistinct(self, s: str) -> int: @@ -72,6 +74,8 @@ class Solution: return len({s[i:j] for i in range(n) for j in range(i + 1, n + 1)}) ``` +#### Java + ```java class Solution { public int countDistinct(String s) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func countDistinct(s string) int { ss := map[string]struct{}{} @@ -137,6 +145,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$. Here, $n$ +#### Python3 + ```python class Solution: def countDistinct(self, s: str) -> int: @@ -156,6 +166,8 @@ class Solution: return len(ss) ``` +#### Java + ```java class Solution { public int countDistinct(String s) { @@ -180,6 +192,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -205,6 +219,8 @@ public: }; ``` +#### Go + ```go func countDistinct(s string) int { n := len(s) diff --git a/solution/1600-1699/1699.Number of Calls Between Two Persons/README.md b/solution/1600-1699/1699.Number of Calls Between Two Persons/README.md index f0e6d18ebc508..971b74fcebd3e 100644 --- a/solution/1600-1699/1699.Number of Calls Between Two Persons/README.md +++ b/solution/1600-1699/1699.Number of Calls Between Two Persons/README.md @@ -82,6 +82,8 @@ Calls 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -93,6 +95,8 @@ FROM Calls GROUP BY 1, 2; ``` +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1600-1699/1699.Number of Calls Between Two Persons/README_EN.md b/solution/1600-1699/1699.Number of Calls Between Two Persons/README_EN.md index cccec46c8f8d3..2b1c319c1261a 100644 --- a/solution/1600-1699/1699.Number of Calls Between Two Persons/README_EN.md +++ b/solution/1600-1699/1699.Number of Calls Between Two Persons/README_EN.md @@ -82,6 +82,8 @@ We can use the `if` function or the `least` and `greatest` functions to convert +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -93,6 +95,8 @@ FROM Calls GROUP BY 1, 2; ``` +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1700-1799/1700.Number of Students Unable to Eat Lunch/README.md b/solution/1700-1799/1700.Number of Students Unable to Eat Lunch/README.md index 3665eeb5e3997..1aa41ea931539 100644 --- a/solution/1700-1799/1700.Number of Students Unable to Eat Lunch/README.md +++ b/solution/1700-1799/1700.Number of Students Unable to Eat Lunch/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def countStudents(self, students: List[int], sandwiches: List[int]) -> int: @@ -99,6 +101,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { public int countStudents(int[] students, int[] sandwiches) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func countStudents(students []int, sandwiches []int) int { cnt := [2]int{} @@ -148,6 +156,8 @@ func countStudents(students []int, sandwiches []int) int { } ``` +#### TypeScript + ```ts function countStudents(students: number[], sandwiches: number[]): number { const count = [0, 0]; @@ -164,6 +174,8 @@ function countStudents(students: number[], sandwiches: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_students(students: Vec, sandwiches: Vec) -> i32 { @@ -183,6 +195,8 @@ impl Solution { } ``` +#### C + ```c int countStudents(int* students, int studentsSize, int* sandwiches, int sandwichesSize) { int count[2] = {0}; diff --git a/solution/1700-1799/1700.Number of Students Unable to Eat Lunch/README_EN.md b/solution/1700-1799/1700.Number of Students Unable to Eat Lunch/README_EN.md index 23daf1c0c4364..42e2f3e222074 100644 --- a/solution/1700-1799/1700.Number of Students Unable to Eat Lunch/README_EN.md +++ b/solution/1700-1799/1700.Number of Students Unable to Eat Lunch/README_EN.md @@ -89,6 +89,8 @@ The time complexity is $O(n)$, where $n$ is the number of sandwiches. The space +#### Python3 + ```python class Solution: def countStudents(self, students: List[int], sandwiches: List[int]) -> int: @@ -100,6 +102,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { public int countStudents(int[] students, int[] sandwiches) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func countStudents(students []int, sandwiches []int) int { cnt := [2]int{} @@ -149,6 +157,8 @@ func countStudents(students []int, sandwiches []int) int { } ``` +#### TypeScript + ```ts function countStudents(students: number[], sandwiches: number[]): number { const count = [0, 0]; @@ -165,6 +175,8 @@ function countStudents(students: number[], sandwiches: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_students(students: Vec, sandwiches: Vec) -> i32 { @@ -184,6 +196,8 @@ impl Solution { } ``` +#### C + ```c int countStudents(int* students, int studentsSize, int* sandwiches, int sandwichesSize) { int count[2] = {0}; diff --git a/solution/1700-1799/1701.Average Waiting Time/README.md b/solution/1700-1799/1701.Average Waiting Time/README.md index 15e9e6eec387c..dc589cf6d6791 100644 --- a/solution/1700-1799/1701.Average Waiting Time/README.md +++ b/solution/1700-1799/1701.Average Waiting Time/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def averageWaitingTime(self, customers: List[List[int]]) -> float: @@ -97,6 +99,8 @@ class Solution: return tot / len(customers) ``` +#### Java + ```java class Solution { public double averageWaitingTime(int[][] customers) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func averageWaitingTime(customers [][]int) float64 { tot, t := 0, 0 @@ -140,6 +148,8 @@ func averageWaitingTime(customers [][]int) float64 { } ``` +#### TypeScript + ```ts function averageWaitingTime(customers: number[][]): number { let [tot, t] = [0, 0]; diff --git a/solution/1700-1799/1701.Average Waiting Time/README_EN.md b/solution/1700-1799/1701.Average Waiting Time/README_EN.md index d5fb4e630994f..12bca99037400 100644 --- a/solution/1700-1799/1701.Average Waiting Time/README_EN.md +++ b/solution/1700-1799/1701.Average Waiting Time/README_EN.md @@ -85,6 +85,8 @@ The time complexity is $O(n)$, where $n$ is the length of the customer array `cu +#### Python3 + ```python class Solution: def averageWaitingTime(self, customers: List[List[int]]) -> float: @@ -95,6 +97,8 @@ class Solution: return tot / len(customers) ``` +#### Java + ```java class Solution { public double averageWaitingTime(int[][] customers) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func averageWaitingTime(customers [][]int) float64 { tot, t := 0, 0 @@ -138,6 +146,8 @@ func averageWaitingTime(customers [][]int) float64 { } ``` +#### TypeScript + ```ts function averageWaitingTime(customers: number[][]): number { let [tot, t] = [0, 0]; diff --git a/solution/1700-1799/1702.Maximum Binary String After Change/README.md b/solution/1700-1799/1702.Maximum Binary String After Change/README.md index dc0886ae6cae1..60b6c39ef7f11 100644 --- a/solution/1700-1799/1702.Maximum Binary String After Change/README.md +++ b/solution/1700-1799/1702.Maximum Binary String After Change/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def maximumBinaryString(self, binary: str) -> str: @@ -98,6 +100,8 @@ class Solution: return '1' * k + '0' + '1' * (len(binary) - k - 1) ``` +#### Java + ```java class Solution { public String maximumBinaryString(String binary) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func maximumBinaryString(binary string) string { k := strings.IndexByte(binary, '0') @@ -158,6 +166,8 @@ func maximumBinaryString(binary string) string { } ``` +#### TypeScript + ```ts function maximumBinaryString(binary: string): string { let k = binary.indexOf('0'); @@ -169,6 +179,8 @@ function maximumBinaryString(binary: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn maximum_binary_string(binary: String) -> String { @@ -186,6 +198,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public string MaximumBinaryString(string binary) { diff --git a/solution/1700-1799/1702.Maximum Binary String After Change/README_EN.md b/solution/1700-1799/1702.Maximum Binary String After Change/README_EN.md index f882e14cfab99..1517cfb7b0d03 100644 --- a/solution/1700-1799/1702.Maximum Binary String After Change/README_EN.md +++ b/solution/1700-1799/1702.Maximum Binary String After Change/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def maximumBinaryString(self, binary: str) -> str: @@ -96,6 +98,8 @@ class Solution: return '1' * k + '0' + '1' * (len(binary) - k - 1) ``` +#### Java + ```java class Solution { public String maximumBinaryString(String binary) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func maximumBinaryString(binary string) string { k := strings.IndexByte(binary, '0') @@ -156,6 +164,8 @@ func maximumBinaryString(binary string) string { } ``` +#### TypeScript + ```ts function maximumBinaryString(binary: string): string { let k = binary.indexOf('0'); @@ -167,6 +177,8 @@ function maximumBinaryString(binary: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn maximum_binary_string(binary: String) -> String { @@ -184,6 +196,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public string MaximumBinaryString(string binary) { diff --git a/solution/1700-1799/1703.Minimum Adjacent Swaps for K Consecutive Ones/README.md b/solution/1700-1799/1703.Minimum Adjacent Swaps for K Consecutive Ones/README.md index b5c55139b9709..3d4b873ca4d9e 100644 --- a/solution/1700-1799/1703.Minimum Adjacent Swaps for K Consecutive Ones/README.md +++ b/solution/1700-1799/1703.Minimum Adjacent Swaps for K Consecutive Ones/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def minMoves(self, nums: List[int], k: int) -> int: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minMoves(int[] nums, int k) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func minMoves(nums []int, k int) int { arr := []int{} diff --git a/solution/1700-1799/1703.Minimum Adjacent Swaps for K Consecutive Ones/README_EN.md b/solution/1700-1799/1703.Minimum Adjacent Swaps for K Consecutive Ones/README_EN.md index 073c5d6571452..7f2d2f6b04f81 100644 --- a/solution/1700-1799/1703.Minimum Adjacent Swaps for K Consecutive Ones/README_EN.md +++ b/solution/1700-1799/1703.Minimum Adjacent Swaps for K Consecutive Ones/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n)$, and the space complexity is $O(m)$. Here, $n$ and +#### Python3 + ```python class Solution: def minMoves(self, nums: List[int], k: int) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minMoves(int[] nums, int k) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func minMoves(nums []int, k int) int { arr := []int{} diff --git a/solution/1700-1799/1704.Determine if String Halves Are Alike/README.md b/solution/1700-1799/1704.Determine if String Halves Are Alike/README.md index 7bb0dbd960673..44e2ebe279f44 100644 --- a/solution/1700-1799/1704.Determine if String Halves Are Alike/README.md +++ b/solution/1700-1799/1704.Determine if String Halves Are Alike/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def halvesAreAlike(self, s: str) -> bool: @@ -79,6 +81,8 @@ class Solution: return cnt == 0 ``` +#### Java + ```java class Solution { private static final Set VOWELS @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func halvesAreAlike(s string) bool { vowels := map[byte]bool{} @@ -129,6 +137,8 @@ func halvesAreAlike(s string) bool { } ``` +#### TypeScript + ```ts function halvesAreAlike(s: string): boolean { const set = new Set(['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']); @@ -142,6 +152,8 @@ function halvesAreAlike(s: string): boolean { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -165,6 +177,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -181,6 +195,8 @@ var halvesAreAlike = function (s) { }; ``` +#### PHP + ```php class Solution { /** @@ -212,6 +228,8 @@ class Solution { +#### Python3 + ```python class Solution: def halvesAreAlike(self, s: str) -> bool: diff --git a/solution/1700-1799/1704.Determine if String Halves Are Alike/README_EN.md b/solution/1700-1799/1704.Determine if String Halves Are Alike/README_EN.md index 321b690b63e3b..058682b874092 100644 --- a/solution/1700-1799/1704.Determine if String Halves Are Alike/README_EN.md +++ b/solution/1700-1799/1704.Determine if String Halves Are Alike/README_EN.md @@ -66,6 +66,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string. The space +#### Python3 + ```python class Solution: def halvesAreAlike(self, s: str) -> bool: @@ -77,6 +79,8 @@ class Solution: return cnt == 0 ``` +#### Java + ```java class Solution { private static final Set VOWELS @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func halvesAreAlike(s string) bool { vowels := map[byte]bool{} @@ -127,6 +135,8 @@ func halvesAreAlike(s string) bool { } ``` +#### TypeScript + ```ts function halvesAreAlike(s: string): boolean { const set = new Set(['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']); @@ -140,6 +150,8 @@ function halvesAreAlike(s: string): boolean { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -163,6 +175,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -179,6 +193,8 @@ var halvesAreAlike = function (s) { }; ``` +#### PHP + ```php class Solution { /** @@ -210,6 +226,8 @@ class Solution { +#### Python3 + ```python class Solution: def halvesAreAlike(self, s: str) -> bool: diff --git a/solution/1700-1799/1705.Maximum Number of Eaten Apples/README.md b/solution/1700-1799/1705.Maximum Number of Eaten Apples/README.md index f5b448d4502d5..5736d7cce86de 100644 --- a/solution/1700-1799/1705.Maximum Number of Eaten Apples/README.md +++ b/solution/1700-1799/1705.Maximum Number of Eaten Apples/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def eatenApples(self, apples: List[int], days: List[int]) -> int: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int eatenApples(int[] apples, int[] days) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp using pii = pair; @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func eatenApples(apples []int, days []int) int { var h hp diff --git a/solution/1700-1799/1705.Maximum Number of Eaten Apples/README_EN.md b/solution/1700-1799/1705.Maximum Number of Eaten Apples/README_EN.md index ee47e0203b52a..8fdc3f0e40064 100644 --- a/solution/1700-1799/1705.Maximum Number of Eaten Apples/README_EN.md +++ b/solution/1700-1799/1705.Maximum Number of Eaten Apples/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def eatenApples(self, apples: List[int], days: List[int]) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int eatenApples(int[] apples, int[] days) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp using pii = pair; @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func eatenApples(apples []int, days []int) int { var h hp diff --git a/solution/1700-1799/1706.Where Will the Ball Fall/README.md b/solution/1700-1799/1706.Where Will the Ball Fall/README.md index 239ef9c3cf696..5b28a84722165 100644 --- a/solution/1700-1799/1706.Where Will the Ball Fall/README.md +++ b/solution/1700-1799/1706.Where Will the Ball Fall/README.md @@ -97,6 +97,8 @@ b4 球开始放在第 4 列上,会卡在第 2、3 列和第 1 行之间的 "V" +#### Python3 + ```python class Solution: def findBall(self, grid: List[List[int]]) -> List[int]: @@ -117,6 +119,8 @@ class Solution: return [dfs(0, j) for j in range(n)] ``` +#### Java + ```java class Solution { private int m; @@ -155,6 +159,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -187,6 +193,8 @@ public: }; ``` +#### Go + ```go func findBall(grid [][]int) (ans []int) { m, n := len(grid), len(grid[0]) @@ -219,6 +227,8 @@ func findBall(grid [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function findBall(grid: number[][]): number[] { const m = grid.length; @@ -247,6 +257,8 @@ function findBall(grid: number[][]): number[] { } ``` +#### Rust + ```rust impl Solution { fn dfs(grid: &Vec>, i: usize, j: usize) -> i32 { diff --git a/solution/1700-1799/1706.Where Will the Ball Fall/README_EN.md b/solution/1700-1799/1706.Where Will the Ball Fall/README_EN.md index f4ff8b3cc8f5f..e0ac840dd1195 100644 --- a/solution/1700-1799/1706.Where Will the Ball Fall/README_EN.md +++ b/solution/1700-1799/1706.Where Will the Ball Fall/README_EN.md @@ -95,6 +95,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m)$. Wher +#### Python3 + ```python class Solution: def findBall(self, grid: List[List[int]]) -> List[int]: @@ -115,6 +117,8 @@ class Solution: return [dfs(0, j) for j in range(n)] ``` +#### Java + ```java class Solution { private int m; @@ -153,6 +157,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -185,6 +191,8 @@ public: }; ``` +#### Go + ```go func findBall(grid [][]int) (ans []int) { m, n := len(grid), len(grid[0]) @@ -217,6 +225,8 @@ func findBall(grid [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function findBall(grid: number[][]): number[] { const m = grid.length; @@ -245,6 +255,8 @@ function findBall(grid: number[][]): number[] { } ``` +#### Rust + ```rust impl Solution { fn dfs(grid: &Vec>, i: usize, j: usize) -> i32 { diff --git a/solution/1700-1799/1707.Maximum XOR With an Element From Array/README.md b/solution/1700-1799/1707.Maximum XOR With an Element From Array/README.md index 95126a946fa4b..26dcf2fea57a6 100644 --- a/solution/1700-1799/1707.Maximum XOR With an Element From Array/README.md +++ b/solution/1700-1799/1707.Maximum XOR With an Element From Array/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Trie: __slots__ = ["children"] @@ -114,6 +116,8 @@ class Solution: return ans ``` +#### Java + ```java class Trie { private Trie[] children = new Trie[2]; @@ -171,6 +175,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { private: @@ -232,6 +238,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [2]*Trie @@ -294,6 +302,8 @@ func maximizeXor(nums []int, queries [][]int) []int { } ``` +#### TypeScript + ```ts class Trie { children: (Trie | null)[]; diff --git a/solution/1700-1799/1707.Maximum XOR With an Element From Array/README_EN.md b/solution/1700-1799/1707.Maximum XOR With an Element From Array/README_EN.md index ce8b3620c8077..48b6e43efcc4e 100644 --- a/solution/1700-1799/1707.Maximum XOR With an Element From Array/README_EN.md +++ b/solution/1700-1799/1707.Maximum XOR With an Element From Array/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(m \times \log m + n \times (\log n + \log M))$, and th +#### Python3 + ```python class Trie: __slots__ = ["children"] @@ -114,6 +116,8 @@ class Solution: return ans ``` +#### Java + ```java class Trie { private Trie[] children = new Trie[2]; @@ -171,6 +175,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { private: @@ -232,6 +238,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [2]*Trie @@ -294,6 +302,8 @@ func maximizeXor(nums []int, queries [][]int) []int { } ``` +#### TypeScript + ```ts class Trie { children: (Trie | null)[]; diff --git a/solution/1700-1799/1708.Largest Subarray Length K/README.md b/solution/1700-1799/1708.Largest Subarray Length K/README.md index 9c17f95fd54ac..f2ac74ba51474 100644 --- a/solution/1700-1799/1708.Largest Subarray Length K/README.md +++ b/solution/1700-1799/1708.Largest Subarray Length K/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def largestSubarray(self, nums: List[int], k: int) -> List[int]: @@ -89,6 +91,8 @@ class Solution: return nums[i : i + k] ``` +#### Java + ```java class Solution { public int[] largestSubarray(int[] nums, int k) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func largestSubarray(nums []int, k int) []int { j := 0 @@ -125,6 +133,8 @@ func largestSubarray(nums []int, k int) []int { } ``` +#### TypeScript + ```ts function largestSubarray(nums: number[], k: number): number[] { let j = 0; @@ -137,6 +147,8 @@ function largestSubarray(nums: number[], k: number): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn largest_subarray(nums: Vec, k: i32) -> Vec { diff --git a/solution/1700-1799/1708.Largest Subarray Length K/README_EN.md b/solution/1700-1799/1708.Largest Subarray Length K/README_EN.md index abaf77e9b0d2f..8c66e9aa8196c 100644 --- a/solution/1700-1799/1708.Largest Subarray Length K/README_EN.md +++ b/solution/1700-1799/1708.Largest Subarray Length K/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. Ignoring th +#### Python3 + ```python class Solution: def largestSubarray(self, nums: List[int], k: int) -> List[int]: @@ -87,6 +89,8 @@ class Solution: return nums[i : i + k] ``` +#### Java + ```java class Solution { public int[] largestSubarray(int[] nums, int k) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func largestSubarray(nums []int, k int) []int { j := 0 @@ -123,6 +131,8 @@ func largestSubarray(nums []int, k int) []int { } ``` +#### TypeScript + ```ts function largestSubarray(nums: number[], k: number): number[] { let j = 0; @@ -135,6 +145,8 @@ function largestSubarray(nums: number[], k: number): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn largest_subarray(nums: Vec, k: i32) -> Vec { diff --git a/solution/1700-1799/1709.Biggest Window Between Visits/README.md b/solution/1700-1799/1709.Biggest Window Between Visits/README.md index 22124284d30dc..9797c9a959844 100644 --- a/solution/1700-1799/1709.Biggest Window Between Visits/README.md +++ b/solution/1700-1799/1709.Biggest Window Between Visits/README.md @@ -87,6 +87,8 @@ UserVisits 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1700-1799/1709.Biggest Window Between Visits/README_EN.md b/solution/1700-1799/1709.Biggest Window Between Visits/README_EN.md index 971cf4dbd04e3..409e3001dacd9 100644 --- a/solution/1700-1799/1709.Biggest Window Between Visits/README_EN.md +++ b/solution/1700-1799/1709.Biggest Window Between Visits/README_EN.md @@ -88,6 +88,8 @@ We can use the window function `LEAD` to obtain the date of the next visit for e +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1700-1799/1710.Maximum Units on a Truck/README.md b/solution/1700-1799/1710.Maximum Units on a Truck/README.md index 049b68516aaab..dbb767893437c 100644 --- a/solution/1700-1799/1710.Maximum Units on a Truck/README.md +++ b/solution/1700-1799/1710.Maximum Units on a Truck/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def maximumUnits(self, boxTypes: List[List[int]], truckSize: int) -> int: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumUnits(int[][] boxTypes, int truckSize) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func maximumUnits(boxTypes [][]int, truckSize int) (ans int) { sort.Slice(boxTypes, func(i, j int) bool { return boxTypes[i][1] > boxTypes[j][1] }) @@ -140,6 +148,8 @@ func maximumUnits(boxTypes [][]int, truckSize int) (ans int) { } ``` +#### TypeScript + ```ts function maximumUnits(boxTypes: number[][], truckSize: number): number { boxTypes.sort((a, b) => b[1] - a[1]); @@ -158,6 +168,8 @@ function maximumUnits(boxTypes: number[][], truckSize: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn maximum_units(mut box_types: Vec>, truck_size: i32) -> i32 { @@ -194,6 +206,8 @@ impl Solution { +#### Python3 + ```python class Solution: def maximumUnits(self, boxTypes: List[List[int]], truckSize: int) -> int: @@ -211,6 +225,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumUnits(int[][] boxTypes, int truckSize) { @@ -232,6 +248,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -254,6 +272,8 @@ public: }; ``` +#### Go + ```go func maximumUnits(boxTypes [][]int, truckSize int) (ans int) { cnt := [1001]int{} @@ -272,6 +292,8 @@ func maximumUnits(boxTypes [][]int, truckSize int) (ans int) { } ``` +#### TypeScript + ```ts function maximumUnits(boxTypes: number[][], truckSize: number): number { const cnt = new Array(1001).fill(0); diff --git a/solution/1700-1799/1710.Maximum Units on a Truck/README_EN.md b/solution/1700-1799/1710.Maximum Units on a Truck/README_EN.md index 5de2a0fd089d4..b08b30b77e361 100644 --- a/solution/1700-1799/1710.Maximum Units on a Truck/README_EN.md +++ b/solution/1700-1799/1710.Maximum Units on a Truck/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n \times \log n)$, where $n$ is the length of the two- +#### Python3 + ```python class Solution: def maximumUnits(self, boxTypes: List[List[int]], truckSize: int) -> int: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumUnits(int[][] boxTypes, int truckSize) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func maximumUnits(boxTypes [][]int, truckSize int) (ans int) { sort.Slice(boxTypes, func(i, j int) bool { return boxTypes[i][1] > boxTypes[j][1] }) @@ -139,6 +147,8 @@ func maximumUnits(boxTypes [][]int, truckSize int) (ans int) { } ``` +#### TypeScript + ```ts function maximumUnits(boxTypes: number[][], truckSize: number): number { boxTypes.sort((a, b) => b[1] - a[1]); @@ -157,6 +167,8 @@ function maximumUnits(boxTypes: number[][], truckSize: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn maximum_units(mut box_types: Vec>, truck_size: i32) -> i32 { @@ -193,6 +205,8 @@ The time complexity is $O(M)$, where $M$ is the maximum number of units. In this +#### Python3 + ```python class Solution: def maximumUnits(self, boxTypes: List[List[int]], truckSize: int) -> int: @@ -210,6 +224,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumUnits(int[][] boxTypes, int truckSize) { @@ -231,6 +247,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -253,6 +271,8 @@ public: }; ``` +#### Go + ```go func maximumUnits(boxTypes [][]int, truckSize int) (ans int) { cnt := [1001]int{} @@ -271,6 +291,8 @@ func maximumUnits(boxTypes [][]int, truckSize int) (ans int) { } ``` +#### TypeScript + ```ts function maximumUnits(boxTypes: number[][], truckSize: number): number { const cnt = new Array(1001).fill(0); diff --git a/solution/1700-1799/1711.Count Good Meals/README.md b/solution/1700-1799/1711.Count Good Meals/README.md index 0c20d9eed5670..d5326a3c94b16 100644 --- a/solution/1700-1799/1711.Count Good Meals/README.md +++ b/solution/1700-1799/1711.Count Good Meals/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def countPairs(self, deliciousness: List[int]) -> int: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func countPairs(deliciousness []int) (ans int) { mx := slices.Max(deliciousness) << 1 @@ -164,6 +172,8 @@ func countPairs(deliciousness []int) (ans int) { +#### Python3 + ```python class Solution: def countPairs(self, deliciousness: List[int]) -> int: @@ -178,6 +188,8 @@ class Solution: return (ans >> 1) % mod ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -205,6 +217,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -228,6 +242,8 @@ public: }; ``` +#### Go + ```go func countPairs(deliciousness []int) (ans int) { cnt := map[int]int{} diff --git a/solution/1700-1799/1711.Count Good Meals/README_EN.md b/solution/1700-1799/1711.Count Good Meals/README_EN.md index 6f9bd124e004a..34bd6819dcbf5 100644 --- a/solution/1700-1799/1711.Count Good Meals/README_EN.md +++ b/solution/1700-1799/1711.Count Good Meals/README_EN.md @@ -80,6 +80,8 @@ The time complexity is the same as the method above. +#### Python3 + ```python class Solution: def countPairs(self, deliciousness: List[int]) -> int: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func countPairs(deliciousness []int) (ans int) { mx := slices.Max(deliciousness) << 1 @@ -160,6 +168,8 @@ func countPairs(deliciousness []int) (ans int) { +#### Python3 + ```python class Solution: def countPairs(self, deliciousness: List[int]) -> int: @@ -174,6 +184,8 @@ class Solution: return (ans >> 1) % mod ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -201,6 +213,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -224,6 +238,8 @@ public: }; ``` +#### Go + ```go func countPairs(deliciousness []int) (ans int) { cnt := map[int]int{} diff --git a/solution/1700-1799/1712.Ways to Split Array Into Three Subarrays/README.md b/solution/1700-1799/1712.Ways to Split Array Into Three Subarrays/README.md index d8f78414e522d..798586267fd27 100644 --- a/solution/1700-1799/1712.Ways to Split Array Into Three Subarrays/README.md +++ b/solution/1700-1799/1712.Ways to Split Array Into Three Subarrays/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def waysToSplit(self, nums: List[int]) -> int: @@ -101,6 +103,8 @@ class Solution: return ans % mod ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func waysToSplit(nums []int) (ans int) { const mod int = 1e9 + 7 @@ -173,6 +181,8 @@ func waysToSplit(nums []int) (ans int) { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/1700-1799/1712.Ways to Split Array Into Three Subarrays/README_EN.md b/solution/1700-1799/1712.Ways to Split Array Into Three Subarrays/README_EN.md index 1bc51106d757b..fd17cf1f00ac6 100644 --- a/solution/1700-1799/1712.Ways to Split Array Into Three Subarrays/README_EN.md +++ b/solution/1700-1799/1712.Ways to Split Array Into Three Subarrays/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(n \times \log n)$, where $n$ is the length of the arra +#### Python3 + ```python class Solution: def waysToSplit(self, nums: List[int]) -> int: @@ -99,6 +101,8 @@ class Solution: return ans % mod ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func waysToSplit(nums []int) (ans int) { const mod int = 1e9 + 7 @@ -171,6 +179,8 @@ func waysToSplit(nums []int) (ans int) { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/1700-1799/1713.Minimum Operations to Make a Subsequence/README.md b/solution/1700-1799/1713.Minimum Operations to Make a Subsequence/README.md index e29db6a483aaf..f17384228f9a3 100644 --- a/solution/1700-1799/1713.Minimum Operations to Make a Subsequence/README.md +++ b/solution/1700-1799/1713.Minimum Operations to Make a Subsequence/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -116,6 +118,8 @@ class Solution: return ans ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -185,6 +189,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -248,6 +254,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int diff --git a/solution/1700-1799/1713.Minimum Operations to Make a Subsequence/README_EN.md b/solution/1700-1799/1713.Minimum Operations to Make a Subsequence/README_EN.md index e63705160e967..f1e46fb7318b1 100644 --- a/solution/1700-1799/1713.Minimum Operations to Make a Subsequence/README_EN.md +++ b/solution/1700-1799/1713.Minimum Operations to Make a Subsequence/README_EN.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -175,6 +179,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -238,6 +244,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int diff --git a/solution/1700-1799/1714.Sum Of Special Evenly-Spaced Elements In Array/README.md b/solution/1700-1799/1714.Sum Of Special Evenly-Spaced Elements In Array/README.md index ff44dd7351320..3ce9cce1a59ab 100644 --- a/solution/1700-1799/1714.Sum Of Special Evenly-Spaced Elements In Array/README.md +++ b/solution/1700-1799/1714.Sum Of Special Evenly-Spaced Elements In Array/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def solve(self, nums: List[int], queries: List[List[int]]) -> List[int]: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] solve(int[] nums, int[][] queries) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func solve(nums []int, queries [][]int) (ans []int) { n := len(nums) @@ -186,6 +194,8 @@ func solve(nums []int, queries [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function solve(nums: number[], queries: number[][]): number[] { const n = nums.length; diff --git a/solution/1700-1799/1714.Sum Of Special Evenly-Spaced Elements In Array/README_EN.md b/solution/1700-1799/1714.Sum Of Special Evenly-Spaced Elements In Array/README_EN.md index df41153bbd7c7..bfa773a335c45 100644 --- a/solution/1700-1799/1714.Sum Of Special Evenly-Spaced Elements In Array/README_EN.md +++ b/solution/1700-1799/1714.Sum Of Special Evenly-Spaced Elements In Array/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O((n + m) \times \sqrt{n})$, and the space complexity i +#### Python3 + ```python class Solution: def solve(self, nums: List[int], queries: List[List[int]]) -> List[int]: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] solve(int[] nums, int[][] queries) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func solve(nums []int, queries [][]int) (ans []int) { n := len(nums) @@ -186,6 +194,8 @@ func solve(nums []int, queries [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function solve(nums: number[], queries: number[][]): number[] { const n = nums.length; diff --git a/solution/1700-1799/1715.Count Apples and Oranges/README.md b/solution/1700-1799/1715.Count Apples and Oranges/README.md index 1f53a660e907d..e4c70f4ce1baa 100644 --- a/solution/1700-1799/1715.Count Apples and Oranges/README.md +++ b/solution/1700-1799/1715.Count Apples and Oranges/README.md @@ -109,6 +109,8 @@ Chests 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1700-1799/1715.Count Apples and Oranges/README_EN.md b/solution/1700-1799/1715.Count Apples and Oranges/README_EN.md index 7b01310942ebb..8f2892e832a7f 100644 --- a/solution/1700-1799/1715.Count Apples and Oranges/README_EN.md +++ b/solution/1700-1799/1715.Count Apples and Oranges/README_EN.md @@ -109,6 +109,8 @@ Total number of oranges = 15 + 25 + 8 + 28 + 15 + 15 + 17 = 123 +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1700-1799/1716.Calculate Money in Leetcode Bank/README.md b/solution/1700-1799/1716.Calculate Money in Leetcode Bank/README.md index 6769b3aa43ab9..831af9485cd13 100644 --- a/solution/1700-1799/1716.Calculate Money in Leetcode Bank/README.md +++ b/solution/1700-1799/1716.Calculate Money in Leetcode Bank/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def totalMoney(self, n: int) -> int: @@ -72,6 +74,8 @@ class Solution: return (28 + 28 + 7 * (a - 1)) * a // 2 + (a * 2 + b + 1) * b // 2 ``` +#### Java + ```java class Solution { public int totalMoney(int n) { @@ -81,6 +85,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -91,6 +97,8 @@ public: }; ``` +#### Go + ```go func totalMoney(n int) int { a, b := n/7, n%7 diff --git a/solution/1700-1799/1716.Calculate Money in Leetcode Bank/README_EN.md b/solution/1700-1799/1716.Calculate Money in Leetcode Bank/README_EN.md index 75b8c67ec8fb6..ef5648bc9a8ae 100644 --- a/solution/1700-1799/1716.Calculate Money in Leetcode Bank/README_EN.md +++ b/solution/1700-1799/1716.Calculate Money in Leetcode Bank/README_EN.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def totalMoney(self, n: int) -> int: @@ -73,6 +75,8 @@ class Solution: return (28 + 28 + 7 * (a - 1)) * a // 2 + (a * 2 + b + 1) * b // 2 ``` +#### Java + ```java class Solution { public int totalMoney(int n) { @@ -82,6 +86,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -92,6 +98,8 @@ public: }; ``` +#### Go + ```go func totalMoney(n int) int { a, b := n/7, n%7 diff --git a/solution/1700-1799/1717.Maximum Score From Removing Substrings/README.md b/solution/1700-1799/1717.Maximum Score From Removing Substrings/README.md index 7fdd72c75a72a..0da3ad6ecbc66 100644 --- a/solution/1700-1799/1717.Maximum Score From Removing Substrings/README.md +++ b/solution/1700-1799/1717.Maximum Score From Removing Substrings/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def maximumGain(self, s: str, x: int, y: int) -> int: @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumGain(String s, int x, int y) { @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go func maximumGain(s string, x int, y int) int { if x < y { diff --git a/solution/1700-1799/1717.Maximum Score From Removing Substrings/README_EN.md b/solution/1700-1799/1717.Maximum Score From Removing Substrings/README_EN.md index d60e7a9a32e34..53e3a359595ab 100644 --- a/solution/1700-1799/1717.Maximum Score From Removing Substrings/README_EN.md +++ b/solution/1700-1799/1717.Maximum Score From Removing Substrings/README_EN.md @@ -78,6 +78,8 @@ Total score = 5 + 4 + 5 + 5 = 19. +#### Python3 + ```python class Solution: def maximumGain(self, s: str, x: int, y: int) -> int: @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumGain(String s, int x, int y) { @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go func maximumGain(s string, x int, y int) int { if x < y { diff --git a/solution/1700-1799/1718.Construct the Lexicographically Largest Valid Sequence/README.md b/solution/1700-1799/1718.Construct the Lexicographically Largest Valid Sequence/README.md index a1604da8c6e26..3c78781cecbc4 100644 --- a/solution/1700-1799/1718.Construct the Lexicographically Largest Valid Sequence/README.md +++ b/solution/1700-1799/1718.Construct the Lexicographically Largest Valid Sequence/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def constructDistancedSequence(self, n: int) -> List[int]: @@ -96,6 +98,8 @@ class Solution: return path[1:] ``` +#### Java + ```java class Solution { private int[] path; @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -191,6 +197,8 @@ public: }; ``` +#### Go + ```go func constructDistancedSequence(n int) []int { path := make([]int, n*2) diff --git a/solution/1700-1799/1718.Construct the Lexicographically Largest Valid Sequence/README_EN.md b/solution/1700-1799/1718.Construct the Lexicographically Largest Valid Sequence/README_EN.md index 478a8aac3a84c..1a16387860023 100644 --- a/solution/1700-1799/1718.Construct the Lexicographically Largest Valid Sequence/README_EN.md +++ b/solution/1700-1799/1718.Construct the Lexicographically Largest Valid Sequence/README_EN.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def constructDistancedSequence(self, n: int) -> List[int]: @@ -96,6 +98,8 @@ class Solution: return path[1:] ``` +#### Java + ```java class Solution { private int[] path; @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -191,6 +197,8 @@ public: }; ``` +#### Go + ```go func constructDistancedSequence(n int) []int { path := make([]int, n*2) diff --git a/solution/1700-1799/1719.Number Of Ways To Reconstruct A Tree/README.md b/solution/1700-1799/1719.Number Of Ways To Reconstruct A Tree/README.md index 2040b9d7168b7..bfdcd3505be3a 100644 --- a/solution/1700-1799/1719.Number Of Ways To Reconstruct A Tree/README.md +++ b/solution/1700-1799/1719.Number Of Ways To Reconstruct A Tree/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def checkWays(self, pairs: List[List[int]]) -> int: @@ -128,6 +130,8 @@ class Solution: return 2 if equal else 1 ``` +#### Java + ```java class Solution { public int checkWays(int[][] pairs) { @@ -178,6 +182,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -221,6 +227,8 @@ public: }; ``` +#### Go + ```go func checkWays(pairs [][]int) int { g := make([][]bool, 510) diff --git a/solution/1700-1799/1719.Number Of Ways To Reconstruct A Tree/README_EN.md b/solution/1700-1799/1719.Number Of Ways To Reconstruct A Tree/README_EN.md index 836533e26abee..2dd847a9ee41c 100644 --- a/solution/1700-1799/1719.Number Of Ways To Reconstruct A Tree/README_EN.md +++ b/solution/1700-1799/1719.Number Of Ways To Reconstruct A Tree/README_EN.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def checkWays(self, pairs: List[List[int]]) -> int: @@ -126,6 +128,8 @@ class Solution: return 2 if equal else 1 ``` +#### Java + ```java class Solution { public int checkWays(int[][] pairs) { @@ -176,6 +180,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -219,6 +225,8 @@ public: }; ``` +#### Go + ```go func checkWays(pairs [][]int) int { g := make([][]bool, 510) diff --git a/solution/1700-1799/1720.Decode XORed Array/README.md b/solution/1700-1799/1720.Decode XORed Array/README.md index 1d2d563e7e6dc..33d201fe422a6 100644 --- a/solution/1700-1799/1720.Decode XORed Array/README.md +++ b/solution/1700-1799/1720.Decode XORed Array/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def decode(self, encoded: List[int], first: int) -> List[int]: @@ -74,6 +76,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] decode(int[] encoded, int first) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -100,6 +106,8 @@ public: }; ``` +#### Go + ```go func decode(encoded []int, first int) []int { ans := []int{first} diff --git a/solution/1700-1799/1720.Decode XORed Array/README_EN.md b/solution/1700-1799/1720.Decode XORed Array/README_EN.md index 9d79bbeef1e25..205d018c860ae 100644 --- a/solution/1700-1799/1720.Decode XORed Array/README_EN.md +++ b/solution/1700-1799/1720.Decode XORed Array/README_EN.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def decode(self, encoded: List[int], first: int) -> List[int]: @@ -72,6 +74,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] decode(int[] encoded, int first) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -98,6 +104,8 @@ public: }; ``` +#### Go + ```go func decode(encoded []int, first int) []int { ans := []int{first} diff --git a/solution/1700-1799/1721.Swapping Nodes in a Linked List/README.md b/solution/1700-1799/1721.Swapping Nodes in a Linked List/README.md index 021226a6f0b67..34cbfeab780b6 100644 --- a/solution/1700-1799/1721.Swapping Nodes in a Linked List/README.md +++ b/solution/1700-1799/1721.Swapping Nodes in a Linked List/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -103,6 +105,8 @@ class Solution: return head ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -190,6 +198,8 @@ func swapNodes(head *ListNode, k int) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -219,6 +229,8 @@ function swapNodes(head: ListNode | null, k: number): ListNode | null { } ``` +#### C# + ```cs /** * Definition for singly-linked list. diff --git a/solution/1700-1799/1721.Swapping Nodes in a Linked List/README_EN.md b/solution/1700-1799/1721.Swapping Nodes in a Linked List/README_EN.md index 5dcaca5fde48b..5d3b2f4358f5f 100644 --- a/solution/1700-1799/1721.Swapping Nodes in a Linked List/README_EN.md +++ b/solution/1700-1799/1721.Swapping Nodes in a Linked List/README_EN.md @@ -61,6 +61,8 @@ The time complexity is $O(n)$, where $n$ is the length of the linked list. The s +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -80,6 +82,8 @@ class Solution: return head ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -167,6 +175,8 @@ func swapNodes(head *ListNode, k int) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -196,6 +206,8 @@ function swapNodes(head: ListNode | null, k: number): ListNode | null { } ``` +#### C# + ```cs /** * Definition for singly-linked list. diff --git a/solution/1700-1799/1722.Minimize Hamming Distance After Swap Operations/README.md b/solution/1700-1799/1722.Minimize Hamming Distance After Swap Operations/README.md index e67192d478422..86c77e64415d1 100644 --- a/solution/1700-1799/1722.Minimize Hamming Distance After Swap Operations/README.md +++ b/solution/1700-1799/1722.Minimize Hamming Distance After Swap Operations/README.md @@ -81,6 +81,8 @@ source 和 target 间的汉明距离是 2 ,二者有 2 处元素不同,在 +#### Python3 + ```python class Solution: def minimumHammingDistance( @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] p; @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go func minimumHammingDistance(source []int, target []int, allowedSwaps [][]int) (ans int) { n := len(source) @@ -209,6 +217,8 @@ func minimumHammingDistance(source []int, target []int, allowedSwaps [][]int) (a } ``` +#### TypeScript + ```ts function minimumHammingDistance( source: number[], diff --git a/solution/1700-1799/1722.Minimize Hamming Distance After Swap Operations/README_EN.md b/solution/1700-1799/1722.Minimize Hamming Distance After Swap Operations/README_EN.md index 28942bb8637d3..857a9a4a05c62 100644 --- a/solution/1700-1799/1722.Minimize Hamming Distance After Swap Operations/README_EN.md +++ b/solution/1700-1799/1722.Minimize Hamming Distance After Swap Operations/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(n \times \log n)$ or $O(n \times \alpha(n))$, and the +#### Python3 + ```python class Solution: def minimumHammingDistance( @@ -109,6 +111,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] p; @@ -147,6 +151,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go func minimumHammingDistance(source []int, target []int, allowedSwaps [][]int) (ans int) { n := len(source) @@ -211,6 +219,8 @@ func minimumHammingDistance(source []int, target []int, allowedSwaps [][]int) (a } ``` +#### TypeScript + ```ts function minimumHammingDistance( source: number[], diff --git a/solution/1700-1799/1723.Find Minimum Time to Finish All Jobs/README.md b/solution/1700-1799/1723.Find Minimum Time to Finish All Jobs/README.md index 79ce5f6cbf12f..fd3e210a92bd9 100644 --- a/solution/1700-1799/1723.Find Minimum Time to Finish All Jobs/README.md +++ b/solution/1700-1799/1723.Find Minimum Time to Finish All Jobs/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def minimumTimeRequired(self, jobs: List[int], k: int) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] cnt; @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go func minimumTimeRequired(jobs []int, k int) int { cnt := make([]int, k) diff --git a/solution/1700-1799/1723.Find Minimum Time to Finish All Jobs/README_EN.md b/solution/1700-1799/1723.Find Minimum Time to Finish All Jobs/README_EN.md index f698dbf246f0d..94f83d3415eab 100644 --- a/solution/1700-1799/1723.Find Minimum Time to Finish All Jobs/README_EN.md +++ b/solution/1700-1799/1723.Find Minimum Time to Finish All Jobs/README_EN.md @@ -65,6 +65,8 @@ The maximum working time is 11. +#### Python3 + ```python class Solution: def minimumTimeRequired(self, jobs: List[int], k: int) -> int: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] cnt; @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func minimumTimeRequired(jobs []int, k int) int { cnt := make([]int, k) diff --git a/solution/1700-1799/1724.Checking Existence of Edge Length Limited Paths II/README.md b/solution/1700-1799/1724.Checking Existence of Edge Length Limited Paths II/README.md index 4d96da83a1a6f..29e440a2da636 100644 --- a/solution/1700-1799/1724.Checking Existence of Edge Length Limited Paths II/README.md +++ b/solution/1700-1799/1724.Checking Existence of Edge Length Limited Paths II/README.md @@ -76,6 +76,8 @@ distanceLimitedPathsExist.query(0, 5, 6); // 返回 false。从 0 到 5 之间 +#### Python3 + ```python class PersistentUnionFind: def __init__(self, n): @@ -114,6 +116,8 @@ class DistanceLimitedPathsExist: return self.puf.find(p, limit) == self.puf.find(q, limit) ``` +#### Java + ```java class PersistentUnionFind { private final int inf = 1 << 30; @@ -181,6 +185,8 @@ public class DistanceLimitedPathsExist { */ ``` +#### C++ + ```cpp class PersistentUnionFind { private: @@ -254,6 +260,8 @@ public: */ ``` +#### Go + ```go type PersistentUnionFind struct { rank []int @@ -337,6 +345,8 @@ func (dle *DistanceLimitedPathsExist) Query(p, q, limit int) bool { */ ``` +#### TypeScript + ```ts class PersistentUnionFind { private rank: number[]; diff --git a/solution/1700-1799/1724.Checking Existence of Edge Length Limited Paths II/README_EN.md b/solution/1700-1799/1724.Checking Existence of Edge Length Limited Paths II/README_EN.md index db18c4c2873a6..d4a0e88fda858 100644 --- a/solution/1700-1799/1724.Checking Existence of Edge Length Limited Paths II/README_EN.md +++ b/solution/1700-1799/1724.Checking Existence of Edge Length Limited Paths II/README_EN.md @@ -71,6 +71,8 @@ distanceLimitedPathsExist.query(0, 5, 6); // return false. There are no paths fr +#### Python3 + ```python class PersistentUnionFind: def __init__(self, n): @@ -109,6 +111,8 @@ class DistanceLimitedPathsExist: return self.puf.find(p, limit) == self.puf.find(q, limit) ``` +#### Java + ```java class PersistentUnionFind { private final int inf = 1 << 30; @@ -176,6 +180,8 @@ public class DistanceLimitedPathsExist { */ ``` +#### C++ + ```cpp class PersistentUnionFind { private: @@ -249,6 +255,8 @@ public: */ ``` +#### Go + ```go type PersistentUnionFind struct { rank []int @@ -332,6 +340,8 @@ func (dle *DistanceLimitedPathsExist) Query(p, q, limit int) bool { */ ``` +#### TypeScript + ```ts class PersistentUnionFind { private rank: number[]; diff --git a/solution/1700-1799/1725.Number Of Rectangles That Can Form The Largest Square/README.md b/solution/1700-1799/1725.Number Of Rectangles That Can Form The Largest Square/README.md index 19067efdd5a50..e96842f14b2f8 100644 --- a/solution/1700-1799/1725.Number Of Rectangles That Can Form The Largest Square/README.md +++ b/solution/1700-1799/1725.Number Of Rectangles That Can Form The Largest Square/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def countGoodRectangles(self, rectangles: List[List[int]]) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countGoodRectangles(int[][] rectangles) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func countGoodRectangles(rectangles [][]int) (ans int) { mx := 0 @@ -140,6 +148,8 @@ func countGoodRectangles(rectangles [][]int) (ans int) { } ``` +#### TypeScript + ```ts function countGoodRectangles(rectangles: number[][]): number { let [ans, mx] = [0, 0]; diff --git a/solution/1700-1799/1725.Number Of Rectangles That Can Form The Largest Square/README_EN.md b/solution/1700-1799/1725.Number Of Rectangles That Can Form The Largest Square/README_EN.md index 666370a488e15..34f00129f2a96 100644 --- a/solution/1700-1799/1725.Number Of Rectangles That Can Form The Largest Square/README_EN.md +++ b/solution/1700-1799/1725.Number Of Rectangles That Can Form The Largest Square/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $rectangles$ +#### Python3 + ```python class Solution: def countGoodRectangles(self, rectangles: List[List[int]]) -> int: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countGoodRectangles(int[][] rectangles) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func countGoodRectangles(rectangles [][]int) (ans int) { mx := 0 @@ -153,6 +161,8 @@ func countGoodRectangles(rectangles [][]int) (ans int) { } ``` +#### TypeScript + ```ts function countGoodRectangles(rectangles: number[][]): number { let [ans, mx] = [0, 0]; diff --git a/solution/1700-1799/1726.Tuple with Same Product/README.md b/solution/1700-1799/1726.Tuple with Same Product/README.md index b3bebb2e080bc..e8a96b75f03f5 100644 --- a/solution/1700-1799/1726.Tuple with Same Product/README.md +++ b/solution/1700-1799/1726.Tuple with Same Product/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def tupleSameProduct(self, nums: List[int]) -> int: @@ -83,6 +85,8 @@ class Solution: return sum(v * (v - 1) // 2 for v in cnt.values()) << 3 ``` +#### Java + ```java class Solution { public int tupleSameProduct(int[] nums) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func tupleSameProduct(nums []int) int { cnt := map[int]int{} @@ -139,6 +147,8 @@ func tupleSameProduct(nums []int) int { } ``` +#### TypeScript + ```ts function tupleSameProduct(nums: number[]): number { const cnt: Map = new Map(); @@ -156,6 +166,8 @@ function tupleSameProduct(nums: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/1700-1799/1726.Tuple with Same Product/README_EN.md b/solution/1700-1799/1726.Tuple with Same Product/README_EN.md index 75a798f35fc6d..5ca0a71f78fca 100644 --- a/solution/1700-1799/1726.Tuple with Same Product/README_EN.md +++ b/solution/1700-1799/1726.Tuple with Same Product/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$. Here, $n$ +#### Python3 + ```python class Solution: def tupleSameProduct(self, nums: List[int]) -> int: @@ -81,6 +83,8 @@ class Solution: return sum(v * (v - 1) // 2 for v in cnt.values()) << 3 ``` +#### Java + ```java class Solution { public int tupleSameProduct(int[] nums) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func tupleSameProduct(nums []int) int { cnt := map[int]int{} @@ -137,6 +145,8 @@ func tupleSameProduct(nums []int) int { } ``` +#### TypeScript + ```ts function tupleSameProduct(nums: number[]): number { const cnt: Map = new Map(); @@ -154,6 +164,8 @@ function tupleSameProduct(nums: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/1700-1799/1727.Largest Submatrix With Rearrangements/README.md b/solution/1700-1799/1727.Largest Submatrix With Rearrangements/README.md index f8db0be4dd45e..aea5f92360fd0 100644 --- a/solution/1700-1799/1727.Largest Submatrix With Rearrangements/README.md +++ b/solution/1700-1799/1727.Largest Submatrix With Rearrangements/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class Solution: def largestSubmatrix(self, matrix: List[List[int]]) -> int: @@ -109,6 +111,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int largestSubmatrix(int[][] matrix) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func largestSubmatrix(matrix [][]int) int { m, n := len(matrix), len(matrix[0]) @@ -178,6 +186,8 @@ func largestSubmatrix(matrix [][]int) int { } ``` +#### TypeScript + ```ts function largestSubmatrix(matrix: number[][]): number { for (let column = 0; column < matrix[0].length; column++) { diff --git a/solution/1700-1799/1727.Largest Submatrix With Rearrangements/README_EN.md b/solution/1700-1799/1727.Largest Submatrix With Rearrangements/README_EN.md index 90d82d6077c2e..e510e513b1dcd 100644 --- a/solution/1700-1799/1727.Largest Submatrix With Rearrangements/README_EN.md +++ b/solution/1700-1799/1727.Largest Submatrix With Rearrangements/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(m \times n \times \log n)$. Here, $m$ and $n$ are the +#### Python3 + ```python class Solution: def largestSubmatrix(self, matrix: List[List[int]]) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int largestSubmatrix(int[][] matrix) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func largestSubmatrix(matrix [][]int) int { m, n := len(matrix), len(matrix[0]) @@ -166,6 +174,8 @@ func largestSubmatrix(matrix [][]int) int { } ``` +#### TypeScript + ```ts function largestSubmatrix(matrix: number[][]): number { for (let column = 0; column < matrix[0].length; column++) { diff --git a/solution/1700-1799/1728.Cat and Mouse II/README.md b/solution/1700-1799/1728.Cat and Mouse II/README.md index 43de422af1edb..a46c8445c1561 100644 --- a/solution/1700-1799/1728.Cat and Mouse II/README.md +++ b/solution/1700-1799/1728.Cat and Mouse II/README.md @@ -123,6 +123,8 @@ tags: +#### Python3 + ```python class Solution: def canMouseWin(self, grid: List[str], catJump: int, mouseJump: int) -> bool: diff --git a/solution/1700-1799/1728.Cat and Mouse II/README_EN.md b/solution/1700-1799/1728.Cat and Mouse II/README_EN.md index 93c2bf2aa807c..fc9bdea13cf05 100644 --- a/solution/1700-1799/1728.Cat and Mouse II/README_EN.md +++ b/solution/1700-1799/1728.Cat and Mouse II/README_EN.md @@ -103,6 +103,8 @@ tags: +#### Python3 + ```python class Solution: def canMouseWin(self, grid: List[str], catJump: int, mouseJump: int) -> bool: diff --git a/solution/1700-1799/1729.Find Followers Count/README.md b/solution/1700-1799/1729.Find Followers Count/README.md index 822553c8e9d5d..a4b8d9f3d5b95 100644 --- a/solution/1700-1799/1729.Find Followers Count/README.md +++ b/solution/1700-1799/1729.Find Followers Count/README.md @@ -76,6 +76,8 @@ Followers 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT user_id, COUNT(1) AS followers_count diff --git a/solution/1700-1799/1729.Find Followers Count/README_EN.md b/solution/1700-1799/1729.Find Followers Count/README_EN.md index 0e6bf159f7471..e4c983dd603ec 100644 --- a/solution/1700-1799/1729.Find Followers Count/README_EN.md +++ b/solution/1700-1799/1729.Find Followers Count/README_EN.md @@ -76,6 +76,8 @@ We can directly group the `Followers` table by `user_id`, and use the `COUNT` fu +#### MySQL + ```sql # Write your MySQL query statement below SELECT user_id, COUNT(1) AS followers_count diff --git a/solution/1700-1799/1730.Shortest Path to Get Food/README.md b/solution/1700-1799/1730.Shortest Path to Get Food/README.md index 3dfc49ce862f7..2da8adfc461c8 100644 --- a/solution/1700-1799/1730.Shortest Path to Get Food/README.md +++ b/solution/1700-1799/1730.Shortest Path to Get Food/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def getFood(self, grid: List[List[str]]) -> int: @@ -108,6 +110,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { private int[] dirs = {-1, 0, 1, 0, -1}; @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -189,6 +195,8 @@ public: }; ``` +#### Go + ```go func getFood(grid [][]byte) (ans int) { m, n := len(grid), len(grid[0]) @@ -227,6 +235,8 @@ func getFood(grid [][]byte) (ans int) { } ``` +#### JavaScript + ```js /** * @param {character[][]} grid diff --git a/solution/1700-1799/1730.Shortest Path to Get Food/README_EN.md b/solution/1700-1799/1730.Shortest Path to Get Food/README_EN.md index 4a12e37279a0f..7b0f8be2b095e 100644 --- a/solution/1700-1799/1730.Shortest Path to Get Food/README_EN.md +++ b/solution/1700-1799/1730.Shortest Path to Get Food/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(1)$. Here +#### Python3 + ```python class Solution: def getFood(self, grid: List[List[str]]) -> int: @@ -109,6 +111,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { private int[] dirs = {-1, 0, 1, 0, -1}; @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -190,6 +196,8 @@ public: }; ``` +#### Go + ```go func getFood(grid [][]byte) (ans int) { m, n := len(grid), len(grid[0]) @@ -228,6 +236,8 @@ func getFood(grid [][]byte) (ans int) { } ``` +#### JavaScript + ```js /** * @param {character[][]} grid diff --git a/solution/1700-1799/1731.The Number of Employees Which Report to Each Employee/README.md b/solution/1700-1799/1731.The Number of Employees Which Report to Each Employee/README.md index c59c69947b726..847d32b0bc893 100644 --- a/solution/1700-1799/1731.The Number of Employees Which Report to Each Employee/README.md +++ b/solution/1700-1799/1731.The Number of Employees Which Report to Each Employee/README.md @@ -104,6 +104,8 @@ Employees 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1700-1799/1731.The Number of Employees Which Report to Each Employee/README_EN.md b/solution/1700-1799/1731.The Number of Employees Which Report to Each Employee/README_EN.md index 1a6eccd95d620..ca0f5118d7945 100644 --- a/solution/1700-1799/1731.The Number of Employees Which Report to Each Employee/README_EN.md +++ b/solution/1700-1799/1731.The Number of Employees Which Report to Each Employee/README_EN.md @@ -104,6 +104,8 @@ We can use self-join to connect the information of each employee's superior mana +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1700-1799/1732.Find the Highest Altitude/README.md b/solution/1700-1799/1732.Find the Highest Altitude/README.md index bd18f7934c439..c8b975e519957 100644 --- a/solution/1700-1799/1732.Find the Highest Altitude/README.md +++ b/solution/1700-1799/1732.Find the Highest Altitude/README.md @@ -79,12 +79,16 @@ $$ +#### Python3 + ```python class Solution: def largestAltitude(self, gain: List[int]) -> int: return max(accumulate(gain, initial=0)) ``` +#### Java + ```java class Solution { public int largestAltitude(int[] gain) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func largestAltitude(gain []int) (ans int) { h := 0 @@ -122,6 +130,8 @@ func largestAltitude(gain []int) (ans int) { } ``` +#### Rust + ```rust impl Solution { pub fn largest_altitude(gain: Vec) -> i32 { @@ -136,6 +146,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} gain @@ -152,6 +164,8 @@ var largestAltitude = function (gain) { }; ``` +#### PHP + ```php class Solution { /** @@ -171,6 +185,8 @@ class Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) @@ -195,6 +211,8 @@ int largestAltitude(int* gain, int gainSize) { +#### Python3 + ```python class Solution: def largestAltitude(self, gain: List[int]) -> int: diff --git a/solution/1700-1799/1732.Find the Highest Altitude/README_EN.md b/solution/1700-1799/1732.Find the Highest Altitude/README_EN.md index 34a885fdf2bde..f7a8882d39bf3 100644 --- a/solution/1700-1799/1732.Find the Highest Altitude/README_EN.md +++ b/solution/1700-1799/1732.Find the Highest Altitude/README_EN.md @@ -77,12 +77,16 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is +#### Python3 + ```python class Solution: def largestAltitude(self, gain: List[int]) -> int: return max(accumulate(gain, initial=0)) ``` +#### Java + ```java class Solution { public int largestAltitude(int[] gain) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func largestAltitude(gain []int) (ans int) { h := 0 @@ -120,6 +128,8 @@ func largestAltitude(gain []int) (ans int) { } ``` +#### Rust + ```rust impl Solution { pub fn largest_altitude(gain: Vec) -> i32 { @@ -134,6 +144,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} gain @@ -150,6 +162,8 @@ var largestAltitude = function (gain) { }; ``` +#### PHP + ```php class Solution { /** @@ -169,6 +183,8 @@ class Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) @@ -193,6 +209,8 @@ int largestAltitude(int* gain, int gainSize) { +#### Python3 + ```python class Solution: def largestAltitude(self, gain: List[int]) -> int: diff --git a/solution/1700-1799/1733.Minimum Number of People to Teach/README.md b/solution/1700-1799/1733.Minimum Number of People to Teach/README.md index d8ed64c80c814..0331927ca43a5 100644 --- a/solution/1700-1799/1733.Minimum Number of People to Teach/README.md +++ b/solution/1700-1799/1733.Minimum Number of People to Teach/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def minimumTeachings( @@ -107,6 +109,8 @@ class Solution: return len(s) - max(cnt.values(), default=0) ``` +#### Java + ```java class Solution { public int minimumTeachings(int n, int[][] languages, int[][] friendships) { @@ -147,6 +151,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -184,6 +190,8 @@ public: }; ``` +#### Go + ```go func minimumTeachings(n int, languages [][]int, friendships [][]int) int { check := func(u, v int) bool { diff --git a/solution/1700-1799/1733.Minimum Number of People to Teach/README_EN.md b/solution/1700-1799/1733.Minimum Number of People to Teach/README_EN.md index a7fcee5684ef5..baab4cb37c5f7 100644 --- a/solution/1700-1799/1733.Minimum Number of People to Teach/README_EN.md +++ b/solution/1700-1799/1733.Minimum Number of People to Teach/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(m^2 \times k)$. Here, $m$ is the number of languages, +#### Python3 + ```python class Solution: def minimumTeachings( @@ -104,6 +106,8 @@ class Solution: return len(s) - max(cnt.values(), default=0) ``` +#### Java + ```java class Solution { public int minimumTeachings(int n, int[][] languages, int[][] friendships) { @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func minimumTeachings(n int, languages [][]int, friendships [][]int) int { check := func(u, v int) bool { diff --git a/solution/1700-1799/1734.Decode XORed Permutation/README.md b/solution/1700-1799/1734.Decode XORed Permutation/README.md index 4eda6cc58b20e..76096ab12ba29 100644 --- a/solution/1700-1799/1734.Decode XORed Permutation/README.md +++ b/solution/1700-1799/1734.Decode XORed Permutation/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def decode(self, encoded: List[int]) -> List[int]: @@ -80,6 +82,8 @@ class Solution: return perm ``` +#### Java + ```java class Solution { public int[] decode(int[] encoded) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func decode(encoded []int) []int { n := len(encoded) + 1 diff --git a/solution/1700-1799/1734.Decode XORed Permutation/README_EN.md b/solution/1700-1799/1734.Decode XORed Permutation/README_EN.md index 18c3e32d5ec83..b4052fedfaac9 100644 --- a/solution/1700-1799/1734.Decode XORed Permutation/README_EN.md +++ b/solution/1700-1799/1734.Decode XORed Permutation/README_EN.md @@ -64,6 +64,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $perm$. Igno +#### Python3 + ```python class Solution: def decode(self, encoded: List[int]) -> List[int]: @@ -80,6 +82,8 @@ class Solution: return perm ``` +#### Java + ```java class Solution { public int[] decode(int[] encoded) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func decode(encoded []int) []int { n := len(encoded) + 1 diff --git a/solution/1700-1799/1735.Count Ways to Make Array With Product/README.md b/solution/1700-1799/1735.Count Ways to Make Array With Product/README.md index 069eb36e4ae99..cdff06c706d5c 100644 --- a/solution/1700-1799/1735.Count Ways to Make Array With Product/README.md +++ b/solution/1700-1799/1735.Count Ways to Make Array With Product/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python N = 10020 MOD = 10**9 + 7 @@ -117,6 +119,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int N = 10020; @@ -181,6 +185,8 @@ class Solution { } ``` +#### C++ + ```cpp int N = 10020; int MOD = 1e9 + 7; @@ -245,6 +251,8 @@ public: }; ``` +#### Go + ```go const n = 1e4 + 20 const mod = 1e9 + 7 diff --git a/solution/1700-1799/1735.Count Ways to Make Array With Product/README_EN.md b/solution/1700-1799/1735.Count Ways to Make Array With Product/README_EN.md index 9aedc8414e1e5..416383b52e1ed 100644 --- a/solution/1700-1799/1735.Count Ways to Make Array With Product/README_EN.md +++ b/solution/1700-1799/1735.Count Ways to Make Array With Product/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(K \times \log \log K + N + m \times \log K)$, and the +#### Python3 + ```python N = 10020 MOD = 10**9 + 7 @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int N = 10020; @@ -179,6 +183,8 @@ class Solution { } ``` +#### C++ + ```cpp int N = 10020; int MOD = 1e9 + 7; @@ -243,6 +249,8 @@ public: }; ``` +#### Go + ```go const n = 1e4 + 20 const mod = 1e9 + 7 diff --git a/solution/1700-1799/1736.Latest Time by Replacing Hidden Digits/README.md b/solution/1700-1799/1736.Latest Time by Replacing Hidden Digits/README.md index 260d33bb6a7d2..09a1eab9458e6 100644 --- a/solution/1700-1799/1736.Latest Time by Replacing Hidden Digits/README.md +++ b/solution/1700-1799/1736.Latest Time by Replacing Hidden Digits/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def maximumTime(self, time: str) -> str: @@ -92,6 +94,8 @@ class Solution: return ''.join(t) ``` +#### Java + ```java class Solution { public String maximumTime(String time) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func maximumTime(time string) string { t := []byte(time) @@ -161,6 +169,8 @@ func maximumTime(time string) string { } ``` +#### JavaScript + ```js /** * @param {string} time diff --git a/solution/1700-1799/1736.Latest Time by Replacing Hidden Digits/README_EN.md b/solution/1700-1799/1736.Latest Time by Replacing Hidden Digits/README_EN.md index b6cba4d5193c4..c682bf037d133 100644 --- a/solution/1700-1799/1736.Latest Time by Replacing Hidden Digits/README_EN.md +++ b/solution/1700-1799/1736.Latest Time by Replacing Hidden Digits/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def maximumTime(self, time: str) -> str: @@ -90,6 +92,8 @@ class Solution: return ''.join(t) ``` +#### Java + ```java class Solution { public String maximumTime(String time) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func maximumTime(time string) string { t := []byte(time) @@ -159,6 +167,8 @@ func maximumTime(time string) string { } ``` +#### JavaScript + ```js /** * @param {string} time diff --git a/solution/1700-1799/1737.Change Minimum Characters to Satisfy One of Three Conditions/README.md b/solution/1700-1799/1737.Change Minimum Characters to Satisfy One of Three Conditions/README.md index a6cbdc3efcdc1..5766714f2fe58 100644 --- a/solution/1700-1799/1737.Change Minimum Characters to Satisfy One of Three Conditions/README.md +++ b/solution/1700-1799/1737.Change Minimum Characters to Satisfy One of Three Conditions/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def minCharacters(self, a: str, b: str) -> int: @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int ans; @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go func minCharacters(a string, b string) int { cnt1 := [26]int{} @@ -203,6 +211,8 @@ func minCharacters(a string, b string) int { } ``` +#### TypeScript + ```ts function minCharacters(a: string, b: string): number { const m = a.length, diff --git a/solution/1700-1799/1737.Change Minimum Characters to Satisfy One of Three Conditions/README_EN.md b/solution/1700-1799/1737.Change Minimum Characters to Satisfy One of Three Conditions/README_EN.md index 97ff43009d5a7..68b9ce14e8d3b 100644 --- a/solution/1700-1799/1737.Change Minimum Characters to Satisfy One of Three Conditions/README_EN.md +++ b/solution/1700-1799/1737.Change Minimum Characters to Satisfy One of Three Conditions/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(m + n + C^2)$, where $m$ and $n$ are the lengths of st +#### Python3 + ```python class Solution: def minCharacters(self, a: str, b: str) -> int: @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int ans; @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go func minCharacters(a string, b string) int { cnt1 := [26]int{} @@ -203,6 +211,8 @@ func minCharacters(a string, b string) int { } ``` +#### TypeScript + ```ts function minCharacters(a: string, b: string): number { const m = a.length, diff --git a/solution/1700-1799/1738.Find Kth Largest XOR Coordinate Value/README.md b/solution/1700-1799/1738.Find Kth Largest XOR Coordinate Value/README.md index 642929b71f0c0..ce393009dc0ce 100644 --- a/solution/1700-1799/1738.Find Kth Largest XOR Coordinate Value/README.md +++ b/solution/1700-1799/1738.Find Kth Largest XOR Coordinate Value/README.md @@ -95,6 +95,8 @@ $$ +#### Python3 + ```python class Solution: def kthLargestValue(self, matrix: List[List[int]], k: int) -> int: @@ -108,6 +110,8 @@ class Solution: return nlargest(k, ans)[-1] ``` +#### Java + ```java class Solution { public int kthLargestValue(int[][] matrix, int k) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func kthLargestValue(matrix [][]int, k int) int { m, n := len(matrix), len(matrix[0]) @@ -164,6 +172,8 @@ func kthLargestValue(matrix [][]int, k int) int { } ``` +#### TypeScript + ```ts function kthLargestValue(matrix: number[][], k: number): number { const m: number = matrix.length; diff --git a/solution/1700-1799/1738.Find Kth Largest XOR Coordinate Value/README_EN.md b/solution/1700-1799/1738.Find Kth Largest XOR Coordinate Value/README_EN.md index 4a69f26e2f20b..9ca9af64825eb 100644 --- a/solution/1700-1799/1738.Find Kth Largest XOR Coordinate Value/README_EN.md +++ b/solution/1700-1799/1738.Find Kth Largest XOR Coordinate Value/README_EN.md @@ -92,6 +92,8 @@ The time complexity is $O(m \times n \times \log (m \times n))$ or $O(m \times n +#### Python3 + ```python class Solution: def kthLargestValue(self, matrix: List[List[int]], k: int) -> int: @@ -105,6 +107,8 @@ class Solution: return nlargest(k, ans)[-1] ``` +#### Java + ```java class Solution { public int kthLargestValue(int[][] matrix, int k) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func kthLargestValue(matrix [][]int, k int) int { m, n := len(matrix), len(matrix[0]) @@ -161,6 +169,8 @@ func kthLargestValue(matrix [][]int, k int) int { } ``` +#### TypeScript + ```ts function kthLargestValue(matrix: number[][], k: number): number { const m: number = matrix.length; diff --git a/solution/1700-1799/1739.Building Boxes/README.md b/solution/1700-1799/1739.Building Boxes/README.md index e9032a0357d9f..b9efdcde92f3e 100644 --- a/solution/1700-1799/1739.Building Boxes/README.md +++ b/solution/1700-1799/1739.Building Boxes/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def minimumBoxes(self, n: int) -> int: @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumBoxes(int n) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func minimumBoxes(n int) int { s, k := 0, 1 diff --git a/solution/1700-1799/1739.Building Boxes/README_EN.md b/solution/1700-1799/1739.Building Boxes/README_EN.md index e6b9c40ad591d..93435d2e0a0af 100644 --- a/solution/1700-1799/1739.Building Boxes/README_EN.md +++ b/solution/1700-1799/1739.Building Boxes/README_EN.md @@ -87,6 +87,8 @@ The time complexity is $O(\sqrt{n})$, where $n$ is the number of boxes given in +#### Python3 + ```python class Solution: def minimumBoxes(self, n: int) -> int: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumBoxes(int n) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func minimumBoxes(n int) int { s, k := 0, 1 diff --git a/solution/1700-1799/1740.Find Distance in a Binary Tree/README.md b/solution/1700-1799/1740.Find Distance in a Binary Tree/README.md index cc6ae044409b2..a7750417e4a84 100644 --- a/solution/1700-1799/1740.Find Distance in a Binary Tree/README.md +++ b/solution/1700-1799/1740.Find Distance in a Binary Tree/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -102,6 +104,8 @@ class Solution: return dfs(g, p) + dfs(g, q) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -156,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -195,6 +201,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/1700-1799/1740.Find Distance in a Binary Tree/README_EN.md b/solution/1700-1799/1740.Find Distance in a Binary Tree/README_EN.md index a957cfcedf3ab..00b350e762297 100644 --- a/solution/1700-1799/1740.Find Distance in a Binary Tree/README_EN.md +++ b/solution/1700-1799/1740.Find Distance in a Binary Tree/README_EN.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -100,6 +102,8 @@ class Solution: return dfs(g, p) + dfs(g, q) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/1700-1799/1741.Find Total Time Spent by Each Employee/README.md b/solution/1700-1799/1741.Find Total Time Spent by Each Employee/README.md index 041a9487fe71a..08d42a34a9eea 100644 --- a/solution/1700-1799/1741.Find Total Time Spent by Each Employee/README.md +++ b/solution/1700-1799/1741.Find Total Time Spent by Each Employee/README.md @@ -83,6 +83,8 @@ Employees table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT event_day AS day, emp_id, SUM(out_time - in_time) AS total_time diff --git a/solution/1700-1799/1741.Find Total Time Spent by Each Employee/README_EN.md b/solution/1700-1799/1741.Find Total Time Spent by Each Employee/README_EN.md index cd202ccd9a2c9..6d2fd1b35aa33 100644 --- a/solution/1700-1799/1741.Find Total Time Spent by Each Employee/README_EN.md +++ b/solution/1700-1799/1741.Find Total Time Spent by Each Employee/README_EN.md @@ -83,6 +83,8 @@ We can first group by `emp_id` and `event_day`, and then calculate the total tim +#### MySQL + ```sql # Write your MySQL query statement below SELECT event_day AS day, emp_id, SUM(out_time - in_time) AS total_time diff --git a/solution/1700-1799/1742.Maximum Number of Balls in a Box/README.md b/solution/1700-1799/1742.Maximum Number of Balls in a Box/README.md index 6aad9838049df..201650a5221bf 100644 --- a/solution/1700-1799/1742.Maximum Number of Balls in a Box/README.md +++ b/solution/1700-1799/1742.Maximum Number of Balls in a Box/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def countBalls(self, lowLimit: int, highLimit: int) -> int: @@ -97,6 +99,8 @@ class Solution: return max(cnt) ``` +#### Java + ```java class Solution { public int countBalls(int lowLimit, int highLimit) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func countBalls(lowLimit int, highLimit int) (ans int) { cnt := [50]int{} @@ -148,6 +156,8 @@ func countBalls(lowLimit int, highLimit int) (ans int) { } ``` +#### TypeScript + ```ts function countBalls(lowLimit: number, highLimit: number): number { const cnt: number[] = Array(50).fill(0); diff --git a/solution/1700-1799/1742.Maximum Number of Balls in a Box/README_EN.md b/solution/1700-1799/1742.Maximum Number of Balls in a Box/README_EN.md index 765ea5ebe412e..f76f6e7f9877a 100644 --- a/solution/1700-1799/1742.Maximum Number of Balls in a Box/README_EN.md +++ b/solution/1700-1799/1742.Maximum Number of Balls in a Box/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n \times \log_{10}m)$. Here, $n = highLimit - lowLimit +#### Python3 + ```python class Solution: def countBalls(self, lowLimit: int, highLimit: int) -> int: @@ -95,6 +97,8 @@ class Solution: return max(cnt) ``` +#### Java + ```java class Solution { public int countBalls(int lowLimit, int highLimit) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func countBalls(lowLimit int, highLimit int) (ans int) { cnt := [50]int{} @@ -146,6 +154,8 @@ func countBalls(lowLimit int, highLimit int) (ans int) { } ``` +#### TypeScript + ```ts function countBalls(lowLimit: number, highLimit: number): number { const cnt: number[] = Array(50).fill(0); diff --git a/solution/1700-1799/1743.Restore the Array From Adjacent Pairs/README.md b/solution/1700-1799/1743.Restore the Array From Adjacent Pairs/README.md index f83ee4400925e..0a94ade621d7c 100644 --- a/solution/1700-1799/1743.Restore the Array From Adjacent Pairs/README.md +++ b/solution/1700-1799/1743.Restore the Array From Adjacent Pairs/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def restoreArray(self, adjacentPairs: List[List[int]]) -> List[int]: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] restoreArray(int[][] adjacentPairs) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func restoreArray(adjacentPairs [][]int) []int { n := len(adjacentPairs) + 1 @@ -184,6 +192,8 @@ func restoreArray(adjacentPairs [][]int) []int { } ``` +#### C# + ```cs public class Solution { public int[] RestoreArray(int[][] adjacentPairs) { @@ -232,6 +242,8 @@ public class Solution { +#### Python3 + ```python class Solution: def restoreArray(self, adjacentPairs: List[List[int]]) -> List[int]: @@ -251,6 +263,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private Map> g = new HashMap<>(); @@ -284,6 +298,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -315,6 +331,8 @@ public: }; ``` +#### Go + ```go func restoreArray(adjacentPairs [][]int) []int { g := map[int][]int{} diff --git a/solution/1700-1799/1743.Restore the Array From Adjacent Pairs/README_EN.md b/solution/1700-1799/1743.Restore the Array From Adjacent Pairs/README_EN.md index 11afe05a5c5b5..abf63dfc5c41e 100644 --- a/solution/1700-1799/1743.Restore the Array From Adjacent Pairs/README_EN.md +++ b/solution/1700-1799/1743.Restore the Array From Adjacent Pairs/README_EN.md @@ -75,6 +75,8 @@ Another solution is [-3,1,4,-2], which would also be accepted. +#### Python3 + ```python class Solution: def restoreArray(self, adjacentPairs: List[List[int]]) -> List[int]: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] restoreArray(int[][] adjacentPairs) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func restoreArray(adjacentPairs [][]int) []int { n := len(adjacentPairs) + 1 @@ -178,6 +186,8 @@ func restoreArray(adjacentPairs [][]int) []int { } ``` +#### C# + ```cs public class Solution { public int[] RestoreArray(int[][] adjacentPairs) { @@ -226,6 +236,8 @@ public class Solution { +#### Python3 + ```python class Solution: def restoreArray(self, adjacentPairs: List[List[int]]) -> List[int]: @@ -245,6 +257,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private Map> g = new HashMap<>(); @@ -278,6 +292,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -309,6 +325,8 @@ public: }; ``` +#### Go + ```go func restoreArray(adjacentPairs [][]int) []int { g := map[int][]int{} diff --git a/solution/1700-1799/1744.Can You Eat Your Favorite Candy on Your Favorite Day/README.md b/solution/1700-1799/1744.Can You Eat Your Favorite Candy on Your Favorite Day/README.md index 4db586abeb686..433a572f22f72 100644 --- a/solution/1700-1799/1744.Can You Eat Your Favorite Candy on Your Favorite Day/README.md +++ b/solution/1700-1799/1744.Can You Eat Your Favorite Candy on Your Favorite Day/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def canEat(self, candiesCount: List[int], queries: List[List[int]]) -> List[bool]: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public boolean[] canEat(int[] candiesCount, int[][] queries) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func canEat(candiesCount []int, queries [][]int) (ans []bool) { n := len(candiesCount) diff --git a/solution/1700-1799/1744.Can You Eat Your Favorite Candy on Your Favorite Day/README_EN.md b/solution/1700-1799/1744.Can You Eat Your Favorite Candy on Your Favorite Day/README_EN.md index 5396f99b41d95..8a508eefb754d 100644 --- a/solution/1700-1799/1744.Can You Eat Your Favorite Candy on Your Favorite Day/README_EN.md +++ b/solution/1700-1799/1744.Can You Eat Your Favorite Candy on Your Favorite Day/README_EN.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def canEat(self, candiesCount: List[int], queries: List[List[int]]) -> List[bool]: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public boolean[] canEat(int[] candiesCount, int[][] queries) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func canEat(candiesCount []int, queries [][]int) (ans []bool) { n := len(candiesCount) diff --git a/solution/1700-1799/1745.Palindrome Partitioning IV/README.md b/solution/1700-1799/1745.Palindrome Partitioning IV/README.md index 0f7b94de4d0d7..ca291ecba0c23 100644 --- a/solution/1700-1799/1745.Palindrome Partitioning IV/README.md +++ b/solution/1700-1799/1745.Palindrome Partitioning IV/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def checkPartitioning(self, s: str) -> bool: @@ -79,6 +81,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean checkPartitioning(String s) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func checkPartitioning(s string) bool { n := len(s) diff --git a/solution/1700-1799/1745.Palindrome Partitioning IV/README_EN.md b/solution/1700-1799/1745.Palindrome Partitioning IV/README_EN.md index 58e2d529929cd..fa7e699680b23 100644 --- a/solution/1700-1799/1745.Palindrome Partitioning IV/README_EN.md +++ b/solution/1700-1799/1745.Palindrome Partitioning IV/README_EN.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python class Solution: def checkPartitioning(self, s: str) -> bool: @@ -73,6 +75,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean checkPartitioning(String s) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func checkPartitioning(s string) bool { n := len(s) diff --git a/solution/1700-1799/1746.Maximum Subarray Sum After One Operation/README.md b/solution/1700-1799/1746.Maximum Subarray Sum After One Operation/README.md index 012240087ef95..8caece62334b4 100644 --- a/solution/1700-1799/1746.Maximum Subarray Sum After One Operation/README.md +++ b/solution/1700-1799/1746.Maximum Subarray Sum After One Operation/README.md @@ -71,6 +71,8 @@ $$ +#### Python3 + ```python class Solution: def maxSumAfterOperation(self, nums: List[int]) -> int: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxSumAfterOperation(int[] nums) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func maxSumAfterOperation(nums []int) int { var f, g int @@ -133,6 +141,8 @@ func maxSumAfterOperation(nums []int) int { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/1700-1799/1746.Maximum Subarray Sum After One Operation/README_EN.md b/solution/1700-1799/1746.Maximum Subarray Sum After One Operation/README_EN.md index 9e9d6d24343c7..2ae33ffa3a49c 100644 --- a/solution/1700-1799/1746.Maximum Subarray Sum After One Operation/README_EN.md +++ b/solution/1700-1799/1746.Maximum Subarray Sum After One Operation/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def maxSumAfterOperation(self, nums: List[int]) -> int: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxSumAfterOperation(int[] nums) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func maxSumAfterOperation(nums []int) int { var f, g int @@ -127,6 +135,8 @@ func maxSumAfterOperation(nums []int) int { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/1700-1799/1747.Leetflex Banned Accounts/README.md b/solution/1700-1799/1747.Leetflex Banned Accounts/README.md index 37ae7ac92bdf8..3b2a3f1e3294e 100644 --- a/solution/1700-1799/1747.Leetflex Banned Accounts/README.md +++ b/solution/1700-1799/1747.Leetflex Banned Accounts/README.md @@ -88,6 +88,8 @@ Account ID 4 --> 该账户从 "2021-02-01 17:00:00" 到 "2021-02-01 17:00:00" +#### MySQL + ```sql # Write your MySQL query statement below SELECT DISTINCT diff --git a/solution/1700-1799/1747.Leetflex Banned Accounts/README_EN.md b/solution/1700-1799/1747.Leetflex Banned Accounts/README_EN.md index a572e526ba8d7..3f118a1acc96f 100644 --- a/solution/1700-1799/1747.Leetflex Banned Accounts/README_EN.md +++ b/solution/1700-1799/1747.Leetflex Banned Accounts/README_EN.md @@ -88,6 +88,8 @@ We can use a self-join to find out the cases where each account logs in from dif +#### MySQL + ```sql # Write your MySQL query statement below SELECT DISTINCT diff --git a/solution/1700-1799/1748.Sum of Unique Elements/README.md b/solution/1700-1799/1748.Sum of Unique Elements/README.md index ddf3616e89c64..63877dfddea62 100644 --- a/solution/1700-1799/1748.Sum of Unique Elements/README.md +++ b/solution/1700-1799/1748.Sum of Unique Elements/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def sumOfUnique(self, nums: List[int]) -> int: @@ -79,6 +81,8 @@ class Solution: return sum(x for x, v in cnt.items() if v == 1) ``` +#### Java + ```java class Solution { public int sumOfUnique(int[] nums) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func sumOfUnique(nums []int) (ans int) { cnt := [101]int{} @@ -131,6 +139,8 @@ func sumOfUnique(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function sumOfUnique(nums: number[]): number { const cnt = new Array(101).fill(0); @@ -147,6 +157,8 @@ function sumOfUnique(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn sum_of_unique(nums: Vec) -> i32 { @@ -165,6 +177,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** @@ -197,6 +211,8 @@ class Solution { +#### Java + ```java class Solution { public int sumOfUnique(int[] nums) { @@ -214,6 +230,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -232,6 +250,8 @@ public: }; ``` +#### Go + ```go func sumOfUnique(nums []int) (ans int) { cnt := [101]int{} @@ -247,6 +267,8 @@ func sumOfUnique(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function sumOfUnique(nums: number[]): number { let ans = 0; @@ -262,6 +284,8 @@ function sumOfUnique(nums: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/1700-1799/1748.Sum of Unique Elements/README_EN.md b/solution/1700-1799/1748.Sum of Unique Elements/README_EN.md index 73c874fe3115e..db60b908ff5c0 100644 --- a/solution/1700-1799/1748.Sum of Unique Elements/README_EN.md +++ b/solution/1700-1799/1748.Sum of Unique Elements/README_EN.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def sumOfUnique(self, nums: List[int]) -> int: @@ -74,6 +76,8 @@ class Solution: return sum(x for x, v in cnt.items() if v == 1) ``` +#### Java + ```java class Solution { public int sumOfUnique(int[] nums) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func sumOfUnique(nums []int) (ans int) { cnt := [101]int{} @@ -126,6 +134,8 @@ func sumOfUnique(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function sumOfUnique(nums: number[]): number { const cnt = new Array(101).fill(0); @@ -142,6 +152,8 @@ function sumOfUnique(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn sum_of_unique(nums: Vec) -> i32 { @@ -160,6 +172,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** @@ -192,6 +206,8 @@ class Solution { +#### Java + ```java class Solution { public int sumOfUnique(int[] nums) { @@ -209,6 +225,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -227,6 +245,8 @@ public: }; ``` +#### Go + ```go func sumOfUnique(nums []int) (ans int) { cnt := [101]int{} @@ -242,6 +262,8 @@ func sumOfUnique(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function sumOfUnique(nums: number[]): number { let ans = 0; @@ -257,6 +279,8 @@ function sumOfUnique(nums: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/1700-1799/1749.Maximum Absolute Sum of Any Subarray/README.md b/solution/1700-1799/1749.Maximum Absolute Sum of Any Subarray/README.md index 9f106f7b9101b..5855a9cf10f88 100644 --- a/solution/1700-1799/1749.Maximum Absolute Sum of Any Subarray/README.md +++ b/solution/1700-1799/1749.Maximum Absolute Sum of Any Subarray/README.md @@ -82,6 +82,8 @@ $$ +#### Python3 + ```python class Solution: def maxAbsoluteSum(self, nums: List[int]) -> int: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxAbsoluteSum(int[] nums) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func maxAbsoluteSum(nums []int) (ans int) { var f, g int @@ -144,6 +152,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function maxAbsoluteSum(nums: number[]): number { let f = 0; @@ -158,6 +168,8 @@ function maxAbsoluteSum(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_absolute_sum(nums: Vec) -> i32 { diff --git a/solution/1700-1799/1749.Maximum Absolute Sum of Any Subarray/README_EN.md b/solution/1700-1799/1749.Maximum Absolute Sum of Any Subarray/README_EN.md index c92e9c7329362..0a249185654ee 100644 --- a/solution/1700-1799/1749.Maximum Absolute Sum of Any Subarray/README_EN.md +++ b/solution/1700-1799/1749.Maximum Absolute Sum of Any Subarray/README_EN.md @@ -80,6 +80,8 @@ Time complexity $O(n)$, space complexity $O(1)$, where $n$ is the length of the +#### Python3 + ```python class Solution: def maxAbsoluteSum(self, nums: List[int]) -> int: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxAbsoluteSum(int[] nums) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func maxAbsoluteSum(nums []int) (ans int) { var f, g int @@ -142,6 +150,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function maxAbsoluteSum(nums: number[]): number { let f = 0; @@ -156,6 +166,8 @@ function maxAbsoluteSum(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_absolute_sum(nums: Vec) -> i32 { diff --git a/solution/1700-1799/1750.Minimum Length of String After Deleting Similar Ends/README.md b/solution/1700-1799/1750.Minimum Length of String After Deleting Similar Ends/README.md index 9e4e5e5fa712d..d3fe8ff57197f 100644 --- a/solution/1700-1799/1750.Minimum Length of String After Deleting Similar Ends/README.md +++ b/solution/1700-1799/1750.Minimum Length of String After Deleting Similar Ends/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def minimumLength(self, s: str) -> int: @@ -98,6 +100,8 @@ class Solution: return max(0, j - i + 1) ``` +#### Java + ```java class Solution { public int minimumLength(String s) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func minimumLength(s string) int { i, j := 0, len(s)-1 @@ -153,6 +161,8 @@ func minimumLength(s string) int { } ``` +#### TypeScript + ```ts function minimumLength(s: string): number { let i = 0; @@ -171,6 +181,8 @@ function minimumLength(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn minimum_length(s: String) -> i32 { @@ -193,6 +205,8 @@ impl Solution { } ``` +#### C + ```c int minimumLength(char* s) { int n = strlen(s); diff --git a/solution/1700-1799/1750.Minimum Length of String After Deleting Similar Ends/README_EN.md b/solution/1700-1799/1750.Minimum Length of String After Deleting Similar Ends/README_EN.md index 7c7c6388e7be1..8c5fe04db9dd7 100644 --- a/solution/1700-1799/1750.Minimum Length of String After Deleting Similar Ends/README_EN.md +++ b/solution/1700-1799/1750.Minimum Length of String After Deleting Similar Ends/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(n)$ and the space complexity is $O(1)$. Where $n$ is t +#### Python3 + ```python class Solution: def minimumLength(self, s: str) -> int: @@ -96,6 +98,8 @@ class Solution: return max(0, j - i + 1) ``` +#### Java + ```java class Solution { public int minimumLength(String s) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func minimumLength(s string) int { i, j := 0, len(s)-1 @@ -151,6 +159,8 @@ func minimumLength(s string) int { } ``` +#### TypeScript + ```ts function minimumLength(s: string): number { let i = 0; @@ -169,6 +179,8 @@ function minimumLength(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn minimum_length(s: String) -> i32 { @@ -191,6 +203,8 @@ impl Solution { } ``` +#### C + ```c int minimumLength(char* s) { int n = strlen(s); diff --git a/solution/1700-1799/1751.Maximum Number of Events That Can Be Attended II/README.md b/solution/1700-1799/1751.Maximum Number of Events That Can Be Attended II/README.md index 79870d2ea6959..97bd26ee00b3a 100644 --- a/solution/1700-1799/1751.Maximum Number of Events That Can Be Attended II/README.md +++ b/solution/1700-1799/1751.Maximum Number of Events That Can Be Attended II/README.md @@ -94,6 +94,8 @@ $$ +#### Python3 + ```python class Solution: def maxValue(self, events: List[List[int]], k: int) -> int: @@ -112,6 +114,8 @@ class Solution: return dfs(0, k) ``` +#### Java + ```java class Solution { private int[][] events; @@ -153,6 +157,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -179,6 +185,8 @@ public: }; ``` +#### Go + ```go func maxValue(events [][]int, k int) int { sort.Slice(events, func(i, j int) bool { return events[i][0] < events[j][0] }) @@ -204,6 +212,8 @@ func maxValue(events [][]int, k int) int { } ``` +#### TypeScript + ```ts function maxValue(events: number[][], k: number): number { events.sort((a, b) => a[1] - b[1]); @@ -262,6 +272,8 @@ $$ +#### Python3 + ```python class Solution: def maxValue(self, events: List[List[int]], k: int) -> int: @@ -275,6 +287,8 @@ class Solution: return f[n][k] ``` +#### Java + ```java class Solution { public int maxValue(int[][] events, int k) { @@ -306,6 +320,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -327,6 +343,8 @@ public: }; ``` +#### Go + ```go func maxValue(events [][]int, k int) int { sort.Slice(events, func(i, j int) bool { return events[i][1] < events[j][1] }) diff --git a/solution/1700-1799/1751.Maximum Number of Events That Can Be Attended II/README_EN.md b/solution/1700-1799/1751.Maximum Number of Events That Can Be Attended II/README_EN.md index be92958cb49d1..a8a515dca126a 100644 --- a/solution/1700-1799/1751.Maximum Number of Events That Can Be Attended II/README_EN.md +++ b/solution/1700-1799/1751.Maximum Number of Events That Can Be Attended II/README_EN.md @@ -76,6 +76,8 @@ Notice that you cannot attend any other event as they overlap, and that you do < +#### Python3 + ```python class Solution: def maxValue(self, events: List[List[int]], k: int) -> int: @@ -94,6 +96,8 @@ class Solution: return dfs(0, k) ``` +#### Java + ```java class Solution { private int[][] events; @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func maxValue(events [][]int, k int) int { sort.Slice(events, func(i, j int) bool { return events[i][0] < events[j][0] }) @@ -186,6 +194,8 @@ func maxValue(events [][]int, k int) int { } ``` +#### TypeScript + ```ts function maxValue(events: number[][], k: number): number { events.sort((a, b) => a[1] - b[1]); @@ -225,6 +235,8 @@ function maxValue(events: number[][], k: number): number { +#### Python3 + ```python class Solution: def maxValue(self, events: List[List[int]], k: int) -> int: @@ -238,6 +250,8 @@ class Solution: return f[n][k] ``` +#### Java + ```java class Solution { public int maxValue(int[][] events, int k) { @@ -269,6 +283,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -290,6 +306,8 @@ public: }; ``` +#### Go + ```go func maxValue(events [][]int, k int) int { sort.Slice(events, func(i, j int) bool { return events[i][1] < events[j][1] }) diff --git a/solution/1700-1799/1752.Check if Array Is Sorted and Rotated/README.md b/solution/1700-1799/1752.Check if Array Is Sorted and Rotated/README.md index 82a377beb5e09..b1685b6f3975a 100644 --- a/solution/1700-1799/1752.Check if Array Is Sorted and Rotated/README.md +++ b/solution/1700-1799/1752.Check if Array Is Sorted and Rotated/README.md @@ -79,12 +79,16 @@ tags: +#### Python3 + ```python class Solution: def check(self, nums: List[int]) -> bool: return sum(nums[i - 1] > v for i, v in enumerate(nums)) <= 1 ``` +#### Java + ```java class Solution { public boolean check(int[] nums) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func check(nums []int) bool { cnt := 0 @@ -124,6 +132,8 @@ func check(nums []int) bool { } ``` +#### TypeScript + ```ts function check(nums: number[]): boolean { const n = nums.length; @@ -131,6 +141,8 @@ function check(nums: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn check(nums: Vec) -> bool { @@ -146,6 +158,8 @@ impl Solution { } ``` +#### C + ```c bool check(int* nums, int numsSize) { int count = 0; diff --git a/solution/1700-1799/1752.Check if Array Is Sorted and Rotated/README_EN.md b/solution/1700-1799/1752.Check if Array Is Sorted and Rotated/README_EN.md index 29ab90ef86d10..a2351785a56a6 100644 --- a/solution/1700-1799/1752.Check if Array Is Sorted and Rotated/README_EN.md +++ b/solution/1700-1799/1752.Check if Array Is Sorted and Rotated/README_EN.md @@ -69,12 +69,16 @@ You can rotate the array by x = 0 positions (i.e. no rotation) to make nums. +#### Python3 + ```python class Solution: def check(self, nums: List[int]) -> bool: return sum(nums[i - 1] > v for i, v in enumerate(nums)) <= 1 ``` +#### Java + ```java class Solution { public boolean check(int[] nums) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -102,6 +108,8 @@ public: }; ``` +#### Go + ```go func check(nums []int) bool { cnt := 0 @@ -114,6 +122,8 @@ func check(nums []int) bool { } ``` +#### TypeScript + ```ts function check(nums: number[]): boolean { const n = nums.length; @@ -121,6 +131,8 @@ function check(nums: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn check(nums: Vec) -> bool { @@ -136,6 +148,8 @@ impl Solution { } ``` +#### C + ```c bool check(int* nums, int numsSize) { int count = 0; diff --git a/solution/1700-1799/1753.Maximum Score From Removing Stones/README.md b/solution/1700-1799/1753.Maximum Score From Removing Stones/README.md index da7c7386b7acc..ee77286d71c64 100644 --- a/solution/1700-1799/1753.Maximum Score From Removing Stones/README.md +++ b/solution/1700-1799/1753.Maximum Score From Removing Stones/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def maximumScore(self, a: int, b: int, c: int) -> int: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumScore(int a, int b, int c) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func maximumScore(a int, b int, c int) (ans int) { s := []int{a, b, c} @@ -168,6 +176,8 @@ func maximumScore(a int, b int, c int) (ans int) { +#### Python3 + ```python class Solution: def maximumScore(self, a: int, b: int, c: int) -> int: @@ -177,6 +187,8 @@ class Solution: return (a + b + c) >> 1 ``` +#### Java + ```java class Solution { public int maximumScore(int a, int b, int c) { @@ -190,6 +202,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -202,6 +216,8 @@ public: }; ``` +#### Go + ```go func maximumScore(a int, b int, c int) int { s := []int{a, b, c} diff --git a/solution/1700-1799/1753.Maximum Score From Removing Stones/README_EN.md b/solution/1700-1799/1753.Maximum Score From Removing Stones/README_EN.md index 914e37cbbd834..4f574b48d3186 100644 --- a/solution/1700-1799/1753.Maximum Score From Removing Stones/README_EN.md +++ b/solution/1700-1799/1753.Maximum Score From Removing Stones/README_EN.md @@ -82,6 +82,8 @@ After that, there are fewer than two non-empty piles, so the game ends. +#### Python3 + ```python class Solution: def maximumScore(self, a: int, b: int, c: int) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumScore(int a, int b, int c) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func maximumScore(a int, b int, c int) (ans int) { s := []int{a, b, c} @@ -154,6 +162,8 @@ func maximumScore(a int, b int, c int) (ans int) { +#### Python3 + ```python class Solution: def maximumScore(self, a: int, b: int, c: int) -> int: @@ -163,6 +173,8 @@ class Solution: return (a + b + c) >> 1 ``` +#### Java + ```java class Solution { public int maximumScore(int a, int b, int c) { @@ -176,6 +188,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +202,8 @@ public: }; ``` +#### Go + ```go func maximumScore(a int, b int, c int) int { s := []int{a, b, c} diff --git a/solution/1700-1799/1754.Largest Merge Of Two Strings/README.md b/solution/1700-1799/1754.Largest Merge Of Two Strings/README.md index 6a930416f2ad3..bb738739e506e 100644 --- a/solution/1700-1799/1754.Largest Merge Of Two Strings/README.md +++ b/solution/1700-1799/1754.Largest Merge Of Two Strings/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def largestMerge(self, word1: str, word2: str) -> str: @@ -106,6 +108,8 @@ class Solution: return "".join(ans) ``` +#### Java + ```java class Solution { public String largestMerge(String word1, String word2) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func largestMerge(word1 string, word2 string) string { m, n := len(word1), len(word2) @@ -161,6 +169,8 @@ func largestMerge(word1 string, word2 string) string { } ``` +#### TypeScript + ```ts function largestMerge(word1: string, word2: string): string { const m = word1.length; @@ -177,6 +187,8 @@ function largestMerge(word1: string, word2: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn largest_merge(word1: String, word2: String) -> String { @@ -203,6 +215,8 @@ impl Solution { } ``` +#### C + ```c char* largestMerge(char* word1, char* word2) { int m = strlen(word1); diff --git a/solution/1700-1799/1754.Largest Merge Of Two Strings/README_EN.md b/solution/1700-1799/1754.Largest Merge Of Two Strings/README_EN.md index 16c4961e38bf4..49b9fac5abb0d 100644 --- a/solution/1700-1799/1754.Largest Merge Of Two Strings/README_EN.md +++ b/solution/1700-1799/1754.Largest Merge Of Two Strings/README_EN.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def largestMerge(self, word1: str, word2: str) -> str: @@ -98,6 +100,8 @@ class Solution: return "".join(ans) ``` +#### Java + ```java class Solution { public String largestMerge(String word1, String word2) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func largestMerge(word1 string, word2 string) string { m, n := len(word1), len(word2) @@ -153,6 +161,8 @@ func largestMerge(word1 string, word2 string) string { } ``` +#### TypeScript + ```ts function largestMerge(word1: string, word2: string): string { const m = word1.length; @@ -169,6 +179,8 @@ function largestMerge(word1: string, word2: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn largest_merge(word1: String, word2: String) -> String { @@ -195,6 +207,8 @@ impl Solution { } ``` +#### C + ```c char* largestMerge(char* word1, char* word2) { int m = strlen(word1); diff --git a/solution/1700-1799/1755.Closest Subsequence Sum/README.md b/solution/1700-1799/1755.Closest Subsequence Sum/README.md index 140ddca4457ce..7eca53e20253d 100644 --- a/solution/1700-1799/1755.Closest Subsequence Sum/README.md +++ b/solution/1700-1799/1755.Closest Subsequence Sum/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def minAbsDifference(self, nums: List[int], goal: int) -> int: @@ -119,6 +121,8 @@ class Solution: self.getSubSeqSum(i + 1, curr + arr[i], arr, result) ``` +#### Java + ```java class Solution { public int minAbsDifference(int[] nums, int goal) { @@ -165,6 +169,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -213,6 +219,8 @@ private: }; ``` +#### Go + ```go func minAbsDifference(nums []int, goal int) int { n := len(nums) @@ -275,6 +283,8 @@ func abs(x int) int { +#### Python3 + ```python class Solution: def minAbsDifference(self, nums: List[int], goal: int) -> int: @@ -301,6 +311,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minAbsDifference(int[] nums, int goal) { @@ -344,6 +356,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -376,6 +390,8 @@ private: }; ``` +#### Go + ```go func minAbsDifference(nums []int, goal int) int { n := len(nums) diff --git a/solution/1700-1799/1755.Closest Subsequence Sum/README_EN.md b/solution/1700-1799/1755.Closest Subsequence Sum/README_EN.md index e05a50923382b..db0bf3506e986 100644 --- a/solution/1700-1799/1755.Closest Subsequence Sum/README_EN.md +++ b/solution/1700-1799/1755.Closest Subsequence Sum/README_EN.md @@ -75,6 +75,8 @@ The absolute difference is abs(-4 - (-5)) = abs(1) = 1, which is the minimum. +#### Python3 + ```python class Solution: def minAbsDifference(self, nums: List[int], goal: int) -> int: @@ -110,6 +112,8 @@ class Solution: self.getSubSeqSum(i + 1, curr + arr[i], arr, result) ``` +#### Java + ```java class Solution { public int minAbsDifference(int[] nums, int goal) { @@ -156,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -204,6 +210,8 @@ private: }; ``` +#### Go + ```go func minAbsDifference(nums []int, goal int) int { n := len(nums) @@ -266,6 +274,8 @@ func abs(x int) int { +#### Python3 + ```python class Solution: def minAbsDifference(self, nums: List[int], goal: int) -> int: @@ -292,6 +302,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minAbsDifference(int[] nums, int goal) { @@ -335,6 +347,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -367,6 +381,8 @@ private: }; ``` +#### Go + ```go func minAbsDifference(nums []int, goal int) int { n := len(nums) diff --git a/solution/1700-1799/1756.Design Most Recently Used Queue/README.md b/solution/1700-1799/1756.Design Most Recently Used Queue/README.md index 07f3d3ee4519e..56283d457fbe9 100644 --- a/solution/1700-1799/1756.Design Most Recently Used Queue/README.md +++ b/solution/1700-1799/1756.Design Most Recently Used Queue/README.md @@ -78,6 +78,8 @@ mRUQueue.fetch(8); // 第 8 个元素 (2) 已经在队列尾部了,所以直 +#### Python3 + ```python class MRUQueue: def __init__(self, n: int): @@ -95,6 +97,8 @@ class MRUQueue: # param_1 = obj.fetch(k) ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -160,6 +164,8 @@ class MRUQueue { */ ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -224,6 +230,8 @@ private: */ ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -287,6 +295,8 @@ func (this *MRUQueue) Fetch(k int) int { */ ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; @@ -361,6 +371,8 @@ class MRUQueue { +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n: int): diff --git a/solution/1700-1799/1756.Design Most Recently Used Queue/README_EN.md b/solution/1700-1799/1756.Design Most Recently Used Queue/README_EN.md index 7677d20a42d97..18d7d885d60b5 100644 --- a/solution/1700-1799/1756.Design Most Recently Used Queue/README_EN.md +++ b/solution/1700-1799/1756.Design Most Recently Used Queue/README_EN.md @@ -70,6 +70,8 @@ mRUQueue.fetch(8); // The 8th element (2) is already at the end of th +#### Python3 + ```python class MRUQueue: def __init__(self, n: int): @@ -87,6 +89,8 @@ class MRUQueue: # param_1 = obj.fetch(k) ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -152,6 +156,8 @@ class MRUQueue { */ ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -216,6 +222,8 @@ private: */ ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -279,6 +287,8 @@ func (this *MRUQueue) Fetch(k int) int { */ ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; @@ -353,6 +363,8 @@ class MRUQueue { +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n: int): diff --git a/solution/1700-1799/1757.Recyclable and Low Fat Products/README.md b/solution/1700-1799/1757.Recyclable and Low Fat Products/README.md index a6bca82a4332f..ad0b9caee5d34 100644 --- a/solution/1700-1799/1757.Recyclable and Low Fat Products/README.md +++ b/solution/1700-1799/1757.Recyclable and Low Fat Products/README.md @@ -77,6 +77,8 @@ Products 表: +#### Python3 + ```python import pandas as pd @@ -87,6 +89,8 @@ def find_products(products: pd.DataFrame) -> pd.DataFrame: return rs ``` +#### MySQL + ```sql SELECT product_id diff --git a/solution/1700-1799/1757.Recyclable and Low Fat Products/README_EN.md b/solution/1700-1799/1757.Recyclable and Low Fat Products/README_EN.md index c6b4d62d7629c..3f6a7d8fd32be 100644 --- a/solution/1700-1799/1757.Recyclable and Low Fat Products/README_EN.md +++ b/solution/1700-1799/1757.Recyclable and Low Fat Products/README_EN.md @@ -75,6 +75,8 @@ We can directly filter the product IDs where `low_fats` is `Y` and `recyclable` +#### Python3 + ```python import pandas as pd @@ -85,6 +87,8 @@ def find_products(products: pd.DataFrame) -> pd.DataFrame: return rs ``` +#### MySQL + ```sql SELECT product_id diff --git a/solution/1700-1799/1758.Minimum Changes To Make Alternating Binary String/README.md b/solution/1700-1799/1758.Minimum Changes To Make Alternating Binary String/README.md index 8ce0ec37a040f..4b6727f829209 100644 --- a/solution/1700-1799/1758.Minimum Changes To Make Alternating Binary String/README.md +++ b/solution/1700-1799/1758.Minimum Changes To Make Alternating Binary String/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def minOperations(self, s: str) -> int: @@ -79,6 +81,8 @@ class Solution: return min(cnt, len(s) - cnt) ``` +#### Java + ```java class Solution { public int minOperations(String s) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -102,6 +108,8 @@ public: }; ``` +#### Go + ```go func minOperations(s string) int { cnt := 0 @@ -114,6 +122,8 @@ func minOperations(s string) int { } ``` +#### TypeScript + ```ts function minOperations(s: string): number { const n = s.length; @@ -125,6 +135,8 @@ function minOperations(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_operations(s: String) -> i32 { @@ -140,6 +152,8 @@ impl Solution { } ``` +#### C + ```c #define min(a, b) (((a) < (b)) ? (a) : (b)) diff --git a/solution/1700-1799/1758.Minimum Changes To Make Alternating Binary String/README_EN.md b/solution/1700-1799/1758.Minimum Changes To Make Alternating Binary String/README_EN.md index 7363e47d110c4..d71f4ebe4764e 100644 --- a/solution/1700-1799/1758.Minimum Changes To Make Alternating Binary String/README_EN.md +++ b/solution/1700-1799/1758.Minimum Changes To Make Alternating Binary String/README_EN.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def minOperations(self, s: str) -> int: @@ -74,6 +76,8 @@ class Solution: return min(cnt, len(s) - cnt) ``` +#### Java + ```java class Solution { public int minOperations(String s) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -97,6 +103,8 @@ public: }; ``` +#### Go + ```go func minOperations(s string) int { cnt := 0 @@ -109,6 +117,8 @@ func minOperations(s string) int { } ``` +#### TypeScript + ```ts function minOperations(s: string): number { const n = s.length; @@ -120,6 +130,8 @@ function minOperations(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_operations(s: String) -> i32 { @@ -135,6 +147,8 @@ impl Solution { } ``` +#### C + ```c #define min(a, b) (((a) < (b)) ? (a) : (b)) diff --git a/solution/1700-1799/1759.Count Number of Homogenous Substrings/README.md b/solution/1700-1799/1759.Count Number of Homogenous Substrings/README.md index 0865524ce3d85..e69b28e0a1833 100644 --- a/solution/1700-1799/1759.Count Number of Homogenous Substrings/README.md +++ b/solution/1700-1799/1759.Count Number of Homogenous Substrings/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def countHomogenous(self, s: str) -> int: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func countHomogenous(s string) (ans int) { n := len(s) @@ -156,6 +164,8 @@ func countHomogenous(s string) (ans int) { } ``` +#### TypeScript + ```ts function countHomogenous(s: string): number { const mod = 1e9 + 7; @@ -171,6 +181,8 @@ function countHomogenous(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_homogenous(s: String) -> i32 { @@ -190,6 +202,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int CountHomogenous(string s) { @@ -209,6 +223,8 @@ public class Solution { } ``` +#### C + ```c int countHomogenous(char* s) { int MOD = 1e9 + 7; @@ -233,6 +249,8 @@ int countHomogenous(char* s) { +#### Python3 + ```python class Solution: def countHomogenous(self, s: str) -> int: @@ -244,6 +262,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -260,6 +280,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -277,6 +299,8 @@ public: }; ``` +#### Go + ```go func countHomogenous(s string) int { n := len(s) diff --git a/solution/1700-1799/1759.Count Number of Homogenous Substrings/README_EN.md b/solution/1700-1799/1759.Count Number of Homogenous Substrings/README_EN.md index 0721dc3748c1c..d03aed3d694c0 100644 --- a/solution/1700-1799/1759.Count Number of Homogenous Substrings/README_EN.md +++ b/solution/1700-1799/1759.Count Number of Homogenous Substrings/README_EN.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def countHomogenous(self, s: str) -> int: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func countHomogenous(s string) (ans int) { n := len(s) @@ -148,6 +156,8 @@ func countHomogenous(s string) (ans int) { } ``` +#### TypeScript + ```ts function countHomogenous(s: string): number { const mod = 1e9 + 7; @@ -163,6 +173,8 @@ function countHomogenous(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_homogenous(s: String) -> i32 { @@ -182,6 +194,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int CountHomogenous(string s) { @@ -201,6 +215,8 @@ public class Solution { } ``` +#### C + ```c int countHomogenous(char* s) { int MOD = 1e9 + 7; @@ -225,6 +241,8 @@ int countHomogenous(char* s) { +#### Python3 + ```python class Solution: def countHomogenous(self, s: str) -> int: @@ -236,6 +254,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -252,6 +272,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -269,6 +291,8 @@ public: }; ``` +#### Go + ```go func countHomogenous(s string) int { n := len(s) diff --git a/solution/1700-1799/1760.Minimum Limit of Balls in a Bag/README.md b/solution/1700-1799/1760.Minimum Limit of Balls in a Bag/README.md index 8ca484f200b1f..62765638217de 100644 --- a/solution/1700-1799/1760.Minimum Limit of Balls in a Bag/README.md +++ b/solution/1700-1799/1760.Minimum Limit of Balls in a Bag/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def minimumSize(self, nums: List[int], maxOperations: int) -> int: @@ -102,6 +104,8 @@ class Solution: return bisect_left(range(1, max(nums)), True, key=check) + 1 ``` +#### Java + ```java class Solution { public int minimumSize(int[] nums, int maxOperations) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func minimumSize(nums []int, maxOperations int) int { r := slices.Max(nums) @@ -162,6 +170,8 @@ func minimumSize(nums []int, maxOperations int) int { } ``` +#### TypeScript + ```ts function minimumSize(nums: number[], maxOperations: number): number { let left = 1; @@ -182,6 +192,8 @@ function minimumSize(nums: number[], maxOperations: number): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/1700-1799/1760.Minimum Limit of Balls in a Bag/README_EN.md b/solution/1700-1799/1760.Minimum Limit of Balls in a Bag/README_EN.md index 01504959414af..476f69ff11d86 100644 --- a/solution/1700-1799/1760.Minimum Limit of Balls in a Bag/README_EN.md +++ b/solution/1700-1799/1760.Minimum Limit of Balls in a Bag/README_EN.md @@ -80,6 +80,8 @@ The bag with the most number of balls has 2 balls, so your penalty is 2, and you +#### Python3 + ```python class Solution: def minimumSize(self, nums: List[int], maxOperations: int) -> int: @@ -89,6 +91,8 @@ class Solution: return bisect_left(range(1, max(nums)), True, key=check) + 1 ``` +#### Java + ```java class Solution { public int minimumSize(int[] nums, int maxOperations) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func minimumSize(nums []int, maxOperations int) int { r := slices.Max(nums) @@ -149,6 +157,8 @@ func minimumSize(nums []int, maxOperations int) int { } ``` +#### TypeScript + ```ts function minimumSize(nums: number[], maxOperations: number): number { let left = 1; @@ -169,6 +179,8 @@ function minimumSize(nums: number[], maxOperations: number): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/1700-1799/1761.Minimum Degree of a Connected Trio in a Graph/README.md b/solution/1700-1799/1761.Minimum Degree of a Connected Trio in a Graph/README.md index 182f45cb49067..b76044df49ef4 100644 --- a/solution/1700-1799/1761.Minimum Degree of a Connected Trio in a Graph/README.md +++ b/solution/1700-1799/1761.Minimum Degree of a Connected Trio in a Graph/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def minTrioDegree(self, n: int, edges: List[List[int]]) -> int: @@ -98,6 +100,8 @@ class Solution: return -1 if ans == inf else ans ``` +#### Java + ```java class Solution { public int minTrioDegree(int n, int[][] edges) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func minTrioDegree(n int, edges [][]int) int { g := make([][]bool, n) @@ -189,6 +197,8 @@ func minTrioDegree(n int, edges [][]int) int { } ``` +#### TypeScript + ```ts function minTrioDegree(n: number, edges: number[][]): number { const g = Array.from({ length: n }, () => Array(n).fill(false)); diff --git a/solution/1700-1799/1761.Minimum Degree of a Connected Trio in a Graph/README_EN.md b/solution/1700-1799/1761.Minimum Degree of a Connected Trio in a Graph/README_EN.md index 7722aa261b510..97e128ac2fbb1 100644 --- a/solution/1700-1799/1761.Minimum Degree of a Connected Trio in a Graph/README_EN.md +++ b/solution/1700-1799/1761.Minimum Degree of a Connected Trio in a Graph/README_EN.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def minTrioDegree(self, n: int, edges: List[List[int]]) -> int: @@ -88,6 +90,8 @@ class Solution: return -1 if ans == inf else ans ``` +#### Java + ```java class Solution { public int minTrioDegree(int n, int[][] edges) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func minTrioDegree(n int, edges [][]int) int { g := make([][]bool, n) @@ -179,6 +187,8 @@ func minTrioDegree(n int, edges [][]int) int { } ``` +#### TypeScript + ```ts function minTrioDegree(n: number, edges: number[][]): number { const g = Array.from({ length: n }, () => Array(n).fill(false)); diff --git a/solution/1700-1799/1762.Buildings With an Ocean View/README.md b/solution/1700-1799/1762.Buildings With an Ocean View/README.md index 29edf7144d60d..59c911016611d 100644 --- a/solution/1700-1799/1762.Buildings With an Ocean View/README.md +++ b/solution/1700-1799/1762.Buildings With an Ocean View/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def findBuildings(self, heights: List[int]) -> List[int]: @@ -92,6 +94,8 @@ class Solution: return ans[::-1] ``` +#### Java + ```java class Solution { public int[] findBuildings(int[] heights) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func findBuildings(heights []int) (ans []int) { mx := 0 @@ -144,6 +152,8 @@ func findBuildings(heights []int) (ans []int) { } ``` +#### TypeScript + ```ts function findBuildings(heights: number[]): number[] { const ans: number[] = []; @@ -158,6 +168,8 @@ function findBuildings(heights: number[]): number[] { } ``` +#### JavaScript + ```js /** * @param {number[]} heights diff --git a/solution/1700-1799/1762.Buildings With an Ocean View/README_EN.md b/solution/1700-1799/1762.Buildings With an Ocean View/README_EN.md index 4eb25e589a55c..1575f307f3fd0 100644 --- a/solution/1700-1799/1762.Buildings With an Ocean View/README_EN.md +++ b/solution/1700-1799/1762.Buildings With an Ocean View/README_EN.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def findBuildings(self, heights: List[int]) -> List[int]: @@ -79,6 +81,8 @@ class Solution: return ans[::-1] ``` +#### Java + ```java class Solution { public int[] findBuildings(int[] heights) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func findBuildings(heights []int) (ans []int) { mx := 0 @@ -131,6 +139,8 @@ func findBuildings(heights []int) (ans []int) { } ``` +#### TypeScript + ```ts function findBuildings(heights: number[]): number[] { const ans: number[] = []; @@ -145,6 +155,8 @@ function findBuildings(heights: number[]): number[] { } ``` +#### JavaScript + ```js /** * @param {number[]} heights diff --git a/solution/1700-1799/1763.Longest Nice Substring/README.md b/solution/1700-1799/1763.Longest Nice Substring/README.md index 22bde65ddafa8..3c48bf008d34e 100644 --- a/solution/1700-1799/1763.Longest Nice Substring/README.md +++ b/solution/1700-1799/1763.Longest Nice Substring/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def longestNiceSubstring(self, s: str) -> str: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String longestNiceSubstring(String s) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func longestNiceSubstring(s string) string { n := len(s) @@ -188,6 +196,8 @@ func longestNiceSubstring(s string) string { } ``` +#### TypeScript + ```ts function longestNiceSubstring(s: string): string { const n = s.length; @@ -227,6 +237,8 @@ function longestNiceSubstring(s: string): string { +#### Python3 + ```python class Solution: def longestNiceSubstring(self, s: str) -> str: @@ -244,6 +256,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String longestNiceSubstring(String s) { @@ -270,6 +284,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -295,6 +311,8 @@ public: }; ``` +#### Go + ```go func longestNiceSubstring(s string) string { n := len(s) diff --git a/solution/1700-1799/1763.Longest Nice Substring/README_EN.md b/solution/1700-1799/1763.Longest Nice Substring/README_EN.md index 3d5da11d23eb5..97f00238a9675 100644 --- a/solution/1700-1799/1763.Longest Nice Substring/README_EN.md +++ b/solution/1700-1799/1763.Longest Nice Substring/README_EN.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def longestNiceSubstring(self, s: str) -> str: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String longestNiceSubstring(String s) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func longestNiceSubstring(s string) string { n := len(s) @@ -174,6 +182,8 @@ func longestNiceSubstring(s string) string { } ``` +#### TypeScript + ```ts function longestNiceSubstring(s: string): string { const n = s.length; @@ -207,6 +217,8 @@ function longestNiceSubstring(s: string): string { +#### Python3 + ```python class Solution: def longestNiceSubstring(self, s: str) -> str: @@ -224,6 +236,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String longestNiceSubstring(String s) { @@ -250,6 +264,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -275,6 +291,8 @@ public: }; ``` +#### Go + ```go func longestNiceSubstring(s string) string { n := len(s) diff --git a/solution/1700-1799/1764.Form Array by Concatenating Subarrays of Another Array/README.md b/solution/1700-1799/1764.Form Array by Concatenating Subarrays of Another Array/README.md index 53454c1282e30..d2c318dbb9d30 100644 --- a/solution/1700-1799/1764.Form Array by Concatenating Subarrays of Another Array/README.md +++ b/solution/1700-1799/1764.Form Array by Concatenating Subarrays of Another Array/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def canChoose(self, groups: List[List[int]], nums: List[int]) -> bool: @@ -101,6 +103,8 @@ class Solution: return i == n ``` +#### Java + ```java class Solution { public boolean canChoose(int[][] groups, int[] nums) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func canChoose(groups [][]int, nums []int) bool { check := func(a, b []int, j int) bool { diff --git a/solution/1700-1799/1764.Form Array by Concatenating Subarrays of Another Array/README_EN.md b/solution/1700-1799/1764.Form Array by Concatenating Subarrays of Another Array/README_EN.md index 9cec0f5c88d66..0cc637d6973b6 100644 --- a/solution/1700-1799/1764.Form Array by Concatenating Subarrays of Another Array/README_EN.md +++ b/solution/1700-1799/1764.Form Array by Concatenating Subarrays of Another Array/README_EN.md @@ -78,6 +78,8 @@ They share a common elements nums[4] (0-indexed). +#### Python3 + ```python class Solution: def canChoose(self, groups: List[List[int]], nums: List[int]) -> bool: @@ -93,6 +95,8 @@ class Solution: return i == n ``` +#### Java + ```java class Solution { public boolean canChoose(int[][] groups, int[] nums) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func canChoose(groups [][]int, nums []int) bool { check := func(a, b []int, j int) bool { diff --git a/solution/1700-1799/1765.Map of Highest Peak/README.md b/solution/1700-1799/1765.Map of Highest Peak/README.md index fb3b1061b3875..e25226064744e 100644 --- a/solution/1700-1799/1765.Map of Highest Peak/README.md +++ b/solution/1700-1799/1765.Map of Highest Peak/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def highestPeak(self, isWater: List[List[int]]) -> List[List[int]]: @@ -112,6 +114,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] highestPeak(int[][] isWater) { @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go func highestPeak(isWater [][]int) [][]int { m, n := len(isWater), len(isWater[0]) @@ -208,6 +216,8 @@ func highestPeak(isWater [][]int) [][]int { } ``` +#### TypeScript + ```ts function highestPeak(isWater: number[][]): number[][] { const m = isWater.length; @@ -241,6 +251,8 @@ function highestPeak(isWater: number[][]): number[][] { } ``` +#### Rust + ```rust use std::collections::VecDeque; @@ -303,6 +315,8 @@ impl Solution { +#### Python3 + ```python class Solution: def highestPeak(self, isWater: List[List[int]]) -> List[List[int]]: @@ -325,6 +339,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] highestPeak(int[][] isWater) { @@ -358,6 +374,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -393,6 +411,8 @@ public: }; ``` +#### Go + ```go func highestPeak(isWater [][]int) [][]int { m, n := len(isWater), len(isWater[0]) diff --git a/solution/1700-1799/1765.Map of Highest Peak/README_EN.md b/solution/1700-1799/1765.Map of Highest Peak/README_EN.md index 587d271e02fc9..1f8c40184f5c5 100644 --- a/solution/1700-1799/1765.Map of Highest Peak/README_EN.md +++ b/solution/1700-1799/1765.Map of Highest Peak/README_EN.md @@ -83,6 +83,8 @@ Any height assignment that has a maximum height of 2 while still meeting the rul +#### Python3 + ```python class Solution: def highestPeak(self, isWater: List[List[int]]) -> List[List[int]]: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] highestPeak(int[][] isWater) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func highestPeak(isWater [][]int) [][]int { m, n := len(isWater), len(isWater[0]) @@ -200,6 +208,8 @@ func highestPeak(isWater [][]int) [][]int { } ``` +#### TypeScript + ```ts function highestPeak(isWater: number[][]): number[][] { const m = isWater.length; @@ -233,6 +243,8 @@ function highestPeak(isWater: number[][]): number[][] { } ``` +#### Rust + ```rust use std::collections::VecDeque; @@ -295,6 +307,8 @@ impl Solution { +#### Python3 + ```python class Solution: def highestPeak(self, isWater: List[List[int]]) -> List[List[int]]: @@ -317,6 +331,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] highestPeak(int[][] isWater) { @@ -350,6 +366,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -385,6 +403,8 @@ public: }; ``` +#### Go + ```go func highestPeak(isWater [][]int) [][]int { m, n := len(isWater), len(isWater[0]) diff --git a/solution/1700-1799/1766.Tree of Coprimes/README.md b/solution/1700-1799/1766.Tree of Coprimes/README.md index 7e887831c78d3..382ed19609a02 100644 --- a/solution/1700-1799/1766.Tree of Coprimes/README.md +++ b/solution/1700-1799/1766.Tree of Coprimes/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def getCoprimes(self, nums: List[int], edges: List[List[int]]) -> List[int]: @@ -118,6 +120,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -177,6 +181,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -222,6 +228,8 @@ public: }; ``` +#### Go + ```go func getCoprimes(nums []int, edges [][]int) []int { n := len(nums) diff --git a/solution/1700-1799/1766.Tree of Coprimes/README_EN.md b/solution/1700-1799/1766.Tree of Coprimes/README_EN.md index 3a404c71e8961..e1e25064d7cbf 100644 --- a/solution/1700-1799/1766.Tree of Coprimes/README_EN.md +++ b/solution/1700-1799/1766.Tree of Coprimes/README_EN.md @@ -87,6 +87,8 @@ The time complexity is $O(n \times M)$, and the space complexity is $O(M^2 + n)$ +#### Python3 + ```python class Solution: def getCoprimes(self, nums: List[int], edges: List[List[int]]) -> List[int]: @@ -118,6 +120,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -177,6 +181,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -222,6 +228,8 @@ public: }; ``` +#### Go + ```go func getCoprimes(nums []int, edges [][]int) []int { n := len(nums) diff --git a/solution/1700-1799/1767.Find the Subtasks That Did Not Execute/README.md b/solution/1700-1799/1767.Find the Subtasks That Did Not Execute/README.md index 9235e1444f23e..3ab0a87b74cc4 100644 --- a/solution/1700-1799/1767.Find the Subtasks That Did Not Execute/README.md +++ b/solution/1700-1799/1767.Find the Subtasks That Did Not Execute/README.md @@ -104,6 +104,8 @@ Task 3 被分成了 4 subtasks (1, 2, 3, 4)。所有的subtask都被成功执行 +#### MySQL + ```sql # Write your MySQL query statement below WITH RECURSIVE diff --git a/solution/1700-1799/1767.Find the Subtasks That Did Not Execute/README_EN.md b/solution/1700-1799/1767.Find the Subtasks That Did Not Execute/README_EN.md index f54f86f400a1b..b51f4d7ecdad0 100644 --- a/solution/1700-1799/1767.Find the Subtasks That Did Not Execute/README_EN.md +++ b/solution/1700-1799/1767.Find the Subtasks That Did Not Execute/README_EN.md @@ -103,6 +103,8 @@ We can generate a table recursively that contains all pairs of (parent task, chi +#### MySQL + ```sql # Write your MySQL query statement below WITH RECURSIVE diff --git a/solution/1700-1799/1768.Merge Strings Alternately/README.md b/solution/1700-1799/1768.Merge Strings Alternately/README.md index 23c016efffdfd..4681f84caa55c 100644 --- a/solution/1700-1799/1768.Merge Strings Alternately/README.md +++ b/solution/1700-1799/1768.Merge Strings Alternately/README.md @@ -81,12 +81,16 @@ word2: p q +#### Python3 + ```python class Solution: def mergeAlternately(self, word1: str, word2: str) -> str: return ''.join(a + b for a, b in zip_longest(word1, word2, fillvalue='')) ``` +#### Java + ```java class Solution { public String mergeAlternately(String word1, String word2) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func mergeAlternately(word1 string, word2 string) string { m, n := len(word1), len(word2) @@ -136,6 +144,8 @@ func mergeAlternately(word1 string, word2 string) string { } ``` +#### TypeScript + ```ts function mergeAlternately(word1: string, word2: string): string { const ans: string[] = []; @@ -152,6 +162,8 @@ function mergeAlternately(word1: string, word2: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn merge_alternately(word1: String, word2: String) -> String { @@ -172,6 +184,8 @@ impl Solution { } ``` +#### C + ```c char* mergeAlternately(char* word1, char* word2) { int m = strlen(word1); diff --git a/solution/1700-1799/1768.Merge Strings Alternately/README_EN.md b/solution/1700-1799/1768.Merge Strings Alternately/README_EN.md index 195984a95d041..23f19bc99a475 100644 --- a/solution/1700-1799/1768.Merge Strings Alternately/README_EN.md +++ b/solution/1700-1799/1768.Merge Strings Alternately/README_EN.md @@ -105,12 +105,16 @@ The time complexity is $O(m + n)$, where $m$ and $n$ are the lengths of the two +#### Python3 + ```python class Solution: def mergeAlternately(self, word1: str, word2: str) -> str: return ''.join(a + b for a, b in zip_longest(word1, word2, fillvalue='')) ``` +#### Java + ```java class Solution { public String mergeAlternately(String word1, String word2) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func mergeAlternately(word1 string, word2 string) string { m, n := len(word1), len(word2) @@ -160,6 +168,8 @@ func mergeAlternately(word1 string, word2 string) string { } ``` +#### TypeScript + ```ts function mergeAlternately(word1: string, word2: string): string { const ans: string[] = []; @@ -176,6 +186,8 @@ function mergeAlternately(word1: string, word2: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn merge_alternately(word1: String, word2: String) -> String { @@ -196,6 +208,8 @@ impl Solution { } ``` +#### C + ```c char* mergeAlternately(char* word1, char* word2) { int m = strlen(word1); diff --git a/solution/1700-1799/1769.Minimum Number of Operations to Move All Balls to Each Box/README.md b/solution/1700-1799/1769.Minimum Number of Operations to Move All Balls to Each Box/README.md index 0324687fc15b5..3a6ccc6fd98eb 100644 --- a/solution/1700-1799/1769.Minimum Number of Operations to Move All Balls to Each Box/README.md +++ b/solution/1700-1799/1769.Minimum Number of Operations to Move All Balls to Each Box/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def minOperations(self, boxes: str) -> List[int]: @@ -91,6 +93,8 @@ class Solution: return [a + b for a, b in zip(left, right)] ``` +#### Java + ```java class Solution { public int[] minOperations(String boxes) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func minOperations(boxes string) []int { n := len(boxes) @@ -167,6 +175,8 @@ func minOperations(boxes string) []int { } ``` +#### TypeScript + ```ts function minOperations(boxes: string): number[] { const n = boxes.length; @@ -188,6 +198,8 @@ function minOperations(boxes: string): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn min_operations(boxes: String) -> Vec { @@ -217,6 +229,8 @@ impl Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). @@ -260,6 +274,8 @@ int* minOperations(char* boxes, int* returnSize) { +#### Python3 + ```python class Solution: def minOperations(self, boxes: str) -> List[int]: @@ -279,6 +295,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] minOperations(String boxes) { @@ -302,6 +320,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -322,6 +342,8 @@ public: }; ``` +#### Go + ```go func minOperations(boxes string) []int { n := len(boxes) @@ -343,6 +365,8 @@ func minOperations(boxes string) []int { } ``` +#### TypeScript + ```ts function minOperations(boxes: string): number[] { const n = boxes.length; @@ -364,6 +388,8 @@ function minOperations(boxes: string): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn min_operations(boxes: String) -> Vec { @@ -391,6 +417,8 @@ impl Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). diff --git a/solution/1700-1799/1769.Minimum Number of Operations to Move All Balls to Each Box/README_EN.md b/solution/1700-1799/1769.Minimum Number of Operations to Move All Balls to Each Box/README_EN.md index d3908f60d29b4..fb4fd910dc98c 100644 --- a/solution/1700-1799/1769.Minimum Number of Operations to Move All Balls to Each Box/README_EN.md +++ b/solution/1700-1799/1769.Minimum Number of Operations to Move All Balls to Each Box/README_EN.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def minOperations(self, boxes: str) -> List[int]: @@ -83,6 +85,8 @@ class Solution: return [a + b for a, b in zip(left, right)] ``` +#### Java + ```java class Solution { public int[] minOperations(String boxes) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func minOperations(boxes string) []int { n := len(boxes) @@ -159,6 +167,8 @@ func minOperations(boxes string) []int { } ``` +#### TypeScript + ```ts function minOperations(boxes: string): number[] { const n = boxes.length; @@ -180,6 +190,8 @@ function minOperations(boxes: string): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn min_operations(boxes: String) -> Vec { @@ -209,6 +221,8 @@ impl Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). @@ -252,6 +266,8 @@ int* minOperations(char* boxes, int* returnSize) { +#### Python3 + ```python class Solution: def minOperations(self, boxes: str) -> List[int]: @@ -271,6 +287,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] minOperations(String boxes) { @@ -294,6 +312,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -314,6 +334,8 @@ public: }; ``` +#### Go + ```go func minOperations(boxes string) []int { n := len(boxes) @@ -335,6 +357,8 @@ func minOperations(boxes string) []int { } ``` +#### TypeScript + ```ts function minOperations(boxes: string): number[] { const n = boxes.length; @@ -356,6 +380,8 @@ function minOperations(boxes: string): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn min_operations(boxes: String) -> Vec { @@ -383,6 +409,8 @@ impl Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). diff --git a/solution/1700-1799/1770.Maximum Score from Performing Multiplication Operations/README.md b/solution/1700-1799/1770.Maximum Score from Performing Multiplication Operations/README.md index 8f1852cd2e1a6..37c9bb5c7ece6 100644 --- a/solution/1700-1799/1770.Maximum Score from Performing Multiplication Operations/README.md +++ b/solution/1700-1799/1770.Maximum Score from Performing Multiplication Operations/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def maximumScore(self, nums: List[int], multipliers: List[int]) -> int: @@ -105,6 +107,8 @@ class Solution: return f(0, n - 1, 0) ``` +#### Java + ```java class Solution { private Integer[][] f; @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func maximumScore(nums []int, multipliers []int) int { n, m := len(nums), len(multipliers) @@ -186,6 +194,8 @@ func maximumScore(nums []int, multipliers []int) int { } ``` +#### TypeScript + ```ts function maximumScore(nums: number[], multipliers: number[]): number { const inf = 1 << 30; @@ -232,6 +242,8 @@ function maximumScore(nums: number[], multipliers: number[]): number { +#### Python3 + ```python class Solution: def maximumScore(self, nums: List[int], multipliers: List[int]) -> int: @@ -251,6 +263,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumScore(int[] nums, int[] multipliers) { @@ -281,6 +295,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -309,6 +325,8 @@ public: }; ``` +#### Go + ```go func maximumScore(nums []int, multipliers []int) int { const inf int = 1 << 30 diff --git a/solution/1700-1799/1770.Maximum Score from Performing Multiplication Operations/README_EN.md b/solution/1700-1799/1770.Maximum Score from Performing Multiplication Operations/README_EN.md index 26f5eb5d8f39d..166375bad0787 100644 --- a/solution/1700-1799/1770.Maximum Score from Performing Multiplication Operations/README_EN.md +++ b/solution/1700-1799/1770.Maximum Score from Performing Multiplication Operations/README_EN.md @@ -82,6 +82,8 @@ The total score is 50 + 15 - 9 + 4 + 42 = 102. +#### Python3 + ```python class Solution: def maximumScore(self, nums: List[int], multipliers: List[int]) -> int: @@ -98,6 +100,8 @@ class Solution: return f(0, n - 1, 0) ``` +#### Java + ```java class Solution { private Integer[][] f; @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func maximumScore(nums []int, multipliers []int) int { n, m := len(nums), len(multipliers) @@ -179,6 +187,8 @@ func maximumScore(nums []int, multipliers []int) int { } ``` +#### TypeScript + ```ts function maximumScore(nums: number[], multipliers: number[]): number { const inf = 1 << 30; @@ -215,6 +225,8 @@ function maximumScore(nums: number[], multipliers: number[]): number { +#### Python3 + ```python class Solution: def maximumScore(self, nums: List[int], multipliers: List[int]) -> int: @@ -234,6 +246,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumScore(int[] nums, int[] multipliers) { @@ -264,6 +278,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -292,6 +308,8 @@ public: }; ``` +#### Go + ```go func maximumScore(nums []int, multipliers []int) int { const inf int = 1 << 30 diff --git a/solution/1700-1799/1771.Maximize Palindrome Length From Subsequences/README.md b/solution/1700-1799/1771.Maximize Palindrome Length From Subsequences/README.md index c0398a979c9e7..cc21e7d6fc0b7 100644 --- a/solution/1700-1799/1771.Maximize Palindrome Length From Subsequences/README.md +++ b/solution/1700-1799/1771.Maximize Palindrome Length From Subsequences/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def longestPalindrome(self, word1: str, word2: str) -> int: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestPalindrome(String word1, String word2) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func longestPalindrome(word1 string, word2 string) (ans int) { s := word1 + word2 @@ -183,6 +191,8 @@ func longestPalindrome(word1 string, word2 string) (ans int) { } ``` +#### TypeScript + ```ts function longestPalindrome(word1: string, word2: string): number { const s = word1 + word2; @@ -208,6 +218,8 @@ function longestPalindrome(word1: string, word2: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn longest_palindrome(word1: String, word2: String) -> i32 { diff --git a/solution/1700-1799/1771.Maximize Palindrome Length From Subsequences/README_EN.md b/solution/1700-1799/1771.Maximize Palindrome Length From Subsequences/README_EN.md index 848ae2019d9e6..047bc4b341d23 100644 --- a/solution/1700-1799/1771.Maximize Palindrome Length From Subsequences/README_EN.md +++ b/solution/1700-1799/1771.Maximize Palindrome Length From Subsequences/README_EN.md @@ -85,6 +85,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$. Here, $n$ +#### Python3 + ```python class Solution: def longestPalindrome(self, word1: str, word2: str) -> int: @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestPalindrome(String word1, String word2) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func longestPalindrome(word1 string, word2 string) (ans int) { s := word1 + word2 @@ -184,6 +192,8 @@ func longestPalindrome(word1 string, word2 string) (ans int) { } ``` +#### TypeScript + ```ts function longestPalindrome(word1: string, word2: string): number { const s = word1 + word2; @@ -209,6 +219,8 @@ function longestPalindrome(word1: string, word2: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn longest_palindrome(word1: String, word2: String) -> i32 { diff --git a/solution/1700-1799/1772.Sort Features by Popularity/README.md b/solution/1700-1799/1772.Sort Features by Popularity/README.md index 8288b974e0b21..3f634efc6cf66 100644 --- a/solution/1700-1799/1772.Sort Features by Popularity/README.md +++ b/solution/1700-1799/1772.Sort Features by Popularity/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def sortFeatures(self, features: List[str], responses: List[str]) -> List[str]: @@ -84,6 +86,8 @@ class Solution: return sorted(features, key=lambda w: -cnt[w]) ``` +#### Java + ```java class Solution { public String[] sortFeatures(String[] features, String[] responses) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func sortFeatures(features []string, responses []string) []string { cnt := map[string]int{} @@ -164,6 +172,8 @@ func sortFeatures(features []string, responses []string) []string { } ``` +#### TypeScript + ```ts function sortFeatures(features: string[], responses: string[]): string[] { const cnt: Map = new Map(); diff --git a/solution/1700-1799/1772.Sort Features by Popularity/README_EN.md b/solution/1700-1799/1772.Sort Features by Popularity/README_EN.md index be4126006dcc9..294294a4b3f42 100644 --- a/solution/1700-1799/1772.Sort Features by Popularity/README_EN.md +++ b/solution/1700-1799/1772.Sort Features by Popularity/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(n \times \log n)$, where $n$ is the length of `feature +#### Python3 + ```python class Solution: def sortFeatures(self, features: List[str], responses: List[str]) -> List[str]: @@ -82,6 +84,8 @@ class Solution: return sorted(features, key=lambda w: -cnt[w]) ``` +#### Java + ```java class Solution { public String[] sortFeatures(String[] features, String[] responses) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func sortFeatures(features []string, responses []string) []string { cnt := map[string]int{} @@ -162,6 +170,8 @@ func sortFeatures(features []string, responses []string) []string { } ``` +#### TypeScript + ```ts function sortFeatures(features: string[], responses: string[]): string[] { const cnt: Map = new Map(); diff --git a/solution/1700-1799/1773.Count Items Matching a Rule/README.md b/solution/1700-1799/1773.Count Items Matching a Rule/README.md index c5c08a9ef1004..fef382a11b62d 100644 --- a/solution/1700-1799/1773.Count Items Matching a Rule/README.md +++ b/solution/1700-1799/1773.Count Items Matching a Rule/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def countMatches(self, items: List[List[str]], ruleKey: str, ruleValue: str) -> int: @@ -82,6 +84,8 @@ class Solution: return sum(v[i] == ruleValue for v in items) ``` +#### Java + ```java class Solution { public int countMatches(List> items, String ruleKey, String ruleValue) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func countMatches(items [][]string, ruleKey string, ruleValue string) (ans int) { i := map[byte]int{'t': 0, 'c': 1, 'n': 2}[ruleKey[0]] @@ -119,6 +127,8 @@ func countMatches(items [][]string, ruleKey string, ruleValue string) (ans int) } ``` +#### TypeScript + ```ts function countMatches(items: string[][], ruleKey: string, ruleValue: string): number { const key = ruleKey === 'type' ? 0 : ruleKey === 'color' ? 1 : 2; @@ -126,6 +136,8 @@ function countMatches(items: string[][], ruleKey: string, ruleValue: string): nu } ``` +#### Rust + ```rust impl Solution { pub fn count_matches(items: Vec>, rule_key: String, rule_value: String) -> i32 { @@ -138,6 +150,8 @@ impl Solution { } ``` +#### C + ```c int countMatches(char*** items, int itemsSize, int* itemsColSize, char* ruleKey, char* ruleValue) { int k = strcmp(ruleKey, "type") == 0 ? 0 : strcmp(ruleKey, "color") == 0 ? 1 diff --git a/solution/1700-1799/1773.Count Items Matching a Rule/README_EN.md b/solution/1700-1799/1773.Count Items Matching a Rule/README_EN.md index 5b7d2021359d3..abdaf339c0520 100644 --- a/solution/1700-1799/1773.Count Items Matching a Rule/README_EN.md +++ b/solution/1700-1799/1773.Count Items Matching a Rule/README_EN.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def countMatches(self, items: List[List[str]], ruleKey: str, ruleValue: str) -> int: @@ -74,6 +76,8 @@ class Solution: return sum(v[i] == ruleValue for v in items) ``` +#### Java + ```java class Solution { public int countMatches(List> items, String ruleKey, String ruleValue) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -99,6 +105,8 @@ public: }; ``` +#### Go + ```go func countMatches(items [][]string, ruleKey string, ruleValue string) (ans int) { i := map[byte]int{'t': 0, 'c': 1, 'n': 2}[ruleKey[0]] @@ -111,6 +119,8 @@ func countMatches(items [][]string, ruleKey string, ruleValue string) (ans int) } ``` +#### TypeScript + ```ts function countMatches(items: string[][], ruleKey: string, ruleValue: string): number { const key = ruleKey === 'type' ? 0 : ruleKey === 'color' ? 1 : 2; @@ -118,6 +128,8 @@ function countMatches(items: string[][], ruleKey: string, ruleValue: string): nu } ``` +#### Rust + ```rust impl Solution { pub fn count_matches(items: Vec>, rule_key: String, rule_value: String) -> i32 { @@ -130,6 +142,8 @@ impl Solution { } ``` +#### C + ```c int countMatches(char*** items, int itemsSize, int* itemsColSize, char* ruleKey, char* ruleValue) { int k = strcmp(ruleKey, "type") == 0 ? 0 : strcmp(ruleKey, "color") == 0 ? 1 diff --git a/solution/1700-1799/1774.Closest Dessert Cost/README.md b/solution/1700-1799/1774.Closest Dessert Cost/README.md index 6eaee8f593135..041c7c83d29dc 100644 --- a/solution/1700-1799/1774.Closest Dessert Cost/README.md +++ b/solution/1700-1799/1774.Closest Dessert Cost/README.md @@ -112,6 +112,8 @@ tags: +#### Python3 + ```python class Solution: def closestCost( @@ -144,6 +146,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List arr = new ArrayList<>(); @@ -200,6 +204,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -239,6 +245,8 @@ public: }; ``` +#### Go + ```go func closestCost(baseCosts []int, toppingCosts []int, target int) int { arr := []int{} @@ -283,6 +291,8 @@ func abs(x int) int { } ``` +#### JavaScript + ```js const closestCost = function (baseCosts, toppingCosts, target) { let closestDessertCost = -Infinity; diff --git a/solution/1700-1799/1774.Closest Dessert Cost/README_EN.md b/solution/1700-1799/1774.Closest Dessert Cost/README_EN.md index b0b6bee3d7399..3d535e9994b15 100644 --- a/solution/1700-1799/1774.Closest Dessert Cost/README_EN.md +++ b/solution/1700-1799/1774.Closest Dessert Cost/README_EN.md @@ -95,6 +95,8 @@ Total: 3 + 4 + 10 + 0 = 17. You cannot make a dessert with a total cost of 18. +#### Python3 + ```python class Solution: def closestCost( @@ -127,6 +129,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List arr = new ArrayList<>(); @@ -183,6 +187,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -222,6 +228,8 @@ public: }; ``` +#### Go + ```go func closestCost(baseCosts []int, toppingCosts []int, target int) int { arr := []int{} @@ -266,6 +274,8 @@ func abs(x int) int { } ``` +#### JavaScript + ```js const closestCost = function (baseCosts, toppingCosts, target) { let closestDessertCost = -Infinity; diff --git a/solution/1700-1799/1775.Equal Sum Arrays With Minimum Number of Operations/README.md b/solution/1700-1799/1775.Equal Sum Arrays With Minimum Number of Operations/README.md index f4d85a8631911..285d46ed6335b 100644 --- a/solution/1700-1799/1775.Equal Sum Arrays With Minimum Number of Operations/README.md +++ b/solution/1700-1799/1775.Equal Sum Arrays With Minimum Number of Operations/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def minOperations(self, nums1: List[int], nums2: List[int]) -> int: @@ -108,6 +110,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minOperations(int[] nums1, int[] nums2) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums1 []int, nums2 []int) int { s1, s2 := sum(nums1), sum(nums2) @@ -214,6 +222,8 @@ func sum(nums []int) (s int) { +#### Python3 + ```python class Solution: def minOperations(self, nums1: List[int], nums2: List[int]) -> int: @@ -233,6 +243,8 @@ class Solution: return ans if d <= 0 else -1 ``` +#### Java + ```java class Solution { public int minOperations(int[] nums1, int[] nums2) { @@ -265,6 +277,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -290,6 +304,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums1 []int, nums2 []int) (ans int) { s1, s2 := sum(nums1), sum(nums2) diff --git a/solution/1700-1799/1775.Equal Sum Arrays With Minimum Number of Operations/README_EN.md b/solution/1700-1799/1775.Equal Sum Arrays With Minimum Number of Operations/README_EN.md index 100954f452541..6100d83aed7ec 100644 --- a/solution/1700-1799/1775.Equal Sum Arrays With Minimum Number of Operations/README_EN.md +++ b/solution/1700-1799/1775.Equal Sum Arrays With Minimum Number of Operations/README_EN.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def minOperations(self, nums1: List[int], nums2: List[int]) -> int: @@ -93,6 +95,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minOperations(int[] nums1, int[] nums2) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums1 []int, nums2 []int) int { s1, s2 := sum(nums1), sum(nums2) @@ -193,6 +201,8 @@ func sum(nums []int) (s int) { +#### Python3 + ```python class Solution: def minOperations(self, nums1: List[int], nums2: List[int]) -> int: @@ -212,6 +222,8 @@ class Solution: return ans if d <= 0 else -1 ``` +#### Java + ```java class Solution { public int minOperations(int[] nums1, int[] nums2) { @@ -244,6 +256,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -269,6 +283,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums1 []int, nums2 []int) (ans int) { s1, s2 := sum(nums1), sum(nums2) diff --git a/solution/1700-1799/1776.Car Fleet II/README.md b/solution/1700-1799/1776.Car Fleet II/README.md index 4bf202306ffe6..34a569efe1733 100644 --- a/solution/1700-1799/1776.Car Fleet II/README.md +++ b/solution/1700-1799/1776.Car Fleet II/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def getCollisionTimes(self, cars: List[List[int]]) -> List[float]: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public double[] getCollisionTimes(int[][] cars) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func getCollisionTimes(cars [][]int) []float64 { n := len(cars) diff --git a/solution/1700-1799/1776.Car Fleet II/README_EN.md b/solution/1700-1799/1776.Car Fleet II/README_EN.md index 1fdf5fef22e9b..2bc7340c7b9a8 100644 --- a/solution/1700-1799/1776.Car Fleet II/README_EN.md +++ b/solution/1700-1799/1776.Car Fleet II/README_EN.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def getCollisionTimes(self, cars: List[List[int]]) -> List[float]: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public double[] getCollisionTimes(int[][] cars) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func getCollisionTimes(cars [][]int) []float64 { n := len(cars) diff --git a/solution/1700-1799/1777.Product's Price for Each Store/README.md b/solution/1700-1799/1777.Product's Price for Each Store/README.md index 894500ffcdd56..1ab9ae755c3a3 100644 --- a/solution/1700-1799/1777.Product's Price for Each Store/README.md +++ b/solution/1700-1799/1777.Product's Price for Each Store/README.md @@ -76,6 +76,8 @@ Products 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1700-1799/1777.Product's Price for Each Store/README_EN.md b/solution/1700-1799/1777.Product's Price for Each Store/README_EN.md index 434bac66b189d..a880ab90c9565 100644 --- a/solution/1700-1799/1777.Product's Price for Each Store/README_EN.md +++ b/solution/1700-1799/1777.Product's Price for Each Store/README_EN.md @@ -76,6 +76,8 @@ Product 1 price's are 70 for store1, 80 for store3 and, it's not sold in +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1700-1799/1778.Shortest Path in a Hidden Grid/README.md b/solution/1700-1799/1778.Shortest Path in a Hidden Grid/README.md index fa6da92564a93..3c74cd0136b01 100644 --- a/solution/1700-1799/1778.Shortest Path in a Hidden Grid/README.md +++ b/solution/1700-1799/1778.Shortest Path in a Hidden Grid/README.md @@ -119,6 +119,8 @@ The robot is initially standing on cell (1, 0), denoted by the -1. +#### Python3 + ```python # """ # This is GridMaster's API interface. @@ -175,6 +177,8 @@ class Solution(object): return -1 ``` +#### Java + ```java /** * // This is the GridMaster's API interface. @@ -237,6 +241,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * // This is the GridMaster's API interface. diff --git a/solution/1700-1799/1778.Shortest Path in a Hidden Grid/README_EN.md b/solution/1700-1799/1778.Shortest Path in a Hidden Grid/README_EN.md index 8eaf3db7beb60..f902059a7f622 100644 --- a/solution/1700-1799/1778.Shortest Path in a Hidden Grid/README_EN.md +++ b/solution/1700-1799/1778.Shortest Path in a Hidden Grid/README_EN.md @@ -119,6 +119,8 @@ Similar problems: +#### Python3 + ```python # """ # This is GridMaster's API interface. @@ -175,6 +177,8 @@ class Solution(object): return -1 ``` +#### Java + ```java /** * // This is the GridMaster's API interface. @@ -237,6 +241,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * // This is the GridMaster's API interface. diff --git a/solution/1700-1799/1779.Find Nearest Point That Has the Same X or Y Coordinate/README.md b/solution/1700-1799/1779.Find Nearest Point That Has the Same X or Y Coordinate/README.md index 9026c20882dd2..963844a9dd0b7 100644 --- a/solution/1700-1799/1779.Find Nearest Point That Has the Same X or Y Coordinate/README.md +++ b/solution/1700-1799/1779.Find Nearest Point That Has the Same X or Y Coordinate/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int nearestValidPoint(int x, int y, int[][] points) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func nearestValidPoint(x int, y int, points [][]int) int { ans, mi := -1, 1000000 @@ -145,6 +153,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function nearestValidPoint(x: number, y: number, points: number[][]): number { let res = -1; @@ -163,6 +173,8 @@ function nearestValidPoint(x: number, y: number, points: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn nearest_valid_point(x: i32, y: i32, points: Vec>) -> i32 { @@ -185,6 +197,8 @@ impl Solution { } ``` +#### C + ```c int nearestValidPoint(int x, int y, int** points, int pointsSize, int* pointsColSize) { int ans = -1; diff --git a/solution/1700-1799/1779.Find Nearest Point That Has the Same X or Y Coordinate/README_EN.md b/solution/1700-1799/1779.Find Nearest Point That Has the Same X or Y Coordinate/README_EN.md index b88c491e72be6..102d73024bd4c 100644 --- a/solution/1700-1799/1779.Find Nearest Point That Has the Same X or Y Coordinate/README_EN.md +++ b/solution/1700-1799/1779.Find Nearest Point That Has the Same X or Y Coordinate/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int: @@ -77,6 +79,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int nearestValidPoint(int x, int y, int[][] points) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func nearestValidPoint(x int, y int, points [][]int) int { ans, mi := -1, 1000000 @@ -139,6 +147,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function nearestValidPoint(x: number, y: number, points: number[][]): number { let res = -1; @@ -157,6 +167,8 @@ function nearestValidPoint(x: number, y: number, points: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn nearest_valid_point(x: i32, y: i32, points: Vec>) -> i32 { @@ -179,6 +191,8 @@ impl Solution { } ``` +#### C + ```c int nearestValidPoint(int x, int y, int** points, int pointsSize, int* pointsColSize) { int ans = -1; diff --git a/solution/1700-1799/1780.Check if Number is a Sum of Powers of Three/README.md b/solution/1700-1799/1780.Check if Number is a Sum of Powers of Three/README.md index da36ad00d743d..c42f804c43b85 100644 --- a/solution/1700-1799/1780.Check if Number is a Sum of Powers of Three/README.md +++ b/solution/1700-1799/1780.Check if Number is a Sum of Powers of Three/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def checkPowersOfThree(self, n: int) -> bool: @@ -78,6 +80,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean checkPowersOfThree(int n) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func checkPowersOfThree(n int) bool { for n > 0 { @@ -117,6 +125,8 @@ func checkPowersOfThree(n int) bool { } ``` +#### TypeScript + ```ts function checkPowersOfThree(n: number): boolean { while (n) { diff --git a/solution/1700-1799/1780.Check if Number is a Sum of Powers of Three/README_EN.md b/solution/1700-1799/1780.Check if Number is a Sum of Powers of Three/README_EN.md index 03f61501da54f..ae217d7ac7430 100644 --- a/solution/1700-1799/1780.Check if Number is a Sum of Powers of Three/README_EN.md +++ b/solution/1700-1799/1780.Check if Number is a Sum of Powers of Three/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(\log_3 n)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def checkPowersOfThree(self, n: int) -> bool: @@ -79,6 +81,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean checkPowersOfThree(int n) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func checkPowersOfThree(n int) bool { for n > 0 { @@ -118,6 +126,8 @@ func checkPowersOfThree(n int) bool { } ``` +#### TypeScript + ```ts function checkPowersOfThree(n: number): boolean { while (n) { diff --git a/solution/1700-1799/1781.Sum of Beauty of All Substrings/README.md b/solution/1700-1799/1781.Sum of Beauty of All Substrings/README.md index 5202984dd57ed..cc7e39c226939 100644 --- a/solution/1700-1799/1781.Sum of Beauty of All Substrings/README.md +++ b/solution/1700-1799/1781.Sum of Beauty of All Substrings/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def beautySum(self, s: str) -> int: @@ -79,6 +81,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int beautySum(String s) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func beautySum(s string) (ans int) { for i := range s { @@ -153,6 +161,8 @@ func beautySum(s string) (ans int) { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -182,6 +192,8 @@ var beautySum = function (s) { +#### Python3 + ```python class Solution: def beautySum(self, s: str) -> int: @@ -206,6 +218,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int beautySum(String s) { @@ -238,6 +252,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -271,6 +287,8 @@ public: }; ``` +#### Go + ```go func beautySum(s string) (ans int) { n := len(s) @@ -300,6 +318,8 @@ func beautySum(s string) (ans int) { } ``` +#### JavaScript + ```js /** * @param {string} s diff --git a/solution/1700-1799/1781.Sum of Beauty of All Substrings/README_EN.md b/solution/1700-1799/1781.Sum of Beauty of All Substrings/README_EN.md index 0d9fb80f08e9f..c8f1fddcad725 100644 --- a/solution/1700-1799/1781.Sum of Beauty of All Substrings/README_EN.md +++ b/solution/1700-1799/1781.Sum of Beauty of All Substrings/README_EN.md @@ -65,6 +65,8 @@ The time complexity is $O(n^2 \times C)$, and the space complexity is $O(C)$. He +#### Python3 + ```python class Solution: def beautySum(self, s: str) -> int: @@ -77,6 +79,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int beautySum(String s) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func beautySum(s string) (ans int) { for i := range s { @@ -151,6 +159,8 @@ func beautySum(s string) (ans int) { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -180,6 +190,8 @@ var beautySum = function (s) { +#### Python3 + ```python class Solution: def beautySum(self, s: str) -> int: @@ -204,6 +216,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int beautySum(String s) { @@ -236,6 +250,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -269,6 +285,8 @@ public: }; ``` +#### Go + ```go func beautySum(s string) (ans int) { n := len(s) @@ -298,6 +316,8 @@ func beautySum(s string) (ans int) { } ``` +#### JavaScript + ```js /** * @param {string} s diff --git a/solution/1700-1799/1782.Count Pairs Of Nodes/README.md b/solution/1700-1799/1782.Count Pairs Of Nodes/README.md index d8d1a30d2be51..147e25290a894 100644 --- a/solution/1700-1799/1782.Count Pairs Of Nodes/README.md +++ b/solution/1700-1799/1782.Count Pairs Of Nodes/README.md @@ -87,6 +87,8 @@ answers[1] = 5。所有的点对(a, b)中除了(3,4)边数等于3,其它点对 +#### Python3 + ```python class Solution: def countPairs( @@ -113,6 +115,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] countPairs(int n, int[][] edges, int[] queries) { @@ -161,6 +165,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -196,6 +202,8 @@ public: }; ``` +#### Go + ```go func countPairs(n int, edges [][]int, queries []int) []int { cnt := make([]int, n) @@ -229,6 +237,8 @@ func countPairs(n int, edges [][]int, queries []int) []int { } ``` +#### TypeScript + ```ts function countPairs(n: number, edges: number[][], queries: number[]): number[] { const cnt: number[] = new Array(n).fill(0); diff --git a/solution/1700-1799/1782.Count Pairs Of Nodes/README_EN.md b/solution/1700-1799/1782.Count Pairs Of Nodes/README_EN.md index adb564a7b4b58..10717cdd494c1 100644 --- a/solution/1700-1799/1782.Count Pairs Of Nodes/README_EN.md +++ b/solution/1700-1799/1782.Count Pairs Of Nodes/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(q \times (n \times \log n + m))$, and the space comple +#### Python3 + ```python class Solution: def countPairs( @@ -112,6 +114,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] countPairs(int n, int[][] edges, int[] queries) { @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -195,6 +201,8 @@ public: }; ``` +#### Go + ```go func countPairs(n int, edges [][]int, queries []int) []int { cnt := make([]int, n) @@ -228,6 +236,8 @@ func countPairs(n int, edges [][]int, queries []int) []int { } ``` +#### TypeScript + ```ts function countPairs(n: number, edges: number[][], queries: number[]): number[] { const cnt: number[] = new Array(n).fill(0); diff --git a/solution/1700-1799/1783.Grand Slam Titles/README.md b/solution/1700-1799/1783.Grand Slam Titles/README.md index c20c4db17c319..949b0383359cc 100644 --- a/solution/1700-1799/1783.Grand Slam Titles/README.md +++ b/solution/1700-1799/1783.Grand Slam Titles/README.md @@ -101,6 +101,8 @@ Player 3 (Novak) 没有赢得,因此不包含在结果集中。 +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -134,6 +136,8 @@ GROUP BY 1; +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1700-1799/1783.Grand Slam Titles/README_EN.md b/solution/1700-1799/1783.Grand Slam Titles/README_EN.md index 8e69b170859ac..5dc590bf4e33a 100644 --- a/solution/1700-1799/1783.Grand Slam Titles/README_EN.md +++ b/solution/1700-1799/1783.Grand Slam Titles/README_EN.md @@ -101,6 +101,8 @@ We can use `UNION ALL` to merge all player IDs who won Grand Slam titles into a +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -134,6 +136,8 @@ GROUP BY 1; +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1700-1799/1784.Check if Binary String Has at Most One Segment of Ones/README.md b/solution/1700-1799/1784.Check if Binary String Has at Most One Segment of Ones/README.md index d9527e77d09cb..6b33f903bb616 100644 --- a/solution/1700-1799/1784.Check if Binary String Has at Most One Segment of Ones/README.md +++ b/solution/1700-1799/1784.Check if Binary String Has at Most One Segment of Ones/README.md @@ -68,12 +68,16 @@ tags: +#### Python3 + ```python class Solution: def checkOnesSegment(self, s: str) -> bool: return '01' not in s ``` +#### Java + ```java class Solution { public boolean checkOnesSegment(String s) { @@ -82,6 +86,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -91,12 +97,16 @@ public: }; ``` +#### Go + ```go func checkOnesSegment(s string) bool { return !strings.Contains(s, "01") } ``` +#### TypeScript + ```ts function checkOnesSegment(s: string): boolean { let pre = s[0]; @@ -110,6 +120,8 @@ function checkOnesSegment(s: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn check_ones_segment(s: String) -> bool { @@ -128,6 +140,8 @@ impl Solution { +#### TypeScript + ```ts function checkOnesSegment(s: string): boolean { return !s.includes('01'); diff --git a/solution/1700-1799/1784.Check if Binary String Has at Most One Segment of Ones/README_EN.md b/solution/1700-1799/1784.Check if Binary String Has at Most One Segment of Ones/README_EN.md index bb546efa92150..ef2ea64e26b02 100644 --- a/solution/1700-1799/1784.Check if Binary String Has at Most One Segment of Ones/README_EN.md +++ b/solution/1700-1799/1784.Check if Binary String Has at Most One Segment of Ones/README_EN.md @@ -64,12 +64,16 @@ The time complexity is $O(n)$, where $n$ is the length of the string $s$. The sp +#### Python3 + ```python class Solution: def checkOnesSegment(self, s: str) -> bool: return '01' not in s ``` +#### Java + ```java class Solution { public boolean checkOnesSegment(String s) { @@ -78,6 +82,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -87,12 +93,16 @@ public: }; ``` +#### Go + ```go func checkOnesSegment(s string) bool { return !strings.Contains(s, "01") } ``` +#### TypeScript + ```ts function checkOnesSegment(s: string): boolean { let pre = s[0]; @@ -106,6 +116,8 @@ function checkOnesSegment(s: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn check_ones_segment(s: String) -> bool { @@ -124,6 +136,8 @@ impl Solution { +#### TypeScript + ```ts function checkOnesSegment(s: string): boolean { return !s.includes('01'); diff --git a/solution/1700-1799/1785.Minimum Elements to Add to Form a Given Sum/README.md b/solution/1700-1799/1785.Minimum Elements to Add to Form a Given Sum/README.md index 73bad22a3f906..6b4e006c43a8a 100644 --- a/solution/1700-1799/1785.Minimum Elements to Add to Form a Given Sum/README.md +++ b/solution/1700-1799/1785.Minimum Elements to Add to Form a Given Sum/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def minElements(self, nums: List[int], limit: int, goal: int) -> int: @@ -78,6 +80,8 @@ class Solution: return (d + limit - 1) // limit ``` +#### Java + ```java class Solution { public int minElements(int[] nums, int limit, int goal) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -103,6 +109,8 @@ public: }; ``` +#### Go + ```go func minElements(nums []int, limit int, goal int) int { s := 0 @@ -121,6 +129,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function minElements(nums: number[], limit: number, goal: number): number { const sum = nums.reduce((r, v) => r + v, 0); @@ -129,6 +139,8 @@ function minElements(nums: number[], limit: number, goal: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_elements(nums: Vec, limit: i32, goal: i32) -> i32 { @@ -144,6 +156,8 @@ impl Solution { } ``` +#### C + ```c int minElements(int* nums, int numsSize, int limit, int goal) { long long sum = 0; diff --git a/solution/1700-1799/1785.Minimum Elements to Add to Form a Given Sum/README_EN.md b/solution/1700-1799/1785.Minimum Elements to Add to Form a Given Sum/README_EN.md index 8e152e3b85e0f..10f6411243317 100644 --- a/solution/1700-1799/1785.Minimum Elements to Add to Form a Given Sum/README_EN.md +++ b/solution/1700-1799/1785.Minimum Elements to Add to Form a Given Sum/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is +#### Python3 + ```python class Solution: def minElements(self, nums: List[int], limit: int, goal: int) -> int: @@ -76,6 +78,8 @@ class Solution: return (d + limit - 1) // limit ``` +#### Java + ```java class Solution { public int minElements(int[] nums, int limit, int goal) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,6 +107,8 @@ public: }; ``` +#### Go + ```go func minElements(nums []int, limit int, goal int) int { s := 0 @@ -119,6 +127,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function minElements(nums: number[], limit: number, goal: number): number { const sum = nums.reduce((r, v) => r + v, 0); @@ -127,6 +137,8 @@ function minElements(nums: number[], limit: number, goal: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_elements(nums: Vec, limit: i32, goal: i32) -> i32 { @@ -142,6 +154,8 @@ impl Solution { } ``` +#### C + ```c int minElements(int* nums, int numsSize, int limit, int goal) { long long sum = 0; diff --git a/solution/1700-1799/1786.Number of Restricted Paths From First to Last Node/README.md b/solution/1700-1799/1786.Number of Restricted Paths From First to Last Node/README.md index 00a8fa424978a..94aa50110fbb2 100644 --- a/solution/1700-1799/1786.Number of Restricted Paths From First to Last Node/README.md +++ b/solution/1700-1799/1786.Number of Restricted Paths From First to Last Node/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def countRestrictedPaths(self, n: int, edges: List[List[int]]) -> int: @@ -105,6 +107,8 @@ class Solution: return dfs(1) ``` +#### Java + ```java class Solution { private static final int INF = Integer.MAX_VALUE; @@ -166,6 +170,8 @@ class Solution { } ``` +#### C++ + ```cpp using pii = pair; @@ -219,6 +225,8 @@ public: }; ``` +#### Go + ```go const inf = math.MaxInt32 const mod = 1e9 + 7 @@ -298,6 +306,8 @@ func countRestrictedPaths(n int, edges [][]int) int { +#### Python3 + ```python class Solution: def countRestrictedPaths(self, n: int, edges: List[List[int]]) -> int: @@ -326,6 +336,8 @@ class Solution: return f[1] ``` +#### Java + ```java class Solution { private static final int INF = Integer.MAX_VALUE; diff --git a/solution/1700-1799/1786.Number of Restricted Paths From First to Last Node/README_EN.md b/solution/1700-1799/1786.Number of Restricted Paths From First to Last Node/README_EN.md index dfe62ea5e8cea..6a5967a1a8746 100644 --- a/solution/1700-1799/1786.Number of Restricted Paths From First to Last Node/README_EN.md +++ b/solution/1700-1799/1786.Number of Restricted Paths From First to Last Node/README_EN.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def countRestrictedPaths(self, n: int, edges: List[List[int]]) -> int: @@ -104,6 +106,8 @@ class Solution: return dfs(1) ``` +#### Java + ```java class Solution { private static final int INF = Integer.MAX_VALUE; @@ -165,6 +169,8 @@ class Solution { } ``` +#### C++ + ```cpp using pii = pair; @@ -218,6 +224,8 @@ public: }; ``` +#### Go + ```go const inf = math.MaxInt32 const mod = 1e9 + 7 @@ -297,6 +305,8 @@ func countRestrictedPaths(n int, edges [][]int) int { +#### Python3 + ```python class Solution: def countRestrictedPaths(self, n: int, edges: List[List[int]]) -> int: @@ -325,6 +335,8 @@ class Solution: return f[1] ``` +#### Java + ```java class Solution { private static final int INF = Integer.MAX_VALUE; diff --git a/solution/1700-1799/1787.Make the XOR of All Segments Equal to Zero/README.md b/solution/1700-1799/1787.Make the XOR of All Segments Equal to Zero/README.md index 5297af2b66489..918d759c46985 100644 --- a/solution/1700-1799/1787.Make the XOR of All Segments Equal to Zero/README.md +++ b/solution/1700-1799/1787.Make the XOR of All Segments Equal to Zero/README.md @@ -94,6 +94,8 @@ $$ +#### Python3 + ```python class Solution: def minChanges(self, nums: List[int], k: int) -> int: @@ -114,6 +116,8 @@ class Solution: return f[0] ``` +#### Java + ```java class Solution { public int minChanges(int[] nums, int k) { @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -182,6 +188,8 @@ public: }; ``` +#### Go + ```go func minChanges(nums []int, k int) int { n := 1 << 10 diff --git a/solution/1700-1799/1787.Make the XOR of All Segments Equal to Zero/README_EN.md b/solution/1700-1799/1787.Make the XOR of All Segments Equal to Zero/README_EN.md index 7b937bd061b46..38dd8f633d43d 100644 --- a/solution/1700-1799/1787.Make the XOR of All Segments Equal to Zero/README_EN.md +++ b/solution/1700-1799/1787.Make the XOR of All Segments Equal to Zero/README_EN.md @@ -92,6 +92,8 @@ The time complexity is $O(2^{C}\times k + n)$. Where $n$ is the length of the ar +#### Python3 + ```python class Solution: def minChanges(self, nums: List[int], k: int) -> int: @@ -112,6 +114,8 @@ class Solution: return f[0] ``` +#### Java + ```java class Solution { public int minChanges(int[] nums, int k) { @@ -152,6 +156,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -180,6 +186,8 @@ public: }; ``` +#### Go + ```go func minChanges(nums []int, k int) int { n := 1 << 10 diff --git a/solution/1700-1799/1788.Maximize the Beauty of the Garden/README.md b/solution/1700-1799/1788.Maximize the Beauty of the Garden/README.md index 236ca7d3f2f7a..fbd00f36c537c 100644 --- a/solution/1700-1799/1788.Maximize the Beauty of the Garden/README.md +++ b/solution/1700-1799/1788.Maximize the Beauty of the Garden/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def maximumBeauty(self, flowers: List[int]) -> int: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumBeauty(int[] flowers) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func maximumBeauty(flowers []int) int { n := len(flowers) @@ -155,6 +163,8 @@ func maximumBeauty(flowers []int) int { } ``` +#### TypeScript + ```ts function maximumBeauty(flowers: number[]): number { const n = flowers.length; @@ -174,6 +184,8 @@ function maximumBeauty(flowers: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/1700-1799/1788.Maximize the Beauty of the Garden/README_EN.md b/solution/1700-1799/1788.Maximize the Beauty of the Garden/README_EN.md index f132a1b09852e..4c13c9e72aa71 100644 --- a/solution/1700-1799/1788.Maximize the Beauty of the Garden/README_EN.md +++ b/solution/1700-1799/1788.Maximize the Beauty of the Garden/README_EN.md @@ -100,6 +100,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def maximumBeauty(self, flowers: List[int]) -> int: @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumBeauty(int[] flowers) { @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func maximumBeauty(flowers []int) int { n := len(flowers) @@ -176,6 +184,8 @@ func maximumBeauty(flowers []int) int { } ``` +#### TypeScript + ```ts function maximumBeauty(flowers: number[]): number { const n = flowers.length; @@ -195,6 +205,8 @@ function maximumBeauty(flowers: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/1700-1799/1789.Primary Department for Each Employee/README.md b/solution/1700-1799/1789.Primary Department for Each Employee/README.md index 1098a9a19132a..a12f0dbf733ff 100644 --- a/solution/1700-1799/1789.Primary Department for Each Employee/README.md +++ b/solution/1700-1799/1789.Primary Department for Each Employee/README.md @@ -89,6 +89,8 @@ Employee table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT employee_id, department_id diff --git a/solution/1700-1799/1789.Primary Department for Each Employee/README_EN.md b/solution/1700-1799/1789.Primary Department for Each Employee/README_EN.md index 4875acc72728b..7afe2ef83aeae 100644 --- a/solution/1700-1799/1789.Primary Department for Each Employee/README_EN.md +++ b/solution/1700-1799/1789.Primary Department for Each Employee/README_EN.md @@ -87,6 +87,8 @@ We can first query all employees who already have a direct department, and then +#### MySQL + ```sql # Write your MySQL query statement below SELECT employee_id, department_id diff --git a/solution/1700-1799/1790.Check if One String Swap Can Make Strings Equal/README.md b/solution/1700-1799/1790.Check if One String Swap Can Make Strings Equal/README.md index d2e2e21ad6034..0777c74ff4795 100644 --- a/solution/1700-1799/1790.Check if One String Swap Can Make Strings Equal/README.md +++ b/solution/1700-1799/1790.Check if One String Swap Can Make Strings Equal/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def areAlmostEqual(self, s1: str, s2: str) -> bool: @@ -95,6 +97,8 @@ class Solution: return cnt != 1 ``` +#### Java + ```java class Solution { public boolean areAlmostEqual(String s1, String s2) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func areAlmostEqual(s1 string, s2 string) bool { cnt := 0 @@ -153,6 +161,8 @@ func areAlmostEqual(s1 string, s2 string) bool { } ``` +#### TypeScript + ```ts function areAlmostEqual(s1: string, s2: string): boolean { let c1, c2; @@ -172,6 +182,8 @@ function areAlmostEqual(s1: string, s2: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn are_almost_equal(s1: String, s2: String) -> bool { @@ -193,6 +205,8 @@ impl Solution { } ``` +#### C + ```c bool areAlmostEqual(char* s1, char* s2) { int n = strlen(s1); diff --git a/solution/1700-1799/1790.Check if One String Swap Can Make Strings Equal/README_EN.md b/solution/1700-1799/1790.Check if One String Swap Can Make Strings Equal/README_EN.md index 95602b5ff363b..d9c03b0f72e1d 100644 --- a/solution/1700-1799/1790.Check if One String Swap Can Make Strings Equal/README_EN.md +++ b/solution/1700-1799/1790.Check if One String Swap Can Make Strings Equal/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string. The space +#### Python3 + ```python class Solution: def areAlmostEqual(self, s1: str, s2: str) -> bool: @@ -90,6 +92,8 @@ class Solution: return cnt != 1 ``` +#### Java + ```java class Solution { public boolean areAlmostEqual(String s1, String s2) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func areAlmostEqual(s1 string, s2 string) bool { cnt := 0 @@ -148,6 +156,8 @@ func areAlmostEqual(s1 string, s2 string) bool { } ``` +#### TypeScript + ```ts function areAlmostEqual(s1: string, s2: string): boolean { let c1, c2; @@ -167,6 +177,8 @@ function areAlmostEqual(s1: string, s2: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn are_almost_equal(s1: String, s2: String) -> bool { @@ -188,6 +200,8 @@ impl Solution { } ``` +#### C + ```c bool areAlmostEqual(char* s1, char* s2) { int n = strlen(s1); diff --git a/solution/1700-1799/1791.Find Center of Star Graph/README.md b/solution/1700-1799/1791.Find Center of Star Graph/README.md index 9d97149b0093e..15bdd53ef8339 100644 --- a/solution/1700-1799/1791.Find Center of Star Graph/README.md +++ b/solution/1700-1799/1791.Find Center of Star Graph/README.md @@ -66,12 +66,16 @@ tags: +#### Python3 + ```python class Solution: def findCenter(self, edges: List[List[int]]) -> int: return edges[0][0] if edges[0][0] in edges[1] else edges[0][1] ``` +#### Java + ```java class Solution { public int findCenter(int[][] edges) { @@ -82,6 +86,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -93,6 +99,8 @@ public: }; ``` +#### Go + ```go func findCenter(edges [][]int) int { a, b := edges[0][0], edges[0][1] @@ -104,6 +112,8 @@ func findCenter(edges [][]int) int { } ``` +#### TypeScript + ```ts function findCenter(edges: number[][]): number { for (let num of edges[0]) { @@ -114,6 +124,8 @@ function findCenter(edges: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_center(edges: Vec>) -> i32 { @@ -125,6 +137,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} edges diff --git a/solution/1700-1799/1791.Find Center of Star Graph/README_EN.md b/solution/1700-1799/1791.Find Center of Star Graph/README_EN.md index 2a23ef2c0cc93..85aead1a806b5 100644 --- a/solution/1700-1799/1791.Find Center of Star Graph/README_EN.md +++ b/solution/1700-1799/1791.Find Center of Star Graph/README_EN.md @@ -64,12 +64,16 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def findCenter(self, edges: List[List[int]]) -> int: return edges[0][0] if edges[0][0] in edges[1] else edges[0][1] ``` +#### Java + ```java class Solution { public int findCenter(int[][] edges) { @@ -80,6 +84,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -91,6 +97,8 @@ public: }; ``` +#### Go + ```go func findCenter(edges [][]int) int { a, b := edges[0][0], edges[0][1] @@ -102,6 +110,8 @@ func findCenter(edges [][]int) int { } ``` +#### TypeScript + ```ts function findCenter(edges: number[][]): number { for (let num of edges[0]) { @@ -112,6 +122,8 @@ function findCenter(edges: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_center(edges: Vec>) -> i32 { @@ -123,6 +135,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} edges diff --git a/solution/1700-1799/1792.Maximum Average Pass Ratio/README.md b/solution/1700-1799/1792.Maximum Average Pass Ratio/README.md index 5903f542793ec..9b1e720162f5a 100644 --- a/solution/1700-1799/1792.Maximum Average Pass Ratio/README.md +++ b/solution/1700-1799/1792.Maximum Average Pass Ratio/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def maxAverageRatio(self, classes: List[List[int]], extraStudents: int) -> float: @@ -88,6 +90,8 @@ class Solution: return sum(v[1] / v[2] for v in h) / len(classes) ``` +#### Java + ```java class Solution { public double maxAverageRatio(int[][] classes, int extraStudents) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func maxAverageRatio(classes [][]int, extraStudents int) float64 { pq := hp{} diff --git a/solution/1700-1799/1792.Maximum Average Pass Ratio/README_EN.md b/solution/1700-1799/1792.Maximum Average Pass Ratio/README_EN.md index 5651c4c381b78..71d46b1c55e0c 100644 --- a/solution/1700-1799/1792.Maximum Average Pass Ratio/README_EN.md +++ b/solution/1700-1799/1792.Maximum Average Pass Ratio/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def maxAverageRatio(self, classes: List[List[int]], extraStudents: int) -> float: @@ -86,6 +88,8 @@ class Solution: return sum(v[1] / v[2] for v in h) / len(classes) ``` +#### Java + ```java class Solution { public double maxAverageRatio(int[][] classes, int extraStudents) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func maxAverageRatio(classes [][]int, extraStudents int) float64 { pq := hp{} diff --git a/solution/1700-1799/1793.Maximum Score of a Good Subarray/README.md b/solution/1700-1799/1793.Maximum Score of a Good Subarray/README.md index b8c3973d61984..d347c9a6a1b02 100644 --- a/solution/1700-1799/1793.Maximum Score of a Good Subarray/README.md +++ b/solution/1700-1799/1793.Maximum Score of a Good Subarray/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def maximumScore(self, nums: List[int], k: int) -> int: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumScore(int[] nums, int k) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -179,6 +185,8 @@ public: }; ``` +#### Go + ```go func maximumScore(nums []int, k int) (ans int) { n := len(nums) @@ -218,6 +226,8 @@ func maximumScore(nums []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function maximumScore(nums: number[], k: number): number { const n = nums.length; diff --git a/solution/1700-1799/1793.Maximum Score of a Good Subarray/README_EN.md b/solution/1700-1799/1793.Maximum Score of a Good Subarray/README_EN.md index 598908f2034a1..5423a12c0c5e1 100644 --- a/solution/1700-1799/1793.Maximum Score of a Good Subarray/README_EN.md +++ b/solution/1700-1799/1793.Maximum Score of a Good Subarray/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def maximumScore(self, nums: List[int], k: int) -> int: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumScore(int[] nums, int k) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -179,6 +185,8 @@ public: }; ``` +#### Go + ```go func maximumScore(nums []int, k int) (ans int) { n := len(nums) @@ -218,6 +226,8 @@ func maximumScore(nums []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function maximumScore(nums: number[], k: number): number { const n = nums.length; diff --git a/solution/1700-1799/1794.Count Pairs of Equal Substrings With Minimum Difference/README.md b/solution/1700-1799/1794.Count Pairs of Equal Substrings With Minimum Difference/README.md index 480a7ec46e4ef..ba8e2716294a5 100644 --- a/solution/1700-1799/1794.Count Pairs of Equal Substrings With Minimum Difference/README.md +++ b/solution/1700-1799/1794.Count Pairs of Equal Substrings With Minimum Difference/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def countQuadruples(self, firstString: str, secondString: str) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countQuadruples(String firstString, String secondString) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func countQuadruples(firstString string, secondString string) (ans int) { last := [26]int{} @@ -162,6 +170,8 @@ func countQuadruples(firstString string, secondString string) (ans int) { } ``` +#### TypeScript + ```ts function countQuadruples(firstString: string, secondString: string): number { const last: number[] = new Array(26).fill(0); diff --git a/solution/1700-1799/1794.Count Pairs of Equal Substrings With Minimum Difference/README_EN.md b/solution/1700-1799/1794.Count Pairs of Equal Substrings With Minimum Difference/README_EN.md index b402703a71180..3dc99ba672203 100644 --- a/solution/1700-1799/1794.Count Pairs of Equal Substrings With Minimum Difference/README_EN.md +++ b/solution/1700-1799/1794.Count Pairs of Equal Substrings With Minimum Difference/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(m + n)$, and the space complexity is $O(C)$. Here, $m$ +#### Python3 + ```python class Solution: def countQuadruples(self, firstString: str, secondString: str) -> int: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countQuadruples(String firstString, String secondString) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func countQuadruples(firstString string, secondString string) (ans int) { last := [26]int{} @@ -160,6 +168,8 @@ func countQuadruples(firstString string, secondString string) (ans int) { } ``` +#### TypeScript + ```ts function countQuadruples(firstString: string, secondString: string): number { const last: number[] = new Array(26).fill(0); diff --git a/solution/1700-1799/1795.Rearrange Products Table/README.md b/solution/1700-1799/1795.Rearrange Products Table/README.md index 4ef9ffd1833ac..ff3f955e3b402 100644 --- a/solution/1700-1799/1795.Rearrange Products Table/README.md +++ b/solution/1700-1799/1795.Rearrange Products Table/README.md @@ -79,6 +79,8 @@ Products table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT product_id, 'store1' AS store, store1 AS price FROM Products WHERE store1 IS NOT NULL diff --git a/solution/1700-1799/1795.Rearrange Products Table/README_EN.md b/solution/1700-1799/1795.Rearrange Products Table/README_EN.md index 0d1192fcf2a91..9afec43413fc1 100644 --- a/solution/1700-1799/1795.Rearrange Products Table/README_EN.md +++ b/solution/1700-1799/1795.Rearrange Products Table/README_EN.md @@ -79,6 +79,8 @@ We can select the products and prices for each store, and then use the `UNION` o +#### MySQL + ```sql # Write your MySQL query statement below SELECT product_id, 'store1' AS store, store1 AS price FROM Products WHERE store1 IS NOT NULL diff --git a/solution/1700-1799/1796.Second Largest Digit in a String/README.md b/solution/1700-1799/1796.Second Largest Digit in a String/README.md index 9263930fd8f94..5449166128575 100644 --- a/solution/1700-1799/1796.Second Largest Digit in a String/README.md +++ b/solution/1700-1799/1796.Second Largest Digit in a String/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def secondHighest(self, s: str) -> int: @@ -82,6 +84,8 @@ class Solution: return b ``` +#### Java + ```java class Solution { public int secondHighest(String s) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func secondHighest(s string) int { a, b := -1, -1 @@ -140,6 +148,8 @@ func secondHighest(s string) int { } ``` +#### TypeScript + ```ts function secondHighest(s: string): number { let first = -1; @@ -158,6 +168,8 @@ function secondHighest(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn second_highest(s: String) -> i32 { @@ -179,6 +191,8 @@ impl Solution { } ``` +#### C + ```c int secondHighest(char* s) { int first = -1; @@ -216,6 +230,8 @@ int secondHighest(char* s) { +#### Python3 + ```python class Solution: def secondHighest(self, s: str) -> int: @@ -229,6 +245,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int secondHighest(String s) { @@ -249,6 +267,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -263,6 +283,8 @@ public: }; ``` +#### Go + ```go func secondHighest(s string) int { mask := 0 diff --git a/solution/1700-1799/1796.Second Largest Digit in a String/README_EN.md b/solution/1700-1799/1796.Second Largest Digit in a String/README_EN.md index 960261e8d3e96..67ff0b8189661 100644 --- a/solution/1700-1799/1796.Second Largest Digit in a String/README_EN.md +++ b/solution/1700-1799/1796.Second Largest Digit in a String/README_EN.md @@ -66,6 +66,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string $s$. The sp +#### Python3 + ```python class Solution: def secondHighest(self, s: str) -> int: @@ -80,6 +82,8 @@ class Solution: return b ``` +#### Java + ```java class Solution { public int secondHighest(String s) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func secondHighest(s string) int { a, b := -1, -1 @@ -138,6 +146,8 @@ func secondHighest(s string) int { } ``` +#### TypeScript + ```ts function secondHighest(s: string): number { let first = -1; @@ -156,6 +166,8 @@ function secondHighest(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn second_highest(s: String) -> i32 { @@ -177,6 +189,8 @@ impl Solution { } ``` +#### C + ```c int secondHighest(char* s) { int first = -1; @@ -214,6 +228,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string $s$. The sp +#### Python3 + ```python class Solution: def secondHighest(self, s: str) -> int: @@ -227,6 +243,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int secondHighest(String s) { @@ -247,6 +265,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -261,6 +281,8 @@ public: }; ``` +#### Go + ```go func secondHighest(s string) int { mask := 0 diff --git a/solution/1700-1799/1797.Design Authentication Manager/README.md b/solution/1700-1799/1797.Design Authentication Manager/README.md index f958ac3384cc9..f85159f9fa63a 100644 --- a/solution/1700-1799/1797.Design Authentication Manager/README.md +++ b/solution/1700-1799/1797.Design Authentication Manager/README.md @@ -89,6 +89,8 @@ authenticationManager.countUnexpiredTokens(15); // tokenId 为 "bbb +#### Python3 + ```python class AuthenticationManager: def __init__(self, timeToLive: int): @@ -114,6 +116,8 @@ class AuthenticationManager: # param_3 = obj.countUnexpiredTokens(currentTime) ``` +#### Java + ```java class AuthenticationManager { private int t; @@ -154,6 +158,8 @@ class AuthenticationManager { */ ``` +#### C++ + ```cpp class AuthenticationManager { public: @@ -190,6 +196,8 @@ private: */ ``` +#### Go + ```go type AuthenticationManager struct { t int @@ -230,6 +238,8 @@ func (this *AuthenticationManager) CountUnexpiredTokens(currentTime int) int { */ ``` +#### TypeScript + ```ts class AuthenticationManager { private timeToLive: number; @@ -271,6 +281,8 @@ class AuthenticationManager { */ ``` +#### Rust + ```rust use std::collections::HashMap; struct AuthenticationManager { diff --git a/solution/1700-1799/1797.Design Authentication Manager/README_EN.md b/solution/1700-1799/1797.Design Authentication Manager/README_EN.md index 062d0f4482b0b..1880a71ded482 100644 --- a/solution/1700-1799/1797.Design Authentication Manager/README_EN.md +++ b/solution/1700-1799/1797.Design Authentication Manager/README_EN.md @@ -87,6 +87,8 @@ The space complexity is $O(n)$, where $n$ is the number of key-value pairs in th +#### Python3 + ```python class AuthenticationManager: def __init__(self, timeToLive: int): @@ -112,6 +114,8 @@ class AuthenticationManager: # param_3 = obj.countUnexpiredTokens(currentTime) ``` +#### Java + ```java class AuthenticationManager { private int t; @@ -152,6 +156,8 @@ class AuthenticationManager { */ ``` +#### C++ + ```cpp class AuthenticationManager { public: @@ -188,6 +194,8 @@ private: */ ``` +#### Go + ```go type AuthenticationManager struct { t int @@ -228,6 +236,8 @@ func (this *AuthenticationManager) CountUnexpiredTokens(currentTime int) int { */ ``` +#### TypeScript + ```ts class AuthenticationManager { private timeToLive: number; @@ -269,6 +279,8 @@ class AuthenticationManager { */ ``` +#### Rust + ```rust use std::collections::HashMap; struct AuthenticationManager { diff --git a/solution/1700-1799/1798.Maximum Number of Consecutive Values You Can Make/README.md b/solution/1700-1799/1798.Maximum Number of Consecutive Values You Can Make/README.md index ec054c6672d02..c5657c523f868 100644 --- a/solution/1700-1799/1798.Maximum Number of Consecutive Values You Can Make/README.md +++ b/solution/1700-1799/1798.Maximum Number of Consecutive Values You Can Make/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def getMaximumConsecutive(self, coins: List[int]) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int getMaximumConsecutive(int[] coins) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func getMaximumConsecutive(coins []int) int { sort.Ints(coins) @@ -144,6 +152,8 @@ func getMaximumConsecutive(coins []int) int { } ``` +#### TypeScript + ```ts function getMaximumConsecutive(coins: number[]): number { coins.sort((a, b) => a - b); diff --git a/solution/1700-1799/1798.Maximum Number of Consecutive Values You Can Make/README_EN.md b/solution/1700-1799/1798.Maximum Number of Consecutive Values You Can Make/README_EN.md index 19e624306c9a8..8ab9fa03ea0b7 100644 --- a/solution/1700-1799/1798.Maximum Number of Consecutive Values You Can Make/README_EN.md +++ b/solution/1700-1799/1798.Maximum Number of Consecutive Values You Can Make/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def getMaximumConsecutive(self, coins: List[int]) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int getMaximumConsecutive(int[] coins) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func getMaximumConsecutive(coins []int) int { sort.Ints(coins) @@ -142,6 +150,8 @@ func getMaximumConsecutive(coins []int) int { } ``` +#### TypeScript + ```ts function getMaximumConsecutive(coins: number[]): number { coins.sort((a, b) => a - b); diff --git a/solution/1700-1799/1799.Maximize Score After N Operations/README.md b/solution/1700-1799/1799.Maximize Score After N Operations/README.md index 8df78d38a2f14..33454bdd534ba 100644 --- a/solution/1700-1799/1799.Maximize Score After N Operations/README.md +++ b/solution/1700-1799/1799.Maximize Score After N Operations/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class Solution: def maxScore(self, nums: List[int]) -> int: @@ -118,6 +120,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int maxScore(int[] nums) { @@ -153,6 +157,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -185,6 +191,8 @@ public: }; ``` +#### Go + ```go func maxScore(nums []int) int { m := len(nums) @@ -220,6 +228,8 @@ func gcd(a, b int) int { } ``` +#### TypeScript + ```ts function maxScore(nums: number[]): number { const m = nums.length; diff --git a/solution/1700-1799/1799.Maximize Score After N Operations/README_EN.md b/solution/1700-1799/1799.Maximize Score After N Operations/README_EN.md index af5dcf8d58b50..9f0f0fc33cce4 100644 --- a/solution/1700-1799/1799.Maximize Score After N Operations/README_EN.md +++ b/solution/1700-1799/1799.Maximize Score After N Operations/README_EN.md @@ -97,6 +97,8 @@ The time complexity is $O(2^m \times m^2)$, and the space complexity is $O(2^m)$ +#### Python3 + ```python class Solution: def maxScore(self, nums: List[int]) -> int: @@ -119,6 +121,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int maxScore(int[] nums) { @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go func maxScore(nums []int) int { m := len(nums) @@ -221,6 +229,8 @@ func gcd(a, b int) int { } ``` +#### TypeScript + ```ts function maxScore(nums: number[]): number { const m = nums.length; diff --git a/solution/1800-1899/1800.Maximum Ascending Subarray Sum/README.md b/solution/1800-1899/1800.Maximum Ascending Subarray Sum/README.md index 85d9f70b62574..ac8eda0612e31 100644 --- a/solution/1800-1899/1800.Maximum Ascending Subarray Sum/README.md +++ b/solution/1800-1899/1800.Maximum Ascending Subarray Sum/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def maxAscendingSum(self, nums: List[int]) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxAscendingSum(int[] nums) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func maxAscendingSum(nums []int) int { ans, t := 0, 0 @@ -151,6 +159,8 @@ func maxAscendingSum(nums []int) int { } ``` +#### TypeScript + ```ts function maxAscendingSum(nums: number[]): number { const n = nums.length; @@ -167,6 +177,8 @@ function maxAscendingSum(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_ascending_sum(nums: Vec) -> i32 { @@ -185,6 +197,8 @@ impl Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) diff --git a/solution/1800-1899/1800.Maximum Ascending Subarray Sum/README_EN.md b/solution/1800-1899/1800.Maximum Ascending Subarray Sum/README_EN.md index b4766ffbbbc4b..cb64f4e45b91a 100644 --- a/solution/1800-1899/1800.Maximum Ascending Subarray Sum/README_EN.md +++ b/solution/1800-1899/1800.Maximum Ascending Subarray Sum/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def maxAscendingSum(self, nums: List[int]) -> int: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxAscendingSum(int[] nums) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func maxAscendingSum(nums []int) int { ans, t := 0, 0 @@ -142,6 +150,8 @@ func maxAscendingSum(nums []int) int { } ``` +#### TypeScript + ```ts function maxAscendingSum(nums: number[]): number { const n = nums.length; @@ -158,6 +168,8 @@ function maxAscendingSum(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_ascending_sum(nums: Vec) -> i32 { @@ -176,6 +188,8 @@ impl Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) diff --git a/solution/1800-1899/1801.Number of Orders in the Backlog/README.md b/solution/1800-1899/1801.Number of Orders in the Backlog/README.md index f443b77d0f8d4..3982246d28a8e 100644 --- a/solution/1800-1899/1801.Number of Orders in the Backlog/README.md +++ b/solution/1800-1899/1801.Number of Orders in the Backlog/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class Solution: def getNumberOfBacklogOrders(self, orders: List[List[int]]) -> int: @@ -125,6 +127,8 @@ class Solution: return sum(v[1] for v in buy + sell) % mod ``` +#### Java + ```java class Solution { public int getNumberOfBacklogOrders(int[][] orders) { @@ -175,6 +179,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -229,6 +235,8 @@ public: }; ``` +#### Go + ```go func getNumberOfBacklogOrders(orders [][]int) (ans int) { sell := hp{} diff --git a/solution/1800-1899/1801.Number of Orders in the Backlog/README_EN.md b/solution/1800-1899/1801.Number of Orders in the Backlog/README_EN.md index 5c5e7cd5b9f7c..fb8b1f0df8967 100644 --- a/solution/1800-1899/1801.Number of Orders in the Backlog/README_EN.md +++ b/solution/1800-1899/1801.Number of Orders in the Backlog/README_EN.md @@ -128,6 +128,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def getNumberOfBacklogOrders(self, orders: List[List[int]]) -> int: @@ -157,6 +159,8 @@ class Solution: return sum(v[1] for v in buy + sell) % mod ``` +#### Java + ```java class Solution { public int getNumberOfBacklogOrders(int[][] orders) { @@ -207,6 +211,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -261,6 +267,8 @@ public: }; ``` +#### Go + ```go func getNumberOfBacklogOrders(orders [][]int) (ans int) { sell := hp{} diff --git a/solution/1800-1899/1802.Maximum Value at a Given Index in a Bounded Array/README.md b/solution/1800-1899/1802.Maximum Value at a Given Index in a Bounded Array/README.md index b5e0648d9d116..3902264817560 100644 --- a/solution/1800-1899/1802.Maximum Value at a Given Index in a Bounded Array/README.md +++ b/solution/1800-1899/1802.Maximum Value at a Given Index in a Bounded Array/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def maxValue(self, n: int, index: int, maxSum: int) -> int: @@ -100,6 +102,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int maxValue(int n, int index, int maxSum) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func maxValue(n int, index int, maxSum int) int { sum := func(x, cnt int) int { diff --git a/solution/1800-1899/1802.Maximum Value at a Given Index in a Bounded Array/README_EN.md b/solution/1800-1899/1802.Maximum Value at a Given Index in a Bounded Array/README_EN.md index faf98dceff822..4370d39827873 100644 --- a/solution/1800-1899/1802.Maximum Value at a Given Index in a Bounded Array/README_EN.md +++ b/solution/1800-1899/1802.Maximum Value at a Given Index in a Bounded Array/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(\log M)$, where $M=maxSum$. The space complexity is $O +#### Python3 + ```python class Solution: def maxValue(self, n: int, index: int, maxSum: int) -> int: @@ -101,6 +103,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int maxValue(int n, int index, int maxSum) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func maxValue(n int, index int, maxSum int) int { sum := func(x, cnt int) int { diff --git a/solution/1800-1899/1803.Count Pairs With XOR in a Range/README.md b/solution/1800-1899/1803.Count Pairs With XOR in a Range/README.md index cd4d0d73dce9b..a60f37d191234 100644 --- a/solution/1800-1899/1803.Count Pairs With XOR in a Range/README.md +++ b/solution/1800-1899/1803.Count Pairs With XOR in a Range/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class Trie: def __init__(self): @@ -137,6 +139,8 @@ class Solution: return ans ``` +#### Java + ```java class Trie { private Trie[] children = new Trie[2]; @@ -185,6 +189,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -240,6 +246,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [2]*Trie diff --git a/solution/1800-1899/1803.Count Pairs With XOR in a Range/README_EN.md b/solution/1800-1899/1803.Count Pairs With XOR in a Range/README_EN.md index f4faffd995bb9..b2f0cba2a3268 100644 --- a/solution/1800-1899/1803.Count Pairs With XOR in a Range/README_EN.md +++ b/solution/1800-1899/1803.Count Pairs With XOR in a Range/README_EN.md @@ -123,6 +123,8 @@ The time complexity is $O(n \times \log M)$, and the space complexity is $O(n \t +#### Python3 + ```python class Trie: def __init__(self): @@ -164,6 +166,8 @@ class Solution: return ans ``` +#### Java + ```java class Trie { private Trie[] children = new Trie[2]; @@ -212,6 +216,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -267,6 +273,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [2]*Trie diff --git a/solution/1800-1899/1804.Implement Trie II (Prefix Tree)/README.md b/solution/1800-1899/1804.Implement Trie II (Prefix Tree)/README.md index 6ee47e37450fe..c42c66bba15de 100644 --- a/solution/1800-1899/1804.Implement Trie II (Prefix Tree)/README.md +++ b/solution/1800-1899/1804.Implement Trie II (Prefix Tree)/README.md @@ -109,6 +109,8 @@ trie.countWordsStartingWith("app"); // 返回 0 +#### Python3 + ```python class Trie: def __init__(self): @@ -159,6 +161,8 @@ class Trie: # obj.erase(word) ``` +#### Java + ```java class Trie { private Trie[] children = new Trie[26]; @@ -224,6 +228,8 @@ class Trie { */ ``` +#### C++ + ```cpp class Trie { public: @@ -293,6 +299,8 @@ private: */ ``` +#### Go + ```go type Trie struct { children [26]*Trie diff --git a/solution/1800-1899/1804.Implement Trie II (Prefix Tree)/README_EN.md b/solution/1800-1899/1804.Implement Trie II (Prefix Tree)/README_EN.md index e7a76b2213648..7c518ac366ba1 100644 --- a/solution/1800-1899/1804.Implement Trie II (Prefix Tree)/README_EN.md +++ b/solution/1800-1899/1804.Implement Trie II (Prefix Tree)/README_EN.md @@ -108,6 +108,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string. +#### Python3 + ```python class Trie: def __init__(self): @@ -158,6 +160,8 @@ class Trie: # obj.erase(word) ``` +#### Java + ```java class Trie { private Trie[] children = new Trie[26]; @@ -223,6 +227,8 @@ class Trie { */ ``` +#### C++ + ```cpp class Trie { public: @@ -292,6 +298,8 @@ private: */ ``` +#### Go + ```go type Trie struct { children [26]*Trie diff --git a/solution/1800-1899/1805.Number of Different Integers in a String/README.md b/solution/1800-1899/1805.Number of Different Integers in a String/README.md index 71552c276b38d..9707a5e78e01e 100644 --- a/solution/1800-1899/1805.Number of Different Integers in a String/README.md +++ b/solution/1800-1899/1805.Number of Different Integers in a String/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def numDifferentIntegers(self, word: str) -> int: @@ -97,6 +99,8 @@ class Solution: return len(s) ``` +#### Java + ```java class Solution { public int numDifferentIntegers(String word) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func numDifferentIntegers(word string) int { s := map[string]struct{}{} @@ -161,6 +169,8 @@ func numDifferentIntegers(word string) int { } ``` +#### TypeScript + ```ts function numDifferentIntegers(word: string): number { return new Set( @@ -174,6 +184,8 @@ function numDifferentIntegers(word: string): number { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { diff --git a/solution/1800-1899/1805.Number of Different Integers in a String/README_EN.md b/solution/1800-1899/1805.Number of Different Integers in a String/README_EN.md index e66e13e0dc93c..a8ef3018f48db 100644 --- a/solution/1800-1899/1805.Number of Different Integers in a String/README_EN.md +++ b/solution/1800-1899/1805.Number of Different Integers in a String/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def numDifferentIntegers(self, word: str) -> int: @@ -96,6 +98,8 @@ class Solution: return len(s) ``` +#### Java + ```java class Solution { public int numDifferentIntegers(String word) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func numDifferentIntegers(word string) int { s := map[string]struct{}{} @@ -160,6 +168,8 @@ func numDifferentIntegers(word string) int { } ``` +#### TypeScript + ```ts function numDifferentIntegers(word: string): number { return new Set( @@ -173,6 +183,8 @@ function numDifferentIntegers(word: string): number { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { diff --git a/solution/1800-1899/1806.Minimum Number of Operations to Reinitialize a Permutation/README.md b/solution/1800-1899/1806.Minimum Number of Operations to Reinitialize a Permutation/README.md index c7f02949416f6..20ac2e82d5d3b 100644 --- a/solution/1800-1899/1806.Minimum Number of Operations to Reinitialize a Permutation/README.md +++ b/solution/1800-1899/1806.Minimum Number of Operations to Reinitialize a Permutation/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def reinitializePermutation(self, n: int) -> int: @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int reinitializePermutation(int n) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func reinitializePermutation(n int) (ans int) { for i := 1; ; { diff --git a/solution/1800-1899/1806.Minimum Number of Operations to Reinitialize a Permutation/README_EN.md b/solution/1800-1899/1806.Minimum Number of Operations to Reinitialize a Permutation/README_EN.md index e0c1ec15c0ed3..6f956c5fdd1f8 100644 --- a/solution/1800-1899/1806.Minimum Number of Operations to Reinitialize a Permutation/README_EN.md +++ b/solution/1800-1899/1806.Minimum Number of Operations to Reinitialize a Permutation/README_EN.md @@ -93,6 +93,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def reinitializePermutation(self, n: int) -> int: @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int reinitializePermutation(int n) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func reinitializePermutation(n int) (ans int) { for i := 1; ; { diff --git a/solution/1800-1899/1807.Evaluate the Bracket Pairs of a String/README.md b/solution/1800-1899/1807.Evaluate the Bracket Pairs of a String/README.md index 2daf67e699716..21729dc892609 100644 --- a/solution/1800-1899/1807.Evaluate the Bracket Pairs of a String/README.md +++ b/solution/1800-1899/1807.Evaluate the Bracket Pairs of a String/README.md @@ -102,6 +102,8 @@ tags: +#### Python3 + ```python class Solution: def evaluate(self, s: str, knowledge: List[List[str]]) -> str: @@ -119,6 +121,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String evaluate(String s, List> knowledge) { @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func evaluate(s string, knowledge [][]string) string { d := map[string]string{} @@ -192,6 +200,8 @@ func evaluate(s string, knowledge [][]string) string { } ``` +#### TypeScript + ```ts function evaluate(s: string, knowledge: string[][]): string { const n = s.length; @@ -215,6 +225,8 @@ function evaluate(s: string, knowledge: string[][]): string { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { diff --git a/solution/1800-1899/1807.Evaluate the Bracket Pairs of a String/README_EN.md b/solution/1800-1899/1807.Evaluate the Bracket Pairs of a String/README_EN.md index e97eea73a8d96..dd55c6e658da0 100644 --- a/solution/1800-1899/1807.Evaluate the Bracket Pairs of a String/README_EN.md +++ b/solution/1800-1899/1807.Evaluate the Bracket Pairs of a String/README_EN.md @@ -100,6 +100,8 @@ The time complexity is $O(n + m)$, and the space complexity is $O(L)$. Here, $n$ +#### Python3 + ```python class Solution: def evaluate(self, s: str, knowledge: List[List[str]]) -> str: @@ -117,6 +119,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String evaluate(String s, List> knowledge) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func evaluate(s string, knowledge [][]string) string { d := map[string]string{} @@ -190,6 +198,8 @@ func evaluate(s string, knowledge [][]string) string { } ``` +#### TypeScript + ```ts function evaluate(s: string, knowledge: string[][]): string { const n = s.length; @@ -213,6 +223,8 @@ function evaluate(s: string, knowledge: string[][]): string { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { diff --git a/solution/1800-1899/1808.Maximize Number of Nice Divisors/README.md b/solution/1800-1899/1808.Maximize Number of Nice Divisors/README.md index 02bf42cc41ce4..19c41e9e73ca1 100644 --- a/solution/1800-1899/1808.Maximize Number of Nice Divisors/README.md +++ b/solution/1800-1899/1808.Maximize Number of Nice Divisors/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def maxNiceDivisors(self, primeFactors: int) -> int: @@ -95,6 +97,8 @@ class Solution: return 2 * pow(3, primeFactors // 3, mod) % mod ``` +#### Java + ```java class Solution { private final int mod = (int) 1e9 + 7; @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func maxNiceDivisors(primeFactors int) int { if primeFactors < 4 { @@ -180,6 +188,8 @@ func maxNiceDivisors(primeFactors int) int { } ``` +#### JavaScript + ```js /** * @param {number} primeFactors diff --git a/solution/1800-1899/1808.Maximize Number of Nice Divisors/README_EN.md b/solution/1800-1899/1808.Maximize Number of Nice Divisors/README_EN.md index 31bba12fe3e42..f7330d2e00fab 100644 --- a/solution/1800-1899/1808.Maximize Number of Nice Divisors/README_EN.md +++ b/solution/1800-1899/1808.Maximize Number of Nice Divisors/README_EN.md @@ -96,6 +96,8 @@ The time complexity is $O(\log n)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def maxNiceDivisors(self, primeFactors: int) -> int: @@ -109,6 +111,8 @@ class Solution: return 2 * pow(3, primeFactors // 3, mod) % mod ``` +#### Java + ```java class Solution { private final int mod = (int) 1e9 + 7; @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func maxNiceDivisors(primeFactors int) int { if primeFactors < 4 { @@ -194,6 +202,8 @@ func maxNiceDivisors(primeFactors int) int { } ``` +#### JavaScript + ```js /** * @param {number} primeFactors diff --git a/solution/1800-1899/1809.Ad-Free Sessions/README.md b/solution/1800-1899/1809.Ad-Free Sessions/README.md index 6a01001273b59..51ee41d0fef04 100644 --- a/solution/1800-1899/1809.Ad-Free Sessions/README.md +++ b/solution/1800-1899/1809.Ad-Free Sessions/README.md @@ -105,6 +105,8 @@ Ads table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT session_id diff --git a/solution/1800-1899/1809.Ad-Free Sessions/README_EN.md b/solution/1800-1899/1809.Ad-Free Sessions/README_EN.md index 9af3a8d146e7d..87ef5fa18a76c 100644 --- a/solution/1800-1899/1809.Ad-Free Sessions/README_EN.md +++ b/solution/1800-1899/1809.Ad-Free Sessions/README_EN.md @@ -105,6 +105,8 @@ We can see that sessions 1 and 4 had at least one ad. Sessions 2, 3, and 5 did n +#### MySQL + ```sql # Write your MySQL query statement below SELECT session_id diff --git a/solution/1800-1899/1810.Minimum Path Cost in a Hidden Grid/README.md b/solution/1800-1899/1810.Minimum Path Cost in a Hidden Grid/README.md index e2b32cd344ac2..9e5976bfed137 100644 --- a/solution/1800-1899/1810.Minimum Path Cost in a Hidden Grid/README.md +++ b/solution/1800-1899/1810.Minimum Path Cost in a Hidden Grid/README.md @@ -115,6 +115,8 @@ tags: +#### Python3 + ```python # """ # This is GridMaster's API interface. @@ -178,6 +180,8 @@ class Solution(object): return 0 ``` +#### Java + ```java /** * // This is the GridMaster's API interface. diff --git a/solution/1800-1899/1810.Minimum Path Cost in a Hidden Grid/README_EN.md b/solution/1800-1899/1810.Minimum Path Cost in a Hidden Grid/README_EN.md index 6205e3815243c..61b3da16627c3 100644 --- a/solution/1800-1899/1810.Minimum Path Cost in a Hidden Grid/README_EN.md +++ b/solution/1800-1899/1810.Minimum Path Cost in a Hidden Grid/README_EN.md @@ -113,6 +113,8 @@ We now know that the target is the cell (1, 0), and the minimum total cost to re +#### Python3 + ```python # """ # This is GridMaster's API interface. @@ -176,6 +178,8 @@ class Solution(object): return 0 ``` +#### Java + ```java /** * // This is the GridMaster's API interface. diff --git a/solution/1800-1899/1811.Find Interview Candidates/README.md b/solution/1800-1899/1811.Find Interview Candidates/README.md index c1b6a5cb8fdc0..7506966915665 100644 --- a/solution/1800-1899/1811.Find Interview Candidates/README.md +++ b/solution/1800-1899/1811.Find Interview Candidates/README.md @@ -123,6 +123,8 @@ Quarz在连续5场竞赛中赢得了奖牌(190, 191, 192, 193, and 194), 所以 +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1800-1899/1811.Find Interview Candidates/README_EN.md b/solution/1800-1899/1811.Find Interview Candidates/README_EN.md index 9661fd551ca7c..eb089595174cc 100644 --- a/solution/1800-1899/1811.Find Interview Candidates/README_EN.md +++ b/solution/1800-1899/1811.Find Interview Candidates/README_EN.md @@ -122,6 +122,8 @@ Quarz won a medal in 5 consecutive contests (190, 191, 192, 193, and 194), so we +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1800-1899/1812.Determine Color of a Chessboard Square/README.md b/solution/1800-1899/1812.Determine Color of a Chessboard Square/README.md index d0f64e8a07bd4..f4e25ae180c56 100644 --- a/solution/1800-1899/1812.Determine Color of a Chessboard Square/README.md +++ b/solution/1800-1899/1812.Determine Color of a Chessboard Square/README.md @@ -78,12 +78,16 @@ tags: +#### Python3 + ```python class Solution: def squareIsWhite(self, coordinates: str) -> bool: return (ord(coordinates[0]) + ord(coordinates[1])) % 2 == 1 ``` +#### Java + ```java class Solution { public boolean squareIsWhite(String coordinates) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,18 +107,24 @@ public: }; ``` +#### Go + ```go func squareIsWhite(coordinates string) bool { return (coordinates[0]+coordinates[1])%2 == 1 } ``` +#### TypeScript + ```ts function squareIsWhite(coordinates: string): boolean { return ((coordinates.charCodeAt(0) + coordinates.charCodeAt(1)) & 1) === 1; } ``` +#### Rust + ```rust impl Solution { pub fn square_is_white(coordinates: String) -> bool { @@ -122,6 +134,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} coordinates @@ -134,6 +148,8 @@ var squareIsWhite = function (coordinates) { }; ``` +#### C + ```c bool squareIsWhite(char* coordinates) { return (coordinates[0] + coordinates[1]) & 1; diff --git a/solution/1800-1899/1812.Determine Color of a Chessboard Square/README_EN.md b/solution/1800-1899/1812.Determine Color of a Chessboard Square/README_EN.md index 227a321b066f6..9a8e137964c34 100644 --- a/solution/1800-1899/1812.Determine Color of a Chessboard Square/README_EN.md +++ b/solution/1800-1899/1812.Determine Color of a Chessboard Square/README_EN.md @@ -76,12 +76,16 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def squareIsWhite(self, coordinates: str) -> bool: return (ord(coordinates[0]) + ord(coordinates[1])) % 2 == 1 ``` +#### Java + ```java class Solution { public boolean squareIsWhite(String coordinates) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -99,18 +105,24 @@ public: }; ``` +#### Go + ```go func squareIsWhite(coordinates string) bool { return (coordinates[0]+coordinates[1])%2 == 1 } ``` +#### TypeScript + ```ts function squareIsWhite(coordinates: string): boolean { return ((coordinates.charCodeAt(0) + coordinates.charCodeAt(1)) & 1) === 1; } ``` +#### Rust + ```rust impl Solution { pub fn square_is_white(coordinates: String) -> bool { @@ -120,6 +132,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} coordinates @@ -132,6 +146,8 @@ var squareIsWhite = function (coordinates) { }; ``` +#### C + ```c bool squareIsWhite(char* coordinates) { return (coordinates[0] + coordinates[1]) & 1; diff --git a/solution/1800-1899/1813.Sentence Similarity III/README.md b/solution/1800-1899/1813.Sentence Similarity III/README.md index e8e2661a6a6ea..afbe56ecb5123 100644 --- a/solution/1800-1899/1813.Sentence Similarity III/README.md +++ b/solution/1800-1899/1813.Sentence Similarity III/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def areSentencesSimilar(self, sentence1: str, sentence2: str) -> bool: @@ -99,6 +101,8 @@ class Solution: return i + j >= n ``` +#### Java + ```java class Solution { public boolean areSentencesSimilar(String sentence1, String sentence2) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func areSentencesSimilar(sentence1 string, sentence2 string) bool { words1, words2 := strings.Fields(sentence1), strings.Fields(sentence2) @@ -172,6 +180,8 @@ func areSentencesSimilar(sentence1 string, sentence2 string) bool { } ``` +#### TypeScript + ```ts function areSentencesSimilar(sentence1: string, sentence2: string): boolean { const words1 = sentence1.split(' '); diff --git a/solution/1800-1899/1813.Sentence Similarity III/README_EN.md b/solution/1800-1899/1813.Sentence Similarity III/README_EN.md index c9b8cd9c692a6..b586818efcdd2 100644 --- a/solution/1800-1899/1813.Sentence Similarity III/README_EN.md +++ b/solution/1800-1899/1813.Sentence Similarity III/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(L)$, and the space complexity is $O(L)$, where $L$ is +#### Python3 + ```python class Solution: def areSentencesSimilar(self, sentence1: str, sentence2: str) -> bool: @@ -94,6 +96,8 @@ class Solution: return i + j >= n ``` +#### Java + ```java class Solution { public boolean areSentencesSimilar(String sentence1, String sentence2) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func areSentencesSimilar(sentence1 string, sentence2 string) bool { words1, words2 := strings.Fields(sentence1), strings.Fields(sentence2) @@ -167,6 +175,8 @@ func areSentencesSimilar(sentence1 string, sentence2 string) bool { } ``` +#### TypeScript + ```ts function areSentencesSimilar(sentence1: string, sentence2: string): boolean { const words1 = sentence1.split(' '); diff --git a/solution/1800-1899/1814.Count Nice Pairs in an Array/README.md b/solution/1800-1899/1814.Count Nice Pairs in an Array/README.md index 4dd988c6ef599..da3b8db6aee29 100644 --- a/solution/1800-1899/1814.Count Nice Pairs in an Array/README.md +++ b/solution/1800-1899/1814.Count Nice Pairs in an Array/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def countNicePairs(self, nums: List[int]) -> int: @@ -89,6 +91,8 @@ class Solution: return sum(v * (v - 1) // 2 for v in cnt.values()) % mod ``` +#### Java + ```java class Solution { public int countNicePairs(int[] nums) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func countNicePairs(nums []int) (ans int) { rev := func(x int) (y int) { @@ -162,6 +170,8 @@ func countNicePairs(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function countNicePairs(nums: number[]): number { const rev = (x: number): number => { @@ -184,6 +194,8 @@ function countNicePairs(nums: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -211,6 +223,8 @@ var countNicePairs = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int CountNicePairs(int[] nums) { @@ -248,6 +262,8 @@ public class Solution { +#### Python3 + ```python class Solution: def countNicePairs(self, nums: List[int]) -> int: @@ -268,6 +284,8 @@ class Solution: return ans % mod ``` +#### Java + ```java class Solution { public int countNicePairs(int[] nums) { @@ -292,6 +310,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -315,6 +335,8 @@ public: }; ``` +#### Go + ```go func countNicePairs(nums []int) (ans int) { rev := func(x int) (y int) { @@ -334,6 +356,8 @@ func countNicePairs(nums []int) (ans int) { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/1800-1899/1814.Count Nice Pairs in an Array/README_EN.md b/solution/1800-1899/1814.Count Nice Pairs in an Array/README_EN.md index a4863d3121983..1fb37be88c75c 100644 --- a/solution/1800-1899/1814.Count Nice Pairs in an Array/README_EN.md +++ b/solution/1800-1899/1814.Count Nice Pairs in an Array/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(n \times \log M)$, where $n$ and $M$ are the length of +#### Python3 + ```python class Solution: def countNicePairs(self, nums: List[int]) -> int: @@ -89,6 +91,8 @@ class Solution: return sum(v * (v - 1) // 2 for v in cnt.values()) % mod ``` +#### Java + ```java class Solution { public int countNicePairs(int[] nums) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func countNicePairs(nums []int) (ans int) { rev := func(x int) (y int) { @@ -162,6 +170,8 @@ func countNicePairs(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function countNicePairs(nums: number[]): number { const rev = (x: number): number => { @@ -184,6 +194,8 @@ function countNicePairs(nums: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -211,6 +223,8 @@ var countNicePairs = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int CountNicePairs(int[] nums) { @@ -248,6 +262,8 @@ public class Solution { +#### Python3 + ```python class Solution: def countNicePairs(self, nums: List[int]) -> int: @@ -268,6 +284,8 @@ class Solution: return ans % mod ``` +#### Java + ```java class Solution { public int countNicePairs(int[] nums) { @@ -292,6 +310,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -315,6 +335,8 @@ public: }; ``` +#### Go + ```go func countNicePairs(nums []int) (ans int) { rev := func(x int) (y int) { @@ -334,6 +356,8 @@ func countNicePairs(nums []int) (ans int) { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/1800-1899/1815.Maximum Number of Groups Getting Fresh Donuts/README.md b/solution/1800-1899/1815.Maximum Number of Groups Getting Fresh Donuts/README.md index 5d69859aa95d3..3b5868b04daeb 100644 --- a/solution/1800-1899/1815.Maximum Number of Groups Getting Fresh Donuts/README.md +++ b/solution/1800-1899/1815.Maximum Number of Groups Getting Fresh Donuts/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def maxHappyGroups(self, batchSize: int, groups: List[int]) -> int: @@ -103,6 +105,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private Map f = new HashMap<>(); @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go func maxHappyGroups(batchSize int, groups []int) (ans int) { state := 0 @@ -222,6 +230,8 @@ func maxHappyGroups(batchSize int, groups []int) (ans int) { +#### Python3 + ```python class Solution: def maxHappyGroups(self, batchSize: int, groups: List[int]) -> int: diff --git a/solution/1800-1899/1815.Maximum Number of Groups Getting Fresh Donuts/README_EN.md b/solution/1800-1899/1815.Maximum Number of Groups Getting Fresh Donuts/README_EN.md index 7092e3d9f9c05..ae71bcef082da 100644 --- a/solution/1800-1899/1815.Maximum Number of Groups Getting Fresh Donuts/README_EN.md +++ b/solution/1800-1899/1815.Maximum Number of Groups Getting Fresh Donuts/README_EN.md @@ -78,6 +78,8 @@ The time complexity does not exceed $O(10^7)$, and the space complexity does not +#### Python3 + ```python class Solution: def maxHappyGroups(self, batchSize: int, groups: List[int]) -> int: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private Map f = new HashMap<>(); @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func maxHappyGroups(batchSize int, groups []int) (ans int) { state := 0 @@ -220,6 +228,8 @@ func maxHappyGroups(batchSize int, groups []int) (ans int) { +#### Python3 + ```python class Solution: def maxHappyGroups(self, batchSize: int, groups: List[int]) -> int: diff --git a/solution/1800-1899/1816.Truncate Sentence/README.md b/solution/1800-1899/1816.Truncate Sentence/README.md index 59e7f2d74bc46..b46d5b21063f6 100644 --- a/solution/1800-1899/1816.Truncate Sentence/README.md +++ b/solution/1800-1899/1816.Truncate Sentence/README.md @@ -82,12 +82,16 @@ s 中的单词为 ["What", "is" "the", "solution", "to", "this", "problem"] +#### Python3 + ```python class Solution: def truncateSentence(self, s: str, k: int) -> str: return ' '.join(s.split()[:k]) ``` +#### Java + ```java class Solution { public String truncateSentence(String s, int k) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func truncateSentence(s string, k int) string { for i, c := range s { @@ -129,6 +137,8 @@ func truncateSentence(s string, k int) string { } ``` +#### TypeScript + ```ts function truncateSentence(s: string, k: number): string { for (let i = 0; i < s.length; ++i) { @@ -140,6 +150,8 @@ function truncateSentence(s: string, k: number): string { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -166,6 +178,8 @@ var truncateSentence = function (s, k) { +#### Python3 + ```python class Solution: def truncateSentence(self, s: str, k: int) -> str: diff --git a/solution/1800-1899/1816.Truncate Sentence/README_EN.md b/solution/1800-1899/1816.Truncate Sentence/README_EN.md index edaf0ee1bf6eb..6d54eb7a2e53a 100644 --- a/solution/1800-1899/1816.Truncate Sentence/README_EN.md +++ b/solution/1800-1899/1816.Truncate Sentence/README_EN.md @@ -83,12 +83,16 @@ The time complexity is $O(n)$, where $n$ is the length of the string $s$. Ignori +#### Python3 + ```python class Solution: def truncateSentence(self, s: str, k: int) -> str: return ' '.join(s.split()[:k]) ``` +#### Java + ```java class Solution { public String truncateSentence(String s, int k) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func truncateSentence(s string, k int) string { for i, c := range s { @@ -130,6 +138,8 @@ func truncateSentence(s string, k int) string { } ``` +#### TypeScript + ```ts function truncateSentence(s: string, k: number): string { for (let i = 0; i < s.length; ++i) { @@ -141,6 +151,8 @@ function truncateSentence(s: string, k: number): string { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -167,6 +179,8 @@ var truncateSentence = function (s, k) { +#### Python3 + ```python class Solution: def truncateSentence(self, s: str, k: int) -> str: diff --git a/solution/1800-1899/1817.Finding the Users Active Minutes/README.md b/solution/1800-1899/1817.Finding the Users Active Minutes/README.md index 823d24aef0bb3..dc9dd9fe5b128 100644 --- a/solution/1800-1899/1817.Finding the Users Active Minutes/README.md +++ b/solution/1800-1899/1817.Finding the Users Active Minutes/README.md @@ -79,6 +79,8 @@ ID=2 的用户执行操作的分钟分别是:2 和 3 。因此,该用户的 +#### Python3 + ```python class Solution: def findingUsersActiveMinutes(self, logs: List[List[int]], k: int) -> List[int]: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] findingUsersActiveMinutes(int[][] logs, int k) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func findingUsersActiveMinutes(logs [][]int, k int) []int { d := map[int]map[int]bool{} @@ -144,6 +152,8 @@ func findingUsersActiveMinutes(logs [][]int, k int) []int { } ``` +#### TypeScript + ```ts function findingUsersActiveMinutes(logs: number[][], k: number): number[] { const d: Map> = new Map(); diff --git a/solution/1800-1899/1817.Finding the Users Active Minutes/README_EN.md b/solution/1800-1899/1817.Finding the Users Active Minutes/README_EN.md index 4f11c0f5c6d15..b04dba73adadb 100644 --- a/solution/1800-1899/1817.Finding the Users Active Minutes/README_EN.md +++ b/solution/1800-1899/1817.Finding the Users Active Minutes/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python class Solution: def findingUsersActiveMinutes(self, logs: List[List[int]], k: int) -> List[int]: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] findingUsersActiveMinutes(int[][] logs, int k) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func findingUsersActiveMinutes(logs [][]int, k int) []int { d := map[int]map[int]bool{} @@ -142,6 +150,8 @@ func findingUsersActiveMinutes(logs [][]int, k int) []int { } ``` +#### TypeScript + ```ts function findingUsersActiveMinutes(logs: number[][], k: number): number[] { const d: Map> = new Map(); diff --git a/solution/1800-1899/1818.Minimum Absolute Sum Difference/README.md b/solution/1800-1899/1818.Minimum Absolute Sum Difference/README.md index 889ec27c346c6..7a045c546a9ff 100644 --- a/solution/1800-1899/1818.Minimum Absolute Sum Difference/README.md +++ b/solution/1800-1899/1818.Minimum Absolute Sum Difference/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python class Solution: def minAbsoluteSumDiff(self, nums1: List[int], nums2: List[int]) -> int: @@ -113,6 +115,8 @@ class Solution: return (s - mx + mod) % mod ``` +#### Java + ```java class Solution { public int minAbsoluteSumDiff(int[] nums1, int[] nums2) { @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -183,6 +189,8 @@ public: }; ``` +#### Go + ```go func minAbsoluteSumDiff(nums1 []int, nums2 []int) int { n := len(nums1) @@ -218,6 +226,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function minAbsoluteSumDiff(nums1: number[], nums2: number[]): number { const mod = 10 ** 9 + 7; @@ -259,6 +269,8 @@ function search(nums: number[], x: number): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums1 diff --git a/solution/1800-1899/1818.Minimum Absolute Sum Difference/README_EN.md b/solution/1800-1899/1818.Minimum Absolute Sum Difference/README_EN.md index 741c35d9d7d3c..0dd139d007f93 100644 --- a/solution/1800-1899/1818.Minimum Absolute Sum Difference/README_EN.md +++ b/solution/1800-1899/1818.Minimum Absolute Sum Difference/README_EN.md @@ -94,6 +94,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def minAbsoluteSumDiff(self, nums1: List[int], nums2: List[int]) -> int: @@ -112,6 +114,8 @@ class Solution: return (s - mx + mod) % mod ``` +#### Java + ```java class Solution { public int minAbsoluteSumDiff(int[] nums1, int[] nums2) { @@ -153,6 +157,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -182,6 +188,8 @@ public: }; ``` +#### Go + ```go func minAbsoluteSumDiff(nums1 []int, nums2 []int) int { n := len(nums1) @@ -217,6 +225,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function minAbsoluteSumDiff(nums1: number[], nums2: number[]): number { const mod = 10 ** 9 + 7; @@ -258,6 +268,8 @@ function search(nums: number[], x: number): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums1 diff --git a/solution/1800-1899/1819.Number of Different Subsequences GCDs/README.md b/solution/1800-1899/1819.Number of Different Subsequences GCDs/README.md index 2a8bb50cf1bd8..8d4e936ac1b2e 100644 --- a/solution/1800-1899/1819.Number of Different Subsequences GCDs/README.md +++ b/solution/1800-1899/1819.Number of Different Subsequences GCDs/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def countDifferentSubsequenceGCDs(self, nums: List[int]) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countDifferentSubsequenceGCDs(int[] nums) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func countDifferentSubsequenceGCDs(nums []int) (ans int) { mx := slices.Max(nums) diff --git a/solution/1800-1899/1819.Number of Different Subsequences GCDs/README_EN.md b/solution/1800-1899/1819.Number of Different Subsequences GCDs/README_EN.md index 30959d280fed1..d788f7eb331b6 100644 --- a/solution/1800-1899/1819.Number of Different Subsequences GCDs/README_EN.md +++ b/solution/1800-1899/1819.Number of Different Subsequences GCDs/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(n + M \times \log M)$, and the space complexity is $O( +#### Python3 + ```python class Solution: def countDifferentSubsequenceGCDs(self, nums: List[int]) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countDifferentSubsequenceGCDs(int[] nums) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func countDifferentSubsequenceGCDs(nums []int) (ans int) { mx := slices.Max(nums) diff --git a/solution/1800-1899/1820.Maximum Number of Accepted Invitations/README.md b/solution/1800-1899/1820.Maximum Number of Accepted Invitations/README.md index 9cf6fbb1599a7..1d3b75bacccac 100644 --- a/solution/1800-1899/1820.Maximum Number of Accepted Invitations/README.md +++ b/solution/1800-1899/1820.Maximum Number of Accepted Invitations/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def maximumInvitations(self, grid: List[List[int]]) -> int: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[][] grid; @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func maximumInvitations(grid [][]int) int { m, n := len(grid), len(grid[0]) diff --git a/solution/1800-1899/1820.Maximum Number of Accepted Invitations/README_EN.md b/solution/1800-1899/1820.Maximum Number of Accepted Invitations/README_EN.md index 789a798d53070..60e153fb9c772 100644 --- a/solution/1800-1899/1820.Maximum Number of Accepted Invitations/README_EN.md +++ b/solution/1800-1899/1820.Maximum Number of Accepted Invitations/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(m \times n)$. +#### Python3 + ```python class Solution: def maximumInvitations(self, grid: List[List[int]]) -> int: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[][] grid; @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func maximumInvitations(grid [][]int) int { m, n := len(grid), len(grid[0]) diff --git a/solution/1800-1899/1821.Find Customers With Positive Revenue this Year/README.md b/solution/1800-1899/1821.Find Customers With Positive Revenue this Year/README.md index 9f732f488236d..98a0616698d13 100644 --- a/solution/1800-1899/1821.Find Customers With Positive Revenue this Year/README.md +++ b/solution/1800-1899/1821.Find Customers With Positive Revenue this Year/README.md @@ -83,6 +83,8 @@ Customers +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1800-1899/1821.Find Customers With Positive Revenue this Year/README_EN.md b/solution/1800-1899/1821.Find Customers With Positive Revenue this Year/README_EN.md index e7a34a51b81bf..ec0f72313db69 100644 --- a/solution/1800-1899/1821.Find Customers With Positive Revenue this Year/README_EN.md +++ b/solution/1800-1899/1821.Find Customers With Positive Revenue this Year/README_EN.md @@ -83,6 +83,8 @@ We can directly use the `WHERE` clause to filter out the customers whose `year` +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1800-1899/1822.Sign of the Product of an Array/README.md b/solution/1800-1899/1822.Sign of the Product of an Array/README.md index b3cfd7306a556..f3e13e6032876 100644 --- a/solution/1800-1899/1822.Sign of the Product of an Array/README.md +++ b/solution/1800-1899/1822.Sign of the Product of an Array/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def arraySign(self, nums: List[int]) -> int: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int arraySign(int[] nums) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func arraySign(nums []int) int { ans := 1 @@ -144,6 +152,8 @@ func arraySign(nums []int) int { } ``` +#### Rust + ```rust impl Solution { pub fn array_sign(nums: Vec) -> i32 { @@ -161,6 +171,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -180,6 +192,8 @@ var arraySign = function (nums) { }; ``` +#### C + ```c int arraySign(int* nums, int numsSize) { int ans = 1; diff --git a/solution/1800-1899/1822.Sign of the Product of an Array/README_EN.md b/solution/1800-1899/1822.Sign of the Product of an Array/README_EN.md index cfcb572828a51..37522697c5fc4 100644 --- a/solution/1800-1899/1822.Sign of the Product of an Array/README_EN.md +++ b/solution/1800-1899/1822.Sign of the Product of an Array/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def arraySign(self, nums: List[int]) -> int: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int arraySign(int[] nums) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func arraySign(nums []int) int { ans := 1 @@ -142,6 +150,8 @@ func arraySign(nums []int) int { } ``` +#### Rust + ```rust impl Solution { pub fn array_sign(nums: Vec) -> i32 { @@ -159,6 +169,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -178,6 +190,8 @@ var arraySign = function (nums) { }; ``` +#### C + ```c int arraySign(int* nums, int numsSize) { int ans = 1; diff --git a/solution/1800-1899/1823.Find the Winner of the Circular Game/README.md b/solution/1800-1899/1823.Find the Winner of the Circular Game/README.md index d1c239f289a25..185dc5936224e 100644 --- a/solution/1800-1899/1823.Find the Winner of the Circular Game/README.md +++ b/solution/1800-1899/1823.Find the Winner of the Circular Game/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def findTheWinner(self, n: int, k: int) -> int: @@ -93,6 +95,8 @@ class Solution: return n if ans == 0 else ans ``` +#### Java + ```java class Solution { public int findTheWinner(int n, int k) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func findTheWinner(n int, k int) int { if n == 1 { @@ -129,6 +137,8 @@ func findTheWinner(n int, k int) int { } ``` +#### TypeScript + ```ts class LinkNode { public val: number; diff --git a/solution/1800-1899/1823.Find the Winner of the Circular Game/README_EN.md b/solution/1800-1899/1823.Find the Winner of the Circular Game/README_EN.md index c7456d8be4358..800d1682c5d8f 100644 --- a/solution/1800-1899/1823.Find the Winner of the Circular Game/README_EN.md +++ b/solution/1800-1899/1823.Find the Winner of the Circular Game/README_EN.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def findTheWinner(self, n: int, k: int) -> int: @@ -92,6 +94,8 @@ class Solution: return n if ans == 0 else ans ``` +#### Java + ```java class Solution { public int findTheWinner(int n, int k) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func findTheWinner(n int, k int) int { if n == 1 { @@ -128,6 +136,8 @@ func findTheWinner(n int, k int) int { } ``` +#### TypeScript + ```ts class LinkNode { public val: number; diff --git a/solution/1800-1899/1824.Minimum Sideway Jumps/README.md b/solution/1800-1899/1824.Minimum Sideway Jumps/README.md index 5a37221b98ce5..746dae9084504 100644 --- a/solution/1800-1899/1824.Minimum Sideway Jumps/README.md +++ b/solution/1800-1899/1824.Minimum Sideway Jumps/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class Solution: def minSideJumps(self, obstacles: List[int]) -> int: @@ -112,6 +114,8 @@ class Solution: return min(f) ``` +#### Java + ```java class Solution { public int minSideJumps(int[] obstacles) { @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func minSideJumps(obstacles []int) int { f := [3]int{1, 0, 1} @@ -183,6 +191,8 @@ func minSideJumps(obstacles []int) int { } ``` +#### TypeScript + ```ts function minSideJumps(obstacles: number[]): number { const inf = 1 << 30; diff --git a/solution/1800-1899/1824.Minimum Sideway Jumps/README_EN.md b/solution/1800-1899/1824.Minimum Sideway Jumps/README_EN.md index e68f0ffdaa6f6..546ae98230798 100644 --- a/solution/1800-1899/1824.Minimum Sideway Jumps/README_EN.md +++ b/solution/1800-1899/1824.Minimum Sideway Jumps/README_EN.md @@ -94,6 +94,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $obstacles$. +#### Python3 + ```python class Solution: def minSideJumps(self, obstacles: List[int]) -> int: @@ -110,6 +112,8 @@ class Solution: return min(f) ``` +#### Java + ```java class Solution { public int minSideJumps(int[] obstacles) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func minSideJumps(obstacles []int) int { f := [3]int{1, 0, 1} @@ -181,6 +189,8 @@ func minSideJumps(obstacles []int) int { } ``` +#### TypeScript + ```ts function minSideJumps(obstacles: number[]): number { const inf = 1 << 30; diff --git a/solution/1800-1899/1825.Finding MK Average/README.md b/solution/1800-1899/1825.Finding MK Average/README.md index 88a7c6f9af55b..30c037ce7ab91 100644 --- a/solution/1800-1899/1825.Finding MK Average/README.md +++ b/solution/1800-1899/1825.Finding MK Average/README.md @@ -109,6 +109,8 @@ obj.calculateMKAverage(); // 最后 3 个元素为 [5,5,5] +#### Python3 + ```python from sortedcontainers import SortedList @@ -168,6 +170,8 @@ class MKAverage: # param_2 = obj.calculateMKAverage() ``` +#### Java + ```java class MKAverage { @@ -262,6 +266,8 @@ class MKAverage { */ ``` +#### C++ + ```cpp class MKAverage { public: @@ -338,6 +344,8 @@ private: */ ``` +#### Go + ```go type MKAverage struct { lo, mid, hi *redblacktree.Tree @@ -443,6 +451,8 @@ func (this *MKAverage) CalculateMKAverage() int { +#### Python3 + ```python from sortedcontainers import SortedList diff --git a/solution/1800-1899/1825.Finding MK Average/README_EN.md b/solution/1800-1899/1825.Finding MK Average/README_EN.md index dbf82da3ece1f..e00b194b4ee85 100644 --- a/solution/1800-1899/1825.Finding MK Average/README_EN.md +++ b/solution/1800-1899/1825.Finding MK Average/README_EN.md @@ -107,6 +107,8 @@ In terms of time complexity, each call to the $addElement(num)$ function has a t +#### Python3 + ```python from sortedcontainers import SortedList @@ -166,6 +168,8 @@ class MKAverage: # param_2 = obj.calculateMKAverage() ``` +#### Java + ```java class MKAverage { @@ -260,6 +264,8 @@ class MKAverage { */ ``` +#### C++ + ```cpp class MKAverage { public: @@ -336,6 +342,8 @@ private: */ ``` +#### Go + ```go type MKAverage struct { lo, mid, hi *redblacktree.Tree @@ -441,6 +449,8 @@ func (this *MKAverage) CalculateMKAverage() int { +#### Python3 + ```python from sortedcontainers import SortedList diff --git a/solution/1800-1899/1826.Faulty Sensor/README.md b/solution/1800-1899/1826.Faulty Sensor/README.md index 1db96fff87b77..7a34b54155bbc 100644 --- a/solution/1800-1899/1826.Faulty Sensor/README.md +++ b/solution/1800-1899/1826.Faulty Sensor/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def badSensor(self, sensor1: List[int], sensor2: List[int]) -> int: @@ -100,6 +102,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int badSensor(int[] sensor1, int[] sensor2) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func badSensor(sensor1 []int, sensor2 []int) int { i, n := 0, len(sensor1) @@ -153,6 +161,8 @@ func badSensor(sensor1 []int, sensor2 []int) int { } ``` +#### TypeScript + ```ts function badSensor(sensor1: number[], sensor2: number[]): number { let i = 0; diff --git a/solution/1800-1899/1826.Faulty Sensor/README_EN.md b/solution/1800-1899/1826.Faulty Sensor/README_EN.md index 30ab2ef715dc2..51d5f3b4e4774 100644 --- a/solution/1800-1899/1826.Faulty Sensor/README_EN.md +++ b/solution/1800-1899/1826.Faulty Sensor/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def badSensor(self, sensor1: List[int], sensor2: List[int]) -> int: @@ -97,6 +99,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int badSensor(int[] sensor1, int[] sensor2) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func badSensor(sensor1 []int, sensor2 []int) int { i, n := 0, len(sensor1) @@ -150,6 +158,8 @@ func badSensor(sensor1 []int, sensor2 []int) int { } ``` +#### TypeScript + ```ts function badSensor(sensor1: number[], sensor2: number[]): number { let i = 0; diff --git a/solution/1800-1899/1827.Minimum Operations to Make the Array Increasing/README.md b/solution/1800-1899/1827.Minimum Operations to Make the Array Increasing/README.md index d2f7b6903f0f1..7c5ddf186954d 100644 --- a/solution/1800-1899/1827.Minimum Operations to Make the Array Increasing/README.md +++ b/solution/1800-1899/1827.Minimum Operations to Make the Array Increasing/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int]) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minOperations(int[] nums) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int) (ans int) { mx := 0 @@ -126,6 +134,8 @@ func minOperations(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function minOperations(nums: number[]): number { let ans = 0; @@ -138,6 +148,8 @@ function minOperations(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_operations(nums: Vec) -> i32 { @@ -152,6 +164,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int MinOperations(int[] nums) { @@ -165,6 +179,8 @@ public class Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) diff --git a/solution/1800-1899/1827.Minimum Operations to Make the Array Increasing/README_EN.md b/solution/1800-1899/1827.Minimum Operations to Make the Array Increasing/README_EN.md index 3ec48072c837c..979e584e8350d 100644 --- a/solution/1800-1899/1827.Minimum Operations to Make the Array Increasing/README_EN.md +++ b/solution/1800-1899/1827.Minimum Operations to Make the Array Increasing/README_EN.md @@ -99,6 +99,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array `nums`. The +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int]) -> int: @@ -109,6 +111,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minOperations(int[] nums) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int) (ans int) { mx := 0 @@ -147,6 +155,8 @@ func minOperations(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function minOperations(nums: number[]): number { let ans = 0; @@ -159,6 +169,8 @@ function minOperations(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_operations(nums: Vec) -> i32 { @@ -173,6 +185,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int MinOperations(int[] nums) { @@ -186,6 +200,8 @@ public class Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) diff --git a/solution/1800-1899/1828.Queries on Number of Points Inside a Circle/README.md b/solution/1800-1899/1828.Queries on Number of Points Inside a Circle/README.md index 3d54e6bb7ed15..51778a1a01de5 100644 --- a/solution/1800-1899/1828.Queries on Number of Points Inside a Circle/README.md +++ b/solution/1800-1899/1828.Queries on Number of Points Inside a Circle/README.md @@ -75,6 +75,8 @@ queries[0] 是绿色的圆,queries[1] 是红色的圆,queries[2] 是蓝色 +#### Python3 + ```python class Solution: def countPoints( @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] countPoints(int[][] points, int[][] queries) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func countPoints(points [][]int, queries [][]int) (ans []int) { for _, q := range queries { @@ -148,6 +156,8 @@ func countPoints(points [][]int, queries [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function countPoints(points: number[][], queries: number[][]): number[] { return queries.map(([cx, cy, r]) => { @@ -162,6 +172,8 @@ function countPoints(points: number[][], queries: number[][]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn count_points(points: Vec>, queries: Vec>) -> Vec { @@ -184,6 +196,8 @@ impl Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). diff --git a/solution/1800-1899/1828.Queries on Number of Points Inside a Circle/README_EN.md b/solution/1800-1899/1828.Queries on Number of Points Inside a Circle/README_EN.md index 34e1433197c14..2e6fd58d6fc17 100644 --- a/solution/1800-1899/1828.Queries on Number of Points Inside a Circle/README_EN.md +++ b/solution/1800-1899/1828.Queries on Number of Points Inside a Circle/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(m \times n)$, where $m$ and $n$ are the lengths of the +#### Python3 + ```python class Solution: def countPoints( @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] countPoints(int[][] points, int[][] queries) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func countPoints(points [][]int, queries [][]int) (ans []int) { for _, q := range queries { @@ -151,6 +159,8 @@ func countPoints(points [][]int, queries [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function countPoints(points: number[][], queries: number[][]): number[] { return queries.map(([cx, cy, r]) => { @@ -165,6 +175,8 @@ function countPoints(points: number[][], queries: number[][]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn count_points(points: Vec>, queries: Vec>) -> Vec { @@ -187,6 +199,8 @@ impl Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). diff --git a/solution/1800-1899/1829.Maximum XOR for Each Query/README.md b/solution/1800-1899/1829.Maximum XOR for Each Query/README.md index c3836801753cd..6631eb107ab8f 100644 --- a/solution/1800-1899/1829.Maximum XOR for Each Query/README.md +++ b/solution/1800-1899/1829.Maximum XOR for Each Query/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def getMaximumXor(self, nums: List[int], maximumBit: int) -> List[int]: @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] getMaximumXor(int[] nums, int maximumBit) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func getMaximumXor(nums []int, maximumBit int) (ans []int) { xs := 0 @@ -179,6 +187,8 @@ func getMaximumXor(nums []int, maximumBit int) (ans []int) { } ``` +#### TypeScript + ```ts function getMaximumXor(nums: number[], maximumBit: number): number[] { let xs = 0; @@ -202,6 +212,8 @@ function getMaximumXor(nums: number[], maximumBit: number): number[] { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -230,6 +242,8 @@ var getMaximumXor = function (nums, maximumBit) { }; ``` +#### C# + ```cs public class Solution { public int[] GetMaximumXor(int[] nums, int maximumBit) { @@ -271,6 +285,8 @@ public class Solution { +#### Python3 + ```python class Solution: def getMaximumXor(self, nums: List[int], maximumBit: int) -> List[int]: @@ -284,6 +300,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] getMaximumXor(int[] nums, int maximumBit) { @@ -305,6 +323,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -327,6 +347,8 @@ public: }; ``` +#### Go + ```go func getMaximumXor(nums []int, maximumBit int) (ans []int) { xs := 0 @@ -344,6 +366,8 @@ func getMaximumXor(nums []int, maximumBit int) (ans []int) { } ``` +#### TypeScript + ```ts function getMaximumXor(nums: number[], maximumBit: number): number[] { let xs = 0; @@ -363,6 +387,8 @@ function getMaximumXor(nums: number[], maximumBit: number): number[] { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -387,6 +413,8 @@ var getMaximumXor = function (nums, maximumBit) { }; ``` +#### C# + ```cs public class Solution { public int[] GetMaximumXor(int[] nums, int maximumBit) { diff --git a/solution/1800-1899/1829.Maximum XOR for Each Query/README_EN.md b/solution/1800-1899/1829.Maximum XOR for Each Query/README_EN.md index 5b49a32215adb..eada5fc3e53ea 100644 --- a/solution/1800-1899/1829.Maximum XOR for Each Query/README_EN.md +++ b/solution/1800-1899/1829.Maximum XOR for Each Query/README_EN.md @@ -90,6 +90,8 @@ The time complexity is $O(n \times m)$, where $n$ and $m$ are the values of the +#### Python3 + ```python class Solution: def getMaximumXor(self, nums: List[int], maximumBit: int) -> List[int]: @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] getMaximumXor(int[] nums, int maximumBit) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func getMaximumXor(nums []int, maximumBit int) (ans []int) { xs := 0 @@ -177,6 +185,8 @@ func getMaximumXor(nums []int, maximumBit int) (ans []int) { } ``` +#### TypeScript + ```ts function getMaximumXor(nums: number[], maximumBit: number): number[] { let xs = 0; @@ -200,6 +210,8 @@ function getMaximumXor(nums: number[], maximumBit: number): number[] { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -228,6 +240,8 @@ var getMaximumXor = function (nums, maximumBit) { }; ``` +#### C# + ```cs public class Solution { public int[] GetMaximumXor(int[] nums, int maximumBit) { @@ -269,6 +283,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array `nums`. Igno +#### Python3 + ```python class Solution: def getMaximumXor(self, nums: List[int], maximumBit: int) -> List[int]: @@ -282,6 +298,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] getMaximumXor(int[] nums, int maximumBit) { @@ -303,6 +321,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -325,6 +345,8 @@ public: }; ``` +#### Go + ```go func getMaximumXor(nums []int, maximumBit int) (ans []int) { xs := 0 @@ -342,6 +364,8 @@ func getMaximumXor(nums []int, maximumBit int) (ans []int) { } ``` +#### TypeScript + ```ts function getMaximumXor(nums: number[], maximumBit: number): number[] { let xs = 0; @@ -361,6 +385,8 @@ function getMaximumXor(nums: number[], maximumBit: number): number[] { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -385,6 +411,8 @@ var getMaximumXor = function (nums, maximumBit) { }; ``` +#### C# + ```cs public class Solution { public int[] GetMaximumXor(int[] nums, int maximumBit) { diff --git a/solution/1800-1899/1830.Minimum Number of Operations to Make String Sorted/README.md b/solution/1800-1899/1830.Minimum Number of Operations to Make String Sorted/README.md index 5687076c735b6..66cfeeadbfcf5 100644 --- a/solution/1800-1899/1830.Minimum Number of Operations to Make String Sorted/README.md +++ b/solution/1800-1899/1830.Minimum Number of Operations to Make String Sorted/README.md @@ -98,6 +98,8 @@ tags: +#### Python3 + ```python n = 3010 mod = 10**9 + 7 @@ -125,6 +127,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int N = 3010; @@ -177,6 +181,8 @@ class Solution { } ``` +#### C++ + ```cpp const int N = 3010; const int MOD = 1e9 + 7; @@ -230,6 +236,8 @@ public: }; ``` +#### Go + ```go const n = 3010 const mod = 1e9 + 7 diff --git a/solution/1800-1899/1830.Minimum Number of Operations to Make String Sorted/README_EN.md b/solution/1800-1899/1830.Minimum Number of Operations to Make String Sorted/README_EN.md index 5aa77f0869a66..ff23b38ebb09a 100644 --- a/solution/1800-1899/1830.Minimum Number of Operations to Make String Sorted/README_EN.md +++ b/solution/1800-1899/1830.Minimum Number of Operations to Make String Sorted/README_EN.md @@ -87,6 +87,8 @@ The time complexity is $O(n \times k)$, and the space complexity is $O(n)$. Wher +#### Python3 + ```python n = 3010 mod = 10**9 + 7 @@ -114,6 +116,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int N = 3010; @@ -166,6 +170,8 @@ class Solution { } ``` +#### C++ + ```cpp const int N = 3010; const int MOD = 1e9 + 7; @@ -219,6 +225,8 @@ public: }; ``` +#### Go + ```go const n = 3010 const mod = 1e9 + 7 diff --git a/solution/1800-1899/1831.Maximum Transaction Each Day/README.md b/solution/1800-1899/1831.Maximum Transaction Each Day/README.md index f67f46ff7943b..9ec4d00ffcbd0 100644 --- a/solution/1800-1899/1831.Maximum Transaction Each Day/README.md +++ b/solution/1800-1899/1831.Maximum Transaction Each Day/README.md @@ -85,6 +85,8 @@ Transactions table: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1800-1899/1831.Maximum Transaction Each Day/README_EN.md b/solution/1800-1899/1831.Maximum Transaction Each Day/README_EN.md index 28cd31d771893..a59011cd244cb 100644 --- a/solution/1800-1899/1831.Maximum Transaction Each Day/README_EN.md +++ b/solution/1800-1899/1831.Maximum Transaction Each Day/README_EN.md @@ -84,6 +84,8 @@ We can use the window function `RANK()`, which assigns a rank to each transactio +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1800-1899/1832.Check if the Sentence Is Pangram/README.md b/solution/1800-1899/1832.Check if the Sentence Is Pangram/README.md index 2bc59a3aa21b9..3153df2a29cd0 100644 --- a/solution/1800-1899/1832.Check if the Sentence Is Pangram/README.md +++ b/solution/1800-1899/1832.Check if the Sentence Is Pangram/README.md @@ -65,12 +65,16 @@ tags: +#### Python3 + ```python class Solution: def checkIfPangram(self, sentence: str) -> bool: return len(set(sentence)) == 26 ``` +#### Java + ```java class Solution { public boolean checkIfPangram(String sentence) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,6 +107,8 @@ public: }; ``` +#### Go + ```go func checkIfPangram(sentence string) bool { vis := [26]bool{} @@ -116,6 +124,8 @@ func checkIfPangram(sentence string) bool { } ``` +#### TypeScript + ```ts function checkIfPangram(sentence: string): boolean { const vis = new Array(26).fill(false); @@ -126,6 +136,8 @@ function checkIfPangram(sentence: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn check_if_pangram(sentence: String) -> bool { @@ -138,6 +150,8 @@ impl Solution { } ``` +#### C + ```c bool checkIfPangram(char* sentence) { int vis[26] = {0}; @@ -169,6 +183,8 @@ bool checkIfPangram(char* sentence) { +#### Python3 + ```python class Solution: def checkIfPangram(self, sentence: str) -> bool: @@ -178,6 +194,8 @@ class Solution: return mask == (1 << 26) - 1 ``` +#### Java + ```java class Solution { public boolean checkIfPangram(String sentence) { @@ -190,6 +208,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -201,6 +221,8 @@ public: }; ``` +#### Go + ```go func checkIfPangram(sentence string) bool { mask := 0 @@ -211,6 +233,8 @@ func checkIfPangram(sentence string) bool { } ``` +#### TypeScript + ```ts function checkIfPangram(sentence: string): boolean { let mark = 0; @@ -221,6 +245,8 @@ function checkIfPangram(sentence: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn check_if_pangram(sentence: String) -> bool { @@ -233,6 +259,8 @@ impl Solution { } ``` +#### C + ```c bool checkIfPangram(char* sentence) { int mark = 0; diff --git a/solution/1800-1899/1832.Check if the Sentence Is Pangram/README_EN.md b/solution/1800-1899/1832.Check if the Sentence Is Pangram/README_EN.md index 98d867bfe93d5..ab271c1e3c600 100644 --- a/solution/1800-1899/1832.Check if the Sentence Is Pangram/README_EN.md +++ b/solution/1800-1899/1832.Check if the Sentence Is Pangram/README_EN.md @@ -61,12 +61,16 @@ The time complexity is $O(n)$, and the space complexity is $O(C)$. Where $n$ is +#### Python3 + ```python class Solution: def checkIfPangram(self, sentence: str) -> bool: return len(set(sentence)) == 26 ``` +#### Java + ```java class Solution { public boolean checkIfPangram(String sentence) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -97,6 +103,8 @@ public: }; ``` +#### Go + ```go func checkIfPangram(sentence string) bool { vis := [26]bool{} @@ -112,6 +120,8 @@ func checkIfPangram(sentence string) bool { } ``` +#### TypeScript + ```ts function checkIfPangram(sentence: string): boolean { const vis = new Array(26).fill(false); @@ -122,6 +132,8 @@ function checkIfPangram(sentence: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn check_if_pangram(sentence: String) -> bool { @@ -134,6 +146,8 @@ impl Solution { } ``` +#### C + ```c bool checkIfPangram(char* sentence) { int vis[26] = {0}; @@ -165,6 +179,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string `sentence`. +#### Python3 + ```python class Solution: def checkIfPangram(self, sentence: str) -> bool: @@ -174,6 +190,8 @@ class Solution: return mask == (1 << 26) - 1 ``` +#### Java + ```java class Solution { public boolean checkIfPangram(String sentence) { @@ -186,6 +204,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -197,6 +217,8 @@ public: }; ``` +#### Go + ```go func checkIfPangram(sentence string) bool { mask := 0 @@ -207,6 +229,8 @@ func checkIfPangram(sentence string) bool { } ``` +#### TypeScript + ```ts function checkIfPangram(sentence: string): boolean { let mark = 0; @@ -217,6 +241,8 @@ function checkIfPangram(sentence: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn check_if_pangram(sentence: String) -> bool { @@ -229,6 +255,8 @@ impl Solution { } ``` +#### C + ```c bool checkIfPangram(char* sentence) { int mark = 0; diff --git a/solution/1800-1899/1833.Maximum Ice Cream Bars/README.md b/solution/1800-1899/1833.Maximum Ice Cream Bars/README.md index a021ccf4488c9..bd53e0643e364 100644 --- a/solution/1800-1899/1833.Maximum Ice Cream Bars/README.md +++ b/solution/1800-1899/1833.Maximum Ice Cream Bars/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def maxIceCream(self, costs: List[int], coins: int) -> int: @@ -94,6 +96,8 @@ class Solution: return len(costs) ``` +#### Java + ```java class Solution { public int maxIceCream(int[] costs, int coins) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func maxIceCream(costs []int, coins int) int { sort.Ints(costs) @@ -138,6 +146,8 @@ func maxIceCream(costs []int, coins int) int { } ``` +#### TypeScript + ```ts function maxIceCream(costs: number[], coins: number): number { costs.sort((a, b) => a - b); @@ -152,6 +162,8 @@ function maxIceCream(costs: number[], coins: number): number { } ``` +#### JavaScript + ```js /** * @param {number[]} costs diff --git a/solution/1800-1899/1833.Maximum Ice Cream Bars/README_EN.md b/solution/1800-1899/1833.Maximum Ice Cream Bars/README_EN.md index 974230ade4de0..18cfd05b4e389 100644 --- a/solution/1800-1899/1833.Maximum Ice Cream Bars/README_EN.md +++ b/solution/1800-1899/1833.Maximum Ice Cream Bars/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def maxIceCream(self, costs: List[int], coins: int) -> int: @@ -92,6 +94,8 @@ class Solution: return len(costs) ``` +#### Java + ```java class Solution { public int maxIceCream(int[] costs, int coins) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func maxIceCream(costs []int, coins int) int { sort.Ints(costs) @@ -136,6 +144,8 @@ func maxIceCream(costs []int, coins int) int { } ``` +#### TypeScript + ```ts function maxIceCream(costs: number[], coins: number): number { costs.sort((a, b) => a - b); @@ -150,6 +160,8 @@ function maxIceCream(costs: number[], coins: number): number { } ``` +#### JavaScript + ```js /** * @param {number[]} costs diff --git a/solution/1800-1899/1834.Single-Threaded CPU/README.md b/solution/1800-1899/1834.Single-Threaded CPU/README.md index 0576988f5d529..c6ecef7239fce 100644 --- a/solution/1800-1899/1834.Single-Threaded CPU/README.md +++ b/solution/1800-1899/1834.Single-Threaded CPU/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class Solution: def getOrder(self, tasks: List[List[int]]) -> List[int]: @@ -118,6 +120,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] getOrder(int[][] tasks) { @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go func getOrder(tasks [][]int) (ans []int) { for i := range tasks { diff --git a/solution/1800-1899/1834.Single-Threaded CPU/README_EN.md b/solution/1800-1899/1834.Single-Threaded CPU/README_EN.md index 759f8918e77b8..fe8ae10345d7e 100644 --- a/solution/1800-1899/1834.Single-Threaded CPU/README_EN.md +++ b/solution/1800-1899/1834.Single-Threaded CPU/README_EN.md @@ -97,6 +97,8 @@ The time complexity is $O(n \times \log n)$, where $n$ is the number of tasks. +#### Python3 + ```python class Solution: def getOrder(self, tasks: List[List[int]]) -> List[int]: @@ -119,6 +121,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] getOrder(int[][] tasks) { @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go func getOrder(tasks [][]int) (ans []int) { for i := range tasks { diff --git a/solution/1800-1899/1835.Find XOR Sum of All Pairs Bitwise AND/README.md b/solution/1800-1899/1835.Find XOR Sum of All Pairs Bitwise AND/README.md index e84ee49642ca9..2026613cd79d8 100644 --- a/solution/1800-1899/1835.Find XOR Sum of All Pairs Bitwise AND/README.md +++ b/solution/1800-1899/1835.Find XOR Sum of All Pairs Bitwise AND/README.md @@ -88,6 +88,8 @@ $$ +#### Python3 + ```python class Solution: def getXORSum(self, arr1: List[int], arr2: List[int]) -> int: @@ -96,6 +98,8 @@ class Solution: return a & b ``` +#### Java + ```java class Solution { public int getXORSum(int[] arr1, int[] arr2) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func getXORSum(arr1 []int, arr2 []int) int { var a, b int @@ -135,6 +143,8 @@ func getXORSum(arr1 []int, arr2 []int) int { } ``` +#### TypeScript + ```ts function getXORSum(arr1: number[], arr2: number[]): number { const a = arr1.reduce((acc, x) => acc ^ x); diff --git a/solution/1800-1899/1835.Find XOR Sum of All Pairs Bitwise AND/README_EN.md b/solution/1800-1899/1835.Find XOR Sum of All Pairs Bitwise AND/README_EN.md index 1f0e5553437c3..a3ae9b3edfd6b 100644 --- a/solution/1800-1899/1835.Find XOR Sum of All Pairs Bitwise AND/README_EN.md +++ b/solution/1800-1899/1835.Find XOR Sum of All Pairs Bitwise AND/README_EN.md @@ -89,6 +89,8 @@ The time complexity is $O(n + m)$, where $n$ and $m$ are the lengths of arrays $ +#### Python3 + ```python class Solution: def getXORSum(self, arr1: List[int], arr2: List[int]) -> int: @@ -97,6 +99,8 @@ class Solution: return a & b ``` +#### Java + ```java class Solution { public int getXORSum(int[] arr1, int[] arr2) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func getXORSum(arr1 []int, arr2 []int) int { var a, b int @@ -136,6 +144,8 @@ func getXORSum(arr1 []int, arr2 []int) int { } ``` +#### TypeScript + ```ts function getXORSum(arr1: number[], arr2: number[]): number { const a = arr1.reduce((acc, x) => acc ^ x); diff --git a/solution/1800-1899/1836.Remove Duplicates From an Unsorted Linked List/README.md b/solution/1800-1899/1836.Remove Duplicates From an Unsorted Linked List/README.md index 848d4d0057a76..9ee950aa6ace5 100644 --- a/solution/1800-1899/1836.Remove Duplicates From an Unsorted Linked List/README.md +++ b/solution/1800-1899/1836.Remove Duplicates From an Unsorted Linked List/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -91,6 +93,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -177,6 +185,8 @@ func deleteDuplicatesUnsorted(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/1800-1899/1836.Remove Duplicates From an Unsorted Linked List/README_EN.md b/solution/1800-1899/1836.Remove Duplicates From an Unsorted Linked List/README_EN.md index 355bee0c53d73..e1c623dee2b31 100644 --- a/solution/1800-1899/1836.Remove Duplicates From an Unsorted Linked List/README_EN.md +++ b/solution/1800-1899/1836.Remove Duplicates From an Unsorted Linked List/README_EN.md @@ -91,6 +91,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -115,6 +117,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -201,6 +209,8 @@ func deleteDuplicatesUnsorted(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/1800-1899/1837.Sum of Digits in Base K/README.md b/solution/1800-1899/1837.Sum of Digits in Base K/README.md index 3dae5daabc887..f9f2ab64aaf08 100644 --- a/solution/1800-1899/1837.Sum of Digits in Base K/README.md +++ b/solution/1800-1899/1837.Sum of Digits in Base K/README.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def sumBase(self, n: int, k: int) -> int: @@ -73,6 +75,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int sumBase(int n, int k) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -100,6 +106,8 @@ public: }; ``` +#### Go + ```go func sumBase(n int, k int) (ans int) { for n > 0 { @@ -110,6 +118,8 @@ func sumBase(n int, k int) (ans int) { } ``` +#### TypeScript + ```ts function sumBase(n: number, k: number): number { let ans = 0; @@ -121,6 +131,8 @@ function sumBase(n: number, k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn sum_base(mut n: i32, k: i32) -> i32 { @@ -134,6 +146,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -150,6 +164,8 @@ var sumBase = function (n, k) { }; ``` +#### C + ```c int sumBase(int n, int k) { int ans = 0; diff --git a/solution/1800-1899/1837.Sum of Digits in Base K/README_EN.md b/solution/1800-1899/1837.Sum of Digits in Base K/README_EN.md index 5a9c8adef0e24..ce6cd324b237f 100644 --- a/solution/1800-1899/1837.Sum of Digits in Base K/README_EN.md +++ b/solution/1800-1899/1837.Sum of Digits in Base K/README_EN.md @@ -61,6 +61,8 @@ The time complexity is $O(\log_{k}n)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def sumBase(self, n: int, k: int) -> int: @@ -71,6 +73,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int sumBase(int n, int k) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -98,6 +104,8 @@ public: }; ``` +#### Go + ```go func sumBase(n int, k int) (ans int) { for n > 0 { @@ -108,6 +116,8 @@ func sumBase(n int, k int) (ans int) { } ``` +#### TypeScript + ```ts function sumBase(n: number, k: number): number { let ans = 0; @@ -119,6 +129,8 @@ function sumBase(n: number, k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn sum_base(mut n: i32, k: i32) -> i32 { @@ -132,6 +144,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -148,6 +162,8 @@ var sumBase = function (n, k) { }; ``` +#### C + ```c int sumBase(int n, int k) { int ans = 0; diff --git a/solution/1800-1899/1838.Frequency of the Most Frequent Element/README.md b/solution/1800-1899/1838.Frequency of the Most Frequent Element/README.md index a978774853882..d7320d201b42c 100644 --- a/solution/1800-1899/1838.Frequency of the Most Frequent Element/README.md +++ b/solution/1800-1899/1838.Frequency of the Most Frequent Element/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def maxFrequency(self, nums: List[int], k: int) -> int: @@ -113,6 +115,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { private int[] nums; @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -184,6 +190,8 @@ public: }; ``` +#### Go + ```go func maxFrequency(nums []int, k int) int { n := len(nums) @@ -213,6 +221,8 @@ func maxFrequency(nums []int, k int) int { } ``` +#### TypeScript + ```ts function maxFrequency(nums: number[], k: number): number { const n = nums.length; @@ -258,6 +268,8 @@ function maxFrequency(nums: number[], k: number): number { +#### Python3 + ```python class Solution: def maxFrequency(self, nums: List[int], k: int) -> int: @@ -273,6 +285,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxFrequency(int[] nums, int k) { @@ -291,6 +305,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -310,6 +326,8 @@ public: }; ``` +#### Go + ```go func maxFrequency(nums []int, k int) int { sort.Ints(nums) @@ -326,6 +344,8 @@ func maxFrequency(nums []int, k int) int { } ``` +#### TypeScript + ```ts function maxFrequency(nums: number[], k: number): number { nums.sort((a, b) => a - b); diff --git a/solution/1800-1899/1838.Frequency of the Most Frequent Element/README_EN.md b/solution/1800-1899/1838.Frequency of the Most Frequent Element/README_EN.md index 8c0d643046fba..d28dd0698d637 100644 --- a/solution/1800-1899/1838.Frequency of the Most Frequent Element/README_EN.md +++ b/solution/1800-1899/1838.Frequency of the Most Frequent Element/README_EN.md @@ -89,6 +89,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def maxFrequency(self, nums: List[int], k: int) -> int: @@ -111,6 +113,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { private int[] nums; @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -182,6 +188,8 @@ public: }; ``` +#### Go + ```go func maxFrequency(nums []int, k int) int { n := len(nums) @@ -211,6 +219,8 @@ func maxFrequency(nums []int, k int) int { } ``` +#### TypeScript + ```ts function maxFrequency(nums: number[], k: number): number { const n = nums.length; @@ -256,6 +266,8 @@ The time complexity is $O(n \log n)$, and the space complexity is $O(\log n)$. W +#### Python3 + ```python class Solution: def maxFrequency(self, nums: List[int], k: int) -> int: @@ -271,6 +283,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxFrequency(int[] nums, int k) { @@ -289,6 +303,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -308,6 +324,8 @@ public: }; ``` +#### Go + ```go func maxFrequency(nums []int, k int) int { sort.Ints(nums) @@ -324,6 +342,8 @@ func maxFrequency(nums []int, k int) int { } ``` +#### TypeScript + ```ts function maxFrequency(nums: number[], k: number): number { nums.sort((a, b) => a - b); diff --git a/solution/1800-1899/1839.Longest Substring Of All Vowels in Order/README.md b/solution/1800-1899/1839.Longest Substring Of All Vowels in Order/README.md index 7b5f3577b4c0e..6507428fb2346 100644 --- a/solution/1800-1899/1839.Longest Substring Of All Vowels in Order/README.md +++ b/solution/1800-1899/1839.Longest Substring Of All Vowels in Order/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def longestBeautifulSubstring(self, word: str) -> int: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestBeautifulSubstring(String word) { @@ -138,6 +142,8 @@ class Node { } ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go func longestBeautifulSubstring(word string) (ans int) { arr := []pair{} diff --git a/solution/1800-1899/1839.Longest Substring Of All Vowels in Order/README_EN.md b/solution/1800-1899/1839.Longest Substring Of All Vowels in Order/README_EN.md index 8e21b667f07a8..7e1c0490fb58e 100644 --- a/solution/1800-1899/1839.Longest Substring Of All Vowels in Order/README_EN.md +++ b/solution/1800-1899/1839.Longest Substring Of All Vowels in Order/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def longestBeautifulSubstring(self, word: str) -> int: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestBeautifulSubstring(String word) { @@ -136,6 +140,8 @@ class Node { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func longestBeautifulSubstring(word string) (ans int) { arr := []pair{} diff --git a/solution/1800-1899/1840.Maximum Building Height/README.md b/solution/1800-1899/1840.Maximum Building Height/README.md index 45f0fdd48ca6a..3aedfae1b5a73 100644 --- a/solution/1800-1899/1840.Maximum Building Height/README.md +++ b/solution/1800-1899/1840.Maximum Building Height/README.md @@ -98,6 +98,8 @@ tags: +#### Python3 + ```python class Solution: def maxBuilding(self, n: int, restrictions: List[List[int]]) -> int: @@ -118,6 +120,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxBuilding(int n, int[][] restrictions) { @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go func maxBuilding(n int, restrictions [][]int) (ans int) { r := restrictions diff --git a/solution/1800-1899/1840.Maximum Building Height/README_EN.md b/solution/1800-1899/1840.Maximum Building Height/README_EN.md index 192c93ff9dad6..159d23bf7b75e 100644 --- a/solution/1800-1899/1840.Maximum Building Height/README_EN.md +++ b/solution/1800-1899/1840.Maximum Building Height/README_EN.md @@ -84,6 +84,8 @@ We can build the buildings with heights [0,1,2,3,3,4,4,5,4,3], and the tallest b +#### Python3 + ```python class Solution: def maxBuilding(self, n: int, restrictions: List[List[int]]) -> int: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxBuilding(int n, int[][] restrictions) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func maxBuilding(n int, restrictions [][]int) (ans int) { r := restrictions diff --git a/solution/1800-1899/1841.League Statistics/README.md b/solution/1800-1899/1841.League Statistics/README.md index 4e8890b469637..03bbc59b8bcc4 100644 --- a/solution/1800-1899/1841.League Statistics/README.md +++ b/solution/1800-1899/1841.League Statistics/README.md @@ -115,6 +115,8 @@ Dortmund 是积分榜上的第一支球队. Ajax和Arsenal 有同样的分数, +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1800-1899/1841.League Statistics/README_EN.md b/solution/1800-1899/1841.League Statistics/README_EN.md index 1008f952ee9aa..81a07551b506f 100644 --- a/solution/1800-1899/1841.League Statistics/README_EN.md +++ b/solution/1800-1899/1841.League Statistics/README_EN.md @@ -115,6 +115,8 @@ Dortmund is the first team in the table. Ajax and Arsenal have the same points, +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1800-1899/1842.Next Palindrome Using Same Digits/README.md b/solution/1800-1899/1842.Next Palindrome Using Same Digits/README.md index a0497ebddec30..d2cd6b487546b 100644 --- a/solution/1800-1899/1842.Next Palindrome Using Same Digits/README.md +++ b/solution/1800-1899/1842.Next Palindrome Using Same Digits/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def nextPalindrome(self, num: str) -> str: @@ -98,6 +100,8 @@ class Solution: return "".join(nums) ``` +#### Java + ```java class Solution { public String nextPalindrome(String num) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func nextPalindrome(num string) string { nums := []byte(num) @@ -192,6 +200,8 @@ func nextPermutation(nums []byte) bool { } ``` +#### TypeScript + ```ts function nextPalindrome(num: string): string { const nums = num.split(''); diff --git a/solution/1800-1899/1842.Next Palindrome Using Same Digits/README_EN.md b/solution/1800-1899/1842.Next Palindrome Using Same Digits/README_EN.md index 34b4d8b08888c..71881b40e0139 100644 --- a/solution/1800-1899/1842.Next Palindrome Using Same Digits/README_EN.md +++ b/solution/1800-1899/1842.Next Palindrome Using Same Digits/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def nextPalindrome(self, num: str) -> str: @@ -96,6 +98,8 @@ class Solution: return "".join(nums) ``` +#### Java + ```java class Solution { public String nextPalindrome(String num) { @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func nextPalindrome(num string) string { nums := []byte(num) @@ -190,6 +198,8 @@ func nextPermutation(nums []byte) bool { } ``` +#### TypeScript + ```ts function nextPalindrome(num: string): string { const nums = num.split(''); diff --git a/solution/1800-1899/1843.Suspicious Bank Accounts/README.md b/solution/1800-1899/1843.Suspicious Bank Accounts/README.md index c28a293a4108c..b3dc4ed042e7a 100644 --- a/solution/1800-1899/1843.Suspicious Bank Accounts/README.md +++ b/solution/1800-1899/1843.Suspicious Bank Accounts/README.md @@ -115,6 +115,8 @@ Transactions 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -149,6 +151,8 @@ ORDER BY s1.tx; +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1800-1899/1843.Suspicious Bank Accounts/README_EN.md b/solution/1800-1899/1843.Suspicious Bank Accounts/README_EN.md index fd84482ff675a..8f4daa09c3702 100644 --- a/solution/1800-1899/1843.Suspicious Bank Accounts/README_EN.md +++ b/solution/1800-1899/1843.Suspicious Bank Accounts/README_EN.md @@ -115,6 +115,8 @@ We can see that the income exceeded the max income in May and July, but not in J +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -149,6 +151,8 @@ ORDER BY s1.tx; +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1800-1899/1844.Replace All Digits with Characters/README.md b/solution/1800-1899/1844.Replace All Digits with Characters/README.md index 2538ab6d88552..dba277222ae69 100644 --- a/solution/1800-1899/1844.Replace All Digits with Characters/README.md +++ b/solution/1800-1899/1844.Replace All Digits with Characters/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def replaceDigits(self, s: str) -> str: @@ -86,6 +88,8 @@ class Solution: return ''.join(s) ``` +#### Java + ```java class Solution { public String replaceDigits(String s) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func replaceDigits(s string) string { cs := []byte(s) @@ -121,6 +129,8 @@ func replaceDigits(s string) string { } ``` +#### TypeScript + ```ts function replaceDigits(s: string): string { const n = s.length; @@ -132,6 +142,8 @@ function replaceDigits(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn replace_digits(s: String) -> String { @@ -147,6 +159,8 @@ impl Solution { } ``` +#### C + ```c char* replaceDigits(char* s) { int n = strlen(s); diff --git a/solution/1800-1899/1844.Replace All Digits with Characters/README_EN.md b/solution/1800-1899/1844.Replace All Digits with Characters/README_EN.md index 74ddab9aee203..7f88677631ccc 100644 --- a/solution/1800-1899/1844.Replace All Digits with Characters/README_EN.md +++ b/solution/1800-1899/1844.Replace All Digits with Characters/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string $s$. Ignori +#### Python3 + ```python class Solution: def replaceDigits(self, s: str) -> str: @@ -86,6 +88,8 @@ class Solution: return ''.join(s) ``` +#### Java + ```java class Solution { public String replaceDigits(String s) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func replaceDigits(s string) string { cs := []byte(s) @@ -121,6 +129,8 @@ func replaceDigits(s string) string { } ``` +#### TypeScript + ```ts function replaceDigits(s: string): string { const n = s.length; @@ -132,6 +142,8 @@ function replaceDigits(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn replace_digits(s: String) -> String { @@ -147,6 +159,8 @@ impl Solution { } ``` +#### C + ```c char* replaceDigits(char* s) { int n = strlen(s); diff --git a/solution/1800-1899/1845.Seat Reservation Manager/README.md b/solution/1800-1899/1845.Seat Reservation Manager/README.md index 0678331af30b8..1ffce0d75d1f5 100644 --- a/solution/1800-1899/1845.Seat Reservation Manager/README.md +++ b/solution/1800-1899/1845.Seat Reservation Manager/README.md @@ -83,6 +83,8 @@ seatManager.unreserve(5); // 将座位 5 变为可以预约,现在可预约的 +#### Python3 + ```python class SeatManager: def __init__(self, n: int): @@ -102,6 +104,8 @@ class SeatManager: # obj.unreserve(seatNumber) ``` +#### Java + ```java class SeatManager { private PriorityQueue q = new PriorityQueue<>(); @@ -129,6 +133,8 @@ class SeatManager { */ ``` +#### C++ + ```cpp class SeatManager { public: @@ -160,6 +166,8 @@ private: */ ``` +#### Go + ```go type SeatManager struct { q hp @@ -200,6 +208,8 @@ func (h *hp) Pop() any { */ ``` +#### C# + ```cs public class SeatManager { private SortedSet availableSeats; diff --git a/solution/1800-1899/1845.Seat Reservation Manager/README_EN.md b/solution/1800-1899/1845.Seat Reservation Manager/README_EN.md index 8527771428004..c1606a9ee5c7b 100644 --- a/solution/1800-1899/1845.Seat Reservation Manager/README_EN.md +++ b/solution/1800-1899/1845.Seat Reservation Manager/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class SeatManager: def __init__(self, n: int): @@ -101,6 +103,8 @@ class SeatManager: # obj.unreserve(seatNumber) ``` +#### Java + ```java class SeatManager { private PriorityQueue q = new PriorityQueue<>(); @@ -128,6 +132,8 @@ class SeatManager { */ ``` +#### C++ + ```cpp class SeatManager { public: @@ -159,6 +165,8 @@ private: */ ``` +#### Go + ```go type SeatManager struct { q hp @@ -199,6 +207,8 @@ func (h *hp) Pop() any { */ ``` +#### C# + ```cs public class SeatManager { private SortedSet availableSeats; diff --git a/solution/1800-1899/1846.Maximum Element After Decreasing and Rearranging/README.md b/solution/1800-1899/1846.Maximum Element After Decreasing and Rearranging/README.md index 7b5be404af723..2e1597d002a90 100644 --- a/solution/1800-1899/1846.Maximum Element After Decreasing and Rearranging/README.md +++ b/solution/1800-1899/1846.Maximum Element After Decreasing and Rearranging/README.md @@ -97,6 +97,8 @@ arr 中最大元素为 3 。 +#### Python3 + ```python class Solution: def maximumElementAfterDecrementingAndRearranging(self, arr: List[int]) -> int: @@ -108,6 +110,8 @@ class Solution: return max(arr) ``` +#### Java + ```java class Solution { public int maximumElementAfterDecrementingAndRearranging(int[] arr) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func maximumElementAfterDecrementingAndRearranging(arr []int) int { sort.Ints(arr) @@ -155,6 +163,8 @@ func maximumElementAfterDecrementingAndRearranging(arr []int) int { } ``` +#### TypeScript + ```ts function maximumElementAfterDecrementingAndRearranging(arr: number[]): number { arr.sort((a, b) => a - b); @@ -169,6 +179,8 @@ function maximumElementAfterDecrementingAndRearranging(arr: number[]): number { } ``` +#### C# + ```cs public class Solution { public int MaximumElementAfterDecrementingAndRearranging(int[] arr) { diff --git a/solution/1800-1899/1846.Maximum Element After Decreasing and Rearranging/README_EN.md b/solution/1800-1899/1846.Maximum Element After Decreasing and Rearranging/README_EN.md index 4994b8c9c18c3..77d0a6e6d46fc 100644 --- a/solution/1800-1899/1846.Maximum Element After Decreasing and Rearranging/README_EN.md +++ b/solution/1800-1899/1846.Maximum Element After Decreasing and Rearranging/README_EN.md @@ -95,6 +95,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def maximumElementAfterDecrementingAndRearranging(self, arr: List[int]) -> int: @@ -106,6 +108,8 @@ class Solution: return max(arr) ``` +#### Java + ```java class Solution { public int maximumElementAfterDecrementingAndRearranging(int[] arr) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func maximumElementAfterDecrementingAndRearranging(arr []int) int { sort.Ints(arr) @@ -153,6 +161,8 @@ func maximumElementAfterDecrementingAndRearranging(arr []int) int { } ``` +#### TypeScript + ```ts function maximumElementAfterDecrementingAndRearranging(arr: number[]): number { arr.sort((a, b) => a - b); @@ -167,6 +177,8 @@ function maximumElementAfterDecrementingAndRearranging(arr: number[]): number { } ``` +#### C# + ```cs public class Solution { public int MaximumElementAfterDecrementingAndRearranging(int[] arr) { diff --git a/solution/1800-1899/1847.Closest Room/README.md b/solution/1800-1899/1847.Closest Room/README.md index 02c708b110adb..6c6fa76cd10a5 100644 --- a/solution/1800-1899/1847.Closest Room/README.md +++ b/solution/1800-1899/1847.Closest Room/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python from sortedcontainers import SortedList @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] closestRoom(int[][] rooms, int[][] queries) { @@ -158,6 +162,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -203,6 +209,8 @@ public: }; ``` +#### Go + ```go func closestRoom(rooms [][]int, queries [][]int) []int { n, k := len(rooms), len(queries) diff --git a/solution/1800-1899/1847.Closest Room/README_EN.md b/solution/1800-1899/1847.Closest Room/README_EN.md index 13982489e8f7b..47f55c2faae62 100644 --- a/solution/1800-1899/1847.Closest Room/README_EN.md +++ b/solution/1800-1899/1847.Closest Room/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n \times \log n + k \times \log k)$, and the space com +#### Python3 + ```python from sortedcontainers import SortedList @@ -113,6 +115,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] closestRoom(int[][] rooms, int[][] queries) { @@ -156,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -201,6 +207,8 @@ public: }; ``` +#### Go + ```go func closestRoom(rooms [][]int, queries [][]int) []int { n, k := len(rooms), len(queries) diff --git a/solution/1800-1899/1848.Minimum Distance to the Target Element/README.md b/solution/1800-1899/1848.Minimum Distance to the Target Element/README.md index a296faacf7d74..0a8d7383bd334 100644 --- a/solution/1800-1899/1848.Minimum Distance to the Target Element/README.md +++ b/solution/1800-1899/1848.Minimum Distance to the Target Element/README.md @@ -75,12 +75,16 @@ tags: +#### Python3 + ```python class Solution: def getMinDistance(self, nums: List[int], target: int, start: int) -> int: return min(abs(i - start) for i, x in enumerate(nums) if x == target) ``` +#### Java + ```java class Solution { public int getMinDistance(int[] nums, int target, int start) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func getMinDistance(nums []int, target int, start int) int { ans := 1 << 30 @@ -131,6 +139,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function getMinDistance(nums: number[], target: number, start: number): number { let ans = Infinity; @@ -143,6 +153,8 @@ function getMinDistance(nums: number[], target: number, start: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn get_min_distance(nums: Vec, target: i32, start: i32) -> i32 { diff --git a/solution/1800-1899/1848.Minimum Distance to the Target Element/README_EN.md b/solution/1800-1899/1848.Minimum Distance to the Target Element/README_EN.md index 4c0abbf1ca5ba..50d4752e3ecb6 100644 --- a/solution/1800-1899/1848.Minimum Distance to the Target Element/README_EN.md +++ b/solution/1800-1899/1848.Minimum Distance to the Target Element/README_EN.md @@ -73,12 +73,16 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def getMinDistance(self, nums: List[int], target: int, start: int) -> int: return min(abs(i - start) for i, x in enumerate(nums) if x == target) ``` +#### Java + ```java class Solution { public int getMinDistance(int[] nums, int target, int start) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func getMinDistance(nums []int, target int, start int) int { ans := 1 << 30 @@ -129,6 +137,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function getMinDistance(nums: number[], target: number, start: number): number { let ans = Infinity; @@ -141,6 +151,8 @@ function getMinDistance(nums: number[], target: number, start: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn get_min_distance(nums: Vec, target: i32, start: i32) -> i32 { diff --git a/solution/1800-1899/1849.Splitting a String Into Descending Consecutive Values/README.md b/solution/1800-1899/1849.Splitting a String Into Descending Consecutive Values/README.md index 5ae09c104f0ae..70c1ac5651f29 100644 --- a/solution/1800-1899/1849.Splitting a String Into Descending Consecutive Values/README.md +++ b/solution/1800-1899/1849.Splitting a String Into Descending Consecutive Values/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def splitString(self, s: str) -> bool: @@ -106,6 +108,8 @@ class Solution: return dfs(0, -1, 0) ``` +#### Java + ```java class Solution { private String s; @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func splitString(s string) bool { var dfs func(i, x, k int) bool diff --git a/solution/1800-1899/1849.Splitting a String Into Descending Consecutive Values/README_EN.md b/solution/1800-1899/1849.Splitting a String Into Descending Consecutive Values/README_EN.md index adbee0eb81ed5..86bb4bdd1a081 100644 --- a/solution/1800-1899/1849.Splitting a String Into Descending Consecutive Values/README_EN.md +++ b/solution/1800-1899/1849.Splitting a String Into Descending Consecutive Values/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$. Where $n$ i +#### Python3 + ```python class Solution: def splitString(self, s: str) -> bool: @@ -96,6 +98,8 @@ class Solution: return dfs(0, -1, 0) ``` +#### Java + ```java class Solution { private String s; @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func splitString(s string) bool { var dfs func(i, x, k int) bool diff --git a/solution/1800-1899/1850.Minimum Adjacent Swaps to Reach the Kth Smallest Number/README.md b/solution/1800-1899/1850.Minimum Adjacent Swaps to Reach the Kth Smallest Number/README.md index 548700136f334..19af0e831d21f 100644 --- a/solution/1800-1899/1850.Minimum Adjacent Swaps to Reach the Kth Smallest Number/README.md +++ b/solution/1800-1899/1850.Minimum Adjacent Swaps to Reach the Kth Smallest Number/README.md @@ -115,6 +115,8 @@ $$ +#### Python3 + ```python class Solution: def getMinSwaps(self, num: str, k: int) -> int: @@ -149,6 +151,8 @@ class Solution: return sum(arr[j] > arr[i] for i in range(n) for j in range(i)) ``` +#### Java + ```java class Solution { public int getMinSwaps(String num, int k) { @@ -206,6 +210,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -237,6 +243,8 @@ public: }; ``` +#### Go + ```go func getMinSwaps(num string, k int) (ans int) { s := []byte(num) @@ -287,6 +295,8 @@ func nextPermutation(nums []byte) bool { } ``` +#### TypeScript + ```ts function getMinSwaps(num: string, k: number): number { const n = num.length; diff --git a/solution/1800-1899/1850.Minimum Adjacent Swaps to Reach the Kth Smallest Number/README_EN.md b/solution/1800-1899/1850.Minimum Adjacent Swaps to Reach the Kth Smallest Number/README_EN.md index f296279432f61..3dd9bba8c4a12 100644 --- a/solution/1800-1899/1850.Minimum Adjacent Swaps to Reach the Kth Smallest Number/README_EN.md +++ b/solution/1800-1899/1850.Minimum Adjacent Swaps to Reach the Kth Smallest Number/README_EN.md @@ -116,6 +116,8 @@ The time complexity is $O(n \times (k + n))$, and the space complexity is $O(n)$ +#### Python3 + ```python class Solution: def getMinSwaps(self, num: str, k: int) -> int: @@ -150,6 +152,8 @@ class Solution: return sum(arr[j] > arr[i] for i in range(n) for j in range(i)) ``` +#### Java + ```java class Solution { public int getMinSwaps(String num, int k) { @@ -207,6 +211,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -238,6 +244,8 @@ public: }; ``` +#### Go + ```go func getMinSwaps(num string, k int) (ans int) { s := []byte(num) @@ -288,6 +296,8 @@ func nextPermutation(nums []byte) bool { } ``` +#### TypeScript + ```ts function getMinSwaps(num: string, k: number): number { const n = num.length; diff --git a/solution/1800-1899/1851.Minimum Interval to Include Each Query/README.md b/solution/1800-1899/1851.Minimum Interval to Include Each Query/README.md index d6012ab1b5659..5d54114cd67da 100644 --- a/solution/1800-1899/1851.Minimum Interval to Include Each Query/README.md +++ b/solution/1800-1899/1851.Minimum Interval to Include Each Query/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def minInterval(self, intervals: List[List[int]], queries: List[int]) -> List[int]: @@ -111,6 +113,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] minInterval(int[][] intervals, int[] queries) { @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go func minInterval(intervals [][]int, queries []int) []int { n, m := len(intervals), len(queries) diff --git a/solution/1800-1899/1851.Minimum Interval to Include Each Query/README_EN.md b/solution/1800-1899/1851.Minimum Interval to Include Each Query/README_EN.md index bc2c94b5fdad0..95d435d4a7bfe 100644 --- a/solution/1800-1899/1851.Minimum Interval to Include Each Query/README_EN.md +++ b/solution/1800-1899/1851.Minimum Interval to Include Each Query/README_EN.md @@ -88,6 +88,8 @@ The time complexity is $O(n \times \log n + m \times \log m)$, and the space com +#### Python3 + ```python class Solution: def minInterval(self, intervals: List[List[int]], queries: List[int]) -> List[int]: @@ -109,6 +111,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] minInterval(int[][] intervals, int[] queries) { @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func minInterval(intervals [][]int, queries []int) []int { n, m := len(intervals), len(queries) diff --git a/solution/1800-1899/1852.Distinct Numbers in Each Subarray/README.md b/solution/1800-1899/1852.Distinct Numbers in Each Subarray/README.md index feed9f4ade5c8..69ca36aced8d7 100644 --- a/solution/1800-1899/1852.Distinct Numbers in Each Subarray/README.md +++ b/solution/1800-1899/1852.Distinct Numbers in Each Subarray/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def distinctNumbers(self, nums: List[int], k: int) -> List[int]: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] distinctNumbers(int[] nums, int k) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func distinctNumbers(nums []int, k int) []int { cnt := map[int]int{} @@ -156,6 +164,8 @@ func distinctNumbers(nums []int, k int) []int { } ``` +#### TypeScript + ```ts function distinctNumbers(nums: number[], k: number): number[] { const cnt: Map = new Map(); @@ -189,6 +199,8 @@ function distinctNumbers(nums: number[], k: number): number[] { +#### Java + ```java class Solution { public int[] distinctNumbers(int[] nums, int k) { @@ -220,6 +232,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -250,6 +264,8 @@ public: }; ``` +#### Go + ```go func distinctNumbers(nums []int, k int) (ans []int) { m := slices.Max(nums) @@ -277,6 +293,8 @@ func distinctNumbers(nums []int, k int) (ans []int) { } ``` +#### TypeScript + ```ts function distinctNumbers(nums: number[], k: number): number[] { const m = Math.max(...nums); diff --git a/solution/1800-1899/1852.Distinct Numbers in Each Subarray/README_EN.md b/solution/1800-1899/1852.Distinct Numbers in Each Subarray/README_EN.md index 459037c32717d..83f25f5b5d2f9 100644 --- a/solution/1800-1899/1852.Distinct Numbers in Each Subarray/README_EN.md +++ b/solution/1800-1899/1852.Distinct Numbers in Each Subarray/README_EN.md @@ -98,6 +98,8 @@ The time complexity is $O(n)$, and the space complexity is $O(k)$. Where $n$ is +#### Python3 + ```python class Solution: def distinctNumbers(self, nums: List[int], k: int) -> List[int]: @@ -112,6 +114,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] distinctNumbers(int[] nums, int k) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func distinctNumbers(nums []int, k int) []int { cnt := map[int]int{} @@ -176,6 +184,8 @@ func distinctNumbers(nums []int, k int) []int { } ``` +#### TypeScript + ```ts function distinctNumbers(nums: number[], k: number): number[] { const cnt: Map = new Map(); @@ -209,6 +219,8 @@ The time complexity is $O(n)$, and the space complexity is $O(M)$. Where $n$ is +#### Java + ```java class Solution { public int[] distinctNumbers(int[] nums, int k) { @@ -240,6 +252,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -270,6 +284,8 @@ public: }; ``` +#### Go + ```go func distinctNumbers(nums []int, k int) (ans []int) { m := slices.Max(nums) @@ -297,6 +313,8 @@ func distinctNumbers(nums []int, k int) (ans []int) { } ``` +#### TypeScript + ```ts function distinctNumbers(nums: number[], k: number): number[] { const m = Math.max(...nums); diff --git a/solution/1800-1899/1853.Convert Date Format/README.md b/solution/1800-1899/1853.Convert Date Format/README.md index 31a985378c708..48439d842b9c0 100644 --- a/solution/1800-1899/1853.Convert Date Format/README.md +++ b/solution/1800-1899/1853.Convert Date Format/README.md @@ -69,6 +69,8 @@ Days table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT DATE_FORMAT(day, '%W, %M %e, %Y') AS day FROM Days; diff --git a/solution/1800-1899/1853.Convert Date Format/README_EN.md b/solution/1800-1899/1853.Convert Date Format/README_EN.md index 5036d02fdd729..e3c9d7c8302fc 100644 --- a/solution/1800-1899/1853.Convert Date Format/README_EN.md +++ b/solution/1800-1899/1853.Convert Date Format/README_EN.md @@ -69,6 +69,8 @@ Days table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT DATE_FORMAT(day, '%W, %M %e, %Y') AS day FROM Days; diff --git a/solution/1800-1899/1854.Maximum Population Year/README.md b/solution/1800-1899/1854.Maximum Population Year/README.md index 7765729fc59e7..2b4e5fcf90636 100644 --- a/solution/1800-1899/1854.Maximum Population Year/README.md +++ b/solution/1800-1899/1854.Maximum Population Year/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def maximumPopulation(self, logs: List[List[int]]) -> int: @@ -85,6 +87,8 @@ class Solution: return j + offset ``` +#### Java + ```java class Solution { public int maximumPopulation(int[][] logs) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func maximumPopulation(logs [][]int) int { d := [101]int{} @@ -157,6 +165,8 @@ func maximumPopulation(logs [][]int) int { } ``` +#### TypeScript + ```ts function maximumPopulation(logs: number[][]): number { const d: number[] = new Array(101).fill(0); @@ -177,6 +187,8 @@ function maximumPopulation(logs: number[][]): number { } ``` +#### JavaScript + ```js /** * @param {number[][]} logs diff --git a/solution/1800-1899/1854.Maximum Population Year/README_EN.md b/solution/1800-1899/1854.Maximum Population Year/README_EN.md index e653662261a0f..2a54e6920aaa5 100644 --- a/solution/1800-1899/1854.Maximum Population Year/README_EN.md +++ b/solution/1800-1899/1854.Maximum Population Year/README_EN.md @@ -68,6 +68,8 @@ The time complexity is $O(n)$, and the space complexity is $O(C)$. Where $n$ is +#### Python3 + ```python class Solution: def maximumPopulation(self, logs: List[List[int]]) -> int: @@ -85,6 +87,8 @@ class Solution: return j + offset ``` +#### Java + ```java class Solution { public int maximumPopulation(int[][] logs) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func maximumPopulation(logs [][]int) int { d := [101]int{} @@ -157,6 +165,8 @@ func maximumPopulation(logs [][]int) int { } ``` +#### TypeScript + ```ts function maximumPopulation(logs: number[][]): number { const d: number[] = new Array(101).fill(0); @@ -177,6 +187,8 @@ function maximumPopulation(logs: number[][]): number { } ``` +#### JavaScript + ```js /** * @param {number[][]} logs diff --git a/solution/1800-1899/1855.Maximum Distance Between a Pair of Values/README.md b/solution/1800-1899/1855.Maximum Distance Between a Pair of Values/README.md index a8513aa1acaf7..fda003f7e435c 100644 --- a/solution/1800-1899/1855.Maximum Distance Between a Pair of Values/README.md +++ b/solution/1800-1899/1855.Maximum Distance Between a Pair of Values/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def maxDistance(self, nums1: List[int], nums2: List[int]) -> int: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxDistance(int[] nums1, int[] nums2) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func maxDistance(nums1 []int, nums2 []int) int { ans, n := 0, len(nums2) @@ -152,6 +160,8 @@ func maxDistance(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function maxDistance(nums1: number[], nums2: number[]): number { let ans = 0; @@ -174,6 +184,8 @@ function maxDistance(nums1: number[], nums2: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_distance(nums1: Vec, nums2: Vec) -> i32 { @@ -198,6 +210,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums1 @@ -239,6 +253,8 @@ var maxDistance = function (nums1, nums2) { +#### Python3 + ```python class Solution: def maxDistance(self, nums1: List[int], nums2: List[int]) -> int: @@ -252,6 +268,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxDistance(int[] nums1, int[] nums2) { @@ -268,6 +286,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -285,6 +305,8 @@ public: }; ``` +#### Go + ```go func maxDistance(nums1 []int, nums2 []int) int { m, n := len(nums1), len(nums2) @@ -301,6 +323,8 @@ func maxDistance(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function maxDistance(nums1: number[], nums2: number[]): number { let ans = 0; @@ -316,6 +340,8 @@ function maxDistance(nums1: number[], nums2: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_distance(nums1: Vec, nums2: Vec) -> i32 { @@ -334,6 +360,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums1 diff --git a/solution/1800-1899/1855.Maximum Distance Between a Pair of Values/README_EN.md b/solution/1800-1899/1855.Maximum Distance Between a Pair of Values/README_EN.md index 559db85f810ac..3d12d931dece6 100644 --- a/solution/1800-1899/1855.Maximum Distance Between a Pair of Values/README_EN.md +++ b/solution/1800-1899/1855.Maximum Distance Between a Pair of Values/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(m \times \log n)$, where $m$ and $n$ are the lengths o +#### Python3 + ```python class Solution: def maxDistance(self, nums1: List[int], nums2: List[int]) -> int: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxDistance(int[] nums1, int[] nums2) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func maxDistance(nums1 []int, nums2 []int) int { ans, n := 0, len(nums2) @@ -150,6 +158,8 @@ func maxDistance(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function maxDistance(nums1: number[], nums2: number[]): number { let ans = 0; @@ -172,6 +182,8 @@ function maxDistance(nums1: number[], nums2: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_distance(nums1: Vec, nums2: Vec) -> i32 { @@ -196,6 +208,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums1 @@ -233,6 +247,8 @@ var maxDistance = function (nums1, nums2) { +#### Python3 + ```python class Solution: def maxDistance(self, nums1: List[int], nums2: List[int]) -> int: @@ -246,6 +262,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxDistance(int[] nums1, int[] nums2) { @@ -262,6 +280,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -279,6 +299,8 @@ public: }; ``` +#### Go + ```go func maxDistance(nums1 []int, nums2 []int) int { m, n := len(nums1), len(nums2) @@ -295,6 +317,8 @@ func maxDistance(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function maxDistance(nums1: number[], nums2: number[]): number { let ans = 0; @@ -310,6 +334,8 @@ function maxDistance(nums1: number[], nums2: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_distance(nums1: Vec, nums2: Vec) -> i32 { @@ -328,6 +354,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums1 diff --git a/solution/1800-1899/1856.Maximum Subarray Min-Product/README.md b/solution/1800-1899/1856.Maximum Subarray Min-Product/README.md index f7aca4c2d1702..850bbd883a037 100644 --- a/solution/1800-1899/1856.Maximum Subarray Min-Product/README.md +++ b/solution/1800-1899/1856.Maximum Subarray Min-Product/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def maxSumMinProduct(self, nums: List[int]) -> int: @@ -114,6 +116,8 @@ class Solution: return max((s[right[i]] - s[left[i] + 1]) * x for i, x in enumerate(nums)) % mod ``` +#### Java + ```java class Solution { public int maxSumMinProduct(int[] nums) { @@ -156,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -198,6 +204,8 @@ public: }; ``` +#### Go + ```go func maxSumMinProduct(nums []int) int { n := len(nums) @@ -242,6 +250,8 @@ func maxSumMinProduct(nums []int) int { } ``` +#### TypeScript + ```ts function maxSumMinProduct(nums: number[]): number { const n = nums.length; diff --git a/solution/1800-1899/1856.Maximum Subarray Min-Product/README_EN.md b/solution/1800-1899/1856.Maximum Subarray Min-Product/README_EN.md index 2b01c934741ae..5277240fab092 100644 --- a/solution/1800-1899/1856.Maximum Subarray Min-Product/README_EN.md +++ b/solution/1800-1899/1856.Maximum Subarray Min-Product/README_EN.md @@ -87,6 +87,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def maxSumMinProduct(self, nums: List[int]) -> int: @@ -112,6 +114,8 @@ class Solution: return max((s[right[i]] - s[left[i] + 1]) * x for i, x in enumerate(nums)) % mod ``` +#### Java + ```java class Solution { public int maxSumMinProduct(int[] nums) { @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -196,6 +202,8 @@ public: }; ``` +#### Go + ```go func maxSumMinProduct(nums []int) int { n := len(nums) @@ -240,6 +248,8 @@ func maxSumMinProduct(nums []int) int { } ``` +#### TypeScript + ```ts function maxSumMinProduct(nums: number[]): number { const n = nums.length; diff --git a/solution/1800-1899/1857.Largest Color Value in a Directed Graph/README.md b/solution/1800-1899/1857.Largest Color Value in a Directed Graph/README.md index 50ee2ac718e85..d252ef7e74def 100644 --- a/solution/1800-1899/1857.Largest Color Value in a Directed Graph/README.md +++ b/solution/1800-1899/1857.Largest Color Value in a Directed Graph/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def largestPathValue(self, colors: str, edges: List[List[int]]) -> int: @@ -110,6 +112,8 @@ class Solution: return -1 if cnt < n else ans ``` +#### Java + ```java class Solution { public int largestPathValue(String colors, int[][] edges) { @@ -152,6 +156,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go func largestPathValue(colors string, edges [][]int) int { n := len(colors) diff --git a/solution/1800-1899/1857.Largest Color Value in a Directed Graph/README_EN.md b/solution/1800-1899/1857.Largest Color Value in a Directed Graph/README_EN.md index 44753737ce14f..d90b69df177ce 100644 --- a/solution/1800-1899/1857.Largest Color Value in a Directed Graph/README_EN.md +++ b/solution/1800-1899/1857.Largest Color Value in a Directed Graph/README_EN.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def largestPathValue(self, colors: str, edges: List[List[int]]) -> int: @@ -123,6 +125,8 @@ class Solution: return -1 if cnt < n else ans ``` +#### Java + ```java class Solution { public int largestPathValue(String colors, int[][] edges) { @@ -165,6 +169,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -206,6 +212,8 @@ public: }; ``` +#### Go + ```go func largestPathValue(colors string, edges [][]int) int { n := len(colors) diff --git a/solution/1800-1899/1858.Longest Word With All Prefixes/README.md b/solution/1800-1899/1858.Longest Word With All Prefixes/README.md index 5edfc42e9e07f..98319b2b037cc 100644 --- a/solution/1800-1899/1858.Longest Word With All Prefixes/README.md +++ b/solution/1800-1899/1858.Longest Word With All Prefixes/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Trie: __slots__ = ["children", "is_end"] @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java class Trie { private Trie[] children = new Trie[26]; @@ -166,6 +170,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { private: @@ -220,6 +226,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [26]*Trie @@ -269,6 +277,8 @@ func longestWord(words []string) string { } ``` +#### TypeScript + ```ts class Trie { private children: (Trie | null)[] = Array(26).fill(null); @@ -314,6 +324,8 @@ function longestWord(words: string[]): string { } ``` +#### Rust + ```rust struct Trie { children: [Option>; 26], @@ -369,6 +381,8 @@ impl Solution { } ``` +#### C# + ```cs public class Trie { private Trie[] children = new Trie[26]; diff --git a/solution/1800-1899/1858.Longest Word With All Prefixes/README_EN.md b/solution/1800-1899/1858.Longest Word With All Prefixes/README_EN.md index 3a5aa97473784..05dd57c29e9c6 100644 --- a/solution/1800-1899/1858.Longest Word With All Prefixes/README_EN.md +++ b/solution/1800-1899/1858.Longest Word With All Prefixes/README_EN.md @@ -97,6 +97,8 @@ The time complexity is $O(\sum_{w \in words} |w|)$, and the space complexity is +#### Python3 + ```python class Trie: __slots__ = ["children", "is_end"] @@ -136,6 +138,8 @@ class Solution: return ans ``` +#### Java + ```java class Trie { private Trie[] children = new Trie[26]; @@ -187,6 +191,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { private: @@ -241,6 +247,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [26]*Trie @@ -290,6 +298,8 @@ func longestWord(words []string) string { } ``` +#### TypeScript + ```ts class Trie { private children: (Trie | null)[] = Array(26).fill(null); @@ -335,6 +345,8 @@ function longestWord(words: string[]): string { } ``` +#### Rust + ```rust struct Trie { children: [Option>; 26], @@ -390,6 +402,8 @@ impl Solution { } ``` +#### C# + ```cs public class Trie { private Trie[] children = new Trie[26]; diff --git a/solution/1800-1899/1859.Sorting the Sentence/README.md b/solution/1800-1899/1859.Sorting the Sentence/README.md index 60d5b957a5d02..d48140da04a01 100644 --- a/solution/1800-1899/1859.Sorting the Sentence/README.md +++ b/solution/1800-1899/1859.Sorting the Sentence/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def sortSentence(self, s: str) -> str: @@ -84,6 +86,8 @@ class Solution: return ' '.join(w for w, _ in ws) ``` +#### Java + ```java class Solution { public String sortSentence(String s) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func sortSentence(s string) string { ws := strings.Split(s, " ") @@ -134,6 +142,8 @@ func sortSentence(s string) string { } ``` +#### TypeScript + ```ts function sortSentence(s: string): string { const ws = s.split(' '); @@ -145,6 +155,8 @@ function sortSentence(s: string): string { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -170,6 +182,8 @@ var sortSentence = function (s) { +#### Python3 + ```python class Solution: def sortSentence(self, s: str) -> str: diff --git a/solution/1800-1899/1859.Sorting the Sentence/README_EN.md b/solution/1800-1899/1859.Sorting the Sentence/README_EN.md index 642c667f1672e..b859d1d2ad743 100644 --- a/solution/1800-1899/1859.Sorting the Sentence/README_EN.md +++ b/solution/1800-1899/1859.Sorting the Sentence/README_EN.md @@ -93,6 +93,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def sortSentence(self, s: str) -> str: @@ -101,6 +103,8 @@ class Solution: return ' '.join(w for w, _ in ws) ``` +#### Java + ```java class Solution { public String sortSentence(String s) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func sortSentence(s string) string { ws := strings.Split(s, " ") @@ -151,6 +159,8 @@ func sortSentence(s string) string { } ``` +#### TypeScript + ```ts function sortSentence(s: string): string { const ws = s.split(' '); @@ -162,6 +172,8 @@ function sortSentence(s: string): string { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -187,6 +199,8 @@ var sortSentence = function (s) { +#### Python3 + ```python class Solution: def sortSentence(self, s: str) -> str: diff --git a/solution/1800-1899/1860.Incremental Memory Leak/README.md b/solution/1800-1899/1860.Incremental Memory Leak/README.md index 340109e976f04..1db49a9350b8c 100644 --- a/solution/1800-1899/1860.Incremental Memory Leak/README.md +++ b/solution/1800-1899/1860.Incremental Memory Leak/README.md @@ -78,6 +78,8 @@ $$ +#### Python3 + ```python class Solution: def memLeak(self, memory1: int, memory2: int) -> List[int]: @@ -91,6 +93,8 @@ class Solution: return [i, memory1, memory2] ``` +#### Java + ```java class Solution { public int[] memLeak(int memory1, int memory2) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func memLeak(memory1 int, memory2 int) []int { i := 1 @@ -138,6 +146,8 @@ func memLeak(memory1 int, memory2 int) []int { } ``` +#### TypeScript + ```ts function memLeak(memory1: number, memory2: number): number[] { let i = 1; @@ -152,6 +162,8 @@ function memLeak(memory1: number, memory2: number): number[] { } ``` +#### JavaScript + ```js /** * @param {number} memory1 diff --git a/solution/1800-1899/1860.Incremental Memory Leak/README_EN.md b/solution/1800-1899/1860.Incremental Memory Leak/README_EN.md index 938ffcb0613b1..81f6b77e2a786 100644 --- a/solution/1800-1899/1860.Incremental Memory Leak/README_EN.md +++ b/solution/1800-1899/1860.Incremental Memory Leak/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(\sqrt{m_1+m_2})$, where $m_1$ and $m_2$ are the sizes +#### Python3 + ```python class Solution: def memLeak(self, memory1: int, memory2: int) -> List[int]: @@ -91,6 +93,8 @@ class Solution: return [i, memory1, memory2] ``` +#### Java + ```java class Solution { public int[] memLeak(int memory1, int memory2) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func memLeak(memory1 int, memory2 int) []int { i := 1 @@ -138,6 +146,8 @@ func memLeak(memory1 int, memory2 int) []int { } ``` +#### TypeScript + ```ts function memLeak(memory1: number, memory2: number): number[] { let i = 1; @@ -152,6 +162,8 @@ function memLeak(memory1: number, memory2: number): number[] { } ``` +#### JavaScript + ```js /** * @param {number} memory1 diff --git a/solution/1800-1899/1861.Rotating the Box/README.md b/solution/1800-1899/1861.Rotating the Box/README.md index 4f12682faa4ec..d8b5644af7adb 100644 --- a/solution/1800-1899/1861.Rotating the Box/README.md +++ b/solution/1800-1899/1861.Rotating the Box/README.md @@ -98,6 +98,8 @@ tags: +#### Python3 + ```python class Solution: def rotateTheBox(self, box: List[List[str]]) -> List[List[str]]: @@ -120,6 +122,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public char[][] rotateTheBox(char[][] box) { @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func rotateTheBox(box [][]byte) [][]byte { m, n := len(box), len(box[0]) diff --git a/solution/1800-1899/1861.Rotating the Box/README_EN.md b/solution/1800-1899/1861.Rotating the Box/README_EN.md index 51a213a425969..9c61ff85d9f6c 100644 --- a/solution/1800-1899/1861.Rotating the Box/README_EN.md +++ b/solution/1800-1899/1861.Rotating the Box/README_EN.md @@ -132,6 +132,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def rotateTheBox(self, box: List[List[str]]) -> List[List[str]]: @@ -154,6 +156,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public char[][] rotateTheBox(char[][] box) { @@ -183,6 +187,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -215,6 +221,8 @@ public: }; ``` +#### Go + ```go func rotateTheBox(box [][]byte) [][]byte { m, n := len(box), len(box[0]) diff --git a/solution/1800-1899/1862.Sum of Floored Pairs/README.md b/solution/1800-1899/1862.Sum of Floored Pairs/README.md index 82574450d1f2b..2ce2bb38bfa37 100644 --- a/solution/1800-1899/1862.Sum of Floored Pairs/README.md +++ b/solution/1800-1899/1862.Sum of Floored Pairs/README.md @@ -71,6 +71,8 @@ floor(9 / 5) = 1 +#### Python3 + ```python class Solution: def sumOfFlooredPairs(self, nums: List[int]) -> int: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int sumOfFlooredPairs(int[] nums) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func sumOfFlooredPairs(nums []int) (ans int) { mx := slices.Max(nums) @@ -173,6 +181,8 @@ func sumOfFlooredPairs(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function sumOfFlooredPairs(nums: number[]): number { const mx = Math.max(...nums); @@ -198,6 +208,8 @@ function sumOfFlooredPairs(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn sum_of_floored_pairs(nums: Vec) -> i32 { diff --git a/solution/1800-1899/1862.Sum of Floored Pairs/README_EN.md b/solution/1800-1899/1862.Sum of Floored Pairs/README_EN.md index 8342c1b97f946..f417acf577ec2 100644 --- a/solution/1800-1899/1862.Sum of Floored Pairs/README_EN.md +++ b/solution/1800-1899/1862.Sum of Floored Pairs/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(M \times \log M)$, and the space complexity is $O(M)$. +#### Python3 + ```python class Solution: def sumOfFlooredPairs(self, nums: List[int]) -> int: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int sumOfFlooredPairs(int[] nums) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func sumOfFlooredPairs(nums []int) (ans int) { mx := slices.Max(nums) @@ -173,6 +181,8 @@ func sumOfFlooredPairs(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function sumOfFlooredPairs(nums: number[]): number { const mx = Math.max(...nums); @@ -198,6 +208,8 @@ function sumOfFlooredPairs(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn sum_of_floored_pairs(nums: Vec) -> i32 { diff --git a/solution/1800-1899/1863.Sum of All Subset XOR Totals/README.md b/solution/1800-1899/1863.Sum of All Subset XOR Totals/README.md index b294e2310a1ae..f22b4aa19c6d9 100644 --- a/solution/1800-1899/1863.Sum of All Subset XOR Totals/README.md +++ b/solution/1800-1899/1863.Sum of All Subset XOR Totals/README.md @@ -97,6 +97,8 @@ tags: +#### Python3 + ```python class Solution: def subsetXORSum(self, nums: List[int]) -> int: @@ -110,6 +112,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int subsetXORSum(int[] nums) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func subsetXORSum(nums []int) (ans int) { n := len(nums) @@ -165,6 +173,8 @@ func subsetXORSum(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function subsetXORSum(nums: number[]): number { let ans = 0; @@ -182,6 +192,8 @@ function subsetXORSum(nums: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -224,6 +236,8 @@ var subsetXORSum = function (nums) { +#### Python3 + ```python class Solution: def subsetXORSum(self, nums: List[int]) -> int: @@ -240,6 +254,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int ans; @@ -262,6 +278,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -282,6 +300,8 @@ public: }; ``` +#### Go + ```go func subsetXORSum(nums []int) (ans int) { n := len(nums) @@ -299,6 +319,8 @@ func subsetXORSum(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function subsetXORSum(nums: number[]): number { let ans = 0; @@ -316,6 +338,8 @@ function subsetXORSum(nums: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/1800-1899/1863.Sum of All Subset XOR Totals/README_EN.md b/solution/1800-1899/1863.Sum of All Subset XOR Totals/README_EN.md index 867064163caa6..bc3a6bf834e85 100644 --- a/solution/1800-1899/1863.Sum of All Subset XOR Totals/README_EN.md +++ b/solution/1800-1899/1863.Sum of All Subset XOR Totals/README_EN.md @@ -98,6 +98,8 @@ The time complexity is $O(n \times 2^n)$, where $n$ is the length of the array $ +#### Python3 + ```python class Solution: def subsetXORSum(self, nums: List[int]) -> int: @@ -111,6 +113,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int subsetXORSum(int[] nums) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func subsetXORSum(nums []int) (ans int) { n := len(nums) @@ -166,6 +174,8 @@ func subsetXORSum(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function subsetXORSum(nums: number[]): number { let ans = 0; @@ -183,6 +193,8 @@ function subsetXORSum(nums: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -225,6 +237,8 @@ The time complexity is $O(2^n)$, and the space complexity is $O(n)$. Where $n$ i +#### Python3 + ```python class Solution: def subsetXORSum(self, nums: List[int]) -> int: @@ -241,6 +255,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int ans; @@ -263,6 +279,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -283,6 +301,8 @@ public: }; ``` +#### Go + ```go func subsetXORSum(nums []int) (ans int) { n := len(nums) @@ -300,6 +320,8 @@ func subsetXORSum(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function subsetXORSum(nums: number[]): number { let ans = 0; @@ -317,6 +339,8 @@ function subsetXORSum(nums: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/1800-1899/1864.Minimum Number of Swaps to Make the Binary String Alternating/README.md b/solution/1800-1899/1864.Minimum Number of Swaps to Make the Binary String Alternating/README.md index a98b7282dc297..c90312362f22c 100644 --- a/solution/1800-1899/1864.Minimum Number of Swaps to Make the Binary String Alternating/README.md +++ b/solution/1800-1899/1864.Minimum Number of Swaps to Make the Binary String Alternating/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def minSwaps(self, s: str) -> int: @@ -93,6 +95,8 @@ class Solution: return min(s0n0, s1n0) ``` +#### Java + ```java class Solution { public int minSwaps(String s) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### JavaScript + ```js /** * @param {string} s diff --git a/solution/1800-1899/1864.Minimum Number of Swaps to Make the Binary String Alternating/README_EN.md b/solution/1800-1899/1864.Minimum Number of Swaps to Make the Binary String Alternating/README_EN.md index 7ac5335005ab5..2891902845c01 100644 --- a/solution/1800-1899/1864.Minimum Number of Swaps to Make the Binary String Alternating/README_EN.md +++ b/solution/1800-1899/1864.Minimum Number of Swaps to Make the Binary String Alternating/README_EN.md @@ -68,6 +68,8 @@ The string is now alternating. +#### Python3 + ```python class Solution: def minSwaps(self, s: str) -> int: @@ -92,6 +94,8 @@ class Solution: return min(s0n0, s1n0) ``` +#### Java + ```java class Solution { public int minSwaps(String s) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### JavaScript + ```js /** * @param {string} s diff --git a/solution/1800-1899/1865.Finding Pairs With a Certain Sum/README.md b/solution/1800-1899/1865.Finding Pairs With a Certain Sum/README.md index afcd7c3e2bac2..86e8c527a7aae 100644 --- a/solution/1800-1899/1865.Finding Pairs With a Certain Sum/README.md +++ b/solution/1800-1899/1865.Finding Pairs With a Certain Sum/README.md @@ -90,6 +90,8 @@ findSumPairs.count(7); // 返回 11 ;下标对 (2,1), (2,2), (2,4), (3,1), (3 +#### Python3 + ```python class FindSumPairs: def __init__(self, nums1: List[int], nums2: List[int]): @@ -113,6 +115,8 @@ class FindSumPairs: # param_2 = obj.count(tot) ``` +#### Java + ```java class FindSumPairs { private int[] nums1; @@ -151,6 +155,8 @@ class FindSumPairs { */ ``` +#### C++ + ```cpp class FindSumPairs { public: @@ -191,6 +197,8 @@ private: */ ``` +#### Go + ```go type FindSumPairs struct { nums1 []int diff --git a/solution/1800-1899/1865.Finding Pairs With a Certain Sum/README_EN.md b/solution/1800-1899/1865.Finding Pairs With a Certain Sum/README_EN.md index a3201cf963d2a..036e96217617f 100644 --- a/solution/1800-1899/1865.Finding Pairs With a Certain Sum/README_EN.md +++ b/solution/1800-1899/1865.Finding Pairs With a Certain Sum/README_EN.md @@ -80,6 +80,8 @@ findSumPairs.count(7); // return 11; pairs (2,1), (2,2), (2,4), (3,1), (3,2), ( +#### Python3 + ```python class FindSumPairs: def __init__(self, nums1: List[int], nums2: List[int]): @@ -103,6 +105,8 @@ class FindSumPairs: # param_2 = obj.count(tot) ``` +#### Java + ```java class FindSumPairs { private int[] nums1; @@ -141,6 +145,8 @@ class FindSumPairs { */ ``` +#### C++ + ```cpp class FindSumPairs { public: @@ -181,6 +187,8 @@ private: */ ``` +#### Go + ```go type FindSumPairs struct { nums1 []int diff --git a/solution/1800-1899/1866.Number of Ways to Rearrange Sticks With K Sticks Visible/README.md b/solution/1800-1899/1866.Number of Ways to Rearrange Sticks With K Sticks Visible/README.md index a3c885544e369..d7e1502eda2c8 100644 --- a/solution/1800-1899/1866.Number of Ways to Rearrange Sticks With K Sticks Visible/README.md +++ b/solution/1800-1899/1866.Number of Ways to Rearrange Sticks With K Sticks Visible/README.md @@ -88,6 +88,8 @@ $$ +#### Python3 + ```python class Solution: def rearrangeSticks(self, n: int, k: int) -> int: @@ -100,6 +102,8 @@ class Solution: return f[n][k] ``` +#### Java + ```java class Solution { public int rearrangeSticks(int n, int k) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func rearrangeSticks(n int, k int) int { const mod = 1e9 + 7 @@ -151,6 +159,8 @@ func rearrangeSticks(n int, k int) int { } ``` +#### TypeScript + ```ts function rearrangeSticks(n: number, k: number): number { const mod = 10 ** 9 + 7; @@ -177,6 +187,8 @@ function rearrangeSticks(n: number, k: number): number { +#### Python3 + ```python class Solution: def rearrangeSticks(self, n: int, k: int) -> int: @@ -189,6 +201,8 @@ class Solution: return f[k] ``` +#### Java + ```java class Solution { public int rearrangeSticks(int n, int k) { @@ -206,6 +220,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -225,6 +241,8 @@ public: }; ``` +#### Go + ```go func rearrangeSticks(n int, k int) int { const mod = 1e9 + 7 @@ -240,6 +258,8 @@ func rearrangeSticks(n int, k int) int { } ``` +#### TypeScript + ```ts function rearrangeSticks(n: number, k: number): number { const mod = 10 ** 9 + 7; diff --git a/solution/1800-1899/1866.Number of Ways to Rearrange Sticks With K Sticks Visible/README_EN.md b/solution/1800-1899/1866.Number of Ways to Rearrange Sticks With K Sticks Visible/README_EN.md index cfa570aee6975..25b5d022febd3 100644 --- a/solution/1800-1899/1866.Number of Ways to Rearrange Sticks With K Sticks Visible/README_EN.md +++ b/solution/1800-1899/1866.Number of Ways to Rearrange Sticks With K Sticks Visible/README_EN.md @@ -89,6 +89,8 @@ The time complexity is $O(n \times k)$, and the space complexity is $O(k)$. Here +#### Python3 + ```python class Solution: def rearrangeSticks(self, n: int, k: int) -> int: @@ -101,6 +103,8 @@ class Solution: return f[n][k] ``` +#### Java + ```java class Solution { public int rearrangeSticks(int n, int k) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func rearrangeSticks(n int, k int) int { const mod = 1e9 + 7 @@ -152,6 +160,8 @@ func rearrangeSticks(n int, k int) int { } ``` +#### TypeScript + ```ts function rearrangeSticks(n: number, k: number): number { const mod = 10 ** 9 + 7; @@ -178,6 +188,8 @@ function rearrangeSticks(n: number, k: number): number { +#### Python3 + ```python class Solution: def rearrangeSticks(self, n: int, k: int) -> int: @@ -190,6 +202,8 @@ class Solution: return f[k] ``` +#### Java + ```java class Solution { public int rearrangeSticks(int n, int k) { @@ -207,6 +221,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -226,6 +242,8 @@ public: }; ``` +#### Go + ```go func rearrangeSticks(n int, k int) int { const mod = 1e9 + 7 @@ -241,6 +259,8 @@ func rearrangeSticks(n int, k int) int { } ``` +#### TypeScript + ```ts function rearrangeSticks(n: number, k: number): number { const mod = 10 ** 9 + 7; diff --git a/solution/1800-1899/1867.Orders With Maximum Quantity Above Average/README.md b/solution/1800-1899/1867.Orders With Maximum Quantity Above Average/README.md index a76effa983ed4..8f70798d8087a 100644 --- a/solution/1800-1899/1867.Orders With Maximum Quantity Above Average/README.md +++ b/solution/1800-1899/1867.Orders With Maximum Quantity Above Average/README.md @@ -103,6 +103,8 @@ OrdersDetails 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1800-1899/1867.Orders With Maximum Quantity Above Average/README_EN.md b/solution/1800-1899/1867.Orders With Maximum Quantity Above Average/README_EN.md index 78321e4023e7b..f48d01e4de39e 100644 --- a/solution/1800-1899/1867.Orders With Maximum Quantity Above Average/README_EN.md +++ b/solution/1800-1899/1867.Orders With Maximum Quantity Above Average/README_EN.md @@ -102,6 +102,8 @@ Orders 1 and 3 are imbalanced because they have a maximum quantity that exceeds +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1800-1899/1868.Product of Two Run-Length Encoded Arrays/README.md b/solution/1800-1899/1868.Product of Two Run-Length Encoded Arrays/README.md index e7d9c75995013..c0608640bd42b 100644 --- a/solution/1800-1899/1868.Product of Two Run-Length Encoded Arrays/README.md +++ b/solution/1800-1899/1868.Product of Two Run-Length Encoded Arrays/README.md @@ -86,6 +86,8 @@ prodNums = [2,2,2,6,9,9],压缩成行程编码数组 [[2,3],[6,1],[9,2]]。 +#### Python3 + ```python class Solution: def findRLEArray( @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> findRLEArray(int[][] encoded1, int[][] encoded2) { @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func findRLEArray(encoded1 [][]int, encoded2 [][]int) (ans [][]int) { j := 0 diff --git a/solution/1800-1899/1868.Product of Two Run-Length Encoded Arrays/README_EN.md b/solution/1800-1899/1868.Product of Two Run-Length Encoded Arrays/README_EN.md index fbb1ce4d24aa2..cab9bdf7c3be6 100644 --- a/solution/1800-1899/1868.Product of Two Run-Length Encoded Arrays/README_EN.md +++ b/solution/1800-1899/1868.Product of Two Run-Length Encoded Arrays/README_EN.md @@ -78,6 +78,8 @@ prodNums = [2,2,2,6,9,9], which is compressed into the run-length encoded array +#### Python3 + ```python class Solution: def findRLEArray( @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> findRLEArray(int[][] encoded1, int[][] encoded2) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func findRLEArray(encoded1 [][]int, encoded2 [][]int) (ans [][]int) { j := 0 diff --git a/solution/1800-1899/1869.Longer Contiguous Segments of Ones than Zeros/README.md b/solution/1800-1899/1869.Longer Contiguous Segments of Ones than Zeros/README.md index ade7d80598ce5..07ff598d3473c 100644 --- a/solution/1800-1899/1869.Longer Contiguous Segments of Ones than Zeros/README.md +++ b/solution/1800-1899/1869.Longer Contiguous Segments of Ones than Zeros/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def checkZeroOnes(self, s: str) -> bool: @@ -100,6 +102,8 @@ class Solution: return f("1") > f("0") ``` +#### Java + ```java class Solution { public boolean checkZeroOnes(String s) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func checkZeroOnes(s string) bool { f := func(x rune) int { @@ -158,6 +166,8 @@ func checkZeroOnes(s string) bool { } ``` +#### TypeScript + ```ts function checkZeroOnes(s: string): boolean { const f = (x: string): number => { @@ -175,6 +185,8 @@ function checkZeroOnes(s: string): boolean { } ``` +#### JavaScript + ```js /** * @param {string} s diff --git a/solution/1800-1899/1869.Longer Contiguous Segments of Ones than Zeros/README_EN.md b/solution/1800-1899/1869.Longer Contiguous Segments of Ones than Zeros/README_EN.md index aeae5ebfc9c17..2545516321514 100644 --- a/solution/1800-1899/1869.Longer Contiguous Segments of Ones than Zeros/README_EN.md +++ b/solution/1800-1899/1869.Longer Contiguous Segments of Ones than Zeros/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string $s$. The sp +#### Python3 + ```python class Solution: def checkZeroOnes(self, s: str) -> bool: @@ -98,6 +100,8 @@ class Solution: return f("1") > f("0") ``` +#### Java + ```java class Solution { public boolean checkZeroOnes(String s) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func checkZeroOnes(s string) bool { f := func(x rune) int { @@ -156,6 +164,8 @@ func checkZeroOnes(s string) bool { } ``` +#### TypeScript + ```ts function checkZeroOnes(s: string): boolean { const f = (x: string): number => { @@ -173,6 +183,8 @@ function checkZeroOnes(s: string): boolean { } ``` +#### JavaScript + ```js /** * @param {string} s diff --git a/solution/1800-1899/1870.Minimum Speed to Arrive on Time/README.md b/solution/1800-1899/1870.Minimum Speed to Arrive on Time/README.md index 13e33e4e4af52..0d6ddf8f60d6e 100644 --- a/solution/1800-1899/1870.Minimum Speed to Arrive on Time/README.md +++ b/solution/1800-1899/1870.Minimum Speed to Arrive on Time/README.md @@ -140,6 +140,8 @@ int search(int left, int right) { +#### Python3 + ```python class Solution: def minSpeedOnTime(self, dist: List[int], hour: float) -> int: @@ -154,6 +156,8 @@ class Solution: return -1 if ans == r else ans ``` +#### Java + ```java class Solution { public int minSpeedOnTime(int[] dist, double hour) { @@ -180,6 +184,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -207,6 +213,8 @@ public: }; ``` +#### Go + ```go func minSpeedOnTime(dist []int, hour float64) int { n := len(dist) @@ -227,6 +235,8 @@ func minSpeedOnTime(dist []int, hour float64) int { } ``` +#### Rust + ```rust impl Solution { pub fn min_speed_on_time(dist: Vec, hour: f64) -> i32 { @@ -263,6 +273,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} dist diff --git a/solution/1800-1899/1870.Minimum Speed to Arrive on Time/README_EN.md b/solution/1800-1899/1870.Minimum Speed to Arrive on Time/README_EN.md index ca83b806beff8..04815774eaef8 100644 --- a/solution/1800-1899/1870.Minimum Speed to Arrive on Time/README_EN.md +++ b/solution/1800-1899/1870.Minimum Speed to Arrive on Time/README_EN.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def minSpeedOnTime(self, dist: List[int], hour: float) -> int: @@ -99,6 +101,8 @@ class Solution: return -1 if ans == r else ans ``` +#### Java + ```java class Solution { public int minSpeedOnTime(int[] dist, double hour) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func minSpeedOnTime(dist []int, hour float64) int { n := len(dist) @@ -172,6 +180,8 @@ func minSpeedOnTime(dist []int, hour float64) int { } ``` +#### Rust + ```rust impl Solution { pub fn min_speed_on_time(dist: Vec, hour: f64) -> i32 { @@ -208,6 +218,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} dist diff --git a/solution/1800-1899/1871.Jump Game VII/README.md b/solution/1800-1899/1871.Jump Game VII/README.md index c51a46f641558..b95a992c4b2f4 100644 --- a/solution/1800-1899/1871.Jump Game VII/README.md +++ b/solution/1800-1899/1871.Jump Game VII/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def canReach(self, s: str, minJump: int, maxJump: int) -> bool: @@ -93,6 +95,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public boolean canReach(String s, int minJump, int maxJump) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func canReach(s string, minJump int, maxJump int) bool { n := len(s) @@ -159,6 +167,8 @@ func canReach(s string, minJump int, maxJump int) bool { } ``` +#### TypeScript + ```ts function canReach(s: string, minJump: number, maxJump: number): boolean { const n = s.length; @@ -177,6 +187,8 @@ function canReach(s: string, minJump: number, maxJump: number): boolean { } ``` +#### JavaScript + ```js /** * @param {string} s diff --git a/solution/1800-1899/1871.Jump Game VII/README_EN.md b/solution/1800-1899/1871.Jump Game VII/README_EN.md index 9eb4c49696c0f..894152e2b4b6a 100644 --- a/solution/1800-1899/1871.Jump Game VII/README_EN.md +++ b/solution/1800-1899/1871.Jump Game VII/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def canReach(self, s: str, minJump: int, maxJump: int) -> bool: @@ -91,6 +93,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public boolean canReach(String s, int minJump, int maxJump) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func canReach(s string, minJump int, maxJump int) bool { n := len(s) @@ -157,6 +165,8 @@ func canReach(s string, minJump int, maxJump int) bool { } ``` +#### TypeScript + ```ts function canReach(s: string, minJump: number, maxJump: number): boolean { const n = s.length; @@ -175,6 +185,8 @@ function canReach(s: string, minJump: number, maxJump: number): boolean { } ``` +#### JavaScript + ```js /** * @param {string} s diff --git a/solution/1800-1899/1872.Stone Game VIII/README.md b/solution/1800-1899/1872.Stone Game VIII/README.md index e54a31290b7ec..093e24c310835 100644 --- a/solution/1800-1899/1872.Stone Game VIII/README.md +++ b/solution/1800-1899/1872.Stone Game VIII/README.md @@ -105,6 +105,8 @@ tags: +#### Python3 + ```python class Solution: def stoneGameVIII(self, stones: List[int]) -> int: @@ -118,6 +120,8 @@ class Solution: return dfs(1) ``` +#### Java + ```java class Solution { private Integer[] f; @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go func stoneGameVIII(stones []int) int { n := len(stones) @@ -194,6 +202,8 @@ func stoneGameVIII(stones []int) int { } ``` +#### TypeScript + ```ts function stoneGameVIII(stones: number[]): number { const n = stones.length; @@ -246,6 +256,8 @@ $$ +#### Python3 + ```python class Solution: def stoneGameVIII(self, stones: List[int]) -> int: @@ -256,6 +268,8 @@ class Solution: return f ``` +#### Java + ```java class Solution { public int stoneGameVIII(int[] stones) { @@ -272,6 +286,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -289,6 +305,8 @@ public: }; ``` +#### TypeScript + ```ts function stoneGameVIII(stones: number[]): number { const n = stones.length; diff --git a/solution/1800-1899/1872.Stone Game VIII/README_EN.md b/solution/1800-1899/1872.Stone Game VIII/README_EN.md index bc71b9705eca4..db273764cb33b 100644 --- a/solution/1800-1899/1872.Stone Game VIII/README_EN.md +++ b/solution/1800-1899/1872.Stone Game VIII/README_EN.md @@ -143,6 +143,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def stoneGameVIII(self, stones: List[int]) -> int: @@ -156,6 +158,8 @@ class Solution: return dfs(1) ``` +#### Java + ```java class Solution { private Integer[] f; @@ -184,6 +188,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -208,6 +214,8 @@ public: }; ``` +#### Go + ```go func stoneGameVIII(stones []int) int { n := len(stones) @@ -232,6 +240,8 @@ func stoneGameVIII(stones []int) int { } ``` +#### TypeScript + ```ts function stoneGameVIII(stones: number[]): number { const n = stones.length; @@ -284,6 +294,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is +#### Python3 + ```python class Solution: def stoneGameVIII(self, stones: List[int]) -> int: @@ -294,6 +306,8 @@ class Solution: return f ``` +#### Java + ```java class Solution { public int stoneGameVIII(int[] stones) { @@ -310,6 +324,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -327,6 +343,8 @@ public: }; ``` +#### TypeScript + ```ts function stoneGameVIII(stones: number[]): number { const n = stones.length; diff --git a/solution/1800-1899/1873.Calculate Special Bonus/README.md b/solution/1800-1899/1873.Calculate Special Bonus/README.md index 9e6a745fcc65f..0ed9d4f7bbe9f 100644 --- a/solution/1800-1899/1873.Calculate Special Bonus/README.md +++ b/solution/1800-1899/1873.Calculate Special Bonus/README.md @@ -81,6 +81,8 @@ Employees 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1800-1899/1873.Calculate Special Bonus/README_EN.md b/solution/1800-1899/1873.Calculate Special Bonus/README_EN.md index d990cfd5b8beb..cb6bedcb229b8 100644 --- a/solution/1800-1899/1873.Calculate Special Bonus/README_EN.md +++ b/solution/1800-1899/1873.Calculate Special Bonus/README_EN.md @@ -81,6 +81,8 @@ We can use the `IF` statement to determine the calculation method of the bonus, +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1800-1899/1874.Minimize Product Sum of Two Arrays/README.md b/solution/1800-1899/1874.Minimize Product Sum of Two Arrays/README.md index d5b7f69d8b3a5..59c561eb80207 100644 --- a/solution/1800-1899/1874.Minimize Product Sum of Two Arrays/README.md +++ b/solution/1800-1899/1874.Minimize Product Sum of Two Arrays/README.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def minProductSum(self, nums1: List[int], nums2: List[int]) -> int: @@ -71,6 +73,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public int minProductSum(int[] nums1, int[] nums2) { @@ -85,6 +89,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -100,6 +106,8 @@ public: }; ``` +#### Go + ```go func minProductSum(nums1 []int, nums2 []int) int { sort.Ints(nums1) diff --git a/solution/1800-1899/1874.Minimize Product Sum of Two Arrays/README_EN.md b/solution/1800-1899/1874.Minimize Product Sum of Two Arrays/README_EN.md index be6cfe936900a..36c4c2c85b10b 100644 --- a/solution/1800-1899/1874.Minimize Product Sum of Two Arrays/README_EN.md +++ b/solution/1800-1899/1874.Minimize Product Sum of Two Arrays/README_EN.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def minProductSum(self, nums1: List[int], nums2: List[int]) -> int: @@ -89,6 +91,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public int minProductSum(int[] nums1, int[] nums2) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func minProductSum(nums1 []int, nums2 []int) int { sort.Ints(nums1) diff --git a/solution/1800-1899/1875.Group Employees of the Same Salary/README.md b/solution/1800-1899/1875.Group Employees of the Same Salary/README.md index 5aadb3325e5b8..7e86e3bd6e61e 100644 --- a/solution/1800-1899/1875.Group Employees of the Same Salary/README.md +++ b/solution/1800-1899/1875.Group Employees of the Same Salary/README.md @@ -92,6 +92,8 @@ Juan的工资(6100)没有被计算在排名中,因为他不属于任何一个 +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1800-1899/1875.Group Employees of the Same Salary/README_EN.md b/solution/1800-1899/1875.Group Employees of the Same Salary/README_EN.md index d8a6eb39c242c..f60473a5a8559 100644 --- a/solution/1800-1899/1875.Group Employees of the Same Salary/README_EN.md +++ b/solution/1800-1899/1875.Group Employees of the Same Salary/README_EN.md @@ -92,6 +92,8 @@ Juan's salary of 6100 is not included in the ranking because they are not on +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1800-1899/1876.Substrings of Size Three with Distinct Characters/README.md b/solution/1800-1899/1876.Substrings of Size Three with Distinct Characters/README.md index e702e9a26cac9..0c99b95b8df00 100644 --- a/solution/1800-1899/1876.Substrings of Size Three with Distinct Characters/README.md +++ b/solution/1800-1899/1876.Substrings of Size Three with Distinct Characters/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def countGoodSubstrings(self, s: str) -> int: @@ -77,6 +79,8 @@ class Solution: return count ``` +#### Java + ```java class Solution { public int countGoodSubstrings(String s) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### TypeScript + ```ts function countGoodSubstrings(s: string): number { const n: number = s.length; @@ -108,6 +114,8 @@ function countGoodSubstrings(s: string): number { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1800-1899/1876.Substrings of Size Three with Distinct Characters/README_EN.md b/solution/1800-1899/1876.Substrings of Size Three with Distinct Characters/README_EN.md index 111691c904945..969bd847d861a 100644 --- a/solution/1800-1899/1876.Substrings of Size Three with Distinct Characters/README_EN.md +++ b/solution/1800-1899/1876.Substrings of Size Three with Distinct Characters/README_EN.md @@ -66,6 +66,8 @@ The good substrings are "abc", "bca", "cab", and & +#### Python3 + ```python class Solution: def countGoodSubstrings(self, s: str) -> int: @@ -75,6 +77,8 @@ class Solution: return count ``` +#### Java + ```java class Solution { public int countGoodSubstrings(String s) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### TypeScript + ```ts function countGoodSubstrings(s: string): number { const n: number = s.length; @@ -106,6 +112,8 @@ function countGoodSubstrings(s: string): number { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1800-1899/1877.Minimize Maximum Pair Sum in Array/README.md b/solution/1800-1899/1877.Minimize Maximum Pair Sum in Array/README.md index 0ac0e5056e4ba..7161980fcade3 100644 --- a/solution/1800-1899/1877.Minimize Maximum Pair Sum in Array/README.md +++ b/solution/1800-1899/1877.Minimize Maximum Pair Sum in Array/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def minPairSum(self, nums: List[int]) -> int: @@ -89,6 +91,8 @@ class Solution: return max(x + nums[n - i - 1] for i, x in enumerate(nums[: n >> 1])) ``` +#### Java + ```java class Solution { public int minPairSum(int[] nums) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func minPairSum(nums []int) (ans int) { sort.Ints(nums) @@ -127,6 +135,8 @@ func minPairSum(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function minPairSum(nums: number[]): number { nums.sort((a, b) => a - b); @@ -139,6 +149,8 @@ function minPairSum(nums: number[]): number { } ``` +#### C# + ```cs public class Solution { public int MinPairSum(int[] nums) { diff --git a/solution/1800-1899/1877.Minimize Maximum Pair Sum in Array/README_EN.md b/solution/1800-1899/1877.Minimize Maximum Pair Sum in Array/README_EN.md index e9cd4af7814ce..27cc1971cb8c9 100644 --- a/solution/1800-1899/1877.Minimize Maximum Pair Sum in Array/README_EN.md +++ b/solution/1800-1899/1877.Minimize Maximum Pair Sum in Array/README_EN.md @@ -97,6 +97,8 @@ The maximum pair sum is max(3+5, 4+4, 6+2) = max(8, 8, 8) = 8. +#### Python3 + ```python class Solution: def minPairSum(self, nums: List[int]) -> int: @@ -105,6 +107,8 @@ class Solution: return max(x + nums[n - i - 1] for i, x in enumerate(nums[: n >> 1])) ``` +#### Java + ```java class Solution { public int minPairSum(int[] nums) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func minPairSum(nums []int) (ans int) { sort.Ints(nums) @@ -143,6 +151,8 @@ func minPairSum(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function minPairSum(nums: number[]): number { nums.sort((a, b) => a - b); @@ -155,6 +165,8 @@ function minPairSum(nums: number[]): number { } ``` +#### C# + ```cs public class Solution { public int MinPairSum(int[] nums) { diff --git a/solution/1800-1899/1878.Get Biggest Three Rhombus Sums in a Grid/README.md b/solution/1800-1899/1878.Get Biggest Three Rhombus Sums in a Grid/README.md index 96187b85b5fab..77eb92ff2e9cb 100644 --- a/solution/1800-1899/1878.Get Biggest Three Rhombus Sums in a Grid/README.md +++ b/solution/1800-1899/1878.Get Biggest Three Rhombus Sums in a Grid/README.md @@ -102,6 +102,8 @@ $$ +#### Python3 + ```python from sortedcontainers import SortedSet @@ -133,6 +135,8 @@ class Solution: return list(ss)[::-1] ``` +#### Java + ```java class Solution { public int[] getBiggestThree(int[][] grid) { @@ -171,6 +175,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -206,6 +212,8 @@ public: }; ``` +#### Go + ```go func getBiggestThree(grid [][]int) []int { m, n := len(grid), len(grid[0]) @@ -248,6 +256,8 @@ func getBiggestThree(grid [][]int) []int { } ``` +#### TypeScript + ```ts function getBiggestThree(grid: number[][]): number[] { const m = grid.length; diff --git a/solution/1800-1899/1878.Get Biggest Three Rhombus Sums in a Grid/README_EN.md b/solution/1800-1899/1878.Get Biggest Three Rhombus Sums in a Grid/README_EN.md index 81784a866d08a..0163f634248d2 100644 --- a/solution/1800-1899/1878.Get Biggest Three Rhombus Sums in a Grid/README_EN.md +++ b/solution/1800-1899/1878.Get Biggest Three Rhombus Sums in a Grid/README_EN.md @@ -98,6 +98,8 @@ The time complexity is $O(m \times n \times \min(m, n))$, and the space complexi +#### Python3 + ```python from sortedcontainers import SortedSet @@ -129,6 +131,8 @@ class Solution: return list(ss)[::-1] ``` +#### Java + ```java class Solution { public int[] getBiggestThree(int[][] grid) { @@ -167,6 +171,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -202,6 +208,8 @@ public: }; ``` +#### Go + ```go func getBiggestThree(grid [][]int) []int { m, n := len(grid), len(grid[0]) @@ -244,6 +252,8 @@ func getBiggestThree(grid [][]int) []int { } ``` +#### TypeScript + ```ts function getBiggestThree(grid: number[][]): number[] { const m = grid.length; diff --git a/solution/1800-1899/1879.Minimum XOR Sum of Two Arrays/README.md b/solution/1800-1899/1879.Minimum XOR Sum of Two Arrays/README.md index 55e22d0132fe7..79c9a98483f25 100644 --- a/solution/1800-1899/1879.Minimum XOR Sum of Two Arrays/README.md +++ b/solution/1800-1899/1879.Minimum XOR Sum of Two Arrays/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def minimumXORSum(self, nums1: List[int], nums2: List[int]) -> int: @@ -99,6 +101,8 @@ class Solution: return f[-1][-1] ``` +#### Java + ```java class Solution { public int minimumXORSum(int[] nums1, int[] nums2) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func minimumXORSum(nums1 []int, nums2 []int) int { n := len(nums1) @@ -169,6 +177,8 @@ func minimumXORSum(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function minimumXORSum(nums1: number[], nums2: number[]): number { const n = nums1.length; @@ -203,6 +213,8 @@ function minimumXORSum(nums1: number[], nums2: number[]): number { +#### Python3 + ```python class Solution: def minimumXORSum(self, nums1: List[int], nums2: List[int]) -> int: @@ -217,6 +229,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int minimumXORSum(int[] nums1, int[] nums2) { @@ -238,6 +252,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -260,6 +276,8 @@ public: }; ``` +#### Go + ```go func minimumXORSum(nums1 []int, nums2 []int) int { n := len(nums1) @@ -281,6 +299,8 @@ func minimumXORSum(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function minimumXORSum(nums1: number[], nums2: number[]): number { const n = nums1.length; @@ -309,6 +329,8 @@ function minimumXORSum(nums1: number[], nums2: number[]): number { +#### Python3 + ```python class Solution: def minimumXORSum(self, nums1: List[int], nums2: List[int]) -> int: @@ -323,6 +345,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int minimumXORSum(int[] nums1, int[] nums2) { @@ -343,6 +367,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -364,6 +390,8 @@ public: }; ``` +#### Go + ```go func minimumXORSum(nums1 []int, nums2 []int) int { n := len(nums1) @@ -384,6 +412,8 @@ func minimumXORSum(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function minimumXORSum(nums1: number[], nums2: number[]): number { const n = nums1.length; diff --git a/solution/1800-1899/1879.Minimum XOR Sum of Two Arrays/README_EN.md b/solution/1800-1899/1879.Minimum XOR Sum of Two Arrays/README_EN.md index d0875ead6c316..b208c82a8daf7 100644 --- a/solution/1800-1899/1879.Minimum XOR Sum of Two Arrays/README_EN.md +++ b/solution/1800-1899/1879.Minimum XOR Sum of Two Arrays/README_EN.md @@ -71,6 +71,8 @@ The XOR sum is (1 XOR 5) + (0 XOR 4) + (3 XOR 3) = 4 + 4 + 0 = 8. +#### Python3 + ```python class Solution: def minimumXORSum(self, nums1: List[int], nums2: List[int]) -> int: @@ -85,6 +87,8 @@ class Solution: return f[-1][-1] ``` +#### Java + ```java class Solution { public int minimumXORSum(int[] nums1, int[] nums2) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func minimumXORSum(nums1 []int, nums2 []int) int { n := len(nums1) @@ -155,6 +163,8 @@ func minimumXORSum(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function minimumXORSum(nums1: number[], nums2: number[]): number { const n = nums1.length; @@ -185,6 +195,8 @@ function minimumXORSum(nums1: number[], nums2: number[]): number { +#### Python3 + ```python class Solution: def minimumXORSum(self, nums1: List[int], nums2: List[int]) -> int: @@ -199,6 +211,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int minimumXORSum(int[] nums1, int[] nums2) { @@ -220,6 +234,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -242,6 +258,8 @@ public: }; ``` +#### Go + ```go func minimumXORSum(nums1 []int, nums2 []int) int { n := len(nums1) @@ -263,6 +281,8 @@ func minimumXORSum(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function minimumXORSum(nums1: number[], nums2: number[]): number { const n = nums1.length; @@ -291,6 +311,8 @@ function minimumXORSum(nums1: number[], nums2: number[]): number { +#### Python3 + ```python class Solution: def minimumXORSum(self, nums1: List[int], nums2: List[int]) -> int: @@ -305,6 +327,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int minimumXORSum(int[] nums1, int[] nums2) { @@ -325,6 +349,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -346,6 +372,8 @@ public: }; ``` +#### Go + ```go func minimumXORSum(nums1 []int, nums2 []int) int { n := len(nums1) @@ -366,6 +394,8 @@ func minimumXORSum(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function minimumXORSum(nums1: number[], nums2: number[]): number { const n = nums1.length; diff --git a/solution/1800-1899/1880.Check if Word Equals Summation of Two Words/README.md b/solution/1800-1899/1880.Check if Word Equals Summation of Two Words/README.md index 960eefcc01524..cbd14a9993e21 100644 --- a/solution/1800-1899/1880.Check if Word Equals Summation of Two Words/README.md +++ b/solution/1800-1899/1880.Check if Word Equals Summation of Two Words/README.md @@ -83,6 +83,8 @@ targetWord 的数值为 "aaaa" -> "0000" -> 0 +#### Python3 + ```python class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: @@ -95,6 +97,8 @@ class Solution: return f(firstWord) + f(secondWord) == f(targetWord) ``` +#### Java + ```java class Solution { public boolean isSumEqual(String firstWord, String secondWord, String targetWord) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func isSumEqual(firstWord string, secondWord string, targetWord string) bool { f := func(s string) int { @@ -139,6 +147,8 @@ func isSumEqual(firstWord string, secondWord string, targetWord string) bool { } ``` +#### TypeScript + ```ts function isSumEqual(firstWord: string, secondWord: string, targetWord: string): boolean { const calc = (s: string) => { @@ -152,6 +162,8 @@ function isSumEqual(firstWord: string, secondWord: string, targetWord: string): } ``` +#### Rust + ```rust impl Solution { fn calc(s: &String) -> i32 { @@ -168,6 +180,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} firstWord @@ -187,6 +201,8 @@ var isSumEqual = function (firstWord, secondWord, targetWord) { }; ``` +#### C + ```c int calc(char* s) { int res = 0; diff --git a/solution/1800-1899/1880.Check if Word Equals Summation of Two Words/README_EN.md b/solution/1800-1899/1880.Check if Word Equals Summation of Two Words/README_EN.md index 6683fb8c3efcd..05b49365f3037 100644 --- a/solution/1800-1899/1880.Check if Word Equals Summation of Two Words/README_EN.md +++ b/solution/1800-1899/1880.Check if Word Equals Summation of Two Words/README_EN.md @@ -85,6 +85,8 @@ We return true because 0 + 0 == 0. +#### Python3 + ```python class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: @@ -97,6 +99,8 @@ class Solution: return f(firstWord) + f(secondWord) == f(targetWord) ``` +#### Java + ```java class Solution { public boolean isSumEqual(String firstWord, String secondWord, String targetWord) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func isSumEqual(firstWord string, secondWord string, targetWord string) bool { f := func(s string) int { @@ -141,6 +149,8 @@ func isSumEqual(firstWord string, secondWord string, targetWord string) bool { } ``` +#### TypeScript + ```ts function isSumEqual(firstWord: string, secondWord: string, targetWord: string): boolean { const calc = (s: string) => { @@ -154,6 +164,8 @@ function isSumEqual(firstWord: string, secondWord: string, targetWord: string): } ``` +#### Rust + ```rust impl Solution { fn calc(s: &String) -> i32 { @@ -170,6 +182,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} firstWord @@ -189,6 +203,8 @@ var isSumEqual = function (firstWord, secondWord, targetWord) { }; ``` +#### C + ```c int calc(char* s) { int res = 0; diff --git a/solution/1800-1899/1881.Maximum Value after Insertion/README.md b/solution/1800-1899/1881.Maximum Value after Insertion/README.md index d78348f5a7233..b173c8378f52e 100644 --- a/solution/1800-1899/1881.Maximum Value after Insertion/README.md +++ b/solution/1800-1899/1881.Maximum Value after Insertion/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def maxValue(self, n: str, x: int) -> str: @@ -85,6 +87,8 @@ class Solution: return n + str(x) ``` +#### Java + ```java class Solution { public String maxValue(String n, int x) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func maxValue(n string, x int) string { i := 0 @@ -132,6 +140,8 @@ func maxValue(n string, x int) string { } ``` +#### JavaScript + ```js /** * @param {string} n diff --git a/solution/1800-1899/1881.Maximum Value after Insertion/README_EN.md b/solution/1800-1899/1881.Maximum Value after Insertion/README_EN.md index aa84acf227737..40d9547510c30 100644 --- a/solution/1800-1899/1881.Maximum Value after Insertion/README_EN.md +++ b/solution/1800-1899/1881.Maximum Value after Insertion/README_EN.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def maxValue(self, n: str, x: int) -> str: @@ -83,6 +85,8 @@ class Solution: return n + str(x) ``` +#### Java + ```java class Solution { public String maxValue(String n, int x) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func maxValue(n string, x int) string { i := 0 @@ -130,6 +138,8 @@ func maxValue(n string, x int) string { } ``` +#### JavaScript + ```js /** * @param {string} n diff --git a/solution/1800-1899/1882.Process Tasks Using Servers/README.md b/solution/1800-1899/1882.Process Tasks Using Servers/README.md index e3cf27bf987a1..ee16565828a44 100644 --- a/solution/1800-1899/1882.Process Tasks Using Servers/README.md +++ b/solution/1800-1899/1882.Process Tasks Using Servers/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def assignTasks(self, servers: List[int], tasks: List[int]) -> List[int]: @@ -114,6 +116,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public int[] assignTasks(int[] servers, int[] tasks) { diff --git a/solution/1800-1899/1882.Process Tasks Using Servers/README_EN.md b/solution/1800-1899/1882.Process Tasks Using Servers/README_EN.md index 9c0a75d57ad73..c3ba6d8eb93ec 100644 --- a/solution/1800-1899/1882.Process Tasks Using Servers/README_EN.md +++ b/solution/1800-1899/1882.Process Tasks Using Servers/README_EN.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def assignTasks(self, servers: List[int], tasks: List[int]) -> List[int]: @@ -103,6 +105,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public int[] assignTasks(int[] servers, int[] tasks) { diff --git a/solution/1800-1899/1883.Minimum Skips to Arrive at Meeting On Time/README.md b/solution/1800-1899/1883.Minimum Skips to Arrive at Meeting On Time/README.md index 402d3478040c7..c71aa41c7ab4b 100644 --- a/solution/1800-1899/1883.Minimum Skips to Arrive at Meeting On Time/README.md +++ b/solution/1800-1899/1883.Minimum Skips to Arrive at Meeting On Time/README.md @@ -102,6 +102,8 @@ $$ +#### Python3 + ```python class Solution: def minSkips(self, dist: List[int], speed: int, hoursBefore: int) -> int: @@ -121,6 +123,8 @@ class Solution: return -1 ``` +#### Python3 + ```python class Solution: def minSkips(self, dist: List[int], speed: int, hoursBefore: int) -> int: @@ -139,6 +143,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minSkips(int[] dist, int speed, int hoursBefore) { @@ -170,6 +176,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -198,6 +206,8 @@ public: }; ``` +#### Go + ```go func minSkips(dist []int, speed int, hoursBefore int) int { n := len(dist) @@ -229,6 +239,8 @@ func minSkips(dist []int, speed int, hoursBefore int) int { } ``` +#### TypeScript + ```ts function minSkips(dist: number[], speed: number, hoursBefore: number): number { const n = dist.length; diff --git a/solution/1800-1899/1883.Minimum Skips to Arrive at Meeting On Time/README_EN.md b/solution/1800-1899/1883.Minimum Skips to Arrive at Meeting On Time/README_EN.md index 2693e5a7ec1db..0484509ca530a 100644 --- a/solution/1800-1899/1883.Minimum Skips to Arrive at Meeting On Time/README_EN.md +++ b/solution/1800-1899/1883.Minimum Skips to Arrive at Meeting On Time/README_EN.md @@ -100,6 +100,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$, where $n$ +#### Python3 + ```python class Solution: def minSkips(self, dist: List[int], speed: int, hoursBefore: int) -> int: @@ -119,6 +121,8 @@ class Solution: return -1 ``` +#### Python3 + ```python class Solution: def minSkips(self, dist: List[int], speed: int, hoursBefore: int) -> int: @@ -137,6 +141,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minSkips(int[] dist, int speed, int hoursBefore) { @@ -168,6 +174,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -196,6 +204,8 @@ public: }; ``` +#### Go + ```go func minSkips(dist []int, speed int, hoursBefore int) int { n := len(dist) @@ -227,6 +237,8 @@ func minSkips(dist []int, speed int, hoursBefore int) int { } ``` +#### TypeScript + ```ts function minSkips(dist: number[], speed: number, hoursBefore: number): number { const n = dist.length; diff --git a/solution/1800-1899/1884.Egg Drop With 2 Eggs and N Floors/README.md b/solution/1800-1899/1884.Egg Drop With 2 Eggs and N Floors/README.md index de13b273de29c..9eab76d1100af 100644 --- a/solution/1800-1899/1884.Egg Drop With 2 Eggs and N Floors/README.md +++ b/solution/1800-1899/1884.Egg Drop With 2 Eggs and N Floors/README.md @@ -69,18 +69,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1800-1899/1884.Egg Drop With 2 Eggs and N Floors/README_EN.md b/solution/1800-1899/1884.Egg Drop With 2 Eggs and N Floors/README_EN.md index 84834888c844d..283098f98acef 100644 --- a/solution/1800-1899/1884.Egg Drop With 2 Eggs and N Floors/README_EN.md +++ b/solution/1800-1899/1884.Egg Drop With 2 Eggs and N Floors/README_EN.md @@ -66,18 +66,26 @@ Regardless of the outcome, it takes at most 14 drops to determine f. +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1800-1899/1885.Count Pairs in Two Arrays/README.md b/solution/1800-1899/1885.Count Pairs in Two Arrays/README.md index 249c130b703d2..8e0478a1149c5 100644 --- a/solution/1800-1899/1885.Count Pairs in Two Arrays/README.md +++ b/solution/1800-1899/1885.Count Pairs in Two Arrays/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def countPairs(self, nums1: List[int], nums2: List[int]) -> int: @@ -78,6 +80,8 @@ class Solution: return sum(n - bisect_right(d, -v, lo=i + 1) for i, v in enumerate(d)) ``` +#### Java + ```java class Solution { public long countPairs(int[] nums1, int[] nums2) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func countPairs(nums1 []int, nums2 []int) int64 { n := len(nums1) diff --git a/solution/1800-1899/1885.Count Pairs in Two Arrays/README_EN.md b/solution/1800-1899/1885.Count Pairs in Two Arrays/README_EN.md index bffba5c89d66c..d45d0abf61dd9 100644 --- a/solution/1800-1899/1885.Count Pairs in Two Arrays/README_EN.md +++ b/solution/1800-1899/1885.Count Pairs in Two Arrays/README_EN.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def countPairs(self, nums1: List[int], nums2: List[int]) -> int: @@ -73,6 +75,8 @@ class Solution: return sum(n - bisect_right(d, -v, lo=i + 1) for i, v in enumerate(d)) ``` +#### Java + ```java class Solution { public long countPairs(int[] nums1, int[] nums2) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func countPairs(nums1 []int, nums2 []int) int64 { n := len(nums1) diff --git a/solution/1800-1899/1886.Determine Whether Matrix Can Be Obtained By Rotation/README.md b/solution/1800-1899/1886.Determine Whether Matrix Can Be Obtained By Rotation/README.md index 86053fe944e09..92930dc382eca 100644 --- a/solution/1800-1899/1886.Determine Whether Matrix Can Be Obtained By Rotation/README.md +++ b/solution/1800-1899/1886.Determine Whether Matrix Can Be Obtained By Rotation/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def findRotation(self, mat: List[List[int]], target: List[List[int]]) -> bool: @@ -90,6 +92,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean findRotation(int[][] mat, int[][] target) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func findRotation(mat [][]int, target [][]int) bool { n := len(mat) @@ -181,6 +189,8 @@ func equals(a, b [][]int) bool { } ``` +#### TypeScript + ```ts function findRotation(mat: number[][], target: number[][]): boolean { for (let k = 0; k < 4; k++) { @@ -224,6 +234,8 @@ function rotate(matrix: number[][]): void { } ``` +#### Rust + ```rust impl Solution { pub fn find_rotation(mat: Vec>, target: Vec>) -> bool { @@ -271,6 +283,8 @@ impl Solution { +#### Python3 + ```python class Solution: def findRotation(self, mat: List[List[int]], target: List[List[int]]) -> bool: @@ -281,6 +295,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean findRotation(int[][] mat, int[][] target) { diff --git a/solution/1800-1899/1886.Determine Whether Matrix Can Be Obtained By Rotation/README_EN.md b/solution/1800-1899/1886.Determine Whether Matrix Can Be Obtained By Rotation/README_EN.md index d233ae5355787..05c86d2764451 100644 --- a/solution/1800-1899/1886.Determine Whether Matrix Can Be Obtained By Rotation/README_EN.md +++ b/solution/1800-1899/1886.Determine Whether Matrix Can Be Obtained By Rotation/README_EN.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def findRotation(self, mat: List[List[int]], target: List[List[int]]) -> bool: @@ -86,6 +88,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean findRotation(int[][] mat, int[][] target) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func findRotation(mat [][]int, target [][]int) bool { n := len(mat) @@ -177,6 +185,8 @@ func equals(a, b [][]int) bool { } ``` +#### TypeScript + ```ts function findRotation(mat: number[][], target: number[][]): boolean { for (let k = 0; k < 4; k++) { @@ -220,6 +230,8 @@ function rotate(matrix: number[][]): void { } ``` +#### Rust + ```rust impl Solution { pub fn find_rotation(mat: Vec>, target: Vec>) -> bool { @@ -256,6 +268,8 @@ impl Solution { +#### Python3 + ```python class Solution: def findRotation(self, mat: List[List[int]], target: List[List[int]]) -> bool: @@ -266,6 +280,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean findRotation(int[][] mat, int[][] target) { diff --git a/solution/1800-1899/1887.Reduction Operations to Make the Array Elements Equal/README.md b/solution/1800-1899/1887.Reduction Operations to Make the Array Elements Equal/README.md index c753afbad14ea..1ed9e059bc6f7 100644 --- a/solution/1800-1899/1887.Reduction Operations to Make the Array Elements Equal/README.md +++ b/solution/1800-1899/1887.Reduction Operations to Make the Array Elements Equal/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def reductionOperations(self, nums: List[int]) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int reductionOperations(int[] nums) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func reductionOperations(nums []int) int { sort.Ints(nums) @@ -144,6 +152,8 @@ func reductionOperations(nums []int) int { } ``` +#### TypeScript + ```ts function reductionOperations(nums: number[]): number { nums.sort((a, b) => a - b); @@ -159,6 +169,8 @@ function reductionOperations(nums: number[]): number { } ``` +#### C# + ```cs public class Solution { public int ReductionOperations(int[] nums) { @@ -185,6 +197,8 @@ public class Solution { +#### Python3 + ```python class Solution: def reductionOperations(self, nums: List[int]) -> int: @@ -195,6 +209,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int reductionOperations(int[] nums) { @@ -212,6 +228,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/1800-1899/1887.Reduction Operations to Make the Array Elements Equal/README_EN.md b/solution/1800-1899/1887.Reduction Operations to Make the Array Elements Equal/README_EN.md index 670e015550b43..18581926f73f7 100644 --- a/solution/1800-1899/1887.Reduction Operations to Make the Array Elements Equal/README_EN.md +++ b/solution/1800-1899/1887.Reduction Operations to Make the Array Elements Equal/README_EN.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def reductionOperations(self, nums: List[int]) -> int: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int reductionOperations(int[] nums) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func reductionOperations(nums []int) int { sort.Ints(nums) @@ -136,6 +144,8 @@ func reductionOperations(nums []int) int { } ``` +#### TypeScript + ```ts function reductionOperations(nums: number[]): number { nums.sort((a, b) => a - b); @@ -151,6 +161,8 @@ function reductionOperations(nums: number[]): number { } ``` +#### C# + ```cs public class Solution { public int ReductionOperations(int[] nums) { @@ -177,6 +189,8 @@ public class Solution { +#### Python3 + ```python class Solution: def reductionOperations(self, nums: List[int]) -> int: @@ -187,6 +201,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int reductionOperations(int[] nums) { @@ -204,6 +220,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/1800-1899/1888.Minimum Number of Flips to Make the Binary String Alternating/README.md b/solution/1800-1899/1888.Minimum Number of Flips to Make the Binary String Alternating/README.md index acab82b4ea2f7..c73838c80a6a1 100644 --- a/solution/1800-1899/1888.Minimum Number of Flips to Make the Binary String Alternating/README.md +++ b/solution/1800-1899/1888.Minimum Number of Flips to Make the Binary String Alternating/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def minFlips(self, s: str) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minFlips(String s) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func minFlips(s string) int { n := len(s) @@ -176,6 +184,8 @@ func minFlips(s string) int { } ``` +#### TypeScript + ```ts function minFlips(s: string): number { const n = s.length; diff --git a/solution/1800-1899/1888.Minimum Number of Flips to Make the Binary String Alternating/README_EN.md b/solution/1800-1899/1888.Minimum Number of Flips to Make the Binary String Alternating/README_EN.md index 1501e6a1801f9..109f3d859b16b 100644 --- a/solution/1800-1899/1888.Minimum Number of Flips to Make the Binary String Alternating/README_EN.md +++ b/solution/1800-1899/1888.Minimum Number of Flips to Make the Binary String Alternating/README_EN.md @@ -80,6 +80,8 @@ Then, use the second operation on the third and sixth elements to make s = " +#### Python3 + ```python class Solution: def minFlips(self, s: str) -> int: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minFlips(String s) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func minFlips(s string) int { n := len(s) @@ -171,6 +179,8 @@ func minFlips(s string) int { } ``` +#### TypeScript + ```ts function minFlips(s: string): number { const n = s.length; diff --git a/solution/1800-1899/1889.Minimum Space Wasted From Packaging/README.md b/solution/1800-1899/1889.Minimum Space Wasted From Packaging/README.md index bb40e66ba12d7..350a9f0134489 100644 --- a/solution/1800-1899/1889.Minimum Space Wasted From Packaging/README.md +++ b/solution/1800-1899/1889.Minimum Space Wasted From Packaging/README.md @@ -99,6 +99,8 @@ tags: +#### Python3 + ```python class Solution: def minWastedSpace(self, packages: List[int], boxes: List[List[int]]) -> int: @@ -120,6 +122,8 @@ class Solution: return (ans - sum(packages)) % mod ``` +#### Java + ```java class Solution { public int minWastedSpace(int[] packages, int[][] boxes) { @@ -167,6 +171,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -195,6 +201,8 @@ public: }; ``` +#### Go + ```go func minWastedSpace(packages []int, boxes [][]int) int { n := len(packages) @@ -226,6 +234,8 @@ func minWastedSpace(packages []int, boxes [][]int) int { } ``` +#### TypeScript + ```ts function minWastedSpace(packages: number[], boxes: number[][]): number { const n = packages.length; diff --git a/solution/1800-1899/1889.Minimum Space Wasted From Packaging/README_EN.md b/solution/1800-1899/1889.Minimum Space Wasted From Packaging/README_EN.md index 19029f1c2d9be..feda4819786fb 100644 --- a/solution/1800-1899/1889.Minimum Space Wasted From Packaging/README_EN.md +++ b/solution/1800-1899/1889.Minimum Space Wasted From Packaging/README_EN.md @@ -85,6 +85,8 @@ The total waste is (5-3) + (5-5) + (10-8) + (10-10) + (14-11) + (14-12) = 9. +#### Python3 + ```python class Solution: def minWastedSpace(self, packages: List[int], boxes: List[List[int]]) -> int: @@ -106,6 +108,8 @@ class Solution: return (ans - sum(packages)) % mod ``` +#### Java + ```java class Solution { public int minWastedSpace(int[] packages, int[][] boxes) { @@ -153,6 +157,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func minWastedSpace(packages []int, boxes [][]int) int { n := len(packages) @@ -212,6 +220,8 @@ func minWastedSpace(packages []int, boxes [][]int) int { } ``` +#### TypeScript + ```ts function minWastedSpace(packages: number[], boxes: number[][]): number { const n = packages.length; diff --git a/solution/1800-1899/1890.The Latest Login in 2020/README.md b/solution/1800-1899/1890.The Latest Login in 2020/README.md index 6c6bf9393d2ef..88bbe331958c9 100644 --- a/solution/1800-1899/1890.The Latest Login in 2020/README.md +++ b/solution/1800-1899/1890.The Latest Login in 2020/README.md @@ -83,6 +83,8 @@ Logins 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT user_id, MAX(time_stamp) AS last_stamp diff --git a/solution/1800-1899/1890.The Latest Login in 2020/README_EN.md b/solution/1800-1899/1890.The Latest Login in 2020/README_EN.md index 60950238139b7..b8f243c122542 100644 --- a/solution/1800-1899/1890.The Latest Login in 2020/README_EN.md +++ b/solution/1800-1899/1890.The Latest Login in 2020/README_EN.md @@ -83,6 +83,8 @@ We can first filter out the login records in 2020, and then group by `user_id`, +#### MySQL + ```sql # Write your MySQL query statement below SELECT user_id, MAX(time_stamp) AS last_stamp diff --git a/solution/1800-1899/1891.Cutting Ribbons/README.md b/solution/1800-1899/1891.Cutting Ribbons/README.md index a1b40589c49c2..5d665cf2d6573 100644 --- a/solution/1800-1899/1891.Cutting Ribbons/README.md +++ b/solution/1800-1899/1891.Cutting Ribbons/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def maxLength(self, ribbons: List[int], k: int) -> int: @@ -105,6 +107,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int maxLength(int[] ribbons, int k) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func maxLength(ribbons []int, k int) int { left, right := 0, slices.Max(ribbons) @@ -170,6 +178,8 @@ func maxLength(ribbons []int, k int) int { } ``` +#### TypeScript + ```ts function maxLength(ribbons: number[], k: number): number { let left = 0; @@ -190,6 +200,8 @@ function maxLength(ribbons: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_length(ribbons: Vec, k: i32) -> i32 { @@ -215,6 +227,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} ribbons diff --git a/solution/1800-1899/1891.Cutting Ribbons/README_EN.md b/solution/1800-1899/1891.Cutting Ribbons/README_EN.md index 037bcfefc8f24..f7767d80e310b 100644 --- a/solution/1800-1899/1891.Cutting Ribbons/README_EN.md +++ b/solution/1800-1899/1891.Cutting Ribbons/README_EN.md @@ -96,6 +96,8 @@ The time complexity is $O(n \times \log M)$, where $n$ and $M$ are the number of +#### Python3 + ```python class Solution: def maxLength(self, ribbons: List[int], k: int) -> int: @@ -110,6 +112,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int maxLength(int[] ribbons, int k) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func maxLength(ribbons []int, k int) int { left, right := 0, slices.Max(ribbons) @@ -175,6 +183,8 @@ func maxLength(ribbons []int, k int) int { } ``` +#### TypeScript + ```ts function maxLength(ribbons: number[], k: number): number { let left = 0; @@ -195,6 +205,8 @@ function maxLength(ribbons: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_length(ribbons: Vec, k: i32) -> i32 { @@ -220,6 +232,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} ribbons diff --git a/solution/1800-1899/1892.Page Recommendations II/README.md b/solution/1800-1899/1892.Page Recommendations II/README.md index 5d51ef8bc218d..1294be439e380 100644 --- a/solution/1800-1899/1892.Page Recommendations II/README.md +++ b/solution/1800-1899/1892.Page Recommendations II/README.md @@ -135,6 +135,8 @@ Likes 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1800-1899/1892.Page Recommendations II/README_EN.md b/solution/1800-1899/1892.Page Recommendations II/README_EN.md index fd4b19504d531..4c9b4f27583e1 100644 --- a/solution/1800-1899/1892.Page Recommendations II/README_EN.md +++ b/solution/1800-1899/1892.Page Recommendations II/README_EN.md @@ -135,6 +135,8 @@ You can recommend pages for users 2, 3, 4, and 5 using a similar process. +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1800-1899/1893.Check if All the Integers in a Range Are Covered/README.md b/solution/1800-1899/1893.Check if All the Integers in a Range Are Covered/README.md index dd69b67267997..24e22b57c188f 100644 --- a/solution/1800-1899/1893.Check if All the Integers in a Range Are Covered/README.md +++ b/solution/1800-1899/1893.Check if All the Integers in a Range Are Covered/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def isCovered(self, ranges: List[List[int]], left: int, right: int) -> bool: @@ -90,6 +92,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isCovered(int[][] ranges, int left, int right) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func isCovered(ranges [][]int, left int, right int) bool { diff := [52]int{} @@ -152,6 +160,8 @@ func isCovered(ranges [][]int, left int, right int) bool { } ``` +#### TypeScript + ```ts function isCovered(ranges: number[][], left: number, right: number): boolean { const diff = new Array(52).fill(0); @@ -170,6 +180,8 @@ function isCovered(ranges: number[][], left: number, right: number): boolean { } ``` +#### JavaScript + ```js /** * @param {number[][]} ranges diff --git a/solution/1800-1899/1893.Check if All the Integers in a Range Are Covered/README_EN.md b/solution/1800-1899/1893.Check if All the Integers in a Range Are Covered/README_EN.md index 0685de9e108b0..0952f79b6a358 100644 --- a/solution/1800-1899/1893.Check if All the Integers in a Range Are Covered/README_EN.md +++ b/solution/1800-1899/1893.Check if All the Integers in a Range Are Covered/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def isCovered(self, ranges: List[List[int]], left: int, right: int) -> bool: @@ -80,6 +82,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean isCovered(int[][] ranges, int left, int right) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func isCovered(ranges [][]int, left int, right int) bool { diff := [52]int{} @@ -142,6 +150,8 @@ func isCovered(ranges [][]int, left int, right int) bool { } ``` +#### TypeScript + ```ts function isCovered(ranges: number[][], left: number, right: number): boolean { const diff = new Array(52).fill(0); @@ -160,6 +170,8 @@ function isCovered(ranges: number[][], left: number, right: number): boolean { } ``` +#### JavaScript + ```js /** * @param {number[][]} ranges diff --git a/solution/1800-1899/1894.Find the Student that Will Replace the Chalk/README.md b/solution/1800-1899/1894.Find the Student that Will Replace the Chalk/README.md index 4894019b28f6d..03ee46d1b0f95 100644 --- a/solution/1800-1899/1894.Find the Student that Will Replace the Chalk/README.md +++ b/solution/1800-1899/1894.Find the Student that Will Replace the Chalk/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def chalkReplacer(self, chalk: List[int], k: int) -> int: @@ -99,6 +101,8 @@ class Solution: k -= x ``` +#### Java + ```java class Solution { public int chalkReplacer(int[] chalk, int k) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func chalkReplacer(chalk []int, k int) int { s := 0 @@ -149,6 +157,8 @@ func chalkReplacer(chalk []int, k int) int { } ``` +#### TypeScript + ```ts function chalkReplacer(chalk: number[], k: number): number { let s = 0; @@ -165,6 +175,8 @@ function chalkReplacer(chalk: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn chalk_replacer(chalk: Vec, k: i32) -> i32 { diff --git a/solution/1800-1899/1894.Find the Student that Will Replace the Chalk/README_EN.md b/solution/1800-1899/1894.Find the Student that Will Replace the Chalk/README_EN.md index 73630762ad9c3..2ac5a1c524349 100644 --- a/solution/1800-1899/1894.Find the Student that Will Replace the Chalk/README_EN.md +++ b/solution/1800-1899/1894.Find the Student that Will Replace the Chalk/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(n)$, where $n$ is the number of students. The space co +#### Python3 + ```python class Solution: def chalkReplacer(self, chalk: List[int], k: int) -> int: @@ -97,6 +99,8 @@ class Solution: k -= x ``` +#### Java + ```java class Solution { public int chalkReplacer(int[] chalk, int k) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func chalkReplacer(chalk []int, k int) int { s := 0 @@ -147,6 +155,8 @@ func chalkReplacer(chalk []int, k int) int { } ``` +#### TypeScript + ```ts function chalkReplacer(chalk: number[], k: number): number { let s = 0; @@ -163,6 +173,8 @@ function chalkReplacer(chalk: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn chalk_replacer(chalk: Vec, k: i32) -> i32 { diff --git a/solution/1800-1899/1895.Largest Magic Square/README.md b/solution/1800-1899/1895.Largest Magic Square/README.md index 72be899f8943f..68b4b554db89d 100644 --- a/solution/1800-1899/1895.Largest Magic Square/README.md +++ b/solution/1800-1899/1895.Largest Magic Square/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def largestMagicSquare(self, grid: List[List[int]]) -> int: @@ -112,6 +114,8 @@ class Solution: return 1 ``` +#### Java + ```java class Solution { private int[][] rowsum; @@ -171,6 +175,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -219,6 +225,8 @@ public: }; ``` +#### Go + ```go func largestMagicSquare(grid [][]int) int { m, n := len(grid), len(grid[0]) @@ -277,6 +285,8 @@ func check(grid, rowsum, colsum [][]int, x1, y1, x2, y2 int) bool { } ``` +#### TypeScript + ```ts function largestMagicSquare(grid: number[][]): number { let m = grid.length, diff --git a/solution/1800-1899/1895.Largest Magic Square/README_EN.md b/solution/1800-1899/1895.Largest Magic Square/README_EN.md index eba15e00ef5e7..87c9230111467 100644 --- a/solution/1800-1899/1895.Largest Magic Square/README_EN.md +++ b/solution/1800-1899/1895.Largest Magic Square/README_EN.md @@ -64,6 +64,8 @@ Every row sum, column sum, and diagonal sum of this magic square is equal to 12. +#### Python3 + ```python class Solution: def largestMagicSquare(self, grid: List[List[int]]) -> int: @@ -112,6 +114,8 @@ class Solution: return 1 ``` +#### Java + ```java class Solution { private int[][] rowsum; @@ -171,6 +175,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -219,6 +225,8 @@ public: }; ``` +#### Go + ```go func largestMagicSquare(grid [][]int) int { m, n := len(grid), len(grid[0]) @@ -277,6 +285,8 @@ func check(grid, rowsum, colsum [][]int, x1, y1, x2, y2 int) bool { } ``` +#### TypeScript + ```ts function largestMagicSquare(grid: number[][]): number { let m = grid.length, diff --git a/solution/1800-1899/1896.Minimum Cost to Change the Final Value of Expression/README.md b/solution/1800-1899/1896.Minimum Cost to Change the Final Value of Expression/README.md index f47eb006798f2..5c18bc3e74c2b 100644 --- a/solution/1800-1899/1896.Minimum Cost to Change the Final Value of Expression/README.md +++ b/solution/1800-1899/1896.Minimum Cost to Change the Final Value of Expression/README.md @@ -90,18 +90,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1800-1899/1896.Minimum Cost to Change the Final Value of Expression/README_EN.md b/solution/1800-1899/1896.Minimum Cost to Change the Final Value of Expression/README_EN.md index 0b2c440ab671e..9e7b293386968 100644 --- a/solution/1800-1899/1896.Minimum Cost to Change the Final Value of Expression/README_EN.md +++ b/solution/1800-1899/1896.Minimum Cost to Change the Final Value of Expression/README_EN.md @@ -91,18 +91,26 @@ The new expression evaluates to 0. +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1800-1899/1897.Redistribute Characters to Make All Strings Equal/README.md b/solution/1800-1899/1897.Redistribute Characters to Make All Strings Equal/README.md index 0902400319a05..07ac29f00b24c 100644 --- a/solution/1800-1899/1897.Redistribute Characters to Make All Strings Equal/README.md +++ b/solution/1800-1899/1897.Redistribute Characters to Make All Strings Equal/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def makeEqual(self, words: List[str]) -> bool: @@ -75,6 +77,8 @@ class Solution: return all(count % n == 0 for count in counter.values()) ``` +#### Java + ```java class Solution { public boolean makeEqual(String[] words) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func makeEqual(words []string) bool { counter := [26]int{} @@ -132,6 +140,8 @@ func makeEqual(words []string) bool { } ``` +#### TypeScript + ```ts function makeEqual(words: string[]): boolean { let n = words.length; diff --git a/solution/1800-1899/1897.Redistribute Characters to Make All Strings Equal/README_EN.md b/solution/1800-1899/1897.Redistribute Characters to Make All Strings Equal/README_EN.md index 5066b8e2ef21f..48c1b5e38ffc6 100644 --- a/solution/1800-1899/1897.Redistribute Characters to Make All Strings Equal/README_EN.md +++ b/solution/1800-1899/1897.Redistribute Characters to Make All Strings Equal/README_EN.md @@ -64,6 +64,8 @@ All the strings are now equal to "abc", so return true. +#### Python3 + ```python class Solution: def makeEqual(self, words: List[str]) -> bool: @@ -75,6 +77,8 @@ class Solution: return all(count % n == 0 for count in counter.values()) ``` +#### Java + ```java class Solution { public boolean makeEqual(String[] words) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func makeEqual(words []string) bool { counter := [26]int{} @@ -132,6 +140,8 @@ func makeEqual(words []string) bool { } ``` +#### TypeScript + ```ts function makeEqual(words: string[]): boolean { let n = words.length; diff --git a/solution/1800-1899/1898.Maximum Number of Removable Characters/README.md b/solution/1800-1899/1898.Maximum Number of Removable Characters/README.md index 398487dfc2401..5143fec2d9f22 100644 --- a/solution/1800-1899/1898.Maximum Number of Removable Characters/README.md +++ b/solution/1800-1899/1898.Maximum Number of Removable Characters/README.md @@ -135,6 +135,8 @@ int search(int left, int right) { +#### Python3 + ```python class Solution: def maximumRemovals(self, s: str, p: str, removable: List[int]) -> int: @@ -158,6 +160,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int maximumRemovals(String s, String p, int[] removable) { @@ -190,6 +194,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -223,6 +229,8 @@ public: }; ``` +#### Go + ```go func maximumRemovals(s string, p string, removable []int) int { check := func(k int) bool { @@ -253,6 +261,8 @@ func maximumRemovals(s string, p string, removable []int) int { } ``` +#### TypeScript + ```ts function maximumRemovals(s: string, p: string, removable: number[]): number { let left = 0, @@ -283,6 +293,8 @@ function isSub(str: string, sub: string, idxes: Set): boolean { } ``` +#### Rust + ```rust use std::collections::HashSet; diff --git a/solution/1800-1899/1898.Maximum Number of Removable Characters/README_EN.md b/solution/1800-1899/1898.Maximum Number of Removable Characters/README_EN.md index 649864f6cc5ad..4604486d6d4a5 100644 --- a/solution/1800-1899/1898.Maximum Number of Removable Characters/README_EN.md +++ b/solution/1800-1899/1898.Maximum Number of Removable Characters/README_EN.md @@ -80,6 +80,8 @@ Hence, the maximum k is 2. +#### Python3 + ```python class Solution: def maximumRemovals(self, s: str, p: str, removable: List[int]) -> int: @@ -103,6 +105,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int maximumRemovals(String s, String p, int[] removable) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func maximumRemovals(s string, p string, removable []int) int { check := func(k int) bool { @@ -198,6 +206,8 @@ func maximumRemovals(s string, p string, removable []int) int { } ``` +#### TypeScript + ```ts function maximumRemovals(s: string, p: string, removable: number[]): number { let left = 0, @@ -228,6 +238,8 @@ function isSub(str: string, sub: string, idxes: Set): boolean { } ``` +#### Rust + ```rust use std::collections::HashSet; diff --git a/solution/1800-1899/1899.Merge Triplets to Form Target Triplet/README.md b/solution/1800-1899/1899.Merge Triplets to Form Target Triplet/README.md index 055f053794da5..0119a877c17ed 100644 --- a/solution/1800-1899/1899.Merge Triplets to Form Target Triplet/README.md +++ b/solution/1800-1899/1899.Merge Triplets to Form Target Triplet/README.md @@ -102,6 +102,8 @@ tags: +#### Python3 + ```python class Solution: def mergeTriplets(self, triplets: List[List[int]], target: List[int]) -> bool: @@ -115,6 +117,8 @@ class Solution: return [d, e, f] == target ``` +#### Java + ```java class Solution { public boolean mergeTriplets(int[][] triplets, int[] target) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func mergeTriplets(triplets [][]int, target []int) bool { x, y, z := target[0], target[1], target[2] @@ -168,6 +176,8 @@ func mergeTriplets(triplets [][]int, target []int) bool { } ``` +#### TypeScript + ```ts function mergeTriplets(triplets: number[][], target: number[]): boolean { const [x, y, z] = target; diff --git a/solution/1800-1899/1899.Merge Triplets to Form Target Triplet/README_EN.md b/solution/1800-1899/1899.Merge Triplets to Form Target Triplet/README_EN.md index 694d2f021f602..90a6d318161dd 100644 --- a/solution/1800-1899/1899.Merge Triplets to Form Target Triplet/README_EN.md +++ b/solution/1800-1899/1899.Merge Triplets to Form Target Triplet/README_EN.md @@ -84,6 +84,8 @@ The target triplet [5,5,5] is now an element of triplets. +#### Python3 + ```python class Solution: def mergeTriplets(self, triplets: List[List[int]], target: List[int]) -> bool: @@ -97,6 +99,8 @@ class Solution: return [d, e, f] == target ``` +#### Java + ```java class Solution { public boolean mergeTriplets(int[][] triplets, int[] target) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func mergeTriplets(triplets [][]int, target []int) bool { x, y, z := target[0], target[1], target[2] @@ -150,6 +158,8 @@ func mergeTriplets(triplets [][]int, target []int) bool { } ``` +#### TypeScript + ```ts function mergeTriplets(triplets: number[][], target: number[]): boolean { const [x, y, z] = target; diff --git a/solution/1900-1999/1900.The Earliest and Latest Rounds Where Players Compete/README.md b/solution/1900-1999/1900.The Earliest and Latest Rounds Where Players Compete/README.md index 896e24ab4c6aa..6e138b23b3d9f 100644 --- a/solution/1900-1999/1900.The Earliest and Latest Rounds Where Players Compete/README.md +++ b/solution/1900-1999/1900.The Earliest and Latest Rounds Where Players Compete/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def earliestAndLatest( diff --git a/solution/1900-1999/1900.The Earliest and Latest Rounds Where Players Compete/README_EN.md b/solution/1900-1999/1900.The Earliest and Latest Rounds Where Players Compete/README_EN.md index 78ba7be024f79..e53be4a5412c8 100644 --- a/solution/1900-1999/1900.The Earliest and Latest Rounds Where Players Compete/README_EN.md +++ b/solution/1900-1999/1900.The Earliest and Latest Rounds Where Players Compete/README_EN.md @@ -86,6 +86,8 @@ There is no way to make them compete in any other round. +#### Python3 + ```python class Solution: def earliestAndLatest( diff --git a/solution/1900-1999/1901.Find a Peak Element II/README.md b/solution/1900-1999/1901.Find a Peak Element II/README.md index 239325b65e575..a4ee857752a9a 100644 --- a/solution/1900-1999/1901.Find a Peak Element II/README.md +++ b/solution/1900-1999/1901.Find a Peak Element II/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def findPeakGrid(self, mat: List[List[int]]) -> List[int]: @@ -106,6 +108,8 @@ class Solution: return [l, mat[l].index(max(mat[l]))] ``` +#### Java + ```java class Solution { public int[] findPeakGrid(int[][] mat) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func findPeakGrid(mat [][]int) []int { maxPos := func(arr []int) int { @@ -180,6 +188,8 @@ func findPeakGrid(mat [][]int) []int { } ``` +#### TypeScript + ```ts function findPeakGrid(mat: number[][]): number[] { let [l, r] = [0, mat.length - 1]; @@ -196,6 +206,8 @@ function findPeakGrid(mat: number[][]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn find_peak_grid(mat: Vec>) -> Vec { diff --git a/solution/1900-1999/1901.Find a Peak Element II/README_EN.md b/solution/1900-1999/1901.Find a Peak Element II/README_EN.md index 7dab67ea5e315..819fccffb9d3b 100644 --- a/solution/1900-1999/1901.Find a Peak Element II/README_EN.md +++ b/solution/1900-1999/1901.Find a Peak Element II/README_EN.md @@ -88,6 +88,8 @@ The time complexity is $O(n \times \log m)$, where $m$ and $n$ are the number of +#### Python3 + ```python class Solution: def findPeakGrid(self, mat: List[List[int]]) -> List[int]: @@ -102,6 +104,8 @@ class Solution: return [l, mat[l].index(max(mat[l]))] ``` +#### Java + ```java class Solution { public int[] findPeakGrid(int[][] mat) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func findPeakGrid(mat [][]int) []int { maxPos := func(arr []int) int { @@ -176,6 +184,8 @@ func findPeakGrid(mat [][]int) []int { } ``` +#### TypeScript + ```ts function findPeakGrid(mat: number[][]): number[] { let [l, r] = [0, mat.length - 1]; @@ -192,6 +202,8 @@ function findPeakGrid(mat: number[][]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn find_peak_grid(mat: Vec>) -> Vec { diff --git a/solution/1900-1999/1902.Depth of BST Given Insertion Order/README.md b/solution/1900-1999/1902.Depth of BST Given Insertion Order/README.md index e323085520afa..7f87c780c5a56 100644 --- a/solution/1900-1999/1902.Depth of BST Given Insertion Order/README.md +++ b/solution/1900-1999/1902.Depth of BST Given Insertion Order/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python from sortedcontainers import SortedDict @@ -103,6 +105,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxDepthBST(int[] order) { diff --git a/solution/1900-1999/1902.Depth of BST Given Insertion Order/README_EN.md b/solution/1900-1999/1902.Depth of BST Given Insertion Order/README_EN.md index e0bfd100b7788..185590cb27c67 100644 --- a/solution/1900-1999/1902.Depth of BST Given Insertion Order/README_EN.md +++ b/solution/1900-1999/1902.Depth of BST Given Insertion Order/README_EN.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python from sortedcontainers import SortedDict @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxDepthBST(int[] order) { diff --git a/solution/1900-1999/1903.Largest Odd Number in String/README.md b/solution/1900-1999/1903.Largest Odd Number in String/README.md index 7134cde747146..122999bae6eab 100644 --- a/solution/1900-1999/1903.Largest Odd Number in String/README.md +++ b/solution/1900-1999/1903.Largest Odd Number in String/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def largestOddNumber(self, num: str) -> str: @@ -82,6 +84,8 @@ class Solution: return '' ``` +#### Java + ```java class Solution { public String largestOddNumber(String num) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func largestOddNumber(num string) string { for i := len(num) - 1; i >= 0; i-- { @@ -123,6 +131,8 @@ func largestOddNumber(num string) string { } ``` +#### TypeScript + ```ts function largestOddNumber(num: string): string { for (let i = num.length - 1; ~i; --i) { @@ -134,6 +144,8 @@ function largestOddNumber(num: string): string { } ``` +#### JavaScript + ```js /** * @param {string} num diff --git a/solution/1900-1999/1903.Largest Odd Number in String/README_EN.md b/solution/1900-1999/1903.Largest Odd Number in String/README_EN.md index 7a76f4f295c62..c3c61bf9d9a94 100644 --- a/solution/1900-1999/1903.Largest Odd Number in String/README_EN.md +++ b/solution/1900-1999/1903.Largest Odd Number in String/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string $num$. Igno +#### Python3 + ```python class Solution: def largestOddNumber(self, num: str) -> str: @@ -80,6 +82,8 @@ class Solution: return '' ``` +#### Java + ```java class Solution { public String largestOddNumber(String num) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func largestOddNumber(num string) string { for i := len(num) - 1; i >= 0; i-- { @@ -121,6 +129,8 @@ func largestOddNumber(num string) string { } ``` +#### TypeScript + ```ts function largestOddNumber(num: string): string { for (let i = num.length - 1; ~i; --i) { @@ -132,6 +142,8 @@ function largestOddNumber(num: string): string { } ``` +#### JavaScript + ```js /** * @param {string} num diff --git a/solution/1900-1999/1904.The Number of Full Rounds You Have Played/README.md b/solution/1900-1999/1904.The Number of Full Rounds You Have Played/README.md index 0b6cb90da7f1a..11b55143b8954 100644 --- a/solution/1900-1999/1904.The Number of Full Rounds You Have Played/README.md +++ b/solution/1900-1999/1904.The Number of Full Rounds You Have Played/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfRounds(self, loginTime: str, logoutTime: str) -> int: @@ -100,6 +102,8 @@ class Solution: return max(0, b - a) ``` +#### Java + ```java class Solution { public int numberOfRounds(String loginTime, String logoutTime) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func numberOfRounds(loginTime string, logoutTime string) int { f := func(s string) int { @@ -151,6 +159,8 @@ func numberOfRounds(loginTime string, logoutTime string) int { } ``` +#### TypeScript + ```ts function numberOfRounds(startTime: string, finishTime: string): number { const f = (s: string): number => { diff --git a/solution/1900-1999/1904.The Number of Full Rounds You Have Played/README_EN.md b/solution/1900-1999/1904.The Number of Full Rounds You Have Played/README_EN.md index fe02b23935e2e..22f43c09f0995 100644 --- a/solution/1900-1999/1904.The Number of Full Rounds You Have Played/README_EN.md +++ b/solution/1900-1999/1904.The Number of Full Rounds You Have Played/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def numberOfRounds(self, loginTime: str, logoutTime: str) -> int: @@ -97,6 +99,8 @@ class Solution: return max(0, b - a) ``` +#### Java + ```java class Solution { public int numberOfRounds(String loginTime, String logoutTime) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func numberOfRounds(loginTime string, logoutTime string) int { f := func(s string) int { @@ -148,6 +156,8 @@ func numberOfRounds(loginTime string, logoutTime string) int { } ``` +#### TypeScript + ```ts function numberOfRounds(startTime: string, finishTime: string): number { const f = (s: string): number => { diff --git a/solution/1900-1999/1905.Count Sub Islands/README.md b/solution/1900-1999/1905.Count Sub Islands/README.md index 55aae85e2cc52..90a0319ccf599 100644 --- a/solution/1900-1999/1905.Count Sub Islands/README.md +++ b/solution/1900-1999/1905.Count Sub Islands/README.md @@ -71,6 +71,8 @@ grid2 中标红的 1 区域是子岛屿,总共有 2 个子岛屿。 +#### Python3 + ```python class Solution: def countSubIslands(self, grid1: List[List[int]], grid2: List[List[int]]) -> int: @@ -88,6 +90,8 @@ class Solution: return sum(dfs(i, j) for i in range(m) for j in range(n) if grid2[i][j]) ``` +#### Java + ```java class Solution { private final int[] dirs = {-1, 0, 1, 0, -1}; @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func countSubIslands(grid1 [][]int, grid2 [][]int) (ans int) { m, n := len(grid1), len(grid1[0]) @@ -183,6 +191,8 @@ func countSubIslands(grid1 [][]int, grid2 [][]int) (ans int) { } ``` +#### TypeScript + ```ts function countSubIslands(grid1: number[][], grid2: number[][]): number { const [m, n] = [grid1.length, grid1[0].length]; @@ -220,6 +230,8 @@ function countSubIslands(grid1: number[][], grid2: number[][]): number { +#### Python3 + ```python class Solution: def countSubIslands(self, grid1: List[List[int]], grid2: List[List[int]]) -> int: diff --git a/solution/1900-1999/1905.Count Sub Islands/README_EN.md b/solution/1900-1999/1905.Count Sub Islands/README_EN.md index 623ddc11c5851..f33ae14457631 100644 --- a/solution/1900-1999/1905.Count Sub Islands/README_EN.md +++ b/solution/1900-1999/1905.Count Sub Islands/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def countSubIslands(self, grid1: List[List[int]], grid2: List[List[int]]) -> int: @@ -88,6 +90,8 @@ class Solution: return sum(dfs(i, j) for i in range(m) for j in range(n) if grid2[i][j]) ``` +#### Java + ```java class Solution { private final int[] dirs = {-1, 0, 1, 0, -1}; @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func countSubIslands(grid1 [][]int, grid2 [][]int) (ans int) { m, n := len(grid1), len(grid1[0]) @@ -183,6 +191,8 @@ func countSubIslands(grid1 [][]int, grid2 [][]int) (ans int) { } ``` +#### TypeScript + ```ts function countSubIslands(grid1: number[][], grid2: number[][]): number { const [m, n] = [grid1.length, grid1[0].length]; @@ -220,6 +230,8 @@ function countSubIslands(grid1: number[][], grid2: number[][]): number { +#### Python3 + ```python class Solution: def countSubIslands(self, grid1: List[List[int]], grid2: List[List[int]]) -> int: diff --git a/solution/1900-1999/1906.Minimum Absolute Difference Queries/README.md b/solution/1900-1999/1906.Minimum Absolute Difference Queries/README.md index 6928d35c8cd39..e36371adefa33 100644 --- a/solution/1900-1999/1906.Minimum Absolute Difference Queries/README.md +++ b/solution/1900-1999/1906.Minimum Absolute Difference Queries/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def minDifference(self, nums: List[int], queries: List[List[int]]) -> List[int]: @@ -111,6 +113,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] minDifference(int[] nums, int[][] queries) { @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -182,6 +188,8 @@ public: }; ``` +#### Go + ```go func minDifference(nums []int, queries [][]int) []int { m, n := len(nums), len(queries) @@ -219,6 +227,8 @@ func minDifference(nums []int, queries [][]int) []int { } ``` +#### TypeScript + ```ts function minDifference(nums: number[], queries: number[][]): number[] { let m = nums.length, diff --git a/solution/1900-1999/1906.Minimum Absolute Difference Queries/README_EN.md b/solution/1900-1999/1906.Minimum Absolute Difference Queries/README_EN.md index ac0b93baf04ed..ba049626a4344 100644 --- a/solution/1900-1999/1906.Minimum Absolute Difference Queries/README_EN.md +++ b/solution/1900-1999/1906.Minimum Absolute Difference Queries/README_EN.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def minDifference(self, nums: List[int], queries: List[List[int]]) -> List[int]: @@ -110,6 +112,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] minDifference(int[] nums, int[][] queries) { @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func minDifference(nums []int, queries [][]int) []int { m, n := len(nums), len(queries) @@ -218,6 +226,8 @@ func minDifference(nums []int, queries [][]int) []int { } ``` +#### TypeScript + ```ts function minDifference(nums: number[], queries: number[][]): number[] { let m = nums.length, diff --git a/solution/1900-1999/1907.Count Salary Categories/README.md b/solution/1900-1999/1907.Count Salary Categories/README.md index 9849d88a2da20..8e67c8daed727 100644 --- a/solution/1900-1999/1907.Count Salary Categories/README.md +++ b/solution/1900-1999/1907.Count Salary Categories/README.md @@ -87,6 +87,8 @@ Accounts 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -126,6 +128,8 @@ FROM +#### MySQL + ```sql # Write your MySQL query statement below SELECT 'Low Salary' AS category, IFNULL(SUM(income < 20000), 0) AS accounts_count FROM Accounts diff --git a/solution/1900-1999/1907.Count Salary Categories/README_EN.md b/solution/1900-1999/1907.Count Salary Categories/README_EN.md index 10724fd51fb85..1f5e940862cdb 100644 --- a/solution/1900-1999/1907.Count Salary Categories/README_EN.md +++ b/solution/1900-1999/1907.Count Salary Categories/README_EN.md @@ -85,6 +85,8 @@ We can first create a temporary table containing all salary categories, and then +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -124,6 +126,8 @@ We can filter out the number of bank accounts for each salary category separatel +#### MySQL + ```sql # Write your MySQL query statement below SELECT 'Low Salary' AS category, IFNULL(SUM(income < 20000), 0) AS accounts_count FROM Accounts diff --git a/solution/1900-1999/1908.Game of Nim/README.md b/solution/1900-1999/1908.Game of Nim/README.md index d73d78e615515..f19724e06d719 100644 --- a/solution/1900-1999/1908.Game of Nim/README.md +++ b/solution/1900-1999/1908.Game of Nim/README.md @@ -100,6 +100,8 @@ tags: +#### Python3 + ```python class Solution: def nimGame(self, piles: List[int]) -> bool: @@ -117,6 +119,8 @@ class Solution: return dfs(tuple(piles)) ``` +#### Java + ```java class Solution { private Map memo = new HashMap<>(); @@ -163,6 +167,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -201,6 +207,8 @@ public: }; ``` +#### Go + ```go func nimGame(piles []int) bool { memo := map[int]bool{} @@ -240,6 +248,8 @@ func nimGame(piles []int) bool { } ``` +#### TypeScript + ```ts function nimGame(piles: number[]): boolean { const p: number[] = Array(8).fill(1); diff --git a/solution/1900-1999/1908.Game of Nim/README_EN.md b/solution/1900-1999/1908.Game of Nim/README_EN.md index 8fb976cdb2da3..c414c66669621 100644 --- a/solution/1900-1999/1908.Game of Nim/README_EN.md +++ b/solution/1900-1999/1908.Game of Nim/README_EN.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def nimGame(self, piles: List[int]) -> bool: @@ -102,6 +104,8 @@ class Solution: return dfs(tuple(piles)) ``` +#### Java + ```java class Solution { private Map memo = new HashMap<>(); @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go func nimGame(piles []int) bool { memo := map[int]bool{} @@ -225,6 +233,8 @@ func nimGame(piles []int) bool { } ``` +#### TypeScript + ```ts function nimGame(piles: number[]): boolean { const p: number[] = Array(8).fill(1); diff --git a/solution/1900-1999/1909.Remove One Element to Make the Array Strictly Increasing/README.md b/solution/1900-1999/1909.Remove One Element to Make the Array Strictly Increasing/README.md index 5d505e871d26a..ad7b37699704e 100644 --- a/solution/1900-1999/1909.Remove One Element to Make the Array Strictly Increasing/README.md +++ b/solution/1900-1999/1909.Remove One Element to Make the Array Strictly Increasing/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def canBeIncreasing(self, nums: List[int]) -> bool: @@ -96,6 +98,8 @@ class Solution: return check(nums, i - 1) or check(nums, i) ``` +#### Java + ```java class Solution { public boolean canBeIncreasing(int[] nums) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func canBeIncreasing(nums []int) bool { i, n := 1, len(nums) @@ -167,6 +175,8 @@ func check(nums []int, i int) bool { } ``` +#### TypeScript + ```ts function canBeIncreasing(nums: number[]): boolean { const check = (p: number) => { @@ -190,6 +200,8 @@ function canBeIncreasing(nums: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn can_be_increasing(nums: Vec) -> bool { diff --git a/solution/1900-1999/1909.Remove One Element to Make the Array Strictly Increasing/README_EN.md b/solution/1900-1999/1909.Remove One Element to Make the Array Strictly Increasing/README_EN.md index 2693e8d5824c9..a91056b311766 100644 --- a/solution/1900-1999/1909.Remove One Element to Make the Array Strictly Increasing/README_EN.md +++ b/solution/1900-1999/1909.Remove One Element to Make the Array Strictly Increasing/README_EN.md @@ -71,6 +71,8 @@ No resulting array is strictly increasing, so return false. +#### Python3 + ```python class Solution: def canBeIncreasing(self, nums: List[int]) -> bool: @@ -90,6 +92,8 @@ class Solution: return check(nums, i - 1) or check(nums, i) ``` +#### Java + ```java class Solution { public boolean canBeIncreasing(int[] nums) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func canBeIncreasing(nums []int) bool { i, n := 1, len(nums) @@ -161,6 +169,8 @@ func check(nums []int, i int) bool { } ``` +#### TypeScript + ```ts function canBeIncreasing(nums: number[]): boolean { const check = (p: number) => { @@ -184,6 +194,8 @@ function canBeIncreasing(nums: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn can_be_increasing(nums: Vec) -> bool { diff --git a/solution/1900-1999/1910.Remove All Occurrences of a Substring/README.md b/solution/1900-1999/1910.Remove All Occurrences of a Substring/README.md index d35eda7358e49..0a57cd8800d79 100644 --- a/solution/1900-1999/1910.Remove All Occurrences of a Substring/README.md +++ b/solution/1900-1999/1910.Remove All Occurrences of a Substring/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def removeOccurrences(self, s: str, part: str) -> str: @@ -85,6 +87,8 @@ class Solution: return s ``` +#### Java + ```java class Solution { public String removeOccurrences(String s, String part) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func removeOccurrences(s string, part string) string { for strings.Contains(s, part) { @@ -118,6 +126,8 @@ func removeOccurrences(s string, part string) string { } ``` +#### TypeScript + ```ts function removeOccurrences(s: string, part: string): string { while (s.includes(part)) { diff --git a/solution/1900-1999/1910.Remove All Occurrences of a Substring/README_EN.md b/solution/1900-1999/1910.Remove All Occurrences of a Substring/README_EN.md index acdf2d09a5e16..d00a53cc53f62 100644 --- a/solution/1900-1999/1910.Remove All Occurrences of a Substring/README_EN.md +++ b/solution/1900-1999/1910.Remove All Occurrences of a Substring/README_EN.md @@ -73,6 +73,8 @@ Now s has no occurrences of "xy". +#### Python3 + ```python class Solution: def removeOccurrences(self, s: str, part: str) -> str: @@ -81,6 +83,8 @@ class Solution: return s ``` +#### Java + ```java class Solution { public String removeOccurrences(String s, String part) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func removeOccurrences(s string, part string) string { for strings.Contains(s, part) { @@ -114,6 +122,8 @@ func removeOccurrences(s string, part string) string { } ``` +#### TypeScript + ```ts function removeOccurrences(s: string, part: string): string { while (s.includes(part)) { diff --git a/solution/1900-1999/1911.Maximum Alternating Subsequence Sum/README.md b/solution/1900-1999/1911.Maximum Alternating Subsequence Sum/README.md index 73a8bc9fb968f..ba6142c972524 100644 --- a/solution/1900-1999/1911.Maximum Alternating Subsequence Sum/README.md +++ b/solution/1900-1999/1911.Maximum Alternating Subsequence Sum/README.md @@ -97,6 +97,8 @@ $$ +#### Python3 + ```python class Solution: def maxAlternatingSum(self, nums: List[int]) -> int: @@ -109,6 +111,8 @@ class Solution: return max(f[n], g[n]) ``` +#### Java + ```java class Solution { public long maxAlternatingSum(int[] nums) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func maxAlternatingSum(nums []int) int64 { n := len(nums) @@ -153,6 +161,8 @@ func maxAlternatingSum(nums []int) int64 { } ``` +#### TypeScript + ```ts function maxAlternatingSum(nums: number[]): number { const n = nums.length; @@ -176,6 +186,8 @@ function maxAlternatingSum(nums: number[]): number { +#### Python3 + ```python class Solution: def maxAlternatingSum(self, nums: List[int]) -> int: @@ -185,6 +197,8 @@ class Solution: return max(f, g) ``` +#### Java + ```java class Solution { public long maxAlternatingSum(int[] nums) { @@ -200,6 +214,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -214,6 +230,8 @@ public: }; ``` +#### Go + ```go func maxAlternatingSum(nums []int) int64 { var f, g int @@ -224,6 +242,8 @@ func maxAlternatingSum(nums []int) int64 { } ``` +#### TypeScript + ```ts function maxAlternatingSum(nums: number[]): number { let [f, g] = [0, 0]; diff --git a/solution/1900-1999/1911.Maximum Alternating Subsequence Sum/README_EN.md b/solution/1900-1999/1911.Maximum Alternating Subsequence Sum/README_EN.md index abecee5c262ac..76cda62341188 100644 --- a/solution/1900-1999/1911.Maximum Alternating Subsequence Sum/README_EN.md +++ b/solution/1900-1999/1911.Maximum Alternating Subsequence Sum/README_EN.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python class Solution: def maxAlternatingSum(self, nums: List[int]) -> int: @@ -107,6 +109,8 @@ class Solution: return max(f[n], g[n]) ``` +#### Java + ```java class Solution { public long maxAlternatingSum(int[] nums) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func maxAlternatingSum(nums []int) int64 { n := len(nums) @@ -151,6 +159,8 @@ func maxAlternatingSum(nums []int) int64 { } ``` +#### TypeScript + ```ts function maxAlternatingSum(nums: number[]): number { const n = nums.length; @@ -174,6 +184,8 @@ function maxAlternatingSum(nums: number[]): number { +#### Python3 + ```python class Solution: def maxAlternatingSum(self, nums: List[int]) -> int: @@ -183,6 +195,8 @@ class Solution: return max(f, g) ``` +#### Java + ```java class Solution { public long maxAlternatingSum(int[] nums) { @@ -198,6 +212,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -212,6 +228,8 @@ public: }; ``` +#### Go + ```go func maxAlternatingSum(nums []int) int64 { var f, g int @@ -222,6 +240,8 @@ func maxAlternatingSum(nums []int) int64 { } ``` +#### TypeScript + ```ts function maxAlternatingSum(nums: number[]): number { let [f, g] = [0, 0]; diff --git a/solution/1900-1999/1912.Design Movie Rental System/README.md b/solution/1900-1999/1912.Design Movie Rental System/README.md index 44b659fc0b43b..e74d1c1ad4bda 100644 --- a/solution/1900-1999/1912.Design Movie Rental System/README.md +++ b/solution/1900-1999/1912.Design Movie Rental System/README.md @@ -91,6 +91,8 @@ movieRentingSystem.search(2); // 返回 [0, 1] 。商店 0 和 1 有未借出 +#### Python3 + ```python from sortedcontainers import SortedList diff --git a/solution/1900-1999/1912.Design Movie Rental System/README_EN.md b/solution/1900-1999/1912.Design Movie Rental System/README_EN.md index 4630330ac7b83..bcd3e54891b5f 100644 --- a/solution/1900-1999/1912.Design Movie Rental System/README_EN.md +++ b/solution/1900-1999/1912.Design Movie Rental System/README_EN.md @@ -89,6 +89,8 @@ movieRentingSystem.search(2); // return [0, 1]. Movies of ID 2 are unrented at +#### Python3 + ```python from sortedcontainers import SortedList diff --git a/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/README.md b/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/README.md index f192043cd7947..67c793d95568f 100644 --- a/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/README.md +++ b/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def maxProductDifference(self, nums: List[int]) -> int: @@ -73,6 +75,8 @@ class Solution: return nums[-1] * nums[-2] - nums[0] * nums[1] ``` +#### Java + ```java class Solution { public int maxProductDifference(int[] nums) { @@ -83,6 +87,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -94,6 +100,8 @@ public: }; ``` +#### Go + ```go func maxProductDifference(nums []int) int { sort.Ints(nums) @@ -102,6 +110,8 @@ func maxProductDifference(nums []int) int { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/README_EN.md b/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/README_EN.md index 6cdc2935ba2ab..806f7cb640d4f 100644 --- a/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/README_EN.md +++ b/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/README_EN.md @@ -83,6 +83,8 @@ The product difference is (9 * 8) - (2 * 4) = 64. +#### Python3 + ```python class Solution: def maxProductDifference(self, nums: List[int]) -> int: @@ -90,6 +92,8 @@ class Solution: return nums[-1] * nums[-2] - nums[0] * nums[1] ``` +#### Java + ```java class Solution { public int maxProductDifference(int[] nums) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func maxProductDifference(nums []int) int { sort.Ints(nums) @@ -119,6 +127,8 @@ func maxProductDifference(nums []int) int { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/1900-1999/1914.Cyclically Rotating a Grid/README.md b/solution/1900-1999/1914.Cyclically Rotating a Grid/README.md index f4c533e7750ee..803bfc4f7102b 100644 --- a/solution/1900-1999/1914.Cyclically Rotating a Grid/README.md +++ b/solution/1900-1999/1914.Cyclically Rotating a Grid/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def rotateGrid(self, grid: List[List[int]], k: int) -> List[List[int]]: @@ -112,6 +114,8 @@ class Solution: return grid ``` +#### Java + ```java class Solution { private int m; @@ -163,6 +167,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -208,6 +214,8 @@ public: }; ``` +#### Go + ```go func rotateGrid(grid [][]int, k int) [][]int { m, n := len(grid), len(grid[0]) @@ -256,6 +264,8 @@ func rotateGrid(grid [][]int, k int) [][]int { } ``` +#### TypeScript + ```ts function rotateGrid(grid: number[][], k: number): number[][] { const m = grid.length; diff --git a/solution/1900-1999/1914.Cyclically Rotating a Grid/README_EN.md b/solution/1900-1999/1914.Cyclically Rotating a Grid/README_EN.md index fe96bf4428a28..2b5a5d14a34c7 100644 --- a/solution/1900-1999/1914.Cyclically Rotating a Grid/README_EN.md +++ b/solution/1900-1999/1914.Cyclically Rotating a Grid/README_EN.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def rotateGrid(self, grid: List[List[int]], k: int) -> List[List[int]]: @@ -129,6 +131,8 @@ class Solution: return grid ``` +#### Java + ```java class Solution { private int m; @@ -180,6 +184,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -225,6 +231,8 @@ public: }; ``` +#### Go + ```go func rotateGrid(grid [][]int, k int) [][]int { m, n := len(grid), len(grid[0]) @@ -273,6 +281,8 @@ func rotateGrid(grid [][]int, k int) [][]int { } ``` +#### TypeScript + ```ts function rotateGrid(grid: number[][], k: number): number[][] { const m = grid.length; diff --git a/solution/1900-1999/1915.Number of Wonderful Substrings/README.md b/solution/1900-1999/1915.Number of Wonderful Substrings/README.md index 78584d2e51773..330fc708bbb1b 100644 --- a/solution/1900-1999/1915.Number of Wonderful Substrings/README.md +++ b/solution/1900-1999/1915.Number of Wonderful Substrings/README.md @@ -103,6 +103,8 @@ tags: +#### Python3 + ```python class Solution: def wonderfulSubstrings(self, word: str) -> int: @@ -117,6 +119,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long wonderfulSubstrings(String word) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func wonderfulSubstrings(word string) (ans int64) { cnt := [1024]int{1} @@ -173,6 +181,8 @@ func wonderfulSubstrings(word string) (ans int64) { } ``` +#### TypeScript + ```ts function wonderfulSubstrings(word: string): number { const cnt: number[] = new Array(1 << 10).fill(0); @@ -191,6 +201,8 @@ function wonderfulSubstrings(word: string): number { } ``` +#### JavaScript + ```js /** * @param {string} word diff --git a/solution/1900-1999/1915.Number of Wonderful Substrings/README_EN.md b/solution/1900-1999/1915.Number of Wonderful Substrings/README_EN.md index 4794bebba2d61..e6048268f5cc4 100644 --- a/solution/1900-1999/1915.Number of Wonderful Substrings/README_EN.md +++ b/solution/1900-1999/1915.Number of Wonderful Substrings/README_EN.md @@ -123,6 +123,8 @@ tags: +#### Python3 + ```python class Solution: def wonderfulSubstrings(self, word: str) -> int: @@ -137,6 +139,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long wonderfulSubstrings(String word) { @@ -157,6 +161,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go func wonderfulSubstrings(word string) (ans int64) { cnt := [1024]int{1} @@ -193,6 +201,8 @@ func wonderfulSubstrings(word string) (ans int64) { } ``` +#### TypeScript + ```ts function wonderfulSubstrings(word: string): number { const cnt: number[] = new Array(1 << 10).fill(0); @@ -211,6 +221,8 @@ function wonderfulSubstrings(word: string): number { } ``` +#### JavaScript + ```js /** * @param {string} word diff --git a/solution/1900-1999/1916.Count Ways to Build Rooms in an Ant Colony/README.md b/solution/1900-1999/1916.Count Ways to Build Rooms in an Ant Colony/README.md index 6c96c62ab88d6..7ef328b99decf 100644 --- a/solution/1900-1999/1916.Count Ways to Build Rooms in an Ant Colony/README.md +++ b/solution/1900-1999/1916.Count Ways to Build Rooms in an Ant Colony/README.md @@ -77,18 +77,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1900-1999/1916.Count Ways to Build Rooms in an Ant Colony/README_EN.md b/solution/1900-1999/1916.Count Ways to Build Rooms in an Ant Colony/README_EN.md index 523a1fa1c8c06..c560e572345c8 100644 --- a/solution/1900-1999/1916.Count Ways to Build Rooms in an Ant Colony/README_EN.md +++ b/solution/1900-1999/1916.Count Ways to Build Rooms in an Ant Colony/README_EN.md @@ -101,18 +101,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1900-1999/1917.Leetcodify Friends Recommendations/README.md b/solution/1900-1999/1917.Leetcodify Friends Recommendations/README.md index 8bbeface00f7f..ed14577570614 100644 --- a/solution/1900-1999/1917.Leetcodify Friends Recommendations/README.md +++ b/solution/1900-1999/1917.Leetcodify Friends Recommendations/README.md @@ -121,6 +121,8 @@ Friendship 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1900-1999/1917.Leetcodify Friends Recommendations/README_EN.md b/solution/1900-1999/1917.Leetcodify Friends Recommendations/README_EN.md index 19af0013ed2d6..b27297aa31d93 100644 --- a/solution/1900-1999/1917.Leetcodify Friends Recommendations/README_EN.md +++ b/solution/1900-1999/1917.Leetcodify Friends Recommendations/README_EN.md @@ -120,6 +120,8 @@ Similarly, we can see that users 2 and 3 listened to songs 10, 11, and 12 on the +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1900-1999/1918.Kth Smallest Subarray Sum/README.md b/solution/1900-1999/1918.Kth Smallest Subarray Sum/README.md index df80208a2df91..8fafc58f2d6fd 100644 --- a/solution/1900-1999/1918.Kth Smallest Subarray Sum/README.md +++ b/solution/1900-1999/1918.Kth Smallest Subarray Sum/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python class Solution: def kthSmallestSubarraySum(self, nums: List[int], k: int) -> int: @@ -113,6 +115,8 @@ class Solution: return l + bisect_left(range(l, r + 1), True, key=f) ``` +#### Java + ```java class Solution { public int kthSmallestSubarraySum(int[] nums, int k) { @@ -147,6 +151,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -180,6 +186,8 @@ public: }; ``` +#### Go + ```go func kthSmallestSubarraySum(nums []int, k int) int { l, r := 1<<30, 0 diff --git a/solution/1900-1999/1918.Kth Smallest Subarray Sum/README_EN.md b/solution/1900-1999/1918.Kth Smallest Subarray Sum/README_EN.md index a0a281329ff54..5048063fda753 100644 --- a/solution/1900-1999/1918.Kth Smallest Subarray Sum/README_EN.md +++ b/solution/1900-1999/1918.Kth Smallest Subarray Sum/README_EN.md @@ -77,6 +77,8 @@ Ordering the sums from smallest to largest gives 3, 3, 5, 5, 6, 8, 10, 11 +#### Python3 + ```python class Solution: def kthSmallestSubarraySum(self, nums: List[int], k: int) -> int: @@ -95,6 +97,8 @@ class Solution: return l + bisect_left(range(l, r + 1), True, key=f) ``` +#### Java + ```java class Solution { public int kthSmallestSubarraySum(int[] nums, int k) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func kthSmallestSubarraySum(nums []int, k int) int { l, r := 1<<30, 0 diff --git a/solution/1900-1999/1919.Leetcodify Similar Friends/README.md b/solution/1900-1999/1919.Leetcodify Similar Friends/README.md index b1bf8ac05c751..2277b135f0df1 100644 --- a/solution/1900-1999/1919.Leetcodify Similar Friends/README.md +++ b/solution/1900-1999/1919.Leetcodify Similar Friends/README.md @@ -115,6 +115,8 @@ Friendship table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT DISTINCT user1_id, user2_id diff --git a/solution/1900-1999/1919.Leetcodify Similar Friends/README_EN.md b/solution/1900-1999/1919.Leetcodify Similar Friends/README_EN.md index ebb4a943edf65..5de14041727c8 100644 --- a/solution/1900-1999/1919.Leetcodify Similar Friends/README_EN.md +++ b/solution/1900-1999/1919.Leetcodify Similar Friends/README_EN.md @@ -115,6 +115,8 @@ Users 2 and 5 are friends and listened to songs 10, 11, and 12, but they did not +#### MySQL + ```sql # Write your MySQL query statement below SELECT DISTINCT user1_id, user2_id diff --git a/solution/1900-1999/1920.Build Array from Permutation/README.md b/solution/1900-1999/1920.Build Array from Permutation/README.md index 7f56798f4e4e1..c9327e72df808 100644 --- a/solution/1900-1999/1920.Build Array from Permutation/README.md +++ b/solution/1900-1999/1920.Build Array from Permutation/README.md @@ -69,12 +69,16 @@ ans = [nums[nums[0]], nums[nums[1]], nums[nums[2]], nums[nums[3]], nums[nums[4]] +#### Python3 + ```python class Solution: def buildArray(self, nums: List[int]) -> List[int]: return [nums[num] for num in nums] ``` +#### Java + ```java class Solution { public int[] buildArray(int[] nums) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -100,6 +106,8 @@ public: }; ``` +#### Go + ```go func buildArray(nums []int) []int { ans := make([]int, len(nums)) @@ -110,12 +118,16 @@ func buildArray(nums []int) []int { } ``` +#### TypeScript + ```ts function buildArray(nums: number[]): number[] { return nums.map(v => nums[v]); } ``` +#### Rust + ```rust impl Solution { pub fn build_array(nums: Vec) -> Vec { @@ -126,6 +138,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -140,6 +154,8 @@ var buildArray = function (nums) { }; ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). diff --git a/solution/1900-1999/1920.Build Array from Permutation/README_EN.md b/solution/1900-1999/1920.Build Array from Permutation/README_EN.md index 0709b91489d5d..a755d7426fa6e 100644 --- a/solution/1900-1999/1920.Build Array from Permutation/README_EN.md +++ b/solution/1900-1999/1920.Build Array from Permutation/README_EN.md @@ -66,12 +66,16 @@ ans = [nums[nums[0]], nums[nums[1]], nums[nums[2]], nums[nums[3]], nums[nums[4]] +#### Python3 + ```python class Solution: def buildArray(self, nums: List[int]) -> List[int]: return [nums[num] for num in nums] ``` +#### Java + ```java class Solution { public int[] buildArray(int[] nums) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -97,6 +103,8 @@ public: }; ``` +#### Go + ```go func buildArray(nums []int) []int { ans := make([]int, len(nums)) @@ -107,12 +115,16 @@ func buildArray(nums []int) []int { } ``` +#### TypeScript + ```ts function buildArray(nums: number[]): number[] { return nums.map(v => nums[v]); } ``` +#### Rust + ```rust impl Solution { pub fn build_array(nums: Vec) -> Vec { @@ -123,6 +135,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -137,6 +151,8 @@ var buildArray = function (nums) { }; ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). diff --git a/solution/1900-1999/1921.Eliminate Maximum Number of Monsters/README.md b/solution/1900-1999/1921.Eliminate Maximum Number of Monsters/README.md index f11528dc4808a..a94e4baeba78e 100644 --- a/solution/1900-1999/1921.Eliminate Maximum Number of Monsters/README.md +++ b/solution/1900-1999/1921.Eliminate Maximum Number of Monsters/README.md @@ -97,6 +97,8 @@ $$times[i] = \lfloor \frac{dist[i]-1}{speed[i]} \rfloor$$ +#### Python3 + ```python class Solution: def eliminateMaximum(self, dist: List[int], speed: List[int]) -> int: @@ -107,6 +109,8 @@ class Solution: return len(times) ``` +#### Java + ```java class Solution { public int eliminateMaximum(int[] dist, int[] speed) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func eliminateMaximum(dist []int, speed []int) int { n := len(dist) @@ -163,6 +171,8 @@ func eliminateMaximum(dist []int, speed []int) int { } ``` +#### TypeScript + ```ts function eliminateMaximum(dist: number[], speed: number[]): number { const n = dist.length; @@ -180,6 +190,8 @@ function eliminateMaximum(dist: number[], speed: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} dist @@ -201,6 +213,8 @@ var eliminateMaximum = function (dist, speed) { }; ``` +#### C# + ```cs public class Solution { public int EliminateMaximum(int[] dist, int[] speed) { diff --git a/solution/1900-1999/1921.Eliminate Maximum Number of Monsters/README_EN.md b/solution/1900-1999/1921.Eliminate Maximum Number of Monsters/README_EN.md index 2d556062a209a..d4bb1dc74e0e8 100644 --- a/solution/1900-1999/1921.Eliminate Maximum Number of Monsters/README_EN.md +++ b/solution/1900-1999/1921.Eliminate Maximum Number of Monsters/README_EN.md @@ -83,6 +83,8 @@ You can only eliminate 1 monster. +#### Python3 + ```python class Solution: def eliminateMaximum(self, dist: List[int], speed: List[int]) -> int: @@ -93,6 +95,8 @@ class Solution: return len(times) ``` +#### Java + ```java class Solution { public int eliminateMaximum(int[] dist, int[] speed) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func eliminateMaximum(dist []int, speed []int) int { n := len(dist) @@ -149,6 +157,8 @@ func eliminateMaximum(dist []int, speed []int) int { } ``` +#### TypeScript + ```ts function eliminateMaximum(dist: number[], speed: number[]): number { const n = dist.length; @@ -166,6 +176,8 @@ function eliminateMaximum(dist: number[], speed: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} dist @@ -187,6 +199,8 @@ var eliminateMaximum = function (dist, speed) { }; ``` +#### C# + ```cs public class Solution { public int EliminateMaximum(int[] dist, int[] speed) { diff --git a/solution/1900-1999/1922.Count Good Numbers/README.md b/solution/1900-1999/1922.Count Good Numbers/README.md index d1975745e0e59..e7054911b43c7 100644 --- a/solution/1900-1999/1922.Count Good Numbers/README.md +++ b/solution/1900-1999/1922.Count Good Numbers/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def countGoodNumbers(self, n: int) -> int: @@ -88,6 +90,8 @@ class Solution: return myPow(5, (n + 1) >> 1) * myPow(4, n >> 1) % mod ``` +#### Java + ```java class Solution { private int mod = 1000000007; @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp int MOD = 1000000007; @@ -134,6 +140,8 @@ private: }; ``` +#### Go + ```go const mod int64 = 1e9 + 7 diff --git a/solution/1900-1999/1922.Count Good Numbers/README_EN.md b/solution/1900-1999/1922.Count Good Numbers/README_EN.md index 938137ff41b71..b69c7c28f34a5 100644 --- a/solution/1900-1999/1922.Count Good Numbers/README_EN.md +++ b/solution/1900-1999/1922.Count Good Numbers/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def countGoodNumbers(self, n: int) -> int: @@ -86,6 +88,8 @@ class Solution: return myPow(5, (n + 1) >> 1) * myPow(4, n >> 1) % mod ``` +#### Java + ```java class Solution { private int mod = 1000000007; @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp int MOD = 1000000007; @@ -132,6 +138,8 @@ private: }; ``` +#### Go + ```go const mod int64 = 1e9 + 7 diff --git a/solution/1900-1999/1923.Longest Common Subpath/README.md b/solution/1900-1999/1923.Longest Common Subpath/README.md index db641861499ff..1d5b1f99dfbf6 100644 --- a/solution/1900-1999/1923.Longest Common Subpath/README.md +++ b/solution/1900-1999/1923.Longest Common Subpath/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def longestCommonSubpath(self, n: int, paths: List[List[int]]) -> int: @@ -129,6 +131,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { int N = 100010; diff --git a/solution/1900-1999/1923.Longest Common Subpath/README_EN.md b/solution/1900-1999/1923.Longest Common Subpath/README_EN.md index f10cb283b183c..3535e2d1768b8 100644 --- a/solution/1900-1999/1923.Longest Common Subpath/README_EN.md +++ b/solution/1900-1999/1923.Longest Common Subpath/README_EN.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def longestCommonSubpath(self, n: int, paths: List[List[int]]) -> int: @@ -119,6 +121,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { int N = 100010; diff --git a/solution/1900-1999/1924.Erect the Fence II/README.md b/solution/1900-1999/1924.Erect the Fence II/README.md index 23d8652607dde..deec3e9652ffd 100644 --- a/solution/1900-1999/1924.Erect the Fence II/README.md +++ b/solution/1900-1999/1924.Erect the Fence II/README.md @@ -66,18 +66,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1900-1999/1924.Erect the Fence II/README_EN.md b/solution/1900-1999/1924.Erect the Fence II/README_EN.md index 29a2c9cb8b20b..1aaaf116c7979 100644 --- a/solution/1900-1999/1924.Erect the Fence II/README_EN.md +++ b/solution/1900-1999/1924.Erect the Fence II/README_EN.md @@ -66,18 +66,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1900-1999/1925.Count Square Sum Triples/README.md b/solution/1900-1999/1925.Count Square Sum Triples/README.md index f35262e4aa808..5433a1a501c94 100644 --- a/solution/1900-1999/1925.Count Square Sum Triples/README.md +++ b/solution/1900-1999/1925.Count Square Sum Triples/README.md @@ -57,6 +57,8 @@ tags: +#### Python3 + ```python class Solution: def countTriples(self, n: int) -> int: @@ -70,6 +72,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public int countTriples(int n) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func countTriples(n int) int { res := 0 diff --git a/solution/1900-1999/1925.Count Square Sum Triples/README_EN.md b/solution/1900-1999/1925.Count Square Sum Triples/README_EN.md index 771bddfce5fa1..a9e377946bc4b 100644 --- a/solution/1900-1999/1925.Count Square Sum Triples/README_EN.md +++ b/solution/1900-1999/1925.Count Square Sum Triples/README_EN.md @@ -57,6 +57,8 @@ tags: +#### Python3 + ```python class Solution: def countTriples(self, n: int) -> int: @@ -70,6 +72,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public int countTriples(int n) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func countTriples(n int) int { res := 0 diff --git a/solution/1900-1999/1926.Nearest Exit from Entrance in Maze/README.md b/solution/1900-1999/1926.Nearest Exit from Entrance in Maze/README.md index eb0bb2f2f936b..b55b4b981160d 100644 --- a/solution/1900-1999/1926.Nearest Exit from Entrance in Maze/README.md +++ b/solution/1900-1999/1926.Nearest Exit from Entrance in Maze/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int: @@ -105,6 +107,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int nearestExit(char[][] maze, int[] entrance) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go func nearestExit(maze [][]byte, entrance []int) int { m, n := len(maze), len(maze[0]) diff --git a/solution/1900-1999/1926.Nearest Exit from Entrance in Maze/README_EN.md b/solution/1900-1999/1926.Nearest Exit from Entrance in Maze/README_EN.md index 021cccbc38d82..55c403a06c6a6 100644 --- a/solution/1900-1999/1926.Nearest Exit from Entrance in Maze/README_EN.md +++ b/solution/1900-1999/1926.Nearest Exit from Entrance in Maze/README_EN.md @@ -84,6 +84,8 @@ Thus, the nearest exit is [1,2], which is 2 steps away. +#### Python3 + ```python class Solution: def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int: @@ -106,6 +108,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int nearestExit(char[][] maze, int[] entrance) { @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func nearestExit(maze [][]byte, entrance []int) int { m, n := len(maze), len(maze[0]) diff --git a/solution/1900-1999/1927.Sum Game/README.md b/solution/1900-1999/1927.Sum Game/README.md index 362de250533d9..ee7f98ea86f34 100644 --- a/solution/1900-1999/1927.Sum Game/README.md +++ b/solution/1900-1999/1927.Sum Game/README.md @@ -108,6 +108,8 @@ Bob 获胜,因为 9 + 3 + 2 + 9 = 5 + 9 + 2 + 7 。 +#### Python3 + ```python class Solution: def sumGame(self, num: str) -> bool: @@ -119,6 +121,8 @@ class Solution: return (cnt1 + cnt2) % 2 == 1 or s1 - s2 != 9 * (cnt2 - cnt1) // 2 ``` +#### Java + ```java class Solution { public boolean sumGame(String num) { @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go func sumGame(num string) bool { n := len(num) @@ -192,6 +200,8 @@ func sumGame(num string) bool { } ``` +#### TypeScript + ```ts function sumGame(num: string): boolean { const n = num.length; diff --git a/solution/1900-1999/1927.Sum Game/README_EN.md b/solution/1900-1999/1927.Sum Game/README_EN.md index 677984e09f58a..0f5be2c9c940a 100644 --- a/solution/1900-1999/1927.Sum Game/README_EN.md +++ b/solution/1900-1999/1927.Sum Game/README_EN.md @@ -90,6 +90,8 @@ Bob wins because 9 + 3 + 2 + 9 = 5 + 9 + 2 + 7. +#### Python3 + ```python class Solution: def sumGame(self, num: str) -> bool: @@ -101,6 +103,8 @@ class Solution: return (cnt1 + cnt2) % 2 == 1 or s1 - s2 != 9 * (cnt2 - cnt1) // 2 ``` +#### Java + ```java class Solution { public boolean sumGame(String num) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func sumGame(num string) bool { n := len(num) @@ -174,6 +182,8 @@ func sumGame(num string) bool { } ``` +#### TypeScript + ```ts function sumGame(num: string): boolean { const n = num.length; diff --git a/solution/1900-1999/1928.Minimum Cost to Reach Destination in Time/README.md b/solution/1900-1999/1928.Minimum Cost to Reach Destination in Time/README.md index fe60c03681609..f06cbb9744d3b 100644 --- a/solution/1900-1999/1928.Minimum Cost to Reach Destination in Time/README.md +++ b/solution/1900-1999/1928.Minimum Cost to Reach Destination in Time/README.md @@ -85,18 +85,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1900-1999/1928.Minimum Cost to Reach Destination in Time/README_EN.md b/solution/1900-1999/1928.Minimum Cost to Reach Destination in Time/README_EN.md index 39f4e8fe08456..246779fdf51d0 100644 --- a/solution/1900-1999/1928.Minimum Cost to Reach Destination in Time/README_EN.md +++ b/solution/1900-1999/1928.Minimum Cost to Reach Destination in Time/README_EN.md @@ -83,18 +83,26 @@ You cannot take path 0 -> 1 -> 2 -> 5 since it would take too long. +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1900-1999/1929.Concatenation of Array/README.md b/solution/1900-1999/1929.Concatenation of Array/README.md index 552ef1a5de515..cb5bfa919efac 100644 --- a/solution/1900-1999/1929.Concatenation of Array/README.md +++ b/solution/1900-1999/1929.Concatenation of Array/README.md @@ -71,12 +71,16 @@ tags: +#### Python3 + ```python class Solution: def getConcatenation(self, nums: List[int]) -> List[int]: return nums + nums ``` +#### Java + ```java class Solution { public int[] getConcatenation(int[] nums) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -102,18 +108,24 @@ public: }; ``` +#### Go + ```go func getConcatenation(nums []int) []int { return append(nums, nums...) } ``` +#### TypeScript + ```ts function getConcatenation(nums: number[]): number[] { return [...nums, ...nums]; } ``` +#### Rust + ```rust impl Solution { pub fn get_concatenation(nums: Vec) -> Vec { @@ -122,6 +134,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -134,6 +148,8 @@ var getConcatenation = function (nums) { }; ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). diff --git a/solution/1900-1999/1929.Concatenation of Array/README_EN.md b/solution/1900-1999/1929.Concatenation of Array/README_EN.md index 0b2d836723d4d..bc384edba3963 100644 --- a/solution/1900-1999/1929.Concatenation of Array/README_EN.md +++ b/solution/1900-1999/1929.Concatenation of Array/README_EN.md @@ -64,12 +64,16 @@ tags: +#### Python3 + ```python class Solution: def getConcatenation(self, nums: List[int]) -> List[int]: return nums + nums ``` +#### Java + ```java class Solution { public int[] getConcatenation(int[] nums) { @@ -83,6 +87,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -95,18 +101,24 @@ public: }; ``` +#### Go + ```go func getConcatenation(nums []int) []int { return append(nums, nums...) } ``` +#### TypeScript + ```ts function getConcatenation(nums: number[]): number[] { return [...nums, ...nums]; } ``` +#### Rust + ```rust impl Solution { pub fn get_concatenation(nums: Vec) -> Vec { @@ -115,6 +127,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -127,6 +141,8 @@ var getConcatenation = function (nums) { }; ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). diff --git a/solution/1900-1999/1930.Unique Length-3 Palindromic Subsequences/README.md b/solution/1900-1999/1930.Unique Length-3 Palindromic Subsequences/README.md index b66d5331a5507..16f40d1bbc983 100644 --- a/solution/1900-1999/1930.Unique Length-3 Palindromic Subsequences/README.md +++ b/solution/1900-1999/1930.Unique Length-3 Palindromic Subsequences/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def countPalindromicSubsequence(self, s: str) -> int: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countPalindromicSubsequence(String s) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func countPalindromicSubsequence(s string) (ans int) { for c := 'a'; c <= 'z'; c++ { @@ -149,6 +157,8 @@ func countPalindromicSubsequence(s string) (ans int) { } ``` +#### C# + ```cs public class Solution { public int CountPalindromicSubsequence(string s) { diff --git a/solution/1900-1999/1930.Unique Length-3 Palindromic Subsequences/README_EN.md b/solution/1900-1999/1930.Unique Length-3 Palindromic Subsequences/README_EN.md index 0936227213bad..7a2ace64876ac 100644 --- a/solution/1900-1999/1930.Unique Length-3 Palindromic Subsequences/README_EN.md +++ b/solution/1900-1999/1930.Unique Length-3 Palindromic Subsequences/README_EN.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def countPalindromicSubsequence(self, s: str) -> int: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countPalindromicSubsequence(String s) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func countPalindromicSubsequence(s string) (ans int) { for c := 'a'; c <= 'z'; c++ { @@ -141,6 +149,8 @@ func countPalindromicSubsequence(s string) (ans int) { } ``` +#### C# + ```cs public class Solution { public int CountPalindromicSubsequence(string s) { diff --git a/solution/1900-1999/1931.Painting a Grid With Three Different Colors/README.md b/solution/1900-1999/1931.Painting a Grid With Three Different Colors/README.md index a8c53e45ad853..3af675abd5697 100644 --- a/solution/1900-1999/1931.Painting a Grid With Three Different Colors/README.md +++ b/solution/1900-1999/1931.Painting a Grid With Three Different Colors/README.md @@ -82,6 +82,8 @@ $$ +#### Python3 + ```python class Solution: def colorTheGrid(self, m: int, n: int) -> int: @@ -119,6 +121,8 @@ class Solution: return sum(f) % mod ``` +#### Java + ```java class Solution { private int m; @@ -184,6 +188,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -246,6 +252,8 @@ public: }; ``` +#### Go + ```go func colorTheGrid(m int, n int) (ans int) { f1 := func(x int) bool { @@ -303,6 +311,8 @@ func colorTheGrid(m int, n int) (ans int) { } ``` +#### TypeScript + ```ts function colorTheGrid(m: number, n: number): number { const f1 = (x: number): boolean => { diff --git a/solution/1900-1999/1931.Painting a Grid With Three Different Colors/README_EN.md b/solution/1900-1999/1931.Painting a Grid With Three Different Colors/README_EN.md index d6ed1d698a5a4..d27ad61cb964e 100644 --- a/solution/1900-1999/1931.Painting a Grid With Three Different Colors/README_EN.md +++ b/solution/1900-1999/1931.Painting a Grid With Three Different Colors/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O((m + n) \times 3^{2m})$, and the space complexity is $ +#### Python3 + ```python class Solution: def colorTheGrid(self, m: int, n: int) -> int: @@ -117,6 +119,8 @@ class Solution: return sum(f) % mod ``` +#### Java + ```java class Solution { private int m; @@ -182,6 +186,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -244,6 +250,8 @@ public: }; ``` +#### Go + ```go func colorTheGrid(m int, n int) (ans int) { f1 := func(x int) bool { @@ -301,6 +309,8 @@ func colorTheGrid(m int, n int) (ans int) { } ``` +#### TypeScript + ```ts function colorTheGrid(m: number, n: number): number { const f1 = (x: number): boolean => { diff --git a/solution/1900-1999/1932.Merge BSTs to Create Single BST/README.md b/solution/1900-1999/1932.Merge BSTs to Create Single BST/README.md index 8a2e3bfe95280..a44e9eb0d11fa 100644 --- a/solution/1900-1999/1932.Merge BSTs to Create Single BST/README.md +++ b/solution/1900-1999/1932.Merge BSTs to Create Single BST/README.md @@ -101,18 +101,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1900-1999/1932.Merge BSTs to Create Single BST/README_EN.md b/solution/1900-1999/1932.Merge BSTs to Create Single BST/README_EN.md index 711583ef3d590..96dd81b4d3716 100644 --- a/solution/1900-1999/1932.Merge BSTs to Create Single BST/README_EN.md +++ b/solution/1900-1999/1932.Merge BSTs to Create Single BST/README_EN.md @@ -99,18 +99,26 @@ The resulting tree is shown above. This is the only valid operation that can be +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1900-1999/1933.Check if String Is Decomposable Into Value-Equal Substrings/README.md b/solution/1900-1999/1933.Check if String Is Decomposable Into Value-Equal Substrings/README.md index fc5767f8fc637..f49d208cd3ddb 100644 --- a/solution/1900-1999/1933.Check if String Is Decomposable Into Value-Equal Substrings/README.md +++ b/solution/1900-1999/1933.Check if String Is Decomposable Into Value-Equal Substrings/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def isDecomposable(self, s: str) -> bool: @@ -95,6 +97,8 @@ class Solution: return cnt2 == 1 ``` +#### Java + ```java class Solution { public boolean isDecomposable(String s) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func isDecomposable(s string) bool { i, n := 0, len(s) @@ -166,6 +174,8 @@ func isDecomposable(s string) bool { } ``` +#### TypeScript + ```ts function isDecomposable(s: string): boolean { const n = s.length; @@ -197,6 +207,8 @@ function isDecomposable(s: string): boolean { +#### Python3 + ```python class Solution: def isDecomposable(self, s: str) -> bool: diff --git a/solution/1900-1999/1933.Check if String Is Decomposable Into Value-Equal Substrings/README_EN.md b/solution/1900-1999/1933.Check if String Is Decomposable Into Value-Equal Substrings/README_EN.md index 9574316ee2ed8..10136446eb960 100644 --- a/solution/1900-1999/1933.Check if String Is Decomposable Into Value-Equal Substrings/README_EN.md +++ b/solution/1900-1999/1933.Check if String Is Decomposable Into Value-Equal Substrings/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string $s$. The sp +#### Python3 + ```python class Solution: def isDecomposable(self, s: str) -> bool: @@ -96,6 +98,8 @@ class Solution: return cnt2 == 1 ``` +#### Java + ```java class Solution { public boolean isDecomposable(String s) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func isDecomposable(s string) bool { i, n := 0, len(s) @@ -167,6 +175,8 @@ func isDecomposable(s string) bool { } ``` +#### TypeScript + ```ts function isDecomposable(s: string): boolean { const n = s.length; @@ -198,6 +208,8 @@ function isDecomposable(s: string): boolean { +#### Python3 + ```python class Solution: def isDecomposable(self, s: str) -> bool: diff --git a/solution/1900-1999/1934.Confirmation Rate/README.md b/solution/1900-1999/1934.Confirmation Rate/README.md index 08d74089bf66e..5888b5e1ebc52 100644 --- a/solution/1900-1999/1934.Confirmation Rate/README.md +++ b/solution/1900-1999/1934.Confirmation Rate/README.md @@ -109,6 +109,8 @@ Confirmations 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1900-1999/1934.Confirmation Rate/README_EN.md b/solution/1900-1999/1934.Confirmation Rate/README_EN.md index 3b4a697f39fa8..c09305a0ea4ad 100644 --- a/solution/1900-1999/1934.Confirmation Rate/README_EN.md +++ b/solution/1900-1999/1934.Confirmation Rate/README_EN.md @@ -111,6 +111,8 @@ We can use a left join to join the `Signups` table and the `Confirmations` table +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1900-1999/1935.Maximum Number of Words You Can Type/README.md b/solution/1900-1999/1935.Maximum Number of Words You Can Type/README.md index ecc7769df05c5..b81d17f99095b 100644 --- a/solution/1900-1999/1935.Maximum Number of Words You Can Type/README.md +++ b/solution/1900-1999/1935.Maximum Number of Words You Can Type/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def canBeTypedWords(self, text: str, brokenLetters: str) -> int: @@ -83,6 +85,8 @@ class Solution: return sum(all(c not in s for c in w) for w in text.split()) ``` +#### Java + ```java class Solution { public int canBeTypedWords(String text, String brokenLetters) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func canBeTypedWords(text string, brokenLetters string) (ans int) { s := [26]bool{} @@ -162,6 +170,8 @@ func canBeTypedWords(text string, brokenLetters string) (ans int) { } ``` +#### TypeScript + ```ts function canBeTypedWords(text: string, brokenLetters: string): number { const s: boolean[] = Array(26).fill(false); @@ -182,6 +192,8 @@ function canBeTypedWords(text: string, brokenLetters: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn can_be_typed_words(text: String, broken_letters: String) -> i32 { diff --git a/solution/1900-1999/1935.Maximum Number of Words You Can Type/README_EN.md b/solution/1900-1999/1935.Maximum Number of Words You Can Type/README_EN.md index 0c97f375d9dd2..d1d843f3f838a 100644 --- a/solution/1900-1999/1935.Maximum Number of Words You Can Type/README_EN.md +++ b/solution/1900-1999/1935.Maximum Number of Words You Can Type/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n)$, and the space complexity is $O(|\Sigma|)$, where +#### Python3 + ```python class Solution: def canBeTypedWords(self, text: str, brokenLetters: str) -> int: @@ -84,6 +86,8 @@ class Solution: return sum(all(c not in s for c in w) for w in text.split()) ``` +#### Java + ```java class Solution { public int canBeTypedWords(String text, String brokenLetters) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func canBeTypedWords(text string, brokenLetters string) (ans int) { s := [26]bool{} @@ -163,6 +171,8 @@ func canBeTypedWords(text string, brokenLetters string) (ans int) { } ``` +#### TypeScript + ```ts function canBeTypedWords(text: string, brokenLetters: string): number { const s: boolean[] = Array(26).fill(false); @@ -183,6 +193,8 @@ function canBeTypedWords(text: string, brokenLetters: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn can_be_typed_words(text: String, broken_letters: String) -> i32 { diff --git a/solution/1900-1999/1936.Add Minimum Number of Rungs/README.md b/solution/1900-1999/1936.Add Minimum Number of Rungs/README.md index 6cec0fe22aa97..0281e002f7a6f 100644 --- a/solution/1900-1999/1936.Add Minimum Number of Rungs/README.md +++ b/solution/1900-1999/1936.Add Minimum Number of Rungs/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def addRungs(self, rungs: List[int], dist: int) -> int: @@ -98,6 +100,8 @@ class Solution: return sum((b - a - 1) // dist for a, b in pairwise(rungs)) ``` +#### Java + ```java class Solution { public int addRungs(int[] rungs, int dist) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func addRungs(rungs []int, dist int) (ans int) { prev := 0 @@ -136,6 +144,8 @@ func addRungs(rungs []int, dist int) (ans int) { } ``` +#### TypeScript + ```ts function addRungs(rungs: number[], dist: number): number { let ans = 0; @@ -148,6 +158,8 @@ function addRungs(rungs: number[], dist: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn add_rungs(rungs: Vec, dist: i32) -> i32 { diff --git a/solution/1900-1999/1936.Add Minimum Number of Rungs/README_EN.md b/solution/1900-1999/1936.Add Minimum Number of Rungs/README_EN.md index 9c4d4b6cfb4b7..0ba4f926719c6 100644 --- a/solution/1900-1999/1936.Add Minimum Number of Rungs/README_EN.md +++ b/solution/1900-1999/1936.Add Minimum Number of Rungs/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(n)$, where $n$ is the length of `rungs`. The space com +#### Python3 + ```python class Solution: def addRungs(self, rungs: List[int], dist: int) -> int: @@ -88,6 +90,8 @@ class Solution: return sum((b - a - 1) // dist for a, b in pairwise(rungs)) ``` +#### Java + ```java class Solution { public int addRungs(int[] rungs, int dist) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func addRungs(rungs []int, dist int) (ans int) { prev := 0 @@ -126,6 +134,8 @@ func addRungs(rungs []int, dist int) (ans int) { } ``` +#### TypeScript + ```ts function addRungs(rungs: number[], dist: number): number { let ans = 0; @@ -138,6 +148,8 @@ function addRungs(rungs: number[], dist: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn add_rungs(rungs: Vec, dist: i32) -> i32 { diff --git a/solution/1900-1999/1937.Maximum Number of Points with Cost/README.md b/solution/1900-1999/1937.Maximum Number of Points with Cost/README.md index 1ce6e1132da84..3d7c0c60e402c 100644 --- a/solution/1900-1999/1937.Maximum Number of Points with Cost/README.md +++ b/solution/1900-1999/1937.Maximum Number of Points with Cost/README.md @@ -100,6 +100,8 @@ $$ +#### Python3 + ```python class Solution: def maxPoints(self, points: List[List[int]]) -> int: @@ -119,6 +121,8 @@ class Solution: return max(f) ``` +#### Java + ```java class Solution { public long maxPoints(int[][] points) { @@ -147,6 +151,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go func maxPoints(points [][]int) int64 { n := len(points[0]) @@ -195,6 +203,8 @@ func maxPoints(points [][]int) int64 { } ``` +#### TypeScript + ```ts function maxPoints(points: number[][]): number { const n = points[0].length; diff --git a/solution/1900-1999/1937.Maximum Number of Points with Cost/README_EN.md b/solution/1900-1999/1937.Maximum Number of Points with Cost/README_EN.md index 34ceb7a32aa10..94be6938d7f0a 100644 --- a/solution/1900-1999/1937.Maximum Number of Points with Cost/README_EN.md +++ b/solution/1900-1999/1937.Maximum Number of Points with Cost/README_EN.md @@ -80,6 +80,8 @@ Your final score is 12 - 1 = 11. +#### Python3 + ```python class Solution: def maxPoints(self, points: List[List[int]]) -> int: @@ -99,6 +101,8 @@ class Solution: return max(f) ``` +#### Java + ```java class Solution { public long maxPoints(int[][] points) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func maxPoints(points [][]int) int64 { n := len(points[0]) @@ -175,6 +183,8 @@ func maxPoints(points [][]int) int64 { } ``` +#### TypeScript + ```ts function maxPoints(points: number[][]): number { const n = points[0].length; diff --git a/solution/1900-1999/1938.Maximum Genetic Difference Query/README.md b/solution/1900-1999/1938.Maximum Genetic Difference Query/README.md index a63af52487ea8..fd2a5f2dfa96e 100644 --- a/solution/1900-1999/1938.Maximum Genetic Difference Query/README.md +++ b/solution/1900-1999/1938.Maximum Genetic Difference Query/README.md @@ -71,18 +71,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1900-1999/1938.Maximum Genetic Difference Query/README_EN.md b/solution/1900-1999/1938.Maximum Genetic Difference Query/README_EN.md index ce5e1f15b9f47..400437007f2ab 100644 --- a/solution/1900-1999/1938.Maximum Genetic Difference Query/README_EN.md +++ b/solution/1900-1999/1938.Maximum Genetic Difference Query/README_EN.md @@ -71,18 +71,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1900-1999/1939.Users That Actively Request Confirmation Messages/README.md b/solution/1900-1999/1939.Users That Actively Request Confirmation Messages/README.md index 4da08c7cd3ebb..0468f73dc19a6 100644 --- a/solution/1900-1999/1939.Users That Actively Request Confirmation Messages/README.md +++ b/solution/1900-1999/1939.Users That Actively Request Confirmation Messages/README.md @@ -97,6 +97,8 @@ Result table +#### MySQL + ```sql SELECT DISTINCT user_id FROM diff --git a/solution/1900-1999/1939.Users That Actively Request Confirmation Messages/README_EN.md b/solution/1900-1999/1939.Users That Actively Request Confirmation Messages/README_EN.md index 762e24d6cdb60..9440db0e7aa05 100644 --- a/solution/1900-1999/1939.Users That Actively Request Confirmation Messages/README_EN.md +++ b/solution/1900-1999/1939.Users That Actively Request Confirmation Messages/README_EN.md @@ -106,6 +106,8 @@ User 7 requested two messages within 24 hours and 1 second of each other, so we +#### MySQL + ```sql SELECT DISTINCT user_id FROM diff --git a/solution/1900-1999/1940.Longest Common Subsequence Between Sorted Arrays/README.md b/solution/1900-1999/1940.Longest Common Subsequence Between Sorted Arrays/README.md index 49bed84654acc..5d92ba40fdfa7 100644 --- a/solution/1900-1999/1940.Longest Common Subsequence Between Sorted Arrays/README.md +++ b/solution/1900-1999/1940.Longest Common Subsequence Between Sorted Arrays/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def longestCommomSubsequence(self, arrays: List[List[int]]) -> List[int]: @@ -82,6 +84,8 @@ class Solution: return [e for e, count in counter.items() if count == n] ``` +#### Java + ```java class Solution { public List longestCommomSubsequence(int[][] arrays) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func longestCommomSubsequence(arrays [][]int) []int { counter := make(map[int]int) @@ -140,6 +148,8 @@ func longestCommomSubsequence(arrays [][]int) []int { } ``` +#### JavaScript + ```js /** * @param {number[][]} arrays @@ -169,6 +179,8 @@ var longestCommonSubsequence = function (arrays) { +#### Python3 + ```python class Solution: def longestCommomSubsequence(self, arrays: List[List[int]]) -> List[int]: diff --git a/solution/1900-1999/1940.Longest Common Subsequence Between Sorted Arrays/README_EN.md b/solution/1900-1999/1940.Longest Common Subsequence Between Sorted Arrays/README_EN.md index 9df32c601823c..75397ce423e0c 100644 --- a/solution/1900-1999/1940.Longest Common Subsequence Between Sorted Arrays/README_EN.md +++ b/solution/1900-1999/1940.Longest Common Subsequence Between Sorted Arrays/README_EN.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def longestCommomSubsequence(self, arrays: List[List[int]]) -> List[int]: @@ -82,6 +84,8 @@ class Solution: return [e for e, count in counter.items() if count == n] ``` +#### Java + ```java class Solution { public List longestCommomSubsequence(int[][] arrays) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func longestCommomSubsequence(arrays [][]int) []int { counter := make(map[int]int) @@ -140,6 +148,8 @@ func longestCommomSubsequence(arrays [][]int) []int { } ``` +#### JavaScript + ```js /** * @param {number[][]} arrays @@ -169,6 +179,8 @@ var longestCommonSubsequence = function (arrays) { +#### Python3 + ```python class Solution: def longestCommomSubsequence(self, arrays: List[List[int]]) -> List[int]: diff --git a/solution/1900-1999/1941.Check if All Characters Have Equal Number of Occurrences/README.md b/solution/1900-1999/1941.Check if All Characters Have Equal Number of Occurrences/README.md index bf1a2d5814373..2ac30846f2b5e 100644 --- a/solution/1900-1999/1941.Check if All Characters Have Equal Number of Occurrences/README.md +++ b/solution/1900-1999/1941.Check if All Characters Have Equal Number of Occurrences/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def areOccurrencesEqual(self, s: str) -> bool: @@ -73,6 +75,8 @@ class Solution: return len(set(cnt.values())) == 1 ``` +#### Java + ```java class Solution { public boolean areOccurrencesEqual(String s) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func areOccurrencesEqual(s string) bool { cnt := [26]int{} @@ -138,6 +146,8 @@ func areOccurrencesEqual(s string) bool { } ``` +#### TypeScript + ```ts function areOccurrencesEqual(s: string): boolean { const cnt: number[] = new Array(26).fill(0); @@ -158,6 +168,8 @@ function areOccurrencesEqual(s: string): boolean { } ``` +#### PHP + ```php class Solution { /** @@ -184,6 +196,8 @@ class Solution { +#### TypeScript + ```ts function areOccurrencesEqual(s: string): boolean { const cnt: number[] = new Array(26).fill(0); diff --git a/solution/1900-1999/1941.Check if All Characters Have Equal Number of Occurrences/README_EN.md b/solution/1900-1999/1941.Check if All Characters Have Equal Number of Occurrences/README_EN.md index d5cfcde35ac28..cf0c8a7241854 100644 --- a/solution/1900-1999/1941.Check if All Characters Have Equal Number of Occurrences/README_EN.md +++ b/solution/1900-1999/1941.Check if All Characters Have Equal Number of Occurrences/README_EN.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def areOccurrencesEqual(self, s: str) -> bool: @@ -67,6 +69,8 @@ class Solution: return len(set(cnt.values())) == 1 ``` +#### Java + ```java class Solution { public boolean areOccurrencesEqual(String s) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func areOccurrencesEqual(s string) bool { cnt := [26]int{} @@ -132,6 +140,8 @@ func areOccurrencesEqual(s string) bool { } ``` +#### TypeScript + ```ts function areOccurrencesEqual(s: string): boolean { const cnt: number[] = new Array(26).fill(0); @@ -152,6 +162,8 @@ function areOccurrencesEqual(s: string): boolean { } ``` +#### PHP + ```php class Solution { /** @@ -178,6 +190,8 @@ class Solution { +#### TypeScript + ```ts function areOccurrencesEqual(s: string): boolean { const cnt: number[] = new Array(26).fill(0); diff --git a/solution/1900-1999/1942.The Number of the Smallest Unoccupied Chair/README.md b/solution/1900-1999/1942.The Number of the Smallest Unoccupied Chair/README.md index 08c30fd7ebcc8..c1d953feb2e75 100644 --- a/solution/1900-1999/1942.The Number of the Smallest Unoccupied Chair/README.md +++ b/solution/1900-1999/1942.The Number of the Smallest Unoccupied Chair/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def smallestChair(self, times: List[List[int]], targetFriend: int) -> int: @@ -104,6 +106,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int smallestChair(int[][] times, int targetFriend) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp using pii = pair; diff --git a/solution/1900-1999/1942.The Number of the Smallest Unoccupied Chair/README_EN.md b/solution/1900-1999/1942.The Number of the Smallest Unoccupied Chair/README_EN.md index 9dbb21cd44cdf..ec4b0aabf85cf 100644 --- a/solution/1900-1999/1942.The Number of the Smallest Unoccupied Chair/README_EN.md +++ b/solution/1900-1999/1942.The Number of the Smallest Unoccupied Chair/README_EN.md @@ -84,6 +84,8 @@ Since friend 0 sat on chair 2, we return 2. +#### Python3 + ```python class Solution: def smallestChair(self, times: List[List[int]], targetFriend: int) -> int: @@ -104,6 +106,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int smallestChair(int[][] times, int targetFriend) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp using pii = pair; diff --git a/solution/1900-1999/1943.Describe the Painting/README.md b/solution/1900-1999/1943.Describe the Painting/README.md index 82472fdd5f61f..a03305e3e0d3e 100644 --- a/solution/1900-1999/1943.Describe the Painting/README.md +++ b/solution/1900-1999/1943.Describe the Painting/README.md @@ -105,6 +105,8 @@ tags: +#### Python3 + ```python class Solution: def splitPainting(self, segments: List[List[int]]) -> List[List[int]]: @@ -119,6 +121,8 @@ class Solution: return [[s[i][0], s[i + 1][0], s[i][1]] for i in range(n - 1) if s[i][1]] ``` +#### Java + ```java class Solution { public List> splitPainting(int[][] segments) { @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/1900-1999/1943.Describe the Painting/README_EN.md b/solution/1900-1999/1943.Describe the Painting/README_EN.md index 4d132968f8e95..be22156df45ea 100644 --- a/solution/1900-1999/1943.Describe the Painting/README_EN.md +++ b/solution/1900-1999/1943.Describe the Painting/README_EN.md @@ -103,6 +103,8 @@ Note that returning a single segment [1,7) is incorrect because the mixed color +#### Python3 + ```python class Solution: def splitPainting(self, segments: List[List[int]]) -> List[List[int]]: @@ -117,6 +119,8 @@ class Solution: return [[s[i][0], s[i + 1][0], s[i][1]] for i in range(n - 1) if s[i][1]] ``` +#### Java + ```java class Solution { public List> splitPainting(int[][] segments) { @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/1900-1999/1944.Number of Visible People in a Queue/README.md b/solution/1900-1999/1944.Number of Visible People in a Queue/README.md index 008f4cf271bbd..d4991ec8604b4 100644 --- a/solution/1900-1999/1944.Number of Visible People in a Queue/README.md +++ b/solution/1900-1999/1944.Number of Visible People in a Queue/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def canSeePersonsCount(self, heights: List[int]) -> List[int]: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] canSeePersonsCount(int[] heights) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func canSeePersonsCount(heights []int) []int { n := len(heights) @@ -166,6 +174,8 @@ func canSeePersonsCount(heights []int) []int { } ``` +#### TypeScript + ```ts function canSeePersonsCount(heights: number[]): number[] { const n = heights.length; @@ -185,6 +195,8 @@ function canSeePersonsCount(heights: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn can_see_persons_count(heights: Vec) -> Vec { @@ -206,6 +218,8 @@ impl Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). diff --git a/solution/1900-1999/1944.Number of Visible People in a Queue/README_EN.md b/solution/1900-1999/1944.Number of Visible People in a Queue/README_EN.md index cea7e248c9f40..3858ce84f433d 100644 --- a/solution/1900-1999/1944.Number of Visible People in a Queue/README_EN.md +++ b/solution/1900-1999/1944.Number of Visible People in a Queue/README_EN.md @@ -70,6 +70,8 @@ Person 5 can see no one since nobody is to the right of them. +#### Python3 + ```python class Solution: def canSeePersonsCount(self, heights: List[int]) -> List[int]: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] canSeePersonsCount(int[] heights) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func canSeePersonsCount(heights []int) []int { n := len(heights) @@ -148,6 +156,8 @@ func canSeePersonsCount(heights []int) []int { } ``` +#### TypeScript + ```ts function canSeePersonsCount(heights: number[]): number[] { const n = heights.length; @@ -167,6 +177,8 @@ function canSeePersonsCount(heights: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn can_see_persons_count(heights: Vec) -> Vec { @@ -188,6 +200,8 @@ impl Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). diff --git a/solution/1900-1999/1945.Sum of Digits of String After Convert/README.md b/solution/1900-1999/1945.Sum of Digits of String After Convert/README.md index 340f4b07d98f1..407862778640b 100644 --- a/solution/1900-1999/1945.Sum of Digits of String After Convert/README.md +++ b/solution/1900-1999/1945.Sum of Digits of String After Convert/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def getLucky(self, s: str, k: int) -> int: @@ -92,6 +94,8 @@ class Solution: return int(s) ``` +#### Java + ```java class Solution { public int getLucky(String s, int k) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func getLucky(s string, k int) int { var t strings.Builder @@ -149,6 +157,8 @@ func getLucky(s string, k int) int { } ``` +#### TypeScript + ```ts function getLucky(s: string, k: number): number { let ans = ''; @@ -166,6 +176,8 @@ function getLucky(s: string, k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn get_lucky(s: String, k: i32) -> i32 { @@ -185,6 +197,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1900-1999/1945.Sum of Digits of String After Convert/README_EN.md b/solution/1900-1999/1945.Sum of Digits of String After Convert/README_EN.md index 5cfae9f44f752..905435ae041d8 100644 --- a/solution/1900-1999/1945.Sum of Digits of String After Convert/README_EN.md +++ b/solution/1900-1999/1945.Sum of Digits of String After Convert/README_EN.md @@ -83,6 +83,8 @@ Thus the resulting integer is 6. +#### Python3 + ```python class Solution: def getLucky(self, s: str, k: int) -> int: @@ -93,6 +95,8 @@ class Solution: return int(s) ``` +#### Java + ```java class Solution { public int getLucky(String s, int k) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func getLucky(s string, k int) int { var t strings.Builder @@ -150,6 +158,8 @@ func getLucky(s string, k int) int { } ``` +#### TypeScript + ```ts function getLucky(s: string, k: number): number { let ans = ''; @@ -167,6 +177,8 @@ function getLucky(s: string, k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn get_lucky(s: String, k: i32) -> i32 { @@ -186,6 +198,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1900-1999/1946.Largest Number After Mutating Substring/README.md b/solution/1900-1999/1946.Largest Number After Mutating Substring/README.md index b95ec76695821..864a97785e26f 100644 --- a/solution/1900-1999/1946.Largest Number After Mutating Substring/README.md +++ b/solution/1900-1999/1946.Largest Number After Mutating Substring/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def maximumNumber(self, num: str, change: List[int]) -> str: @@ -97,6 +99,8 @@ class Solution: return ''.join(s) ``` +#### Java + ```java class Solution { public String maximumNumber(String num, int[] change) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func maximumNumber(num string, change []int) string { s := []byte(num) diff --git a/solution/1900-1999/1946.Largest Number After Mutating Substring/README_EN.md b/solution/1900-1999/1946.Largest Number After Mutating Substring/README_EN.md index a1dc1f0c38b01..bb56bffe2c0c1 100644 --- a/solution/1900-1999/1946.Largest Number After Mutating Substring/README_EN.md +++ b/solution/1900-1999/1946.Largest Number After Mutating Substring/README_EN.md @@ -81,6 +81,8 @@ Thus, "021" becomes "934". +#### Python3 + ```python class Solution: def maximumNumber(self, num: str, change: List[int]) -> str: @@ -94,6 +96,8 @@ class Solution: return ''.join(s) ``` +#### Java + ```java class Solution { public String maximumNumber(String num, int[] change) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func maximumNumber(num string, change []int) string { s := []byte(num) diff --git a/solution/1900-1999/1947.Maximum Compatibility Score Sum/README.md b/solution/1900-1999/1947.Maximum Compatibility Score Sum/README.md index 19986c9486bdd..9213b7ce2c14d 100644 --- a/solution/1900-1999/1947.Maximum Compatibility Score Sum/README.md +++ b/solution/1900-1999/1947.Maximum Compatibility Score Sum/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def maxCompatibilitySum( @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[][] g; @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -183,6 +189,8 @@ public: }; ``` +#### Go + ```go func maxCompatibilitySum(students [][]int, mentors [][]int) (ans int) { m, n := len(students), len(students[0]) diff --git a/solution/1900-1999/1947.Maximum Compatibility Score Sum/README_EN.md b/solution/1900-1999/1947.Maximum Compatibility Score Sum/README_EN.md index 9185afc790c24..631659279f02d 100644 --- a/solution/1900-1999/1947.Maximum Compatibility Score Sum/README_EN.md +++ b/solution/1900-1999/1947.Maximum Compatibility Score Sum/README_EN.md @@ -78,6 +78,8 @@ The compatibility score sum is 3 + 2 + 3 = 8. +#### Python3 + ```python class Solution: def maxCompatibilitySum( @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[][] g; @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -180,6 +186,8 @@ public: }; ``` +#### Go + ```go func maxCompatibilitySum(students [][]int, mentors [][]int) (ans int) { m, n := len(students), len(students[0]) diff --git a/solution/1900-1999/1948.Delete Duplicate Folders in System/README.md b/solution/1900-1999/1948.Delete Duplicate Folders in System/README.md index 33bb6754cd57c..d3255436fb79c 100644 --- a/solution/1900-1999/1948.Delete Duplicate Folders in System/README.md +++ b/solution/1900-1999/1948.Delete Duplicate Folders in System/README.md @@ -126,18 +126,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1900-1999/1948.Delete Duplicate Folders in System/README_EN.md b/solution/1900-1999/1948.Delete Duplicate Folders in System/README_EN.md index 59d2a9c9de51d..01fa7d10a03c7 100644 --- a/solution/1900-1999/1948.Delete Duplicate Folders in System/README_EN.md +++ b/solution/1900-1999/1948.Delete Duplicate Folders in System/README_EN.md @@ -105,18 +105,26 @@ Note that the returned array can be in a different order as the order does not m +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1900-1999/1949.Strong Friendship/README.md b/solution/1900-1999/1949.Strong Friendship/README.md index 4bf3aba3810b5..ba80ed2be12ac 100644 --- a/solution/1900-1999/1949.Strong Friendship/README.md +++ b/solution/1900-1999/1949.Strong Friendship/README.md @@ -88,6 +88,8 @@ Friendship table: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1900-1999/1949.Strong Friendship/README_EN.md b/solution/1900-1999/1949.Strong Friendship/README_EN.md index c2e6b06c3acb7..55631cb633e73 100644 --- a/solution/1900-1999/1949.Strong Friendship/README_EN.md +++ b/solution/1900-1999/1949.Strong Friendship/README_EN.md @@ -87,6 +87,8 @@ We did not include the friendship of users 2 and 3 because they only have two co +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1900-1999/1950.Maximum of Minimum Values in All Subarrays/README.md b/solution/1900-1999/1950.Maximum of Minimum Values in All Subarrays/README.md index 2dd0cba16cf2f..9b4f0e33f59bb 100644 --- a/solution/1900-1999/1950.Maximum of Minimum Values in All Subarrays/README.md +++ b/solution/1900-1999/1950.Maximum of Minimum Values in All Subarrays/README.md @@ -99,6 +99,8 @@ i = 3: +#### Python3 + ```python class Solution: def findMaximums(self, nums: List[int]) -> List[int]: @@ -128,6 +130,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] findMaximums(int[] nums) { @@ -169,6 +173,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -209,6 +215,8 @@ public: }; ``` +#### Go + ```go func findMaximums(nums []int) []int { n := len(nums) diff --git a/solution/1900-1999/1950.Maximum of Minimum Values in All Subarrays/README_EN.md b/solution/1900-1999/1950.Maximum of Minimum Values in All Subarrays/README_EN.md index 35758d324f768..bdd2f0fe30883 100644 --- a/solution/1900-1999/1950.Maximum of Minimum Values in All Subarrays/README_EN.md +++ b/solution/1900-1999/1950.Maximum of Minimum Values in All Subarrays/README_EN.md @@ -91,6 +91,8 @@ i=3: +#### Python3 + ```python class Solution: def findMaximums(self, nums: List[int]) -> List[int]: @@ -120,6 +122,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] findMaximums(int[] nums) { @@ -161,6 +165,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -201,6 +207,8 @@ public: }; ``` +#### Go + ```go func findMaximums(nums []int) []int { n := len(nums) diff --git a/solution/1900-1999/1951.All the Pairs With the Maximum Number of Common Followers/README.md b/solution/1900-1999/1951.All the Pairs With the Maximum Number of Common Followers/README.md index 71f8ab5bf886d..ddd8a924afea0 100644 --- a/solution/1900-1999/1951.All the Pairs With the Maximum Number of Common Followers/README.md +++ b/solution/1900-1999/1951.All the Pairs With the Maximum Number of Common Followers/README.md @@ -82,6 +82,8 @@ Result 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1900-1999/1951.All the Pairs With the Maximum Number of Common Followers/README_EN.md b/solution/1900-1999/1951.All the Pairs With the Maximum Number of Common Followers/README_EN.md index 59c2e8e52386a..0766dbd7ef183 100644 --- a/solution/1900-1999/1951.All the Pairs With the Maximum Number of Common Followers/README_EN.md +++ b/solution/1900-1999/1951.All the Pairs With the Maximum Number of Common Followers/README_EN.md @@ -82,6 +82,8 @@ Note that we do not have any information about the users that follow users 3, 4, +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1900-1999/1952.Three Divisors/README.md b/solution/1900-1999/1952.Three Divisors/README.md index b337af77849bc..5c37282100a15 100644 --- a/solution/1900-1999/1952.Three Divisors/README.md +++ b/solution/1900-1999/1952.Three Divisors/README.md @@ -61,12 +61,16 @@ tags: +#### Python3 + ```python class Solution: def isThree(self, n: int) -> bool: return sum(n % i == 0 for i in range(2, n)) == 1 ``` +#### Java + ```java class Solution { public boolean isThree(int n) { @@ -81,6 +85,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -94,6 +100,8 @@ public: }; ``` +#### Go + ```go func isThree(n int) bool { cnt := 0 @@ -106,6 +114,8 @@ func isThree(n int) bool { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -136,6 +146,8 @@ var isThree = function (n) { +#### Python3 + ```python class Solution: def isThree(self, n: int) -> bool: @@ -148,6 +160,8 @@ class Solution: return cnt == 3 ``` +#### Java + ```java class Solution { public boolean isThree(int n) { @@ -162,6 +176,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -177,6 +193,8 @@ public: }; ``` +#### Go + ```go func isThree(n int) bool { cnt := 0 @@ -193,6 +211,8 @@ func isThree(n int) bool { } ``` +#### JavaScript + ```js /** * @param {number} n diff --git a/solution/1900-1999/1952.Three Divisors/README_EN.md b/solution/1900-1999/1952.Three Divisors/README_EN.md index 4551721ea99c9..0d68d5e3e3ea8 100644 --- a/solution/1900-1999/1952.Three Divisors/README_EN.md +++ b/solution/1900-1999/1952.Three Divisors/README_EN.md @@ -58,12 +58,16 @@ tags: +#### Python3 + ```python class Solution: def isThree(self, n: int) -> bool: return sum(n % i == 0 for i in range(2, n)) == 1 ``` +#### Java + ```java class Solution { public boolean isThree(int n) { @@ -78,6 +82,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -91,6 +97,8 @@ public: }; ``` +#### Go + ```go func isThree(n int) bool { cnt := 0 @@ -103,6 +111,8 @@ func isThree(n int) bool { } ``` +#### JavaScript + ```js /** * @param {number} n @@ -129,6 +139,8 @@ var isThree = function (n) { +#### Python3 + ```python class Solution: def isThree(self, n: int) -> bool: @@ -141,6 +153,8 @@ class Solution: return cnt == 3 ``` +#### Java + ```java class Solution { public boolean isThree(int n) { @@ -155,6 +169,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -170,6 +186,8 @@ public: }; ``` +#### Go + ```go func isThree(n int) bool { cnt := 0 @@ -186,6 +204,8 @@ func isThree(n int) bool { } ``` +#### JavaScript + ```js /** * @param {number} n diff --git a/solution/1900-1999/1953.Maximum Number of Weeks for Which You Can Work/README.md b/solution/1900-1999/1953.Maximum Number of Weeks for Which You Can Work/README.md index 6b530c158ed56..38db65faaf0f2 100644 --- a/solution/1900-1999/1953.Maximum Number of Weeks for Which You Can Work/README.md +++ b/solution/1900-1999/1953.Maximum Number of Weeks for Which You Can Work/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfWeeks(self, milestones: List[int]) -> int: @@ -102,6 +104,8 @@ class Solution: return rest * 2 + 1 if mx > rest + 1 else s ``` +#### Java + ```java class Solution { public long numberOfWeeks(int[] milestones) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func numberOfWeeks(milestones []int) int64 { mx := slices.Max(milestones) @@ -144,6 +152,8 @@ func numberOfWeeks(milestones []int) int64 { } ``` +#### TypeScript + ```ts function numberOfWeeks(milestones: number[]): number { const mx = Math.max(...milestones); diff --git a/solution/1900-1999/1953.Maximum Number of Weeks for Which You Can Work/README_EN.md b/solution/1900-1999/1953.Maximum Number of Weeks for Which You Can Work/README_EN.md index 46498c78afb0b..6f278d3794f69 100644 --- a/solution/1900-1999/1953.Maximum Number of Weeks for Which You Can Work/README_EN.md +++ b/solution/1900-1999/1953.Maximum Number of Weeks for Which You Can Work/README_EN.md @@ -93,6 +93,8 @@ The time complexity is $O(n)$, where $n$ is the number of projects. The space co +#### Python3 + ```python class Solution: def numberOfWeeks(self, milestones: List[int]) -> int: @@ -101,6 +103,8 @@ class Solution: return rest * 2 + 1 if mx > rest + 1 else s ``` +#### Java + ```java class Solution { public long numberOfWeeks(int[] milestones) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func numberOfWeeks(milestones []int) int64 { mx := slices.Max(milestones) @@ -143,6 +151,8 @@ func numberOfWeeks(milestones []int) int64 { } ``` +#### TypeScript + ```ts function numberOfWeeks(milestones: number[]): number { const mx = Math.max(...milestones); diff --git a/solution/1900-1999/1954.Minimum Garden Perimeter to Collect Enough Apples/README.md b/solution/1900-1999/1954.Minimum Garden Perimeter to Collect Enough Apples/README.md index 8a276528af3a9..d3b39970bb456 100644 --- a/solution/1900-1999/1954.Minimum Garden Perimeter to Collect Enough Apples/README.md +++ b/solution/1900-1999/1954.Minimum Garden Perimeter to Collect Enough Apples/README.md @@ -100,6 +100,8 @@ $$ +#### Python3 + ```python class Solution: def minimumPerimeter(self, neededApples: int) -> int: @@ -109,6 +111,8 @@ class Solution: return x * 8 ``` +#### Java + ```java class Solution { public long minimumPerimeter(long neededApples) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func minimumPerimeter(neededApples int64) int64 { var x int64 = 1 @@ -144,6 +152,8 @@ func minimumPerimeter(neededApples int64) int64 { } ``` +#### TypeScript + ```ts function minimumPerimeter(neededApples: number): number { let x = 1; @@ -166,6 +176,8 @@ function minimumPerimeter(neededApples: number): number { +#### Python3 + ```python class Solution: def minimumPerimeter(self, neededApples: int) -> int: @@ -179,6 +191,8 @@ class Solution: return l * 8 ``` +#### Java + ```java class Solution { public long minimumPerimeter(long neededApples) { @@ -196,6 +210,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -214,6 +230,8 @@ public: }; ``` +#### Go + ```go func minimumPerimeter(neededApples int64) int64 { var l, r int64 = 1, 100000 @@ -229,6 +247,8 @@ func minimumPerimeter(neededApples int64) int64 { } ``` +#### TypeScript + ```ts function minimumPerimeter(neededApples: number): number { let l = 1; diff --git a/solution/1900-1999/1954.Minimum Garden Perimeter to Collect Enough Apples/README_EN.md b/solution/1900-1999/1954.Minimum Garden Perimeter to Collect Enough Apples/README_EN.md index a3a53a97faac5..3461a89b66e0e 100644 --- a/solution/1900-1999/1954.Minimum Garden Perimeter to Collect Enough Apples/README_EN.md +++ b/solution/1900-1999/1954.Minimum Garden Perimeter to Collect Enough Apples/README_EN.md @@ -74,6 +74,8 @@ The perimeter is 2 * 4 = 8. +#### Python3 + ```python class Solution: def minimumPerimeter(self, neededApples: int) -> int: @@ -83,6 +85,8 @@ class Solution: return x * 8 ``` +#### Java + ```java class Solution { public long minimumPerimeter(long neededApples) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func minimumPerimeter(neededApples int64) int64 { var x int64 = 1 @@ -118,6 +126,8 @@ func minimumPerimeter(neededApples int64) int64 { } ``` +#### TypeScript + ```ts function minimumPerimeter(neededApples: number): number { let x = 1; @@ -138,6 +148,8 @@ function minimumPerimeter(neededApples: number): number { +#### Python3 + ```python class Solution: def minimumPerimeter(self, neededApples: int) -> int: @@ -151,6 +163,8 @@ class Solution: return l * 8 ``` +#### Java + ```java class Solution { public long minimumPerimeter(long neededApples) { @@ -168,6 +182,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -186,6 +202,8 @@ public: }; ``` +#### Go + ```go func minimumPerimeter(neededApples int64) int64 { var l, r int64 = 1, 100000 @@ -201,6 +219,8 @@ func minimumPerimeter(neededApples int64) int64 { } ``` +#### TypeScript + ```ts function minimumPerimeter(neededApples: number): number { let l = 1; diff --git a/solution/1900-1999/1955.Count Number of Special Subsequences/README.md b/solution/1900-1999/1955.Count Number of Special Subsequences/README.md index efc3a30bf9ff0..b96be4d54015b 100644 --- a/solution/1900-1999/1955.Count Number of Special Subsequences/README.md +++ b/solution/1900-1999/1955.Count Number of Special Subsequences/README.md @@ -109,6 +109,8 @@ $$ +#### Python3 + ```python class Solution: def countSpecialSubsequences(self, nums: List[int]) -> int: @@ -132,6 +134,8 @@ class Solution: return f[n - 1][2] ``` +#### Java + ```java class Solution { public int countSpecialSubsequences(int[] nums) { @@ -159,6 +163,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go func countSpecialSubsequences(nums []int) int { const mod = 1e9 + 7 @@ -215,6 +223,8 @@ func countSpecialSubsequences(nums []int) int { } ``` +#### TypeScript + ```ts function countSpecialSubsequences(nums: number[]): number { const mod = 1e9 + 7; @@ -252,6 +262,8 @@ function countSpecialSubsequences(nums: number[]): number { +#### Python3 + ```python class Solution: def countSpecialSubsequences(self, nums: List[int]) -> int: @@ -269,6 +281,8 @@ class Solution: return f[2] ``` +#### Java + ```java class Solution { public int countSpecialSubsequences(int[] nums) { @@ -290,6 +304,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -312,6 +328,8 @@ public: }; ``` +#### Go + ```go func countSpecialSubsequences(nums []int) int { const mod = 1e9 + 7 @@ -333,6 +351,8 @@ func countSpecialSubsequences(nums []int) int { } ``` +#### TypeScript + ```ts function countSpecialSubsequences(nums: number[]): number { const mod = 1e9 + 7; diff --git a/solution/1900-1999/1955.Count Number of Special Subsequences/README_EN.md b/solution/1900-1999/1955.Count Number of Special Subsequences/README_EN.md index cb40881154d16..3d29305a5c3be 100644 --- a/solution/1900-1999/1955.Count Number of Special Subsequences/README_EN.md +++ b/solution/1900-1999/1955.Count Number of Special Subsequences/README_EN.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def countSpecialSubsequences(self, nums: List[int]) -> int: @@ -103,6 +105,8 @@ class Solution: return f[n - 1][2] ``` +#### Java + ```java class Solution { public int countSpecialSubsequences(int[] nums) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func countSpecialSubsequences(nums []int) int { const mod = 1e9 + 7 @@ -186,6 +194,8 @@ func countSpecialSubsequences(nums []int) int { } ``` +#### TypeScript + ```ts function countSpecialSubsequences(nums: number[]): number { const mod = 1e9 + 7; @@ -223,6 +233,8 @@ function countSpecialSubsequences(nums: number[]): number { +#### Python3 + ```python class Solution: def countSpecialSubsequences(self, nums: List[int]) -> int: @@ -240,6 +252,8 @@ class Solution: return f[2] ``` +#### Java + ```java class Solution { public int countSpecialSubsequences(int[] nums) { @@ -261,6 +275,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -283,6 +299,8 @@ public: }; ``` +#### Go + ```go func countSpecialSubsequences(nums []int) int { const mod = 1e9 + 7 @@ -304,6 +322,8 @@ func countSpecialSubsequences(nums []int) int { } ``` +#### TypeScript + ```ts function countSpecialSubsequences(nums: number[]): number { const mod = 1e9 + 7; diff --git a/solution/1900-1999/1956.Minimum Time For K Virus Variants to Spread/README.md b/solution/1900-1999/1956.Minimum Time For K Virus Variants to Spread/README.md index f3b8829567f88..d85d292b1cce5 100644 --- a/solution/1900-1999/1956.Minimum Time For K Virus Variants to Spread/README.md +++ b/solution/1900-1999/1956.Minimum Time For K Virus Variants to Spread/README.md @@ -80,18 +80,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1900-1999/1956.Minimum Time For K Virus Variants to Spread/README_EN.md b/solution/1900-1999/1956.Minimum Time For K Virus Variants to Spread/README_EN.md index 2f9bd62cfaa06..e401264434cdf 100644 --- a/solution/1900-1999/1956.Minimum Time For K Virus Variants to Spread/README_EN.md +++ b/solution/1900-1999/1956.Minimum Time For K Virus Variants to Spread/README_EN.md @@ -72,18 +72,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1900-1999/1957.Delete Characters to Make Fancy String/README.md b/solution/1900-1999/1957.Delete Characters to Make Fancy String/README.md index 7f3148c3d531c..3092d6b382469 100644 --- a/solution/1900-1999/1957.Delete Characters to Make Fancy String/README.md +++ b/solution/1900-1999/1957.Delete Characters to Make Fancy String/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def makeFancyString(self, s: str) -> str: @@ -85,6 +87,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String makeFancyString(String s) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func makeFancyString(s string) string { ans := []rune{} @@ -130,6 +138,8 @@ func makeFancyString(s string) string { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1900-1999/1957.Delete Characters to Make Fancy String/README_EN.md b/solution/1900-1999/1957.Delete Characters to Make Fancy String/README_EN.md index 5e1f2cd86251d..ab45eafdca3d7 100644 --- a/solution/1900-1999/1957.Delete Characters to Make Fancy String/README_EN.md +++ b/solution/1900-1999/1957.Delete Characters to Make Fancy String/README_EN.md @@ -72,6 +72,8 @@ No three consecutive characters are equal, so return "aabaa". +#### Python3 + ```python class Solution: def makeFancyString(self, s: str) -> str: @@ -83,6 +85,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String makeFancyString(String s) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func makeFancyString(s string) string { ans := []rune{} @@ -128,6 +136,8 @@ func makeFancyString(s string) string { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1900-1999/1958.Check if Move is Legal/README.md b/solution/1900-1999/1958.Check if Move is Legal/README.md index 08dafa98b734e..00b59437160a4 100644 --- a/solution/1900-1999/1958.Check if Move is Legal/README.md +++ b/solution/1900-1999/1958.Check if Move is Legal/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def checkMove( @@ -92,6 +94,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { private static final int[][] DIRS @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func checkMove(board [][]byte, rMove int, cMove int, color byte) bool { dirs := [8][2]int{{1, 0}, {0, 1}, {-1, 0}, {0, -1}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}} diff --git a/solution/1900-1999/1958.Check if Move is Legal/README_EN.md b/solution/1900-1999/1958.Check if Move is Legal/README_EN.md index 8e71c252bf1e1..3af37b39865b2 100644 --- a/solution/1900-1999/1958.Check if Move is Legal/README_EN.md +++ b/solution/1900-1999/1958.Check if Move is Legal/README_EN.md @@ -66,6 +66,8 @@ The two good lines with the chosen cell as an endpoint are annotated above with +#### Python3 + ```python class Solution: def checkMove( @@ -86,6 +88,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { private static final int[][] DIRS @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func checkMove(board [][]byte, rMove int, cMove int, color byte) bool { dirs := [8][2]int{{1, 0}, {0, 1}, {-1, 0}, {0, -1}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}} diff --git a/solution/1900-1999/1959.Minimum Total Space Wasted With K Resizing Operations/README.md b/solution/1900-1999/1959.Minimum Total Space Wasted With K Resizing Operations/README.md index eb5ea89880221..11ce72783a078 100644 --- a/solution/1900-1999/1959.Minimum Total Space Wasted With K Resizing Operations/README.md +++ b/solution/1900-1999/1959.Minimum Total Space Wasted With K Resizing Operations/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def minSpaceWastedKResizing(self, nums: List[int], k: int) -> int: @@ -97,6 +99,8 @@ class Solution: return f[-1][-1] ``` +#### Java + ```java class Solution { public int minSpaceWastedKResizing(int[] nums, int k) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func minSpaceWastedKResizing(nums []int, k int) int { k++ diff --git a/solution/1900-1999/1959.Minimum Total Space Wasted With K Resizing Operations/README_EN.md b/solution/1900-1999/1959.Minimum Total Space Wasted With K Resizing Operations/README_EN.md index 3db8b481263fa..90fc97567380f 100644 --- a/solution/1900-1999/1959.Minimum Total Space Wasted With K Resizing Operations/README_EN.md +++ b/solution/1900-1999/1959.Minimum Total Space Wasted With K Resizing Operations/README_EN.md @@ -77,6 +77,8 @@ The total wasted space is (10 - 10) + (20 - 20) + (20 - 15) + (30 - 30) + (30 - +#### Python3 + ```python class Solution: def minSpaceWastedKResizing(self, nums: List[int], k: int) -> int: @@ -98,6 +100,8 @@ class Solution: return f[-1][-1] ``` +#### Java + ```java class Solution { public int minSpaceWastedKResizing(int[] nums, int k) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func minSpaceWastedKResizing(nums []int, k int) int { k++ diff --git a/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README.md b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README.md index 83f2c30e4d648..b918ee2cb015b 100644 --- a/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README.md +++ b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README.md @@ -65,18 +65,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README_EN.md b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README_EN.md index 7a6bc2c132a92..044c570412d56 100644 --- a/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README_EN.md +++ b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README_EN.md @@ -63,18 +63,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/1900-1999/1961.Check If String Is a Prefix of Array/README.md b/solution/1900-1999/1961.Check If String Is a Prefix of Array/README.md index 578beb01927b5..a7543b7c90ecb 100644 --- a/solution/1900-1999/1961.Check If String Is a Prefix of Array/README.md +++ b/solution/1900-1999/1961.Check If String Is a Prefix of Array/README.md @@ -72,6 +72,8 @@ s 可以由 "i"、"love" 和 "leetcode" 相连得到。 +#### Python3 + ```python class Solution: def isPrefixString(self, s: str, words: List[str]) -> bool: @@ -83,6 +85,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean isPrefixString(String s, String[] words) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func isPrefixString(s string, words []string) bool { t := strings.Builder{} @@ -136,6 +144,8 @@ func isPrefixString(s string, words []string) bool { } ``` +#### TypeScript + ```ts function isPrefixString(s: string, words: string[]): boolean { const t: string[] = []; diff --git a/solution/1900-1999/1961.Check If String Is a Prefix of Array/README_EN.md b/solution/1900-1999/1961.Check If String Is a Prefix of Array/README_EN.md index 0e686390f12df..0eb07ed79f6cf 100644 --- a/solution/1900-1999/1961.Check If String Is a Prefix of Array/README_EN.md +++ b/solution/1900-1999/1961.Check If String Is a Prefix of Array/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def isPrefixString(self, s: str, words: List[str]) -> bool: @@ -81,6 +83,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean isPrefixString(String s, String[] words) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func isPrefixString(s string, words []string) bool { t := strings.Builder{} @@ -134,6 +142,8 @@ func isPrefixString(s string, words []string) bool { } ``` +#### TypeScript + ```ts function isPrefixString(s: string, words: string[]): boolean { const t: string[] = []; diff --git a/solution/1900-1999/1962.Remove Stones to Minimize the Total/README.md b/solution/1900-1999/1962.Remove Stones to Minimize the Total/README.md index 819c004992fe8..10f304b6ebb49 100644 --- a/solution/1900-1999/1962.Remove Stones to Minimize the Total/README.md +++ b/solution/1900-1999/1962.Remove Stones to Minimize the Total/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def minStoneSum(self, piles: List[int], k: int) -> int: @@ -97,6 +99,8 @@ class Solution: return -sum(pq) ``` +#### Java + ```java class Solution { public int minStoneSum(int[] piles, int k) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func minStoneSum(piles []int, k int) (ans int) { pq := &hp{piles} @@ -168,6 +176,8 @@ func (h *hp) push(v int) { heap.Push(h, v) } func (h *hp) pop() int { return heap.Pop(h).(int) } ``` +#### TypeScript + ```ts function minStoneSum(piles: number[], k: number): number { const pq = new MaxPriorityQueue(); diff --git a/solution/1900-1999/1962.Remove Stones to Minimize the Total/README_EN.md b/solution/1900-1999/1962.Remove Stones to Minimize the Total/README_EN.md index 2be8ddf0a9f7a..0cff23e5eeb7b 100644 --- a/solution/1900-1999/1962.Remove Stones to Minimize the Total/README_EN.md +++ b/solution/1900-1999/1962.Remove Stones to Minimize the Total/README_EN.md @@ -85,6 +85,8 @@ The time complexity is $O(n + k \times \log n)$, and the space complexity is $O( +#### Python3 + ```python class Solution: def minStoneSum(self, piles: List[int], k: int) -> int: @@ -95,6 +97,8 @@ class Solution: return -sum(pq) ``` +#### Java + ```java class Solution { public int minStoneSum(int[] piles, int k) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func minStoneSum(piles []int, k int) (ans int) { pq := &hp{piles} @@ -166,6 +174,8 @@ func (h *hp) push(v int) { heap.Push(h, v) } func (h *hp) pop() int { return heap.Pop(h).(int) } ``` +#### TypeScript + ```ts function minStoneSum(piles: number[], k: number): number { const pq = new MaxPriorityQueue(); diff --git a/solution/1900-1999/1963.Minimum Number of Swaps to Make the String Balanced/README.md b/solution/1900-1999/1963.Minimum Number of Swaps to Make the String Balanced/README.md index 2ce614252f8fa..f3bb3724ca39f 100644 --- a/solution/1900-1999/1963.Minimum Number of Swaps to Make the String Balanced/README.md +++ b/solution/1900-1999/1963.Minimum Number of Swaps to Make the String Balanced/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class Solution: def minSwaps(self, s: str) -> int: @@ -108,6 +110,8 @@ class Solution: return (x + 1) >> 1 ``` +#### Java + ```java class Solution { public int minSwaps(String s) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func minSwaps(s string) int { x := 0 @@ -156,6 +164,8 @@ func minSwaps(s string) int { } ``` +#### TypeScript + ```ts function minSwaps(s: string): number { let x = 0; diff --git a/solution/1900-1999/1963.Minimum Number of Swaps to Make the String Balanced/README_EN.md b/solution/1900-1999/1963.Minimum Number of Swaps to Make the String Balanced/README_EN.md index 040c0e7ac8e0d..d907236424132 100644 --- a/solution/1900-1999/1963.Minimum Number of Swaps to Make the String Balanced/README_EN.md +++ b/solution/1900-1999/1963.Minimum Number of Swaps to Make the String Balanced/README_EN.md @@ -94,6 +94,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string $s$. The sp +#### Python3 + ```python class Solution: def minSwaps(self, s: str) -> int: @@ -106,6 +108,8 @@ class Solution: return (x + 1) >> 1 ``` +#### Java + ```java class Solution { public int minSwaps(String s) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func minSwaps(s string) int { x := 0 @@ -154,6 +162,8 @@ func minSwaps(s string) int { } ``` +#### TypeScript + ```ts function minSwaps(s: string): number { let x = 0; diff --git a/solution/1900-1999/1964.Find the Longest Valid Obstacle Course at Each Position/README.md b/solution/1900-1999/1964.Find the Longest Valid Obstacle Course at Each Position/README.md index fad15887a0dc5..b8b318c0d082d 100644 --- a/solution/1900-1999/1964.Find the Longest Valid Obstacle Course at Each Position/README.md +++ b/solution/1900-1999/1964.Find the Longest Valid Obstacle Course at Each Position/README.md @@ -98,6 +98,8 @@ tags: +#### Python3 + ```python class BinaryIndexedTree: __slots__ = ["n", "c"] @@ -132,6 +134,8 @@ class Solution: return ans ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -177,6 +181,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { private: @@ -226,6 +232,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -265,6 +273,8 @@ func longestObstacleCourseAtEachPosition(obstacles []int) (ans []int) { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; diff --git a/solution/1900-1999/1964.Find the Longest Valid Obstacle Course at Each Position/README_EN.md b/solution/1900-1999/1964.Find the Longest Valid Obstacle Course at Each Position/README_EN.md index 0d1cdf67eb790..c53cd0bac7fa2 100644 --- a/solution/1900-1999/1964.Find the Longest Valid Obstacle Course at Each Position/README_EN.md +++ b/solution/1900-1999/1964.Find the Longest Valid Obstacle Course at Each Position/README_EN.md @@ -96,6 +96,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class BinaryIndexedTree: __slots__ = ["n", "c"] @@ -130,6 +132,8 @@ class Solution: return ans ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -175,6 +179,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { private: @@ -224,6 +230,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -263,6 +271,8 @@ func longestObstacleCourseAtEachPosition(obstacles []int) (ans []int) { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; diff --git a/solution/1900-1999/1965.Employees With Missing Information/README.md b/solution/1900-1999/1965.Employees With Missing Information/README.md index 0a5d833d6833d..3e1f11943662f 100644 --- a/solution/1900-1999/1965.Employees With Missing Information/README.md +++ b/solution/1900-1999/1965.Employees With Missing Information/README.md @@ -101,6 +101,8 @@ Salaries table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT employee_id diff --git a/solution/1900-1999/1965.Employees With Missing Information/README_EN.md b/solution/1900-1999/1965.Employees With Missing Information/README_EN.md index f2b02d9f166f1..a3a51fd3d0545 100644 --- a/solution/1900-1999/1965.Employees With Missing Information/README_EN.md +++ b/solution/1900-1999/1965.Employees With Missing Information/README_EN.md @@ -103,6 +103,8 @@ We can first find all `employee_id` that are not in the `Salaries` table from th +#### MySQL + ```sql # Write your MySQL query statement below SELECT employee_id diff --git a/solution/1900-1999/1966.Binary Searchable Numbers in an Unsorted Array/README.md b/solution/1900-1999/1966.Binary Searchable Numbers in an Unsorted Array/README.md index d37101b99bb80..a217405a5c5a4 100644 --- a/solution/1900-1999/1966.Binary Searchable Numbers in an Unsorted Array/README.md +++ b/solution/1900-1999/1966.Binary Searchable Numbers in an Unsorted Array/README.md @@ -106,6 +106,8 @@ func(sequence, target) +#### Python3 + ```python class Solution: def binarySearchableNumbers(self, nums: List[int]) -> int: @@ -125,6 +127,8 @@ class Solution: return sum(ok) ``` +#### Java + ```java class Solution { public int binarySearchableNumbers(int[] nums) { @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go func binarySearchableNumbers(nums []int) (ans int) { n := len(nums) diff --git a/solution/1900-1999/1966.Binary Searchable Numbers in an Unsorted Array/README_EN.md b/solution/1900-1999/1966.Binary Searchable Numbers in an Unsorted Array/README_EN.md index a951dc0ee68bf..122eb02a81ef8 100644 --- a/solution/1900-1999/1966.Binary Searchable Numbers in an Unsorted Array/README_EN.md +++ b/solution/1900-1999/1966.Binary Searchable Numbers in an Unsorted Array/README_EN.md @@ -89,6 +89,8 @@ Because only -1 is guaranteed to be found, you should return 1. +#### Python3 + ```python class Solution: def binarySearchableNumbers(self, nums: List[int]) -> int: @@ -108,6 +110,8 @@ class Solution: return sum(ok) ``` +#### Java + ```java class Solution { public int binarySearchableNumbers(int[] nums) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func binarySearchableNumbers(nums []int) (ans int) { n := len(nums) diff --git a/solution/1900-1999/1967.Number of Strings That Appear as Substrings in Word/README.md b/solution/1900-1999/1967.Number of Strings That Appear as Substrings in Word/README.md index 5acfc2b69d5f6..0dde0320a078d 100644 --- a/solution/1900-1999/1967.Number of Strings That Appear as Substrings in Word/README.md +++ b/solution/1900-1999/1967.Number of Strings That Appear as Substrings in Word/README.md @@ -84,12 +84,16 @@ patterns 中有 2 个字符串作为子字符串出现在 word 中。 +#### Python3 + ```python class Solution: def numOfStrings(self, patterns: List[str], word: str) -> int: return sum(p in word for p in patterns) ``` +#### Java + ```java class Solution { public int numOfStrings(String[] patterns, String word) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func numOfStrings(patterns []string, word string) (ans int) { for _, p := range patterns { @@ -128,6 +136,8 @@ func numOfStrings(patterns []string, word string) (ans int) { } ``` +#### TypeScript + ```ts function numOfStrings(patterns: string[], word: string): number { let ans = 0; diff --git a/solution/1900-1999/1967.Number of Strings That Appear as Substrings in Word/README_EN.md b/solution/1900-1999/1967.Number of Strings That Appear as Substrings in Word/README_EN.md index b79bdb74751ce..dbceaffdfb7d0 100644 --- a/solution/1900-1999/1967.Number of Strings That Appear as Substrings in Word/README_EN.md +++ b/solution/1900-1999/1967.Number of Strings That Appear as Substrings in Word/README_EN.md @@ -76,12 +76,16 @@ tags: +#### Python3 + ```python class Solution: def numOfStrings(self, patterns: List[str], word: str) -> int: return sum(p in word for p in patterns) ``` +#### Java + ```java class Solution { public int numOfStrings(String[] patterns, String word) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func numOfStrings(patterns []string, word string) (ans int) { for _, p := range patterns { @@ -120,6 +128,8 @@ func numOfStrings(patterns []string, word string) (ans int) { } ``` +#### TypeScript + ```ts function numOfStrings(patterns: string[], word: string): number { let ans = 0; diff --git a/solution/1900-1999/1968.Array With Elements Not Equal to Average of Neighbors/README.md b/solution/1900-1999/1968.Array With Elements Not Equal to Average of Neighbors/README.md index 9d508c0e0e5de..547074165ff9e 100644 --- a/solution/1900-1999/1968.Array With Elements Not Equal to Average of Neighbors/README.md +++ b/solution/1900-1999/1968.Array With Elements Not Equal to Average of Neighbors/README.md @@ -67,6 +67,8 @@ i=3, nums[i] = 2, 两相邻元素平均值为 (6+0) / 2 = 3 +#### Python3 + ```python class Solution: def rearrangeArray(self, nums: List[int]) -> List[int]: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] rearrangeArray(int[] nums) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func rearrangeArray(nums []int) []int { sort.Ints(nums) @@ -142,6 +150,8 @@ func rearrangeArray(nums []int) []int { +#### Go + ```go func rearrangeArray(nums []int) []int { rand.Seed(time.Now().UnixNano()) diff --git a/solution/1900-1999/1968.Array With Elements Not Equal to Average of Neighbors/README_EN.md b/solution/1900-1999/1968.Array With Elements Not Equal to Average of Neighbors/README_EN.md index 6306439b9fd1f..f3d560a2b5333 100644 --- a/solution/1900-1999/1968.Array With Elements Not Equal to Average of Neighbors/README_EN.md +++ b/solution/1900-1999/1968.Array With Elements Not Equal to Average of Neighbors/README_EN.md @@ -67,6 +67,8 @@ When i=3, nums[i] = 2, and the average of its neighbors is (6+0) / 2 = 3. +#### Python3 + ```python class Solution: def rearrangeArray(self, nums: List[int]) -> List[int]: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] rearrangeArray(int[] nums) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func rearrangeArray(nums []int) []int { sort.Ints(nums) @@ -142,6 +150,8 @@ func rearrangeArray(nums []int) []int { +#### Go + ```go func rearrangeArray(nums []int) []int { rand.Seed(time.Now().UnixNano()) diff --git a/solution/1900-1999/1969.Minimum Non-Zero Product of the Array Elements/README.md b/solution/1900-1999/1969.Minimum Non-Zero Product of the Array Elements/README.md index c35c417ab0e19..8f23cafea415b 100644 --- a/solution/1900-1999/1969.Minimum Non-Zero Product of the Array Elements/README.md +++ b/solution/1900-1999/1969.Minimum Non-Zero Product of the Array Elements/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def minNonZeroProduct(self, p: int) -> int: @@ -100,6 +102,8 @@ class Solution: return (2**p - 1) * pow(2**p - 2, 2 ** (p - 1) - 1, mod) % mod ``` +#### Java + ```java class Solution { public int minNonZeroProduct(int p) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func minNonZeroProduct(p int) int { const mod int = 1e9 + 7 @@ -164,6 +172,8 @@ func minNonZeroProduct(p int) int { } ``` +#### TypeScript + ```ts function minNonZeroProduct(p: number): number { const mod = BigInt(1e9 + 7); diff --git a/solution/1900-1999/1969.Minimum Non-Zero Product of the Array Elements/README_EN.md b/solution/1900-1999/1969.Minimum Non-Zero Product of the Array Elements/README_EN.md index de89edc7c33a3..b24704825c750 100644 --- a/solution/1900-1999/1969.Minimum Non-Zero Product of the Array Elements/README_EN.md +++ b/solution/1900-1999/1969.Minimum Non-Zero Product of the Array Elements/README_EN.md @@ -91,6 +91,8 @@ The time complexity is $O(p)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def minNonZeroProduct(self, p: int) -> int: @@ -98,6 +100,8 @@ class Solution: return (2**p - 1) * pow(2**p - 2, 2 ** (p - 1) - 1, mod) % mod ``` +#### Java + ```java class Solution { public int minNonZeroProduct(int p) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func minNonZeroProduct(p int) int { const mod int = 1e9 + 7 @@ -162,6 +170,8 @@ func minNonZeroProduct(p int) int { } ``` +#### TypeScript + ```ts function minNonZeroProduct(p: number): number { const mod = BigInt(1e9 + 7); diff --git a/solution/1900-1999/1970.Last Day Where You Can Still Cross/README.md b/solution/1900-1999/1970.Last Day Where You Can Still Cross/README.md index 7077e3f82370e..d32f41c311c71 100644 --- a/solution/1900-1999/1970.Last Day Where You Can Still Cross/README.md +++ b/solution/1900-1999/1970.Last Day Where You Can Still Cross/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def latestDayToCross(self, row: int, col: int, cells: List[List[int]]) -> int: @@ -111,6 +113,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { private int[] p; @@ -163,6 +167,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -204,6 +210,8 @@ public: }; ``` +#### Go + ```go var p []int diff --git a/solution/1900-1999/1970.Last Day Where You Can Still Cross/README_EN.md b/solution/1900-1999/1970.Last Day Where You Can Still Cross/README_EN.md index 925210d4e9801..2351c186e3228 100644 --- a/solution/1900-1999/1970.Last Day Where You Can Still Cross/README_EN.md +++ b/solution/1900-1999/1970.Last Day Where You Can Still Cross/README_EN.md @@ -81,6 +81,8 @@ The last day where it is possible to cross from top to bottom is on day 3. +#### Python3 + ```python class Solution: def latestDayToCross(self, row: int, col: int, cells: List[List[int]]) -> int: @@ -112,6 +114,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { private int[] p; @@ -164,6 +168,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -205,6 +211,8 @@ public: }; ``` +#### Go + ```go var p []int diff --git a/solution/1900-1999/1971.Find if Path Exists in Graph/README.md b/solution/1900-1999/1971.Find if Path Exists in Graph/README.md index 2f54761df3823..154ef49a2e3c9 100644 --- a/solution/1900-1999/1971.Find if Path Exists in Graph/README.md +++ b/solution/1900-1999/1971.Find if Path Exists in Graph/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def validPath( @@ -98,6 +100,8 @@ class Solution: return dfs(source) ``` +#### Java + ```java class Solution { private boolean[] vis; @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func validPath(n int, edges [][]int, source int, destination int) bool { vis := make([]bool, n) @@ -182,6 +190,8 @@ func validPath(n int, edges [][]int, source int, destination int) bool { } ``` +#### Rust + ```rust impl Solution { pub fn valid_path(n: i32, edges: Vec>, source: i32, destination: i32) -> bool { @@ -340,6 +350,8 @@ func union(a, b int) { +#### Python3 + ```python class Solution: def validPath( @@ -356,6 +368,8 @@ class Solution: return find(source) == find(destination) ``` +#### Java + ```java class Solution { private int[] p; @@ -380,6 +394,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -396,6 +412,8 @@ public: }; ``` +#### Go + ```go func validPath(n int, edges [][]int, source int, destination int) bool { p := make([]int, n) diff --git a/solution/1900-1999/1971.Find if Path Exists in Graph/README_EN.md b/solution/1900-1999/1971.Find if Path Exists in Graph/README_EN.md index 77b2fe14f4f13..213c7f919686d 100644 --- a/solution/1900-1999/1971.Find if Path Exists in Graph/README_EN.md +++ b/solution/1900-1999/1971.Find if Path Exists in Graph/README_EN.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def validPath( @@ -90,6 +92,8 @@ class Solution: return dfs(source) ``` +#### Java + ```java class Solution { private boolean[] vis; @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func validPath(n int, edges [][]int, source int, destination int) bool { vis := make([]bool, n) @@ -174,6 +182,8 @@ func validPath(n int, edges [][]int, source int, destination int) bool { } ``` +#### Rust + ```rust impl Solution { pub fn valid_path(n: i32, edges: Vec>, source: i32, destination: i32) -> bool { @@ -215,6 +225,8 @@ impl Solution { +#### Python3 + ```python class Solution: def validPath( @@ -231,6 +243,8 @@ class Solution: return find(source) == find(destination) ``` +#### Java + ```java class Solution { private int[] p; @@ -255,6 +269,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -271,6 +287,8 @@ public: }; ``` +#### Go + ```go func validPath(n int, edges [][]int, source int, destination int) bool { p := make([]int, n) diff --git a/solution/1900-1999/1972.First and Last Call On the Same Day/README.md b/solution/1900-1999/1972.First and Last Call On the Same Day/README.md index 4321fd54283f5..b3cbdab90b421 100644 --- a/solution/1900-1999/1972.First and Last Call On the Same Day/README.md +++ b/solution/1900-1999/1972.First and Last Call On the Same Day/README.md @@ -76,6 +76,8 @@ Calls table: +#### MySQL + ```sql # Write your MySQL query statement below with s as ( diff --git a/solution/1900-1999/1972.First and Last Call On the Same Day/README_EN.md b/solution/1900-1999/1972.First and Last Call On the Same Day/README_EN.md index 067d69d9a695f..622b9a3a3a0a9 100644 --- a/solution/1900-1999/1972.First and Last Call On the Same Day/README_EN.md +++ b/solution/1900-1999/1972.First and Last Call On the Same Day/README_EN.md @@ -79,6 +79,8 @@ On 2021-08-11, user 1 and 5 had a call. This call was the only call for both of +#### MySQL + ```sql # Write your MySQL query statement below with s as ( diff --git a/solution/1900-1999/1973.Count Nodes Equal to Sum of Descendants/README.md b/solution/1900-1999/1973.Count Nodes Equal to Sum of Descendants/README.md index 5636e85180d28..7b19a3dba7711 100644 --- a/solution/1900-1999/1973.Count Nodes Equal to Sum of Descendants/README.md +++ b/solution/1900-1999/1973.Count Nodes Equal to Sum of Descendants/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -103,6 +105,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/1900-1999/1973.Count Nodes Equal to Sum of Descendants/README_EN.md b/solution/1900-1999/1973.Count Nodes Equal to Sum of Descendants/README_EN.md index 4e8614c56bb86..8c799f0f0a1f9 100644 --- a/solution/1900-1999/1973.Count Nodes Equal to Sum of Descendants/README_EN.md +++ b/solution/1900-1999/1973.Count Nodes Equal to Sum of Descendants/README_EN.md @@ -68,6 +68,8 @@ For the node with value 0: The sum of its descendants is 0 since it has no desce +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/1900-1999/1974.Minimum Time to Type Word Using Special Typewriter/README.md b/solution/1900-1999/1974.Minimum Time to Type Word Using Special Typewriter/README.md index d412c8c52891a..a2e36ebb0a709 100644 --- a/solution/1900-1999/1974.Minimum Time to Type Word Using Special Typewriter/README.md +++ b/solution/1900-1999/1974.Minimum Time to Type Word Using Special Typewriter/README.md @@ -97,6 +97,8 @@ tags: +#### Python3 + ```python class Solution: def minTimeToType(self, word: str) -> int: @@ -110,6 +112,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minTimeToType(String word) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func minTimeToType(word string) int { ans, prev := 0, 0 diff --git a/solution/1900-1999/1974.Minimum Time to Type Word Using Special Typewriter/README_EN.md b/solution/1900-1999/1974.Minimum Time to Type Word Using Special Typewriter/README_EN.md index b40cd81947582..42963092b4003 100644 --- a/solution/1900-1999/1974.Minimum Time to Type Word Using Special Typewriter/README_EN.md +++ b/solution/1900-1999/1974.Minimum Time to Type Word Using Special Typewriter/README_EN.md @@ -95,6 +95,8 @@ The characters are printed as follows: +#### Python3 + ```python class Solution: def minTimeToType(self, word: str) -> int: @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minTimeToType(String word) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func minTimeToType(word string) int { ans, prev := 0, 0 diff --git a/solution/1900-1999/1975.Maximum Matrix Sum/README.md b/solution/1900-1999/1975.Maximum Matrix Sum/README.md index 6c177a525eda9..6eafd918560c2 100644 --- a/solution/1900-1999/1975.Maximum Matrix Sum/README.md +++ b/solution/1900-1999/1975.Maximum Matrix Sum/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def maxMatrixSum(self, matrix: List[List[int]]) -> int: @@ -91,6 +93,8 @@ class Solution: return s - mi * 2 ``` +#### Java + ```java class Solution { public long maxMatrixSum(int[][] matrix) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func maxMatrixSum(matrix [][]int) int64 { s := 0 @@ -160,6 +168,8 @@ func abs(x int) int { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix diff --git a/solution/1900-1999/1975.Maximum Matrix Sum/README_EN.md b/solution/1900-1999/1975.Maximum Matrix Sum/README_EN.md index 3db1d1be0e4ad..ca957bd75468d 100644 --- a/solution/1900-1999/1975.Maximum Matrix Sum/README_EN.md +++ b/solution/1900-1999/1975.Maximum Matrix Sum/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def maxMatrixSum(self, matrix: List[List[int]]) -> int: @@ -85,6 +87,8 @@ class Solution: return s - mi * 2 ``` +#### Java + ```java class Solution { public long maxMatrixSum(int[][] matrix) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func maxMatrixSum(matrix [][]int) int64 { s := 0 @@ -154,6 +162,8 @@ func abs(x int) int { } ``` +#### JavaScript + ```js /** * @param {number[][]} matrix diff --git a/solution/1900-1999/1976.Number of Ways to Arrive at Destination/README.md b/solution/1900-1999/1976.Number of Ways to Arrive at Destination/README.md index 55df39ac0799c..ca77511e5a638 100644 --- a/solution/1900-1999/1976.Number of Ways to Arrive at Destination/README.md +++ b/solution/1900-1999/1976.Number of Ways to Arrive at Destination/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def countPaths(self, n: int, roads: List[List[int]]) -> int: @@ -117,6 +119,8 @@ class Solution: return f[-1] % mod ``` +#### Java + ```java class Solution { public int countPaths(int n, int[][] roads) { @@ -164,6 +168,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -218,6 +224,8 @@ public: }; ``` +#### Go + ```go func countPaths(n int, roads [][]int) int { const inf = math.MaxInt64 / 2 @@ -270,6 +278,8 @@ func countPaths(n int, roads [][]int) int { } ``` +#### TypeScript + ```ts function countPaths(n: number, roads: number[][]): number { const mod: number = 1e9 + 7; diff --git a/solution/1900-1999/1976.Number of Ways to Arrive at Destination/README_EN.md b/solution/1900-1999/1976.Number of Ways to Arrive at Destination/README_EN.md index 08e291b2af5ca..0fbf29ebb4252 100644 --- a/solution/1900-1999/1976.Number of Ways to Arrive at Destination/README_EN.md +++ b/solution/1900-1999/1976.Number of Ways to Arrive at Destination/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$, where $n$ +#### Python3 + ```python class Solution: def countPaths(self, n: int, roads: List[List[int]]) -> int: @@ -117,6 +119,8 @@ class Solution: return f[-1] % mod ``` +#### Java + ```java class Solution { public int countPaths(int n, int[][] roads) { @@ -164,6 +168,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -218,6 +224,8 @@ public: }; ``` +#### Go + ```go func countPaths(n int, roads [][]int) int { const inf = math.MaxInt64 / 2 @@ -270,6 +278,8 @@ func countPaths(n int, roads [][]int) int { } ``` +#### TypeScript + ```ts function countPaths(n: number, roads: number[][]): number { const mod: number = 1e9 + 7; diff --git a/solution/1900-1999/1977.Number of Ways to Separate Numbers/README.md b/solution/1900-1999/1977.Number of Ways to Separate Numbers/README.md index e1f8422e0b05e..521855d4a79f7 100644 --- a/solution/1900-1999/1977.Number of Ways to Separate Numbers/README.md +++ b/solution/1900-1999/1977.Number of Ways to Separate Numbers/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfCombinations(self, num: str) -> int: @@ -111,6 +113,8 @@ class Solution: return dp[n][n] ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go func numberOfCombinations(num string) int { n := len(num) diff --git a/solution/1900-1999/1977.Number of Ways to Separate Numbers/README_EN.md b/solution/1900-1999/1977.Number of Ways to Separate Numbers/README_EN.md index 980a27f7d8e51..dc2c5cfb1c97c 100644 --- a/solution/1900-1999/1977.Number of Ways to Separate Numbers/README_EN.md +++ b/solution/1900-1999/1977.Number of Ways to Separate Numbers/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfCombinations(self, num: str) -> int: @@ -98,6 +100,8 @@ class Solution: return dp[n][n] ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go func numberOfCombinations(num string) int { n := len(num) diff --git a/solution/1900-1999/1978.Employees Whose Manager Left the Company/README.md b/solution/1900-1999/1978.Employees Whose Manager Left the Company/README.md index 3b2c6e7d0eb9d..d14bbb783b816 100644 --- a/solution/1900-1999/1978.Employees Whose Manager Left the Company/README.md +++ b/solution/1900-1999/1978.Employees Whose Manager Left the Company/README.md @@ -82,6 +82,8 @@ Joziah 的上级经理是 6 号员工,他已经离职,因为员工表里面 +#### MySQL + ```sql # Write your MySQL query statement below SELECT e1.employee_id @@ -104,6 +106,8 @@ ORDER BY 1; +#### MySQL + ```sql # Write your MySQL query statement below SELECT employee_id diff --git a/solution/1900-1999/1978.Employees Whose Manager Left the Company/README_EN.md b/solution/1900-1999/1978.Employees Whose Manager Left the Company/README_EN.md index fd3f8cabd7edd..546d3d7328917 100644 --- a/solution/1900-1999/1978.Employees Whose Manager Left the Company/README_EN.md +++ b/solution/1900-1999/1978.Employees Whose Manager Left the Company/README_EN.md @@ -80,6 +80,8 @@ We can use a left join to connect the employee table with itself, and then filte +#### MySQL + ```sql # Write your MySQL query statement below SELECT e1.employee_id @@ -102,6 +104,8 @@ We can also use a subquery to first find all the managers who have left the comp +#### MySQL + ```sql # Write your MySQL query statement below SELECT employee_id diff --git a/solution/1900-1999/1979.Find Greatest Common Divisor of Array/README.md b/solution/1900-1999/1979.Find Greatest Common Divisor of Array/README.md index 6f83ccedb7f8d..5f721e49abaf5 100644 --- a/solution/1900-1999/1979.Find Greatest Common Divisor of Array/README.md +++ b/solution/1900-1999/1979.Find Greatest Common Divisor of Array/README.md @@ -79,12 +79,16 @@ nums 中最大的数是 3 +#### Python3 + ```python class Solution: def findGCD(self, nums: List[int]) -> int: return gcd(max(nums), min(nums)) ``` +#### Java + ```java class Solution { public int findGCD(int[] nums) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func findGCD(nums []int) int { a, b := slices.Max(nums), slices.Min(nums) @@ -127,6 +135,8 @@ func gcd(a, b int) int { } ``` +#### TypeScript + ```ts function findGCD(nums: number[]): number { let a = 1; diff --git a/solution/1900-1999/1979.Find Greatest Common Divisor of Array/README_EN.md b/solution/1900-1999/1979.Find Greatest Common Divisor of Array/README_EN.md index 286f79cba7ed5..0e5dfa62773f6 100644 --- a/solution/1900-1999/1979.Find Greatest Common Divisor of Array/README_EN.md +++ b/solution/1900-1999/1979.Find Greatest Common Divisor of Array/README_EN.md @@ -76,12 +76,16 @@ The greatest common divisor of 3 and 3 is 3. +#### Python3 + ```python class Solution: def findGCD(self, nums: List[int]) -> int: return gcd(max(nums), min(nums)) ``` +#### Java + ```java class Solution { public int findGCD(int[] nums) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func findGCD(nums []int) int { a, b := slices.Max(nums), slices.Min(nums) @@ -124,6 +132,8 @@ func gcd(a, b int) int { } ``` +#### TypeScript + ```ts function findGCD(nums: number[]): number { let a = 1; diff --git a/solution/1900-1999/1980.Find Unique Binary String/README.md b/solution/1900-1999/1980.Find Unique Binary String/README.md index 1168d87dd5fed..999e51b5a4c92 100644 --- a/solution/1900-1999/1980.Find Unique Binary String/README.md +++ b/solution/1900-1999/1980.Find Unique Binary String/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def findDifferentBinaryString(self, nums: List[str]) -> str: @@ -90,6 +92,8 @@ class Solution: return "1" * i + "0" * (n - i) ``` +#### Java + ```java class Solution { public String findDifferentBinaryString(String[] nums) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func findDifferentBinaryString(nums []string) string { mask := 0 @@ -144,6 +152,8 @@ func findDifferentBinaryString(nums []string) string { } ``` +#### TypeScript + ```ts function findDifferentBinaryString(nums: string[]): string { let mask = 0; @@ -159,6 +169,8 @@ function findDifferentBinaryString(nums: string[]): string { } ``` +#### C# + ```cs public class Solution { public string FindDifferentBinaryString(string[] nums) { diff --git a/solution/1900-1999/1980.Find Unique Binary String/README_EN.md b/solution/1900-1999/1980.Find Unique Binary String/README_EN.md index 25138cf2b90d2..bbef5ad0084a6 100644 --- a/solution/1900-1999/1980.Find Unique Binary String/README_EN.md +++ b/solution/1900-1999/1980.Find Unique Binary String/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(L)$, where $L$ is the total length of the strings in ` +#### Python3 + ```python class Solution: def findDifferentBinaryString(self, nums: List[str]) -> str: @@ -89,6 +91,8 @@ class Solution: return "1" * i + "0" * (n - i) ``` +#### Java + ```java class Solution { public String findDifferentBinaryString(String[] nums) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func findDifferentBinaryString(nums []string) string { mask := 0 @@ -143,6 +151,8 @@ func findDifferentBinaryString(nums []string) string { } ``` +#### TypeScript + ```ts function findDifferentBinaryString(nums: string[]): string { let mask = 0; @@ -158,6 +168,8 @@ function findDifferentBinaryString(nums: string[]): string { } ``` +#### C# + ```cs public class Solution { public string FindDifferentBinaryString(string[] nums) { diff --git a/solution/1900-1999/1981.Minimize the Difference Between Target and Chosen Elements/README.md b/solution/1900-1999/1981.Minimize the Difference Between Target and Chosen Elements/README.md index 1e6af66cfe6f1..b2eaf9741054e 100644 --- a/solution/1900-1999/1981.Minimize the Difference Between Target and Chosen Elements/README.md +++ b/solution/1900-1999/1981.Minimize the Difference Between Target and Chosen Elements/README.md @@ -105,6 +105,8 @@ $$ +#### Python3 + ```python class Solution: def minimizeTheDifference(self, mat: List[List[int]], target: int) -> int: @@ -114,6 +116,8 @@ class Solution: return min(abs(v - target) for v in f) ``` +#### Java + ```java class Solution { public int minimizeTheDifference(int[][] mat, int target) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### Java + ```java class Solution { public int minimizeTheDifference(int[][] mat, int target) { @@ -165,6 +171,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -191,6 +199,8 @@ public: }; ``` +#### Go + ```go func minimizeTheDifference(mat [][]int, target int) int { f := []int{1} diff --git a/solution/1900-1999/1981.Minimize the Difference Between Target and Chosen Elements/README_EN.md b/solution/1900-1999/1981.Minimize the Difference Between Target and Chosen Elements/README_EN.md index 8193e2627f3fc..3edbf948ad8fc 100644 --- a/solution/1900-1999/1981.Minimize the Difference Between Target and Chosen Elements/README_EN.md +++ b/solution/1900-1999/1981.Minimize the Difference Between Target and Chosen Elements/README_EN.md @@ -97,6 +97,8 @@ The time complexity is $O(m^2 \times n \times C)$ and the space complexity is $O +#### Python3 + ```python class Solution: def minimizeTheDifference(self, mat: List[List[int]], target: int) -> int: @@ -106,6 +108,8 @@ class Solution: return min(abs(v - target) for v in f) ``` +#### Java + ```java class Solution { public int minimizeTheDifference(int[][] mat, int target) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### Java + ```java class Solution { public int minimizeTheDifference(int[][] mat, int target) { @@ -157,6 +163,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -183,6 +191,8 @@ public: }; ``` +#### Go + ```go func minimizeTheDifference(mat [][]int, target int) int { f := []int{1} diff --git a/solution/1900-1999/1982.Find Array Given Subset Sums/README.md b/solution/1900-1999/1982.Find Array Given Subset Sums/README.md index 7612d0f61ce0e..d93a7fc193a73 100644 --- a/solution/1900-1999/1982.Find Array Given Subset Sums/README.md +++ b/solution/1900-1999/1982.Find Array Given Subset Sums/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python from sortedcontainers import SortedList @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] recoverArray(int n, int[] sums) { @@ -162,6 +166,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -210,6 +216,8 @@ public: }; ``` +#### Go + ```go func recoverArray(n int, sums []int) []int { m := -slices.Min(sums) @@ -277,6 +285,8 @@ func recoverArray(n int, sums []int) []int { +#### Python3 + ```python class Solution: def recoverArray(self, n: int, sums: List[int]) -> List[int]: @@ -302,6 +312,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] recoverArray(int n, int[] sums) { @@ -338,6 +350,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -376,6 +390,8 @@ public: }; ``` +#### Go + ```go func recoverArray(n int, sums []int) (ans []int) { sort.Ints(sums) diff --git a/solution/1900-1999/1982.Find Array Given Subset Sums/README_EN.md b/solution/1900-1999/1982.Find Array Given Subset Sums/README_EN.md index 300b313880768..ac4ec35f9d98c 100644 --- a/solution/1900-1999/1982.Find Array Given Subset Sums/README_EN.md +++ b/solution/1900-1999/1982.Find Array Given Subset Sums/README_EN.md @@ -80,6 +80,8 @@ Note that any permutation of [1,2,-3] and also any permutation of [-1,-2,3] will +#### Python3 + ```python from sortedcontainers import SortedList @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] recoverArray(int n, int[] sums) { @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -208,6 +214,8 @@ public: }; ``` +#### Go + ```go func recoverArray(n int, sums []int) []int { m := -slices.Min(sums) @@ -275,6 +283,8 @@ func recoverArray(n int, sums []int) []int { +#### Python3 + ```python class Solution: def recoverArray(self, n: int, sums: List[int]) -> List[int]: @@ -300,6 +310,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] recoverArray(int n, int[] sums) { @@ -336,6 +348,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -374,6 +388,8 @@ public: }; ``` +#### Go + ```go func recoverArray(n int, sums []int) (ans []int) { sort.Ints(sums) diff --git a/solution/1900-1999/1983.Widest Pair of Indices With Equal Range Sum/README.md b/solution/1900-1999/1983.Widest Pair of Indices With Equal Range Sum/README.md index cf1104322d955..b711fbe0e5ede 100644 --- a/solution/1900-1999/1983.Widest Pair of Indices With Equal Range Sum/README.md +++ b/solution/1900-1999/1983.Widest Pair of Indices With Equal Range Sum/README.md @@ -90,6 +90,8 @@ i和j之间的距离是j - i + 1 = 1 - 1 + 1 = 1。 +#### Python3 + ```python class Solution: def widestPairOfIndices(self, nums1: List[int], nums2: List[int]) -> int: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int widestPairOfIndices(int[] nums1, int[] nums2) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func widestPairOfIndices(nums1 []int, nums2 []int) (ans int) { d := map[int]int{0: -1} @@ -162,6 +170,8 @@ func widestPairOfIndices(nums1 []int, nums2 []int) (ans int) { } ``` +#### TypeScript + ```ts function widestPairOfIndices(nums1: number[], nums2: number[]): number { const d: Map = new Map(); diff --git a/solution/1900-1999/1983.Widest Pair of Indices With Equal Range Sum/README_EN.md b/solution/1900-1999/1983.Widest Pair of Indices With Equal Range Sum/README_EN.md index 43228ddc2c1cb..1473b15788094 100644 --- a/solution/1900-1999/1983.Widest Pair of Indices With Equal Range Sum/README_EN.md +++ b/solution/1900-1999/1983.Widest Pair of Indices With Equal Range Sum/README_EN.md @@ -88,6 +88,8 @@ The time complexity is $O(n)$ and the space complexity is $O(n)$, where $n$ is t +#### Python3 + ```python class Solution: def widestPairOfIndices(self, nums1: List[int], nums2: List[int]) -> int: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int widestPairOfIndices(int[] nums1, int[] nums2) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func widestPairOfIndices(nums1 []int, nums2 []int) (ans int) { d := map[int]int{0: -1} @@ -160,6 +168,8 @@ func widestPairOfIndices(nums1 []int, nums2 []int) (ans int) { } ``` +#### TypeScript + ```ts function widestPairOfIndices(nums1: number[], nums2: number[]): number { const d: Map = new Map(); diff --git a/solution/1900-1999/1984.Minimum Difference Between Highest and Lowest of K Scores/README.md b/solution/1900-1999/1984.Minimum Difference Between Highest and Lowest of K Scores/README.md index b5683133ba9e1..aa929343f6359 100644 --- a/solution/1900-1999/1984.Minimum Difference Between Highest and Lowest of K Scores/README.md +++ b/solution/1900-1999/1984.Minimum Difference Between Highest and Lowest of K Scores/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def minimumDifference(self, nums: List[int], k: int) -> int: @@ -82,6 +84,8 @@ class Solution: return min(nums[i + k - 1] - nums[i] for i in range(len(nums) - k + 1)) ``` +#### Java + ```java class Solution { public int minimumDifference(int[] nums, int k) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func minimumDifference(nums []int, k int) int { sort.Ints(nums) @@ -120,6 +128,8 @@ func minimumDifference(nums []int, k int) int { } ``` +#### TypeScript + ```ts function minimumDifference(nums: number[], k: number): number { nums.sort((a, b) => a - b); @@ -132,6 +142,8 @@ function minimumDifference(nums: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn minimum_difference(mut nums: Vec, k: i32) -> i32 { @@ -146,6 +158,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1900-1999/1984.Minimum Difference Between Highest and Lowest of K Scores/README_EN.md b/solution/1900-1999/1984.Minimum Difference Between Highest and Lowest of K Scores/README_EN.md index ab817493fc2ff..b4fa9d2bdab1a 100644 --- a/solution/1900-1999/1984.Minimum Difference Between Highest and Lowest of K Scores/README_EN.md +++ b/solution/1900-1999/1984.Minimum Difference Between Highest and Lowest of K Scores/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def minimumDifference(self, nums: List[int], k: int) -> int: @@ -82,6 +84,8 @@ class Solution: return min(nums[i + k - 1] - nums[i] for i in range(len(nums) - k + 1)) ``` +#### Java + ```java class Solution { public int minimumDifference(int[] nums, int k) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func minimumDifference(nums []int, k int) int { sort.Ints(nums) @@ -120,6 +128,8 @@ func minimumDifference(nums []int, k int) int { } ``` +#### TypeScript + ```ts function minimumDifference(nums: number[], k: number): number { nums.sort((a, b) => a - b); @@ -132,6 +142,8 @@ function minimumDifference(nums: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn minimum_difference(mut nums: Vec, k: i32) -> i32 { @@ -146,6 +158,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/1900-1999/1985.Find the Kth Largest Integer in the Array/README.md b/solution/1900-1999/1985.Find the Kth Largest Integer in the Array/README.md index c28bdb28803b6..d3fef7d9de1f9 100644 --- a/solution/1900-1999/1985.Find the Kth Largest Integer in the Array/README.md +++ b/solution/1900-1999/1985.Find the Kth Largest Integer in the Array/README.md @@ -82,6 +82,8 @@ nums 中的数字按非递减顺序排列为 ["0","0"] +#### Python3 + ```python class Solution: def kthLargestNumber(self, nums: List[str], k: int) -> str: @@ -94,6 +96,8 @@ class Solution: return nums[k - 1] ``` +#### Java + ```java class Solution { public String kthLargestNumber(String[] nums, int k) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func kthLargestNumber(nums []string, k int) string { sort.Slice(nums, func(i, j int) bool { diff --git a/solution/1900-1999/1985.Find the Kth Largest Integer in the Array/README_EN.md b/solution/1900-1999/1985.Find the Kth Largest Integer in the Array/README_EN.md index 984fba5b32f43..ba1b62fb1f919 100644 --- a/solution/1900-1999/1985.Find the Kth Largest Integer in the Array/README_EN.md +++ b/solution/1900-1999/1985.Find the Kth Largest Integer in the Array/README_EN.md @@ -80,6 +80,8 @@ The 2nd largest integer in nums is "0". +#### Python3 + ```python class Solution: def kthLargestNumber(self, nums: List[str], k: int) -> str: @@ -92,6 +94,8 @@ class Solution: return nums[k - 1] ``` +#### Java + ```java class Solution { public String kthLargestNumber(String[] nums, int k) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func kthLargestNumber(nums []string, k int) string { sort.Slice(nums, func(i, j int) bool { diff --git a/solution/1900-1999/1986.Minimum Number of Work Sessions to Finish the Tasks/README.md b/solution/1900-1999/1986.Minimum Number of Work Sessions to Finish the Tasks/README.md index 8a7ce4bf75944..e4ef7c6ce9229 100644 --- a/solution/1900-1999/1986.Minimum Number of Work Sessions to Finish the Tasks/README.md +++ b/solution/1900-1999/1986.Minimum Number of Work Sessions to Finish the Tasks/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class Solution: def minSessions(self, tasks: List[int], sessionTime: int) -> int: @@ -113,6 +115,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int minSessions(int[] tasks, int sessionTime) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go func minSessions(tasks []int, sessionTime int) int { n := len(tasks) @@ -199,6 +207,8 @@ func minSessions(tasks []int, sessionTime int) int { } ``` +#### TypeScript + ```ts function minSessions(tasks: number[], sessionTime: number): number { const n = tasks.length; diff --git a/solution/1900-1999/1986.Minimum Number of Work Sessions to Finish the Tasks/README_EN.md b/solution/1900-1999/1986.Minimum Number of Work Sessions to Finish the Tasks/README_EN.md index 99d8e5e038775..18c712efc0a19 100644 --- a/solution/1900-1999/1986.Minimum Number of Work Sessions to Finish the Tasks/README_EN.md +++ b/solution/1900-1999/1986.Minimum Number of Work Sessions to Finish the Tasks/README_EN.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def minSessions(self, tasks: List[int], sessionTime: int) -> int: @@ -104,6 +106,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int minSessions(int[] tasks, int sessionTime) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func minSessions(tasks []int, sessionTime int) int { n := len(tasks) @@ -190,6 +198,8 @@ func minSessions(tasks []int, sessionTime int) int { } ``` +#### TypeScript + ```ts function minSessions(tasks: number[], sessionTime: number): number { const n = tasks.length; diff --git a/solution/1900-1999/1987.Number of Unique Good Subsequences/README.md b/solution/1900-1999/1987.Number of Unique Good Subsequences/README.md index 28853b5657edc..7a6f766da1c4d 100644 --- a/solution/1900-1999/1987.Number of Unique Good Subsequences/README.md +++ b/solution/1900-1999/1987.Number of Unique Good Subsequences/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfUniqueGoodSubsequences(self, binary: str) -> int: @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numberOfUniqueGoodSubsequences(String binary) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func numberOfUniqueGoodSubsequences(binary string) (ans int) { const mod int = 1e9 + 7 @@ -164,6 +172,8 @@ func numberOfUniqueGoodSubsequences(binary string) (ans int) { } ``` +#### TypeScript + ```ts function numberOfUniqueGoodSubsequences(binary: string): number { let [f, g] = [0, 0]; diff --git a/solution/1900-1999/1987.Number of Unique Good Subsequences/README_EN.md b/solution/1900-1999/1987.Number of Unique Good Subsequences/README_EN.md index e6e2366525aec..4a1643e6b8baf 100644 --- a/solution/1900-1999/1987.Number of Unique Good Subsequences/README_EN.md +++ b/solution/1900-1999/1987.Number of Unique Good Subsequences/README_EN.md @@ -76,6 +76,8 @@ The unique good subsequences are "0", "1", "10", & +#### Python3 + ```python class Solution: def numberOfUniqueGoodSubsequences(self, binary: str) -> int: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numberOfUniqueGoodSubsequences(String binary) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func numberOfUniqueGoodSubsequences(binary string) (ans int) { const mod int = 1e9 + 7 @@ -150,6 +158,8 @@ func numberOfUniqueGoodSubsequences(binary string) (ans int) { } ``` +#### TypeScript + ```ts function numberOfUniqueGoodSubsequences(binary: string): number { let [f, g] = [0, 0]; diff --git a/solution/1900-1999/1988.Find Cutoff Score for Each School/README.md b/solution/1900-1999/1988.Find Cutoff Score for Each School/README.md index 82ab14e85ac3f..e13130f1327cd 100644 --- a/solution/1900-1999/1988.Find Cutoff Score for Each School/README.md +++ b/solution/1900-1999/1988.Find Cutoff Score for Each School/README.md @@ -110,6 +110,8 @@ Exam 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT school_id, MIN(IFNULL(score, -1)) AS score diff --git a/solution/1900-1999/1988.Find Cutoff Score for Each School/README_EN.md b/solution/1900-1999/1988.Find Cutoff Score for Each School/README_EN.md index 907d433f35c69..e11a9647a0c08 100644 --- a/solution/1900-1999/1988.Find Cutoff Score for Each School/README_EN.md +++ b/solution/1900-1999/1988.Find Cutoff Score for Each School/README_EN.md @@ -111,6 +111,8 @@ Exam table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT school_id, MIN(IFNULL(score, -1)) AS score diff --git a/solution/1900-1999/1989.Maximum Number of People That Can Be Caught in Tag/README.md b/solution/1900-1999/1989.Maximum Number of People That Can Be Caught in Tag/README.md index 3f4a202a34495..de9d457858eb2 100644 --- a/solution/1900-1999/1989.Maximum Number of People That Can Be Caught in Tag/README.md +++ b/solution/1900-1999/1989.Maximum Number of People That Can Be Caught in Tag/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def catchMaximumAmountofPeople(self, team: List[int], dist: int) -> int: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int catchMaximumAmountofPeople(int[] team, int dist) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func catchMaximumAmountofPeople(team []int, dist int) (ans int) { n := len(team) diff --git a/solution/1900-1999/1989.Maximum Number of People That Can Be Caught in Tag/README_EN.md b/solution/1900-1999/1989.Maximum Number of People That Can Be Caught in Tag/README_EN.md index 99bda3d9b32ba..946ab86ecb64d 100644 --- a/solution/1900-1999/1989.Maximum Number of People That Can Be Caught in Tag/README_EN.md +++ b/solution/1900-1999/1989.Maximum Number of People That Can Be Caught in Tag/README_EN.md @@ -73,6 +73,8 @@ There are no people who are not "it" to catch. +#### Python3 + ```python class Solution: def catchMaximumAmountofPeople(self, team: List[int], dist: int) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int catchMaximumAmountofPeople(int[] team, int dist) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func catchMaximumAmountofPeople(team []int, dist int) (ans int) { n := len(team) diff --git a/solution/1900-1999/1990.Count the Number of Experiments/README.md b/solution/1900-1999/1990.Count the Number of Experiments/README.md index d4b9c2f1073ae..6bea75ff5d940 100644 --- a/solution/1900-1999/1990.Count the Number of Experiments/README.md +++ b/solution/1900-1999/1990.Count the Number of Experiments/README.md @@ -88,6 +88,8 @@ Experiments table: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1900-1999/1990.Count the Number of Experiments/README_EN.md b/solution/1900-1999/1990.Count the Number of Experiments/README_EN.md index d29c1d1a96b9b..8f5b37e6caf3c 100644 --- a/solution/1900-1999/1990.Count the Number of Experiments/README_EN.md +++ b/solution/1900-1999/1990.Count the Number of Experiments/README_EN.md @@ -86,6 +86,8 @@ On the platform "Web", we had two "Reading" experiments and +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/1900-1999/1991.Find the Middle Index in Array/README.md b/solution/1900-1999/1991.Find the Middle Index in Array/README.md index 961a1a99de997..8da4d8155eb14 100644 --- a/solution/1900-1999/1991.Find the Middle Index in Array/README.md +++ b/solution/1900-1999/1991.Find the Middle Index in Array/README.md @@ -104,6 +104,8 @@ tags: +#### Python3 + ```python class Solution: def findMiddleIndex(self, nums: List[int]) -> int: @@ -116,6 +118,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int findMiddleIndex(int[] nums) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func findMiddleIndex(nums []int) int { s := 0 @@ -166,6 +174,8 @@ func findMiddleIndex(nums []int) int { } ``` +#### TypeScript + ```ts function findMiddleIndex(nums: number[]): number { let left = 0, @@ -181,6 +191,8 @@ function findMiddleIndex(nums: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/1900-1999/1991.Find the Middle Index in Array/README_EN.md b/solution/1900-1999/1991.Find the Middle Index in Array/README_EN.md index 9681cddba7571..566edbe82ff6c 100644 --- a/solution/1900-1999/1991.Find the Middle Index in Array/README_EN.md +++ b/solution/1900-1999/1991.Find the Middle Index in Array/README_EN.md @@ -75,6 +75,8 @@ The sum of the numbers after index 2 is: 0 +#### Python3 + ```python class Solution: def findMiddleIndex(self, nums: List[int]) -> int: @@ -87,6 +89,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int findMiddleIndex(int[] nums) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func findMiddleIndex(nums []int) int { s := 0 @@ -137,6 +145,8 @@ func findMiddleIndex(nums []int) int { } ``` +#### TypeScript + ```ts function findMiddleIndex(nums: number[]): number { let left = 0, @@ -152,6 +162,8 @@ function findMiddleIndex(nums: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/1900-1999/1992.Find All Groups of Farmland/README.md b/solution/1900-1999/1992.Find All Groups of Farmland/README.md index 22fa11bc10806..a6cc18fe87a80 100644 --- a/solution/1900-1999/1992.Find All Groups of Farmland/README.md +++ b/solution/1900-1999/1992.Find All Groups of Farmland/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def findFarmland(self, land: List[List[int]]) -> List[List[int]]: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] findFarmland(int[][] land) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func findFarmland(land [][]int) [][]int { m, n := len(land), len(land[0]) diff --git a/solution/1900-1999/1992.Find All Groups of Farmland/README_EN.md b/solution/1900-1999/1992.Find All Groups of Farmland/README_EN.md index 15b47633afce0..e79bca85a7a7f 100644 --- a/solution/1900-1999/1992.Find All Groups of Farmland/README_EN.md +++ b/solution/1900-1999/1992.Find All Groups of Farmland/README_EN.md @@ -79,6 +79,8 @@ There are no groups of farmland. +#### Python3 + ```python class Solution: def findFarmland(self, land: List[List[int]]) -> List[List[int]]: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] findFarmland(int[][] land) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func findFarmland(land [][]int) [][]int { m, n := len(land), len(land[0]) diff --git a/solution/1900-1999/1993.Operations on Tree/README.md b/solution/1900-1999/1993.Operations on Tree/README.md index 34ba841181c80..65aac17e619e1 100644 --- a/solution/1900-1999/1993.Operations on Tree/README.md +++ b/solution/1900-1999/1993.Operations on Tree/README.md @@ -113,6 +113,8 @@ lockingTree.lock(0, 1); // 返回 false ,因为节点 0 已经被上锁了 +#### Python3 + ```python class LockingTree: def __init__(self, parent: List[int]): @@ -165,6 +167,8 @@ class LockingTree: # param_3 = obj.upgrade(num,user) ``` +#### Java + ```java class LockingTree { private int[] locked; @@ -236,6 +240,8 @@ class LockingTree { */ ``` +#### C++ + ```cpp class LockingTree { public: @@ -306,6 +312,8 @@ private: */ ``` +#### Go + ```go type LockingTree struct { locked []int @@ -377,6 +385,8 @@ func (this *LockingTree) Upgrade(num int, user int) bool { */ ``` +#### TypeScript + ```ts class LockingTree { private locked: number[]; diff --git a/solution/1900-1999/1993.Operations on Tree/README_EN.md b/solution/1900-1999/1993.Operations on Tree/README_EN.md index 26858ecba91b6..f21899531675c 100644 --- a/solution/1900-1999/1993.Operations on Tree/README_EN.md +++ b/solution/1900-1999/1993.Operations on Tree/README_EN.md @@ -97,6 +97,8 @@ lockingTree.lock(0, 1); // return false because node 0 is already locked. +#### Python3 + ```python class LockingTree: def __init__(self, parent: List[int]): @@ -149,6 +151,8 @@ class LockingTree: # param_3 = obj.upgrade(num,user) ``` +#### Java + ```java class LockingTree { private int[] locked; @@ -220,6 +224,8 @@ class LockingTree { */ ``` +#### C++ + ```cpp class LockingTree { public: @@ -290,6 +296,8 @@ private: */ ``` +#### Go + ```go type LockingTree struct { locked []int @@ -361,6 +369,8 @@ func (this *LockingTree) Upgrade(num int, user int) bool { */ ``` +#### TypeScript + ```ts class LockingTree { private locked: number[]; diff --git a/solution/1900-1999/1994.The Number of Good Subsets/README.md b/solution/1900-1999/1994.The Number of Good Subsets/README.md index eae8dcba56c16..8c088483d9df5 100644 --- a/solution/1900-1999/1994.The Number of Good Subsets/README.md +++ b/solution/1900-1999/1994.The Number of Good Subsets/README.md @@ -103,6 +103,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfGoodSubsets(self, nums: List[int]) -> int: @@ -125,6 +127,8 @@ class Solution: return sum(f[i] for i in range(1, 1 << n)) % mod ``` +#### Java + ```java class Solution { public int numberOfGoodSubsets(int[] nums) { @@ -165,6 +169,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -206,6 +212,8 @@ public: }; ``` +#### Go + ```go func numberOfGoodSubsets(nums []int) (ans int) { primes := []int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29} diff --git a/solution/1900-1999/1994.The Number of Good Subsets/README_EN.md b/solution/1900-1999/1994.The Number of Good Subsets/README_EN.md index f54e0066c7be2..3db69382669c8 100644 --- a/solution/1900-1999/1994.The Number of Good Subsets/README_EN.md +++ b/solution/1900-1999/1994.The Number of Good Subsets/README_EN.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfGoodSubsets(self, nums: List[int]) -> int: @@ -107,6 +109,8 @@ class Solution: return sum(f[i] for i in range(1, 1 << n)) % mod ``` +#### Java + ```java class Solution { public int numberOfGoodSubsets(int[] nums) { @@ -147,6 +151,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go func numberOfGoodSubsets(nums []int) (ans int) { primes := []int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29} diff --git a/solution/1900-1999/1995.Count Special Quadruplets/README.md b/solution/1900-1999/1995.Count Special Quadruplets/README.md index 31828061e9267..78d248e9a3fff 100644 --- a/solution/1900-1999/1995.Count Special Quadruplets/README.md +++ b/solution/1900-1999/1995.Count Special Quadruplets/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def countQuadruplets(self, nums: List[int]) -> int: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countQuadruplets(int[] nums) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func countQuadruplets(nums []int) int { ans, n := 0, len(nums) @@ -149,6 +157,8 @@ func countQuadruplets(nums []int) int { +#### Python3 + ```python class Solution: def countQuadruplets(self, nums: List[int]) -> int: @@ -162,6 +172,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countQuadruplets(int[] nums) { @@ -180,6 +192,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -199,6 +213,8 @@ public: }; ``` +#### Go + ```go func countQuadruplets(nums []int) int { ans, n := 0, len(nums) @@ -225,6 +241,8 @@ func countQuadruplets(nums []int) int { +#### Python3 + ```python class Solution: def countQuadruplets(self, nums: List[int]) -> int: @@ -239,6 +257,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countQuadruplets(int[] nums) { @@ -260,6 +280,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -282,6 +304,8 @@ public: }; ``` +#### Go + ```go func countQuadruplets(nums []int) int { ans, n := 0, len(nums) diff --git a/solution/1900-1999/1995.Count Special Quadruplets/README_EN.md b/solution/1900-1999/1995.Count Special Quadruplets/README_EN.md index a0302f1291bd5..0d03ec5b150e0 100644 --- a/solution/1900-1999/1995.Count Special Quadruplets/README_EN.md +++ b/solution/1900-1999/1995.Count Special Quadruplets/README_EN.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def countQuadruplets(self, nums: List[int]) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countQuadruplets(int[] nums) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func countQuadruplets(nums []int) int { ans, n := 0, len(nums) @@ -150,6 +158,8 @@ func countQuadruplets(nums []int) int { +#### Python3 + ```python class Solution: def countQuadruplets(self, nums: List[int]) -> int: @@ -163,6 +173,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countQuadruplets(int[] nums) { @@ -181,6 +193,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -200,6 +214,8 @@ public: }; ``` +#### Go + ```go func countQuadruplets(nums []int) int { ans, n := 0, len(nums) @@ -226,6 +242,8 @@ func countQuadruplets(nums []int) int { +#### Python3 + ```python class Solution: def countQuadruplets(self, nums: List[int]) -> int: @@ -240,6 +258,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countQuadruplets(int[] nums) { @@ -261,6 +281,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -283,6 +305,8 @@ public: }; ``` +#### Go + ```go func countQuadruplets(nums []int) int { ans, n := 0, len(nums) diff --git a/solution/1900-1999/1996.The Number of Weak Characters in the Game/README.md b/solution/1900-1999/1996.The Number of Weak Characters in the Game/README.md index 02b4a5b75520b..790f7050b0058 100644 --- a/solution/1900-1999/1996.The Number of Weak Characters in the Game/README.md +++ b/solution/1900-1999/1996.The Number of Weak Characters in the Game/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfWeakCharacters(self, properties: List[List[int]]) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numberOfWeakCharacters(int[][] properties) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func numberOfWeakCharacters(properties [][]int) (ans int) { sort.Slice(properties, func(i, j int) bool { @@ -145,6 +153,8 @@ func numberOfWeakCharacters(properties [][]int) (ans int) { } ``` +#### TypeScript + ```ts function numberOfWeakCharacters(properties: number[][]): number { properties.sort((a, b) => (a[0] == b[0] ? a[1] - b[1] : b[0] - a[0])); @@ -161,6 +171,8 @@ function numberOfWeakCharacters(properties: number[][]): number { } ``` +#### JavaScript + ```js /** * @param {number[][]} properties diff --git a/solution/1900-1999/1996.The Number of Weak Characters in the Game/README_EN.md b/solution/1900-1999/1996.The Number of Weak Characters in the Game/README_EN.md index 405ca8016dde5..e1b2c7c8a6b04 100644 --- a/solution/1900-1999/1996.The Number of Weak Characters in the Game/README_EN.md +++ b/solution/1900-1999/1996.The Number of Weak Characters in the Game/README_EN.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfWeakCharacters(self, properties: List[List[int]]) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numberOfWeakCharacters(int[][] properties) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func numberOfWeakCharacters(properties [][]int) (ans int) { sort.Slice(properties, func(i, j int) bool { @@ -135,6 +143,8 @@ func numberOfWeakCharacters(properties [][]int) (ans int) { } ``` +#### TypeScript + ```ts function numberOfWeakCharacters(properties: number[][]): number { properties.sort((a, b) => (a[0] == b[0] ? a[1] - b[1] : b[0] - a[0])); @@ -151,6 +161,8 @@ function numberOfWeakCharacters(properties: number[][]): number { } ``` +#### JavaScript + ```js /** * @param {number[][]} properties diff --git a/solution/1900-1999/1997.First Day Where You Have Been in All the Rooms/README.md b/solution/1900-1999/1997.First Day Where You Have Been in All the Rooms/README.md index 0a7b7f3d4a18a..7e4094857875a 100644 --- a/solution/1900-1999/1997.First Day Where You Have Been in All the Rooms/README.md +++ b/solution/1900-1999/1997.First Day Where You Have Been in All the Rooms/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class Solution: def firstDayBeenInAllRooms(self, nextVisit: List[int]) -> int: @@ -107,6 +109,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int firstDayBeenInAllRooms(int[] nextVisit) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func firstDayBeenInAllRooms(nextVisit []int) int { n := len(nextVisit) @@ -148,6 +156,8 @@ func firstDayBeenInAllRooms(nextVisit []int) int { } ``` +#### TypeScript + ```ts function firstDayBeenInAllRooms(nextVisit: number[]): number { const n = nextVisit.length; @@ -160,6 +170,8 @@ function firstDayBeenInAllRooms(nextVisit: number[]): number { } ``` +#### C# + ```cs public class Solution { public int FirstDayBeenInAllRooms(int[] nextVisit) { diff --git a/solution/1900-1999/1997.First Day Where You Have Been in All the Rooms/README_EN.md b/solution/1900-1999/1997.First Day Where You Have Been in All the Rooms/README_EN.md index 19d4c42223a36..ba072aca2dae9 100644 --- a/solution/1900-1999/1997.First Day Where You Have Been in All the Rooms/README_EN.md +++ b/solution/1900-1999/1997.First Day Where You Have Been in All the Rooms/README_EN.md @@ -94,6 +94,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python class Solution: def firstDayBeenInAllRooms(self, nextVisit: List[int]) -> int: @@ -105,6 +107,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int firstDayBeenInAllRooms(int[] nextVisit) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func firstDayBeenInAllRooms(nextVisit []int) int { n := len(nextVisit) @@ -146,6 +154,8 @@ func firstDayBeenInAllRooms(nextVisit []int) int { } ``` +#### TypeScript + ```ts function firstDayBeenInAllRooms(nextVisit: number[]): number { const n = nextVisit.length; @@ -158,6 +168,8 @@ function firstDayBeenInAllRooms(nextVisit: number[]): number { } ``` +#### C# + ```cs public class Solution { public int FirstDayBeenInAllRooms(int[] nextVisit) { diff --git a/solution/1900-1999/1998.GCD Sort of an Array/README.md b/solution/1900-1999/1998.GCD Sort of an Array/README.md index e08057066980f..c4bcdff6afb10 100644 --- a/solution/1900-1999/1998.GCD Sort of an Array/README.md +++ b/solution/1900-1999/1998.GCD Sort of an Array/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def gcdSort(self, nums: List[int]) -> bool: @@ -107,6 +109,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { private int[] p; @@ -155,6 +159,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -189,6 +195,8 @@ public: }; ``` +#### Go + ```go var p []int diff --git a/solution/1900-1999/1998.GCD Sort of an Array/README_EN.md b/solution/1900-1999/1998.GCD Sort of an Array/README_EN.md index 3c62fbce1d6c8..331dfafb0efaa 100644 --- a/solution/1900-1999/1998.GCD Sort of an Array/README_EN.md +++ b/solution/1900-1999/1998.GCD Sort of an Array/README_EN.md @@ -78,6 +78,8 @@ We can sort [10,5,9,3,15] by performing the following operations: +#### Python3 + ```python class Solution: def gcdSort(self, nums: List[int]) -> bool: @@ -107,6 +109,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { private int[] p; @@ -155,6 +159,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -189,6 +195,8 @@ public: }; ``` +#### Go + ```go var p []int diff --git a/solution/1900-1999/1999.Smallest Greater Multiple Made of Two Digits/README.md b/solution/1900-1999/1999.Smallest Greater Multiple Made of Two Digits/README.md index b3b522b379b4d..950c7331f9028 100644 --- a/solution/1900-1999/1999.Smallest Greater Multiple Made of Two Digits/README.md +++ b/solution/1900-1999/1999.Smallest Greater Multiple Made of Two Digits/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def findInteger(self, k: int, digit1: int, digit2: int) -> int: @@ -99,6 +101,8 @@ class Solution: q.append(x * 10 + digit2) ``` +#### Java + ```java class Solution { public int findInteger(int k, int digit1, int digit2) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func findInteger(k int, digit1 int, digit2 int) int { if digit1 == 0 && digit2 == 0 { diff --git a/solution/1900-1999/1999.Smallest Greater Multiple Made of Two Digits/README_EN.md b/solution/1900-1999/1999.Smallest Greater Multiple Made of Two Digits/README_EN.md index e53991ab4de8a..a86a2638227cc 100644 --- a/solution/1900-1999/1999.Smallest Greater Multiple Made of Two Digits/README_EN.md +++ b/solution/1900-1999/1999.Smallest Greater Multiple Made of Two Digits/README_EN.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def findInteger(self, k: int, digit1: int, digit2: int) -> int: @@ -93,6 +95,8 @@ class Solution: q.append(x * 10 + digit2) ``` +#### Java + ```java class Solution { public int findInteger(int k, int digit1, int digit2) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func findInteger(k int, digit1 int, digit2 int) int { if digit1 == 0 && digit2 == 0 { diff --git a/solution/2000-2099/2000.Reverse Prefix of Word/README.md b/solution/2000-2099/2000.Reverse Prefix of Word/README.md index 40e0327f96f28..e9b0ceedf2b59 100644 --- a/solution/2000-2099/2000.Reverse Prefix of Word/README.md +++ b/solution/2000-2099/2000.Reverse Prefix of Word/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def reversePrefix(self, word: str, ch: str) -> str: @@ -84,6 +86,8 @@ class Solution: return word if i == -1 else word[i::-1] + word[i + 1 :] ``` +#### Java + ```java class Solution { public String reversePrefix(String word, char ch) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func reversePrefix(word string, ch byte) string { j := strings.IndexByte(word, ch) @@ -130,6 +138,8 @@ func reversePrefix(word string, ch byte) string { } ``` +#### TypeScript + ```ts function reversePrefix(word: string, ch: string): string { const i = word.indexOf(ch) + 1; @@ -140,6 +150,8 @@ function reversePrefix(word: string, ch: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn reverse_prefix(word: String, ch: char) -> String { @@ -151,6 +163,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/2000-2099/2000.Reverse Prefix of Word/README_EN.md b/solution/2000-2099/2000.Reverse Prefix of Word/README_EN.md index 7c030353da6b1..6c6d59ce12870 100644 --- a/solution/2000-2099/2000.Reverse Prefix of Word/README_EN.md +++ b/solution/2000-2099/2000.Reverse Prefix of Word/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def reversePrefix(self, word: str, ch: str) -> str: @@ -85,6 +87,8 @@ class Solution: return word if i == -1 else word[i::-1] + word[i + 1 :] ``` +#### Java + ```java class Solution { public String reversePrefix(String word, char ch) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func reversePrefix(word string, ch byte) string { j := strings.IndexByte(word, ch) @@ -131,6 +139,8 @@ func reversePrefix(word string, ch byte) string { } ``` +#### TypeScript + ```ts function reversePrefix(word: string, ch: string): string { const i = word.indexOf(ch) + 1; @@ -141,6 +151,8 @@ function reversePrefix(word: string, ch: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn reverse_prefix(word: String, ch: char) -> String { @@ -152,6 +164,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/2000-2099/2001.Number of Pairs of Interchangeable Rectangles/README.md b/solution/2000-2099/2001.Number of Pairs of Interchangeable Rectangles/README.md index 9b25b7ba96b68..8aa5a06fde6ec 100644 --- a/solution/2000-2099/2001.Number of Pairs of Interchangeable Rectangles/README.md +++ b/solution/2000-2099/2001.Number of Pairs of Interchangeable Rectangles/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def interchangeableRectangles(self, rectangles: List[List[int]]) -> int: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long interchangeableRectangles(int[][] rectangles) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func interchangeableRectangles(rectangles [][]int) int64 { ans := 0 @@ -159,6 +167,8 @@ func gcd(a, b int) int { } ``` +#### JavaScript + ```js /** * @param {number[][]} rectangles diff --git a/solution/2000-2099/2001.Number of Pairs of Interchangeable Rectangles/README_EN.md b/solution/2000-2099/2001.Number of Pairs of Interchangeable Rectangles/README_EN.md index 78f77c61f8b70..e5ee32fa0bc03 100644 --- a/solution/2000-2099/2001.Number of Pairs of Interchangeable Rectangles/README_EN.md +++ b/solution/2000-2099/2001.Number of Pairs of Interchangeable Rectangles/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(n \times \log M)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def interchangeableRectangles(self, rectangles: List[List[int]]) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long interchangeableRectangles(int[][] rectangles) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func interchangeableRectangles(rectangles [][]int) int64 { ans := 0 @@ -157,6 +165,8 @@ func gcd(a, b int) int { } ``` +#### JavaScript + ```js /** * @param {number[][]} rectangles diff --git a/solution/2000-2099/2002.Maximum Product of the Length of Two Palindromic Subsequences/README.md b/solution/2000-2099/2002.Maximum Product of the Length of Two Palindromic Subsequences/README.md index 0b7ca32efd62f..9d8000206686a 100644 --- a/solution/2000-2099/2002.Maximum Product of the Length of Two Palindromic Subsequences/README.md +++ b/solution/2000-2099/2002.Maximum Product of the Length of Two Palindromic Subsequences/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def maxProduct(self, s: str) -> int: @@ -111,6 +113,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxProduct(String s) { @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -187,6 +193,8 @@ public: }; ``` +#### Go + ```go func maxProduct(s string) (ans int) { n := len(s) diff --git a/solution/2000-2099/2002.Maximum Product of the Length of Two Palindromic Subsequences/README_EN.md b/solution/2000-2099/2002.Maximum Product of the Length of Two Palindromic Subsequences/README_EN.md index 893bbd553eac2..e42b1b954bedd 100644 --- a/solution/2000-2099/2002.Maximum Product of the Length of Two Palindromic Subsequences/README_EN.md +++ b/solution/2000-2099/2002.Maximum Product of the Length of Two Palindromic Subsequences/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $(2^n \times n + 3^n)$, and the space complexity is $O(2^ +#### Python3 + ```python class Solution: def maxProduct(self, s: str) -> int: @@ -110,6 +112,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxProduct(String s) { @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go func maxProduct(s string) (ans int) { n := len(s) diff --git a/solution/2000-2099/2003.Smallest Missing Genetic Value in Each Subtree/README.md b/solution/2000-2099/2003.Smallest Missing Genetic Value in Each Subtree/README.md index d8c2f96c5ccbe..19ae9cb4646b8 100644 --- a/solution/2000-2099/2003.Smallest Missing Genetic Value in Each Subtree/README.md +++ b/solution/2000-2099/2003.Smallest Missing Genetic Value in Each Subtree/README.md @@ -104,6 +104,8 @@ tags: +#### Python3 + ```python class Solution: def smallestMissingValueSubtree( @@ -141,6 +143,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -194,6 +198,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -241,6 +247,8 @@ public: }; ``` +#### Go + ```go func smallestMissingValueSubtree(parents []int, nums []int) []int { n := len(nums) @@ -285,6 +293,8 @@ func smallestMissingValueSubtree(parents []int, nums []int) []int { } ``` +#### TypeScript + ```ts function smallestMissingValueSubtree(parents: number[], nums: number[]): number[] { const n = nums.length; @@ -327,6 +337,8 @@ function smallestMissingValueSubtree(parents: number[], nums: number[]): number[ } ``` +#### Rust + ```rust impl Solution { pub fn smallest_missing_value_subtree(parents: Vec, nums: Vec) -> Vec { diff --git a/solution/2000-2099/2003.Smallest Missing Genetic Value in Each Subtree/README_EN.md b/solution/2000-2099/2003.Smallest Missing Genetic Value in Each Subtree/README_EN.md index b61addd12828d..01e382e688604 100644 --- a/solution/2000-2099/2003.Smallest Missing Genetic Value in Each Subtree/README_EN.md +++ b/solution/2000-2099/2003.Smallest Missing Genetic Value in Each Subtree/README_EN.md @@ -101,6 +101,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def smallestMissingValueSubtree( @@ -138,6 +140,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -191,6 +195,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -238,6 +244,8 @@ public: }; ``` +#### Go + ```go func smallestMissingValueSubtree(parents []int, nums []int) []int { n := len(nums) @@ -282,6 +290,8 @@ func smallestMissingValueSubtree(parents []int, nums []int) []int { } ``` +#### TypeScript + ```ts function smallestMissingValueSubtree(parents: number[], nums: number[]): number[] { const n = nums.length; @@ -324,6 +334,8 @@ function smallestMissingValueSubtree(parents: number[], nums: number[]): number[ } ``` +#### Rust + ```rust impl Solution { pub fn smallest_missing_value_subtree(parents: Vec, nums: Vec) -> Vec { diff --git a/solution/2000-2099/2004.The Number of Seniors and Juniors to Join the Company/README.md b/solution/2000-2099/2004.The Number of Seniors and Juniors to Join the Company/README.md index 08a6604f8367f..de15b0c353b84 100644 --- a/solution/2000-2099/2004.The Number of Seniors and Juniors to Join the Company/README.md +++ b/solution/2000-2099/2004.The Number of Seniors and Juniors to Join the Company/README.md @@ -112,6 +112,8 @@ Candidates table: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2000-2099/2004.The Number of Seniors and Juniors to Join the Company/README_EN.md b/solution/2000-2099/2004.The Number of Seniors and Juniors to Join the Company/README_EN.md index 59e810e443170..d6b0d3d13dca9 100644 --- a/solution/2000-2099/2004.The Number of Seniors and Juniors to Join the Company/README_EN.md +++ b/solution/2000-2099/2004.The Number of Seniors and Juniors to Join the Company/README_EN.md @@ -111,6 +111,8 @@ We can hire all three juniors with the remaining budget. +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2000-2099/2005.Subtree Removal Game with Fibonacci Tree/README.md b/solution/2000-2099/2005.Subtree Removal Game with Fibonacci Tree/README.md index 1144bf46714c0..e9053affd7ef8 100644 --- a/solution/2000-2099/2005.Subtree Removal Game with Fibonacci Tree/README.md +++ b/solution/2000-2099/2005.Subtree Removal Game with Fibonacci Tree/README.md @@ -91,18 +91,26 @@ Bob 只能删除根节点 2,所以 Bob 输了。 +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2000-2099/2005.Subtree Removal Game with Fibonacci Tree/README_EN.md b/solution/2000-2099/2005.Subtree Removal Game with Fibonacci Tree/README_EN.md index d98a3fa8d4692..ebae83f24fda4 100644 --- a/solution/2000-2099/2005.Subtree Removal Game with Fibonacci Tree/README_EN.md +++ b/solution/2000-2099/2005.Subtree Removal Game with Fibonacci Tree/README_EN.md @@ -89,18 +89,26 @@ Return true because Alice wins. +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2000-2099/2006.Count Number of Pairs With Absolute Difference K/README.md b/solution/2000-2099/2006.Count Number of Pairs With Absolute Difference K/README.md index 42fa78a07e102..66cf2c910f022 100644 --- a/solution/2000-2099/2006.Count Number of Pairs With Absolute Difference K/README.md +++ b/solution/2000-2099/2006.Count Number of Pairs With Absolute Difference K/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def countKDifference(self, nums: List[int], k: int) -> int: @@ -94,6 +96,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public int countKDifference(int[] nums, int k) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func countKDifference(nums []int, k int) int { n := len(nums) @@ -148,6 +156,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function countKDifference(nums: number[], k: number): number { let ans = 0; @@ -160,6 +170,8 @@ function countKDifference(nums: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_k_difference(nums: Vec, k: i32) -> i32 { @@ -193,6 +205,8 @@ impl Solution { +#### Python3 + ```python class Solution: def countKDifference(self, nums: List[int], k: int) -> int: @@ -204,6 +218,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countKDifference(int[] nums, int k) { @@ -223,6 +239,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -243,6 +261,8 @@ public: }; ``` +#### Go + ```go func countKDifference(nums []int, k int) (ans int) { cnt := [110]int{} @@ -259,6 +279,8 @@ func countKDifference(nums []int, k int) (ans int) { } ``` +#### Rust + ```rust impl Solution { pub fn count_k_difference(nums: Vec, k: i32) -> i32 { diff --git a/solution/2000-2099/2006.Count Number of Pairs With Absolute Difference K/README_EN.md b/solution/2000-2099/2006.Count Number of Pairs With Absolute Difference K/README_EN.md index f1fcb78ace0ed..10169992e7a70 100644 --- a/solution/2000-2099/2006.Count Number of Pairs With Absolute Difference K/README_EN.md +++ b/solution/2000-2099/2006.Count Number of Pairs With Absolute Difference K/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(1)$. Here, $n$ i +#### Python3 + ```python class Solution: def countKDifference(self, nums: List[int], k: int) -> int: @@ -95,6 +97,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public int countKDifference(int[] nums, int k) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func countKDifference(nums []int, k int) int { n := len(nums) @@ -149,6 +157,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function countKDifference(nums: number[], k: number): number { let ans = 0; @@ -161,6 +171,8 @@ function countKDifference(nums: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_k_difference(nums: Vec, k: i32) -> i32 { @@ -194,6 +206,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def countKDifference(self, nums: List[int], k: int) -> int: @@ -205,6 +219,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countKDifference(int[] nums, int k) { @@ -224,6 +240,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -244,6 +262,8 @@ public: }; ``` +#### Go + ```go func countKDifference(nums []int, k int) (ans int) { cnt := [110]int{} @@ -260,6 +280,8 @@ func countKDifference(nums []int, k int) (ans int) { } ``` +#### Rust + ```rust impl Solution { pub fn count_k_difference(nums: Vec, k: i32) -> i32 { diff --git a/solution/2000-2099/2007.Find Original Array From Doubled Array/README.md b/solution/2000-2099/2007.Find Original Array From Doubled Array/README.md index e10761593224f..fb50e1269f59c 100644 --- a/solution/2000-2099/2007.Find Original Array From Doubled Array/README.md +++ b/solution/2000-2099/2007.Find Original Array From Doubled Array/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def findOriginalArray(self, changed: List[int]) -> List[int]: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] findOriginalArray(int[] changed) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func findOriginalArray(changed []int) (ans []int) { sort.Ints(changed) @@ -174,6 +182,8 @@ func findOriginalArray(changed []int) (ans []int) { } ``` +#### TypeScript + ```ts function findOriginalArray(changed: number[]): number[] { changed.sort((a, b) => a - b); diff --git a/solution/2000-2099/2007.Find Original Array From Doubled Array/README_EN.md b/solution/2000-2099/2007.Find Original Array From Doubled Array/README_EN.md index 1420c86406e98..8af4d0b114d47 100644 --- a/solution/2000-2099/2007.Find Original Array From Doubled Array/README_EN.md +++ b/solution/2000-2099/2007.Find Original Array From Doubled Array/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$, +#### Python3 + ```python class Solution: def findOriginalArray(self, changed: List[int]) -> List[int]: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] findOriginalArray(int[] changed) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func findOriginalArray(changed []int) (ans []int) { sort.Ints(changed) @@ -175,6 +183,8 @@ func findOriginalArray(changed []int) (ans []int) { } ``` +#### TypeScript + ```ts function findOriginalArray(changed: number[]): number[] { changed.sort((a, b) => a - b); diff --git a/solution/2000-2099/2008.Maximum Earnings From Taxi/README.md b/solution/2000-2099/2008.Maximum Earnings From Taxi/README.md index 5d915b0a52ae3..e6bc0808ed7d7 100644 --- a/solution/2000-2099/2008.Maximum Earnings From Taxi/README.md +++ b/solution/2000-2099/2008.Maximum Earnings From Taxi/README.md @@ -89,6 +89,8 @@ $$ +#### Python3 + ```python class Solution: def maxTaxiEarnings(self, n: int, rides: List[List[int]]) -> int: @@ -104,6 +106,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private int m; @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func maxTaxiEarnings(n int, rides [][]int) int64 { sort.Slice(rides, func(i, j int) bool { return rides[i][0] < rides[j][0] }) @@ -192,6 +200,8 @@ func maxTaxiEarnings(n int, rides [][]int) int64 { } ``` +#### TypeScript + ```ts function maxTaxiEarnings(n: number, rides: number[][]): number { rides.sort((a, b) => a[0] - b[0]); @@ -253,6 +263,8 @@ $$ +#### Python3 + ```python class Solution: def maxTaxiEarnings(self, n: int, rides: List[List[int]]) -> int: @@ -264,6 +276,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public long maxTaxiEarnings(int n, int[][] rides) { @@ -294,6 +308,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -313,6 +329,8 @@ public: }; ``` +#### Go + ```go func maxTaxiEarnings(n int, rides [][]int) int64 { sort.Slice(rides, func(i, j int) bool { return rides[i][1] < rides[j][1] }) @@ -328,6 +346,8 @@ func maxTaxiEarnings(n int, rides [][]int) int64 { } ``` +#### TypeScript + ```ts function maxTaxiEarnings(n: number, rides: number[][]): number { rides.sort((a, b) => a[1] - b[1]); diff --git a/solution/2000-2099/2008.Maximum Earnings From Taxi/README_EN.md b/solution/2000-2099/2008.Maximum Earnings From Taxi/README_EN.md index d0cc2067006ea..ace95e0421379 100644 --- a/solution/2000-2099/2008.Maximum Earnings From Taxi/README_EN.md +++ b/solution/2000-2099/2008.Maximum Earnings From Taxi/README_EN.md @@ -89,6 +89,8 @@ The time complexity is $O(m \times \log m)$, and the space complexity is $O(m)$. +#### Python3 + ```python class Solution: def maxTaxiEarnings(self, n: int, rides: List[List[int]]) -> int: @@ -104,6 +106,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private int m; @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func maxTaxiEarnings(n int, rides [][]int) int64 { sort.Slice(rides, func(i, j int) bool { return rides[i][0] < rides[j][0] }) @@ -192,6 +200,8 @@ func maxTaxiEarnings(n int, rides [][]int) int64 { } ``` +#### TypeScript + ```ts function maxTaxiEarnings(n: number, rides: number[][]): number { rides.sort((a, b) => a[0] - b[0]); @@ -253,6 +263,8 @@ Similar problems: +#### Python3 + ```python class Solution: def maxTaxiEarnings(self, n: int, rides: List[List[int]]) -> int: @@ -264,6 +276,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public long maxTaxiEarnings(int n, int[][] rides) { @@ -294,6 +308,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -313,6 +329,8 @@ public: }; ``` +#### Go + ```go func maxTaxiEarnings(n int, rides [][]int) int64 { sort.Slice(rides, func(i, j int) bool { return rides[i][1] < rides[j][1] }) @@ -328,6 +346,8 @@ func maxTaxiEarnings(n int, rides [][]int) int64 { } ``` +#### TypeScript + ```ts function maxTaxiEarnings(n: number, rides: number[][]): number { rides.sort((a, b) => a[1] - b[1]); diff --git a/solution/2000-2099/2009.Minimum Number of Operations to Make Array Continuous/README.md b/solution/2000-2099/2009.Minimum Number of Operations to Make Array Continuous/README.md index 345b926816694..c8fc041d37caf 100644 --- a/solution/2000-2099/2009.Minimum Number of Operations to Make Array Continuous/README.md +++ b/solution/2000-2099/2009.Minimum Number of Operations to Make Array Continuous/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int]) -> int: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minOperations(int[] nums) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int) int { sort.Ints(nums) @@ -170,6 +178,8 @@ func minOperations(nums []int) int { } ``` +#### Rust + ```rust use std::collections::BTreeSet; @@ -215,6 +225,8 @@ impl Solution { +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int]) -> int: @@ -228,6 +240,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minOperations(int[] nums) { @@ -251,6 +265,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -270,6 +286,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int) int { sort.Ints(nums) diff --git a/solution/2000-2099/2009.Minimum Number of Operations to Make Array Continuous/README_EN.md b/solution/2000-2099/2009.Minimum Number of Operations to Make Array Continuous/README_EN.md index edcd4e31521a0..788d6ea6ba7e6 100644 --- a/solution/2000-2099/2009.Minimum Number of Operations to Make Array Continuous/README_EN.md +++ b/solution/2000-2099/2009.Minimum Number of Operations to Make Array Continuous/README_EN.md @@ -90,6 +90,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int]) -> int: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minOperations(int[] nums) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int) int { sort.Ints(nums) @@ -171,6 +179,8 @@ func minOperations(nums []int) int { } ``` +#### Rust + ```rust use std::collections::BTreeSet; @@ -216,6 +226,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int]) -> int: @@ -229,6 +241,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minOperations(int[] nums) { @@ -252,6 +266,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -271,6 +287,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int) int { sort.Ints(nums) diff --git a/solution/2000-2099/2010.The Number of Seniors and Juniors to Join the Company II/README.md b/solution/2000-2099/2010.The Number of Seniors and Juniors to Join the Company II/README.md index b08c408afc2c8..496a1ca865d63 100644 --- a/solution/2000-2099/2010.The Number of Seniors and Juniors to Join the Company II/README.md +++ b/solution/2000-2099/2010.The Number of Seniors and Juniors to Join the Company II/README.md @@ -117,6 +117,8 @@ Candidates table: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2000-2099/2010.The Number of Seniors and Juniors to Join the Company II/README_EN.md b/solution/2000-2099/2010.The Number of Seniors and Juniors to Join the Company II/README_EN.md index b3daf5e854956..fb654501dbcb4 100644 --- a/solution/2000-2099/2010.The Number of Seniors and Juniors to Join the Company II/README_EN.md +++ b/solution/2000-2099/2010.The Number of Seniors and Juniors to Join the Company II/README_EN.md @@ -115,6 +115,8 @@ We can hire all three juniors with the remaining budget. +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2000-2099/2011.Final Value of Variable After Performing Operations/README.md b/solution/2000-2099/2011.Final Value of Variable After Performing Operations/README.md index 025914de64abc..fb25fd9622540 100644 --- a/solution/2000-2099/2011.Final Value of Variable After Performing Operations/README.md +++ b/solution/2000-2099/2011.Final Value of Variable After Performing Operations/README.md @@ -93,12 +93,16 @@ X--:X 减 1 ,X = 1 - 1 = 0 +#### Python3 + ```python class Solution: def finalValueAfterOperations(self, operations: List[str]) -> int: return sum(1 if s[1] == '+' else -1 for s in operations) ``` +#### Java + ```java class Solution { public int finalValueAfterOperations(String[] operations) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func finalValueAfterOperations(operations []string) (ans int) { for _, s := range operations { @@ -135,6 +143,8 @@ func finalValueAfterOperations(operations []string) (ans int) { } ``` +#### TypeScript + ```ts function finalValueAfterOperations(operations: string[]): number { let ans = 0; @@ -145,6 +155,8 @@ function finalValueAfterOperations(operations: string[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn final_value_after_operations(operations: Vec) -> i32 { @@ -157,6 +169,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string[]} operations @@ -171,6 +185,8 @@ var finalValueAfterOperations = function (operations) { }; ``` +#### C + ```c int finalValueAfterOperations(char** operations, int operationsSize) { int ans = 0; @@ -191,6 +207,8 @@ int finalValueAfterOperations(char** operations, int operationsSize) { +#### TypeScript + ```ts function finalValueAfterOperations(operations: string[]): number { return operations.reduce((r, v) => r + (v[1] === '+' ? 1 : -1), 0); diff --git a/solution/2000-2099/2011.Final Value of Variable After Performing Operations/README_EN.md b/solution/2000-2099/2011.Final Value of Variable After Performing Operations/README_EN.md index 2e61604574aac..ade0b3ec54916 100644 --- a/solution/2000-2099/2011.Final Value of Variable After Performing Operations/README_EN.md +++ b/solution/2000-2099/2011.Final Value of Variable After Performing Operations/README_EN.md @@ -91,12 +91,16 @@ The time complexity is $O(n)$, where $n$ is the length of the array `operations` +#### Python3 + ```python class Solution: def finalValueAfterOperations(self, operations: List[str]) -> int: return sum(1 if s[1] == '+' else -1 for s in operations) ``` +#### Java + ```java class Solution { public int finalValueAfterOperations(String[] operations) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func finalValueAfterOperations(operations []string) (ans int) { for _, s := range operations { @@ -133,6 +141,8 @@ func finalValueAfterOperations(operations []string) (ans int) { } ``` +#### TypeScript + ```ts function finalValueAfterOperations(operations: string[]): number { let ans = 0; @@ -143,6 +153,8 @@ function finalValueAfterOperations(operations: string[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn final_value_after_operations(operations: Vec) -> i32 { @@ -155,6 +167,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string[]} operations @@ -169,6 +183,8 @@ var finalValueAfterOperations = function (operations) { }; ``` +#### C + ```c int finalValueAfterOperations(char** operations, int operationsSize) { int ans = 0; @@ -189,6 +205,8 @@ int finalValueAfterOperations(char** operations, int operationsSize) { +#### TypeScript + ```ts function finalValueAfterOperations(operations: string[]): number { return operations.reduce((r, v) => r + (v[1] === '+' ? 1 : -1), 0); diff --git a/solution/2000-2099/2012.Sum of Beauty in the Array/README.md b/solution/2000-2099/2012.Sum of Beauty in the Array/README.md index e13bfe0e7e8be..1dbeeb99ae4fa 100644 --- a/solution/2000-2099/2012.Sum of Beauty in the Array/README.md +++ b/solution/2000-2099/2012.Sum of Beauty in the Array/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def sumOfBeauties(self, nums: List[int]) -> int: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int sumOfBeauties(int[] nums) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func sumOfBeauties(nums []int) (ans int) { n := len(nums) @@ -171,6 +179,8 @@ func sumOfBeauties(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function sumOfBeauties(nums: number[]): number { const n = nums.length; diff --git a/solution/2000-2099/2012.Sum of Beauty in the Array/README_EN.md b/solution/2000-2099/2012.Sum of Beauty in the Array/README_EN.md index 9708c9a69d12d..56cc3dfeae47e 100644 --- a/solution/2000-2099/2012.Sum of Beauty in the Array/README_EN.md +++ b/solution/2000-2099/2012.Sum of Beauty in the Array/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def sumOfBeauties(self, nums: List[int]) -> int: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int sumOfBeauties(int[] nums) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func sumOfBeauties(nums []int) (ans int) { n := len(nums) @@ -172,6 +180,8 @@ func sumOfBeauties(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function sumOfBeauties(nums: number[]): number { const n = nums.length; diff --git a/solution/2000-2099/2013.Detect Squares/README.md b/solution/2000-2099/2013.Detect Squares/README.md index 9163937e7a8fa..c1db3d5dae639 100644 --- a/solution/2000-2099/2013.Detect Squares/README.md +++ b/solution/2000-2099/2013.Detect Squares/README.md @@ -92,6 +92,8 @@ detectSquares.count([11, 10]); // 返回 2 。你可以选择: +#### Python3 + ```python class DetectSquares: def __init__(self): @@ -120,6 +122,8 @@ class DetectSquares: # param_2 = obj.count(point) ``` +#### Java + ```java class DetectSquares { private Map> cnt = new HashMap<>(); @@ -162,6 +166,8 @@ class DetectSquares { */ ``` +#### C++ + ```cpp class DetectSquares { public: @@ -202,6 +208,8 @@ private: */ ``` +#### Go + ```go type DetectSquares struct { cnt map[int]map[int]int diff --git a/solution/2000-2099/2013.Detect Squares/README_EN.md b/solution/2000-2099/2013.Detect Squares/README_EN.md index 1c3d51eb22bf1..3c4571b7b41ed 100644 --- a/solution/2000-2099/2013.Detect Squares/README_EN.md +++ b/solution/2000-2099/2013.Detect Squares/README_EN.md @@ -90,6 +90,8 @@ In terms of time complexity, the time complexity of calling the $add(x, y)$ meth +#### Python3 + ```python class DetectSquares: def __init__(self): @@ -118,6 +120,8 @@ class DetectSquares: # param_2 = obj.count(point) ``` +#### Java + ```java class DetectSquares { private Map> cnt = new HashMap<>(); @@ -160,6 +164,8 @@ class DetectSquares { */ ``` +#### C++ + ```cpp class DetectSquares { public: @@ -200,6 +206,8 @@ private: */ ``` +#### Go + ```go type DetectSquares struct { cnt map[int]map[int]int diff --git a/solution/2000-2099/2014.Longest Subsequence Repeated k Times/README.md b/solution/2000-2099/2014.Longest Subsequence Repeated k Times/README.md index 1aec81863bdec..971cc3b505454 100644 --- a/solution/2000-2099/2014.Longest Subsequence Repeated k Times/README.md +++ b/solution/2000-2099/2014.Longest Subsequence Repeated k Times/README.md @@ -84,18 +84,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2000-2099/2014.Longest Subsequence Repeated k Times/README_EN.md b/solution/2000-2099/2014.Longest Subsequence Repeated k Times/README_EN.md index 5a697b1eb26ad..31b8034b543c5 100644 --- a/solution/2000-2099/2014.Longest Subsequence Repeated k Times/README_EN.md +++ b/solution/2000-2099/2014.Longest Subsequence Repeated k Times/README_EN.md @@ -80,18 +80,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2000-2099/2015.Average Height of Buildings in Each Segment/README.md b/solution/2000-2099/2015.Average Height of Buildings in Each Segment/README.md index 465c16b0b16db..56472db80a8b6 100644 --- a/solution/2000-2099/2015.Average Height of Buildings in Each Segment/README.md +++ b/solution/2000-2099/2015.Average Height of Buildings in Each Segment/README.md @@ -104,6 +104,8 @@ tags: +#### Python3 + ```python class Solution: def averageHeightOfBuildings(self, buildings: List[List[int]]) -> List[List[int]]: @@ -129,6 +131,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] averageHeightOfBuildings(int[][] buildings) { @@ -166,6 +170,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -196,6 +202,8 @@ public: }; ``` +#### Go + ```go func averageHeightOfBuildings(buildings [][]int) [][]int { height := make(map[int]int) diff --git a/solution/2000-2099/2015.Average Height of Buildings in Each Segment/README_EN.md b/solution/2000-2099/2015.Average Height of Buildings in Each Segment/README_EN.md index cff58b87723c1..3dd6827cdc451 100644 --- a/solution/2000-2099/2015.Average Height of Buildings in Each Segment/README_EN.md +++ b/solution/2000-2099/2015.Average Height of Buildings in Each Segment/README_EN.md @@ -105,6 +105,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def averageHeightOfBuildings(self, buildings: List[List[int]]) -> List[List[int]]: @@ -130,6 +132,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] averageHeightOfBuildings(int[][] buildings) { @@ -167,6 +171,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -197,6 +203,8 @@ public: }; ``` +#### Go + ```go func averageHeightOfBuildings(buildings [][]int) [][]int { height := make(map[int]int) diff --git a/solution/2000-2099/2016.Maximum Difference Between Increasing Elements/README.md b/solution/2000-2099/2016.Maximum Difference Between Increasing Elements/README.md index 4de0bda11c994..2071ad30aa074 100644 --- a/solution/2000-2099/2016.Maximum Difference Between Increasing Elements/README.md +++ b/solution/2000-2099/2016.Maximum Difference Between Increasing Elements/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def maximumDifference(self, nums: List[int]) -> int: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumDifference(int[] nums) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func maximumDifference(nums []int) int { mi := 1 << 30 @@ -140,6 +148,8 @@ func maximumDifference(nums []int) int { } ``` +#### TypeScript + ```ts function maximumDifference(nums: number[]): number { const n = nums.length; @@ -153,6 +163,8 @@ function maximumDifference(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn maximum_difference(nums: Vec) -> i32 { @@ -170,6 +182,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/2000-2099/2016.Maximum Difference Between Increasing Elements/README_EN.md b/solution/2000-2099/2016.Maximum Difference Between Increasing Elements/README_EN.md index 577dec06ff30c..6e674cdebac22 100644 --- a/solution/2000-2099/2016.Maximum Difference Between Increasing Elements/README_EN.md +++ b/solution/2000-2099/2016.Maximum Difference Between Increasing Elements/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def maximumDifference(self, nums: List[int]) -> int: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumDifference(int[] nums) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func maximumDifference(nums []int) int { mi := 1 << 30 @@ -141,6 +149,8 @@ func maximumDifference(nums []int) int { } ``` +#### TypeScript + ```ts function maximumDifference(nums: number[]): number { const n = nums.length; @@ -154,6 +164,8 @@ function maximumDifference(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn maximum_difference(nums: Vec) -> i32 { @@ -171,6 +183,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/2000-2099/2017.Grid Game/README.md b/solution/2000-2099/2017.Grid Game/README.md index 92e7fcbee47ef..cc7c572ee9236 100644 --- a/solution/2000-2099/2017.Grid Game/README.md +++ b/solution/2000-2099/2017.Grid Game/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def gridGame(self, grid: List[List[int]]) -> int: @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long gridGame(int[][] grid) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func gridGame(grid [][]int) int64 { ans := math.MaxInt64 @@ -160,6 +168,8 @@ func gridGame(grid [][]int) int64 { } ``` +#### TypeScript + ```ts function gridGame(grid: number[][]): number { let ans = Number.MAX_SAFE_INTEGER; diff --git a/solution/2000-2099/2017.Grid Game/README_EN.md b/solution/2000-2099/2017.Grid Game/README_EN.md index db68522a14a90..2fe3a1d3ab902 100644 --- a/solution/2000-2099/2017.Grid Game/README_EN.md +++ b/solution/2000-2099/2017.Grid Game/README_EN.md @@ -89,6 +89,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is +#### Python3 + ```python class Solution: def gridGame(self, grid: List[List[int]]) -> int: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long gridGame(int[][] grid) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func gridGame(grid [][]int) int64 { ans := math.MaxInt64 @@ -156,6 +164,8 @@ func gridGame(grid [][]int) int64 { } ``` +#### TypeScript + ```ts function gridGame(grid: number[][]): number { let ans = Number.MAX_SAFE_INTEGER; diff --git a/solution/2000-2099/2018.Check if Word Can Be Placed In Crossword/README.md b/solution/2000-2099/2018.Check if Word Can Be Placed In Crossword/README.md index 86803567a8c76..5fc1f949fe9e2 100644 --- a/solution/2000-2099/2018.Check if Word Can Be Placed In Crossword/README.md +++ b/solution/2000-2099/2018.Check if Word Can Be Placed In Crossword/README.md @@ -106,6 +106,8 @@ tags: +#### Python3 + ```python class Solution: def placeWordInCrossword(self, board: List[List[str]], word: str) -> bool: @@ -142,6 +144,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { private int m; @@ -188,6 +192,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -224,6 +230,8 @@ public: }; ``` +#### Go + ```go func placeWordInCrossword(board [][]byte, word string) bool { m, n := len(board), len(board[0]) diff --git a/solution/2000-2099/2018.Check if Word Can Be Placed In Crossword/README_EN.md b/solution/2000-2099/2018.Check if Word Can Be Placed In Crossword/README_EN.md index 57716eb04183d..85a7020f25533 100644 --- a/solution/2000-2099/2018.Check if Word Can Be Placed In Crossword/README_EN.md +++ b/solution/2000-2099/2018.Check if Word Can Be Placed In Crossword/README_EN.md @@ -98,6 +98,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(1)$. Here +#### Python3 + ```python class Solution: def placeWordInCrossword(self, board: List[List[str]], word: str) -> bool: @@ -134,6 +136,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { private int m; @@ -180,6 +184,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -216,6 +222,8 @@ public: }; ``` +#### Go + ```go func placeWordInCrossword(board [][]byte, word string) bool { m, n := len(board), len(board[0]) diff --git a/solution/2000-2099/2019.The Score of Students Solving Math Expression/README.md b/solution/2000-2099/2019.The Score of Students Solving Math Expression/README.md index 3c95427443972..3f98e3762a616 100644 --- a/solution/2000-2099/2019.The Score of Students Solving Math Expression/README.md +++ b/solution/2000-2099/2019.The Score of Students Solving Math Expression/README.md @@ -120,6 +120,8 @@ $$ +#### Python3 + ```python class Solution: def scoreOfStudents(self, s: str, answers: List[int]) -> int: @@ -157,6 +159,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int scoreOfStudents(String s, int[] answers) { @@ -217,6 +221,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -275,6 +281,8 @@ public: }; ``` +#### Go + ```go func scoreOfStudents(s string, answers []int) int { n := len(s) @@ -333,6 +341,8 @@ func cal(s string) int { } ``` +#### TypeScript + ```ts function scoreOfStudents(s: string, answers: number[]): number { const n = s.length; diff --git a/solution/2000-2099/2019.The Score of Students Solving Math Expression/README_EN.md b/solution/2000-2099/2019.The Score of Students Solving Math Expression/README_EN.md index 5a733582ead96..57471129cdde4 100644 --- a/solution/2000-2099/2019.The Score of Students Solving Math Expression/README_EN.md +++ b/solution/2000-2099/2019.The Score of Students Solving Math Expression/README_EN.md @@ -119,6 +119,8 @@ The time complexity is $O(n^3 \times M^2)$, and the space complexity is $O(n^2 \ +#### Python3 + ```python class Solution: def scoreOfStudents(self, s: str, answers: List[int]) -> int: @@ -156,6 +158,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int scoreOfStudents(String s, int[] answers) { @@ -216,6 +220,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -274,6 +280,8 @@ public: }; ``` +#### Go + ```go func scoreOfStudents(s string, answers []int) int { n := len(s) @@ -332,6 +340,8 @@ func cal(s string) int { } ``` +#### TypeScript + ```ts function scoreOfStudents(s: string, answers: number[]): number { const n = s.length; diff --git a/solution/2000-2099/2020.Number of Accounts That Did Not Stream/README.md b/solution/2000-2099/2020.Number of Accounts That Did Not Stream/README.md index 082c057b7b94e..c4a2561acacff 100644 --- a/solution/2000-2099/2020.Number of Accounts That Did Not Stream/README.md +++ b/solution/2000-2099/2020.Number of Accounts That Did Not Stream/README.md @@ -98,6 +98,8 @@ Streams table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT COUNT(sub.account_id) AS accounts_count diff --git a/solution/2000-2099/2020.Number of Accounts That Did Not Stream/README_EN.md b/solution/2000-2099/2020.Number of Accounts That Did Not Stream/README_EN.md index 3fb5e8a532ddf..df1a6313db8e9 100644 --- a/solution/2000-2099/2020.Number of Accounts That Did Not Stream/README_EN.md +++ b/solution/2000-2099/2020.Number of Accounts That Did Not Stream/README_EN.md @@ -101,6 +101,8 @@ User 11 did not subscribe in 2021. +#### MySQL + ```sql # Write your MySQL query statement below SELECT COUNT(sub.account_id) AS accounts_count diff --git a/solution/2000-2099/2021.Brightest Position on Street/README.md b/solution/2000-2099/2021.Brightest Position on Street/README.md index 3f5d6b6e893fa..ebb76f1ebe4c1 100644 --- a/solution/2000-2099/2021.Brightest Position on Street/README.md +++ b/solution/2000-2099/2021.Brightest Position on Street/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def brightestPosition(self, lights: List[List[int]]) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int brightestPosition(int[][] lights) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func brightestPosition(lights [][]int) (ans int) { d := map[int]int{} @@ -168,6 +176,8 @@ func brightestPosition(lights [][]int) (ans int) { } ``` +#### JavaScript + ```js /** * @param {number[][]} lights diff --git a/solution/2000-2099/2021.Brightest Position on Street/README_EN.md b/solution/2000-2099/2021.Brightest Position on Street/README_EN.md index 79357885e7498..b1d2f9bfb9d07 100644 --- a/solution/2000-2099/2021.Brightest Position on Street/README_EN.md +++ b/solution/2000-2099/2021.Brightest Position on Street/README_EN.md @@ -94,6 +94,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def brightestPosition(self, lights: List[List[int]]) -> int: @@ -111,6 +113,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int brightestPosition(int[][] lights) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func brightestPosition(lights [][]int) (ans int) { d := map[int]int{} @@ -182,6 +190,8 @@ func brightestPosition(lights [][]int) (ans int) { } ``` +#### JavaScript + ```js /** * @param {number[][]} lights diff --git a/solution/2000-2099/2022.Convert 1D Array Into 2D Array/README.md b/solution/2000-2099/2022.Convert 1D Array Into 2D Array/README.md index 8a72205607366..bbe553fa25d14 100644 --- a/solution/2000-2099/2022.Convert 1D Array Into 2D Array/README.md +++ b/solution/2000-2099/2022.Convert 1D Array Into 2D Array/README.md @@ -91,6 +91,8 @@ original 中只有 1 个元素。 +#### Python3 + ```python class Solution: def construct2DArray(self, original: List[int], m: int, n: int) -> List[List[int]]: @@ -99,6 +101,8 @@ class Solution: return [original[i : i + n] for i in range(0, m * n, n)] ``` +#### Java + ```java class Solution { public int[][] construct2DArray(int[] original, int m, int n) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func construct2DArray(original []int, m int, n int) (ans [][]int) { if m*n != len(original) { @@ -146,6 +154,8 @@ func construct2DArray(original []int, m int, n int) (ans [][]int) { } ``` +#### TypeScript + ```ts function construct2DArray(original: number[], m: number, n: number): number[][] { if (m * n != original.length) { @@ -159,6 +169,8 @@ function construct2DArray(original: number[], m: number, n: number): number[][] } ``` +#### JavaScript + ```js /** * @param {number[]} original diff --git a/solution/2000-2099/2022.Convert 1D Array Into 2D Array/README_EN.md b/solution/2000-2099/2022.Convert 1D Array Into 2D Array/README_EN.md index 09605f797837e..0a719dbb6121a 100644 --- a/solution/2000-2099/2022.Convert 1D Array Into 2D Array/README_EN.md +++ b/solution/2000-2099/2022.Convert 1D Array Into 2D Array/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(m \times n)$, where $m$ and $n$ are the number of rows +#### Python3 + ```python class Solution: def construct2DArray(self, original: List[int], m: int, n: int) -> List[List[int]]: @@ -88,6 +90,8 @@ class Solution: return [original[i : i + n] for i in range(0, m * n, n)] ``` +#### Java + ```java class Solution { public int[][] construct2DArray(int[] original, int m, int n) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func construct2DArray(original []int, m int, n int) (ans [][]int) { if m*n != len(original) { @@ -135,6 +143,8 @@ func construct2DArray(original []int, m int, n int) (ans [][]int) { } ``` +#### TypeScript + ```ts function construct2DArray(original: number[], m: number, n: number): number[][] { if (m * n != original.length) { @@ -148,6 +158,8 @@ function construct2DArray(original: number[], m: number, n: number): number[][] } ``` +#### JavaScript + ```js /** * @param {number[]} original diff --git a/solution/2000-2099/2023.Number of Pairs of Strings With Concatenation Equal to Target/README.md b/solution/2000-2099/2023.Number of Pairs of Strings With Concatenation Equal to Target/README.md index 7837a6940dec3..429a401ffe04d 100644 --- a/solution/2000-2099/2023.Number of Pairs of Strings With Concatenation Equal to Target/README.md +++ b/solution/2000-2099/2023.Number of Pairs of Strings With Concatenation Equal to Target/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def numOfPairs(self, nums: List[str], target: str) -> int: @@ -93,6 +95,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public int numOfPairs(String[] nums, String target) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func numOfPairs(nums []string, target string) (ans int) { for i, a := range nums { @@ -153,6 +161,8 @@ func numOfPairs(nums []string, target string) (ans int) { +#### Python3 + ```python class Solution: def numOfPairs(self, nums: List[str], target: str) -> int: @@ -167,6 +177,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numOfPairs(String[] nums, String target) { @@ -191,6 +203,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -213,6 +227,8 @@ public: }; ``` +#### Go + ```go func numOfPairs(nums []string, target string) (ans int) { cnt := map[string]int{} diff --git a/solution/2000-2099/2023.Number of Pairs of Strings With Concatenation Equal to Target/README_EN.md b/solution/2000-2099/2023.Number of Pairs of Strings With Concatenation Equal to Target/README_EN.md index 5a305ee29af65..6dc3db6c6f65e 100644 --- a/solution/2000-2099/2023.Number of Pairs of Strings With Concatenation Equal to Target/README_EN.md +++ b/solution/2000-2099/2023.Number of Pairs of Strings With Concatenation Equal to Target/README_EN.md @@ -85,6 +85,8 @@ The time complexity is $O(n^2 \times m)$, where $n$ and $m$ are the lengths of t +#### Python3 + ```python class Solution: def numOfPairs(self, nums: List[str], target: str) -> int: @@ -94,6 +96,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public int numOfPairs(String[] nums, String target) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func numOfPairs(nums []string, target string) (ans int) { for i, a := range nums { @@ -154,6 +162,8 @@ The time complexity is $O(n + m^2)$, and the space complexity is $O(n)$. Here, $ +#### Python3 + ```python class Solution: def numOfPairs(self, nums: List[str], target: str) -> int: @@ -168,6 +178,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numOfPairs(String[] nums, String target) { @@ -192,6 +204,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -214,6 +228,8 @@ public: }; ``` +#### Go + ```go func numOfPairs(nums []string, target string) (ans int) { cnt := map[string]int{} diff --git a/solution/2000-2099/2024.Maximize the Confusion of an Exam/README.md b/solution/2000-2099/2024.Maximize the Confusion of an Exam/README.md index c5ae120b9d4a4..657d15a108179 100644 --- a/solution/2000-2099/2024.Maximize the Confusion of an Exam/README.md +++ b/solution/2000-2099/2024.Maximize the Confusion of an Exam/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def maxConsecutiveAnswers(self, answerKey: str, k: int) -> int: @@ -106,6 +108,8 @@ class Solution: return max(f("T"), f("F")) ``` +#### Java + ```java class Solution { private char[] s; @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func maxConsecutiveAnswers(answerKey string, k int) int { f := func(c byte) int { @@ -174,6 +182,8 @@ func maxConsecutiveAnswers(answerKey string, k int) int { } ``` +#### TypeScript + ```ts function maxConsecutiveAnswers(answerKey: string, k: number): number { const n = answerKey.length; @@ -192,6 +202,8 @@ function maxConsecutiveAnswers(answerKey: string, k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_consecutive_answers(answer_key: String, k: i32) -> i32 { diff --git a/solution/2000-2099/2024.Maximize the Confusion of an Exam/README_EN.md b/solution/2000-2099/2024.Maximize the Confusion of an Exam/README_EN.md index b2f83d72de59a..2c68d235a6ef7 100644 --- a/solution/2000-2099/2024.Maximize the Confusion of an Exam/README_EN.md +++ b/solution/2000-2099/2024.Maximize the Confusion of an Exam/README_EN.md @@ -87,6 +87,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string. The space +#### Python3 + ```python class Solution: def maxConsecutiveAnswers(self, answerKey: str, k: int) -> int: @@ -104,6 +106,8 @@ class Solution: return max(f("T"), f("F")) ``` +#### Java + ```java class Solution { private char[] s; @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func maxConsecutiveAnswers(answerKey string, k int) int { f := func(c byte) int { @@ -172,6 +180,8 @@ func maxConsecutiveAnswers(answerKey string, k int) int { } ``` +#### TypeScript + ```ts function maxConsecutiveAnswers(answerKey: string, k: number): number { const n = answerKey.length; @@ -190,6 +200,8 @@ function maxConsecutiveAnswers(answerKey: string, k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_consecutive_answers(answer_key: String, k: i32) -> i32 { diff --git a/solution/2000-2099/2025.Maximum Number of Ways to Partition an Array/README.md b/solution/2000-2099/2025.Maximum Number of Ways to Partition an Array/README.md index 1125a6d251227..9443bdd40b4ae 100644 --- a/solution/2000-2099/2025.Maximum Number of Ways to Partition an Array/README.md +++ b/solution/2000-2099/2025.Maximum Number of Ways to Partition an Array/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def waysToPartition(self, nums: List[int], k: int) -> int: @@ -118,6 +120,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int waysToPartition(int[] nums, int k) { @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -180,6 +186,8 @@ public: }; ``` +#### Go + ```go func waysToPartition(nums []int, k int) (ans int) { n := len(nums) diff --git a/solution/2000-2099/2025.Maximum Number of Ways to Partition an Array/README_EN.md b/solution/2000-2099/2025.Maximum Number of Ways to Partition an Array/README_EN.md index c59f8466b168a..8033878ce068c 100644 --- a/solution/2000-2099/2025.Maximum Number of Ways to Partition an Array/README_EN.md +++ b/solution/2000-2099/2025.Maximum Number of Ways to Partition an Array/README_EN.md @@ -93,6 +93,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def waysToPartition(self, nums: List[int], k: int) -> int: @@ -119,6 +121,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int waysToPartition(int[] nums, int k) { @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func waysToPartition(nums []int, k int) (ans int) { n := len(nums) diff --git a/solution/2000-2099/2026.Low-Quality Problems/README.md b/solution/2000-2099/2026.Low-Quality Problems/README.md index c047427b31805..05e6c66ff6cb8 100644 --- a/solution/2000-2099/2026.Low-Quality Problems/README.md +++ b/solution/2000-2099/2026.Low-Quality Problems/README.md @@ -83,6 +83,8 @@ Problems 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT problem_id diff --git a/solution/2000-2099/2026.Low-Quality Problems/README_EN.md b/solution/2000-2099/2026.Low-Quality Problems/README_EN.md index a04c320d41326..45c9a909d0d56 100644 --- a/solution/2000-2099/2026.Low-Quality Problems/README_EN.md +++ b/solution/2000-2099/2026.Low-Quality Problems/README_EN.md @@ -82,6 +82,8 @@ Problems 7, 10, 11, and 13 are low-quality problems because their like percentag +#### MySQL + ```sql # Write your MySQL query statement below SELECT problem_id diff --git a/solution/2000-2099/2027.Minimum Moves to Convert String/README.md b/solution/2000-2099/2027.Minimum Moves to Convert String/README.md index c5a80867a4009..3addbf38a40a2 100644 --- a/solution/2000-2099/2027.Minimum Moves to Convert String/README.md +++ b/solution/2000-2099/2027.Minimum Moves to Convert String/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def minimumMoves(self, s: str) -> int: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumMoves(String s) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func minimumMoves(s string) (ans int) { for i := 0; i < len(s); i++ { @@ -132,6 +140,8 @@ func minimumMoves(s string) (ans int) { } ``` +#### TypeScript + ```ts function minimumMoves(s: string): number { const n = s.length; @@ -149,6 +159,8 @@ function minimumMoves(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn minimum_moves(s: String) -> i32 { @@ -169,6 +181,8 @@ impl Solution { } ``` +#### C + ```c int minimumMoves(char* s) { int n = strlen(s); diff --git a/solution/2000-2099/2027.Minimum Moves to Convert String/README_EN.md b/solution/2000-2099/2027.Minimum Moves to Convert String/README_EN.md index 38371b1fa7359..7bf5d52cd5b52 100644 --- a/solution/2000-2099/2027.Minimum Moves to Convert String/README_EN.md +++ b/solution/2000-2099/2027.Minimum Moves to Convert String/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(n)$, where $n$ represents the length of the string $s$ +#### Python3 + ```python class Solution: def minimumMoves(self, s: str) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumMoves(String s) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func minimumMoves(s string) (ans int) { for i := 0; i < len(s); i++ { @@ -130,6 +138,8 @@ func minimumMoves(s string) (ans int) { } ``` +#### TypeScript + ```ts function minimumMoves(s: string): number { const n = s.length; @@ -147,6 +157,8 @@ function minimumMoves(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn minimum_moves(s: String) -> i32 { @@ -167,6 +179,8 @@ impl Solution { } ``` +#### C + ```c int minimumMoves(char* s) { int n = strlen(s); diff --git a/solution/2000-2099/2028.Find Missing Observations/README.md b/solution/2000-2099/2028.Find Missing Observations/README.md index 1b498e79b49df..d7fb13431874c 100644 --- a/solution/2000-2099/2028.Find Missing Observations/README.md +++ b/solution/2000-2099/2028.Find Missing Observations/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def missingRolls(self, rolls: List[int], mean: int, n: int) -> List[int]: @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] missingRolls(int[] rolls, int mean, int n) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func missingRolls(rolls []int, mean int, n int) []int { m := len(rolls) @@ -162,6 +170,8 @@ func missingRolls(rolls []int, mean int, n int) []int { } ``` +#### TypeScript + ```ts function missingRolls(rolls: number[], mean: number, n: number): number[] { const len = rolls.length + n; @@ -194,6 +204,8 @@ function missingRolls(rolls: number[], mean: number, n: number): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn missing_rolls(rolls: Vec, mean: i32, n: i32) -> Vec { diff --git a/solution/2000-2099/2028.Find Missing Observations/README_EN.md b/solution/2000-2099/2028.Find Missing Observations/README_EN.md index ddcab5845430d..753c7b117082e 100644 --- a/solution/2000-2099/2028.Find Missing Observations/README_EN.md +++ b/solution/2000-2099/2028.Find Missing Observations/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n + m)$, and the space complexity is $O(1)$. Here, $n$ +#### Python3 + ```python class Solution: def missingRolls(self, rolls: List[int], mean: int, n: int) -> List[int]: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] missingRolls(int[] rolls, int mean, int n) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func missingRolls(rolls []int, mean int, n int) []int { m := len(rolls) @@ -152,6 +160,8 @@ func missingRolls(rolls []int, mean int, n int) []int { } ``` +#### TypeScript + ```ts function missingRolls(rolls: number[], mean: number, n: number): number[] { const len = rolls.length + n; @@ -184,6 +194,8 @@ function missingRolls(rolls: number[], mean: number, n: number): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn missing_rolls(rolls: Vec, mean: i32, n: i32) -> Vec { diff --git a/solution/2000-2099/2029.Stone Game IX/README.md b/solution/2000-2099/2029.Stone Game IX/README.md index 2caeb93ad8658..3d77ab7e0a4c1 100644 --- a/solution/2000-2099/2029.Stone Game IX/README.md +++ b/solution/2000-2099/2029.Stone Game IX/README.md @@ -88,6 +88,8 @@ Alice 输掉游戏,因为已移除石子值总和(15)可以被 3 整除, +#### Python3 + ```python class Solution: def stoneGameIX(self, stones: List[int]) -> bool: @@ -108,6 +110,8 @@ class Solution: return check(c) or check(c1) ``` +#### Java + ```java class Solution { public boolean stoneGameIX(int[] stones) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func stoneGameIX(stones []int) bool { check := func(c [3]int) bool { diff --git a/solution/2000-2099/2029.Stone Game IX/README_EN.md b/solution/2000-2099/2029.Stone Game IX/README_EN.md index 6c0d70298a09f..f9c7e94f2768f 100644 --- a/solution/2000-2099/2029.Stone Game IX/README_EN.md +++ b/solution/2000-2099/2029.Stone Game IX/README_EN.md @@ -81,6 +81,8 @@ Alice loses the game because the sum of the removed stones (15) is divisible by +#### Python3 + ```python class Solution: def stoneGameIX(self, stones: List[int]) -> bool: @@ -101,6 +103,8 @@ class Solution: return check(c) or check(c1) ``` +#### Java + ```java class Solution { public boolean stoneGameIX(int[] stones) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func stoneGameIX(stones []int) bool { check := func(c [3]int) bool { diff --git a/solution/2000-2099/2030.Smallest K-Length Subsequence With Occurrences of a Letter/README.md b/solution/2000-2099/2030.Smallest K-Length Subsequence With Occurrences of a Letter/README.md index 86914e6d3417a..0327666aa3fcb 100644 --- a/solution/2000-2099/2030.Smallest K-Length Subsequence With Occurrences of a Letter/README.md +++ b/solution/2000-2099/2030.Smallest K-Length Subsequence With Occurrences of a Letter/README.md @@ -82,18 +82,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2000-2099/2030.Smallest K-Length Subsequence With Occurrences of a Letter/README_EN.md b/solution/2000-2099/2030.Smallest K-Length Subsequence With Occurrences of a Letter/README_EN.md index 741b351c141d9..ac533d741726d 100644 --- a/solution/2000-2099/2030.Smallest K-Length Subsequence With Occurrences of a Letter/README_EN.md +++ b/solution/2000-2099/2030.Smallest K-Length Subsequence With Occurrences of a Letter/README_EN.md @@ -78,18 +78,26 @@ The lexicographically smallest subsequence among them is "eet". +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2000-2099/2031.Count Subarrays With More Ones Than Zeros/README.md b/solution/2000-2099/2031.Count Subarrays With More Ones Than Zeros/README.md index 429ca330fc0ce..08b1f1e3c7700 100644 --- a/solution/2000-2099/2031.Count Subarrays With More Ones Than Zeros/README.md +++ b/solution/2000-2099/2031.Count Subarrays With More Ones Than Zeros/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class BinaryIndexedTree: __slots__ = ["n", "c"] @@ -122,6 +124,8 @@ class Solution: return ans ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -166,6 +170,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { private: @@ -212,6 +218,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -256,6 +264,8 @@ func subarraysWithMoreZerosThanOnes(nums []int) (ans int) { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; @@ -309,6 +319,8 @@ function subarraysWithMoreZerosThanOnes(nums: number[]): number { +#### Python3 + ```python from sortedcontainers import SortedList diff --git a/solution/2000-2099/2031.Count Subarrays With More Ones Than Zeros/README_EN.md b/solution/2000-2099/2031.Count Subarrays With More Ones Than Zeros/README_EN.md index 3b86ba034258c..05a7b8d838d59 100644 --- a/solution/2000-2099/2031.Count Subarrays With More Ones Than Zeros/README_EN.md +++ b/solution/2000-2099/2031.Count Subarrays With More Ones Than Zeros/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class BinaryIndexedTree: __slots__ = ["n", "c"] @@ -123,6 +125,8 @@ class Solution: return ans ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -167,6 +171,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { private: @@ -213,6 +219,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -257,6 +265,8 @@ func subarraysWithMoreZerosThanOnes(nums []int) (ans int) { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; @@ -310,6 +320,8 @@ function subarraysWithMoreZerosThanOnes(nums: number[]): number { +#### Python3 + ```python from sortedcontainers import SortedList diff --git a/solution/2000-2099/2032.Two Out of Three/README.md b/solution/2000-2099/2032.Two Out of Three/README.md index 71828062d07e1..87364dda70f89 100644 --- a/solution/2000-2099/2032.Two Out of Three/README.md +++ b/solution/2000-2099/2032.Two Out of Three/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def twoOutOfThree( @@ -85,6 +87,8 @@ class Solution: return [i for i in range(1, 101) if (i in s1) + (i in s2) + (i in s3) > 1] ``` +#### Java + ```java class Solution { public List twoOutOfThree(int[] nums1, int[] nums2, int[] nums3) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func twoOutOfThree(nums1 []int, nums2 []int, nums3 []int) (ans []int) { get := func(nums []int) (s [101]int) { @@ -147,6 +155,8 @@ func twoOutOfThree(nums1 []int, nums2 []int, nums3 []int) (ans []int) { } ``` +#### TypeScript + ```ts function twoOutOfThree(nums1: number[], nums2: number[], nums3: number[]): number[] { const count = new Array(101).fill(0); @@ -163,6 +173,8 @@ function twoOutOfThree(nums1: number[], nums2: number[], nums3: number[]): numbe } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { diff --git a/solution/2000-2099/2032.Two Out of Three/README_EN.md b/solution/2000-2099/2032.Two Out of Three/README_EN.md index ab7e19479a45a..3addc3751bfdf 100644 --- a/solution/2000-2099/2032.Two Out of Three/README_EN.md +++ b/solution/2000-2099/2032.Two Out of Three/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(n_1 + n_2 + n_3)$, and the space complexity is $O(n_1 +#### Python3 + ```python class Solution: def twoOutOfThree( @@ -83,6 +85,8 @@ class Solution: return [i for i in range(1, 101) if (i in s1) + (i in s2) + (i in s3) > 1] ``` +#### Java + ```java class Solution { public List twoOutOfThree(int[] nums1, int[] nums2, int[] nums3) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func twoOutOfThree(nums1 []int, nums2 []int, nums3 []int) (ans []int) { get := func(nums []int) (s [101]int) { @@ -145,6 +153,8 @@ func twoOutOfThree(nums1 []int, nums2 []int, nums3 []int) (ans []int) { } ``` +#### TypeScript + ```ts function twoOutOfThree(nums1: number[], nums2: number[], nums3: number[]): number[] { const count = new Array(101).fill(0); @@ -161,6 +171,8 @@ function twoOutOfThree(nums1: number[], nums2: number[], nums3: number[]): numbe } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { diff --git a/solution/2000-2099/2033.Minimum Operations to Make a Uni-Value Grid/README.md b/solution/2000-2099/2033.Minimum Operations to Make a Uni-Value Grid/README.md index 952c878a60a3c..8b89ac1c47017 100644 --- a/solution/2000-2099/2033.Minimum Operations to Make a Uni-Value Grid/README.md +++ b/solution/2000-2099/2033.Minimum Operations to Make a Uni-Value Grid/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def minOperations(self, grid: List[List[int]], x: int) -> int: @@ -106,6 +108,8 @@ class Solution: return sum(abs(v - mid) // x for v in nums) ``` +#### Java + ```java class Solution { public int minOperations(int[][] grid, int x) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func minOperations(grid [][]int, x int) int { mod := grid[0][0] % x diff --git a/solution/2000-2099/2033.Minimum Operations to Make a Uni-Value Grid/README_EN.md b/solution/2000-2099/2033.Minimum Operations to Make a Uni-Value Grid/README_EN.md index 6e69da6279531..202e609bd8de3 100644 --- a/solution/2000-2099/2033.Minimum Operations to Make a Uni-Value Grid/README_EN.md +++ b/solution/2000-2099/2033.Minimum Operations to Make a Uni-Value Grid/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O((m \times n) \times \log (m \times n))$, and the space +#### Python3 + ```python class Solution: def minOperations(self, grid: List[List[int]], x: int) -> int: @@ -98,6 +100,8 @@ class Solution: return sum(abs(v - mid) // x for v in nums) ``` +#### Java + ```java class Solution { public int minOperations(int[][] grid, int x) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func minOperations(grid [][]int, x int) int { mod := grid[0][0] % x diff --git a/solution/2000-2099/2034.Stock Price Fluctuation/README.md b/solution/2000-2099/2034.Stock Price Fluctuation/README.md index 92da47c25f222..2086a63f83136 100644 --- a/solution/2000-2099/2034.Stock Price Fluctuation/README.md +++ b/solution/2000-2099/2034.Stock Price Fluctuation/README.md @@ -103,6 +103,8 @@ stockPrice.minimum(); // 返回 2 ,最低价格时间戳为 4 ,价格为 +#### Python3 + ```python from sortedcontainers import SortedList @@ -138,6 +140,8 @@ class StockPrice: # param_4 = obj.minimum() ``` +#### Java + ```java class StockPrice { private Map d = new HashMap<>(); @@ -182,6 +186,8 @@ class StockPrice { */ ``` +#### C++ + ```cpp class StockPrice { public: @@ -225,6 +231,8 @@ private: */ ``` +#### Go + ```go type StockPrice struct { d map[int]int diff --git a/solution/2000-2099/2034.Stock Price Fluctuation/README_EN.md b/solution/2000-2099/2034.Stock Price Fluctuation/README_EN.md index 17c914f5cf084..efb87ad3aa4f5 100644 --- a/solution/2000-2099/2034.Stock Price Fluctuation/README_EN.md +++ b/solution/2000-2099/2034.Stock Price Fluctuation/README_EN.md @@ -102,6 +102,8 @@ The space complexity is $O(n)$, where $n$ is the number of `update` operations. +#### Python3 + ```python from sortedcontainers import SortedList @@ -137,6 +139,8 @@ class StockPrice: # param_4 = obj.minimum() ``` +#### Java + ```java class StockPrice { private Map d = new HashMap<>(); @@ -181,6 +185,8 @@ class StockPrice { */ ``` +#### C++ + ```cpp class StockPrice { public: @@ -224,6 +230,8 @@ private: */ ``` +#### Go + ```go type StockPrice struct { d map[int]int diff --git a/solution/2000-2099/2035.Partition Array Into Two Arrays to Minimize Sum Difference/README.md b/solution/2000-2099/2035.Partition Array Into Two Arrays to Minimize Sum Difference/README.md index 54d2893b42e54..fb0357080a332 100644 --- a/solution/2000-2099/2035.Partition Array Into Two Arrays to Minimize Sum Difference/README.md +++ b/solution/2000-2099/2035.Partition Array Into Two Arrays to Minimize Sum Difference/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def minimumDifference(self, nums: List[int]) -> int: @@ -118,6 +120,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumDifference(int[] nums) { @@ -169,6 +173,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -217,6 +223,8 @@ public: }; ``` +#### Go + ```go func minimumDifference(nums []int) int { n := len(nums) >> 1 diff --git a/solution/2000-2099/2035.Partition Array Into Two Arrays to Minimize Sum Difference/README_EN.md b/solution/2000-2099/2035.Partition Array Into Two Arrays to Minimize Sum Difference/README_EN.md index ba677e2277a03..9d73059492e22 100644 --- a/solution/2000-2099/2035.Partition Array Into Two Arrays to Minimize Sum Difference/README_EN.md +++ b/solution/2000-2099/2035.Partition Array Into Two Arrays to Minimize Sum Difference/README_EN.md @@ -75,6 +75,8 @@ The absolute difference between the sums of the arrays is abs((2 + 4 + -9) - (-1 +#### Python3 + ```python class Solution: def minimumDifference(self, nums: List[int]) -> int: @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumDifference(int[] nums) { @@ -166,6 +170,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -214,6 +220,8 @@ public: }; ``` +#### Go + ```go func minimumDifference(nums []int) int { n := len(nums) >> 1 diff --git a/solution/2000-2099/2036.Maximum Alternating Subarray Sum/README.md b/solution/2000-2099/2036.Maximum Alternating Subarray Sum/README.md index 3c1f1c411e8ad..3d2e551c11625 100644 --- a/solution/2000-2099/2036.Maximum Alternating Subarray Sum/README.md +++ b/solution/2000-2099/2036.Maximum Alternating Subarray Sum/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def maximumAlternatingSubarraySum(self, nums: List[int]) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maximumAlternatingSubarraySum(int[] nums) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func maximumAlternatingSubarraySum(nums []int) int64 { const inf = 1 << 60 @@ -134,6 +142,8 @@ func maximumAlternatingSubarraySum(nums []int) int64 { } ``` +#### TypeScript + ```ts function maximumAlternatingSubarraySum(nums: number[]): number { let [ans, f, g] = [-Infinity, -Infinity, -Infinity]; diff --git a/solution/2000-2099/2036.Maximum Alternating Subarray Sum/README_EN.md b/solution/2000-2099/2036.Maximum Alternating Subarray Sum/README_EN.md index 70e36ea202b95..911a2efa664c7 100644 --- a/solution/2000-2099/2036.Maximum Alternating Subarray Sum/README_EN.md +++ b/solution/2000-2099/2036.Maximum Alternating Subarray Sum/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def maximumAlternatingSubarraySum(self, nums: List[int]) -> int: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maximumAlternatingSubarraySum(int[] nums) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func maximumAlternatingSubarraySum(nums []int) int64 { const inf = 1 << 60 @@ -136,6 +144,8 @@ func maximumAlternatingSubarraySum(nums []int) int64 { } ``` +#### TypeScript + ```ts function maximumAlternatingSubarraySum(nums: number[]): number { let [ans, f, g] = [-Infinity, -Infinity, -Infinity]; diff --git a/solution/2000-2099/2037.Minimum Number of Moves to Seat Everyone/README.md b/solution/2000-2099/2037.Minimum Number of Moves to Seat Everyone/README.md index 64a155b4f8b33..163cc801628c0 100644 --- a/solution/2000-2099/2037.Minimum Number of Moves to Seat Everyone/README.md +++ b/solution/2000-2099/2037.Minimum Number of Moves to Seat Everyone/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def minMovesToSeat(self, seats: List[int], students: List[int]) -> int: @@ -101,6 +103,8 @@ class Solution: return sum(abs(a - b) for a, b in zip(seats, students)) ``` +#### Java + ```java class Solution { public int minMovesToSeat(int[] seats, int[] students) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func minMovesToSeat(seats []int, students []int) (ans int) { sort.Ints(seats) @@ -149,6 +157,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function minMovesToSeat(seats: number[], students: number[]): number { seats.sort((a, b) => a - b); @@ -162,6 +172,8 @@ function minMovesToSeat(seats: number[], students: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_moves_to_seat(mut seats: Vec, mut students: Vec) -> i32 { @@ -177,6 +189,8 @@ impl Solution { } ``` +#### C + ```c int cmp(const void* a, const void* b) { return *(int*) a - *(int*) b; diff --git a/solution/2000-2099/2037.Minimum Number of Moves to Seat Everyone/README_EN.md b/solution/2000-2099/2037.Minimum Number of Moves to Seat Everyone/README_EN.md index 8e1211a66fe68..74bc96781cc11 100644 --- a/solution/2000-2099/2037.Minimum Number of Moves to Seat Everyone/README_EN.md +++ b/solution/2000-2099/2037.Minimum Number of Moves to Seat Everyone/README_EN.md @@ -95,6 +95,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def minMovesToSeat(self, seats: List[int], students: List[int]) -> int: @@ -103,6 +105,8 @@ class Solution: return sum(abs(a - b) for a, b in zip(seats, students)) ``` +#### Java + ```java class Solution { public int minMovesToSeat(int[] seats, int[] students) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func minMovesToSeat(seats []int, students []int) (ans int) { sort.Ints(seats) @@ -151,6 +159,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function minMovesToSeat(seats: number[], students: number[]): number { seats.sort((a, b) => a - b); @@ -164,6 +174,8 @@ function minMovesToSeat(seats: number[], students: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_moves_to_seat(mut seats: Vec, mut students: Vec) -> i32 { @@ -179,6 +191,8 @@ impl Solution { } ``` +#### C + ```c int cmp(const void* a, const void* b) { return *(int*) a - *(int*) b; diff --git a/solution/2000-2099/2038.Remove Colored Pieces if Both Neighbors are the Same Color/README.md b/solution/2000-2099/2038.Remove Colored Pieces if Both Neighbors are the Same Color/README.md index b2e2f55b847b1..bddbc6a5ecf6a 100644 --- a/solution/2000-2099/2038.Remove Colored Pieces if Both Neighbors are the Same Color/README.md +++ b/solution/2000-2099/2038.Remove Colored Pieces if Both Neighbors are the Same Color/README.md @@ -102,6 +102,8 @@ ABBBBBBBAA -> ABBBBBBAA +#### Python3 + ```python class Solution: def winnerOfGame(self, colors: str) -> bool: @@ -115,6 +117,8 @@ class Solution: return a > b ``` +#### Java + ```java class Solution { public boolean winnerOfGame(String colors) { @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func winnerOfGame(colors string) bool { n := len(colors) @@ -183,6 +191,8 @@ func winnerOfGame(colors string) bool { } ``` +#### TypeScript + ```ts function winnerOfGame(colors: string): boolean { const n = colors.length; diff --git a/solution/2000-2099/2038.Remove Colored Pieces if Both Neighbors are the Same Color/README_EN.md b/solution/2000-2099/2038.Remove Colored Pieces if Both Neighbors are the Same Color/README_EN.md index 4471d0844292b..5d328f1a0edbb 100644 --- a/solution/2000-2099/2038.Remove Colored Pieces if Both Neighbors are the Same Color/README_EN.md +++ b/solution/2000-2099/2038.Remove Colored Pieces if Both Neighbors are the Same Color/README_EN.md @@ -103,6 +103,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string `colors`. T +#### Python3 + ```python class Solution: def winnerOfGame(self, colors: str) -> bool: @@ -116,6 +118,8 @@ class Solution: return a > b ``` +#### Java + ```java class Solution { public boolean winnerOfGame(String colors) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func winnerOfGame(colors string) bool { n := len(colors) @@ -184,6 +192,8 @@ func winnerOfGame(colors string) bool { } ``` +#### TypeScript + ```ts function winnerOfGame(colors: string): boolean { const n = colors.length; diff --git a/solution/2000-2099/2039.The Time When the Network Becomes Idle/README.md b/solution/2000-2099/2039.The Time When the Network Becomes Idle/README.md index 7a1cec4346920..f7068d2f366eb 100644 --- a/solution/2000-2099/2039.The Time When the Network Becomes Idle/README.md +++ b/solution/2000-2099/2039.The Time When the Network Becomes Idle/README.md @@ -112,6 +112,8 @@ tags: +#### Python3 + ```python class Solution: def networkBecomesIdle(self, edges: List[List[int]], patience: List[int]) -> int: @@ -135,6 +137,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int networkBecomesIdle(int[][] edges, int[] patience) { @@ -170,6 +174,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -206,6 +212,8 @@ public: }; ``` +#### Go + ```go func networkBecomesIdle(edges [][]int, patience []int) (ans int) { n := len(patience) @@ -236,6 +244,8 @@ func networkBecomesIdle(edges [][]int, patience []int) (ans int) { } ``` +#### TypeScript + ```ts function networkBecomesIdle(edges: number[][], patience: number[]): number { const n = patience.length; diff --git a/solution/2000-2099/2039.The Time When the Network Becomes Idle/README_EN.md b/solution/2000-2099/2039.The Time When the Network Becomes Idle/README_EN.md index c696288966cff..2640ca15ac0eb 100644 --- a/solution/2000-2099/2039.The Time When the Network Becomes Idle/README_EN.md +++ b/solution/2000-2099/2039.The Time When the Network Becomes Idle/README_EN.md @@ -111,6 +111,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def networkBecomesIdle(self, edges: List[List[int]], patience: List[int]) -> int: @@ -134,6 +136,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int networkBecomesIdle(int[][] edges, int[] patience) { @@ -169,6 +173,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -205,6 +211,8 @@ public: }; ``` +#### Go + ```go func networkBecomesIdle(edges [][]int, patience []int) (ans int) { n := len(patience) @@ -235,6 +243,8 @@ func networkBecomesIdle(edges [][]int, patience []int) (ans int) { } ``` +#### TypeScript + ```ts function networkBecomesIdle(edges: number[][], patience: number[]): number { const n = patience.length; diff --git a/solution/2000-2099/2040.Kth Smallest Product of Two Sorted Arrays/README.md b/solution/2000-2099/2040.Kth Smallest Product of Two Sorted Arrays/README.md index 6f913112e9e66..e02862bcdbd96 100644 --- a/solution/2000-2099/2040.Kth Smallest Product of Two Sorted Arrays/README.md +++ b/solution/2000-2099/2040.Kth Smallest Product of Two Sorted Arrays/README.md @@ -79,18 +79,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2000-2099/2040.Kth Smallest Product of Two Sorted Arrays/README_EN.md b/solution/2000-2099/2040.Kth Smallest Product of Two Sorted Arrays/README_EN.md index 10ec75fc9aee6..28eff906807e6 100644 --- a/solution/2000-2099/2040.Kth Smallest Product of Two Sorted Arrays/README_EN.md +++ b/solution/2000-2099/2040.Kth Smallest Product of Two Sorted Arrays/README_EN.md @@ -80,18 +80,26 @@ The 3rd smallest product is -6. +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2000-2099/2041.Accepted Candidates From the Interviews/README.md b/solution/2000-2099/2041.Accepted Candidates From the Interviews/README.md index cb09a690c6ef9..9ec911ddc5824 100644 --- a/solution/2000-2099/2041.Accepted Candidates From the Interviews/README.md +++ b/solution/2000-2099/2041.Accepted Candidates From the Interviews/README.md @@ -110,6 +110,8 @@ Rounds table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT candidate_id diff --git a/solution/2000-2099/2041.Accepted Candidates From the Interviews/README_EN.md b/solution/2000-2099/2041.Accepted Candidates From the Interviews/README_EN.md index b3865571c466f..54b99d6654b41 100644 --- a/solution/2000-2099/2041.Accepted Candidates From the Interviews/README_EN.md +++ b/solution/2000-2099/2041.Accepted Candidates From the Interviews/README_EN.md @@ -109,6 +109,8 @@ Rounds table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT candidate_id diff --git a/solution/2000-2099/2042.Check if Numbers Are Ascending in a Sentence/README.md b/solution/2000-2099/2042.Check if Numbers Are Ascending in a Sentence/README.md index 3e7477e7a6f59..9d8f248876abe 100644 --- a/solution/2000-2099/2042.Check if Numbers Are Ascending in a Sentence/README.md +++ b/solution/2000-2099/2042.Check if Numbers Are Ascending in a Sentence/README.md @@ -98,6 +98,8 @@ tags: +#### Python3 + ```python class Solution: def areNumbersAscending(self, s: str) -> bool: @@ -110,6 +112,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean areNumbersAscending(String s) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func areNumbersAscending(s string) bool { pre := 0 @@ -165,6 +173,8 @@ func areNumbersAscending(s string) bool { } ``` +#### TypeScript + ```ts function areNumbersAscending(s: string): boolean { let pre = -1; @@ -181,6 +191,8 @@ function areNumbersAscending(s: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn are_numbers_ascending(s: String) -> bool { @@ -199,6 +211,8 @@ impl Solution { } ``` +#### C + ```c bool areNumbersAscending(char* s) { int pre = -1; @@ -233,6 +247,8 @@ bool areNumbersAscending(char* s) { +#### Python3 + ```python class Solution: def areNumbersAscending(self, s: str) -> bool: diff --git a/solution/2000-2099/2042.Check if Numbers Are Ascending in a Sentence/README_EN.md b/solution/2000-2099/2042.Check if Numbers Are Ascending in a Sentence/README_EN.md index 2bb96ef38179e..968532d42cfea 100644 --- a/solution/2000-2099/2042.Check if Numbers Are Ascending in a Sentence/README_EN.md +++ b/solution/2000-2099/2042.Check if Numbers Are Ascending in a Sentence/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def areNumbersAscending(self, s: str) -> bool: @@ -95,6 +97,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean areNumbersAscending(String s) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func areNumbersAscending(s string) bool { pre := 0 @@ -150,6 +158,8 @@ func areNumbersAscending(s string) bool { } ``` +#### TypeScript + ```ts function areNumbersAscending(s: string): boolean { let pre = -1; @@ -166,6 +176,8 @@ function areNumbersAscending(s: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn are_numbers_ascending(s: String) -> bool { @@ -184,6 +196,8 @@ impl Solution { } ``` +#### C + ```c bool areNumbersAscending(char* s) { int pre = -1; @@ -218,6 +232,8 @@ bool areNumbersAscending(char* s) { +#### Python3 + ```python class Solution: def areNumbersAscending(self, s: str) -> bool: diff --git a/solution/2000-2099/2043.Simple Bank System/README.md b/solution/2000-2099/2043.Simple Bank System/README.md index 80cce48850c60..d71e4e5638c44 100644 --- a/solution/2000-2099/2043.Simple Bank System/README.md +++ b/solution/2000-2099/2043.Simple Bank System/README.md @@ -93,6 +93,8 @@ bank.withdraw(10, 50); // 返回 false ,交易无效,因为账户 10 并 +#### Python3 + ```python class Bank: def __init__(self, balance: List[int]): @@ -126,6 +128,8 @@ class Bank: # param_3 = obj.withdraw(account,money) ``` +#### Java + ```java class Bank { private long[] balance; @@ -171,6 +175,8 @@ class Bank { */ ``` +#### C++ + ```cpp class Bank { public: @@ -211,6 +217,8 @@ public: */ ``` +#### Go + ```go type Bank struct { balance []int64 @@ -255,6 +263,8 @@ func (this *Bank) Withdraw(account int, money int64) bool { */ ``` +#### TypeScript + ```ts class Bank { balance: number[]; @@ -298,6 +308,8 @@ class Bank { */ ``` +#### Rust + ```rust struct Bank { balance: Vec, diff --git a/solution/2000-2099/2043.Simple Bank System/README_EN.md b/solution/2000-2099/2043.Simple Bank System/README_EN.md index 2b2ebf5eb6def..6af2e06b68385 100644 --- a/solution/2000-2099/2043.Simple Bank System/README_EN.md +++ b/solution/2000-2099/2043.Simple Bank System/README_EN.md @@ -91,6 +91,8 @@ The time complexity of the above operations is $O(1)$, and the space complexity +#### Python3 + ```python class Bank: def __init__(self, balance: List[int]): @@ -124,6 +126,8 @@ class Bank: # param_3 = obj.withdraw(account,money) ``` +#### Java + ```java class Bank { private long[] balance; @@ -169,6 +173,8 @@ class Bank { */ ``` +#### C++ + ```cpp class Bank { public: @@ -209,6 +215,8 @@ public: */ ``` +#### Go + ```go type Bank struct { balance []int64 @@ -253,6 +261,8 @@ func (this *Bank) Withdraw(account int, money int64) bool { */ ``` +#### TypeScript + ```ts class Bank { balance: number[]; @@ -296,6 +306,8 @@ class Bank { */ ``` +#### Rust + ```rust struct Bank { balance: Vec, diff --git a/solution/2000-2099/2044.Count Number of Maximum Bitwise-OR Subsets/README.md b/solution/2000-2099/2044.Count Number of Maximum Bitwise-OR Subsets/README.md index 95c2a71fd29df..e2c3dbe051e3e 100644 --- a/solution/2000-2099/2044.Count Number of Maximum Bitwise-OR Subsets/README.md +++ b/solution/2000-2099/2044.Count Number of Maximum Bitwise-OR Subsets/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def countMaxOrSubsets(self, nums: List[int]) -> int: @@ -103,6 +105,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int mx; @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func countMaxOrSubsets(nums []int) int { mx, ans := 0, 0 @@ -183,6 +191,8 @@ func countMaxOrSubsets(nums []int) int { } ``` +#### TypeScript + ```ts function countMaxOrSubsets(nums: number[]): number { let n = nums.length; @@ -204,6 +214,8 @@ function countMaxOrSubsets(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { fn dfs(nums: &Vec, i: usize, sum: i32) -> (i32, i32) { @@ -249,6 +261,8 @@ impl Solution { +#### Python3 + ```python class Solution: def countMaxOrSubsets(self, nums: List[int]) -> int: @@ -268,6 +282,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int mx; @@ -296,6 +312,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -322,6 +340,8 @@ public: }; ``` +#### Go + ```go func countMaxOrSubsets(nums []int) int { n := len(nums) @@ -345,6 +365,8 @@ func countMaxOrSubsets(nums []int) int { } ``` +#### TypeScript + ```ts function countMaxOrSubsets(nums: number[]): number { const n = nums.length; @@ -379,6 +401,8 @@ function countMaxOrSubsets(nums: number[]): number { +#### Python3 + ```python class Solution: def countMaxOrSubsets(self, nums: List[int]) -> int: @@ -398,6 +422,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countMaxOrSubsets(int[] nums) { @@ -423,6 +449,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -448,6 +476,8 @@ public: }; ``` +#### Go + ```go func countMaxOrSubsets(nums []int) int { mx, ans := 0, 0 diff --git a/solution/2000-2099/2044.Count Number of Maximum Bitwise-OR Subsets/README_EN.md b/solution/2000-2099/2044.Count Number of Maximum Bitwise-OR Subsets/README_EN.md index 495858d342342..8f9aa2c0c8fa3 100644 --- a/solution/2000-2099/2044.Count Number of Maximum Bitwise-OR Subsets/README_EN.md +++ b/solution/2000-2099/2044.Count Number of Maximum Bitwise-OR Subsets/README_EN.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def countMaxOrSubsets(self, nums: List[int]) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int mx; @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func countMaxOrSubsets(nums []int) int { mx, ans := 0, 0 @@ -177,6 +185,8 @@ func countMaxOrSubsets(nums []int) int { } ``` +#### TypeScript + ```ts function countMaxOrSubsets(nums: number[]): number { let n = nums.length; @@ -198,6 +208,8 @@ function countMaxOrSubsets(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { fn dfs(nums: &Vec, i: usize, sum: i32) -> (i32, i32) { @@ -241,6 +253,8 @@ impl Solution { +#### Python3 + ```python class Solution: def countMaxOrSubsets(self, nums: List[int]) -> int: @@ -260,6 +274,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int mx; @@ -288,6 +304,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -314,6 +332,8 @@ public: }; ``` +#### Go + ```go func countMaxOrSubsets(nums []int) int { n := len(nums) @@ -337,6 +357,8 @@ func countMaxOrSubsets(nums []int) int { } ``` +#### TypeScript + ```ts function countMaxOrSubsets(nums: number[]): number { const n = nums.length; @@ -371,6 +393,8 @@ function countMaxOrSubsets(nums: number[]): number { +#### Python3 + ```python class Solution: def countMaxOrSubsets(self, nums: List[int]) -> int: @@ -390,6 +414,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countMaxOrSubsets(int[] nums) { @@ -415,6 +441,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -440,6 +468,8 @@ public: }; ``` +#### Go + ```go func countMaxOrSubsets(nums []int) int { mx, ans := 0, 0 diff --git a/solution/2000-2099/2045.Second Minimum Time to Reach Destination/README.md b/solution/2000-2099/2045.Second Minimum Time to Reach Destination/README.md index 12a00d7e72349..88ad23581119e 100644 --- a/solution/2000-2099/2045.Second Minimum Time to Reach Destination/README.md +++ b/solution/2000-2099/2045.Second Minimum Time to Reach Destination/README.md @@ -102,6 +102,8 @@ tags: +#### Python3 + ```python class Solution: def secondMinimum( @@ -133,6 +135,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int secondMinimum(int n, int[][] edges, int time, int change) { diff --git a/solution/2000-2099/2045.Second Minimum Time to Reach Destination/README_EN.md b/solution/2000-2099/2045.Second Minimum Time to Reach Destination/README_EN.md index 684cf97e330a2..76090aa6faddc 100644 --- a/solution/2000-2099/2045.Second Minimum Time to Reach Destination/README_EN.md +++ b/solution/2000-2099/2045.Second Minimum Time to Reach Destination/README_EN.md @@ -97,6 +97,8 @@ The second minimum time path is 1 -> 2 -> 1 -> 2 with time = 11 minutes +#### Python3 + ```python class Solution: def secondMinimum( @@ -128,6 +130,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int secondMinimum(int n, int[][] edges, int time, int change) { diff --git a/solution/2000-2099/2046.Sort Linked List Already Sorted Using Absolute Values/README.md b/solution/2000-2099/2046.Sort Linked List Already Sorted Using Absolute Values/README.md index 116d8c6e0b5d9..35f568b1f0cd7 100644 --- a/solution/2000-2099/2046.Sort Linked List Already Sorted Using Absolute Values/README.md +++ b/solution/2000-2099/2046.Sort Linked List Already Sorted Using Absolute Values/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -99,6 +101,8 @@ class Solution: return head ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -188,6 +196,8 @@ func sortLinkedList(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/2000-2099/2046.Sort Linked List Already Sorted Using Absolute Values/README_EN.md b/solution/2000-2099/2046.Sort Linked List Already Sorted Using Absolute Values/README_EN.md index 5501d458beecd..6461587049b5a 100644 --- a/solution/2000-2099/2046.Sort Linked List Already Sorted Using Absolute Values/README_EN.md +++ b/solution/2000-2099/2046.Sort Linked List Already Sorted Using Absolute Values/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n)$, where $n$ is the length of the linked list. The s +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -99,6 +101,8 @@ class Solution: return head ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -188,6 +196,8 @@ func sortLinkedList(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/2000-2099/2047.Number of Valid Words in a Sentence/README.md b/solution/2000-2099/2047.Number of Valid Words in a Sentence/README.md index 1fd458ed33168..e1dd7c62b333f 100644 --- a/solution/2000-2099/2047.Number of Valid Words in a Sentence/README.md +++ b/solution/2000-2099/2047.Number of Valid Words in a Sentence/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def countValidWords(self, sentence: str) -> int: @@ -104,6 +106,8 @@ class Solution: return sum(check(token) for token in sentence.split()) ``` +#### Java + ```java class Solution { public int countValidWords(String sentence) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### TypeScript + ```ts function countValidWords(sentence: string): number { let words = sentence.trim().split(/\s+/); diff --git a/solution/2000-2099/2047.Number of Valid Words in a Sentence/README_EN.md b/solution/2000-2099/2047.Number of Valid Words in a Sentence/README_EN.md index 9985c5474b460..81fc9791d496a 100644 --- a/solution/2000-2099/2047.Number of Valid Words in a Sentence/README_EN.md +++ b/solution/2000-2099/2047.Number of Valid Words in a Sentence/README_EN.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def countValidWords(self, sentence: str) -> int: @@ -102,6 +104,8 @@ class Solution: return sum(check(token) for token in sentence.split()) ``` +#### Java + ```java class Solution { public int countValidWords(String sentence) { @@ -138,6 +142,8 @@ class Solution { } ``` +#### TypeScript + ```ts function countValidWords(sentence: string): number { let words = sentence.trim().split(/\s+/); diff --git a/solution/2000-2099/2048.Next Greater Numerically Balanced Number/README.md b/solution/2000-2099/2048.Next Greater Numerically Balanced Number/README.md index feb65ca780b07..972fcc5a01044 100644 --- a/solution/2000-2099/2048.Next Greater Numerically Balanced Number/README.md +++ b/solution/2000-2099/2048.Next Greater Numerically Balanced Number/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def nextBeautifulNumber(self, n: int) -> int: @@ -96,6 +98,8 @@ class Solution: return x ``` +#### Java + ```java class Solution { public int nextBeautifulNumber(int n) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func nextBeautifulNumber(n int) int { for x := n + 1; ; x++ { @@ -164,6 +172,8 @@ func nextBeautifulNumber(n int) int { } ``` +#### TypeScript + ```ts function nextBeautifulNumber(n: number): number { for (let x = n + 1; ; ++x) { diff --git a/solution/2000-2099/2048.Next Greater Numerically Balanced Number/README_EN.md b/solution/2000-2099/2048.Next Greater Numerically Balanced Number/README_EN.md index 457e100dc9cae..9f71d7418956d 100644 --- a/solution/2000-2099/2048.Next Greater Numerically Balanced Number/README_EN.md +++ b/solution/2000-2099/2048.Next Greater Numerically Balanced Number/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(M - n)$, where $M = 1224444$. The space complexity is +#### Python3 + ```python class Solution: def nextBeautifulNumber(self, n: int) -> int: @@ -95,6 +97,8 @@ class Solution: return x ``` +#### Java + ```java class Solution { public int nextBeautifulNumber(int n) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func nextBeautifulNumber(n int) int { for x := n + 1; ; x++ { @@ -163,6 +171,8 @@ func nextBeautifulNumber(n int) int { } ``` +#### TypeScript + ```ts function nextBeautifulNumber(n: number): number { for (let x = n + 1; ; ++x) { diff --git a/solution/2000-2099/2049.Count Nodes With the Highest Score/README.md b/solution/2000-2099/2049.Count Nodes With the Highest Score/README.md index 18f6ddd287e95..e8fc4b9a61da4 100644 --- a/solution/2000-2099/2049.Count Nodes With the Highest Score/README.md +++ b/solution/2000-2099/2049.Count Nodes With the Highest Score/README.md @@ -99,6 +99,8 @@ tags: +#### Python3 + ```python class Solution: def countHighestScoreNodes(self, parents: List[int]) -> int: @@ -128,6 +130,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -170,6 +174,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -208,6 +214,8 @@ public: }; ``` +#### Go + ```go func countHighestScoreNodes(parents []int) (ans int) { n := len(parents) @@ -242,6 +250,8 @@ func countHighestScoreNodes(parents []int) (ans int) { } ``` +#### TypeScript + ```ts function countHighestScoreNodes(parents: number[]): number { const n = parents.length; @@ -275,6 +285,8 @@ function countHighestScoreNodes(parents: number[]): number { } ``` +#### C# + ```cs public class Solution { private List[] g; diff --git a/solution/2000-2099/2049.Count Nodes With the Highest Score/README_EN.md b/solution/2000-2099/2049.Count Nodes With the Highest Score/README_EN.md index 3c8d33969c31b..c7836d39edcbe 100644 --- a/solution/2000-2099/2049.Count Nodes With the Highest Score/README_EN.md +++ b/solution/2000-2099/2049.Count Nodes With the Highest Score/README_EN.md @@ -95,6 +95,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def countHighestScoreNodes(self, parents: List[int]) -> int: @@ -124,6 +126,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -166,6 +170,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -204,6 +210,8 @@ public: }; ``` +#### Go + ```go func countHighestScoreNodes(parents []int) (ans int) { n := len(parents) @@ -238,6 +246,8 @@ func countHighestScoreNodes(parents []int) (ans int) { } ``` +#### TypeScript + ```ts function countHighestScoreNodes(parents: number[]): number { const n = parents.length; @@ -271,6 +281,8 @@ function countHighestScoreNodes(parents: number[]): number { } ``` +#### C# + ```cs public class Solution { private List[] g; diff --git a/solution/2000-2099/2050.Parallel Courses III/README.md b/solution/2000-2099/2050.Parallel Courses III/README.md index 1dbc3a89631ba..bc19d7a057956 100644 --- a/solution/2000-2099/2050.Parallel Courses III/README.md +++ b/solution/2000-2099/2050.Parallel Courses III/README.md @@ -103,6 +103,8 @@ tags: +#### Python3 + ```python class Solution: def minimumTime(self, n: int, relations: List[List[int]], time: List[int]) -> int: @@ -130,6 +132,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumTime(int n, int[][] relations, int[] time) { @@ -167,6 +171,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -205,6 +211,8 @@ public: }; ``` +#### Go + ```go func minimumTime(n int, relations [][]int, time []int) int { g := make([][]int, n) @@ -240,6 +248,8 @@ func minimumTime(n int, relations [][]int, time []int) int { } ``` +#### TypeScript + ```ts function minimumTime(n: number, relations: number[][], time: number[]): number { const g: number[][] = Array(n) diff --git a/solution/2000-2099/2050.Parallel Courses III/README_EN.md b/solution/2000-2099/2050.Parallel Courses III/README_EN.md index e1ca2c674d72d..cdd902908ee07 100644 --- a/solution/2000-2099/2050.Parallel Courses III/README_EN.md +++ b/solution/2000-2099/2050.Parallel Courses III/README_EN.md @@ -101,6 +101,8 @@ The time complexity is $O(m + n)$, and the space complexity is $O(m + n)$. Where +#### Python3 + ```python class Solution: def minimumTime(self, n: int, relations: List[List[int]], time: List[int]) -> int: @@ -128,6 +130,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumTime(int n, int[][] relations, int[] time) { @@ -165,6 +169,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -203,6 +209,8 @@ public: }; ``` +#### Go + ```go func minimumTime(n int, relations [][]int, time []int) int { g := make([][]int, n) @@ -238,6 +246,8 @@ func minimumTime(n int, relations [][]int, time []int) int { } ``` +#### TypeScript + ```ts function minimumTime(n: number, relations: number[][], time: number[]): number { const g: number[][] = Array(n) diff --git a/solution/2000-2099/2051.The Category of Each Member in the Store/README.md b/solution/2000-2099/2051.The Category of Each Member in the Store/README.md index 863899b1fc8e3..7518bd7b3b07d 100644 --- a/solution/2000-2099/2051.The Category of Each Member in the Store/README.md +++ b/solution/2000-2099/2051.The Category of Each Member in the Store/README.md @@ -144,6 +144,8 @@ Purchases 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2000-2099/2051.The Category of Each Member in the Store/README_EN.md b/solution/2000-2099/2051.The Category of Each Member in the Store/README_EN.md index f23c393407006..d95a4ec7ce0d4 100644 --- a/solution/2000-2099/2051.The Category of Each Member in the Store/README_EN.md +++ b/solution/2000-2099/2051.The Category of Each Member in the Store/README_EN.md @@ -144,6 +144,8 @@ Purchases table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2000-2099/2052.Minimum Cost to Separate Sentence Into Rows/README.md b/solution/2000-2099/2052.Minimum Cost to Separate Sentence Into Rows/README.md index 40604fa003e16..769aa01176013 100644 --- a/solution/2000-2099/2052.Minimum Cost to Separate Sentence Into Rows/README.md +++ b/solution/2000-2099/2052.Minimum Cost to Separate Sentence Into Rows/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def minimumCost(self, sentence: str, k: int) -> int: @@ -111,6 +113,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private static final int INF = Integer.MAX_VALUE; @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go func minimumCost(sentence string, k int) int { words := strings.Split(sentence, " ") diff --git a/solution/2000-2099/2052.Minimum Cost to Separate Sentence Into Rows/README_EN.md b/solution/2000-2099/2052.Minimum Cost to Separate Sentence Into Rows/README_EN.md index 88b77c581f87d..d08bc2c2c6035 100644 --- a/solution/2000-2099/2052.Minimum Cost to Separate Sentence Into Rows/README_EN.md +++ b/solution/2000-2099/2052.Minimum Cost to Separate Sentence Into Rows/README_EN.md @@ -91,6 +91,8 @@ The cost of the last row is not included in the total cost, and since there is o +#### Python3 + ```python class Solution: def minimumCost(self, sentence: str, k: int) -> int: @@ -110,6 +112,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private static final int INF = Integer.MAX_VALUE; @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -185,6 +191,8 @@ public: }; ``` +#### Go + ```go func minimumCost(sentence string, k int) int { words := strings.Split(sentence, " ") diff --git a/solution/2000-2099/2053.Kth Distinct String in an Array/README.md b/solution/2000-2099/2053.Kth Distinct String in an Array/README.md index 3073b5bbc8398..4c1ed23414feb 100644 --- a/solution/2000-2099/2053.Kth Distinct String in an Array/README.md +++ b/solution/2000-2099/2053.Kth Distinct String in an Array/README.md @@ -76,6 +76,8 @@ arr 中所有字符串都是独一无二的,所以返回第 1 个字符串 "aa +#### Python3 + ```python class Solution: def kthDistinct(self, arr: List[str], k: int) -> str: @@ -88,6 +90,8 @@ class Solution: return '' ``` +#### Java + ```java class Solution { public String kthDistinct(String[] arr, int k) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func kthDistinct(arr []string, k int) string { counter := make(map[string]int) diff --git a/solution/2000-2099/2053.Kth Distinct String in an Array/README_EN.md b/solution/2000-2099/2053.Kth Distinct String in an Array/README_EN.md index 9e63ba20b88aa..ed9fe534b1c1a 100644 --- a/solution/2000-2099/2053.Kth Distinct String in an Array/README_EN.md +++ b/solution/2000-2099/2053.Kth Distinct String in an Array/README_EN.md @@ -77,6 +77,8 @@ The only distinct string is "b". Since there are fewer than 3 distinct +#### Python3 + ```python class Solution: def kthDistinct(self, arr: List[str], k: int) -> str: @@ -89,6 +91,8 @@ class Solution: return '' ``` +#### Java + ```java class Solution { public String kthDistinct(String[] arr, int k) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func kthDistinct(arr []string, k int) string { counter := make(map[string]int) diff --git a/solution/2000-2099/2054.Two Best Non-Overlapping Events/README.md b/solution/2000-2099/2054.Two Best Non-Overlapping Events/README.md index 385a5356d31d1..b6bf5fbdce5cb 100644 --- a/solution/2000-2099/2054.Two Best Non-Overlapping Events/README.md +++ b/solution/2000-2099/2054.Two Best Non-Overlapping Events/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def maxTwoEvents(self, events: List[List[int]]) -> int: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxTwoEvents(int[][] events) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func maxTwoEvents(events [][]int) int { sort.Slice(events, func(i, j int) bool { diff --git a/solution/2000-2099/2054.Two Best Non-Overlapping Events/README_EN.md b/solution/2000-2099/2054.Two Best Non-Overlapping Events/README_EN.md index 09de68a42b95c..ae8de3ba6d653 100644 --- a/solution/2000-2099/2054.Two Best Non-Overlapping Events/README_EN.md +++ b/solution/2000-2099/2054.Two Best Non-Overlapping Events/README_EN.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def maxTwoEvents(self, events: List[List[int]]) -> int: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxTwoEvents(int[][] events) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func maxTwoEvents(events [][]int) int { sort.Slice(events, func(i, j int) bool { diff --git a/solution/2000-2099/2055.Plates Between Candles/README.md b/solution/2000-2099/2055.Plates Between Candles/README.md index 8ca4412ef3ae6..05bd78fe5d6d5 100644 --- a/solution/2000-2099/2055.Plates Between Candles/README.md +++ b/solution/2000-2099/2055.Plates Between Candles/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def platesBetweenCandles(self, s: str, queries: List[List[int]]) -> List[int]: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] platesBetweenCandles(String s, int[][] queries) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func platesBetweenCandles(s string, queries [][]int) []int { n := len(s) diff --git a/solution/2000-2099/2055.Plates Between Candles/README_EN.md b/solution/2000-2099/2055.Plates Between Candles/README_EN.md index 27a829b1ab42b..18d99fba005bd 100644 --- a/solution/2000-2099/2055.Plates Between Candles/README_EN.md +++ b/solution/2000-2099/2055.Plates Between Candles/README_EN.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def platesBetweenCandles(self, s: str, queries: List[List[int]]) -> List[int]: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] platesBetweenCandles(String s, int[][] queries) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func platesBetweenCandles(s string, queries [][]int) []int { n := len(s) diff --git a/solution/2000-2099/2056.Number of Valid Move Combinations On Chessboard/README.md b/solution/2000-2099/2056.Number of Valid Move Combinations On Chessboard/README.md index 6e432cc621608..91fea0d7ece99 100644 --- a/solution/2000-2099/2056.Number of Valid Move Combinations On Chessboard/README.md +++ b/solution/2000-2099/2056.Number of Valid Move Combinations On Chessboard/README.md @@ -130,18 +130,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2000-2099/2056.Number of Valid Move Combinations On Chessboard/README_EN.md b/solution/2000-2099/2056.Number of Valid Move Combinations On Chessboard/README_EN.md index cea4f93ff2d86..c1e915b7abecf 100644 --- a/solution/2000-2099/2056.Number of Valid Move Combinations On Chessboard/README_EN.md +++ b/solution/2000-2099/2056.Number of Valid Move Combinations On Chessboard/README_EN.md @@ -91,18 +91,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2000-2099/2057.Smallest Index With Equal Value/README.md b/solution/2000-2099/2057.Smallest Index With Equal Value/README.md index 42e2c94b724b9..2387346f8734c 100644 --- a/solution/2000-2099/2057.Smallest Index With Equal Value/README.md +++ b/solution/2000-2099/2057.Smallest Index With Equal Value/README.md @@ -80,6 +80,8 @@ i=3: 3 mod 10 = 3 != nums[3]. +#### Python3 + ```python class Solution: def smallestEqual(self, nums: List[int]) -> int: @@ -89,6 +91,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int smallestEqual(int[] nums) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func smallestEqual(nums []int) int { for i, v := range nums { @@ -125,6 +133,8 @@ func smallestEqual(nums []int) int { } ``` +#### TypeScript + ```ts function smallestEqual(nums: number[]): number { for (let i = 0; i < nums.length; i++) { diff --git a/solution/2000-2099/2057.Smallest Index With Equal Value/README_EN.md b/solution/2000-2099/2057.Smallest Index With Equal Value/README_EN.md index bf33572f57982..c4179432ef8da 100644 --- a/solution/2000-2099/2057.Smallest Index With Equal Value/README_EN.md +++ b/solution/2000-2099/2057.Smallest Index With Equal Value/README_EN.md @@ -74,6 +74,8 @@ i=3: 3 mod 10 = 3 != nums[3]. +#### Python3 + ```python class Solution: def smallestEqual(self, nums: List[int]) -> int: @@ -83,6 +85,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int smallestEqual(int[] nums) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func smallestEqual(nums []int) int { for i, v := range nums { @@ -119,6 +127,8 @@ func smallestEqual(nums []int) int { } ``` +#### TypeScript + ```ts function smallestEqual(nums: number[]): number { for (let i = 0; i < nums.length; i++) { diff --git a/solution/2000-2099/2058.Find the Minimum and Maximum Number of Nodes Between Critical Points/README.md b/solution/2000-2099/2058.Find the Minimum and Maximum Number of Nodes Between Critical Points/README.md index 587e8d41282b2..88e778e46bb73 100644 --- a/solution/2000-2099/2058.Find the Minimum and Maximum Number of Nodes Between Critical Points/README.md +++ b/solution/2000-2099/2058.Find the Minimum and Maximum Number of Nodes Between Critical Points/README.md @@ -99,6 +99,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -126,6 +128,8 @@ class Solution: return ans if first != last else [-1, -1] ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -166,6 +170,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -205,6 +211,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -238,6 +246,8 @@ func nodesBetweenCriticalPoints(head *ListNode) []int { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/2000-2099/2058.Find the Minimum and Maximum Number of Nodes Between Critical Points/README_EN.md b/solution/2000-2099/2058.Find the Minimum and Maximum Number of Nodes Between Critical Points/README_EN.md index 30356a9213a48..c5dab213e4d63 100644 --- a/solution/2000-2099/2058.Find the Minimum and Maximum Number of Nodes Between Critical Points/README_EN.md +++ b/solution/2000-2099/2058.Find the Minimum and Maximum Number of Nodes Between Critical Points/README_EN.md @@ -81,6 +81,8 @@ Note that the last node is not considered a local maxima because it does not hav +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -108,6 +110,8 @@ class Solution: return ans if first != last else [-1, -1] ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -187,6 +193,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -220,6 +228,8 @@ func nodesBetweenCriticalPoints(head *ListNode) []int { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/2000-2099/2059.Minimum Operations to Convert Number/README.md b/solution/2000-2099/2059.Minimum Operations to Convert Number/README.md index d77ba0030ffff..a39886c789fc4 100644 --- a/solution/2000-2099/2059.Minimum Operations to Convert Number/README.md +++ b/solution/2000-2099/2059.Minimum Operations to Convert Number/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def minimumOperations(self, nums: List[int], start: int, goal: int) -> int: @@ -112,6 +114,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minimumOperations(int[] nums, int start, int goal) { @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go func minimumOperations(nums []int, start int, goal int) int { type pair struct { @@ -212,6 +220,8 @@ func minimumOperations(nums []int, start int, goal int) int { } ``` +#### TypeScript + ```ts function minimumOperations(nums: number[], start: number, goal: number): number { const n = nums.length; @@ -257,6 +267,8 @@ function minimumOperations(nums: number[], start: number, goal: number): number +#### Python3 + ```python class Solution: def minimumOperations(self, nums: List[int], start: int, goal: int) -> int: @@ -284,6 +296,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minimumOperations(int[] nums, int start, int goal) { @@ -321,6 +335,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -357,6 +373,8 @@ public: }; ``` +#### Go + ```go func minimumOperations(nums []int, start int, goal int) int { next := func(x int) []int { @@ -399,6 +417,8 @@ func minimumOperations(nums []int, start int, goal int) int { +#### Python3 + ```python class Solution: def minimumOperations(self, nums: List[int], start: int, goal: int) -> int: @@ -433,6 +453,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { private int[] nums; @@ -488,6 +510,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -534,6 +558,8 @@ public: }; ``` +#### Go + ```go func minimumOperations(nums []int, start int, goal int) int { next := func(x int) []int { diff --git a/solution/2000-2099/2059.Minimum Operations to Convert Number/README_EN.md b/solution/2000-2099/2059.Minimum Operations to Convert Number/README_EN.md index 32daea415ca13..b3afdf1ffaa77 100644 --- a/solution/2000-2099/2059.Minimum Operations to Convert Number/README_EN.md +++ b/solution/2000-2099/2059.Minimum Operations to Convert Number/README_EN.md @@ -84,6 +84,8 @@ Note that the last operation sets x out of the range 0 <= x <= 1000, which +#### Python3 + ```python class Solution: def minimumOperations(self, nums: List[int], start: int, goal: int) -> int: @@ -106,6 +108,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minimumOperations(int[] nums, int start, int goal) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func minimumOperations(nums []int, start int, goal int) int { type pair struct { @@ -206,6 +214,8 @@ func minimumOperations(nums []int, start int, goal int) int { } ``` +#### TypeScript + ```ts function minimumOperations(nums: number[], start: number, goal: number): number { const n = nums.length; @@ -251,6 +261,8 @@ function minimumOperations(nums: number[], start: number, goal: number): number +#### Python3 + ```python class Solution: def minimumOperations(self, nums: List[int], start: int, goal: int) -> int: @@ -278,6 +290,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minimumOperations(int[] nums, int start, int goal) { @@ -315,6 +329,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -351,6 +367,8 @@ public: }; ``` +#### Go + ```go func minimumOperations(nums []int, start int, goal int) int { next := func(x int) []int { @@ -393,6 +411,8 @@ func minimumOperations(nums []int, start int, goal int) int { +#### Python3 + ```python class Solution: def minimumOperations(self, nums: List[int], start: int, goal: int) -> int: @@ -427,6 +447,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { private int[] nums; @@ -482,6 +504,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -528,6 +552,8 @@ public: }; ``` +#### Go + ```go func minimumOperations(nums []int, start int, goal int) int { next := func(x int) []int { diff --git a/solution/2000-2099/2060.Check if an Original String Exists Given Two Encoded Strings/README.md b/solution/2000-2099/2060.Check if an Original String Exists Given Two Encoded Strings/README.md index eee39cb6acb51..61a6130440f34 100644 --- a/solution/2000-2099/2060.Check if an Original String Exists Given Two Encoded Strings/README.md +++ b/solution/2000-2099/2060.Check if an Original String Exists Given Two Encoded Strings/README.md @@ -124,6 +124,8 @@ tags: +#### TypeScript + ```ts function possiblyEquals(s1: string, s2: string): boolean { const n = s1.length, diff --git a/solution/2000-2099/2060.Check if an Original String Exists Given Two Encoded Strings/README_EN.md b/solution/2000-2099/2060.Check if an Original String Exists Given Two Encoded Strings/README_EN.md index 098eaef0f428b..6c2b0f4997c84 100644 --- a/solution/2000-2099/2060.Check if an Original String Exists Given Two Encoded Strings/README_EN.md +++ b/solution/2000-2099/2060.Check if an Original String Exists Given Two Encoded Strings/README_EN.md @@ -101,6 +101,8 @@ tags: +#### TypeScript + ```ts function possiblyEquals(s1: string, s2: string): boolean { const n = s1.length, diff --git a/solution/2000-2099/2061.Number of Spaces Cleaning Robot Cleaned/README.md b/solution/2000-2099/2061.Number of Spaces Cleaning Robot Cleaned/README.md index adbd21fba682a..98a2ef0670aa1 100644 --- a/solution/2000-2099/2061.Number of Spaces Cleaning Robot Cleaned/README.md +++ b/solution/2000-2099/2061.Number of Spaces Cleaning Robot Cleaned/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfCleanRooms(self, room: List[List[int]]) -> int: @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private boolean[][][] vis; @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func numberOfCleanRooms(room [][]int) (ans int) { m, n := len(room), len(room[0]) @@ -208,6 +216,8 @@ func numberOfCleanRooms(room [][]int) (ans int) { +#### Python3 + ```python class Solution: def numberOfCleanRooms(self, room: List[List[int]]) -> int: @@ -227,6 +237,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numberOfCleanRooms(int[][] room) { @@ -252,6 +264,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -279,6 +293,8 @@ public: }; ``` +#### Go + ```go func numberOfCleanRooms(room [][]int) (ans int) { m, n := len(room), len(room[0]) diff --git a/solution/2000-2099/2061.Number of Spaces Cleaning Robot Cleaned/README_EN.md b/solution/2000-2099/2061.Number of Spaces Cleaning Robot Cleaned/README_EN.md index 503d240efe4d1..83a65b22467fb 100644 --- a/solution/2000-2099/2061.Number of Spaces Cleaning Robot Cleaned/README_EN.md +++ b/solution/2000-2099/2061.Number of Spaces Cleaning Robot Cleaned/README_EN.md @@ -77,6 +77,8 @@ The robot has cleaned 1 space, so return 1. +#### Python3 + ```python class Solution: def numberOfCleanRooms(self, room: List[List[int]]) -> int: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private boolean[][][] vis; @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func numberOfCleanRooms(room [][]int) (ans int) { m, n := len(room), len(room[0]) @@ -200,6 +208,8 @@ func numberOfCleanRooms(room [][]int) (ans int) { +#### Python3 + ```python class Solution: def numberOfCleanRooms(self, room: List[List[int]]) -> int: @@ -219,6 +229,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numberOfCleanRooms(int[][] room) { @@ -244,6 +256,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -271,6 +285,8 @@ public: }; ``` +#### Go + ```go func numberOfCleanRooms(room [][]int) (ans int) { m, n := len(room), len(room[0]) diff --git a/solution/2000-2099/2062.Count Vowel Substrings of a String/README.md b/solution/2000-2099/2062.Count Vowel Substrings of a String/README.md index 245085e392303..5239fdba01444 100644 --- a/solution/2000-2099/2062.Count Vowel Substrings of a String/README.md +++ b/solution/2000-2099/2062.Count Vowel Substrings of a String/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def countVowelSubstrings(self, word: str) -> int: @@ -98,6 +100,8 @@ class Solution: return sum(set(word[i:j]) == s for i in range(n) for j in range(i + 1, n + 1)) ``` +#### Java + ```java class Solution { public int countVowelSubstrings(String word) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func countVowelSubstrings(word string) int { ans, n := 0, len(word) @@ -169,6 +177,8 @@ func countVowelSubstrings(word string) int { } ``` +#### TypeScript + ```ts function countVowelSubstrings(word: string): number { let ans = 0; @@ -200,6 +210,8 @@ function countVowelSubstrings(word: string): number { +#### Python3 + ```python class Solution: def countVowelSubstrings(self, word: str) -> int: diff --git a/solution/2000-2099/2062.Count Vowel Substrings of a String/README_EN.md b/solution/2000-2099/2062.Count Vowel Substrings of a String/README_EN.md index 592d735a0f44c..03631871aa52a 100644 --- a/solution/2000-2099/2062.Count Vowel Substrings of a String/README_EN.md +++ b/solution/2000-2099/2062.Count Vowel Substrings of a String/README_EN.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def countVowelSubstrings(self, word: str) -> int: @@ -85,6 +87,8 @@ class Solution: return sum(set(word[i:j]) == s for i in range(n) for j in range(i + 1, n + 1)) ``` +#### Java + ```java class Solution { public int countVowelSubstrings(String word) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func countVowelSubstrings(word string) int { ans, n := 0, len(word) @@ -156,6 +164,8 @@ func countVowelSubstrings(word string) int { } ``` +#### TypeScript + ```ts function countVowelSubstrings(word: string): number { let ans = 0; @@ -187,6 +197,8 @@ function countVowelSubstrings(word: string): number { +#### Python3 + ```python class Solution: def countVowelSubstrings(self, word: str) -> int: diff --git a/solution/2000-2099/2063.Vowels of All Substrings/README.md b/solution/2000-2099/2063.Vowels of All Substrings/README.md index 0f3b7a0a32ba3..2653b85def8e6 100644 --- a/solution/2000-2099/2063.Vowels of All Substrings/README.md +++ b/solution/2000-2099/2063.Vowels of All Substrings/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def countVowels(self, word: str) -> int: @@ -98,6 +100,8 @@ class Solution: return sum((i + 1) * (n - i) for i, c in enumerate(word) if c in 'aeiou') ``` +#### Java + ```java class Solution { public long countVowels(String word) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func countVowels(word string) (ans int64) { for i, c := range word { @@ -140,6 +148,8 @@ func countVowels(word string) (ans int64) { } ``` +#### TypeScript + ```ts function countVowels(word: string): number { const n = word.length; diff --git a/solution/2000-2099/2063.Vowels of All Substrings/README_EN.md b/solution/2000-2099/2063.Vowels of All Substrings/README_EN.md index 8eaaa89d6a280..f7c07bc373390 100644 --- a/solution/2000-2099/2063.Vowels of All Substrings/README_EN.md +++ b/solution/2000-2099/2063.Vowels of All Substrings/README_EN.md @@ -79,6 +79,8 @@ Hence, the total sum of vowels = 1 + 1 + 1 + 0 + 0 + 0 = 3. +#### Python3 + ```python class Solution: def countVowels(self, word: str) -> int: @@ -86,6 +88,8 @@ class Solution: return sum((i + 1) * (n - i) for i, c in enumerate(word) if c in 'aeiou') ``` +#### Java + ```java class Solution { public long countVowels(String word) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func countVowels(word string) (ans int64) { for i, c := range word { @@ -128,6 +136,8 @@ func countVowels(word string) (ans int64) { } ``` +#### TypeScript + ```ts function countVowels(word: string): number { const n = word.length; diff --git a/solution/2000-2099/2064.Minimized Maximum of Products Distributed to Any Store/README.md b/solution/2000-2099/2064.Minimized Maximum of Products Distributed to Any Store/README.md index 91550e9e85b45..86d39b86ebe63 100644 --- a/solution/2000-2099/2064.Minimized Maximum of Products Distributed to Any Store/README.md +++ b/solution/2000-2099/2064.Minimized Maximum of Products Distributed to Any Store/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def minimizedMaximum(self, n: int, quantities: List[int]) -> int: @@ -102,6 +104,8 @@ class Solution: return 1 + bisect_left(range(1, 10**6), True, key=check) ``` +#### Java + ```java class Solution { public int minimizedMaximum(int n, int[] quantities) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func minimizedMaximum(n int, quantities []int) int { return 1 + sort.Search(1e5, func(x int) bool { @@ -158,6 +166,8 @@ func minimizedMaximum(n int, quantities []int) int { } ``` +#### TypeScript + ```ts function minimizedMaximum(n: number, quantities: number[]): number { let left = 1; diff --git a/solution/2000-2099/2064.Minimized Maximum of Products Distributed to Any Store/README_EN.md b/solution/2000-2099/2064.Minimized Maximum of Products Distributed to Any Store/README_EN.md index 0ce7039e62e0b..b055c4f3665be 100644 --- a/solution/2000-2099/2064.Minimized Maximum of Products Distributed to Any Store/README_EN.md +++ b/solution/2000-2099/2064.Minimized Maximum of Products Distributed to Any Store/README_EN.md @@ -83,6 +83,8 @@ The maximum number of products given to any store is max(100000) = 100000. +#### Python3 + ```python class Solution: def minimizedMaximum(self, n: int, quantities: List[int]) -> int: @@ -92,6 +94,8 @@ class Solution: return 1 + bisect_left(range(1, 10**6), True, key=check) ``` +#### Java + ```java class Solution { public int minimizedMaximum(int n, int[] quantities) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func minimizedMaximum(n int, quantities []int) int { return 1 + sort.Search(1e5, func(x int) bool { @@ -148,6 +156,8 @@ func minimizedMaximum(n int, quantities []int) int { } ``` +#### TypeScript + ```ts function minimizedMaximum(n: number, quantities: number[]): number { let left = 1; diff --git a/solution/2000-2099/2065.Maximum Path Quality of a Graph/README.md b/solution/2000-2099/2065.Maximum Path Quality of a Graph/README.md index 703c673197c9c..21b63ca87a19a 100644 --- a/solution/2000-2099/2065.Maximum Path Quality of a Graph/README.md +++ b/solution/2000-2099/2065.Maximum Path Quality of a Graph/README.md @@ -104,6 +104,8 @@ tags: +#### TypeScript + ```ts function maximalPathQuality(values: number[], edges: number[][], maxTime: number): number { const n = values.length; diff --git a/solution/2000-2099/2065.Maximum Path Quality of a Graph/README_EN.md b/solution/2000-2099/2065.Maximum Path Quality of a Graph/README_EN.md index 20cbce20a40b1..ede563a026d37 100644 --- a/solution/2000-2099/2065.Maximum Path Quality of a Graph/README_EN.md +++ b/solution/2000-2099/2065.Maximum Path Quality of a Graph/README_EN.md @@ -85,6 +85,8 @@ The nodes visited are 0, 1, and 3, giving a maximal path quality of 1 + 2 + 4 = +#### TypeScript + ```ts function maximalPathQuality(values: number[], edges: number[][], maxTime: number): number { const n = values.length; diff --git a/solution/2000-2099/2066.Account Balance/README.md b/solution/2000-2099/2066.Account Balance/README.md index aed4693942dd5..f641e58df1c6d 100644 --- a/solution/2000-2099/2066.Account Balance/README.md +++ b/solution/2000-2099/2066.Account Balance/README.md @@ -89,6 +89,8 @@ Transactions 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2000-2099/2066.Account Balance/README_EN.md b/solution/2000-2099/2066.Account Balance/README_EN.md index f6f2836ca98d3..2fbdfa1977ef5 100644 --- a/solution/2000-2099/2066.Account Balance/README_EN.md +++ b/solution/2000-2099/2066.Account Balance/README_EN.md @@ -87,6 +87,8 @@ Account 2: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2000-2099/2067.Number of Equal Count Substrings/README.md b/solution/2000-2099/2067.Number of Equal Count Substrings/README.md index b90ad7804246b..6e645f6e5a575 100644 --- a/solution/2000-2099/2067.Number of Equal Count Substrings/README.md +++ b/solution/2000-2099/2067.Number of Equal Count Substrings/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def equalCountSubstrings(self, s: str, count: int) -> int: @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int equalCountSubstrings(String s, int count) { @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func equalCountSubstrings(s string, count int) (ans int) { n := len(s) @@ -197,6 +205,8 @@ func equalCountSubstrings(s string, count int) (ans int) { } ``` +#### TypeScript + ```ts function equalCountSubstrings(s: string, count: number): number { const n = s.length; @@ -221,6 +231,8 @@ function equalCountSubstrings(s: string, count: number): number { } ``` +#### JavaScript + ```js /** * @param {string} s diff --git a/solution/2000-2099/2067.Number of Equal Count Substrings/README_EN.md b/solution/2000-2099/2067.Number of Equal Count Substrings/README_EN.md index 93d6f4ffc604d..2abb7b46e1175 100644 --- a/solution/2000-2099/2067.Number of Equal Count Substrings/README_EN.md +++ b/solution/2000-2099/2067.Number of Equal Count Substrings/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(n \times C)$, and the space complexity is $O(C)$. Wher +#### Python3 + ```python class Solution: def equalCountSubstrings(self, s: str, count: int) -> int: @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int equalCountSubstrings(String s, int count) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func equalCountSubstrings(s string, count int) (ans int) { n := len(s) @@ -195,6 +203,8 @@ func equalCountSubstrings(s string, count int) (ans int) { } ``` +#### TypeScript + ```ts function equalCountSubstrings(s: string, count: number): number { const n = s.length; @@ -219,6 +229,8 @@ function equalCountSubstrings(s: string, count: number): number { } ``` +#### JavaScript + ```js /** * @param {string} s diff --git a/solution/2000-2099/2068.Check Whether Two Strings are Almost Equivalent/README.md b/solution/2000-2099/2068.Check Whether Two Strings are Almost Equivalent/README.md index 72ff3000c9e10..45909ef028cfe 100644 --- a/solution/2000-2099/2068.Check Whether Two Strings are Almost Equivalent/README.md +++ b/solution/2000-2099/2068.Check Whether Two Strings are Almost Equivalent/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def checkAlmostEquivalent(self, word1: str, word2: str) -> bool: @@ -93,6 +95,8 @@ class Solution: return all(abs(x) <= 3 for x in cnt.values()) ``` +#### Java + ```java class Solution { public boolean checkAlmostEquivalent(String word1, String word2) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func checkAlmostEquivalent(word1 string, word2 string) bool { cnt := [26]int{} @@ -152,6 +160,8 @@ func checkAlmostEquivalent(word1 string, word2 string) bool { } ``` +#### TypeScript + ```ts function checkAlmostEquivalent(word1: string, word2: string): boolean { const cnt: number[] = new Array(26).fill(0); @@ -165,6 +175,8 @@ function checkAlmostEquivalent(word1: string, word2: string): boolean { } ``` +#### JavaScript + ```js /** * @param {string} word1 @@ -186,6 +198,8 @@ var checkAlmostEquivalent = function (word1, word2) { }; ``` +#### C# + ```cs public class Solution { public bool CheckAlmostEquivalent(string word1, string word2) { @@ -201,6 +215,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/2000-2099/2068.Check Whether Two Strings are Almost Equivalent/README_EN.md b/solution/2000-2099/2068.Check Whether Two Strings are Almost Equivalent/README_EN.md index a84f6aff18cb6..cf42491bff0ab 100644 --- a/solution/2000-2099/2068.Check Whether Two Strings are Almost Equivalent/README_EN.md +++ b/solution/2000-2099/2068.Check Whether Two Strings are Almost Equivalent/README_EN.md @@ -85,6 +85,8 @@ The time complexity is $O(n)$ and the space complexity is $O(C)$. Where $n$ is t +#### Python3 + ```python class Solution: def checkAlmostEquivalent(self, word1: str, word2: str) -> bool: @@ -94,6 +96,8 @@ class Solution: return all(abs(x) <= 3 for x in cnt.values()) ``` +#### Java + ```java class Solution { public boolean checkAlmostEquivalent(String word1, String word2) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func checkAlmostEquivalent(word1 string, word2 string) bool { cnt := [26]int{} @@ -153,6 +161,8 @@ func checkAlmostEquivalent(word1 string, word2 string) bool { } ``` +#### TypeScript + ```ts function checkAlmostEquivalent(word1: string, word2: string): boolean { const cnt: number[] = new Array(26).fill(0); @@ -166,6 +176,8 @@ function checkAlmostEquivalent(word1: string, word2: string): boolean { } ``` +#### JavaScript + ```js /** * @param {string} word1 @@ -187,6 +199,8 @@ var checkAlmostEquivalent = function (word1, word2) { }; ``` +#### C# + ```cs public class Solution { public bool CheckAlmostEquivalent(string word1, string word2) { @@ -202,6 +216,8 @@ public class Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/2000-2099/2069.Walking Robot Simulation II/README.md b/solution/2000-2099/2069.Walking Robot Simulation II/README.md index 06a6cca04b71a..5a03344deb946 100644 --- a/solution/2000-2099/2069.Walking Robot Simulation II/README.md +++ b/solution/2000-2099/2069.Walking Robot Simulation II/README.md @@ -89,18 +89,26 @@ robot.getDir(); // 返回 "West" +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2000-2099/2069.Walking Robot Simulation II/README_EN.md b/solution/2000-2099/2069.Walking Robot Simulation II/README_EN.md index 41a2cc4f6dd63..ee4e11f553e48 100644 --- a/solution/2000-2099/2069.Walking Robot Simulation II/README_EN.md +++ b/solution/2000-2099/2069.Walking Robot Simulation II/README_EN.md @@ -85,18 +85,26 @@ robot.getDir(); // return "West" +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2000-2099/2070.Most Beautiful Item for Each Query/README.md b/solution/2000-2099/2070.Most Beautiful Item for Each Query/README.md index 5352fa1794d4f..cb2f55401b418 100644 --- a/solution/2000-2099/2070.Most Beautiful Item for Each Query/README.md +++ b/solution/2000-2099/2070.Most Beautiful Item for Each Query/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def maximumBeauty(self, items: List[List[int]], queries: List[int]) -> List[int]: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] maximumBeauty(int[][] items, int[] queries) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func maximumBeauty(items [][]int, queries []int) []int { sort.Slice(items, func(i, j int) bool { @@ -176,6 +184,8 @@ func maximumBeauty(items [][]int, queries []int) []int { } ``` +#### TypeScript + ```ts function maximumBeauty(items: number[][], queries: number[]): number[] { const n = items.length; @@ -214,6 +224,8 @@ function maximumBeauty(items: number[][], queries: number[]): number[] { +#### Python3 + ```python class Solution: def maximumBeauty(self, items: List[List[int]], queries: List[int]) -> List[int]: @@ -230,6 +242,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] maximumBeauty(int[][] items, int[] queries) { @@ -253,6 +267,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -275,6 +291,8 @@ public: }; ``` +#### Go + ```go func maximumBeauty(items [][]int, queries []int) []int { sort.Slice(items, func(i, j int) bool { @@ -298,6 +316,8 @@ func maximumBeauty(items [][]int, queries []int) []int { } ``` +#### TypeScript + ```ts function maximumBeauty(items: number[][], queries: number[]): number[] { items.sort((a, b) => a[0] - b[0]); diff --git a/solution/2000-2099/2070.Most Beautiful Item for Each Query/README_EN.md b/solution/2000-2099/2070.Most Beautiful Item for Each Query/README_EN.md index 828599749e25c..35c23d03fc641 100644 --- a/solution/2000-2099/2070.Most Beautiful Item for Each Query/README_EN.md +++ b/solution/2000-2099/2070.Most Beautiful Item for Each Query/README_EN.md @@ -87,6 +87,8 @@ The time complexity is $O(n \times \log n + m \times \log m)$, and the space com +#### Python3 + ```python class Solution: def maximumBeauty(self, items: List[List[int]], queries: List[int]) -> List[int]: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] maximumBeauty(int[][] items, int[] queries) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func maximumBeauty(items [][]int, queries []int) []int { sort.Slice(items, func(i, j int) bool { @@ -177,6 +185,8 @@ func maximumBeauty(items [][]int, queries []int) []int { } ``` +#### TypeScript + ```ts function maximumBeauty(items: number[][], queries: number[]): number[] { const n = items.length; @@ -215,6 +225,8 @@ The time complexity is $O((m + n) \times \log n)$, and the space complexity is $ +#### Python3 + ```python class Solution: def maximumBeauty(self, items: List[List[int]], queries: List[int]) -> List[int]: @@ -231,6 +243,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] maximumBeauty(int[][] items, int[] queries) { @@ -254,6 +268,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -276,6 +292,8 @@ public: }; ``` +#### Go + ```go func maximumBeauty(items [][]int, queries []int) []int { sort.Slice(items, func(i, j int) bool { @@ -299,6 +317,8 @@ func maximumBeauty(items [][]int, queries []int) []int { } ``` +#### TypeScript + ```ts function maximumBeauty(items: number[][], queries: number[]): number[] { items.sort((a, b) => a[0] - b[0]); diff --git a/solution/2000-2099/2071.Maximum Number of Tasks You Can Assign/README.md b/solution/2000-2099/2071.Maximum Number of Tasks You Can Assign/README.md index 3953dbbb44062..76f800e3ea397 100644 --- a/solution/2000-2099/2071.Maximum Number of Tasks You Can Assign/README.md +++ b/solution/2000-2099/2071.Maximum Number of Tasks You Can Assign/README.md @@ -112,6 +112,8 @@ tags: +#### Python3 + ```python class Solution: def maxTaskAssign( @@ -149,6 +151,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { private int[] tasks; @@ -204,6 +208,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -247,6 +253,8 @@ public: }; ``` +#### Go + ```go func maxTaskAssign(tasks []int, workers []int, pills int, strength int) int { sort.Ints(tasks) diff --git a/solution/2000-2099/2071.Maximum Number of Tasks You Can Assign/README_EN.md b/solution/2000-2099/2071.Maximum Number of Tasks You Can Assign/README_EN.md index 864f94d046dc1..390eb0fc9ef37 100644 --- a/solution/2000-2099/2071.Maximum Number of Tasks You Can Assign/README_EN.md +++ b/solution/2000-2099/2071.Maximum Number of Tasks You Can Assign/README_EN.md @@ -88,6 +88,8 @@ The last pill is not given because it will not make any worker strong enough for +#### Python3 + ```python class Solution: def maxTaskAssign( @@ -125,6 +127,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { private int[] tasks; @@ -180,6 +184,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -223,6 +229,8 @@ public: }; ``` +#### Go + ```go func maxTaskAssign(tasks []int, workers []int, pills int, strength int) int { sort.Ints(tasks) diff --git a/solution/2000-2099/2072.The Winner University/README.md b/solution/2000-2099/2072.The Winner University/README.md index 195098e91a521..0b05390ee4df3 100644 --- a/solution/2000-2099/2072.The Winner University/README.md +++ b/solution/2000-2099/2072.The Winner University/README.md @@ -156,6 +156,8 @@ California 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2000-2099/2072.The Winner University/README_EN.md b/solution/2000-2099/2072.The Winner University/README_EN.md index 8227f4bc5e018..32ee4de13fb94 100644 --- a/solution/2000-2099/2072.The Winner University/README_EN.md +++ b/solution/2000-2099/2072.The Winner University/README_EN.md @@ -155,6 +155,8 @@ Both New York University and California University have 1 excellent student. +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2000-2099/2073.Time Needed to Buy Tickets/README.md b/solution/2000-2099/2073.Time Needed to Buy Tickets/README.md index 417ac546ee714..b3140552550b1 100644 --- a/solution/2000-2099/2073.Time Needed to Buy Tickets/README.md +++ b/solution/2000-2099/2073.Time Needed to Buy Tickets/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def timeRequiredToBuy(self, tickets: List[int], k: int) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int timeRequiredToBuy(int[] tickets, int k) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func timeRequiredToBuy(tickets []int, k int) int { ans := 0 @@ -130,6 +138,8 @@ func timeRequiredToBuy(tickets []int, k int) int { } ``` +#### TypeScript + ```ts function timeRequiredToBuy(tickets: number[], k: number): number { const n = tickets.length; diff --git a/solution/2000-2099/2073.Time Needed to Buy Tickets/README_EN.md b/solution/2000-2099/2073.Time Needed to Buy Tickets/README_EN.md index fa2e6a67bfb49..97d6d1f99895e 100644 --- a/solution/2000-2099/2073.Time Needed to Buy Tickets/README_EN.md +++ b/solution/2000-2099/2073.Time Needed to Buy Tickets/README_EN.md @@ -71,6 +71,8 @@ The person at position 0 has successfully bought 5 tickets and it took 4 + +#### Python3 + ```python class Solution: def timeRequiredToBuy(self, tickets: List[int], k: int) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int timeRequiredToBuy(int[] tickets, int k) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func timeRequiredToBuy(tickets []int, k int) int { ans := 0 @@ -130,6 +138,8 @@ func timeRequiredToBuy(tickets []int, k int) int { } ``` +#### TypeScript + ```ts function timeRequiredToBuy(tickets: number[], k: number): number { const n = tickets.length; diff --git a/solution/2000-2099/2074.Reverse Nodes in Even Length Groups/README.md b/solution/2000-2099/2074.Reverse Nodes in Even Length Groups/README.md index c51bc5858b0ba..f40075625dbb1 100644 --- a/solution/2000-2099/2074.Reverse Nodes in Even Length Groups/README.md +++ b/solution/2000-2099/2074.Reverse Nodes in Even Length Groups/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -134,6 +136,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -189,6 +193,8 @@ class Solution { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/2000-2099/2074.Reverse Nodes in Even Length Groups/README_EN.md b/solution/2000-2099/2074.Reverse Nodes in Even Length Groups/README_EN.md index a8e7b135a639d..b5ab4e71316fa 100644 --- a/solution/2000-2099/2074.Reverse Nodes in Even Length Groups/README_EN.md +++ b/solution/2000-2099/2074.Reverse Nodes in Even Length Groups/README_EN.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -127,6 +129,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -182,6 +186,8 @@ class Solution { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/2000-2099/2075.Decode the Slanted Ciphertext/README.md b/solution/2000-2099/2075.Decode the Slanted Ciphertext/README.md index a4a67330d2cb5..b8f28226ae247 100644 --- a/solution/2000-2099/2075.Decode the Slanted Ciphertext/README.md +++ b/solution/2000-2099/2075.Decode the Slanted Ciphertext/README.md @@ -104,6 +104,8 @@ tags: +#### Python3 + ```python class Solution: def decodeCiphertext(self, encodedText: str, rows: int) -> str: @@ -117,6 +119,8 @@ class Solution: return ''.join(ans).rstrip() ``` +#### Java + ```java class Solution { public String decodeCiphertext(String encodedText, int rows) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func decodeCiphertext(encodedText string, rows int) string { ans := []byte{} @@ -170,6 +178,8 @@ func decodeCiphertext(encodedText string, rows int) string { } ``` +#### TypeScript + ```ts function decodeCiphertext(encodedText: string, rows: number): string { const cols = Math.ceil(encodedText.length / rows); diff --git a/solution/2000-2099/2075.Decode the Slanted Ciphertext/README_EN.md b/solution/2000-2099/2075.Decode the Slanted Ciphertext/README_EN.md index 57f3d28c978ed..551264b06d6b4 100644 --- a/solution/2000-2099/2075.Decode the Slanted Ciphertext/README_EN.md +++ b/solution/2000-2099/2075.Decode the Slanted Ciphertext/README_EN.md @@ -90,6 +90,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python class Solution: def decodeCiphertext(self, encodedText: str, rows: int) -> str: @@ -103,6 +105,8 @@ class Solution: return ''.join(ans).rstrip() ``` +#### Java + ```java class Solution { public String decodeCiphertext(String encodedText, int rows) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func decodeCiphertext(encodedText string, rows int) string { ans := []byte{} @@ -156,6 +164,8 @@ func decodeCiphertext(encodedText string, rows int) string { } ``` +#### TypeScript + ```ts function decodeCiphertext(encodedText: string, rows: number): string { const cols = Math.ceil(encodedText.length / rows); diff --git a/solution/2000-2099/2076.Process Restricted Friend Requests/README.md b/solution/2000-2099/2076.Process Restricted Friend Requests/README.md index 0e79571992122..3e952cdb457e5 100644 --- a/solution/2000-2099/2076.Process Restricted Friend Requests/README.md +++ b/solution/2000-2099/2076.Process Restricted Friend Requests/README.md @@ -97,6 +97,8 @@ tags: +#### Python3 + ```python class Solution: def friendRequests( @@ -126,6 +128,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] p; @@ -169,6 +173,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -207,6 +213,8 @@ public: }; ``` +#### Go + ```go func friendRequests(n int, restrictions [][]int, requests [][]int) (ans []bool) { p := make([]int, n) @@ -243,6 +251,8 @@ func friendRequests(n int, restrictions [][]int, requests [][]int) (ans []bool) } ``` +#### TypeScript + ```ts function friendRequests(n: number, restrictions: number[][], requests: number[][]): boolean[] { const p: number[] = Array.from({ length: n }, (_, i) => i); diff --git a/solution/2000-2099/2076.Process Restricted Friend Requests/README_EN.md b/solution/2000-2099/2076.Process Restricted Friend Requests/README_EN.md index a7749fab5f9a5..88b19a3254873 100644 --- a/solution/2000-2099/2076.Process Restricted Friend Requests/README_EN.md +++ b/solution/2000-2099/2076.Process Restricted Friend Requests/README_EN.md @@ -95,6 +95,8 @@ The time complexity is $O(q \times m \times \log(n))$, and the space complexity +#### Python3 + ```python class Solution: def friendRequests( @@ -124,6 +126,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] p; @@ -167,6 +171,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -205,6 +211,8 @@ public: }; ``` +#### Go + ```go func friendRequests(n int, restrictions [][]int, requests [][]int) (ans []bool) { p := make([]int, n) @@ -241,6 +249,8 @@ func friendRequests(n int, restrictions [][]int, requests [][]int) (ans []bool) } ``` +#### TypeScript + ```ts function friendRequests(n: number, restrictions: number[][], requests: number[][]): boolean[] { const p: number[] = Array.from({ length: n }, (_, i) => i); diff --git a/solution/2000-2099/2077.Paths in Maze That Lead to Same Room/README.md b/solution/2000-2099/2077.Paths in Maze That Lead to Same Room/README.md index 26c9926433c89..168e1b87b6813 100644 --- a/solution/2000-2099/2077.Paths in Maze That Lead to Same Room/README.md +++ b/solution/2000-2099/2077.Paths in Maze That Lead to Same Room/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfPaths(self, n: int, corridors: List[List[int]]) -> int: @@ -96,6 +98,8 @@ class Solution: return ans // 3 ``` +#### Java + ```java class Solution { public int numberOfPaths(int n, int[][] corridors) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func numberOfPaths(n int, corridors [][]int) int { g := make([]map[int]bool, n+1) diff --git a/solution/2000-2099/2077.Paths in Maze That Lead to Same Room/README_EN.md b/solution/2000-2099/2077.Paths in Maze That Lead to Same Room/README_EN.md index e3ca51a7bd8fe..fb5a1fbae5bc6 100644 --- a/solution/2000-2099/2077.Paths in Maze That Lead to Same Room/README_EN.md +++ b/solution/2000-2099/2077.Paths in Maze That Lead to Same Room/README_EN.md @@ -72,6 +72,8 @@ There are no cycles of length 3. +#### Python3 + ```python class Solution: def numberOfPaths(self, n: int, corridors: List[List[int]]) -> int: @@ -87,6 +89,8 @@ class Solution: return ans // 3 ``` +#### Java + ```java class Solution { public int numberOfPaths(int n, int[][] corridors) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func numberOfPaths(n int, corridors [][]int) int { g := make([]map[int]bool, n+1) diff --git a/solution/2000-2099/2078.Two Furthest Houses With Different Colors/README.md b/solution/2000-2099/2078.Two Furthest Houses With Different Colors/README.md index fe83414464fd2..0d7999c74ad63 100644 --- a/solution/2000-2099/2078.Two Furthest Houses With Different Colors/README.md +++ b/solution/2000-2099/2078.Two Furthest Houses With Different Colors/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def maxDistance(self, colors: List[int]) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxDistance(int[] colors) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func maxDistance(colors []int) int { ans, n := 0, len(colors) @@ -156,6 +164,8 @@ func abs(x int) int { +#### Python3 + ```python class Solution: def maxDistance(self, colors: List[int]) -> int: @@ -170,6 +180,8 @@ class Solution: return max(n - i - 1, j) ``` +#### Java + ```java class Solution { public int maxDistance(int[] colors) { @@ -187,6 +199,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -203,6 +217,8 @@ public: }; ``` +#### Go + ```go func maxDistance(colors []int) int { n := len(colors) diff --git a/solution/2000-2099/2078.Two Furthest Houses With Different Colors/README_EN.md b/solution/2000-2099/2078.Two Furthest Houses With Different Colors/README_EN.md index f38108f52b37b..a05713e13d234 100644 --- a/solution/2000-2099/2078.Two Furthest Houses With Different Colors/README_EN.md +++ b/solution/2000-2099/2078.Two Furthest Houses With Different Colors/README_EN.md @@ -76,6 +76,8 @@ House 0 has color 0, and house 1 has color 1. The distance between them is abs(0 +#### Python3 + ```python class Solution: def maxDistance(self, colors: List[int]) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxDistance(int[] colors) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func maxDistance(colors []int) int { ans, n := 0, len(colors) @@ -148,6 +156,8 @@ func abs(x int) int { +#### Python3 + ```python class Solution: def maxDistance(self, colors: List[int]) -> int: @@ -162,6 +172,8 @@ class Solution: return max(n - i - 1, j) ``` +#### Java + ```java class Solution { public int maxDistance(int[] colors) { @@ -179,6 +191,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -195,6 +209,8 @@ public: }; ``` +#### Go + ```go func maxDistance(colors []int) int { n := len(colors) diff --git a/solution/2000-2099/2079.Watering Plants/README.md b/solution/2000-2099/2079.Watering Plants/README.md index 1fc33354b920f..68eaa90014003 100644 --- a/solution/2000-2099/2079.Watering Plants/README.md +++ b/solution/2000-2099/2079.Watering Plants/README.md @@ -103,6 +103,8 @@ tags: +#### Python3 + ```python class Solution: def wateringPlants(self, plants: List[int], capacity: int) -> int: @@ -117,6 +119,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int wateringPlants(int[] plants, int capacity) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func wateringPlants(plants []int, capacity int) (ans int) { water := capacity @@ -170,6 +178,8 @@ func wateringPlants(plants []int, capacity int) (ans int) { } ``` +#### TypeScript + ```ts function wateringPlants(plants: number[], capacity: number): number { let [ans, water] = [0, capacity]; @@ -186,6 +196,8 @@ function wateringPlants(plants: number[], capacity: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn watering_plants(plants: Vec, capacity: i32) -> i32 { @@ -205,6 +217,8 @@ impl Solution { } ``` +#### C + ```c int wateringPlants(int* plants, int plantsSize, int capacity) { int ans = 0, water = capacity; diff --git a/solution/2000-2099/2079.Watering Plants/README_EN.md b/solution/2000-2099/2079.Watering Plants/README_EN.md index ed071b2352596..7bb0ed1256881 100644 --- a/solution/2000-2099/2079.Watering Plants/README_EN.md +++ b/solution/2000-2099/2079.Watering Plants/README_EN.md @@ -102,6 +102,8 @@ The time complexity is $O(n)$, where $n$ is the number of plants. The space comp +#### Python3 + ```python class Solution: def wateringPlants(self, plants: List[int], capacity: int) -> int: @@ -116,6 +118,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int wateringPlants(int[] plants, int capacity) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func wateringPlants(plants []int, capacity int) (ans int) { water := capacity @@ -169,6 +177,8 @@ func wateringPlants(plants []int, capacity int) (ans int) { } ``` +#### TypeScript + ```ts function wateringPlants(plants: number[], capacity: number): number { let [ans, water] = [0, capacity]; @@ -185,6 +195,8 @@ function wateringPlants(plants: number[], capacity: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn watering_plants(plants: Vec, capacity: i32) -> i32 { @@ -204,6 +216,8 @@ impl Solution { } ``` +#### C + ```c int wateringPlants(int* plants, int plantsSize, int capacity) { int ans = 0, water = capacity; diff --git a/solution/2000-2099/2080.Range Frequency Queries/README.md b/solution/2000-2099/2080.Range Frequency Queries/README.md index 14fa7b149ae82..24521896eaa08 100644 --- a/solution/2000-2099/2080.Range Frequency Queries/README.md +++ b/solution/2000-2099/2080.Range Frequency Queries/README.md @@ -78,6 +78,8 @@ rangeFreqQuery.query(0, 11, 33); // 返回 2 。33 在整个子数组中出现 2 +#### Python3 + ```python class RangeFreqQuery: @@ -98,6 +100,8 @@ class RangeFreqQuery: # param_1 = obj.query(left,right,value) ``` +#### Java + ```java class RangeFreqQuery { private Map> g = new HashMap<>(); @@ -128,6 +132,8 @@ class RangeFreqQuery { */ ``` +#### C++ + ```cpp class RangeFreqQuery { public: @@ -158,6 +164,8 @@ private: */ ``` +#### Go + ```go type RangeFreqQuery struct { g map[int][]int @@ -187,6 +195,8 @@ func (this *RangeFreqQuery) Query(left int, right int, value int) int { */ ``` +#### TypeScript + ```ts class RangeFreqQuery { private g: Map = new Map(); diff --git a/solution/2000-2099/2080.Range Frequency Queries/README_EN.md b/solution/2000-2099/2080.Range Frequency Queries/README_EN.md index d25d2feb498f5..66309cc1300a0 100644 --- a/solution/2000-2099/2080.Range Frequency Queries/README_EN.md +++ b/solution/2000-2099/2080.Range Frequency Queries/README_EN.md @@ -77,6 +77,8 @@ In terms of time complexity, the time complexity of the constructor is $O(n)$, a +#### Python3 + ```python class RangeFreqQuery: @@ -97,6 +99,8 @@ class RangeFreqQuery: # param_1 = obj.query(left,right,value) ``` +#### Java + ```java class RangeFreqQuery { private Map> g = new HashMap<>(); @@ -127,6 +131,8 @@ class RangeFreqQuery { */ ``` +#### C++ + ```cpp class RangeFreqQuery { public: @@ -157,6 +163,8 @@ private: */ ``` +#### Go + ```go type RangeFreqQuery struct { g map[int][]int @@ -186,6 +194,8 @@ func (this *RangeFreqQuery) Query(left int, right int, value int) int { */ ``` +#### TypeScript + ```ts class RangeFreqQuery { private g: Map = new Map(); diff --git a/solution/2000-2099/2081.Sum of k-Mirror Numbers/README.md b/solution/2000-2099/2081.Sum of k-Mirror Numbers/README.md index 7619e77f28b3f..53bad43650637 100644 --- a/solution/2000-2099/2081.Sum of k-Mirror Numbers/README.md +++ b/solution/2000-2099/2081.Sum of k-Mirror Numbers/README.md @@ -89,6 +89,8 @@ tags: +#### Java + ```java class Solution { public long kMirror(int k, int n) { diff --git a/solution/2000-2099/2081.Sum of k-Mirror Numbers/README_EN.md b/solution/2000-2099/2081.Sum of k-Mirror Numbers/README_EN.md index 866147e471831..ec3ab6bf5b1bd 100644 --- a/solution/2000-2099/2081.Sum of k-Mirror Numbers/README_EN.md +++ b/solution/2000-2099/2081.Sum of k-Mirror Numbers/README_EN.md @@ -90,6 +90,8 @@ Their sum = 1 + 2 + 4 + 8 + 121 + 151 + 212 = 499. +#### Java + ```java class Solution { public long kMirror(int k, int n) { diff --git a/solution/2000-2099/2082.The Number of Rich Customers/README.md b/solution/2000-2099/2082.The Number of Rich Customers/README.md index 0ae7e8e9e9d56..d6918c413b68b 100644 --- a/solution/2000-2099/2082.The Number of Rich Customers/README.md +++ b/solution/2000-2099/2082.The Number of Rich Customers/README.md @@ -74,6 +74,8 @@ Store 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2000-2099/2082.The Number of Rich Customers/README_EN.md b/solution/2000-2099/2082.The Number of Rich Customers/README_EN.md index e1472c6d98b77..130ae8ceb365b 100644 --- a/solution/2000-2099/2082.The Number of Rich Customers/README_EN.md +++ b/solution/2000-2099/2082.The Number of Rich Customers/README_EN.md @@ -73,6 +73,8 @@ Customer 3 has one bill with an amount strictly greater than 500. +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2000-2099/2083.Substrings That Begin and End With the Same Letter/README.md b/solution/2000-2099/2083.Substrings That Begin and End With the Same Letter/README.md index a5dcc9ddb8227..cd4c72cfa80ce 100644 --- a/solution/2000-2099/2083.Substrings That Begin and End With the Same Letter/README.md +++ b/solution/2000-2099/2083.Substrings That Begin and End With the Same Letter/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfSubstrings(self, s: str) -> int: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long numberOfSubstrings(String s) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func numberOfSubstrings(s string) (ans int64) { cnt := [26]int{} diff --git a/solution/2000-2099/2083.Substrings That Begin and End With the Same Letter/README_EN.md b/solution/2000-2099/2083.Substrings That Begin and End With the Same Letter/README_EN.md index 33f197ee9929c..0c829e8d2696e 100644 --- a/solution/2000-2099/2083.Substrings That Begin and End With the Same Letter/README_EN.md +++ b/solution/2000-2099/2083.Substrings That Begin and End With the Same Letter/README_EN.md @@ -74,6 +74,8 @@ The substring of length 1 that starts and ends with the same letter is: "a& +#### Python3 + ```python class Solution: def numberOfSubstrings(self, s: str) -> int: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long numberOfSubstrings(String s) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func numberOfSubstrings(s string) (ans int64) { cnt := [26]int{} diff --git a/solution/2000-2099/2084.Drop Type 1 Orders for Customers With Type 0 Orders/README.md b/solution/2000-2099/2084.Drop Type 1 Orders for Customers With Type 0 Orders/README.md index f75fe010eb06a..1ac80055708e7 100644 --- a/solution/2000-2099/2084.Drop Type 1 Orders for Customers With Type 0 Orders/README.md +++ b/solution/2000-2099/2084.Drop Type 1 Orders for Customers With Type 0 Orders/README.md @@ -89,6 +89,8 @@ Orders table: +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -112,6 +114,8 @@ WHERE order_type = 0 OR NOT EXISTS (SELECT 1 FROM T AS t WHERE t.customer_id = o +#### MySQL + ```sql SELECT DISTINCT a.order_id, diff --git a/solution/2000-2099/2084.Drop Type 1 Orders for Customers With Type 0 Orders/README_EN.md b/solution/2000-2099/2084.Drop Type 1 Orders for Customers With Type 0 Orders/README_EN.md index 9542fb43d09c0..c610f34202b87 100644 --- a/solution/2000-2099/2084.Drop Type 1 Orders for Customers With Type 0 Orders/README_EN.md +++ b/solution/2000-2099/2084.Drop Type 1 Orders for Customers With Type 0 Orders/README_EN.md @@ -91,6 +91,8 @@ Customer 4 has two orders of type 1. We return both of them. +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -114,6 +116,8 @@ WHERE order_type = 0 OR NOT EXISTS (SELECT 1 FROM T AS t WHERE t.customer_id = o +#### MySQL + ```sql SELECT DISTINCT a.order_id, diff --git a/solution/2000-2099/2085.Count Common Words With One Occurrence/README.md b/solution/2000-2099/2085.Count Common Words With One Occurrence/README.md index 1bb4e42be0a85..e9135f1aa728a 100644 --- a/solution/2000-2099/2085.Count Common Words With One Occurrence/README.md +++ b/solution/2000-2099/2085.Count Common Words With One Occurrence/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def countWords(self, words1: List[str], words2: List[str]) -> int: @@ -86,6 +88,8 @@ class Solution: return sum(v == 1 and cnt2[w] == 1 for w, v in cnt1.items()) ``` +#### Java + ```java class Solution { public int countWords(String[] words1, String[] words2) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func countWords(words1 []string, words2 []string) (ans int) { cnt1 := map[string]int{} @@ -148,6 +156,8 @@ func countWords(words1 []string, words2 []string) (ans int) { } ``` +#### TypeScript + ```ts function countWords(words1: string[], words2: string[]): number { const cnt1 = new Map(); diff --git a/solution/2000-2099/2085.Count Common Words With One Occurrence/README_EN.md b/solution/2000-2099/2085.Count Common Words With One Occurrence/README_EN.md index 492f86b44907b..6da2223a76717 100644 --- a/solution/2000-2099/2085.Count Common Words With One Occurrence/README_EN.md +++ b/solution/2000-2099/2085.Count Common Words With One Occurrence/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(n + m)$, and the space complexity is $O(n + m)$. Where +#### Python3 + ```python class Solution: def countWords(self, words1: List[str], words2: List[str]) -> int: @@ -84,6 +86,8 @@ class Solution: return sum(v == 1 and cnt2[w] == 1 for w, v in cnt1.items()) ``` +#### Java + ```java class Solution { public int countWords(String[] words1, String[] words2) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func countWords(words1 []string, words2 []string) (ans int) { cnt1 := map[string]int{} @@ -146,6 +154,8 @@ func countWords(words1 []string, words2 []string) (ans int) { } ``` +#### TypeScript + ```ts function countWords(words1: string[], words2: string[]): number { const cnt1 = new Map(); diff --git a/solution/2000-2099/2086.Minimum Number of Food Buckets to Feed the Hamsters/README.md b/solution/2000-2099/2086.Minimum Number of Food Buckets to Feed the Hamsters/README.md index dbf7012b09839..5936412445f2a 100644 --- a/solution/2000-2099/2086.Minimum Number of Food Buckets to Feed the Hamsters/README.md +++ b/solution/2000-2099/2086.Minimum Number of Food Buckets to Feed the Hamsters/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def minimumBuckets(self, street: str) -> int: @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumBuckets(String street) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func minimumBuckets(street string) int { ans, n := 0, len(street) diff --git a/solution/2000-2099/2086.Minimum Number of Food Buckets to Feed the Hamsters/README_EN.md b/solution/2000-2099/2086.Minimum Number of Food Buckets to Feed the Hamsters/README_EN.md index cdeb78eb215be..add2ba6c67076 100644 --- a/solution/2000-2099/2086.Minimum Number of Food Buckets to Feed the Hamsters/README_EN.md +++ b/solution/2000-2099/2086.Minimum Number of Food Buckets to Feed the Hamsters/README_EN.md @@ -75,6 +75,8 @@ It can be shown that if we place only one food bucket, one of the hamsters will +#### Python3 + ```python class Solution: def minimumBuckets(self, street: str) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumBuckets(String street) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func minimumBuckets(street string) int { ans, n := 0, len(street) diff --git a/solution/2000-2099/2087.Minimum Cost Homecoming of a Robot in a Grid/README.md b/solution/2000-2099/2087.Minimum Cost Homecoming of a Robot in a Grid/README.md index 298d745776f5b..eb675a99d9ba3 100644 --- a/solution/2000-2099/2087.Minimum Cost Homecoming of a Robot in a Grid/README.md +++ b/solution/2000-2099/2087.Minimum Cost Homecoming of a Robot in a Grid/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def minCost( @@ -110,6 +112,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minCost(int[] startPos, int[] homePos, int[] rowCosts, int[] colCosts) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func minCost(startPos []int, homePos []int, rowCosts []int, colCosts []int) (ans int) { i, j := startPos[0], startPos[1] diff --git a/solution/2000-2099/2087.Minimum Cost Homecoming of a Robot in a Grid/README_EN.md b/solution/2000-2099/2087.Minimum Cost Homecoming of a Robot in a Grid/README_EN.md index 564ee6bd89824..2a2b32ca6c72c 100644 --- a/solution/2000-2099/2087.Minimum Cost Homecoming of a Robot in a Grid/README_EN.md +++ b/solution/2000-2099/2087.Minimum Cost Homecoming of a Robot in a Grid/README_EN.md @@ -76,6 +76,8 @@ The total cost is 3 + 2 + 6 + 7 = 18 +#### Python3 + ```python class Solution: def minCost( @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minCost(int[] startPos, int[] homePos, int[] rowCosts, int[] colCosts) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func minCost(startPos []int, homePos []int, rowCosts []int, colCosts []int) (ans int) { i, j := startPos[0], startPos[1] diff --git a/solution/2000-2099/2088.Count Fertile Pyramids in a Land/README.md b/solution/2000-2099/2088.Count Fertile Pyramids in a Land/README.md index 9741dfd87f2fd..7cecc25f4b6db 100644 --- a/solution/2000-2099/2088.Count Fertile Pyramids in a Land/README.md +++ b/solution/2000-2099/2088.Count Fertile Pyramids in a Land/README.md @@ -131,6 +131,8 @@ $$ +#### Python3 + ```python class Solution: def countPyramids(self, grid: List[List[int]]) -> int: @@ -156,6 +158,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countPyramids(int[][] grid) { @@ -191,6 +195,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -227,6 +233,8 @@ public: }; ``` +#### Go + ```go func countPyramids(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) diff --git a/solution/2000-2099/2088.Count Fertile Pyramids in a Land/README_EN.md b/solution/2000-2099/2088.Count Fertile Pyramids in a Land/README_EN.md index 7d03f56a60895..43ae92acb7306 100644 --- a/solution/2000-2099/2088.Count Fertile Pyramids in a Land/README_EN.md +++ b/solution/2000-2099/2088.Count Fertile Pyramids in a Land/README_EN.md @@ -91,6 +91,8 @@ The total number of plots is 7 + 6 = 13. +#### Python3 + ```python class Solution: def countPyramids(self, grid: List[List[int]]) -> int: @@ -116,6 +118,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countPyramids(int[][] grid) { @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -187,6 +193,8 @@ public: }; ``` +#### Go + ```go func countPyramids(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) diff --git a/solution/2000-2099/2089.Find Target Indices After Sorting Array/README.md b/solution/2000-2099/2089.Find Target Indices After Sorting Array/README.md index 0642e01e5684b..72a21504f72d3 100644 --- a/solution/2000-2099/2089.Find Target Indices After Sorting Array/README.md +++ b/solution/2000-2099/2089.Find Target Indices After Sorting Array/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def targetIndices(self, nums: List[int], target: int) -> List[int]: @@ -89,6 +91,8 @@ class Solution: return [i for i, v in enumerate(nums) if v == target] ``` +#### Java + ```java class Solution { public List targetIndices(int[] nums, int target) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func targetIndices(nums []int, target int) (ans []int) { sort.Ints(nums) @@ -132,6 +140,8 @@ func targetIndices(nums []int, target int) (ans []int) { } ``` +#### TypeScript + ```ts function targetIndices(nums: number[], target: number): number[] { nums.sort((a, b) => a - b); diff --git a/solution/2000-2099/2089.Find Target Indices After Sorting Array/README_EN.md b/solution/2000-2099/2089.Find Target Indices After Sorting Array/README_EN.md index a9b2acc8cf61b..34337d1ff1e49 100644 --- a/solution/2000-2099/2089.Find Target Indices After Sorting Array/README_EN.md +++ b/solution/2000-2099/2089.Find Target Indices After Sorting Array/README_EN.md @@ -72,6 +72,8 @@ The index where nums[i] == 5 is 4. +#### Python3 + ```python class Solution: def targetIndices(self, nums: List[int], target: int) -> List[int]: @@ -79,6 +81,8 @@ class Solution: return [i for i, v in enumerate(nums) if v == target] ``` +#### Java + ```java class Solution { public List targetIndices(int[] nums, int target) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func targetIndices(nums []int, target int) (ans []int) { sort.Ints(nums) @@ -122,6 +130,8 @@ func targetIndices(nums []int, target int) (ans []int) { } ``` +#### TypeScript + ```ts function targetIndices(nums: number[], target: number): number[] { nums.sort((a, b) => a - b); diff --git a/solution/2000-2099/2090.K Radius Subarray Averages/README.md b/solution/2000-2099/2090.K Radius Subarray Averages/README.md index 31df75761863b..9dc7e762f6bf6 100644 --- a/solution/2000-2099/2090.K Radius Subarray Averages/README.md +++ b/solution/2000-2099/2090.K Radius Subarray Averages/README.md @@ -102,6 +102,8 @@ tags: +#### Python3 + ```python class Solution: def getAverages(self, nums: List[int], k: int) -> List[int]: @@ -120,6 +122,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] getAverages(int[] nums, int k) { @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func getAverages(nums []int, k int) []int { k = k<<1 | 1 @@ -193,6 +201,8 @@ func getAverages(nums []int, k int) []int { } ``` +#### TypeScript + ```ts function getAverages(nums: number[], k: number): number[] { k = (k << 1) | 1; @@ -232,6 +242,8 @@ function getAverages(nums: number[], k: number): number[] { +#### Python3 + ```python class Solution: def getAverages(self, nums: List[int], k: int) -> List[int]: @@ -245,6 +257,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] getAverages(int[] nums, int k) { @@ -264,6 +278,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -283,6 +299,8 @@ public: }; ``` +#### Go + ```go func getAverages(nums []int, k int) []int { ans := make([]int, len(nums)) @@ -299,6 +317,8 @@ func getAverages(nums []int, k int) []int { } ``` +#### TypeScript + ```ts function getAverages(nums: number[], k: number): number[] { const n = nums.length; diff --git a/solution/2000-2099/2090.K Radius Subarray Averages/README_EN.md b/solution/2000-2099/2090.K Radius Subarray Averages/README_EN.md index 9901d76b4adbd..e4a843725e86d 100644 --- a/solution/2000-2099/2090.K Radius Subarray Averages/README_EN.md +++ b/solution/2000-2099/2090.K Radius Subarray Averages/README_EN.md @@ -98,6 +98,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array `nums`. Igno +#### Python3 + ```python class Solution: def getAverages(self, nums: List[int], k: int) -> List[int]: @@ -116,6 +118,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] getAverages(int[] nums, int k) { @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func getAverages(nums []int, k int) []int { k = k<<1 | 1 @@ -189,6 +197,8 @@ func getAverages(nums []int, k int) []int { } ``` +#### TypeScript + ```ts function getAverages(nums: number[], k: number): number[] { k = (k << 1) | 1; @@ -228,6 +238,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array `nums`. Igno +#### Python3 + ```python class Solution: def getAverages(self, nums: List[int], k: int) -> List[int]: @@ -241,6 +253,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] getAverages(int[] nums, int k) { @@ -260,6 +274,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -279,6 +295,8 @@ public: }; ``` +#### Go + ```go func getAverages(nums []int, k int) []int { ans := make([]int, len(nums)) @@ -295,6 +313,8 @@ func getAverages(nums []int, k int) []int { } ``` +#### TypeScript + ```ts function getAverages(nums: number[], k: number): number[] { const n = nums.length; diff --git a/solution/2000-2099/2091.Removing Minimum and Maximum From Array/README.md b/solution/2000-2099/2091.Removing Minimum and Maximum From Array/README.md index d7577be51fa22..40702d85986bf 100644 --- a/solution/2000-2099/2091.Removing Minimum and Maximum From Array/README.md +++ b/solution/2000-2099/2091.Removing Minimum and Maximum From Array/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def minimumDeletions(self, nums: List[int]) -> int: @@ -97,6 +99,8 @@ class Solution: return min(mx + 1, len(nums) - mi, mi + 1 + len(nums) - mx) ``` +#### Java + ```java class Solution { public int minimumDeletions(int[] nums) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func minimumDeletions(nums []int) int { mi, mx, n := 0, 0, len(nums) @@ -156,6 +164,8 @@ func minimumDeletions(nums []int) int { } ``` +#### TypeScript + ```ts function minimumDeletions(nums: number[]): number { const n = nums.length; diff --git a/solution/2000-2099/2091.Removing Minimum and Maximum From Array/README_EN.md b/solution/2000-2099/2091.Removing Minimum and Maximum From Array/README_EN.md index 186c7963c52a4..f99395f5109c0 100644 --- a/solution/2000-2099/2091.Removing Minimum and Maximum From Array/README_EN.md +++ b/solution/2000-2099/2091.Removing Minimum and Maximum From Array/README_EN.md @@ -81,6 +81,8 @@ We can remove it with 1 deletion. +#### Python3 + ```python class Solution: def minimumDeletions(self, nums: List[int]) -> int: @@ -95,6 +97,8 @@ class Solution: return min(mx + 1, len(nums) - mi, mi + 1 + len(nums) - mx) ``` +#### Java + ```java class Solution { public int minimumDeletions(int[] nums) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func minimumDeletions(nums []int) int { mi, mx, n := 0, 0, len(nums) @@ -154,6 +162,8 @@ func minimumDeletions(nums []int) int { } ``` +#### TypeScript + ```ts function minimumDeletions(nums: number[]): number { const n = nums.length; diff --git a/solution/2000-2099/2092.Find All People With Secret/README.md b/solution/2000-2099/2092.Find All People With Secret/README.md index deddc3c9c57ba..39bdc198ced42 100644 --- a/solution/2000-2099/2092.Find All People With Secret/README.md +++ b/solution/2000-2099/2092.Find All People With Secret/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def findAllPeople( @@ -123,6 +125,8 @@ class Solution: return [i for i, v in enumerate(vis) if v] ``` +#### Java + ```java class Solution { public List findAllPeople(int n, int[][] meetings, int firstPerson) { @@ -172,6 +176,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -219,6 +225,8 @@ public: }; ``` +#### Go + ```go func findAllPeople(n int, meetings [][]int, firstPerson int) []int { vis := make([]bool, n) @@ -266,6 +274,8 @@ func findAllPeople(n int, meetings [][]int, firstPerson int) []int { } ``` +#### TypeScript + ```ts function findAllPeople(n: number, meetings: number[][], firstPerson: number): number[] { let parent: Array = Array.from({ length: n + 1 }, (v, i) => i); diff --git a/solution/2000-2099/2092.Find All People With Secret/README_EN.md b/solution/2000-2099/2092.Find All People With Secret/README_EN.md index e9ce516416f81..1601cf0a8d31b 100644 --- a/solution/2000-2099/2092.Find All People With Secret/README_EN.md +++ b/solution/2000-2099/2092.Find All People With Secret/README_EN.md @@ -92,6 +92,8 @@ Thus, people 0, 1, 2, 3, and 4 know the secret after all the meetings. +#### Python3 + ```python class Solution: def findAllPeople( @@ -122,6 +124,8 @@ class Solution: return [i for i, v in enumerate(vis) if v] ``` +#### Java + ```java class Solution { public List findAllPeople(int n, int[][] meetings, int firstPerson) { @@ -171,6 +175,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -218,6 +224,8 @@ public: }; ``` +#### Go + ```go func findAllPeople(n int, meetings [][]int, firstPerson int) []int { vis := make([]bool, n) @@ -265,6 +273,8 @@ func findAllPeople(n int, meetings [][]int, firstPerson int) []int { } ``` +#### TypeScript + ```ts function findAllPeople(n: number, meetings: number[][], firstPerson: number): number[] { let parent: Array = Array.from({ length: n + 1 }, (v, i) => i); diff --git a/solution/2000-2099/2093.Minimum Cost to Reach City With Discounts/README.md b/solution/2000-2099/2093.Minimum Cost to Reach City With Discounts/README.md index e240242c4eece..121b6caea229e 100644 --- a/solution/2000-2099/2093.Minimum Cost to Reach City With Discounts/README.md +++ b/solution/2000-2099/2093.Minimum Cost to Reach City With Discounts/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def minimumCost(self, n: int, highways: List[List[int]], discounts: int) -> int: @@ -111,6 +113,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minimumCost(int n, int[][] highways, int discounts) { @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/2000-2099/2093.Minimum Cost to Reach City With Discounts/README_EN.md b/solution/2000-2099/2093.Minimum Cost to Reach City With Discounts/README_EN.md index 5c4a973cf1c1a..b65a4179bdbd5 100644 --- a/solution/2000-2099/2093.Minimum Cost to Reach City With Discounts/README_EN.md +++ b/solution/2000-2099/2093.Minimum Cost to Reach City With Discounts/README_EN.md @@ -84,6 +84,8 @@ It is impossible to go from 0 to 3 so return -1. +#### Python3 + ```python class Solution: def minimumCost(self, n: int, highways: List[List[int]], discounts: int) -> int: @@ -107,6 +109,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minimumCost(int n, int[][] highways, int discounts) { @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/2000-2099/2094.Finding 3-Digit Even Numbers/README.md b/solution/2000-2099/2094.Finding 3-Digit Even Numbers/README.md index 979550815c727..d0f756c1a57a9 100644 --- a/solution/2000-2099/2094.Finding 3-Digit Even Numbers/README.md +++ b/solution/2000-2099/2094.Finding 3-Digit Even Numbers/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def findEvenNumbers(self, digits: List[int]) -> List[int]: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] findEvenNumbers(int[] digits) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go func findEvenNumbers(digits []int) []int { counter := count(digits) @@ -209,6 +217,8 @@ func check(cnt1, cnt2 []int) bool { } ``` +#### TypeScript + ```ts function findEvenNumbers(digits: number[]): number[] { let record = new Array(10).fill(0); diff --git a/solution/2000-2099/2094.Finding 3-Digit Even Numbers/README_EN.md b/solution/2000-2099/2094.Finding 3-Digit Even Numbers/README_EN.md index 5dde23e97f35e..ee8e5f560b6f3 100644 --- a/solution/2000-2099/2094.Finding 3-Digit Even Numbers/README_EN.md +++ b/solution/2000-2099/2094.Finding 3-Digit Even Numbers/README_EN.md @@ -80,6 +80,8 @@ In this example, the digit 8 is used twice each time in 288, 828, and 882. +#### Python3 + ```python class Solution: def findEvenNumbers(self, digits: List[int]) -> List[int]: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] findEvenNumbers(int[] digits) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func findEvenNumbers(digits []int) []int { counter := count(digits) @@ -205,6 +213,8 @@ func check(cnt1, cnt2 []int) bool { } ``` +#### TypeScript + ```ts function findEvenNumbers(digits: number[]): number[] { let record = new Array(10).fill(0); diff --git a/solution/2000-2099/2095.Delete the Middle Node of a Linked List/README.md b/solution/2000-2099/2095.Delete the Middle Node of a Linked List/README.md index 8b74369f7efa6..75130395fb9d6 100644 --- a/solution/2000-2099/2095.Delete the Middle Node of a Linked List/README.md +++ b/solution/2000-2099/2095.Delete the Middle Node of a Linked List/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -102,6 +104,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -173,6 +181,8 @@ func deleteMiddle(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/2000-2099/2095.Delete the Middle Node of a Linked List/README_EN.md b/solution/2000-2099/2095.Delete the Middle Node of a Linked List/README_EN.md index e3006327ec0cc..3f244977be916 100644 --- a/solution/2000-2099/2095.Delete the Middle Node of a Linked List/README_EN.md +++ b/solution/2000-2099/2095.Delete the Middle Node of a Linked List/README_EN.md @@ -77,6 +77,8 @@ Node 0 with value 2 is the only node remaining after removing node 1. +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -94,6 +96,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -165,6 +173,8 @@ func deleteMiddle(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/2000-2099/2096.Step-By-Step Directions From a Binary Tree Node to Another/README.md b/solution/2000-2099/2096.Step-By-Step Directions From a Binary Tree Node to Another/README.md index ac09ab549da01..c7e958f93e469 100644 --- a/solution/2000-2099/2096.Step-By-Step Directions From a Binary Tree Node to Another/README.md +++ b/solution/2000-2099/2096.Step-By-Step Directions From a Binary Tree Node to Another/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -122,6 +124,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -194,6 +198,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. diff --git a/solution/2000-2099/2096.Step-By-Step Directions From a Binary Tree Node to Another/README_EN.md b/solution/2000-2099/2096.Step-By-Step Directions From a Binary Tree Node to Another/README_EN.md index c9156a77e18ef..f83a49ec6545c 100644 --- a/solution/2000-2099/2096.Step-By-Step Directions From a Binary Tree Node to Another/README_EN.md +++ b/solution/2000-2099/2096.Step-By-Step Directions From a Binary Tree Node to Another/README_EN.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -118,6 +120,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -190,6 +194,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. diff --git a/solution/2000-2099/2097.Valid Arrangement of Pairs/README.md b/solution/2000-2099/2097.Valid Arrangement of Pairs/README.md index 63839024bb776..1fa6c8e20ed4e 100644 --- a/solution/2000-2099/2097.Valid Arrangement of Pairs/README.md +++ b/solution/2000-2099/2097.Valid Arrangement of Pairs/README.md @@ -86,18 +86,26 @@ end1 = 1 == 1 = start2 +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2000-2099/2097.Valid Arrangement of Pairs/README_EN.md b/solution/2000-2099/2097.Valid Arrangement of Pairs/README_EN.md index f33439e86d425..d6634170a35e5 100644 --- a/solution/2000-2099/2097.Valid Arrangement of Pairs/README_EN.md +++ b/solution/2000-2099/2097.Valid Arrangement of Pairs/README_EN.md @@ -84,18 +84,26 @@ end1 = 1 == 1 = start2 +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2000-2099/2098.Subsequence of Size K With the Largest Even Sum/README.md b/solution/2000-2099/2098.Subsequence of Size K With the Largest Even Sum/README.md index f7f54e5aa3a92..3dc021a1729e5 100644 --- a/solution/2000-2099/2098.Subsequence of Size K With the Largest Even Sum/README.md +++ b/solution/2000-2099/2098.Subsequence of Size K With the Largest Even Sum/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def largestEvenSum(self, nums: List[int], k: int) -> int: @@ -108,6 +110,8 @@ class Solution: return -1 if ans % 2 else ans ``` +#### Java + ```java class Solution { public long largestEvenSum(int[] nums, int k) { @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -179,6 +185,8 @@ public: }; ``` +#### Go + ```go func largestEvenSum(nums []int, k int) int64 { sort.Ints(nums) diff --git a/solution/2000-2099/2098.Subsequence of Size K With the Largest Even Sum/README_EN.md b/solution/2000-2099/2098.Subsequence of Size K With the Largest Even Sum/README_EN.md index 2259cbb1f14c3..9090b2463b126 100644 --- a/solution/2000-2099/2098.Subsequence of Size K With the Largest Even Sum/README_EN.md +++ b/solution/2000-2099/2098.Subsequence of Size K With the Largest Even Sum/README_EN.md @@ -71,6 +71,8 @@ No subsequence of nums with length 1 has an even sum. +#### Python3 + ```python class Solution: def largestEvenSum(self, nums: List[int], k: int) -> int: @@ -95,6 +97,8 @@ class Solution: return -1 if ans % 2 else ans ``` +#### Java + ```java class Solution { public long largestEvenSum(int[] nums, int k) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go func largestEvenSum(nums []int, k int) int64 { sort.Ints(nums) diff --git a/solution/2000-2099/2099.Find Subsequence of Length K With the Largest Sum/README.md b/solution/2000-2099/2099.Find Subsequence of Length K With the Largest Sum/README.md index b3c2dff7d734e..f4f49b5bb21a4 100644 --- a/solution/2000-2099/2099.Find Subsequence of Length K With the Largest Sum/README.md +++ b/solution/2000-2099/2099.Find Subsequence of Length K With the Largest Sum/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def maxSubsequence(self, nums: List[int], k: int) -> List[int]: @@ -81,6 +83,8 @@ class Solution: return [nums[i] for i in sorted(idx[-k:])] ``` +#### Java + ```java class Solution { public int[] maxSubsequence(int[] nums, int k) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func maxSubsequence(nums []int, k int) []int { idx := make([]int, len(nums)) diff --git a/solution/2000-2099/2099.Find Subsequence of Length K With the Largest Sum/README_EN.md b/solution/2000-2099/2099.Find Subsequence of Length K With the Largest Sum/README_EN.md index e6f0e9311a660..93d2dba9f0118 100644 --- a/solution/2000-2099/2099.Find Subsequence of Length K With the Largest Sum/README_EN.md +++ b/solution/2000-2099/2099.Find Subsequence of Length K With the Largest Sum/README_EN.md @@ -74,6 +74,8 @@ Another possible subsequence is [4, 3]. +#### Python3 + ```python class Solution: def maxSubsequence(self, nums: List[int], k: int) -> List[int]: @@ -82,6 +84,8 @@ class Solution: return [nums[i] for i in sorted(idx[-k:])] ``` +#### Java + ```java class Solution { public int[] maxSubsequence(int[] nums, int k) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func maxSubsequence(nums []int, k int) []int { idx := make([]int, len(nums)) diff --git a/solution/2100-2199/2100.Find Good Days to Rob the Bank/README.md b/solution/2100-2199/2100.Find Good Days to Rob the Bank/README.md index d69396f48f0dd..7cc0232e08b7e 100644 --- a/solution/2100-2199/2100.Find Good Days to Rob the Bank/README.md +++ b/solution/2100-2199/2100.Find Good Days to Rob the Bank/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def goodDaysToRobBank(self, security: List[int], time: int) -> List[int]: @@ -101,6 +103,8 @@ class Solution: return [i for i in range(n) if time <= min(left[i], right[i])] ``` +#### Java + ```java class Solution { public List goodDaysToRobBank(int[] security, int time) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func goodDaysToRobBank(security []int, time int) []int { n := len(security) @@ -182,6 +190,8 @@ func goodDaysToRobBank(security []int, time int) []int { } ``` +#### TypeScript + ```ts function goodDaysToRobBank(security: number[], time: number): number[] { const n = security.length; @@ -208,6 +218,8 @@ function goodDaysToRobBank(security: number[], time: number): number[] { } ``` +#### Rust + ```rust use std::cmp::Ordering; diff --git a/solution/2100-2199/2100.Find Good Days to Rob the Bank/README_EN.md b/solution/2100-2199/2100.Find Good Days to Rob the Bank/README_EN.md index 67fd0cd99c3f2..c97d69e34c197 100644 --- a/solution/2100-2199/2100.Find Good Days to Rob the Bank/README_EN.md +++ b/solution/2100-2199/2100.Find Good Days to Rob the Bank/README_EN.md @@ -83,6 +83,8 @@ Thus, no day is a good day to rob the bank, so return an empty list. +#### Python3 + ```python class Solution: def goodDaysToRobBank(self, security: List[int], time: int) -> List[int]: @@ -99,6 +101,8 @@ class Solution: return [i for i in range(n) if time <= min(left[i], right[i])] ``` +#### Java + ```java class Solution { public List goodDaysToRobBank(int[] security, int time) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func goodDaysToRobBank(security []int, time int) []int { n := len(security) @@ -180,6 +188,8 @@ func goodDaysToRobBank(security []int, time int) []int { } ``` +#### TypeScript + ```ts function goodDaysToRobBank(security: number[], time: number): number[] { const n = security.length; @@ -206,6 +216,8 @@ function goodDaysToRobBank(security: number[], time: number): number[] { } ``` +#### Rust + ```rust use std::cmp::Ordering; diff --git a/solution/2100-2199/2101.Detonate the Maximum Bombs/README.md b/solution/2100-2199/2101.Detonate the Maximum Bombs/README.md index f6f388ca63b9f..e0e8ad0876f63 100644 --- a/solution/2100-2199/2101.Detonate the Maximum Bombs/README.md +++ b/solution/2100-2199/2101.Detonate the Maximum Bombs/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def maximumDetonation(self, bombs: List[List[int]]) -> int: @@ -125,6 +127,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[][] bombs; @@ -172,6 +176,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -213,6 +219,8 @@ public: }; ``` +#### Go + ```go func maximumDetonation(bombs [][]int) int { check := func(i, j int) bool { diff --git a/solution/2100-2199/2101.Detonate the Maximum Bombs/README_EN.md b/solution/2100-2199/2101.Detonate the Maximum Bombs/README_EN.md index a057d1422c53d..2b9c0daa54c67 100644 --- a/solution/2100-2199/2101.Detonate the Maximum Bombs/README_EN.md +++ b/solution/2100-2199/2101.Detonate the Maximum Bombs/README_EN.md @@ -85,6 +85,8 @@ Thus all 5 bombs are detonated. +#### Python3 + ```python class Solution: def maximumDetonation(self, bombs: List[List[int]]) -> int: @@ -118,6 +120,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[][] bombs; @@ -165,6 +169,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -206,6 +212,8 @@ public: }; ``` +#### Go + ```go func maximumDetonation(bombs [][]int) int { check := func(i, j int) bool { diff --git a/solution/2100-2199/2102.Sequentially Ordinal Rank Tracker/README.md b/solution/2100-2199/2102.Sequentially Ordinal Rank Tracker/README.md index de7cad9eb5111..ab2779fcc5ade 100644 --- a/solution/2100-2199/2102.Sequentially Ordinal Rank Tracker/README.md +++ b/solution/2100-2199/2102.Sequentially Ordinal Rank Tracker/README.md @@ -110,6 +110,8 @@ tracker.get(); // 从好到坏的景点为:branford, orlando, alp +#### Python3 + ```python from sortedcontainers import SortedList @@ -134,6 +136,8 @@ class SORTracker: # param_2 = obj.get() ``` +#### C++ + ```cpp #include #include @@ -186,6 +190,8 @@ private: +#### Python3 + ```python class Node: def __init__(self, s: str): @@ -217,6 +223,8 @@ class SORTracker: # param_2 = obj.get() ``` +#### Java + ```java class SORTracker { private PriorityQueue> good = new PriorityQueue<>( @@ -250,6 +258,8 @@ class SORTracker { */ ``` +#### C++ + ```cpp using pis = pair; diff --git a/solution/2100-2199/2102.Sequentially Ordinal Rank Tracker/README_EN.md b/solution/2100-2199/2102.Sequentially Ordinal Rank Tracker/README_EN.md index f815bbdec1bbc..43359b58f43a8 100644 --- a/solution/2100-2199/2102.Sequentially Ordinal Rank Tracker/README_EN.md +++ b/solution/2100-2199/2102.Sequentially Ordinal Rank Tracker/README_EN.md @@ -108,6 +108,8 @@ The time complexity of each operation is $O(\log n)$, where $n$ is the number of +#### Python3 + ```python from sortedcontainers import SortedList @@ -132,6 +134,8 @@ class SORTracker: # param_2 = obj.get() ``` +#### C++ + ```cpp #include #include @@ -184,6 +188,8 @@ The time complexity of each operation is $O(\log n)$, where $n$ is the number of +#### Python3 + ```python class Node: def __init__(self, s: str): @@ -215,6 +221,8 @@ class SORTracker: # param_2 = obj.get() ``` +#### Java + ```java class SORTracker { private PriorityQueue> good = new PriorityQueue<>( @@ -248,6 +256,8 @@ class SORTracker { */ ``` +#### C++ + ```cpp using pis = pair; diff --git a/solution/2100-2199/2103.Rings and Rods/README.md b/solution/2100-2199/2103.Rings and Rods/README.md index 13feef64e69ac..d3b05845655ac 100644 --- a/solution/2100-2199/2103.Rings and Rods/README.md +++ b/solution/2100-2199/2103.Rings and Rods/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python class Solution: def countPoints(self, rings: str) -> int: @@ -107,6 +109,8 @@ class Solution: return mask.count(7) ``` +#### Java + ```java class Solution { public int countPoints(String rings) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func countPoints(rings string) (ans int) { d := ['Z']int{'R': 1, 'G': 2, 'B': 4} @@ -165,6 +173,8 @@ func countPoints(rings string) (ans int) { } ``` +#### TypeScript + ```ts function countPoints(rings: string): number { const idx = (c: string) => c.charCodeAt(0) - 'A'.charCodeAt(0); @@ -182,6 +192,8 @@ function countPoints(rings: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_points(rings: String) -> i32 { @@ -208,6 +220,8 @@ impl Solution { } ``` +#### C + ```c int countPoints(char* rings) { int d['Z']; @@ -246,6 +260,8 @@ int countPoints(char* rings) { +#### TypeScript + ```ts function countPoints(rings: string): number { let c = 0; diff --git a/solution/2100-2199/2103.Rings and Rods/README_EN.md b/solution/2100-2199/2103.Rings and Rods/README_EN.md index 727cecac333dc..0717bc4c864b4 100644 --- a/solution/2100-2199/2103.Rings and Rods/README_EN.md +++ b/solution/2100-2199/2103.Rings and Rods/README_EN.md @@ -93,6 +93,8 @@ The time complexity is $O(n)$, and the space complexity is $O(|\Sigma|)$, where +#### Python3 + ```python class Solution: def countPoints(self, rings: str) -> int: @@ -105,6 +107,8 @@ class Solution: return mask.count(7) ``` +#### Java + ```java class Solution { public int countPoints(String rings) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func countPoints(rings string) (ans int) { d := ['Z']int{'R': 1, 'G': 2, 'B': 4} @@ -163,6 +171,8 @@ func countPoints(rings string) (ans int) { } ``` +#### TypeScript + ```ts function countPoints(rings: string): number { const idx = (c: string) => c.charCodeAt(0) - 'A'.charCodeAt(0); @@ -180,6 +190,8 @@ function countPoints(rings: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_points(rings: String) -> i32 { @@ -206,6 +218,8 @@ impl Solution { } ``` +#### C + ```c int countPoints(char* rings) { int d['Z']; @@ -244,6 +258,8 @@ int countPoints(char* rings) { +#### TypeScript + ```ts function countPoints(rings: string): number { let c = 0; diff --git a/solution/2100-2199/2104.Sum of Subarray Ranges/README.md b/solution/2100-2199/2104.Sum of Subarray Ranges/README.md index 074781f315c9b..d5f1462b8f46e 100644 --- a/solution/2100-2199/2104.Sum of Subarray Ranges/README.md +++ b/solution/2100-2199/2104.Sum of Subarray Ranges/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class Solution: def subArrayRanges(self, nums: List[int]) -> int: @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long subArrayRanges(int[] nums) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func subArrayRanges(nums []int) int64 { var ans int64 @@ -160,6 +168,8 @@ func subArrayRanges(nums []int) int64 { } ``` +#### TypeScript + ```ts function subArrayRanges(nums: number[]): number { const n = nums.length; @@ -177,6 +187,8 @@ function subArrayRanges(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn sub_array_ranges(nums: Vec) -> i64 { @@ -218,6 +230,8 @@ impl Solution { +#### Python3 + ```python class Solution: def subArrayRanges(self, nums: List[int]) -> int: @@ -246,6 +260,8 @@ class Solution: return mx + mi ``` +#### Java + ```java class Solution { public long subArrayRanges(int[] nums) { @@ -292,6 +308,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -327,6 +345,8 @@ public: }; ``` +#### Go + ```go func subArrayRanges(nums []int) int64 { f := func(nums []int) int64 { diff --git a/solution/2100-2199/2104.Sum of Subarray Ranges/README_EN.md b/solution/2100-2199/2104.Sum of Subarray Ranges/README_EN.md index 0fef2a2f50213..291578e904959 100644 --- a/solution/2100-2199/2104.Sum of Subarray Ranges/README_EN.md +++ b/solution/2100-2199/2104.Sum of Subarray Ranges/README_EN.md @@ -85,6 +85,8 @@ So the sum of all ranges is 0 + 0 + 0 + 2 + 0 + 2 = 4. +#### Python3 + ```python class Solution: def subArrayRanges(self, nums: List[int]) -> int: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long subArrayRanges(int[] nums) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func subArrayRanges(nums []int) int64 { var ans int64 @@ -151,6 +159,8 @@ func subArrayRanges(nums []int) int64 { } ``` +#### TypeScript + ```ts function subArrayRanges(nums: number[]): number { const n = nums.length; @@ -168,6 +178,8 @@ function subArrayRanges(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn sub_array_ranges(nums: Vec) -> i64 { @@ -197,6 +209,8 @@ impl Solution { +#### Python3 + ```python class Solution: def subArrayRanges(self, nums: List[int]) -> int: @@ -225,6 +239,8 @@ class Solution: return mx + mi ``` +#### Java + ```java class Solution { public long subArrayRanges(int[] nums) { @@ -271,6 +287,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -306,6 +324,8 @@ public: }; ``` +#### Go + ```go func subArrayRanges(nums []int) int64 { f := func(nums []int) int64 { diff --git a/solution/2100-2199/2105.Watering Plants II/README.md b/solution/2100-2199/2105.Watering Plants II/README.md index 41ef66898cbbf..0e26c1bfe8e92 100644 --- a/solution/2100-2199/2105.Watering Plants II/README.md +++ b/solution/2100-2199/2105.Watering Plants II/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class Solution: def minimumRefill(self, plants: List[int], capacityA: int, capacityB: int) -> int: @@ -116,6 +118,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumRefill(int[] plants, int capacityA, int capacityB) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func minimumRefill(plants []int, capacityA int, capacityB int) (ans int) { a, b := capacityA, capacityB @@ -188,6 +196,8 @@ func minimumRefill(plants []int, capacityA int, capacityB int) (ans int) { } ``` +#### TypeScript + ```ts function minimumRefill(plants: number[], capacityA: number, capacityB: number): number { let [a, b] = [capacityA, capacityB]; @@ -210,6 +220,8 @@ function minimumRefill(plants: number[], capacityA: number, capacityB: number): } ``` +#### Rust + ```rust impl Solution { pub fn minimum_refill(plants: Vec, capacity_a: i32, capacity_b: i32) -> i32 { diff --git a/solution/2100-2199/2105.Watering Plants II/README_EN.md b/solution/2100-2199/2105.Watering Plants II/README_EN.md index ff0bcf07e9ea8..9667b8f70b252 100644 --- a/solution/2100-2199/2105.Watering Plants II/README_EN.md +++ b/solution/2100-2199/2105.Watering Plants II/README_EN.md @@ -97,6 +97,8 @@ The time complexity is $O(n)$, where $n$ is the length of the plant array. The s +#### Python3 + ```python class Solution: def minimumRefill(self, plants: List[int], capacityA: int, capacityB: int) -> int: @@ -117,6 +119,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumRefill(int[] plants, int capacityA, int capacityB) { @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go func minimumRefill(plants []int, capacityA int, capacityB int) (ans int) { a, b := capacityA, capacityB @@ -189,6 +197,8 @@ func minimumRefill(plants []int, capacityA int, capacityB int) (ans int) { } ``` +#### TypeScript + ```ts function minimumRefill(plants: number[], capacityA: number, capacityB: number): number { let [a, b] = [capacityA, capacityB]; @@ -211,6 +221,8 @@ function minimumRefill(plants: number[], capacityA: number, capacityB: number): } ``` +#### Rust + ```rust impl Solution { pub fn minimum_refill(plants: Vec, capacity_a: i32, capacity_b: i32) -> i32 { diff --git a/solution/2100-2199/2106.Maximum Fruits Harvested After at Most K Steps/README.md b/solution/2100-2199/2106.Maximum Fruits Harvested After at Most K Steps/README.md index 8ad2ede6b36d1..d487c6ae2cdbf 100644 --- a/solution/2100-2199/2106.Maximum Fruits Harvested After at Most K Steps/README.md +++ b/solution/2100-2199/2106.Maximum Fruits Harvested After at Most K Steps/README.md @@ -108,6 +108,8 @@ tags: +#### Python3 + ```python class Solution: def maxTotalFruits(self, fruits: List[List[int]], startPos: int, k: int) -> int: @@ -127,6 +129,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxTotalFruits(int[][] fruits, int startPos, int k) { @@ -147,6 +151,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func maxTotalFruits(fruits [][]int, startPos int, k int) (ans int) { var s, i int @@ -187,6 +195,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function maxTotalFruits(fruits: number[][], startPos: number, k: number): number { let ans = 0; diff --git a/solution/2100-2199/2106.Maximum Fruits Harvested After at Most K Steps/README_EN.md b/solution/2100-2199/2106.Maximum Fruits Harvested After at Most K Steps/README_EN.md index 3d39577e611af..3f9a05e1dfb76 100644 --- a/solution/2100-2199/2106.Maximum Fruits Harvested After at Most K Steps/README_EN.md +++ b/solution/2100-2199/2106.Maximum Fruits Harvested After at Most K Steps/README_EN.md @@ -86,6 +86,8 @@ You can move at most k = 2 steps and cannot reach any position with fruits. +#### Python3 + ```python class Solution: def maxTotalFruits(self, fruits: List[List[int]], startPos: int, k: int) -> int: @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxTotalFruits(int[][] fruits, int startPos, int k) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func maxTotalFruits(fruits [][]int, startPos int, k int) (ans int) { var s, i int @@ -165,6 +173,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function maxTotalFruits(fruits: number[][], startPos: number, k: number): number { let ans = 0; diff --git a/solution/2100-2199/2107.Number of Unique Flavors After Sharing K Candies/README.md b/solution/2100-2199/2107.Number of Unique Flavors After Sharing K Candies/README.md index db1a343b7199c..3dc5f50c0b886 100644 --- a/solution/2100-2199/2107.Number of Unique Flavors After Sharing K Candies/README.md +++ b/solution/2100-2199/2107.Number of Unique Flavors After Sharing K Candies/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def shareCandies(self, candies: List[int], k: int) -> int: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int shareCandies(int[] candies, int k) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func shareCandies(candies []int, k int) (ans int) { cnt := map[int]int{} @@ -163,6 +171,8 @@ func shareCandies(candies []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function shareCandies(candies: number[], k: number): number { const cnt: Map = new Map(); @@ -182,6 +192,8 @@ function shareCandies(candies: number[], k: number): number { } ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/2100-2199/2107.Number of Unique Flavors After Sharing K Candies/README_EN.md b/solution/2100-2199/2107.Number of Unique Flavors After Sharing K Candies/README_EN.md index 64de86f868b70..015b016e29833 100644 --- a/solution/2100-2199/2107.Number of Unique Flavors After Sharing K Candies/README_EN.md +++ b/solution/2100-2199/2107.Number of Unique Flavors After Sharing K Candies/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def shareCandies(self, candies: List[int], k: int) -> int: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int shareCandies(int[] candies, int k) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func shareCandies(candies []int, k int) (ans int) { cnt := map[int]int{} @@ -162,6 +170,8 @@ func shareCandies(candies []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function shareCandies(candies: number[], k: number): number { const cnt: Map = new Map(); @@ -181,6 +191,8 @@ function shareCandies(candies: number[], k: number): number { } ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/2100-2199/2108.Find First Palindromic String in the Array/README.md b/solution/2100-2199/2108.Find First Palindromic String in the Array/README.md index 431e61737818e..b478b56af3736 100644 --- a/solution/2100-2199/2108.Find First Palindromic String in the Array/README.md +++ b/solution/2100-2199/2108.Find First Palindromic String in the Array/README.md @@ -74,12 +74,16 @@ tags: +#### Python3 + ```python class Solution: def firstPalindrome(self, words: List[str]) -> str: return next((w for w in words if w == w[::-1]), "") ``` +#### Java + ```java class Solution { public String firstPalindrome(String[] words) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func firstPalindrome(words []string) string { for _, w := range words { @@ -136,6 +144,8 @@ func firstPalindrome(words []string) string { } ``` +#### TypeScript + ```ts function firstPalindrome(words: string[]): string { for (const word of words) { @@ -156,6 +166,8 @@ function firstPalindrome(words: string[]): string { } ``` +#### Rust + ```rust impl Solution { pub fn first_palindrome(words: Vec) -> String { @@ -179,6 +191,8 @@ impl Solution { } ``` +#### C + ```c char* firstPalindrome(char** words, int wordsSize) { for (int i = 0; i < wordsSize; i++) { diff --git a/solution/2100-2199/2108.Find First Palindromic String in the Array/README_EN.md b/solution/2100-2199/2108.Find First Palindromic String in the Array/README_EN.md index 17ba8b523893c..c4678255a54a6 100644 --- a/solution/2100-2199/2108.Find First Palindromic String in the Array/README_EN.md +++ b/solution/2100-2199/2108.Find First Palindromic String in the Array/README_EN.md @@ -69,12 +69,16 @@ Note that "racecar" is also palindromic, but it is not the first. +#### Python3 + ```python class Solution: def firstPalindrome(self, words: List[str]) -> str: return next((w for w in words if w == w[::-1]), "") ``` +#### Java + ```java class Solution { public String firstPalindrome(String[] words) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func firstPalindrome(words []string) string { for _, w := range words { @@ -131,6 +139,8 @@ func firstPalindrome(words []string) string { } ``` +#### TypeScript + ```ts function firstPalindrome(words: string[]): string { for (const word of words) { @@ -151,6 +161,8 @@ function firstPalindrome(words: string[]): string { } ``` +#### Rust + ```rust impl Solution { pub fn first_palindrome(words: Vec) -> String { @@ -174,6 +186,8 @@ impl Solution { } ``` +#### C + ```c char* firstPalindrome(char** words, int wordsSize) { for (int i = 0; i < wordsSize; i++) { diff --git a/solution/2100-2199/2109.Adding Spaces to a String/README.md b/solution/2100-2199/2109.Adding Spaces to a String/README.md index 3741bddf94020..caac6d01969bd 100644 --- a/solution/2100-2199/2109.Adding Spaces to a String/README.md +++ b/solution/2100-2199/2109.Adding Spaces to a String/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def addSpaces(self, s: str, spaces: List[int]) -> str: @@ -101,6 +103,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String addSpaces(String s, int[] spaces) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func addSpaces(s string, spaces []int) string { var ans []byte @@ -148,6 +156,8 @@ func addSpaces(s string, spaces []int) string { } ``` +#### TypeScript + ```ts function addSpaces(s: string, spaces: number[]): string { let ans = ''; @@ -172,6 +182,8 @@ function addSpaces(s: string, spaces: number[]): string { +#### Python3 + ```python class Solution: def addSpaces(self, s: str, spaces: List[int]) -> str: diff --git a/solution/2100-2199/2109.Adding Spaces to a String/README_EN.md b/solution/2100-2199/2109.Adding Spaces to a String/README_EN.md index 12f09338fd85f..a742a247c315f 100644 --- a/solution/2100-2199/2109.Adding Spaces to a String/README_EN.md +++ b/solution/2100-2199/2109.Adding Spaces to a String/README_EN.md @@ -80,6 +80,8 @@ We are also able to place spaces before the first character of the string. +#### Python3 + ```python class Solution: def addSpaces(self, s: str, spaces: List[int]) -> str: @@ -93,6 +95,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String addSpaces(String s, int[] spaces) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func addSpaces(s string, spaces []int) string { var ans []byte @@ -140,6 +148,8 @@ func addSpaces(s string, spaces []int) string { } ``` +#### TypeScript + ```ts function addSpaces(s: string, spaces: number[]): string { let ans = ''; @@ -164,6 +174,8 @@ function addSpaces(s: string, spaces: number[]): string { +#### Python3 + ```python class Solution: def addSpaces(self, s: str, spaces: List[int]) -> str: diff --git a/solution/2100-2199/2110.Number of Smooth Descent Periods of a Stock/README.md b/solution/2100-2199/2110.Number of Smooth Descent Periods of a Stock/README.md index f5af9d4fde230..f78c4a37e6b6e 100644 --- a/solution/2100-2199/2110.Number of Smooth Descent Periods of a Stock/README.md +++ b/solution/2100-2199/2110.Number of Smooth Descent Periods of a Stock/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def getDescentPeriods(self, prices: List[int]) -> int: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long getDescentPeriods(int[] prices) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func getDescentPeriods(prices []int) (ans int64) { n := len(prices) @@ -148,6 +156,8 @@ func getDescentPeriods(prices []int) (ans int64) { } ``` +#### TypeScript + ```ts function getDescentPeriods(prices: number[]): number { let ans = 0; diff --git a/solution/2100-2199/2110.Number of Smooth Descent Periods of a Stock/README_EN.md b/solution/2100-2199/2110.Number of Smooth Descent Periods of a Stock/README_EN.md index 774fb62fd53c8..b0fa9ebd0644e 100644 --- a/solution/2100-2199/2110.Number of Smooth Descent Periods of a Stock/README_EN.md +++ b/solution/2100-2199/2110.Number of Smooth Descent Periods of a Stock/README_EN.md @@ -72,6 +72,8 @@ Note that [8,6] is not a smooth descent period as 8 - 6 ≠ 1. +#### Python3 + ```python class Solution: def getDescentPeriods(self, prices: List[int]) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long getDescentPeriods(int[] prices) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func getDescentPeriods(prices []int) (ans int64) { n := len(prices) @@ -139,6 +147,8 @@ func getDescentPeriods(prices []int) (ans int64) { } ``` +#### TypeScript + ```ts function getDescentPeriods(prices: number[]): number { let ans = 0; diff --git a/solution/2100-2199/2111.Minimum Operations to Make the Array K-Increasing/README.md b/solution/2100-2199/2111.Minimum Operations to Make the Array K-Increasing/README.md index afe8d48922895..819631111e659 100644 --- a/solution/2100-2199/2111.Minimum Operations to Make the Array K-Increasing/README.md +++ b/solution/2100-2199/2111.Minimum Operations to Make the Array K-Increasing/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def kIncreasing(self, arr: List[int], k: int) -> int: @@ -109,6 +111,8 @@ class Solution: return sum(lis(arr[i::k]) for i in range(k)) ``` +#### Java + ```java class Solution { public int kIncreasing(int[] arr, int k) { @@ -152,6 +156,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -179,6 +185,8 @@ public: }; ``` +#### Go + ```go func kIncreasing(arr []int, k int) int { searchRight := func(arr []int, x int) int { diff --git a/solution/2100-2199/2111.Minimum Operations to Make the Array K-Increasing/README_EN.md b/solution/2100-2199/2111.Minimum Operations to Make the Array K-Increasing/README_EN.md index 4681ed4ae5dc5..358616888761d 100644 --- a/solution/2100-2199/2111.Minimum Operations to Make the Array K-Increasing/README_EN.md +++ b/solution/2100-2199/2111.Minimum Operations to Make the Array K-Increasing/README_EN.md @@ -94,6 +94,8 @@ Note that there can be other ways to make the array K-increasing, but none of th +#### Python3 + ```python class Solution: def kIncreasing(self, arr: List[int], k: int) -> int: @@ -110,6 +112,8 @@ class Solution: return sum(lis(arr[i::k]) for i in range(k)) ``` +#### Java + ```java class Solution { public int kIncreasing(int[] arr, int k) { @@ -153,6 +157,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -180,6 +186,8 @@ public: }; ``` +#### Go + ```go func kIncreasing(arr []int, k int) int { searchRight := func(arr []int, x int) int { diff --git a/solution/2100-2199/2112.The Airport With the Most Traffic/README.md b/solution/2100-2199/2112.The Airport With the Most Traffic/README.md index 673e45c4c9179..5a47b5967f599 100644 --- a/solution/2100-2199/2112.The Airport With the Most Traffic/README.md +++ b/solution/2100-2199/2112.The Airport With the Most Traffic/README.md @@ -107,6 +107,8 @@ Flights 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2100-2199/2112.The Airport With the Most Traffic/README_EN.md b/solution/2100-2199/2112.The Airport With the Most Traffic/README_EN.md index 9e0daa5ade2cc..ea9805223e837 100644 --- a/solution/2100-2199/2112.The Airport With the Most Traffic/README_EN.md +++ b/solution/2100-2199/2112.The Airport With the Most Traffic/README_EN.md @@ -107,6 +107,8 @@ The airports with the most traffic are airports 1, 2, 3, and 4. +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2100-2199/2113.Elements in Array After Removing and Replacing Elements/README.md b/solution/2100-2199/2113.Elements in Array After Removing and Replacing Elements/README.md index be452bbee9ef1..ae54582bb58a8 100644 --- a/solution/2100-2199/2113.Elements in Array After Removing and Replacing Elements/README.md +++ b/solution/2100-2199/2113.Elements in Array After Removing and Replacing Elements/README.md @@ -101,6 +101,8 @@ tags: +#### Python3 + ```python class Solution: def elementInNums(self, nums: List[int], queries: List[List[int]]) -> List[int]: @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] elementInNums(int[] nums, int[][] queries) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func elementInNums(nums []int, queries [][]int) []int { n, m := len(nums), len(queries) diff --git a/solution/2100-2199/2113.Elements in Array After Removing and Replacing Elements/README_EN.md b/solution/2100-2199/2113.Elements in Array After Removing and Replacing Elements/README_EN.md index a365d7ee2bec6..7a429981002a5 100644 --- a/solution/2100-2199/2113.Elements in Array After Removing and Replacing Elements/README_EN.md +++ b/solution/2100-2199/2113.Elements in Array After Removing and Replacing Elements/README_EN.md @@ -90,6 +90,8 @@ At minute 3, nums[0] does not exist. +#### Python3 + ```python class Solution: def elementInNums(self, nums: List[int], queries: List[List[int]]) -> List[int]: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] elementInNums(int[] nums, int[][] queries) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func elementInNums(nums []int, queries [][]int) []int { n, m := len(nums), len(queries) diff --git a/solution/2100-2199/2114.Maximum Number of Words Found in Sentences/README.md b/solution/2100-2199/2114.Maximum Number of Words Found in Sentences/README.md index bb0112f845906..4d90a8aa09cba 100644 --- a/solution/2100-2199/2114.Maximum Number of Words Found in Sentences/README.md +++ b/solution/2100-2199/2114.Maximum Number of Words Found in Sentences/README.md @@ -72,12 +72,16 @@ tags: +#### Python3 + ```python class Solution: def mostWordsFound(self, sentences: List[str]) -> int: return 1 + max(s.count(' ') for s in sentences) ``` +#### Java + ```java class Solution { public int mostWordsFound(String[] sentences) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func mostWordsFound(sentences []string) (ans int) { for _, s := range sentences { @@ -122,6 +130,8 @@ func mostWordsFound(sentences []string) (ans int) { } ``` +#### TypeScript + ```ts function mostWordsFound(sentences: string[]): number { return sentences.reduce( @@ -135,6 +145,8 @@ function mostWordsFound(sentences: string[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn most_words_found(sentences: Vec) -> i32 { @@ -153,6 +165,8 @@ impl Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) diff --git a/solution/2100-2199/2114.Maximum Number of Words Found in Sentences/README_EN.md b/solution/2100-2199/2114.Maximum Number of Words Found in Sentences/README_EN.md index 7e3a85aa1446f..dc152eb95ba22 100644 --- a/solution/2100-2199/2114.Maximum Number of Words Found in Sentences/README_EN.md +++ b/solution/2100-2199/2114.Maximum Number of Words Found in Sentences/README_EN.md @@ -68,12 +68,16 @@ In this example, the second and third sentences (underlined) have the same numbe +#### Python3 + ```python class Solution: def mostWordsFound(self, sentences: List[str]) -> int: return 1 + max(s.count(' ') for s in sentences) ``` +#### Java + ```java class Solution { public int mostWordsFound(String[] sentences) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func mostWordsFound(sentences []string) (ans int) { for _, s := range sentences { @@ -118,6 +126,8 @@ func mostWordsFound(sentences []string) (ans int) { } ``` +#### TypeScript + ```ts function mostWordsFound(sentences: string[]): number { return sentences.reduce( @@ -131,6 +141,8 @@ function mostWordsFound(sentences: string[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn most_words_found(sentences: Vec) -> i32 { @@ -149,6 +161,8 @@ impl Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) diff --git a/solution/2100-2199/2115.Find All Possible Recipes from Given Supplies/README.md b/solution/2100-2199/2115.Find All Possible Recipes from Given Supplies/README.md index f5fb1aa1d922f..0e78daaeb048e 100644 --- a/solution/2100-2199/2115.Find All Possible Recipes from Given Supplies/README.md +++ b/solution/2100-2199/2115.Find All Possible Recipes from Given Supplies/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def findAllRecipes( @@ -117,6 +119,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List findAllRecipes( @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -185,6 +191,8 @@ public: }; ``` +#### Go + ```go func findAllRecipes(recipes []string, ingredients [][]string, supplies []string) []string { g := map[string][]string{} diff --git a/solution/2100-2199/2115.Find All Possible Recipes from Given Supplies/README_EN.md b/solution/2100-2199/2115.Find All Possible Recipes from Given Supplies/README_EN.md index 172794310064f..90682d8814ee9 100644 --- a/solution/2100-2199/2115.Find All Possible Recipes from Given Supplies/README_EN.md +++ b/solution/2100-2199/2115.Find All Possible Recipes from Given Supplies/README_EN.md @@ -84,6 +84,8 @@ We can create "burger" since we have the ingredient "meat" a +#### Python3 + ```python class Solution: def findAllRecipes( @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List findAllRecipes( @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go func findAllRecipes(recipes []string, ingredients [][]string, supplies []string) []string { g := map[string][]string{} diff --git a/solution/2100-2199/2116.Check if a Parentheses String Can Be Valid/README.md b/solution/2100-2199/2116.Check if a Parentheses String Can Be Valid/README.md index 70f5435c84c12..777169a24ad6b 100644 --- a/solution/2100-2199/2116.Check if a Parentheses String Can Be Valid/README.md +++ b/solution/2100-2199/2116.Check if a Parentheses String Can Be Valid/README.md @@ -103,6 +103,8 @@ tags: +#### Python3 + ```python class Solution: def canBeValid(self, s: str, locked: str) -> bool: @@ -128,6 +130,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean canBeValid(String s, String locked) { @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go func canBeValid(s string, locked string) bool { n := len(s) diff --git a/solution/2100-2199/2116.Check if a Parentheses String Can Be Valid/README_EN.md b/solution/2100-2199/2116.Check if a Parentheses String Can Be Valid/README_EN.md index 4beda83e79dc4..e131386022afb 100644 --- a/solution/2100-2199/2116.Check if a Parentheses String Can Be Valid/README_EN.md +++ b/solution/2100-2199/2116.Check if a Parentheses String Can Be Valid/README_EN.md @@ -83,6 +83,8 @@ Changing s[0] to either '(' or ')' will not make s valid. +#### Python3 + ```python class Solution: def canBeValid(self, s: str, locked: str) -> bool: @@ -108,6 +110,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean canBeValid(String s, String locked) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go func canBeValid(s string, locked string) bool { n := len(s) diff --git a/solution/2100-2199/2117.Abbreviating the Product of a Range/README.md b/solution/2100-2199/2117.Abbreviating the Product of a Range/README.md index 226ad14e3a0bc..be7fca6ed0487 100644 --- a/solution/2100-2199/2117.Abbreviating the Product of a Range/README.md +++ b/solution/2100-2199/2117.Abbreviating the Product of a Range/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python import numpy @@ -131,6 +133,8 @@ class Solution: return str(pre) + "..." + str(suf).zfill(5) + "e" + str(c) ``` +#### Java + ```java class Solution { @@ -172,6 +176,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -215,6 +221,8 @@ public: }; ``` +#### Go + ```go func abbreviateProduct(left int, right int) string { cnt2, cnt5 := 0, 0 @@ -269,6 +277,8 @@ func abbreviateProduct(left int, right int) string { +#### Python3 + ```python class Solution: def abbreviateProduct(self, left: int, right: int) -> str: diff --git a/solution/2100-2199/2117.Abbreviating the Product of a Range/README_EN.md b/solution/2100-2199/2117.Abbreviating the Product of a Range/README_EN.md index e0195bab78777..4327a39cdbc67 100644 --- a/solution/2100-2199/2117.Abbreviating the Product of a Range/README_EN.md +++ b/solution/2100-2199/2117.Abbreviating the Product of a Range/README_EN.md @@ -92,6 +92,8 @@ Hence, the abbreviated product is "399168e2". +#### Python3 + ```python import numpy @@ -128,6 +130,8 @@ class Solution: return str(pre) + "..." + str(suf).zfill(5) + "e" + str(c) ``` +#### Java + ```java class Solution { @@ -169,6 +173,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -212,6 +218,8 @@ public: }; ``` +#### Go + ```go func abbreviateProduct(left int, right int) string { cnt2, cnt5 := 0, 0 @@ -266,6 +274,8 @@ func abbreviateProduct(left int, right int) string { +#### Python3 + ```python class Solution: def abbreviateProduct(self, left: int, right: int) -> str: diff --git a/solution/2100-2199/2118.Build the Equation/README.md b/solution/2100-2199/2118.Build the Equation/README.md index aa8d69e2f3b69..f1827a35b3091 100644 --- a/solution/2100-2199/2118.Build the Equation/README.md +++ b/solution/2100-2199/2118.Build the Equation/README.md @@ -118,6 +118,8 @@ Terms 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2100-2199/2118.Build the Equation/README_EN.md b/solution/2100-2199/2118.Build the Equation/README_EN.md index 82f01ecf8bbb1..4678cf1f62e3a 100644 --- a/solution/2100-2199/2118.Build the Equation/README_EN.md +++ b/solution/2100-2199/2118.Build the Equation/README_EN.md @@ -116,6 +116,8 @@ Terms table: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2100-2199/2119.A Number After a Double Reversal/README.md b/solution/2100-2199/2119.A Number After a Double Reversal/README.md index 1425e5c01ed1f..117583e9746f4 100644 --- a/solution/2100-2199/2119.A Number After a Double Reversal/README.md +++ b/solution/2100-2199/2119.A Number After a Double Reversal/README.md @@ -66,12 +66,16 @@ tags: +#### Python3 + ```python class Solution: def isSameAfterReversals(self, num: int) -> bool: return num == 0 or num % 10 != 0 ``` +#### Java + ```java class Solution { public boolean isSameAfterReversals(int num) { @@ -80,6 +84,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -89,6 +95,8 @@ public: }; ``` +#### Go + ```go func isSameAfterReversals(num int) bool { return num == 0 || num%10 != 0 diff --git a/solution/2100-2199/2119.A Number After a Double Reversal/README_EN.md b/solution/2100-2199/2119.A Number After a Double Reversal/README_EN.md index f8ad201bd9aab..b8c12ddd1000e 100644 --- a/solution/2100-2199/2119.A Number After a Double Reversal/README_EN.md +++ b/solution/2100-2199/2119.A Number After a Double Reversal/README_EN.md @@ -68,12 +68,16 @@ tags: +#### Python3 + ```python class Solution: def isSameAfterReversals(self, num: int) -> bool: return num == 0 or num % 10 != 0 ``` +#### Java + ```java class Solution { public boolean isSameAfterReversals(int num) { @@ -82,6 +86,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -91,6 +97,8 @@ public: }; ``` +#### Go + ```go func isSameAfterReversals(num int) bool { return num == 0 || num%10 != 0 diff --git a/solution/2100-2199/2120.Execution of All Suffix Instructions Staying in a Grid/README.md b/solution/2100-2199/2120.Execution of All Suffix Instructions Staying in a Grid/README.md index 6823c4aec743f..abfeb35a659e8 100644 --- a/solution/2100-2199/2120.Execution of All Suffix Instructions Staying in a Grid/README.md +++ b/solution/2100-2199/2120.Execution of All Suffix Instructions Staying in a Grid/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class Solution: def executeInstructions(self, n: int, startPos: List[int], s: str) -> List[int]: @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] executeInstructions(int n, int[] startPos, String s) { @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go func executeInstructions(n int, startPos []int, s string) []int { m := len(s) @@ -204,6 +212,8 @@ func executeInstructions(n int, startPos []int, s string) []int { } ``` +#### TypeScript + ```ts function executeInstructions(n: number, startPos: number[], s: string): number[] { const m = s.length; @@ -232,6 +242,8 @@ function executeInstructions(n: number, startPos: number[], s: string): number[] } ``` +#### Rust + ```rust impl Solution { pub fn execute_instructions(n: i32, start_pos: Vec, s: String) -> Vec { @@ -269,6 +281,8 @@ impl Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). diff --git a/solution/2100-2199/2120.Execution of All Suffix Instructions Staying in a Grid/README_EN.md b/solution/2100-2199/2120.Execution of All Suffix Instructions Staying in a Grid/README_EN.md index b29148d76b1d8..428192ee2df80 100644 --- a/solution/2100-2199/2120.Execution of All Suffix Instructions Staying in a Grid/README_EN.md +++ b/solution/2100-2199/2120.Execution of All Suffix Instructions Staying in a Grid/README_EN.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def executeInstructions(self, n: int, startPos: List[int], s: str) -> List[int]: @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] executeInstructions(int n, int[] startPos, String s) { @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func executeInstructions(n int, startPos []int, s string) []int { m := len(s) @@ -196,6 +204,8 @@ func executeInstructions(n int, startPos []int, s string) []int { } ``` +#### TypeScript + ```ts function executeInstructions(n: number, startPos: number[], s: string): number[] { const m = s.length; @@ -224,6 +234,8 @@ function executeInstructions(n: number, startPos: number[], s: string): number[] } ``` +#### Rust + ```rust impl Solution { pub fn execute_instructions(n: i32, start_pos: Vec, s: String) -> Vec { @@ -261,6 +273,8 @@ impl Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). diff --git a/solution/2100-2199/2121.Intervals Between Identical Elements/README.md b/solution/2100-2199/2121.Intervals Between Identical Elements/README.md index dae6fc688b493..893a3ddbe2bd4 100644 --- a/solution/2100-2199/2121.Intervals Between Identical Elements/README.md +++ b/solution/2100-2199/2121.Intervals Between Identical Elements/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def getDistances(self, arr: List[int]) -> List[int]: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long[] getDistances(int[] arr) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func getDistances(arr []int) []int64 { d := make(map[int][]int) diff --git a/solution/2100-2199/2121.Intervals Between Identical Elements/README_EN.md b/solution/2100-2199/2121.Intervals Between Identical Elements/README_EN.md index 748b0180cafdc..489c02e4f3319 100644 --- a/solution/2100-2199/2121.Intervals Between Identical Elements/README_EN.md +++ b/solution/2100-2199/2121.Intervals Between Identical Elements/README_EN.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def getDistances(self, arr: List[int]) -> List[int]: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long[] getDistances(int[] arr) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func getDistances(arr []int) []int64 { d := make(map[int][]int) diff --git a/solution/2100-2199/2122.Recover the Original Array/README.md b/solution/2100-2199/2122.Recover the Original Array/README.md index 7fc1884da1015..958bb9fda7038 100644 --- a/solution/2100-2199/2122.Recover the Original Array/README.md +++ b/solution/2100-2199/2122.Recover the Original Array/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def recoverArray(self, nums: List[int]) -> List[int]: @@ -113,6 +115,8 @@ class Solution: return [] ``` +#### Java + ```java class Solution { public int[] recoverArray(int[] nums) { @@ -153,6 +157,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -179,6 +185,8 @@ public: }; ``` +#### Go + ```go func recoverArray(nums []int) []int { sort.Ints(nums) diff --git a/solution/2100-2199/2122.Recover the Original Array/README_EN.md b/solution/2100-2199/2122.Recover the Original Array/README_EN.md index b17f01bd82e54..b96a6c1b200ba 100644 --- a/solution/2100-2199/2122.Recover the Original Array/README_EN.md +++ b/solution/2100-2199/2122.Recover the Original Array/README_EN.md @@ -87,6 +87,8 @@ The only possible combination is arr = [220] and k = 215. Using them, we get low +#### Python3 + ```python class Solution: def recoverArray(self, nums: List[int]) -> List[int]: @@ -115,6 +117,8 @@ class Solution: return [] ``` +#### Java + ```java class Solution { public int[] recoverArray(int[] nums) { @@ -155,6 +159,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func recoverArray(nums []int) []int { sort.Ints(nums) diff --git a/solution/2100-2199/2123.Minimum Operations to Remove Adjacent Ones in Matrix/README.md b/solution/2100-2199/2123.Minimum Operations to Remove Adjacent Ones in Matrix/README.md index db926337acc88..14780cf154377 100644 --- a/solution/2100-2199/2123.Minimum Operations to Remove Adjacent Ones in Matrix/README.md +++ b/solution/2100-2199/2123.Minimum Operations to Remove Adjacent Ones in Matrix/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def minimumOperations(self, grid: List[List[int]]) -> int: @@ -112,6 +114,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private Map> g = new HashMap<>(); @@ -163,6 +167,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -212,6 +218,8 @@ public: }; ``` +#### Go + ```go func minimumOperations(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -261,6 +269,8 @@ func minimumOperations(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function minimumOperations(grid: number[][]): number { const m = grid.length; diff --git a/solution/2100-2199/2123.Minimum Operations to Remove Adjacent Ones in Matrix/README_EN.md b/solution/2100-2199/2123.Minimum Operations to Remove Adjacent Ones in Matrix/README_EN.md index f40ee6bb98ae2..99187fb7ae7dd 100644 --- a/solution/2100-2199/2123.Minimum Operations to Remove Adjacent Ones in Matrix/README_EN.md +++ b/solution/2100-2199/2123.Minimum Operations to Remove Adjacent Ones in Matrix/README_EN.md @@ -72,6 +72,8 @@ No operations were done so return 0. +#### Python3 + ```python class Solution: def minimumOperations(self, grid: List[List[int]]) -> int: @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private Map> g = new HashMap<>(); @@ -158,6 +162,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -207,6 +213,8 @@ public: }; ``` +#### Go + ```go func minimumOperations(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -256,6 +264,8 @@ func minimumOperations(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function minimumOperations(grid: number[][]): number { const m = grid.length; diff --git a/solution/2100-2199/2124.Check if All A's Appears Before All B's/README.md b/solution/2100-2199/2124.Check if All A's Appears Before All B's/README.md index cc29967746ed1..aa96d404a1291 100644 --- a/solution/2100-2199/2124.Check if All A's Appears Before All B's/README.md +++ b/solution/2100-2199/2124.Check if All A's Appears Before All B's/README.md @@ -73,12 +73,16 @@ tags: +#### Python3 + ```python class Solution: def checkString(self, s: str) -> bool: return "ba" not in s ``` +#### Java + ```java class Solution { public boolean checkString(String s) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -96,6 +102,8 @@ public: }; ``` +#### Go + ```go func checkString(s string) bool { return !strings.Contains(s, "ba") diff --git a/solution/2100-2199/2124.Check if All A's Appears Before All B's/README_EN.md b/solution/2100-2199/2124.Check if All A's Appears Before All B's/README_EN.md index 4ab40ad66e37c..b0315271a3f92 100644 --- a/solution/2100-2199/2124.Check if All A's Appears Before All B's/README_EN.md +++ b/solution/2100-2199/2124.Check if All A's Appears Before All B's/README_EN.md @@ -68,12 +68,16 @@ There are no 'a's, hence, every 'a' appears before every 'b& +#### Python3 + ```python class Solution: def checkString(self, s: str) -> bool: return "ba" not in s ``` +#### Java + ```java class Solution { public boolean checkString(String s) { @@ -82,6 +86,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -91,6 +97,8 @@ public: }; ``` +#### Go + ```go func checkString(s string) bool { return !strings.Contains(s, "ba") diff --git a/solution/2100-2199/2125.Number of Laser Beams in a Bank/README.md b/solution/2100-2199/2125.Number of Laser Beams in a Bank/README.md index 9b0ec690be4ff..c5edf129f898f 100644 --- a/solution/2100-2199/2125.Number of Laser Beams in a Bank/README.md +++ b/solution/2100-2199/2125.Number of Laser Beams in a Bank/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfBeams(self, bank: List[str]) -> int: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numberOfBeams(String[] bank) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func numberOfBeams(bank []string) (ans int) { pre := 0 @@ -151,6 +159,8 @@ func numberOfBeams(bank []string) (ans int) { } ``` +#### TypeScript + ```ts function numberOfBeams(bank: string[]): number { let [ans, pre] = [0, 0]; @@ -165,6 +175,8 @@ function numberOfBeams(bank: string[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn number_of_beams(bank: Vec) -> i32 { @@ -185,6 +197,8 @@ impl Solution { } ``` +#### C + ```c int numberOfBeams(char** bank, int bankSize) { int ans = 0, pre = 0; diff --git a/solution/2100-2199/2125.Number of Laser Beams in a Bank/README_EN.md b/solution/2100-2199/2125.Number of Laser Beams in a Bank/README_EN.md index f558a029ec522..82f880a45b39b 100644 --- a/solution/2100-2199/2125.Number of Laser Beams in a Bank/README_EN.md +++ b/solution/2100-2199/2125.Number of Laser Beams in a Bank/README_EN.md @@ -85,6 +85,8 @@ The time complexity is $O(m \times n)$, where $m$ and $n$ are the number of rows +#### Python3 + ```python class Solution: def numberOfBeams(self, bank: List[str]) -> int: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numberOfBeams(String[] bank) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func numberOfBeams(bank []string) (ans int) { pre := 0 @@ -145,6 +153,8 @@ func numberOfBeams(bank []string) (ans int) { } ``` +#### TypeScript + ```ts function numberOfBeams(bank: string[]): number { let [ans, pre] = [0, 0]; @@ -159,6 +169,8 @@ function numberOfBeams(bank: string[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn number_of_beams(bank: Vec) -> i32 { @@ -179,6 +191,8 @@ impl Solution { } ``` +#### C + ```c int numberOfBeams(char** bank, int bankSize) { int ans = 0, pre = 0; diff --git a/solution/2100-2199/2126.Destroying Asteroids/README.md b/solution/2100-2199/2126.Destroying Asteroids/README.md index 960986907b55c..c4b0908d0a6ca 100644 --- a/solution/2100-2199/2126.Destroying Asteroids/README.md +++ b/solution/2100-2199/2126.Destroying Asteroids/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def asteroidsDestroyed(self, mass: int, asteroids: List[int]) -> bool: @@ -81,6 +83,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean asteroidsDestroyed(int mass, int[] asteroids) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func asteroidsDestroyed(mass int, asteroids []int) bool { m := mass diff --git a/solution/2100-2199/2126.Destroying Asteroids/README_EN.md b/solution/2100-2199/2126.Destroying Asteroids/README_EN.md index 51c3a7c10bfed..e1947b890a9ca 100644 --- a/solution/2100-2199/2126.Destroying Asteroids/README_EN.md +++ b/solution/2100-2199/2126.Destroying Asteroids/README_EN.md @@ -70,6 +70,8 @@ This is less than 23, so a collision would not destroy the last asteroid. +#### Python3 + ```python class Solution: def asteroidsDestroyed(self, mass: int, asteroids: List[int]) -> bool: @@ -81,6 +83,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean asteroidsDestroyed(int mass, int[] asteroids) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func asteroidsDestroyed(mass int, asteroids []int) bool { m := mass diff --git a/solution/2100-2199/2127.Maximum Employees to Be Invited to a Meeting/README.md b/solution/2100-2199/2127.Maximum Employees to Be Invited to a Meeting/README.md index 6e80fb8fae81f..c779a063e554d 100644 --- a/solution/2100-2199/2127.Maximum Employees to Be Invited to a Meeting/README.md +++ b/solution/2100-2199/2127.Maximum Employees to Be Invited to a Meeting/README.md @@ -109,6 +109,8 @@ tags: +#### Python3 + ```python class Solution: def maximumInvitations(self, favorite: List[int]) -> int: @@ -149,6 +151,8 @@ class Solution: return max(max_cycle(favorite), topological_sort(favorite)) ``` +#### Java + ```java class Solution { public int maximumInvitations(int[] favorite) { @@ -211,6 +215,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -263,6 +269,8 @@ public: }; ``` +#### Go + ```go func maximumInvitations(favorite []int) int { a, b := maxCycle(favorite), topologicalSort(favorite) @@ -329,6 +337,8 @@ func topologicalSort(fa []int) int { } ``` +#### TypeScript + ```ts function maximumInvitations(favorite: number[]): number { return Math.max(maxCycle(favorite), topologicalSort(favorite)); diff --git a/solution/2100-2199/2127.Maximum Employees to Be Invited to a Meeting/README_EN.md b/solution/2100-2199/2127.Maximum Employees to Be Invited to a Meeting/README_EN.md index 2c3f4a18baf58..e25ef6a853ac5 100644 --- a/solution/2100-2199/2127.Maximum Employees to Be Invited to a Meeting/README_EN.md +++ b/solution/2100-2199/2127.Maximum Employees to Be Invited to a Meeting/README_EN.md @@ -99,6 +99,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def maximumInvitations(self, favorite: List[int]) -> int: @@ -139,6 +141,8 @@ class Solution: return max(max_cycle(favorite), topological_sort(favorite)) ``` +#### Java + ```java class Solution { public int maximumInvitations(int[] favorite) { @@ -201,6 +205,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -253,6 +259,8 @@ public: }; ``` +#### Go + ```go func maximumInvitations(favorite []int) int { a, b := maxCycle(favorite), topologicalSort(favorite) @@ -319,6 +327,8 @@ func topologicalSort(fa []int) int { } ``` +#### TypeScript + ```ts function maximumInvitations(favorite: number[]): number { return Math.max(maxCycle(favorite), topologicalSort(favorite)); diff --git a/solution/2100-2199/2128.Remove All Ones With Row and Column Flips/README.md b/solution/2100-2199/2128.Remove All Ones With Row and Column Flips/README.md index 3e26428bc3bc6..373fbed95ad97 100644 --- a/solution/2100-2199/2128.Remove All Ones With Row and Column Flips/README.md +++ b/solution/2100-2199/2128.Remove All Ones With Row and Column Flips/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def removeOnes(self, grid: List[List[int]]) -> bool: @@ -101,6 +103,8 @@ class Solution: return len(s) == 1 ``` +#### Java + ```java class Solution { public boolean removeOnes(int[][] grid) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func removeOnes(grid [][]int) bool { s := map[string]bool{} @@ -152,6 +160,8 @@ func removeOnes(grid [][]int) bool { } ``` +#### TypeScript + ```ts function removeOnes(grid: number[][]): boolean { const s = new Set(); diff --git a/solution/2100-2199/2128.Remove All Ones With Row and Column Flips/README_EN.md b/solution/2100-2199/2128.Remove All Ones With Row and Column Flips/README_EN.md index 2aeebbf386032..3eb12f5804665 100644 --- a/solution/2100-2199/2128.Remove All Ones With Row and Column Flips/README_EN.md +++ b/solution/2100-2199/2128.Remove All Ones With Row and Column Flips/README_EN.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def removeOnes(self, grid: List[List[int]]) -> bool: @@ -82,6 +84,8 @@ class Solution: return len(s) == 1 ``` +#### Java + ```java class Solution { public boolean removeOnes(int[][] grid) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func removeOnes(grid [][]int) bool { s := map[string]bool{} @@ -133,6 +141,8 @@ func removeOnes(grid [][]int) bool { } ``` +#### TypeScript + ```ts function removeOnes(grid: number[][]): boolean { const s = new Set(); diff --git a/solution/2100-2199/2129.Capitalize the Title/README.md b/solution/2100-2199/2129.Capitalize the Title/README.md index e7ca760852456..a566485b30723 100644 --- a/solution/2100-2199/2129.Capitalize the Title/README.md +++ b/solution/2100-2199/2129.Capitalize the Title/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def capitalizeTitle(self, title: str) -> str: @@ -86,6 +88,8 @@ class Solution: return " ".join(words) ``` +#### Java + ```java class Solution { public String capitalizeTitle(String title) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func capitalizeTitle(title string) string { title = strings.ToLower(title) @@ -135,6 +143,8 @@ func capitalizeTitle(title string) string { } ``` +#### TypeScript + ```ts function capitalizeTitle(title: string): string { return title @@ -148,6 +158,8 @@ function capitalizeTitle(title: string): string { } ``` +#### C# + ```cs public class Solution { public string CapitalizeTitle(string title) { diff --git a/solution/2100-2199/2129.Capitalize the Title/README_EN.md b/solution/2100-2199/2129.Capitalize the Title/README_EN.md index 0786244456be1..43b08742e5584 100644 --- a/solution/2100-2199/2129.Capitalize the Title/README_EN.md +++ b/solution/2100-2199/2129.Capitalize the Title/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python class Solution: def capitalizeTitle(self, title: str) -> str: @@ -87,6 +89,8 @@ class Solution: return " ".join(words) ``` +#### Java + ```java class Solution { public String capitalizeTitle(String title) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func capitalizeTitle(title string) string { title = strings.ToLower(title) @@ -136,6 +144,8 @@ func capitalizeTitle(title string) string { } ``` +#### TypeScript + ```ts function capitalizeTitle(title: string): string { return title @@ -147,6 +157,8 @@ function capitalizeTitle(title: string): string { } ``` +#### C# + ```cs public class Solution { public string CapitalizeTitle(string title) { diff --git a/solution/2100-2199/2130.Maximum Twin Sum of a Linked List/README.md b/solution/2100-2199/2130.Maximum Twin Sum of a Linked List/README.md index 492b27e65fab9..89f9b62d1dee6 100644 --- a/solution/2100-2199/2130.Maximum Twin Sum of a Linked List/README.md +++ b/solution/2100-2199/2130.Maximum Twin Sum of a Linked List/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -104,6 +106,8 @@ class Solution: return max(s[i] + s[-(i + 1)] for i in range(n >> 1)) ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -176,6 +184,8 @@ func pairSum(head *ListNode) int { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -205,6 +215,8 @@ function pairSum(head: ListNode | null): number { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -253,6 +265,8 @@ impl Solution { +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -286,6 +300,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -332,6 +348,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -379,6 +397,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -417,6 +437,8 @@ func pairSum(head *ListNode) int { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/2100-2199/2130.Maximum Twin Sum of a Linked List/README_EN.md b/solution/2100-2199/2130.Maximum Twin Sum of a Linked List/README_EN.md index f8c86e2786f19..689cc69226e20 100644 --- a/solution/2100-2199/2130.Maximum Twin Sum of a Linked List/README_EN.md +++ b/solution/2100-2199/2130.Maximum Twin Sum of a Linked List/README_EN.md @@ -81,6 +81,8 @@ There is only one node with a twin in the linked list having twin sum of 1 + 100 +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -97,6 +99,8 @@ class Solution: return max(s[i] + s[-(i + 1)] for i in range(n >> 1)) ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -169,6 +177,8 @@ func pairSum(head *ListNode) int { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -198,6 +208,8 @@ function pairSum(head: ListNode | null): number { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -244,6 +256,8 @@ impl Solution { +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -277,6 +291,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -323,6 +339,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -370,6 +388,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -408,6 +428,8 @@ func pairSum(head *ListNode) int { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/2100-2199/2131.Longest Palindrome by Concatenating Two Letter Words/README.md b/solution/2100-2199/2131.Longest Palindrome by Concatenating Two Letter Words/README.md index 3f7ad30a28a1a..16eadec79aa72 100644 --- a/solution/2100-2199/2131.Longest Palindrome by Concatenating Two Letter Words/README.md +++ b/solution/2100-2199/2131.Longest Palindrome by Concatenating Two Letter Words/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def longestPalindrome(self, words: List[str]) -> int: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestPalindrome(String[] words) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func longestPalindrome(words []string) int { cnt := map[string]int{} diff --git a/solution/2100-2199/2131.Longest Palindrome by Concatenating Two Letter Words/README_EN.md b/solution/2100-2199/2131.Longest Palindrome by Concatenating Two Letter Words/README_EN.md index f4658ea04db3d..e947717112683 100644 --- a/solution/2100-2199/2131.Longest Palindrome by Concatenating Two Letter Words/README_EN.md +++ b/solution/2100-2199/2131.Longest Palindrome by Concatenating Two Letter Words/README_EN.md @@ -77,6 +77,8 @@ Note that "ll" is another longest palindrome that can be created, and +#### Python3 + ```python class Solution: def longestPalindrome(self, words: List[str]) -> int: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestPalindrome(String[] words) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func longestPalindrome(words []string) int { cnt := map[string]int{} diff --git a/solution/2100-2199/2132.Stamping the Grid/README.md b/solution/2100-2199/2132.Stamping the Grid/README.md index 6dc5291b44824..de2b0401b5173 100644 --- a/solution/2100-2199/2132.Stamping the Grid/README.md +++ b/solution/2100-2199/2132.Stamping the Grid/README.md @@ -98,6 +98,8 @@ $$ +#### Python3 + ```python class Solution: def possibleToStamp( @@ -125,6 +127,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean possibleToStamp(int[][] grid, int stampHeight, int stampWidth) { @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -198,6 +204,8 @@ public: }; ``` +#### Go + ```go func possibleToStamp(grid [][]int, stampHeight int, stampWidth int) bool { m, n := len(grid), len(grid[0]) @@ -240,6 +248,8 @@ func possibleToStamp(grid [][]int, stampHeight int, stampWidth int) bool { } ``` +#### TypeScript + ```ts function possibleToStamp(grid: number[][], stampHeight: number, stampWidth: number): boolean { const m = grid.length; @@ -276,6 +286,8 @@ function possibleToStamp(grid: number[][], stampHeight: number, stampWidth: numb } ``` +#### Rust + ```rust impl Solution { pub fn possible_to_stamp(grid: Vec>, stamp_height: i32, stamp_width: i32) -> bool { @@ -345,6 +357,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} grid diff --git a/solution/2100-2199/2132.Stamping the Grid/README_EN.md b/solution/2100-2199/2132.Stamping the Grid/README_EN.md index 8be9cef0fab53..ecc4c0e5b3c92 100644 --- a/solution/2100-2199/2132.Stamping the Grid/README_EN.md +++ b/solution/2100-2199/2132.Stamping the Grid/README_EN.md @@ -94,6 +94,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def possibleToStamp( @@ -121,6 +123,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean possibleToStamp(int[][] grid, int stampHeight, int stampWidth) { @@ -156,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -194,6 +200,8 @@ public: }; ``` +#### Go + ```go func possibleToStamp(grid [][]int, stampHeight int, stampWidth int) bool { m, n := len(grid), len(grid[0]) @@ -236,6 +244,8 @@ func possibleToStamp(grid [][]int, stampHeight int, stampWidth int) bool { } ``` +#### TypeScript + ```ts function possibleToStamp(grid: number[][], stampHeight: number, stampWidth: number): boolean { const m = grid.length; @@ -272,6 +282,8 @@ function possibleToStamp(grid: number[][], stampHeight: number, stampWidth: numb } ``` +#### Rust + ```rust impl Solution { pub fn possible_to_stamp(grid: Vec>, stamp_height: i32, stamp_width: i32) -> bool { @@ -341,6 +353,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[][]} grid diff --git a/solution/2100-2199/2133.Check if Every Row and Column Contains All Numbers/README.md b/solution/2100-2199/2133.Check if Every Row and Column Contains All Numbers/README.md index 4517c6f2a643b..a79a45b585b6b 100644 --- a/solution/2100-2199/2133.Check if Every Row and Column Contains All Numbers/README.md +++ b/solution/2100-2199/2133.Check if Every Row and Column Contains All Numbers/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def checkValid(self, matrix: List[List[int]]) -> bool: @@ -89,6 +91,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean checkValid(int[][] matrix) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func checkValid(matrix [][]int) bool { n := len(matrix) @@ -171,6 +179,8 @@ func checkValid(matrix [][]int) bool { } ``` +#### TypeScript + ```ts function checkValid(matrix: number[][]): boolean { const n = matrix.length; diff --git a/solution/2100-2199/2133.Check if Every Row and Column Contains All Numbers/README_EN.md b/solution/2100-2199/2133.Check if Every Row and Column Contains All Numbers/README_EN.md index 00ef335d7a05b..c9a85c8de829d 100644 --- a/solution/2100-2199/2133.Check if Every Row and Column Contains All Numbers/README_EN.md +++ b/solution/2100-2199/2133.Check if Every Row and Column Contains All Numbers/README_EN.md @@ -62,6 +62,8 @@ Hence, we return false. +#### Python3 + ```python class Solution: def checkValid(self, matrix: List[List[int]]) -> bool: @@ -83,6 +85,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean checkValid(int[][] matrix) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func checkValid(matrix [][]int) bool { n := len(matrix) @@ -165,6 +173,8 @@ func checkValid(matrix [][]int) bool { } ``` +#### TypeScript + ```ts function checkValid(matrix: number[][]): boolean { const n = matrix.length; diff --git a/solution/2100-2199/2134.Minimum Swaps to Group All 1's Together II/README.md b/solution/2100-2199/2134.Minimum Swaps to Group All 1's Together II/README.md index 72e2dcd0a7038..4a57b5acc1c90 100644 --- a/solution/2100-2199/2134.Minimum Swaps to Group All 1's Together II/README.md +++ b/solution/2100-2199/2134.Minimum Swaps to Group All 1's Together II/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def minSwaps(self, nums: List[int]) -> int: @@ -95,6 +97,8 @@ class Solution: return k - mx ``` +#### Java + ```java class Solution { public int minSwaps(int[] nums) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func minSwaps(nums []int) int { k := 0 @@ -151,6 +159,8 @@ func minSwaps(nums []int) int { } ``` +#### TypeScript + ```ts function minSwaps(nums: number[]): number { const k = nums.reduce((a, b) => a + b, 0); @@ -165,6 +175,8 @@ function minSwaps(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_swaps(nums: Vec) -> i32 { @@ -186,6 +198,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int MinSwaps(int[] nums) { diff --git a/solution/2100-2199/2134.Minimum Swaps to Group All 1's Together II/README_EN.md b/solution/2100-2199/2134.Minimum Swaps to Group All 1's Together II/README_EN.md index 9348e2ffab3dd..2663f18f1b6b0 100644 --- a/solution/2100-2199/2134.Minimum Swaps to Group All 1's Together II/README_EN.md +++ b/solution/2100-2199/2134.Minimum Swaps to Group All 1's Together II/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def minSwaps(self, nums: List[int]) -> int: @@ -97,6 +99,8 @@ class Solution: return k - mx ``` +#### Java + ```java class Solution { public int minSwaps(int[] nums) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func minSwaps(nums []int) int { k := 0 @@ -153,6 +161,8 @@ func minSwaps(nums []int) int { } ``` +#### TypeScript + ```ts function minSwaps(nums: number[]): number { const k = nums.reduce((a, b) => a + b, 0); @@ -167,6 +177,8 @@ function minSwaps(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_swaps(nums: Vec) -> i32 { @@ -188,6 +200,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int MinSwaps(int[] nums) { diff --git a/solution/2100-2199/2135.Count Words Obtained After Adding a Letter/README.md b/solution/2100-2199/2135.Count Words Obtained After Adding a Letter/README.md index 872c90c7d0a63..17a147e98aeae 100644 --- a/solution/2100-2199/2135.Count Words Obtained After Adding a Letter/README.md +++ b/solution/2100-2199/2135.Count Words Obtained After Adding a Letter/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def wordCount(self, startWords: List[str], targetWords: List[str]) -> int: @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go func wordCount(startWords []string, targetWords []string) int { s := make(map[int]bool) diff --git a/solution/2100-2199/2135.Count Words Obtained After Adding a Letter/README_EN.md b/solution/2100-2199/2135.Count Words Obtained After Adding a Letter/README_EN.md index 51a88a3247010..620fa277596d0 100644 --- a/solution/2100-2199/2135.Count Words Obtained After Adding a Letter/README_EN.md +++ b/solution/2100-2199/2135.Count Words Obtained After Adding a Letter/README_EN.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def wordCount(self, startWords: List[str], targetWords: List[str]) -> int: @@ -113,6 +115,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go func wordCount(startWords []string, targetWords []string) int { s := make(map[int]bool) diff --git a/solution/2100-2199/2136.Earliest Possible Day of Full Bloom/README.md b/solution/2100-2199/2136.Earliest Possible Day of Full Bloom/README.md index 9fa605f290bc3..d06751ca01e70 100644 --- a/solution/2100-2199/2136.Earliest Possible Day of Full Bloom/README.md +++ b/solution/2100-2199/2136.Earliest Possible Day of Full Bloom/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def earliestFullBloom(self, plantTime: List[int], growTime: List[int]) -> int: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int earliestFullBloom(int[] plantTime, int[] growTime) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func earliestFullBloom(plantTime []int, growTime []int) (ans int) { n := len(plantTime) @@ -154,6 +162,8 @@ func earliestFullBloom(plantTime []int, growTime []int) (ans int) { } ``` +#### TypeScript + ```ts function earliestFullBloom(plantTime: number[], growTime: number[]): number { const n = plantTime.length; @@ -168,6 +178,8 @@ function earliestFullBloom(plantTime: number[], growTime: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn earliest_full_bloom(plant_time: Vec, grow_time: Vec) -> i32 { diff --git a/solution/2100-2199/2136.Earliest Possible Day of Full Bloom/README_EN.md b/solution/2100-2199/2136.Earliest Possible Day of Full Bloom/README_EN.md index 9f4d6d5b2c24b..8f7a09700fc97 100644 --- a/solution/2100-2199/2136.Earliest Possible Day of Full Bloom/README_EN.md +++ b/solution/2100-2199/2136.Earliest Possible Day of Full Bloom/README_EN.md @@ -87,6 +87,8 @@ Thus, on day 2, all the seeds are blooming. +#### Python3 + ```python class Solution: def earliestFullBloom(self, plantTime: List[int], growTime: List[int]) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int earliestFullBloom(int[] plantTime, int[] growTime) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func earliestFullBloom(plantTime []int, growTime []int) (ans int) { n := len(plantTime) @@ -151,6 +159,8 @@ func earliestFullBloom(plantTime []int, growTime []int) (ans int) { } ``` +#### TypeScript + ```ts function earliestFullBloom(plantTime: number[], growTime: number[]): number { const n = plantTime.length; @@ -165,6 +175,8 @@ function earliestFullBloom(plantTime: number[], growTime: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn earliest_full_bloom(plant_time: Vec, grow_time: Vec) -> i32 { diff --git a/solution/2100-2199/2137.Pour Water Between Buckets to Make Water Levels Equal/README.md b/solution/2100-2199/2137.Pour Water Between Buckets to Make Water Levels Equal/README.md index a7d2b6aa83a9d..f77cddb11360d 100644 --- a/solution/2100-2199/2137.Pour Water Between Buckets to Make Water Levels Equal/README.md +++ b/solution/2100-2199/2137.Pour Water Between Buckets to Make Water Levels Equal/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def equalizeWater(self, buckets: List[int], loss: int) -> float: @@ -103,6 +105,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { public double equalizeWater(int[] buckets, int loss) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func equalizeWater(buckets []int, loss int) float64 { check := func(v float64) bool { @@ -189,6 +197,8 @@ func equalizeWater(buckets []int, loss int) float64 { } ``` +#### TypeScript + ```ts function equalizeWater(buckets: number[], loss: number): number { let l = 0; diff --git a/solution/2100-2199/2137.Pour Water Between Buckets to Make Water Levels Equal/README_EN.md b/solution/2100-2199/2137.Pour Water Between Buckets to Make Water Levels Equal/README_EN.md index bed1652775485..2b042258e9e8d 100644 --- a/solution/2100-2199/2137.Pour Water Between Buckets to Make Water Levels Equal/README_EN.md +++ b/solution/2100-2199/2137.Pour Water Between Buckets to Make Water Levels Equal/README_EN.md @@ -74,6 +74,8 @@ All buckets have 3.5 gallons of water in them so return 3.5. +#### Python3 + ```python class Solution: def equalizeWater(self, buckets: List[int], loss: int) -> float: @@ -96,6 +98,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { public double equalizeWater(int[] buckets, int loss) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func equalizeWater(buckets []int, loss int) float64 { check := func(v float64) bool { @@ -182,6 +190,8 @@ func equalizeWater(buckets []int, loss int) float64 { } ``` +#### TypeScript + ```ts function equalizeWater(buckets: number[], loss: number): number { let l = 0; diff --git a/solution/2100-2199/2138.Divide a String Into Groups of Size k/README.md b/solution/2100-2199/2138.Divide a String Into Groups of Size k/README.md index 1a22f542b81b5..e1bf9c3c09a54 100644 --- a/solution/2100-2199/2138.Divide a String Into Groups of Size k/README.md +++ b/solution/2100-2199/2138.Divide a String Into Groups of Size k/README.md @@ -75,12 +75,16 @@ tags: +#### Python3 + ```python class Solution: def divideString(self, s: str, k: int, fill: str) -> List[str]: return [s[i : i + k].ljust(k, fill) for i in range(0, len(s), k)] ``` +#### Java + ```java class Solution { public String[] divideString(String s, int k, char fill) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func divideString(s string, k int, fill byte) []string { n := len(s) diff --git a/solution/2100-2199/2138.Divide a String Into Groups of Size k/README_EN.md b/solution/2100-2199/2138.Divide a String Into Groups of Size k/README_EN.md index 68b199c81e185..4013d205e724d 100644 --- a/solution/2100-2199/2138.Divide a String Into Groups of Size k/README_EN.md +++ b/solution/2100-2199/2138.Divide a String Into Groups of Size k/README_EN.md @@ -75,12 +75,16 @@ Thus, the 4 groups formed are "abc", "def", "ghi", +#### Python3 + ```python class Solution: def divideString(self, s: str, k: int, fill: str) -> List[str]: return [s[i : i + k].ljust(k, fill) for i in range(0, len(s), k)] ``` +#### Java + ```java class Solution { public String[] divideString(String s, int k, char fill) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func divideString(s string, k int, fill byte) []string { n := len(s) diff --git a/solution/2100-2199/2139.Minimum Moves to Reach Target Score/README.md b/solution/2100-2199/2139.Minimum Moves to Reach Target Score/README.md index 41f6b0f2e0459..4828fd47a49d9 100644 --- a/solution/2100-2199/2139.Minimum Moves to Reach Target Score/README.md +++ b/solution/2100-2199/2139.Minimum Moves to Reach Target Score/README.md @@ -98,6 +98,8 @@ tags: +#### Python3 + ```python class Solution: def minMoves(self, target: int, maxDoubles: int) -> int: @@ -110,6 +112,8 @@ class Solution: return 1 + self.minMoves(target - 1, maxDoubles) ``` +#### Java + ```java class Solution { public int minMoves(int target, int maxDoubles) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func minMoves(target int, maxDoubles int) int { if target == 1 { @@ -160,6 +168,8 @@ func minMoves(target int, maxDoubles int) int { } ``` +#### TypeScript + ```ts function minMoves(target: number, maxDoubles: number): number { if (target === 1) { @@ -185,6 +195,8 @@ function minMoves(target: number, maxDoubles: number): number { +#### Python3 + ```python class Solution: def minMoves(self, target: int, maxDoubles: int) -> int: @@ -200,6 +212,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minMoves(int target, int maxDoubles) { @@ -219,6 +233,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -239,6 +255,8 @@ public: }; ``` +#### Go + ```go func minMoves(target int, maxDoubles int) (ans int) { for maxDoubles > 0 && target > 1 { @@ -255,6 +273,8 @@ func minMoves(target int, maxDoubles int) (ans int) { } ``` +#### TypeScript + ```ts function minMoves(target: number, maxDoubles: number): number { let ans = 0; diff --git a/solution/2100-2199/2139.Minimum Moves to Reach Target Score/README_EN.md b/solution/2100-2199/2139.Minimum Moves to Reach Target Score/README_EN.md index ca1b8a8b9255e..d24200eb0cee6 100644 --- a/solution/2100-2199/2139.Minimum Moves to Reach Target Score/README_EN.md +++ b/solution/2100-2199/2139.Minimum Moves to Reach Target Score/README_EN.md @@ -98,6 +98,8 @@ We can also change the above process to an iterative way to avoid the space over +#### Python3 + ```python class Solution: def minMoves(self, target: int, maxDoubles: int) -> int: @@ -110,6 +112,8 @@ class Solution: return 1 + self.minMoves(target - 1, maxDoubles) ``` +#### Java + ```java class Solution { public int minMoves(int target, int maxDoubles) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func minMoves(target int, maxDoubles int) int { if target == 1 { @@ -160,6 +168,8 @@ func minMoves(target int, maxDoubles int) int { } ``` +#### TypeScript + ```ts function minMoves(target: number, maxDoubles: number): number { if (target === 1) { @@ -185,6 +195,8 @@ function minMoves(target: number, maxDoubles: number): number { +#### Python3 + ```python class Solution: def minMoves(self, target: int, maxDoubles: int) -> int: @@ -200,6 +212,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minMoves(int target, int maxDoubles) { @@ -219,6 +233,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -239,6 +255,8 @@ public: }; ``` +#### Go + ```go func minMoves(target int, maxDoubles int) (ans int) { for maxDoubles > 0 && target > 1 { @@ -255,6 +273,8 @@ func minMoves(target int, maxDoubles int) (ans int) { } ``` +#### TypeScript + ```ts function minMoves(target: number, maxDoubles: number): number { let ans = 0; diff --git a/solution/2100-2199/2140.Solving Questions With Brainpower/README.md b/solution/2100-2199/2140.Solving Questions With Brainpower/README.md index cce11c7eab52f..b0040edf5e294 100644 --- a/solution/2100-2199/2140.Solving Questions With Brainpower/README.md +++ b/solution/2100-2199/2140.Solving Questions With Brainpower/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def mostPoints(self, questions: List[List[int]]) -> int: @@ -105,6 +107,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private int n; @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func mostPoints(questions [][]int) int64 { n := len(questions) @@ -173,6 +181,8 @@ func mostPoints(questions [][]int) int64 { } ``` +#### TypeScript + ```ts function mostPoints(questions: number[][]): number { const n = questions.length; @@ -213,6 +223,8 @@ $$ +#### Python3 + ```python class Solution: def mostPoints(self, questions: List[List[int]]) -> int: @@ -225,6 +237,8 @@ class Solution: return f[0] ``` +#### Java + ```java class Solution { public long mostPoints(int[][] questions) { @@ -240,6 +254,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -257,6 +273,8 @@ public: }; ``` +#### Go + ```go func mostPoints(questions [][]int) int64 { n := len(questions) @@ -272,6 +290,8 @@ func mostPoints(questions [][]int) int64 { } ``` +#### TypeScript + ```ts function mostPoints(questions: number[][]): number { const n = questions.length; diff --git a/solution/2100-2199/2140.Solving Questions With Brainpower/README_EN.md b/solution/2100-2199/2140.Solving Questions With Brainpower/README_EN.md index ed508debe346c..8c526726d15bc 100644 --- a/solution/2100-2199/2140.Solving Questions With Brainpower/README_EN.md +++ b/solution/2100-2199/2140.Solving Questions With Brainpower/README_EN.md @@ -81,6 +81,8 @@ Total points earned: 2 + 5 = 7. There is no other way to earn 7 or more points. +#### Python3 + ```python class Solution: def mostPoints(self, questions: List[List[int]]) -> int: @@ -94,6 +96,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private int n; @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func mostPoints(questions [][]int) int64 { n := len(questions) @@ -162,6 +170,8 @@ func mostPoints(questions [][]int) int64 { } ``` +#### TypeScript + ```ts function mostPoints(questions: number[][]): number { const n = questions.length; @@ -190,6 +200,8 @@ function mostPoints(questions: number[][]): number { +#### Python3 + ```python class Solution: def mostPoints(self, questions: List[List[int]]) -> int: @@ -202,6 +214,8 @@ class Solution: return f[0] ``` +#### Java + ```java class Solution { public long mostPoints(int[][] questions) { @@ -217,6 +231,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -234,6 +250,8 @@ public: }; ``` +#### Go + ```go func mostPoints(questions [][]int) int64 { n := len(questions) @@ -249,6 +267,8 @@ func mostPoints(questions [][]int) int64 { } ``` +#### TypeScript + ```ts function mostPoints(questions: number[][]): number { const n = questions.length; diff --git a/solution/2100-2199/2141.Maximum Running Time of N Computers/README.md b/solution/2100-2199/2141.Maximum Running Time of N Computers/README.md index ba9f87ff17683..2c225e80ef2d0 100644 --- a/solution/2100-2199/2141.Maximum Running Time of N Computers/README.md +++ b/solution/2100-2199/2141.Maximum Running Time of N Computers/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def maxRunTime(self, n: int, batteries: List[int]) -> int: @@ -98,6 +100,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { public long maxRunTime(int n, int[] batteries) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func maxRunTime(n int, batteries []int) int64 { l, r := 0, 0 @@ -169,6 +177,8 @@ func maxRunTime(n int, batteries []int) int64 { } ``` +#### TypeScript + ```ts function maxRunTime(n: number, batteries: number[]): number { let l = 0n; @@ -192,6 +202,8 @@ function maxRunTime(n: number, batteries: number[]): number { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/2100-2199/2141.Maximum Running Time of N Computers/README_EN.md b/solution/2100-2199/2141.Maximum Running Time of N Computers/README_EN.md index 2fb36777af6ab..d827d9a49b03c 100644 --- a/solution/2100-2199/2141.Maximum Running Time of N Computers/README_EN.md +++ b/solution/2100-2199/2141.Maximum Running Time of N Computers/README_EN.md @@ -74,6 +74,8 @@ We can run the two computers simultaneously for at most 2 minutes, so we return +#### Python3 + ```python class Solution: def maxRunTime(self, n: int, batteries: List[int]) -> int: @@ -87,6 +89,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { public long maxRunTime(int n, int[] batteries) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func maxRunTime(n int, batteries []int) int64 { l, r := 0, 0 @@ -158,6 +166,8 @@ func maxRunTime(n int, batteries []int) int64 { } ``` +#### TypeScript + ```ts function maxRunTime(n: number, batteries: number[]): number { let l = 0n; @@ -181,6 +191,8 @@ function maxRunTime(n: number, batteries: number[]): number { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/2100-2199/2142.The Number of Passengers in Each Bus I/README.md b/solution/2100-2199/2142.The Number of Passengers in Each Bus I/README.md index be0e49180b776..3e30f60b7fda6 100644 --- a/solution/2100-2199/2142.The Number of Passengers in Each Bus I/README.md +++ b/solution/2100-2199/2142.The Number of Passengers in Each Bus I/README.md @@ -104,6 +104,8 @@ Passengers 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2100-2199/2142.The Number of Passengers in Each Bus I/README_EN.md b/solution/2100-2199/2142.The Number of Passengers in Each Bus I/README_EN.md index 615a4434abde8..6a46bb5b12c3b 100644 --- a/solution/2100-2199/2142.The Number of Passengers in Each Bus I/README_EN.md +++ b/solution/2100-2199/2142.The Number of Passengers in Each Bus I/README_EN.md @@ -107,6 +107,8 @@ Passengers table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2100-2199/2143.Choose Numbers From Two Arrays in Range/README.md b/solution/2100-2199/2143.Choose Numbers From Two Arrays in Range/README.md index e406b47e83f1e..8a601e38ad610 100644 --- a/solution/2100-2199/2143.Choose Numbers From Two Arrays in Range/README.md +++ b/solution/2100-2199/2143.Choose Numbers From Two Arrays in Range/README.md @@ -98,6 +98,8 @@ tags: +#### Python3 + ```python class Solution: def countSubranges(self, nums1: List[int], nums2: List[int]) -> int: @@ -119,6 +121,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countSubranges(int[] nums1, int[] nums2) { @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func countSubranges(nums1 []int, nums2 []int) (ans int) { n := len(nums1) @@ -217,6 +225,8 @@ func sum(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function countSubranges(nums1: number[], nums2: number[]): number { const n = nums1.length; diff --git a/solution/2100-2199/2143.Choose Numbers From Two Arrays in Range/README_EN.md b/solution/2100-2199/2143.Choose Numbers From Two Arrays in Range/README_EN.md index 5344aa9c6089c..0824d9a5dcbd5 100644 --- a/solution/2100-2199/2143.Choose Numbers From Two Arrays in Range/README_EN.md +++ b/solution/2100-2199/2143.Choose Numbers From Two Arrays in Range/README_EN.md @@ -88,6 +88,8 @@ In the second balanced range, we choose nums2[1] and in the third balanced range +#### Python3 + ```python class Solution: def countSubranges(self, nums1: List[int], nums2: List[int]) -> int: @@ -109,6 +111,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countSubranges(int[] nums1, int[] nums2) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func countSubranges(nums1 []int, nums2 []int) (ans int) { n := len(nums1) @@ -207,6 +215,8 @@ func sum(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function countSubranges(nums1: number[], nums2: number[]): number { const n = nums1.length; diff --git a/solution/2100-2199/2144.Minimum Cost of Buying Candies With Discount/README.md b/solution/2100-2199/2144.Minimum Cost of Buying Candies With Discount/README.md index 97b8bddbffaae..1174c511b98a1 100644 --- a/solution/2100-2199/2144.Minimum Cost of Buying Candies With Discount/README.md +++ b/solution/2100-2199/2144.Minimum Cost of Buying Candies With Discount/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def minimumCost(self, cost: List[int]) -> int: @@ -92,6 +94,8 @@ class Solution: return sum(cost) - sum(cost[2::3]) ``` +#### Java + ```java class Solution { public int minimumCost(int[] cost) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func minimumCost(cost []int) (ans int) { sort.Ints(cost) @@ -138,6 +146,8 @@ func minimumCost(cost []int) (ans int) { } ``` +#### TypeScript + ```ts function minimumCost(cost: number[]): number { cost.sort((a, b) => a - b); diff --git a/solution/2100-2199/2144.Minimum Cost of Buying Candies With Discount/README_EN.md b/solution/2100-2199/2144.Minimum Cost of Buying Candies With Discount/README_EN.md index 22dd8114505be..bdeef31a1f61a 100644 --- a/solution/2100-2199/2144.Minimum Cost of Buying Candies With Discount/README_EN.md +++ b/solution/2100-2199/2144.Minimum Cost of Buying Candies With Discount/README_EN.md @@ -82,6 +82,8 @@ Hence, the minimum cost to buy all candies is 5 + 5 = 10. +#### Python3 + ```python class Solution: def minimumCost(self, cost: List[int]) -> int: @@ -89,6 +91,8 @@ class Solution: return sum(cost) - sum(cost[2::3]) ``` +#### Java + ```java class Solution { public int minimumCost(int[] cost) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func minimumCost(cost []int) (ans int) { sort.Ints(cost) @@ -135,6 +143,8 @@ func minimumCost(cost []int) (ans int) { } ``` +#### TypeScript + ```ts function minimumCost(cost: number[]): number { cost.sort((a, b) => a - b); diff --git a/solution/2100-2199/2145.Count the Hidden Sequences/README.md b/solution/2100-2199/2145.Count the Hidden Sequences/README.md index 4608e5ac05290..8b541d7d3f821 100644 --- a/solution/2100-2199/2145.Count the Hidden Sequences/README.md +++ b/solution/2100-2199/2145.Count the Hidden Sequences/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfArrays(self, differences: List[int], lower: int, upper: int) -> int: @@ -100,6 +102,8 @@ class Solution: return max(0, upper - lower - (mx - mi) + 1) ``` +#### Java + ```java class Solution { public int numberOfArrays(int[] differences, int lower, int upper) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func numberOfArrays(differences []int, lower int, upper int) int { num, mi, mx := 0, 0, 0 diff --git a/solution/2100-2199/2145.Count the Hidden Sequences/README_EN.md b/solution/2100-2199/2145.Count the Hidden Sequences/README_EN.md index a2848eb674bb3..8e2df29176083 100644 --- a/solution/2100-2199/2145.Count the Hidden Sequences/README_EN.md +++ b/solution/2100-2199/2145.Count the Hidden Sequences/README_EN.md @@ -90,6 +90,8 @@ Thus, we return 4. +#### Python3 + ```python class Solution: def numberOfArrays(self, differences: List[int], lower: int, upper: int) -> int: @@ -101,6 +103,8 @@ class Solution: return max(0, upper - lower - (mx - mi) + 1) ``` +#### Java + ```java class Solution { public int numberOfArrays(int[] differences, int lower, int upper) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func numberOfArrays(differences []int, lower int, upper int) int { num, mi, mx := 0, 0, 0 diff --git a/solution/2100-2199/2146.K Highest Ranked Items Within a Price Range/README.md b/solution/2100-2199/2146.K Highest Ranked Items Within a Price Range/README.md index 061f1652c7c9c..4dcd7f3797ce7 100644 --- a/solution/2100-2199/2146.K Highest Ranked Items Within a Price Range/README.md +++ b/solution/2100-2199/2146.K Highest Ranked Items Within a Price Range/README.md @@ -123,6 +123,8 @@ tags: +#### Python3 + ```python class Solution: def highestRankedKItems( @@ -148,6 +150,8 @@ class Solution: return [item[2:] for item in items][:k] ``` +#### Java + ```java class Solution { public List> highestRankedKItems( @@ -199,6 +203,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -236,6 +242,8 @@ public: }; ``` +#### Go + ```go func highestRankedKItems(grid [][]int, pricing []int, start []int, k int) [][]int { m, n := len(grid), len(grid[0]) diff --git a/solution/2100-2199/2146.K Highest Ranked Items Within a Price Range/README_EN.md b/solution/2100-2199/2146.K Highest Ranked Items Within a Price Range/README_EN.md index d0b0a38dbe5b4..594d962793180 100644 --- a/solution/2100-2199/2146.K Highest Ranked Items Within a Price Range/README_EN.md +++ b/solution/2100-2199/2146.K Highest Ranked Items Within a Price Range/README_EN.md @@ -118,6 +118,8 @@ Note that k = 3 but there are only 2 reachable items within the price range. +#### Python3 + ```python class Solution: def highestRankedKItems( @@ -143,6 +145,8 @@ class Solution: return [item[2:] for item in items][:k] ``` +#### Java + ```java class Solution { public List> highestRankedKItems( @@ -194,6 +198,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -231,6 +237,8 @@ public: }; ``` +#### Go + ```go func highestRankedKItems(grid [][]int, pricing []int, start []int, k int) [][]int { m, n := len(grid), len(grid[0]) diff --git a/solution/2100-2199/2147.Number of Ways to Divide a Long Corridor/README.md b/solution/2100-2199/2147.Number of Ways to Divide a Long Corridor/README.md index eec4274c103c1..3c0381c463ed3 100644 --- a/solution/2100-2199/2147.Number of Ways to Divide a Long Corridor/README.md +++ b/solution/2100-2199/2147.Number of Ways to Divide a Long Corridor/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfWays(self, corridor: str) -> int: @@ -113,6 +115,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private String s; @@ -152,6 +156,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -179,6 +185,8 @@ public: }; ``` +#### Go + ```go func numberOfWays(corridor string) int { n := len(corridor) @@ -219,6 +227,8 @@ func numberOfWays(corridor string) int { } ``` +#### TypeScript + ```ts function numberOfWays(corridor: string): number { const M: number = 1e9 + 7; diff --git a/solution/2100-2199/2147.Number of Ways to Divide a Long Corridor/README_EN.md b/solution/2100-2199/2147.Number of Ways to Divide a Long Corridor/README_EN.md index c9b8198646adf..6f14f957aedee 100644 --- a/solution/2100-2199/2147.Number of Ways to Divide a Long Corridor/README_EN.md +++ b/solution/2100-2199/2147.Number of Ways to Divide a Long Corridor/README_EN.md @@ -75,6 +75,8 @@ Installing any would create some section that does not have exactly two seats. +#### Python3 + ```python class Solution: def numberOfWays(self, corridor: str) -> int: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private String s; @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func numberOfWays(corridor string) int { n := len(corridor) @@ -204,6 +212,8 @@ func numberOfWays(corridor string) int { } ``` +#### TypeScript + ```ts function numberOfWays(corridor: string): number { const M: number = 1e9 + 7; diff --git a/solution/2100-2199/2148.Count Elements With Strictly Smaller and Greater Elements/README.md b/solution/2100-2199/2148.Count Elements With Strictly Smaller and Greater Elements/README.md index daddd11ec8e11..21e6a7623ca42 100644 --- a/solution/2100-2199/2148.Count Elements With Strictly Smaller and Greater Elements/README.md +++ b/solution/2100-2199/2148.Count Elements With Strictly Smaller and Greater Elements/README.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def countElements(self, nums: List[int]) -> int: @@ -68,6 +70,8 @@ class Solution: return sum(mi < num < mx for num in nums) ``` +#### Java + ```java class Solution { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func countElements(nums []int) int { mi, mx := int(1e6), -int(1e6) @@ -127,6 +135,8 @@ func countElements(nums []int) int { } ``` +#### TypeScript + ```ts function countElements(nums: number[]): number { const min = Math.min(...nums), diff --git a/solution/2100-2199/2148.Count Elements With Strictly Smaller and Greater Elements/README_EN.md b/solution/2100-2199/2148.Count Elements With Strictly Smaller and Greater Elements/README_EN.md index 01d26c88a80ea..bcbba03f2f12b 100644 --- a/solution/2100-2199/2148.Count Elements With Strictly Smaller and Greater Elements/README_EN.md +++ b/solution/2100-2199/2148.Count Elements With Strictly Smaller and Greater Elements/README_EN.md @@ -59,6 +59,8 @@ Since there are two elements with the value 3, in total there are 2 elements hav +#### Python3 + ```python class Solution: def countElements(self, nums: List[int]) -> int: @@ -66,6 +68,8 @@ class Solution: return sum(mi < num < mx for num in nums) ``` +#### Java + ```java class Solution { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -104,6 +110,8 @@ public: }; ``` +#### Go + ```go func countElements(nums []int) int { mi, mx := int(1e6), -int(1e6) @@ -125,6 +133,8 @@ func countElements(nums []int) int { } ``` +#### TypeScript + ```ts function countElements(nums: number[]): number { const min = Math.min(...nums), diff --git a/solution/2100-2199/2149.Rearrange Array Elements by Sign/README.md b/solution/2100-2199/2149.Rearrange Array Elements by Sign/README.md index a09ab16e2b917..ef55109061bb1 100644 --- a/solution/2100-2199/2149.Rearrange Array Elements by Sign/README.md +++ b/solution/2100-2199/2149.Rearrange Array Elements by Sign/README.md @@ -80,6 +80,8 @@ nums 中的正整数是 [3,1,2] ,负整数是 [-2,-5,-4] 。 +#### Python3 + ```python class Solution: def rearrangeArray(self, nums: List[int]) -> List[int]: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func rearrangeArray(nums []int) []int { ans := make([]int, len(nums)) @@ -152,6 +160,8 @@ func rearrangeArray(nums []int) []int { } ``` +#### TypeScript + ```ts function rearrangeArray(nums: number[]): number[] { let ans = []; diff --git a/solution/2100-2199/2149.Rearrange Array Elements by Sign/README_EN.md b/solution/2100-2199/2149.Rearrange Array Elements by Sign/README_EN.md index 935ada3a94449..e7b040c53704d 100644 --- a/solution/2100-2199/2149.Rearrange Array Elements by Sign/README_EN.md +++ b/solution/2100-2199/2149.Rearrange Array Elements by Sign/README_EN.md @@ -77,6 +77,8 @@ It is not required to do the modifications in-place. +#### Python3 + ```python class Solution: def rearrangeArray(self, nums: List[int]) -> List[int]: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func rearrangeArray(nums []int) []int { ans := make([]int, len(nums)) @@ -149,6 +157,8 @@ func rearrangeArray(nums []int) []int { } ``` +#### TypeScript + ```ts function rearrangeArray(nums: number[]): number[] { let ans = []; diff --git a/solution/2100-2199/2150.Find All Lonely Numbers in the Array/README.md b/solution/2100-2199/2150.Find All Lonely Numbers in the Array/README.md index 78e6aa176d94a..30ca9fd942ca4 100644 --- a/solution/2100-2199/2150.Find All Lonely Numbers in the Array/README.md +++ b/solution/2100-2199/2150.Find All Lonely Numbers in the Array/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def findLonely(self, nums: List[int]) -> List[int]: @@ -79,6 +81,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func findLonely(nums []int) []int { counter := make(map[int]int) @@ -130,6 +138,8 @@ func findLonely(nums []int) []int { } ``` +#### TypeScript + ```ts function findLonely(nums: number[]): number[] { let hashMap: Map = new Map(); diff --git a/solution/2100-2199/2150.Find All Lonely Numbers in the Array/README_EN.md b/solution/2100-2199/2150.Find All Lonely Numbers in the Array/README_EN.md index 89c2107de4d1c..bc490d0563c97 100644 --- a/solution/2100-2199/2150.Find All Lonely Numbers in the Array/README_EN.md +++ b/solution/2100-2199/2150.Find All Lonely Numbers in the Array/README_EN.md @@ -69,6 +69,8 @@ Note that [5, 1] may also be returned. +#### Python3 + ```python class Solution: def findLonely(self, nums: List[int]) -> List[int]: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func findLonely(nums []int) []int { counter := make(map[int]int) @@ -131,6 +139,8 @@ func findLonely(nums []int) []int { } ``` +#### TypeScript + ```ts function findLonely(nums: number[]): number[] { let hashMap: Map = new Map(); diff --git a/solution/2100-2199/2151.Maximum Good People Based on Statements/README.md b/solution/2100-2199/2151.Maximum Good People Based on Statements/README.md index 995838a482516..659b191fe6d76 100644 --- a/solution/2100-2199/2151.Maximum Good People Based on Statements/README.md +++ b/solution/2100-2199/2151.Maximum Good People Based on Statements/README.md @@ -115,6 +115,8 @@ tags: +#### Python3 + ```python class Solution: def maximumGood(self, statements: List[List[int]]) -> int: @@ -131,6 +133,8 @@ class Solution: return max(check(mask) for mask in range(1, 1 << len(statements))) ``` +#### Java + ```java class Solution { public int maximumGood(int[][] statements) { @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go func maximumGood(statements [][]int) int { n := len(statements) @@ -211,6 +219,8 @@ func maximumGood(statements [][]int) int { } ``` +#### TypeScript + ```ts function maximumGood(statements: number[][]): number { const n = statements.length; diff --git a/solution/2100-2199/2151.Maximum Good People Based on Statements/README_EN.md b/solution/2100-2199/2151.Maximum Good People Based on Statements/README_EN.md index eb9ee325de161..c6fafdd848c24 100644 --- a/solution/2100-2199/2151.Maximum Good People Based on Statements/README_EN.md +++ b/solution/2100-2199/2151.Maximum Good People Based on Statements/README_EN.md @@ -111,6 +111,8 @@ Note that there is more than one way to arrive at this conclusion. +#### Python3 + ```python class Solution: def maximumGood(self, statements: List[List[int]]) -> int: @@ -127,6 +129,8 @@ class Solution: return max(check(mask) for mask in range(1, 1 << len(statements))) ``` +#### Java + ```java class Solution { public int maximumGood(int[][] statements) { @@ -156,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -182,6 +188,8 @@ public: }; ``` +#### Go + ```go func maximumGood(statements [][]int) int { n := len(statements) @@ -207,6 +215,8 @@ func maximumGood(statements [][]int) int { } ``` +#### TypeScript + ```ts function maximumGood(statements: number[][]): number { const n = statements.length; diff --git a/solution/2100-2199/2152.Minimum Number of Lines to Cover Points/README.md b/solution/2100-2199/2152.Minimum Number of Lines to Cover Points/README.md index 2a09d4909401f..15e1b9bd3467d 100644 --- a/solution/2100-2199/2152.Minimum Number of Lines to Cover Points/README.md +++ b/solution/2100-2199/2152.Minimum Number of Lines to Cover Points/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def minimumLines(self, points: List[List[int]]) -> int: @@ -114,6 +116,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private int[] f; @@ -163,6 +167,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -203,6 +209,8 @@ public: }; ``` +#### Go + ```go func minimumLines(points [][]int) int { check := func(i, j, k int) bool { diff --git a/solution/2100-2199/2152.Minimum Number of Lines to Cover Points/README_EN.md b/solution/2100-2199/2152.Minimum Number of Lines to Cover Points/README_EN.md index 599b8e1792aa3..b40db857f18fd 100644 --- a/solution/2100-2199/2152.Minimum Number of Lines to Cover Points/README_EN.md +++ b/solution/2100-2199/2152.Minimum Number of Lines to Cover Points/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def minimumLines(self, points: List[List[int]]) -> int: @@ -99,6 +101,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private int[] f; @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go func minimumLines(points [][]int) int { check := func(i, j, k int) bool { diff --git a/solution/2100-2199/2153.The Number of Passengers in Each Bus II/README.md b/solution/2100-2199/2153.The Number of Passengers in Each Bus II/README.md index 86e2cf21bad85..bf984998ac266 100644 --- a/solution/2100-2199/2153.The Number of Passengers in Each Bus II/README.md +++ b/solution/2100-2199/2153.The Number of Passengers in Each Bus II/README.md @@ -110,6 +110,8 @@ Passengers 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2100-2199/2153.The Number of Passengers in Each Bus II/README_EN.md b/solution/2100-2199/2153.The Number of Passengers in Each Bus II/README_EN.md index db7572efcad91..0807e22d3911f 100644 --- a/solution/2100-2199/2153.The Number of Passengers in Each Bus II/README_EN.md +++ b/solution/2100-2199/2153.The Number of Passengers in Each Bus II/README_EN.md @@ -110,6 +110,8 @@ Passengers table: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2100-2199/2154.Keep Multiplying Found Values by Two/README.md b/solution/2100-2199/2154.Keep Multiplying Found Values by Two/README.md index b8a54b29a1e3a..bca847888e4c5 100644 --- a/solution/2100-2199/2154.Keep Multiplying Found Values by Two/README.md +++ b/solution/2100-2199/2154.Keep Multiplying Found Values by Two/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def findFinalValue(self, nums: List[int], original: int) -> int: @@ -84,6 +86,8 @@ class Solution: return original ``` +#### Java + ```java class Solution { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func findFinalValue(nums []int, original int) int { s := make(map[int]bool) @@ -125,6 +133,8 @@ func findFinalValue(nums []int, original int) int { } ``` +#### TypeScript + ```ts function findFinalValue(nums: number[], original: number): number { let set: Set = new Set(nums); diff --git a/solution/2100-2199/2154.Keep Multiplying Found Values by Two/README_EN.md b/solution/2100-2199/2154.Keep Multiplying Found Values by Two/README_EN.md index de16fd63a1297..98b26eff9d52a 100644 --- a/solution/2100-2199/2154.Keep Multiplying Found Values by Two/README_EN.md +++ b/solution/2100-2199/2154.Keep Multiplying Found Values by Two/README_EN.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def findFinalValue(self, nums: List[int], original: int) -> int: @@ -82,6 +84,8 @@ class Solution: return original ``` +#### Java + ```java class Solution { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func findFinalValue(nums []int, original int) int { s := make(map[int]bool) @@ -123,6 +131,8 @@ func findFinalValue(nums []int, original int) int { } ``` +#### TypeScript + ```ts function findFinalValue(nums: number[], original: number): number { let set: Set = new Set(nums); diff --git a/solution/2100-2199/2155.All Divisions With the Highest Score of a Binary Array/README.md b/solution/2100-2199/2155.All Divisions With the Highest Score of a Binary Array/README.md index 262abfec67d03..afa9f90ecb617 100644 --- a/solution/2100-2199/2155.All Divisions With the Highest Score of a Binary Array/README.md +++ b/solution/2100-2199/2155.All Divisions With the Highest Score of a Binary Array/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def maxScoreIndices(self, nums: List[int]) -> List[int]: @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func maxScoreIndices(nums []int) []int { left, right := 0, 0 @@ -197,6 +205,8 @@ func maxScoreIndices(nums []int) []int { } ``` +#### TypeScript + ```ts function maxScoreIndices(nums: number[]): number[] { const n = nums.length; diff --git a/solution/2100-2199/2155.All Divisions With the Highest Score of a Binary Array/README_EN.md b/solution/2100-2199/2155.All Divisions With the Highest Score of a Binary Array/README_EN.md index b1f503f24b64f..32825443cbf7b 100644 --- a/solution/2100-2199/2155.All Divisions With the Highest Score of a Binary Array/README_EN.md +++ b/solution/2100-2199/2155.All Divisions With the Highest Score of a Binary Array/README_EN.md @@ -89,6 +89,8 @@ Only index 0 has the highest possible division score 2. +#### Python3 + ```python class Solution: def maxScoreIndices(self, nums: List[int]) -> List[int]: @@ -109,6 +111,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go func maxScoreIndices(nums []int) []int { left, right := 0, 0 @@ -198,6 +206,8 @@ func maxScoreIndices(nums []int) []int { } ``` +#### TypeScript + ```ts function maxScoreIndices(nums: number[]): number[] { const n = nums.length; diff --git a/solution/2100-2199/2156.Find Substring With Given Hash Value/README.md b/solution/2100-2199/2156.Find Substring With Given Hash Value/README.md index 7c3eeee0c5e73..2ac3c3991dad7 100644 --- a/solution/2100-2199/2156.Find Substring With Given Hash Value/README.md +++ b/solution/2100-2199/2156.Find Substring With Given Hash Value/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def subStrHash( @@ -107,6 +109,8 @@ class Solution: return s[j : j + k] ``` +#### Java + ```java class Solution { public String subStrHash(String s, int power, int modulo, int k, int hashValue) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func subStrHash(s string, power int, modulo int, k int, hashValue int) string { h, p := 0, 1 @@ -184,6 +192,8 @@ func subStrHash(s string, power int, modulo int, k int, hashValue int) string { } ``` +#### TypeScript + ```ts function subStrHash( s: string, @@ -216,6 +226,8 @@ function subStrHash( } ``` +#### JavaScript + ```js /** * @param {string} s diff --git a/solution/2100-2199/2156.Find Substring With Given Hash Value/README_EN.md b/solution/2100-2199/2156.Find Substring With Given Hash Value/README_EN.md index f8108deb33d33..0d95a2dd5f93d 100644 --- a/solution/2100-2199/2156.Find Substring With Given Hash Value/README_EN.md +++ b/solution/2100-2199/2156.Find Substring With Given Hash Value/README_EN.md @@ -85,6 +85,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string. The space +#### Python3 + ```python class Solution: def subStrHash( @@ -107,6 +109,8 @@ class Solution: return s[j : j + k] ``` +#### Java + ```java class Solution { public String subStrHash(String s, int power, int modulo, int k, int hashValue) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func subStrHash(s string, power int, modulo int, k int, hashValue int) string { h, p := 0, 1 @@ -184,6 +192,8 @@ func subStrHash(s string, power int, modulo int, k int, hashValue int) string { } ``` +#### TypeScript + ```ts function subStrHash( s: string, @@ -216,6 +226,8 @@ function subStrHash( } ``` +#### JavaScript + ```js /** * @param {string} s diff --git a/solution/2100-2199/2157.Groups of Strings/README.md b/solution/2100-2199/2157.Groups of Strings/README.md index 9027c933ba76a..420102d2dccf8 100644 --- a/solution/2100-2199/2157.Groups of Strings/README.md +++ b/solution/2100-2199/2157.Groups of Strings/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def groupStrings(self, words: List[str]) -> List[int]: @@ -133,6 +135,8 @@ class Solution: return [n, mx] ``` +#### Java + ```java class Solution { private Map p; @@ -195,6 +199,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -243,6 +249,8 @@ public: }; ``` +#### Go + ```go func groupStrings(words []string) []int { p := map[int]int{} diff --git a/solution/2100-2199/2157.Groups of Strings/README_EN.md b/solution/2100-2199/2157.Groups of Strings/README_EN.md index ee35d53fffa77..bab80e3c8213e 100644 --- a/solution/2100-2199/2157.Groups of Strings/README_EN.md +++ b/solution/2100-2199/2157.Groups of Strings/README_EN.md @@ -93,6 +93,8 @@ Thus, the size of the largest group is 3. +#### Python3 + ```python class Solution: def groupStrings(self, words: List[str]) -> List[int]: @@ -136,6 +138,8 @@ class Solution: return [n, mx] ``` +#### Java + ```java class Solution { private Map p; @@ -198,6 +202,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -246,6 +252,8 @@ public: }; ``` +#### Go + ```go func groupStrings(words []string) []int { p := map[int]int{} diff --git a/solution/2100-2199/2158.Amount of New Area Painted Each Day/README.md b/solution/2100-2199/2158.Amount of New Area Painted Each Day/README.md index 093007ad043eb..204bff1dbcf91 100644 --- a/solution/2100-2199/2158.Amount of New Area Painted Each Day/README.md +++ b/solution/2100-2199/2158.Amount of New Area Painted Each Day/README.md @@ -100,6 +100,8 @@ tags: +#### Python3 + ```python class Node: def __init__(self, l, r): @@ -176,6 +178,8 @@ class Solution: return ans ``` +#### Java + ```java class Node { Node left; @@ -283,6 +287,8 @@ class Solution { } ``` +#### C++ + ```cpp class Node { public: diff --git a/solution/2100-2199/2158.Amount of New Area Painted Each Day/README_EN.md b/solution/2100-2199/2158.Amount of New Area Painted Each Day/README_EN.md index c6c8c06504972..9ad8b49b5efc6 100644 --- a/solution/2100-2199/2158.Amount of New Area Painted Each Day/README_EN.md +++ b/solution/2100-2199/2158.Amount of New Area Painted Each Day/README_EN.md @@ -86,6 +86,8 @@ The amount of new area painted on day 1 is 0. +#### Python3 + ```python class Node: def __init__(self, l, r): @@ -162,6 +164,8 @@ class Solution: return ans ``` +#### Java + ```java class Node { Node left; @@ -269,6 +273,8 @@ class Solution { } ``` +#### C++ + ```cpp class Node { public: diff --git a/solution/2100-2199/2159.Order Two Columns Independently/README.md b/solution/2100-2199/2159.Order Two Columns Independently/README.md index 6e44e4843e435..f483746e0500e 100644 --- a/solution/2100-2199/2159.Order Two Columns Independently/README.md +++ b/solution/2100-2199/2159.Order Two Columns Independently/README.md @@ -75,6 +75,8 @@ Data 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2100-2199/2159.Order Two Columns Independently/README_EN.md b/solution/2100-2199/2159.Order Two Columns Independently/README_EN.md index 7449cbf56daeb..6308c3d9513a4 100644 --- a/solution/2100-2199/2159.Order Two Columns Independently/README_EN.md +++ b/solution/2100-2199/2159.Order Two Columns Independently/README_EN.md @@ -74,6 +74,8 @@ Data table: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2100-2199/2160.Minimum Sum of Four Digit Number After Splitting Digits/README.md b/solution/2100-2199/2160.Minimum Sum of Four Digit Number After Splitting Digits/README.md index 86b46338b55f8..2b48bb453016b 100644 --- a/solution/2100-2199/2160.Minimum Sum of Four Digit Number After Splitting Digits/README.md +++ b/solution/2100-2199/2160.Minimum Sum of Four Digit Number After Splitting Digits/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def minimumSum(self, num: int) -> int: @@ -75,6 +77,8 @@ class Solution: return 10 * (nums[0] + nums[1]) + nums[2] + nums[3] ``` +#### Java + ```java class Solution { public int minimumSum(int num) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -104,6 +110,8 @@ public: }; ``` +#### Go + ```go func minimumSum(num int) int { var nums []int @@ -116,6 +124,8 @@ func minimumSum(num int) int { } ``` +#### TypeScript + ```ts function minimumSum(num: number): number { const nums = new Array(4).fill(0); @@ -128,6 +138,8 @@ function minimumSum(num: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn minimum_sum(mut num: i32) -> i32 { @@ -142,6 +154,8 @@ impl Solution { } ``` +#### C + ```c int cmp(const void* a, const void* b) { return *(int*) a - *(int*) b; diff --git a/solution/2100-2199/2160.Minimum Sum of Four Digit Number After Splitting Digits/README_EN.md b/solution/2100-2199/2160.Minimum Sum of Four Digit Number After Splitting Digits/README_EN.md index bdb78a889a2fb..80213e3c6a48d 100644 --- a/solution/2100-2199/2160.Minimum Sum of Four Digit Number After Splitting Digits/README_EN.md +++ b/solution/2100-2199/2160.Minimum Sum of Four Digit Number After Splitting Digits/README_EN.md @@ -64,6 +64,8 @@ The minimum sum can be obtained by the pair [4, 9]: 4 + 9 = 13. +#### Python3 + ```python class Solution: def minimumSum(self, num: int) -> int: @@ -75,6 +77,8 @@ class Solution: return 10 * (nums[0] + nums[1]) + nums[2] + nums[3] ``` +#### Java + ```java class Solution { public int minimumSum(int num) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -104,6 +110,8 @@ public: }; ``` +#### Go + ```go func minimumSum(num int) int { var nums []int @@ -116,6 +124,8 @@ func minimumSum(num int) int { } ``` +#### TypeScript + ```ts function minimumSum(num: number): number { const nums = new Array(4).fill(0); @@ -128,6 +138,8 @@ function minimumSum(num: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn minimum_sum(mut num: i32) -> i32 { @@ -142,6 +154,8 @@ impl Solution { } ``` +#### C + ```c int cmp(const void* a, const void* b) { return *(int*) a - *(int*) b; diff --git a/solution/2100-2199/2161.Partition Array According to Given Pivot/README.md b/solution/2100-2199/2161.Partition Array According to Given Pivot/README.md index 3427aea05ee2e..6a84347ce1581 100644 --- a/solution/2100-2199/2161.Partition Array According to Given Pivot/README.md +++ b/solution/2100-2199/2161.Partition Array According to Given Pivot/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def pivotArray(self, nums: List[int], pivot: int) -> List[int]: @@ -90,6 +92,8 @@ class Solution: return a + b + c ``` +#### Java + ```java class Solution { public int[] pivotArray(int[] nums, int pivot) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func pivotArray(nums []int, pivot int) []int { var ans []int diff --git a/solution/2100-2199/2161.Partition Array According to Given Pivot/README_EN.md b/solution/2100-2199/2161.Partition Array According to Given Pivot/README_EN.md index 11d82ee6e3b72..3820f0cc07b51 100644 --- a/solution/2100-2199/2161.Partition Array According to Given Pivot/README_EN.md +++ b/solution/2100-2199/2161.Partition Array According to Given Pivot/README_EN.md @@ -76,6 +76,8 @@ The relative ordering of the elements less than and greater than pivot is also m +#### Python3 + ```python class Solution: def pivotArray(self, nums: List[int], pivot: int) -> List[int]: @@ -90,6 +92,8 @@ class Solution: return a + b + c ``` +#### Java + ```java class Solution { public int[] pivotArray(int[] nums, int pivot) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func pivotArray(nums []int, pivot int) []int { var ans []int diff --git a/solution/2100-2199/2162.Minimum Cost to Set Cooking Time/README.md b/solution/2100-2199/2162.Minimum Cost to Set Cooking Time/README.md index a7ffa6bf4d2a8..81ead364e1dab 100644 --- a/solution/2100-2199/2162.Minimum Cost to Set Cooking Time/README.md +++ b/solution/2100-2199/2162.Minimum Cost to Set Cooking Time/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class Solution: def minCostSetTime( @@ -120,6 +122,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minCostSetTime(int startAt, int moveCost, int pushCost, int targetSeconds) { @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go func minCostSetTime(startAt int, moveCost int, pushCost int, targetSeconds int) int { m, s := targetSeconds/60, targetSeconds%60 diff --git a/solution/2100-2199/2162.Minimum Cost to Set Cooking Time/README_EN.md b/solution/2100-2199/2162.Minimum Cost to Set Cooking Time/README_EN.md index 8943506e8fe1c..14553d3bcb6b0 100644 --- a/solution/2100-2199/2162.Minimum Cost to Set Cooking Time/README_EN.md +++ b/solution/2100-2199/2162.Minimum Cost to Set Cooking Time/README_EN.md @@ -90,6 +90,8 @@ Note other possible ways are 0076, 076, 0116, and 116, but none of them produces +#### Python3 + ```python class Solution: def minCostSetTime( @@ -116,6 +118,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minCostSetTime(int startAt, int moveCost, int pushCost, int targetSeconds) { @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func minCostSetTime(startAt int, moveCost int, pushCost int, targetSeconds int) int { m, s := targetSeconds/60, targetSeconds%60 diff --git a/solution/2100-2199/2163.Minimum Difference in Sums After Removal of Elements/README.md b/solution/2100-2199/2163.Minimum Difference in Sums After Removal of Elements/README.md index 62678b3d539e9..fc6d85ba96c64 100644 --- a/solution/2100-2199/2163.Minimum Difference in Sums After Removal of Elements/README.md +++ b/solution/2100-2199/2163.Minimum Difference in Sums After Removal of Elements/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def minimumDifference(self, nums: List[int]) -> int: @@ -120,6 +122,8 @@ class Solution: return min(pre[i] - suf[i + 1] for i in range(n, n * 2 + 1)) ``` +#### Java + ```java class Solution { public long minimumDifference(int[] nums) { @@ -158,6 +162,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -201,6 +207,8 @@ public: }; ``` +#### Go + ```go func minimumDifference(nums []int) int64 { m := len(nums) @@ -248,6 +256,8 @@ func (h *hp) Pop() any { } ``` +#### TypeScript + ```ts function minimumDifference(nums: number[]): number { const m = nums.length; diff --git a/solution/2100-2199/2163.Minimum Difference in Sums After Removal of Elements/README_EN.md b/solution/2100-2199/2163.Minimum Difference in Sums After Removal of Elements/README_EN.md index 4e3847a07ab52..849885bb56d1f 100644 --- a/solution/2100-2199/2163.Minimum Difference in Sums After Removal of Elements/README_EN.md +++ b/solution/2100-2199/2163.Minimum Difference in Sums After Removal of Elements/README_EN.md @@ -82,6 +82,8 @@ It can be shown that it is not possible to obtain a difference smaller than 1. +#### Python3 + ```python class Solution: def minimumDifference(self, nums: List[int]) -> int: @@ -112,6 +114,8 @@ class Solution: return min(pre[i] - suf[i + 1] for i in range(n, n * 2 + 1)) ``` +#### Java + ```java class Solution { public long minimumDifference(int[] nums) { @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go func minimumDifference(nums []int) int64 { m := len(nums) @@ -240,6 +248,8 @@ func (h *hp) Pop() any { } ``` +#### TypeScript + ```ts function minimumDifference(nums: number[]): number { const m = nums.length; diff --git a/solution/2100-2199/2164.Sort Even and Odd Indices Independently/README.md b/solution/2100-2199/2164.Sort Even and Odd Indices Independently/README.md index 1ef5cb5651610..0d7ed75734d49 100644 --- a/solution/2100-2199/2164.Sort Even and Odd Indices Independently/README.md +++ b/solution/2100-2199/2164.Sort Even and Odd Indices Independently/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def sortEvenOdd(self, nums: List[int]) -> List[int]: @@ -92,6 +94,8 @@ class Solution: return nums ``` +#### Java + ```java class Solution { public int[] sortEvenOdd(int[] nums) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func sortEvenOdd(nums []int) []int { n := len(nums) diff --git a/solution/2100-2199/2164.Sort Even and Odd Indices Independently/README_EN.md b/solution/2100-2199/2164.Sort Even and Odd Indices Independently/README_EN.md index 70a43526f3ba7..8b5e790948b82 100644 --- a/solution/2100-2199/2164.Sort Even and Odd Indices Independently/README_EN.md +++ b/solution/2100-2199/2164.Sort Even and Odd Indices Independently/README_EN.md @@ -80,6 +80,8 @@ The resultant array formed is [2,1], which is the same as the initial array. +#### Python3 + ```python class Solution: def sortEvenOdd(self, nums: List[int]) -> List[int]: @@ -90,6 +92,8 @@ class Solution: return nums ``` +#### Java + ```java class Solution { public int[] sortEvenOdd(int[] nums) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func sortEvenOdd(nums []int) []int { n := len(nums) diff --git a/solution/2100-2199/2165.Smallest Value of the Rearranged Number/README.md b/solution/2100-2199/2165.Smallest Value of the Rearranged Number/README.md index 19a73fb12c784..da96e150a5a4d 100644 --- a/solution/2100-2199/2165.Smallest Value of the Rearranged Number/README.md +++ b/solution/2100-2199/2165.Smallest Value of the Rearranged Number/README.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def smallestNumber(self, num: int) -> int: @@ -89,6 +91,8 @@ class Solution: return int(ans) ``` +#### Java + ```java class Solution { public long smallestNumber(long num) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func smallestNumber(num int64) int64 { if num == 0 { diff --git a/solution/2100-2199/2165.Smallest Value of the Rearranged Number/README_EN.md b/solution/2100-2199/2165.Smallest Value of the Rearranged Number/README_EN.md index 596b30c699aea..54cdc3fb112a4 100644 --- a/solution/2100-2199/2165.Smallest Value of the Rearranged Number/README_EN.md +++ b/solution/2100-2199/2165.Smallest Value of the Rearranged Number/README_EN.md @@ -61,6 +61,8 @@ The arrangement with the smallest value that does not contain any leading zeros +#### Python3 + ```python class Solution: def smallestNumber(self, num: int) -> int: @@ -90,6 +92,8 @@ class Solution: return int(ans) ``` +#### Java + ```java class Solution { public long smallestNumber(long num) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func smallestNumber(num int64) int64 { if num == 0 { diff --git a/solution/2100-2199/2166.Design Bitset/README.md b/solution/2100-2199/2166.Design Bitset/README.md index 52777451d927e..17c3ca1de0eda 100644 --- a/solution/2100-2199/2166.Design Bitset/README.md +++ b/solution/2100-2199/2166.Design Bitset/README.md @@ -83,6 +83,8 @@ bs.toString(); // 返回 "01010" ,即 bitset 的当前组成情况。 +#### Python3 + ```python class Bitset: def __init__(self, size: int): @@ -130,6 +132,8 @@ class Bitset: # param_7 = obj.toString() ``` +#### Java + ```java class Bitset { private char[] a; @@ -196,6 +200,8 @@ class Bitset { */ ``` +#### C++ + ```cpp class Bitset { public: @@ -252,6 +258,8 @@ public: */ ``` +#### Go + ```go type Bitset struct { a []byte diff --git a/solution/2100-2199/2166.Design Bitset/README_EN.md b/solution/2100-2199/2166.Design Bitset/README_EN.md index 8f5c2db606fd4..7219c0279263a 100644 --- a/solution/2100-2199/2166.Design Bitset/README_EN.md +++ b/solution/2100-2199/2166.Design Bitset/README_EN.md @@ -81,6 +81,8 @@ bs.toString(); // return "01010", which is the composition of bitset. +#### Python3 + ```python class Bitset: def __init__(self, size: int): @@ -128,6 +130,8 @@ class Bitset: # param_7 = obj.toString() ``` +#### Java + ```java class Bitset { private char[] a; @@ -194,6 +198,8 @@ class Bitset { */ ``` +#### C++ + ```cpp class Bitset { public: @@ -250,6 +256,8 @@ public: */ ``` +#### Go + ```go type Bitset struct { a []byte diff --git a/solution/2100-2199/2167.Minimum Time to Remove All Cars Containing Illegal Goods/README.md b/solution/2100-2199/2167.Minimum Time to Remove All Cars Containing Illegal Goods/README.md index 771ab08f9b023..e3ec9ce66017f 100644 --- a/solution/2100-2199/2167.Minimum Time to Remove All Cars Containing Illegal Goods/README.md +++ b/solution/2100-2199/2167.Minimum Time to Remove All Cars Containing Illegal Goods/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python class Solution: def minimumTime(self, s: str) -> int: @@ -108,6 +110,8 @@ class Solution: return min(a + b for a, b in zip(pre[1:], suf[1:])) ``` +#### Java + ```java class Solution { public int minimumTime(String s) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func minimumTime(s string) int { n := len(s) diff --git a/solution/2100-2199/2167.Minimum Time to Remove All Cars Containing Illegal Goods/README_EN.md b/solution/2100-2199/2167.Minimum Time to Remove All Cars Containing Illegal Goods/README_EN.md index fc15709c855a4..ece6d0aae0e7a 100644 --- a/solution/2100-2199/2167.Minimum Time to Remove All Cars Containing Illegal Goods/README_EN.md +++ b/solution/2100-2199/2167.Minimum Time to Remove All Cars Containing Illegal Goods/README_EN.md @@ -94,6 +94,8 @@ There are no other ways to remove them with less time. +#### Python3 + ```python class Solution: def minimumTime(self, s: str) -> int: @@ -107,6 +109,8 @@ class Solution: return min(a + b for a, b in zip(pre[1:], suf[1:])) ``` +#### Java + ```java class Solution { public int minimumTime(String s) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func minimumTime(s string) int { n := len(s) diff --git a/solution/2100-2199/2168.Unique Substrings With Equal Digit Frequency/README.md b/solution/2100-2199/2168.Unique Substrings With Equal Digit Frequency/README.md index 5a6560cbef47a..b268e68b6796e 100644 --- a/solution/2100-2199/2168.Unique Substrings With Equal Digit Frequency/README.md +++ b/solution/2100-2199/2168.Unique Substrings With Equal Digit Frequency/README.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def equalDigitFrequency(self, s: str) -> int: @@ -83,6 +85,8 @@ class Solution: return len(vis) ``` +#### Java + ```java class Solution { public int equalDigitFrequency(String s) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### Go + ```go func equalDigitFrequency(s string) int { n := len(s) diff --git a/solution/2100-2199/2168.Unique Substrings With Equal Digit Frequency/README_EN.md b/solution/2100-2199/2168.Unique Substrings With Equal Digit Frequency/README_EN.md index cef8f17434f09..0bdf91df61ee2 100644 --- a/solution/2100-2199/2168.Unique Substrings With Equal Digit Frequency/README_EN.md +++ b/solution/2100-2199/2168.Unique Substrings With Equal Digit Frequency/README_EN.md @@ -58,6 +58,8 @@ Note that although the substring "12" appears twice, it is only counte +#### Python3 + ```python class Solution: def equalDigitFrequency(self, s: str) -> int: @@ -81,6 +83,8 @@ class Solution: return len(vis) ``` +#### Java + ```java class Solution { public int equalDigitFrequency(String s) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### Go + ```go func equalDigitFrequency(s string) int { n := len(s) diff --git a/solution/2100-2199/2169.Count Operations to Obtain Zero/README.md b/solution/2100-2199/2169.Count Operations to Obtain Zero/README.md index f2eea5753daf3..1a47df3e9151d 100644 --- a/solution/2100-2199/2169.Count Operations to Obtain Zero/README.md +++ b/solution/2100-2199/2169.Count Operations to Obtain Zero/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def countOperations(self, num1: int, num2: int) -> int: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countOperations(int num1, int num2) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func countOperations(num1 int, num2 int) int { ans := 0 @@ -131,6 +139,8 @@ func countOperations(num1 int, num2 int) int { } ``` +#### TypeScript + ```ts function countOperations(num1: number, num2: number): number { let ans = 0; diff --git a/solution/2100-2199/2169.Count Operations to Obtain Zero/README_EN.md b/solution/2100-2199/2169.Count Operations to Obtain Zero/README_EN.md index 28b9da2e19d7e..06c6724f6ba2a 100644 --- a/solution/2100-2199/2169.Count Operations to Obtain Zero/README_EN.md +++ b/solution/2100-2199/2169.Count Operations to Obtain Zero/README_EN.md @@ -71,6 +71,8 @@ So the total number of operations required is 1. +#### Python3 + ```python class Solution: def countOperations(self, num1: int, num2: int) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countOperations(int num1, int num2) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func countOperations(num1 int, num2 int) int { ans := 0 @@ -129,6 +137,8 @@ func countOperations(num1 int, num2 int) int { } ``` +#### TypeScript + ```ts function countOperations(num1: number, num2: number): number { let ans = 0; diff --git a/solution/2100-2199/2170.Minimum Operations to Make the Array Alternating/README.md b/solution/2100-2199/2170.Minimum Operations to Make the Array Alternating/README.md index 7777eb258783c..2aaac511eef60 100644 --- a/solution/2100-2199/2170.Minimum Operations to Make the Array Alternating/README.md +++ b/solution/2100-2199/2170.Minimum Operations to Make the Array Alternating/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def minimumOperations(self, nums: List[int]) -> int: @@ -91,6 +93,8 @@ class Solution: return min(n - (n1 + n2) for a, n1 in get(0) for b, n2 in get(1) if a != b) ``` +#### Java + ```java class Solution { private int[] nums; @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp typedef pair PII; @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go func minimumOperations(nums []int) int { n := len(nums) @@ -202,6 +210,8 @@ func minimumOperations(nums []int) int { } ``` +#### TypeScript + ```ts function minimumOperations(nums: number[]): number { const n = nums.length, diff --git a/solution/2100-2199/2170.Minimum Operations to Make the Array Alternating/README_EN.md b/solution/2100-2199/2170.Minimum Operations to Make the Array Alternating/README_EN.md index 04d0cfb976949..22556697b8d3f 100644 --- a/solution/2100-2199/2170.Minimum Operations to Make the Array Alternating/README_EN.md +++ b/solution/2100-2199/2170.Minimum Operations to Make the Array Alternating/README_EN.md @@ -75,6 +75,8 @@ Note that the array cannot be converted to [2,2,2,2,2] b +#### Python3 + ```python class Solution: def minimumOperations(self, nums: List[int]) -> int: @@ -90,6 +92,8 @@ class Solution: return min(n - (n1 + n2) for a, n1 in get(0) for b, n2 in get(1) if a != b) ``` +#### Java + ```java class Solution { private int[] nums; @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp typedef pair PII; @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func minimumOperations(nums []int) int { n := len(nums) @@ -201,6 +209,8 @@ func minimumOperations(nums []int) int { } ``` +#### TypeScript + ```ts function minimumOperations(nums: number[]): number { const n = nums.length, diff --git a/solution/2100-2199/2171.Removing Minimum Number of Magic Beans/README.md b/solution/2100-2199/2171.Removing Minimum Number of Magic Beans/README.md index cb6dd99096529..e70371f19a127 100644 --- a/solution/2100-2199/2171.Removing Minimum Number of Magic Beans/README.md +++ b/solution/2100-2199/2171.Removing Minimum Number of Magic Beans/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def minimumRemoval(self, beans: List[int]) -> int: @@ -93,6 +95,8 @@ class Solution: return min(s - x * (n - i) for i, x in enumerate(beans)) ``` +#### Java + ```java class Solution { public long minimumRemoval(int[] beans) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func minimumRemoval(beans []int) int64 { sort.Ints(beans) @@ -143,6 +151,8 @@ func minimumRemoval(beans []int) int64 { } ``` +#### TypeScript + ```ts function minimumRemoval(beans: number[]): number { beans.sort((a, b) => a - b); diff --git a/solution/2100-2199/2171.Removing Minimum Number of Magic Beans/README_EN.md b/solution/2100-2199/2171.Removing Minimum Number of Magic Beans/README_EN.md index 33d42e98c752a..8b5990304e1f6 100644 --- a/solution/2100-2199/2171.Removing Minimum Number of Magic Beans/README_EN.md +++ b/solution/2100-2199/2171.Removing Minimum Number of Magic Beans/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def minimumRemoval(self, beans: List[int]) -> int: @@ -91,6 +93,8 @@ class Solution: return min(s - x * (n - i) for i, x in enumerate(beans)) ``` +#### Java + ```java class Solution { public long minimumRemoval(int[] beans) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func minimumRemoval(beans []int) int64 { sort.Ints(beans) @@ -141,6 +149,8 @@ func minimumRemoval(beans []int) int64 { } ``` +#### TypeScript + ```ts function minimumRemoval(beans: number[]): number { beans.sort((a, b) => a - b); diff --git a/solution/2100-2199/2172.Maximum AND Sum of Array/README.md b/solution/2100-2199/2172.Maximum AND Sum of Array/README.md index a37a4e817e0de..1f6856cb20859 100644 --- a/solution/2100-2199/2172.Maximum AND Sum of Array/README.md +++ b/solution/2100-2199/2172.Maximum AND Sum of Array/README.md @@ -89,6 +89,8 @@ $$ +#### Python3 + ```python class Solution: def maximumANDSum(self, nums: List[int], numSlots: int) -> int: @@ -105,6 +107,8 @@ class Solution: return max(f) ``` +#### Java + ```java class Solution { public int maximumANDSum(int[] nums, int numSlots) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func maximumANDSum(nums []int, numSlots int) int { n := len(nums) @@ -173,6 +181,8 @@ func maximumANDSum(nums []int, numSlots int) int { } ``` +#### TypeScript + ```ts function maximumANDSum(nums: number[], numSlots: number): number { const n = nums.length; diff --git a/solution/2100-2199/2172.Maximum AND Sum of Array/README_EN.md b/solution/2100-2199/2172.Maximum AND Sum of Array/README_EN.md index 26838bb6f5706..99349803a2368 100644 --- a/solution/2100-2199/2172.Maximum AND Sum of Array/README_EN.md +++ b/solution/2100-2199/2172.Maximum AND Sum of Array/README_EN.md @@ -71,6 +71,8 @@ Note that slots 2, 5, 6, and 8 are empty which is permitted. +#### Python3 + ```python class Solution: def maximumANDSum(self, nums: List[int], numSlots: int) -> int: @@ -87,6 +89,8 @@ class Solution: return max(f) ``` +#### Java + ```java class Solution { public int maximumANDSum(int[] nums, int numSlots) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func maximumANDSum(nums []int, numSlots int) int { n := len(nums) @@ -155,6 +163,8 @@ func maximumANDSum(nums []int, numSlots int) int { } ``` +#### TypeScript + ```ts function maximumANDSum(nums: number[], numSlots: number): number { const n = nums.length; diff --git a/solution/2100-2199/2173.Longest Winning Streak/README.md b/solution/2100-2199/2173.Longest Winning Streak/README.md index ec1a87bb1f1c7..16987b46a82cc 100644 --- a/solution/2100-2199/2173.Longest Winning Streak/README.md +++ b/solution/2100-2199/2173.Longest Winning Streak/README.md @@ -97,6 +97,8 @@ Player 3: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2100-2199/2173.Longest Winning Streak/README_EN.md b/solution/2100-2199/2173.Longest Winning Streak/README_EN.md index 0154dd6f84586..27cbff002bd7c 100644 --- a/solution/2100-2199/2173.Longest Winning Streak/README_EN.md +++ b/solution/2100-2199/2173.Longest Winning Streak/README_EN.md @@ -96,6 +96,8 @@ The longest winning streak was 1 match. +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2100-2199/2174.Remove All Ones With Row and Column Flips II/README.md b/solution/2100-2199/2174.Remove All Ones With Row and Column Flips II/README.md index 4c4a49180c069..a60b13c137f71 100644 --- a/solution/2100-2199/2174.Remove All Ones With Row and Column Flips II/README.md +++ b/solution/2100-2199/2174.Remove All Ones With Row and Column Flips II/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def removeOnes(self, grid: List[List[int]]) -> int: @@ -115,6 +117,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int removeOnes(int[][] grid) { @@ -164,6 +168,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -202,6 +208,8 @@ public: }; ``` +#### Go + ```go func removeOnes(grid [][]int) int { m, n := len(grid), len(grid[0]) diff --git a/solution/2100-2199/2174.Remove All Ones With Row and Column Flips II/README_EN.md b/solution/2100-2199/2174.Remove All Ones With Row and Column Flips II/README_EN.md index 530d06a40dea7..cbf2ccbb16ebb 100644 --- a/solution/2100-2199/2174.Remove All Ones With Row and Column Flips II/README_EN.md +++ b/solution/2100-2199/2174.Remove All Ones With Row and Column Flips II/README_EN.md @@ -85,6 +85,8 @@ There are no 1's to remove so return 0. +#### Python3 + ```python class Solution: def removeOnes(self, grid: List[List[int]]) -> int: @@ -114,6 +116,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int removeOnes(int[][] grid) { @@ -163,6 +167,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -201,6 +207,8 @@ public: }; ``` +#### Go + ```go func removeOnes(grid [][]int) int { m, n := len(grid), len(grid[0]) diff --git a/solution/2100-2199/2175.The Change in Global Rankings/README.md b/solution/2100-2199/2175.The Change in Global Rankings/README.md index 951c33c95b0e1..7fd94a6ff6113 100644 --- a/solution/2100-2199/2175.The Change in Global Rankings/README.md +++ b/solution/2100-2199/2175.The Change in Global Rankings/README.md @@ -133,6 +133,8 @@ New Zealand 没有获得或丢失分数,他们的排名也没有发生变化 +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2100-2199/2175.The Change in Global Rankings/README_EN.md b/solution/2100-2199/2175.The Change in Global Rankings/README_EN.md index 295fc28f58d92..abb1e11011a6d 100644 --- a/solution/2100-2199/2175.The Change in Global Rankings/README_EN.md +++ b/solution/2100-2199/2175.The Change in Global Rankings/README_EN.md @@ -130,6 +130,8 @@ New Zealand did not gain or lose points and their rank did not change. +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2100-2199/2176.Count Equal and Divisible Pairs in an Array/README.md b/solution/2100-2199/2176.Count Equal and Divisible Pairs in an Array/README.md index 5d428c44c85ae..c615ddc16f258 100644 --- a/solution/2100-2199/2176.Count Equal and Divisible Pairs in an Array/README.md +++ b/solution/2100-2199/2176.Count Equal and Divisible Pairs in an Array/README.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def countPairs(self, nums: List[int], k: int) -> int: @@ -71,6 +73,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public int countPairs(int[] nums, int k) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -104,6 +110,8 @@ public: }; ``` +#### Go + ```go func countPairs(nums []int, k int) int { n := len(nums) @@ -119,6 +127,8 @@ func countPairs(nums []int, k int) int { } ``` +#### TypeScript + ```ts function countPairs(nums: number[], k: number): number { const n = nums.length; @@ -134,6 +144,8 @@ function countPairs(nums: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_pairs(nums: Vec, k: i32) -> i32 { @@ -152,6 +164,8 @@ impl Solution { } ``` +#### C + ```c int countPairs(int* nums, int numsSize, int k) { int ans = 0; diff --git a/solution/2100-2199/2176.Count Equal and Divisible Pairs in an Array/README_EN.md b/solution/2100-2199/2176.Count Equal and Divisible Pairs in an Array/README_EN.md index 95e53d6e39eb9..15fbb18d27999 100644 --- a/solution/2100-2199/2176.Count Equal and Divisible Pairs in an Array/README_EN.md +++ b/solution/2100-2199/2176.Count Equal and Divisible Pairs in an Array/README_EN.md @@ -60,6 +60,8 @@ There are 4 pairs that meet all the requirements: +#### Python3 + ```python class Solution: def countPairs(self, nums: List[int], k: int) -> int: @@ -71,6 +73,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public int countPairs(int[] nums, int k) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -104,6 +110,8 @@ public: }; ``` +#### Go + ```go func countPairs(nums []int, k int) int { n := len(nums) @@ -119,6 +127,8 @@ func countPairs(nums []int, k int) int { } ``` +#### TypeScript + ```ts function countPairs(nums: number[], k: number): number { const n = nums.length; @@ -134,6 +144,8 @@ function countPairs(nums: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_pairs(nums: Vec, k: i32) -> i32 { @@ -152,6 +164,8 @@ impl Solution { } ``` +#### C + ```c int countPairs(int* nums, int numsSize, int k) { int ans = 0; diff --git a/solution/2100-2199/2177.Find Three Consecutive Integers That Sum to a Given Number/README.md b/solution/2100-2199/2177.Find Three Consecutive Integers That Sum to a Given Number/README.md index 833e72f9e7a86..69bf1511aff3b 100644 --- a/solution/2100-2199/2177.Find Three Consecutive Integers That Sum to a Given Number/README.md +++ b/solution/2100-2199/2177.Find Three Consecutive Integers That Sum to a Given Number/README.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def sumOfThree(self, num: int) -> List[int]: @@ -67,6 +69,8 @@ class Solution: return [] if mod else [x - 1, x, x + 1] ``` +#### Java + ```java class Solution { public long[] sumOfThree(long num) { @@ -79,6 +83,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -92,6 +98,8 @@ public: }; ``` +#### Go + ```go func sumOfThree(num int64) []int64 { if num%3 != 0 { @@ -102,6 +110,8 @@ func sumOfThree(num int64) []int64 { } ``` +#### TypeScript + ```ts function sumOfThree(num: number): number[] { if (num % 3) { diff --git a/solution/2100-2199/2177.Find Three Consecutive Integers That Sum to a Given Number/README_EN.md b/solution/2100-2199/2177.Find Three Consecutive Integers That Sum to a Given Number/README_EN.md index f159e53d88cee..0e3704a8613d0 100644 --- a/solution/2100-2199/2177.Find Three Consecutive Integers That Sum to a Given Number/README_EN.md +++ b/solution/2100-2199/2177.Find Three Consecutive Integers That Sum to a Given Number/README_EN.md @@ -56,6 +56,8 @@ tags: +#### Python3 + ```python class Solution: def sumOfThree(self, num: int) -> List[int]: @@ -63,6 +65,8 @@ class Solution: return [] if mod else [x - 1, x, x + 1] ``` +#### Java + ```java class Solution { public long[] sumOfThree(long num) { @@ -75,6 +79,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -88,6 +94,8 @@ public: }; ``` +#### Go + ```go func sumOfThree(num int64) []int64 { if num%3 != 0 { @@ -98,6 +106,8 @@ func sumOfThree(num int64) []int64 { } ``` +#### TypeScript + ```ts function sumOfThree(num: number): number[] { if (num % 3) { diff --git a/solution/2100-2199/2178.Maximum Split of Positive Even Integers/README.md b/solution/2100-2199/2178.Maximum Split of Positive Even Integers/README.md index 75a98f148db20..9bce03a06b2e9 100644 --- a/solution/2100-2199/2178.Maximum Split of Positive Even Integers/README.md +++ b/solution/2100-2199/2178.Maximum Split of Positive Even Integers/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def maximumEvenSplit(self, finalSum: int) -> List[int]: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List maximumEvenSplit(long finalSum) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func maximumEvenSplit(finalSum int64) (ans []int64) { if finalSum%2 == 1 { @@ -145,6 +153,8 @@ func maximumEvenSplit(finalSum int64) (ans []int64) { } ``` +#### TypeScript + ```ts function maximumEvenSplit(finalSum: number): number[] { const ans: number[] = []; @@ -160,6 +170,8 @@ function maximumEvenSplit(finalSum: number): number[] { } ``` +#### C# + ```cs public class Solution { public IList MaximumEvenSplit(long finalSum) { diff --git a/solution/2100-2199/2178.Maximum Split of Positive Even Integers/README_EN.md b/solution/2100-2199/2178.Maximum Split of Positive Even Integers/README_EN.md index c43b7cb3287ef..74aa745a0a5f2 100644 --- a/solution/2100-2199/2178.Maximum Split of Positive Even Integers/README_EN.md +++ b/solution/2100-2199/2178.Maximum Split of Positive Even Integers/README_EN.md @@ -75,6 +75,8 @@ Note that [10,2,4,12], [6,2,4,16], etc. are also accepted. +#### Python3 + ```python class Solution: def maximumEvenSplit(self, finalSum: int) -> List[int]: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List maximumEvenSplit(long finalSum) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func maximumEvenSplit(finalSum int64) (ans []int64) { if finalSum%2 == 1 { @@ -137,6 +145,8 @@ func maximumEvenSplit(finalSum int64) (ans []int64) { } ``` +#### TypeScript + ```ts function maximumEvenSplit(finalSum: number): number[] { const ans: number[] = []; @@ -152,6 +162,8 @@ function maximumEvenSplit(finalSum: number): number[] { } ``` +#### C# + ```cs public class Solution { public IList MaximumEvenSplit(long finalSum) { diff --git a/solution/2100-2199/2179.Count Good Triplets in an Array/README.md b/solution/2100-2199/2179.Count Good Triplets in an Array/README.md index 97c7f6ae0f58f..9a4d4e04c971a 100644 --- a/solution/2100-2199/2179.Count Good Triplets in an Array/README.md +++ b/solution/2100-2199/2179.Count Good Triplets in an Array/README.md @@ -103,6 +103,8 @@ tags: +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -141,6 +143,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long goodTriplets(int[] nums1, int[] nums2) { @@ -193,6 +197,8 @@ class BinaryIndexedTree { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -244,6 +250,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -304,6 +312,8 @@ func goodTriplets(nums1 []int, nums2 []int) int64 { +#### Python3 + ```python class Node: def __init__(self): @@ -367,6 +377,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long goodTriplets(int[] nums1, int[] nums2) { @@ -451,6 +463,8 @@ class SegmentTree { } ``` +#### C++ + ```cpp class Node { public: diff --git a/solution/2100-2199/2179.Count Good Triplets in an Array/README_EN.md b/solution/2100-2199/2179.Count Good Triplets in an Array/README_EN.md index 8091960068477..b33e22ee45d77 100644 --- a/solution/2100-2199/2179.Count Good Triplets in an Array/README_EN.md +++ b/solution/2100-2199/2179.Count Good Triplets in an Array/README_EN.md @@ -69,6 +69,8 @@ Out of those triplets, only the triplet (0,1,3) satisfies pos2x < +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long goodTriplets(int[] nums1, int[] nums2) { @@ -159,6 +163,8 @@ class BinaryIndexedTree { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -210,6 +216,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -270,6 +278,8 @@ func goodTriplets(nums1 []int, nums2 []int) int64 { +#### Python3 + ```python class Node: def __init__(self): @@ -333,6 +343,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long goodTriplets(int[] nums1, int[] nums2) { @@ -417,6 +429,8 @@ class SegmentTree { } ``` +#### C++ + ```cpp class Node { public: diff --git a/solution/2100-2199/2180.Count Integers With Even Digit Sum/README.md b/solution/2100-2199/2180.Count Integers With Even Digit Sum/README.md index cafddf9c616b7..1665dd88dbd2e 100644 --- a/solution/2100-2199/2180.Count Integers With Even Digit Sum/README.md +++ b/solution/2100-2199/2180.Count Integers With Even Digit Sum/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def countEven(self, num: int) -> int: @@ -79,6 +81,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countEven(int num) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func countEven(num int) (ans int) { for i := 1; i <= num; i++ { @@ -129,6 +137,8 @@ func countEven(num int) (ans int) { } ``` +#### TypeScript + ```ts function countEven(num: number): number { let ans = 0; @@ -167,6 +177,8 @@ function countEven(num: number): number { +#### Python3 + ```python class Solution: def countEven(self, num: int) -> int: @@ -179,6 +191,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countEven(int num) { @@ -193,6 +207,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -208,6 +224,8 @@ public: }; ``` +#### Go + ```go func countEven(num int) (ans int) { ans = num/10*5 - 1 @@ -220,6 +238,8 @@ func countEven(num int) (ans int) { } ``` +#### TypeScript + ```ts function countEven(num: number): number { let ans = Math.floor(num / 10) * 5 - 1; diff --git a/solution/2100-2199/2180.Count Integers With Even Digit Sum/README_EN.md b/solution/2100-2199/2180.Count Integers With Even Digit Sum/README_EN.md index 5aedcb5b327af..5c2a0e6c2bead 100644 --- a/solution/2100-2199/2180.Count Integers With Even Digit Sum/README_EN.md +++ b/solution/2100-2199/2180.Count Integers With Even Digit Sum/README_EN.md @@ -60,6 +60,8 @@ The 14 integers less than or equal to 30 whose digit sums are even are +#### Python3 + ```python class Solution: def countEven(self, num: int) -> int: @@ -73,6 +75,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countEven(int num) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func countEven(num int) (ans int) { for i := 1; i <= num; i++ { @@ -123,6 +131,8 @@ func countEven(num int) (ans int) { } ``` +#### TypeScript + ```ts function countEven(num: number): number { let ans = 0; @@ -149,6 +159,8 @@ function countEven(num: number): number { +#### Python3 + ```python class Solution: def countEven(self, num: int) -> int: @@ -161,6 +173,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countEven(int num) { @@ -175,6 +189,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -190,6 +206,8 @@ public: }; ``` +#### Go + ```go func countEven(num int) (ans int) { ans = num/10*5 - 1 @@ -202,6 +220,8 @@ func countEven(num int) (ans int) { } ``` +#### TypeScript + ```ts function countEven(num: number): number { let ans = Math.floor(num / 10) * 5 - 1; diff --git a/solution/2100-2199/2181.Merge Nodes in Between Zeros/README.md b/solution/2100-2199/2181.Merge Nodes in Between Zeros/README.md index e3f189c44b02c..277cb10774aa6 100644 --- a/solution/2100-2199/2181.Merge Nodes in Between Zeros/README.md +++ b/solution/2100-2199/2181.Merge Nodes in Between Zeros/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -95,6 +97,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -181,6 +189,8 @@ func mergeNodes(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -211,6 +221,8 @@ function mergeNodes(head: ListNode | null): ListNode | null { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -247,6 +259,8 @@ impl Solution { } ``` +#### C + ```c /** * Definition for singly-linked list. diff --git a/solution/2100-2199/2181.Merge Nodes in Between Zeros/README_EN.md b/solution/2100-2199/2181.Merge Nodes in Between Zeros/README_EN.md index 13bc6a17475e8..ed3b2fa611046 100644 --- a/solution/2100-2199/2181.Merge Nodes in Between Zeros/README_EN.md +++ b/solution/2100-2199/2181.Merge Nodes in Between Zeros/README_EN.md @@ -69,6 +69,8 @@ The above figure represents the given linked list. The modified list contains +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -91,6 +93,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -177,6 +185,8 @@ func mergeNodes(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -207,6 +217,8 @@ function mergeNodes(head: ListNode | null): ListNode | null { } ``` +#### Rust + ```rust // Definition for singly-linked list. // #[derive(PartialEq, Eq, Clone, Debug)] @@ -243,6 +255,8 @@ impl Solution { } ``` +#### C + ```c /** * Definition for singly-linked list. diff --git a/solution/2100-2199/2182.Construct String With Repeat Limit/README.md b/solution/2100-2199/2182.Construct String With Repeat Limit/README.md index db1a3a142b73f..22e0815962827 100644 --- a/solution/2100-2199/2182.Construct String With Repeat Limit/README.md +++ b/solution/2100-2199/2182.Construct String With Repeat Limit/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def repeatLimitedString(self, s: str, repeatLimit: int) -> str: @@ -104,6 +106,8 @@ class Solution: return "".join(ans) ``` +#### Java + ```java class Solution { public String repeatLimitedString(String s, int repeatLimit) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func repeatLimitedString(s string, repeatLimit int) string { cnt := [26]int{} @@ -202,6 +210,8 @@ func repeatLimitedString(s string, repeatLimit int) string { } ``` +#### TypeScript + ```ts function repeatLimitedString(s: string, repeatLimit: number): string { const cnt: number[] = Array(26).fill(0); diff --git a/solution/2100-2199/2182.Construct String With Repeat Limit/README_EN.md b/solution/2100-2199/2182.Construct String With Repeat Limit/README_EN.md index 2b6a3a93bd51d..d2b3f44d90fc3 100644 --- a/solution/2100-2199/2182.Construct String With Repeat Limit/README_EN.md +++ b/solution/2100-2199/2182.Construct String With Repeat Limit/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n + |\Sigma|)$, and the space complexity is $O(|\Sigma +#### Python3 + ```python class Solution: def repeatLimitedString(self, s: str, repeatLimit: int) -> str: @@ -103,6 +105,8 @@ class Solution: return "".join(ans) ``` +#### Java + ```java class Solution { public String repeatLimitedString(String s, int repeatLimit) { @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go func repeatLimitedString(s string, repeatLimit int) string { cnt := [26]int{} @@ -201,6 +209,8 @@ func repeatLimitedString(s string, repeatLimit int) string { } ``` +#### TypeScript + ```ts function repeatLimitedString(s: string, repeatLimit: number): string { const cnt: number[] = Array(26).fill(0); diff --git a/solution/2100-2199/2183.Count Array Pairs Divisible by K/README.md b/solution/2100-2199/2183.Count Array Pairs Divisible by K/README.md index 6e9a66681df82..81f283313f1d1 100644 --- a/solution/2100-2199/2183.Count Array Pairs Divisible by K/README.md +++ b/solution/2100-2199/2183.Count Array Pairs Divisible by K/README.md @@ -66,18 +66,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2100-2199/2183.Count Array Pairs Divisible by K/README_EN.md b/solution/2100-2199/2183.Count Array Pairs Divisible by K/README_EN.md index c0833387082ea..06c97ae1ba988 100644 --- a/solution/2100-2199/2183.Count Array Pairs Divisible by K/README_EN.md +++ b/solution/2100-2199/2183.Count Array Pairs Divisible by K/README_EN.md @@ -66,18 +66,26 @@ Other pairs such as (0, 2) and (2, 4) have products 3 and 15 respectively, which +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2100-2199/2184.Number of Ways to Build Sturdy Brick Wall/README.md b/solution/2100-2199/2184.Number of Ways to Build Sturdy Brick Wall/README.md index 49cc0bd653f93..24d7a65d998bb 100644 --- a/solution/2100-2199/2184.Number of Ways to Build Sturdy Brick Wall/README.md +++ b/solution/2100-2199/2184.Number of Ways to Build Sturdy Brick Wall/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def buildWall(self, height: int, width: int, bricks: List[int]) -> int: @@ -127,6 +129,8 @@ class Solution: return sum(dp[-1]) % mod ``` +#### Java + ```java class Solution { private List> res = new ArrayList<>(); @@ -205,6 +209,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -278,6 +284,8 @@ public: }; ``` +#### Go + ```go func buildWall(height int, width int, bricks []int) int { mod := int(1e9) + 7 diff --git a/solution/2100-2199/2184.Number of Ways to Build Sturdy Brick Wall/README_EN.md b/solution/2100-2199/2184.Number of Ways to Build Sturdy Brick Wall/README_EN.md index f83c80faf029a..391555e80cbd5 100644 --- a/solution/2100-2199/2184.Number of Ways to Build Sturdy Brick Wall/README_EN.md +++ b/solution/2100-2199/2184.Number of Ways to Build Sturdy Brick Wall/README_EN.md @@ -66,6 +66,8 @@ There are no ways to build a sturdy wall because the only type of brick we have +#### Python3 + ```python class Solution: def buildWall(self, height: int, width: int, bricks: List[int]) -> int: @@ -118,6 +120,8 @@ class Solution: return sum(dp[-1]) % mod ``` +#### Java + ```java class Solution { private List> res = new ArrayList<>(); @@ -196,6 +200,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -269,6 +275,8 @@ public: }; ``` +#### Go + ```go func buildWall(height int, width int, bricks []int) int { mod := int(1e9) + 7 diff --git a/solution/2100-2199/2185.Counting Words With a Given Prefix/README.md b/solution/2100-2199/2185.Counting Words With a Given Prefix/README.md index 43ae962e61a67..50aa54a53ee4f 100644 --- a/solution/2100-2199/2185.Counting Words With a Given Prefix/README.md +++ b/solution/2100-2199/2185.Counting Words With a Given Prefix/README.md @@ -66,12 +66,16 @@ tags: +#### Python3 + ```python class Solution: def prefixCount(self, words: List[str], pref: str) -> int: return sum(w.startswith(pref) for w in words) ``` +#### Java + ```java class Solution { public int prefixCount(String[] words, String pref) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -97,6 +103,8 @@ public: }; ``` +#### Go + ```go func prefixCount(words []string, pref string) (ans int) { for _, w := range words { @@ -108,12 +116,16 @@ func prefixCount(words []string, pref string) (ans int) { } ``` +#### TypeScript + ```ts function prefixCount(words: string[], pref: string): number { return words.reduce((r, s) => (r += s.startsWith(pref) ? 1 : 0), 0); } ``` +#### Rust + ```rust impl Solution { pub fn prefix_count(words: Vec, pref: String) -> i32 { @@ -125,6 +137,8 @@ impl Solution { } ``` +#### C + ```c int prefixCount(char** words, int wordsSize, char* pref) { int ans = 0; @@ -166,6 +180,8 @@ int prefixCount(char** words, int wordsSize, char* pref) { +#### Python3 + ```python class Trie: def __init__(self): @@ -199,6 +215,8 @@ class Solution: return tree.search(pref) ``` +#### Java + ```java class Trie { private Trie[] children = new Trie[26]; @@ -240,6 +258,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -288,6 +308,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [26]*Trie diff --git a/solution/2100-2199/2185.Counting Words With a Given Prefix/README_EN.md b/solution/2100-2199/2185.Counting Words With a Given Prefix/README_EN.md index 51ddaac20af79..ceebea5554929 100644 --- a/solution/2100-2199/2185.Counting Words With a Given Prefix/README_EN.md +++ b/solution/2100-2199/2185.Counting Words With a Given Prefix/README_EN.md @@ -62,12 +62,16 @@ tags: +#### Python3 + ```python class Solution: def prefixCount(self, words: List[str], pref: str) -> int: return sum(w.startswith(pref) for w in words) ``` +#### Java + ```java class Solution { public int prefixCount(String[] words, String pref) { @@ -82,6 +86,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -93,6 +99,8 @@ public: }; ``` +#### Go + ```go func prefixCount(words []string, pref string) (ans int) { for _, w := range words { @@ -104,12 +112,16 @@ func prefixCount(words []string, pref string) (ans int) { } ``` +#### TypeScript + ```ts function prefixCount(words: string[], pref: string): number { return words.reduce((r, s) => (r += s.startsWith(pref) ? 1 : 0), 0); } ``` +#### Rust + ```rust impl Solution { pub fn prefix_count(words: Vec, pref: String) -> i32 { @@ -121,6 +133,8 @@ impl Solution { } ``` +#### C + ```c int prefixCount(char** words, int wordsSize, char* pref) { int ans = 0; @@ -144,6 +158,8 @@ int prefixCount(char** words, int wordsSize, char* pref) { +#### Python3 + ```python class Trie: def __init__(self): @@ -177,6 +193,8 @@ class Solution: return tree.search(pref) ``` +#### Java + ```java class Trie { private Trie[] children = new Trie[26]; @@ -218,6 +236,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -266,6 +286,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [26]*Trie diff --git a/solution/2100-2199/2186.Minimum Number of Steps to Make Two Strings Anagram II/README.md b/solution/2100-2199/2186.Minimum Number of Steps to Make Two Strings Anagram II/README.md index 194e321431486..b6ac78a178424 100644 --- a/solution/2100-2199/2186.Minimum Number of Steps to Make Two Strings Anagram II/README.md +++ b/solution/2100-2199/2186.Minimum Number of Steps to Make Two Strings Anagram II/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def minSteps(self, s: str, t: str) -> int: @@ -74,6 +76,8 @@ class Solution: return sum(abs(v) for v in cnt.values()) ``` +#### Java + ```java class Solution { public int minSteps(String s, String t) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func minSteps(s string, t string) int { cnt := make([]int, 26) @@ -131,6 +139,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function minSteps(s: string, t: string): number { let cnt = new Array(128).fill(0); @@ -148,6 +158,8 @@ function minSteps(s: string, t: string): number { } ``` +#### JavaScript + ```js /** * @param {string} s diff --git a/solution/2100-2199/2186.Minimum Number of Steps to Make Two Strings Anagram II/README_EN.md b/solution/2100-2199/2186.Minimum Number of Steps to Make Two Strings Anagram II/README_EN.md index f6e25855a8d9a..0140739662960 100644 --- a/solution/2100-2199/2186.Minimum Number of Steps to Make Two Strings Anagram II/README_EN.md +++ b/solution/2100-2199/2186.Minimum Number of Steps to Make Two Strings Anagram II/README_EN.md @@ -66,6 +66,8 @@ It can be shown that there is no way to make them anagrams of each other with le +#### Python3 + ```python class Solution: def minSteps(self, s: str, t: str) -> int: @@ -75,6 +77,8 @@ class Solution: return sum(abs(v) for v in cnt.values()) ``` +#### Java + ```java class Solution { public int minSteps(String s, String t) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func minSteps(s string, t string) int { cnt := make([]int, 26) @@ -132,6 +140,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function minSteps(s: string, t: string): number { let cnt = new Array(128).fill(0); @@ -149,6 +159,8 @@ function minSteps(s: string, t: string): number { } ``` +#### JavaScript + ```js /** * @param {string} s diff --git a/solution/2100-2199/2187.Minimum Time to Complete Trips/README.md b/solution/2100-2199/2187.Minimum Time to Complete Trips/README.md index c9264152be8dd..d7a230d9cdfb9 100644 --- a/solution/2100-2199/2187.Minimum Time to Complete Trips/README.md +++ b/solution/2100-2199/2187.Minimum Time to Complete Trips/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def minimumTime(self, time: List[int], totalTrips: int) -> int: @@ -86,6 +88,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public long minimumTime(int[] time, int totalTrips) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func minimumTime(time []int, totalTrips int) int64 { mx := slices.Min(time) * totalTrips @@ -147,6 +155,8 @@ func minimumTime(time []int, totalTrips int) int64 { } ``` +#### TypeScript + ```ts function minimumTime(time: number[], totalTrips: number): number { let left = 1n; diff --git a/solution/2100-2199/2187.Minimum Time to Complete Trips/README_EN.md b/solution/2100-2199/2187.Minimum Time to Complete Trips/README_EN.md index d3b93bc4baf30..47bf8c42401a5 100644 --- a/solution/2100-2199/2187.Minimum Time to Complete Trips/README_EN.md +++ b/solution/2100-2199/2187.Minimum Time to Complete Trips/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n \times \log(m \times k))$, where $n$ and $k$ are the +#### Python3 + ```python class Solution: def minimumTime(self, time: List[int], totalTrips: int) -> int: @@ -86,6 +88,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public long minimumTime(int[] time, int totalTrips) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func minimumTime(time []int, totalTrips int) int64 { mx := slices.Min(time) * totalTrips @@ -147,6 +155,8 @@ func minimumTime(time []int, totalTrips int) int64 { } ``` +#### TypeScript + ```ts function minimumTime(time: number[], totalTrips: number): number { let left = 1n; diff --git a/solution/2100-2199/2188.Minimum Time to Finish the Race/README.md b/solution/2100-2199/2188.Minimum Time to Finish the Race/README.md index 5fda4ab56f4da..2e0bfa100ce36 100644 --- a/solution/2100-2199/2188.Minimum Time to Finish the Race/README.md +++ b/solution/2100-2199/2188.Minimum Time to Finish the Race/README.md @@ -100,6 +100,8 @@ $$ +#### Python3 + ```python class Solution: def minimumFinishTime( @@ -122,6 +124,8 @@ class Solution: return f[numLaps] ``` +#### Java + ```java class Solution { public int minimumFinishTime(int[][] tires, int changeTime, int numLaps) { @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func minimumFinishTime(tires [][]int, changeTime int, numLaps int) int { const inf = 1 << 30 @@ -212,6 +220,8 @@ func minimumFinishTime(tires [][]int, changeTime int, numLaps int) int { } ``` +#### TypeScript + ```ts function minimumFinishTime(tires: number[][], changeTime: number, numLaps: number): number { const cost: number[] = Array(18).fill(Infinity); diff --git a/solution/2100-2199/2188.Minimum Time to Finish the Race/README_EN.md b/solution/2100-2199/2188.Minimum Time to Finish the Race/README_EN.md index a404ea18e2960..b820f96a7dfad 100644 --- a/solution/2100-2199/2188.Minimum Time to Finish the Race/README_EN.md +++ b/solution/2100-2199/2188.Minimum Time to Finish the Race/README_EN.md @@ -82,6 +82,8 @@ The minimum time to complete the race is 25 seconds. +#### Python3 + ```python class Solution: def minimumFinishTime( @@ -104,6 +106,8 @@ class Solution: return f[numLaps] ``` +#### Java + ```java class Solution { public int minimumFinishTime(int[][] tires, int changeTime, int numLaps) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func minimumFinishTime(tires [][]int, changeTime int, numLaps int) int { const inf = 1 << 30 @@ -194,6 +202,8 @@ func minimumFinishTime(tires [][]int, changeTime int, numLaps int) int { } ``` +#### TypeScript + ```ts function minimumFinishTime(tires: number[][], changeTime: number, numLaps: number): number { const cost: number[] = Array(18).fill(Infinity); diff --git a/solution/2100-2199/2189.Number of Ways to Build House of Cards/README.md b/solution/2100-2199/2189.Number of Ways to Build House of Cards/README.md index 440bacccfbe5a..a0717156e998b 100644 --- a/solution/2100-2199/2189.Number of Ways to Build House of Cards/README.md +++ b/solution/2100-2199/2189.Number of Ways to Build House of Cards/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def houseOfCards(self, n: int) -> int: @@ -104,6 +106,8 @@ class Solution: return dfs(n, 0) ``` +#### Java + ```java class Solution { private Integer[][] f; @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func houseOfCards(n int) int { f := make([][]int, n+1) @@ -180,6 +188,8 @@ func houseOfCards(n int) int { } ``` +#### TypeScript + ```ts function houseOfCards(n: number): number { const f: number[][] = Array(n + 1) diff --git a/solution/2100-2199/2189.Number of Ways to Build House of Cards/README_EN.md b/solution/2100-2199/2189.Number of Ways to Build House of Cards/README_EN.md index d1518364b2700..539f86fc31198 100644 --- a/solution/2100-2199/2189.Number of Ways to Build House of Cards/README_EN.md +++ b/solution/2100-2199/2189.Number of Ways to Build House of Cards/README_EN.md @@ -75,6 +75,8 @@ The third house of cards uses 2 cards. +#### Python3 + ```python class Solution: def houseOfCards(self, n: int) -> int: @@ -90,6 +92,8 @@ class Solution: return dfs(n, 0) ``` +#### Java + ```java class Solution { private Integer[][] f; @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func houseOfCards(n int) int { f := make([][]int, n+1) @@ -166,6 +174,8 @@ func houseOfCards(n int) int { } ``` +#### TypeScript + ```ts function houseOfCards(n: number): number { const f: number[][] = Array(n + 1) diff --git a/solution/2100-2199/2190.Most Frequent Number Following Key In an Array/README.md b/solution/2100-2199/2190.Most Frequent Number Following Key In an Array/README.md index a2f9e7c0d503f..6f0ac6f8c4f56 100644 --- a/solution/2100-2199/2190.Most Frequent Number Following Key In an Array/README.md +++ b/solution/2100-2199/2190.Most Frequent Number Following Key In an Array/README.md @@ -79,6 +79,8 @@ target = 2 是紧跟着 key 之后出现次数最多的数字,所以我们返 +#### Python3 + ```python class Solution: def mostFrequent(self, nums: List[int], key: int) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int mostFrequent(int[] nums, int key) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func mostFrequent(nums []int, key int) (ans int) { cnt := [1001]int{} @@ -147,6 +155,8 @@ func mostFrequent(nums []int, key int) (ans int) { } ``` +#### TypeScript + ```ts function mostFrequent(nums: number[], key: number): number { const cnt: number[] = new Array(1001).fill(0); @@ -164,6 +174,8 @@ function mostFrequent(nums: number[], key: number): number { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/2100-2199/2190.Most Frequent Number Following Key In an Array/README_EN.md b/solution/2100-2199/2190.Most Frequent Number Following Key In an Array/README_EN.md index 2c3df85bcbc80..0e0df1f0b9a64 100644 --- a/solution/2100-2199/2190.Most Frequent Number Following Key In an Array/README_EN.md +++ b/solution/2100-2199/2190.Most Frequent Number Following Key In an Array/README_EN.md @@ -71,6 +71,8 @@ target = 2 has the maximum number of occurrences following an occurrence of key, +#### Python3 + ```python class Solution: def mostFrequent(self, nums: List[int], key: int) -> int: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int mostFrequent(int[] nums, int key) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func mostFrequent(nums []int, key int) (ans int) { cnt := [1001]int{} @@ -139,6 +147,8 @@ func mostFrequent(nums []int, key int) (ans int) { } ``` +#### TypeScript + ```ts function mostFrequent(nums: number[], key: number): number { const cnt: number[] = new Array(1001).fill(0); @@ -156,6 +166,8 @@ function mostFrequent(nums: number[], key: number): number { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/2100-2199/2191.Sort the Jumbled Numbers/README.md b/solution/2100-2199/2191.Sort the Jumbled Numbers/README.md index 637ec387a44a2..b54f88cacd5ec 100644 --- a/solution/2100-2199/2191.Sort the Jumbled Numbers/README.md +++ b/solution/2100-2199/2191.Sort the Jumbled Numbers/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def sortJumbled(self, mapping: List[int], nums: List[int]) -> List[int]: @@ -102,6 +104,8 @@ class Solution: return [nums[i] for _, i in arr] ``` +#### Java + ```java class Solution { private int[] mapping; @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func sortJumbled(mapping []int, nums []int) (ans []int) { n := len(nums) @@ -193,6 +201,8 @@ func sortJumbled(mapping []int, nums []int) (ans []int) { } ``` +#### TypeScript + ```ts function sortJumbled(mapping: number[], nums: number[]): number[] { const n = nums.length; @@ -214,6 +224,8 @@ function sortJumbled(mapping: number[], nums: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn sort_jumbled(mapping: Vec, nums: Vec) -> Vec { @@ -249,6 +261,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int[] SortJumbled(int[] mapping, int[] nums) { diff --git a/solution/2100-2199/2191.Sort the Jumbled Numbers/README_EN.md b/solution/2100-2199/2191.Sort the Jumbled Numbers/README_EN.md index b62716bc1b7ce..c60368d7e450e 100644 --- a/solution/2100-2199/2191.Sort the Jumbled Numbers/README_EN.md +++ b/solution/2100-2199/2191.Sort the Jumbled Numbers/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def sortJumbled(self, mapping: List[int], nums: List[int]) -> List[int]: @@ -100,6 +102,8 @@ class Solution: return [nums[i] for _, i in arr] ``` +#### Java + ```java class Solution { private int[] mapping; @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func sortJumbled(mapping []int, nums []int) (ans []int) { n := len(nums) @@ -191,6 +199,8 @@ func sortJumbled(mapping []int, nums []int) (ans []int) { } ``` +#### TypeScript + ```ts function sortJumbled(mapping: number[], nums: number[]): number[] { const n = nums.length; @@ -212,6 +222,8 @@ function sortJumbled(mapping: number[], nums: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn sort_jumbled(mapping: Vec, nums: Vec) -> Vec { @@ -247,6 +259,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int[] SortJumbled(int[] mapping, int[] nums) { diff --git a/solution/2100-2199/2192.All Ancestors of a Node in a Directed Acyclic Graph/README.md b/solution/2100-2199/2192.All Ancestors of a Node in a Directed Acyclic Graph/README.md index e6f2fa9e69f54..b54c27e751be6 100644 --- a/solution/2100-2199/2192.All Ancestors of a Node in a Directed Acyclic Graph/README.md +++ b/solution/2100-2199/2192.All Ancestors of a Node in a Directed Acyclic Graph/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def getAncestors(self, n: int, edges: List[List[int]]) -> List[List[int]]: @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -157,6 +161,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -192,6 +198,8 @@ public: }; ``` +#### Go + ```go func getAncestors(n int, edges [][]int) [][]int { g := make([][]int, n) @@ -222,6 +230,8 @@ func getAncestors(n int, edges [][]int) [][]int { } ``` +#### TypeScript + ```ts function getAncestors(n: number, edges: number[][]): number[][] { const g: number[][] = Array.from({ length: n }, () => []); @@ -251,6 +261,8 @@ function getAncestors(n: number, edges: number[][]): number[][] { } ``` +#### C# + ```cs public class Solution { private int n; diff --git a/solution/2100-2199/2192.All Ancestors of a Node in a Directed Acyclic Graph/README_EN.md b/solution/2100-2199/2192.All Ancestors of a Node in a Directed Acyclic Graph/README_EN.md index 58784df695955..039e61db2ccc7 100644 --- a/solution/2100-2199/2192.All Ancestors of a Node in a Directed Acyclic Graph/README_EN.md +++ b/solution/2100-2199/2192.All Ancestors of a Node in a Directed Acyclic Graph/README_EN.md @@ -88,6 +88,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$. Where $n$ +#### Python3 + ```python class Solution: def getAncestors(self, n: int, edges: List[List[int]]) -> List[List[int]]: @@ -111,6 +113,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -153,6 +157,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go func getAncestors(n int, edges [][]int) [][]int { g := make([][]int, n) @@ -218,6 +226,8 @@ func getAncestors(n int, edges [][]int) [][]int { } ``` +#### TypeScript + ```ts function getAncestors(n: number, edges: number[][]): number[][] { const g: number[][] = Array.from({ length: n }, () => []); @@ -247,6 +257,8 @@ function getAncestors(n: number, edges: number[][]): number[][] { } ``` +#### C# + ```cs public class Solution { private int n; diff --git a/solution/2100-2199/2193.Minimum Number of Moves to Make Palindrome/README.md b/solution/2100-2199/2193.Minimum Number of Moves to Make Palindrome/README.md index 475a293015e38..eee2067b848d1 100644 --- a/solution/2100-2199/2193.Minimum Number of Moves to Make Palindrome/README.md +++ b/solution/2100-2199/2193.Minimum Number of Moves to Make Palindrome/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def minMovesToMakePalindrome(self, s: str) -> int: @@ -114,6 +116,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minMovesToMakePalindrome(String s) { @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go func minMovesToMakePalindrome(s string) int { cs := []byte(s) diff --git a/solution/2100-2199/2193.Minimum Number of Moves to Make Palindrome/README_EN.md b/solution/2100-2199/2193.Minimum Number of Moves to Make Palindrome/README_EN.md index e6c50cb62d082..96b6fbd942e1f 100644 --- a/solution/2100-2199/2193.Minimum Number of Moves to Make Palindrome/README_EN.md +++ b/solution/2100-2199/2193.Minimum Number of Moves to Make Palindrome/README_EN.md @@ -73,6 +73,8 @@ It can be shown that it is not possible to obtain a palindrome in less than 2 mo +#### Python3 + ```python class Solution: def minMovesToMakePalindrome(self, s: str) -> int: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minMovesToMakePalindrome(String s) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func minMovesToMakePalindrome(s string) int { cs := []byte(s) diff --git a/solution/2100-2199/2194.Cells in a Range on an Excel Sheet/README.md b/solution/2100-2199/2194.Cells in a Range on an Excel Sheet/README.md index ebb3cb649ea92..718dfb11b62ed 100644 --- a/solution/2100-2199/2194.Cells in a Range on an Excel Sheet/README.md +++ b/solution/2100-2199/2194.Cells in a Range on an Excel Sheet/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def cellsInRange(self, s: str) -> List[str]: @@ -96,6 +98,8 @@ class Solution: ] ``` +#### Java + ```java class Solution { public List cellsInRange(String s) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func cellsInRange(s string) (ans []string) { for i := s[0]; i <= s[3]; i++ { @@ -136,6 +144,8 @@ func cellsInRange(s string) (ans []string) { } ``` +#### TypeScript + ```ts function cellsInRange(s: string): string[] { const ans: string[] = []; diff --git a/solution/2100-2199/2194.Cells in a Range on an Excel Sheet/README_EN.md b/solution/2100-2199/2194.Cells in a Range on an Excel Sheet/README_EN.md index bf5133fe665fe..683b5033197eb 100644 --- a/solution/2100-2199/2194.Cells in a Range on an Excel Sheet/README_EN.md +++ b/solution/2100-2199/2194.Cells in a Range on an Excel Sheet/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def cellsInRange(self, s: str) -> List[str]: @@ -90,6 +92,8 @@ class Solution: ] ``` +#### Java + ```java class Solution { public List cellsInRange(String s) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func cellsInRange(s string) (ans []string) { for i := s[0]; i <= s[3]; i++ { @@ -130,6 +138,8 @@ func cellsInRange(s string) (ans []string) { } ``` +#### TypeScript + ```ts function cellsInRange(s: string): string[] { const ans: string[] = []; diff --git a/solution/2100-2199/2195.Append K Integers With Minimal Sum/README.md b/solution/2100-2199/2195.Append K Integers With Minimal Sum/README.md index 8b4d9ceed4738..1e4178073fd76 100644 --- a/solution/2100-2199/2195.Append K Integers With Minimal Sum/README.md +++ b/solution/2100-2199/2195.Append K Integers With Minimal Sum/README.md @@ -71,6 +71,8 @@ nums 最终元素和为 5 + 6 + 1 + 2 + 3 + 4 + 7 + 8 = 36 ,这是所有情况 +#### Python3 + ```python class Solution: def minimalKSum(self, nums: List[int], k: int) -> int: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long minimalKSum(int[] nums, int k) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func minimalKSum(nums []int, k int) (ans int64) { nums = append(nums, []int{0, 2e9}...) @@ -135,6 +143,8 @@ func minimalKSum(nums []int, k int) (ans int64) { } ``` +#### TypeScript + ```ts function minimalKSum(nums: number[], k: number): number { nums.push(...[0, 2 * 10 ** 9]); diff --git a/solution/2100-2199/2195.Append K Integers With Minimal Sum/README_EN.md b/solution/2100-2199/2195.Append K Integers With Minimal Sum/README_EN.md index 45f9682d7d87f..7a07e889ec6e7 100644 --- a/solution/2100-2199/2195.Append K Integers With Minimal Sum/README_EN.md +++ b/solution/2100-2199/2195.Append K Integers With Minimal Sum/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def minimalKSum(self, nums: List[int], k: int) -> int: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long minimalKSum(int[] nums, int k) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func minimalKSum(nums []int, k int) (ans int64) { nums = append(nums, []int{0, 2e9}...) @@ -136,6 +144,8 @@ func minimalKSum(nums []int, k int) (ans int64) { } ``` +#### TypeScript + ```ts function minimalKSum(nums: number[], k: number): number { nums.push(...[0, 2 * 10 ** 9]); diff --git a/solution/2100-2199/2196.Create Binary Tree From Descriptions/README.md b/solution/2100-2199/2196.Create Binary Tree From Descriptions/README.md index 4ccdb467d974a..fe5388c1e0233 100644 --- a/solution/2100-2199/2196.Create Binary Tree From Descriptions/README.md +++ b/solution/2100-2199/2196.Create Binary Tree From Descriptions/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -103,6 +105,8 @@ class Solution: return node ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -183,6 +189,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -220,6 +228,8 @@ func createBinaryTree(descriptions [][]int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -267,6 +277,8 @@ function createBinaryTree(descriptions: number[][]): TreeNode | null { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/2100-2199/2196.Create Binary Tree From Descriptions/README_EN.md b/solution/2100-2199/2196.Create Binary Tree From Descriptions/README_EN.md index 2917fb2f028a0..1ed1385d040a3 100644 --- a/solution/2100-2199/2196.Create Binary Tree From Descriptions/README_EN.md +++ b/solution/2100-2199/2196.Create Binary Tree From Descriptions/README_EN.md @@ -72,6 +72,8 @@ The resulting binary tree is shown in the diagram. +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -98,6 +100,8 @@ class Solution: return node ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -178,6 +184,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -215,6 +223,8 @@ func createBinaryTree(descriptions [][]int) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -262,6 +272,8 @@ function createBinaryTree(descriptions: number[][]): TreeNode | null { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/2100-2199/2197.Replace Non-Coprime Numbers in Array/README.md b/solution/2100-2199/2197.Replace Non-Coprime Numbers in Array/README.md index eb9c276b3d481..a428de4ddbd4c 100644 --- a/solution/2100-2199/2197.Replace Non-Coprime Numbers in Array/README.md +++ b/solution/2100-2199/2197.Replace Non-Coprime Numbers in Array/README.md @@ -97,6 +97,8 @@ tags: +#### Python3 + ```python class Solution: def replaceNonCoprimes(self, nums: List[int]) -> List[int]: @@ -113,6 +115,8 @@ class Solution: return stk ``` +#### Java + ```java class Solution { public List replaceNonCoprimes(int[] nums) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func replaceNonCoprimes(nums []int) []int { stk := []int{} @@ -192,6 +200,8 @@ func gcd(a, b int) int { } ``` +#### TypeScript + ```ts function replaceNonCoprimes(nums: number[]): number[] { const gcd = (a: number, b: number): number => { diff --git a/solution/2100-2199/2197.Replace Non-Coprime Numbers in Array/README_EN.md b/solution/2100-2199/2197.Replace Non-Coprime Numbers in Array/README_EN.md index c7e0290513fd7..860a78e33ae49 100644 --- a/solution/2100-2199/2197.Replace Non-Coprime Numbers in Array/README_EN.md +++ b/solution/2100-2199/2197.Replace Non-Coprime Numbers in Array/README_EN.md @@ -95,6 +95,8 @@ The time complexity is $O(n \times \log M)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def replaceNonCoprimes(self, nums: List[int]) -> List[int]: @@ -111,6 +113,8 @@ class Solution: return stk ``` +#### Java + ```java class Solution { public List replaceNonCoprimes(int[] nums) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func replaceNonCoprimes(nums []int) []int { stk := []int{} @@ -190,6 +198,8 @@ func gcd(a, b int) int { } ``` +#### TypeScript + ```ts function replaceNonCoprimes(nums: number[]): number[] { const gcd = (a: number, b: number): number => { diff --git a/solution/2100-2199/2198.Number of Single Divisor Triplets/README.md b/solution/2100-2199/2198.Number of Single Divisor Triplets/README.md index 67c43a35277b0..c67a4f64c9c20 100644 --- a/solution/2100-2199/2198.Number of Single Divisor Triplets/README.md +++ b/solution/2100-2199/2198.Number of Single Divisor Triplets/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def singleDivisorTriplet(self, nums: List[int]) -> int: @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long singleDivisorTriplet(int[] nums) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go func singleDivisorTriplet(nums []int) (ans int64) { cnt := [101]int{} @@ -211,6 +219,8 @@ func singleDivisorTriplet(nums []int) (ans int64) { } ``` +#### TypeScript + ```ts function singleDivisorTriplet(nums: number[]): number { const cnt: number[] = Array(101).fill(0); diff --git a/solution/2100-2199/2198.Number of Single Divisor Triplets/README_EN.md b/solution/2100-2199/2198.Number of Single Divisor Triplets/README_EN.md index bf96b516745d7..897808c40ab88 100644 --- a/solution/2100-2199/2198.Number of Single Divisor Triplets/README_EN.md +++ b/solution/2100-2199/2198.Number of Single Divisor Triplets/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(M^3)$, and the space complexity is $O(M)$. Where $M$ i +#### Python3 + ```python class Solution: def singleDivisorTriplet(self, nums: List[int]) -> int: @@ -103,6 +105,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long singleDivisorTriplet(int[] nums) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go func singleDivisorTriplet(nums []int) (ans int64) { cnt := [101]int{} @@ -208,6 +216,8 @@ func singleDivisorTriplet(nums []int) (ans int64) { } ``` +#### TypeScript + ```ts function singleDivisorTriplet(nums: number[]): number { const cnt: number[] = Array(101).fill(0); diff --git a/solution/2100-2199/2199.Finding the Topic of Each Post/README.md b/solution/2100-2199/2199.Finding the Topic of Each Post/README.md index 6c3c9a2a09744..357f3e76f8670 100644 --- a/solution/2100-2199/2199.Finding the Topic of Each Post/README.md +++ b/solution/2100-2199/2199.Finding the Topic of Each Post/README.md @@ -121,6 +121,8 @@ Posts 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2100-2199/2199.Finding the Topic of Each Post/README_EN.md b/solution/2100-2199/2199.Finding the Topic of Each Post/README_EN.md index af786e0d34bfe..7386b627eae85 100644 --- a/solution/2100-2199/2199.Finding the Topic of Each Post/README_EN.md +++ b/solution/2100-2199/2199.Finding the Topic of Each Post/README_EN.md @@ -122,6 +122,8 @@ Note that it is okay to have one word that expresses more than one topic. +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2200-2299/2200.Find All K-Distant Indices in an Array/README.md b/solution/2200-2299/2200.Find All K-Distant Indices in an Array/README.md index 065d85242ff26..d0f0cc6921a97 100644 --- a/solution/2200-2299/2200.Find All K-Distant Indices in an Array/README.md +++ b/solution/2200-2299/2200.Find All K-Distant Indices in an Array/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def findKDistantIndices(self, nums: List[int], key: int, k: int) -> List[int]: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List findKDistantIndices(int[] nums, int key, int k) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func findKDistantIndices(nums []int, key int, k int) (ans []int) { for i := range nums { @@ -144,6 +152,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function findKDistantIndices(nums: number[], key: number, k: number): number[] { const n = nums.length; @@ -176,6 +186,8 @@ function findKDistantIndices(nums: number[], key: number, k: number): number[] { +#### Python3 + ```python class Solution: def findKDistantIndices(self, nums: List[int], key: int, k: int) -> List[int]: @@ -189,6 +201,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List findKDistantIndices(int[] nums, int key, int k) { @@ -213,6 +227,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -237,6 +253,8 @@ public: }; ``` +#### Go + ```go func findKDistantIndices(nums []int, key int, k int) (ans []int) { idx := []int{} @@ -256,6 +274,8 @@ func findKDistantIndices(nums []int, key int, k int) (ans []int) { } ``` +#### TypeScript + ```ts function findKDistantIndices(nums: number[], key: number, k: number): number[] { const n = nums.length; @@ -303,6 +323,8 @@ function findKDistantIndices(nums: number[], key: number, k: number): number[] { +#### Python3 + ```python class Solution: def findKDistantIndices(self, nums: List[int], key: int, k: int) -> List[int]: @@ -316,6 +338,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List findKDistantIndices(int[] nums, int key, int k) { @@ -334,6 +358,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -353,6 +379,8 @@ public: }; ``` +#### Go + ```go func findKDistantIndices(nums []int, key int, k int) (ans []int) { n := len(nums) @@ -368,6 +396,8 @@ func findKDistantIndices(nums []int, key int, k int) (ans []int) { } ``` +#### TypeScript + ```ts function findKDistantIndices(nums: number[], key: number, k: number): number[] { const n = nums.length; diff --git a/solution/2200-2299/2200.Find All K-Distant Indices in an Array/README_EN.md b/solution/2200-2299/2200.Find All K-Distant Indices in an Array/README_EN.md index a5efe8e75ca33..4bc9425ea523a 100644 --- a/solution/2200-2299/2200.Find All K-Distant Indices in an Array/README_EN.md +++ b/solution/2200-2299/2200.Find All K-Distant Indices in an Array/README_EN.md @@ -73,6 +73,8 @@ The time complexity is $O(n^2)$, where $n$ is the length of the array $nums$. Th +#### Python3 + ```python class Solution: def findKDistantIndices(self, nums: List[int], key: int, k: int) -> List[int]: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List findKDistantIndices(int[] nums, int key, int k) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func findKDistantIndices(nums []int, key int, k int) (ans []int) { for i := range nums { @@ -142,6 +150,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function findKDistantIndices(nums: number[], key: number, k: number): number[] { const n = nums.length; @@ -174,6 +184,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def findKDistantIndices(self, nums: List[int], key: int, k: int) -> List[int]: @@ -187,6 +199,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List findKDistantIndices(int[] nums, int key, int k) { @@ -211,6 +225,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -235,6 +251,8 @@ public: }; ``` +#### Go + ```go func findKDistantIndices(nums []int, key int, k int) (ans []int) { idx := []int{} @@ -254,6 +272,8 @@ func findKDistantIndices(nums []int, key int, k int) (ans []int) { } ``` +#### TypeScript + ```ts function findKDistantIndices(nums: number[], key: number, k: number): number[] { const n = nums.length; @@ -301,6 +321,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def findKDistantIndices(self, nums: List[int], key: int, k: int) -> List[int]: @@ -314,6 +336,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List findKDistantIndices(int[] nums, int key, int k) { @@ -332,6 +356,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -351,6 +377,8 @@ public: }; ``` +#### Go + ```go func findKDistantIndices(nums []int, key int, k int) (ans []int) { n := len(nums) @@ -366,6 +394,8 @@ func findKDistantIndices(nums []int, key int, k int) (ans []int) { } ``` +#### TypeScript + ```ts function findKDistantIndices(nums: number[], key: number, k: number): number[] { const n = nums.length; diff --git a/solution/2200-2299/2201.Count Artifacts That Can Be Extracted/README.md b/solution/2200-2299/2201.Count Artifacts That Can Be Extracted/README.md index 33866ecb0f357..2e57a3d26d0fe 100644 --- a/solution/2200-2299/2201.Count Artifacts That Can Be Extracted/README.md +++ b/solution/2200-2299/2201.Count Artifacts That Can Be Extracted/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def digArtifacts( @@ -105,6 +107,8 @@ class Solution: return sum(check(a) for a in artifacts) ``` +#### Java + ```java class Solution { private Set s = new HashSet<>(); @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func digArtifacts(n int, artifacts [][]int, dig [][]int) (ans int) { s := map[int]bool{} @@ -188,6 +196,8 @@ func digArtifacts(n int, artifacts [][]int, dig [][]int) (ans int) { } ``` +#### TypeScript + ```ts function digArtifacts(n: number, artifacts: number[][], dig: number[][]): number { const s: Set = new Set(); @@ -213,6 +223,8 @@ function digArtifacts(n: number, artifacts: number[][], dig: number[][]): number } ``` +#### Rust + ```rust use std::collections::HashSet; diff --git a/solution/2200-2299/2201.Count Artifacts That Can Be Extracted/README_EN.md b/solution/2200-2299/2201.Count Artifacts That Can Be Extracted/README_EN.md index 44e8497dd31fd..1013e83c1b341 100644 --- a/solution/2200-2299/2201.Count Artifacts That Can Be Extracted/README_EN.md +++ b/solution/2200-2299/2201.Count Artifacts That Can Be Extracted/README_EN.md @@ -90,6 +90,8 @@ The time complexity is $O(m + k)$, and the space complexity is $O(k)$. Here, $m$ +#### Python3 + ```python class Solution: def digArtifacts( @@ -105,6 +107,8 @@ class Solution: return sum(check(a) for a in artifacts) ``` +#### Java + ```java class Solution { private Set s = new HashSet<>(); @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func digArtifacts(n int, artifacts [][]int, dig [][]int) (ans int) { s := map[int]bool{} @@ -188,6 +196,8 @@ func digArtifacts(n int, artifacts [][]int, dig [][]int) (ans int) { } ``` +#### TypeScript + ```ts function digArtifacts(n: number, artifacts: number[][], dig: number[][]): number { const s: Set = new Set(); @@ -213,6 +223,8 @@ function digArtifacts(n: number, artifacts: number[][], dig: number[][]): number } ``` +#### Rust + ```rust use std::collections::HashSet; diff --git a/solution/2200-2299/2202.Maximize the Topmost Element After K Moves/README.md b/solution/2200-2299/2202.Maximize the Topmost Element After K Moves/README.md index 9baf4a9785169..799703ce18a09 100644 --- a/solution/2200-2299/2202.Maximize the Topmost Element After K Moves/README.md +++ b/solution/2200-2299/2202.Maximize the Topmost Element After K Moves/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def maximumTop(self, nums: List[int], k: int) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumTop(int[] nums, int k) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func maximumTop(nums []int, k int) int { if k == 0 { diff --git a/solution/2200-2299/2202.Maximize the Topmost Element After K Moves/README_EN.md b/solution/2200-2299/2202.Maximize the Topmost Element After K Moves/README_EN.md index cc2d863e9a1ad..bb5ea6f89c301 100644 --- a/solution/2200-2299/2202.Maximize the Topmost Element After K Moves/README_EN.md +++ b/solution/2200-2299/2202.Maximize the Topmost Element After K Moves/README_EN.md @@ -75,6 +75,8 @@ Since it is not possible to obtain a non-empty pile after one move, we return -1 +#### Python3 + ```python class Solution: def maximumTop(self, nums: List[int], k: int) -> int: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumTop(int[] nums, int k) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func maximumTop(nums []int, k int) int { if k == 0 { diff --git a/solution/2200-2299/2203.Minimum Weighted Subgraph With the Required Paths/README.md b/solution/2200-2299/2203.Minimum Weighted Subgraph With the Required Paths/README.md index ef039da72c39a..32b122b9652a6 100644 --- a/solution/2200-2299/2203.Minimum Weighted Subgraph With the Required Paths/README.md +++ b/solution/2200-2299/2203.Minimum Weighted Subgraph With the Required Paths/README.md @@ -96,6 +96,8 @@ $A$, $B$ 两条路径一定存在着公共点 $p$,因为 $dest$ 一定是其 +#### Python3 + ```python class Solution: def minimumWeight( @@ -127,6 +129,8 @@ class Solution: return -1 if ans >= inf else ans ``` +#### Java + ```java class Solution { private static final Long INF = Long.MAX_VALUE; diff --git a/solution/2200-2299/2203.Minimum Weighted Subgraph With the Required Paths/README_EN.md b/solution/2200-2299/2203.Minimum Weighted Subgraph With the Required Paths/README_EN.md index 8558efd280c58..945f7bb908482 100644 --- a/solution/2200-2299/2203.Minimum Weighted Subgraph With the Required Paths/README_EN.md +++ b/solution/2200-2299/2203.Minimum Weighted Subgraph With the Required Paths/README_EN.md @@ -74,6 +74,8 @@ It can be seen that there does not exist any path from node 1 to node 2, hence t +#### Python3 + ```python class Solution: def minimumWeight( @@ -105,6 +107,8 @@ class Solution: return -1 if ans >= inf else ans ``` +#### Java + ```java class Solution { private static final Long INF = Long.MAX_VALUE; diff --git a/solution/2200-2299/2204.Distance to a Cycle in Undirected Graph/README.md b/solution/2200-2299/2204.Distance to a Cycle in Undirected Graph/README.md index b544685da9712..82c3b917a97ec 100644 --- a/solution/2200-2299/2204.Distance to a Cycle in Undirected Graph/README.md +++ b/solution/2200-2299/2204.Distance to a Cycle in Undirected Graph/README.md @@ -102,6 +102,8 @@ tags: +#### Python3 + ```python class Solution: def distanceToCycle(self, n: int, edges: List[List[int]]) -> List[int]: @@ -127,6 +129,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] distanceToCycle(int n, int[][] edges) { @@ -166,6 +170,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -208,6 +214,8 @@ public: }; ``` +#### Go + ```go func distanceToCycle(n int, edges [][]int) []int { g := make([]map[int]bool, n) @@ -249,6 +257,8 @@ func distanceToCycle(n int, edges [][]int) []int { } ``` +#### TypeScript + ```ts function distanceToCycle(n: number, edges: number[][]): number[] { const g: Set[] = new Array(n).fill(0).map(() => new Set()); diff --git a/solution/2200-2299/2204.Distance to a Cycle in Undirected Graph/README_EN.md b/solution/2200-2299/2204.Distance to a Cycle in Undirected Graph/README_EN.md index 66625371369ad..414bb6cf6dc90 100644 --- a/solution/2200-2299/2204.Distance to a Cycle in Undirected Graph/README_EN.md +++ b/solution/2200-2299/2204.Distance to a Cycle in Undirected Graph/README_EN.md @@ -102,6 +102,8 @@ Similar problems: +#### Python3 + ```python class Solution: def distanceToCycle(self, n: int, edges: List[List[int]]) -> List[int]: @@ -127,6 +129,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] distanceToCycle(int n, int[][] edges) { @@ -166,6 +170,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -208,6 +214,8 @@ public: }; ``` +#### Go + ```go func distanceToCycle(n int, edges [][]int) []int { g := make([]map[int]bool, n) @@ -249,6 +257,8 @@ func distanceToCycle(n int, edges [][]int) []int { } ``` +#### TypeScript + ```ts function distanceToCycle(n: number, edges: number[][]): number[] { const g: Set[] = new Array(n).fill(0).map(() => new Set()); diff --git a/solution/2200-2299/2205.The Number of Users That Are Eligible for Discount/README.md b/solution/2200-2299/2205.The Number of Users That Are Eligible for Discount/README.md index 6cad81ece296b..6854118c4541a 100644 --- a/solution/2200-2299/2205.The Number of Users That Are Eligible for Discount/README.md +++ b/solution/2200-2299/2205.The Number of Users That Are Eligible for Discount/README.md @@ -78,6 +78,8 @@ startDate = 2022-03-08, endDate = 2022-03-20, minAmount = 1000 +#### MySQL + ```sql CREATE FUNCTION getUserIDs(startDate DATE, endDate DATE, minAmount INT) RETURNS INT BEGIN diff --git a/solution/2200-2299/2205.The Number of Users That Are Eligible for Discount/README_EN.md b/solution/2200-2299/2205.The Number of Users That Are Eligible for Discount/README_EN.md index 679e4492f2511..9d6271546adfd 100644 --- a/solution/2200-2299/2205.The Number of Users That Are Eligible for Discount/README_EN.md +++ b/solution/2200-2299/2205.The Number of Users That Are Eligible for Discount/README_EN.md @@ -76,6 +76,8 @@ Out of the three users, only User 3 is eligible for a discount. +#### MySQL + ```sql CREATE FUNCTION getUserIDs(startDate DATE, endDate DATE, minAmount INT) RETURNS INT BEGIN diff --git a/solution/2200-2299/2206.Divide Array Into Equal Pairs/README.md b/solution/2200-2299/2206.Divide Array Into Equal Pairs/README.md index 2b187989117be..8f888f89578a8 100644 --- a/solution/2200-2299/2206.Divide Array Into Equal Pairs/README.md +++ b/solution/2200-2299/2206.Divide Array Into Equal Pairs/README.md @@ -73,6 +73,8 @@ nums 可以划分成 (2, 2) ,(3, 3) 和 (2, 2) ,满足所有要求。 +#### Python3 + ```python class Solution: def divideArray(self, nums: List[int]) -> bool: @@ -80,6 +82,8 @@ class Solution: return all(v % 2 == 0 for v in cnt.values()) ``` +#### Java + ```java class Solution { public boolean divideArray(int[] nums) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func divideArray(nums []int) bool { cnt := make([]int, 510) diff --git a/solution/2200-2299/2206.Divide Array Into Equal Pairs/README_EN.md b/solution/2200-2299/2206.Divide Array Into Equal Pairs/README_EN.md index ce15956633198..2049b988e5c04 100644 --- a/solution/2200-2299/2206.Divide Array Into Equal Pairs/README_EN.md +++ b/solution/2200-2299/2206.Divide Array Into Equal Pairs/README_EN.md @@ -71,6 +71,8 @@ There is no way to divide nums into 4 / 2 = 2 pairs such that the pairs satisfy +#### Python3 + ```python class Solution: def divideArray(self, nums: List[int]) -> bool: @@ -78,6 +80,8 @@ class Solution: return all(v % 2 == 0 for v in cnt.values()) ``` +#### Java + ```java class Solution { public boolean divideArray(int[] nums) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func divideArray(nums []int) bool { cnt := make([]int, 510) diff --git a/solution/2200-2299/2207.Maximize Number of Subsequences in a String/README.md b/solution/2200-2299/2207.Maximize Number of Subsequences in a String/README.md index 66b3ef9f9a605..65db32d48661b 100644 --- a/solution/2200-2299/2207.Maximize Number of Subsequences in a String/README.md +++ b/solution/2200-2299/2207.Maximize Number of Subsequences in a String/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def maximumSubsequenceCount(self, text: str, pattern: str) -> int: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maximumSubsequenceCount(String text, String pattern) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func maximumSubsequenceCount(text string, pattern string) int64 { ans := 0 diff --git a/solution/2200-2299/2207.Maximize Number of Subsequences in a String/README_EN.md b/solution/2200-2299/2207.Maximize Number of Subsequences in a String/README_EN.md index 48f2b8fbd31b2..4665b50fca998 100644 --- a/solution/2200-2299/2207.Maximize Number of Subsequences in a String/README_EN.md +++ b/solution/2200-2299/2207.Maximize Number of Subsequences in a String/README_EN.md @@ -69,6 +69,8 @@ Some of the strings which can be obtained from text and have 6 subsequences &quo +#### Python3 + ```python class Solution: def maximumSubsequenceCount(self, text: str, pattern: str) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maximumSubsequenceCount(String text, String pattern) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func maximumSubsequenceCount(text string, pattern string) int64 { ans := 0 diff --git a/solution/2200-2299/2208.Minimum Operations to Halve Array Sum/README.md b/solution/2200-2299/2208.Minimum Operations to Halve Array Sum/README.md index 9cb8748fe9570..0318fc275ad1f 100644 --- a/solution/2200-2299/2208.Minimum Operations to Halve Array Sum/README.md +++ b/solution/2200-2299/2208.Minimum Operations to Halve Array Sum/README.md @@ -83,6 +83,8 @@ nums 的和减小了 31 - 14.5 = 16.5 ,减小的部分超过了初始数组和 +#### Python3 + ```python class Solution: def halveArray(self, nums: List[int]) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int halveArray(int[] nums) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func halveArray(nums []int) (ans int) { var s float64 @@ -175,6 +183,8 @@ func (h *hp) Pop() any { } ``` +#### TypeScript + ```ts function halveArray(nums: number[]): number { let s: number = nums.reduce((a, b) => a + b) / 2; @@ -204,6 +214,8 @@ function halveArray(nums: number[]): number { +#### Go + ```go func halveArray(nums []int) (ans int) { half := 0 diff --git a/solution/2200-2299/2208.Minimum Operations to Halve Array Sum/README_EN.md b/solution/2200-2299/2208.Minimum Operations to Halve Array Sum/README_EN.md index efadfe52a6688..80146fe2ea082 100644 --- a/solution/2200-2299/2208.Minimum Operations to Halve Array Sum/README_EN.md +++ b/solution/2200-2299/2208.Minimum Operations to Halve Array Sum/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def halveArray(self, nums: List[int]) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int halveArray(int[] nums) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func halveArray(nums []int) (ans int) { var s float64 @@ -173,6 +181,8 @@ func (h *hp) Pop() any { } ``` +#### TypeScript + ```ts function halveArray(nums: number[]): number { let s: number = nums.reduce((a, b) => a + b) / 2; @@ -202,6 +212,8 @@ function halveArray(nums: number[]): number { +#### Go + ```go func halveArray(nums []int) (ans int) { half := 0 diff --git a/solution/2200-2299/2209.Minimum White Tiles After Covering With Carpets/README.md b/solution/2200-2299/2209.Minimum White Tiles After Covering With Carpets/README.md index 047153f3e21f3..bb4eabb2ad096 100644 --- a/solution/2200-2299/2209.Minimum White Tiles After Covering With Carpets/README.md +++ b/solution/2200-2299/2209.Minimum White Tiles After Covering With Carpets/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def minimumWhiteTiles(self, floor: str, numCarpets: int, carpetLen: int) -> int: @@ -110,6 +112,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[][] f; @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go func minimumWhiteTiles(floor string, numCarpets int, carpetLen int) int { n := len(floor) diff --git a/solution/2200-2299/2209.Minimum White Tiles After Covering With Carpets/README_EN.md b/solution/2200-2299/2209.Minimum White Tiles After Covering With Carpets/README_EN.md index 5c0f1d92c76d5..0d9cd9ff602aa 100644 --- a/solution/2200-2299/2209.Minimum White Tiles After Covering With Carpets/README_EN.md +++ b/solution/2200-2299/2209.Minimum White Tiles After Covering With Carpets/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n\times m)$, and the space complexity is $O(n\times m) +#### Python3 + ```python class Solution: def minimumWhiteTiles(self, floor: str, numCarpets: int, carpetLen: int) -> int: @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[][] f; @@ -147,6 +151,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go func minimumWhiteTiles(floor string, numCarpets int, carpetLen int) int { n := len(floor) diff --git a/solution/2200-2299/2210.Count Hills and Valleys in an Array/README.md b/solution/2200-2299/2210.Count Hills and Valleys in an Array/README.md index 22034f515a545..60bc67710cf29 100644 --- a/solution/2200-2299/2210.Count Hills and Valleys in an Array/README.md +++ b/solution/2200-2299/2210.Count Hills and Valleys in an Array/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def countHillValley(self, nums: List[int]) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countHillValley(int[] nums) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func countHillValley(nums []int) int { ans := 0 @@ -161,6 +169,8 @@ func countHillValley(nums []int) int { } ``` +#### TypeScript + ```ts function countHillValley(nums: number[]): number { let ans = 0; @@ -180,6 +190,8 @@ function countHillValley(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_hill_valley(nums: Vec) -> i32 { diff --git a/solution/2200-2299/2210.Count Hills and Valleys in an Array/README_EN.md b/solution/2200-2299/2210.Count Hills and Valleys in an Array/README_EN.md index 66660e9ab27b8..1ef17fb89abf1 100644 --- a/solution/2200-2299/2210.Count Hills and Valleys in an Array/README_EN.md +++ b/solution/2200-2299/2210.Count Hills and Valleys in an Array/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def countHillValley(self, nums: List[int]) -> int: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countHillValley(int[] nums) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func countHillValley(nums []int) int { ans := 0 @@ -160,6 +168,8 @@ func countHillValley(nums []int) int { } ``` +#### TypeScript + ```ts function countHillValley(nums: number[]): number { let ans = 0; @@ -179,6 +189,8 @@ function countHillValley(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_hill_valley(nums: Vec) -> i32 { diff --git a/solution/2200-2299/2211.Count Collisions on a Road/README.md b/solution/2200-2299/2211.Count Collisions on a Road/README.md index 0e17f06591161..96f15ee59205e 100644 --- a/solution/2200-2299/2211.Count Collisions on a Road/README.md +++ b/solution/2200-2299/2211.Count Collisions on a Road/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def countCollisions(self, directions: str) -> int: @@ -85,6 +87,8 @@ class Solution: return len(d) - d.count('S') ``` +#### Java + ```java class Solution { public int countCollisions(String directions) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func countCollisions(directions string) int { d := strings.TrimLeft(directions, "L") @@ -136,6 +144,8 @@ func countCollisions(directions string) int { } ``` +#### TypeScript + ```ts function countCollisions(directions: string): number { const n = directions.length; diff --git a/solution/2200-2299/2211.Count Collisions on a Road/README_EN.md b/solution/2200-2299/2211.Count Collisions on a Road/README_EN.md index 23df11ac839e6..26d6baee153b7 100644 --- a/solution/2200-2299/2211.Count Collisions on a Road/README_EN.md +++ b/solution/2200-2299/2211.Count Collisions on a Road/README_EN.md @@ -76,6 +76,8 @@ No cars will collide with each other. Thus, the total number of collisions that +#### Python3 + ```python class Solution: def countCollisions(self, directions: str) -> int: @@ -83,6 +85,8 @@ class Solution: return len(d) - d.count('S') ``` +#### Java + ```java class Solution { public int countCollisions(String directions) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func countCollisions(directions string) int { d := strings.TrimLeft(directions, "L") @@ -134,6 +142,8 @@ func countCollisions(directions string) int { } ``` +#### TypeScript + ```ts function countCollisions(directions: string): number { const n = directions.length; diff --git a/solution/2200-2299/2212.Maximum Points in an Archery Competition/README.md b/solution/2200-2299/2212.Maximum Points in an Archery Competition/README.md index f7cb65e3eac70..1289804aba490 100644 --- a/solution/2200-2299/2212.Maximum Points in an Archery Competition/README.md +++ b/solution/2200-2299/2212.Maximum Points in an Archery Competition/README.md @@ -95,6 +95,8 @@ Bob 获得总分 8 + 9 + 10 = 27 。 +#### Python3 + ```python class Solution: def maximumBobPoints(self, numArrows: int, aliceArrows: List[int]) -> List[int]: @@ -119,6 +121,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] maximumBobPoints(int numArrows, int[] aliceArrows) { @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -183,6 +189,8 @@ public: }; ``` +#### Go + ```go func maximumBobPoints(numArrows int, aliceArrows []int) []int { n := len(aliceArrows) @@ -212,6 +220,8 @@ func maximumBobPoints(numArrows int, aliceArrows []int) []int { } ``` +#### TypeScript + ```ts function maximumBobPoints(numArrows: number, aliceArrows: number[]): number[] { const dfs = (arr: number[], i: number, c: number): number[] => { @@ -236,6 +246,8 @@ function maximumBobPoints(numArrows: number, aliceArrows: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { fn dfs(alice_arrows: &Vec, mut res: Vec, count: i32, i: usize) -> Vec { diff --git a/solution/2200-2299/2212.Maximum Points in an Archery Competition/README_EN.md b/solution/2200-2299/2212.Maximum Points in an Archery Competition/README_EN.md index cf928751aefed..c6ef77c7979f7 100644 --- a/solution/2200-2299/2212.Maximum Points in an Archery Competition/README_EN.md +++ b/solution/2200-2299/2212.Maximum Points in an Archery Competition/README_EN.md @@ -87,6 +87,8 @@ It can be shown that Bob cannot obtain a score higher than 27 points. +#### Python3 + ```python class Solution: def maximumBobPoints(self, numArrows: int, aliceArrows: List[int]) -> List[int]: @@ -111,6 +113,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] maximumBobPoints(int numArrows, int[] aliceArrows) { @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go func maximumBobPoints(numArrows int, aliceArrows []int) []int { n := len(aliceArrows) @@ -204,6 +212,8 @@ func maximumBobPoints(numArrows int, aliceArrows []int) []int { } ``` +#### TypeScript + ```ts function maximumBobPoints(numArrows: number, aliceArrows: number[]): number[] { const dfs = (arr: number[], i: number, c: number): number[] => { @@ -228,6 +238,8 @@ function maximumBobPoints(numArrows: number, aliceArrows: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { fn dfs(alice_arrows: &Vec, mut res: Vec, count: i32, i: usize) -> Vec { diff --git a/solution/2200-2299/2213.Longest Substring of One Repeating Character/README.md b/solution/2200-2299/2213.Longest Substring of One Repeating Character/README.md index 30c26b0f8d73f..d043ddb31eb7b 100644 --- a/solution/2200-2299/2213.Longest Substring of One Repeating Character/README.md +++ b/solution/2200-2299/2213.Longest Substring of One Repeating Character/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Node: def __init__(self): @@ -180,6 +182,8 @@ class Solution: return ans ``` +#### Java + ```java class Node { int l; @@ -298,6 +302,8 @@ class Solution { } ``` +#### C++ + ```cpp class Node { public: @@ -395,6 +401,8 @@ public: }; ``` +#### Go + ```go type segmentTree struct { str []byte diff --git a/solution/2200-2299/2213.Longest Substring of One Repeating Character/README_EN.md b/solution/2200-2299/2213.Longest Substring of One Repeating Character/README_EN.md index 35f6c789f349a..356e1eb9df251 100644 --- a/solution/2200-2299/2213.Longest Substring of One Repeating Character/README_EN.md +++ b/solution/2200-2299/2213.Longest Substring of One Repeating Character/README_EN.md @@ -74,6 +74,8 @@ Thus, we return [2,3]. +#### Python3 + ```python class Node: def __init__(self): @@ -165,6 +167,8 @@ class Solution: return ans ``` +#### Java + ```java class Node { int l; @@ -283,6 +287,8 @@ class Solution { } ``` +#### C++ + ```cpp class Node { public: @@ -380,6 +386,8 @@ public: }; ``` +#### Go + ```go type segmentTree struct { str []byte diff --git a/solution/2200-2299/2214.Minimum Health to Beat Game/README.md b/solution/2200-2299/2214.Minimum Health to Beat Game/README.md index 8405a9f180891..03ad47dfe2fe9 100644 --- a/solution/2200-2299/2214.Minimum Health to Beat Game/README.md +++ b/solution/2200-2299/2214.Minimum Health to Beat Game/README.md @@ -89,12 +89,16 @@ tags: +#### Python3 + ```python class Solution: def minimumHealth(self, damage: List[int], armor: int) -> int: return sum(damage) - min(max(damage), armor) + 1 ``` +#### Java + ```java class Solution { public long minimumHealth(int[] damage, int armor) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func minimumHealth(damage []int, armor int) int64 { var s int64 @@ -136,6 +144,8 @@ func minimumHealth(damage []int, armor int) int64 { } ``` +#### TypeScript + ```ts function minimumHealth(damage: number[], armor: number): number { let s = 0; diff --git a/solution/2200-2299/2214.Minimum Health to Beat Game/README_EN.md b/solution/2200-2299/2214.Minimum Health to Beat Game/README_EN.md index 7d905c63ac6ef..452854014cf69 100644 --- a/solution/2200-2299/2214.Minimum Health to Beat Game/README_EN.md +++ b/solution/2200-2299/2214.Minimum Health to Beat Game/README_EN.md @@ -88,12 +88,16 @@ The time complexity is $O(n)$, where $n$ is the length of the `damage` array. Th +#### Python3 + ```python class Solution: def minimumHealth(self, damage: List[int], armor: int) -> int: return sum(damage) - min(max(damage), armor) + 1 ``` +#### Java + ```java class Solution { public long minimumHealth(int[] damage, int armor) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func minimumHealth(damage []int, armor int) int64 { var s int64 @@ -135,6 +143,8 @@ func minimumHealth(damage []int, armor int) int64 { } ``` +#### TypeScript + ```ts function minimumHealth(damage: number[], armor: number): number { let s = 0; diff --git a/solution/2200-2299/2215.Find the Difference of Two Arrays/README.md b/solution/2200-2299/2215.Find the Difference of Two Arrays/README.md index f0ebb4bc30743..14c3d5d8ff90d 100644 --- a/solution/2200-2299/2215.Find the Difference of Two Arrays/README.md +++ b/solution/2200-2299/2215.Find the Difference of Two Arrays/README.md @@ -72,6 +72,8 @@ nums2 中的每个整数都在 nums1 中出现,因此,answer[1] = [] 。 +#### Python3 + ```python class Solution: def findDifference(self, nums1: List[int], nums2: List[int]) -> List[List[int]]: @@ -79,6 +81,8 @@ class Solution: return [list(s1 - s2), list(s2 - s1)] ``` +#### Java + ```java class Solution { public List> findDifference(int[] nums1, int[] nums2) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func findDifference(nums1 []int, nums2 []int) [][]int { s1, s2 := make(map[int]bool), make(map[int]bool) @@ -155,6 +163,8 @@ func findDifference(nums1 []int, nums2 []int) [][]int { } ``` +#### TypeScript + ```ts function findDifference(nums1: number[], nums2: number[]): number[][] { const s1: Set = new Set(nums1); @@ -165,6 +175,8 @@ function findDifference(nums1: number[], nums2: number[]): number[][] { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -187,6 +199,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums1 @@ -202,6 +216,8 @@ var findDifference = function (nums1, nums2) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/2200-2299/2215.Find the Difference of Two Arrays/README_EN.md b/solution/2200-2299/2215.Find the Difference of Two Arrays/README_EN.md index a5457e6136f67..458ea5b8fef56 100644 --- a/solution/2200-2299/2215.Find the Difference of Two Arrays/README_EN.md +++ b/solution/2200-2299/2215.Find the Difference of Two Arrays/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def findDifference(self, nums1: List[int], nums2: List[int]) -> List[List[int]]: @@ -77,6 +79,8 @@ class Solution: return [list(s1 - s2), list(s2 - s1)] ``` +#### Java + ```java class Solution { public List> findDifference(int[] nums1, int[] nums2) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func findDifference(nums1 []int, nums2 []int) [][]int { s1, s2 := make(map[int]bool), make(map[int]bool) @@ -153,6 +161,8 @@ func findDifference(nums1 []int, nums2 []int) [][]int { } ``` +#### TypeScript + ```ts function findDifference(nums1: number[], nums2: number[]): number[][] { const s1: Set = new Set(nums1); @@ -163,6 +173,8 @@ function findDifference(nums1: number[], nums2: number[]): number[][] { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -185,6 +197,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums1 @@ -200,6 +214,8 @@ var findDifference = function (nums1, nums2) { }; ``` +#### PHP + ```php class Solution { /** diff --git a/solution/2200-2299/2216.Minimum Deletions to Make Array Beautiful/README.md b/solution/2200-2299/2216.Minimum Deletions to Make Array Beautiful/README.md index c2268aa3575aa..2446602e814e1 100644 --- a/solution/2200-2299/2216.Minimum Deletions to Make Array Beautiful/README.md +++ b/solution/2200-2299/2216.Minimum Deletions to Make Array Beautiful/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def minDeletion(self, nums: List[int]) -> int: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minDeletion(int[] nums) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func minDeletion(nums []int) (ans int) { n := len(nums) @@ -142,6 +150,8 @@ func minDeletion(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function minDeletion(nums: number[]): number { const n = nums.length; @@ -158,6 +168,8 @@ function minDeletion(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_deletion(nums: Vec) -> i32 { @@ -188,6 +200,8 @@ impl Solution { +#### Python3 + ```python class Solution: def minDeletion(self, nums: List[int]) -> int: @@ -203,6 +217,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minDeletion(int[] nums) { @@ -222,6 +238,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -242,6 +260,8 @@ public: }; ``` +#### Go + ```go func minDeletion(nums []int) (ans int) { n := len(nums) @@ -257,6 +277,8 @@ func minDeletion(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function minDeletion(nums: number[]): number { const n = nums.length; @@ -273,6 +295,8 @@ function minDeletion(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_deletion(nums: Vec) -> i32 { diff --git a/solution/2200-2299/2216.Minimum Deletions to Make Array Beautiful/README_EN.md b/solution/2200-2299/2216.Minimum Deletions to Make Array Beautiful/README_EN.md index b26e5e5a6611c..61646d0dcfb42 100644 --- a/solution/2200-2299/2216.Minimum Deletions to Make Array Beautiful/README_EN.md +++ b/solution/2200-2299/2216.Minimum Deletions to Make Array Beautiful/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. We only nee +#### Python3 + ```python class Solution: def minDeletion(self, nums: List[int]) -> int: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minDeletion(int[] nums) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func minDeletion(nums []int) (ans int) { n := len(nums) @@ -143,6 +151,8 @@ func minDeletion(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function minDeletion(nums: number[]): number { const n = nums.length; @@ -159,6 +169,8 @@ function minDeletion(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_deletion(nums: Vec) -> i32 { @@ -189,6 +201,8 @@ impl Solution { +#### Python3 + ```python class Solution: def minDeletion(self, nums: List[int]) -> int: @@ -204,6 +218,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minDeletion(int[] nums) { @@ -223,6 +239,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -243,6 +261,8 @@ public: }; ``` +#### Go + ```go func minDeletion(nums []int) (ans int) { n := len(nums) @@ -258,6 +278,8 @@ func minDeletion(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function minDeletion(nums: number[]): number { const n = nums.length; @@ -274,6 +296,8 @@ function minDeletion(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_deletion(nums: Vec) -> i32 { diff --git a/solution/2200-2299/2217.Find Palindrome With Fixed Length/README.md b/solution/2200-2299/2217.Find Palindrome With Fixed Length/README.md index 8f5f3e5221386..851bbc91a6085 100644 --- a/solution/2200-2299/2217.Find Palindrome With Fixed Length/README.md +++ b/solution/2200-2299/2217.Find Palindrome With Fixed Length/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def kthPalindrome(self, queries: List[int], intLength: int) -> List[int]: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long[] kthPalindrome(int[] queries, int intLength) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func kthPalindrome(queries []int, intLength int) []int64 { l := (intLength + 1) >> 1 @@ -155,6 +163,8 @@ func kthPalindrome(queries []int, intLength int) []int64 { } ``` +#### TypeScript + ```ts function kthPalindrome(queries: number[], intLength: number): number[] { const isOdd = intLength % 2 === 1; @@ -177,6 +187,8 @@ function kthPalindrome(queries: number[], intLength: number): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn kth_palindrome(queries: Vec, int_length: i32) -> Vec { diff --git a/solution/2200-2299/2217.Find Palindrome With Fixed Length/README_EN.md b/solution/2200-2299/2217.Find Palindrome With Fixed Length/README_EN.md index c2d58437a307e..ee98f5a69e744 100644 --- a/solution/2200-2299/2217.Find Palindrome With Fixed Length/README_EN.md +++ b/solution/2200-2299/2217.Find Palindrome With Fixed Length/README_EN.md @@ -64,6 +64,8 @@ The first six palindromes of length 4 are: +#### Python3 + ```python class Solution: def kthPalindrome(self, queries: List[int], intLength: int) -> List[int]: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long[] kthPalindrome(int[] queries, int intLength) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func kthPalindrome(queries []int, intLength int) []int64 { l := (intLength + 1) >> 1 @@ -153,6 +161,8 @@ func kthPalindrome(queries []int, intLength int) []int64 { } ``` +#### TypeScript + ```ts function kthPalindrome(queries: number[], intLength: number): number[] { const isOdd = intLength % 2 === 1; @@ -175,6 +185,8 @@ function kthPalindrome(queries: number[], intLength: number): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn kth_palindrome(queries: Vec, int_length: i32) -> Vec { diff --git a/solution/2200-2299/2218.Maximum Value of K Coins From Piles/README.md b/solution/2200-2299/2218.Maximum Value of K Coins From Piles/README.md index 65369dc5a0b44..99afcc122fd0f 100644 --- a/solution/2200-2299/2218.Maximum Value of K Coins From Piles/README.md +++ b/solution/2200-2299/2218.Maximum Value of K Coins From Piles/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def maxValueOfCoins(self, piles: List[List[int]], k: int) -> int: @@ -92,6 +94,8 @@ class Solution: return dp[-1][-1] ``` +#### Java + ```java class Solution { public int maxValueOfCoins(List> piles, int k) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func maxValueOfCoins(piles [][]int, k int) int { var presum [][]int @@ -179,6 +187,8 @@ func maxValueOfCoins(piles [][]int, k int) int { +#### Python3 + ```python class Solution: def maxValueOfCoins(self, piles: List[List[int]], k: int) -> int: diff --git a/solution/2200-2299/2218.Maximum Value of K Coins From Piles/README_EN.md b/solution/2200-2299/2218.Maximum Value of K Coins From Piles/README_EN.md index d9e6a7ee8b42e..9cacb442c8d8c 100644 --- a/solution/2200-2299/2218.Maximum Value of K Coins From Piles/README_EN.md +++ b/solution/2200-2299/2218.Maximum Value of K Coins From Piles/README_EN.md @@ -66,6 +66,8 @@ The maximum total we can obtain is 101. +#### Python3 + ```python class Solution: def maxValueOfCoins(self, piles: List[List[int]], k: int) -> int: @@ -80,6 +82,8 @@ class Solution: return dp[-1][-1] ``` +#### Java + ```java class Solution { public int maxValueOfCoins(List> piles, int k) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func maxValueOfCoins(piles [][]int, k int) int { var presum [][]int @@ -167,6 +175,8 @@ func maxValueOfCoins(piles [][]int, k int) int { +#### Python3 + ```python class Solution: def maxValueOfCoins(self, piles: List[List[int]], k: int) -> int: diff --git a/solution/2200-2299/2219.Maximum Sum Score of Array/README.md b/solution/2200-2299/2219.Maximum Sum Score of Array/README.md index dcd2b27d75a86..7bdd953e6528a 100644 --- a/solution/2200-2299/2219.Maximum Sum Score of Array/README.md +++ b/solution/2200-2299/2219.Maximum Sum Score of Array/README.md @@ -74,6 +74,8 @@ nums 可取得的最大总分是 -3 。 +#### Python3 + ```python class Solution: def maximumSumScore(self, nums: List[int]) -> int: @@ -81,6 +83,8 @@ class Solution: return max(max(s[i + 1], s[-1] - s[i]) for i in range(len(nums))) ``` +#### Java + ```java class Solution { public long maximumSumScore(int[] nums) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func maximumSumScore(nums []int) int64 { n := len(nums) @@ -127,6 +135,8 @@ func maximumSumScore(nums []int) int64 { } ``` +#### TypeScript + ```ts function maximumSumScore(nums: number[]): number { const n = nums.length; @@ -142,6 +152,8 @@ function maximumSumScore(nums: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/2200-2299/2219.Maximum Sum Score of Array/README_EN.md b/solution/2200-2299/2219.Maximum Sum Score of Array/README_EN.md index c3998960fabd1..1a6507db26ad9 100644 --- a/solution/2200-2299/2219.Maximum Sum Score of Array/README_EN.md +++ b/solution/2200-2299/2219.Maximum Sum Score of Array/README_EN.md @@ -72,6 +72,8 @@ The maximum sum score of nums is -3. +#### Python3 + ```python class Solution: def maximumSumScore(self, nums: List[int]) -> int: @@ -79,6 +81,8 @@ class Solution: return max(max(s[i + 1], s[-1] - s[i]) for i in range(len(nums))) ``` +#### Java + ```java class Solution { public long maximumSumScore(int[] nums) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func maximumSumScore(nums []int) int64 { n := len(nums) @@ -125,6 +133,8 @@ func maximumSumScore(nums []int) int64 { } ``` +#### TypeScript + ```ts function maximumSumScore(nums: number[]): number { const n = nums.length; @@ -140,6 +150,8 @@ function maximumSumScore(nums: number[]): number { } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/2200-2299/2220.Minimum Bit Flips to Convert Number/README.md b/solution/2200-2299/2220.Minimum Bit Flips to Convert Number/README.md index 68dab8f85a1be..f536c47fa0c77 100644 --- a/solution/2200-2299/2220.Minimum Bit Flips to Convert Number/README.md +++ b/solution/2200-2299/2220.Minimum Bit Flips to Convert Number/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def minBitFlips(self, start: int, goal: int) -> int: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minBitFlips(int start, int goal) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func minBitFlips(start int, goal int) int { t := start ^ goal @@ -121,6 +129,8 @@ func minBitFlips(start int, goal int) int { } ``` +#### TypeScript + ```ts function minBitFlips(start: number, goal: number): number { let tmp = start ^ goal; @@ -133,6 +143,8 @@ function minBitFlips(start: number, goal: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_bit_flips(start: i32, goal: i32) -> i32 { @@ -147,6 +159,8 @@ impl Solution { } ``` +#### C + ```c int minBitFlips(int start, int goal) { int tmp = start ^ goal; diff --git a/solution/2200-2299/2220.Minimum Bit Flips to Convert Number/README_EN.md b/solution/2200-2299/2220.Minimum Bit Flips to Convert Number/README_EN.md index 08307c2bcbe86..162f652c598d5 100644 --- a/solution/2200-2299/2220.Minimum Bit Flips to Convert Number/README_EN.md +++ b/solution/2200-2299/2220.Minimum Bit Flips to Convert Number/README_EN.md @@ -67,6 +67,8 @@ It can be shown we cannot convert 3 to 4 in less than 3 steps. Hence, we return +#### Python3 + ```python class Solution: def minBitFlips(self, start: int, goal: int) -> int: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minBitFlips(int start, int goal) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func minBitFlips(start int, goal int) int { t := start ^ goal @@ -119,6 +127,8 @@ func minBitFlips(start int, goal int) int { } ``` +#### TypeScript + ```ts function minBitFlips(start: number, goal: number): number { let tmp = start ^ goal; @@ -131,6 +141,8 @@ function minBitFlips(start: number, goal: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_bit_flips(start: i32, goal: i32) -> i32 { @@ -145,6 +157,8 @@ impl Solution { } ``` +#### C + ```c int minBitFlips(int start, int goal) { int tmp = start ^ goal; diff --git a/solution/2200-2299/2221.Find Triangular Sum of an Array/README.md b/solution/2200-2299/2221.Find Triangular Sum of an Array/README.md index 24dd4bd39202b..d090fccb30c1f 100644 --- a/solution/2200-2299/2221.Find Triangular Sum of an Array/README.md +++ b/solution/2200-2299/2221.Find Triangular Sum of an Array/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def triangularSum(self, nums: List[int]) -> int: @@ -83,6 +85,8 @@ class Solution: return nums[0] ``` +#### Java + ```java class Solution { public int triangularSum(int[] nums) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func triangularSum(nums []int) int { n := len(nums) diff --git a/solution/2200-2299/2221.Find Triangular Sum of an Array/README_EN.md b/solution/2200-2299/2221.Find Triangular Sum of an Array/README_EN.md index 25061cbd55da8..77103da95bd7d 100644 --- a/solution/2200-2299/2221.Find Triangular Sum of an Array/README_EN.md +++ b/solution/2200-2299/2221.Find Triangular Sum of an Array/README_EN.md @@ -69,6 +69,8 @@ Since there is only one element in nums, the triangular sum is the value of that +#### Python3 + ```python class Solution: def triangularSum(self, nums: List[int]) -> int: @@ -79,6 +81,8 @@ class Solution: return nums[0] ``` +#### Java + ```java class Solution { public int triangularSum(int[] nums) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func triangularSum(nums []int) int { n := len(nums) diff --git a/solution/2200-2299/2222.Number of Ways to Select Buildings/README.md b/solution/2200-2299/2222.Number of Ways to Select Buildings/README.md index 1257228ff37c7..6106143c1db59 100644 --- a/solution/2200-2299/2222.Number of Ways to Select Buildings/README.md +++ b/solution/2200-2299/2222.Number of Ways to Select Buildings/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfWays(self, s: str) -> int: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long numberOfWays(String s) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func numberOfWays(s string) int64 { n := len(s) diff --git a/solution/2200-2299/2222.Number of Ways to Select Buildings/README_EN.md b/solution/2200-2299/2222.Number of Ways to Select Buildings/README_EN.md index da28b35c07c8c..af2039eccefbf 100644 --- a/solution/2200-2299/2222.Number of Ways to Select Buildings/README_EN.md +++ b/solution/2200-2299/2222.Number of Ways to Select Buildings/README_EN.md @@ -78,6 +78,8 @@ No other selection is valid. Thus, there are 6 total ways. +#### Python3 + ```python class Solution: def numberOfWays(self, s: str) -> int: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long numberOfWays(String s) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func numberOfWays(s string) int64 { n := len(s) diff --git a/solution/2200-2299/2223.Sum of Scores of Built Strings/README.md b/solution/2200-2299/2223.Sum of Scores of Built Strings/README.md index 7cb749b186862..3e778ddf43d40 100644 --- a/solution/2200-2299/2223.Sum of Scores of Built Strings/README.md +++ b/solution/2200-2299/2223.Sum of Scores of Built Strings/README.md @@ -80,18 +80,26 @@ s9 == "azbazbzaz" ,最长公共前缀为 "azbazbzaz" ,得分为 9 +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2200-2299/2223.Sum of Scores of Built Strings/README_EN.md b/solution/2200-2299/2223.Sum of Scores of Built Strings/README_EN.md index 5abc7b2e1ecf2..94d436fff9fdf 100644 --- a/solution/2200-2299/2223.Sum of Scores of Built Strings/README_EN.md +++ b/solution/2200-2299/2223.Sum of Scores of Built Strings/README_EN.md @@ -78,18 +78,26 @@ The sum of the scores is 2 + 3 + 9 = 14, so we return 14. +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2200-2299/2224.Minimum Number of Operations to Convert Time/README.md b/solution/2200-2299/2224.Minimum Number of Operations to Convert Time/README.md index 647ec9b69d758..2f8cea033daf4 100644 --- a/solution/2200-2299/2224.Minimum Number of Operations to Convert Time/README.md +++ b/solution/2200-2299/2224.Minimum Number of Operations to Convert Time/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def convertTime(self, current: str, correct: str) -> int: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int convertTime(String current, String correct) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func convertTime(current string, correct string) int { parse := func(s string) int { diff --git a/solution/2200-2299/2224.Minimum Number of Operations to Convert Time/README_EN.md b/solution/2200-2299/2224.Minimum Number of Operations to Convert Time/README_EN.md index 94b5bd681ba91..d970cdedc7411 100644 --- a/solution/2200-2299/2224.Minimum Number of Operations to Convert Time/README_EN.md +++ b/solution/2200-2299/2224.Minimum Number of Operations to Convert Time/README_EN.md @@ -66,6 +66,8 @@ It can be proven that it is not possible to convert current to correct in fewer +#### Python3 + ```python class Solution: def convertTime(self, current: str, correct: str) -> int: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int convertTime(String current, String correct) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func convertTime(current string, correct string) int { parse := func(s string) int { diff --git a/solution/2200-2299/2225.Find Players With Zero or One Losses/README.md b/solution/2200-2299/2225.Find Players With Zero or One Losses/README.md index 90aece568bb3a..4a5522ee74b42 100644 --- a/solution/2200-2299/2225.Find Players With Zero or One Losses/README.md +++ b/solution/2200-2299/2225.Find Players With Zero or One Losses/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def findWinners(self, matches: List[List[int]]) -> List[List[int]]: @@ -103,6 +105,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> findWinners(int[][] matches) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func findWinners(matches [][]int) [][]int { cnt := map[int]int{} @@ -172,6 +180,8 @@ func findWinners(matches [][]int) [][]int { } ``` +#### TypeScript + ```ts function findWinners(matches: number[][]): number[][] { const cnt: Map = new Map(); @@ -191,6 +201,8 @@ function findWinners(matches: number[][]): number[][] { } ``` +#### JavaScript + ```js /** * @param {number[][]} matches @@ -224,6 +236,8 @@ var findWinners = function (matches) { +#### JavaScript + ```js /** * @param {number[][]} matches diff --git a/solution/2200-2299/2225.Find Players With Zero or One Losses/README_EN.md b/solution/2200-2299/2225.Find Players With Zero or One Losses/README_EN.md index 8f3f92222f6e0..9213f286c6d58 100644 --- a/solution/2200-2299/2225.Find Players With Zero or One Losses/README_EN.md +++ b/solution/2200-2299/2225.Find Players With Zero or One Losses/README_EN.md @@ -84,6 +84,8 @@ Thus, answer[0] = [1,2,5,6] and answer[1] = []. +#### Python3 + ```python class Solution: def findWinners(self, matches: List[List[int]]) -> List[List[int]]: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> findWinners(int[][] matches) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func findWinners(matches [][]int) [][]int { cnt := map[int]int{} @@ -170,6 +178,8 @@ func findWinners(matches [][]int) [][]int { } ``` +#### TypeScript + ```ts function findWinners(matches: number[][]): number[][] { const cnt: Map = new Map(); @@ -189,6 +199,8 @@ function findWinners(matches: number[][]): number[][] { } ``` +#### JavaScript + ```js /** * @param {number[][]} matches @@ -222,6 +234,8 @@ var findWinners = function (matches) { +#### JavaScript + ```js /** * @param {number[][]} matches diff --git a/solution/2200-2299/2226.Maximum Candies Allocated to K Children/README.md b/solution/2200-2299/2226.Maximum Candies Allocated to K Children/README.md index 0c42df4160bc4..eda1ef547b603 100644 --- a/solution/2200-2299/2226.Maximum Candies Allocated to K Children/README.md +++ b/solution/2200-2299/2226.Maximum Candies Allocated to K Children/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def maximumCandies(self, candies: List[int], k: int) -> int: @@ -79,6 +81,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int maximumCandies(int[] candies, long k) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func maximumCandies(candies []int, k int64) int { left, right := 0, int(1e7) diff --git a/solution/2200-2299/2226.Maximum Candies Allocated to K Children/README_EN.md b/solution/2200-2299/2226.Maximum Candies Allocated to K Children/README_EN.md index bb2c669ec4c3f..1e549fd12040b 100644 --- a/solution/2200-2299/2226.Maximum Candies Allocated to K Children/README_EN.md +++ b/solution/2200-2299/2226.Maximum Candies Allocated to K Children/README_EN.md @@ -60,6 +60,8 @@ tags: +#### Python3 + ```python class Solution: def maximumCandies(self, candies: List[int], k: int) -> int: @@ -74,6 +76,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { public int maximumCandies(int[] candies, long k) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func maximumCandies(candies []int, k int64) int { left, right := 0, int(1e7) diff --git a/solution/2200-2299/2227.Encrypt and Decrypt Strings/README.md b/solution/2200-2299/2227.Encrypt and Decrypt Strings/README.md index c5d7d9bb11a47..2d6ebcfefa55b 100644 --- a/solution/2200-2299/2227.Encrypt and Decrypt Strings/README.md +++ b/solution/2200-2299/2227.Encrypt and Decrypt Strings/README.md @@ -95,6 +95,8 @@ encrypter.decrypt("eizfeiam"); // return 2. +#### Python3 + ```python class Encrypter: def __init__(self, keys: List[str], values: List[str], dictionary: List[str]): @@ -119,6 +121,8 @@ class Encrypter: # param_2 = obj.decrypt(word2) ``` +#### Java + ```java class Encrypter { private Map mp = new HashMap<>(); @@ -158,6 +162,8 @@ class Encrypter { */ ``` +#### C++ + ```cpp class Encrypter { public: @@ -191,6 +197,8 @@ public: */ ``` +#### Go + ```go type Encrypter struct { mp map[byte]string diff --git a/solution/2200-2299/2227.Encrypt and Decrypt Strings/README_EN.md b/solution/2200-2299/2227.Encrypt and Decrypt Strings/README_EN.md index 6b5ea23c829ab..8151f492c79ec 100644 --- a/solution/2200-2299/2227.Encrypt and Decrypt Strings/README_EN.md +++ b/solution/2200-2299/2227.Encrypt and Decrypt Strings/README_EN.md @@ -95,6 +95,8 @@ encrypter.decrypt("eizfeiam"); // return 2. +#### Python3 + ```python class Encrypter: def __init__(self, keys: List[str], values: List[str], dictionary: List[str]): @@ -119,6 +121,8 @@ class Encrypter: # param_2 = obj.decrypt(word2) ``` +#### Java + ```java class Encrypter { private Map mp = new HashMap<>(); @@ -158,6 +162,8 @@ class Encrypter { */ ``` +#### C++ + ```cpp class Encrypter { public: @@ -191,6 +197,8 @@ public: */ ``` +#### Go + ```go type Encrypter struct { mp map[byte]string diff --git a/solution/2200-2299/2228.Users With Two Purchases Within Seven Days/README.md b/solution/2200-2299/2228.Users With Two Purchases Within Seven Days/README.md index 5651981824a08..f180f9ddb8941 100644 --- a/solution/2200-2299/2228.Users With Two Purchases Within Seven Days/README.md +++ b/solution/2200-2299/2228.Users With Two Purchases Within Seven Days/README.md @@ -77,6 +77,8 @@ Purchases 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2200-2299/2228.Users With Two Purchases Within Seven Days/README_EN.md b/solution/2200-2299/2228.Users With Two Purchases Within Seven Days/README_EN.md index 636693411fed6..1244012cb304d 100644 --- a/solution/2200-2299/2228.Users With Two Purchases Within Seven Days/README_EN.md +++ b/solution/2200-2299/2228.Users With Two Purchases Within Seven Days/README_EN.md @@ -77,6 +77,8 @@ User 7 had two purchases on the same day so we add their ID. +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2200-2299/2229.Check if an Array Is Consecutive/README.md b/solution/2200-2299/2229.Check if an Array Is Consecutive/README.md index 246ba3361d348..24d8ac69375f0 100644 --- a/solution/2200-2299/2229.Check if an Array Is Consecutive/README.md +++ b/solution/2200-2299/2229.Check if an Array Is Consecutive/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def isConsecutive(self, nums: List[int]) -> bool: @@ -83,6 +85,8 @@ class Solution: return len(set(nums)) == n and mx == mi + n - 1 ``` +#### Java + ```java class Solution { public boolean isConsecutive(int[] nums) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func isConsecutive(nums []int) bool { s := map[int]bool{} diff --git a/solution/2200-2299/2229.Check if an Array Is Consecutive/README_EN.md b/solution/2200-2299/2229.Check if an Array Is Consecutive/README_EN.md index e7b64c252ef03..d1529274fc66a 100644 --- a/solution/2200-2299/2229.Check if an Array Is Consecutive/README_EN.md +++ b/solution/2200-2299/2229.Check if an Array Is Consecutive/README_EN.md @@ -74,6 +74,8 @@ Therefore, nums is consecutive. +#### Python3 + ```python class Solution: def isConsecutive(self, nums: List[int]) -> bool: @@ -82,6 +84,8 @@ class Solution: return len(set(nums)) == n and mx == mi + n - 1 ``` +#### Java + ```java class Solution { public boolean isConsecutive(int[] nums) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func isConsecutive(nums []int) bool { s := map[int]bool{} diff --git a/solution/2200-2299/2230.The Users That Are Eligible for Discount/README.md b/solution/2200-2299/2230.The Users That Are Eligible for Discount/README.md index 82137291c5e24..2758a9eea4878 100644 --- a/solution/2200-2299/2230.The Users That Are Eligible for Discount/README.md +++ b/solution/2200-2299/2230.The Users That Are Eligible for Discount/README.md @@ -75,6 +75,8 @@ startDate = 2022-03-08, endDate = 2022-03-20, minAmount = 1000 +#### MySQL + ```sql CREATE PROCEDURE getUserIDs(startDate DATE, endDate DATE, minAmount INT) BEGIN diff --git a/solution/2200-2299/2230.The Users That Are Eligible for Discount/README_EN.md b/solution/2200-2299/2230.The Users That Are Eligible for Discount/README_EN.md index 88fd80d27e8a0..bdaa134779f8b 100644 --- a/solution/2200-2299/2230.The Users That Are Eligible for Discount/README_EN.md +++ b/solution/2200-2299/2230.The Users That Are Eligible for Discount/README_EN.md @@ -81,6 +81,8 @@ Out of the three users, only User 3 is eligible for a discount. +#### MySQL + ```sql CREATE PROCEDURE getUserIDs(startDate DATE, endDate DATE, minAmount INT) BEGIN diff --git a/solution/2200-2299/2231.Largest Number After Digit Swaps by Parity/README.md b/solution/2200-2299/2231.Largest Number After Digit Swaps by Parity/README.md index 8f9c25be56c03..dcbe22b610ee5 100644 --- a/solution/2200-2299/2231.Largest Number After Digit Swaps by Parity/README.md +++ b/solution/2200-2299/2231.Largest Number After Digit Swaps by Parity/README.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def largestInteger(self, num: int) -> int: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int largestInteger(int num) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func largestInteger(num int) int { cnt := make([]int, 10) @@ -169,6 +177,8 @@ func largestInteger(num int) int { } ``` +#### TypeScript + ```ts function largestInteger(num: number): number { const arrs: number[] = String(num).split('').map(Number); diff --git a/solution/2200-2299/2231.Largest Number After Digit Swaps by Parity/README_EN.md b/solution/2200-2299/2231.Largest Number After Digit Swaps by Parity/README_EN.md index 10863b94f9af2..24b59f7539e32 100644 --- a/solution/2200-2299/2231.Largest Number After Digit Swaps by Parity/README_EN.md +++ b/solution/2200-2299/2231.Largest Number After Digit Swaps by Parity/README_EN.md @@ -62,6 +62,8 @@ Note that there may be other sequences of swaps but it can be shown that 87655 i +#### Python3 + ```python class Solution: def largestInteger(self, num: int) -> int: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int largestInteger(int num) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func largestInteger(num int) int { cnt := make([]int, 10) @@ -169,6 +177,8 @@ func largestInteger(num int) int { } ``` +#### TypeScript + ```ts function largestInteger(num: number): number { const arrs: number[] = String(num).split('').map(Number); diff --git a/solution/2200-2299/2232.Minimize Result by Adding Parentheses to Expression/README.md b/solution/2200-2299/2232.Minimize Result by Adding Parentheses to Expression/README.md index 71ca6b817e574..e867683341d80 100644 --- a/solution/2200-2299/2232.Minimize Result by Adding Parentheses to Expression/README.md +++ b/solution/2200-2299/2232.Minimize Result by Adding Parentheses to Expression/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def minimizeResult(self, expression: str) -> str: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String minimizeResult(String expression) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### TypeScript + ```ts function minimizeResult(expression: string): string { const [n1, n2] = expression.split('+'); diff --git a/solution/2200-2299/2232.Minimize Result by Adding Parentheses to Expression/README_EN.md b/solution/2200-2299/2232.Minimize Result by Adding Parentheses to Expression/README_EN.md index a2690312c3cf7..584b5ef9f9c2b 100644 --- a/solution/2200-2299/2232.Minimize Result by Adding Parentheses to Expression/README_EN.md +++ b/solution/2200-2299/2232.Minimize Result by Adding Parentheses to Expression/README_EN.md @@ -75,6 +75,8 @@ It can be shown that 170 is the smallest possible value. +#### Python3 + ```python class Solution: def minimizeResult(self, expression: str) -> str: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String minimizeResult(String expression) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### TypeScript + ```ts function minimizeResult(expression: string): string { const [n1, n2] = expression.split('+'); diff --git a/solution/2200-2299/2233.Maximum Product After K Increments/README.md b/solution/2200-2299/2233.Maximum Product After K Increments/README.md index 6214f549299da..a4152a059f5d7 100644 --- a/solution/2200-2299/2233.Maximum Product After K Increments/README.md +++ b/solution/2200-2299/2233.Maximum Product After K Increments/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def maximumProduct(self, nums: List[int], k: int) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func maximumProduct(nums []int, k int) int { h := hp{nums} @@ -141,6 +149,8 @@ func (hp) Push(any) {} func (hp) Pop() (_ any) { return } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/2200-2299/2233.Maximum Product After K Increments/README_EN.md b/solution/2200-2299/2233.Maximum Product After K Increments/README_EN.md index 4a569fb486e0e..d695ef8547689 100644 --- a/solution/2200-2299/2233.Maximum Product After K Increments/README_EN.md +++ b/solution/2200-2299/2233.Maximum Product After K Increments/README_EN.md @@ -65,6 +65,8 @@ Note that there may be other ways to increment nums to have the maximum product. +#### Python3 + ```python class Solution: def maximumProduct(self, nums: List[int], k: int) -> int: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func maximumProduct(nums []int, k int) int { h := hp{nums} @@ -137,6 +145,8 @@ func (hp) Push(any) {} func (hp) Pop() (_ any) { return } ``` +#### JavaScript + ```js /** * @param {number[]} nums diff --git a/solution/2200-2299/2234.Maximum Total Beauty of the Gardens/README.md b/solution/2200-2299/2234.Maximum Total Beauty of the Gardens/README.md index 8c2eff75fcc67..04cdcc1b200f1 100644 --- a/solution/2200-2299/2234.Maximum Total Beauty of the Gardens/README.md +++ b/solution/2200-2299/2234.Maximum Total Beauty of the Gardens/README.md @@ -103,6 +103,8 @@ tags: +#### Python3 + ```python class Solution: def maximumBeauty( @@ -131,6 +133,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maximumBeauty(int[] flowers, long newFlowers, int target, int full, int partial) { @@ -173,6 +177,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -214,6 +220,8 @@ public: }; ``` +#### Go + ```go func maximumBeauty(flowers []int, newFlowers int64, target int, full int, partial int) int64 { sort.Ints(flowers) @@ -251,6 +259,8 @@ func maximumBeauty(flowers []int, newFlowers int64, target int, full int, partia } ``` +#### TypeScript + ```ts function maximumBeauty( flowers: number[], diff --git a/solution/2200-2299/2234.Maximum Total Beauty of the Gardens/README_EN.md b/solution/2200-2299/2234.Maximum Total Beauty of the Gardens/README_EN.md index 919d77ec0a88e..1ac2b03a66353 100644 --- a/solution/2200-2299/2234.Maximum Total Beauty of the Gardens/README_EN.md +++ b/solution/2200-2299/2234.Maximum Total Beauty of the Gardens/README_EN.md @@ -91,6 +91,8 @@ Note that Alice could make all the gardens complete but in this case, she would +#### Python3 + ```python class Solution: def maximumBeauty( @@ -119,6 +121,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maximumBeauty(int[] flowers, long newFlowers, int target, int full, int partial) { @@ -161,6 +165,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -202,6 +208,8 @@ public: }; ``` +#### Go + ```go func maximumBeauty(flowers []int, newFlowers int64, target int, full int, partial int) int64 { sort.Ints(flowers) @@ -239,6 +247,8 @@ func maximumBeauty(flowers []int, newFlowers int64, target int, full int, partia } ``` +#### TypeScript + ```ts function maximumBeauty( flowers: number[], diff --git a/solution/2200-2299/2235.Add Two Integers/README.md b/solution/2200-2299/2235.Add Two Integers/README.md index 1c7b6edd95619..39ccbeeca053b 100644 --- a/solution/2200-2299/2235.Add Two Integers/README.md +++ b/solution/2200-2299/2235.Add Two Integers/README.md @@ -58,12 +58,16 @@ tags: +#### Python3 + ```python class Solution: def sum(self, num1: int, num2: int) -> int: return num1 + num2 ``` +#### Java + ```java class Solution { public int sum(int num1, int num2) { @@ -72,6 +76,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -81,18 +87,24 @@ public: }; ``` +#### Go + ```go func sum(num1 int, num2 int) int { return num1 + num2 } ``` +#### TypeScript + ```ts function sum(num1: number, num2: number): number { return num1 + num2; } ``` +#### Rust + ```rust impl Solution { pub fn sum(num1: i32, num2: i32) -> i32 { @@ -101,6 +113,8 @@ impl Solution { } ``` +#### C + ```c int sum(int num1, int num2) { return num1 + num2; @@ -139,6 +153,8 @@ int sum(int num1, int num2) { +#### Python3 + ```python class Solution: def sum(self, num1: int, num2: int) -> int: @@ -149,6 +165,8 @@ class Solution: return num1 if num1 < 0x80000000 else ~(num1 ^ 0xFFFFFFFF) ``` +#### Java + ```java class Solution { public int sum(int num1, int num2) { @@ -162,6 +180,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +196,8 @@ public: }; ``` +#### Go + ```go func sum(num1 int, num2 int) int { for num2 != 0 { @@ -187,6 +209,8 @@ func sum(num1 int, num2 int) int { } ``` +#### TypeScript + ```ts function sum(num1: number, num2: number): number { while (num2) { @@ -198,6 +222,8 @@ function sum(num1: number, num2: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn sum(num1: i32, num2: i32) -> i32 { diff --git a/solution/2200-2299/2235.Add Two Integers/README_EN.md b/solution/2200-2299/2235.Add Two Integers/README_EN.md index 3e91cc910d2ea..cd35272ab35a8 100644 --- a/solution/2200-2299/2235.Add Two Integers/README_EN.md +++ b/solution/2200-2299/2235.Add Two Integers/README_EN.md @@ -52,12 +52,16 @@ Given two integers num1 and num2, return the +#### Python3 + ```python class Solution: def sum(self, num1: int, num2: int) -> int: return num1 + num2 ``` +#### Java + ```java class Solution { public int sum(int num1, int num2) { @@ -66,6 +70,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -75,18 +81,24 @@ public: }; ``` +#### Go + ```go func sum(num1 int, num2 int) int { return num1 + num2 } ``` +#### TypeScript + ```ts function sum(num1: number, num2: number): number { return num1 + num2; } ``` +#### Rust + ```rust impl Solution { pub fn sum(num1: i32, num2: i32) -> i32 { @@ -95,6 +107,8 @@ impl Solution { } ``` +#### C + ```c int sum(int num1, int num2) { return num1 + num2; @@ -111,6 +125,8 @@ int sum(int num1, int num2) { +#### Python3 + ```python class Solution: def sum(self, num1: int, num2: int) -> int: @@ -121,6 +137,8 @@ class Solution: return num1 if num1 < 0x80000000 else ~(num1 ^ 0xFFFFFFFF) ``` +#### Java + ```java class Solution { public int sum(int num1, int num2) { @@ -134,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +168,8 @@ public: }; ``` +#### Go + ```go func sum(num1 int, num2 int) int { for num2 != 0 { @@ -159,6 +181,8 @@ func sum(num1 int, num2 int) int { } ``` +#### TypeScript + ```ts function sum(num1: number, num2: number): number { while (num2) { @@ -170,6 +194,8 @@ function sum(num1: number, num2: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn sum(num1: i32, num2: i32) -> i32 { diff --git a/solution/2200-2299/2236.Root Equals Sum of Children/README.md b/solution/2200-2299/2236.Root Equals Sum of Children/README.md index 5140623d1493c..be9b82f8ae1b2 100644 --- a/solution/2200-2299/2236.Root Equals Sum of Children/README.md +++ b/solution/2200-2299/2236.Root Equals Sum of Children/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -76,6 +78,8 @@ class Solution: return root.val == root.left.val + root.right.val ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -133,6 +141,8 @@ func checkTree(root *TreeNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -153,6 +163,8 @@ function checkTree(root: TreeNode | null): boolean { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -184,6 +196,8 @@ impl Solution { } ``` +#### C + ```c /** * Definition for a binary tree node. diff --git a/solution/2200-2299/2236.Root Equals Sum of Children/README_EN.md b/solution/2200-2299/2236.Root Equals Sum of Children/README_EN.md index 7ff4a6dc08d5e..ad9c083f61929 100644 --- a/solution/2200-2299/2236.Root Equals Sum of Children/README_EN.md +++ b/solution/2200-2299/2236.Root Equals Sum of Children/README_EN.md @@ -58,6 +58,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -70,6 +72,8 @@ class Solution: return root.val == root.left.val + root.right.val ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -127,6 +135,8 @@ func checkTree(root *TreeNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -147,6 +157,8 @@ function checkTree(root: TreeNode | null): boolean { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -178,6 +190,8 @@ impl Solution { } ``` +#### C + ```c /** * Definition for a binary tree node. diff --git a/solution/2200-2299/2237.Count Positions on Street With Required Brightness/README.md b/solution/2200-2299/2237.Count Positions on Street With Required Brightness/README.md index dde0c8ebffee8..643644df7470e 100644 --- a/solution/2200-2299/2237.Count Positions on Street With Required Brightness/README.md +++ b/solution/2200-2299/2237.Count Positions on Street With Required Brightness/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def meetRequirement( @@ -94,6 +96,8 @@ class Solution: return sum(s >= r for s, r in zip(accumulate(d), requirement)) ``` +#### Java + ```java class Solution { public int meetRequirement(int n, int[][] lights, int[] requirement) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func meetRequirement(n int, lights [][]int, requirement []int) int { d := make([]int, 100010) diff --git a/solution/2200-2299/2237.Count Positions on Street With Required Brightness/README_EN.md b/solution/2200-2299/2237.Count Positions on Street With Required Brightness/README_EN.md index 0220e8306c03e..3a9e28455a101 100644 --- a/solution/2200-2299/2237.Count Positions on Street With Required Brightness/README_EN.md +++ b/solution/2200-2299/2237.Count Positions on Street With Required Brightness/README_EN.md @@ -77,6 +77,8 @@ Positions 0, 1, 2, and 4 meet the requirement so we return 4. +#### Python3 + ```python class Solution: def meetRequirement( @@ -90,6 +92,8 @@ class Solution: return sum(s >= r for s, r in zip(accumulate(d), requirement)) ``` +#### Java + ```java class Solution { public int meetRequirement(int n, int[][] lights, int[] requirement) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func meetRequirement(n int, lights [][]int, requirement []int) int { d := make([]int, 100010) diff --git a/solution/2200-2299/2238.Number of Times a Driver Was a Passenger/README.md b/solution/2200-2299/2238.Number of Times a Driver Was a Passenger/README.md index e683dea82902f..03c511f6d6f29 100644 --- a/solution/2200-2299/2238.Number of Times a Driver Was a Passenger/README.md +++ b/solution/2200-2299/2238.Number of Times a Driver Was a Passenger/README.md @@ -77,6 +77,8 @@ ID = 11 的司机从来不是乘客。 +#### MySQL + ```sql # Write your MySQL query statement below WITH T AS (SELECT DISTINCT driver_id FROM Rides) diff --git a/solution/2200-2299/2238.Number of Times a Driver Was a Passenger/README_EN.md b/solution/2200-2299/2238.Number of Times a Driver Was a Passenger/README_EN.md index 3fbe593fe5240..9d70fea7151fc 100644 --- a/solution/2200-2299/2238.Number of Times a Driver Was a Passenger/README_EN.md +++ b/solution/2200-2299/2238.Number of Times a Driver Was a Passenger/README_EN.md @@ -78,6 +78,8 @@ The driver with ID = 11 was never a passenger. +#### MySQL + ```sql # Write your MySQL query statement below WITH T AS (SELECT DISTINCT driver_id FROM Rides) diff --git a/solution/2200-2299/2239.Find Closest Number to Zero/README.md b/solution/2200-2299/2239.Find Closest Number to Zero/README.md index 826f1183b4c01..c1711f87b107d 100644 --- a/solution/2200-2299/2239.Find Closest Number to Zero/README.md +++ b/solution/2200-2299/2239.Find Closest Number to Zero/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def findClosestNumber(self, nums: List[int]) -> int: @@ -77,6 +79,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findClosestNumber(int[] nums) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func findClosestNumber(nums []int) int { ans, d := 0, 1<<30 @@ -129,6 +137,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function findClosestNumber(nums: number[]): number { let [ans, d] = [0, 1 << 30]; diff --git a/solution/2200-2299/2239.Find Closest Number to Zero/README_EN.md b/solution/2200-2299/2239.Find Closest Number to Zero/README_EN.md index a9da13853d940..23720b28cd3cc 100644 --- a/solution/2200-2299/2239.Find Closest Number to Zero/README_EN.md +++ b/solution/2200-2299/2239.Find Closest Number to Zero/README_EN.md @@ -60,6 +60,8 @@ Thus, the closest number to 0 in the array is 1. +#### Python3 + ```python class Solution: def findClosestNumber(self, nums: List[int]) -> int: @@ -70,6 +72,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findClosestNumber(int[] nums) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -103,6 +109,8 @@ public: }; ``` +#### Go + ```go func findClosestNumber(nums []int) int { ans, d := 0, 1<<30 @@ -122,6 +130,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function findClosestNumber(nums: number[]): number { let [ans, d] = [0, 1 << 30]; diff --git a/solution/2200-2299/2240.Number of Ways to Buy Pens and Pencils/README.md b/solution/2200-2299/2240.Number of Ways to Buy Pens and Pencils/README.md index 564eaaf7682ba..dcdf52b7e82fd 100644 --- a/solution/2200-2299/2240.Number of Ways to Buy Pens and Pencils/README.md +++ b/solution/2200-2299/2240.Number of Ways to Buy Pens and Pencils/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int: @@ -75,6 +77,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long waysToBuyPensPencils(int total, int cost1, int cost2) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -102,6 +108,8 @@ public: }; ``` +#### Go + ```go func waysToBuyPensPencils(total int, cost1 int, cost2 int) (ans int64) { for x := 0; x <= total/cost1; x++ { @@ -112,6 +120,8 @@ func waysToBuyPensPencils(total int, cost1 int, cost2 int) (ans int64) { } ``` +#### TypeScript + ```ts function waysToBuyPensPencils(total: number, cost1: number, cost2: number): number { let ans = 0; @@ -123,6 +133,8 @@ function waysToBuyPensPencils(total: number, cost1: number, cost2: number): numb } ``` +#### Rust + ```rust impl Solution { pub fn ways_to_buy_pens_pencils(total: i32, cost1: i32, cost2: i32) -> i64 { diff --git a/solution/2200-2299/2240.Number of Ways to Buy Pens and Pencils/README_EN.md b/solution/2200-2299/2240.Number of Ways to Buy Pens and Pencils/README_EN.md index 2874fa27ea5c4..7e6f4037e915b 100644 --- a/solution/2200-2299/2240.Number of Ways to Buy Pens and Pencils/README_EN.md +++ b/solution/2200-2299/2240.Number of Ways to Buy Pens and Pencils/README_EN.md @@ -61,6 +61,8 @@ The total number of ways to buy pens and pencils is 5 + 3 + 1 = 9. +#### Python3 + ```python class Solution: def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int: @@ -71,6 +73,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long waysToBuyPensPencils(int total, int cost1, int cost2) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -98,6 +104,8 @@ public: }; ``` +#### Go + ```go func waysToBuyPensPencils(total int, cost1 int, cost2 int) (ans int64) { for x := 0; x <= total/cost1; x++ { @@ -108,6 +116,8 @@ func waysToBuyPensPencils(total int, cost1 int, cost2 int) (ans int64) { } ``` +#### TypeScript + ```ts function waysToBuyPensPencils(total: number, cost1: number, cost2: number): number { let ans = 0; @@ -119,6 +129,8 @@ function waysToBuyPensPencils(total: number, cost1: number, cost2: number): numb } ``` +#### Rust + ```rust impl Solution { pub fn ways_to_buy_pens_pencils(total: i32, cost1: i32, cost2: i32) -> i64 { diff --git a/solution/2200-2299/2241.Design an ATM Machine/README.md b/solution/2200-2299/2241.Design an ATM Machine/README.md index 7d7dbb2a77158..503ca9a2b6c92 100644 --- a/solution/2200-2299/2241.Design an ATM Machine/README.md +++ b/solution/2200-2299/2241.Design an ATM Machine/README.md @@ -86,6 +86,8 @@ atm.withdraw(550); // 返回 [0,1,0,0,1] ,机器会返回 1 张 $50 的 +#### Python3 + ```python class ATM: def __init__(self): @@ -114,6 +116,8 @@ class ATM: # param_2 = obj.withdraw(amount) ``` +#### Java + ```java class ATM { private long[] cnt = new long[5]; @@ -152,6 +156,8 @@ class ATM { */ ``` +#### C++ + ```cpp class ATM { public: @@ -192,6 +198,8 @@ private: */ ``` +#### Go + ```go type ATM struct { d [5]int diff --git a/solution/2200-2299/2241.Design an ATM Machine/README_EN.md b/solution/2200-2299/2241.Design an ATM Machine/README_EN.md index ee1ea4e7f5c13..a35605b8ec5d7 100644 --- a/solution/2200-2299/2241.Design an ATM Machine/README_EN.md +++ b/solution/2200-2299/2241.Design an ATM Machine/README_EN.md @@ -86,6 +86,8 @@ atm.withdraw(550); // Returns [0,1,0,0,1]. The machine uses 1 $50 banknot +#### Python3 + ```python class ATM: def __init__(self): @@ -114,6 +116,8 @@ class ATM: # param_2 = obj.withdraw(amount) ``` +#### Java + ```java class ATM { private long[] cnt = new long[5]; @@ -152,6 +156,8 @@ class ATM { */ ``` +#### C++ + ```cpp class ATM { public: @@ -192,6 +198,8 @@ private: */ ``` +#### Go + ```go type ATM struct { d [5]int diff --git a/solution/2200-2299/2242.Maximum Score of a Node Sequence/README.md b/solution/2200-2299/2242.Maximum Score of a Node Sequence/README.md index cc2897b1ec5de..56d40385823e8 100644 --- a/solution/2200-2299/2242.Maximum Score of a Node Sequence/README.md +++ b/solution/2200-2299/2242.Maximum Score of a Node Sequence/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def maximumScore(self, scores: List[int], edges: List[List[int]]) -> int: @@ -109,6 +111,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumScore(int[] scores, int[][] edges) { diff --git a/solution/2200-2299/2242.Maximum Score of a Node Sequence/README_EN.md b/solution/2200-2299/2242.Maximum Score of a Node Sequence/README_EN.md index 3208f253a9ea0..0c4d2e05a5588 100644 --- a/solution/2200-2299/2242.Maximum Score of a Node Sequence/README_EN.md +++ b/solution/2200-2299/2242.Maximum Score of a Node Sequence/README_EN.md @@ -82,6 +82,8 @@ There are no valid node sequences of length 4, so we return -1. +#### Python3 + ```python class Solution: def maximumScore(self, scores: List[int], edges: List[List[int]]) -> int: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumScore(int[] scores, int[][] edges) { diff --git a/solution/2200-2299/2243.Calculate Digit Sum of a String/README.md b/solution/2200-2299/2243.Calculate Digit Sum of a String/README.md index 28bebf9e9e163..0a686aa5b5dd6 100644 --- a/solution/2200-2299/2243.Calculate Digit Sum of a String/README.md +++ b/solution/2200-2299/2243.Calculate Digit Sum of a String/README.md @@ -81,6 +81,8 @@ s 变为 "0" + "0" + "0" = "000" ,其长度等于 k ,所以返回 "000" 。 +#### Python3 + ```python class Solution: def digitSum(self, s: str, k: int) -> str: @@ -96,6 +98,8 @@ class Solution: return s ``` +#### Java + ```java class Solution { public String digitSum(String s, int k) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func digitSum(s string, k int) string { for len(s) > k { @@ -155,6 +163,8 @@ func digitSum(s string, k int) string { } ``` +#### TypeScript + ```ts function digitSum(s: string, k: number): string { let ans = []; @@ -180,6 +190,8 @@ function digitSum(s: string, k: number): string { +#### Python3 + ```python class Solution: def digitSum(self, s: str, k: int) -> str: diff --git a/solution/2200-2299/2243.Calculate Digit Sum of a String/README_EN.md b/solution/2200-2299/2243.Calculate Digit Sum of a String/README_EN.md index 65f1586347f78..24f5b5e1dc55e 100644 --- a/solution/2200-2299/2243.Calculate Digit Sum of a String/README_EN.md +++ b/solution/2200-2299/2243.Calculate Digit Sum of a String/README_EN.md @@ -77,6 +77,8 @@ s becomes "0" + "0" + "0" = "000", whose +#### Python3 + ```python class Solution: def digitSum(self, s: str, k: int) -> str: @@ -92,6 +94,8 @@ class Solution: return s ``` +#### Java + ```java class Solution { public String digitSum(String s, int k) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func digitSum(s string, k int) string { for len(s) > k { @@ -151,6 +159,8 @@ func digitSum(s string, k int) string { } ``` +#### TypeScript + ```ts function digitSum(s: string, k: number): string { let ans = []; @@ -176,6 +186,8 @@ function digitSum(s: string, k: number): string { +#### Python3 + ```python class Solution: def digitSum(self, s: str, k: int) -> str: diff --git a/solution/2200-2299/2244.Minimum Rounds to Complete All Tasks/README.md b/solution/2200-2299/2244.Minimum Rounds to Complete All Tasks/README.md index f01be368c6ef6..cb66ca61fd4bf 100644 --- a/solution/2200-2299/2244.Minimum Rounds to Complete All Tasks/README.md +++ b/solution/2200-2299/2244.Minimum Rounds to Complete All Tasks/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def minimumRounds(self, tasks: List[int]) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumRounds(int[] tasks) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func minimumRounds(tasks []int) int { cnt := map[int]int{} @@ -142,6 +150,8 @@ func minimumRounds(tasks []int) int { } ``` +#### TypeScript + ```ts function minimumRounds(tasks: number[]): number { const cnt = new Map(); @@ -159,6 +169,8 @@ function minimumRounds(tasks: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/2200-2299/2244.Minimum Rounds to Complete All Tasks/README_EN.md b/solution/2200-2299/2244.Minimum Rounds to Complete All Tasks/README_EN.md index 7af6ed9eaa1b4..17bc5c86bb95e 100644 --- a/solution/2200-2299/2244.Minimum Rounds to Complete All Tasks/README_EN.md +++ b/solution/2200-2299/2244.Minimum Rounds to Complete All Tasks/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python class Solution: def minimumRounds(self, tasks: List[int]) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumRounds(int[] tasks) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func minimumRounds(tasks []int) int { cnt := map[int]int{} @@ -142,6 +150,8 @@ func minimumRounds(tasks []int) int { } ``` +#### TypeScript + ```ts function minimumRounds(tasks: number[]): number { const cnt = new Map(); @@ -159,6 +169,8 @@ function minimumRounds(tasks: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/2200-2299/2245.Maximum Trailing Zeros in a Cornered Path/README.md b/solution/2200-2299/2245.Maximum Trailing Zeros in a Cornered Path/README.md index 279e3676fdbd0..cf3ef8bdb1980 100644 --- a/solution/2200-2299/2245.Maximum Trailing Zeros in a Cornered Path/README.md +++ b/solution/2200-2299/2245.Maximum Trailing Zeros in a Cornered Path/README.md @@ -109,6 +109,8 @@ tags: +#### Python3 + ```python class Solution: def maxTrailingZeros(self, grid: List[List[int]]) -> int: @@ -144,6 +146,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxTrailingZeros(int[][] grid) { @@ -184,6 +188,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -224,6 +230,8 @@ public: }; ``` +#### Go + ```go func maxTrailingZeros(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -268,6 +276,8 @@ func get(m, n int) [][]int { } ``` +#### TypeScript + ```ts function maxTrailingZeros(grid: number[][]): number { const m = grid.length; diff --git a/solution/2200-2299/2245.Maximum Trailing Zeros in a Cornered Path/README_EN.md b/solution/2200-2299/2245.Maximum Trailing Zeros in a Cornered Path/README_EN.md index 680bf7a95c446..41e4af7ed2368 100644 --- a/solution/2200-2299/2245.Maximum Trailing Zeros in a Cornered Path/README_EN.md +++ b/solution/2200-2299/2245.Maximum Trailing Zeros in a Cornered Path/README_EN.md @@ -104,6 +104,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def maxTrailingZeros(self, grid: List[List[int]]) -> int: @@ -139,6 +141,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxTrailingZeros(int[][] grid) { @@ -179,6 +183,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -219,6 +225,8 @@ public: }; ``` +#### Go + ```go func maxTrailingZeros(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -263,6 +271,8 @@ func get(m, n int) [][]int { } ``` +#### TypeScript + ```ts function maxTrailingZeros(grid: number[][]): number { const m = grid.length; diff --git a/solution/2200-2299/2246.Longest Path With Different Adjacent Characters/README.md b/solution/2200-2299/2246.Longest Path With Different Adjacent Characters/README.md index 2ade39b779901..501aca50235d8 100644 --- a/solution/2200-2299/2246.Longest Path With Different Adjacent Characters/README.md +++ b/solution/2200-2299/2246.Longest Path With Different Adjacent Characters/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def longestPath(self, parent: List[int], s: str) -> int: @@ -104,6 +106,8 @@ class Solution: return ans + 1 ``` +#### Java + ```java class Solution { private List[] g; @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func longestPath(parent []int, s string) int { n := len(parent) @@ -188,6 +196,8 @@ func longestPath(parent []int, s string) int { } ``` +#### TypeScript + ```ts function longestPath(parent: number[], s: string): number { const n = parent.length; diff --git a/solution/2200-2299/2246.Longest Path With Different Adjacent Characters/README_EN.md b/solution/2200-2299/2246.Longest Path With Different Adjacent Characters/README_EN.md index 1c697519ad8f9..11eb458892958 100644 --- a/solution/2200-2299/2246.Longest Path With Different Adjacent Characters/README_EN.md +++ b/solution/2200-2299/2246.Longest Path With Different Adjacent Characters/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python class Solution: def longestPath(self, parent: List[int], s: str) -> int: @@ -98,6 +100,8 @@ class Solution: return ans + 1 ``` +#### Java + ```java class Solution { private List[] g; @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func longestPath(parent []int, s string) int { n := len(parent) @@ -182,6 +190,8 @@ func longestPath(parent []int, s string) int { } ``` +#### TypeScript + ```ts function longestPath(parent: number[], s: string): number { const n = parent.length; diff --git a/solution/2200-2299/2247.Maximum Cost of Trip With K Highways/README.md b/solution/2200-2299/2247.Maximum Cost of Trip With K Highways/README.md index 460e3a4646948..38cc90cc5e64b 100644 --- a/solution/2200-2299/2247.Maximum Cost of Trip With K Highways/README.md +++ b/solution/2200-2299/2247.Maximum Cost of Trip With K Highways/README.md @@ -92,6 +92,8 @@ $$ +#### Python3 + ```python class Solution: def maximumCost(self, n: int, highways: List[List[int]], k: int) -> int: @@ -116,6 +118,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumCost(int n, int[][] highways, int k) { @@ -157,6 +161,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -195,6 +201,8 @@ public: }; ``` +#### Go + ```go func maximumCost(n int, highways [][]int, k int) int { if k >= n { @@ -236,6 +244,8 @@ func maximumCost(n int, highways [][]int, k int) int { } ``` +#### TypeScript + ```ts function maximumCost(n: number, highways: number[][], k: number): number { if (k >= n) { diff --git a/solution/2200-2299/2247.Maximum Cost of Trip With K Highways/README_EN.md b/solution/2200-2299/2247.Maximum Cost of Trip With K Highways/README_EN.md index 26b54f0a35cf6..41885867f0eb1 100644 --- a/solution/2200-2299/2247.Maximum Cost of Trip With K Highways/README_EN.md +++ b/solution/2200-2299/2247.Maximum Cost of Trip With K Highways/README_EN.md @@ -90,6 +90,8 @@ The time complexity is $O(2^n \times n^2)$, and the space complexity is $O(2^n \ +#### Python3 + ```python class Solution: def maximumCost(self, n: int, highways: List[List[int]], k: int) -> int: @@ -114,6 +116,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumCost(int n, int[][] highways, int k) { @@ -155,6 +159,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go func maximumCost(n int, highways [][]int, k int) int { if k >= n { @@ -234,6 +242,8 @@ func maximumCost(n int, highways [][]int, k int) int { } ``` +#### TypeScript + ```ts function maximumCost(n: number, highways: number[][], k: number): number { if (k >= n) { diff --git a/solution/2200-2299/2248.Intersection of Multiple Arrays/README.md b/solution/2200-2299/2248.Intersection of Multiple Arrays/README.md index 2db30ca46972d..cbbbb58f5cae4 100644 --- a/solution/2200-2299/2248.Intersection of Multiple Arrays/README.md +++ b/solution/2200-2299/2248.Intersection of Multiple Arrays/README.md @@ -67,6 +67,8 @@ nums[0] = [3,1,2,4,5],nums +#### Python3 + ```python class Solution: def intersection(self, nums: List[List[int]]) -> List[int]: @@ -77,6 +79,8 @@ class Solution: return [x for x, v in enumerate(cnt) if v == len(nums)] ``` +#### Java + ```java class Solution { public List intersection(int[][] nums) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func intersection(nums [][]int) (ans []int) { cnt := [1001]int{} @@ -135,6 +143,8 @@ func intersection(nums [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function intersection(nums: number[][]): number[] { const cnt = new Array(1001).fill(0); @@ -153,6 +163,8 @@ function intersection(nums: number[][]): number[] { } ``` +#### PHP + ```php class Solution { /** @@ -185,6 +197,8 @@ class Solution { +#### Python3 + ```python class Solution: def intersection(self, nums: List[List[int]]) -> List[int]: @@ -199,6 +213,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List intersection(int[][] nums) { @@ -217,6 +233,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -236,6 +254,8 @@ public: }; ``` +#### Go + ```go func intersection(nums [][]int) (ans []int) { cnt := map[int]int{} @@ -252,6 +272,8 @@ func intersection(nums [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function intersection(nums: number[][]): number[] { const cnt = new Array(1001).fill(0); diff --git a/solution/2200-2299/2248.Intersection of Multiple Arrays/README_EN.md b/solution/2200-2299/2248.Intersection of Multiple Arrays/README_EN.md index e23e3466f8499..45c60eb474f91 100644 --- a/solution/2200-2299/2248.Intersection of Multiple Arrays/README_EN.md +++ b/solution/2200-2299/2248.Intersection of Multiple Arrays/README_EN.md @@ -65,6 +65,8 @@ The time complexity is $O(N)$, and the space complexity is $O(1000)$. Where $N$ +#### Python3 + ```python class Solution: def intersection(self, nums: List[List[int]]) -> List[int]: @@ -75,6 +77,8 @@ class Solution: return [x for x, v in enumerate(cnt) if v == len(nums)] ``` +#### Java + ```java class Solution { public List intersection(int[][] nums) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func intersection(nums [][]int) (ans []int) { cnt := [1001]int{} @@ -133,6 +141,8 @@ func intersection(nums [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function intersection(nums: number[][]): number[] { const cnt = new Array(1001).fill(0); @@ -151,6 +161,8 @@ function intersection(nums: number[][]): number[] { } ``` +#### PHP + ```php class Solution { /** @@ -183,6 +195,8 @@ class Solution { +#### Python3 + ```python class Solution: def intersection(self, nums: List[List[int]]) -> List[int]: @@ -197,6 +211,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List intersection(int[][] nums) { @@ -215,6 +231,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -234,6 +252,8 @@ public: }; ``` +#### Go + ```go func intersection(nums [][]int) (ans []int) { cnt := map[int]int{} @@ -250,6 +270,8 @@ func intersection(nums [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function intersection(nums: number[][]): number[] { const cnt = new Array(1001).fill(0); diff --git a/solution/2200-2299/2249.Count Lattice Points Inside a Circle/README.md b/solution/2200-2299/2249.Count Lattice Points Inside a Circle/README.md index ec7b8ff4e6ef0..eed21ff2ed3a5 100644 --- a/solution/2200-2299/2249.Count Lattice Points Inside a Circle/README.md +++ b/solution/2200-2299/2249.Count Lattice Points Inside a Circle/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def countLatticePoints(self, circles: List[List[int]]) -> int: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countLatticePoints(int[][] circles) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func countLatticePoints(circles [][]int) (ans int) { mx, my := 0, 0 @@ -175,6 +183,8 @@ func countLatticePoints(circles [][]int) (ans int) { } ``` +#### TypeScript + ```ts function countLatticePoints(circles: number[][]): number { let mx = 0; diff --git a/solution/2200-2299/2249.Count Lattice Points Inside a Circle/README_EN.md b/solution/2200-2299/2249.Count Lattice Points Inside a Circle/README_EN.md index ccf8cb61cbeab..f5082caf0aa09 100644 --- a/solution/2200-2299/2249.Count Lattice Points Inside a Circle/README_EN.md +++ b/solution/2200-2299/2249.Count Lattice Points Inside a Circle/README_EN.md @@ -74,6 +74,8 @@ Some of them are (0, 2), (2, 0), (2, 4), (3, 2), and (4, 4). +#### Python3 + ```python class Solution: def countLatticePoints(self, circles: List[List[int]]) -> int: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countLatticePoints(int[][] circles) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func countLatticePoints(circles [][]int) (ans int) { mx, my := 0, 0 @@ -163,6 +171,8 @@ func countLatticePoints(circles [][]int) (ans int) { } ``` +#### TypeScript + ```ts function countLatticePoints(circles: number[][]): number { let mx = 0; diff --git a/solution/2200-2299/2250.Count Number of Rectangles Containing Each Point/README.md b/solution/2200-2299/2250.Count Number of Rectangles Containing Each Point/README.md index b494391c6240c..92fb3093149e9 100644 --- a/solution/2200-2299/2250.Count Number of Rectangles Containing Each Point/README.md +++ b/solution/2200-2299/2250.Count Number of Rectangles Containing Each Point/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def countRectangles( @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] countRectangles(int[][] rectangles, int[][] points) { @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func countRectangles(rectangles [][]int, points [][]int) []int { n := 101 @@ -197,6 +205,8 @@ func countRectangles(rectangles [][]int, points [][]int) []int { } ``` +#### TypeScript + ```ts function countRectangles(rectangles: number[][], points: number[][]): number[] { const n = 101; diff --git a/solution/2200-2299/2250.Count Number of Rectangles Containing Each Point/README_EN.md b/solution/2200-2299/2250.Count Number of Rectangles Containing Each Point/README_EN.md index 0147ed120ba14..18771b2ae2cfd 100644 --- a/solution/2200-2299/2250.Count Number of Rectangles Containing Each Point/README_EN.md +++ b/solution/2200-2299/2250.Count Number of Rectangles Containing Each Point/README_EN.md @@ -80,6 +80,8 @@ Therefore, we return [1, 3]. +#### Python3 + ```python class Solution: def countRectangles( @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] countRectangles(int[][] rectangles, int[][] points) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func countRectangles(rectangles [][]int, points [][]int) []int { n := 101 @@ -193,6 +201,8 @@ func countRectangles(rectangles [][]int, points [][]int) []int { } ``` +#### TypeScript + ```ts function countRectangles(rectangles: number[][], points: number[][]): number[] { const n = 101; diff --git a/solution/2200-2299/2251.Number of Flowers in Full Bloom/README.md b/solution/2200-2299/2251.Number of Flowers in Full Bloom/README.md index 18de22c5b06bb..bd66845ec4a92 100644 --- a/solution/2200-2299/2251.Number of Flowers in Full Bloom/README.md +++ b/solution/2200-2299/2251.Number of Flowers in Full Bloom/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def fullBloomFlowers( @@ -86,6 +88,8 @@ class Solution: return [bisect_right(start, p) - bisect_left(end, p) for p in people] ``` +#### Java + ```java class Solution { public int[] fullBloomFlowers(int[][] flowers, int[] people) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func fullBloomFlowers(flowers [][]int, people []int) (ans []int) { n := len(flowers) @@ -165,6 +173,8 @@ func fullBloomFlowers(flowers [][]int, people []int) (ans []int) { } ``` +#### TypeScript + ```ts function fullBloomFlowers(flowers: number[][], people: number[]): number[] { const n = flowers.length; @@ -200,6 +210,8 @@ function search(nums: number[], x: number): number { } ``` +#### Rust + ```rust use std::collections::BTreeMap; @@ -265,6 +277,8 @@ impl Solution { +#### Python3 + ```python class Solution: def fullBloomFlowers( @@ -286,6 +300,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] fullBloomFlowers(int[][] flowers, int[] people) { @@ -314,6 +330,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -344,6 +362,8 @@ public: }; ``` +#### Go + ```go func fullBloomFlowers(flowers [][]int, people []int) []int { d := map[int]int{} @@ -376,6 +396,8 @@ func fullBloomFlowers(flowers [][]int, people []int) []int { } ``` +#### TypeScript + ```ts function fullBloomFlowers(flowers: number[][], people: number[]): number[] { const d: Map = new Map(); diff --git a/solution/2200-2299/2251.Number of Flowers in Full Bloom/README_EN.md b/solution/2200-2299/2251.Number of Flowers in Full Bloom/README_EN.md index f40890d47897c..2fceb1bcc9ed8 100644 --- a/solution/2200-2299/2251.Number of Flowers in Full Bloom/README_EN.md +++ b/solution/2200-2299/2251.Number of Flowers in Full Bloom/README_EN.md @@ -67,6 +67,8 @@ For each person, we return the number of flowers in full bloom during their arri +#### Python3 + ```python class Solution: def fullBloomFlowers( @@ -76,6 +78,8 @@ class Solution: return [bisect_right(start, p) - bisect_left(end, p) for p in people] ``` +#### Java + ```java class Solution { public int[] fullBloomFlowers(int[][] flowers, int[] people) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func fullBloomFlowers(flowers [][]int, people []int) (ans []int) { n := len(flowers) @@ -155,6 +163,8 @@ func fullBloomFlowers(flowers [][]int, people []int) (ans []int) { } ``` +#### TypeScript + ```ts function fullBloomFlowers(flowers: number[][], people: number[]): number[] { const n = flowers.length; @@ -190,6 +200,8 @@ function search(nums: number[], x: number): number { } ``` +#### Rust + ```rust use std::collections::BTreeMap; @@ -251,6 +263,8 @@ impl Solution { +#### Python3 + ```python class Solution: def fullBloomFlowers( @@ -272,6 +286,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] fullBloomFlowers(int[][] flowers, int[] people) { @@ -300,6 +316,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -330,6 +348,8 @@ public: }; ``` +#### Go + ```go func fullBloomFlowers(flowers [][]int, people []int) []int { d := map[int]int{} @@ -362,6 +382,8 @@ func fullBloomFlowers(flowers [][]int, people []int) []int { } ``` +#### TypeScript + ```ts function fullBloomFlowers(flowers: number[][], people: number[]): number[] { const d: Map = new Map(); diff --git a/solution/2200-2299/2252.Dynamic Pivoting of a Table/README.md b/solution/2200-2299/2252.Dynamic Pivoting of a Table/README.md index e9d20e3cb2963..f7d49ef3fc089 100644 --- a/solution/2200-2299/2252.Dynamic Pivoting of a Table/README.md +++ b/solution/2200-2299/2252.Dynamic Pivoting of a Table/README.md @@ -85,6 +85,8 @@ Products 表: +#### MySQL + ```sql CREATE PROCEDURE PivotProducts() BEGIN diff --git a/solution/2200-2299/2252.Dynamic Pivoting of a Table/README_EN.md b/solution/2200-2299/2252.Dynamic Pivoting of a Table/README_EN.md index b42db1a64bf0d..18a2eb26650d8 100644 --- a/solution/2200-2299/2252.Dynamic Pivoting of a Table/README_EN.md +++ b/solution/2200-2299/2252.Dynamic Pivoting of a Table/README_EN.md @@ -85,6 +85,8 @@ For product 3, the price is 1000 in Shop and 1900 in Souq. It is not sold in the +#### MySQL + ```sql CREATE PROCEDURE PivotProducts() BEGIN diff --git a/solution/2200-2299/2253.Dynamic Unpivoting of a Table/README.md b/solution/2200-2299/2253.Dynamic Unpivoting of a Table/README.md index 5e1c35fbb774c..492a0dcbd958a 100644 --- a/solution/2200-2299/2253.Dynamic Unpivoting of a Table/README.md +++ b/solution/2200-2299/2253.Dynamic Unpivoting of a Table/README.md @@ -88,6 +88,8 @@ Products 表: +#### MySQL + ```sql CREATE PROCEDURE UnpivotProducts() BEGIN diff --git a/solution/2200-2299/2253.Dynamic Unpivoting of a Table/README_EN.md b/solution/2200-2299/2253.Dynamic Unpivoting of a Table/README_EN.md index 8b7003d2a2e24..f3d157c20de2b 100644 --- a/solution/2200-2299/2253.Dynamic Unpivoting of a Table/README_EN.md +++ b/solution/2200-2299/2253.Dynamic Unpivoting of a Table/README_EN.md @@ -88,6 +88,8 @@ Product 3 is sold in Shop and Souq with prices of 1000 and 1900. +#### MySQL + ```sql CREATE PROCEDURE UnpivotProducts() BEGIN diff --git a/solution/2200-2299/2254.Design Video Sharing Platform/README.md b/solution/2200-2299/2254.Design Video Sharing Platform/README.md index f69726e93c5ec..ced9a2d1dd444 100644 --- a/solution/2200-2299/2254.Design Video Sharing Platform/README.md +++ b/solution/2200-2299/2254.Design Video Sharing Platform/README.md @@ -110,18 +110,26 @@ videoSharingPlatform.getViews(0); // 没有视频与 videoId 0 相关 +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2200-2299/2254.Design Video Sharing Platform/README_EN.md b/solution/2200-2299/2254.Design Video Sharing Platform/README_EN.md index 910902236cf50..b7b1563eb9f78 100644 --- a/solution/2200-2299/2254.Design Video Sharing Platform/README_EN.md +++ b/solution/2200-2299/2254.Design Video Sharing Platform/README_EN.md @@ -108,18 +108,26 @@ videoSharingPlatform.getViews(0); // There is no video associated wit +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2200-2299/2255.Count Prefixes of a Given String/README.md b/solution/2200-2299/2255.Count Prefixes of a Given String/README.md index 9f3b5b46ce503..279f9f900b29c 100644 --- a/solution/2200-2299/2255.Count Prefixes of a Given String/README.md +++ b/solution/2200-2299/2255.Count Prefixes of a Given String/README.md @@ -70,12 +70,16 @@ words 中是 s = "abc" 前缀的字符串为: +#### Python3 + ```python class Solution: def countPrefixes(self, words: List[str], s: str) -> int: return sum(s.startswith(w) for w in words) ``` +#### Java + ```java class Solution { public int countPrefixes(String[] words, String s) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -103,6 +109,8 @@ public: }; ``` +#### Go + ```go func countPrefixes(words []string, s string) (ans int) { for _, w := range words { @@ -114,6 +122,8 @@ func countPrefixes(words []string, s string) (ans int) { } ``` +#### TypeScript + ```ts function countPrefixes(words: string[], s: string): number { return words.filter(w => s.startsWith(w)).length; diff --git a/solution/2200-2299/2255.Count Prefixes of a Given String/README_EN.md b/solution/2200-2299/2255.Count Prefixes of a Given String/README_EN.md index e45972071f34c..5db0aa3641db0 100644 --- a/solution/2200-2299/2255.Count Prefixes of a Given String/README_EN.md +++ b/solution/2200-2299/2255.Count Prefixes of a Given String/README_EN.md @@ -70,12 +70,16 @@ The time complexity is $O(m \times n)$, where $m$ and $n$ are the lengths of the +#### Python3 + ```python class Solution: def countPrefixes(self, words: List[str], s: str) -> int: return sum(s.startswith(w) for w in words) ``` +#### Java + ```java class Solution { public int countPrefixes(String[] words, String s) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -103,6 +109,8 @@ public: }; ``` +#### Go + ```go func countPrefixes(words []string, s string) (ans int) { for _, w := range words { @@ -114,6 +122,8 @@ func countPrefixes(words []string, s string) (ans int) { } ``` +#### TypeScript + ```ts function countPrefixes(words: string[], s: string): number { return words.filter(w => s.startsWith(w)).length; diff --git a/solution/2200-2299/2256.Minimum Average Difference/README.md b/solution/2200-2299/2256.Minimum Average Difference/README.md index 890fb9a8b7e97..df5378f7e6d04 100644 --- a/solution/2200-2299/2256.Minimum Average Difference/README.md +++ b/solution/2200-2299/2256.Minimum Average Difference/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def minimumAverageDifference(self, nums: List[int]) -> int: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumAverageDifference(int[] nums) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func minimumAverageDifference(nums []int) (ans int) { n := len(nums) @@ -184,6 +192,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function minimumAverageDifference(nums: number[]): number { const n = nums.length; diff --git a/solution/2200-2299/2256.Minimum Average Difference/README_EN.md b/solution/2200-2299/2256.Minimum Average Difference/README_EN.md index 1478354c3ae93..36b933d1e70a3 100644 --- a/solution/2200-2299/2256.Minimum Average Difference/README_EN.md +++ b/solution/2200-2299/2256.Minimum Average Difference/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def minimumAverageDifference(self, nums: List[int]) -> int: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumAverageDifference(int[] nums) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func minimumAverageDifference(nums []int) (ans int) { n := len(nums) @@ -184,6 +192,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function minimumAverageDifference(nums: number[]): number { const n = nums.length; diff --git a/solution/2200-2299/2257.Count Unguarded Cells in the Grid/README.md b/solution/2200-2299/2257.Count Unguarded Cells in the Grid/README.md index b369dddc07041..df85a041a3777 100644 --- a/solution/2200-2299/2257.Count Unguarded Cells in the Grid/README.md +++ b/solution/2200-2299/2257.Count Unguarded Cells in the Grid/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def countUnguarded( @@ -103,6 +105,8 @@ class Solution: return sum(v == 0 for row in g for v in row) ``` +#### Java + ```java class Solution { public int countUnguarded(int m, int n, int[][] guards, int[][] walls) { @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func countUnguarded(m int, n int, guards [][]int, walls [][]int) (ans int) { g := make([][]int, m) @@ -205,6 +213,8 @@ func countUnguarded(m int, n int, guards [][]int, walls [][]int) (ans int) { } ``` +#### TypeScript + ```ts function countUnguarded(m: number, n: number, guards: number[][], walls: number[][]): number { const g: number[][] = Array.from({ length: m }, () => Array.from({ length: n }, () => 0)); diff --git a/solution/2200-2299/2257.Count Unguarded Cells in the Grid/README_EN.md b/solution/2200-2299/2257.Count Unguarded Cells in the Grid/README_EN.md index 04ff26e9e2672..d56f3851590cd 100644 --- a/solution/2200-2299/2257.Count Unguarded Cells in the Grid/README_EN.md +++ b/solution/2200-2299/2257.Count Unguarded Cells in the Grid/README_EN.md @@ -79,6 +79,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def countUnguarded( @@ -99,6 +101,8 @@ class Solution: return sum(v == 0 for row in g for v in row) ``` +#### Java + ```java class Solution { public int countUnguarded(int m, int n, int[][] guards, int[][] walls) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func countUnguarded(m int, n int, guards [][]int, walls [][]int) (ans int) { g := make([][]int, m) @@ -201,6 +209,8 @@ func countUnguarded(m int, n int, guards [][]int, walls [][]int) (ans int) { } ``` +#### TypeScript + ```ts function countUnguarded(m: number, n: number, guards: number[][], walls: number[][]): number { const g: number[][] = Array.from({ length: m }, () => Array.from({ length: n }, () => 0)); diff --git a/solution/2200-2299/2258.Escape the Spreading Fire/README.md b/solution/2200-2299/2258.Escape the Spreading Fire/README.md index ad8acabe6fe6c..e91f8fef7f222 100644 --- a/solution/2200-2299/2258.Escape the Spreading Fire/README.md +++ b/solution/2200-2299/2258.Escape the Spreading Fire/README.md @@ -102,6 +102,8 @@ tags: +#### Python3 + ```python class Solution: def maximumMinutes(self, grid: List[List[int]]) -> int: @@ -168,6 +170,8 @@ class Solution: return int(1e9) if l == m * n else l ``` +#### Java + ```java class Solution { private int[][] grid; @@ -257,6 +261,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -336,6 +342,8 @@ public: }; ``` +#### Go + ```go func maximumMinutes(grid [][]int) int { m, n := len(grid), len(grid[0]) @@ -419,6 +427,8 @@ func maximumMinutes(grid [][]int) int { } ``` +#### TypeScript + ```ts function maximumMinutes(grid: number[][]): number { const m = grid.length; diff --git a/solution/2200-2299/2258.Escape the Spreading Fire/README_EN.md b/solution/2200-2299/2258.Escape the Spreading Fire/README_EN.md index 1f6f7b7330915..c8177696ec451 100644 --- a/solution/2200-2299/2258.Escape the Spreading Fire/README_EN.md +++ b/solution/2200-2299/2258.Escape the Spreading Fire/README_EN.md @@ -97,6 +97,8 @@ The time complexity is $O(m \times n \times \log (m \times n))$, and the space c +#### Python3 + ```python class Solution: def maximumMinutes(self, grid: List[List[int]]) -> int: @@ -163,6 +165,8 @@ class Solution: return int(1e9) if l == m * n else l ``` +#### Java + ```java class Solution { private int[][] grid; @@ -252,6 +256,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -331,6 +337,8 @@ public: }; ``` +#### Go + ```go func maximumMinutes(grid [][]int) int { m, n := len(grid), len(grid[0]) @@ -414,6 +422,8 @@ func maximumMinutes(grid [][]int) int { } ``` +#### TypeScript + ```ts function maximumMinutes(grid: number[][]): number { const m = grid.length; diff --git a/solution/2200-2299/2259.Remove Digit From Number to Maximize Result/README.md b/solution/2200-2299/2259.Remove Digit From Number to Maximize Result/README.md index cd96d37402384..3587558f11aed 100644 --- a/solution/2200-2299/2259.Remove Digit From Number to Maximize Result/README.md +++ b/solution/2200-2299/2259.Remove Digit From Number to Maximize Result/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def removeDigit(self, number: str, digit: str) -> str: @@ -85,6 +87,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public String removeDigit(String number, char digit) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func removeDigit(number string, digit byte) string { ans := "0" @@ -137,6 +145,8 @@ func removeDigit(number string, digit byte) string { } ``` +#### TypeScript + ```ts function removeDigit(number: string, digit: string): string { const n = number.length; @@ -153,6 +163,8 @@ function removeDigit(number: string, digit: string): string { } ``` +#### PHP + ```php class Solution { /** @@ -191,6 +203,8 @@ class Solution { +#### Python3 + ```python class Solution: def removeDigit(self, number: str, digit: str) -> str: @@ -204,6 +218,8 @@ class Solution: return number[:last] + number[last + 1 :] ``` +#### Java + ```java class Solution { public String removeDigit(String number, char digit) { @@ -223,6 +239,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -243,6 +261,8 @@ public: }; ``` +#### Go + ```go func removeDigit(number string, digit byte) string { last := -1 diff --git a/solution/2200-2299/2259.Remove Digit From Number to Maximize Result/README_EN.md b/solution/2200-2299/2259.Remove Digit From Number to Maximize Result/README_EN.md index 37a9ac1b73754..519bc5d879f73 100644 --- a/solution/2200-2299/2259.Remove Digit From Number to Maximize Result/README_EN.md +++ b/solution/2200-2299/2259.Remove Digit From Number to Maximize Result/README_EN.md @@ -71,6 +71,8 @@ Both result in the string "51". +#### Python3 + ```python class Solution: def removeDigit(self, number: str, digit: str) -> str: @@ -79,6 +81,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public String removeDigit(String number, char digit) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func removeDigit(number string, digit byte) string { ans := "0" @@ -131,6 +139,8 @@ func removeDigit(number string, digit byte) string { } ``` +#### TypeScript + ```ts function removeDigit(number: string, digit: string): string { const n = number.length; @@ -147,6 +157,8 @@ function removeDigit(number: string, digit: string): string { } ``` +#### PHP + ```php class Solution { /** @@ -179,6 +191,8 @@ class Solution { +#### Python3 + ```python class Solution: def removeDigit(self, number: str, digit: str) -> str: @@ -192,6 +206,8 @@ class Solution: return number[:last] + number[last + 1 :] ``` +#### Java + ```java class Solution { public String removeDigit(String number, char digit) { @@ -211,6 +227,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -231,6 +249,8 @@ public: }; ``` +#### Go + ```go func removeDigit(number string, digit byte) string { last := -1 diff --git a/solution/2200-2299/2260.Minimum Consecutive Cards to Pick Up/README.md b/solution/2200-2299/2260.Minimum Consecutive Cards to Pick Up/README.md index 65164e01e4109..7496714fe4dcd 100644 --- a/solution/2200-2299/2260.Minimum Consecutive Cards to Pick Up/README.md +++ b/solution/2200-2299/2260.Minimum Consecutive Cards to Pick Up/README.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def minimumCardPickup(self, cards: List[int]) -> int: @@ -73,6 +75,8 @@ class Solution: return -1 if ans == inf else ans ``` +#### Java + ```java class Solution { public int minimumCardPickup(int[] cards) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func minimumCardPickup(cards []int) int { last := map[int]int{} @@ -126,6 +134,8 @@ func minimumCardPickup(cards []int) int { } ``` +#### TypeScript + ```ts function minimumCardPickup(cards: number[]): number { const n = cards.length; diff --git a/solution/2200-2299/2260.Minimum Consecutive Cards to Pick Up/README_EN.md b/solution/2200-2299/2260.Minimum Consecutive Cards to Pick Up/README_EN.md index 4670edb1cd850..cc859ce215c35 100644 --- a/solution/2200-2299/2260.Minimum Consecutive Cards to Pick Up/README_EN.md +++ b/solution/2200-2299/2260.Minimum Consecutive Cards to Pick Up/README_EN.md @@ -59,6 +59,8 @@ tags: +#### Python3 + ```python class Solution: def minimumCardPickup(self, cards: List[int]) -> int: @@ -71,6 +73,8 @@ class Solution: return -1 if ans == inf else ans ``` +#### Java + ```java class Solution { public int minimumCardPickup(int[] cards) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func minimumCardPickup(cards []int) int { last := map[int]int{} @@ -124,6 +132,8 @@ func minimumCardPickup(cards []int) int { } ``` +#### TypeScript + ```ts function minimumCardPickup(cards: number[]): number { const n = cards.length; diff --git a/solution/2200-2299/2261.K Divisible Elements Subarrays/README.md b/solution/2200-2299/2261.K Divisible Elements Subarrays/README.md index dc6e6d4bf9356..33385681b8955 100644 --- a/solution/2200-2299/2261.K Divisible Elements Subarrays/README.md +++ b/solution/2200-2299/2261.K Divisible Elements Subarrays/README.md @@ -90,6 +90,8 @@ nums 中的所有元素都可以被 p = 1 整除。 +#### Python3 + ```python class Solution: def countDistinct(self, nums: List[int], k: int, p: int) -> int: @@ -105,6 +107,8 @@ class Solution: return len(s) ``` +#### Java + ```java class Solution { public int countDistinct(int[] nums, int k, int p) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func countDistinct(nums []int, k int, p int) int { s := map[string]struct{}{} @@ -168,6 +176,8 @@ func countDistinct(nums []int, k int, p int) int { } ``` +#### TypeScript + ```ts function countDistinct(nums: number[], k: number, p: number): number { const n = nums.length; @@ -197,6 +207,8 @@ function countDistinct(nums: number[], k: number, p: number): number { +#### Python3 + ```python class Solution: def countDistinct(self, nums: List[int], k: int, p: int) -> int: diff --git a/solution/2200-2299/2261.K Divisible Elements Subarrays/README_EN.md b/solution/2200-2299/2261.K Divisible Elements Subarrays/README_EN.md index dbedcd1f0092b..4751c1686cfdb 100644 --- a/solution/2200-2299/2261.K Divisible Elements Subarrays/README_EN.md +++ b/solution/2200-2299/2261.K Divisible Elements Subarrays/README_EN.md @@ -83,6 +83,8 @@ Since all subarrays are distinct, the total number of subarrays satisfying all t +#### Python3 + ```python class Solution: def countDistinct(self, nums: List[int], k: int, p: int) -> int: @@ -98,6 +100,8 @@ class Solution: return len(s) ``` +#### Java + ```java class Solution { public int countDistinct(int[] nums, int k, int p) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func countDistinct(nums []int, k int, p int) int { s := map[string]struct{}{} @@ -161,6 +169,8 @@ func countDistinct(nums []int, k int, p int) int { } ``` +#### TypeScript + ```ts function countDistinct(nums: number[], k: number, p: number): number { const n = nums.length; @@ -190,6 +200,8 @@ function countDistinct(nums: number[], k: number, p: number): number { +#### Python3 + ```python class Solution: def countDistinct(self, nums: List[int], k: int, p: int) -> int: diff --git a/solution/2200-2299/2262.Total Appeal of A String/README.md b/solution/2200-2299/2262.Total Appeal of A String/README.md index c811005e4eeba..97419ded5e9cc 100644 --- a/solution/2200-2299/2262.Total Appeal of A String/README.md +++ b/solution/2200-2299/2262.Total Appeal of A String/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def appealSum(self, s: str) -> int: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long appealSum(String s) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func appealSum(s string) int64 { var ans, t int64 @@ -154,6 +162,8 @@ func appealSum(s string) int64 { } ``` +#### TypeScript + ```ts function appealSum(s: string): number { const pos: number[] = Array(26).fill(-1); diff --git a/solution/2200-2299/2262.Total Appeal of A String/README_EN.md b/solution/2200-2299/2262.Total Appeal of A String/README_EN.md index 9b47aad2bc161..61cd4eb70e542 100644 --- a/solution/2200-2299/2262.Total Appeal of A String/README_EN.md +++ b/solution/2200-2299/2262.Total Appeal of A String/README_EN.md @@ -89,6 +89,8 @@ The time complexity is $O(n)$, and the space complexity is $O(|\Sigma|)$, where +#### Python3 + ```python class Solution: def appealSum(self, s: str) -> int: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long appealSum(String s) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func appealSum(s string) int64 { var ans, t int64 @@ -154,6 +162,8 @@ func appealSum(s string) int64 { } ``` +#### TypeScript + ```ts function appealSum(s: string): number { const pos: number[] = Array(26).fill(-1); diff --git a/solution/2200-2299/2263.Make Array Non-decreasing or Non-increasing/README.md b/solution/2200-2299/2263.Make Array Non-decreasing or Non-increasing/README.md index 3118c1759fc39..f82c4c3d8e546 100644 --- a/solution/2200-2299/2263.Make Array Non-decreasing or Non-increasing/README.md +++ b/solution/2200-2299/2263.Make Array Non-decreasing or Non-increasing/README.md @@ -93,6 +93,8 @@ $$ +#### Python3 + ```python class Solution: def convertArray(self, nums: List[int]) -> int: @@ -110,6 +112,8 @@ class Solution: return min(solve(nums), solve(nums[::-1])) ``` +#### Java + ```java class Solution { public int convertArray(int[] nums) { @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go func convertArray(nums []int) int { return min(solve(nums), solve(reverse(nums))) diff --git a/solution/2200-2299/2263.Make Array Non-decreasing or Non-increasing/README_EN.md b/solution/2200-2299/2263.Make Array Non-decreasing or Non-increasing/README_EN.md index 67d8de8e770c4..20e5a65f53729 100644 --- a/solution/2200-2299/2263.Make Array Non-decreasing or Non-increasing/README_EN.md +++ b/solution/2200-2299/2263.Make Array Non-decreasing or Non-increasing/README_EN.md @@ -79,6 +79,8 @@ It can be proven that 4 is the minimum number of operations needed. +#### Python3 + ```python class Solution: def convertArray(self, nums: List[int]) -> int: @@ -96,6 +98,8 @@ class Solution: return min(solve(nums), solve(nums[::-1])) ``` +#### Java + ```java class Solution { public int convertArray(int[] nums) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func convertArray(nums []int) int { return min(solve(nums), solve(reverse(nums))) diff --git a/solution/2200-2299/2264.Largest 3-Same-Digit Number in String/README.md b/solution/2200-2299/2264.Largest 3-Same-Digit Number in String/README.md index 24131a098bf1b..2888a5af37941 100644 --- a/solution/2200-2299/2264.Largest 3-Same-Digit Number in String/README.md +++ b/solution/2200-2299/2264.Largest 3-Same-Digit Number in String/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def largestGoodInteger(self, num: str) -> str: @@ -95,6 +97,8 @@ class Solution: return "" ``` +#### Java + ```java class Solution { public String largestGoodInteger(String num) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func largestGoodInteger(num string) string { for c := '9'; c >= '0'; c-- { @@ -135,6 +143,8 @@ func largestGoodInteger(num string) string { } ``` +#### TypeScript + ```ts function largestGoodInteger(num: string): string { for (let i = 9; i >= 0; i--) { diff --git a/solution/2200-2299/2264.Largest 3-Same-Digit Number in String/README_EN.md b/solution/2200-2299/2264.Largest 3-Same-Digit Number in String/README_EN.md index 29374bd31b708..510a798494989 100644 --- a/solution/2200-2299/2264.Largest 3-Same-Digit Number in String/README_EN.md +++ b/solution/2200-2299/2264.Largest 3-Same-Digit Number in String/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(10 \times n)$, where $n$ is the length of the string $ +#### Python3 + ```python class Solution: def largestGoodInteger(self, num: str) -> str: @@ -93,6 +95,8 @@ class Solution: return "" ``` +#### Java + ```java class Solution { public String largestGoodInteger(String num) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func largestGoodInteger(num string) string { for c := '9'; c >= '0'; c-- { @@ -133,6 +141,8 @@ func largestGoodInteger(num string) string { } ``` +#### TypeScript + ```ts function largestGoodInteger(num: string): string { for (let i = 9; i >= 0; i--) { diff --git a/solution/2200-2299/2265.Count Nodes Equal to Average of Subtree/README.md b/solution/2200-2299/2265.Count Nodes Equal to Average of Subtree/README.md index 554a52f059097..3474d770ff23b 100644 --- a/solution/2200-2299/2265.Count Nodes Equal to Average of Subtree/README.md +++ b/solution/2200-2299/2265.Count Nodes Equal to Average of Subtree/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/2200-2299/2265.Count Nodes Equal to Average of Subtree/README_EN.md b/solution/2200-2299/2265.Count Nodes Equal to Average of Subtree/README_EN.md index d72d6ad4801aa..9b88f0c4993d9 100644 --- a/solution/2200-2299/2265.Count Nodes Equal to Average of Subtree/README_EN.md +++ b/solution/2200-2299/2265.Count Nodes Equal to Average of Subtree/README_EN.md @@ -69,6 +69,8 @@ For the node with value 6: The average of its subtree is 6 / 1 = 6. +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/2200-2299/2266.Count Number of Texts/README.md b/solution/2200-2299/2266.Count Number of Texts/README.md index 582ae6af0ae9d..e407c0c1bccab 100644 --- a/solution/2200-2299/2266.Count Number of Texts/README.md +++ b/solution/2200-2299/2266.Count Number of Texts/README.md @@ -82,6 +82,8 @@ Alice 可能发出的文字信息包括: +#### Python3 + ```python mod = 10**9 + 7 f = [1, 1, 2, 4] @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int N = 100010; @@ -138,6 +142,8 @@ class Solution { } ``` +#### Go + ```go const mod int = 1e9 + 7 const n int = 1e5 + 10 diff --git a/solution/2200-2299/2266.Count Number of Texts/README_EN.md b/solution/2200-2299/2266.Count Number of Texts/README_EN.md index 2ef804d8b34ef..63a88bc75b843 100644 --- a/solution/2200-2299/2266.Count Number of Texts/README_EN.md +++ b/solution/2200-2299/2266.Count Number of Texts/README_EN.md @@ -80,6 +80,8 @@ Since we need to return the answer modulo 109 + 7, we return 20828761 +#### Python3 + ```python mod = 10**9 + 7 f = [1, 1, 2, 4] @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int N = 100010; @@ -136,6 +140,8 @@ class Solution { } ``` +#### Go + ```go const mod int = 1e9 + 7 const n int = 1e5 + 10 diff --git a/solution/2200-2299/2267.Check if There Is a Valid Parentheses String Path/README.md b/solution/2200-2299/2267.Check if There Is a Valid Parentheses String Path/README.md index e1530eafe48f4..4b0b57cb37067 100644 --- a/solution/2200-2299/2267.Check if There Is a Valid Parentheses String Path/README.md +++ b/solution/2200-2299/2267.Check if There Is a Valid Parentheses String Path/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def hasValidPath(self, grid: List[List[str]]) -> bool: @@ -107,6 +109,8 @@ class Solution: return dfs(0, 0, 0) ``` +#### Java + ```java class Solution { private boolean[][][] vis; @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp bool vis[100][100][200]; int dirs[3] = {1, 0, 1}; @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go func hasValidPath(grid [][]byte) bool { m, n := len(grid), len(grid[0]) diff --git a/solution/2200-2299/2267.Check if There Is a Valid Parentheses String Path/README_EN.md b/solution/2200-2299/2267.Check if There Is a Valid Parentheses String Path/README_EN.md index decccdb3946b0..521b1c94c34ee 100644 --- a/solution/2200-2299/2267.Check if There Is a Valid Parentheses String Path/README_EN.md +++ b/solution/2200-2299/2267.Check if There Is a Valid Parentheses String Path/README_EN.md @@ -79,6 +79,8 @@ Note that there may be other valid parentheses string paths. +#### Python3 + ```python class Solution: def hasValidPath(self, grid: List[List[str]]) -> bool: @@ -101,6 +103,8 @@ class Solution: return dfs(0, 0, 0) ``` +#### Java + ```java class Solution { private boolean[][][] vis; @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp bool vis[100][100][200]; int dirs[3] = {1, 0, 1}; @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func hasValidPath(grid [][]byte) bool { m, n := len(grid), len(grid[0]) diff --git a/solution/2200-2299/2268.Minimum Number of Keypresses/README.md b/solution/2200-2299/2268.Minimum Number of Keypresses/README.md index 0e9fbd9c423e5..950623f6d487c 100644 --- a/solution/2200-2299/2268.Minimum Number of Keypresses/README.md +++ b/solution/2200-2299/2268.Minimum Number of Keypresses/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def minimumKeypresses(self, s: str) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumKeypresses(String s) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func minimumKeypresses(s string) int { cnt := make([]int, 26) diff --git a/solution/2200-2299/2268.Minimum Number of Keypresses/README_EN.md b/solution/2200-2299/2268.Minimum Number of Keypresses/README_EN.md index ee90f2a26be90..72af1ff29d8bb 100644 --- a/solution/2200-2299/2268.Minimum Number of Keypresses/README_EN.md +++ b/solution/2200-2299/2268.Minimum Number of Keypresses/README_EN.md @@ -80,6 +80,8 @@ A total of 15 button presses are needed, so return 15. +#### Python3 + ```python class Solution: def minimumKeypresses(self, s: str) -> int: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumKeypresses(String s) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func minimumKeypresses(s string) int { cnt := make([]int, 26) diff --git a/solution/2200-2299/2269.Find the K-Beauty of a Number/README.md b/solution/2200-2299/2269.Find the K-Beauty of a Number/README.md index 6dad451da20bc..d9b80ac05c9d1 100644 --- a/solution/2200-2299/2269.Find the K-Beauty of a Number/README.md +++ b/solution/2200-2299/2269.Find the K-Beauty of a Number/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def divisorSubstrings(self, num: int, k: int) -> int: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int divisorSubstrings(int num, int k) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func divisorSubstrings(num int, k int) int { ans := 0 @@ -145,6 +153,8 @@ func divisorSubstrings(num int, k int) int { } ``` +#### TypeScript + ```ts function divisorSubstrings(num: number, k: number): number { let ans = 0; @@ -173,6 +183,8 @@ function divisorSubstrings(num: number, k: number): number { +#### Python3 + ```python class Solution: def divisorSubstrings(self, num: int, k: int) -> int: @@ -192,6 +204,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int divisorSubstrings(int num, int k) { @@ -215,6 +229,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -240,6 +256,8 @@ public: }; ``` +#### Go + ```go func divisorSubstrings(num int, k int) (ans int) { x, p, t := 0, 1, num @@ -264,6 +282,8 @@ func divisorSubstrings(num int, k int) (ans int) { } ``` +#### TypeScript + ```ts function divisorSubstrings(num: number, k: number): number { let [x, p, t] = [0, 1, num]; diff --git a/solution/2200-2299/2269.Find the K-Beauty of a Number/README_EN.md b/solution/2200-2299/2269.Find the K-Beauty of a Number/README_EN.md index 9cada24e46df8..d9862dbfb43fa 100644 --- a/solution/2200-2299/2269.Find the K-Beauty of a Number/README_EN.md +++ b/solution/2200-2299/2269.Find the K-Beauty of a Number/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(\log num \times k)$, and the space complexity is $O(\l +#### Python3 + ```python class Solution: def divisorSubstrings(self, num: int, k: int) -> int: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int divisorSubstrings(int num, int k) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func divisorSubstrings(num int, k int) int { ans := 0 @@ -143,6 +151,8 @@ func divisorSubstrings(num int, k int) int { } ``` +#### TypeScript + ```ts function divisorSubstrings(num: number, k: number): number { let ans = 0; @@ -171,6 +181,8 @@ The time complexity is $O(\log num)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def divisorSubstrings(self, num: int, k: int) -> int: @@ -190,6 +202,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int divisorSubstrings(int num, int k) { @@ -213,6 +227,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -238,6 +254,8 @@ public: }; ``` +#### Go + ```go func divisorSubstrings(num int, k int) (ans int) { x, p, t := 0, 1, num @@ -262,6 +280,8 @@ func divisorSubstrings(num int, k int) (ans int) { } ``` +#### TypeScript + ```ts function divisorSubstrings(num: number, k: number): number { let [x, p, t] = [0, 1, num]; diff --git a/solution/2200-2299/2270.Number of Ways to Split Array/README.md b/solution/2200-2299/2270.Number of Ways to Split Array/README.md index ec687e60f6f1c..be2626031537d 100644 --- a/solution/2200-2299/2270.Number of Ways to Split Array/README.md +++ b/solution/2200-2299/2270.Number of Ways to Split Array/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def waysToSplitArray(self, nums: List[int]) -> int: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int waysToSplitArray(int[] nums) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func waysToSplitArray(nums []int) int { s := 0 diff --git a/solution/2200-2299/2270.Number of Ways to Split Array/README_EN.md b/solution/2200-2299/2270.Number of Ways to Split Array/README_EN.md index fd5fbddccd188..3122e415b8163 100644 --- a/solution/2200-2299/2270.Number of Ways to Split Array/README_EN.md +++ b/solution/2200-2299/2270.Number of Ways to Split Array/README_EN.md @@ -73,6 +73,8 @@ There are two valid splits in nums: +#### Python3 + ```python class Solution: def waysToSplitArray(self, nums: List[int]) -> int: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int waysToSplitArray(int[] nums) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func waysToSplitArray(nums []int) int { s := 0 diff --git a/solution/2200-2299/2271.Maximum White Tiles Covered by a Carpet/README.md b/solution/2200-2299/2271.Maximum White Tiles Covered by a Carpet/README.md index b72bceb5e9b9a..bf7b9436936e7 100644 --- a/solution/2200-2299/2271.Maximum White Tiles Covered by a Carpet/README.md +++ b/solution/2200-2299/2271.Maximum White Tiles Covered by a Carpet/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def maximumWhiteTiles(self, tiles: List[List[int]], carpetLen: int) -> int: @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumWhiteTiles(int[][] tiles, int carpetLen) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func maximumWhiteTiles(tiles [][]int, carpetLen int) int { sort.Slice(tiles, func(i, j int) bool { return tiles[i][0] < tiles[j][0] }) diff --git a/solution/2200-2299/2271.Maximum White Tiles Covered by a Carpet/README_EN.md b/solution/2200-2299/2271.Maximum White Tiles Covered by a Carpet/README_EN.md index 2f77bb71cd239..335ff7aae63de 100644 --- a/solution/2200-2299/2271.Maximum White Tiles Covered by a Carpet/README_EN.md +++ b/solution/2200-2299/2271.Maximum White Tiles Covered by a Carpet/README_EN.md @@ -70,6 +70,8 @@ It covers 2 white tiles, so we return 2. +#### Python3 + ```python class Solution: def maximumWhiteTiles(self, tiles: List[List[int]], carpetLen: int) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumWhiteTiles(int[][] tiles, int carpetLen) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func maximumWhiteTiles(tiles [][]int, carpetLen int) int { sort.Slice(tiles, func(i, j int) bool { return tiles[i][0] < tiles[j][0] }) diff --git a/solution/2200-2299/2272.Substring With Largest Variance/README.md b/solution/2200-2299/2272.Substring With Largest Variance/README.md index 959ad444e30ab..e66f437d2f9d4 100644 --- a/solution/2200-2299/2272.Substring With Largest Variance/README.md +++ b/solution/2200-2299/2272.Substring With Largest Variance/README.md @@ -83,6 +83,8 @@ s 中没有字母出现超过 1 次,所以 s 中每个子字符串的波动值 +#### Python3 + ```python class Solution: def largestVariance(self, s: str) -> int: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int largestVariance(String s) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func largestVariance(s string) int { ans, n := 0, len(s) diff --git a/solution/2200-2299/2272.Substring With Largest Variance/README_EN.md b/solution/2200-2299/2272.Substring With Largest Variance/README_EN.md index 877e57d410b46..74b82d61a8b8d 100644 --- a/solution/2200-2299/2272.Substring With Largest Variance/README_EN.md +++ b/solution/2200-2299/2272.Substring With Largest Variance/README_EN.md @@ -67,6 +67,8 @@ No letter occurs more than once in s, so the variance of every substring is 0. +#### Python3 + ```python class Solution: def largestVariance(self, s: str) -> int: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int largestVariance(String s) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func largestVariance(s string) int { ans, n := 0, len(s) diff --git a/solution/2200-2299/2273.Find Resultant Array After Removing Anagrams/README.md b/solution/2200-2299/2273.Find Resultant Array After Removing Anagrams/README.md index 75d0d62585e42..76a1097bbe742 100644 --- a/solution/2200-2299/2273.Find Resultant Array After Removing Anagrams/README.md +++ b/solution/2200-2299/2273.Find Resultant Array After Removing Anagrams/README.md @@ -79,6 +79,8 @@ words 中不存在互为字母异位词的两个相邻字符串,所以无需 +#### Python3 + ```python class Solution: def removeAnagrams(self, words: List[str]) -> List[str]: @@ -89,6 +91,8 @@ class Solution: ] ``` +#### Java + ```java class Solution { public List removeAnagrams(String[] words) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### TypeScript + ```ts function removeAnagrams(words: string[]): string[] { const n = words.length; diff --git a/solution/2200-2299/2273.Find Resultant Array After Removing Anagrams/README_EN.md b/solution/2200-2299/2273.Find Resultant Array After Removing Anagrams/README_EN.md index 22eb91fc3141c..73e5c8e5edcc6 100644 --- a/solution/2200-2299/2273.Find Resultant Array After Removing Anagrams/README_EN.md +++ b/solution/2200-2299/2273.Find Resultant Array After Removing Anagrams/README_EN.md @@ -72,6 +72,8 @@ No two adjacent strings in words are anagrams of each other, so no operations ar +#### Python3 + ```python class Solution: def removeAnagrams(self, words: List[str]) -> List[str]: @@ -82,6 +84,8 @@ class Solution: ] ``` +#### Java + ```java class Solution { public List removeAnagrams(String[] words) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### TypeScript + ```ts function removeAnagrams(words: string[]): string[] { const n = words.length; diff --git a/solution/2200-2299/2274.Maximum Consecutive Floors Without Special Floors/README.md b/solution/2200-2299/2274.Maximum Consecutive Floors Without Special Floors/README.md index df23bbca40537..3c410d455cafc 100644 --- a/solution/2200-2299/2274.Maximum Consecutive Floors Without Special Floors/README.md +++ b/solution/2200-2299/2274.Maximum Consecutive Floors Without Special Floors/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int: @@ -77,6 +79,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxConsecutive(int bottom, int top, int[] special) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### TypeScript + ```ts function maxConsecutive(bottom: number, top: number, special: number[]): number { let nums = special.slice().sort((a, b) => a - b); diff --git a/solution/2200-2299/2274.Maximum Consecutive Floors Without Special Floors/README_EN.md b/solution/2200-2299/2274.Maximum Consecutive Floors Without Special Floors/README_EN.md index b95a745f17b05..94eafc7cee58a 100644 --- a/solution/2200-2299/2274.Maximum Consecutive Floors Without Special Floors/README_EN.md +++ b/solution/2200-2299/2274.Maximum Consecutive Floors Without Special Floors/README_EN.md @@ -65,6 +65,8 @@ Therefore, we return the maximum number which is 3 floors. +#### Python3 + ```python class Solution: def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int: @@ -75,6 +77,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxConsecutive(int bottom, int top, int[] special) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### TypeScript + ```ts function maxConsecutive(bottom: number, top: number, special: number[]): number { let nums = special.slice().sort((a, b) => a - b); diff --git a/solution/2200-2299/2275.Largest Combination With Bitwise AND Greater Than Zero/README.md b/solution/2200-2299/2275.Largest Combination With Bitwise AND Greater Than Zero/README.md index 5cdf34db2d7af..181f59683b0d6 100644 --- a/solution/2200-2299/2275.Largest Combination With Bitwise AND Greater Than Zero/README.md +++ b/solution/2200-2299/2275.Largest Combination With Bitwise AND Greater Than Zero/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def largestCombination(self, candidates: List[int]) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int largestCombination(int[] candidates) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### TypeScript + ```ts function largestCombination(candidates: number[]): number { const n = 24; diff --git a/solution/2200-2299/2275.Largest Combination With Bitwise AND Greater Than Zero/README_EN.md b/solution/2200-2299/2275.Largest Combination With Bitwise AND Greater Than Zero/README_EN.md index 7e9a3bb13e028..851c65a1d46a2 100644 --- a/solution/2200-2299/2275.Largest Combination With Bitwise AND Greater Than Zero/README_EN.md +++ b/solution/2200-2299/2275.Largest Combination With Bitwise AND Greater Than Zero/README_EN.md @@ -72,6 +72,8 @@ The size of the combination is 2, so we return 2. +#### Python3 + ```python class Solution: def largestCombination(self, candidates: List[int]) -> int: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int largestCombination(int[] candidates) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### TypeScript + ```ts function largestCombination(candidates: number[]): number { const n = 24; diff --git a/solution/2200-2299/2276.Count Integers in Intervals/README.md b/solution/2200-2299/2276.Count Integers in Intervals/README.md index 7511cbef269fd..e6816beea5747 100644 --- a/solution/2200-2299/2276.Count Integers in Intervals/README.md +++ b/solution/2200-2299/2276.Count Integers in Intervals/README.md @@ -95,6 +95,8 @@ countIntervals.count(); // 返回 8 +#### Python3 + ```python class Node: def __init__(self): @@ -140,6 +142,8 @@ class CountIntervals: # param_2 = obj.count() ``` +#### Java + ```java class Node { Node left; @@ -253,6 +257,8 @@ class CountIntervals { */ ``` +#### C++ + ```cpp class Node { public: @@ -368,6 +374,8 @@ private: */ ``` +#### Go + ```go type Node struct { left *Node @@ -492,6 +500,8 @@ func (ci *CountIntervals) Count() int { */ ``` +#### TypeScript + ```ts class CountIntervals { left: null | CountIntervals; @@ -544,6 +554,8 @@ class CountIntervals { +#### Python3 + ```python class Node: __slots__ = ("left", "right", "l", "r", "mid", "v", "add") diff --git a/solution/2200-2299/2276.Count Integers in Intervals/README_EN.md b/solution/2200-2299/2276.Count Integers in Intervals/README_EN.md index b2168c4bf6d72..b446c7e66e4d0 100644 --- a/solution/2200-2299/2276.Count Integers in Intervals/README_EN.md +++ b/solution/2200-2299/2276.Count Integers in Intervals/README_EN.md @@ -81,6 +81,8 @@ countIntervals.count(); // return 8 +#### Python3 + ```python class Node: def __init__(self): @@ -126,6 +128,8 @@ class CountIntervals: # param_2 = obj.count() ``` +#### Java + ```java class Node { Node left; @@ -239,6 +243,8 @@ class CountIntervals { */ ``` +#### C++ + ```cpp class Node { public: @@ -354,6 +360,8 @@ private: */ ``` +#### Go + ```go type Node struct { left *Node @@ -478,6 +486,8 @@ func (ci *CountIntervals) Count() int { */ ``` +#### TypeScript + ```ts class CountIntervals { left: null | CountIntervals; @@ -530,6 +540,8 @@ class CountIntervals { +#### Python3 + ```python class Node: __slots__ = ("left", "right", "l", "r", "mid", "v", "add") diff --git a/solution/2200-2299/2277.Closest Node to Path in Tree/README.md b/solution/2200-2299/2277.Closest Node to Path in Tree/README.md index 1d51f1dc960e7..f77a5a833196b 100644 --- a/solution/2200-2299/2277.Closest Node to Path in Tree/README.md +++ b/solution/2200-2299/2277.Closest Node to Path in Tree/README.md @@ -88,18 +88,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2200-2299/2277.Closest Node to Path in Tree/README_EN.md b/solution/2200-2299/2277.Closest Node to Path in Tree/README_EN.md index 456019d361ab8..8616f9400e5b5 100644 --- a/solution/2200-2299/2277.Closest Node to Path in Tree/README_EN.md +++ b/solution/2200-2299/2277.Closest Node to Path in Tree/README_EN.md @@ -84,18 +84,26 @@ Since 0 is the only node on the path, the answer to the first query is 0. +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2200-2299/2278.Percentage of Letter in String/README.md b/solution/2200-2299/2278.Percentage of Letter in String/README.md index 36851ddbf2a82..8c1d7fc62de18 100644 --- a/solution/2200-2299/2278.Percentage of Letter in String/README.md +++ b/solution/2200-2299/2278.Percentage of Letter in String/README.md @@ -59,12 +59,16 @@ tags: +#### Python3 + ```python class Solution: def percentageLetter(self, s: str, letter: str) -> int: return s.count(letter) * 100 // len(s) ``` +#### Java + ```java class Solution { public int percentageLetter(String s, char letter) { @@ -79,6 +83,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -90,6 +96,8 @@ public: }; ``` +#### Go + ```go func percentageLetter(s string, letter byte) int { cnt := 0 @@ -102,6 +110,8 @@ func percentageLetter(s string, letter byte) int { } ``` +#### TypeScript + ```ts function percentageLetter(s: string, letter: string): number { let count = 0; @@ -113,6 +123,8 @@ function percentageLetter(s: string, letter: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn percentage_letter(s: String, letter: char) -> i32 { diff --git a/solution/2200-2299/2278.Percentage of Letter in String/README_EN.md b/solution/2200-2299/2278.Percentage of Letter in String/README_EN.md index d59d51754afe7..2152a2dc0ff70 100644 --- a/solution/2200-2299/2278.Percentage of Letter in String/README_EN.md +++ b/solution/2200-2299/2278.Percentage of Letter in String/README_EN.md @@ -57,12 +57,16 @@ The percentage of characters in s that equal the letter 'k' is 0%, so we +#### Python3 + ```python class Solution: def percentageLetter(self, s: str, letter: str) -> int: return s.count(letter) * 100 // len(s) ``` +#### Java + ```java class Solution { public int percentageLetter(String s, char letter) { @@ -77,6 +81,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -88,6 +94,8 @@ public: }; ``` +#### Go + ```go func percentageLetter(s string, letter byte) int { cnt := 0 @@ -100,6 +108,8 @@ func percentageLetter(s string, letter byte) int { } ``` +#### TypeScript + ```ts function percentageLetter(s: string, letter: string): number { let count = 0; @@ -111,6 +121,8 @@ function percentageLetter(s: string, letter: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn percentage_letter(s: String, letter: char) -> i32 { diff --git a/solution/2200-2299/2279.Maximum Bags With Full Capacity of Rocks/README.md b/solution/2200-2299/2279.Maximum Bags With Full Capacity of Rocks/README.md index aa2013ae1b639..9383d4f33594b 100644 --- a/solution/2200-2299/2279.Maximum Bags With Full Capacity of Rocks/README.md +++ b/solution/2200-2299/2279.Maximum Bags With Full Capacity of Rocks/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def maximumBags( @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumBags(int[] capacity, int[] rocks, int additionalRocks) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func maximumBags(capacity []int, rocks []int, additionalRocks int) int { n := len(capacity) @@ -153,6 +161,8 @@ func maximumBags(capacity []int, rocks []int, additionalRocks int) int { } ``` +#### TypeScript + ```ts function maximumBags(capacity: number[], rocks: number[], additionalRocks: number): number { const n = capacity.length; @@ -167,6 +177,8 @@ function maximumBags(capacity: number[], rocks: number[], additionalRocks: numbe } ``` +#### Rust + ```rust impl Solution { pub fn maximum_bags(capacity: Vec, rocks: Vec, mut additional_rocks: i32) -> i32 { diff --git a/solution/2200-2299/2279.Maximum Bags With Full Capacity of Rocks/README_EN.md b/solution/2200-2299/2279.Maximum Bags With Full Capacity of Rocks/README_EN.md index 435fc4b6b664d..8b53a9d2dcb78 100644 --- a/solution/2200-2299/2279.Maximum Bags With Full Capacity of Rocks/README_EN.md +++ b/solution/2200-2299/2279.Maximum Bags With Full Capacity of Rocks/README_EN.md @@ -74,6 +74,8 @@ Note that we did not use all of the additional rocks. +#### Python3 + ```python class Solution: def maximumBags( @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumBags(int[] capacity, int[] rocks, int additionalRocks) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func maximumBags(capacity []int, rocks []int, additionalRocks int) int { n := len(capacity) @@ -151,6 +159,8 @@ func maximumBags(capacity []int, rocks []int, additionalRocks int) int { } ``` +#### TypeScript + ```ts function maximumBags(capacity: number[], rocks: number[], additionalRocks: number): number { const n = capacity.length; @@ -165,6 +175,8 @@ function maximumBags(capacity: number[], rocks: number[], additionalRocks: numbe } ``` +#### Rust + ```rust impl Solution { pub fn maximum_bags(capacity: Vec, rocks: Vec, mut additional_rocks: i32) -> i32 { diff --git a/solution/2200-2299/2280.Minimum Lines to Represent a Line Chart/README.md b/solution/2200-2299/2280.Minimum Lines to Represent a Line Chart/README.md index b62cc42e9fa59..03b5794bd546e 100644 --- a/solution/2200-2299/2280.Minimum Lines to Represent a Line Chart/README.md +++ b/solution/2200-2299/2280.Minimum Lines to Represent a Line Chart/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def minimumLines(self, stockPrices: List[List[int]]) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumLines(int[][] stockPrices) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func minimumLines(stockPrices [][]int) int { ans := 0 @@ -151,6 +159,8 @@ func minimumLines(stockPrices [][]int) int { } ``` +#### TypeScript + ```ts function minimumLines(stockPrices: number[][]): number { const n = stockPrices.length; diff --git a/solution/2200-2299/2280.Minimum Lines to Represent a Line Chart/README_EN.md b/solution/2200-2299/2280.Minimum Lines to Represent a Line Chart/README_EN.md index 1da7a74d78083..dd93d137bb8b9 100644 --- a/solution/2200-2299/2280.Minimum Lines to Represent a Line Chart/README_EN.md +++ b/solution/2200-2299/2280.Minimum Lines to Represent a Line Chart/README_EN.md @@ -70,6 +70,8 @@ As shown in the diagram above, the line chart can be represented with a single l +#### Python3 + ```python class Solution: def minimumLines(self, stockPrices: List[List[int]]) -> int: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumLines(int[][] stockPrices) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func minimumLines(stockPrices [][]int) int { ans := 0 @@ -142,6 +150,8 @@ func minimumLines(stockPrices [][]int) int { } ``` +#### TypeScript + ```ts function minimumLines(stockPrices: number[][]): number { const n = stockPrices.length; diff --git a/solution/2200-2299/2281.Sum of Total Strength of Wizards/README.md b/solution/2200-2299/2281.Sum of Total Strength of Wizards/README.md index c057ea196a29f..95d18ccc943be 100644 --- a/solution/2200-2299/2281.Sum of Total Strength of Wizards/README.md +++ b/solution/2200-2299/2281.Sum of Total Strength of Wizards/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def totalStrength(self, strength: List[int]) -> int: @@ -123,6 +125,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int totalStrength(int[] strength) { @@ -173,6 +177,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -210,6 +216,8 @@ public: }; ``` +#### Go + ```go func totalStrength(strength []int) int { n := len(strength) diff --git a/solution/2200-2299/2281.Sum of Total Strength of Wizards/README_EN.md b/solution/2200-2299/2281.Sum of Total Strength of Wizards/README_EN.md index dd2069636830e..7494727e98189 100644 --- a/solution/2200-2299/2281.Sum of Total Strength of Wizards/README_EN.md +++ b/solution/2200-2299/2281.Sum of Total Strength of Wizards/README_EN.md @@ -87,6 +87,8 @@ The sum of all the total strengths is 25 + 16 + 36 + 36 + 40 + 60 = 213. +#### Python3 + ```python class Solution: def totalStrength(self, strength: List[int]) -> int: @@ -119,6 +121,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int totalStrength(int[] strength) { @@ -169,6 +173,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -206,6 +212,8 @@ public: }; ``` +#### Go + ```go func totalStrength(strength []int) int { n := len(strength) diff --git a/solution/2200-2299/2282.Number of People That Can Be Seen in a Grid/README.md b/solution/2200-2299/2282.Number of People That Can Be Seen in a Grid/README.md index 9cd37e0709c5a..39a4af03aff23 100644 --- a/solution/2200-2299/2282.Number of People That Can Be Seen in a Grid/README.md +++ b/solution/2200-2299/2282.Number of People That Can Be Seen in a Grid/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class Solution: def seePeople(self, heights: List[List[int]]) -> List[List[int]]: @@ -123,6 +125,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] seePeople(int[][] heights) { @@ -166,6 +170,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -209,6 +215,8 @@ public: }; ``` +#### Go + ```go func seePeople(heights [][]int) (ans [][]int) { f := func(nums []int) []int { @@ -247,6 +255,8 @@ func seePeople(heights [][]int) (ans [][]int) { } ``` +#### TypeScript + ```ts function seePeople(heights: number[][]): number[][] { const f = (nums: number[]): number[] => { diff --git a/solution/2200-2299/2282.Number of People That Can Be Seen in a Grid/README_EN.md b/solution/2200-2299/2282.Number of People That Can Be Seen in a Grid/README_EN.md index 824fbe7ccc4fd..9605ecd80704a 100644 --- a/solution/2200-2299/2282.Number of People That Can Be Seen in a Grid/README_EN.md +++ b/solution/2200-2299/2282.Number of People That Can Be Seen in a Grid/README_EN.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def seePeople(self, heights: List[List[int]]) -> List[List[int]]: @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] seePeople(int[][] heights) { @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -191,6 +197,8 @@ public: }; ``` +#### Go + ```go func seePeople(heights [][]int) (ans [][]int) { f := func(nums []int) []int { @@ -229,6 +237,8 @@ func seePeople(heights [][]int) (ans [][]int) { } ``` +#### TypeScript + ```ts function seePeople(heights: number[][]): number[][] { const f = (nums: number[]): number[] => { diff --git a/solution/2200-2299/2283.Check if Number Has Equal Digit Count and Digit Value/README.md b/solution/2200-2299/2283.Check if Number Has Equal Digit Count and Digit Value/README.md index 55db0d15691a4..54a2cb136451a 100644 --- a/solution/2200-2299/2283.Check if Number Has Equal Digit Count and Digit Value/README.md +++ b/solution/2200-2299/2283.Check if Number Has Equal Digit Count and Digit Value/README.md @@ -75,6 +75,8 @@ num[2] = '0' 。数字 2 在 num 中出现了 0 次。 +#### Python3 + ```python class Solution: def digitCount(self, num: str) -> bool: @@ -82,6 +84,8 @@ class Solution: return all(cnt[str(i)] == int(v) for i, v in enumerate(num)) ``` +#### Java + ```java class Solution { public boolean digitCount(String num) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func digitCount(num string) bool { cnt := [10]int{} @@ -133,6 +141,8 @@ func digitCount(num string) bool { } ``` +#### TypeScript + ```ts function digitCount(num: string): boolean { const n = num.length; @@ -147,6 +157,8 @@ function digitCount(num: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn digit_count(num: String) -> bool { @@ -164,6 +176,8 @@ impl Solution { } ``` +#### C + ```c bool digitCount(char* num) { int count[10] = {0}; diff --git a/solution/2200-2299/2283.Check if Number Has Equal Digit Count and Digit Value/README_EN.md b/solution/2200-2299/2283.Check if Number Has Equal Digit Count and Digit Value/README_EN.md index 88eb2dcb77f61..28e6796c0d1db 100644 --- a/solution/2200-2299/2283.Check if Number Has Equal Digit Count and Digit Value/README_EN.md +++ b/solution/2200-2299/2283.Check if Number Has Equal Digit Count and Digit Value/README_EN.md @@ -69,6 +69,8 @@ The indices 0 and 1 both violate the condition, so return false. +#### Python3 + ```python class Solution: def digitCount(self, num: str) -> bool: @@ -76,6 +78,8 @@ class Solution: return all(cnt[str(i)] == int(v) for i, v in enumerate(num)) ``` +#### Java + ```java class Solution { public boolean digitCount(String num) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func digitCount(num string) bool { cnt := [10]int{} @@ -127,6 +135,8 @@ func digitCount(num string) bool { } ``` +#### TypeScript + ```ts function digitCount(num: string): boolean { const n = num.length; @@ -141,6 +151,8 @@ function digitCount(num: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn digit_count(num: String) -> bool { @@ -158,6 +170,8 @@ impl Solution { } ``` +#### C + ```c bool digitCount(char* num) { int count[10] = {0}; diff --git a/solution/2200-2299/2284.Sender With Largest Word Count/README.md b/solution/2200-2299/2284.Sender With Largest Word Count/README.md index bea1a3b969506..1c4543072a1c2 100644 --- a/solution/2200-2299/2284.Sender With Largest Word Count/README.md +++ b/solution/2200-2299/2284.Sender With Largest Word Count/README.md @@ -83,6 +83,8 @@ Charlie 总共发出了 5 个单词。 +#### Python3 + ```python class Solution: def largestWordCount(self, messages: List[str], senders: List[str]) -> str: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String largestWordCount(String[] messages, String[] senders) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func largestWordCount(messages []string, senders []string) (ans string) { cnt := map[string]int{} diff --git a/solution/2200-2299/2284.Sender With Largest Word Count/README_EN.md b/solution/2200-2299/2284.Sender With Largest Word Count/README_EN.md index af44b1238ecc4..bc3c4199d8497 100644 --- a/solution/2200-2299/2284.Sender With Largest Word Count/README_EN.md +++ b/solution/2200-2299/2284.Sender With Largest Word Count/README_EN.md @@ -79,6 +79,8 @@ Since there is a tie for the largest word count, we return the sender with the l +#### Python3 + ```python class Solution: def largestWordCount(self, messages: List[str], senders: List[str]) -> str: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String largestWordCount(String[] messages, String[] senders) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func largestWordCount(messages []string, senders []string) (ans string) { cnt := map[string]int{} diff --git a/solution/2200-2299/2285.Maximum Total Importance of Roads/README.md b/solution/2200-2299/2285.Maximum Total Importance of Roads/README.md index 51b6dfc008d19..01f3f9039266e 100644 --- a/solution/2200-2299/2285.Maximum Total Importance of Roads/README.md +++ b/solution/2200-2299/2285.Maximum Total Importance of Roads/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def maximumImportance(self, n: int, roads: List[List[int]]) -> int: @@ -100,6 +102,8 @@ class Solution: return sum(i * v for i, v in enumerate(deg, 1)) ``` +#### Java + ```java class Solution { public long maximumImportance(int n, int[][] roads) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func maximumImportance(n int, roads [][]int) int64 { deg := make([]int, n) diff --git a/solution/2200-2299/2285.Maximum Total Importance of Roads/README_EN.md b/solution/2200-2299/2285.Maximum Total Importance of Roads/README_EN.md index cc5040b8e965f..ac606129a4e6d 100644 --- a/solution/2200-2299/2285.Maximum Total Importance of Roads/README_EN.md +++ b/solution/2200-2299/2285.Maximum Total Importance of Roads/README_EN.md @@ -81,6 +81,8 @@ It can be shown that we cannot obtain a greater total importance than 20. +#### Python3 + ```python class Solution: def maximumImportance(self, n: int, roads: List[List[int]]) -> int: @@ -92,6 +94,8 @@ class Solution: return sum(i * v for i, v in enumerate(deg, 1)) ``` +#### Java + ```java class Solution { public long maximumImportance(int n, int[][] roads) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func maximumImportance(n int, roads [][]int) int64 { deg := make([]int, n) diff --git a/solution/2200-2299/2286.Booking Concert Tickets in Groups/README.md b/solution/2200-2299/2286.Booking Concert Tickets in Groups/README.md index dd9b24cdd20ce..37da7d0030d9d 100644 --- a/solution/2200-2299/2286.Booking Concert Tickets in Groups/README.md +++ b/solution/2200-2299/2286.Booking Concert Tickets in Groups/README.md @@ -122,6 +122,8 @@ bms.scatter(5, 1); // 返回 False +#### Python3 + ```python class Node: def __init__(self): @@ -219,6 +221,8 @@ class BookMyShow: # param_2 = obj.scatter(k,maxRow) ``` +#### Java + ```java class Node { int l, r; @@ -354,6 +358,8 @@ class BookMyShow { */ ``` +#### C++ + ```cpp class Node { public: @@ -492,6 +498,8 @@ private: */ ``` +#### Go + ```go type BookMyShow struct { n, m int diff --git a/solution/2200-2299/2286.Booking Concert Tickets in Groups/README_EN.md b/solution/2200-2299/2286.Booking Concert Tickets in Groups/README_EN.md index 1a70ff03d1a78..d3262ff11b6f5 100644 --- a/solution/2200-2299/2286.Booking Concert Tickets in Groups/README_EN.md +++ b/solution/2200-2299/2286.Booking Concert Tickets in Groups/README_EN.md @@ -86,6 +86,8 @@ bms.scatter(5, 1); // return False +#### Python3 + ```python class Node: def __init__(self): @@ -183,6 +185,8 @@ class BookMyShow: # param_2 = obj.scatter(k,maxRow) ``` +#### Java + ```java class Node { int l, r; @@ -318,6 +322,8 @@ class BookMyShow { */ ``` +#### C++ + ```cpp class Node { public: @@ -456,6 +462,8 @@ private: */ ``` +#### Go + ```go type BookMyShow struct { n, m int diff --git a/solution/2200-2299/2287.Rearrange Characters to Make Target String/README.md b/solution/2200-2299/2287.Rearrange Characters to Make Target String/README.md index 7875f0658c762..49b566f50a742 100644 --- a/solution/2200-2299/2287.Rearrange Characters to Make Target String/README.md +++ b/solution/2200-2299/2287.Rearrange Characters to Make Target String/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def rearrangeCharacters(self, s: str, target: str) -> int: @@ -88,6 +90,8 @@ class Solution: return min(cnt1[c] // v for c, v in cnt2.items()) ``` +#### Java + ```java class Solution { public int rearrangeCharacters(String s, String target) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func rearrangeCharacters(s string, target string) int { var cnt1, cnt2 [26]int @@ -152,6 +160,8 @@ func rearrangeCharacters(s string, target string) int { } ``` +#### TypeScript + ```ts function rearrangeCharacters(s: string, target: string): number { const idx = (s: string) => s.charCodeAt(0) - 97; @@ -173,6 +183,8 @@ function rearrangeCharacters(s: string, target: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn rearrange_characters(s: String, target: String) -> i32 { @@ -195,6 +207,8 @@ impl Solution { } ``` +#### C + ```c #define min(a, b) (((a) < (b)) ? (a) : (b)) diff --git a/solution/2200-2299/2287.Rearrange Characters to Make Target String/README_EN.md b/solution/2200-2299/2287.Rearrange Characters to Make Target String/README_EN.md index 613f0713ee3a1..d51bf724e6daf 100644 --- a/solution/2200-2299/2287.Rearrange Characters to Make Target String/README_EN.md +++ b/solution/2200-2299/2287.Rearrange Characters to Make Target String/README_EN.md @@ -77,6 +77,8 @@ We can make at most one copy of "aaaaa", so we return 1. +#### Python3 + ```python class Solution: def rearrangeCharacters(self, s: str, target: str) -> int: @@ -85,6 +87,8 @@ class Solution: return min(cnt1[c] // v for c, v in cnt2.items()) ``` +#### Java + ```java class Solution { public int rearrangeCharacters(String s, String target) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func rearrangeCharacters(s string, target string) int { var cnt1, cnt2 [26]int @@ -149,6 +157,8 @@ func rearrangeCharacters(s string, target string) int { } ``` +#### TypeScript + ```ts function rearrangeCharacters(s: string, target: string): number { const idx = (s: string) => s.charCodeAt(0) - 97; @@ -170,6 +180,8 @@ function rearrangeCharacters(s: string, target: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn rearrange_characters(s: String, target: String) -> i32 { @@ -192,6 +204,8 @@ impl Solution { } ``` +#### C + ```c #define min(a, b) (((a) < (b)) ? (a) : (b)) diff --git a/solution/2200-2299/2288.Apply Discount to Prices/README.md b/solution/2200-2299/2288.Apply Discount to Prices/README.md index 16ae49a7e5074..7b7bc38fe248a 100644 --- a/solution/2200-2299/2288.Apply Discount to Prices/README.md +++ b/solution/2200-2299/2288.Apply Discount to Prices/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def discountPrices(self, sentence: str, discount: int) -> str: @@ -92,6 +94,8 @@ class Solution: return ' '.join(ans) ``` +#### Java + ```java class Solution { public String discountPrices(String sentence, int discount) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func discountPrices(sentence string, discount int) string { words := strings.Split(sentence, " ") @@ -168,6 +176,8 @@ func discountPrices(sentence string, discount int) string { } ``` +#### TypeScript + ```ts function discountPrices(sentence: string, discount: number): string { const sell = (100 - discount) / 100; diff --git a/solution/2200-2299/2288.Apply Discount to Prices/README_EN.md b/solution/2200-2299/2288.Apply Discount to Prices/README_EN.md index 954830746d79f..5ae53113932cb 100644 --- a/solution/2200-2299/2288.Apply Discount to Prices/README_EN.md +++ b/solution/2200-2299/2288.Apply Discount to Prices/README_EN.md @@ -76,6 +76,8 @@ Each of them is replaced by "$0.00". +#### Python3 + ```python class Solution: def discountPrices(self, sentence: str, discount: int) -> str: @@ -87,6 +89,8 @@ class Solution: return ' '.join(ans) ``` +#### Java + ```java class Solution { public String discountPrices(String sentence, int discount) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func discountPrices(sentence string, discount int) string { words := strings.Split(sentence, " ") @@ -163,6 +171,8 @@ func discountPrices(sentence string, discount int) string { } ``` +#### TypeScript + ```ts function discountPrices(sentence: string, discount: number): string { const sell = (100 - discount) / 100; diff --git a/solution/2200-2299/2289.Steps to Make Array Non-decreasing/README.md b/solution/2200-2299/2289.Steps to Make Array Non-decreasing/README.md index 98114b1975ddd..5fdc6be56d7ed 100644 --- a/solution/2200-2299/2289.Steps to Make Array Non-decreasing/README.md +++ b/solution/2200-2299/2289.Steps to Make Array Non-decreasing/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def totalSteps(self, nums: List[int]) -> int: @@ -79,6 +81,8 @@ class Solution: return max(dp) ``` +#### Java + ```java class Solution { public int totalSteps(int[] nums) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func totalSteps(nums []int) int { stk := []int{} @@ -135,6 +143,8 @@ func totalSteps(nums []int) int { } ``` +#### TypeScript + ```ts function totalSteps(nums: number[]): number { let ans = 0; diff --git a/solution/2200-2299/2289.Steps to Make Array Non-decreasing/README_EN.md b/solution/2200-2299/2289.Steps to Make Array Non-decreasing/README_EN.md index 735dc7b609e3c..27488812c299a 100644 --- a/solution/2200-2299/2289.Steps to Make Array Non-decreasing/README_EN.md +++ b/solution/2200-2299/2289.Steps to Make Array Non-decreasing/README_EN.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def totalSteps(self, nums: List[int]) -> int: @@ -77,6 +79,8 @@ class Solution: return max(dp) ``` +#### Java + ```java class Solution { public int totalSteps(int[] nums) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func totalSteps(nums []int) int { stk := []int{} @@ -133,6 +141,8 @@ func totalSteps(nums []int) int { } ``` +#### TypeScript + ```ts function totalSteps(nums: number[]): number { let ans = 0; diff --git a/solution/2200-2299/2290.Minimum Obstacle Removal to Reach Corner/README.md b/solution/2200-2299/2290.Minimum Obstacle Removal to Reach Corner/README.md index a59db3964e288..843c7ee9fcc13 100644 --- a/solution/2200-2299/2290.Minimum Obstacle Removal to Reach Corner/README.md +++ b/solution/2200-2299/2290.Minimum Obstacle Removal to Reach Corner/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def minimumObstacles(self, grid: List[List[int]]) -> int: @@ -116,6 +118,8 @@ class Solution: q.append((x, y, k + 1)) ``` +#### Java + ```java class Solution { public int minimumObstacles(int[][] grid) { @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -183,6 +189,8 @@ public: }; ``` +#### Go + ```go func minimumObstacles(grid [][]int) int { m, n := len(grid), len(grid[0]) @@ -220,6 +228,8 @@ func minimumObstacles(grid [][]int) int { } ``` +#### TypeScript + ```ts function minimumObstacles(grid: number[][]): number { const m = grid.length, diff --git a/solution/2200-2299/2290.Minimum Obstacle Removal to Reach Corner/README_EN.md b/solution/2200-2299/2290.Minimum Obstacle Removal to Reach Corner/README_EN.md index ceeea5bca39ed..3fe7d2e1ccced 100644 --- a/solution/2200-2299/2290.Minimum Obstacle Removal to Reach Corner/README_EN.md +++ b/solution/2200-2299/2290.Minimum Obstacle Removal to Reach Corner/README_EN.md @@ -75,6 +75,8 @@ Note that there may be other ways to remove 2 obstacles to create a path. +#### Python3 + ```python class Solution: def minimumObstacles(self, grid: List[List[int]]) -> int: @@ -98,6 +100,8 @@ class Solution: q.append((x, y, k + 1)) ``` +#### Java + ```java class Solution { public int minimumObstacles(int[][] grid) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func minimumObstacles(grid [][]int) int { m, n := len(grid), len(grid[0]) @@ -202,6 +210,8 @@ func minimumObstacles(grid [][]int) int { } ``` +#### TypeScript + ```ts function minimumObstacles(grid: number[][]): number { const m = grid.length, diff --git a/solution/2200-2299/2291.Maximum Profit From Trading Stocks/README.md b/solution/2200-2299/2291.Maximum Profit From Trading Stocks/README.md index 8e253e301a3d6..928d477f9b72a 100644 --- a/solution/2200-2299/2291.Maximum Profit From Trading Stocks/README.md +++ b/solution/2200-2299/2291.Maximum Profit From Trading Stocks/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def maximumProfit(self, present: List[int], future: List[int], budget: int) -> int: @@ -93,6 +95,8 @@ class Solution: return f[-1][-1] ``` +#### Java + ```java class Solution { public int maximumProfit(int[] present, int[] future, int budget) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func maximumProfit(present []int, future []int, budget int) int { n := len(present) @@ -151,6 +159,8 @@ func maximumProfit(present []int, future []int, budget int) int { } ``` +#### TypeScript + ```ts function maximumProfit(present: number[], future: number[], budget: number): number { const f = new Array(budget + 1).fill(0); @@ -174,6 +184,8 @@ function maximumProfit(present: number[], future: number[], budget: number): num +#### Python3 + ```python class Solution: def maximumProfit(self, present: List[int], future: List[int], budget: int) -> int: @@ -184,6 +196,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int maximumProfit(int[] present, int[] future, int budget) { @@ -200,6 +214,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -218,6 +234,8 @@ public: }; ``` +#### Go + ```go func maximumProfit(present []int, future []int, budget int) int { f := make([]int, budget+1) diff --git a/solution/2200-2299/2291.Maximum Profit From Trading Stocks/README_EN.md b/solution/2200-2299/2291.Maximum Profit From Trading Stocks/README_EN.md index 4dd202b519e98..10abc56c4cf7b 100644 --- a/solution/2200-2299/2291.Maximum Profit From Trading Stocks/README_EN.md +++ b/solution/2200-2299/2291.Maximum Profit From Trading Stocks/README_EN.md @@ -74,6 +74,8 @@ It can be shown that the maximum profit you can make is 0. +#### Python3 + ```python class Solution: def maximumProfit(self, present: List[int], future: List[int], budget: int) -> int: @@ -86,6 +88,8 @@ class Solution: return f[-1][-1] ``` +#### Java + ```java class Solution { public int maximumProfit(int[] present, int[] future, int budget) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func maximumProfit(present []int, future []int, budget int) int { n := len(present) @@ -144,6 +152,8 @@ func maximumProfit(present []int, future []int, budget int) int { } ``` +#### TypeScript + ```ts function maximumProfit(present: number[], future: number[], budget: number): number { const f = new Array(budget + 1).fill(0); @@ -167,6 +177,8 @@ function maximumProfit(present: number[], future: number[], budget: number): num +#### Python3 + ```python class Solution: def maximumProfit(self, present: List[int], future: List[int], budget: int) -> int: @@ -177,6 +189,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int maximumProfit(int[] present, int[] future, int budget) { @@ -193,6 +207,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -211,6 +227,8 @@ public: }; ``` +#### Go + ```go func maximumProfit(present []int, future []int, budget int) int { f := make([]int, budget+1) diff --git a/solution/2200-2299/2292.Products With Three or More Orders in Two Consecutive Years/README.md b/solution/2200-2299/2292.Products With Three or More Orders in Two Consecutive Years/README.md index 21ba33474a430..45320a479e691 100644 --- a/solution/2200-2299/2292.Products With Three or More Orders in Two Consecutive Years/README.md +++ b/solution/2200-2299/2292.Products With Three or More Orders in Two Consecutive Years/README.md @@ -78,6 +78,8 @@ Orders 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -103,6 +105,8 @@ WHERE p1.mark AND p2.mark; +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2200-2299/2292.Products With Three or More Orders in Two Consecutive Years/README_EN.md b/solution/2200-2299/2292.Products With Three or More Orders in Two Consecutive Years/README_EN.md index 4565043f8a97d..1ae6e2b347626 100644 --- a/solution/2200-2299/2292.Products With Three or More Orders in Two Consecutive Years/README_EN.md +++ b/solution/2200-2299/2292.Products With Three or More Orders in Two Consecutive Years/README_EN.md @@ -77,6 +77,8 @@ Product 2 was ordered one time in 2022. We do not include it in the answer. +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -102,6 +104,8 @@ WHERE p1.mark AND p2.mark; +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2200-2299/2293.Min Max Game/README.md b/solution/2200-2299/2293.Min Max Game/README.md index 7f203477c8d93..3f33f38faa9b6 100644 --- a/solution/2200-2299/2293.Min Max Game/README.md +++ b/solution/2200-2299/2293.Min Max Game/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def minMaxGame(self, nums: List[int]) -> int: @@ -93,6 +95,8 @@ class Solution: return nums[0] ``` +#### Java + ```java class Solution { public int minMaxGame(int[] nums) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func minMaxGame(nums []int) int { for n := len(nums); n > 1; { @@ -141,6 +149,8 @@ func minMaxGame(nums []int) int { } ``` +#### TypeScript + ```ts function minMaxGame(nums: number[]): number { for (let n = nums.length; n > 1; ) { @@ -155,6 +165,8 @@ function minMaxGame(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_max_game(mut nums: Vec) -> i32 { @@ -173,6 +185,8 @@ impl Solution { } ``` +#### C + ```c #define min(a, b) (((a) < (b)) ? (a) : (b)) #define max(a, b) (((a) > (b)) ? (a) : (b)) diff --git a/solution/2200-2299/2293.Min Max Game/README_EN.md b/solution/2200-2299/2293.Min Max Game/README_EN.md index 9b66afc4f6028..028546c274575 100644 --- a/solution/2200-2299/2293.Min Max Game/README_EN.md +++ b/solution/2200-2299/2293.Min Max Game/README_EN.md @@ -73,6 +73,8 @@ Third: nums = [1] +#### Python3 + ```python class Solution: def minMaxGame(self, nums: List[int]) -> int: @@ -85,6 +87,8 @@ class Solution: return nums[0] ``` +#### Java + ```java class Solution { public int minMaxGame(int[] nums) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func minMaxGame(nums []int) int { for n := len(nums); n > 1; { @@ -133,6 +141,8 @@ func minMaxGame(nums []int) int { } ``` +#### TypeScript + ```ts function minMaxGame(nums: number[]): number { for (let n = nums.length; n > 1; ) { @@ -147,6 +157,8 @@ function minMaxGame(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_max_game(mut nums: Vec) -> i32 { @@ -165,6 +177,8 @@ impl Solution { } ``` +#### C + ```c #define min(a, b) (((a) < (b)) ? (a) : (b)) #define max(a, b) (((a) > (b)) ? (a) : (b)) diff --git a/solution/2200-2299/2294.Partition Array Such That Maximum Difference Is K/README.md b/solution/2200-2299/2294.Partition Array Such That Maximum Difference Is K/README.md index b8497cb83c0c1..bbcd842bc17c7 100644 --- a/solution/2200-2299/2294.Partition Array Such That Maximum Difference Is K/README.md +++ b/solution/2200-2299/2294.Partition Array Such That Maximum Difference Is K/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def partitionArray(self, nums: List[int], k: int) -> int: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int partitionArray(int[] nums, int k) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func partitionArray(nums []int, k int) int { sort.Ints(nums) @@ -148,6 +156,8 @@ func partitionArray(nums []int, k int) int { } ``` +#### TypeScript + ```ts function partitionArray(nums: number[], k: number): number { nums.sort((a, b) => a - b); diff --git a/solution/2200-2299/2294.Partition Array Such That Maximum Difference Is K/README_EN.md b/solution/2200-2299/2294.Partition Array Such That Maximum Difference Is K/README_EN.md index fd9f83deb7c7e..bbf4c0002ffcb 100644 --- a/solution/2200-2299/2294.Partition Array Such That Maximum Difference Is K/README_EN.md +++ b/solution/2200-2299/2294.Partition Array Such That Maximum Difference Is K/README_EN.md @@ -83,6 +83,8 @@ Since three subsequences were created, we return 3. It can be shown that 3 is th +#### Python3 + ```python class Solution: def partitionArray(self, nums: List[int], k: int) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int partitionArray(int[] nums, int k) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func partitionArray(nums []int, k int) int { sort.Ints(nums) @@ -142,6 +150,8 @@ func partitionArray(nums []int, k int) int { } ``` +#### TypeScript + ```ts function partitionArray(nums: number[], k: number): number { nums.sort((a, b) => a - b); diff --git a/solution/2200-2299/2295.Replace Elements in an Array/README.md b/solution/2200-2299/2295.Replace Elements in an Array/README.md index 0835d23941a5b..3509330051a05 100644 --- a/solution/2200-2299/2295.Replace Elements in an Array/README.md +++ b/solution/2200-2299/2295.Replace Elements in an Array/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def arrayChange(self, nums: List[int], operations: List[List[int]]) -> List[int]: @@ -96,6 +98,8 @@ class Solution: return nums ``` +#### Java + ```java class Solution { public int[] arrayChange(int[] nums, int[][] operations) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func arrayChange(nums []int, operations [][]int) []int { d := map[int]int{} @@ -146,6 +154,8 @@ func arrayChange(nums []int, operations [][]int) []int { } ``` +#### TypeScript + ```ts function arrayChange(nums: number[], operations: number[][]): number[] { const d = new Map(nums.map((v, i) => [v, i])); diff --git a/solution/2200-2299/2295.Replace Elements in an Array/README_EN.md b/solution/2200-2299/2295.Replace Elements in an Array/README_EN.md index 49c0de742fb4d..284387d56548a 100644 --- a/solution/2200-2299/2295.Replace Elements in an Array/README_EN.md +++ b/solution/2200-2299/2295.Replace Elements in an Array/README_EN.md @@ -80,6 +80,8 @@ We return the array [2,1]. +#### Python3 + ```python class Solution: def arrayChange(self, nums: List[int], operations: List[List[int]]) -> List[int]: @@ -90,6 +92,8 @@ class Solution: return nums ``` +#### Java + ```java class Solution { public int[] arrayChange(int[] nums, int[][] operations) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func arrayChange(nums []int, operations [][]int) []int { d := map[int]int{} @@ -140,6 +148,8 @@ func arrayChange(nums []int, operations [][]int) []int { } ``` +#### TypeScript + ```ts function arrayChange(nums: number[], operations: number[][]): number[] { const d = new Map(nums.map((v, i) => [v, i])); diff --git a/solution/2200-2299/2296.Design a Text Editor/README.md b/solution/2200-2299/2296.Design a Text Editor/README.md index 1c9d451e6c711..6d8b4274f4458 100644 --- a/solution/2200-2299/2296.Design a Text Editor/README.md +++ b/solution/2200-2299/2296.Design a Text Editor/README.md @@ -111,6 +111,8 @@ textEditor.cursorRight(6); // 返回 "practi" +#### Python3 + ```python class TextEditor: def __init__(self): @@ -147,6 +149,8 @@ class TextEditor: # param_4 = obj.cursorRight(k) ``` +#### Java + ```java class TextEditor { private StringBuilder left = new StringBuilder(); @@ -194,6 +198,8 @@ class TextEditor { */ ``` +#### C++ + ```cpp class TextEditor { public: @@ -242,6 +248,8 @@ private: */ ``` +#### Go + ```go type TextEditor struct { left, right []byte diff --git a/solution/2200-2299/2296.Design a Text Editor/README_EN.md b/solution/2200-2299/2296.Design a Text Editor/README_EN.md index 673381f79dbe7..c87145f63d889 100644 --- a/solution/2200-2299/2296.Design a Text Editor/README_EN.md +++ b/solution/2200-2299/2296.Design a Text Editor/README_EN.md @@ -101,6 +101,8 @@ textEditor.cursorRight(6); // return "practi" +#### Python3 + ```python class TextEditor: def __init__(self): @@ -137,6 +139,8 @@ class TextEditor: # param_4 = obj.cursorRight(k) ``` +#### Java + ```java class TextEditor { private StringBuilder left = new StringBuilder(); @@ -184,6 +188,8 @@ class TextEditor { */ ``` +#### C++ + ```cpp class TextEditor { public: @@ -232,6 +238,8 @@ private: */ ``` +#### Go + ```go type TextEditor struct { left, right []byte diff --git a/solution/2200-2299/2297.Jump Game VIII/README.md b/solution/2200-2299/2297.Jump Game VIII/README.md index 27da998c05650..222ec0fb652ce 100644 --- a/solution/2200-2299/2297.Jump Game VIII/README.md +++ b/solution/2200-2299/2297.Jump Game VIII/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def minCost(self, nums: List[int], costs: List[int]) -> int: @@ -111,6 +113,8 @@ class Solution: return f[n - 1] ``` +#### Java + ```java class Solution { public long minCost(int[] nums, int[] costs) { @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go func minCost(nums []int, costs []int) int64 { n := len(nums) @@ -225,6 +233,8 @@ func minCost(nums []int, costs []int) int64 { } ``` +#### TypeScript + ```ts function minCost(nums: number[], costs: number[]): number { const n = nums.length; diff --git a/solution/2200-2299/2297.Jump Game VIII/README_EN.md b/solution/2200-2299/2297.Jump Game VIII/README_EN.md index d79f43edeb712..876bea63d4678 100644 --- a/solution/2200-2299/2297.Jump Game VIII/README_EN.md +++ b/solution/2200-2299/2297.Jump Game VIII/README_EN.md @@ -76,6 +76,8 @@ The total cost is 2. Note that you cannot jump directly from index 0 to index 2 +#### Python3 + ```python class Solution: def minCost(self, nums: List[int], costs: List[int]) -> int: @@ -105,6 +107,8 @@ class Solution: return f[n - 1] ``` +#### Java + ```java class Solution { public long minCost(int[] nums, int[] costs) { @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -182,6 +188,8 @@ public: }; ``` +#### Go + ```go func minCost(nums []int, costs []int) int64 { n := len(nums) @@ -219,6 +227,8 @@ func minCost(nums []int, costs []int) int64 { } ``` +#### TypeScript + ```ts function minCost(nums: number[], costs: number[]): number { const n = nums.length; diff --git a/solution/2200-2299/2298.Tasks Count in the Weekend/README.md b/solution/2200-2299/2298.Tasks Count in the Weekend/README.md index 5fc3e13d14bae..112ea2612d55a 100644 --- a/solution/2200-2299/2298.Tasks Count in the Weekend/README.md +++ b/solution/2200-2299/2298.Tasks Count in the Weekend/README.md @@ -88,6 +88,8 @@ Task 6 是在周日提交的。 +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2200-2299/2298.Tasks Count in the Weekend/README_EN.md b/solution/2200-2299/2298.Tasks Count in the Weekend/README_EN.md index 79046ccc16743..0badaa54484b4 100644 --- a/solution/2200-2299/2298.Tasks Count in the Weekend/README_EN.md +++ b/solution/2200-2299/2298.Tasks Count in the Weekend/README_EN.md @@ -86,6 +86,8 @@ Task 6 was submitted on Sunday. +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2200-2299/2299.Strong Password Checker II/README.md b/solution/2200-2299/2299.Strong Password Checker II/README.md index 4c750e14f19ae..8df124cb5d4f2 100644 --- a/solution/2200-2299/2299.Strong Password Checker II/README.md +++ b/solution/2200-2299/2299.Strong Password Checker II/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def strongPasswordCheckerII(self, password: str) -> bool: @@ -100,6 +102,8 @@ class Solution: return mask == 15 ``` +#### Java + ```java class Solution { public boolean strongPasswordCheckerII(String password) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func strongPasswordCheckerII(password string) bool { if len(password) < 8 { @@ -179,6 +187,8 @@ func strongPasswordCheckerII(password string) bool { } ``` +#### TypeScript + ```ts function strongPasswordCheckerII(password: string): boolean { if (password.length < 8) { @@ -204,6 +214,8 @@ function strongPasswordCheckerII(password: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn strong_password_checker_ii(password: String) -> bool { @@ -234,6 +246,8 @@ impl Solution { } ``` +#### C + ```c bool strongPasswordCheckerII(char* password) { int n = strlen(password); diff --git a/solution/2200-2299/2299.Strong Password Checker II/README_EN.md b/solution/2200-2299/2299.Strong Password Checker II/README_EN.md index b50eb1a3e1ab9..b88f2f25efe5b 100644 --- a/solution/2200-2299/2299.Strong Password Checker II/README_EN.md +++ b/solution/2200-2299/2299.Strong Password Checker II/README_EN.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def strongPasswordCheckerII(self, password: str) -> bool: @@ -93,6 +95,8 @@ class Solution: return mask == 15 ``` +#### Java + ```java class Solution { public boolean strongPasswordCheckerII(String password) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func strongPasswordCheckerII(password string) bool { if len(password) < 8 { @@ -172,6 +180,8 @@ func strongPasswordCheckerII(password string) bool { } ``` +#### TypeScript + ```ts function strongPasswordCheckerII(password: string): boolean { if (password.length < 8) { @@ -197,6 +207,8 @@ function strongPasswordCheckerII(password: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn strong_password_checker_ii(password: String) -> bool { @@ -227,6 +239,8 @@ impl Solution { } ``` +#### C + ```c bool strongPasswordCheckerII(char* password) { int n = strlen(password); diff --git a/solution/2300-2399/2300.Successful Pairs of Spells and Potions/README.md b/solution/2300-2399/2300.Successful Pairs of Spells and Potions/README.md index 09a416e3f0a3f..88e65ee3b9473 100644 --- a/solution/2300-2399/2300.Successful Pairs of Spells and Potions/README.md +++ b/solution/2300-2399/2300.Successful Pairs of Spells and Potions/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def successfulPairs( @@ -87,6 +89,8 @@ class Solution: return [m - bisect_left(potions, success / v) for v in spells] ``` +#### Java + ```java class Solution { public int[] successfulPairs(int[] spells, int[] potions, long success) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func successfulPairs(spells []int, potions []int, success int64) (ans []int) { sort.Ints(potions) @@ -138,6 +146,8 @@ func successfulPairs(spells []int, potions []int, success int64) (ans []int) { } ``` +#### TypeScript + ```ts function successfulPairs(spells: number[], potions: number[], success: number): number[] { potions.sort((a, b) => a - b); diff --git a/solution/2300-2399/2300.Successful Pairs of Spells and Potions/README_EN.md b/solution/2300-2399/2300.Successful Pairs of Spells and Potions/README_EN.md index 48306779318db..463d652b4ed1e 100644 --- a/solution/2300-2399/2300.Successful Pairs of Spells and Potions/README_EN.md +++ b/solution/2300-2399/2300.Successful Pairs of Spells and Potions/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O((m + n) \times \log m)$, and the space complexity is $ +#### Python3 + ```python class Solution: def successfulPairs( @@ -87,6 +89,8 @@ class Solution: return [m - bisect_left(potions, success / v) for v in spells] ``` +#### Java + ```java class Solution { public int[] successfulPairs(int[] spells, int[] potions, long success) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func successfulPairs(spells []int, potions []int, success int64) (ans []int) { sort.Ints(potions) @@ -138,6 +146,8 @@ func successfulPairs(spells []int, potions []int, success int64) (ans []int) { } ``` +#### TypeScript + ```ts function successfulPairs(spells: number[], potions: number[], success: number): number[] { potions.sort((a, b) => a - b); diff --git a/solution/2300-2399/2301.Match Substring After Replacement/README.md b/solution/2300-2399/2301.Match Substring After Replacement/README.md index a5cc1b6c8eb21..0db742c84b8fb 100644 --- a/solution/2300-2399/2301.Match Substring After Replacement/README.md +++ b/solution/2300-2399/2301.Match Substring After Replacement/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def matchReplacement(self, s: str, sub: str, mappings: List[List[str]]) -> bool: @@ -98,6 +100,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean matchReplacement(String s, String sub, char[][] mappings) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func matchReplacement(s string, sub string, mappings [][]byte) bool { d := map[byte]map[byte]bool{} @@ -188,6 +196,8 @@ func matchReplacement(s string, sub string, mappings [][]byte) bool { +#### Python3 + ```python class Solution: def matchReplacement(self, s: str, sub: str, mappings: List[List[str]]) -> bool: @@ -202,6 +212,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean matchReplacement(String s, String sub, char[][] mappings) { @@ -227,6 +239,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -253,6 +267,8 @@ public: }; ``` +#### Go + ```go func matchReplacement(s string, sub string, mappings [][]byte) bool { d := [128][128]bool{} diff --git a/solution/2300-2399/2301.Match Substring After Replacement/README_EN.md b/solution/2300-2399/2301.Match Substring After Replacement/README_EN.md index 59aa3b6488400..0309820fbb31c 100644 --- a/solution/2300-2399/2301.Match Substring After Replacement/README_EN.md +++ b/solution/2300-2399/2301.Match Substring After Replacement/README_EN.md @@ -91,6 +91,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(C^2)$. He +#### Python3 + ```python class Solution: def matchReplacement(self, s: str, sub: str, mappings: List[List[str]]) -> bool: @@ -103,6 +105,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean matchReplacement(String s, String sub, char[][] mappings) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func matchReplacement(s string, sub string, mappings [][]byte) bool { d := map[byte]map[byte]bool{} @@ -193,6 +201,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(C^2)$. +#### Python3 + ```python class Solution: def matchReplacement(self, s: str, sub: str, mappings: List[List[str]]) -> bool: @@ -207,6 +217,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean matchReplacement(String s, String sub, char[][] mappings) { @@ -232,6 +244,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -258,6 +272,8 @@ public: }; ``` +#### Go + ```go func matchReplacement(s string, sub string, mappings [][]byte) bool { d := [128][128]bool{} diff --git a/solution/2300-2399/2302.Count Subarrays With Score Less Than K/README.md b/solution/2300-2399/2302.Count Subarrays With Score Less Than K/README.md index 9f69d6fded339..db62a96d934a3 100644 --- a/solution/2300-2399/2302.Count Subarrays With Score Less Than K/README.md +++ b/solution/2300-2399/2302.Count Subarrays With Score Less Than K/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def countSubarrays(self, nums: List[int], k: int) -> int: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long countSubarrays(int[] nums, long k) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func countSubarrays(nums []int, k int64) (ans int64) { n := len(nums) @@ -193,6 +201,8 @@ func countSubarrays(nums []int, k int64) (ans int64) { +#### Python3 + ```python class Solution: def countSubarrays(self, nums: List[int], k: int) -> int: @@ -206,6 +216,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long countSubarrays(int[] nums, long k) { @@ -222,6 +234,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -239,6 +253,8 @@ public: }; ``` +#### Go + ```go func countSubarrays(nums []int, k int64) (ans int64) { s, j := 0, 0 diff --git a/solution/2300-2399/2302.Count Subarrays With Score Less Than K/README_EN.md b/solution/2300-2399/2302.Count Subarrays With Score Less Than K/README_EN.md index a0461474f4d2f..7e1fed60dc386 100644 --- a/solution/2300-2399/2302.Count Subarrays With Score Less Than K/README_EN.md +++ b/solution/2300-2399/2302.Count Subarrays With Score Less Than K/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def countSubarrays(self, nums: List[int], k: int) -> int: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long countSubarrays(int[] nums, long k) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func countSubarrays(nums []int, k int64) (ans int64) { n := len(nums) @@ -191,6 +199,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def countSubarrays(self, nums: List[int], k: int) -> int: @@ -204,6 +214,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long countSubarrays(int[] nums, long k) { @@ -220,6 +232,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -237,6 +251,8 @@ public: }; ``` +#### Go + ```go func countSubarrays(nums []int, k int64) (ans int64) { s, j := 0, 0 diff --git a/solution/2300-2399/2303.Calculate Amount Paid in Taxes/README.md b/solution/2300-2399/2303.Calculate Amount Paid in Taxes/README.md index 8c6b0bb792f62..16d207e777082 100644 --- a/solution/2300-2399/2303.Calculate Amount Paid in Taxes/README.md +++ b/solution/2300-2399/2303.Calculate Amount Paid in Taxes/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def calculateTax(self, brackets: List[List[int]], income: int) -> float: @@ -101,6 +103,8 @@ class Solution: return ans / 100 ``` +#### Java + ```java class Solution { public double calculateTax(int[][] brackets, int income) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func calculateTax(brackets [][]int, income int) float64 { var ans, prev int @@ -142,6 +150,8 @@ func calculateTax(brackets [][]int, income int) float64 { } ``` +#### TypeScript + ```ts function calculateTax(brackets: number[][], income: number): number { let ans = 0; @@ -154,6 +164,8 @@ function calculateTax(brackets: number[][], income: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn calculate_tax(brackets: Vec>, income: i32) -> f64 { diff --git a/solution/2300-2399/2303.Calculate Amount Paid in Taxes/README_EN.md b/solution/2300-2399/2303.Calculate Amount Paid in Taxes/README_EN.md index 3149e63eb74d2..281f4dc27d1de 100644 --- a/solution/2300-2399/2303.Calculate Amount Paid in Taxes/README_EN.md +++ b/solution/2300-2399/2303.Calculate Amount Paid in Taxes/README_EN.md @@ -91,6 +91,8 @@ The time complexity is $O(n)$, where $n$ is the length of `brackets`. The space +#### Python3 + ```python class Solution: def calculateTax(self, brackets: List[List[int]], income: int) -> float: @@ -101,6 +103,8 @@ class Solution: return ans / 100 ``` +#### Java + ```java class Solution { public double calculateTax(int[][] brackets, int income) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func calculateTax(brackets [][]int, income int) float64 { var ans, prev int @@ -142,6 +150,8 @@ func calculateTax(brackets [][]int, income int) float64 { } ``` +#### TypeScript + ```ts function calculateTax(brackets: number[][], income: number): number { let ans = 0; @@ -154,6 +164,8 @@ function calculateTax(brackets: number[][], income: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn calculate_tax(brackets: Vec>, income: i32) -> f64 { diff --git a/solution/2300-2399/2304.Minimum Path Cost in a Grid/README.md b/solution/2300-2399/2304.Minimum Path Cost in a Grid/README.md index 42af7bf80314d..4f6ea9b5c3fab 100644 --- a/solution/2300-2399/2304.Minimum Path Cost in a Grid/README.md +++ b/solution/2300-2399/2304.Minimum Path Cost in a Grid/README.md @@ -91,6 +91,8 @@ $$ +#### Python3 + ```python class Solution: def minPathCost(self, grid: List[List[int]], moveCost: List[List[int]]) -> int: @@ -105,6 +107,8 @@ class Solution: return min(f) ``` +#### Java + ```java class Solution { public int minPathCost(int[][] grid, int[][] moveCost) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func minPathCost(grid [][]int, moveCost [][]int) int { m, n := len(grid), len(grid[0]) @@ -171,6 +179,8 @@ func minPathCost(grid [][]int, moveCost [][]int) int { } ``` +#### TypeScript + ```ts function minPathCost(grid: number[][], moveCost: number[][]): number { const m = grid.length; @@ -189,6 +199,8 @@ function minPathCost(grid: number[][], moveCost: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_path_cost(grid: Vec>, move_cost: Vec>) -> i32 { diff --git a/solution/2300-2399/2304.Minimum Path Cost in a Grid/README_EN.md b/solution/2300-2399/2304.Minimum Path Cost in a Grid/README_EN.md index e7dd049dc8e37..a6cf4c68b7f89 100644 --- a/solution/2300-2399/2304.Minimum Path Cost in a Grid/README_EN.md +++ b/solution/2300-2399/2304.Minimum Path Cost in a Grid/README_EN.md @@ -87,6 +87,8 @@ The time complexity is $O(m \times n^2)$, and the space complexity is $O(n)$. He +#### Python3 + ```python class Solution: def minPathCost(self, grid: List[List[int]], moveCost: List[List[int]]) -> int: @@ -101,6 +103,8 @@ class Solution: return min(f) ``` +#### Java + ```java class Solution { public int minPathCost(int[][] grid, int[][] moveCost) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func minPathCost(grid [][]int, moveCost [][]int) int { m, n := len(grid), len(grid[0]) @@ -167,6 +175,8 @@ func minPathCost(grid [][]int, moveCost [][]int) int { } ``` +#### TypeScript + ```ts function minPathCost(grid: number[][], moveCost: number[][]): number { const m = grid.length; @@ -185,6 +195,8 @@ function minPathCost(grid: number[][], moveCost: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_path_cost(grid: Vec>, move_cost: Vec>) -> i32 { diff --git a/solution/2300-2399/2305.Fair Distribution of Cookies/README.md b/solution/2300-2399/2305.Fair Distribution of Cookies/README.md index 43ea5f3ad203c..059b9bc17fa9b 100644 --- a/solution/2300-2399/2305.Fair Distribution of Cookies/README.md +++ b/solution/2300-2399/2305.Fair Distribution of Cookies/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def distributeCookies(self, cookies: List[int], k: int) -> int: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] cookies; @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func distributeCookies(cookies []int, k int) int { sort.Sort(sort.Reverse(sort.IntSlice(cookies))) @@ -196,6 +204,8 @@ func distributeCookies(cookies []int, k int) int { } ``` +#### TypeScript + ```ts function distributeCookies(cookies: number[], k: number): number { const cnt = new Array(k).fill(0); diff --git a/solution/2300-2399/2305.Fair Distribution of Cookies/README_EN.md b/solution/2300-2399/2305.Fair Distribution of Cookies/README_EN.md index 740b204fa8c87..d919c0e888d01 100644 --- a/solution/2300-2399/2305.Fair Distribution of Cookies/README_EN.md +++ b/solution/2300-2399/2305.Fair Distribution of Cookies/README_EN.md @@ -79,6 +79,8 @@ Finally, we return $ans$. +#### Python3 + ```python class Solution: def distributeCookies(self, cookies: List[int], k: int) -> int: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] cookies; @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func distributeCookies(cookies []int, k int) int { sort.Sort(sort.Reverse(sort.IntSlice(cookies))) @@ -196,6 +204,8 @@ func distributeCookies(cookies []int, k int) int { } ``` +#### TypeScript + ```ts function distributeCookies(cookies: number[], k: number): number { const cnt = new Array(k).fill(0); diff --git a/solution/2300-2399/2306.Naming a Company/README.md b/solution/2300-2399/2306.Naming a Company/README.md index af8629b0c888a..c56b0c39063f3 100644 --- a/solution/2300-2399/2306.Naming a Company/README.md +++ b/solution/2300-2399/2306.Naming a Company/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def distinctNames(self, ideas: List[str]) -> int: @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long distinctNames(String[] ideas) { @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -179,6 +185,8 @@ public: }; ``` +#### Go + ```go func distinctNames(ideas []string) (ans int64) { s := map[string]bool{} @@ -211,6 +219,8 @@ func distinctNames(ideas []string) (ans int64) { } ``` +#### TypeScript + ```ts function distinctNames(ideas: string[]): number { const s = new Set(ideas); diff --git a/solution/2300-2399/2306.Naming a Company/README_EN.md b/solution/2300-2399/2306.Naming a Company/README_EN.md index 69a7b83059bbd..9d0016530900a 100644 --- a/solution/2300-2399/2306.Naming a Company/README_EN.md +++ b/solution/2300-2399/2306.Naming a Company/README_EN.md @@ -92,6 +92,8 @@ The time complexity is $O(n \times m \times |\Sigma|)$, and the space complexity +#### Python3 + ```python class Solution: def distinctNames(self, ideas: List[str]) -> int: @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long distinctNames(String[] ideas) { @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -179,6 +185,8 @@ public: }; ``` +#### Go + ```go func distinctNames(ideas []string) (ans int64) { s := map[string]bool{} @@ -211,6 +219,8 @@ func distinctNames(ideas []string) (ans int64) { } ``` +#### TypeScript + ```ts function distinctNames(ideas: string[]): number { const s = new Set(ideas); diff --git a/solution/2300-2399/2307.Check for Contradictions in Equations/README.md b/solution/2300-2399/2307.Check for Contradictions in Equations/README.md index 73233047901d3..ee236c70fdec3 100644 --- a/solution/2300-2399/2307.Check for Contradictions in Equations/README.md +++ b/solution/2300-2399/2307.Check for Contradictions in Equations/README.md @@ -86,6 +86,8 @@ a = 3, b = 1 和 c = 2. +#### Python3 + ```python class Solution: def checkContradictions( @@ -119,6 +121,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { private int[] p; @@ -166,6 +170,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -206,6 +212,8 @@ public: }; ``` +#### Go + ```go func checkContradictions(equations [][]string, values []float64) bool { d := make(map[string]int) @@ -256,6 +264,8 @@ func checkContradictions(equations [][]string, values []float64) bool { } ``` +#### TypeScript + ```ts function checkContradictions(equations: string[][], values: number[]): boolean { const d: { [key: string]: number } = {}; diff --git a/solution/2300-2399/2307.Check for Contradictions in Equations/README_EN.md b/solution/2300-2399/2307.Check for Contradictions in Equations/README_EN.md index 014a920d25f72..eba5095e80b53 100644 --- a/solution/2300-2399/2307.Check for Contradictions in Equations/README_EN.md +++ b/solution/2300-2399/2307.Check for Contradictions in Equations/README_EN.md @@ -84,6 +84,8 @@ Similar problems: +#### Python3 + ```python class Solution: def checkContradictions( @@ -117,6 +119,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { private int[] p; @@ -164,6 +168,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -204,6 +210,8 @@ public: }; ``` +#### Go + ```go func checkContradictions(equations [][]string, values []float64) bool { d := make(map[string]int) @@ -254,6 +262,8 @@ func checkContradictions(equations [][]string, values []float64) bool { } ``` +#### TypeScript + ```ts function checkContradictions(equations: string[][], values: number[]): boolean { const d: { [key: string]: number } = {}; diff --git a/solution/2300-2399/2308.Arrange Table by Gender/README.md b/solution/2300-2399/2308.Arrange Table by Gender/README.md index d682ebf0935d0..91fd14f611ab9 100644 --- a/solution/2300-2399/2308.Arrange Table by Gender/README.md +++ b/solution/2300-2399/2308.Arrange Table by Gender/README.md @@ -89,6 +89,8 @@ Genders 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -121,6 +123,8 @@ ORDER BY rk1, rk2; +#### MySQL + ```sql SELECT user_id, diff --git a/solution/2300-2399/2308.Arrange Table by Gender/README_EN.md b/solution/2300-2399/2308.Arrange Table by Gender/README_EN.md index 172888b9814a5..bdad9cc1243f3 100644 --- a/solution/2300-2399/2308.Arrange Table by Gender/README_EN.md +++ b/solution/2300-2399/2308.Arrange Table by Gender/README_EN.md @@ -90,6 +90,8 @@ Note that the IDs of each gender are sorted in ascending order. +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -122,6 +124,8 @@ ORDER BY rk1, rk2; +#### MySQL + ```sql SELECT user_id, diff --git a/solution/2300-2399/2309.Greatest English Letter in Upper and Lower Case/README.md b/solution/2300-2399/2309.Greatest English Letter in Upper and Lower Case/README.md index 45b21f44a2337..e914400d69bc0 100644 --- a/solution/2300-2399/2309.Greatest English Letter in Upper and Lower Case/README.md +++ b/solution/2300-2399/2309.Greatest English Letter in Upper and Lower Case/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def greatestLetter(self, s: str) -> str: @@ -90,6 +92,8 @@ class Solution: return '' ``` +#### Java + ```java class Solution { public String greatestLetter(String s) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func greatestLetter(s string) string { ss := map[rune]bool{} @@ -137,6 +145,8 @@ func greatestLetter(s string) string { } ``` +#### TypeScript + ```ts function greatestLetter(s: string): string { const ss = new Array(128).fill(false); @@ -152,6 +162,8 @@ function greatestLetter(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn greatest_letter(s: String) -> String { @@ -173,6 +185,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -210,6 +224,8 @@ var greatestLetter = function (s) { +#### Python3 + ```python class Solution: def greatestLetter(self, s: str) -> str: @@ -223,6 +239,8 @@ class Solution: return chr(mask.bit_length() - 1 + ord("A")) if mask else "" ``` +#### Java + ```java class Solution { public String greatestLetter(String s) { @@ -242,6 +260,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -260,6 +280,8 @@ public: }; ``` +#### Go + ```go func greatestLetter(s string) string { mask1, mask2 := 0, 0 diff --git a/solution/2300-2399/2309.Greatest English Letter in Upper and Lower Case/README_EN.md b/solution/2300-2399/2309.Greatest English Letter in Upper and Lower Case/README_EN.md index 9f0053e754d78..1d24250b89915 100644 --- a/solution/2300-2399/2309.Greatest English Letter in Upper and Lower Case/README_EN.md +++ b/solution/2300-2399/2309.Greatest English Letter in Upper and Lower Case/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n)$, and the space complexity is $O(C)$. Here, $n$ and +#### Python3 + ```python class Solution: def greatestLetter(self, s: str) -> str: @@ -87,6 +89,8 @@ class Solution: return '' ``` +#### Java + ```java class Solution { public String greatestLetter(String s) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func greatestLetter(s string) string { ss := map[rune]bool{} @@ -134,6 +142,8 @@ func greatestLetter(s string) string { } ``` +#### TypeScript + ```ts function greatestLetter(s: string): string { const ss = new Array(128).fill(false); @@ -149,6 +159,8 @@ function greatestLetter(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn greatest_letter(s: String) -> String { @@ -170,6 +182,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -207,6 +221,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string $s$. The sp +#### Python3 + ```python class Solution: def greatestLetter(self, s: str) -> str: @@ -220,6 +236,8 @@ class Solution: return chr(mask.bit_length() - 1 + ord("A")) if mask else "" ``` +#### Java + ```java class Solution { public String greatestLetter(String s) { @@ -239,6 +257,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -257,6 +277,8 @@ public: }; ``` +#### Go + ```go func greatestLetter(s string) string { mask1, mask2 := 0, 0 diff --git a/solution/2300-2399/2310.Sum of Numbers With Units Digit K/README.md b/solution/2300-2399/2310.Sum of Numbers With Units Digit K/README.md index 7811e1077b475..de7df0a926a90 100644 --- a/solution/2300-2399/2310.Sum of Numbers With Units Digit K/README.md +++ b/solution/2300-2399/2310.Sum of Numbers With Units Digit K/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def minimumNumbers(self, num: int, k: int) -> int: @@ -101,6 +103,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minimumNumbers(int num, int k) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func minimumNumbers(num int, k int) int { if num == 0 { @@ -147,6 +155,8 @@ func minimumNumbers(num int, k int) int { } ``` +#### TypeScript + ```ts function minimumNumbers(num: number, k: number): number { if (!num) return 0; @@ -169,6 +179,8 @@ function minimumNumbers(num: number, k: number): number { +#### Python3 + ```python class Solution: def minimumNumbers(self, num: int, k: int) -> int: @@ -180,6 +192,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minimumNumbers(int num, int k) { @@ -196,6 +210,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -209,6 +225,8 @@ public: }; ``` +#### Go + ```go func minimumNumbers(num int, k int) int { if num == 0 { @@ -233,6 +251,8 @@ func minimumNumbers(num int, k int) int { +#### Python3 + ```python class Solution: def minimumNumbers(self, num: int, k: int) -> int: diff --git a/solution/2300-2399/2310.Sum of Numbers With Units Digit K/README_EN.md b/solution/2300-2399/2310.Sum of Numbers With Units Digit K/README_EN.md index 0b79dc3c6faaf..7c19e6cc30f97 100644 --- a/solution/2300-2399/2310.Sum of Numbers With Units Digit K/README_EN.md +++ b/solution/2300-2399/2310.Sum of Numbers With Units Digit K/README_EN.md @@ -83,6 +83,8 @@ It can be shown that 2 is the minimum possible size of a valid set. +#### Python3 + ```python class Solution: def minimumNumbers(self, num: int, k: int) -> int: @@ -94,6 +96,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minimumNumbers(int num, int k) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func minimumNumbers(num int, k int) int { if num == 0 { @@ -140,6 +148,8 @@ func minimumNumbers(num int, k int) int { } ``` +#### TypeScript + ```ts function minimumNumbers(num: number, k: number): number { if (!num) return 0; @@ -162,6 +172,8 @@ function minimumNumbers(num: number, k: number): number { +#### Python3 + ```python class Solution: def minimumNumbers(self, num: int, k: int) -> int: @@ -173,6 +185,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minimumNumbers(int num, int k) { @@ -189,6 +203,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -202,6 +218,8 @@ public: }; ``` +#### Go + ```go func minimumNumbers(num int, k int) int { if num == 0 { @@ -226,6 +244,8 @@ func minimumNumbers(num int, k int) int { +#### Python3 + ```python class Solution: def minimumNumbers(self, num: int, k: int) -> int: diff --git a/solution/2300-2399/2311.Longest Binary Subsequence Less Than or Equal to K/README.md b/solution/2300-2399/2311.Longest Binary Subsequence Less Than or Equal to K/README.md index 485ebd7d3e8be..c680901ec6715 100644 --- a/solution/2300-2399/2311.Longest Binary Subsequence Less Than or Equal to K/README.md +++ b/solution/2300-2399/2311.Longest Binary Subsequence Less Than or Equal to K/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def longestSubsequence(self, s: str, k: int) -> int: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestSubsequence(String s, int k) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func longestSubsequence(s string, k int) (ans int) { for i, v := len(s)-1, 0; i >= 0; i-- { @@ -138,6 +146,8 @@ func longestSubsequence(s string, k int) (ans int) { } ``` +#### TypeScript + ```ts function longestSubsequence(s: string, k: number): number { let ans = 0; @@ -153,6 +163,8 @@ function longestSubsequence(s: string, k: number): number { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -173,6 +185,8 @@ var longestSubsequence = function (s, k) { }; ``` +#### C# + ```cs public class Solution { public int LongestSubsequence(string s, int k) { diff --git a/solution/2300-2399/2311.Longest Binary Subsequence Less Than or Equal to K/README_EN.md b/solution/2300-2399/2311.Longest Binary Subsequence Less Than or Equal to K/README_EN.md index 96727f52d6c49..653789687bf26 100644 --- a/solution/2300-2399/2311.Longest Binary Subsequence Less Than or Equal to K/README_EN.md +++ b/solution/2300-2399/2311.Longest Binary Subsequence Less Than or Equal to K/README_EN.md @@ -72,6 +72,8 @@ The length of this subsequence is 6, so 6 is returned. +#### Python3 + ```python class Solution: def longestSubsequence(self, s: str, k: int) -> int: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestSubsequence(String s, int k) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func longestSubsequence(s string, k int) (ans int) { for i, v := len(s)-1, 0; i >= 0; i-- { @@ -134,6 +142,8 @@ func longestSubsequence(s string, k int) (ans int) { } ``` +#### TypeScript + ```ts function longestSubsequence(s: string, k: number): number { let ans = 0; @@ -149,6 +159,8 @@ function longestSubsequence(s: string, k: number): number { } ``` +#### JavaScript + ```js /** * @param {string} s @@ -169,6 +181,8 @@ var longestSubsequence = function (s, k) { }; ``` +#### C# + ```cs public class Solution { public int LongestSubsequence(string s, int k) { diff --git a/solution/2300-2399/2312.Selling Pieces of Wood/README.md b/solution/2300-2399/2312.Selling Pieces of Wood/README.md index 178075afc8341..b596bba0366d8 100644 --- a/solution/2300-2399/2312.Selling Pieces of Wood/README.md +++ b/solution/2300-2399/2312.Selling Pieces of Wood/README.md @@ -101,6 +101,8 @@ tags: +#### Python3 + ```python class Solution: def sellingWood(self, m: int, n: int, prices: List[List[int]]) -> int: @@ -119,6 +121,8 @@ class Solution: return dfs(m, n) ``` +#### Java + ```java class Solution { private int[][] d; @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -179,6 +185,8 @@ public: }; ``` +#### Go + ```go func sellingWood(m int, n int, prices [][]int) int64 { f := make([][]int64, m+1) @@ -212,6 +220,8 @@ func sellingWood(m int, n int, prices [][]int) int64 { } ``` +#### TypeScript + ```ts function sellingWood(m: number, n: number, prices: number[][]): number { const f: number[][] = Array.from({ length: m + 1 }, () => Array(n + 1).fill(-1)); @@ -263,6 +273,8 @@ function sellingWood(m: number, n: number, prices: number[][]): number { +#### Python3 + ```python class Solution: def sellingWood(self, m: int, n: int, prices: List[List[int]]) -> int: @@ -280,6 +292,8 @@ class Solution: return f[m][n] ``` +#### Java + ```java class Solution { public long sellingWood(int m, int n, int[][] prices) { @@ -304,6 +318,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -331,6 +347,8 @@ public: }; ``` +#### Go + ```go func sellingWood(m int, n int, prices [][]int) int64 { d := make([][]int, m+1) @@ -357,6 +375,8 @@ func sellingWood(m int, n int, prices [][]int) int64 { } ``` +#### TypeScript + ```ts function sellingWood(m: number, n: number, prices: number[][]): number { const f: number[][] = Array.from({ length: m + 1 }, () => Array(n + 1).fill(0)); diff --git a/solution/2300-2399/2312.Selling Pieces of Wood/README_EN.md b/solution/2300-2399/2312.Selling Pieces of Wood/README_EN.md index 0c07df71af51e..47274d1fb0409 100644 --- a/solution/2300-2399/2312.Selling Pieces of Wood/README_EN.md +++ b/solution/2300-2399/2312.Selling Pieces of Wood/README_EN.md @@ -88,6 +88,8 @@ The time complexity is $O(m \times n \times (m + n) + p)$, and the space complex +#### Python3 + ```python class Solution: def sellingWood(self, m: int, n: int, prices: List[List[int]]) -> int: @@ -106,6 +108,8 @@ class Solution: return dfs(m, n) ``` +#### Java + ```java class Solution { private int[][] d; @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go func sellingWood(m int, n int, prices [][]int) int64 { f := make([][]int64, m+1) @@ -199,6 +207,8 @@ func sellingWood(m int, n int, prices [][]int) int64 { } ``` +#### TypeScript + ```ts function sellingWood(m: number, n: number, prices: number[][]): number { const f: number[][] = Array.from({ length: m + 1 }, () => Array(n + 1).fill(-1)); @@ -250,6 +260,8 @@ Similar problems: +#### Python3 + ```python class Solution: def sellingWood(self, m: int, n: int, prices: List[List[int]]) -> int: @@ -267,6 +279,8 @@ class Solution: return f[m][n] ``` +#### Java + ```java class Solution { public long sellingWood(int m, int n, int[][] prices) { @@ -291,6 +305,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -318,6 +334,8 @@ public: }; ``` +#### Go + ```go func sellingWood(m int, n int, prices [][]int) int64 { d := make([][]int, m+1) @@ -344,6 +362,8 @@ func sellingWood(m int, n int, prices [][]int) int64 { } ``` +#### TypeScript + ```ts function sellingWood(m: number, n: number, prices: number[][]): number { const f: number[][] = Array.from({ length: m + 1 }, () => Array(n + 1).fill(0)); diff --git a/solution/2300-2399/2313.Minimum Flips in Binary Tree to Get Result/README.md b/solution/2300-2399/2313.Minimum Flips in Binary Tree to Get Result/README.md index df8e3abce5344..991d3770eaca6 100644 --- a/solution/2300-2399/2313.Minimum Flips in Binary Tree to Get Result/README.md +++ b/solution/2300-2399/2313.Minimum Flips in Binary Tree to Get Result/README.md @@ -102,6 +102,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -129,6 +131,8 @@ class Solution: return dfs(root)[int(result)] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -179,6 +183,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -226,6 +232,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -271,6 +279,8 @@ func minimumFlips(root *TreeNode, result bool) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/2300-2399/2313.Minimum Flips in Binary Tree to Get Result/README_EN.md b/solution/2300-2399/2313.Minimum Flips in Binary Tree to Get Result/README_EN.md index c6b21509a82f2..3abe488471b50 100644 --- a/solution/2300-2399/2313.Minimum Flips in Binary Tree to Get Result/README_EN.md +++ b/solution/2300-2399/2313.Minimum Flips in Binary Tree to Get Result/README_EN.md @@ -85,6 +85,8 @@ The root of the tree already evaluates to false, so 0 nodes have to be flipped. +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -112,6 +114,8 @@ class Solution: return dfs(root)[int(result)] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -162,6 +166,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -209,6 +215,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -254,6 +262,8 @@ func minimumFlips(root *TreeNode, result bool) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/2300-2399/2314.The First Day of the Maximum Recorded Degree in Each City/README.md b/solution/2300-2399/2314.The First Day of the Maximum Recorded Degree in Each City/README.md index 6f325ffac9325..46a0c824efcdc 100644 --- a/solution/2300-2399/2314.The First Day of the Maximum Recorded Degree in Each City/README.md +++ b/solution/2300-2399/2314.The First Day of the Maximum Recorded Degree in Each City/README.md @@ -81,6 +81,8 @@ Weather 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2300-2399/2314.The First Day of the Maximum Recorded Degree in Each City/README_EN.md b/solution/2300-2399/2314.The First Day of the Maximum Recorded Degree in Each City/README_EN.md index d6246ec1a42bd..082509da7d255 100644 --- a/solution/2300-2399/2314.The First Day of the Maximum Recorded Degree in Each City/README_EN.md +++ b/solution/2300-2399/2314.The First Day of the Maximum Recorded Degree in Each City/README_EN.md @@ -80,6 +80,8 @@ For city 3, the maximum degree was recorded on 2022-12-07 with -6 degrees. +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2300-2399/2315.Count Asterisks/README.md b/solution/2300-2399/2315.Count Asterisks/README.md index 5a8f7ed251166..209529a6d4bb2 100644 --- a/solution/2300-2399/2315.Count Asterisks/README.md +++ b/solution/2300-2399/2315.Count Asterisks/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def countAsterisks(self, s: str) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countAsterisks(String s) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func countAsterisks(s string) (ans int) { ok := 1 @@ -136,6 +144,8 @@ func countAsterisks(s string) (ans int) { } ``` +#### TypeScript + ```ts function countAsterisks(s: string): number { let ans = 0; @@ -151,6 +161,8 @@ function countAsterisks(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_asterisks(s: String) -> i32 { @@ -168,6 +180,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int CountAsterisks(string s) { @@ -184,6 +198,8 @@ public class Solution { } ``` +#### C + ```c int countAsterisks(char* s) { int ans = 0; diff --git a/solution/2300-2399/2315.Count Asterisks/README_EN.md b/solution/2300-2399/2315.Count Asterisks/README_EN.md index 03faec4fff571..6d183486e43d9 100644 --- a/solution/2300-2399/2315.Count Asterisks/README_EN.md +++ b/solution/2300-2399/2315.Count Asterisks/README_EN.md @@ -69,6 +69,8 @@ There are 2 asterisks considered. Therefore, we return 2. +#### Python3 + ```python class Solution: def countAsterisks(self, s: str) -> int: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countAsterisks(String s) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func countAsterisks(s string) (ans int) { ok := 1 @@ -129,6 +137,8 @@ func countAsterisks(s string) (ans int) { } ``` +#### TypeScript + ```ts function countAsterisks(s: string): number { let ans = 0; @@ -144,6 +154,8 @@ function countAsterisks(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_asterisks(s: String) -> i32 { @@ -161,6 +173,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int CountAsterisks(string s) { @@ -177,6 +191,8 @@ public class Solution { } ``` +#### C + ```c int countAsterisks(char* s) { int ans = 0; diff --git a/solution/2300-2399/2316.Count Unreachable Pairs of Nodes in an Undirected Graph/README.md b/solution/2300-2399/2316.Count Unreachable Pairs of Nodes in an Undirected Graph/README.md index f972efc738621..3a1041a2d40ac 100644 --- a/solution/2300-2399/2316.Count Unreachable Pairs of Nodes in an Undirected Graph/README.md +++ b/solution/2300-2399/2316.Count Unreachable Pairs of Nodes in an Undirected Graph/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def countPairs(self, n: int, edges: List[List[int]]) -> int: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go func countPairs(n int, edges [][]int) (ans int64) { g := make([][]int, n) @@ -200,6 +208,8 @@ func countPairs(n int, edges [][]int) (ans int64) { } ``` +#### TypeScript + ```ts function countPairs(n: number, edges: number[][]): number { const g: number[][] = Array.from({ length: n }, () => []); @@ -229,6 +239,8 @@ function countPairs(n: number, edges: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_pairs(n: i32, edges: Vec>) -> i64 { diff --git a/solution/2300-2399/2316.Count Unreachable Pairs of Nodes in an Undirected Graph/README_EN.md b/solution/2300-2399/2316.Count Unreachable Pairs of Nodes in an Undirected Graph/README_EN.md index c1a32e303e175..e1c9d72bf6d85 100644 --- a/solution/2300-2399/2316.Count Unreachable Pairs of Nodes in an Undirected Graph/README_EN.md +++ b/solution/2300-2399/2316.Count Unreachable Pairs of Nodes in an Undirected Graph/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(n + m)$, and the space complexity is $O(n + m)$. Here, +#### Python3 + ```python class Solution: def countPairs(self, n: int, edges: List[List[int]]) -> int: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func countPairs(n int, edges [][]int) (ans int64) { g := make([][]int, n) @@ -196,6 +204,8 @@ func countPairs(n int, edges [][]int) (ans int64) { } ``` +#### TypeScript + ```ts function countPairs(n: number, edges: number[][]): number { const g: number[][] = Array.from({ length: n }, () => []); @@ -225,6 +235,8 @@ function countPairs(n: number, edges: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_pairs(n: i32, edges: Vec>) -> i64 { diff --git a/solution/2300-2399/2317.Maximum XOR After Operations/README.md b/solution/2300-2399/2317.Maximum XOR After Operations/README.md index 89fae440c56be..96109e454a02e 100644 --- a/solution/2300-2399/2317.Maximum XOR After Operations/README.md +++ b/solution/2300-2399/2317.Maximum XOR After Operations/README.md @@ -70,12 +70,16 @@ tags: +#### Python3 + ```python class Solution: def maximumXOR(self, nums: List[int]) -> int: return reduce(or_, nums) ``` +#### Java + ```java class Solution { public int maximumXOR(int[] nums) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,6 +107,8 @@ public: }; ``` +#### Go + ```go func maximumXOR(nums []int) (ans int) { for _, x := range nums { @@ -110,6 +118,8 @@ func maximumXOR(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function maximumXOR(nums: number[]): number { let ans = 0; diff --git a/solution/2300-2399/2317.Maximum XOR After Operations/README_EN.md b/solution/2300-2399/2317.Maximum XOR After Operations/README_EN.md index 6c483ea7df8de..f9b949b91ea15 100644 --- a/solution/2300-2399/2317.Maximum XOR After Operations/README_EN.md +++ b/solution/2300-2399/2317.Maximum XOR After Operations/README_EN.md @@ -64,12 +64,16 @@ It can be shown that 11 is the maximum possible bitwise XOR. +#### Python3 + ```python class Solution: def maximumXOR(self, nums: List[int]) -> int: return reduce(or_, nums) ``` +#### Java + ```java class Solution { public int maximumXOR(int[] nums) { @@ -82,6 +86,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -95,6 +101,8 @@ public: }; ``` +#### Go + ```go func maximumXOR(nums []int) (ans int) { for _, x := range nums { @@ -104,6 +112,8 @@ func maximumXOR(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function maximumXOR(nums: number[]): number { let ans = 0; diff --git a/solution/2300-2399/2318.Number of Distinct Roll Sequences/README.md b/solution/2300-2399/2318.Number of Distinct Roll Sequences/README.md index 75ae4d24e91e9..24a81b484d2b9 100644 --- a/solution/2300-2399/2318.Number of Distinct Roll Sequences/README.md +++ b/solution/2300-2399/2318.Number of Distinct Roll Sequences/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def distinctSequences(self, n: int) -> int: @@ -100,6 +102,8 @@ class Solution: return ans % mod ``` +#### Java + ```java class Solution { public int distinctSequences(int n) { @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func distinctSequences(n int) int { if n == 1 { diff --git a/solution/2300-2399/2318.Number of Distinct Roll Sequences/README_EN.md b/solution/2300-2399/2318.Number of Distinct Roll Sequences/README_EN.md index 9226623903322..3a2ef2d3bbf53 100644 --- a/solution/2300-2399/2318.Number of Distinct Roll Sequences/README_EN.md +++ b/solution/2300-2399/2318.Number of Distinct Roll Sequences/README_EN.md @@ -69,6 +69,8 @@ There are a total of 22 distinct sequences possible, so we return 22. +#### Python3 + ```python class Solution: def distinctSequences(self, n: int) -> int: @@ -94,6 +96,8 @@ class Solution: return ans % mod ``` +#### Java + ```java class Solution { public int distinctSequences(int n) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func distinctSequences(n int) int { if n == 1 { diff --git a/solution/2300-2399/2319.Check if Matrix Is X-Matrix/README.md b/solution/2300-2399/2319.Check if Matrix Is X-Matrix/README.md index 2194ff967e35b..18ff945b08dfb 100644 --- a/solution/2300-2399/2319.Check if Matrix Is X-Matrix/README.md +++ b/solution/2300-2399/2319.Check if Matrix Is X-Matrix/README.md @@ -72,6 +72,8 @@ X 矩阵应该满足:绿色元素(对角线上)都不是 0 ,红色元素 +#### Python3 + ```python class Solution: def checkXMatrix(self, grid: List[List[int]]) -> bool: @@ -85,6 +87,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean checkXMatrix(int[][] grid) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func checkXMatrix(grid [][]int) bool { for i, row := range grid { @@ -143,6 +151,8 @@ func checkXMatrix(grid [][]int) bool { } ``` +#### TypeScript + ```ts function checkXMatrix(grid: number[][]): boolean { const n = grid.length; @@ -161,6 +171,8 @@ function checkXMatrix(grid: number[][]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn check_x_matrix(grid: Vec>) -> bool { @@ -181,6 +193,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public bool CheckXMatrix(int[][] grid) { @@ -201,6 +215,8 @@ public class Solution { } ``` +#### C + ```c bool checkXMatrix(int** grid, int gridSize, int* gridColSize) { for (int i = 0; i < gridSize; i++) { diff --git a/solution/2300-2399/2319.Check if Matrix Is X-Matrix/README_EN.md b/solution/2300-2399/2319.Check if Matrix Is X-Matrix/README_EN.md index d598c0b8b07f8..b098396ee1bcc 100644 --- a/solution/2300-2399/2319.Check if Matrix Is X-Matrix/README_EN.md +++ b/solution/2300-2399/2319.Check if Matrix Is X-Matrix/README_EN.md @@ -68,6 +68,8 @@ Thus, grid is not an X-Matrix. +#### Python3 + ```python class Solution: def checkXMatrix(self, grid: List[List[int]]) -> bool: @@ -81,6 +83,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean checkXMatrix(int[][] grid) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func checkXMatrix(grid [][]int) bool { for i, row := range grid { @@ -139,6 +147,8 @@ func checkXMatrix(grid [][]int) bool { } ``` +#### TypeScript + ```ts function checkXMatrix(grid: number[][]): boolean { const n = grid.length; @@ -157,6 +167,8 @@ function checkXMatrix(grid: number[][]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn check_x_matrix(grid: Vec>) -> bool { @@ -177,6 +189,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public bool CheckXMatrix(int[][] grid) { @@ -197,6 +211,8 @@ public class Solution { } ``` +#### C + ```c bool checkXMatrix(int** grid, int gridSize, int* gridColSize) { for (int i = 0; i < gridSize; i++) { diff --git a/solution/2300-2399/2320.Count Number of Ways to Place Houses/README.md b/solution/2300-2399/2320.Count Number of Ways to Place Houses/README.md index 9ee8fe958c9e0..343b87fbc0242 100644 --- a/solution/2300-2399/2320.Count Number of Ways to Place Houses/README.md +++ b/solution/2300-2399/2320.Count Number of Ways to Place Houses/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def countHousePlacements(self, n: int) -> int: @@ -89,6 +91,8 @@ class Solution: return v * v % mod ``` +#### Java + ```java class Solution { public int countHousePlacements(int n) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func countHousePlacements(n int) int { const mod = 1e9 + 7 @@ -139,6 +147,8 @@ func countHousePlacements(n int) int { } ``` +#### TypeScript + ```ts function countHousePlacements(n: number): number { const f = new Array(n); @@ -154,6 +164,8 @@ function countHousePlacements(n: number): number { } ``` +#### C# + ```cs public class Solution { public int CountHousePlacements(int n) { diff --git a/solution/2300-2399/2320.Count Number of Ways to Place Houses/README_EN.md b/solution/2300-2399/2320.Count Number of Ways to Place Houses/README_EN.md index 75e44cdc4115a..8406046e8481b 100644 --- a/solution/2300-2399/2320.Count Number of Ways to Place Houses/README_EN.md +++ b/solution/2300-2399/2320.Count Number of Ways to Place Houses/README_EN.md @@ -63,6 +63,8 @@ Possible arrangements: +#### Python3 + ```python class Solution: def countHousePlacements(self, n: int) -> int: @@ -76,6 +78,8 @@ class Solution: return v * v % mod ``` +#### Java + ```java class Solution { public int countHousePlacements(int n) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func countHousePlacements(n int) int { const mod = 1e9 + 7 @@ -126,6 +134,8 @@ func countHousePlacements(n int) int { } ``` +#### TypeScript + ```ts function countHousePlacements(n: number): number { const f = new Array(n); @@ -141,6 +151,8 @@ function countHousePlacements(n: number): number { } ``` +#### C# + ```cs public class Solution { public int CountHousePlacements(int n) { diff --git a/solution/2300-2399/2321.Maximum Score Of Spliced Array/README.md b/solution/2300-2399/2321.Maximum Score Of Spliced Array/README.md index a47d5ffdfa82e..c5cf7c73b088a 100644 --- a/solution/2300-2399/2321.Maximum Score Of Spliced Array/README.md +++ b/solution/2300-2399/2321.Maximum Score Of Spliced Array/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def maximumsSplicedArray(self, nums1: List[int], nums2: List[int]) -> int: @@ -101,6 +103,8 @@ class Solution: return max(s2 + f(nums1, nums2), s1 + f(nums2, nums1)) ``` +#### Java + ```java class Solution { public int maximumsSplicedArray(int[] nums1, int[] nums2) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func maximumsSplicedArray(nums1 []int, nums2 []int) int { s1, s2 := 0, 0 diff --git a/solution/2300-2399/2321.Maximum Score Of Spliced Array/README_EN.md b/solution/2300-2399/2321.Maximum Score Of Spliced Array/README_EN.md index cb8fbaf2946f8..0ae6408dfc9ac 100644 --- a/solution/2300-2399/2321.Maximum Score Of Spliced Array/README_EN.md +++ b/solution/2300-2399/2321.Maximum Score Of Spliced Array/README_EN.md @@ -81,6 +81,8 @@ The score is max(sum(nums1), sum(nums2)) = max(31, 3) = 31. +#### Python3 + ```python class Solution: def maximumsSplicedArray(self, nums1: List[int], nums2: List[int]) -> int: @@ -99,6 +101,8 @@ class Solution: return max(s2 + f(nums1, nums2), s1 + f(nums2, nums1)) ``` +#### Java + ```java class Solution { public int maximumsSplicedArray(int[] nums1, int[] nums2) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func maximumsSplicedArray(nums1 []int, nums2 []int) int { s1, s2 := 0, 0 diff --git a/solution/2300-2399/2322.Minimum Score After Removals on a Tree/README.md b/solution/2300-2399/2322.Minimum Score After Removals on a Tree/README.md index 92a5efbc5efcc..b41b68cd1bac7 100644 --- a/solution/2300-2399/2322.Minimum Score After Removals on a Tree/README.md +++ b/solution/2300-2399/2322.Minimum Score After Removals on a Tree/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python class Solution: def minimumScore(self, nums: List[int], edges: List[List[int]]) -> int: @@ -135,6 +137,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int s; @@ -193,6 +197,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -245,6 +251,8 @@ public: }; ``` +#### Go + ```go func minimumScore(nums []int, edges [][]int) int { n := len(nums) diff --git a/solution/2300-2399/2322.Minimum Score After Removals on a Tree/README_EN.md b/solution/2300-2399/2322.Minimum Score After Removals on a Tree/README_EN.md index c9b6ff93fb2d1..693b479f9db27 100644 --- a/solution/2300-2399/2322.Minimum Score After Removals on a Tree/README_EN.md +++ b/solution/2300-2399/2322.Minimum Score After Removals on a Tree/README_EN.md @@ -89,6 +89,8 @@ We cannot obtain a smaller score than 0. +#### Python3 + ```python class Solution: def minimumScore(self, nums: List[int], edges: List[List[int]]) -> int: @@ -129,6 +131,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int s; @@ -187,6 +191,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -239,6 +245,8 @@ public: }; ``` +#### Go + ```go func minimumScore(nums []int, edges [][]int) int { n := len(nums) diff --git a/solution/2300-2399/2323.Find Minimum Time to Finish All Jobs II/README.md b/solution/2300-2399/2323.Find Minimum Time to Finish All Jobs II/README.md index 90d7747ad1d2e..81a63e74d5406 100644 --- a/solution/2300-2399/2323.Find Minimum Time to Finish All Jobs II/README.md +++ b/solution/2300-2399/2323.Find Minimum Time to Finish All Jobs II/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def minimumTime(self, jobs: List[int], workers: List[int]) -> int: @@ -81,6 +83,8 @@ class Solution: return max((a + b - 1) // b for a, b in zip(jobs, workers)) ``` +#### Java + ```java class Solution { public int minimumTime(int[] jobs, int[] workers) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func minimumTime(jobs []int, workers []int) int { sort.Ints(jobs) diff --git a/solution/2300-2399/2323.Find Minimum Time to Finish All Jobs II/README_EN.md b/solution/2300-2399/2323.Find Minimum Time to Finish All Jobs II/README_EN.md index 742901554dfb3..ffc9b3761674f 100644 --- a/solution/2300-2399/2323.Find Minimum Time to Finish All Jobs II/README_EN.md +++ b/solution/2300-2399/2323.Find Minimum Time to Finish All Jobs II/README_EN.md @@ -71,6 +71,8 @@ It can be proven that 3 days is the minimum number of days needed. +#### Python3 + ```python class Solution: def minimumTime(self, jobs: List[int], workers: List[int]) -> int: @@ -79,6 +81,8 @@ class Solution: return max((a + b - 1) // b for a, b in zip(jobs, workers)) ``` +#### Java + ```java class Solution { public int minimumTime(int[] jobs, int[] workers) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func minimumTime(jobs []int, workers []int) int { sort.Ints(jobs) diff --git a/solution/2300-2399/2324.Product Sales Analysis IV/README.md b/solution/2300-2399/2324.Product Sales Analysis IV/README.md index 157dadf06318b..e0ce6c0c0ccc7 100644 --- a/solution/2300-2399/2324.Product Sales Analysis IV/README.md +++ b/solution/2300-2399/2324.Product Sales Analysis IV/README.md @@ -111,6 +111,8 @@ Product 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2300-2399/2324.Product Sales Analysis IV/README_EN.md b/solution/2300-2399/2324.Product Sales Analysis IV/README_EN.md index d82654fff1ced..0cb4d7d3160c7 100644 --- a/solution/2300-2399/2324.Product Sales Analysis IV/README_EN.md +++ b/solution/2300-2399/2324.Product Sales Analysis IV/README_EN.md @@ -110,6 +110,8 @@ User 102 spent the most money on products 1, 2, and 3. +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2300-2399/2325.Decode the Message/README.md b/solution/2300-2399/2325.Decode the Message/README.md index c12b0e6300c47..eede18e77d7f0 100644 --- a/solution/2300-2399/2325.Decode the Message/README.md +++ b/solution/2300-2399/2325.Decode the Message/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def decodeMessage(self, key: str, message: str) -> str: @@ -96,6 +98,8 @@ class Solution: return "".join(d[c] for c in message) ``` +#### Java + ```java class Solution { public String decodeMessage(String key, String message) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func decodeMessage(key string, message string) string { d := [128]byte{} @@ -154,6 +162,8 @@ func decodeMessage(key string, message string) string { } ``` +#### TypeScript + ```ts function decodeMessage(key: string, message: string): string { const d = new Map(); @@ -168,6 +178,8 @@ function decodeMessage(key: string, message: string): string { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { @@ -188,6 +200,8 @@ impl Solution { } ``` +#### C + ```c char* decodeMessage(char* key, char* message) { int m = strlen(key); diff --git a/solution/2300-2399/2325.Decode the Message/README_EN.md b/solution/2300-2399/2325.Decode the Message/README_EN.md index 8db1d1cf5b1ac..32cd5801f962a 100644 --- a/solution/2300-2399/2325.Decode the Message/README_EN.md +++ b/solution/2300-2399/2325.Decode the Message/README_EN.md @@ -74,6 +74,8 @@ It is obtained by taking the first appearance of each letter in " +#### Python3 + ```python class Solution: def decodeMessage(self, key: str, message: str) -> str: @@ -86,6 +88,8 @@ class Solution: return "".join(d[c] for c in message) ``` +#### Java + ```java class Solution { public String decodeMessage(String key, String message) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func decodeMessage(key string, message string) string { d := [128]byte{} @@ -144,6 +152,8 @@ func decodeMessage(key string, message string) string { } ``` +#### TypeScript + ```ts function decodeMessage(key: string, message: string): string { const d = new Map(); @@ -158,6 +168,8 @@ function decodeMessage(key: string, message: string): string { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { @@ -178,6 +190,8 @@ impl Solution { } ``` +#### C + ```c char* decodeMessage(char* key, char* message) { int m = strlen(key); diff --git a/solution/2300-2399/2326.Spiral Matrix IV/README.md b/solution/2300-2399/2326.Spiral Matrix IV/README.md index df1cc0f541bd6..beb216d8be181 100644 --- a/solution/2300-2399/2326.Spiral Matrix IV/README.md +++ b/solution/2300-2399/2326.Spiral Matrix IV/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -180,6 +186,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -216,6 +224,8 @@ func spiralMatrix(m int, n int, head *ListNode) [][]int { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/2300-2399/2326.Spiral Matrix IV/README_EN.md b/solution/2300-2399/2326.Spiral Matrix IV/README_EN.md index 1c56b5c230205..0bfc63775c8af 100644 --- a/solution/2300-2399/2326.Spiral Matrix IV/README_EN.md +++ b/solution/2300-2399/2326.Spiral Matrix IV/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -180,6 +186,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -216,6 +224,8 @@ func spiralMatrix(m int, n int, head *ListNode) [][]int { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/2300-2399/2327.Number of People Aware of a Secret/README.md b/solution/2300-2399/2327.Number of People Aware of a Secret/README.md index f7b64f3dae643..2ce1e427c180c 100644 --- a/solution/2300-2399/2327.Number of People Aware of a Secret/README.md +++ b/solution/2300-2399/2327.Number of People Aware of a Secret/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def peopleAwareOfSecret(self, n: int, delay: int, forget: int) -> int: @@ -96,6 +98,8 @@ class Solution: return sum(d[: n + 1]) % mod ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; const int mod = 1e9 + 7; @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func peopleAwareOfSecret(n int, delay int, forget int) int { m := (n << 1) + 10 @@ -180,6 +188,8 @@ func peopleAwareOfSecret(n int, delay int, forget int) int { } ``` +#### TypeScript + ```ts function peopleAwareOfSecret(n: number, delay: number, forget: number): number { let dp = new Array(n + 1).fill(0n); diff --git a/solution/2300-2399/2327.Number of People Aware of a Secret/README_EN.md b/solution/2300-2399/2327.Number of People Aware of a Secret/README_EN.md index 1e9b204e67300..0872e1acdb5cc 100644 --- a/solution/2300-2399/2327.Number of People Aware of a Secret/README_EN.md +++ b/solution/2300-2399/2327.Number of People Aware of a Secret/README_EN.md @@ -71,6 +71,8 @@ Day 4: A forgets the secret. B, C, and D share the secret with 3 new people. (6 +#### Python3 + ```python class Solution: def peopleAwareOfSecret(self, n: int, delay: int, forget: int) -> int: @@ -90,6 +92,8 @@ class Solution: return sum(d[: n + 1]) % mod ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; const int mod = 1e9 + 7; @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func peopleAwareOfSecret(n int, delay int, forget int) int { m := (n << 1) + 10 @@ -174,6 +182,8 @@ func peopleAwareOfSecret(n int, delay int, forget int) int { } ``` +#### TypeScript + ```ts function peopleAwareOfSecret(n: number, delay: number, forget: number): number { let dp = new Array(n + 1).fill(0n); diff --git a/solution/2300-2399/2328.Number of Increasing Paths in a Grid/README.md b/solution/2300-2399/2328.Number of Increasing Paths in a Grid/README.md index d420ed64af3eb..61eb1d3093505 100644 --- a/solution/2300-2399/2328.Number of Increasing Paths in a Grid/README.md +++ b/solution/2300-2399/2328.Number of Increasing Paths in a Grid/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python class Solution: def countPaths(self, grid: List[List[int]]) -> int: @@ -112,6 +114,8 @@ class Solution: return sum(dfs(i, j) for i in range(m) for j in range(n)) % mod ``` +#### Java + ```java class Solution { private int[][] f; @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -184,6 +190,8 @@ public: }; ``` +#### Go + ```go func countPaths(grid [][]int) (ans int) { const mod = 1e9 + 7 @@ -216,6 +224,8 @@ func countPaths(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function countPaths(grid: number[][]): number { const mod = 1e9 + 7; diff --git a/solution/2300-2399/2328.Number of Increasing Paths in a Grid/README_EN.md b/solution/2300-2399/2328.Number of Increasing Paths in a Grid/README_EN.md index 6f4eaef48459d..c1c03c4908553 100644 --- a/solution/2300-2399/2328.Number of Increasing Paths in a Grid/README_EN.md +++ b/solution/2300-2399/2328.Number of Increasing Paths in a Grid/README_EN.md @@ -89,6 +89,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def countPaths(self, grid: List[List[int]]) -> int: @@ -106,6 +108,8 @@ class Solution: return sum(dfs(i, j) for i in range(m) for j in range(n)) % mod ``` +#### Java + ```java class Solution { private int[][] f; @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -178,6 +184,8 @@ public: }; ``` +#### Go + ```go func countPaths(grid [][]int) (ans int) { const mod = 1e9 + 7 @@ -210,6 +218,8 @@ func countPaths(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function countPaths(grid: number[][]): number { const mod = 1e9 + 7; diff --git a/solution/2300-2399/2329.Product Sales Analysis V/README.md b/solution/2300-2399/2329.Product Sales Analysis V/README.md index c96c0981b227d..58096d6a31d7a 100644 --- a/solution/2300-2399/2329.Product Sales Analysis V/README.md +++ b/solution/2300-2399/2329.Product Sales Analysis V/README.md @@ -102,6 +102,8 @@ Product 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT user_id, SUM(quantity * price) AS spending diff --git a/solution/2300-2399/2329.Product Sales Analysis V/README_EN.md b/solution/2300-2399/2329.Product Sales Analysis V/README_EN.md index 3ebc19fe771cb..361bcc4dc4316 100644 --- a/solution/2300-2399/2329.Product Sales Analysis V/README_EN.md +++ b/solution/2300-2399/2329.Product Sales Analysis V/README_EN.md @@ -103,6 +103,8 @@ Users 102 and 103 spent the same amount and we break the tie by their ID while u +#### MySQL + ```sql # Write your MySQL query statement below SELECT user_id, SUM(quantity * price) AS spending diff --git a/solution/2300-2399/2330.Valid Palindrome IV/README.md b/solution/2300-2399/2330.Valid Palindrome IV/README.md index ebe410f857de9..0af8b1d403fde 100644 --- a/solution/2300-2399/2330.Valid Palindrome IV/README.md +++ b/solution/2300-2399/2330.Valid Palindrome IV/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def makePalindrome(self, s: str) -> bool: @@ -86,6 +88,8 @@ class Solution: return cnt <= 2 ``` +#### Java + ```java class Solution { public boolean makePalindrome(String s) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func makePalindrome(s string) bool { cnt := 0 @@ -128,6 +136,8 @@ func makePalindrome(s string) bool { } ``` +#### TypeScript + ```ts function makePalindrome(s: string): boolean { let cnt = 0; diff --git a/solution/2300-2399/2330.Valid Palindrome IV/README_EN.md b/solution/2300-2399/2330.Valid Palindrome IV/README_EN.md index 55e4fa59fb66a..1bf906064d8c1 100644 --- a/solution/2300-2399/2330.Valid Palindrome IV/README_EN.md +++ b/solution/2300-2399/2330.Valid Palindrome IV/README_EN.md @@ -69,6 +69,8 @@ Two operations could be performed to make s a palindrome so return true. +#### Python3 + ```python class Solution: def makePalindrome(self, s: str) -> bool: @@ -80,6 +82,8 @@ class Solution: return cnt <= 2 ``` +#### Java + ```java class Solution { public boolean makePalindrome(String s) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func makePalindrome(s string) bool { cnt := 0 @@ -122,6 +130,8 @@ func makePalindrome(s string) bool { } ``` +#### TypeScript + ```ts function makePalindrome(s: string): boolean { let cnt = 0; diff --git a/solution/2300-2399/2331.Evaluate Boolean Binary Tree/README.md b/solution/2300-2399/2331.Evaluate Boolean Binary Tree/README.md index 349d9f1efcaf8..d1c7aa221bbe5 100644 --- a/solution/2300-2399/2331.Evaluate Boolean Binary Tree/README.md +++ b/solution/2300-2399/2331.Evaluate Boolean Binary Tree/README.md @@ -93,6 +93,8 @@ OR 运算节点的值为 True OR False = True 。 +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -111,6 +113,8 @@ class Solution: return dfs(root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -197,6 +205,8 @@ func evaluateTree(root *TreeNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -224,6 +234,8 @@ function evaluateTree(root: TreeNode | null): boolean { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -263,6 +275,8 @@ impl Solution { } ``` +#### C + ```c /** * Definition for a binary tree node. @@ -293,6 +307,8 @@ bool evaluateTree(struct TreeNode* root) { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -309,6 +325,8 @@ class Solution: return l or r if root.val == 2 else l and r ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -337,6 +355,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -362,6 +382,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/2300-2399/2331.Evaluate Boolean Binary Tree/README_EN.md b/solution/2300-2399/2331.Evaluate Boolean Binary Tree/README_EN.md index cee8b69de304d..94a94a6b39fa5 100644 --- a/solution/2300-2399/2331.Evaluate Boolean Binary Tree/README_EN.md +++ b/solution/2300-2399/2331.Evaluate Boolean Binary Tree/README_EN.md @@ -80,6 +80,8 @@ The root node evaluates to True, so we return true. +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -98,6 +100,8 @@ class Solution: return dfs(root) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -184,6 +192,8 @@ func evaluateTree(root *TreeNode) bool { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -211,6 +221,8 @@ function evaluateTree(root: TreeNode | null): boolean { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] @@ -250,6 +262,8 @@ impl Solution { } ``` +#### C + ```c /** * Definition for a binary tree node. @@ -280,6 +294,8 @@ bool evaluateTree(struct TreeNode* root) { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -296,6 +312,8 @@ class Solution: return l or r if root.val == 2 else l and r ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -324,6 +342,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -349,6 +369,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README.md b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README.md index 32bd21c005b66..04d884c429f0a 100644 --- a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README.md +++ b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def latestTimeCatchTheBus( @@ -103,6 +105,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int latestTimeCatchTheBus(int[] buses, int[] passengers, int capacity) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func latestTimeCatchTheBus(buses []int, passengers []int, capacity int) int { sort.Ints(buses) @@ -171,6 +179,8 @@ func latestTimeCatchTheBus(buses []int, passengers []int, capacity int) int { } ``` +#### TypeScript + ```ts function latestTimeCatchTheBus(buses: number[], passengers: number[], capacity: number): number { buses.sort((a, b) => a - b); @@ -193,6 +203,8 @@ function latestTimeCatchTheBus(buses: number[], passengers: number[], capacity: } ``` +#### JavaScript + ```js /** * @param {number[]} buses diff --git a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md index 9098bbda35ad7..1fe3a339e12a8 100644 --- a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md +++ b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md @@ -91,6 +91,8 @@ The time complexity is $O(n \times \log n + m \times \log m)$, and the space com +#### Python3 + ```python class Solution: def latestTimeCatchTheBus( @@ -110,6 +112,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int latestTimeCatchTheBus(int[] buses, int[] passengers, int capacity) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func latestTimeCatchTheBus(buses []int, passengers []int, capacity int) int { sort.Ints(buses) @@ -178,6 +186,8 @@ func latestTimeCatchTheBus(buses []int, passengers []int, capacity int) int { } ``` +#### TypeScript + ```ts function latestTimeCatchTheBus(buses: number[], passengers: number[], capacity: number): number { buses.sort((a, b) => a - b); @@ -200,6 +210,8 @@ function latestTimeCatchTheBus(buses: number[], passengers: number[], capacity: } ``` +#### JavaScript + ```js /** * @param {number[]} buses diff --git a/solution/2300-2399/2333.Minimum Sum of Squared Difference/README.md b/solution/2300-2399/2333.Minimum Sum of Squared Difference/README.md index c3c7b5f996209..0111eaa0fe786 100644 --- a/solution/2300-2399/2333.Minimum Sum of Squared Difference/README.md +++ b/solution/2300-2399/2333.Minimum Sum of Squared Difference/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def minSumSquareDiff( @@ -101,6 +103,8 @@ class Solution: return sum(v * v for v in d) ``` +#### Java + ```java class Solution { public long minSumSquareDiff(int[] nums1, int[] nums2, int k1, int k2) { @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go func minSumSquareDiff(nums1 []int, nums2 []int, k1 int, k2 int) int64 { k := k1 + k2 diff --git a/solution/2300-2399/2333.Minimum Sum of Squared Difference/README_EN.md b/solution/2300-2399/2333.Minimum Sum of Squared Difference/README_EN.md index baeb278104713..274360be1b076 100644 --- a/solution/2300-2399/2333.Minimum Sum of Squared Difference/README_EN.md +++ b/solution/2300-2399/2333.Minimum Sum of Squared Difference/README_EN.md @@ -73,6 +73,8 @@ Note that, there are other ways to obtain the minimum of the sum of square diffe +#### Python3 + ```python class Solution: def minSumSquareDiff( @@ -101,6 +103,8 @@ class Solution: return sum(v * v for v in d) ``` +#### Java + ```java class Solution { public long minSumSquareDiff(int[] nums1, int[] nums2, int k1, int k2) { @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go func minSumSquareDiff(nums1 []int, nums2 []int, k1 int, k2 int) int64 { k := k1 + k2 diff --git a/solution/2300-2399/2334.Subarray With Elements Greater Than Varying Threshold/README.md b/solution/2300-2399/2334.Subarray With Elements Greater Than Varying Threshold/README.md index cbf69871585df..2715c2822e1bf 100644 --- a/solution/2300-2399/2334.Subarray With Elements Greater Than Varying Threshold/README.md +++ b/solution/2300-2399/2334.Subarray With Elements Greater Than Varying Threshold/README.md @@ -83,6 +83,8 @@ $v$ 作为当前连通块的最小值,当前连通块的大小为 $size[find(i +#### Python3 + ```python class Solution: def validSubarraySize(self, nums: List[int], threshold: int) -> int: @@ -114,6 +116,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { private int[] p; @@ -168,6 +172,8 @@ class Solution { } ``` +#### C++ + ```cpp using pii = pair; @@ -209,6 +215,8 @@ public: }; ``` +#### Go + ```go func validSubarraySize(nums []int, threshold int) int { n := len(nums) @@ -277,6 +285,8 @@ func validSubarraySize(nums []int, threshold int) int { +#### Python3 + ```python class Solution: def validSubarraySize(self, nums: List[int], threshold: int) -> int: @@ -304,6 +314,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int validSubarraySize(int[] nums, int threshold) { @@ -346,6 +358,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -377,6 +391,8 @@ public: }; ``` +#### Go + ```go func validSubarraySize(nums []int, threshold int) int { n := len(nums) diff --git a/solution/2300-2399/2334.Subarray With Elements Greater Than Varying Threshold/README_EN.md b/solution/2300-2399/2334.Subarray With Elements Greater Than Varying Threshold/README_EN.md index 14d25be2fe6a9..29e46c20516e3 100644 --- a/solution/2300-2399/2334.Subarray With Elements Greater Than Varying Threshold/README_EN.md +++ b/solution/2300-2399/2334.Subarray With Elements Greater Than Varying Threshold/README_EN.md @@ -67,6 +67,8 @@ Therefore, 2, 3, 4, or 5 may also be returned. +#### Python3 + ```python class Solution: def validSubarraySize(self, nums: List[int], threshold: int) -> int: @@ -98,6 +100,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { private int[] p; @@ -152,6 +156,8 @@ class Solution { } ``` +#### C++ + ```cpp using pii = pair; @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go func validSubarraySize(nums []int, threshold int) int { n := len(nums) @@ -253,6 +261,8 @@ func validSubarraySize(nums []int, threshold int) int { +#### Python3 + ```python class Solution: def validSubarraySize(self, nums: List[int], threshold: int) -> int: @@ -280,6 +290,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int validSubarraySize(int[] nums, int threshold) { @@ -322,6 +334,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -353,6 +367,8 @@ public: }; ``` +#### Go + ```go func validSubarraySize(nums []int, threshold int) int { n := len(nums) diff --git a/solution/2300-2399/2335.Minimum Amount of Time to Fill Cups/README.md b/solution/2300-2399/2335.Minimum Amount of Time to Fill Cups/README.md index e0bc7664eb2bc..97b30ab4a9678 100644 --- a/solution/2300-2399/2335.Minimum Amount of Time to Fill Cups/README.md +++ b/solution/2300-2399/2335.Minimum Amount of Time to Fill Cups/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def fillCups(self, amount: List[int]) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int fillCups(int[] amount) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func fillCups(amount []int) int { ans := 0 @@ -141,6 +149,8 @@ func fillCups(amount []int) int { } ``` +#### TypeScript + ```ts function fillCups(amount: number[]): number { amount.sort((a, b) => a - b); @@ -151,6 +161,8 @@ function fillCups(amount: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn fill_cups(mut amount: Vec) -> i32 { @@ -181,6 +193,8 @@ impl Solution { +#### Python3 + ```python class Solution: def fillCups(self, amount: List[int]) -> int: @@ -190,6 +204,8 @@ class Solution: return (sum(amount) + 1) // 2 ``` +#### Java + ```java class Solution { public int fillCups(int[] amount) { @@ -202,6 +218,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -215,6 +233,8 @@ public: }; ``` +#### Go + ```go func fillCups(amount []int) int { sort.Ints(amount) diff --git a/solution/2300-2399/2335.Minimum Amount of Time to Fill Cups/README_EN.md b/solution/2300-2399/2335.Minimum Amount of Time to Fill Cups/README_EN.md index 2f8e1bde664f0..ad937cf0dd754 100644 --- a/solution/2300-2399/2335.Minimum Amount of Time to Fill Cups/README_EN.md +++ b/solution/2300-2399/2335.Minimum Amount of Time to Fill Cups/README_EN.md @@ -80,6 +80,8 @@ Second 7: Fill up a hot cup. +#### Python3 + ```python class Solution: def fillCups(self, amount: List[int]) -> int: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int fillCups(int[] amount) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func fillCups(amount []int) int { ans := 0 @@ -138,6 +146,8 @@ func fillCups(amount []int) int { } ``` +#### TypeScript + ```ts function fillCups(amount: number[]): number { amount.sort((a, b) => a - b); @@ -148,6 +158,8 @@ function fillCups(amount: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn fill_cups(mut amount: Vec) -> i32 { @@ -171,6 +183,8 @@ impl Solution { +#### Python3 + ```python class Solution: def fillCups(self, amount: List[int]) -> int: @@ -180,6 +194,8 @@ class Solution: return (sum(amount) + 1) // 2 ``` +#### Java + ```java class Solution { public int fillCups(int[] amount) { @@ -192,6 +208,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -205,6 +223,8 @@ public: }; ``` +#### Go + ```go func fillCups(amount []int) int { sort.Ints(amount) diff --git a/solution/2300-2399/2336.Smallest Number in Infinite Set/README.md b/solution/2300-2399/2336.Smallest Number in Infinite Set/README.md index befa8c44be180..f9a584bdf213d 100644 --- a/solution/2300-2399/2336.Smallest Number in Infinite Set/README.md +++ b/solution/2300-2399/2336.Smallest Number in Infinite Set/README.md @@ -87,6 +87,8 @@ smallestInfiniteSet.popSmallest(); // 返回 5 ,并将其从集合中移除。 +#### Python3 + ```python from sortedcontainers import SortedSet @@ -110,6 +112,8 @@ class SmallestInfiniteSet: # obj.addBack(num) ``` +#### Java + ```java class SmallestInfiniteSet { private TreeSet s = new TreeSet<>(); @@ -137,6 +141,8 @@ class SmallestInfiniteSet { */ ``` +#### C++ + ```cpp class SmallestInfiniteSet { public: @@ -168,6 +174,8 @@ private: */ ``` +#### Go + ```go type SmallestInfiniteSet struct { s *treemap.Map @@ -199,6 +207,8 @@ func (this *SmallestInfiniteSet) AddBack(num int) { */ ``` +#### TypeScript + ```ts class SmallestInfiniteSet { private s: TreeSet; @@ -867,6 +877,8 @@ class TreeMultiSet { */ ``` +#### Rust + ```rust use std::collections::BTreeSet; @@ -910,6 +922,8 @@ impl SmallestInfiniteSet { +#### TypeScript + ```ts class SmallestInfiniteSet { private pq: typeof MinPriorityQueue; diff --git a/solution/2300-2399/2336.Smallest Number in Infinite Set/README_EN.md b/solution/2300-2399/2336.Smallest Number in Infinite Set/README_EN.md index c387efbcaf3d9..34fd5ed3e89a4 100644 --- a/solution/2300-2399/2336.Smallest Number in Infinite Set/README_EN.md +++ b/solution/2300-2399/2336.Smallest Number in Infinite Set/README_EN.md @@ -86,6 +86,8 @@ The space complexity is $O(n)$. +#### Python3 + ```python from sortedcontainers import SortedSet @@ -109,6 +111,8 @@ class SmallestInfiniteSet: # obj.addBack(num) ``` +#### Java + ```java class SmallestInfiniteSet { private TreeSet s = new TreeSet<>(); @@ -136,6 +140,8 @@ class SmallestInfiniteSet { */ ``` +#### C++ + ```cpp class SmallestInfiniteSet { public: @@ -167,6 +173,8 @@ private: */ ``` +#### Go + ```go type SmallestInfiniteSet struct { s *treemap.Map @@ -198,6 +206,8 @@ func (this *SmallestInfiniteSet) AddBack(num int) { */ ``` +#### TypeScript + ```ts class SmallestInfiniteSet { private s: TreeSet; @@ -866,6 +876,8 @@ class TreeMultiSet { */ ``` +#### Rust + ```rust use std::collections::BTreeSet; @@ -909,6 +921,8 @@ impl SmallestInfiniteSet { +#### TypeScript + ```ts class SmallestInfiniteSet { private pq: typeof MinPriorityQueue; diff --git a/solution/2300-2399/2337.Move Pieces to Obtain a String/README.md b/solution/2300-2399/2337.Move Pieces to Obtain a String/README.md index 04fa4c990847c..ed1c048691c59 100644 --- a/solution/2300-2399/2337.Move Pieces to Obtain a String/README.md +++ b/solution/2300-2399/2337.Move Pieces to Obtain a String/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def canChange(self, start: str, target: str) -> bool: @@ -110,6 +112,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean canChange(String start, String target) { @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp using pii = pair; @@ -179,6 +185,8 @@ public: }; ``` +#### Go + ```go func canChange(start string, target string) bool { f := func(s string) [][]int { @@ -213,6 +221,8 @@ func canChange(start string, target string) bool { } ``` +#### TypeScript + ```ts function canChange(start: string, target: string): boolean { if ( @@ -257,6 +267,8 @@ function canChange(start: string, target: string): boolean { +#### Python3 + ```python class Solution: def canChange(self, start: str, target: str) -> bool: @@ -278,6 +290,8 @@ class Solution: i, j = i + 1, j + 1 ``` +#### Java + ```java class Solution { public boolean canChange(String start, String target) { @@ -306,6 +320,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -326,6 +342,8 @@ public: }; ``` +#### Go + ```go func canChange(start string, target string) bool { n := len(start) @@ -354,6 +372,8 @@ func canChange(start string, target string) bool { } ``` +#### TypeScript + ```ts function canChange(start: string, target: string): boolean { const n = start.length; diff --git a/solution/2300-2399/2337.Move Pieces to Obtain a String/README_EN.md b/solution/2300-2399/2337.Move Pieces to Obtain a String/README_EN.md index 6feb8c15b61e1..821c23cb61c26 100644 --- a/solution/2300-2399/2337.Move Pieces to Obtain a String/README_EN.md +++ b/solution/2300-2399/2337.Move Pieces to Obtain a String/README_EN.md @@ -76,6 +76,8 @@ After that, no pieces can move anymore, so it is impossible to obtain the string +#### Python3 + ```python class Solution: def canChange(self, start: str, target: str) -> bool: @@ -93,6 +95,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean canChange(String start, String target) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp using pii = pair; @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func canChange(start string, target string) bool { f := func(s string) [][]int { @@ -196,6 +204,8 @@ func canChange(start string, target string) bool { } ``` +#### TypeScript + ```ts function canChange(start: string, target: string): boolean { if ( @@ -240,6 +250,8 @@ function canChange(start: string, target: string): boolean { +#### Python3 + ```python class Solution: def canChange(self, start: str, target: str) -> bool: @@ -261,6 +273,8 @@ class Solution: i, j = i + 1, j + 1 ``` +#### Java + ```java class Solution { public boolean canChange(String start, String target) { @@ -289,6 +303,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -309,6 +325,8 @@ public: }; ``` +#### Go + ```go func canChange(start string, target string) bool { n := len(start) @@ -337,6 +355,8 @@ func canChange(start string, target string) bool { } ``` +#### TypeScript + ```ts function canChange(start: string, target: string): boolean { const n = start.length; diff --git a/solution/2300-2399/2338.Count the Number of Ideal Arrays/README.md b/solution/2300-2399/2338.Count the Number of Ideal Arrays/README.md index c517425cf171d..c1275bf4e2c24 100644 --- a/solution/2300-2399/2338.Count the Number of Ideal Arrays/README.md +++ b/solution/2300-2399/2338.Count the Number of Ideal Arrays/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def idealArrays(self, n: int, maxValue: int) -> int: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[][] f; @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func idealArrays(n int, maxValue int) int { mod := int(1e9) + 7 @@ -245,6 +253,8 @@ func idealArrays(n int, maxValue int) int { +#### Python3 + ```python class Solution: def idealArrays(self, n: int, maxValue: int) -> int: @@ -269,6 +279,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -303,6 +315,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -332,6 +346,8 @@ public: }; ``` +#### Go + ```go func idealArrays(n int, maxValue int) int { mod := int(1e9) + 7 diff --git a/solution/2300-2399/2338.Count the Number of Ideal Arrays/README_EN.md b/solution/2300-2399/2338.Count the Number of Ideal Arrays/README_EN.md index a2c0f92814bd9..61eb5b4d8b0ba 100644 --- a/solution/2300-2399/2338.Count the Number of Ideal Arrays/README_EN.md +++ b/solution/2300-2399/2338.Count the Number of Ideal Arrays/README_EN.md @@ -80,6 +80,8 @@ There are a total of 9 + 1 + 1 = 11 distinct ideal arrays. +#### Python3 + ```python class Solution: def idealArrays(self, n: int, maxValue: int) -> int: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[][] f; @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func idealArrays(n int, maxValue int) int { mod := int(1e9) + 7 @@ -237,6 +245,8 @@ func idealArrays(n int, maxValue int) int { +#### Python3 + ```python class Solution: def idealArrays(self, n: int, maxValue: int) -> int: @@ -261,6 +271,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -295,6 +307,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -324,6 +338,8 @@ public: }; ``` +#### Go + ```go func idealArrays(n int, maxValue int) int { mod := int(1e9) + 7 diff --git a/solution/2300-2399/2339.All the Matches of the League/README.md b/solution/2300-2399/2339.All the Matches of the League/README.md index 10bd6a547fa37..150fca1bde30f 100644 --- a/solution/2300-2399/2339.All the Matches of the League/README.md +++ b/solution/2300-2399/2339.All the Matches of the League/README.md @@ -72,6 +72,8 @@ Teams 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT t1.team_name AS home_team, t2.team_name AS away_team diff --git a/solution/2300-2399/2339.All the Matches of the League/README_EN.md b/solution/2300-2399/2339.All the Matches of the League/README_EN.md index e3f9842194e60..54d0391ba2ae0 100644 --- a/solution/2300-2399/2339.All the Matches of the League/README_EN.md +++ b/solution/2300-2399/2339.All the Matches of the League/README_EN.md @@ -73,6 +73,8 @@ Teams table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT t1.team_name AS home_team, t2.team_name AS away_team diff --git a/solution/2300-2399/2340.Minimum Adjacent Swaps to Make a Valid Array/README.md b/solution/2300-2399/2340.Minimum Adjacent Swaps to Make a Valid Array/README.md index 8c7094a02f383..dcf7e9f0d5e7d 100644 --- a/solution/2300-2399/2340.Minimum Adjacent Swaps to Make a Valid Array/README.md +++ b/solution/2300-2399/2340.Minimum Adjacent Swaps to Make a Valid Array/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def minimumSwaps(self, nums: List[int]) -> int: @@ -95,6 +97,8 @@ class Solution: return 0 if i == j else i + len(nums) - 1 - j - (i > j) ``` +#### Java + ```java class Solution { public int minimumSwaps(int[] nums) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func minimumSwaps(nums []int) int { var i, j int @@ -159,6 +167,8 @@ func minimumSwaps(nums []int) int { } ``` +#### TypeScript + ```ts function minimumSwaps(nums: number[]): number { let i = 0; diff --git a/solution/2300-2399/2340.Minimum Adjacent Swaps to Make a Valid Array/README_EN.md b/solution/2300-2399/2340.Minimum Adjacent Swaps to Make a Valid Array/README_EN.md index 3993faa49dc09..2e358b52eee24 100644 --- a/solution/2300-2399/2340.Minimum Adjacent Swaps to Make a Valid Array/README_EN.md +++ b/solution/2300-2399/2340.Minimum Adjacent Swaps to Make a Valid Array/README_EN.md @@ -72,6 +72,8 @@ It can be shown that 6 swaps is the minimum swaps required to make a valid array +#### Python3 + ```python class Solution: def minimumSwaps(self, nums: List[int]) -> int: @@ -84,6 +86,8 @@ class Solution: return 0 if i == j else i + len(nums) - 1 - j - (i > j) ``` +#### Java + ```java class Solution { public int minimumSwaps(int[] nums) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func minimumSwaps(nums []int) int { var i, j int @@ -148,6 +156,8 @@ func minimumSwaps(nums []int) int { } ``` +#### TypeScript + ```ts function minimumSwaps(nums: number[]): number { let i = 0; diff --git a/solution/2300-2399/2341.Maximum Number of Pairs in Array/README.md b/solution/2300-2399/2341.Maximum Number of Pairs in Array/README.md index f75a262488448..2cd351206bf00 100644 --- a/solution/2300-2399/2341.Maximum Number of Pairs in Array/README.md +++ b/solution/2300-2399/2341.Maximum Number of Pairs in Array/README.md @@ -86,6 +86,8 @@ nums[0] 和 nums[1] 形成一个数对,并从 nums 中移除,nums = [2] 。 +#### Python3 + ```python class Solution: def numberOfPairs(self, nums: List[int]) -> List[int]: @@ -94,6 +96,8 @@ class Solution: return [s, len(nums) - s * 2] ``` +#### Java + ```java class Solution { public int[] numberOfPairs(int[] nums) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func numberOfPairs(nums []int) []int { cnt := [101]int{} @@ -141,6 +149,8 @@ func numberOfPairs(nums []int) []int { } ``` +#### TypeScript + ```ts function numberOfPairs(nums: number[]): number[] { const n = nums.length; @@ -153,6 +163,8 @@ function numberOfPairs(nums: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn number_of_pairs(nums: Vec) -> Vec { @@ -170,6 +182,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -185,6 +199,8 @@ var numberOfPairs = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int[] NumberOfPairs(int[] nums) { @@ -201,6 +217,8 @@ public class Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). diff --git a/solution/2300-2399/2341.Maximum Number of Pairs in Array/README_EN.md b/solution/2300-2399/2341.Maximum Number of Pairs in Array/README_EN.md index 2bbea834736a0..73ad1a25d51af 100644 --- a/solution/2300-2399/2341.Maximum Number of Pairs in Array/README_EN.md +++ b/solution/2300-2399/2341.Maximum Number of Pairs in Array/README_EN.md @@ -79,6 +79,8 @@ No more pairs can be formed. A total of 1 pair has been formed, and there are 0 +#### Python3 + ```python class Solution: def numberOfPairs(self, nums: List[int]) -> List[int]: @@ -87,6 +89,8 @@ class Solution: return [s, len(nums) - s * 2] ``` +#### Java + ```java class Solution { public int[] numberOfPairs(int[] nums) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func numberOfPairs(nums []int) []int { cnt := [101]int{} @@ -134,6 +142,8 @@ func numberOfPairs(nums []int) []int { } ``` +#### TypeScript + ```ts function numberOfPairs(nums: number[]): number[] { const n = nums.length; @@ -146,6 +156,8 @@ function numberOfPairs(nums: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn number_of_pairs(nums: Vec) -> Vec { @@ -163,6 +175,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {number[]} nums @@ -178,6 +192,8 @@ var numberOfPairs = function (nums) { }; ``` +#### C# + ```cs public class Solution { public int[] NumberOfPairs(int[] nums) { @@ -194,6 +210,8 @@ public class Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). diff --git a/solution/2300-2399/2342.Max Sum of a Pair With Equal Sum of Digits/README.md b/solution/2300-2399/2342.Max Sum of a Pair With Equal Sum of Digits/README.md index 2eb3521e81f0e..f84ee9d0130f1 100644 --- a/solution/2300-2399/2342.Max Sum of a Pair With Equal Sum of Digits/README.md +++ b/solution/2300-2399/2342.Max Sum of a Pair With Equal Sum of Digits/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def maximumSum(self, nums: List[int]) -> int: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumSum(int[] nums) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func maximumSum(nums []int) int { d := [100]int{} @@ -149,6 +157,8 @@ func maximumSum(nums []int) int { } ``` +#### TypeScript + ```ts function maximumSum(nums: number[]): number { const d: number[] = Array(100).fill(0); @@ -167,6 +177,8 @@ function maximumSum(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn maximum_sum(nums: Vec) -> i32 { diff --git a/solution/2300-2399/2342.Max Sum of a Pair With Equal Sum of Digits/README_EN.md b/solution/2300-2399/2342.Max Sum of a Pair With Equal Sum of Digits/README_EN.md index 1648241aef585..307a3d6bb8fb8 100644 --- a/solution/2300-2399/2342.Max Sum of a Pair With Equal Sum of Digits/README_EN.md +++ b/solution/2300-2399/2342.Max Sum of a Pair With Equal Sum of Digits/README_EN.md @@ -73,6 +73,8 @@ The time complexity is $O(n \times \log M)$, and the space complexity is $O(D)$. +#### Python3 + ```python class Solution: def maximumSum(self, nums: List[int]) -> int: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumSum(int[] nums) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func maximumSum(nums []int) int { d := [100]int{} @@ -148,6 +156,8 @@ func maximumSum(nums []int) int { } ``` +#### TypeScript + ```ts function maximumSum(nums: number[]): number { const d: number[] = Array(100).fill(0); @@ -166,6 +176,8 @@ function maximumSum(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn maximum_sum(nums: Vec) -> i32 { diff --git a/solution/2300-2399/2343.Query Kth Smallest Trimmed Number/README.md b/solution/2300-2399/2343.Query Kth Smallest Trimmed Number/README.md index 1ee2baba3189c..22c53442ab950 100644 --- a/solution/2300-2399/2343.Query Kth Smallest Trimmed Number/README.md +++ b/solution/2300-2399/2343.Query Kth Smallest Trimmed Number/README.md @@ -102,6 +102,8 @@ tags: +#### Python3 + ```python class Solution: def smallestTrimmedNumbers( @@ -114,6 +116,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] smallestTrimmedNumbers(String[] nums, int[][] queries) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func smallestTrimmedNumbers(nums []string, queries [][]int) []int { type pair struct { diff --git a/solution/2300-2399/2343.Query Kth Smallest Trimmed Number/README_EN.md b/solution/2300-2399/2343.Query Kth Smallest Trimmed Number/README_EN.md index 89d18be1c223c..303323a701a66 100644 --- a/solution/2300-2399/2343.Query Kth Smallest Trimmed Number/README_EN.md +++ b/solution/2300-2399/2343.Query Kth Smallest Trimmed Number/README_EN.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python class Solution: def smallestTrimmedNumbers( @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] smallestTrimmedNumbers(String[] nums, int[][] queries) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func smallestTrimmedNumbers(nums []string, queries [][]int) []int { type pair struct { diff --git a/solution/2300-2399/2344.Minimum Deletions to Make Array Divisible/README.md b/solution/2300-2399/2344.Minimum Deletions to Make Array Divisible/README.md index 7403313411ea8..e889199fac935 100644 --- a/solution/2300-2399/2344.Minimum Deletions to Make Array Divisible/README.md +++ b/solution/2300-2399/2344.Minimum Deletions to Make Array Divisible/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int], numsDivide: List[int]) -> int: @@ -91,6 +93,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minOperations(int[] nums, int[] numsDivide) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int, numsDivide []int) int { x := 0 @@ -165,6 +173,8 @@ func gcd(a, b int) int { +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int], numsDivide: List[int]) -> int: @@ -173,6 +183,8 @@ class Solution: return next((i for i, v in enumerate(nums) if x % v == 0), -1) ``` +#### Java + ```java class Solution { public int minOperations(int[] nums, int[] numsDivide) { @@ -204,6 +216,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -230,6 +244,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int, numsDivide []int) int { x := 0 @@ -272,6 +288,8 @@ func gcd(a, b int) int { +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int], numsDivide: List[int]) -> int: diff --git a/solution/2300-2399/2344.Minimum Deletions to Make Array Divisible/README_EN.md b/solution/2300-2399/2344.Minimum Deletions to Make Array Divisible/README_EN.md index 71cbaa9653d91..41204155ac738 100644 --- a/solution/2300-2399/2344.Minimum Deletions to Make Array Divisible/README_EN.md +++ b/solution/2300-2399/2344.Minimum Deletions to Make Array Divisible/README_EN.md @@ -68,6 +68,8 @@ There is no way to delete elements from nums to allow this. +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int], numsDivide: List[int]) -> int: @@ -81,6 +83,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minOperations(int[] nums, int[] numsDivide) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int, numsDivide []int) int { x := 0 @@ -155,6 +163,8 @@ func gcd(a, b int) int { +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int], numsDivide: List[int]) -> int: @@ -163,6 +173,8 @@ class Solution: return next((i for i, v in enumerate(nums) if x % v == 0), -1) ``` +#### Java + ```java class Solution { public int minOperations(int[] nums, int[] numsDivide) { @@ -194,6 +206,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -220,6 +234,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int, numsDivide []int) int { x := 0 @@ -262,6 +278,8 @@ func gcd(a, b int) int { +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int], numsDivide: List[int]) -> int: diff --git a/solution/2300-2399/2345.Finding the Number of Visible Mountains/README.md b/solution/2300-2399/2345.Finding the Number of Visible Mountains/README.md index b09a9e8cad3d2..d684e9f107ef9 100644 --- a/solution/2300-2399/2345.Finding the Number of Visible Mountains/README.md +++ b/solution/2300-2399/2345.Finding the Number of Visible Mountains/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def visibleMountains(self, peaks: List[List[int]]) -> int: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int visibleMountains(int[][] peaks) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func visibleMountains(peaks [][]int) (ans int) { n := len(peaks) @@ -180,6 +188,8 @@ func visibleMountains(peaks [][]int) (ans int) { +#### Java + ```java class Solution { public int visibleMountains(int[][] peaks) { diff --git a/solution/2300-2399/2345.Finding the Number of Visible Mountains/README_EN.md b/solution/2300-2399/2345.Finding the Number of Visible Mountains/README_EN.md index ac7774e659e95..f888cd86deeb0 100644 --- a/solution/2300-2399/2345.Finding the Number of Visible Mountains/README_EN.md +++ b/solution/2300-2399/2345.Finding the Number of Visible Mountains/README_EN.md @@ -65,6 +65,8 @@ Both mountains are not visible since their peaks lie within each other. +#### Python3 + ```python class Solution: def visibleMountains(self, peaks: List[List[int]]) -> int: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int visibleMountains(int[][] peaks) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func visibleMountains(peaks [][]int) (ans int) { n := len(peaks) @@ -170,6 +178,8 @@ func visibleMountains(peaks [][]int) (ans int) { +#### Java + ```java class Solution { public int visibleMountains(int[][] peaks) { diff --git a/solution/2300-2399/2346.Compute the Rank as a Percentage/README.md b/solution/2300-2399/2346.Compute the Rank as a Percentage/README.md index 9255926fc791b..20e1581d654b2 100644 --- a/solution/2300-2399/2346.Compute the Rank as a Percentage/README.md +++ b/solution/2300-2399/2346.Compute the Rank as a Percentage/README.md @@ -90,6 +90,8 @@ Students 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2300-2399/2346.Compute the Rank as a Percentage/README_EN.md b/solution/2300-2399/2346.Compute the Rank as a Percentage/README_EN.md index 4aafa093d3c95..95817183c6255 100644 --- a/solution/2300-2399/2346.Compute the Rank as a Percentage/README_EN.md +++ b/solution/2300-2399/2346.Compute the Rank as a Percentage/README_EN.md @@ -83,6 +83,8 @@ For Department 2: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2300-2399/2347.Best Poker Hand/README.md b/solution/2300-2399/2347.Best Poker Hand/README.md index 7b4fc6fcce116..3adcdd0d65d7c 100644 --- a/solution/2300-2399/2347.Best Poker Hand/README.md +++ b/solution/2300-2399/2347.Best Poker Hand/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def bestHand(self, ranks: List[int], suits: List[str]) -> str: @@ -105,6 +107,8 @@ class Solution: return 'High Card' ``` +#### Java + ```java class Solution { public String bestHand(int[] ranks, char[] suits) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func bestHand(ranks []int, suits []byte) string { flush := true @@ -177,6 +185,8 @@ func bestHand(ranks []int, suits []byte) string { } ``` +#### TypeScript + ```ts function bestHand(ranks: number[], suits: string[]): string { if (suits.every(v => v === suits[0])) { @@ -197,6 +207,8 @@ function bestHand(ranks: number[], suits: string[]): string { } ``` +#### Rust + ```rust impl Solution { pub fn best_hand(ranks: Vec, suits: Vec) -> String { @@ -218,6 +230,8 @@ impl Solution { } ``` +#### C + ```c char* bestHand(int* ranks, int ranksSize, char* suits, int suitsSize) { bool isFlush = true; diff --git a/solution/2300-2399/2347.Best Poker Hand/README_EN.md b/solution/2300-2399/2347.Best Poker Hand/README_EN.md index 3a567f2f04d82..5c35ef13e94a8 100644 --- a/solution/2300-2399/2347.Best Poker Hand/README_EN.md +++ b/solution/2300-2399/2347.Best Poker Hand/README_EN.md @@ -82,6 +82,8 @@ Note that we cannot make a "Flush" or a "Three of a Kind". +#### Python3 + ```python class Solution: def bestHand(self, ranks: List[int], suits: List[str]) -> str: @@ -96,6 +98,8 @@ class Solution: return 'High Card' ``` +#### Java + ```java class Solution { public String bestHand(int[] ranks, char[] suits) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func bestHand(ranks []int, suits []byte) string { flush := true @@ -168,6 +176,8 @@ func bestHand(ranks []int, suits []byte) string { } ``` +#### TypeScript + ```ts function bestHand(ranks: number[], suits: string[]): string { if (suits.every(v => v === suits[0])) { @@ -188,6 +198,8 @@ function bestHand(ranks: number[], suits: string[]): string { } ``` +#### Rust + ```rust impl Solution { pub fn best_hand(ranks: Vec, suits: Vec) -> String { @@ -209,6 +221,8 @@ impl Solution { } ``` +#### C + ```c char* bestHand(int* ranks, int ranksSize, char* suits, int suitsSize) { bool isFlush = true; diff --git a/solution/2300-2399/2348.Number of Zero-Filled Subarrays/README.md b/solution/2300-2399/2348.Number of Zero-Filled Subarrays/README.md index 0a2db519d3b2e..c08d483e02ed0 100644 --- a/solution/2300-2399/2348.Number of Zero-Filled Subarrays/README.md +++ b/solution/2300-2399/2348.Number of Zero-Filled Subarrays/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def zeroFilledSubarray(self, nums: List[int]) -> int: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long zeroFilledSubarray(int[] nums) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func zeroFilledSubarray(nums []int) (ans int64) { cnt := 0 @@ -136,6 +144,8 @@ func zeroFilledSubarray(nums []int) (ans int64) { } ``` +#### TypeScript + ```ts function zeroFilledSubarray(nums: number[]): number { let ans = 0; diff --git a/solution/2300-2399/2348.Number of Zero-Filled Subarrays/README_EN.md b/solution/2300-2399/2348.Number of Zero-Filled Subarrays/README_EN.md index 340f3804dbecb..126a680583ed6 100644 --- a/solution/2300-2399/2348.Number of Zero-Filled Subarrays/README_EN.md +++ b/solution/2300-2399/2348.Number of Zero-Filled Subarrays/README_EN.md @@ -72,6 +72,8 @@ There is no occurrence of a subarray with a size more than 3 filled with 0. Ther +#### Python3 + ```python class Solution: def zeroFilledSubarray(self, nums: List[int]) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long zeroFilledSubarray(int[] nums) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func zeroFilledSubarray(nums []int) (ans int64) { cnt := 0 @@ -126,6 +134,8 @@ func zeroFilledSubarray(nums []int) (ans int64) { } ``` +#### TypeScript + ```ts function zeroFilledSubarray(nums: number[]): number { let ans = 0; diff --git a/solution/2300-2399/2349.Design a Number Container System/README.md b/solution/2300-2399/2349.Design a Number Container System/README.md index 288b915b6b1f9..75e89b38e3e0a 100644 --- a/solution/2300-2399/2349.Design a Number Container System/README.md +++ b/solution/2300-2399/2349.Design a Number Container System/README.md @@ -78,6 +78,8 @@ nc.find(10); // 数字 10 所在下标为 2 ,3 和 5 。最小下标为 2 , +#### Python3 + ```python from sortedcontainers import SortedSet @@ -105,6 +107,8 @@ class NumberContainers: # param_2 = obj.find(number) ``` +#### Java + ```java class NumberContainers { private Map mp = new HashMap<>(); @@ -138,6 +142,8 @@ class NumberContainers { */ ``` +#### C++ + ```cpp class NumberContainers { public: @@ -171,6 +177,8 @@ public: */ ``` +#### Go + ```go type NumberContainers struct { mp map[int]int diff --git a/solution/2300-2399/2349.Design a Number Container System/README_EN.md b/solution/2300-2399/2349.Design a Number Container System/README_EN.md index 6373b6f6a5b74..2b5447bae3f35 100644 --- a/solution/2300-2399/2349.Design a Number Container System/README_EN.md +++ b/solution/2300-2399/2349.Design a Number Container System/README_EN.md @@ -76,6 +76,8 @@ nc.find(10); // Number 10 is at the indices 2, 3, and 5. The smallest index that +#### Python3 + ```python from sortedcontainers import SortedSet @@ -103,6 +105,8 @@ class NumberContainers: # param_2 = obj.find(number) ``` +#### Java + ```java class NumberContainers { private Map mp = new HashMap<>(); @@ -136,6 +140,8 @@ class NumberContainers { */ ``` +#### C++ + ```cpp class NumberContainers { public: @@ -169,6 +175,8 @@ public: */ ``` +#### Go + ```go type NumberContainers struct { mp map[int]int diff --git a/solution/2300-2399/2350.Shortest Impossible Sequence of Rolls/README.md b/solution/2300-2399/2350.Shortest Impossible Sequence of Rolls/README.md index e521cf0548b17..ab78d87b00f31 100644 --- a/solution/2300-2399/2350.Shortest Impossible Sequence of Rolls/README.md +++ b/solution/2300-2399/2350.Shortest Impossible Sequence of Rolls/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def shortestSequence(self, rolls: List[int], k: int) -> int: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int shortestSequence(int[] rolls, int k) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func shortestSequence(rolls []int, k int) int { s := map[int]bool{} diff --git a/solution/2300-2399/2350.Shortest Impossible Sequence of Rolls/README_EN.md b/solution/2300-2399/2350.Shortest Impossible Sequence of Rolls/README_EN.md index 7eeb0021ace22..91d83710ac4ed 100644 --- a/solution/2300-2399/2350.Shortest Impossible Sequence of Rolls/README_EN.md +++ b/solution/2300-2399/2350.Shortest Impossible Sequence of Rolls/README_EN.md @@ -77,6 +77,8 @@ Note that there are other sequences that cannot be taken from rolls but [4] is t +#### Python3 + ```python class Solution: def shortestSequence(self, rolls: List[int], k: int) -> int: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int shortestSequence(int[] rolls, int k) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func shortestSequence(rolls []int, k int) int { s := map[int]bool{} diff --git a/solution/2300-2399/2351.First Letter to Appear Twice/README.md b/solution/2300-2399/2351.First Letter to Appear Twice/README.md index 41cc590753a4d..ba571df7a86a0 100644 --- a/solution/2300-2399/2351.First Letter to Appear Twice/README.md +++ b/solution/2300-2399/2351.First Letter to Appear Twice/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def repeatedCharacter(self, s: str) -> str: @@ -86,6 +88,8 @@ class Solution: return c ``` +#### Java + ```java class Solution { public char repeatedCharacter(String s) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func repeatedCharacter(s string) byte { cnt := [26]int{} @@ -126,6 +134,8 @@ func repeatedCharacter(s string) byte { } ``` +#### TypeScript + ```ts function repeatedCharacter(s: string): string { const vis = new Array(26).fill(false); @@ -140,6 +150,8 @@ function repeatedCharacter(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn repeated_character(s: String) -> char { @@ -155,6 +167,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** @@ -172,6 +186,8 @@ class Solution { } ``` +#### C + ```c char repeatedCharacter(char* s) { int vis[26] = {0}; @@ -199,6 +215,8 @@ char repeatedCharacter(char* s) { +#### Python3 + ```python class Solution: def repeatedCharacter(self, s: str) -> str: @@ -210,6 +228,8 @@ class Solution: mask |= 1 << i ``` +#### Java + ```java class Solution { public char repeatedCharacter(String s) { @@ -225,6 +245,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -240,6 +262,8 @@ public: }; ``` +#### Go + ```go func repeatedCharacter(s string) byte { mask := 0 @@ -252,6 +276,8 @@ func repeatedCharacter(s string) byte { } ``` +#### TypeScript + ```ts function repeatedCharacter(s: string): string { let mask = 0; @@ -266,6 +292,8 @@ function repeatedCharacter(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn repeated_character(s: String) -> char { @@ -281,6 +309,8 @@ impl Solution { } ``` +#### C + ```c char repeatedCharacter(char* s) { int mask = 0; diff --git a/solution/2300-2399/2351.First Letter to Appear Twice/README_EN.md b/solution/2300-2399/2351.First Letter to Appear Twice/README_EN.md index d022b8402daac..eb9c3fed9df79 100644 --- a/solution/2300-2399/2351.First Letter to Appear Twice/README_EN.md +++ b/solution/2300-2399/2351.First Letter to Appear Twice/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(n)$ and the space complexity is $O(C)$. Here, $n$ is t +#### Python3 + ```python class Solution: def repeatedCharacter(self, s: str) -> str: @@ -86,6 +88,8 @@ class Solution: return c ``` +#### Java + ```java class Solution { public char repeatedCharacter(String s) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func repeatedCharacter(s string) byte { cnt := [26]int{} @@ -126,6 +134,8 @@ func repeatedCharacter(s string) byte { } ``` +#### TypeScript + ```ts function repeatedCharacter(s: string): string { const vis = new Array(26).fill(false); @@ -140,6 +150,8 @@ function repeatedCharacter(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn repeated_character(s: String) -> char { @@ -155,6 +167,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** @@ -172,6 +186,8 @@ class Solution { } ``` +#### C + ```c char repeatedCharacter(char* s) { int vis[26] = {0}; @@ -199,6 +215,8 @@ The time complexity is $O(n)$ and the space complexity is $O(1)$. Here, $n$ is t +#### Python3 + ```python class Solution: def repeatedCharacter(self, s: str) -> str: @@ -210,6 +228,8 @@ class Solution: mask |= 1 << i ``` +#### Java + ```java class Solution { public char repeatedCharacter(String s) { @@ -225,6 +245,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -240,6 +262,8 @@ public: }; ``` +#### Go + ```go func repeatedCharacter(s string) byte { mask := 0 @@ -252,6 +276,8 @@ func repeatedCharacter(s string) byte { } ``` +#### TypeScript + ```ts function repeatedCharacter(s: string): string { let mask = 0; @@ -266,6 +292,8 @@ function repeatedCharacter(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn repeated_character(s: String) -> char { @@ -281,6 +309,8 @@ impl Solution { } ``` +#### C + ```c char repeatedCharacter(char* s) { int mask = 0; diff --git a/solution/2300-2399/2352.Equal Row and Column Pairs/README.md b/solution/2300-2399/2352.Equal Row and Column Pairs/README.md index 47c72385275d6..2978741440efa 100644 --- a/solution/2300-2399/2352.Equal Row and Column Pairs/README.md +++ b/solution/2300-2399/2352.Equal Row and Column Pairs/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def equalPairs(self, grid: List[List[int]]) -> int: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int equalPairs(int[][] grid) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func equalPairs(grid [][]int) (ans int) { for i := range grid { @@ -149,6 +157,8 @@ func equalPairs(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function equalPairs(grid: number[][]): number { const n = grid.length; diff --git a/solution/2300-2399/2352.Equal Row and Column Pairs/README_EN.md b/solution/2300-2399/2352.Equal Row and Column Pairs/README_EN.md index 52fefc3c8305f..526b633e49d28 100644 --- a/solution/2300-2399/2352.Equal Row and Column Pairs/README_EN.md +++ b/solution/2300-2399/2352.Equal Row and Column Pairs/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n^3)$, where $n$ is the number of rows or columns in t +#### Python3 + ```python class Solution: def equalPairs(self, grid: List[List[int]]) -> int: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int equalPairs(int[][] grid) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func equalPairs(grid [][]int) (ans int) { for i := range grid { @@ -143,6 +151,8 @@ func equalPairs(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function equalPairs(grid: number[][]): number { const n = grid.length; diff --git a/solution/2300-2399/2353.Design a Food Rating System/README.md b/solution/2300-2399/2353.Design a Food Rating System/README.md index 715555fb6edbc..953968ce47fe8 100644 --- a/solution/2300-2399/2353.Design a Food Rating System/README.md +++ b/solution/2300-2399/2353.Design a Food Rating System/README.md @@ -97,6 +97,8 @@ foodRatings.highestRated("japanese"); // 返回 "ramen" +#### Python3 + ```python from sortedcontainers import SortedSet @@ -126,6 +128,8 @@ class FoodRatings: # param_2 = obj.highestRated(cuisine) ``` +#### C++ + ```cpp using pis = pair; diff --git a/solution/2300-2399/2353.Design a Food Rating System/README_EN.md b/solution/2300-2399/2353.Design a Food Rating System/README_EN.md index cae6253b338cc..a76a43ed232ad 100644 --- a/solution/2300-2399/2353.Design a Food Rating System/README_EN.md +++ b/solution/2300-2399/2353.Design a Food Rating System/README_EN.md @@ -96,6 +96,8 @@ foodRatings.highestRated("japanese"); // return "ramen" +#### Python3 + ```python from sortedcontainers import SortedSet @@ -125,6 +127,8 @@ class FoodRatings: # param_2 = obj.highestRated(cuisine) ``` +#### C++ + ```cpp using pis = pair; diff --git a/solution/2300-2399/2354.Number of Excellent Pairs/README.md b/solution/2300-2399/2354.Number of Excellent Pairs/README.md index 7653f32dd8ada..cab9374db3567 100644 --- a/solution/2300-2399/2354.Number of Excellent Pairs/README.md +++ b/solution/2300-2399/2354.Number of Excellent Pairs/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def countExcellentPairs(self, nums: List[int], k: int) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long countExcellentPairs(int[] nums, int k) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func countExcellentPairs(nums []int, k int) int64 { s := map[int]bool{} diff --git a/solution/2300-2399/2354.Number of Excellent Pairs/README_EN.md b/solution/2300-2399/2354.Number of Excellent Pairs/README_EN.md index ecf60e2109175..18ff5bd5a6b32 100644 --- a/solution/2300-2399/2354.Number of Excellent Pairs/README_EN.md +++ b/solution/2300-2399/2354.Number of Excellent Pairs/README_EN.md @@ -75,6 +75,8 @@ So the number of excellent pairs is 5. +#### Python3 + ```python class Solution: def countExcellentPairs(self, nums: List[int], k: int) -> int: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long countExcellentPairs(int[] nums, int k) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func countExcellentPairs(nums []int, k int) int64 { s := map[int]bool{} diff --git a/solution/2300-2399/2355.Maximum Number of Books You Can Take/README.md b/solution/2300-2399/2355.Maximum Number of Books You Can Take/README.md index 05b632b43bb20..eb7b0369783cf 100644 --- a/solution/2300-2399/2355.Maximum Number of Books You Can Take/README.md +++ b/solution/2300-2399/2355.Maximum Number of Books You Can Take/README.md @@ -97,6 +97,8 @@ tags: +#### Python3 + ```python class Solution: def maximumBooks(self, books: List[int]) -> int: @@ -123,6 +125,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maximumBooks(int[] books) { @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go func maximumBooks(books []int) int64 { n := len(books) diff --git a/solution/2300-2399/2355.Maximum Number of Books You Can Take/README_EN.md b/solution/2300-2399/2355.Maximum Number of Books You Can Take/README_EN.md index 2f7bbefe3e849..d1e95c8cf69a4 100644 --- a/solution/2300-2399/2355.Maximum Number of Books You Can Take/README_EN.md +++ b/solution/2300-2399/2355.Maximum Number of Books You Can Take/README_EN.md @@ -89,6 +89,8 @@ The time complexity is $O(n^3)$, where $n$ is the number of rows or columns in t +#### Python3 + ```python class Solution: def maximumBooks(self, books: List[int]) -> int: @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maximumBooks(int[] books) { @@ -152,6 +156,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -185,6 +191,8 @@ public: }; ``` +#### Go + ```go func maximumBooks(books []int) int64 { n := len(books) diff --git a/solution/2300-2399/2356.Number of Unique Subjects Taught by Each Teacher/README.md b/solution/2300-2399/2356.Number of Unique Subjects Taught by Each Teacher/README.md index 4b82a3917a812..05c18fb00c54b 100644 --- a/solution/2300-2399/2356.Number of Unique Subjects Taught by Each Teacher/README.md +++ b/solution/2300-2399/2356.Number of Unique Subjects Taught by Each Teacher/README.md @@ -83,6 +83,8 @@ Teacher 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT teacher_id, COUNT(DISTINCT subject_id) AS cnt diff --git a/solution/2300-2399/2356.Number of Unique Subjects Taught by Each Teacher/README_EN.md b/solution/2300-2399/2356.Number of Unique Subjects Taught by Each Teacher/README_EN.md index dd77a348c62ae..9ece647b2da4c 100644 --- a/solution/2300-2399/2356.Number of Unique Subjects Taught by Each Teacher/README_EN.md +++ b/solution/2300-2399/2356.Number of Unique Subjects Taught by Each Teacher/README_EN.md @@ -83,6 +83,8 @@ Teacher 2: +#### MySQL + ```sql # Write your MySQL query statement below SELECT teacher_id, COUNT(DISTINCT subject_id) AS cnt diff --git a/solution/2300-2399/2357.Make Array Zero by Subtracting Equal Amounts/README.md b/solution/2300-2399/2357.Make Array Zero by Subtracting Equal Amounts/README.md index 69506bcc611bb..ef26b3b7f4864 100644 --- a/solution/2300-2399/2357.Make Array Zero by Subtracting Equal Amounts/README.md +++ b/solution/2300-2399/2357.Make Array Zero by Subtracting Equal Amounts/README.md @@ -75,12 +75,16 @@ tags: +#### Python3 + ```python class Solution: def minimumOperations(self, nums: List[int]) -> int: return len({x for x in nums if x}) ``` +#### Java + ```java class Solution { public int minimumOperations(int[] nums) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func minimumOperations(nums []int) (ans int) { s := [101]bool{true} @@ -129,6 +137,8 @@ func minimumOperations(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function minimumOperations(nums: number[]): number { const set = new Set(nums); @@ -137,6 +147,8 @@ function minimumOperations(nums: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -148,6 +160,8 @@ impl Solution { } ``` +#### C + ```c int minimumOperations(int* nums, int numsSize) { int vis[101] = {0}; diff --git a/solution/2300-2399/2357.Make Array Zero by Subtracting Equal Amounts/README_EN.md b/solution/2300-2399/2357.Make Array Zero by Subtracting Equal Amounts/README_EN.md index d13972516342e..c838453885ea3 100644 --- a/solution/2300-2399/2357.Make Array Zero by Subtracting Equal Amounts/README_EN.md +++ b/solution/2300-2399/2357.Make Array Zero by Subtracting Equal Amounts/README_EN.md @@ -70,12 +70,16 @@ In the third operation, choose x = 2. Now, nums = [0,0,0,0,0]. +#### Python3 + ```python class Solution: def minimumOperations(self, nums: List[int]) -> int: return len({x for x in nums if x}) ``` +#### Java + ```java class Solution { public int minimumOperations(int[] nums) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func minimumOperations(nums []int) (ans int) { s := [101]bool{true} @@ -124,6 +132,8 @@ func minimumOperations(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function minimumOperations(nums: number[]): number { const set = new Set(nums); @@ -132,6 +142,8 @@ function minimumOperations(nums: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -143,6 +155,8 @@ impl Solution { } ``` +#### C + ```c int minimumOperations(int* nums, int numsSize) { int vis[101] = {0}; diff --git a/solution/2300-2399/2358.Maximum Number of Groups Entering a Competition/README.md b/solution/2300-2399/2358.Maximum Number of Groups Entering a Competition/README.md index 41ce6559ccb3b..a1c8bfc0ec628 100644 --- a/solution/2300-2399/2358.Maximum Number of Groups Entering a Competition/README.md +++ b/solution/2300-2399/2358.Maximum Number of Groups Entering a Competition/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def maximumGroups(self, grades: List[int]) -> int: @@ -86,6 +88,8 @@ class Solution: return bisect_right(range(n + 1), n * 2, key=lambda x: x * x + x) - 1 ``` +#### Java + ```java class Solution { public int maximumGroups(int[] grades) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func maximumGroups(grades []int) int { n := len(grades) @@ -133,6 +141,8 @@ func maximumGroups(grades []int) int { } ``` +#### TypeScript + ```ts function maximumGroups(grades: number[]): number { const n = grades.length; diff --git a/solution/2300-2399/2358.Maximum Number of Groups Entering a Competition/README_EN.md b/solution/2300-2399/2358.Maximum Number of Groups Entering a Competition/README_EN.md index d3b34249a4777..c8e777fea4956 100644 --- a/solution/2300-2399/2358.Maximum Number of Groups Entering a Competition/README_EN.md +++ b/solution/2300-2399/2358.Maximum Number of Groups Entering a Competition/README_EN.md @@ -69,6 +69,8 @@ It can be shown that it is not possible to form more than 3 groups. +#### Python3 + ```python class Solution: def maximumGroups(self, grades: List[int]) -> int: @@ -76,6 +78,8 @@ class Solution: return bisect_right(range(n + 1), n * 2, key=lambda x: x * x + x) - 1 ``` +#### Java + ```java class Solution { public int maximumGroups(int[] grades) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func maximumGroups(grades []int) int { n := len(grades) @@ -123,6 +131,8 @@ func maximumGroups(grades []int) int { } ``` +#### TypeScript + ```ts function maximumGroups(grades: number[]): number { const n = grades.length; diff --git a/solution/2300-2399/2359.Find Closest Node to Given Two Nodes/README.md b/solution/2300-2399/2359.Find Closest Node to Given Two Nodes/README.md index 7037e3ca50a72..4be648359d10b 100644 --- a/solution/2300-2399/2359.Find Closest Node to Given Two Nodes/README.md +++ b/solution/2300-2399/2359.Find Closest Node to Given Two Nodes/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def closestMeetingNode(self, edges: List[int], node1: int, node2: int) -> int: @@ -111,6 +113,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -206,6 +212,8 @@ public: }; ``` +#### Go + ```go func closestMeetingNode(edges []int, node1 int, node2 int) int { n := len(edges) @@ -259,6 +267,8 @@ func (h *hp) Push(v any) { *h = append(*h, v.(pair)) } func (h *hp) Pop() any { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; return v } ``` +#### TypeScript + ```ts function closestMeetingNode(edges: number[], node1: number, node2: number): number { const n = edges.length; @@ -309,6 +319,8 @@ function closestMeetingNode(edges: number[], node1: number, node2: number): numb +#### Python3 + ```python class Solution: def closestMeetingNode(self, edges: List[int], node1: int, node2: int) -> int: @@ -339,6 +351,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -387,6 +401,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -431,6 +447,8 @@ public: }; ``` +#### Go + ```go func closestMeetingNode(edges []int, node1 int, node2 int) int { n := len(edges) diff --git a/solution/2300-2399/2359.Find Closest Node to Given Two Nodes/README_EN.md b/solution/2300-2399/2359.Find Closest Node to Given Two Nodes/README_EN.md index ccc55daf438a4..12a7148f5a56e 100644 --- a/solution/2300-2399/2359.Find Closest Node to Given Two Nodes/README_EN.md +++ b/solution/2300-2399/2359.Find Closest Node to Given Two Nodes/README_EN.md @@ -69,6 +69,8 @@ The maximum of those two distances is 2. It can be proven that we cannot get a n +#### Python3 + ```python class Solution: def closestMeetingNode(self, edges: List[int], node1: int, node2: int) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -194,6 +200,8 @@ public: }; ``` +#### Go + ```go func closestMeetingNode(edges []int, node1 int, node2 int) int { n := len(edges) @@ -247,6 +255,8 @@ func (h *hp) Push(v any) { *h = append(*h, v.(pair)) } func (h *hp) Pop() any { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; return v } ``` +#### TypeScript + ```ts function closestMeetingNode(edges: number[], node1: number, node2: number): number { const n = edges.length; @@ -297,6 +307,8 @@ function closestMeetingNode(edges: number[], node1: number, node2: number): numb +#### Python3 + ```python class Solution: def closestMeetingNode(self, edges: List[int], node1: int, node2: int) -> int: @@ -327,6 +339,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -375,6 +389,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -419,6 +435,8 @@ public: }; ``` +#### Go + ```go func closestMeetingNode(edges []int, node1 int, node2 int) int { n := len(edges) diff --git a/solution/2300-2399/2360.Longest Cycle in a Graph/README.md b/solution/2300-2399/2360.Longest Cycle in a Graph/README.md index 4ea8307529db6..ea49719262da7 100644 --- a/solution/2300-2399/2360.Longest Cycle in a Graph/README.md +++ b/solution/2300-2399/2360.Longest Cycle in a Graph/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def longestCycle(self, edges: List[int]) -> int: @@ -103,6 +105,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestCycle(int[] edges) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go func longestCycle(edges []int) int { vis := make([]bool, len(edges)) @@ -194,6 +202,8 @@ func longestCycle(edges []int) int { } ``` +#### TypeScript + ```ts function longestCycle(edges: number[]): number { const n = edges.length; diff --git a/solution/2300-2399/2360.Longest Cycle in a Graph/README_EN.md b/solution/2300-2399/2360.Longest Cycle in a Graph/README_EN.md index f288afa755e72..8fd72f8c8c901 100644 --- a/solution/2300-2399/2360.Longest Cycle in a Graph/README_EN.md +++ b/solution/2300-2399/2360.Longest Cycle in a Graph/README_EN.md @@ -74,6 +74,8 @@ Similar problems: +#### Python3 + ```python class Solution: def longestCycle(self, edges: List[int]) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestCycle(int[] edges) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func longestCycle(edges []int) int { vis := make([]bool, len(edges)) @@ -188,6 +196,8 @@ func longestCycle(edges []int) int { } ``` +#### TypeScript + ```ts function longestCycle(edges: number[]): number { const n = edges.length; diff --git a/solution/2300-2399/2361.Minimum Costs Using the Train Line/README.md b/solution/2300-2399/2361.Minimum Costs Using the Train Line/README.md index be7df3e679361..19c3f051f850b 100644 --- a/solution/2300-2399/2361.Minimum Costs Using the Train Line/README.md +++ b/solution/2300-2399/2361.Minimum Costs Using the Train Line/README.md @@ -110,6 +110,8 @@ $$ +#### Python3 + ```python class Solution: def minimumCosts( @@ -126,6 +128,8 @@ class Solution: return cost ``` +#### Java + ```java class Solution { public long[] minimumCosts(int[] regular, int[] express, int expressCost) { @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func minimumCosts(regular []int, express []int, expressCost int) []int64 { n := len(regular) @@ -185,6 +193,8 @@ func minimumCosts(regular []int, express []int, expressCost int) []int64 { } ``` +#### TypeScript + ```ts function minimumCosts(regular: number[], express: number[], expressCost: number): number[] { const n = regular.length; @@ -208,6 +218,8 @@ function minimumCosts(regular: number[], express: number[], expressCost: number) +#### Python3 + ```python class Solution: def minimumCosts( @@ -224,6 +236,8 @@ class Solution: return cost ``` +#### Java + ```java class Solution { public long[] minimumCosts(int[] regular, int[] express, int expressCost) { @@ -245,6 +259,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -267,6 +283,8 @@ public: }; ``` +#### Go + ```go func minimumCosts(regular []int, express []int, expressCost int) []int64 { f, g := 0, 1<<30 @@ -282,6 +300,8 @@ func minimumCosts(regular []int, express []int, expressCost int) []int64 { } ``` +#### TypeScript + ```ts function minimumCosts(regular: number[], express: number[], expressCost: number): number[] { const n = regular.length; diff --git a/solution/2300-2399/2361.Minimum Costs Using the Train Line/README_EN.md b/solution/2300-2399/2361.Minimum Costs Using the Train Line/README_EN.md index 9f643596b3722..081f0d6fc57d8 100644 --- a/solution/2300-2399/2361.Minimum Costs Using the Train Line/README_EN.md +++ b/solution/2300-2399/2361.Minimum Costs Using the Train Line/README_EN.md @@ -108,6 +108,8 @@ The time complexity is $O(n)$ and the space complexity is $O(n)$, where $n$ is t +#### Python3 + ```python class Solution: def minimumCosts( @@ -124,6 +126,8 @@ class Solution: return cost ``` +#### Java + ```java class Solution { public long[] minimumCosts(int[] regular, int[] express, int expressCost) { @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go func minimumCosts(regular []int, express []int, expressCost int) []int64 { n := len(regular) @@ -183,6 +191,8 @@ func minimumCosts(regular []int, express []int, expressCost int) []int64 { } ``` +#### TypeScript + ```ts function minimumCosts(regular: number[], express: number[], expressCost: number): number[] { const n = regular.length; @@ -206,6 +216,8 @@ We notice that in the state transition equations of $f[i]$ and $g[i]$, we only n +#### Python3 + ```python class Solution: def minimumCosts( @@ -222,6 +234,8 @@ class Solution: return cost ``` +#### Java + ```java class Solution { public long[] minimumCosts(int[] regular, int[] express, int expressCost) { @@ -243,6 +257,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -265,6 +281,8 @@ public: }; ``` +#### Go + ```go func minimumCosts(regular []int, express []int, expressCost int) []int64 { f, g := 0, 1<<30 @@ -280,6 +298,8 @@ func minimumCosts(regular []int, express []int, expressCost int) []int64 { } ``` +#### TypeScript + ```ts function minimumCosts(regular: number[], express: number[], expressCost: number): number[] { const n = regular.length; diff --git a/solution/2300-2399/2362.Generate the Invoice/README.md b/solution/2300-2399/2362.Generate the Invoice/README.md index 245753953a80a..6fb6d8d3b5a4a 100644 --- a/solution/2300-2399/2362.Generate the Invoice/README.md +++ b/solution/2300-2399/2362.Generate the Invoice/README.md @@ -101,6 +101,8 @@ Purchases 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2300-2399/2362.Generate the Invoice/README_EN.md b/solution/2300-2399/2362.Generate the Invoice/README_EN.md index ed5f71450eb02..3adf2f05b220e 100644 --- a/solution/2300-2399/2362.Generate the Invoice/README_EN.md +++ b/solution/2300-2399/2362.Generate the Invoice/README_EN.md @@ -101,6 +101,8 @@ The highest price is $1000, and the invoices with the highest prices are 2 and 4 +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2300-2399/2363.Merge Similar Items/README.md b/solution/2300-2399/2363.Merge Similar Items/README.md index 5b2d7cdf9d926..29d98a57b1686 100644 --- a/solution/2300-2399/2363.Merge Similar Items/README.md +++ b/solution/2300-2399/2363.Merge Similar Items/README.md @@ -95,6 +95,8 @@ value = 7 的物品在 items2 中 weight = 1 ,总重量为 1 。 +#### Python3 + ```python class Solution: def mergeSimilarItems( @@ -106,6 +108,8 @@ class Solution: return sorted(cnt.items()) ``` +#### Java + ```java class Solution { public List> mergeSimilarItems(int[][] items1, int[][] items2) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func mergeSimilarItems(items1 [][]int, items2 [][]int) (ans [][]int) { cnt := [1010]int{} @@ -167,6 +175,8 @@ func mergeSimilarItems(items1 [][]int, items2 [][]int) (ans [][]int) { } ``` +#### TypeScript + ```ts function mergeSimilarItems(items1: number[][], items2: number[][]): number[][] { const count = new Array(1001).fill(0); @@ -180,6 +190,8 @@ function mergeSimilarItems(items1: number[][], items2: number[][]): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn merge_similar_items(items1: Vec>, items2: Vec>) -> Vec> { @@ -204,6 +216,8 @@ impl Solution { } ``` +#### C + ```c /** * Return an array of arrays of size *returnSize. diff --git a/solution/2300-2399/2363.Merge Similar Items/README_EN.md b/solution/2300-2399/2363.Merge Similar Items/README_EN.md index 3c5afc720c030..9fac04157606c 100644 --- a/solution/2300-2399/2363.Merge Similar Items/README_EN.md +++ b/solution/2300-2399/2363.Merge Similar Items/README_EN.md @@ -93,6 +93,8 @@ The time complexity is $O(n + m)$ and the space complexity is $O(n + m)$, where +#### Python3 + ```python class Solution: def mergeSimilarItems( @@ -104,6 +106,8 @@ class Solution: return sorted(cnt.items()) ``` +#### Java + ```java class Solution { public List> mergeSimilarItems(int[][] items1, int[][] items2) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func mergeSimilarItems(items1 [][]int, items2 [][]int) (ans [][]int) { cnt := [1010]int{} @@ -165,6 +173,8 @@ func mergeSimilarItems(items1 [][]int, items2 [][]int) (ans [][]int) { } ``` +#### TypeScript + ```ts function mergeSimilarItems(items1: number[][], items2: number[][]): number[][] { const count = new Array(1001).fill(0); @@ -178,6 +188,8 @@ function mergeSimilarItems(items1: number[][], items2: number[][]): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn merge_similar_items(items1: Vec>, items2: Vec>) -> Vec> { @@ -202,6 +214,8 @@ impl Solution { } ``` +#### C + ```c /** * Return an array of arrays of size *returnSize. diff --git a/solution/2300-2399/2364.Count Number of Bad Pairs/README.md b/solution/2300-2399/2364.Count Number of Bad Pairs/README.md index 60b1ec36ec371..fb7ae0f252728 100644 --- a/solution/2300-2399/2364.Count Number of Bad Pairs/README.md +++ b/solution/2300-2399/2364.Count Number of Bad Pairs/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def countBadPairs(self, nums: List[int]) -> int: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long countBadPairs(int[] nums) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func countBadPairs(nums []int) (ans int64) { cnt := map[int]int{} @@ -127,6 +135,8 @@ func countBadPairs(nums []int) (ans int64) { } ``` +#### TypeScript + ```ts function countBadPairs(nums: number[]): number { const cnt = new Map(); diff --git a/solution/2300-2399/2364.Count Number of Bad Pairs/README_EN.md b/solution/2300-2399/2364.Count Number of Bad Pairs/README_EN.md index 0d30b9332d5b4..b2f7b50ebc63c 100644 --- a/solution/2300-2399/2364.Count Number of Bad Pairs/README_EN.md +++ b/solution/2300-2399/2364.Count Number of Bad Pairs/README_EN.md @@ -73,6 +73,8 @@ The time complexity is $O(n)$ and the space complexity is $O(n)$, where $n$ is t +#### Python3 + ```python class Solution: def countBadPairs(self, nums: List[int]) -> int: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long countBadPairs(int[] nums) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func countBadPairs(nums []int) (ans int64) { cnt := map[int]int{} @@ -127,6 +135,8 @@ func countBadPairs(nums []int) (ans int64) { } ``` +#### TypeScript + ```ts function countBadPairs(nums: number[]): number { const cnt = new Map(); diff --git a/solution/2300-2399/2365.Task Scheduler II/README.md b/solution/2300-2399/2365.Task Scheduler II/README.md index 1b5544ccd0047..e19fa2fefe4a1 100644 --- a/solution/2300-2399/2365.Task Scheduler II/README.md +++ b/solution/2300-2399/2365.Task Scheduler II/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class Solution: def taskSchedulerII(self, tasks: List[int], space: int) -> int: @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long taskSchedulerII(int[] tasks, int space) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func taskSchedulerII(tasks []int, space int) (ans int64) { day := map[int]int64{} @@ -153,6 +161,8 @@ func taskSchedulerII(tasks []int, space int) (ans int64) { } ``` +#### TypeScript + ```ts function taskSchedulerII(tasks: number[], space: number): number { const day = new Map(); diff --git a/solution/2300-2399/2365.Task Scheduler II/README_EN.md b/solution/2300-2399/2365.Task Scheduler II/README_EN.md index 988fb359e971c..b575d9500f032 100644 --- a/solution/2300-2399/2365.Task Scheduler II/README_EN.md +++ b/solution/2300-2399/2365.Task Scheduler II/README_EN.md @@ -96,6 +96,8 @@ The time complexity is $O(n)$ and the space complexity is $O(n)$, where $n$ is t +#### Python3 + ```python class Solution: def taskSchedulerII(self, tasks: List[int], space: int) -> int: @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long taskSchedulerII(int[] tasks, int space) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func taskSchedulerII(tasks []int, space int) (ans int64) { day := map[int]int64{} @@ -153,6 +161,8 @@ func taskSchedulerII(tasks []int, space int) (ans int64) { } ``` +#### TypeScript + ```ts function taskSchedulerII(tasks: number[], space: number): number { const day = new Map(); diff --git a/solution/2300-2399/2366.Minimum Replacements to Sort the Array/README.md b/solution/2300-2399/2366.Minimum Replacements to Sort the Array/README.md index 385bf662f125b..e3475e60c3e62 100644 --- a/solution/2300-2399/2366.Minimum Replacements to Sort the Array/README.md +++ b/solution/2300-2399/2366.Minimum Replacements to Sort the Array/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def minimumReplacement(self, nums: List[int]) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long minimumReplacement(int[] nums) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func minimumReplacement(nums []int) (ans int64) { n := len(nums) @@ -153,6 +161,8 @@ func minimumReplacement(nums []int) (ans int64) { } ``` +#### TypeScript + ```ts function minimumReplacement(nums: number[]): number { const n = nums.length; @@ -171,6 +181,8 @@ function minimumReplacement(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/2300-2399/2366.Minimum Replacements to Sort the Array/README_EN.md b/solution/2300-2399/2366.Minimum Replacements to Sort the Array/README_EN.md index 895565cf9de9e..e0606df9f0ee9 100644 --- a/solution/2300-2399/2366.Minimum Replacements to Sort the Array/README_EN.md +++ b/solution/2300-2399/2366.Minimum Replacements to Sort the Array/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def minimumReplacement(self, nums: List[int]) -> int: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long minimumReplacement(int[] nums) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func minimumReplacement(nums []int) (ans int64) { n := len(nums) @@ -152,6 +160,8 @@ func minimumReplacement(nums []int) (ans int64) { } ``` +#### TypeScript + ```ts function minimumReplacement(nums: number[]): number { const n = nums.length; @@ -170,6 +180,8 @@ function minimumReplacement(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/2300-2399/2367.Number of Arithmetic Triplets/README.md b/solution/2300-2399/2367.Number of Arithmetic Triplets/README.md index 8287854d14c0b..ab5d03766026f 100644 --- a/solution/2300-2399/2367.Number of Arithmetic Triplets/README.md +++ b/solution/2300-2399/2367.Number of Arithmetic Triplets/README.md @@ -76,12 +76,16 @@ tags: +#### Python3 + ```python class Solution: def arithmeticTriplets(self, nums: List[int], diff: int) -> int: return sum(b - a == diff and c - b == diff for a, b, c in combinations(nums, 3)) ``` +#### Java + ```java class Solution { public int arithmeticTriplets(int[] nums, int diff) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func arithmeticTriplets(nums []int, diff int) (ans int) { n := len(nums) @@ -137,6 +145,8 @@ func arithmeticTriplets(nums []int, diff int) (ans int) { } ``` +#### TypeScript + ```ts function arithmeticTriplets(nums: number[], diff: number): number { const n = nums.length; @@ -170,6 +180,8 @@ function arithmeticTriplets(nums: number[], diff: number): number { +#### Python3 + ```python class Solution: def arithmeticTriplets(self, nums: List[int], diff: int) -> int: @@ -177,6 +189,8 @@ class Solution: return sum(x + diff in vis and x + diff * 2 in vis for x in nums) ``` +#### Java + ```java class Solution { public int arithmeticTriplets(int[] nums, int diff) { @@ -195,6 +209,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -212,6 +228,8 @@ public: }; ``` +#### Go + ```go func arithmeticTriplets(nums []int, diff int) (ans int) { vis := [301]bool{} @@ -227,6 +245,8 @@ func arithmeticTriplets(nums []int, diff int) (ans int) { } ``` +#### TypeScript + ```ts function arithmeticTriplets(nums: number[], diff: number): number { const vis: boolean[] = new Array(301).fill(false); diff --git a/solution/2300-2399/2367.Number of Arithmetic Triplets/README_EN.md b/solution/2300-2399/2367.Number of Arithmetic Triplets/README_EN.md index a981fbd51733d..dfe7885e2dfe3 100644 --- a/solution/2300-2399/2367.Number of Arithmetic Triplets/README_EN.md +++ b/solution/2300-2399/2367.Number of Arithmetic Triplets/README_EN.md @@ -76,12 +76,16 @@ The time complexity is $O(n^3)$, where $n$ is the length of the array $nums$. Th +#### Python3 + ```python class Solution: def arithmeticTriplets(self, nums: List[int], diff: int) -> int: return sum(b - a == diff and c - b == diff for a, b, c in combinations(nums, 3)) ``` +#### Java + ```java class Solution { public int arithmeticTriplets(int[] nums, int diff) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func arithmeticTriplets(nums []int, diff int) (ans int) { n := len(nums) @@ -137,6 +145,8 @@ func arithmeticTriplets(nums []int, diff int) (ans int) { } ``` +#### TypeScript + ```ts function arithmeticTriplets(nums: number[], diff: number): number { const n = nums.length; @@ -170,6 +180,8 @@ The time complexity is $O(n)$ and the space complexity is $O(n)$, where $n$ is t +#### Python3 + ```python class Solution: def arithmeticTriplets(self, nums: List[int], diff: int) -> int: @@ -177,6 +189,8 @@ class Solution: return sum(x + diff in vis and x + diff * 2 in vis for x in nums) ``` +#### Java + ```java class Solution { public int arithmeticTriplets(int[] nums, int diff) { @@ -195,6 +209,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -212,6 +228,8 @@ public: }; ``` +#### Go + ```go func arithmeticTriplets(nums []int, diff int) (ans int) { vis := [301]bool{} @@ -227,6 +245,8 @@ func arithmeticTriplets(nums []int, diff int) (ans int) { } ``` +#### TypeScript + ```ts function arithmeticTriplets(nums: number[], diff: number): number { const vis: boolean[] = new Array(301).fill(false); diff --git a/solution/2300-2399/2368.Reachable Nodes With Restrictions/README.md b/solution/2300-2399/2368.Reachable Nodes With Restrictions/README.md index 45de95fdb85ee..1e22b17f5361c 100644 --- a/solution/2300-2399/2368.Reachable Nodes With Restrictions/README.md +++ b/solution/2300-2399/2368.Reachable Nodes With Restrictions/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def reachableNodes( @@ -100,6 +102,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private List[] g; @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func reachableNodes(n int, edges [][]int, restricted []int) int { g := make([][]int, n) @@ -191,6 +199,8 @@ func reachableNodes(n int, edges [][]int, restricted []int) int { } ``` +#### TypeScript + ```ts function reachableNodes(n: number, edges: number[][], restricted: number[]): number { const vis: boolean[] = Array(n).fill(false); @@ -234,6 +244,8 @@ function reachableNodes(n: number, edges: number[][], restricted: number[]): num +#### Python3 + ```python class Solution: def reachableNodes( @@ -256,6 +268,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int reachableNodes(int n, int[][] edges, int[] restricted) { @@ -287,6 +301,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -318,6 +334,8 @@ public: }; ``` +#### Go + ```go func reachableNodes(n int, edges [][]int, restricted []int) (ans int) { g := make([][]int, n) @@ -345,6 +363,8 @@ func reachableNodes(n int, edges [][]int, restricted []int) (ans int) { } ``` +#### TypeScript + ```ts function reachableNodes(n: number, edges: number[][], restricted: number[]): number { const vis: boolean[] = Array(n).fill(false); diff --git a/solution/2300-2399/2368.Reachable Nodes With Restrictions/README_EN.md b/solution/2300-2399/2368.Reachable Nodes With Restrictions/README_EN.md index f8aae50addb73..7eb0035ef6255 100644 --- a/solution/2300-2399/2368.Reachable Nodes With Restrictions/README_EN.md +++ b/solution/2300-2399/2368.Reachable Nodes With Restrictions/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def reachableNodes( @@ -101,6 +103,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private List[] g; @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func reachableNodes(n int, edges [][]int, restricted []int) int { g := make([][]int, n) @@ -190,6 +198,8 @@ func reachableNodes(n int, edges [][]int, restricted []int) int { } ``` +#### TypeScript + ```ts function reachableNodes(n: number, edges: number[][], restricted: number[]): number { const vis: boolean[] = Array(n).fill(false); @@ -233,6 +243,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def reachableNodes( @@ -255,6 +267,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int reachableNodes(int n, int[][] edges, int[] restricted) { @@ -286,6 +300,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -317,6 +333,8 @@ public: }; ``` +#### Go + ```go func reachableNodes(n int, edges [][]int, restricted []int) (ans int) { g := make([][]int, n) @@ -344,6 +362,8 @@ func reachableNodes(n int, edges [][]int, restricted []int) (ans int) { } ``` +#### TypeScript + ```ts function reachableNodes(n: number, edges: number[][], restricted: number[]): number { const vis: boolean[] = Array(n).fill(false); diff --git a/solution/2300-2399/2369.Check if There is a Valid Partition For The Array/README.md b/solution/2300-2399/2369.Check if There is a Valid Partition For The Array/README.md index 7567993092272..a3cc8407d5b49 100644 --- a/solution/2300-2399/2369.Check if There is a Valid Partition For The Array/README.md +++ b/solution/2300-2399/2369.Check if There is a Valid Partition For The Array/README.md @@ -95,6 +95,8 @@ $$ +#### Python3 + ```python class Solution: def validPartition(self, nums: List[int]) -> bool: @@ -115,6 +117,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private int n; @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ private: }; ``` +#### Go + ```go func validPartition(nums []int) bool { n := len(nums) @@ -202,6 +210,8 @@ func validPartition(nums []int) bool { } ``` +#### TypeScript + ```ts function validPartition(nums: number[]): boolean { const n = nums.length; @@ -251,6 +261,8 @@ $$ +#### Python3 + ```python class Solution: def validPartition(self, nums: List[int]) -> bool: @@ -264,6 +276,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public boolean validPartition(int[] nums) { @@ -282,6 +296,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -300,6 +316,8 @@ public: }; ``` +#### Go + ```go func validPartition(nums []int) bool { n := len(nums) @@ -316,6 +334,8 @@ func validPartition(nums []int) bool { } ``` +#### TypeScript + ```ts function validPartition(nums: number[]): boolean { const n = nums.length; diff --git a/solution/2300-2399/2369.Check if There is a Valid Partition For The Array/README_EN.md b/solution/2300-2399/2369.Check if There is a Valid Partition For The Array/README_EN.md index 487f8182395e3..470bf722492a4 100644 --- a/solution/2300-2399/2369.Check if There is a Valid Partition For The Array/README_EN.md +++ b/solution/2300-2399/2369.Check if There is a Valid Partition For The Array/README_EN.md @@ -93,6 +93,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def validPartition(self, nums: List[int]) -> bool: @@ -113,6 +115,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private int n; @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -172,6 +178,8 @@ private: }; ``` +#### Go + ```go func validPartition(nums []int) bool { n := len(nums) @@ -200,6 +208,8 @@ func validPartition(nums []int) bool { } ``` +#### TypeScript + ```ts function validPartition(nums: number[]): boolean { const n = nums.length; @@ -249,6 +259,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def validPartition(self, nums: List[int]) -> bool: @@ -262,6 +274,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public boolean validPartition(int[] nums) { @@ -280,6 +294,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -298,6 +314,8 @@ public: }; ``` +#### Go + ```go func validPartition(nums []int) bool { n := len(nums) @@ -314,6 +332,8 @@ func validPartition(nums []int) bool { } ``` +#### TypeScript + ```ts function validPartition(nums: number[]): boolean { const n = nums.length; diff --git a/solution/2300-2399/2370.Longest Ideal Subsequence/README.md b/solution/2300-2399/2370.Longest Ideal Subsequence/README.md index 3c9d098e0beac..f3f5ed46d2bb5 100644 --- a/solution/2300-2399/2370.Longest Ideal Subsequence/README.md +++ b/solution/2300-2399/2370.Longest Ideal Subsequence/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def longestIdealString(self, s: str, k: int) -> int: @@ -97,6 +99,8 @@ class Solution: return max(dp) ``` +#### Java + ```java class Solution { public int longestIdealString(String s, int k) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func longestIdealString(s string, k int) int { n := len(s) @@ -173,6 +181,8 @@ func longestIdealString(s string, k int) int { } ``` +#### TypeScript + ```ts function longestIdealString(s: string, k: number): number { const dp = new Array(26).fill(0); diff --git a/solution/2300-2399/2370.Longest Ideal Subsequence/README_EN.md b/solution/2300-2399/2370.Longest Ideal Subsequence/README_EN.md index 87ea904d722d3..c28d127af8f2c 100644 --- a/solution/2300-2399/2370.Longest Ideal Subsequence/README_EN.md +++ b/solution/2300-2399/2370.Longest Ideal Subsequence/README_EN.md @@ -69,6 +69,8 @@ Note that "acfgbd" is not ideal because 'c' and 'f' ha +#### Python3 + ```python class Solution: def longestIdealString(self, s: str, k: int) -> int: @@ -87,6 +89,8 @@ class Solution: return max(dp) ``` +#### Java + ```java class Solution { public int longestIdealString(String s, int k) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func longestIdealString(s string, k int) int { n := len(s) @@ -163,6 +171,8 @@ func longestIdealString(s string, k int) int { } ``` +#### TypeScript + ```ts function longestIdealString(s: string, k: number): number { const dp = new Array(26).fill(0); diff --git a/solution/2300-2399/2371.Minimize Maximum Value in a Grid/README.md b/solution/2300-2399/2371.Minimize Maximum Value in a Grid/README.md index c2650fe830ecc..7a1e484285d76 100644 --- a/solution/2300-2399/2371.Minimize Maximum Value in a Grid/README.md +++ b/solution/2300-2399/2371.Minimize Maximum Value in a Grid/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def minScore(self, grid: List[List[int]]) -> List[List[int]]: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] minScore(int[][] grid) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func minScore(grid [][]int) [][]int { m, n := len(grid), len(grid[0]) @@ -176,6 +184,8 @@ func minScore(grid [][]int) [][]int { } ``` +#### TypeScript + ```ts function minScore(grid: number[][]): number[][] { const m = grid.length; diff --git a/solution/2300-2399/2371.Minimize Maximum Value in a Grid/README_EN.md b/solution/2300-2399/2371.Minimize Maximum Value in a Grid/README_EN.md index 45c168ff97259..50354527e9c74 100644 --- a/solution/2300-2399/2371.Minimize Maximum Value in a Grid/README_EN.md +++ b/solution/2300-2399/2371.Minimize Maximum Value in a Grid/README_EN.md @@ -76,6 +76,8 @@ The maximum number in the matrix is 2. It can be shown that no smaller value can +#### Python3 + ```python class Solution: def minScore(self, grid: List[List[int]]) -> List[List[int]]: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] minScore(int[][] grid) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func minScore(grid [][]int) [][]int { m, n := len(grid), len(grid[0]) @@ -166,6 +174,8 @@ func minScore(grid [][]int) [][]int { } ``` +#### TypeScript + ```ts function minScore(grid: number[][]): number[][] { const m = grid.length; diff --git a/solution/2300-2399/2372.Calculate the Influence of Each Salesperson/README.md b/solution/2300-2399/2372.Calculate the Influence of Each Salesperson/README.md index 58d5668c03ab8..3164e5f7f10fc 100644 --- a/solution/2300-2399/2372.Calculate the Influence of Each Salesperson/README.md +++ b/solution/2300-2399/2372.Calculate the Influence of Each Salesperson/README.md @@ -130,6 +130,8 @@ Jerry 的总数是 0。 +#### MySQL + ```sql # Write your MySQL query statement below SELECT sp.salesperson_id, name, IFNULL(SUM(price), 0) AS total diff --git a/solution/2300-2399/2372.Calculate the Influence of Each Salesperson/README_EN.md b/solution/2300-2399/2372.Calculate the Influence of Each Salesperson/README_EN.md index ed37e06c5b79c..ca4ed3d1e2072 100644 --- a/solution/2300-2399/2372.Calculate the Influence of Each Salesperson/README_EN.md +++ b/solution/2300-2399/2372.Calculate the Influence of Each Salesperson/README_EN.md @@ -132,6 +132,8 @@ The total for Jerry is 0. +#### MySQL + ```sql # Write your MySQL query statement below SELECT sp.salesperson_id, name, IFNULL(SUM(price), 0) AS total diff --git a/solution/2300-2399/2373.Largest Local Values in a Matrix/README.md b/solution/2300-2399/2373.Largest Local Values in a Matrix/README.md index 839883c2673b7..c702dcf682417 100644 --- a/solution/2300-2399/2373.Largest Local Values in a Matrix/README.md +++ b/solution/2300-2399/2373.Largest Local Values in a Matrix/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def largestLocal(self, grid: List[List[int]]) -> List[List[int]]: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] largestLocal(int[][] grid) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func largestLocal(grid [][]int) [][]int { n := len(grid) @@ -147,6 +155,8 @@ func largestLocal(grid [][]int) [][]int { } ``` +#### TypeScript + ```ts function largestLocal(grid: number[][]): number[][] { const n = grid.length; diff --git a/solution/2300-2399/2373.Largest Local Values in a Matrix/README_EN.md b/solution/2300-2399/2373.Largest Local Values in a Matrix/README_EN.md index 8422bc16c4b90..10a232543c13f 100644 --- a/solution/2300-2399/2373.Largest Local Values in a Matrix/README_EN.md +++ b/solution/2300-2399/2373.Largest Local Values in a Matrix/README_EN.md @@ -67,6 +67,8 @@ Notice that each value in the generated matrix corresponds to the largest value +#### Python3 + ```python class Solution: def largestLocal(self, grid: List[List[int]]) -> List[List[int]]: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] largestLocal(int[][] grid) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func largestLocal(grid [][]int) [][]int { n := len(grid) @@ -137,6 +145,8 @@ func largestLocal(grid [][]int) [][]int { } ``` +#### TypeScript + ```ts function largestLocal(grid: number[][]): number[][] { const n = grid.length; diff --git a/solution/2300-2399/2374.Node With Highest Edge Score/README.md b/solution/2300-2399/2374.Node With Highest Edge Score/README.md index 5651a345cd275..85072537277bd 100644 --- a/solution/2300-2399/2374.Node With Highest Edge Score/README.md +++ b/solution/2300-2399/2374.Node With Highest Edge Score/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def edgeScore(self, edges: List[int]) -> int: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int edgeScore(int[] edges) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func edgeScore(edges []int) int { n := len(edges) @@ -147,6 +155,8 @@ func edgeScore(edges []int) int { } ``` +#### TypeScript + ```ts function edgeScore(edges: number[]): number { const n = edges.length; diff --git a/solution/2300-2399/2374.Node With Highest Edge Score/README_EN.md b/solution/2300-2399/2374.Node With Highest Edge Score/README_EN.md index b62bf8a54406f..af10493a773d4 100644 --- a/solution/2300-2399/2374.Node With Highest Edge Score/README_EN.md +++ b/solution/2300-2399/2374.Node With Highest Edge Score/README_EN.md @@ -72,6 +72,8 @@ Nodes 0 and 2 both have an edge score of 3. Since node 0 has a smaller index, we +#### Python3 + ```python class Solution: def edgeScore(self, edges: List[int]) -> int: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int edgeScore(int[] edges) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func edgeScore(edges []int) int { n := len(edges) @@ -141,6 +149,8 @@ func edgeScore(edges []int) int { } ``` +#### TypeScript + ```ts function edgeScore(edges: number[]): number { const n = edges.length; diff --git a/solution/2300-2399/2375.Construct Smallest Number From DI String/README.md b/solution/2300-2399/2375.Construct Smallest Number From DI String/README.md index 4a75b913b34e6..1978701dde595 100644 --- a/solution/2300-2399/2375.Construct Smallest Number From DI String/README.md +++ b/solution/2300-2399/2375.Construct Smallest Number From DI String/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def smallestNumber(self, pattern: str) -> str: @@ -109,6 +111,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private boolean[] vis = new boolean[10]; @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -185,6 +191,8 @@ public: }; ``` +#### Go + ```go func smallestNumber(pattern string) string { vis := make([]bool, 10) @@ -220,6 +228,8 @@ func smallestNumber(pattern string) string { } ``` +#### TypeScript + ```ts function smallestNumber(pattern: string): string { const n = pattern.length; diff --git a/solution/2300-2399/2375.Construct Smallest Number From DI String/README_EN.md b/solution/2300-2399/2375.Construct Smallest Number From DI String/README_EN.md index 8f9db05dc36a1..12e5d8a9c09bd 100644 --- a/solution/2300-2399/2375.Construct Smallest Number From DI String/README_EN.md +++ b/solution/2300-2399/2375.Construct Smallest Number From DI String/README_EN.md @@ -74,6 +74,8 @@ It can be proven that "4321" is the smallest possible num that meets t +#### Python3 + ```python class Solution: def smallestNumber(self, pattern: str) -> str: @@ -103,6 +105,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private boolean[] vis = new boolean[10]; @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -179,6 +185,8 @@ public: }; ``` +#### Go + ```go func smallestNumber(pattern string) string { vis := make([]bool, 10) @@ -214,6 +222,8 @@ func smallestNumber(pattern string) string { } ``` +#### TypeScript + ```ts function smallestNumber(pattern: string): string { const n = pattern.length; diff --git a/solution/2300-2399/2376.Count Special Integers/README.md b/solution/2300-2399/2376.Count Special Integers/README.md index db498e620179c..3984bef3a3161 100644 --- a/solution/2300-2399/2376.Count Special Integers/README.md +++ b/solution/2300-2399/2376.Count Special Integers/README.md @@ -92,6 +92,8 @@ $$ +#### Python3 + ```python class Solution: def countSpecialNumbers(self, n: int) -> int: @@ -119,6 +121,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countSpecialNumbers(int n) { @@ -158,6 +162,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -197,6 +203,8 @@ public: }; ``` +#### Go + ```go func countSpecialNumbers(n int) int { digits := []int{} @@ -250,6 +258,8 @@ func A(m, n int) int { +#### Python3 + ```python class Solution: def countSpecialNumbers(self, n: int) -> int: @@ -280,6 +290,8 @@ class Solution: return dfs(l, 0, True, True) ``` +#### Java + ```java class Solution { private int[] a = new int[11]; @@ -328,6 +340,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -373,6 +387,8 @@ public: }; ``` +#### Go + ```go func countSpecialNumbers(n int) int { return f(n) diff --git a/solution/2300-2399/2376.Count Special Integers/README_EN.md b/solution/2300-2399/2376.Count Special Integers/README_EN.md index 47265265484a9..ccf94c143d6bf 100644 --- a/solution/2300-2399/2376.Count Special Integers/README_EN.md +++ b/solution/2300-2399/2376.Count Special Integers/README_EN.md @@ -65,6 +65,8 @@ Some of the integers that are not special are: 22, 114, and 131. +#### Python3 + ```python class Solution: def countSpecialNumbers(self, n: int) -> int: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countSpecialNumbers(int n) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go func countSpecialNumbers(n int) int { digits := []int{} @@ -223,6 +231,8 @@ func A(m, n int) int { +#### Python3 + ```python class Solution: def countSpecialNumbers(self, n: int) -> int: @@ -253,6 +263,8 @@ class Solution: return dfs(l, 0, True, True) ``` +#### Java + ```java class Solution { private int[] a = new int[11]; @@ -301,6 +313,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -346,6 +360,8 @@ public: }; ``` +#### Go + ```go func countSpecialNumbers(n int) int { return f(n) diff --git a/solution/2300-2399/2377.Sort the Olympic Table/README.md b/solution/2300-2399/2377.Sort the Olympic Table/README.md index bef7519cb79b8..c00b0e283c060 100644 --- a/solution/2300-2399/2377.Sort the Olympic Table/README.md +++ b/solution/2300-2399/2377.Sort the Olympic Table/README.md @@ -86,6 +86,8 @@ Olympic 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT * diff --git a/solution/2300-2399/2377.Sort the Olympic Table/README_EN.md b/solution/2300-2399/2377.Sort the Olympic Table/README_EN.md index 4ac48fb482e68..cd956aca820d3 100644 --- a/solution/2300-2399/2377.Sort the Olympic Table/README_EN.md +++ b/solution/2300-2399/2377.Sort the Olympic Table/README_EN.md @@ -86,6 +86,8 @@ Israel comes before Egypt because it has more bronze medals. +#### MySQL + ```sql # Write your MySQL query statement below SELECT * diff --git a/solution/2300-2399/2378.Choose Edges to Maximize Score in a Tree/README.md b/solution/2300-2399/2378.Choose Edges to Maximize Score in a Tree/README.md index 15d4c71001f24..f46b76f92c0f0 100644 --- a/solution/2300-2399/2378.Choose Edges to Maximize Score in a Tree/README.md +++ b/solution/2300-2399/2378.Choose Edges to Maximize Score in a Tree/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class Solution: def maxScore(self, edges: List[List[int]]) -> int: @@ -115,6 +117,8 @@ class Solution: return dfs(0)[1] ``` +#### Java + ```java class Solution { private List[] g; @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go func maxScore(edges [][]int) int64 { n := len(edges) diff --git a/solution/2300-2399/2378.Choose Edges to Maximize Score in a Tree/README_EN.md b/solution/2300-2399/2378.Choose Edges to Maximize Score in a Tree/README_EN.md index e738fc26e0dcd..8d3a1943303c3 100644 --- a/solution/2300-2399/2378.Choose Edges to Maximize Score in a Tree/README_EN.md +++ b/solution/2300-2399/2378.Choose Edges to Maximize Score in a Tree/README_EN.md @@ -81,6 +81,8 @@ Note that we cannot choose more than one edge because all edges are adjacent to +#### Python3 + ```python class Solution: def maxScore(self, edges: List[List[int]]) -> int: @@ -100,6 +102,8 @@ class Solution: return dfs(0)[1] ``` +#### Java + ```java class Solution { private List[] g; @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func maxScore(edges [][]int) int64 { n := len(edges) diff --git a/solution/2300-2399/2379.Minimum Recolors to Get K Consecutive Black Blocks/README.md b/solution/2300-2399/2379.Minimum Recolors to Get K Consecutive Black Blocks/README.md index 587102964ab11..59ed1fa084b45 100644 --- a/solution/2300-2399/2379.Minimum Recolors to Get K Consecutive Black Blocks/README.md +++ b/solution/2300-2399/2379.Minimum Recolors to Get K Consecutive Black Blocks/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def minimumRecolors(self, blocks: str, k: int) -> int: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumRecolors(String blocks, int k) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func minimumRecolors(blocks string, k int) int { cnt := strings.Count(blocks[:k], "W") @@ -144,6 +152,8 @@ func minimumRecolors(blocks string, k int) int { } ``` +#### TypeScript + ```ts function minimumRecolors(blocks: string, k: number): number { let cnt = 0; @@ -160,6 +170,8 @@ function minimumRecolors(blocks: string, k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn minimum_recolors(blocks: String, k: i32) -> i32 { @@ -187,6 +199,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** @@ -216,6 +230,8 @@ class Solution { } ``` +#### C + ```c #define min(a, b) (((a) < (b)) ? (a) : (b)) diff --git a/solution/2300-2399/2379.Minimum Recolors to Get K Consecutive Black Blocks/README_EN.md b/solution/2300-2399/2379.Minimum Recolors to Get K Consecutive Black Blocks/README_EN.md index 5f6499501d035..b622f15ce2bad 100644 --- a/solution/2300-2399/2379.Minimum Recolors to Get K Consecutive Black Blocks/README_EN.md +++ b/solution/2300-2399/2379.Minimum Recolors to Get K Consecutive Black Blocks/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string $blocks$. T +#### Python3 + ```python class Solution: def minimumRecolors(self, blocks: str, k: int) -> int: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumRecolors(String blocks, int k) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func minimumRecolors(blocks string, k int) int { cnt := strings.Count(blocks[:k], "W") @@ -142,6 +150,8 @@ func minimumRecolors(blocks string, k int) int { } ``` +#### TypeScript + ```ts function minimumRecolors(blocks: string, k: number): number { let cnt = 0; @@ -158,6 +168,8 @@ function minimumRecolors(blocks: string, k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn minimum_recolors(blocks: String, k: i32) -> i32 { @@ -185,6 +197,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** @@ -214,6 +228,8 @@ class Solution { } ``` +#### C + ```c #define min(a, b) (((a) < (b)) ? (a) : (b)) diff --git a/solution/2300-2399/2380.Time Needed to Rearrange a Binary String/README.md b/solution/2300-2399/2380.Time Needed to Rearrange a Binary String/README.md index b9b9001660c45..d9ef8073adb05 100644 --- a/solution/2300-2399/2380.Time Needed to Rearrange a Binary String/README.md +++ b/solution/2300-2399/2380.Time Needed to Rearrange a Binary String/README.md @@ -79,6 +79,8 @@ s 中没有 "01" 存在,整个过程花费 0 秒。 +#### Python3 + ```python class Solution: def secondsToRemoveOccurrences(self, s: str) -> int: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int secondsToRemoveOccurrences(String s) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func secondsToRemoveOccurrences(s string) int { cs := []byte(s) @@ -194,6 +202,8 @@ func secondsToRemoveOccurrences(s string) int { +#### Python3 + ```python class Solution: def secondsToRemoveOccurrences(self, s: str) -> int: @@ -206,6 +216,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int secondsToRemoveOccurrences(String s) { @@ -222,6 +234,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -239,6 +253,8 @@ public: }; ``` +#### Go + ```go func secondsToRemoveOccurrences(s string) int { ans, cnt := 0, 0 diff --git a/solution/2300-2399/2380.Time Needed to Rearrange a Binary String/README_EN.md b/solution/2300-2399/2380.Time Needed to Rearrange a Binary String/README_EN.md index c80b1578092bf..47a6ace2a55ef 100644 --- a/solution/2300-2399/2380.Time Needed to Rearrange a Binary String/README_EN.md +++ b/solution/2300-2399/2380.Time Needed to Rearrange a Binary String/README_EN.md @@ -72,6 +72,8 @@ so we return 0. +#### Python3 + ```python class Solution: def secondsToRemoveOccurrences(self, s: str) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int secondsToRemoveOccurrences(String s) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func secondsToRemoveOccurrences(s string) int { cs := []byte(s) @@ -164,6 +172,8 @@ func secondsToRemoveOccurrences(s string) int { +#### Python3 + ```python class Solution: def secondsToRemoveOccurrences(self, s: str) -> int: @@ -176,6 +186,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int secondsToRemoveOccurrences(String s) { @@ -192,6 +204,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -209,6 +223,8 @@ public: }; ``` +#### Go + ```go func secondsToRemoveOccurrences(s string) int { ans, cnt := 0, 0 diff --git a/solution/2300-2399/2381.Shifting Letters II/README.md b/solution/2300-2399/2381.Shifting Letters II/README.md index 1db8a029584b0..6bf395e473e80 100644 --- a/solution/2300-2399/2381.Shifting Letters II/README.md +++ b/solution/2300-2399/2381.Shifting Letters II/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def shiftingLetters(self, s: str, shifts: List[List[int]]) -> str: @@ -89,6 +91,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public String shiftingLetters(String s, int[][] shifts) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func shiftingLetters(s string, shifts [][]int) string { n := len(s) @@ -163,6 +171,8 @@ func shiftingLetters(s string, shifts [][]int) string { } ``` +#### TypeScript + ```ts function shiftingLetters(s: string, shifts: number[][]): string { const n: number = s.length; diff --git a/solution/2300-2399/2381.Shifting Letters II/README_EN.md b/solution/2300-2399/2381.Shifting Letters II/README_EN.md index 9363c44d30d0d..95bf687226676 100644 --- a/solution/2300-2399/2381.Shifting Letters II/README_EN.md +++ b/solution/2300-2399/2381.Shifting Letters II/README_EN.md @@ -66,6 +66,8 @@ Finally, shift the characters from index 1 to index 1 forward. Now s = "cat +#### Python3 + ```python class Solution: def shiftingLetters(self, s: str, shifts: List[List[int]]) -> str: @@ -83,6 +85,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public String shiftingLetters(String s, int[][] shifts) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func shiftingLetters(s string, shifts [][]int) string { n := len(s) @@ -157,6 +165,8 @@ func shiftingLetters(s string, shifts [][]int) string { } ``` +#### TypeScript + ```ts function shiftingLetters(s: string, shifts: number[][]): string { const n: number = s.length; diff --git a/solution/2300-2399/2382.Maximum Segment Sum After Removals/README.md b/solution/2300-2399/2382.Maximum Segment Sum After Removals/README.md index c2052e32c24c0..e9be0f1f4ca64 100644 --- a/solution/2300-2399/2382.Maximum Segment Sum After Removals/README.md +++ b/solution/2300-2399/2382.Maximum Segment Sum After Removals/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def maximumSegmentSum(self, nums: List[int], removeQueries: List[int]) -> List[int]: @@ -119,6 +121,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] p; @@ -163,6 +167,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -202,6 +208,8 @@ public: }; ``` +#### Go + ```go func maximumSegmentSum(nums []int, removeQueries []int) []int64 { n := len(nums) diff --git a/solution/2300-2399/2382.Maximum Segment Sum After Removals/README_EN.md b/solution/2300-2399/2382.Maximum Segment Sum After Removals/README_EN.md index 791f3dff0e62a..d2ac274684488 100644 --- a/solution/2300-2399/2382.Maximum Segment Sum After Removals/README_EN.md +++ b/solution/2300-2399/2382.Maximum Segment Sum After Removals/README_EN.md @@ -77,6 +77,8 @@ Finally, we return [16,5,3,0]. +#### Python3 + ```python class Solution: def maximumSegmentSum(self, nums: List[int], removeQueries: List[int]) -> List[int]: @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] p; @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -190,6 +196,8 @@ public: }; ``` +#### Go + ```go func maximumSegmentSum(nums []int, removeQueries []int) []int64 { n := len(nums) diff --git a/solution/2300-2399/2383.Minimum Hours of Training to Win a Competition/README.md b/solution/2300-2399/2383.Minimum Hours of Training to Win a Competition/README.md index 124890a807bd9..a335d1de4d8d8 100644 --- a/solution/2300-2399/2383.Minimum Hours of Training to Win a Competition/README.md +++ b/solution/2300-2399/2383.Minimum Hours of Training to Win a Competition/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def minNumberOfHours( @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minNumberOfHours( @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func minNumberOfHours(initialEnergy int, initialExperience int, energy []int, experience []int) int { ans := 0 @@ -172,6 +180,8 @@ func minNumberOfHours(initialEnergy int, initialExperience int, energy []int, ex } ``` +#### TypeScript + ```ts function minNumberOfHours( initialEnergy: number, @@ -201,6 +211,8 @@ function minNumberOfHours( } ``` +#### Rust + ```rust impl Solution { pub fn min_number_of_hours( @@ -228,6 +240,8 @@ impl Solution { } ``` +#### C + ```c int minNumberOfHours(int initialEnergy, int initialExperience, int* energy, int energySize, int* experience, int experienceSize) { int res = 0; @@ -265,6 +279,8 @@ int minNumberOfHours(int initialEnergy, int initialExperience, int* energy, int +#### Python3 + ```python class Solution: def minNumberOfHours( @@ -283,6 +299,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minNumberOfHours( @@ -304,6 +322,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -322,6 +342,8 @@ public: }; ``` +#### Go + ```go func minNumberOfHours(initialEnergy int, initialExperience int, energy []int, experience []int) (ans int) { s := 0 @@ -342,6 +364,8 @@ func minNumberOfHours(initialEnergy int, initialExperience int, energy []int, ex } ``` +#### TypeScript + ```ts function minNumberOfHours( initialEnergy: number, @@ -378,6 +402,8 @@ function minNumberOfHours( +#### TypeScript + ```ts function minNumberOfHours( initialEnergy: number, diff --git a/solution/2300-2399/2383.Minimum Hours of Training to Win a Competition/README_EN.md b/solution/2300-2399/2383.Minimum Hours of Training to Win a Competition/README_EN.md index 7c6e0375f6b5a..576d6682f1ab8 100644 --- a/solution/2300-2399/2383.Minimum Hours of Training to Win a Competition/README_EN.md +++ b/solution/2300-2399/2383.Minimum Hours of Training to Win a Competition/README_EN.md @@ -78,6 +78,8 @@ It can be proven that no smaller answer exists. +#### Python3 + ```python class Solution: def minNumberOfHours( @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minNumberOfHours( @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func minNumberOfHours(initialEnergy int, initialExperience int, energy []int, experience []int) int { ans := 0 @@ -166,6 +174,8 @@ func minNumberOfHours(initialEnergy int, initialExperience int, energy []int, ex } ``` +#### TypeScript + ```ts function minNumberOfHours( initialEnergy: number, @@ -195,6 +205,8 @@ function minNumberOfHours( } ``` +#### Rust + ```rust impl Solution { pub fn min_number_of_hours( @@ -222,6 +234,8 @@ impl Solution { } ``` +#### C + ```c int minNumberOfHours(int initialEnergy, int initialExperience, int* energy, int energySize, int* experience, int experienceSize) { int res = 0; @@ -251,6 +265,8 @@ int minNumberOfHours(int initialEnergy, int initialExperience, int* energy, int +#### Python3 + ```python class Solution: def minNumberOfHours( @@ -269,6 +285,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minNumberOfHours( @@ -290,6 +308,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -308,6 +328,8 @@ public: }; ``` +#### Go + ```go func minNumberOfHours(initialEnergy int, initialExperience int, energy []int, experience []int) (ans int) { s := 0 @@ -328,6 +350,8 @@ func minNumberOfHours(initialEnergy int, initialExperience int, energy []int, ex } ``` +#### TypeScript + ```ts function minNumberOfHours( initialEnergy: number, @@ -364,6 +388,8 @@ function minNumberOfHours( +#### TypeScript + ```ts function minNumberOfHours( initialEnergy: number, diff --git a/solution/2300-2399/2384.Largest Palindromic Number/README.md b/solution/2300-2399/2384.Largest Palindromic Number/README.md index b4b7f531dcb1a..27443e9a29295 100644 --- a/solution/2300-2399/2384.Largest Palindromic Number/README.md +++ b/solution/2300-2399/2384.Largest Palindromic Number/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def largestPalindromic(self, num: str) -> str: @@ -102,6 +104,8 @@ class Solution: return ans.strip('0') or '0' ``` +#### Java + ```java class Solution { public String largestPalindromic(String num) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func largestPalindromic(num string) string { cnt := make([]int, 10) @@ -197,6 +205,8 @@ func largestPalindromic(num string) string { } ``` +#### TypeScript + ```ts function largestPalindromic(num: string): string { const count = new Array(10).fill(0); diff --git a/solution/2300-2399/2384.Largest Palindromic Number/README_EN.md b/solution/2300-2399/2384.Largest Palindromic Number/README_EN.md index 4f967f6d879c5..3393a54cfb6b8 100644 --- a/solution/2300-2399/2384.Largest Palindromic Number/README_EN.md +++ b/solution/2300-2399/2384.Largest Palindromic Number/README_EN.md @@ -70,6 +70,8 @@ Note that the integer returned should not contain leading zeroes. +#### Python3 + ```python class Solution: def largestPalindromic(self, num: str) -> str: @@ -90,6 +92,8 @@ class Solution: return ans.strip('0') or '0' ``` +#### Java + ```java class Solution { public String largestPalindromic(String num) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func largestPalindromic(num string) string { cnt := make([]int, 10) @@ -185,6 +193,8 @@ func largestPalindromic(num string) string { } ``` +#### TypeScript + ```ts function largestPalindromic(num: string): string { const count = new Array(10).fill(0); diff --git a/solution/2300-2399/2385.Amount of Time for Binary Tree to Be Infected/README.md b/solution/2300-2399/2385.Amount of Time for Binary Tree to Be Infected/README.md index 66a0085afeeff..6e7b9df44cbc1 100644 --- a/solution/2300-2399/2385.Amount of Time for Binary Tree to Be Infected/README.md +++ b/solution/2300-2399/2385.Amount of Time for Binary Tree to Be Infected/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -112,6 +114,8 @@ class Solution: return dfs2(start, -1) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -202,6 +208,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -239,6 +247,8 @@ func amountOfTime(root *TreeNode, start int) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/2300-2399/2385.Amount of Time for Binary Tree to Be Infected/README_EN.md b/solution/2300-2399/2385.Amount of Time for Binary Tree to Be Infected/README_EN.md index 3527f829a1d16..0400041e3cb71 100644 --- a/solution/2300-2399/2385.Amount of Time for Binary Tree to Be Infected/README_EN.md +++ b/solution/2300-2399/2385.Amount of Time for Binary Tree to Be Infected/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -112,6 +114,8 @@ class Solution: return dfs2(start, -1) ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -202,6 +208,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -239,6 +247,8 @@ func amountOfTime(root *TreeNode, start int) int { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/2300-2399/2386.Find the K-Sum of an Array/README.md b/solution/2300-2399/2386.Find the K-Sum of an Array/README.md index c53d32dccddb0..3ec75c6778f57 100644 --- a/solution/2300-2399/2386.Find the K-Sum of an Array/README.md +++ b/solution/2300-2399/2386.Find the K-Sum of an Array/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def kSum(self, nums: List[int], k: int) -> int: @@ -103,6 +105,8 @@ class Solution: return mx - h[0][0] ``` +#### Java + ```java class Solution { public long kSum(int[] nums, int k) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go func kSum(nums []int, k int) int64 { mx := 0 diff --git a/solution/2300-2399/2386.Find the K-Sum of an Array/README_EN.md b/solution/2300-2399/2386.Find the K-Sum of an Array/README_EN.md index 4bfdab371a8ca..574d66089667f 100644 --- a/solution/2300-2399/2386.Find the K-Sum of an Array/README_EN.md +++ b/solution/2300-2399/2386.Find the K-Sum of an Array/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(n \times \log n + k \times \log k)$, where $n$ is the +#### Python3 + ```python class Solution: def kSum(self, nums: List[int], k: int) -> int: @@ -101,6 +103,8 @@ class Solution: return mx - h[0][0] ``` +#### Java + ```java class Solution { public long kSum(int[] nums, int k) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func kSum(nums []int, k int) int64 { mx := 0 diff --git a/solution/2300-2399/2387.Median of a Row Wise Sorted Matrix/README.md b/solution/2300-2399/2387.Median of a Row Wise Sorted Matrix/README.md index cb8bb41448f75..acb9b1a892f88 100644 --- a/solution/2300-2399/2387.Median of a Row Wise Sorted Matrix/README.md +++ b/solution/2300-2399/2387.Median of a Row Wise Sorted Matrix/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def matrixMedian(self, grid: List[List[int]]) -> int: @@ -80,6 +82,8 @@ class Solution: return bisect_left(range(10**6 + 1), target, key=count) ``` +#### Java + ```java class Solution { private int[][] grid; @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func matrixMedian(grid [][]int) int { m, n := len(grid), len(grid[0]) diff --git a/solution/2300-2399/2387.Median of a Row Wise Sorted Matrix/README_EN.md b/solution/2300-2399/2387.Median of a Row Wise Sorted Matrix/README_EN.md index 2450f2d2dcbe3..e07b08518e3ac 100644 --- a/solution/2300-2399/2387.Median of a Row Wise Sorted Matrix/README_EN.md +++ b/solution/2300-2399/2387.Median of a Row Wise Sorted Matrix/README_EN.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def matrixMedian(self, grid: List[List[int]]) -> int: @@ -72,6 +74,8 @@ class Solution: return bisect_left(range(10**6 + 1), target, key=count) ``` +#### Java + ```java class Solution { private int[][] grid; @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func matrixMedian(grid [][]int) int { m, n := len(grid), len(grid[0]) diff --git a/solution/2300-2399/2388.Change Null Values in a Table to the Previous Value/README.md b/solution/2300-2399/2388.Change Null Values in a Table to the Previous Value/README.md index 18ab650bcce42..07ac75cdf5964 100644 --- a/solution/2300-2399/2388.Change Null Values in a Table to the Previous Value/README.md +++ b/solution/2300-2399/2388.Change Null Values in a Table to the Previous Value/README.md @@ -84,6 +84,8 @@ CoffeeShop 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -107,6 +109,8 @@ FROM CoffeeShop; +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2300-2399/2388.Change Null Values in a Table to the Previous Value/README_EN.md b/solution/2300-2399/2388.Change Null Values in a Table to the Previous Value/README_EN.md index cac71987445aa..e21e0b9ea2e3d 100644 --- a/solution/2300-2399/2388.Change Null Values in a Table to the Previous Value/README_EN.md +++ b/solution/2300-2399/2388.Change Null Values in a Table to the Previous Value/README_EN.md @@ -81,6 +81,8 @@ Note that the rows in the output are the same as in the input. +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -102,6 +104,8 @@ FROM CoffeeShop; +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2300-2399/2389.Longest Subsequence With Limited Sum/README.md b/solution/2300-2399/2389.Longest Subsequence With Limited Sum/README.md index 252a69b8c16c4..27236e377d9ed 100644 --- a/solution/2300-2399/2389.Longest Subsequence With Limited Sum/README.md +++ b/solution/2300-2399/2389.Longest Subsequence With Limited Sum/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def answerQueries(self, nums: List[int], queries: List[int]) -> List[int]: @@ -83,6 +85,8 @@ class Solution: return [bisect_right(s, q) for q in queries] ``` +#### Java + ```java class Solution { public int[] answerQueries(int[] nums, int[] queries) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func answerQueries(nums []int, queries []int) (ans []int) { sort.Ints(nums) @@ -143,6 +151,8 @@ func answerQueries(nums []int, queries []int) (ans []int) { } ``` +#### TypeScript + ```ts function answerQueries(nums: number[], queries: number[]): number[] { nums.sort((a, b) => a - b); @@ -170,6 +180,8 @@ function answerQueries(nums: number[], queries: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn answer_queries(mut nums: Vec, queries: Vec) -> Vec { @@ -192,6 +204,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int[] AnswerQueries(int[] nums, int[] queries) { @@ -239,6 +253,8 @@ public class Solution { +#### Python3 + ```python class Solution: def answerQueries(self, nums: List[int], queries: List[int]) -> List[int]: @@ -255,6 +271,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] answerQueries(int[] nums, int[] queries) { @@ -278,6 +296,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -302,6 +322,8 @@ public: }; ``` +#### Go + ```go func answerQueries(nums []int, queries []int) (ans []int) { sort.Ints(nums) @@ -324,6 +346,8 @@ func answerQueries(nums []int, queries []int) (ans []int) { } ``` +#### TypeScript + ```ts function answerQueries(nums: number[], queries: number[]): number[] { nums.sort((a, b) => a - b); diff --git a/solution/2300-2399/2389.Longest Subsequence With Limited Sum/README_EN.md b/solution/2300-2399/2389.Longest Subsequence With Limited Sum/README_EN.md index fc0eab40c2dac..88f10ae3083fe 100644 --- a/solution/2300-2399/2389.Longest Subsequence With Limited Sum/README_EN.md +++ b/solution/2300-2399/2389.Longest Subsequence With Limited Sum/README_EN.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def answerQueries(self, nums: List[int], queries: List[int]) -> List[int]: @@ -75,6 +77,8 @@ class Solution: return [bisect_right(s, q) for q in queries] ``` +#### Java + ```java class Solution { public int[] answerQueries(int[] nums, int[] queries) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func answerQueries(nums []int, queries []int) (ans []int) { sort.Ints(nums) @@ -135,6 +143,8 @@ func answerQueries(nums []int, queries []int) (ans []int) { } ``` +#### TypeScript + ```ts function answerQueries(nums: number[], queries: number[]): number[] { nums.sort((a, b) => a - b); @@ -162,6 +172,8 @@ function answerQueries(nums: number[], queries: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn answer_queries(mut nums: Vec, queries: Vec) -> Vec { @@ -184,6 +196,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int[] AnswerQueries(int[] nums, int[] queries) { @@ -219,6 +233,8 @@ public class Solution { +#### Python3 + ```python class Solution: def answerQueries(self, nums: List[int], queries: List[int]) -> List[int]: @@ -235,6 +251,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] answerQueries(int[] nums, int[] queries) { @@ -258,6 +276,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -282,6 +302,8 @@ public: }; ``` +#### Go + ```go func answerQueries(nums []int, queries []int) (ans []int) { sort.Ints(nums) @@ -304,6 +326,8 @@ func answerQueries(nums []int, queries []int) (ans []int) { } ``` +#### TypeScript + ```ts function answerQueries(nums: number[], queries: number[]): number[] { nums.sort((a, b) => a - b); diff --git a/solution/2300-2399/2390.Removing Stars From a String/README.md b/solution/2300-2399/2390.Removing Stars From a String/README.md index 090acc48d1959..05ae99299fe41 100644 --- a/solution/2300-2399/2390.Removing Stars From a String/README.md +++ b/solution/2300-2399/2390.Removing Stars From a String/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def removeStars(self, s: str) -> str: @@ -97,6 +99,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String removeStars(String s) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func removeStars(s string) string { ans := []rune{} @@ -144,6 +152,8 @@ func removeStars(s string) string { } ``` +#### TypeScript + ```ts function removeStars(s: string): string { const ans: string[] = []; @@ -158,6 +168,8 @@ function removeStars(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn remove_stars(s: String) -> String { @@ -174,6 +186,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/2300-2399/2390.Removing Stars From a String/README_EN.md b/solution/2300-2399/2390.Removing Stars From a String/README_EN.md index 95be7a5359854..5d41a59b88995 100644 --- a/solution/2300-2399/2390.Removing Stars From a String/README_EN.md +++ b/solution/2300-2399/2390.Removing Stars From a String/README_EN.md @@ -77,6 +77,8 @@ There are no more stars, so we return "lecoe". +#### Python3 + ```python class Solution: def removeStars(self, s: str) -> str: @@ -89,6 +91,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String removeStars(String s) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func removeStars(s string) string { ans := []rune{} @@ -136,6 +144,8 @@ func removeStars(s string) string { } ``` +#### TypeScript + ```ts function removeStars(s: string): string { const ans: string[] = []; @@ -150,6 +160,8 @@ function removeStars(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn remove_stars(s: String) -> String { @@ -166,6 +178,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/2300-2399/2391.Minimum Amount of Time to Collect Garbage/README.md b/solution/2300-2399/2391.Minimum Amount of Time to Collect Garbage/README.md index 35060330d72c5..540904b95e0cc 100644 --- a/solution/2300-2399/2391.Minimum Amount of Time to Collect Garbage/README.md +++ b/solution/2300-2399/2391.Minimum Amount of Time to Collect Garbage/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class Solution: def garbageCollection(self, garbage: List[str], travel: List[int]) -> int: @@ -110,6 +112,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int garbageCollection(String[] garbage, int[] travel) { @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func garbageCollection(garbage []string, travel []int) (ans int) { last := map[byte]int{} @@ -185,6 +193,8 @@ func garbageCollection(garbage []string, travel []int) (ans int) { } ``` +#### TypeScript + ```ts function garbageCollection(garbage: string[], travel: number[]): number { const last: Map = new Map(); @@ -209,6 +219,8 @@ function garbageCollection(garbage: string[], travel: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -236,6 +248,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int GarbageCollection(string[] garbage, int[] travel) { diff --git a/solution/2300-2399/2391.Minimum Amount of Time to Collect Garbage/README_EN.md b/solution/2300-2399/2391.Minimum Amount of Time to Collect Garbage/README_EN.md index 281f4dc3ed2dc..4c6400d0066e5 100644 --- a/solution/2300-2399/2391.Minimum Amount of Time to Collect Garbage/README_EN.md +++ b/solution/2300-2399/2391.Minimum Amount of Time to Collect Garbage/README_EN.md @@ -94,6 +94,8 @@ The time complexity is $O(n)$, and the space complexity is $O(k)$, where $n$ and +#### Python3 + ```python class Solution: def garbageCollection(self, garbage: List[str], travel: List[int]) -> int: @@ -110,6 +112,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int garbageCollection(String[] garbage, int[] travel) { @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func garbageCollection(garbage []string, travel []int) (ans int) { last := map[byte]int{} @@ -185,6 +193,8 @@ func garbageCollection(garbage []string, travel []int) (ans int) { } ``` +#### TypeScript + ```ts function garbageCollection(garbage: string[], travel: number[]): number { const last: Map = new Map(); @@ -209,6 +219,8 @@ function garbageCollection(garbage: string[], travel: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -236,6 +248,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int GarbageCollection(string[] garbage, int[] travel) { diff --git a/solution/2300-2399/2392.Build a Matrix With Conditions/README.md b/solution/2300-2399/2392.Build a Matrix With Conditions/README.md index f6bb1bdb1cba6..4f6de36542338 100644 --- a/solution/2300-2399/2392.Build a Matrix With Conditions/README.md +++ b/solution/2300-2399/2392.Build a Matrix With Conditions/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class Solution: def buildMatrix( @@ -130,6 +132,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int k; @@ -184,6 +188,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -237,6 +243,8 @@ public: }; ``` +#### Go + ```go func buildMatrix(k int, rowConditions [][]int, colConditions [][]int) [][]int { f := func(cond [][]int) []int { @@ -293,6 +301,8 @@ func buildMatrix(k int, rowConditions [][]int, colConditions [][]int) [][]int { } ``` +#### TypeScript + ```ts function buildMatrix(k: number, rowConditions: number[][], colConditions: number[][]): number[][] { function f(cond) { diff --git a/solution/2300-2399/2392.Build a Matrix With Conditions/README_EN.md b/solution/2300-2399/2392.Build a Matrix With Conditions/README_EN.md index dd41889e5aadf..158223d44e66a 100644 --- a/solution/2300-2399/2392.Build a Matrix With Conditions/README_EN.md +++ b/solution/2300-2399/2392.Build a Matrix With Conditions/README_EN.md @@ -88,6 +88,8 @@ No matrix can satisfy all the conditions, so we return the empty matrix. +#### Python3 + ```python class Solution: def buildMatrix( @@ -124,6 +126,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int k; @@ -178,6 +182,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -231,6 +237,8 @@ public: }; ``` +#### Go + ```go func buildMatrix(k int, rowConditions [][]int, colConditions [][]int) [][]int { f := func(cond [][]int) []int { @@ -287,6 +295,8 @@ func buildMatrix(k int, rowConditions [][]int, colConditions [][]int) [][]int { } ``` +#### TypeScript + ```ts function buildMatrix(k: number, rowConditions: number[][], colConditions: number[][]): number[][] { function f(cond) { diff --git a/solution/2300-2399/2393.Count Strictly Increasing Subarrays/README.md b/solution/2300-2399/2393.Count Strictly Increasing Subarrays/README.md index 4ea0df440826d..4f453f8618363 100644 --- a/solution/2300-2399/2393.Count Strictly Increasing Subarrays/README.md +++ b/solution/2300-2399/2393.Count Strictly Increasing Subarrays/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def countSubarrays(self, nums: List[int]) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long countSubarrays(int[] nums) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func countSubarrays(nums []int) int64 { ans := 0 @@ -139,6 +147,8 @@ func countSubarrays(nums []int) int64 { } ``` +#### TypeScript + ```ts function countSubarrays(nums: number[]): number { let ans = 0; @@ -171,6 +181,8 @@ function countSubarrays(nums: number[]): number { +#### Python3 + ```python class Solution: def countSubarrays(self, nums: List[int]) -> int: @@ -185,6 +197,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long countSubarrays(int[] nums) { @@ -204,6 +218,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -224,6 +240,8 @@ public: }; ``` +#### Go + ```go func countSubarrays(nums []int) (ans int64) { pre, cnt := 0, 0 @@ -240,6 +258,8 @@ func countSubarrays(nums []int) (ans int64) { } ``` +#### TypeScript + ```ts function countSubarrays(nums: number[]): number { let ans = 0; diff --git a/solution/2300-2399/2393.Count Strictly Increasing Subarrays/README_EN.md b/solution/2300-2399/2393.Count Strictly Increasing Subarrays/README_EN.md index 733054ad98756..8b6f0b499d300 100644 --- a/solution/2300-2399/2393.Count Strictly Increasing Subarrays/README_EN.md +++ b/solution/2300-2399/2393.Count Strictly Increasing Subarrays/README_EN.md @@ -63,6 +63,8 @@ The total number of subarrays is 6 + 3 + 1 = 10. +#### Python3 + ```python class Solution: def countSubarrays(self, nums: List[int]) -> int: @@ -77,6 +79,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long countSubarrays(int[] nums) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func countSubarrays(nums []int) int64 { ans := 0 @@ -133,6 +141,8 @@ func countSubarrays(nums []int) int64 { } ``` +#### TypeScript + ```ts function countSubarrays(nums: number[]): number { let ans = 0; @@ -161,6 +171,8 @@ function countSubarrays(nums: number[]): number { +#### Python3 + ```python class Solution: def countSubarrays(self, nums: List[int]) -> int: @@ -175,6 +187,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long countSubarrays(int[] nums) { @@ -194,6 +208,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -214,6 +230,8 @@ public: }; ``` +#### Go + ```go func countSubarrays(nums []int) (ans int64) { pre, cnt := 0, 0 @@ -230,6 +248,8 @@ func countSubarrays(nums []int) (ans int64) { } ``` +#### TypeScript + ```ts function countSubarrays(nums: number[]): number { let ans = 0; diff --git a/solution/2300-2399/2394.Employees With Deductions/README.md b/solution/2300-2399/2394.Employees With Deductions/README.md index 5821545bcf1a4..7525966c96a2b 100644 --- a/solution/2300-2399/2394.Employees With Deductions/README.md +++ b/solution/2300-2399/2394.Employees With Deductions/README.md @@ -116,6 +116,8 @@ Logs 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2300-2399/2394.Employees With Deductions/README_EN.md b/solution/2300-2399/2394.Employees With Deductions/README_EN.md index 7f47623c20138..b54de57ef34ba 100644 --- a/solution/2300-2399/2394.Employees With Deductions/README_EN.md +++ b/solution/2300-2399/2394.Employees With Deductions/README_EN.md @@ -115,6 +115,8 @@ Employee 3: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2300-2399/2395.Find Subarrays With Equal Sum/README.md b/solution/2300-2399/2395.Find Subarrays With Equal Sum/README.md index 4822683e38614..2b656593e0add 100644 --- a/solution/2300-2399/2395.Find Subarrays With Equal Sum/README.md +++ b/solution/2300-2399/2395.Find Subarrays With Equal Sum/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def findSubarrays(self, nums: List[int]) -> bool: @@ -85,6 +87,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean findSubarrays(int[] nums) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func findSubarrays(nums []int) bool { vis := map[int]bool{} @@ -130,6 +138,8 @@ func findSubarrays(nums []int) bool { } ``` +#### TypeScript + ```ts function findSubarrays(nums: number[]): boolean { const vis: Set = new Set(); @@ -144,6 +154,8 @@ function findSubarrays(nums: number[]): boolean { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -160,6 +172,8 @@ impl Solution { } ``` +#### C + ```c bool findSubarrays(int* nums, int numsSize) { for (int i = 1; i < numsSize - 1; i++) { diff --git a/solution/2300-2399/2395.Find Subarrays With Equal Sum/README_EN.md b/solution/2300-2399/2395.Find Subarrays With Equal Sum/README_EN.md index 813c89dfebd3f..2f973bb1e7564 100644 --- a/solution/2300-2399/2395.Find Subarrays With Equal Sum/README_EN.md +++ b/solution/2300-2399/2395.Find Subarrays With Equal Sum/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python class Solution: def findSubarrays(self, nums: List[int]) -> bool: @@ -86,6 +88,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean findSubarrays(int[] nums) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func findSubarrays(nums []int) bool { vis := map[int]bool{} @@ -131,6 +139,8 @@ func findSubarrays(nums []int) bool { } ``` +#### TypeScript + ```ts function findSubarrays(nums: number[]): boolean { const vis: Set = new Set(); @@ -145,6 +155,8 @@ function findSubarrays(nums: number[]): boolean { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -161,6 +173,8 @@ impl Solution { } ``` +#### C + ```c bool findSubarrays(int* nums, int numsSize) { for (int i = 1; i < numsSize - 1; i++) { diff --git a/solution/2300-2399/2396.Strictly Palindromic Number/README.md b/solution/2300-2399/2396.Strictly Palindromic Number/README.md index 8cf0fb00cf911..b1233e71a1742 100644 --- a/solution/2300-2399/2396.Strictly Palindromic Number/README.md +++ b/solution/2300-2399/2396.Strictly Palindromic Number/README.md @@ -72,12 +72,16 @@ tags: +#### Python3 + ```python class Solution: def isStrictlyPalindromic(self, n: int) -> bool: return False ``` +#### Java + ```java class Solution { public boolean isStrictlyPalindromic(int n) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -95,18 +101,24 @@ public: }; ``` +#### Go + ```go func isStrictlyPalindromic(n int) bool { return false } ``` +#### TypeScript + ```ts function isStrictlyPalindromic(n: number): boolean { return false; } ``` +#### Rust + ```rust impl Solution { pub fn is_strictly_palindromic(n: i32) -> bool { @@ -115,6 +127,8 @@ impl Solution { } ``` +#### C + ```c bool isStrictlyPalindromic(int n) { return 0; diff --git a/solution/2300-2399/2396.Strictly Palindromic Number/README_EN.md b/solution/2300-2399/2396.Strictly Palindromic Number/README_EN.md index 26f404889eb9a..9834d8dc4ff1e 100644 --- a/solution/2300-2399/2396.Strictly Palindromic Number/README_EN.md +++ b/solution/2300-2399/2396.Strictly Palindromic Number/README_EN.md @@ -73,12 +73,16 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def isStrictlyPalindromic(self, n: int) -> bool: return False ``` +#### Java + ```java class Solution { public boolean isStrictlyPalindromic(int n) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -96,18 +102,24 @@ public: }; ``` +#### Go + ```go func isStrictlyPalindromic(n int) bool { return false } ``` +#### TypeScript + ```ts function isStrictlyPalindromic(n: number): boolean { return false; } ``` +#### Rust + ```rust impl Solution { pub fn is_strictly_palindromic(n: i32) -> bool { @@ -116,6 +128,8 @@ impl Solution { } ``` +#### C + ```c bool isStrictlyPalindromic(int n) { return 0; diff --git a/solution/2300-2399/2397.Maximum Rows Covered by Columns/README.md b/solution/2300-2399/2397.Maximum Rows Covered by Columns/README.md index 73a3e10c27f15..0ae5abe9be164 100644 --- a/solution/2300-2399/2397.Maximum Rows Covered by Columns/README.md +++ b/solution/2300-2399/2397.Maximum Rows Covered by Columns/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class Solution: def maximumRows(self, matrix: List[List[int]], numSelect: int) -> int: @@ -113,6 +115,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumRows(int[][] matrix, int numSelect) { @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go func maximumRows(matrix [][]int, numSelect int) (ans int) { m, n := len(matrix), len(matrix[0]) @@ -202,6 +210,8 @@ func maximumRows(matrix [][]int, numSelect int) (ans int) { } ``` +#### TypeScript + ```ts function maximumRows(matrix: number[][], numSelect: number): number { const [m, n] = [matrix.length, matrix[0].length]; diff --git a/solution/2300-2399/2397.Maximum Rows Covered by Columns/README_EN.md b/solution/2300-2399/2397.Maximum Rows Covered by Columns/README_EN.md index fab4dcdfd1e42..082f5951418e2 100644 --- a/solution/2300-2399/2397.Maximum Rows Covered by Columns/README_EN.md +++ b/solution/2300-2399/2397.Maximum Rows Covered by Columns/README_EN.md @@ -87,6 +87,8 @@ The time complexity is $O(2^n \times m)$, and the space complexity is $O(m)$. Wh +#### Python3 + ```python class Solution: def maximumRows(self, matrix: List[List[int]], numSelect: int) -> int: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumRows(int[][] matrix, int numSelect) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func maximumRows(matrix [][]int, numSelect int) (ans int) { m, n := len(matrix), len(matrix[0]) @@ -193,6 +201,8 @@ func maximumRows(matrix [][]int, numSelect int) (ans int) { } ``` +#### TypeScript + ```ts function maximumRows(matrix: number[][], numSelect: number): number { const [m, n] = [matrix.length, matrix[0].length]; diff --git a/solution/2300-2399/2398.Maximum Number of Robots Within Budget/README.md b/solution/2300-2399/2398.Maximum Number of Robots Within Budget/README.md index 7dbc97fb6d3a4..6358298483bda 100644 --- a/solution/2300-2399/2398.Maximum Number of Robots Within Budget/README.md +++ b/solution/2300-2399/2398.Maximum Number of Robots Within Budget/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def maximumRobots( @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumRobots(int[] chargeTimes, int[] runningCosts, long budget) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func maximumRobots(chargeTimes []int, runningCosts []int, budget int64) int { s := int64(0) diff --git a/solution/2300-2399/2398.Maximum Number of Robots Within Budget/README_EN.md b/solution/2300-2399/2398.Maximum Number of Robots Within Budget/README_EN.md index 5ef10c59ccd6f..56b1fcb9007b6 100644 --- a/solution/2300-2399/2398.Maximum Number of Robots Within Budget/README_EN.md +++ b/solution/2300-2399/2398.Maximum Number of Robots Within Budget/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python class Solution: def maximumRobots( @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumRobots(int[] chargeTimes, int[] runningCosts, long budget) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func maximumRobots(chargeTimes []int, runningCosts []int, budget int64) int { s := int64(0) diff --git a/solution/2300-2399/2399.Check Distances Between Same Letters/README.md b/solution/2300-2399/2399.Check Distances Between Same Letters/README.md index 1fb239b11c72f..0b9c220b70ecd 100644 --- a/solution/2300-2399/2399.Check Distances Between Same Letters/README.md +++ b/solution/2300-2399/2399.Check Distances Between Same Letters/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def checkDistances(self, s: str, distance: List[int]) -> bool: @@ -88,6 +90,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean checkDistances(String s, int[] distance) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func checkDistances(s string, distance []int) bool { d := [26]int{} @@ -135,6 +143,8 @@ func checkDistances(s string, distance []int) bool { } ``` +#### TypeScript + ```ts function checkDistances(s: string, distance: number[]): boolean { const n = s.length; @@ -150,6 +160,8 @@ function checkDistances(s: string, distance: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn check_distances(s: String, distance: Vec) -> bool { @@ -169,6 +181,8 @@ impl Solution { } ``` +#### C + ```c bool checkDistances(char* s, int* distance, int distanceSize) { int n = strlen(s); diff --git a/solution/2300-2399/2399.Check Distances Between Same Letters/README_EN.md b/solution/2300-2399/2399.Check Distances Between Same Letters/README_EN.md index 60c99b52489bc..3600ab493dfd1 100644 --- a/solution/2300-2399/2399.Check Distances Between Same Letters/README_EN.md +++ b/solution/2300-2399/2399.Check Distances Between Same Letters/README_EN.md @@ -73,6 +73,8 @@ Because distance[0] = 1, s is not a well-spaced string. +#### Python3 + ```python class Solution: def checkDistances(self, s: str, distance: List[int]) -> bool: @@ -84,6 +86,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean checkDistances(String s, int[] distance) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func checkDistances(s string, distance []int) bool { d := [26]int{} @@ -131,6 +139,8 @@ func checkDistances(s string, distance []int) bool { } ``` +#### TypeScript + ```ts function checkDistances(s: string, distance: number[]): boolean { const n = s.length; @@ -146,6 +156,8 @@ function checkDistances(s: string, distance: number[]): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn check_distances(s: String, distance: Vec) -> bool { @@ -165,6 +177,8 @@ impl Solution { } ``` +#### C + ```c bool checkDistances(char* s, int* distance, int distanceSize) { int n = strlen(s); diff --git a/solution/2400-2499/2400.Number of Ways to Reach a Position After Exactly k Steps/README.md b/solution/2400-2499/2400.Number of Ways to Reach a Position After Exactly k Steps/README.md index 535374aeea307..138b294bcc774 100644 --- a/solution/2400-2499/2400.Number of Ways to Reach a Position After Exactly k Steps/README.md +++ b/solution/2400-2499/2400.Number of Ways to Reach a Position After Exactly k Steps/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfWays(self, startPos: int, endPos: int, k: int) -> int: @@ -94,6 +96,8 @@ class Solution: return dfs(abs(startPos - endPos), k) ``` +#### Java + ```java class Solution { private Integer[][] f; @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func numberOfWays(startPos int, endPos int, k int) int { const mod = 1e9 + 7 @@ -184,6 +192,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function numberOfWays(startPos: number, endPos: number, k: number): number { const mod = 10 ** 9 + 7; diff --git a/solution/2400-2499/2400.Number of Ways to Reach a Position After Exactly k Steps/README_EN.md b/solution/2400-2499/2400.Number of Ways to Reach a Position After Exactly k Steps/README_EN.md index e7763c892c76a..a3b5c0f5db4c0 100644 --- a/solution/2400-2499/2400.Number of Ways to Reach a Position After Exactly k Steps/README_EN.md +++ b/solution/2400-2499/2400.Number of Ways to Reach a Position After Exactly k Steps/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(k^2)$, and the space complexity is $O(k^2)$. Here, $k$ +#### Python3 + ```python class Solution: def numberOfWays(self, startPos: int, endPos: int, k: int) -> int: @@ -95,6 +97,8 @@ class Solution: return dfs(abs(startPos - endPos), k) ``` +#### Java + ```java class Solution { private Integer[][] f; @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func numberOfWays(startPos int, endPos int, k int) int { const mod = 1e9 + 7 @@ -185,6 +193,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function numberOfWays(startPos: number, endPos: number, k: number): number { const mod = 10 ** 9 + 7; diff --git a/solution/2400-2499/2401.Longest Nice Subarray/README.md b/solution/2400-2499/2401.Longest Nice Subarray/README.md index d2d4cb84bb8dc..e867a761f5f2f 100644 --- a/solution/2400-2499/2401.Longest Nice Subarray/README.md +++ b/solution/2400-2499/2401.Longest Nice Subarray/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def longestNiceSubarray(self, nums: List[int]) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestNiceSubarray(int[] nums) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func longestNiceSubarray(nums []int) (ans int) { mask, j := 0, 0 @@ -144,6 +152,8 @@ func longestNiceSubarray(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function longestNiceSubarray(nums: number[]): number { let mask = 0; @@ -159,6 +169,8 @@ function longestNiceSubarray(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn longest_nice_subarray(nums: Vec) -> i32 { @@ -181,6 +193,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int LongestNiceSubarray(int[] nums) { diff --git a/solution/2400-2499/2401.Longest Nice Subarray/README_EN.md b/solution/2400-2499/2401.Longest Nice Subarray/README_EN.md index b8a4d375ec068..78a33fed5a1d4 100644 --- a/solution/2400-2499/2401.Longest Nice Subarray/README_EN.md +++ b/solution/2400-2499/2401.Longest Nice Subarray/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is +#### Python3 + ```python class Solution: def longestNiceSubarray(self, nums: List[int]) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestNiceSubarray(int[] nums) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func longestNiceSubarray(nums []int) (ans int) { mask, j := 0, 0 @@ -144,6 +152,8 @@ func longestNiceSubarray(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function longestNiceSubarray(nums: number[]): number { let mask = 0; @@ -159,6 +169,8 @@ function longestNiceSubarray(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn longest_nice_subarray(nums: Vec) -> i32 { @@ -181,6 +193,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int LongestNiceSubarray(int[] nums) { diff --git a/solution/2400-2499/2402.Meeting Rooms III/README.md b/solution/2400-2499/2402.Meeting Rooms III/README.md index 2bc7ae6bd05e9..b3c4d9b13ccc1 100644 --- a/solution/2400-2499/2402.Meeting Rooms III/README.md +++ b/solution/2400-2499/2402.Meeting Rooms III/README.md @@ -105,6 +105,8 @@ tags: +#### Python3 + ```python class Solution: def mostBooked(self, n: int, meetings: List[List[int]]) -> int: @@ -131,6 +133,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int mostBooked(int n, int[][] meetings) { @@ -169,6 +173,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; using pii = pair; @@ -211,6 +217,8 @@ public: }; ``` +#### Go + ```go func mostBooked(n int, meetings [][]int) int { sort.Slice(meetings, func(i, j int) bool { return meetings[i][0] < meetings[j][0] }) diff --git a/solution/2400-2499/2402.Meeting Rooms III/README_EN.md b/solution/2400-2499/2402.Meeting Rooms III/README_EN.md index 32a4492087999..0af3a2d96dc3f 100644 --- a/solution/2400-2499/2402.Meeting Rooms III/README_EN.md +++ b/solution/2400-2499/2402.Meeting Rooms III/README_EN.md @@ -105,6 +105,8 @@ Similar problems: +#### Python3 + ```python class Solution: def mostBooked(self, n: int, meetings: List[List[int]]) -> int: @@ -131,6 +133,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int mostBooked(int n, int[][] meetings) { @@ -169,6 +173,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; using pii = pair; @@ -211,6 +217,8 @@ public: }; ``` +#### Go + ```go func mostBooked(n int, meetings [][]int) int { sort.Slice(meetings, func(i, j int) bool { return meetings[i][0] < meetings[j][0] }) diff --git a/solution/2400-2499/2403.Minimum Time to Kill All Monsters/README.md b/solution/2400-2499/2403.Minimum Time to Kill All Monsters/README.md index a80148c2ced91..3c24e0e78b8ea 100644 --- a/solution/2400-2499/2403.Minimum Time to Kill All Monsters/README.md +++ b/solution/2400-2499/2403.Minimum Time to Kill All Monsters/README.md @@ -104,6 +104,8 @@ tags: +#### Python3 + ```python class Solution: def minimumTime(self, power: List[int]) -> int: @@ -122,6 +124,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private int n; @@ -157,6 +161,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go func minimumTime(power []int) int64 { n := len(power) @@ -218,6 +226,8 @@ func minimumTime(power []int) int64 { } ``` +#### TypeScript + ```ts function minimumTime(power: number[]): number { const n = power.length; @@ -264,6 +274,8 @@ function bitCount(x) { +#### Python3 + ```python class Solution: def minimumTime(self, power: List[int]) -> int: @@ -278,6 +290,8 @@ class Solution: return dp[-1] ``` +#### Java + ```java class Solution { public long minimumTime(int[] power) { @@ -298,6 +312,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -318,6 +334,8 @@ public: }; ``` +#### Go + ```go func minimumTime(power []int) int64 { n := len(power) @@ -338,6 +356,8 @@ func minimumTime(power []int) int64 { } ``` +#### TypeScript + ```ts function minimumTime(power: number[]): number { const n = power.length; diff --git a/solution/2400-2499/2403.Minimum Time to Kill All Monsters/README_EN.md b/solution/2400-2499/2403.Minimum Time to Kill All Monsters/README_EN.md index e07d32f4ac79e..0bef7e39c7188 100644 --- a/solution/2400-2499/2403.Minimum Time to Kill All Monsters/README_EN.md +++ b/solution/2400-2499/2403.Minimum Time to Kill All Monsters/README_EN.md @@ -98,6 +98,8 @@ The time complexity is $O(n \times 2^n)$, and the space complexity is $O(2^n)$. +#### Python3 + ```python class Solution: def minimumTime(self, power: List[int]) -> int: @@ -116,6 +118,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private int n; @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -182,6 +188,8 @@ public: }; ``` +#### Go + ```go func minimumTime(power []int) int64 { n := len(power) @@ -212,6 +220,8 @@ func minimumTime(power []int) int64 { } ``` +#### TypeScript + ```ts function minimumTime(power: number[]): number { const n = power.length; @@ -258,6 +268,8 @@ function bitCount(x) { +#### Python3 + ```python class Solution: def minimumTime(self, power: List[int]) -> int: @@ -272,6 +284,8 @@ class Solution: return dp[-1] ``` +#### Java + ```java class Solution { public long minimumTime(int[] power) { @@ -292,6 +306,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -312,6 +328,8 @@ public: }; ``` +#### Go + ```go func minimumTime(power []int) int64 { n := len(power) @@ -332,6 +350,8 @@ func minimumTime(power []int) int64 { } ``` +#### TypeScript + ```ts function minimumTime(power: number[]): number { const n = power.length; diff --git a/solution/2400-2499/2404.Most Frequent Even Element/README.md b/solution/2400-2499/2404.Most Frequent Even Element/README.md index 154b14064792e..6c76d8ae47f91 100644 --- a/solution/2400-2499/2404.Most Frequent Even Element/README.md +++ b/solution/2400-2499/2404.Most Frequent Even Element/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def mostFrequentEven(self, nums: List[int]) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int mostFrequentEven(int[] nums) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func mostFrequentEven(nums []int) int { cnt := map[int]int{} @@ -144,6 +152,8 @@ func mostFrequentEven(nums []int) int { } ``` +#### TypeScript + ```ts function mostFrequentEven(nums: number[]): number { const cnt: Map = new Map(); @@ -164,6 +174,8 @@ function mostFrequentEven(nums: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { @@ -187,6 +199,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/2400-2499/2404.Most Frequent Even Element/README_EN.md b/solution/2400-2499/2404.Most Frequent Even Element/README_EN.md index 2f8ddf42b832b..79acd66454607 100644 --- a/solution/2400-2499/2404.Most Frequent Even Element/README_EN.md +++ b/solution/2400-2499/2404.Most Frequent Even Element/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def mostFrequentEven(self, nums: List[int]) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int mostFrequentEven(int[] nums) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func mostFrequentEven(nums []int) int { cnt := map[int]int{} @@ -145,6 +153,8 @@ func mostFrequentEven(nums []int) int { } ``` +#### TypeScript + ```ts function mostFrequentEven(nums: number[]): number { const cnt: Map = new Map(); @@ -165,6 +175,8 @@ function mostFrequentEven(nums: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { @@ -188,6 +200,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/2400-2499/2405.Optimal Partition of String/README.md b/solution/2400-2499/2405.Optimal Partition of String/README.md index d2c047b94f46e..e847070b034e3 100644 --- a/solution/2400-2499/2405.Optimal Partition of String/README.md +++ b/solution/2400-2499/2405.Optimal Partition of String/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def partitionString(self, s: str) -> int: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int partitionString(String s) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func partitionString(s string) int { ss := map[rune]bool{} @@ -135,6 +143,8 @@ func partitionString(s string) int { } ``` +#### TypeScript + ```ts function partitionString(s: string): number { const set = new Set(); @@ -150,6 +160,8 @@ function partitionString(s: string): number { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -178,6 +190,8 @@ impl Solution { +#### Python3 + ```python class Solution: def partitionString(self, s: str) -> int: @@ -191,6 +205,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int partitionString(String s) { @@ -209,6 +225,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -228,6 +246,8 @@ public: }; ``` +#### Go + ```go func partitionString(s string) int { ans, v := 1, 0 diff --git a/solution/2400-2499/2405.Optimal Partition of String/README_EN.md b/solution/2400-2499/2405.Optimal Partition of String/README_EN.md index a2eec3b05c5fd..196a381d382cc 100644 --- a/solution/2400-2499/2405.Optimal Partition of String/README_EN.md +++ b/solution/2400-2499/2405.Optimal Partition of String/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string $s$. +#### Python3 + ```python class Solution: def partitionString(self, s: str) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int partitionString(String s) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func partitionString(s string) int { ss := map[rune]bool{} @@ -133,6 +141,8 @@ func partitionString(s string) int { } ``` +#### TypeScript + ```ts function partitionString(s: string): number { const set = new Set(); @@ -148,6 +158,8 @@ function partitionString(s: string): number { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -176,6 +188,8 @@ impl Solution { +#### Python3 + ```python class Solution: def partitionString(self, s: str) -> int: @@ -189,6 +203,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int partitionString(String s) { @@ -207,6 +223,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -226,6 +244,8 @@ public: }; ``` +#### Go + ```go func partitionString(s string) int { ans, v := 1, 0 diff --git a/solution/2400-2499/2406.Divide Intervals Into Minimum Number of Groups/README.md b/solution/2400-2499/2406.Divide Intervals Into Minimum Number of Groups/README.md index 5b6a71784a03a..92287a026edc2 100644 --- a/solution/2400-2499/2406.Divide Intervals Into Minimum Number of Groups/README.md +++ b/solution/2400-2499/2406.Divide Intervals Into Minimum Number of Groups/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def minGroups(self, intervals: List[List[int]]) -> int: @@ -92,6 +94,8 @@ class Solution: return len(q) ``` +#### Java + ```java class Solution { public int minGroups(int[][] intervals) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func minGroups(intervals [][]int) int { sort.Slice(intervals, func(i, j int) bool { return intervals[i][0] < intervals[j][0] }) @@ -149,6 +157,8 @@ func (h *hp) Pop() any { } ``` +#### TypeScript + ```ts function minGroups(intervals: number[][]): number { intervals.sort((a, b) => a[0] - b[0]); diff --git a/solution/2400-2499/2406.Divide Intervals Into Minimum Number of Groups/README_EN.md b/solution/2400-2499/2406.Divide Intervals Into Minimum Number of Groups/README_EN.md index 03d016f662994..a99b2128d0987 100644 --- a/solution/2400-2499/2406.Divide Intervals Into Minimum Number of Groups/README_EN.md +++ b/solution/2400-2499/2406.Divide Intervals Into Minimum Number of Groups/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def minGroups(self, intervals: List[List[int]]) -> int: @@ -91,6 +93,8 @@ class Solution: return len(q) ``` +#### Java + ```java class Solution { public int minGroups(int[][] intervals) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func minGroups(intervals [][]int) int { sort.Slice(intervals, func(i, j int) bool { return intervals[i][0] < intervals[j][0] }) @@ -148,6 +156,8 @@ func (h *hp) Pop() any { } ``` +#### TypeScript + ```ts function minGroups(intervals: number[][]): number { intervals.sort((a, b) => a[0] - b[0]); diff --git a/solution/2400-2499/2407.Longest Increasing Subsequence II/README.md b/solution/2400-2499/2407.Longest Increasing Subsequence II/README.md index cecc85a44d631..02c5d42d6cb63 100644 --- a/solution/2400-2499/2407.Longest Increasing Subsequence II/README.md +++ b/solution/2400-2499/2407.Longest Increasing Subsequence II/README.md @@ -103,6 +103,8 @@ tags: +#### Python3 + ```python class Node: def __init__(self): @@ -162,6 +164,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int lengthOfLIS(int[] nums, int k) { @@ -243,6 +247,8 @@ class SegmentTree { } ``` +#### C++ + ```cpp class Node { public: @@ -312,6 +318,8 @@ public: }; ``` +#### Go + ```go func lengthOfLIS(nums []int, k int) int { mx := slices.Max(nums) diff --git a/solution/2400-2499/2407.Longest Increasing Subsequence II/README_EN.md b/solution/2400-2499/2407.Longest Increasing Subsequence II/README_EN.md index efc0690af3f5c..50fed9b5f75d6 100644 --- a/solution/2400-2499/2407.Longest Increasing Subsequence II/README_EN.md +++ b/solution/2400-2499/2407.Longest Increasing Subsequence II/README_EN.md @@ -104,6 +104,8 @@ The time complexity is $O(n \times \log n)$, where $n$ is the length of the arra +#### Python3 + ```python class Node: def __init__(self): @@ -163,6 +165,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int lengthOfLIS(int[] nums, int k) { @@ -244,6 +248,8 @@ class SegmentTree { } ``` +#### C++ + ```cpp class Node { public: @@ -313,6 +319,8 @@ public: }; ``` +#### Go + ```go func lengthOfLIS(nums []int, k int) int { mx := slices.Max(nums) diff --git a/solution/2400-2499/2408.Design SQL/README.md b/solution/2400-2499/2408.Design SQL/README.md index 86ee64e5e6aae..c11b9c20aca56 100644 --- a/solution/2400-2499/2408.Design SQL/README.md +++ b/solution/2400-2499/2408.Design SQL/README.md @@ -90,6 +90,8 @@ sql.selectCell("two", 2, 2); // 返回 "fifth",查找表 "two" 中 id 为 2 +#### Python3 + ```python class SQL: def __init__(self, names: List[str], columns: List[int]): @@ -112,6 +114,8 @@ class SQL: # param_3 = obj.selectCell(name,rowId,columnId) ``` +#### Java + ```java class SQL { private Map>> tables; @@ -141,6 +145,8 @@ class SQL { */ ``` +#### C++ + ```cpp class SQL { public: @@ -169,6 +175,8 @@ public: */ ``` +#### Go + ```go type SQL struct { tables map[string][][]string diff --git a/solution/2400-2499/2408.Design SQL/README_EN.md b/solution/2400-2499/2408.Design SQL/README_EN.md index f7ee6dace250e..c711bdc50f6b6 100644 --- a/solution/2400-2499/2408.Design SQL/README_EN.md +++ b/solution/2400-2499/2408.Design SQL/README_EN.md @@ -88,6 +88,8 @@ The time complexity of each operation is $O(1)$, and the space complexity is $O( +#### Python3 + ```python class SQL: def __init__(self, names: List[str], columns: List[int]): @@ -110,6 +112,8 @@ class SQL: # param_3 = obj.selectCell(name,rowId,columnId) ``` +#### Java + ```java class SQL { private Map>> tables; @@ -139,6 +143,8 @@ class SQL { */ ``` +#### C++ + ```cpp class SQL { public: @@ -167,6 +173,8 @@ public: */ ``` +#### Go + ```go type SQL struct { tables map[string][][]string diff --git a/solution/2400-2499/2409.Count Days Spent Together/README.md b/solution/2400-2499/2409.Count Days Spent Together/README.md index e374f39f19af3..3dbfff5642d8c 100644 --- a/solution/2400-2499/2409.Count Days Spent Together/README.md +++ b/solution/2400-2499/2409.Count Days Spent Together/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def countDaysTogether( @@ -82,6 +84,8 @@ class Solution: return max(y - x + 1, 0) ``` +#### Java + ```java class Solution { private int[] days = new int[] {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func countDaysTogether(arriveAlice string, leaveAlice string, arriveBob string, leaveBob string) int { days := []int{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} diff --git a/solution/2400-2499/2409.Count Days Spent Together/README_EN.md b/solution/2400-2499/2409.Count Days Spent Together/README_EN.md index 9cf77f6e04ab6..ef512b78bdc16 100644 --- a/solution/2400-2499/2409.Count Days Spent Together/README_EN.md +++ b/solution/2400-2499/2409.Count Days Spent Together/README_EN.md @@ -67,6 +67,8 @@ The time complexity is $O(C)$, and the space complexity is $O(C)$. Here, $C$ is +#### Python3 + ```python class Solution: def countDaysTogether( @@ -80,6 +82,8 @@ class Solution: return max(y - x + 1, 0) ``` +#### Java + ```java class Solution { private int[] days = new int[] {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func countDaysTogether(arriveAlice string, leaveAlice string, arriveBob string, leaveBob string) int { days := []int{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} diff --git a/solution/2400-2499/2410.Maximum Matching of Players With Trainers/README.md b/solution/2400-2499/2410.Maximum Matching of Players With Trainers/README.md index d704a7966b0c9..628d4b04ad1e1 100644 --- a/solution/2400-2499/2410.Maximum Matching of Players With Trainers/README.md +++ b/solution/2400-2499/2410.Maximum Matching of Players With Trainers/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def matchPlayersAndTrainers(self, players: List[int], trainers: List[int]) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int matchPlayersAndTrainers(int[] players, int[] trainers) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func matchPlayersAndTrainers(players []int, trainers []int) int { sort.Ints(players) diff --git a/solution/2400-2499/2410.Maximum Matching of Players With Trainers/README_EN.md b/solution/2400-2499/2410.Maximum Matching of Players With Trainers/README_EN.md index a5586403a3449..30b237f79e30f 100644 --- a/solution/2400-2499/2410.Maximum Matching of Players With Trainers/README_EN.md +++ b/solution/2400-2499/2410.Maximum Matching of Players With Trainers/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(n \times \log n + m \times \log m)$, and the space com +#### Python3 + ```python class Solution: def matchPlayersAndTrainers(self, players: List[int], trainers: List[int]) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int matchPlayersAndTrainers(int[] players, int[] trainers) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func matchPlayersAndTrainers(players []int, trainers []int) int { sort.Ints(players) diff --git a/solution/2400-2499/2411.Smallest Subarrays With Maximum Bitwise OR/README.md b/solution/2400-2499/2411.Smallest Subarrays With Maximum Bitwise OR/README.md index 0a4f4bb4df793..5324665f4dcf0 100644 --- a/solution/2400-2499/2411.Smallest Subarrays With Maximum Bitwise OR/README.md +++ b/solution/2400-2499/2411.Smallest Subarrays With Maximum Bitwise OR/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def smallestSubarrays(self, nums: List[int]) -> List[int]: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] smallestSubarrays(int[] nums) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func smallestSubarrays(nums []int) []int { n := len(nums) diff --git a/solution/2400-2499/2411.Smallest Subarrays With Maximum Bitwise OR/README_EN.md b/solution/2400-2499/2411.Smallest Subarrays With Maximum Bitwise OR/README_EN.md index b344161bd6d1f..39e27135248b9 100644 --- a/solution/2400-2499/2411.Smallest Subarrays With Maximum Bitwise OR/README_EN.md +++ b/solution/2400-2499/2411.Smallest Subarrays With Maximum Bitwise OR/README_EN.md @@ -87,6 +87,8 @@ The time complexity is $O(n \times \log m)$, where $n$ is the length of the arra +#### Python3 + ```python class Solution: def smallestSubarrays(self, nums: List[int]) -> List[int]: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] smallestSubarrays(int[] nums) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func smallestSubarrays(nums []int) []int { n := len(nums) diff --git a/solution/2400-2499/2412.Minimum Money Required Before Transactions/README.md b/solution/2400-2499/2412.Minimum Money Required Before Transactions/README.md index d5ec92ae6e86b..417b5d69c77f3 100644 --- a/solution/2400-2499/2412.Minimum Money Required Before Transactions/README.md +++ b/solution/2400-2499/2412.Minimum Money Required Before Transactions/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def minimumMoney(self, transactions: List[List[int]]) -> int: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long minimumMoney(int[][] transactions) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func minimumMoney(transactions [][]int) int64 { s, ans := 0, 0 diff --git a/solution/2400-2499/2412.Minimum Money Required Before Transactions/README_EN.md b/solution/2400-2499/2412.Minimum Money Required Before Transactions/README_EN.md index 82412beaf6025..487c51184f565 100644 --- a/solution/2400-2499/2412.Minimum Money Required Before Transactions/README_EN.md +++ b/solution/2400-2499/2412.Minimum Money Required Before Transactions/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(n)$, where $n$ is the number of transactions. The spac +#### Python3 + ```python class Solution: def minimumMoney(self, transactions: List[List[int]]) -> int: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long minimumMoney(int[][] transactions) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func minimumMoney(transactions [][]int) int64 { s, ans := 0, 0 diff --git a/solution/2400-2499/2413.Smallest Even Multiple/README.md b/solution/2400-2499/2413.Smallest Even Multiple/README.md index 0d1197c2fa0be..4dbb190f934a6 100644 --- a/solution/2400-2499/2413.Smallest Even Multiple/README.md +++ b/solution/2400-2499/2413.Smallest Even Multiple/README.md @@ -59,12 +59,16 @@ tags: +#### Python3 + ```python class Solution: def smallestEvenMultiple(self, n: int) -> int: return n if n % 2 == 0 else n * 2 ``` +#### Java + ```java class Solution { public int smallestEvenMultiple(int n) { @@ -73,6 +77,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -82,6 +88,8 @@ public: }; ``` +#### Go + ```go func smallestEvenMultiple(n int) int { if n%2 == 0 { @@ -91,12 +99,16 @@ func smallestEvenMultiple(n int) int { } ``` +#### TypeScript + ```ts function smallestEvenMultiple(n: number): number { return n % 2 === 0 ? n : n * 2; } ``` +#### Rust + ```rust impl Solution { pub fn smallest_even_multiple(n: i32) -> i32 { @@ -108,6 +120,8 @@ impl Solution { } ``` +#### C + ```c int smallestEvenMultiple(int n) { return n % 2 == 0 ? n : n * 2; diff --git a/solution/2400-2499/2413.Smallest Even Multiple/README_EN.md b/solution/2400-2499/2413.Smallest Even Multiple/README_EN.md index be083d7ac13ec..8181eddacb362 100644 --- a/solution/2400-2499/2413.Smallest Even Multiple/README_EN.md +++ b/solution/2400-2499/2413.Smallest Even Multiple/README_EN.md @@ -59,12 +59,16 @@ The time complexity is $O(1)$. +#### Python3 + ```python class Solution: def smallestEvenMultiple(self, n: int) -> int: return n if n % 2 == 0 else n * 2 ``` +#### Java + ```java class Solution { public int smallestEvenMultiple(int n) { @@ -73,6 +77,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -82,6 +88,8 @@ public: }; ``` +#### Go + ```go func smallestEvenMultiple(n int) int { if n%2 == 0 { @@ -91,12 +99,16 @@ func smallestEvenMultiple(n int) int { } ``` +#### TypeScript + ```ts function smallestEvenMultiple(n: number): number { return n % 2 === 0 ? n : n * 2; } ``` +#### Rust + ```rust impl Solution { pub fn smallest_even_multiple(n: i32) -> i32 { @@ -108,6 +120,8 @@ impl Solution { } ``` +#### C + ```c int smallestEvenMultiple(int n) { return n % 2 == 0 ? n : n * 2; diff --git a/solution/2400-2499/2414.Length of the Longest Alphabetical Continuous Substring/README.md b/solution/2400-2499/2414.Length of the Longest Alphabetical Continuous Substring/README.md index d929c4c1b721f..c13ffe7a93a2c 100644 --- a/solution/2400-2499/2414.Length of the Longest Alphabetical Continuous Substring/README.md +++ b/solution/2400-2499/2414.Length of the Longest Alphabetical Continuous Substring/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def longestContinuousSubstring(self, s: str) -> int: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestContinuousSubstring(String s) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func longestContinuousSubstring(s string) int { ans := 0 @@ -130,6 +138,8 @@ func longestContinuousSubstring(s string) int { } ``` +#### TypeScript + ```ts function longestContinuousSubstring(s: string): number { const n = s.length; @@ -145,6 +155,8 @@ function longestContinuousSubstring(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn longest_continuous_substring(s: String) -> i32 { @@ -163,6 +175,8 @@ impl Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) diff --git a/solution/2400-2499/2414.Length of the Longest Alphabetical Continuous Substring/README_EN.md b/solution/2400-2499/2414.Length of the Longest Alphabetical Continuous Substring/README_EN.md index 51522ebeb32e1..e5b0d9799fcb1 100644 --- a/solution/2400-2499/2414.Length of the Longest Alphabetical Continuous Substring/README_EN.md +++ b/solution/2400-2499/2414.Length of the Longest Alphabetical Continuous Substring/README_EN.md @@ -66,6 +66,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string $s$. The sp +#### Python3 + ```python class Solution: def longestContinuousSubstring(self, s: str) -> int: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestContinuousSubstring(String s) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func longestContinuousSubstring(s string) int { ans := 0 @@ -130,6 +138,8 @@ func longestContinuousSubstring(s string) int { } ``` +#### TypeScript + ```ts function longestContinuousSubstring(s: string): number { const n = s.length; @@ -145,6 +155,8 @@ function longestContinuousSubstring(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn longest_continuous_substring(s: String) -> i32 { @@ -163,6 +175,8 @@ impl Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) diff --git a/solution/2400-2499/2415.Reverse Odd Levels of Binary Tree/README.md b/solution/2400-2499/2415.Reverse Odd Levels of Binary Tree/README.md index e53b0928cb3cc..4062864f77b3d 100644 --- a/solution/2400-2499/2415.Reverse Odd Levels of Binary Tree/README.md +++ b/solution/2400-2499/2415.Reverse Odd Levels of Binary Tree/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -114,6 +116,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -157,6 +161,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -195,6 +201,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -227,6 +235,8 @@ func reverseOddLevels(root *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -263,6 +273,8 @@ function reverseOddLevels(root: TreeNode | null): TreeNode | null { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/2400-2499/2415.Reverse Odd Levels of Binary Tree/README_EN.md b/solution/2400-2499/2415.Reverse Odd Levels of Binary Tree/README_EN.md index e06b09dc3c323..cc33e4d58b1b9 100644 --- a/solution/2400-2499/2415.Reverse Odd Levels of Binary Tree/README_EN.md +++ b/solution/2400-2499/2415.Reverse Odd Levels of Binary Tree/README_EN.md @@ -87,6 +87,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -113,6 +115,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -156,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -194,6 +200,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -226,6 +234,8 @@ func reverseOddLevels(root *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -262,6 +272,8 @@ function reverseOddLevels(root: TreeNode | null): TreeNode | null { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/2400-2499/2416.Sum of Prefix Scores of Strings/README.md b/solution/2400-2499/2416.Sum of Prefix Scores of Strings/README.md index cb5838cabf855..68056afc595f9 100644 --- a/solution/2400-2499/2416.Sum of Prefix Scores of Strings/README.md +++ b/solution/2400-2499/2416.Sum of Prefix Scores of Strings/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Trie: def __init__(self): @@ -124,6 +126,8 @@ class Solution: return [trie.search(w) for w in words] ``` +#### Java + ```java class Trie { private Trie[] children = new Trie[26]; @@ -171,6 +175,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { private: @@ -221,6 +227,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [26]*Trie @@ -269,6 +277,8 @@ func sumPrefixScores(words []string) []int { } ``` +#### TypeScript + ```ts function sumPrefixScores(words: string[]): number[] { const map = new Map(); @@ -303,6 +313,8 @@ function sumPrefixScores(words: string[]): number[] { +#### TypeScript + ```ts class Trie { children: Array; diff --git a/solution/2400-2499/2416.Sum of Prefix Scores of Strings/README_EN.md b/solution/2400-2499/2416.Sum of Prefix Scores of Strings/README_EN.md index d7814747dcf87..683e263314376 100644 --- a/solution/2400-2499/2416.Sum of Prefix Scores of Strings/README_EN.md +++ b/solution/2400-2499/2416.Sum of Prefix Scores of Strings/README_EN.md @@ -89,6 +89,8 @@ The time complexity is $O(n \times m)$. Here, $n$ and $m$ are the length of the +#### Python3 + ```python class Trie: def __init__(self): @@ -124,6 +126,8 @@ class Solution: return [trie.search(w) for w in words] ``` +#### Java + ```java class Trie { private Trie[] children = new Trie[26]; @@ -171,6 +175,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { private: @@ -221,6 +227,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [26]*Trie @@ -269,6 +277,8 @@ func sumPrefixScores(words []string) []int { } ``` +#### TypeScript + ```ts function sumPrefixScores(words: string[]): number[] { const map = new Map(); @@ -303,6 +313,8 @@ function sumPrefixScores(words: string[]): number[] { +#### TypeScript + ```ts class Trie { children: Array; diff --git a/solution/2400-2499/2417.Closest Fair Integer/README.md b/solution/2400-2499/2417.Closest Fair Integer/README.md index d4676f547ab5d..a63eb7aa65bcf 100644 --- a/solution/2400-2499/2417.Closest Fair Integer/README.md +++ b/solution/2400-2499/2417.Closest Fair Integer/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def closestFair(self, n: int) -> int: @@ -88,6 +90,8 @@ class Solution: return self.closestFair(n + 1) ``` +#### Java + ```java class Solution { public int closestFair(int n) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func closestFair(n int) int { a, b := 0, 0 diff --git a/solution/2400-2499/2417.Closest Fair Integer/README_EN.md b/solution/2400-2499/2417.Closest Fair Integer/README_EN.md index a3e891d6c9bc6..c638c3eb77036 100644 --- a/solution/2400-2499/2417.Closest Fair Integer/README_EN.md +++ b/solution/2400-2499/2417.Closest Fair Integer/README_EN.md @@ -65,6 +65,8 @@ The time complexity is $O(\sqrt{n} \times \log_{10} n)$. +#### Python3 + ```python class Solution: def closestFair(self, n: int) -> int: @@ -86,6 +88,8 @@ class Solution: return self.closestFair(n + 1) ``` +#### Java + ```java class Solution { public int closestFair(int n) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func closestFair(n int) int { a, b := 0, 0 diff --git a/solution/2400-2499/2418.Sort the People/README.md b/solution/2400-2499/2418.Sort the People/README.md index 534e933b93567..4a7c2508fcbcf 100644 --- a/solution/2400-2499/2418.Sort the People/README.md +++ b/solution/2400-2499/2418.Sort the People/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def sortPeople(self, names: List[str], heights: List[int]) -> List[str]: @@ -80,6 +82,8 @@ class Solution: return [names[i] for i in idx] ``` +#### Java + ```java class Solution { public String[] sortPeople(String[] names, int[] heights) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func sortPeople(names []string, heights []int) (ans []string) { n := len(names) @@ -130,6 +138,8 @@ func sortPeople(names []string, heights []int) (ans []string) { } ``` +#### TypeScript + ```ts function sortPeople(names: string[], heights: number[]): string[] { const n = names.length; @@ -146,6 +156,8 @@ function sortPeople(names: string[], heights: number[]): string[] { } ``` +#### Rust + ```rust impl Solution { pub fn sort_people(names: Vec, heights: Vec) -> Vec { @@ -169,12 +181,16 @@ impl Solution { +#### Python3 + ```python class Solution: def sortPeople(self, names: List[str], heights: List[int]) -> List[str]: return [name for _, name in sorted(zip(heights, names), reverse=True)] ``` +#### Java + ```java class Solution { public String[] sortPeople(String[] names, int[] heights) { @@ -193,6 +209,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -212,6 +230,8 @@ public: }; ``` +#### Go + ```go func sortPeople(names []string, heights []int) []string { n := len(names) @@ -228,6 +248,8 @@ func sortPeople(names []string, heights []int) []string { } ``` +#### TypeScript + ```ts function sortPeople(names: string[], heights: number[]): string[] { return names diff --git a/solution/2400-2499/2418.Sort the People/README_EN.md b/solution/2400-2499/2418.Sort the People/README_EN.md index 5d75437480582..304babee3613a 100644 --- a/solution/2400-2499/2418.Sort the People/README_EN.md +++ b/solution/2400-2499/2418.Sort the People/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def sortPeople(self, names: List[str], heights: List[int]) -> List[str]: @@ -80,6 +82,8 @@ class Solution: return [names[i] for i in idx] ``` +#### Java + ```java class Solution { public String[] sortPeople(String[] names, int[] heights) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func sortPeople(names []string, heights []int) (ans []string) { n := len(names) @@ -130,6 +138,8 @@ func sortPeople(names []string, heights []int) (ans []string) { } ``` +#### TypeScript + ```ts function sortPeople(names: string[], heights: number[]): string[] { const n = names.length; @@ -146,6 +156,8 @@ function sortPeople(names: string[], heights: number[]): string[] { } ``` +#### Rust + ```rust impl Solution { pub fn sort_people(names: Vec, heights: Vec) -> Vec { @@ -169,12 +181,16 @@ impl Solution { +#### Python3 + ```python class Solution: def sortPeople(self, names: List[str], heights: List[int]) -> List[str]: return [name for _, name in sorted(zip(heights, names), reverse=True)] ``` +#### Java + ```java class Solution { public String[] sortPeople(String[] names, int[] heights) { @@ -193,6 +209,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -212,6 +230,8 @@ public: }; ``` +#### Go + ```go func sortPeople(names []string, heights []int) []string { n := len(names) @@ -228,6 +248,8 @@ func sortPeople(names []string, heights []int) []string { } ``` +#### TypeScript + ```ts function sortPeople(names: string[], heights: number[]): string[] { return names 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 f8124f4ed9b1a..66a3323734c16 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 @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def longestSubarray(self, nums: List[int]) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestSubarray(int[] nums) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func longestSubarray(nums []int) int { mx := slices.Max(nums) 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 c743f0362426e..96b33268c4496 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 @@ -81,6 +81,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. +#### Python3 + ```python class Solution: def longestSubarray(self, nums: List[int]) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestSubarray(int[] nums) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func longestSubarray(nums []int) int { mx := slices.Max(nums) diff --git a/solution/2400-2499/2420.Find All Good Indices/README.md b/solution/2400-2499/2420.Find All Good Indices/README.md index de673fd99c6e3..ed82af020e7a4 100644 --- a/solution/2400-2499/2420.Find All Good Indices/README.md +++ b/solution/2400-2499/2420.Find All Good Indices/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def goodIndices(self, nums: List[int], k: int) -> List[int]: @@ -95,6 +97,8 @@ class Solution: return [i for i in range(k, n - k) if decr[i] >= k and incr[i] >= k] ``` +#### Java + ```java class Solution { public List goodIndices(int[] nums, int k) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func goodIndices(nums []int, k int) []int { n := len(nums) diff --git a/solution/2400-2499/2420.Find All Good Indices/README_EN.md b/solution/2400-2499/2420.Find All Good Indices/README_EN.md index ace7ac6325d30..9c6cc51db6b3a 100644 --- a/solution/2400-2499/2420.Find All Good Indices/README_EN.md +++ b/solution/2400-2499/2420.Find All Good Indices/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def goodIndices(self, nums: List[int], k: int) -> List[int]: @@ -93,6 +95,8 @@ class Solution: return [i for i in range(k, n - k) if decr[i] >= k and incr[i] >= k] ``` +#### Java + ```java class Solution { public List goodIndices(int[] nums, int k) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func goodIndices(nums []int, k int) []int { n := len(nums) diff --git a/solution/2400-2499/2421.Number of Good Paths/README.md b/solution/2400-2499/2421.Number of Good Paths/README.md index 69bcdd38a5593..fdb73552795e4 100644 --- a/solution/2400-2499/2421.Number of Good Paths/README.md +++ b/solution/2400-2499/2421.Number of Good Paths/README.md @@ -102,6 +102,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfGoodPaths(self, vals: List[int], edges: List[List[int]]) -> int: @@ -134,6 +136,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] p; @@ -184,6 +188,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -230,6 +236,8 @@ public: }; ``` +#### Go + ```go func numberOfGoodPaths(vals []int, edges [][]int) int { n := len(vals) diff --git a/solution/2400-2499/2421.Number of Good Paths/README_EN.md b/solution/2400-2499/2421.Number of Good Paths/README_EN.md index 33ee4c77a96d5..7dca78a73eff5 100644 --- a/solution/2400-2499/2421.Number of Good Paths/README_EN.md +++ b/solution/2400-2499/2421.Number of Good Paths/README_EN.md @@ -97,6 +97,8 @@ The time complexity is $O(n \times \log n)$. +#### Python3 + ```python class Solution: def numberOfGoodPaths(self, vals: List[int], edges: List[List[int]]) -> int: @@ -129,6 +131,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] p; @@ -179,6 +183,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -225,6 +231,8 @@ public: }; ``` +#### Go + ```go func numberOfGoodPaths(vals []int, edges [][]int) int { n := len(vals) diff --git a/solution/2400-2499/2422.Merge Operations to Turn Array Into a Palindrome/README.md b/solution/2400-2499/2422.Merge Operations to Turn Array Into a Palindrome/README.md index f53c5ffa16f40..5028b91fd9efe 100644 --- a/solution/2400-2499/2422.Merge Operations to Turn Array Into a Palindrome/README.md +++ b/solution/2400-2499/2422.Merge Operations to Turn Array Into a Palindrome/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def minimumOperations(self, nums: List[int]) -> int: @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumOperations(int[] nums) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func minimumOperations(nums []int) int { i, j := 0, len(nums)-1 diff --git a/solution/2400-2499/2422.Merge Operations to Turn Array Into a Palindrome/README_EN.md b/solution/2400-2499/2422.Merge Operations to Turn Array Into a Palindrome/README_EN.md index 39cabb3320ada..17bc79fa37bef 100644 --- a/solution/2400-2499/2422.Merge Operations to Turn Array Into a Palindrome/README_EN.md +++ b/solution/2400-2499/2422.Merge Operations to Turn Array Into a Palindrome/README_EN.md @@ -85,6 +85,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def minimumOperations(self, nums: List[int]) -> int: @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumOperations(int[] nums) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func minimumOperations(nums []int) int { i, j := 0, len(nums)-1 diff --git a/solution/2400-2499/2423.Remove Letter To Equalize Frequency/README.md b/solution/2400-2499/2423.Remove Letter To Equalize Frequency/README.md index c756754ca2db1..c65b748d0fbd5 100644 --- a/solution/2400-2499/2423.Remove Letter To Equalize Frequency/README.md +++ b/solution/2400-2499/2423.Remove Letter To Equalize Frequency/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def equalFrequency(self, word: str) -> bool: @@ -88,6 +90,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean equalFrequency(String word) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func equalFrequency(word string) bool { cnt := [26]int{} @@ -186,6 +194,8 @@ func equalFrequency(word string) bool { } ``` +#### TypeScript + ```ts function equalFrequency(word: string): boolean { const cnt: number[] = new Array(26).fill(0); diff --git a/solution/2400-2499/2423.Remove Letter To Equalize Frequency/README_EN.md b/solution/2400-2499/2423.Remove Letter To Equalize Frequency/README_EN.md index bc22d5b0237ff..a41e4762d4bcd 100644 --- a/solution/2400-2499/2423.Remove Letter To Equalize Frequency/README_EN.md +++ b/solution/2400-2499/2423.Remove Letter To Equalize Frequency/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(n + C^2)$, and the space complexity is $O(C)$. Here, $ +#### Python3 + ```python class Solution: def equalFrequency(self, word: str) -> bool: @@ -86,6 +88,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean equalFrequency(String word) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func equalFrequency(word string) bool { cnt := [26]int{} @@ -184,6 +192,8 @@ func equalFrequency(word string) bool { } ``` +#### TypeScript + ```ts function equalFrequency(word: string): boolean { const cnt: number[] = new Array(26).fill(0); diff --git a/solution/2400-2499/2424.Longest Uploaded Prefix/README.md b/solution/2400-2499/2424.Longest Uploaded Prefix/README.md index 78184b5a37a99..3aaa73c45213d 100644 --- a/solution/2400-2499/2424.Longest Uploaded Prefix/README.md +++ b/solution/2400-2499/2424.Longest Uploaded Prefix/README.md @@ -84,6 +84,8 @@ server.longest(); // 前缀 [1,2,3] 是最长上传前缀, +#### Python3 + ```python class LUPrefix: def __init__(self, n: int): @@ -105,6 +107,8 @@ class LUPrefix: # param_2 = obj.longest() ``` +#### Java + ```java class LUPrefix { private int r; @@ -133,6 +137,8 @@ class LUPrefix { */ ``` +#### C++ + ```cpp class LUPrefix { public: @@ -163,6 +169,8 @@ private: */ ``` +#### Go + ```go type LUPrefix struct { r int diff --git a/solution/2400-2499/2424.Longest Uploaded Prefix/README_EN.md b/solution/2400-2499/2424.Longest Uploaded Prefix/README_EN.md index a74d14d1b48f0..b85559cbf9146 100644 --- a/solution/2400-2499/2424.Longest Uploaded Prefix/README_EN.md +++ b/solution/2400-2499/2424.Longest Uploaded Prefix/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class LUPrefix: def __init__(self, n: int): @@ -105,6 +107,8 @@ class LUPrefix: # param_2 = obj.longest() ``` +#### Java + ```java class LUPrefix { private int r; @@ -133,6 +137,8 @@ class LUPrefix { */ ``` +#### C++ + ```cpp class LUPrefix { public: @@ -163,6 +169,8 @@ private: */ ``` +#### Go + ```go type LUPrefix struct { r int diff --git a/solution/2400-2499/2425.Bitwise XOR of All Pairings/README.md b/solution/2400-2499/2425.Bitwise XOR of All Pairings/README.md index d6565c9b0e602..624b3b7462dd5 100644 --- a/solution/2400-2499/2425.Bitwise XOR of All Pairings/README.md +++ b/solution/2400-2499/2425.Bitwise XOR of All Pairings/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def xorAllNums(self, nums1: List[int], nums2: List[int]) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int xorAllNums(int[] nums1, int[] nums2) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func xorAllNums(nums1 []int, nums2 []int) int { ans := 0 @@ -143,6 +151,8 @@ func xorAllNums(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function xorAllNums(nums1: number[], nums2: number[]): number { let ans = 0; diff --git a/solution/2400-2499/2425.Bitwise XOR of All Pairings/README_EN.md b/solution/2400-2499/2425.Bitwise XOR of All Pairings/README_EN.md index b525b9a8ac70d..f1e242b13a948 100644 --- a/solution/2400-2499/2425.Bitwise XOR of All Pairings/README_EN.md +++ b/solution/2400-2499/2425.Bitwise XOR of All Pairings/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(m+n)$. Where $m$ and $n$ are the lengths of the `nums1 +#### Python3 + ```python class Solution: def xorAllNums(self, nums1: List[int], nums2: List[int]) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int xorAllNums(int[] nums1, int[] nums2) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func xorAllNums(nums1 []int, nums2 []int) int { ans := 0 @@ -144,6 +152,8 @@ func xorAllNums(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function xorAllNums(nums1: number[], nums2: number[]): number { let ans = 0; diff --git a/solution/2400-2499/2426.Number of Pairs Satisfying Inequality/README.md b/solution/2400-2499/2426.Number of Pairs Satisfying Inequality/README.md index d9e055096c15f..fd36fdc2d7a73 100644 --- a/solution/2400-2499/2426.Number of Pairs Satisfying Inequality/README.md +++ b/solution/2400-2499/2426.Number of Pairs Satisfying Inequality/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -116,6 +118,8 @@ class Solution: return ans ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -161,6 +165,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -207,6 +213,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int diff --git a/solution/2400-2499/2426.Number of Pairs Satisfying Inequality/README_EN.md b/solution/2400-2499/2426.Number of Pairs Satisfying Inequality/README_EN.md index 69ac8ec4e809e..0510ee16e2874 100644 --- a/solution/2400-2499/2426.Number of Pairs Satisfying Inequality/README_EN.md +++ b/solution/2400-2499/2426.Number of Pairs Satisfying Inequality/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n \times \log n)$. +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -116,6 +118,8 @@ class Solution: return ans ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -161,6 +165,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -207,6 +213,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int diff --git a/solution/2400-2499/2427.Number of Common Factors/README.md b/solution/2400-2499/2427.Number of Common Factors/README.md index 1aa8ce0378cf4..f1edf6bf9f0cc 100644 --- a/solution/2400-2499/2427.Number of Common Factors/README.md +++ b/solution/2400-2499/2427.Number of Common Factors/README.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def commonFactors(self, a: int, b: int) -> int: @@ -68,6 +70,8 @@ class Solution: return sum(g % x == 0 for x in range(1, g + 1)) ``` +#### Java + ```java class Solution { public int commonFactors(int a, int b) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,6 +107,8 @@ public: }; ``` +#### Go + ```go func commonFactors(a int, b int) (ans int) { g := gcd(a, b) @@ -120,6 +128,8 @@ func gcd(a int, b int) int { } ``` +#### TypeScript + ```ts function commonFactors(a: number, b: number): number { const g = gcd(a, b); @@ -151,6 +161,8 @@ function gcd(a: number, b: number): number { +#### Python3 + ```python class Solution: def commonFactors(self, a: int, b: int) -> int: @@ -164,6 +176,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int commonFactors(int a, int b) { @@ -186,6 +200,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -203,6 +219,8 @@ public: }; ``` +#### Go + ```go func commonFactors(a int, b int) (ans int) { g := gcd(a, b) @@ -225,6 +243,8 @@ func gcd(a int, b int) int { } ``` +#### TypeScript + ```ts function commonFactors(a: number, b: number): number { const g = gcd(a, b); diff --git a/solution/2400-2499/2427.Number of Common Factors/README_EN.md b/solution/2400-2499/2427.Number of Common Factors/README_EN.md index 553d5839a90cf..7f4c5f6617297 100644 --- a/solution/2400-2499/2427.Number of Common Factors/README_EN.md +++ b/solution/2400-2499/2427.Number of Common Factors/README_EN.md @@ -62,6 +62,8 @@ The time complexity is $O(\min(a, b))$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def commonFactors(self, a: int, b: int) -> int: @@ -69,6 +71,8 @@ class Solution: return sum(g % x == 0 for x in range(1, g + 1)) ``` +#### Java + ```java class Solution { public int commonFactors(int a, int b) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -102,6 +108,8 @@ public: }; ``` +#### Go + ```go func commonFactors(a int, b int) (ans int) { g := gcd(a, b) @@ -121,6 +129,8 @@ func gcd(a int, b int) int { } ``` +#### TypeScript + ```ts function commonFactors(a: number, b: number): number { const g = gcd(a, b); @@ -152,6 +162,8 @@ The time complexity is $O(\sqrt{\min(a, b)})$, and the space complexity is $O(1) +#### Python3 + ```python class Solution: def commonFactors(self, a: int, b: int) -> int: @@ -165,6 +177,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int commonFactors(int a, int b) { @@ -187,6 +201,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -204,6 +220,8 @@ public: }; ``` +#### Go + ```go func commonFactors(a int, b int) (ans int) { g := gcd(a, b) @@ -226,6 +244,8 @@ func gcd(a int, b int) int { } ``` +#### TypeScript + ```ts function commonFactors(a: number, b: number): number { const g = gcd(a, b); diff --git a/solution/2400-2499/2428.Maximum Sum of an Hourglass/README.md b/solution/2400-2499/2428.Maximum Sum of an Hourglass/README.md index 47eae5826592a..be1aa02193cc0 100644 --- a/solution/2400-2499/2428.Maximum Sum of an Hourglass/README.md +++ b/solution/2400-2499/2428.Maximum Sum of an Hourglass/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def maxSum(self, grid: List[List[int]]) -> int: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxSum(int[][] grid) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func maxSum(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -145,6 +153,8 @@ func maxSum(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function maxSum(grid: number[][]): number { const m = grid.length; diff --git a/solution/2400-2499/2428.Maximum Sum of an Hourglass/README_EN.md b/solution/2400-2499/2428.Maximum Sum of an Hourglass/README_EN.md index 741a45c62b11e..d4f00b0e6f507 100644 --- a/solution/2400-2499/2428.Maximum Sum of an Hourglass/README_EN.md +++ b/solution/2400-2499/2428.Maximum Sum of an Hourglass/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(m \times n)$, where $m$ and $n$ are the number of rows +#### Python3 + ```python class Solution: def maxSum(self, grid: List[List[int]]) -> int: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxSum(int[][] grid) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func maxSum(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -145,6 +153,8 @@ func maxSum(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function maxSum(grid: number[][]): number { const m = grid.length; diff --git a/solution/2400-2499/2429.Minimize XOR/README.md b/solution/2400-2499/2429.Minimize XOR/README.md index c1976505fb71f..d08cad94b4057 100644 --- a/solution/2400-2499/2429.Minimize XOR/README.md +++ b/solution/2400-2499/2429.Minimize XOR/README.md @@ -76,6 +76,8 @@ num1 和 num2 的二进制表示分别是 0001 和 1100 。 +#### Python3 + ```python class Solution: def minimizeXor(self, num1: int, num2: int) -> int: @@ -92,6 +94,8 @@ class Solution: return x ``` +#### Java + ```java class Solution { public int minimizeXor(int num1, int num2) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func minimizeXor(num1 int, num2 int) int { cnt := bits.OnesCount(uint(num2)) @@ -157,6 +165,8 @@ func minimizeXor(num1 int, num2 int) int { } ``` +#### TypeScript + ```ts function minimizeXor(num1: number, num2: number): number { let cnt = 0; @@ -191,6 +201,8 @@ function minimizeXor(num1: number, num2: number): number { +#### Python3 + ```python class Solution: def minimizeXor(self, num1: int, num2: int) -> int: @@ -205,6 +217,8 @@ class Solution: return num1 ``` +#### Java + ```java class Solution { public int minimizeXor(int num1, int num2) { @@ -221,6 +235,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -238,6 +254,8 @@ public: }; ``` +#### Go + ```go func minimizeXor(num1 int, num2 int) int { cnt1 := bits.OnesCount(uint(num1)) @@ -252,6 +270,8 @@ func minimizeXor(num1 int, num2 int) int { } ``` +#### TypeScript + ```ts function minimizeXor(num1: number, num2: number): number { let cnt1 = bitCount(num1); diff --git a/solution/2400-2499/2429.Minimize XOR/README_EN.md b/solution/2400-2499/2429.Minimize XOR/README_EN.md index d1e9f3dda7a79..61c60717d64f9 100644 --- a/solution/2400-2499/2429.Minimize XOR/README_EN.md +++ b/solution/2400-2499/2429.Minimize XOR/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(\log n)$, and the space complexity is $O(1)$. Here, $n +#### Python3 + ```python class Solution: def minimizeXor(self, num1: int, num2: int) -> int: @@ -90,6 +92,8 @@ class Solution: return x ``` +#### Java + ```java class Solution { public int minimizeXor(int num1, int num2) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func minimizeXor(num1 int, num2 int) int { cnt := bits.OnesCount(uint(num2)) @@ -155,6 +163,8 @@ func minimizeXor(num1 int, num2 int) int { } ``` +#### TypeScript + ```ts function minimizeXor(num1: number, num2: number): number { let cnt = 0; @@ -189,6 +199,8 @@ function minimizeXor(num1: number, num2: number): number { +#### Python3 + ```python class Solution: def minimizeXor(self, num1: int, num2: int) -> int: @@ -203,6 +215,8 @@ class Solution: return num1 ``` +#### Java + ```java class Solution { public int minimizeXor(int num1, int num2) { @@ -219,6 +233,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -236,6 +252,8 @@ public: }; ``` +#### Go + ```go func minimizeXor(num1 int, num2 int) int { cnt1 := bits.OnesCount(uint(num1)) @@ -250,6 +268,8 @@ func minimizeXor(num1 int, num2 int) int { } ``` +#### TypeScript + ```ts function minimizeXor(num1: number, num2: number): number { let cnt1 = bitCount(num1); diff --git a/solution/2400-2499/2430.Maximum Deletions on a String/README.md b/solution/2400-2499/2430.Maximum Deletions on a String/README.md index 7ead4655fe48e..1c5f20af4bab7 100644 --- a/solution/2400-2499/2430.Maximum Deletions on a String/README.md +++ b/solution/2400-2499/2430.Maximum Deletions on a String/README.md @@ -100,6 +100,8 @@ tags: +#### Python3 + ```python class Solution: def deleteString(self, s: str) -> int: @@ -117,6 +119,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private int n; @@ -155,6 +159,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -191,6 +197,8 @@ public: }; ``` +#### Go + ```go func deleteString(s string) int { n := len(s) @@ -226,6 +234,8 @@ func deleteString(s string) int { } ``` +#### TypeScript + ```ts function deleteString(s: string): number { const n = s.length; @@ -265,6 +275,8 @@ function deleteString(s: string): number { +#### Python3 + ```python class Solution: def deleteString(self, s: str) -> int: @@ -283,6 +295,8 @@ class Solution: return f[0] ``` +#### Java + ```java class Solution { public int deleteString(String s) { @@ -309,6 +323,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -337,6 +353,8 @@ public: }; ``` +#### Go + ```go func deleteString(s string) int { n := len(s) @@ -364,6 +382,8 @@ func deleteString(s string) int { } ``` +#### TypeScript + ```ts function deleteString(s: string): number { const n = s.length; diff --git a/solution/2400-2499/2430.Maximum Deletions on a String/README_EN.md b/solution/2400-2499/2430.Maximum Deletions on a String/README_EN.md index 725bc738c4ce8..bd6beaf6d21c5 100644 --- a/solution/2400-2499/2430.Maximum Deletions on a String/README_EN.md +++ b/solution/2400-2499/2430.Maximum Deletions on a String/README_EN.md @@ -98,6 +98,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$. Here, $n$ +#### Python3 + ```python class Solution: def deleteString(self, s: str) -> int: @@ -115,6 +117,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private int n; @@ -153,6 +157,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -189,6 +195,8 @@ public: }; ``` +#### Go + ```go func deleteString(s string) int { n := len(s) @@ -224,6 +232,8 @@ func deleteString(s string) int { } ``` +#### TypeScript + ```ts function deleteString(s: string): number { const n = s.length; @@ -263,6 +273,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$. Here, $n$ i +#### Python3 + ```python class Solution: def deleteString(self, s: str) -> int: @@ -281,6 +293,8 @@ class Solution: return f[0] ``` +#### Java + ```java class Solution { public int deleteString(String s) { @@ -307,6 +321,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -335,6 +351,8 @@ public: }; ``` +#### Go + ```go func deleteString(s string) int { n := len(s) @@ -362,6 +380,8 @@ func deleteString(s string) int { } ``` +#### TypeScript + ```ts function deleteString(s: string): number { const n = s.length; diff --git a/solution/2400-2499/2431.Maximize Total Tastiness of Purchased Fruits/README.md b/solution/2400-2499/2431.Maximize Total Tastiness of Purchased Fruits/README.md index 377be45b29688..23575f5055584 100644 --- a/solution/2400-2499/2431.Maximize Total Tastiness of Purchased Fruits/README.md +++ b/solution/2400-2499/2431.Maximize Total Tastiness of Purchased Fruits/README.md @@ -100,6 +100,8 @@ tags: +#### Python3 + ```python class Solution: def maxTastiness( @@ -119,6 +121,8 @@ class Solution: return dfs(0, maxAmount, maxCoupons) ``` +#### Java + ```java class Solution { private int[][][] f; @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -178,6 +184,8 @@ private: }; ``` +#### Go + ```go func maxTastiness(price []int, tastiness []int, maxAmount int, maxCoupons int) int { n := len(price) diff --git a/solution/2400-2499/2431.Maximize Total Tastiness of Purchased Fruits/README_EN.md b/solution/2400-2499/2431.Maximize Total Tastiness of Purchased Fruits/README_EN.md index 4a1ddb438c720..1ad7853f95289 100644 --- a/solution/2400-2499/2431.Maximize Total Tastiness of Purchased Fruits/README_EN.md +++ b/solution/2400-2499/2431.Maximize Total Tastiness of Purchased Fruits/README_EN.md @@ -96,6 +96,8 @@ The time complexity is $O(n \times maxAmount \times maxCoupons)$, where $n$ is t +#### Python3 + ```python class Solution: def maxTastiness( @@ -115,6 +117,8 @@ class Solution: return dfs(0, maxAmount, maxCoupons) ``` +#### Java + ```java class Solution { private int[][][] f; @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ private: }; ``` +#### Go + ```go func maxTastiness(price []int, tastiness []int, maxAmount int, maxCoupons int) int { n := len(price) diff --git a/solution/2400-2499/2432.The Employee That Worked on the Longest Task/README.md b/solution/2400-2499/2432.The Employee That Worked on the Longest Task/README.md index a415fea9dac86..25ac000845eb7 100644 --- a/solution/2400-2499/2432.The Employee That Worked on the Longest Task/README.md +++ b/solution/2400-2499/2432.The Employee That Worked on the Longest Task/README.md @@ -102,6 +102,8 @@ tags: +#### Python3 + ```python class Solution: def hardestWorker(self, n: int, logs: List[List[int]]) -> int: @@ -114,6 +116,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int hardestWorker(int n, int[][] logs) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func hardestWorker(n int, logs [][]int) (ans int) { var mx, last int @@ -168,6 +176,8 @@ func hardestWorker(n int, logs [][]int) (ans int) { } ``` +#### TypeScript + ```ts function hardestWorker(n: number, logs: number[][]): number { let [ans, mx, last] = [0, 0, 0]; @@ -183,6 +193,8 @@ function hardestWorker(n: number, logs: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn hardest_worker(n: i32, logs: Vec>) -> i32 { @@ -202,6 +214,8 @@ impl Solution { } ``` +#### C + ```c #define min(a, b) (((a) < (b)) ? (a) : (b)) @@ -231,6 +245,8 @@ int hardestWorker(int n, int** logs, int logsSize, int* logsColSize) { +#### Rust + ```rust impl Solution { pub fn hardest_worker(n: i32, logs: Vec>) -> i32 { diff --git a/solution/2400-2499/2432.The Employee That Worked on the Longest Task/README_EN.md b/solution/2400-2499/2432.The Employee That Worked on the Longest Task/README_EN.md index 8b06ea5795797..be8515b8c5b90 100644 --- a/solution/2400-2499/2432.The Employee That Worked on the Longest Task/README_EN.md +++ b/solution/2400-2499/2432.The Employee That Worked on the Longest Task/README_EN.md @@ -100,6 +100,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $logs$. The +#### Python3 + ```python class Solution: def hardestWorker(self, n: int, logs: List[List[int]]) -> int: @@ -112,6 +114,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int hardestWorker(int n, int[][] logs) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func hardestWorker(n int, logs [][]int) (ans int) { var mx, last int @@ -166,6 +174,8 @@ func hardestWorker(n int, logs [][]int) (ans int) { } ``` +#### TypeScript + ```ts function hardestWorker(n: number, logs: number[][]): number { let [ans, mx, last] = [0, 0, 0]; @@ -181,6 +191,8 @@ function hardestWorker(n: number, logs: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn hardest_worker(n: i32, logs: Vec>) -> i32 { @@ -200,6 +212,8 @@ impl Solution { } ``` +#### C + ```c #define min(a, b) (((a) < (b)) ? (a) : (b)) @@ -229,6 +243,8 @@ int hardestWorker(int n, int** logs, int logsSize, int* logsColSize) { +#### Rust + ```rust impl Solution { pub fn hardest_worker(n: i32, logs: Vec>) -> i32 { diff --git a/solution/2400-2499/2433.Find The Original Array of Prefix Xor/README.md b/solution/2400-2499/2433.Find The Original Array of Prefix Xor/README.md index da9dcd9d70e39..ff689154ccedd 100644 --- a/solution/2400-2499/2433.Find The Original Array of Prefix Xor/README.md +++ b/solution/2400-2499/2433.Find The Original Array of Prefix Xor/README.md @@ -91,12 +91,16 @@ $$ +#### Python3 + ```python class Solution: def findArray(self, pref: List[int]) -> List[int]: return [a ^ b for a, b in pairwise([0] + pref)] ``` +#### Java + ```java class Solution { public int[] findArray(int[] pref) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func findArray(pref []int) []int { n := len(pref) @@ -136,6 +144,8 @@ func findArray(pref []int) []int { } ``` +#### TypeScript + ```ts function findArray(pref: number[]): number[] { let ans = pref.slice(); @@ -146,6 +156,8 @@ function findArray(pref: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn find_array(pref: Vec) -> Vec { @@ -160,6 +172,8 @@ impl Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). diff --git a/solution/2400-2499/2433.Find The Original Array of Prefix Xor/README_EN.md b/solution/2400-2499/2433.Find The Original Array of Prefix Xor/README_EN.md index 57119fad02769..67def16c05f42 100644 --- a/solution/2400-2499/2433.Find The Original Array of Prefix Xor/README_EN.md +++ b/solution/2400-2499/2433.Find The Original Array of Prefix Xor/README_EN.md @@ -91,12 +91,16 @@ The time complexity is $O(n)$, where $n$ is the length of the prefix XOR array. +#### Python3 + ```python class Solution: def findArray(self, pref: List[int]) -> List[int]: return [a ^ b for a, b in pairwise([0] + pref)] ``` +#### Java + ```java class Solution { public int[] findArray(int[] pref) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func findArray(pref []int) []int { n := len(pref) @@ -136,6 +144,8 @@ func findArray(pref []int) []int { } ``` +#### TypeScript + ```ts function findArray(pref: number[]): number[] { let ans = pref.slice(); @@ -146,6 +156,8 @@ function findArray(pref: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn find_array(pref: Vec) -> Vec { @@ -160,6 +172,8 @@ impl Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). diff --git a/solution/2400-2499/2434.Using a Robot to Print the Lexicographically Smallest String/README.md b/solution/2400-2499/2434.Using a Robot to Print the Lexicographically Smallest String/README.md index e446e7a498458..6c1e3b08fc26e 100644 --- a/solution/2400-2499/2434.Using a Robot to Print the Lexicographically Smallest String/README.md +++ b/solution/2400-2499/2434.Using a Robot to Print the Lexicographically Smallest String/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def robotWithString(self, s: str) -> str: @@ -109,6 +111,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String robotWithString(String s) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func robotWithString(s string) string { cnt := make([]int, 26) @@ -181,6 +189,8 @@ func robotWithString(s string) string { } ``` +#### TypeScript + ```ts function robotWithString(s: string): string { let cnt = new Array(128).fill(0); @@ -212,6 +222,8 @@ function robotWithString(s: string): string { +#### Python3 + ```python class Solution: def robotWithString(self, s: str) -> str: @@ -228,6 +240,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String robotWithString(String s) { @@ -251,6 +265,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/2400-2499/2434.Using a Robot to Print the Lexicographically Smallest String/README_EN.md b/solution/2400-2499/2434.Using a Robot to Print the Lexicographically Smallest String/README_EN.md index e2a0366f95b64..028be62ce4fdd 100644 --- a/solution/2400-2499/2434.Using a Robot to Print the Lexicographically Smallest String/README_EN.md +++ b/solution/2400-2499/2434.Using a Robot to Print the Lexicographically Smallest String/README_EN.md @@ -93,6 +93,8 @@ The time complexity is $O(n+C)$, and the space complexity is $O(n)$. Here, $n$ i +#### Python3 + ```python class Solution: def robotWithString(self, s: str) -> str: @@ -110,6 +112,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String robotWithString(String s) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func robotWithString(s string) string { cnt := make([]int, 26) @@ -182,6 +190,8 @@ func robotWithString(s string) string { } ``` +#### TypeScript + ```ts function robotWithString(s: string): string { let cnt = new Array(128).fill(0); @@ -213,6 +223,8 @@ function robotWithString(s: string): string { +#### Python3 + ```python class Solution: def robotWithString(self, s: str) -> str: @@ -229,6 +241,8 @@ class Solution: return ''.join(ans) ``` +#### Java + ```java class Solution { public String robotWithString(String s) { @@ -252,6 +266,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/2400-2499/2435.Paths in Matrix Whose Sum Is Divisible by K/README.md b/solution/2400-2499/2435.Paths in Matrix Whose Sum Is Divisible by K/README.md index 919d846505614..f434ee713066d 100644 --- a/solution/2400-2499/2435.Paths in Matrix Whose Sum Is Divisible by K/README.md +++ b/solution/2400-2499/2435.Paths in Matrix Whose Sum Is Divisible by K/README.md @@ -86,6 +86,8 @@ $$ +#### Python3 + ```python class Solution: def numberOfPaths(self, grid: List[List[int]], k: int) -> int: @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int m; @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func numberOfPaths(grid [][]int, k int) int { m, n := len(grid), len(grid[0]) @@ -209,6 +217,8 @@ func numberOfPaths(grid [][]int, k int) int { } ``` +#### TypeScript + ```ts function numberOfPaths(grid: number[][], k: number): number { const MOD = 10 ** 9 + 7; @@ -255,6 +265,8 @@ $$ +#### Python3 + ```python class Solution: def numberOfPaths(self, grid: List[List[int]], k: int) -> int: @@ -274,6 +286,8 @@ class Solution: return dp[-1][-1][0] ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -301,6 +315,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -325,6 +341,8 @@ public: }; ``` +#### Go + ```go func numberOfPaths(grid [][]int, k int) int { m, n := len(grid), len(grid[0]) diff --git a/solution/2400-2499/2435.Paths in Matrix Whose Sum Is Divisible by K/README_EN.md b/solution/2400-2499/2435.Paths in Matrix Whose Sum Is Divisible by K/README_EN.md index a1f39cc3e07d7..3958a01ea6b17 100644 --- a/solution/2400-2499/2435.Paths in Matrix Whose Sum Is Divisible by K/README_EN.md +++ b/solution/2400-2499/2435.Paths in Matrix Whose Sum Is Divisible by K/README_EN.md @@ -85,6 +85,8 @@ The time complexity is $O(m \times n \times k)$, and the space complexity is $O( +#### Python3 + ```python class Solution: def numberOfPaths(self, grid: List[List[int]], k: int) -> int: @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int m; @@ -147,6 +151,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go func numberOfPaths(grid [][]int, k int) int { m, n := len(grid), len(grid[0]) @@ -208,6 +216,8 @@ func numberOfPaths(grid [][]int, k int) int { } ``` +#### TypeScript + ```ts function numberOfPaths(grid: number[][], k: number): number { const MOD = 10 ** 9 + 7; @@ -254,6 +264,8 @@ The time complexity is $O(m \times n \times k)$, and the space complexity is $O( +#### Python3 + ```python class Solution: def numberOfPaths(self, grid: List[List[int]], k: int) -> int: @@ -273,6 +285,8 @@ class Solution: return dp[-1][-1][0] ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -300,6 +314,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -324,6 +340,8 @@ public: }; ``` +#### Go + ```go func numberOfPaths(grid [][]int, k int) int { m, n := len(grid), len(grid[0]) diff --git a/solution/2400-2499/2436.Minimum Split Into Subarrays With GCD Greater Than One/README.md b/solution/2400-2499/2436.Minimum Split Into Subarrays With GCD Greater Than One/README.md index 95500522b7566..5e41c1d04f2dd 100644 --- a/solution/2400-2499/2436.Minimum Split Into Subarrays With GCD Greater Than One/README.md +++ b/solution/2400-2499/2436.Minimum Split Into Subarrays With GCD Greater Than One/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def minimumSplits(self, nums: List[int]) -> int: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumSplits(int[] nums) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func minimumSplits(nums []int) int { ans, g := 1, 0 @@ -158,6 +166,8 @@ func gcd(a, b int) int { } ``` +#### TypeScript + ```ts function minimumSplits(nums: number[]): number { let ans = 1; diff --git a/solution/2400-2499/2436.Minimum Split Into Subarrays With GCD Greater Than One/README_EN.md b/solution/2400-2499/2436.Minimum Split Into Subarrays With GCD Greater Than One/README_EN.md index fcddee510a936..265626b0a1d8d 100644 --- a/solution/2400-2499/2436.Minimum Split Into Subarrays With GCD Greater Than One/README_EN.md +++ b/solution/2400-2499/2436.Minimum Split Into Subarrays With GCD Greater Than One/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n \times \log m)$, where $n$ and $m$ are the length of +#### Python3 + ```python class Solution: def minimumSplits(self, nums: List[int]) -> int: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumSplits(int[] nums) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func minimumSplits(nums []int) int { ans, g := 1, 0 @@ -154,6 +162,8 @@ func gcd(a, b int) int { } ``` +#### TypeScript + ```ts function minimumSplits(nums: number[]): number { let ans = 1; diff --git a/solution/2400-2499/2437.Number of Valid Clock Times/README.md b/solution/2400-2499/2437.Number of Valid Clock Times/README.md index 9f6dd95facb56..76d6e4a45020a 100644 --- a/solution/2400-2499/2437.Number of Valid Clock Times/README.md +++ b/solution/2400-2499/2437.Number of Valid Clock Times/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def countTime(self, time: str) -> int: @@ -86,6 +88,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public int countTime(String time) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func countTime(time string) int { ans := 0 @@ -152,6 +160,8 @@ func countTime(time string) int { } ``` +#### TypeScript + ```ts function countTime(time: string): number { let ans = 0; @@ -172,6 +182,8 @@ function countTime(time: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_time(time: String) -> i32 { @@ -213,6 +225,8 @@ impl Solution { +#### Python3 + ```python class Solution: def countTime(self, time: str) -> int: @@ -227,6 +241,8 @@ class Solution: return f(time[:2], 24) * f(time[3:], 60) ``` +#### Java + ```java class Solution { public int countTime(String time) { @@ -245,6 +261,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -263,6 +281,8 @@ public: }; ``` +#### Go + ```go func countTime(time string) int { f := func(s string, m int) (cnt int) { @@ -279,6 +299,8 @@ func countTime(time string) int { } ``` +#### TypeScript + ```ts function countTime(time: string): number { const f = (s: string, m: number): number => { @@ -296,6 +318,8 @@ function countTime(time: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_time(time: String) -> i32 { diff --git a/solution/2400-2499/2437.Number of Valid Clock Times/README_EN.md b/solution/2400-2499/2437.Number of Valid Clock Times/README_EN.md index b8c31a35a9e11..969684cdebd02 100644 --- a/solution/2400-2499/2437.Number of Valid Clock Times/README_EN.md +++ b/solution/2400-2499/2437.Number of Valid Clock Times/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(24 \times 60)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def countTime(self, time: str) -> int: @@ -87,6 +89,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public int countTime(String time) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func countTime(time string) int { ans := 0 @@ -153,6 +161,8 @@ func countTime(time string) int { } ``` +#### TypeScript + ```ts function countTime(time: string): number { let ans = 0; @@ -173,6 +183,8 @@ function countTime(time: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_time(time: String) -> i32 { @@ -214,6 +226,8 @@ The time complexity is $O(24 + 60)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def countTime(self, time: str) -> int: @@ -228,6 +242,8 @@ class Solution: return f(time[:2], 24) * f(time[3:], 60) ``` +#### Java + ```java class Solution { public int countTime(String time) { @@ -246,6 +262,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -264,6 +282,8 @@ public: }; ``` +#### Go + ```go func countTime(time string) int { f := func(s string, m int) (cnt int) { @@ -280,6 +300,8 @@ func countTime(time string) int { } ``` +#### TypeScript + ```ts function countTime(time: string): number { const f = (s: string, m: number): number => { @@ -297,6 +319,8 @@ function countTime(time: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_time(time: String) -> i32 { diff --git a/solution/2400-2499/2438.Range Product Queries of Powers/README.md b/solution/2400-2499/2438.Range Product Queries of Powers/README.md index a1410661a4335..5f7f48e560173 100644 --- a/solution/2400-2499/2438.Range Product Queries of Powers/README.md +++ b/solution/2400-2499/2438.Range Product Queries of Powers/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def productQueries(self, n: int, queries: List[List[int]]) -> List[int]: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func productQueries(n int, queries [][]int) []int { var mod int = 1e9 + 7 diff --git a/solution/2400-2499/2438.Range Product Queries of Powers/README_EN.md b/solution/2400-2499/2438.Range Product Queries of Powers/README_EN.md index b674dfad90c6a..9c4df7b6e5e5f 100644 --- a/solution/2400-2499/2438.Range Product Queries of Powers/README_EN.md +++ b/solution/2400-2499/2438.Range Product Queries of Powers/README_EN.md @@ -73,6 +73,8 @@ The time complexity is $O(n \times \log n)$, ignoring the space consumption of t +#### Python3 + ```python class Solution: def productQueries(self, n: int, queries: List[List[int]]) -> List[int]: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func productQueries(n int, queries [][]int) []int { var mod int = 1e9 + 7 diff --git a/solution/2400-2499/2439.Minimize Maximum of Array/README.md b/solution/2400-2499/2439.Minimize Maximum of Array/README.md index dfa3bfdb82c48..3af14df0aece8 100644 --- a/solution/2400-2499/2439.Minimize Maximum of Array/README.md +++ b/solution/2400-2499/2439.Minimize Maximum of Array/README.md @@ -81,6 +81,8 @@ nums 中最大值为 5 。无法得到比 5 更小的最大值。 +#### Python3 + ```python class Solution: def minimizeArrayValue(self, nums: List[int]) -> int: @@ -100,6 +102,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { private int[] nums; @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func minimizeArrayValue(nums []int) int { check := func(mx int) bool { diff --git a/solution/2400-2499/2439.Minimize Maximum of Array/README_EN.md b/solution/2400-2499/2439.Minimize Maximum of Array/README_EN.md index 7b68bdb9417e5..689dc64771c8e 100644 --- a/solution/2400-2499/2439.Minimize Maximum of Array/README_EN.md +++ b/solution/2400-2499/2439.Minimize Maximum of Array/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(n \times \log M)$, where $n$ is the length of the arra +#### Python3 + ```python class Solution: def minimizeArrayValue(self, nums: List[int]) -> int: @@ -100,6 +102,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { private int[] nums; @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func minimizeArrayValue(nums []int) int { check := func(mx int) bool { diff --git a/solution/2400-2499/2440.Create Components With Same Value/README.md b/solution/2400-2499/2440.Create Components With Same Value/README.md index d58cdbdb1c2d0..1742f2cbaaca0 100644 --- a/solution/2400-2499/2440.Create Components With Same Value/README.md +++ b/solution/2400-2499/2440.Create Components With Same Value/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def componentValue(self, nums: List[int], edges: List[List[int]]) -> int: @@ -112,6 +114,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { private List[] g; @@ -175,6 +179,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -214,6 +220,8 @@ public: }; ``` +#### Go + ```go func componentValue(nums []int, edges [][]int) int { s, mx := 0, slices.Max(nums) diff --git a/solution/2400-2499/2440.Create Components With Same Value/README_EN.md b/solution/2400-2499/2440.Create Components With Same Value/README_EN.md index 8a2ce3bf5ffca..955f5d0fb7234 100644 --- a/solution/2400-2499/2440.Create Components With Same Value/README_EN.md +++ b/solution/2400-2499/2440.Create Components With Same Value/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(n \times \sqrt{s})$, where $n$ and $s$ are the length +#### Python3 + ```python class Solution: def componentValue(self, nums: List[int], edges: List[List[int]]) -> int: @@ -110,6 +112,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { private List[] g; @@ -173,6 +177,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -212,6 +218,8 @@ public: }; ``` +#### Go + ```go func componentValue(nums []int, edges [][]int) int { s, mx := 0, slices.Max(nums) diff --git a/solution/2400-2499/2441.Largest Positive Integer That Exists With Its Negative/README.md b/solution/2400-2499/2441.Largest Positive Integer That Exists With Its Negative/README.md index e05093cb6d188..8da0c5df6d51e 100644 --- a/solution/2400-2499/2441.Largest Positive Integer That Exists With Its Negative/README.md +++ b/solution/2400-2499/2441.Largest Positive Integer That Exists With Its Negative/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def findMaxK(self, nums: List[int]) -> int: @@ -86,6 +88,8 @@ class Solution: return max((x for x in s if -x in s), default=-1) ``` +#### Java + ```java class Solution { public int findMaxK(int[] nums) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func findMaxK(nums []int) int { ans := -1 @@ -136,6 +144,8 @@ func findMaxK(nums []int) int { } ``` +#### TypeScript + ```ts function findMaxK(nums: number[]): number { let ans = -1; @@ -149,6 +159,8 @@ function findMaxK(nums: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -175,6 +187,8 @@ impl Solution { +#### Rust + ```rust use std::collections::HashSet; diff --git a/solution/2400-2499/2441.Largest Positive Integer That Exists With Its Negative/README_EN.md b/solution/2400-2499/2441.Largest Positive Integer That Exists With Its Negative/README_EN.md index bc9ebf6709f5f..0cea9c1fb3861 100644 --- a/solution/2400-2499/2441.Largest Positive Integer That Exists With Its Negative/README_EN.md +++ b/solution/2400-2499/2441.Largest Positive Integer That Exists With Its Negative/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def findMaxK(self, nums: List[int]) -> int: @@ -84,6 +86,8 @@ class Solution: return max((x for x in s if -x in s), default=-1) ``` +#### Java + ```java class Solution { public int findMaxK(int[] nums) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func findMaxK(nums []int) int { ans := -1 @@ -134,6 +142,8 @@ func findMaxK(nums []int) int { } ``` +#### TypeScript + ```ts function findMaxK(nums: number[]): number { let ans = -1; @@ -147,6 +157,8 @@ function findMaxK(nums: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -173,6 +185,8 @@ impl Solution { +#### Rust + ```rust use std::collections::HashSet; diff --git a/solution/2400-2499/2442.Count Number of Distinct Integers After Reverse Operations/README.md b/solution/2400-2499/2442.Count Number of Distinct Integers After Reverse Operations/README.md index 1781b376aaea8..ccdf194337c68 100644 --- a/solution/2400-2499/2442.Count Number of Distinct Integers After Reverse Operations/README.md +++ b/solution/2400-2499/2442.Count Number of Distinct Integers After Reverse Operations/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: @@ -79,6 +81,8 @@ class Solution: return len(s) ``` +#### Java + ```java class Solution { public int countDistinctIntegers(int[] nums) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func countDistinctIntegers(nums []int) int { s := map[int]struct{}{} @@ -135,6 +143,8 @@ func countDistinctIntegers(nums []int) int { } ``` +#### TypeScript + ```ts function countDistinctIntegers(nums: number[]): number { const n = nums.length; @@ -145,6 +155,8 @@ function countDistinctIntegers(nums: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { diff --git a/solution/2400-2499/2442.Count Number of Distinct Integers After Reverse Operations/README_EN.md b/solution/2400-2499/2442.Count Number of Distinct Integers After Reverse Operations/README_EN.md index 3f4367b7ac3ba..cff712ccfdcf0 100644 --- a/solution/2400-2499/2442.Count Number of Distinct Integers After Reverse Operations/README_EN.md +++ b/solution/2400-2499/2442.Count Number of Distinct Integers After Reverse Operations/README_EN.md @@ -67,6 +67,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: @@ -77,6 +79,8 @@ class Solution: return len(s) ``` +#### Java + ```java class Solution { public int countDistinctIntegers(int[] nums) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func countDistinctIntegers(nums []int) int { s := map[int]struct{}{} @@ -133,6 +141,8 @@ func countDistinctIntegers(nums []int) int { } ``` +#### TypeScript + ```ts function countDistinctIntegers(nums: number[]): number { const n = nums.length; @@ -143,6 +153,8 @@ function countDistinctIntegers(nums: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { diff --git a/solution/2400-2499/2443.Sum of Number and Its Reverse/README.md b/solution/2400-2499/2443.Sum of Number and Its Reverse/README.md index ffbd5388b9fc2..fa68199348d9d 100644 --- a/solution/2400-2499/2443.Sum of Number and Its Reverse/README.md +++ b/solution/2400-2499/2443.Sum of Number and Its Reverse/README.md @@ -71,12 +71,16 @@ tags: +#### Python3 + ```python class Solution: def sumOfNumberAndReverse(self, num: int) -> bool: return any(k + int(str(k)[::-1]) == num for k in range(num + 1)) ``` +#### Java + ```java class Solution { public boolean sumOfNumberAndReverse(int num) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func sumOfNumberAndReverse(num int) bool { for x := 0; x <= num; x++ { @@ -132,6 +140,8 @@ func sumOfNumberAndReverse(num int) bool { } ``` +#### TypeScript + ```ts function sumOfNumberAndReverse(num: number): boolean { for (let i = 0; i <= num; i++) { @@ -143,6 +153,8 @@ function sumOfNumberAndReverse(num: number): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn sum_of_number_and_reverse(num: i32) -> bool { @@ -167,6 +179,8 @@ impl Solution { } ``` +#### C + ```c bool sumOfNumberAndReverse(int num) { for (int i = 0; i <= num; i++) { diff --git a/solution/2400-2499/2443.Sum of Number and Its Reverse/README_EN.md b/solution/2400-2499/2443.Sum of Number and Its Reverse/README_EN.md index 54de244de4d4b..cd4d9adaa9284 100644 --- a/solution/2400-2499/2443.Sum of Number and Its Reverse/README_EN.md +++ b/solution/2400-2499/2443.Sum of Number and Its Reverse/README_EN.md @@ -67,12 +67,16 @@ The time complexity is $O(n \times \log n)$, where $n$ is the size of $num$. +#### Python3 + ```python class Solution: def sumOfNumberAndReverse(self, num: int) -> bool: return any(k + int(str(k)[::-1]) == num for k in range(num + 1)) ``` +#### Java + ```java class Solution { public boolean sumOfNumberAndReverse(int num) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func sumOfNumberAndReverse(num int) bool { for x := 0; x <= num; x++ { @@ -128,6 +136,8 @@ func sumOfNumberAndReverse(num int) bool { } ``` +#### TypeScript + ```ts function sumOfNumberAndReverse(num: number): boolean { for (let i = 0; i <= num; i++) { @@ -139,6 +149,8 @@ function sumOfNumberAndReverse(num: number): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn sum_of_number_and_reverse(num: i32) -> bool { @@ -163,6 +175,8 @@ impl Solution { } ``` +#### C + ```c bool sumOfNumberAndReverse(int num) { for (int i = 0; i <= num; i++) { diff --git a/solution/2400-2499/2444.Count Subarrays With Fixed Bounds/README.md b/solution/2400-2499/2444.Count Subarrays With Fixed Bounds/README.md index 1fc6e13e877e2..b0e15a6ef5fb0 100644 --- a/solution/2400-2499/2444.Count Subarrays With Fixed Bounds/README.md +++ b/solution/2400-2499/2444.Count Subarrays With Fixed Bounds/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def countSubarrays(self, nums: List[int], minK: int, maxK: int) -> int: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long countSubarrays(int[] nums, int minK, int maxK) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func countSubarrays(nums []int, minK int, maxK int) int64 { ans := 0 @@ -155,6 +163,8 @@ func countSubarrays(nums []int, minK int, maxK int) int64 { } ``` +#### TypeScript + ```ts function countSubarrays(nums: number[], minK: number, maxK: number): number { let res = 0; @@ -177,6 +187,8 @@ function countSubarrays(nums: number[], minK: number, maxK: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_subarrays(nums: Vec, min_k: i32, max_k: i32) -> i64 { @@ -203,6 +215,8 @@ impl Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) #define min(a, b) (((a) < (b)) ? (a) : (b)) diff --git a/solution/2400-2499/2444.Count Subarrays With Fixed Bounds/README_EN.md b/solution/2400-2499/2444.Count Subarrays With Fixed Bounds/README_EN.md index cc4519de07e87..83e8bbb0189cd 100644 --- a/solution/2400-2499/2444.Count Subarrays With Fixed Bounds/README_EN.md +++ b/solution/2400-2499/2444.Count Subarrays With Fixed Bounds/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is +#### Python3 + ```python class Solution: def countSubarrays(self, nums: List[int], minK: int, maxK: int) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long countSubarrays(int[] nums, int minK, int maxK) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func countSubarrays(nums []int, minK int, maxK int) int64 { ans := 0 @@ -156,6 +164,8 @@ func countSubarrays(nums []int, minK int, maxK int) int64 { } ``` +#### TypeScript + ```ts function countSubarrays(nums: number[], minK: number, maxK: number): number { let res = 0; @@ -178,6 +188,8 @@ function countSubarrays(nums: number[], minK: number, maxK: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_subarrays(nums: Vec, min_k: i32, max_k: i32) -> i64 { @@ -204,6 +216,8 @@ impl Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) #define min(a, b) (((a) < (b)) ? (a) : (b)) diff --git a/solution/2400-2499/2445.Number of Nodes With Value One/README.md b/solution/2400-2499/2445.Number of Nodes With Value One/README.md index fdf527fc2972c..fa2ef7b41954c 100644 --- a/solution/2400-2499/2445.Number of Nodes With Value One/README.md +++ b/solution/2400-2499/2445.Number of Nodes With Value One/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfNodes(self, n: int, queries: List[int]) -> int: @@ -100,6 +102,8 @@ class Solution: return sum(tree) ``` +#### Java + ```java class Solution { private int[] tree; @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func numberOfNodes(n int, queries []int) int { tree := make([]int, n+1) diff --git a/solution/2400-2499/2445.Number of Nodes With Value One/README_EN.md b/solution/2400-2499/2445.Number of Nodes With Value One/README_EN.md index 0b1f705689308..c2512fb1457fd 100644 --- a/solution/2400-2499/2445.Number of Nodes With Value One/README_EN.md +++ b/solution/2400-2499/2445.Number of Nodes With Value One/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def numberOfNodes(self, n: int, queries: List[int]) -> int: @@ -98,6 +100,8 @@ class Solution: return sum(tree) ``` +#### Java + ```java class Solution { private int[] tree; @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func numberOfNodes(n int, queries []int) int { tree := make([]int, n+1) diff --git a/solution/2400-2499/2446.Determine if Two Events Have Conflict/README.md b/solution/2400-2499/2446.Determine if Two Events Have Conflict/README.md index ca8fd9a4b0a9a..7204c9dfb22d7 100644 --- a/solution/2400-2499/2446.Determine if Two Events Have Conflict/README.md +++ b/solution/2400-2499/2446.Determine if Two Events Have Conflict/README.md @@ -86,12 +86,16 @@ tags: +#### Python3 + ```python class Solution: def haveConflict(self, event1: List[str], event2: List[str]) -> bool: return not (event1[0] > event2[1] or event1[1] < event2[0]) ``` +#### Java + ```java class Solution { public boolean haveConflict(String[] event1, String[] event2) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,18 +115,24 @@ public: }; ``` +#### Go + ```go func haveConflict(event1 []string, event2 []string) bool { return !(event1[0] > event2[1] || event1[1] < event2[0]) } ``` +#### TypeScript + ```ts function haveConflict(event1: string[], event2: string[]): boolean { return !(event1[0] > event2[1] || event1[1] < event2[0]); } ``` +#### Rust + ```rust impl Solution { pub fn have_conflict(event1: Vec, event2: Vec) -> bool { diff --git a/solution/2400-2499/2446.Determine if Two Events Have Conflict/README_EN.md b/solution/2400-2499/2446.Determine if Two Events Have Conflict/README_EN.md index 749cbdc388998..5a255e2a5fdef 100644 --- a/solution/2400-2499/2446.Determine if Two Events Have Conflict/README_EN.md +++ b/solution/2400-2499/2446.Determine if Two Events Have Conflict/README_EN.md @@ -84,12 +84,16 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def haveConflict(self, event1: List[str], event2: List[str]) -> bool: return not (event1[0] > event2[1] or event1[1] < event2[0]) ``` +#### Java + ```java class Solution { public boolean haveConflict(String[] event1, String[] event2) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,18 +113,24 @@ public: }; ``` +#### Go + ```go func haveConflict(event1 []string, event2 []string) bool { return !(event1[0] > event2[1] || event1[1] < event2[0]) } ``` +#### TypeScript + ```ts function haveConflict(event1: string[], event2: string[]): boolean { return !(event1[0] > event2[1] || event1[1] < event2[0]); } ``` +#### Rust + ```rust impl Solution { pub fn have_conflict(event1: Vec, event2: Vec) -> bool { diff --git a/solution/2400-2499/2447.Number of Subarrays With GCD Equal to K/README.md b/solution/2400-2499/2447.Number of Subarrays With GCD Equal to K/README.md index 810914a426e60..91d49e17c58de 100644 --- a/solution/2400-2499/2447.Number of Subarrays With GCD Equal to K/README.md +++ b/solution/2400-2499/2447.Number of Subarrays With GCD Equal to K/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def subarrayGCD(self, nums: List[int], k: int) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int subarrayGCD(int[] nums, int k) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func subarrayGCD(nums []int, k int) (ans int) { for i := range nums { @@ -146,6 +154,8 @@ func gcd(a, b int) int { } ``` +#### TypeScript + ```ts function subarrayGCD(nums: number[], k: number): number { let ans = 0; diff --git a/solution/2400-2499/2447.Number of Subarrays With GCD Equal to K/README_EN.md b/solution/2400-2499/2447.Number of Subarrays With GCD Equal to K/README_EN.md index dc625de538dde..cec3ec32eef7c 100644 --- a/solution/2400-2499/2447.Number of Subarrays With GCD Equal to K/README_EN.md +++ b/solution/2400-2499/2447.Number of Subarrays With GCD Equal to K/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(n \times (n + \log M))$, where $n$ and $M$ are the len +#### Python3 + ```python class Solution: def subarrayGCD(self, nums: List[int], k: int) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int subarrayGCD(int[] nums, int k) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func subarrayGCD(nums []int, k int) (ans int) { for i := range nums { @@ -146,6 +154,8 @@ func gcd(a, b int) int { } ``` +#### TypeScript + ```ts function subarrayGCD(nums: number[], k: number): number { let ans = 0; diff --git a/solution/2400-2499/2448.Minimum Cost to Make Array Equal/README.md b/solution/2400-2499/2448.Minimum Cost to Make Array Equal/README.md index 1594c9ed81979..78b0cf35fd98b 100644 --- a/solution/2400-2499/2448.Minimum Cost to Make Array Equal/README.md +++ b/solution/2400-2499/2448.Minimum Cost to Make Array Equal/README.md @@ -97,6 +97,8 @@ $$ +#### Python3 + ```python class Solution: def minCost(self, nums: List[int], cost: List[int]) -> int: @@ -117,6 +119,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long minCost(int[] nums, int[] cost) { @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go func minCost(nums []int, cost []int) int64 { n := len(nums) @@ -201,6 +209,8 @@ func minCost(nums []int, cost []int) int64 { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -268,6 +278,8 @@ impl Solution { +#### Python3 + ```python class Solution: def minCost(self, nums: List[int], cost: List[int]) -> int: @@ -280,6 +292,8 @@ class Solution: return sum(abs(v - x) * c for v, c in arr) ``` +#### Java + ```java class Solution { public long minCost(int[] nums, int[] cost) { @@ -314,6 +328,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -340,6 +356,8 @@ public: }; ``` +#### Go + ```go func minCost(nums []int, cost []int) int64 { n := len(nums) diff --git a/solution/2400-2499/2448.Minimum Cost to Make Array Equal/README_EN.md b/solution/2400-2499/2448.Minimum Cost to Make Array Equal/README_EN.md index afda96ded9de7..83411a63ed933 100644 --- a/solution/2400-2499/2448.Minimum Cost to Make Array Equal/README_EN.md +++ b/solution/2400-2499/2448.Minimum Cost to Make Array Equal/README_EN.md @@ -95,6 +95,8 @@ The time complexity is $O(n\times \log n)$, where $n$ is the length of the array +#### Python3 + ```python class Solution: def minCost(self, nums: List[int], cost: List[int]) -> int: @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long minCost(int[] nums, int[] cost) { @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func minCost(nums []int, cost []int) int64 { n := len(nums) @@ -199,6 +207,8 @@ func minCost(nums []int, cost []int) int64 { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] @@ -266,6 +276,8 @@ Similar problems: +#### Python3 + ```python class Solution: def minCost(self, nums: List[int], cost: List[int]) -> int: @@ -278,6 +290,8 @@ class Solution: return sum(abs(v - x) * c for v, c in arr) ``` +#### Java + ```java class Solution { public long minCost(int[] nums, int[] cost) { @@ -312,6 +326,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -338,6 +354,8 @@ public: }; ``` +#### Go + ```go func minCost(nums []int, cost []int) int64 { n := len(nums) diff --git a/solution/2400-2499/2449.Minimum Number of Operations to Make Arrays Similar/README.md b/solution/2400-2499/2449.Minimum Number of Operations to Make Arrays Similar/README.md index 74146d33a7f82..33b1646f87284 100644 --- a/solution/2400-2499/2449.Minimum Number of Operations to Make Arrays Similar/README.md +++ b/solution/2400-2499/2449.Minimum Number of Operations to Make Arrays Similar/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class Solution: def makeSimilar(self, nums: List[int], target: List[int]) -> int: @@ -102,6 +104,8 @@ class Solution: return sum(abs(a - b) for a, b in zip(nums, target)) // 4 ``` +#### Java + ```java class Solution { public long makeSimilar(int[] nums, int[] target) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func makeSimilar(nums []int, target []int) int64 { sort.Ints(nums) @@ -204,6 +212,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function makeSimilar(nums: number[], target: number[]): number { nums.sort((a, b) => a - b); diff --git a/solution/2400-2499/2449.Minimum Number of Operations to Make Arrays Similar/README_EN.md b/solution/2400-2499/2449.Minimum Number of Operations to Make Arrays Similar/README_EN.md index 0ee67d937c3f0..83499610ac08a 100644 --- a/solution/2400-2499/2449.Minimum Number of Operations to Make Arrays Similar/README_EN.md +++ b/solution/2400-2499/2449.Minimum Number of Operations to Make Arrays Similar/README_EN.md @@ -92,6 +92,8 @@ The time complexity is $O(n \times \log n)$, where $n$ is the length of the arra +#### Python3 + ```python class Solution: def makeSimilar(self, nums: List[int], target: List[int]) -> int: @@ -100,6 +102,8 @@ class Solution: return sum(abs(a - b) for a, b in zip(nums, target)) // 4 ``` +#### Java + ```java class Solution { public long makeSimilar(int[] nums, int[] target) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func makeSimilar(nums []int, target []int) int64 { sort.Ints(nums) @@ -202,6 +210,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function makeSimilar(nums: number[], target: number[]): number { nums.sort((a, b) => a - b); diff --git a/solution/2400-2499/2450.Number of Distinct Binary Strings After Applying Operations/README.md b/solution/2400-2499/2450.Number of Distinct Binary Strings After Applying Operations/README.md index 20178e822688d..fe077295c8d37 100644 --- a/solution/2400-2499/2450.Number of Distinct Binary Strings After Applying Operations/README.md +++ b/solution/2400-2499/2450.Number of Distinct Binary Strings After Applying Operations/README.md @@ -84,12 +84,16 @@ tags: +#### Python3 + ```python class Solution: def countDistinctStrings(self, s: str, k: int) -> int: return pow(2, len(s) - k + 1) % (10**9 + 7) ``` +#### Java + ```java class Solution { public static final int MOD = (int) 1e9 + 7; @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func countDistinctStrings(s string, k int) int { const mod int = 1e9 + 7 diff --git a/solution/2400-2499/2450.Number of Distinct Binary Strings After Applying Operations/README_EN.md b/solution/2400-2499/2450.Number of Distinct Binary Strings After Applying Operations/README_EN.md index e0b294dbd0f3f..e75cee0111776 100644 --- a/solution/2400-2499/2450.Number of Distinct Binary Strings After Applying Operations/README_EN.md +++ b/solution/2400-2499/2450.Number of Distinct Binary Strings After Applying Operations/README_EN.md @@ -80,12 +80,16 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is +#### Python3 + ```python class Solution: def countDistinctStrings(self, s: str, k: int) -> int: return pow(2, len(s) - k + 1) % (10**9 + 7) ``` +#### Java + ```java class Solution { public static final int MOD = (int) 1e9 + 7; @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func countDistinctStrings(s string, k int) int { const mod int = 1e9 + 7 diff --git a/solution/2400-2499/2451.Odd String Difference/README.md b/solution/2400-2499/2451.Odd String Difference/README.md index 128264ebc2d18..f0cd98f872e72 100644 --- a/solution/2400-2499/2451.Odd String Difference/README.md +++ b/solution/2400-2499/2451.Odd String Difference/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def oddString(self, words: List[str]) -> str: @@ -89,6 +91,8 @@ class Solution: return next(ss[0] for ss in d.values() if len(ss) == 1) ``` +#### Java + ```java class Solution { public String oddString(String[] words) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func oddString(words []string) string { d := map[string][]string{} @@ -157,6 +165,8 @@ func oddString(words []string) string { } ``` +#### TypeScript + ```ts function oddString(words: string[]): string { const d: Map = new Map(); @@ -180,6 +190,8 @@ function oddString(words: string[]): string { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { @@ -215,6 +227,8 @@ impl Solution { +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/2400-2499/2451.Odd String Difference/README_EN.md b/solution/2400-2499/2451.Odd String Difference/README_EN.md index 1fd0f2b8e57ee..3ef807f7ba30f 100644 --- a/solution/2400-2499/2451.Odd String Difference/README_EN.md +++ b/solution/2400-2499/2451.Odd String Difference/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m + n)$. +#### Python3 + ```python class Solution: def oddString(self, words: List[str]) -> str: @@ -87,6 +89,8 @@ class Solution: return next(ss[0] for ss in d.values() if len(ss) == 1) ``` +#### Java + ```java class Solution { public String oddString(String[] words) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func oddString(words []string) string { d := map[string][]string{} @@ -155,6 +163,8 @@ func oddString(words []string) string { } ``` +#### TypeScript + ```ts function oddString(words: string[]): string { const d: Map = new Map(); @@ -178,6 +188,8 @@ function oddString(words: string[]): string { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { @@ -213,6 +225,8 @@ impl Solution { +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/2400-2499/2452.Words Within Two Edits of Dictionary/README.md b/solution/2400-2499/2452.Words Within Two Edits of Dictionary/README.md index 310df295d8019..3cc3665d5f4e6 100644 --- a/solution/2400-2499/2452.Words Within Two Edits of Dictionary/README.md +++ b/solution/2400-2499/2452.Words Within Two Edits of Dictionary/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def twoEditWords(self, queries: List[str], dictionary: List[str]) -> List[str]: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List twoEditWords(String[] queries, String[] dictionary) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func twoEditWords(queries []string, dictionary []string) (ans []string) { for _, s := range queries { @@ -151,6 +159,8 @@ func twoEditWords(queries []string, dictionary []string) (ans []string) { } ``` +#### TypeScript + ```ts function twoEditWords(queries: string[], dictionary: string[]): string[] { const n = queries[0].length; @@ -171,6 +181,8 @@ function twoEditWords(queries: string[], dictionary: string[]): string[] { } ``` +#### Rust + ```rust impl Solution { pub fn two_edit_words(queries: Vec, dictionary: Vec) -> Vec { @@ -190,6 +202,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public IList TwoEditWords(string[] queries, string[] dictionary) { diff --git a/solution/2400-2499/2452.Words Within Two Edits of Dictionary/README_EN.md b/solution/2400-2499/2452.Words Within Two Edits of Dictionary/README_EN.md index f82ba238786e9..deef5fc710905 100644 --- a/solution/2400-2499/2452.Words Within Two Edits of Dictionary/README_EN.md +++ b/solution/2400-2499/2452.Words Within Two Edits of Dictionary/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(m \times n \times l)$, where $m$ and $n$ are the lengt +#### Python3 + ```python class Solution: def twoEditWords(self, queries: List[str], dictionary: List[str]) -> List[str]: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List twoEditWords(String[] queries, String[] dictionary) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func twoEditWords(queries []string, dictionary []string) (ans []string) { for _, s := range queries { @@ -150,6 +158,8 @@ func twoEditWords(queries []string, dictionary []string) (ans []string) { } ``` +#### TypeScript + ```ts function twoEditWords(queries: string[], dictionary: string[]): string[] { const n = queries[0].length; @@ -170,6 +180,8 @@ function twoEditWords(queries: string[], dictionary: string[]): string[] { } ``` +#### Rust + ```rust impl Solution { pub fn two_edit_words(queries: Vec, dictionary: Vec) -> Vec { @@ -189,6 +201,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public IList TwoEditWords(string[] queries, string[] dictionary) { diff --git a/solution/2400-2499/2453.Destroy Sequential Targets/README.md b/solution/2400-2499/2453.Destroy Sequential Targets/README.md index e9f9a8c73a9dc..b98202b9692de 100644 --- a/solution/2400-2499/2453.Destroy Sequential Targets/README.md +++ b/solution/2400-2499/2453.Destroy Sequential Targets/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def destroyTargets(self, nums: List[int], space: int) -> int: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int destroyTargets(int[] nums, int space) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func destroyTargets(nums []int, space int) int { cnt := map[int]int{} diff --git a/solution/2400-2499/2453.Destroy Sequential Targets/README_EN.md b/solution/2400-2499/2453.Destroy Sequential Targets/README_EN.md index ae7efc75f746a..02a0dd98a5137 100644 --- a/solution/2400-2499/2453.Destroy Sequential Targets/README_EN.md +++ b/solution/2400-2499/2453.Destroy Sequential Targets/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def destroyTargets(self, nums: List[int], space: int) -> int: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int destroyTargets(int[] nums, int space) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func destroyTargets(nums []int, space int) int { cnt := map[int]int{} diff --git a/solution/2400-2499/2454.Next Greater Element IV/README.md b/solution/2400-2499/2454.Next Greater Element IV/README.md index 0fdcc19643597..347666767adcf 100644 --- a/solution/2400-2499/2454.Next Greater Element IV/README.md +++ b/solution/2400-2499/2454.Next Greater Element IV/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python from sortedcontainers import SortedList @@ -110,6 +112,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] secondGreaterElement(int[] nums) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### TypeScript + ```ts function secondGreaterElement(nums: number[]): number[] { const n = nums.length; diff --git a/solution/2400-2499/2454.Next Greater Element IV/README_EN.md b/solution/2400-2499/2454.Next Greater Element IV/README_EN.md index 3f7ee3b5a091e..c9993558b5303 100644 --- a/solution/2400-2499/2454.Next Greater Element IV/README_EN.md +++ b/solution/2400-2499/2454.Next Greater Element IV/README_EN.md @@ -89,6 +89,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python from sortedcontainers import SortedList @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] secondGreaterElement(int[] nums) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### TypeScript + ```ts function secondGreaterElement(nums: number[]): number[] { const n = nums.length; diff --git a/solution/2400-2499/2455.Average Value of Even Numbers That Are Divisible by Three/README.md b/solution/2400-2499/2455.Average Value of Even Numbers That Are Divisible by Three/README.md index 19d2327fac9e2..c4e4df207aef1 100644 --- a/solution/2400-2499/2455.Average Value of Even Numbers That Are Divisible by Three/README.md +++ b/solution/2400-2499/2455.Average Value of Even Numbers That Are Divisible by Three/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def averageValue(self, nums: List[int]) -> int: @@ -75,6 +77,8 @@ class Solution: return 0 if n == 0 else s // n ``` +#### Java + ```java class Solution { public int averageValue(int[] nums) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func averageValue(nums []int) int { var s, n int @@ -122,6 +130,8 @@ func averageValue(nums []int) int { } ``` +#### TypeScript + ```ts function averageValue(nums: number[]): number { let s = 0; @@ -136,6 +146,8 @@ function averageValue(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn average_value(nums: Vec) -> i32 { @@ -155,6 +167,8 @@ impl Solution { } ``` +#### C + ```c int averageValue(int* nums, int numsSize) { int s = 0, n = 0; @@ -178,6 +192,8 @@ int averageValue(int* nums, int numsSize) { +#### Rust + ```rust impl Solution { pub fn average_value(nums: Vec) -> i32 { diff --git a/solution/2400-2499/2455.Average Value of Even Numbers That Are Divisible by Three/README_EN.md b/solution/2400-2499/2455.Average Value of Even Numbers That Are Divisible by Three/README_EN.md index ef8d24a6c9526..e29ad2cc572e3 100644 --- a/solution/2400-2499/2455.Average Value of Even Numbers That Are Divisible by Three/README_EN.md +++ b/solution/2400-2499/2455.Average Value of Even Numbers That Are Divisible by Three/README_EN.md @@ -62,6 +62,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def averageValue(self, nums: List[int]) -> int: @@ -73,6 +75,8 @@ class Solution: return 0 if n == 0 else s // n ``` +#### Java + ```java class Solution { public int averageValue(int[] nums) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -104,6 +110,8 @@ public: }; ``` +#### Go + ```go func averageValue(nums []int) int { var s, n int @@ -120,6 +128,8 @@ func averageValue(nums []int) int { } ``` +#### TypeScript + ```ts function averageValue(nums: number[]): number { let s = 0; @@ -134,6 +144,8 @@ function averageValue(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn average_value(nums: Vec) -> i32 { @@ -153,6 +165,8 @@ impl Solution { } ``` +#### C + ```c int averageValue(int* nums, int numsSize) { int s = 0, n = 0; @@ -176,6 +190,8 @@ int averageValue(int* nums, int numsSize) { +#### Rust + ```rust impl Solution { pub fn average_value(nums: Vec) -> i32 { diff --git a/solution/2400-2499/2456.Most Popular Video Creator/README.md b/solution/2400-2499/2456.Most Popular Video Creator/README.md index 2a551633e63b9..4d588a731bbdc 100644 --- a/solution/2400-2499/2456.Most Popular Video Creator/README.md +++ b/solution/2400-2499/2456.Most Popular Video Creator/README.md @@ -87,6 +87,8 @@ id 为 "b" 和 "c" 的视频都满足播放量最高的条件。 +#### Python3 + ```python class Solution: def mostPopularCreator( @@ -102,6 +104,8 @@ class Solution: return [[c, ids[d[c]]] for c, x in cnt.items() if x == mx] ``` +#### Java + ```java class Solution { public List> mostPopularCreator(String[] creators, String[] ids, int[] views) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func mostPopularCreator(creators []string, ids []string, views []int) (ans [][]string) { cnt := map[string]int{} @@ -189,6 +197,8 @@ func mostPopularCreator(creators []string, ids []string, views []int) (ans [][]s } ``` +#### TypeScript + ```ts function mostPopularCreator(creators: string[], ids: string[], views: number[]): string[][] { const cnt: Map = new Map(); diff --git a/solution/2400-2499/2456.Most Popular Video Creator/README_EN.md b/solution/2400-2499/2456.Most Popular Video Creator/README_EN.md index d3f4f8bef12bb..9c04d49793fdd 100644 --- a/solution/2400-2499/2456.Most Popular Video Creator/README_EN.md +++ b/solution/2400-2499/2456.Most Popular Video Creator/README_EN.md @@ -85,6 +85,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def mostPopularCreator( @@ -100,6 +102,8 @@ class Solution: return [[c, ids[d[c]]] for c, x in cnt.items() if x == mx] ``` +#### Java + ```java class Solution { public List> mostPopularCreator(String[] creators, String[] ids, int[] views) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func mostPopularCreator(creators []string, ids []string, views []int) (ans [][]string) { cnt := map[string]int{} @@ -187,6 +195,8 @@ func mostPopularCreator(creators []string, ids []string, views []int) (ans [][]s } ``` +#### TypeScript + ```ts function mostPopularCreator(creators: string[], ids: string[], views: number[]): string[][] { const cnt: Map = new Map(); diff --git a/solution/2400-2499/2457.Minimum Addition to Make Integer Beautiful/README.md b/solution/2400-2499/2457.Minimum Addition to Make Integer Beautiful/README.md index 47a51155af989..f7d549343b42f 100644 --- a/solution/2400-2499/2457.Minimum Addition to Make Integer Beautiful/README.md +++ b/solution/2400-2499/2457.Minimum Addition to Make Integer Beautiful/README.md @@ -86,6 +86,8 @@ $$ +#### Python3 + ```python class Solution: def makeIntegerBeautiful(self, n: int, target: int) -> int: @@ -107,6 +109,8 @@ class Solution: return x ``` +#### Java + ```java class Solution { public long makeIntegerBeautiful(long n, int target) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func makeIntegerBeautiful(n int64, target int) (x int64) { f := func(x int64) (y int) { @@ -184,6 +192,8 @@ func makeIntegerBeautiful(n int64, target int) (x int64) { } ``` +#### TypeScript + ```ts function makeIntegerBeautiful(n: number, target: number): number { const f = (x: number): number => { diff --git a/solution/2400-2499/2457.Minimum Addition to Make Integer Beautiful/README_EN.md b/solution/2400-2499/2457.Minimum Addition to Make Integer Beautiful/README_EN.md index ed9087a7f73f2..d532868ea5526 100644 --- a/solution/2400-2499/2457.Minimum Addition to Make Integer Beautiful/README_EN.md +++ b/solution/2400-2499/2457.Minimum Addition to Make Integer Beautiful/README_EN.md @@ -88,6 +88,8 @@ The time complexity is $O(\log^2 n)$, where $n$ is the integer given in the prob +#### Python3 + ```python class Solution: def makeIntegerBeautiful(self, n: int, target: int) -> int: @@ -109,6 +111,8 @@ class Solution: return x ``` +#### Java + ```java class Solution { public long makeIntegerBeautiful(long n, int target) { @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func makeIntegerBeautiful(n int64, target int) (x int64) { f := func(x int64) (y int) { @@ -186,6 +194,8 @@ func makeIntegerBeautiful(n int64, target int) (x int64) { } ``` +#### TypeScript + ```ts function makeIntegerBeautiful(n: number, target: number): number { const f = (x: number): number => { diff --git a/solution/2400-2499/2458.Height of Binary Tree After Subtree Removal Queries/README.md b/solution/2400-2499/2458.Height of Binary Tree After Subtree Removal Queries/README.md index 793b7607a8668..15fb797234463 100644 --- a/solution/2400-2499/2458.Height of Binary Tree After Subtree Removal Queries/README.md +++ b/solution/2400-2499/2458.Height of Binary Tree After Subtree Removal Queries/README.md @@ -113,6 +113,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -144,6 +146,8 @@ class Solution: return [res[v] for v in queries] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -198,6 +202,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -237,6 +243,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/2400-2499/2458.Height of Binary Tree After Subtree Removal Queries/README_EN.md b/solution/2400-2499/2458.Height of Binary Tree After Subtree Removal Queries/README_EN.md index 123ec4ee7022f..f87176a740fe2 100644 --- a/solution/2400-2499/2458.Height of Binary Tree After Subtree Removal Queries/README_EN.md +++ b/solution/2400-2499/2458.Height of Binary Tree After Subtree Removal Queries/README_EN.md @@ -107,6 +107,8 @@ The time complexity is $O(n+m)$, and the space complexity is $O(n)$. Here, $n$ a +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -138,6 +140,8 @@ class Solution: return [res[v] for v in queries] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -192,6 +196,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -231,6 +237,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/2400-2499/2459.Sort Array by Moving Items to Empty Space/README.md b/solution/2400-2499/2459.Sort Array by Moving Items to Empty Space/README.md index a494f19726009..05644fe0356a8 100644 --- a/solution/2400-2499/2459.Sort Array by Moving Items to Empty Space/README.md +++ b/solution/2400-2499/2459.Sort Array by Moving Items to Empty Space/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class Solution: def sortArray(self, nums: List[int]) -> int: @@ -117,6 +119,8 @@ class Solution: return min(a, b) ``` +#### Java + ```java class Solution { public int sortArray(int[] nums) { @@ -153,6 +157,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -184,6 +190,8 @@ public: }; ``` +#### Go + ```go func sortArray(nums []int) int { n := len(nums) diff --git a/solution/2400-2499/2459.Sort Array by Moving Items to Empty Space/README_EN.md b/solution/2400-2499/2459.Sort Array by Moving Items to Empty Space/README_EN.md index 7a2a1014d6643..353a7acb2100f 100644 --- a/solution/2400-2499/2459.Sort Array by Moving Items to Empty Space/README_EN.md +++ b/solution/2400-2499/2459.Sort Array by Moving Items to Empty Space/README_EN.md @@ -93,6 +93,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def sortArray(self, nums: List[int]) -> int: @@ -116,6 +118,8 @@ class Solution: return min(a, b) ``` +#### Java + ```java class Solution { public int sortArray(int[] nums) { @@ -152,6 +156,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -183,6 +189,8 @@ public: }; ``` +#### Go + ```go func sortArray(nums []int) int { n := len(nums) diff --git a/solution/2400-2499/2460.Apply Operations to an Array/README.md b/solution/2400-2499/2460.Apply Operations to an Array/README.md index cb57a9f670d6f..8864c0644fa07 100644 --- a/solution/2400-2499/2460.Apply Operations to an Array/README.md +++ b/solution/2400-2499/2460.Apply Operations to an Array/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def applyOperations(self, nums: List[int]) -> List[int]: @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] applyOperations(int[] nums) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func applyOperations(nums []int) []int { n := len(nums) @@ -174,6 +182,8 @@ func applyOperations(nums []int) []int { } ``` +#### TypeScript + ```ts function applyOperations(nums: number[]): number[] { const n = nums.length; @@ -194,6 +204,8 @@ function applyOperations(nums: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn apply_operations(nums: Vec) -> Vec { diff --git a/solution/2400-2499/2460.Apply Operations to an Array/README_EN.md b/solution/2400-2499/2460.Apply Operations to an Array/README_EN.md index 33c408f6afb97..108437b0174ea 100644 --- a/solution/2400-2499/2460.Apply Operations to an Array/README_EN.md +++ b/solution/2400-2499/2460.Apply Operations to an Array/README_EN.md @@ -89,6 +89,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. Igno +#### Python3 + ```python class Solution: def applyOperations(self, nums: List[int]) -> List[int]: @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] applyOperations(int[] nums) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func applyOperations(nums []int) []int { n := len(nums) @@ -172,6 +180,8 @@ func applyOperations(nums []int) []int { } ``` +#### TypeScript + ```ts function applyOperations(nums: number[]): number[] { const n = nums.length; @@ -192,6 +202,8 @@ function applyOperations(nums: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn apply_operations(nums: Vec) -> Vec { diff --git a/solution/2400-2499/2461.Maximum Sum of Distinct Subarrays With Length K/README.md b/solution/2400-2499/2461.Maximum Sum of Distinct Subarrays With Length K/README.md index b6d493c8a78f8..5b1e969bb0499 100644 --- a/solution/2400-2499/2461.Maximum Sum of Distinct Subarrays With Length K/README.md +++ b/solution/2400-2499/2461.Maximum Sum of Distinct Subarrays With Length K/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def maximumSubarraySum(self, nums: List[int], k: int) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maximumSubarraySum(int[] nums, int k) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func maximumSubarraySum(nums []int, k int) (ans int64) { n := len(nums) @@ -176,6 +184,8 @@ func maximumSubarraySum(nums []int, k int) (ans int64) { } ``` +#### TypeScript + ```ts function maximumSubarraySum(nums: number[], k: number): number { const n = nums.length; @@ -201,6 +211,8 @@ function maximumSubarraySum(nums: number[], k: number): number { } ``` +#### C# + ```cs public class Solution { public long MaximumSubarraySum(int[] nums, int k) { diff --git a/solution/2400-2499/2461.Maximum Sum of Distinct Subarrays With Length K/README_EN.md b/solution/2400-2499/2461.Maximum Sum of Distinct Subarrays With Length K/README_EN.md index caa3db2375bfa..5a9bf628aa080 100644 --- a/solution/2400-2499/2461.Maximum Sum of Distinct Subarrays With Length K/README_EN.md +++ b/solution/2400-2499/2461.Maximum Sum of Distinct Subarrays With Length K/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def maximumSubarraySum(self, nums: List[int], k: int) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maximumSubarraySum(int[] nums, int k) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func maximumSubarraySum(nums []int, k int) (ans int64) { n := len(nums) @@ -176,6 +184,8 @@ func maximumSubarraySum(nums []int, k int) (ans int64) { } ``` +#### TypeScript + ```ts function maximumSubarraySum(nums: number[], k: number): number { const n = nums.length; @@ -201,6 +211,8 @@ function maximumSubarraySum(nums: number[], k: number): number { } ``` +#### C# + ```cs public class Solution { public long MaximumSubarraySum(int[] nums, int k) { diff --git a/solution/2400-2499/2462.Total Cost to Hire K Workers/README.md b/solution/2400-2499/2462.Total Cost to Hire K Workers/README.md index c55bedc032edd..aaede43410030 100644 --- a/solution/2400-2499/2462.Total Cost to Hire K Workers/README.md +++ b/solution/2400-2499/2462.Total Cost to Hire K Workers/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python class Solution: def totalCost(self, costs: List[int], k: int, candidates: int) -> int: @@ -123,6 +125,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long totalCost(int[] costs, int k, int candidates) { @@ -159,6 +163,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -194,6 +200,8 @@ public: }; ``` +#### Go + ```go func totalCost(costs []int, k int, candidates int) (ans int64) { n := len(costs) @@ -239,6 +247,8 @@ func (h *hp) Push(v any) { *h = append(*h, v.(pair)) } func (h *hp) Pop() any { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; return v } ``` +#### TypeScript + ```ts function totalCost(costs: number[], k: number, candidates: number): number { const n = costs.length; diff --git a/solution/2400-2499/2462.Total Cost to Hire K Workers/README_EN.md b/solution/2400-2499/2462.Total Cost to Hire K Workers/README_EN.md index c0de42f033da7..e5e31227b3edd 100644 --- a/solution/2400-2499/2462.Total Cost to Hire K Workers/README_EN.md +++ b/solution/2400-2499/2462.Total Cost to Hire K Workers/README_EN.md @@ -95,6 +95,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def totalCost(self, costs: List[int], k: int, candidates: int) -> int: @@ -123,6 +125,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long totalCost(int[] costs, int k, int candidates) { @@ -159,6 +163,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -194,6 +200,8 @@ public: }; ``` +#### Go + ```go func totalCost(costs []int, k int, candidates int) (ans int64) { n := len(costs) @@ -239,6 +247,8 @@ func (h *hp) Push(v any) { *h = append(*h, v.(pair)) } func (h *hp) Pop() any { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; return v } ``` +#### TypeScript + ```ts function totalCost(costs: number[], k: number, candidates: number): number { const n = costs.length; diff --git a/solution/2400-2499/2463.Minimum Total Distance Traveled/README.md b/solution/2400-2499/2463.Minimum Total Distance Traveled/README.md index 2dc7b0105d3a0..ec620f6250e62 100644 --- a/solution/2400-2499/2463.Minimum Total Distance Traveled/README.md +++ b/solution/2400-2499/2463.Minimum Total Distance Traveled/README.md @@ -101,6 +101,8 @@ tags: +#### Python3 + ```python class Solution: def minimumTotalDistance(self, robot: List[int], factory: List[List[int]]) -> int: @@ -126,6 +128,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private long[][] f; @@ -166,6 +170,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -194,6 +200,8 @@ public: }; ``` +#### Go + ```go func minimumTotalDistance(robot []int, factory [][]int) int64 { sort.Ints(robot) diff --git a/solution/2400-2499/2463.Minimum Total Distance Traveled/README_EN.md b/solution/2400-2499/2463.Minimum Total Distance Traveled/README_EN.md index a6797f733497a..7545088dd0945 100644 --- a/solution/2400-2499/2463.Minimum Total Distance Traveled/README_EN.md +++ b/solution/2400-2499/2463.Minimum Total Distance Traveled/README_EN.md @@ -95,6 +95,8 @@ The time complexity is $O(m^2 \times n)$, and the space complexity is $O(m \time +#### Python3 + ```python class Solution: def minimumTotalDistance(self, robot: List[int], factory: List[List[int]]) -> int: @@ -120,6 +122,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private long[][] f; @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go func minimumTotalDistance(robot []int, factory [][]int) int64 { sort.Ints(robot) diff --git a/solution/2400-2499/2464.Minimum Subarrays in a Valid Split/README.md b/solution/2400-2499/2464.Minimum Subarrays in a Valid Split/README.md index d079dfe3dfcb2..d394e35eabb05 100644 --- a/solution/2400-2499/2464.Minimum Subarrays in a Valid Split/README.md +++ b/solution/2400-2499/2464.Minimum Subarrays in a Valid Split/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def validSubarraySplit(self, nums: List[int]) -> int: @@ -110,6 +112,8 @@ class Solution: return ans if ans < inf else -1 ``` +#### Java + ```java class Solution { private int n; @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go func validSubarraySplit(nums []int) int { n := len(nums) diff --git a/solution/2400-2499/2464.Minimum Subarrays in a Valid Split/README_EN.md b/solution/2400-2499/2464.Minimum Subarrays in a Valid Split/README_EN.md index 1042c8033138c..940f0674e899a 100644 --- a/solution/2400-2499/2464.Minimum Subarrays in a Valid Split/README_EN.md +++ b/solution/2400-2499/2464.Minimum Subarrays in a Valid Split/README_EN.md @@ -90,6 +90,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$. Here, $n$ i +#### Python3 + ```python class Solution: def validSubarraySplit(self, nums: List[int]) -> int: @@ -109,6 +111,8 @@ class Solution: return ans if ans < inf else -1 ``` +#### Java + ```java class Solution { private int n; @@ -147,6 +151,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go func validSubarraySplit(nums []int) int { n := len(nums) diff --git a/solution/2400-2499/2465.Number of Distinct Averages/README.md b/solution/2400-2499/2465.Number of Distinct Averages/README.md index 26636c15b9609..1a0f279b514b5 100644 --- a/solution/2400-2499/2465.Number of Distinct Averages/README.md +++ b/solution/2400-2499/2465.Number of Distinct Averages/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def distinctAverages(self, nums: List[int]) -> int: @@ -93,6 +95,8 @@ class Solution: return len(set(nums[i] + nums[-i - 1] for i in range(len(nums) >> 1))) ``` +#### Java + ```java class Solution { public int distinctAverages(int[] nums) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func distinctAverages(nums []int) (ans int) { sort.Ints(nums) @@ -134,6 +142,8 @@ func distinctAverages(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function distinctAverages(nums: number[]): number { nums.sort((a, b) => a - b); @@ -146,6 +156,8 @@ function distinctAverages(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn distinct_averages(nums: Vec) -> i32 { @@ -179,6 +191,8 @@ impl Solution { +#### Python3 + ```python class Solution: def distinctAverages(self, nums: List[int]) -> int: @@ -193,6 +207,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int distinctAverages(int[] nums) { @@ -210,6 +226,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -228,6 +246,8 @@ public: }; ``` +#### Go + ```go func distinctAverages(nums []int) (ans int) { sort.Ints(nums) @@ -244,6 +264,8 @@ func distinctAverages(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function distinctAverages(nums: number[]): number { nums.sort((a, b) => a - b); @@ -259,6 +281,8 @@ function distinctAverages(nums: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -294,6 +318,8 @@ impl Solution { +#### Rust + ```rust use std::collections::HashSet; diff --git a/solution/2400-2499/2465.Number of Distinct Averages/README_EN.md b/solution/2400-2499/2465.Number of Distinct Averages/README_EN.md index 1247d2744de0f..aef70360ac9b2 100644 --- a/solution/2400-2499/2465.Number of Distinct Averages/README_EN.md +++ b/solution/2400-2499/2465.Number of Distinct Averages/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def distinctAverages(self, nums: List[int]) -> int: @@ -93,6 +95,8 @@ class Solution: return len(set(nums[i] + nums[-i - 1] for i in range(len(nums) >> 1))) ``` +#### Java + ```java class Solution { public int distinctAverages(int[] nums) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func distinctAverages(nums []int) (ans int) { sort.Ints(nums) @@ -134,6 +142,8 @@ func distinctAverages(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function distinctAverages(nums: number[]): number { nums.sort((a, b) => a - b); @@ -146,6 +156,8 @@ function distinctAverages(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn distinct_averages(nums: Vec) -> i32 { @@ -179,6 +191,8 @@ impl Solution { +#### Python3 + ```python class Solution: def distinctAverages(self, nums: List[int]) -> int: @@ -193,6 +207,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int distinctAverages(int[] nums) { @@ -210,6 +226,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -228,6 +246,8 @@ public: }; ``` +#### Go + ```go func distinctAverages(nums []int) (ans int) { sort.Ints(nums) @@ -244,6 +264,8 @@ func distinctAverages(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function distinctAverages(nums: number[]): number { nums.sort((a, b) => a - b); @@ -259,6 +281,8 @@ function distinctAverages(nums: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -294,6 +318,8 @@ impl Solution { +#### Rust + ```rust use std::collections::HashSet; diff --git a/solution/2400-2499/2466.Count Ways To Build Good Strings/README.md b/solution/2400-2499/2466.Count Ways To Build Good Strings/README.md index 4d634a7cfd787..88b8698471c7d 100644 --- a/solution/2400-2499/2466.Count Ways To Build Good Strings/README.md +++ b/solution/2400-2499/2466.Count Ways To Build Good Strings/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def countGoodStrings(self, low: int, high: int, zero: int, one: int) -> int: @@ -97,6 +99,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func countGoodStrings(low int, high int, zero int, one int) int { f := make([]int, high+1) diff --git a/solution/2400-2499/2466.Count Ways To Build Good Strings/README_EN.md b/solution/2400-2499/2466.Count Ways To Build Good Strings/README_EN.md index 0c094eb203e59..00e065265953c 100644 --- a/solution/2400-2499/2466.Count Ways To Build Good Strings/README_EN.md +++ b/solution/2400-2499/2466.Count Ways To Build Good Strings/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n = hi +#### Python3 + ```python class Solution: def countGoodStrings(self, low: int, high: int, zero: int, one: int) -> int: @@ -97,6 +99,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func countGoodStrings(low int, high int, zero int, one int) int { f := make([]int, high+1) diff --git a/solution/2400-2499/2467.Most Profitable Path in a Tree/README.md b/solution/2400-2499/2467.Most Profitable Path in a Tree/README.md index df5c6c8ee46ee..5da67133a3c57 100644 --- a/solution/2400-2499/2467.Most Profitable Path in a Tree/README.md +++ b/solution/2400-2499/2467.Most Profitable Path in a Tree/README.md @@ -118,6 +118,8 @@ Alice 按照路径 0->1 移动,同时 Bob 按照路径 1->0 移动。 +#### Python3 + ```python class Solution: def mostProfitablePath( @@ -159,6 +161,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -217,6 +221,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -263,6 +269,8 @@ public: }; ``` +#### Go + ```go func mostProfitablePath(edges [][]int, bob int, amount []int) int { n := len(edges) + 1 diff --git a/solution/2400-2499/2467.Most Profitable Path in a Tree/README_EN.md b/solution/2400-2499/2467.Most Profitable Path in a Tree/README_EN.md index 993f6ec729aa6..0deab3c4edd80 100644 --- a/solution/2400-2499/2467.Most Profitable Path in a Tree/README_EN.md +++ b/solution/2400-2499/2467.Most Profitable Path in a Tree/README_EN.md @@ -114,6 +114,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def mostProfitablePath( @@ -155,6 +157,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -213,6 +217,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -259,6 +265,8 @@ public: }; ``` +#### Go + ```go func mostProfitablePath(edges [][]int, bob int, amount []int) int { n := len(edges) + 1 diff --git a/solution/2400-2499/2468.Split Message Based on Limit/README.md b/solution/2400-2499/2468.Split Message Based on Limit/README.md index 6b1c26c7605c3..b6eb2a748270c 100644 --- a/solution/2400-2499/2468.Split Message Based on Limit/README.md +++ b/solution/2400-2499/2468.Split Message Based on Limit/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def splitMessage(self, message: str, limit: int) -> List[str]: @@ -103,6 +105,8 @@ class Solution: return [] ``` +#### Java + ```java class Solution { public String[] splitMessage(String message, int limit) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func splitMessage(message string, limit int) (ans []string) { n := len(message) diff --git a/solution/2400-2499/2468.Split Message Based on Limit/README_EN.md b/solution/2400-2499/2468.Split Message Based on Limit/README_EN.md index cb8ea8f67c272..29c7dbcc0e97d 100644 --- a/solution/2400-2499/2468.Split Message Based on Limit/README_EN.md +++ b/solution/2400-2499/2468.Split Message Based on Limit/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n\times \log n)$, where $n$ is the length of the strin +#### Python3 + ```python class Solution: def splitMessage(self, message: str, limit: int) -> List[str]: @@ -103,6 +105,8 @@ class Solution: return [] ``` +#### Java + ```java class Solution { public String[] splitMessage(String message, int limit) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func splitMessage(message string, limit int) (ans []string) { n := len(message) diff --git a/solution/2400-2499/2469.Convert the Temperature/README.md b/solution/2400-2499/2469.Convert the Temperature/README.md index 0edd80e016d53..cb8352060b984 100644 --- a/solution/2400-2499/2469.Convert the Temperature/README.md +++ b/solution/2400-2499/2469.Convert the Temperature/README.md @@ -68,12 +68,16 @@ tags: +#### Python3 + ```python class Solution: def convertTemperature(self, celsius: float) -> List[float]: return [celsius + 273.15, celsius * 1.8 + 32] ``` +#### Java + ```java class Solution { public double[] convertTemperature(double celsius) { @@ -82,6 +86,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -91,18 +97,24 @@ public: }; ``` +#### Go + ```go func convertTemperature(celsius float64) []float64 { return []float64{celsius + 273.15, celsius*1.8 + 32} } ``` +#### TypeScript + ```ts function convertTemperature(celsius: number): number[] { return [celsius + 273.15, celsius * 1.8 + 32]; } ``` +#### Rust + ```rust impl Solution { pub fn convert_temperature(celsius: f64) -> Vec { @@ -111,6 +123,8 @@ impl Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). diff --git a/solution/2400-2499/2469.Convert the Temperature/README_EN.md b/solution/2400-2499/2469.Convert the Temperature/README_EN.md index bdf1c176896d7..4603232a2cda7 100644 --- a/solution/2400-2499/2469.Convert the Temperature/README_EN.md +++ b/solution/2400-2499/2469.Convert the Temperature/README_EN.md @@ -69,12 +69,16 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def convertTemperature(self, celsius: float) -> List[float]: return [celsius + 273.15, celsius * 1.8 + 32] ``` +#### Java + ```java class Solution { public double[] convertTemperature(double celsius) { @@ -83,6 +87,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -92,18 +98,24 @@ public: }; ``` +#### Go + ```go func convertTemperature(celsius float64) []float64 { return []float64{celsius + 273.15, celsius*1.8 + 32} } ``` +#### TypeScript + ```ts function convertTemperature(celsius: number): number[] { return [celsius + 273.15, celsius * 1.8 + 32]; } ``` +#### Rust + ```rust impl Solution { pub fn convert_temperature(celsius: f64) -> Vec { @@ -112,6 +124,8 @@ impl Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). diff --git a/solution/2400-2499/2470.Number of Subarrays With LCM Equal to K/README.md b/solution/2400-2499/2470.Number of Subarrays With LCM Equal to K/README.md index 49729a819f7fe..aa040725c5c93 100644 --- a/solution/2400-2499/2470.Number of Subarrays With LCM Equal to K/README.md +++ b/solution/2400-2499/2470.Number of Subarrays With LCM Equal to K/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def subarrayLCM(self, nums: List[int], k: int) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int subarrayLCM(int[] nums, int k) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func subarrayLCM(nums []int, k int) (ans int) { for i, a := range nums { diff --git a/solution/2400-2499/2470.Number of Subarrays With LCM Equal to K/README_EN.md b/solution/2400-2499/2470.Number of Subarrays With LCM Equal to K/README_EN.md index cdbec5b935d96..6918c51d226d8 100644 --- a/solution/2400-2499/2470.Number of Subarrays With LCM Equal to K/README_EN.md +++ b/solution/2400-2499/2470.Number of Subarrays With LCM Equal to K/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n^2)$. Here, $n$ is the length of the array. +#### Python3 + ```python class Solution: def subarrayLCM(self, nums: List[int], k: int) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int subarrayLCM(int[] nums, int k) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func subarrayLCM(nums []int, k int) (ans int) { for i, a := range nums { diff --git a/solution/2400-2499/2471.Minimum Number of Operations to Sort a Binary Tree by Level/README.md b/solution/2400-2499/2471.Minimum Number of Operations to Sort a Binary Tree by Level/README.md index 3164128366251..2cd6e1e48d827 100644 --- a/solution/2400-2499/2471.Minimum Number of Operations to Sort a Binary Tree by Level/README.md +++ b/solution/2400-2499/2471.Minimum Number of Operations to Sort a Binary Tree by Level/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -124,6 +126,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -192,6 +196,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -241,6 +247,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -294,6 +302,8 @@ func minimumOperations(root *TreeNode) (ans int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -338,6 +348,8 @@ function minimumOperations(root: TreeNode | null): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/2400-2499/2471.Minimum Number of Operations to Sort a Binary Tree by Level/README_EN.md b/solution/2400-2499/2471.Minimum Number of Operations to Sort a Binary Tree by Level/README_EN.md index 58c1b43866ac1..066f46bb1b63a 100644 --- a/solution/2400-2499/2471.Minimum Number of Operations to Sort a Binary Tree by Level/README_EN.md +++ b/solution/2400-2499/2471.Minimum Number of Operations to Sort a Binary Tree by Level/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(n \times \log n)$. Here, $n$ is the number of nodes in +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -125,6 +127,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -193,6 +197,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -242,6 +248,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -295,6 +303,8 @@ func minimumOperations(root *TreeNode) (ans int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -339,6 +349,8 @@ function minimumOperations(root: TreeNode | null): number { } ``` +#### Rust + ```rust // Definition for a binary tree node. // #[derive(Debug, PartialEq, Eq)] diff --git a/solution/2400-2499/2472.Maximum Number of Non-overlapping Palindrome Substrings/README.md b/solution/2400-2499/2472.Maximum Number of Non-overlapping Palindrome Substrings/README.md index 34db2a46773e5..3aa114fa416c9 100644 --- a/solution/2400-2499/2472.Maximum Number of Non-overlapping Palindrome Substrings/README.md +++ b/solution/2400-2499/2472.Maximum Number of Non-overlapping Palindrome Substrings/README.md @@ -85,6 +85,8 @@ $$ +#### Python3 + ```python class Solution: def maxPalindromes(self, s: str, k: int) -> int: @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private boolean[][] dp; @@ -153,6 +157,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -182,6 +188,8 @@ public: }; ``` +#### Go + ```go func maxPalindromes(s string, k int) int { n := len(s) diff --git a/solution/2400-2499/2472.Maximum Number of Non-overlapping Palindrome Substrings/README_EN.md b/solution/2400-2499/2472.Maximum Number of Non-overlapping Palindrome Substrings/README_EN.md index 4813b69e55239..8820941796c8f 100644 --- a/solution/2400-2499/2472.Maximum Number of Non-overlapping Palindrome Substrings/README_EN.md +++ b/solution/2400-2499/2472.Maximum Number of Non-overlapping Palindrome Substrings/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$. Here, $n$ +#### Python3 + ```python class Solution: def maxPalindromes(self, s: str, k: int) -> int: @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private boolean[][] dp; @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -180,6 +186,8 @@ public: }; ``` +#### Go + ```go func maxPalindromes(s string, k int) int { n := len(s) diff --git a/solution/2400-2499/2473.Minimum Cost to Buy Apples/README.md b/solution/2400-2499/2473.Minimum Cost to Buy Apples/README.md index 4b3931702fdc4..e2a480fe44427 100644 --- a/solution/2400-2499/2473.Minimum Cost to Buy Apples/README.md +++ b/solution/2400-2499/2473.Minimum Cost to Buy Apples/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def minCost( @@ -109,6 +111,8 @@ class Solution: return [dijkstra(i) for i in range(n)] ``` +#### Java + ```java class Solution { private int k; @@ -161,6 +165,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; using pii = pair; @@ -206,6 +212,8 @@ public: }; ``` +#### Go + ```go func minCost(n int, roads [][]int, appleCost []int, k int) []int64 { g := make([]pairs, n) diff --git a/solution/2400-2499/2473.Minimum Cost to Buy Apples/README_EN.md b/solution/2400-2499/2473.Minimum Cost to Buy Apples/README_EN.md index e48cdc604afcc..b93f4ea921a33 100644 --- a/solution/2400-2499/2473.Minimum Cost to Buy Apples/README_EN.md +++ b/solution/2400-2499/2473.Minimum Cost to Buy Apples/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n \times m \times \log m)$, where $n$ and $m$ are the +#### Python3 + ```python class Solution: def minCost( @@ -104,6 +106,8 @@ class Solution: return [dijkstra(i) for i in range(n)] ``` +#### Java + ```java class Solution { private int k; @@ -156,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; using pii = pair; @@ -201,6 +207,8 @@ public: }; ``` +#### Go + ```go func minCost(n int, roads [][]int, appleCost []int, k int) []int64 { g := make([]pairs, n) diff --git a/solution/2400-2499/2474.Customers With Strictly Increasing Purchases/README.md b/solution/2400-2499/2474.Customers With Strictly Increasing Purchases/README.md index 33bd3d498e5de..aa3ffa9232310 100644 --- a/solution/2400-2499/2474.Customers With Strictly Increasing Purchases/README.md +++ b/solution/2400-2499/2474.Customers With Strictly Increasing Purchases/README.md @@ -99,6 +99,8 @@ Orders 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2400-2499/2474.Customers With Strictly Increasing Purchases/README_EN.md b/solution/2400-2499/2474.Customers With Strictly Increasing Purchases/README_EN.md index 071130ca2853f..ac3f8c6a8268d 100644 --- a/solution/2400-2499/2474.Customers With Strictly Increasing Purchases/README_EN.md +++ b/solution/2400-2499/2474.Customers With Strictly Increasing Purchases/README_EN.md @@ -100,6 +100,8 @@ Customer 3: The first year is 2017, and the last year is 2018 +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2400-2499/2475.Number of Unequal Triplets in Array/README.md b/solution/2400-2499/2475.Number of Unequal Triplets in Array/README.md index a3b42567b0c8f..81c28a6be75e5 100644 --- a/solution/2400-2499/2475.Number of Unequal Triplets in Array/README.md +++ b/solution/2400-2499/2475.Number of Unequal Triplets in Array/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def unequalTriplets(self, nums: List[int]) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int unequalTriplets(int[] nums) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func unequalTriplets(nums []int) (ans int) { n := len(nums) @@ -148,6 +156,8 @@ func unequalTriplets(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function unequalTriplets(nums: number[]): number { const n = nums.length; @@ -165,6 +175,8 @@ function unequalTriplets(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn unequal_triplets(nums: Vec) -> i32 { @@ -200,6 +212,8 @@ impl Solution { +#### Python3 + ```python class Solution: def unequalTriplets(self, nums: List[int]) -> int: @@ -212,6 +226,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int unequalTriplets(int[] nums) { @@ -241,6 +257,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -259,6 +277,8 @@ public: }; ``` +#### Go + ```go func unequalTriplets(nums []int) (ans int) { sort.Ints(nums) @@ -274,6 +294,8 @@ func unequalTriplets(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function unequalTriplets(nums: number[]): number { const n = nums.length; @@ -292,6 +314,8 @@ function unequalTriplets(nums: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { @@ -329,6 +353,8 @@ impl Solution { +#### Python3 + ```python class Solution: def unequalTriplets(self, nums: List[int]) -> int: @@ -342,6 +368,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int unequalTriplets(int[] nums) { @@ -361,6 +389,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -381,6 +411,8 @@ public: }; ``` +#### Go + ```go func unequalTriplets(nums []int) (ans int) { cnt := map[int]int{} @@ -397,6 +429,8 @@ func unequalTriplets(nums []int) (ans int) { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -431,6 +465,8 @@ impl Solution { +#### Rust + ```rust impl Solution { pub fn unequal_triplets(nums: Vec) -> i32 { diff --git a/solution/2400-2499/2475.Number of Unequal Triplets in Array/README_EN.md b/solution/2400-2499/2475.Number of Unequal Triplets in Array/README_EN.md index bea10a541cca1..31a9fc4917271 100644 --- a/solution/2400-2499/2475.Number of Unequal Triplets in Array/README_EN.md +++ b/solution/2400-2499/2475.Number of Unequal Triplets in Array/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n^3)$, where $n$ is the length of the array $nums$. Th +#### Python3 + ```python class Solution: def unequalTriplets(self, nums: List[int]) -> int: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int unequalTriplets(int[] nums) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func unequalTriplets(nums []int) (ans int) { n := len(nums) @@ -146,6 +154,8 @@ func unequalTriplets(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function unequalTriplets(nums: number[]): number { const n = nums.length; @@ -163,6 +173,8 @@ function unequalTriplets(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn unequal_triplets(nums: Vec) -> i32 { @@ -198,6 +210,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def unequalTriplets(self, nums: List[int]) -> int: @@ -210,6 +224,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int unequalTriplets(int[] nums) { @@ -239,6 +255,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -257,6 +275,8 @@ public: }; ``` +#### Go + ```go func unequalTriplets(nums []int) (ans int) { sort.Ints(nums) @@ -272,6 +292,8 @@ func unequalTriplets(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function unequalTriplets(nums: number[]): number { const n = nums.length; @@ -290,6 +312,8 @@ function unequalTriplets(nums: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; impl Solution { @@ -327,6 +351,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def unequalTriplets(self, nums: List[int]) -> int: @@ -340,6 +366,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int unequalTriplets(int[] nums) { @@ -359,6 +387,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -379,6 +409,8 @@ public: }; ``` +#### Go + ```go func unequalTriplets(nums []int) (ans int) { cnt := map[int]int{} @@ -395,6 +427,8 @@ func unequalTriplets(nums []int) (ans int) { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -429,6 +463,8 @@ impl Solution { +#### Rust + ```rust impl Solution { pub fn unequal_triplets(nums: Vec) -> i32 { diff --git a/solution/2400-2499/2476.Closest Nodes Queries in a Binary Search Tree/README.md b/solution/2400-2499/2476.Closest Nodes Queries in a Binary Search Tree/README.md index af8310c46a202..191620d04a537 100644 --- a/solution/2400-2499/2476.Closest Nodes Queries in a Binary Search Tree/README.md +++ b/solution/2400-2499/2476.Closest Nodes Queries in a Binary Search Tree/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -199,6 +205,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -236,6 +244,8 @@ func closestNodes(root *TreeNode, queries []int) (ans [][]int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -286,6 +296,8 @@ function closestNodes(root: TreeNode | null, queries: number[]): number[][] { } ``` +#### C# + ```cs /** * Definition for a binary tree node. diff --git a/solution/2400-2499/2476.Closest Nodes Queries in a Binary Search Tree/README_EN.md b/solution/2400-2499/2476.Closest Nodes Queries in a Binary Search Tree/README_EN.md index 95335fa9d4d22..194f0a1479397 100644 --- a/solution/2400-2499/2476.Closest Nodes Queries in a Binary Search Tree/README_EN.md +++ b/solution/2400-2499/2476.Closest Nodes Queries in a Binary Search Tree/README_EN.md @@ -79,6 +79,8 @@ The time complexity is $O(n + m \times \log n)$, and the space complexity is $O( +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -109,6 +111,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -230,6 +238,8 @@ func closestNodes(root *TreeNode, queries []int) (ans [][]int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -280,6 +290,8 @@ function closestNodes(root: TreeNode | null, queries: number[]): number[][] { } ``` +#### C# + ```cs /** * Definition for a binary tree node. diff --git a/solution/2400-2499/2477.Minimum Fuel Cost to Report to the Capital/README.md b/solution/2400-2499/2477.Minimum Fuel Cost to Report to the Capital/README.md index 7c44a421664f2..8cf1c9a432c3d 100644 --- a/solution/2400-2499/2477.Minimum Fuel Cost to Report to the Capital/README.md +++ b/solution/2400-2499/2477.Minimum Fuel Cost to Report to the Capital/README.md @@ -104,6 +104,8 @@ tags: +#### Python3 + ```python class Solution: def minimumFuelCost(self, roads: List[List[int]], seats: int) -> int: @@ -126,6 +128,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -189,6 +195,8 @@ public: }; ``` +#### Go + ```go func minimumFuelCost(roads [][]int, seats int) (ans int64) { n := len(roads) + 1 @@ -215,6 +223,8 @@ func minimumFuelCost(roads [][]int, seats int) (ans int64) { } ``` +#### TypeScript + ```ts function minimumFuelCost(roads: number[][], seats: number): number { const n = roads.length + 1; @@ -240,6 +250,8 @@ function minimumFuelCost(roads: number[][], seats: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn minimum_fuel_cost(roads: Vec>, seats: i32) -> i64 { diff --git a/solution/2400-2499/2477.Minimum Fuel Cost to Report to the Capital/README_EN.md b/solution/2400-2499/2477.Minimum Fuel Cost to Report to the Capital/README_EN.md index 26a1b3a73a5f3..ad33bc999ee0a 100644 --- a/solution/2400-2499/2477.Minimum Fuel Cost to Report to the Capital/README_EN.md +++ b/solution/2400-2499/2477.Minimum Fuel Cost to Report to the Capital/README_EN.md @@ -101,6 +101,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def minimumFuelCost(self, roads: List[List[int]], seats: int) -> int: @@ -123,6 +125,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -157,6 +161,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go func minimumFuelCost(roads [][]int, seats int) (ans int64) { n := len(roads) + 1 @@ -212,6 +220,8 @@ func minimumFuelCost(roads [][]int, seats int) (ans int64) { } ``` +#### TypeScript + ```ts function minimumFuelCost(roads: number[][], seats: number): number { const n = roads.length + 1; @@ -237,6 +247,8 @@ function minimumFuelCost(roads: number[][], seats: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn minimum_fuel_cost(roads: Vec>, seats: i32) -> i64 { diff --git a/solution/2400-2499/2478.Number of Beautiful Partitions/README.md b/solution/2400-2499/2478.Number of Beautiful Partitions/README.md index 9679d39cfa1ad..3b2c218164d25 100644 --- a/solution/2400-2499/2478.Number of Beautiful Partitions/README.md +++ b/solution/2400-2499/2478.Number of Beautiful Partitions/README.md @@ -104,6 +104,8 @@ $$ +#### Python3 + ```python class Solution: def beautifulPartitions(self, s: str, k: int, minLength: int) -> int: @@ -124,6 +126,8 @@ class Solution: return f[n][k] ``` +#### Java + ```java class Solution { public int beautifulPartitions(String s, int k, int minLength) { @@ -155,6 +159,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -183,6 +189,8 @@ public: }; ``` +#### Go + ```go func beautifulPartitions(s string, k int, minLength int) int { prime := func(c byte) bool { @@ -214,6 +222,8 @@ func beautifulPartitions(s string, k int, minLength int) int { } ``` +#### TypeScript + ```ts function beautifulPartitions(s: string, k: number, minLength: number): number { const prime = (c: string): boolean => { diff --git a/solution/2400-2499/2478.Number of Beautiful Partitions/README_EN.md b/solution/2400-2499/2478.Number of Beautiful Partitions/README_EN.md index a43eecd8b2b49..e60cceec4cbcf 100644 --- a/solution/2400-2499/2478.Number of Beautiful Partitions/README_EN.md +++ b/solution/2400-2499/2478.Number of Beautiful Partitions/README_EN.md @@ -102,6 +102,8 @@ The time complexity is $O(n \times k)$, and the space complexity is $O(n \times +#### Python3 + ```python class Solution: def beautifulPartitions(self, s: str, k: int, minLength: int) -> int: @@ -122,6 +124,8 @@ class Solution: return f[n][k] ``` +#### Java + ```java class Solution { public int beautifulPartitions(String s, int k, int minLength) { @@ -153,6 +157,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func beautifulPartitions(s string, k int, minLength int) int { prime := func(c byte) bool { @@ -212,6 +220,8 @@ func beautifulPartitions(s string, k int, minLength int) int { } ``` +#### TypeScript + ```ts function beautifulPartitions(s: string, k: number, minLength: number): number { const prime = (c: string): boolean => { diff --git a/solution/2400-2499/2479.Maximum XOR of Two Non-Overlapping Subtrees/README.md b/solution/2400-2499/2479.Maximum XOR of Two Non-Overlapping Subtrees/README.md index dbc7104a47612..16692364bd8f8 100644 --- a/solution/2400-2499/2479.Maximum XOR of Two Non-Overlapping Subtrees/README.md +++ b/solution/2400-2499/2479.Maximum XOR of Two Non-Overlapping Subtrees/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Trie: def __init__(self): @@ -142,6 +144,8 @@ class Solution: return ans ``` +#### Java + ```java class Trie { Trie[] children = new Trie[2]; @@ -223,6 +227,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -296,6 +302,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [2]*Trie diff --git a/solution/2400-2499/2479.Maximum XOR of Two Non-Overlapping Subtrees/README_EN.md b/solution/2400-2499/2479.Maximum XOR of Two Non-Overlapping Subtrees/README_EN.md index 164ba763c5e4e..84020913caa53 100644 --- a/solution/2400-2499/2479.Maximum XOR of Two Non-Overlapping Subtrees/README_EN.md +++ b/solution/2400-2499/2479.Maximum XOR of Two Non-Overlapping Subtrees/README_EN.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Trie: def __init__(self): @@ -132,6 +134,8 @@ class Solution: return ans ``` +#### Java + ```java class Trie { Trie[] children = new Trie[2]; @@ -213,6 +217,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -286,6 +292,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [2]*Trie diff --git a/solution/2400-2499/2480.Form a Chemical Bond/README.md b/solution/2400-2499/2480.Form a Chemical Bond/README.md index 52b4e8e369c03..30d672d6c6ef8 100644 --- a/solution/2400-2499/2480.Form a Chemical Bond/README.md +++ b/solution/2400-2499/2480.Form a Chemical Bond/README.md @@ -91,6 +91,8 @@ Nonmetal 元素包括 Cl, O, and N. +#### MySQL + ```sql # Write your MySQL query statement below SELECT a.symbol AS metal, b.symbol AS nonmetal diff --git a/solution/2400-2499/2480.Form a Chemical Bond/README_EN.md b/solution/2400-2499/2480.Form a Chemical Bond/README_EN.md index 227517c23cf55..ab6d524af1ad0 100644 --- a/solution/2400-2499/2480.Form a Chemical Bond/README_EN.md +++ b/solution/2400-2499/2480.Form a Chemical Bond/README_EN.md @@ -91,6 +91,8 @@ Each Metal element pairs with a Nonmetal element in the output table. +#### MySQL + ```sql # Write your MySQL query statement below SELECT a.symbol AS metal, b.symbol AS nonmetal diff --git a/solution/2400-2499/2481.Minimum Cuts to Divide a Circle/README.md b/solution/2400-2499/2481.Minimum Cuts to Divide a Circle/README.md index 437c1c586e6bd..6b7769b4edb40 100644 --- a/solution/2400-2499/2481.Minimum Cuts to Divide a Circle/README.md +++ b/solution/2400-2499/2481.Minimum Cuts to Divide a Circle/README.md @@ -91,12 +91,16 @@ $$ +#### Python3 + ```python class Solution: def numberOfCuts(self, n: int) -> int: return n if (n > 1 and n & 1) else n >> 1 ``` +#### Java + ```java class Solution { public int numberOfCuts(int n) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func numberOfCuts(n int) int { if n > 1 && n%2 == 1 { @@ -123,12 +131,16 @@ func numberOfCuts(n int) int { } ``` +#### TypeScript + ```ts function numberOfCuts(n: number): number { return n > 1 && n & 1 ? n : n >> 1; } ``` +#### Rust + ```rust impl Solution { pub fn number_of_cuts(n: i32) -> i32 { @@ -140,6 +152,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int NumberOfCuts(int n) { diff --git a/solution/2400-2499/2481.Minimum Cuts to Divide a Circle/README_EN.md b/solution/2400-2499/2481.Minimum Cuts to Divide a Circle/README_EN.md index cafce252af266..d71da0ef58172 100644 --- a/solution/2400-2499/2481.Minimum Cuts to Divide a Circle/README_EN.md +++ b/solution/2400-2499/2481.Minimum Cuts to Divide a Circle/README_EN.md @@ -83,12 +83,16 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def numberOfCuts(self, n: int) -> int: return n if (n > 1 and n & 1) else n >> 1 ``` +#### Java + ```java class Solution { public int numberOfCuts(int n) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func numberOfCuts(n int) int { if n > 1 && n%2 == 1 { @@ -115,12 +123,16 @@ func numberOfCuts(n int) int { } ``` +#### TypeScript + ```ts function numberOfCuts(n: number): number { return n > 1 && n & 1 ? n : n >> 1; } ``` +#### Rust + ```rust impl Solution { pub fn number_of_cuts(n: i32) -> i32 { @@ -132,6 +144,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int NumberOfCuts(int n) { diff --git a/solution/2400-2499/2482.Difference Between Ones and Zeros in Row and Column/README.md b/solution/2400-2499/2482.Difference Between Ones and Zeros in Row and Column/README.md index d44109149cbf2..7f1c2d381023a 100644 --- a/solution/2400-2499/2482.Difference Between Ones and Zeros in Row and Column/README.md +++ b/solution/2400-2499/2482.Difference Between Ones and Zeros in Row and Column/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python class Solution: def onesMinusZeros(self, grid: List[List[int]]) -> List[List[int]]: @@ -112,6 +114,8 @@ class Solution: return diff ``` +#### Java + ```java class Solution { public int[][] onesMinusZeros(int[][] grid) { @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func onesMinusZeros(grid [][]int) [][]int { m, n := len(grid), len(grid[0]) @@ -183,6 +191,8 @@ func onesMinusZeros(grid [][]int) [][]int { } ``` +#### TypeScript + ```ts function onesMinusZeros(grid: number[][]): number[][] { const m = grid.length; @@ -207,6 +217,8 @@ function onesMinusZeros(grid: number[][]): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn ones_minus_zeros(grid: Vec>) -> Vec> { @@ -233,6 +245,8 @@ impl Solution { } ``` +#### C + ```c /** * Return an array of arrays of size *returnSize. diff --git a/solution/2400-2499/2482.Difference Between Ones and Zeros in Row and Column/README_EN.md b/solution/2400-2499/2482.Difference Between Ones and Zeros in Row and Column/README_EN.md index 383bb68551f6b..24ea92acde8d5 100644 --- a/solution/2400-2499/2482.Difference Between Ones and Zeros in Row and Column/README_EN.md +++ b/solution/2400-2499/2482.Difference Between Ones and Zeros in Row and Column/README_EN.md @@ -91,6 +91,8 @@ The time complexity is $O(m \times n)$, and if we ignore the space used by the a +#### Python3 + ```python class Solution: def onesMinusZeros(self, grid: List[List[int]]) -> List[List[int]]: @@ -108,6 +110,8 @@ class Solution: return diff ``` +#### Java + ```java class Solution { public int[][] onesMinusZeros(int[][] grid) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func onesMinusZeros(grid [][]int) [][]int { m, n := len(grid), len(grid[0]) @@ -179,6 +187,8 @@ func onesMinusZeros(grid [][]int) [][]int { } ``` +#### TypeScript + ```ts function onesMinusZeros(grid: number[][]): number[][] { const m = grid.length; @@ -203,6 +213,8 @@ function onesMinusZeros(grid: number[][]): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn ones_minus_zeros(grid: Vec>) -> Vec> { @@ -229,6 +241,8 @@ impl Solution { } ``` +#### C + ```c /** * Return an array of arrays of size *returnSize. diff --git a/solution/2400-2499/2483.Minimum Penalty for a Shop/README.md b/solution/2400-2499/2483.Minimum Penalty for a Shop/README.md index 320de4ebc7e22..a1201dbd190e8 100644 --- a/solution/2400-2499/2483.Minimum Penalty for a Shop/README.md +++ b/solution/2400-2499/2483.Minimum Penalty for a Shop/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def bestClosingTime(self, customers: str) -> int: @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int bestClosingTime(String customers) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func bestClosingTime(customers string) (ans int) { n := len(customers) @@ -172,6 +180,8 @@ func bestClosingTime(customers string) (ans int) { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/2400-2499/2483.Minimum Penalty for a Shop/README_EN.md b/solution/2400-2499/2483.Minimum Penalty for a Shop/README_EN.md index 8d26cec79da70..1d8ac74549c2b 100644 --- a/solution/2400-2499/2483.Minimum Penalty for a Shop/README_EN.md +++ b/solution/2400-2499/2483.Minimum Penalty for a Shop/README_EN.md @@ -91,6 +91,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def bestClosingTime(self, customers: str) -> int: @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int bestClosingTime(String customers) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func bestClosingTime(customers string) (ans int) { n := len(customers) @@ -170,6 +178,8 @@ func bestClosingTime(customers string) (ans int) { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/2400-2499/2484.Count Palindromic Subsequences/README.md b/solution/2400-2499/2484.Count Palindromic Subsequences/README.md index 81fff7d36661e..3295a23a4b35c 100644 --- a/solution/2400-2499/2484.Count Palindromic Subsequences/README.md +++ b/solution/2400-2499/2484.Count Palindromic Subsequences/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def countPalindromes(self, s: str) -> int: @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -213,6 +219,8 @@ public: }; ``` +#### Go + ```go func countPalindromes(s string) int { n := len(s) diff --git a/solution/2400-2499/2484.Count Palindromic Subsequences/README_EN.md b/solution/2400-2499/2484.Count Palindromic Subsequences/README_EN.md index 23dee92c76aef..550a26eb32eb6 100644 --- a/solution/2400-2499/2484.Count Palindromic Subsequences/README_EN.md +++ b/solution/2400-2499/2484.Count Palindromic Subsequences/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(100 \times n)$, and the space complexity is $O(100 \ti +#### Python3 + ```python class Solution: def countPalindromes(self, s: str) -> int: @@ -109,6 +111,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -161,6 +165,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -214,6 +220,8 @@ public: }; ``` +#### Go + ```go func countPalindromes(s string) int { n := len(s) diff --git a/solution/2400-2499/2485.Find the Pivot Integer/README.md b/solution/2400-2499/2485.Find the Pivot Integer/README.md index 3d8f37c991901..298bc33811377 100644 --- a/solution/2400-2499/2485.Find the Pivot Integer/README.md +++ b/solution/2400-2499/2485.Find the Pivot Integer/README.md @@ -78,6 +78,8 @@ $$ +#### Python3 + ```python class Solution: def pivotInteger(self, n: int) -> int: @@ -87,6 +89,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int pivotInteger(int n) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func pivotInteger(n int) int { for x := 1; x <= n; x++ { @@ -125,6 +133,8 @@ func pivotInteger(n int) int { } ``` +#### TypeScript + ```ts function pivotInteger(n: number): number { for (let x = 1; x <= n; ++x) { @@ -136,6 +146,8 @@ function pivotInteger(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn pivot_integer(n: i32) -> i32 { @@ -151,6 +163,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** @@ -197,6 +211,8 @@ $$ +#### Python3 + ```python class Solution: def pivotInteger(self, n: int) -> int: @@ -205,6 +221,8 @@ class Solution: return x if x * x == y else -1 ``` +#### Java + ```java class Solution { public int pivotInteger(int n) { @@ -215,6 +233,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -226,6 +246,8 @@ public: }; ``` +#### Go + ```go func pivotInteger(n int) int { y := n * (n + 1) / 2 @@ -237,6 +259,8 @@ func pivotInteger(n int) int { } ``` +#### TypeScript + ```ts function pivotInteger(n: number): number { const y = Math.floor((n * (n + 1)) / 2); diff --git a/solution/2400-2499/2485.Find the Pivot Integer/README_EN.md b/solution/2400-2499/2485.Find the Pivot Integer/README_EN.md index 9a33c47d3977c..6e500380caeef 100644 --- a/solution/2400-2499/2485.Find the Pivot Integer/README_EN.md +++ b/solution/2400-2499/2485.Find the Pivot Integer/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n)$, where $n$ is the given positive integer $n$. The +#### Python3 + ```python class Solution: def pivotInteger(self, n: int) -> int: @@ -86,6 +88,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int pivotInteger(int n) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func pivotInteger(n int) int { for x := 1; x <= n; x++ { @@ -124,6 +132,8 @@ func pivotInteger(n int) int { } ``` +#### TypeScript + ```ts function pivotInteger(n: number): number { for (let x = 1; x <= n; ++x) { @@ -135,6 +145,8 @@ function pivotInteger(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn pivot_integer(n: i32) -> i32 { @@ -150,6 +162,8 @@ impl Solution { } ``` +#### PHP + ```php class Solution { /** @@ -196,6 +210,8 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def pivotInteger(self, n: int) -> int: @@ -204,6 +220,8 @@ class Solution: return x if x * x == y else -1 ``` +#### Java + ```java class Solution { public int pivotInteger(int n) { @@ -214,6 +232,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -225,6 +245,8 @@ public: }; ``` +#### Go + ```go func pivotInteger(n int) int { y := n * (n + 1) / 2 @@ -236,6 +258,8 @@ func pivotInteger(n int) int { } ``` +#### TypeScript + ```ts function pivotInteger(n: number): number { const y = Math.floor((n * (n + 1)) / 2); diff --git a/solution/2400-2499/2486.Append Characters to String to Make Subsequence/README.md b/solution/2400-2499/2486.Append Characters to String to Make Subsequence/README.md index 3e56ce4597608..998e1140b44cc 100644 --- a/solution/2400-2499/2486.Append Characters to String to Make Subsequence/README.md +++ b/solution/2400-2499/2486.Append Characters to String to Make Subsequence/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def appendCharacters(self, s: str, t: str) -> int: @@ -92,6 +94,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { public int appendCharacters(String s, String t) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func appendCharacters(s string, t string) int { m, n := len(s), len(t) @@ -142,6 +150,8 @@ func appendCharacters(s string, t string) int { } ``` +#### TypeScript + ```ts function appendCharacters(s: string, t: string): number { const [m, n] = [s.length, t.length]; diff --git a/solution/2400-2499/2486.Append Characters to String to Make Subsequence/README_EN.md b/solution/2400-2499/2486.Append Characters to String to Make Subsequence/README_EN.md index 8126b97198cf6..2c5ff6c1b120c 100644 --- a/solution/2400-2499/2486.Append Characters to String to Make Subsequence/README_EN.md +++ b/solution/2400-2499/2486.Append Characters to String to Make Subsequence/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(m + n)$, and the space complexity is $O(1)$. Where $m$ +#### Python3 + ```python class Solution: def appendCharacters(self, s: str, t: str) -> int: @@ -90,6 +92,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { public int appendCharacters(String s, String t) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func appendCharacters(s string, t string) int { m, n := len(s), len(t) @@ -140,6 +148,8 @@ func appendCharacters(s string, t string) int { } ``` +#### TypeScript + ```ts function appendCharacters(s: string, t: string): number { const [m, n] = [s.length, t.length]; diff --git a/solution/2400-2499/2487.Remove Nodes From Linked List/README.md b/solution/2400-2499/2487.Remove Nodes From Linked List/README.md index f6aae22d13152..111bf230ec01d 100644 --- a/solution/2400-2499/2487.Remove Nodes From Linked List/README.md +++ b/solution/2400-2499/2487.Remove Nodes From Linked List/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -106,6 +108,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -179,6 +185,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -210,6 +218,8 @@ func removeNodes(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -255,6 +265,8 @@ function removeNodes(head: ListNode | null): ListNode | null { +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -275,6 +287,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -303,6 +317,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -332,6 +348,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -354,6 +372,8 @@ func removeNodes(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/2400-2499/2487.Remove Nodes From Linked List/README_EN.md b/solution/2400-2499/2487.Remove Nodes From Linked List/README_EN.md index 2658555e5c0f1..fb92502d04701 100644 --- a/solution/2400-2499/2487.Remove Nodes From Linked List/README_EN.md +++ b/solution/2400-2499/2487.Remove Nodes From Linked List/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -102,6 +104,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -206,6 +214,8 @@ func removeNodes(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. @@ -251,6 +261,8 @@ function removeNodes(head: ListNode | null): ListNode | null { +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -271,6 +283,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -299,6 +313,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -328,6 +344,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -350,6 +368,8 @@ func removeNodes(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/2400-2499/2488.Count Subarrays With Median K/README.md b/solution/2400-2499/2488.Count Subarrays With Median K/README.md index 9ba752a760f38..1adb8969101e7 100644 --- a/solution/2400-2499/2488.Count Subarrays With Median K/README.md +++ b/solution/2400-2499/2488.Count Subarrays With Median K/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def countSubarrays(self, nums: List[int], k: int) -> int: @@ -109,6 +111,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countSubarrays(int[] nums, int k) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go func countSubarrays(nums []int, k int) int { i, n := 0, len(nums) @@ -205,6 +213,8 @@ func countSubarrays(nums []int, k int) int { } ``` +#### TypeScript + ```ts function countSubarrays(nums: number[], k: number): number { const i = nums.indexOf(k); diff --git a/solution/2400-2499/2488.Count Subarrays With Median K/README_EN.md b/solution/2400-2499/2488.Count Subarrays With Median K/README_EN.md index 699464da0f768..5d61e6be50d06 100644 --- a/solution/2400-2499/2488.Count Subarrays With Median K/README_EN.md +++ b/solution/2400-2499/2488.Count Subarrays With Median K/README_EN.md @@ -88,6 +88,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def countSubarrays(self, nums: List[int], k: int) -> int: @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countSubarrays(int[] nums, int k) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func countSubarrays(nums []int, k int) int { i, n := 0, len(nums) @@ -203,6 +211,8 @@ func countSubarrays(nums []int, k int) int { } ``` +#### TypeScript + ```ts function countSubarrays(nums: number[], k: number): number { const i = nums.indexOf(k); diff --git a/solution/2400-2499/2489.Number of Substrings With Fixed Ratio/README.md b/solution/2400-2499/2489.Number of Substrings With Fixed Ratio/README.md index 7ccc23295e018..f1b2a1cab38d9 100644 --- a/solution/2400-2499/2489.Number of Substrings With Fixed Ratio/README.md +++ b/solution/2400-2499/2489.Number of Substrings With Fixed Ratio/README.md @@ -97,6 +97,8 @@ $$ +#### Python3 + ```python class Solution: def fixedRatio(self, s: str, num1: int, num2: int) -> int: @@ -112,6 +114,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long fixedRatio(String s, int num1, int num2) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func fixedRatio(s string, num1 int, num2 int) int64 { n0, n1 := 0, 0 diff --git a/solution/2400-2499/2489.Number of Substrings With Fixed Ratio/README_EN.md b/solution/2400-2499/2489.Number of Substrings With Fixed Ratio/README_EN.md index 01f67c3f939f0..7e1094e52956b 100644 --- a/solution/2400-2499/2489.Number of Substrings With Fixed Ratio/README_EN.md +++ b/solution/2400-2499/2489.Number of Substrings With Fixed Ratio/README_EN.md @@ -95,6 +95,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def fixedRatio(self, s: str, num1: int, num2: int) -> int: @@ -110,6 +112,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long fixedRatio(String s, int num1, int num2) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func fixedRatio(s string, num1 int, num2 int) int64 { n0, n1 := 0, 0 diff --git a/solution/2400-2499/2490.Circular Sentence/README.md b/solution/2400-2499/2490.Circular Sentence/README.md index 1e8474fcbebb0..cf39da89272a5 100644 --- a/solution/2400-2499/2490.Circular Sentence/README.md +++ b/solution/2400-2499/2490.Circular Sentence/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class Solution: def isCircularSentence(self, sentence: str) -> bool: @@ -102,6 +104,8 @@ class Solution: return all(s[-1] == ss[(i + 1) % n][0] for i, s in enumerate(ss)) ``` +#### Java + ```java class Solution { public boolean isCircularSentence(String sentence) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func isCircularSentence(sentence string) bool { ss := strings.Split(sentence, " ") @@ -156,6 +164,8 @@ func isCircularSentence(sentence string) bool { } ``` +#### TypeScript + ```ts function isCircularSentence(sentence: string): boolean { const ss = sentence.split(' '); @@ -169,6 +179,8 @@ function isCircularSentence(sentence: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn is_circular_sentence(sentence: String) -> bool { @@ -184,6 +196,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} sentence @@ -215,6 +229,8 @@ var isCircularSentence = function (sentence) { +#### Python3 + ```python class Solution: def isCircularSentence(self, s: str) -> bool: @@ -223,6 +239,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public boolean isCircularSentence(String s) { @@ -240,6 +258,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -258,6 +278,8 @@ public: }; ``` +#### Go + ```go func isCircularSentence(s string) bool { n := len(s) @@ -273,6 +295,8 @@ func isCircularSentence(s string) bool { } ``` +#### TypeScript + ```ts function isCircularSentence(s: string): boolean { const n = s.length; @@ -288,6 +312,8 @@ function isCircularSentence(s: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn is_circular_sentence(sentence: String) -> bool { @@ -309,6 +335,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s diff --git a/solution/2400-2499/2490.Circular Sentence/README_EN.md b/solution/2400-2499/2490.Circular Sentence/README_EN.md index 7641a1c37baa9..195dcadc67fde 100644 --- a/solution/2400-2499/2490.Circular Sentence/README_EN.md +++ b/solution/2400-2499/2490.Circular Sentence/README_EN.md @@ -92,6 +92,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def isCircularSentence(self, sentence: str) -> bool: @@ -100,6 +102,8 @@ class Solution: return all(s[-1] == ss[(i + 1) % n][0] for i, s in enumerate(ss)) ``` +#### Java + ```java class Solution { public boolean isCircularSentence(String sentence) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func isCircularSentence(sentence string) bool { ss := strings.Split(sentence, " ") @@ -154,6 +162,8 @@ func isCircularSentence(sentence string) bool { } ``` +#### TypeScript + ```ts function isCircularSentence(sentence: string): boolean { const ss = sentence.split(' '); @@ -167,6 +177,8 @@ function isCircularSentence(sentence: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn is_circular_sentence(sentence: String) -> bool { @@ -182,6 +194,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} sentence @@ -213,6 +227,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string. The space +#### Python3 + ```python class Solution: def isCircularSentence(self, s: str) -> bool: @@ -221,6 +237,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public boolean isCircularSentence(String s) { @@ -238,6 +256,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -256,6 +276,8 @@ public: }; ``` +#### Go + ```go func isCircularSentence(s string) bool { n := len(s) @@ -271,6 +293,8 @@ func isCircularSentence(s string) bool { } ``` +#### TypeScript + ```ts function isCircularSentence(s: string): boolean { const n = s.length; @@ -286,6 +310,8 @@ function isCircularSentence(s: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn is_circular_sentence(sentence: String) -> bool { @@ -307,6 +333,8 @@ impl Solution { } ``` +#### JavaScript + ```js /** * @param {string} s diff --git a/solution/2400-2499/2491.Divide Players Into Teams of Equal Skill/README.md b/solution/2400-2499/2491.Divide Players Into Teams of Equal Skill/README.md index 232e15522f67e..ce1954306d327 100644 --- a/solution/2400-2499/2491.Divide Players Into Teams of Equal Skill/README.md +++ b/solution/2400-2499/2491.Divide Players Into Teams of Equal Skill/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def dividePlayers(self, skill: List[int]) -> int: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long dividePlayers(int[] skill) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func dividePlayers(skill []int) (ans int64) { sort.Ints(skill) @@ -151,6 +159,8 @@ func dividePlayers(skill []int) (ans int64) { } ``` +#### TypeScript + ```ts function dividePlayers(skill: number[]): number { const n = skill.length; @@ -167,6 +177,8 @@ function dividePlayers(skill: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn divide_players(mut skill: Vec) -> i64 { @@ -185,6 +197,8 @@ impl Solution { } ``` +#### JavaScript + ```js var dividePlayers = function (skill) { const n = skill.length, @@ -214,6 +228,8 @@ var dividePlayers = function (skill) { +#### Python3 + ```python class Solution: def dividePlayers(self, skill: List[int]) -> int: @@ -234,6 +250,8 @@ class Solution: return -1 if m else ans ``` +#### Java + ```java class Solution { public long dividePlayers(int[] skill) { @@ -259,6 +277,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -283,6 +303,8 @@ public: }; ``` +#### Go + ```go func dividePlayers(skill []int) int64 { s := 0 diff --git a/solution/2400-2499/2491.Divide Players Into Teams of Equal Skill/README_EN.md b/solution/2400-2499/2491.Divide Players Into Teams of Equal Skill/README_EN.md index 760c46a6b3acb..2b6db5edd6a7f 100644 --- a/solution/2400-2499/2491.Divide Players Into Teams of Equal Skill/README_EN.md +++ b/solution/2400-2499/2491.Divide Players Into Teams of Equal Skill/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def dividePlayers(self, skill: List[int]) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long dividePlayers(int[] skill) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func dividePlayers(skill []int) (ans int64) { sort.Ints(skill) @@ -149,6 +157,8 @@ func dividePlayers(skill []int) (ans int64) { } ``` +#### TypeScript + ```ts function dividePlayers(skill: number[]): number { const n = skill.length; @@ -165,6 +175,8 @@ function dividePlayers(skill: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn divide_players(mut skill: Vec) -> i64 { @@ -183,6 +195,8 @@ impl Solution { } ``` +#### JavaScript + ```js var dividePlayers = function (skill) { const n = skill.length, @@ -212,6 +226,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def dividePlayers(self, skill: List[int]) -> int: @@ -232,6 +248,8 @@ class Solution: return -1 if m else ans ``` +#### Java + ```java class Solution { public long dividePlayers(int[] skill) { @@ -257,6 +275,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -281,6 +301,8 @@ public: }; ``` +#### Go + ```go func dividePlayers(skill []int) int64 { s := 0 diff --git a/solution/2400-2499/2492.Minimum Score of a Path Between Two Cities/README.md b/solution/2400-2499/2492.Minimum Score of a Path Between Two Cities/README.md index 37d832b541071..340601b6b8d41 100644 --- a/solution/2400-2499/2492.Minimum Score of a Path Between Two Cities/README.md +++ b/solution/2400-2499/2492.Minimum Score of a Path Between Two Cities/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def minScore(self, n: int, roads: List[List[int]]) -> int: @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func minScore(n int, roads [][]int) int { type pair struct{ i, v int } @@ -195,6 +203,8 @@ func minScore(n int, roads [][]int) int { } ``` +#### TypeScript + ```ts function minScore(n: number, roads: number[][]): number { const vis = new Array(n + 1).fill(false); @@ -219,6 +229,8 @@ function minScore(n: number, roads: number[][]): number { } ``` +#### Rust + ```rust impl Solution { fn dfs(i: usize, mut ans: i32, g: &Vec>, vis: &mut Vec) -> i32 { @@ -248,6 +260,8 @@ impl Solution { } ``` +#### JavaScript + ```js var minScore = function (n, roads) { // 构建点到点的映射表 @@ -287,6 +301,8 @@ var minScore = function (n, roads) { +#### Python3 + ```python class Solution: def minScore(self, n: int, roads: List[List[int]]) -> int: @@ -309,6 +325,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minScore(int n, int[][] roads) { @@ -342,6 +360,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -375,6 +395,8 @@ public: }; ``` +#### Go + ```go func minScore(n int, roads [][]int) int { type pair struct{ i, v int } diff --git a/solution/2400-2499/2492.Minimum Score of a Path Between Two Cities/README_EN.md b/solution/2400-2499/2492.Minimum Score of a Path Between Two Cities/README_EN.md index 5aa2e8bb8c5d4..19473c7433c6d 100644 --- a/solution/2400-2499/2492.Minimum Score of a Path Between Two Cities/README_EN.md +++ b/solution/2400-2499/2492.Minimum Score of a Path Between Two Cities/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(n + m)$, where $n$ and $m$ are the number of nodes and +#### Python3 + ```python class Solution: def minScore(self, n: int, roads: List[List[int]]) -> int: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func minScore(n int, roads [][]int) int { type pair struct{ i, v int } @@ -189,6 +197,8 @@ func minScore(n int, roads [][]int) int { } ``` +#### TypeScript + ```ts function minScore(n: number, roads: number[][]): number { const vis = new Array(n + 1).fill(false); @@ -213,6 +223,8 @@ function minScore(n: number, roads: number[][]): number { } ``` +#### Rust + ```rust impl Solution { fn dfs(i: usize, mut ans: i32, g: &Vec>, vis: &mut Vec) -> i32 { @@ -242,6 +254,8 @@ impl Solution { } ``` +#### JavaScript + ```js var minScore = function (n, roads) { // 构建点到点的映射表 @@ -281,6 +295,8 @@ The time complexity is $O(n + m)$, where $n$ and $m$ are the number of nodes and +#### Python3 + ```python class Solution: def minScore(self, n: int, roads: List[List[int]]) -> int: @@ -303,6 +319,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minScore(int n, int[][] roads) { @@ -336,6 +354,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -369,6 +389,8 @@ public: }; ``` +#### Go + ```go func minScore(n int, roads [][]int) int { type pair struct{ i, v int } diff --git a/solution/2400-2499/2493.Divide Nodes Into the Maximum Number of Groups/README.md b/solution/2400-2499/2493.Divide Nodes Into the Maximum Number of Groups/README.md index c1f82e0269d55..acb99166a82c1 100644 --- a/solution/2400-2499/2493.Divide Nodes Into the Maximum Number of Groups/README.md +++ b/solution/2400-2499/2493.Divide Nodes Into the Maximum Number of Groups/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def magnificentSets(self, n: int, edges: List[List[int]]) -> int: @@ -118,6 +120,8 @@ class Solution: return sum(d.values()) ``` +#### Java + ```java class Solution { public int magnificentSets(int n, int[][] edges) { @@ -157,6 +161,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -195,6 +201,8 @@ public: }; ``` +#### Go + ```go func magnificentSets(n int, edges [][]int) (ans int) { g := make([][]int, n) @@ -240,6 +248,8 @@ func abs(x int) int { } ``` +#### JavaScript + ```js /** * @param {number} n diff --git a/solution/2400-2499/2493.Divide Nodes Into the Maximum Number of Groups/README_EN.md b/solution/2400-2499/2493.Divide Nodes Into the Maximum Number of Groups/README_EN.md index 8c0c76e869bcb..7eda66abfe9e2 100644 --- a/solution/2400-2499/2493.Divide Nodes Into the Maximum Number of Groups/README_EN.md +++ b/solution/2400-2499/2493.Divide Nodes Into the Maximum Number of Groups/README_EN.md @@ -89,6 +89,8 @@ The time complexity is $O(n \times (n + m))$, and the space complexity is $O(n + +#### Python3 + ```python class Solution: def magnificentSets(self, n: int, edges: List[List[int]]) -> int: @@ -116,6 +118,8 @@ class Solution: return sum(d.values()) ``` +#### Java + ```java class Solution { public int magnificentSets(int n, int[][] edges) { @@ -155,6 +159,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go func magnificentSets(n int, edges [][]int) (ans int) { g := make([][]int, n) @@ -238,6 +246,8 @@ func abs(x int) int { } ``` +#### JavaScript + ```js /** * @param {number} n diff --git a/solution/2400-2499/2494.Merge Overlapping Events in the Same Hall/README.md b/solution/2400-2499/2494.Merge Overlapping Events in the Same Hall/README.md index a8c80c9d41651..bc6dbb7b63fd3 100644 --- a/solution/2400-2499/2494.Merge Overlapping Events in the Same Hall/README.md +++ b/solution/2400-2499/2494.Merge Overlapping Events in the Same Hall/README.md @@ -82,6 +82,8 @@ HallEvents 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2400-2499/2494.Merge Overlapping Events in the Same Hall/README_EN.md b/solution/2400-2499/2494.Merge Overlapping Events in the Same Hall/README_EN.md index 74d77bb74bd60..73c41e12ba60f 100644 --- a/solution/2400-2499/2494.Merge Overlapping Events in the Same Hall/README_EN.md +++ b/solution/2400-2499/2494.Merge Overlapping Events in the Same Hall/README_EN.md @@ -83,6 +83,8 @@ Hall 3: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2400-2499/2495.Number of Subarrays Having Even Product/README.md b/solution/2400-2499/2495.Number of Subarrays Having Even Product/README.md index 0b2541fadabad..ef98f895cb1f0 100644 --- a/solution/2400-2499/2495.Number of Subarrays Having Even Product/README.md +++ b/solution/2400-2499/2495.Number of Subarrays Having Even Product/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def evenProduct(self, nums: List[int]) -> int: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long evenProduct(int[] nums) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func evenProduct(nums []int) int64 { ans, last := 0, -1 diff --git a/solution/2400-2499/2495.Number of Subarrays Having Even Product/README_EN.md b/solution/2400-2499/2495.Number of Subarrays Having Even Product/README_EN.md index 55dd91fe6b23e..63ed502c80090 100644 --- a/solution/2400-2499/2495.Number of Subarrays Having Even Product/README_EN.md +++ b/solution/2400-2499/2495.Number of Subarrays Having Even Product/README_EN.md @@ -67,6 +67,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array `nums`. The +#### Python3 + ```python class Solution: def evenProduct(self, nums: List[int]) -> int: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long evenProduct(int[] nums) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func evenProduct(nums []int) int64 { ans, last := 0, -1 diff --git a/solution/2400-2499/2496.Maximum Value of a String in an Array/README.md b/solution/2400-2499/2496.Maximum Value of a String in an Array/README.md index ad19b4074c124..a7b3e654b5021 100644 --- a/solution/2400-2499/2496.Maximum Value of a String in an Array/README.md +++ b/solution/2400-2499/2496.Maximum Value of a String in an Array/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def maximumValue(self, strs: List[str]) -> int: @@ -87,6 +89,8 @@ class Solution: return max(f(s) for s in strs) ``` +#### Java + ```java class Solution { public int maximumValue(String[] strs) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func maximumValue(strs []string) (ans int) { f := func(s string) (x int) { @@ -154,6 +162,8 @@ func maximumValue(strs []string) (ans int) { } ``` +#### TypeScript + ```ts function maximumValue(strs: string[]): number { const f = (s: string) => (Number.isNaN(Number(s)) ? s.length : Number(s)); @@ -161,6 +171,8 @@ function maximumValue(strs: string[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn maximum_value(strs: Vec) -> i32 { @@ -174,6 +186,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int MaximumValue(string[] strs) { @@ -193,6 +207,8 @@ public class Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) @@ -228,6 +244,8 @@ int maximumValue(char** strs, int strsSize) { +#### Python3 + ```python class Solution: def maximumValue(self, strs: List[str]) -> int: @@ -242,6 +260,8 @@ class Solution: return max(f(s) for s in strs) ``` +#### Rust + ```rust impl Solution { pub fn maximum_value(strs: Vec) -> i32 { @@ -283,6 +303,8 @@ impl Solution { +#### Rust + ```rust use std::cmp::max; diff --git a/solution/2400-2499/2496.Maximum Value of a String in an Array/README_EN.md b/solution/2400-2499/2496.Maximum Value of a String in an Array/README_EN.md index 688504f5aaf14..c238cd51b1d36 100644 --- a/solution/2400-2499/2496.Maximum Value of a String in an Array/README_EN.md +++ b/solution/2400-2499/2496.Maximum Value of a String in an Array/README_EN.md @@ -71,6 +71,8 @@ Each string in the array has value 1. Hence, we return 1. +#### Python3 + ```python class Solution: def maximumValue(self, strs: List[str]) -> int: @@ -80,6 +82,8 @@ class Solution: return max(f(s) for s in strs) ``` +#### Java + ```java class Solution { public int maximumValue(String[] strs) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func maximumValue(strs []string) (ans int) { f := func(s string) (x int) { @@ -147,6 +155,8 @@ func maximumValue(strs []string) (ans int) { } ``` +#### TypeScript + ```ts function maximumValue(strs: string[]): number { const f = (s: string) => (Number.isNaN(Number(s)) ? s.length : Number(s)); @@ -154,6 +164,8 @@ function maximumValue(strs: string[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn maximum_value(strs: Vec) -> i32 { @@ -167,6 +179,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int MaximumValue(string[] strs) { @@ -186,6 +200,8 @@ public class Solution { } ``` +#### C + ```c #define max(a, b) (((a) > (b)) ? (a) : (b)) @@ -221,6 +237,8 @@ int maximumValue(char** strs, int strsSize) { +#### Python3 + ```python class Solution: def maximumValue(self, strs: List[str]) -> int: @@ -235,6 +253,8 @@ class Solution: return max(f(s) for s in strs) ``` +#### Rust + ```rust impl Solution { pub fn maximum_value(strs: Vec) -> i32 { @@ -276,6 +296,8 @@ impl Solution { +#### Rust + ```rust use std::cmp::max; diff --git a/solution/2400-2499/2497.Maximum Star Sum of a Graph/README.md b/solution/2400-2499/2497.Maximum Star Sum of a Graph/README.md index 3a10cead3c113..d12836cf38a7b 100644 --- a/solution/2400-2499/2497.Maximum Star Sum of a Graph/README.md +++ b/solution/2400-2499/2497.Maximum Star Sum of a Graph/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def maxStarSum(self, vals: List[int], edges: List[List[int]], k: int) -> int: @@ -104,6 +106,8 @@ class Solution: return max(v + sum(g[i][:k]) for i, v in enumerate(vals)) ``` +#### Java + ```java class Solution { public int maxStarSum(int[] vals, int[][] edges, int k) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func maxStarSum(vals []int, edges [][]int, k int) (ans int) { n := len(vals) diff --git a/solution/2400-2499/2497.Maximum Star Sum of a Graph/README_EN.md b/solution/2400-2499/2497.Maximum Star Sum of a Graph/README_EN.md index 50ce0a652231b..5e2fc2c7e5057 100644 --- a/solution/2400-2499/2497.Maximum Star Sum of a Graph/README_EN.md +++ b/solution/2400-2499/2497.Maximum Star Sum of a Graph/README_EN.md @@ -78,6 +78,8 @@ Hence, we return -5. +#### Python3 + ```python class Solution: def maxStarSum(self, vals: List[int], edges: List[List[int]], k: int) -> int: @@ -92,6 +94,8 @@ class Solution: return max(v + sum(g[i][:k]) for i, v in enumerate(vals)) ``` +#### Java + ```java class Solution { public int maxStarSum(int[] vals, int[][] edges, int k) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func maxStarSum(vals []int, edges [][]int, k int) (ans int) { n := len(vals) diff --git a/solution/2400-2499/2498.Frog Jump II/README.md b/solution/2400-2499/2498.Frog Jump II/README.md index 6d0e8ad02d902..c335c72495e7a 100644 --- a/solution/2400-2499/2498.Frog Jump II/README.md +++ b/solution/2400-2499/2498.Frog Jump II/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def maxJump(self, stones: List[int]) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxJump(int[] stones) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func maxJump(stones []int) int { ans := stones[1] - stones[0] diff --git a/solution/2400-2499/2498.Frog Jump II/README_EN.md b/solution/2400-2499/2498.Frog Jump II/README_EN.md index d73e511a0e155..586a732317c2c 100644 --- a/solution/2400-2499/2498.Frog Jump II/README_EN.md +++ b/solution/2400-2499/2498.Frog Jump II/README_EN.md @@ -76,6 +76,8 @@ It can be shown that this is the minimum achievable cost. +#### Python3 + ```python class Solution: def maxJump(self, stones: List[int]) -> int: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxJump(int[] stones) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func maxJump(stones []int) int { ans := stones[1] - stones[0] diff --git a/solution/2400-2499/2499.Minimum Total Cost to Make Arrays Unequal/README.md b/solution/2400-2499/2499.Minimum Total Cost to Make Arrays Unequal/README.md index 12a3f095968ba..c73249bf9d1b1 100644 --- a/solution/2400-2499/2499.Minimum Total Cost to Make Arrays Unequal/README.md +++ b/solution/2400-2499/2499.Minimum Total Cost to Make Arrays Unequal/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python class Solution: def minimumTotalCost(self, nums1: List[int], nums2: List[int]) -> int: @@ -119,6 +121,8 @@ class Solution: return -1 if m else ans ``` +#### Java + ```java class Solution { public long minimumTotalCost(int[] nums1, int[] nums2) { @@ -153,6 +157,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -189,6 +195,8 @@ public: }; ``` +#### Go + ```go func minimumTotalCost(nums1 []int, nums2 []int) (ans int64) { same, n := 0, len(nums1) diff --git a/solution/2400-2499/2499.Minimum Total Cost to Make Arrays Unequal/README_EN.md b/solution/2400-2499/2499.Minimum Total Cost to Make Arrays Unequal/README_EN.md index 9b71c3bbb04c5..ed632206d24e8 100644 --- a/solution/2400-2499/2499.Minimum Total Cost to Make Arrays Unequal/README_EN.md +++ b/solution/2400-2499/2499.Minimum Total Cost to Make Arrays Unequal/README_EN.md @@ -85,6 +85,8 @@ Hence, we return -1. +#### Python3 + ```python class Solution: def minimumTotalCost(self, nums1: List[int], nums2: List[int]) -> int: @@ -109,6 +111,8 @@ class Solution: return -1 if m else ans ``` +#### Java + ```java class Solution { public long minimumTotalCost(int[] nums1, int[] nums2) { @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -179,6 +185,8 @@ public: }; ``` +#### Go + ```go func minimumTotalCost(nums1 []int, nums2 []int) (ans int64) { same, n := 0, len(nums1) diff --git a/solution/2500-2599/2500.Delete Greatest Value in Each Row/README.md b/solution/2500-2599/2500.Delete Greatest Value in Each Row/README.md index a9d2a908adf5c..9bbc002d73693 100644 --- a/solution/2500-2599/2500.Delete Greatest Value in Each Row/README.md +++ b/solution/2500-2599/2500.Delete Greatest Value in Each Row/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def deleteGreatestValue(self, grid: List[List[int]]) -> int: @@ -98,6 +100,8 @@ class Solution: return sum(max(col) for col in zip(*grid)) ``` +#### Java + ```java class Solution { public int deleteGreatestValue(int[][] grid) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func deleteGreatestValue(grid [][]int) (ans int) { for _, row := range grid { @@ -153,6 +161,8 @@ func deleteGreatestValue(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function deleteGreatestValue(grid: number[][]): number { for (const row of grid) { @@ -172,6 +182,8 @@ function deleteGreatestValue(grid: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn delete_greatest_value(grid: Vec>) -> i32 { diff --git a/solution/2500-2599/2500.Delete Greatest Value in Each Row/README_EN.md b/solution/2500-2599/2500.Delete Greatest Value in Each Row/README_EN.md index c6a9d91d9d31d..f1b468ac3d74f 100644 --- a/solution/2500-2599/2500.Delete Greatest Value in Each Row/README_EN.md +++ b/solution/2500-2599/2500.Delete Greatest Value in Each Row/README_EN.md @@ -78,6 +78,8 @@ The final answer = 10. +#### Python3 + ```python class Solution: def deleteGreatestValue(self, grid: List[List[int]]) -> int: @@ -86,6 +88,8 @@ class Solution: return sum(max(col) for col in zip(*grid)) ``` +#### Java + ```java class Solution { public int deleteGreatestValue(int[][] grid) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func deleteGreatestValue(grid [][]int) (ans int) { for _, row := range grid { @@ -141,6 +149,8 @@ func deleteGreatestValue(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function deleteGreatestValue(grid: number[][]): number { for (const row of grid) { @@ -160,6 +170,8 @@ function deleteGreatestValue(grid: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn delete_greatest_value(grid: Vec>) -> i32 { diff --git a/solution/2500-2599/2501.Longest Square Streak in an Array/README.md b/solution/2500-2599/2501.Longest Square Streak in an Array/README.md index a493a0973b89d..8f39309d88f53 100644 --- a/solution/2500-2599/2501.Longest Square Streak in an Array/README.md +++ b/solution/2500-2599/2501.Longest Square Streak in an Array/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def longestSquareStreak(self, nums: List[int]) -> int: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestSquareStreak(int[] nums) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func longestSquareStreak(nums []int) int { s := map[int]bool{} @@ -176,6 +184,8 @@ func longestSquareStreak(nums []int) int { +#### Python3 + ```python class Solution: def longestSquareStreak(self, nums: List[int]) -> int: @@ -190,6 +200,8 @@ class Solution: return -1 if ans < 2 else ans ``` +#### Java + ```java class Solution { private Map f = new HashMap<>(); @@ -220,6 +232,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -241,6 +255,8 @@ public: }; ``` +#### Go + ```go func longestSquareStreak(nums []int) (ans int) { s := map[int]bool{} diff --git a/solution/2500-2599/2501.Longest Square Streak in an Array/README_EN.md b/solution/2500-2599/2501.Longest Square Streak in an Array/README_EN.md index 2bb8637b3f252..f0b303d11751d 100644 --- a/solution/2500-2599/2501.Longest Square Streak in an Array/README_EN.md +++ b/solution/2500-2599/2501.Longest Square Streak in an Array/README_EN.md @@ -72,6 +72,8 @@ It can be shown that every subsequence of length 4 is not a square streak. +#### Python3 + ```python class Solution: def longestSquareStreak(self, nums: List[int]) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestSquareStreak(int[] nums) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func longestSquareStreak(nums []int) int { s := map[int]bool{} @@ -161,6 +169,8 @@ func longestSquareStreak(nums []int) int { +#### Python3 + ```python class Solution: def longestSquareStreak(self, nums: List[int]) -> int: @@ -175,6 +185,8 @@ class Solution: return -1 if ans < 2 else ans ``` +#### Java + ```java class Solution { private Map f = new HashMap<>(); @@ -205,6 +217,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -226,6 +240,8 @@ public: }; ``` +#### Go + ```go func longestSquareStreak(nums []int) (ans int) { s := map[int]bool{} diff --git a/solution/2500-2599/2502.Design Memory Allocator/README.md b/solution/2500-2599/2502.Design Memory Allocator/README.md index babe892b1a8fb..9c0c5822c6848 100644 --- a/solution/2500-2599/2502.Design Memory Allocator/README.md +++ b/solution/2500-2599/2502.Design Memory Allocator/README.md @@ -98,6 +98,8 @@ loc.free(7); // 释放 mID 为 7 的所有内存单元。内存数组保持原 +#### Python3 + ```python class Allocator: def __init__(self, n: int): @@ -130,6 +132,8 @@ class Allocator: # param_2 = obj.free(mID) ``` +#### Java + ```java class Allocator { private int[] m; @@ -171,6 +175,8 @@ class Allocator { */ ``` +#### C++ + ```cpp class Allocator { public: @@ -220,6 +226,8 @@ private: */ ``` +#### Go + ```go type Allocator struct { m []int @@ -283,6 +291,8 @@ func (this *Allocator) Free(mID int) (ans int) { +#### Python3 + ```python from sortedcontainers import SortedList @@ -316,6 +326,8 @@ class Allocator: # param_2 = obj.free(mID) ``` +#### Java + ```java class Allocator { private TreeMap tm = new TreeMap<>(); @@ -362,6 +374,8 @@ class Allocator { */ ``` +#### C++ + ```cpp class Allocator { public: @@ -410,6 +424,8 @@ private: */ ``` +#### Go + ```go type Allocator struct { rbt *redblacktree.Tree diff --git a/solution/2500-2599/2502.Design Memory Allocator/README_EN.md b/solution/2500-2599/2502.Design Memory Allocator/README_EN.md index 3c84baa7be231..223bc84a35fc5 100644 --- a/solution/2500-2599/2502.Design Memory Allocator/README_EN.md +++ b/solution/2500-2599/2502.Design Memory Allocator/README_EN.md @@ -87,6 +87,8 @@ loc.free(7); // Free all memory units with mID 7. The memory array remains the s +#### Python3 + ```python class Allocator: def __init__(self, n: int): @@ -119,6 +121,8 @@ class Allocator: # param_2 = obj.free(mID) ``` +#### Java + ```java class Allocator { private int[] m; @@ -160,6 +164,8 @@ class Allocator { */ ``` +#### C++ + ```cpp class Allocator { public: @@ -209,6 +215,8 @@ private: */ ``` +#### Go + ```go type Allocator struct { m []int @@ -264,6 +272,8 @@ func (this *Allocator) Free(mID int) (ans int) { +#### Python3 + ```python from sortedcontainers import SortedList @@ -297,6 +307,8 @@ class Allocator: # param_2 = obj.free(mID) ``` +#### Java + ```java class Allocator { private TreeMap tm = new TreeMap<>(); @@ -343,6 +355,8 @@ class Allocator { */ ``` +#### C++ + ```cpp class Allocator { public: @@ -391,6 +405,8 @@ private: */ ``` +#### Go + ```go type Allocator struct { rbt *redblacktree.Tree diff --git a/solution/2500-2599/2503.Maximum Number of Points From Grid Queries/README.md b/solution/2500-2599/2503.Maximum Number of Points From Grid Queries/README.md index d36244363f211..7fd2bd79fb9d4 100644 --- a/solution/2500-2599/2503.Maximum Number of Points From Grid Queries/README.md +++ b/solution/2500-2599/2503.Maximum Number of Points From Grid Queries/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def maxPoints(self, grid: List[List[int]], queries: List[int]) -> List[int]: @@ -111,6 +113,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] maxPoints(int[][] grid, int[] queries) { @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -189,6 +195,8 @@ public: }; ``` +#### Go + ```go func maxPoints(grid [][]int, queries []int) []int { k := len(queries) @@ -246,6 +254,8 @@ func (h *hp) Pop() any { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; +#### Python3 + ```python class Solution: def maxPoints(self, grid: List[List[int]], queries: List[int]) -> List[int]: diff --git a/solution/2500-2599/2503.Maximum Number of Points From Grid Queries/README_EN.md b/solution/2500-2599/2503.Maximum Number of Points From Grid Queries/README_EN.md index ac98bcbf95b54..b1999e6334603 100644 --- a/solution/2500-2599/2503.Maximum Number of Points From Grid Queries/README_EN.md +++ b/solution/2500-2599/2503.Maximum Number of Points From Grid Queries/README_EN.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def maxPoints(self, grid: List[List[int]], queries: List[int]) -> List[int]: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] maxPoints(int[][] grid, int[] queries) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go func maxPoints(grid [][]int, queries []int) []int { k := len(queries) @@ -234,6 +242,8 @@ func (h *hp) Pop() any { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; +#### Python3 + ```python class Solution: def maxPoints(self, grid: List[List[int]], queries: List[int]) -> List[int]: diff --git a/solution/2500-2599/2504.Concatenate the Name and the Profession/README.md b/solution/2500-2599/2504.Concatenate the Name and the Profession/README.md index 0730b72553dd0..46140a6b2f742 100644 --- a/solution/2500-2599/2504.Concatenate the Name and the Profession/README.md +++ b/solution/2500-2599/2504.Concatenate the Name and the Profession/README.md @@ -79,6 +79,8 @@ Person 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT person_id, CONCAT(name, "(", SUBSTRING(profession, 1, 1), ")") AS name diff --git a/solution/2500-2599/2504.Concatenate the Name and the Profession/README_EN.md b/solution/2500-2599/2504.Concatenate the Name and the Profession/README_EN.md index 3db9918a8ecc3..152c3dbd8ca73 100644 --- a/solution/2500-2599/2504.Concatenate the Name and the Profession/README_EN.md +++ b/solution/2500-2599/2504.Concatenate the Name and the Profession/README_EN.md @@ -79,6 +79,8 @@ Person table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT person_id, CONCAT(name, "(", SUBSTRING(profession, 1, 1), ")") AS name diff --git a/solution/2500-2599/2505.Bitwise OR of All Subsequence Sums/README.md b/solution/2500-2599/2505.Bitwise OR of All Subsequence Sums/README.md index c23ce58215ce5..8f0d867aa8cf8 100644 --- a/solution/2500-2599/2505.Bitwise OR of All Subsequence Sums/README.md +++ b/solution/2500-2599/2505.Bitwise OR of All Subsequence Sums/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def subsequenceSumOr(self, nums: List[int]) -> int: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long subsequenceSumOr(int[] nums) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func subsequenceSumOr(nums []int) int64 { cnt := make([]int, 64) diff --git a/solution/2500-2599/2505.Bitwise OR of All Subsequence Sums/README_EN.md b/solution/2500-2599/2505.Bitwise OR of All Subsequence Sums/README_EN.md index 1f5fa58d1d70e..efa39b26b9614 100644 --- a/solution/2500-2599/2505.Bitwise OR of All Subsequence Sums/README_EN.md +++ b/solution/2500-2599/2505.Bitwise OR of All Subsequence Sums/README_EN.md @@ -59,6 +59,8 @@ And we have 0 OR 1 OR 2 OR 3 OR 4 OR 5 OR 6 = 7, so we return 7. +#### Python3 + ```python class Solution: def subsequenceSumOr(self, nums: List[int]) -> int: @@ -75,6 +77,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long subsequenceSumOr(int[] nums) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func subsequenceSumOr(nums []int) int64 { cnt := make([]int, 64) diff --git a/solution/2500-2599/2506.Count Pairs Of Similar Strings/README.md b/solution/2500-2599/2506.Count Pairs Of Similar Strings/README.md index c9281d2a9bc33..cd17af9badb85 100644 --- a/solution/2500-2599/2506.Count Pairs Of Similar Strings/README.md +++ b/solution/2500-2599/2506.Count Pairs Of Similar Strings/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def similarPairs(self, words: List[str]) -> int: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int similarPairs(String[] words) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func similarPairs(words []string) (ans int) { cnt := map[int]int{} @@ -152,6 +160,8 @@ func similarPairs(words []string) (ans int) { } ``` +#### TypeScript + ```ts function similarPairs(words: string[]): number { let ans = 0; @@ -168,6 +178,8 @@ function similarPairs(words: string[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/2500-2599/2506.Count Pairs Of Similar Strings/README_EN.md b/solution/2500-2599/2506.Count Pairs Of Similar Strings/README_EN.md index a1b9915521ea3..4fd22e5926292 100644 --- a/solution/2500-2599/2506.Count Pairs Of Similar Strings/README_EN.md +++ b/solution/2500-2599/2506.Count Pairs Of Similar Strings/README_EN.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def similarPairs(self, words: List[str]) -> int: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int similarPairs(String[] words) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func similarPairs(words []string) (ans int) { cnt := map[int]int{} @@ -144,6 +152,8 @@ func similarPairs(words []string) (ans int) { } ``` +#### TypeScript + ```ts function similarPairs(words: string[]): number { let ans = 0; @@ -160,6 +170,8 @@ function similarPairs(words: string[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/2500-2599/2507.Smallest Value After Replacing With Sum of Prime Factors/README.md b/solution/2500-2599/2507.Smallest Value After Replacing With Sum of Prime Factors/README.md index 0cc75b7ad03db..dca6e53bc02fb 100644 --- a/solution/2500-2599/2507.Smallest Value After Replacing With Sum of Prime Factors/README.md +++ b/solution/2500-2599/2507.Smallest Value After Replacing With Sum of Prime Factors/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def smallestValue(self, n: int) -> int: @@ -89,6 +91,8 @@ class Solution: n = s ``` +#### Java + ```java class Solution { public int smallestValue(int n) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func smallestValue(n int) int { for { diff --git a/solution/2500-2599/2507.Smallest Value After Replacing With Sum of Prime Factors/README_EN.md b/solution/2500-2599/2507.Smallest Value After Replacing With Sum of Prime Factors/README_EN.md index da502d0506961..7b3ea9be249e8 100644 --- a/solution/2500-2599/2507.Smallest Value After Replacing With Sum of Prime Factors/README_EN.md +++ b/solution/2500-2599/2507.Smallest Value After Replacing With Sum of Prime Factors/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def smallestValue(self, n: int) -> int: @@ -86,6 +88,8 @@ class Solution: n = s ``` +#### Java + ```java class Solution { public int smallestValue(int n) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func smallestValue(n int) int { for { diff --git a/solution/2500-2599/2508.Add Edges to Make Degrees of All Nodes Even/README.md b/solution/2500-2599/2508.Add Edges to Make Degrees of All Nodes Even/README.md index 1708380a1bc89..b9a328daca062 100644 --- a/solution/2500-2599/2508.Add Edges to Make Degrees of All Nodes Even/README.md +++ b/solution/2500-2599/2508.Add Edges to Make Degrees of All Nodes Even/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def isPossible(self, n: int, edges: List[List[int]]) -> bool: @@ -120,6 +122,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean isPossible(int n, List> edges) { @@ -169,6 +173,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -210,6 +216,8 @@ public: }; ``` +#### Go + ```go func isPossible(n int, edges [][]int) bool { g := make([]map[int]bool, n+1) diff --git a/solution/2500-2599/2508.Add Edges to Make Degrees of All Nodes Even/README_EN.md b/solution/2500-2599/2508.Add Edges to Make Degrees of All Nodes Even/README_EN.md index 99bb8c925976a..62154bcd75034 100644 --- a/solution/2500-2599/2508.Add Edges to Make Degrees of All Nodes Even/README_EN.md +++ b/solution/2500-2599/2508.Add Edges to Make Degrees of All Nodes Even/README_EN.md @@ -73,6 +73,8 @@ Every node in the resulting graph is connected to an even number of edges. +#### Python3 + ```python class Solution: def isPossible(self, n: int, edges: List[List[int]]) -> bool: @@ -100,6 +102,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean isPossible(int n, List> edges) { @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -190,6 +196,8 @@ public: }; ``` +#### Go + ```go func isPossible(n int, edges [][]int) bool { g := make([]map[int]bool, n+1) diff --git a/solution/2500-2599/2509.Cycle Length Queries in a Tree/README.md b/solution/2500-2599/2509.Cycle Length Queries in a Tree/README.md index 9abd82036caba..32a86166c6672 100644 --- a/solution/2500-2599/2509.Cycle Length Queries in a Tree/README.md +++ b/solution/2500-2599/2509.Cycle Length Queries in a Tree/README.md @@ -100,6 +100,8 @@ tags: +#### Python3 + ```python class Solution: def cycleLengthQueries(self, n: int, queries: List[List[int]]) -> List[int]: @@ -116,6 +118,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] cycleLengthQueries(int n, int[][] queries) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func cycleLengthQueries(n int, queries [][]int) []int { ans := []int{} diff --git a/solution/2500-2599/2509.Cycle Length Queries in a Tree/README_EN.md b/solution/2500-2599/2509.Cycle Length Queries in a Tree/README_EN.md index 43283d7ebe70c..1fc448893b164 100644 --- a/solution/2500-2599/2509.Cycle Length Queries in a Tree/README_EN.md +++ b/solution/2500-2599/2509.Cycle Length Queries in a Tree/README_EN.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def cycleLengthQueries(self, n: int, queries: List[List[int]]) -> List[int]: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] cycleLengthQueries(int n, int[][] queries) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func cycleLengthQueries(n int, queries [][]int) []int { ans := []int{} diff --git a/solution/2500-2599/2510.Check if There is a Path With Equal Number of 0's And 1's/README.md b/solution/2500-2599/2510.Check if There is a Path With Equal Number of 0's And 1's/README.md index fdf6929e6d18c..faff92eaa3a4f 100644 --- a/solution/2500-2599/2510.Check if There is a Path With Equal Number of 0's And 1's/README.md +++ b/solution/2500-2599/2510.Check if There is a Path With Equal Number of 0's And 1's/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def isThereAPath(self, grid: List[List[int]]) -> bool: @@ -89,6 +91,8 @@ class Solution: return dfs(0, 0, 0) ``` +#### Java + ```java class Solution { private int s; @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func isThereAPath(grid [][]int) bool { m, n := len(grid), len(grid[0]) diff --git a/solution/2500-2599/2510.Check if There is a Path With Equal Number of 0's And 1's/README_EN.md b/solution/2500-2599/2510.Check if There is a Path With Equal Number of 0's And 1's/README_EN.md index f93168dd58946..1742ea5e83382 100644 --- a/solution/2500-2599/2510.Check if There is a Path With Equal Number of 0's And 1's/README_EN.md +++ b/solution/2500-2599/2510.Check if There is a Path With Equal Number of 0's And 1's/README_EN.md @@ -59,6 +59,8 @@ tags: +#### Python3 + ```python class Solution: def isThereAPath(self, grid: List[List[int]]) -> bool: @@ -81,6 +83,8 @@ class Solution: return dfs(0, 0, 0) ``` +#### Java + ```java class Solution { private int s; @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func isThereAPath(grid [][]int) bool { m, n := len(grid), len(grid[0]) diff --git a/solution/2500-2599/2511.Maximum Enemy Forts That Can Be Captured/README.md b/solution/2500-2599/2511.Maximum Enemy Forts That Can Be Captured/README.md index 7648bf69fb902..7cf37c724b58c 100644 --- a/solution/2500-2599/2511.Maximum Enemy Forts That Can Be Captured/README.md +++ b/solution/2500-2599/2511.Maximum Enemy Forts That Can Be Captured/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def captureForts(self, forts: List[int]) -> int: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int captureForts(int[] forts) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func captureForts(forts []int) (ans int) { n := len(forts) @@ -161,6 +169,8 @@ func captureForts(forts []int) (ans int) { } ``` +#### TypeScript + ```ts function captureForts(forts: number[]): number { const n = forts.length; @@ -182,6 +192,8 @@ function captureForts(forts: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn capture_forts(forts: Vec) -> i32 { @@ -215,6 +227,8 @@ impl Solution { +#### Rust + ```rust impl Solution { pub fn capture_forts(forts: Vec) -> i32 { diff --git a/solution/2500-2599/2511.Maximum Enemy Forts That Can Be Captured/README_EN.md b/solution/2500-2599/2511.Maximum Enemy Forts That Can Be Captured/README_EN.md index f4e2d822357e6..b46d1246ead1f 100644 --- a/solution/2500-2599/2511.Maximum Enemy Forts That Can Be Captured/README_EN.md +++ b/solution/2500-2599/2511.Maximum Enemy Forts That Can Be Captured/README_EN.md @@ -76,6 +76,8 @@ Since 4 is the maximum number of enemy forts that can be captured, we return 4. +#### Python3 + ```python class Solution: def captureForts(self, forts: List[int]) -> int: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int captureForts(int[] forts) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func captureForts(forts []int) (ans int) { n := len(forts) @@ -157,6 +165,8 @@ func captureForts(forts []int) (ans int) { } ``` +#### TypeScript + ```ts function captureForts(forts: number[]): number { const n = forts.length; @@ -178,6 +188,8 @@ function captureForts(forts: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn capture_forts(forts: Vec) -> i32 { @@ -211,6 +223,8 @@ impl Solution { +#### Rust + ```rust impl Solution { pub fn capture_forts(forts: Vec) -> i32 { diff --git a/solution/2500-2599/2512.Reward Top K Students/README.md b/solution/2500-2599/2512.Reward Top K Students/README.md index 9453b05eef6a4..fc55f6119b564 100644 --- a/solution/2500-2599/2512.Reward Top K Students/README.md +++ b/solution/2500-2599/2512.Reward Top K Students/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def topStudents( @@ -112,6 +114,8 @@ class Solution: return [v[1] for v in arr[:k]] ``` +#### Java + ```java class Solution { public List topStudents(String[] positive_feedback, String[] negative_feedback, @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -189,6 +195,8 @@ public: }; ``` +#### Go + ```go func topStudents(positive_feedback []string, negative_feedback []string, report []string, student_id []int, k int) (ans []int) { ps := map[string]bool{} @@ -219,6 +227,8 @@ func topStudents(positive_feedback []string, negative_feedback []string, report } ``` +#### TypeScript + ```ts function topStudents( positive_feedback: string[], @@ -257,6 +267,8 @@ function topStudents( } ``` +#### Rust + ```rust use std::collections::{ HashMap, HashSet }; impl Solution { diff --git a/solution/2500-2599/2512.Reward Top K Students/README_EN.md b/solution/2500-2599/2512.Reward Top K Students/README_EN.md index d25405cb2d140..55c91662fc1ae 100644 --- a/solution/2500-2599/2512.Reward Top K Students/README_EN.md +++ b/solution/2500-2599/2512.Reward Top K Students/README_EN.md @@ -87,6 +87,8 @@ The time complexity is $O(n \times \log n + (|ps| + |ns| + n) \times |s|)$, and +#### Python3 + ```python class Solution: def topStudents( @@ -112,6 +114,8 @@ class Solution: return [v[1] for v in arr[:k]] ``` +#### Java + ```java class Solution { public List topStudents(String[] positive_feedback, String[] negative_feedback, @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -189,6 +195,8 @@ public: }; ``` +#### Go + ```go func topStudents(positive_feedback []string, negative_feedback []string, report []string, student_id []int, k int) (ans []int) { ps := map[string]bool{} @@ -219,6 +227,8 @@ func topStudents(positive_feedback []string, negative_feedback []string, report } ``` +#### TypeScript + ```ts function topStudents( positive_feedback: string[], @@ -257,6 +267,8 @@ function topStudents( } ``` +#### Rust + ```rust use std::collections::{ HashMap, HashSet }; impl Solution { diff --git a/solution/2500-2599/2513.Minimize the Maximum of Two Arrays/README.md b/solution/2500-2599/2513.Minimize the Maximum of Two Arrays/README.md index 956256fd66efa..ec6475cc713c1 100644 --- a/solution/2500-2599/2513.Minimize the Maximum of Two Arrays/README.md +++ b/solution/2500-2599/2513.Minimize the Maximum of Two Arrays/README.md @@ -83,6 +83,8 @@ arr1 = [1,2] 和 arr2 = [3] 满足所有条件。 +#### Python3 + ```python class Solution: def minimizeSet( @@ -102,6 +104,8 @@ class Solution: return bisect_left(range(10**10), True, key=f) ``` +#### Java + ```java class Solution { public int minimizeSet(int divisor1, int divisor2, int uniqueCnt1, int uniqueCnt2) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func minimizeSet(divisor1 int, divisor2 int, uniqueCnt1 int, uniqueCnt2 int) int { divisor := lcm(divisor1, divisor2) diff --git a/solution/2500-2599/2513.Minimize the Maximum of Two Arrays/README_EN.md b/solution/2500-2599/2513.Minimize the Maximum of Two Arrays/README_EN.md index 490e7c9ee6902..e5c6bbf2b9dc4 100644 --- a/solution/2500-2599/2513.Minimize the Maximum of Two Arrays/README_EN.md +++ b/solution/2500-2599/2513.Minimize the Maximum of Two Arrays/README_EN.md @@ -81,6 +81,8 @@ It can be shown that it is not possible to obtain a lower maximum satisfying all +#### Python3 + ```python class Solution: def minimizeSet( @@ -100,6 +102,8 @@ class Solution: return bisect_left(range(10**10), True, key=f) ``` +#### Java + ```java class Solution { public int minimizeSet(int divisor1, int divisor2, int uniqueCnt1, int uniqueCnt2) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func minimizeSet(divisor1 int, divisor2 int, uniqueCnt1 int, uniqueCnt2 int) int { divisor := lcm(divisor1, divisor2) diff --git a/solution/2500-2599/2514.Count Anagrams/README.md b/solution/2500-2599/2514.Count Anagrams/README.md index ec4cfa05e6356..1bfa4d98d5cb4 100644 --- a/solution/2500-2599/2514.Count Anagrams/README.md +++ b/solution/2500-2599/2514.Count Anagrams/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python mod = 10**9 + 7 f = [1] @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java import java.math.BigInteger; @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go const mod int = 1e9 + 7 @@ -188,6 +196,8 @@ func pow(x, n int) int { +#### Python3 + ```python class Solution: def countAnagrams(self, s: str) -> int: diff --git a/solution/2500-2599/2514.Count Anagrams/README_EN.md b/solution/2500-2599/2514.Count Anagrams/README_EN.md index 084346ccec72f..0f0409c3ae82d 100644 --- a/solution/2500-2599/2514.Count Anagrams/README_EN.md +++ b/solution/2500-2599/2514.Count Anagrams/README_EN.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python mod = 10**9 + 7 f = [1] @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java import java.math.BigInteger; @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go const mod int = 1e9 + 7 @@ -188,6 +196,8 @@ func pow(x, n int) int { +#### Python3 + ```python class Solution: def countAnagrams(self, s: str) -> int: diff --git a/solution/2500-2599/2515.Shortest Distance to Target String in a Circular Array/README.md b/solution/2500-2599/2515.Shortest Distance to Target String in a Circular Array/README.md index 2122f225cf039..615b7cca0826f 100644 --- a/solution/2500-2599/2515.Shortest Distance to Target String in a Circular Array/README.md +++ b/solution/2500-2599/2515.Shortest Distance to Target String in a Circular Array/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def closetTarget(self, words: List[str], target: str, startIndex: int) -> int: @@ -96,6 +98,8 @@ class Solution: return -1 if ans == n else ans ``` +#### Java + ```java class Solution { public int closetTarget(String[] words, String target, int startIndex) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func closetTarget(words []string, target string, startIndex int) int { n := len(words) @@ -155,6 +163,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function closetTarget(words: string[], target: string, startIndex: number): number { const n = words.length; @@ -167,6 +177,8 @@ function closetTarget(words: string[], target: string, startIndex: number): numb } ``` +#### Rust + ```rust impl Solution { pub fn closet_target(words: Vec, target: String, start_index: i32) -> i32 { @@ -185,6 +197,8 @@ impl Solution { } ``` +#### C + ```c int closetTarget(char** words, int wordsSize, char* target, int startIndex) { for (int i = 0; i <= wordsSize >> 1; i++) { @@ -206,6 +220,8 @@ int closetTarget(char** words, int wordsSize, char* target, int startIndex) { +#### Rust + ```rust use std::cmp::min; diff --git a/solution/2500-2599/2515.Shortest Distance to Target String in a Circular Array/README_EN.md b/solution/2500-2599/2515.Shortest Distance to Target String in a Circular Array/README_EN.md index 38e85008596db..5d2c2f1bd0a72 100644 --- a/solution/2500-2599/2515.Shortest Distance to Target String in a Circular Array/README_EN.md +++ b/solution/2500-2599/2515.Shortest Distance to Target String in a Circular Array/README_EN.md @@ -81,6 +81,8 @@ The shortest distance to reach "leetcode" is 1. +#### Python3 + ```python class Solution: def closetTarget(self, words: List[str], target: str, startIndex: int) -> int: @@ -93,6 +95,8 @@ class Solution: return -1 if ans == n else ans ``` +#### Java + ```java class Solution { public int closetTarget(String[] words, String target, int startIndex) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func closetTarget(words []string, target string, startIndex int) int { n := len(words) @@ -152,6 +160,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function closetTarget(words: string[], target: string, startIndex: number): number { const n = words.length; @@ -164,6 +174,8 @@ function closetTarget(words: string[], target: string, startIndex: number): numb } ``` +#### Rust + ```rust impl Solution { pub fn closet_target(words: Vec, target: String, start_index: i32) -> i32 { @@ -182,6 +194,8 @@ impl Solution { } ``` +#### C + ```c int closetTarget(char** words, int wordsSize, char* target, int startIndex) { for (int i = 0; i <= wordsSize >> 1; i++) { @@ -203,6 +217,8 @@ int closetTarget(char** words, int wordsSize, char* target, int startIndex) { +#### Rust + ```rust use std::cmp::min; diff --git a/solution/2500-2599/2516.Take K of Each Character From Left and Right/README.md b/solution/2500-2599/2516.Take K of Each Character From Left and Right/README.md index 997580a5fe912..80675bac66453 100644 --- a/solution/2500-2599/2516.Take K of Each Character From Left and Right/README.md +++ b/solution/2500-2599/2516.Take K of Each Character From Left and Right/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def takeCharacters(self, s: str, k: int) -> int: @@ -92,6 +94,8 @@ class Solution: return len(s) - mx ``` +#### Java + ```java class Solution { public int takeCharacters(String s, int k) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func takeCharacters(s string, k int) int { cnt := [3]int{} @@ -170,6 +178,8 @@ func takeCharacters(s string, k int) int { } ``` +#### TypeScript + ```ts function takeCharacters(s: string, k: number): number { const idx = (c: string) => c.charCodeAt(0) - 97; @@ -194,6 +204,8 @@ function takeCharacters(s: string, k: number): number { } ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/2500-2599/2516.Take K of Each Character From Left and Right/README_EN.md b/solution/2500-2599/2516.Take K of Each Character From Left and Right/README_EN.md index 516125d74bcd7..98b50f227be89 100644 --- a/solution/2500-2599/2516.Take K of Each Character From Left and Right/README_EN.md +++ b/solution/2500-2599/2516.Take K of Each Character From Left and Right/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(n)$, where $n$ is the length of string $s$. The space +#### Python3 + ```python class Solution: def takeCharacters(self, s: str, k: int) -> int: @@ -90,6 +92,8 @@ class Solution: return len(s) - mx ``` +#### Java + ```java class Solution { public int takeCharacters(String s, int k) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func takeCharacters(s string, k int) int { cnt := [3]int{} @@ -168,6 +176,8 @@ func takeCharacters(s string, k int) int { } ``` +#### TypeScript + ```ts function takeCharacters(s: string, k: number): number { const idx = (c: string) => c.charCodeAt(0) - 97; @@ -192,6 +202,8 @@ function takeCharacters(s: string, k: number): number { } ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/2500-2599/2517.Maximum Tastiness of Candy Basket/README.md b/solution/2500-2599/2517.Maximum Tastiness of Candy Basket/README.md index 96ae241484e9f..cb001aaad8df7 100644 --- a/solution/2500-2599/2517.Maximum Tastiness of Candy Basket/README.md +++ b/solution/2500-2599/2517.Maximum Tastiness of Candy Basket/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def maximumTastiness(self, price: List[int], k: int) -> int: @@ -108,6 +110,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { public int maximumTastiness(int[] price, int k) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go func maximumTastiness(price []int, k int) int { sort.Ints(price) @@ -182,6 +190,8 @@ func maximumTastiness(price []int, k int) int { } ``` +#### TypeScript + ```ts function maximumTastiness(price: number[], k: number): number { price.sort((a, b) => a - b); @@ -209,6 +219,8 @@ function maximumTastiness(price: number[], k: number): number { } ``` +#### C# + ```cs public class Solution { public int MaximumTastiness(int[] price, int k) { diff --git a/solution/2500-2599/2517.Maximum Tastiness of Candy Basket/README_EN.md b/solution/2500-2599/2517.Maximum Tastiness of Candy Basket/README_EN.md index 47963c575073d..66f5fe9627e87 100644 --- a/solution/2500-2599/2517.Maximum Tastiness of Candy Basket/README_EN.md +++ b/solution/2500-2599/2517.Maximum Tastiness of Candy Basket/README_EN.md @@ -74,6 +74,8 @@ It can be proven that 2 is the maximum tastiness that can be achieved. +#### Python3 + ```python class Solution: def maximumTastiness(self, price: List[int], k: int) -> int: @@ -96,6 +98,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { public int maximumTastiness(int[] price, int k) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func maximumTastiness(price []int, k int) int { sort.Ints(price) @@ -170,6 +178,8 @@ func maximumTastiness(price []int, k int) int { } ``` +#### TypeScript + ```ts function maximumTastiness(price: number[], k: number): number { price.sort((a, b) => a - b); @@ -197,6 +207,8 @@ function maximumTastiness(price: number[], k: number): number { } ``` +#### C# + ```cs public class Solution { public int MaximumTastiness(int[] price, int k) { diff --git a/solution/2500-2599/2518.Number of Great Partitions/README.md b/solution/2500-2599/2518.Number of Great Partitions/README.md index 7d833003f7984..badaa2171d00a 100644 --- a/solution/2500-2599/2518.Number of Great Partitions/README.md +++ b/solution/2500-2599/2518.Number of Great Partitions/README.md @@ -92,6 +92,8 @@ $$ +#### Python3 + ```python class Solution: def countPartitions(self, nums: List[int], k: int) -> int: @@ -111,6 +113,8 @@ class Solution: return (ans - sum(f[-1]) * 2 + mod) % mod ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go func countPartitions(nums []int, k int) int { s := 0 diff --git a/solution/2500-2599/2518.Number of Great Partitions/README_EN.md b/solution/2500-2599/2518.Number of Great Partitions/README_EN.md index f52451dde611f..dcc1770c82c95 100644 --- a/solution/2500-2599/2518.Number of Great Partitions/README_EN.md +++ b/solution/2500-2599/2518.Number of Great Partitions/README_EN.md @@ -71,6 +71,8 @@ The great partitions will be ([6], [6]) and ([6], [6]). +#### Python3 + ```python class Solution: def countPartitions(self, nums: List[int], k: int) -> int: @@ -90,6 +92,8 @@ class Solution: return (ans - sum(f[-1]) * 2 + mod) % mod ``` +#### Java + ```java class Solution { private static final int MOD = (int) 1e9 + 7; @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func countPartitions(nums []int, k int) int { s := 0 diff --git a/solution/2500-2599/2519.Count the Number of K-Big Indices/README.md b/solution/2500-2599/2519.Count the Number of K-Big Indices/README.md index baad187b063f1..bf3e63181dffe 100644 --- a/solution/2500-2599/2519.Count the Number of K-Big Indices/README.md +++ b/solution/2500-2599/2519.Count the Number of K-Big Indices/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -111,6 +113,8 @@ class Solution: return ans ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -159,6 +163,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -207,6 +213,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int diff --git a/solution/2500-2599/2519.Count the Number of K-Big Indices/README_EN.md b/solution/2500-2599/2519.Count the Number of K-Big Indices/README_EN.md index 138606493164c..400779d495627 100644 --- a/solution/2500-2599/2519.Count the Number of K-Big Indices/README_EN.md +++ b/solution/2500-2599/2519.Count the Number of K-Big Indices/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$, +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): @@ -110,6 +112,8 @@ class Solution: return ans ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -158,6 +162,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -206,6 +212,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int diff --git a/solution/2500-2599/2520.Count the Digits That Divide a Number/README.md b/solution/2500-2599/2520.Count the Digits That Divide a Number/README.md index eac2dbcf98420..c4f3755dbc30c 100644 --- a/solution/2500-2599/2520.Count the Digits That Divide a Number/README.md +++ b/solution/2500-2599/2520.Count the Digits That Divide a Number/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def countDigits(self, num: int) -> int: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countDigits(int num) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func countDigits(num int) (ans int) { for x := num; x > 0; x /= 10 { @@ -120,6 +128,8 @@ func countDigits(num int) (ans int) { } ``` +#### TypeScript + ```ts function countDigits(num: number): number { let ans = 0; @@ -132,6 +142,8 @@ function countDigits(num: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_digits(num: i32) -> i32 { @@ -148,6 +160,8 @@ impl Solution { } ``` +#### C + ```c int countDigits(int num) { int ans = 0; @@ -172,6 +186,8 @@ int countDigits(int num) { +#### TypeScript + ```ts function countDigits(num: number): number { let ans = 0; @@ -184,6 +200,8 @@ function countDigits(num: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_digits(num: i32) -> i32 { diff --git a/solution/2500-2599/2520.Count the Digits That Divide a Number/README_EN.md b/solution/2500-2599/2520.Count the Digits That Divide a Number/README_EN.md index 9a3c9b8201417..b18abae97d0ff 100644 --- a/solution/2500-2599/2520.Count the Digits That Divide a Number/README_EN.md +++ b/solution/2500-2599/2520.Count the Digits That Divide a Number/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(\log num)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def countDigits(self, num: int) -> int: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countDigits(int num) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func countDigits(num int) (ans int) { for x := num; x > 0; x /= 10 { @@ -121,6 +129,8 @@ func countDigits(num int) (ans int) { } ``` +#### TypeScript + ```ts function countDigits(num: number): number { let ans = 0; @@ -133,6 +143,8 @@ function countDigits(num: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_digits(num: i32) -> i32 { @@ -149,6 +161,8 @@ impl Solution { } ``` +#### C + ```c int countDigits(int num) { int ans = 0; @@ -173,6 +187,8 @@ int countDigits(int num) { +#### TypeScript + ```ts function countDigits(num: number): number { let ans = 0; @@ -185,6 +201,8 @@ function countDigits(num: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_digits(num: i32) -> i32 { diff --git a/solution/2500-2599/2521.Distinct Prime Factors of Product of Array/README.md b/solution/2500-2599/2521.Distinct Prime Factors of Product of Array/README.md index 9b96895170f12..aba31d5276fa3 100644 --- a/solution/2500-2599/2521.Distinct Prime Factors of Product of Array/README.md +++ b/solution/2500-2599/2521.Distinct Prime Factors of Product of Array/README.md @@ -72,6 +72,8 @@ nums 中所有元素的乘积是:2 * 4 * 8 * 16 = 1024 = 210 +#### Python3 + ```python class Solution: def distinctPrimeFactors(self, nums: List[int]) -> int: @@ -89,6 +91,8 @@ class Solution: return len(s) ``` +#### Java + ```java class Solution { public int distinctPrimeFactors(int[] nums) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func distinctPrimeFactors(nums []int) int { s := map[int]bool{} @@ -154,6 +162,8 @@ func distinctPrimeFactors(nums []int) int { } ``` +#### TypeScript + ```ts function distinctPrimeFactors(nums: number[]): number { const s: Set = new Set(); diff --git a/solution/2500-2599/2521.Distinct Prime Factors of Product of Array/README_EN.md b/solution/2500-2599/2521.Distinct Prime Factors of Product of Array/README_EN.md index 7e21250a89929..699ef4b6b64cf 100644 --- a/solution/2500-2599/2521.Distinct Prime Factors of Product of Array/README_EN.md +++ b/solution/2500-2599/2521.Distinct Prime Factors of Product of Array/README_EN.md @@ -73,6 +73,8 @@ The time complexity is $O(n \times \sqrt{m})$, and the space complexity is $O(\f +#### Python3 + ```python class Solution: def distinctPrimeFactors(self, nums: List[int]) -> int: @@ -90,6 +92,8 @@ class Solution: return len(s) ``` +#### Java + ```java class Solution { public int distinctPrimeFactors(int[] nums) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func distinctPrimeFactors(nums []int) int { s := map[int]bool{} @@ -155,6 +163,8 @@ func distinctPrimeFactors(nums []int) int { } ``` +#### TypeScript + ```ts function distinctPrimeFactors(nums: number[]): number { const s: Set = new Set(); diff --git a/solution/2500-2599/2522.Partition String Into Substrings With Values at Most K/README.md b/solution/2500-2599/2522.Partition String Into Substrings With Values at Most K/README.md index 088e81d8738fd..1a6adaab34c37 100644 --- a/solution/2500-2599/2522.Partition String Into Substrings With Values at Most K/README.md +++ b/solution/2500-2599/2522.Partition String Into Substrings With Values at Most K/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def minimumPartition(self, s: str, k: int) -> int: @@ -110,6 +112,8 @@ class Solution: return ans if ans < inf else -1 ``` +#### Java + ```java class Solution { private Integer[] f; @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func minimumPartition(s string, k int) int { n := len(s) diff --git a/solution/2500-2599/2522.Partition String Into Substrings With Values at Most K/README_EN.md b/solution/2500-2599/2522.Partition String Into Substrings With Values at Most K/README_EN.md index d0485375950a1..e8bfe6091c9d2 100644 --- a/solution/2500-2599/2522.Partition String Into Substrings With Values at Most K/README_EN.md +++ b/solution/2500-2599/2522.Partition String Into Substrings With Values at Most K/README_EN.md @@ -97,6 +97,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def minimumPartition(self, s: str, k: int) -> int: @@ -117,6 +119,8 @@ class Solution: return ans if ans < inf else -1 ``` +#### Java + ```java class Solution { private Integer[] f; @@ -155,6 +159,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func minimumPartition(s string, k int) int { n := len(s) diff --git a/solution/2500-2599/2523.Closest Prime Numbers in Range/README.md b/solution/2500-2599/2523.Closest Prime Numbers in Range/README.md index 5713651a06510..777736b987e51 100644 --- a/solution/2500-2599/2523.Closest Prime Numbers in Range/README.md +++ b/solution/2500-2599/2523.Closest Prime Numbers in Range/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def closestPrimes(self, left: int, right: int) -> List[int]: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] closestPrimes(int left, int right) { @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -187,6 +193,8 @@ public: }; ``` +#### Go + ```go func closestPrimes(left int, right int) []int { cnt := 0 diff --git a/solution/2500-2599/2523.Closest Prime Numbers in Range/README_EN.md b/solution/2500-2599/2523.Closest Prime Numbers in Range/README_EN.md index 37dffdf7d8346..29dcd7e77ab81 100644 --- a/solution/2500-2599/2523.Closest Prime Numbers in Range/README_EN.md +++ b/solution/2500-2599/2523.Closest Prime Numbers in Range/README_EN.md @@ -76,6 +76,8 @@ Since 11 is smaller than 17, we return the first pair. +#### Python3 + ```python class Solution: def closestPrimes(self, left: int, right: int) -> List[int]: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] closestPrimes(int left, int right) { @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -190,6 +196,8 @@ public: }; ``` +#### Go + ```go func closestPrimes(left int, right int) []int { cnt := 0 diff --git a/solution/2500-2599/2524.Maximum Frequency Score of a Subarray/README.md b/solution/2500-2599/2524.Maximum Frequency Score of a Subarray/README.md index fdf340a3cff84..95e7e7b50593e 100644 --- a/solution/2500-2599/2524.Maximum Frequency Score of a Subarray/README.md +++ b/solution/2500-2599/2524.Maximum Frequency Score of a Subarray/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def maxFrequencyScore(self, nums: List[int], k: int) -> int: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private final int mod = (int) 1e9 + 7; @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -183,6 +189,8 @@ public: }; ``` +#### Go + ```go func maxFrequencyScore(nums []int, k int) int { cnt := map[int]int{} diff --git a/solution/2500-2599/2524.Maximum Frequency Score of a Subarray/README_EN.md b/solution/2500-2599/2524.Maximum Frequency Score of a Subarray/README_EN.md index e30b0fe7cc5a5..38e1bbc6239d3 100644 --- a/solution/2500-2599/2524.Maximum Frequency Score of a Subarray/README_EN.md +++ b/solution/2500-2599/2524.Maximum Frequency Score of a Subarray/README_EN.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def maxFrequencyScore(self, nums: List[int], k: int) -> int: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private final int mod = (int) 1e9 + 7; @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go func maxFrequencyScore(nums []int, k int) int { cnt := map[int]int{} diff --git a/solution/2500-2599/2525.Categorize Box According to Criteria/README.md b/solution/2500-2599/2525.Categorize Box According to Criteria/README.md index 707c03ab674f0..952b3457ef6bd 100644 --- a/solution/2500-2599/2525.Categorize Box According to Criteria/README.md +++ b/solution/2500-2599/2525.Categorize Box According to Criteria/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def categorizeBox(self, length: int, width: int, height: int, mass: int) -> str: @@ -96,6 +98,8 @@ class Solution: return d[i] ``` +#### Java + ```java class Solution { public String categorizeBox(int length, int width, int height, int mass) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func categorizeBox(length int, width int, height int, mass int) string { v := length * width * height @@ -138,6 +146,8 @@ func categorizeBox(length int, width int, height int, mass int) string { } ``` +#### TypeScript + ```ts function categorizeBox(length: number, width: number, height: number, mass: number): string { const v = length * width * height; @@ -152,6 +162,8 @@ function categorizeBox(length: number, width: number, height: number, mass: numb } ``` +#### Rust + ```rust impl Solution { pub fn categorize_box(length: i32, width: i32, height: i32, mass: i32) -> String { @@ -182,6 +194,8 @@ impl Solution { +#### Python3 + ```python class Solution: def categorizeBox(self, length: int, width: int, height: int, mass: int) -> str: @@ -199,6 +213,8 @@ class Solution: return "Neither" ``` +#### Java + ```java class Solution { public String categorizeBox(int length, int width, int height, int mass) { @@ -221,6 +237,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -244,6 +262,8 @@ public: }; ``` +#### Go + ```go func categorizeBox(length int, width int, height int, mass int) string { v := length * width * height @@ -262,6 +282,8 @@ func categorizeBox(length int, width int, height int, mass int) string { } ``` +#### TypeScript + ```ts function categorizeBox(length: number, width: number, height: number, mass: number): string { const v = length * width * height; @@ -280,6 +302,8 @@ function categorizeBox(length: number, width: number, height: number, mass: numb } ``` +#### Rust + ```rust impl Solution { pub fn categorize_box(length: i32, width: i32, height: i32, mass: i32) -> String { diff --git a/solution/2500-2599/2525.Categorize Box According to Criteria/README_EN.md b/solution/2500-2599/2525.Categorize Box According to Criteria/README_EN.md index c872f53c4b806..f4ffa0fb31536 100644 --- a/solution/2500-2599/2525.Categorize Box According to Criteria/README_EN.md +++ b/solution/2500-2599/2525.Categorize Box According to Criteria/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def categorizeBox(self, length: int, width: int, height: int, mass: int) -> str: @@ -94,6 +96,8 @@ class Solution: return d[i] ``` +#### Java + ```java class Solution { public String categorizeBox(int length, int width, int height, int mass) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func categorizeBox(length int, width int, height int, mass int) string { v := length * width * height @@ -136,6 +144,8 @@ func categorizeBox(length int, width int, height int, mass int) string { } ``` +#### TypeScript + ```ts function categorizeBox(length: number, width: number, height: number, mass: number): string { const v = length * width * height; @@ -150,6 +160,8 @@ function categorizeBox(length: number, width: number, height: number, mass: numb } ``` +#### Rust + ```rust impl Solution { pub fn categorize_box(length: i32, width: i32, height: i32, mass: i32) -> String { @@ -180,6 +192,8 @@ impl Solution { +#### Python3 + ```python class Solution: def categorizeBox(self, length: int, width: int, height: int, mass: int) -> str: @@ -197,6 +211,8 @@ class Solution: return "Neither" ``` +#### Java + ```java class Solution { public String categorizeBox(int length, int width, int height, int mass) { @@ -219,6 +235,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -242,6 +260,8 @@ public: }; ``` +#### Go + ```go func categorizeBox(length int, width int, height int, mass int) string { v := length * width * height @@ -260,6 +280,8 @@ func categorizeBox(length int, width int, height int, mass int) string { } ``` +#### TypeScript + ```ts function categorizeBox(length: number, width: number, height: number, mass: number): string { const v = length * width * height; @@ -278,6 +300,8 @@ function categorizeBox(length: number, width: number, height: number, mass: numb } ``` +#### Rust + ```rust impl Solution { pub fn categorize_box(length: i32, width: i32, height: i32, mass: i32) -> String { diff --git a/solution/2500-2599/2526.Find Consecutive Integers from a Data Stream/README.md b/solution/2500-2599/2526.Find Consecutive Integers from a Data Stream/README.md index a4c0daedcb1aa..607077d83f71b 100644 --- a/solution/2500-2599/2526.Find Consecutive Integers from a Data Stream/README.md +++ b/solution/2500-2599/2526.Find Consecutive Integers from a Data Stream/README.md @@ -78,6 +78,8 @@ dataStream.consec(3); // 最后 k 个整数分别是 [4,4,3] 。 +#### Python3 + ```python class DataStream: def __init__(self, value: int, k: int): @@ -94,6 +96,8 @@ class DataStream: # param_1 = obj.consec(num) ``` +#### Java + ```java class DataStream { private int cnt; @@ -118,6 +122,8 @@ class DataStream { */ ``` +#### C++ + ```cpp class DataStream { public: @@ -143,6 +149,8 @@ private: */ ``` +#### Go + ```go type DataStream struct { val, k, cnt int @@ -168,6 +176,8 @@ func (this *DataStream) Consec(num int) bool { */ ``` +#### TypeScript + ```ts class DataStream { private val: number; diff --git a/solution/2500-2599/2526.Find Consecutive Integers from a Data Stream/README_EN.md b/solution/2500-2599/2526.Find Consecutive Integers from a Data Stream/README_EN.md index 0c785a14556c6..db06510c54582 100644 --- a/solution/2500-2599/2526.Find Consecutive Integers from a Data Stream/README_EN.md +++ b/solution/2500-2599/2526.Find Consecutive Integers from a Data Stream/README_EN.md @@ -70,6 +70,8 @@ dataStream.consec(3); // The last k integers parsed in the stream are [4,4,3]. +#### Python3 + ```python class DataStream: def __init__(self, value: int, k: int): @@ -86,6 +88,8 @@ class DataStream: # param_1 = obj.consec(num) ``` +#### Java + ```java class DataStream { private int cnt; @@ -110,6 +114,8 @@ class DataStream { */ ``` +#### C++ + ```cpp class DataStream { public: @@ -135,6 +141,8 @@ private: */ ``` +#### Go + ```go type DataStream struct { val, k, cnt int @@ -160,6 +168,8 @@ func (this *DataStream) Consec(num int) bool { */ ``` +#### TypeScript + ```ts class DataStream { private val: number; diff --git a/solution/2500-2599/2527.Find Xor-Beauty of Array/README.md b/solution/2500-2599/2527.Find Xor-Beauty of Array/README.md index f073f2174adf8..4230ac5dd8991 100644 --- a/solution/2500-2599/2527.Find Xor-Beauty of Array/README.md +++ b/solution/2500-2599/2527.Find Xor-Beauty of Array/README.md @@ -89,12 +89,16 @@ tags: +#### Python3 + ```python class Solution: def xorBeauty(self, nums: List[int]) -> int: return reduce(xor, nums) ``` +#### Java + ```java class Solution { public int xorBeauty(int[] nums) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func xorBeauty(nums []int) (ans int) { for _, x := range nums { @@ -129,6 +137,8 @@ func xorBeauty(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function xorBeauty(nums: number[]): number { return nums.reduce((acc, cur) => acc ^ cur, 0); diff --git a/solution/2500-2599/2527.Find Xor-Beauty of Array/README_EN.md b/solution/2500-2599/2527.Find Xor-Beauty of Array/README_EN.md index 131c64e6c9de8..c1552595eaffe 100644 --- a/solution/2500-2599/2527.Find Xor-Beauty of Array/README_EN.md +++ b/solution/2500-2599/2527.Find Xor-Beauty of Array/README_EN.md @@ -79,12 +79,16 @@ Xor-beauty of array will be bitwise XOR of all beauties = 1 ^ 0 ^ 1 ^ 4 ^ 1 ^ 4 +#### Python3 + ```python class Solution: def xorBeauty(self, nums: List[int]) -> int: return reduce(xor, nums) ``` +#### Java + ```java class Solution { public int xorBeauty(int[] nums) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func xorBeauty(nums []int) (ans int) { for _, x := range nums { @@ -119,6 +127,8 @@ func xorBeauty(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function xorBeauty(nums: number[]): number { return nums.reduce((acc, cur) => acc ^ cur, 0); diff --git a/solution/2500-2599/2528.Maximize the Minimum Powered City/README.md b/solution/2500-2599/2528.Maximize the Minimum Powered City/README.md index 7d0067f908bb8..a063a2f3e728a 100644 --- a/solution/2500-2599/2528.Maximize the Minimum Powered City/README.md +++ b/solution/2500-2599/2528.Maximize the Minimum Powered City/README.md @@ -101,6 +101,8 @@ tags: +#### Python3 + ```python class Solution: def maxPower(self, stations: List[int], r: int, k: int) -> int: @@ -138,6 +140,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { private long[] s; @@ -192,6 +196,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -243,6 +249,8 @@ public: }; ``` +#### Go + ```go func maxPower(stations []int, r int, k int) int64 { n := len(stations) @@ -290,6 +298,8 @@ func maxPower(stations []int, r int, k int) int64 { } ``` +#### TypeScript + ```ts function maxPower(stations: number[], r: number, k: number): number { function check(x: bigint, k: bigint): boolean { diff --git a/solution/2500-2599/2528.Maximize the Minimum Powered City/README_EN.md b/solution/2500-2599/2528.Maximize the Minimum Powered City/README_EN.md index 500dc378cfd6e..a0ad2f0d95e0a 100644 --- a/solution/2500-2599/2528.Maximize the Minimum Powered City/README_EN.md +++ b/solution/2500-2599/2528.Maximize the Minimum Powered City/README_EN.md @@ -87,6 +87,8 @@ It can be proved that we cannot make the minimum power of a city greater than 4. +#### Python3 + ```python class Solution: def maxPower(self, stations: List[int], r: int, k: int) -> int: @@ -124,6 +126,8 @@ class Solution: return left ``` +#### Java + ```java class Solution { private long[] s; @@ -178,6 +182,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -229,6 +235,8 @@ public: }; ``` +#### Go + ```go func maxPower(stations []int, r int, k int) int64 { n := len(stations) @@ -276,6 +284,8 @@ func maxPower(stations []int, r int, k int) int64 { } ``` +#### TypeScript + ```ts function maxPower(stations: number[], r: number, k: number): number { function check(x: bigint, k: bigint): boolean { diff --git a/solution/2500-2599/2529.Maximum Count of Positive Integer and Negative Integer/README.md b/solution/2500-2599/2529.Maximum Count of Positive Integer and Negative Integer/README.md index e30bf1e824d83..fb23d6af7fc82 100644 --- a/solution/2500-2599/2529.Maximum Count of Positive Integer and Negative Integer/README.md +++ b/solution/2500-2599/2529.Maximum Count of Positive Integer and Negative Integer/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def maximumCount(self, nums: List[int]) -> int: @@ -90,6 +92,8 @@ class Solution: return max(a, b) ``` +#### Java + ```java class Solution { public int maximumCount(int[] nums) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func maximumCount(nums []int) int { var a, b int @@ -137,6 +145,8 @@ func maximumCount(nums []int) int { } ``` +#### TypeScript + ```ts function maximumCount(nums: number[]): number { let [a, b] = [0, 0]; @@ -151,6 +161,8 @@ function maximumCount(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn maximum_count(nums: Vec) -> i32 { @@ -170,6 +182,8 @@ impl Solution { } ``` +#### C + ```c #define max(a, b) (a > b ? a : b) @@ -200,6 +214,8 @@ int maximumCount(int* nums, int numsSize) { +#### Python3 + ```python class Solution: def maximumCount(self, nums: List[int]) -> int: @@ -208,6 +224,8 @@ class Solution: return max(a, b) ``` +#### Java + ```java class Solution { public int maximumCount(int[] nums) { @@ -231,6 +249,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -242,6 +262,8 @@ public: }; ``` +#### Go + ```go func maximumCount(nums []int) int { a := len(nums) - sort.SearchInts(nums, 1) @@ -250,6 +272,8 @@ func maximumCount(nums []int) int { } ``` +#### TypeScript + ```ts function maximumCount(nums: number[]): number { const search = (x: number): number => { @@ -271,6 +295,8 @@ function maximumCount(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { fn search(nums: &Vec, x: i32) -> usize { @@ -296,6 +322,8 @@ impl Solution { } ``` +#### C + ```c #define max(a, b) (a > b ? a : b) diff --git a/solution/2500-2599/2529.Maximum Count of Positive Integer and Negative Integer/README_EN.md b/solution/2500-2599/2529.Maximum Count of Positive Integer and Negative Integer/README_EN.md index 3b0091fa1b6ec..cb5d35068f54b 100644 --- a/solution/2500-2599/2529.Maximum Count of Positive Integer and Negative Integer/README_EN.md +++ b/solution/2500-2599/2529.Maximum Count of Positive Integer and Negative Integer/README_EN.md @@ -79,6 +79,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def maximumCount(self, nums: List[int]) -> int: @@ -87,6 +89,8 @@ class Solution: return max(a, b) ``` +#### Java + ```java class Solution { public int maximumCount(int[] nums) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func maximumCount(nums []int) int { var a, b int @@ -134,6 +142,8 @@ func maximumCount(nums []int) int { } ``` +#### TypeScript + ```ts function maximumCount(nums: number[]): number { let [a, b] = [0, 0]; @@ -148,6 +158,8 @@ function maximumCount(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn maximum_count(nums: Vec) -> i32 { @@ -167,6 +179,8 @@ impl Solution { } ``` +#### C + ```c #define max(a, b) (a > b ? a : b) @@ -197,6 +211,8 @@ The time complexity is $O(\log n)$, where $n$ is the length of the array. The sp +#### Python3 + ```python class Solution: def maximumCount(self, nums: List[int]) -> int: @@ -205,6 +221,8 @@ class Solution: return max(a, b) ``` +#### Java + ```java class Solution { public int maximumCount(int[] nums) { @@ -228,6 +246,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -239,6 +259,8 @@ public: }; ``` +#### Go + ```go func maximumCount(nums []int) int { a := len(nums) - sort.SearchInts(nums, 1) @@ -247,6 +269,8 @@ func maximumCount(nums []int) int { } ``` +#### TypeScript + ```ts function maximumCount(nums: number[]): number { const search = (x: number): number => { @@ -268,6 +292,8 @@ function maximumCount(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { fn search(nums: &Vec, x: i32) -> usize { @@ -293,6 +319,8 @@ impl Solution { } ``` +#### C + ```c #define max(a, b) (a > b ? a : b) diff --git a/solution/2500-2599/2530.Maximal Score After Applying K Operations/README.md b/solution/2500-2599/2530.Maximal Score After Applying K Operations/README.md index 2fe9224946d49..d37deee80b869 100644 --- a/solution/2500-2599/2530.Maximal Score After Applying K Operations/README.md +++ b/solution/2500-2599/2530.Maximal Score After Applying K Operations/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def maxKelements(self, nums: List[int], k: int) -> int: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maxKelements(int[] nums, int k) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func maxKelements(nums []int, k int) (ans int64) { h := &hp{nums} @@ -155,6 +163,8 @@ func (h *hp) push(v int) { heap.Push(h, v) } func (h *hp) pop() int { return heap.Pop(h).(int) } ``` +#### TypeScript + ```ts function maxKelements(nums: number[], k: number): number { const pq = new MaxPriorityQueue(); @@ -170,6 +180,8 @@ function maxKelements(nums: number[], k: number): number { } ``` +#### Rust + ```rust use std::collections::BinaryHeap; @@ -200,6 +212,8 @@ impl Solution { +#### Python3 + ```python class Solution: def maxKelements(self, nums: List[int], k: int) -> int: @@ -212,6 +226,8 @@ class Solution: return ans ``` +#### C++ + ```cpp class Solution { public: @@ -230,6 +246,8 @@ public: }; ``` +#### Go + ```go func maxKelements(nums []int, k int) (ans int64) { h := hp{nums} diff --git a/solution/2500-2599/2530.Maximal Score After Applying K Operations/README_EN.md b/solution/2500-2599/2530.Maximal Score After Applying K Operations/README_EN.md index f19d01b87e5f5..a1dcfe3aa869e 100644 --- a/solution/2500-2599/2530.Maximal Score After Applying K Operations/README_EN.md +++ b/solution/2500-2599/2530.Maximal Score After Applying K Operations/README_EN.md @@ -79,6 +79,8 @@ The time complexity is $O(n + k \times \log n)$, and the space complexity is $O( +#### Python3 + ```python class Solution: def maxKelements(self, nums: List[int], k: int) -> int: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maxKelements(int[] nums, int k) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func maxKelements(nums []int, k int) (ans int64) { h := &hp{nums} @@ -153,6 +161,8 @@ func (h *hp) push(v int) { heap.Push(h, v) } func (h *hp) pop() int { return heap.Pop(h).(int) } ``` +#### TypeScript + ```ts function maxKelements(nums: number[], k: number): number { const pq = new MaxPriorityQueue(); @@ -168,6 +178,8 @@ function maxKelements(nums: number[], k: number): number { } ``` +#### Rust + ```rust use std::collections::BinaryHeap; @@ -198,6 +210,8 @@ impl Solution { +#### Python3 + ```python class Solution: def maxKelements(self, nums: List[int], k: int) -> int: @@ -210,6 +224,8 @@ class Solution: return ans ``` +#### C++ + ```cpp class Solution { public: @@ -228,6 +244,8 @@ public: }; ``` +#### Go + ```go func maxKelements(nums []int, k int) (ans int64) { h := hp{nums} diff --git a/solution/2500-2599/2531.Make Number of Distinct Characters Equal/README.md b/solution/2500-2599/2531.Make Number of Distinct Characters Equal/README.md index 360b6c8bd919b..562650aeba64f 100644 --- a/solution/2500-2599/2531.Make Number of Distinct Characters Equal/README.md +++ b/solution/2500-2599/2531.Make Number of Distinct Characters Equal/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def isItPossible(self, word1: str, word2: str) -> bool: @@ -101,6 +103,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean isItPossible(String word1, String word2) { @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go func isItPossible(word1 string, word2 string) bool { cnt1 := [26]int{} diff --git a/solution/2500-2599/2531.Make Number of Distinct Characters Equal/README_EN.md b/solution/2500-2599/2531.Make Number of Distinct Characters Equal/README_EN.md index 97427c996333f..9a1bb1fc3f55c 100644 --- a/solution/2500-2599/2531.Make Number of Distinct Characters Equal/README_EN.md +++ b/solution/2500-2599/2531.Make Number of Distinct Characters Equal/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def isItPossible(self, word1: str, word2: str) -> bool: @@ -90,6 +92,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean isItPossible(String word1, String word2) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go func isItPossible(word1 string, word2 string) bool { cnt1 := [26]int{} diff --git a/solution/2500-2599/2532.Time to Cross a Bridge/README.md b/solution/2500-2599/2532.Time to Cross a Bridge/README.md index a5acecf8939ae..485fdbc9b831f 100644 --- a/solution/2500-2599/2532.Time to Cross a Bridge/README.md +++ b/solution/2500-2599/2532.Time to Cross a Bridge/README.md @@ -128,6 +128,8 @@ tags: +#### Python3 + ```python class Solution: def findCrossingTime(self, n: int, k: int, time: List[List[int]]) -> int: @@ -173,6 +175,8 @@ class Solution: heappush(work_in_right, (cur + time[i][1], i)) ``` +#### Java + ```java class Solution { public int findCrossingTime(int n, int k, int[][] time) { @@ -239,6 +243,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -307,6 +313,8 @@ public: }; ``` +#### Go + ```go func findCrossingTime(n int, k int, time [][]int) int { sort.SliceStable(time, func(i, j int) bool { return time[i][0]+time[i][2] < time[j][0]+time[j][2] }) diff --git a/solution/2500-2599/2532.Time to Cross a Bridge/README_EN.md b/solution/2500-2599/2532.Time to Cross a Bridge/README_EN.md index 88d0e92889fd4..762ca45274e43 100644 --- a/solution/2500-2599/2532.Time to Cross a Bridge/README_EN.md +++ b/solution/2500-2599/2532.Time to Cross a Bridge/README_EN.md @@ -103,6 +103,8 @@ The whole process ends after 58 minutes. We return 50 because the problem asks f +#### Python3 + ```python class Solution: def findCrossingTime(self, n: int, k: int, time: List[List[int]]) -> int: @@ -148,6 +150,8 @@ class Solution: heappush(work_in_right, (cur + time[i][1], i)) ``` +#### Java + ```java class Solution { public int findCrossingTime(int n, int k, int[][] time) { @@ -214,6 +218,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -282,6 +288,8 @@ public: }; ``` +#### Go + ```go func findCrossingTime(n int, k int, time [][]int) int { sort.SliceStable(time, func(i, j int) bool { return time[i][0]+time[i][2] < time[j][0]+time[j][2] }) diff --git a/solution/2500-2599/2533.Number of Good Binary Strings/README.md b/solution/2500-2599/2533.Number of Good Binary Strings/README.md index e8daef0f6d85e..0d51d2a2ab9f3 100644 --- a/solution/2500-2599/2533.Number of Good Binary Strings/README.md +++ b/solution/2500-2599/2533.Number of Good Binary Strings/README.md @@ -89,6 +89,8 @@ $$ +#### Python3 + ```python class Solution: def goodBinaryStrings( @@ -105,6 +107,8 @@ class Solution: return sum(f[minLength:]) % mod ``` +#### Java + ```java class Solution { public int goodBinaryStrings(int minLength, int maxLength, int oneGroup, int zeroGroup) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func goodBinaryStrings(minLength int, maxLength int, oneGroup int, zeroGroup int) (ans int) { const mod int = 1e9 + 7 @@ -174,6 +182,8 @@ func goodBinaryStrings(minLength int, maxLength int, oneGroup int, zeroGroup int } ``` +#### TypeScript + ```ts function goodBinaryStrings( minLength: number, diff --git a/solution/2500-2599/2533.Number of Good Binary Strings/README_EN.md b/solution/2500-2599/2533.Number of Good Binary Strings/README_EN.md index 69dd3a96c9de8..772ab1cfdf024 100644 --- a/solution/2500-2599/2533.Number of Good Binary Strings/README_EN.md +++ b/solution/2500-2599/2533.Number of Good Binary Strings/README_EN.md @@ -88,6 +88,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n=maxL +#### Python3 + ```python class Solution: def goodBinaryStrings( @@ -104,6 +106,8 @@ class Solution: return sum(f[minLength:]) % mod ``` +#### Java + ```java class Solution { public int goodBinaryStrings(int minLength, int maxLength, int oneGroup, int zeroGroup) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func goodBinaryStrings(minLength int, maxLength int, oneGroup int, zeroGroup int) (ans int) { const mod int = 1e9 + 7 @@ -173,6 +181,8 @@ func goodBinaryStrings(minLength int, maxLength int, oneGroup int, zeroGroup int } ``` +#### TypeScript + ```ts function goodBinaryStrings( minLength: number, diff --git a/solution/2500-2599/2534.Time Taken to Cross the Door/README.md b/solution/2500-2599/2534.Time Taken to Cross the Door/README.md index 7905ca04ae4fa..a71d438dc295f 100644 --- a/solution/2500-2599/2534.Time Taken to Cross the Door/README.md +++ b/solution/2500-2599/2534.Time Taken to Cross the Door/README.md @@ -87,18 +87,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2500-2599/2534.Time Taken to Cross the Door/README_EN.md b/solution/2500-2599/2534.Time Taken to Cross the Door/README_EN.md index d7f5bf54a156e..c43f24d9e26e0 100644 --- a/solution/2500-2599/2534.Time Taken to Cross the Door/README_EN.md +++ b/solution/2500-2599/2534.Time Taken to Cross the Door/README_EN.md @@ -86,18 +86,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2500-2599/2535.Difference Between Element Sum and Digit Sum of an Array/README.md b/solution/2500-2599/2535.Difference Between Element Sum and Digit Sum of an Array/README.md index 0f6a97c8dfa7b..a76e3e1a1b8bb 100644 --- a/solution/2500-2599/2535.Difference Between Element Sum and Digit Sum of an Array/README.md +++ b/solution/2500-2599/2535.Difference Between Element Sum and Digit Sum of an Array/README.md @@ -77,6 +77,8 @@ nums 的数字和是 1 + 2 + 3 + 4 = 10 。 +#### Python3 + ```python class Solution: def differenceOfSum(self, nums: List[int]) -> int: @@ -88,6 +90,8 @@ class Solution: return abs(a - b) ``` +#### Java + ```java class Solution { public int differenceOfSum(int[] nums) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func differenceOfSum(nums []int) int { a, b := 0, 0 @@ -139,6 +147,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function differenceOfSum(nums: number[]): number { return nums.reduce((r, v) => { @@ -152,6 +162,8 @@ function differenceOfSum(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn difference_of_sum(nums: Vec) -> i32 { @@ -169,6 +181,8 @@ impl Solution { } ``` +#### C + ```c int differenceOfSum(int* nums, int numsSize) { int ans = 0; @@ -193,6 +207,8 @@ int differenceOfSum(int* nums, int numsSize) { +#### Rust + ```rust impl Solution { pub fn difference_of_sum(nums: Vec) -> i32 { diff --git a/solution/2500-2599/2535.Difference Between Element Sum and Digit Sum of an Array/README_EN.md b/solution/2500-2599/2535.Difference Between Element Sum and Digit Sum of an Array/README_EN.md index aab6f94481404..88550919a8897 100644 --- a/solution/2500-2599/2535.Difference Between Element Sum and Digit Sum of an Array/README_EN.md +++ b/solution/2500-2599/2535.Difference Between Element Sum and Digit Sum of an Array/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def differenceOfSum(self, nums: List[int]) -> int: @@ -86,6 +88,8 @@ class Solution: return abs(a - b) ``` +#### Java + ```java class Solution { public int differenceOfSum(int[] nums) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func differenceOfSum(nums []int) int { a, b := 0, 0 @@ -137,6 +145,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function differenceOfSum(nums: number[]): number { return nums.reduce((r, v) => { @@ -150,6 +160,8 @@ function differenceOfSum(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn difference_of_sum(nums: Vec) -> i32 { @@ -167,6 +179,8 @@ impl Solution { } ``` +#### C + ```c int differenceOfSum(int* nums, int numsSize) { int ans = 0; @@ -191,6 +205,8 @@ int differenceOfSum(int* nums, int numsSize) { +#### Rust + ```rust impl Solution { pub fn difference_of_sum(nums: Vec) -> i32 { diff --git a/solution/2500-2599/2536.Increment Submatrices by One/README.md b/solution/2500-2599/2536.Increment Submatrices by One/README.md index 8380be4d7c581..aa31270c1d7f9 100644 --- a/solution/2500-2599/2536.Increment Submatrices by One/README.md +++ b/solution/2500-2599/2536.Increment Submatrices by One/README.md @@ -95,6 +95,8 @@ for i in range(1, n + 1): +#### Python3 + ```python class Solution: def rangeAddQueries(self, n: int, queries: List[List[int]]) -> List[List[int]]: @@ -119,6 +121,8 @@ class Solution: return mat ``` +#### Java + ```java class Solution { public int[][] rangeAddQueries(int n, int[][] queries) { @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -190,6 +196,8 @@ public: }; ``` +#### Go + ```go func rangeAddQueries(n int, queries [][]int) [][]int { mat := make([][]int, n) diff --git a/solution/2500-2599/2536.Increment Submatrices by One/README_EN.md b/solution/2500-2599/2536.Increment Submatrices by One/README_EN.md index b0bd90eecee39..6e328c5fcd0a1 100644 --- a/solution/2500-2599/2536.Increment Submatrices by One/README_EN.md +++ b/solution/2500-2599/2536.Increment Submatrices by One/README_EN.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def rangeAddQueries(self, n: int, queries: List[List[int]]) -> List[List[int]]: @@ -94,6 +96,8 @@ class Solution: return mat ``` +#### Java + ```java class Solution { public int[][] rangeAddQueries(int n, int[][] queries) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func rangeAddQueries(n int, queries [][]int) [][]int { mat := make([][]int, n) diff --git a/solution/2500-2599/2537.Count the Number of Good Subarrays/README.md b/solution/2500-2599/2537.Count the Number of Good Subarrays/README.md index cbfdc7df0c539..b366f85a1bbd0 100644 --- a/solution/2500-2599/2537.Count the Number of Good Subarrays/README.md +++ b/solution/2500-2599/2537.Count the Number of Good Subarrays/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def countGood(self, nums: List[int], k: int) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long countGood(int[] nums, int k) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func countGood(nums []int, k int) int64 { cnt := map[int]int{} diff --git a/solution/2500-2599/2537.Count the Number of Good Subarrays/README_EN.md b/solution/2500-2599/2537.Count the Number of Good Subarrays/README_EN.md index 516bdf3d3a5f0..441d921c2108b 100644 --- a/solution/2500-2599/2537.Count the Number of Good Subarrays/README_EN.md +++ b/solution/2500-2599/2537.Count the Number of Good Subarrays/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python class Solution: def countGood(self, nums: List[int], k: int) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long countGood(int[] nums, int k) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func countGood(nums []int, k int) int64 { cnt := map[int]int{} diff --git a/solution/2500-2599/2538.Difference Between Maximum and Minimum Price Sum/README.md b/solution/2500-2599/2538.Difference Between Maximum and Minimum Price Sum/README.md index 95470c293f797..4f490c6e37ba1 100644 --- a/solution/2500-2599/2538.Difference Between Maximum and Minimum Price Sum/README.md +++ b/solution/2500-2599/2538.Difference Between Maximum and Minimum Price Sum/README.md @@ -101,6 +101,8 @@ tags: +#### Python3 + ```python class Solution: def maxOutput(self, n: int, edges: List[List[int]], price: List[int]) -> int: @@ -124,6 +126,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -159,6 +163,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -190,6 +196,8 @@ public: }; ``` +#### Go + ```go func maxOutput(n int, edges [][]int, price []int) int64 { g := make([][]int, n) diff --git a/solution/2500-2599/2538.Difference Between Maximum and Minimum Price Sum/README_EN.md b/solution/2500-2599/2538.Difference Between Maximum and Minimum Price Sum/README_EN.md index 02f368e4d2c15..059afdc7c8003 100644 --- a/solution/2500-2599/2538.Difference Between Maximum and Minimum Price Sum/README_EN.md +++ b/solution/2500-2599/2538.Difference Between Maximum and Minimum Price Sum/README_EN.md @@ -76,6 +76,8 @@ The difference between the maximum and minimum price sum is 2. It can be proved +#### Python3 + ```python class Solution: def maxOutput(self, n: int, edges: List[List[int]], price: List[int]) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func maxOutput(n int, edges [][]int, price []int) int64 { g := make([][]int, n) diff --git a/solution/2500-2599/2539.Count the Number of Good Subsequences/README.md b/solution/2500-2599/2539.Count the Number of Good Subsequences/README.md index 79907be3647db..e73c4affe439c 100644 --- a/solution/2500-2599/2539.Count the Number of Good Subsequences/README.md +++ b/solution/2500-2599/2539.Count the Number of Good Subsequences/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python N = 10001 MOD = 10**9 + 7 @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int N = 10001; @@ -158,6 +162,8 @@ class Solution { } ``` +#### C++ + ```cpp int N = 10001; int MOD = 1e9 + 7; @@ -213,6 +219,8 @@ public: }; ``` +#### Go + ```go const n = 1e4 + 1 const mod = 1e9 + 7 diff --git a/solution/2500-2599/2539.Count the Number of Good Subsequences/README_EN.md b/solution/2500-2599/2539.Count the Number of Good Subsequences/README_EN.md index 55c8ddde84c6f..b9f6618516452 100644 --- a/solution/2500-2599/2539.Count the Number of Good Subsequences/README_EN.md +++ b/solution/2500-2599/2539.Count the Number of Good Subsequences/README_EN.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python N = 10001 MOD = 10**9 + 7 @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int N = 10001; @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp int N = 10001; int MOD = 1e9 + 7; @@ -203,6 +209,8 @@ public: }; ``` +#### Go + ```go const n = 1e4 + 1 const mod = 1e9 + 7 diff --git a/solution/2500-2599/2540.Minimum Common Value/README.md b/solution/2500-2599/2540.Minimum Common Value/README.md index f730f16ecbffa..aef6f9b7f4fa7 100644 --- a/solution/2500-2599/2540.Minimum Common Value/README.md +++ b/solution/2500-2599/2540.Minimum Common Value/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def getCommon(self, nums1: List[int], nums2: List[int]) -> int: @@ -80,6 +82,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int getCommon(int[] nums1, int[] nums2) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func getCommon(nums1 []int, nums2 []int) int { m, n := len(nums1), len(nums2) @@ -136,6 +144,8 @@ func getCommon(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function getCommon(nums1: number[], nums2: number[]): number { const m = nums1.length; @@ -156,6 +166,8 @@ function getCommon(nums1: number[], nums2: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn get_common(nums1: Vec, nums2: Vec) -> i32 { @@ -178,6 +190,8 @@ impl Solution { } ``` +#### C + ```c int getCommon(int* nums1, int nums1Size, int* nums2, int nums2Size) { int i = 0; @@ -206,6 +220,8 @@ int getCommon(int* nums1, int nums1Size, int* nums2, int nums2Size) { +#### Rust + ```rust impl Solution { pub fn get_common(nums1: Vec, nums2: Vec) -> i32 { diff --git a/solution/2500-2599/2540.Minimum Common Value/README_EN.md b/solution/2500-2599/2540.Minimum Common Value/README_EN.md index 243cc1853243b..1cacd5d3c5179 100644 --- a/solution/2500-2599/2540.Minimum Common Value/README_EN.md +++ b/solution/2500-2599/2540.Minimum Common Value/README_EN.md @@ -65,6 +65,8 @@ The time complexity is $O(m + n)$, where $m$ and $n$ are the lengths of the two +#### Python3 + ```python class Solution: def getCommon(self, nums1: List[int], nums2: List[int]) -> int: @@ -80,6 +82,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int getCommon(int[] nums1, int[] nums2) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func getCommon(nums1 []int, nums2 []int) int { m, n := len(nums1), len(nums2) @@ -136,6 +144,8 @@ func getCommon(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function getCommon(nums1: number[], nums2: number[]): number { const m = nums1.length; @@ -156,6 +166,8 @@ function getCommon(nums1: number[], nums2: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn get_common(nums1: Vec, nums2: Vec) -> i32 { @@ -178,6 +190,8 @@ impl Solution { } ``` +#### C + ```c int getCommon(int* nums1, int nums1Size, int* nums2, int nums2Size) { int i = 0; @@ -206,6 +220,8 @@ int getCommon(int* nums1, int nums1Size, int* nums2, int nums2Size) { +#### Rust + ```rust impl Solution { pub fn get_common(nums1: Vec, nums2: Vec) -> i32 { diff --git a/solution/2500-2599/2541.Minimum Operations to Make Array Equal II/README.md b/solution/2500-2599/2541.Minimum Operations to Make Array Equal II/README.md index 3e4fb5b181aee..fa2a67b3613c8 100644 --- a/solution/2500-2599/2541.Minimum Operations to Make Array Equal II/README.md +++ b/solution/2500-2599/2541.Minimum Operations to Make Array Equal II/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def minOperations(self, nums1: List[int], nums2: List[int], k: int) -> int: @@ -94,6 +96,8 @@ class Solution: return -1 if x else ans // 2 ``` +#### Java + ```java class Solution { public long minOperations(int[] nums1, int[] nums2, int k) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums1 []int, nums2 []int, k int) int64 { ans, x := 0, 0 @@ -175,6 +183,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function minOperations(nums1: number[], nums2: number[], k: number): number { const n = nums1.length; @@ -198,6 +208,8 @@ function minOperations(nums1: number[], nums2: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_operations(nums1: Vec, nums2: Vec, k: i32) -> i64 { @@ -233,6 +245,8 @@ impl Solution { } ``` +#### C + ```c long long minOperations(int* nums1, int nums1Size, int* nums2, int nums2Size, int k) { if (k == 0) { diff --git a/solution/2500-2599/2541.Minimum Operations to Make Array Equal II/README_EN.md b/solution/2500-2599/2541.Minimum Operations to Make Array Equal II/README_EN.md index 9e858095db4b7..900814bb79525 100644 --- a/solution/2500-2599/2541.Minimum Operations to Make Array Equal II/README_EN.md +++ b/solution/2500-2599/2541.Minimum Operations to Make Array Equal II/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$, where $n$ is +#### Python3 + ```python class Solution: def minOperations(self, nums1: List[int], nums2: List[int], k: int) -> int: @@ -94,6 +96,8 @@ class Solution: return -1 if x else ans // 2 ``` +#### Java + ```java class Solution { public long minOperations(int[] nums1, int[] nums2, int k) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums1 []int, nums2 []int, k int) int64 { ans, x := 0, 0 @@ -175,6 +183,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function minOperations(nums1: number[], nums2: number[], k: number): number { const n = nums1.length; @@ -198,6 +208,8 @@ function minOperations(nums1: number[], nums2: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_operations(nums1: Vec, nums2: Vec, k: i32) -> i64 { @@ -233,6 +245,8 @@ impl Solution { } ``` +#### C + ```c long long minOperations(int* nums1, int nums1Size, int* nums2, int nums2Size, int k) { if (k == 0) { diff --git a/solution/2500-2599/2542.Maximum Subsequence Score/README.md b/solution/2500-2599/2542.Maximum Subsequence Score/README.md index fdc52eafabbeb..460793936ab25 100644 --- a/solution/2500-2599/2542.Maximum Subsequence Score/README.md +++ b/solution/2500-2599/2542.Maximum Subsequence Score/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def maxScore(self, nums1: List[int], nums2: List[int], k: int) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maxScore(int[] nums1, int[] nums2, int k) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func maxScore(nums1 []int, nums2 []int, k int) int64 { type pair struct{ a, b int } diff --git a/solution/2500-2599/2542.Maximum Subsequence Score/README_EN.md b/solution/2500-2599/2542.Maximum Subsequence Score/README_EN.md index 7596966ba0ae6..f0b951c1388c0 100644 --- a/solution/2500-2599/2542.Maximum Subsequence Score/README_EN.md +++ b/solution/2500-2599/2542.Maximum Subsequence Score/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def maxScore(self, nums1: List[int], nums2: List[int], k: int) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maxScore(int[] nums1, int[] nums2, int k) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func maxScore(nums1 []int, nums2 []int, k int) int64 { type pair struct{ a, b int } diff --git a/solution/2500-2599/2543.Check if Point Is Reachable/README.md b/solution/2500-2599/2543.Check if Point Is Reachable/README.md index 8959f47c463a9..926d180b44abf 100644 --- a/solution/2500-2599/2543.Check if Point Is Reachable/README.md +++ b/solution/2500-2599/2543.Check if Point Is Reachable/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def isReachable(self, targetX: int, targetY: int) -> bool: @@ -83,6 +85,8 @@ class Solution: return x & (x - 1) == 0 ``` +#### Java + ```java class Solution { public boolean isReachable(int targetX, int targetY) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func isReachable(targetX int, targetY int) bool { x := gcd(targetX, targetY) @@ -120,6 +128,8 @@ func gcd(a, b int) int { } ``` +#### TypeScript + ```ts function isReachable(targetX: number, targetY: number): boolean { const x = gcd(targetX, targetY); diff --git a/solution/2500-2599/2543.Check if Point Is Reachable/README_EN.md b/solution/2500-2599/2543.Check if Point Is Reachable/README_EN.md index 2f0e3411adb8b..5e88d12d00536 100644 --- a/solution/2500-2599/2543.Check if Point Is Reachable/README_EN.md +++ b/solution/2500-2599/2543.Check if Point Is Reachable/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(\log(\min(targetX, targetY)))$, and the space complexi +#### Python3 + ```python class Solution: def isReachable(self, targetX: int, targetY: int) -> bool: @@ -83,6 +85,8 @@ class Solution: return x & (x - 1) == 0 ``` +#### Java + ```java class Solution { public boolean isReachable(int targetX, int targetY) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func isReachable(targetX int, targetY int) bool { x := gcd(targetX, targetY) @@ -120,6 +128,8 @@ func gcd(a, b int) int { } ``` +#### TypeScript + ```ts function isReachable(targetX: number, targetY: number): boolean { const x = gcd(targetX, targetY); diff --git a/solution/2500-2599/2544.Alternating Digit Sum/README.md b/solution/2500-2599/2544.Alternating Digit Sum/README.md index 3e29d8d724be7..9dc2f787a3957 100644 --- a/solution/2500-2599/2544.Alternating Digit Sum/README.md +++ b/solution/2500-2599/2544.Alternating Digit Sum/README.md @@ -78,12 +78,16 @@ tags: +#### Python3 + ```python class Solution: def alternateDigitSum(self, n: int) -> int: return sum((-1) ** i * int(x) for i, x in enumerate(str(n))) ``` +#### Java + ```java class Solution { public int alternateDigitSum(int n) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func alternateDigitSum(n int) (ans int) { sign := 1 @@ -125,6 +133,8 @@ func alternateDigitSum(n int) (ans int) { } ``` +#### TypeScript + ```ts function alternateDigitSum(n: number): number { let ans = 0; @@ -138,6 +148,8 @@ function alternateDigitSum(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn alternate_digit_sum(mut n: i32) -> i32 { @@ -153,6 +165,8 @@ impl Solution { } ``` +#### C + ```c int alternateDigitSum(int n) { int ans = 0; @@ -176,6 +190,8 @@ int alternateDigitSum(int n) { +#### Python3 + ```python class Solution: def alternateDigitSum(self, n: int) -> int: @@ -187,6 +203,8 @@ class Solution: return ans ``` +#### Rust + ```rust impl Solution { pub fn alternate_digit_sum(n: i32) -> i32 { diff --git a/solution/2500-2599/2544.Alternating Digit Sum/README_EN.md b/solution/2500-2599/2544.Alternating Digit Sum/README_EN.md index 9013743a4bb20..ad57a62d3d464 100644 --- a/solution/2500-2599/2544.Alternating Digit Sum/README_EN.md +++ b/solution/2500-2599/2544.Alternating Digit Sum/README_EN.md @@ -84,12 +84,16 @@ The time complexity is $O(\log n)$, and the space complexity is $O(\log n)$. Her +#### Python3 + ```python class Solution: def alternateDigitSum(self, n: int) -> int: return sum((-1) ** i * int(x) for i, x in enumerate(str(n))) ``` +#### Java + ```java class Solution { public int alternateDigitSum(int n) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func alternateDigitSum(n int) (ans int) { sign := 1 @@ -131,6 +139,8 @@ func alternateDigitSum(n int) (ans int) { } ``` +#### TypeScript + ```ts function alternateDigitSum(n: number): number { let ans = 0; @@ -144,6 +154,8 @@ function alternateDigitSum(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn alternate_digit_sum(mut n: i32) -> i32 { @@ -159,6 +171,8 @@ impl Solution { } ``` +#### C + ```c int alternateDigitSum(int n) { int ans = 0; @@ -182,6 +196,8 @@ int alternateDigitSum(int n) { +#### Python3 + ```python class Solution: def alternateDigitSum(self, n: int) -> int: @@ -193,6 +209,8 @@ class Solution: return ans ``` +#### Rust + ```rust impl Solution { pub fn alternate_digit_sum(n: i32) -> i32 { diff --git a/solution/2500-2599/2545.Sort the Students by Their Kth Score/README.md b/solution/2500-2599/2545.Sort the Students by Their Kth Score/README.md index 66ca36c85c051..12f1854d530c0 100644 --- a/solution/2500-2599/2545.Sort the Students by Their Kth Score/README.md +++ b/solution/2500-2599/2545.Sort the Students by Their Kth Score/README.md @@ -80,12 +80,16 @@ tags: +#### Python3 + ```python class Solution: def sortTheStudents(self, score: List[List[int]], k: int) -> List[List[int]]: return sorted(score, key=lambda x: -x[k]) ``` +#### Java + ```java class Solution { public int[][] sortTheStudents(int[][] score, int k) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func sortTheStudents(score [][]int, k int) [][]int { sort.Slice(score, func(i, j int) bool { return score[i][k] > score[j][k] }) @@ -112,12 +120,16 @@ func sortTheStudents(score [][]int, k int) [][]int { } ``` +#### TypeScript + ```ts function sortTheStudents(score: number[][], k: number): number[][] { return score.sort((a, b) => b[k] - a[k]); } ``` +#### Rust + ```rust impl Solution { pub fn sort_the_students(mut score: Vec>, k: i32) -> Vec> { diff --git a/solution/2500-2599/2545.Sort the Students by Their Kth Score/README_EN.md b/solution/2500-2599/2545.Sort the Students by Their Kth Score/README_EN.md index 3eab47d4332ae..d484ec0bffcb9 100644 --- a/solution/2500-2599/2545.Sort the Students by Their Kth Score/README_EN.md +++ b/solution/2500-2599/2545.Sort the Students by Their Kth Score/README_EN.md @@ -74,12 +74,16 @@ The time complexity is $O(m \times \log m)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def sortTheStudents(self, score: List[List[int]], k: int) -> List[List[int]]: return sorted(score, key=lambda x: -x[k]) ``` +#### Java + ```java class Solution { public int[][] sortTheStudents(int[][] score, int k) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -99,6 +105,8 @@ public: }; ``` +#### Go + ```go func sortTheStudents(score [][]int, k int) [][]int { sort.Slice(score, func(i, j int) bool { return score[i][k] > score[j][k] }) @@ -106,12 +114,16 @@ func sortTheStudents(score [][]int, k int) [][]int { } ``` +#### TypeScript + ```ts function sortTheStudents(score: number[][], k: number): number[][] { return score.sort((a, b) => b[k] - a[k]); } ``` +#### Rust + ```rust impl Solution { pub fn sort_the_students(mut score: Vec>, k: i32) -> Vec> { diff --git a/solution/2500-2599/2546.Apply Bitwise Operations to Make Strings Equal/README.md b/solution/2500-2599/2546.Apply Bitwise Operations to Make Strings Equal/README.md index 15735083ed123..52dcc39b1c83f 100644 --- a/solution/2500-2599/2546.Apply Bitwise Operations to Make Strings Equal/README.md +++ b/solution/2500-2599/2546.Apply Bitwise Operations to Make Strings Equal/README.md @@ -73,12 +73,16 @@ tags: +#### Python3 + ```python class Solution: def makeStringsEqual(self, s: str, target: str) -> bool: return ("1" in s) == ("1" in target) ``` +#### Java + ```java class Solution { public boolean makeStringsEqual(String s, String target) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -98,18 +104,24 @@ public: }; ``` +#### Go + ```go func makeStringsEqual(s string, target string) bool { return strings.Contains(s, "1") == strings.Contains(target, "1") } ``` +#### TypeScript + ```ts function makeStringsEqual(s: string, target: string): boolean { return s.includes('1') === target.includes('1'); } ``` +#### Rust + ```rust impl Solution { pub fn make_strings_equal(s: String, target: String) -> bool { @@ -118,6 +130,8 @@ impl Solution { } ``` +#### C + ```c bool makeStringsEqual(char* s, char* target) { int count = 0; diff --git a/solution/2500-2599/2546.Apply Bitwise Operations to Make Strings Equal/README_EN.md b/solution/2500-2599/2546.Apply Bitwise Operations to Make Strings Equal/README_EN.md index 352ea57f652f6..21d186c8731fb 100644 --- a/solution/2500-2599/2546.Apply Bitwise Operations to Make Strings Equal/README_EN.md +++ b/solution/2500-2599/2546.Apply Bitwise Operations to Make Strings Equal/README_EN.md @@ -73,12 +73,16 @@ The time complexity is $O(n)$, where $n$ is the length of the string. The space +#### Python3 + ```python class Solution: def makeStringsEqual(self, s: str, target: str) -> bool: return ("1" in s) == ("1" in target) ``` +#### Java + ```java class Solution { public boolean makeStringsEqual(String s, String target) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -98,18 +104,24 @@ public: }; ``` +#### Go + ```go func makeStringsEqual(s string, target string) bool { return strings.Contains(s, "1") == strings.Contains(target, "1") } ``` +#### TypeScript + ```ts function makeStringsEqual(s: string, target: string): boolean { return s.includes('1') === target.includes('1'); } ``` +#### Rust + ```rust impl Solution { pub fn make_strings_equal(s: String, target: String) -> bool { @@ -118,6 +130,8 @@ impl Solution { } ``` +#### C + ```c bool makeStringsEqual(char* s, char* target) { int count = 0; diff --git a/solution/2500-2599/2547.Minimum Cost to Split an Array/README.md b/solution/2500-2599/2547.Minimum Cost to Split an Array/README.md index 159515c0d4e21..6ab030ae32cfc 100644 --- a/solution/2500-2599/2547.Minimum Cost to Split an Array/README.md +++ b/solution/2500-2599/2547.Minimum Cost to Split an Array/README.md @@ -108,6 +108,8 @@ tags: +#### Python3 + ```python class Solution: def minCost(self, nums: List[int], k: int) -> int: @@ -131,6 +133,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private Integer[] f; @@ -169,6 +173,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -203,6 +209,8 @@ public: }; ``` +#### Go + ```go func minCost(nums []int, k int) int { n := len(nums) @@ -234,6 +242,8 @@ func minCost(nums []int, k int) int { } ``` +#### TypeScript + ```ts function minCost(nums: number[], k: number): number { const n = nums.length; diff --git a/solution/2500-2599/2547.Minimum Cost to Split an Array/README_EN.md b/solution/2500-2599/2547.Minimum Cost to Split an Array/README_EN.md index 0d79bfb17228f..50a790082861c 100644 --- a/solution/2500-2599/2547.Minimum Cost to Split an Array/README_EN.md +++ b/solution/2500-2599/2547.Minimum Cost to Split an Array/README_EN.md @@ -112,6 +112,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$. Where $n$ i +#### Python3 + ```python class Solution: def minCost(self, nums: List[int], k: int) -> int: @@ -135,6 +137,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private Integer[] f; @@ -173,6 +177,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -207,6 +213,8 @@ public: }; ``` +#### Go + ```go func minCost(nums []int, k int) int { n := len(nums) @@ -238,6 +246,8 @@ func minCost(nums []int, k int) int { } ``` +#### TypeScript + ```ts function minCost(nums: number[], k: number): number { const n = nums.length; diff --git a/solution/2500-2599/2548.Maximum Price to Fill a Bag/README.md b/solution/2500-2599/2548.Maximum Price to Fill a Bag/README.md index 76653447ce87c..c0a0138ef3120 100644 --- a/solution/2500-2599/2548.Maximum Price to Fill a Bag/README.md +++ b/solution/2500-2599/2548.Maximum Price to Fill a Bag/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def maxPrice(self, items: List[List[int]], capacity: int) -> float: @@ -92,6 +94,8 @@ class Solution: return -1 if capacity else ans ``` +#### Java + ```java class Solution { public double maxPrice(int[][] items, int capacity) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func maxPrice(items [][]int, capacity int) (ans float64) { sort.Slice(items, func(i, j int) bool { return items[i][1]*items[j][0] < items[i][0]*items[j][1] }) @@ -141,6 +149,8 @@ func maxPrice(items [][]int, capacity int) (ans float64) { } ``` +#### TypeScript + ```ts function maxPrice(items: number[][], capacity: number): number { items.sort((a, b) => a[1] * b[0] - a[0] * b[1]); diff --git a/solution/2500-2599/2548.Maximum Price to Fill a Bag/README_EN.md b/solution/2500-2599/2548.Maximum Price to Fill a Bag/README_EN.md index 3c434cbe0f412..796ec08b9bb70 100644 --- a/solution/2500-2599/2548.Maximum Price to Fill a Bag/README_EN.md +++ b/solution/2500-2599/2548.Maximum Price to Fill a Bag/README_EN.md @@ -79,6 +79,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def maxPrice(self, items: List[List[int]], capacity: int) -> float: @@ -90,6 +92,8 @@ class Solution: return -1 if capacity else ans ``` +#### Java + ```java class Solution { public double maxPrice(int[][] items, int capacity) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func maxPrice(items [][]int, capacity int) (ans float64) { sort.Slice(items, func(i, j int) bool { return items[i][1]*items[j][0] < items[i][0]*items[j][1] }) @@ -139,6 +147,8 @@ func maxPrice(items [][]int, capacity int) (ans float64) { } ``` +#### TypeScript + ```ts function maxPrice(items: number[][], capacity: number): number { items.sort((a, b) => a[1] * b[0] - a[0] * b[1]); diff --git a/solution/2500-2599/2549.Count Distinct Numbers on Board/README.md b/solution/2500-2599/2549.Count Distinct Numbers on Board/README.md index 8d4b5f8f8556e..f987278683833 100644 --- a/solution/2500-2599/2549.Count Distinct Numbers on Board/README.md +++ b/solution/2500-2599/2549.Count Distinct Numbers on Board/README.md @@ -84,12 +84,16 @@ tags: +#### Python3 + ```python class Solution: def distinctIntegers(self, n: int) -> int: return max(1, n - 1) ``` +#### Java + ```java class Solution { public int distinctIntegers(int n) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,18 +113,24 @@ public: }; ``` +#### Go + ```go func distinctIntegers(n int) int { return max(1, n-1) } ``` +#### TypeScript + ```ts function distinctIntegers(n: number): number { return Math.max(1, n - 1); } ``` +#### Rust + ```rust impl Solution { pub fn distinct_integers(n: i32) -> i32 { diff --git a/solution/2500-2599/2549.Count Distinct Numbers on Board/README_EN.md b/solution/2500-2599/2549.Count Distinct Numbers on Board/README_EN.md index a0419ac5a3884..ad6522fed0444 100644 --- a/solution/2500-2599/2549.Count Distinct Numbers on Board/README_EN.md +++ b/solution/2500-2599/2549.Count Distinct Numbers on Board/README_EN.md @@ -82,12 +82,16 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def distinctIntegers(self, n: int) -> int: return max(1, n - 1) ``` +#### Java + ```java class Solution { public int distinctIntegers(int n) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,18 +111,24 @@ public: }; ``` +#### Go + ```go func distinctIntegers(n int) int { return max(1, n-1) } ``` +#### TypeScript + ```ts function distinctIntegers(n: number): number { return Math.max(1, n - 1); } ``` +#### Rust + ```rust impl Solution { pub fn distinct_integers(n: i32) -> i32 { diff --git a/solution/2500-2599/2550.Count Collisions of Monkeys on a Polygon/README.md b/solution/2500-2599/2550.Count Collisions of Monkeys on a Polygon/README.md index 62eed877e2fe5..fa777aa04b6ba 100644 --- a/solution/2500-2599/2550.Count Collisions of Monkeys on a Polygon/README.md +++ b/solution/2500-2599/2550.Count Collisions of Monkeys on a Polygon/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def monkeyMove(self, n: int) -> int: @@ -88,6 +90,8 @@ class Solution: return (pow(2, n, mod) - 2) % mod ``` +#### Java + ```java class Solution { public int monkeyMove(int n) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func monkeyMove(n int) int { const mod = 1e9 + 7 @@ -146,6 +154,8 @@ func monkeyMove(n int) int { } ``` +#### TypeScript + ```ts function monkeyMove(n: number): number { const mod = 10 ** 9 + 7; diff --git a/solution/2500-2599/2550.Count Collisions of Monkeys on a Polygon/README_EN.md b/solution/2500-2599/2550.Count Collisions of Monkeys on a Polygon/README_EN.md index 7fe632a0b329e..3d827837cf96b 100644 --- a/solution/2500-2599/2550.Count Collisions of Monkeys on a Polygon/README_EN.md +++ b/solution/2500-2599/2550.Count Collisions of Monkeys on a Polygon/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(\log n)$, where $n$ is the number of monkeys. The spac +#### Python3 + ```python class Solution: def monkeyMove(self, n: int) -> int: @@ -82,6 +84,8 @@ class Solution: return (pow(2, n, mod) - 2) % mod ``` +#### Java + ```java class Solution { public int monkeyMove(int n) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func monkeyMove(n int) int { const mod = 1e9 + 7 @@ -140,6 +148,8 @@ func monkeyMove(n int) int { } ``` +#### TypeScript + ```ts function monkeyMove(n: number): number { const mod = 10 ** 9 + 7; diff --git a/solution/2500-2599/2551.Put Marbles in Bags/README.md b/solution/2500-2599/2551.Put Marbles in Bags/README.md index bb896a6b97d2e..833b41ae161c4 100644 --- a/solution/2500-2599/2551.Put Marbles in Bags/README.md +++ b/solution/2500-2599/2551.Put Marbles in Bags/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def putMarbles(self, weights: List[int], k: int) -> int: @@ -87,6 +89,8 @@ class Solution: return sum(arr[len(arr) - k + 1 :]) - sum(arr[: k - 1]) ``` +#### Java + ```java class Solution { public long putMarbles(int[] weights, int k) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func putMarbles(weights []int, k int) (ans int64) { n := len(weights) @@ -141,6 +149,8 @@ func putMarbles(weights []int, k int) (ans int64) { } ``` +#### TypeScript + ```ts function putMarbles(weights: number[], k: number): number { const n = weights.length; diff --git a/solution/2500-2599/2551.Put Marbles in Bags/README_EN.md b/solution/2500-2599/2551.Put Marbles in Bags/README_EN.md index 3cb4b50f0ec23..b824ae1b9176f 100644 --- a/solution/2500-2599/2551.Put Marbles in Bags/README_EN.md +++ b/solution/2500-2599/2551.Put Marbles in Bags/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def putMarbles(self, weights: List[int], k: int) -> int: @@ -87,6 +89,8 @@ class Solution: return sum(arr[len(arr) - k + 1 :]) - sum(arr[: k - 1]) ``` +#### Java + ```java class Solution { public long putMarbles(int[] weights, int k) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func putMarbles(weights []int, k int) (ans int64) { n := len(weights) @@ -141,6 +149,8 @@ func putMarbles(weights []int, k int) (ans int64) { } ``` +#### TypeScript + ```ts function putMarbles(weights: number[], k: number): number { const n = weights.length; diff --git a/solution/2500-2599/2552.Count Increasing Quadruplets/README.md b/solution/2500-2599/2552.Count Increasing Quadruplets/README.md index f1e97e853eb2f..f980cf7078241 100644 --- a/solution/2500-2599/2552.Count Increasing Quadruplets/README.md +++ b/solution/2500-2599/2552.Count Increasing Quadruplets/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def countQuadruplets(self, nums: List[int]) -> int: @@ -106,6 +108,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public long countQuadruplets(int[] nums) { @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp const int N = 4001; int f[N][N]; @@ -197,6 +203,8 @@ public: }; ``` +#### Go + ```go func countQuadruplets(nums []int) int64 { n := len(nums) diff --git a/solution/2500-2599/2552.Count Increasing Quadruplets/README_EN.md b/solution/2500-2599/2552.Count Increasing Quadruplets/README_EN.md index df73501c171d9..263352cbc8751 100644 --- a/solution/2500-2599/2552.Count Increasing Quadruplets/README_EN.md +++ b/solution/2500-2599/2552.Count Increasing Quadruplets/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$. Where $n$ +#### Python3 + ```python class Solution: def countQuadruplets(self, nums: List[int]) -> int: @@ -106,6 +108,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public long countQuadruplets(int[] nums) { @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp const int N = 4001; int f[N][N]; @@ -197,6 +203,8 @@ public: }; ``` +#### Go + ```go func countQuadruplets(nums []int) int64 { n := len(nums) diff --git a/solution/2500-2599/2553.Separate the Digits in an Array/README.md b/solution/2500-2599/2553.Separate the Digits in an Array/README.md index e76d4033461c4..1a3325ad18bfc 100644 --- a/solution/2500-2599/2553.Separate the Digits in an Array/README.md +++ b/solution/2500-2599/2553.Separate the Digits in an Array/README.md @@ -72,6 +72,8 @@ answer = [7,1,3,9] 。 +#### Python3 + ```python class Solution: def separateDigits(self, nums: List[int]) -> List[int]: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] separateDigits(int[] nums) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func separateDigits(nums []int) (ans []int) { for _, x := range nums { @@ -142,6 +150,8 @@ func separateDigits(nums []int) (ans []int) { } ``` +#### TypeScript + ```ts function separateDigits(nums: number[]): number[] { const ans: number[] = []; @@ -157,6 +167,8 @@ function separateDigits(nums: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn separate_digits(nums: Vec) -> Vec { @@ -177,6 +189,8 @@ impl Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). @@ -213,6 +227,8 @@ int* separateDigits(int* nums, int numsSize, int* returnSize) { +#### Rust + ```rust impl Solution { pub fn separate_digits(nums: Vec) -> Vec { diff --git a/solution/2500-2599/2553.Separate the Digits in an Array/README_EN.md b/solution/2500-2599/2553.Separate the Digits in an Array/README_EN.md index 7a41a36594f66..2c4745fb73046 100644 --- a/solution/2500-2599/2553.Separate the Digits in an Array/README_EN.md +++ b/solution/2500-2599/2553.Separate the Digits in an Array/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(n \times \log_{10} M)$, and the space complexity is $O +#### Python3 + ```python class Solution: def separateDigits(self, nums: List[int]) -> List[int]: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] separateDigits(int[] nums) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func separateDigits(nums []int) (ans []int) { for _, x := range nums { @@ -142,6 +150,8 @@ func separateDigits(nums []int) (ans []int) { } ``` +#### TypeScript + ```ts function separateDigits(nums: number[]): number[] { const ans: number[] = []; @@ -157,6 +167,8 @@ function separateDigits(nums: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn separate_digits(nums: Vec) -> Vec { @@ -177,6 +189,8 @@ impl Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). @@ -213,6 +227,8 @@ int* separateDigits(int* nums, int numsSize, int* returnSize) { +#### Rust + ```rust impl Solution { pub fn separate_digits(nums: Vec) -> Vec { diff --git a/solution/2500-2599/2554.Maximum Number of Integers to Choose From a Range I/README.md b/solution/2500-2599/2554.Maximum Number of Integers to Choose From a Range I/README.md index 42f55c22a8ac5..b1d8fa8bbaead 100644 --- a/solution/2500-2599/2554.Maximum Number of Integers to Choose From a Range I/README.md +++ b/solution/2500-2599/2554.Maximum Number of Integers to Choose From a Range I/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def maxCount(self, banned: List[int], n: int, maxSum: int) -> int: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxCount(int[] banned, int n, int maxSum) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func maxCount(banned []int, n int, maxSum int) (ans int) { ban := map[int]bool{} @@ -153,6 +161,8 @@ func maxCount(banned []int, n int, maxSum int) (ans int) { } ``` +#### TypeScript + ```ts function maxCount(banned: number[], n: number, maxSum: number): number { const set = new Set(banned); @@ -172,6 +182,8 @@ function maxCount(banned: number[], n: number, maxSum: number): number { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -194,6 +206,8 @@ impl Solution { } ``` +#### C + ```c int cmp(const void* a, const void* b) { return *(int*) a - *(int*) b; @@ -242,6 +256,8 @@ int maxCount(int* banned, int bannedSize, int n, int maxSum) { +#### Python3 + ```python class Solution: def maxCount(self, banned: List[int], n: int, maxSum: int) -> int: @@ -263,6 +279,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxCount(int[] banned, int n, int maxSum) { @@ -299,6 +317,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -331,6 +351,8 @@ public: }; ``` +#### Go + ```go func maxCount(banned []int, n int, maxSum int) (ans int) { banned = append(banned, []int{0, n + 1}...) diff --git a/solution/2500-2599/2554.Maximum Number of Integers to Choose From a Range I/README_EN.md b/solution/2500-2599/2554.Maximum Number of Integers to Choose From a Range I/README_EN.md index 7ee1aebf1f119..fca455b31b8c0 100644 --- a/solution/2500-2599/2554.Maximum Number of Integers to Choose From a Range I/README_EN.md +++ b/solution/2500-2599/2554.Maximum Number of Integers to Choose From a Range I/README_EN.md @@ -87,6 +87,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def maxCount(self, banned: List[int], n: int, maxSum: int) -> int: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxCount(int[] banned, int n, int maxSum) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func maxCount(banned []int, n int, maxSum int) (ans int) { ban := map[int]bool{} @@ -154,6 +162,8 @@ func maxCount(banned []int, n int, maxSum int) (ans int) { } ``` +#### TypeScript + ```ts function maxCount(banned: number[], n: number, maxSum: number): number { const set = new Set(banned); @@ -173,6 +183,8 @@ function maxCount(banned: number[], n: number, maxSum: number): number { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -195,6 +207,8 @@ impl Solution { } ``` +#### C + ```c int cmp(const void* a, const void* b) { return *(int*) a - *(int*) b; @@ -243,6 +257,8 @@ Similar problems: +#### Python3 + ```python class Solution: def maxCount(self, banned: List[int], n: int, maxSum: int) -> int: @@ -264,6 +280,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxCount(int[] banned, int n, int maxSum) { @@ -300,6 +318,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -332,6 +352,8 @@ public: }; ``` +#### Go + ```go func maxCount(banned []int, n int, maxSum int) (ans int) { banned = append(banned, []int{0, n + 1}...) diff --git a/solution/2500-2599/2555.Maximize Win From Two Segments/README.md b/solution/2500-2599/2555.Maximize Win From Two Segments/README.md index 47bc570425a3d..ad66cbe0091c2 100644 --- a/solution/2500-2599/2555.Maximize Win From Two Segments/README.md +++ b/solution/2500-2599/2555.Maximize Win From Two Segments/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def maximizeWin(self, prizePositions: List[int], k: int) -> int: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximizeWin(int[] prizePositions, int k) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func maximizeWin(prizePositions []int, k int) (ans int) { n := len(prizePositions) @@ -151,6 +159,8 @@ func maximizeWin(prizePositions []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function maximizeWin(prizePositions: number[], k: number): number { const n = prizePositions.length; diff --git a/solution/2500-2599/2555.Maximize Win From Two Segments/README_EN.md b/solution/2500-2599/2555.Maximize Win From Two Segments/README_EN.md index 71c1ccbb37315..baa05bbc93260 100644 --- a/solution/2500-2599/2555.Maximize Win From Two Segments/README_EN.md +++ b/solution/2500-2599/2555.Maximize Win From Two Segments/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def maximizeWin(self, prizePositions: List[int], k: int) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximizeWin(int[] prizePositions, int k) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func maximizeWin(prizePositions []int, k int) (ans int) { n := len(prizePositions) @@ -158,6 +166,8 @@ func maximizeWin(prizePositions []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function maximizeWin(prizePositions: number[], k: number): number { const n = prizePositions.length; diff --git a/solution/2500-2599/2556.Disconnect Path in a Binary Matrix by at Most One Flip/README.md b/solution/2500-2599/2556.Disconnect Path in a Binary Matrix by at Most One Flip/README.md index 90aa454d35979..9869291284f24 100644 --- a/solution/2500-2599/2556.Disconnect Path in a Binary Matrix by at Most One Flip/README.md +++ b/solution/2500-2599/2556.Disconnect Path in a Binary Matrix by at Most One Flip/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def isPossibleToCutPath(self, grid: List[List[int]]) -> bool: @@ -100,6 +102,8 @@ class Solution: return not (a and b) ``` +#### Java + ```java class Solution { private int[][] grid; @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func isPossibleToCutPath(grid [][]int) bool { m, n := len(grid), len(grid[0]) @@ -174,6 +182,8 @@ func isPossibleToCutPath(grid [][]int) bool { } ``` +#### TypeScript + ```ts function isPossibleToCutPath(grid: number[][]): boolean { const m = grid.length; diff --git a/solution/2500-2599/2556.Disconnect Path in a Binary Matrix by at Most One Flip/README_EN.md b/solution/2500-2599/2556.Disconnect Path in a Binary Matrix by at Most One Flip/README_EN.md index cf5a98536ecc5..9d451f8d4538c 100644 --- a/solution/2500-2599/2556.Disconnect Path in a Binary Matrix by at Most One Flip/README_EN.md +++ b/solution/2500-2599/2556.Disconnect Path in a Binary Matrix by at Most One Flip/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def isPossibleToCutPath(self, grid: List[List[int]]) -> bool: @@ -95,6 +97,8 @@ class Solution: return not (a and b) ``` +#### Java + ```java class Solution { private int[][] grid; @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func isPossibleToCutPath(grid [][]int) bool { m, n := len(grid), len(grid[0]) @@ -169,6 +177,8 @@ func isPossibleToCutPath(grid [][]int) bool { } ``` +#### TypeScript + ```ts function isPossibleToCutPath(grid: number[][]): boolean { const m = grid.length; diff --git a/solution/2500-2599/2557.Maximum Number of Integers to Choose From a Range II/README.md b/solution/2500-2599/2557.Maximum Number of Integers to Choose From a Range II/README.md index c62b4d2ffcb52..ec37bbea957a2 100644 --- a/solution/2500-2599/2557.Maximum Number of Integers to Choose From a Range II/README.md +++ b/solution/2500-2599/2557.Maximum Number of Integers to Choose From a Range II/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def maxCount(self, banned: List[int], n: int, maxSum: int) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxCount(int[] banned, int n, long maxSum) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func maxCount(banned []int, n int, maxSum int64) (ans int) { banned = append(banned, []int{0, n + 1}...) diff --git a/solution/2500-2599/2557.Maximum Number of Integers to Choose From a Range II/README_EN.md b/solution/2500-2599/2557.Maximum Number of Integers to Choose From a Range II/README_EN.md index b7843cbc161b2..3c897b5dcff99 100644 --- a/solution/2500-2599/2557.Maximum Number of Integers to Choose From a Range II/README_EN.md +++ b/solution/2500-2599/2557.Maximum Number of Integers to Choose From a Range II/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def maxCount(self, banned: List[int], n: int, maxSum: int) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxCount(int[] banned, int n, long maxSum) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func maxCount(banned []int, n int, maxSum int64) (ans int) { banned = append(banned, []int{0, n + 1}...) diff --git a/solution/2500-2599/2558.Take Gifts From the Richest Pile/README.md b/solution/2500-2599/2558.Take Gifts From the Richest Pile/README.md index 322afb7dbcf75..adfaa8beb8a86 100644 --- a/solution/2500-2599/2558.Take Gifts From the Richest Pile/README.md +++ b/solution/2500-2599/2558.Take Gifts From the Richest Pile/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def pickGifts(self, gifts: List[int], k: int) -> int: @@ -93,6 +95,8 @@ class Solution: return -sum(h) ``` +#### Java + ```java class Solution { public long pickGifts(int[] gifts, int k) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func pickGifts(gifts []int, k int) (ans int64) { h := &hp{gifts} @@ -148,6 +156,8 @@ func (hp) Pop() (_ any) { return } func (hp) Push(any) {} ``` +#### TypeScript + ```ts function pickGifts(gifts: number[], k: number): number { const pq = new MaxPriorityQueue(); @@ -165,6 +175,8 @@ function pickGifts(gifts: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn pick_gifts(gifts: Vec, k: i32) -> i64 { diff --git a/solution/2500-2599/2558.Take Gifts From the Richest Pile/README_EN.md b/solution/2500-2599/2558.Take Gifts From the Richest Pile/README_EN.md index 87d0dcd0c88c6..85fb5b4506dfb 100644 --- a/solution/2500-2599/2558.Take Gifts From the Richest Pile/README_EN.md +++ b/solution/2500-2599/2558.Take Gifts From the Richest Pile/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(n + k \times \log n)$, and the space complexity is $O( +#### Python3 + ```python class Solution: def pickGifts(self, gifts: List[int], k: int) -> int: @@ -91,6 +93,8 @@ class Solution: return -sum(h) ``` +#### Java + ```java class Solution { public long pickGifts(int[] gifts, int k) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func pickGifts(gifts []int, k int) (ans int64) { h := &hp{gifts} @@ -146,6 +154,8 @@ func (hp) Pop() (_ any) { return } func (hp) Push(any) {} ``` +#### TypeScript + ```ts function pickGifts(gifts: number[], k: number): number { const pq = new MaxPriorityQueue(); @@ -163,6 +173,8 @@ function pickGifts(gifts: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn pick_gifts(gifts: Vec, k: i32) -> i64 { diff --git a/solution/2500-2599/2559.Count Vowel Strings in Ranges/README.md b/solution/2500-2599/2559.Count Vowel Strings in Ranges/README.md index 5fdb314aa9040..b76611b1ba688 100644 --- a/solution/2500-2599/2559.Count Vowel Strings in Ranges/README.md +++ b/solution/2500-2599/2559.Count Vowel Strings in Ranges/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]: @@ -86,6 +88,8 @@ class Solution: return [bisect_right(nums, r) - bisect_left(nums, l) for l, r in queries] ``` +#### Java + ```java class Solution { private List nums = new ArrayList<>(); @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func vowelStrings(words []string, queries [][]int) []int { vowels := map[byte]bool{'a': true, 'e': true, 'i': true, 'o': true, 'u': true} @@ -163,6 +171,8 @@ func vowelStrings(words []string, queries [][]int) []int { } ``` +#### TypeScript + ```ts function vowelStrings(words: string[], queries: number[][]): number[] { const vowels = new Set(['a', 'e', 'i', 'o', 'u']); @@ -207,6 +217,8 @@ function vowelStrings(words: string[], queries: number[][]): number[] { +#### Python3 + ```python class Solution: def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]: @@ -219,6 +231,8 @@ class Solution: return [s[r + 1] - s[l] for l, r in queries] ``` +#### Java + ```java class Solution { public int[] vowelStrings(String[] words, int[][] queries) { @@ -240,6 +254,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -262,6 +278,8 @@ public: }; ``` +#### Go + ```go func vowelStrings(words []string, queries [][]int) []int { vowels := map[byte]bool{'a': true, 'e': true, 'i': true, 'o': true, 'u': true} @@ -283,6 +301,8 @@ func vowelStrings(words []string, queries [][]int) []int { } ``` +#### TypeScript + ```ts function vowelStrings(words: string[], queries: number[][]): number[] { const vowels = new Set(['a', 'e', 'i', 'o', 'u']); diff --git a/solution/2500-2599/2559.Count Vowel Strings in Ranges/README_EN.md b/solution/2500-2599/2559.Count Vowel Strings in Ranges/README_EN.md index c4e63d1a9f52e..1645999adeb40 100644 --- a/solution/2500-2599/2559.Count Vowel Strings in Ranges/README_EN.md +++ b/solution/2500-2599/2559.Count Vowel Strings in Ranges/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(n + m \times \log n)$, and the space complexity is $O( +#### Python3 + ```python class Solution: def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]: @@ -84,6 +86,8 @@ class Solution: return [bisect_right(nums, r) - bisect_left(nums, l) for l, r in queries] ``` +#### Java + ```java class Solution { private List nums = new ArrayList<>(); @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func vowelStrings(words []string, queries [][]int) []int { vowels := map[byte]bool{'a': true, 'e': true, 'i': true, 'o': true, 'u': true} @@ -161,6 +169,8 @@ func vowelStrings(words []string, queries [][]int) []int { } ``` +#### TypeScript + ```ts function vowelStrings(words: string[], queries: number[][]): number[] { const vowels = new Set(['a', 'e', 'i', 'o', 'u']); @@ -205,6 +215,8 @@ The time complexity is $O(n + m)$, and the space complexity is $O(n)$. Where $n$ +#### Python3 + ```python class Solution: def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]: @@ -217,6 +229,8 @@ class Solution: return [s[r + 1] - s[l] for l, r in queries] ``` +#### Java + ```java class Solution { public int[] vowelStrings(String[] words, int[][] queries) { @@ -238,6 +252,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -260,6 +276,8 @@ public: }; ``` +#### Go + ```go func vowelStrings(words []string, queries [][]int) []int { vowels := map[byte]bool{'a': true, 'e': true, 'i': true, 'o': true, 'u': true} @@ -281,6 +299,8 @@ func vowelStrings(words []string, queries [][]int) []int { } ``` +#### TypeScript + ```ts function vowelStrings(words: string[], queries: number[][]): number[] { const vowels = new Set(['a', 'e', 'i', 'o', 'u']); diff --git a/solution/2500-2599/2560.House Robber IV/README.md b/solution/2500-2599/2560.House Robber IV/README.md index 95824e72aba6b..671bb2240c71b 100644 --- a/solution/2500-2599/2560.House Robber IV/README.md +++ b/solution/2500-2599/2560.House Robber IV/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def minCapability(self, nums: List[int], k: int) -> int: @@ -93,6 +95,8 @@ class Solution: return bisect_left(range(max(nums) + 1), True, key=f) ``` +#### Java + ```java class Solution { public int minCapability(int[] nums, int k) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func minCapability(nums []int, k int) int { return sort.Search(1e9+1, func(x int) bool { @@ -167,6 +175,8 @@ func minCapability(nums []int, k int) int { } ``` +#### TypeScript + ```ts function minCapability(nums: number[], k: number): number { const f = (mx: number): boolean => { diff --git a/solution/2500-2599/2560.House Robber IV/README_EN.md b/solution/2500-2599/2560.House Robber IV/README_EN.md index 8ff750849898b..f0583ad2d5ccc 100644 --- a/solution/2500-2599/2560.House Robber IV/README_EN.md +++ b/solution/2500-2599/2560.House Robber IV/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(n \times \log m)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def minCapability(self, nums: List[int], k: int) -> int: @@ -89,6 +91,8 @@ class Solution: return bisect_left(range(max(nums) + 1), True, key=f) ``` +#### Java + ```java class Solution { public int minCapability(int[] nums, int k) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func minCapability(nums []int, k int) int { return sort.Search(1e9+1, func(x int) bool { @@ -163,6 +171,8 @@ func minCapability(nums []int, k int) int { } ``` +#### TypeScript + ```ts function minCapability(nums: number[], k: number): number { const f = (mx: number): boolean => { diff --git a/solution/2500-2599/2561.Rearranging Fruits/README.md b/solution/2500-2599/2561.Rearranging Fruits/README.md index 240cd01ca0282..29055569cca7d 100644 --- a/solution/2500-2599/2561.Rearranging Fruits/README.md +++ b/solution/2500-2599/2561.Rearranging Fruits/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def minCost(self, basket1: List[int], basket2: List[int]) -> int: @@ -99,6 +101,8 @@ class Solution: return sum(min(x, mi * 2) for x in nums[:m]) ``` +#### Java + ```java class Solution { public long minCost(int[] basket1, int[] basket2) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func minCost(basket1 []int, basket2 []int) (ans int64) { cnt := map[int]int{} diff --git a/solution/2500-2599/2561.Rearranging Fruits/README_EN.md b/solution/2500-2599/2561.Rearranging Fruits/README_EN.md index ea1e98df532ed..867d00f7d626d 100644 --- a/solution/2500-2599/2561.Rearranging Fruits/README_EN.md +++ b/solution/2500-2599/2561.Rearranging Fruits/README_EN.md @@ -79,6 +79,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def minCost(self, basket1: List[int], basket2: List[int]) -> int: @@ -97,6 +99,8 @@ class Solution: return sum(min(x, mi * 2) for x in nums[:m]) ``` +#### Java + ```java class Solution { public long minCost(int[] basket1, int[] basket2) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func minCost(basket1 []int, basket2 []int) (ans int64) { cnt := map[int]int{} diff --git a/solution/2500-2599/2562.Find the Array Concatenation Value/README.md b/solution/2500-2599/2562.Find the Array Concatenation Value/README.md index a01653266a36e..5de202fae172a 100644 --- a/solution/2500-2599/2562.Find the Array Concatenation Value/README.md +++ b/solution/2500-2599/2562.Find the Array Concatenation Value/README.md @@ -99,6 +99,8 @@ nums 只有一个元素,所以我们选中 13 并将其加到串联值上, +#### Python3 + ```python class Solution: def findTheArrayConcVal(self, nums: List[int]) -> int: @@ -112,6 +114,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long findTheArrayConcVal(int[] nums) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func findTheArrayConcVal(nums []int) (ans int64) { i, j := 0, len(nums)-1 @@ -159,6 +167,8 @@ func findTheArrayConcVal(nums []int) (ans int64) { } ``` +#### TypeScript + ```ts function findTheArrayConcVal(nums: number[]): number { const n = nums.length; @@ -177,6 +187,8 @@ function findTheArrayConcVal(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_the_array_conc_val(nums: Vec) -> i64 { @@ -197,6 +209,8 @@ impl Solution { } ``` +#### C + ```c int getLen(int num) { int res = 0; @@ -233,6 +247,8 @@ long long findTheArrayConcVal(int* nums, int numsSize) { +#### Rust + ```rust impl Solution { pub fn find_the_array_conc_val(nums: Vec) -> i64 { diff --git a/solution/2500-2599/2562.Find the Array Concatenation Value/README_EN.md b/solution/2500-2599/2562.Find the Array Concatenation Value/README_EN.md index 5482ec2873bbe..2eeeadbf4b7d6 100644 --- a/solution/2500-2599/2562.Find the Array Concatenation Value/README_EN.md +++ b/solution/2500-2599/2562.Find the Array Concatenation Value/README_EN.md @@ -106,6 +106,8 @@ The time complexity is $O(n \times \log M)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def findTheArrayConcVal(self, nums: List[int]) -> int: @@ -119,6 +121,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long findTheArrayConcVal(int[] nums) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func findTheArrayConcVal(nums []int) (ans int64) { i, j := 0, len(nums)-1 @@ -166,6 +174,8 @@ func findTheArrayConcVal(nums []int) (ans int64) { } ``` +#### TypeScript + ```ts function findTheArrayConcVal(nums: number[]): number { const n = nums.length; @@ -184,6 +194,8 @@ function findTheArrayConcVal(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_the_array_conc_val(nums: Vec) -> i64 { @@ -204,6 +216,8 @@ impl Solution { } ``` +#### C + ```c int getLen(int num) { int res = 0; @@ -240,6 +254,8 @@ long long findTheArrayConcVal(int* nums, int numsSize) { +#### Rust + ```rust impl Solution { pub fn find_the_array_conc_val(nums: Vec) -> i64 { diff --git a/solution/2500-2599/2563.Count the Number of Fair Pairs/README.md b/solution/2500-2599/2563.Count the Number of Fair Pairs/README.md index 8963d0069c98f..11f77d08cd569 100644 --- a/solution/2500-2599/2563.Count the Number of Fair Pairs/README.md +++ b/solution/2500-2599/2563.Count the Number of Fair Pairs/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def countFairPairs(self, nums: List[int], lower: int, upper: int) -> int: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long countFairPairs(int[] nums, int lower, int upper) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func countFairPairs(nums []int, lower int, upper int) (ans int64) { sort.Ints(nums) @@ -142,6 +150,8 @@ func countFairPairs(nums []int, lower int, upper int) (ans int64) { } ``` +#### TypeScript + ```ts function countFairPairs(nums: number[], lower: number, upper: number): number { const search = (x: number, l: number): number => { diff --git a/solution/2500-2599/2563.Count the Number of Fair Pairs/README_EN.md b/solution/2500-2599/2563.Count the Number of Fair Pairs/README_EN.md index d7563294a4a1d..46b87cdcd053c 100644 --- a/solution/2500-2599/2563.Count the Number of Fair Pairs/README_EN.md +++ b/solution/2500-2599/2563.Count the Number of Fair Pairs/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def countFairPairs(self, nums: List[int], lower: int, upper: int) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long countFairPairs(int[] nums, int lower, int upper) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func countFairPairs(nums []int, lower int, upper int) (ans int64) { sort.Ints(nums) @@ -140,6 +148,8 @@ func countFairPairs(nums []int, lower int, upper int) (ans int64) { } ``` +#### TypeScript + ```ts function countFairPairs(nums: number[], lower: number, upper: number): number { const search = (x: number, l: number): number => { diff --git a/solution/2500-2599/2564.Substring XOR Queries/README.md b/solution/2500-2599/2564.Substring XOR Queries/README.md index 489ef1fc71eed..1ebdd63703eb8 100644 --- a/solution/2500-2599/2564.Substring XOR Queries/README.md +++ b/solution/2500-2599/2564.Substring XOR Queries/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def substringXorQueries(self, s: str, queries: List[List[int]]) -> List[List[int]]: @@ -104,6 +106,8 @@ class Solution: return [d.get(first ^ second, [-1, -1]) for first, second in queries] ``` +#### Java + ```java class Solution { public int[][] substringXorQueries(String s, int[][] queries) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func substringXorQueries(s string, queries [][]int) (ans [][]int) { d := map[int][]int{} diff --git a/solution/2500-2599/2564.Substring XOR Queries/README_EN.md b/solution/2500-2599/2564.Substring XOR Queries/README_EN.md index 9eb658e8eba9c..ae95a9b575861 100644 --- a/solution/2500-2599/2564.Substring XOR Queries/README_EN.md +++ b/solution/2500-2599/2564.Substring XOR Queries/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(n \times \log M + m)$, and the space complexity is $O( +#### Python3 + ```python class Solution: def substringXorQueries(self, s: str, queries: List[List[int]]) -> List[List[int]]: @@ -101,6 +103,8 @@ class Solution: return [d.get(first ^ second, [-1, -1]) for first, second in queries] ``` +#### Java + ```java class Solution { public int[][] substringXorQueries(String s, int[][] queries) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func substringXorQueries(s string, queries [][]int) (ans [][]int) { d := map[int][]int{} diff --git a/solution/2500-2599/2565.Subsequence With the Minimum Score/README.md b/solution/2500-2599/2565.Subsequence With the Minimum Score/README.md index 82ab6acdc4e4c..6a4af57324606 100644 --- a/solution/2500-2599/2565.Subsequence With the Minimum Score/README.md +++ b/solution/2500-2599/2565.Subsequence With the Minimum Score/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def minimumScore(self, s: str, t: str) -> int: @@ -119,6 +121,8 @@ class Solution: return bisect_left(range(n + 1), True, key=check) ``` +#### Java + ```java class Solution { private int m; @@ -173,6 +177,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -219,6 +225,8 @@ public: }; ``` +#### Go + ```go func minimumScore(s string, t string) int { m, n := len(s), len(t) diff --git a/solution/2500-2599/2565.Subsequence With the Minimum Score/README_EN.md b/solution/2500-2599/2565.Subsequence With the Minimum Score/README_EN.md index 10a4ab622765b..324a041c46fac 100644 --- a/solution/2500-2599/2565.Subsequence With the Minimum Score/README_EN.md +++ b/solution/2500-2599/2565.Subsequence With the Minimum Score/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def minimumScore(self, s: str, t: str) -> int: @@ -115,6 +117,8 @@ class Solution: return bisect_left(range(n + 1), True, key=check) ``` +#### Java + ```java class Solution { private int m; @@ -169,6 +173,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -215,6 +221,8 @@ public: }; ``` +#### Go + ```go func minimumScore(s string, t string) int { m, n := len(s), len(t) diff --git a/solution/2500-2599/2566.Maximum Difference by Remapping a Digit/README.md b/solution/2500-2599/2566.Maximum Difference by Remapping a Digit/README.md index 2a61bea1dc896..5b405487fe0ba 100644 --- a/solution/2500-2599/2566.Maximum Difference by Remapping a Digit/README.md +++ b/solution/2500-2599/2566.Maximum Difference by Remapping a Digit/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def minMaxDifference(self, num: int) -> int: @@ -94,6 +96,8 @@ class Solution: return num - mi ``` +#### Java + ```java class Solution { public int minMaxDifference(int num) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func minMaxDifference(num int) int { s := []byte(strconv.Itoa(num)) @@ -165,6 +173,8 @@ func minMaxDifference(num int) int { } ``` +#### TypeScript + ```ts function minMaxDifference(num: number): number { const s = num + ''; @@ -178,6 +188,8 @@ function minMaxDifference(num: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_max_difference(num: i32) -> i32 { @@ -193,6 +205,8 @@ impl Solution { } ``` +#### C + ```c int getLen(int num) { int res = 0; @@ -242,6 +256,8 @@ int minMaxDifference(int num) { +#### Rust + ```rust impl Solution { pub fn min_max_difference(num: i32) -> i32 { diff --git a/solution/2500-2599/2566.Maximum Difference by Remapping a Digit/README_EN.md b/solution/2500-2599/2566.Maximum Difference by Remapping a Digit/README_EN.md index d42ccc14d4673..22180b56081c1 100644 --- a/solution/2500-2599/2566.Maximum Difference by Remapping a Digit/README_EN.md +++ b/solution/2500-2599/2566.Maximum Difference by Remapping a Digit/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(\log n)$, and the space complexity is $O(\log n)$. Whe +#### Python3 + ```python class Solution: def minMaxDifference(self, num: int) -> int: @@ -91,6 +93,8 @@ class Solution: return num - mi ``` +#### Java + ```java class Solution { public int minMaxDifference(int num) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func minMaxDifference(num int) int { s := []byte(strconv.Itoa(num)) @@ -162,6 +170,8 @@ func minMaxDifference(num int) int { } ``` +#### TypeScript + ```ts function minMaxDifference(num: number): number { const s = num + ''; @@ -175,6 +185,8 @@ function minMaxDifference(num: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_max_difference(num: i32) -> i32 { @@ -190,6 +202,8 @@ impl Solution { } ``` +#### C + ```c int getLen(int num) { int res = 0; @@ -239,6 +253,8 @@ int minMaxDifference(int num) { +#### Rust + ```rust impl Solution { pub fn min_max_difference(num: i32) -> i32 { diff --git a/solution/2500-2599/2567.Minimum Score by Changing Two Elements/README.md b/solution/2500-2599/2567.Minimum Score by Changing Two Elements/README.md index 1cf0882ab4326..eefd2b6617a25 100644 --- a/solution/2500-2599/2567.Minimum Score by Changing Two Elements/README.md +++ b/solution/2500-2599/2567.Minimum Score by Changing Two Elements/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def minimizeSum(self, nums: List[int]) -> int: @@ -98,6 +100,8 @@ class Solution: return min(nums[-1] - nums[2], nums[-2] - nums[1], nums[-3] - nums[0]) ``` +#### Java + ```java class Solution { public int minimizeSum(int[] nums) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func minimizeSum(nums []int) int { sort.Ints(nums) @@ -130,6 +138,8 @@ func minimizeSum(nums []int) int { } ``` +#### TypeScript + ```ts function minimizeSum(nums: number[]): number { nums.sort((a, b) => a - b); @@ -138,6 +148,8 @@ function minimizeSum(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn minimize_sum(mut nums: Vec) -> i32 { @@ -148,6 +160,8 @@ impl Solution { } ``` +#### C + ```c #define min(a, b) (((a) < (b)) ? (a) : (b)) diff --git a/solution/2500-2599/2567.Minimum Score by Changing Two Elements/README_EN.md b/solution/2500-2599/2567.Minimum Score by Changing Two Elements/README_EN.md index b8f252b3ca727..8546ac3c2b268 100644 --- a/solution/2500-2599/2567.Minimum Score by Changing Two Elements/README_EN.md +++ b/solution/2500-2599/2567.Minimum Score by Changing Two Elements/README_EN.md @@ -87,6 +87,8 @@ Similar problems: +#### Python3 + ```python class Solution: def minimizeSum(self, nums: List[int]) -> int: @@ -94,6 +96,8 @@ class Solution: return min(nums[-1] - nums[2], nums[-2] - nums[1], nums[-3] - nums[0]) ``` +#### Java + ```java class Solution { public int minimizeSum(int[] nums) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func minimizeSum(nums []int) int { sort.Ints(nums) @@ -126,6 +134,8 @@ func minimizeSum(nums []int) int { } ``` +#### TypeScript + ```ts function minimizeSum(nums: number[]): number { nums.sort((a, b) => a - b); @@ -134,6 +144,8 @@ function minimizeSum(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn minimize_sum(mut nums: Vec) -> i32 { @@ -144,6 +156,8 @@ impl Solution { } ``` +#### C + ```c #define min(a, b) (((a) < (b)) ? (a) : (b)) diff --git a/solution/2500-2599/2568.Minimum Impossible OR/README.md b/solution/2500-2599/2568.Minimum Impossible OR/README.md index 4f71bfb02ea4f..c821f7a016005 100644 --- a/solution/2500-2599/2568.Minimum Impossible OR/README.md +++ b/solution/2500-2599/2568.Minimum Impossible OR/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def minImpossibleOR(self, nums: List[int]) -> int: @@ -74,6 +76,8 @@ class Solution: return next(1 << i for i in range(32) if 1 << i not in s) ``` +#### Java + ```java class Solution { public int minImpossibleOR(int[] nums) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -104,6 +110,8 @@ public: }; ``` +#### Go + ```go func minImpossibleOR(nums []int) int { s := map[int]bool{} @@ -118,6 +126,8 @@ func minImpossibleOR(nums []int) int { } ``` +#### TypeScript + ```ts function minImpossibleOR(nums: number[]): number { const s: Set = new Set(); diff --git a/solution/2500-2599/2568.Minimum Impossible OR/README_EN.md b/solution/2500-2599/2568.Minimum Impossible OR/README_EN.md index ca10514ee8832..7cf42606b7f6b 100644 --- a/solution/2500-2599/2568.Minimum Impossible OR/README_EN.md +++ b/solution/2500-2599/2568.Minimum Impossible OR/README_EN.md @@ -67,6 +67,8 @@ The time complexity is $O(n + \log M)$, and the space complexity is $O(n)$. Here +#### Python3 + ```python class Solution: def minImpossibleOR(self, nums: List[int]) -> int: @@ -74,6 +76,8 @@ class Solution: return next(1 << i for i in range(32) if 1 << i not in s) ``` +#### Java + ```java class Solution { public int minImpossibleOR(int[] nums) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -104,6 +110,8 @@ public: }; ``` +#### Go + ```go func minImpossibleOR(nums []int) int { s := map[int]bool{} @@ -118,6 +126,8 @@ func minImpossibleOR(nums []int) int { } ``` +#### TypeScript + ```ts function minImpossibleOR(nums: number[]): number { const s: Set = new Set(); diff --git a/solution/2500-2599/2569.Handling Sum Queries After Update/README.md b/solution/2500-2599/2569.Handling Sum Queries After Update/README.md index add92e3153b2d..aa0b418b7c507 100644 --- a/solution/2500-2599/2569.Handling Sum Queries After Update/README.md +++ b/solution/2500-2599/2569.Handling Sum Queries After Update/README.md @@ -105,6 +105,8 @@ tags: +#### Python3 + ```python class Node: def __init__(self): @@ -184,6 +186,8 @@ class Solution: return ans ``` +#### Java + ```java class Node { int l, r; @@ -295,6 +299,8 @@ class Solution { } ``` +#### C++ + ```cpp class Node { public: @@ -403,6 +409,8 @@ public: }; ``` +#### Go + ```go type node struct { l, r, s, lazy int diff --git a/solution/2500-2599/2569.Handling Sum Queries After Update/README_EN.md b/solution/2500-2599/2569.Handling Sum Queries After Update/README_EN.md index fe7e72f14fe63..34d1c594abb98 100644 --- a/solution/2500-2599/2569.Handling Sum Queries After Update/README_EN.md +++ b/solution/2500-2599/2569.Handling Sum Queries After Update/README_EN.md @@ -103,6 +103,8 @@ The time complexity is $O(n + m \times \log n)$, and the space complexity is $O( +#### Python3 + ```python class Node: def __init__(self): @@ -182,6 +184,8 @@ class Solution: return ans ``` +#### Java + ```java class Node { int l, r; @@ -293,6 +297,8 @@ class Solution { } ``` +#### C++ + ```cpp class Node { public: @@ -401,6 +407,8 @@ public: }; ``` +#### Go + ```go type node struct { l, r, s, lazy int diff --git a/solution/2500-2599/2570.Merge Two 2D Arrays by Summing Values/README.md b/solution/2500-2599/2570.Merge Two 2D Arrays by Summing Values/README.md index c92b89032f91c..611a865fc24ab 100644 --- a/solution/2500-2599/2570.Merge Two 2D Arrays by Summing Values/README.md +++ b/solution/2500-2599/2570.Merge Two 2D Arrays by Summing Values/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def mergeArrays( @@ -97,6 +99,8 @@ class Solution: return sorted(cnt.items()) ``` +#### Java + ```java class Solution { public int[][] mergeArrays(int[][] nums1, int[][] nums2) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func mergeArrays(nums1 [][]int, nums2 [][]int) (ans [][]int) { cnt := [1001]int{} @@ -164,6 +172,8 @@ func mergeArrays(nums1 [][]int, nums2 [][]int) (ans [][]int) { } ``` +#### TypeScript + ```ts function mergeArrays(nums1: number[][], nums2: number[][]): number[][] { const n = 1001; @@ -184,6 +194,8 @@ function mergeArrays(nums1: number[][], nums2: number[][]): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn merge_arrays(nums1: Vec>, nums2: Vec>) -> Vec> { diff --git a/solution/2500-2599/2570.Merge Two 2D Arrays by Summing Values/README_EN.md b/solution/2500-2599/2570.Merge Two 2D Arrays by Summing Values/README_EN.md index cd3389af5a84d..fe1f631b5eee2 100644 --- a/solution/2500-2599/2570.Merge Two 2D Arrays by Summing Values/README_EN.md +++ b/solution/2500-2599/2570.Merge Two 2D Arrays by Summing Values/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(n + m)$, and the space complexity is $O(M)$. Where $n$ +#### Python3 + ```python class Solution: def mergeArrays( @@ -97,6 +99,8 @@ class Solution: return sorted(cnt.items()) ``` +#### Java + ```java class Solution { public int[][] mergeArrays(int[][] nums1, int[][] nums2) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func mergeArrays(nums1 [][]int, nums2 [][]int) (ans [][]int) { cnt := [1001]int{} @@ -164,6 +172,8 @@ func mergeArrays(nums1 [][]int, nums2 [][]int) (ans [][]int) { } ``` +#### TypeScript + ```ts function mergeArrays(nums1: number[][], nums2: number[][]): number[][] { const n = 1001; @@ -184,6 +194,8 @@ function mergeArrays(nums1: number[][], nums2: number[][]): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn merge_arrays(nums1: Vec>, nums2: Vec>) -> Vec> { diff --git a/solution/2500-2599/2571.Minimum Operations to Reduce an Integer to 0/README.md b/solution/2500-2599/2571.Minimum Operations to Reduce an Integer to 0/README.md index b4b8232ceac25..0d36b52528373 100644 --- a/solution/2500-2599/2571.Minimum Operations to Reduce an Integer to 0/README.md +++ b/solution/2500-2599/2571.Minimum Operations to Reduce an Integer to 0/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def minOperations(self, n: int) -> int: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minOperations(int n) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func minOperations(n int) (ans int) { cnt := 0 @@ -164,6 +172,8 @@ func minOperations(n int) (ans int) { } ``` +#### TypeScript + ```ts function minOperations(n: number): number { let [ans, cnt] = [0, 0]; diff --git a/solution/2500-2599/2571.Minimum Operations to Reduce an Integer to 0/README_EN.md b/solution/2500-2599/2571.Minimum Operations to Reduce an Integer to 0/README_EN.md index ab1031030cbc4..0c59d7c81d9eb 100644 --- a/solution/2500-2599/2571.Minimum Operations to Reduce an Integer to 0/README_EN.md +++ b/solution/2500-2599/2571.Minimum Operations to Reduce an Integer to 0/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(\log n)$, and the space complexity is $O(1)$. Here, $n +#### Python3 + ```python class Solution: def minOperations(self, n: int) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minOperations(int n) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func minOperations(n int) (ans int) { cnt := 0 @@ -162,6 +170,8 @@ func minOperations(n int) (ans int) { } ``` +#### TypeScript + ```ts function minOperations(n: number): number { let [ans, cnt] = [0, 0]; diff --git a/solution/2500-2599/2572.Count the Number of Square-Free Subsets/README.md b/solution/2500-2599/2572.Count the Number of Square-Free Subsets/README.md index f2a773f2cd8d1..ecbda6d9b25f3 100644 --- a/solution/2500-2599/2572.Count the Number of Square-Free Subsets/README.md +++ b/solution/2500-2599/2572.Count the Number of Square-Free Subsets/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def squareFreeSubsets(self, nums: List[int]) -> int: @@ -111,6 +113,8 @@ class Solution: return sum(v for v in f) % mod - 1 ``` +#### Java + ```java class Solution { public int squareFreeSubsets(int[] nums) { @@ -152,6 +156,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go func squareFreeSubsets(nums []int) (ans int) { primes := []int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29} @@ -231,6 +239,8 @@ func squareFreeSubsets(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function squareFreeSubsets(nums: number[]): number { const primes: number[] = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]; diff --git a/solution/2500-2599/2572.Count the Number of Square-Free Subsets/README_EN.md b/solution/2500-2599/2572.Count the Number of Square-Free Subsets/README_EN.md index 003687e3cf1ff..cf1a560980a5c 100644 --- a/solution/2500-2599/2572.Count the Number of Square-Free Subsets/README_EN.md +++ b/solution/2500-2599/2572.Count the Number of Square-Free Subsets/README_EN.md @@ -88,6 +88,8 @@ Similar problems: +#### Python3 + ```python class Solution: def squareFreeSubsets(self, nums: List[int]) -> int: @@ -110,6 +112,8 @@ class Solution: return sum(v for v in f) % mod - 1 ``` +#### Java + ```java class Solution { public int squareFreeSubsets(int[] nums) { @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -192,6 +198,8 @@ public: }; ``` +#### Go + ```go func squareFreeSubsets(nums []int) (ans int) { primes := []int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29} @@ -230,6 +238,8 @@ func squareFreeSubsets(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function squareFreeSubsets(nums: number[]): number { const primes: number[] = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]; diff --git a/solution/2500-2599/2573.Find the String with LCP/README.md b/solution/2500-2599/2573.Find the String with LCP/README.md index 8380bf7ffdaff..df38346fe8ab5 100644 --- a/solution/2500-2599/2573.Find the String with LCP/README.md +++ b/solution/2500-2599/2573.Find the String with LCP/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def findTheString(self, lcp: List[List[int]]) -> str: @@ -122,6 +124,8 @@ class Solution: return "".join(s) ``` +#### Java + ```java class Solution { public String findTheString(int[][] lcp) { @@ -166,6 +170,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -208,6 +214,8 @@ public: }; ``` +#### Go + ```go func findTheString(lcp [][]int) string { i, n := 0, len(lcp) @@ -247,6 +255,8 @@ func findTheString(lcp [][]int) string { } ``` +#### TypeScript + ```ts function findTheString(lcp: number[][]): string { let i: number = 0; diff --git a/solution/2500-2599/2573.Find the String with LCP/README_EN.md b/solution/2500-2599/2573.Find the String with LCP/README_EN.md index e39e42a88a665..d6447f05dd718 100644 --- a/solution/2500-2599/2573.Find the String with LCP/README_EN.md +++ b/solution/2500-2599/2573.Find the String with LCP/README_EN.md @@ -91,6 +91,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$. Where $n$ i +#### Python3 + ```python class Solution: def findTheString(self, lcp: List[List[int]]) -> str: @@ -120,6 +122,8 @@ class Solution: return "".join(s) ``` +#### Java + ```java class Solution { public String findTheString(int[][] lcp) { @@ -164,6 +168,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -206,6 +212,8 @@ public: }; ``` +#### Go + ```go func findTheString(lcp [][]int) string { i, n := 0, len(lcp) @@ -245,6 +253,8 @@ func findTheString(lcp [][]int) string { } ``` +#### TypeScript + ```ts function findTheString(lcp: number[][]): string { let i: number = 0; diff --git a/solution/2500-2599/2574.Left and Right Sum Differences/README.md b/solution/2500-2599/2574.Left and Right Sum Differences/README.md index bae041b57ec9a..312261098b10b 100644 --- a/solution/2500-2599/2574.Left and Right Sum Differences/README.md +++ b/solution/2500-2599/2574.Left and Right Sum Differences/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def leftRigthDifference(self, nums: List[int]) -> List[int]: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] leftRigthDifference(int[] nums) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func leftRigthDifference(nums []int) (ans []int) { var left, right int @@ -151,6 +159,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function leftRigthDifference(nums: number[]): number[] { let left = 0, @@ -165,6 +175,8 @@ function leftRigthDifference(nums: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn left_rigth_difference(nums: Vec) -> Vec { @@ -182,6 +194,8 @@ impl Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). @@ -213,6 +227,8 @@ int* leftRigthDifference(int* nums, int numsSize, int* returnSize) { +#### TypeScript + ```ts function leftRigthDifference(nums: number[]): number[] { let left = 0; @@ -226,6 +242,8 @@ function leftRigthDifference(nums: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn left_right_difference(nums: Vec) -> Vec { @@ -260,6 +278,8 @@ impl Solution { +#### Rust + ```rust impl Solution { pub fn left_right_difference(nums: Vec) -> Vec { diff --git a/solution/2500-2599/2574.Left and Right Sum Differences/README_EN.md b/solution/2500-2599/2574.Left and Right Sum Differences/README_EN.md index 9dd357fdf570e..ca52712ec0df2 100644 --- a/solution/2500-2599/2574.Left and Right Sum Differences/README_EN.md +++ b/solution/2500-2599/2574.Left and Right Sum Differences/README_EN.md @@ -85,6 +85,8 @@ Similar problems: +#### Python3 + ```python class Solution: def leftRigthDifference(self, nums: List[int]) -> List[int]: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] leftRigthDifference(int[] nums) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func leftRigthDifference(nums []int) (ans []int) { var left, right int @@ -151,6 +159,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function leftRigthDifference(nums: number[]): number[] { let left = 0, @@ -165,6 +175,8 @@ function leftRigthDifference(nums: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn left_rigth_difference(nums: Vec) -> Vec { @@ -182,6 +194,8 @@ impl Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). @@ -213,6 +227,8 @@ int* leftRigthDifference(int* nums, int numsSize, int* returnSize) { +#### TypeScript + ```ts function leftRigthDifference(nums: number[]): number[] { let left = 0; @@ -226,6 +242,8 @@ function leftRigthDifference(nums: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn left_right_difference(nums: Vec) -> Vec { @@ -260,6 +278,8 @@ impl Solution { +#### Rust + ```rust impl Solution { pub fn left_right_difference(nums: Vec) -> Vec { diff --git a/solution/2500-2599/2575.Find the Divisibility Array of a String/README.md b/solution/2500-2599/2575.Find the Divisibility Array of a String/README.md index c8a033a292d54..86e68d5f31279 100644 --- a/solution/2500-2599/2575.Find the Divisibility Array of a String/README.md +++ b/solution/2500-2599/2575.Find the Divisibility Array of a String/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def divisibilityArray(self, word: str, m: int) -> List[int]: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] divisibilityArray(String word, int m) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func divisibilityArray(word string, m int) (ans []int) { x := 0 @@ -132,6 +140,8 @@ func divisibilityArray(word string, m int) (ans []int) { } ``` +#### TypeScript + ```ts function divisibilityArray(word: string, m: number): number[] { const ans: number[] = []; @@ -144,6 +154,8 @@ function divisibilityArray(word: string, m: number): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn divisibility_array(word: String, m: i32) -> Vec { @@ -164,6 +176,8 @@ impl Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). diff --git a/solution/2500-2599/2575.Find the Divisibility Array of a String/README_EN.md b/solution/2500-2599/2575.Find the Divisibility Array of a String/README_EN.md index 9315b0a7cb69d..cff7852c6d717 100644 --- a/solution/2500-2599/2575.Find the Divisibility Array of a String/README_EN.md +++ b/solution/2500-2599/2575.Find the Divisibility Array of a String/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string `word`. The +#### Python3 + ```python class Solution: def divisibilityArray(self, word: str, m: int) -> List[int]: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] divisibilityArray(String word, int m) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func divisibilityArray(word string, m int) (ans []int) { x := 0 @@ -130,6 +138,8 @@ func divisibilityArray(word string, m int) (ans []int) { } ``` +#### TypeScript + ```ts function divisibilityArray(word: string, m: number): number[] { const ans: number[] = []; @@ -142,6 +152,8 @@ function divisibilityArray(word: string, m: number): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn divisibility_array(word: String, m: i32) -> Vec { @@ -162,6 +174,8 @@ impl Solution { } ``` +#### C + ```c /** * Note: The returned array must be malloced, assume caller calls free(). diff --git a/solution/2500-2599/2576.Find the Maximum Number of Marked Indices/README.md b/solution/2500-2599/2576.Find the Maximum Number of Marked Indices/README.md index 17e128024ab9d..a4b5345d11e7d 100644 --- a/solution/2500-2599/2576.Find the Maximum Number of Marked Indices/README.md +++ b/solution/2500-2599/2576.Find the Maximum Number of Marked Indices/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def maxNumOfMarkedIndices(self, nums: List[int]) -> int: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxNumOfMarkedIndices(int[] nums) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func maxNumOfMarkedIndices(nums []int) (ans int) { sort.Ints(nums) @@ -155,6 +163,8 @@ func maxNumOfMarkedIndices(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function maxNumOfMarkedIndices(nums: number[]): number { nums.sort((a, b) => a - b); diff --git a/solution/2500-2599/2576.Find the Maximum Number of Marked Indices/README_EN.md b/solution/2500-2599/2576.Find the Maximum Number of Marked Indices/README_EN.md index 8b3a610c3f3e7..34bf3bd91bfe1 100644 --- a/solution/2500-2599/2576.Find the Maximum Number of Marked Indices/README_EN.md +++ b/solution/2500-2599/2576.Find the Maximum Number of Marked Indices/README_EN.md @@ -92,6 +92,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def maxNumOfMarkedIndices(self, nums: List[int]) -> int: @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxNumOfMarkedIndices(int[] nums) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func maxNumOfMarkedIndices(nums []int) (ans int) { sort.Ints(nums) @@ -163,6 +171,8 @@ func maxNumOfMarkedIndices(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function maxNumOfMarkedIndices(nums: number[]): number { nums.sort((a, b) => a - b); diff --git a/solution/2500-2599/2577.Minimum Time to Visit a Cell In a Grid/README.md b/solution/2500-2599/2577.Minimum Time to Visit a Cell In a Grid/README.md index 9e2819389561b..95200a5adb14c 100644 --- a/solution/2500-2599/2577.Minimum Time to Visit a Cell In a Grid/README.md +++ b/solution/2500-2599/2577.Minimum Time to Visit a Cell In a Grid/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def minimumTime(self, grid: List[List[int]]) -> int: @@ -118,6 +120,8 @@ class Solution: heappush(q, (nt, x, y)) ``` +#### Java + ```java class Solution { public int minimumTime(int[][] grid) { @@ -157,6 +161,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -196,6 +202,8 @@ public: }; ``` +#### Go + ```go func minimumTime(grid [][]int) int { if grid[0][1] > 1 && grid[1][0] > 1 { diff --git a/solution/2500-2599/2577.Minimum Time to Visit a Cell In a Grid/README_EN.md b/solution/2500-2599/2577.Minimum Time to Visit a Cell In a Grid/README_EN.md index cdc2896a00250..1b7a3d7fa9251 100644 --- a/solution/2500-2599/2577.Minimum Time to Visit a Cell In a Grid/README_EN.md +++ b/solution/2500-2599/2577.Minimum Time to Visit a Cell In a Grid/README_EN.md @@ -100,6 +100,8 @@ The time complexity is $O(m \times n \times \log (m \times n))$, and the space c +#### Python3 + ```python class Solution: def minimumTime(self, grid: List[List[int]]) -> int: @@ -125,6 +127,8 @@ class Solution: heappush(q, (nt, x, y)) ``` +#### Java + ```java class Solution { public int minimumTime(int[][] grid) { @@ -164,6 +168,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -203,6 +209,8 @@ public: }; ``` +#### Go + ```go func minimumTime(grid [][]int) int { if grid[0][1] > 1 && grid[1][0] > 1 { diff --git a/solution/2500-2599/2578.Split With Minimum Sum/README.md b/solution/2500-2599/2578.Split With Minimum Sum/README.md index 18ad9a07a05b5..9152ca9a2d8b2 100644 --- a/solution/2500-2599/2578.Split With Minimum Sum/README.md +++ b/solution/2500-2599/2578.Split With Minimum Sum/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def splitNum(self, num: int) -> int: @@ -103,6 +105,8 @@ class Solution: return sum(ans) ``` +#### Java + ```java class Solution { public int splitNum(int num) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func splitNum(num int) int { cnt := [10]int{} @@ -168,6 +176,8 @@ func splitNum(num int) int { } ``` +#### TypeScript + ```ts function splitNum(num: number): number { const cnt: number[] = Array(10).fill(0); @@ -188,6 +198,8 @@ function splitNum(num: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn split_num(mut num: i32) -> i32 { @@ -230,6 +242,8 @@ impl Solution { +#### Python3 + ```python class Solution: def splitNum(self, num: int) -> int: @@ -237,6 +251,8 @@ class Solution: return int(''.join(s[::2])) + int(''.join(s[1::2])) ``` +#### Java + ```java class Solution { public int splitNum(int num) { @@ -251,6 +267,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -266,6 +284,8 @@ public: }; ``` +#### Go + ```go func splitNum(num int) int { s := []byte(strconv.Itoa(num)) @@ -278,6 +298,8 @@ func splitNum(num int) int { } ``` +#### TypeScript + ```ts function splitNum(num: number): number { const s: string[] = String(num).split(''); @@ -290,6 +312,8 @@ function splitNum(num: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn split_num(num: i32) -> i32 { diff --git a/solution/2500-2599/2578.Split With Minimum Sum/README_EN.md b/solution/2500-2599/2578.Split With Minimum Sum/README_EN.md index 234a100cba008..be554cb57d79e 100644 --- a/solution/2500-2599/2578.Split With Minimum Sum/README_EN.md +++ b/solution/2500-2599/2578.Split With Minimum Sum/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n)$, and the space complexity is $O(C)$. Where $n$ is +#### Python3 + ```python class Solution: def splitNum(self, num: int) -> int: @@ -101,6 +103,8 @@ class Solution: return sum(ans) ``` +#### Java + ```java class Solution { public int splitNum(int num) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func splitNum(num int) int { cnt := [10]int{} @@ -166,6 +174,8 @@ func splitNum(num int) int { } ``` +#### TypeScript + ```ts function splitNum(num: number): number { const cnt: number[] = Array(10).fill(0); @@ -186,6 +196,8 @@ function splitNum(num: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn split_num(mut num: i32) -> i32 { @@ -228,6 +240,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def splitNum(self, num: int) -> int: @@ -235,6 +249,8 @@ class Solution: return int(''.join(s[::2])) + int(''.join(s[1::2])) ``` +#### Java + ```java class Solution { public int splitNum(int num) { @@ -249,6 +265,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -264,6 +282,8 @@ public: }; ``` +#### Go + ```go func splitNum(num int) int { s := []byte(strconv.Itoa(num)) @@ -276,6 +296,8 @@ func splitNum(num int) int { } ``` +#### TypeScript + ```ts function splitNum(num: number): number { const s: string[] = String(num).split(''); @@ -288,6 +310,8 @@ function splitNum(num: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn split_num(num: i32) -> i32 { diff --git a/solution/2500-2599/2579.Count Total Number of Colored Cells/README.md b/solution/2500-2599/2579.Count Total Number of Colored Cells/README.md index a6a69849c9b8d..3a41143bf8854 100644 --- a/solution/2500-2599/2579.Count Total Number of Colored Cells/README.md +++ b/solution/2500-2599/2579.Count Total Number of Colored Cells/README.md @@ -67,12 +67,16 @@ tags: +#### Python3 + ```python class Solution: def coloredCells(self, n: int) -> int: return 2 * n * (n - 1) + 1 ``` +#### Java + ```java class Solution { public long coloredCells(int n) { @@ -81,6 +85,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -90,18 +96,24 @@ public: }; ``` +#### Go + ```go func coloredCells(n int) int64 { return int64(2*n*(n-1) + 1) } ``` +#### TypeScript + ```ts function coloredCells(n: number): number { return 2 * n * (n - 1) + 1; } ``` +#### Rust + ```rust impl Solution { pub fn colored_cells(n: i32) -> i64 { diff --git a/solution/2500-2599/2579.Count Total Number of Colored Cells/README_EN.md b/solution/2500-2599/2579.Count Total Number of Colored Cells/README_EN.md index 5d429ea939390..8690eb400a13f 100644 --- a/solution/2500-2599/2579.Count Total Number of Colored Cells/README_EN.md +++ b/solution/2500-2599/2579.Count Total Number of Colored Cells/README_EN.md @@ -67,12 +67,16 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def coloredCells(self, n: int) -> int: return 2 * n * (n - 1) + 1 ``` +#### Java + ```java class Solution { public long coloredCells(int n) { @@ -81,6 +85,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -90,18 +96,24 @@ public: }; ``` +#### Go + ```go func coloredCells(n int) int64 { return int64(2*n*(n-1) + 1) } ``` +#### TypeScript + ```ts function coloredCells(n: number): number { return 2 * n * (n - 1) + 1; } ``` +#### Rust + ```rust impl Solution { pub fn colored_cells(n: i32) -> i64 { diff --git a/solution/2500-2599/2580.Count Ways to Group Overlapping Ranges/README.md b/solution/2500-2599/2580.Count Ways to Group Overlapping Ranges/README.md index 6f99157e6452f..43815602ac842 100644 --- a/solution/2500-2599/2580.Count Ways to Group Overlapping Ranges/README.md +++ b/solution/2500-2599/2580.Count Ways to Group Overlapping Ranges/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def countWays(self, ranges: List[List[int]]) -> int: @@ -104,6 +106,8 @@ class Solution: return pow(2, cnt, mod) ``` +#### Java + ```java class Solution { public int countWays(int[][] ranges) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func countWays(ranges [][]int) int { sort.Slice(ranges, func(i, j int) bool { return ranges[i][0] < ranges[j][0] }) @@ -183,6 +191,8 @@ func countWays(ranges [][]int) int { } ``` +#### TypeScript + ```ts function countWays(ranges: number[][]): number { ranges.sort((a, b) => a[0] - b[0]); @@ -209,6 +219,8 @@ function countWays(ranges: number[][]): number { +#### Python3 + ```python class Solution: def countWays(self, ranges: List[List[int]]) -> int: @@ -223,6 +235,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countWays(int[][] ranges) { @@ -241,6 +255,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -259,6 +275,8 @@ public: }; ``` +#### Go + ```go func countWays(ranges [][]int) int { sort.Slice(ranges, func(i, j int) bool { return ranges[i][0] < ranges[j][0] }) diff --git a/solution/2500-2599/2580.Count Ways to Group Overlapping Ranges/README_EN.md b/solution/2500-2599/2580.Count Ways to Group Overlapping Ranges/README_EN.md index 485166d65ec12..d42161d792c69 100644 --- a/solution/2500-2599/2580.Count Ways to Group Overlapping Ranges/README_EN.md +++ b/solution/2500-2599/2580.Count Ways to Group Overlapping Ranges/README_EN.md @@ -91,6 +91,8 @@ Alternatively, we can also avoid using fast power. Once a new non-overlapping in +#### Python3 + ```python class Solution: def countWays(self, ranges: List[List[int]]) -> int: @@ -104,6 +106,8 @@ class Solution: return pow(2, cnt, mod) ``` +#### Java + ```java class Solution { public int countWays(int[][] ranges) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func countWays(ranges [][]int) int { sort.Slice(ranges, func(i, j int) bool { return ranges[i][0] < ranges[j][0] }) @@ -183,6 +191,8 @@ func countWays(ranges [][]int) int { } ``` +#### TypeScript + ```ts function countWays(ranges: number[][]): number { ranges.sort((a, b) => a[0] - b[0]); @@ -209,6 +219,8 @@ function countWays(ranges: number[][]): number { +#### Python3 + ```python class Solution: def countWays(self, ranges: List[List[int]]) -> int: @@ -223,6 +235,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countWays(int[][] ranges) { @@ -241,6 +255,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -259,6 +275,8 @@ public: }; ``` +#### Go + ```go func countWays(ranges [][]int) int { sort.Slice(ranges, func(i, j int) bool { return ranges[i][0] < ranges[j][0] }) diff --git a/solution/2500-2599/2581.Count Number of Possible Root Nodes/README.md b/solution/2500-2599/2581.Count Number of Possible Root Nodes/README.md index 2dcfc849b5737..1d847a9b9b802 100644 --- a/solution/2500-2599/2581.Count Number of Possible Root Nodes/README.md +++ b/solution/2500-2599/2581.Count Number of Possible Root Nodes/README.md @@ -113,6 +113,8 @@ tags: +#### Python3 + ```python class Solution: def rootCount( @@ -148,6 +150,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -206,6 +210,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -258,6 +264,8 @@ public: }; ``` +#### Go + ```go func rootCount(edges [][]int, guesses [][]int, k int) (ans int) { n := len(edges) + 1 @@ -308,6 +316,8 @@ func rootCount(edges [][]int, guesses [][]int, k int) (ans int) { } ``` +#### TypeScript + ```ts function rootCount(edges: number[][], guesses: number[][], k: number): number { const n = edges.length + 1; diff --git a/solution/2500-2599/2581.Count Number of Possible Root Nodes/README_EN.md b/solution/2500-2599/2581.Count Number of Possible Root Nodes/README_EN.md index f4b2ab1deb8b6..233efe70d307a 100644 --- a/solution/2500-2599/2581.Count Number of Possible Root Nodes/README_EN.md +++ b/solution/2500-2599/2581.Count Number of Possible Root Nodes/README_EN.md @@ -109,6 +109,8 @@ The time complexity is $O(n + m)$ and the space complexity is $O(n + m)$, where +#### Python3 + ```python class Solution: def rootCount( @@ -144,6 +146,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -202,6 +206,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -254,6 +260,8 @@ public: }; ``` +#### Go + ```go func rootCount(edges [][]int, guesses [][]int, k int) (ans int) { n := len(edges) + 1 @@ -304,6 +312,8 @@ func rootCount(edges [][]int, guesses [][]int, k int) (ans int) { } ``` +#### TypeScript + ```ts function rootCount(edges: number[][], guesses: number[][], k: number): number { const n = edges.length + 1; diff --git a/solution/2500-2599/2582.Pass the Pillow/README.md b/solution/2500-2599/2582.Pass the Pillow/README.md index 83842870777aa..42d9357793c80 100644 --- a/solution/2500-2599/2582.Pass the Pillow/README.md +++ b/solution/2500-2599/2582.Pass the Pillow/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def passThePillow(self, n: int, time: int) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int passThePillow(int n, int time) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func passThePillow(n int, time int) int { ans, k := 1, 1 @@ -127,6 +135,8 @@ func passThePillow(n int, time int) int { } ``` +#### TypeScript + ```ts function passThePillow(n: number, time: number): number { let ans = 1, @@ -141,6 +151,8 @@ function passThePillow(n: number, time: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn pass_the_pillow(n: i32, time: i32) -> i32 { @@ -179,6 +191,8 @@ impl Solution { +#### Python3 + ```python class Solution: def passThePillow(self, n: int, time: int) -> int: @@ -186,6 +200,8 @@ class Solution: return n - mod if k & 1 else mod + 1 ``` +#### Java + ```java class Solution { public int passThePillow(int n, int time) { @@ -196,6 +212,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -207,6 +225,8 @@ public: }; ``` +#### Go + ```go func passThePillow(n int, time int) int { k, mod := time/(n-1), time%(n-1) @@ -217,6 +237,8 @@ func passThePillow(n int, time int) int { } ``` +#### TypeScript + ```ts function passThePillow(n: number, time: number): number { const k = time / (n - 1); @@ -225,6 +247,8 @@ function passThePillow(n: number, time: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn pass_the_pillow(n: i32, time: i32) -> i32 { diff --git a/solution/2500-2599/2582.Pass the Pillow/README_EN.md b/solution/2500-2599/2582.Pass the Pillow/README_EN.md index 965f64196dddb..d43c7d1d5a8df 100644 --- a/solution/2500-2599/2582.Pass the Pillow/README_EN.md +++ b/solution/2500-2599/2582.Pass the Pillow/README_EN.md @@ -67,6 +67,8 @@ The time complexity is $O(time)$ and the space complexity is $O(1)$, where $time +#### Python3 + ```python class Solution: def passThePillow(self, n: int, time: int) -> int: @@ -78,6 +80,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int passThePillow(int n, int time) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func passThePillow(n int, time int) int { ans, k := 1, 1 @@ -122,6 +130,8 @@ func passThePillow(n int, time int) int { } ``` +#### TypeScript + ```ts function passThePillow(n: number, time: number): number { let ans = 1, @@ -136,6 +146,8 @@ function passThePillow(n: number, time: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn pass_the_pillow(n: i32, time: i32) -> i32 { @@ -174,6 +186,8 @@ The time complexity is $O(1)$ and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def passThePillow(self, n: int, time: int) -> int: @@ -181,6 +195,8 @@ class Solution: return n - mod if k & 1 else mod + 1 ``` +#### Java + ```java class Solution { public int passThePillow(int n, int time) { @@ -191,6 +207,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -202,6 +220,8 @@ public: }; ``` +#### Go + ```go func passThePillow(n int, time int) int { k, mod := time/(n-1), time%(n-1) @@ -212,6 +232,8 @@ func passThePillow(n int, time int) int { } ``` +#### TypeScript + ```ts function passThePillow(n: number, time: number): number { const k = time / (n - 1); @@ -220,6 +242,8 @@ function passThePillow(n: number, time: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn pass_the_pillow(n: i32, time: i32) -> i32 { diff --git a/solution/2500-2599/2583.Kth Largest Sum in a Binary Tree/README.md b/solution/2500-2599/2583.Kth Largest Sum in a Binary Tree/README.md index 2c0452dfa7dee..1c63c49b58791 100644 --- a/solution/2500-2599/2583.Kth Largest Sum in a Binary Tree/README.md +++ b/solution/2500-2599/2583.Kth Largest Sum in a Binary Tree/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -105,6 +107,8 @@ class Solution: return -1 if len(arr) < k else nlargest(k, arr)[-1] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -190,6 +196,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -225,6 +233,8 @@ func kthLargestLevelSum(root *TreeNode, k int) int64 { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -279,6 +289,8 @@ function kthLargestLevelSum(root: TreeNode | null, k: number): number { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -302,6 +314,8 @@ class Solution: return -1 if len(arr) < k else nlargest(k, arr)[-1] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -344,6 +358,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -381,6 +397,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -414,6 +432,8 @@ func kthLargestLevelSum(root *TreeNode, k int) int64 { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/2500-2599/2583.Kth Largest Sum in a Binary Tree/README_EN.md b/solution/2500-2599/2583.Kth Largest Sum in a Binary Tree/README_EN.md index 0bf94073eb7e6..10eff25c6cd81 100644 --- a/solution/2500-2599/2583.Kth Largest Sum in a Binary Tree/README_EN.md +++ b/solution/2500-2599/2583.Kth Largest Sum in a Binary Tree/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -99,6 +101,8 @@ class Solution: return -1 if len(arr) < k else nlargest(k, arr)[-1] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -184,6 +190,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -219,6 +227,8 @@ func kthLargestLevelSum(root *TreeNode, k int) int64 { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -273,6 +283,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -296,6 +308,8 @@ class Solution: return -1 if len(arr) < k else nlargest(k, arr)[-1] ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -338,6 +352,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -375,6 +391,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -408,6 +426,8 @@ func kthLargestLevelSum(root *TreeNode, k int) int64 { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/2500-2599/2584.Split the Array to Make Coprime Products/README.md b/solution/2500-2599/2584.Split the Array to Make Coprime Products/README.md index 51414831835d4..0f6388f15c439 100644 --- a/solution/2500-2599/2584.Split the Array to Make Coprime Products/README.md +++ b/solution/2500-2599/2584.Split the Array to Make Coprime Products/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def findValidSplit(self, nums: List[int]) -> int: @@ -106,6 +108,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int findValidSplit(int[] nums) { @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -191,6 +197,8 @@ public: }; ``` +#### Go + ```go func findValidSplit(nums []int) int { first := map[int]int{} diff --git a/solution/2500-2599/2584.Split the Array to Make Coprime Products/README_EN.md b/solution/2500-2599/2584.Split the Array to Make Coprime Products/README_EN.md index ab36f8ed416a4..54c4a6a8a2924 100644 --- a/solution/2500-2599/2584.Split the Array to Make Coprime Products/README_EN.md +++ b/solution/2500-2599/2584.Split the Array to Make Coprime Products/README_EN.md @@ -71,6 +71,8 @@ There is no valid split. +#### Python3 + ```python class Solution: def findValidSplit(self, nums: List[int]) -> int: @@ -101,6 +103,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int findValidSplit(int[] nums) { @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go func findValidSplit(nums []int) int { first := map[int]int{} diff --git a/solution/2500-2599/2585.Number of Ways to Earn Points/README.md b/solution/2500-2599/2585.Number of Ways to Earn Points/README.md index 805744359f569..3abaa43fa482b 100644 --- a/solution/2500-2599/2585.Number of Ways to Earn Points/README.md +++ b/solution/2500-2599/2585.Number of Ways to Earn Points/README.md @@ -99,6 +99,8 @@ $$ +#### Python3 + ```python class Solution: def waysToReachTarget(self, target: int, types: List[List[int]]) -> int: @@ -115,6 +117,8 @@ class Solution: return f[n][target] ``` +#### Java + ```java class Solution { public int waysToReachTarget(int target, int[][] types) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func waysToReachTarget(target int, types [][]int) int { n := len(types) @@ -184,6 +192,8 @@ func waysToReachTarget(target int, types [][]int) int { } ``` +#### TypeScript + ```ts function waysToReachTarget(target: number, types: number[][]): number { const n = types.length; diff --git a/solution/2500-2599/2585.Number of Ways to Earn Points/README_EN.md b/solution/2500-2599/2585.Number of Ways to Earn Points/README_EN.md index 575af368b5889..b558931d597db 100644 --- a/solution/2500-2599/2585.Number of Ways to Earn Points/README_EN.md +++ b/solution/2500-2599/2585.Number of Ways to Earn Points/README_EN.md @@ -103,6 +103,8 @@ The time complexity is $O(n \times target \times count)$ and the space complexit +#### Python3 + ```python class Solution: def waysToReachTarget(self, target: int, types: List[List[int]]) -> int: @@ -119,6 +121,8 @@ class Solution: return f[n][target] ``` +#### Java + ```java class Solution { public int waysToReachTarget(int target, int[][] types) { @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func waysToReachTarget(target int, types [][]int) int { n := len(types) @@ -188,6 +196,8 @@ func waysToReachTarget(target int, types [][]int) int { } ``` +#### TypeScript + ```ts function waysToReachTarget(target: number, types: number[][]): number { const n = types.length; diff --git a/solution/2500-2599/2586.Count the Number of Vowel Strings in Range/README.md b/solution/2500-2599/2586.Count the Number of Vowel Strings in Range/README.md index f733116e91158..6f7dc3cce8766 100644 --- a/solution/2500-2599/2586.Count the Number of Vowel Strings in Range/README.md +++ b/solution/2500-2599/2586.Count the Number of Vowel Strings in Range/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def vowelStrings(self, words: List[str], left: int, right: int) -> int: @@ -87,6 +89,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public int vowelStrings(String[] words, int left, int right) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func vowelStrings(words []string, left int, right int) (ans int) { check := func(c byte) bool { @@ -137,6 +145,8 @@ func vowelStrings(words []string, left int, right int) (ans int) { } ``` +#### TypeScript + ```ts function vowelStrings(words: string[], left: number, right: number): number { let ans = 0; @@ -151,6 +161,8 @@ function vowelStrings(words: string[], left: number, right: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn vowel_strings(words: Vec, left: i32, right: i32) -> i32 { diff --git a/solution/2500-2599/2586.Count the Number of Vowel Strings in Range/README_EN.md b/solution/2500-2599/2586.Count the Number of Vowel Strings in Range/README_EN.md index d64646f5266b7..37fe0e4af82b9 100644 --- a/solution/2500-2599/2586.Count the Number of Vowel Strings in Range/README_EN.md +++ b/solution/2500-2599/2586.Count the Number of Vowel Strings in Range/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(m)$, and the space complexity is $O(1)$. Where $m = ri +#### Python3 + ```python class Solution: def vowelStrings(self, words: List[str], left: int, right: int) -> int: @@ -85,6 +87,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public int vowelStrings(String[] words, int left, int right) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func vowelStrings(words []string, left int, right int) (ans int) { check := func(c byte) bool { @@ -135,6 +143,8 @@ func vowelStrings(words []string, left int, right int) (ans int) { } ``` +#### TypeScript + ```ts function vowelStrings(words: string[], left: number, right: number): number { let ans = 0; @@ -149,6 +159,8 @@ function vowelStrings(words: string[], left: number, right: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn vowel_strings(words: Vec, left: i32, right: i32) -> i32 { diff --git a/solution/2500-2599/2587.Rearrange Array to Maximize Prefix Score/README.md b/solution/2500-2599/2587.Rearrange Array to Maximize Prefix Score/README.md index d35cd0c694a9f..1d1468d1ea392 100644 --- a/solution/2500-2599/2587.Rearrange Array to Maximize Prefix Score/README.md +++ b/solution/2500-2599/2587.Rearrange Array to Maximize Prefix Score/README.md @@ -70,6 +70,8 @@ prefix = [2,5,6,5,2,2,-1] ,分数为 6 。 +#### Python3 + ```python class Solution: def maxScore(self, nums: List[int]) -> int: @@ -82,6 +84,8 @@ class Solution: return len(nums) ``` +#### Java + ```java class Solution { public int maxScore(int[] nums) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func maxScore(nums []int) int { sort.Ints(nums) @@ -132,6 +140,8 @@ func maxScore(nums []int) int { } ``` +#### TypeScript + ```ts function maxScore(nums: number[]): number { nums.sort((a, b) => a - b); @@ -147,6 +157,8 @@ function maxScore(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_score(mut nums: Vec) -> i32 { diff --git a/solution/2500-2599/2587.Rearrange Array to Maximize Prefix Score/README_EN.md b/solution/2500-2599/2587.Rearrange Array to Maximize Prefix Score/README_EN.md index b18b2ab5797ed..79cbdcea49ff9 100644 --- a/solution/2500-2599/2587.Rearrange Array to Maximize Prefix Score/README_EN.md +++ b/solution/2500-2599/2587.Rearrange Array to Maximize Prefix Score/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def maxScore(self, nums: List[int]) -> int: @@ -82,6 +84,8 @@ class Solution: return len(nums) ``` +#### Java + ```java class Solution { public int maxScore(int[] nums) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func maxScore(nums []int) int { sort.Ints(nums) @@ -132,6 +140,8 @@ func maxScore(nums []int) int { } ``` +#### TypeScript + ```ts function maxScore(nums: number[]): number { nums.sort((a, b) => a - b); @@ -147,6 +157,8 @@ function maxScore(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_score(mut nums: Vec) -> i32 { diff --git a/solution/2500-2599/2588.Count the Number of Beautiful Subarrays/README.md b/solution/2500-2599/2588.Count the Number of Beautiful Subarrays/README.md index 6a4943242955a..b22b64c660993 100644 --- a/solution/2500-2599/2588.Count the Number of Beautiful Subarrays/README.md +++ b/solution/2500-2599/2588.Count the Number of Beautiful Subarrays/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def beautifulSubarrays(self, nums: List[int]) -> int: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long beautifulSubarrays(int[] nums) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func beautifulSubarrays(nums []int) (ans int64) { cnt := map[int]int{0: 1} @@ -148,6 +156,8 @@ func beautifulSubarrays(nums []int) (ans int64) { } ``` +#### TypeScript + ```ts function beautifulSubarrays(nums: number[]): number { const cnt = new Map(); diff --git a/solution/2500-2599/2588.Count the Number of Beautiful Subarrays/README_EN.md b/solution/2500-2599/2588.Count the Number of Beautiful Subarrays/README_EN.md index 947e99e5dce6d..cd4420ece7bf7 100644 --- a/solution/2500-2599/2588.Count the Number of Beautiful Subarrays/README_EN.md +++ b/solution/2500-2599/2588.Count the Number of Beautiful Subarrays/README_EN.md @@ -87,6 +87,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def beautifulSubarrays(self, nums: List[int]) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long beautifulSubarrays(int[] nums) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func beautifulSubarrays(nums []int) (ans int64) { cnt := map[int]int{0: 1} @@ -146,6 +154,8 @@ func beautifulSubarrays(nums []int) (ans int64) { } ``` +#### TypeScript + ```ts function beautifulSubarrays(nums: number[]): number { const cnt = new Map(); diff --git a/solution/2500-2599/2589.Minimum Time to Complete All Tasks/README.md b/solution/2500-2599/2589.Minimum Time to Complete All Tasks/README.md index c8e924f9d9e7c..eca6388a195a0 100644 --- a/solution/2500-2599/2589.Minimum Time to Complete All Tasks/README.md +++ b/solution/2500-2599/2589.Minimum Time to Complete All Tasks/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def findMinimumTime(self, tasks: List[List[int]]) -> int: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findMinimumTime(int[][] tasks) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func findMinimumTime(tasks [][]int) (ans int) { sort.Slice(tasks, func(i, j int) bool { return tasks[i][1] < tasks[j][1] }) @@ -169,6 +177,8 @@ func findMinimumTime(tasks [][]int) (ans int) { } ``` +#### TypeScript + ```ts function findMinimumTime(tasks: number[][]): number { tasks.sort((a, b) => a[1] - b[1]); @@ -189,6 +199,8 @@ function findMinimumTime(tasks: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_minimum_time(tasks: Vec>) -> i32 { diff --git a/solution/2500-2599/2589.Minimum Time to Complete All Tasks/README_EN.md b/solution/2500-2599/2589.Minimum Time to Complete All Tasks/README_EN.md index a39ab1da6cef9..89099f2f05f0e 100644 --- a/solution/2500-2599/2589.Minimum Time to Complete All Tasks/README_EN.md +++ b/solution/2500-2599/2589.Minimum Time to Complete All Tasks/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(n \times \log n + n \times m)$, and the space complexi +#### Python3 + ```python class Solution: def findMinimumTime(self, tasks: List[List[int]]) -> int: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findMinimumTime(int[][] tasks) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func findMinimumTime(tasks [][]int) (ans int) { sort.Slice(tasks, func(i, j int) bool { return tasks[i][1] < tasks[j][1] }) @@ -169,6 +177,8 @@ func findMinimumTime(tasks [][]int) (ans int) { } ``` +#### TypeScript + ```ts function findMinimumTime(tasks: number[][]): number { tasks.sort((a, b) => a[1] - b[1]); @@ -189,6 +199,8 @@ function findMinimumTime(tasks: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_minimum_time(tasks: Vec>) -> i32 { diff --git a/solution/2500-2599/2590.Design a Todo List/README.md b/solution/2500-2599/2590.Design a Todo List/README.md index a3d0f64e7ea9a..9d54747b280ec 100644 --- a/solution/2500-2599/2590.Design a Todo List/README.md +++ b/solution/2500-2599/2590.Design a Todo List/README.md @@ -95,6 +95,8 @@ todoList.getAllTasks(1); // 返回["Task3", "Task1"]。用户1现在有两个未 +#### Python3 + ```python from sortedcontainers import SortedList @@ -133,6 +135,8 @@ class TodoList: # obj.completeTask(userId,taskId) ``` +#### Java + ```java class Task { int taskId; @@ -209,6 +213,8 @@ class TodoList { */ ``` +#### Rust + ```rust use std::collections::{ HashMap, HashSet }; diff --git a/solution/2500-2599/2590.Design a Todo List/README_EN.md b/solution/2500-2599/2590.Design a Todo List/README_EN.md index f03133279dccf..04b525117328a 100644 --- a/solution/2500-2599/2590.Design a Todo List/README_EN.md +++ b/solution/2500-2599/2590.Design a Todo List/README_EN.md @@ -93,6 +93,8 @@ The space complexity is $O(n)$. Where $n$ is the number of all tasks. +#### Python3 + ```python from sortedcontainers import SortedList @@ -131,6 +133,8 @@ class TodoList: # obj.completeTask(userId,taskId) ``` +#### Java + ```java class Task { int taskId; @@ -207,6 +211,8 @@ class TodoList { */ ``` +#### Rust + ```rust use std::collections::{ HashMap, HashSet }; diff --git a/solution/2500-2599/2591.Distribute Money to Maximum Children/README.md b/solution/2500-2599/2591.Distribute Money to Maximum Children/README.md index 2ba3f6f534a19..dd3b1f9e1541d 100644 --- a/solution/2500-2599/2591.Distribute Money to Maximum Children/README.md +++ b/solution/2500-2599/2591.Distribute Money to Maximum Children/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def distMoney(self, money: int, children: int) -> int: @@ -94,6 +96,8 @@ class Solution: return (money - children) // 7 ``` +#### Java + ```java class Solution { public int distMoney(int money, int children) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func distMoney(money int, children int) int { if money < children { @@ -147,6 +155,8 @@ func distMoney(money int, children int) int { } ``` +#### TypeScript + ```ts function distMoney(money: number, children: number): number { if (money < children) { @@ -162,6 +172,8 @@ function distMoney(money: number, children: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn dist_money(money: i32, children: i32) -> i32 { diff --git a/solution/2500-2599/2591.Distribute Money to Maximum Children/README_EN.md b/solution/2500-2599/2591.Distribute Money to Maximum Children/README_EN.md index 63bcfae304044..59f1e54d0b786 100644 --- a/solution/2500-2599/2591.Distribute Money to Maximum Children/README_EN.md +++ b/solution/2500-2599/2591.Distribute Money to Maximum Children/README_EN.md @@ -81,6 +81,8 @@ Time complexity $O(1)$, space complexity $O(1)$. +#### Python3 + ```python class Solution: def distMoney(self, money: int, children: int) -> int: @@ -94,6 +96,8 @@ class Solution: return (money - children) // 7 ``` +#### Java + ```java class Solution { public int distMoney(int money, int children) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func distMoney(money int, children int) int { if money < children { @@ -147,6 +155,8 @@ func distMoney(money int, children int) int { } ``` +#### TypeScript + ```ts function distMoney(money: number, children: number): number { if (money < children) { @@ -162,6 +172,8 @@ function distMoney(money: number, children: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn dist_money(money: i32, children: i32) -> i32 { diff --git a/solution/2500-2599/2592.Maximize Greatness of an Array/README.md b/solution/2500-2599/2592.Maximize Greatness of an Array/README.md index 9ee6337b986ec..fb8c7c323157a 100644 --- a/solution/2500-2599/2592.Maximize Greatness of an Array/README.md +++ b/solution/2500-2599/2592.Maximize Greatness of an Array/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def maximizeGreatness(self, nums: List[int]) -> int: @@ -81,6 +83,8 @@ class Solution: return i ``` +#### Java + ```java class Solution { public int maximizeGreatness(int[] nums) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func maximizeGreatness(nums []int) int { sort.Ints(nums) @@ -123,6 +131,8 @@ func maximizeGreatness(nums []int) int { } ``` +#### TypeScript + ```ts function maximizeGreatness(nums: number[]): number { nums.sort((a, b) => a - b); diff --git a/solution/2500-2599/2592.Maximize Greatness of an Array/README_EN.md b/solution/2500-2599/2592.Maximize Greatness of an Array/README_EN.md index 0770741b14580..7c19f3a163887 100644 --- a/solution/2500-2599/2592.Maximize Greatness of an Array/README_EN.md +++ b/solution/2500-2599/2592.Maximize Greatness of an Array/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def maximizeGreatness(self, nums: List[int]) -> int: @@ -81,6 +83,8 @@ class Solution: return i ``` +#### Java + ```java class Solution { public int maximizeGreatness(int[] nums) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func maximizeGreatness(nums []int) int { sort.Ints(nums) @@ -123,6 +131,8 @@ func maximizeGreatness(nums []int) int { } ``` +#### TypeScript + ```ts function maximizeGreatness(nums: number[]): number { nums.sort((a, b) => a - b); diff --git a/solution/2500-2599/2593.Find Score of an Array After Marking All Elements/README.md b/solution/2500-2599/2593.Find Score of an Array After Marking All Elements/README.md index a9c954dcb5548..d0711bef2109f 100644 --- a/solution/2500-2599/2593.Find Score of an Array After Marking All Elements/README.md +++ b/solution/2500-2599/2593.Find Score of an Array After Marking All Elements/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def findScore(self, nums: List[int]) -> int: @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long findScore(int[] nums) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go func findScore(nums []int) (ans int64) { h := hp{} @@ -201,6 +209,8 @@ func (h *hp) Push(v any) { *h = append(*h, v.(pair)) } func (h *hp) Pop() any { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; return v } ``` +#### TypeScript + ```ts interface pair { x: number; @@ -258,6 +268,8 @@ function findScore(nums: number[]): number { +#### Python3 + ```python class Solution: def findScore(self, nums: List[int]) -> int: @@ -272,6 +284,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long findScore(int[] nums) { @@ -295,6 +309,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -318,6 +334,8 @@ public: }; ``` +#### Go + ```go func findScore(nums []int) (ans int64) { n := len(nums) @@ -340,6 +358,8 @@ func findScore(nums []int) (ans int64) { } ``` +#### TypeScript + ```ts function findScore(nums: number[]): number { const n = nums.length; diff --git a/solution/2500-2599/2593.Find Score of an Array After Marking All Elements/README_EN.md b/solution/2500-2599/2593.Find Score of an Array After Marking All Elements/README_EN.md index 176d7160dbecf..1893b2388926f 100644 --- a/solution/2500-2599/2593.Find Score of an Array After Marking All Elements/README_EN.md +++ b/solution/2500-2599/2593.Find Score of an Array After Marking All Elements/README_EN.md @@ -85,6 +85,8 @@ The time complexity is $O(n \times \log n)$ and the space complexity is $O(n)$, +#### Python3 + ```python class Solution: def findScore(self, nums: List[int]) -> int: @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long findScore(int[] nums) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go func findScore(nums []int) (ans int64) { h := hp{} @@ -201,6 +209,8 @@ func (h *hp) Push(v any) { *h = append(*h, v.(pair)) } func (h *hp) Pop() any { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; return v } ``` +#### TypeScript + ```ts interface pair { x: number; @@ -258,6 +268,8 @@ The time complexity is $O(n \times \log n)$ and the space complexity is $O(n)$, +#### Python3 + ```python class Solution: def findScore(self, nums: List[int]) -> int: @@ -272,6 +284,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long findScore(int[] nums) { @@ -295,6 +309,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -318,6 +334,8 @@ public: }; ``` +#### Go + ```go func findScore(nums []int) (ans int64) { n := len(nums) @@ -340,6 +358,8 @@ func findScore(nums []int) (ans int64) { } ``` +#### TypeScript + ```ts function findScore(nums: number[]): number { const n = nums.length; diff --git a/solution/2500-2599/2594.Minimum Time to Repair Cars/README.md b/solution/2500-2599/2594.Minimum Time to Repair Cars/README.md index 473ef8744fc24..f59da5e89ade9 100644 --- a/solution/2500-2599/2594.Minimum Time to Repair Cars/README.md +++ b/solution/2500-2599/2594.Minimum Time to Repair Cars/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def repairCars(self, ranks: List[int], cars: int) -> int: @@ -91,6 +93,8 @@ class Solution: return bisect_left(range(ranks[0] * cars * cars), True, key=check) ``` +#### Java + ```java class Solution { public long repairCars(int[] ranks, int cars) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func repairCars(ranks []int, cars int) int64 { return int64(sort.Search(ranks[0]*cars*cars, func(t int) bool { @@ -146,6 +154,8 @@ func repairCars(ranks []int, cars int) int64 { } ``` +#### TypeScript + ```ts function repairCars(ranks: number[], cars: number): number { let left = 0; diff --git a/solution/2500-2599/2594.Minimum Time to Repair Cars/README_EN.md b/solution/2500-2599/2594.Minimum Time to Repair Cars/README_EN.md index b3151b3b9a188..1f09915a15d5a 100644 --- a/solution/2500-2599/2594.Minimum Time to Repair Cars/README_EN.md +++ b/solution/2500-2599/2594.Minimum Time to Repair Cars/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(n \times \log M)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def repairCars(self, ranks: List[int], cars: int) -> int: @@ -89,6 +91,8 @@ class Solution: return bisect_left(range(ranks[0] * cars * cars), True, key=check) ``` +#### Java + ```java class Solution { public long repairCars(int[] ranks, int cars) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func repairCars(ranks []int, cars int) int64 { return int64(sort.Search(ranks[0]*cars*cars, func(t int) bool { @@ -144,6 +152,8 @@ func repairCars(ranks []int, cars int) int64 { } ``` +#### TypeScript + ```ts function repairCars(ranks: number[], cars: number): number { let left = 0; diff --git a/solution/2500-2599/2595.Number of Even and Odd Bits/README.md b/solution/2500-2599/2595.Number of Even and Odd Bits/README.md index f5a93615e7008..0edd41cc945d3 100644 --- a/solution/2500-2599/2595.Number of Even and Odd Bits/README.md +++ b/solution/2500-2599/2595.Number of Even and Odd Bits/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def evenOddBit(self, n: int) -> List[int]: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] evenOddBit(int n) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func evenOddBit(n int) []int { ans := make([]int, 2) @@ -115,6 +123,8 @@ func evenOddBit(n int) []int { } ``` +#### TypeScript + ```ts function evenOddBit(n: number): number[] { const ans = new Array(2).fill(0); @@ -125,6 +135,8 @@ function evenOddBit(n: number): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn even_odd_bit(mut n: i32) -> Vec { @@ -153,6 +165,8 @@ impl Solution { +#### Python3 + ```python class Solution: def evenOddBit(self, n: int) -> List[int]: @@ -162,6 +176,8 @@ class Solution: return [even, odd] ``` +#### Java + ```java class Solution { public int[] evenOddBit(int n) { @@ -173,6 +189,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -185,6 +203,8 @@ public: }; ``` +#### Go + ```go func evenOddBit(n int) []int { mask := 0x5555 @@ -194,6 +214,8 @@ func evenOddBit(n int) []int { } ``` +#### TypeScript + ```ts function evenOddBit(n: number): number[] { const mask = 0x5555; @@ -212,6 +234,8 @@ function bitCount(i: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn even_odd_bit(n: i32) -> Vec { diff --git a/solution/2500-2599/2595.Number of Even and Odd Bits/README_EN.md b/solution/2500-2599/2595.Number of Even and Odd Bits/README_EN.md index 66c61421b0a07..d64b537961ea2 100644 --- a/solution/2500-2599/2595.Number of Even and Odd Bits/README_EN.md +++ b/solution/2500-2599/2595.Number of Even and Odd Bits/README_EN.md @@ -68,6 +68,8 @@ The time complexity is $O(\log n)$ and the space complexity is $O(1)$. Where $n$ +#### Python3 + ```python class Solution: def evenOddBit(self, n: int) -> List[int]: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] evenOddBit(int n) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func evenOddBit(n int) []int { ans := make([]int, 2) @@ -115,6 +123,8 @@ func evenOddBit(n int) []int { } ``` +#### TypeScript + ```ts function evenOddBit(n: number): number[] { const ans = new Array(2).fill(0); @@ -125,6 +135,8 @@ function evenOddBit(n: number): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn even_odd_bit(mut n: i32) -> Vec { @@ -153,6 +165,8 @@ impl Solution { +#### Python3 + ```python class Solution: def evenOddBit(self, n: int) -> List[int]: @@ -162,6 +176,8 @@ class Solution: return [even, odd] ``` +#### Java + ```java class Solution { public int[] evenOddBit(int n) { @@ -173,6 +189,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -185,6 +203,8 @@ public: }; ``` +#### Go + ```go func evenOddBit(n int) []int { mask := 0x5555 @@ -194,6 +214,8 @@ func evenOddBit(n int) []int { } ``` +#### TypeScript + ```ts function evenOddBit(n: number): number[] { const mask = 0x5555; @@ -212,6 +234,8 @@ function bitCount(i: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn even_odd_bit(n: i32) -> Vec { diff --git a/solution/2500-2599/2596.Check Knight Tour Configuration/README.md b/solution/2500-2599/2596.Check Knight Tour Configuration/README.md index e3b5c0c6da9eb..f4786763e53ef 100644 --- a/solution/2500-2599/2596.Check Knight Tour Configuration/README.md +++ b/solution/2500-2599/2596.Check Knight Tour Configuration/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def checkValidGrid(self, grid: List[List[int]]) -> bool: @@ -94,6 +96,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean checkValidGrid(int[][] grid) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func checkValidGrid(grid [][]int) bool { if grid[0][0] != 0 { @@ -184,6 +192,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function checkValidGrid(grid: number[][]): boolean { if (grid[0][0] !== 0) { diff --git a/solution/2500-2599/2596.Check Knight Tour Configuration/README_EN.md b/solution/2500-2599/2596.Check Knight Tour Configuration/README_EN.md index e393f8ada3b7e..832c843a9eb15 100644 --- a/solution/2500-2599/2596.Check Knight Tour Configuration/README_EN.md +++ b/solution/2500-2599/2596.Check Knight Tour Configuration/README_EN.md @@ -73,6 +73,8 @@ The time complexity is $O(n^2)$ and the space complexity is $O(n^2)$, where $n$ +#### Python3 + ```python class Solution: def checkValidGrid(self, grid: List[List[int]]) -> bool: @@ -91,6 +93,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean checkValidGrid(int[][] grid) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func checkValidGrid(grid [][]int) bool { if grid[0][0] != 0 { @@ -181,6 +189,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function checkValidGrid(grid: number[][]): boolean { if (grid[0][0] !== 0) { diff --git a/solution/2500-2599/2597.The Number of Beautiful Subsets/README.md b/solution/2500-2599/2597.The Number of Beautiful Subsets/README.md index 54fe3b3bbf31e..5eb293e05828e 100644 --- a/solution/2500-2599/2597.The Number of Beautiful Subsets/README.md +++ b/solution/2500-2599/2597.The Number of Beautiful Subsets/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def beautifulSubsets(self, nums: List[int], k: int) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] nums; @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func beautifulSubsets(nums []int, k int) int { ans := -1 @@ -181,6 +189,8 @@ func beautifulSubsets(nums []int, k int) int { } ``` +#### TypeScript + ```ts function beautifulSubsets(nums: number[], k: number): number { let ans: number = -1; diff --git a/solution/2500-2599/2597.The Number of Beautiful Subsets/README_EN.md b/solution/2500-2599/2597.The Number of Beautiful Subsets/README_EN.md index 14922bc158847..174bbcb250cf8 100644 --- a/solution/2500-2599/2597.The Number of Beautiful Subsets/README_EN.md +++ b/solution/2500-2599/2597.The Number of Beautiful Subsets/README_EN.md @@ -77,6 +77,8 @@ Time complexity $O(2^n)$, space complexity $O(n)$, where $n$ is the length of th +#### Python3 + ```python class Solution: def beautifulSubsets(self, nums: List[int], k: int) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] nums; @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func beautifulSubsets(nums []int, k int) int { ans := -1 @@ -181,6 +189,8 @@ func beautifulSubsets(nums []int, k int) int { } ``` +#### TypeScript + ```ts function beautifulSubsets(nums: number[], k: number): number { let ans: number = -1; diff --git a/solution/2500-2599/2598.Smallest Missing Non-negative Integer After Operations/README.md b/solution/2500-2599/2598.Smallest Missing Non-negative Integer After Operations/README.md index 9462260839e01..037fdfea29efa 100644 --- a/solution/2500-2599/2598.Smallest Missing Non-negative Integer After Operations/README.md +++ b/solution/2500-2599/2598.Smallest Missing Non-negative Integer After Operations/README.md @@ -84,6 +84,8 @@ nums 的 MEX 是 2 。可以证明 2 是可以取到的最大 MEX 。 +#### Python3 + ```python class Solution: def findSmallestInteger(self, nums: List[int], value: int) -> int: @@ -94,6 +96,8 @@ class Solution: cnt[i % value] -= 1 ``` +#### Java + ```java class Solution { public int findSmallestInteger(int[] nums, int value) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func findSmallestInteger(nums []int, value int) int { cnt := make([]int, value) @@ -143,6 +151,8 @@ func findSmallestInteger(nums []int, value int) int { } ``` +#### TypeScript + ```ts function findSmallestInteger(nums: number[], value: number): number { const cnt: number[] = new Array(value).fill(0); diff --git a/solution/2500-2599/2598.Smallest Missing Non-negative Integer After Operations/README_EN.md b/solution/2500-2599/2598.Smallest Missing Non-negative Integer After Operations/README_EN.md index 3902292623164..7f72face7dfb5 100644 --- a/solution/2500-2599/2598.Smallest Missing Non-negative Integer After Operations/README_EN.md +++ b/solution/2500-2599/2598.Smallest Missing Non-negative Integer After Operations/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n)$ and the space complexity is $O(value)$. Where $n$ +#### Python3 + ```python class Solution: def findSmallestInteger(self, nums: List[int], value: int) -> int: @@ -94,6 +96,8 @@ class Solution: cnt[i % value] -= 1 ``` +#### Java + ```java class Solution { public int findSmallestInteger(int[] nums, int value) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func findSmallestInteger(nums []int, value int) int { cnt := make([]int, value) @@ -143,6 +151,8 @@ func findSmallestInteger(nums []int, value int) int { } ``` +#### TypeScript + ```ts function findSmallestInteger(nums: number[], value: number): number { const cnt: number[] = new Array(value).fill(0); diff --git a/solution/2500-2599/2599.Make the Prefix Sum Non-negative/README.md b/solution/2500-2599/2599.Make the Prefix Sum Non-negative/README.md index 100f30fc3d304..07c55d10ed6a9 100644 --- a/solution/2500-2599/2599.Make the Prefix Sum Non-negative/README.md +++ b/solution/2500-2599/2599.Make the Prefix Sum Non-negative/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def makePrefSumNonNegative(self, nums: List[int]) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int makePrefSumNonNegative(int[] nums) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func makePrefSumNonNegative(nums []int) (ans int) { pq := hp{} @@ -161,6 +169,8 @@ func (h *hp) Pop() any { } ``` +#### TypeScript + ```ts function makePrefSumNonNegative(nums: number[]): number { const pq = new MinPriorityQueue(); diff --git a/solution/2500-2599/2599.Make the Prefix Sum Non-negative/README_EN.md b/solution/2500-2599/2599.Make the Prefix Sum Non-negative/README_EN.md index 118641df534db..5d03a107f0069 100644 --- a/solution/2500-2599/2599.Make the Prefix Sum Non-negative/README_EN.md +++ b/solution/2500-2599/2599.Make the Prefix Sum Non-negative/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$, +#### Python3 + ```python class Solution: def makePrefSumNonNegative(self, nums: List[int]) -> int: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int makePrefSumNonNegative(int[] nums) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func makePrefSumNonNegative(nums []int) (ans int) { pq := hp{} @@ -159,6 +167,8 @@ func (h *hp) Pop() any { } ``` +#### TypeScript + ```ts function makePrefSumNonNegative(nums: number[]): number { const pq = new MinPriorityQueue(); diff --git a/solution/2600-2699/2600.K Items With the Maximum Sum/README.md b/solution/2600-2699/2600.K Items With the Maximum Sum/README.md index f87fd33520ffc..2c8fd486de48f 100644 --- a/solution/2600-2699/2600.K Items With the Maximum Sum/README.md +++ b/solution/2600-2699/2600.K Items With the Maximum Sum/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def kItemsWithMaximumSum( @@ -93,6 +95,8 @@ class Solution: return numOnes - (k - numOnes - numZeros) ``` +#### Java + ```java class Solution { public int kItemsWithMaximumSum(int numOnes, int numZeros, int numNegOnes, int k) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func kItemsWithMaximumSum(numOnes int, numZeros int, numNegOnes int, k int) int { if numOnes >= k { @@ -134,6 +142,8 @@ func kItemsWithMaximumSum(numOnes int, numZeros int, numNegOnes int, k int) int } ``` +#### TypeScript + ```ts function kItemsWithMaximumSum( numOnes: number, @@ -151,6 +161,8 @@ function kItemsWithMaximumSum( } ``` +#### Rust + ```rust impl Solution { pub fn k_items_with_maximum_sum( @@ -172,6 +184,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int KItemsWithMaximumSum(int numOnes, int numZeros, int numNegOnes, int k) { diff --git a/solution/2600-2699/2600.K Items With the Maximum Sum/README_EN.md b/solution/2600-2699/2600.K Items With the Maximum Sum/README_EN.md index a93826f6d4d57..1d3865f3b551c 100644 --- a/solution/2600-2699/2600.K Items With the Maximum Sum/README_EN.md +++ b/solution/2600-2699/2600.K Items With the Maximum Sum/README_EN.md @@ -70,6 +70,8 @@ It can be proven that 3 is the maximum possible sum. +#### Python3 + ```python class Solution: def kItemsWithMaximumSum( @@ -82,6 +84,8 @@ class Solution: return numOnes - (k - numOnes - numZeros) ``` +#### Java + ```java class Solution { public int kItemsWithMaximumSum(int numOnes, int numZeros, int numNegOnes, int k) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func kItemsWithMaximumSum(numOnes int, numZeros int, numNegOnes int, k int) int { if numOnes >= k { @@ -123,6 +131,8 @@ func kItemsWithMaximumSum(numOnes int, numZeros int, numNegOnes int, k int) int } ``` +#### TypeScript + ```ts function kItemsWithMaximumSum( numOnes: number, @@ -140,6 +150,8 @@ function kItemsWithMaximumSum( } ``` +#### Rust + ```rust impl Solution { pub fn k_items_with_maximum_sum( @@ -161,6 +173,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int KItemsWithMaximumSum(int numOnes, int numZeros, int numNegOnes, int k) { diff --git a/solution/2600-2699/2601.Prime Subtraction Operation/README.md b/solution/2600-2699/2601.Prime Subtraction Operation/README.md index fdc9638444478..b6f011b5d6c23 100644 --- a/solution/2600-2699/2601.Prime Subtraction Operation/README.md +++ b/solution/2600-2699/2601.Prime Subtraction Operation/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def primeSubOperation(self, nums: List[int]) -> bool: @@ -110,6 +112,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean primeSubOperation(int[] nums) { @@ -155,6 +159,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go func primeSubOperation(nums []int) bool { p := []int{} @@ -217,6 +225,8 @@ func primeSubOperation(nums []int) bool { } ``` +#### TypeScript + ```ts function primeSubOperation(nums: number[]): boolean { const p: number[] = []; diff --git a/solution/2600-2699/2601.Prime Subtraction Operation/README_EN.md b/solution/2600-2699/2601.Prime Subtraction Operation/README_EN.md index 4f624f268f4d5..07438db2f7fb5 100644 --- a/solution/2600-2699/2601.Prime Subtraction Operation/README_EN.md +++ b/solution/2600-2699/2601.Prime Subtraction Operation/README_EN.md @@ -85,6 +85,8 @@ The time complexity is $O(n \log n)$ and the space complexity is $O(n)$. where $ +#### Python3 + ```python class Solution: def primeSubOperation(self, nums: List[int]) -> bool: @@ -107,6 +109,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean primeSubOperation(int[] nums) { @@ -152,6 +156,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -185,6 +191,8 @@ public: }; ``` +#### Go + ```go func primeSubOperation(nums []int) bool { p := []int{} @@ -214,6 +222,8 @@ func primeSubOperation(nums []int) bool { } ``` +#### TypeScript + ```ts function primeSubOperation(nums: number[]): boolean { const p: number[] = []; diff --git a/solution/2600-2699/2602.Minimum Operations to Make All Array Elements Equal/README.md b/solution/2600-2699/2602.Minimum Operations to Make All Array Elements Equal/README.md index da32b7366dffa..b142d4b5559ae 100644 --- a/solution/2600-2699/2602.Minimum Operations to Make All Array Elements Equal/README.md +++ b/solution/2600-2699/2602.Minimum Operations to Make All Array Elements Equal/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int], queries: List[int]) -> List[int]: @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List minOperations(int[] nums, int[] queries) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int, queries []int) (ans []int64) { sort.Ints(nums) @@ -184,6 +192,8 @@ func minOperations(nums []int, queries []int) (ans []int64) { } ``` +#### TypeScript + ```ts function minOperations(nums: number[], queries: number[]): number[] { nums.sort((a, b) => a - b); diff --git a/solution/2600-2699/2602.Minimum Operations to Make All Array Elements Equal/README_EN.md b/solution/2600-2699/2602.Minimum Operations to Make All Array Elements Equal/README_EN.md index 79f4bf3eb772b..4908b44679da0 100644 --- a/solution/2600-2699/2602.Minimum Operations to Make All Array Elements Equal/README_EN.md +++ b/solution/2600-2699/2602.Minimum Operations to Make All Array Elements Equal/README_EN.md @@ -92,6 +92,8 @@ Time complexity $O(n \times \log n)$, space complexity $O(n)$, where $n$ is the +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int], queries: List[int]) -> List[int]: @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List minOperations(int[] nums, int[] queries) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int, queries []int) (ans []int64) { sort.Ints(nums) @@ -184,6 +192,8 @@ func minOperations(nums []int, queries []int) (ans []int64) { } ``` +#### TypeScript + ```ts function minOperations(nums: number[], queries: number[]): number[] { nums.sort((a, b) => a - b); diff --git a/solution/2600-2699/2603.Collect Coins in a Tree/README.md b/solution/2600-2699/2603.Collect Coins in a Tree/README.md index 0f6c7fb9fb616..96edea16dea00 100644 --- a/solution/2600-2699/2603.Collect Coins in a Tree/README.md +++ b/solution/2600-2699/2603.Collect Coins in a Tree/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python class Solution: def collectTheCoins(self, coins: List[int], edges: List[List[int]]) -> int: @@ -120,6 +122,8 @@ class Solution: return sum(len(g[a]) > 0 and len(g[b]) > 0 for a, b in edges) * 2 ``` +#### Java + ```java class Solution { public int collectTheCoins(int[] coins, int[][] edges) { @@ -173,6 +177,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -227,6 +233,8 @@ public: }; ``` +#### Go + ```go func collectTheCoins(coins []int, edges [][]int) int { n := len(coins) @@ -281,6 +289,8 @@ func collectTheCoins(coins []int, edges [][]int) int { } ``` +#### TypeScript + ```ts function collectTheCoins(coins: number[], edges: number[][]): number { const n = coins.length; diff --git a/solution/2600-2699/2603.Collect Coins in a Tree/README_EN.md b/solution/2600-2699/2603.Collect Coins in a Tree/README_EN.md index 80826513236dd..4b79392715515 100644 --- a/solution/2600-2699/2603.Collect Coins in a Tree/README_EN.md +++ b/solution/2600-2699/2603.Collect Coins in a Tree/README_EN.md @@ -91,6 +91,8 @@ Similar problems: +#### Python3 + ```python class Solution: def collectTheCoins(self, coins: List[int], edges: List[List[int]]) -> int: @@ -116,6 +118,8 @@ class Solution: return sum(len(g[a]) > 0 and len(g[b]) > 0 for a, b in edges) * 2 ``` +#### Java + ```java class Solution { public int collectTheCoins(int[] coins, int[][] edges) { @@ -169,6 +173,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -223,6 +229,8 @@ public: }; ``` +#### Go + ```go func collectTheCoins(coins []int, edges [][]int) int { n := len(coins) @@ -277,6 +285,8 @@ func collectTheCoins(coins []int, edges [][]int) int { } ``` +#### TypeScript + ```ts function collectTheCoins(coins: number[], edges: number[][]): number { const n = coins.length; diff --git a/solution/2600-2699/2604.Minimum Time to Eat All Grains/README.md b/solution/2600-2699/2604.Minimum Time to Eat All Grains/README.md index d2db45692ab32..ed16a1522bd05 100644 --- a/solution/2600-2699/2604.Minimum Time to Eat All Grains/README.md +++ b/solution/2600-2699/2604.Minimum Time to Eat All Grains/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def minimumTime(self, hens: List[int], grains: List[int]) -> int: @@ -116,6 +118,8 @@ class Solution: return bisect_left(range(r), True, key=check) ``` +#### Java + ```java class Solution { private int[] hens; @@ -170,6 +174,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -218,6 +224,8 @@ public: }; ``` +#### Go + ```go func minimumTime(hens []int, grains []int) int { sort.Ints(hens) @@ -269,6 +277,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function minimumTime(hens: number[], grains: number[]): number { hens.sort((a, b) => a - b); diff --git a/solution/2600-2699/2604.Minimum Time to Eat All Grains/README_EN.md b/solution/2600-2699/2604.Minimum Time to Eat All Grains/README_EN.md index b23b980e2bcd6..beff14fcdec86 100644 --- a/solution/2600-2699/2604.Minimum Time to Eat All Grains/README_EN.md +++ b/solution/2600-2699/2604.Minimum Time to Eat All Grains/README_EN.md @@ -84,6 +84,8 @@ Time complexity $O(n \times \log n + m \times \log m + (m + n) \times \log U)$, +#### Python3 + ```python class Solution: def minimumTime(self, hens: List[int], grains: List[int]) -> int: @@ -113,6 +115,8 @@ class Solution: return bisect_left(range(r), True, key=check) ``` +#### Java + ```java class Solution { private int[] hens; @@ -167,6 +171,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -215,6 +221,8 @@ public: }; ``` +#### Go + ```go func minimumTime(hens []int, grains []int) int { sort.Ints(hens) @@ -266,6 +274,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function minimumTime(hens: number[], grains: number[]): number { hens.sort((a, b) => a - b); diff --git a/solution/2600-2699/2605.Form Smallest Number From Two Digit Arrays/README.md b/solution/2600-2699/2605.Form Smallest Number From Two Digit Arrays/README.md index 6f83a469745e4..c49cb2c70b613 100644 --- a/solution/2600-2699/2605.Form Smallest Number From Two Digit Arrays/README.md +++ b/solution/2600-2699/2605.Form Smallest Number From Two Digit Arrays/README.md @@ -62,6 +62,8 @@ tags: +#### Python3 + ```python class Solution: def minNumber(self, nums1: List[int], nums2: List[int]) -> int: @@ -75,6 +77,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minNumber(int[] nums1, int[] nums2) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func minNumber(nums1 []int, nums2 []int) int { ans := 100 @@ -128,6 +136,8 @@ func minNumber(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function minNumber(nums1: number[], nums2: number[]): number { let ans = 100; @@ -144,6 +154,8 @@ function minNumber(nums1: number[], nums2: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_number(nums1: Vec, nums2: Vec) -> i32 { @@ -178,6 +190,8 @@ impl Solution { +#### Python3 + ```python class Solution: def minNumber(self, nums1: List[int], nums2: List[int]) -> int: @@ -188,6 +202,8 @@ class Solution: return min(a * 10 + b, b * 10 + a) ``` +#### Java + ```java class Solution { public int minNumber(int[] nums1, int[] nums2) { @@ -216,6 +232,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -245,6 +263,8 @@ public: }; ``` +#### Go + ```go func minNumber(nums1 []int, nums2 []int) int { s1 := [10]bool{} @@ -271,6 +291,8 @@ func minNumber(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function minNumber(nums1: number[], nums2: number[]): number { const s1: boolean[] = new Array(10).fill(false); @@ -298,6 +320,8 @@ function minNumber(nums1: number[], nums2: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -353,6 +377,8 @@ impl Solution { +#### Python3 + ```python class Solution: def minNumber(self, nums1: List[int], nums2: List[int]) -> int: @@ -369,6 +395,8 @@ class Solution: return min(a * 10 + b, b * 10 + a) ``` +#### Java + ```java class Solution { public int minNumber(int[] nums1, int[] nums2) { @@ -390,6 +418,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -412,6 +442,8 @@ public: }; ``` +#### Go + ```go func minNumber(nums1 []int, nums2 []int) int { var mask1, mask2 uint @@ -429,6 +461,8 @@ func minNumber(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function minNumber(nums1: number[], nums2: number[]): number { let mask1: number = 0; diff --git a/solution/2600-2699/2605.Form Smallest Number From Two Digit Arrays/README_EN.md b/solution/2600-2699/2605.Form Smallest Number From Two Digit Arrays/README_EN.md index f073ebb784d7a..51f799582bc03 100644 --- a/solution/2600-2699/2605.Form Smallest Number From Two Digit Arrays/README_EN.md +++ b/solution/2600-2699/2605.Form Smallest Number From Two Digit Arrays/README_EN.md @@ -62,6 +62,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(1)$, wher +#### Python3 + ```python class Solution: def minNumber(self, nums1: List[int], nums2: List[int]) -> int: @@ -75,6 +77,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minNumber(int[] nums1, int[] nums2) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func minNumber(nums1 []int, nums2 []int) int { ans := 100 @@ -128,6 +136,8 @@ func minNumber(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function minNumber(nums1: number[], nums2: number[]): number { let ans = 100; @@ -144,6 +154,8 @@ function minNumber(nums1: number[], nums2: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_number(nums1: Vec, nums2: Vec) -> i32 { @@ -178,6 +190,8 @@ The time complexity is $(m + n)$, and the space complexity is $O(C)$. Where $m$ +#### Python3 + ```python class Solution: def minNumber(self, nums1: List[int], nums2: List[int]) -> int: @@ -188,6 +202,8 @@ class Solution: return min(a * 10 + b, b * 10 + a) ``` +#### Java + ```java class Solution { public int minNumber(int[] nums1, int[] nums2) { @@ -216,6 +232,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -245,6 +263,8 @@ public: }; ``` +#### Go + ```go func minNumber(nums1 []int, nums2 []int) int { s1 := [10]bool{} @@ -271,6 +291,8 @@ func minNumber(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function minNumber(nums1: number[], nums2: number[]): number { const s1: boolean[] = new Array(10).fill(false); @@ -298,6 +320,8 @@ function minNumber(nums1: number[], nums2: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -353,6 +377,8 @@ The time complexity is $O(m + n)$, and the space complexity is $O(1)$. Where $m$ +#### Python3 + ```python class Solution: def minNumber(self, nums1: List[int], nums2: List[int]) -> int: @@ -369,6 +395,8 @@ class Solution: return min(a * 10 + b, b * 10 + a) ``` +#### Java + ```java class Solution { public int minNumber(int[] nums1, int[] nums2) { @@ -390,6 +418,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -412,6 +442,8 @@ public: }; ``` +#### Go + ```go func minNumber(nums1 []int, nums2 []int) int { var mask1, mask2 uint @@ -429,6 +461,8 @@ func minNumber(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function minNumber(nums1: number[], nums2: number[]): number { let mask1: number = 0; diff --git a/solution/2600-2699/2606.Find the Substring With Maximum Cost/README.md b/solution/2600-2699/2606.Find the Substring With Maximum Cost/README.md index ba1a79357effe..860799cf6678e 100644 --- a/solution/2600-2699/2606.Find the Substring With Maximum Cost/README.md +++ b/solution/2600-2699/2606.Find the Substring With Maximum Cost/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def maximumCostSubstring(self, s: str, chars: str, vals: List[int]) -> int: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumCostSubstring(String s, String chars, int[] vals) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func maximumCostSubstring(s string, chars string, vals []int) (ans int) { d := [26]int{} @@ -168,6 +176,8 @@ func maximumCostSubstring(s string, chars string, vals []int) (ans int) { } ``` +#### TypeScript + ```ts function maximumCostSubstring(s: string, chars: string, vals: number[]): number { const d: number[] = Array.from({ length: 26 }, (_, i) => i + 1); @@ -202,6 +212,8 @@ function maximumCostSubstring(s: string, chars: string, vals: number[]): number +#### Python3 + ```python class Solution: def maximumCostSubstring(self, s: str, chars: str, vals: List[int]) -> int: @@ -214,6 +226,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumCostSubstring(String s, String chars, int[] vals) { @@ -237,6 +251,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -258,6 +274,8 @@ public: }; ``` +#### Go + ```go func maximumCostSubstring(s string, chars string, vals []int) (ans int) { d := [26]int{} @@ -277,6 +295,8 @@ func maximumCostSubstring(s string, chars string, vals []int) (ans int) { } ``` +#### TypeScript + ```ts function maximumCostSubstring(s: string, chars: string, vals: number[]): number { const d: number[] = Array.from({ length: 26 }, (_, i) => i + 1); diff --git a/solution/2600-2699/2606.Find the Substring With Maximum Cost/README_EN.md b/solution/2600-2699/2606.Find the Substring With Maximum Cost/README_EN.md index 80321d3333e21..ef23a93399600 100644 --- a/solution/2600-2699/2606.Find the Substring With Maximum Cost/README_EN.md +++ b/solution/2600-2699/2606.Find the Substring With Maximum Cost/README_EN.md @@ -89,6 +89,8 @@ The time complexity is $O(n)$, and the space complexity is $O(C)$. Where $n$ is +#### Python3 + ```python class Solution: def maximumCostSubstring(self, s: str, chars: str, vals: List[int]) -> int: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumCostSubstring(String s, String chars, int[] vals) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func maximumCostSubstring(s string, chars string, vals []int) (ans int) { d := [26]int{} @@ -168,6 +176,8 @@ func maximumCostSubstring(s string, chars string, vals []int) (ans int) { } ``` +#### TypeScript + ```ts function maximumCostSubstring(s: string, chars: string, vals: number[]): number { const d: number[] = Array.from({ length: 26 }, (_, i) => i + 1); @@ -202,6 +212,8 @@ The time complexity is $O(n)$, and the space complexity is $O(C)$. Where $n$ is +#### Python3 + ```python class Solution: def maximumCostSubstring(self, s: str, chars: str, vals: List[int]) -> int: @@ -214,6 +226,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumCostSubstring(String s, String chars, int[] vals) { @@ -237,6 +251,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -258,6 +274,8 @@ public: }; ``` +#### Go + ```go func maximumCostSubstring(s string, chars string, vals []int) (ans int) { d := [26]int{} @@ -277,6 +295,8 @@ func maximumCostSubstring(s string, chars string, vals []int) (ans int) { } ``` +#### TypeScript + ```ts function maximumCostSubstring(s: string, chars: string, vals: number[]): number { const d: number[] = Array.from({ length: 26 }, (_, i) => i + 1); diff --git a/solution/2600-2699/2607.Make K-Subarray Sums Equal/README.md b/solution/2600-2699/2607.Make K-Subarray Sums Equal/README.md index 9fda1a5af4fa7..d0e8a21a6fe60 100644 --- a/solution/2600-2699/2607.Make K-Subarray Sums Equal/README.md +++ b/solution/2600-2699/2607.Make K-Subarray Sums Equal/README.md @@ -106,6 +106,8 @@ $$ +#### Python3 + ```python class Solution: def makeSubKSumEqual(self, arr: List[int], k: int) -> int: @@ -119,6 +121,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long makeSubKSumEqual(int[] arr, int k) { @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func makeSubKSumEqual(arr []int, k int) (ans int64) { n := len(arr) @@ -201,6 +209,8 @@ func gcd(a, b int) int { } ``` +#### TypeScript + ```ts function makeSubKSumEqual(arr: number[], k: number): number { const n = arr.length; diff --git a/solution/2600-2699/2607.Make K-Subarray Sums Equal/README_EN.md b/solution/2600-2699/2607.Make K-Subarray Sums Equal/README_EN.md index 9aabfd9288ad9..ce1d249486a98 100644 --- a/solution/2600-2699/2607.Make K-Subarray Sums Equal/README_EN.md +++ b/solution/2600-2699/2607.Make K-Subarray Sums Equal/README_EN.md @@ -78,6 +78,8 @@ The array after the operations is [5,5,5,5] +#### Python3 + ```python class Solution: def makeSubKSumEqual(self, arr: List[int], k: int) -> int: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long makeSubKSumEqual(int[] arr, int k) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func makeSubKSumEqual(arr []int, k int) (ans int64) { n := len(arr) @@ -173,6 +181,8 @@ func gcd(a, b int) int { } ``` +#### TypeScript + ```ts function makeSubKSumEqual(arr: number[], k: number): number { const n = arr.length; diff --git a/solution/2600-2699/2608.Shortest Cycle in a Graph/README.md b/solution/2600-2699/2608.Shortest Cycle in a Graph/README.md index 66753c87d8862..a3683765dcfab 100644 --- a/solution/2600-2699/2608.Shortest Cycle in a Graph/README.md +++ b/solution/2600-2699/2608.Shortest Cycle in a Graph/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def findShortestCycle(self, n: int, edges: List[List[int]]) -> int: @@ -93,6 +95,8 @@ class Solution: return ans if ans < inf else -1 ``` +#### Java + ```java class Solution { private List[] g; @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func findShortestCycle(n int, edges [][]int) int { g := make([][]int, n) @@ -215,6 +223,8 @@ func findShortestCycle(n int, edges [][]int) int { } ``` +#### TypeScript + ```ts function findShortestCycle(n: number, edges: number[][]): number { const g: number[][] = new Array(n).fill(0).map(() => []); @@ -263,6 +273,8 @@ function findShortestCycle(n: number, edges: number[][]): number { +#### Python3 + ```python class Solution: def findShortestCycle(self, n: int, edges: List[List[int]]) -> int: @@ -289,6 +301,8 @@ class Solution: return ans if ans < inf else -1 ``` +#### Java + ```java class Solution { private List[] g; @@ -334,6 +348,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -377,6 +393,8 @@ public: }; ``` +#### Go + ```go func findShortestCycle(n int, edges [][]int) int { g := make([][]int, n) @@ -421,6 +439,8 @@ func findShortestCycle(n int, edges [][]int) int { } ``` +#### TypeScript + ```ts function findShortestCycle(n: number, edges: number[][]): number { const g: number[][] = new Array(n).fill(0).map(() => []); diff --git a/solution/2600-2699/2608.Shortest Cycle in a Graph/README_EN.md b/solution/2600-2699/2608.Shortest Cycle in a Graph/README_EN.md index 1b45bc2d5c198..1a5a670dd2a5a 100644 --- a/solution/2600-2699/2608.Shortest Cycle in a Graph/README_EN.md +++ b/solution/2600-2699/2608.Shortest Cycle in a Graph/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(m^2)$ and the space complexity is $O(m + n)$, where $m +#### Python3 + ```python class Solution: def findShortestCycle(self, n: int, edges: List[List[int]]) -> int: @@ -93,6 +95,8 @@ class Solution: return ans if ans < inf else -1 ``` +#### Java + ```java class Solution { private List[] g; @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func findShortestCycle(n int, edges [][]int) int { g := make([][]int, n) @@ -215,6 +223,8 @@ func findShortestCycle(n int, edges [][]int) int { } ``` +#### TypeScript + ```ts function findShortestCycle(n: number, edges: number[][]): number { const g: number[][] = new Array(n).fill(0).map(() => []); @@ -263,6 +273,8 @@ The time complexity is $O(m \times n)$ and the space complexity is $O(m + n)$, w +#### Python3 + ```python class Solution: def findShortestCycle(self, n: int, edges: List[List[int]]) -> int: @@ -289,6 +301,8 @@ class Solution: return ans if ans < inf else -1 ``` +#### Java + ```java class Solution { private List[] g; @@ -334,6 +348,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -377,6 +393,8 @@ public: }; ``` +#### Go + ```go func findShortestCycle(n int, edges [][]int) int { g := make([][]int, n) @@ -421,6 +439,8 @@ func findShortestCycle(n int, edges [][]int) int { } ``` +#### TypeScript + ```ts function findShortestCycle(n: number, edges: number[][]): number { const g: number[][] = new Array(n).fill(0).map(() => []); diff --git a/solution/2600-2699/2609.Find the Longest Balanced Substring of a Binary String/README.md b/solution/2600-2699/2609.Find the Longest Balanced Substring of a Binary String/README.md index 5a631965de595..65cff29940a4c 100644 --- a/solution/2600-2699/2609.Find the Longest Balanced Substring of a Binary String/README.md +++ b/solution/2600-2699/2609.Find the Longest Balanced Substring of a Binary String/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def findTheLongestBalancedSubstring(self, s: str) -> int: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findTheLongestBalancedSubstring(String s) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func findTheLongestBalancedSubstring(s string) (ans int) { n := len(s) @@ -179,6 +187,8 @@ func findTheLongestBalancedSubstring(s string) (ans int) { } ``` +#### TypeScript + ```ts function findTheLongestBalancedSubstring(s: string): number { const n = s.length; @@ -205,6 +215,8 @@ function findTheLongestBalancedSubstring(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_the_longest_balanced_substring(s: String) -> i32 { @@ -263,6 +275,8 @@ impl Solution { +#### Python3 + ```python class Solution: def findTheLongestBalancedSubstring(self, s: str) -> int: @@ -278,6 +292,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findTheLongestBalancedSubstring(String s) { @@ -299,6 +315,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -321,6 +339,8 @@ public: }; ``` +#### Go + ```go func findTheLongestBalancedSubstring(s string) (ans int) { zero, one := 0, 0 @@ -339,6 +359,8 @@ func findTheLongestBalancedSubstring(s string) (ans int) { } ``` +#### TypeScript + ```ts function findTheLongestBalancedSubstring(s: string): number { let zero = 0; @@ -359,6 +381,8 @@ function findTheLongestBalancedSubstring(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_the_longest_balanced_substring(s: String) -> i32 { diff --git a/solution/2600-2699/2609.Find the Longest Balanced Substring of a Binary String/README_EN.md b/solution/2600-2699/2609.Find the Longest Balanced Substring of a Binary String/README_EN.md index c4f64ce0548c9..a0f24705f0cad 100644 --- a/solution/2600-2699/2609.Find the Longest Balanced Substring of a Binary String/README_EN.md +++ b/solution/2600-2699/2609.Find the Longest Balanced Substring of a Binary String/README_EN.md @@ -73,6 +73,8 @@ The time complexity is $O(n^3)$, and the space complexity is $O(1)$. Where $n$ i +#### Python3 + ```python class Solution: def findTheLongestBalancedSubstring(self, s: str) -> int: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findTheLongestBalancedSubstring(String s) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func findTheLongestBalancedSubstring(s string) (ans int) { n := len(s) @@ -177,6 +185,8 @@ func findTheLongestBalancedSubstring(s string) (ans int) { } ``` +#### TypeScript + ```ts function findTheLongestBalancedSubstring(s: string): number { const n = s.length; @@ -203,6 +213,8 @@ function findTheLongestBalancedSubstring(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_the_longest_balanced_substring(s: String) -> i32 { @@ -261,6 +273,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. Where $n$ is +#### Python3 + ```python class Solution: def findTheLongestBalancedSubstring(self, s: str) -> int: @@ -276,6 +290,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findTheLongestBalancedSubstring(String s) { @@ -297,6 +313,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -319,6 +337,8 @@ public: }; ``` +#### Go + ```go func findTheLongestBalancedSubstring(s string) (ans int) { zero, one := 0, 0 @@ -337,6 +357,8 @@ func findTheLongestBalancedSubstring(s string) (ans int) { } ``` +#### TypeScript + ```ts function findTheLongestBalancedSubstring(s: string): number { let zero = 0; @@ -357,6 +379,8 @@ function findTheLongestBalancedSubstring(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn find_the_longest_balanced_substring(s: String) -> i32 { diff --git a/solution/2600-2699/2610.Convert an Array Into a 2D Array With Conditions/README.md b/solution/2600-2699/2610.Convert an Array Into a 2D Array With Conditions/README.md index baa014bd83daf..4dfe8f322ecd7 100644 --- a/solution/2600-2699/2610.Convert an Array Into a 2D Array With Conditions/README.md +++ b/solution/2600-2699/2610.Convert an Array Into a 2D Array With Conditions/README.md @@ -78,6 +78,8 @@ nums 中的所有元素都有用到,并且每一行都由不同的整数组成 +#### Python3 + ```python class Solution: def findMatrix(self, nums: List[int]) -> List[List[int]]: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> findMatrix(int[] nums) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func findMatrix(nums []int) (ans [][]int) { n := len(nums) @@ -157,6 +165,8 @@ func findMatrix(nums []int) (ans [][]int) { } ``` +#### TypeScript + ```ts function findMatrix(nums: number[]): number[][] { const ans: number[][] = []; diff --git a/solution/2600-2699/2610.Convert an Array Into a 2D Array With Conditions/README_EN.md b/solution/2600-2699/2610.Convert an Array Into a 2D Array With Conditions/README_EN.md index 1f2c024c53982..e299ea99103fd 100644 --- a/solution/2600-2699/2610.Convert an Array Into a 2D Array With Conditions/README_EN.md +++ b/solution/2600-2699/2610.Convert an Array Into a 2D Array With Conditions/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n)$ and the space complexity is $O(n)$, where $n$ is t +#### Python3 + ```python class Solution: def findMatrix(self, nums: List[int]) -> List[List[int]]: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> findMatrix(int[] nums) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func findMatrix(nums []int) (ans [][]int) { n := len(nums) @@ -157,6 +165,8 @@ func findMatrix(nums []int) (ans [][]int) { } ``` +#### TypeScript + ```ts function findMatrix(nums: number[]): number[][] { const ans: number[][] = []; diff --git a/solution/2600-2699/2611.Mice and Cheese/README.md b/solution/2600-2699/2611.Mice and Cheese/README.md index d93b0417c660c..85785a8dbbb89 100644 --- a/solution/2600-2699/2611.Mice and Cheese/README.md +++ b/solution/2600-2699/2611.Mice and Cheese/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def miceAndCheese(self, reward1: List[int], reward2: List[int], k: int) -> int: @@ -96,6 +98,8 @@ class Solution: return sum(reward1[i] for i in idx[:k]) + sum(reward2[i] for i in idx[k:]) ``` +#### Java + ```java class Solution { public int miceAndCheese(int[] reward1, int[] reward2, int k) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func miceAndCheese(reward1 []int, reward2 []int, k int) (ans int) { n := len(reward1) @@ -158,6 +166,8 @@ func miceAndCheese(reward1 []int, reward2 []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function miceAndCheese(reward1: number[], reward2: number[], k: number): number { const n = reward1.length; @@ -184,6 +194,8 @@ function miceAndCheese(reward1: number[], reward2: number[], k: number): number +#### Python3 + ```python class Solution: def miceAndCheese(self, reward1: List[int], reward2: List[int], k: int) -> int: @@ -193,6 +205,8 @@ class Solution: return sum(reward2) + sum(reward1[:k]) ``` +#### Java + ```java class Solution { public int miceAndCheese(int[] reward1, int[] reward2, int k) { @@ -211,6 +225,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -228,6 +244,8 @@ public: }; ``` +#### Go + ```go func miceAndCheese(reward1 []int, reward2 []int, k int) (ans int) { for i, x := range reward2 { @@ -243,6 +261,8 @@ func miceAndCheese(reward1 []int, reward2 []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function miceAndCheese(reward1: number[], reward2: number[], k: number): number { const n = reward1.length; diff --git a/solution/2600-2699/2611.Mice and Cheese/README_EN.md b/solution/2600-2699/2611.Mice and Cheese/README_EN.md index 0921e30a36ff0..af96f1dd754e6 100644 --- a/solution/2600-2699/2611.Mice and Cheese/README_EN.md +++ b/solution/2600-2699/2611.Mice and Cheese/README_EN.md @@ -80,6 +80,8 @@ Time complexity $O(n \times \log n)$, space complexity $O(n)$. Where $n$ is the +#### Python3 + ```python class Solution: def miceAndCheese(self, reward1: List[int], reward2: List[int], k: int) -> int: @@ -88,6 +90,8 @@ class Solution: return sum(reward1[i] for i in idx[:k]) + sum(reward2[i] for i in idx[k:]) ``` +#### Java + ```java class Solution { public int miceAndCheese(int[] reward1, int[] reward2, int k) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func miceAndCheese(reward1 []int, reward2 []int, k int) (ans int) { n := len(reward1) @@ -150,6 +158,8 @@ func miceAndCheese(reward1 []int, reward2 []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function miceAndCheese(reward1: number[], reward2: number[], k: number): number { const n = reward1.length; @@ -176,6 +186,8 @@ function miceAndCheese(reward1: number[], reward2: number[], k: number): number +#### Python3 + ```python class Solution: def miceAndCheese(self, reward1: List[int], reward2: List[int], k: int) -> int: @@ -185,6 +197,8 @@ class Solution: return sum(reward2) + sum(reward1[:k]) ``` +#### Java + ```java class Solution { public int miceAndCheese(int[] reward1, int[] reward2, int k) { @@ -203,6 +217,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -220,6 +236,8 @@ public: }; ``` +#### Go + ```go func miceAndCheese(reward1 []int, reward2 []int, k int) (ans int) { for i, x := range reward2 { @@ -235,6 +253,8 @@ func miceAndCheese(reward1 []int, reward2 []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function miceAndCheese(reward1: number[], reward2: number[], k: number): number { const n = reward1.length; diff --git a/solution/2600-2699/2612.Minimum Reverse Operations/README.md b/solution/2600-2699/2612.Minimum Reverse Operations/README.md index 99368030e08ef..20b78a7dc434c 100644 --- a/solution/2600-2699/2612.Minimum Reverse Operations/README.md +++ b/solution/2600-2699/2612.Minimum Reverse Operations/README.md @@ -110,6 +110,8 @@ tags: +#### Python3 + ```python from sortedcontainers import SortedSet @@ -143,6 +145,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] minReverseOperations(int n, int p, int[] banned, int k) { @@ -176,6 +180,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -212,6 +218,8 @@ public: }; ``` +#### Go + ```go func minReverseOperations(n int, p int, banned []int, k int) []int { ans := make([]int, n) @@ -245,6 +253,8 @@ func minReverseOperations(n int, p int, banned []int, k int) []int { } ``` +#### TypeScript + ```ts function minReverseOperations(n: number, p: number, banned: number[], k: number): number[] { const ans = new Array(n).fill(-1); @@ -928,6 +938,8 @@ class TreeMultiSet { +#### TypeScript + ```ts function minReverseOperations(n: number, p: number, banned: number[], k: number): number[] { const ans = new Array(n).fill(-1); diff --git a/solution/2600-2699/2612.Minimum Reverse Operations/README_EN.md b/solution/2600-2699/2612.Minimum Reverse Operations/README_EN.md index cd1fb8e858358..9bd452fa7a4e7 100644 --- a/solution/2600-2699/2612.Minimum Reverse Operations/README_EN.md +++ b/solution/2600-2699/2612.Minimum Reverse Operations/README_EN.md @@ -104,6 +104,8 @@ The time complexity is $O(n \times \log n)$ and the space complexity is $O(n)$. +#### Python3 + ```python from sortedcontainers import SortedSet @@ -137,6 +139,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] minReverseOperations(int n, int p, int[] banned, int k) { @@ -170,6 +174,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -206,6 +212,8 @@ public: }; ``` +#### Go + ```go func minReverseOperations(n int, p int, banned []int, k int) []int { ans := make([]int, n) @@ -239,6 +247,8 @@ func minReverseOperations(n int, p int, banned []int, k int) []int { } ``` +#### TypeScript + ```ts function minReverseOperations(n: number, p: number, banned: number[], k: number): number[] { const ans = new Array(n).fill(-1); @@ -922,6 +932,8 @@ class TreeMultiSet { +#### TypeScript + ```ts function minReverseOperations(n: number, p: number, banned: number[], k: number): number[] { const ans = new Array(n).fill(-1); diff --git a/solution/2600-2699/2613.Beautiful Pairs/README.md b/solution/2600-2699/2613.Beautiful Pairs/README.md index c843fb89de5b1..fed8c6f46ea2a 100644 --- a/solution/2600-2699/2613.Beautiful Pairs/README.md +++ b/solution/2600-2699/2613.Beautiful Pairs/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def beautifulPair(self, nums1: List[int], nums2: List[int]) -> List[int]: @@ -125,6 +127,8 @@ class Solution: return [pi, pj] ``` +#### Java + ```java class Solution { private List points = new ArrayList<>(); @@ -193,6 +197,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -262,6 +268,8 @@ public: }; ``` +#### Go + ```go func beautifulPair(nums1 []int, nums2 []int) []int { n := len(nums1) @@ -330,6 +338,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function beautifulPair(nums1: number[], nums2: number[]): number[] { const pl: Map = new Map(); diff --git a/solution/2600-2699/2613.Beautiful Pairs/README_EN.md b/solution/2600-2699/2613.Beautiful Pairs/README_EN.md index 9b844113f5823..ed0188376c00d 100644 --- a/solution/2600-2699/2613.Beautiful Pairs/README_EN.md +++ b/solution/2600-2699/2613.Beautiful Pairs/README_EN.md @@ -85,6 +85,8 @@ Space complexity: $O(n)$. +#### Python3 + ```python class Solution: def beautifulPair(self, nums1: List[int], nums2: List[int]) -> List[int]: @@ -125,6 +127,8 @@ class Solution: return [pi, pj] ``` +#### Java + ```java class Solution { private List points = new ArrayList<>(); @@ -193,6 +197,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -262,6 +268,8 @@ public: }; ``` +#### Go + ```go func beautifulPair(nums1 []int, nums2 []int) []int { n := len(nums1) @@ -330,6 +338,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function beautifulPair(nums1: number[], nums2: number[]): number[] { const pl: Map = new Map(); diff --git a/solution/2600-2699/2614.Prime In Diagonal/README.md b/solution/2600-2699/2614.Prime In Diagonal/README.md index a2360449ef4e7..ac7d02d3a9bdb 100644 --- a/solution/2600-2699/2614.Prime In Diagonal/README.md +++ b/solution/2600-2699/2614.Prime In Diagonal/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def diagonalPrime(self, nums: List[List[int]]) -> int: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int diagonalPrime(int[][] nums) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func diagonalPrime(nums [][]int) (ans int) { n := len(nums) @@ -186,6 +194,8 @@ func isPrime(x int) bool { } ``` +#### Rust + ```rust impl Solution { pub fn diagonal_prime(nums: Vec>) -> i32 { diff --git a/solution/2600-2699/2614.Prime In Diagonal/README_EN.md b/solution/2600-2699/2614.Prime In Diagonal/README_EN.md index f42aaac2bb2e3..55cbebcbccb83 100644 --- a/solution/2600-2699/2614.Prime In Diagonal/README_EN.md +++ b/solution/2600-2699/2614.Prime In Diagonal/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n \times \sqrt{M})$, where $n$ and $M$ are the number +#### Python3 + ```python class Solution: def diagonalPrime(self, nums: List[List[int]]) -> int: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int diagonalPrime(int[][] nums) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func diagonalPrime(nums [][]int) (ans int) { n := len(nums) @@ -184,6 +192,8 @@ func isPrime(x int) bool { } ``` +#### Rust + ```rust impl Solution { pub fn diagonal_prime(nums: Vec>) -> i32 { diff --git a/solution/2600-2699/2615.Sum of Distances/README.md b/solution/2600-2699/2615.Sum of Distances/README.md index 67811194719e3..7fa2ee01eecc8 100644 --- a/solution/2600-2699/2615.Sum of Distances/README.md +++ b/solution/2600-2699/2615.Sum of Distances/README.md @@ -74,6 +74,8 @@ i = 4 ,arr[4] = 0 因为不存在值等于 2 的其他下标。 +#### Python3 + ```python class Solution: def distance(self, nums: List[int]) -> List[int]: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long[] distance(int[] nums) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func distance(nums []int) []int64 { n := len(nums) diff --git a/solution/2600-2699/2615.Sum of Distances/README_EN.md b/solution/2600-2699/2615.Sum of Distances/README_EN.md index 68b12ff76d14a..63a17462edb92 100644 --- a/solution/2600-2699/2615.Sum of Distances/README_EN.md +++ b/solution/2600-2699/2615.Sum of Distances/README_EN.md @@ -65,6 +65,8 @@ When i = 4, arr[4] = 0 because there is no other index with value 2. +#### Python3 + ```python class Solution: def distance(self, nums: List[int]) -> List[int]: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long[] distance(int[] nums) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func distance(nums []int) []int64 { n := len(nums) diff --git a/solution/2600-2699/2616.Minimize the Maximum Difference of Pairs/README.md b/solution/2600-2699/2616.Minimize the Maximum Difference of Pairs/README.md index 9ef965e37cf9e..ddc1aad7d23b1 100644 --- a/solution/2600-2699/2616.Minimize the Maximum Difference of Pairs/README.md +++ b/solution/2600-2699/2616.Minimize the Maximum Difference of Pairs/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def minimizeMax(self, nums: List[int], p: int) -> int: @@ -90,6 +92,8 @@ class Solution: return bisect_left(range(nums[-1] - nums[0] + 1), True, key=check) ``` +#### Java + ```java class Solution { public int minimizeMax(int[] nums, int p) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func minimizeMax(nums []int, p int) int { sort.Ints(nums) diff --git a/solution/2600-2699/2616.Minimize the Maximum Difference of Pairs/README_EN.md b/solution/2600-2699/2616.Minimize the Maximum Difference of Pairs/README_EN.md index a1ed0f7b8de8c..5cc179665dfd8 100644 --- a/solution/2600-2699/2616.Minimize the Maximum Difference of Pairs/README_EN.md +++ b/solution/2600-2699/2616.Minimize the Maximum Difference of Pairs/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(n \times (\log n + \log m))$, where $n$ is the length +#### Python3 + ```python class Solution: def minimizeMax(self, nums: List[int], p: int) -> int: @@ -88,6 +90,8 @@ class Solution: return bisect_left(range(nums[-1] - nums[0] + 1), True, key=check) ``` +#### Java + ```java class Solution { public int minimizeMax(int[] nums, int p) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func minimizeMax(nums []int, p int) int { sort.Ints(nums) diff --git a/solution/2600-2699/2617.Minimum Number of Visited Cells in a Grid/README.md b/solution/2600-2699/2617.Minimum Number of Visited Cells in a Grid/README.md index 23b3d7726b860..d530d5bfcc03d 100644 --- a/solution/2600-2699/2617.Minimum Number of Visited Cells in a Grid/README.md +++ b/solution/2600-2699/2617.Minimum Number of Visited Cells in a Grid/README.md @@ -100,6 +100,8 @@ tags: +#### Python3 + ```python class Solution: def minimumVisitedCells(self, grid: List[List[int]]) -> int: @@ -124,6 +126,8 @@ class Solution: return dist[-1][-1] ``` +#### Java + ```java class Solution { public int minimumVisitedCells(int[][] grid) { @@ -164,6 +168,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -199,6 +205,8 @@ public: }; ``` +#### Go + ```go func minimumVisitedCells(grid [][]int) int { m, n := len(grid), len(grid[0]) diff --git a/solution/2600-2699/2617.Minimum Number of Visited Cells in a Grid/README_EN.md b/solution/2600-2699/2617.Minimum Number of Visited Cells in a Grid/README_EN.md index f232ca42cf348..5d29382fdfb7f 100644 --- a/solution/2600-2699/2617.Minimum Number of Visited Cells in a Grid/README_EN.md +++ b/solution/2600-2699/2617.Minimum Number of Visited Cells in a Grid/README_EN.md @@ -95,6 +95,8 @@ The time complexity is $O(m \times n \times \log (m \times n))$ and the space co +#### Python3 + ```python class Solution: def minimumVisitedCells(self, grid: List[List[int]]) -> int: @@ -119,6 +121,8 @@ class Solution: return dist[-1][-1] ``` +#### Java + ```java class Solution { public int minimumVisitedCells(int[][] grid) { @@ -159,6 +163,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -194,6 +200,8 @@ public: }; ``` +#### Go + ```go func minimumVisitedCells(grid [][]int) int { m, n := len(grid), len(grid[0]) diff --git a/solution/2600-2699/2618.Check if Object Instance of Class/README.md b/solution/2600-2699/2618.Check if Object Instance of Class/README.md index 7c0072ddb7d8a..4010fa0ef3f61 100644 --- a/solution/2600-2699/2618.Check if Object Instance of Class/README.md +++ b/solution/2600-2699/2618.Check if Object Instance of Class/README.md @@ -65,6 +65,8 @@ Dog 是 Animal 的子类。因此,Dog 对象同时是 Dog 和 Animal 的实例 +#### TypeScript + ```ts function checkIfInstanceOf(obj: any, classFunction: any): boolean { if (classFunction === null || classFunction === undefined) { diff --git a/solution/2600-2699/2618.Check if Object Instance of Class/README_EN.md b/solution/2600-2699/2618.Check if Object Instance of Class/README_EN.md index 4e683b87783e3..5158ed9c07ae6 100644 --- a/solution/2600-2699/2618.Check if Object Instance of Class/README_EN.md +++ b/solution/2600-2699/2618.Check if Object Instance of Class/README_EN.md @@ -65,6 +65,8 @@ Dog is a subclass of Animal. Therefore, a Dog object is an instance of both Dog +#### TypeScript + ```ts function checkIfInstanceOf(obj: any, classFunction: any): boolean { if (classFunction === null || classFunction === undefined) { diff --git a/solution/2600-2699/2619.Array Prototype Last/README.md b/solution/2600-2699/2619.Array Prototype Last/README.md index 770f94e8d31da..ca0b9cdb7fa56 100644 --- a/solution/2600-2699/2619.Array Prototype Last/README.md +++ b/solution/2600-2699/2619.Array Prototype Last/README.md @@ -55,6 +55,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2600-2699/2619.Ar +#### TypeScript + ```ts declare global { interface Array { diff --git a/solution/2600-2699/2619.Array Prototype Last/README_EN.md b/solution/2600-2699/2619.Array Prototype Last/README_EN.md index f372f48015b52..f031997d092e9 100644 --- a/solution/2600-2699/2619.Array Prototype Last/README_EN.md +++ b/solution/2600-2699/2619.Array Prototype Last/README_EN.md @@ -53,6 +53,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2600-2699/2619.Ar +#### TypeScript + ```ts declare global { interface Array { diff --git a/solution/2600-2699/2620.Counter/README.md b/solution/2600-2699/2620.Counter/README.md index 5b064a30a6cae..8e48a33cc6a4e 100644 --- a/solution/2600-2699/2620.Counter/README.md +++ b/solution/2600-2699/2620.Counter/README.md @@ -61,6 +61,8 @@ n = -2 +#### TypeScript + ```ts function createCounter(n: number): () => number { let i = n; diff --git a/solution/2600-2699/2620.Counter/README_EN.md b/solution/2600-2699/2620.Counter/README_EN.md index f76af76a3bba8..480792a04ffc8 100644 --- a/solution/2600-2699/2620.Counter/README_EN.md +++ b/solution/2600-2699/2620.Counter/README_EN.md @@ -59,6 +59,8 @@ n = -2 +#### TypeScript + ```ts function createCounter(n: number): () => number { let i = n; diff --git a/solution/2600-2699/2621.Sleep/README.md b/solution/2600-2699/2621.Sleep/README.md index 65d0a8366008c..2607dfdc0a1d6 100644 --- a/solution/2600-2699/2621.Sleep/README.md +++ b/solution/2600-2699/2621.Sleep/README.md @@ -57,6 +57,8 @@ sleep(100).then(() => { +#### TypeScript + ```ts async function sleep(millis: number): Promise { return new Promise(r => setTimeout(r, millis)); diff --git a/solution/2600-2699/2621.Sleep/README_EN.md b/solution/2600-2699/2621.Sleep/README_EN.md index 7a513453d0766..4d33630e3513d 100644 --- a/solution/2600-2699/2621.Sleep/README_EN.md +++ b/solution/2600-2699/2621.Sleep/README_EN.md @@ -54,6 +54,8 @@ sleep(100).then(() => { +#### TypeScript + ```ts async function sleep(millis: number): Promise { return new Promise(r => setTimeout(r, millis)); diff --git a/solution/2600-2699/2622.Cache With Time Limit/README.md b/solution/2600-2699/2622.Cache With Time Limit/README.md index 846955cf5c6e6..c642916f9e75d 100644 --- a/solution/2600-2699/2622.Cache With Time Limit/README.md +++ b/solution/2600-2699/2622.Cache With Time Limit/README.md @@ -93,6 +93,8 @@ timeDelays = [0, 0, 40, 50, 120, 200, 250] +#### TypeScript + ```ts class TimeLimitedCache { private cache: Map = new Map(); diff --git a/solution/2600-2699/2622.Cache With Time Limit/README_EN.md b/solution/2600-2699/2622.Cache With Time Limit/README_EN.md index ccc422c256690..643f4cebbe7f0 100644 --- a/solution/2600-2699/2622.Cache With Time Limit/README_EN.md +++ b/solution/2600-2699/2622.Cache With Time Limit/README_EN.md @@ -85,6 +85,8 @@ At t=250, count() returns 0 because the cache is empty. +#### TypeScript + ```ts class TimeLimitedCache { private cache: Map = new Map(); diff --git a/solution/2600-2699/2623.Memoize/README.md b/solution/2600-2699/2623.Memoize/README.md index 433b540bda4b6..7b9a0b89d8a66 100644 --- a/solution/2600-2699/2623.Memoize/README.md +++ b/solution/2600-2699/2623.Memoize/README.md @@ -104,6 +104,8 @@ values = [[5],[]] +#### TypeScript + ```ts type Fn = (...params: any) => any; diff --git a/solution/2600-2699/2623.Memoize/README_EN.md b/solution/2600-2699/2623.Memoize/README_EN.md index 55d851503fc31..b5650216d7409 100644 --- a/solution/2600-2699/2623.Memoize/README_EN.md +++ b/solution/2600-2699/2623.Memoize/README_EN.md @@ -99,6 +99,8 @@ values = [[5],[]] +#### TypeScript + ```ts type Fn = (...params: any) => any; diff --git a/solution/2600-2699/2624.Snail Traversal/README.md b/solution/2600-2699/2624.Snail Traversal/README.md index a3bbd5af4c852..1b9165b67bc08 100644 --- a/solution/2600-2699/2624.Snail Traversal/README.md +++ b/solution/2600-2699/2624.Snail Traversal/README.md @@ -89,6 +89,8 @@ colsCount = 2 +#### TypeScript + ```ts declare global { interface Array { diff --git a/solution/2600-2699/2624.Snail Traversal/README_EN.md b/solution/2600-2699/2624.Snail Traversal/README_EN.md index f7fc423991e42..dd5ce97803431 100644 --- a/solution/2600-2699/2624.Snail Traversal/README_EN.md +++ b/solution/2600-2699/2624.Snail Traversal/README_EN.md @@ -83,6 +83,8 @@ colsCount = 2 +#### TypeScript + ```ts declare global { interface Array { diff --git a/solution/2600-2699/2625.Flatten Deeply Nested Array/README.md b/solution/2600-2699/2625.Flatten Deeply Nested Array/README.md index 635251059b398..74f1fa245dcac 100644 --- a/solution/2600-2699/2625.Flatten Deeply Nested Array/README.md +++ b/solution/2600-2699/2625.Flatten Deeply Nested Array/README.md @@ -89,6 +89,8 @@ n = 2 +#### TypeScript + ```ts type MultiDimensionalArray = (number | MultiDimensionalArray)[]; diff --git a/solution/2600-2699/2625.Flatten Deeply Nested Array/README_EN.md b/solution/2600-2699/2625.Flatten Deeply Nested Array/README_EN.md index 14bf9cdc16f8c..c5beff0b8b0d9 100644 --- a/solution/2600-2699/2625.Flatten Deeply Nested Array/README_EN.md +++ b/solution/2600-2699/2625.Flatten Deeply Nested Array/README_EN.md @@ -80,6 +80,8 @@ The maximum depth of any subarray is 1. Thus, all of them are flattened. +#### TypeScript + ```ts type MultiDimensionalArray = (number | MultiDimensionalArray)[]; diff --git a/solution/2600-2699/2626.Array Reduce Transformation/README.md b/solution/2600-2699/2626.Array Reduce Transformation/README.md index f3a98cd0f8b02..2b657d046471c 100644 --- a/solution/2600-2699/2626.Array Reduce Transformation/README.md +++ b/solution/2600-2699/2626.Array Reduce Transformation/README.md @@ -89,6 +89,8 @@ init = 25 +#### TypeScript + ```ts type Fn = (accum: number, curr: number) => number; diff --git a/solution/2600-2699/2626.Array Reduce Transformation/README_EN.md b/solution/2600-2699/2626.Array Reduce Transformation/README_EN.md index 9b692e40d993b..2a90977ebc78a 100644 --- a/solution/2600-2699/2626.Array Reduce Transformation/README_EN.md +++ b/solution/2600-2699/2626.Array Reduce Transformation/README_EN.md @@ -87,6 +87,8 @@ init = 25 +#### TypeScript + ```ts type Fn = (accum: number, curr: number) => number; diff --git a/solution/2600-2699/2627.Debounce/README.md b/solution/2600-2699/2627.Debounce/README.md index 61e8a03e29791..8dc2581327e8c 100644 --- a/solution/2600-2699/2627.Debounce/README.md +++ b/solution/2600-2699/2627.Debounce/README.md @@ -104,6 +104,8 @@ calls = [ +#### TypeScript + ```ts type F = (...p: any[]) => any; diff --git a/solution/2600-2699/2627.Debounce/README_EN.md b/solution/2600-2699/2627.Debounce/README_EN.md index 2adb79f9dd7be..53b0386323bb7 100644 --- a/solution/2600-2699/2627.Debounce/README_EN.md +++ b/solution/2600-2699/2627.Debounce/README_EN.md @@ -106,6 +106,8 @@ The 3rd call is delayed by 150ms and ran at 450ms. The inputs were (5, 6). +#### TypeScript + ```ts type F = (...p: any[]) => any; diff --git a/solution/2600-2699/2628.JSON Deep Equal/README.md b/solution/2600-2699/2628.JSON Deep Equal/README.md index eeed629767346..4dd1baac9ac63 100644 --- a/solution/2600-2699/2628.JSON Deep Equal/README.md +++ b/solution/2600-2699/2628.JSON Deep Equal/README.md @@ -93,6 +93,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2600-2699/2628.JS +#### TypeScript + ```ts function areDeeplyEqual(o1: any, o2: any): boolean { if (o1 === null || typeof o1 !== 'object') { diff --git a/solution/2600-2699/2628.JSON Deep Equal/README_EN.md b/solution/2600-2699/2628.JSON Deep Equal/README_EN.md index 40c9d959d02d0..caf60f00660dd 100644 --- a/solution/2600-2699/2628.JSON Deep Equal/README_EN.md +++ b/solution/2600-2699/2628.JSON Deep Equal/README_EN.md @@ -85,6 +85,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2600-2699/2628.JS +#### TypeScript + ```ts function areDeeplyEqual(o1: any, o2: any): boolean { if (o1 === null || typeof o1 !== 'object') { diff --git a/solution/2600-2699/2629.Function Composition/README.md b/solution/2600-2699/2629.Function Composition/README.md index 8ffca870cd4b7..59c74ccaaef60 100644 --- a/solution/2600-2699/2629.Function Composition/README.md +++ b/solution/2600-2699/2629.Function Composition/README.md @@ -77,6 +77,8 @@ Starting with x = 4. +#### TypeScript + ```ts type F = (x: number) => number; diff --git a/solution/2600-2699/2629.Function Composition/README_EN.md b/solution/2600-2699/2629.Function Composition/README_EN.md index 2851a1b8b4da2..81c0019bdd40a 100644 --- a/solution/2600-2699/2629.Function Composition/README_EN.md +++ b/solution/2600-2699/2629.Function Composition/README_EN.md @@ -75,6 +75,8 @@ The composition of zero functions is the identity function +#### TypeScript + ```ts type F = (x: number) => number; diff --git a/solution/2600-2699/2630.Memoize II/README.md b/solution/2600-2699/2630.Memoize II/README.md index 9c9099b202aa2..3cc90235199fd 100644 --- a/solution/2600-2699/2630.Memoize II/README.md +++ b/solution/2600-2699/2630.Memoize II/README.md @@ -92,6 +92,8 @@ fn = function (a, b) { return ({...a, ...b}); } +#### TypeScript + ```ts type Fn = (...params: any) => any; diff --git a/solution/2600-2699/2630.Memoize II/README_EN.md b/solution/2600-2699/2630.Memoize II/README_EN.md index 5ae5cdd268837..07cccacc86e97 100644 --- a/solution/2600-2699/2630.Memoize II/README_EN.md +++ b/solution/2600-2699/2630.Memoize II/README_EN.md @@ -81,6 +81,8 @@ Merging two empty objects will always result in an empty object. The 2nd and 3rd +#### TypeScript + ```ts type Fn = (...params: any) => any; diff --git a/solution/2600-2699/2631.Group By/README.md b/solution/2600-2699/2631.Group By/README.md index 74ee9a17fd52f..0abb58a8c60f2 100644 --- a/solution/2600-2699/2631.Group By/README.md +++ b/solution/2600-2699/2631.Group By/README.md @@ -110,6 +110,8 @@ fn = function (n) { +#### TypeScript + ```ts declare global { interface Array { diff --git a/solution/2600-2699/2631.Group By/README_EN.md b/solution/2600-2699/2631.Group By/README_EN.md index 1370b6927e528..beb0325d01fd0 100644 --- a/solution/2600-2699/2631.Group By/README_EN.md +++ b/solution/2600-2699/2631.Group By/README_EN.md @@ -108,6 +108,8 @@ The selector function splits the array by whether each number is greater than 5. +#### TypeScript + ```ts declare global { interface Array { diff --git a/solution/2600-2699/2632.Curry/README.md b/solution/2600-2699/2632.Curry/README.md index e1e79ccdc3eed..1f5132254043a 100644 --- a/solution/2600-2699/2632.Curry/README.md +++ b/solution/2600-2699/2632.Curry/README.md @@ -94,6 +94,8 @@ curriedLife() === 42 +#### TypeScript + ```ts function curry(fn: Function): Function { return function curried(...args) { diff --git a/solution/2600-2699/2632.Curry/README_EN.md b/solution/2600-2699/2632.Curry/README_EN.md index ccd785325024a..6a4cad22f3a59 100644 --- a/solution/2600-2699/2632.Curry/README_EN.md +++ b/solution/2600-2699/2632.Curry/README_EN.md @@ -92,6 +92,8 @@ curriedLife() === 42 +#### TypeScript + ```ts function curry(fn: Function): Function { return function curried(...args) { diff --git a/solution/2600-2699/2633.Convert Object to JSON String/README.md b/solution/2600-2699/2633.Convert Object to JSON String/README.md index fb6ea02c999d4..1b767f0389760 100644 --- a/solution/2600-2699/2633.Convert Object to JSON String/README.md +++ b/solution/2600-2699/2633.Convert Object to JSON String/README.md @@ -76,6 +76,8 @@ JSON 的基本类型是字符串、数字型、布尔值和 null。 +#### TypeScript + ```ts function jsonStringify(object: any): string { if (object === null) { diff --git a/solution/2600-2699/2633.Convert Object to JSON String/README_EN.md b/solution/2600-2699/2633.Convert Object to JSON String/README_EN.md index 26515af1b4d5f..32d350c81c521 100644 --- a/solution/2600-2699/2633.Convert Object to JSON String/README_EN.md +++ b/solution/2600-2699/2633.Convert Object to JSON String/README_EN.md @@ -74,6 +74,8 @@ Primitive types are valid inputs. +#### TypeScript + ```ts function jsonStringify(object: any): string { if (object === null) { diff --git a/solution/2600-2699/2634.Filter Elements from Array/README.md b/solution/2600-2699/2634.Filter Elements from Array/README.md index ad8b0f9e6a0eb..a518f356f96b4 100644 --- a/solution/2600-2699/2634.Filter Elements from Array/README.md +++ b/solution/2600-2699/2634.Filter Elements from Array/README.md @@ -80,6 +80,8 @@ const newArray = filter(arr, fn); // [20, 30] +#### TypeScript + ```ts function filter(arr: number[], fn: (n: number, i: number) => any): number[] { const ans: number[] = []; diff --git a/solution/2600-2699/2634.Filter Elements from Array/README_EN.md b/solution/2600-2699/2634.Filter Elements from Array/README_EN.md index 64df9aadacdd6..2550be75e4d94 100644 --- a/solution/2600-2699/2634.Filter Elements from Array/README_EN.md +++ b/solution/2600-2699/2634.Filter Elements from Array/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $arr$. Ignor +#### TypeScript + ```ts function filter(arr: number[], fn: (n: number, i: number) => any): number[] { const ans: number[] = []; diff --git a/solution/2600-2699/2635.Apply Transform Over Each Element in Array/README.md b/solution/2600-2699/2635.Apply Transform Over Each Element in Array/README.md index 088ac7994ed82..75d7169cd14dc 100644 --- a/solution/2600-2699/2635.Apply Transform Over Each Element in Array/README.md +++ b/solution/2600-2699/2635.Apply Transform Over Each Element in Array/README.md @@ -73,6 +73,8 @@ const newArray = map(arr, plusone); // [2,3,4] +#### TypeScript + ```ts function map(arr: number[], fn: (n: number, i: number) => number): number[] { for (let i = 0; i < arr.length; ++i) { diff --git a/solution/2600-2699/2635.Apply Transform Over Each Element in Array/README_EN.md b/solution/2600-2699/2635.Apply Transform Over Each Element in Array/README_EN.md index fa1053fe6d56b..281605339a33c 100644 --- a/solution/2600-2699/2635.Apply Transform Over Each Element in Array/README_EN.md +++ b/solution/2600-2699/2635.Apply Transform Over Each Element in Array/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $arr$. The s +#### TypeScript + ```ts function map(arr: number[], fn: (n: number, i: number) => number): number[] { for (let i = 0; i < arr.length; ++i) { diff --git a/solution/2600-2699/2636.Promise Pool/README.md b/solution/2600-2699/2636.Promise Pool/README.md index c4121dbd788af..83a4bbd5bd06f 100644 --- a/solution/2600-2699/2636.Promise Pool/README.md +++ b/solution/2600-2699/2636.Promise Pool/README.md @@ -98,6 +98,8 @@ n = 1 +#### TypeScript + ```ts type F = () => Promise; diff --git a/solution/2600-2699/2636.Promise Pool/README_EN.md b/solution/2600-2699/2636.Promise Pool/README_EN.md index 11c97b493f9c9..02ad36332fbaa 100644 --- a/solution/2600-2699/2636.Promise Pool/README_EN.md +++ b/solution/2600-2699/2636.Promise Pool/README_EN.md @@ -101,6 +101,8 @@ At t=900, the 3rd function resolves. Pool size is 0 so the returned promise reso +#### TypeScript + ```ts type F = () => Promise; diff --git a/solution/2600-2699/2637.Promise Time Limit/README.md b/solution/2600-2699/2637.Promise Time Limit/README.md index 248219dc6f3e2..df62ccc21b98e 100644 --- a/solution/2600-2699/2637.Promise Time Limit/README.md +++ b/solution/2600-2699/2637.Promise Time Limit/README.md @@ -114,6 +114,8 @@ t = 1000 +#### TypeScript + ```ts type Fn = (...params: any[]) => Promise; diff --git a/solution/2600-2699/2637.Promise Time Limit/README_EN.md b/solution/2600-2699/2637.Promise Time Limit/README_EN.md index 9e04dd428cc78..8b863db922d0f 100644 --- a/solution/2600-2699/2637.Promise Time Limit/README_EN.md +++ b/solution/2600-2699/2637.Promise Time Limit/README_EN.md @@ -112,6 +112,8 @@ The function immediately throws an error. +#### TypeScript + ```ts type Fn = (...params: any[]) => Promise; diff --git a/solution/2600-2699/2638.Count the Number of K-Free Subsets/README.md b/solution/2600-2699/2638.Count the Number of K-Free Subsets/README.md index eb08d54ec5f12..05e5117c7c9b8 100644 --- a/solution/2600-2699/2638.Count the Number of K-Free Subsets/README.md +++ b/solution/2600-2699/2638.Count the Number of K-Free Subsets/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def countTheNumOfKFreeSubsets(self, nums: List[int], k: int) -> int: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long countTheNumOfKFreeSubsets(int[] nums, int k) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func countTheNumOfKFreeSubsets(nums []int, k int) int64 { sort.Ints(nums) @@ -185,6 +193,8 @@ func countTheNumOfKFreeSubsets(nums []int, k int) int64 { } ``` +#### TypeScript + ```ts function countTheNumOfKFreeSubsets(nums: number[], k: number): number { nums.sort((a, b) => a - b); diff --git a/solution/2600-2699/2638.Count the Number of K-Free Subsets/README_EN.md b/solution/2600-2699/2638.Count the Number of K-Free Subsets/README_EN.md index 8f3aac9b93d6d..99e97811a4dde 100644 --- a/solution/2600-2699/2638.Count the Number of K-Free Subsets/README_EN.md +++ b/solution/2600-2699/2638.Count the Number of K-Free Subsets/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n \times \log n)$ and the space complexity is $O(n)$, +#### Python3 + ```python class Solution: def countTheNumOfKFreeSubsets(self, nums: List[int], k: int) -> int: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long countTheNumOfKFreeSubsets(int[] nums, int k) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func countTheNumOfKFreeSubsets(nums []int, k int) int64 { sort.Ints(nums) @@ -183,6 +191,8 @@ func countTheNumOfKFreeSubsets(nums []int, k int) int64 { } ``` +#### TypeScript + ```ts function countTheNumOfKFreeSubsets(nums: number[], k: number): number { nums.sort((a, b) => a - b); diff --git a/solution/2600-2699/2639.Find the Width of Columns of a Grid/README.md b/solution/2600-2699/2639.Find the Width of Columns of a Grid/README.md index 59e1cb80322b9..5267d260e3959 100644 --- a/solution/2600-2699/2639.Find the Width of Columns of a Grid/README.md +++ b/solution/2600-2699/2639.Find the Width of Columns of a Grid/README.md @@ -77,12 +77,16 @@ tags: +#### Python3 + ```python class Solution: def findColumnWidth(self, grid: List[List[int]]) -> List[int]: return [max(len(str(x)) for x in col) for col in zip(*grid)] ``` +#### Java + ```java class Solution { public int[] findColumnWidth(int[][] grid) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func findColumnWidth(grid [][]int) []int { ans := make([]int, len(grid[0])) @@ -129,6 +137,8 @@ func findColumnWidth(grid [][]int) []int { } ``` +#### TypeScript + ```ts function findColumnWidth(grid: number[][]): number[] { const n = grid[0].length; @@ -143,6 +153,8 @@ function findColumnWidth(grid: number[][]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn find_column_width(grid: Vec>) -> Vec { diff --git a/solution/2600-2699/2639.Find the Width of Columns of a Grid/README_EN.md b/solution/2600-2699/2639.Find the Width of Columns of a Grid/README_EN.md index f07bfc8132f2d..d0355dd0727f0 100644 --- a/solution/2600-2699/2639.Find the Width of Columns of a Grid/README_EN.md +++ b/solution/2600-2699/2639.Find the Width of Columns of a Grid/README_EN.md @@ -77,12 +77,16 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(\log M)$. +#### Python3 + ```python class Solution: def findColumnWidth(self, grid: List[List[int]]) -> List[int]: return [max(len(str(x)) for x in col) for col in zip(*grid)] ``` +#### Java + ```java class Solution { public int[] findColumnWidth(int[][] grid) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func findColumnWidth(grid [][]int) []int { ans := make([]int, len(grid[0])) @@ -129,6 +137,8 @@ func findColumnWidth(grid [][]int) []int { } ``` +#### TypeScript + ```ts function findColumnWidth(grid: number[][]): number[] { const n = grid[0].length; @@ -143,6 +153,8 @@ function findColumnWidth(grid: number[][]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn find_column_width(grid: Vec>) -> Vec { diff --git a/solution/2600-2699/2640.Find the Score of All Prefixes of an Array/README.md b/solution/2600-2699/2640.Find the Score of All Prefixes of an Array/README.md index 692442b760507..43951723a716b 100644 --- a/solution/2600-2699/2640.Find the Score of All Prefixes of an Array/README.md +++ b/solution/2600-2699/2640.Find the Score of All Prefixes of an Array/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def findPrefixScore(self, nums: List[int]) -> List[int]: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long[] findPrefixScore(int[] nums) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func findPrefixScore(nums []int) []int64 { n := len(nums) @@ -140,6 +148,8 @@ func findPrefixScore(nums []int) []int64 { } ``` +#### TypeScript + ```ts function findPrefixScore(nums: number[]): number[] { const n = nums.length; diff --git a/solution/2600-2699/2640.Find the Score of All Prefixes of an Array/README_EN.md b/solution/2600-2699/2640.Find the Score of All Prefixes of an Array/README_EN.md index 2d2da295e8b52..75cdfd12c3263 100644 --- a/solution/2600-2699/2640.Find the Score of All Prefixes of an Array/README_EN.md +++ b/solution/2600-2699/2640.Find the Score of All Prefixes of an Array/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. Igno +#### Python3 + ```python class Solution: def findPrefixScore(self, nums: List[int]) -> List[int]: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long[] findPrefixScore(int[] nums) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func findPrefixScore(nums []int) []int64 { n := len(nums) @@ -140,6 +148,8 @@ func findPrefixScore(nums []int) []int64 { } ``` +#### TypeScript + ```ts function findPrefixScore(nums: number[]): number[] { const n = nums.length; diff --git a/solution/2600-2699/2641.Cousins in Binary Tree II/README.md b/solution/2600-2699/2641.Cousins in Binary Tree II/README.md index 9ccece09e03cf..c47f0afe07bc7 100644 --- a/solution/2600-2699/2641.Cousins in Binary Tree II/README.md +++ b/solution/2600-2699/2641.Cousins in Binary Tree II/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -123,6 +125,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -178,6 +182,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -228,6 +234,8 @@ private: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -278,6 +286,8 @@ func replaceValueInTree(root *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -343,6 +353,8 @@ function replaceValueInTree(root: TreeNode | null): TreeNode | null { +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -376,6 +388,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -426,6 +440,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -472,6 +488,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -518,6 +536,8 @@ func replaceValueInTree(root *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/2600-2699/2641.Cousins in Binary Tree II/README_EN.md b/solution/2600-2699/2641.Cousins in Binary Tree II/README_EN.md index 87f6288e28448..2b0f516247a68 100644 --- a/solution/2600-2699/2641.Cousins in Binary Tree II/README_EN.md +++ b/solution/2600-2699/2641.Cousins in Binary Tree II/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -117,6 +119,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -172,6 +176,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -222,6 +228,8 @@ private: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -272,6 +280,8 @@ func replaceValueInTree(root *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. @@ -337,6 +347,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -370,6 +382,8 @@ class Solution: return root ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -420,6 +434,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -466,6 +482,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -512,6 +530,8 @@ func replaceValueInTree(root *TreeNode) *TreeNode { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/2600-2699/2642.Design Graph With Shortest Path Calculator/README.md b/solution/2600-2699/2642.Design Graph With Shortest Path Calculator/README.md index 7b75568b955da..f1d9da30ee0ec 100644 --- a/solution/2600-2699/2642.Design Graph With Shortest Path Calculator/README.md +++ b/solution/2600-2699/2642.Design Graph With Shortest Path Calculator/README.md @@ -84,6 +84,8 @@ g.shortestPath(0, 3); // 返回 6 。从 0 到 3 的最短路径为 0 -> 1 -& +#### Python3 + ```python class Graph: def __init__(self, n: int, edges: List[List[int]]): @@ -117,6 +119,8 @@ class Graph: # param_2 = obj.shortestPath(node1,node2) ``` +#### Java + ```java class Graph { private int n; @@ -169,6 +173,8 @@ class Graph { */ ``` +#### C++ + ```cpp class Graph { public: @@ -219,6 +225,8 @@ private: */ ``` +#### Go + ```go const inf = 1 << 29 @@ -280,6 +288,8 @@ func (this *Graph) ShortestPath(node1 int, node2 int) int { */ ``` +#### TypeScript + ```ts class Graph { private g: number[][] = []; @@ -326,6 +336,8 @@ class Graph { */ ``` +#### C# + ```cs public class Graph { private int n; diff --git a/solution/2600-2699/2642.Design Graph With Shortest Path Calculator/README_EN.md b/solution/2600-2699/2642.Design Graph With Shortest Path Calculator/README_EN.md index 6b6e3e3d1d179..631bb04bcd75e 100644 --- a/solution/2600-2699/2642.Design Graph With Shortest Path Calculator/README_EN.md +++ b/solution/2600-2699/2642.Design Graph With Shortest Path Calculator/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n^2 \times q)$, and the space complexity is $O(n^2)$. +#### Python3 + ```python class Graph: def __init__(self, n: int, edges: List[List[int]]): @@ -115,6 +117,8 @@ class Graph: # param_2 = obj.shortestPath(node1,node2) ``` +#### Java + ```java class Graph { private int n; @@ -167,6 +171,8 @@ class Graph { */ ``` +#### C++ + ```cpp class Graph { public: @@ -217,6 +223,8 @@ private: */ ``` +#### Go + ```go const inf = 1 << 29 @@ -278,6 +286,8 @@ func (this *Graph) ShortestPath(node1 int, node2 int) int { */ ``` +#### TypeScript + ```ts class Graph { private g: number[][] = []; @@ -324,6 +334,8 @@ class Graph { */ ``` +#### C# + ```cs public class Graph { private int n; diff --git a/solution/2600-2699/2643.Row With Maximum Ones/README.md b/solution/2600-2699/2643.Row With Maximum Ones/README.md index 085e220ee9ab6..e132cf6a53e76 100644 --- a/solution/2600-2699/2643.Row With Maximum Ones/README.md +++ b/solution/2600-2699/2643.Row With Maximum Ones/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] rowAndMaximumOnes(int[][] mat) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func rowAndMaximumOnes(mat [][]int) []int { ans := make([]int, 2) @@ -145,6 +153,8 @@ func rowAndMaximumOnes(mat [][]int) []int { } ``` +#### TypeScript + ```ts function rowAndMaximumOnes(mat: number[][]): number[] { const ans: number[] = [0, 0]; @@ -159,6 +169,8 @@ function rowAndMaximumOnes(mat: number[][]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn row_and_maximum_ones(mat: Vec>) -> Vec { diff --git a/solution/2600-2699/2643.Row With Maximum Ones/README_EN.md b/solution/2600-2699/2643.Row With Maximum Ones/README_EN.md index 29f0fb6c39a52..98773e363d9c9 100644 --- a/solution/2600-2699/2643.Row With Maximum Ones/README_EN.md +++ b/solution/2600-2699/2643.Row With Maximum Ones/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(m \times n)$, where $m$ and $n$ are the number of rows +#### Python3 + ```python class Solution: def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] rowAndMaximumOnes(int[][] mat) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func rowAndMaximumOnes(mat [][]int) []int { ans := make([]int, 2) @@ -144,6 +152,8 @@ func rowAndMaximumOnes(mat [][]int) []int { } ``` +#### TypeScript + ```ts function rowAndMaximumOnes(mat: number[][]): number[] { const ans: number[] = [0, 0]; @@ -158,6 +168,8 @@ function rowAndMaximumOnes(mat: number[][]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn row_and_maximum_ones(mat: Vec>) -> Vec { diff --git a/solution/2600-2699/2644.Find the Maximum Divisibility Score/README.md b/solution/2600-2699/2644.Find the Maximum Divisibility Score/README.md index f83606b603228..881a460d5d42c 100644 --- a/solution/2600-2699/2644.Find the Maximum Divisibility Score/README.md +++ b/solution/2600-2699/2644.Find the Maximum Divisibility Score/README.md @@ -89,6 +89,8 @@ divisors[1] 的可整除性得分为 0 ,因为 nums 中没有任何数字能 +#### Python3 + ```python class Solution: def maxDivScore(self, nums: List[int], divisors: List[int]) -> int: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxDivScore(int[] nums, int[] divisors) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func maxDivScore(nums []int, divisors []int) int { ans, mx := divisors[0], 0 @@ -169,6 +177,8 @@ func maxDivScore(nums []int, divisors []int) int { } ``` +#### TypeScript + ```ts function maxDivScore(nums: number[], divisors: number[]): number { let ans: number = divisors[0]; @@ -186,6 +196,8 @@ function maxDivScore(nums: number[], divisors: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_div_score(nums: Vec, divisors: Vec) -> i32 { diff --git a/solution/2600-2699/2644.Find the Maximum Divisibility Score/README_EN.md b/solution/2600-2699/2644.Find the Maximum Divisibility Score/README_EN.md index c81a9c40e3ea8..6066481fc4d98 100644 --- a/solution/2600-2699/2644.Find the Maximum Divisibility Score/README_EN.md +++ b/solution/2600-2699/2644.Find the Maximum Divisibility Score/README_EN.md @@ -87,6 +87,8 @@ The time complexity is $O(m \times n)$, where $m$ and $n$ are the lengths of $nu +#### Python3 + ```python class Solution: def maxDivScore(self, nums: List[int], divisors: List[int]) -> int: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxDivScore(int[] nums, int[] divisors) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func maxDivScore(nums []int, divisors []int) int { ans, mx := divisors[0], 0 @@ -167,6 +175,8 @@ func maxDivScore(nums []int, divisors []int) int { } ``` +#### TypeScript + ```ts function maxDivScore(nums: number[], divisors: number[]): number { let ans: number = divisors[0]; @@ -184,6 +194,8 @@ function maxDivScore(nums: number[], divisors: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_div_score(nums: Vec, divisors: Vec) -> i32 { diff --git a/solution/2600-2699/2645.Minimum Additions to Make Valid String/README.md b/solution/2600-2699/2645.Minimum Additions to Make Valid String/README.md index 91148cc001193..9d5df021771f0 100644 --- a/solution/2600-2699/2645.Minimum Additions to Make Valid String/README.md +++ b/solution/2600-2699/2645.Minimum Additions to Make Valid String/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def addMinimum(self, word: str) -> int: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int addMinimum(String word) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func addMinimum(word string) (ans int) { s := "abc" @@ -155,6 +163,8 @@ func addMinimum(word string) (ans int) { } ``` +#### TypeScript + ```ts function addMinimum(word: string): number { const s: string = 'abc'; diff --git a/solution/2600-2699/2645.Minimum Additions to Make Valid String/README_EN.md b/solution/2600-2699/2645.Minimum Additions to Make Valid String/README_EN.md index 3469a7754f917..6a2bb1b9f2dec 100644 --- a/solution/2600-2699/2645.Minimum Additions to Make Valid String/README_EN.md +++ b/solution/2600-2699/2645.Minimum Additions to Make Valid String/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string $word$. The +#### Python3 + ```python class Solution: def addMinimum(self, word: str) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int addMinimum(String word) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func addMinimum(word string) (ans int) { s := "abc" @@ -156,6 +164,8 @@ func addMinimum(word string) (ans int) { } ``` +#### TypeScript + ```ts function addMinimum(word: string): number { const s: string = 'abc'; diff --git a/solution/2600-2699/2646.Minimize the Total Price of the Trips/README.md b/solution/2600-2699/2646.Minimize the Total Price of the Trips/README.md index a1b9780123062..7d3320af197fc 100644 --- a/solution/2600-2699/2646.Minimize the Total Price of the Trips/README.md +++ b/solution/2600-2699/2646.Minimize the Total Price of the Trips/README.md @@ -97,6 +97,8 @@ tags: +#### Python3 + ```python class Solution: def minimumTotalPrice( @@ -131,6 +133,8 @@ class Solution: return min(dfs2(0, -1)) ``` +#### Java + ```java class Solution { private List[] g; @@ -190,6 +194,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -242,6 +248,8 @@ public: }; ``` +#### Go + ```go func minimumTotalPrice(n int, edges [][]int, price []int, trips [][]int) int { g := make([][]int, n) @@ -293,6 +301,8 @@ func minimumTotalPrice(n int, edges [][]int, price []int, trips [][]int) int { } ``` +#### TypeScript + ```ts function minimumTotalPrice( n: number, diff --git a/solution/2600-2699/2646.Minimize the Total Price of the Trips/README_EN.md b/solution/2600-2699/2646.Minimize the Total Price of the Trips/README_EN.md index cdad0f4479015..48163bd54ceb3 100644 --- a/solution/2600-2699/2646.Minimize the Total Price of the Trips/README_EN.md +++ b/solution/2600-2699/2646.Minimize the Total Price of the Trips/README_EN.md @@ -92,6 +92,8 @@ The time complexity is $O(m \times n)$, where $m$ and $n$ are the lengths of $nu +#### Python3 + ```python class Solution: def minimumTotalPrice( @@ -126,6 +128,8 @@ class Solution: return min(dfs2(0, -1)) ``` +#### Java + ```java class Solution { private List[] g; @@ -185,6 +189,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -237,6 +243,8 @@ public: }; ``` +#### Go + ```go func minimumTotalPrice(n int, edges [][]int, price []int, trips [][]int) int { g := make([][]int, n) @@ -288,6 +296,8 @@ func minimumTotalPrice(n int, edges [][]int, price []int, trips [][]int) int { } ``` +#### TypeScript + ```ts function minimumTotalPrice( n: number, diff --git a/solution/2600-2699/2647.Color the Triangle Red/README.md b/solution/2600-2699/2647.Color the Triangle Red/README.md index f8fd3da4f2317..9fa75ee8b339e 100644 --- a/solution/2600-2699/2647.Color the Triangle Red/README.md +++ b/solution/2600-2699/2647.Color the Triangle Red/README.md @@ -104,6 +104,8 @@ tags: +#### Python3 + ```python class Solution: def colorRed(self, n: int) -> List[List[int]]: @@ -124,6 +126,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] colorRed(int n) { @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go func colorRed(n int) (ans [][]int) { ans = append(ans, []int{1, 1}) @@ -197,6 +205,8 @@ func colorRed(n int) (ans [][]int) { } ``` +#### TypeScript + ```ts function colorRed(n: number): number[][] { const ans: number[][] = [[1, 1]]; diff --git a/solution/2600-2699/2647.Color the Triangle Red/README_EN.md b/solution/2600-2699/2647.Color the Triangle Red/README_EN.md index 2f6250e261376..53f140ef11977 100644 --- a/solution/2600-2699/2647.Color the Triangle Red/README_EN.md +++ b/solution/2600-2699/2647.Color the Triangle Red/README_EN.md @@ -103,6 +103,8 @@ The time complexity is $(n^2)$, where $n$ is the parameter given in the problem. +#### Python3 + ```python class Solution: def colorRed(self, n: int) -> List[List[int]]: @@ -123,6 +125,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] colorRed(int n) { @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func colorRed(n int) (ans [][]int) { ans = append(ans, []int{1, 1}) @@ -196,6 +204,8 @@ func colorRed(n int) (ans [][]int) { } ``` +#### TypeScript + ```ts function colorRed(n: number): number[][] { const ans: number[][] = [[1, 1]]; diff --git a/solution/2600-2699/2648.Generate Fibonacci Sequence/README.md b/solution/2600-2699/2648.Generate Fibonacci Sequence/README.md index 384a9e3c89a9f..af8f1ab392ecb 100644 --- a/solution/2600-2699/2648.Generate Fibonacci Sequence/README.md +++ b/solution/2600-2699/2648.Generate Fibonacci Sequence/README.md @@ -62,6 +62,8 @@ gen.next().value; // 3 +#### TypeScript + ```ts function* fibGenerator(): Generator { let a = 0; diff --git a/solution/2600-2699/2648.Generate Fibonacci Sequence/README_EN.md b/solution/2600-2699/2648.Generate Fibonacci Sequence/README_EN.md index 657078a14e005..0e0f9604ef336 100644 --- a/solution/2600-2699/2648.Generate Fibonacci Sequence/README_EN.md +++ b/solution/2600-2699/2648.Generate Fibonacci Sequence/README_EN.md @@ -60,6 +60,8 @@ gen.next().value; // 3 +#### TypeScript + ```ts function* fibGenerator(): Generator { let a = 0; diff --git a/solution/2600-2699/2649.Nested Array Generator/README.md b/solution/2600-2699/2649.Nested Array Generator/README.md index 9cad1fa196f9a..2d2fed70cb754 100644 --- a/solution/2600-2699/2649.Nested Array Generator/README.md +++ b/solution/2600-2699/2649.Nested Array Generator/README.md @@ -63,6 +63,8 @@ generator.next().done; // true +#### TypeScript + ```ts type MultidimensionalArray = (MultidimensionalArray | number)[]; diff --git a/solution/2600-2699/2649.Nested Array Generator/README_EN.md b/solution/2600-2699/2649.Nested Array Generator/README_EN.md index dbb3876070bf9..6a4cb1cf66417 100644 --- a/solution/2600-2699/2649.Nested Array Generator/README_EN.md +++ b/solution/2600-2699/2649.Nested Array Generator/README_EN.md @@ -64,6 +64,8 @@ generator.next().done; // true +#### TypeScript + ```ts type MultidimensionalArray = (MultidimensionalArray | number)[]; diff --git a/solution/2600-2699/2650.Design Cancellable Function/README.md b/solution/2600-2699/2650.Design Cancellable Function/README.md index 99ecc3cb3fb60..cb6daeff1e144 100644 --- a/solution/2600-2699/2650.Design Cancellable Function/README.md +++ b/solution/2600-2699/2650.Design Cancellable Function/README.md @@ -162,6 +162,8 @@ cancelledAt = null +#### TypeScript + ```ts function cancellable(generator: Generator, T, unknown>): [() => void, Promise] { let cancel: () => void = () => {}; diff --git a/solution/2600-2699/2650.Design Cancellable Function/README_EN.md b/solution/2600-2699/2650.Design Cancellable Function/README_EN.md index 0e1bdbd8646c3..38464a395127d 100644 --- a/solution/2600-2699/2650.Design Cancellable Function/README_EN.md +++ b/solution/2600-2699/2650.Design Cancellable Function/README_EN.md @@ -160,6 +160,8 @@ The first yielded promise immediately rejects. This error is caught. Because the +#### TypeScript + ```ts function cancellable(generator: Generator, T, unknown>): [() => void, Promise] { let cancel: () => void = () => {}; diff --git a/solution/2600-2699/2651.Calculate Delayed Arrival Time/README.md b/solution/2600-2699/2651.Calculate Delayed Arrival Time/README.md index 88ca19a0b35b6..b53f430c4d098 100644 --- a/solution/2600-2699/2651.Calculate Delayed Arrival Time/README.md +++ b/solution/2600-2699/2651.Calculate Delayed Arrival Time/README.md @@ -62,12 +62,16 @@ tags: +#### Python3 + ```python class Solution: def findDelayedArrivalTime(self, arrivalTime: int, delayedTime: int) -> int: return (arrivalTime + delayedTime) % 24 ``` +#### Java + ```java class Solution { public int findDelayedArrivalTime(int arrivalTime, int delayedTime) { @@ -76,6 +80,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -85,18 +91,24 @@ public: }; ``` +#### Go + ```go func findDelayedArrivalTime(arrivalTime int, delayedTime int) int { return (arrivalTime + delayedTime) % 24 } ``` +#### TypeScript + ```ts function findDelayedArrivalTime(arrivalTime: number, delayedTime: number): number { return (arrivalTime + delayedTime) % 24; } ``` +#### Rust + ```rust impl Solution { pub fn find_delayed_arrival_time(arrival_time: i32, delayed_time: i32) -> i32 { diff --git a/solution/2600-2699/2651.Calculate Delayed Arrival Time/README_EN.md b/solution/2600-2699/2651.Calculate Delayed Arrival Time/README_EN.md index 069bce772c2c3..1d57b20e48c92 100644 --- a/solution/2600-2699/2651.Calculate Delayed Arrival Time/README_EN.md +++ b/solution/2600-2699/2651.Calculate Delayed Arrival Time/README_EN.md @@ -59,12 +59,16 @@ tags: +#### Python3 + ```python class Solution: def findDelayedArrivalTime(self, arrivalTime: int, delayedTime: int) -> int: return (arrivalTime + delayedTime) % 24 ``` +#### Java + ```java class Solution { public int findDelayedArrivalTime(int arrivalTime, int delayedTime) { @@ -73,6 +77,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -82,18 +88,24 @@ public: }; ``` +#### Go + ```go func findDelayedArrivalTime(arrivalTime int, delayedTime int) int { return (arrivalTime + delayedTime) % 24 } ``` +#### TypeScript + ```ts function findDelayedArrivalTime(arrivalTime: number, delayedTime: number): number { return (arrivalTime + delayedTime) % 24; } ``` +#### Rust + ```rust impl Solution { pub fn find_delayed_arrival_time(arrival_time: i32, delayed_time: i32) -> i32 { diff --git a/solution/2600-2699/2652.Sum Multiples/README.md b/solution/2600-2699/2652.Sum Multiples/README.md index b45735dede95d..8e9d0b0b0d6c8 100644 --- a/solution/2600-2699/2652.Sum Multiples/README.md +++ b/solution/2600-2699/2652.Sum Multiples/README.md @@ -70,12 +70,16 @@ tags: +#### Python3 + ```python class Solution: def sumOfMultiples(self, n: int) -> int: return sum(x for x in range(1, n + 1) if x % 3 == 0 or x % 5 == 0 or x % 7 == 0) ``` +#### Java + ```java class Solution { public int sumOfMultiples(int n) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func sumOfMultiples(n int) (ans int) { for x := 1; x <= n; x++ { @@ -116,6 +124,8 @@ func sumOfMultiples(n int) (ans int) { } ``` +#### TypeScript + ```ts function sumOfMultiples(n: number): number { let ans = 0; @@ -128,6 +138,8 @@ function sumOfMultiples(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn sum_of_multiples(n: i32) -> i32 { @@ -164,6 +176,8 @@ $$ +#### Python3 + ```python class Solution: def sumOfMultiples(self, n: int) -> int: @@ -174,6 +188,8 @@ class Solution: return f(3) + f(5) + f(7) - f(3 * 5) - f(3 * 7) - f(5 * 7) + f(3 * 5 * 7) ``` +#### Java + ```java class Solution { private int n; @@ -190,6 +206,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -203,6 +221,8 @@ public: }; ``` +#### Go + ```go func sumOfMultiples(n int) int { f := func(x int) int { @@ -213,6 +233,8 @@ func sumOfMultiples(n int) int { } ``` +#### TypeScript + ```ts function sumOfMultiples(n: number): number { const f = (x: number): number => { @@ -223,6 +245,8 @@ function sumOfMultiples(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn sum_of_multiples(n: i32) -> i32 { @@ -241,6 +265,8 @@ impl Solution { +#### Rust + ```rust impl Solution { pub fn sum_of_multiples(n: i32) -> i32 { diff --git a/solution/2600-2699/2652.Sum Multiples/README_EN.md b/solution/2600-2699/2652.Sum Multiples/README_EN.md index eb425ddb847b6..a6b36bbc60d09 100644 --- a/solution/2600-2699/2652.Sum Multiples/README_EN.md +++ b/solution/2600-2699/2652.Sum Multiples/README_EN.md @@ -70,12 +70,16 @@ The time complexity is $O(n)$, where $n$ is the given integer. The space complex +#### Python3 + ```python class Solution: def sumOfMultiples(self, n: int) -> int: return sum(x for x in range(1, n + 1) if x % 3 == 0 or x % 5 == 0 or x % 7 == 0) ``` +#### Java + ```java class Solution { public int sumOfMultiples(int n) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func sumOfMultiples(n int) (ans int) { for x := 1; x <= n; x++ { @@ -116,6 +124,8 @@ func sumOfMultiples(n int) (ans int) { } ``` +#### TypeScript + ```ts function sumOfMultiples(n: number): number { let ans = 0; @@ -128,6 +138,8 @@ function sumOfMultiples(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn sum_of_multiples(n: i32) -> i32 { @@ -164,6 +176,8 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def sumOfMultiples(self, n: int) -> int: @@ -174,6 +188,8 @@ class Solution: return f(3) + f(5) + f(7) - f(3 * 5) - f(3 * 7) - f(5 * 7) + f(3 * 5 * 7) ``` +#### Java + ```java class Solution { private int n; @@ -190,6 +206,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -203,6 +221,8 @@ public: }; ``` +#### Go + ```go func sumOfMultiples(n int) int { f := func(x int) int { @@ -213,6 +233,8 @@ func sumOfMultiples(n int) int { } ``` +#### TypeScript + ```ts function sumOfMultiples(n: number): number { const f = (x: number): number => { @@ -223,6 +245,8 @@ function sumOfMultiples(n: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn sum_of_multiples(n: i32) -> i32 { @@ -241,6 +265,8 @@ impl Solution { +#### Rust + ```rust impl Solution { pub fn sum_of_multiples(n: i32) -> i32 { diff --git a/solution/2600-2699/2653.Sliding Subarray Beauty/README.md b/solution/2600-2699/2653.Sliding Subarray Beauty/README.md index ce8b6699f0d1e..96ca078500a57 100644 --- a/solution/2600-2699/2653.Sliding Subarray Beauty/README.md +++ b/solution/2600-2699/2653.Sliding Subarray Beauty/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def getSubarrayBeauty(self, nums: List[int], k: int, x: int) -> List[int]: @@ -114,6 +116,8 @@ class Solution: return ans ``` +#### Python3 + ```python from sortedcontainers import SortedList @@ -129,6 +133,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] getSubarrayBeauty(int[] nums, int k, int x) { @@ -160,6 +166,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -191,6 +199,8 @@ public: }; ``` +#### Go + ```go func getSubarrayBeauty(nums []int, k int, x int) []int { n := len(nums) @@ -219,6 +229,8 @@ func getSubarrayBeauty(nums []int, k int, x int) []int { } ``` +#### TypeScript + ```ts function getSubarrayBeauty(nums: number[], k: number, x: number): number[] { const n = nums.length; @@ -283,6 +295,8 @@ function getSubarrayBeauty(nums: number[], k: number, x: number): number[] { +#### Python3 + ```python class MedianFinder: def __init__(self, x: int): @@ -354,6 +368,8 @@ class Solution: return ans ``` +#### Java + ```java class MedianFinder { private PriorityQueue small = new PriorityQueue<>(Comparator.reverseOrder()); @@ -447,6 +463,8 @@ class Solution { } ``` +#### C++ + ```cpp class MedianFinder { public: @@ -546,6 +564,8 @@ public: }; ``` +#### Go + ```go type MedianFinder struct { small hp diff --git a/solution/2600-2699/2653.Sliding Subarray Beauty/README_EN.md b/solution/2600-2699/2653.Sliding Subarray Beauty/README_EN.md index 272e2fa20bf39..33594f7b46342 100644 --- a/solution/2600-2699/2653.Sliding Subarray Beauty/README_EN.md +++ b/solution/2600-2699/2653.Sliding Subarray Beauty/README_EN.md @@ -93,6 +93,8 @@ The time complexity is $O(n \times 50)$, and the space complexity is $O(100)$. W +#### Python3 + ```python class Solution: def getSubarrayBeauty(self, nums: List[int], k: int, x: int) -> List[int]: @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Python3 + ```python from sortedcontainers import SortedList @@ -130,6 +134,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] getSubarrayBeauty(int[] nums, int k, int x) { @@ -161,6 +167,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -192,6 +200,8 @@ public: }; ``` +#### Go + ```go func getSubarrayBeauty(nums []int, k int, x int) []int { n := len(nums) @@ -220,6 +230,8 @@ func getSubarrayBeauty(nums []int, k int, x int) []int { } ``` +#### TypeScript + ```ts function getSubarrayBeauty(nums: number[], k: number, x: number): number[] { const n = nums.length; @@ -284,6 +296,8 @@ Similar problems: +#### Python3 + ```python class MedianFinder: def __init__(self, x: int): @@ -355,6 +369,8 @@ class Solution: return ans ``` +#### Java + ```java class MedianFinder { private PriorityQueue small = new PriorityQueue<>(Comparator.reverseOrder()); @@ -448,6 +464,8 @@ class Solution { } ``` +#### C++ + ```cpp class MedianFinder { public: @@ -547,6 +565,8 @@ public: }; ``` +#### Go + ```go type MedianFinder struct { small hp diff --git a/solution/2600-2699/2654.Minimum Number of Operations to Make All Array Elements Equal to 1/README.md b/solution/2600-2699/2654.Minimum Number of Operations to Make All Array Elements Equal to 1/README.md index 70b671929a994..3c9486ab851ac 100644 --- a/solution/2600-2699/2654.Minimum Number of Operations to Make All Array Elements Equal to 1/README.md +++ b/solution/2600-2699/2654.Minimum Number of Operations to Make All Array Elements Equal to 1/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int]) -> int: @@ -94,6 +96,8 @@ class Solution: return -1 if mi > n else n - 1 + mi - 1 ``` +#### Java + ```java class Solution { public int minOperations(int[] nums) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int) int { n := len(nums) @@ -191,6 +199,8 @@ func gcd(a, b int) int { } ``` +#### TypeScript + ```ts function minOperations(nums: number[]): number { const n = nums.length; diff --git a/solution/2600-2699/2654.Minimum Number of Operations to Make All Array Elements Equal to 1/README_EN.md b/solution/2600-2699/2654.Minimum Number of Operations to Make All Array Elements Equal to 1/README_EN.md index 3e948a48200ea..89e788cf442fd 100644 --- a/solution/2600-2699/2654.Minimum Number of Operations to Make All Array Elements Equal to 1/README_EN.md +++ b/solution/2600-2699/2654.Minimum Number of Operations to Make All Array Elements Equal to 1/README_EN.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int]) -> int: @@ -86,6 +88,8 @@ class Solution: return -1 if mi > n else n - 1 + mi - 1 ``` +#### Java + ```java class Solution { public int minOperations(int[] nums) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int) int { n := len(nums) @@ -183,6 +191,8 @@ func gcd(a, b int) int { } ``` +#### TypeScript + ```ts function minOperations(nums: number[]): number { const n = nums.length; diff --git a/solution/2600-2699/2655.Find Maximal Uncovered Ranges/README.md b/solution/2600-2699/2655.Find Maximal Uncovered Ranges/README.md index 864177f124021..068b97848071c 100644 --- a/solution/2600-2699/2655.Find Maximal Uncovered Ranges/README.md +++ b/solution/2600-2699/2655.Find Maximal Uncovered Ranges/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def findMaximalUncoveredRanges( @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] findMaximalUncoveredRanges(int n, int[][] ranges) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func findMaximalUncoveredRanges(n int, ranges [][]int) (ans [][]int) { sort.Slice(ranges, func(i, j int) bool { return ranges[i][0] < ranges[j][0] }) diff --git a/solution/2600-2699/2655.Find Maximal Uncovered Ranges/README_EN.md b/solution/2600-2699/2655.Find Maximal Uncovered Ranges/README_EN.md index 50c17ab28d0f0..48e350fc88fb0 100644 --- a/solution/2600-2699/2655.Find Maximal Uncovered Ranges/README_EN.md +++ b/solution/2600-2699/2655.Find Maximal Uncovered Ranges/README_EN.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def findMaximalUncoveredRanges( @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] findMaximalUncoveredRanges(int n, int[][] ranges) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func findMaximalUncoveredRanges(n int, ranges [][]int) (ans [][]int) { sort.Slice(ranges, func(i, j int) bool { return ranges[i][0] < ranges[j][0] }) diff --git a/solution/2600-2699/2656.Maximum Sum With Exactly K Elements/README.md b/solution/2600-2699/2656.Maximum Sum With Exactly K Elements/README.md index f1281ac931944..6b84427881b67 100644 --- a/solution/2600-2699/2656.Maximum Sum With Exactly K Elements/README.md +++ b/solution/2600-2699/2656.Maximum Sum With Exactly K Elements/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def maximizeSum(self, nums: List[int], k: int) -> int: @@ -88,6 +90,8 @@ class Solution: return k * x + k * (k - 1) // 2 ``` +#### Java + ```java class Solution { public int maximizeSum(int[] nums, int k) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func maximizeSum(nums []int, k int) int { x := slices.Max(nums) @@ -117,6 +125,8 @@ func maximizeSum(nums []int, k int) int { } ``` +#### TypeScript + ```ts function maximizeSum(nums: number[], k: number): number { const x = Math.max(...nums); @@ -124,6 +134,8 @@ function maximizeSum(nums: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn maximize_sum(nums: Vec, k: i32) -> i32 { @@ -150,6 +162,8 @@ impl Solution { +#### Rust + ```rust impl Solution { pub fn maximize_sum(nums: Vec, k: i32) -> i32 { diff --git a/solution/2600-2699/2656.Maximum Sum With Exactly K Elements/README_EN.md b/solution/2600-2699/2656.Maximum Sum With Exactly K Elements/README_EN.md index be1ffa6cc7b4f..cf4a71119505b 100644 --- a/solution/2600-2699/2656.Maximum Sum With Exactly K Elements/README_EN.md +++ b/solution/2600-2699/2656.Maximum Sum With Exactly K Elements/README_EN.md @@ -88,6 +88,8 @@ Time complexity is $O(n)$, where $n$ is the length of the array. Space complexit +#### Python3 + ```python class Solution: def maximizeSum(self, nums: List[int], k: int) -> int: @@ -95,6 +97,8 @@ class Solution: return k * x + k * (k - 1) // 2 ``` +#### Java + ```java class Solution { public int maximizeSum(int[] nums, int k) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func maximizeSum(nums []int, k int) int { x := slices.Max(nums) @@ -124,6 +132,8 @@ func maximizeSum(nums []int, k int) int { } ``` +#### TypeScript + ```ts function maximizeSum(nums: number[], k: number): number { const x = Math.max(...nums); @@ -131,6 +141,8 @@ function maximizeSum(nums: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn maximize_sum(nums: Vec, k: i32) -> i32 { @@ -157,6 +169,8 @@ impl Solution { +#### Rust + ```rust impl Solution { pub fn maximize_sum(nums: Vec, k: i32) -> i32 { diff --git a/solution/2600-2699/2657.Find the Prefix Common Array of Two Arrays/README.md b/solution/2600-2699/2657.Find the Prefix Common Array of Two Arrays/README.md index 73d8ae2946b28..e0bfe58e23e11 100644 --- a/solution/2600-2699/2657.Find the Prefix Common Array of Two Arrays/README.md +++ b/solution/2600-2699/2657.Find the Prefix Common Array of Two Arrays/README.md @@ -77,6 +77,8 @@ i = 2:1,2 和 3 是两个数组的前缀公共元素,所以 C[2] = 3 。 +#### Python3 + ```python class Solution: def findThePrefixCommonArray(self, A: List[int], B: List[int]) -> List[int]: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] findThePrefixCommonArray(int[] A, int[] B) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func findThePrefixCommonArray(A []int, B []int) []int { n := len(A) @@ -147,6 +155,8 @@ func findThePrefixCommonArray(A []int, B []int) []int { } ``` +#### TypeScript + ```ts function findThePrefixCommonArray(A: number[], B: number[]): number[] { const n = A.length; @@ -184,6 +194,8 @@ function findThePrefixCommonArray(A: number[], B: number[]): number[] { +#### Python3 + ```python class Solution: def findThePrefixCommonArray(self, A: List[int], B: List[int]) -> List[int]: @@ -199,6 +211,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] findThePrefixCommonArray(int[] A, int[] B) { @@ -219,6 +233,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -239,6 +255,8 @@ public: }; ``` +#### Go + ```go func findThePrefixCommonArray(A []int, B []int) (ans []int) { vis := make([]int, len(A)+1) @@ -258,6 +276,8 @@ func findThePrefixCommonArray(A []int, B []int) (ans []int) { } ``` +#### TypeScript + ```ts function findThePrefixCommonArray(A: number[], B: number[]): number[] { const n = A.length; diff --git a/solution/2600-2699/2657.Find the Prefix Common Array of Two Arrays/README_EN.md b/solution/2600-2699/2657.Find the Prefix Common Array of Two Arrays/README_EN.md index 7a03f6572649c..12976a4d9baad 100644 --- a/solution/2600-2699/2657.Find the Prefix Common Array of Two Arrays/README_EN.md +++ b/solution/2600-2699/2657.Find the Prefix Common Array of Two Arrays/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$. Here, $n$ i +#### Python3 + ```python class Solution: def findThePrefixCommonArray(self, A: List[int], B: List[int]) -> List[int]: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] findThePrefixCommonArray(int[] A, int[] B) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func findThePrefixCommonArray(A []int, B []int) []int { n := len(A) @@ -147,6 +155,8 @@ func findThePrefixCommonArray(A []int, B []int) []int { } ``` +#### TypeScript + ```ts function findThePrefixCommonArray(A: number[], B: number[]): number[] { const n = A.length; @@ -184,6 +194,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def findThePrefixCommonArray(self, A: List[int], B: List[int]) -> List[int]: @@ -199,6 +211,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] findThePrefixCommonArray(int[] A, int[] B) { @@ -219,6 +233,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -239,6 +255,8 @@ public: }; ``` +#### Go + ```go func findThePrefixCommonArray(A []int, B []int) (ans []int) { vis := make([]int, len(A)+1) @@ -258,6 +276,8 @@ func findThePrefixCommonArray(A []int, B []int) (ans []int) { } ``` +#### TypeScript + ```ts function findThePrefixCommonArray(A: number[], B: number[]): number[] { const n = A.length; diff --git a/solution/2600-2699/2658.Maximum Number of Fish in a Grid/README.md b/solution/2600-2699/2658.Maximum Number of Fish in a Grid/README.md index c99a7ca1192f8..65ec03c579188 100644 --- a/solution/2600-2699/2658.Maximum Number of Fish in a Grid/README.md +++ b/solution/2600-2699/2658.Maximum Number of Fish in a Grid/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def findMaxFish(self, grid: List[List[int]]) -> int: @@ -112,6 +114,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[][] grid; @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -178,6 +184,8 @@ public: }; ``` +#### Go + ```go func findMaxFish(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -205,6 +213,8 @@ func findMaxFish(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function findMaxFish(grid: number[][]): number { const m = grid.length; diff --git a/solution/2600-2699/2658.Maximum Number of Fish in a Grid/README_EN.md b/solution/2600-2699/2658.Maximum Number of Fish in a Grid/README_EN.md index 1de199a5dc32f..112ea0843bcc8 100644 --- a/solution/2600-2699/2658.Maximum Number of Fish in a Grid/README_EN.md +++ b/solution/2600-2699/2658.Maximum Number of Fish in a Grid/README_EN.md @@ -87,6 +87,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def findMaxFish(self, grid: List[List[int]]) -> int: @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[][] grid; @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func findMaxFish(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -201,6 +209,8 @@ func findMaxFish(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function findMaxFish(grid: number[][]): number { const m = grid.length; diff --git a/solution/2600-2699/2659.Make Array Empty/README.md b/solution/2600-2699/2659.Make Array Empty/README.md index e251ee555fa86..f2b9c92358653 100644 --- a/solution/2600-2699/2659.Make Array Empty/README.md +++ b/solution/2600-2699/2659.Make Array Empty/README.md @@ -173,6 +173,8 @@ tags: +#### Python3 + ```python from sortedcontainers import SortedList @@ -192,6 +194,8 @@ class Solution: return ans ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -240,6 +244,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -290,6 +296,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -339,6 +347,8 @@ func countOperationsToEmptyArray(nums []int) int64 { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; @@ -399,6 +409,8 @@ function countOperationsToEmptyArray(nums: number[]): number { +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): diff --git a/solution/2600-2699/2659.Make Array Empty/README_EN.md b/solution/2600-2699/2659.Make Array Empty/README_EN.md index 4143b44ee2790..a81bbd04fcd5b 100644 --- a/solution/2600-2699/2659.Make Array Empty/README_EN.md +++ b/solution/2600-2699/2659.Make Array Empty/README_EN.md @@ -167,6 +167,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python from sortedcontainers import SortedList @@ -186,6 +188,8 @@ class Solution: return ans ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -234,6 +238,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { public: @@ -284,6 +290,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -333,6 +341,8 @@ func countOperationsToEmptyArray(nums []int) int64 { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; @@ -393,6 +403,8 @@ function countOperationsToEmptyArray(nums: number[]): number { +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n): diff --git a/solution/2600-2699/2660.Determine the Winner of a Bowling Game/README.md b/solution/2600-2699/2660.Determine the Winner of a Bowling Game/README.md index 9dcdcd76a749e..d1344e9362b27 100644 --- a/solution/2600-2699/2660.Determine the Winner of a Bowling Game/README.md +++ b/solution/2600-2699/2660.Determine the Winner of a Bowling Game/README.md @@ -95,6 +95,8 @@ player1 的得分等于 player2 的得分,所以这一场比赛平局,答案 +#### Python3 + ```python class Solution: def isWinner(self, player1: List[int], player2: List[int]) -> int: @@ -109,6 +111,8 @@ class Solution: return 1 if a > b else (2 if b > a else 0) ``` +#### Java + ```java class Solution { public int isWinner(int[] player1, int[] player2) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func isWinner(player1 []int, player2 []int) int { f := func(arr []int) int { @@ -169,6 +177,8 @@ func isWinner(player1 []int, player2 []int) int { } ``` +#### TypeScript + ```ts function isWinner(player1: number[], player2: number[]): number { const f = (arr: number[]): number => { @@ -187,6 +197,8 @@ function isWinner(player1: number[], player2: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn is_winner(player1: Vec, player2: Vec) -> i32 { diff --git a/solution/2600-2699/2660.Determine the Winner of a Bowling Game/README_EN.md b/solution/2600-2699/2660.Determine the Winner of a Bowling Game/README_EN.md index a4c4ca50317af..decee37cdb66f 100644 --- a/solution/2600-2699/2660.Determine the Winner of a Bowling Game/README_EN.md +++ b/solution/2600-2699/2660.Determine the Winner of a Bowling Game/README_EN.md @@ -95,6 +95,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def isWinner(self, player1: List[int], player2: List[int]) -> int: @@ -109,6 +111,8 @@ class Solution: return 1 if a > b else (2 if b > a else 0) ``` +#### Java + ```java class Solution { public int isWinner(int[] player1, int[] player2) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func isWinner(player1 []int, player2 []int) int { f := func(arr []int) int { @@ -169,6 +177,8 @@ func isWinner(player1 []int, player2 []int) int { } ``` +#### TypeScript + ```ts function isWinner(player1: number[], player2: number[]): number { const f = (arr: number[]): number => { @@ -187,6 +197,8 @@ function isWinner(player1: number[], player2: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn is_winner(player1: Vec, player2: Vec) -> i32 { diff --git a/solution/2600-2699/2661.First Completely Painted Row or Column/README.md b/solution/2600-2699/2661.First Completely Painted Row or Column/README.md index 48fdb8ace2ff1..21cb7475671b0 100644 --- a/solution/2600-2699/2661.First Completely Painted Row or Column/README.md +++ b/solution/2600-2699/2661.First Completely Painted Row or Column/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def firstCompleteIndex(self, arr: List[int], mat: List[List[int]]) -> int: @@ -93,6 +95,8 @@ class Solution: return k ``` +#### Java + ```java class Solution { public int firstCompleteIndex(int[] arr, int[][] mat) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func firstCompleteIndex(arr []int, mat [][]int) int { m, n := len(mat), len(mat[0]) @@ -165,6 +173,8 @@ func firstCompleteIndex(arr []int, mat [][]int) int { } ``` +#### TypeScript + ```ts function firstCompleteIndex(arr: number[], mat: number[][]): number { const m = mat.length; @@ -188,6 +198,8 @@ function firstCompleteIndex(arr: number[], mat: number[][]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/2600-2699/2661.First Completely Painted Row or Column/README_EN.md b/solution/2600-2699/2661.First Completely Painted Row or Column/README_EN.md index 42e378c903749..d10a79f93d32c 100644 --- a/solution/2600-2699/2661.First Completely Painted Row or Column/README_EN.md +++ b/solution/2600-2699/2661.First Completely Painted Row or Column/README_EN.md @@ -73,6 +73,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def firstCompleteIndex(self, arr: List[int], mat: List[List[int]]) -> int: @@ -91,6 +93,8 @@ class Solution: return k ``` +#### Java + ```java class Solution { public int firstCompleteIndex(int[] arr, int[][] mat) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func firstCompleteIndex(arr []int, mat [][]int) int { m, n := len(mat), len(mat[0]) @@ -163,6 +171,8 @@ func firstCompleteIndex(arr []int, mat [][]int) int { } ``` +#### TypeScript + ```ts function firstCompleteIndex(arr: number[], mat: number[][]): number { const m = mat.length; @@ -186,6 +196,8 @@ function firstCompleteIndex(arr: number[], mat: number[][]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/2600-2699/2662.Minimum Cost of a Path With Special Roads/README.md b/solution/2600-2699/2662.Minimum Cost of a Path With Special Roads/README.md index 8e97f342f1e89..5338eb6cd49d8 100644 --- a/solution/2600-2699/2662.Minimum Cost of a Path With Special Roads/README.md +++ b/solution/2600-2699/2662.Minimum Cost of a Path With Special Roads/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def minimumCost( @@ -110,6 +112,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumCost(int[] start, int[] target, int[][] specialRoads) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go func minimumCost(start []int, target []int, specialRoads [][]int) int { ans := 1 << 30 @@ -219,6 +227,8 @@ func (h *hp) Push(v any) { *h = append(*h, v.(tuple)) } func (h *hp) Pop() any { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; return v } ``` +#### TypeScript + ```ts function minimumCost(start: number[], target: number[], specialRoads: number[][]): number { const dist = (x1: number, y1: number, x2: number, y2: number): number => { diff --git a/solution/2600-2699/2662.Minimum Cost of a Path With Special Roads/README_EN.md b/solution/2600-2699/2662.Minimum Cost of a Path With Special Roads/README_EN.md index 10ab5d5911c08..d52ede0b94f62 100644 --- a/solution/2600-2699/2662.Minimum Cost of a Path With Special Roads/README_EN.md +++ b/solution/2600-2699/2662.Minimum Cost of a Path With Special Roads/README_EN.md @@ -88,6 +88,8 @@ The time complexity is $O(n^2 \times \log n)$, and the space complexity is $O(n^ +#### Python3 + ```python class Solution: def minimumCost( @@ -110,6 +112,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumCost(int[] start, int[] target, int[][] specialRoads) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go func minimumCost(start []int, target []int, specialRoads [][]int) int { ans := 1 << 30 @@ -219,6 +227,8 @@ func (h *hp) Push(v any) { *h = append(*h, v.(tuple)) } func (h *hp) Pop() any { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; return v } ``` +#### TypeScript + ```ts function minimumCost(start: number[], target: number[], specialRoads: number[][]): number { const dist = (x1: number, y1: number, x2: number, y2: number): number => { diff --git a/solution/2600-2699/2663.Lexicographically Smallest Beautiful String/README.md b/solution/2600-2699/2663.Lexicographically Smallest Beautiful String/README.md index aaed390361ff7..b8723beddc0f0 100644 --- a/solution/2600-2699/2663.Lexicographically Smallest Beautiful String/README.md +++ b/solution/2600-2699/2663.Lexicographically Smallest Beautiful String/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def smallestBeautifulString(self, s: str, k: int) -> str: @@ -106,6 +108,8 @@ class Solution: return '' ``` +#### Java + ```java class Solution { public String smallestBeautifulString(String s, int k) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func smallestBeautifulString(s string, k int) string { cs := []byte(s) @@ -197,6 +205,8 @@ func smallestBeautifulString(s string, k int) string { } ``` +#### TypeScript + ```ts function smallestBeautifulString(s: string, k: number): string { const cs: string[] = s.split(''); diff --git a/solution/2600-2699/2663.Lexicographically Smallest Beautiful String/README_EN.md b/solution/2600-2699/2663.Lexicographically Smallest Beautiful String/README_EN.md index 899c9b2df13ed..c4b38adea2515 100644 --- a/solution/2600-2699/2663.Lexicographically Smallest Beautiful String/README_EN.md +++ b/solution/2600-2699/2663.Lexicographically Smallest Beautiful String/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string. The space +#### Python3 + ```python class Solution: def smallestBeautifulString(self, s: str, k: int) -> str: @@ -105,6 +107,8 @@ class Solution: return '' ``` +#### Java + ```java class Solution { public String smallestBeautifulString(String s, int k) { @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func smallestBeautifulString(s string, k int) string { cs := []byte(s) @@ -196,6 +204,8 @@ func smallestBeautifulString(s string, k int) string { } ``` +#### TypeScript + ```ts function smallestBeautifulString(s: string, k: number): string { const cs: string[] = s.split(''); diff --git "a/solution/2600-2699/2664.The Knight\342\200\231s Tour/README.md" "b/solution/2600-2699/2664.The Knight\342\200\231s Tour/README.md" index 9ac42ef137109..e584eefb079f4 100644 --- "a/solution/2600-2699/2664.The Knight\342\200\231s Tour/README.md" +++ "b/solution/2600-2699/2664.The Knight\342\200\231s Tour/README.md" @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def tourOfKnight(self, m: int, n: int, r: int, c: int) -> List[List[int]]: @@ -97,6 +99,8 @@ class Solution: return g ``` +#### Java + ```java class Solution { private int[][] g; @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func tourOfKnight(m int, n int, r int, c int) [][]int { g := make([][]int, m) @@ -203,6 +211,8 @@ func tourOfKnight(m int, n int, r int, c int) [][]int { } ``` +#### TypeScript + ```ts function tourOfKnight(m: number, n: number, r: number, c: number): number[][] { const g: number[][] = Array.from({ length: m }, () => Array(n).fill(-1)); @@ -231,6 +241,8 @@ function tourOfKnight(m: number, n: number, r: number, c: number): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn tour_of_knight(m: i32, n: i32, r: i32, c: i32) -> Vec> { diff --git "a/solution/2600-2699/2664.The Knight\342\200\231s Tour/README_EN.md" "b/solution/2600-2699/2664.The Knight\342\200\231s Tour/README_EN.md" index cfcf53c482d77..62831fb7b9126 100644 --- "a/solution/2600-2699/2664.The Knight\342\200\231s Tour/README_EN.md" +++ "b/solution/2600-2699/2664.The Knight\342\200\231s Tour/README_EN.md" @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def tourOfKnight(self, m: int, n: int, r: int, c: int) -> List[List[int]]: @@ -87,6 +89,8 @@ class Solution: return g ``` +#### Java + ```java class Solution { private int[][] g; @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func tourOfKnight(m int, n int, r int, c int) [][]int { g := make([][]int, m) @@ -193,6 +201,8 @@ func tourOfKnight(m int, n int, r int, c int) [][]int { } ``` +#### TypeScript + ```ts function tourOfKnight(m: number, n: number, r: number, c: number): number[][] { const g: number[][] = Array.from({ length: m }, () => Array(n).fill(-1)); @@ -221,6 +231,8 @@ function tourOfKnight(m: number, n: number, r: number, c: number): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn tour_of_knight(m: i32, n: i32, r: i32, c: i32) -> Vec> { diff --git a/solution/2600-2699/2665.Counter II/README.md b/solution/2600-2699/2665.Counter II/README.md index b37dff5149023..246494a7183cf 100644 --- a/solution/2600-2699/2665.Counter II/README.md +++ b/solution/2600-2699/2665.Counter II/README.md @@ -72,6 +72,8 @@ counter.reset(); // 0 +#### TypeScript + ```ts type ReturnObj = { increment: () => number; diff --git a/solution/2600-2699/2665.Counter II/README_EN.md b/solution/2600-2699/2665.Counter II/README_EN.md index bd5e6ddb07a83..aa013e790a850 100644 --- a/solution/2600-2699/2665.Counter II/README_EN.md +++ b/solution/2600-2699/2665.Counter II/README_EN.md @@ -70,6 +70,8 @@ counter.reset(); // 0 +#### TypeScript + ```ts type ReturnObj = { increment: () => number; diff --git a/solution/2600-2699/2666.Allow One Function Call/README.md b/solution/2600-2699/2666.Allow One Function Call/README.md index fa24590088fec..4f4a3e6c685e6 100644 --- a/solution/2600-2699/2666.Allow One Function Call/README.md +++ b/solution/2600-2699/2666.Allow One Function Call/README.md @@ -67,6 +67,8 @@ onceFn(4, 6, 8); // undefined, fn 没有被调用 +#### TypeScript + ```ts function once any>( fn: T, diff --git a/solution/2600-2699/2666.Allow One Function Call/README_EN.md b/solution/2600-2699/2666.Allow One Function Call/README_EN.md index 63b889617afba..540b24580e47f 100644 --- a/solution/2600-2699/2666.Allow One Function Call/README_EN.md +++ b/solution/2600-2699/2666.Allow One Function Call/README_EN.md @@ -65,6 +65,8 @@ onceFn(4, 6, 8); // undefined, fn was not called +#### TypeScript + ```ts function once any>( fn: T, diff --git a/solution/2600-2699/2667.Create Hello World Function/README.md b/solution/2600-2699/2667.Create Hello World Function/README.md index 38b4dbced8b6d..a207569bbf76b 100644 --- a/solution/2600-2699/2667.Create Hello World Function/README.md +++ b/solution/2600-2699/2667.Create Hello World Function/README.md @@ -60,6 +60,8 @@ f({}, null, 42); // "Hello World" +#### TypeScript + ```ts function createHelloWorld() { return function (...args): string { diff --git a/solution/2600-2699/2667.Create Hello World Function/README_EN.md b/solution/2600-2699/2667.Create Hello World Function/README_EN.md index 7dbb9f754fe02..fba21f6b7d30b 100644 --- a/solution/2600-2699/2667.Create Hello World Function/README_EN.md +++ b/solution/2600-2699/2667.Create Hello World Function/README_EN.md @@ -58,6 +58,8 @@ Any arguments could be passed to the function but it should still always return +#### TypeScript + ```ts function createHelloWorld() { return function (...args): string { diff --git a/solution/2600-2699/2668.Find Latest Salaries/README.md b/solution/2600-2699/2668.Find Latest Salaries/README.md index 45da5f4d9cccd..da79c4e994d18 100644 --- a/solution/2600-2699/2668.Find Latest Salaries/README.md +++ b/solution/2600-2699/2668.Find Latest Salaries/README.md @@ -89,6 +89,8 @@ tags: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2600-2699/2668.Find Latest Salaries/README_EN.md b/solution/2600-2699/2668.Find Latest Salaries/README_EN.md index 9947484d458d5..48366df3fed31 100644 --- a/solution/2600-2699/2668.Find Latest Salaries/README_EN.md +++ b/solution/2600-2699/2668.Find Latest Salaries/README_EN.md @@ -89,6 +89,8 @@ Each row contains employees details and their yearly salaries, however, some of +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2600-2699/2669.Count Artist Occurrences On Spotify Ranking List/README.md b/solution/2600-2699/2669.Count Artist Occurrences On Spotify Ranking List/README.md index 2c03fdb8d8eaa..b747c46c700e5 100644 --- a/solution/2600-2699/2669.Count Artist Occurrences On Spotify Ranking List/README.md +++ b/solution/2600-2699/2669.Count Artist Occurrences On Spotify Ranking List/README.md @@ -74,6 +74,8 @@ id 是该表的主键(具有唯一值的列)。 +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2600-2699/2669.Count Artist Occurrences On Spotify Ranking List/README_EN.md b/solution/2600-2699/2669.Count Artist Occurrences On Spotify Ranking List/README_EN.md index dcfeff38bd831..f903658284f97 100644 --- a/solution/2600-2699/2669.Count Artist Occurrences On Spotify Ranking List/README_EN.md +++ b/solution/2600-2699/2669.Count Artist Occurrences On Spotify Ranking List/README_EN.md @@ -73,6 +73,8 @@ Each row contains an id, track_name, and artist. +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2600-2699/2670.Find the Distinct Difference Array/README.md b/solution/2600-2699/2670.Find the Distinct Difference Array/README.md index f4c9d6735d883..589e0961be90d 100644 --- a/solution/2600-2699/2670.Find the Distinct Difference Array/README.md +++ b/solution/2600-2699/2670.Find the Distinct Difference Array/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def distinctDifferenceArray(self, nums: List[int]) -> List[int]: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] distinctDifferenceArray(int[] nums) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func distinctDifferenceArray(nums []int) []int { n := len(nums) @@ -159,6 +167,8 @@ func distinctDifferenceArray(nums []int) []int { } ``` +#### TypeScript + ```ts function distinctDifferenceArray(nums: number[]): number[] { const n = nums.length; @@ -178,6 +188,8 @@ function distinctDifferenceArray(nums: number[]): number[] { } ``` +#### Rust + ```rust use std::collections::HashSet; diff --git a/solution/2600-2699/2670.Find the Distinct Difference Array/README_EN.md b/solution/2600-2699/2670.Find the Distinct Difference Array/README_EN.md index 9d0e74268fdb3..78b17b6e214b8 100644 --- a/solution/2600-2699/2670.Find the Distinct Difference Array/README_EN.md +++ b/solution/2600-2699/2670.Find the Distinct Difference Array/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def distinctDifferenceArray(self, nums: List[int]) -> List[int]: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] distinctDifferenceArray(int[] nums) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func distinctDifferenceArray(nums []int) []int { n := len(nums) @@ -155,6 +163,8 @@ func distinctDifferenceArray(nums []int) []int { } ``` +#### TypeScript + ```ts function distinctDifferenceArray(nums: number[]): number[] { const n = nums.length; @@ -174,6 +184,8 @@ function distinctDifferenceArray(nums: number[]): number[] { } ``` +#### Rust + ```rust use std::collections::HashSet; diff --git a/solution/2600-2699/2671.Frequency Tracker/README.md b/solution/2600-2699/2671.Frequency Tracker/README.md index a075c5b53ba5e..032e6d06ffbbf 100644 --- a/solution/2600-2699/2671.Frequency Tracker/README.md +++ b/solution/2600-2699/2671.Frequency Tracker/README.md @@ -110,6 +110,8 @@ frequencyTracker.hasFrequency(1); // 返回 true ,因为 3 出现 1 次 +#### Python3 + ```python class FrequencyTracker: def __init__(self): @@ -138,6 +140,8 @@ class FrequencyTracker: # param_3 = obj.hasFrequency(frequency) ``` +#### Java + ```java class FrequencyTracker { private Map cnt = new HashMap<>(); @@ -174,6 +178,8 @@ class FrequencyTracker { */ ``` +#### C++ + ```cpp class FrequencyTracker { public: @@ -212,6 +218,8 @@ private: */ ``` +#### Go + ```go type FrequencyTracker struct { cnt map[int]int @@ -249,6 +257,8 @@ func (this *FrequencyTracker) HasFrequency(frequency int) bool { */ ``` +#### TypeScript + ```ts class FrequencyTracker { private cnt: Map; @@ -289,6 +299,8 @@ class FrequencyTracker { */ ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/2600-2699/2671.Frequency Tracker/README_EN.md b/solution/2600-2699/2671.Frequency Tracker/README_EN.md index ff08c3cec54cc..c1475cc1081c2 100644 --- a/solution/2600-2699/2671.Frequency Tracker/README_EN.md +++ b/solution/2600-2699/2671.Frequency Tracker/README_EN.md @@ -111,6 +111,8 @@ In terms of time complexity, since we use hash tables, the time complexity of ea +#### Python3 + ```python class FrequencyTracker: def __init__(self): @@ -139,6 +141,8 @@ class FrequencyTracker: # param_3 = obj.hasFrequency(frequency) ``` +#### Java + ```java class FrequencyTracker { private Map cnt = new HashMap<>(); @@ -175,6 +179,8 @@ class FrequencyTracker { */ ``` +#### C++ + ```cpp class FrequencyTracker { public: @@ -213,6 +219,8 @@ private: */ ``` +#### Go + ```go type FrequencyTracker struct { cnt map[int]int @@ -250,6 +258,8 @@ func (this *FrequencyTracker) HasFrequency(frequency int) bool { */ ``` +#### TypeScript + ```ts class FrequencyTracker { private cnt: Map; @@ -290,6 +300,8 @@ class FrequencyTracker { */ ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/2600-2699/2672.Number of Adjacent Elements With the Same Color/README.md b/solution/2600-2699/2672.Number of Adjacent Elements With the Same Color/README.md index f9183a0926693..640abb4822276 100644 --- a/solution/2600-2699/2672.Number of Adjacent Elements With the Same Color/README.md +++ b/solution/2600-2699/2672.Number of Adjacent Elements With the Same Color/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def colorTheArray(self, n: int, queries: List[List[int]]) -> List[int]: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] colorTheArray(int n, int[][] queries) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func colorTheArray(n int, queries [][]int) (ans []int) { nums := make([]int, n) @@ -176,6 +184,8 @@ func colorTheArray(n int, queries [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function colorTheArray(n: number, queries: number[][]): number[] { const nums: number[] = new Array(n).fill(0); diff --git a/solution/2600-2699/2672.Number of Adjacent Elements With the Same Color/README_EN.md b/solution/2600-2699/2672.Number of Adjacent Elements With the Same Color/README_EN.md index 7b2d4b5452b0c..6e6cc8feae12d 100644 --- a/solution/2600-2699/2672.Number of Adjacent Elements With the Same Color/README_EN.md +++ b/solution/2600-2699/2672.Number of Adjacent Elements With the Same Color/README_EN.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def colorTheArray(self, n: int, queries: List[List[int]]) -> List[int]: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] colorTheArray(int n, int[][] queries) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func colorTheArray(n int, queries [][]int) (ans []int) { nums := make([]int, n) @@ -174,6 +182,8 @@ func colorTheArray(n int, queries [][]int) (ans []int) { } ``` +#### TypeScript + ```ts function colorTheArray(n: number, queries: number[][]): number[] { const nums: number[] = new Array(n).fill(0); diff --git a/solution/2600-2699/2673.Make Costs of Paths Equal in a Binary Tree/README.md b/solution/2600-2699/2673.Make Costs of Paths Equal in a Binary Tree/README.md index 0cc62cac213a2..b890926bf444d 100644 --- a/solution/2600-2699/2673.Make Costs of Paths Equal in a Binary Tree/README.md +++ b/solution/2600-2699/2673.Make Costs of Paths Equal in a Binary Tree/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class Solution: def minIncrements(self, n: int, cost: List[int]) -> int: @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minIncrements(int n, int[] cost) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func minIncrements(n int, cost []int) (ans int) { for i := n >> 1; i > 0; i-- { @@ -154,6 +162,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function minIncrements(n: number, cost: number[]): number { let ans = 0; diff --git a/solution/2600-2699/2673.Make Costs of Paths Equal in a Binary Tree/README_EN.md b/solution/2600-2699/2673.Make Costs of Paths Equal in a Binary Tree/README_EN.md index 5aab04da55545..12f0e980dea8c 100644 --- a/solution/2600-2699/2673.Make Costs of Paths Equal in a Binary Tree/README_EN.md +++ b/solution/2600-2699/2673.Make Costs of Paths Equal in a Binary Tree/README_EN.md @@ -90,6 +90,8 @@ The time complexity is $O(n)$, where $n$ is the number of nodes. The space compl +#### Python3 + ```python class Solution: def minIncrements(self, n: int, cost: List[int]) -> int: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minIncrements(int n, int[] cost) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func minIncrements(n int, cost []int) (ans int) { for i := n >> 1; i > 0; i-- { @@ -148,6 +156,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function minIncrements(n: number, cost: number[]): number { let ans = 0; diff --git a/solution/2600-2699/2674.Split a Circular Linked List/README.md b/solution/2600-2699/2674.Split a Circular Linked List/README.md index eea2464352a78..0abbed8f317f7 100644 --- a/solution/2600-2699/2674.Split a Circular Linked List/README.md +++ b/solution/2600-2699/2674.Split a Circular Linked List/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -87,6 +89,8 @@ class Solution: return [list, list2] ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -171,6 +179,8 @@ func splitCircularLinkedList(list *ListNode) []*ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/2600-2699/2674.Split a Circular Linked List/README_EN.md b/solution/2600-2699/2674.Split a Circular Linked List/README_EN.md index 0c3975814a599..89b48f05550a0 100644 --- a/solution/2600-2699/2674.Split a Circular Linked List/README_EN.md +++ b/solution/2600-2699/2674.Split a Circular Linked List/README_EN.md @@ -63,6 +63,8 @@ The time complexity is $O(n)$, where $n$ is the length of the linked list. It re +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -85,6 +87,8 @@ class Solution: return [list, list2] ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -169,6 +177,8 @@ func splitCircularLinkedList(list *ListNode) []*ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/2600-2699/2675.Array of Objects to Matrix/README.md b/solution/2600-2699/2675.Array of Objects to Matrix/README.md index f48dfa7b94939..61e698afc6862 100644 --- a/solution/2600-2699/2675.Array of Objects to Matrix/README.md +++ b/solution/2600-2699/2675.Array of Objects to Matrix/README.md @@ -153,6 +153,8 @@ arr = [ +#### TypeScript + ```ts function jsonToMatrix(arr: any[]): (string | number | boolean | null)[] { const dfs = (key: string, obj: any) => { diff --git a/solution/2600-2699/2675.Array of Objects to Matrix/README_EN.md b/solution/2600-2699/2675.Array of Objects to Matrix/README_EN.md index b212fb06dee69..605cdc2c77fc0 100644 --- a/solution/2600-2699/2675.Array of Objects to Matrix/README_EN.md +++ b/solution/2600-2699/2675.Array of Objects to Matrix/README_EN.md @@ -151,6 +151,8 @@ There are no keys so every row is an empty array. +#### TypeScript + ```ts function jsonToMatrix(arr: any[]): (string | number | boolean | null)[] { const dfs = (key: string, obj: any) => { diff --git a/solution/2600-2699/2676.Throttle/README.md b/solution/2600-2699/2676.Throttle/README.md index 75a799ae009df..270f5e6af358b 100644 --- a/solution/2600-2699/2676.Throttle/README.md +++ b/solution/2600-2699/2676.Throttle/README.md @@ -95,6 +95,8 @@ calls = [ +#### TypeScript + ```ts type F = (...args: any[]) => void; diff --git a/solution/2600-2699/2676.Throttle/README_EN.md b/solution/2600-2699/2676.Throttle/README_EN.md index 7a7d89c1d32e9..f27e1be703788 100644 --- a/solution/2600-2699/2676.Throttle/README_EN.md +++ b/solution/2600-2699/2676.Throttle/README_EN.md @@ -96,6 +96,8 @@ The 5th is called at 300ms, but it is after 260ms, so it should be called immedi +#### TypeScript + ```ts type F = (...args: any[]) => void; diff --git a/solution/2600-2699/2677.Chunk Array/README.md b/solution/2600-2699/2677.Chunk Array/README.md index 7c9f689e1523c..ef96c795d514d 100644 --- a/solution/2600-2699/2677.Chunk Array/README.md +++ b/solution/2600-2699/2677.Chunk Array/README.md @@ -75,6 +75,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2600-2699/2677.Ch +#### TypeScript + ```ts function chunk(arr: any[], size: number): any[][] { const ans: any[][] = []; @@ -85,6 +87,8 @@ function chunk(arr: any[], size: number): any[][] { } ``` +#### JavaScript + ```js /** * @param {Array} arr diff --git a/solution/2600-2699/2677.Chunk Array/README_EN.md b/solution/2600-2699/2677.Chunk Array/README_EN.md index ce61088ba53dd..a4742655ba88d 100644 --- a/solution/2600-2699/2677.Chunk Array/README_EN.md +++ b/solution/2600-2699/2677.Chunk Array/README_EN.md @@ -73,6 +73,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2600-2699/2677.Ch +#### TypeScript + ```ts function chunk(arr: any[], size: number): any[][] { const ans: any[][] = []; @@ -83,6 +85,8 @@ function chunk(arr: any[], size: number): any[][] { } ``` +#### JavaScript + ```js /** * @param {Array} arr diff --git a/solution/2600-2699/2678.Number of Senior Citizens/README.md b/solution/2600-2699/2678.Number of Senior Citizens/README.md index 8b41fdaa04bcf..af82776b9af1c 100644 --- a/solution/2600-2699/2678.Number of Senior Citizens/README.md +++ b/solution/2600-2699/2678.Number of Senior Citizens/README.md @@ -76,12 +76,16 @@ tags: +#### Python3 + ```python class Solution: def countSeniors(self, details: List[str]) -> int: return sum(int(x[11:13]) > 60 for x in details) ``` +#### Java + ```java class Solution { public int countSeniors(String[] details) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func countSeniors(details []string) (ans int) { for _, x := range details { @@ -123,6 +131,8 @@ func countSeniors(details []string) (ans int) { } ``` +#### TypeScript + ```ts function countSeniors(details: string[]): number { let ans = 0; @@ -136,6 +146,8 @@ function countSeniors(details: string[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_seniors(details: Vec) -> i32 { @@ -164,12 +176,16 @@ impl Solution { +#### TypeScript + ```ts function countSeniors(details: string[]): number { return details.filter(v => parseInt(v.slice(11, 13)) > 60).length; } ``` +#### Rust + ```rust impl Solution { pub fn count_seniors(details: Vec) -> i32 { diff --git a/solution/2600-2699/2678.Number of Senior Citizens/README_EN.md b/solution/2600-2699/2678.Number of Senior Citizens/README_EN.md index 72cc0cc242b4a..4c0f22a62122b 100644 --- a/solution/2600-2699/2678.Number of Senior Citizens/README_EN.md +++ b/solution/2600-2699/2678.Number of Senior Citizens/README_EN.md @@ -74,12 +74,16 @@ The time complexity is $O(n)$, where $n$ is the length of `details`. The space c +#### Python3 + ```python class Solution: def countSeniors(self, details: List[str]) -> int: return sum(int(x[11:13]) > 60 for x in details) ``` +#### Java + ```java class Solution { public int countSeniors(String[] details) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func countSeniors(details []string) (ans int) { for _, x := range details { @@ -121,6 +129,8 @@ func countSeniors(details []string) (ans int) { } ``` +#### TypeScript + ```ts function countSeniors(details: string[]): number { let ans = 0; @@ -134,6 +144,8 @@ function countSeniors(details: string[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_seniors(details: Vec) -> i32 { @@ -162,12 +174,16 @@ impl Solution { +#### TypeScript + ```ts function countSeniors(details: string[]): number { return details.filter(v => parseInt(v.slice(11, 13)) > 60).length; } ``` +#### Rust + ```rust impl Solution { pub fn count_seniors(details: Vec) -> i32 { diff --git a/solution/2600-2699/2679.Sum in a Matrix/README.md b/solution/2600-2699/2679.Sum in a Matrix/README.md index 4c5188576f096..714b643c973f6 100644 --- a/solution/2600-2699/2679.Sum in a Matrix/README.md +++ b/solution/2600-2699/2679.Sum in a Matrix/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def matrixSum(self, nums: List[List[int]]) -> int: @@ -82,6 +84,8 @@ class Solution: return sum(map(max, zip(*nums))) ``` +#### Java + ```java class Solution { public int matrixSum(int[][] nums) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func matrixSum(nums [][]int) (ans int) { for _, row := range nums { @@ -137,6 +145,8 @@ func matrixSum(nums [][]int) (ans int) { } ``` +#### TypeScript + ```ts function matrixSum(nums: number[][]): number { for (const row of nums) { @@ -154,6 +164,8 @@ function matrixSum(nums: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn matrix_sum(nums: Vec>) -> i32 { @@ -187,6 +199,8 @@ impl Solution { +#### Rust + ```rust impl Solution { pub fn matrix_sum(nums: Vec>) -> i32 { diff --git a/solution/2600-2699/2679.Sum in a Matrix/README_EN.md b/solution/2600-2699/2679.Sum in a Matrix/README_EN.md index 140acbfa17485..1ed73ffc21fb4 100644 --- a/solution/2600-2699/2679.Sum in a Matrix/README_EN.md +++ b/solution/2600-2699/2679.Sum in a Matrix/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def matrixSum(self, nums: List[List[int]]) -> int: @@ -73,6 +75,8 @@ class Solution: return sum(map(max, zip(*nums))) ``` +#### Java + ```java class Solution { public int matrixSum(int[][] nums) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func matrixSum(nums [][]int) (ans int) { for _, row := range nums { @@ -128,6 +136,8 @@ func matrixSum(nums [][]int) (ans int) { } ``` +#### TypeScript + ```ts function matrixSum(nums: number[][]): number { for (const row of nums) { @@ -145,6 +155,8 @@ function matrixSum(nums: number[][]): number { } ``` +#### Rust + ```rust impl Solution { pub fn matrix_sum(nums: Vec>) -> i32 { @@ -178,6 +190,8 @@ impl Solution { +#### Rust + ```rust impl Solution { pub fn matrix_sum(nums: Vec>) -> i32 { diff --git a/solution/2600-2699/2680.Maximum OR/README.md b/solution/2600-2699/2680.Maximum OR/README.md index a3d1e969a7f64..6203a48f22f5c 100644 --- a/solution/2600-2699/2680.Maximum OR/README.md +++ b/solution/2600-2699/2680.Maximum OR/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def maximumOr(self, nums: List[int], k: int) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maximumOr(int[] nums, int k) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func maximumOr(nums []int, k int) int64 { n := len(nums) @@ -141,6 +149,8 @@ func maximumOr(nums []int, k int) int64 { } ``` +#### TypeScript + ```ts function maximumOr(nums: number[], k: number): number { const n = nums.length; @@ -157,6 +167,8 @@ function maximumOr(nums: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn maximum_or(nums: Vec, k: i32) -> i64 { diff --git a/solution/2600-2699/2680.Maximum OR/README_EN.md b/solution/2600-2699/2680.Maximum OR/README_EN.md index daef34a7cb6b2..e6f9fa216c406 100644 --- a/solution/2600-2699/2680.Maximum OR/README_EN.md +++ b/solution/2600-2699/2680.Maximum OR/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def maximumOr(self, nums: List[int], k: int) -> int: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maximumOr(int[] nums, int k) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func maximumOr(nums []int, k int) int64 { n := len(nums) @@ -139,6 +147,8 @@ func maximumOr(nums []int, k int) int64 { } ``` +#### TypeScript + ```ts function maximumOr(nums: number[], k: number): number { const n = nums.length; @@ -155,6 +165,8 @@ function maximumOr(nums: number[], k: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn maximum_or(nums: Vec, k: i32) -> i64 { diff --git a/solution/2600-2699/2681.Power of Heroes/README.md b/solution/2600-2699/2681.Power of Heroes/README.md index ad19cc78b2aa0..ef6294dc05c62 100644 --- a/solution/2600-2699/2681.Power of Heroes/README.md +++ b/solution/2600-2699/2681.Power of Heroes/README.md @@ -91,6 +91,8 @@ $$ +#### Python3 + ```python class Solution: def sumOfPower(self, nums: List[int]) -> int: @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int sumOfPower(int[] nums) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func sumOfPower(nums []int) (ans int) { const mod = 1e9 + 7 @@ -154,6 +162,8 @@ func sumOfPower(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function sumOfPower(nums: number[]): number { const mod = 10 ** 9 + 7; diff --git a/solution/2600-2699/2681.Power of Heroes/README_EN.md b/solution/2600-2699/2681.Power of Heroes/README_EN.md index 0bdf08aef4055..72ee227a6625f 100644 --- a/solution/2600-2699/2681.Power of Heroes/README_EN.md +++ b/solution/2600-2699/2681.Power of Heroes/README_EN.md @@ -74,6 +74,8 @@ The sum of powers of all groups is 8 + 1 + 64 + 4 + 32 + 16 + 16 = 141. +#### Python3 + ```python class Solution: def sumOfPower(self, nums: List[int]) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int sumOfPower(int[] nums) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func sumOfPower(nums []int) (ans int) { const mod = 1e9 + 7 @@ -137,6 +145,8 @@ func sumOfPower(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function sumOfPower(nums: number[]): number { const mod = 10 ** 9 + 7; diff --git a/solution/2600-2699/2682.Find the Losers of the Circular Game/README.md b/solution/2600-2699/2682.Find the Losers of the Circular Game/README.md index 9e2e5fe692b40..bed109445504a 100644 --- a/solution/2600-2699/2682.Find the Losers of the Circular Game/README.md +++ b/solution/2600-2699/2682.Find the Losers of the Circular Game/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def circularGameLosers(self, n: int, k: int) -> List[int]: @@ -101,6 +103,8 @@ class Solution: return [i + 1 for i in range(n) if not vis[i]] ``` +#### Java + ```java class Solution { public int[] circularGameLosers(int n, int k) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func circularGameLosers(n int, k int) (ans []int) { vis := make([]bool, n) @@ -159,6 +167,8 @@ func circularGameLosers(n int, k int) (ans []int) { } ``` +#### TypeScript + ```ts function circularGameLosers(n: number, k: number): number[] { const vis = new Array(n).fill(false); @@ -176,6 +186,8 @@ function circularGameLosers(n: number, k: number): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn circular_game_losers(n: i32, k: i32) -> Vec { diff --git a/solution/2600-2699/2682.Find the Losers of the Circular Game/README_EN.md b/solution/2600-2699/2682.Find the Losers of the Circular Game/README_EN.md index f417b0e6d9f4b..383cb0fedb0c7 100644 --- a/solution/2600-2699/2682.Find the Losers of the Circular Game/README_EN.md +++ b/solution/2600-2699/2682.Find the Losers of the Circular Game/README_EN.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def circularGameLosers(self, n: int, k: int) -> List[int]: @@ -92,6 +94,8 @@ class Solution: return [i + 1 for i in range(n) if not vis[i]] ``` +#### Java + ```java class Solution { public int[] circularGameLosers(int n, int k) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func circularGameLosers(n int, k int) (ans []int) { vis := make([]bool, n) @@ -150,6 +158,8 @@ func circularGameLosers(n int, k int) (ans []int) { } ``` +#### TypeScript + ```ts function circularGameLosers(n: number, k: number): number[] { const vis = new Array(n).fill(false); @@ -167,6 +177,8 @@ function circularGameLosers(n: number, k: number): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn circular_game_losers(n: i32, k: i32) -> Vec { diff --git a/solution/2600-2699/2683.Neighboring Bitwise XOR/README.md b/solution/2600-2699/2683.Neighboring Bitwise XOR/README.md index a1fa7f8db9549..cb5152971b48a 100644 --- a/solution/2600-2699/2683.Neighboring Bitwise XOR/README.md +++ b/solution/2600-2699/2683.Neighboring Bitwise XOR/README.md @@ -103,12 +103,16 @@ $$ +#### Python3 + ```python class Solution: def doesValidArrayExist(self, derived: List[int]) -> bool: return reduce(xor, derived) == 0 ``` +#### Java + ```java class Solution { public boolean doesValidArrayExist(int[] derived) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func doesValidArrayExist(derived []int) bool { s := 0 @@ -144,6 +152,8 @@ func doesValidArrayExist(derived []int) bool { } ``` +#### TypeScript + ```ts function doesValidArrayExist(derived: number[]): boolean { let s = 0; @@ -164,6 +174,8 @@ function doesValidArrayExist(derived: number[]): boolean { +#### TypeScript + ```ts function doesValidArrayExist(derived: number[]): boolean { return derived.reduce((acc, x) => acc ^ x, 0) === 0; diff --git a/solution/2600-2699/2683.Neighboring Bitwise XOR/README_EN.md b/solution/2600-2699/2683.Neighboring Bitwise XOR/README_EN.md index f99f93bc1b0ff..313aef5710a93 100644 --- a/solution/2600-2699/2683.Neighboring Bitwise XOR/README_EN.md +++ b/solution/2600-2699/2683.Neighboring Bitwise XOR/README_EN.md @@ -85,12 +85,16 @@ derived[1] = original[1] ⊕ original[0] = 1 +#### Python3 + ```python class Solution: def doesValidArrayExist(self, derived: List[int]) -> bool: return reduce(xor, derived) == 0 ``` +#### Java + ```java class Solution { public boolean doesValidArrayExist(int[] derived) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func doesValidArrayExist(derived []int) bool { s := 0 @@ -126,6 +134,8 @@ func doesValidArrayExist(derived []int) bool { } ``` +#### TypeScript + ```ts function doesValidArrayExist(derived: number[]): boolean { let s = 0; @@ -146,6 +156,8 @@ function doesValidArrayExist(derived: number[]): boolean { +#### TypeScript + ```ts function doesValidArrayExist(derived: number[]): boolean { return derived.reduce((acc, x) => acc ^ x, 0) === 0; diff --git a/solution/2600-2699/2684.Maximum Number of Moves in a Grid/README.md b/solution/2600-2699/2684.Maximum Number of Moves in a Grid/README.md index ba7c202a1e784..10a44c5e57fa5 100644 --- a/solution/2600-2699/2684.Maximum Number of Moves in a Grid/README.md +++ b/solution/2600-2699/2684.Maximum Number of Moves in a Grid/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def maxMoves(self, grid: List[List[int]]) -> int: @@ -97,6 +99,8 @@ class Solution: return n - 1 ``` +#### Java + ```java class Solution { public int maxMoves(int[][] grid) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func maxMoves(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -174,6 +182,8 @@ func maxMoves(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function maxMoves(grid: number[][]): number { const m = grid.length; diff --git a/solution/2600-2699/2684.Maximum Number of Moves in a Grid/README_EN.md b/solution/2600-2699/2684.Maximum Number of Moves in a Grid/README_EN.md index 79ab4d142ac8e..69026a39d2f44 100644 --- a/solution/2600-2699/2684.Maximum Number of Moves in a Grid/README_EN.md +++ b/solution/2600-2699/2684.Maximum Number of Moves in a Grid/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m)$. Wher +#### Python3 + ```python class Solution: def maxMoves(self, grid: List[List[int]]) -> int: @@ -97,6 +99,8 @@ class Solution: return n - 1 ``` +#### Java + ```java class Solution { public int maxMoves(int[][] grid) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func maxMoves(grid [][]int) (ans int) { m, n := len(grid), len(grid[0]) @@ -174,6 +182,8 @@ func maxMoves(grid [][]int) (ans int) { } ``` +#### TypeScript + ```ts function maxMoves(grid: number[][]): number { const m = grid.length; diff --git a/solution/2600-2699/2685.Count the Number of Complete Components/README.md b/solution/2600-2699/2685.Count the Number of Complete Components/README.md index 77b0b46100df9..523f109cef196 100644 --- a/solution/2600-2699/2685.Count the Number of Complete Components/README.md +++ b/solution/2600-2699/2685.Count the Number of Complete Components/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def countCompleteComponents(self, n: int, edges: List[List[int]]) -> int: @@ -109,6 +111,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go func countCompleteComponents(n int, edges [][]int) (ans int) { g := make([][]int, n) diff --git a/solution/2600-2699/2685.Count the Number of Complete Components/README_EN.md b/solution/2600-2699/2685.Count the Number of Complete Components/README_EN.md index b7327e8f35c97..fb6077f895077 100644 --- a/solution/2600-2699/2685.Count the Number of Complete Components/README_EN.md +++ b/solution/2600-2699/2685.Count the Number of Complete Components/README_EN.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def countCompleteComponents(self, n: int, edges: List[List[int]]) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go func countCompleteComponents(n int, edges [][]int) (ans int) { g := make([][]int, n) diff --git a/solution/2600-2699/2686.Immediate Food Delivery III/README.md b/solution/2600-2699/2686.Immediate Food Delivery III/README.md index 2914b4b008f33..4bf67def91a6a 100644 --- a/solution/2600-2699/2686.Immediate Food Delivery III/README.md +++ b/solution/2600-2699/2686.Immediate Food Delivery III/README.md @@ -88,6 +88,8 @@ order_dste 按升序排序。 +#### MySQL + ```sql # Write your MySQL query statement below SELECT order_date diff --git a/solution/2600-2699/2686.Immediate Food Delivery III/README_EN.md b/solution/2600-2699/2686.Immediate Food Delivery III/README_EN.md index ae8a597902e2a..debbcd9b28a22 100644 --- a/solution/2600-2699/2686.Immediate Food Delivery III/README_EN.md +++ b/solution/2600-2699/2686.Immediate Food Delivery III/README_EN.md @@ -86,6 +86,8 @@ order_date is sorted in ascending order. +#### MySQL + ```sql # Write your MySQL query statement below SELECT order_date diff --git a/solution/2600-2699/2687.Bikes Last Time Used/README.md b/solution/2600-2699/2687.Bikes Last Time Used/README.md index fa952c81c4cd8..feeb362b818a0 100644 --- a/solution/2600-2699/2687.Bikes Last Time Used/README.md +++ b/solution/2600-2699/2687.Bikes Last Time Used/README.md @@ -79,6 +79,8 @@ ride_id 是该表的主键。 +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2600-2699/2687.Bikes Last Time Used/README_EN.md b/solution/2600-2699/2687.Bikes Last Time Used/README_EN.md index bac439859868a..5faf3f375adf6 100644 --- a/solution/2600-2699/2687.Bikes Last Time Used/README_EN.md +++ b/solution/2600-2699/2687.Bikes Last Time Used/README_EN.md @@ -81,6 +81,8 @@ Returning output in order by the bike that were most recently used. +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2600-2699/2688.Find Active Users/README.md b/solution/2600-2699/2688.Find Active Users/README.md index 42477368fcf99..9d4555ddee213 100644 --- a/solution/2600-2699/2688.Find Active Users/README.md +++ b/solution/2600-2699/2688.Find Active Users/README.md @@ -77,6 +77,8 @@ tags: +#### MySQL + ```sql # Write your MySQL query statement SELECT DISTINCT diff --git a/solution/2600-2699/2688.Find Active Users/README_EN.md b/solution/2600-2699/2688.Find Active Users/README_EN.md index e10222548aebb..1a13f3bfc054b 100644 --- a/solution/2600-2699/2688.Find Active Users/README_EN.md +++ b/solution/2600-2699/2688.Find Active Users/README_EN.md @@ -78,6 +78,8 @@ Each row includes the user ID, the purchased item, the date of purchase, and the +#### MySQL + ```sql # Write your MySQL query statement SELECT DISTINCT diff --git a/solution/2600-2699/2689.Extract Kth Character From The Rope Tree/README.md b/solution/2600-2699/2689.Extract Kth Character From The Rope Tree/README.md index e2bcca438a2e1..e18e62e837402 100644 --- a/solution/2600-2699/2689.Extract Kth Character From The Rope Tree/README.md +++ b/solution/2600-2699/2689.Extract Kth Character From The Rope Tree/README.md @@ -102,6 +102,8 @@ tags: +#### Python3 + ```python # Definition for a rope tree node. # class RopeTreeNode(object): @@ -122,6 +124,8 @@ class Solution: return dfs(root)[k - 1] ``` +#### Java + ```java /** * Definition for a rope tree node. @@ -166,6 +170,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a rope tree node. @@ -199,6 +205,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a rope tree node. diff --git a/solution/2600-2699/2689.Extract Kth Character From The Rope Tree/README_EN.md b/solution/2600-2699/2689.Extract Kth Character From The Rope Tree/README_EN.md index c82fa6f21371e..5568acdca5517 100644 --- a/solution/2600-2699/2689.Extract Kth Character From The Rope Tree/README_EN.md +++ b/solution/2600-2699/2689.Extract Kth Character From The Rope Tree/README_EN.md @@ -93,6 +93,8 @@ You can see that S[root] = "ropetree". So S[root][7], which represents +#### Python3 + ```python # Definition for a rope tree node. # class RopeTreeNode(object): @@ -113,6 +115,8 @@ class Solution: return dfs(root)[k - 1] ``` +#### Java + ```java /** * Definition for a rope tree node. @@ -157,6 +161,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a rope tree node. @@ -190,6 +196,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a rope tree node. diff --git a/solution/2600-2699/2690.Infinite Method Object/README.md b/solution/2600-2699/2690.Infinite Method Object/README.md index a37b8c2c59946..e28269c1c9322 100644 --- a/solution/2600-2699/2690.Infinite Method Object/README.md +++ b/solution/2600-2699/2690.Infinite Method Object/README.md @@ -57,6 +57,8 @@ obj['abc123'](); // "abc123" +#### TypeScript + ```ts function createInfiniteObject(): Record string> { return new Proxy( diff --git a/solution/2600-2699/2690.Infinite Method Object/README_EN.md b/solution/2600-2699/2690.Infinite Method Object/README_EN.md index fc4a7332824f2..e0f6c08fbe8a6 100644 --- a/solution/2600-2699/2690.Infinite Method Object/README_EN.md +++ b/solution/2600-2699/2690.Infinite Method Object/README_EN.md @@ -55,6 +55,8 @@ The returned string should always match the method name. +#### TypeScript + ```ts function createInfiniteObject(): Record string> { return new Proxy( diff --git a/solution/2600-2699/2691.Immutability Helper/README.md b/solution/2600-2699/2691.Immutability Helper/README.md index 055ae08c29b01..664293f6c1f4f 100644 --- a/solution/2600-2699/2691.Immutability Helper/README.md +++ b/solution/2600-2699/2691.Immutability Helper/README.md @@ -122,6 +122,8 @@ mutators = [ +#### TypeScript + ```ts ``` diff --git a/solution/2600-2699/2691.Immutability Helper/README_EN.md b/solution/2600-2699/2691.Immutability Helper/README_EN.md index 178da2f87c384..bd8f48beb53eb 100644 --- a/solution/2600-2699/2691.Immutability Helper/README_EN.md +++ b/solution/2600-2699/2691.Immutability Helper/README_EN.md @@ -121,6 +121,8 @@ mutators = [ +#### TypeScript + ```ts ``` diff --git a/solution/2600-2699/2692.Make Object Immutable/README.md b/solution/2600-2699/2692.Make Object Immutable/README.md index 49865c35046e8..a6d0287a165c4 100644 --- a/solution/2600-2699/2692.Make Object Immutable/README.md +++ b/solution/2600-2699/2692.Make Object Immutable/README.md @@ -108,6 +108,8 @@ fn = (obj) => { +#### TypeScript + ```ts type Obj = Array | Record; diff --git a/solution/2600-2699/2692.Make Object Immutable/README_EN.md b/solution/2600-2699/2692.Make Object Immutable/README_EN.md index 70e242a556c2f..a367e0d1a25f1 100644 --- a/solution/2600-2699/2692.Make Object Immutable/README_EN.md +++ b/solution/2600-2699/2692.Make Object Immutable/README_EN.md @@ -107,6 +107,8 @@ fn = (obj) => { +#### TypeScript + ```ts type Obj = Array | Record; diff --git a/solution/2600-2699/2693.Call Function with Custom Context/README.md b/solution/2600-2699/2693.Call Function with Custom Context/README.md index 92437a6fe9020..c5578a9994a28 100644 --- a/solution/2600-2699/2693.Call Function with Custom Context/README.md +++ b/solution/2600-2699/2693.Call Function with Custom Context/README.md @@ -79,6 +79,8 @@ args = [{"item": "burger"}, 10, 1,1] +#### TypeScript + ```ts declare global { interface Function { diff --git a/solution/2600-2699/2693.Call Function with Custom Context/README_EN.md b/solution/2600-2699/2693.Call Function with Custom Context/README_EN.md index eadd74b4a6f72..81db4dfc947bb 100644 --- a/solution/2600-2699/2693.Call Function with Custom Context/README_EN.md +++ b/solution/2600-2699/2693.Call Function with Custom Context/README_EN.md @@ -77,6 +77,8 @@ args = [{"item": "burger"}, 10, 1.1] +#### TypeScript + ```ts declare global { interface Function { diff --git a/solution/2600-2699/2694.Event Emitter/README.md b/solution/2600-2699/2694.Event Emitter/README.md index 75642e73cdc80..02b6a605e7bde 100644 --- a/solution/2600-2699/2694.Event Emitter/README.md +++ b/solution/2600-2699/2694.Event Emitter/README.md @@ -108,6 +108,8 @@ emitter.emit("firstEvent", [5]); // [7] +#### TypeScript + ```ts type Callback = (...args: any[]) => any; type Subscription = { diff --git a/solution/2600-2699/2694.Event Emitter/README_EN.md b/solution/2600-2699/2694.Event Emitter/README_EN.md index d3f3c326e5b7c..7fd188f6e212b 100644 --- a/solution/2600-2699/2694.Event Emitter/README_EN.md +++ b/solution/2600-2699/2694.Event Emitter/README_EN.md @@ -109,6 +109,8 @@ emitter.emit("firstEvent", [5]); // [7] +#### TypeScript + ```ts type Callback = (...args: any[]) => any; type Subscription = { diff --git a/solution/2600-2699/2695.Array Wrapper/README.md b/solution/2600-2699/2695.Array Wrapper/README.md index 3b917a4427201..0e49aaf1bf7e9 100644 --- a/solution/2600-2699/2695.Array Wrapper/README.md +++ b/solution/2600-2699/2695.Array Wrapper/README.md @@ -75,6 +75,8 @@ obj1 + obj2; // 0 +#### TypeScript + ```ts class ArrayWrapper { private nums: number[]; diff --git a/solution/2600-2699/2695.Array Wrapper/README_EN.md b/solution/2600-2699/2695.Array Wrapper/README_EN.md index 53eb71df04a03..504182dfacf73 100644 --- a/solution/2600-2699/2695.Array Wrapper/README_EN.md +++ b/solution/2600-2699/2695.Array Wrapper/README_EN.md @@ -73,6 +73,8 @@ obj1 + obj2; // 0 +#### TypeScript + ```ts class ArrayWrapper { private nums: number[]; diff --git a/solution/2600-2699/2696.Minimum String Length After Removing Substrings/README.md b/solution/2600-2699/2696.Minimum String Length After Removing Substrings/README.md index 24130e21ebc3f..8c645a32a26b7 100644 --- a/solution/2600-2699/2696.Minimum String Length After Removing Substrings/README.md +++ b/solution/2600-2699/2696.Minimum String Length After Removing Substrings/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def minLength(self, s: str) -> int: @@ -89,6 +91,8 @@ class Solution: return len(stk) - 1 ``` +#### Java + ```java class Solution { public int minLength(String s) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func minLength(s string) int { stk := []byte{' '} @@ -137,6 +145,8 @@ func minLength(s string) int { } ``` +#### TypeScript + ```ts function minLength(s: string): number { const stk: string[] = ['']; @@ -153,6 +163,8 @@ function minLength(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_length(s: String) -> i32 { diff --git a/solution/2600-2699/2696.Minimum String Length After Removing Substrings/README_EN.md b/solution/2600-2699/2696.Minimum String Length After Removing Substrings/README_EN.md index 6edfde0a1b022..cd8e37d1d4110 100644 --- a/solution/2600-2699/2696.Minimum String Length After Removing Substrings/README_EN.md +++ b/solution/2600-2699/2696.Minimum String Length After Removing Substrings/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python class Solution: def minLength(self, s: str) -> int: @@ -87,6 +89,8 @@ class Solution: return len(stk) - 1 ``` +#### Java + ```java class Solution { public int minLength(String s) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func minLength(s string) int { stk := []byte{' '} @@ -135,6 +143,8 @@ func minLength(s string) int { } ``` +#### TypeScript + ```ts function minLength(s: string): number { const stk: string[] = ['']; @@ -151,6 +161,8 @@ function minLength(s: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_length(s: String) -> i32 { diff --git a/solution/2600-2699/2697.Lexicographically Smallest Palindrome/README.md b/solution/2600-2699/2697.Lexicographically Smallest Palindrome/README.md index 2fa4a1c358c69..605f5843c3070 100644 --- a/solution/2600-2699/2697.Lexicographically Smallest Palindrome/README.md +++ b/solution/2600-2699/2697.Lexicographically Smallest Palindrome/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def makeSmallestPalindrome(self, s: str) -> str: @@ -89,6 +91,8 @@ class Solution: return "".join(cs) ``` +#### Java + ```java class Solution { public String makeSmallestPalindrome(String s) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func makeSmallestPalindrome(s string) string { cs := []byte(s) @@ -124,6 +132,8 @@ func makeSmallestPalindrome(s string) string { } ``` +#### TypeScript + ```ts function makeSmallestPalindrome(s: string): string { const cs = s.split(''); @@ -134,6 +144,8 @@ function makeSmallestPalindrome(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn make_smallest_palindrome(s: String) -> String { diff --git a/solution/2600-2699/2697.Lexicographically Smallest Palindrome/README_EN.md b/solution/2600-2699/2697.Lexicographically Smallest Palindrome/README_EN.md index 9018f24de7a88..00a89eb61a187 100644 --- a/solution/2600-2699/2697.Lexicographically Smallest Palindrome/README_EN.md +++ b/solution/2600-2699/2697.Lexicographically Smallest Palindrome/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def makeSmallestPalindrome(self, s: str) -> str: @@ -88,6 +90,8 @@ class Solution: return "".join(cs) ``` +#### Java + ```java class Solution { public String makeSmallestPalindrome(String s) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func makeSmallestPalindrome(s string) string { cs := []byte(s) @@ -123,6 +131,8 @@ func makeSmallestPalindrome(s string) string { } ``` +#### TypeScript + ```ts function makeSmallestPalindrome(s: string): string { const cs = s.split(''); @@ -133,6 +143,8 @@ function makeSmallestPalindrome(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn make_smallest_palindrome(s: String) -> String { diff --git a/solution/2600-2699/2698.Find the Punishment Number of an Integer/README.md b/solution/2600-2699/2698.Find the Punishment Number of an Integer/README.md index 594f3588e82e8..cbf9eec2d6087 100644 --- a/solution/2600-2699/2698.Find the Punishment Number of an Integer/README.md +++ b/solution/2600-2699/2698.Find the Punishment Number of an Integer/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def punishmentNumber(self, n: int) -> int: @@ -103,6 +105,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int punishmentNumber(int n) { @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func punishmentNumber(n int) (ans int) { var check func(string, int, int) bool @@ -202,6 +210,8 @@ func punishmentNumber(n int) (ans int) { } ``` +#### TypeScript + ```ts function punishmentNumber(n: number): number { const check = (s: string, i: number, x: number): boolean => { diff --git a/solution/2600-2699/2698.Find the Punishment Number of an Integer/README_EN.md b/solution/2600-2699/2698.Find the Punishment Number of an Integer/README_EN.md index 2cbee7a2196bb..c9b6fe3ae0020 100644 --- a/solution/2600-2699/2698.Find the Punishment Number of an Integer/README_EN.md +++ b/solution/2600-2699/2698.Find the Punishment Number of an Integer/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n^{1 + 2 \log_{10}^2})$, and the space complexity is $ +#### Python3 + ```python class Solution: def punishmentNumber(self, n: int) -> int: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int punishmentNumber(int n) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go func punishmentNumber(n int) (ans int) { var check func(string, int, int) bool @@ -200,6 +208,8 @@ func punishmentNumber(n int) (ans int) { } ``` +#### TypeScript + ```ts function punishmentNumber(n: number): number { const check = (s: string, i: number, x: number): boolean => { diff --git a/solution/2600-2699/2699.Modify Graph Edge Weights/README.md b/solution/2600-2699/2699.Modify Graph Edge Weights/README.md index a723d1a2a35e4..66e4a6b2f33c3 100644 --- a/solution/2600-2699/2699.Modify Graph Edge Weights/README.md +++ b/solution/2600-2699/2699.Modify Graph Edge Weights/README.md @@ -102,6 +102,8 @@ tags: +#### Python3 + ```python class Solution: def modifiedGraphEdges( @@ -145,6 +147,8 @@ class Solution: return edges if ok else [] ``` +#### Java + ```java class Solution { private final int inf = 2000000000; @@ -208,6 +212,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; const int inf = 2e9; @@ -273,6 +279,8 @@ public: }; ``` +#### Go + ```go func modifiedGraphEdges(n int, edges [][]int, source int, destination int, target int) [][]int { const inf int = 2e9 @@ -336,6 +344,8 @@ func modifiedGraphEdges(n int, edges [][]int, source int, destination int, targe } ``` +#### TypeScript + ```ts function modifiedGraphEdges( n: number, diff --git a/solution/2600-2699/2699.Modify Graph Edge Weights/README_EN.md b/solution/2600-2699/2699.Modify Graph Edge Weights/README_EN.md index e59d1a757275f..acc4d10fef0e0 100644 --- a/solution/2600-2699/2699.Modify Graph Edge Weights/README_EN.md +++ b/solution/2600-2699/2699.Modify Graph Edge Weights/README_EN.md @@ -100,6 +100,8 @@ The time complexity is $O(n^3)$, and the space complexity is $O(n^2)$, where $n$ +#### Python3 + ```python class Solution: def modifiedGraphEdges( @@ -143,6 +145,8 @@ class Solution: return edges if ok else [] ``` +#### Java + ```java class Solution { private final int inf = 2000000000; @@ -206,6 +210,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; const int inf = 2e9; @@ -271,6 +277,8 @@ public: }; ``` +#### Go + ```go func modifiedGraphEdges(n int, edges [][]int, source int, destination int, target int) [][]int { const inf int = 2e9 @@ -334,6 +342,8 @@ func modifiedGraphEdges(n int, edges [][]int, source int, destination int, targe } ``` +#### TypeScript + ```ts function modifiedGraphEdges( n: number, diff --git a/solution/2700-2799/2700.Differences Between Two Objects/README.md b/solution/2700-2799/2700.Differences Between Two Objects/README.md index 17e499ad4d325..e90695d816ead 100644 --- a/solution/2700-2799/2700.Differences Between Two Objects/README.md +++ b/solution/2700-2799/2700.Differences Between Two Objects/README.md @@ -147,6 +147,8 @@ obj2 = {   +#### TypeScript + ```ts function objDiff(obj1: any, obj2: any): any { if (type(obj1) !== type(obj2)) return [obj1, obj2]; diff --git a/solution/2700-2799/2700.Differences Between Two Objects/README_EN.md b/solution/2700-2799/2700.Differences Between Two Objects/README_EN.md index e55517981d86d..f59bf738997ef 100644 --- a/solution/2700-2799/2700.Differences Between Two Objects/README_EN.md +++ b/solution/2700-2799/2700.Differences Between Two Objects/README_EN.md @@ -147,6 +147,8 @@ obj2 = {   +#### TypeScript + ```ts function objDiff(obj1: any, obj2: any): any { if (type(obj1) !== type(obj2)) return [obj1, obj2]; diff --git a/solution/2700-2799/2701.Consecutive Transactions with Increasing Amounts/README.md b/solution/2700-2799/2701.Consecutive Transactions with Increasing Amounts/README.md index ff03037d6e2f2..0a7a2e016b1b9 100644 --- a/solution/2700-2799/2701.Consecutive Transactions with Increasing Amounts/README.md +++ b/solution/2700-2799/2701.Consecutive Transactions with Increasing Amounts/README.md @@ -85,6 +85,8 @@ Transactions 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2700-2799/2701.Consecutive Transactions with Increasing Amounts/README_EN.md b/solution/2700-2799/2701.Consecutive Transactions with Increasing Amounts/README_EN.md index 10a464e670eef..0e1e213add19c 100644 --- a/solution/2700-2799/2701.Consecutive Transactions with Increasing Amounts/README_EN.md +++ b/solution/2700-2799/2701.Consecutive Transactions with Increasing Amounts/README_EN.md @@ -87,6 +87,8 @@ customer_id is sorted in ascending order. +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2700-2799/2702.Minimum Operations to Make Numbers Non-positive/README.md b/solution/2700-2799/2702.Minimum Operations to Make Numbers Non-positive/README.md index c1d8139cdca6b..e85cd8a703a8c 100644 --- a/solution/2700-2799/2702.Minimum Operations to Make Numbers Non-positive/README.md +++ b/solution/2700-2799/2702.Minimum Operations to Make Numbers Non-positive/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int], x: int, y: int) -> int: @@ -98,6 +100,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { private int[] nums; @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int, x int, y int) int { check := func(t int) bool { @@ -187,6 +195,8 @@ func minOperations(nums []int, x int, y int) int { } ``` +#### TypeScript + ```ts function minOperations(nums: number[], x: number, y: number): number { let l = 0; diff --git a/solution/2700-2799/2702.Minimum Operations to Make Numbers Non-positive/README_EN.md b/solution/2700-2799/2702.Minimum Operations to Make Numbers Non-positive/README_EN.md index fd330a4ee4112..c2fa602a616a5 100644 --- a/solution/2700-2799/2702.Minimum Operations to Make Numbers Non-positive/README_EN.md +++ b/solution/2700-2799/2702.Minimum Operations to Make Numbers Non-positive/README_EN.md @@ -70,6 +70,8 @@ We define the left boundary of the binary search as $l=0$, and the right boundar +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int], x: int, y: int) -> int: @@ -90,6 +92,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { private int[] nums; @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int, x int, y int) int { check := func(t int) bool { @@ -179,6 +187,8 @@ func minOperations(nums []int, x int, y int) int { } ``` +#### TypeScript + ```ts function minOperations(nums: number[], x: number, y: number): number { let l = 0; diff --git a/solution/2700-2799/2703.Return Length of Arguments Passed/README.md b/solution/2700-2799/2703.Return Length of Arguments Passed/README.md index c3770c6a719a9..a6453c056230c 100644 --- a/solution/2700-2799/2703.Return Length of Arguments Passed/README.md +++ b/solution/2700-2799/2703.Return Length of Arguments Passed/README.md @@ -59,6 +59,8 @@ argumentsLength({}, null, "3"); // 3 +#### TypeScript + ```ts function argumentsLength(...args: any[]): number { return args.length; diff --git a/solution/2700-2799/2703.Return Length of Arguments Passed/README_EN.md b/solution/2700-2799/2703.Return Length of Arguments Passed/README_EN.md index 6e774b90226e7..3796664da488f 100644 --- a/solution/2700-2799/2703.Return Length of Arguments Passed/README_EN.md +++ b/solution/2700-2799/2703.Return Length of Arguments Passed/README_EN.md @@ -57,6 +57,8 @@ Three values were passed to the function so it should return 3. +#### TypeScript + ```ts function argumentsLength(...args: any[]): number { return args.length; diff --git a/solution/2700-2799/2704.To Be Or Not To Be/README.md b/solution/2700-2799/2704.To Be Or Not To Be/README.md index 82ff1860c6eb1..9915e3bab6c6f 100644 --- a/solution/2700-2799/2704.To Be Or Not To Be/README.md +++ b/solution/2700-2799/2704.To Be Or Not To Be/README.md @@ -57,6 +57,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2700-2799/2704.To +#### TypeScript + ```ts type ToBeOrNotToBe = { toBe: (val: any) => boolean; @@ -86,6 +88,8 @@ function expect(val: any): ToBeOrNotToBe { */ ``` +#### JavaScript + ```js /** * @param {string} val diff --git a/solution/2700-2799/2704.To Be Or Not To Be/README_EN.md b/solution/2700-2799/2704.To Be Or Not To Be/README_EN.md index bee7c6702bbbd..58d778f9104a1 100644 --- a/solution/2700-2799/2704.To Be Or Not To Be/README_EN.md +++ b/solution/2700-2799/2704.To Be Or Not To Be/README_EN.md @@ -56,6 +56,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2700-2799/2704.To +#### TypeScript + ```ts type ToBeOrNotToBe = { toBe: (val: any) => boolean; @@ -85,6 +87,8 @@ function expect(val: any): ToBeOrNotToBe { */ ``` +#### JavaScript + ```js /** * @param {string} val diff --git a/solution/2700-2799/2705.Compact Object/README.md b/solution/2700-2799/2705.Compact Object/README.md index 32856a77f3314..85eedb03cd868 100644 --- a/solution/2700-2799/2705.Compact Object/README.md +++ b/solution/2700-2799/2705.Compact Object/README.md @@ -72,6 +72,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2700-2799/2705.Co +#### TypeScript + ```ts type Obj = Record; @@ -94,6 +96,8 @@ function compactObject(obj: Obj): Obj { } ``` +#### JavaScript + ```js var compactObject = function (obj) { if (obj === null || typeof obj !== 'object') { diff --git a/solution/2700-2799/2705.Compact Object/README_EN.md b/solution/2700-2799/2705.Compact Object/README_EN.md index df97088d35564..8f0388abce004 100644 --- a/solution/2700-2799/2705.Compact Object/README_EN.md +++ b/solution/2700-2799/2705.Compact Object/README_EN.md @@ -62,6 +62,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2700-2799/2705.Co +#### TypeScript + ```ts type Obj = Record; @@ -84,6 +86,8 @@ function compactObject(obj: Obj): Obj { } ``` +#### JavaScript + ```js var compactObject = function (obj) { if (obj === null || typeof obj !== 'object') { diff --git a/solution/2700-2799/2706.Buy Two Chocolates/README.md b/solution/2700-2799/2706.Buy Two Chocolates/README.md index 3b8bd11d92960..5e35f12159df5 100644 --- a/solution/2700-2799/2706.Buy Two Chocolates/README.md +++ b/solution/2700-2799/2706.Buy Two Chocolates/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def buyChoco(self, prices: List[int], money: int) -> int: @@ -73,6 +75,8 @@ class Solution: return money if money < cost else money - cost ``` +#### Java + ```java class Solution { public int buyChoco(int[] prices, int money) { @@ -83,6 +87,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -94,6 +100,8 @@ public: }; ``` +#### Go + ```go func buyChoco(prices []int, money int) int { sort.Ints(prices) @@ -105,6 +113,8 @@ func buyChoco(prices []int, money int) int { } ``` +#### TypeScript + ```ts function buyChoco(prices: number[], money: number): number { prices.sort((a, b) => a - b); @@ -113,6 +123,8 @@ function buyChoco(prices: number[], money: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn buy_choco(mut prices: Vec, money: i32) -> i32 { @@ -140,6 +152,8 @@ impl Solution { +#### Python3 + ```python class Solution: def buyChoco(self, prices: List[int], money: int) -> int: @@ -153,6 +167,8 @@ class Solution: return money if money < cost else money - cost ``` +#### Java + ```java class Solution { public int buyChoco(int[] prices, int money) { @@ -171,6 +187,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -190,6 +208,8 @@ public: }; ``` +#### Go + ```go func buyChoco(prices []int, money int) int { a, b := 1001, 1001 @@ -208,6 +228,8 @@ func buyChoco(prices []int, money int) int { } ``` +#### TypeScript + ```ts function buyChoco(prices: number[], money: number): number { let [a, b] = [1000, 1000]; @@ -224,6 +246,8 @@ function buyChoco(prices: number[], money: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn buy_choco(prices: Vec, money: i32) -> i32 { diff --git a/solution/2700-2799/2706.Buy Two Chocolates/README_EN.md b/solution/2700-2799/2706.Buy Two Chocolates/README_EN.md index 7157bff3bb3e8..fecf79f13f5cc 100644 --- a/solution/2700-2799/2706.Buy Two Chocolates/README_EN.md +++ b/solution/2700-2799/2706.Buy Two Chocolates/README_EN.md @@ -65,6 +65,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def buyChoco(self, prices: List[int], money: int) -> int: @@ -73,6 +75,8 @@ class Solution: return money if money < cost else money - cost ``` +#### Java + ```java class Solution { public int buyChoco(int[] prices, int money) { @@ -83,6 +87,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -94,6 +100,8 @@ public: }; ``` +#### Go + ```go func buyChoco(prices []int, money int) int { sort.Ints(prices) @@ -105,6 +113,8 @@ func buyChoco(prices []int, money int) int { } ``` +#### TypeScript + ```ts function buyChoco(prices: number[], money: number): number { prices.sort((a, b) => a - b); @@ -113,6 +123,8 @@ function buyChoco(prices: number[], money: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn buy_choco(mut prices: Vec, money: i32) -> i32 { @@ -140,6 +152,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array `prices`. Th +#### Python3 + ```python class Solution: def buyChoco(self, prices: List[int], money: int) -> int: @@ -153,6 +167,8 @@ class Solution: return money if money < cost else money - cost ``` +#### Java + ```java class Solution { public int buyChoco(int[] prices, int money) { @@ -171,6 +187,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -190,6 +208,8 @@ public: }; ``` +#### Go + ```go func buyChoco(prices []int, money int) int { a, b := 1001, 1001 @@ -208,6 +228,8 @@ func buyChoco(prices []int, money int) int { } ``` +#### TypeScript + ```ts function buyChoco(prices: number[], money: number): number { let [a, b] = [1000, 1000]; @@ -224,6 +246,8 @@ function buyChoco(prices: number[], money: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn buy_choco(prices: Vec, money: i32) -> i32 { diff --git a/solution/2700-2799/2707.Extra Characters in a String/README.md b/solution/2700-2799/2707.Extra Characters in a String/README.md index d203e8b0e9619..b2cff7fea73de 100644 --- a/solution/2700-2799/2707.Extra Characters in a String/README.md +++ b/solution/2700-2799/2707.Extra Characters in a String/README.md @@ -82,6 +82,8 @@ $$ +#### Python3 + ```python class Solution: def minExtraChar(self, s: str, dictionary: List[str]) -> int: @@ -96,6 +98,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int minExtraChar(String s, String[] dictionary) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func minExtraChar(s string, dictionary []string) int { ss := map[string]bool{} @@ -160,6 +168,8 @@ func minExtraChar(s string, dictionary []string) int { } ``` +#### TypeScript + ```ts function minExtraChar(s: string, dictionary: string[]): number { const ss = new Set(dictionary); @@ -177,6 +187,8 @@ function minExtraChar(s: string, dictionary: string[]): number { } ``` +#### Rust + ```rust use std::collections::HashSet; @@ -216,6 +228,8 @@ impl Solution { +#### Python3 + ```python class Node: __slots__ = ['children', 'is_end'] @@ -251,6 +265,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Node { Node[] children = new Node[26]; @@ -291,6 +307,8 @@ class Solution { } ``` +#### C++ + ```cpp class Node { public: @@ -338,6 +356,8 @@ public: }; ``` +#### Go + ```go type Node struct { children [26]*Node @@ -377,6 +397,8 @@ func minExtraChar(s string, dictionary []string) int { } ``` +#### TypeScript + ```ts class Node { children: (Node | null)[] = Array(26).fill(null); diff --git a/solution/2700-2799/2707.Extra Characters in a String/README_EN.md b/solution/2700-2799/2707.Extra Characters in a String/README_EN.md index dd6c78ba3a75c..13eb8c12b9d59 100644 --- a/solution/2700-2799/2707.Extra Characters in a String/README_EN.md +++ b/solution/2700-2799/2707.Extra Characters in a String/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(n^3 + L)$, and the space complexity is $O(n + L)$. Her +#### Python3 + ```python class Solution: def minExtraChar(self, s: str, dictionary: List[str]) -> int: @@ -97,6 +99,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int minExtraChar(String s, String[] dictionary) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func minExtraChar(s string, dictionary []string) int { ss := map[string]bool{} @@ -161,6 +169,8 @@ func minExtraChar(s string, dictionary []string) int { } ``` +#### TypeScript + ```ts function minExtraChar(s: string, dictionary: string[]): number { const ss = new Set(dictionary); @@ -178,6 +188,8 @@ function minExtraChar(s: string, dictionary: string[]): number { } ``` +#### Rust + ```rust use std::collections::HashSet; @@ -217,6 +229,8 @@ The time complexity is $O(n^2 + L)$, and the space complexity is $O(n + L \times +#### Python3 + ```python class Node: __slots__ = ['children', 'is_end'] @@ -252,6 +266,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Node { Node[] children = new Node[26]; @@ -292,6 +308,8 @@ class Solution { } ``` +#### C++ + ```cpp class Node { public: @@ -339,6 +357,8 @@ public: }; ``` +#### Go + ```go type Node struct { children [26]*Node @@ -378,6 +398,8 @@ func minExtraChar(s string, dictionary []string) int { } ``` +#### TypeScript + ```ts class Node { children: (Node | null)[] = Array(26).fill(null); diff --git a/solution/2700-2799/2708.Maximum Strength of a Group/README.md b/solution/2700-2799/2708.Maximum Strength of a Group/README.md index d75216f38c850..c72c41cd0ed14 100644 --- a/solution/2700-2799/2708.Maximum Strength of a Group/README.md +++ b/solution/2700-2799/2708.Maximum Strength of a Group/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def maxStrength(self, nums: List[int]) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maxStrength(int[] nums) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func maxStrength(nums []int) int64 { ans := int64(-1e14) @@ -137,6 +145,8 @@ func maxStrength(nums []int) int64 { } ``` +#### TypeScript + ```ts function maxStrength(nums: number[]): number { let ans = -Infinity; @@ -172,6 +182,8 @@ function maxStrength(nums: number[]): number { +#### Python3 + ```python class Solution: def maxStrength(self, nums: List[int]) -> int: @@ -194,6 +206,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maxStrength(int[] nums) { @@ -223,6 +237,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -253,6 +269,8 @@ public: }; ``` +#### Go + ```go func maxStrength(nums []int) int64 { sort.Ints(nums) @@ -276,6 +294,8 @@ func maxStrength(nums []int) int64 { } ``` +#### TypeScript + ```ts function maxStrength(nums: number[]): number { nums.sort((a, b) => a - b); diff --git a/solution/2700-2799/2708.Maximum Strength of a Group/README_EN.md b/solution/2700-2799/2708.Maximum Strength of a Group/README_EN.md index f0d9a3e1966c4..d256c6d57fe55 100644 --- a/solution/2700-2799/2708.Maximum Strength of a Group/README_EN.md +++ b/solution/2700-2799/2708.Maximum Strength of a Group/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(2^n \times n)$, where $n$ is the length of the array. +#### Python3 + ```python class Solution: def maxStrength(self, nums: List[int]) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maxStrength(int[] nums) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func maxStrength(nums []int) int64 { ans := int64(-1e14) @@ -137,6 +145,8 @@ func maxStrength(nums []int) int64 { } ``` +#### TypeScript + ```ts function maxStrength(nums: number[]): number { let ans = -Infinity; @@ -172,6 +182,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def maxStrength(self, nums: List[int]) -> int: @@ -194,6 +206,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maxStrength(int[] nums) { @@ -223,6 +237,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -253,6 +269,8 @@ public: }; ``` +#### Go + ```go func maxStrength(nums []int) int64 { sort.Ints(nums) @@ -276,6 +294,8 @@ func maxStrength(nums []int) int64 { } ``` +#### TypeScript + ```ts function maxStrength(nums: number[]): number { nums.sort((a, b) => a - b); diff --git a/solution/2700-2799/2709.Greatest Common Divisor Traversal/README.md b/solution/2700-2799/2709.Greatest Common Divisor Traversal/README.md index 926f81bfd9025..d68200e07f9ca 100644 --- a/solution/2700-2799/2709.Greatest Common Divisor Traversal/README.md +++ b/solution/2700-2799/2709.Greatest Common Divisor Traversal/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class UnionFind: def __init__(self, n): @@ -124,6 +126,8 @@ class Solution: return len(set(uf.find(i) for i in range(n))) == 1 ``` +#### Java + ```java class UnionFind { private int[] p; @@ -203,6 +207,8 @@ class Solution { } ``` +#### C++ + ```cpp int MX = 100010; vector P[100010]; @@ -281,6 +287,8 @@ public: }; ``` +#### Go + ```go const mx = 100010 diff --git a/solution/2700-2799/2709.Greatest Common Divisor Traversal/README_EN.md b/solution/2700-2799/2709.Greatest Common Divisor Traversal/README_EN.md index fb21dba434385..4eaeae35db96f 100644 --- a/solution/2700-2799/2709.Greatest Common Divisor Traversal/README_EN.md +++ b/solution/2700-2799/2709.Greatest Common Divisor Traversal/README_EN.md @@ -72,6 +72,8 @@ To go from index 0 to index 2, we can just go directly because gcd(nums[0], nums +#### Python3 + ```python class UnionFind: def __init__(self, n): @@ -122,6 +124,8 @@ class Solution: return len(set(uf.find(i) for i in range(n))) == 1 ``` +#### Java + ```java class UnionFind { private int[] p; @@ -201,6 +205,8 @@ class Solution { } ``` +#### C++ + ```cpp int MX = 100010; vector P[100010]; @@ -279,6 +285,8 @@ public: }; ``` +#### Go + ```go const mx = 100010 diff --git a/solution/2700-2799/2710.Remove Trailing Zeros From a String/README.md b/solution/2700-2799/2710.Remove Trailing Zeros From a String/README.md index 6864ccf5db8ee..0e64c1a2c8c17 100644 --- a/solution/2700-2799/2710.Remove Trailing Zeros From a String/README.md +++ b/solution/2700-2799/2710.Remove Trailing Zeros From a String/README.md @@ -60,12 +60,16 @@ tags: +#### Python3 + ```python class Solution: def removeTrailingZeros(self, num: str) -> str: return num.rstrip("0") ``` +#### Java + ```java class Solution { public String removeTrailingZeros(String num) { @@ -78,6 +82,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -90,6 +96,8 @@ public: }; ``` +#### Go + ```go func removeTrailingZeros(num string) string { i := len(num) - 1 @@ -100,6 +108,8 @@ func removeTrailingZeros(num string) string { } ``` +#### TypeScript + ```ts function removeTrailingZeros(num: string): string { let i = num.length - 1; @@ -110,6 +120,8 @@ function removeTrailingZeros(num: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn remove_trailing_zeros(num: String) -> String { @@ -134,6 +146,8 @@ impl Solution { +#### Rust + ```rust impl Solution { pub fn remove_trailing_zeros(num: String) -> String { diff --git a/solution/2700-2799/2710.Remove Trailing Zeros From a String/README_EN.md b/solution/2700-2799/2710.Remove Trailing Zeros From a String/README_EN.md index ca55b8ae2c4a4..4df31753576c2 100644 --- a/solution/2700-2799/2710.Remove Trailing Zeros From a String/README_EN.md +++ b/solution/2700-2799/2710.Remove Trailing Zeros From a String/README_EN.md @@ -56,12 +56,16 @@ tags: +#### Python3 + ```python class Solution: def removeTrailingZeros(self, num: str) -> str: return num.rstrip("0") ``` +#### Java + ```java class Solution { public String removeTrailingZeros(String num) { @@ -74,6 +78,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -86,6 +92,8 @@ public: }; ``` +#### Go + ```go func removeTrailingZeros(num string) string { i := len(num) - 1 @@ -96,6 +104,8 @@ func removeTrailingZeros(num string) string { } ``` +#### TypeScript + ```ts function removeTrailingZeros(num: string): string { let i = num.length - 1; @@ -106,6 +116,8 @@ function removeTrailingZeros(num: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn remove_trailing_zeros(num: String) -> String { @@ -130,6 +142,8 @@ impl Solution { +#### Rust + ```rust impl Solution { pub fn remove_trailing_zeros(num: String) -> String { diff --git a/solution/2700-2799/2711.Difference of Number of Distinct Values on Diagonals/README.md b/solution/2700-2799/2711.Difference of Number of Distinct Values on Diagonals/README.md index 78d4475a830f8..6fab1f7b72395 100644 --- a/solution/2700-2799/2711.Difference of Number of Distinct Values on Diagonals/README.md +++ b/solution/2700-2799/2711.Difference of Number of Distinct Values on Diagonals/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def differenceOfDistinctValues(self, grid: List[List[int]]) -> List[List[int]]: @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] differenceOfDistinctValues(int[][] grid) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func differenceOfDistinctValues(grid [][]int) [][]int { m, n := len(grid), len(grid[0]) @@ -197,6 +205,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function differenceOfDistinctValues(grid: number[][]): number[][] { const m = grid.length; diff --git a/solution/2700-2799/2711.Difference of Number of Distinct Values on Diagonals/README_EN.md b/solution/2700-2799/2711.Difference of Number of Distinct Values on Diagonals/README_EN.md index 5b0a57ac83a85..f593d5b3148ec 100644 --- a/solution/2700-2799/2711.Difference of Number of Distinct Values on Diagonals/README_EN.md +++ b/solution/2700-2799/2711.Difference of Number of Distinct Values on Diagonals/README_EN.md @@ -81,6 +81,8 @@ The answers of other cells are similarly calculated. +#### Python3 + ```python class Solution: def differenceOfDistinctValues(self, grid: List[List[int]]) -> List[List[int]]: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] differenceOfDistinctValues(int[][] grid) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func differenceOfDistinctValues(grid [][]int) [][]int { m, n := len(grid), len(grid[0]) @@ -196,6 +204,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function differenceOfDistinctValues(grid: number[][]): number[][] { const m = grid.length; diff --git a/solution/2700-2799/2712.Minimum Cost to Make All Characters Equal/README.md b/solution/2700-2799/2712.Minimum Cost to Make All Characters Equal/README.md index b558cc276478d..28f65ebc72965 100644 --- a/solution/2700-2799/2712.Minimum Cost to Make All Characters Equal/README.md +++ b/solution/2700-2799/2712.Minimum Cost to Make All Characters Equal/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def minimumCost(self, s: str) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long minimumCost(String s) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func minimumCost(s string) (ans int64) { n := len(s) @@ -125,6 +133,8 @@ func minimumCost(s string) (ans int64) { } ``` +#### TypeScript + ```ts function minimumCost(s: string): number { let ans = 0; diff --git a/solution/2700-2799/2712.Minimum Cost to Make All Characters Equal/README_EN.md b/solution/2700-2799/2712.Minimum Cost to Make All Characters Equal/README_EN.md index 1156034bdf20f..e630798ffe95e 100644 --- a/solution/2700-2799/2712.Minimum Cost to Make All Characters Equal/README_EN.md +++ b/solution/2700-2799/2712.Minimum Cost to Make All Characters Equal/README_EN.md @@ -71,6 +71,8 @@ The total cost to make all characters equal is 9. It can be shown that 9 is the +#### Python3 + ```python class Solution: def minimumCost(self, s: str) -> int: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long minimumCost(String s) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func minimumCost(s string) (ans int64) { n := len(s) @@ -124,6 +132,8 @@ func minimumCost(s string) (ans int64) { } ``` +#### TypeScript + ```ts function minimumCost(s: string): number { let ans = 0; diff --git a/solution/2700-2799/2713.Maximum Strictly Increasing Cells in a Matrix/README.md b/solution/2700-2799/2713.Maximum Strictly Increasing Cells in a Matrix/README.md index 0cd20e456eba8..9693e6ca32902 100644 --- a/solution/2700-2799/2713.Maximum Strictly Increasing Cells in a Matrix/README.md +++ b/solution/2700-2799/2713.Maximum Strictly Increasing Cells in a Matrix/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def maxIncreasingCells(self, mat: List[List[int]]) -> int: @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxIncreasingCells(int[][] mat) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go func maxIncreasingCells(mat [][]int) (ans int) { m, n := len(mat), len(mat[0]) diff --git a/solution/2700-2799/2713.Maximum Strictly Increasing Cells in a Matrix/README_EN.md b/solution/2700-2799/2713.Maximum Strictly Increasing Cells in a Matrix/README_EN.md index 62bde531b6059..80916d086b372 100644 --- a/solution/2700-2799/2713.Maximum Strictly Increasing Cells in a Matrix/README_EN.md +++ b/solution/2700-2799/2713.Maximum Strictly Increasing Cells in a Matrix/README_EN.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def maxIncreasingCells(self, mat: List[List[int]]) -> int: @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxIncreasingCells(int[][] mat) { @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go func maxIncreasingCells(mat [][]int) (ans int) { m, n := len(mat), len(mat[0]) diff --git a/solution/2700-2799/2714.Find Shortest Path with K Hops/README.md b/solution/2700-2799/2714.Find Shortest Path with K Hops/README.md index 7bdd5a33b4507..a1f7386aa88ec 100644 --- a/solution/2700-2799/2714.Find Shortest Path with K Hops/README.md +++ b/solution/2700-2799/2714.Find Shortest Path with K Hops/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def shortestPathWithHops( @@ -116,6 +118,8 @@ class Solution: return int(min(dist[d])) ``` +#### Java + ```java class Solution { public int shortestPathWithHops(int n, int[][] edges, int s, int d, int k) { @@ -158,6 +162,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -192,6 +198,8 @@ public: }; ``` +#### Go + ```go func shortestPathWithHops(n int, edges [][]int, s int, d int, k int) int { g := make([][][2]int, n) diff --git a/solution/2700-2799/2714.Find Shortest Path with K Hops/README_EN.md b/solution/2700-2799/2714.Find Shortest Path with K Hops/README_EN.md index 9d74e760ae0c1..1c1209d39f77e 100644 --- a/solution/2700-2799/2714.Find Shortest Path with K Hops/README_EN.md +++ b/solution/2700-2799/2714.Find Shortest Path with K Hops/README_EN.md @@ -90,6 +90,8 @@ The time complexity is $O(n^2 \times \log n)$, and the space complexity is $O(n +#### Python3 + ```python class Solution: def shortestPathWithHops( @@ -114,6 +116,8 @@ class Solution: return int(min(dist[d])) ``` +#### Java + ```java class Solution { public int shortestPathWithHops(int n, int[][] edges, int s, int d, int k) { @@ -156,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -190,6 +196,8 @@ public: }; ``` +#### Go + ```go func shortestPathWithHops(n int, edges [][]int, s int, d int, k int) int { g := make([][][2]int, n) diff --git a/solution/2700-2799/2715.Timeout Cancellation/README.md b/solution/2700-2799/2715.Timeout Cancellation/README.md index 2fb1f1be36895..b3089e6318040 100644 --- a/solution/2700-2799/2715.Timeout Cancellation/README.md +++ b/solution/2700-2799/2715.Timeout Cancellation/README.md @@ -88,6 +88,8 @@ setTimeout(cancelFn, cancelTimeMs); +#### TypeScript + ```ts function cancellable(fn: Function, args: any[], t: number): Function { const timer = setTimeout(() => fn(...args), t); @@ -123,6 +125,8 @@ function cancellable(fn: Function, args: any[], t: number): Function { */ ``` +#### JavaScript + ```js /** * @param {Function} fn diff --git a/solution/2700-2799/2715.Timeout Cancellation/README_EN.md b/solution/2700-2799/2715.Timeout Cancellation/README_EN.md index e8406cbbd7e62..c6fc2ea363669 100644 --- a/solution/2700-2799/2715.Timeout Cancellation/README_EN.md +++ b/solution/2700-2799/2715.Timeout Cancellation/README_EN.md @@ -87,6 +87,8 @@ The cancellation was scheduled to occur after a delay of cancelTimeMs (100ms), w +#### TypeScript + ```ts function cancellable(fn: Function, args: any[], t: number): Function { const timer = setTimeout(() => fn(...args), t); @@ -122,6 +124,8 @@ function cancellable(fn: Function, args: any[], t: number): Function { */ ``` +#### JavaScript + ```js /** * @param {Function} fn diff --git a/solution/2700-2799/2716.Minimize String Length/README.md b/solution/2700-2799/2716.Minimize String Length/README.md index 6875437810272..e42a1aebad986 100644 --- a/solution/2700-2799/2716.Minimize String Length/README.md +++ b/solution/2700-2799/2716.Minimize String Length/README.md @@ -76,12 +76,16 @@ tags: +#### Python3 + ```python class Solution: def minimizedStringLength(self, s: str) -> int: return len(set(s)) ``` +#### Java + ```java class Solution { public int minimizedStringLength(String s) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -104,6 +110,8 @@ public: }; ``` +#### Go + ```go func minimizedStringLength(s string) int { ss := map[rune]struct{}{} @@ -114,12 +122,16 @@ func minimizedStringLength(s string) int { } ``` +#### TypeScript + ```ts function minimizedStringLength(s: string): number { return new Set(s.split('')).size; } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -146,6 +158,8 @@ impl Solution { +#### Rust + ```rust use std::collections::HashSet; diff --git a/solution/2700-2799/2716.Minimize String Length/README_EN.md b/solution/2700-2799/2716.Minimize String Length/README_EN.md index fa1764bd9bd21..add6435b9779f 100644 --- a/solution/2700-2799/2716.Minimize String Length/README_EN.md +++ b/solution/2700-2799/2716.Minimize String Length/README_EN.md @@ -77,12 +77,16 @@ The time complexity is $O(n)$, and the space complexity is $O(C)$. Here, $n$ is +#### Python3 + ```python class Solution: def minimizedStringLength(self, s: str) -> int: return len(set(s)) ``` +#### Java + ```java class Solution { public int minimizedStringLength(String s) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func minimizedStringLength(s string) int { ss := map[rune]struct{}{} @@ -115,12 +123,16 @@ func minimizedStringLength(s string) int { } ``` +#### TypeScript + ```ts function minimizedStringLength(s: string): number { return new Set(s.split('')).size; } ``` +#### Rust + ```rust use std::collections::HashMap; @@ -147,6 +159,8 @@ impl Solution { +#### Rust + ```rust use std::collections::HashSet; diff --git a/solution/2700-2799/2717.Semi-Ordered Permutation/README.md b/solution/2700-2799/2717.Semi-Ordered Permutation/README.md index e9f541ad1552e..f5f0573110661 100644 --- a/solution/2700-2799/2717.Semi-Ordered Permutation/README.md +++ b/solution/2700-2799/2717.Semi-Ordered Permutation/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def semiOrderedPermutation(self, nums: List[int]) -> int: @@ -100,6 +102,8 @@ class Solution: return i + n - j - k ``` +#### Java + ```java class Solution { public int semiOrderedPermutation(int[] nums) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func semiOrderedPermutation(nums []int) int { n := len(nums) @@ -152,6 +160,8 @@ func semiOrderedPermutation(nums []int) int { } ``` +#### TypeScript + ```ts function semiOrderedPermutation(nums: number[]): number { const n = nums.length; @@ -162,6 +172,8 @@ function semiOrderedPermutation(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn semi_ordered_permutation(nums: Vec) -> i32 { @@ -198,6 +210,8 @@ impl Solution { +#### Rust + ```rust impl Solution { pub fn semi_ordered_permutation(nums: Vec) -> i32 { diff --git a/solution/2700-2799/2717.Semi-Ordered Permutation/README_EN.md b/solution/2700-2799/2717.Semi-Ordered Permutation/README_EN.md index 95a1d5b4b3abd..bcfad92f83932 100644 --- a/solution/2700-2799/2717.Semi-Ordered Permutation/README_EN.md +++ b/solution/2700-2799/2717.Semi-Ordered Permutation/README_EN.md @@ -88,6 +88,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def semiOrderedPermutation(self, nums: List[int]) -> int: @@ -98,6 +100,8 @@ class Solution: return i + n - j - k ``` +#### Java + ```java class Solution { public int semiOrderedPermutation(int[] nums) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func semiOrderedPermutation(nums []int) int { n := len(nums) @@ -150,6 +158,8 @@ func semiOrderedPermutation(nums []int) int { } ``` +#### TypeScript + ```ts function semiOrderedPermutation(nums: number[]): number { const n = nums.length; @@ -160,6 +170,8 @@ function semiOrderedPermutation(nums: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn semi_ordered_permutation(nums: Vec) -> i32 { @@ -196,6 +208,8 @@ impl Solution { +#### Rust + ```rust impl Solution { pub fn semi_ordered_permutation(nums: Vec) -> i32 { diff --git a/solution/2700-2799/2718.Sum of Matrix After Queries/README.md b/solution/2700-2799/2718.Sum of Matrix After Queries/README.md index 1f1a250fa2c58..2f2832230b2fb 100644 --- a/solution/2700-2799/2718.Sum of Matrix After Queries/README.md +++ b/solution/2700-2799/2718.Sum of Matrix After Queries/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def matrixSumQueries(self, n: int, queries: List[List[int]]) -> int: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long matrixSumQueries(int n, int[][] queries) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func matrixSumQueries(n int, queries [][]int) (ans int64) { row, col := map[int]bool{}, map[int]bool{} @@ -175,6 +183,8 @@ func matrixSumQueries(n int, queries [][]int) (ans int64) { } ``` +#### TypeScript + ```ts function matrixSumQueries(n: number, queries: number[][]): number { const row: Set = new Set(); diff --git a/solution/2700-2799/2718.Sum of Matrix After Queries/README_EN.md b/solution/2700-2799/2718.Sum of Matrix After Queries/README_EN.md index 06b861791fe41..b266db66291bb 100644 --- a/solution/2700-2799/2718.Sum of Matrix After Queries/README_EN.md +++ b/solution/2700-2799/2718.Sum of Matrix After Queries/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(m)$, and the space complexity is $O(n)$. Here, $m$ rep +#### Python3 + ```python class Solution: def matrixSumQueries(self, n: int, queries: List[List[int]]) -> int: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long matrixSumQueries(int n, int[][] queries) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func matrixSumQueries(n int, queries [][]int) (ans int64) { row, col := map[int]bool{}, map[int]bool{} @@ -171,6 +179,8 @@ func matrixSumQueries(n int, queries [][]int) (ans int64) { } ``` +#### TypeScript + ```ts function matrixSumQueries(n: number, queries: number[][]): number { const row: Set = new Set(); diff --git a/solution/2700-2799/2719.Count of Integers/README.md b/solution/2700-2799/2719.Count of Integers/README.md index 18fe6bb1c108e..fcf2c9b557908 100644 --- a/solution/2700-2799/2719.Count of Integers/README.md +++ b/solution/2700-2799/2719.Count of Integers/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def count(self, num1: str, num2: str, min_sum: int, max_sum: int) -> int: @@ -101,6 +103,8 @@ class Solution: return (a - b) % mod ``` +#### Java + ```java import java.math.BigInteger; @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go func count(num1 string, num2 string, min_sum int, max_sum int) int { const mod = 1e9 + 7 @@ -243,6 +251,8 @@ func count(num1 string, num2 string, min_sum int, max_sum int) int { } ``` +#### TypeScript + ```ts function count(num1: string, num2: string, min_sum: number, max_sum: number): number { const mod = 1e9 + 7; diff --git a/solution/2700-2799/2719.Count of Integers/README_EN.md b/solution/2700-2799/2719.Count of Integers/README_EN.md index d1e5c070a8479..455a411b8c3f9 100644 --- a/solution/2700-2799/2719.Count of Integers/README_EN.md +++ b/solution/2700-2799/2719.Count of Integers/README_EN.md @@ -78,6 +78,8 @@ Similar problems: +#### Python3 + ```python class Solution: def count(self, num1: str, num2: str, min_sum: int, max_sum: int) -> int: @@ -99,6 +101,8 @@ class Solution: return (a - b) % mod ``` +#### Java + ```java import java.math.BigInteger; @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go func count(num1 string, num2 string, min_sum int, max_sum int) int { const mod = 1e9 + 7 @@ -241,6 +249,8 @@ func count(num1 string, num2 string, min_sum int, max_sum int) int { } ``` +#### TypeScript + ```ts function count(num1: string, num2: string, min_sum: number, max_sum: number): number { const mod = 1e9 + 7; diff --git a/solution/2700-2799/2720.Popularity Percentage/README.md b/solution/2700-2799/2720.Popularity Percentage/README.md index 7ced31d172237..2e9a9df75167d 100644 --- a/solution/2700-2799/2720.Popularity Percentage/README.md +++ b/solution/2700-2799/2720.Popularity Percentage/README.md @@ -92,6 +92,8 @@ user1 按升序排序。 +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2700-2799/2720.Popularity Percentage/README_EN.md b/solution/2700-2799/2720.Popularity Percentage/README_EN.md index d12c9265d12cd..4a5fd8081e2c5 100644 --- a/solution/2700-2799/2720.Popularity Percentage/README_EN.md +++ b/solution/2700-2799/2720.Popularity Percentage/README_EN.md @@ -92,6 +92,8 @@ user1 is sorted in ascending order. +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2700-2799/2721.Execute Asynchronous Functions in Parallel/README.md b/solution/2700-2799/2721.Execute Asynchronous Functions in Parallel/README.md index 8932ed43ac21a..b034bae7bbbc4 100644 --- a/solution/2700-2799/2721.Execute Asynchronous Functions in Parallel/README.md +++ b/solution/2700-2799/2721.Execute Asynchronous Functions in Parallel/README.md @@ -87,6 +87,8 @@ promiseAll(functions).then(console.log); // [5] +#### TypeScript + ```ts async function promiseAll(functions: (() => Promise)[]): Promise { return new Promise((resolve, reject) => { diff --git a/solution/2700-2799/2721.Execute Asynchronous Functions in Parallel/README_EN.md b/solution/2700-2799/2721.Execute Asynchronous Functions in Parallel/README_EN.md index 96bcc033a95e2..9176a300b9456 100644 --- a/solution/2700-2799/2721.Execute Asynchronous Functions in Parallel/README_EN.md +++ b/solution/2700-2799/2721.Execute Asynchronous Functions in Parallel/README_EN.md @@ -85,6 +85,8 @@ The single function was resolved at 200ms with a value of 5. +#### TypeScript + ```ts async function promiseAll(functions: (() => Promise)[]): Promise { return new Promise((resolve, reject) => { diff --git a/solution/2700-2799/2722.Join Two Arrays by ID/README.md b/solution/2700-2799/2722.Join Two Arrays by ID/README.md index b7137521b4951..ba69bc67defa3 100644 --- a/solution/2700-2799/2722.Join Two Arrays by ID/README.md +++ b/solution/2700-2799/2722.Join Two Arrays by ID/README.md @@ -106,6 +106,8 @@ arr2 = [ +#### TypeScript + ```ts function join(arr1: any[], arr2: any[]): any[] { const d = new Map(arr1.map(x => [x.id, x])); diff --git a/solution/2700-2799/2722.Join Two Arrays by ID/README_EN.md b/solution/2700-2799/2722.Join Two Arrays by ID/README_EN.md index 1300d1145a668..60780b24b5db6 100644 --- a/solution/2700-2799/2722.Join Two Arrays by ID/README_EN.md +++ b/solution/2700-2799/2722.Join Two Arrays by ID/README_EN.md @@ -104,6 +104,8 @@ arr2 = [ +#### TypeScript + ```ts function join(arr1: any[], arr2: any[]): any[] { const d = new Map(arr1.map(x => [x.id, x])); diff --git a/solution/2700-2799/2723.Add Two Promises/README.md b/solution/2700-2799/2723.Add Two Promises/README.md index ca59a927e5c2a..a32454416e035 100644 --- a/solution/2700-2799/2723.Add Two Promises/README.md +++ b/solution/2700-2799/2723.Add Two Promises/README.md @@ -56,6 +56,8 @@ promise2 = new Promise(resolve => setTimeout(() => resolve(-12), 30)) +#### TypeScript + ```ts async function addTwoPromises( promise1: Promise, @@ -70,6 +72,8 @@ async function addTwoPromises( */ ``` +#### JavaScript + ```js var addTwoPromises = async function (promise1, promise2) { return (await promise1) + (await promise2); diff --git a/solution/2700-2799/2723.Add Two Promises/README_EN.md b/solution/2700-2799/2723.Add Two Promises/README_EN.md index dbc45c58d80db..f9f845f1d75a2 100644 --- a/solution/2700-2799/2723.Add Two Promises/README_EN.md +++ b/solution/2700-2799/2723.Add Two Promises/README_EN.md @@ -54,6 +54,8 @@ promise2 = new Promise(resolve => setTimeout(() => resolve(-12), 30)) +#### TypeScript + ```ts async function addTwoPromises( promise1: Promise, @@ -68,6 +70,8 @@ async function addTwoPromises( */ ``` +#### JavaScript + ```js var addTwoPromises = async function (promise1, promise2) { return (await promise1) + (await promise2); diff --git a/solution/2700-2799/2724.Sort By/README.md b/solution/2700-2799/2724.Sort By/README.md index 8ddd3e404311f..868065d394a5e 100644 --- a/solution/2700-2799/2724.Sort By/README.md +++ b/solution/2700-2799/2724.Sort By/README.md @@ -64,6 +64,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2700-2799/2724.So +#### TypeScript + ```ts function sortBy(arr: any[], fn: Function): any[] { return arr.sort((a, b) => fn(a) - fn(b)); diff --git a/solution/2700-2799/2724.Sort By/README_EN.md b/solution/2700-2799/2724.Sort By/README_EN.md index 62efd476aa49f..13cf9d441a898 100644 --- a/solution/2700-2799/2724.Sort By/README_EN.md +++ b/solution/2700-2799/2724.Sort By/README_EN.md @@ -62,6 +62,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2700-2799/2724.So +#### TypeScript + ```ts function sortBy(arr: any[], fn: Function): any[] { return arr.sort((a, b) => fn(a) - fn(b)); diff --git a/solution/2700-2799/2725.Interval Cancellation/README.md b/solution/2700-2799/2725.Interval Cancellation/README.md index 5575020118651..6e1d331c850e0 100644 --- a/solution/2700-2799/2725.Interval Cancellation/README.md +++ b/solution/2700-2799/2725.Interval Cancellation/README.md @@ -128,6 +128,8 @@ setTimeout(cancelFn, cancelTimeMs) +#### TypeScript + ```ts function cancellable(fn: Function, args: any[], t: number): Function { fn(...args); diff --git a/solution/2700-2799/2725.Interval Cancellation/README_EN.md b/solution/2700-2799/2725.Interval Cancellation/README_EN.md index 650ac560df9ad..8659ea4543710 100644 --- a/solution/2700-2799/2725.Interval Cancellation/README_EN.md +++ b/solution/2700-2799/2725.Interval Cancellation/README_EN.md @@ -128,6 +128,8 @@ Cancelled at 180ms +#### TypeScript + ```ts function cancellable(fn: Function, args: any[], t: number): Function { fn(...args); diff --git a/solution/2700-2799/2726.Calculator with Method Chaining/README.md b/solution/2700-2799/2726.Calculator with Method Chaining/README.md index d63f8c600f947..db2d35206cffd 100644 --- a/solution/2700-2799/2726.Calculator with Method Chaining/README.md +++ b/solution/2700-2799/2726.Calculator with Method Chaining/README.md @@ -87,6 +87,8 @@ new Calculator(20).divide(0).getResult() // 20 / 0 +#### TypeScript + ```ts class Calculator { private x: number; diff --git a/solution/2700-2799/2726.Calculator with Method Chaining/README_EN.md b/solution/2700-2799/2726.Calculator with Method Chaining/README_EN.md index 01e7513bc3859..730be544e838e 100644 --- a/solution/2700-2799/2726.Calculator with Method Chaining/README_EN.md +++ b/solution/2700-2799/2726.Calculator with Method Chaining/README_EN.md @@ -88,6 +88,8 @@ The error should be thrown because we cannot divide by zero. +#### TypeScript + ```ts class Calculator { private x: number; diff --git a/solution/2700-2799/2727.Is Object Empty/README.md b/solution/2700-2799/2727.Is Object Empty/README.md index 4bb7cbabec892..224c733fd60c1 100644 --- a/solution/2700-2799/2727.Is Object Empty/README.md +++ b/solution/2700-2799/2727.Is Object Empty/README.md @@ -75,6 +75,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2700-2799/2727.Is +#### TypeScript + ```ts function isEmpty(obj: Record | any[]): boolean { for (const x in obj) { @@ -84,6 +86,8 @@ function isEmpty(obj: Record | any[]): boolean { } ``` +#### JavaScript + ```js /** * @param {Object | Array} obj @@ -107,6 +111,8 @@ var isEmpty = function (obj) { +#### TypeScript + ```ts function isEmpty(obj: Record | any[]): boolean { return Object.keys(obj).length === 0; diff --git a/solution/2700-2799/2727.Is Object Empty/README_EN.md b/solution/2700-2799/2727.Is Object Empty/README_EN.md index 19f3b006f5d92..7e97ee20a30f5 100644 --- a/solution/2700-2799/2727.Is Object Empty/README_EN.md +++ b/solution/2700-2799/2727.Is Object Empty/README_EN.md @@ -69,6 +69,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2700-2799/2727.Is +#### TypeScript + ```ts function isEmpty(obj: Record | any[]): boolean { for (const x in obj) { @@ -78,6 +80,8 @@ function isEmpty(obj: Record | any[]): boolean { } ``` +#### JavaScript + ```js /** * @param {Object | Array} obj @@ -101,6 +105,8 @@ var isEmpty = function (obj) { +#### TypeScript + ```ts function isEmpty(obj: Record | any[]): boolean { return Object.keys(obj).length === 0; diff --git a/solution/2700-2799/2728.Count Houses in a Circular Street/README.md b/solution/2700-2799/2728.Count Houses in a Circular Street/README.md index 89a0f9a353a7b..cc652be9961b2 100644 --- a/solution/2700-2799/2728.Count Houses in a Circular Street/README.md +++ b/solution/2700-2799/2728.Count Houses in a Circular Street/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python # Definition for a street. # class Street: @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a street. @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a street. @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a street. @@ -190,6 +198,8 @@ func houseCount(street Street, k int) (ans int) { } ``` +#### TypeScript + ```ts /** * Definition for a street. diff --git a/solution/2700-2799/2728.Count Houses in a Circular Street/README_EN.md b/solution/2700-2799/2728.Count Houses in a Circular Street/README_EN.md index 6faf8fef7945d..cbbe7c188236e 100644 --- a/solution/2700-2799/2728.Count Houses in a Circular Street/README_EN.md +++ b/solution/2700-2799/2728.Count Houses in a Circular Street/README_EN.md @@ -69,6 +69,8 @@ The number of houses is equal to k, which is 5. +#### Python3 + ```python # Definition for a street. # class Street: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a street. @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a street. @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a street. @@ -179,6 +187,8 @@ func houseCount(street Street, k int) (ans int) { } ``` +#### TypeScript + ```ts /** * Definition for a street. diff --git a/solution/2700-2799/2729.Check if The Number is Fascinating/README.md b/solution/2700-2799/2729.Check if The Number is Fascinating/README.md index 840e5360faf19..e940750ebd83a 100644 --- a/solution/2700-2799/2729.Check if The Number is Fascinating/README.md +++ b/solution/2700-2799/2729.Check if The Number is Fascinating/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def isFascinating(self, n: int) -> bool: @@ -76,6 +78,8 @@ class Solution: return "".join(sorted(s)) == "123456789" ``` +#### Java + ```java class Solution { public boolean isFascinating(int n) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -102,6 +108,8 @@ public: }; ``` +#### Go + ```go func isFascinating(n int) bool { s := strconv.Itoa(n) + strconv.Itoa(n*2) + strconv.Itoa(n*3) @@ -116,6 +124,8 @@ func isFascinating(n int) bool { } ``` +#### TypeScript + ```ts function isFascinating(n: number): boolean { const s = `${n}${n * 2}${n * 3}`; @@ -123,6 +133,8 @@ function isFascinating(n: number): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn is_fascinating(n: i32) -> bool { @@ -152,6 +164,8 @@ impl Solution { +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/2700-2799/2729.Check if The Number is Fascinating/README_EN.md b/solution/2700-2799/2729.Check if The Number is Fascinating/README_EN.md index 6c0196a830e93..a41a0d7a5d003 100644 --- a/solution/2700-2799/2729.Check if The Number is Fascinating/README_EN.md +++ b/solution/2700-2799/2729.Check if The Number is Fascinating/README_EN.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def isFascinating(self, n: int) -> bool: @@ -72,6 +74,8 @@ class Solution: return "".join(sorted(s)) == "123456789" ``` +#### Java + ```java class Solution { public boolean isFascinating(int n) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -98,6 +104,8 @@ public: }; ``` +#### Go + ```go func isFascinating(n int) bool { s := strconv.Itoa(n) + strconv.Itoa(n*2) + strconv.Itoa(n*3) @@ -112,6 +120,8 @@ func isFascinating(n int) bool { } ``` +#### TypeScript + ```ts function isFascinating(n: number): boolean { const s = `${n}${n * 2}${n * 3}`; @@ -119,6 +129,8 @@ function isFascinating(n: number): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn is_fascinating(n: i32) -> bool { @@ -148,6 +160,8 @@ impl Solution { +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/2700-2799/2730.Find the Longest Semi-Repetitive Substring/README.md b/solution/2700-2799/2730.Find the Longest Semi-Repetitive Substring/README.md index df32f85124c08..9e159f6673ec3 100644 --- a/solution/2700-2799/2730.Find the Longest Semi-Repetitive Substring/README.md +++ b/solution/2700-2799/2730.Find the Longest Semi-Repetitive Substring/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def longestSemiRepetitiveSubstring(self, s: str) -> int: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestSemiRepetitiveSubstring(String s) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func longestSemiRepetitiveSubstring(s string) (ans int) { ans = 1 @@ -143,6 +151,8 @@ func longestSemiRepetitiveSubstring(s string) (ans int) { } ``` +#### TypeScript + ```ts function longestSemiRepetitiveSubstring(s: string): number { const n = s.length; diff --git a/solution/2700-2799/2730.Find the Longest Semi-Repetitive Substring/README_EN.md b/solution/2700-2799/2730.Find the Longest Semi-Repetitive Substring/README_EN.md index 5db9657a54eb1..63ba99ecc71ca 100644 --- a/solution/2700-2799/2730.Find the Longest Semi-Repetitive Substring/README_EN.md +++ b/solution/2700-2799/2730.Find the Longest Semi-Repetitive Substring/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string. The space +#### Python3 + ```python class Solution: def longestSemiRepetitiveSubstring(self, s: str) -> int: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestSemiRepetitiveSubstring(String s) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func longestSemiRepetitiveSubstring(s string) (ans int) { ans = 1 @@ -141,6 +149,8 @@ func longestSemiRepetitiveSubstring(s string) (ans int) { } ``` +#### TypeScript + ```ts function longestSemiRepetitiveSubstring(s: string): number { const n = s.length; diff --git a/solution/2700-2799/2731.Movement of Robots/README.md b/solution/2700-2799/2731.Movement of Robots/README.md index 9f0bb196d9afb..8ebcc579fe67e 100644 --- a/solution/2700-2799/2731.Movement of Robots/README.md +++ b/solution/2700-2799/2731.Movement of Robots/README.md @@ -106,6 +106,8 @@ tags: +#### Python3 + ```python class Solution: def sumDistance(self, nums: List[int], s: str, d: int) -> int: @@ -120,6 +122,8 @@ class Solution: return ans % mod ``` +#### Java + ```java class Solution { public int sumDistance(int[] nums, String s, int d) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func sumDistance(nums []int, s string, d int) (ans int) { for i, c := range s { @@ -182,6 +190,8 @@ func sumDistance(nums []int, s string, d int) (ans int) { } ``` +#### TypeScript + ```ts function sumDistance(nums: number[], s: string, d: number): number { const n = nums.length; diff --git a/solution/2700-2799/2731.Movement of Robots/README_EN.md b/solution/2700-2799/2731.Movement of Robots/README_EN.md index b6dd8319ebe39..fe13001869f1e 100644 --- a/solution/2700-2799/2731.Movement of Robots/README_EN.md +++ b/solution/2700-2799/2731.Movement of Robots/README_EN.md @@ -97,6 +97,8 @@ The time complexity is $O(n \times \log n)$ and the space complexity is $O(n)$, +#### Python3 + ```python class Solution: def sumDistance(self, nums: List[int], s: str, d: int) -> int: @@ -111,6 +113,8 @@ class Solution: return ans % mod ``` +#### Java + ```java class Solution { public int sumDistance(int[] nums, String s, int d) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func sumDistance(nums []int, s string, d int) (ans int) { for i, c := range s { @@ -173,6 +181,8 @@ func sumDistance(nums []int, s string, d int) (ans int) { } ``` +#### TypeScript + ```ts function sumDistance(nums: number[], s: string, d: number): number { const n = nums.length; diff --git a/solution/2700-2799/2732.Find a Good Subset of the Matrix/README.md b/solution/2700-2799/2732.Find a Good Subset of the Matrix/README.md index 69583f1458521..a9bfc7cfac906 100644 --- a/solution/2700-2799/2732.Find a Good Subset of the Matrix/README.md +++ b/solution/2700-2799/2732.Find a Good Subset of the Matrix/README.md @@ -88,18 +88,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2700-2799/2732.Find a Good Subset of the Matrix/README_EN.md b/solution/2700-2799/2732.Find a Good Subset of the Matrix/README_EN.md index b5aa8dc5ca89e..2289f662722e2 100644 --- a/solution/2700-2799/2732.Find a Good Subset of the Matrix/README_EN.md +++ b/solution/2700-2799/2732.Find a Good Subset of the Matrix/README_EN.md @@ -86,18 +86,26 @@ The length of the chosen subset is 1. +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2700-2799/2733.Neither Minimum nor Maximum/README.md b/solution/2700-2799/2733.Neither Minimum nor Maximum/README.md index fe993509b92b4..9f3104587d63c 100644 --- a/solution/2700-2799/2733.Neither Minimum nor Maximum/README.md +++ b/solution/2700-2799/2733.Neither Minimum nor Maximum/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def findNonMinOrMax(self, nums: List[int]) -> int: @@ -77,6 +79,8 @@ class Solution: return next((x for x in nums if x != mi and x != mx), -1) ``` +#### Java + ```java class Solution { public int findNonMinOrMax(int[] nums) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func findNonMinOrMax(nums []int) int { mi, mx := slices.Min(nums), slices.Max(nums) @@ -122,6 +130,8 @@ func findNonMinOrMax(nums []int) int { } ``` +#### Rust + ```rust impl Solution { pub fn find_non_min_or_max(nums: Vec) -> i32 { @@ -158,6 +168,8 @@ impl Solution { +#### Python3 + ```python class Solution: def findNonMinOrMax(self, nums: List[int]) -> int: diff --git a/solution/2700-2799/2733.Neither Minimum nor Maximum/README_EN.md b/solution/2700-2799/2733.Neither Minimum nor Maximum/README_EN.md index 07b10570a5dcc..e46af268e3a5d 100644 --- a/solution/2700-2799/2733.Neither Minimum nor Maximum/README_EN.md +++ b/solution/2700-2799/2733.Neither Minimum nor Maximum/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def findNonMinOrMax(self, nums: List[int]) -> int: @@ -78,6 +80,8 @@ class Solution: return next((x for x in nums if x != mi and x != mx), -1) ``` +#### Java + ```java class Solution { public int findNonMinOrMax(int[] nums) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func findNonMinOrMax(nums []int) int { mi, mx := slices.Min(nums), slices.Max(nums) @@ -123,6 +131,8 @@ func findNonMinOrMax(nums []int) int { } ``` +#### Rust + ```rust impl Solution { pub fn find_non_min_or_max(nums: Vec) -> i32 { @@ -159,6 +169,8 @@ impl Solution { +#### Python3 + ```python class Solution: def findNonMinOrMax(self, nums: List[int]) -> int: diff --git a/solution/2700-2799/2734.Lexicographically Smallest String After Substring Operation/README.md b/solution/2700-2799/2734.Lexicographically Smallest String After Substring Operation/README.md index 31fdd6c6a3419..5bcd4fd9133e9 100644 --- a/solution/2700-2799/2734.Lexicographically Smallest String After Substring Operation/README.md +++ b/solution/2700-2799/2734.Lexicographically Smallest String After Substring Operation/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def smallestString(self, s: str) -> str: @@ -93,6 +95,8 @@ class Solution: return s[:i] + "".join(chr(ord(c) - 1) for c in s[i:j]) + s[j:] ``` +#### Java + ```java class Solution { public String smallestString(String s) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func smallestString(s string) string { n := len(s) @@ -159,6 +167,8 @@ func smallestString(s string) string { } ``` +#### TypeScript + ```ts function smallestString(s: string): string { const cs: string[] = s.split(''); @@ -184,6 +194,8 @@ function smallestString(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn smallest_string(s: String) -> String { diff --git a/solution/2700-2799/2734.Lexicographically Smallest String After Substring Operation/README_EN.md b/solution/2700-2799/2734.Lexicographically Smallest String After Substring Operation/README_EN.md index c971adf2cc5bc..f28fd1e4f0946 100644 --- a/solution/2700-2799/2734.Lexicographically Smallest String After Substring Operation/README_EN.md +++ b/solution/2700-2799/2734.Lexicographically Smallest String After Substring Operation/README_EN.md @@ -75,6 +75,8 @@ It can be proven that the resulting string is the lexicographically smallest. +#### Python3 + ```python class Solution: def smallestString(self, s: str) -> str: @@ -90,6 +92,8 @@ class Solution: return s[:i] + "".join(chr(ord(c) - 1) for c in s[i:j]) + s[j:] ``` +#### Java + ```java class Solution { public String smallestString(String s) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func smallestString(s string) string { n := len(s) @@ -156,6 +164,8 @@ func smallestString(s string) string { } ``` +#### TypeScript + ```ts function smallestString(s: string): string { const cs: string[] = s.split(''); @@ -181,6 +191,8 @@ function smallestString(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn smallest_string(s: String) -> String { diff --git a/solution/2700-2799/2735.Collecting Chocolates/README.md b/solution/2700-2799/2735.Collecting Chocolates/README.md index 9b5d357780ecc..e7673f2e91c90 100644 --- a/solution/2700-2799/2735.Collecting Chocolates/README.md +++ b/solution/2700-2799/2735.Collecting Chocolates/README.md @@ -92,6 +92,8 @@ $$ +#### Python3 + ```python class Solution: def minCost(self, nums: List[int], x: int) -> int: @@ -104,6 +106,8 @@ class Solution: return min(sum(f[i][j] for i in range(n)) + x * j for j in range(n)) ``` +#### Java + ```java class Solution { public long minCost(int[] nums, int x) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func minCost(nums []int, x int) int64 { n := len(nums) @@ -176,6 +184,8 @@ func minCost(nums []int, x int) int64 { } ``` +#### TypeScript + ```ts function minCost(nums: number[], x: number): number { const n = nums.length; @@ -198,6 +208,8 @@ function minCost(nums: number[], x: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_cost(nums: Vec, x: i32) -> i64 { diff --git a/solution/2700-2799/2735.Collecting Chocolates/README_EN.md b/solution/2700-2799/2735.Collecting Chocolates/README_EN.md index 2c312a2995f93..457a4934152f1 100644 --- a/solution/2700-2799/2735.Collecting Chocolates/README_EN.md +++ b/solution/2700-2799/2735.Collecting Chocolates/README_EN.md @@ -90,6 +90,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$. Where $n$ +#### Python3 + ```python class Solution: def minCost(self, nums: List[int], x: int) -> int: @@ -102,6 +104,8 @@ class Solution: return min(sum(f[i][j] for i in range(n)) + x * j for j in range(n)) ``` +#### Java + ```java class Solution { public long minCost(int[] nums, int x) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func minCost(nums []int, x int) int64 { n := len(nums) @@ -174,6 +182,8 @@ func minCost(nums []int, x int) int64 { } ``` +#### TypeScript + ```ts function minCost(nums: number[], x: number): number { const n = nums.length; @@ -196,6 +206,8 @@ function minCost(nums: number[], x: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn min_cost(nums: Vec, x: i32) -> i64 { diff --git a/solution/2700-2799/2736.Maximum Sum Queries/README.md b/solution/2700-2799/2736.Maximum Sum Queries/README.md index b4421f3431d7c..314658c5846c5 100644 --- a/solution/2700-2799/2736.Maximum Sum Queries/README.md +++ b/solution/2700-2799/2736.Maximum Sum Queries/README.md @@ -103,6 +103,8 @@ $$ +#### Python3 + ```python class BinaryIndexedTree: __slots__ = ["n", "c"] @@ -145,6 +147,8 @@ class Solution: return ans ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -206,6 +210,8 @@ class Solution { } ``` +#### Java + ```java class Solution { public int[] maximumSumQueries(int[] nums1, int[] nums2, int[][] q) { @@ -251,6 +257,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { private: @@ -310,6 +318,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -369,6 +379,8 @@ func maximumSumQueries(nums1 []int, nums2 []int, queries [][]int) []int { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; diff --git a/solution/2700-2799/2736.Maximum Sum Queries/README_EN.md b/solution/2700-2799/2736.Maximum Sum Queries/README_EN.md index 134615543700e..c0296eba71310 100644 --- a/solution/2700-2799/2736.Maximum Sum Queries/README_EN.md +++ b/solution/2700-2799/2736.Maximum Sum Queries/README_EN.md @@ -107,6 +107,8 @@ Similar problems: +#### Python3 + ```python class BinaryIndexedTree: __slots__ = ["n", "c"] @@ -149,6 +151,8 @@ class Solution: return ans ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -210,6 +214,8 @@ class Solution { } ``` +#### Java + ```java class Solution { public int[] maximumSumQueries(int[] nums1, int[] nums2, int[][] q) { @@ -255,6 +261,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { private: @@ -314,6 +322,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -373,6 +383,8 @@ func maximumSumQueries(nums1 []int, nums2 []int, queries [][]int) []int { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; diff --git a/solution/2700-2799/2737.Find the Closest Marked Node/README.md b/solution/2700-2799/2737.Find the Closest Marked Node/README.md index 249728808d04a..617a3dd65e3ea 100644 --- a/solution/2700-2799/2737.Find the Closest Marked Node/README.md +++ b/solution/2700-2799/2737.Find the Closest Marked Node/README.md @@ -97,6 +97,8 @@ tags: +#### Python3 + ```python class Solution: def minimumDistance( @@ -120,6 +122,8 @@ class Solution: return -1 if ans >= inf else ans ``` +#### Java + ```java class Solution { public int minimumDistance(int n, List> edges, int s, int[] marked) { @@ -157,6 +161,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -191,6 +197,8 @@ public: }; ``` +#### Go + ```go func minimumDistance(n int, edges [][]int, s int, marked []int) int { const inf = 1 << 29 @@ -232,6 +240,8 @@ func minimumDistance(n int, edges [][]int, s int, marked []int) int { } ``` +#### TypeScript + ```ts function minimumDistance(n: number, edges: number[][], s: number, marked: number[]): number { const inf = 1 << 29; diff --git a/solution/2700-2799/2737.Find the Closest Marked Node/README_EN.md b/solution/2700-2799/2737.Find the Closest Marked Node/README_EN.md index da23a7d1b339f..75ad6022c1c09 100644 --- a/solution/2700-2799/2737.Find the Closest Marked Node/README_EN.md +++ b/solution/2700-2799/2737.Find the Closest Marked Node/README_EN.md @@ -95,6 +95,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$. Here, $n$ +#### Python3 + ```python class Solution: def minimumDistance( @@ -118,6 +120,8 @@ class Solution: return -1 if ans >= inf else ans ``` +#### Java + ```java class Solution { public int minimumDistance(int n, List> edges, int s, int[] marked) { @@ -155,6 +159,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -189,6 +195,8 @@ public: }; ``` +#### Go + ```go func minimumDistance(n int, edges [][]int, s int, marked []int) int { const inf = 1 << 29 @@ -230,6 +238,8 @@ func minimumDistance(n int, edges [][]int, s int, marked []int) int { } ``` +#### TypeScript + ```ts function minimumDistance(n: number, edges: number[][], s: number, marked: number[]): number { const inf = 1 << 29; diff --git a/solution/2700-2799/2738.Count Occurrences in Text/README.md b/solution/2700-2799/2738.Count Occurrences in Text/README.md index ba95682674e8f..719cd0ae2ffee 100644 --- a/solution/2700-2799/2738.Count Occurrences in Text/README.md +++ b/solution/2700-2799/2738.Count Occurrences in Text/README.md @@ -77,6 +77,8 @@ Files 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT 'bull' AS word, COUNT(*) AS count diff --git a/solution/2700-2799/2738.Count Occurrences in Text/README_EN.md b/solution/2700-2799/2738.Count Occurrences in Text/README_EN.md index 06d9fa125d6f8..342f88ac7e79e 100644 --- a/solution/2700-2799/2738.Count Occurrences in Text/README_EN.md +++ b/solution/2700-2799/2738.Count Occurrences in Text/README_EN.md @@ -76,6 +76,8 @@ Files table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT 'bull' AS word, COUNT(*) AS count diff --git a/solution/2700-2799/2739.Total Distance Traveled/README.md b/solution/2700-2799/2739.Total Distance Traveled/README.md index 19e9aaf5a8e78..2476f1b5c1de7 100644 --- a/solution/2700-2799/2739.Total Distance Traveled/README.md +++ b/solution/2700-2799/2739.Total Distance Traveled/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def distanceTraveled(self, mainTank: int, additionalTank: int) -> int: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int distanceTraveled(int mainTank, int additionalTank) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func distanceTraveled(mainTank int, additionalTank int) (ans int) { cur := 0 @@ -137,6 +145,8 @@ func distanceTraveled(mainTank int, additionalTank int) (ans int) { } ``` +#### Rust + ```rust impl Solution { pub fn distance_traveled(mut main_tank: i32, mut additional_tank: i32) -> i32 { @@ -159,6 +169,8 @@ impl Solution { } ``` +#### JavaScript + ```js var distanceTraveled = function (mainTank, additionalTank) { let ans = 0, diff --git a/solution/2700-2799/2739.Total Distance Traveled/README_EN.md b/solution/2700-2799/2739.Total Distance Traveled/README_EN.md index 5c5b64dff05e6..32b69e8999fbd 100644 --- a/solution/2700-2799/2739.Total Distance Traveled/README_EN.md +++ b/solution/2700-2799/2739.Total Distance Traveled/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(n + m)$, where $n$ and $m$ are the amounts of fuel in +#### Python3 + ```python class Solution: def distanceTraveled(self, mainTank: int, additionalTank: int) -> int: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int distanceTraveled(int mainTank, int additionalTank) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func distanceTraveled(mainTank int, additionalTank int) (ans int) { cur := 0 @@ -138,6 +146,8 @@ func distanceTraveled(mainTank int, additionalTank int) (ans int) { } ``` +#### Rust + ```rust impl Solution { pub fn distance_traveled(mut main_tank: i32, mut additional_tank: i32) -> i32 { @@ -160,6 +170,8 @@ impl Solution { } ``` +#### JavaScript + ```js var distanceTraveled = function (mainTank, additionalTank) { let ans = 0, diff --git a/solution/2700-2799/2740.Find the Value of the Partition/README.md b/solution/2700-2799/2740.Find the Value of the Partition/README.md index 4b5f7dfa805bf..d3d5ea2c61396 100644 --- a/solution/2700-2799/2740.Find the Value of the Partition/README.md +++ b/solution/2700-2799/2740.Find the Value of the Partition/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def findValueOfPartition(self, nums: List[int]) -> int: @@ -89,6 +91,8 @@ class Solution: return min(b - a for a, b in pairwise(nums)) ``` +#### Java + ```java class Solution { public int findValueOfPartition(int[] nums) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func findValueOfPartition(nums []int) int { sort.Ints(nums) diff --git a/solution/2700-2799/2740.Find the Value of the Partition/README_EN.md b/solution/2700-2799/2740.Find the Value of the Partition/README_EN.md index 7d269a9594cb1..141c414f9431c 100644 --- a/solution/2700-2799/2740.Find the Value of the Partition/README_EN.md +++ b/solution/2700-2799/2740.Find the Value of the Partition/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def findValueOfPartition(self, nums: List[int]) -> int: @@ -89,6 +91,8 @@ class Solution: return min(b - a for a, b in pairwise(nums)) ``` +#### Java + ```java class Solution { public int findValueOfPartition(int[] nums) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func findValueOfPartition(nums []int) int { sort.Ints(nums) diff --git a/solution/2700-2799/2741.Special Permutations/README.md b/solution/2700-2799/2741.Special Permutations/README.md index d7f7c79b53e07..f9722dfe15b17 100644 --- a/solution/2700-2799/2741.Special Permutations/README.md +++ b/solution/2700-2799/2741.Special Permutations/README.md @@ -81,6 +81,8 @@ $$ +#### Python3 + ```python class Solution: def specialPerm(self, nums: List[int]) -> int: @@ -101,6 +103,8 @@ class Solution: return sum(f[-1]) % mod ``` +#### Java + ```java class Solution { public int specialPerm(int[] nums) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func specialPerm(nums []int) (ans int) { const mod int = 1e9 + 7 diff --git a/solution/2700-2799/2741.Special Permutations/README_EN.md b/solution/2700-2799/2741.Special Permutations/README_EN.md index 2b430c4c0ce91..ba2bb1f01f0ad 100644 --- a/solution/2700-2799/2741.Special Permutations/README_EN.md +++ b/solution/2700-2799/2741.Special Permutations/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(n^2 \times 2^n)$, and the space complexity is $O(n \ti +#### Python3 + ```python class Solution: def specialPerm(self, nums: List[int]) -> int: @@ -101,6 +103,8 @@ class Solution: return sum(f[-1]) % mod ``` +#### Java + ```java class Solution { public int specialPerm(int[] nums) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func specialPerm(nums []int) (ans int) { const mod int = 1e9 + 7 diff --git a/solution/2700-2799/2742.Painting the Walls/README.md b/solution/2700-2799/2742.Painting the Walls/README.md index 06cf5125dce17..43be9bfc16aaa 100644 --- a/solution/2700-2799/2742.Painting the Walls/README.md +++ b/solution/2700-2799/2742.Painting the Walls/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def paintWalls(self, cost: List[int], time: List[int]) -> int: @@ -92,6 +94,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private int n; @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func paintWalls(cost []int, time []int) int { n := len(cost) @@ -173,6 +181,8 @@ func paintWalls(cost []int, time []int) int { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/2700-2799/2742.Painting the Walls/README_EN.md b/solution/2700-2799/2742.Painting the Walls/README_EN.md index bd0815448f806..4ed33d1670909 100644 --- a/solution/2700-2799/2742.Painting the Walls/README_EN.md +++ b/solution/2700-2799/2742.Painting the Walls/README_EN.md @@ -77,6 +77,8 @@ Time complexity $O(n^2)$, space complexity $O(n^2)$. Where $n$ is the length of +#### Python3 + ```python class Solution: def paintWalls(self, cost: List[int], time: List[int]) -> int: @@ -92,6 +94,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private int n; @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func paintWalls(cost []int, time []int) int { n := len(cost) @@ -173,6 +181,8 @@ func paintWalls(cost []int, time []int) int { } ``` +#### Rust + ```rust impl Solution { #[allow(dead_code)] diff --git a/solution/2700-2799/2743.Count Substrings Without Repeating Character/README.md b/solution/2700-2799/2743.Count Substrings Without Repeating Character/README.md index 00fdddcdb059e..fe5597ee9542e 100644 --- a/solution/2700-2799/2743.Count Substrings Without Repeating Character/README.md +++ b/solution/2700-2799/2743.Count Substrings Without Repeating Character/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfSpecialSubstrings(self, s: str) -> int: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numberOfSpecialSubstrings(String s) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func numberOfSpecialSubstrings(s string) (ans int) { j := 0 @@ -145,6 +153,8 @@ func numberOfSpecialSubstrings(s string) (ans int) { } ``` +#### TypeScript + ```ts function numberOfSpecialSubstrings(s: string): number { const idx = (c: string) => c.charCodeAt(0) - 'a'.charCodeAt(0); diff --git a/solution/2700-2799/2743.Count Substrings Without Repeating Character/README_EN.md b/solution/2700-2799/2743.Count Substrings Without Repeating Character/README_EN.md index 2a97a820d4365..5c1613131121f 100644 --- a/solution/2700-2799/2743.Count Substrings Without Repeating Character/README_EN.md +++ b/solution/2700-2799/2743.Count Substrings Without Repeating Character/README_EN.md @@ -73,6 +73,8 @@ The time complexity is $O(n)$, and the space complexity is $O(C)$. Here, $n$ is +#### Python3 + ```python class Solution: def numberOfSpecialSubstrings(self, s: str) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numberOfSpecialSubstrings(String s) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func numberOfSpecialSubstrings(s string) (ans int) { j := 0 @@ -143,6 +151,8 @@ func numberOfSpecialSubstrings(s string) (ans int) { } ``` +#### TypeScript + ```ts function numberOfSpecialSubstrings(s: string): number { const idx = (c: string) => c.charCodeAt(0) - 'a'.charCodeAt(0); diff --git a/solution/2700-2799/2744.Find Maximum Number of String Pairs/README.md b/solution/2700-2799/2744.Find Maximum Number of String Pairs/README.md index 23dff76509f5f..639521f518825 100644 --- a/solution/2700-2799/2744.Find Maximum Number of String Pairs/README.md +++ b/solution/2700-2799/2744.Find Maximum Number of String Pairs/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class Solution: def maximumNumberOfStringPairs(self, words: List[str]) -> int: @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumNumberOfStringPairs(String[] words) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func maximumNumberOfStringPairs(words []string) (ans int) { cnt := map[int]int{} @@ -148,6 +156,8 @@ func maximumNumberOfStringPairs(words []string) (ans int) { } ``` +#### TypeScript + ```ts function maximumNumberOfStringPairs(words: string[]): number { const cnt: { [key: number]: number } = {}; diff --git a/solution/2700-2799/2744.Find Maximum Number of String Pairs/README_EN.md b/solution/2700-2799/2744.Find Maximum Number of String Pairs/README_EN.md index 283ca56671678..b892ea5182cfc 100644 --- a/solution/2700-2799/2744.Find Maximum Number of String Pairs/README_EN.md +++ b/solution/2700-2799/2744.Find Maximum Number of String Pairs/README_EN.md @@ -91,6 +91,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def maximumNumberOfStringPairs(self, words: List[str]) -> int: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumNumberOfStringPairs(String[] words) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func maximumNumberOfStringPairs(words []string) (ans int) { cnt := map[int]int{} @@ -145,6 +153,8 @@ func maximumNumberOfStringPairs(words []string) (ans int) { } ``` +#### TypeScript + ```ts function maximumNumberOfStringPairs(words: string[]): number { const cnt: { [key: number]: number } = {}; diff --git a/solution/2700-2799/2745.Construct the Longest New String/README.md b/solution/2700-2799/2745.Construct the Longest New String/README.md index 2992f2033bfff..7e0bc94dd6c60 100644 --- a/solution/2700-2799/2745.Construct the Longest New String/README.md +++ b/solution/2700-2799/2745.Construct the Longest New String/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def longestString(self, x: int, y: int, z: int) -> int: @@ -85,6 +87,8 @@ class Solution: return (x + y + z) * 2 ``` +#### Java + ```java class Solution { public int longestString(int x, int y, int z) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func longestString(x int, y int, z int) int { if x < y { @@ -126,6 +134,8 @@ func longestString(x int, y int, z int) int { } ``` +#### TypeScript + ```ts function longestString(x: number, y: number, z: number): number { if (x < y) { diff --git a/solution/2700-2799/2745.Construct the Longest New String/README_EN.md b/solution/2700-2799/2745.Construct the Longest New String/README_EN.md index 67bb3605d8556..8a22a21228c99 100644 --- a/solution/2700-2799/2745.Construct the Longest New String/README_EN.md +++ b/solution/2700-2799/2745.Construct the Longest New String/README_EN.md @@ -73,6 +73,8 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def longestString(self, x: int, y: int, z: int) -> int: @@ -83,6 +85,8 @@ class Solution: return (x + y + z) * 2 ``` +#### Java + ```java class Solution { public int longestString(int x, int y, int z) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -112,6 +118,8 @@ public: }; ``` +#### Go + ```go func longestString(x int, y int, z int) int { if x < y { @@ -124,6 +132,8 @@ func longestString(x int, y int, z int) int { } ``` +#### TypeScript + ```ts function longestString(x: number, y: number, z: number): number { if (x < y) { diff --git a/solution/2700-2799/2746.Decremental String Concatenation/README.md b/solution/2700-2799/2746.Decremental String Concatenation/README.md index 23afcea13d4d6..e741a1d0fb614 100644 --- a/solution/2700-2799/2746.Decremental String Concatenation/README.md +++ b/solution/2700-2799/2746.Decremental String Concatenation/README.md @@ -105,6 +105,8 @@ join(str0, "b") = "ab" 或者 join("b", str0) = "bab" 。 +#### Python3 + ```python class Solution: def minimizeConcatenatedLength(self, words: List[str]) -> int: @@ -120,6 +122,8 @@ class Solution: return len(words[0]) + dfs(1, words[0][0], words[0][-1]) ``` +#### Java + ```java class Solution { private Integer[][][] f; @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go func minimizeConcatenatedLength(words []string) int { n := len(words) @@ -204,6 +212,8 @@ func minimizeConcatenatedLength(words []string) int { } ``` +#### TypeScript + ```ts function minimizeConcatenatedLength(words: string[]): number { const n = words.length; diff --git a/solution/2700-2799/2746.Decremental String Concatenation/README_EN.md b/solution/2700-2799/2746.Decremental String Concatenation/README_EN.md index 53a225ac2b773..e83f37fb86286 100644 --- a/solution/2700-2799/2746.Decremental String Concatenation/README_EN.md +++ b/solution/2700-2799/2746.Decremental String Concatenation/README_EN.md @@ -105,6 +105,8 @@ The time complexity is $O(n \times C^2)$, and the space complexity is $O(n \time +#### Python3 + ```python class Solution: def minimizeConcatenatedLength(self, words: List[str]) -> int: @@ -120,6 +122,8 @@ class Solution: return len(words[0]) + dfs(1, words[0][0], words[0][-1]) ``` +#### Java + ```java class Solution { private Integer[][][] f; @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go func minimizeConcatenatedLength(words []string) int { n := len(words) @@ -204,6 +212,8 @@ func minimizeConcatenatedLength(words []string) int { } ``` +#### TypeScript + ```ts function minimizeConcatenatedLength(words: string[]): number { const n = words.length; diff --git a/solution/2700-2799/2747.Count Zero Request Servers/README.md b/solution/2700-2799/2747.Count Zero Request Servers/README.md index 2cacc48877704..5a9276db7cb46 100644 --- a/solution/2700-2799/2747.Count Zero Request Servers/README.md +++ b/solution/2700-2799/2747.Count Zero Request Servers/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def countServers( @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] countServers(int n, int[][] logs, int x, int[] queries) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func countServers(n int, logs [][]int, x int, queries []int) []int { sort.Slice(logs, func(i, j int) bool { return logs[i][1] < logs[j][1] }) @@ -203,6 +211,8 @@ func countServers(n int, logs [][]int, x int, queries []int) []int { } ``` +#### TypeScript + ```ts function countServers(n: number, logs: number[][], x: number, queries: number[]): number[] { logs.sort((a, b) => a[1] - b[1]); diff --git a/solution/2700-2799/2747.Count Zero Request Servers/README_EN.md b/solution/2700-2799/2747.Count Zero Request Servers/README_EN.md index a2431e0b12024..821a87a3fce9c 100644 --- a/solution/2700-2799/2747.Count Zero Request Servers/README_EN.md +++ b/solution/2700-2799/2747.Count Zero Request Servers/README_EN.md @@ -76,6 +76,8 @@ For queries[1]: Only server with id 3 gets no request in the duration [2,4]. +#### Python3 + ```python class Solution: def countServers( @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] countServers(int n, int[][] logs, int x, int[] queries) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func countServers(n int, logs [][]int, x int, queries []int) []int { sort.Slice(logs, func(i, j int) bool { return logs[i][1] < logs[j][1] }) @@ -197,6 +205,8 @@ func countServers(n int, logs [][]int, x int, queries []int) []int { } ``` +#### TypeScript + ```ts function countServers(n: number, logs: number[][], x: number, queries: number[]): number[] { logs.sort((a, b) => a[1] - b[1]); diff --git a/solution/2700-2799/2748.Number of Beautiful Pairs/README.md b/solution/2700-2799/2748.Number of Beautiful Pairs/README.md index 359cea765c734..bb9ceeded64b0 100644 --- a/solution/2700-2799/2748.Number of Beautiful Pairs/README.md +++ b/solution/2700-2799/2748.Number of Beautiful Pairs/README.md @@ -72,6 +72,8 @@ i = 0 和 j = 2 :nums[0] 的第一个数字是 1 ,nums[2] 的最后一个数 +#### Python3 + ```python class Solution: def countBeautifulPairs(self, nums: List[int]) -> int: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countBeautifulPairs(int[] nums) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func countBeautifulPairs(nums []int) (ans int) { cnt := [10]int{} @@ -157,6 +165,8 @@ func gcd(a, b int) int { } ``` +#### TypeScript + ```ts function countBeautifulPairs(nums: number[]): number { const cnt: number[] = Array(10).fill(0); diff --git a/solution/2700-2799/2748.Number of Beautiful Pairs/README_EN.md b/solution/2700-2799/2748.Number of Beautiful Pairs/README_EN.md index 6d1b060c35046..bce8938de3f38 100644 --- a/solution/2700-2799/2748.Number of Beautiful Pairs/README_EN.md +++ b/solution/2700-2799/2748.Number of Beautiful Pairs/README_EN.md @@ -71,6 +71,8 @@ Thus, we return 2. +#### Python3 + ```python class Solution: def countBeautifulPairs(self, nums: List[int]) -> int: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countBeautifulPairs(int[] nums) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func countBeautifulPairs(nums []int) (ans int) { cnt := [10]int{} @@ -156,6 +164,8 @@ func gcd(a, b int) int { } ``` +#### TypeScript + ```ts function countBeautifulPairs(nums: number[]): number { const cnt: number[] = Array(10).fill(0); diff --git a/solution/2700-2799/2749.Minimum Operations to Make the Integer Zero/README.md b/solution/2700-2799/2749.Minimum Operations to Make the Integer Zero/README.md index 406d0ed8b31fe..3085eac02d571 100644 --- a/solution/2700-2799/2749.Minimum Operations to Make the Integer Zero/README.md +++ b/solution/2700-2799/2749.Minimum Operations to Make the Integer Zero/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def makeTheIntegerZero(self, num1: int, num2: int) -> int: @@ -92,6 +94,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int makeTheIntegerZero(int num1, int num2) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func makeTheIntegerZero(num1 int, num2 int) int { for k := 1; ; k++ { diff --git a/solution/2700-2799/2749.Minimum Operations to Make the Integer Zero/README_EN.md b/solution/2700-2799/2749.Minimum Operations to Make the Integer Zero/README_EN.md index e98fea24055b4..9c856a5f39992 100644 --- a/solution/2700-2799/2749.Minimum Operations to Make the Integer Zero/README_EN.md +++ b/solution/2700-2799/2749.Minimum Operations to Make the Integer Zero/README_EN.md @@ -66,6 +66,8 @@ It can be proven, that 3 is the minimum number of operations that we need to per +#### Python3 + ```python class Solution: def makeTheIntegerZero(self, num1: int, num2: int) -> int: @@ -78,6 +80,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int makeTheIntegerZero(int num1, int num2) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -114,6 +120,8 @@ public: }; ``` +#### Go + ```go func makeTheIntegerZero(num1 int, num2 int) int { for k := 1; ; k++ { diff --git a/solution/2700-2799/2750.Ways to Split Array Into Good Subarrays/README.md b/solution/2700-2799/2750.Ways to Split Array Into Good Subarrays/README.md index 85491ce7b0dde..3598cc04bbe81 100644 --- a/solution/2700-2799/2750.Ways to Split Array Into Good Subarrays/README.md +++ b/solution/2700-2799/2750.Ways to Split Array Into Good Subarrays/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfGoodSubarraySplits(self, nums: List[int]) -> int: @@ -84,6 +86,8 @@ class Solution: return 0 if j == -1 else ans ``` +#### Java + ```java class Solution { public int numberOfGoodSubarraySplits(int[] nums) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func numberOfGoodSubarraySplits(nums []int) int { const mod int = 1e9 + 7 @@ -143,6 +151,8 @@ func numberOfGoodSubarraySplits(nums []int) int { } ``` +#### TypeScript + ```ts function numberOfGoodSubarraySplits(nums: number[]): number { let ans = 1; @@ -162,6 +172,8 @@ function numberOfGoodSubarraySplits(nums: number[]): number { } ``` +#### C# + ```cs public class Solution { public int NumberOfGoodSubarraySplits(int[] nums) { diff --git a/solution/2700-2799/2750.Ways to Split Array Into Good Subarrays/README_EN.md b/solution/2700-2799/2750.Ways to Split Array Into Good Subarrays/README_EN.md index 41517886c659a..4b05464c56e17 100644 --- a/solution/2700-2799/2750.Ways to Split Array Into Good Subarrays/README_EN.md +++ b/solution/2700-2799/2750.Ways to Split Array Into Good Subarrays/README_EN.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfGoodSubarraySplits(self, nums: List[int]) -> int: @@ -80,6 +82,8 @@ class Solution: return 0 if j == -1 else ans ``` +#### Java + ```java class Solution { public int numberOfGoodSubarraySplits(int[] nums) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func numberOfGoodSubarraySplits(nums []int) int { const mod int = 1e9 + 7 @@ -139,6 +147,8 @@ func numberOfGoodSubarraySplits(nums []int) int { } ``` +#### TypeScript + ```ts function numberOfGoodSubarraySplits(nums: number[]): number { let ans = 1; @@ -158,6 +168,8 @@ function numberOfGoodSubarraySplits(nums: number[]): number { } ``` +#### C# + ```cs public class Solution { public int NumberOfGoodSubarraySplits(int[] nums) { diff --git a/solution/2700-2799/2751.Robot Collisions/README.md b/solution/2700-2799/2751.Robot Collisions/README.md index 0653b48d66913..ed0bb46be82ec 100644 --- a/solution/2700-2799/2751.Robot Collisions/README.md +++ b/solution/2700-2799/2751.Robot Collisions/README.md @@ -87,18 +87,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2700-2799/2751.Robot Collisions/README_EN.md b/solution/2700-2799/2751.Robot Collisions/README_EN.md index 5cf832a66cd08..f624b21067c2e 100644 --- a/solution/2700-2799/2751.Robot Collisions/README_EN.md +++ b/solution/2700-2799/2751.Robot Collisions/README_EN.md @@ -87,18 +87,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2700-2799/2752.Customers with Maximum Number of Transactions on Consecutive Days/README.md b/solution/2700-2799/2752.Customers with Maximum Number of Transactions on Consecutive Days/README.md index 6bb5a5ec53b1d..2f62808e7f5b9 100644 --- a/solution/2700-2799/2752.Customers with Maximum Number of Transactions on Consecutive Days/README.md +++ b/solution/2700-2799/2752.Customers with Maximum Number of Transactions on Consecutive Days/README.md @@ -80,6 +80,8 @@ Transactions 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2700-2799/2752.Customers with Maximum Number of Transactions on Consecutive Days/README_EN.md b/solution/2700-2799/2752.Customers with Maximum Number of Transactions on Consecutive Days/README_EN.md index 572cb999a05bb..baa6eb2806b8f 100644 --- a/solution/2700-2799/2752.Customers with Maximum Number of Transactions on Consecutive Days/README_EN.md +++ b/solution/2700-2799/2752.Customers with Maximum Number of Transactions on Consecutive Days/README_EN.md @@ -80,6 +80,8 @@ In total, the highest number of consecutive transactions is 3, achieved by custo +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2700-2799/2753.Count Houses in a Circular Street II/README.md b/solution/2700-2799/2753.Count Houses in a Circular Street II/README.md index 9a172ec164583..a13de9ce1c317 100644 --- a/solution/2700-2799/2753.Count Houses in a Circular Street II/README.md +++ b/solution/2700-2799/2753.Count Houses in a Circular Street II/README.md @@ -80,6 +80,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2700-2799/2753.Co +#### Python3 + ```python # Definition for a street. # class Street: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a street. @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a street. @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a street. @@ -183,6 +191,8 @@ func houseCount(street Street, k int) (ans int) { } ``` +#### TypeScript + ```ts /** * Definition for a street. diff --git a/solution/2700-2799/2753.Count Houses in a Circular Street II/README_EN.md b/solution/2700-2799/2753.Count Houses in a Circular Street II/README_EN.md index acecb9cb936a7..8b6747744dff2 100644 --- a/solution/2700-2799/2753.Count Houses in a Circular Street II/README_EN.md +++ b/solution/2700-2799/2753.Count Houses in a Circular Street II/README_EN.md @@ -68,6 +68,8 @@ The number of houses is equal to k, which is 5. +#### Python3 + ```python # Definition for a street. # class Street: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a street. @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a street. @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a street. @@ -171,6 +179,8 @@ func houseCount(street Street, k int) (ans int) { } ``` +#### TypeScript + ```ts /** * Definition for a street. diff --git a/solution/2700-2799/2754.Bind Function to Context/README.md b/solution/2700-2799/2754.Bind Function to Context/README.md index de7a019a787b7..9efc28374931e 100644 --- a/solution/2700-2799/2754.Bind Function to Context/README.md +++ b/solution/2700-2799/2754.Bind Function to Context/README.md @@ -97,6 +97,8 @@ boundFunc(); // "My name is Kathy" +#### TypeScript + ```ts type Fn = (...args) => any; diff --git a/solution/2700-2799/2754.Bind Function to Context/README_EN.md b/solution/2700-2799/2754.Bind Function to Context/README_EN.md index 1ccd084f6041c..687902e2b3051 100644 --- a/solution/2700-2799/2754.Bind Function to Context/README_EN.md +++ b/solution/2700-2799/2754.Bind Function to Context/README_EN.md @@ -95,6 +95,8 @@ boundFunc(); // "My name is Kathy" +#### TypeScript + ```ts type Fn = (...args) => any; diff --git a/solution/2700-2799/2755.Deep Merge of Two Objects/README.md b/solution/2700-2799/2755.Deep Merge of Two Objects/README.md index a145b0512650c..2a61b2c6abba4 100644 --- a/solution/2700-2799/2755.Deep Merge of Two Objects/README.md +++ b/solution/2700-2799/2755.Deep Merge of Two Objects/README.md @@ -83,6 +83,8 @@ obj2 = {"a": 1, "b": {"c": [6, [6], [9]], "e": 3}} +#### TypeScript + ```ts function deepMerge(obj1: any, obj2: any): any { const isObj = (obj: any) => obj && typeof obj === 'object'; diff --git a/solution/2700-2799/2755.Deep Merge of Two Objects/README_EN.md b/solution/2700-2799/2755.Deep Merge of Two Objects/README_EN.md index 4a974eb03c323..40abd15bf3eea 100644 --- a/solution/2700-2799/2755.Deep Merge of Two Objects/README_EN.md +++ b/solution/2700-2799/2755.Deep Merge of Two Objects/README_EN.md @@ -81,6 +81,8 @@ obj2["b"]["c"] has key "e" that obj1 doesn't h +#### TypeScript + ```ts function deepMerge(obj1: any, obj2: any): any { const isObj = (obj: any) => obj && typeof obj === 'object'; diff --git a/solution/2700-2799/2756.Query Batching/README.md b/solution/2700-2799/2756.Query Batching/README.md index 383602a26cf46..a97c42c912888 100644 --- a/solution/2700-2799/2756.Query Batching/README.md +++ b/solution/2700-2799/2756.Query Batching/README.md @@ -144,6 +144,8 @@ calls = [ +#### TypeScript + ```ts ``` diff --git a/solution/2700-2799/2756.Query Batching/README_EN.md b/solution/2700-2799/2756.Query Batching/README_EN.md index da828117df8e1..c0ee5ff3c8569 100644 --- a/solution/2700-2799/2756.Query Batching/README_EN.md +++ b/solution/2700-2799/2756.Query Batching/README_EN.md @@ -140,6 +140,8 @@ queryMultiple(['f']) is called at t=350ms, it is resolved at 450ms +#### TypeScript + ```ts ``` diff --git a/solution/2700-2799/2757.Generate Circular Array Values/README.md b/solution/2700-2799/2757.Generate Circular Array Values/README.md index 8e7201af11728..85291ef28a0e1 100644 --- a/solution/2700-2799/2757.Generate Circular Array Values/README.md +++ b/solution/2700-2799/2757.Generate Circular Array Values/README.md @@ -86,6 +86,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2700-2799/2757.Ge +#### TypeScript + ```ts function* cycleGenerator(arr: number[], startIndex: number): Generator { const n = arr.length; diff --git a/solution/2700-2799/2757.Generate Circular Array Values/README_EN.md b/solution/2700-2799/2757.Generate Circular Array Values/README_EN.md index 8a3bc1535ff13..aa40722172e74 100644 --- a/solution/2700-2799/2757.Generate Circular Array Values/README_EN.md +++ b/solution/2700-2799/2757.Generate Circular Array Values/README_EN.md @@ -88,6 +88,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2700-2799/2757.Ge +#### TypeScript + ```ts function* cycleGenerator(arr: number[], startIndex: number): Generator { const n = arr.length; diff --git a/solution/2700-2799/2758.Next Day/README.md b/solution/2700-2799/2758.Next Day/README.md index ab83ca574999c..6b751e6858616 100644 --- a/solution/2700-2799/2758.Next Day/README.md +++ b/solution/2700-2799/2758.Next Day/README.md @@ -54,6 +54,8 @@ date.nextDay(); // "2014-06-21" +#### TypeScript + ```ts declare global { interface Date { diff --git a/solution/2700-2799/2758.Next Day/README_EN.md b/solution/2700-2799/2758.Next Day/README_EN.md index 5a669115e7a52..5d192314d7554 100644 --- a/solution/2700-2799/2758.Next Day/README_EN.md +++ b/solution/2700-2799/2758.Next Day/README_EN.md @@ -52,6 +52,8 @@ date.nextDay(); // "2014-06-21" +#### TypeScript + ```ts declare global { interface Date { diff --git a/solution/2700-2799/2759.Convert JSON String to Object/README.md b/solution/2700-2799/2759.Convert JSON String to Object/README.md index f033d32cea3cc..e5dc5a42aa86e 100644 --- a/solution/2700-2799/2759.Convert JSON String to Object/README.md +++ b/solution/2700-2799/2759.Convert JSON String to Object/README.md @@ -60,6 +60,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2700-2799/2759.Co +#### TypeScript + ```ts function jsonParse(str: string): any { const n = str.length; diff --git a/solution/2700-2799/2759.Convert JSON String to Object/README_EN.md b/solution/2700-2799/2759.Convert JSON String to Object/README_EN.md index e564f4ff65a83..3e03d4f86f091 100644 --- a/solution/2700-2799/2759.Convert JSON String to Object/README_EN.md +++ b/solution/2700-2799/2759.Convert JSON String to Object/README_EN.md @@ -58,6 +58,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2700-2799/2759.Co +#### TypeScript + ```ts function jsonParse(str: string): any { const n = str.length; diff --git a/solution/2700-2799/2760.Longest Even Odd Subarray With Threshold/README.md b/solution/2700-2799/2760.Longest Even Odd Subarray With Threshold/README.md index 4c373d04e0a5f..98a54258dfd79 100644 --- a/solution/2700-2799/2760.Longest Even Odd Subarray With Threshold/README.md +++ b/solution/2700-2799/2760.Longest Even Odd Subarray With Threshold/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def longestAlternatingSubarray(self, nums: List[int], threshold: int) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestAlternatingSubarray(int[] nums, int threshold) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func longestAlternatingSubarray(nums []int, threshold int) (ans int) { n := len(nums) @@ -150,6 +158,8 @@ func longestAlternatingSubarray(nums []int, threshold int) (ans int) { } ``` +#### TypeScript + ```ts function longestAlternatingSubarray(nums: number[], threshold: number): number { const n = nums.length; @@ -181,6 +191,8 @@ function longestAlternatingSubarray(nums: number[], threshold: number): number { +#### Python3 + ```python class Solution: def longestAlternatingSubarray(self, nums: List[int], threshold: int) -> int: @@ -197,6 +209,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestAlternatingSubarray(int[] nums, int threshold) { @@ -218,6 +232,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -240,6 +256,8 @@ public: }; ``` +#### Go + ```go func longestAlternatingSubarray(nums []int, threshold int) (ans int) { for l, n := 0, len(nums); l < n; { @@ -258,6 +276,8 @@ func longestAlternatingSubarray(nums []int, threshold int) (ans int) { } ``` +#### TypeScript + ```ts function longestAlternatingSubarray(nums: number[], threshold: number): number { const n = nums.length; diff --git a/solution/2700-2799/2760.Longest Even Odd Subarray With Threshold/README_EN.md b/solution/2700-2799/2760.Longest Even Odd Subarray With Threshold/README_EN.md index 55f3ba78f52ab..93a9521664300 100644 --- a/solution/2700-2799/2760.Longest Even Odd Subarray With Threshold/README_EN.md +++ b/solution/2700-2799/2760.Longest Even Odd Subarray With Threshold/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n^2)$, where $n$ is the length of the array $nums$. Th +#### Python3 + ```python class Solution: def longestAlternatingSubarray(self, nums: List[int], threshold: int) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestAlternatingSubarray(int[] nums, int threshold) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func longestAlternatingSubarray(nums []int, threshold int) (ans int) { n := len(nums) @@ -150,6 +158,8 @@ func longestAlternatingSubarray(nums []int, threshold int) (ans int) { } ``` +#### TypeScript + ```ts function longestAlternatingSubarray(nums: number[], threshold: number): number { const n = nums.length; @@ -181,6 +191,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def longestAlternatingSubarray(self, nums: List[int], threshold: int) -> int: @@ -197,6 +209,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestAlternatingSubarray(int[] nums, int threshold) { @@ -218,6 +232,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -240,6 +256,8 @@ public: }; ``` +#### Go + ```go func longestAlternatingSubarray(nums []int, threshold int) (ans int) { for l, n := 0, len(nums); l < n; { @@ -258,6 +276,8 @@ func longestAlternatingSubarray(nums []int, threshold int) (ans int) { } ``` +#### TypeScript + ```ts function longestAlternatingSubarray(nums: number[], threshold: number): number { const n = nums.length; diff --git a/solution/2700-2799/2761.Prime Pairs With Target Sum/README.md b/solution/2700-2799/2761.Prime Pairs With Target Sum/README.md index 0e3ac1687617c..74d3ca91f881c 100644 --- a/solution/2700-2799/2761.Prime Pairs With Target Sum/README.md +++ b/solution/2700-2799/2761.Prime Pairs With Target Sum/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def findPrimePairs(self, n: int) -> List[List[int]]: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> findPrimePairs(int n) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func findPrimePairs(n int) (ans [][]int) { primes := make([]bool, n) @@ -164,6 +172,8 @@ func findPrimePairs(n int) (ans [][]int) { } ``` +#### TypeScript + ```ts function findPrimePairs(n: number): number[][] { const primes: boolean[] = new Array(n).fill(true); diff --git a/solution/2700-2799/2761.Prime Pairs With Target Sum/README_EN.md b/solution/2700-2799/2761.Prime Pairs With Target Sum/README_EN.md index 5c35101a88da8..00d43ff7cb91b 100644 --- a/solution/2700-2799/2761.Prime Pairs With Target Sum/README_EN.md +++ b/solution/2700-2799/2761.Prime Pairs With Target Sum/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(n \log \log n)$ and the space complexity is $O(n)$, wh +#### Python3 + ```python class Solution: def findPrimePairs(self, n: int) -> List[List[int]]: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List> findPrimePairs(int n) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func findPrimePairs(n int) (ans [][]int) { primes := make([]bool, n) @@ -164,6 +172,8 @@ func findPrimePairs(n int) (ans [][]int) { } ``` +#### TypeScript + ```ts function findPrimePairs(n: number): number[][] { const primes: boolean[] = new Array(n).fill(true); diff --git a/solution/2700-2799/2762.Continuous Subarrays/README.md b/solution/2700-2799/2762.Continuous Subarrays/README.md index 7e99b62b96d23..b9b3fcb68402a 100644 --- a/solution/2700-2799/2762.Continuous Subarrays/README.md +++ b/solution/2700-2799/2762.Continuous Subarrays/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python from sortedcontainers import SortedList @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long continuousSubarrays(int[] nums) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func continuousSubarrays(nums []int) (ans int64) { i := 0 diff --git a/solution/2700-2799/2762.Continuous Subarrays/README_EN.md b/solution/2700-2799/2762.Continuous Subarrays/README_EN.md index 410fb2297899b..0e75cdd023e96 100644 --- a/solution/2700-2799/2762.Continuous Subarrays/README_EN.md +++ b/solution/2700-2799/2762.Continuous Subarrays/README_EN.md @@ -88,6 +88,8 @@ The time complexity is $O(n \times \log n)$ and the space complexity is $O(n)$, +#### Python3 + ```python from sortedcontainers import SortedList @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long continuousSubarrays(int[] nums) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func continuousSubarrays(nums []int) (ans int64) { i := 0 diff --git a/solution/2700-2799/2763.Sum of Imbalance Numbers of All Subarrays/README.md b/solution/2700-2799/2763.Sum of Imbalance Numbers of All Subarrays/README.md index 2f5b99fd916db..e443e54314275 100644 --- a/solution/2700-2799/2763.Sum of Imbalance Numbers of All Subarrays/README.md +++ b/solution/2700-2799/2763.Sum of Imbalance Numbers of All Subarrays/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python from sortedcontainers import SortedList @@ -116,6 +118,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int sumImbalanceNumbers(int[] nums) { @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git a/solution/2700-2799/2763.Sum of Imbalance Numbers of All Subarrays/README_EN.md b/solution/2700-2799/2763.Sum of Imbalance Numbers of All Subarrays/README_EN.md index 9b56c01b29591..4259e60bb808b 100644 --- a/solution/2700-2799/2763.Sum of Imbalance Numbers of All Subarrays/README_EN.md +++ b/solution/2700-2799/2763.Sum of Imbalance Numbers of All Subarrays/README_EN.md @@ -91,6 +91,8 @@ The time complexity is $O(n^2 \times \log n)$ and the space complexity is $O(n)$ +#### Python3 + ```python from sortedcontainers import SortedList @@ -116,6 +118,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int sumImbalanceNumbers(int[] nums) { @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: diff --git "a/solution/2700-2799/2764.Is Array a Preorder of Some \342\200\214Binary Tree/README.md" "b/solution/2700-2799/2764.Is Array a Preorder of Some \342\200\214Binary Tree/README.md" index 856ca78639c7b..94bf372e0efcb 100644 --- "a/solution/2700-2799/2764.Is Array a Preorder of Some \342\200\214Binary Tree/README.md" +++ "b/solution/2700-2799/2764.Is Array a Preorder of Some \342\200\214Binary Tree/README.md" @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def isPreorder(self, nodes: List[List[int]]) -> bool: @@ -103,6 +105,8 @@ class Solution: return dfs(nodes[0][0]) and k == len(nodes) ``` +#### Java + ```java class Solution { private Map> g = new HashMap<>(); @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func isPreorder(nodes [][]int) bool { k := 0 @@ -182,6 +190,8 @@ func isPreorder(nodes [][]int) bool { } ``` +#### TypeScript + ```ts function isPreorder(nodes: number[][]): boolean { let k = 0; diff --git "a/solution/2700-2799/2764.Is Array a Preorder of Some \342\200\214Binary Tree/README_EN.md" "b/solution/2700-2799/2764.Is Array a Preorder of Some \342\200\214Binary Tree/README_EN.md" index 8916b69f87ce1..26f0a49a8ffbf 100644 --- "a/solution/2700-2799/2764.Is Array a Preorder of Some \342\200\214Binary Tree/README_EN.md" +++ "b/solution/2700-2799/2764.Is Array a Preorder of Some \342\200\214Binary Tree/README_EN.md" @@ -71,6 +71,8 @@ For the preorder traversal, first we visit node 0, then we do the preorder trave +#### Python3 + ```python class Solution: def isPreorder(self, nodes: List[List[int]]) -> bool: @@ -88,6 +90,8 @@ class Solution: return dfs(nodes[0][0]) and k == len(nodes) ``` +#### Java + ```java class Solution { private Map> g = new HashMap<>(); @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func isPreorder(nodes [][]int) bool { k := 0 @@ -167,6 +175,8 @@ func isPreorder(nodes [][]int) bool { } ``` +#### TypeScript + ```ts function isPreorder(nodes: number[][]): boolean { let k = 0; diff --git a/solution/2700-2799/2765.Longest Alternating Subarray/README.md b/solution/2700-2799/2765.Longest Alternating Subarray/README.md index b072cf95411ec..0afb76cf37c1f 100644 --- a/solution/2700-2799/2765.Longest Alternating Subarray/README.md +++ b/solution/2700-2799/2765.Longest Alternating Subarray/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def alternatingSubarray(self, nums: List[int]) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int alternatingSubarray(int[] nums) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func alternatingSubarray(nums []int) int { ans, n := -1, len(nums) @@ -143,6 +151,8 @@ func alternatingSubarray(nums []int) int { } ``` +#### TypeScript + ```ts function alternatingSubarray(nums: number[]): number { let ans = -1; diff --git a/solution/2700-2799/2765.Longest Alternating Subarray/README_EN.md b/solution/2700-2799/2765.Longest Alternating Subarray/README_EN.md index 9dd6eee8d7598..016a15e5616e9 100644 --- a/solution/2700-2799/2765.Longest Alternating Subarray/README_EN.md +++ b/solution/2700-2799/2765.Longest Alternating Subarray/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n^2)$, where $n$ is the length of the array. We need t +#### Python3 + ```python class Solution: def alternatingSubarray(self, nums: List[int]) -> int: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int alternatingSubarray(int[] nums) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func alternatingSubarray(nums []int) int { ans, n := -1, len(nums) @@ -141,6 +149,8 @@ func alternatingSubarray(nums []int) int { } ``` +#### TypeScript + ```ts function alternatingSubarray(nums: number[]): number { let ans = -1; diff --git a/solution/2700-2799/2766.Relocate Marbles/README.md b/solution/2700-2799/2766.Relocate Marbles/README.md index e7319e984f780..297f0e86fcb5e 100644 --- a/solution/2700-2799/2766.Relocate Marbles/README.md +++ b/solution/2700-2799/2766.Relocate Marbles/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def relocateMarbles( @@ -96,6 +98,8 @@ class Solution: return sorted(pos) ``` +#### Java + ```java class Solution { public List relocateMarbles(int[] nums, int[] moveFrom, int[] moveTo) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func relocateMarbles(nums []int, moveFrom []int, moveTo []int) (ans []int) { pos := map[int]bool{} @@ -151,6 +159,8 @@ func relocateMarbles(nums []int, moveFrom []int, moveTo []int) (ans []int) { } ``` +#### TypeScript + ```ts function relocateMarbles(nums: number[], moveFrom: number[], moveTo: number[]): number[] { const pos: Set = new Set(nums); diff --git a/solution/2700-2799/2766.Relocate Marbles/README_EN.md b/solution/2700-2799/2766.Relocate Marbles/README_EN.md index 60d73210b1603..2d4cddb4f23bd 100644 --- a/solution/2700-2799/2766.Relocate Marbles/README_EN.md +++ b/solution/2700-2799/2766.Relocate Marbles/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n \times \log n)$ and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def relocateMarbles( @@ -94,6 +96,8 @@ class Solution: return sorted(pos) ``` +#### Java + ```java class Solution { public List relocateMarbles(int[] nums, int[] moveFrom, int[] moveTo) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func relocateMarbles(nums []int, moveFrom []int, moveTo []int) (ans []int) { pos := map[int]bool{} @@ -149,6 +157,8 @@ func relocateMarbles(nums []int, moveFrom []int, moveTo []int) (ans []int) { } ``` +#### TypeScript + ```ts function relocateMarbles(nums: number[], moveFrom: number[], moveTo: number[]): number[] { const pos: Set = new Set(nums); diff --git a/solution/2700-2799/2767.Partition String Into Minimum Beautiful Substrings/README.md b/solution/2700-2799/2767.Partition String Into Minimum Beautiful Substrings/README.md index 6402352c187b8..dd64914664ede 100644 --- a/solution/2700-2799/2767.Partition String Into Minimum Beautiful Substrings/README.md +++ b/solution/2700-2799/2767.Partition String Into Minimum Beautiful Substrings/README.md @@ -97,6 +97,8 @@ tags: +#### Python3 + ```python class Solution: def minimumBeautifulSubstrings(self, s: str) -> int: @@ -124,6 +126,8 @@ class Solution: return -1 if ans == inf else ans ``` +#### Java + ```java class Solution { private Integer[] f; @@ -167,6 +171,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -206,6 +212,8 @@ public: }; ``` +#### Go + ```go func minimumBeautifulSubstrings(s string) int { ss := map[int]bool{} @@ -246,6 +254,8 @@ func minimumBeautifulSubstrings(s string) int { } ``` +#### TypeScript + ```ts function minimumBeautifulSubstrings(s: string): number { const ss: Set = new Set(); diff --git a/solution/2700-2799/2767.Partition String Into Minimum Beautiful Substrings/README_EN.md b/solution/2700-2799/2767.Partition String Into Minimum Beautiful Substrings/README_EN.md index 5032905cba424..14eec4ee7fe17 100644 --- a/solution/2700-2799/2767.Partition String Into Minimum Beautiful Substrings/README_EN.md +++ b/solution/2700-2799/2767.Partition String Into Minimum Beautiful Substrings/README_EN.md @@ -98,6 +98,8 @@ Time complexity $O(n^2)$, space complexity $O(n)$. Where $n$ is the length of st +#### Python3 + ```python class Solution: def minimumBeautifulSubstrings(self, s: str) -> int: @@ -125,6 +127,8 @@ class Solution: return -1 if ans == inf else ans ``` +#### Java + ```java class Solution { private Integer[] f; @@ -168,6 +172,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -207,6 +213,8 @@ public: }; ``` +#### Go + ```go func minimumBeautifulSubstrings(s string) int { ss := map[int]bool{} @@ -247,6 +255,8 @@ func minimumBeautifulSubstrings(s string) int { } ``` +#### TypeScript + ```ts function minimumBeautifulSubstrings(s: string): number { const ss: Set = new Set(); diff --git a/solution/2700-2799/2768.Number of Black Blocks/README.md b/solution/2700-2799/2768.Number of Black Blocks/README.md index 8879f9ac655a8..d9211a0062bfd 100644 --- a/solution/2700-2799/2768.Number of Black Blocks/README.md +++ b/solution/2700-2799/2768.Number of Black Blocks/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def countBlackBlocks( @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long[] countBlackBlocks(int m, int n, int[][] coordinates) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func countBlackBlocks(m int, n int, coordinates [][]int) []int64 { cnt := map[int64]int{} @@ -180,6 +188,8 @@ func countBlackBlocks(m int, n int, coordinates [][]int) []int64 { } ``` +#### TypeScript + ```ts function countBlackBlocks(m: number, n: number, coordinates: number[][]): number[] { const cnt: Map = new Map(); diff --git a/solution/2700-2799/2768.Number of Black Blocks/README_EN.md b/solution/2700-2799/2768.Number of Black Blocks/README_EN.md index 41f97ae8e8518..12c783abe92b5 100644 --- a/solution/2700-2799/2768.Number of Black Blocks/README_EN.md +++ b/solution/2700-2799/2768.Number of Black Blocks/README_EN.md @@ -86,6 +86,8 @@ Time complexity $O(l)$, space complexity $O(l)$, where $l$ is the length of $coo +#### Python3 + ```python class Solution: def countBlackBlocks( @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long[] countBlackBlocks(int m, int n, int[][] coordinates) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func countBlackBlocks(m int, n int, coordinates [][]int) []int64 { cnt := map[int64]int{} @@ -178,6 +186,8 @@ func countBlackBlocks(m int, n int, coordinates [][]int) []int64 { } ``` +#### TypeScript + ```ts function countBlackBlocks(m: number, n: number, coordinates: number[][]): number[] { const cnt: Map = new Map(); diff --git a/solution/2700-2799/2769.Find the Maximum Achievable Number/README.md b/solution/2700-2799/2769.Find the Maximum Achievable Number/README.md index 821285f17ec0f..89cc83c80979f 100644 --- a/solution/2700-2799/2769.Find the Maximum Achievable Number/README.md +++ b/solution/2700-2799/2769.Find the Maximum Achievable Number/README.md @@ -71,12 +71,16 @@ tags: +#### Python3 + ```python class Solution: def theMaximumAchievableX(self, num: int, t: int) -> int: return num + t * 2 ``` +#### Java + ```java class Solution { public int theMaximumAchievableX(int num, int t) { @@ -85,6 +89,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -94,12 +100,16 @@ public: }; ``` +#### Go + ```go func theMaximumAchievableX(num int, t int) int { return num + t*2 } ``` +#### TypeScript + ```ts function theMaximumAchievableX(num: number, t: number): number { return num + t * 2; diff --git a/solution/2700-2799/2769.Find the Maximum Achievable Number/README_EN.md b/solution/2700-2799/2769.Find the Maximum Achievable Number/README_EN.md index 1dd716593cad0..c08f0bab1424e 100644 --- a/solution/2700-2799/2769.Find the Maximum Achievable Number/README_EN.md +++ b/solution/2700-2799/2769.Find the Maximum Achievable Number/README_EN.md @@ -72,12 +72,16 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def theMaximumAchievableX(self, num: int, t: int) -> int: return num + t * 2 ``` +#### Java + ```java class Solution { public int theMaximumAchievableX(int num, int t) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -95,12 +101,16 @@ public: }; ``` +#### Go + ```go func theMaximumAchievableX(num int, t int) int { return num + t*2 } ``` +#### TypeScript + ```ts function theMaximumAchievableX(num: number, t: number): number { return num + t * 2; diff --git a/solution/2700-2799/2770.Maximum Number of Jumps to Reach the Last Index/README.md b/solution/2700-2799/2770.Maximum Number of Jumps to Reach the Last Index/README.md index 3679eab189426..f632509e7e278 100644 --- a/solution/2700-2799/2770.Maximum Number of Jumps to Reach the Last Index/README.md +++ b/solution/2700-2799/2770.Maximum Number of Jumps to Reach the Last Index/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class Solution: def maximumJumps(self, nums: List[int], target: int) -> int: @@ -114,6 +116,8 @@ class Solution: return -1 if ans < 0 else ans ``` +#### Java + ```java class Solution { private Integer[] f; @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go func maximumJumps(nums []int, target int) int { n := len(nums) @@ -214,6 +222,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function maximumJumps(nums: number[], target: number): number { const n = nums.length; diff --git a/solution/2700-2799/2770.Maximum Number of Jumps to Reach the Last Index/README_EN.md b/solution/2700-2799/2770.Maximum Number of Jumps to Reach the Last Index/README_EN.md index 5ab7091547fde..03a0fcc12170e 100644 --- a/solution/2700-2799/2770.Maximum Number of Jumps to Reach the Last Index/README_EN.md +++ b/solution/2700-2799/2770.Maximum Number of Jumps to Reach the Last Index/README_EN.md @@ -97,6 +97,8 @@ Time complexity $O(n^2)$, space complexity $O(n)$. where $n$ is the length of ar +#### Python3 + ```python class Solution: def maximumJumps(self, nums: List[int], target: int) -> int: @@ -115,6 +117,8 @@ class Solution: return -1 if ans < 0 else ans ``` +#### Java + ```java class Solution { private Integer[] f; @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go func maximumJumps(nums []int, target int) int { n := len(nums) @@ -215,6 +223,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function maximumJumps(nums: number[], target: number): number { const n = nums.length; diff --git a/solution/2700-2799/2771.Longest Non-decreasing Subarray From Two Arrays/README.md b/solution/2700-2799/2771.Longest Non-decreasing Subarray From Two Arrays/README.md index 4556a09c5f61c..0e4ef58d4b13e 100644 --- a/solution/2700-2799/2771.Longest Non-decreasing Subarray From Two Arrays/README.md +++ b/solution/2700-2799/2771.Longest Non-decreasing Subarray From Two Arrays/README.md @@ -94,6 +94,8 @@ nums3 = [nums1[0], nums1[1]] => [1,1] +#### Python3 + ```python class Solution: def maxNonDecreasingLength(self, nums1: List[int], nums2: List[int]) -> int: @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxNonDecreasingLength(int[] nums1, int[] nums2) { @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func maxNonDecreasingLength(nums1 []int, nums2 []int) int { n := len(nums1) @@ -199,6 +207,8 @@ func maxNonDecreasingLength(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function maxNonDecreasingLength(nums1: number[], nums2: number[]): number { const n = nums1.length; diff --git a/solution/2700-2799/2771.Longest Non-decreasing Subarray From Two Arrays/README_EN.md b/solution/2700-2799/2771.Longest Non-decreasing Subarray From Two Arrays/README_EN.md index 931a57521528f..e3168894a350a 100644 --- a/solution/2700-2799/2771.Longest Non-decreasing Subarray From Two Arrays/README_EN.md +++ b/solution/2700-2799/2771.Longest Non-decreasing Subarray From Two Arrays/README_EN.md @@ -95,6 +95,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def maxNonDecreasingLength(self, nums1: List[int], nums2: List[int]) -> int: @@ -116,6 +118,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxNonDecreasingLength(int[] nums1, int[] nums2) { @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go func maxNonDecreasingLength(nums1 []int, nums2 []int) int { n := len(nums1) @@ -200,6 +208,8 @@ func maxNonDecreasingLength(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function maxNonDecreasingLength(nums1: number[], nums2: number[]): number { const n = nums1.length; diff --git a/solution/2700-2799/2772.Apply Operations to Make All Array Elements Equal to Zero/README.md b/solution/2700-2799/2772.Apply Operations to Make All Array Elements Equal to Zero/README.md index 653f1eb44fac1..1c82954a07264 100644 --- a/solution/2700-2799/2772.Apply Operations to Make All Array Elements Equal to Zero/README.md +++ b/solution/2700-2799/2772.Apply Operations to Make All Array Elements Equal to Zero/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def checkArray(self, nums: List[int], k: int) -> bool: @@ -104,6 +106,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean checkArray(int[] nums, int k) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func checkArray(nums []int, k int) bool { n := len(nums) @@ -172,6 +180,8 @@ func checkArray(nums []int, k int) bool { } ``` +#### TypeScript + ```ts function checkArray(nums: number[], k: number): boolean { const n = nums.length; diff --git a/solution/2700-2799/2772.Apply Operations to Make All Array Elements Equal to Zero/README_EN.md b/solution/2700-2799/2772.Apply Operations to Make All Array Elements Equal to Zero/README_EN.md index 8f375eb8e0795..f942ecc675caa 100644 --- a/solution/2700-2799/2772.Apply Operations to Make All Array Elements Equal to Zero/README_EN.md +++ b/solution/2700-2799/2772.Apply Operations to Make All Array Elements Equal to Zero/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python class Solution: def checkArray(self, nums: List[int], k: int) -> bool: @@ -104,6 +106,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean checkArray(int[] nums, int k) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func checkArray(nums []int, k int) bool { n := len(nums) @@ -172,6 +180,8 @@ func checkArray(nums []int, k int) bool { } ``` +#### TypeScript + ```ts function checkArray(nums: number[], k: number): boolean { const n = nums.length; diff --git a/solution/2700-2799/2773.Height of Special Binary Tree/README.md b/solution/2700-2799/2773.Height of Special Binary Tree/README.md index 119173f597802..1f7cbe9665db1 100644 --- a/solution/2700-2799/2773.Height of Special Binary Tree/README.md +++ b/solution/2700-2799/2773.Height of Special Binary Tree/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -111,6 +113,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -147,6 +151,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -178,6 +184,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -206,6 +214,8 @@ func heightOfTree(root *TreeNode) (ans int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/2700-2799/2773.Height of Special Binary Tree/README_EN.md b/solution/2700-2799/2773.Height of Special Binary Tree/README_EN.md index 0acdf23a108b2..71ad763774fa9 100644 --- a/solution/2700-2799/2773.Height of Special Binary Tree/README_EN.md +++ b/solution/2700-2799/2773.Height of Special Binary Tree/README_EN.md @@ -87,6 +87,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -109,6 +111,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -176,6 +182,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. @@ -204,6 +212,8 @@ func heightOfTree(root *TreeNode) (ans int) { } ``` +#### TypeScript + ```ts /** * Definition for a binary tree node. diff --git a/solution/2700-2799/2774.Array Upper Bound/README.md b/solution/2700-2799/2774.Array Upper Bound/README.md index 7ab049db5ebd8..e2fb9d4e50987 100644 --- a/solution/2700-2799/2774.Array Upper Bound/README.md +++ b/solution/2700-2799/2774.Array Upper Bound/README.md @@ -65,6 +65,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2700-2799/2774.Ar +#### TypeScript + ```ts declare global { interface Array { @@ -101,6 +103,8 @@ Array.prototype.upperBound = function (target: number) { +#### TypeScript + ```ts declare global { interface Array { diff --git a/solution/2700-2799/2774.Array Upper Bound/README_EN.md b/solution/2700-2799/2774.Array Upper Bound/README_EN.md index fe95dbd0623d3..9c91426f94466 100644 --- a/solution/2700-2799/2774.Array Upper Bound/README_EN.md +++ b/solution/2700-2799/2774.Array Upper Bound/README_EN.md @@ -62,6 +62,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2700-2799/2774.Ar +#### TypeScript + ```ts declare global { interface Array { @@ -98,6 +100,8 @@ Array.prototype.upperBound = function (target: number) { +#### TypeScript + ```ts declare global { interface Array { diff --git a/solution/2700-2799/2775.Undefined to Null/README.md b/solution/2700-2799/2775.Undefined to Null/README.md index d72347f02b84c..281b26483b813 100644 --- a/solution/2700-2799/2775.Undefined to Null/README.md +++ b/solution/2700-2799/2775.Undefined to Null/README.md @@ -55,6 +55,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2700-2799/2775.Un +#### TypeScript + ```ts function undefinedToNull(obj: Record): Record { for (const key in obj) { diff --git a/solution/2700-2799/2775.Undefined to Null/README_EN.md b/solution/2700-2799/2775.Undefined to Null/README_EN.md index 57107ba6b842b..38ad410d1378e 100644 --- a/solution/2700-2799/2775.Undefined to Null/README_EN.md +++ b/solution/2700-2799/2775.Undefined to Null/README_EN.md @@ -53,6 +53,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2700-2799/2775.Un +#### TypeScript + ```ts function undefinedToNull(obj: Record): Record { for (const key in obj) { diff --git a/solution/2700-2799/2776.Convert Callback Based Function to Promise Based Function/README.md b/solution/2700-2799/2776.Convert Callback Based Function to Promise Based Function/README.md index 0d0694d643cd5..9429400bed990 100644 --- a/solution/2700-2799/2776.Convert Callback Based Function to Promise Based Function/README.md +++ b/solution/2700-2799/2776.Convert Callback Based Function to Promise Based Function/README.md @@ -98,6 +98,8 @@ fn 以回调函数作为第一个参数和 args 作为其余参数进行调用 +#### TypeScript + ```ts type CallbackFn = (next: (data: number, error: string) => void, ...args: number[]) => void; type Promisified = (...args: number[]) => Promise; diff --git a/solution/2700-2799/2776.Convert Callback Based Function to Promise Based Function/README_EN.md b/solution/2700-2799/2776.Convert Callback Based Function to Promise Based Function/README_EN.md index 27c3c1ef98b29..e0bd3f6277f1e 100644 --- a/solution/2700-2799/2776.Convert Callback Based Function to Promise Based Function/README_EN.md +++ b/solution/2700-2799/2776.Convert Callback Based Function to Promise Based Function/README_EN.md @@ -96,6 +96,8 @@ fn is called with a callback as the first argument and args as the rest. As the +#### TypeScript + ```ts type CallbackFn = (next: (data: number, error: string) => void, ...args: number[]) => void; type Promisified = (...args: number[]) => Promise; diff --git a/solution/2700-2799/2777.Date Range Generator/README.md b/solution/2700-2799/2777.Date Range Generator/README.md index 48117f2b71ac4..cb1e1a5414173 100644 --- a/solution/2700-2799/2777.Date Range Generator/README.md +++ b/solution/2700-2799/2777.Date Range Generator/README.md @@ -77,6 +77,8 @@ g.next().value // '2023-04-10' +#### TypeScript + ```ts function* dateRangeGenerator(start: string, end: string, step: number): Generator { const startDate = new Date(start); diff --git a/solution/2700-2799/2777.Date Range Generator/README_EN.md b/solution/2700-2799/2777.Date Range Generator/README_EN.md index d9797c08f76e2..4d3f7aa7401f0 100644 --- a/solution/2700-2799/2777.Date Range Generator/README_EN.md +++ b/solution/2700-2799/2777.Date Range Generator/README_EN.md @@ -75,6 +75,8 @@ g.next().value // '2023-04-10' +#### TypeScript + ```ts function* dateRangeGenerator(start: string, end: string, step: number): Generator { const startDate = new Date(start); diff --git a/solution/2700-2799/2778.Sum of Squares of Special Elements/README.md b/solution/2700-2799/2778.Sum of Squares of Special Elements/README.md index 8342416fc508c..55bdb3b2401cb 100644 --- a/solution/2700-2799/2778.Sum of Squares of Special Elements/README.md +++ b/solution/2700-2799/2778.Sum of Squares of Special Elements/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def sumOfSquares(self, nums: List[int]) -> int: @@ -74,6 +76,8 @@ class Solution: return sum(x * x for i, x in enumerate(nums, 1) if n % i == 0) ``` +#### Java + ```java class Solution { public int sumOfSquares(int[] nums) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func sumOfSquares(nums []int) (ans int) { n := len(nums) @@ -117,6 +125,8 @@ func sumOfSquares(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function sumOfSquares(nums: number[]): number { const n = nums.length; diff --git a/solution/2700-2799/2778.Sum of Squares of Special Elements/README_EN.md b/solution/2700-2799/2778.Sum of Squares of Special Elements/README_EN.md index 04d81257ebb76..99d6053eb3082 100644 --- a/solution/2700-2799/2778.Sum of Squares of Special Elements/README_EN.md +++ b/solution/2700-2799/2778.Sum of Squares of Special Elements/README_EN.md @@ -62,6 +62,8 @@ Hence, the sum of the squares of all special elements of nums is nums[1] * nums[ +#### Python3 + ```python class Solution: def sumOfSquares(self, nums: List[int]) -> int: @@ -69,6 +71,8 @@ class Solution: return sum(x * x for i, x in enumerate(nums, 1) if n % i == 0) ``` +#### Java + ```java class Solution { public int sumOfSquares(int[] nums) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -100,6 +106,8 @@ public: }; ``` +#### Go + ```go func sumOfSquares(nums []int) (ans int) { n := len(nums) @@ -112,6 +120,8 @@ func sumOfSquares(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function sumOfSquares(nums: number[]): number { const n = nums.length; diff --git a/solution/2700-2799/2779.Maximum Beauty of an Array After Applying Operation/README.md b/solution/2700-2799/2779.Maximum Beauty of an Array After Applying Operation/README.md index fb81c784901fb..a80b6b04e3a96 100644 --- a/solution/2700-2799/2779.Maximum Beauty of an Array After Applying Operation/README.md +++ b/solution/2700-2799/2779.Maximum Beauty of an Array After Applying Operation/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def maximumBeauty(self, nums: List[int], k: int) -> int: @@ -103,6 +105,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumBeauty(int[] nums, int k) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func maximumBeauty(nums []int, k int) (ans int) { m := slices.Max(nums) @@ -162,6 +170,8 @@ func maximumBeauty(nums []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function maximumBeauty(nums: number[], k: number): number { const m = Math.max(...nums) + k * 2 + 2; diff --git a/solution/2700-2799/2779.Maximum Beauty of an Array After Applying Operation/README_EN.md b/solution/2700-2799/2779.Maximum Beauty of an Array After Applying Operation/README_EN.md index 954e4a85de33f..c7fa96f1804de 100644 --- a/solution/2700-2799/2779.Maximum Beauty of an Array After Applying Operation/README_EN.md +++ b/solution/2700-2799/2779.Maximum Beauty of an Array After Applying Operation/README_EN.md @@ -78,6 +78,8 @@ The beauty of the array nums is 4 (whole array). +#### Python3 + ```python class Solution: def maximumBeauty(self, nums: List[int], k: int) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumBeauty(int[] nums, int k) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func maximumBeauty(nums []int, k int) (ans int) { m := slices.Max(nums) @@ -152,6 +160,8 @@ func maximumBeauty(nums []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function maximumBeauty(nums: number[], k: number): number { const m = Math.max(...nums) + k * 2 + 2; diff --git a/solution/2700-2799/2780.Minimum Index of a Valid Split/README.md b/solution/2700-2799/2780.Minimum Index of a Valid Split/README.md index 7a3db7ed17eb1..c137291a94a7f 100644 --- a/solution/2700-2799/2780.Minimum Index of a Valid Split/README.md +++ b/solution/2700-2799/2780.Minimum Index of a Valid Split/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def minimumIndex(self, nums: List[int]) -> int: @@ -103,6 +105,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minimumIndex(List nums) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func minimumIndex(nums []int) int { x, cnt := 0, 0 @@ -180,6 +188,8 @@ func minimumIndex(nums []int) int { } ``` +#### TypeScript + ```ts function minimumIndex(nums: number[]): number { let [x, cnt] = [0, 0]; diff --git a/solution/2700-2799/2780.Minimum Index of a Valid Split/README_EN.md b/solution/2700-2799/2780.Minimum Index of a Valid Split/README_EN.md index 2a992051b4c50..1277efbf7eeec 100644 --- a/solution/2700-2799/2780.Minimum Index of a Valid Split/README_EN.md +++ b/solution/2700-2799/2780.Minimum Index of a Valid Split/README_EN.md @@ -85,6 +85,8 @@ It can be shown that index 4 is the minimum index of a valid split. +#### Python3 + ```python class Solution: def minimumIndex(self, nums: List[int]) -> int: @@ -98,6 +100,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minimumIndex(List nums) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func minimumIndex(nums []int) int { x, cnt := 0, 0 @@ -175,6 +183,8 @@ func minimumIndex(nums []int) int { } ``` +#### TypeScript + ```ts function minimumIndex(nums: number[]): number { let [x, cnt] = [0, 0]; diff --git a/solution/2700-2799/2781.Length of the Longest Valid Substring/README.md b/solution/2700-2799/2781.Length of the Longest Valid Substring/README.md index 7e1967ea23b13..884836a847c90 100644 --- a/solution/2700-2799/2781.Length of the Longest Valid Substring/README.md +++ b/solution/2700-2799/2781.Length of the Longest Valid Substring/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def longestValidSubstring(self, word: str, forbidden: List[str]) -> int: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestValidSubstring(String word, List forbidden) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func longestValidSubstring(word string, forbidden []string) (ans int) { s := map[string]bool{} @@ -149,6 +157,8 @@ func longestValidSubstring(word string, forbidden []string) (ans int) { } ``` +#### TypeScript + ```ts function longestValidSubstring(word: string, forbidden: string[]): number { const s: Set = new Set(forbidden); diff --git a/solution/2700-2799/2781.Length of the Longest Valid Substring/README_EN.md b/solution/2700-2799/2781.Length of the Longest Valid Substring/README_EN.md index 30b792ac5ae7b..0989190206514 100644 --- a/solution/2700-2799/2781.Length of the Longest Valid Substring/README_EN.md +++ b/solution/2700-2799/2781.Length of the Longest Valid Substring/README_EN.md @@ -68,6 +68,8 @@ It can be shown that all other substrings contain either "de", "l +#### Python3 + ```python class Solution: def longestValidSubstring(self, word: str, forbidden: List[str]) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestValidSubstring(String word, List forbidden) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func longestValidSubstring(word string, forbidden []string) (ans int) { s := map[string]bool{} @@ -141,6 +149,8 @@ func longestValidSubstring(word string, forbidden []string) (ans int) { } ``` +#### TypeScript + ```ts function longestValidSubstring(word: string, forbidden: string[]): number { const s: Set = new Set(forbidden); diff --git a/solution/2700-2799/2782.Number of Unique Categories/README.md b/solution/2700-2799/2782.Number of Unique Categories/README.md index ce060fd8bce62..e30cb778b3813 100644 --- a/solution/2700-2799/2782.Number of Unique Categories/README.md +++ b/solution/2700-2799/2782.Number of Unique Categories/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python # Definition for a category handler. # class CategoryHandler: @@ -100,6 +102,8 @@ class Solution: return sum(i == x for i, x in enumerate(p)) ``` +#### Java + ```java /** * Definition for a category handler. @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a category handler. @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a category handler. @@ -212,6 +220,8 @@ func numberOfCategories(n int, categoryHandler CategoryHandler) (ans int) { } ``` +#### TypeScript + ```ts /** * Definition for a category handler. diff --git a/solution/2700-2799/2782.Number of Unique Categories/README_EN.md b/solution/2700-2799/2782.Number of Unique Categories/README_EN.md index a4243b431e4e2..c9f089f4a658a 100644 --- a/solution/2700-2799/2782.Number of Unique Categories/README_EN.md +++ b/solution/2700-2799/2782.Number of Unique Categories/README_EN.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python # Definition for a category handler. # class CategoryHandler: @@ -94,6 +96,8 @@ class Solution: return sum(i == x for i, x in enumerate(p)) ``` +#### Java + ```java /** * Definition for a category handler. @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a category handler. @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a category handler. @@ -206,6 +214,8 @@ func numberOfCategories(n int, categoryHandler CategoryHandler) (ans int) { } ``` +#### TypeScript + ```ts /** * Definition for a category handler. diff --git a/solution/2700-2799/2783.Flight Occupancy and Waitlist Analysis/README.md b/solution/2700-2799/2783.Flight Occupancy and Waitlist Analysis/README.md index a7112e22ccc29..30cf9ebc00b0a 100644 --- a/solution/2700-2799/2783.Flight Occupancy and Waitlist Analysis/README.md +++ b/solution/2700-2799/2783.Flight Occupancy and Waitlist Analysis/README.md @@ -103,6 +103,8 @@ Passengers table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2700-2799/2783.Flight Occupancy and Waitlist Analysis/README_EN.md b/solution/2700-2799/2783.Flight Occupancy and Waitlist Analysis/README_EN.md index 4a8a5c64781c5..975115721e530 100644 --- a/solution/2700-2799/2783.Flight Occupancy and Waitlist Analysis/README_EN.md +++ b/solution/2700-2799/2783.Flight Occupancy and Waitlist Analysis/README_EN.md @@ -99,6 +99,8 @@ Passengers table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2700-2799/2784.Check if Array is Good/README.md b/solution/2700-2799/2784.Check if Array is Good/README.md index 45c7e5e497434..9f905b8e14fc4 100644 --- a/solution/2700-2799/2784.Check if Array is Good/README.md +++ b/solution/2700-2799/2784.Check if Array is Good/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def isGood(self, nums: List[int]) -> bool: @@ -92,6 +94,8 @@ class Solution: return cnt[n] == 2 and all(cnt[i] for i in range(1, n)) ``` +#### Java + ```java class Solution { public boolean isGood(int[] nums) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func isGood(nums []int) bool { n := len(nums) - 1 @@ -154,6 +162,8 @@ func isGood(nums []int) bool { } ``` +#### TypeScript + ```ts function isGood(nums: number[]): boolean { const n = nums.length - 1; @@ -173,6 +183,8 @@ function isGood(nums: number[]): boolean { } ``` +#### C# + ```cs public class Solution { public bool IsGood(int[] nums) { diff --git a/solution/2700-2799/2784.Check if Array is Good/README_EN.md b/solution/2700-2799/2784.Check if Array is Good/README_EN.md index 4fac2468bfc29..565c96e533446 100644 --- a/solution/2700-2799/2784.Check if Array is Good/README_EN.md +++ b/solution/2700-2799/2784.Check if Array is Good/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def isGood(self, nums: List[int]) -> bool: @@ -94,6 +96,8 @@ class Solution: return cnt[n] == 2 and all(cnt[i] for i in range(1, n)) ``` +#### Java + ```java class Solution { public boolean isGood(int[] nums) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func isGood(nums []int) bool { n := len(nums) - 1 @@ -156,6 +164,8 @@ func isGood(nums []int) bool { } ``` +#### TypeScript + ```ts function isGood(nums: number[]): boolean { const n = nums.length - 1; @@ -175,6 +185,8 @@ function isGood(nums: number[]): boolean { } ``` +#### C# + ```cs public class Solution { public bool IsGood(int[] nums) { diff --git a/solution/2700-2799/2785.Sort Vowels in a String/README.md b/solution/2700-2799/2785.Sort Vowels in a String/README.md index da3ac1b2d62fe..d1e58e9d7f245 100644 --- a/solution/2700-2799/2785.Sort Vowels in a String/README.md +++ b/solution/2700-2799/2785.Sort Vowels in a String/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def sortVowels(self, s: str) -> str: @@ -87,6 +89,8 @@ class Solution: return "".join(cs) ``` +#### Java + ```java class Solution { public String sortVowels(String s) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func sortVowels(s string) string { cs := []byte(s) @@ -156,6 +164,8 @@ func sortVowels(s string) string { } ``` +#### TypeScript + ```ts function sortVowels(s: string): string { const vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']; @@ -172,6 +182,8 @@ function sortVowels(s: string): string { } ``` +#### C# + ```cs public class Solution { public string SortVowels(string s) { diff --git a/solution/2700-2799/2785.Sort Vowels in a String/README_EN.md b/solution/2700-2799/2785.Sort Vowels in a String/README_EN.md index 68b4db26a5100..50c2e9d07b200 100644 --- a/solution/2700-2799/2785.Sort Vowels in a String/README_EN.md +++ b/solution/2700-2799/2785.Sort Vowels in a String/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def sortVowels(self, s: str) -> str: @@ -85,6 +87,8 @@ class Solution: return "".join(cs) ``` +#### Java + ```java class Solution { public String sortVowels(String s) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func sortVowels(s string) string { cs := []byte(s) @@ -154,6 +162,8 @@ func sortVowels(s string) string { } ``` +#### TypeScript + ```ts function sortVowels(s: string): string { const vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']; @@ -170,6 +180,8 @@ function sortVowels(s: string): string { } ``` +#### C# + ```cs public class Solution { public string SortVowels(string s) { diff --git a/solution/2700-2799/2786.Visit Array Positions to Maximize Score/README.md b/solution/2700-2799/2786.Visit Array Positions to Maximize Score/README.md index f7f3f61a91d18..746d86d842f7c 100644 --- a/solution/2700-2799/2786.Visit Array Positions to Maximize Score/README.md +++ b/solution/2700-2799/2786.Visit Array Positions to Maximize Score/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def maxScore(self, nums: List[int], x: int) -> int: @@ -81,6 +83,8 @@ class Solution: return max(f) ``` +#### Java + ```java class Solution { public long maxScore(int[] nums, int x) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func maxScore(nums []int, x int) int64 { const inf int = 1 << 40 @@ -123,6 +131,8 @@ func maxScore(nums []int, x int) int64 { } ``` +#### TypeScript + ```ts function maxScore(nums: number[], x: number): number { const inf = 1 << 30; diff --git a/solution/2700-2799/2786.Visit Array Positions to Maximize Score/README_EN.md b/solution/2700-2799/2786.Visit Array Positions to Maximize Score/README_EN.md index 35b2697b41be8..b38632b020df1 100644 --- a/solution/2700-2799/2786.Visit Array Positions to Maximize Score/README_EN.md +++ b/solution/2700-2799/2786.Visit Array Positions to Maximize Score/README_EN.md @@ -71,6 +71,8 @@ The total score is: 2 + 4 + 6 + 8 = 20. +#### Python3 + ```python class Solution: def maxScore(self, nums: List[int], x: int) -> int: @@ -81,6 +83,8 @@ class Solution: return max(f) ``` +#### Java + ```java class Solution { public long maxScore(int[] nums, int x) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func maxScore(nums []int, x int) int64 { const inf int = 1 << 40 @@ -123,6 +131,8 @@ func maxScore(nums []int, x int) int64 { } ``` +#### TypeScript + ```ts function maxScore(nums: number[], x: number): number { const inf = 1 << 30; diff --git a/solution/2700-2799/2787.Ways to Express an Integer as Sum of Powers/README.md b/solution/2700-2799/2787.Ways to Express an Integer as Sum of Powers/README.md index 5663f91bebbf5..14351bbdf47ba 100644 --- a/solution/2700-2799/2787.Ways to Express an Integer as Sum of Powers/README.md +++ b/solution/2700-2799/2787.Ways to Express an Integer as Sum of Powers/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfWays(self, n: int, x: int) -> int: @@ -79,6 +81,8 @@ class Solution: return f[n][n] ``` +#### Java + ```java class Solution { public int numberOfWays(int n, int x) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func numberOfWays(n int, x int) int { const mod int = 1e9 + 7 @@ -142,6 +150,8 @@ func numberOfWays(n int, x int) int { } ``` +#### TypeScript + ```ts function numberOfWays(n: number, x: number): number { const mod = 10 ** 9 + 7; diff --git a/solution/2700-2799/2787.Ways to Express an Integer as Sum of Powers/README_EN.md b/solution/2700-2799/2787.Ways to Express an Integer as Sum of Powers/README_EN.md index 1ea05150f2ec6..7b305c05503a0 100644 --- a/solution/2700-2799/2787.Ways to Express an Integer as Sum of Powers/README_EN.md +++ b/solution/2700-2799/2787.Ways to Express an Integer as Sum of Powers/README_EN.md @@ -64,6 +64,8 @@ It can be shown that it is the only way to express 10 as the sum of the 2nd +#### Python3 + ```python class Solution: def numberOfWays(self, n: int, x: int) -> int: @@ -79,6 +81,8 @@ class Solution: return f[n][n] ``` +#### Java + ```java class Solution { public int numberOfWays(int n, int x) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func numberOfWays(n int, x int) int { const mod int = 1e9 + 7 @@ -142,6 +150,8 @@ func numberOfWays(n int, x int) int { } ``` +#### TypeScript + ```ts function numberOfWays(n: number, x: number): number { const mod = 10 ** 9 + 7; diff --git a/solution/2700-2799/2788.Split Strings by Separator/README.md b/solution/2700-2799/2788.Split Strings by Separator/README.md index 6df7a34cef222..1c4343e1e263a 100644 --- a/solution/2700-2799/2788.Split Strings by Separator/README.md +++ b/solution/2700-2799/2788.Split Strings by Separator/README.md @@ -91,12 +91,16 @@ tags: +#### Python3 + ```python class Solution: def splitWordsBySeparator(self, words: List[str], separator: str) -> List[str]: return [s for w in words for s in w.split(separator) if s] ``` +#### Java + ```java import java.util.regex.Pattern; @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func splitWordsBySeparator(words []string, separator byte) (ans []string) { for _, w := range words { @@ -147,6 +155,8 @@ func splitWordsBySeparator(words []string, separator byte) (ans []string) { } ``` +#### TypeScript + ```ts function splitWordsBySeparator(words: string[], separator: string): string[] { return words.flatMap(w => w.split(separator).filter(s => s.length > 0)); diff --git a/solution/2700-2799/2788.Split Strings by Separator/README_EN.md b/solution/2700-2799/2788.Split Strings by Separator/README_EN.md index 1a7450bf389a2..39c4538964db5 100644 --- a/solution/2700-2799/2788.Split Strings by Separator/README_EN.md +++ b/solution/2700-2799/2788.Split Strings by Separator/README_EN.md @@ -89,12 +89,16 @@ The time complexity is $O(n \times m)$, and the space complexity is $O(m)$, wher +#### Python3 + ```python class Solution: def splitWordsBySeparator(self, words: List[str], separator: str) -> List[str]: return [s for w in words for s in w.split(separator) if s] ``` +#### Java + ```java import java.util.regex.Pattern; @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func splitWordsBySeparator(words []string, separator byte) (ans []string) { for _, w := range words { @@ -145,6 +153,8 @@ func splitWordsBySeparator(words []string, separator byte) (ans []string) { } ``` +#### TypeScript + ```ts function splitWordsBySeparator(words: string[], separator: string): string[] { return words.flatMap(w => w.split(separator).filter(s => s.length > 0)); diff --git a/solution/2700-2799/2789.Largest Element in an Array after Merge Operations/README.md b/solution/2700-2799/2789.Largest Element in an Array after Merge Operations/README.md index 6b568a1427f8c..30ab0b169102a 100644 --- a/solution/2700-2799/2789.Largest Element in an Array after Merge Operations/README.md +++ b/solution/2700-2799/2789.Largest Element in an Array after Merge Operations/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def maxArrayValue(self, nums: List[int]) -> int: @@ -88,6 +90,8 @@ class Solution: return max(nums) ``` +#### Java + ```java class Solution { public long maxArrayValue(int[] nums) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func maxArrayValue(nums []int) int64 { n := len(nums) @@ -141,6 +149,8 @@ func maxArrayValue(nums []int) int64 { } ``` +#### TypeScript + ```ts function maxArrayValue(nums: number[]): number { for (let i = nums.length - 2; i >= 0; --i) { diff --git a/solution/2700-2799/2789.Largest Element in an Array after Merge Operations/README_EN.md b/solution/2700-2799/2789.Largest Element in an Array after Merge Operations/README_EN.md index 7e1835c547d93..2fb99f28345e4 100644 --- a/solution/2700-2799/2789.Largest Element in an Array after Merge Operations/README_EN.md +++ b/solution/2700-2799/2789.Largest Element in an Array after Merge Operations/README_EN.md @@ -79,6 +79,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def maxArrayValue(self, nums: List[int]) -> int: @@ -88,6 +90,8 @@ class Solution: return max(nums) ``` +#### Java + ```java class Solution { public long maxArrayValue(int[] nums) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func maxArrayValue(nums []int) int64 { n := len(nums) @@ -141,6 +149,8 @@ func maxArrayValue(nums []int) int64 { } ``` +#### TypeScript + ```ts function maxArrayValue(nums: number[]): number { for (let i = nums.length - 2; i >= 0; --i) { diff --git a/solution/2700-2799/2790.Maximum Number of Groups With Increasing Length/README.md b/solution/2700-2799/2790.Maximum Number of Groups With Increasing Length/README.md index 432e4512c9dbc..e18624b393ede 100644 --- a/solution/2700-2799/2790.Maximum Number of Groups With Increasing Length/README.md +++ b/solution/2700-2799/2790.Maximum Number of Groups With Increasing Length/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def maxIncreasingGroups(self, usageLimits: List[int]) -> int: @@ -106,6 +108,8 @@ class Solution: return k ``` +#### Java + ```java class Solution { public int maxIncreasingGroups(List usageLimits) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func maxIncreasingGroups(usageLimits []int) int { sort.Ints(usageLimits) @@ -158,6 +166,8 @@ func maxIncreasingGroups(usageLimits []int) int { } ``` +#### TypeScript + ```ts function maxIncreasingGroups(usageLimits: number[]): number { usageLimits.sort((a, b) => a - b); @@ -184,6 +194,8 @@ function maxIncreasingGroups(usageLimits: number[]): number { +#### Python3 + ```python class Solution: def maxIncreasingGroups(self, usageLimits: List[int]) -> int: diff --git a/solution/2700-2799/2790.Maximum Number of Groups With Increasing Length/README_EN.md b/solution/2700-2799/2790.Maximum Number of Groups With Increasing Length/README_EN.md index 13acaebc7b1d7..c7ac954fbdab4 100644 --- a/solution/2700-2799/2790.Maximum Number of Groups With Increasing Length/README_EN.md +++ b/solution/2700-2799/2790.Maximum Number of Groups With Increasing Length/README_EN.md @@ -90,6 +90,8 @@ So, the output is 1. +#### Python3 + ```python class Solution: def maxIncreasingGroups(self, usageLimits: List[int]) -> int: @@ -104,6 +106,8 @@ class Solution: return k ``` +#### Java + ```java class Solution { public int maxIncreasingGroups(List usageLimits) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func maxIncreasingGroups(usageLimits []int) int { sort.Ints(usageLimits) @@ -156,6 +164,8 @@ func maxIncreasingGroups(usageLimits []int) int { } ``` +#### TypeScript + ```ts function maxIncreasingGroups(usageLimits: number[]): number { usageLimits.sort((a, b) => a - b); @@ -182,6 +192,8 @@ function maxIncreasingGroups(usageLimits: number[]): number { +#### Python3 + ```python class Solution: def maxIncreasingGroups(self, usageLimits: List[int]) -> int: diff --git a/solution/2700-2799/2791.Count Paths That Can Form a Palindrome in a Tree/README.md b/solution/2700-2799/2791.Count Paths That Can Form a Palindrome in a Tree/README.md index 56ff94d466081..746a8197d6400 100644 --- a/solution/2700-2799/2791.Count Paths That Can Form a Palindrome in a Tree/README.md +++ b/solution/2700-2799/2791.Count Paths That Can Form a Palindrome in a Tree/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def countPalindromePaths(self, parent: List[int], s: str) -> int: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func countPalindromePaths(parent []int, s string) (ans int64) { type pair struct{ i, v int } @@ -192,6 +200,8 @@ func countPalindromePaths(parent []int, s string) (ans int64) { } ``` +#### TypeScript + ```ts function countPalindromePaths(parent: number[], s: string): number { const n = parent.length; diff --git a/solution/2700-2799/2791.Count Paths That Can Form a Palindrome in a Tree/README_EN.md b/solution/2700-2799/2791.Count Paths That Can Form a Palindrome in a Tree/README_EN.md index 83e40d40914c4..a2270e5ff1807 100644 --- a/solution/2700-2799/2791.Count Paths That Can Form a Palindrome in a Tree/README_EN.md +++ b/solution/2700-2799/2791.Count Paths That Can Form a Palindrome in a Tree/README_EN.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def countPalindromePaths(self, parent: List[int], s: str) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func countPalindromePaths(parent []int, s string) (ans int64) { type pair struct{ i, v int } @@ -190,6 +198,8 @@ func countPalindromePaths(parent []int, s string) (ans int64) { } ``` +#### TypeScript + ```ts function countPalindromePaths(parent: number[], s: string): number { const n = parent.length; diff --git a/solution/2700-2799/2792.Count Nodes That Are Great Enough/README.md b/solution/2700-2799/2792.Count Nodes That Are Great Enough/README.md index 48fd62f4e1a7d..6f728d60c89c7 100644 --- a/solution/2700-2799/2792.Count Nodes That Are Great Enough/README.md +++ b/solution/2700-2799/2792.Count Nodes That Are Great Enough/README.md @@ -99,6 +99,8 @@ tags: +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -130,6 +132,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -180,6 +184,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -224,6 +230,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/2700-2799/2792.Count Nodes That Are Great Enough/README_EN.md b/solution/2700-2799/2792.Count Nodes That Are Great Enough/README_EN.md index 27284b4d23320..4b2bda8404ff9 100644 --- a/solution/2700-2799/2792.Count Nodes That Are Great Enough/README_EN.md +++ b/solution/2700-2799/2792.Count Nodes That Are Great Enough/README_EN.md @@ -90,6 +90,8 @@ See the picture below for a better understanding. +#### Python3 + ```python # Definition for a binary tree node. # class TreeNode: @@ -121,6 +123,8 @@ class Solution: return ans ``` +#### Java + ```java /** * Definition for a binary tree node. @@ -171,6 +175,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for a binary tree node. @@ -215,6 +221,8 @@ public: }; ``` +#### Go + ```go /** * Definition for a binary tree node. diff --git a/solution/2700-2799/2793.Status of Flight Tickets/README.md b/solution/2700-2799/2793.Status of Flight Tickets/README.md index 54c8c3505f6e9..0a79d90731ac7 100644 --- a/solution/2700-2799/2793.Status of Flight Tickets/README.md +++ b/solution/2700-2799/2793.Status of Flight Tickets/README.md @@ -105,6 +105,8 @@ Passengers 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2700-2799/2793.Status of Flight Tickets/README_EN.md b/solution/2700-2799/2793.Status of Flight Tickets/README_EN.md index fcc133fba7c0f..635a8abfb75b7 100644 --- a/solution/2700-2799/2793.Status of Flight Tickets/README_EN.md +++ b/solution/2700-2799/2793.Status of Flight Tickets/README_EN.md @@ -103,6 +103,8 @@ Passengers table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2700-2799/2794.Create Object from Two Arrays/README.md b/solution/2700-2799/2794.Create Object from Two Arrays/README.md index 617560e54d968..dfa181524b591 100644 --- a/solution/2700-2799/2794.Create Object from Two Arrays/README.md +++ b/solution/2700-2799/2794.Create Object from Two Arrays/README.md @@ -66,6 +66,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2700-2799/2794.Cr +#### TypeScript + ```ts function createObject(keysArr: any[], valuesArr: any[]): Record { const ans: Record = {}; @@ -79,6 +81,8 @@ function createObject(keysArr: any[], valuesArr: any[]): Record { } ``` +#### JavaScript + ```js /** * @param {Array} keysArr diff --git a/solution/2700-2799/2794.Create Object from Two Arrays/README_EN.md b/solution/2700-2799/2794.Create Object from Two Arrays/README_EN.md index a07d5c01e1004..b0796a953f43e 100644 --- a/solution/2700-2799/2794.Create Object from Two Arrays/README_EN.md +++ b/solution/2700-2799/2794.Create Object from Two Arrays/README_EN.md @@ -64,6 +64,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2700-2799/2794.Cr +#### TypeScript + ```ts function createObject(keysArr: any[], valuesArr: any[]): Record { const ans: Record = {}; @@ -77,6 +79,8 @@ function createObject(keysArr: any[], valuesArr: any[]): Record { } ``` +#### JavaScript + ```js /** * @param {Array} keysArr diff --git a/solution/2700-2799/2795.Parallel Execution of Promises for Individual Results Retrieval/README.md b/solution/2700-2799/2795.Parallel Execution of Promises for Individual Results Retrieval/README.md index acf6abe04490c..d4cabdc465336 100644 --- a/solution/2700-2799/2795.Parallel Execution of Promises for Individual Results Retrieval/README.md +++ b/solution/2700-2799/2795.Parallel Execution of Promises for Individual Results Retrieval/README.md @@ -103,6 +103,8 @@ promise.then(res => { +#### TypeScript + ```ts type FulfilledObj = { status: 'fulfilled'; @@ -147,6 +149,8 @@ function promiseAllSettled(functions: Function[]): Promise { */ ``` +#### JavaScript + ```js /** * @param {Array} functions diff --git a/solution/2700-2799/2795.Parallel Execution of Promises for Individual Results Retrieval/README_EN.md b/solution/2700-2799/2795.Parallel Execution of Promises for Individual Results Retrieval/README_EN.md index 515979c136e51..920ec1b149b76 100644 --- a/solution/2700-2799/2795.Parallel Execution of Promises for Individual Results Retrieval/README_EN.md +++ b/solution/2700-2799/2795.Parallel Execution of Promises for Individual Results Retrieval/README_EN.md @@ -101,6 +101,8 @@ The returned promise resolves within 100 milliseconds. Since promise from the ar +#### TypeScript + ```ts type FulfilledObj = { status: 'fulfilled'; @@ -145,6 +147,8 @@ function promiseAllSettled(functions: Function[]): Promise { */ ``` +#### JavaScript + ```js /** * @param {Array} functions diff --git a/solution/2700-2799/2796.Repeat String/README.md b/solution/2700-2799/2796.Repeat String/README.md index 79ec6add7fd4f..fc5d4927ebe53 100644 --- a/solution/2700-2799/2796.Repeat String/README.md +++ b/solution/2700-2799/2796.Repeat String/README.md @@ -67,6 +67,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2700-2799/2796.Re +#### TypeScript + ```ts declare global { interface String { @@ -79,6 +81,8 @@ String.prototype.replicate = function (times: number) { }; ``` +#### JavaScript + ```js String.prototype.replicate = function (times) { return Array(times).fill(this).join(''); diff --git a/solution/2700-2799/2796.Repeat String/README_EN.md b/solution/2700-2799/2796.Repeat String/README_EN.md index 8061feddaa169..916af04305451 100644 --- a/solution/2700-2799/2796.Repeat String/README_EN.md +++ b/solution/2700-2799/2796.Repeat String/README_EN.md @@ -64,6 +64,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2700-2799/2796.Re +#### TypeScript + ```ts declare global { interface String { @@ -76,6 +78,8 @@ String.prototype.replicate = function (times: number) { }; ``` +#### JavaScript + ```js String.prototype.replicate = function (times) { return Array(times).fill(this).join(''); diff --git a/solution/2700-2799/2797.Partial Function with Placeholders/README.md b/solution/2700-2799/2797.Partial Function with Placeholders/README.md index 6d25adeef0a7a..40e9a3cf7d64a 100644 --- a/solution/2700-2799/2797.Partial Function with Placeholders/README.md +++ b/solution/2700-2799/2797.Partial Function with Placeholders/README.md @@ -83,6 +83,8 @@ console.log(result) // -10 +#### TypeScript + ```ts function partial(fn: Function, args: any[]): Function { return function (...restArgs) { @@ -100,6 +102,8 @@ function partial(fn: Function, args: any[]): Function { } ``` +#### JavaScript + ```js /** * @param {Function} fn diff --git a/solution/2700-2799/2797.Partial Function with Placeholders/README_EN.md b/solution/2700-2799/2797.Partial Function with Placeholders/README_EN.md index 6fb5edcc18611..25453033c44ca 100644 --- a/solution/2700-2799/2797.Partial Function with Placeholders/README_EN.md +++ b/solution/2700-2799/2797.Partial Function with Placeholders/README_EN.md @@ -81,6 +81,8 @@ Placeholder "_" is replaced with 5 and 20 is added at the end of args. +#### TypeScript + ```ts function partial(fn: Function, args: any[]): Function { return function (...restArgs) { @@ -98,6 +100,8 @@ function partial(fn: Function, args: any[]): Function { } ``` +#### JavaScript + ```js /** * @param {Function} fn diff --git a/solution/2700-2799/2798.Number of Employees Who Met the Target/README.md b/solution/2700-2799/2798.Number of Employees Who Met the Target/README.md index 1ef2933645e0a..a3fc7480ac831 100644 --- a/solution/2700-2799/2798.Number of Employees Who Met the Target/README.md +++ b/solution/2700-2799/2798.Number of Employees Who Met the Target/README.md @@ -74,12 +74,16 @@ tags: +#### Python3 + ```python class Solution: def numberOfEmployeesWhoMetTarget(self, hours: List[int], target: int) -> int: return sum(x >= target for x in hours) ``` +#### Java + ```java class Solution { public int numberOfEmployeesWhoMetTarget(int[] hours, int target) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -103,6 +109,8 @@ public: }; ``` +#### Go + ```go func numberOfEmployeesWhoMetTarget(hours []int, target int) (ans int) { for _, x := range hours { @@ -114,12 +122,16 @@ func numberOfEmployeesWhoMetTarget(hours []int, target int) (ans int) { } ``` +#### TypeScript + ```ts function numberOfEmployeesWhoMetTarget(hours: number[], target: number): number { return hours.filter(x => x >= target).length; } ``` +#### Rust + ```rust impl Solution { pub fn number_of_employees_who_met_target(hours: Vec, target: i32) -> i32 { diff --git a/solution/2700-2799/2798.Number of Employees Who Met the Target/README_EN.md b/solution/2700-2799/2798.Number of Employees Who Met the Target/README_EN.md index 1528d8c12b62f..7f2296dcbc31f 100644 --- a/solution/2700-2799/2798.Number of Employees Who Met the Target/README_EN.md +++ b/solution/2700-2799/2798.Number of Employees Who Met the Target/README_EN.md @@ -74,12 +74,16 @@ The time complexity is $O(n)$, where $n$ is the length of the array $hours$. The +#### Python3 + ```python class Solution: def numberOfEmployeesWhoMetTarget(self, hours: List[int], target: int) -> int: return sum(x >= target for x in hours) ``` +#### Java + ```java class Solution { public int numberOfEmployeesWhoMetTarget(int[] hours, int target) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -103,6 +109,8 @@ public: }; ``` +#### Go + ```go func numberOfEmployeesWhoMetTarget(hours []int, target int) (ans int) { for _, x := range hours { @@ -114,12 +122,16 @@ func numberOfEmployeesWhoMetTarget(hours []int, target int) (ans int) { } ``` +#### TypeScript + ```ts function numberOfEmployeesWhoMetTarget(hours: number[], target: number): number { return hours.filter(x => x >= target).length; } ``` +#### Rust + ```rust impl Solution { pub fn number_of_employees_who_met_target(hours: Vec, target: i32) -> i32 { diff --git a/solution/2700-2799/2799.Count Complete Subarrays in an Array/README.md b/solution/2700-2799/2799.Count Complete Subarrays in an Array/README.md index 4d58522ed0091..b011c8621ffeb 100644 --- a/solution/2700-2799/2799.Count Complete Subarrays in an Array/README.md +++ b/solution/2700-2799/2799.Count Complete Subarrays in an Array/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def countCompleteSubarrays(self, nums: List[int]) -> int: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countCompleteSubarrays(int[] nums) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func countCompleteSubarrays(nums []int) (ans int) { s := map[int]bool{} @@ -153,6 +161,8 @@ func countCompleteSubarrays(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function countCompleteSubarrays(nums: number[]): number { const s: Set = new Set(nums); @@ -172,6 +182,8 @@ function countCompleteSubarrays(nums: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -213,6 +225,8 @@ impl Solution { +#### Python3 + ```python class Solution: def countCompleteSubarrays(self, nums: List[int]) -> int: @@ -231,6 +245,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countCompleteSubarrays(int[] nums) { @@ -256,6 +272,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -282,6 +300,8 @@ public: }; ``` +#### Go + ```go func countCompleteSubarrays(nums []int) (ans int) { d := map[int]int{} @@ -306,6 +326,8 @@ func countCompleteSubarrays(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function countCompleteSubarrays(nums: number[]): number { const d: Map = new Map(); @@ -332,6 +354,8 @@ function countCompleteSubarrays(nums: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; use std::collections::HashSet; diff --git a/solution/2700-2799/2799.Count Complete Subarrays in an Array/README_EN.md b/solution/2700-2799/2799.Count Complete Subarrays in an Array/README_EN.md index bffa54c090e0a..989fc082af15e 100644 --- a/solution/2700-2799/2799.Count Complete Subarrays in an Array/README_EN.md +++ b/solution/2700-2799/2799.Count Complete Subarrays in an Array/README_EN.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def countCompleteSubarrays(self, nums: List[int]) -> int: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countCompleteSubarrays(int[] nums) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func countCompleteSubarrays(nums []int) (ans int) { s := map[int]bool{} @@ -145,6 +153,8 @@ func countCompleteSubarrays(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function countCompleteSubarrays(nums: number[]): number { const s: Set = new Set(nums); @@ -164,6 +174,8 @@ function countCompleteSubarrays(nums: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashSet; impl Solution { @@ -197,6 +209,8 @@ impl Solution { +#### Python3 + ```python class Solution: def countCompleteSubarrays(self, nums: List[int]) -> int: @@ -215,6 +229,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countCompleteSubarrays(int[] nums) { @@ -240,6 +256,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -266,6 +284,8 @@ public: }; ``` +#### Go + ```go func countCompleteSubarrays(nums []int) (ans int) { d := map[int]int{} @@ -290,6 +310,8 @@ func countCompleteSubarrays(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function countCompleteSubarrays(nums: number[]): number { const d: Map = new Map(); @@ -316,6 +338,8 @@ function countCompleteSubarrays(nums: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; use std::collections::HashSet; diff --git a/solution/2800-2899/2800.Shortest String That Contains Three Strings/README.md b/solution/2800-2899/2800.Shortest String That Contains Three Strings/README.md index bfdb9f3c77682..703812a4e9a58 100644 --- a/solution/2800-2899/2800.Shortest String That Contains Three Strings/README.md +++ b/solution/2800-2899/2800.Shortest String That Contains Three Strings/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def minimumString(self, a: str, b: str, c: str) -> str: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String minimumString(String a, String b, String c) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func minimumString(a string, b string, c string) string { f := func(s, t string) string { @@ -193,6 +201,8 @@ func minimumString(a string, b string, c string) string { } ``` +#### TypeScript + ```ts function minimumString(a: string, b: string, c: string): string { const f = (s: string, t: string): string => { @@ -231,6 +241,8 @@ function minimumString(a: string, b: string, c: string): string { } ``` +#### Rust + ```rust impl Solution { fn f(s1: String, s2: String) -> String { diff --git a/solution/2800-2899/2800.Shortest String That Contains Three Strings/README_EN.md b/solution/2800-2899/2800.Shortest String That Contains Three Strings/README_EN.md index b49958085335d..3c56ba0479479 100644 --- a/solution/2800-2899/2800.Shortest String That Contains Three Strings/README_EN.md +++ b/solution/2800-2899/2800.Shortest String That Contains Three Strings/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$. Where $n$ i +#### Python3 + ```python class Solution: def minimumString(self, a: str, b: str, c: str) -> str: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String minimumString(String a, String b, String c) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func minimumString(a string, b string, c string) string { f := func(s, t string) string { @@ -193,6 +201,8 @@ func minimumString(a string, b string, c string) string { } ``` +#### TypeScript + ```ts function minimumString(a: string, b: string, c: string): string { const f = (s: string, t: string): string => { @@ -231,6 +241,8 @@ function minimumString(a: string, b: string, c: string): string { } ``` +#### Rust + ```rust impl Solution { fn f(s1: String, s2: String) -> String { diff --git a/solution/2800-2899/2801.Count Stepping Numbers in Range/README.md b/solution/2800-2899/2801.Count Stepping Numbers in Range/README.md index 9ac33b5397460..1b4903476d640 100644 --- a/solution/2800-2899/2801.Count Stepping Numbers in Range/README.md +++ b/solution/2800-2899/2801.Count Stepping Numbers in Range/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def countSteppingNumbers(self, low: str, high: str) -> int: @@ -112,6 +114,8 @@ class Solution: return (a - b) % mod ``` +#### Java + ```java import java.math.BigInteger; @@ -155,6 +159,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -205,6 +211,8 @@ public: }; ``` +#### Go + ```go func countSteppingNumbers(low string, high string) int { const mod = 1e9 + 7 @@ -272,6 +280,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function countSteppingNumbers(low: string, high: string): number { const mod = 1e9 + 7; diff --git a/solution/2800-2899/2801.Count Stepping Numbers in Range/README_EN.md b/solution/2800-2899/2801.Count Stepping Numbers in Range/README_EN.md index bb1cf4ad3205f..b6aecfea3ffa0 100644 --- a/solution/2800-2899/2801.Count Stepping Numbers in Range/README_EN.md +++ b/solution/2800-2899/2801.Count Stepping Numbers in Range/README_EN.md @@ -87,6 +87,8 @@ Similar problems: +#### Python3 + ```python class Solution: def countSteppingNumbers(self, low: str, high: str) -> int: @@ -112,6 +114,8 @@ class Solution: return (a - b) % mod ``` +#### Java + ```java import java.math.BigInteger; @@ -155,6 +159,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -205,6 +211,8 @@ public: }; ``` +#### Go + ```go func countSteppingNumbers(low string, high string) int { const mod = 1e9 + 7 @@ -272,6 +280,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function countSteppingNumbers(low: string, high: string): number { const mod = 1e9 + 7; diff --git a/solution/2800-2899/2802.Find The K-th Lucky Number/README.md b/solution/2800-2899/2802.Find The K-th Lucky Number/README.md index e448603cf7e5a..43c1a276ac39f 100644 --- a/solution/2800-2899/2802.Find The K-th Lucky Number/README.md +++ b/solution/2800-2899/2802.Find The K-th Lucky Number/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def kthLuckyNumber(self, k: int) -> str: @@ -92,6 +94,8 @@ class Solution: return "".join(ans) ``` +#### Java + ```java class Solution { public String kthLuckyNumber(int k) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func kthLuckyNumber(k int) string { n := 1 @@ -158,6 +166,8 @@ func kthLuckyNumber(k int) string { } ``` +#### TypeScript + ```ts function kthLuckyNumber(k: number): string { let n = 1; diff --git a/solution/2800-2899/2802.Find The K-th Lucky Number/README_EN.md b/solution/2800-2899/2802.Find The K-th Lucky Number/README_EN.md index 34b54e94b0638..eb2e41d2f593c 100644 --- a/solution/2800-2899/2802.Find The K-th Lucky Number/README_EN.md +++ b/solution/2800-2899/2802.Find The K-th Lucky Number/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(\log k)$, and the space complexity is $O(\log k)$. +#### Python3 + ```python class Solution: def kthLuckyNumber(self, k: int) -> str: @@ -90,6 +92,8 @@ class Solution: return "".join(ans) ``` +#### Java + ```java class Solution { public String kthLuckyNumber(int k) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func kthLuckyNumber(k int) string { n := 1 @@ -156,6 +164,8 @@ func kthLuckyNumber(k int) string { } ``` +#### TypeScript + ```ts function kthLuckyNumber(k: number): string { let n = 1; diff --git a/solution/2800-2899/2803.Factorial Generator/README.md b/solution/2800-2899/2803.Factorial Generator/README.md index e1ff96888a6b8..f6cf94a711fb6 100644 --- a/solution/2800-2899/2803.Factorial Generator/README.md +++ b/solution/2800-2899/2803.Factorial Generator/README.md @@ -75,6 +75,8 @@ gen.next().value // 1 +#### TypeScript + ```ts function* factorial(n: number): Generator { if (n === 0) { diff --git a/solution/2800-2899/2803.Factorial Generator/README_EN.md b/solution/2800-2899/2803.Factorial Generator/README_EN.md index d0d4489e2437b..aa1c6618d658e 100644 --- a/solution/2800-2899/2803.Factorial Generator/README_EN.md +++ b/solution/2800-2899/2803.Factorial Generator/README_EN.md @@ -73,6 +73,8 @@ gen.next().value // 1 +#### TypeScript + ```ts function* factorial(n: number): Generator { if (n === 0) { diff --git a/solution/2800-2899/2804.Array Prototype ForEach/README.md b/solution/2800-2899/2804.Array Prototype ForEach/README.md index 6612435a91188..3f9d8411e259f 100644 --- a/solution/2800-2899/2804.Array Prototype ForEach/README.md +++ b/solution/2800-2899/2804.Array Prototype ForEach/README.md @@ -91,6 +91,8 @@ context = {"context": 5} +#### TypeScript + ```ts Array.prototype.forEach = function (callback: Function, context: any): void { for (let i = 0; i < this.length; ++i) { diff --git a/solution/2800-2899/2804.Array Prototype ForEach/README_EN.md b/solution/2800-2899/2804.Array Prototype ForEach/README_EN.md index 70041502d265d..740cf473818cd 100644 --- a/solution/2800-2899/2804.Array Prototype ForEach/README_EN.md +++ b/solution/2800-2899/2804.Array Prototype ForEach/README_EN.md @@ -89,6 +89,8 @@ context = {"context": 5} +#### TypeScript + ```ts Array.prototype.forEach = function (callback: Function, context: any): void { for (let i = 0; i < this.length; ++i) { diff --git a/solution/2800-2899/2805.Custom Interval/README.md b/solution/2800-2899/2805.Custom Interval/README.md index 833e402e1524d..29ad14ba79b2c 100644 --- a/solution/2800-2899/2805.Custom Interval/README.md +++ b/solution/2800-2899/2805.Custom Interval/README.md @@ -89,6 +89,8 @@ setTimeout(() => { +#### TypeScript + ```ts const intervalMap = new Map(); diff --git a/solution/2800-2899/2805.Custom Interval/README_EN.md b/solution/2800-2899/2805.Custom Interval/README_EN.md index d941bd9e2e17d..4e53683331147 100644 --- a/solution/2800-2899/2805.Custom Interval/README_EN.md +++ b/solution/2800-2899/2805.Custom Interval/README_EN.md @@ -93,6 +93,8 @@ setTimeout(() => { +#### TypeScript + ```ts const intervalMap = new Map(); diff --git a/solution/2800-2899/2806.Account Balance After Rounded Purchase/README.md b/solution/2800-2899/2806.Account Balance After Rounded Purchase/README.md index 157afe6cefe39..fb530d1b54ca6 100644 --- a/solution/2800-2899/2806.Account Balance After Rounded Purchase/README.md +++ b/solution/2800-2899/2806.Account Balance After Rounded Purchase/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int: @@ -80,6 +82,8 @@ class Solution: return 100 - x ``` +#### Java + ```java class Solution { public int accountBalanceAfterPurchase(int purchaseAmount) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func accountBalanceAfterPurchase(purchaseAmount int) int { diff, x := 100, 0 @@ -134,6 +142,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function accountBalanceAfterPurchase(purchaseAmount: number): number { let [diff, x] = [100, 0]; diff --git a/solution/2800-2899/2806.Account Balance After Rounded Purchase/README_EN.md b/solution/2800-2899/2806.Account Balance After Rounded Purchase/README_EN.md index 75dfcb2df20fd..9f655c2f61cf3 100644 --- a/solution/2800-2899/2806.Account Balance After Rounded Purchase/README_EN.md +++ b/solution/2800-2899/2806.Account Balance After Rounded Purchase/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int: @@ -80,6 +82,8 @@ class Solution: return 100 - x ``` +#### Java + ```java class Solution { public int accountBalanceAfterPurchase(int purchaseAmount) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func accountBalanceAfterPurchase(purchaseAmount int) int { diff, x := 100, 0 @@ -134,6 +142,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function accountBalanceAfterPurchase(purchaseAmount: number): number { let [diff, x] = [100, 0]; diff --git a/solution/2800-2899/2807.Insert Greatest Common Divisors in Linked List/README.md b/solution/2800-2899/2807.Insert Greatest Common Divisors in Linked List/README.md index b653b2c289bfc..99138e29b48dc 100644 --- a/solution/2800-2899/2807.Insert Greatest Common Divisors in Linked List/README.md +++ b/solution/2800-2899/2807.Insert Greatest Common Divisors in Linked List/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -94,6 +96,8 @@ class Solution: return head ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -174,6 +182,8 @@ func gcd(a, b int) int { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/2800-2899/2807.Insert Greatest Common Divisors in Linked List/README_EN.md b/solution/2800-2899/2807.Insert Greatest Common Divisors in Linked List/README_EN.md index 9cf42841b96e7..e76671ded4309 100644 --- a/solution/2800-2899/2807.Insert Greatest Common Divisors in Linked List/README_EN.md +++ b/solution/2800-2899/2807.Insert Greatest Common Divisors in Linked List/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(n \times \log M)$, where $n$ is the length of the link +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -90,6 +92,8 @@ class Solution: return head ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -170,6 +178,8 @@ func gcd(a, b int) int { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/2800-2899/2808.Minimum Seconds to Equalize a Circular Array/README.md b/solution/2800-2899/2808.Minimum Seconds to Equalize a Circular Array/README.md index 63a2eac673567..ee94c02e73b2e 100644 --- a/solution/2800-2899/2808.Minimum Seconds to Equalize a Circular Array/README.md +++ b/solution/2800-2899/2808.Minimum Seconds to Equalize a Circular Array/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def minimumSeconds(self, nums: List[int]) -> int: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumSeconds(List nums) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func minimumSeconds(nums []int) int { d := map[int][]int{} @@ -167,6 +175,8 @@ func minimumSeconds(nums []int) int { } ``` +#### TypeScript + ```ts function minimumSeconds(nums: number[]): number { const d: Map = new Map(); diff --git a/solution/2800-2899/2808.Minimum Seconds to Equalize a Circular Array/README_EN.md b/solution/2800-2899/2808.Minimum Seconds to Equalize a Circular Array/README_EN.md index 5c82ff61cf9e7..82ccf1df3e923 100644 --- a/solution/2800-2899/2808.Minimum Seconds to Equalize a Circular Array/README_EN.md +++ b/solution/2800-2899/2808.Minimum Seconds to Equalize a Circular Array/README_EN.md @@ -87,6 +87,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python class Solution: def minimumSeconds(self, nums: List[int]) -> int: @@ -103,6 +105,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumSeconds(List nums) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func minimumSeconds(nums []int) int { d := map[int][]int{} @@ -168,6 +176,8 @@ func minimumSeconds(nums []int) int { } ``` +#### TypeScript + ```ts function minimumSeconds(nums: number[]): number { const d: Map = new Map(); diff --git a/solution/2800-2899/2809.Minimum Time to Make Array Sum At Most x/README.md b/solution/2800-2899/2809.Minimum Time to Make Array Sum At Most x/README.md index fbef31e2687ea..63eb7182b1ce3 100644 --- a/solution/2800-2899/2809.Minimum Time to Make Array Sum At Most x/README.md +++ b/solution/2800-2899/2809.Minimum Time to Make Array Sum At Most x/README.md @@ -99,6 +99,8 @@ $$ +#### Python3 + ```python class Solution: def minimumTime(self, nums1: List[int], nums2: List[int], x: int) -> int: @@ -117,6 +119,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minimumTime(List nums1, List nums2, int x) { @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -187,6 +193,8 @@ public: }; ``` +#### Go + ```go func minimumTime(nums1 []int, nums2 []int, x int) int { n := len(nums1) @@ -221,6 +229,8 @@ func minimumTime(nums1 []int, nums2 []int, x int) int { } ``` +#### TypeScript + ```ts function minimumTime(nums1: number[], nums2: number[], x: number): number { const n = nums1.length; @@ -258,6 +268,8 @@ function minimumTime(nums1: number[], nums2: number[], x: number): number { +#### Python3 + ```python class Solution: def minimumTime(self, nums1: List[int], nums2: List[int], x: int) -> int: @@ -274,6 +286,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minimumTime(List nums1, List nums2, int x) { @@ -308,6 +322,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -337,6 +353,8 @@ public: }; ``` +#### Go + ```go func minimumTime(nums1 []int, nums2 []int, x int) int { n := len(nums1) @@ -365,6 +383,8 @@ func minimumTime(nums1 []int, nums2 []int, x int) int { } ``` +#### TypeScript + ```ts function minimumTime(nums1: number[], nums2: number[], x: number): number { const n = nums1.length; diff --git a/solution/2800-2899/2809.Minimum Time to Make Array Sum At Most x/README_EN.md b/solution/2800-2899/2809.Minimum Time to Make Array Sum At Most x/README_EN.md index a84cd6b336fe3..734e7ae44cda3 100644 --- a/solution/2800-2899/2809.Minimum Time to Make Array Sum At Most x/README_EN.md +++ b/solution/2800-2899/2809.Minimum Time to Make Array Sum At Most x/README_EN.md @@ -98,6 +98,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$, where $n$ +#### Python3 + ```python class Solution: def minimumTime(self, nums1: List[int], nums2: List[int], x: int) -> int: @@ -116,6 +118,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minimumTime(List nums1, List nums2, int x) { @@ -153,6 +157,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go func minimumTime(nums1 []int, nums2 []int, x int) int { n := len(nums1) @@ -220,6 +228,8 @@ func minimumTime(nums1 []int, nums2 []int, x int) int { } ``` +#### TypeScript + ```ts function minimumTime(nums1: number[], nums2: number[], x: number): number { const n = nums1.length; @@ -257,6 +267,8 @@ We notice that the state $f[i][j]$ is only related to $f[i-1][j]$ and $f[i-1][j- +#### Python3 + ```python class Solution: def minimumTime(self, nums1: List[int], nums2: List[int], x: int) -> int: @@ -273,6 +285,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minimumTime(List nums1, List nums2, int x) { @@ -307,6 +321,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -336,6 +352,8 @@ public: }; ``` +#### Go + ```go func minimumTime(nums1 []int, nums2 []int, x int) int { n := len(nums1) @@ -364,6 +382,8 @@ func minimumTime(nums1 []int, nums2 []int, x int) int { } ``` +#### TypeScript + ```ts function minimumTime(nums1: number[], nums2: number[], x: number): number { const n = nums1.length; diff --git a/solution/2800-2899/2810.Faulty Keyboard/README.md b/solution/2800-2899/2810.Faulty Keyboard/README.md index afd80fad7e64e..68f6db3ae85b1 100644 --- a/solution/2800-2899/2810.Faulty Keyboard/README.md +++ b/solution/2800-2899/2810.Faulty Keyboard/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def finalString(self, s: str) -> str: @@ -96,6 +98,8 @@ class Solution: return "".join(t) ``` +#### Java + ```java class Solution { public String finalString(String s) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func finalString(s string) string { t := []rune{} @@ -145,6 +153,8 @@ func finalString(s string) string { } ``` +#### TypeScript + ```ts function finalString(s: string): string { const t: string[] = []; @@ -159,6 +169,8 @@ function finalString(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn final_string(s: String) -> String { diff --git a/solution/2800-2899/2810.Faulty Keyboard/README_EN.md b/solution/2800-2899/2810.Faulty Keyboard/README_EN.md index 90a1fd0205afb..e6d440f57277b 100644 --- a/solution/2800-2899/2810.Faulty Keyboard/README_EN.md +++ b/solution/2800-2899/2810.Faulty Keyboard/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$, where $n$ i +#### Python3 + ```python class Solution: def finalString(self, s: str) -> str: @@ -96,6 +98,8 @@ class Solution: return "".join(t) ``` +#### Java + ```java class Solution { public String finalString(String s) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func finalString(s string) string { t := []rune{} @@ -145,6 +153,8 @@ func finalString(s string) string { } ``` +#### TypeScript + ```ts function finalString(s: string): string { const t: string[] = []; @@ -159,6 +169,8 @@ function finalString(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn final_string(s: String) -> String { diff --git a/solution/2800-2899/2811.Check if it is Possible to Split Array/README.md b/solution/2800-2899/2811.Check if it is Possible to Split Array/README.md index af11f407c3aed..2ad93a41d524c 100644 --- a/solution/2800-2899/2811.Check if it is Possible to Split Array/README.md +++ b/solution/2800-2899/2811.Check if it is Possible to Split Array/README.md @@ -106,6 +106,8 @@ tags: +#### Python3 + ```python class Solution: def canSplitArray(self, nums: List[int], m: int) -> bool: @@ -124,6 +126,8 @@ class Solution: return dfs(0, len(nums) - 1) ``` +#### Java + ```java class Solution { private Boolean[][] f; @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -194,6 +200,8 @@ public: }; ``` +#### Go + ```go func canSplitArray(nums []int, m int) bool { n := len(nums) @@ -228,6 +236,8 @@ func canSplitArray(nums []int, m int) bool { } ``` +#### TypeScript + ```ts function canSplitArray(nums: number[], m: number): boolean { const n = nums.length; @@ -260,6 +270,8 @@ function canSplitArray(nums: number[], m: number): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn can_split_array(nums: Vec, m: i32) -> bool { @@ -293,6 +305,8 @@ impl Solution { +#### TypeScript + ```ts function canSplitArray(nums: number[], m: number): boolean { const n = nums.length; diff --git a/solution/2800-2899/2811.Check if it is Possible to Split Array/README_EN.md b/solution/2800-2899/2811.Check if it is Possible to Split Array/README_EN.md index 0b945a66e3be2..2ff6f893464c1 100644 --- a/solution/2800-2899/2811.Check if it is Possible to Split Array/README_EN.md +++ b/solution/2800-2899/2811.Check if it is Possible to Split Array/README_EN.md @@ -93,6 +93,8 @@ The time complexity is $O(n^3)$, and the space complexity is $O(n^2)$, where $n$ +#### Python3 + ```python class Solution: def canSplitArray(self, nums: List[int], m: int) -> bool: @@ -111,6 +113,8 @@ class Solution: return dfs(0, len(nums) - 1) ``` +#### Java + ```java class Solution { private Boolean[][] f; @@ -147,6 +151,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func canSplitArray(nums []int, m int) bool { n := len(nums) @@ -215,6 +223,8 @@ func canSplitArray(nums []int, m int) bool { } ``` +#### TypeScript + ```ts function canSplitArray(nums: number[], m: number): boolean { const n = nums.length; @@ -247,6 +257,8 @@ function canSplitArray(nums: number[], m: number): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn can_split_array(nums: Vec, m: i32) -> bool { @@ -280,6 +292,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### TypeScript + ```ts function canSplitArray(nums: number[], m: number): boolean { const n = nums.length; diff --git a/solution/2800-2899/2812.Find the Safest Path in a Grid/README.md b/solution/2800-2899/2812.Find the Safest Path in a Grid/README.md index 0a76c27bbbe45..2bb6774ec41ae 100644 --- a/solution/2800-2899/2812.Find the Safest Path in a Grid/README.md +++ b/solution/2800-2899/2812.Find the Safest Path in a Grid/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class UnionFind: def __init__(self, n): @@ -154,6 +156,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { public int maximumSafenessFactor(List> grid) { @@ -243,6 +247,8 @@ class UnionFind { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -324,6 +330,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p []int @@ -415,6 +423,8 @@ func maximumSafenessFactor(grid [][]int) int { } ``` +#### TypeScript + ```ts class UnionFind { private p: number[]; @@ -498,6 +508,8 @@ function maximumSafenessFactor(grid: number[][]): number { } ``` +#### Rust + ```rust use std::collections::VecDeque; impl Solution { @@ -574,6 +586,8 @@ impl Solution { +#### TypeScript + ```ts function maximumSafenessFactor(grid: number[][]): number { const n = grid.length; diff --git a/solution/2800-2899/2812.Find the Safest Path in a Grid/README_EN.md b/solution/2800-2899/2812.Find the Safest Path in a Grid/README_EN.md index fcecb750692ac..f00c06bc93e32 100644 --- a/solution/2800-2899/2812.Find the Safest Path in a Grid/README_EN.md +++ b/solution/2800-2899/2812.Find the Safest Path in a Grid/README_EN.md @@ -93,6 +93,8 @@ The time complexity is $O(n^2 \times \log n)$, and the space complexity $O(n^2)$ +#### Python3 + ```python class UnionFind: def __init__(self, n): @@ -151,6 +153,8 @@ class Solution: return 0 ``` +#### Java + ```java class Solution { public int maximumSafenessFactor(List> grid) { @@ -240,6 +244,8 @@ class UnionFind { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -321,6 +327,8 @@ public: }; ``` +#### Go + ```go type unionFind struct { p []int @@ -412,6 +420,8 @@ func maximumSafenessFactor(grid [][]int) int { } ``` +#### TypeScript + ```ts class UnionFind { private p: number[]; @@ -495,6 +505,8 @@ function maximumSafenessFactor(grid: number[][]): number { } ``` +#### Rust + ```rust use std::collections::VecDeque; impl Solution { @@ -571,6 +583,8 @@ impl Solution { +#### TypeScript + ```ts function maximumSafenessFactor(grid: number[][]): number { const n = grid.length; diff --git a/solution/2800-2899/2813.Maximum Elegance of a K-Length Subsequence/README.md b/solution/2800-2899/2813.Maximum Elegance of a K-Length Subsequence/README.md index ab1c1e30f4d06..c86bb08b9ee66 100644 --- a/solution/2800-2899/2813.Maximum Elegance of a K-Length Subsequence/README.md +++ b/solution/2800-2899/2813.Maximum Elegance of a K-Length Subsequence/README.md @@ -102,6 +102,8 @@ tags: +#### Python3 + ```python class Solution: def findMaximumElegance(self, items: List[List[int]], k: int) -> int: @@ -125,6 +127,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long findMaximumElegance(int[][] items, int k) { @@ -155,6 +159,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -191,6 +197,8 @@ public: }; ``` +#### Go + ```go func findMaximumElegance(items [][]int, k int) int64 { sort.Slice(items, func(i, j int) bool { return items[i][0] > items[j][0] }) @@ -221,6 +229,8 @@ func findMaximumElegance(items [][]int, k int) int64 { } ``` +#### TypeScript + ```ts function findMaximumElegance(items: number[][], k: number): number { items.sort((a, b) => b[0] - a[0]); diff --git a/solution/2800-2899/2813.Maximum Elegance of a K-Length Subsequence/README_EN.md b/solution/2800-2899/2813.Maximum Elegance of a K-Length Subsequence/README_EN.md index 80e7b2ea8e8c9..d02f3f201cad2 100644 --- a/solution/2800-2899/2813.Maximum Elegance of a K-Length Subsequence/README_EN.md +++ b/solution/2800-2899/2813.Maximum Elegance of a K-Length Subsequence/README_EN.md @@ -97,6 +97,8 @@ The time complexity is $O(n \times \log n)$ and the space complexity is $O(n)$, +#### Python3 + ```python class Solution: def findMaximumElegance(self, items: List[List[int]], k: int) -> int: @@ -120,6 +122,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long findMaximumElegance(int[][] items, int k) { @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go func findMaximumElegance(items [][]int, k int) int64 { sort.Slice(items, func(i, j int) bool { return items[i][0] > items[j][0] }) @@ -216,6 +224,8 @@ func findMaximumElegance(items [][]int, k int) int64 { } ``` +#### TypeScript + ```ts function findMaximumElegance(items: number[][], k: number): number { items.sort((a, b) => b[0] - a[0]); diff --git a/solution/2800-2899/2814.Minimum Time Takes to Reach Destination Without Drowning/README.md b/solution/2800-2899/2814.Minimum Time Takes to Reach Destination Without Drowning/README.md index f6d0e16c055c7..43ea5f2a8db49 100644 --- a/solution/2800-2899/2814.Minimum Time Takes to Reach Destination Without Drowning/README.md +++ b/solution/2800-2899/2814.Minimum Time Takes to Reach Destination Without Drowning/README.md @@ -98,6 +98,8 @@ tags: +#### Python3 + ```python class Solution: def minimumSeconds(self, land: List[List[str]]) -> int: @@ -154,6 +156,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minimumSeconds(List> land) { @@ -221,6 +225,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -290,6 +296,8 @@ public: }; ``` +#### Go + ```go func minimumSeconds(land [][]string) int { m, n := len(land), len(land[0]) @@ -362,6 +370,8 @@ func minimumSeconds(land [][]string) int { } ``` +#### TypeScript + ```ts function minimumSeconds(land: string[][]): number { const m = land.length; diff --git a/solution/2800-2899/2814.Minimum Time Takes to Reach Destination Without Drowning/README_EN.md b/solution/2800-2899/2814.Minimum Time Takes to Reach Destination Without Drowning/README_EN.md index 76078fdcadc50..c33fe54b03def 100644 --- a/solution/2800-2899/2814.Minimum Time Takes to Reach Destination Without Drowning/README_EN.md +++ b/solution/2800-2899/2814.Minimum Time Takes to Reach Destination Without Drowning/README_EN.md @@ -95,6 +95,8 @@ The time complexity is $O(m \times n)$ and the space complexity is $O(m \times n +#### Python3 + ```python class Solution: def minimumSeconds(self, land: List[List[str]]) -> int: @@ -151,6 +153,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minimumSeconds(List> land) { @@ -218,6 +222,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -287,6 +293,8 @@ public: }; ``` +#### Go + ```go func minimumSeconds(land [][]string) int { m, n := len(land), len(land[0]) @@ -359,6 +367,8 @@ func minimumSeconds(land [][]string) int { } ``` +#### TypeScript + ```ts function minimumSeconds(land: string[][]): number { const m = land.length; diff --git a/solution/2800-2899/2815.Max Pair Sum in an Array/README.md b/solution/2800-2899/2815.Max Pair Sum in an Array/README.md index 36777c26d25ce..c899c15aaa62b 100644 --- a/solution/2800-2899/2815.Max Pair Sum in an Array/README.md +++ b/solution/2800-2899/2815.Max Pair Sum in an Array/README.md @@ -64,6 +64,8 @@ i = 3 和 j = 4 ,nums[i] 和 nums[j] 数位上最大的数字相等,且这 +#### Python3 + ```python class Solution: def maxSum(self, nums: List[int]) -> int: @@ -76,6 +78,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxSum(int[] nums) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func maxSum(nums []int) int { ans := -1 @@ -149,6 +157,8 @@ func maxSum(nums []int) int { } ``` +#### TypeScript + ```ts function maxSum(nums: number[]): number { const n = nums.length; diff --git a/solution/2800-2899/2815.Max Pair Sum in an Array/README_EN.md b/solution/2800-2899/2815.Max Pair Sum in an Array/README_EN.md index 980517bdd7631..2661cdcba801b 100644 --- a/solution/2800-2899/2815.Max Pair Sum in an Array/README_EN.md +++ b/solution/2800-2899/2815.Max Pair Sum in an Array/README_EN.md @@ -64,6 +64,8 @@ The time complexity is $O(n^2 \times \log M)$, where $n$ is the length of the ar +#### Python3 + ```python class Solution: def maxSum(self, nums: List[int]) -> int: @@ -76,6 +78,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxSum(int[] nums) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func maxSum(nums []int) int { ans := -1 @@ -149,6 +157,8 @@ func maxSum(nums []int) int { } ``` +#### TypeScript + ```ts function maxSum(nums: number[]): number { const n = nums.length; diff --git a/solution/2800-2899/2816.Double a Number Represented as a Linked List/README.md b/solution/2800-2899/2816.Double a Number Represented as a Linked List/README.md index a6e27e81e55b7..b9b035b9dcfee 100644 --- a/solution/2800-2899/2816.Double a Number Represented as a Linked List/README.md +++ b/solution/2800-2899/2816.Double a Number Represented as a Linked List/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -97,6 +99,8 @@ class Solution: return reverse(dummy.next) ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -225,6 +233,8 @@ func reverse(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/2800-2899/2816.Double a Number Represented as a Linked List/README_EN.md b/solution/2800-2899/2816.Double a Number Represented as a Linked List/README_EN.md index 61ba91ccefcf8..b0b0db490a9d7 100644 --- a/solution/2800-2899/2816.Double a Number Represented as a Linked List/README_EN.md +++ b/solution/2800-2899/2816.Double a Number Represented as a Linked List/README_EN.md @@ -64,6 +64,8 @@ Time complexity is $O(n)$, where $n$ is the length of the linked list. Ignoring +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -96,6 +98,8 @@ class Solution: return reverse(dummy.next) ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -185,6 +191,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -224,6 +232,8 @@ func reverse(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/2800-2899/2817.Minimum Absolute Difference Between Elements With Constraint/README.md b/solution/2800-2899/2817.Minimum Absolute Difference Between Elements With Constraint/README.md index b7b6995c2e525..5e57054fd1f25 100644 --- a/solution/2800-2899/2817.Minimum Absolute Difference Between Elements With Constraint/README.md +++ b/solution/2800-2899/2817.Minimum Absolute Difference Between Elements With Constraint/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python from sortedcontainers import SortedList @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minAbsoluteDifference(List nums, int x) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func minAbsoluteDifference(nums []int, x int) int { rbt := redblacktree.NewWithIntComparator() @@ -166,6 +174,8 @@ func minAbsoluteDifference(nums []int, x int) int { } ``` +#### TypeScript + ```ts function minAbsoluteDifference(nums: number[], x: number): number { const s = new TreeMultiSet(); diff --git a/solution/2800-2899/2817.Minimum Absolute Difference Between Elements With Constraint/README_EN.md b/solution/2800-2899/2817.Minimum Absolute Difference Between Elements With Constraint/README_EN.md index 64b7d69a8e8f5..89819908e0154 100644 --- a/solution/2800-2899/2817.Minimum Absolute Difference Between Elements With Constraint/README_EN.md +++ b/solution/2800-2899/2817.Minimum Absolute Difference Between Elements With Constraint/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python from sortedcontainers import SortedList @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minAbsoluteDifference(List nums, int x) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func minAbsoluteDifference(nums []int, x int) int { rbt := redblacktree.NewWithIntComparator() @@ -164,6 +172,8 @@ func minAbsoluteDifference(nums []int, x int) int { } ``` +#### TypeScript + ```ts function minAbsoluteDifference(nums: number[], x: number): number { const s = new TreeMultiSet(); diff --git a/solution/2800-2899/2818.Apply Operations to Maximize Score/README.md b/solution/2800-2899/2818.Apply Operations to Maximize Score/README.md index 91472d2240ebb..3dd8183c6d550 100644 --- a/solution/2800-2899/2818.Apply Operations to Maximize Score/README.md +++ b/solution/2800-2899/2818.Apply Operations to Maximize Score/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python def primeFactors(n): i = 2 @@ -145,6 +147,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private final int mod = (int) 1e9 + 7; @@ -227,6 +231,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -306,6 +312,8 @@ public: }; ``` +#### Go + ```go func maximumScore(nums []int, k int) int { n := len(nums) @@ -384,6 +392,8 @@ func primeFactors(n int) int { } ``` +#### TypeScript + ```ts function maximumScore(nums: number[], k: number): number { const mod = 10 ** 9 + 7; diff --git a/solution/2800-2899/2818.Apply Operations to Maximize Score/README_EN.md b/solution/2800-2899/2818.Apply Operations to Maximize Score/README_EN.md index 7e54c83f13f79..74cd2e23fdaf0 100644 --- a/solution/2800-2899/2818.Apply Operations to Maximize Score/README_EN.md +++ b/solution/2800-2899/2818.Apply Operations to Maximize Score/README_EN.md @@ -91,6 +91,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python def primeFactors(n): i = 2 @@ -143,6 +145,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private final int mod = (int) 1e9 + 7; @@ -225,6 +229,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -304,6 +310,8 @@ public: }; ``` +#### Go + ```go func maximumScore(nums []int, k int) int { n := len(nums) @@ -382,6 +390,8 @@ func primeFactors(n int) int { } ``` +#### TypeScript + ```ts function maximumScore(nums: number[], k: number): number { const mod = 10 ** 9 + 7; diff --git a/solution/2800-2899/2819.Minimum Relative Loss After Buying Chocolates/README.md b/solution/2800-2899/2819.Minimum Relative Loss After Buying Chocolates/README.md index bfb6382a6b767..811c544b59315 100644 --- a/solution/2800-2899/2819.Minimum Relative Loss After Buying Chocolates/README.md +++ b/solution/2800-2899/2819.Minimum Relative Loss After Buying Chocolates/README.md @@ -105,6 +105,8 @@ tags: +#### Python3 + ```python class Solution: def minimumRelativeLosses( @@ -133,6 +135,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -177,6 +181,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -214,6 +220,8 @@ public: }; ``` +#### Go + ```go func minimumRelativeLosses(prices []int, queries [][]int) []int64 { n := len(prices) @@ -249,6 +257,8 @@ func minimumRelativeLosses(prices []int, queries [][]int) []int64 { } ``` +#### TypeScript + ```ts function minimumRelativeLosses(prices: number[], queries: number[][]): number[] { const n = prices.length; diff --git a/solution/2800-2899/2819.Minimum Relative Loss After Buying Chocolates/README_EN.md b/solution/2800-2899/2819.Minimum Relative Loss After Buying Chocolates/README_EN.md index 3a5a255320445..a95bbb435fe23 100644 --- a/solution/2800-2899/2819.Minimum Relative Loss After Buying Chocolates/README_EN.md +++ b/solution/2800-2899/2819.Minimum Relative Loss After Buying Chocolates/README_EN.md @@ -103,6 +103,8 @@ The time complexity is $O((n + m) \times \log n)$, and the space complexity is $ +#### Python3 + ```python class Solution: def minimumRelativeLosses( @@ -131,6 +133,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -175,6 +179,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -212,6 +218,8 @@ public: }; ``` +#### Go + ```go func minimumRelativeLosses(prices []int, queries [][]int) []int64 { n := len(prices) @@ -247,6 +255,8 @@ func minimumRelativeLosses(prices []int, queries [][]int) []int64 { } ``` +#### TypeScript + ```ts function minimumRelativeLosses(prices: number[], queries: number[][]): number[] { const n = prices.length; diff --git a/solution/2800-2899/2820.Election Results/README.md b/solution/2800-2899/2820.Election Results/README.md index a5da97f57c50a..761e0bf9fee42 100644 --- a/solution/2800-2899/2820.Election Results/README.md +++ b/solution/2800-2899/2820.Election Results/README.md @@ -82,6 +82,8 @@ Votes table: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2800-2899/2820.Election Results/README_EN.md b/solution/2800-2899/2820.Election Results/README_EN.md index d3101b97f1728..cb090789ea858 100644 --- a/solution/2800-2899/2820.Election Results/README_EN.md +++ b/solution/2800-2899/2820.Election Results/README_EN.md @@ -81,6 +81,8 @@ Note that there may be multiple candidates ranking first in the result set, so w +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2800-2899/2821.Delay the Resolution of Each Promise/README.md b/solution/2800-2899/2821.Delay the Resolution of Each Promise/README.md index b130487eb849c..4593531c0184b 100644 --- a/solution/2800-2899/2821.Delay the Resolution of Each Promise/README.md +++ b/solution/2800-2899/2821.Delay the Resolution of Each Promise/README.md @@ -70,6 +70,8 @@ ms = 70 +#### TypeScript + ```ts function delayAll(functions: Function[], ms: number): Function[] { return functions.map(fn => { diff --git a/solution/2800-2899/2821.Delay the Resolution of Each Promise/README_EN.md b/solution/2800-2899/2821.Delay the Resolution of Each Promise/README_EN.md index d9d06dcafd270..3809fbe31e8e7 100644 --- a/solution/2800-2899/2821.Delay the Resolution of Each Promise/README_EN.md +++ b/solution/2800-2899/2821.Delay the Resolution of Each Promise/README_EN.md @@ -82,6 +82,8 @@ ms = 30 +#### TypeScript + ```ts function delayAll(functions: Function[], ms: number): Function[] { return functions.map(fn => { diff --git a/solution/2800-2899/2822.Inversion of Object/README.md b/solution/2800-2899/2822.Inversion of Object/README.md index 257db4a790176..100037565b132 100644 --- a/solution/2800-2899/2822.Inversion of Object/README.md +++ b/solution/2800-2899/2822.Inversion of Object/README.md @@ -63,6 +63,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2800-2899/2822.In +#### TypeScript + ```ts function invertObject(obj: Record): Record { const ans: Record = {}; diff --git a/solution/2800-2899/2822.Inversion of Object/README_EN.md b/solution/2800-2899/2822.Inversion of Object/README_EN.md index 47d203abe7772..45a35931e6be7 100644 --- a/solution/2800-2899/2822.Inversion of Object/README_EN.md +++ b/solution/2800-2899/2822.Inversion of Object/README_EN.md @@ -65,6 +65,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2800-2899/2822.In +#### TypeScript + ```ts function invertObject(obj: Record): Record { const ans: Record = {}; diff --git a/solution/2800-2899/2823.Deep Object Filter/README.md b/solution/2800-2899/2823.Deep Object Filter/README.md index e730a23955d9b..6ce29b13fd655 100644 --- a/solution/2800-2899/2823.Deep Object Filter/README.md +++ b/solution/2800-2899/2823.Deep Object Filter/README.md @@ -87,6 +87,8 @@ fn = (x) => Array.isArray(x) +#### TypeScript + ```ts function deepFilter(obj: Record, fn: Function): Record | undefined { const dfs = (data: any): any => { diff --git a/solution/2800-2899/2823.Deep Object Filter/README_EN.md b/solution/2800-2899/2823.Deep Object Filter/README_EN.md index 7454778154c98..c8a702e4a9dad 100644 --- a/solution/2800-2899/2823.Deep Object Filter/README_EN.md +++ b/solution/2800-2899/2823.Deep Object Filter/README_EN.md @@ -78,6 +78,8 @@ fn = (x) => Array.isArray(x) +#### TypeScript + ```ts function deepFilter(obj: Record, fn: Function): Record | undefined { const dfs = (data: any): any => { diff --git a/solution/2800-2899/2824.Count Pairs Whose Sum is Less than Target/README.md b/solution/2800-2899/2824.Count Pairs Whose Sum is Less than Target/README.md index 13d596b43d05a..2a4ba3d84c5bc 100644 --- a/solution/2800-2899/2824.Count Pairs Whose Sum is Less than Target/README.md +++ b/solution/2800-2899/2824.Count Pairs Whose Sum is Less than Target/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def countPairs(self, nums: List[int], target: int) -> int: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countPairs(List nums, int target) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func countPairs(nums []int, target int) (ans int) { sort.Ints(nums) @@ -145,6 +153,8 @@ func countPairs(nums []int, target int) (ans int) { } ``` +#### TypeScript + ```ts function countPairs(nums: number[], target: number): number { nums.sort((a, b) => a - b); diff --git a/solution/2800-2899/2824.Count Pairs Whose Sum is Less than Target/README_EN.md b/solution/2800-2899/2824.Count Pairs Whose Sum is Less than Target/README_EN.md index 79445d227e17d..76b2dec063762 100644 --- a/solution/2800-2899/2824.Count Pairs Whose Sum is Less than Target/README_EN.md +++ b/solution/2800-2899/2824.Count Pairs Whose Sum is Less than Target/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def countPairs(self, nums: List[int], target: int) -> int: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countPairs(List nums, int target) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func countPairs(nums []int, target int) (ans int) { sort.Ints(nums) @@ -143,6 +151,8 @@ func countPairs(nums []int, target int) (ans int) { } ``` +#### TypeScript + ```ts function countPairs(nums: number[], target: number): number { nums.sort((a, b) => a - b); diff --git a/solution/2800-2899/2825.Make String a Subsequence Using Cyclic Increments/README.md b/solution/2800-2899/2825.Make String a Subsequence Using Cyclic Increments/README.md index 2eb7df2ec51c6..63ad4181c3c4a 100644 --- a/solution/2800-2899/2825.Make String a Subsequence Using Cyclic Increments/README.md +++ b/solution/2800-2899/2825.Make String a Subsequence Using Cyclic Increments/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def canMakeSubsequence(self, str1: str, str2: str) -> bool: @@ -91,6 +93,8 @@ class Solution: return i == len(str2) ``` +#### Java + ```java class Solution { public boolean canMakeSubsequence(String str1, String str2) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func canMakeSubsequence(str1 string, str2 string) bool { i, n := 0, len(str2) @@ -138,6 +146,8 @@ func canMakeSubsequence(str1 string, str2 string) bool { } ``` +#### TypeScript + ```ts function canMakeSubsequence(str1: string, str2: string): boolean { let i = 0; diff --git a/solution/2800-2899/2825.Make String a Subsequence Using Cyclic Increments/README_EN.md b/solution/2800-2899/2825.Make String a Subsequence Using Cyclic Increments/README_EN.md index 32a272a732d28..69f0494135ca9 100644 --- a/solution/2800-2899/2825.Make String a Subsequence Using Cyclic Increments/README_EN.md +++ b/solution/2800-2899/2825.Make String a Subsequence Using Cyclic Increments/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(m + n)$, where $m$ and $n$ are the lengths of the stri +#### Python3 + ```python class Solution: def canMakeSubsequence(self, str1: str, str2: str) -> bool: @@ -89,6 +91,8 @@ class Solution: return i == len(str2) ``` +#### Java + ```java class Solution { public boolean canMakeSubsequence(String str1, String str2) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func canMakeSubsequence(str1 string, str2 string) bool { i, n := 0, len(str2) @@ -136,6 +144,8 @@ func canMakeSubsequence(str1 string, str2 string) bool { } ``` +#### TypeScript + ```ts function canMakeSubsequence(str1: string, str2: string): boolean { let i = 0; diff --git a/solution/2800-2899/2826.Sorting Three Groups/README.md b/solution/2800-2899/2826.Sorting Three Groups/README.md index 98f8ee1615c03..1e820f8ba84ee 100644 --- a/solution/2800-2899/2826.Sorting Three Groups/README.md +++ b/solution/2800-2899/2826.Sorting Three Groups/README.md @@ -78,6 +78,8 @@ nums 已是非递减顺序的。 +#### Python3 + ```python class Solution: def minimumOperations(self, nums: List[int]) -> int: @@ -100,6 +102,8 @@ class Solution: return min(f, g, h) ``` +#### Java + ```java class Solution { public int minimumOperations(List nums) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func minimumOperations(nums []int) int { f := make([]int, 3) @@ -177,6 +185,8 @@ func minimumOperations(nums []int) int { } ``` +#### TypeScript + ```ts function minimumOperations(nums: number[]): number { let f: number[] = new Array(3).fill(0); @@ -211,6 +221,8 @@ function minimumOperations(nums: number[]): number { +#### Python3 + ```python class Solution: def minimumOperations(self, nums: List[int]) -> int: diff --git a/solution/2800-2899/2826.Sorting Three Groups/README_EN.md b/solution/2800-2899/2826.Sorting Three Groups/README_EN.md index be0f317618396..ffdbcf1d87bac 100644 --- a/solution/2800-2899/2826.Sorting Three Groups/README_EN.md +++ b/solution/2800-2899/2826.Sorting Three Groups/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def minimumOperations(self, nums: List[int]) -> int: @@ -108,6 +110,8 @@ class Solution: return min(f, g, h) ``` +#### Java + ```java class Solution { public int minimumOperations(List nums) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func minimumOperations(nums []int) int { f := make([]int, 3) @@ -185,6 +193,8 @@ func minimumOperations(nums []int) int { } ``` +#### TypeScript + ```ts function minimumOperations(nums: number[]): number { let f: number[] = new Array(3).fill(0); @@ -219,6 +229,8 @@ function minimumOperations(nums: number[]): number { +#### Python3 + ```python class Solution: def minimumOperations(self, nums: List[int]) -> int: diff --git a/solution/2800-2899/2827.Number of Beautiful Integers in the Range/README.md b/solution/2800-2899/2827.Number of Beautiful Integers in the Range/README.md index 319776b076e5c..2aa49bce40078 100644 --- a/solution/2800-2899/2827.Number of Beautiful Integers in the Range/README.md +++ b/solution/2800-2899/2827.Number of Beautiful Integers in the Range/README.md @@ -107,6 +107,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfBeautifulIntegers(self, low: int, high: int, k: int) -> int: @@ -132,6 +134,8 @@ class Solution: return a - b ``` +#### Java + ```java class Solution { private String s; @@ -173,6 +177,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -213,6 +219,8 @@ public: }; ``` +#### Go + ```go func numberOfBeautifulIntegers(low int, high int, k int) int { s := strconv.Itoa(high) @@ -273,6 +281,8 @@ func g(m, n, k int) [][][]int { } ``` +#### TypeScript + ```ts function numberOfBeautifulIntegers(low: number, high: number, k: number): number { let s = String(high); diff --git a/solution/2800-2899/2827.Number of Beautiful Integers in the Range/README_EN.md b/solution/2800-2899/2827.Number of Beautiful Integers in the Range/README_EN.md index 6b0ac1f83e8d2..fb73550272af9 100644 --- a/solution/2800-2899/2827.Number of Beautiful Integers in the Range/README_EN.md +++ b/solution/2800-2899/2827.Number of Beautiful Integers in the Range/README_EN.md @@ -105,6 +105,8 @@ Similar problems: +#### Python3 + ```python class Solution: def numberOfBeautifulIntegers(self, low: int, high: int, k: int) -> int: @@ -130,6 +132,8 @@ class Solution: return a - b ``` +#### Java + ```java class Solution { private String s; @@ -171,6 +175,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -211,6 +217,8 @@ public: }; ``` +#### Go + ```go func numberOfBeautifulIntegers(low int, high int, k int) int { s := strconv.Itoa(high) @@ -271,6 +279,8 @@ func g(m, n, k int) [][][]int { } ``` +#### TypeScript + ```ts function numberOfBeautifulIntegers(low: number, high: number, k: number): number { let s = String(high); diff --git a/solution/2800-2899/2828.Check if a String Is an Acronym of Words/README.md b/solution/2800-2899/2828.Check if a String Is an Acronym of Words/README.md index c8b7cc0b46deb..5b8699b43f4cb 100644 --- a/solution/2800-2899/2828.Check if a String Is an Acronym of Words/README.md +++ b/solution/2800-2899/2828.Check if a String Is an Acronym of Words/README.md @@ -79,12 +79,16 @@ tags: +#### Python3 + ```python class Solution: def isAcronym(self, words: List[str], s: str) -> bool: return "".join(w[0] for w in words) == s ``` +#### Java + ```java class Solution { public boolean isAcronym(List words, String s) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -110,6 +116,8 @@ public: }; ``` +#### Go + ```go func isAcronym(words []string, s string) bool { t := []byte{} @@ -120,12 +128,16 @@ func isAcronym(words []string, s string) bool { } ``` +#### TypeScript + ```ts function isAcronym(words: string[], s: string): boolean { return words.map(w => w[0]).join('') === s; } ``` +#### Rust + ```rust impl Solution { pub fn is_acronym(words: Vec, s: String) -> bool { @@ -155,12 +167,16 @@ impl Solution { +#### Python3 + ```python class Solution: def isAcronym(self, words: List[str], s: str) -> bool: return len(words) == len(s) and all(w[0] == c for w, c in zip(words, s)) ``` +#### Java + ```java class Solution { public boolean isAcronym(List words, String s) { @@ -177,6 +193,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -194,6 +212,8 @@ public: }; ``` +#### Go + ```go func isAcronym(words []string, s string) bool { if len(words) != len(s) { @@ -208,6 +228,8 @@ func isAcronym(words []string, s string) bool { } ``` +#### TypeScript + ```ts function isAcronym(words: string[], s: string): boolean { if (words.length !== s.length) { @@ -222,6 +244,8 @@ function isAcronym(words: string[], s: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn is_acronym(words: Vec, s: String) -> bool { diff --git a/solution/2800-2899/2828.Check if a String Is an Acronym of Words/README_EN.md b/solution/2800-2899/2828.Check if a String Is an Acronym of Words/README_EN.md index 64e2c78a369e8..74025fc1b2054 100644 --- a/solution/2800-2899/2828.Check if a String Is an Acronym of Words/README_EN.md +++ b/solution/2800-2899/2828.Check if a String Is an Acronym of Words/README_EN.md @@ -77,12 +77,16 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def isAcronym(self, words: List[str], s: str) -> bool: return "".join(w[0] for w in words) == s ``` +#### Java + ```java class Solution { public boolean isAcronym(List words, String s) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func isAcronym(words []string, s string) bool { t := []byte{} @@ -118,12 +126,16 @@ func isAcronym(words []string, s string) bool { } ``` +#### TypeScript + ```ts function isAcronym(words: string[], s: string): boolean { return words.map(w => w[0]).join('') === s; } ``` +#### Rust + ```rust impl Solution { pub fn is_acronym(words: Vec, s: String) -> bool { @@ -153,12 +165,16 @@ The time complexity is $O(n)$, where $n$ is the length of the array $words$. The +#### Python3 + ```python class Solution: def isAcronym(self, words: List[str], s: str) -> bool: return len(words) == len(s) and all(w[0] == c for w, c in zip(words, s)) ``` +#### Java + ```java class Solution { public boolean isAcronym(List words, String s) { @@ -175,6 +191,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -192,6 +210,8 @@ public: }; ``` +#### Go + ```go func isAcronym(words []string, s string) bool { if len(words) != len(s) { @@ -206,6 +226,8 @@ func isAcronym(words []string, s string) bool { } ``` +#### TypeScript + ```ts function isAcronym(words: string[], s: string): boolean { if (words.length !== s.length) { @@ -220,6 +242,8 @@ function isAcronym(words: string[], s: string): boolean { } ``` +#### Rust + ```rust impl Solution { pub fn is_acronym(words: Vec, s: String) -> bool { diff --git a/solution/2800-2899/2829.Determine the Minimum Sum of a k-avoiding Array/README.md b/solution/2800-2899/2829.Determine the Minimum Sum of a k-avoiding Array/README.md index 699703df6ad67..3d9cd834ac3f9 100644 --- a/solution/2800-2899/2829.Determine the Minimum Sum of a k-avoiding Array/README.md +++ b/solution/2800-2899/2829.Determine the Minimum Sum of a k-avoiding Array/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def minimumSum(self, n: int, k: int) -> int: @@ -81,6 +83,8 @@ class Solution: return s ``` +#### Java + ```java class Solution { public int minimumSum(int n, int k) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func minimumSum(n int, k int) int { s, i := 0, 1 @@ -141,6 +149,8 @@ func minimumSum(n int, k int) int { } ``` +#### TypeScript + ```ts function minimumSum(n: number, k: number): number { let s = 0; diff --git a/solution/2800-2899/2829.Determine the Minimum Sum of a k-avoiding Array/README_EN.md b/solution/2800-2899/2829.Determine the Minimum Sum of a k-avoiding Array/README_EN.md index 0c9e591798b1f..9d36054d96cac 100644 --- a/solution/2800-2899/2829.Determine the Minimum Sum of a k-avoiding Array/README_EN.md +++ b/solution/2800-2899/2829.Determine the Minimum Sum of a k-avoiding Array/README_EN.md @@ -65,6 +65,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$. Here, $n$ +#### Python3 + ```python class Solution: def minimumSum(self, n: int, k: int) -> int: @@ -79,6 +81,8 @@ class Solution: return s ``` +#### Java + ```java class Solution { public int minimumSum(int n, int k) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func minimumSum(n int, k int) int { s, i := 0, 1 @@ -139,6 +147,8 @@ func minimumSum(n int, k int) int { } ``` +#### TypeScript + ```ts function minimumSum(n: number, k: number): number { let s = 0; diff --git a/solution/2800-2899/2830.Maximize the Profit as the Salesman/README.md b/solution/2800-2899/2830.Maximize the Profit as the Salesman/README.md index 0cbfea35454fa..6a2da63e459e2 100644 --- a/solution/2800-2899/2830.Maximize the Profit as the Salesman/README.md +++ b/solution/2800-2899/2830.Maximize the Profit as the Salesman/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def maximizeTheProfit(self, n: int, offers: List[List[int]]) -> int: @@ -95,6 +97,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int maximizeTheProfit(int n, List> offers) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func maximizeTheProfit(n int, offers [][]int) int { sort.Slice(offers, func(i, j int) bool { return offers[i][1] < offers[j][1] }) @@ -168,6 +176,8 @@ func maximizeTheProfit(n int, offers [][]int) int { } ``` +#### TypeScript + ```ts function maximizeTheProfit(n: number, offers: number[][]): number { offers.sort((a, b) => a[1] - b[1]); diff --git a/solution/2800-2899/2830.Maximize the Profit as the Salesman/README_EN.md b/solution/2800-2899/2830.Maximize the Profit as the Salesman/README_EN.md index 12b2d95c53a95..d52852ecc3a80 100644 --- a/solution/2800-2899/2830.Maximize the Profit as the Salesman/README_EN.md +++ b/solution/2800-2899/2830.Maximize the Profit as the Salesman/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def maximizeTheProfit(self, n: int, offers: List[List[int]]) -> int: @@ -94,6 +96,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int maximizeTheProfit(int n, List> offers) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func maximizeTheProfit(n int, offers [][]int) int { sort.Slice(offers, func(i, j int) bool { return offers[i][1] < offers[j][1] }) @@ -167,6 +175,8 @@ func maximizeTheProfit(n int, offers [][]int) int { } ``` +#### TypeScript + ```ts function maximizeTheProfit(n: number, offers: number[][]): number { offers.sort((a, b) => a[1] - b[1]); diff --git a/solution/2800-2899/2831.Find the Longest Equal Subarray/README.md b/solution/2800-2899/2831.Find the Longest Equal Subarray/README.md index f8f4d132f2205..5475d42d547ec 100644 --- a/solution/2800-2899/2831.Find the Longest Equal Subarray/README.md +++ b/solution/2800-2899/2831.Find the Longest Equal Subarray/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def longestEqualSubarray(self, nums: List[int], k: int) -> int: @@ -98,6 +100,8 @@ class Solution: return mx ``` +#### Java + ```java class Solution { public int longestEqualSubarray(List nums, int k) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func longestEqualSubarray(nums []int, k int) int { cnt := map[int]int{} @@ -148,6 +156,8 @@ func longestEqualSubarray(nums []int, k int) int { } ``` +#### TypeScript + ```ts function longestEqualSubarray(nums: number[], k: number): number { const cnt: Map = new Map(); diff --git a/solution/2800-2899/2831.Find the Longest Equal Subarray/README_EN.md b/solution/2800-2899/2831.Find the Longest Equal Subarray/README_EN.md index 535f3a1624d17..63efd02282c4f 100644 --- a/solution/2800-2899/2831.Find the Longest Equal Subarray/README_EN.md +++ b/solution/2800-2899/2831.Find the Longest Equal Subarray/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def longestEqualSubarray(self, nums: List[int], k: int) -> int: @@ -96,6 +98,8 @@ class Solution: return mx ``` +#### Java + ```java class Solution { public int longestEqualSubarray(List nums, int k) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func longestEqualSubarray(nums []int, k int) int { cnt := map[int]int{} @@ -146,6 +154,8 @@ func longestEqualSubarray(nums []int, k int) int { } ``` +#### TypeScript + ```ts function longestEqualSubarray(nums: number[], k: number): number { const cnt: Map = new Map(); diff --git a/solution/2800-2899/2832.Maximal Range That Each Element Is Maximum in It/README.md b/solution/2800-2899/2832.Maximal Range That Each Element Is Maximum in It/README.md index 89dededb2db5b..add8f58079039 100644 --- a/solution/2800-2899/2832.Maximal Range That Each Element Is Maximum in It/README.md +++ b/solution/2800-2899/2832.Maximal Range That Each Element Is Maximum in It/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def maximumLengthOfRanges(self, nums: List[int]) -> List[int]: @@ -99,6 +101,8 @@ class Solution: return [r - l - 1 for l, r in zip(left, right)] ``` +#### Java + ```java class Solution { public int[] maximumLengthOfRanges(int[] nums) { @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go func maximumLengthOfRanges(nums []int) []int { n := len(nums) @@ -210,6 +218,8 @@ func maximumLengthOfRanges(nums []int) []int { } ``` +#### TypeScript + ```ts function maximumLengthOfRanges(nums: number[]): number[] { const n = nums.length; diff --git a/solution/2800-2899/2832.Maximal Range That Each Element Is Maximum in It/README_EN.md b/solution/2800-2899/2832.Maximal Range That Each Element Is Maximum in It/README_EN.md index 28c2320331db8..19903fc34cdb5 100644 --- a/solution/2800-2899/2832.Maximal Range That Each Element Is Maximum in It/README_EN.md +++ b/solution/2800-2899/2832.Maximal Range That Each Element Is Maximum in It/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def maximumLengthOfRanges(self, nums: List[int]) -> List[int]: @@ -97,6 +99,8 @@ class Solution: return [r - l - 1 for l, r in zip(left, right)] ``` +#### Java + ```java class Solution { public int[] maximumLengthOfRanges(int[] nums) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go func maximumLengthOfRanges(nums []int) []int { n := len(nums) @@ -208,6 +216,8 @@ func maximumLengthOfRanges(nums []int) []int { } ``` +#### TypeScript + ```ts function maximumLengthOfRanges(nums: number[]): number[] { const n = nums.length; diff --git a/solution/2800-2899/2833.Furthest Point From Origin/README.md b/solution/2800-2899/2833.Furthest Point From Origin/README.md index 2f4985f043778..55f7923ced34f 100644 --- a/solution/2800-2899/2833.Furthest Point From Origin/README.md +++ b/solution/2800-2899/2833.Furthest Point From Origin/README.md @@ -81,12 +81,16 @@ tags: +#### Python3 + ```python class Solution: def furthestDistanceFromOrigin(self, moves: str) -> int: return abs(moves.count("L") - moves.count("R")) + moves.count("_") ``` +#### Java + ```java class Solution { public int furthestDistanceFromOrigin(String moves) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func furthestDistanceFromOrigin(moves string) int { count := func(c string) int { return strings.Count(moves, c) } @@ -131,6 +139,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function furthestDistanceFromOrigin(moves: string): number { const count = (c: string) => moves.split('').filter(x => x === c).length; diff --git a/solution/2800-2899/2833.Furthest Point From Origin/README_EN.md b/solution/2800-2899/2833.Furthest Point From Origin/README_EN.md index 04728690ebfa9..3f03fb8f092d9 100644 --- a/solution/2800-2899/2833.Furthest Point From Origin/README_EN.md +++ b/solution/2800-2899/2833.Furthest Point From Origin/README_EN.md @@ -79,12 +79,16 @@ The time complexity is $O(n)$, where $n$ is the length of the string. The space +#### Python3 + ```python class Solution: def furthestDistanceFromOrigin(self, moves: str) -> int: return abs(moves.count("L") - moves.count("R")) + moves.count("_") ``` +#### Java + ```java class Solution { public int furthestDistanceFromOrigin(String moves) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func furthestDistanceFromOrigin(moves string) int { count := func(c string) int { return strings.Count(moves, c) } @@ -129,6 +137,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function furthestDistanceFromOrigin(moves: string): number { const count = (c: string) => moves.split('').filter(x => x === c).length; diff --git a/solution/2800-2899/2834.Find the Minimum Possible Sum of a Beautiful Array/README.md b/solution/2800-2899/2834.Find the Minimum Possible Sum of a Beautiful Array/README.md index 973884561d85d..5090f215617ea 100644 --- a/solution/2800-2899/2834.Find the Minimum Possible Sum of a Beautiful Array/README.md +++ b/solution/2800-2899/2834.Find the Minimum Possible Sum of a Beautiful Array/README.md @@ -95,6 +95,8 @@ nums = [1,3,4] 是美丽数组。 +#### Python3 + ```python class Solution: def minimumPossibleSum(self, n: int, target: int) -> int: @@ -105,6 +107,8 @@ class Solution: return ((1 + m) * m // 2 + (target + target + n - m - 1) * (n - m) // 2) % mod ``` +#### Java + ```java class Solution { public int minimumPossibleSum(int n, int target) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func minimumPossibleSum(n int, target int) int { const mod int = 1e9 + 7 @@ -149,6 +157,8 @@ func minimumPossibleSum(n int, target int) int { } ``` +#### TypeScript + ```ts function minimumPossibleSum(n: number, target: number): number { const mod = 10 ** 9 + 7; @@ -160,6 +170,8 @@ function minimumPossibleSum(n: number, target: number): number { } ``` +#### C# + ```cs public class Solution { public int MinimumPossibleSum(int n, int target) { diff --git a/solution/2800-2899/2834.Find the Minimum Possible Sum of a Beautiful Array/README_EN.md b/solution/2800-2899/2834.Find the Minimum Possible Sum of a Beautiful Array/README_EN.md index 16670d7032019..ec3c9a8b551a5 100644 --- a/solution/2800-2899/2834.Find the Minimum Possible Sum of a Beautiful Array/README_EN.md +++ b/solution/2800-2899/2834.Find the Minimum Possible Sum of a Beautiful Array/README_EN.md @@ -94,6 +94,8 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def minimumPossibleSum(self, n: int, target: int) -> int: @@ -104,6 +106,8 @@ class Solution: return ((1 + m) * m // 2 + (target + target + n - m - 1) * (n - m) // 2) % mod ``` +#### Java + ```java class Solution { public int minimumPossibleSum(int n, int target) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func minimumPossibleSum(n int, target int) int { const mod int = 1e9 + 7 @@ -148,6 +156,8 @@ func minimumPossibleSum(n int, target int) int { } ``` +#### TypeScript + ```ts function minimumPossibleSum(n: number, target: number): number { const mod = 10 ** 9 + 7; @@ -159,6 +169,8 @@ function minimumPossibleSum(n: number, target: number): number { } ``` +#### C# + ```cs public class Solution { public int MinimumPossibleSum(int n, int target) { diff --git a/solution/2800-2899/2835.Minimum Operations to Form Subsequence With Target Sum/README.md b/solution/2800-2899/2835.Minimum Operations to Form Subsequence With Target Sum/README.md index f53548b250468..eb38fd637488b 100644 --- a/solution/2800-2899/2835.Minimum Operations to Form Subsequence With Target Sum/README.md +++ b/solution/2800-2899/2835.Minimum Operations to Form Subsequence With Target Sum/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int], target: int) -> int: @@ -127,6 +129,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minOperations(List nums, int target) { @@ -170,6 +174,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -214,6 +220,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int, target int) (ans int) { s := 0 @@ -254,6 +262,8 @@ func minOperations(nums []int, target int) (ans int) { } ``` +#### TypeScript + ```ts function minOperations(nums: number[], target: number): number { let s = 0; diff --git a/solution/2800-2899/2835.Minimum Operations to Form Subsequence With Target Sum/README_EN.md b/solution/2800-2899/2835.Minimum Operations to Form Subsequence With Target Sum/README_EN.md index 0cae103f355a2..74624a611ba07 100644 --- a/solution/2800-2899/2835.Minimum Operations to Form Subsequence With Target Sum/README_EN.md +++ b/solution/2800-2899/2835.Minimum Operations to Form Subsequence With Target Sum/README_EN.md @@ -93,6 +93,8 @@ The time complexity is $O(n \times \log M)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int], target: int) -> int: @@ -125,6 +127,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minOperations(List nums, int target) { @@ -168,6 +172,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -212,6 +218,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int, target int) (ans int) { s := 0 @@ -252,6 +260,8 @@ func minOperations(nums []int, target int) (ans int) { } ``` +#### TypeScript + ```ts function minOperations(nums: number[], target: number): number { let s = 0; diff --git a/solution/2800-2899/2836.Maximize Value of Function in a Ball Passing Game/README.md b/solution/2800-2899/2836.Maximize Value of Function in a Ball Passing Game/README.md index 6b3ab64356b16..eeba94177edca 100644 --- a/solution/2800-2899/2836.Maximize Value of Function in a Ball Passing Game/README.md +++ b/solution/2800-2899/2836.Maximize Value of Function in a Ball Passing Game/README.md @@ -176,6 +176,8 @@ tags: +#### Python3 + ```python class Solution: def getMaxFunctionValue(self, receiver: List[int], k: int) -> int: @@ -200,6 +202,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long getMaxFunctionValue(List receiver, long k) { @@ -233,6 +237,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -267,6 +273,8 @@ public: }; ``` +#### Go + ```go func getMaxFunctionValue(receiver []int, k int64) (ans int64) { n, m := len(receiver), bits.Len(uint(k)) diff --git a/solution/2800-2899/2836.Maximize Value of Function in a Ball Passing Game/README_EN.md b/solution/2800-2899/2836.Maximize Value of Function in a Ball Passing Game/README_EN.md index f57d5b294610f..74370904715ea 100644 --- a/solution/2800-2899/2836.Maximize Value of Function in a Ball Passing Game/README_EN.md +++ b/solution/2800-2899/2836.Maximize Value of Function in a Ball Passing Game/README_EN.md @@ -159,6 +159,8 @@ Similar problems: +#### Python3 + ```python class Solution: def getMaxFunctionValue(self, receiver: List[int], k: int) -> int: @@ -183,6 +185,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long getMaxFunctionValue(List receiver, long k) { @@ -216,6 +220,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -250,6 +256,8 @@ public: }; ``` +#### Go + ```go func getMaxFunctionValue(receiver []int, k int64) (ans int64) { n, m := len(receiver), bits.Len(uint(k)) diff --git a/solution/2800-2899/2837.Total Traveled Distance/README.md b/solution/2800-2899/2837.Total Traveled Distance/README.md index 8f3e33cfcc1a5..cbc7287b37fdf 100644 --- a/solution/2800-2899/2837.Total Traveled Distance/README.md +++ b/solution/2800-2899/2837.Total Traveled Distance/README.md @@ -107,6 +107,8 @@ Rides table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT user_id, name, IFNULL(SUM(distance), 0) AS 'traveled distance' diff --git a/solution/2800-2899/2837.Total Traveled Distance/README_EN.md b/solution/2800-2899/2837.Total Traveled Distance/README_EN.md index f5737fcdf4db7..640fe4c967200 100644 --- a/solution/2800-2899/2837.Total Traveled Distance/README_EN.md +++ b/solution/2800-2899/2837.Total Traveled Distance/README_EN.md @@ -106,6 +106,8 @@ We can use a left join to connect the two tables, and then use group by sum to c +#### MySQL + ```sql # Write your MySQL query statement below SELECT user_id, name, IFNULL(SUM(distance), 0) AS 'traveled distance' diff --git a/solution/2800-2899/2838.Maximum Coins Heroes Can Collect/README.md b/solution/2800-2899/2838.Maximum Coins Heroes Can Collect/README.md index fae8c53fa4beb..1b7eb67290ba8 100644 --- a/solution/2800-2899/2838.Maximum Coins Heroes Can Collect/README.md +++ b/solution/2800-2899/2838.Maximum Coins Heroes Can Collect/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def maximumCoins( @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long[] maximumCoins(int[] heroes, int[] monsters, int[] coins) { @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func maximumCoins(heroes []int, monsters []int, coins []int) (ans []int64) { m := len(monsters) @@ -201,6 +209,8 @@ func maximumCoins(heroes []int, monsters []int, coins []int) (ans []int64) { } ``` +#### TypeScript + ```ts function maximumCoins(heroes: number[], monsters: number[], coins: number[]): number[] { const m = monsters.length; diff --git a/solution/2800-2899/2838.Maximum Coins Heroes Can Collect/README_EN.md b/solution/2800-2899/2838.Maximum Coins Heroes Can Collect/README_EN.md index e3c94ff226e48..729d5d64b6af8 100644 --- a/solution/2800-2899/2838.Maximum Coins Heroes Can Collect/README_EN.md +++ b/solution/2800-2899/2838.Maximum Coins Heroes Can Collect/README_EN.md @@ -89,6 +89,8 @@ The time complexity is $O((m + n) \times \log n)$, and the space complexity is $ +#### Python3 + ```python class Solution: def maximumCoins( @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long[] maximumCoins(int[] heroes, int[] monsters, int[] coins) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -178,6 +184,8 @@ public: }; ``` +#### Go + ```go func maximumCoins(heroes []int, monsters []int, coins []int) (ans []int64) { m := len(monsters) @@ -198,6 +206,8 @@ func maximumCoins(heroes []int, monsters []int, coins []int) (ans []int64) { } ``` +#### TypeScript + ```ts function maximumCoins(heroes: number[], monsters: number[], coins: number[]): number[] { const m = monsters.length; diff --git a/solution/2800-2899/2839.Check if Strings Can be Made Equal With Operations I/README.md b/solution/2800-2899/2839.Check if Strings Can be Made Equal With Operations I/README.md index 5d4f55b7737eb..81202afed756b 100644 --- a/solution/2800-2899/2839.Check if Strings Can be Made Equal With Operations I/README.md +++ b/solution/2800-2899/2839.Check if Strings Can be Made Equal With Operations I/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def canBeEqual(self, s1: str, s2: str) -> bool: @@ -85,6 +87,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public boolean canBeEqual(String s1, String s2) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func canBeEqual(s1 string, s2 string) bool { cnt := [2][26]int{} @@ -138,6 +146,8 @@ func canBeEqual(s1 string, s2 string) bool { } ``` +#### TypeScript + ```ts function canBeEqual(s1: string, s2: string): boolean { const cnt: number[][] = Array.from({ length: 2 }, () => Array.from({ length: 26 }, () => 0)); diff --git a/solution/2800-2899/2839.Check if Strings Can be Made Equal With Operations I/README_EN.md b/solution/2800-2899/2839.Check if Strings Can be Made Equal With Operations I/README_EN.md index 8c6c75e65a209..0439e09b8fc59 100644 --- a/solution/2800-2899/2839.Check if Strings Can be Made Equal With Operations I/README_EN.md +++ b/solution/2800-2899/2839.Check if Strings Can be Made Equal With Operations I/README_EN.md @@ -75,6 +75,8 @@ Similar problems: +#### Python3 + ```python class Solution: def canBeEqual(self, s1: str, s2: str) -> bool: @@ -83,6 +85,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public boolean canBeEqual(String s1, String s2) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func canBeEqual(s1 string, s2 string) bool { cnt := [2][26]int{} @@ -136,6 +144,8 @@ func canBeEqual(s1 string, s2 string) bool { } ``` +#### TypeScript + ```ts function canBeEqual(s1: string, s2: string): boolean { const cnt: number[][] = Array.from({ length: 2 }, () => Array.from({ length: 26 }, () => 0)); diff --git a/solution/2800-2899/2840.Check if Strings Can be Made Equal With Operations II/README.md b/solution/2800-2899/2840.Check if Strings Can be Made Equal With Operations II/README.md index 5dbb4c5d8a0fe..6ce948e754075 100644 --- a/solution/2800-2899/2840.Check if Strings Can be Made Equal With Operations II/README.md +++ b/solution/2800-2899/2840.Check if Strings Can be Made Equal With Operations II/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def checkStrings(self, s1: str, s2: str) -> bool: @@ -93,6 +95,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public boolean checkStrings(String s1, String s2) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func checkStrings(s1 string, s2 string) bool { cnt := [2][26]int{} @@ -146,6 +154,8 @@ func checkStrings(s1 string, s2 string) bool { } ``` +#### TypeScript + ```ts function checkStrings(s1: string, s2: string): boolean { const cnt: number[][] = Array.from({ length: 2 }, () => Array.from({ length: 26 }, () => 0)); diff --git a/solution/2800-2899/2840.Check if Strings Can be Made Equal With Operations II/README_EN.md b/solution/2800-2899/2840.Check if Strings Can be Made Equal With Operations II/README_EN.md index bb87043aeed1f..3bff37e0f6906 100644 --- a/solution/2800-2899/2840.Check if Strings Can be Made Equal With Operations II/README_EN.md +++ b/solution/2800-2899/2840.Check if Strings Can be Made Equal With Operations II/README_EN.md @@ -79,6 +79,8 @@ Similar problems: +#### Python3 + ```python class Solution: def checkStrings(self, s1: str, s2: str) -> bool: @@ -87,6 +89,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public boolean checkStrings(String s1, String s2) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func checkStrings(s1 string, s2 string) bool { cnt := [2][26]int{} @@ -140,6 +148,8 @@ func checkStrings(s1 string, s2 string) bool { } ``` +#### TypeScript + ```ts function checkStrings(s1: string, s2: string): boolean { const cnt: number[][] = Array.from({ length: 2 }, () => Array.from({ length: 26 }, () => 0)); diff --git a/solution/2800-2899/2841.Maximum Sum of Almost Unique Subarray/README.md b/solution/2800-2899/2841.Maximum Sum of Almost Unique Subarray/README.md index 3d77957e9fd63..ff112a07cbafc 100644 --- a/solution/2800-2899/2841.Maximum Sum of Almost Unique Subarray/README.md +++ b/solution/2800-2899/2841.Maximum Sum of Almost Unique Subarray/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def maxSum(self, nums: List[int], m: int, k: int) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maxSum(List nums, int m, int k) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func maxSum(nums []int, m int, k int) int64 { cnt := map[int]int{} @@ -177,6 +185,8 @@ func maxSum(nums []int, m int, k int) int64 { } ``` +#### TypeScript + ```ts function maxSum(nums: number[], m: number, k: number): number { const n = nums.length; @@ -202,6 +212,8 @@ function maxSum(nums: number[], m: number, k: number): number { } ``` +#### C# + ```cs public class Solution { public long MaxSum(IList nums, int m, int k) { diff --git a/solution/2800-2899/2841.Maximum Sum of Almost Unique Subarray/README_EN.md b/solution/2800-2899/2841.Maximum Sum of Almost Unique Subarray/README_EN.md index 4d8fb9d6284e5..faf67c341e9f4 100644 --- a/solution/2800-2899/2841.Maximum Sum of Almost Unique Subarray/README_EN.md +++ b/solution/2800-2899/2841.Maximum Sum of Almost Unique Subarray/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n)$, and the space complexity is $O(k)$. Here, $n$ is +#### Python3 + ```python class Solution: def maxSum(self, nums: List[int], m: int, k: int) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maxSum(List nums, int m, int k) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func maxSum(nums []int, m int, k int) int64 { cnt := map[int]int{} @@ -175,6 +183,8 @@ func maxSum(nums []int, m int, k int) int64 { } ``` +#### TypeScript + ```ts function maxSum(nums: number[], m: number, k: number): number { const n = nums.length; @@ -200,6 +210,8 @@ function maxSum(nums: number[], m: number, k: number): number { } ``` +#### C# + ```cs public class Solution { public long MaxSum(IList nums, int m, int k) { diff --git a/solution/2800-2899/2842.Count K-Subsequences of a String With Maximum Beauty/README.md b/solution/2800-2899/2842.Count K-Subsequences of a String With Maximum Beauty/README.md index 30da1a957f9d4..2158c6a945d68 100644 --- a/solution/2800-2899/2842.Count K-Subsequences of a String With Maximum Beauty/README.md +++ b/solution/2800-2899/2842.Count K-Subsequences of a String With Maximum Beauty/README.md @@ -119,6 +119,8 @@ s 的 k 子序列为: +#### Python3 + ```python class Solution: def countKSubsequencesWithMaxBeauty(self, s: str, k: int) -> int: @@ -139,6 +141,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private final int mod = (int) 1e9 + 7; @@ -201,6 +205,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -260,6 +266,8 @@ public: }; ``` +#### Go + ```go func countKSubsequencesWithMaxBeauty(s string, k int) int { f := [26]int{} @@ -321,6 +329,8 @@ func countKSubsequencesWithMaxBeauty(s string, k int) int { } ``` +#### TypeScript + ```ts function countKSubsequencesWithMaxBeauty(s: string, k: number): number { const f: number[] = new Array(26).fill(0); diff --git a/solution/2800-2899/2842.Count K-Subsequences of a String With Maximum Beauty/README_EN.md b/solution/2800-2899/2842.Count K-Subsequences of a String With Maximum Beauty/README_EN.md index ec0790dd065fa..133e5c455e929 100644 --- a/solution/2800-2899/2842.Count K-Subsequences of a String With Maximum Beauty/README_EN.md +++ b/solution/2800-2899/2842.Count K-Subsequences of a String With Maximum Beauty/README_EN.md @@ -117,6 +117,8 @@ The time complexity is $O(n)$, and the space complexity is $O(|\Sigma|)$. Here, +#### Python3 + ```python class Solution: def countKSubsequencesWithMaxBeauty(self, s: str, k: int) -> int: @@ -137,6 +139,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private final int mod = (int) 1e9 + 7; @@ -199,6 +203,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -258,6 +264,8 @@ public: }; ``` +#### Go + ```go func countKSubsequencesWithMaxBeauty(s string, k int) int { f := [26]int{} @@ -319,6 +327,8 @@ func countKSubsequencesWithMaxBeauty(s string, k int) int { } ``` +#### TypeScript + ```ts function countKSubsequencesWithMaxBeauty(s: string, k: number): number { const f: number[] = new Array(26).fill(0); diff --git a/solution/2800-2899/2843.Count Symmetric Integers/README.md b/solution/2800-2899/2843.Count Symmetric Integers/README.md index 718401d23cb06..d494fdf7e0db9 100644 --- a/solution/2800-2899/2843.Count Symmetric Integers/README.md +++ b/solution/2800-2899/2843.Count Symmetric Integers/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def countSymmetricIntegers(self, low: int, high: int) -> int: @@ -78,6 +80,8 @@ class Solution: return sum(f(x) for x in range(low, high + 1)) ``` +#### Java + ```java class Solution { public int countSymmetricIntegers(int low, int high) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func countSymmetricIntegers(low int, high int) (ans int) { f := func(x int) int { @@ -157,6 +165,8 @@ func countSymmetricIntegers(low int, high int) (ans int) { } ``` +#### TypeScript + ```ts function countSymmetricIntegers(low: number, high: number): number { let ans = 0; diff --git a/solution/2800-2899/2843.Count Symmetric Integers/README_EN.md b/solution/2800-2899/2843.Count Symmetric Integers/README_EN.md index 7a4c9d3f08e0c..e7b42f59c891c 100644 --- a/solution/2800-2899/2843.Count Symmetric Integers/README_EN.md +++ b/solution/2800-2899/2843.Count Symmetric Integers/README_EN.md @@ -63,6 +63,8 @@ The time complexity is $O(n \times \log m)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def countSymmetricIntegers(self, low: int, high: int) -> int: @@ -76,6 +78,8 @@ class Solution: return sum(f(x) for x in range(low, high + 1)) ``` +#### Java + ```java class Solution { public int countSymmetricIntegers(int low, int high) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func countSymmetricIntegers(low int, high int) (ans int) { f := func(x int) int { @@ -155,6 +163,8 @@ func countSymmetricIntegers(low int, high int) (ans int) { } ``` +#### TypeScript + ```ts function countSymmetricIntegers(low: number, high: number): number { let ans = 0; diff --git a/solution/2800-2899/2844.Minimum Operations to Make a Special Number/README.md b/solution/2800-2899/2844.Minimum Operations to Make a Special Number/README.md index 85836e63ffa07..3634817955d0a 100644 --- a/solution/2800-2899/2844.Minimum Operations to Make a Special Number/README.md +++ b/solution/2800-2899/2844.Minimum Operations to Make a Special Number/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def minimumOperations(self, num: str) -> int: @@ -104,6 +106,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private Integer[][] f; @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func minimumOperations(num string) int { n := len(num) @@ -182,6 +190,8 @@ func minimumOperations(num string) int { } ``` +#### TypeScript + ```ts function minimumOperations(num: string): number { const n = num.length; diff --git a/solution/2800-2899/2844.Minimum Operations to Make a Special Number/README_EN.md b/solution/2800-2899/2844.Minimum Operations to Make a Special Number/README_EN.md index 9efdd7936bcf4..de2bc8aaa4061 100644 --- a/solution/2800-2899/2844.Minimum Operations to Make a Special Number/README_EN.md +++ b/solution/2800-2899/2844.Minimum Operations to Make a Special Number/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(n \times 25)$, and the space complexity is $O(n \times +#### Python3 + ```python class Solution: def minimumOperations(self, num: str) -> int: @@ -101,6 +103,8 @@ class Solution: return dfs(0, 0) ``` +#### Java + ```java class Solution { private Integer[][] f; @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func minimumOperations(num string) int { n := len(num) @@ -179,6 +187,8 @@ func minimumOperations(num string) int { } ``` +#### TypeScript + ```ts function minimumOperations(num: string): number { const n = num.length; diff --git a/solution/2800-2899/2845.Count of Interesting Subarrays/README.md b/solution/2800-2899/2845.Count of Interesting Subarrays/README.md index d12ceb50b25f4..0935acfe76c62 100644 --- a/solution/2800-2899/2845.Count of Interesting Subarrays/README.md +++ b/solution/2800-2899/2845.Count of Interesting Subarrays/README.md @@ -100,6 +100,8 @@ tags: +#### Python3 + ```python class Solution: def countInterestingSubarrays(self, nums: List[int], modulo: int, k: int) -> int: @@ -114,6 +116,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long countInterestingSubarrays(List nums, int modulo, int k) { @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func countInterestingSubarrays(nums []int, modulo int, k int) (ans int64) { arr := make([]int, len(nums)) @@ -179,6 +187,8 @@ func countInterestingSubarrays(nums []int, modulo int, k int) (ans int64) { } ``` +#### TypeScript + ```ts function countInterestingSubarrays(nums: number[], modulo: number, k: number): number { const arr: number[] = []; diff --git a/solution/2800-2899/2845.Count of Interesting Subarrays/README_EN.md b/solution/2800-2899/2845.Count of Interesting Subarrays/README_EN.md index 952e36e5eff42..043784d59ce20 100644 --- a/solution/2800-2899/2845.Count of Interesting Subarrays/README_EN.md +++ b/solution/2800-2899/2845.Count of Interesting Subarrays/README_EN.md @@ -98,6 +98,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def countInterestingSubarrays(self, nums: List[int], modulo: int, k: int) -> int: @@ -112,6 +114,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long countInterestingSubarrays(List nums, int modulo, int k) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func countInterestingSubarrays(nums []int, modulo int, k int) (ans int64) { arr := make([]int, len(nums)) @@ -177,6 +185,8 @@ func countInterestingSubarrays(nums []int, modulo int, k int) (ans int64) { } ``` +#### TypeScript + ```ts function countInterestingSubarrays(nums: number[], modulo: number, k: number): number { const arr: number[] = []; diff --git a/solution/2800-2899/2846.Minimum Edge Weight Equilibrium Queries in a Tree/README.md b/solution/2800-2899/2846.Minimum Edge Weight Equilibrium Queries in a Tree/README.md index 5796de4a79cba..4728e2ccdaf6c 100644 --- a/solution/2800-2899/2846.Minimum Edge Weight Equilibrium Queries in a Tree/README.md +++ b/solution/2800-2899/2846.Minimum Edge Weight Equilibrium Queries in a Tree/README.md @@ -104,6 +104,8 @@ tags: +#### Python3 + ```python class Solution: def minOperationsQueries( @@ -150,6 +152,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] minOperationsQueries(int n, int[][] edges, int[][] queries) { @@ -220,6 +224,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -290,6 +296,8 @@ public: }; ``` +#### Go + ```go func minOperationsQueries(n int, edges [][]int, queries [][]int) []int { m := bits.Len(uint(n)) diff --git a/solution/2800-2899/2846.Minimum Edge Weight Equilibrium Queries in a Tree/README_EN.md b/solution/2800-2899/2846.Minimum Edge Weight Equilibrium Queries in a Tree/README_EN.md index 4a77f34c41bb1..2130f2f63d5a3 100644 --- a/solution/2800-2899/2846.Minimum Edge Weight Equilibrium Queries in a Tree/README_EN.md +++ b/solution/2800-2899/2846.Minimum Edge Weight Equilibrium Queries in a Tree/README_EN.md @@ -102,6 +102,8 @@ The time complexity is $O((n + q) \times C \times \log n)$, and the space comple +#### Python3 + ```python class Solution: def minOperationsQueries( @@ -148,6 +150,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] minOperationsQueries(int n, int[][] edges, int[][] queries) { @@ -218,6 +222,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -288,6 +294,8 @@ public: }; ``` +#### Go + ```go func minOperationsQueries(n int, edges [][]int, queries [][]int) []int { m := bits.Len(uint(n)) diff --git a/solution/2800-2899/2847.Smallest Number With Given Digit Product/README.md b/solution/2800-2899/2847.Smallest Number With Given Digit Product/README.md index e9dc524148a1f..895f2aa154e30 100644 --- a/solution/2800-2899/2847.Smallest Number With Given Digit Product/README.md +++ b/solution/2800-2899/2847.Smallest Number With Given Digit Product/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def smallestNumber(self, n: int) -> str: @@ -83,6 +85,8 @@ class Solution: return ans if ans else "1" ``` +#### Java + ```java class Solution { public String smallestNumber(long n) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func smallestNumber(n int64) string { cnt := [10]int{} diff --git a/solution/2800-2899/2847.Smallest Number With Given Digit Product/README_EN.md b/solution/2800-2899/2847.Smallest Number With Given Digit Product/README_EN.md index 24b0c69f24eb0..d342b59a83419 100644 --- a/solution/2800-2899/2847.Smallest Number With Given Digit Product/README_EN.md +++ b/solution/2800-2899/2847.Smallest Number With Given Digit Product/README_EN.md @@ -67,6 +67,8 @@ The time complexity is $O(\log n)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def smallestNumber(self, n: int) -> str: @@ -81,6 +83,8 @@ class Solution: return ans if ans else "1" ``` +#### Java + ```java class Solution { public String smallestNumber(long n) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func smallestNumber(n int64) string { cnt := [10]int{} diff --git a/solution/2800-2899/2848.Points That Intersect With Cars/README.md b/solution/2800-2899/2848.Points That Intersect With Cars/README.md index 2e6f65147b3eb..91b4505bda382 100644 --- a/solution/2800-2899/2848.Points That Intersect With Cars/README.md +++ b/solution/2800-2899/2848.Points That Intersect With Cars/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfPoints(self, nums: List[List[int]]) -> int: @@ -76,6 +78,8 @@ class Solution: return sum(s > 0 for s in accumulate(d)) ``` +#### Java + ```java class Solution { public int numberOfPoints(List> nums) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func numberOfPoints(nums [][]int) (ans int) { d := [110]int{} @@ -133,6 +141,8 @@ func numberOfPoints(nums [][]int) (ans int) { } ``` +#### TypeScript + ```ts function numberOfPoints(nums: number[][]): number { const d: number[] = Array(110).fill(0); diff --git a/solution/2800-2899/2848.Points That Intersect With Cars/README_EN.md b/solution/2800-2899/2848.Points That Intersect With Cars/README_EN.md index 278e26d2a190a..99356bce138a6 100644 --- a/solution/2800-2899/2848.Points That Intersect With Cars/README_EN.md +++ b/solution/2800-2899/2848.Points That Intersect With Cars/README_EN.md @@ -64,6 +64,8 @@ The time complexity is $O(n)$, and the space complexity is $O(M)$. Here, $n$ is +#### Python3 + ```python class Solution: def numberOfPoints(self, nums: List[List[int]]) -> int: @@ -74,6 +76,8 @@ class Solution: return sum(s > 0 for s in accumulate(d)) ``` +#### Java + ```java class Solution { public int numberOfPoints(List> nums) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func numberOfPoints(nums [][]int) (ans int) { d := [110]int{} @@ -131,6 +139,8 @@ func numberOfPoints(nums [][]int) (ans int) { } ``` +#### TypeScript + ```ts function numberOfPoints(nums: number[][]): number { const d: number[] = Array(110).fill(0); diff --git a/solution/2800-2899/2849.Determine if a Cell Is Reachable at a Given Time/README.md b/solution/2800-2899/2849.Determine if a Cell Is Reachable at a Given Time/README.md index 4901ce4863fc6..d23ab089fe8ee 100644 --- a/solution/2800-2899/2849.Determine if a Cell Is Reachable at a Given Time/README.md +++ b/solution/2800-2899/2849.Determine if a Cell Is Reachable at a Given Time/README.md @@ -63,6 +63,8 @@ tags: +#### Python3 + ```python class Solution: def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool: @@ -73,6 +75,8 @@ class Solution: return max(dx, dy) <= t ``` +#### Java + ```java class Solution { public boolean isReachableAtTime(int sx, int sy, int fx, int fy, int t) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -99,6 +105,8 @@ public: }; ``` +#### Go + ```go func isReachableAtTime(sx int, sy int, fx int, fy int, t int) bool { if sx == fx && sy == fy { @@ -117,6 +125,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function isReachableAtTime(sx: number, sy: number, fx: number, fy: number, t: number): boolean { if (sx === fx && sy === fy) { @@ -128,6 +138,8 @@ function isReachableAtTime(sx: number, sy: number, fx: number, fy: number, t: nu } ``` +#### C# + ```cs public class Solution { public bool IsReachableAtTime(int sx, int sy, int fx, int fy, int t) { diff --git a/solution/2800-2899/2849.Determine if a Cell Is Reachable at a Given Time/README_EN.md b/solution/2800-2899/2849.Determine if a Cell Is Reachable at a Given Time/README_EN.md index 4b7cdd7aeabaf..2db4ad1b539c7 100644 --- a/solution/2800-2899/2849.Determine if a Cell Is Reachable at a Given Time/README_EN.md +++ b/solution/2800-2899/2849.Determine if a Cell Is Reachable at a Given Time/README_EN.md @@ -61,6 +61,8 @@ tags: +#### Python3 + ```python class Solution: def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool: @@ -71,6 +73,8 @@ class Solution: return max(dx, dy) <= t ``` +#### Java + ```java class Solution { public boolean isReachableAtTime(int sx, int sy, int fx, int fy, int t) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -97,6 +103,8 @@ public: }; ``` +#### Go + ```go func isReachableAtTime(sx int, sy int, fx int, fy int, t int) bool { if sx == fx && sy == fy { @@ -115,6 +123,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function isReachableAtTime(sx: number, sy: number, fx: number, fy: number, t: number): boolean { if (sx === fx && sy === fy) { @@ -126,6 +136,8 @@ function isReachableAtTime(sx: number, sy: number, fx: number, fy: number, t: nu } ``` +#### C# + ```cs public class Solution { public bool IsReachableAtTime(int sx, int sy, int fx, int fy, int t) { diff --git a/solution/2800-2899/2850.Minimum Moves to Spread Stones Over Grid/README.md b/solution/2800-2899/2850.Minimum Moves to Spread Stones Over Grid/README.md index 199053c7a2c5a..0ee00e17913b1 100644 --- a/solution/2800-2899/2850.Minimum Moves to Spread Stones Over Grid/README.md +++ b/solution/2800-2899/2850.Minimum Moves to Spread Stones Over Grid/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def minimumMoves(self, grid: List[List[int]]) -> int: @@ -110,6 +112,8 @@ class Solution: ans += 1 ``` +#### Java + ```java class Solution { public int minimumMoves(int[][] grid) { @@ -176,6 +180,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -213,6 +219,8 @@ public: }; ``` +#### Go + ```go func minimumMoves(grid [][]int) int { left := [][2]int{} @@ -254,6 +262,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function minimumMoves(grid: number[][]): number { const left: number[][] = []; @@ -310,6 +320,8 @@ function minimumMoves(grid: number[][]): number { +#### Python3 + ```python class Solution: def minimumMoves(self, grid: List[List[int]]) -> int: @@ -336,6 +348,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int minimumMoves(int[][] grid) { diff --git a/solution/2800-2899/2850.Minimum Moves to Spread Stones Over Grid/README_EN.md b/solution/2800-2899/2850.Minimum Moves to Spread Stones Over Grid/README_EN.md index 0bfe1d93a5da2..ed438d555fb94 100644 --- a/solution/2800-2899/2850.Minimum Moves to Spread Stones Over Grid/README_EN.md +++ b/solution/2800-2899/2850.Minimum Moves to Spread Stones Over Grid/README_EN.md @@ -76,6 +76,8 @@ The problem is essentially finding the shortest path from the initial state to t +#### Python3 + ```python class Solution: def minimumMoves(self, grid: List[List[int]]) -> int: @@ -104,6 +106,8 @@ class Solution: ans += 1 ``` +#### Java + ```java class Solution { public int minimumMoves(int[][] grid) { @@ -170,6 +174,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -207,6 +213,8 @@ public: }; ``` +#### Go + ```go func minimumMoves(grid [][]int) int { left := [][2]int{} @@ -248,6 +256,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function minimumMoves(grid: number[][]): number { const left: number[][] = []; @@ -304,6 +314,8 @@ The time complexity is $O(n \times 2^n)$, and the space complexity is $O(2^n)$. +#### Python3 + ```python class Solution: def minimumMoves(self, grid: List[List[int]]) -> int: @@ -330,6 +342,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int minimumMoves(int[][] grid) { diff --git a/solution/2800-2899/2851.String Transformation/README.md b/solution/2800-2899/2851.String Transformation/README.md index 58e96c1b32e5c..add46e484b8f6 100644 --- a/solution/2800-2899/2851.String Transformation/README.md +++ b/solution/2800-2899/2851.String Transformation/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python """ DP, Z-algorithm, Fast mod. @@ -186,6 +188,8 @@ class Solution: return result ``` +#### Java + ```java class Solution { private static final int M = 1000000007; @@ -272,6 +276,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { const int M = 1000000007; diff --git a/solution/2800-2899/2851.String Transformation/README_EN.md b/solution/2800-2899/2851.String Transformation/README_EN.md index 6f2270a4bc201..c2d264ade939d 100644 --- a/solution/2800-2899/2851.String Transformation/README_EN.md +++ b/solution/2800-2899/2851.String Transformation/README_EN.md @@ -81,6 +81,8 @@ Choose suffix from index = 4, so resulting s = "ababab". +#### Python3 + ```python """ DP, Z-algorithm, Fast mod. @@ -184,6 +186,8 @@ class Solution: return result ``` +#### Java + ```java class Solution { private static final int M = 1000000007; @@ -270,6 +274,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { const int M = 1000000007; diff --git a/solution/2800-2899/2852.Sum of Remoteness of All Cells/README.md b/solution/2800-2899/2852.Sum of Remoteness of All Cells/README.md index add924739ae36..675a820223870 100644 --- a/solution/2800-2899/2852.Sum of Remoteness of All Cells/README.md +++ b/solution/2800-2899/2852.Sum of Remoteness of All Cells/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def sumRemoteness(self, grid: List[List[int]]) -> int: @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -162,6 +166,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -203,6 +209,8 @@ public: }; ``` +#### Go + ```go func sumRemoteness(grid [][]int) (ans int64) { n := len(grid) @@ -241,6 +249,8 @@ func sumRemoteness(grid [][]int) (ans int64) { } ``` +#### TypeScript + ```ts function sumRemoteness(grid: number[][]): number { const n = grid.length; diff --git a/solution/2800-2899/2852.Sum of Remoteness of All Cells/README_EN.md b/solution/2800-2899/2852.Sum of Remoteness of All Cells/README_EN.md index 56ef6a2f0209c..f73d388e39a54 100644 --- a/solution/2800-2899/2852.Sum of Remoteness of All Cells/README_EN.md +++ b/solution/2800-2899/2852.Sum of Remoteness of All Cells/README_EN.md @@ -88,6 +88,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$. Here, $n$ +#### Python3 + ```python class Solution: def sumRemoteness(self, grid: List[List[int]]) -> int: @@ -113,6 +115,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int n; @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -201,6 +207,8 @@ public: }; ``` +#### Go + ```go func sumRemoteness(grid [][]int) (ans int64) { n := len(grid) @@ -239,6 +247,8 @@ func sumRemoteness(grid [][]int) (ans int64) { } ``` +#### TypeScript + ```ts function sumRemoteness(grid: number[][]): number { const n = grid.length; diff --git a/solution/2800-2899/2853.Highest Salaries Difference/README.md b/solution/2800-2899/2853.Highest Salaries Difference/README.md index 82c5908c23bfc..b6e4f96581dc3 100644 --- a/solution/2800-2899/2853.Highest Salaries Difference/README.md +++ b/solution/2800-2899/2853.Highest Salaries Difference/README.md @@ -79,6 +79,8 @@ Salaries table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT MAX(s) - MIN(s) AS salary_difference diff --git a/solution/2800-2899/2853.Highest Salaries Difference/README_EN.md b/solution/2800-2899/2853.Highest Salaries Difference/README_EN.md index fe32205033cd7..e10bf26e4b94f 100644 --- a/solution/2800-2899/2853.Highest Salaries Difference/README_EN.md +++ b/solution/2800-2899/2853.Highest Salaries Difference/README_EN.md @@ -78,6 +78,8 @@ We can first calculate the highest salary for each department, and then calculat +#### MySQL + ```sql # Write your MySQL query statement below SELECT MAX(s) - MIN(s) AS salary_difference diff --git a/solution/2800-2899/2854.Rolling Average Steps/README.md b/solution/2800-2899/2854.Rolling Average Steps/README.md index 30c5ea8e25352..285bc2dbab7bf 100644 --- a/solution/2800-2899/2854.Rolling Average Steps/README.md +++ b/solution/2800-2899/2854.Rolling Average Steps/README.md @@ -102,6 +102,8 @@ Steps table: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2800-2899/2854.Rolling Average Steps/README_EN.md b/solution/2800-2899/2854.Rolling Average Steps/README_EN.md index 2cb8e8d44e494..4abc281615b3a 100644 --- a/solution/2800-2899/2854.Rolling Average Steps/README_EN.md +++ b/solution/2800-2899/2854.Rolling Average Steps/README_EN.md @@ -101,6 +101,8 @@ We can use the window function `LAG() OVER()` to calculate the difference in day +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2800-2899/2855.Minimum Right Shifts to Sort the Array/README.md b/solution/2800-2899/2855.Minimum Right Shifts to Sort the Array/README.md index cafa2b01f1ca0..1332fef1a3466 100644 --- a/solution/2800-2899/2855.Minimum Right Shifts to Sort the Array/README.md +++ b/solution/2800-2899/2855.Minimum Right Shifts to Sort the Array/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def minimumRightShifts(self, nums: List[int]) -> int: @@ -87,6 +89,8 @@ class Solution: return -1 if k < n else n - i ``` +#### Java + ```java class Solution { public int minimumRightShifts(List nums) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func minimumRightShifts(nums []int) int { n := len(nums) @@ -140,6 +148,8 @@ func minimumRightShifts(nums []int) int { } ``` +#### TypeScript + ```ts function minimumRightShifts(nums: number[]): number { const n = nums.length; diff --git a/solution/2800-2899/2855.Minimum Right Shifts to Sort the Array/README_EN.md b/solution/2800-2899/2855.Minimum Right Shifts to Sort the Array/README_EN.md index 1eb8730073160..a5b30cc7ae411 100644 --- a/solution/2800-2899/2855.Minimum Right Shifts to Sort the Array/README_EN.md +++ b/solution/2800-2899/2855.Minimum Right Shifts to Sort the Array/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is +#### Python3 + ```python class Solution: def minimumRightShifts(self, nums: List[int]) -> int: @@ -85,6 +87,8 @@ class Solution: return -1 if k < n else n - i ``` +#### Java + ```java class Solution { public int minimumRightShifts(List nums) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func minimumRightShifts(nums []int) int { n := len(nums) @@ -138,6 +146,8 @@ func minimumRightShifts(nums []int) int { } ``` +#### TypeScript + ```ts function minimumRightShifts(nums: number[]): number { const n = nums.length; diff --git a/solution/2800-2899/2856.Minimum Array Length After Pair Removals/README.md b/solution/2800-2899/2856.Minimum Array Length After Pair Removals/README.md index f7077b59b4316..8faf6a472558f 100644 --- a/solution/2800-2899/2856.Minimum Array Length After Pair Removals/README.md +++ b/solution/2800-2899/2856.Minimum Array Length After Pair Removals/README.md @@ -99,6 +99,8 @@ tags: +#### Python3 + ```python class Solution: def minLengthAfterRemovals(self, nums: List[int]) -> int: @@ -118,6 +120,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minLengthAfterRemovals(List nums) { @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func minLengthAfterRemovals(nums []int) int { cnt := map[int]int{} @@ -219,6 +227,8 @@ func (h *hp) push(v int) { heap.Push(h, v) } func (h *hp) pop() int { return heap.Pop(h).(int) } ``` +#### TypeScript + ```ts function minLengthAfterRemovals(nums: number[]): number { const cnt: Map = new Map(); diff --git a/solution/2800-2899/2856.Minimum Array Length After Pair Removals/README_EN.md b/solution/2800-2899/2856.Minimum Array Length After Pair Removals/README_EN.md index 144162ee6d01e..c2a62647a185c 100644 --- a/solution/2800-2899/2856.Minimum Array Length After Pair Removals/README_EN.md +++ b/solution/2800-2899/2856.Minimum Array Length After Pair Removals/README_EN.md @@ -97,6 +97,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def minLengthAfterRemovals(self, nums: List[int]) -> int: @@ -116,6 +118,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minLengthAfterRemovals(List nums) { @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -179,6 +185,8 @@ public: }; ``` +#### Go + ```go func minLengthAfterRemovals(nums []int) int { cnt := map[int]int{} @@ -217,6 +225,8 @@ func (h *hp) push(v int) { heap.Push(h, v) } func (h *hp) pop() int { return heap.Pop(h).(int) } ``` +#### TypeScript + ```ts function minLengthAfterRemovals(nums: number[]): number { const cnt: Map = new Map(); diff --git a/solution/2800-2899/2857.Count Pairs of Points With Distance k/README.md b/solution/2800-2899/2857.Count Pairs of Points With Distance k/README.md index 95732c9f21f2a..e2ea73d2e799c 100644 --- a/solution/2800-2899/2857.Count Pairs of Points With Distance k/README.md +++ b/solution/2800-2899/2857.Count Pairs of Points With Distance k/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def countPairs(self, coordinates: List[List[int]], k: int) -> int: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countPairs(List> coordinates, int k) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func countPairs(coordinates [][]int, k int) (ans int) { cnt := map[[2]int]int{} @@ -141,6 +149,8 @@ func countPairs(coordinates [][]int, k int) (ans int) { } ``` +#### TypeScript + ```ts function countPairs(coordinates: number[][], k: number): number { const cnt: Map = new Map(); @@ -168,6 +178,8 @@ function countPairs(coordinates: number[][], k: number): number { +#### C++ + ```cpp class Solution { public: diff --git a/solution/2800-2899/2857.Count Pairs of Points With Distance k/README_EN.md b/solution/2800-2899/2857.Count Pairs of Points With Distance k/README_EN.md index 8fc2eb56a0734..7d2879f80d177 100644 --- a/solution/2800-2899/2857.Count Pairs of Points With Distance k/README_EN.md +++ b/solution/2800-2899/2857.Count Pairs of Points With Distance k/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n \times k)$, and the space complexity is $O(n)$. Here +#### Python3 + ```python class Solution: def countPairs(self, coordinates: List[List[int]], k: int) -> int: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countPairs(List> coordinates, int k) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func countPairs(coordinates [][]int, k int) (ans int) { cnt := map[[2]int]int{} @@ -139,6 +147,8 @@ func countPairs(coordinates [][]int, k int) (ans int) { } ``` +#### TypeScript + ```ts function countPairs(coordinates: number[][], k: number): number { const cnt: Map = new Map(); @@ -166,6 +176,8 @@ function countPairs(coordinates: number[][], k: number): number { +#### C++ + ```cpp class Solution { public: diff --git a/solution/2800-2899/2858.Minimum Edge Reversals So Every Node Is Reachable/README.md b/solution/2800-2899/2858.Minimum Edge Reversals So Every Node Is Reachable/README.md index f296ad31a66d4..3a7144b625644 100644 --- a/solution/2800-2899/2858.Minimum Edge Reversals So Every Node Is Reachable/README.md +++ b/solution/2800-2899/2858.Minimum Edge Reversals So Every Node Is Reachable/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def minEdgeReversals(self, n: int, edges: List[List[int]]) -> List[int]: @@ -120,6 +122,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -161,6 +165,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -195,6 +201,8 @@ public: }; ``` +#### Go + ```go func minEdgeReversals(n int, edges [][]int) []int { g := make([][][2]int, n) @@ -232,6 +240,8 @@ func minEdgeReversals(n int, edges [][]int) []int { } ``` +#### TypeScript + ```ts function minEdgeReversals(n: number, edges: number[][]): number[] { const g: number[][][] = Array.from({ length: n }, () => []); diff --git a/solution/2800-2899/2858.Minimum Edge Reversals So Every Node Is Reachable/README_EN.md b/solution/2800-2899/2858.Minimum Edge Reversals So Every Node Is Reachable/README_EN.md index 12e19e0dd8ebe..dedfc98faf3c1 100644 --- a/solution/2800-2899/2858.Minimum Edge Reversals So Every Node Is Reachable/README_EN.md +++ b/solution/2800-2899/2858.Minimum Edge Reversals So Every Node Is Reachable/README_EN.md @@ -89,6 +89,8 @@ So, answer[2] = 1. +#### Python3 + ```python class Solution: def minEdgeReversals(self, n: int, edges: List[List[int]]) -> List[int]: @@ -116,6 +118,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -157,6 +161,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -191,6 +197,8 @@ public: }; ``` +#### Go + ```go func minEdgeReversals(n int, edges [][]int) []int { g := make([][][2]int, n) @@ -228,6 +236,8 @@ func minEdgeReversals(n int, edges [][]int) []int { } ``` +#### TypeScript + ```ts function minEdgeReversals(n: number, edges: number[][]): number[] { const g: number[][][] = Array.from({ length: n }, () => []); diff --git a/solution/2800-2899/2859.Sum of Values at Indices With K Set Bits/README.md b/solution/2800-2899/2859.Sum of Values at Indices With K Set Bits/README.md index 76205d21f3fa2..ae72b0f738a3e 100644 --- a/solution/2800-2899/2859.Sum of Values at Indices With K Set Bits/README.md +++ b/solution/2800-2899/2859.Sum of Values at Indices With K Set Bits/README.md @@ -83,12 +83,16 @@ tags: +#### Python3 + ```python class Solution: def sumIndicesWithKSetBits(self, nums: List[int], k: int) -> int: return sum(x for i, x in enumerate(nums) if i.bit_count() == k) ``` +#### Java + ```java class Solution { public int sumIndicesWithKSetBits(List nums, int k) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func sumIndicesWithKSetBits(nums []int, k int) (ans int) { for i, x := range nums { @@ -129,6 +137,8 @@ func sumIndicesWithKSetBits(nums []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function sumIndicesWithKSetBits(nums: number[], k: number): number { let ans = 0; diff --git a/solution/2800-2899/2859.Sum of Values at Indices With K Set Bits/README_EN.md b/solution/2800-2899/2859.Sum of Values at Indices With K Set Bits/README_EN.md index a259c645c97fc..ef790ea563758 100644 --- a/solution/2800-2899/2859.Sum of Values at Indices With K Set Bits/README_EN.md +++ b/solution/2800-2899/2859.Sum of Values at Indices With K Set Bits/README_EN.md @@ -83,12 +83,16 @@ The time complexity is $O(n \times \log n)$, where $n$ is the length of the arra +#### Python3 + ```python class Solution: def sumIndicesWithKSetBits(self, nums: List[int], k: int) -> int: return sum(x for i, x in enumerate(nums) if i.bit_count() == k) ``` +#### Java + ```java class Solution { public int sumIndicesWithKSetBits(List nums, int k) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func sumIndicesWithKSetBits(nums []int, k int) (ans int) { for i, x := range nums { @@ -129,6 +137,8 @@ func sumIndicesWithKSetBits(nums []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function sumIndicesWithKSetBits(nums: number[], k: number): number { let ans = 0; diff --git a/solution/2800-2899/2860.Happy Students/README.md b/solution/2800-2899/2860.Happy Students/README.md index a8ffe2ca18e45..10c6d5480b071 100644 --- a/solution/2800-2899/2860.Happy Students/README.md +++ b/solution/2800-2899/2860.Happy Students/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def countWays(self, nums: List[int]) -> int: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countWays(List nums) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func countWays(nums []int) (ans int) { sort.Ints(nums) @@ -152,6 +160,8 @@ func countWays(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function countWays(nums: number[]): number { nums.sort((a, b) => a - b); diff --git a/solution/2800-2899/2860.Happy Students/README_EN.md b/solution/2800-2899/2860.Happy Students/README_EN.md index cbf00b66dcc6f..1e91136df7353 100644 --- a/solution/2800-2899/2860.Happy Students/README_EN.md +++ b/solution/2800-2899/2860.Happy Students/README_EN.md @@ -88,6 +88,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def countWays(self, nums: List[int]) -> int: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countWays(List nums) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func countWays(nums []int) (ans int) { sort.Ints(nums) @@ -150,6 +158,8 @@ func countWays(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function countWays(nums: number[]): number { nums.sort((a, b) => a - b); diff --git a/solution/2800-2899/2861.Maximum Number of Alloys/README.md b/solution/2800-2899/2861.Maximum Number of Alloys/README.md index 6923c2a4fc3de..3cbf2067df150 100644 --- a/solution/2800-2899/2861.Maximum Number of Alloys/README.md +++ b/solution/2800-2899/2861.Maximum Number of Alloys/README.md @@ -104,6 +104,8 @@ tags: +#### Python3 + ```python class Solution: def maxNumberOfAlloys( @@ -129,6 +131,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { int n; @@ -173,6 +177,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -205,6 +211,8 @@ public: }; ``` +#### Go + ```go func maxNumberOfAlloys(n int, k int, budget int, composition [][]int, stock []int, cost []int) int { isValid := func(target int) bool { @@ -234,6 +242,8 @@ func maxNumberOfAlloys(n int, k int, budget int, composition [][]int, stock []in } ``` +#### TypeScript + ```ts function maxNumberOfAlloys( n: number, diff --git a/solution/2800-2899/2861.Maximum Number of Alloys/README_EN.md b/solution/2800-2899/2861.Maximum Number of Alloys/README_EN.md index 4103f19a849eb..383e57fc34f37 100644 --- a/solution/2800-2899/2861.Maximum Number of Alloys/README_EN.md +++ b/solution/2800-2899/2861.Maximum Number of Alloys/README_EN.md @@ -102,6 +102,8 @@ The time complexity is $O(n \times k \times \log M)$, where $M$ is the upper bou +#### Python3 + ```python class Solution: def maxNumberOfAlloys( @@ -127,6 +129,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { int n; @@ -171,6 +175,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -203,6 +209,8 @@ public: }; ``` +#### Go + ```go func maxNumberOfAlloys(n int, k int, budget int, composition [][]int, stock []int, cost []int) int { isValid := func(target int) bool { @@ -232,6 +240,8 @@ func maxNumberOfAlloys(n int, k int, budget int, composition [][]int, stock []in } ``` +#### TypeScript + ```ts function maxNumberOfAlloys( n: number, diff --git a/solution/2800-2899/2862.Maximum Element-Sum of a Complete Subset of Indices/README.md b/solution/2800-2899/2862.Maximum Element-Sum of a Complete Subset of Indices/README.md index 7632ea6f9f8fb..ec383171d1f39 100644 --- a/solution/2800-2899/2862.Maximum Element-Sum of a Complete Subset of Indices/README.md +++ b/solution/2800-2899/2862.Maximum Element-Sum of a Complete Subset of Indices/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def maximumSum(self, nums: List[int]) -> int: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maximumSum(List nums) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### Java + ```java class Solution { public long maximumSum(List nums) { @@ -127,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +153,8 @@ public: }; ``` +#### Go + ```go func maximumSum(nums []int) (ans int64) { n := len(nums) @@ -159,6 +169,8 @@ func maximumSum(nums []int) (ans int64) { } ``` +#### TypeScript + ```ts function maximumSum(nums: number[]): number { let ans = 0; diff --git a/solution/2800-2899/2862.Maximum Element-Sum of a Complete Subset of Indices/README_EN.md b/solution/2800-2899/2862.Maximum Element-Sum of a Complete Subset of Indices/README_EN.md index 416b054fcb917..e53437d23692e 100644 --- a/solution/2800-2899/2862.Maximum Element-Sum of a Complete Subset of Indices/README_EN.md +++ b/solution/2800-2899/2862.Maximum Element-Sum of a Complete Subset of Indices/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def maximumSum(self, nums: List[int]) -> int: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maximumSum(List nums) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### Java + ```java class Solution { public long maximumSum(List nums) { @@ -133,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +159,8 @@ public: }; ``` +#### Go + ```go func maximumSum(nums []int) (ans int64) { n := len(nums) @@ -165,6 +175,8 @@ func maximumSum(nums []int) (ans int64) { } ``` +#### TypeScript + ```ts function maximumSum(nums: number[]): number { let ans = 0; diff --git a/solution/2800-2899/2863.Maximum Length of Semi-Decreasing Subarrays/README.md b/solution/2800-2899/2863.Maximum Length of Semi-Decreasing Subarrays/README.md index 848c29b59270c..dbf5509786a4e 100644 --- a/solution/2800-2899/2863.Maximum Length of Semi-Decreasing Subarrays/README.md +++ b/solution/2800-2899/2863.Maximum Length of Semi-Decreasing Subarrays/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def maxSubarrayLength(self, nums: List[int]) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxSubarrayLength(int[] nums) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func maxSubarrayLength(nums []int) (ans int) { d := map[int][]int{} @@ -153,6 +161,8 @@ func maxSubarrayLength(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function maxSubarrayLength(nums: number[]): number { const d: Map = new Map(); diff --git a/solution/2800-2899/2863.Maximum Length of Semi-Decreasing Subarrays/README_EN.md b/solution/2800-2899/2863.Maximum Length of Semi-Decreasing Subarrays/README_EN.md index f286f7d186d74..e105f445388c4 100644 --- a/solution/2800-2899/2863.Maximum Length of Semi-Decreasing Subarrays/README_EN.md +++ b/solution/2800-2899/2863.Maximum Length of Semi-Decreasing Subarrays/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def maxSubarrayLength(self, nums: List[int]) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxSubarrayLength(int[] nums) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func maxSubarrayLength(nums []int) (ans int) { d := map[int][]int{} @@ -151,6 +159,8 @@ func maxSubarrayLength(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function maxSubarrayLength(nums: number[]): number { const d: Map = new Map(); diff --git a/solution/2800-2899/2864.Maximum Odd Binary Number/README.md b/solution/2800-2899/2864.Maximum Odd Binary Number/README.md index c96179d4959cb..8aa2e3acafe34 100644 --- a/solution/2800-2899/2864.Maximum Odd Binary Number/README.md +++ b/solution/2800-2899/2864.Maximum Odd Binary Number/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def maximumOddBinaryNumber(self, s: str) -> str: @@ -77,6 +79,8 @@ class Solution: return "1" * (cnt - 1) + (len(s) - cnt) * "0" + "1" ``` +#### Java + ```java class Solution { public String maximumOddBinaryNumber(String s) { @@ -86,6 +90,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -96,6 +102,8 @@ public: }; ``` +#### Go + ```go func maximumOddBinaryNumber(s string) string { cnt := strings.Count(s, "1") @@ -103,6 +111,8 @@ func maximumOddBinaryNumber(s string) string { } ``` +#### TypeScript + ```ts function maximumOddBinaryNumber(s: string): string { const cnt = s.length - s.replace(/1/g, '').length; @@ -110,6 +120,8 @@ function maximumOddBinaryNumber(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn maximum_odd_binary_number(s: String) -> String { diff --git a/solution/2800-2899/2864.Maximum Odd Binary Number/README_EN.md b/solution/2800-2899/2864.Maximum Odd Binary Number/README_EN.md index 28c30c42356ba..45312f3dcf436 100644 --- a/solution/2800-2899/2864.Maximum Odd Binary Number/README_EN.md +++ b/solution/2800-2899/2864.Maximum Odd Binary Number/README_EN.md @@ -68,6 +68,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def maximumOddBinaryNumber(self, s: str) -> str: @@ -75,6 +77,8 @@ class Solution: return "1" * (cnt - 1) + (len(s) - cnt) * "0" + "1" ``` +#### Java + ```java class Solution { public String maximumOddBinaryNumber(String s) { @@ -84,6 +88,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -94,6 +100,8 @@ public: }; ``` +#### Go + ```go func maximumOddBinaryNumber(s string) string { cnt := strings.Count(s, "1") @@ -101,6 +109,8 @@ func maximumOddBinaryNumber(s string) string { } ``` +#### TypeScript + ```ts function maximumOddBinaryNumber(s: string): string { const cnt = s.length - s.replace(/1/g, '').length; @@ -108,6 +118,8 @@ function maximumOddBinaryNumber(s: string): string { } ``` +#### Rust + ```rust impl Solution { pub fn maximum_odd_binary_number(s: String) -> String { diff --git a/solution/2800-2899/2865.Beautiful Towers I/README.md b/solution/2800-2899/2865.Beautiful Towers I/README.md index ff4bc759bb0a2..421a86d5f4635 100644 --- a/solution/2800-2899/2865.Beautiful Towers I/README.md +++ b/solution/2800-2899/2865.Beautiful Towers I/README.md @@ -97,6 +97,8 @@ tags: +#### Python3 + ```python class Solution: def maximumSumOfHeights(self, maxHeights: List[int]) -> int: @@ -114,6 +116,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maximumSumOfHeights(List maxHeights) { @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func maximumSumOfHeights(maxHeights []int) (ans int64) { n := len(maxHeights) @@ -183,6 +191,8 @@ func maximumSumOfHeights(maxHeights []int) (ans int64) { } ``` +#### TypeScript + ```ts function maximumSumOfHeights(maxHeights: number[]): number { let ans = 0; @@ -233,6 +243,8 @@ $$ +#### Python3 + ```python class Solution: def maximumSumOfHeights(self, maxHeights: List[int]) -> int: @@ -271,6 +283,8 @@ class Solution: return max(a + b - c for a, b, c in zip(f, g, maxHeights)) ``` +#### Java + ```java class Solution { public long maximumSumOfHeights(List maxHeights) { @@ -330,6 +344,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -387,6 +403,8 @@ public: }; ``` +#### Go + ```go func maximumSumOfHeights(maxHeights []int) (ans int64) { n := len(maxHeights) @@ -449,6 +467,8 @@ func maximumSumOfHeights(maxHeights []int) (ans int64) { } ``` +#### TypeScript + ```ts function maximumSumOfHeights(maxHeights: number[]): number { const n = maxHeights.length; diff --git a/solution/2800-2899/2865.Beautiful Towers I/README_EN.md b/solution/2800-2899/2865.Beautiful Towers I/README_EN.md index 0bd2a05a3c3ed..57ef0640465dd 100644 --- a/solution/2800-2899/2865.Beautiful Towers I/README_EN.md +++ b/solution/2800-2899/2865.Beautiful Towers I/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(1)$. Here, $n$ i +#### Python3 + ```python class Solution: def maximumSumOfHeights(self, maxHeights: List[int]) -> int: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maximumSumOfHeights(List maxHeights) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func maximumSumOfHeights(maxHeights []int) (ans int64) { n := len(maxHeights) @@ -169,6 +177,8 @@ func maximumSumOfHeights(maxHeights []int) (ans int64) { } ``` +#### TypeScript + ```ts function maximumSumOfHeights(maxHeights: number[]): number { let ans = 0; @@ -219,6 +229,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def maximumSumOfHeights(self, maxHeights: List[int]) -> int: @@ -257,6 +269,8 @@ class Solution: return max(a + b - c for a, b, c in zip(f, g, maxHeights)) ``` +#### Java + ```java class Solution { public long maximumSumOfHeights(List maxHeights) { @@ -316,6 +330,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -373,6 +389,8 @@ public: }; ``` +#### Go + ```go func maximumSumOfHeights(maxHeights []int) (ans int64) { n := len(maxHeights) @@ -435,6 +453,8 @@ func maximumSumOfHeights(maxHeights []int) (ans int64) { } ``` +#### TypeScript + ```ts function maximumSumOfHeights(maxHeights: number[]): number { const n = maxHeights.length; diff --git a/solution/2800-2899/2866.Beautiful Towers II/README.md b/solution/2800-2899/2866.Beautiful Towers II/README.md index 83c5a1c387c9f..df2d7b737f3a4 100644 --- a/solution/2800-2899/2866.Beautiful Towers II/README.md +++ b/solution/2800-2899/2866.Beautiful Towers II/README.md @@ -109,6 +109,8 @@ $$ +#### Python3 + ```python class Solution: def maximumSumOfHeights(self, maxHeights: List[int]) -> int: @@ -147,6 +149,8 @@ class Solution: return max(a + b - c for a, b, c in zip(f, g, maxHeights)) ``` +#### Java + ```java class Solution { public long maximumSumOfHeights(List maxHeights) { @@ -206,6 +210,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -263,6 +269,8 @@ public: }; ``` +#### Go + ```go func maximumSumOfHeights(maxHeights []int) (ans int64) { n := len(maxHeights) @@ -325,6 +333,8 @@ func maximumSumOfHeights(maxHeights []int) (ans int64) { } ``` +#### TypeScript + ```ts function maximumSumOfHeights(maxHeights: number[]): number { const n = maxHeights.length; diff --git a/solution/2800-2899/2866.Beautiful Towers II/README_EN.md b/solution/2800-2899/2866.Beautiful Towers II/README_EN.md index 47ee4979c8d1a..601a19175f4c3 100644 --- a/solution/2800-2899/2866.Beautiful Towers II/README_EN.md +++ b/solution/2800-2899/2866.Beautiful Towers II/README_EN.md @@ -107,6 +107,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def maximumSumOfHeights(self, maxHeights: List[int]) -> int: @@ -145,6 +147,8 @@ class Solution: return max(a + b - c for a, b, c in zip(f, g, maxHeights)) ``` +#### Java + ```java class Solution { public long maximumSumOfHeights(List maxHeights) { @@ -204,6 +208,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -261,6 +267,8 @@ public: }; ``` +#### Go + ```go func maximumSumOfHeights(maxHeights []int) (ans int64) { n := len(maxHeights) @@ -323,6 +331,8 @@ func maximumSumOfHeights(maxHeights []int) (ans int64) { } ``` +#### TypeScript + ```ts function maximumSumOfHeights(maxHeights: number[]): number { const n = maxHeights.length; diff --git a/solution/2800-2899/2867.Count Valid Paths in a Tree/README.md b/solution/2800-2899/2867.Count Valid Paths in a Tree/README.md index ee01a82c7ddf3..004183c66bb3d 100644 --- a/solution/2800-2899/2867.Count Valid Paths in a Tree/README.md +++ b/solution/2800-2899/2867.Count Valid Paths in a Tree/README.md @@ -101,6 +101,8 @@ tags: +#### Python3 + ```python class UnionFind: def __init__(self, n): @@ -157,6 +159,8 @@ class Solution: return ans ``` +#### Java + ```java class PrimeTable { private final boolean[] prime; @@ -254,6 +258,8 @@ class Solution { } ``` +#### C++ + ```cpp const int mx = 1e5 + 10; bool prime[mx + 1]; @@ -339,6 +345,8 @@ public: }; ``` +#### Go + ```go const mx int = 1e5 + 10 @@ -424,6 +432,8 @@ func countPaths(n int, edges [][]int) (ans int64) { } ``` +#### TypeScript + ```ts const mx = 100010; const prime = Array(mx).fill(true); @@ -512,6 +522,8 @@ function countPaths(n: number, edges: number[][]): number { +#### Python3 + ```python class Solution: def countPaths(self, n: int, edges: List[List[int]]) -> int: @@ -557,6 +569,8 @@ class Solution: return r[0] ``` +#### Java + ```java class Solution { public long countPaths(int n, int[][] edges) { @@ -629,6 +643,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { long long mul(long long x, long long y) { diff --git a/solution/2800-2899/2867.Count Valid Paths in a Tree/README_EN.md b/solution/2800-2899/2867.Count Valid Paths in a Tree/README_EN.md index 90fa3352a1d2f..69c54f72c3a3a 100644 --- a/solution/2800-2899/2867.Count Valid Paths in a Tree/README_EN.md +++ b/solution/2800-2899/2867.Count Valid Paths in a Tree/README_EN.md @@ -95,6 +95,8 @@ The time complexity is $O(n \times \alpha(n))$, and the space complexity is $O(n +#### Python3 + ```python class UnionFind: def __init__(self, n): @@ -151,6 +153,8 @@ class Solution: return ans ``` +#### Java + ```java class PrimeTable { private final boolean[] prime; @@ -248,6 +252,8 @@ class Solution { } ``` +#### C++ + ```cpp const int mx = 1e5 + 10; bool prime[mx + 1]; @@ -333,6 +339,8 @@ public: }; ``` +#### Go + ```go const mx int = 1e5 + 10 @@ -418,6 +426,8 @@ func countPaths(n int, edges [][]int) (ans int64) { } ``` +#### TypeScript + ```ts const mx = 100010; const prime = Array(mx).fill(true); @@ -506,6 +516,8 @@ function countPaths(n: number, edges: number[][]): number { +#### Python3 + ```python class Solution: def countPaths(self, n: int, edges: List[List[int]]) -> int: @@ -551,6 +563,8 @@ class Solution: return r[0] ``` +#### Java + ```java class Solution { public long countPaths(int n, int[][] edges) { @@ -623,6 +637,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { long long mul(long long x, long long y) { diff --git a/solution/2800-2899/2868.The Wording Game/README.md b/solution/2800-2899/2868.The Wording Game/README.md index aa5c3d2ca437c..8a78a69147417 100644 --- a/solution/2800-2899/2868.The Wording Game/README.md +++ b/solution/2800-2899/2868.The Wording Game/README.md @@ -116,6 +116,8 @@ Bob 无法出牌,因为他的两个单词的第一个字母都比 Alice 的单 +#### Python3 + ```python class Solution: def canAliceWin(self, a: List[str], b: List[str]) -> bool: @@ -138,6 +140,8 @@ class Solution: i += 1 ``` +#### Java + ```java class Solution { public boolean canAliceWin(String[] a, String[] b) { @@ -171,6 +175,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -202,6 +208,8 @@ public: }; ``` +#### Go + ```go func canAliceWin(a []string, b []string) bool { i, j, k := 1, 0, 1 @@ -230,6 +238,8 @@ func canAliceWin(a []string, b []string) bool { } ``` +#### TypeScript + ```ts function canAliceWin(a: string[], b: string[]): boolean { let [i, j, k] = [1, 0, 1]; diff --git a/solution/2800-2899/2868.The Wording Game/README_EN.md b/solution/2800-2899/2868.The Wording Game/README_EN.md index f23695c926a73..701ab12ea17e3 100644 --- a/solution/2800-2899/2868.The Wording Game/README_EN.md +++ b/solution/2800-2899/2868.The Wording Game/README_EN.md @@ -103,6 +103,8 @@ The time complexity is $O(m+n)$, where $m$ and $n$ are the lengths of arrays $a$ +#### Python3 + ```python class Solution: def canAliceWin(self, a: List[str], b: List[str]) -> bool: @@ -125,6 +127,8 @@ class Solution: i += 1 ``` +#### Java + ```java class Solution { public boolean canAliceWin(String[] a, String[] b) { @@ -158,6 +162,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -189,6 +195,8 @@ public: }; ``` +#### Go + ```go func canAliceWin(a []string, b []string) bool { i, j, k := 1, 0, 1 @@ -217,6 +225,8 @@ func canAliceWin(a []string, b []string) bool { } ``` +#### TypeScript + ```ts function canAliceWin(a: string[], b: string[]): boolean { let [i, j, k] = [1, 0, 1]; diff --git a/solution/2800-2899/2869.Minimum Operations to Collect Elements/README.md b/solution/2800-2899/2869.Minimum Operations to Collect Elements/README.md index c9fd9fff756be..56a04c5315e52 100644 --- a/solution/2800-2899/2869.Minimum Operations to Collect Elements/README.md +++ b/solution/2800-2899/2869.Minimum Operations to Collect Elements/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int], k: int) -> int: @@ -92,6 +94,8 @@ class Solution: return n - i ``` +#### Java + ```java class Solution { public int minOperations(List nums, int k) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int, k int) int { isAdded := make([]bool, k) @@ -150,6 +158,8 @@ func minOperations(nums []int, k int) int { } ``` +#### TypeScript + ```ts function minOperations(nums: number[], k: number): number { const n = nums.length; diff --git a/solution/2800-2899/2869.Minimum Operations to Collect Elements/README_EN.md b/solution/2800-2899/2869.Minimum Operations to Collect Elements/README_EN.md index 1c8ab82aa5dcb..18c15a78df9e2 100644 --- a/solution/2800-2899/2869.Minimum Operations to Collect Elements/README_EN.md +++ b/solution/2800-2899/2869.Minimum Operations to Collect Elements/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int], k: int) -> int: @@ -90,6 +92,8 @@ class Solution: return n - i ``` +#### Java + ```java class Solution { public int minOperations(List nums, int k) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int, k int) int { isAdded := make([]bool, k) @@ -148,6 +156,8 @@ func minOperations(nums []int, k int) int { } ``` +#### TypeScript + ```ts function minOperations(nums: number[], k: number): number { const n = nums.length; diff --git a/solution/2800-2899/2870.Minimum Number of Operations to Make Array Empty/README.md b/solution/2800-2899/2870.Minimum Number of Operations to Make Array Empty/README.md index cf6eb958bebc9..651a08bdc3a1c 100644 --- a/solution/2800-2899/2870.Minimum Number of Operations to Make Array Empty/README.md +++ b/solution/2800-2899/2870.Minimum Number of Operations to Make Array Empty/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int]) -> int: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minOperations(int[] nums) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int) (ans int) { count := map[int]int{} @@ -155,6 +163,8 @@ func minOperations(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function minOperations(nums: number[]): number { const count: Map = new Map(); diff --git a/solution/2800-2899/2870.Minimum Number of Operations to Make Array Empty/README_EN.md b/solution/2800-2899/2870.Minimum Number of Operations to Make Array Empty/README_EN.md index 384802749d930..53a497127b369 100644 --- a/solution/2800-2899/2870.Minimum Number of Operations to Make Array Empty/README_EN.md +++ b/solution/2800-2899/2870.Minimum Number of Operations to Make Array Empty/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int]) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minOperations(int[] nums) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int) (ans int) { count := map[int]int{} @@ -153,6 +161,8 @@ func minOperations(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function minOperations(nums: number[]): number { const count: Map = new Map(); diff --git a/solution/2800-2899/2871.Split Array Into Maximum Number of Subarrays/README.md b/solution/2800-2899/2871.Split Array Into Maximum Number of Subarrays/README.md index 8f9eeefbdda40..2aee2a4350353 100644 --- a/solution/2800-2899/2871.Split Array Into Maximum Number of Subarrays/README.md +++ b/solution/2800-2899/2871.Split Array Into Maximum Number of Subarrays/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def maxSubarrays(self, nums: List[int]) -> int: @@ -94,6 +96,8 @@ class Solution: return 1 if ans == 1 else ans - 1 ``` +#### Java + ```java class Solution { public int maxSubarrays(int[] nums) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func maxSubarrays(nums []int) int { ans, score := 1, -1 @@ -145,6 +153,8 @@ func maxSubarrays(nums []int) int { } ``` +#### TypeScript + ```ts function maxSubarrays(nums: number[]): number { let [ans, score] = [1, -1]; diff --git a/solution/2800-2899/2871.Split Array Into Maximum Number of Subarrays/README_EN.md b/solution/2800-2899/2871.Split Array Into Maximum Number of Subarrays/README_EN.md index 923eb11fc303e..224c62ae2bd54 100644 --- a/solution/2800-2899/2871.Split Array Into Maximum Number of Subarrays/README_EN.md +++ b/solution/2800-2899/2871.Split Array Into Maximum Number of Subarrays/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def maxSubarrays(self, nums: List[int]) -> int: @@ -92,6 +94,8 @@ class Solution: return 1 if ans == 1 else ans - 1 ``` +#### Java + ```java class Solution { public int maxSubarrays(int[] nums) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func maxSubarrays(nums []int) int { ans, score := 1, -1 @@ -143,6 +151,8 @@ func maxSubarrays(nums []int) int { } ``` +#### TypeScript + ```ts function maxSubarrays(nums: number[]): number { let [ans, score] = [1, -1]; diff --git a/solution/2800-2899/2872.Maximum Number of K-Divisible Components/README.md b/solution/2800-2899/2872.Maximum Number of K-Divisible Components/README.md index 1fe861f3fa14d..3f1a01d8beb06 100644 --- a/solution/2800-2899/2872.Maximum Number of K-Divisible Components/README.md +++ b/solution/2800-2899/2872.Maximum Number of K-Divisible Components/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def maxKDivisibleComponents( @@ -110,6 +112,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int ans; @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func maxKDivisibleComponents(n int, edges [][]int, values []int, k int) (ans int) { g := make([][]int, n) @@ -197,6 +205,8 @@ func maxKDivisibleComponents(n int, edges [][]int, values []int, k int) (ans int } ``` +#### TypeScript + ```ts function maxKDivisibleComponents( n: number, @@ -237,6 +247,8 @@ function maxKDivisibleComponents( +#### Java + ```java class Solution { int n, k; diff --git a/solution/2800-2899/2872.Maximum Number of K-Divisible Components/README_EN.md b/solution/2800-2899/2872.Maximum Number of K-Divisible Components/README_EN.md index f5bf8568e63c2..71fe8cb9e2641 100644 --- a/solution/2800-2899/2872.Maximum Number of K-Divisible Components/README_EN.md +++ b/solution/2800-2899/2872.Maximum Number of K-Divisible Components/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where n is th +#### Python3 + ```python class Solution: def maxKDivisibleComponents( @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int ans; @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func maxKDivisibleComponents(n int, edges [][]int, values []int, k int) (ans int) { g := make([][]int, n) @@ -191,6 +199,8 @@ func maxKDivisibleComponents(n int, edges [][]int, values []int, k int) (ans int } ``` +#### TypeScript + ```ts function maxKDivisibleComponents( n: number, @@ -231,6 +241,8 @@ function maxKDivisibleComponents( +#### Java + ```java class Solution { int n, k; diff --git a/solution/2800-2899/2873.Maximum Value of an Ordered Triplet I/README.md b/solution/2800-2899/2873.Maximum Value of an Ordered Triplet I/README.md index 600b8f3e2a006..17abe43dc30a1 100644 --- a/solution/2800-2899/2873.Maximum Value of an Ordered Triplet I/README.md +++ b/solution/2800-2899/2873.Maximum Value of an Ordered Triplet I/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def maximumTripletValue(self, nums: List[int]) -> int: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maximumTripletValue(int[] nums) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func maximumTripletValue(nums []int) int64 { ans, mx, mx_diff := 0, 0, 0 @@ -131,6 +139,8 @@ func maximumTripletValue(nums []int) int64 { } ``` +#### TypeScript + ```ts function maximumTripletValue(nums: number[]): number { let [ans, mx, mx_diff] = [0, 0, 0]; diff --git a/solution/2800-2899/2873.Maximum Value of an Ordered Triplet I/README_EN.md b/solution/2800-2899/2873.Maximum Value of an Ordered Triplet I/README_EN.md index 31b307d146a4c..42059e472f811 100644 --- a/solution/2800-2899/2873.Maximum Value of an Ordered Triplet I/README_EN.md +++ b/solution/2800-2899/2873.Maximum Value of an Ordered Triplet I/README_EN.md @@ -73,6 +73,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def maximumTripletValue(self, nums: List[int]) -> int: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maximumTripletValue(int[] nums) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func maximumTripletValue(nums []int) int64 { ans, mx, mx_diff := 0, 0, 0 @@ -129,6 +137,8 @@ func maximumTripletValue(nums []int) int64 { } ``` +#### TypeScript + ```ts function maximumTripletValue(nums: number[]): number { let [ans, mx, mx_diff] = [0, 0, 0]; diff --git a/solution/2800-2899/2874.Maximum Value of an Ordered Triplet II/README.md b/solution/2800-2899/2874.Maximum Value of an Ordered Triplet II/README.md index 0eabc23b90a4c..55b6402ce953e 100644 --- a/solution/2800-2899/2874.Maximum Value of an Ordered Triplet II/README.md +++ b/solution/2800-2899/2874.Maximum Value of an Ordered Triplet II/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def maximumTripletValue(self, nums: List[int]) -> int: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maximumTripletValue(int[] nums) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func maximumTripletValue(nums []int) int64 { ans, mx, mx_diff := 0, 0, 0 @@ -131,6 +139,8 @@ func maximumTripletValue(nums []int) int64 { } ``` +#### TypeScript + ```ts function maximumTripletValue(nums: number[]): number { let [ans, mx, mx_diff] = [0, 0, 0]; diff --git a/solution/2800-2899/2874.Maximum Value of an Ordered Triplet II/README_EN.md b/solution/2800-2899/2874.Maximum Value of an Ordered Triplet II/README_EN.md index 05ce4cb474ca1..6ca64b15433a0 100644 --- a/solution/2800-2899/2874.Maximum Value of an Ordered Triplet II/README_EN.md +++ b/solution/2800-2899/2874.Maximum Value of an Ordered Triplet II/README_EN.md @@ -73,6 +73,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def maximumTripletValue(self, nums: List[int]) -> int: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maximumTripletValue(int[] nums) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func maximumTripletValue(nums []int) int64 { ans, mx, mx_diff := 0, 0, 0 @@ -129,6 +137,8 @@ func maximumTripletValue(nums []int) int64 { } ``` +#### TypeScript + ```ts function maximumTripletValue(nums: number[]): number { let [ans, mx, mx_diff] = [0, 0, 0]; diff --git a/solution/2800-2899/2875.Minimum Size Subarray in Infinite Array/README.md b/solution/2800-2899/2875.Minimum Size Subarray in Infinite Array/README.md index ff96087c18a6f..4eef5a2899895 100644 --- a/solution/2800-2899/2875.Minimum Size Subarray in Infinite Array/README.md +++ b/solution/2800-2899/2875.Minimum Size Subarray in Infinite Array/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def minSizeSubarray(self, nums: List[int], target: int) -> int: @@ -111,6 +113,8 @@ class Solution: return -1 if b == inf else a + b ``` +#### Java + ```java class Solution { public int minSizeSubarray(int[] nums, int target) { @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go func minSizeSubarray(nums []int, target int) int { s := 0 @@ -210,6 +218,8 @@ func minSizeSubarray(nums []int, target int) int { } ``` +#### TypeScript + ```ts function minSizeSubarray(nums: number[], target: number): number { const s = nums.reduce((a, b) => a + b); @@ -250,6 +260,8 @@ function minSizeSubarray(nums: number[], target: number): number { +#### Java + ```java class Solution { public int shortestSubarray(int[] nums, int k) { diff --git a/solution/2800-2899/2875.Minimum Size Subarray in Infinite Array/README_EN.md b/solution/2800-2899/2875.Minimum Size Subarray in Infinite Array/README_EN.md index 08bdc0e0f4c8e..65949027fdb04 100644 --- a/solution/2800-2899/2875.Minimum Size Subarray in Infinite Array/README_EN.md +++ b/solution/2800-2899/2875.Minimum Size Subarray in Infinite Array/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where n is th +#### Python3 + ```python class Solution: def minSizeSubarray(self, nums: List[int], target: int) -> int: @@ -110,6 +112,8 @@ class Solution: return -1 if b == inf else a + b ``` +#### Java + ```java class Solution { public int minSizeSubarray(int[] nums, int target) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func minSizeSubarray(nums []int, target int) int { s := 0 @@ -209,6 +217,8 @@ func minSizeSubarray(nums []int, target int) int { } ``` +#### TypeScript + ```ts function minSizeSubarray(nums: number[], target: number): number { const s = nums.reduce((a, b) => a + b); @@ -249,6 +259,8 @@ function minSizeSubarray(nums: number[], target: number): number { +#### Java + ```java class Solution { public int shortestSubarray(int[] nums, int k) { diff --git a/solution/2800-2899/2876.Count Visited Nodes in a Directed Graph/README.md b/solution/2800-2899/2876.Count Visited Nodes in a Directed Graph/README.md index cc505967de687..4440a4a45c129 100644 --- a/solution/2800-2899/2876.Count Visited Nodes in a Directed Graph/README.md +++ b/solution/2800-2899/2876.Count Visited Nodes in a Directed Graph/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def countVisitedNodes(self, edges: List[int]) -> List[int]: @@ -109,6 +111,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] countVisitedNodes(List edges) { @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func countVisitedNodes(edges []int) []int { n := len(edges) @@ -196,6 +204,8 @@ func countVisitedNodes(edges []int) []int { } ``` +#### TypeScript + ```ts function countVisitedNodes(edges: number[]): number[] { const n = edges.length; @@ -233,6 +243,8 @@ function countVisitedNodes(edges: number[]): number[] { +#### Java + ```java class Solution { void dfs(int curr, List edges, int[] ans) { diff --git a/solution/2800-2899/2876.Count Visited Nodes in a Directed Graph/README_EN.md b/solution/2800-2899/2876.Count Visited Nodes in a Directed Graph/README_EN.md index 32f16e756b304..5f37efa76b5fd 100644 --- a/solution/2800-2899/2876.Count Visited Nodes in a Directed Graph/README_EN.md +++ b/solution/2800-2899/2876.Count Visited Nodes in a Directed Graph/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python class Solution: def countVisitedNodes(self, edges: List[int]) -> List[int]: @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] countVisitedNodes(List edges) { @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func countVisitedNodes(edges []int) []int { n := len(edges) @@ -194,6 +202,8 @@ func countVisitedNodes(edges []int) []int { } ``` +#### TypeScript + ```ts function countVisitedNodes(edges: number[]): number[] { const n = edges.length; @@ -231,6 +241,8 @@ function countVisitedNodes(edges: number[]): number[] { +#### Java + ```java class Solution { void dfs(int curr, List edges, int[] ans) { diff --git a/solution/2800-2899/2877.Create a DataFrame from List/README.md b/solution/2800-2899/2877.Create a DataFrame from List/README.md index a6498d39ec19b..d8e6a5b6b49e0 100644 --- a/solution/2800-2899/2877.Create a DataFrame from List/README.md +++ b/solution/2800-2899/2877.Create a DataFrame from List/README.md @@ -56,6 +56,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2800-2899/2877.Cr +#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2877.Create a DataFrame from List/README_EN.md b/solution/2800-2899/2877.Create a DataFrame from List/README_EN.md index 6b10f7b7709b5..32afc51ca9dd9 100644 --- a/solution/2800-2899/2877.Create a DataFrame from List/README_EN.md +++ b/solution/2800-2899/2877.Create a DataFrame from List/README_EN.md @@ -55,6 +55,8 @@ A DataFrame was created on top of student_data, with two columns named stu +#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2878.Get the Size of a DataFrame/README.md b/solution/2800-2899/2878.Get the Size of a DataFrame/README.md index 302ae6f125c39..9660a5cdb2617 100644 --- a/solution/2800-2899/2878.Get the Size of a DataFrame/README.md +++ b/solution/2800-2899/2878.Get the Size of a DataFrame/README.md @@ -71,6 +71,8 @@ DataFrame players: +#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2878.Get the Size of a DataFrame/README_EN.md b/solution/2800-2899/2878.Get the Size of a DataFrame/README_EN.md index 1ae50670704d8..b46e2458fa5fa 100644 --- a/solution/2800-2899/2878.Get the Size of a DataFrame/README_EN.md +++ b/solution/2800-2899/2878.Get the Size of a DataFrame/README_EN.md @@ -70,6 +70,8 @@ This DataFrame contains 10 rows and 5 columns. +#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2879.Display the First Three Rows/README.md b/solution/2800-2899/2879.Display the First Three Rows/README.md index a9257429f404b..700d7332cfe95 100644 --- a/solution/2800-2899/2879.Display the First Three Rows/README.md +++ b/solution/2800-2899/2879.Display the First Three Rows/README.md @@ -66,6 +66,8 @@ DataFrame: employees +#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2879.Display the First Three Rows/README_EN.md b/solution/2800-2899/2879.Display the First Three Rows/README_EN.md index 20921e0bc9f23..333b19d903849 100644 --- a/solution/2800-2899/2879.Display the First Three Rows/README_EN.md +++ b/solution/2800-2899/2879.Display the First Three Rows/README_EN.md @@ -65,6 +65,8 @@ Only the first 3 rows are displayed. +#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2880.Select Data/README.md b/solution/2800-2899/2880.Select Data/README.md index c3a51325a2427..ca31248031f6c 100644 --- a/solution/2800-2899/2880.Select Data/README.md +++ b/solution/2800-2899/2880.Select Data/README.md @@ -63,6 +63,8 @@ DataFrame students +#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2880.Select Data/README_EN.md b/solution/2800-2899/2880.Select Data/README_EN.md index bcd5bc1093fe1..8171f65bcc5e6 100644 --- a/solution/2800-2899/2880.Select Data/README_EN.md +++ b/solution/2800-2899/2880.Select Data/README_EN.md @@ -61,6 +61,8 @@ Input: +#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2881.Create a New Column/README.md b/solution/2800-2899/2881.Create a New Column/README.md index 4ed23e8d916c9..74d3e4c670bc9 100644 --- a/solution/2800-2899/2881.Create a New Column/README.md +++ b/solution/2800-2899/2881.Create a New Column/README.md @@ -75,6 +75,8 @@ DataFrame employees +#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2881.Create a New Column/README_EN.md b/solution/2800-2899/2881.Create a New Column/README_EN.md index 54a04398a80ec..4fd045a988abe 100644 --- a/solution/2800-2899/2881.Create a New Column/README_EN.md +++ b/solution/2800-2899/2881.Create a New Column/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2882.Drop Duplicate Rows/README.md b/solution/2800-2899/2882.Drop Duplicate Rows/README.md index 5ed9ccaab1e9c..d8aeab0f6458b 100644 --- a/solution/2800-2899/2882.Drop Duplicate Rows/README.md +++ b/solution/2800-2899/2882.Drop Duplicate Rows/README.md @@ -71,6 +71,8 @@ Alice (customer_id = 4) 和 Finn (customer_id = 5) 都使用 john@example.com, +#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2882.Drop Duplicate Rows/README_EN.md b/solution/2800-2899/2882.Drop Duplicate Rows/README_EN.md index 23f0d674c8e78..fb7f0143196d2 100644 --- a/solution/2800-2899/2882.Drop Duplicate Rows/README_EN.md +++ b/solution/2800-2899/2882.Drop Duplicate Rows/README_EN.md @@ -69,6 +69,8 @@ Alic (customer_id = 4) and Finn (customer_id = 5) both use john@example.com, so +#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2883.Drop Missing Data/README.md b/solution/2800-2899/2883.Drop Missing Data/README.md index 38bd0157ff4fd..1e4ff66875c05 100644 --- a/solution/2800-2899/2883.Drop Missing Data/README.md +++ b/solution/2800-2899/2883.Drop Missing Data/README.md @@ -66,6 +66,8 @@ DataFrame students +#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2883.Drop Missing Data/README_EN.md b/solution/2800-2899/2883.Drop Missing Data/README_EN.md index 6d7ae2c0894de..64f0838e4c8f5 100644 --- a/solution/2800-2899/2883.Drop Missing Data/README_EN.md +++ b/solution/2800-2899/2883.Drop Missing Data/README_EN.md @@ -65,6 +65,8 @@ Student with id 217 havs empty value in the name column, so it will be removed.< +#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2884.Modify Columns/README.md b/solution/2800-2899/2884.Modify Columns/README.md index f4bb8c9034bcb..d4b2eccf7a704 100644 --- a/solution/2800-2899/2884.Modify Columns/README.md +++ b/solution/2800-2899/2884.Modify Columns/README.md @@ -67,6 +67,8 @@ DataFrame employees +#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2884.Modify Columns/README_EN.md b/solution/2800-2899/2884.Modify Columns/README_EN.md index 828479dc15f5a..80f207ac1be15 100644 --- a/solution/2800-2899/2884.Modify Columns/README_EN.md +++ b/solution/2800-2899/2884.Modify Columns/README_EN.md @@ -66,6 +66,8 @@ DataFrame employees +#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2885.Rename Columns/README.md b/solution/2800-2899/2885.Rename Columns/README.md index 35395e2f90292..d550d2185c24a 100644 --- a/solution/2800-2899/2885.Rename Columns/README.md +++ b/solution/2800-2899/2885.Rename Columns/README.md @@ -75,6 +75,8 @@ DataFrame students +#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2885.Rename Columns/README_EN.md b/solution/2800-2899/2885.Rename Columns/README_EN.md index 1c57dba38acb9..e24aab23a7866 100644 --- a/solution/2800-2899/2885.Rename Columns/README_EN.md +++ b/solution/2800-2899/2885.Rename Columns/README_EN.md @@ -73,6 +73,8 @@ The column names are changed accordingly. +#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2886.Change Data Type/README.md b/solution/2800-2899/2886.Change Data Type/README.md index 8a1746cc20fc9..38ea16abdbc19 100644 --- a/solution/2800-2899/2886.Change Data Type/README.md +++ b/solution/2800-2899/2886.Change Data Type/README.md @@ -65,6 +65,8 @@ grade 列的数据类型已转换为整数。 +#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2886.Change Data Type/README_EN.md b/solution/2800-2899/2886.Change Data Type/README_EN.md index 198a6baf377a5..062bacbfe3eab 100644 --- a/solution/2800-2899/2886.Change Data Type/README_EN.md +++ b/solution/2800-2899/2886.Change Data Type/README_EN.md @@ -63,6 +63,8 @@ The data types of the column grade is converted to int. +#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2887.Fill Missing Data/README.md b/solution/2800-2899/2887.Fill Missing Data/README.md index 2365e969054c3..3e6078bbb8a79 100644 --- a/solution/2800-2899/2887.Fill Missing Data/README.md +++ b/solution/2800-2899/2887.Fill Missing Data/README.md @@ -64,6 +64,8 @@ Toaster 和 Headphones 的数量被填充为 0。 +#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2887.Fill Missing Data/README_EN.md b/solution/2800-2899/2887.Fill Missing Data/README_EN.md index 733e7f1c1844f..86778d37f36c8 100644 --- a/solution/2800-2899/2887.Fill Missing Data/README_EN.md +++ b/solution/2800-2899/2887.Fill Missing Data/README_EN.md @@ -62,6 +62,8 @@ The quantity for Wristwatch and WirelessEarbuds are filled by 0. +#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2888.Reshape Data Concatenate/README.md b/solution/2800-2899/2888.Reshape Data Concatenate/README.md index 88c14553f84f3..cc3aa84a48f8c 100644 --- a/solution/2800-2899/2888.Reshape Data Concatenate/README.md +++ b/solution/2800-2899/2888.Reshape Data Concatenate/README.md @@ -85,6 +85,8 @@ df1
+#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2888.Reshape Data Concatenate/README_EN.md b/solution/2800-2899/2888.Reshape Data Concatenate/README_EN.md index bbe988b64155c..5b45dd97d0089 100644 --- a/solution/2800-2899/2888.Reshape Data Concatenate/README_EN.md +++ b/solution/2800-2899/2888.Reshape Data Concatenate/README_EN.md @@ -84,6 +84,8 @@ df1
+#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2889.Reshape Data Pivot/README.md b/solution/2800-2899/2889.Reshape Data Pivot/README.md index 76853953c98d3..8923d1fc11d4f 100644 --- a/solution/2800-2899/2889.Reshape Data Pivot/README.md +++ b/solution/2800-2899/2889.Reshape Data Pivot/README.md @@ -71,6 +71,8 @@ DataFrame weather +#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2889.Reshape Data Pivot/README_EN.md b/solution/2800-2899/2889.Reshape Data Pivot/README_EN.md index deaaa25c836db..9680804a47b21 100644 --- a/solution/2800-2899/2889.Reshape Data Pivot/README_EN.md +++ b/solution/2800-2899/2889.Reshape Data Pivot/README_EN.md @@ -70,6 +70,8 @@ DataFrame weather +#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2890.Reshape Data Melt/README.md b/solution/2800-2899/2890.Reshape Data Melt/README.md index 988a05ac2041d..161eee0fa89fc 100644 --- a/solution/2800-2899/2890.Reshape Data Melt/README.md +++ b/solution/2800-2899/2890.Reshape Data Melt/README.md @@ -70,6 +70,8 @@ DataFrame 已从宽格式重塑为长格式。每一行表示一个季度内产 +#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2890.Reshape Data Melt/README_EN.md b/solution/2800-2899/2890.Reshape Data Melt/README_EN.md index 1ff96fc859a80..407efa672910f 100644 --- a/solution/2800-2899/2890.Reshape Data Melt/README_EN.md +++ b/solution/2800-2899/2890.Reshape Data Melt/README_EN.md @@ -69,6 +69,8 @@ The DataFrame is reshaped from wide to long format. Each row represents the sale +#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2891.Method Chaining/README.md b/solution/2800-2899/2891.Method Chaining/README.md index e8d73198f1f97..8706dee377ed8 100644 --- a/solution/2800-2899/2891.Method Chaining/README.md +++ b/solution/2800-2899/2891.Method Chaining/README.md @@ -79,6 +79,8 @@ Tatiana 的体重为 464,Jonathan 的体重为 463,Tommy 的体重为 349, +#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2891.Method Chaining/README_EN.md b/solution/2800-2899/2891.Method Chaining/README_EN.md index 17f950e8ed194..920428e4cd7fa 100644 --- a/solution/2800-2899/2891.Method Chaining/README_EN.md +++ b/solution/2800-2899/2891.Method Chaining/README_EN.md @@ -77,6 +77,8 @@ The results should be sorted in descending order of weight. +#### Python3 + ```python import pandas as pd diff --git a/solution/2800-2899/2892.Minimizing Array After Replacing Pairs With Their Product/README.md b/solution/2800-2899/2892.Minimizing Array After Replacing Pairs With Their Product/README.md index ac757e76ebc6e..c8c6f7e672085 100644 --- a/solution/2800-2899/2892.Minimizing Array After Replacing Pairs With Their Product/README.md +++ b/solution/2800-2899/2892.Minimizing Array After Replacing Pairs With Their Product/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def minArrayLength(self, nums: List[int], k: int) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minArrayLength(int[] nums, int k) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func minArrayLength(nums []int, k int) int { ans, y := 1, nums[0] @@ -156,6 +164,8 @@ func minArrayLength(nums []int, k int) int { } ``` +#### TypeScript + ```ts function minArrayLength(nums: number[], k: number): number { let [ans, y] = [1, nums[0]]; diff --git a/solution/2800-2899/2892.Minimizing Array After Replacing Pairs With Their Product/README_EN.md b/solution/2800-2899/2892.Minimizing Array After Replacing Pairs With Their Product/README_EN.md index e3dc63599a38e..a113dde05547d 100644 --- a/solution/2800-2899/2892.Minimizing Array After Replacing Pairs With Their Product/README_EN.md +++ b/solution/2800-2899/2892.Minimizing Array After Replacing Pairs With Their Product/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n)$, where n is the length of the array. The space com +#### Python3 + ```python class Solution: def minArrayLength(self, nums: List[int], k: int) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minArrayLength(int[] nums, int k) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func minArrayLength(nums []int, k int) int { ans, y := 1, nums[0] @@ -156,6 +164,8 @@ func minArrayLength(nums []int, k int) int { } ``` +#### TypeScript + ```ts function minArrayLength(nums: number[], k: number): number { let [ans, y] = [1, nums[0]]; diff --git a/solution/2800-2899/2893.Calculate Orders Within Each Interval/README.md b/solution/2800-2899/2893.Calculate Orders Within Each Interval/README.md index 450716da48fe8..b3dc905cb68e9 100644 --- a/solution/2800-2899/2893.Calculate Orders Within Each Interval/README.md +++ b/solution/2800-2899/2893.Calculate Orders Within Each Interval/README.md @@ -85,6 +85,8 @@ Orders table: +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -112,6 +114,8 @@ WHERE minute % 6 = 0; +#### MySQL + ```sql SELECT FLOOR((minute + 5) / 6) AS interval_no, diff --git a/solution/2800-2899/2893.Calculate Orders Within Each Interval/README_EN.md b/solution/2800-2899/2893.Calculate Orders Within Each Interval/README_EN.md index fd28c42691a47..063b8cc192299 100644 --- a/solution/2800-2899/2893.Calculate Orders Within Each Interval/README_EN.md +++ b/solution/2800-2899/2893.Calculate Orders Within Each Interval/README_EN.md @@ -83,6 +83,8 @@ Returning table orderd by interval_no in ascending order. +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -110,6 +112,8 @@ WHERE minute % 6 = 0; +#### MySQL + ```sql SELECT FLOOR((minute + 5) / 6) AS interval_no, diff --git a/solution/2800-2899/2894.Divisible and Non-divisible Sums Difference/README.md b/solution/2800-2899/2894.Divisible and Non-divisible Sums Difference/README.md index f6b3495fbf746..d2cc4cc3864bd 100644 --- a/solution/2800-2899/2894.Divisible and Non-divisible Sums Difference/README.md +++ b/solution/2800-2899/2894.Divisible and Non-divisible Sums Difference/README.md @@ -88,12 +88,16 @@ tags: +#### Python3 + ```python class Solution: def differenceOfSums(self, n: int, m: int) -> int: return sum(i if i % m else -i for i in range(1, n + 1)) ``` +#### Java + ```java class Solution { public int differenceOfSums(int n, int m) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func differenceOfSums(n int, m int) (ans int) { for i := 1; i <= n; i++ { @@ -132,6 +140,8 @@ func differenceOfSums(n int, m int) (ans int) { } ``` +#### TypeScript + ```ts function differenceOfSums(n: number, m: number): number { let ans = 0; @@ -152,6 +162,8 @@ function differenceOfSums(n: number, m: number): number { +#### Java + ```java class Solution { public int differenceOfSums(int n, int m) { diff --git a/solution/2800-2899/2894.Divisible and Non-divisible Sums Difference/README_EN.md b/solution/2800-2899/2894.Divisible and Non-divisible Sums Difference/README_EN.md index 54bc1971f7ce0..8b631f8307b0c 100644 --- a/solution/2800-2899/2894.Divisible and Non-divisible Sums Difference/README_EN.md +++ b/solution/2800-2899/2894.Divisible and Non-divisible Sums Difference/README_EN.md @@ -86,12 +86,16 @@ The time complexity is $O(n)$, where $n$ is the given integer. The space complex +#### Python3 + ```python class Solution: def differenceOfSums(self, n: int, m: int) -> int: return sum(i if i % m else -i for i in range(1, n + 1)) ``` +#### Java + ```java class Solution { public int differenceOfSums(int n, int m) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func differenceOfSums(n int, m int) (ans int) { for i := 1; i <= n; i++ { @@ -130,6 +138,8 @@ func differenceOfSums(n int, m int) (ans int) { } ``` +#### TypeScript + ```ts function differenceOfSums(n: number, m: number): number { let ans = 0; @@ -150,6 +160,8 @@ function differenceOfSums(n: number, m: number): number { +#### Java + ```java class Solution { public int differenceOfSums(int n, int m) { diff --git a/solution/2800-2899/2895.Minimum Processing Time/README.md b/solution/2800-2899/2895.Minimum Processing Time/README.md index d5b76929525a6..6441d861a9c78 100644 --- a/solution/2800-2899/2895.Minimum Processing Time/README.md +++ b/solution/2800-2899/2895.Minimum Processing Time/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def minProcessingTime(self, processorTime: List[int], tasks: List[int]) -> int: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minProcessingTime(List processorTime, List tasks) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func minProcessingTime(processorTime []int, tasks []int) (ans int) { sort.Ints(processorTime) @@ -136,6 +144,8 @@ func minProcessingTime(processorTime []int, tasks []int) (ans int) { } ``` +#### TypeScript + ```ts function minProcessingTime(processorTime: number[], tasks: number[]): number { processorTime.sort((a, b) => a - b); diff --git a/solution/2800-2899/2895.Minimum Processing Time/README_EN.md b/solution/2800-2899/2895.Minimum Processing Time/README_EN.md index c584f1cc186d2..2e11fa806d460 100644 --- a/solution/2800-2899/2895.Minimum Processing Time/README_EN.md +++ b/solution/2800-2899/2895.Minimum Processing Time/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def minProcessingTime(self, processorTime: List[int], tasks: List[int]) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minProcessingTime(List processorTime, List tasks) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func minProcessingTime(processorTime []int, tasks []int) (ans int) { sort.Ints(processorTime) @@ -141,6 +149,8 @@ func minProcessingTime(processorTime []int, tasks []int) (ans int) { } ``` +#### TypeScript + ```ts function minProcessingTime(processorTime: number[], tasks: number[]): number { processorTime.sort((a, b) => a - b); diff --git a/solution/2800-2899/2896.Apply Operations to Make Two Strings Equal/README.md b/solution/2800-2899/2896.Apply Operations to Make Two Strings Equal/README.md index 128a0c62ecc58..d78ca52db46d4 100644 --- a/solution/2800-2899/2896.Apply Operations to Make Two Strings Equal/README.md +++ b/solution/2800-2899/2896.Apply Operations to Make Two Strings Equal/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class Solution: def minOperations(self, s1: str, s2: str, x: int) -> int: @@ -114,6 +116,8 @@ class Solution: return dfs(0, m - 1) ``` +#### Java + ```java class Solution { private List idx = new ArrayList<>(); @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -185,6 +191,8 @@ public: }; ``` +#### Go + ```go func minOperations(s1 string, s2 string, x int) int { idx := []int{} @@ -221,6 +229,8 @@ func minOperations(s1 string, s2 string, x int) int { } ``` +#### TypeScript + ```ts function minOperations(s1: string, s2: string, x: number): number { const idx: number[] = []; @@ -263,6 +273,8 @@ function minOperations(s1: string, s2: string, x: number): number { +#### Java + ```java class Solution { public int minOperations(String s1, String s2, int x) { diff --git a/solution/2800-2899/2896.Apply Operations to Make Two Strings Equal/README_EN.md b/solution/2800-2899/2896.Apply Operations to Make Two Strings Equal/README_EN.md index 73798907bbe57..05ed44cb0bd90 100644 --- a/solution/2800-2899/2896.Apply Operations to Make Two Strings Equal/README_EN.md +++ b/solution/2800-2899/2896.Apply Operations to Make Two Strings Equal/README_EN.md @@ -92,6 +92,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$. Here, $n$ +#### Python3 + ```python class Solution: def minOperations(self, s1: str, s2: str, x: int) -> int: @@ -112,6 +114,8 @@ class Solution: return dfs(0, m - 1) ``` +#### Java + ```java class Solution { private List idx = new ArrayList<>(); @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -183,6 +189,8 @@ public: }; ``` +#### Go + ```go func minOperations(s1 string, s2 string, x int) int { idx := []int{} @@ -219,6 +227,8 @@ func minOperations(s1 string, s2 string, x int) int { } ``` +#### TypeScript + ```ts function minOperations(s1: string, s2: string, x: number): number { const idx: number[] = []; @@ -261,6 +271,8 @@ function minOperations(s1: string, s2: string, x: number): number { +#### Java + ```java class Solution { public int minOperations(String s1, String s2, int x) { diff --git a/solution/2800-2899/2897.Apply Operations on Array to Maximize Sum of Squares/README.md b/solution/2800-2899/2897.Apply Operations on Array to Maximize Sum of Squares/README.md index e77198f14571d..823141e72cc2c 100644 --- a/solution/2800-2899/2897.Apply Operations on Array to Maximize Sum of Squares/README.md +++ b/solution/2800-2899/2897.Apply Operations on Array to Maximize Sum of Squares/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def maxSum(self, nums: List[int], k: int) -> int: @@ -104,6 +106,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxSum(List nums, int k) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func maxSum(nums []int, k int) (ans int) { cnt := [31]int{} @@ -186,6 +194,8 @@ func maxSum(nums []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function maxSum(nums: number[], k: number): number { const cnt: number[] = Array(31).fill(0); diff --git a/solution/2800-2899/2897.Apply Operations on Array to Maximize Sum of Squares/README_EN.md b/solution/2800-2899/2897.Apply Operations on Array to Maximize Sum of Squares/README_EN.md index 929f759c04cfc..259b35944606a 100644 --- a/solution/2800-2899/2897.Apply Operations on Array to Maximize Sum of Squares/README_EN.md +++ b/solution/2800-2899/2897.Apply Operations on Array to Maximize Sum of Squares/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n \times \log M)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def maxSum(self, nums: List[int], k: int) -> int: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxSum(List nums, int k) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func maxSum(nums []int, k int) (ans int) { cnt := [31]int{} @@ -184,6 +192,8 @@ func maxSum(nums []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function maxSum(nums: number[], k: number): number { const cnt: number[] = Array(31).fill(0); diff --git a/solution/2800-2899/2898.Maximum Linear Stock Score/README.md b/solution/2800-2899/2898.Maximum Linear Stock Score/README.md index ca6a94596045f..d152a7bcb538e 100644 --- a/solution/2800-2899/2898.Maximum Linear Stock Score/README.md +++ b/solution/2800-2899/2898.Maximum Linear Stock Score/README.md @@ -88,6 +88,8 @@ $$ +#### Python3 + ```python class Solution: def maxScore(self, prices: List[int]) -> int: @@ -97,6 +99,8 @@ class Solution: return max(cnt.values()) ``` +#### Java + ```java class Solution { public long maxScore(int[] prices) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func maxScore(prices []int) (ans int64) { cnt := map[int]int{} @@ -143,6 +151,8 @@ func maxScore(prices []int) (ans int64) { } ``` +#### TypeScript + ```ts function maxScore(prices: number[]): number { const cnt: Map = new Map(); @@ -154,6 +164,8 @@ function maxScore(prices: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/2800-2899/2898.Maximum Linear Stock Score/README_EN.md b/solution/2800-2899/2898.Maximum Linear Stock Score/README_EN.md index cbefc6025e626..d4ee0bc60269a 100644 --- a/solution/2800-2899/2898.Maximum Linear Stock Score/README_EN.md +++ b/solution/2800-2899/2898.Maximum Linear Stock Score/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python class Solution: def maxScore(self, prices: List[int]) -> int: @@ -95,6 +97,8 @@ class Solution: return max(cnt.values()) ``` +#### Java + ```java class Solution { public long maxScore(int[] prices) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func maxScore(prices []int) (ans int64) { cnt := map[int]int{} @@ -141,6 +149,8 @@ func maxScore(prices []int) (ans int64) { } ``` +#### TypeScript + ```ts function maxScore(prices: number[]): number { const cnt: Map = new Map(); @@ -152,6 +162,8 @@ function maxScore(prices: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/2800-2899/2899.Last Visited Integers/README.md b/solution/2800-2899/2899.Last Visited Integers/README.md index b1ecb84c4a79e..c030ac79f138e 100644 --- a/solution/2800-2899/2899.Last Visited Integers/README.md +++ b/solution/2800-2899/2899.Last Visited Integers/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def lastVisitedIntegers(self, words: List[str]) -> List[int]: @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List lastVisitedIntegers(List words) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func lastVisitedIntegers(words []string) (ans []int) { nums := []int{} @@ -171,6 +179,8 @@ func lastVisitedIntegers(words []string) (ans []int) { } ``` +#### TypeScript + ```ts function lastVisitedIntegers(words: string[]): number[] { const nums: number[] = []; @@ -190,6 +200,8 @@ function lastVisitedIntegers(words: string[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn last_visited_integers(words: Vec) -> Vec { diff --git a/solution/2800-2899/2899.Last Visited Integers/README_EN.md b/solution/2800-2899/2899.Last Visited Integers/README_EN.md index 6bc6e24927562..93a4dd14c1c3e 100644 --- a/solution/2800-2899/2899.Last Visited Integers/README_EN.md +++ b/solution/2800-2899/2899.Last Visited Integers/README_EN.md @@ -100,6 +100,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $words$. The +#### Python3 + ```python class Solution: def lastVisitedIntegers(self, words: List[str]) -> List[int]: @@ -117,6 +119,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List lastVisitedIntegers(List words) { @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func lastVisitedIntegers(words []string) (ans []int) { nums := []int{} @@ -183,6 +191,8 @@ func lastVisitedIntegers(words []string) (ans []int) { } ``` +#### TypeScript + ```ts function lastVisitedIntegers(words: string[]): number[] { const nums: number[] = []; @@ -202,6 +212,8 @@ function lastVisitedIntegers(words: string[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn last_visited_integers(words: Vec) -> Vec { diff --git a/solution/2900-2999/2900.Longest Unequal Adjacent Groups Subsequence I/README.md b/solution/2900-2999/2900.Longest Unequal Adjacent Groups Subsequence I/README.md index 4f3420f63e0b9..5d07d0d048caf 100644 --- a/solution/2900-2999/2900.Longest Unequal Adjacent Groups Subsequence I/README.md +++ b/solution/2900-2999/2900.Longest Unequal Adjacent Groups Subsequence I/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def getWordsInLongestSubsequence( @@ -91,6 +93,8 @@ class Solution: return [words[i] for i, x in enumerate(groups) if i == 0 or x != groups[i - 1]] ``` +#### Java + ```java class Solution { public List getWordsInLongestSubsequence(int n, String[] words, int[] groups) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func getWordsInLongestSubsequence(n int, words []string, groups []int) (ans []string) { for i, x := range groups { @@ -131,6 +139,8 @@ func getWordsInLongestSubsequence(n int, words []string, groups []int) (ans []st } ``` +#### TypeScript + ```ts function getWordsInLongestSubsequence(n: number, words: string[], groups: number[]): string[] { const ans: string[] = []; @@ -143,6 +153,8 @@ function getWordsInLongestSubsequence(n: number, words: string[], groups: number } ``` +#### Rust + ```rust impl Solution { pub fn get_words_in_longest_subsequence( diff --git a/solution/2900-2999/2900.Longest Unequal Adjacent Groups Subsequence I/README_EN.md b/solution/2900-2999/2900.Longest Unequal Adjacent Groups Subsequence I/README_EN.md index 007955705f003..d26df2cfd389f 100644 --- a/solution/2900-2999/2900.Longest Unequal Adjacent Groups Subsequence I/README_EN.md +++ b/solution/2900-2999/2900.Longest Unequal Adjacent Groups Subsequence I/README_EN.md @@ -107,6 +107,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $groups$. Th +#### Python3 + ```python class Solution: def getWordsInLongestSubsequence( @@ -115,6 +117,8 @@ class Solution: return [words[i] for i, x in enumerate(groups) if i == 0 or x != groups[i - 1]] ``` +#### Java + ```java class Solution { public List getWordsInLongestSubsequence(int n, String[] words, int[] groups) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func getWordsInLongestSubsequence(n int, words []string, groups []int) (ans []string) { for i, x := range groups { @@ -155,6 +163,8 @@ func getWordsInLongestSubsequence(n int, words []string, groups []int) (ans []st } ``` +#### TypeScript + ```ts function getWordsInLongestSubsequence(n: number, words: string[], groups: number[]): string[] { const ans: string[] = []; @@ -167,6 +177,8 @@ function getWordsInLongestSubsequence(n: number, words: string[], groups: number } ``` +#### Rust + ```rust impl Solution { pub fn get_words_in_longest_subsequence( diff --git a/solution/2900-2999/2901.Longest Unequal Adjacent Groups Subsequence II/README.md b/solution/2900-2999/2901.Longest Unequal Adjacent Groups Subsequence II/README.md index 2173ba7a22979..8582ac4ccd194 100644 --- a/solution/2900-2999/2901.Longest Unequal Adjacent Groups Subsequence II/README.md +++ b/solution/2900-2999/2901.Longest Unequal Adjacent Groups Subsequence II/README.md @@ -102,6 +102,8 @@ tags: +#### Python3 + ```python class Solution: def getWordsInLongestSubsequence( @@ -130,6 +132,8 @@ class Solution: return ans[::-1] ``` +#### Java + ```java class Solution { public List getWordsInLongestSubsequence(int n, String[] words, int[] groups) { @@ -175,6 +179,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -216,6 +222,8 @@ public: }; ``` +#### Go + ```go func getWordsInLongestSubsequence(n int, words []string, groups []int) []string { check := func(s, t string) bool { @@ -264,6 +272,8 @@ func getWordsInLongestSubsequence(n int, words []string, groups []int) []string } ``` +#### TypeScript + ```ts function getWordsInLongestSubsequence(n: number, words: string[], groups: number[]): string[] { const f: number[] = Array(n).fill(1); @@ -303,6 +313,8 @@ function getWordsInLongestSubsequence(n: number, words: string[], groups: number } ``` +#### Rust + ```rust impl Solution { pub fn get_words_in_longest_subsequence( @@ -367,6 +379,8 @@ impl Solution { +#### Java + ```java class Solution { public List getWordsInLongestSubsequence(int n, String[] words, int[] groups) { diff --git a/solution/2900-2999/2901.Longest Unequal Adjacent Groups Subsequence II/README_EN.md b/solution/2900-2999/2901.Longest Unequal Adjacent Groups Subsequence II/README_EN.md index a2ee4243b44ae..3ad9656b05d66 100644 --- a/solution/2900-2999/2901.Longest Unequal Adjacent Groups Subsequence II/README_EN.md +++ b/solution/2900-2999/2901.Longest Unequal Adjacent Groups Subsequence II/README_EN.md @@ -117,6 +117,8 @@ In **Solution 1**, we need to enumerate all $i$ and $j$ combinations, a step tha +#### Python3 + ```python class Solution: def getWordsInLongestSubsequence( @@ -145,6 +147,8 @@ class Solution: return ans[::-1] ``` +#### Java + ```java class Solution { public List getWordsInLongestSubsequence(int n, String[] words, int[] groups) { @@ -190,6 +194,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -231,6 +237,8 @@ public: }; ``` +#### Go + ```go func getWordsInLongestSubsequence(n int, words []string, groups []int) []string { check := func(s, t string) bool { @@ -279,6 +287,8 @@ func getWordsInLongestSubsequence(n int, words []string, groups []int) []string } ``` +#### TypeScript + ```ts function getWordsInLongestSubsequence(n: number, words: string[], groups: number[]): string[] { const f: number[] = Array(n).fill(1); @@ -318,6 +328,8 @@ function getWordsInLongestSubsequence(n: number, words: string[], groups: number } ``` +#### Rust + ```rust impl Solution { pub fn get_words_in_longest_subsequence( @@ -382,6 +394,8 @@ impl Solution { +#### Java + ```java class Solution { public List getWordsInLongestSubsequence(int n, String[] words, int[] groups) { diff --git a/solution/2900-2999/2902.Count of Sub-Multisets With Bounded Sum/README.md b/solution/2900-2999/2902.Count of Sub-Multisets With Bounded Sum/README.md index a08bbe3624f1a..5f9917abdf755 100644 --- a/solution/2900-2999/2902.Count of Sub-Multisets With Bounded Sum/README.md +++ b/solution/2900-2999/2902.Count of Sub-Multisets With Bounded Sum/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def countSubMultisets(self, nums: List[int], l: int, r: int) -> int: @@ -106,6 +108,8 @@ class Solution: return (zeros + 1) * sum(dp[l : r + 1]) % kMod ``` +#### Java + ```java class Solution { static final int MOD = 1_000_000_007; @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -183,6 +189,8 @@ public: }; ``` +#### Go + ```go func countSubMultisets(nums []int, l int, r int) int { multiset := make(map[int]int) @@ -217,6 +225,8 @@ func countSubMultisets(nums []int, l int, r int) int { var mod int = 1e9 + 7 ``` +#### TypeScript + ```ts function countSubMultisets(nums: number[], l: number, r: number): number { const cnt: number[] = Array(20001).fill(0); diff --git a/solution/2900-2999/2902.Count of Sub-Multisets With Bounded Sum/README_EN.md b/solution/2900-2999/2902.Count of Sub-Multisets With Bounded Sum/README_EN.md index 65ae3852394a3..f4faecef9db81 100644 --- a/solution/2900-2999/2902.Count of Sub-Multisets With Bounded Sum/README_EN.md +++ b/solution/2900-2999/2902.Count of Sub-Multisets With Bounded Sum/README_EN.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def countSubMultisets(self, nums: List[int], l: int, r: int) -> int: @@ -104,6 +106,8 @@ class Solution: return (zeros + 1) * sum(dp[l : r + 1]) % kMod ``` +#### Java + ```java class Solution { static final int MOD = 1_000_000_007; @@ -152,6 +156,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func countSubMultisets(nums []int, l int, r int) int { multiset := make(map[int]int) @@ -215,6 +223,8 @@ func countSubMultisets(nums []int, l int, r int) int { var mod int = 1e9 + 7 ``` +#### TypeScript + ```ts function countSubMultisets(nums: number[], l: number, r: number): number { const cnt: number[] = Array(20001).fill(0); diff --git a/solution/2900-2999/2903.Find Indices With Index and Value Difference I/README.md b/solution/2900-2999/2903.Find Indices With Index and Value Difference I/README.md index 35e50f8190a19..5b5e6bf156de9 100644 --- a/solution/2900-2999/2903.Find Indices With Index and Value Difference I/README.md +++ b/solution/2900-2999/2903.Find Indices With Index and Value Difference I/README.md @@ -96,6 +96,8 @@ abs(0 - 0) >= 0 且 abs(nums[0] - nums[0]) >= 0 。 +#### Python3 + ```python class Solution: def findIndices( @@ -115,6 +117,8 @@ class Solution: return [-1, -1] ``` +#### Java + ```java class Solution { public int[] findIndices(int[] nums, int indexDifference, int valueDifference) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func findIndices(nums []int, indexDifference int, valueDifference int) []int { mi, mx := 0, 0 @@ -187,6 +195,8 @@ func findIndices(nums []int, indexDifference int, valueDifference int) []int { } ``` +#### TypeScript + ```ts function findIndices(nums: number[], indexDifference: number, valueDifference: number): number[] { let [mi, mx] = [0, 0]; @@ -209,6 +219,8 @@ function findIndices(nums: number[], indexDifference: number, valueDifference: n } ``` +#### Rust + ```rust impl Solution { pub fn find_indices(nums: Vec, index_difference: i32, value_difference: i32) -> Vec { diff --git a/solution/2900-2999/2903.Find Indices With Index and Value Difference I/README_EN.md b/solution/2900-2999/2903.Find Indices With Index and Value Difference I/README_EN.md index 41563f9d239c0..d7a652865fc9a 100644 --- a/solution/2900-2999/2903.Find Indices With Index and Value Difference I/README_EN.md +++ b/solution/2900-2999/2903.Find Indices With Index and Value Difference I/README_EN.md @@ -93,6 +93,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def findIndices( @@ -112,6 +114,8 @@ class Solution: return [-1, -1] ``` +#### Java + ```java class Solution { public int[] findIndices(int[] nums, int indexDifference, int valueDifference) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func findIndices(nums []int, indexDifference int, valueDifference int) []int { mi, mx := 0, 0 @@ -184,6 +192,8 @@ func findIndices(nums []int, indexDifference int, valueDifference int) []int { } ``` +#### TypeScript + ```ts function findIndices(nums: number[], indexDifference: number, valueDifference: number): number[] { let [mi, mx] = [0, 0]; @@ -206,6 +216,8 @@ function findIndices(nums: number[], indexDifference: number, valueDifference: n } ``` +#### Rust + ```rust impl Solution { pub fn find_indices(nums: Vec, index_difference: i32, value_difference: i32) -> Vec { diff --git a/solution/2900-2999/2904.Shortest and Lexicographically Smallest Beautiful String/README.md b/solution/2900-2999/2904.Shortest and Lexicographically Smallest Beautiful String/README.md index 251833b764961..39594949b2794 100644 --- a/solution/2900-2999/2904.Shortest and Lexicographically Smallest Beautiful String/README.md +++ b/solution/2900-2999/2904.Shortest and Lexicographically Smallest Beautiful String/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class Solution: def shortestBeautifulSubstring(self, s: str, k: int) -> str: @@ -111,6 +113,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String shortestBeautifulSubstring(String s, int k) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func shortestBeautifulSubstring(s string, k int) (ans string) { n := len(s) @@ -176,6 +184,8 @@ func shortestBeautifulSubstring(s string, k int) (ans string) { } ``` +#### TypeScript + ```ts function shortestBeautifulSubstring(s: string, k: number): string { const n = s.length; @@ -196,6 +206,8 @@ function shortestBeautifulSubstring(s: string, k: number): string { } ``` +#### Rust + ```rust impl Solution { pub fn shortest_beautiful_substring(s: String, k: i32) -> String { @@ -236,6 +248,8 @@ impl Solution { +#### Python3 + ```python class Solution: def shortestBeautifulSubstring(self, s: str, k: int) -> str: @@ -255,6 +269,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String shortestBeautifulSubstring(String s, int k) { @@ -280,6 +296,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -303,6 +321,8 @@ public: }; ``` +#### Go + ```go func shortestBeautifulSubstring(s string, k int) (ans string) { i, j, cnt := 0, 0, 0 @@ -323,6 +343,8 @@ func shortestBeautifulSubstring(s string, k int) (ans string) { } ``` +#### TypeScript + ```ts function shortestBeautifulSubstring(s: string, k: number): string { let [i, j, cnt] = [0, 0, 0]; @@ -343,6 +365,8 @@ function shortestBeautifulSubstring(s: string, k: number): string { } ``` +#### Rust + ```rust impl Solution { pub fn shortest_beautiful_substring(s: String, k: i32) -> String { diff --git a/solution/2900-2999/2904.Shortest and Lexicographically Smallest Beautiful String/README_EN.md b/solution/2900-2999/2904.Shortest and Lexicographically Smallest Beautiful String/README_EN.md index 1fdec93fa858a..cef92f2bb7d1e 100644 --- a/solution/2900-2999/2904.Shortest and Lexicographically Smallest Beautiful String/README_EN.md +++ b/solution/2900-2999/2904.Shortest and Lexicographically Smallest Beautiful String/README_EN.md @@ -94,6 +94,8 @@ The time complexity is $O(n^3)$, and the space complexity is $O(n)$. Here, $n$ i +#### Python3 + ```python class Solution: def shortestBeautifulSubstring(self, s: str, k: int) -> str: @@ -109,6 +111,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String shortestBeautifulSubstring(String s, int k) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func shortestBeautifulSubstring(s string, k int) (ans string) { n := len(s) @@ -174,6 +182,8 @@ func shortestBeautifulSubstring(s string, k int) (ans string) { } ``` +#### TypeScript + ```ts function shortestBeautifulSubstring(s: string, k: number): string { const n = s.length; @@ -194,6 +204,8 @@ function shortestBeautifulSubstring(s: string, k: number): string { } ``` +#### Rust + ```rust impl Solution { pub fn shortest_beautiful_substring(s: String, k: i32) -> String { @@ -234,6 +246,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$. Here, $n$ i +#### Python3 + ```python class Solution: def shortestBeautifulSubstring(self, s: str, k: int) -> str: @@ -253,6 +267,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String shortestBeautifulSubstring(String s, int k) { @@ -278,6 +294,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -301,6 +319,8 @@ public: }; ``` +#### Go + ```go func shortestBeautifulSubstring(s string, k int) (ans string) { i, j, cnt := 0, 0, 0 @@ -321,6 +341,8 @@ func shortestBeautifulSubstring(s string, k int) (ans string) { } ``` +#### TypeScript + ```ts function shortestBeautifulSubstring(s: string, k: number): string { let [i, j, cnt] = [0, 0, 0]; @@ -341,6 +363,8 @@ function shortestBeautifulSubstring(s: string, k: number): string { } ``` +#### Rust + ```rust impl Solution { pub fn shortest_beautiful_substring(s: String, k: i32) -> String { diff --git a/solution/2900-2999/2905.Find Indices With Index and Value Difference II/README.md b/solution/2900-2999/2905.Find Indices With Index and Value Difference II/README.md index 4f01883889642..3f52288cd5b8f 100644 --- a/solution/2900-2999/2905.Find Indices With Index and Value Difference II/README.md +++ b/solution/2900-2999/2905.Find Indices With Index and Value Difference II/README.md @@ -86,6 +86,8 @@ abs(0 - 0) >= 0 且 abs(nums[0] - nums[0]) >= 0 。 +#### Python3 + ```python class Solution: def findIndices( @@ -105,6 +107,8 @@ class Solution: return [-1, -1] ``` +#### Java + ```java class Solution { public int[] findIndices(int[] nums, int indexDifference, int valueDifference) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func findIndices(nums []int, indexDifference int, valueDifference int) []int { mi, mx := 0, 0 @@ -177,6 +185,8 @@ func findIndices(nums []int, indexDifference int, valueDifference int) []int { } ``` +#### TypeScript + ```ts function findIndices(nums: number[], indexDifference: number, valueDifference: number): number[] { let [mi, mx] = [0, 0]; @@ -199,6 +209,8 @@ function findIndices(nums: number[], indexDifference: number, valueDifference: n } ``` +#### Rust + ```rust impl Solution { pub fn find_indices(nums: Vec, index_difference: i32, value_difference: i32) -> Vec { diff --git a/solution/2900-2999/2905.Find Indices With Index and Value Difference II/README_EN.md b/solution/2900-2999/2905.Find Indices With Index and Value Difference II/README_EN.md index 5526ce18def2a..2873420354f4e 100644 --- a/solution/2900-2999/2905.Find Indices With Index and Value Difference II/README_EN.md +++ b/solution/2900-2999/2905.Find Indices With Index and Value Difference II/README_EN.md @@ -83,6 +83,8 @@ Hence, [-1,-1] is returned. +#### Python3 + ```python class Solution: def findIndices( @@ -102,6 +104,8 @@ class Solution: return [-1, -1] ``` +#### Java + ```java class Solution { public int[] findIndices(int[] nums, int indexDifference, int valueDifference) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func findIndices(nums []int, indexDifference int, valueDifference int) []int { mi, mx := 0, 0 @@ -174,6 +182,8 @@ func findIndices(nums []int, indexDifference int, valueDifference int) []int { } ``` +#### TypeScript + ```ts function findIndices(nums: number[], indexDifference: number, valueDifference: number): number[] { let [mi, mx] = [0, 0]; @@ -196,6 +206,8 @@ function findIndices(nums: number[], indexDifference: number, valueDifference: n } ``` +#### Rust + ```rust impl Solution { pub fn find_indices(nums: Vec, index_difference: i32, value_difference: i32) -> Vec { diff --git a/solution/2900-2999/2906.Construct Product Matrix/README.md b/solution/2900-2999/2906.Construct Product Matrix/README.md index d580d537ff8b6..1166dce490b89 100644 --- a/solution/2900-2999/2906.Construct Product Matrix/README.md +++ b/solution/2900-2999/2906.Construct Product Matrix/README.md @@ -82,6 +82,8 @@ p[0][2] = grid[0][0] * grid[0][1] = 12345 * 2 = 24690. 24690 % 12345 = 0 ,所 +#### Python3 + ```python class Solution: def constructProductMatrix(self, grid: List[List[int]]) -> List[List[int]]: @@ -101,6 +103,8 @@ class Solution: return p ``` +#### Java + ```java class Solution { public int[][] constructProductMatrix(int[][] grid) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func constructProductMatrix(grid [][]int) [][]int { const mod int = 12345 @@ -178,6 +186,8 @@ func constructProductMatrix(grid [][]int) [][]int { } ``` +#### TypeScript + ```ts function constructProductMatrix(grid: number[][]): number[][] { const mod = 12345; @@ -201,6 +211,8 @@ function constructProductMatrix(grid: number[][]): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn construct_product_matrix(grid: Vec>) -> Vec> { diff --git a/solution/2900-2999/2906.Construct Product Matrix/README_EN.md b/solution/2900-2999/2906.Construct Product Matrix/README_EN.md index d65e69be32ad6..198acbcd2c94a 100644 --- a/solution/2900-2999/2906.Construct Product Matrix/README_EN.md +++ b/solution/2900-2999/2906.Construct Product Matrix/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(n \times m)$, where $n$ and $m$ are the number of rows +#### Python3 + ```python class Solution: def constructProductMatrix(self, grid: List[List[int]]) -> List[List[int]]: @@ -99,6 +101,8 @@ class Solution: return p ``` +#### Java + ```java class Solution { public int[][] constructProductMatrix(int[][] grid) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func constructProductMatrix(grid [][]int) [][]int { const mod int = 12345 @@ -176,6 +184,8 @@ func constructProductMatrix(grid [][]int) [][]int { } ``` +#### TypeScript + ```ts function constructProductMatrix(grid: number[][]): number[][] { const mod = 12345; @@ -199,6 +209,8 @@ function constructProductMatrix(grid: number[][]): number[][] { } ``` +#### Rust + ```rust impl Solution { pub fn construct_product_matrix(grid: Vec>) -> Vec> { diff --git a/solution/2900-2999/2907.Maximum Profitable Triplets With Increasing Prices I/README.md b/solution/2900-2999/2907.Maximum Profitable Triplets With Increasing Prices I/README.md index 608343775004b..2370cf6482615 100644 --- a/solution/2900-2999/2907.Maximum Profitable Triplets With Increasing Prices I/README.md +++ b/solution/2900-2999/2907.Maximum Profitable Triplets With Increasing Prices I/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def maxProfit(self, prices: List[int], profits: List[int]) -> int: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxProfit(int[] prices, int[] profits) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func maxProfit(prices []int, profits []int) int { n := len(prices) @@ -177,6 +185,8 @@ func maxProfit(prices []int, profits []int) int { } ``` +#### TypeScript + ```ts function maxProfit(prices: number[], profits: number[]): number { const n = prices.length; @@ -201,6 +211,8 @@ function maxProfit(prices: number[], profits: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_profit(prices: Vec, profits: Vec) -> i32 { @@ -249,6 +261,8 @@ impl Solution { +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n: int): @@ -291,6 +305,8 @@ class Solution: ) ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -350,6 +366,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { private: @@ -409,6 +427,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -468,6 +488,8 @@ func maxProfit(prices []int, profits []int) int { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; @@ -528,6 +550,8 @@ function maxProfit(prices: number[], profits: number[]): number { } ``` +#### Rust + ```rust struct BinaryIndexedTree { n: usize, @@ -605,6 +629,8 @@ impl Solution { +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n: int): @@ -649,6 +675,8 @@ class Solution: ) ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -725,6 +753,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { private: @@ -787,6 +817,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -856,6 +888,8 @@ func maxProfit(prices []int, profits []int) int { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; diff --git a/solution/2900-2999/2907.Maximum Profitable Triplets With Increasing Prices I/README_EN.md b/solution/2900-2999/2907.Maximum Profitable Triplets With Increasing Prices I/README_EN.md index ef165efa2f299..7f9fbb14e481a 100644 --- a/solution/2900-2999/2907.Maximum Profitable Triplets With Increasing Prices I/README_EN.md +++ b/solution/2900-2999/2907.Maximum Profitable Triplets With Increasing Prices I/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(n^2)$, where $n$ is the length of the array. The space +#### Python3 + ```python class Solution: def maxProfit(self, prices: List[int], profits: List[int]) -> int: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxProfit(int[] prices, int[] profits) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func maxProfit(prices []int, profits []int) int { n := len(prices) @@ -175,6 +183,8 @@ func maxProfit(prices []int, profits []int) int { } ``` +#### TypeScript + ```ts function maxProfit(prices: number[], profits: number[]): number { const n = prices.length; @@ -199,6 +209,8 @@ function maxProfit(prices: number[], profits: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_profit(prices: Vec, profits: Vec) -> i32 { @@ -247,6 +259,8 @@ Since the length of $prices$ does not exceed $2000$, and the value of $prices[i] +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n: int): @@ -289,6 +303,8 @@ class Solution: ) ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -348,6 +364,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { private: @@ -407,6 +425,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -466,6 +486,8 @@ func maxProfit(prices []int, profits []int) int { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; @@ -526,6 +548,8 @@ function maxProfit(prices: number[], profits: number[]): number { } ``` +#### Rust + ```rust struct BinaryIndexedTree { n: usize, @@ -603,6 +627,8 @@ impl Solution { +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n: int): @@ -647,6 +673,8 @@ class Solution: ) ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -723,6 +751,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { private: @@ -785,6 +815,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -854,6 +886,8 @@ func maxProfit(prices []int, profits []int) int { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; diff --git a/solution/2900-2999/2908.Minimum Sum of Mountain Triplets I/README.md b/solution/2900-2999/2908.Minimum Sum of Mountain Triplets I/README.md index ccb9c916299f9..22605f540a4bc 100644 --- a/solution/2900-2999/2908.Minimum Sum of Mountain Triplets I/README.md +++ b/solution/2900-2999/2908.Minimum Sum of Mountain Triplets I/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def minimumSum(self, nums: List[int]) -> int: @@ -103,6 +105,8 @@ class Solution: return -1 if ans == inf else ans ``` +#### Java + ```java class Solution { public int minimumSum(int[] nums) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func minimumSum(nums []int) int { n := len(nums) @@ -171,6 +179,8 @@ func minimumSum(nums []int) int { } ``` +#### TypeScript + ```ts function minimumSum(nums: number[]): number { const n = nums.length; diff --git a/solution/2900-2999/2908.Minimum Sum of Mountain Triplets I/README_EN.md b/solution/2900-2999/2908.Minimum Sum of Mountain Triplets I/README_EN.md index eec28bf0df47e..08e4279936024 100644 --- a/solution/2900-2999/2908.Minimum Sum of Mountain Triplets I/README_EN.md +++ b/solution/2900-2999/2908.Minimum Sum of Mountain Triplets I/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def minimumSum(self, nums: List[int]) -> int: @@ -101,6 +103,8 @@ class Solution: return -1 if ans == inf else ans ``` +#### Java + ```java class Solution { public int minimumSum(int[] nums) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func minimumSum(nums []int) int { n := len(nums) @@ -169,6 +177,8 @@ func minimumSum(nums []int) int { } ``` +#### TypeScript + ```ts function minimumSum(nums: number[]): number { const n = nums.length; diff --git a/solution/2900-2999/2909.Minimum Sum of Mountain Triplets II/README.md b/solution/2900-2999/2909.Minimum Sum of Mountain Triplets II/README.md index caeebe90df92b..ea24b4a19b3f5 100644 --- a/solution/2900-2999/2909.Minimum Sum of Mountain Triplets II/README.md +++ b/solution/2900-2999/2909.Minimum Sum of Mountain Triplets II/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def minimumSum(self, nums: List[int]) -> int: @@ -103,6 +105,8 @@ class Solution: return -1 if ans == inf else ans ``` +#### Java + ```java class Solution { public int minimumSum(int[] nums) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func minimumSum(nums []int) int { n := len(nums) @@ -171,6 +179,8 @@ func minimumSum(nums []int) int { } ``` +#### TypeScript + ```ts function minimumSum(nums: number[]): number { const n = nums.length; diff --git a/solution/2900-2999/2909.Minimum Sum of Mountain Triplets II/README_EN.md b/solution/2900-2999/2909.Minimum Sum of Mountain Triplets II/README_EN.md index 6f55b82edbc1b..27eb768a16a0e 100644 --- a/solution/2900-2999/2909.Minimum Sum of Mountain Triplets II/README_EN.md +++ b/solution/2900-2999/2909.Minimum Sum of Mountain Triplets II/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def minimumSum(self, nums: List[int]) -> int: @@ -101,6 +103,8 @@ class Solution: return -1 if ans == inf else ans ``` +#### Java + ```java class Solution { public int minimumSum(int[] nums) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func minimumSum(nums []int) int { n := len(nums) @@ -169,6 +177,8 @@ func minimumSum(nums []int) int { } ``` +#### TypeScript + ```ts function minimumSum(nums: number[]): number { const n = nums.length; diff --git a/solution/2900-2999/2910.Minimum Number of Groups to Create a Valid Assignment/README.md b/solution/2900-2999/2910.Minimum Number of Groups to Create a Valid Assignment/README.md index f6086b43b600d..637a5939e3183 100644 --- a/solution/2900-2999/2910.Minimum Number of Groups to Create a Valid Assignment/README.md +++ b/solution/2900-2999/2910.Minimum Number of Groups to Create a Valid Assignment/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def minGroupsForValidAssignment(self, nums: List[int]) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minGroupsForValidAssignment(int[] nums) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func minGroupsForValidAssignment(nums []int) int { cnt := map[int]int{} @@ -178,6 +186,8 @@ func minGroupsForValidAssignment(nums []int) int { } ``` +#### TypeScript + ```ts function minGroupsForValidAssignment(nums: number[]): number { const cnt: Map = new Map(); @@ -200,6 +210,8 @@ function minGroupsForValidAssignment(nums: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/2900-2999/2910.Minimum Number of Groups to Create a Valid Assignment/README_EN.md b/solution/2900-2999/2910.Minimum Number of Groups to Create a Valid Assignment/README_EN.md index 99f7df7965f8f..eb22d14c58cb9 100644 --- a/solution/2900-2999/2910.Minimum Number of Groups to Create a Valid Assignment/README_EN.md +++ b/solution/2900-2999/2910.Minimum Number of Groups to Create a Valid Assignment/README_EN.md @@ -97,6 +97,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def minGroupsForValidAssignment(self, nums: List[int]) -> int: @@ -112,6 +114,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minGroupsForValidAssignment(int[] nums) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go func minGroupsForValidAssignment(nums []int) int { cnt := map[int]int{} @@ -195,6 +203,8 @@ func minGroupsForValidAssignment(nums []int) int { } ``` +#### TypeScript + ```ts function minGroupsForValidAssignment(nums: number[]): number { const cnt: Map = new Map(); @@ -217,6 +227,8 @@ function minGroupsForValidAssignment(nums: number[]): number { } ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/2900-2999/2911.Minimum Changes to Make K Semi-palindromes/README.md b/solution/2900-2999/2911.Minimum Changes to Make K Semi-palindromes/README.md index 9950119b3e832..bee63bf8c3279 100644 --- a/solution/2900-2999/2911.Minimum Changes to Make K Semi-palindromes/README.md +++ b/solution/2900-2999/2911.Minimum Changes to Make K Semi-palindromes/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def minimumChanges(self, s: str, k: int) -> int: @@ -107,6 +109,8 @@ class Solution: return f[n][k] ``` +#### Java + ```java class Solution { public int minimumChanges(String s, int k) { @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go func minimumChanges(s string, k int) int { n := len(s) @@ -241,6 +249,8 @@ func minimumChanges(s string, k int) int { } ``` +#### TypeScript + ```ts function minimumChanges(s: string, k: number): number { const n = s.length; @@ -288,6 +298,8 @@ function minimumChanges(s: string, k: number): number { +#### Java + ```java class Solution { static int inf = 200; diff --git a/solution/2900-2999/2911.Minimum Changes to Make K Semi-palindromes/README_EN.md b/solution/2900-2999/2911.Minimum Changes to Make K Semi-palindromes/README_EN.md index d79f72b61b52d..46416931012aa 100644 --- a/solution/2900-2999/2911.Minimum Changes to Make K Semi-palindromes/README_EN.md +++ b/solution/2900-2999/2911.Minimum Changes to Make K Semi-palindromes/README_EN.md @@ -104,6 +104,8 @@ tags: +#### Python3 + ```python class Solution: def minimumChanges(self, s: str, k: int) -> int: @@ -132,6 +134,8 @@ class Solution: return f[n][k] ``` +#### Java + ```java class Solution { public int minimumChanges(String s, int k) { @@ -176,6 +180,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -218,6 +224,8 @@ public: }; ``` +#### Go + ```go func minimumChanges(s string, k int) int { n := len(s) @@ -266,6 +274,8 @@ func minimumChanges(s string, k int) int { } ``` +#### TypeScript + ```ts function minimumChanges(s: string, k: number): number { const n = s.length; @@ -313,6 +323,8 @@ function minimumChanges(s: string, k: number): number { +#### Java + ```java class Solution { static int inf = 200; diff --git a/solution/2900-2999/2912.Number of Ways to Reach Destination in the Grid/README.md b/solution/2900-2999/2912.Number of Ways to Reach Destination in the Grid/README.md index 4cff661960d9a..45a5638cf9771 100644 --- a/solution/2900-2999/2912.Number of Ways to Reach Destination in the Grid/README.md +++ b/solution/2900-2999/2912.Number of Ways to Reach Destination in the Grid/README.md @@ -106,6 +106,8 @@ $$ +#### Python3 + ```python class Solution: def numberOfWays( @@ -124,6 +126,8 @@ class Solution: return b if source[1] == dest[1] else d ``` +#### Python3 + ```python class Solution: def numberOfWays( @@ -143,6 +147,8 @@ class Solution: return f[1] if source[1] == dest[1] else f[3] ``` +#### Java + ```java class Solution { public int numberOfWays(int n, int m, int k, int[] source, int[] dest) { @@ -165,6 +171,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +196,8 @@ public: }; ``` +#### Go + ```go func numberOfWays(n int, m int, k int, source []int, dest []int) int { const mod int = 1e9 + 7 diff --git a/solution/2900-2999/2912.Number of Ways to Reach Destination in the Grid/README_EN.md b/solution/2900-2999/2912.Number of Ways to Reach Destination in the Grid/README_EN.md index d61ddd3b229d3..6271a72f42604 100644 --- a/solution/2900-2999/2912.Number of Ways to Reach Destination in the Grid/README_EN.md +++ b/solution/2900-2999/2912.Number of Ways to Reach Destination in the Grid/README_EN.md @@ -104,6 +104,8 @@ The time complexity is $O(k)$, where $k$ is the number of moves. The space compl +#### Python3 + ```python class Solution: def numberOfWays( @@ -122,6 +124,8 @@ class Solution: return b if source[1] == dest[1] else d ``` +#### Python3 + ```python class Solution: def numberOfWays( @@ -141,6 +145,8 @@ class Solution: return f[1] if source[1] == dest[1] else f[3] ``` +#### Java + ```java class Solution { public int numberOfWays(int n, int m, int k, int[] source, int[] dest) { @@ -163,6 +169,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -186,6 +194,8 @@ public: }; ``` +#### Go + ```go func numberOfWays(n int, m int, k int, source []int, dest []int) int { const mod int = 1e9 + 7 diff --git a/solution/2900-2999/2913.Subarrays Distinct Element Sum of Squares I/README.md b/solution/2900-2999/2913.Subarrays Distinct Element Sum of Squares I/README.md index 823d805dbdc73..17af2631c84f9 100644 --- a/solution/2900-2999/2913.Subarrays Distinct Element Sum of Squares I/README.md +++ b/solution/2900-2999/2913.Subarrays Distinct Element Sum of Squares I/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def sumCounts(self, nums: List[int]) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int sumCounts(List nums) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func sumCounts(nums []int) (ans int) { for i := range nums { @@ -157,6 +165,8 @@ func sumCounts(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function sumCounts(nums: number[]): number { let ans = 0; diff --git a/solution/2900-2999/2913.Subarrays Distinct Element Sum of Squares I/README_EN.md b/solution/2900-2999/2913.Subarrays Distinct Element Sum of Squares I/README_EN.md index 56bcb13c81609..038e987cf41c2 100644 --- a/solution/2900-2999/2913.Subarrays Distinct Element Sum of Squares I/README_EN.md +++ b/solution/2900-2999/2913.Subarrays Distinct Element Sum of Squares I/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$. Here, $n$ i +#### Python3 + ```python class Solution: def sumCounts(self, nums: List[int]) -> int: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int sumCounts(List nums) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func sumCounts(nums []int) (ans int) { for i := range nums { @@ -152,6 +160,8 @@ func sumCounts(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function sumCounts(nums: number[]): number { let ans = 0; diff --git a/solution/2900-2999/2914.Minimum Number of Changes to Make Binary String Beautiful/README.md b/solution/2900-2999/2914.Minimum Number of Changes to Make Binary String Beautiful/README.md index d35d68293cb78..c8b4e12185359 100644 --- a/solution/2900-2999/2914.Minimum Number of Changes to Make Binary String Beautiful/README.md +++ b/solution/2900-2999/2914.Minimum Number of Changes to Make Binary String Beautiful/README.md @@ -87,12 +87,16 @@ tags: +#### Python3 + ```python class Solution: def minChanges(self, s: str) -> int: return sum(s[i] != s[i - 1] for i in range(1, len(s), 2)) ``` +#### Java + ```java class Solution { public int minChanges(String s) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func minChanges(s string) (ans int) { for i := 1; i < len(s); i += 2 { @@ -132,6 +140,8 @@ func minChanges(s string) (ans int) { } ``` +#### TypeScript + ```ts function minChanges(s: string): number { let ans = 0; diff --git a/solution/2900-2999/2914.Minimum Number of Changes to Make Binary String Beautiful/README_EN.md b/solution/2900-2999/2914.Minimum Number of Changes to Make Binary String Beautiful/README_EN.md index 3ed7c55cd2923..a89b5f694a555 100644 --- a/solution/2900-2999/2914.Minimum Number of Changes to Make Binary String Beautiful/README_EN.md +++ b/solution/2900-2999/2914.Minimum Number of Changes to Make Binary String Beautiful/README_EN.md @@ -85,12 +85,16 @@ The time complexity is $O(n)$, where $n$ is the length of the string $s$. The sp +#### Python3 + ```python class Solution: def minChanges(self, s: str) -> int: return sum(s[i] != s[i - 1] for i in range(1, len(s), 2)) ``` +#### Java + ```java class Solution { public int minChanges(String s) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func minChanges(s string) (ans int) { for i := 1; i < len(s); i += 2 { @@ -130,6 +138,8 @@ func minChanges(s string) (ans int) { } ``` +#### TypeScript + ```ts function minChanges(s: string): number { let ans = 0; diff --git a/solution/2900-2999/2915.Length of the Longest Subsequence That Sums to Target/README.md b/solution/2900-2999/2915.Length of the Longest Subsequence That Sums to Target/README.md index fba5ab634504a..dcb4c2fcb1c76 100644 --- a/solution/2900-2999/2915.Length of the Longest Subsequence That Sums to Target/README.md +++ b/solution/2900-2999/2915.Length of the Longest Subsequence That Sums to Target/README.md @@ -85,6 +85,8 @@ $$ +#### Python3 + ```python class Solution: def lengthOfLongestSubsequence(self, nums: List[int], target: int) -> int: @@ -99,6 +101,8 @@ class Solution: return -1 if f[n][target] <= 0 else f[n][target] ``` +#### Java + ```java class Solution { public int lengthOfLongestSubsequence(List nums, int target) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func lengthOfLongestSubsequence(nums []int, target int) int { n := len(nums) @@ -172,6 +180,8 @@ func lengthOfLongestSubsequence(nums []int, target int) int { } ``` +#### TypeScript + ```ts function lengthOfLongestSubsequence(nums: number[], target: number): number { const n = nums.length; @@ -200,6 +210,8 @@ function lengthOfLongestSubsequence(nums: number[], target: number): number { +#### Python3 + ```python class Solution: def lengthOfLongestSubsequence(self, nums: List[int], target: int) -> int: @@ -210,6 +222,8 @@ class Solution: return -1 if f[-1] <= 0 else f[-1] ``` +#### Java + ```java class Solution { public int lengthOfLongestSubsequence(List nums, int target) { @@ -227,6 +241,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -244,6 +260,8 @@ public: }; ``` +#### Go + ```go func lengthOfLongestSubsequence(nums []int, target int) int { f := make([]int, target+1) @@ -263,6 +281,8 @@ func lengthOfLongestSubsequence(nums []int, target int) int { } ``` +#### TypeScript + ```ts function lengthOfLongestSubsequence(nums: number[], target: number): number { const f: number[] = Array(target + 1).fill(-Infinity); diff --git a/solution/2900-2999/2915.Length of the Longest Subsequence That Sums to Target/README_EN.md b/solution/2900-2999/2915.Length of the Longest Subsequence That Sums to Target/README_EN.md index f35eac9635edc..24a678d76996b 100644 --- a/solution/2900-2999/2915.Length of the Longest Subsequence That Sums to Target/README_EN.md +++ b/solution/2900-2999/2915.Length of the Longest Subsequence That Sums to Target/README_EN.md @@ -83,6 +83,8 @@ We notice that the state of $f[i][j]$ is only related to $f[i-1][\cdot]$, so we +#### Python3 + ```python class Solution: def lengthOfLongestSubsequence(self, nums: List[int], target: int) -> int: @@ -97,6 +99,8 @@ class Solution: return -1 if f[n][target] <= 0 else f[n][target] ``` +#### Java + ```java class Solution { public int lengthOfLongestSubsequence(List nums, int target) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func lengthOfLongestSubsequence(nums []int, target int) int { n := len(nums) @@ -170,6 +178,8 @@ func lengthOfLongestSubsequence(nums []int, target int) int { } ``` +#### TypeScript + ```ts function lengthOfLongestSubsequence(nums: number[], target: number): number { const n = nums.length; @@ -198,6 +208,8 @@ function lengthOfLongestSubsequence(nums: number[], target: number): number { +#### Python3 + ```python class Solution: def lengthOfLongestSubsequence(self, nums: List[int], target: int) -> int: @@ -208,6 +220,8 @@ class Solution: return -1 if f[-1] <= 0 else f[-1] ``` +#### Java + ```java class Solution { public int lengthOfLongestSubsequence(List nums, int target) { @@ -225,6 +239,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -242,6 +258,8 @@ public: }; ``` +#### Go + ```go func lengthOfLongestSubsequence(nums []int, target int) int { f := make([]int, target+1) @@ -261,6 +279,8 @@ func lengthOfLongestSubsequence(nums []int, target int) int { } ``` +#### TypeScript + ```ts function lengthOfLongestSubsequence(nums: number[], target: number): number { const f: number[] = Array(target + 1).fill(-Infinity); diff --git a/solution/2900-2999/2916.Subarrays Distinct Element Sum of Squares II/README.md b/solution/2900-2999/2916.Subarrays Distinct Element Sum of Squares II/README.md index 21bae998de3b4..87ba9977c5a60 100644 --- a/solution/2900-2999/2916.Subarrays Distinct Element Sum of Squares II/README.md +++ b/solution/2900-2999/2916.Subarrays Distinct Element Sum of Squares II/README.md @@ -83,18 +83,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2900-2999/2916.Subarrays Distinct Element Sum of Squares II/README_EN.md b/solution/2900-2999/2916.Subarrays Distinct Element Sum of Squares II/README_EN.md index f14897f770a7a..00b45bc92a4db 100644 --- a/solution/2900-2999/2916.Subarrays Distinct Element Sum of Squares II/README_EN.md +++ b/solution/2900-2999/2916.Subarrays Distinct Element Sum of Squares II/README_EN.md @@ -80,18 +80,26 @@ The sum of the squares of the distinct counts in all subarrays is equal to 1 +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/2900-2999/2917.Find the K-or of an Array/README.md b/solution/2900-2999/2917.Find the K-or of an Array/README.md index 550cbd43de2ea..5dea97f61ec64 100644 --- a/solution/2900-2999/2917.Find the K-or of an Array/README.md +++ b/solution/2900-2999/2917.Find the K-or of an Array/README.md @@ -140,6 +140,8 @@ tags: +#### Python3 + ```python class Solution: def findKOr(self, nums: List[int], k: int) -> int: @@ -151,6 +153,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findKOr(int[] nums, int k) { @@ -169,6 +173,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go func findKOr(nums []int, k int) (ans int) { for i := 0; i < 32; i++ { @@ -203,6 +211,8 @@ func findKOr(nums []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function findKOr(nums: number[], k: number): number { let ans = 0; @@ -219,6 +229,8 @@ function findKOr(nums: number[], k: number): number { } ``` +#### C# + ```cs public class Solution { public int FindKOr(int[] nums, int k) { diff --git a/solution/2900-2999/2917.Find the K-or of an Array/README_EN.md b/solution/2900-2999/2917.Find the K-or of an Array/README_EN.md index 956ec9a5a56e2..ec4b7f3050aec 100644 --- a/solution/2900-2999/2917.Find the K-or of an Array/README_EN.md +++ b/solution/2900-2999/2917.Find the K-or of an Array/README_EN.md @@ -145,6 +145,8 @@ The time complexity is $O(n \times \log M)$, where $n$ and $M$ are the length of +#### Python3 + ```python class Solution: def findKOr(self, nums: List[int], k: int) -> int: @@ -156,6 +158,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int findKOr(int[] nums, int k) { @@ -174,6 +178,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go func findKOr(nums []int, k int) (ans int) { for i := 0; i < 32; i++ { @@ -208,6 +216,8 @@ func findKOr(nums []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function findKOr(nums: number[], k: number): number { let ans = 0; @@ -224,6 +234,8 @@ function findKOr(nums: number[], k: number): number { } ``` +#### C# + ```cs public class Solution { public int FindKOr(int[] nums, int k) { diff --git a/solution/2900-2999/2918.Minimum Equal Sum of Two Arrays After Replacing Zeros/README.md b/solution/2900-2999/2918.Minimum Equal Sum of Two Arrays After Replacing Zeros/README.md index d51199630b351..296300d0ecda4 100644 --- a/solution/2900-2999/2918.Minimum Equal Sum of Two Arrays After Replacing Zeros/README.md +++ b/solution/2900-2999/2918.Minimum Equal Sum of Two Arrays After Replacing Zeros/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def minSum(self, nums1: List[int], nums2: List[int]) -> int: @@ -84,6 +86,8 @@ class Solution: return -1 if nums1.count(0) == 0 else s2 ``` +#### Java + ```java class Solution { public long minSum(int[] nums1, int[] nums2) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func minSum(nums1 []int, nums2 []int) int64 { s1, s2 := 0, 0 @@ -157,6 +165,8 @@ func minSum(nums1 []int, nums2 []int) int64 { } ``` +#### TypeScript + ```ts function minSum(nums1: number[], nums2: number[]): number { let [s1, s2] = [0, 0]; @@ -180,6 +190,8 @@ function minSum(nums1: number[], nums2: number[]): number { } ``` +#### C# + ```cs public class Solution { public long MinSum(int[] nums1, int[] nums2) { diff --git a/solution/2900-2999/2918.Minimum Equal Sum of Two Arrays After Replacing Zeros/README_EN.md b/solution/2900-2999/2918.Minimum Equal Sum of Two Arrays After Replacing Zeros/README_EN.md index 3cfb52276371d..1ce130ecca834 100644 --- a/solution/2900-2999/2918.Minimum Equal Sum of Two Arrays After Replacing Zeros/README_EN.md +++ b/solution/2900-2999/2918.Minimum Equal Sum of Two Arrays After Replacing Zeros/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n + m)$, where $n$ and $m$ are the lengths of the arra +#### Python3 + ```python class Solution: def minSum(self, nums1: List[int], nums2: List[int]) -> int: @@ -82,6 +84,8 @@ class Solution: return -1 if nums1.count(0) == 0 else s2 ``` +#### Java + ```java class Solution { public long minSum(int[] nums1, int[] nums2) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func minSum(nums1 []int, nums2 []int) int64 { s1, s2 := 0, 0 @@ -155,6 +163,8 @@ func minSum(nums1 []int, nums2 []int) int64 { } ``` +#### TypeScript + ```ts function minSum(nums1: number[], nums2: number[]): number { let [s1, s2] = [0, 0]; @@ -178,6 +188,8 @@ function minSum(nums1: number[], nums2: number[]): number { } ``` +#### C# + ```cs public class Solution { public long MinSum(int[] nums1, int[] nums2) { diff --git a/solution/2900-2999/2919.Minimum Increment Operations to Make Array Beautiful/README.md b/solution/2900-2999/2919.Minimum Increment Operations to Make Array Beautiful/README.md index bd68680dc1543..76794cf2c5f4a 100644 --- a/solution/2900-2999/2919.Minimum Increment Operations to Make Array Beautiful/README.md +++ b/solution/2900-2999/2919.Minimum Increment Operations to Make Array Beautiful/README.md @@ -110,6 +110,8 @@ $$ +#### Python3 + ```python class Solution: def minIncrementOperations(self, nums: List[int], k: int) -> int: @@ -119,6 +121,8 @@ class Solution: return min(f, g, h) ``` +#### Java + ```java class Solution { public long minIncrementOperations(int[] nums, int k) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func minIncrementOperations(nums []int, k int) int64 { var f, g, h int @@ -160,6 +168,8 @@ func minIncrementOperations(nums []int, k int) int64 { } ``` +#### TypeScript + ```ts function minIncrementOperations(nums: number[], k: number): number { let [f, g, h] = [0, 0, 0]; @@ -170,6 +180,8 @@ function minIncrementOperations(nums: number[], k: number): number { } ``` +#### C# + ```cs public class Solution { public long MinIncrementOperations(int[] nums, int k) { diff --git a/solution/2900-2999/2919.Minimum Increment Operations to Make Array Beautiful/README_EN.md b/solution/2900-2999/2919.Minimum Increment Operations to Make Array Beautiful/README_EN.md index c9c3bfba3b074..994579d1d6f2c 100644 --- a/solution/2900-2999/2919.Minimum Increment Operations to Make Array Beautiful/README_EN.md +++ b/solution/2900-2999/2919.Minimum Increment Operations to Make Array Beautiful/README_EN.md @@ -108,6 +108,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def minIncrementOperations(self, nums: List[int], k: int) -> int: @@ -117,6 +119,8 @@ class Solution: return min(f, g, h) ``` +#### Java + ```java class Solution { public long minIncrementOperations(int[] nums, int k) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func minIncrementOperations(nums []int, k int) int64 { var f, g, h int @@ -158,6 +166,8 @@ func minIncrementOperations(nums []int, k int) int64 { } ``` +#### TypeScript + ```ts function minIncrementOperations(nums: number[], k: number): number { let [f, g, h] = [0, 0, 0]; @@ -168,6 +178,8 @@ function minIncrementOperations(nums: number[], k: number): number { } ``` +#### C# + ```cs public class Solution { public long MinIncrementOperations(int[] nums, int k) { diff --git a/solution/2900-2999/2920.Maximum Points After Collecting Coins From All Nodes/README.md b/solution/2900-2999/2920.Maximum Points After Collecting Coins From All Nodes/README.md index a6831109d38e8..24490f679c037 100644 --- a/solution/2900-2999/2920.Maximum Points After Collecting Coins From All Nodes/README.md +++ b/solution/2900-2999/2920.Maximum Points After Collecting Coins From All Nodes/README.md @@ -99,6 +99,8 @@ tags: +#### Python3 + ```python class Solution: def maximumPoints(self, edges: List[List[int]], coins: List[int], k: int) -> int: @@ -123,6 +125,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int k; @@ -164,6 +168,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -198,6 +204,8 @@ public: }; ``` +#### Go + ```go func maximumPoints(edges [][]int, coins []int, k int) int { n := len(coins) @@ -236,6 +244,8 @@ func maximumPoints(edges [][]int, coins []int, k int) int { } ``` +#### TypeScript + ```ts function maximumPoints(edges: number[][], coins: number[], k: number): number { const n = coins.length; diff --git a/solution/2900-2999/2920.Maximum Points After Collecting Coins From All Nodes/README_EN.md b/solution/2900-2999/2920.Maximum Points After Collecting Coins From All Nodes/README_EN.md index 601400a16e393..c717dc6955ba8 100644 --- a/solution/2900-2999/2920.Maximum Points After Collecting Coins From All Nodes/README_EN.md +++ b/solution/2900-2999/2920.Maximum Points After Collecting Coins From All Nodes/README_EN.md @@ -97,6 +97,8 @@ The time complexity is $O(n \times \log M)$, and the space complexity is $O(n \t +#### Python3 + ```python class Solution: def maximumPoints(self, edges: List[List[int]], coins: List[int], k: int) -> int: @@ -121,6 +123,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int k; @@ -162,6 +166,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -196,6 +202,8 @@ public: }; ``` +#### Go + ```go func maximumPoints(edges [][]int, coins []int, k int) int { n := len(coins) @@ -234,6 +242,8 @@ func maximumPoints(edges [][]int, coins []int, k int) int { } ``` +#### TypeScript + ```ts function maximumPoints(edges: number[][], coins: number[], k: number): number { const n = coins.length; diff --git a/solution/2900-2999/2921.Maximum Profitable Triplets With Increasing Prices II/README.md b/solution/2900-2999/2921.Maximum Profitable Triplets With Increasing Prices II/README.md index a9e32c366373c..335da8bb8f3e1 100644 --- a/solution/2900-2999/2921.Maximum Profitable Triplets With Increasing Prices II/README.md +++ b/solution/2900-2999/2921.Maximum Profitable Triplets With Increasing Prices II/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n: int): @@ -124,6 +126,8 @@ class Solution: ) ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -183,6 +187,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { private: @@ -242,6 +248,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -301,6 +309,8 @@ func maxProfit(prices []int, profits []int) int { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; @@ -361,6 +371,8 @@ function maxProfit(prices: number[], profits: number[]): number { } ``` +#### Rust + ```rust struct BinaryIndexedTree { n: usize, diff --git a/solution/2900-2999/2921.Maximum Profitable Triplets With Increasing Prices II/README_EN.md b/solution/2900-2999/2921.Maximum Profitable Triplets With Increasing Prices II/README_EN.md index 921e22d8fe526..ec6a348c3790a 100644 --- a/solution/2900-2999/2921.Maximum Profitable Triplets With Increasing Prices II/README_EN.md +++ b/solution/2900-2999/2921.Maximum Profitable Triplets With Increasing Prices II/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(n \times \log M)$, and the space complexity is $O(M)$. +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n: int): @@ -122,6 +124,8 @@ class Solution: ) ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -181,6 +185,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { private: @@ -240,6 +246,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -299,6 +307,8 @@ func maxProfit(prices []int, profits []int) int { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; @@ -359,6 +369,8 @@ function maxProfit(prices: number[], profits: number[]): number { } ``` +#### Rust + ```rust struct BinaryIndexedTree { n: usize, diff --git a/solution/2900-2999/2922.Market Analysis III/README.md b/solution/2900-2999/2922.Market Analysis III/README.md index 330e9354d8a9f..d93f19aef3221 100644 --- a/solution/2900-2999/2922.Market Analysis III/README.md +++ b/solution/2900-2999/2922.Market Analysis III/README.md @@ -122,6 +122,8 @@ Items table: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2900-2999/2922.Market Analysis III/README_EN.md b/solution/2900-2999/2922.Market Analysis III/README_EN.md index 19de31f952fad..8465b4f70f22b 100644 --- a/solution/2900-2999/2922.Market Analysis III/README_EN.md +++ b/solution/2900-2999/2922.Market Analysis III/README_EN.md @@ -120,6 +120,8 @@ We can use equijoin to connect the `Orders` table and the `Users` table accordin +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2900-2999/2923.Find Champion I/README.md b/solution/2900-2999/2923.Find Champion I/README.md index 7f6d0bb508d9e..218b7781cb9e2 100644 --- a/solution/2900-2999/2923.Find Champion I/README.md +++ b/solution/2900-2999/2923.Find Champion I/README.md @@ -77,6 +77,8 @@ grid[1][2] == 1 表示 1 队比 2 队强。 +#### Python3 + ```python class Solution: def findChampion(self, grid: List[List[int]]) -> int: @@ -85,6 +87,8 @@ class Solution: return i ``` +#### Java + ```java class Solution { public int findChampion(int[][] grid) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func findChampion(grid [][]int) int { n := len(grid) @@ -141,6 +149,8 @@ func findChampion(grid [][]int) int { } ``` +#### TypeScript + ```ts function findChampion(grid: number[][]): number { for (let i = 0, n = grid.length; ; ++i) { diff --git a/solution/2900-2999/2923.Find Champion I/README_EN.md b/solution/2900-2999/2923.Find Champion I/README_EN.md index 06866b6777cc0..ceb0b74f2edeb 100644 --- a/solution/2900-2999/2923.Find Champion I/README_EN.md +++ b/solution/2900-2999/2923.Find Champion I/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(n^2)$, where $n$ is the number of teams. The space com +#### Python3 + ```python class Solution: def findChampion(self, grid: List[List[int]]) -> int: @@ -83,6 +85,8 @@ class Solution: return i ``` +#### Java + ```java class Solution { public int findChampion(int[][] grid) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func findChampion(grid [][]int) int { n := len(grid) @@ -139,6 +147,8 @@ func findChampion(grid [][]int) int { } ``` +#### TypeScript + ```ts function findChampion(grid: number[][]): number { for (let i = 0, n = grid.length; ; ++i) { diff --git a/solution/2900-2999/2924.Find Champion II/README.md b/solution/2900-2999/2924.Find Champion II/README.md index f6b59665e4f81..06297b5a2df91 100644 --- a/solution/2900-2999/2924.Find Champion II/README.md +++ b/solution/2900-2999/2924.Find Champion II/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def findChampion(self, n: int, edges: List[List[int]]) -> int: @@ -95,6 +97,8 @@ class Solution: return -1 if indeg.count(0) != 1 else indeg.index(0) ``` +#### Java + ```java class Solution { public int findChampion(int n, int[][] edges) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func findChampion(n int, edges [][]int) int { indeg := make([]int, n) @@ -155,6 +163,8 @@ func findChampion(n int, edges [][]int) int { } ``` +#### TypeScript + ```ts function findChampion(n: number, edges: number[][]): number { const indeg: number[] = Array(n).fill(0); diff --git a/solution/2900-2999/2924.Find Champion II/README_EN.md b/solution/2900-2999/2924.Find Champion II/README_EN.md index 6e2c29de00df7..24c47c075f9de 100644 --- a/solution/2900-2999/2924.Find Champion II/README_EN.md +++ b/solution/2900-2999/2924.Find Champion II/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def findChampion(self, n: int, edges: List[List[int]]) -> int: @@ -93,6 +95,8 @@ class Solution: return -1 if indeg.count(0) != 1 else indeg.index(0) ``` +#### Java + ```java class Solution { public int findChampion(int n, int[][] edges) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func findChampion(n int, edges [][]int) int { indeg := make([]int, n) @@ -153,6 +161,8 @@ func findChampion(n int, edges [][]int) int { } ``` +#### TypeScript + ```ts function findChampion(n: number, edges: number[][]): number { const indeg: number[] = Array(n).fill(0); diff --git a/solution/2900-2999/2925.Maximum Score After Applying Operations on a Tree/README.md b/solution/2900-2999/2925.Maximum Score After Applying Operations on a Tree/README.md index a391f1d2df979..b5bb225ce1d7c 100644 --- a/solution/2900-2999/2925.Maximum Score After Applying Operations on a Tree/README.md +++ b/solution/2900-2999/2925.Maximum Score After Applying Operations on a Tree/README.md @@ -103,6 +103,8 @@ tags: +#### Python3 + ```python class Solution: def maximumScoreAfterOperations( @@ -128,6 +130,8 @@ class Solution: return dfs(0)[1] ``` +#### Java + ```java class Solution { private List[] g; @@ -165,6 +169,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -199,6 +205,8 @@ public: }; ``` +#### Go + ```go func maximumScoreAfterOperations(edges [][]int, values []int) int64 { g := make([][]int, len(values)) @@ -229,6 +237,8 @@ func maximumScoreAfterOperations(edges [][]int, values []int) int64 { } ``` +#### TypeScript + ```ts function maximumScoreAfterOperations(edges: number[][], values: number[]): number { const g: number[][] = Array.from({ length: values.length }, () => []); diff --git a/solution/2900-2999/2925.Maximum Score After Applying Operations on a Tree/README_EN.md b/solution/2900-2999/2925.Maximum Score After Applying Operations on a Tree/README_EN.md index ed7a7bd1e499f..46768b0844d2e 100644 --- a/solution/2900-2999/2925.Maximum Score After Applying Operations on a Tree/README_EN.md +++ b/solution/2900-2999/2925.Maximum Score After Applying Operations on a Tree/README_EN.md @@ -97,6 +97,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def maximumScoreAfterOperations( @@ -122,6 +124,8 @@ class Solution: return dfs(0)[1] ``` +#### Java + ```java class Solution { private List[] g; @@ -159,6 +163,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go func maximumScoreAfterOperations(edges [][]int, values []int) int64 { g := make([][]int, len(values)) @@ -223,6 +231,8 @@ func maximumScoreAfterOperations(edges [][]int, values []int) int64 { } ``` +#### TypeScript + ```ts function maximumScoreAfterOperations(edges: number[][], values: number[]): number { const g: number[][] = Array.from({ length: values.length }, () => []); diff --git a/solution/2900-2999/2926.Maximum Balanced Subsequence Sum/README.md b/solution/2900-2999/2926.Maximum Balanced Subsequence Sum/README.md index c14aaa6558c79..e6a67fb64b8b7 100644 --- a/solution/2900-2999/2926.Maximum Balanced Subsequence Sum/README.md +++ b/solution/2900-2999/2926.Maximum Balanced Subsequence Sum/README.md @@ -107,6 +107,8 @@ $$ +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n: int): @@ -138,6 +140,8 @@ class Solution: return tree.query(len(s)) ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -205,6 +209,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { private: @@ -257,6 +263,8 @@ public: }; ``` +#### Go + ```go const inf int = 1e18 @@ -314,6 +322,8 @@ func maxBalancedSubsequenceSum(nums []int) int64 { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; diff --git a/solution/2900-2999/2926.Maximum Balanced Subsequence Sum/README_EN.md b/solution/2900-2999/2926.Maximum Balanced Subsequence Sum/README_EN.md index 648b612564b35..442664aa6c140 100644 --- a/solution/2900-2999/2926.Maximum Balanced Subsequence Sum/README_EN.md +++ b/solution/2900-2999/2926.Maximum Balanced Subsequence Sum/README_EN.md @@ -105,6 +105,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class BinaryIndexedTree: def __init__(self, n: int): @@ -136,6 +138,8 @@ class Solution: return tree.query(len(s)) ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -203,6 +207,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { private: @@ -255,6 +261,8 @@ public: }; ``` +#### Go + ```go const inf int = 1e18 @@ -312,6 +320,8 @@ func maxBalancedSubsequenceSum(nums []int) int64 { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; diff --git a/solution/2900-2999/2927.Distribute Candies Among Children III/README.md b/solution/2900-2999/2927.Distribute Candies Among Children III/README.md index 250f79a2dd4e9..b14fc377cbc0f 100644 --- a/solution/2900-2999/2927.Distribute Candies Among Children III/README.md +++ b/solution/2900-2999/2927.Distribute Candies Among Children III/README.md @@ -66,6 +66,8 @@ tags: +#### Python3 + ```python class Solution: def distributeCandies(self, n: int, limit: int) -> int: @@ -79,6 +81,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long distributeCandies(int n, int limit) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func distributeCandies(n int, limit int) int64 { comb2 := func(n int) int { @@ -142,6 +150,8 @@ func distributeCandies(n int, limit int) int64 { } ``` +#### TypeScript + ```ts function distributeCandies(n: number, limit: number): number { const comb2 = (n: number) => (n * (n - 1)) / 2; diff --git a/solution/2900-2999/2927.Distribute Candies Among Children III/README_EN.md b/solution/2900-2999/2927.Distribute Candies Among Children III/README_EN.md index bd1cb7659bcc0..1737007c66894 100644 --- a/solution/2900-2999/2927.Distribute Candies Among Children III/README_EN.md +++ b/solution/2900-2999/2927.Distribute Candies Among Children III/README_EN.md @@ -64,6 +64,8 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def distributeCandies(self, n: int, limit: int) -> int: @@ -77,6 +79,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long distributeCandies(int n, int limit) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func distributeCandies(n int, limit int) int64 { comb2 := func(n int) int { @@ -140,6 +148,8 @@ func distributeCandies(n int, limit int) int64 { } ``` +#### TypeScript + ```ts function distributeCandies(n: number, limit: number): number { const comb2 = (n: number) => (n * (n - 1)) / 2; diff --git a/solution/2900-2999/2928.Distribute Candies Among Children I/README.md b/solution/2900-2999/2928.Distribute Candies Among Children I/README.md index 9608c4f64a7a2..72a766e34781f 100644 --- a/solution/2900-2999/2928.Distribute Candies Among Children I/README.md +++ b/solution/2900-2999/2928.Distribute Candies Among Children I/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def distributeCandies(self, n: int, limit: int) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int distributeCandies(int n, int limit) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func distributeCandies(n int, limit int) int { comb2 := func(n int) int { @@ -145,6 +153,8 @@ func distributeCandies(n int, limit int) int { } ``` +#### TypeScript + ```ts function distributeCandies(n: number, limit: number): number { const comb2 = (n: number) => (n * (n - 1)) / 2; diff --git a/solution/2900-2999/2928.Distribute Candies Among Children I/README_EN.md b/solution/2900-2999/2928.Distribute Candies Among Children I/README_EN.md index 8958a85401650..348abf02cfd8a 100644 --- a/solution/2900-2999/2928.Distribute Candies Among Children I/README_EN.md +++ b/solution/2900-2999/2928.Distribute Candies Among Children I/README_EN.md @@ -67,6 +67,8 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def distributeCandies(self, n: int, limit: int) -> int: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int distributeCandies(int n, int limit) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func distributeCandies(n int, limit int) int { comb2 := func(n int) int { @@ -143,6 +151,8 @@ func distributeCandies(n int, limit int) int { } ``` +#### TypeScript + ```ts function distributeCandies(n: number, limit: number): number { const comb2 = (n: number) => (n * (n - 1)) / 2; diff --git a/solution/2900-2999/2929.Distribute Candies Among Children II/README.md b/solution/2900-2999/2929.Distribute Candies Among Children II/README.md index 20a2f485dba64..36ac2fc4a6239 100644 --- a/solution/2900-2999/2929.Distribute Candies Among Children II/README.md +++ b/solution/2900-2999/2929.Distribute Candies Among Children II/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def distributeCandies(self, n: int, limit: int) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long distributeCandies(int n, int limit) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func distributeCandies(n int, limit int) int64 { comb2 := func(n int) int { @@ -145,6 +153,8 @@ func distributeCandies(n int, limit int) int64 { } ``` +#### TypeScript + ```ts function distributeCandies(n: number, limit: number): number { const comb2 = (n: number) => (n * (n - 1)) / 2; diff --git a/solution/2900-2999/2929.Distribute Candies Among Children II/README_EN.md b/solution/2900-2999/2929.Distribute Candies Among Children II/README_EN.md index 9c200536eafb9..e6da8d83b3c2b 100644 --- a/solution/2900-2999/2929.Distribute Candies Among Children II/README_EN.md +++ b/solution/2900-2999/2929.Distribute Candies Among Children II/README_EN.md @@ -67,6 +67,8 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def distributeCandies(self, n: int, limit: int) -> int: @@ -80,6 +82,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long distributeCandies(int n, int limit) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func distributeCandies(n int, limit int) int64 { comb2 := func(n int) int { @@ -143,6 +151,8 @@ func distributeCandies(n int, limit int) int64 { } ``` +#### TypeScript + ```ts function distributeCandies(n: number, limit: number): number { const comb2 = (n: number) => (n * (n - 1)) / 2; diff --git a/solution/2900-2999/2930.Number of Strings Which Can Be Rearranged to Contain Substring/README.md b/solution/2900-2999/2930.Number of Strings Which Can Be Rearranged to Contain Substring/README.md index 617db8250bd94..fd99eafdbd5e9 100644 --- a/solution/2900-2999/2930.Number of Strings Which Can Be Rearranged to Contain Substring/README.md +++ b/solution/2900-2999/2930.Number of Strings Which Can Be Rearranged to Contain Substring/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def stringCount(self, n: int) -> int: @@ -104,6 +106,8 @@ class Solution: return dfs(n, 0, 0, 0) ``` +#### Java + ```java class Solution { private final int mod = (int) 1e9 + 7; @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func stringCount(n int) int { const mod int = 1e9 + 7 @@ -190,6 +198,8 @@ func stringCount(n int) int { } ``` +#### TypeScript + ```ts function stringCount(n: number): number { const mod = 10 ** 9 + 7; @@ -243,6 +253,8 @@ function stringCount(n: number): number { +#### Python3 + ```python class Solution: def stringCount(self, n: int) -> int: @@ -256,6 +268,8 @@ class Solution: return (tot - (a + b + c - ab - ac - bc + abc)) % mod ``` +#### Java + ```java class Solution { private final int mod = (int) 1e9 + 7; @@ -285,6 +299,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -314,6 +330,8 @@ public: }; ``` +#### Go + ```go func stringCount(n int) int { const mod int = 1e9 + 7 @@ -339,6 +357,8 @@ func stringCount(n int) int { } ``` +#### TypeScript + ```ts function stringCount(n: number): number { const mod = BigInt(10 ** 9 + 7); diff --git a/solution/2900-2999/2930.Number of Strings Which Can Be Rearranged to Contain Substring/README_EN.md b/solution/2900-2999/2930.Number of Strings Which Can Be Rearranged to Contain Substring/README_EN.md index 94ef24139c54c..b1c606990b1a1 100644 --- a/solution/2900-2999/2930.Number of Strings Which Can Be Rearranged to Contain Substring/README_EN.md +++ b/solution/2900-2999/2930.Number of Strings Which Can Be Rearranged to Contain Substring/README_EN.md @@ -87,6 +87,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def stringCount(self, n: int) -> int: @@ -104,6 +106,8 @@ class Solution: return dfs(n, 0, 0, 0) ``` +#### Java + ```java class Solution { private final int mod = (int) 1e9 + 7; @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func stringCount(n int) int { const mod int = 1e9 + 7 @@ -190,6 +198,8 @@ func stringCount(n int) int { } ``` +#### TypeScript + ```ts function stringCount(n: number): number { const mod = 10 ** 9 + 7; @@ -243,6 +253,8 @@ The time complexity is $O(\log n)$, and the space complexity is $O(1)$. Here, $n +#### Python3 + ```python class Solution: def stringCount(self, n: int) -> int: @@ -256,6 +268,8 @@ class Solution: return (tot - (a + b + c - ab - ac - bc + abc)) % mod ``` +#### Java + ```java class Solution { private final int mod = (int) 1e9 + 7; @@ -285,6 +299,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -314,6 +330,8 @@ public: }; ``` +#### Go + ```go func stringCount(n int) int { const mod int = 1e9 + 7 @@ -339,6 +357,8 @@ func stringCount(n int) int { } ``` +#### TypeScript + ```ts function stringCount(n: number): number { const mod = BigInt(10 ** 9 + 7); diff --git a/solution/2900-2999/2931.Maximum Spending After Buying Items/README.md b/solution/2900-2999/2931.Maximum Spending After Buying Items/README.md index a59452cd72e0a..677192433ad30 100644 --- a/solution/2900-2999/2931.Maximum Spending After Buying Items/README.md +++ b/solution/2900-2999/2931.Maximum Spending After Buying Items/README.md @@ -101,6 +101,8 @@ tags: +#### Python3 + ```python class Solution: def maxSpending(self, values: List[List[int]]) -> int: @@ -117,6 +119,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maxSpending(int[][] values) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func maxSpending(values [][]int) (ans int64) { pq := hp{} @@ -189,6 +197,8 @@ func (h *hp) Push(v any) { *h = append(*h, v.(tuple)) } func (h *hp) Pop() any { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; return v } ``` +#### TypeScript + ```ts function maxSpending(values: number[][]): number { const m = values.length; diff --git a/solution/2900-2999/2931.Maximum Spending After Buying Items/README_EN.md b/solution/2900-2999/2931.Maximum Spending After Buying Items/README_EN.md index e8c935988293f..15ea50d35167c 100644 --- a/solution/2900-2999/2931.Maximum Spending After Buying Items/README_EN.md +++ b/solution/2900-2999/2931.Maximum Spending After Buying Items/README_EN.md @@ -99,6 +99,8 @@ The time complexity is $O(m \times n \times \log m)$, and the space complexity i +#### Python3 + ```python class Solution: def maxSpending(self, values: List[List[int]]) -> int: @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maxSpending(int[][] values) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func maxSpending(values [][]int) (ans int64) { pq := hp{} @@ -187,6 +195,8 @@ func (h *hp) Push(v any) { *h = append(*h, v.(tuple)) } func (h *hp) Pop() any { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; return v } ``` +#### TypeScript + ```ts function maxSpending(values: number[][]): number { const m = values.length; diff --git a/solution/2900-2999/2932.Maximum Strong Pair XOR I/README.md b/solution/2900-2999/2932.Maximum Strong Pair XOR I/README.md index 59d36d7c23c04..2c73b09b4b304 100644 --- a/solution/2900-2999/2932.Maximum Strong Pair XOR I/README.md +++ b/solution/2900-2999/2932.Maximum Strong Pair XOR I/README.md @@ -86,12 +86,16 @@ tags: +#### Python3 + ```python class Solution: def maximumStrongPairXor(self, nums: List[int]) -> int: return max(x ^ y for x in nums for y in nums if abs(x - y) <= min(x, y)) ``` +#### Java + ```java class Solution { public int maximumStrongPairXor(int[] nums) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func maximumStrongPairXor(nums []int) (ans int) { for _, x := range nums { @@ -145,6 +153,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function maximumStrongPairXor(nums: number[]): number { let ans = 0; @@ -175,6 +185,8 @@ function maximumStrongPairXor(nums: number[]): number { +#### Python3 + ```python class Trie: __slots__ = ("children", "cnt") @@ -226,6 +238,8 @@ class Solution: return ans ``` +#### Java + ```java class Trie { private Trie[] children = new Trie[2]; @@ -288,6 +302,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -355,6 +371,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [2]*Trie @@ -416,6 +434,8 @@ func maximumStrongPairXor(nums []int) (ans int) { } ``` +#### TypeScript + ```ts class Trie { children: (Trie | null)[]; diff --git a/solution/2900-2999/2932.Maximum Strong Pair XOR I/README_EN.md b/solution/2900-2999/2932.Maximum Strong Pair XOR I/README_EN.md index fe528c73fd583..5f3fc4ba96211 100644 --- a/solution/2900-2999/2932.Maximum Strong Pair XOR I/README_EN.md +++ b/solution/2900-2999/2932.Maximum Strong Pair XOR I/README_EN.md @@ -84,12 +84,16 @@ The time complexity is $O(n^2)$, where $n$ is the length of the array $nums$. Th +#### Python3 + ```python class Solution: def maximumStrongPairXor(self, nums: List[int]) -> int: return max(x ^ y for x in nums for y in nums if abs(x - y) <= min(x, y)) ``` +#### Java + ```java class Solution { public int maximumStrongPairXor(int[] nums) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func maximumStrongPairXor(nums []int) (ans int) { for _, x := range nums { @@ -143,6 +151,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function maximumStrongPairXor(nums: number[]): number { let ans = 0; @@ -173,6 +183,8 @@ The time complexity is $O(n \times \log M)$, and the space complexity is $O(n \t +#### Python3 + ```python class Trie: __slots__ = ("children", "cnt") @@ -224,6 +236,8 @@ class Solution: return ans ``` +#### Java + ```java class Trie { private Trie[] children = new Trie[2]; @@ -286,6 +300,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -353,6 +369,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [2]*Trie @@ -414,6 +432,8 @@ func maximumStrongPairXor(nums []int) (ans int) { } ``` +#### TypeScript + ```ts class Trie { children: (Trie | null)[]; diff --git a/solution/2900-2999/2933.High-Access Employees/README.md b/solution/2900-2999/2933.High-Access Employees/README.md index 8e37d40675c0c..46d4584824b00 100644 --- a/solution/2900-2999/2933.High-Access Employees/README.md +++ b/solution/2900-2999/2933.High-Access Employees/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class Solution: def findHighAccessEmployees(self, access_times: List[List[str]]) -> List[str]: @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List findHighAccessEmployees(List> access_times) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func findHighAccessEmployees(access_times [][]string) (ans []string) { d := map[string][]int{} @@ -183,6 +191,8 @@ func findHighAccessEmployees(access_times [][]string) (ans []string) { } ``` +#### TypeScript + ```ts function findHighAccessEmployees(access_times: string[][]): string[] { const d: Map = new Map(); diff --git a/solution/2900-2999/2933.High-Access Employees/README_EN.md b/solution/2900-2999/2933.High-Access Employees/README_EN.md index 73c60eea2a1fe..937280cda1f29 100644 --- a/solution/2900-2999/2933.High-Access Employees/README_EN.md +++ b/solution/2900-2999/2933.High-Access Employees/README_EN.md @@ -92,6 +92,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def findHighAccessEmployees(self, access_times: List[List[str]]) -> List[str]: @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public List findHighAccessEmployees(List> access_times) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func findHighAccessEmployees(access_times [][]string) (ans []string) { d := map[string][]int{} @@ -181,6 +189,8 @@ func findHighAccessEmployees(access_times [][]string) (ans []string) { } ``` +#### TypeScript + ```ts function findHighAccessEmployees(access_times: string[][]): string[] { const d: Map = new Map(); diff --git a/solution/2900-2999/2934.Minimum Operations to Maximize Last Elements in Arrays/README.md b/solution/2900-2999/2934.Minimum Operations to Maximize Last Elements in Arrays/README.md index 6532baad84037..8c89399c4bd81 100644 --- a/solution/2900-2999/2934.Minimum Operations to Maximize Last Elements in Arrays/README.md +++ b/solution/2900-2999/2934.Minimum Operations to Maximize Last Elements in Arrays/README.md @@ -103,6 +103,8 @@ tags: +#### Python3 + ```python class Solution: def minOperations(self, nums1: List[int], nums2: List[int]) -> int: @@ -120,6 +122,8 @@ class Solution: return -1 if a + b == -2 else min(a, b + 1) ``` +#### Java + ```java class Solution { private int n; @@ -147,6 +151,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums1 []int, nums2 []int) int { n := len(nums1) @@ -196,6 +204,8 @@ func minOperations(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function minOperations(nums1: number[], nums2: number[]): number { const n = nums1.length; diff --git a/solution/2900-2999/2934.Minimum Operations to Maximize Last Elements in Arrays/README_EN.md b/solution/2900-2999/2934.Minimum Operations to Maximize Last Elements in Arrays/README_EN.md index 786d2435b6c5e..f7e62b1b82fe6 100644 --- a/solution/2900-2999/2934.Minimum Operations to Maximize Last Elements in Arrays/README_EN.md +++ b/solution/2900-2999/2934.Minimum Operations to Maximize Last Elements in Arrays/README_EN.md @@ -101,6 +101,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def minOperations(self, nums1: List[int], nums2: List[int]) -> int: @@ -118,6 +120,8 @@ class Solution: return -1 if a + b == -2 else min(a, b + 1) ``` +#### Java + ```java class Solution { private int n; @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums1 []int, nums2 []int) int { n := len(nums1) @@ -194,6 +202,8 @@ func minOperations(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function minOperations(nums1: number[], nums2: number[]): number { const n = nums1.length; diff --git a/solution/2900-2999/2935.Maximum Strong Pair XOR II/README.md b/solution/2900-2999/2935.Maximum Strong Pair XOR II/README.md index 43a15da8fd685..243bc97a032ff 100644 --- a/solution/2900-2999/2935.Maximum Strong Pair XOR II/README.md +++ b/solution/2900-2999/2935.Maximum Strong Pair XOR II/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Trie: __slots__ = ("children", "cnt") @@ -139,6 +141,8 @@ class Solution: return ans ``` +#### Java + ```java class Trie { private Trie[] children = new Trie[2]; @@ -201,6 +205,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -268,6 +274,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [2]*Trie @@ -329,6 +337,8 @@ func maximumStrongPairXor(nums []int) (ans int) { } ``` +#### TypeScript + ```ts class Trie { children: (Trie | null)[]; diff --git a/solution/2900-2999/2935.Maximum Strong Pair XOR II/README_EN.md b/solution/2900-2999/2935.Maximum Strong Pair XOR II/README_EN.md index 504aac3be2145..05953af63c238 100644 --- a/solution/2900-2999/2935.Maximum Strong Pair XOR II/README_EN.md +++ b/solution/2900-2999/2935.Maximum Strong Pair XOR II/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(n \times \log M)$, and the space complexity is $O(n \t +#### Python3 + ```python class Trie: __slots__ = ("children", "cnt") @@ -137,6 +139,8 @@ class Solution: return ans ``` +#### Java + ```java class Trie { private Trie[] children = new Trie[2]; @@ -199,6 +203,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { public: @@ -266,6 +272,8 @@ public: }; ``` +#### Go + ```go type Trie struct { children [2]*Trie @@ -327,6 +335,8 @@ func maximumStrongPairXor(nums []int) (ans int) { } ``` +#### TypeScript + ```ts class Trie { children: (Trie | null)[]; diff --git a/solution/2900-2999/2936.Number of Equal Numbers Blocks/README.md b/solution/2900-2999/2936.Number of Equal Numbers Blocks/README.md index 68be8d7fabdf6..2635eab6b3201 100644 --- a/solution/2900-2999/2936.Number of Equal Numbers Blocks/README.md +++ b/solution/2900-2999/2936.Number of Equal Numbers Blocks/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python # Definition for BigArray. # class BigArray: @@ -112,6 +114,8 @@ class Solution(object): return ans ``` +#### Java + ```java /** * Definition for BigArray. @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for BigArray. @@ -183,6 +189,8 @@ public: }; ``` +#### TypeScript + ```ts /** * Definition for BigArray. @@ -230,6 +238,8 @@ function countBlocks(nums: BigArray | null): number { +#### Java + ```java /** * Definition for BigArray. @@ -256,6 +266,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for BigArray. @@ -284,6 +296,8 @@ public: }; ``` +#### TypeScript + ```ts /** * Definition for BigArray. diff --git a/solution/2900-2999/2936.Number of Equal Numbers Blocks/README_EN.md b/solution/2900-2999/2936.Number of Equal Numbers Blocks/README_EN.md index 39e880c7a0559..d597680273a27 100644 --- a/solution/2900-2999/2936.Number of Equal Numbers Blocks/README_EN.md +++ b/solution/2900-2999/2936.Number of Equal Numbers Blocks/README_EN.md @@ -89,6 +89,8 @@ The time complexity is $O(m \times \log n)$, where $m$ is the number of differen +#### Python3 + ```python # Definition for BigArray. # class BigArray: @@ -110,6 +112,8 @@ class Solution(object): return ans ``` +#### Java + ```java /** * Definition for BigArray. @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for BigArray. @@ -181,6 +187,8 @@ public: }; ``` +#### TypeScript + ```ts /** * Definition for BigArray. @@ -228,6 +236,8 @@ The time complexity is $O(\log n)$, and the space complexity is $O(\log n)$. Her +#### Java + ```java /** * Definition for BigArray. @@ -254,6 +264,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for BigArray. @@ -282,6 +294,8 @@ public: }; ``` +#### TypeScript + ```ts /** * Definition for BigArray. diff --git a/solution/2900-2999/2937.Make Three Strings Equal/README.md b/solution/2900-2999/2937.Make Three Strings Equal/README.md index 8e9dc7382400e..eb5fbd64555a4 100644 --- a/solution/2900-2999/2937.Make Three Strings Equal/README.md +++ b/solution/2900-2999/2937.Make Three Strings Equal/README.md @@ -64,6 +64,8 @@ tags: +#### Python3 + ```python class Solution: def findMinimumOperations(self, s1: str, s2: str, s3: str) -> int: @@ -75,6 +77,8 @@ class Solution: return s - 3 * n ``` +#### Java + ```java class Solution { public int findMinimumOperations(String s1, String s2, String s3) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func findMinimumOperations(s1 string, s2 string, s3 string) int { s := len(s1) + len(s2) + len(s3) @@ -122,6 +130,8 @@ func findMinimumOperations(s1 string, s2 string, s3 string) int { } ``` +#### TypeScript + ```ts function findMinimumOperations(s1: string, s2: string, s3: string): number { const s = s1.length + s2.length + s3.length; diff --git a/solution/2900-2999/2937.Make Three Strings Equal/README_EN.md b/solution/2900-2999/2937.Make Three Strings Equal/README_EN.md index bffbab1f41f62..a4a101fe97bf2 100644 --- a/solution/2900-2999/2937.Make Three Strings Equal/README_EN.md +++ b/solution/2900-2999/2937.Make Three Strings Equal/README_EN.md @@ -65,6 +65,8 @@ The time complexity is $O(n)$, where $n$ is the minimum length of the three stri +#### Python3 + ```python class Solution: def findMinimumOperations(self, s1: str, s2: str, s3: str) -> int: @@ -76,6 +78,8 @@ class Solution: return s - 3 * n ``` +#### Java + ```java class Solution { public int findMinimumOperations(String s1, String s2, String s3) { @@ -91,6 +95,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func findMinimumOperations(s1 string, s2 string, s3 string) int { s := len(s1) + len(s2) + len(s3) @@ -123,6 +131,8 @@ func findMinimumOperations(s1 string, s2 string, s3 string) int { } ``` +#### TypeScript + ```ts function findMinimumOperations(s1: string, s2: string, s3: string): number { const s = s1.length + s2.length + s3.length; diff --git a/solution/2900-2999/2938.Separate Black and White Balls/README.md b/solution/2900-2999/2938.Separate Black and White Balls/README.md index 81ba242a684a4..be4d36b70abb1 100644 --- a/solution/2900-2999/2938.Separate Black and White Balls/README.md +++ b/solution/2900-2999/2938.Separate Black and White Balls/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def minimumSteps(self, s: str) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long minimumSteps(String s) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func minimumSteps(s string) (ans int64) { n := len(s) @@ -144,6 +152,8 @@ func minimumSteps(s string) (ans int64) { } ``` +#### TypeScript + ```ts function minimumSteps(s: string): number { const n = s.length; diff --git a/solution/2900-2999/2938.Separate Black and White Balls/README_EN.md b/solution/2900-2999/2938.Separate Black and White Balls/README_EN.md index 2b0eec137ec25..bb3b1a5b566e7 100644 --- a/solution/2900-2999/2938.Separate Black and White Balls/README_EN.md +++ b/solution/2900-2999/2938.Separate Black and White Balls/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string. The space +#### Python3 + ```python class Solution: def minimumSteps(self, s: str) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long minimumSteps(String s) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func minimumSteps(s string) (ans int64) { n := len(s) @@ -142,6 +150,8 @@ func minimumSteps(s string) (ans int64) { } ``` +#### TypeScript + ```ts function minimumSteps(s: string): number { const n = s.length; diff --git a/solution/2900-2999/2939.Maximum Xor Product/README.md b/solution/2900-2999/2939.Maximum Xor Product/README.md index 2a6f017b6aae2..af16f134f4d98 100644 --- a/solution/2900-2999/2939.Maximum Xor Product/README.md +++ b/solution/2900-2999/2939.Maximum Xor Product/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def maximumXorProduct(self, a: int, b: int, n: int) -> int: @@ -103,6 +105,8 @@ class Solution: return ax * bx % mod ``` +#### Java + ```java class Solution { public int maximumXorProduct(long a, long b, int n) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func maximumXorProduct(a int64, b int64, n int) int { const mod int64 = 1e9 + 7 @@ -174,6 +182,8 @@ func maximumXorProduct(a int64, b int64, n int) int { } ``` +#### TypeScript + ```ts function maximumXorProduct(a: number, b: number, n: number): number { const mod = BigInt(1e9 + 7); diff --git a/solution/2900-2999/2939.Maximum Xor Product/README_EN.md b/solution/2900-2999/2939.Maximum Xor Product/README_EN.md index 34b2bb8fc7a64..587d105c7d80d 100644 --- a/solution/2900-2999/2939.Maximum Xor Product/README_EN.md +++ b/solution/2900-2999/2939.Maximum Xor Product/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(n)$, where $n$ is the integer given in the problem. Th +#### Python3 + ```python class Solution: def maximumXorProduct(self, a: int, b: int, n: int) -> int: @@ -101,6 +103,8 @@ class Solution: return ax * bx % mod ``` +#### Java + ```java class Solution { public int maximumXorProduct(long a, long b, int n) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func maximumXorProduct(a int64, b int64, n int) int { const mod int64 = 1e9 + 7 @@ -172,6 +180,8 @@ func maximumXorProduct(a int64, b int64, n int) int { } ``` +#### TypeScript + ```ts function maximumXorProduct(a: number, b: number, n: number): number { const mod = BigInt(1e9 + 7); diff --git a/solution/2900-2999/2940.Find Building Where Alice and Bob Can Meet/README.md b/solution/2900-2999/2940.Find Building Where Alice and Bob Can Meet/README.md index 21b7dbddbfb26..323efdc693c94 100644 --- a/solution/2900-2999/2940.Find Building Where Alice and Bob Can Meet/README.md +++ b/solution/2900-2999/2940.Find Building Where Alice and Bob Can Meet/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class BinaryIndexedTree: __slots__ = ["n", "c"] @@ -142,6 +144,8 @@ class Solution: return ans ``` +#### Java + ```java class BinaryIndexedTree { private final int inf = 1 << 30; @@ -209,6 +213,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { private: @@ -278,6 +284,8 @@ public: }; ``` +#### Go + ```go const inf int = 1 << 30 @@ -348,6 +356,8 @@ func leftmostBuildingQueries(heights []int, queries [][]int) []int { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; diff --git a/solution/2900-2999/2940.Find Building Where Alice and Bob Can Meet/README_EN.md b/solution/2900-2999/2940.Find Building Where Alice and Bob Can Meet/README_EN.md index aa2a6945bae07..efcb9ce0808f9 100644 --- a/solution/2900-2999/2940.Find Building Where Alice and Bob Can Meet/README_EN.md +++ b/solution/2900-2999/2940.Find Building Where Alice and Bob Can Meet/README_EN.md @@ -95,6 +95,8 @@ Similar problems: +#### Python3 + ```python class BinaryIndexedTree: __slots__ = ["n", "c"] @@ -141,6 +143,8 @@ class Solution: return ans ``` +#### Java + ```java class BinaryIndexedTree { private final int inf = 1 << 30; @@ -208,6 +212,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { private: @@ -277,6 +283,8 @@ public: }; ``` +#### Go + ```go const inf int = 1 << 30 @@ -347,6 +355,8 @@ func leftmostBuildingQueries(heights []int, queries [][]int) []int { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; diff --git a/solution/2900-2999/2941.Maximum GCD-Sum of a Subarray/README.md b/solution/2900-2999/2941.Maximum GCD-Sum of a Subarray/README.md index 484d2d04f2576..ab6d0771327e3 100644 --- a/solution/2900-2999/2941.Maximum GCD-Sum of a Subarray/README.md +++ b/solution/2900-2999/2941.Maximum GCD-Sum of a Subarray/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def maxGcdSum(self, nums: List[int], k: int) -> int: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maxGcdSum(int[] nums, int k) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func maxGcdSum(nums []int, k int) int64 { n := len(nums) @@ -200,6 +208,8 @@ func gcd(a, b int) int { } ``` +#### TypeScript + ```ts function maxGcdSum(nums: number[], k: number): number { const n: number = nums.length; @@ -246,6 +256,8 @@ function gcd(a: number, b: number): number { +#### TypeScript + ```ts function maxGcdSum(nums: number[], k: number): number { const n: number = nums.length; diff --git a/solution/2900-2999/2941.Maximum GCD-Sum of a Subarray/README_EN.md b/solution/2900-2999/2941.Maximum GCD-Sum of a Subarray/README_EN.md index ecf55e121ce92..505b86406b0b7 100644 --- a/solution/2900-2999/2941.Maximum GCD-Sum of a Subarray/README_EN.md +++ b/solution/2900-2999/2941.Maximum GCD-Sum of a Subarray/README_EN.md @@ -68,6 +68,8 @@ It can be shown that we can not select any other subarray with a gcd-sum greater +#### Python3 + ```python class Solution: def maxGcdSum(self, nums: List[int], k: int) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maxGcdSum(int[] nums, int k) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func maxGcdSum(nums []int, k int) int64 { n := len(nums) @@ -198,6 +206,8 @@ func gcd(a, b int) int { } ``` +#### TypeScript + ```ts function maxGcdSum(nums: number[], k: number): number { const n: number = nums.length; @@ -244,6 +254,8 @@ function gcd(a: number, b: number): number { +#### TypeScript + ```ts function maxGcdSum(nums: number[], k: number): number { const n: number = nums.length; diff --git a/solution/2900-2999/2942.Find Words Containing Character/README.md b/solution/2900-2999/2942.Find Words Containing Character/README.md index a006001dd69a3..ac978867e8681 100644 --- a/solution/2900-2999/2942.Find Words Containing Character/README.md +++ b/solution/2900-2999/2942.Find Words Containing Character/README.md @@ -78,12 +78,16 @@ tags: +#### Python3 + ```python class Solution: def findWordsContaining(self, words: List[str], x: str) -> List[int]: return [i for i, w in enumerate(words) if x in w] ``` +#### Java + ```java class Solution { public List findWordsContaining(String[] words, char x) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func findWordsContaining(words []string, x byte) (ans []int) { for i, w := range words { @@ -127,6 +135,8 @@ func findWordsContaining(words []string, x byte) (ans []int) { } ``` +#### TypeScript + ```ts function findWordsContaining(words: string[], x: string): number[] { const ans: number[] = []; diff --git a/solution/2900-2999/2942.Find Words Containing Character/README_EN.md b/solution/2900-2999/2942.Find Words Containing Character/README_EN.md index 1ff065c5ef524..26bc8faf7efcb 100644 --- a/solution/2900-2999/2942.Find Words Containing Character/README_EN.md +++ b/solution/2900-2999/2942.Find Words Containing Character/README_EN.md @@ -76,12 +76,16 @@ The time complexity is $O(L)$, where $L$ is the sum of the lengths of all string +#### Python3 + ```python class Solution: def findWordsContaining(self, words: List[str], x: str) -> List[int]: return [i for i, w in enumerate(words) if x in w] ``` +#### Java + ```java class Solution { public List findWordsContaining(String[] words, char x) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func findWordsContaining(words []string, x byte) (ans []int) { for i, w := range words { @@ -125,6 +133,8 @@ func findWordsContaining(words []string, x byte) (ans []int) { } ``` +#### TypeScript + ```ts function findWordsContaining(words: string[], x: string): number[] { const ans: number[] = []; diff --git a/solution/2900-2999/2943.Maximize Area of Square Hole in Grid/README.md b/solution/2900-2999/2943.Maximize Area of Square Hole in Grid/README.md index a08496cafaa51..1147ab2000f46 100644 --- a/solution/2900-2999/2943.Maximize Area of Square Hole in Grid/README.md +++ b/solution/2900-2999/2943.Maximize Area of Square Hole in Grid/README.md @@ -129,6 +129,8 @@ tags: +#### Python3 + ```python class Solution: def maximizeSquareHoleArea( @@ -148,6 +150,8 @@ class Solution: return min(f(hBars), f(vBars)) ** 2 ``` +#### Java + ```java class Solution { public int maximizeSquareHoleArea(int n, int m, int[] hBars, int[] vBars) { @@ -170,6 +174,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -192,6 +198,8 @@ public: }; ``` +#### Go + ```go func maximizeSquareHoleArea(n int, m int, hBars []int, vBars []int) int { f := func(nums []int) int { @@ -212,6 +220,8 @@ func maximizeSquareHoleArea(n int, m int, hBars []int, vBars []int) int { } ``` +#### TypeScript + ```ts function maximizeSquareHoleArea(n: number, m: number, hBars: number[], vBars: number[]): number { const f = (nums: number[]): number => { @@ -230,6 +240,8 @@ function maximizeSquareHoleArea(n: number, m: number, hBars: number[], vBars: nu } ``` +#### Rust + ```rust impl Solution { pub fn maximize_square_hole_area(n: i32, m: i32, h_bars: Vec, v_bars: Vec) -> i32 { diff --git a/solution/2900-2999/2943.Maximize Area of Square Hole in Grid/README_EN.md b/solution/2900-2999/2943.Maximize Area of Square Hole in Grid/README_EN.md index 74d7b7da4778d..db3594285211b 100644 --- a/solution/2900-2999/2943.Maximize Area of Square Hole in Grid/README_EN.md +++ b/solution/2900-2999/2943.Maximize Area of Square Hole in Grid/README_EN.md @@ -104,6 +104,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def maximizeSquareHoleArea( @@ -123,6 +125,8 @@ class Solution: return min(f(hBars), f(vBars)) ** 2 ``` +#### Java + ```java class Solution { public int maximizeSquareHoleArea(int n, int m, int[] hBars, int[] vBars) { @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func maximizeSquareHoleArea(n int, m int, hBars []int, vBars []int) int { f := func(nums []int) int { @@ -187,6 +195,8 @@ func maximizeSquareHoleArea(n int, m int, hBars []int, vBars []int) int { } ``` +#### TypeScript + ```ts function maximizeSquareHoleArea(n: number, m: number, hBars: number[], vBars: number[]): number { const f = (nums: number[]): number => { @@ -205,6 +215,8 @@ function maximizeSquareHoleArea(n: number, m: number, hBars: number[], vBars: nu } ``` +#### Rust + ```rust impl Solution { pub fn maximize_square_hole_area(n: i32, m: i32, h_bars: Vec, v_bars: Vec) -> i32 { diff --git a/solution/2900-2999/2944.Minimum Number of Coins for Fruits/README.md b/solution/2900-2999/2944.Minimum Number of Coins for Fruits/README.md index 5c4d083b45b1a..76c8752ac8b25 100644 --- a/solution/2900-2999/2944.Minimum Number of Coins for Fruits/README.md +++ b/solution/2900-2999/2944.Minimum Number of Coins for Fruits/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class Solution: def minimumCoins(self, prices: List[int]) -> int: @@ -106,6 +108,8 @@ class Solution: return dfs(1) ``` +#### Java + ```java class Solution { private int[] prices; @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func minimumCoins(prices []int) int { n := len(prices) @@ -178,6 +186,8 @@ func minimumCoins(prices []int) int { } ``` +#### TypeScript + ```ts function minimumCoins(prices: number[]): number { const n = prices.length; @@ -218,6 +228,8 @@ function minimumCoins(prices: number[]): number { +#### Python3 + ```python class Solution: def minimumCoins(self, prices: List[int]) -> int: @@ -227,6 +239,8 @@ class Solution: return prices[0] ``` +#### Java + ```java class Solution { public int minimumCoins(int[] prices) { @@ -243,6 +257,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -256,6 +272,8 @@ public: }; ``` +#### Go + ```go func minimumCoins(prices []int) int { for i := (len(prices) - 1) / 2; i > 0; i-- { @@ -265,6 +283,8 @@ func minimumCoins(prices []int) int { } ``` +#### TypeScript + ```ts function minimumCoins(prices: number[]): number { for (let i = (prices.length - 1) >> 1; i; --i) { @@ -290,6 +310,8 @@ function minimumCoins(prices: number[]): number { +#### Python3 + ```python class Solution: def minimumCoins(self, prices: List[int]) -> int: @@ -306,6 +328,8 @@ class Solution: return prices[0] ``` +#### Java + ```java class Solution { public int minimumCoins(int[] prices) { @@ -328,6 +352,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -351,6 +377,8 @@ public: }; ``` +#### Go + ```go func minimumCoins(prices []int) int { n := len(prices) @@ -429,6 +457,8 @@ func (q Deque) Get(i int) int { } ``` +#### TypeScript + ```ts function minimumCoins(prices: number[]): number { const n = prices.length; diff --git a/solution/2900-2999/2944.Minimum Number of Coins for Fruits/README_EN.md b/solution/2900-2999/2944.Minimum Number of Coins for Fruits/README_EN.md index fb53a9ec1ec5c..bd7cd491ce628 100644 --- a/solution/2900-2999/2944.Minimum Number of Coins for Fruits/README_EN.md +++ b/solution/2900-2999/2944.Minimum Number of Coins for Fruits/README_EN.md @@ -81,6 +81,8 @@ It can be proven that 2 is the minimum number of coins needed to acquire all the +#### Python3 + ```python class Solution: def minimumCoins(self, prices: List[int]) -> int: @@ -93,6 +95,8 @@ class Solution: return dfs(1) ``` +#### Java + ```java class Solution { private int[] prices; @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func minimumCoins(prices []int) int { n := len(prices) @@ -165,6 +173,8 @@ func minimumCoins(prices []int) int { } ``` +#### TypeScript + ```ts function minimumCoins(prices: number[]): number { const n = prices.length; @@ -195,6 +205,8 @@ function minimumCoins(prices: number[]): number { +#### Python3 + ```python class Solution: def minimumCoins(self, prices: List[int]) -> int: @@ -204,6 +216,8 @@ class Solution: return prices[0] ``` +#### Java + ```java class Solution { public int minimumCoins(int[] prices) { @@ -220,6 +234,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -233,6 +249,8 @@ public: }; ``` +#### Go + ```go func minimumCoins(prices []int) int { for i := (len(prices) - 1) / 2; i > 0; i-- { @@ -242,6 +260,8 @@ func minimumCoins(prices []int) int { } ``` +#### TypeScript + ```ts function minimumCoins(prices: number[]): number { for (let i = (prices.length - 1) >> 1; i; --i) { @@ -261,6 +281,8 @@ function minimumCoins(prices: number[]): number { +#### Python3 + ```python class Solution: def minimumCoins(self, prices: List[int]) -> int: @@ -277,6 +299,8 @@ class Solution: return prices[0] ``` +#### Java + ```java class Solution { public int minimumCoins(int[] prices) { @@ -299,6 +323,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -322,6 +348,8 @@ public: }; ``` +#### Go + ```go func minimumCoins(prices []int) int { n := len(prices) @@ -400,6 +428,8 @@ func (q Deque) Get(i int) int { } ``` +#### TypeScript + ```ts function minimumCoins(prices: number[]): number { const n = prices.length; diff --git a/solution/2900-2999/2945.Find Maximum Non-decreasing Array Length/README.md b/solution/2900-2999/2945.Find Maximum Non-decreasing Array Length/README.md index 982b6b042701f..10896ca0459b7 100644 --- a/solution/2900-2999/2945.Find Maximum Non-decreasing Array Length/README.md +++ b/solution/2900-2999/2945.Find Maximum Non-decreasing Array Length/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def findMaximumLength(self, nums: List[int]) -> int: @@ -98,6 +100,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int findMaximumLength(int[] nums) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go func findMaximumLength(nums []int) int { n := len(nums) @@ -162,6 +170,8 @@ func findMaximumLength(nums []int) int { } ``` +#### TypeScript + ```ts function findMaximumLength(nums: number[]): number { const n = nums.length; diff --git a/solution/2900-2999/2945.Find Maximum Non-decreasing Array Length/README_EN.md b/solution/2900-2999/2945.Find Maximum Non-decreasing Array Length/README_EN.md index 653fb1387cfd9..e4ca74a60a307 100644 --- a/solution/2900-2999/2945.Find Maximum Non-decreasing Array Length/README_EN.md +++ b/solution/2900-2999/2945.Find Maximum Non-decreasing Array Length/README_EN.md @@ -81,6 +81,8 @@ Because the given array is not non-decreasing, the maximum +#### Python3 + ```python class Solution: def findMaximumLength(self, nums: List[int]) -> int: @@ -96,6 +98,8 @@ class Solution: return f[n] ``` +#### Java + ```java class Solution { public int findMaximumLength(int[] nums) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func findMaximumLength(nums []int) int { n := len(nums) @@ -160,6 +168,8 @@ func findMaximumLength(nums []int) int { } ``` +#### TypeScript + ```ts function findMaximumLength(nums: number[]): number { const n = nums.length; diff --git a/solution/2900-2999/2946.Matrix Similarity After Cyclic Shifts/README.md b/solution/2900-2999/2946.Matrix Similarity After Cyclic Shifts/README.md index f2c982c1a4a56..3373a57554602 100644 --- a/solution/2900-2999/2946.Matrix Similarity After Cyclic Shifts/README.md +++ b/solution/2900-2999/2946.Matrix Similarity After Cyclic Shifts/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def areSimilar(self, mat: List[List[int]], k: int) -> bool: @@ -91,6 +93,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean areSimilar(int[][] mat, int k) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func areSimilar(mat [][]int, k int) bool { n := len(mat[0]) @@ -150,6 +158,8 @@ func areSimilar(mat [][]int, k int) bool { } ``` +#### TypeScript + ```ts function areSimilar(mat: number[][], k: number): boolean { const m = mat.length; diff --git a/solution/2900-2999/2946.Matrix Similarity After Cyclic Shifts/README_EN.md b/solution/2900-2999/2946.Matrix Similarity After Cyclic Shifts/README_EN.md index e594d7da5986f..f211bf166921a 100644 --- a/solution/2900-2999/2946.Matrix Similarity After Cyclic Shifts/README_EN.md +++ b/solution/2900-2999/2946.Matrix Similarity After Cyclic Shifts/README_EN.md @@ -76,6 +76,8 @@ Therefore, return true. +#### Python3 + ```python class Solution: def areSimilar(self, mat: List[List[int]], k: int) -> bool: @@ -89,6 +91,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean areSimilar(int[][] mat, int k) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func areSimilar(mat [][]int, k int) bool { n := len(mat[0]) @@ -148,6 +156,8 @@ func areSimilar(mat [][]int, k int) bool { } ``` +#### TypeScript + ```ts function areSimilar(mat: number[][], k: number): boolean { const m = mat.length; diff --git a/solution/2900-2999/2947.Count Beautiful Substrings I/README.md b/solution/2900-2999/2947.Count Beautiful Substrings I/README.md index 73cff908ab1cb..111857199e43a 100644 --- a/solution/2900-2999/2947.Count Beautiful Substrings I/README.md +++ b/solution/2900-2999/2947.Count Beautiful Substrings I/README.md @@ -97,6 +97,8 @@ tags: +#### Python3 + ```python class Solution: def beautifulSubstrings(self, s: str, k: int) -> int: @@ -113,6 +115,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int beautifulSubstrings(String s, int k) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func beautifulSubstrings(s string, k int) (ans int) { n := len(s) @@ -184,6 +192,8 @@ func beautifulSubstrings(s string, k int) (ans int) { } ``` +#### TypeScript + ```ts function beautifulSubstrings(s: string, k: number): number { const n = s.length; diff --git a/solution/2900-2999/2947.Count Beautiful Substrings I/README_EN.md b/solution/2900-2999/2947.Count Beautiful Substrings I/README_EN.md index fdefd42c49e39..be235229bba2f 100644 --- a/solution/2900-2999/2947.Count Beautiful Substrings I/README_EN.md +++ b/solution/2900-2999/2947.Count Beautiful Substrings I/README_EN.md @@ -95,6 +95,8 @@ It can be shown that there are only 3 beautiful substrings in the given string. +#### Python3 + ```python class Solution: def beautifulSubstrings(self, s: str, k: int) -> int: @@ -111,6 +113,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int beautifulSubstrings(String s, int k) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func beautifulSubstrings(s string, k int) (ans int) { n := len(s) @@ -182,6 +190,8 @@ func beautifulSubstrings(s string, k int) (ans int) { } ``` +#### TypeScript + ```ts function beautifulSubstrings(s: string, k: number): number { const n = s.length; diff --git a/solution/2900-2999/2948.Make Lexicographically Smallest Array by Swapping Elements/README.md b/solution/2900-2999/2948.Make Lexicographically Smallest Array by Swapping Elements/README.md index a55d231a3df31..3f09229169241 100644 --- a/solution/2900-2999/2948.Make Lexicographically Smallest Array by Swapping Elements/README.md +++ b/solution/2900-2999/2948.Make Lexicographically Smallest Array by Swapping Elements/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def lexicographicallySmallestArray(self, nums: List[int], limit: int) -> List[int]: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] lexicographicallySmallestArray(int[] nums, int limit) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func lexicographicallySmallestArray(nums []int, limit int) []int { n := len(nums) @@ -180,6 +188,8 @@ func lexicographicallySmallestArray(nums []int, limit int) []int { } ``` +#### TypeScript + ```ts function lexicographicallySmallestArray(nums: number[], limit: number): number[] { const n: number = nums.length; diff --git a/solution/2900-2999/2948.Make Lexicographically Smallest Array by Swapping Elements/README_EN.md b/solution/2900-2999/2948.Make Lexicographically Smallest Array by Swapping Elements/README_EN.md index c03b2957d7e08..2288ef732c2bd 100644 --- a/solution/2900-2999/2948.Make Lexicographically Smallest Array by Swapping Elements/README_EN.md +++ b/solution/2900-2999/2948.Make Lexicographically Smallest Array by Swapping Elements/README_EN.md @@ -80,6 +80,8 @@ We cannot obtain a lexicographically smaller array by applying any more operatio +#### Python3 + ```python class Solution: def lexicographicallySmallestArray(self, nums: List[int], limit: int) -> List[int]: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] lexicographicallySmallestArray(int[] nums, int limit) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func lexicographicallySmallestArray(nums []int, limit int) []int { n := len(nums) @@ -178,6 +186,8 @@ func lexicographicallySmallestArray(nums []int, limit int) []int { } ``` +#### TypeScript + ```ts function lexicographicallySmallestArray(nums: number[], limit: number): number[] { const n: number = nums.length; diff --git a/solution/2900-2999/2949.Count Beautiful Substrings II/README.md b/solution/2900-2999/2949.Count Beautiful Substrings II/README.md index 3d357d3c652c4..10d19032e3d18 100644 --- a/solution/2900-2999/2949.Count Beautiful Substrings II/README.md +++ b/solution/2900-2999/2949.Count Beautiful Substrings II/README.md @@ -96,6 +96,8 @@ tags: +#### TypeScript + ```ts function beautifulSubstrings(s: string, k: number): number { const l = pSqrt(k * 4); diff --git a/solution/2900-2999/2949.Count Beautiful Substrings II/README_EN.md b/solution/2900-2999/2949.Count Beautiful Substrings II/README_EN.md index a9d9cb00d5a67..05fbcb992e800 100644 --- a/solution/2900-2999/2949.Count Beautiful Substrings II/README_EN.md +++ b/solution/2900-2999/2949.Count Beautiful Substrings II/README_EN.md @@ -94,6 +94,8 @@ It can be shown that there are only 3 beautiful substrings in the given string. +#### TypeScript + ```ts function beautifulSubstrings(s: string, k: number): number { const l = pSqrt(k * 4); diff --git a/solution/2900-2999/2950.Number of Divisible Substrings/README.md b/solution/2900-2999/2950.Number of Divisible Substrings/README.md index fc517bfa62f86..2885daeddf7e4 100644 --- a/solution/2900-2999/2950.Number of Divisible Substrings/README.md +++ b/solution/2900-2999/2950.Number of Divisible Substrings/README.md @@ -166,6 +166,8 @@ tags: +#### Python3 + ```python class Solution: def countDivisibleSubstrings(self, word: str) -> int: @@ -184,6 +186,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countDivisibleSubstrings(String word) { @@ -208,6 +212,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -233,6 +239,8 @@ public: }; ``` +#### Go + ```go func countDivisibleSubstrings(word string) (ans int) { d := []string{"ab", "cde", "fgh", "ijk", "lmn", "opq", "rst", "uvw", "xyz"} @@ -256,6 +264,8 @@ func countDivisibleSubstrings(word string) (ans int) { } ``` +#### TypeScript + ```ts function countDivisibleSubstrings(word: string): number { const d: string[] = ['ab', 'cde', 'fgh', 'ijk', 'lmn', 'opq', 'rst', 'uvw', 'xyz']; @@ -280,6 +290,8 @@ function countDivisibleSubstrings(word: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_divisible_substrings(word: String) -> i32 { @@ -327,6 +339,8 @@ impl Solution { +#### Python3 + ```python class Solution: def countDivisibleSubstrings(self, word: str) -> int: @@ -347,6 +361,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countDivisibleSubstrings(String word) { @@ -374,6 +390,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -399,6 +417,8 @@ public: }; ``` +#### Go + ```go func countDivisibleSubstrings(word string) (ans int) { d := []string{"ab", "cde", "fgh", "ijk", "lmn", "opq", "rst", "uvw", "xyz"} @@ -421,6 +441,8 @@ func countDivisibleSubstrings(word string) (ans int) { } ``` +#### TypeScript + ```ts function countDivisibleSubstrings(word: string): number { const d = ['ab', 'cde', 'fgh', 'ijk', 'lmn', 'opq', 'rst', 'uvw', 'xyz']; @@ -446,6 +468,8 @@ function countDivisibleSubstrings(word: string): number { } ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/2900-2999/2950.Number of Divisible Substrings/README_EN.md b/solution/2900-2999/2950.Number of Divisible Substrings/README_EN.md index a38d7fa257ebe..1f986a82884b6 100644 --- a/solution/2900-2999/2950.Number of Divisible Substrings/README_EN.md +++ b/solution/2900-2999/2950.Number of Divisible Substrings/README_EN.md @@ -164,6 +164,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(C)$. Where $n$ i +#### Python3 + ```python class Solution: def countDivisibleSubstrings(self, word: str) -> int: @@ -182,6 +184,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countDivisibleSubstrings(String word) { @@ -206,6 +210,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -231,6 +237,8 @@ public: }; ``` +#### Go + ```go func countDivisibleSubstrings(word string) (ans int) { d := []string{"ab", "cde", "fgh", "ijk", "lmn", "opq", "rst", "uvw", "xyz"} @@ -254,6 +262,8 @@ func countDivisibleSubstrings(word string) (ans int) { } ``` +#### TypeScript + ```ts function countDivisibleSubstrings(word: string): number { const d: string[] = ['ab', 'cde', 'fgh', 'ijk', 'lmn', 'opq', 'rst', 'uvw', 'xyz']; @@ -278,6 +288,8 @@ function countDivisibleSubstrings(word: string): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_divisible_substrings(word: String) -> i32 { @@ -325,6 +337,8 @@ The time complexity is $O(10 \times n)$, and the space complexity is $O(n)$. Her +#### Python3 + ```python class Solution: def countDivisibleSubstrings(self, word: str) -> int: @@ -345,6 +359,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countDivisibleSubstrings(String word) { @@ -372,6 +388,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -397,6 +415,8 @@ public: }; ``` +#### Go + ```go func countDivisibleSubstrings(word string) (ans int) { d := []string{"ab", "cde", "fgh", "ijk", "lmn", "opq", "rst", "uvw", "xyz"} @@ -419,6 +439,8 @@ func countDivisibleSubstrings(word string) (ans int) { } ``` +#### TypeScript + ```ts function countDivisibleSubstrings(word: string): number { const d = ['ab', 'cde', 'fgh', 'ijk', 'lmn', 'opq', 'rst', 'uvw', 'xyz']; @@ -444,6 +466,8 @@ function countDivisibleSubstrings(word: string): number { } ``` +#### Rust + ```rust use std::collections::HashMap; diff --git a/solution/2900-2999/2951.Find the Peaks/README.md b/solution/2900-2999/2951.Find the Peaks/README.md index 8902e8a55b252..75ba8d19f4e50 100644 --- a/solution/2900-2999/2951.Find the Peaks/README.md +++ b/solution/2900-2999/2951.Find the Peaks/README.md @@ -78,6 +78,8 @@ mountain[2] 也不可能是峰值,因为它不严格大于 mountain[3] 和 mou +#### Python3 + ```python class Solution: def findPeaks(self, mountain: List[int]) -> List[int]: @@ -88,6 +90,8 @@ class Solution: ] ``` +#### Java + ```java class Solution { public List findPeaks(int[] mountain) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func findPeaks(mountain []int) (ans []int) { for i := 1; i < len(mountain)-1; i++ { @@ -128,6 +136,8 @@ func findPeaks(mountain []int) (ans []int) { } ``` +#### TypeScript + ```ts function findPeaks(mountain: number[]): number[] { const ans: number[] = []; diff --git a/solution/2900-2999/2951.Find the Peaks/README_EN.md b/solution/2900-2999/2951.Find the Peaks/README_EN.md index da91132849cb0..598d9a9810f87 100644 --- a/solution/2900-2999/2951.Find the Peaks/README_EN.md +++ b/solution/2900-2999/2951.Find the Peaks/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. Ignoring th +#### Python3 + ```python class Solution: def findPeaks(self, mountain: List[int]) -> List[int]: @@ -86,6 +88,8 @@ class Solution: ] ``` +#### Java + ```java class Solution { public List findPeaks(int[] mountain) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func findPeaks(mountain []int) (ans []int) { for i := 1; i < len(mountain)-1; i++ { @@ -126,6 +134,8 @@ func findPeaks(mountain []int) (ans []int) { } ``` +#### TypeScript + ```ts function findPeaks(mountain: number[]): number[] { const ans: number[] = []; diff --git a/solution/2900-2999/2952.Minimum Number of Coins to be Added/README.md b/solution/2900-2999/2952.Minimum Number of Coins to be Added/README.md index dde6368806228..490157d382947 100644 --- a/solution/2900-2999/2952.Minimum Number of Coins to be Added/README.md +++ b/solution/2900-2999/2952.Minimum Number of Coins to be Added/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def minimumAddedCoins(self, coins: List[int], target: int) -> int: @@ -103,6 +105,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumAddedCoins(int[] coins, int target) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func minimumAddedCoins(coins []int, target int) (ans int) { slices.Sort(coins) @@ -156,6 +164,8 @@ func minimumAddedCoins(coins []int, target int) (ans int) { } ``` +#### TypeScript + ```ts function minimumAddedCoins(coins: number[], target: number): number { coins.sort((a, b) => a - b); diff --git a/solution/2900-2999/2952.Minimum Number of Coins to be Added/README_EN.md b/solution/2900-2999/2952.Minimum Number of Coins to be Added/README_EN.md index 384bed7f643a8..d747d0fd8af72 100644 --- a/solution/2900-2999/2952.Minimum Number of Coins to be Added/README_EN.md +++ b/solution/2900-2999/2952.Minimum Number of Coins to be Added/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def minimumAddedCoins(self, coins: List[int], target: int) -> int: @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumAddedCoins(int[] coins, int target) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func minimumAddedCoins(coins []int, target int) (ans int) { slices.Sort(coins) @@ -155,6 +163,8 @@ func minimumAddedCoins(coins []int, target int) (ans int) { } ``` +#### TypeScript + ```ts function minimumAddedCoins(coins: number[], target: number): number { coins.sort((a, b) => a - b); diff --git a/solution/2900-2999/2953.Count Complete Substrings/README.md b/solution/2900-2999/2953.Count Complete Substrings/README.md index 008736460046e..fc6393f1e3b68 100644 --- a/solution/2900-2999/2953.Count Complete Substrings/README.md +++ b/solution/2900-2999/2953.Count Complete Substrings/README.md @@ -79,6 +79,8 @@ tags: +#### Python3 + ```python class Solution: def countCompleteSubstrings(self, word: str, k: int) -> int: @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countCompleteSubstrings(String word, int k) { @@ -169,6 +173,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -224,6 +230,8 @@ public: }; ``` +#### Go + ```go func countCompleteSubstrings(word string, k int) (ans int) { n := len(word) @@ -281,6 +289,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function countCompleteSubstrings(word: string, k: number): number { const f = (s: string): number => { diff --git a/solution/2900-2999/2953.Count Complete Substrings/README_EN.md b/solution/2900-2999/2953.Count Complete Substrings/README_EN.md index 0e54608d8fbc0..2a8f6f80e977f 100644 --- a/solution/2900-2999/2953.Count Complete Substrings/README_EN.md +++ b/solution/2900-2999/2953.Count Complete Substrings/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n \times |\Sigma|)$, and the space complexity is $O(|\ +#### Python3 + ```python class Solution: def countCompleteSubstrings(self, word: str, k: int) -> int: @@ -113,6 +115,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countCompleteSubstrings(String word, int k) { @@ -167,6 +171,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -222,6 +228,8 @@ public: }; ``` +#### Go + ```go func countCompleteSubstrings(word string, k int) (ans int) { n := len(word) @@ -279,6 +287,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function countCompleteSubstrings(word: string, k: number): number { const f = (s: string): number => { diff --git a/solution/2900-2999/2954.Count the Number of Infection Sequences/README.md b/solution/2900-2999/2954.Count the Number of Infection Sequences/README.md index 12e981fe34829..69f9b8f675d49 100644 --- a/solution/2900-2999/2954.Count the Number of Infection Sequences/README.md +++ b/solution/2900-2999/2954.Count the Number of Infection Sequences/README.md @@ -96,6 +96,8 @@ $$ +#### Python3 + ```python mod = 10**9 + 7 mx = 10**5 @@ -119,6 +121,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int MOD = (int) (1e9 + 7); @@ -171,6 +175,8 @@ class Solution { } ``` +#### C++ + ```cpp const int MX = 1e5; const int MOD = 1e9 + 7; @@ -224,6 +230,8 @@ public: }; ``` +#### Go + ```go const MX = 1e5 const MOD = 1e9 + 7 @@ -278,6 +286,8 @@ func numberOfSequence(n int, sick []int) int { } ``` +#### TypeScript + ```ts const MX = 1e5; const MOD: bigint = BigInt(1e9 + 7); diff --git a/solution/2900-2999/2954.Count the Number of Infection Sequences/README_EN.md b/solution/2900-2999/2954.Count the Number of Infection Sequences/README_EN.md index 1d97a01182ec9..f2a68636df52a 100644 --- a/solution/2900-2999/2954.Count the Number of Infection Sequences/README_EN.md +++ b/solution/2900-2999/2954.Count the Number of Infection Sequences/README_EN.md @@ -94,6 +94,8 @@ The time complexity is $O(m)$, where $m$ is the length of the array $sick$. Igno +#### Python3 + ```python mod = 10**9 + 7 mx = 10**5 @@ -117,6 +119,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private static final int MOD = (int) (1e9 + 7); @@ -169,6 +173,8 @@ class Solution { } ``` +#### C++ + ```cpp const int MX = 1e5; const int MOD = 1e9 + 7; @@ -222,6 +228,8 @@ public: }; ``` +#### Go + ```go const MX = 1e5 const MOD = 1e9 + 7 @@ -276,6 +284,8 @@ func numberOfSequence(n int, sick []int) int { } ``` +#### TypeScript + ```ts const MX = 1e5; const MOD: bigint = BigInt(1e9 + 7); diff --git a/solution/2900-2999/2955.Number of Same-End Substrings/README.md b/solution/2900-2999/2955.Number of Same-End Substrings/README.md index 56b3d5b29bcb6..a78fff51422dd 100644 --- a/solution/2900-2999/2955.Number of Same-End Substrings/README.md +++ b/solution/2900-2999/2955.Number of Same-End Substrings/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def sameEndSubstringCount(self, s: str, queries: List[List[int]]) -> List[int]: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] sameEndSubstringCount(String s, int[][] queries) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func sameEndSubstringCount(s string, queries [][]int) []int { n := len(s) @@ -177,6 +185,8 @@ func sameEndSubstringCount(s string, queries [][]int) []int { } ``` +#### TypeScript + ```ts function sameEndSubstringCount(s: string, queries: number[][]): number[] { const n: number = s.length; @@ -199,6 +209,8 @@ function sameEndSubstringCount(s: string, queries: number[][]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn same_end_substring_count(s: String, queries: Vec>) -> Vec { diff --git a/solution/2900-2999/2955.Number of Same-End Substrings/README_EN.md b/solution/2900-2999/2955.Number of Same-End Substrings/README_EN.md index 9327819fdfe7b..ca3c187058002 100644 --- a/solution/2900-2999/2955.Number of Same-End Substrings/README_EN.md +++ b/solution/2900-2999/2955.Number of Same-End Substrings/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O((n + m) \times |\Sigma|)$, and the space complexity is +#### Python3 + ```python class Solution: def sameEndSubstringCount(self, s: str, queries: List[List[int]]) -> List[int]: @@ -94,6 +96,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] sameEndSubstringCount(String s, int[][] queries) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func sameEndSubstringCount(s string, queries [][]int) []int { n := len(s) @@ -176,6 +184,8 @@ func sameEndSubstringCount(s string, queries [][]int) []int { } ``` +#### TypeScript + ```ts function sameEndSubstringCount(s: string, queries: number[][]): number[] { const n: number = s.length; @@ -198,6 +208,8 @@ function sameEndSubstringCount(s: string, queries: number[][]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn same_end_substring_count(s: String, queries: Vec>) -> Vec { diff --git a/solution/2900-2999/2956.Find Common Elements Between Two Arrays/README.md b/solution/2900-2999/2956.Find Common Elements Between Two Arrays/README.md index d6e18dfec2a01..43429501f9304 100644 --- a/solution/2900-2999/2956.Find Common Elements Between Two Arrays/README.md +++ b/solution/2900-2999/2956.Find Common Elements Between Two Arrays/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def findIntersectionValues(self, nums1: List[int], nums2: List[int]) -> List[int]: @@ -88,6 +90,8 @@ class Solution: return [sum(x in s2 for x in nums1), sum(x in s1 for x in nums2)] ``` +#### Java + ```java class Solution { public int[] findIntersectionValues(int[] nums1, int[] nums2) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func findIntersectionValues(nums1 []int, nums2 []int) []int { s1 := [101]int{} @@ -156,6 +164,8 @@ func findIntersectionValues(nums1 []int, nums2 []int) []int { } ``` +#### TypeScript + ```ts function findIntersectionValues(nums1: number[], nums2: number[]): number[] { const s1: number[] = Array(101).fill(0); diff --git a/solution/2900-2999/2956.Find Common Elements Between Two Arrays/README_EN.md b/solution/2900-2999/2956.Find Common Elements Between Two Arrays/README_EN.md index 1e6a8ea00fb63..c0e7ad12a1bd1 100644 --- a/solution/2900-2999/2956.Find Common Elements Between Two Arrays/README_EN.md +++ b/solution/2900-2999/2956.Find Common Elements Between Two Arrays/README_EN.md @@ -79,6 +79,8 @@ The time complexity is $O(n + m)$, and the space complexity is $O(n + m)$. Here, +#### Python3 + ```python class Solution: def findIntersectionValues(self, nums1: List[int], nums2: List[int]) -> List[int]: @@ -86,6 +88,8 @@ class Solution: return [sum(x in s2 for x in nums1), sum(x in s1 for x in nums2)] ``` +#### Java + ```java class Solution { public int[] findIntersectionValues(int[] nums1, int[] nums2) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func findIntersectionValues(nums1 []int, nums2 []int) []int { s1 := [101]int{} @@ -154,6 +162,8 @@ func findIntersectionValues(nums1 []int, nums2 []int) []int { } ``` +#### TypeScript + ```ts function findIntersectionValues(nums1: number[], nums2: number[]): number[] { const s1: number[] = Array(101).fill(0); diff --git a/solution/2900-2999/2957.Remove Adjacent Almost-Equal Characters/README.md b/solution/2900-2999/2957.Remove Adjacent Almost-Equal Characters/README.md index d3004d3398b83..19a62da702dc4 100644 --- a/solution/2900-2999/2957.Remove Adjacent Almost-Equal Characters/README.md +++ b/solution/2900-2999/2957.Remove Adjacent Almost-Equal Characters/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def removeAlmostEqualCharacters(self, word: str) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int removeAlmostEqualCharacters(String word) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func removeAlmostEqualCharacters(word string) (ans int) { for i := 1; i < len(word); i++ { @@ -145,6 +153,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function removeAlmostEqualCharacters(word: string): number { let ans = 0; diff --git a/solution/2900-2999/2957.Remove Adjacent Almost-Equal Characters/README_EN.md b/solution/2900-2999/2957.Remove Adjacent Almost-Equal Characters/README_EN.md index 1d4937634cf14..0fe5bf41239f0 100644 --- a/solution/2900-2999/2957.Remove Adjacent Almost-Equal Characters/README_EN.md +++ b/solution/2900-2999/2957.Remove Adjacent Almost-Equal Characters/README_EN.md @@ -79,6 +79,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string `word`. The +#### Python3 + ```python class Solution: def removeAlmostEqualCharacters(self, word: str) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int removeAlmostEqualCharacters(String word) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func removeAlmostEqualCharacters(word string) (ans int) { for i := 1; i < len(word); i++ { @@ -143,6 +151,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function removeAlmostEqualCharacters(word: string): number { let ans = 0; diff --git a/solution/2900-2999/2958.Length of Longest Subarray With at Most K Frequency/README.md b/solution/2900-2999/2958.Length of Longest Subarray With at Most K Frequency/README.md index 3a9ea324fb301..e4e9605fb7ce4 100644 --- a/solution/2900-2999/2958.Length of Longest Subarray With at Most K Frequency/README.md +++ b/solution/2900-2999/2958.Length of Longest Subarray With at Most K Frequency/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def maxSubarrayLength(self, nums: List[int], k: int) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxSubarrayLength(int[] nums, int k) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func maxSubarrayLength(nums []int, k int) (ans int) { cnt := map[int]int{} @@ -148,6 +156,8 @@ func maxSubarrayLength(nums []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function maxSubarrayLength(nums: number[], k: number): number { const cnt: Map = new Map(); diff --git a/solution/2900-2999/2958.Length of Longest Subarray With at Most K Frequency/README_EN.md b/solution/2900-2999/2958.Length of Longest Subarray With at Most K Frequency/README_EN.md index 989151860845a..14b62b5fd931b 100644 --- a/solution/2900-2999/2958.Length of Longest Subarray With at Most K Frequency/README_EN.md +++ b/solution/2900-2999/2958.Length of Longest Subarray With at Most K Frequency/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def maxSubarrayLength(self, nums: List[int], k: int) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxSubarrayLength(int[] nums, int k) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func maxSubarrayLength(nums []int, k int) (ans int) { cnt := map[int]int{} @@ -146,6 +154,8 @@ func maxSubarrayLength(nums []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function maxSubarrayLength(nums: number[], k: number): number { const cnt: Map = new Map(); diff --git a/solution/2900-2999/2959.Number of Possible Sets of Closing Branches/README.md b/solution/2900-2999/2959.Number of Possible Sets of Closing Branches/README.md index 44bcb9a09631d..cfda725e63bd7 100644 --- a/solution/2900-2999/2959.Number of Possible Sets of Closing Branches/README.md +++ b/solution/2900-2999/2959.Number of Possible Sets of Closing Branches/README.md @@ -114,6 +114,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfSets(self, n: int, maxDistance: int, roads: List[List[int]]) -> int: @@ -142,6 +144,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numberOfSets(int n, int maxDistance, int[][] roads) { @@ -185,6 +189,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -225,6 +231,8 @@ public: }; ``` +#### Go + ```go func numberOfSets(n int, maxDistance int, roads [][]int) (ans int) { for mask := 0; mask < 1< +#### Python3 + ```python class Solution: def numberOfSets(self, n: int, maxDistance: int, roads: List[List[int]]) -> int: @@ -136,6 +138,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numberOfSets(int n, int maxDistance, int[][] roads) { @@ -179,6 +183,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -219,6 +225,8 @@ public: }; ``` +#### Go + ```go func numberOfSets(n int, maxDistance int, roads [][]int) (ans int) { for mask := 0; mask < 1< +#### Python3 + ```python class Solution: def countTestedDevices(self, batteryPercentages: List[int]) -> int: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countTestedDevices(int[] batteryPercentages) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func countTestedDevices(batteryPercentages []int) (ans int) { for _, x := range batteryPercentages { @@ -136,6 +144,8 @@ func countTestedDevices(batteryPercentages []int) (ans int) { } ``` +#### TypeScript + ```ts function countTestedDevices(batteryPercentages: number[]): number { let ans = 0; @@ -146,6 +156,8 @@ function countTestedDevices(batteryPercentages: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_tested_devices(battery_percentages: Vec) -> i32 { diff --git a/solution/2900-2999/2960.Count Tested Devices After Test Operations/README_EN.md b/solution/2900-2999/2960.Count Tested Devices After Test Operations/README_EN.md index f97ec94ddae1b..1f53d8659d66d 100644 --- a/solution/2900-2999/2960.Count Tested Devices After Test Operations/README_EN.md +++ b/solution/2900-2999/2960.Count Tested Devices After Test Operations/README_EN.md @@ -89,6 +89,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def countTestedDevices(self, batteryPercentages: List[int]) -> int: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countTestedDevices(int[] batteryPercentages) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func countTestedDevices(batteryPercentages []int) (ans int) { for _, x := range batteryPercentages { @@ -134,6 +142,8 @@ func countTestedDevices(batteryPercentages []int) (ans int) { } ``` +#### TypeScript + ```ts function countTestedDevices(batteryPercentages: number[]): number { let ans = 0; @@ -144,6 +154,8 @@ function countTestedDevices(batteryPercentages: number[]): number { } ``` +#### Rust + ```rust impl Solution { pub fn count_tested_devices(battery_percentages: Vec) -> i32 { diff --git a/solution/2900-2999/2961.Double Modular Exponentiation/README.md b/solution/2900-2999/2961.Double Modular Exponentiation/README.md index 8b5ca2a3db05b..1a873ff76a207 100644 --- a/solution/2900-2999/2961.Double Modular Exponentiation/README.md +++ b/solution/2900-2999/2961.Double Modular Exponentiation/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def getGoodIndices(self, variables: List[List[int]], target: int) -> List[int]: @@ -90,6 +92,8 @@ class Solution: ] ``` +#### Java + ```java class Solution { public List getGoodIndices(int[][] variables, int target) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func getGoodIndices(variables [][]int, target int) (ans []int) { qpow := func(a, n, mod int) int { @@ -166,6 +174,8 @@ func getGoodIndices(variables [][]int, target int) (ans []int) { } ``` +#### TypeScript + ```ts function getGoodIndices(variables: number[][], target: number): number[] { const qpow = (a: number, n: number, mod: number) => { diff --git a/solution/2900-2999/2961.Double Modular Exponentiation/README_EN.md b/solution/2900-2999/2961.Double Modular Exponentiation/README_EN.md index c1af3785072c5..26f8c8046d1e6 100644 --- a/solution/2900-2999/2961.Double Modular Exponentiation/README_EN.md +++ b/solution/2900-2999/2961.Double Modular Exponentiation/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n \times \log M)$, where $n$ is the length of the arra +#### Python3 + ```python class Solution: def getGoodIndices(self, variables: List[List[int]], target: int) -> List[int]: @@ -88,6 +90,8 @@ class Solution: ] ``` +#### Java + ```java class Solution { public List getGoodIndices(int[][] variables, int target) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func getGoodIndices(variables [][]int, target int) (ans []int) { qpow := func(a, n, mod int) int { @@ -164,6 +172,8 @@ func getGoodIndices(variables [][]int, target int) (ans []int) { } ``` +#### TypeScript + ```ts function getGoodIndices(variables: number[][], target: number): number[] { const qpow = (a: number, n: number, mod: number) => { diff --git a/solution/2900-2999/2962.Count Subarrays Where Max Element Appears at Least K Times/README.md b/solution/2900-2999/2962.Count Subarrays Where Max Element Appears at Least K Times/README.md index 0e2957d79e1df..7faf9c2c5a9a7 100644 --- a/solution/2900-2999/2962.Count Subarrays Where Max Element Appears at Least K Times/README.md +++ b/solution/2900-2999/2962.Count Subarrays Where Max Element Appears at Least K Times/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def countSubarrays(self, nums: List[int], k: int) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long countSubarrays(int[] nums, int k) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func countSubarrays(nums []int, k int) (ans int64) { mx := slices.Max(nums) @@ -156,6 +164,8 @@ func countSubarrays(nums []int, k int) (ans int64) { } ``` +#### TypeScript + ```ts function countSubarrays(nums: number[], k: number): number { const mx = Math.max(...nums); diff --git a/solution/2900-2999/2962.Count Subarrays Where Max Element Appears at Least K Times/README_EN.md b/solution/2900-2999/2962.Count Subarrays Where Max Element Appears at Least K Times/README_EN.md index d6972cb6bf962..07b37a3dd5c18 100644 --- a/solution/2900-2999/2962.Count Subarrays Where Max Element Appears at Least K Times/README_EN.md +++ b/solution/2900-2999/2962.Count Subarrays Where Max Element Appears at Least K Times/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def countSubarrays(self, nums: List[int], k: int) -> int: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long countSubarrays(int[] nums, int k) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -131,6 +137,8 @@ public: }; ``` +#### Go + ```go func countSubarrays(nums []int, k int) (ans int64) { mx := slices.Max(nums) @@ -154,6 +162,8 @@ func countSubarrays(nums []int, k int) (ans int64) { } ``` +#### TypeScript + ```ts function countSubarrays(nums: number[], k: number): number { const mx = Math.max(...nums); diff --git a/solution/2900-2999/2963.Count the Number of Good Partitions/README.md b/solution/2900-2999/2963.Count the Number of Good Partitions/README.md index 4ae523c1a8ac4..bb22ac6f8e067 100644 --- a/solution/2900-2999/2963.Count the Number of Good Partitions/README.md +++ b/solution/2900-2999/2963.Count the Number of Good Partitions/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfGoodPartitions(self, nums: List[int]) -> int: @@ -96,6 +98,8 @@ class Solution: return pow(2, k - 1, mod) ``` +#### Java + ```java class Solution { public int numberOfGoodPartitions(int[] nums) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func numberOfGoodPartitions(nums []int) int { qpow := func(a, n, mod int) int { @@ -185,6 +193,8 @@ func numberOfGoodPartitions(nums []int) int { } ``` +#### TypeScript + ```ts function numberOfGoodPartitions(nums: number[]): number { const qpow = (a: number, n: number, mod: number) => { diff --git a/solution/2900-2999/2963.Count the Number of Good Partitions/README_EN.md b/solution/2900-2999/2963.Count the Number of Good Partitions/README_EN.md index e5c92e5fb2361..ad9f6989f0aa1 100644 --- a/solution/2900-2999/2963.Count the Number of Good Partitions/README_EN.md +++ b/solution/2900-2999/2963.Count the Number of Good Partitions/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def numberOfGoodPartitions(self, nums: List[int]) -> int: @@ -94,6 +96,8 @@ class Solution: return pow(2, k - 1, mod) ``` +#### Java + ```java class Solution { public int numberOfGoodPartitions(int[] nums) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func numberOfGoodPartitions(nums []int) int { qpow := func(a, n, mod int) int { @@ -183,6 +191,8 @@ func numberOfGoodPartitions(nums []int) int { } ``` +#### TypeScript + ```ts function numberOfGoodPartitions(nums: number[]): number { const qpow = (a: number, n: number, mod: number) => { diff --git a/solution/2900-2999/2964.Number of Divisible Triplet Sums/README.md b/solution/2900-2999/2964.Number of Divisible Triplet Sums/README.md index 04492ded5a129..27af189606693 100644 --- a/solution/2900-2999/2964.Number of Divisible Triplet Sums/README.md +++ b/solution/2900-2999/2964.Number of Divisible Triplet Sums/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def divisibleTripletCount(self, nums: List[int], d: int) -> int: @@ -82,6 +84,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int divisibleTripletCount(int[] nums, int d) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func divisibleTripletCount(nums []int, d int) (ans int) { n := len(nums) @@ -132,6 +140,8 @@ func divisibleTripletCount(nums []int, d int) (ans int) { } ``` +#### TypeScript + ```ts function divisibleTripletCount(nums: number[], d: number): number { const n = nums.length; diff --git a/solution/2900-2999/2964.Number of Divisible Triplet Sums/README_EN.md b/solution/2900-2999/2964.Number of Divisible Triplet Sums/README_EN.md index 68bb5e22538fe..5fc384d853822 100644 --- a/solution/2900-2999/2964.Number of Divisible Triplet Sums/README_EN.md +++ b/solution/2900-2999/2964.Number of Divisible Triplet Sums/README_EN.md @@ -68,6 +68,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$. Here, $n$ i +#### Python3 + ```python class Solution: def divisibleTripletCount(self, nums: List[int], d: int) -> int: @@ -81,6 +83,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int divisibleTripletCount(int[] nums, int d) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func divisibleTripletCount(nums []int, d int) (ans int) { n := len(nums) @@ -131,6 +139,8 @@ func divisibleTripletCount(nums []int, d int) (ans int) { } ``` +#### TypeScript + ```ts function divisibleTripletCount(nums: number[], d: number): number { const n = nums.length; diff --git a/solution/2900-2999/2965.Find Missing and Repeated Values/README.md b/solution/2900-2999/2965.Find Missing and Repeated Values/README.md index 25dde321bf182..3be5af6acdedb 100644 --- a/solution/2900-2999/2965.Find Missing and Repeated Values/README.md +++ b/solution/2900-2999/2965.Find Missing and Repeated Values/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def findMissingAndRepeatedValues(self, grid: List[List[int]]) -> List[int]: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] findMissingAndRepeatedValues(int[][] grid) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func findMissingAndRepeatedValues(grid [][]int) []int { n := len(grid) @@ -159,6 +167,8 @@ func findMissingAndRepeatedValues(grid [][]int) []int { } ``` +#### TypeScript + ```ts function findMissingAndRepeatedValues(grid: number[][]): number[] { const n = grid.length; diff --git a/solution/2900-2999/2965.Find Missing and Repeated Values/README_EN.md b/solution/2900-2999/2965.Find Missing and Repeated Values/README_EN.md index f4aa57e97f58c..048ee68ec8351 100644 --- a/solution/2900-2999/2965.Find Missing and Repeated Values/README_EN.md +++ b/solution/2900-2999/2965.Find Missing and Repeated Values/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$. Here, $n$ +#### Python3 + ```python class Solution: def findMissingAndRepeatedValues(self, grid: List[List[int]]) -> List[int]: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] findMissingAndRepeatedValues(int[][] grid) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -133,6 +139,8 @@ public: }; ``` +#### Go + ```go func findMissingAndRepeatedValues(grid [][]int) []int { n := len(grid) @@ -155,6 +163,8 @@ func findMissingAndRepeatedValues(grid [][]int) []int { } ``` +#### TypeScript + ```ts function findMissingAndRepeatedValues(grid: number[][]): number[] { const n = grid.length; diff --git a/solution/2900-2999/2966.Divide Array Into Arrays With Max Difference/README.md b/solution/2900-2999/2966.Divide Array Into Arrays With Max Difference/README.md index bb44bc24e982d..8f009806f0e0e 100644 --- a/solution/2900-2999/2966.Divide Array Into Arrays With Max Difference/README.md +++ b/solution/2900-2999/2966.Divide Array Into Arrays With Max Difference/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def divideArray(self, nums: List[int], k: int) -> List[List[int]]: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] divideArray(int[] nums, int k) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func divideArray(nums []int, k int) [][]int { sort.Ints(nums) @@ -143,6 +151,8 @@ func divideArray(nums []int, k int) [][]int { } ``` +#### TypeScript + ```ts function divideArray(nums: number[], k: number): number[][] { nums.sort((a, b) => a - b); diff --git a/solution/2900-2999/2966.Divide Array Into Arrays With Max Difference/README_EN.md b/solution/2900-2999/2966.Divide Array Into Arrays With Max Difference/README_EN.md index 8b52f534b1014..ef600b055a69d 100644 --- a/solution/2900-2999/2966.Divide Array Into Arrays With Max Difference/README_EN.md +++ b/solution/2900-2999/2966.Divide Array Into Arrays With Max Difference/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def divideArray(self, nums: List[int], k: int) -> List[List[int]]: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] divideArray(int[] nums, int k) { @@ -107,6 +111,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func divideArray(nums []int, k int) [][]int { sort.Ints(nums) @@ -141,6 +149,8 @@ func divideArray(nums []int, k int) [][]int { } ``` +#### TypeScript + ```ts function divideArray(nums: number[], k: number): number[][] { nums.sort((a, b) => a - b); diff --git a/solution/2900-2999/2967.Minimum Cost to Make Array Equalindromic/README.md b/solution/2900-2999/2967.Minimum Cost to Make Array Equalindromic/README.md index 25719c6cd4c6a..b1518e39a5b21 100644 --- a/solution/2900-2999/2967.Minimum Cost to Make Array Equalindromic/README.md +++ b/solution/2900-2999/2967.Minimum Cost to Make Array Equalindromic/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python ps = [] for i in range(1, 10**5 + 1): @@ -116,6 +118,8 @@ class Solution: return min(f(ps[j]) for j in range(i - 1, i + 2) if 0 <= j < len(ps)) ``` +#### Java + ```java public class Solution { private static long[] ps; @@ -157,6 +161,8 @@ public class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -199,6 +205,8 @@ public: }; ``` +#### Go + ```go var ps [2 * 100000]int64 @@ -254,6 +262,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts const ps = Array(2e5).fill(0); diff --git a/solution/2900-2999/2967.Minimum Cost to Make Array Equalindromic/README_EN.md b/solution/2900-2999/2967.Minimum Cost to Make Array Equalindromic/README_EN.md index 2bca058c851dd..844930b3fc80a 100644 --- a/solution/2900-2999/2967.Minimum Cost to Make Array Equalindromic/README_EN.md +++ b/solution/2900-2999/2967.Minimum Cost to Make Array Equalindromic/README_EN.md @@ -93,6 +93,8 @@ Similar problems: +#### Python3 + ```python ps = [] for i in range(1, 10**5 + 1): @@ -114,6 +116,8 @@ class Solution: return min(f(ps[j]) for j in range(i - 1, i + 2) if 0 <= j < len(ps)) ``` +#### Java + ```java public class Solution { private static long[] ps; @@ -155,6 +159,8 @@ public class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -197,6 +203,8 @@ public: }; ``` +#### Go + ```go var ps [2 * 100000]int64 @@ -252,6 +260,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts const ps = Array(2e5).fill(0); diff --git a/solution/2900-2999/2968.Apply Operations to Maximize Frequency Score/README.md b/solution/2900-2999/2968.Apply Operations to Maximize Frequency Score/README.md index 461729c83ac43..2d9dd8dd08c58 100644 --- a/solution/2900-2999/2968.Apply Operations to Maximize Frequency Score/README.md +++ b/solution/2900-2999/2968.Apply Operations to Maximize Frequency Score/README.md @@ -107,6 +107,8 @@ $$ +#### Python3 + ```python class Solution: def maxFrequencyScore(self, nums: List[int], k: int) -> int: @@ -132,6 +134,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { public int maxFrequencyScore(int[] nums, long k) { @@ -169,6 +173,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -209,6 +215,8 @@ public: }; ``` +#### Go + ```go func maxFrequencyScore(nums []int, k int64) int { sort.Ints(nums) @@ -246,6 +254,8 @@ func maxFrequencyScore(nums []int, k int64) int { } ``` +#### TypeScript + ```ts function maxFrequencyScore(nums: number[], k: number): number { nums.sort((a, b) => a - b); diff --git a/solution/2900-2999/2968.Apply Operations to Maximize Frequency Score/README_EN.md b/solution/2900-2999/2968.Apply Operations to Maximize Frequency Score/README_EN.md index 4aa80a7045541..b4a4ad056a701 100644 --- a/solution/2900-2999/2968.Apply Operations to Maximize Frequency Score/README_EN.md +++ b/solution/2900-2999/2968.Apply Operations to Maximize Frequency Score/README_EN.md @@ -105,6 +105,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def maxFrequencyScore(self, nums: List[int], k: int) -> int: @@ -130,6 +132,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { public int maxFrequencyScore(int[] nums, long k) { @@ -167,6 +171,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -207,6 +213,8 @@ public: }; ``` +#### Go + ```go func maxFrequencyScore(nums []int, k int64) int { sort.Ints(nums) @@ -244,6 +252,8 @@ func maxFrequencyScore(nums []int, k int64) int { } ``` +#### TypeScript + ```ts function maxFrequencyScore(nums: number[], k: number): number { nums.sort((a, b) => a - b); diff --git a/solution/2900-2999/2969.Minimum Number of Coins for Fruits II/README.md b/solution/2900-2999/2969.Minimum Number of Coins for Fruits II/README.md index aa4727f7f2a6e..fb81ff2faf597 100644 --- a/solution/2900-2999/2969.Minimum Number of Coins for Fruits II/README.md +++ b/solution/2900-2999/2969.Minimum Number of Coins for Fruits II/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python class Solution: def minimumCoins(self, prices: List[int]) -> int: @@ -111,6 +113,8 @@ class Solution: return prices[0] ``` +#### Java + ```java class Solution { public int minimumCoins(int[] prices) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func minimumCoins(prices []int) int { n := len(prices) @@ -234,6 +242,8 @@ func (q Deque) Get(i int) int { } ``` +#### TypeScript + ```ts function minimumCoins(prices: number[]): number { const n = prices.length; diff --git a/solution/2900-2999/2969.Minimum Number of Coins for Fruits II/README_EN.md b/solution/2900-2999/2969.Minimum Number of Coins for Fruits II/README_EN.md index 856dfca986b84..36d9583112545 100644 --- a/solution/2900-2999/2969.Minimum Number of Coins for Fruits II/README_EN.md +++ b/solution/2900-2999/2969.Minimum Number of Coins for Fruits II/README_EN.md @@ -93,6 +93,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def minimumCoins(self, prices: List[int]) -> int: @@ -109,6 +111,8 @@ class Solution: return prices[0] ``` +#### Java + ```java class Solution { public int minimumCoins(int[] prices) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func minimumCoins(prices []int) int { n := len(prices) @@ -232,6 +240,8 @@ func (q Deque) Get(i int) int { } ``` +#### TypeScript + ```ts function minimumCoins(prices: number[]): number { const n = prices.length; diff --git a/solution/2900-2999/2970.Count the Number of Incremovable Subarrays I/README.md b/solution/2900-2999/2970.Count the Number of Incremovable Subarrays I/README.md index bcc71b95483f5..bf61727a04815 100644 --- a/solution/2900-2999/2970.Count the Number of Incremovable Subarrays I/README.md +++ b/solution/2900-2999/2970.Count the Number of Incremovable Subarrays I/README.md @@ -103,6 +103,8 @@ nums 中只有这 7 个移除递增子数组。 +#### Python3 + ```python class Solution: def incremovableSubarrayCount(self, nums: List[int]) -> int: @@ -123,6 +125,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int incremovableSubarrayCount(int[] nums) { @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func incremovableSubarrayCount(nums []int) int { i, n := 0, len(nums) @@ -197,6 +205,8 @@ func incremovableSubarrayCount(nums []int) int { } ``` +#### TypeScript + ```ts function incremovableSubarrayCount(nums: number[]): number { const n = nums.length; diff --git a/solution/2900-2999/2970.Count the Number of Incremovable Subarrays I/README_EN.md b/solution/2900-2999/2970.Count the Number of Incremovable Subarrays I/README_EN.md index c16b4c848fe31..30d1b7dc6d5d4 100644 --- a/solution/2900-2999/2970.Count the Number of Incremovable Subarrays I/README_EN.md +++ b/solution/2900-2999/2970.Count the Number of Incremovable Subarrays I/README_EN.md @@ -101,6 +101,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def incremovableSubarrayCount(self, nums: List[int]) -> int: @@ -121,6 +123,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int incremovableSubarrayCount(int[] nums) { @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go func incremovableSubarrayCount(nums []int) int { i, n := 0, len(nums) @@ -195,6 +203,8 @@ func incremovableSubarrayCount(nums []int) int { } ``` +#### TypeScript + ```ts function incremovableSubarrayCount(nums: number[]): number { const n = nums.length; diff --git a/solution/2900-2999/2971.Find Polygon With the Largest Perimeter/README.md b/solution/2900-2999/2971.Find Polygon With the Largest Perimeter/README.md index 5073c506eee3d..2061d7f68a2b8 100644 --- a/solution/2900-2999/2971.Find Polygon With the Largest Perimeter/README.md +++ b/solution/2900-2999/2971.Find Polygon With the Largest Perimeter/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def largestPerimeter(self, nums: List[int]) -> int: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long largestPerimeter(int[] nums) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func largestPerimeter(nums []int) int64 { sort.Ints(nums) @@ -155,6 +163,8 @@ func largestPerimeter(nums []int) int64 { } ``` +#### TypeScript + ```ts function largestPerimeter(nums: number[]): number { nums.sort((a, b) => a - b); diff --git a/solution/2900-2999/2971.Find Polygon With the Largest Perimeter/README_EN.md b/solution/2900-2999/2971.Find Polygon With the Largest Perimeter/README_EN.md index 34c35e2f093d7..d662cc8eee23b 100644 --- a/solution/2900-2999/2971.Find Polygon With the Largest Perimeter/README_EN.md +++ b/solution/2900-2999/2971.Find Polygon With the Largest Perimeter/README_EN.md @@ -76,6 +76,8 @@ It can be shown that the largest possible perimeter is 12. +#### Python3 + ```python class Solution: def largestPerimeter(self, nums: List[int]) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long largestPerimeter(int[] nums) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func largestPerimeter(nums []int) int64 { sort.Ints(nums) @@ -147,6 +155,8 @@ func largestPerimeter(nums []int) int64 { } ``` +#### TypeScript + ```ts function largestPerimeter(nums: number[]): number { nums.sort((a, b) => a - b); diff --git a/solution/2900-2999/2972.Count the Number of Incremovable Subarrays II/README.md b/solution/2900-2999/2972.Count the Number of Incremovable Subarrays II/README.md index 8e2bfd31e5204..04a8840d635fb 100644 --- a/solution/2900-2999/2972.Count the Number of Incremovable Subarrays II/README.md +++ b/solution/2900-2999/2972.Count the Number of Incremovable Subarrays II/README.md @@ -102,6 +102,8 @@ nums 中只有这 7 个移除递增子数组。 +#### Python3 + ```python class Solution: def incremovableSubarrayCount(self, nums: List[int]) -> int: @@ -122,6 +124,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long incremovableSubarrayCount(int[] nums) { @@ -147,6 +151,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -173,6 +179,8 @@ public: }; ``` +#### Go + ```go func incremovableSubarrayCount(nums []int) int64 { i, n := 0, len(nums) @@ -196,6 +204,8 @@ func incremovableSubarrayCount(nums []int) int64 { } ``` +#### TypeScript + ```ts function incremovableSubarrayCount(nums: number[]): number { const n = nums.length; diff --git a/solution/2900-2999/2972.Count the Number of Incremovable Subarrays II/README_EN.md b/solution/2900-2999/2972.Count the Number of Incremovable Subarrays II/README_EN.md index 03423609e31e5..bdf3a7f27099e 100644 --- a/solution/2900-2999/2972.Count the Number of Incremovable Subarrays II/README_EN.md +++ b/solution/2900-2999/2972.Count the Number of Incremovable Subarrays II/README_EN.md @@ -100,6 +100,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def incremovableSubarrayCount(self, nums: List[int]) -> int: @@ -120,6 +122,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long incremovableSubarrayCount(int[] nums) { @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -171,6 +177,8 @@ public: }; ``` +#### Go + ```go func incremovableSubarrayCount(nums []int) int64 { i, n := 0, len(nums) @@ -194,6 +202,8 @@ func incremovableSubarrayCount(nums []int) int64 { } ``` +#### TypeScript + ```ts function incremovableSubarrayCount(nums: number[]): number { const n = nums.length; diff --git a/solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/README.md b/solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/README.md index 92aafbb20bc8e..5b206924234e2 100644 --- a/solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/README.md +++ b/solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/README.md @@ -119,6 +119,8 @@ tags: +#### Python3 + ```python class Solution: def placedCoins(self, edges: List[List[int]], cost: List[int]) -> List[int]: @@ -144,6 +146,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] cost; @@ -189,6 +193,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -227,6 +233,8 @@ public: }; ``` +#### Go + ```go func placedCoins(edges [][]int, cost []int) []int64 { n := len(cost) @@ -265,6 +273,8 @@ func placedCoins(edges [][]int, cost []int) []int64 { } ``` +#### TypeScript + ```ts function placedCoins(edges: number[][], cost: number[]): number[] { const n = cost.length; diff --git a/solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/README_EN.md b/solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/README_EN.md index 4aa073769de1d..193f7dad8434c 100644 --- a/solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/README_EN.md +++ b/solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/README_EN.md @@ -111,6 +111,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def placedCoins(self, edges: List[List[int]], cost: List[int]) -> List[int]: @@ -136,6 +138,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int[] cost; @@ -181,6 +185,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -219,6 +225,8 @@ public: }; ``` +#### Go + ```go func placedCoins(edges [][]int, cost []int) []int64 { n := len(cost) @@ -257,6 +265,8 @@ func placedCoins(edges [][]int, cost []int) []int64 { } ``` +#### TypeScript + ```ts function placedCoins(edges: number[][], cost: number[]): number[] { const n = cost.length; diff --git a/solution/2900-2999/2974.Minimum Number Game/README.md b/solution/2900-2999/2974.Minimum Number Game/README.md index 8db2f8ebf949d..ac04c9f8d758f 100644 --- a/solution/2900-2999/2974.Minimum Number Game/README.md +++ b/solution/2900-2999/2974.Minimum Number Game/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def numberGame(self, nums: List[int]) -> List[int]: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] numberGame(int[] nums) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func numberGame(nums []int) (ans []int) { pq := &hp{nums} @@ -155,6 +163,8 @@ func (h *hp) Push(x interface{}) { } ``` +#### TypeScript + ```ts function numberGame(nums: number[]): number[] { const pq = new MinPriorityQueue(); @@ -171,6 +181,8 @@ function numberGame(nums: number[]): number[] { } ``` +#### Rust + ```rust use std::collections::BinaryHeap; use std::cmp::Reverse; @@ -211,6 +223,8 @@ impl Solution { +#### Python3 + ```python class Solution: def numberGame(self, nums: List[int]) -> List[int]: @@ -220,6 +234,8 @@ class Solution: return nums ``` +#### Java + ```java class Solution { public int[] numberGame(int[] nums) { @@ -234,6 +250,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -248,6 +266,8 @@ public: }; ``` +#### Go + ```go func numberGame(nums []int) []int { sort.Ints(nums) @@ -258,6 +278,8 @@ func numberGame(nums []int) []int { } ``` +#### TypeScript + ```ts function numberGame(nums: number[]): number[] { nums.sort((a, b) => a - b); @@ -268,6 +290,8 @@ function numberGame(nums: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn number_game(nums: Vec) -> Vec { diff --git a/solution/2900-2999/2974.Minimum Number Game/README_EN.md b/solution/2900-2999/2974.Minimum Number Game/README_EN.md index a0e25ac1333e7..dd8a23bd05010 100644 --- a/solution/2900-2999/2974.Minimum Number Game/README_EN.md +++ b/solution/2900-2999/2974.Minimum Number Game/README_EN.md @@ -72,6 +72,8 @@ Time complexity is $O(n \times \log n)$, and space complexity is $O(n)$. Where $ +#### Python3 + ```python class Solution: def numberGame(self, nums: List[int]) -> List[int]: @@ -84,6 +86,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] numberGame(int[] nums) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func numberGame(nums []int) (ans []int) { pq := &hp{nums} @@ -153,6 +161,8 @@ func (h *hp) Push(x interface{}) { } ``` +#### TypeScript + ```ts function numberGame(nums: number[]): number[] { const pq = new MinPriorityQueue(); @@ -169,6 +179,8 @@ function numberGame(nums: number[]): number[] { } ``` +#### Rust + ```rust use std::collections::BinaryHeap; use std::cmp::Reverse; @@ -209,6 +221,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def numberGame(self, nums: List[int]) -> List[int]: @@ -218,6 +232,8 @@ class Solution: return nums ``` +#### Java + ```java class Solution { public int[] numberGame(int[] nums) { @@ -232,6 +248,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -246,6 +264,8 @@ public: }; ``` +#### Go + ```go func numberGame(nums []int) []int { sort.Ints(nums) @@ -256,6 +276,8 @@ func numberGame(nums []int) []int { } ``` +#### TypeScript + ```ts function numberGame(nums: number[]): number[] { nums.sort((a, b) => a - b); @@ -266,6 +288,8 @@ function numberGame(nums: number[]): number[] { } ``` +#### Rust + ```rust impl Solution { pub fn number_game(nums: Vec) -> Vec { diff --git a/solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/README.md b/solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/README.md index 1ed5d98dfdd18..8a286c9d07e8f 100644 --- a/solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/README.md +++ b/solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def maximizeSquareArea( @@ -95,6 +97,8 @@ class Solution: return ans**2 % mod if ans else -1 ``` +#### Java + ```java class Solution { public int maximizeSquareArea(int m, int n, int[] hFences, int[] vFences) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func maximizeSquareArea(m int, n int, hFences []int, vFences []int) int { f := func(nums []int, k int) map[int]bool { @@ -184,6 +192,8 @@ func maximizeSquareArea(m int, n int, hFences []int, vFences []int) int { } ``` +#### TypeScript + ```ts function maximizeSquareArea(m: number, n: number, hFences: number[], vFences: number[]): number { const f = (nums: number[], k: number): Set => { diff --git a/solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/README_EN.md b/solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/README_EN.md index 786fb3c89b39b..b64005eacc8c5 100644 --- a/solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/README_EN.md +++ b/solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(h^2 + v^2)$, and the space complexity is $O(h^2 + v^2) +#### Python3 + ```python class Solution: def maximizeSquareArea( @@ -93,6 +95,8 @@ class Solution: return ans**2 % mod if ans else -1 ``` +#### Java + ```java class Solution { public int maximizeSquareArea(int m, int n, int[] hFences, int[] vFences) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func maximizeSquareArea(m int, n int, hFences []int, vFences []int) int { f := func(nums []int, k int) map[int]bool { @@ -182,6 +190,8 @@ func maximizeSquareArea(m int, n int, hFences []int, vFences []int) int { } ``` +#### TypeScript + ```ts function maximizeSquareArea(m: number, n: number, hFences: number[], vFences: number[]): number { const f = (nums: number[], k: number): Set => { diff --git a/solution/2900-2999/2976.Minimum Cost to Convert String I/README.md b/solution/2900-2999/2976.Minimum Cost to Convert String I/README.md index d0dfe8cdf8c91..c581c9b46204b 100644 --- a/solution/2900-2999/2976.Minimum Cost to Convert String I/README.md +++ b/solution/2900-2999/2976.Minimum Cost to Convert String I/README.md @@ -100,6 +100,8 @@ tags: +#### Python3 + ```python class Solution: def minimumCost( @@ -131,6 +133,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long minimumCost( @@ -171,6 +175,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -214,6 +220,8 @@ public: }; ``` +#### Go + ```go func minimumCost(source string, target string, original []byte, changed []byte, cost []int) (ans int64) { const inf = 1 << 29 @@ -258,6 +266,8 @@ func minimumCost(source string, target string, original []byte, changed []byte, } ``` +#### TypeScript + ```ts function minimumCost( source: string, diff --git a/solution/2900-2999/2976.Minimum Cost to Convert String I/README_EN.md b/solution/2900-2999/2976.Minimum Cost to Convert String I/README_EN.md index 17f6639e77794..1575a16ef3d44 100644 --- a/solution/2900-2999/2976.Minimum Cost to Convert String I/README_EN.md +++ b/solution/2900-2999/2976.Minimum Cost to Convert String I/README_EN.md @@ -92,6 +92,8 @@ The time complexity is $O(m + n + |\Sigma|^3)$, and the space complexity is $O(| +#### Python3 + ```python class Solution: def minimumCost( @@ -123,6 +125,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long minimumCost( @@ -163,6 +167,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -206,6 +212,8 @@ public: }; ``` +#### Go + ```go func minimumCost(source string, target string, original []byte, changed []byte, cost []int) (ans int64) { const inf = 1 << 29 @@ -250,6 +258,8 @@ func minimumCost(source string, target string, original []byte, changed []byte, } ``` +#### TypeScript + ```ts function minimumCost( source: string, diff --git a/solution/2900-2999/2977.Minimum Cost to Convert String II/README.md b/solution/2900-2999/2977.Minimum Cost to Convert String II/README.md index a2dae133a8750..846a3b81d3653 100644 --- a/solution/2900-2999/2977.Minimum Cost to Convert String II/README.md +++ b/solution/2900-2999/2977.Minimum Cost to Convert String II/README.md @@ -128,6 +128,8 @@ $$ +#### Python3 + ```python class Node: __slots__ = ["children", "v"] @@ -199,6 +201,8 @@ class Solution: return -1 if ans >= inf else ans ``` +#### Java + ```java class Node { Node[] children = new Node[26]; @@ -288,6 +292,8 @@ class Solution { } ``` +#### C++ + ```cpp class Node { public: @@ -387,6 +393,8 @@ private: }; ``` +#### Go + ```go type Node struct { children [26]*Node @@ -479,6 +487,8 @@ func minimumCost(source string, target string, original []string, changed []stri } ``` +#### TypeScript + ```ts class Node { children: (Node | null)[] = Array(26).fill(null); diff --git a/solution/2900-2999/2977.Minimum Cost to Convert String II/README_EN.md b/solution/2900-2999/2977.Minimum Cost to Convert String II/README_EN.md index f1d2d0da1d20c..09e91005bf5b6 100644 --- a/solution/2900-2999/2977.Minimum Cost to Convert String II/README_EN.md +++ b/solution/2900-2999/2977.Minimum Cost to Convert String II/README_EN.md @@ -124,6 +124,8 @@ The time complexity is $O(m^3 + n^2 + m \times n)$, and the space complexity is +#### Python3 + ```python class Node: __slots__ = ["children", "v"] @@ -195,6 +197,8 @@ class Solution: return -1 if ans >= inf else ans ``` +#### Java + ```java class Node { Node[] children = new Node[26]; @@ -284,6 +288,8 @@ class Solution { } ``` +#### C++ + ```cpp class Node { public: @@ -383,6 +389,8 @@ private: }; ``` +#### Go + ```go type Node struct { children [26]*Node @@ -475,6 +483,8 @@ func minimumCost(source string, target string, original []string, changed []stri } ``` +#### TypeScript + ```ts class Node { children: (Node | null)[] = Array(26).fill(null); diff --git a/solution/2900-2999/2978.Symmetric Coordinates/README.md b/solution/2900-2999/2978.Symmetric Coordinates/README.md index 54cd75843feb5..449a7c3f1acaf 100644 --- a/solution/2900-2999/2978.Symmetric Coordinates/README.md +++ b/solution/2900-2999/2978.Symmetric Coordinates/README.md @@ -80,6 +80,8 @@ Coordinates table: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2900-2999/2978.Symmetric Coordinates/README_EN.md b/solution/2900-2999/2978.Symmetric Coordinates/README_EN.md index 698c68f1c5c0c..c9532b9754ef8 100644 --- a/solution/2900-2999/2978.Symmetric Coordinates/README_EN.md +++ b/solution/2900-2999/2978.Symmetric Coordinates/README_EN.md @@ -79,6 +79,8 @@ We can use the window function `ROW_NUMBER()` to add an auto-incrementing sequen +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2900-2999/2979.Most Expensive Item That Can Not Be Bought/README.md b/solution/2900-2999/2979.Most Expensive Item That Can Not Be Bought/README.md index 00541b977a0a8..27643ea3e6b8b 100644 --- a/solution/2900-2999/2979.Most Expensive Item That Can Not Be Bought/README.md +++ b/solution/2900-2999/2979.Most Expensive Item That Can Not Be Bought/README.md @@ -66,12 +66,16 @@ tags: +#### Python3 + ```python class Solution: def mostExpensiveItem(self, primeOne: int, primeTwo: int) -> int: return primeOne * primeTwo - primeOne - primeTwo ``` +#### Java + ```java class Solution { public int mostExpensiveItem(int primeOne, int primeTwo) { @@ -80,6 +84,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -89,18 +95,24 @@ public: }; ``` +#### Go + ```go func mostExpensiveItem(primeOne int, primeTwo int) int { return primeOne*primeTwo - primeOne - primeTwo } ``` +#### TypeScript + ```ts function mostExpensiveItem(primeOne: number, primeTwo: number): number { return primeOne * primeTwo - primeOne - primeTwo; } ``` +#### Rust + ```rust impl Solution { pub fn most_expensive_item(prime_one: i32, prime_two: i32) -> i32 { diff --git a/solution/2900-2999/2979.Most Expensive Item That Can Not Be Bought/README_EN.md b/solution/2900-2999/2979.Most Expensive Item That Can Not Be Bought/README_EN.md index 98ae1b9c71589..4f0d54246f8b4 100644 --- a/solution/2900-2999/2979.Most Expensive Item That Can Not Be Bought/README_EN.md +++ b/solution/2900-2999/2979.Most Expensive Item That Can Not Be Bought/README_EN.md @@ -64,12 +64,16 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def mostExpensiveItem(self, primeOne: int, primeTwo: int) -> int: return primeOne * primeTwo - primeOne - primeTwo ``` +#### Java + ```java class Solution { public int mostExpensiveItem(int primeOne, int primeTwo) { @@ -78,6 +82,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -87,18 +93,24 @@ public: }; ``` +#### Go + ```go func mostExpensiveItem(primeOne int, primeTwo int) int { return primeOne*primeTwo - primeOne - primeTwo } ``` +#### TypeScript + ```ts function mostExpensiveItem(primeOne: number, primeTwo: number): number { return primeOne * primeTwo - primeOne - primeTwo; } ``` +#### Rust + ```rust impl Solution { pub fn most_expensive_item(prime_one: i32, prime_two: i32) -> i32 { diff --git a/solution/2900-2999/2980.Check if Bitwise OR Has Trailing Zeros/README.md b/solution/2900-2999/2980.Check if Bitwise OR Has Trailing Zeros/README.md index 3603d712f4054..3d68b6502b5b1 100644 --- a/solution/2900-2999/2980.Check if Bitwise OR Has Trailing Zeros/README.md +++ b/solution/2900-2999/2980.Check if Bitwise OR Has Trailing Zeros/README.md @@ -77,12 +77,16 @@ tags: +#### Python3 + ```python class Solution: def hasTrailingZeros(self, nums: List[int]) -> bool: return sum(x & 1 ^ 1 for x in nums) >= 2 ``` +#### Java + ```java class Solution { public boolean hasTrailingZeros(int[] nums) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -108,6 +114,8 @@ public: }; ``` +#### Go + ```go func hasTrailingZeros(nums []int) bool { cnt := 0 @@ -118,6 +126,8 @@ func hasTrailingZeros(nums []int) bool { } ``` +#### TypeScript + ```ts function hasTrailingZeros(nums: number[]): boolean { let cnt = 0; diff --git a/solution/2900-2999/2980.Check if Bitwise OR Has Trailing Zeros/README_EN.md b/solution/2900-2999/2980.Check if Bitwise OR Has Trailing Zeros/README_EN.md index c3b51e7d25659..3ab1f66994c43 100644 --- a/solution/2900-2999/2980.Check if Bitwise OR Has Trailing Zeros/README_EN.md +++ b/solution/2900-2999/2980.Check if Bitwise OR Has Trailing Zeros/README_EN.md @@ -75,12 +75,16 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def hasTrailingZeros(self, nums: List[int]) -> bool: return sum(x & 1 ^ 1 for x in nums) >= 2 ``` +#### Java + ```java class Solution { public boolean hasTrailingZeros(int[] nums) { @@ -93,6 +97,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func hasTrailingZeros(nums []int) bool { cnt := 0 @@ -116,6 +124,8 @@ func hasTrailingZeros(nums []int) bool { } ``` +#### TypeScript + ```ts function hasTrailingZeros(nums: number[]): boolean { let cnt = 0; diff --git a/solution/2900-2999/2981.Find Longest Special Substring That Occurs Thrice I/README.md b/solution/2900-2999/2981.Find Longest Special Substring That Occurs Thrice I/README.md index cb25ecc8649e0..1803db0911635 100644 --- a/solution/2900-2999/2981.Find Longest Special Substring That Occurs Thrice I/README.md +++ b/solution/2900-2999/2981.Find Longest Special Substring That Occurs Thrice I/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def maximumLength(self, s: str) -> int: @@ -114,6 +116,8 @@ class Solution: return -1 if l == 0 else l ``` +#### Java + ```java class Solution { private String s; @@ -153,6 +157,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go func maximumLength(s string) int { n := len(s) @@ -223,6 +231,8 @@ func maximumLength(s string) int { } ``` +#### TypeScript + ```ts function maximumLength(s: string): number { const n = s.length; diff --git a/solution/2900-2999/2981.Find Longest Special Substring That Occurs Thrice I/README_EN.md b/solution/2900-2999/2981.Find Longest Special Substring That Occurs Thrice I/README_EN.md index 7f81fb5c17120..ad15033df3ed7 100644 --- a/solution/2900-2999/2981.Find Longest Special Substring That Occurs Thrice I/README_EN.md +++ b/solution/2900-2999/2981.Find Longest Special Substring That Occurs Thrice I/README_EN.md @@ -87,6 +87,8 @@ The time complexity is $O((n + |\Sigma|) \times \log n)$, and the space complexi +#### Python3 + ```python class Solution: def maximumLength(self, s: str) -> int: @@ -112,6 +114,8 @@ class Solution: return -1 if l == 0 else l ``` +#### Java + ```java class Solution { private String s; @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go func maximumLength(s string) int { n := len(s) @@ -221,6 +229,8 @@ func maximumLength(s string) int { } ``` +#### TypeScript + ```ts function maximumLength(s: string): number { const n = s.length; diff --git a/solution/2900-2999/2982.Find Longest Special Substring That Occurs Thrice II/README.md b/solution/2900-2999/2982.Find Longest Special Substring That Occurs Thrice II/README.md index 6c5c6e6887da8..0e59aa8124844 100644 --- a/solution/2900-2999/2982.Find Longest Special Substring That Occurs Thrice II/README.md +++ b/solution/2900-2999/2982.Find Longest Special Substring That Occurs Thrice II/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def maximumLength(self, s: str) -> int: @@ -114,6 +116,8 @@ class Solution: return -1 if l == 0 else l ``` +#### Java + ```java class Solution { private String s; @@ -153,6 +157,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go func maximumLength(s string) int { n := len(s) @@ -223,6 +231,8 @@ func maximumLength(s string) int { } ``` +#### TypeScript + ```ts function maximumLength(s: string): number { const n = s.length; diff --git a/solution/2900-2999/2982.Find Longest Special Substring That Occurs Thrice II/README_EN.md b/solution/2900-2999/2982.Find Longest Special Substring That Occurs Thrice II/README_EN.md index 057622be5fb36..08f2f3c6c4851 100644 --- a/solution/2900-2999/2982.Find Longest Special Substring That Occurs Thrice II/README_EN.md +++ b/solution/2900-2999/2982.Find Longest Special Substring That Occurs Thrice II/README_EN.md @@ -87,6 +87,8 @@ The time complexity is $O((n + |\Sigma|) \times \log n)$, and the space complexi +#### Python3 + ```python class Solution: def maximumLength(self, s: str) -> int: @@ -112,6 +114,8 @@ class Solution: return -1 if l == 0 else l ``` +#### Java + ```java class Solution { private String s; @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go func maximumLength(s string) int { n := len(s) @@ -221,6 +229,8 @@ func maximumLength(s string) int { } ``` +#### TypeScript + ```ts function maximumLength(s: string): number { const n = s.length; diff --git a/solution/2900-2999/2983.Palindrome Rearrangement Queries/README.md b/solution/2900-2999/2983.Palindrome Rearrangement Queries/README.md index d5bdb11ca3ae7..8f60667e6bd8b 100644 --- a/solution/2900-2999/2983.Palindrome Rearrangement Queries/README.md +++ b/solution/2900-2999/2983.Palindrome Rearrangement Queries/README.md @@ -130,6 +130,8 @@ a0 = 1, b0 = 2, c0 = 4, d0 = 5. +#### Python3 + ```python class Solution: def canMakePalindromeQueries(self, s: str, queries: List[List[int]]) -> List[bool]: @@ -186,6 +188,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public boolean[] canMakePalindromeQueries(String s, int[][] queries) { @@ -253,6 +257,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -325,6 +331,8 @@ private: }; ``` +#### Go + ```go func canMakePalindromeQueries(s string, queries [][]int) (ans []bool) { n := len(s) @@ -407,6 +415,8 @@ func reverse(s string) string { } ``` +#### TypeScript + ```ts function canMakePalindromeQueries(s: string, queries: number[][]): boolean[] { const n: number = s.length; diff --git a/solution/2900-2999/2983.Palindrome Rearrangement Queries/README_EN.md b/solution/2900-2999/2983.Palindrome Rearrangement Queries/README_EN.md index baff36c4b4c36..00fcd88c4e65c 100644 --- a/solution/2900-2999/2983.Palindrome Rearrangement Queries/README_EN.md +++ b/solution/2900-2999/2983.Palindrome Rearrangement Queries/README_EN.md @@ -128,6 +128,8 @@ The time complexity is $O((n + q) \times |\Sigma|)$, and the space complexity is +#### Python3 + ```python class Solution: def canMakePalindromeQueries(self, s: str, queries: List[List[int]]) -> List[bool]: @@ -184,6 +186,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public boolean[] canMakePalindromeQueries(String s, int[][] queries) { @@ -251,6 +255,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -323,6 +329,8 @@ private: }; ``` +#### Go + ```go func canMakePalindromeQueries(s string, queries [][]int) (ans []bool) { n := len(s) @@ -405,6 +413,8 @@ func reverse(s string) string { } ``` +#### TypeScript + ```ts function canMakePalindromeQueries(s: string, queries: number[][]): boolean[] { const n: number = s.length; diff --git a/solution/2900-2999/2984.Find Peak Calling Hours for Each City/README.md b/solution/2900-2999/2984.Find Peak Calling Hours for Each City/README.md index 0f2bc8e5c4d96..589a90c48646c 100644 --- a/solution/2900-2999/2984.Find Peak Calling Hours for Each City/README.md +++ b/solution/2900-2999/2984.Find Peak Calling Hours for Each City/README.md @@ -79,6 +79,8 @@ Calls table: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2900-2999/2984.Find Peak Calling Hours for Each City/README_EN.md b/solution/2900-2999/2984.Find Peak Calling Hours for Each City/README_EN.md index 254a1ae8a096a..84c4aaf68a68e 100644 --- a/solution/2900-2999/2984.Find Peak Calling Hours for Each City/README_EN.md +++ b/solution/2900-2999/2984.Find Peak Calling Hours for Each City/README_EN.md @@ -78,6 +78,8 @@ Output table is ordered by peak_calling_hour and city in descending order. +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2900-2999/2985.Calculate Compressed Mean/README.md b/solution/2900-2999/2985.Calculate Compressed Mean/README.md index 3b6c1779cb97f..5c8f18f8bfc56 100644 --- a/solution/2900-2999/2985.Calculate Compressed Mean/README.md +++ b/solution/2900-2999/2985.Calculate Compressed Mean/README.md @@ -76,6 +76,8 @@ Orders table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2900-2999/2985.Calculate Compressed Mean/README_EN.md b/solution/2900-2999/2985.Calculate Compressed Mean/README_EN.md index 29a5525f44f8a..a75ae290d4134 100644 --- a/solution/2900-2999/2985.Calculate Compressed Mean/README_EN.md +++ b/solution/2900-2999/2985.Calculate Compressed Mean/README_EN.md @@ -74,6 +74,8 @@ We use the `SUM` function to calculate the total quantity of products and the to +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2900-2999/2986.Find Third Transaction/README.md b/solution/2900-2999/2986.Find Third Transaction/README.md index cc91c20c2bafd..93a801ca71091 100644 --- a/solution/2900-2999/2986.Find Third Transaction/README.md +++ b/solution/2900-2999/2986.Find Third Transaction/README.md @@ -80,6 +80,8 @@ Transactions table: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2900-2999/2986.Find Third Transaction/README_EN.md b/solution/2900-2999/2986.Find Third Transaction/README_EN.md index 58b8be0af2806..8301fb119059c 100644 --- a/solution/2900-2999/2986.Find Third Transaction/README_EN.md +++ b/solution/2900-2999/2986.Find Third Transaction/README_EN.md @@ -79,6 +79,8 @@ Output table is ordered by user_id in ascending order. +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2900-2999/2987.Find Expensive Cities/README.md b/solution/2900-2999/2987.Find Expensive Cities/README.md index 4964a1ee827c2..c761f7dba5c93 100644 --- a/solution/2900-2999/2987.Find Expensive Cities/README.md +++ b/solution/2900-2999/2987.Find Expensive Cities/README.md @@ -86,6 +86,8 @@ Listings table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT city diff --git a/solution/2900-2999/2987.Find Expensive Cities/README_EN.md b/solution/2900-2999/2987.Find Expensive Cities/README_EN.md index 020bafca34ab2..bcfcbb9ef01a2 100644 --- a/solution/2900-2999/2987.Find Expensive Cities/README_EN.md +++ b/solution/2900-2999/2987.Find Expensive Cities/README_EN.md @@ -86,6 +86,8 @@ We group the `Listings` table by `city`, then calculate the average house price +#### MySQL + ```sql # Write your MySQL query statement below SELECT city diff --git a/solution/2900-2999/2988.Manager of the Largest Department/README.md b/solution/2900-2999/2988.Manager of the Largest Department/README.md index fe684d03722f1..d19054129c822 100644 --- a/solution/2900-2999/2988.Manager of the Largest Department/README.md +++ b/solution/2900-2999/2988.Manager of the Largest Department/README.md @@ -84,6 +84,8 @@ Employees table: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2900-2999/2988.Manager of the Largest Department/README_EN.md b/solution/2900-2999/2988.Manager of the Largest Department/README_EN.md index ffc016e5701fb..d6cec47d5a848 100644 --- a/solution/2900-2999/2988.Manager of the Largest Department/README_EN.md +++ b/solution/2900-2999/2988.Manager of the Largest Department/README_EN.md @@ -83,6 +83,8 @@ We can first count the number of employees in each department, denoted as table +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2900-2999/2989.Class Performance/README.md b/solution/2900-2999/2989.Class Performance/README.md index 87fc27e41bf01..f54fe5ef161b9 100644 --- a/solution/2900-2999/2989.Class Performance/README.md +++ b/solution/2900-2999/2989.Class Performance/README.md @@ -83,6 +83,8 @@ student_id 321 拥有最高分为 230,而 student_id 896 拥有最低分为 11 +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2900-2999/2989.Class Performance/README_EN.md b/solution/2900-2999/2989.Class Performance/README_EN.md index 5127ce25fd6fa..600d0fc94ba45 100644 --- a/solution/2900-2999/2989.Class Performance/README_EN.md +++ b/solution/2900-2999/2989.Class Performance/README_EN.md @@ -82,6 +82,8 @@ We can use the `MAX` and `MIN` functions to get the maximum and minimum sums of +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2900-2999/2990.Loan Types/README.md b/solution/2900-2999/2990.Loan Types/README.md index 410ebf70d34d8..16e4f64d8658a 100644 --- a/solution/2900-2999/2990.Loan Types/README.md +++ b/solution/2900-2999/2990.Loan Types/README.md @@ -81,6 +81,8 @@ Loans table: +#### MySQL + ```sql # Write your MySQL query statement below SELECT user_id diff --git a/solution/2900-2999/2990.Loan Types/README_EN.md b/solution/2900-2999/2990.Loan Types/README_EN.md index 16a82acae64bc..8c0c73e5b76e8 100644 --- a/solution/2900-2999/2990.Loan Types/README_EN.md +++ b/solution/2900-2999/2990.Loan Types/README_EN.md @@ -80,6 +80,8 @@ We can group the `Loans` table by `user_id` to find users who have both `Refinan +#### MySQL + ```sql # Write your MySQL query statement below SELECT user_id diff --git a/solution/2900-2999/2991.Top Three Wineries/README.md b/solution/2900-2999/2991.Top Three Wineries/README.md index 0fd2b8430df74..6354e2f08d4bb 100644 --- a/solution/2900-2999/2991.Top Three Wineries/README.md +++ b/solution/2900-2999/2991.Top Three Wineries/README.md @@ -107,6 +107,8 @@ Wineries table: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2900-2999/2991.Top Three Wineries/README_EN.md b/solution/2900-2999/2991.Top Three Wineries/README_EN.md index e7cae0607b8f6..536806ca20553 100644 --- a/solution/2900-2999/2991.Top Three Wineries/README_EN.md +++ b/solution/2900-2999/2991.Top Three Wineries/README_EN.md @@ -106,6 +106,8 @@ Next, we just need to filter out the data where `rk = 1`, then join table `T` to +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2900-2999/2992.Number of Self-Divisible Permutations/README.md b/solution/2900-2999/2992.Number of Self-Divisible Permutations/README.md index 51b80953329de..4aad8e74116f9 100644 --- a/solution/2900-2999/2992.Number of Self-Divisible Permutations/README.md +++ b/solution/2900-2999/2992.Number of Self-Divisible Permutations/README.md @@ -96,6 +96,8 @@ nums = [2,1]:这是自整除的,因为 gcd(nums[1], 1) == 1 并且 gcd(nums[ +#### Python3 + ```python class Solution: def selfDivisiblePermutationCount(self, n: int) -> int: @@ -113,6 +115,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private int n; @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -170,6 +176,8 @@ public: }; ``` +#### Go + ```go func selfDivisiblePermutationCount(n int) int { f := make([]int, 1<<(n+1)) @@ -197,6 +205,8 @@ func selfDivisiblePermutationCount(n int) int { } ``` +#### TypeScript + ```ts function selfDivisiblePermutationCount(n: number): number { const f: number[] = Array(1 << (n + 1)).fill(-1); @@ -247,6 +257,8 @@ function bitCount(i: number): number { +#### Python3 + ```python class Solution: def selfDivisiblePermutationCount(self, n: int) -> int: @@ -260,6 +272,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int selfDivisiblePermutationCount(int n) { @@ -278,6 +292,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -298,6 +314,8 @@ public: }; ``` +#### Go + ```go func selfDivisiblePermutationCount(n int) int { f := make([]int, 1< +#### Python3 + ```python class Solution: def selfDivisiblePermutationCount(self, n: int) -> int: @@ -111,6 +113,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private int n; @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -168,6 +174,8 @@ public: }; ``` +#### Go + ```go func selfDivisiblePermutationCount(n int) int { f := make([]int, 1<<(n+1)) @@ -195,6 +203,8 @@ func selfDivisiblePermutationCount(n int) int { } ``` +#### TypeScript + ```ts function selfDivisiblePermutationCount(n: number): number { const f: number[] = Array(1 << (n + 1)).fill(-1); @@ -245,6 +255,8 @@ The time complexity is $O(n \times 2^n)$, and the space complexity is $O(2^n)$. +#### Python3 + ```python class Solution: def selfDivisiblePermutationCount(self, n: int) -> int: @@ -258,6 +270,8 @@ class Solution: return f[-1] ``` +#### Java + ```java class Solution { public int selfDivisiblePermutationCount(int n) { @@ -276,6 +290,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -296,6 +312,8 @@ public: }; ``` +#### Go + ```go func selfDivisiblePermutationCount(n int) int { f := make([]int, 1< +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2900-2999/2993.Friday Purchases I/README_EN.md b/solution/2900-2999/2993.Friday Purchases I/README_EN.md index ee118f59de423..de15cef1fbe73 100644 --- a/solution/2900-2999/2993.Friday Purchases I/README_EN.md +++ b/solution/2900-2999/2993.Friday Purchases I/README_EN.md @@ -87,6 +87,8 @@ First, we use the `DATE_FORMAT` function to format the date in the form of `YYYY +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/2900-2999/2994.Friday Purchases II/README.md b/solution/2900-2999/2994.Friday Purchases II/README.md index 8e96ba58a72af..fd57e105d86e0 100644 --- a/solution/2900-2999/2994.Friday Purchases II/README.md +++ b/solution/2900-2999/2994.Friday Purchases II/README.md @@ -85,6 +85,8 @@ Purchases table: +#### MySQL + ```sql WITH RECURSIVE T AS ( diff --git a/solution/2900-2999/2994.Friday Purchases II/README_EN.md b/solution/2900-2999/2994.Friday Purchases II/README_EN.md index ffebb6d3880fd..5f21892e99d5b 100644 --- a/solution/2900-2999/2994.Friday Purchases II/README_EN.md +++ b/solution/2900-2999/2994.Friday Purchases II/README_EN.md @@ -83,6 +83,8 @@ We can generate a table `T` that contains all dates in November 2023 using recur +#### MySQL + ```sql WITH RECURSIVE T AS ( diff --git a/solution/2900-2999/2995.Viewers Turned Streamers/README.md b/solution/2900-2999/2995.Viewers Turned Streamers/README.md index 5a4ca05c560f8..f9ecec97e57fc 100644 --- a/solution/2900-2999/2995.Viewers Turned Streamers/README.md +++ b/solution/2900-2999/2995.Viewers Turned Streamers/README.md @@ -83,6 +83,8 @@ Sessions table: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2900-2999/2995.Viewers Turned Streamers/README_EN.md b/solution/2900-2999/2995.Viewers Turned Streamers/README_EN.md index 43dc6c654f35a..a6d8bc8abcbf9 100644 --- a/solution/2900-2999/2995.Viewers Turned Streamers/README_EN.md +++ b/solution/2900-2999/2995.Viewers Turned Streamers/README_EN.md @@ -82,6 +82,8 @@ We can use the window function `RANK()` to rank each session by `user_id` dimens +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/2900-2999/2996.Smallest Missing Integer Greater Than Sequential Prefix Sum/README.md b/solution/2900-2999/2996.Smallest Missing Integer Greater Than Sequential Prefix Sum/README.md index ce91f42462802..f7d7862c750ed 100644 --- a/solution/2900-2999/2996.Smallest Missing Integer Greater Than Sequential Prefix Sum/README.md +++ b/solution/2900-2999/2996.Smallest Missing Integer Greater Than Sequential Prefix Sum/README.md @@ -67,6 +67,8 @@ tags: +#### Python3 + ```python class Solution: def missingInteger(self, nums: List[int]) -> int: @@ -80,6 +82,8 @@ class Solution: return x ``` +#### Java + ```java class Solution { public int missingInteger(int[] nums) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -121,6 +127,8 @@ public: }; ``` +#### Go + ```go func missingInteger(nums []int) int { s := nums[0] @@ -139,6 +147,8 @@ func missingInteger(nums []int) int { } ``` +#### TypeScript + ```ts function missingInteger(nums: number[]): number { let s = nums[0]; diff --git a/solution/2900-2999/2996.Smallest Missing Integer Greater Than Sequential Prefix Sum/README_EN.md b/solution/2900-2999/2996.Smallest Missing Integer Greater Than Sequential Prefix Sum/README_EN.md index da6846348791f..0a737ff3633aa 100644 --- a/solution/2900-2999/2996.Smallest Missing Integer Greater Than Sequential Prefix Sum/README_EN.md +++ b/solution/2900-2999/2996.Smallest Missing Integer Greater Than Sequential Prefix Sum/README_EN.md @@ -65,6 +65,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python class Solution: def missingInteger(self, nums: List[int]) -> int: @@ -78,6 +80,8 @@ class Solution: return x ``` +#### Java + ```java class Solution { public int missingInteger(int[] nums) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func missingInteger(nums []int) int { s := nums[0] @@ -137,6 +145,8 @@ func missingInteger(nums []int) int { } ``` +#### TypeScript + ```ts function missingInteger(nums: number[]): number { let s = nums[0]; diff --git a/solution/2900-2999/2997.Minimum Number of Operations to Make Array XOR Equal to K/README.md b/solution/2900-2999/2997.Minimum Number of Operations to Make Array XOR Equal to K/README.md index c67bebc045f45..2c39229117b45 100644 --- a/solution/2900-2999/2997.Minimum Number of Operations to Make Array XOR Equal to K/README.md +++ b/solution/2900-2999/2997.Minimum Number of Operations to Make Array XOR Equal to K/README.md @@ -77,12 +77,16 @@ tags: +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int], k: int) -> int: return reduce(xor, nums, k).bit_count() ``` +#### Java + ```java class Solution { public int minOperations(int[] nums, int k) { @@ -94,6 +98,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -106,6 +112,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int, k int) (ans int) { for _, x := range nums { @@ -115,6 +123,8 @@ func minOperations(nums []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function minOperations(nums: number[], k: number): number { for (const x of nums) { diff --git a/solution/2900-2999/2997.Minimum Number of Operations to Make Array XOR Equal to K/README_EN.md b/solution/2900-2999/2997.Minimum Number of Operations to Make Array XOR Equal to K/README_EN.md index 7aa49c764b4a4..66e188f24597a 100644 --- a/solution/2900-2999/2997.Minimum Number of Operations to Make Array XOR Equal to K/README_EN.md +++ b/solution/2900-2999/2997.Minimum Number of Operations to Make Array XOR Equal to K/README_EN.md @@ -75,12 +75,16 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int], k: int) -> int: return reduce(xor, nums, k).bit_count() ``` +#### Java + ```java class Solution { public int minOperations(int[] nums, int k) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -104,6 +110,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int, k int) (ans int) { for _, x := range nums { @@ -113,6 +121,8 @@ func minOperations(nums []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function minOperations(nums: number[], k: number): number { for (const x of nums) { diff --git a/solution/2900-2999/2998.Minimum Number of Operations to Make X and Y Equal/README.md b/solution/2900-2999/2998.Minimum Number of Operations to Make X and Y Equal/README.md index 6c79aa0b552a9..da34647ef0cff 100644 --- a/solution/2900-2999/2998.Minimum Number of Operations to Make X and Y Equal/README.md +++ b/solution/2900-2999/2998.Minimum Number of Operations to Make X and Y Equal/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def minimumOperationsToMakeEqual(self, x: int, y: int) -> int: @@ -109,6 +111,8 @@ class Solution: return dfs(x) ``` +#### Java + ```java class Solution { private Map f = new HashMap<>(); @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func minimumOperationsToMakeEqual(x int, y int) int { f := map[int]int{} @@ -183,6 +191,8 @@ func minimumOperationsToMakeEqual(x int, y int) int { } ``` +#### TypeScript + ```ts function minimumOperationsToMakeEqual(x: number, y: number): number { const f: Map = new Map(); diff --git a/solution/2900-2999/2998.Minimum Number of Operations to Make X and Y Equal/README_EN.md b/solution/2900-2999/2998.Minimum Number of Operations to Make X and Y Equal/README_EN.md index dcdc23537d44a..83b49f3124c6e 100644 --- a/solution/2900-2999/2998.Minimum Number of Operations to Make X and Y Equal/README_EN.md +++ b/solution/2900-2999/2998.Minimum Number of Operations to Make X and Y Equal/README_EN.md @@ -90,6 +90,8 @@ It can be shown that 5 is the minimum number of operations required to make 25 e +#### Python3 + ```python class Solution: def minimumOperationsToMakeEqual(self, x: int, y: int) -> int: @@ -107,6 +109,8 @@ class Solution: return dfs(x) ``` +#### Java + ```java class Solution { private Map f = new HashMap<>(); @@ -136,6 +140,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func minimumOperationsToMakeEqual(x int, y int) int { f := map[int]int{} @@ -181,6 +189,8 @@ func minimumOperationsToMakeEqual(x int, y int) int { } ``` +#### TypeScript + ```ts function minimumOperationsToMakeEqual(x: number, y: number): number { const f: Map = new Map(); diff --git a/solution/2900-2999/2999.Count the Number of Powerful Integers/README.md b/solution/2900-2999/2999.Count the Number of Powerful Integers/README.md index 22d9323a22de9..6537a1be36b84 100644 --- a/solution/2900-2999/2999.Count the Number of Powerful Integers/README.md +++ b/solution/2900-2999/2999.Count the Number of Powerful Integers/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfPowerfulInt(self, start: int, finish: int, limit: int, s: str) -> int: @@ -102,6 +104,8 @@ class Solution: return b - a ``` +#### Java + ```java class Solution { private String s; @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -183,6 +189,8 @@ public: }; ``` +#### Go + ```go func numberOfPowerfulInt(start, finish int64, limit int, s string) int64 { t := strconv.FormatInt(start-1, 10) @@ -234,6 +242,8 @@ func numberOfPowerfulInt(start, finish int64, limit int, s string) int64 { } ``` +#### TypeScript + ```ts function numberOfPowerfulInt(start: number, finish: number, limit: number, s: string): number { let t: string = (start - 1).toString(); diff --git a/solution/2900-2999/2999.Count the Number of Powerful Integers/README_EN.md b/solution/2900-2999/2999.Count the Number of Powerful Integers/README_EN.md index 963310b26f72f..2b975af6910dc 100644 --- a/solution/2900-2999/2999.Count the Number of Powerful Integers/README_EN.md +++ b/solution/2900-2999/2999.Count the Number of Powerful Integers/README_EN.md @@ -76,6 +76,8 @@ It can be shown that there are only 2 powerful integers in this range. +#### Python3 + ```python class Solution: def numberOfPowerfulInt(self, start: int, finish: int, limit: int, s: str) -> int: @@ -100,6 +102,8 @@ class Solution: return b - a ``` +#### Java + ```java class Solution { private String s; @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func numberOfPowerfulInt(start, finish int64, limit int, s string) int64 { t := strconv.FormatInt(start-1, 10) @@ -232,6 +240,8 @@ func numberOfPowerfulInt(start, finish int64, limit int, s string) int64 { } ``` +#### TypeScript + ```ts function numberOfPowerfulInt(start: number, finish: number, limit: number, s: string): number { let t: string = (start - 1).toString(); diff --git a/solution/3000-3099/3000.Maximum Area of Longest Diagonal Rectangle/README.md b/solution/3000-3099/3000.Maximum Area of Longest Diagonal Rectangle/README.md index 5520744ff11bf..b199aeb486540 100644 --- a/solution/3000-3099/3000.Maximum Area of Longest Diagonal Rectangle/README.md +++ b/solution/3000-3099/3000.Maximum Area of Longest Diagonal Rectangle/README.md @@ -65,6 +65,8 @@ tags: +#### Python3 + ```python class Solution: def areaOfMaxDiagonal(self, dimensions: List[List[int]]) -> int: @@ -79,6 +81,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int areaOfMaxDiagonal(int[][] dimensions) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func areaOfMaxDiagonal(dimensions [][]int) (ans int) { mx := 0 @@ -135,6 +143,8 @@ func areaOfMaxDiagonal(dimensions [][]int) (ans int) { } ``` +#### TypeScript + ```ts function areaOfMaxDiagonal(dimensions: number[][]): number { let [ans, mx] = [0, 0]; diff --git a/solution/3000-3099/3000.Maximum Area of Longest Diagonal Rectangle/README_EN.md b/solution/3000-3099/3000.Maximum Area of Longest Diagonal Rectangle/README_EN.md index 171cee195f07b..2b81e6b997e67 100644 --- a/solution/3000-3099/3000.Maximum Area of Longest Diagonal Rectangle/README_EN.md +++ b/solution/3000-3099/3000.Maximum Area of Longest Diagonal Rectangle/README_EN.md @@ -63,6 +63,8 @@ So, the rectangle at index 1 has a greater diagonal length therefore we return a +#### Python3 + ```python class Solution: def areaOfMaxDiagonal(self, dimensions: List[List[int]]) -> int: @@ -77,6 +79,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int areaOfMaxDiagonal(int[][] dimensions) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go func areaOfMaxDiagonal(dimensions [][]int) (ans int) { mx := 0 @@ -133,6 +141,8 @@ func areaOfMaxDiagonal(dimensions [][]int) (ans int) { } ``` +#### TypeScript + ```ts function areaOfMaxDiagonal(dimensions: number[][]): number { let [ans, mx] = [0, 0]; diff --git a/solution/3000-3099/3001.Minimum Moves to Capture The Queen/README.md b/solution/3000-3099/3001.Minimum Moves to Capture The Queen/README.md index 2f4d4aa22ee7e..fc82a9351286c 100644 --- a/solution/3000-3099/3001.Minimum Moves to Capture The Queen/README.md +++ b/solution/3000-3099/3001.Minimum Moves to Capture The Queen/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def minMovesToCaptureTheQueen( @@ -101,6 +103,8 @@ class Solution: return 1 if check(dirs1, a, b, c, d) or check(dirs2, c, d, a, b) else 2 ``` +#### Java + ```java class Solution { private final int[] dirs1 = {-1, 0, 1, 0, -1}; @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func minMovesToCaptureTheQueen(a int, b int, c int, d int, e int, f int) int { dirs := [2][5]int{{-1, 0, 1, 0, -1}, {-1, 1, 1, -1, -1}} @@ -181,6 +189,8 @@ func minMovesToCaptureTheQueen(a int, b int, c int, d int, e int, f int) int { } ``` +#### TypeScript + ```ts function minMovesToCaptureTheQueen( a: number, diff --git a/solution/3000-3099/3001.Minimum Moves to Capture The Queen/README_EN.md b/solution/3000-3099/3001.Minimum Moves to Capture The Queen/README_EN.md index 6af22fc04f861..6b041652c9a05 100644 --- a/solution/3000-3099/3001.Minimum Moves to Capture The Queen/README_EN.md +++ b/solution/3000-3099/3001.Minimum Moves to Capture The Queen/README_EN.md @@ -78,6 +78,8 @@ It is impossible to capture the black queen in less than two moves since it is n +#### Python3 + ```python class Solution: def minMovesToCaptureTheQueen( @@ -99,6 +101,8 @@ class Solution: return 1 if check(dirs1, a, b, c, d) or check(dirs2, c, d, a, b) else 2 ``` +#### Java + ```java class Solution { private final int[] dirs1 = {-1, 0, 1, 0, -1}; @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func minMovesToCaptureTheQueen(a int, b int, c int, d int, e int, f int) int { dirs := [2][5]int{{-1, 0, 1, 0, -1}, {-1, 1, 1, -1, -1}} @@ -179,6 +187,8 @@ func minMovesToCaptureTheQueen(a int, b int, c int, d int, e int, f int) int { } ``` +#### TypeScript + ```ts function minMovesToCaptureTheQueen( a: number, diff --git a/solution/3000-3099/3002.Maximum Size of a Set After Removals/README.md b/solution/3000-3099/3002.Maximum Size of a Set After Removals/README.md index f470ffbde117d..67f8f8db3d27a 100644 --- a/solution/3000-3099/3002.Maximum Size of a Set After Removals/README.md +++ b/solution/3000-3099/3002.Maximum Size of a Set After Removals/README.md @@ -75,6 +75,8 @@ tags: +#### Python3 + ```python class Solution: def maximumSetSize(self, nums1: List[int], nums2: List[int]) -> int: @@ -86,6 +88,8 @@ class Solution: return min(a + b + len(s1 & s2), n) ``` +#### Java + ```java class Solution { public int maximumSetSize(int[] nums1, int[] nums2) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -145,6 +151,8 @@ public: }; ``` +#### Go + ```go func maximumSetSize(nums1 []int, nums2 []int) int { s1 := map[int]bool{} @@ -175,6 +183,8 @@ func maximumSetSize(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function maximumSetSize(nums1: number[], nums2: number[]): number { const s1: Set = new Set(nums1); diff --git a/solution/3000-3099/3002.Maximum Size of a Set After Removals/README_EN.md b/solution/3000-3099/3002.Maximum Size of a Set After Removals/README_EN.md index 6ae52f2280e9e..861ee3649c482 100644 --- a/solution/3000-3099/3002.Maximum Size of a Set After Removals/README_EN.md +++ b/solution/3000-3099/3002.Maximum Size of a Set After Removals/README_EN.md @@ -74,6 +74,8 @@ It can be shown that 6 is the maximum possible size of the set s after the remov +#### Python3 + ```python class Solution: def maximumSetSize(self, nums1: List[int], nums2: List[int]) -> int: @@ -85,6 +87,8 @@ class Solution: return min(a + b + len(s1 & s2), n) ``` +#### Java + ```java class Solution { public int maximumSetSize(int[] nums1, int[] nums2) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func maximumSetSize(nums1 []int, nums2 []int) int { s1 := map[int]bool{} @@ -174,6 +182,8 @@ func maximumSetSize(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function maximumSetSize(nums1: number[], nums2: number[]): number { const s1: Set = new Set(nums1); diff --git a/solution/3000-3099/3003.Maximize the Number of Partitions After Operations/README.md b/solution/3000-3099/3003.Maximize the Number of Partitions After Operations/README.md index 1dc919a7f3a6f..7945e57b62d6b 100644 --- a/solution/3000-3099/3003.Maximize the Number of Partitions After Operations/README.md +++ b/solution/3000-3099/3003.Maximize the Number of Partitions After Operations/README.md @@ -104,6 +104,8 @@ s 变为 "xayz"。 +#### Python3 + ```python class Solution: def maxPartitionsAfterOperations(self, s: str, k: int) -> int: @@ -130,6 +132,8 @@ class Solution: return dfs(0, 0, 1) ``` +#### Java + ```java class Solution { private Map, Integer> f = new HashMap<>(); @@ -169,6 +173,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -203,6 +209,8 @@ public: }; ``` +#### Go + ```go func maxPartitionsAfterOperations(s string, k int) int { n := len(s) @@ -242,6 +250,8 @@ func maxPartitionsAfterOperations(s string, k int) int { } ``` +#### TypeScript + ```ts function maxPartitionsAfterOperations(s: string, k: number): number { const n = s.length; diff --git a/solution/3000-3099/3003.Maximize the Number of Partitions After Operations/README_EN.md b/solution/3000-3099/3003.Maximize the Number of Partitions After Operations/README_EN.md index fb150da5a318f..963eb2f4f2e59 100644 --- a/solution/3000-3099/3003.Maximize the Number of Partitions After Operations/README_EN.md +++ b/solution/3000-3099/3003.Maximize the Number of Partitions After Operations/README_EN.md @@ -103,6 +103,8 @@ It can be shown that it is not possible to obtain more than 4 partitions. +#### Python3 + ```python class Solution: def maxPartitionsAfterOperations(self, s: str, k: int) -> int: @@ -129,6 +131,8 @@ class Solution: return dfs(0, 0, 1) ``` +#### Java + ```java class Solution { private Map, Integer> f = new HashMap<>(); @@ -168,6 +172,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -202,6 +208,8 @@ public: }; ``` +#### Go + ```go func maxPartitionsAfterOperations(s string, k int) int { n := len(s) @@ -241,6 +249,8 @@ func maxPartitionsAfterOperations(s string, k int) int { } ``` +#### TypeScript + ```ts function maxPartitionsAfterOperations(s: string, k: number): number { const n = s.length; diff --git a/solution/3000-3099/3004.Maximum Subtree of the Same Color/README.md b/solution/3000-3099/3004.Maximum Subtree of the Same Color/README.md index 3f607d69c4115..89263081e0cb2 100644 --- a/solution/3000-3099/3004.Maximum Subtree of the Same Color/README.md +++ b/solution/3000-3099/3004.Maximum Subtree of the Same Color/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class Solution: def maximumSubtreeSize(self, edges: List[List[int]], colors: List[int]) -> int: @@ -120,6 +122,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go func maximumSubtreeSize(edges [][]int, colors []int) (ans int) { n := len(edges) + 1 @@ -224,6 +232,8 @@ func maximumSubtreeSize(edges [][]int, colors []int) (ans int) { } ``` +#### TypeScript + ```ts function maximumSubtreeSize(edges: number[][], colors: number[]): number { const n = edges.length + 1; diff --git a/solution/3000-3099/3004.Maximum Subtree of the Same Color/README_EN.md b/solution/3000-3099/3004.Maximum Subtree of the Same Color/README_EN.md index 1e26ec04fd3f1..99601dfef56c0 100644 --- a/solution/3000-3099/3004.Maximum Subtree of the Same Color/README_EN.md +++ b/solution/3000-3099/3004.Maximum Subtree of the Same Color/README_EN.md @@ -92,6 +92,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def maximumSubtreeSize(self, edges: List[List[int]], colors: List[int]) -> int: @@ -118,6 +120,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private List[] g; @@ -158,6 +162,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -191,6 +197,8 @@ public: }; ``` +#### Go + ```go func maximumSubtreeSize(edges [][]int, colors []int) (ans int) { n := len(edges) + 1 @@ -222,6 +230,8 @@ func maximumSubtreeSize(edges [][]int, colors []int) (ans int) { } ``` +#### TypeScript + ```ts function maximumSubtreeSize(edges: number[][], colors: number[]): number { const n = edges.length + 1; diff --git a/solution/3000-3099/3005.Count Elements With Maximum Frequency/README.md b/solution/3000-3099/3005.Count Elements With Maximum Frequency/README.md index a19c361da0efc..ff70843e27dd8 100644 --- a/solution/3000-3099/3005.Count Elements With Maximum Frequency/README.md +++ b/solution/3000-3099/3005.Count Elements With Maximum Frequency/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def maxFrequencyElements(self, nums: List[int]) -> int: @@ -79,6 +81,8 @@ class Solution: return sum(x for x in cnt.values() if x == mx) ``` +#### Java + ```java class Solution { public int maxFrequencyElements(int[] nums) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func maxFrequencyElements(nums []int) (ans int) { cnt := [101]int{} @@ -140,6 +148,8 @@ func maxFrequencyElements(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function maxFrequencyElements(nums: number[]): number { const cnt: number[] = Array(101).fill(0); diff --git a/solution/3000-3099/3005.Count Elements With Maximum Frequency/README_EN.md b/solution/3000-3099/3005.Count Elements With Maximum Frequency/README_EN.md index c38fa9e312573..b373ee56ae147 100644 --- a/solution/3000-3099/3005.Count Elements With Maximum Frequency/README_EN.md +++ b/solution/3000-3099/3005.Count Elements With Maximum Frequency/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def maxFrequencyElements(self, nums: List[int]) -> int: @@ -77,6 +79,8 @@ class Solution: return sum(x for x in cnt.values() if x == mx) ``` +#### Java + ```java class Solution { public int maxFrequencyElements(int[] nums) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func maxFrequencyElements(nums []int) (ans int) { cnt := [101]int{} @@ -138,6 +146,8 @@ func maxFrequencyElements(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function maxFrequencyElements(nums: number[]): number { const cnt: number[] = Array(101).fill(0); diff --git a/solution/3000-3099/3006.Find Beautiful Indices in the Given Array I/README.md b/solution/3000-3099/3006.Find Beautiful Indices in the Given Array I/README.md index 18caa46638ee1..2fbdcf530d233 100644 --- a/solution/3000-3099/3006.Find Beautiful Indices in the Given Array I/README.md +++ b/solution/3000-3099/3006.Find Beautiful Indices in the Given Array I/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def beautifulIndices(self, s: str, a: str, b: str, k: int) -> List[int]: @@ -136,6 +138,8 @@ class Solution: return res ``` +#### Java + ```java public class Solution { public void computeLPS(String pattern, int[] lps) { @@ -238,6 +242,8 @@ public class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -306,6 +312,8 @@ private: }; ``` +#### Go + ```go func beautifulIndices(s string, a string, b string, k int) []int { diff --git a/solution/3000-3099/3006.Find Beautiful Indices in the Given Array I/README_EN.md b/solution/3000-3099/3006.Find Beautiful Indices in the Given Array I/README_EN.md index 0597fff7a264c..14fbf3abb8954 100644 --- a/solution/3000-3099/3006.Find Beautiful Indices in the Given Array I/README_EN.md +++ b/solution/3000-3099/3006.Find Beautiful Indices in the Given Array I/README_EN.md @@ -82,6 +82,8 @@ Thus we return [0] as the result. +#### Python3 + ```python class Solution: def beautifulIndices(self, s: str, a: str, b: str, k: int) -> List[int]: @@ -134,6 +136,8 @@ class Solution: return res ``` +#### Java + ```java public class Solution { public void computeLPS(String pattern, int[] lps) { @@ -236,6 +240,8 @@ public class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -304,6 +310,8 @@ private: }; ``` +#### Go + ```go func beautifulIndices(s string, a string, b string, k int) []int { diff --git a/solution/3000-3099/3007.Maximum Number That Sum of the Prices Is Less Than or Equal to K/README.md b/solution/3000-3099/3007.Maximum Number That Sum of the Prices Is Less Than or Equal to K/README.md index 26576757ac84b..a0a2145ded851 100644 --- a/solution/3000-3099/3007.Maximum Number That Sum of the Prices Is Less Than or Equal to K/README.md +++ b/solution/3000-3099/3007.Maximum Number That Sum of the Prices Is Less Than or Equal to K/README.md @@ -249,6 +249,8 @@ tags: +#### Python3 + ```python class Solution: def findMaximumNumber(self, k: int, x: int) -> int: @@ -275,6 +277,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { private int x; @@ -318,6 +322,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -359,6 +365,8 @@ public: }; ``` +#### Go + ```go func findMaximumNumber(k int64, x int) int64 { var l, r int64 = 1, 1e17 diff --git a/solution/3000-3099/3007.Maximum Number That Sum of the Prices Is Less Than or Equal to K/README_EN.md b/solution/3000-3099/3007.Maximum Number That Sum of the Prices Is Less Than or Equal to K/README_EN.md index 82793d581b262..c9900a07c7ad6 100644 --- a/solution/3000-3099/3007.Maximum Number That Sum of the Prices Is Less Than or Equal to K/README_EN.md +++ b/solution/3000-3099/3007.Maximum Number That Sum of the Prices Is Less Than or Equal to K/README_EN.md @@ -253,6 +253,8 @@ tags: +#### Python3 + ```python class Solution: def findMaximumNumber(self, k: int, x: int) -> int: @@ -279,6 +281,8 @@ class Solution: return l ``` +#### Java + ```java class Solution { private int x; @@ -322,6 +326,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -363,6 +369,8 @@ public: }; ``` +#### Go + ```go func findMaximumNumber(k int64, x int) int64 { var l, r int64 = 1, 1e17 diff --git a/solution/3000-3099/3008.Find Beautiful Indices in the Given Array II/README.md b/solution/3000-3099/3008.Find Beautiful Indices in the Given Array II/README.md index 87b6954f1d0b6..2395b11990e40 100644 --- a/solution/3000-3099/3008.Find Beautiful Indices in the Given Array II/README.md +++ b/solution/3000-3099/3008.Find Beautiful Indices in the Given Array II/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def beautifulIndices(self, s: str, a: str, b: str, k: int) -> List[int]: @@ -134,6 +136,8 @@ class Solution: return res ``` +#### Java + ```java public class Solution { public void computeLPS(String pattern, int[] lps) { @@ -236,6 +240,8 @@ public class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -304,6 +310,8 @@ private: }; ``` +#### Go + ```go func beautifulIndices(s string, a string, b string, k int) []int { diff --git a/solution/3000-3099/3008.Find Beautiful Indices in the Given Array II/README_EN.md b/solution/3000-3099/3008.Find Beautiful Indices in the Given Array II/README_EN.md index 7975119aed7bd..a5c5f97514dd7 100644 --- a/solution/3000-3099/3008.Find Beautiful Indices in the Given Array II/README_EN.md +++ b/solution/3000-3099/3008.Find Beautiful Indices in the Given Array II/README_EN.md @@ -82,6 +82,8 @@ Thus we return [0] as the result. +#### Python3 + ```python class Solution: def beautifulIndices(self, s: str, a: str, b: str, k: int) -> List[int]: @@ -134,6 +136,8 @@ class Solution: return res ``` +#### Java + ```java public class Solution { public void computeLPS(String pattern, int[] lps) { @@ -236,6 +240,8 @@ public class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -304,6 +310,8 @@ private: }; ``` +#### Go + ```go func beautifulIndices(s string, a string, b string, k int) []int { diff --git a/solution/3000-3099/3009.Maximum Number of Intersections on the Chart/README.md b/solution/3000-3099/3009.Maximum Number of Intersections on the Chart/README.md index 9a6eb21ff79d1..56173b050e420 100644 --- a/solution/3000-3099/3009.Maximum Number of Intersections on the Chart/README.md +++ b/solution/3000-3099/3009.Maximum Number of Intersections on the Chart/README.md @@ -63,10 +63,14 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java class Solution { public int maxIntersectionCount(int[] y) { @@ -92,10 +96,14 @@ class Solution { } ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/3000-3099/3009.Maximum Number of Intersections on the Chart/README_EN.md b/solution/3000-3099/3009.Maximum Number of Intersections on the Chart/README_EN.md index e1a3a25cbc0b8..1842926a05eb1 100644 --- a/solution/3000-3099/3009.Maximum Number of Intersections on the Chart/README_EN.md +++ b/solution/3000-3099/3009.Maximum Number of Intersections on the Chart/README_EN.md @@ -61,10 +61,14 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java class Solution { public int maxIntersectionCount(int[] y) { @@ -90,10 +94,14 @@ class Solution { } ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/3000-3099/3010.Divide an Array Into Subarrays With Minimum Cost I/README.md b/solution/3000-3099/3010.Divide an Array Into Subarrays With Minimum Cost I/README.md index 405f2ea888d3d..d08e5fb7a0137 100644 --- a/solution/3000-3099/3010.Divide an Array Into Subarrays With Minimum Cost I/README.md +++ b/solution/3000-3099/3010.Divide an Array Into Subarrays With Minimum Cost I/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def minimumCost(self, nums: List[int]) -> int: @@ -94,6 +96,8 @@ class Solution: return a + b + c ``` +#### Java + ```java class Solution { public int minimumCost(int[] nums) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func minimumCost(nums []int) int { a, b, c := nums[0], 100, 100 @@ -143,6 +151,8 @@ func minimumCost(nums []int) int { } ``` +#### TypeScript + ```ts function minimumCost(nums: number[]): number { let [a, b, c] = [nums[0], 100, 100]; diff --git a/solution/3000-3099/3010.Divide an Array Into Subarrays With Minimum Cost I/README_EN.md b/solution/3000-3099/3010.Divide an Array Into Subarrays With Minimum Cost I/README_EN.md index 362611d767af6..30041a2d124e5 100644 --- a/solution/3000-3099/3010.Divide an Array Into Subarrays With Minimum Cost I/README_EN.md +++ b/solution/3000-3099/3010.Divide an Array Into Subarrays With Minimum Cost I/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def minimumCost(self, nums: List[int]) -> int: @@ -92,6 +94,8 @@ class Solution: return a + b + c ``` +#### Java + ```java class Solution { public int minimumCost(int[] nums) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func minimumCost(nums []int) int { a, b, c := nums[0], 100, 100 @@ -141,6 +149,8 @@ func minimumCost(nums []int) int { } ``` +#### TypeScript + ```ts function minimumCost(nums: number[]): number { let [a, b, c] = [nums[0], 100, 100]; diff --git a/solution/3000-3099/3011.Find if Array Can Be Sorted/README.md b/solution/3000-3099/3011.Find if Array Can Be Sorted/README.md index 3affb2e45f09f..bb59981a6f7bb 100644 --- a/solution/3000-3099/3011.Find if Array Can Be Sorted/README.md +++ b/solution/3000-3099/3011.Find if Array Can Be Sorted/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def canSortArray(self, nums: List[int]) -> bool: @@ -102,6 +104,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean canSortArray(int[] nums) { @@ -127,6 +131,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -153,6 +159,8 @@ public: }; ``` +#### Go + ```go func canSortArray(nums []int) bool { preMx := -300 @@ -176,6 +184,8 @@ func canSortArray(nums []int) bool { } ``` +#### TypeScript + ```ts function canSortArray(nums: number[]): boolean { let preMx = -300; diff --git a/solution/3000-3099/3011.Find if Array Can Be Sorted/README_EN.md b/solution/3000-3099/3011.Find if Array Can Be Sorted/README_EN.md index c44899362adec..517f9a2b7df35 100644 --- a/solution/3000-3099/3011.Find if Array Can Be Sorted/README_EN.md +++ b/solution/3000-3099/3011.Find if Array Can Be Sorted/README_EN.md @@ -80,6 +80,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def canSortArray(self, nums: List[int]) -> bool: @@ -100,6 +102,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean canSortArray(int[] nums) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func canSortArray(nums []int) bool { preMx := -300 @@ -174,6 +182,8 @@ func canSortArray(nums []int) bool { } ``` +#### TypeScript + ```ts function canSortArray(nums: number[]): boolean { let preMx = -300; diff --git a/solution/3000-3099/3012.Minimize Length of Array Using Operations/README.md b/solution/3000-3099/3012.Minimize Length of Array Using Operations/README.md index e3b2da23d66fb..664bc413ada04 100644 --- a/solution/3000-3099/3012.Minimize Length of Array Using Operations/README.md +++ b/solution/3000-3099/3012.Minimize Length of Array Using Operations/README.md @@ -105,6 +105,8 @@ nums 的长度无法进一步减小,所以答案为 1 。 +#### Python3 + ```python class Solution: def minimumArrayLength(self, nums: List[int]) -> int: @@ -114,6 +116,8 @@ class Solution: return (nums.count(mi) + 1) // 2 ``` +#### Java + ```java class Solution { public int minimumArrayLength(int[] nums) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func minimumArrayLength(nums []int) int { mi := slices.Min(nums) @@ -165,6 +173,8 @@ func minimumArrayLength(nums []int) int { } ``` +#### TypeScript + ```ts function minimumArrayLength(nums: number[]): number { const mi = Math.min(...nums); diff --git a/solution/3000-3099/3012.Minimize Length of Array Using Operations/README_EN.md b/solution/3000-3099/3012.Minimize Length of Array Using Operations/README_EN.md index 614f098cac452..ff29c61d4cb5d 100644 --- a/solution/3000-3099/3012.Minimize Length of Array Using Operations/README_EN.md +++ b/solution/3000-3099/3012.Minimize Length of Array Using Operations/README_EN.md @@ -103,6 +103,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def minimumArrayLength(self, nums: List[int]) -> int: @@ -112,6 +114,8 @@ class Solution: return (nums.count(mi) + 1) // 2 ``` +#### Java + ```java class Solution { public int minimumArrayLength(int[] nums) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func minimumArrayLength(nums []int) int { mi := slices.Min(nums) @@ -163,6 +171,8 @@ func minimumArrayLength(nums []int) int { } ``` +#### TypeScript + ```ts function minimumArrayLength(nums: number[]): number { const mi = Math.min(...nums); diff --git a/solution/3000-3099/3013.Divide an Array Into Subarrays With Minimum Cost II/README.md b/solution/3000-3099/3013.Divide an Array Into Subarrays With Minimum Cost II/README.md index 76c33f2390e8d..883b7c488f425 100644 --- a/solution/3000-3099/3013.Divide an Array Into Subarrays With Minimum Cost II/README.md +++ b/solution/3000-3099/3013.Divide an Array Into Subarrays With Minimum Cost II/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python from sortedcontainers import SortedList @@ -121,6 +123,8 @@ class Solution: return ans + y ``` +#### Java + ```java class Solution { public long minimumCost(int[] nums, int k, int dist) { @@ -159,6 +163,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -211,6 +217,8 @@ public: }; ``` +#### Go + ```go func minimumCost(nums []int, k int, dist int) int64 { res := nums[0] + slices.Min(windowTopKSum(nums[1:], dist+1, k-1, true)) diff --git a/solution/3000-3099/3013.Divide an Array Into Subarrays With Minimum Cost II/README_EN.md b/solution/3000-3099/3013.Divide an Array Into Subarrays With Minimum Cost II/README_EN.md index fe05e72586c2c..9985e78b47231 100644 --- a/solution/3000-3099/3013.Divide an Array Into Subarrays With Minimum Cost II/README_EN.md +++ b/solution/3000-3099/3013.Divide an Array Into Subarrays With Minimum Cost II/README_EN.md @@ -79,6 +79,8 @@ It can be shown that there is no possible way to divide nums into 3 subarrays at +#### Python3 + ```python from sortedcontainers import SortedList @@ -119,6 +121,8 @@ class Solution: return ans + y ``` +#### Java + ```java class Solution { public long minimumCost(int[] nums, int k, int dist) { @@ -157,6 +161,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -209,6 +215,8 @@ public: }; ``` +#### Go + ```go func minimumCost(nums []int, k int, dist int) int64 { res := nums[0] + slices.Min(windowTopKSum(nums[1:], dist+1, k-1, true)) diff --git a/solution/3000-3099/3014.Minimum Number of Pushes to Type Word I/README.md b/solution/3000-3099/3014.Minimum Number of Pushes to Type Word I/README.md index f0e0eca11ccfa..0418eaa139b6e 100644 --- a/solution/3000-3099/3014.Minimum Number of Pushes to Type Word I/README.md +++ b/solution/3000-3099/3014.Minimum Number of Pushes to Type Word I/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def minimumPushes(self, word: str) -> int: @@ -103,6 +105,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumPushes(String word) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -134,6 +140,8 @@ public: }; ``` +#### Go + ```go func minimumPushes(word string) (ans int) { n := len(word) @@ -147,6 +155,8 @@ func minimumPushes(word string) (ans int) { } ``` +#### TypeScript + ```ts function minimumPushes(word: string): number { const n = word.length; diff --git a/solution/3000-3099/3014.Minimum Number of Pushes to Type Word I/README_EN.md b/solution/3000-3099/3014.Minimum Number of Pushes to Type Word I/README_EN.md index 4b6404df6e59d..e2f7865b8a10c 100644 --- a/solution/3000-3099/3014.Minimum Number of Pushes to Type Word I/README_EN.md +++ b/solution/3000-3099/3014.Minimum Number of Pushes to Type Word I/README_EN.md @@ -89,6 +89,8 @@ The time complexity is $O(n / 8)$, where $n$ is the length of the string $word$. +#### Python3 + ```python class Solution: def minimumPushes(self, word: str) -> int: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumPushes(String word) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -132,6 +138,8 @@ public: }; ``` +#### Go + ```go func minimumPushes(word string) (ans int) { n := len(word) @@ -145,6 +153,8 @@ func minimumPushes(word string) (ans int) { } ``` +#### TypeScript + ```ts function minimumPushes(word: string): number { const n = word.length; diff --git a/solution/3000-3099/3015.Count the Number of Houses at a Certain Distance I/README.md b/solution/3000-3099/3015.Count the Number of Houses at a Certain Distance I/README.md index 7bcfc9f6d5f72..f8bef317691f9 100644 --- a/solution/3000-3099/3015.Count the Number of Houses at a Certain Distance I/README.md +++ b/solution/3000-3099/3015.Count the Number of Houses at a Certain Distance I/README.md @@ -93,6 +93,8 @@ tags: +#### Python3 + ```python class Solution: def countOfPairs(self, n: int, x: int, y: int) -> List[int]: @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] countOfPairs(int n, int x, int y) { @@ -126,6 +130,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func countOfPairs(n int, x int, y int) []int { ans := make([]int, n) @@ -169,6 +177,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function countOfPairs(n: number, x: number, y: number): number[] { const ans: number[] = Array(n).fill(0); diff --git a/solution/3000-3099/3015.Count the Number of Houses at a Certain Distance I/README_EN.md b/solution/3000-3099/3015.Count the Number of Houses at a Certain Distance I/README_EN.md index caba497044e15..82c5c409c7c32 100644 --- a/solution/3000-3099/3015.Count the Number of Houses at a Certain Distance I/README_EN.md +++ b/solution/3000-3099/3015.Count the Number of Houses at a Certain Distance I/README_EN.md @@ -91,6 +91,8 @@ The time complexity is $O(n^2)$, where $n$ is the $n$ given in the problem. Igno +#### Python3 + ```python class Solution: def countOfPairs(self, n: int, x: int, y: int) -> List[int]: @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[] countOfPairs(int n, int x, int y) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func countOfPairs(n int, x int, y int) []int { ans := make([]int, n) @@ -167,6 +175,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function countOfPairs(n: number, x: number, y: number): number[] { const ans: number[] = Array(n).fill(0); diff --git a/solution/3000-3099/3016.Minimum Number of Pushes to Type Word II/README.md b/solution/3000-3099/3016.Minimum Number of Pushes to Type Word II/README.md index 11237adbb3fae..7e0a1dab7f5b4 100644 --- a/solution/3000-3099/3016.Minimum Number of Pushes to Type Word II/README.md +++ b/solution/3000-3099/3016.Minimum Number of Pushes to Type Word II/README.md @@ -105,6 +105,8 @@ tags: +#### Python3 + ```python class Solution: def minimumPushes(self, word: str) -> int: @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumPushes(String word) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func minimumPushes(word string) (ans int) { cnt := make([]int, 26) @@ -164,6 +172,8 @@ func minimumPushes(word string) (ans int) { } ``` +#### TypeScript + ```ts function minimumPushes(word: string): number { const cnt: number[] = Array(26).fill(0); diff --git a/solution/3000-3099/3016.Minimum Number of Pushes to Type Word II/README_EN.md b/solution/3000-3099/3016.Minimum Number of Pushes to Type Word II/README_EN.md index 92bb5527e4f44..ed9a33d2f0aae 100644 --- a/solution/3000-3099/3016.Minimum Number of Pushes to Type Word II/README_EN.md +++ b/solution/3000-3099/3016.Minimum Number of Pushes to Type Word II/README_EN.md @@ -103,6 +103,8 @@ The time complexity is $O(n + |\Sigma| \times \log |\Sigma|)$, and the space com +#### Python3 + ```python class Solution: def minimumPushes(self, word: str) -> int: @@ -113,6 +115,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumPushes(String word) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go func minimumPushes(word string) (ans int) { cnt := make([]int, 26) @@ -162,6 +170,8 @@ func minimumPushes(word string) (ans int) { } ``` +#### TypeScript + ```ts function minimumPushes(word: string): number { const cnt: number[] = Array(26).fill(0); diff --git a/solution/3000-3099/3017.Count the Number of Houses at a Certain Distance II/README.md b/solution/3000-3099/3017.Count the Number of Houses at a Certain Distance II/README.md index e86c57c8fd54d..3e6da8cc45135 100644 --- a/solution/3000-3099/3017.Count the Number of Houses at a Certain Distance II/README.md +++ b/solution/3000-3099/3017.Count the Number of Houses at a Certain Distance II/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def countOfPairs(self, n: int, x: int, y: int) -> List[int]: @@ -133,6 +135,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public long[] countOfPairs(int n, int x, int y) { @@ -162,6 +166,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go func countOfPairs(n int, x int, y int) []int64 { if x > y { diff --git a/solution/3000-3099/3017.Count the Number of Houses at a Certain Distance II/README_EN.md b/solution/3000-3099/3017.Count the Number of Houses at a Certain Distance II/README_EN.md index 8899c4e8de885..76a6bc27dd038 100644 --- a/solution/3000-3099/3017.Count the Number of Houses at a Certain Distance II/README_EN.md +++ b/solution/3000-3099/3017.Count the Number of Houses at a Certain Distance II/README_EN.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def countOfPairs(self, n: int, x: int, y: int) -> List[int]: @@ -131,6 +133,8 @@ class Solution: return res ``` +#### Java + ```java class Solution { public long[] countOfPairs(int n, int x, int y) { @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go func countOfPairs(n int, x int, y int) []int64 { if x > y { diff --git a/solution/3000-3099/3018.Maximum Number of Removal Queries That Can Be Processed I/README.md b/solution/3000-3099/3018.Maximum Number of Removal Queries That Can Be Processed I/README.md index 5b8fbfb4acb17..f052a78651502 100644 --- a/solution/3000-3099/3018.Maximum Number of Removal Queries That Can Be Processed I/README.md +++ b/solution/3000-3099/3018.Maximum Number of Removal Queries That Can Be Processed I/README.md @@ -110,6 +110,8 @@ tags: +#### Python3 + ```python class Solution: def maximumProcessableQueries(self, nums: List[int], queries: List[int]) -> int: @@ -131,6 +133,8 @@ class Solution: return max(f[i][i] + (nums[i] >= queries[f[i][i]]) for i in range(n)) ``` +#### Java + ```java class Solution { public int maximumProcessableQueries(int[] nums, int[] queries) { @@ -161,6 +165,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -191,6 +197,8 @@ public: }; ``` +#### Go + ```go func maximumProcessableQueries(nums []int, queries []int) (ans int) { n := len(nums) @@ -231,6 +239,8 @@ func maximumProcessableQueries(nums []int, queries []int) (ans int) { } ``` +#### TypeScript + ```ts function maximumProcessableQueries(nums: number[], queries: number[]): number { const n = nums.length; diff --git a/solution/3000-3099/3018.Maximum Number of Removal Queries That Can Be Processed I/README_EN.md b/solution/3000-3099/3018.Maximum Number of Removal Queries That Can Be Processed I/README_EN.md index ddd1a6eacf214..31ee5f85dfc83 100644 --- a/solution/3000-3099/3018.Maximum Number of Removal Queries That Can Be Processed I/README_EN.md +++ b/solution/3000-3099/3018.Maximum Number of Removal Queries That Can Be Processed I/README_EN.md @@ -108,6 +108,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$. Here, $n$ +#### Python3 + ```python class Solution: def maximumProcessableQueries(self, nums: List[int], queries: List[int]) -> int: @@ -129,6 +131,8 @@ class Solution: return max(f[i][i] + (nums[i] >= queries[f[i][i]]) for i in range(n)) ``` +#### Java + ```java class Solution { public int maximumProcessableQueries(int[] nums, int[] queries) { @@ -159,6 +163,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -189,6 +195,8 @@ public: }; ``` +#### Go + ```go func maximumProcessableQueries(nums []int, queries []int) (ans int) { n := len(nums) @@ -229,6 +237,8 @@ func maximumProcessableQueries(nums []int, queries []int) (ans int) { } ``` +#### TypeScript + ```ts function maximumProcessableQueries(nums: number[], queries: number[]): number { const n = nums.length; diff --git a/solution/3000-3099/3019.Number of Changing Keys/README.md b/solution/3000-3099/3019.Number of Changing Keys/README.md index 3bcbf037e21f9..6398be4e58991 100644 --- a/solution/3000-3099/3019.Number of Changing Keys/README.md +++ b/solution/3000-3099/3019.Number of Changing Keys/README.md @@ -70,12 +70,16 @@ tags: +#### Python3 + ```python class Solution: def countKeyChanges(self, s: str) -> int: return sum(a.lower() != b.lower() for a, b in pairwise(s)) ``` +#### Java + ```java class Solution { public int countKeyChanges(String s) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -104,6 +110,8 @@ public: }; ``` +#### Go + ```go func countKeyChanges(s string) (ans int) { s = strings.ToLower(s) @@ -116,6 +124,8 @@ func countKeyChanges(s string) (ans int) { } ``` +#### TypeScript + ```ts function countKeyChanges(s: string): number { s = s.toLowerCase(); diff --git a/solution/3000-3099/3019.Number of Changing Keys/README_EN.md b/solution/3000-3099/3019.Number of Changing Keys/README_EN.md index 38bc5114a10f6..ca7144d2a990f 100644 --- a/solution/3000-3099/3019.Number of Changing Keys/README_EN.md +++ b/solution/3000-3099/3019.Number of Changing Keys/README_EN.md @@ -69,12 +69,16 @@ The time complexity is $O(n)$, where $n$ is the length of the string $s$. The sp +#### Python3 + ```python class Solution: def countKeyChanges(self, s: str) -> int: return sum(a.lower() != b.lower() for a, b in pairwise(s)) ``` +#### Java + ```java class Solution { public int countKeyChanges(String s) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -103,6 +109,8 @@ public: }; ``` +#### Go + ```go func countKeyChanges(s string) (ans int) { s = strings.ToLower(s) @@ -115,6 +123,8 @@ func countKeyChanges(s string) (ans int) { } ``` +#### TypeScript + ```ts function countKeyChanges(s: string): number { s = s.toLowerCase(); diff --git a/solution/3000-3099/3020.Find the Maximum Number of Elements in Subset/README.md b/solution/3000-3099/3020.Find the Maximum Number of Elements in Subset/README.md index cd414b33cd40f..c801f8390d059 100644 --- a/solution/3000-3099/3020.Find the Maximum Number of Elements in Subset/README.md +++ b/solution/3000-3099/3020.Find the Maximum Number of Elements in Subset/README.md @@ -73,6 +73,8 @@ tags: +#### Python3 + ```python class Solution: def maximumLength(self, nums: List[int]) -> int: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumLength(int[] nums) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func maximumLength(nums []int) (ans int) { cnt := map[int]int{} @@ -162,6 +170,8 @@ func maximumLength(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function maximumLength(nums: number[]): number { const cnt: Map = new Map(); diff --git a/solution/3000-3099/3020.Find the Maximum Number of Elements in Subset/README_EN.md b/solution/3000-3099/3020.Find the Maximum Number of Elements in Subset/README_EN.md index 03846df212255..664e9a347794d 100644 --- a/solution/3000-3099/3020.Find the Maximum Number of Elements in Subset/README_EN.md +++ b/solution/3000-3099/3020.Find the Maximum Number of Elements in Subset/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(n \times \log \log M)$, and the space complexity is $O +#### Python3 + ```python class Solution: def maximumLength(self, nums: List[int]) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumLength(int[] nums) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func maximumLength(nums []int) (ans int) { cnt := map[int]int{} @@ -160,6 +168,8 @@ func maximumLength(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function maximumLength(nums: number[]): number { const cnt: Map = new Map(); diff --git a/solution/3000-3099/3021.Alice and Bob Playing Flower Game/README.md b/solution/3000-3099/3021.Alice and Bob Playing Flower Game/README.md index c1f2e58722eaf..b88e8d06009ff 100644 --- a/solution/3000-3099/3021.Alice and Bob Playing Flower Game/README.md +++ b/solution/3000-3099/3021.Alice and Bob Playing Flower Game/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def flowerGame(self, n: int, m: int) -> int: @@ -100,6 +102,8 @@ class Solution: return a1 * b2 + a2 * b1 ``` +#### Java + ```java class Solution { public long flowerGame(int n, int m) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func flowerGame(n int, m int) int64 { a1, b1 := (n+1)/2, (m+1)/2 @@ -133,6 +141,8 @@ func flowerGame(n int, m int) int64 { } ``` +#### TypeScript + ```ts function flowerGame(n: number, m: number): number { const [a1, b1] = [(n + 1) >> 1, (m + 1) >> 1]; @@ -165,12 +175,16 @@ function flowerGame(n: number, m: number): number { +#### Python3 + ```python class Solution: def flowerGame(self, n: int, m: int) -> int: return (n * m) // 2 ``` +#### Java + ```java class Solution { public long flowerGame(int n, int m) { @@ -179,6 +193,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,12 +204,16 @@ public: }; ``` +#### Go + ```go func flowerGame(n int, m int) int64 { return int64((n * m) / 2) } ``` +#### TypeScript + ```ts function flowerGame(n: number, m: number): number { return Number(((BigInt(n) * BigInt(m)) / 2n) | 0n); diff --git a/solution/3000-3099/3021.Alice and Bob Playing Flower Game/README_EN.md b/solution/3000-3099/3021.Alice and Bob Playing Flower Game/README_EN.md index 114329957cc60..739f74052ae2b 100644 --- a/solution/3000-3099/3021.Alice and Bob Playing Flower Game/README_EN.md +++ b/solution/3000-3099/3021.Alice and Bob Playing Flower Game/README_EN.md @@ -88,6 +88,8 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def flowerGame(self, n: int, m: int) -> int: @@ -98,6 +100,8 @@ class Solution: return a1 * b2 + a2 * b1 ``` +#### Java + ```java class Solution { public long flowerGame(int n, int m) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func flowerGame(n int, m int) int64 { a1, b1 := (n+1)/2, (m+1)/2 @@ -131,6 +139,8 @@ func flowerGame(n int, m int) int64 { } ``` +#### TypeScript + ```ts function flowerGame(n: number, m: number): number { const [a1, b1] = [(n + 1) >> 1, (m + 1) >> 1]; @@ -163,12 +173,16 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def flowerGame(self, n: int, m: int) -> int: return (n * m) // 2 ``` +#### Java + ```java class Solution { public long flowerGame(int n, int m) { @@ -177,6 +191,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -186,12 +202,16 @@ public: }; ``` +#### Go + ```go func flowerGame(n int, m int) int64 { return int64((n * m) / 2) } ``` +#### TypeScript + ```ts function flowerGame(n: number, m: number): number { return Number(((BigInt(n) * BigInt(m)) / 2n) | 0n); diff --git a/solution/3000-3099/3022.Minimize OR of Remaining Elements Using Operations/README.md b/solution/3000-3099/3022.Minimize OR of Remaining Elements Using Operations/README.md index 3d66ba8df8c8f..c752b430a8500 100644 --- a/solution/3000-3099/3022.Minimize OR of Remaining Elements Using Operations/README.md +++ b/solution/3000-3099/3022.Minimize OR of Remaining Elements Using Operations/README.md @@ -82,6 +82,8 @@ tags: +#### Python3 + ```python class Solution: def minOrAfterOperations(self, nums: List[int], k: int) -> int: @@ -105,6 +107,8 @@ class Solution: return rans ``` +#### Java + ```java class Solution { public int minOrAfterOperations(int[] nums, int k) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func minOrAfterOperations(nums []int, k int) int { ans := 0 diff --git a/solution/3000-3099/3022.Minimize OR of Remaining Elements Using Operations/README_EN.md b/solution/3000-3099/3022.Minimize OR of Remaining Elements Using Operations/README_EN.md index 57b0fd5a46c5c..8be3cb7c39df2 100644 --- a/solution/3000-3099/3022.Minimize OR of Remaining Elements Using Operations/README_EN.md +++ b/solution/3000-3099/3022.Minimize OR of Remaining Elements Using Operations/README_EN.md @@ -80,6 +80,8 @@ It can be shown that 15 is the minimum possible value of the bitwise OR of the r +#### Python3 + ```python class Solution: def minOrAfterOperations(self, nums: List[int], k: int) -> int: @@ -103,6 +105,8 @@ class Solution: return rans ``` +#### Java + ```java class Solution { public int minOrAfterOperations(int[] nums, int k) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func minOrAfterOperations(nums []int, k int) int { ans := 0 diff --git a/solution/3000-3099/3023.Find Pattern in Infinite Stream I/README.md b/solution/3000-3099/3023.Find Pattern in Infinite Stream I/README.md index b8ef7d7920103..b3b2a89ef1bfa 100644 --- a/solution/3000-3099/3023.Find Pattern in Infinite Stream I/README.md +++ b/solution/3000-3099/3023.Find Pattern in Infinite Stream I/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python # Definition for an infinite stream. # class InfiniteStream: @@ -113,6 +115,8 @@ class Solution: return i - m ``` +#### Java + ```java /** * Definition for an infinite stream. @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for an infinite stream. @@ -189,6 +195,8 @@ public: }; ``` +#### Go + ```go /** * Definition for an infinite stream. diff --git a/solution/3000-3099/3023.Find Pattern in Infinite Stream I/README_EN.md b/solution/3000-3099/3023.Find Pattern in Infinite Stream I/README_EN.md index b32c6ba1312ad..102f62dd713e9 100644 --- a/solution/3000-3099/3023.Find Pattern in Infinite Stream I/README_EN.md +++ b/solution/3000-3099/3023.Find Pattern in Infinite Stream I/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(n + m)$, where $n$ and $m$ are the number of elements +#### Python3 + ```python # Definition for an infinite stream. # class InfiniteStream: @@ -111,6 +113,8 @@ class Solution: return i - m ``` +#### Java + ```java /** * Definition for an infinite stream. @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for an infinite stream. @@ -187,6 +193,8 @@ public: }; ``` +#### Go + ```go /** * Definition for an infinite stream. diff --git a/solution/3000-3099/3024.Type of Triangle/README.md b/solution/3000-3099/3024.Type of Triangle/README.md index 3bd877f83a967..b6bb82e2e9cd0 100644 --- a/solution/3000-3099/3024.Type of Triangle/README.md +++ b/solution/3000-3099/3024.Type of Triangle/README.md @@ -78,6 +78,8 @@ nums[1] + nums[2] = 4 + 5 = 9 ,大于 nums[0] = 3 。 +#### Python3 + ```python class Solution: def triangleType(self, nums: List[int]) -> str: @@ -91,6 +93,8 @@ class Solution: return "scalene" ``` +#### Java + ```java class Solution { public String triangleType(int[] nums) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func triangleType(nums []int) string { sort.Ints(nums) @@ -144,6 +152,8 @@ func triangleType(nums []int) string { } ``` +#### TypeScript + ```ts function triangleType(nums: number[]): string { nums.sort((a, b) => a - b); @@ -160,6 +170,8 @@ function triangleType(nums: number[]): string { } ``` +#### C# + ```cs public class Solution { public string TriangleType(int[] nums) { diff --git a/solution/3000-3099/3024.Type of Triangle/README_EN.md b/solution/3000-3099/3024.Type of Triangle/README_EN.md index 847d1a91e5988..ef2e9459783fb 100644 --- a/solution/3000-3099/3024.Type of Triangle/README_EN.md +++ b/solution/3000-3099/3024.Type of Triangle/README_EN.md @@ -79,6 +79,8 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def triangleType(self, nums: List[int]) -> str: @@ -92,6 +94,8 @@ class Solution: return "scalene" ``` +#### Java + ```java class Solution { public String triangleType(int[] nums) { @@ -110,6 +114,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func triangleType(nums []int) string { sort.Ints(nums) @@ -145,6 +153,8 @@ func triangleType(nums []int) string { } ``` +#### TypeScript + ```ts function triangleType(nums: number[]): string { nums.sort((a, b) => a - b); @@ -161,6 +171,8 @@ function triangleType(nums: number[]): string { } ``` +#### C# + ```cs public class Solution { public string TriangleType(int[] nums) { diff --git a/solution/3000-3099/3025.Find the Number of Ways to Place People I/README.md b/solution/3000-3099/3025.Find the Number of Ways to Place People I/README.md index c1e91046a175b..b285c4000491a 100644 --- a/solution/3000-3099/3025.Find the Number of Ways to Place People I/README.md +++ b/solution/3000-3099/3025.Find the Number of Ways to Place People I/README.md @@ -107,6 +107,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfPairs(self, points: List[List[int]]) -> int: @@ -121,6 +123,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numberOfPairs(int[][] points) { @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go func numberOfPairs(points [][]int) (ans int) { sort.Slice(points, func(i, j int) bool { @@ -189,6 +197,8 @@ func numberOfPairs(points [][]int) (ans int) { } ``` +#### TypeScript + ```ts function numberOfPairs(points: number[][]): number { points.sort((a, b) => (a[0] === b[0] ? b[1] - a[1] : a[0] - b[0])); @@ -209,6 +219,8 @@ function numberOfPairs(points: number[][]): number { } ``` +#### C# + ```cs public class Solution { public int NumberOfPairs(int[][] points) { diff --git a/solution/3000-3099/3025.Find the Number of Ways to Place People I/README_EN.md b/solution/3000-3099/3025.Find the Number of Ways to Place People I/README_EN.md index 4509b46569967..4ff37de556ffc 100644 --- a/solution/3000-3099/3025.Find the Number of Ways to Place People I/README_EN.md +++ b/solution/3000-3099/3025.Find the Number of Ways to Place People I/README_EN.md @@ -98,6 +98,8 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def numberOfPairs(self, points: List[List[int]]) -> int: @@ -112,6 +114,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numberOfPairs(int[][] points) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func numberOfPairs(points [][]int) (ans int) { sort.Slice(points, func(i, j int) bool { @@ -180,6 +188,8 @@ func numberOfPairs(points [][]int) (ans int) { } ``` +#### TypeScript + ```ts function numberOfPairs(points: number[][]): number { points.sort((a, b) => (a[0] === b[0] ? b[1] - a[1] : a[0] - b[0])); @@ -200,6 +210,8 @@ function numberOfPairs(points: number[][]): number { } ``` +#### C# + ```cs public class Solution { public int NumberOfPairs(int[][] points) { diff --git a/solution/3000-3099/3026.Maximum Good Subarray Sum/README.md b/solution/3000-3099/3026.Maximum Good Subarray Sum/README.md index 696b5bff58bf7..07dd0b5759a8e 100644 --- a/solution/3000-3099/3026.Maximum Good Subarray Sum/README.md +++ b/solution/3000-3099/3026.Maximum Good Subarray Sum/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def maximumSubarraySum(self, nums: List[int], k: int) -> int: @@ -97,6 +99,8 @@ class Solution: return 0 if ans == -inf else ans ``` +#### Java + ```java class Solution { public long maximumSubarraySum(int[] nums, int k) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func maximumSubarraySum(nums []int, k int) int64 { p := map[int]int64{nums[0]: 0} @@ -182,6 +190,8 @@ func maximumSubarraySum(nums []int, k int) int64 { } ``` +#### TypeScript + ```ts function maximumSubarraySum(nums: number[], k: number): number { const p: Map = new Map(); @@ -205,6 +215,8 @@ function maximumSubarraySum(nums: number[], k: number): number { } ``` +#### C# + ```cs public class Solution { public long MaximumSubarraySum(int[] nums, int k) { diff --git a/solution/3000-3099/3026.Maximum Good Subarray Sum/README_EN.md b/solution/3000-3099/3026.Maximum Good Subarray Sum/README_EN.md index 1565778230187..847f65e342f18 100644 --- a/solution/3000-3099/3026.Maximum Good Subarray Sum/README_EN.md +++ b/solution/3000-3099/3026.Maximum Good Subarray Sum/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Solution: def maximumSubarraySum(self, nums: List[int], k: int) -> int: @@ -95,6 +97,8 @@ class Solution: return 0 if ans == -inf else ans ``` +#### Java + ```java class Solution { public long maximumSubarraySum(int[] nums, int k) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func maximumSubarraySum(nums []int, k int) int64 { p := map[int]int64{nums[0]: 0} @@ -180,6 +188,8 @@ func maximumSubarraySum(nums []int, k int) int64 { } ``` +#### TypeScript + ```ts function maximumSubarraySum(nums: number[], k: number): number { const p: Map = new Map(); @@ -203,6 +213,8 @@ function maximumSubarraySum(nums: number[], k: number): number { } ``` +#### C# + ```cs public class Solution { public long MaximumSubarraySum(int[] nums, int k) { diff --git a/solution/3000-3099/3027.Find the Number of Ways to Place People II/README.md b/solution/3000-3099/3027.Find the Number of Ways to Place People II/README.md index b78272f4661eb..6e7bc0bc5985a 100644 --- a/solution/3000-3099/3027.Find the Number of Ways to Place People II/README.md +++ b/solution/3000-3099/3027.Find the Number of Ways to Place People II/README.md @@ -107,6 +107,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfPairs(self, points: List[List[int]]) -> int: @@ -121,6 +123,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numberOfPairs(int[][] points) { @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go func numberOfPairs(points [][]int) (ans int) { sort.Slice(points, func(i, j int) bool { @@ -189,6 +197,8 @@ func numberOfPairs(points [][]int) (ans int) { } ``` +#### TypeScript + ```ts function numberOfPairs(points: number[][]): number { points.sort((a, b) => (a[0] === b[0] ? b[1] - a[1] : a[0] - b[0])); @@ -209,6 +219,8 @@ function numberOfPairs(points: number[][]): number { } ``` +#### C# + ```cs public class Solution { public int NumberOfPairs(int[][] points) { diff --git a/solution/3000-3099/3027.Find the Number of Ways to Place People II/README_EN.md b/solution/3000-3099/3027.Find the Number of Ways to Place People II/README_EN.md index 9b68c01219c87..e7f0aec4fdc60 100644 --- a/solution/3000-3099/3027.Find the Number of Ways to Place People II/README_EN.md +++ b/solution/3000-3099/3027.Find the Number of Ways to Place People II/README_EN.md @@ -98,6 +98,8 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def numberOfPairs(self, points: List[List[int]]) -> int: @@ -112,6 +114,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int numberOfPairs(int[][] points) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func numberOfPairs(points [][]int) (ans int) { sort.Slice(points, func(i, j int) bool { @@ -180,6 +188,8 @@ func numberOfPairs(points [][]int) (ans int) { } ``` +#### TypeScript + ```ts function numberOfPairs(points: number[][]): number { points.sort((a, b) => (a[0] === b[0] ? b[1] - a[1] : a[0] - b[0])); @@ -200,6 +210,8 @@ function numberOfPairs(points: number[][]): number { } ``` +#### C# + ```cs public class Solution { public int NumberOfPairs(int[][] points) { diff --git a/solution/3000-3099/3028.Ant on the Boundary/README.md b/solution/3000-3099/3028.Ant on the Boundary/README.md index 46950549b09a0..c97c9f2685e2d 100644 --- a/solution/3000-3099/3028.Ant on the Boundary/README.md +++ b/solution/3000-3099/3028.Ant on the Boundary/README.md @@ -87,12 +87,16 @@ tags: +#### Python3 + ```python class Solution: def returnToBoundaryCount(self, nums: List[int]) -> int: return sum(s == 0 for s in accumulate(nums)) ``` +#### Java + ```java class Solution { public int returnToBoundaryCount(int[] nums) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func returnToBoundaryCount(nums []int) (ans int) { s := 0 @@ -135,6 +143,8 @@ func returnToBoundaryCount(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function returnToBoundaryCount(nums: number[]): number { let [ans, s] = [0, 0]; diff --git a/solution/3000-3099/3028.Ant on the Boundary/README_EN.md b/solution/3000-3099/3028.Ant on the Boundary/README_EN.md index a03be69c1d242..ea70d6e998b68 100644 --- a/solution/3000-3099/3028.Ant on the Boundary/README_EN.md +++ b/solution/3000-3099/3028.Ant on the Boundary/README_EN.md @@ -85,12 +85,16 @@ The time complexity is $O(n)$, where $n$ is the length of `nums`. The space comp +#### Python3 + ```python class Solution: def returnToBoundaryCount(self, nums: List[int]) -> int: return sum(s == 0 for s in accumulate(nums)) ``` +#### Java + ```java class Solution { public int returnToBoundaryCount(int[] nums) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func returnToBoundaryCount(nums []int) (ans int) { s := 0 @@ -133,6 +141,8 @@ func returnToBoundaryCount(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function returnToBoundaryCount(nums: number[]): number { let [ans, s] = [0, 0]; diff --git a/solution/3000-3099/3029.Minimum Time to Revert Word to Initial State I/README.md b/solution/3000-3099/3029.Minimum Time to Revert Word to Initial State I/README.md index a8c12c65c9a8e..90222859ab55d 100644 --- a/solution/3000-3099/3029.Minimum Time to Revert Word to Initial State I/README.md +++ b/solution/3000-3099/3029.Minimum Time to Revert Word to Initial State I/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class Solution: def minimumTimeToInitialState(self, word: str, k: int) -> int: @@ -106,6 +108,8 @@ class Solution: return (n + k - 1) // k ``` +#### Java + ```java class Solution { public int minimumTimeToInitialState(String word, int k) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func minimumTimeToInitialState(word string, k int) int { n := len(word) @@ -147,6 +155,8 @@ func minimumTimeToInitialState(word string, k int) int { } ``` +#### TypeScript + ```ts function minimumTimeToInitialState(word: string, k: number): number { const n = word.length; @@ -173,6 +183,8 @@ function minimumTimeToInitialState(word: string, k: number): number { +#### Python3 + ```python class Hashing: __slots__ = ["mod", "h", "p"] @@ -199,6 +211,8 @@ class Solution: return (n + k - 1) // k ``` +#### Java + ```java class Hashing { private final long[] p; @@ -236,6 +250,8 @@ class Solution { } ``` +#### C++ + ```cpp class Hashing { private: @@ -276,6 +292,8 @@ public: }; ``` +#### Go + ```go type Hashing struct { p []int64 diff --git a/solution/3000-3099/3029.Minimum Time to Revert Word to Initial State I/README_EN.md b/solution/3000-3099/3029.Minimum Time to Revert Word to Initial State I/README_EN.md index 69d68e61f8802..6a7b5493456a5 100644 --- a/solution/3000-3099/3029.Minimum Time to Revert Word to Initial State I/README_EN.md +++ b/solution/3000-3099/3029.Minimum Time to Revert Word to Initial State I/README_EN.md @@ -91,6 +91,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$. Here, $n$ i +#### Python3 + ```python class Solution: def minimumTimeToInitialState(self, word: str, k: int) -> int: @@ -101,6 +103,8 @@ class Solution: return (n + k - 1) // k ``` +#### Java + ```java class Solution { public int minimumTimeToInitialState(String word, int k) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func minimumTimeToInitialState(word string, k int) int { n := len(word) @@ -142,6 +150,8 @@ func minimumTimeToInitialState(word string, k int) int { } ``` +#### TypeScript + ```ts function minimumTimeToInitialState(word: string, k: number): number { const n = word.length; @@ -168,6 +178,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is +#### Python3 + ```python class Hashing: __slots__ = ["mod", "h", "p"] @@ -194,6 +206,8 @@ class Solution: return (n + k - 1) // k ``` +#### Java + ```java class Hashing { private final long[] p; @@ -231,6 +245,8 @@ class Solution { } ``` +#### C++ + ```cpp class Hashing { private: @@ -271,6 +287,8 @@ public: }; ``` +#### Go + ```go type Hashing struct { p []int64 diff --git a/solution/3000-3099/3030.Find the Grid of Region Average/README.md b/solution/3000-3099/3030.Find the Grid of Region Average/README.md index 9dc4b7a9c95ac..e1e73104050c2 100644 --- a/solution/3000-3099/3030.Find the Grid of Region Average/README.md +++ b/solution/3000-3099/3030.Find the Grid of Region Average/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def resultGrid(self, image: List[List[int]], threshold: int) -> List[List[int]]: @@ -120,6 +122,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] resultGrid(int[][] image, int threshold) { @@ -172,6 +176,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -222,6 +228,8 @@ public: }; ``` +#### Go + ```go func resultGrid(image [][]int, threshold int) [][]int { n := len(image) @@ -280,6 +288,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function resultGrid(image: number[][], threshold: number): number[][] { const n: number = image.length; diff --git a/solution/3000-3099/3030.Find the Grid of Region Average/README_EN.md b/solution/3000-3099/3030.Find the Grid of Region Average/README_EN.md index 9d4e80936f661..ca8da739fddae 100644 --- a/solution/3000-3099/3030.Find the Grid of Region Average/README_EN.md +++ b/solution/3000-3099/3030.Find the Grid of Region Average/README_EN.md @@ -76,6 +76,8 @@ Please note that the rounded-down values are used when calculating the average o +#### Python3 + ```python class Solution: def resultGrid(self, image: List[List[int]], threshold: int) -> List[List[int]]: @@ -118,6 +120,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int[][] resultGrid(int[][] image, int threshold) { @@ -170,6 +174,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -220,6 +226,8 @@ public: }; ``` +#### Go + ```go func resultGrid(image [][]int, threshold int) [][]int { n := len(image) @@ -278,6 +286,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function resultGrid(image: number[][], threshold: number): number[][] { const n: number = image.length; diff --git a/solution/3000-3099/3031.Minimum Time to Revert Word to Initial State II/README.md b/solution/3000-3099/3031.Minimum Time to Revert Word to Initial State II/README.md index 86c2105d39840..f4d887fc5514f 100644 --- a/solution/3000-3099/3031.Minimum Time to Revert Word to Initial State II/README.md +++ b/solution/3000-3099/3031.Minimum Time to Revert Word to Initial State II/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class Hashing: __slots__ = ["mod", "h", "p"] @@ -122,6 +124,8 @@ class Solution: return (n + k - 1) // k ``` +#### Java + ```java class Hashing { private final long[] p; @@ -159,6 +163,8 @@ class Solution { } ``` +#### C++ + ```cpp class Hashing { private: @@ -199,6 +205,8 @@ public: }; ``` +#### Go + ```go type Hashing struct { p []int64 diff --git a/solution/3000-3099/3031.Minimum Time to Revert Word to Initial State II/README_EN.md b/solution/3000-3099/3031.Minimum Time to Revert Word to Initial State II/README_EN.md index 774945999c651..12998f89525cb 100644 --- a/solution/3000-3099/3031.Minimum Time to Revert Word to Initial State II/README_EN.md +++ b/solution/3000-3099/3031.Minimum Time to Revert Word to Initial State II/README_EN.md @@ -83,6 +83,8 @@ It can be shown that 4 seconds is the minimum time greater than zero required fo +#### Python3 + ```python class Hashing: __slots__ = ["mod", "h", "p"] @@ -109,6 +111,8 @@ class Solution: return (n + k - 1) // k ``` +#### Java + ```java class Hashing { private final long[] p; @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Hashing { private: @@ -186,6 +192,8 @@ public: }; ``` +#### Go + ```go type Hashing struct { p []int64 diff --git a/solution/3000-3099/3032.Count Numbers With Unique Digits II/README.md b/solution/3000-3099/3032.Count Numbers With Unique Digits II/README.md index b29fc13f25f16..8966a2a95f2c3 100644 --- a/solution/3000-3099/3032.Count Numbers With Unique Digits II/README.md +++ b/solution/3000-3099/3032.Count Numbers With Unique Digits II/README.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python class Solution: def numberCount(self, a: int, b: int) -> int: @@ -105,6 +107,8 @@ class Solution: return y - x ``` +#### Java + ```java class Solution { private String num; @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -182,6 +188,8 @@ public: }; ``` +#### Go + ```go func numberCount(a int, b int) int { num := strconv.Itoa(b) @@ -234,6 +242,8 @@ func numberCount(a int, b int) int { } ``` +#### TypeScript + ```ts function numberCount(a: number, b: number): number { let num: string = b.toString(); @@ -283,12 +293,16 @@ function numberCount(a: number, b: number): number { +#### Python3 + ```python class Solution: def numberCount(self, a: int, b: int) -> int: return sum(len(set(str(num))) == len(str(num)) for num in range(a, b + 1)) ``` +#### Java + ```java class Solution { public int numberCount(int a, int b) { @@ -316,6 +330,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -342,6 +358,8 @@ public: }; ``` +#### Go + ```go func numberCount(a int, b int) int { count := 0 @@ -365,6 +383,8 @@ func hasUniqueDigits(num int) bool { } ``` +#### TypeScript + ```ts function numberCount(a: number, b: number): number { let count: number = 0; diff --git a/solution/3000-3099/3032.Count Numbers With Unique Digits II/README_EN.md b/solution/3000-3099/3032.Count Numbers With Unique Digits II/README_EN.md index 0d58e02439c57..01596f3536907 100644 --- a/solution/3000-3099/3032.Count Numbers With Unique Digits II/README_EN.md +++ b/solution/3000-3099/3032.Count Numbers With Unique Digits II/README_EN.md @@ -79,6 +79,8 @@ The time complexity is $O(m \times 2^{10} \times 10)$, and the space complexity +#### Python3 + ```python class Solution: def numberCount(self, a: int, b: int) -> int: @@ -103,6 +105,8 @@ class Solution: return y - x ``` +#### Java + ```java class Solution { private String num; @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -180,6 +186,8 @@ public: }; ``` +#### Go + ```go func numberCount(a int, b int) int { num := strconv.Itoa(b) @@ -232,6 +240,8 @@ func numberCount(a int, b int) int { } ``` +#### TypeScript + ```ts function numberCount(a: number, b: number): number { let num: string = b.toString(); @@ -281,12 +291,16 @@ function numberCount(a: number, b: number): number { +#### Python3 + ```python class Solution: def numberCount(self, a: int, b: int) -> int: return sum(len(set(str(num))) == len(str(num)) for num in range(a, b + 1)) ``` +#### Java + ```java class Solution { public int numberCount(int a, int b) { @@ -314,6 +328,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -340,6 +356,8 @@ public: }; ``` +#### Go + ```go func numberCount(a int, b int) int { count := 0 @@ -363,6 +381,8 @@ func hasUniqueDigits(num int) bool { } ``` +#### TypeScript + ```ts function numberCount(a: number, b: number): number { let count: number = 0; diff --git a/solution/3000-3099/3033.Modify the Matrix/README.md b/solution/3000-3099/3033.Modify the Matrix/README.md index bfad00ff27ed6..b24aa8d94a18d 100644 --- a/solution/3000-3099/3033.Modify the Matrix/README.md +++ b/solution/3000-3099/3033.Modify the Matrix/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python class Solution: def modifiedMatrix(self, matrix: List[List[int]]) -> List[List[int]]: @@ -81,6 +83,8 @@ class Solution: return matrix ``` +#### Java + ```java class Solution { public int[][] modifiedMatrix(int[][] matrix) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func modifiedMatrix(matrix [][]int) [][]int { m, n := len(matrix), len(matrix[0]) @@ -140,6 +148,8 @@ func modifiedMatrix(matrix [][]int) [][]int { } ``` +#### TypeScript + ```ts function modifiedMatrix(matrix: number[][]): number[][] { const [m, n] = [matrix.length, matrix[0].length]; @@ -158,6 +168,8 @@ function modifiedMatrix(matrix: number[][]): number[][] { } ``` +#### C# + ```cs public class Solution { public int[][] ModifiedMatrix(int[][] matrix) { diff --git a/solution/3000-3099/3033.Modify the Matrix/README_EN.md b/solution/3000-3099/3033.Modify the Matrix/README_EN.md index d7b1c27bd9036..9207f736eb259 100644 --- a/solution/3000-3099/3033.Modify the Matrix/README_EN.md +++ b/solution/3000-3099/3033.Modify the Matrix/README_EN.md @@ -67,6 +67,8 @@ The time complexity is $O(m \times n)$, where $m$ and $n$ are the number of rows +#### Python3 + ```python class Solution: def modifiedMatrix(self, matrix: List[List[int]]) -> List[List[int]]: @@ -79,6 +81,8 @@ class Solution: return matrix ``` +#### Java + ```java class Solution { public int[][] modifiedMatrix(int[][] matrix) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func modifiedMatrix(matrix [][]int) [][]int { m, n := len(matrix), len(matrix[0]) @@ -138,6 +146,8 @@ func modifiedMatrix(matrix [][]int) [][]int { } ``` +#### TypeScript + ```ts function modifiedMatrix(matrix: number[][]): number[][] { const [m, n] = [matrix.length, matrix[0].length]; @@ -156,6 +166,8 @@ function modifiedMatrix(matrix: number[][]): number[][] { } ``` +#### C# + ```cs public class Solution { public int[][] ModifiedMatrix(int[][] matrix) { diff --git a/solution/3000-3099/3034.Number of Subarrays That Match a Pattern I/README.md b/solution/3000-3099/3034.Number of Subarrays That Match a Pattern I/README.md index 80228bec6f641..de015ff91dcce 100644 --- a/solution/3000-3099/3034.Number of Subarrays That Match a Pattern I/README.md +++ b/solution/3000-3099/3034.Number of Subarrays That Match a Pattern I/README.md @@ -78,6 +78,8 @@ tags: +#### Python3 + ```python class Solution: def countMatchingSubarrays(self, nums: List[int], pattern: List[int]) -> int: @@ -92,6 +94,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countMatchingSubarrays(int[] nums, int[] pattern) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func countMatchingSubarrays(nums []int, pattern []int) (ans int) { f := func(a, b int) int { @@ -163,6 +171,8 @@ func countMatchingSubarrays(nums []int, pattern []int) (ans int) { } ``` +#### TypeScript + ```ts function countMatchingSubarrays(nums: number[], pattern: number[]): number { const f = (a: number, b: number) => (a === b ? 0 : a < b ? 1 : -1); @@ -182,6 +192,8 @@ function countMatchingSubarrays(nums: number[], pattern: number[]): number { } ``` +#### C# + ```cs public class Solution { public int CountMatchingSubarrays(int[] nums, int[] pattern) { diff --git a/solution/3000-3099/3034.Number of Subarrays That Match a Pattern I/README_EN.md b/solution/3000-3099/3034.Number of Subarrays That Match a Pattern I/README_EN.md index da6945017c1a9..168f28067c156 100644 --- a/solution/3000-3099/3034.Number of Subarrays That Match a Pattern I/README_EN.md +++ b/solution/3000-3099/3034.Number of Subarrays That Match a Pattern I/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(n \times m)$, where $n$ and $m$ are the lengths of the +#### Python3 + ```python class Solution: def countMatchingSubarrays(self, nums: List[int], pattern: List[int]) -> int: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countMatchingSubarrays(int[] nums, int[] pattern) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -136,6 +142,8 @@ public: }; ``` +#### Go + ```go func countMatchingSubarrays(nums []int, pattern []int) (ans int) { f := func(a, b int) int { @@ -161,6 +169,8 @@ func countMatchingSubarrays(nums []int, pattern []int) (ans int) { } ``` +#### TypeScript + ```ts function countMatchingSubarrays(nums: number[], pattern: number[]): number { const f = (a: number, b: number) => (a === b ? 0 : a < b ? 1 : -1); @@ -180,6 +190,8 @@ function countMatchingSubarrays(nums: number[], pattern: number[]): number { } ``` +#### C# + ```cs public class Solution { public int CountMatchingSubarrays(int[] nums, int[] pattern) { diff --git a/solution/3000-3099/3035.Maximum Palindromes After Operations/README.md b/solution/3000-3099/3035.Maximum Palindromes After Operations/README.md index 8a1c7ed1912ab..5425dd35f47d7 100644 --- a/solution/3000-3099/3035.Maximum Palindromes After Operations/README.md +++ b/solution/3000-3099/3035.Maximum Palindromes After Operations/README.md @@ -91,6 +91,8 @@ words 中有一个回文 "a" 。 +#### Python3 + ```python class Solution: def maxPalindromesAfterOperations(self, words: List[str]) -> int: @@ -110,6 +112,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxPalindromesAfterOperations(String[] words) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -161,6 +167,8 @@ public: }; ``` +#### Go + ```go func maxPalindromesAfterOperations(words []string) (ans int) { var s, mask int @@ -185,6 +193,8 @@ func maxPalindromesAfterOperations(words []string) (ans int) { } ``` +#### TypeScript + ```ts function maxPalindromesAfterOperations(words: string[]): number { let s: number = 0; diff --git a/solution/3000-3099/3035.Maximum Palindromes After Operations/README_EN.md b/solution/3000-3099/3035.Maximum Palindromes After Operations/README_EN.md index 9c54136a62a4d..310e5f708d1aa 100644 --- a/solution/3000-3099/3035.Maximum Palindromes After Operations/README_EN.md +++ b/solution/3000-3099/3035.Maximum Palindromes After Operations/README_EN.md @@ -87,6 +87,8 @@ Hence, the answer is 1. +#### Python3 + ```python class Solution: def maxPalindromesAfterOperations(self, words: List[str]) -> int: @@ -106,6 +108,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxPalindromesAfterOperations(String[] words) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func maxPalindromesAfterOperations(words []string) (ans int) { var s, mask int @@ -181,6 +189,8 @@ func maxPalindromesAfterOperations(words []string) (ans int) { } ``` +#### TypeScript + ```ts function maxPalindromesAfterOperations(words: string[]): number { let s: number = 0; diff --git a/solution/3000-3099/3036.Number of Subarrays That Match a Pattern II/README.md b/solution/3000-3099/3036.Number of Subarrays That Match a Pattern II/README.md index 1500f641f31a5..8decbdfcef57f 100644 --- a/solution/3000-3099/3036.Number of Subarrays That Match a Pattern II/README.md +++ b/solution/3000-3099/3036.Number of Subarrays That Match a Pattern II/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python def partial(s): g, pi = 0, [0] * len(s) @@ -122,6 +124,8 @@ class Solution: return len(match(s, pattern)) ``` +#### Java + ```java class Solution { public int countMatchingSubarrays(int[] nums, int[] pattern) { @@ -164,6 +168,8 @@ class Solution { ``` +#### C++ + ```cpp int ps[1000001]; class Solution { @@ -196,6 +202,8 @@ public: }; ``` +#### Go + ```go func countMatchingSubarrays(nums []int, pattern []int) int { N := len(pattern) @@ -231,6 +239,8 @@ func countMatchingSubarrays(nums []int, pattern []int) int { } ``` +#### TypeScript + ```ts class Solution { countMatchingSubarrays(nums: number[], pattern: number[]): number { diff --git a/solution/3000-3099/3036.Number of Subarrays That Match a Pattern II/README_EN.md b/solution/3000-3099/3036.Number of Subarrays That Match a Pattern II/README_EN.md index fd32d67ac41ed..54a3b5f76ccbc 100644 --- a/solution/3000-3099/3036.Number of Subarrays That Match a Pattern II/README_EN.md +++ b/solution/3000-3099/3036.Number of Subarrays That Match a Pattern II/README_EN.md @@ -72,6 +72,8 @@ Hence, there are 2 subarrays in nums that match the pattern. +#### Python3 + ```python def partial(s): g, pi = 0, [0] * len(s) @@ -120,6 +122,8 @@ class Solution: return len(match(s, pattern)) ``` +#### Java + ```java class Solution { public int countMatchingSubarrays(int[] nums, int[] pattern) { @@ -161,6 +165,8 @@ class Solution { } ``` +#### C++ + ```cpp int ps[1000001]; class Solution { @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go func countMatchingSubarrays(nums []int, pattern []int) int { N := len(pattern) @@ -228,6 +236,8 @@ func countMatchingSubarrays(nums []int, pattern []int) int { } ``` +#### TypeScript + ```ts class Solution { countMatchingSubarrays(nums: number[], pattern: number[]): number { diff --git a/solution/3000-3099/3037.Find Pattern in Infinite Stream II/README.md b/solution/3000-3099/3037.Find Pattern in Infinite Stream II/README.md index c9d8d43b48f5a..30d466c43e730 100644 --- a/solution/3000-3099/3037.Find Pattern in Infinite Stream II/README.md +++ b/solution/3000-3099/3037.Find Pattern in Infinite Stream II/README.md @@ -79,18 +79,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/3000-3099/3037.Find Pattern in Infinite Stream II/README_EN.md b/solution/3000-3099/3037.Find Pattern in Infinite Stream II/README_EN.md index 5f2bca9d22913..0fe632282f0a3 100644 --- a/solution/3000-3099/3037.Find Pattern in Infinite Stream II/README_EN.md +++ b/solution/3000-3099/3037.Find Pattern in Infinite Stream II/README_EN.md @@ -75,18 +75,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/3000-3099/3038.Maximum Number of Operations With the Same Score I/README.md b/solution/3000-3099/3038.Maximum Number of Operations With the Same Score I/README.md index 9fbba84846ff7..e84aebd68c6e3 100644 --- a/solution/3000-3099/3038.Maximum Number of Operations With the Same Score I/README.md +++ b/solution/3000-3099/3038.Maximum Number of Operations With the Same Score I/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def maxOperations(self, nums: List[int]) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxOperations(int[] nums) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func maxOperations(nums []int) (ans int) { s, n := nums[0]+nums[1], len(nums) @@ -125,6 +133,8 @@ func maxOperations(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function maxOperations(nums: number[]): number { const s = nums[0] + nums[1]; diff --git a/solution/3000-3099/3038.Maximum Number of Operations With the Same Score I/README_EN.md b/solution/3000-3099/3038.Maximum Number of Operations With the Same Score I/README_EN.md index 09e21886210ed..2cd6426fb8d25 100644 --- a/solution/3000-3099/3038.Maximum Number of Operations With the Same Score I/README_EN.md +++ b/solution/3000-3099/3038.Maximum Number of Operations With the Same Score I/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The +#### Python3 + ```python class Solution: def maxOperations(self, nums: List[int]) -> int: @@ -86,6 +88,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxOperations(int[] nums) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func maxOperations(nums []int) (ans int) { s, n := nums[0]+nums[1], len(nums) @@ -123,6 +131,8 @@ func maxOperations(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function maxOperations(nums: number[]): number { const s = nums[0] + nums[1]; diff --git a/solution/3000-3099/3039.Apply Operations to Make String Empty/README.md b/solution/3000-3099/3039.Apply Operations to Make String Empty/README.md index f43dd54c93d8f..13ba3c7e5e5cc 100644 --- a/solution/3000-3099/3039.Apply Operations to Make String Empty/README.md +++ b/solution/3000-3099/3039.Apply Operations to Make String Empty/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def lastNonEmptyString(self, s: str) -> str: @@ -95,6 +97,8 @@ class Solution: return "".join(c for i, c in enumerate(s) if cnt[c] == mx and last[c] == i) ``` +#### Java + ```java class Solution { public String lastNonEmptyString(String s) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func lastNonEmptyString(s string) string { cnt := [26]int{} @@ -165,6 +173,8 @@ func lastNonEmptyString(s string) string { } ``` +#### TypeScript + ```ts function lastNonEmptyString(s: string): string { const cnt: number[] = Array(26).fill(0); diff --git a/solution/3000-3099/3039.Apply Operations to Make String Empty/README_EN.md b/solution/3000-3099/3039.Apply Operations to Make String Empty/README_EN.md index 37cb2d69c8f08..6267f30f456fa 100644 --- a/solution/3000-3099/3039.Apply Operations to Make String Empty/README_EN.md +++ b/solution/3000-3099/3039.Apply Operations to Make String Empty/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n)$, and the space complexity is $O(|\Sigma|)$, where +#### Python3 + ```python class Solution: def lastNonEmptyString(self, s: str) -> str: @@ -93,6 +95,8 @@ class Solution: return "".join(c for i, c in enumerate(s) if cnt[c] == mx and last[c] == i) ``` +#### Java + ```java class Solution { public String lastNonEmptyString(String s) { @@ -117,6 +121,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func lastNonEmptyString(s string) string { cnt := [26]int{} @@ -163,6 +171,8 @@ func lastNonEmptyString(s string) string { } ``` +#### TypeScript + ```ts function lastNonEmptyString(s: string): string { const cnt: number[] = Array(26).fill(0); diff --git a/solution/3000-3099/3040.Maximum Number of Operations With the Same Score II/README.md b/solution/3000-3099/3040.Maximum Number of Operations With the Same Score II/README.md index 6ec4e50689587..1bc88eead9ae9 100644 --- a/solution/3000-3099/3040.Maximum Number of Operations With the Same Score II/README.md +++ b/solution/3000-3099/3040.Maximum Number of Operations With the Same Score II/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def maxOperations(self, nums: List[int]) -> int: @@ -115,6 +117,8 @@ class Solution: return 1 + max(a, b, c) ``` +#### Java + ```java class Solution { private Integer[][] f; @@ -159,6 +163,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -196,6 +202,8 @@ public: }; ``` +#### Go + ```go func maxOperations(nums []int) int { n := len(nums) @@ -240,6 +248,8 @@ func maxOperations(nums []int) int { } ``` +#### TypeScript + ```ts function maxOperations(nums: number[]): number { const n = nums.length; diff --git a/solution/3000-3099/3040.Maximum Number of Operations With the Same Score II/README_EN.md b/solution/3000-3099/3040.Maximum Number of Operations With the Same Score II/README_EN.md index e0f49c6f1a604..7bba7cabfe8c4 100644 --- a/solution/3000-3099/3040.Maximum Number of Operations With the Same Score II/README_EN.md +++ b/solution/3000-3099/3040.Maximum Number of Operations With the Same Score II/README_EN.md @@ -90,6 +90,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$. Here, $n$ +#### Python3 + ```python class Solution: def maxOperations(self, nums: List[int]) -> int: @@ -113,6 +115,8 @@ class Solution: return 1 + max(a, b, c) ``` +#### Java + ```java class Solution { private Integer[][] f; @@ -157,6 +161,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -194,6 +200,8 @@ public: }; ``` +#### Go + ```go func maxOperations(nums []int) int { n := len(nums) @@ -238,6 +246,8 @@ func maxOperations(nums []int) int { } ``` +#### TypeScript + ```ts function maxOperations(nums: number[]): number { const n = nums.length; diff --git a/solution/3000-3099/3041.Maximize Consecutive Elements in an Array After Modification/README.md b/solution/3000-3099/3041.Maximize Consecutive Elements in an Array After Modification/README.md index a8298f335ae80..80764719995b1 100644 --- a/solution/3000-3099/3041.Maximize Consecutive Elements in an Array After Modification/README.md +++ b/solution/3000-3099/3041.Maximize Consecutive Elements in an Array After Modification/README.md @@ -66,18 +66,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/3000-3099/3041.Maximize Consecutive Elements in an Array After Modification/README_EN.md b/solution/3000-3099/3041.Maximize Consecutive Elements in an Array After Modification/README_EN.md index a82ede7530c65..d31cc98fd4fe6 100644 --- a/solution/3000-3099/3041.Maximize Consecutive Elements in an Array After Modification/README_EN.md +++ b/solution/3000-3099/3041.Maximize Consecutive Elements in an Array After Modification/README_EN.md @@ -64,18 +64,26 @@ It can be shown that we cannot select more than 3 consecutive elements. +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/3000-3099/3042.Count Prefix and Suffix Pairs I/README.md b/solution/3000-3099/3042.Count Prefix and Suffix Pairs I/README.md index b596830e96758..237a79b3809c5 100644 --- a/solution/3000-3099/3042.Count Prefix and Suffix Pairs I/README.md +++ b/solution/3000-3099/3042.Count Prefix and Suffix Pairs I/README.md @@ -91,6 +91,8 @@ i = 2 且 j = 3 ,因为 isPrefixAndSuffix("ma", "mama") 为 true 。 +#### Python3 + ```python class Solution: def countPrefixSuffixPairs(self, words: List[str]) -> int: @@ -101,6 +103,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countPrefixSuffixPairs(String[] words) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func countPrefixSuffixPairs(words []string) (ans int) { for i, s := range words { @@ -153,6 +161,8 @@ func countPrefixSuffixPairs(words []string) (ans int) { } ``` +#### TypeScript + ```ts function countPrefixSuffixPairs(words: string[]): number { let ans = 0; @@ -184,6 +194,8 @@ function countPrefixSuffixPairs(words: string[]): number { +#### Python3 + ```python class Node: __slots__ = ["children", "cnt"] @@ -208,6 +220,8 @@ class Solution: return ans ``` +#### Java + ```java class Node { Map children = new HashMap<>(); @@ -234,6 +248,8 @@ class Solution { } ``` +#### C++ + ```cpp class Node { public: @@ -267,6 +283,8 @@ public: }; ``` +#### Go + ```go type Node struct { children map[int]*Node diff --git a/solution/3000-3099/3042.Count Prefix and Suffix Pairs I/README_EN.md b/solution/3000-3099/3042.Count Prefix and Suffix Pairs I/README_EN.md index f632ef3d608bb..3e48434591f80 100644 --- a/solution/3000-3099/3042.Count Prefix and Suffix Pairs I/README_EN.md +++ b/solution/3000-3099/3042.Count Prefix and Suffix Pairs I/README_EN.md @@ -89,6 +89,8 @@ The time complexity is $O(n^2 \times m)$, where $n$ and $m$ are the length of `w +#### Python3 + ```python class Solution: def countPrefixSuffixPairs(self, words: List[str]) -> int: @@ -99,6 +101,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countPrefixSuffixPairs(String[] words) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -138,6 +144,8 @@ public: }; ``` +#### Go + ```go func countPrefixSuffixPairs(words []string) (ans int) { for i, s := range words { @@ -151,6 +159,8 @@ func countPrefixSuffixPairs(words []string) (ans int) { } ``` +#### TypeScript + ```ts function countPrefixSuffixPairs(words: string[]): number { let ans = 0; @@ -182,6 +192,8 @@ The time complexity is $O(n \times m)$, and the space complexity is $O(n \times +#### Python3 + ```python class Node: __slots__ = ["children", "cnt"] @@ -206,6 +218,8 @@ class Solution: return ans ``` +#### Java + ```java class Node { Map children = new HashMap<>(); @@ -232,6 +246,8 @@ class Solution { } ``` +#### C++ + ```cpp class Node { public: @@ -265,6 +281,8 @@ public: }; ``` +#### Go + ```go type Node struct { children map[int]*Node diff --git a/solution/3000-3099/3043.Find the Length of the Longest Common Prefix/README.md b/solution/3000-3099/3043.Find the Length of the Longest Common Prefix/README.md index c525cf3bb3a90..b4d7746119489 100644 --- a/solution/3000-3099/3043.Find the Length of the Longest Common Prefix/README.md +++ b/solution/3000-3099/3043.Find the Length of the Longest Common Prefix/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def longestCommonPrefix(self, arr1: List[int], arr2: List[int]) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestCommonPrefix(int[] arr1, int[] arr2) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func longestCommonPrefix(arr1 []int, arr2 []int) (ans int) { s := map[int]bool{} @@ -162,6 +170,8 @@ func longestCommonPrefix(arr1 []int, arr2 []int) (ans int) { } ``` +#### TypeScript + ```ts function longestCommonPrefix(arr1: number[], arr2: number[]): number { const s: Set = new Set(); diff --git a/solution/3000-3099/3043.Find the Length of the Longest Common Prefix/README_EN.md b/solution/3000-3099/3043.Find the Length of the Longest Common Prefix/README_EN.md index d4ec99f9f6bde..1ff77d43c30de 100644 --- a/solution/3000-3099/3043.Find the Length of the Longest Common Prefix/README_EN.md +++ b/solution/3000-3099/3043.Find the Length of the Longest Common Prefix/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(m \times \log M + n \times \log N)$, and the space com +#### Python3 + ```python class Solution: def longestCommonPrefix(self, arr1: List[int], arr2: List[int]) -> int: @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestCommonPrefix(int[] arr1, int[] arr2) { @@ -116,6 +120,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func longestCommonPrefix(arr1 []int, arr2 []int) (ans int) { s := map[int]bool{} @@ -160,6 +168,8 @@ func longestCommonPrefix(arr1 []int, arr2 []int) (ans int) { } ``` +#### TypeScript + ```ts function longestCommonPrefix(arr1: number[], arr2: number[]): number { const s: Set = new Set(); diff --git a/solution/3000-3099/3044.Most Frequent Prime/README.md b/solution/3000-3099/3044.Most Frequent Prime/README.md index 01e86845c385c..ae90bf60ea6c2 100644 --- a/solution/3000-3099/3044.Most Frequent Prime/README.md +++ b/solution/3000-3099/3044.Most Frequent Prime/README.md @@ -109,6 +109,8 @@ tags: +#### Python3 + ```python class Solution: def mostFrequentPrime(self, mat: List[List[int]]) -> int: @@ -139,6 +141,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int mostFrequentPrime(int[][] mat) { @@ -186,6 +190,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -234,6 +240,8 @@ private: }; ``` +#### Go + ```go func mostFrequentPrime(mat [][]int) int { m, n := len(mat), len(mat[0]) @@ -278,6 +286,8 @@ func isPrime(n int) bool { } ``` +#### TypeScript + ```ts function mostFrequentPrime(mat: number[][]): number { const m: number = mat.length; diff --git a/solution/3000-3099/3044.Most Frequent Prime/README_EN.md b/solution/3000-3099/3044.Most Frequent Prime/README_EN.md index 4e3b73c0cc725..81d1f4e8a10b1 100644 --- a/solution/3000-3099/3044.Most Frequent Prime/README_EN.md +++ b/solution/3000-3099/3044.Most Frequent Prime/README_EN.md @@ -107,6 +107,8 @@ The time complexity is $O(m \times n \times \max(m, n) \times {10}^{\frac{\max(m +#### Python3 + ```python class Solution: def mostFrequentPrime(self, mat: List[List[int]]) -> int: @@ -137,6 +139,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int mostFrequentPrime(int[][] mat) { @@ -184,6 +188,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -232,6 +238,8 @@ private: }; ``` +#### Go + ```go func mostFrequentPrime(mat [][]int) int { m, n := len(mat), len(mat[0]) @@ -276,6 +284,8 @@ func isPrime(n int) bool { } ``` +#### TypeScript + ```ts function mostFrequentPrime(mat: number[][]): number { const m: number = mat.length; diff --git a/solution/3000-3099/3045.Count Prefix and Suffix Pairs II/README.md b/solution/3000-3099/3045.Count Prefix and Suffix Pairs II/README.md index d13aafb89f187..a2883a72c9f93 100644 --- a/solution/3000-3099/3045.Count Prefix and Suffix Pairs II/README.md +++ b/solution/3000-3099/3045.Count Prefix and Suffix Pairs II/README.md @@ -94,6 +94,8 @@ i = 2 且 j = 3 ,因为 isPrefixAndSuffix("ma", "mama") 为 true 。 +#### Python3 + ```python class Node: __slots__ = ["children", "cnt"] @@ -118,6 +120,8 @@ class Solution: return ans ``` +#### Java + ```java class Node { Map children = new HashMap<>(); @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Node { public: @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go type Node struct { children map[int]*Node @@ -202,6 +210,8 @@ func countPrefixSuffixPairs(words []string) (ans int64) { } ``` +#### TypeScript + ```ts class Node { children: Map = new Map(); diff --git a/solution/3000-3099/3045.Count Prefix and Suffix Pairs II/README_EN.md b/solution/3000-3099/3045.Count Prefix and Suffix Pairs II/README_EN.md index 56ca8be4123f2..386908ee7ed4a 100644 --- a/solution/3000-3099/3045.Count Prefix and Suffix Pairs II/README_EN.md +++ b/solution/3000-3099/3045.Count Prefix and Suffix Pairs II/README_EN.md @@ -92,6 +92,8 @@ The time complexity is $O(n \times m)$, and the space complexity is $O(n \times +#### Python3 + ```python class Node: __slots__ = ["children", "cnt"] @@ -116,6 +118,8 @@ class Solution: return ans ``` +#### Java + ```java class Node { Map children = new HashMap<>(); @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Node { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go type Node struct { children map[int]*Node @@ -200,6 +208,8 @@ func countPrefixSuffixPairs(words []string) (ans int64) { } ``` +#### TypeScript + ```ts class Node { children: Map = new Map(); diff --git a/solution/3000-3099/3046.Split the Array/README.md b/solution/3000-3099/3046.Split the Array/README.md index c713114158f75..028f64aa7b85f 100644 --- a/solution/3000-3099/3046.Split the Array/README.md +++ b/solution/3000-3099/3046.Split the Array/README.md @@ -72,12 +72,16 @@ tags: +#### Python3 + ```python class Solution: def isPossibleToSplit(self, nums: List[int]) -> bool: return max(Counter(nums).values()) < 3 ``` +#### Java + ```java class Solution { public boolean isPossibleToSplit(int[] nums) { @@ -92,6 +96,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -107,6 +113,8 @@ public: }; ``` +#### Go + ```go func isPossibleToSplit(nums []int) bool { cnt := [101]int{} @@ -120,6 +128,8 @@ func isPossibleToSplit(nums []int) bool { } ``` +#### TypeScript + ```ts function isPossibleToSplit(nums: number[]): boolean { const cnt: number[] = Array(101).fill(0); diff --git a/solution/3000-3099/3046.Split the Array/README_EN.md b/solution/3000-3099/3046.Split the Array/README_EN.md index 8bf5dbfb44787..0fd29ec9f8c09 100644 --- a/solution/3000-3099/3046.Split the Array/README_EN.md +++ b/solution/3000-3099/3046.Split the Array/README_EN.md @@ -70,12 +70,16 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def isPossibleToSplit(self, nums: List[int]) -> bool: return max(Counter(nums).values()) < 3 ``` +#### Java + ```java class Solution { public boolean isPossibleToSplit(int[] nums) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -105,6 +111,8 @@ public: }; ``` +#### Go + ```go func isPossibleToSplit(nums []int) bool { cnt := [101]int{} @@ -118,6 +126,8 @@ func isPossibleToSplit(nums []int) bool { } ``` +#### TypeScript + ```ts function isPossibleToSplit(nums: number[]): boolean { const cnt: number[] = Array(101).fill(0); diff --git a/solution/3000-3099/3047.Find the Largest Area of Square Inside Two Rectangles/README.md b/solution/3000-3099/3047.Find the Largest Area of Square Inside Two Rectangles/README.md index 81d9beb82e015..189cc62207691 100644 --- a/solution/3000-3099/3047.Find the Largest Area of Square Inside Two Rectangles/README.md +++ b/solution/3000-3099/3047.Find the Largest Area of Square Inside Two Rectangles/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class Solution: def largestSquareArea( @@ -111,6 +113,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long largestSquareArea(int[][] bottomLeft, int[][] topRight) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func largestSquareArea(bottomLeft [][]int, topRight [][]int) (ans int64) { for i, b1 := range bottomLeft { @@ -179,6 +187,8 @@ func largestSquareArea(bottomLeft [][]int, topRight [][]int) (ans int64) { } ``` +#### TypeScript + ```ts function largestSquareArea(bottomLeft: number[][], topRight: number[][]): number { let ans = 0; diff --git a/solution/3000-3099/3047.Find the Largest Area of Square Inside Two Rectangles/README_EN.md b/solution/3000-3099/3047.Find the Largest Area of Square Inside Two Rectangles/README_EN.md index d0d09c11f2571..6ec1f35cbc797 100644 --- a/solution/3000-3099/3047.Find the Largest Area of Square Inside Two Rectangles/README_EN.md +++ b/solution/3000-3099/3047.Find the Largest Area of Square Inside Two Rectangles/README_EN.md @@ -90,6 +90,8 @@ The time complexity is $O(n^2)$, where $n$ is the number of rectangles. The spac +#### Python3 + ```python class Solution: def largestSquareArea( @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long largestSquareArea(int[][] bottomLeft, int[][] topRight) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func largestSquareArea(bottomLeft [][]int, topRight [][]int) (ans int64) { for i, b1 := range bottomLeft { @@ -175,6 +183,8 @@ func largestSquareArea(bottomLeft [][]int, topRight [][]int) (ans int64) { } ``` +#### TypeScript + ```ts function largestSquareArea(bottomLeft: number[][], topRight: number[][]): number { let ans = 0; diff --git a/solution/3000-3099/3048.Earliest Second to Mark Indices I/README.md b/solution/3000-3099/3048.Earliest Second to Mark Indices I/README.md index 133aa149621bd..d61d8be3c3b4a 100644 --- a/solution/3000-3099/3048.Earliest Second to Mark Indices I/README.md +++ b/solution/3000-3099/3048.Earliest Second to Mark Indices I/README.md @@ -111,6 +111,8 @@ tags: +#### Python3 + ```python class Solution: def earliestSecondToMarkIndices( @@ -135,6 +137,8 @@ class Solution: return -1 if l > m else l ``` +#### Java + ```java class Solution { private int[] nums; @@ -180,6 +184,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -222,6 +228,8 @@ public: }; ``` +#### Go + ```go func earliestSecondToMarkIndices(nums []int, changeIndices []int) int { n, m := len(nums), len(changeIndices) @@ -251,6 +259,8 @@ func earliestSecondToMarkIndices(nums []int, changeIndices []int) int { } ``` +#### TypeScript + ```ts function earliestSecondToMarkIndices(nums: number[], changeIndices: number[]): number { const [n, m] = [nums.length, changeIndices.length]; diff --git a/solution/3000-3099/3048.Earliest Second to Mark Indices I/README_EN.md b/solution/3000-3099/3048.Earliest Second to Mark Indices I/README_EN.md index 03810dd165afb..85932e79fa8a2 100644 --- a/solution/3000-3099/3048.Earliest Second to Mark Indices I/README_EN.md +++ b/solution/3000-3099/3048.Earliest Second to Mark Indices I/README_EN.md @@ -109,6 +109,8 @@ The time complexity is $O(m \times \log m)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def earliestSecondToMarkIndices( @@ -133,6 +135,8 @@ class Solution: return -1 if l > m else l ``` +#### Java + ```java class Solution { private int[] nums; @@ -178,6 +182,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -220,6 +226,8 @@ public: }; ``` +#### Go + ```go func earliestSecondToMarkIndices(nums []int, changeIndices []int) int { n, m := len(nums), len(changeIndices) @@ -249,6 +257,8 @@ func earliestSecondToMarkIndices(nums []int, changeIndices []int) int { } ``` +#### TypeScript + ```ts function earliestSecondToMarkIndices(nums: number[], changeIndices: number[]): number { const [n, m] = [nums.length, changeIndices.length]; diff --git a/solution/3000-3099/3049.Earliest Second to Mark Indices II/README.md b/solution/3000-3099/3049.Earliest Second to Mark Indices II/README.md index eeb3d9a296aff..5c5796f009bd7 100644 --- a/solution/3000-3099/3049.Earliest Second to Mark Indices II/README.md +++ b/solution/3000-3099/3049.Earliest Second to Mark Indices II/README.md @@ -103,18 +103,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/3000-3099/3049.Earliest Second to Mark Indices II/README_EN.md b/solution/3000-3099/3049.Earliest Second to Mark Indices II/README_EN.md index 1346e008e197b..f7ece584ee48b 100644 --- a/solution/3000-3099/3049.Earliest Second to Mark Indices II/README_EN.md +++ b/solution/3000-3099/3049.Earliest Second to Mark Indices II/README_EN.md @@ -101,18 +101,26 @@ Hence, the answer is -1. +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/3000-3099/3050.Pizza Toppings Cost Analysis/README.md b/solution/3000-3099/3050.Pizza Toppings Cost Analysis/README.md index a985874aa6f14..fec099b1095db 100644 --- a/solution/3000-3099/3050.Pizza Toppings Cost Analysis/README.md +++ b/solution/3000-3099/3050.Pizza Toppings Cost Analysis/README.md @@ -88,6 +88,8 @@ Toppings 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/3000-3099/3050.Pizza Toppings Cost Analysis/README_EN.md b/solution/3000-3099/3050.Pizza Toppings Cost Analysis/README_EN.md index debc8ca5bae14..6dfe2f7dfbb20 100644 --- a/solution/3000-3099/3050.Pizza Toppings Cost Analysis/README_EN.md +++ b/solution/3000-3099/3050.Pizza Toppings Cost Analysis/README_EN.md @@ -87,6 +87,8 @@ Then we use conditional join to join the table `T` three times, named as `t1`, ` +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/3000-3099/3051.Find Candidates for Data Scientist Position/README.md b/solution/3000-3099/3051.Find Candidates for Data Scientist Position/README.md index 0db82423a6f7c..9f4bc73b93034 100644 --- a/solution/3000-3099/3051.Find Candidates for Data Scientist Position/README.md +++ b/solution/3000-3099/3051.Find Candidates for Data Scientist Position/README.md @@ -84,6 +84,8 @@ Candidates 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT candidate_id diff --git a/solution/3000-3099/3051.Find Candidates for Data Scientist Position/README_EN.md b/solution/3000-3099/3051.Find Candidates for Data Scientist Position/README_EN.md index 51e76346572ab..28fd2842acd21 100644 --- a/solution/3000-3099/3051.Find Candidates for Data Scientist Position/README_EN.md +++ b/solution/3000-3099/3051.Find Candidates for Data Scientist Position/README_EN.md @@ -83,6 +83,8 @@ First, we filter out candidates who have the skills `Python`, `Tableau`, and `Po +#### MySQL + ```sql # Write your MySQL query statement below SELECT candidate_id diff --git a/solution/3000-3099/3052.Maximize Items/README.md b/solution/3000-3099/3052.Maximize Items/README.md index c65f30df36dd5..1e131c3401b91 100644 --- a/solution/3000-3099/3052.Maximize Items/README.md +++ b/solution/3000-3099/3052.Maximize Items/README.md @@ -93,6 +93,8 @@ Inventory 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/3000-3099/3052.Maximize Items/README_EN.md b/solution/3000-3099/3052.Maximize Items/README_EN.md index 75463fe1538c6..6e0df2f90172a 100644 --- a/solution/3000-3099/3052.Maximize Items/README_EN.md +++ b/solution/3000-3099/3052.Maximize Items/README_EN.md @@ -92,6 +92,8 @@ Next, we calculate the number of items of type `prime_eligible` and `not_prime` +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/3000-3099/3053.Classifying Triangles by Lengths/README.md b/solution/3000-3099/3053.Classifying Triangles by Lengths/README.md index 4ceaff2e65270..5d3aa5706ef47 100644 --- a/solution/3000-3099/3053.Classifying Triangles by Lengths/README.md +++ b/solution/3000-3099/3053.Classifying Triangles by Lengths/README.md @@ -93,6 +93,8 @@ Triangles 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/3000-3099/3053.Classifying Triangles by Lengths/README_EN.md b/solution/3000-3099/3053.Classifying Triangles by Lengths/README_EN.md index 88cc7cbe0b2c1..a6f5bbdcb2830 100644 --- a/solution/3000-3099/3053.Classifying Triangles by Lengths/README_EN.md +++ b/solution/3000-3099/3053.Classifying Triangles by Lengths/README_EN.md @@ -92,6 +92,8 @@ Otherwise, it means that the lengths of the three sides are all different, so we +#### MySQL + ```sql # Write your MySQL query statement below SELECT diff --git a/solution/3000-3099/3054.Binary Tree Nodes/README.md b/solution/3000-3099/3054.Binary Tree Nodes/README.md index 2eb86e2a28f46..d2b9c0dd479a2 100644 --- a/solution/3000-3099/3054.Binary Tree Nodes/README.md +++ b/solution/3000-3099/3054.Binary Tree Nodes/README.md @@ -91,6 +91,8 @@ Tree 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT DISTINCT diff --git a/solution/3000-3099/3054.Binary Tree Nodes/README_EN.md b/solution/3000-3099/3054.Binary Tree Nodes/README_EN.md index e70c11734b367..9493460c1ea71 100644 --- a/solution/3000-3099/3054.Binary Tree Nodes/README_EN.md +++ b/solution/3000-3099/3054.Binary Tree Nodes/README_EN.md @@ -90,6 +90,8 @@ Therefore, we use left join to join the `Tree` table twice, with the join condit +#### MySQL + ```sql # Write your MySQL query statement below SELECT DISTINCT diff --git a/solution/3000-3099/3055.Top Percentile Fraud/README.md b/solution/3000-3099/3055.Top Percentile Fraud/README.md index d52f2969e98b4..753aff3c12b47 100644 --- a/solution/3000-3099/3055.Top Percentile Fraud/README.md +++ b/solution/3000-3099/3055.Top Percentile Fraud/README.md @@ -92,6 +92,8 @@ Fraud 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/3000-3099/3055.Top Percentile Fraud/README_EN.md b/solution/3000-3099/3055.Top Percentile Fraud/README_EN.md index 82a67babb1262..c17e3c65b1f70 100644 --- a/solution/3000-3099/3055.Top Percentile Fraud/README_EN.md +++ b/solution/3000-3099/3055.Top Percentile Fraud/README_EN.md @@ -91,6 +91,8 @@ We can use the `RANK()` window function to calculate the ranking of fraud scores +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/3000-3099/3056.Snaps Analysis/README.md b/solution/3000-3099/3056.Snaps Analysis/README.md index 6ec9feb349fe7..e32fc9a99328c 100644 --- a/solution/3000-3099/3056.Snaps Analysis/README.md +++ b/solution/3000-3099/3056.Snaps Analysis/README.md @@ -117,6 +117,8 @@ Age 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -129,6 +131,8 @@ FROM GROUP BY 1; ``` +#### Python3 + ```python import pandas as pd diff --git a/solution/3000-3099/3056.Snaps Analysis/README_EN.md b/solution/3000-3099/3056.Snaps Analysis/README_EN.md index 96380e5fa8522..24c50af66ef06 100644 --- a/solution/3000-3099/3056.Snaps Analysis/README_EN.md +++ b/solution/3000-3099/3056.Snaps Analysis/README_EN.md @@ -116,6 +116,8 @@ We can perform an equi-join to connect the `Activities` table and the `Age` tabl +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -128,6 +130,8 @@ FROM GROUP BY 1; ``` +#### Python3 + ```python import pandas as pd diff --git a/solution/3000-3099/3057.Employees Project Allocation/README.md b/solution/3000-3099/3057.Employees Project Allocation/README.md index e1ef2534ab943..4434d14209e0a 100644 --- a/solution/3000-3099/3057.Employees Project Allocation/README.md +++ b/solution/3000-3099/3057.Employees Project Allocation/README.md @@ -104,6 +104,8 @@ Employees 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -127,6 +129,8 @@ WHERE workload > avg_workload ORDER BY 1, 2; ``` +#### Python3 + ```python import pandas as pd diff --git a/solution/3000-3099/3057.Employees Project Allocation/README_EN.md b/solution/3000-3099/3057.Employees Project Allocation/README_EN.md index 3035f4f71bdd7..e3b704aed634c 100644 --- a/solution/3000-3099/3057.Employees Project Allocation/README_EN.md +++ b/solution/3000-3099/3057.Employees Project Allocation/README_EN.md @@ -103,6 +103,8 @@ Then, we join the `Project` table and the `Employees` table again, and also join +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -126,6 +128,8 @@ WHERE workload > avg_workload ORDER BY 1, 2; ``` +#### Python3 + ```python import pandas as pd diff --git a/solution/3000-3099/3058.Friends With No Mutual Friends/README.md b/solution/3000-3099/3058.Friends With No Mutual Friends/README.md index 8a87c757b6ac0..ed43509f80aee 100644 --- a/solution/3000-3099/3058.Friends With No Mutual Friends/README.md +++ b/solution/3000-3099/3058.Friends With No Mutual Friends/README.md @@ -83,6 +83,8 @@ Friends 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -103,6 +105,8 @@ WHERE ORDER BY 1, 2; ``` +#### Python3 + ```python import pandas as pd diff --git a/solution/3000-3099/3058.Friends With No Mutual Friends/README_EN.md b/solution/3000-3099/3058.Friends With No Mutual Friends/README_EN.md index bc2087907f678..4001230b273b1 100644 --- a/solution/3000-3099/3058.Friends With No Mutual Friends/README_EN.md +++ b/solution/3000-3099/3058.Friends With No Mutual Friends/README_EN.md @@ -82,6 +82,8 @@ Next, we can use a subquery to find pairs of friends who do not have common frie +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -102,6 +104,8 @@ WHERE ORDER BY 1, 2; ``` +#### Python3 + ```python import pandas as pd diff --git a/solution/3000-3099/3059.Find All Unique Email Domains/README.md b/solution/3000-3099/3059.Find All Unique Email Domains/README.md index efecd73f9c43f..459305e9194d5 100644 --- a/solution/3000-3099/3059.Find All Unique Email Domains/README.md +++ b/solution/3000-3099/3059.Find All Unique Email Domains/README.md @@ -76,6 +76,8 @@ Emails 表: +#### MySQL + ```sql # Write your MySQL query statement below SELECT SUBSTRING_INDEX(email, '@', -1) AS email_domain, COUNT(1) AS count @@ -85,6 +87,8 @@ GROUP BY 1 ORDER BY 1; ``` +#### Python3 + ```python import pandas as pd diff --git a/solution/3000-3099/3059.Find All Unique Email Domains/README_EN.md b/solution/3000-3099/3059.Find All Unique Email Domains/README_EN.md index ff07312cd643d..06166dc0e661a 100644 --- a/solution/3000-3099/3059.Find All Unique Email Domains/README_EN.md +++ b/solution/3000-3099/3059.Find All Unique Email Domains/README_EN.md @@ -75,6 +75,8 @@ First, we filter out all emails ending with `.com`, then use the `SUBSTRING_INDE +#### MySQL + ```sql # Write your MySQL query statement below SELECT SUBSTRING_INDEX(email, '@', -1) AS email_domain, COUNT(1) AS count @@ -84,6 +86,8 @@ GROUP BY 1 ORDER BY 1; ``` +#### Python3 + ```python import pandas as pd diff --git a/solution/3000-3099/3060.User Activities within Time Bounds/README.md b/solution/3000-3099/3060.User Activities within Time Bounds/README.md index e37e9c60794d4..c2c21ce3301d1 100644 --- a/solution/3000-3099/3060.User Activities within Time Bounds/README.md +++ b/solution/3000-3099/3060.User Activities within Time Bounds/README.md @@ -87,6 +87,8 @@ Sessions 表: +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -106,6 +108,8 @@ FROM T WHERE TIMESTAMPDIFF(HOUR, prev_session_end, session_start) <= 12; ``` +#### Python3 + ```python import pandas as pd diff --git a/solution/3000-3099/3060.User Activities within Time Bounds/README_EN.md b/solution/3000-3099/3060.User Activities within Time Bounds/README_EN.md index 66c5ae34771cd..5137445c7d7d5 100644 --- a/solution/3000-3099/3060.User Activities within Time Bounds/README_EN.md +++ b/solution/3000-3099/3060.User Activities within Time Bounds/README_EN.md @@ -86,6 +86,8 @@ First, we use the `LAG` window function to find the end time of the previous ses +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -105,6 +107,8 @@ FROM T WHERE TIMESTAMPDIFF(HOUR, prev_session_end, session_start) <= 12; ``` +#### Python3 + ```python import pandas as pd diff --git a/solution/3000-3099/3061.Calculate Trapping Rain Water/README.md b/solution/3000-3099/3061.Calculate Trapping Rain Water/README.md index 5a1a2176f06aa..476bc6a56974d 100644 --- a/solution/3000-3099/3061.Calculate Trapping Rain Water/README.md +++ b/solution/3000-3099/3061.Calculate Trapping Rain Water/README.md @@ -82,6 +82,8 @@ Heights table: +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -96,6 +98,8 @@ SELECT SUM(LEAST(l, r) - height) AS total_trapped_water FROM T; ``` +#### Python3 + ```python import pandas as pd diff --git a/solution/3000-3099/3061.Calculate Trapping Rain Water/README_EN.md b/solution/3000-3099/3061.Calculate Trapping Rain Water/README_EN.md index 0b2b9034349f9..d4b07d43edfac 100644 --- a/solution/3000-3099/3061.Calculate Trapping Rain Water/README_EN.md +++ b/solution/3000-3099/3061.Calculate Trapping Rain Water/README_EN.md @@ -81,6 +81,8 @@ We use the window function `MAX(height) OVER (ORDER BY id)` to calculate the max +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -95,6 +97,8 @@ SELECT SUM(LEAST(l, r) - height) AS total_trapped_water FROM T; ``` +#### Python3 + ```python import pandas as pd diff --git a/solution/3000-3099/3062.Winner of the Linked List Game/README.md b/solution/3000-3099/3062.Winner of the Linked List Game/README.md index ab1ff21eae2e6..16659edbae76c 100644 --- a/solution/3000-3099/3062.Winner of the Linked List Game/README.md +++ b/solution/3000-3099/3062.Winner of the Linked List Game/README.md @@ -97,6 +97,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -119,6 +121,8 @@ class Solution: return "Tie" ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -150,6 +154,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -182,6 +188,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -211,6 +219,8 @@ func gameResult(head *ListNode) string { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/3000-3099/3062.Winner of the Linked List Game/README_EN.md b/solution/3000-3099/3062.Winner of the Linked List Game/README_EN.md index 34bafe94c0951..3105b3b09f805 100644 --- a/solution/3000-3099/3062.Winner of the Linked List Game/README_EN.md +++ b/solution/3000-3099/3062.Winner of the Linked List Game/README_EN.md @@ -107,6 +107,8 @@ The time complexity is $O(n)$, where $n$ is the length of the linked list. The s +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -129,6 +131,8 @@ class Solution: return "Tie" ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -192,6 +198,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -221,6 +229,8 @@ func gameResult(head *ListNode) string { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/3000-3099/3063.Linked List Frequency/README.md b/solution/3000-3099/3063.Linked List Frequency/README.md index 90f0b22b5430d..c7c6a39e6ba6f 100644 --- a/solution/3000-3099/3063.Linked List Frequency/README.md +++ b/solution/3000-3099/3063.Linked List Frequency/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -95,6 +97,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -148,6 +154,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -169,6 +177,8 @@ func frequenciesOfElements(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/3000-3099/3063.Linked List Frequency/README_EN.md b/solution/3000-3099/3063.Linked List Frequency/README_EN.md index cf1cc4e833e39..70f67eeb8914f 100644 --- a/solution/3000-3099/3063.Linked List Frequency/README_EN.md +++ b/solution/3000-3099/3063.Linked List Frequency/README_EN.md @@ -75,6 +75,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python # Definition for singly-linked list. # class ListNode: @@ -93,6 +95,8 @@ class Solution: return dummy.next ``` +#### Java + ```java /** * Definition for singly-linked list. @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp /** * Definition for singly-linked list. @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go /** * Definition for singly-linked list. @@ -167,6 +175,8 @@ func frequenciesOfElements(head *ListNode) *ListNode { } ``` +#### TypeScript + ```ts /** * Definition for singly-linked list. diff --git a/solution/3000-3099/3064.Guess the Number Using Bitwise Questions I/README.md b/solution/3000-3099/3064.Guess the Number Using Bitwise Questions I/README.md index a9e6e988e3ccb..7916b50c30aed 100644 --- a/solution/3000-3099/3064.Guess the Number Using Bitwise Questions I/README.md +++ b/solution/3000-3099/3064.Guess the Number Using Bitwise Questions I/README.md @@ -69,6 +69,8 @@ tags: +#### Python3 + ```python # Definition of commonSetBits API. # def commonSetBits(num: int) -> int: @@ -79,6 +81,8 @@ class Solution: return sum(1 << i for i in range(32) if commonSetBits(1 << i)) ``` +#### Java + ```java /** * Definition of commonSetBits API (defined in the parent class Problem). @@ -98,6 +102,8 @@ public class Solution extends Problem { } ``` +#### C++ + ```cpp /** * Definition of commonSetBits API. @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go /** * Definition of commonSetBits API. @@ -134,6 +142,8 @@ func findNumber() (n int) { } ``` +#### TypeScript + ```ts /** * Definition of commonSetBits API. diff --git a/solution/3000-3099/3064.Guess the Number Using Bitwise Questions I/README_EN.md b/solution/3000-3099/3064.Guess the Number Using Bitwise Questions I/README_EN.md index ed5db266ac43b..4685ae2b82c73 100644 --- a/solution/3000-3099/3064.Guess the Number Using Bitwise Questions I/README_EN.md +++ b/solution/3000-3099/3064.Guess the Number Using Bitwise Questions I/README_EN.md @@ -67,6 +67,8 @@ The time complexity is $O(\log n)$, where $n \le 2^{30}$ in this problem. The sp +#### Python3 + ```python # Definition of commonSetBits API. # def commonSetBits(num: int) -> int: @@ -77,6 +79,8 @@ class Solution: return sum(1 << i for i in range(32) if commonSetBits(1 << i)) ``` +#### Java + ```java /** * Definition of commonSetBits API (defined in the parent class Problem). @@ -96,6 +100,8 @@ public class Solution extends Problem { } ``` +#### C++ + ```cpp /** * Definition of commonSetBits API. @@ -116,6 +122,8 @@ public: }; ``` +#### Go + ```go /** * Definition of commonSetBits API. @@ -132,6 +140,8 @@ func findNumber() (n int) { } ``` +#### TypeScript + ```ts /** * Definition of commonSetBits API. diff --git a/solution/3000-3099/3065.Minimum Operations to Exceed Threshold Value I/README.md b/solution/3000-3099/3065.Minimum Operations to Exceed Threshold Value I/README.md index c1b8a9da35305..2957300171b65 100644 --- a/solution/3000-3099/3065.Minimum Operations to Exceed Threshold Value I/README.md +++ b/solution/3000-3099/3065.Minimum Operations to Exceed Threshold Value I/README.md @@ -78,12 +78,16 @@ tags: +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int], k: int) -> int: return sum(x < k for x in nums) ``` +#### Java + ```java class Solution { public int minOperations(int[] nums, int k) { @@ -98,6 +102,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int, k int) (ans int) { for _, x := range nums { @@ -124,6 +132,8 @@ func minOperations(nums []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function minOperations(nums: number[], k: number): number { return nums.filter(x => x < k).length; diff --git a/solution/3000-3099/3065.Minimum Operations to Exceed Threshold Value I/README_EN.md b/solution/3000-3099/3065.Minimum Operations to Exceed Threshold Value I/README_EN.md index 5b8efbc4eef32..bfeb9adee61f5 100644 --- a/solution/3000-3099/3065.Minimum Operations to Exceed Threshold Value I/README_EN.md +++ b/solution/3000-3099/3065.Minimum Operations to Exceed Threshold Value I/README_EN.md @@ -76,12 +76,16 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int], k: int) -> int: return sum(x < k for x in nums) ``` +#### Java + ```java class Solution { public int minOperations(int[] nums, int k) { @@ -96,6 +100,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -111,6 +117,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int, k int) (ans int) { for _, x := range nums { @@ -122,6 +130,8 @@ func minOperations(nums []int, k int) (ans int) { } ``` +#### TypeScript + ```ts function minOperations(nums: number[], k: number): number { return nums.filter(x => x < k).length; diff --git a/solution/3000-3099/3066.Minimum Operations to Exceed Threshold Value II/README.md b/solution/3000-3099/3066.Minimum Operations to Exceed Threshold Value II/README.md index 3fa7bf120a4b1..9e4c56847bf99 100644 --- a/solution/3000-3099/3066.Minimum Operations to Exceed Threshold Value II/README.md +++ b/solution/3000-3099/3066.Minimum Operations to Exceed Threshold Value II/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int], k: int) -> int: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minOperations(int[] nums, int k) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -137,6 +143,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int, k int) (ans int) { pq := &hp{nums} @@ -163,6 +171,8 @@ func (h *hp) Push(x interface{}) { } ``` +#### TypeScript + ```ts function minOperations(nums: number[], k: number): number { const pq = new MinPriorityQueue(); diff --git a/solution/3000-3099/3066.Minimum Operations to Exceed Threshold Value II/README_EN.md b/solution/3000-3099/3066.Minimum Operations to Exceed Threshold Value II/README_EN.md index 891349819f8ce..d1db632834946 100644 --- a/solution/3000-3099/3066.Minimum Operations to Exceed Threshold Value II/README_EN.md +++ b/solution/3000-3099/3066.Minimum Operations to Exceed Threshold Value II/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$, +#### Python3 + ```python class Solution: def minOperations(self, nums: List[int], k: int) -> int: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minOperations(int[] nums, int k) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -135,6 +141,8 @@ public: }; ``` +#### Go + ```go func minOperations(nums []int, k int) (ans int) { pq := &hp{nums} @@ -161,6 +169,8 @@ func (h *hp) Push(x interface{}) { } ``` +#### TypeScript + ```ts function minOperations(nums: number[], k: number): number { const pq = new MinPriorityQueue(); diff --git a/solution/3000-3099/3067.Count Pairs of Connectable Servers in a Weighted Tree Network/README.md b/solution/3000-3099/3067.Count Pairs of Connectable Servers in a Weighted Tree Network/README.md index bc3bf9fb9e3fb..f7be7290e8d8a 100644 --- a/solution/3000-3099/3067.Count Pairs of Connectable Servers in a Weighted Tree Network/README.md +++ b/solution/3000-3099/3067.Count Pairs of Connectable Servers in a Weighted Tree Network/README.md @@ -91,6 +91,8 @@ tags: +#### Python3 + ```python class Solution: def countPairsOfConnectableServers( @@ -118,6 +120,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int signalSpeed; @@ -159,6 +163,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go func countPairsOfConnectableServers(edges [][]int, signalSpeed int) []int { n := len(edges) + 1 @@ -231,6 +239,8 @@ func countPairsOfConnectableServers(edges [][]int, signalSpeed int) []int { } ``` +#### TypeScript + ```ts function countPairsOfConnectableServers(edges: number[][], signalSpeed: number): number[] { const n = edges.length + 1; diff --git a/solution/3000-3099/3067.Count Pairs of Connectable Servers in a Weighted Tree Network/README_EN.md b/solution/3000-3099/3067.Count Pairs of Connectable Servers in a Weighted Tree Network/README_EN.md index 3923de9884984..745f64c7e23f2 100644 --- a/solution/3000-3099/3067.Count Pairs of Connectable Servers in a Weighted Tree Network/README_EN.md +++ b/solution/3000-3099/3067.Count Pairs of Connectable Servers in a Weighted Tree Network/README_EN.md @@ -85,6 +85,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$, where $n$ i +#### Python3 + ```python class Solution: def countPairsOfConnectableServers( @@ -112,6 +114,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private int signalSpeed; @@ -153,6 +157,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -187,6 +193,8 @@ public: }; ``` +#### Go + ```go func countPairsOfConnectableServers(edges [][]int, signalSpeed int) []int { n := len(edges) + 1 @@ -225,6 +233,8 @@ func countPairsOfConnectableServers(edges [][]int, signalSpeed int) []int { } ``` +#### TypeScript + ```ts function countPairsOfConnectableServers(edges: number[][], signalSpeed: number): number[] { const n = edges.length + 1; diff --git a/solution/3000-3099/3068.Find the Maximum Sum of Node Values/README.md b/solution/3000-3099/3068.Find the Maximum Sum of Node Values/README.md index d9abb87719f60..d4276dd9abe95 100644 --- a/solution/3000-3099/3068.Find the Maximum Sum of Node Values/README.md +++ b/solution/3000-3099/3068.Find the Maximum Sum of Node Values/README.md @@ -102,18 +102,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/3000-3099/3068.Find the Maximum Sum of Node Values/README_EN.md b/solution/3000-3099/3068.Find the Maximum Sum of Node Values/README_EN.md index 2e265c13e0173..9e04d8750514d 100644 --- a/solution/3000-3099/3068.Find the Maximum Sum of Node Values/README_EN.md +++ b/solution/3000-3099/3068.Find the Maximum Sum of Node Values/README_EN.md @@ -94,18 +94,26 @@ It can be shown that 9 is the maximum achievable sum of values. +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/3000-3099/3069.Distribute Elements Into Two Arrays I/README.md b/solution/3000-3099/3069.Distribute Elements Into Two Arrays I/README.md index 2f58a273142e7..479cb95eabaf6 100644 --- a/solution/3000-3099/3069.Distribute Elements Into Two Arrays I/README.md +++ b/solution/3000-3099/3069.Distribute Elements Into Two Arrays I/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python class Solution: def resultArray(self, nums: List[int]) -> List[int]: @@ -97,6 +99,8 @@ class Solution: return arr1 + arr2 ``` +#### Java + ```java class Solution { public int[] resultArray(int[] nums) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go func resultArray(nums []int) []int { arr1 := []int{nums[0]} @@ -156,6 +164,8 @@ func resultArray(nums []int) []int { } ``` +#### TypeScript + ```ts function resultArray(nums: number[]): number[] { const arr1: number[] = [nums[0]]; diff --git a/solution/3000-3099/3069.Distribute Elements Into Two Arrays I/README_EN.md b/solution/3000-3099/3069.Distribute Elements Into Two Arrays I/README_EN.md index b10aa217f9cb5..f71369f46dca8 100644 --- a/solution/3000-3099/3069.Distribute Elements Into Two Arrays I/README_EN.md +++ b/solution/3000-3099/3069.Distribute Elements Into Two Arrays I/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python class Solution: def resultArray(self, nums: List[int]) -> List[int]: @@ -95,6 +97,8 @@ class Solution: return arr1 + arr2 ``` +#### Java + ```java class Solution { public int[] resultArray(int[] nums) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -139,6 +145,8 @@ public: }; ``` +#### Go + ```go func resultArray(nums []int) []int { arr1 := []int{nums[0]} @@ -154,6 +162,8 @@ func resultArray(nums []int) []int { } ``` +#### TypeScript + ```ts function resultArray(nums: number[]): number[] { const arr1: number[] = [nums[0]]; diff --git a/solution/3000-3099/3070.Count Submatrices with Top-Left Element and Sum Less Than k/README.md b/solution/3000-3099/3070.Count Submatrices with Top-Left Element and Sum Less Than k/README.md index 357b80cc20e78..d7509bbf81ba2 100644 --- a/solution/3000-3099/3070.Count Submatrices with Top-Left Element and Sum Less Than k/README.md +++ b/solution/3000-3099/3070.Count Submatrices with Top-Left Element and Sum Less Than k/README.md @@ -73,6 +73,8 @@ $$ +#### Python3 + ```python class Solution: def countSubmatrices(self, grid: List[List[int]], k: int) -> int: @@ -85,6 +87,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countSubmatrices(int[][] grid, int k) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -125,6 +131,8 @@ public: }; ``` +#### Go + ```go func countSubmatrices(grid [][]int, k int) (ans int) { s := make([][]int, len(grid)+1) @@ -143,6 +151,8 @@ func countSubmatrices(grid [][]int, k int) (ans int) { } ``` +#### TypeScript + ```ts function countSubmatrices(grid: number[][], k: number): number { const m = grid.length; diff --git a/solution/3000-3099/3070.Count Submatrices with Top-Left Element and Sum Less Than k/README_EN.md b/solution/3000-3099/3070.Count Submatrices with Top-Left Element and Sum Less Than k/README_EN.md index d340c09b1f819..f3b1108bd9132 100644 --- a/solution/3000-3099/3070.Count Submatrices with Top-Left Element and Sum Less Than k/README_EN.md +++ b/solution/3000-3099/3070.Count Submatrices with Top-Left Element and Sum Less Than k/README_EN.md @@ -71,6 +71,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def countSubmatrices(self, grid: List[List[int]], k: int) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int countSubmatrices(int[][] grid, int k) { @@ -102,6 +106,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -123,6 +129,8 @@ public: }; ``` +#### Go + ```go func countSubmatrices(grid [][]int, k int) (ans int) { s := make([][]int, len(grid)+1) @@ -141,6 +149,8 @@ func countSubmatrices(grid [][]int, k int) (ans int) { } ``` +#### TypeScript + ```ts function countSubmatrices(grid: number[][], k: number): number { const m = grid.length; diff --git a/solution/3000-3099/3071.Minimum Operations to Write the Letter Y on a Grid/README.md b/solution/3000-3099/3071.Minimum Operations to Write the Letter Y on a Grid/README.md index ad1df453fa0a9..5ac34e5f5be7a 100644 --- a/solution/3000-3099/3071.Minimum Operations to Write the Letter Y on a Grid/README.md +++ b/solution/3000-3099/3071.Minimum Operations to Write the Letter Y on a Grid/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def minimumOperationsToWriteY(self, grid: List[List[int]]) -> int: @@ -106,6 +108,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public int minimumOperationsToWriteY(int[][] grid) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go func minimumOperationsToWriteY(grid [][]int) int { n := len(grid) @@ -198,6 +206,8 @@ func minimumOperationsToWriteY(grid [][]int) int { } ``` +#### TypeScript + ```ts function minimumOperationsToWriteY(grid: number[][]): number { const n = grid.length; diff --git a/solution/3000-3099/3071.Minimum Operations to Write the Letter Y on a Grid/README_EN.md b/solution/3000-3099/3071.Minimum Operations to Write the Letter Y on a Grid/README_EN.md index 1b9ef18e9ae0f..33afc4b7e5441 100644 --- a/solution/3000-3099/3071.Minimum Operations to Write the Letter Y on a Grid/README_EN.md +++ b/solution/3000-3099/3071.Minimum Operations to Write the Letter Y on a Grid/README_EN.md @@ -83,6 +83,8 @@ The time complexity is $O(n^2)$, where $n$ is the size of the matrix. The space +#### Python3 + ```python class Solution: def minimumOperationsToWriteY(self, grid: List[List[int]]) -> int: @@ -103,6 +105,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public int minimumOperationsToWriteY(int[][] grid) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -166,6 +172,8 @@ public: }; ``` +#### Go + ```go func minimumOperationsToWriteY(grid [][]int) int { n := len(grid) @@ -195,6 +203,8 @@ func minimumOperationsToWriteY(grid [][]int) int { } ``` +#### TypeScript + ```ts function minimumOperationsToWriteY(grid: number[][]): number { const n = grid.length; diff --git a/solution/3000-3099/3072.Distribute Elements Into Two Arrays II/README.md b/solution/3000-3099/3072.Distribute Elements Into Two Arrays II/README.md index 4c446d1d35ae7..19799cab9aef9 100644 --- a/solution/3000-3099/3072.Distribute Elements Into Two Arrays II/README.md +++ b/solution/3000-3099/3072.Distribute Elements Into Two Arrays II/README.md @@ -99,6 +99,8 @@ tags: +#### Python3 + ```python class BinaryIndexedTree: __slots__ = "n", "c" @@ -149,6 +151,8 @@ class Solution: return arr1 + arr2 ``` +#### Python3 + ```python from sortedcontainers import SortedList @@ -177,6 +181,8 @@ class Solution: return arr1 + arr2 ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -242,6 +248,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { private: @@ -304,6 +312,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -362,6 +372,8 @@ func resultArray(nums []int) []int { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; @@ -430,6 +442,8 @@ function resultArray(nums: number[]): number[] { } ``` +#### PHP + ```php class Solution { /** diff --git a/solution/3000-3099/3072.Distribute Elements Into Two Arrays II/README_EN.md b/solution/3000-3099/3072.Distribute Elements Into Two Arrays II/README_EN.md index 2264c8b20f7a1..4f45a20cf1aac 100644 --- a/solution/3000-3099/3072.Distribute Elements Into Two Arrays II/README_EN.md +++ b/solution/3000-3099/3072.Distribute Elements Into Two Arrays II/README_EN.md @@ -97,6 +97,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$, +#### Python3 + ```python class BinaryIndexedTree: __slots__ = "n", "c" @@ -147,6 +149,8 @@ class Solution: return arr1 + arr2 ``` +#### Python3 + ```python from sortedcontainers import SortedList @@ -175,6 +179,8 @@ class Solution: return arr1 + arr2 ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -240,6 +246,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { private: @@ -302,6 +310,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -360,6 +370,8 @@ func resultArray(nums []int) []int { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; diff --git a/solution/3000-3099/3073.Maximum Increasing Triplet Value/README.md b/solution/3000-3099/3073.Maximum Increasing Triplet Value/README.md index e9ce90f33b061..3d5badf69696f 100644 --- a/solution/3000-3099/3073.Maximum Increasing Triplet Value/README.md +++ b/solution/3000-3099/3073.Maximum Increasing Triplet Value/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python from sortedcontainers import SortedList @@ -93,6 +95,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumTripletValue(int[] nums) { @@ -119,6 +123,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func maximumTripletValue(nums []int) (ans int) { n := len(nums) @@ -169,6 +177,8 @@ func maximumTripletValue(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function maximumTripletValue(nums: number[]): number { const n = nums.length; diff --git a/solution/3000-3099/3073.Maximum Increasing Triplet Value/README_EN.md b/solution/3000-3099/3073.Maximum Increasing Triplet Value/README_EN.md index e8bcbc3993d86..99eaf81e6d9a9 100644 --- a/solution/3000-3099/3073.Maximum Increasing Triplet Value/README_EN.md +++ b/solution/3000-3099/3073.Maximum Increasing Triplet Value/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$, +#### Python3 + ```python from sortedcontainers import SortedList @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumTripletValue(int[] nums) { @@ -124,6 +128,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func maximumTripletValue(nums []int) (ans int) { n := len(nums) @@ -174,6 +182,8 @@ func maximumTripletValue(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function maximumTripletValue(nums: number[]): number { const n = nums.length; diff --git a/solution/3000-3099/3074.Apple Redistribution into Boxes/README.md b/solution/3000-3099/3074.Apple Redistribution into Boxes/README.md index af5fcbcb5e102..7590c1bbbe302 100644 --- a/solution/3000-3099/3074.Apple Redistribution into Boxes/README.md +++ b/solution/3000-3099/3074.Apple Redistribution into Boxes/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def minimumBoxes(self, apple: List[int], capacity: List[int]) -> int: @@ -83,6 +85,8 @@ class Solution: return i ``` +#### Java + ```java class Solution { public int minimumBoxes(int[] apple, int[] capacity) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -117,6 +123,8 @@ public: }; ``` +#### Go + ```go func minimumBoxes(apple []int, capacity []int) int { sort.Ints(capacity) @@ -133,6 +141,8 @@ func minimumBoxes(apple []int, capacity []int) int { } ``` +#### TypeScript + ```ts function minimumBoxes(apple: number[], capacity: number[]): number { capacity.sort((a, b) => b - a); diff --git a/solution/3000-3099/3074.Apple Redistribution into Boxes/README_EN.md b/solution/3000-3099/3074.Apple Redistribution into Boxes/README_EN.md index a50006bd0f221..befb471b5cafc 100644 --- a/solution/3000-3099/3074.Apple Redistribution into Boxes/README_EN.md +++ b/solution/3000-3099/3074.Apple Redistribution into Boxes/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(m \times \log m + n)$ and the space complexity is $O(\ +#### Python3 + ```python class Solution: def minimumBoxes(self, apple: List[int], capacity: List[int]) -> int: @@ -81,6 +83,8 @@ class Solution: return i ``` +#### Java + ```java class Solution { public int minimumBoxes(int[] apple, int[] capacity) { @@ -99,6 +103,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func minimumBoxes(apple []int, capacity []int) int { sort.Ints(capacity) @@ -131,6 +139,8 @@ func minimumBoxes(apple []int, capacity []int) int { } ``` +#### TypeScript + ```ts function minimumBoxes(apple: number[], capacity: number[]): number { capacity.sort((a, b) => b - a); diff --git a/solution/3000-3099/3075.Maximize Happiness of Selected Children/README.md b/solution/3000-3099/3075.Maximize Happiness of Selected Children/README.md index 9593f7b1e727a..4a4f8e4c362ea 100644 --- a/solution/3000-3099/3075.Maximize Happiness of Selected Children/README.md +++ b/solution/3000-3099/3075.Maximize Happiness of Selected Children/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def maximumHappinessSum(self, happiness: List[int], k: int) -> int: @@ -97,6 +99,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maximumHappinessSum(int[] happiness, int k) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func maximumHappinessSum(happiness []int, k int) (ans int64) { sort.Ints(happiness) @@ -137,6 +145,8 @@ func maximumHappinessSum(happiness []int, k int) (ans int64) { } ``` +#### TypeScript + ```ts function maximumHappinessSum(happiness: number[], k: number): number { happiness.sort((a, b) => b - a); diff --git a/solution/3000-3099/3075.Maximize Happiness of Selected Children/README_EN.md b/solution/3000-3099/3075.Maximize Happiness of Selected Children/README_EN.md index 2ce45f0c27015..eea37e7e640d1 100644 --- a/solution/3000-3099/3075.Maximize Happiness of Selected Children/README_EN.md +++ b/solution/3000-3099/3075.Maximize Happiness of Selected Children/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n \times \log n + k)$ and the space complexity is $O(\ +#### Python3 + ```python class Solution: def maximumHappinessSum(self, happiness: List[int], k: int) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long maximumHappinessSum(int[] happiness, int k) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func maximumHappinessSum(happiness []int, k int) (ans int64) { sort.Ints(happiness) @@ -135,6 +143,8 @@ func maximumHappinessSum(happiness []int, k int) (ans int64) { } ``` +#### TypeScript + ```ts function maximumHappinessSum(happiness: number[], k: number): number { happiness.sort((a, b) => b - a); diff --git a/solution/3000-3099/3076.Shortest Uncommon Substring in an Array/README.md b/solution/3000-3099/3076.Shortest Uncommon Substring in an Array/README.md index 7f64d3fd0245d..09830e7e955d6 100644 --- a/solution/3000-3099/3076.Shortest Uncommon Substring in an Array/README.md +++ b/solution/3000-3099/3076.Shortest Uncommon Substring in an Array/README.md @@ -83,6 +83,8 @@ tags: +#### Python3 + ```python class Solution: def shortestSubstrings(self, arr: List[str]) -> List[str]: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String[] shortestSubstrings(String[] arr) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -160,6 +166,8 @@ public: }; ``` +#### Go + ```go func shortestSubstrings(arr []string) []string { ans := make([]string, len(arr)) @@ -187,6 +195,8 @@ func shortestSubstrings(arr []string) []string { } ``` +#### TypeScript + ```ts function shortestSubstrings(arr: string[]): string[] { const n: number = arr.length; diff --git a/solution/3000-3099/3076.Shortest Uncommon Substring in an Array/README_EN.md b/solution/3000-3099/3076.Shortest Uncommon Substring in an Array/README_EN.md index 2d6c87246d2b9..2c15e7a9893d3 100644 --- a/solution/3000-3099/3076.Shortest Uncommon Substring in an Array/README_EN.md +++ b/solution/3000-3099/3076.Shortest Uncommon Substring in an Array/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(n^2 \times m^4)$, and the space complexity is $O(m)$. +#### Python3 + ```python class Solution: def shortestSubstrings(self, arr: List[str]) -> List[str]: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public String[] shortestSubstrings(String[] arr) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func shortestSubstrings(arr []string) []string { ans := make([]string, len(arr)) @@ -185,6 +193,8 @@ func shortestSubstrings(arr []string) []string { } ``` +#### TypeScript + ```ts function shortestSubstrings(arr: string[]): string[] { const n: number = arr.length; diff --git a/solution/3000-3099/3077.Maximum Strength of K Disjoint Subarrays/README.md b/solution/3000-3099/3077.Maximum Strength of K Disjoint Subarrays/README.md index bedaeaefa2b3d..97131a1041aea 100644 --- a/solution/3000-3099/3077.Maximum Strength of K Disjoint Subarrays/README.md +++ b/solution/3000-3099/3077.Maximum Strength of K Disjoint Subarrays/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def maximumStrength(self, nums: List[int], k: int) -> int: @@ -110,6 +112,8 @@ class Solution: return max(f[n][k]) ``` +#### Java + ```java class Solution { public long maximumStrength(int[] nums, int k) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -165,6 +171,8 @@ public: }; ``` +#### Go + ```go func maximumStrength(nums []int, k int) int64 { n := len(nums) @@ -197,6 +205,8 @@ func maximumStrength(nums []int, k int) int64 { } ``` +#### TypeScript + ```ts function maximumStrength(nums: number[], k: number): number { const n: number = nums.length; diff --git a/solution/3000-3099/3077.Maximum Strength of K Disjoint Subarrays/README_EN.md b/solution/3000-3099/3077.Maximum Strength of K Disjoint Subarrays/README_EN.md index 7e7283fdb3132..d8da4ba7f9d0f 100644 --- a/solution/3000-3099/3077.Maximum Strength of K Disjoint Subarrays/README_EN.md +++ b/solution/3000-3099/3077.Maximum Strength of K Disjoint Subarrays/README_EN.md @@ -90,6 +90,8 @@ The time complexity is $O(n \times k)$, and the space complexity is $O(n \times +#### Python3 + ```python class Solution: def maximumStrength(self, nums: List[int], k: int) -> int: @@ -108,6 +110,8 @@ class Solution: return max(f[n][k]) ``` +#### Java + ```java class Solution { public long maximumStrength(int[] nums, int k) { @@ -137,6 +141,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func maximumStrength(nums []int, k int) int64 { n := len(nums) @@ -195,6 +203,8 @@ func maximumStrength(nums []int, k int) int64 { } ``` +#### TypeScript + ```ts function maximumStrength(nums: number[], k: number): number { const n: number = nums.length; diff --git a/solution/3000-3099/3078.Match Alphanumerical Pattern in Matrix I/README.md b/solution/3000-3099/3078.Match Alphanumerical Pattern in Matrix I/README.md index 34f412c90abc8..3e64175b8232c 100644 --- a/solution/3000-3099/3078.Match Alphanumerical Pattern in Matrix I/README.md +++ b/solution/3000-3099/3078.Match Alphanumerical Pattern in Matrix I/README.md @@ -197,6 +197,8 @@ tags: +#### Python3 + ```python class Solution: def findPattern(self, board: List[List[int]], pattern: List[str]) -> List[int]: @@ -227,6 +229,8 @@ class Solution: return [-1, -1] ``` +#### Java + ```java class Solution { public int[] findPattern(int[][] board, String[] pattern) { @@ -273,6 +277,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -317,6 +323,8 @@ public: }; ``` +#### Go + ```go func findPattern(board [][]int, pattern []string) []int { m, n := len(board), len(board[0]) @@ -358,6 +366,8 @@ func findPattern(board [][]int, pattern []string) []int { } ``` +#### TypeScript + ```ts function findPattern(board: number[][], pattern: string[]): number[] { const m: number = board.length; diff --git a/solution/3000-3099/3078.Match Alphanumerical Pattern in Matrix I/README_EN.md b/solution/3000-3099/3078.Match Alphanumerical Pattern in Matrix I/README_EN.md index 559091f33919c..8adcc88cc0b71 100644 --- a/solution/3000-3099/3078.Match Alphanumerical Pattern in Matrix I/README_EN.md +++ b/solution/3000-3099/3078.Match Alphanumerical Pattern in Matrix I/README_EN.md @@ -195,6 +195,8 @@ The time complexity is $O(m \times n \times r \times c)$, where $m$ and $n$ are +#### Python3 + ```python class Solution: def findPattern(self, board: List[List[int]], pattern: List[str]) -> List[int]: @@ -225,6 +227,8 @@ class Solution: return [-1, -1] ``` +#### Java + ```java class Solution { public int[] findPattern(int[][] board, String[] pattern) { @@ -271,6 +275,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -315,6 +321,8 @@ public: }; ``` +#### Go + ```go func findPattern(board [][]int, pattern []string) []int { m, n := len(board), len(board[0]) @@ -356,6 +364,8 @@ func findPattern(board [][]int, pattern []string) []int { } ``` +#### TypeScript + ```ts function findPattern(board: number[][], pattern: string[]): number[] { const m: number = board.length; diff --git a/solution/3000-3099/3079.Find the Sum of Encrypted Integers/README.md b/solution/3000-3099/3079.Find the Sum of Encrypted Integers/README.md index 01fb4d8464ede..6e9d50a503b3f 100644 --- a/solution/3000-3099/3079.Find the Sum of Encrypted Integers/README.md +++ b/solution/3000-3099/3079.Find the Sum of Encrypted Integers/README.md @@ -70,6 +70,8 @@ tags: +#### Python3 + ```python class Solution: def sumOfEncryptedInt(self, nums: List[int]) -> int: @@ -84,6 +86,8 @@ class Solution: return sum(encrypt(x) for x in nums) ``` +#### Java + ```java class Solution { public int sumOfEncryptedInt(int[] nums) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func sumOfEncryptedInt(nums []int) (ans int) { encrypt := func(x int) int { @@ -143,6 +151,8 @@ func sumOfEncryptedInt(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function sumOfEncryptedInt(nums: number[]): number { const encrypt = (x: number): number => { diff --git a/solution/3000-3099/3079.Find the Sum of Encrypted Integers/README_EN.md b/solution/3000-3099/3079.Find the Sum of Encrypted Integers/README_EN.md index 76fae6808bed0..1120eaf2deab9 100644 --- a/solution/3000-3099/3079.Find the Sum of Encrypted Integers/README_EN.md +++ b/solution/3000-3099/3079.Find the Sum of Encrypted Integers/README_EN.md @@ -68,6 +68,8 @@ The time complexity is $O(n \times \log M)$, where $n$ is the length of the arra +#### Python3 + ```python class Solution: def sumOfEncryptedInt(self, nums: List[int]) -> int: @@ -82,6 +84,8 @@ class Solution: return sum(encrypt(x) for x in nums) ``` +#### Java + ```java class Solution { public int sumOfEncryptedInt(int[] nums) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func sumOfEncryptedInt(nums []int) (ans int) { encrypt := func(x int) int { @@ -141,6 +149,8 @@ func sumOfEncryptedInt(nums []int) (ans int) { } ``` +#### TypeScript + ```ts function sumOfEncryptedInt(nums: number[]): number { const encrypt = (x: number): number => { diff --git a/solution/3000-3099/3080.Mark Elements on Array by Performing Queries/README.md b/solution/3000-3099/3080.Mark Elements on Array by Performing Queries/README.md index 0b73e72d43c38..5badd4dd7b116 100644 --- a/solution/3000-3099/3080.Mark Elements on Array by Performing Queries/README.md +++ b/solution/3000-3099/3080.Mark Elements on Array by Performing Queries/README.md @@ -100,6 +100,8 @@ tags: +#### Python3 + ```python class Solution: def unmarkedSumArray(self, nums: List[int], queries: List[List[int]]) -> List[int]: @@ -123,6 +125,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long[] unmarkedSumArray(int[] nums, int[][] queries) { @@ -156,6 +160,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -190,6 +196,8 @@ public: }; ``` +#### Go + ```go func unmarkedSumArray(nums []int, queries [][]int) []int64 { n := len(nums) @@ -229,6 +237,8 @@ func unmarkedSumArray(nums []int, queries [][]int) []int64 { } ``` +#### TypeScript + ```ts function unmarkedSumArray(nums: number[], queries: number[][]): number[] { const n = nums.length; diff --git a/solution/3000-3099/3080.Mark Elements on Array by Performing Queries/README_EN.md b/solution/3000-3099/3080.Mark Elements on Array by Performing Queries/README_EN.md index 6e422e9c9cd37..43754b79457f3 100644 --- a/solution/3000-3099/3080.Mark Elements on Array by Performing Queries/README_EN.md +++ b/solution/3000-3099/3080.Mark Elements on Array by Performing Queries/README_EN.md @@ -98,6 +98,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def unmarkedSumArray(self, nums: List[int], queries: List[List[int]]) -> List[int]: @@ -121,6 +123,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long[] unmarkedSumArray(int[] nums, int[][] queries) { @@ -154,6 +158,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -188,6 +194,8 @@ public: }; ``` +#### Go + ```go func unmarkedSumArray(nums []int, queries [][]int) []int64 { n := len(nums) @@ -227,6 +235,8 @@ func unmarkedSumArray(nums []int, queries [][]int) []int64 { } ``` +#### TypeScript + ```ts function unmarkedSumArray(nums: number[], queries: number[][]): number[] { const n = nums.length; diff --git a/solution/3000-3099/3081.Replace Question Marks in String to Minimize Its Value/README.md b/solution/3000-3099/3081.Replace Question Marks in String to Minimize Its Value/README.md index 4d7a6d5cabde5..4788f93f47e24 100644 --- a/solution/3000-3099/3081.Replace Question Marks in String to Minimize Its Value/README.md +++ b/solution/3000-3099/3081.Replace Question Marks in String to Minimize Its Value/README.md @@ -101,6 +101,8 @@ tags: +#### Python3 + ```python class Solution: def minimizeStringValue(self, s: str) -> str: @@ -122,6 +124,8 @@ class Solution: return "".join(cs) ``` +#### Java + ```java class Solution { public String minimizeStringValue(String s) { @@ -159,6 +163,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -195,6 +201,8 @@ public: }; ``` +#### Go + ```go func minimizeStringValue(s string) string { cnt := [26]int{} diff --git a/solution/3000-3099/3081.Replace Question Marks in String to Minimize Its Value/README_EN.md b/solution/3000-3099/3081.Replace Question Marks in String to Minimize Its Value/README_EN.md index 141da1b19ecea..9521c6a934136 100644 --- a/solution/3000-3099/3081.Replace Question Marks in String to Minimize Its Value/README_EN.md +++ b/solution/3000-3099/3081.Replace Question Marks in String to Minimize Its Value/README_EN.md @@ -99,6 +99,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def minimizeStringValue(self, s: str) -> str: @@ -120,6 +122,8 @@ class Solution: return "".join(cs) ``` +#### Java + ```java class Solution { public String minimizeStringValue(String s) { @@ -157,6 +161,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -193,6 +199,8 @@ public: }; ``` +#### Go + ```go func minimizeStringValue(s string) string { cnt := [26]int{} diff --git a/solution/3000-3099/3082.Find the Sum of the Power of All Subsequences/README.md b/solution/3000-3099/3082.Find the Sum of the Power of All Subsequences/README.md index 1f392b7afbbae..54cdb0646eff4 100644 --- a/solution/3000-3099/3082.Find the Sum of the Power of All Subsequences/README.md +++ b/solution/3000-3099/3082.Find the Sum of the Power of All Subsequences/README.md @@ -101,18 +101,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/3000-3099/3082.Find the Sum of the Power of All Subsequences/README_EN.md b/solution/3000-3099/3082.Find the Sum of the Power of All Subsequences/README_EN.md index 80f20b45c9be1..0069c359275d9 100644 --- a/solution/3000-3099/3082.Find the Sum of the Power of All Subsequences/README_EN.md +++ b/solution/3000-3099/3082.Find the Sum of the Power of All Subsequences/README_EN.md @@ -99,18 +99,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/3000-3099/3083.Existence of a Substring in a String and Its Reverse/README.md b/solution/3000-3099/3083.Existence of a Substring in a String and Its Reverse/README.md index d629dcd99cda1..275c85c5d9064 100644 --- a/solution/3000-3099/3083.Existence of a Substring in a String and Its Reverse/README.md +++ b/solution/3000-3099/3083.Existence of a Substring in a String and Its Reverse/README.md @@ -80,6 +80,8 @@ tags: +#### Python3 + ```python class Solution: def isSubstringPresent(self, s: str) -> bool: @@ -87,6 +89,8 @@ class Solution: return any((a, b) in st for a, b in pairwise(s)) ``` +#### Java + ```java class Solution { public boolean isSubstringPresent(String s) { @@ -105,6 +109,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func isSubstringPresent(s string) bool { st := [26][26]bool{} @@ -139,6 +147,8 @@ func isSubstringPresent(s string) bool { } ``` +#### TypeScript + ```ts function isSubstringPresent(s: string): boolean { const st: boolean[][] = Array.from({ length: 26 }, () => Array(26).fill(false)); diff --git a/solution/3000-3099/3083.Existence of a Substring in a String and Its Reverse/README_EN.md b/solution/3000-3099/3083.Existence of a Substring in a String and Its Reverse/README_EN.md index ce059d8362dde..3ee967bb8a9e1 100644 --- a/solution/3000-3099/3083.Existence of a Substring in a String and Its Reverse/README_EN.md +++ b/solution/3000-3099/3083.Existence of a Substring in a String and Its Reverse/README_EN.md @@ -78,6 +78,8 @@ The time complexity is $O(n)$ and the space complexity is $O(|\Sigma|^2)$. Here, +#### Python3 + ```python class Solution: def isSubstringPresent(self, s: str) -> bool: @@ -85,6 +87,8 @@ class Solution: return any((a, b) in st for a, b in pairwise(s)) ``` +#### Java + ```java class Solution { public boolean isSubstringPresent(String s) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func isSubstringPresent(s string) bool { st := [26][26]bool{} @@ -137,6 +145,8 @@ func isSubstringPresent(s string) bool { } ``` +#### TypeScript + ```ts function isSubstringPresent(s: string): boolean { const st: boolean[][] = Array.from({ length: 26 }, () => Array(26).fill(false)); diff --git a/solution/3000-3099/3084.Count Substrings Starting and Ending with Given Character/README.md b/solution/3000-3099/3084.Count Substrings Starting and Ending with Given Character/README.md index d1ade8ed245f4..a4b82baaa0c02 100644 --- a/solution/3000-3099/3084.Count Substrings Starting and Ending with Given Character/README.md +++ b/solution/3000-3099/3084.Count Substrings Starting and Ending with Given Character/README.md @@ -71,6 +71,8 @@ tags: +#### Python3 + ```python class Solution: def countSubstrings(self, s: str, c: str) -> int: @@ -78,6 +80,8 @@ class Solution: return cnt + cnt * (cnt - 1) // 2 ``` +#### Java + ```java class Solution { public long countSubstrings(String s, char c) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -97,6 +103,8 @@ public: }; ``` +#### Go + ```go func countSubstrings(s string, c byte) int64 { cnt := int64(strings.Count(s, string(c))) @@ -104,6 +112,8 @@ func countSubstrings(s string, c byte) int64 { } ``` +#### TypeScript + ```ts function countSubstrings(s: string, c: string): number { const cnt = s.split('').filter(ch => ch === c).length; diff --git a/solution/3000-3099/3084.Count Substrings Starting and Ending with Given Character/README_EN.md b/solution/3000-3099/3084.Count Substrings Starting and Ending with Given Character/README_EN.md index d0921da39061f..8e1c5dee917c4 100644 --- a/solution/3000-3099/3084.Count Substrings Starting and Ending with Given Character/README_EN.md +++ b/solution/3000-3099/3084.Count Substrings Starting and Ending with Given Character/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string $s$. The sp +#### Python3 + ```python class Solution: def countSubstrings(self, s: str, c: str) -> int: @@ -76,6 +78,8 @@ class Solution: return cnt + cnt * (cnt - 1) // 2 ``` +#### Java + ```java class Solution { public long countSubstrings(String s, char c) { @@ -85,6 +89,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -95,6 +101,8 @@ public: }; ``` +#### Go + ```go func countSubstrings(s string, c byte) int64 { cnt := int64(strings.Count(s, string(c))) @@ -102,6 +110,8 @@ func countSubstrings(s string, c byte) int64 { } ``` +#### TypeScript + ```ts function countSubstrings(s: string, c: string): number { const cnt = s.split('').filter(ch => ch === c).length; diff --git a/solution/3000-3099/3085.Minimum Deletions to Make String K-Special/README.md b/solution/3000-3099/3085.Minimum Deletions to Make String K-Special/README.md index 9371f7d87493c..225b0183637ec 100644 --- a/solution/3000-3099/3085.Minimum Deletions to Make String K-Special/README.md +++ b/solution/3000-3099/3085.Minimum Deletions to Make String K-Special/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def minimumDeletions(self, word: str, k: int) -> int: @@ -108,6 +110,8 @@ class Solution: return min(f(v) for v in range(len(word) + 1)) ``` +#### Java + ```java class Solution { private List nums = new ArrayList<>(); @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -179,6 +185,8 @@ public: }; ``` +#### Go + ```go func minimumDeletions(word string, k int) int { freq := [26]int{} diff --git a/solution/3000-3099/3085.Minimum Deletions to Make String K-Special/README_EN.md b/solution/3000-3099/3085.Minimum Deletions to Make String K-Special/README_EN.md index 1c5e83c97072e..fd41724f58148 100644 --- a/solution/3000-3099/3085.Minimum Deletions to Make String K-Special/README_EN.md +++ b/solution/3000-3099/3085.Minimum Deletions to Make String K-Special/README_EN.md @@ -90,6 +90,8 @@ The time complexity is $O(n \times |\Sigma|)$, and the space complexity is $O(|\ +#### Python3 + ```python class Solution: def minimumDeletions(self, word: str, k: int) -> int: @@ -106,6 +108,8 @@ class Solution: return min(f(v) for v in range(len(word) + 1)) ``` +#### Java + ```java class Solution { private List nums = new ArrayList<>(); @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go func minimumDeletions(word string, k int) int { freq := [26]int{} @@ -208,6 +216,8 @@ func minimumDeletions(word string, k int) int { } ``` +#### TypeScript + ```ts function minimumDeletions(word: string, k: number): number { const freq: number[] = Array(26).fill(0); diff --git a/solution/3000-3099/3086.Minimum Moves to Pick K Ones/README.md b/solution/3000-3099/3086.Minimum Moves to Pick K Ones/README.md index e3f8af6de7d0b..77d72163b5de7 100644 --- a/solution/3000-3099/3086.Minimum Moves to Pick K Ones/README.md +++ b/solution/3000-3099/3086.Minimum Moves to Pick K Ones/README.md @@ -92,18 +92,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/3000-3099/3086.Minimum Moves to Pick K Ones/README_EN.md b/solution/3000-3099/3086.Minimum Moves to Pick K Ones/README_EN.md index 432f9fc867b7e..bd662b8be4613 100644 --- a/solution/3000-3099/3086.Minimum Moves to Pick K Ones/README_EN.md +++ b/solution/3000-3099/3086.Minimum Moves to Pick K Ones/README_EN.md @@ -90,18 +90,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/3000-3099/3087.Find Trending Hashtags/README.md b/solution/3000-3099/3087.Find Trending Hashtags/README.md index 8657a6ae061d6..d55454e752259 100644 --- a/solution/3000-3099/3087.Find Trending Hashtags/README.md +++ b/solution/3000-3099/3087.Find Trending Hashtags/README.md @@ -94,6 +94,8 @@ tweet_id 是这张表的主键 (值互不相同的列)。 +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -106,6 +108,8 @@ ORDER BY 2 DESC, 1 DESC LIMIT 3; ``` +#### Python3 + ```python import pandas as pd diff --git a/solution/3000-3099/3087.Find Trending Hashtags/README_EN.md b/solution/3000-3099/3087.Find Trending Hashtags/README_EN.md index 96d4eb1410677..ce2ab24e7302d 100644 --- a/solution/3000-3099/3087.Find Trending Hashtags/README_EN.md +++ b/solution/3000-3099/3087.Find Trending Hashtags/README_EN.md @@ -95,6 +95,8 @@ We can query all tweets from February 2024, use the `SUBSTRING_INDEX` function t +#### MySQL + ```sql # Write your MySQL query statement below SELECT @@ -107,6 +109,8 @@ ORDER BY 2 DESC, 1 DESC LIMIT 3; ``` +#### Python3 + ```python import pandas as pd diff --git a/solution/3000-3099/3088.Make String Anti-palindrome/README.md b/solution/3000-3099/3088.Make String Anti-palindrome/README.md index 6a8ebb73f2455..03069d2caade2 100644 --- a/solution/3000-3099/3088.Make String Anti-palindrome/README.md +++ b/solution/3000-3099/3088.Make String Anti-palindrome/README.md @@ -90,6 +90,8 @@ tags: +#### Python3 + ```python class Solution: def makeAntiPalindrome(self, s: str) -> str: @@ -109,6 +111,8 @@ class Solution: return "".join(cs) ``` +#### Java + ```java class Solution { public String makeAntiPalindrome(String s) { @@ -135,6 +139,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -159,6 +165,8 @@ public: }; ``` +#### Go + ```go func makeAntiPalindrome(s string) string { cs := []byte(s) @@ -181,6 +189,8 @@ func makeAntiPalindrome(s string) string { } ``` +#### TypeScript + ```ts function makeAntiPalindrome(s: string): string { const cs: string[] = s.split('').sort(); diff --git a/solution/3000-3099/3088.Make String Anti-palindrome/README_EN.md b/solution/3000-3099/3088.Make String Anti-palindrome/README_EN.md index e27c738c355a5..135f934052fe5 100644 --- a/solution/3000-3099/3088.Make String Anti-palindrome/README_EN.md +++ b/solution/3000-3099/3088.Make String Anti-palindrome/README_EN.md @@ -88,6 +88,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def makeAntiPalindrome(self, s: str) -> str: @@ -107,6 +109,8 @@ class Solution: return "".join(cs) ``` +#### Java + ```java class Solution { public String makeAntiPalindrome(String s) { @@ -133,6 +137,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func makeAntiPalindrome(s string) string { cs := []byte(s) @@ -179,6 +187,8 @@ func makeAntiPalindrome(s string) string { } ``` +#### TypeScript + ```ts function makeAntiPalindrome(s: string): string { const cs: string[] = s.split('').sort(); diff --git a/solution/3000-3099/3089.Find Bursty Behavior/README.md b/solution/3000-3099/3089.Find Bursty Behavior/README.md index a0eec9288bf66..c14344548c49d 100644 --- a/solution/3000-3099/3089.Find Bursty Behavior/README.md +++ b/solution/3000-3099/3089.Find Bursty Behavior/README.md @@ -100,6 +100,8 @@ post_id 是这张表的主键(有不同值的列)。 +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -127,6 +129,8 @@ HAVING max_7day_posts >= avg_weekly_posts * 2 ORDER BY 1; ``` +#### Python3 + ```python import pandas as pd diff --git a/solution/3000-3099/3089.Find Bursty Behavior/README_EN.md b/solution/3000-3099/3089.Find Bursty Behavior/README_EN.md index ccf306fc54910..b73e82e1bf91b 100644 --- a/solution/3000-3099/3089.Find Bursty Behavior/README_EN.md +++ b/solution/3000-3099/3089.Find Bursty Behavior/README_EN.md @@ -99,6 +99,8 @@ Finally, we connect tables `P` and `T` with the condition `P.user_id = T.user_id +#### MySQL + ```sql # Write your MySQL query statement below WITH @@ -126,6 +128,8 @@ HAVING max_7day_posts >= avg_weekly_posts * 2 ORDER BY 1; ``` +#### Python3 + ```python import pandas as pd diff --git a/solution/3000-3099/3090.Maximum Length Substring With Two Occurrences/README.md b/solution/3000-3099/3090.Maximum Length Substring With Two Occurrences/README.md index fc5293f5dfe0a..504e9d1872550 100644 --- a/solution/3000-3099/3090.Maximum Length Substring With Two Occurrences/README.md +++ b/solution/3000-3099/3090.Maximum Length Substring With Two Occurrences/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def maximumLengthSubstring(self, s: str) -> int: @@ -90,6 +92,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumLengthSubstring(String s) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func maximumLengthSubstring(s string) (ans int) { cnt := [26]int{} @@ -144,6 +152,8 @@ func maximumLengthSubstring(s string) (ans int) { } ``` +#### TypeScript + ```ts function maximumLengthSubstring(s: string): number { let ans = 0; diff --git a/solution/3000-3099/3090.Maximum Length Substring With Two Occurrences/README_EN.md b/solution/3000-3099/3090.Maximum Length Substring With Two Occurrences/README_EN.md index 6ed2c8531dde7..9f94f0871954b 100644 --- a/solution/3000-3099/3090.Maximum Length Substring With Two Occurrences/README_EN.md +++ b/solution/3000-3099/3090.Maximum Length Substring With Two Occurrences/README_EN.md @@ -69,6 +69,8 @@ The time complexity is $O(n)$, where $n$ is the length of the string $s$. The sp +#### Python3 + ```python class Solution: def maximumLengthSubstring(self, s: str) -> int: @@ -83,6 +85,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumLengthSubstring(String s) { @@ -101,6 +105,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func maximumLengthSubstring(s string) (ans int) { cnt := [26]int{} @@ -137,6 +145,8 @@ func maximumLengthSubstring(s string) (ans int) { } ``` +#### TypeScript + ```ts function maximumLengthSubstring(s: string): number { let ans = 0; diff --git a/solution/3000-3099/3091.Apply Operations to Make Sum of Array Greater Than or Equal to k/README.md b/solution/3000-3099/3091.Apply Operations to Make Sum of Array Greater Than or Equal to k/README.md index 47ef8a4ae86b2..480e2c2e9090e 100644 --- a/solution/3000-3099/3091.Apply Operations to Make Sum of Array Greater Than or Equal to k/README.md +++ b/solution/3000-3099/3091.Apply Operations to Make Sum of Array Greater Than or Equal to k/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def minOperations(self, k: int) -> int: @@ -100,6 +102,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minOperations(int k) { @@ -114,6 +118,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,6 +135,8 @@ public: }; ``` +#### Go + ```go func minOperations(k int) int { ans := k @@ -141,6 +149,8 @@ func minOperations(k int) int { } ``` +#### TypeScript + ```ts function minOperations(k: number): number { let ans = k; diff --git a/solution/3000-3099/3091.Apply Operations to Make Sum of Array Greater Than or Equal to k/README_EN.md b/solution/3000-3099/3091.Apply Operations to Make Sum of Array Greater Than or Equal to k/README_EN.md index 02d8092859d53..e770afb61bf0d 100644 --- a/solution/3000-3099/3091.Apply Operations to Make Sum of Array Greater Than or Equal to k/README_EN.md +++ b/solution/3000-3099/3091.Apply Operations to Make Sum of Array Greater Than or Equal to k/README_EN.md @@ -87,6 +87,8 @@ The time complexity is $O(k)$, where $k$ is the input positive integer $k$. The +#### Python3 + ```python class Solution: def minOperations(self, k: int) -> int: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minOperations(int k) { @@ -112,6 +116,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,6 +133,8 @@ public: }; ``` +#### Go + ```go func minOperations(k int) int { ans := k @@ -139,6 +147,8 @@ func minOperations(k int) int { } ``` +#### TypeScript + ```ts function minOperations(k: number): number { let ans = k; diff --git a/solution/3000-3099/3092.Most Frequent IDs/README.md b/solution/3000-3099/3092.Most Frequent IDs/README.md index 5cd9b1380473c..aa2e2b4153587 100644 --- a/solution/3000-3099/3092.Most Frequent IDs/README.md +++ b/solution/3000-3099/3092.Most Frequent IDs/README.md @@ -89,6 +89,8 @@ tags: +#### Python3 + ```python class Solution: def mostFrequentIDs(self, nums: List[int], freq: List[int]) -> List[int]: @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long[] mostFrequentIDs(int[] nums, int[] freq) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -157,6 +163,8 @@ public: }; ``` +#### Go + ```go func mostFrequentIDs(nums []int, freq []int) []int64 { n := len(nums) diff --git a/solution/3000-3099/3092.Most Frequent IDs/README_EN.md b/solution/3000-3099/3092.Most Frequent IDs/README_EN.md index 357a431274761..8a549b55f549a 100644 --- a/solution/3000-3099/3092.Most Frequent IDs/README_EN.md +++ b/solution/3000-3099/3092.Most Frequent IDs/README_EN.md @@ -87,6 +87,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class Solution: def mostFrequentIDs(self, nums: List[int], freq: List[int]) -> List[int]: @@ -105,6 +107,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long[] mostFrequentIDs(int[] nums, int[] freq) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -155,6 +161,8 @@ public: }; ``` +#### Go + ```go func mostFrequentIDs(nums []int, freq []int) []int64 { n := len(nums) diff --git a/solution/3000-3099/3093.Longest Common Suffix Queries/README.md b/solution/3000-3099/3093.Longest Common Suffix Queries/README.md index 7a2bf7dceea9e..8cfba53e35be6 100644 --- a/solution/3000-3099/3093.Longest Common Suffix Queries/README.md +++ b/solution/3000-3099/3093.Longest Common Suffix Queries/README.md @@ -102,6 +102,8 @@ tags: +#### Python3 + ```python class Trie: __slots__ = ("children", "length", "idx") @@ -145,6 +147,8 @@ class Solution: return [trie.query(w) for w in wordsQuery] ``` +#### Java + ```java class Trie { private final int inf = 1 << 30; @@ -200,6 +204,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { private: @@ -264,6 +270,8 @@ public: }; ``` +#### Go + ```go const inf = 1 << 30 @@ -320,6 +328,8 @@ func stringIndices(wordsContainer []string, wordsQuery []string) (ans []int) { } ``` +#### TypeScript + ```ts class Trie { private children: Trie[] = new Array(26); diff --git a/solution/3000-3099/3093.Longest Common Suffix Queries/README_EN.md b/solution/3000-3099/3093.Longest Common Suffix Queries/README_EN.md index 5c5719980f156..6a970f286031c 100644 --- a/solution/3000-3099/3093.Longest Common Suffix Queries/README_EN.md +++ b/solution/3000-3099/3093.Longest Common Suffix Queries/README_EN.md @@ -100,6 +100,8 @@ The time complexity is $(L_1 \times |\Sigma| + L_2)$, and the space complexity i +#### Python3 + ```python class Trie: __slots__ = ("children", "length", "idx") @@ -143,6 +145,8 @@ class Solution: return [trie.query(w) for w in wordsQuery] ``` +#### Java + ```java class Trie { private final int inf = 1 << 30; @@ -198,6 +202,8 @@ class Solution { } ``` +#### C++ + ```cpp class Trie { private: @@ -262,6 +268,8 @@ public: }; ``` +#### Go + ```go const inf = 1 << 30 @@ -318,6 +326,8 @@ func stringIndices(wordsContainer []string, wordsQuery []string) (ans []int) { } ``` +#### TypeScript + ```ts class Trie { private children: Trie[] = new Array(26); diff --git a/solution/3000-3099/3094.Guess the Number Using Bitwise Questions II/README.md b/solution/3000-3099/3094.Guess the Number Using Bitwise Questions II/README.md index 0ecdeebe3cfdc..de04893c61f6b 100644 --- a/solution/3000-3099/3094.Guess the Number Using Bitwise Questions II/README.md +++ b/solution/3000-3099/3094.Guess the Number Using Bitwise Questions II/README.md @@ -84,6 +84,8 @@ tags: +#### Python3 + ```python # Definition of commonBits API. # def commonBits(num: int) -> int: @@ -100,6 +102,8 @@ class Solution: return n ``` +#### Java + ```java /** * Definition of commonBits API (defined in the parent class Problem). @@ -121,6 +125,8 @@ public class Solution extends Problem { } ``` +#### C++ + ```cpp /** * Definition of commonBits API. @@ -143,6 +149,8 @@ public: }; ``` +#### Go + ```go /** * Definition of commonBits API. diff --git a/solution/3000-3099/3094.Guess the Number Using Bitwise Questions II/README_EN.md b/solution/3000-3099/3094.Guess the Number Using Bitwise Questions II/README_EN.md index 89fd011a12fe4..e0767466c4392 100644 --- a/solution/3000-3099/3094.Guess the Number Using Bitwise Questions II/README_EN.md +++ b/solution/3000-3099/3094.Guess the Number Using Bitwise Questions II/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $O(\log n)$, and the space complexity is $O(1)$. +#### Python3 + ```python # Definition of commonBits API. # def commonBits(num: int) -> int: @@ -98,6 +100,8 @@ class Solution: return n ``` +#### Java + ```java /** * Definition of commonBits API (defined in the parent class Problem). @@ -119,6 +123,8 @@ public class Solution extends Problem { } ``` +#### C++ + ```cpp /** * Definition of commonBits API. @@ -141,6 +147,8 @@ public: }; ``` +#### Go + ```go /** * Definition of commonBits API. diff --git a/solution/3000-3099/3095.Shortest Subarray With OR at Least K I/README.md b/solution/3000-3099/3095.Shortest Subarray With OR at Least K I/README.md index 8bdf7a8ff7291..4236141ac07c9 100644 --- a/solution/3000-3099/3095.Shortest Subarray With OR at Least K I/README.md +++ b/solution/3000-3099/3095.Shortest Subarray With OR at Least K I/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class Solution: def minimumSubarrayLength(self, nums: List[int], k: int) -> int: @@ -118,6 +120,8 @@ class Solution: return -1 if ans > n else ans ``` +#### Java + ```java class Solution { public int minimumSubarrayLength(int[] nums, int k) { @@ -147,6 +151,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go func minimumSubarrayLength(nums []int, k int) int { n := len(nums) @@ -209,6 +217,8 @@ func minimumSubarrayLength(nums []int, k int) int { } ``` +#### TypeScript + ```ts function minimumSubarrayLength(nums: number[], k: number): number { const n = nums.length; diff --git a/solution/3000-3099/3095.Shortest Subarray With OR at Least K I/README_EN.md b/solution/3000-3099/3095.Shortest Subarray With OR at Least K I/README_EN.md index 48920861326f0..b61019222153c 100644 --- a/solution/3000-3099/3095.Shortest Subarray With OR at Least K I/README_EN.md +++ b/solution/3000-3099/3095.Shortest Subarray With OR at Least K I/README_EN.md @@ -92,6 +92,8 @@ The time complexity is $O(n \times \log M)$ and the space complexity is $O(\log +#### Python3 + ```python class Solution: def minimumSubarrayLength(self, nums: List[int], k: int) -> int: @@ -116,6 +118,8 @@ class Solution: return -1 if ans > n else ans ``` +#### Java + ```java class Solution { public int minimumSubarrayLength(int[] nums, int k) { @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go func minimumSubarrayLength(nums []int, k int) int { n := len(nums) @@ -207,6 +215,8 @@ func minimumSubarrayLength(nums []int, k int) int { } ``` +#### TypeScript + ```ts function minimumSubarrayLength(nums: number[], k: number): number { const n = nums.length; diff --git a/solution/3000-3099/3096.Minimum Levels to Gain More Points/README.md b/solution/3000-3099/3096.Minimum Levels to Gain More Points/README.md index 67c891bc3c728..d8949a6889d80 100644 --- a/solution/3000-3099/3096.Minimum Levels to Gain More Points/README.md +++ b/solution/3000-3099/3096.Minimum Levels to Gain More Points/README.md @@ -113,6 +113,8 @@ tags: +#### Python3 + ```python class Solution: def minimumLevels(self, possible: List[int]) -> int: @@ -125,6 +127,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minimumLevels(int[] possible) { @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -164,6 +170,8 @@ public: }; ``` +#### Go + ```go func minimumLevels(possible []int) int { s := 0 @@ -187,6 +195,8 @@ func minimumLevels(possible []int) int { } ``` +#### TypeScript + ```ts function minimumLevels(possible: number[]): number { const s = possible.reduce((acc, x) => acc + (x === 0 ? -1 : 1), 0); diff --git a/solution/3000-3099/3096.Minimum Levels to Gain More Points/README_EN.md b/solution/3000-3099/3096.Minimum Levels to Gain More Points/README_EN.md index dbe3ce1d77bd2..5f7f1c7ce2e2d 100644 --- a/solution/3000-3099/3096.Minimum Levels to Gain More Points/README_EN.md +++ b/solution/3000-3099/3096.Minimum Levels to Gain More Points/README_EN.md @@ -111,6 +111,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def minimumLevels(self, possible: List[int]) -> int: @@ -123,6 +125,8 @@ class Solution: return -1 ``` +#### Java + ```java class Solution { public int minimumLevels(int[] possible) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func minimumLevels(possible []int) int { s := 0 @@ -185,6 +193,8 @@ func minimumLevels(possible []int) int { } ``` +#### TypeScript + ```ts function minimumLevels(possible: number[]): number { const s = possible.reduce((acc, x) => acc + (x === 0 ? -1 : 1), 0); diff --git a/solution/3000-3099/3097.Shortest Subarray With OR at Least K II/README.md b/solution/3000-3099/3097.Shortest Subarray With OR at Least K II/README.md index 25d00d1b2695e..52c43a01bea97 100644 --- a/solution/3000-3099/3097.Shortest Subarray With OR at Least K II/README.md +++ b/solution/3000-3099/3097.Shortest Subarray With OR at Least K II/README.md @@ -94,6 +94,8 @@ tags: +#### Python3 + ```python class Solution: def minimumSubarrayLength(self, nums: List[int], k: int) -> int: @@ -118,6 +120,8 @@ class Solution: return -1 if ans > n else ans ``` +#### Java + ```java class Solution { public int minimumSubarrayLength(int[] nums, int k) { @@ -147,6 +151,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go func minimumSubarrayLength(nums []int, k int) int { n := len(nums) @@ -209,6 +217,8 @@ func minimumSubarrayLength(nums []int, k int) int { } ``` +#### TypeScript + ```ts function minimumSubarrayLength(nums: number[], k: number): number { const n = nums.length; diff --git a/solution/3000-3099/3097.Shortest Subarray With OR at Least K II/README_EN.md b/solution/3000-3099/3097.Shortest Subarray With OR at Least K II/README_EN.md index eb2a3c2b078ef..caf7e78ba986e 100644 --- a/solution/3000-3099/3097.Shortest Subarray With OR at Least K II/README_EN.md +++ b/solution/3000-3099/3097.Shortest Subarray With OR at Least K II/README_EN.md @@ -92,6 +92,8 @@ The time complexity is $O(n \times \log M)$ and the space complexity is $O(\log +#### Python3 + ```python class Solution: def minimumSubarrayLength(self, nums: List[int], k: int) -> int: @@ -116,6 +118,8 @@ class Solution: return -1 if ans > n else ans ``` +#### Java + ```java class Solution { public int minimumSubarrayLength(int[] nums, int k) { @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go func minimumSubarrayLength(nums []int, k int) int { n := len(nums) @@ -207,6 +215,8 @@ func minimumSubarrayLength(nums []int, k int) int { } ``` +#### TypeScript + ```ts function minimumSubarrayLength(nums: number[], k: number): number { const n = nums.length; diff --git a/solution/3000-3099/3098.Find the Sum of Subsequence Powers/README.md b/solution/3000-3099/3098.Find the Sum of Subsequence Powers/README.md index 2a1c0044eaf19..ad5ed9ef43dce 100644 --- a/solution/3000-3099/3098.Find the Sum of Subsequence Powers/README.md +++ b/solution/3000-3099/3098.Find the Sum of Subsequence Powers/README.md @@ -99,6 +99,8 @@ tags: +#### Python3 + ```python class Solution: def sumOfPowers(self, nums: List[int], k: int) -> int: @@ -120,6 +122,8 @@ class Solution: return dfs(0, n, k, inf) ``` +#### Java + ```java class Solution { private Map f = new HashMap<>(); @@ -153,6 +157,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -184,6 +190,8 @@ public: }; ``` +#### Go + ```go func sumOfPowers(nums []int, k int) int { const mod int = 1e9 + 7 diff --git a/solution/3000-3099/3098.Find the Sum of Subsequence Powers/README_EN.md b/solution/3000-3099/3098.Find the Sum of Subsequence Powers/README_EN.md index 6daedc2fa2917..5b0cac31f3d1f 100644 --- a/solution/3000-3099/3098.Find the Sum of Subsequence Powers/README_EN.md +++ b/solution/3000-3099/3098.Find the Sum of Subsequence Powers/README_EN.md @@ -97,6 +97,8 @@ The time complexity is $O(n^5)$, and the space complexity is $O(n^5)$. Where $n$ +#### Python3 + ```python class Solution: def sumOfPowers(self, nums: List[int], k: int) -> int: @@ -118,6 +120,8 @@ class Solution: return dfs(0, n, k, inf) ``` +#### Java + ```java class Solution { private Map f = new HashMap<>(); @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -182,6 +188,8 @@ public: }; ``` +#### Go + ```go func sumOfPowers(nums []int, k int) int { const mod int = 1e9 + 7 diff --git a/solution/3000-3099/3099.Harshad Number/README.md b/solution/3000-3099/3099.Harshad Number/README.md index 682d5fdf1c07e..e6cad9bf17217 100644 --- a/solution/3000-3099/3099.Harshad Number/README.md +++ b/solution/3000-3099/3099.Harshad Number/README.md @@ -68,6 +68,8 @@ tags: +#### Python3 + ```python class Solution: def sumOfTheDigitsOfHarshadNumber(self, x: int) -> int: @@ -78,6 +80,8 @@ class Solution: return s if x % s == 0 else -1 ``` +#### Java + ```java class Solution { public int sumOfTheDigitsOfHarshadNumber(int x) { @@ -90,6 +94,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -103,6 +109,8 @@ public: }; ``` +#### Go + ```go func sumOfTheDigitsOfHarshadNumber(x int) int { s := 0 @@ -116,6 +124,8 @@ func sumOfTheDigitsOfHarshadNumber(x int) int { } ``` +#### TypeScript + ```ts function sumOfTheDigitsOfHarshadNumber(x: number): number { let s = 0; diff --git a/solution/3000-3099/3099.Harshad Number/README_EN.md b/solution/3000-3099/3099.Harshad Number/README_EN.md index 1f0d1d197bbbd..81154cde0e4fe 100644 --- a/solution/3000-3099/3099.Harshad Number/README_EN.md +++ b/solution/3000-3099/3099.Harshad Number/README_EN.md @@ -66,6 +66,8 @@ The time complexity is $O(\log x)$, where $x$ is the input integer. The space co +#### Python3 + ```python class Solution: def sumOfTheDigitsOfHarshadNumber(self, x: int) -> int: @@ -76,6 +78,8 @@ class Solution: return s if x % s == 0 else -1 ``` +#### Java + ```java class Solution { public int sumOfTheDigitsOfHarshadNumber(int x) { @@ -88,6 +92,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -101,6 +107,8 @@ public: }; ``` +#### Go + ```go func sumOfTheDigitsOfHarshadNumber(x int) int { s := 0 @@ -114,6 +122,8 @@ func sumOfTheDigitsOfHarshadNumber(x int) int { } ``` +#### TypeScript + ```ts function sumOfTheDigitsOfHarshadNumber(x: number): number { let s = 0; diff --git a/solution/3100-3199/3100.Water Bottles II/README.md b/solution/3100-3199/3100.Water Bottles II/README.md index a68a42d581cfb..798a1a8488b1d 100644 --- a/solution/3100-3199/3100.Water Bottles II/README.md +++ b/solution/3100-3199/3100.Water Bottles II/README.md @@ -77,6 +77,8 @@ tags: +#### Python3 + ```python class Solution: def maxBottlesDrunk(self, numBottles: int, numExchange: int) -> int: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxBottlesDrunk(int numBottles, int numExchange) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -120,6 +126,8 @@ public: }; ``` +#### Go + ```go func maxBottlesDrunk(numBottles int, numExchange int) int { ans := numBottles @@ -133,6 +141,8 @@ func maxBottlesDrunk(numBottles int, numExchange int) int { } ``` +#### TypeScript + ```ts function maxBottlesDrunk(numBottles: number, numExchange: number): number { let ans = numBottles; diff --git a/solution/3100-3199/3100.Water Bottles II/README_EN.md b/solution/3100-3199/3100.Water Bottles II/README_EN.md index e479457e124bb..a255611acad8e 100644 --- a/solution/3100-3199/3100.Water Bottles II/README_EN.md +++ b/solution/3100-3199/3100.Water Bottles II/README_EN.md @@ -76,6 +76,8 @@ The time complexity is $O(\sqrt{numBottles})$ and the space complexity is $O(1)$ +#### Python3 + ```python class Solution: def maxBottlesDrunk(self, numBottles: int, numExchange: int) -> int: @@ -88,6 +90,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxBottlesDrunk(int numBottles, int numExchange) { @@ -103,6 +107,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -119,6 +125,8 @@ public: }; ``` +#### Go + ```go func maxBottlesDrunk(numBottles int, numExchange int) int { ans := numBottles @@ -132,6 +140,8 @@ func maxBottlesDrunk(numBottles int, numExchange int) int { } ``` +#### TypeScript + ```ts function maxBottlesDrunk(numBottles: number, numExchange: number): number { let ans = numBottles; diff --git a/solution/3100-3199/3101.Count Alternating Subarrays/README.md b/solution/3100-3199/3101.Count Alternating Subarrays/README.md index 12e3361475850..4c84d8a70f576 100644 --- a/solution/3100-3199/3101.Count Alternating Subarrays/README.md +++ b/solution/3100-3199/3101.Count Alternating Subarrays/README.md @@ -85,6 +85,8 @@ tags: +#### Python3 + ```python class Solution: def countAlternatingSubarrays(self, nums: List[int]) -> int: @@ -95,6 +97,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long countAlternatingSubarrays(int[] nums) { @@ -108,6 +112,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func countAlternatingSubarrays(nums []int) int64 { ans, s := int64(1), int64(1) @@ -137,6 +145,8 @@ func countAlternatingSubarrays(nums []int) int64 { } ``` +#### TypeScript + ```ts function countAlternatingSubarrays(nums: number[]): number { let [ans, s] = [1, 1]; diff --git a/solution/3100-3199/3101.Count Alternating Subarrays/README_EN.md b/solution/3100-3199/3101.Count Alternating Subarrays/README_EN.md index 4cf856172f0b5..5f3b6572f4327 100644 --- a/solution/3100-3199/3101.Count Alternating Subarrays/README_EN.md +++ b/solution/3100-3199/3101.Count Alternating Subarrays/README_EN.md @@ -81,6 +81,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def countAlternatingSubarrays(self, nums: List[int]) -> int: @@ -91,6 +93,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long countAlternatingSubarrays(int[] nums) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -118,6 +124,8 @@ public: }; ``` +#### Go + ```go func countAlternatingSubarrays(nums []int) int64 { ans, s := int64(1), int64(1) @@ -133,6 +141,8 @@ func countAlternatingSubarrays(nums []int) int64 { } ``` +#### TypeScript + ```ts function countAlternatingSubarrays(nums: number[]): number { let [ans, s] = [1, 1]; diff --git a/solution/3100-3199/3102.Minimize Manhattan Distances/README.md b/solution/3100-3199/3102.Minimize Manhattan Distances/README.md index 94f638b72a9da..85f2016fedf69 100644 --- a/solution/3100-3199/3102.Minimize Manhattan Distances/README.md +++ b/solution/3100-3199/3102.Minimize Manhattan Distances/README.md @@ -99,6 +99,8 @@ $$ +#### Python3 + ```python from sortedcontainers import SortedList @@ -120,6 +122,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumDistance(int[][] points) { @@ -149,6 +153,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func minimumDistance(points [][]int) int { st1 := redblacktree.New[int, int]() diff --git a/solution/3100-3199/3102.Minimize Manhattan Distances/README_EN.md b/solution/3100-3199/3102.Minimize Manhattan Distances/README_EN.md index 4cc0170439369..50ad421b7eaa4 100644 --- a/solution/3100-3199/3102.Minimize Manhattan Distances/README_EN.md +++ b/solution/3100-3199/3102.Minimize Manhattan Distances/README_EN.md @@ -81,6 +81,8 @@ tags: +#### Python3 + ```python from sortedcontainers import SortedList @@ -102,6 +104,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minimumDistance(int[][] points) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -156,6 +162,8 @@ public: }; ``` +#### Go + ```go func minimumDistance(points [][]int) int { st1 := redblacktree.New[int, int]() diff --git a/solution/3100-3199/3103.Find Trending Hashtags II/README.md b/solution/3100-3199/3103.Find Trending Hashtags II/README.md index 499a55378d17b..0e1ad49452348 100644 --- a/solution/3100-3199/3103.Find Trending Hashtags II/README.md +++ b/solution/3100-3199/3103.Find Trending Hashtags II/README.md @@ -96,6 +96,8 @@ tweet_id 是这张表的主键 (值互不相同的列)。 +#### Python3 + ```python import pandas as pd diff --git a/solution/3100-3199/3103.Find Trending Hashtags II/README_EN.md b/solution/3100-3199/3103.Find Trending Hashtags II/README_EN.md index 49d828d746e01..5cce6fa19a796 100644 --- a/solution/3100-3199/3103.Find Trending Hashtags II/README_EN.md +++ b/solution/3100-3199/3103.Find Trending Hashtags II/README_EN.md @@ -95,6 +95,8 @@ We can use regular expressions to match all tags in each tweet, and then count t +#### Python3 + ```python import pandas as pd diff --git a/solution/3100-3199/3104.Find Longest Self-Contained Substring/README.md b/solution/3100-3199/3104.Find Longest Self-Contained Substring/README.md index 1a79f16e708e2..b7bc91dac3183 100644 --- a/solution/3100-3199/3104.Find Longest Self-Contained Substring/README.md +++ b/solution/3100-3199/3104.Find Longest Self-Contained Substring/README.md @@ -87,6 +87,8 @@ Let's check the substring "abac&q +#### Python3 + ```python class Solution: def maxSubstringLength(self, s: str) -> int: @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxSubstringLength(String s) { @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -184,6 +190,8 @@ public: }; ``` +#### Go + ```go func maxSubstringLength(s string) int { first := [26]int{} @@ -221,6 +229,8 @@ func maxSubstringLength(s string) int { } ``` +#### TypeScript + ```ts function maxSubstringLength(s: string): number { const first: number[] = Array(26).fill(-1); diff --git a/solution/3100-3199/3104.Find Longest Self-Contained Substring/README_EN.md b/solution/3100-3199/3104.Find Longest Self-Contained Substring/README_EN.md index 938d696f95fba..2c556517f8ccf 100644 --- a/solution/3100-3199/3104.Find Longest Self-Contained Substring/README_EN.md +++ b/solution/3100-3199/3104.Find Longest Self-Contained Substring/README_EN.md @@ -87,6 +87,8 @@ The time complexity is $O(n \times |\Sigma|)$, and the space complexity is $O(|\ +#### Python3 + ```python class Solution: def maxSubstringLength(self, s: str) -> int: @@ -108,6 +110,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxSubstringLength(String s) { @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -184,6 +190,8 @@ public: }; ``` +#### Go + ```go func maxSubstringLength(s string) int { first := [26]int{} @@ -221,6 +229,8 @@ func maxSubstringLength(s string) int { } ``` +#### TypeScript + ```ts function maxSubstringLength(s: string): number { const first: number[] = Array(26).fill(-1); diff --git a/solution/3100-3199/3105.Longest Strictly Increasing or Strictly Decreasing Subarray/README.md b/solution/3100-3199/3105.Longest Strictly Increasing or Strictly Decreasing Subarray/README.md index f62e802886eb1..6cfc08fd14814 100644 --- a/solution/3100-3199/3105.Longest Strictly Increasing or Strictly Decreasing Subarray/README.md +++ b/solution/3100-3199/3105.Longest Strictly Increasing or Strictly Decreasing Subarray/README.md @@ -95,6 +95,8 @@ tags: +#### Python3 + ```python class Solution: def longestMonotonicSubarray(self, nums: List[int]) -> int: @@ -115,6 +117,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestMonotonicSubarray(int[] nums) { @@ -138,6 +142,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -162,6 +168,8 @@ public: }; ``` +#### Go + ```go func longestMonotonicSubarray(nums []int) int { ans := 1 @@ -187,6 +195,8 @@ func longestMonotonicSubarray(nums []int) int { } ``` +#### TypeScript + ```ts function longestMonotonicSubarray(nums: number[]): number { let ans = 1; diff --git a/solution/3100-3199/3105.Longest Strictly Increasing or Strictly Decreasing Subarray/README_EN.md b/solution/3100-3199/3105.Longest Strictly Increasing or Strictly Decreasing Subarray/README_EN.md index fd3eb5524b4cb..a8a0aba72d547 100644 --- a/solution/3100-3199/3105.Longest Strictly Increasing or Strictly Decreasing Subarray/README_EN.md +++ b/solution/3100-3199/3105.Longest Strictly Increasing or Strictly Decreasing Subarray/README_EN.md @@ -91,6 +91,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def longestMonotonicSubarray(self, nums: List[int]) -> int: @@ -111,6 +113,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int longestMonotonicSubarray(int[] nums) { @@ -134,6 +138,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -158,6 +164,8 @@ public: }; ``` +#### Go + ```go func longestMonotonicSubarray(nums []int) int { ans := 1 @@ -183,6 +191,8 @@ func longestMonotonicSubarray(nums []int) int { } ``` +#### TypeScript + ```ts function longestMonotonicSubarray(nums: number[]): number { let ans = 1; diff --git a/solution/3100-3199/3106.Lexicographically Smallest String After Operations With Constraint/README.md b/solution/3100-3199/3106.Lexicographically Smallest String After Operations With Constraint/README.md index 46140fea61c67..23247467d5752 100644 --- a/solution/3100-3199/3106.Lexicographically Smallest String After Operations With Constraint/README.md +++ b/solution/3100-3199/3106.Lexicographically Smallest String After Operations With Constraint/README.md @@ -96,6 +96,8 @@ tags: +#### Python3 + ```python class Solution: def getSmallestString(self, s: str, k: int) -> str: @@ -112,6 +114,8 @@ class Solution: return "".join(cs) ``` +#### Java + ```java class Solution { public String getSmallestString(String s, int k) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -152,6 +158,8 @@ public: }; ``` +#### Go + ```go func getSmallestString(s string, k int) string { cs := []byte(s) @@ -169,6 +177,8 @@ func getSmallestString(s string, k int) string { } ``` +#### TypeScript + ```ts function getSmallestString(s: string, k: number): string { const cs: string[] = s.split(''); diff --git a/solution/3100-3199/3106.Lexicographically Smallest String After Operations With Constraint/README_EN.md b/solution/3100-3199/3106.Lexicographically Smallest String After Operations With Constraint/README_EN.md index b3c0afa6470a8..fd1882db5c4fb 100644 --- a/solution/3100-3199/3106.Lexicographically Smallest String After Operations With Constraint/README_EN.md +++ b/solution/3100-3199/3106.Lexicographically Smallest String After Operations With Constraint/README_EN.md @@ -95,6 +95,8 @@ The time complexity is $O(n \times |\Sigma|)$, and the space complexity is $O(n) +#### Python3 + ```python class Solution: def getSmallestString(self, s: str, k: int) -> str: @@ -111,6 +113,8 @@ class Solution: return "".join(cs) ``` +#### Java + ```java class Solution { public String getSmallestString(String s, int k) { @@ -131,6 +135,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -151,6 +157,8 @@ public: }; ``` +#### Go + ```go func getSmallestString(s string, k int) string { cs := []byte(s) @@ -168,6 +176,8 @@ func getSmallestString(s string, k int) string { } ``` +#### TypeScript + ```ts function getSmallestString(s: string, k: number): string { const cs: string[] = s.split(''); diff --git a/solution/3100-3199/3107.Minimum Operations to Make Median of Array Equal to K/README.md b/solution/3100-3199/3107.Minimum Operations to Make Median of Array Equal to K/README.md index 69473005fe786..ce157510a2662 100644 --- a/solution/3100-3199/3107.Minimum Operations to Make Median of Array Equal to K/README.md +++ b/solution/3100-3199/3107.Minimum Operations to Make Median of Array Equal to K/README.md @@ -87,6 +87,8 @@ tags: +#### Python3 + ```python class Solution: def minOperationsToMakeMedianK(self, nums: List[int], k: int) -> int: @@ -107,6 +109,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long minOperationsToMakeMedianK(int[] nums, int k) { @@ -128,6 +132,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -150,6 +156,8 @@ public: }; ``` +#### Go + ```go func minOperationsToMakeMedianK(nums []int, k int) (ans int64) { sort.Ints(nums) @@ -176,6 +184,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function minOperationsToMakeMedianK(nums: number[], k: number): number { nums.sort((a, b) => a - b); diff --git a/solution/3100-3199/3107.Minimum Operations to Make Median of Array Equal to K/README_EN.md b/solution/3100-3199/3107.Minimum Operations to Make Median of Array Equal to K/README_EN.md index 0756474b434f6..15bd3c1802576 100644 --- a/solution/3100-3199/3107.Minimum Operations to Make Median of Array Equal to K/README_EN.md +++ b/solution/3100-3199/3107.Minimum Operations to Make Median of Array Equal to K/README_EN.md @@ -91,6 +91,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def minOperationsToMakeMedianK(self, nums: List[int], k: int) -> int: @@ -111,6 +113,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long minOperationsToMakeMedianK(int[] nums, int k) { @@ -132,6 +136,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func minOperationsToMakeMedianK(nums []int, k int) (ans int64) { sort.Ints(nums) @@ -180,6 +188,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function minOperationsToMakeMedianK(nums: number[], k: number): number { nums.sort((a, b) => a - b); diff --git a/solution/3100-3199/3108.Minimum Cost Walk in Weighted Graph/README.md b/solution/3100-3199/3108.Minimum Cost Walk in Weighted Graph/README.md index 09883863e91ba..79032d59f8435 100644 --- a/solution/3100-3199/3108.Minimum Cost Walk in Weighted Graph/README.md +++ b/solution/3100-3199/3108.Minimum Cost Walk in Weighted Graph/README.md @@ -103,6 +103,8 @@ tags: +#### Python3 + ```python class UnionFind: def __init__(self, n): @@ -148,6 +150,8 @@ class Solution: return [f(s, t) for s, t in query] ``` +#### Java + ```java class UnionFind { private final int[] p; @@ -223,6 +227,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -295,6 +301,8 @@ private: }; ``` +#### Go + ```go type unionFind struct { p, size []int @@ -366,6 +374,8 @@ func minimumCost(n int, edges [][]int, query [][]int) (ans []int) { } ``` +#### TypeScript + ```ts class UnionFind { p: number[]; diff --git a/solution/3100-3199/3108.Minimum Cost Walk in Weighted Graph/README_EN.md b/solution/3100-3199/3108.Minimum Cost Walk in Weighted Graph/README_EN.md index b69e77e15a7f1..15f3be72bf4ea 100644 --- a/solution/3100-3199/3108.Minimum Cost Walk in Weighted Graph/README_EN.md +++ b/solution/3100-3199/3108.Minimum Cost Walk in Weighted Graph/README_EN.md @@ -98,6 +98,8 @@ The time complexity is $O((n + m + q) \times \alpha(n))$, and the space complexi +#### Python3 + ```python class UnionFind: def __init__(self, n): @@ -143,6 +145,8 @@ class Solution: return [f(s, t) for s, t in query] ``` +#### Java + ```java class UnionFind { private final int[] p; @@ -218,6 +222,8 @@ class Solution { } ``` +#### C++ + ```cpp class UnionFind { public: @@ -290,6 +296,8 @@ private: }; ``` +#### Go + ```go type unionFind struct { p, size []int @@ -361,6 +369,8 @@ func minimumCost(n int, edges [][]int, query [][]int) (ans []int) { } ``` +#### TypeScript + ```ts class UnionFind { p: number[]; diff --git a/solution/3100-3199/3109.Find the Index of Permutation/README.md b/solution/3100-3199/3109.Find the Index of Permutation/README.md index 688e3e9637b48..61493ca42d714 100644 --- a/solution/3100-3199/3109.Find the Index of Permutation/README.md +++ b/solution/3100-3199/3109.Find the Index of Permutation/README.md @@ -89,6 +89,8 @@ And [3,1,2] is at index 4.

+#### Python3 + ```python class BinaryIndexedTree: __slots__ = "n", "c" @@ -125,6 +127,8 @@ class Solution: return ans % mod ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -171,6 +175,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { private: @@ -220,6 +226,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -262,6 +270,8 @@ func getPermutationIndex(perm []int) (ans int) { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; diff --git a/solution/3100-3199/3109.Find the Index of Permutation/README_EN.md b/solution/3100-3199/3109.Find the Index of Permutation/README_EN.md index cca519e7cfecc..6eb06b43a6337 100644 --- a/solution/3100-3199/3109.Find the Index of Permutation/README_EN.md +++ b/solution/3100-3199/3109.Find the Index of Permutation/README_EN.md @@ -89,6 +89,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. +#### Python3 + ```python class BinaryIndexedTree: __slots__ = "n", "c" @@ -125,6 +127,8 @@ class Solution: return ans % mod ``` +#### Java + ```java class BinaryIndexedTree { private int n; @@ -171,6 +175,8 @@ class Solution { } ``` +#### C++ + ```cpp class BinaryIndexedTree { private: @@ -220,6 +226,8 @@ public: }; ``` +#### Go + ```go type BinaryIndexedTree struct { n int @@ -262,6 +270,8 @@ func getPermutationIndex(perm []int) (ans int) { } ``` +#### TypeScript + ```ts class BinaryIndexedTree { private n: number; diff --git a/solution/3100-3199/3110.Score of a String/README.md b/solution/3100-3199/3110.Score of a String/README.md index fad3061b3d7ef..ebb9d173910c2 100644 --- a/solution/3100-3199/3110.Score of a String/README.md +++ b/solution/3100-3199/3110.Score of a String/README.md @@ -71,12 +71,16 @@ tags: +#### Python3 + ```python class Solution: def scoreOfString(self, s: str) -> int: return sum(abs(a - b) for a, b in pairwise(map(ord, s))) ``` +#### Java + ```java class Solution { public int scoreOfString(String s) { @@ -89,6 +93,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -102,6 +108,8 @@ public: }; ``` +#### Go + ```go func scoreOfString(s string) (ans int) { for i := 1; i < len(s); i++ { @@ -118,6 +126,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function scoreOfString(s: string): number { let ans = 0; diff --git a/solution/3100-3199/3110.Score of a String/README_EN.md b/solution/3100-3199/3110.Score of a String/README_EN.md index 4f2bccb448098..8cf897eeecb94 100644 --- a/solution/3100-3199/3110.Score of a String/README_EN.md +++ b/solution/3100-3199/3110.Score of a String/README_EN.md @@ -69,12 +69,16 @@ The time complexity is $O(n)$, where $n$ is the length of the string $s$. The sp +#### Python3 + ```python class Solution: def scoreOfString(self, s: str) -> int: return sum(abs(a - b) for a, b in pairwise(map(ord, s))) ``` +#### Java + ```java class Solution { public int scoreOfString(String s) { @@ -87,6 +91,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -100,6 +106,8 @@ public: }; ``` +#### Go + ```go func scoreOfString(s string) (ans int) { for i := 1; i < len(s); i++ { @@ -116,6 +124,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function scoreOfString(s: string): number { let ans = 0; diff --git a/solution/3100-3199/3111.Minimum Rectangles to Cover Points/README.md b/solution/3100-3199/3111.Minimum Rectangles to Cover Points/README.md index 85ea971c68a7e..c51e9bb67edf0 100644 --- a/solution/3100-3199/3111.Minimum Rectangles to Cover Points/README.md +++ b/solution/3100-3199/3111.Minimum Rectangles to Cover Points/README.md @@ -121,6 +121,8 @@ tags: +#### Python3 + ```python class Solution: def minRectanglesToCoverPoints(self, points: List[List[int]], w: int) -> int: @@ -133,6 +135,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minRectanglesToCoverPoints(int[][] points, int w) { @@ -151,6 +155,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go func minRectanglesToCoverPoints(points [][]int, w int) (ans int) { sort.Slice(points, func(i, j int) bool { return points[i][0] < points[j][0] }) @@ -183,6 +191,8 @@ func minRectanglesToCoverPoints(points [][]int, w int) (ans int) { } ``` +#### TypeScript + ```ts function minRectanglesToCoverPoints(points: number[][], w: number): number { points.sort((a, b) => a[0] - b[0]); diff --git a/solution/3100-3199/3111.Minimum Rectangles to Cover Points/README_EN.md b/solution/3100-3199/3111.Minimum Rectangles to Cover Points/README_EN.md index 457d1d3a9d244..75c8a95b32d09 100644 --- a/solution/3100-3199/3111.Minimum Rectangles to Cover Points/README_EN.md +++ b/solution/3100-3199/3111.Minimum Rectangles to Cover Points/README_EN.md @@ -164,6 +164,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def minRectanglesToCoverPoints(self, points: List[List[int]], w: int) -> int: @@ -176,6 +178,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int minRectanglesToCoverPoints(int[][] points, int w) { @@ -194,6 +198,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -212,6 +218,8 @@ public: }; ``` +#### Go + ```go func minRectanglesToCoverPoints(points [][]int, w int) (ans int) { sort.Slice(points, func(i, j int) bool { return points[i][0] < points[j][0] }) @@ -226,6 +234,8 @@ func minRectanglesToCoverPoints(points [][]int, w int) (ans int) { } ``` +#### TypeScript + ```ts function minRectanglesToCoverPoints(points: number[][], w: number): number { points.sort((a, b) => a[0] - b[0]); diff --git a/solution/3100-3199/3112.Minimum Time to Visit Disappearing Nodes/README.md b/solution/3100-3199/3112.Minimum Time to Visit Disappearing Nodes/README.md index 71476168974c1..5f704610a9f14 100644 --- a/solution/3100-3199/3112.Minimum Time to Visit Disappearing Nodes/README.md +++ b/solution/3100-3199/3112.Minimum Time to Visit Disappearing Nodes/README.md @@ -120,6 +120,8 @@ tags: +#### Python3 + ```python class Solution: def minimumTime( @@ -143,6 +145,8 @@ class Solution: return [a if a < b else -1 for a, b in zip(dist, disappear)] ``` +#### Java + ```java class Solution { public int[] minimumTime(int n, int[][] edges, int[] disappear) { @@ -181,6 +185,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -225,6 +231,8 @@ public: }; ``` +#### Go + ```go func minimumTime(n int, edges [][]int, disappear []int) []int { g := make([][]pair, n) diff --git a/solution/3100-3199/3112.Minimum Time to Visit Disappearing Nodes/README_EN.md b/solution/3100-3199/3112.Minimum Time to Visit Disappearing Nodes/README_EN.md index b5e1783845e0f..9ba4b772101c8 100644 --- a/solution/3100-3199/3112.Minimum Time to Visit Disappearing Nodes/README_EN.md +++ b/solution/3100-3199/3112.Minimum Time to Visit Disappearing Nodes/README_EN.md @@ -118,6 +118,8 @@ The time complexity is $O(m \times \log m)$, and the space complexity is $O(m)$, +#### Python3 + ```python class Solution: def minimumTime( @@ -141,6 +143,8 @@ class Solution: return [a if a < b else -1 for a, b in zip(dist, disappear)] ``` +#### Java + ```java class Solution { public int[] minimumTime(int n, int[][] edges, int[] disappear) { @@ -179,6 +183,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -223,6 +229,8 @@ public: }; ``` +#### Go + ```go func minimumTime(n int, edges [][]int, disappear []int) []int { g := make([][]pair, n) diff --git a/solution/3100-3199/3113.Find the Number of Subarrays Where Boundary Elements Are Maximum/README.md b/solution/3100-3199/3113.Find the Number of Subarrays Where Boundary Elements Are Maximum/README.md index 6852ca2e32ea2..a14edfda6f65c 100644 --- a/solution/3100-3199/3113.Find the Number of Subarrays Where Boundary Elements Are Maximum/README.md +++ b/solution/3100-3199/3113.Find the Number of Subarrays Where Boundary Elements Are Maximum/README.md @@ -118,6 +118,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfSubarrays(self, nums: List[int]) -> int: @@ -134,6 +136,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long numberOfSubarrays(int[] nums) { @@ -155,6 +159,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -177,6 +183,8 @@ public: }; ``` +#### Go + ```go func numberOfSubarrays(nums []int) (ans int64) { stk := [][2]int{} @@ -195,6 +203,8 @@ func numberOfSubarrays(nums []int) (ans int64) { } ``` +#### TypeScript + ```ts function numberOfSubarrays(nums: number[]): number { const stk: number[][] = []; diff --git a/solution/3100-3199/3113.Find the Number of Subarrays Where Boundary Elements Are Maximum/README_EN.md b/solution/3100-3199/3113.Find the Number of Subarrays Where Boundary Elements Are Maximum/README_EN.md index 3cb71e24e7fb9..d8ea0cbf91341 100644 --- a/solution/3100-3199/3113.Find the Number of Subarrays Where Boundary Elements Are Maximum/README_EN.md +++ b/solution/3100-3199/3113.Find the Number of Subarrays Where Boundary Elements Are Maximum/README_EN.md @@ -116,6 +116,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def numberOfSubarrays(self, nums: List[int]) -> int: @@ -132,6 +134,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long numberOfSubarrays(int[] nums) { @@ -153,6 +157,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go func numberOfSubarrays(nums []int) (ans int64) { stk := [][2]int{} @@ -193,6 +201,8 @@ func numberOfSubarrays(nums []int) (ans int64) { } ``` +#### TypeScript + ```ts function numberOfSubarrays(nums: number[]): number { const stk: number[][] = []; diff --git a/solution/3100-3199/3114.Latest Time You Can Obtain After Replacing Characters/README.md b/solution/3100-3199/3114.Latest Time You Can Obtain After Replacing Characters/README.md index 26faf17ba0786..c27c361536233 100644 --- a/solution/3100-3199/3114.Latest Time You Can Obtain After Replacing Characters/README.md +++ b/solution/3100-3199/3114.Latest Time You Can Obtain After Replacing Characters/README.md @@ -74,6 +74,8 @@ tags: +#### Python3 + ```python class Solution: def findLatestTime(self, s: str) -> str: @@ -84,6 +86,8 @@ class Solution: return t ``` +#### Java + ```java class Solution { public String findLatestTime(String s) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -130,6 +136,8 @@ public: }; ``` +#### Go + ```go func findLatestTime(s string) string { for h := 11; ; h-- { @@ -150,6 +158,8 @@ func findLatestTime(s string) string { } ``` +#### TypeScript + ```ts function findLatestTime(s: string): string { for (let h = 11; ; h--) { @@ -189,6 +199,8 @@ function findLatestTime(s: string): string { +#### Python3 + ```python class Solution: def findLatestTime(self, s: str) -> str: @@ -204,6 +216,8 @@ class Solution: return "".join(s) ``` +#### Java + ```java class Solution { public String findLatestTime(String s) { @@ -225,6 +239,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -246,6 +262,8 @@ public: }; ``` +#### Go + ```go func findLatestTime(s string) string { cs := []byte(s) @@ -273,6 +291,8 @@ func findLatestTime(s string) string { } ``` +#### TypeScript + ```ts function findLatestTime(s: string): string { const cs = s.split(''); diff --git a/solution/3100-3199/3114.Latest Time You Can Obtain After Replacing Characters/README_EN.md b/solution/3100-3199/3114.Latest Time You Can Obtain After Replacing Characters/README_EN.md index f08123c74c3f9..2c66f6fe67ef7 100644 --- a/solution/3100-3199/3114.Latest Time You Can Obtain After Replacing Characters/README_EN.md +++ b/solution/3100-3199/3114.Latest Time You Can Obtain After Replacing Characters/README_EN.md @@ -72,6 +72,8 @@ The time complexity is $O(h \times m)$, where $h = 12$ and $m = 60$. The space c +#### Python3 + ```python class Solution: def findLatestTime(self, s: str) -> str: @@ -82,6 +84,8 @@ class Solution: return t ``` +#### Java + ```java class Solution { public String findLatestTime(String s) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func findLatestTime(s string) string { for h := 11; ; h-- { @@ -148,6 +156,8 @@ func findLatestTime(s string) string { } ``` +#### TypeScript + ```ts function findLatestTime(s: string): string { for (let h = 11; ; h--) { @@ -187,6 +197,8 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def findLatestTime(self, s: str) -> str: @@ -202,6 +214,8 @@ class Solution: return "".join(s) ``` +#### Java + ```java class Solution { public String findLatestTime(String s) { @@ -223,6 +237,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -244,6 +260,8 @@ public: }; ``` +#### Go + ```go func findLatestTime(s string) string { cs := []byte(s) @@ -271,6 +289,8 @@ func findLatestTime(s string) string { } ``` +#### TypeScript + ```ts function findLatestTime(s: string): string { const cs = s.split(''); diff --git a/solution/3100-3199/3115.Maximum Prime Difference/README.md b/solution/3100-3199/3115.Maximum Prime Difference/README.md index f435eb403a637..3948ff94314e5 100644 --- a/solution/3100-3199/3115.Maximum Prime Difference/README.md +++ b/solution/3100-3199/3115.Maximum Prime Difference/README.md @@ -72,6 +72,8 @@ tags: +#### Python3 + ```python class Solution: def maximumPrimeDifference(self, nums: List[int]) -> int: @@ -87,6 +89,8 @@ class Solution: return j - i ``` +#### Java + ```java class Solution { public int maximumPrimeDifference(int[] nums) { @@ -115,6 +119,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -144,6 +150,8 @@ public: }; ``` +#### Go + ```go func maximumPrimeDifference(nums []int) int { for i := 0; ; i++ { @@ -170,6 +178,8 @@ func isPrime(n int) bool { } ``` +#### TypeScript + ```ts function maximumPrimeDifference(nums: number[]): number { const isPrime = (x: number): boolean => { diff --git a/solution/3100-3199/3115.Maximum Prime Difference/README_EN.md b/solution/3100-3199/3115.Maximum Prime Difference/README_EN.md index 415f1aee8165b..94c86a95a76af 100644 --- a/solution/3100-3199/3115.Maximum Prime Difference/README_EN.md +++ b/solution/3100-3199/3115.Maximum Prime Difference/README_EN.md @@ -70,6 +70,8 @@ The time complexity is $O(n \times \sqrt{M})$, where $n$ and $M$ are the length +#### Python3 + ```python class Solution: def maximumPrimeDifference(self, nums: List[int]) -> int: @@ -85,6 +87,8 @@ class Solution: return j - i ``` +#### Java + ```java class Solution { public int maximumPrimeDifference(int[] nums) { @@ -113,6 +117,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func maximumPrimeDifference(nums []int) int { for i := 0; ; i++ { @@ -168,6 +176,8 @@ func isPrime(n int) bool { } ``` +#### TypeScript + ```ts function maximumPrimeDifference(nums: number[]): number { const isPrime = (x: number): boolean => { diff --git a/solution/3100-3199/3116.Kth Smallest Amount With Single Denomination Combination/README.md b/solution/3100-3199/3116.Kth Smallest Amount With Single Denomination Combination/README.md index 6261433362981..b03cc3a720a45 100644 --- a/solution/3100-3199/3116.Kth Smallest Amount With Single Denomination Combination/README.md +++ b/solution/3100-3199/3116.Kth Smallest Amount With Single Denomination Combination/README.md @@ -127,6 +127,8 @@ $$ +#### Python3 + ```python class Solution: def findKthSmallest(self, coins: List[int], k: int) -> int: @@ -149,6 +151,8 @@ class Solution: return bisect_left(range(10**11), True, key=check) ``` +#### Java + ```java class Solution { private int[] coins; @@ -202,6 +206,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -245,6 +251,8 @@ public: }; ``` +#### Go + ```go func findKthSmallest(coins []int, k int) int64 { var r int = 1e11 @@ -285,6 +293,8 @@ func lcm(a, b int) int { } ``` +#### TypeScript + ```ts function findKthSmallest(coins: number[], k: number): number { let [l, r] = [1n, BigInt(1e11)]; diff --git a/solution/3100-3199/3116.Kth Smallest Amount With Single Denomination Combination/README_EN.md b/solution/3100-3199/3116.Kth Smallest Amount With Single Denomination Combination/README_EN.md index bc8b2f9e7b29f..9abce2b49aa89 100644 --- a/solution/3100-3199/3116.Kth Smallest Amount With Single Denomination Combination/README_EN.md +++ b/solution/3100-3199/3116.Kth Smallest Amount With Single Denomination Combination/README_EN.md @@ -131,6 +131,8 @@ The time complexity is $O(n \times 2^n \times \log (k \times M))$, where $n$ is +#### Python3 + ```python class Solution: def findKthSmallest(self, coins: List[int], k: int) -> int: @@ -153,6 +155,8 @@ class Solution: return bisect_left(range(10**11), True, key=check) ``` +#### Java + ```java class Solution { private int[] coins; @@ -206,6 +210,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -249,6 +255,8 @@ public: }; ``` +#### Go + ```go func findKthSmallest(coins []int, k int) int64 { var r int = 1e11 @@ -289,6 +297,8 @@ func lcm(a, b int) int { } ``` +#### TypeScript + ```ts function findKthSmallest(coins: number[], k: number): number { let [l, r] = [1n, BigInt(1e11)]; diff --git a/solution/3100-3199/3117.Minimum Sum of Values by Dividing Array/README.md b/solution/3100-3199/3117.Minimum Sum of Values by Dividing Array/README.md index 5dad41183b0d6..a70a1efd64bf1 100644 --- a/solution/3100-3199/3117.Minimum Sum of Values by Dividing Array/README.md +++ b/solution/3100-3199/3117.Minimum Sum of Values by Dividing Array/README.md @@ -122,6 +122,8 @@ tags: +#### Python3 + ```python class Solution: def minimumValueSum(self, nums: List[int], andValues: List[int]) -> int: @@ -144,6 +146,8 @@ class Solution: return ans if ans < inf else -1 ``` +#### Java + ```java class Solution { private int[] nums; @@ -184,6 +188,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -228,6 +234,8 @@ private: }; ``` +#### Go + ```go func minimumValueSum(nums []int, andValues []int) int { n, m := len(nums), len(andValues) @@ -266,6 +274,8 @@ func minimumValueSum(nums []int, andValues []int) int { } ``` +#### TypeScript + ```ts function minimumValueSum(nums: number[], andValues: number[]): number { const [n, m] = [nums.length, andValues.length]; diff --git a/solution/3100-3199/3117.Minimum Sum of Values by Dividing Array/README_EN.md b/solution/3100-3199/3117.Minimum Sum of Values by Dividing Array/README_EN.md index cde0683cc4177..1b6337782d412 100644 --- a/solution/3100-3199/3117.Minimum Sum of Values by Dividing Array/README_EN.md +++ b/solution/3100-3199/3117.Minimum Sum of Values by Dividing Array/README_EN.md @@ -120,6 +120,8 @@ The time complexity is $O(n \times m \times \log M)$, and the space complexity i +#### Python3 + ```python class Solution: def minimumValueSum(self, nums: List[int], andValues: List[int]) -> int: @@ -142,6 +144,8 @@ class Solution: return ans if ans < inf else -1 ``` +#### Java + ```java class Solution { private int[] nums; @@ -182,6 +186,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -226,6 +232,8 @@ private: }; ``` +#### Go + ```go func minimumValueSum(nums []int, andValues []int) int { n, m := len(nums), len(andValues) @@ -264,6 +272,8 @@ func minimumValueSum(nums []int, andValues []int) int { } ``` +#### TypeScript + ```ts function minimumValueSum(nums: number[], andValues: number[]): number { const [n, m] = [nums.length, andValues.length]; diff --git a/solution/3100-3199/3118.Friday Purchase III/README.md b/solution/3100-3199/3118.Friday Purchase III/README.md index 4ea2429141359..e410bb23e0d0e 100644 --- a/solution/3100-3199/3118.Friday Purchase III/README.md +++ b/solution/3100-3199/3118.Friday Purchase III/README.md @@ -134,6 +134,8 @@ Each row of this table indicates the user_id, membership type. +#### MySQL + ```sql # Write your MySQL query statement below WITH RECURSIVE diff --git a/solution/3100-3199/3118.Friday Purchase III/README_EN.md b/solution/3100-3199/3118.Friday Purchase III/README_EN.md index 01c8f7f8afd48..2c5beb9a8c00b 100644 --- a/solution/3100-3199/3118.Friday Purchase III/README_EN.md +++ b/solution/3100-3199/3118.Friday Purchase III/README_EN.md @@ -134,6 +134,8 @@ Next, we create a table `P` that includes `week_of_month`, `membership`, and `am +#### MySQL + ```sql # Write your MySQL query statement below WITH RECURSIVE diff --git a/solution/3100-3199/3119.Maximum Number of Potholes That Can Be Fixed/README.md b/solution/3100-3199/3119.Maximum Number of Potholes That Can Be Fixed/README.md index d9b2bf9fa4c69..66df692861657 100644 --- a/solution/3100-3199/3119.Maximum Number of Potholes That Can Be Fixed/README.md +++ b/solution/3100-3199/3119.Maximum Number of Potholes That Can Be Fixed/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def maxPotholes(self, road: str, budget: int) -> int: @@ -114,6 +116,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxPotholes(String road, int budget) { @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go func maxPotholes(road string, budget int) (ans int) { road += "." @@ -193,6 +201,8 @@ func maxPotholes(road string, budget int) (ans int) { } ``` +#### TypeScript + ```ts function maxPotholes(road: string, budget: number): number { road += '.'; @@ -218,6 +228,8 @@ function maxPotholes(road: string, budget: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_potholes(road: String, budget: i32) -> i32 { @@ -254,6 +266,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int MaxPotholes(string road, int budget) { diff --git a/solution/3100-3199/3119.Maximum Number of Potholes That Can Be Fixed/README_EN.md b/solution/3100-3199/3119.Maximum Number of Potholes That Can Be Fixed/README_EN.md index b92c2cac30b55..8b937a8299651 100644 --- a/solution/3100-3199/3119.Maximum Number of Potholes That Can Be Fixed/README_EN.md +++ b/solution/3100-3199/3119.Maximum Number of Potholes That Can Be Fixed/README_EN.md @@ -88,6 +88,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is +#### Python3 + ```python class Solution: def maxPotholes(self, road: str, budget: int) -> int: @@ -114,6 +116,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxPotholes(String road, int budget) { @@ -141,6 +145,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go func maxPotholes(road string, budget int) (ans int) { road += "." @@ -193,6 +201,8 @@ func maxPotholes(road string, budget int) (ans int) { } ``` +#### TypeScript + ```ts function maxPotholes(road: string, budget: number): number { road += '.'; @@ -218,6 +228,8 @@ function maxPotholes(road: string, budget: number): number { } ``` +#### Rust + ```rust impl Solution { pub fn max_potholes(road: String, budget: i32) -> i32 { @@ -254,6 +266,8 @@ impl Solution { } ``` +#### C# + ```cs public class Solution { public int MaxPotholes(string road, int budget) { diff --git a/solution/3100-3199/3120.Count the Number of Special Characters I/README.md b/solution/3100-3199/3120.Count the Number of Special Characters I/README.md index adb29aca006ab..694a4604adaac 100644 --- a/solution/3100-3199/3120.Count the Number of Special Characters I/README.md +++ b/solution/3100-3199/3120.Count the Number of Special Characters I/README.md @@ -86,6 +86,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfSpecialChars(self, word: str) -> int: @@ -93,6 +95,8 @@ class Solution: return sum(a in s and b in s for a, b in zip(ascii_lowercase, ascii_uppercase)) ``` +#### Java + ```java class Solution { public int numberOfSpecialChars(String word) { @@ -111,6 +115,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -128,6 +134,8 @@ public: }; ``` +#### Go + ```go func numberOfSpecialChars(word string) (ans int) { s := make([]bool, 'z'+1) @@ -143,6 +151,8 @@ func numberOfSpecialChars(word string) (ans int) { } ``` +#### TypeScript + ```ts function numberOfSpecialChars(word: string): number { const s: boolean[] = Array.from({ length: 'z'.charCodeAt(0) + 1 }, () => false); diff --git a/solution/3100-3199/3120.Count the Number of Special Characters I/README_EN.md b/solution/3100-3199/3120.Count the Number of Special Characters I/README_EN.md index 8d0d5f42e0cd4..587a075d80938 100644 --- a/solution/3100-3199/3120.Count the Number of Special Characters I/README_EN.md +++ b/solution/3100-3199/3120.Count the Number of Special Characters I/README_EN.md @@ -84,6 +84,8 @@ The time complexity is $O(n + |\Sigma|)$, and the space complexity is $O(|\Sigma +#### Python3 + ```python class Solution: def numberOfSpecialChars(self, word: str) -> int: @@ -91,6 +93,8 @@ class Solution: return sum(a in s and b in s for a, b in zip(ascii_lowercase, ascii_uppercase)) ``` +#### Java + ```java class Solution { public int numberOfSpecialChars(String word) { @@ -109,6 +113,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -126,6 +132,8 @@ public: }; ``` +#### Go + ```go func numberOfSpecialChars(word string) (ans int) { s := make([]bool, 'z'+1) @@ -141,6 +149,8 @@ func numberOfSpecialChars(word string) (ans int) { } ``` +#### TypeScript + ```ts function numberOfSpecialChars(word: string): number { const s: boolean[] = Array.from({ length: 'z'.charCodeAt(0) + 1 }, () => false); diff --git a/solution/3100-3199/3121.Count the Number of Special Characters II/README.md b/solution/3100-3199/3121.Count the Number of Special Characters II/README.md index 09d5e048a1bc7..915daadef689b 100644 --- a/solution/3100-3199/3121.Count the Number of Special Characters II/README.md +++ b/solution/3100-3199/3121.Count the Number of Special Characters II/README.md @@ -88,6 +88,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfSpecialChars(self, word: str) -> int: @@ -102,6 +104,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public int numberOfSpecialChars(String word) { @@ -125,6 +129,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func numberOfSpecialChars(word string) (ans int) { first := make([]int, 'z'+1) @@ -168,6 +176,8 @@ func numberOfSpecialChars(word string) (ans int) { } ``` +#### TypeScript + ```ts function numberOfSpecialChars(word: string): number { const first: number[] = Array.from({ length: 'z'.charCodeAt(0) + 1 }, () => 0); diff --git a/solution/3100-3199/3121.Count the Number of Special Characters II/README_EN.md b/solution/3100-3199/3121.Count the Number of Special Characters II/README_EN.md index 2fcdaef9650ca..a64fcfefe9f67 100644 --- a/solution/3100-3199/3121.Count the Number of Special Characters II/README_EN.md +++ b/solution/3100-3199/3121.Count the Number of Special Characters II/README_EN.md @@ -86,6 +86,8 @@ The time complexity is $O(n + |\Sigma|)$, and the space complexity is $O(|\Sigma +#### Python3 + ```python class Solution: def numberOfSpecialChars(self, word: str) -> int: @@ -100,6 +102,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public int numberOfSpecialChars(String word) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func numberOfSpecialChars(word string) (ans int) { first := make([]int, 'z'+1) @@ -166,6 +174,8 @@ func numberOfSpecialChars(word string) (ans int) { } ``` +#### TypeScript + ```ts function numberOfSpecialChars(word: string): number { const first: number[] = Array.from({ length: 'z'.charCodeAt(0) + 1 }, () => 0); diff --git a/solution/3100-3199/3122.Minimum Number of Operations to Satisfy Conditions/README.md b/solution/3100-3199/3122.Minimum Number of Operations to Satisfy Conditions/README.md index b8771236eebe1..f7451e714ecfe 100644 --- a/solution/3100-3199/3122.Minimum Number of Operations to Satisfy Conditions/README.md +++ b/solution/3100-3199/3122.Minimum Number of Operations to Satisfy Conditions/README.md @@ -112,6 +112,8 @@ $$ +#### Python3 + ```python class Solution: def minimumOperations(self, grid: List[List[int]]) -> int: @@ -132,6 +134,8 @@ class Solution: return min(f[-1]) ``` +#### Java + ```java class Solution { public int minimumOperations(int[][] grid) { @@ -169,6 +173,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -200,6 +206,8 @@ public: }; ``` +#### Go + ```go func minimumOperations(grid [][]int) int { m, n := len(grid), len(grid[0]) @@ -233,6 +241,8 @@ func minimumOperations(grid [][]int) int { } ``` +#### TypeScript + ```ts function minimumOperations(grid: number[][]): number { const m = grid.length; diff --git a/solution/3100-3199/3122.Minimum Number of Operations to Satisfy Conditions/README_EN.md b/solution/3100-3199/3122.Minimum Number of Operations to Satisfy Conditions/README_EN.md index 38805c994d95d..08af516eed734 100644 --- a/solution/3100-3199/3122.Minimum Number of Operations to Satisfy Conditions/README_EN.md +++ b/solution/3100-3199/3122.Minimum Number of Operations to Satisfy Conditions/README_EN.md @@ -110,6 +110,8 @@ The time complexity is $O(n \times (m + C^2))$, and the space complexity is $O(n +#### Python3 + ```python class Solution: def minimumOperations(self, grid: List[List[int]]) -> int: @@ -130,6 +132,8 @@ class Solution: return min(f[-1]) ``` +#### Java + ```java class Solution { public int minimumOperations(int[][] grid) { @@ -167,6 +171,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -198,6 +204,8 @@ public: }; ``` +#### Go + ```go func minimumOperations(grid [][]int) int { m, n := len(grid), len(grid[0]) @@ -231,6 +239,8 @@ func minimumOperations(grid [][]int) int { } ``` +#### TypeScript + ```ts function minimumOperations(grid: number[][]): number { const m = grid.length; diff --git a/solution/3100-3199/3123.Find Edges in Shortest Paths/README.md b/solution/3100-3199/3123.Find Edges in Shortest Paths/README.md index e2c0be3c37a83..620b4e990b844 100644 --- a/solution/3100-3199/3123.Find Edges in Shortest Paths/README.md +++ b/solution/3100-3199/3123.Find Edges in Shortest Paths/README.md @@ -105,6 +105,8 @@ tags: +#### Python3 + ```python class Solution: def findAnswer(self, n: int, edges: List[List[int]]) -> List[bool]: @@ -137,6 +139,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public boolean[] findAnswer(int n, int[][] edges) { @@ -189,6 +193,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -243,6 +249,8 @@ public: }; ``` +#### Go + ```go func findAnswer(n int, edges [][]int) []bool { g := make([][][3]int, n) diff --git a/solution/3100-3199/3123.Find Edges in Shortest Paths/README_EN.md b/solution/3100-3199/3123.Find Edges in Shortest Paths/README_EN.md index 16c097596f6d3..5d1e613d19ccf 100644 --- a/solution/3100-3199/3123.Find Edges in Shortest Paths/README_EN.md +++ b/solution/3100-3199/3123.Find Edges in Shortest Paths/README_EN.md @@ -99,6 +99,8 @@ The time complexity is $O(m \times \log m)$, and the space complexity is $O(n + +#### Python3 + ```python class Solution: def findAnswer(self, n: int, edges: List[List[int]]) -> List[bool]: @@ -131,6 +133,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public boolean[] findAnswer(int n, int[][] edges) { @@ -183,6 +187,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -237,6 +243,8 @@ public: }; ``` +#### Go + ```go func findAnswer(n int, edges [][]int) []bool { g := make([][][3]int, n) diff --git a/solution/3100-3199/3124.Find Longest Calls/README.md b/solution/3100-3199/3124.Find Longest Calls/README.md index 8b6e084bc52a5..4ed98747439e3 100644 --- a/solution/3100-3199/3124.Find Longest Calls/README.md +++ b/solution/3100-3199/3124.Find Longest Calls/README.md @@ -133,6 +133,8 @@ id 是 Calls 表的外键(引用列)。 +#### MySQL + ```sql WITH T AS ( @@ -157,6 +159,8 @@ WHERE rk <= 3 ORDER BY 2, 3 DESC, 1 DESC; ``` +#### Python3 + ```python import pandas as pd diff --git a/solution/3100-3199/3124.Find Longest Calls/README_EN.md b/solution/3100-3199/3124.Find Longest Calls/README_EN.md index 20d795c455b29..8f9215c557c1f 100644 --- a/solution/3100-3199/3124.Find Longest Calls/README_EN.md +++ b/solution/3100-3199/3124.Find Longest Calls/README_EN.md @@ -132,6 +132,8 @@ We can use equi-join to connect the two tables, and then use the window function +#### MySQL + ```sql WITH T AS ( @@ -156,6 +158,8 @@ WHERE rk <= 3 ORDER BY 2, 3 DESC, 1 DESC; ``` +#### Python3 + ```python import pandas as pd diff --git a/solution/3100-3199/3125.Maximum Number That Makes Result of Bitwise AND Zero/README.md b/solution/3100-3199/3125.Maximum Number That Makes Result of Bitwise AND Zero/README.md index 420d977399c9b..39d09eda95a83 100644 --- a/solution/3100-3199/3125.Maximum Number That Makes Result of Bitwise AND Zero/README.md +++ b/solution/3100-3199/3125.Maximum Number That Makes Result of Bitwise AND Zero/README.md @@ -86,12 +86,16 @@ tags: +#### Python3 + ```python class Solution: def maxNumber(self, n: int) -> int: return (1 << (n.bit_length() - 1)) - 1 ``` +#### Java + ```java class Solution { public long maxNumber(long n) { @@ -100,6 +104,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -109,6 +115,8 @@ public: }; ``` +#### Go + ```go func maxNumber(n int64) int64 { return int64(1<<(bits.Len64(uint64(n))-1)) - 1 diff --git a/solution/3100-3199/3125.Maximum Number That Makes Result of Bitwise AND Zero/README_EN.md b/solution/3100-3199/3125.Maximum Number That Makes Result of Bitwise AND Zero/README_EN.md index cc6bdbb6086be..e211a32d8909a 100644 --- a/solution/3100-3199/3125.Maximum Number That Makes Result of Bitwise AND Zero/README_EN.md +++ b/solution/3100-3199/3125.Maximum Number That Makes Result of Bitwise AND Zero/README_EN.md @@ -81,12 +81,16 @@ The time complexity is $O(\log n)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def maxNumber(self, n: int) -> int: return (1 << (n.bit_length() - 1)) - 1 ``` +#### Java + ```java class Solution { public long maxNumber(long n) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -104,6 +110,8 @@ public: }; ``` +#### Go + ```go func maxNumber(n int64) int64 { return int64(1<<(bits.Len64(uint64(n))-1)) - 1 diff --git a/solution/3100-3199/3126.Server Utilization Time/README.md b/solution/3100-3199/3126.Server Utilization Time/README.md index 76312c92fea0c..c61839c8dcf92 100644 --- a/solution/3100-3199/3126.Server Utilization Time/README.md +++ b/solution/3100-3199/3126.Server Utilization Time/README.md @@ -126,6 +126,8 @@ The accumulated runtime for all servers totals approximately 44.46 hours, equiva +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/3100-3199/3126.Server Utilization Time/README_EN.md b/solution/3100-3199/3126.Server Utilization Time/README_EN.md index 8047bf21d3b2d..a00197a175095 100644 --- a/solution/3100-3199/3126.Server Utilization Time/README_EN.md +++ b/solution/3100-3199/3126.Server Utilization Time/README_EN.md @@ -126,6 +126,8 @@ We can use the window function `LEAD` to get the time of the next status for eac +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/3100-3199/3127.Make a Square with the Same Color/README.md b/solution/3100-3199/3127.Make a Square with the Same Color/README.md index 017ddfef91283..403f8e5a47f10 100644 --- a/solution/3100-3199/3127.Make a Square with the Same Color/README.md +++ b/solution/3100-3199/3127.Make a Square with the Same Color/README.md @@ -167,6 +167,8 @@ tags: +#### Python3 + ```python class Solution: def canMakeSquare(self, grid: List[List[str]]) -> bool: @@ -182,6 +184,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean canMakeSquare(char[][] grid) { @@ -204,6 +208,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -227,6 +233,8 @@ public: }; ``` +#### Go + ```go func canMakeSquare(grid [][]byte) bool { dirs := [5]int{0, 0, 1, 1, 0} @@ -250,6 +258,8 @@ func canMakeSquare(grid [][]byte) bool { } ``` +#### TypeScript + ```ts function canMakeSquare(grid: string[][]): boolean { const dirs: number[] = [0, 0, 1, 1, 0]; diff --git a/solution/3100-3199/3127.Make a Square with the Same Color/README_EN.md b/solution/3100-3199/3127.Make a Square with the Same Color/README_EN.md index 30f967cb300bf..837836f515f2c 100644 --- a/solution/3100-3199/3127.Make a Square with the Same Color/README_EN.md +++ b/solution/3100-3199/3127.Make a Square with the Same Color/README_EN.md @@ -166,6 +166,8 @@ The time complexity is $O(1)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def canMakeSquare(self, grid: List[List[str]]) -> bool: @@ -181,6 +183,8 @@ class Solution: return False ``` +#### Java + ```java class Solution { public boolean canMakeSquare(char[][] grid) { @@ -203,6 +207,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -226,6 +232,8 @@ public: }; ``` +#### Go + ```go func canMakeSquare(grid [][]byte) bool { dirs := [5]int{0, 0, 1, 1, 0} @@ -249,6 +257,8 @@ func canMakeSquare(grid [][]byte) bool { } ``` +#### TypeScript + ```ts function canMakeSquare(grid: string[][]): boolean { const dirs: number[] = [0, 0, 1, 1, 0]; diff --git a/solution/3100-3199/3128.Right Triangles/README.md b/solution/3100-3199/3128.Right Triangles/README.md index 14c43833bfeea..d105cd34aae93 100644 --- a/solution/3100-3199/3128.Right Triangles/README.md +++ b/solution/3100-3199/3128.Right Triangles/README.md @@ -205,6 +205,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfRightTriangles(self, grid: List[List[int]]) -> int: @@ -222,6 +224,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long numberOfRightTriangles(int[][] grid) { @@ -247,6 +251,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -273,6 +279,8 @@ public: }; ``` +#### Go + ```go func numberOfRightTriangles(grid [][]int) (ans int64) { m, n := len(grid), len(grid[0]) @@ -295,6 +303,8 @@ func numberOfRightTriangles(grid [][]int) (ans int64) { } ``` +#### TypeScript + ```ts function numberOfRightTriangles(grid: number[][]): number { const m = grid.length; diff --git a/solution/3100-3199/3128.Right Triangles/README_EN.md b/solution/3100-3199/3128.Right Triangles/README_EN.md index 7335a9e3e570f..ed41f2c70beaf 100644 --- a/solution/3100-3199/3128.Right Triangles/README_EN.md +++ b/solution/3100-3199/3128.Right Triangles/README_EN.md @@ -203,6 +203,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m + n)$. +#### Python3 + ```python class Solution: def numberOfRightTriangles(self, grid: List[List[int]]) -> int: @@ -220,6 +222,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long numberOfRightTriangles(int[][] grid) { @@ -245,6 +249,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -271,6 +277,8 @@ public: }; ``` +#### Go + ```go func numberOfRightTriangles(grid [][]int) (ans int64) { m, n := len(grid), len(grid[0]) @@ -293,6 +301,8 @@ func numberOfRightTriangles(grid [][]int) (ans int64) { } ``` +#### TypeScript + ```ts function numberOfRightTriangles(grid: number[][]): number { const m = grid.length; diff --git a/solution/3100-3199/3129.Find All Possible Stable Binary Arrays I/README.md b/solution/3100-3199/3129.Find All Possible Stable Binary Arrays I/README.md index 8951346ac859d..8d975b6c1078b 100644 --- a/solution/3100-3199/3129.Find All Possible Stable Binary Arrays I/README.md +++ b/solution/3100-3199/3129.Find All Possible Stable Binary Arrays I/README.md @@ -105,6 +105,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfStableArrays(self, zero: int, one: int, limit: int) -> int: @@ -132,6 +134,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private final int mod = (int) 1e9 + 7; @@ -169,6 +173,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -209,6 +215,8 @@ private: }; ``` +#### Go + ```go func numberOfStableArrays(zero int, one int, limit int) int { const mod int = 1e9 + 7 @@ -274,6 +282,8 @@ func numberOfStableArrays(zero int, one int, limit int) int { +#### Python3 + ```python class Solution: def numberOfStableArrays(self, zero: int, one: int, limit: int) -> int: @@ -298,6 +308,8 @@ class Solution: return sum(f[zero][one]) % mod ``` +#### Java + ```java class Solution { public int numberOfStableArrays(int zero, int one, int limit) { @@ -324,6 +336,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -353,6 +367,8 @@ public: }; ``` +#### Go + ```go func numberOfStableArrays(zero int, one int, limit int) int { const mod int = 1e9 + 7 diff --git a/solution/3100-3199/3129.Find All Possible Stable Binary Arrays I/README_EN.md b/solution/3100-3199/3129.Find All Possible Stable Binary Arrays I/README_EN.md index bccf38f9502bb..35924ccabd7d6 100644 --- a/solution/3100-3199/3129.Find All Possible Stable Binary Arrays I/README_EN.md +++ b/solution/3100-3199/3129.Find All Possible Stable Binary Arrays I/README_EN.md @@ -98,6 +98,8 @@ The calculation process of the function $dfs(i, j, k)$ is as follows: +#### Python3 + ```python class Solution: def numberOfStableArrays(self, zero: int, one: int, limit: int) -> int: @@ -125,6 +127,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private final int mod = (int) 1e9 + 7; @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -200,6 +206,8 @@ private: }; ``` +#### Go + ```go func numberOfStableArrays(zero int, one int, limit int) int { const mod int = 1e9 + 7 @@ -265,6 +273,8 @@ The time complexity is $O(zero \times one)$, and the space complexity is $O(zero +#### Python3 + ```python class Solution: def numberOfStableArrays(self, zero: int, one: int, limit: int) -> int: @@ -289,6 +299,8 @@ class Solution: return sum(f[zero][one]) % mod ``` +#### Java + ```java class Solution { private final int mod = (int) 1e9 + 7; @@ -326,6 +338,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -355,6 +369,8 @@ public: }; ``` +#### Go + ```go func numberOfStableArrays(zero int, one int, limit int) int { const mod int = 1e9 + 7 diff --git a/solution/3100-3199/3130.Find All Possible Stable Binary Arrays II/README.md b/solution/3100-3199/3130.Find All Possible Stable Binary Arrays II/README.md index e7d600e9331dd..992561be84377 100644 --- a/solution/3100-3199/3130.Find All Possible Stable Binary Arrays II/README.md +++ b/solution/3100-3199/3130.Find All Possible Stable Binary Arrays II/README.md @@ -105,6 +105,8 @@ tags: +#### Python3 + ```python class Solution: def numberOfStableArrays(self, zero: int, one: int, limit: int) -> int: @@ -132,6 +134,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private final int mod = (int) 1e9 + 7; @@ -169,6 +173,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -209,6 +215,8 @@ private: }; ``` +#### Go + ```go func numberOfStableArrays(zero int, one int, limit int) int { const mod int = 1e9 + 7 @@ -274,6 +282,8 @@ func numberOfStableArrays(zero int, one int, limit int) int { +#### Python3 + ```python class Solution: def numberOfStableArrays(self, zero: int, one: int, limit: int) -> int: @@ -298,6 +308,8 @@ class Solution: return sum(f[zero][one]) % mod ``` +#### Java + ```java class Solution { public int numberOfStableArrays(int zero, int one, int limit) { @@ -324,6 +336,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -353,6 +367,8 @@ public: }; ``` +#### Go + ```go func numberOfStableArrays(zero int, one int, limit int) int { const mod int = 1e9 + 7 diff --git a/solution/3100-3199/3130.Find All Possible Stable Binary Arrays II/README_EN.md b/solution/3100-3199/3130.Find All Possible Stable Binary Arrays II/README_EN.md index 578c139108a70..cfc043bbd5b40 100644 --- a/solution/3100-3199/3130.Find All Possible Stable Binary Arrays II/README_EN.md +++ b/solution/3100-3199/3130.Find All Possible Stable Binary Arrays II/README_EN.md @@ -96,6 +96,8 @@ The calculation process of the function $dfs(i, j, k)$ is as follows: +#### Python3 + ```python class Solution: def numberOfStableArrays(self, zero: int, one: int, limit: int) -> int: @@ -123,6 +125,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private final int mod = (int) 1e9 + 7; @@ -160,6 +164,8 @@ class Solution { } ``` +#### C++ + ```cpp using ll = long long; @@ -200,6 +206,8 @@ private: }; ``` +#### Go + ```go func numberOfStableArrays(zero int, one int, limit int) int { const mod int = 1e9 + 7 @@ -265,6 +273,8 @@ The time complexity is $O(zero \times one)$, and the space complexity is $O(zero +#### Python3 + ```python class Solution: def numberOfStableArrays(self, zero: int, one: int, limit: int) -> int: @@ -289,6 +299,8 @@ class Solution: return sum(f[zero][one]) % mod ``` +#### Java + ```java class Solution { public int numberOfStableArrays(int zero, int one, int limit) { @@ -315,6 +327,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -344,6 +358,8 @@ public: }; ``` +#### Go + ```go func numberOfStableArrays(zero int, one int, limit int) int { const mod int = 1e9 + 7 diff --git a/solution/3100-3199/3131.Find the Integer Added to Array I/README.md b/solution/3100-3199/3131.Find the Integer Added to Array I/README.md index d585b4b14da4a..8ec9d08345092 100644 --- a/solution/3100-3199/3131.Find the Integer Added to Array I/README.md +++ b/solution/3100-3199/3131.Find the Integer Added to Array I/README.md @@ -106,12 +106,16 @@ tags: +#### Python3 + ```python class Solution: def addedInteger(self, nums1: List[int], nums2: List[int]) -> int: return min(nums2) - min(nums1) ``` +#### Java + ```java class Solution { public int addedInteger(int[] nums1, int[] nums2) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -129,12 +135,16 @@ public: }; ``` +#### Go + ```go func addedInteger(nums1 []int, nums2 []int) int { return slices.Min(nums2) - slices.Min(nums1) } ``` +#### TypeScript + ```ts function addedInteger(nums1: number[], nums2: number[]): number { return Math.min(...nums2) - Math.min(...nums1); diff --git a/solution/3100-3199/3131.Find the Integer Added to Array I/README_EN.md b/solution/3100-3199/3131.Find the Integer Added to Array I/README_EN.md index d6c89ef4a174d..a2ac7dc052f4f 100644 --- a/solution/3100-3199/3131.Find the Integer Added to Array I/README_EN.md +++ b/solution/3100-3199/3131.Find the Integer Added to Array I/README_EN.md @@ -104,12 +104,16 @@ The time complexity is $O(n)$, where $n$ is the length of the array. The space c +#### Python3 + ```python class Solution: def addedInteger(self, nums1: List[int], nums2: List[int]) -> int: return min(nums2) - min(nums1) ``` +#### Java + ```java class Solution { public int addedInteger(int[] nums1, int[] nums2) { @@ -118,6 +122,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -127,12 +133,16 @@ public: }; ``` +#### Go + ```go func addedInteger(nums1 []int, nums2 []int) int { return slices.Min(nums2) - slices.Min(nums1) } ``` +#### TypeScript + ```ts function addedInteger(nums1: number[], nums2: number[]): number { return Math.min(...nums2) - Math.min(...nums1); diff --git a/solution/3100-3199/3132.Find the Integer Added to Array II/README.md b/solution/3100-3199/3132.Find the Integer Added to Array II/README.md index 84131df8d1305..5fa21531a3008 100644 --- a/solution/3100-3199/3132.Find the Integer Added to Array II/README.md +++ b/solution/3100-3199/3132.Find the Integer Added to Array II/README.md @@ -92,6 +92,8 @@ tags: +#### Python3 + ```python class Solution: def minimumAddedInteger(self, nums1: List[int], nums2: List[int]) -> int: @@ -114,6 +116,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public int minimumAddedInteger(int[] nums1, int[] nums2) { @@ -144,6 +148,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -174,6 +180,8 @@ public: }; ``` +#### Go + ```go func minimumAddedInteger(nums1 []int, nums2 []int) int { sort.Ints(nums1) @@ -201,6 +209,8 @@ func minimumAddedInteger(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function minimumAddedInteger(nums1: number[], nums2: number[]): number { nums1.sort((a, b) => a - b); diff --git a/solution/3100-3199/3132.Find the Integer Added to Array II/README_EN.md b/solution/3100-3199/3132.Find the Integer Added to Array II/README_EN.md index a77b2f358e923..14781b2a25c71 100644 --- a/solution/3100-3199/3132.Find the Integer Added to Array II/README_EN.md +++ b/solution/3100-3199/3132.Find the Integer Added to Array II/README_EN.md @@ -90,6 +90,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log +#### Python3 + ```python class Solution: def minimumAddedInteger(self, nums1: List[int], nums2: List[int]) -> int: @@ -112,6 +114,8 @@ class Solution: ) ``` +#### Java + ```java class Solution { public int minimumAddedInteger(int[] nums1, int[] nums2) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -172,6 +178,8 @@ public: }; ``` +#### Go + ```go func minimumAddedInteger(nums1 []int, nums2 []int) int { sort.Ints(nums1) @@ -199,6 +207,8 @@ func minimumAddedInteger(nums1 []int, nums2 []int) int { } ``` +#### TypeScript + ```ts function minimumAddedInteger(nums1: number[], nums2: number[]): number { nums1.sort((a, b) => a - b); diff --git a/solution/3100-3199/3133.Minimum Array End/README.md b/solution/3100-3199/3133.Minimum Array End/README.md index d0962d10bf2d4..6a73df88b9752 100644 --- a/solution/3100-3199/3133.Minimum Array End/README.md +++ b/solution/3100-3199/3133.Minimum Array End/README.md @@ -76,6 +76,8 @@ tags: +#### Python3 + ```python class Solution: def minEnd(self, n: int, x: int) -> int: @@ -89,6 +91,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long minEnd(int n, int x) { @@ -106,6 +110,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -124,6 +130,8 @@ public: }; ``` +#### Go + ```go func minEnd(n int, x int) (ans int64) { n-- @@ -139,6 +147,8 @@ func minEnd(n int, x int) (ans int64) { } ``` +#### TypeScript + ```ts function minEnd(n: number, x: number): number { --n; diff --git a/solution/3100-3199/3133.Minimum Array End/README_EN.md b/solution/3100-3199/3133.Minimum Array End/README_EN.md index 2dcccbdcf00d8..8a83149fe3bad 100644 --- a/solution/3100-3199/3133.Minimum Array End/README_EN.md +++ b/solution/3100-3199/3133.Minimum Array End/README_EN.md @@ -74,6 +74,8 @@ The time complexity is $O(\log x)$, and the space complexity is $O(1)$. +#### Python3 + ```python class Solution: def minEnd(self, n: int, x: int) -> int: @@ -87,6 +89,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public long minEnd(int n, int x) { @@ -104,6 +108,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -122,6 +128,8 @@ public: }; ``` +#### Go + ```go func minEnd(n int, x int) (ans int64) { n-- @@ -137,6 +145,8 @@ func minEnd(n int, x int) (ans int64) { } ``` +#### TypeScript + ```ts function minEnd(n: number, x: number): number { --n; diff --git a/solution/3100-3199/3134.Find the Median of the Uniqueness Array/README.md b/solution/3100-3199/3134.Find the Median of the Uniqueness Array/README.md index 3468723de91a9..adfa421aafb35 100644 --- a/solution/3100-3199/3134.Find the Median of the Uniqueness Array/README.md +++ b/solution/3100-3199/3134.Find the Median of the Uniqueness Array/README.md @@ -88,18 +88,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/3100-3199/3134.Find the Median of the Uniqueness Array/README_EN.md b/solution/3100-3199/3134.Find the Median of the Uniqueness Array/README_EN.md index 37891a63110f5..fecdc83f62b45 100644 --- a/solution/3100-3199/3134.Find the Median of the Uniqueness Array/README_EN.md +++ b/solution/3100-3199/3134.Find the Median of the Uniqueness Array/README_EN.md @@ -84,18 +84,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/3100-3199/3135.Equalize Strings by Adding or Removing Characters at Ends/README.md b/solution/3100-3199/3135.Equalize Strings by Adding or Removing Characters at Ends/README.md index 6db10777ef132..43ea1bc598fff 100644 --- a/solution/3100-3199/3135.Equalize Strings by Adding or Removing Characters at Ends/README.md +++ b/solution/3100-3199/3135.Equalize Strings by Adding or Removing Characters at Ends/README.md @@ -129,6 +129,8 @@ $$ +#### Python3 + ```python class Solution: def minOperations(self, initial: str, target: str) -> int: @@ -143,6 +145,8 @@ class Solution: return m + n - mx * 2 ``` +#### Java + ```java class Solution { public int minOperations(String initial, String target) { @@ -162,6 +166,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -183,6 +189,8 @@ public: }; ``` +#### Go + ```go func minOperations(initial string, target string) int { m, n := len(initial), len(target) @@ -203,6 +211,8 @@ func minOperations(initial string, target string) int { } ``` +#### TypeScript + ```ts function minOperations(initial: string, target: string): number { const m = initial.length; diff --git a/solution/3100-3199/3135.Equalize Strings by Adding or Removing Characters at Ends/README_EN.md b/solution/3100-3199/3135.Equalize Strings by Adding or Removing Characters at Ends/README_EN.md index dde8887d5df97..511240f056ad1 100644 --- a/solution/3100-3199/3135.Equalize Strings by Adding or Removing Characters at Ends/README_EN.md +++ b/solution/3100-3199/3135.Equalize Strings by Adding or Removing Characters at Ends/README_EN.md @@ -129,6 +129,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def minOperations(self, initial: str, target: str) -> int: @@ -143,6 +145,8 @@ class Solution: return m + n - mx * 2 ``` +#### Java + ```java class Solution { public int minOperations(String initial, String target) { @@ -162,6 +166,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -183,6 +189,8 @@ public: }; ``` +#### Go + ```go func minOperations(initial string, target string) int { m, n := len(initial), len(target) @@ -203,6 +211,8 @@ func minOperations(initial string, target string) int { } ``` +#### TypeScript + ```ts function minOperations(initial: string, target: string): number { const m = initial.length; diff --git a/solution/3100-3199/3136.Valid Word/README.md b/solution/3100-3199/3136.Valid Word/README.md index abde41507fe06..3c6f8d5733a46 100644 --- a/solution/3100-3199/3136.Valid Word/README.md +++ b/solution/3100-3199/3136.Valid Word/README.md @@ -101,6 +101,8 @@ tags: +#### Python3 + ```python class Solution: def isValid(self, word: str) -> bool: @@ -119,6 +121,8 @@ class Solution: return has_vowel and has_consonant ``` +#### Java + ```java class Solution { public boolean isValid(String word) { @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go func isValid(word string) bool { if len(word) < 3 { @@ -201,6 +209,8 @@ func isValid(word string) bool { } ``` +#### TypeScript + ```ts function isValid(word: string): boolean { if (word.length < 3) { diff --git a/solution/3100-3199/3136.Valid Word/README_EN.md b/solution/3100-3199/3136.Valid Word/README_EN.md index 288858255190e..a9adb8b47100e 100644 --- a/solution/3100-3199/3136.Valid Word/README_EN.md +++ b/solution/3100-3199/3136.Valid Word/README_EN.md @@ -101,6 +101,8 @@ The time complexity is $O(n)$, and the space complexity is $O(1)$. Where $n$ is +#### Python3 + ```python class Solution: def isValid(self, word: str) -> bool: @@ -119,6 +121,8 @@ class Solution: return has_vowel and has_consonant ``` +#### Java + ```java class Solution { public boolean isValid(String word) { @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -175,6 +181,8 @@ public: }; ``` +#### Go + ```go func isValid(word string) bool { if len(word) < 3 { @@ -201,6 +209,8 @@ func isValid(word string) bool { } ``` +#### TypeScript + ```ts function isValid(word: string): boolean { if (word.length < 3) { diff --git a/solution/3100-3199/3137.Minimum Number of Operations to Make Word K-Periodic/README.md b/solution/3100-3199/3137.Minimum Number of Operations to Make Word K-Periodic/README.md index 26e6e0f7be86d..a2a5f3d0250a7 100644 --- a/solution/3100-3199/3137.Minimum Number of Operations to Make Word K-Periodic/README.md +++ b/solution/3100-3199/3137.Minimum Number of Operations to Make Word K-Periodic/README.md @@ -127,6 +127,8 @@ font-size: 0.85rem; +#### Python3 + ```python class Solution: def minimumOperationsToMakeKPeriodic(self, word: str, k: int) -> int: @@ -134,6 +136,8 @@ class Solution: return n // k - max(Counter(word[i : i + k] for i in range(0, n, k)).values()) ``` +#### Java + ```java class Solution { public int minimumOperationsToMakeKPeriodic(String word, int k) { @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -163,6 +169,8 @@ public: }; ``` +#### Go + ```go func minimumOperationsToMakeKPeriodic(word string, k int) int { cnt := map[string]int{} @@ -177,6 +185,8 @@ func minimumOperationsToMakeKPeriodic(word string, k int) int { } ``` +#### TypeScript + ```ts function minimumOperationsToMakeKPeriodic(word: string, k: number): number { const cnt: Map = new Map(); diff --git a/solution/3100-3199/3137.Minimum Number of Operations to Make Word K-Periodic/README_EN.md b/solution/3100-3199/3137.Minimum Number of Operations to Make Word K-Periodic/README_EN.md index 8daec2f603358..c98250b26aeab 100644 --- a/solution/3100-3199/3137.Minimum Number of Operations to Make Word K-Periodic/README_EN.md +++ b/solution/3100-3199/3137.Minimum Number of Operations to Make Word K-Periodic/README_EN.md @@ -118,6 +118,8 @@ The time complexity is $O(n)$, and the space complexity is $O(n)$. Where $n$ is +#### Python3 + ```python class Solution: def minimumOperationsToMakeKPeriodic(self, word: str, k: int) -> int: @@ -125,6 +127,8 @@ class Solution: return n // k - max(Counter(word[i : i + k] for i in range(0, n, k)).values()) ``` +#### Java + ```java class Solution { public int minimumOperationsToMakeKPeriodic(String word, int k) { @@ -139,6 +143,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -154,6 +160,8 @@ public: }; ``` +#### Go + ```go func minimumOperationsToMakeKPeriodic(word string, k int) int { cnt := map[string]int{} @@ -168,6 +176,8 @@ func minimumOperationsToMakeKPeriodic(word string, k int) int { } ``` +#### TypeScript + ```ts function minimumOperationsToMakeKPeriodic(word: string, k: number): number { const cnt: Map = new Map(); diff --git a/solution/3100-3199/3138.Minimum Length of Anagram Concatenation/README.md b/solution/3100-3199/3138.Minimum Length of Anagram Concatenation/README.md index c52eabcb16525..6a0acbf169245 100644 --- a/solution/3100-3199/3138.Minimum Length of Anagram Concatenation/README.md +++ b/solution/3100-3199/3138.Minimum Length of Anagram Concatenation/README.md @@ -71,18 +71,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/3100-3199/3138.Minimum Length of Anagram Concatenation/README_EN.md b/solution/3100-3199/3138.Minimum Length of Anagram Concatenation/README_EN.md index 3e58568762877..2d0227af66cb4 100644 --- a/solution/3100-3199/3138.Minimum Length of Anagram Concatenation/README_EN.md +++ b/solution/3100-3199/3138.Minimum Length of Anagram Concatenation/README_EN.md @@ -69,18 +69,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/3100-3199/3139.Minimum Cost to Equalize Array/README.md b/solution/3100-3199/3139.Minimum Cost to Equalize Array/README.md index 3f11d09f518a5..4a1856f7904b8 100644 --- a/solution/3100-3199/3139.Minimum Cost to Equalize Array/README.md +++ b/solution/3100-3199/3139.Minimum Cost to Equalize Array/README.md @@ -117,18 +117,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/3100-3199/3139.Minimum Cost to Equalize Array/README_EN.md b/solution/3100-3199/3139.Minimum Cost to Equalize Array/README_EN.md index 4db0cbd41ce30..6ba8643735da5 100644 --- a/solution/3100-3199/3139.Minimum Cost to Equalize Array/README_EN.md +++ b/solution/3100-3199/3139.Minimum Cost to Equalize Array/README_EN.md @@ -115,18 +115,26 @@ tags: +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/3100-3199/3140.Consecutive Available Seats II/README.md b/solution/3100-3199/3140.Consecutive Available Seats II/README.md index 8c827fb5a24d3..67087013b22c6 100644 --- a/solution/3100-3199/3140.Consecutive Available Seats II/README.md +++ b/solution/3100-3199/3140.Consecutive Available Seats II/README.md @@ -92,6 +92,8 @@ seat_id 是这张表中的自增列。 +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/3100-3199/3140.Consecutive Available Seats II/README_EN.md b/solution/3100-3199/3140.Consecutive Available Seats II/README_EN.md index 4a9e7737c02c8..57993de495837 100644 --- a/solution/3100-3199/3140.Consecutive Available Seats II/README_EN.md +++ b/solution/3100-3199/3140.Consecutive Available Seats II/README_EN.md @@ -91,6 +91,8 @@ First, we find all the vacant seats, and then group the seats. The grouping is b +#### MySQL + ```sql # Write your MySQL query statement below WITH diff --git a/solution/3100-3199/3141.Maximum Hamming Distances/README.md b/solution/3100-3199/3141.Maximum Hamming Distances/README.md index 5aa4dada8c5d5..1d73d75c83e56 100644 --- a/solution/3100-3199/3141.Maximum Hamming Distances/README.md +++ b/solution/3100-3199/3141.Maximum Hamming Distances/README.md @@ -97,6 +97,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3141.Ma +#### Python3 + ```python class Solution: def maxHammingDistances(self, nums: List[int], m: int) -> List[int]: @@ -118,6 +120,8 @@ class Solution: return [m - dist[x ^ ((1 << m) - 1)] for x in nums] ``` +#### Java + ```java class Solution { public int[] maxHammingDistances(int[] nums, int m) { @@ -148,6 +152,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -180,6 +186,8 @@ public: }; ``` +#### Go + ```go func maxHammingDistances(nums []int, m int) []int { dist := make([]int, 1< -1); diff --git a/solution/3100-3199/3141.Maximum Hamming Distances/README_EN.md b/solution/3100-3199/3141.Maximum Hamming Distances/README_EN.md index fd7e5e5990f3e..04967b4710783 100644 --- a/solution/3100-3199/3141.Maximum Hamming Distances/README_EN.md +++ b/solution/3100-3199/3141.Maximum Hamming Distances/README_EN.md @@ -95,6 +95,8 @@ The time complexity is $O(2^m)$, and the space complexity is $O(2^m)$, where $m$ +#### Python3 + ```python class Solution: def maxHammingDistances(self, nums: List[int], m: int) -> List[int]: @@ -116,6 +118,8 @@ class Solution: return [m - dist[x ^ ((1 << m) - 1)] for x in nums] ``` +#### Java + ```java class Solution { public int[] maxHammingDistances(int[] nums, int m) { @@ -146,6 +150,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -178,6 +184,8 @@ public: }; ``` +#### Go + ```go func maxHammingDistances(nums []int, m int) []int { dist := make([]int, 1< -1); diff --git a/solution/3100-3199/3142.Check if Grid Satisfies Conditions/README.md b/solution/3100-3199/3142.Check if Grid Satisfies Conditions/README.md index f0e23611ee8ca..0525c6740c2b8 100644 --- a/solution/3100-3199/3142.Check if Grid Satisfies Conditions/README.md +++ b/solution/3100-3199/3142.Check if Grid Satisfies Conditions/README.md @@ -90,6 +90,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3142.Ch +#### Python3 + ```python class Solution: def satisfiesConditions(self, grid: List[List[int]]) -> bool: @@ -103,6 +105,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean satisfiesConditions(int[][] grid) { @@ -122,6 +126,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -142,6 +148,8 @@ public: }; ``` +#### Go + ```go func satisfiesConditions(grid [][]int) bool { m, n := len(grid), len(grid[0]) @@ -159,6 +167,8 @@ func satisfiesConditions(grid [][]int) bool { } ``` +#### TypeScript + ```ts function satisfiesConditions(grid: number[][]): boolean { const [m, n] = [grid.length, grid[0].length]; diff --git a/solution/3100-3199/3142.Check if Grid Satisfies Conditions/README_EN.md b/solution/3100-3199/3142.Check if Grid Satisfies Conditions/README_EN.md index 581f87683d5fa..95bbf987b27ef 100644 --- a/solution/3100-3199/3142.Check if Grid Satisfies Conditions/README_EN.md +++ b/solution/3100-3199/3142.Check if Grid Satisfies Conditions/README_EN.md @@ -88,6 +88,8 @@ The time complexity is $O(m \times n)$, where $m$ and $n$ are the number of rows +#### Python3 + ```python class Solution: def satisfiesConditions(self, grid: List[List[int]]) -> bool: @@ -101,6 +103,8 @@ class Solution: return True ``` +#### Java + ```java class Solution { public boolean satisfiesConditions(int[][] grid) { @@ -120,6 +124,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -140,6 +146,8 @@ public: }; ``` +#### Go + ```go func satisfiesConditions(grid [][]int) bool { m, n := len(grid), len(grid[0]) @@ -157,6 +165,8 @@ func satisfiesConditions(grid [][]int) bool { } ``` +#### TypeScript + ```ts function satisfiesConditions(grid: number[][]): boolean { const [m, n] = [grid.length, grid[0].length]; diff --git a/solution/3100-3199/3143.Maximum Points Inside the Square/README.md b/solution/3100-3199/3143.Maximum Points Inside the Square/README.md index b4965092d2ef8..bdcbf817a8ddc 100644 --- a/solution/3100-3199/3143.Maximum Points Inside the Square/README.md +++ b/solution/3100-3199/3143.Maximum Points Inside the Square/README.md @@ -98,6 +98,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3143.Ma +#### Python3 + ```python class Solution: def maxPointsInsideSquare(self, points: List[List[int]], s: str) -> int: @@ -116,6 +118,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxPointsInsideSquare(int[][] points, String s) { @@ -142,6 +146,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -169,6 +175,8 @@ public: }; ``` +#### Go + ```go func maxPointsInsideSquare(points [][]int, s string) (ans int) { g := map[int][]int{} @@ -197,6 +205,8 @@ func maxPointsInsideSquare(points [][]int, s string) (ans int) { } ``` +#### TypeScript + ```ts function maxPointsInsideSquare(points: number[][], s: string): number { const n = points.length; diff --git a/solution/3100-3199/3143.Maximum Points Inside the Square/README_EN.md b/solution/3100-3199/3143.Maximum Points Inside the Square/README_EN.md index 9ac03c21cc17c..502cebe5b842c 100644 --- a/solution/3100-3199/3143.Maximum Points Inside the Square/README_EN.md +++ b/solution/3100-3199/3143.Maximum Points Inside the Square/README_EN.md @@ -96,6 +96,8 @@ The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$, +#### Python3 + ```python class Solution: def maxPointsInsideSquare(self, points: List[List[int]], s: str) -> int: @@ -114,6 +116,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxPointsInsideSquare(int[][] points, String s) { @@ -140,6 +144,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -167,6 +173,8 @@ public: }; ``` +#### Go + ```go func maxPointsInsideSquare(points [][]int, s string) (ans int) { g := map[int][]int{} @@ -195,6 +203,8 @@ func maxPointsInsideSquare(points [][]int, s string) (ans int) { } ``` +#### TypeScript + ```ts function maxPointsInsideSquare(points: number[][], s: string): number { const n = points.length; diff --git a/solution/3100-3199/3144.Minimum Substring Partition of Equal Character Frequency/README.md b/solution/3100-3199/3144.Minimum Substring Partition of Equal Character Frequency/README.md index dc62376d477f1..942e343dffe47 100644 --- a/solution/3100-3199/3144.Minimum Substring Partition of Equal Character Frequency/README.md +++ b/solution/3100-3199/3144.Minimum Substring Partition of Equal Character Frequency/README.md @@ -79,6 +79,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3144.Mi +#### Python3 + ```python class Solution: def minimumSubstringsInPartition(self, s: str) -> int: @@ -104,6 +106,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private int n; @@ -145,6 +149,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -183,6 +189,8 @@ public: }; ``` +#### Go + ```go func minimumSubstringsInPartition(s string) int { n := len(s) @@ -221,6 +229,8 @@ func minimumSubstringsInPartition(s string) int { } ``` +#### TypeScript + ```ts function minimumSubstringsInPartition(s: string): number { const n = s.length; diff --git a/solution/3100-3199/3144.Minimum Substring Partition of Equal Character Frequency/README_EN.md b/solution/3100-3199/3144.Minimum Substring Partition of Equal Character Frequency/README_EN.md index 37ddc86e5d722..58526e1b19a53 100644 --- a/solution/3100-3199/3144.Minimum Substring Partition of Equal Character Frequency/README_EN.md +++ b/solution/3100-3199/3144.Minimum Substring Partition of Equal Character Frequency/README_EN.md @@ -77,6 +77,8 @@ The time complexity is $O(n^2)$, and the space complexity is $O(n)$. Where $n$ i +#### Python3 + ```python class Solution: def minimumSubstringsInPartition(self, s: str) -> int: @@ -102,6 +104,8 @@ class Solution: return dfs(0) ``` +#### Java + ```java class Solution { private int n; @@ -143,6 +147,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -181,6 +187,8 @@ public: }; ``` +#### Go + ```go func minimumSubstringsInPartition(s string) int { n := len(s) @@ -219,6 +227,8 @@ func minimumSubstringsInPartition(s string) int { } ``` +#### TypeScript + ```ts function minimumSubstringsInPartition(s: string): number { const n = s.length; diff --git a/solution/3100-3199/3145.Find Products of Elements of Big Array/README.md b/solution/3100-3199/3145.Find Products of Elements of Big Array/README.md index a859e446a12cb..bd2a880c29b86 100644 --- a/solution/3100-3199/3145.Find Products of Elements of Big Array/README.md +++ b/solution/3100-3199/3145.Find Products of Elements of Big Array/README.md @@ -75,18 +75,26 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3145.Fi +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/3100-3199/3145.Find Products of Elements of Big Array/README_EN.md b/solution/3100-3199/3145.Find Products of Elements of Big Array/README_EN.md index 3030bef2dcd6a..73b85900f1d0e 100644 --- a/solution/3100-3199/3145.Find Products of Elements of Big Array/README_EN.md +++ b/solution/3100-3199/3145.Find Products of Elements of Big Array/README_EN.md @@ -73,18 +73,26 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3145.Fi +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` diff --git a/solution/3100-3199/3146.Permutation Difference between Two Strings/README.md b/solution/3100-3199/3146.Permutation Difference between Two Strings/README.md index 140354abfa106..048d804a06577 100644 --- a/solution/3100-3199/3146.Permutation Difference between Two Strings/README.md +++ b/solution/3100-3199/3146.Permutation Difference between Two Strings/README.md @@ -73,6 +73,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3146.Pe +#### Python3 + ```python class Solution: def findPermutationDifference(self, s: str, t: str) -> int: @@ -80,6 +82,8 @@ class Solution: return sum(abs(d[c] - i) for i, c in enumerate(t)) ``` +#### Java + ```java class Solution { public int findPermutationDifference(String s, String t) { @@ -97,6 +101,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -115,6 +121,8 @@ public: }; ``` +#### Go + ```go func findPermutationDifference(s string, t string) (ans int) { d := [26]int{} @@ -128,6 +136,8 @@ func findPermutationDifference(s string, t string) (ans int) { } ``` +#### TypeScript + ```ts function findPermutationDifference(s: string, t: string): number { const d: number[] = Array(26).fill(0); diff --git a/solution/3100-3199/3146.Permutation Difference between Two Strings/README_EN.md b/solution/3100-3199/3146.Permutation Difference between Two Strings/README_EN.md index 3fc312150cdf6..2c21eaf3d7d4e 100644 --- a/solution/3100-3199/3146.Permutation Difference between Two Strings/README_EN.md +++ b/solution/3100-3199/3146.Permutation Difference between Two Strings/README_EN.md @@ -71,6 +71,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3146.Pe +#### Python3 + ```python class Solution: def findPermutationDifference(self, s: str, t: str) -> int: @@ -78,6 +80,8 @@ class Solution: return sum(abs(d[c] - i) for i, c in enumerate(t)) ``` +#### Java + ```java class Solution { public int findPermutationDifference(String s, String t) { @@ -95,6 +99,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -113,6 +119,8 @@ public: }; ``` +#### Go + ```go func findPermutationDifference(s string, t string) (ans int) { d := [26]int{} @@ -126,6 +134,8 @@ func findPermutationDifference(s string, t string) (ans int) { } ``` +#### TypeScript + ```ts function findPermutationDifference(s: string, t: string): number { const d: number[] = Array(26).fill(0); diff --git a/solution/3100-3199/3147.Taking Maximum Energy From the Mystic Dungeon/README.md b/solution/3100-3199/3147.Taking Maximum Energy From the Mystic Dungeon/README.md index 1c46df99605ec..b64e9874c0b75 100644 --- a/solution/3100-3199/3147.Taking Maximum Energy From the Mystic Dungeon/README.md +++ b/solution/3100-3199/3147.Taking Maximum Energy From the Mystic Dungeon/README.md @@ -100,6 +100,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3147.Ta +#### Python3 + ```python class Solution: def maximumEnergy(self, energy: List[int], k: int) -> int: @@ -114,6 +116,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumEnergy(int[] energy, int k) { @@ -130,6 +134,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func maximumEnergy(energy []int, k int) int { ans := -(1 << 30) @@ -161,6 +169,8 @@ func maximumEnergy(energy []int, k int) int { } ``` +#### TypeScript + ```ts function maximumEnergy(energy: number[], k: number): number { const n = energy.length; diff --git a/solution/3100-3199/3147.Taking Maximum Energy From the Mystic Dungeon/README_EN.md b/solution/3100-3199/3147.Taking Maximum Energy From the Mystic Dungeon/README_EN.md index c8dc4238253aa..d3ce00a973fd2 100644 --- a/solution/3100-3199/3147.Taking Maximum Energy From the Mystic Dungeon/README_EN.md +++ b/solution/3100-3199/3147.Taking Maximum Energy From the Mystic Dungeon/README_EN.md @@ -99,6 +99,8 @@ The time complexity is $O(n)$, where $n$ is the length of the array `energy`. Th +#### Python3 + ```python class Solution: def maximumEnergy(self, energy: List[int], k: int) -> int: @@ -113,6 +115,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maximumEnergy(int[] energy, int k) { @@ -129,6 +133,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -146,6 +152,8 @@ public: }; ``` +#### Go + ```go func maximumEnergy(energy []int, k int) int { ans := -(1 << 30) @@ -160,6 +168,8 @@ func maximumEnergy(energy []int, k int) int { } ``` +#### TypeScript + ```ts function maximumEnergy(energy: number[], k: number): number { const n = energy.length; diff --git a/solution/3100-3199/3148.Maximum Difference Score in a Grid/README.md b/solution/3100-3199/3148.Maximum Difference Score in a Grid/README.md index ea63a19e60101..d4d02ccb4092b 100644 --- a/solution/3100-3199/3148.Maximum Difference Score in a Grid/README.md +++ b/solution/3100-3199/3148.Maximum Difference Score in a Grid/README.md @@ -81,6 +81,8 @@ $$ +#### Python3 + ```python class Solution: def maxScore(self, grid: List[List[int]]) -> int: @@ -98,6 +100,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxScore(List> grid) { @@ -123,6 +127,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -149,6 +155,8 @@ public: }; ``` +#### Go + ```go func maxScore(grid [][]int) int { m, n := len(grid), len(grid[0]) @@ -175,6 +183,8 @@ func maxScore(grid [][]int) int { } ``` +#### TypeScript + ```ts function maxScore(grid: number[][]): number { const [m, n] = [grid.length, grid[0].length]; diff --git a/solution/3100-3199/3148.Maximum Difference Score in a Grid/README_EN.md b/solution/3100-3199/3148.Maximum Difference Score in a Grid/README_EN.md index 28b3f4146d596..bddbb05180ff2 100644 --- a/solution/3100-3199/3148.Maximum Difference Score in a Grid/README_EN.md +++ b/solution/3100-3199/3148.Maximum Difference Score in a Grid/README_EN.md @@ -79,6 +79,8 @@ The time complexity is $O(m \times n)$, and the space complexity is $O(m \times +#### Python3 + ```python class Solution: def maxScore(self, grid: List[List[int]]) -> int: @@ -96,6 +98,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { public int maxScore(List> grid) { @@ -121,6 +125,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -147,6 +153,8 @@ public: }; ``` +#### Go + ```go func maxScore(grid [][]int) int { m, n := len(grid), len(grid[0]) @@ -173,6 +181,8 @@ func maxScore(grid [][]int) int { } ``` +#### TypeScript + ```ts function maxScore(grid: number[][]): number { const [m, n] = [grid.length, grid[0].length]; diff --git a/solution/3100-3199/3149.Find the Minimum Cost Array Permutation/README.md b/solution/3100-3199/3149.Find the Minimum Cost Array Permutation/README.md index a2e8c82ddb095..898903f6b7704 100644 --- a/solution/3100-3199/3149.Find the Minimum Cost Array Permutation/README.md +++ b/solution/3100-3199/3149.Find the Minimum Cost Array Permutation/README.md @@ -84,6 +84,8 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3149.Fi +#### Python3 + ```python class Solution: def findPermutation(self, nums: List[int]) -> List[int]: @@ -114,6 +116,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private Integer[][] f; @@ -164,6 +168,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -209,6 +215,8 @@ public: }; ``` +#### Go + ```go func findPermutation(nums []int) (ans []int) { n := len(nums) @@ -264,6 +272,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function findPermutation(nums: number[]): number[] { const n = nums.length; diff --git a/solution/3100-3199/3149.Find the Minimum Cost Array Permutation/README_EN.md b/solution/3100-3199/3149.Find the Minimum Cost Array Permutation/README_EN.md index a36f9b5052898..8decf84be7b05 100644 --- a/solution/3100-3199/3149.Find the Minimum Cost Array Permutation/README_EN.md +++ b/solution/3100-3199/3149.Find the Minimum Cost Array Permutation/README_EN.md @@ -82,6 +82,8 @@ The time complexity is $(n^2 \times 2^n)$, and the space complexity is $O(n \tim +#### Python3 + ```python class Solution: def findPermutation(self, nums: List[int]) -> List[int]: @@ -112,6 +114,8 @@ class Solution: return ans ``` +#### Java + ```java class Solution { private Integer[][] f; @@ -162,6 +166,8 @@ class Solution { } ``` +#### C++ + ```cpp class Solution { public: @@ -207,6 +213,8 @@ public: }; ``` +#### Go + ```go func findPermutation(nums []int) (ans []int) { n := len(nums) @@ -262,6 +270,8 @@ func abs(x int) int { } ``` +#### TypeScript + ```ts function findPermutation(nums: number[]): number[] { const n = nums.length; diff --git a/solution/3100-3199/3150.Invalid Tweets II/README.md b/solution/3100-3199/3150.Invalid Tweets II/README.md index ca874f2bfd182..3714c682a6520 100644 --- a/solution/3100-3199/3150.Invalid Tweets II/README.md +++ b/solution/3100-3199/3150.Invalid Tweets II/README.md @@ -89,6 +89,8 @@ tweet_id 是这个表的主键(有不同值的列)。 +#### MySQL + ```sql # Write your MySQL query statement below SELECT tweet_id @@ -99,6 +101,8 @@ WHERE LENGTH(content) > 140 ORDER BY 1; ``` +#### Python3 + ```python import pandas as pd diff --git a/solution/3100-3199/3150.Invalid Tweets II/README_EN.md b/solution/3100-3199/3150.Invalid Tweets II/README_EN.md index 8415de69f2299..5a9eae83403fc 100644 --- a/solution/3100-3199/3150.Invalid Tweets II/README_EN.md +++ b/solution/3100-3199/3150.Invalid Tweets II/README_EN.md @@ -89,6 +89,8 @@ We can use the `LENGTH()` function to calculate the length of the string, calcul +#### MySQL + ```sql # Write your MySQL query statement below SELECT tweet_id @@ -99,6 +101,8 @@ WHERE LENGTH(content) > 140 ORDER BY 1; ``` +#### Python3 + ```python import pandas as pd diff --git a/solution/template.md b/solution/template.md index a26e999da2d67..07538cac32df5 100644 --- a/solution/template.md +++ b/solution/template.md @@ -215,18 +215,26 @@ If you want to estimate your score changes after the contest ends, you can visit +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` @@ -267,18 +275,26 @@ If you want to estimate your score changes after the contest ends, you can visit +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` @@ -319,18 +335,26 @@ If you want to estimate your score changes after the contest ends, you can visit +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` @@ -371,18 +395,26 @@ If you want to estimate your score changes after the contest ends, you can visit +#### Python3 + ```python ``` +#### Java + ```java ``` +#### C++ + ```cpp ``` +#### Go + ```go ``` @@ -423,6 +455,8 @@ If you want to estimate your score changes after the contest ends, you can visit +#### MySQL + ```sql ``` @@ -463,6 +497,8 @@ If you want to estimate your score changes after the contest ends, you can visit +#### MySQL + ```sql ``` @@ -503,6 +539,8 @@ If you want to estimate your score changes after the contest ends, you can visit +#### TypeScript + ```ts ``` @@ -543,6 +581,8 @@ If you want to estimate your score changes after the contest ends, you can visit +#### TypeScript + ```ts ```