Skip to content

Commit

Permalink
delete week03, and refactor according to tags
Browse files Browse the repository at this point in the history
  • Loading branch information
selfboot committed Nov 6, 2015
1 parent 6b21918 commit db7ffcf
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 44 deletions.
7 changes: 7 additions & 0 deletions Week03/22.py → Backtracking/22_GenerateParentheses.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,10 @@ def generate_child_tree(self, node, n, solution):
right_child = [None, None, node[2], node[3] + 1, node[4] + ")"]
node[1] = right_child
self.generate_child_tree(right_child, n, solution)

"""
0
1
3
5
"""
5 changes: 5 additions & 0 deletions Week03/23.py → Heap/23_MergeKSortedLists.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,8 @@ def mergeKLists(self, lists):
heapq.heappush(heap_record, (next_node.val, next_node))

return head.next

"""
[]
[[1,4,5,6,9], [2,3,4,5,6,8], [0,1,2,3,4], [2,2,2,2]]
"""
9 changes: 9 additions & 0 deletions Week03/21.py → LinkedList/21_MergeTwoSortedLists.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,12 @@ def mergeTwoLists(self, l1, l2):
merged_list = merged_list.next

return merged_head.next

"""
[]
[]
[1,4,8,12]
[2,3]
[1,3,5,7,9]
[2,4,6,8,10]
"""
7 changes: 7 additions & 0 deletions Week03/24.py → LinkedList/24_SwapNodesInPairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ def swapPairs(self, head):
else:
break
return result.next

"""
[]
[1]
[1,2,3]
[1,2,3,4,5,6]
"""
9 changes: 9 additions & 0 deletions Week03/25.py → LinkedList/25_ReverseNodesIn-k-Group.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,12 @@ def reverse_k_nodes(self, before_node, after_node):
before_node.next = reversed_list_head
reversed_list_tail.next = after_node
return reversed_list_tail

"""
[]
1
[1]
1
[1,2,3,4,5,6,7,8,9]
4
"""
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
# [Linked List](LinkedList/)

* 02. [Add Two Numbers](LinkedList/02.AddTwoNumbers.py)
* 21. [Merge Two Sorted Lists](LinkedList/21_MergeTwoSortedLists.py)
* 24. [Swap Nodes in Pairs](LinkedList/24_SwapNodesInPairs.py)
* 25. [Reverse Nodes in k-Group](LinkedList/25_ReverseNodesIn-k-Group.py)
* 61. Rotate List
* 82. Remove Duplicates from Sorted List II
* 83. Remove Duplicates from Sorted List
Expand All @@ -38,6 +41,9 @@
* 03. [Longest Substring Without Repeating Characters](HashTable/03_LongestSubstringWithoutRepeatingCharacters.py)
* 18. `4Sum`

# [Heap](Heap/)
* 23. [Merge k Sorted Lists](Heap/23_MergeKSortedLists.py)

# [Binary Search](BinarySearch/)

* 69. Sqrt(x)
Expand All @@ -57,6 +63,7 @@

# [Backtracking](Backtracking/)

* 22. [Generate Parentheses](Backtracking/23_GenerateParentheses.py)
* 51. N-Queens
* 52. N-Queens II
* 79. Word Search
Expand Down Expand Up @@ -87,6 +94,7 @@

# [Stack](Stack/)

* 20. [Valid Parentheses](Stack/20_ValidParentheses.py)
* 71. [Simplify Path](Stack/71_SimplifyPath.py)
* 84. [Largest Rectangle in Histogram](Stack/84_LargestRectangleInHistogram.py)
* 85. [Maximal Rectangle](Stack/85_MaximalRectangle.py)
Expand Down Expand Up @@ -117,5 +125,5 @@

# DFA

* 65. [Valid Number](65_ValidNumber.py)
* 65. [Valid Number](DFA/65_ValidNumber.py)

35 changes: 35 additions & 0 deletions Stack/20_ValidParentheses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-


class Solution(object):
def isValid(self, s):
"""
:type s: str
:rtype: bool
"""
parenthes_stack = []
match_rule = {")": "(", "]": "[", "}": "{"}
for symble in s:
if symble == "(" or symble == "[" or symble == "{":
parenthes_stack.append(symble)

else:
# Check if stack top matches the current ), ] or }.
if (parenthes_stack and
parenthes_stack[-1] == match_rule[symble]):
parenthes_stack.pop()
else:
return False
# Have some symbles that is not matched.
if parenthes_stack:
return False

return True

"""
""
"["
"()()()()[]"
"()((()){})"
"""
43 changes: 0 additions & 43 deletions Week03/20.py

This file was deleted.

0 comments on commit db7ffcf

Please sign in to comment.