Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

matrix diagonal sum leetcode in Python

# 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 :: django form example 
Python :: edit models in django admin 
Python :: pow() Function Function in python 
Python :: flask send email gmail 
Python :: pandas value in series 
Python :: django change settings at runtime 
Python :: flask on gevent over https 
Python :: merge 2 dataframes in python 
Python :: tensorflow.keras.utils.to_categorical 
Python :: pandas remove whitespace 
Python :: nested ternary operator python 
Python :: convert number to char python 
Python :: seaborn 
Python :: pandas dataframe from list how to make the date column an index 
Python :: remove item from list 
Python :: keyboard python 
Python :: Customize color stacked bar chart matplotlib 
Python :: numpy evenly spaced numbers 
Python :: strip characters from a string python 
Python :: Python Split list into chunks using for loop 
Python :: python doctype 
Python :: inpuit inf terfminal ppython 
Python :: pandas cummin 
Python :: data type array 
Python :: python write subprocess stdout stderr to file 
Python :: remove stopwords from a sentence 
Python :: Django delete a session value 
Python :: add a column with initial value to an existing dataframe 
Python :: django form field add attrs 
Python :: add item to tuple python 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =