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 the total number of full staircase rows that can be formed. n is a non-negative integer and fits within the range of…
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.   Since 2 has only one digit, return it. Follow up:Could you do…
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 the total number of full staircase rows that can be formed. n is a non-negative integer and fits within the range of…
Problem: 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 the total number of full staircase rows that can be formed. n is a non-negative integer and fits within the…
Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: "202" Example 2: Input: -7 Output: "-10" Note: The input will be in range of [-1e7, 1e7]. 不停除以7, 然后把余数放到ans里面, 最后reverse ans加上符号即可. Code class Sol…
You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the winner. You will take the first turn to remove th…
There are 1000 buckets, one and only one of them contains poison, the rest are filled with water. They all look the same. If a pig drinks that poison it will die within 15 minutes. What is the minimum amount of pigs you need to figure out which bucke…
problem 441. Arranging Coins solution1: class Solution { public: int arrangeCoins(int n) { ; ; while(sum<=n) { curLevel += ; sum += curLevel; } ); } }; solution2: class Solution { public: int arrangeCoins(int n) { *()-)*0.5);//数学求和公式求解x,注意参数类型是否越界. }…
一.204. Count Primes Count the number of prime numbers less than a non-negative number, n. Input: 10 Output: 4 Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7. 1.数学原理:两个质数的乘积一定是合数.一个质数乘以任何数的积都一定不是质数.(除了1) 2.代码:需要注意的点:for (int…
Given a 2D board containing 'X' and 'O' (the letter O), capture all regions surrounded by 'X'. A region is captured by flipping all 'O's into 'X's in that surrounded region. Example: X X X X X O O X X X O X X O X X After running your function, the bo…