1663. The smallest string with a given value
Thought:
今天的One question daily读题可以得知:Actually I want to ask for:
27 How to disassemble 3 Number 1 + 1 + 25
73 How to disassemble 5 Number 1 + 1 + 19 + 26 + 26
nIs the number of string we are going to return,So we put itaAs1,Createnindivual1list of[1]*n
贪心Thought
First time:从第一Number开始加,Add to26。Determine whether it is with each timekequal,Timeout。
Second attempt:Turn all the numbers passed directly into26,Turn all the numbers passed directly into26,kEvery time-25,最后将Remaining数字Add to我们遍历到的位置
,Last+Remainingk。
The optimal solution is not usedlambdaThe function converts the number into a string,Instead‘a’Become up to become‘z’。Save a lot of time。
Code:
1 | class Solution: |
1 | class Solution: |
1 | class Solution: |