原创 102/107. Binary Tree Level Order Traversal/II

原文題目: 102. Binary Tree Level Order Traversal 107. Binary Tree Level Order Traversal II 讀題: 102. 層序遍歷二叉樹,每一層作爲一個數組,從上到下輸

原创 windows下多線程簡單demo

#include <iostream> #include <cstdlib> #include <Windows.h> using namespace std; int tickets = 100; HANDLE hMutex; DWOR

原创 尋找最大連續子串和以及尋找最長數字串

'''尋找最大連續子串和''' def find_max_sub_sum(data): if not data: return None sub = data[0] submax = data[0] for i in rang

原创 python中itertools裏的product和permutation

平時經常碰到全排列或者在n個數組中每個數組選一個值組成的所有序列等等問題,可以用permutation和product解決,很方便,所以在此mark一下吧 直接上代碼 from itertools import * if __name__

原创 DFS和BFS

#include <iostream> #include <stack> #include <queue> #include <stdlib.h> using namespace std; #define MAX 100 typedef

原创 108. Convert Sorted Array to Binary Search Tree

原文題目: 108. Convert Sorted Array to Binary Search Tree 讀題: 首先是個有序序列,從小到大排列,要轉成一個高度平衡的二叉搜索樹,那麼有序序列的中間那個數就是根節點,該數左邊的序列爲左孩子

原创 101. Symmetric Tree

本題判斷一個二叉樹是否爲對稱樹題目鏈接:101. Symmetric Tree# Definition for a binary tree node. # class TreeNode(object): # def __init_

原创 69. Sqrt(x)

原文題目: Implement int sqrt(int x). Compute and return the square root of x. 讀題: 題目就是求x的開根號,很重要的一點是返回值是整數,而不是浮點數,因此這個開根

原创 160. Intersection of Two Linked Lists

原文題目: 160. Intersection of Two Linked Lists 讀題: 給定兩個無環鏈表,判斷是否有交叉點,返回第一個交叉點 解題思路: 求出兩個鏈表長度lenA和lenB,得到兩者的差值,deltaLen = l

原创 112. Path Sum

原文題目: 112. Path Sum 讀題: 二叉樹中是否存在給定和爲給定數的路徑,遞歸實現最簡單 # Definition for a binary tree node. # class TreeNode(object): #

原创 118/119. Pascal's Triangle/II

原文題目: 118. Pascal's Triangle 119. Pascal's Triangle II 讀題: 楊輝三角問題 '''118''' class Solution(object): def generate(se

原创 python Excel的操作

算是學習記錄,平常用到的Excel表格的操作 import xlrd import matplotlib.pyplot as plt if __name__ == '__main__': target = xlrd.open_wo

原创 111. Minimum Depth of Binary Tree

原文題目: 111. Minimum Depth of Binary Tree 讀題: 求最小深度,這和求樹的最大深度差不多,只不過需要注意當左子樹或者右子樹爲空時,最小深度並不爲0,而是取決於非空子樹的最小深度 # Definition

原创 半精度浮點數取5bit指數位

半精度浮點是指用16bit表示一個浮點數,最高1bit爲符號位,中間5bit爲指數a,低10bit爲尾數b Value = (符號位)(1+b/1024)*(2^(a-16)) 程序很簡單,用pyinstaller -F getEx

原创 八皇后問題

八皇后問題描述大家都比較熟悉,就是在8*8的方格中放置8個皇后,使得8個皇后不在同一行、同一列以及不在對角線上,這樣8個皇后纔不會互相攻擊,求放置的方法有多少種? 答案就是92種。 解題思路:假設用C[j]表示皇后在j行代表的列號,也即皇