標籤:Scanner 類封裝了輸入資料流對象,並使用nextLine()方法輸入資料流中擷取使用者輸入的整行文本字元package hahaa;import java.util.Scanner;public class ha {public static void main (String[] args) {Scanner scanner =new Scanner(System.in);System.out.println("請輸入你的想輸入的數字");String line =
標籤: 1題string str1=”1″+”2″+”3″+….+”1000″; 1式string str2;for(int i = 1; i <=1000 ;i++)str2+=i; 2式stringbuffer str3 = new stringbuffer();for(int i = 1; i <=1000 ;i++)str3 = str3.append(i)
標籤:The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially positioned in the top-left room and must fight
標籤:Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result may be very large, so you need to return a string instead of an
標籤:Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most k transactions.解題思路:本題是Best Time to Buy and Sell Stock系列最難的一道,需要用到dp,JAVA實現如下:
標籤: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-