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]

  

[LeetCode&Python] Problem 504. Base 7的更多相关文章

  1. [LeetCode&Python] Problem 108. Convert Sorted Array to Binary Search Tree

    Given an array where elements are sorted in ascending order, convert it to a height balanced BST. Fo ...

  2. [LeetCode&Python] Problem 387. First Unique Character in a String

    Given a string, find the first non-repeating character in it and return it's index. If it doesn't ex ...

  3. [LeetCode&Python] Problem 427. Construct Quad Tree

    We want to use quad trees to store an N x N boolean grid. Each cell in the grid can only be true or ...

  4. [LeetCode&Python] Problem 371. Sum of Two Integers

    Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...

  5. [LeetCode&Python] Problem 520. Detect Capital

    Given a word, you need to judge whether the usage of capitals in it is right or not. We define the u ...

  6. [LeetCode&Python] Problem 226. Invert Binary Tree

    Invert a binary tree. Example: Input: 4 / \ 2 7 / \ / \ 1 3 6 9 Output: 4 / \ 7 2 / \ / \ 9 6 3 1 Tr ...

  7. [LeetCode&Python] Problem 905: Sort Array By Parity

    Given an array A of non-negative integers, return an array consisting of all the even elements of A, ...

  8. [LeetCode&Python] Problem 1: Two Sum

    Problem Description: Given an array of integers, return indices of the two numbers such that they ad ...

  9. [LeetCode&Python] Problem 682. Baseball Game

    You're now a baseball game point recorder. Given a list of strings, each string can be one of the 4 ...

随机推荐

  1. 浅析Tomcat、JBOSS、WebSphere、WebLogic、Apache

    做任何web项目,都离不开服务器,有钱的公司用WebSphere.WebLogic,没钱公司用nginx+tomcat,不要小瞧nginx+tomcat麻雀虽小,五脏俱全. 服务器的知识,在笔试.面试 ...

  2. Pandas之分组

    假如我们现在有这样一组数据:星巴克在全球的咖啡店信息,如下图所示.数据来源:starbucks_store_locations.我们想要统计中国每个城市的星巴克商店的数量,那我们应该怎么做呢? 在pa ...

  3. TabBar + TabBarView导航风格

    import 'package:flutter/material.dart'; import 'News.dart'; import 'Video.dart'; import 'Chat.dart'; ...

  4. linux centos7添加ip黑名单禁止某个ip访问

    centos7用的是firewall 添加单个黑名单只需要把ip添加到 /etc/hosts.deny 格式  sshd:$IP:deny vim /etc/hosts.deny   添加你要禁止的i ...

  5. C# HttpWebResponse WebClient 基础连接已经关闭: 发送时发生错误.

    https://blog.csdn.net/sun49842566/article/details/82802297 net 4.0 设置: ServicePointManager.SecurityP ...

  6. 初始Vue

    渐进式 JavaScript 框架 通过对框架的了解与运用程度,来决定其在整个项目中的应用范围,最终可以独立以框架方式完成整个web前端项目 走进Vue what -- 什么是Vue 可以独立完成前后 ...

  7. DAY11 函数(二)

    一.函数的对象 1.1定义:函数名就是存放了函数的内存地址,存放了内存地址的变量都是对象,即 函数名 就是 函数对象 1.2函数对象的应用 1 可以直接被引用 fn = cp_fn def fn(): ...

  8. 20175317 《Java程序设计》第二周学习总结

    20175317 <Java程序设计>第二周学习总结 教材学习内容总结 第二周我学习了教材三四章的内容,了解了Java与C语言的相似与不同之处. 其中第二章学到了标识符与关键字.基本数据类 ...

  9. 【文献07】基于MPC的WMR点镇定-极坐标系下和轨迹跟踪

    参考: Kuhne F , Lages W , Silva J D . Point stabilization of mobile robots with nonlinear model predic ...

  10. part4:素数判别

    法一: √n判别 这个的话就是暴力了吧,不过只能判别单个数是不是质数,而且很大的话会爆 //没有代码qwq(不想写 法二:埃式筛法 O(nloglogn)判别 直接代码好不啦: ],n,num; ]; ...