美文网首页
504. Base 7

504. Base 7

作者: matrxyz | 来源:发表于2018-01-14 07:48 被阅读0次

Given an integer, return its base 7 string representation.

Example 1:
Input: 100
Output: "202"
Example 2:
Input: -7
Output: "-10"

Note: The input will be in range of [-1e7, 1e7].

Solution:

思路:
Time Complexity: O(N) Space Complexity: O(N)

Solution Code:

class Solution {
    public String convertTo7(int num) {
    if (num < 0) {
        return '-' + convertTo7(-num);
    }
    if (num < 7) {
        return num + "";
    }
    return convertTo7(num / 7) + num % 7;
}
}

相关文章

  • 504. Base 7

    求一个数的7进制表示。这题跟Excel Sheet有点像。这类题可以用递归。 我的代码: 别人的代码: 用了递归

  • 504. Base 7

    Given an integer, return its base 7 string representation...

  • [LeetCode]504. Base 7

    题目 Given an integer, return its base 7 string representat...

  • [LeetCode By Go 56]504. Base 7

    题目 Given an integer, return its base 7 string representat...

  • Base64编码简单总结

    1 Base64编码原理 随着iOS7正式版推出,Apple增加了使用Base64编解码的支持。Base64编码之...

  • 504.正名

    两人同时落难,一个是将陪伴我的人,一个是给予我生命的人,我只能救一个,而我的想法是备受争议的,两个都救,既然反正他...

  • 504.香樟

    昨天电站进行树木修枝,有两棵香樟树,吃饭的时候,老师傅告诉我,有香樟的枝条,拿来可以放在家里驱蚊虫,昨天就去拖了一...

  • base64

    s =b'i\xb7\x1d\xfb\xef\xff=='"""标准base64"""s_en = base64....

  • 攻防世界-Crypto-告诉你个秘密

    题目信息 得到两串base64 解密base64,得到7段字符,疑似键盘围绕加密 解密得到:TONGYUAN(必须...

  • menuconfig之编译选项2

    7>. Boot options (0x0) Compressed ROM boot loader base ...

网友评论

      本文标题:504. Base 7

      本文链接:https://www.haomeiwen.com/subject/jnzhoxtx.html