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 65006061026e0..313a8cc79e576 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 @@ -71,7 +71,15 @@ ```python - +class Solution: + def divisorSubstrings(self, num: int, k: int) -> int: + cnt = 0 + s = str(num) + for i in range(len(s) - k + 1): + tmp = int(s[i: i + k]) + if tmp != 0 and num % tmp == 0: + cnt += 1 + return cnt ``` ### **Java** @@ -79,7 +87,19 @@ ```java - +class Solution { + public int divisorSubstrings(int num, int k) { + int cnt = 0; + String s = String.valueOf(num); + for (int i = 0; i <= s.length() - k; i++) { + int tmp = Integer.parseInt(s.substring(i, i + k)); + if (tmp != 0 && num % tmp == 0) { + cnt++; + } + } + return cnt; + } +} ``` ### **TypeScript** 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 8a5156d87baa0..0fa9601f85c85 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 @@ -63,13 +63,33 @@ Therefore, the k-beauty is 2. ### **Python3** ```python - +class Solution: + def divisorSubstrings(self, num: int, k: int) -> int: + cnt = 0 + s = str(num) + for i in range(len(s) - k + 1): + tmp = int(s[i: i + k]) + if tmp != 0 and num % tmp == 0: + cnt += 1 + return cnt ``` ### **Java** ```java - +class Solution { + public int divisorSubstrings(int num, int k) { + int cnt = 0; + String s = String.valueOf(num); + for (int i = 0; i <= s.length() - k; i++) { + int tmp = Integer.parseInt(s.substring(i, i + k)); + if (tmp != 0 && num % tmp == 0) { + cnt++; + } + } + return cnt; + } +} ``` ### **TypeScript** diff --git a/solution/2200-2299/2269.Find the K-Beauty of a Number/Solution.java b/solution/2200-2299/2269.Find the K-Beauty of a Number/Solution.java new file mode 100644 index 0000000000000..97b8e29b40177 --- /dev/null +++ b/solution/2200-2299/2269.Find the K-Beauty of a Number/Solution.java @@ -0,0 +1,13 @@ +class Solution { + public int divisorSubstrings(int num, int k) { + int cnt = 0; + String s = String.valueOf(num); + for (int i = 0; i <= s.length() - k; i++) { + int tmp = Integer.parseInt(s.substring(i, i + k)); + if (tmp != 0 && num % tmp == 0) { + cnt++; + } + } + return cnt; + } +} \ No newline at end of file diff --git a/solution/2200-2299/2269.Find the K-Beauty of a Number/Solution.py b/solution/2200-2299/2269.Find the K-Beauty of a Number/Solution.py new file mode 100644 index 0000000000000..e052711b4c024 --- /dev/null +++ b/solution/2200-2299/2269.Find the K-Beauty of a Number/Solution.py @@ -0,0 +1,9 @@ +class Solution: + def divisorSubstrings(self, num: int, k: int) -> int: + cnt = 0 + s = str(num) + for i in range(len(s) - k + 1): + tmp = int(s[i: i + k]) + if tmp != 0 and num % tmp == 0: + cnt += 1 + return cnt \ No newline at end of file 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 990667c240255..5f00e259f3fd4 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 @@ -62,7 +62,16 @@ ```python - +class Solution: + def waysToSplitArray(self, nums: List[int]) -> int: + left, right = 0, sum(nums) + cnt = 0 + for v in nums[:-1]: + left += v + right -= v + if left >= right: + cnt += 1 + return cnt ``` ### **Java** @@ -70,7 +79,21 @@ ```java - +class Solution { + public int waysToSplitArray(int[] nums) { + long[] pre = new long[nums.length + 1]; + for (int i = 0; i < nums.length; i++) { + pre[i + 1] = pre[i] + nums[i]; + } + int cnt = 0; + for (int i = 1; i < nums.length; i++) { + if (pre[i] >= pre[nums.length] - pre[i]) { + cnt++; + } + } + return cnt; + } +} ``` ### **TypeScript** 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 4e64f49ba044b..3d46f2d4992fc 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 @@ -55,13 +55,36 @@ There are two valid splits in nums: ### **Python3** ```python - +class Solution: + def waysToSplitArray(self, nums: List[int]) -> int: + left, right = 0, sum(nums) + cnt = 0 + for v in nums[:-1]: + left += v + right -= v + if left >= right: + cnt += 1 + return cnt ``` ### **Java** ```java - +class Solution { + public int waysToSplitArray(int[] nums) { + long[] pre = new long[nums.length + 1]; + for (int i = 0; i < nums.length; i++) { + pre[i + 1] = pre[i] + nums[i]; + } + int cnt = 0; + for (int i = 1; i < nums.length; i++) { + if (pre[i] >= pre[nums.length] - pre[i]) { + cnt++; + } + } + return cnt; + } +} ``` ### **TypeScript** diff --git a/solution/2200-2299/2270.Number of Ways to Split Array/Solution.java b/solution/2200-2299/2270.Number of Ways to Split Array/Solution.java new file mode 100644 index 0000000000000..36124d5c9ffbd --- /dev/null +++ b/solution/2200-2299/2270.Number of Ways to Split Array/Solution.java @@ -0,0 +1,15 @@ +class Solution { + public int waysToSplitArray(int[] nums) { + long[] pre = new long[nums.length + 1]; + for (int i = 0; i < nums.length; i++) { + pre[i + 1] = pre[i] + nums[i]; + } + int cnt = 0; + for (int i = 1; i < nums.length; i++) { + if (pre[i] >= pre[nums.length] - pre[i]) { + cnt++; + } + } + return cnt; + } +} \ No newline at end of file diff --git a/solution/2200-2299/2270.Number of Ways to Split Array/Solution.py b/solution/2200-2299/2270.Number of Ways to Split Array/Solution.py new file mode 100644 index 0000000000000..454cf6d2f6532 --- /dev/null +++ b/solution/2200-2299/2270.Number of Ways to Split Array/Solution.py @@ -0,0 +1,10 @@ +class Solution: + def waysToSplitArray(self, nums: List[int]) -> int: + left, right = 0, sum(nums) + cnt = 0 + for v in nums[:-1]: + left += v + right -= v + if left >= right: + cnt += 1 + return cnt \ No newline at end of file