原创 幾種sort的優劣勢

quicksort有最好的實踐效率。同時是in-place。配上random pivot/shuffle,median-of-K 和 少量元素轉insertion sort是最實用的排序方法。O(n^2)複雜度是極其小概率事件,一般不會發

原创 longest Palindrome substring

class Solution { public: string longestPalindrome(string s) { // Start typing your C/C++ solution below

原创 [leetcode] Distinct Subsequences

Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a

原创 找出一個bst中第二大的數

search the most right node from root. If the most right root has no child,

原创 [leetcode]longest Valid Parentheses(!!)

class Solution { public: int longestValidParentheses(string s) { // Start typing your C/C++ solution below

原创 Maximum Subarrary

Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For exampl

原创 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

原创 LeetCode Single Number I & II 都符合兩個問題額外要求的 通用解法 與 思考過程

Single Number Given an array of integers, every element appears twice except for one. Find that single one. Note: Yo

原创 [leetcode]

Given a sorted array and a target value, return the index if the target is found. If not, return the index where it w

原创 leetcode power (x,n)

1. 考慮double float 的相等,不能僅僅用==表示,是有精度限制的。 2.  n 大於0,小於0的情況 3. if (temp_diveded & 1) result *= base;

原创 [leetcode ] gray code

class Solution { public: vector<int> grayCode(int n) { vector<int> results; do{ if (n <

原创 find medium of two array

class Solution { public: double findMedianSortedArrays(int A[], int m, int B[], int n) { // Start typing y

原创 Divide Two Integers

class Solution { public: int divide(int dividend, int divisor) { // Start typing your C/C++ solution below

原创 reverse interger

Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 Have you thought abou

原创 [leetcode] simplify path

Given an absolute path for a file (Unix-style), simplify it. For example,path = "/home/", => "/home"path = "/a/./b/