重訓的十里坡
326. Power of Three
Given an integer n, return true if it is a power of three. Otherwise, return false.
An integer n is a power of three, if there exists an integer x such that n == 3x.
Example 1:
1 | Input: n = 27 |
Example 2:
1 | Input: n = 0 |
Example 3:
1 | Input: n = 9 |
Example 4:
1 | Input: n = 45 |
66. Plus One
Given a non-empty array of decimal digits representing a non-negative integer, increment one to the integer.
The digits are stored such that the most significant digit is at the head of the list, and each element in the array contains a single digit.
You may assume the integer does not contain any leading zero, except the number 0 itself.
Example 1:
1 | Input: digits = [1,2,3] |
Example 2:
1 | Input: digits = [4,3,2,1] |
Example 3:
1 | Input: digits = [0] |
38. Count and Say
The count-and-say sequence is a sequence of digit strings defined by the recursive formula:
countAndSay(1) = “1”
countAndSay(n) is the way you would “say” the digit string from countAndSay(n-1), which is then converted into a different digit string.
To determine how you “say” a digit string, split it into the minimal number of groups so that each group is a contiguous section all of the same character. Then for each group, say the number of characters, then say the character. To convert the saying into a digit string, replace the counts with a number and concatenate every saying.
Given a positive integer n, return the nth term of the count-and-say sequence.
Example 1:
1 | Input: n = 1 |
Example 2:
1 | Input: n = 4 |