Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

matrix diagonal sum leetcode in java

# Problem Link : https://leetcode.com/problems/matrix-diagonal-sum/

class Solution(object):
    def diagonalSum(self, array):
        """
        :type array: List[List[int]]
        :rtype: int
        """
        n = len(array)
        primary = 0
        secondary = 0;
        for i in range(0, n):
            primary += array[i][i]
            secondary += array[i][n-i-1]
        if (n % 2 == 0): return primary + secondary
        else: return primary + secondary - array[n//2][n//2]
Comment

PREVIOUS NEXT
Code Example
Python :: color plt 
Python :: free download django app for windows 10 
Python :: append in python 
Python :: yml anaconda 
Python :: calculate quantiles python 
Python :: fast input python 
Python :: flask app with spark 
Python :: django create view class 
Python :: pylab plotting data 
Python :: python find first occurrence in list 
Python :: sort 2 lists together python 
Python :: list vs tuple python 
Python :: simple heatmap 
Python :: merge keep left index 
Python :: get index of dataframe 
Python :: python conditions 
Python :: python library for downsampling a photo 
Python :: open pdfs using python 
Python :: defaultdict python 
Python :: Kivy Python ListView Scrollview with Toggle on off 
Python :: python to linux executable 
Python :: group by pandas 
Python :: #adding new str to set in python 
Python :: dtype array 
Python :: django class based views 
Python :: reply_photo bot telegram python 
Python :: import matplotlib sub 
Python :: how to merge dictionaries in python 
Python :: how to add elements to a dictionary 
Python :: arrays in python 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =