原创 lintcode: ugly number

問題描述 Ugly number is a number that only have factors 3, 5 and 7. Design an algorithm to find the Kth ugly number. Th

原创 中序遍歷二叉樹+O(1)空間

問題描述 中序遍歷二叉樹時,很簡單,需要加上遞歸就可以優雅地實現了。當然,使用遞歸的話,函數調用棧的空間就會達到O(log n)。那麼有什麼方式,可以使得中序遍歷二叉樹的複雜度爲O(1)呢? 問題分析 既然要保證O(1)複雜度,那

原创 [Lintcode] Maximum Gap Problem

問題描述 在一個無序的數組中,如果對其進行排序,然後掃描一遍有序數組,可以獲得相鄰兩元素的最大差值,比如 {-1, 2, 4, 9},那麼最大差值就是4和9之間,是5. 現在如果不對原始數組進行排序,有什麼好的方案,來獲取有序

原创 【算法】直方圖中最大面積問題

問題描述 給定一個直方圖,求這個直方圖中最大矩陣對應的面積是多少? 比如有個圖如下 (對應的數組爲:[2,1,5,6,2,3]) 那麼對應的最大矩形的面積應該爲 10: 問題分析 這類題是很常見的一道題,也是面試當中很容

原创 [概率]m個球扔到n個盒子

問題描述 有m個球,要扔到n個盒子裏。其中每個球都是互相獨立地扔。問最後平均有幾個盒子是有球的? 問題解析 這類問題是較爲純粹的數學問題,當然也可以用計算機精確地求出答案。 方案一:編程解決 p(m, i):表示前 m 個球,扔

原创 Timezone in Python

Just as a mark If we want to set PST timezone for a given datetime, it should be usually UTC-8. But sometimes it coul

原创 debug date filter in logstash

Background Recently some guys came by and were curious about the date filter in logstash (both 2.4 and 5.x, but I am us

原创 [Elasticsearch] setup Elasticsearch in intellij idea

Introduction Elasticsearch is quite a cool project. This post introduces how to setup Elasticsearch in IntelliJ Idea lo

原创 Kibana aggregation with missing / null fields

Background Kibana is a good tool for aggregations. It looks like the group by in mysql. However Kibana will ignore docu

原创 Vim 多行替換

Replace multiple lines in Vim Aim // to replace the following line with new multiple lines // original line

原创 Kibana displays customized percentage in pie chart

Introduction Kibana 3 has got a good pie chart, which will displays the percentage label by default. But when it comes

原创 [Kibana > Timelion] Timelion.json is not working

Just a mark to investigate the reason configuration file of Timelion plugin is not working. It is maybe a designed feat

原创 Java ObjectMapper String轉HashMap

Just to remind HashMap<String, Object> rDefHashMap = om.readValue(rDefStr, new TypeReference<HashMap<String, Object>>()

原创 [Kibana > Timelion] Divide multi-valued seriesList by another multi-valued seriesList

Kibana Timelion Plugin Enhancement Why need to divide multiple valued seriesList? Timelion is quite a great plugin for

原创 Best time to buy and sell stocks IV

題目 https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv/ Say you have an array for which the ith element i