当前位置:网站首页>leetcode. 12 --- integer to Roman numeral
leetcode. 12 --- integer to Roman numeral
2022-06-24 14:26:00 【_ End, broken chord】
Integer to Roman number

Answer key : simulation
Use the maximum number each time
An array is stored value, An array storage unit
The code is as follows :
class Solution {
public:
string intToRoman(int num) {
// value
int value[] =
{
1000,
900,500,400,100,
90,50,40,10,
9,5,4,1
};
// Company
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;
}
};
Time complexity :O(1)
Spatial complexity :O(1)
边栏推荐
- [untitled]
- 不要小看了积分商城,它的作用可以很大
- R language plot visualization: use plot to visualize the training set and test set after data division, use different shape label representation, training set, test set, and display training and test
- 数据库注意事项
- Kunpeng arm server compilation and installation paddlepaddle
- Convolution kernel and characteristic graph visualization
- 测试 H5 和小程序的区别,你真的知道吗?
- 如何避免下重复订单
- Maximum path sum in binary tree [handle any subtree, then handle the whole tree]
- June training (day 23) - dictionary tree
猜你喜欢
随机推荐
GO语言-goroutine协程的使用
The function and principle of key in V-for
How to avoid placing duplicate orders
【ansible问题处理】远程执行用户环境变量加载问题
How to implement redis cache of highly paid programmers & interview questions series 115? How do I find a hot key? What are the possible problems with caching?
Maximum path sum in binary tree [handle any subtree, then handle the whole tree]
Mots clés pour la cartographie es; Ajouter une requête par mot - clé à la requête term; Changer le type de mot - clé de cartographie
动作捕捉系统用于地下隧道移动机器人定位与建图
[environment setup] zip volume compression
Go language - use of goroutine coroutine
ESP32系列--ESP32各个系列对比
leetcode.12 --- 整数转罗马数字
二叉树中最大路径和[处理好任意一颗子树,就处理好了整个树]
Development of B2B transaction collaborative management platform for kitchen and bathroom electrical appliance industry and optimization of enterprise inventory structure
box-sizing
Keyword of ES mapping; Term query add keyword query; Change mapping keyword type
打败 二叉树!
六石管理学:垃圾场效应:工作不管理,就会变成垃圾场
【比特熊故事汇】6月MVP英雄故事|技术实践碰撞境界思维
Overview of SAP marketing cloud functions (III)

![二叉树中最大路径和[处理好任意一颗子树,就处理好了整个树]](/img/d0/91ab1cc1851d7137a1cab3cf458302.png)







