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 Packer: | |
| delimiter = '#|#' | |
| @staticmethod | |
| def pack(string_list): | |
| packed = '' | |
| for s in string_list: | |
| mlist = list(s) | |
| for i, char in enumerate(mlist): | |
| if char == '#': |
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
| <script src="https://cdn.rawgit.com/moski/gist-Blogger/master/public/gistLoader.js" type="text/javascript"></script> |
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
| <div class="github-card" data-user="UserID"></div> | |
| <script src="//cdn.jsdelivr.net/github-cards/latest/widget.js"></script> |
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
| <div class="github-widget pull-left" | |
| data-toggle="github-widget" | |
| data-user="UserId" | |
| data-widget="gists" | |
| data-body="auto" | |
| data-footer="auto" | |
| data-limit="4"> | |
| </div> | |
| <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" /> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.min.css" /> |
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
| """ | |
| Design an algorithm and write code to serialize and deserialize a binary tree. | |
| Writing the tree to a file is called 'serialization' | |
| and reading back from the file to reconstruct | |
| the exact same binary tree is 'deserialization'. | |
| There is no limit of how you deserialize or serialize a binary tree, | |
| you only need to make sure you can serialize a binary tree to a string | |
| and deserialize this string to the original structure. | |
| Have you met this question in a real interview? Yes | |
| Example |
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')) |
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
| 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 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, label): | |
| self.label = label | |
| self.childrens = [] | |
| self.sibling = None | |
| def __str__(self): | |
| return 'Tree[' + str(self.label) + ']' | |
| class BinaryTreeNode: |