Skip to content

Instantly share code, notes, and snippets.

@rpf5573
Created March 4, 2019 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rpf5573/95650bf434a29a3c3be51b32de3465f2 to your computer and use it in GitHub Desktop.
Save rpf5573/95650bf434a29a3c3be51b32de3465f2 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
def solution(left, right):
total = 0
indexOfLeft = 0
indexOfRight = 0
lengthOfLeft = len(left)
lengthOfRight = len(right)
while( (lengthOfLeft != indexOfLeft) and (lengthOfRight != indexOfRight) ):
l = left[indexOfLeft]
r = right[indexOfRight]
if l > r :
total = total + r
indexOfRight = indexOfRight + 1
continue
if l <= r :
additionalIndex = 0
for i in range(indexOfLeft+1, lengthOfLeft):
l = left[i]
if l > r :
additionalIndex = additionalIndex + 1
break
if additionalIndex > 0 :
indexOfLeft = indexOfLeft + additionalIndex
else :
indexOfLeft = indexOfLeft + 1
indexOfRight = indexOfRight + 1
continue
return total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment