LintCode有大部分題目來自LeetCode,但LeetCode比較卡,下面以LintCode為平台,簡單介紹我AC的幾個題目,並由此引出一些算法基礎。 1)兩數之和(two-sum) 題目編 ...
LintCode有大部分題目來自LeetCode,但LeetCode比較卡,下面以LintCode為平台,簡單介紹我AC的幾個題目,並由此引出一些算法基礎。 1)兩數之和(two-sum) 題目編 ...
描述 設計一種方法,通過給重復字符計數來進行基本的字符串壓縮。 例如,字符串 aabcccccaaa 可壓縮為 a2b1c5a3 。而如果壓縮后的字符 ...
Given a sequence of integers, find the longest increasing subsequence (LIS). You code should ret ...
There are n coins with different value in a line. Two players take turns to take one or tw ...
For an array A, if i < j, and A [i] > A [j], called (A [i], A [j]) is a reverse pair.return ...
Given an array of integers and a number k, find k non-overlapping subarrays which have the largest s ...
Reverse digits of an integer. Returns 0 when the reversed integer overflows (signed 32-bit int ...
自己寫的代碼有幾個比較大的用例一直過不去,網上的代碼大部分有問題,思路是先將鏈表置空表,再將鏈表中的元素循環插入到指定位置。 下面是一份正確的代碼,但是是帶頭節點的鏈表: void ...
Given an integer array nums with all positive numbers and no duplicates, find the number o ...
主要利用快排遞歸划分的思想,可以在期望復雜度為O(n)的條件下求第k大數。快排的期望復雜度為O(nlogn),因為快排會遞歸處理划分的兩邊,而求第k大數則只需要處理划分的一邊,其期望復雜 ...