标签归档:leetcode

RSS feed of leetcode

[LeetCode]Integer to English Words

题目描述:

Convert a non-negative integer to its english words representation. Given input is guaranteed to be less than 2 ^ 31 - 1.

For example,

123 -> "One Hundred Twenty Three"
12345 -> "Twelve Thousand Three Hundred Forty Five"
1234567 ...

继续阅读

[LeetCode]Sqrt(x)

题目描述:

Implement int sqrt(int x).

Compute and return the square root of x.

题目大意:

实现函数 int sqrt(int x).

计算并返回x的平方根(整型)

解题思路:

题目并不要求计算sqrt(x)的精确值,只需返回小于等于sqrt(x)的最大整数即可。

方法I:二分法

Python代码:

class Solution(object):
    def mySqrt(self, x):
        """
        :type x: int
        :rtype: int
        """
        low, high, mid ...

继续阅读

[LeetCode]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?

题目大意:

你正在爬楼梯。爬到顶部需要n步。

每一次你爬1步或者2步。爬到顶部有多少种不同的方式? ...

继续阅读