-
1572. Matrix Diagonal Sum javaLeetCode_Study_Plan/Programming Skills 2022. 9. 21. 00:13
https://leetcode.com/problems/matrix-diagonal-sum/?envType=study-plan&id=programming-skills-i
class Solution { public int diagonalSum(int[][] mat){ int sum = 0; for(int i = 0; i < mat.length; i++){ for(int j = 0; j < mat.length; j++){ if (i==j || i+j == mat.length - 1){ sum += mat[i][j]; } } } return sum; } public static void main(String[] args){ Solution sol = new Solution(); int[][] mat = {{1,1,1,1}, {1,1,1,1}, {1,1,1,1}, {1,1,1,1}}; System.out.println(sol.diagonalSum(mat)); } }
'LeetCode_Study_Plan > Programming Skills' 카테고리의 다른 글
1768. Merge Strings Alternately java (1) 2022.09.21 566. Reshape the Matrix java (1) 2022.09.21 1672. Richest Customer Wealth java (0) 2022.09.21 283. Move Zeroes java (0) 2022.09.20 1588. Sum of All Odd Length Subarrays java (1) 2022.09.20