Skip to content

Instantly share code, notes, and snippets.

@KaiserKatze
Last active July 10, 2019 15:00
Show Gist options
  • Select an option

  • Save KaiserKatze/3bb62d68c93a531efea603dd58629b2a to your computer and use it in GitHub Desktop.

Select an option

Save KaiserKatze/3bb62d68c93a531efea603dd58629b2a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
class Solution:
def __init__(self):
self.array = None
def create_array(self, array_length):
result = [0] * array_length;
self.array = result
def update_array(self, update_operation):
startIndex, endIndex, inc = update_operation
array = self.array
for index in range(startIndex, endIndex + 1):
array[index] += inc
@classmethod
def compare_update_opeartion(cls, operation0, operation1):
s0, e0, i0 = operation0
s1, e1, i1 = operation0
if s0 < s1:
return -1
elif s0 > s1:
return 1
if e0 < e1:
return -1
elif e0 > e1:
return 1
return 0
"""
@param length: the length of the array
@param updates: update operations
@return: the modified array after all k operations were executed
"""
def getModifiedArray(self, length, updates):
self.create_array(length)
for update in updates:
self.update_array(update)
return self.array
if __name__ == '__main__':
solution = Solution()
solution.getModifiedArray(5, [(1, 3, 2), (2, 4, 3), (0, 2, -2)])
assert(solution.array == [-2, 0, 3, 5, 3])
print('Test case passed.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment