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
| def quick_sort(data: list[int]) -> list[int]: | |
| if (length := len(data)) <= 1: | |
| return data | |
| pivot = data.pop(length // 2) | |
| smaller_list = [i for i in data if i < pivot] | |
| bigger_list = [i for i in data if i >= pivot] | |
| return quick_sort(smaller_list) + [pivot] + quick_sort(bigger_list) |
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
| def get_aid_from_url(url: str) -> (str, str): | |
| # from get_aid_from_url in PyPtt | |
| # 檢查是否符合 PTT BBS 文章網址格式 | |
| pattern = re.compile('https://www.ptt.cc/bbs/[-.\w]+/M.[\d]+.A[.\w]*.html') | |
| r = pattern.search(url) | |
| if r is None: | |
| raise ValueError('url must be www.ptt.cc article url') |
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 for singly-linked list. | |
| # class ListNode: | |
| # def __init__(self, val=0, next=None): | |
| # self.val = val | |
| # self.next = next | |
| def get_reversed_linked_list(self, root): | |
| current_node = root | |
| next_node = root.next | |
| pre_node = None |
NewerOlder