Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Tape Equilibrium

//Time complexity of 100% and correctness of 100%
def solution(A):
    total = 0
    left_total = 0
    right_total = 0
    if len(A) == 0:
        return 0
    elif len(A) == 1:
        return A[0]

    for x in range(1,len(A)):
        left_total += A[x-1]

        if x == 1:
            right_total = sum(A[x:])
        else:
            right_total -= A[x-1]

        mySum =abs(right_total-left_total)

        if x == 1 or total > mySum:
            total = mySum

    return total
Comment

PREVIOUS NEXT
Code Example
Python :: even number list generator 
Python :: Show output of views in html using ajax, django 
Python :: more args python 
Python :: open weather get local time python 
Python :: Implement a function word_list() that reads the 5_letter_words.txt file and returns a list of the words in the file. 
Python :: Improve the Request Change User-Agent 
Python :: python zpl 
Python :: Python Global variable and Local variable with same name 
Python :: Python String Membership 
Python :: Python Deleting Attributes and Objects 
Python :: osmapi 
Python :: How to deal with SettingWithCopyWarning in Pandas 
Python :: With Python, it is possible to use the ** operator to calculate powers 
Python :: latex new command with arguments 
Python :: python dateien auflisten 
Python :: dataframe to DatasetDict 
Python :: python ternary mittels tupel index 
Python :: python 2 factor authentication 
Python :: colab show all value 
Python :: rich import in python 
Python :: how to produce txt file from list python 
Python :: matplotlib gfg 
Python :: add column to wandb.Table 
Python :: custom point annotation pyplot scatter 
Python :: how to enumerate the names inside a list python 
Python :: some problem occurred shows payubiz 
Python :: hover 777-286 
Python :: python print list in dictionary 
Python :: moving element to the start ofa list python 
Python :: Python Script to check how many images are broken 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =