標籤:Reference: http://www.programcreek.com/2013/10/efficient-counter-in-java/ You may often need a counter to understand the frequency of something (e.g., words) from a database or text file. A counter can be easily implemented by using a
標籤:一、原廠模式 原廠模式的關鍵是:將建立對象和使用對象分開。(便於修改,如果有一天你建立對象的方式改變了,那麼只需修改工廠即可)(例)比如我想造一輛寶馬車並讓它跑起來,以前我們都是寫一個寶馬車的類然後直接在這個類裡邊執行個體化一個他的對象,完了以後緊接著在下邊寫寶馬車的跑的方法,是吧?但是原廠模式不這麼做,原廠模式怎麼做呢?請看下面的步驟:1.寫一個車的介面,並在裡邊定義一個車的go()方法:public interface Car { public void go();
標籤:There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).解題思路:由於要求時間複雜度O(log
標籤:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. Input: (2 -> 4 -> 3) + (5 ->
標籤:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note