標籤:Given a binary tree, return the preorder traversal of its nodes‘ values. For example:Given binary tree {1,#,2,3}, 1 2 / 3return [1,2,3].二叉樹的前序走訪,根節點→左子樹→右子樹解題思路一:遞迴實現,JAVA實現如下: public List<Integer>
標籤:Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set. get(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return
標籤:內容:ThreadLocal:允許我們建立只能被同一個線程讀寫的變數,例如Web應用中將變數從前端到後台,並且需要在這次請求的線程中始終可以隨時擷取到。內部實現是通過一個ThreadLocalMap這個Map結構來實現的,將線程對象作為Key,變數副本作為Value。public class TestThreadLocal {public static class MyRunnable1 implements Runnable {private
標籤:Given an array of integers, every element appears twice except for one. Find that single one. Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra
標籤:set特性Set中不允許出現重複元素,是根據什麼原理呢?答案是:根據equals()方法來區分的。那麼如想自訂類對象執行個體在Set中不重複出現,則需要覆寫equals方法了: 這裡我們假定自訂類為Person:package Public;public class Person{ private int age; private String name; public Person() { super(); } public
標籤:內容:藉助網上的解釋:第一步分割任務。首先我們需要有一個fork類來把大任務分割成子任務,有可能子任務還是很大,所以還需要不停的分割,直到分割出的子任務足夠小。第二步執行任務併合並結果。分割的子任務分別放在雙端隊列裡,然後幾個啟動線程分別從雙端隊列裡擷取任務執行。子任務執行完的結果都統一放在一個隊列裡,啟動一個線程從隊列裡拿資料,然後合并這些資料。public class CountTaskTmp extends RecursiveTask<Integer>{private
標籤:題目:There are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair: [0,1]Given