原创 Jump Game I and II leetcode

Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element i

原创 C++中map、hash_map、unordered_map、unordered_set通俗辨析

一、hash_map、unordered_map 這兩個的內部結構都是採用哈希表來實現。區別在哪裏?unordered_map在C++11的時候被引入標準庫了,而hash_map沒有,所以建議還是使用unordered_map比較好。

原创 Palindrome Partitioning I and II leetcode

Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palind

原创 Edit Distance leetcode

Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation

原创 C++ 棧對象 堆對象 理解

在C++中,類的對象建立分爲兩種,一種是靜態建立,如A a;另一種是動態建立,如A* ptr=new A;這兩種方式是有區別的。 1、靜態建立類對象:是由編譯器爲對象在棧空間中分配內存,是通過直接移動棧頂指針,挪出適當的空間,然後在這

原创 Permutation Sequence leetcode

The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in o

原创 壓棧思想計算運算表達式

棧的規則是先進後出。利用壓棧的思想來計算四則運算表達式是這樣的:我們給定兩個棧,一個用來存放數字、一個用來存放對應的操作符。假定我們有一個給定的四則運算表達式a+b+c/d*(e+f)-d*a,那我們先把這個表達式拆分成一個個的數字

原创 Best Time to Buy and Sell Stock III leetcode

Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find t

原创 Merge k Sorted Lists leetcode

Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 這道題目在分佈式系統中非常常見,來

原创 最長公共子串和最長公共子序列

 注意最長公共子串(Longest CommonSubstring)和最長公共子序列(LongestCommon Subsequence, LCS)的區別:子串(Substring)是串的一個連續的部分,子序列(Subsequence)則

原创 Clone Graph leetcode

Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. 這裏使用深度優先搜索。這樣可以遞歸實現,

原创 Implement strStr() leetcode

Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of

原创 Sqrt(x) leetcode

Implement int sqrt(int x). Compute and return the square root of x. 這是一道數值處理的題目,和Divide Two Integers不同,這道題一般採用數值中經常用

原创 First Missing Positive leetcode

Given an unsorted integer array, find the first missing positive integer. For example, Given [1,2,0] return 3, and [3

原创 求最長單調遞減子序列

解法一:   首先將這個序列進行排序,然後再求出已排序的和未排序的這兩個數列最長公共子序列 解法二:就是用動態規劃法來解決問題  問題描述:求一個數組的最長遞減子序列 比如{9,4,3,2,5,4,3,2}的最長遞減子序列爲