Ruizhi Ma's Blog

Keep Calm and Carry On

Problem 70

Climbing Stairs

问题描述 You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Note: Given n will be a ...

Problem 101

Symmetric Tree

问题描述 Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). (树状图画不出来,右转看原题:https://leetcode.com/problems/symmetric-tree/) Note: Bonus points if you could s...

Problem 66

Plus One

问题描述 Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The digits are stored such that the most significant digit is at the head of the list, and each...

Problem 258

Add Digits

问题描述 Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. Example: Input: 38 Output: 2 Explanation: The process is like: 3 + 8 = 11, 1 + 1 = 2. ...

Problem 167

Two Sum II - Input array is sorted

问题描述 Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two ...

递归

汉诺塔问题

解决思路 所有不管多少个盘子,都可以看成两个盘子,即最后一个盘子,和其他所有盘子,然后都可以拆解为三步: 将最后一个盘子上面的所有盘子,借助目标柱移动到中间柱子上 将最后一个盘子移动到目标柱上 将中间柱上所有盘子,借助初始柱,移动到最后一个柱子上 TestHanoi类 package demo3; public class TestHanoi { /* * n...

递归

斐波那契数列问题

TestFeobnacci类 package demo3; public class TestFebonacci { //斐波那契数列: 1 1 2 3 5 8 13 ... public static int febonacci(int i){ //出口条件 if(i == 1 || i == 2){ return 1; }else{ ...

Problem 125

Valid Palindrome

问题描述 Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. Note: For the purpose of this problem, we define empty string as valid palindrome...

Problem 387

First Unique Character in a String

问题描述 Given a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1. Examples: s = “leetcode” return 0. s = “loveleetcode”, return 2. Note: Yo...

Problem 28

Implement strStr()

问题描述 Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Example 1: Input: haystack = “hello”, needle = “ll” Output: 2 Ex...