GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — 添加了阿拉伯数字向罗马数字的转换题目 · walkerzhao/leetcode@624111d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • string/IntegerToRoman
    • IntegerToRoman.java
    • problem.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎string/IntegerToRoman/IntegerToRoman.java‎

Copy file name to clipboard
+36Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import java.util.HashMap;
2+
import java.util.Map;
3+
4+
5+
public class IntegerToRoman {
6+
public String intToRoman(int num) {
7+
int[] arrayInteger= {1000,900,500,400,100,90,50,40,10,9,5,4,1};
8+
String arrayRoman[] = {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
9+
10+
String result="";
11+
int length = arrayInteger.length;
12+
for(int i=0;i<length;i++) {
13+
while(num>=arrayInteger[i]) {
14+
num = num - arrayInteger[i];
15+
result = result+arrayRoman[i];
16+
}
17+
}
18+
return result;
19+
}
20+
21+
}
22+
23+
class Test {
24+
public static void main(String[] args) {
25+
IntegerToRoman test = new IntegerToRoman();
26+
int num = 3999;
27+
String result = test.intToRoman(num);
28+
System.out.println(result);
29+
}
30+
}
31+
//测试用例
32+
//5
33+
//4
34+
//90
35+
//3999
36+
Collapse file

‎string/IntegerToRoman/problem.md‎

Copy file name to clipboard
+10Lines changed: 10 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# 题目
2+
Given an integer, convert it to a roman numeral.
3+
4+
Input is guaranteed to be within the range from 1 to 3999.
5+
6+
## tag:Math String
7+
8+
##思路:
9+
* 基本的罗马字符将0-4000中的数字进行了分段
10+
* 判断给定字段属于哪个字段,循环就可以求得对应的罗马字符串

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.