標籤:Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.解題思路:用兩個boolean數組row col表示行列是否有零即可,JAVA實現如下:public void setZeroes(int[][] matrix) {if (matrix.length == 0 || matrix[0].length == 0)return;boolean[] row =
標籤:JAVA的LIST在刪除時,一般會用list.remove(o); 但這樣往往會出現問題,先來看下面的這段代碼:package com.demo;import java.util.ArrayList;import java.util.List;public class Test11 {public void delete(){List<Integer> list = new
標籤:Composite定義:將對象以樹形結構組織起來,以達成“部分-整體” 的階層,使得用戶端對單個對象和組合對象的使用具有一致性。Composite比較容易理解,想到Composite就應該想到樹形結構圖。組合體內這些對象都有共同介面,當組合體一個對象的方法被調用執行時,Composite將遍曆(Iterator)整個樹形結構,尋找同樣包含這個方法的對象並實現調用執行。可以用牽一動百來形容。所以Composite模式使用到Iterator模式,和Chain of
標籤:Implement int sqrt(int x).Compute and return the square root of x.解題思路一: public int mySqrt(int x) { return (int)Math.sqrt(x); } 神奇般的Accepted。解題思路二:參考平方根計算方法 計算平方根的演算法這裡給出最簡單的牛頓法,JAVA實現如下: public int mySqrt(int x) {
標籤:題目描述:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is.You may not alter the values in the nodes,
標籤:Given a string s consists of upper/lower-case alphabets and empty space characters ‘ ‘, return the length of last word in the string.If the last word does not exist, return 0.Note: A word is defined as a character sequence consists of non-space
標籤:Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at any point in