Closed frankegoesdown closed 3 years ago
:exclamation: No coverage uploaded for pull request base (
master@65d2fd6
). Click here to learn what that means. The diff coverage isn/a
.
@@ Coverage Diff @@
## master #95 +/- ##
=========================================
Coverage ? 71.60%
=========================================
Files ? 578
Lines ? 10395
Branches ? 0
=========================================
Hits ? 7443
Misses ? 2671
Partials ? 281
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update 65d2fd6...74ef066. Read the comment docs.
Thank you for your solution. I optimized your solution again. Like your solution, the solution idea is greed. The time complexity of our solution is the same, both are O(n), and optimization is only constant-level optimization. My solution beats 100%. This is my new code:
func getSmallestString(n int, k int) string {
str, i, j := make([]byte, n), 0, 0
for i = n - 1; i <= k-26; i, k = i-1, k-26 {
str[i] = 'z'
}
if i >= 0 {
str[i] = byte('a' + k - 1 - i)
for ; j < i; j++ {
str[j] = 'a'
}
}
return string(str)
}
Looks great and clean
This solution time complexity is the same with you. Only reduced the number of loops.
And my solution example:
as you can see it shows more perfomance