標籤: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 the total number of courses and a
標籤:Description:Count the number of prime numbers less than a non-negative number, n.解題思路:空間換時間,開一個空間為n的數組,因為非素數至少可以分解為一個素數,因此遇到素數的時候,將其有限倍置為非素數,這樣動態遍曆+構造下來,沒有被設定的就是素數。public int countPrimes(int n) {if (n <= 2)return 0;boolean[] notPrime = new
標籤:Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with another character while preserving the order of characters.
標籤:Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5解題思路:JAVA實現如下: public ListNode
標籤:Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive.For example, given the range [5, 7], you should return 4.解題思路:本題有很多思路,最簡單的方法:result就是m和n二進位前面相同的部分!!!JAVA實現如下: public
標籤:Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. For example:Given the following binary tree, 1 <--- / 2 3 <--- \
標籤: The SortedMap interface extends Map. It ensures that the entries are maintained in ascending key orderSeveral methods throw a NoSuchElementException when no items are in the invoking map. A ClassCastException is thrown when an object is