原创 【LeetCode】面試題43. 1~n整數中1出現的次數(JAVA)

原題地址:https://leetcode-cn.com/problems/1nzheng-shu-zhong-1chu-xian-de-ci-shu-lcof/ 題目描述: 解題方案: 參考了題解,自己雖然也能想出來但是思路很

原创 【LeetCode】二叉樹非遞歸遍歷(JAVA)

參考:史上最全遍歷二叉樹詳解 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode

原创 【LeetCode】面試題21. 調整數組順序使奇數位於偶數前面(JAVA)

原題地址:https://leetcode-cn.com/problems/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof/ 題目描述: 解題方

原创 【LeetCode】面試題51. 數組中的逆序對(JAVA)(非100%)

原題地址:https://leetcode-cn.com/problems/shu-zu-zhong-de-ni-xu-dui-lcof/ 題目描述: 在數組中的兩個數字,如果前面一個數字大於後面的數字,則這兩個數字組成一個逆序對

原创 【LeetCode】面試題55 - II. 平衡二叉樹(JAVA)

原題地址:https://leetcode-cn.com/problems/ping-heng-er-cha-shu-lcof/ 題目描述: 代碼: 遞歸: /** * Definition for a binary tree

原创 【LeetCode】92. 反轉鏈表 II(JAVA)

原題地址:https://leetcode-cn.com/problems/reverse-linked-list-ii/ 題目描述: 反轉從位置 m 到 n 的鏈表。請使用一趟掃描完成反轉。 說明: 1 ≤ m ≤ n ≤ 鏈表

原创 【LeetCode】面試題38. 字符串的排列(JAVA)

原題地址:https://leetcode-cn.com/problems/zi-fu-chuan-de-pai-lie-lcof/ 題目描述: 解題方案: 開始用的普通回溯,set去重,而且用的是StringBuilder,但

原创 【LeetCode】面試題29. 順時針打印矩陣(JAVA)

原題地址:https://leetcode-cn.com/problems/shun-shi-zhen-da-yin-ju-zhen-lcof/ 題目描述: 解題方案: 無論是遞歸還是迭代,本質都是上下左右分別設定一個邊界值,每

原创 【LeetCode】面試題68 - II. 二叉樹的最近公共祖先(JAVA)

原題地址:https://leetcode-cn.com/problems/er-cha-shu-de-zui-jin-gong-gong-zu-xian-lcof/ 題目描述: 給定一個二叉樹, 找到該樹中兩個指定節點的最近公共

原创 Java----類與接口

類 1. 基本概念 由類構造對象的過程成爲創建類的實例 對象:類的一個實例 實例域:對象中的數據 方法:操縱數據的過程 隱式參數:調用方法的對象在類的方法中使用了類的實例域,這個被調用的實例域就是隱式參數。 顯示參數:方法名括號

原创 【LeetCode】1. 兩數之和(JAVA)

原題地址:https://leetcode-cn.com/problems/two-sum/ 題目描述: 給定一個整數數組 nums 和一個目標值 target,請你在該數組中找出和爲目標值的那 兩個 整數,並返回他們的數組下標。

原创 【LeetCode】面試題42. 連續子數組的最大和(JAVA)

原題地址:https://leetcode-cn.com/problems/lian-xu-zi-shu-zu-de-zui-da-he-lcof/ 題目描述: 解題方案: 可以用動態規劃來解。dp[i]表示以i爲結尾的子數組的

原创 【LeetCode】面試題39. 數組中出現次數超過一半的數字(JAVA)

原題地址:https://leetcode-cn.com/problems/shu-zu-zhong-chu-xian-ci-shu-chao-guo-yi-ban-de-shu-zi-lcof/ 題目描述: 代碼: 參考:巧妙

原创 【LeetCode】面試題46. 把數字翻譯成字符串(JAVA)

原題地址:https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/ 題目描述: 解題方案: 參考:題解 大佬寫的代碼真的很簡潔 代碼: c

原创 【LeetCode】面試題25. 合併兩個排序的鏈表(JAVA)

原題地址:https://leetcode-cn.com/problems/he-bing-liang-ge-pai-xu-de-lian-biao-lcof/ 題目描述: 解題方案: 設定虛頭節點,將兩個鏈表中較小值依次接在後