-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac23e98
commit f327df3
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# """ | ||
# This is the interface that allows for creating nested lists. | ||
# You should not implement it, or speculate about its implementation | ||
# """ | ||
#class NestedInteger(object): | ||
# def isInteger(self): | ||
# """ | ||
# @return True if this NestedInteger holds a single integer, rather than a nested list. | ||
# :rtype bool | ||
# """ | ||
# | ||
# def getInteger(self): | ||
# """ | ||
# @return the single integer that this NestedInteger holds, if it holds a single integer | ||
# Return None if this NestedInteger holds a nested list | ||
# :rtype int | ||
# """ | ||
# | ||
# def getList(self): | ||
# """ | ||
# @return the nested list that this NestedInteger holds, if it holds a nested list | ||
# Return None if this NestedInteger holds a single integer | ||
# :rtype List[NestedInteger] | ||
# """ | ||
|
||
class NestedIterator(object): | ||
|
||
def __init__(self, nestedList): | ||
""" | ||
Initialize your data structure here. | ||
:type nestedList: List[NestedInteger] | ||
""" | ||
self.list = self.flatten(nestedList) | ||
self.index = 0 | ||
|
||
def flatten(self, nestedList): | ||
result = [] | ||
for item in nestedList: | ||
if item.isInteger(): | ||
result.append(item.getInteger()) | ||
else: | ||
result += self.flatten(item.getList()) | ||
return result | ||
|
||
def next(self): | ||
""" | ||
:rtype: int | ||
""" | ||
if self.index >= len(self.list): | ||
return None | ||
v = self.list[self.index] | ||
self.index += 1 | ||
return v | ||
|
||
def hasNext(self): | ||
""" | ||
:rtype: bool | ||
""" | ||
return self.index < len(self.list) | ||
|
||
# Your NestedIterator object will be instantiated and called as such: | ||
# i, v = NestedIterator(nestedList), [] | ||
# while i.hasNext(): v.append(i.next()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class Solution(object): | ||
def reverseVowels(self, s): | ||
""" | ||
:type s: str | ||
:rtype: str | ||
""" | ||
vowels = "aeiou" | ||
poses = [] | ||
for i,c in enumerate(s): | ||
if c.lower() in vowels: | ||
poses.append(i) | ||
|
||
chars = [c for c in s] | ||
for k in range(len(poses)/2): | ||
chars[poses[k]], chars[poses[-k-1]] = chars[poses[-k-1]], chars[poses[k]] | ||
|
||
return ''.join(chars) |