原创 LintCode | 408. 二進制求和

給定兩個二進制字符串,返回他們的和(用二進制表示)。 比較蠢的辦法 public class Solution { public String addBinary(String a, String b) {

原创 LintCode | 66. 二叉樹的前序遍歷

給出一棵二叉樹,返回其節點值的前序遍歷。 題目鏈接 /** * Definition of TreeNode: * public class TreeNode { * public int val; *

原创 LeetCode | 412. Fizz Buzz

Write a program that outputs the string representation of numbers from 1 to n. But for multiples of three it s

原创 LintCode | 569. Add Digits

Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. 樣例 Given

原创 LintCode | 167. 鏈表求和

你有兩個用鏈表代表的整數,其中每個節點包含一個數字。數字存儲按照在原來整數中相反的順序,使得第一個數字位於鏈表的開頭。寫出一個函數將兩個整數相加,用鏈表形式返回和。 /** * Definition for singly-l

原创 LeetCode | 485. Max Consecutive Ones

Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1,1,0,1,1,1]

原创 LeetCode | 492. Construct the Rectangle

For a web developer, it is very important to know how to design a web page’s size. So, given a specific rectangula

原创 LeetCode | 463. Island Perimeter

You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid

原创 LeetCode | 530. Minimum Absolute Difference in BST

Given a binary search tree with non-negative values, find the minimum absolute difference between values of any tw

原创 LeetCode | 496. Next Greater Element I

You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all

原创 LintCode | 111. 爬樓梯

假設你正在爬樓梯,需要n步你才能到達頂部。但每次你只能爬一步或者兩步,你能有多少種不同的方法爬到樓頂部? 題目鏈接 DP基礎題,不多說了。取模可以減少空間浪費。 public class Solution { /**

原创 LeetCode | 506. Relative Ranks

Given scores of N athletes, find their relative ranks and the people with the top three highest scores, who will b

原创 LeetCode | 520. Detect Capital

Given a word, you need to judge whether the usage of capitals in it is right or not. We define the usage of capita

原创 LintCode | 69. 二叉樹的層次遍歷

給出一棵二叉樹,返回其節點值的層次遍歷(逐層從左往右訪問) /** * Definition of TreeNode: * public class TreeNode { * public int val;

原创 LintCode | 376. 二叉樹的路徑和

給定一個二叉樹,找出所有路徑中各節點相加總和等於給定 目標值 的路徑。 一個有效的路徑,指的是從根節點到葉節點的路徑。 題目不難,關鍵在於想清楚遞歸怎麼判斷。 /** * Definition of TreeNode