-
Notifications
You must be signed in to change notification settings - Fork 211
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
Showing
6 changed files
with
82 additions
and
41 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,3 @@ | ||
{ | ||
"python.pythonPath": "C:\\ProgramData\\Anaconda2\\envs\\py3\\python.exe" | ||
} |
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 wiggleSort(self, nums): | ||
""" | ||
:type nums: List[int] | ||
:rtype: None Do not return anything, modify nums in-place instead. | ||
""" | ||
if not nums: | ||
return nums | ||
i = 0 | ||
while i < len(nums): | ||
if i % 2 == 0 and i < len(nums) - 1 and nums[i] > nums[i + 1]: | ||
nums[i], nums[i + 1] = nums[i + 1], nums[i] | ||
elif i % 2 and i < len(nums) - 1 and nums[i] < nums[i + 1]: | ||
nums[i], nums[i + 1] = nums[i + 1], nums[i] | ||
else: | ||
i += 1 | ||
return nums |
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
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
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
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,23 @@ | ||
# Definition for a binary tree node. | ||
# class TreeNode(object): | ||
# def __init__(self, x): | ||
# self.val = x | ||
# self.left = None | ||
# self.right = None | ||
|
||
class Solution(object): | ||
def inorderSuccessor(self, root, p): | ||
""" | ||
:type root: TreeNode | ||
:type p: TreeNode | ||
:rtype: TreeNode | ||
""" | ||
if not root: | ||
return None | ||
def inorder(node): | ||
if not node: | ||
return [] | ||
return inorder(node.left) + [node] + inorder(node.right) | ||
l = inorder(root) | ||
i = l.index(p) | ||
return l[i + 1] if i < len(l) - 1 else None |