標籤:一、建立類:Test.java//定義類public class Test{ //屬性 String name; String gender; int age; //方法,無參無返回 public void eat(){ System.out.println("我在吃飯。"); }}二、使用類:如果類與使用類的檔案在同一目錄,則不需要引入檔案Test1.java//使用類public class Test1{
標籤:一、while迴圈執行個體:public class Test{ public static void main(String[] args){ int i = 1; while(i<30){ System.out.println(i); i++; } }}二、do-while迴圈public class Test{ public static void
標籤:Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.解題思路:注意minimum depth最後遍曆的那個點,left right都必須為null,JAVA實現如下: public int
標籤:Given a binary tree and a sum, find all root-to-leaf paths where each path‘s sum equals the given sum.For example:Given the below binary tree and sum = 22, 5 / 4 8 / / 11 13 4
標籤:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.解題思路:同上題,JAVA實現如下: public TreeNode sortedListToBST(ListNode head) { ArrayList<Integer> list=new ArrayList<Integer>()
標籤:Construct Binary Tree from Inorder and Postorder TraversalTotal Accepted: 31041 Total Submissions: 115870 Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in
標籤:資料輸入首先需要匯入掃描器然後聲明掃描器輸出輸入提示接收使用者資料的資料輸出使用者資料的資料執行個體:import java.util.Scanner; //匯入掃描器public class Test{ public static void main(String[] args){ Scanner in = new Scanner(System.in); //聲明掃描器,賦值掃描器給in