原创 (LeetCode)二叉樹
0. 總結 二叉樹的核心就是用遞歸的思想解決問題,三個要素分析清楚: 尋求遞歸的子問題,子問題就是要解決的問題落實到一個(帶左右孩子的)節點上時應該怎麼做; 遞歸終止條件; 遞歸返回值; 1. 合併二叉樹 617. merge
原创 (LeetCode)排序
1. 排序鏈表 148. sort-list # Definition for singly-linked list. # class ListNode(object): # def __init__(self, x):
原创 (LeetCode)字符串
1. 實現 Trie (前綴樹) 208. implement-trie-prefix-tree class Trie(object): def __init__(self): """
原创 (LeetCode)哈希表
1. 兩數之和 1. two-sum class Solution(object): def twoSum(self, nums, target): """ :type nums: Lis
原创 (LeetCode)數組
1. 多數元素 169. majority-element class Solution(object): def majorityElement(self, nums): """ :ty
原创 (LeetCode)動態規劃
1. 買賣股票的最佳時機 121. best-time-to-buy-and-sell-stock class Solution(object): def maxProfit(self, prices):
原创 (LeetCode)鏈表
1. 反轉鏈表 206. reverse-linked-list # Definition for singly-linked list. # class ListNode(object): # def __init__
原创 (LeetCode)雙指針
1. 移動零 283. move-zeroes class Solution(object): def moveZeroes(self, nums): """ :type nums: Li
原创 (LeetCode)棧
1. 最小棧 155. min-stack class MinStack(object): def __init__(self): """ initialize your data st
原创 (LeetCode)全排列, 回溯法
1. 子集 78. subsets class Solution(object): def subsets(self, nums): """ :type nums: List[int]
原创 (LeetCode)位運算
1. 漢明距離 461. hamming-distance class Solution(object): def hammingDistance(self, x, y): """ :ty
原创 tornado異步client使用post方法
post_data = {'key1': 'value1'} body = urllib.urlencode(post_data) http_client = tornado.httpclient.AsyncHTTPClient(
原创 gevent實現異步
test_gevent.py import gevent import requests import time from gevent import monkey monkey.patch_all() def f(url,
原创 Python setuptools自動安裝git私有庫
install_requires=[ 'private_package_name==1.1', ], dependency_links=[ 'git+ssh://[email protected]/use
原创 服務多分片下的文件log問題
1. 常見錯誤 當你的服務開了多個分片,並且這多個分片打同一個log文件時,經常會出一些問題,比如: log打串,分片之間產生的請求log相互交叉,閱讀起來極爲困難; 甚至會出現行內串掉的情況,比如一個分片一行還沒打完,另外一個