原创 [LintCode]Wiggle Sort

http://www.lintcode.com/en/problem/wiggle-sort/ Given an unsorted array nums, reorder it in-place such that nums[0] <

原创 [LintCode]Number of Airplanes in the Sky

http://www.lintcode.com/en/problem/number-of-airplanes-in-the-sky/# 給出起降時間,判斷最多有多少飛機同時在天上 解法一: HashMap,內外循環,內層循環當前飛機

原创 [LintCode]Print Numbers by Recursion

http://www.lintcode.com/en/problem/print-numbers-by-recursion/ 遞歸打印1 ~ n,n可能很大,要防止棧溢出 public class Solution {

原创 [LeetCode]460. LFU Cache

https://leetcode.com/problems/lfu-cache/#/description 實現一個 Least Frequently Used (LFU),保存訪問頻率最高的capacity個數,如果要淘汰的可能有多個數

原创 [LintCode]Paint House II

http://www.lintcode.com/en/problem/paint-house-ii/# 刷房子,每個房子刷每種顏色有一個cost[i][j],相鄰兩個房子不能刷同一種顏色,求最小cost 要求時間複雜度O(NK) 每次

原创 [LeetCode]643. Maximum Average Subarray I

https://leetcode.com/problems/maximum-average-subarray-i/#/description 找出連續k個數平均值最大的那個平均值,注意註釋! public class Solu

原创 [LeetCode]632. Smallest Range

https://leetcode.com/problems/smallest-range/#/description 給k個遞增數組,找出一個最小範圍,保證每個數組內至少有一個數字落在這個區間上 類似歸併排序思想——多維有序數組

原创 面試常見問題——操作系統

線程切換開銷: 1、內存同步(每個線程都用內存保存線程本地棧) 2、上下文切換開銷 3、線程調度開銷(需要佔用操作系統資源) 數據庫事務隔離四個級別: 隔離級別 髒讀(Dirty Read) 不可重複讀(NonRepeatable

原创 [LeetCode]630. Course Schedule III

https://leetcode.com/problems/course-schedule-iii/#/description 每個課程c是長度爲2的數組,c[0]爲課程時間長度,c[1]爲課程最晚截止時間 先按照c[1]遞增排序,

原创 [LeetCode]581. Shortest Unsorted Continuous Subarray

https://leetcode.com/problems/shortest-unsorted-continuous-subarray/#/description 找到最短連續子數組,將這個子數組排序之後整個數組就有序了。求最短子數組長度

原创 [LeetCode]636. Exclusive Time of Functions

https://leetcode.com/problems/exclusive-time-of-functions/#/description 給一個log數組,表示非搶佔式CPU調用function的情況。格式爲id:start or

原创 [LeetCode]638. Shopping Offers

https://leetcode.com/problems/shopping-offers/#/description 給每種商品的價格、多組不同offer(每個offer內最後一個爲價格,前面爲每種商品在這個offer內的數量)、最終要

原创 [LeetCode]565. Array Nesting

https://leetcode.com/problems/array-nesting/#/description 給一個長度N的數組,裏面元素爲1 ~ N - 1 找到最長的子數組 S[K] = { A[K], A[A[K]], A[A

原创 [LeetCode]600. Non-negative Integers without Consecutive Ones

https://leetcode.com/problems/non-negative-integers-without-consecutive-ones/#/description 給一個數n,找出有多少個不大於n的正數,且這些正數的二進

原创 [LeetCode]624. Maximum Distance in Arrays

https://leetcode.com/problems/maximum-distance-in-arrays/#/description 找出不同數組之間數字差值絕對值的最大值 每個數組內部都是遞增的 因爲不能算上同一數組