This file contains hidden or 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
| class Solution: | |
| def find_equal_subsets(self, arr): | |
| """ | |
| @param: arr: List[str] | |
| @return: Tuple | |
| """ | |
| total = sum(arr) | |
| # if half subsets value exist | |
| if total % 2 != 0: | |
| return |
This file contains hidden or 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
| class SegmentTreeNode: | |
| def __init__(self, st, ed, mval): | |
| self.st = st | |
| self.ed = ed | |
| self.min = mval | |
| class SegmentTree: | |
| def __init__(self, arr): | |
| if not arr: | |
| raise 'Empty input array' |
This file contains hidden or 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
| """ | |
| Definition of TreeNode: | |
| class TreeNode: | |
| def __init__(self, val): | |
| self.val = val | |
| self.left, self.right = None, None | |
| """ | |
| class Solution: | |
| """ | |
| @param root: The root of the binary search tree. |
This file contains hidden or 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
| """ | |
| Definition of TreeNode: | |
| class TreeNode: | |
| def __init__(self, val): | |
| self.val = val | |
| self.left, self.right = None, None | |
| """ | |
| class Solution: |
This file contains hidden or 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
| """ | |
| Definition of TreeNode: | |
| class TreeNode: | |
| def __init__(self, val): | |
| self.val = val | |
| self.left, self.right = None, None | |
| """ | |
| import collections | |
This file contains hidden or 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
| class TreeNode: | |
| def __init__(self, label): | |
| self.label = label | |
| self.childrens = [] | |
| self.sibling = None | |
| def __str__(self): | |
| return 'Tree[' + str(self.label) + ']' | |
| class BinaryTreeNode: |
This file contains hidden or 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
| class QuickSort: | |
| def sort(self, arr): | |
| self.qsort(arr, 0, len(arr) - 1) | |
| return arr | |
| def qsort(self, arr, st, ed): | |
| if st >= ed: | |
| return | |
| index = self.partition(arr, st, ed) |
This file contains hidden or 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
| class TreeNode: | |
| def __init__(self, val): | |
| self.val = val | |
| self.left = self.right = None | |
| def __str__(self): | |
| return '[' + str(self.val) + ']' | |
| class LCA: | |
| def find_lca(self, root, A, B): | |
| if not root: |
This file contains hidden or 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
| class BinarySearch: | |
| @staticmethod | |
| def find_first_position(arr, target): | |
| st, ed = 0, len(arr) - 1 | |
| while st + 1 < ed: | |
| mid = (st + ed) / 2 | |
| if arr[mid] == target: | |
| ed = mid | |
| elif arr[mid] < target: | |
| st = mid |
This file contains hidden or 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
| #!/usr/bin/env python3 | |
| import chardet | |
| from colorclass import Color | |
| from terminaltables import AsciiTable | |
| def generate_test(chars_list): | |
| table_data = [['Chars', 'Confidence', 'Encoding', 'Issue'], ] | |
| for chars in chars_list: | |
| result = chardet.detect(chars.encode('utf-8')) |