
LeetCode-Math
R_zz
这个作者很懒,什么都没留下…
展开
-
LeetCode-231. Power of Two
问题:https://leetcode.com/problems/power-of-two/?tab=Description Given an integer, write a function to determine if it is a power of two. 给定一个数,判断它是不是2的幂数。 分析:二进制来说,2的幂数都是首位是1,其他位是0。所以用n&(n-1)是否为0可以判断原创 2017-02-21 10:28:06 · 273 阅读 · 0 评论 -
LeetCode-69. Sqrt(x)
问题:https://leetcode.com/problems/sqrtx/ Implement int sqrt(int x).Compute and return the square root of x. 计算x的平方根。 分析:二分法计算。不是整数的取整数部分。 C++代码:class Solution {public: int mySqrt(int x) {原创 2017-02-22 20:05:34 · 234 阅读 · 0 评论 -
LeetCode-258. Add Digits
问题:https://leetcode.com/problems/add-digits/?tab=Description Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. 给定一个非负的整数,求它各位和,直到出现最终个位数,返回这个个位数。也就是原创 2017-02-22 16:34:34 · 190 阅读 · 0 评论 -
LeetCode-168. Excel Sheet Column Title
问题:https://leetcode.com/problems/excel-sheet-column-title/?tab=Description Given a positive integer, return its corresponding column title as appear in an Excel sheet. For example: 1 -> A 2原创 2017-02-22 16:22:32 · 285 阅读 · 0 评论 -
LeetCode-171. Excel Sheet Column Number
问题:https://leetcode.com/problems/excel-sheet-column-number/?tab=Description Related to question Excel Sheet Column Title。 Given a column title as appear in an Excel sheet, return its corresponding co原创 2017-02-22 16:01:01 · 225 阅读 · 0 评论 -
LeetCode-172. Factorial Trailing Zeroes
问题:https://leetcode.com/problems/factorial-trailing-zeroes/?tab=Description Given an integer n, return the number of trailing zeroes in n!. 给定一个整数n,返回n!的末尾0的个数,要求对数阶时间复杂度。 分析:产生0是因为2*5才有,而n!中2的个数永远比原创 2017-02-22 15:47:42 · 142 阅读 · 0 评论 -
LeetCode-7. Reverse Integer
问题:https://leetcode.com/problems/reverse-integer/?tab=Description Reverse digits of an integer.Example1: x = 123, return 321 Example2: x = -123, return -321 给定一个整数,求它逆序后的数。如果逆序后的数越界了,返回0. 分析:用y原创 2017-02-22 15:32:53 · 150 阅读 · 0 评论 -
LeetCode-268. Missing Number
问题:https://leetcode.com/problems/missing-number/?tab=Description Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array. 给一个有序的序列,找出缺少的数。原创 2017-02-22 15:01:04 · 153 阅读 · 0 评论 -
LeetCode-326. Power of Three
问题:https://leetcode.com/problems/power-of-three/?tab=Description Given an integer, write a function to determine if it is a power of three. 给定一个整数,判断它是不是3的幂数。 分析:不能用递归和循环。任何一个3的i次方一定能被最大的3的i次方整除。 C原创 2017-02-22 11:37:52 · 164 阅读 · 0 评论 -
LeetCode-367. Valid Perfect Square
问题:https://leetcode.com/problems/valid-perfect-square/?tab=Description Given a positive integer num, write a function which returns True if num is a perfect square else False. 给定一个正数,如果它是某一个数的平方则返回tr原创 2017-02-22 11:19:39 · 277 阅读 · 0 评论 -
LeetCode-400. Nth Digit
问题:https://leetcode.com/problems/nth-digit/?tab=Description Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, **分析:**S1=1 S2=12 S3=123 S4=1234 … S9=123456789原创 2017-02-22 11:03:04 · 546 阅读 · 0 评论 -
LeetCode-415. Add Strings
问题:https://leetcode.com/problems/add-strings/?tab=Description Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2.给定两个字符串形式的正整数num1和num2,计算num1和num2之和。原创 2017-02-22 10:36:13 · 224 阅读 · 0 评论 -
LeetCode-13. Roman to Integer
问题:https://leetcode.com/problems/roman-to-integer/?tab=Description Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 给一个罗马数字,把它转为整数。输入的数是1到39原创 2017-02-22 09:33:56 · 164 阅读 · 0 评论 -
LeetCode-441. Arranging Coins
问题:https://leetcode.com/problems/arranging-coins/?tab=Description You have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins.Given n, find t原创 2017-02-21 16:07:14 · 180 阅读 · 0 评论 -
LeetCode-9. Palindrome Number
问题:https://leetcode.com/problems/palindrome-number/?tab=Description Determine whether an integer is a palindrome. Do this without extra space. 判断一个整数是否是回文数。不能增加额外的空间。 分析: 因为不能增加额外的空间,所以每次比较头的数和末尾的数原创 2017-02-21 15:51:00 · 230 阅读 · 0 评论 -
LeetCode-453. Minimum Moves to Equal Array Elements
问题: https://leetcode.com/problems/minimum-moves-to-equal-array-elements/?tab=Description Given a non-empty integer array of size n, find the minimum number of moves required to make all array element原创 2017-02-21 15:21:10 · 258 阅读 · 0 评论 -
LeetCode-263. Ugly Number
问题:https://leetcode.com/problems/ugly-number/?tab=Description Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3,原创 2017-02-21 11:22:42 · 229 阅读 · 0 评论 -
LeetCode-67. Add Binary
问题:https://leetcode.com/problems/add-binary/?tab=Description Given two binary strings, return their sum (also a binary string). For example,a = “11”b = “1” Return “100”. 给两个二进制数,返回它们的和,仍然用二进制表示。原创 2017-02-22 20:48:54 · 135 阅读 · 0 评论