標籤:Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers 0, 1, and 2 to represent the color red, white, and
標籤:Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted from left to right.The first integer of each row is greater than the last integer of the
標籤:最大堆的性質是除了根節點之外的所有節點(i)都需要滿足A[PARENT(i)]>A[i],即其對應節點值小於其父節點對應值。下面實現以數組int []a構建最大堆。 public class Heap {public static int Left(int i)//返回左子結點{return 2*i+1;}public static int Right(int i)//返回右子節點{return 2*i+2;}public static void
標籤:內容:一個簡單的死結例子,大概的思路:兩個線程A和B,兩把鎖X和Y,現在A先拿到鎖X,然後sleep()一段時間,我們知道sleep()是不會釋放鎖資源的。然後如果這段時間軸程B拿到鎖Y,也sleep()一段時間的話,那麼等到兩個線程都醒過來的話,那麼將互相等待對方釋放鎖資源而僵持下去,陷入死結。flag的作用就是讓A和B獲得不同的鎖。public class TestDeadLock {public void run() {MyThread mt = new
標籤:Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ]] 解題思路:參考Java for LeetCode 05
標籤:一 string public final class String繼承自java.lang.Object類。實現了介面:java.io.Serializable, Comparable<String>, CharSequenceString類是不能被修改的字串。因為String類裡面的資料是final類型的。 區別兩種方式:① String s = "aaaa";② String s1 = new String("aaaa");對於第一種,只在池中建立,