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