原创 Reverse Integer

Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 要求:不使用額外的內存空間。反轉之後考慮越界問題。

原创 Valid Palindrome

題目:判斷字符串是否是迴文字符串,只考慮字符串中的數字和字符,不考慮標點符號 例如:"A man, a plan, a canal: Panama"是迴文字符串"race a car" 不是迴文字符串 方法1:使用額外的內存空間    注

原创 用兩個棧實現隊列

題目1:用兩個棧來實現一個隊列,完成隊列的Push和Pop操作。 隊列中的元素爲int類型。 import java.util.Stack; public class Solution { Stack<Integer> stac

原创 重建二叉樹

題目:輸入某二叉樹的前序遍歷和中序遍歷的結果,請重建出該二叉樹。假設輸入的前序遍歷和中序遍歷的結果中都不含重複的數字。 例如:輸入前序遍歷序列{1,2,4,7,3,5,6,8}和中序遍歷序列{4,7,2,1,5,3,8,6},則重建二叉

原创 java 位操作符

位運算的應用場景: 因爲位運算的運算效率比直接對數字進行加減乘除高很多,所以當出現以下情景且對運算效率要求較高時,可以考慮使用位運算。 情況1: 題目描述 輸入一個int型的正整數,計算出該int型數據在內存中存儲時1的個數。例如輸

原创 字符串替換

題目:請實現一個函數,將一個字符串中的空格替換成“%20”。 例如:當字符串爲We Are Happy.則經過替換之後的字符串爲We%20Are%20Happy。 思路: 問題1:替換字符串,是在原來的字符串上做替換,還是新開闢一個字符串

原创 Binary Tree Level Order Traversal I和II 層次遍歷二叉樹

Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).

原创 java.lang.reflect.UndeclaredThrowableException原因和解決方法

在 Spring AOP中調用一個方法來進行數據驗證 一旦數據驗證失敗,拋出一個自定義的異常。然而,卻拋出了java.lang.reflect.UndeclaredThrowableException 查了一下,因爲我的自定義異常繼承

原创 Minimum Depth of Binary Tree

Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from th

原创 Path Sum

Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along

原创 Balanced Binary Tree

Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined a

原创 Maximum Depth of Binary Tree

Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the

原创 Add Two Numbers

You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each

原创 求兩個數的最小公倍數

兩個數的最下公倍數 = 兩個數的乘積 / 兩個數的最大公約數 import java.util.*; public class Main{ public static void main(String[] args){

原创 Symmetric Tree

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this bina