diff --git a/solution/0700-0799/0737.Sentence Similarity II/README.md b/solution/0700-0799/0737.Sentence Similarity II/README.md index cdcff4c75a678..b07c7fa1c366b 100644 --- a/solution/0700-0799/0737.Sentence Similarity II/README.md +++ b/solution/0700-0799/0737.Sentence Similarity II/README.md @@ -30,7 +30,7 @@ tags:

两个句子是相似的,如果:

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 41251e6250970..0f0c134573d43 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 @@ -68,7 +68,13 @@ tags: -### 方法一 +### 方法一:DFS + +我们可以枚举所有长度为 $n$ 的数字的第一个数字,然后使用深度优先搜索的方法,递归地构造所有符合条件的数字。 + +具体地,我们首先定义一个边界值 $\textit{boundary} = 10^{n-1}$,表示我们需要构造的数字的最小值。然后,我们从 $1$ 到 $9$ 枚举第一个数字,对于每一个数字 $i$,我们递归地构造以 $i$ 为第一个数字的长度为 $n$ 的数字。 + +时间复杂度 $(n \times 2^n \times |\Sigma|)$,其中 $|\Sigma|$ 表示数字集合,本题中 $|\Sigma| = 9$。空间复杂度 $O(2^n)$。 @@ -77,20 +83,20 @@ tags: ```python class Solution: def numsSameConsecDiff(self, n: int, k: int) -> List[int]: - ans = [] - - def dfs(n, k, t): - if n == 0: - ans.append(t) + def dfs(x: int): + if x >= boundary: + ans.append(x) return - last = t % 10 + last = x % 10 if last + k <= 9: - dfs(n - 1, k, t * 10 + last + k) + dfs(x * 10 + last + k) if last - k >= 0 and k != 0: - dfs(n - 1, k, t * 10 + last - k) + dfs(x * 10 + last - k) + ans = [] + boundary = 10 ** (n - 1) for i in range(1, 10): - dfs(n - 1, k, i) + dfs(i) return ans ``` @@ -98,29 +104,30 @@ class Solution: ```java class Solution { + private List ans = new ArrayList<>(); + private int boundary; + private int k; + public int[] numsSameConsecDiff(int n, int k) { - List res = new ArrayList<>(); + this.k = k; + boundary = (int) Math.pow(10, n - 1); for (int i = 1; i < 10; ++i) { - dfs(n - 1, k, i, res); + dfs(i); } - int[] ans = new int[res.size()]; - for (int i = 0; i < res.size(); ++i) { - ans[i] = res.get(i); - } - return ans; + return ans.stream().mapToInt(i -> i).toArray(); } - private void dfs(int n, int k, int t, List res) { - if (n == 0) { - res.add(t); + private void dfs(int x) { + if (x >= boundary) { + ans.add(x); return; } - int last = t % 10; - if (last + k <= 9) { - dfs(n - 1, k, t * 10 + last + k, res); + int last = x % 10; + if (last + k < 10) { + dfs(x * 10 + last + k); } - if (last - k >= 0 && k != 0) { - dfs(n - 1, k, t * 10 + last - k, res); + if (k != 0 && last - k >= 0) { + dfs(x * 10 + last - k); } } } @@ -131,22 +138,26 @@ class Solution { ```cpp class Solution { public: - vector ans; - vector numsSameConsecDiff(int n, int k) { - for (int i = 1; i < 10; ++i) - dfs(n - 1, k, i); - return ans; - } - - void dfs(int n, int k, int t) { - if (n == 0) { - ans.push_back(t); - return; + vector ans; + int boundary = pow(10, n - 1); + auto dfs = [&](auto&& dfs, int x) { + if (x >= boundary) { + ans.push_back(x); + return; + } + int last = x % 10; + if (last + k < 10) { + dfs(dfs, x * 10 + last + k); + } + if (k != 0 && last - k >= 0) { + dfs(dfs, x * 10 + last - k); + } + }; + for (int i = 1; i < 10; ++i) { + dfs(dfs, i); } - int last = t % 10; - if (last + k <= 9) dfs(n - 1, k, t * 10 + last + k); - if (last - k >= 0 && k != 0) dfs(n - 1, k, t * 10 + last - k); + return ans; } }; ``` @@ -154,27 +165,26 @@ public: #### Go ```go -func numsSameConsecDiff(n int, k int) []int { - var ans []int - var dfs func(n, k, t int) - dfs = func(n, k, t int) { - if n == 0 { - ans = append(ans, t) +func numsSameConsecDiff(n int, k int) (ans []int) { + bounary := int(math.Pow10(n - 1)) + var dfs func(int) + dfs = func(x int) { + if x >= bounary { + ans = append(ans, x) return } - last := t % 10 - if last+k <= 9 { - dfs(n-1, k, t*10+last+k) + last := x % 10 + if last+k < 10 { + dfs(x*10 + last + k) } - if last-k >= 0 && k != 0 { - dfs(n-1, k, t*10+last-k) + if k > 0 && last-k >= 0 { + dfs(x*10 + last - k) } } - for i := 1; i < 10; i++ { - dfs(n-1, k, i) + dfs(i) } - return ans + return } ``` @@ -182,58 +192,57 @@ func numsSameConsecDiff(n int, k int) []int { ```ts function numsSameConsecDiff(n: number, k: number): number[] { - const ans = new Set(); + const ans: number[] = []; const boundary = 10 ** (n - 1); - - const dfs = (nums: number) => { - if (nums >= boundary) { - ans.add(nums); + const dfs = (x: number) => { + if (x >= boundary) { + ans.push(x); return; } - - const num = nums % 10; - for (const x of [num + k, num - k]) { - if (0 <= x && x < 10) { - dfs(nums * 10 + x); - } + const last = x % 10; + if (last + k < 10) { + dfs(x * 10 + last + k); + } + if (k > 0 && last - k >= 0) { + dfs(x * 10 + last - k); } }; - for (let i = 1; i < 10; i++) { dfs(i); } - - return [...ans]; + return ans; } ``` #### JavaScript ```js -function numsSameConsecDiff(n, k) { - const ans = new Set(); +/** + * @param {number} n + * @param {number} k + * @return {number[]} + */ +var numsSameConsecDiff = function (n, k) { + const ans = []; const boundary = 10 ** (n - 1); - - const dfs = nums => { - if (nums >= boundary) { - ans.add(nums); + const dfs = x => { + if (x >= boundary) { + ans.push(x); return; } - - const num = nums % 10; - for (const x of [num + k, num - k]) { - if (0 <= x && x < 10) { - dfs(nums * 10 + x); - } + const last = x % 10; + if (last + k < 10) { + dfs(x * 10 + last + k); + } + if (k > 0 && last - k >= 0) { + dfs(x * 10 + last - k); } }; - for (let i = 1; i < 10; i++) { dfs(i); } - - return [...ans]; -} + return ans; +}; ``` 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 07361120c47c5..df81fe1180a94 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 @@ -51,7 +51,13 @@ tags: -### Solution 1 +### Solution 1: DFS + +We can enumerate the first digit of all numbers of length $n$, and then use the depth-first search method to recursively construct all numbers that meet the conditions. + +Specifically, we first define a boundary value $\textit{boundary} = 10^{n-1}$, which represents the minimum value of the number we need to construct. Then, we enumerate the first digit from $1$ to $9$. For each digit $i$, we recursively construct the number of length $n$ with $i$ as the first digit. + +The time complexity is $(n \times 2^n \times |\Sigma|)$, where $|\Sigma|$ represents the set of digits, and in this problem $|\Sigma| = 9$. The space complexity is $O(2^n)$. @@ -60,20 +66,20 @@ tags: ```python class Solution: def numsSameConsecDiff(self, n: int, k: int) -> List[int]: - ans = [] - - def dfs(n, k, t): - if n == 0: - ans.append(t) + def dfs(x: int): + if x >= boundary: + ans.append(x) return - last = t % 10 + last = x % 10 if last + k <= 9: - dfs(n - 1, k, t * 10 + last + k) + dfs(x * 10 + last + k) if last - k >= 0 and k != 0: - dfs(n - 1, k, t * 10 + last - k) + dfs(x * 10 + last - k) + ans = [] + boundary = 10 ** (n - 1) for i in range(1, 10): - dfs(n - 1, k, i) + dfs(i) return ans ``` @@ -81,29 +87,30 @@ class Solution: ```java class Solution { + private List ans = new ArrayList<>(); + private int boundary; + private int k; + public int[] numsSameConsecDiff(int n, int k) { - List res = new ArrayList<>(); + this.k = k; + boundary = (int) Math.pow(10, n - 1); for (int i = 1; i < 10; ++i) { - dfs(n - 1, k, i, res); + dfs(i); } - int[] ans = new int[res.size()]; - for (int i = 0; i < res.size(); ++i) { - ans[i] = res.get(i); - } - return ans; + return ans.stream().mapToInt(i -> i).toArray(); } - private void dfs(int n, int k, int t, List res) { - if (n == 0) { - res.add(t); + private void dfs(int x) { + if (x >= boundary) { + ans.add(x); return; } - int last = t % 10; - if (last + k <= 9) { - dfs(n - 1, k, t * 10 + last + k, res); + int last = x % 10; + if (last + k < 10) { + dfs(x * 10 + last + k); } - if (last - k >= 0 && k != 0) { - dfs(n - 1, k, t * 10 + last - k, res); + if (k != 0 && last - k >= 0) { + dfs(x * 10 + last - k); } } } @@ -114,22 +121,26 @@ class Solution { ```cpp class Solution { public: - vector ans; - vector numsSameConsecDiff(int n, int k) { - for (int i = 1; i < 10; ++i) - dfs(n - 1, k, i); - return ans; - } - - void dfs(int n, int k, int t) { - if (n == 0) { - ans.push_back(t); - return; + vector ans; + int boundary = pow(10, n - 1); + auto dfs = [&](auto&& dfs, int x) { + if (x >= boundary) { + ans.push_back(x); + return; + } + int last = x % 10; + if (last + k < 10) { + dfs(dfs, x * 10 + last + k); + } + if (k != 0 && last - k >= 0) { + dfs(dfs, x * 10 + last - k); + } + }; + for (int i = 1; i < 10; ++i) { + dfs(dfs, i); } - int last = t % 10; - if (last + k <= 9) dfs(n - 1, k, t * 10 + last + k); - if (last - k >= 0 && k != 0) dfs(n - 1, k, t * 10 + last - k); + return ans; } }; ``` @@ -137,27 +148,26 @@ public: #### Go ```go -func numsSameConsecDiff(n int, k int) []int { - var ans []int - var dfs func(n, k, t int) - dfs = func(n, k, t int) { - if n == 0 { - ans = append(ans, t) +func numsSameConsecDiff(n int, k int) (ans []int) { + bounary := int(math.Pow10(n - 1)) + var dfs func(int) + dfs = func(x int) { + if x >= bounary { + ans = append(ans, x) return } - last := t % 10 - if last+k <= 9 { - dfs(n-1, k, t*10+last+k) + last := x % 10 + if last+k < 10 { + dfs(x*10 + last + k) } - if last-k >= 0 && k != 0 { - dfs(n-1, k, t*10+last-k) + if k > 0 && last-k >= 0 { + dfs(x*10 + last - k) } } - for i := 1; i < 10; i++ { - dfs(n-1, k, i) + dfs(i) } - return ans + return } ``` @@ -165,58 +175,57 @@ func numsSameConsecDiff(n int, k int) []int { ```ts function numsSameConsecDiff(n: number, k: number): number[] { - const ans = new Set(); + const ans: number[] = []; const boundary = 10 ** (n - 1); - - const dfs = (nums: number) => { - if (nums >= boundary) { - ans.add(nums); + const dfs = (x: number) => { + if (x >= boundary) { + ans.push(x); return; } - - const num = nums % 10; - for (const x of [num + k, num - k]) { - if (0 <= x && x < 10) { - dfs(nums * 10 + x); - } + const last = x % 10; + if (last + k < 10) { + dfs(x * 10 + last + k); + } + if (k > 0 && last - k >= 0) { + dfs(x * 10 + last - k); } }; - for (let i = 1; i < 10; i++) { dfs(i); } - - return [...ans]; + return ans; } ``` #### JavaScript ```js -function numsSameConsecDiff(n, k) { - const ans = new Set(); +/** + * @param {number} n + * @param {number} k + * @return {number[]} + */ +var numsSameConsecDiff = function (n, k) { + const ans = []; const boundary = 10 ** (n - 1); - - const dfs = nums => { - if (nums >= boundary) { - ans.add(nums); + const dfs = x => { + if (x >= boundary) { + ans.push(x); return; } - - const num = nums % 10; - for (const x of [num + k, num - k]) { - if (0 <= x && x < 10) { - dfs(nums * 10 + x); - } + const last = x % 10; + if (last + k < 10) { + dfs(x * 10 + last + k); + } + if (k > 0 && last - k >= 0) { + dfs(x * 10 + last - k); } }; - for (let i = 1; i < 10; i++) { dfs(i); } - - return [...ans]; -} + return ans; +}; ``` diff --git a/solution/0900-0999/0967.Numbers With Same Consecutive Differences/Solution.cpp b/solution/0900-0999/0967.Numbers With Same Consecutive Differences/Solution.cpp index 9e5b5b328b2c9..93d2a7e666196 100644 --- a/solution/0900-0999/0967.Numbers With Same Consecutive Differences/Solution.cpp +++ b/solution/0900-0999/0967.Numbers With Same Consecutive Differences/Solution.cpp @@ -1,20 +1,24 @@ class Solution { public: - vector ans; - vector numsSameConsecDiff(int n, int k) { - for (int i = 1; i < 10; ++i) - dfs(n - 1, k, i); - return ans; - } - - void dfs(int n, int k, int t) { - if (n == 0) { - ans.push_back(t); - return; + vector ans; + int boundary = pow(10, n - 1); + auto dfs = [&](auto&& dfs, int x) { + if (x >= boundary) { + ans.push_back(x); + return; + } + int last = x % 10; + if (last + k < 10) { + dfs(dfs, x * 10 + last + k); + } + if (k != 0 && last - k >= 0) { + dfs(dfs, x * 10 + last - k); + } + }; + for (int i = 1; i < 10; ++i) { + dfs(dfs, i); } - int last = t % 10; - if (last + k <= 9) dfs(n - 1, k, t * 10 + last + k); - if (last - k >= 0 && k != 0) dfs(n - 1, k, t * 10 + last - k); + return ans; } -}; \ No newline at end of file +}; diff --git a/solution/0900-0999/0967.Numbers With Same Consecutive Differences/Solution.go b/solution/0900-0999/0967.Numbers With Same Consecutive Differences/Solution.go index 4d14a3b227a09..dc737e6064234 100644 --- a/solution/0900-0999/0967.Numbers With Same Consecutive Differences/Solution.go +++ b/solution/0900-0999/0967.Numbers With Same Consecutive Differences/Solution.go @@ -1,22 +1,21 @@ -func numsSameConsecDiff(n int, k int) []int { - var ans []int - var dfs func(n, k, t int) - dfs = func(n, k, t int) { - if n == 0 { - ans = append(ans, t) +func numsSameConsecDiff(n int, k int) (ans []int) { + bounary := int(math.Pow10(n - 1)) + var dfs func(int) + dfs = func(x int) { + if x >= bounary { + ans = append(ans, x) return } - last := t % 10 - if last+k <= 9 { - dfs(n-1, k, t*10+last+k) + last := x % 10 + if last+k < 10 { + dfs(x*10 + last + k) } - if last-k >= 0 && k != 0 { - dfs(n-1, k, t*10+last-k) + if k > 0 && last-k >= 0 { + dfs(x*10 + last - k) } } - for i := 1; i < 10; i++ { - dfs(n-1, k, i) + dfs(i) } - return ans -} \ No newline at end of file + return +} diff --git a/solution/0900-0999/0967.Numbers With Same Consecutive Differences/Solution.java b/solution/0900-0999/0967.Numbers With Same Consecutive Differences/Solution.java index c4dd47c64720d..1b11274810fcf 100644 --- a/solution/0900-0999/0967.Numbers With Same Consecutive Differences/Solution.java +++ b/solution/0900-0999/0967.Numbers With Same Consecutive Differences/Solution.java @@ -1,27 +1,28 @@ class Solution { + private List ans = new ArrayList<>(); + private int boundary; + private int k; + public int[] numsSameConsecDiff(int n, int k) { - List res = new ArrayList<>(); + this.k = k; + boundary = (int) Math.pow(10, n - 1); for (int i = 1; i < 10; ++i) { - dfs(n - 1, k, i, res); - } - int[] ans = new int[res.size()]; - for (int i = 0; i < res.size(); ++i) { - ans[i] = res.get(i); + dfs(i); } - return ans; + return ans.stream().mapToInt(i -> i).toArray(); } - private void dfs(int n, int k, int t, List res) { - if (n == 0) { - res.add(t); + private void dfs(int x) { + if (x >= boundary) { + ans.add(x); return; } - int last = t % 10; - if (last + k <= 9) { - dfs(n - 1, k, t * 10 + last + k, res); + int last = x % 10; + if (last + k < 10) { + dfs(x * 10 + last + k); } - if (last - k >= 0 && k != 0) { - dfs(n - 1, k, t * 10 + last - k, res); + if (k != 0 && last - k >= 0) { + dfs(x * 10 + last - k); } } -} \ No newline at end of file +} diff --git a/solution/0900-0999/0967.Numbers With Same Consecutive Differences/Solution.js b/solution/0900-0999/0967.Numbers With Same Consecutive Differences/Solution.js index 29fe44aa4c446..83f2a8eeb880b 100644 --- a/solution/0900-0999/0967.Numbers With Same Consecutive Differences/Solution.js +++ b/solution/0900-0999/0967.Numbers With Same Consecutive Differences/Solution.js @@ -1,24 +1,26 @@ -function numsSameConsecDiff(n, k) { - const ans = new Set(); +/** + * @param {number} n + * @param {number} k + * @return {number[]} + */ +var numsSameConsecDiff = function (n, k) { + const ans = []; const boundary = 10 ** (n - 1); - - const dfs = nums => { - if (nums >= boundary) { - ans.add(nums); + const dfs = x => { + if (x >= boundary) { + ans.push(x); return; } - - const num = nums % 10; - for (const x of [num + k, num - k]) { - if (0 <= x && x < 10) { - dfs(nums * 10 + x); - } + const last = x % 10; + if (last + k < 10) { + dfs(x * 10 + last + k); + } + if (k > 0 && last - k >= 0) { + dfs(x * 10 + last - k); } }; - for (let i = 1; i < 10; i++) { dfs(i); } - - return [...ans]; -} + return ans; +}; diff --git a/solution/0900-0999/0967.Numbers With Same Consecutive Differences/Solution.py b/solution/0900-0999/0967.Numbers With Same Consecutive Differences/Solution.py index 1705a57304394..049b2e22a2469 100644 --- a/solution/0900-0999/0967.Numbers With Same Consecutive Differences/Solution.py +++ b/solution/0900-0999/0967.Numbers With Same Consecutive Differences/Solution.py @@ -1,17 +1,17 @@ class Solution: def numsSameConsecDiff(self, n: int, k: int) -> List[int]: - ans = [] - - def dfs(n, k, t): - if n == 0: - ans.append(t) + def dfs(x: int): + if x >= boundary: + ans.append(x) return - last = t % 10 + last = x % 10 if last + k <= 9: - dfs(n - 1, k, t * 10 + last + k) + dfs(x * 10 + last + k) if last - k >= 0 and k != 0: - dfs(n - 1, k, t * 10 + last - k) + dfs(x * 10 + last - k) + ans = [] + boundary = 10 ** (n - 1) for i in range(1, 10): - dfs(n - 1, k, i) + dfs(i) return ans diff --git a/solution/0900-0999/0967.Numbers With Same Consecutive Differences/Solution.ts b/solution/0900-0999/0967.Numbers With Same Consecutive Differences/Solution.ts index 8da7c4da8a91c..a35d9eb752483 100644 --- a/solution/0900-0999/0967.Numbers With Same Consecutive Differences/Solution.ts +++ b/solution/0900-0999/0967.Numbers With Same Consecutive Differences/Solution.ts @@ -1,24 +1,21 @@ function numsSameConsecDiff(n: number, k: number): number[] { - const ans = new Set(); + const ans: number[] = []; const boundary = 10 ** (n - 1); - - const dfs = (nums: number) => { - if (nums >= boundary) { - ans.add(nums); + const dfs = (x: number) => { + if (x >= boundary) { + ans.push(x); return; } - - const num = nums % 10; - for (const x of [num + k, num - k]) { - if (0 <= x && x < 10) { - dfs(nums * 10 + x); - } + const last = x % 10; + if (last + k < 10) { + dfs(x * 10 + last + k); + } + if (k > 0 && last - k >= 0) { + dfs(x * 10 + last - k); } }; - for (let i = 1; i < 10; i++) { dfs(i); } - - return [...ans]; + return ans; } diff --git a/solution/3200-3299/3235.Check if the Rectangle Corner Is Reachable/README_EN.md b/solution/3200-3299/3235.Check if the Rectangle Corner Is Reachable/README_EN.md index 4ba4816ceb507..0df33207445b8 100644 --- a/solution/3200-3299/3235.Check if the Rectangle Corner Is Reachable/README_EN.md +++ b/solution/3200-3299/3235.Check if the Rectangle Corner Is Reachable/README_EN.md @@ -21,9 +21,9 @@ tags: -

You are given two positive integers X and Y, and a 2D array circles, where circles[i] = [xi, yi, ri] denotes a circle with center at (xi, yi) and radius ri.

+

You are given two positive integers xCorner and yCorner, and a 2D array circles, where circles[i] = [xi, yi, ri] denotes a circle with center at (xi, yi) and radius ri.

-

There is a rectangle in the coordinate plane with its bottom left corner at the origin and top right corner at the coordinate (X, Y). You need to check whether there is a path from the bottom left corner to the top right corner such that the entire path lies inside the rectangle, does not touch or lie inside any circle, and touches the rectangle only at the two corners.

+

There is a rectangle in the coordinate plane with its bottom left corner at the origin and top right corner at the coordinate (xCorner, yCorner). You need to check whether there is a path from the bottom left corner to the top right corner such that the entire path lies inside the rectangle, does not touch or lie inside any circle, and touches the rectangle only at the two corners.

Return true if such a path exists, and false otherwise.

@@ -31,7 +31,7 @@ tags:

Example 1:

-

Input: X = 3, Y = 4, circles = [[2,1,1]]

+

Input: xCorner = 3, yCorner = 4, circles = [[2,1,1]]

Output: true

@@ -45,7 +45,7 @@ tags:

Example 2:

-

Input: X = 3, Y = 3, circles = [[1,1,2]]

+

Input: xCorner = 3, yCorner = 3, circles = [[1,1,2]]

Output: false

@@ -59,7 +59,7 @@ tags:

Example 3:

-

Input: X = 3, Y = 3, circles = [[2,1,1],[1,2,1]]

+

Input: xCorner = 3, yCorner = 3, circles = [[2,1,1],[1,2,1]]

Output: false

@@ -73,7 +73,7 @@ tags:

Example 4:

-

Input: X = 4, Y = 4, circles = [[5,5,1]]

+

Input: xCorner = 4, yCorner = 4, circles = [[5,5,1]]

Output: true

@@ -86,7 +86,7 @@ tags:

Constraints:

    -
  • 3 <= X, Y <= 109
  • +
  • 3 <= xCorner, yCorner <= 109
  • 1 <= circles.length <= 1000
  • circles[i].length == 3
  • 1 <= xi, yi, ri <= 109
  • diff --git a/solution/3200-3299/3242.Design Neighbor Sum Service/README_EN.md b/solution/3200-3299/3242.Design Neighbor Sum Service/README_EN.md index 2acee83f91304..e04c93c92bc15 100644 --- a/solution/3200-3299/3242.Design Neighbor Sum Service/README_EN.md +++ b/solution/3200-3299/3242.Design Neighbor Sum Service/README_EN.md @@ -22,10 +22,10 @@ tags:

    You are given a n x n 2D array grid containing distinct elements in the range [0, n2 - 1].

    -

    Implement the neighborSum class:

    +

    Implement the NeighborSum class:

      -
    • neighborSum(int [][]grid) initializes the object.
    • +
    • NeighborSum(int [][]grid) initializes the object.
    • int adjacentSum(int value) returns the sum of elements which are adjacent neighbors of value, that is either to the top, left, right, or bottom of value in grid.
    • int diagonalSum(int value) returns the sum of elements which are diagonal neighbors of value, that is either to the top-left, top-right, bottom-left, or bottom-right of value in grid.
    @@ -38,7 +38,7 @@ tags:

    Input:

    -

    ["neighborSum", "adjacentSum", "adjacentSum", "diagonalSum", "diagonalSum"]

    +

    ["NeighborSum", "adjacentSum", "adjacentSum", "diagonalSum", "diagonalSum"]

    [[[[0, 1, 2], [3, 4, 5], [6, 7, 8]]], [1], [4], [4], [8]]

    @@ -61,7 +61,7 @@ tags:

    Input:

    -

    ["neighborSum", "adjacentSum", "diagonalSum"]

    +

    ["NeighborSum", "adjacentSum", "diagonalSum"]

    [[[[1, 2, 0, 3], [4, 7, 15, 6], [8, 9, 10, 11], [12, 13, 14, 5]]], [15], [9]]