LeetCode 504. Base 7 (C++)
题目:
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].
分析:
给定一个7进制数,求十进制表示,注意返回的是字符串。
进制转换没什么好说的,注意这道题测试用例是有负数的,且返回值是字符串,记得转成字符串形式。
程序:
class Solution {
public:
string convertToBase7(int num) {
if(num == ) return "";
string res;
int n = abs(num);
while(n){
res = to_string(n%) + res;
n /= ;
}
if(num < )
return "-"+res;
else
return res;
}
};
LeetCode 504. Base 7 (C++)的更多相关文章
- 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 ...
- 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"注意: 输入范围是 [- ...
随机推荐
- Javascript之DOM性能优化
原文地址:http://ce.sysu.edu.cn/hope/Item/140355.aspx 作者:陈古松 来源:本站原创 发布时间:2015-03-14 更新时间:2015-03-14 点击数 ...
- redis在.net架构中的应用(2)--并发和原子操作不可兼得
在上一篇文章中,我主要向大家介绍了利用servicestack连接redis以及一些redis的基本数据类型,传送门 本文中,我将通过一个具体应用场景为大家介绍redis中的并发和原子操作 其中用到的 ...
- Redux入门学习
一.Redux三大原则 1. 单一数据源 应用中所有的state都以一个对象树的形式储存在一个单一的store中. 2. state只读 唯一改变state的办法是触发action.action是一个 ...
- 【转】mysql交互式连接&非交互式连接
交互式操作:通俗的说,就是你在你的本机上打开mysql的客户端,就是那个黑窗口,在黑窗口下进行各种sql操作,当然走的肯定是tcp协议. 非交互式操作:就是你在你的项目中进行程序调用.比如一边是tom ...
- Python2.7-matplotlib
matplotlib的pyplot子库提供了和matlab类似的绘图API,方便用户快速绘制2D图表 一般用以下形式导入:import matplotlib.pyplot as plt 一般用法:1. ...
- CAN调度理论与实践分析
CAN调度理论与实践分析 分布式嵌入式系统是当前嵌入式系统的重要发展方向,因为它能提供更强的性能,节约系统的总体成本.但是由于各单个节点必须有通信网络相连才能协调地工作,网络就成了关键部分,没有网络提 ...
- 编写Linux脚本
下面是重新启动Linux下某进程的shell脚本.以tomcat进程为例: #!/bin/sh pid=`ps -ef|grep tomcat|grep -v grep|awk '{print $2} ...
- 【Nodejs】Browsersync同步浏览器测试
说明文档:http://www.browsersync.cn/docs/ 安装命令: ①全局安装 npm install -g browser-sync ②局部/本地安装 npm install br ...
- 基于多进程和基于多线程服务器的优缺点及nginx服务器的启动过程
基于多进程服务器的优点: 1.由操作系统进行调度,运行比较稳定强壮 2.能够方便地通过操作系统进行监控和管理 例如对每个进程的内存变化状况,甚至某个进程处理什么web请求进行监控.同时可以通过给进程发 ...
- MySQL学习笔记04 插入中文时出现ERROR 1366 (HY000)
1 环境: MySQL Server 6.0 命令行工具 2 问题 : 插入中文字符数据出现如下错误: ERROR 1366 (HY000): Incorrect string value: '\ ...