본문 바로가기
HackerRank

Diagonal Difference C#

by Doromi 2023. 10. 4.
728x90
반응형
  public static int diagonalDifference(int n,List<List<int>> arr)
    {
        int LTR = 0, RTL = 0;
        for(int i = 0;i<n;i++){
            LTR += arr[i][i];
            RTL += arr[(n-1)-i][i];      

        }
        return Math.Abs(LTR-RTL);

    }

대각선 합 더 쉽게 구할 수 있는 방법 있으면 공유해주세요~

728x90
반응형

'HackerRank' 카테고리의 다른 글

Tree: Preorder Traversal  (0) 2023.10.04
Tree: Postorder Traversal  (0) 2023.10.04
Lonely Integer C#  (0) 2023.10.04
Mini-Max Sum C#  (0) 2023.10.04
Plus Minus C#  (0) 2023.10.04