Skip to content

Latest commit

 

History

History
54 lines (41 loc) · 1.26 KB

_2221. Find Triangular Sum of an Array.md

File metadata and controls

54 lines (41 loc) · 1.26 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : June 27, 2024

Last updated : June 27, 2024


Related Topics : Array, Math, Simulation, Combinatorics

Acceptance Rate : 78.74 %


Solutions

C

int triangularSum(int* nums, int numsSize) {
    for (int i = 0; i < numsSize; i++) {
        for (int j = 0; j < numsSize - i - 1; j++) {
            nums[j] = (nums[j] + nums[j + 1]) % 10;
        }
    }

    return nums[0] % 10;
}

Java

class Solution {
    public int triangularSum(int[] nums) {
        for (int i = 0; i < nums.length; i++) {
            for (int j = 0; j < nums.length - i - 1; j++) {
                nums[j] = (nums[j] + nums[j + 1]) % 10;
            }
        }

        return nums[0] % 10;
    }
}