Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6a4b505

Browse files
integer to roman
1 parent 2c46b7a commit 6a4b505

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

MEDIUM/src/medium/IntegertoRoman.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package medium;
2+
3+
public class IntegertoRoman {
4+
//looked at this post: https://discuss.leetcode.com/topic/12384/simple-solution
5+
public String intToRoman(int num) {
6+
String M[] = {"", "M", "MM", "MMM"};
7+
String C[] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};
8+
String X[] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
9+
String I[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
10+
return M[num/1000] + C[(num%1000)/100] + X[(num%100)/10] + I[num%10];
11+
}
12+
13+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
|17|[Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number/)|[Solution](../../blob/master/MEDIUM/src/medium/LetterCombinationsofaPhoneNumber.java)|O(n*4^n)|O(n)|Medium|Backtracking
125125
|15|[3Sum](https://leetcode.com/problems/3sum/)|[Solution](../../blob/master/MEDIUM/src/medium/_3Sum.java)|O(n^2)|O(1)|Medium|Two Pointers
126126
|14|[Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/)|[Solution](../../blob/master/EASY/src/easy/LongestCommonPrefix.java)| O(n*min(wordLength in this array)) | O(1) | Easy
127+
|12|[Integer to Roman](https://leetcode.com/problems/integer-to-roman/)|[Solution](../../blob/master/MEDIUM/src/medium/IntegertoRoman.java)|O(1)|O(1)|Medium|
127128
|10|[Regular Expression Matching](https://leetcode.com/problems/regular-expression-matching/)|[Solution](../../blob/master/HARD/src/hard/RegularExpressionMatching.java)|O(m*n)|O(m*n)|Hard|DP
128129
|9|[Palindrome Number](https://leetcode.com/problems/palindrome-number/)|[Solution](../../blob/master/EASY/src/easy/PalindromeNumber.java)| O(logn)/(n) | O(1) | Easy
129130
|8|[String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi/)|[Solution](../../blob/master/EASY/src/easy/StringToInteger.java)| O(n) | O(1) | Easy

0 commit comments

Comments
 (0)