Skip to content

Commit 81d3ca7

Browse files
committed
Runtime 79 ms (Top 72.59%) | Memory 42.0 MB (Top 32.23%)
1 parent cd9e042 commit 81d3ca7

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
class Solution {
22
public int triangularSum(int[] nums) {
3-
while(nums.length > 1){
4-
int[] arr = new int[nums.length-1];
5-
for(int i=0; i<arr.length; i++){
6-
arr[i] = (nums[i] + nums[i+1]) % 10;
7-
}
8-
nums = arr;
3+
return find(nums,nums.length);
4+
}
5+
6+
public int find(int[] a, int n){
7+
if(n == 1)
8+
return a[0];
9+
10+
for(int i=0;i<n-1;i++){
11+
a[i] = (a[i] + a[i+1])%10;
912
}
10-
return nums[0];
13+
return find(a,n-1);
1114
}
12-
}
15+
}

0 commit comments

Comments
 (0)