当前位置:网站首页>leetcode.12 --- 整数转罗马数字
leetcode.12 --- 整数转罗马数字
2022-06-24 13:04:00 【_End丶断弦】
整数转罗马数字

题解:模拟
每次用最大的数来表示
一个数组存value,一个数组存单位
代码如下:
class Solution {
public:
string intToRoman(int num) {
//值
int value[] =
{
1000,
900,500,400,100,
90,50,40,10,
9,5,4,1
};
//单位
string company[] =
{
"M",
"CM","D","CD","C",
"XC","L","XL","X",
"IX","V","IV","I"
};
string res;
for(int i = 0;i < 13;i++)
{
while(num >= value[i]){
num -= value[i];
res += company[i];
}
}
return res;
}
};
时间复杂度:O(1)
空间复杂度:O(1)
边栏推荐
- 百度地图API绘制点及提示信息
- Digital business cloud: strengthen supplier management and promote efficient collaboration between air transport enterprises and suppliers
- Unit contour creation method
- SAP Marketing Cloud 功能概述(四)
- Overview of SAP marketing cloud functions (III)
- Redis interview questions
- tongweb使用之端口冲突处理办法
- 数字臧品系统开发 NFT数字臧品系统异常处理源码分享
- 第八章 操作位和位串(四)
- Halcon draw area into picture
猜你喜欢

【比特熊故事汇】6月MVP英雄故事|技术实践碰撞境界思维

The "little giant" specialized in special new products is restarted, and the "enterprise cloud" digital empowerment
![[untitled]](/img/6c/df2ebb3e39d1e47b8dd74cfdddbb06.gif)
[untitled]

Rasa 3. X learning series - it is a great honor to be a source code contributor of Rasa contributors, and to build and share the rasa community with rasa source code contributors all over the world!

SAP Marketing Cloud 功能概述(三)

OpenHarmony 1
![Jerry's infrared filtering [chapter]](/img/6b/7c4b52d39a4c90f969674a5c21b2c7.png)
Jerry's infrared filtering [chapter]

数字臧品系统开发 NFT数字臧品系统异常处理源码分享

GO语言并发模型-MPG模型

初识云原生安全:云时代的最佳保障
随机推荐
Jericho After sleep, the system will wake up regularly and continue to run without resetting [chapter]
[environment setup] zip volume compression
10_那些格调很高的个性签名
Halcon 绘制区域 到图片中
取消冒泡
Generate binary tree according to preorder & inorder traversal [partition / generation / splicing of left subtree | root | right subtree]
【Pytorch】量化
Baidu map API drawing points and tips
Rasa 3. X learning series - it is a great honor to be a source code contributor of Rasa contributors, and to build and share the rasa community with rasa source code contributors all over the world!
NPM package [details] (including NPM package development, release, installation, update, search, uninstall, view, version number update rules, package.json details, etc.)
pip uninstall all packages except builtin package
4 reasons for "safe left shift"
3环杀掉360安全卫士进程
v-if 和 v-show 的区别
六月集训(第23天) —— 字典树
v-for 中 key的作用和原理
`Thymeleaf`模板引擎全面解析
A review of text contrastive learning
打败 二叉树!
探索云原生数据库,纵观未来科技发展
