[LeetCode]-011-Integer_to_Roman
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
题目大意:把一个整数转换成罗马数字
public class Solution{
private String[][] arr = {
{"0","I","II","III","IV","V","VI","VII","VIII","IX"},
{"0","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"},
{"0","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"},
{"0","M","MM","MMM"}
};
public String intToRoman(int num) {
if(num<0 || num>3999)
return "";
StringBuilder res = new StringBuilder();
int tmp = num;
if((tmp/1000)!=0)
res.append(arr[3][tmp/1000]);
tmp = tmp%1000;
if((tmp/100)!=0)
res.append(arr[2][tmp/100]);
tmp = tmp%100;
if((tmp/10)!=0)
res.append(arr[1][tmp/10]);
tmp = tmp%10;
if(tmp!=0)
res.append(arr[0][tmp]);
return res.toString();
}
public static void main(String[] args){
int param = 1234;
if(args.length==1){
param = Integer.valueOf(args[0]);
}
Solution solution = new Solution();
String res = solution.intToRoman(param);
System.out.println(res);
}
}
[LeetCode]-011-Integer_to_Roman的更多相关文章
- 【JAVA、C++】LeetCode 011 Container With Most Water
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
- [Leetcode]011. Container With Most Water
public class Solution { public int maxArea(int[] height) { int left = 0, right = height.length - 1; ...
- leetcode python 011
####给定n个非负整数a1,a2,...,an,其中每个表示坐标(i,ai)处的点.##绘制n条垂直线,使得线i的两个端点位于(i,ai)和(i,0).##找到两条线,它们与x轴一起形成一个容器,这 ...
- Leetcode:integer_to_roman
一. 题目 将给定的数字(阿拉伯数字)转化成罗马数字. 数字不会大于3999 二. 分析 首先我们要知道神马是罗马数字,尽管听说过.但事实上我还真没有记住,于是就google了下,具体 ...
- 【LeetCode】011 Container With Most Water
题目: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, a ...
- [LeetCode] Binary Watch 二进制表
A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom ...
- [LeetCode] Bitwise AND of Numbers Range 数字范围位相与
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
- [LeetCode] Restore IP Addresses 复原IP地址
Given a string containing only digits, restore it by returning all possible valid IP address combina ...
- leetcode & lintcode for bug-free
刷题备忘录,for bug-free leetcode 396. Rotate Function 题意: Given an array of integers A and let n to be it ...
- [LeetCode] Stickers to Spell Word 贴片拼单词
We are given N different types of stickers. Each sticker has a lowercase English word on it. You wou ...
随机推荐
- 如何减少程序间的耦合度?_DI与接口
spring 开发提倡接口编程,配合DI技术可以更好的减少层(程序)与层(程序)之间的解耦合例子说明: 任务:要求: 1.打印机依赖纸张和墨盒 2.纸张有A4和B5两种 ...
- zk ui安装 (选装,页面查看zk的数据)
# 使用WEB UI查看监控集群-zk ui安装 cd /usr/local git clone https://github.com/DeemOpen/zkui.git yum install -y ...
- LVS实现负载均衡原理及安装配置 负载均衡
LVS实现负载均衡原理及安装配置 负载均衡集群是 load balance 集群的简写,翻译成中文就是负载均衡集群.常用的负载均衡开源软件有nginx.lvs.haproxy,商业的硬件负载均衡设备F ...
- python多线程之threading、ThreadPoolExecutor.map
背景: 某个应用场景需要从数据库中取出几十万的数据时,需要对每个数据进行相应的操作.逐个数据处理过慢,于是考虑对数据进行分段线程处理: 方法一:使用threading模块 代码: # -*- codi ...
- linux如何配置使用sendEmail发送邮件
sendEmail是一个轻量级.命令行的SMTP邮件客户端.如果你需要使用命令行发送邮件,那么sendEmail是非常完美的选择.使用简单并且功能强大.这个被设计用在php.bash.perl和web ...
- 一、Signalr WebApi客服
一.搭建环境 (redis服务) 链接测试 二.项目搭建 参考 1.搭建项目(直接项目-不包含MVC以及API) 项目结构 但是需要访问(所以还需要添加控制器Api的模式)选择Api 添加类库一个专门 ...
- (转) ESB 企业服务总线基本内容概述
ESB全称为Enterprise Service Bus,即企业服务总线. 它是传统中间件技术与XML.Web服务等技术结合的产物(SOAP协议= HTTP协议+ XML数据格式). ESB提供了网络 ...
- Interviewe HDU - 3486 (ST表+枚举 )(非二分,看下这个数据、)
YaoYao has a company and he wants to employ m people recently. Since his company is so famous, there ...
- Quartz(二)
1 SchedulerFactory 1.1 概述 Quartz是以模块的方式构建的,因为,要使它运行,几个组件必须很好的组合在一起.非常幸运的是,已经有了一些现存的助手可以完成这些工作. 所有Sch ...
- Xshell6-项目使用
前端开发中,涉及服务器的地方一般都交给后端处理,这样有时候很不方便,所以,自己来上传服务器是非常爽的啦 工具: Xshell6 传送门: http://www.netsarang.com/produc ...