上次跟大家提到重訓的吃,接下來就是開始動,問題是怎麼動呢? 其實我一開始也不知道,所以這份課表叫十里坡,在不斷努力後,還是練成了劍神。
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 |
26. Remove Duplicates from Sorted Array
Given a sorted array nums, remove the duplicates in-place such that each element appears only once and returns the new length.
Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.
Clarification:
Confused why the returned value is an integer but your answer is an array?
Note that the input array is passed in by reference, which means a modification to the input array will be known to the caller as well.
Internally you can think of this:
// nums is passed in by reference. (i.e., without making a copy)
int len = removeDuplicates(nums);
// any modification to nums in your function would be known by the caller.
// using the length returned by your function, it prints the first len elements.
for (int i = 0; i < len; i++) {
print(nums[i]);
}
Example 1:
1 | Input: nums = [1,1,2] |
Example 2:
1 | Input: nums = [0,0,1,1,1,2,2,3,3,4] |
Constraints:
1 | 0 <= nums.length <= 3 * 104 |