
Math
WX_ming
写代码就像写作文一样,思路要明确,方法要对,否则又臭又长还出错
展开
-
LeetCode 319. Bulb Switcher C++
319. Bulb SwitcherThere are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it’s...原创 2018-08-15 16:13:32 · 218 阅读 · 0 评论 -
[WXM] LeetCode Minimum Moves to Equal Array Elements II C++
Minimum Moves to Equal Array Elements IIGiven a non-empty integer array, find the minimum number of moves required to make all array elements equal, where a move is incrementing a selected element b...原创 2018-09-04 23:08:08 · 176 阅读 · 0 评论 -
[WXM] LeetCode 413. Arithmetic Slices C++
413. Arithmetic SlicesA sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.For example, these ...原创 2018-08-27 11:11:12 · 188 阅读 · 0 评论 -
LeetCode 829. Consecutive Numbers Sum C++
829. Consecutive Numbers SumGiven a positive integer N, how many ways can we write it as a sum of consecutive positive integers?Example 1:Input: 5Output: 2Explanation: 5 = 5 = 2 + 3Example...原创 2018-08-17 15:16:52 · 356 阅读 · 0 评论 -
LeetCode 775. Global and Local Inversions C++
775. Global and Local InversionsWe have some permutation A of [0, 1, …, N - 1], where N is the length of A.The number of (global) inversions is the number of i < j with 0 <= i < j < N ...原创 2018-08-17 09:36:57 · 236 阅读 · 0 评论 -
LeetCode 357. Count Numbers with Unique Digits C++
357. Count Numbers with Unique DigitsGiven a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n.Example:Input: 2Output: 91 Explanation: The answer should b...原创 2018-08-22 17:01:06 · 147 阅读 · 0 评论 -
[WXM] LeetCode 714. Best Time to Buy and Sell Stock with Transaction Fee C++
714. Best Time to Buy and Sell Stock with Transaction FeeYour are given an array of integers prices, for which the i-th element is the price of a given stock on day i; and a non-negative integer fee...原创 2018-08-26 10:32:19 · 202 阅读 · 0 评论 -
LeetCode 754. Reach a Number C++
754. Reach a NumberYou are standing at position 0 on an infinite number line. There is a goal at position target.On each move, you can either go left or right. During the n-th move (starting from ...原创 2018-08-16 16:32:28 · 392 阅读 · 0 评论 -
LeetCode 640. Solve the Equation C++
640. Solve the EquationSolve a given equation and return the value of x in the form of string “x=#value”. The equation contains only ‘+’, ‘-’ operation, the variable x and its coefficient.If there...原创 2018-08-16 15:15:51 · 474 阅读 · 0 评论 -
LeetCode 396. Rotate Function C++
396. Rotate FunctionGiven an array of integers A and let n to be its length.Assume Bk to be an array obtained by rotating the array A k positions clock-wise, we define a “rotation function” F on A...原创 2018-08-16 09:19:31 · 200 阅读 · 0 评论 -
LeetCode 453. Minimum Moves to Equal Array Elements C++
453. Minimum Moves to Equal Array ElementsGiven 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 el...原创 2018-08-13 15:34:17 · 146 阅读 · 0 评论 -
LeetCode 326. Power of Three 231. Power of Two 342. Power of Four C++
Approach这三道题题目大意基本是一样的,就是判断某个数n是不是该数的幂次方m^p,这里我用数学技巧解决这道题,我们用对数logm(n)来处理,只要它是m的幂次方,那么结果必然是整数,我们只要判断结果是不是整数就可以解决,因为math头文件只包含log10或者log少量对数底,所以我们用数学的换底公式logm(n)=log10(n)/log10(m),然后C++判断是否为整数的,我们将其...原创 2018-08-13 11:38:05 · 189 阅读 · 0 评论 -
LeetCode 365. Water and Jug Problem C++
365. Water and Jug ProblemYou are given two jugs with capacities x and y litres. There is an infinite amount of water supply available. You need to determine whether it is possible to measure exactl...原创 2018-08-15 17:39:43 · 274 阅读 · 0 评论