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].

class Solution(object):
def convertToBase7(self, num):
"""
:type num: int
:rtype: str
"""
ans=""
if num<0:
neg=True
else:
neg=False
num=abs(num)
while num>=7:
ans+=str(num%7)
num=num//7
ans+=str(num)
if neg:
ans='-'+ans[::-1]
return ans
return ans[::-1]

  

最新文章

  1. 【CodeVS2800】 送外卖 最短路+状压DP
  2. jquery ui 常用(一)(自动完成 | 标签页 | 折叠面板 | 带图标的按钮 | 日期选择器| )
  3. 服饰行业淘宝商城店铺首页设计报告-转载自http://bbs.paidai.com/topic/88363
  4. GSS4 2713. Can you answer these queries IV 线段树
  5. SpringMVC最基础配置
  6. Light OJ Dynamic Programming
  7. $.ajax()详解
  8. 前端 IoC 理念入门
  9. Leetcode_234_Palindrome Linked List
  10. C#多态及接口
  11. 在docker中运行mariadb程序
  12. springmvc文件上传示例
  13. kubernetes中filebeat以sidecar方式和应用一起部署,并且传入环境变量
  14. MVC所有的ActionResult
  15. MySQL Binlog 解析工具 Maxwell 详解
  16. ThreadPoolExecutor 使用说明
  17. Lua脚本语言快速入门手册
  18. Sublime Text3编辑器简介
  19. iOS开发之UITableViewController重写
  20. LinuxShell脚本基础 6-case...esac的使用和通配符

热门文章

  1. Java类的加载时机
  2. js运行机制详解:event loop
  3. nodejs web API 相关杂项
  4. CentOs系统设置python版本
  5. kibana升级之后原本保存的数据dashboards, visualizations, index patterns丢失
  6. ES6 新加的类型Symbol()
  7. React文档(十二)组合vs继承
  8. 全面了解TCP/IP到HTTP
  9. mac 配置php+php_fpm+nginx
  10. canvas绘图基础