leetcode之旅(11)-Integer to Roman
题目描述:
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
Subscribe to see which companies asked this question
Show Tags
Show Similar Problems
准备知识看上篇博客
leetcode之旅(10)-Roman to Integer
思路:
当前这个数是否大于最大的权?若大于则循环判断有几个这样的权?若小于,则降低权进行判断,重复判断操作
代码:
public class Solution {
public String intToRoman(int num) {
int values[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 };
String numerals[] = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" };
String result = "";
for (int i = 0; i < 13; i++)
{
while (num >= values[i]) //循环判断当前权值个数
{
num -= values[i];
result = result +numerals[i]; //append函数是向string 的后面追加字符或字符串。
}
}
return result;
}
}
leetcode之旅(11)-Integer to Roman的更多相关文章
- 【LeetCode】12 & 13 - Integer to Roman & Roman to Integer
12 - Integer to Roman Given an integer, convert it to a roman numeral. Input is guaranteed to be wit ...
- leetCode练题——12. Integer to Roman
1.题目 12. Integer to Roman Roman numerals are represented by seven different symbols: I, V, X, L, C, ...
- leetcode之旅(10)-Roman to Integer
题目描述: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range fr ...
- leetcode解决问题的方法||Integer to Roman问题
problem: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range ...
- leetcode第12题--Integer to Roman
Problem: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range ...
- LeetCode(12)Integer to Roman
题目 Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from ...
- [LeetCode][Python]Integer to Roman
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/integer ...
- [LeetCode] Integer to Roman 整数转化成罗马数字
Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...
- Integer to Roman - LeetCode
目录 题目链接 注意点 解法 小结 题目链接 Integer to Roman - LeetCode 注意点 考虑输入为0的情况 解法 解法一:从大到小考虑1000,900,500,400,100,9 ...
随机推荐
- Android之EditText imeOptions属性解析
在我们的手机中,虽然通常输入法软键盘右下角会是回车按键,但我们经常会看到点击不同的编辑框,输入法软键盘右下角会有不同的图标.例如: 点击浏览器网址栏的时候,输入法软键盘右下角会变成"GO& ...
- 18 UI美化状态集合的位图selector
当我们某个控件 想在不同状态下显示不同的背景图的需求 如我们需要按钮在正常状态显示一种图 按下显示另一背景图 或者单选框被选中时是一种显示图片 没选中是另一种背景图 例子 按钮在不同状态显示不同的背景 ...
- 1.1、Android Studio创建一个项目
Android Studio中的项目包含一个或多个模块.本节帮助你创建一个新的项目. 创建一个新的项目 如果你之前没有打开项目,Android Studio显示欢迎页面,通过点击Start a New ...
- leetcode 37. Sudoku Solver 36. Valid Sudoku 数独问题
三星机试也考了类似的题目,只不过是要针对给出的数独修改其中三个错误数字,总过10个测试用例只过了3个与世界500强无缘了 36. Valid Sudoku Determine if a Sudoku ...
- linux crontab定时任务详解
1. 为当前用户创建cron服务: crontab -e 例如 文件内容如下(每隔1分钟执行sql脚本): */1 * * * * mysql -h127.0.0.1 -uroot -proot ...
- Dynamics CRM 导入用户数据错误 could not retrieve salesperson role
在CRM中通过导入数据的方式创建用户时报下图中的错误,"could not retrieve saleperson role".原因是系统中的自带的salesperson安全角色被 ...
- linux下JAVA开发的环境配置
1.去http: //java.sun.com/j2se/1.4.2/download.html 下载一个Linux Platform的JDK,建议下载RPM自解压格式的(RPM in self-ex ...
- 如何利用BI搭建电商数据分析平台
某电商是某大型服装集团下的重要销售平台.2015 年,该集团品牌价值达数百亿元,产品质量.市场占有率.出口创汇.销售收入连年居全国绒纺行业第一,在中国有终端店3000多家,零售额80 亿.其羊绒制品年 ...
- TCP的定时器系列 — 保活定时器
主要内容:保活定时器的实现,TCP_USER_TIMEOUT选项的实现. 内核版本:3.15.2 我的博客:http://blog.csdn.net/zhangskd 原理 HTTP有Keepaliv ...
- Android后台消息推送-android学习之旅(71)
建议使用第三方的sdk,比如极光推送,小米推送,百度推送