標籤: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
標籤: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
標籤:You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will
標籤:轉自http://tutorials.jenkov.com/java-concurrency/volatile.htmlThe Java volatile keyword is used to mark a Java variable as "being stored in main memory". More precisely that means, that every read of a volatile variable will be read from
標籤:Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.解題思路:計算n能達到的5的最大次冪,算出在這種情況下能提供的5的個數,然後減去之後遞迴即可,JAVA實現如下:static public int trailingZeroes(int n) {if(n<25)return
標籤:Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element always exist in the array.解題思路:編程之美P130
標籤: 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
標籤:題目:You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in wordsexactly once and without any
標籤:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).Find the minimum element.You may assume no duplicate exists in the array.解題思路:本題和Java for LeetCode 033 Search in Rotated
標籤:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).Find the minimum element.The array may contain duplicates.解題思路:參考Java for LeetCode 081 Search in Rotated Sorted Array II