原创 Valid Number
判斷是否數字,考慮多種情況 class Solution{ public: bool isNumber(string s){ int i = 0; while(s[i] == ' ') ++i; while(
原创 Binary Search Tree Iterator
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST. C
原创 Median of Two Sorted Arrays
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall
原创 Binary Tree Maximum Path Sum
Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. 求樹的一點到另一點的最大路徑,利用遞歸
原创 Search for a Range
Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm's runt
原创 Search in Rotated Sorted Array I && II
對翻過一次的排序數組二分查找,要利用好已排序這個條件 class Solution { public: int search(int A[], int n, int target) { int left = 0,
原创 Dungeon Game
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consis
原创 Count and Say
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ... 1 is read off
原创 Balanced Binary Tree
檢測一個樹是否平衡,不需要求出高度,而是從底到頂檢測是否平衡,這樣纔算法時間複雜度爲O(n)。但是需要額外的O(logn)的空間 /** * Definition for binary tree * struct TreeNode {
原创 Find Minimum in Rotated Sorted Array I && II
這些題比較考驗邊界條件 Find Minimum in Rotated Sorted Array class Solution { public: int findMin(vector<int> &num) {
原创 socket 的通信過程
下圖是基於TCP協議的客戶端/服務器程序的一般流程: 服務器調用socket()、bind()、listen()完成初始化後,調用accept()阻塞等待,處於監聽端口的狀態,客戶端調用socket()初始化後,調用connect()
原创 Interleaving String
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example, Given:s1 = "aabcc",s2 = "dbb
原创 strcpy的實現
要考慮內存重疊 char * strcpy(char *dst,const char *src) { assert(dst != NULL && src != NULL); char *ret = dst; m
原创 Vector類的實現
實現部分vector的類 template <typename Object> class Vector{ public: explicit Vector(int initSize = 0) :theSize(initSi
原创 Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to le