当前位置:网站首页>Leetcode topic resolution integer to Roman
Leetcode topic resolution integer to Roman
2022-06-23 06:02:00 【ruochen】
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
- Write the same numbers together , The number represented is equal to the sum of these numbers , Such as :Ⅲ = 3;
- The small number is to the right of the big number , The number represented is equal to the sum of these numbers , Such as :Ⅷ = 8;Ⅻ = 12;
- Small numbers ,( Be limited to Ⅰ、X and C) To the left of the big numbers , The number represented is equal to the number obtained by subtracting the decimal from the large number , Such as :Ⅳ= 4;Ⅸ= 9;
- In normal use , Consecutive numbers should not be repeated more than three times .( Four o'clock on the dial “IIII” exception );
- Draw a horizontal line over a number , Indicates that the number is enlarged 1000 times .
public String intToRoman(int num) {
final int[] values = { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5,
4, 1 };
final String[] symbol = { "M", "CM", "D", "CD", "C", "XC", "L", "XL",
"X", "IX", "V", "IV", "I" };
StringBuilder result = new StringBuilder();
for (int i = 0; num > 0; i++) {
int count = num / values[i];
num %= values[i];
for (; count > 0; count--) {
result.append(symbol[i]);
}
}
return new String(result);
}边栏推荐
- jvm-03. JVM memory model
- The traditional Internet like platform may no longer exist, and a new industry integrating industrial characteristics and Internet characteristics
- PAT 乙等 1019 C语言
- [OWT] OWT client native P2P E2E test vs2017 build 6: modify script automatic generation vs Project
- [open source project] excel export Lua configuration table tool
- [image fusion] sparse regularization based on non convex penalty to realize image fusion with matlab code
- Software design and Development Notes 2: serial port debugging tool based on QT design
- Basic calculator for leetcode topic analysis
- [Stanford Jiwang cs144 project] lab2: tcpreceiver
- Huawei's software and hardware ecosystem has taken shape, fundamentally changing the leading position of the United States in the software and hardware system
猜你喜欢

ssm项目搭建

A bit of knowledge - folding forging and Damascus steel

Visual Studio调试技巧

How does win11 enable mobile hotspot? How to enable mobile hotspot in win11

jvm-05.垃圾回收

Redis cache penetration solution - bloom filter

runc 符号链接挂载与容器逃逸漏洞预警(CVE-2021-30465)

Addressing and addressing units

编址和编址单位

如何指定pig-register项目日志的输出路径
随机推荐
Advanced Mathematics (Seventh Edition) Tongji University exercises 1-8 personal solutions
A bit of knowledge - folding forging and Damascus steel
Ansible 使用普通用户管理被控端
HierarchyViewer工具找不到 HierarchyViewer位置
Oracle exception
Real MySQL interview question (23) -- pinduoduo ball game analysis
密码学系列之:PKI的证书格式表示X.509
App SHA1 acquisition program Baidu map Gaode map simple program for acquiring SHA1 value
Centos7部署radius服务-freeradius-3.0.13-15.el7集成mysql
jvm-01. Instruction rearrangement
PAT 乙等 1012 C语言
数字藏品到底有什么魔力?目前有哪些靠谱的团队在开发
The construction of digital factory can be divided into three aspects
最优传输理论下对抗攻击可解释性
Pat class B 1022 d-ary a+b
数字藏品——新的投资机遇
数字藏品如何赋能经济实体?
PAT 乙等 1018 C语言
PAT 乙等 1021 个位数统计
PAT 乙等 1010 C语言