標籤: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
標籤:Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].解題思路:JAVA實現如下: public void rotate(int[] nums, int k) { k%=nums.length; k=nums.length-
標籤: final 通常是指“無法改變的事”。下面就介紹final在類,方法,變數中的用法。 1.final可以修飾類,該類不能被繼承。 2.final可以修飾方法,該方法不能被重寫。 class Fu { public final void show() { } }class Zi extends Fu { // Zi中的show()無法覆蓋Fu中的show() public void show() {
標籤: Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples: ["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -> 9 [
標籤:java socket報文通訊(一) socket的建立今天來和大家分享一下java中如何使用socket進行通訊。先來囉嗦兩句,看看Tcp/ip和udp:TCP是 Transfer Control Protocol 的 簡稱,是一種連線導向的保證可靠傳輸的協議。通過TCP協議傳輸,得到的是一個順序的無差錯的資料流。發送方和接收方的成對的兩個socket之間必須建 立串連,以便在TCP協議的基礎上進行通訊,當一個socket(通常都是server