原创 Java 整數溢出

int 類型在 Java 中是“有符號”的。所謂“有符號”就是有正負。 在計算機中用二進制表示所有的信息,這個符號的區別就看首位。 首位如果是 0,就是正的,1 就是負的。正與負的區別也因此就在於取反加一。這不僅在 Java,

原创 **LeetCode 70. Climbing Stairs

70.Climbing Stairs 題意: You are climbing a stair case. It takes n steps to reach to the top. Each time you can ei

原创 Java 產生隨機數的三種方式

Java產生隨機數的三種方式 在Java中,隨機數的概念從廣義上講,有三種。 1、通過System.currentTimeMillis()來獲取一個當前時間毫秒數的long型數字。 2、通過Math.rando

原创 LeetCode121. Best Time to Buy and Sell Stock

121.Best Time to Buy and Sell Stock Say you have an array for which the ith element is the price of a given stock

原创 Java 中的 this 和 super

this( ) 函數: this是自身的一個對象,代表對象本身,可以理解爲:指向對象本身的一個指針。 this的用法在java中大體可以分爲3種: 1.普通的直接引用 這種就不用講了,this相當於是指向當前對象本身。 2.形參

原创 對Java方法參數按值傳遞的理解

轉載於:http://blog.csdn.net/mr_wenjian/article/details/58696564 今天看到(Java核心計數)Java方法對參數按值傳遞的時候,居然怎麼都想不通,故而自己寫代碼嘗試了理解了一下:

原创 LeetCode119. Pascal's Triangle II

119.Pascal’s Triangle II Given an index k, return the kth row of the Pascal’s triangle. For example, given k = 3,

原创 LeetCode112. Path Sum

112.Path Sum 使用遞歸的方法,要注意題意只要有一個葉子節點符合要求就返回 true,所以return 語句回一個或語句. public boolean hasPathSum(TreeNode root, int

原创 LeetCode108. Convert Sorted Array to Binary Search Tree

108.Convert Sorted Array to Binary Search Tree Given an array where elements are sorted in ascending order, conve

原创 LeetCode101. Symmetric Tree

101.Symmetric Tree Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center)

原创 LeetCode111. Minimum Depth of Binary Tree

111.Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the number of

原创 LeetCode83. Remove Duplicates from Sorted List

83.Remove Duplicates from Sorted List 題意: 給一個已排序的鏈表,刪除重複的元素,使得所有元素只出現一次。 Given a sorted linked list, delete all du

原创 LeetCode 88. Merge Sorted Array

88.Merge Sorted Array Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.

原创 LeetCode118. Pascal's Triangle

118.Pascal’s Triangle 帕斯卡爾三角形也就是楊輝三角形 發現規律: * 每一行中數的個數與行號相等; * 每一行中除了第一個和最後一個元素,其他元素是上一行中相鄰兩個元素之和; 由這兩個規律可以

原创 Java 集合

上圖是java 集合框架的接口繼承圖,集合中有兩個基本接口:Collection 和 Map。Collection 實現了 Iterable 接口,所以所有實現了 Iterable 接口的類都能使用 Iterator 迭代器。