base7 Posted on 2018-04-25 Edited on 2021-06-17 Base 7 – LeetCode 504ProblemDescriptionGiven an integer, return its base 7 string representation. AnswerOriginalCode123456789101112class Solution {public: string convertToBase7(int num) { string s; int tmp = abs(num); do { s = (static_cast<char>('0' + tmp % 7)) + s; tmp /= 7; } while(tmp > 0); return (num < 0 ? '-' + s : s); }}; 思路最简单的常规进制转换。时间复杂度$O(log_{7}n)$,空间复杂度$O(1)$。耗时$7$ ms,排名$20.73\%$ Better思路还没看到更好的思路。