数学
_xiaoyuer
世界一定有光
展开
-
LeetCode - 50/69/367/633 - Pow(x, n)、Sqrt(x)
50. Pow(x, n)Implement pow(x, n).简单粗暴的题目解释【笑哭】用了快速幂,不过wa了一下,因为没考虑到int的最小值转化为正数后会爆掉。时间复杂度O(logn),空间复杂度O(1)class Solution {public: double myPow(double x, int n) { if (n == 0) re原创 2017-07-18 09:52:13 · 233 阅读 · 0 评论 -
LeetCode - 204 - Count Primes
Description:Count the number of prime numbers less than a non-negative number, n.素数筛法。居然还没有忘掉,难得啊。class Solution {public: int countPrimes(int n) { vector prime; vector v原创 2017-07-26 18:37:56 · 138 阅读 · 0 评论 -
LeetCode - 152 - Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4],the contiguous subarray [2,3] has the largest原创 2017-07-26 16:01:44 · 170 阅读 · 0 评论 -
LeetCode - 371 - Sum of Two Integers
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example:Given a = 1 and b = 2, return 3.不用+-法计算两数的和我们用 & 可以得到二进制位上哪些位置需要进位carry因为相加进位后该位置为0原创 2017-08-10 15:28:58 · 149 阅读 · 0 评论 -
LeetCode - 628 - Maximum Product of Three Numbers
Given an integer array, find three numbers whose product is maximum and output the maximum product.Example 1:Input: [1,2,3]Output: 6Example 2:Input: [1,2,3,4]Output: 24原创 2017-07-25 21:48:04 · 170 阅读 · 0 评论 -
LeetCode - 172 - Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.问有多少个0,其实就是问有多少个2*5,而5的个数必定少于2的个数,所以就是求n!中有多少个5。用n / 5,可求出n中有多少数可以原创 2017-07-25 21:31:57 · 204 阅读 · 0 评论 -
LeetCode - 343 - Integer Break
Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.For example, given n = 2, ret原创 2017-08-02 15:41:17 · 239 阅读 · 0 评论 -
LeetCode - 334 - Increasing Triplet Subsequence
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.Formally the function should:Return true if there exists i, j, k such that arr[i] ar原创 2017-08-02 15:41:03 · 129 阅读 · 0 评论 -
LeetCode - 217/219/220 - Contains Duplicate
217. Contains DuplicateGiven an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should ret原创 2017-07-31 20:08:06 · 197 阅读 · 0 评论 -
LeetCode - 258 - Add Digits
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has on原创 2017-07-31 20:07:55 · 170 阅读 · 0 评论 -
LeetCode - 453/462 - Minimum Moves to Equal Array Elements
Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements equal, where a move is incrementing n - 1 elements by 1.Example:Input:[1,2,3]Ou原创 2017-07-31 14:30:59 · 163 阅读 · 0 评论 -
LeetCode - 118/119 - Pascal's Triangle
118. Pascal's TriangleGiven numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]原创 2017-07-31 14:30:38 · 150 阅读 · 0 评论 -
LeetCode - 168/171 - Excel Sheet Column Title/Number
168. Excel Sheet Column TitleGiven a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z原创 2017-07-21 15:19:11 · 272 阅读 · 0 评论 -
LeetCode - 231/326/342 - Power of Two/Three/Four
231. Power of TwoGiven an integer, write a function to determine if it is a power of two.判断一个数是不是2的幂。我写的是不断地除以2除以2除以2,很一般的思路。看评论区有一个很巧的做法,感觉超优雅!是2的幂就表明这个数的二进制只能有一个1,那样(n & (n - 1))就应该为0。凡是不为原创 2017-07-18 09:52:36 · 207 阅读 · 0 评论 -
LeetCode - 268 - Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.Note:Your algorithm shoul原创 2017-07-28 14:36:47 · 200 阅读 · 0 评论