[leetcode-504-Base 7]
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].
string convertToBase7(int num)
{
if (num == ) return "";
string ret = "";
int temp = num;
if (num < ) num = -num;
while (num)
{
ret.insert(ret.begin(), num % + '');
//ret = to_string(num % 7) + ret;//to_string用法
num /= ;
}
if (temp < )ret.insert(ret.begin(), '-');
return ret;
}
[leetcode-504-Base 7]的更多相关文章
- 45. leetcode 504. Base 7
504. Base 7 Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: ...
- [LeetCode] 504. Base 7 基数七
Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: "202&q ...
- [LeetCode] 504. Base 7_Easy tag: Math
Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: "202&q ...
- LeetCode 504. Base 7 (C++)
题目: Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: "2 ...
- C#版 - Leetcode 504. 七进制数 - 题解
C#版 - Leetcode 504. 七进制数 - 题解 Leetcode 504. Base 7 在线提交: https://leetcode.com/problems/base-7/ 题目描述 ...
- 【leetcode】504. Base 7
problem 504. Base 7 solution: class Solution { public: string convertToBase7(int num) { ) "; st ...
- 【LeetCode】504. Base 7 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 内建库 BigInteger类 逐位计算 倍数相加 ...
- [LeetCode&Python] Problem 504. Base 7
Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: "202&q ...
- 504. Base 7
Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: "202&q ...
- 504 Base 7 七进制数
给定一个整数,将其转化为7进制,并以字符串形式输出.示例 1:输入: 100输出: "202" 示例 2:输入: -7输出: "-10"注意: 输入范围是 [- ...
随机推荐
- MFC基础程序设计VS2015 最新03
视频教程地址观看:http://pan.baidu.com/s/1mhKQ6kK 一.数字(浮点数或整数)转为文字:a)如果转为窄字符字符串,sprintf函数很好用,浮点数都没问题:b)如果转为宽字 ...
- Linux部分命令及通配符用法
pwd: 显示工作目录 cd -: 在上一次所在目录与当前目录之间来回切换 cd: 切换回家目录 cat: 文本查看工具 -n:给显示的文本行编号 passwd 修改用户的密码 which 查看系统 ...
- 精益IT组织与分享式领导
精益IT组织 未来的组织将专注于同行业的产品或业务流--其他的一切,包括专家和管理者在内,都是为了让一线工作人员可以第一时间就做好,而又不会遇到任何麻烦.最大的制约不是技术:真正的挑战是变 ...
- jQuery选择器的分类
jQuery选择器的分类 jQuery中有很多分类,大类分为四类,四类里面又分为很多小类,下面就为大家一一介绍,这些选择器的使用和好处,Me用的是jQuery1.8.3的版本 选择器都有哪四类?? 1 ...
- 高斯消元法(Gauss Elimination)【超详解&模板】
高斯消元法,是线性代数中的一个算法,可用来求解线性方程组,并可以求出矩阵的秩,以及求出可逆方阵的逆矩阵.高斯消元法的原理是:若用初等行变换将增广矩阵 化为 ,则AX = B与CX = D是同解方程组. ...
- (数字IC)低功耗设计入门(一)
低功耗设计这个专题整理了好久,有一个月了,有图有证据: 然而最近一直有些烦心事.郁闷事,拖延了一下,虽然现在还是有点烦,但是还是先发表了吧.下面我们就来聊聊低功耗设计吧,由于文章比较长,因此我就不一次 ...
- php回调函数的使用
1.array_map — 将回调函数作用到给定数组的单元上 参数:array array_map ( callable $callback , array $arr1 [, array $... ] ...
- 几个常用的linux快捷键和shell知识
1) !$ !$是一个特殊的环境变量,它代表了上一个命令的最后一个字符串.如:你可能会这样: $mkdir mydir $mv mydir yourdir $cd y ...
- numpy中linspace用法 (等差数列创建函数)
linspace 函数 是创建等差数列的函数, 最好是在 Matlab 语言中见到这个函数的,近期在学习Python 中的 Numpy, 发现也有这个函数,以下给出自己在学习过程中的一些总结. ( ...
- java并发编程(Exchanger)
package org.bianqi.demo1; import java.util.concurrent.Exchanger; import java.util.concurrent.Executo ...