Commit 1ec0f302 authored by Siu, Pui Chung's avatar Siu, Pui Chung
Browse files

Add new file

parent 7eec0afc
def dirReduc(arr):
dict = {"NORTH":"SOUTH","SOUTH":"NORTH","EAST":"WEST","WEST":"EAST"}
path = [] #initialize stack
for dir in arr:
#if path not empty and previous direction is opp of current direction
if path != [] and dict[dir] == path[-1]:
path.pop()
else:
path.append(dir)
return path
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment