LeetCode——Integer to Roman
Description:
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
noting to say.
public class Solution {
public String intToRoman(int number) {
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" };
StringBuilder result = new StringBuilder();
for (int i = 0; i < values.length; i++) {
while (number >= values[i]) {
number -= values[i];
result.append(numerals[i]);
}
}
return result.toString();
}
}
LeetCode——Integer to Roman的更多相关文章
- LeetCode: Integer to Roman 解题报告
Integer to Roman Given an integer, convert it to a roman numeral. Input is guaranteed to be within t ...
- [LeetCode] Integer to Roman 整数转化成罗马数字
Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...
- Leetcode Integer to Roman
Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...
- leetcode Integer to Roman python
class Solution(object): def intToRoman(self, num): """ :type num: int :rtype: str &qu ...
- [LeetCode][Python]Integer to Roman
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/integer ...
- Integer to Roman - LeetCode
目录 题目链接 注意点 解法 小结 题目链接 Integer to Roman - LeetCode 注意点 考虑输入为0的情况 解法 解法一:从大到小考虑1000,900,500,400,100,9 ...
- LeetCode OJ:Integer to Roman(转换整数到罗马字符)
Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...
- LeetCode:12. Roman to Integer (Easy)
1. 原题链接 https://leetcode.com/problems/roman-to-integer/description/ 2. 题目要求 (1)将罗马数字转换成整数:(2)范围1-399 ...
- leetCode练题——12. Integer to Roman
1.题目 12. Integer to Roman Roman numerals are represented by seven different symbols: I, V, X, L, C, ...
随机推荐
- Hadoop日志分析工具——White Elephant
White Elephant 是一个Hadoop日志收集器和展示器,它提供了用户角度的Hadoop集群可视化.White Elephant 是全球最大的职业社交网站Linkedin开发的一套分析Had ...
- hive中创建表失败
使用create table命令创建表失败,如下错误信息: hive> create table test(id int,name string,age int,sex string); FAI ...
- Lua中的loadfile、dofile、require详解
1.loadfile——只编译,不运行 loadfile故名思议,它只会加载文件,编译代码,不会运行文件里的代码.比如,我们有一个hellofile.lua文件: 复制代码代码如下: print(“h ...
- [Linux小技巧] 一行命令让CPU占用率达到100%
for i in `seq 1 $(cat /proc/cpuinfo |grep "physical id" |wc -l)`; do dd if=/dev/zero of=/d ...
- PHP中动态增加属性到对象
参见: <深入PHP 面向对象.模式与实践>(第三版) [ matt zandstra ] - 3.2章节,设置类中的属性(p17)
- JPA多对多关联
关于JPA多对多关系,这是使用学生与教师来表示.一个Student由多个Teacher教,同样一个Teacher也可以教多个学生.Student类如下: package com.yichun.bean ...
- jenkins配置过程遇到的问题
jenkins 搭建完成后,可以浏览器访问: http://localhost:8081/jenkins, 新建任务过程中遇到以下问题: 1. 源码管理不现实git, 只显示无 解决: 插件管理 - ...
- 有了malloc/free 为什么还要new/delete ?
有了malloc/free 为什么还要new/delete ? malloc 与 free 是 C++/C 语言的标准库函数,new/delete 是 C++的运算符.它们都可 用于申请动态内存和释放 ...
- htaccess正则规则学习笔记整理
# —— 位于行首时表示注释. [F] —— Forbidden(禁止): 命令服务器返回 403 Forbidden错误给用户浏览器 [L] —— Last rule(最后一条规则): 告诉服务器在 ...
- 使用MFC WinInet进行FTP中文件的简单上传和下载功能
建立基于对话框的MFC应用程序CMfcFtpWinInetDlg: 1.首先Dlg类中包含头文件 #include "afxinet.h" 2.添加成员变量: C++ Code ...