Skip to content

Commit

Permalink
Update flatten-2d-vector.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyu104 committed Aug 6, 2015
1 parent d148cb0 commit 6cb656a
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions Python/flatten-2d-vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@
# Space: O(1)

class Vector2D:
x, x_len = 0, 0
y, y_len = 0, 0
x, y = 0, 0
vec = None

# Initialize your data structure here.
# @param {integer[][]} vec2d
def __init__(self, vec2d):
self.vec = vec2d
self.x = 0
self.x_len = len(self.vec)
if self.x != self.x_len:
if self.x != len(self.vec):
self.y = 0
self.y_len = len(self.vec[self.x])
self.adjustNextIter()

# @return {integer}
Expand All @@ -26,11 +23,10 @@ def next(self):

# @return {boolean}
def hasNext(self):
return self.x != self.x_len and self.y != self.y_len
return self.x != len(self.vec) and self.y != len(self.vec[self.x])

def adjustNextIter(self):
while self.x != self.x_len and self.y == self.y_len:
while self.x != len(self.vec) and self.y == len(self.vec[self.x]):
self.x += 1
if self.x != self.x_len:
if self.x != len(self.vec):
self.y = 0
self.y_len = len(self.vec[self.x])

0 comments on commit 6cb656a

Please sign in to comment.