Skip to content

Commit 9fa1591

Browse files
String and Math Done
1 parent b0536ca commit 9fa1591

28 files changed

Lines changed: 74 additions & 0 deletions

4 Math/RomanToInteger.java renamed to 1 Leetcode Easy Problems/Leetcode 13 Roman to Integer using Math.java

File renamed without changes.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
private final Map<Character, Integer> SYMBOLS = new HashMap<>();
5+
{
6+
SYMBOLS.put('I', 1);
7+
SYMBOLS.put('V', 5);
8+
SYMBOLS.put('X', 10);
9+
SYMBOLS.put('L', 50);
10+
SYMBOLS.put('C', 100);
11+
SYMBOLS.put('D', 500);
12+
SYMBOLS.put('M', 1000);
13+
}
14+
15+
public int romanToInt(String roman) {
16+
int result = 0;
17+
for (int i = 0; i < roman.length(); i++) {
18+
char current = roman.charAt(i);
19+
int currValue = SYMBOLS.get(current);
20+
int nextValue = 0;
21+
22+
if (i + 1 < roman.length()) {
23+
char nextChar = roman.charAt(i+1);
24+
nextValue = SYMBOLS.get(nextChar);
25+
}
26+
27+
if (nextValue > currValue) {
28+
result += (nextValue - currValue);
29+
i++;
30+
} else {
31+
result += currValue;
32+
}
33+
}
34+
return result;
35+
}
36+
}

3 Strings/LongestCommonPrefix.java renamed to 1 Leetcode Easy Problems/Leetcode 14 Longest Common Prefix.java

File renamed without changes.

3 Strings/168 Excel Sheet Column Title.java renamed to 1 Leetcode Easy Problems/Leetcode 168 Excel Sheet Column Title.java

File renamed without changes.

4 Math/ExcelSheetColumnNumber.java renamed to 1 Leetcode Easy Problems/Leetcode 171 Excel Sheet Column Number using Math.java

File renamed without changes.

3 Strings/171 Excel Sheet Column Number.java renamed to 1 Leetcode Easy Problems/Leetcode 171 Excel Sheet Column Number.java

File renamed without changes.

3 Strings/205 Isomorphic Strings.java renamed to 1 Leetcode Easy Problems/Leetcode 205 Isomorphic Strings.java

File renamed without changes.

3 Strings/242 Valid Anagram.java renamed to 1 Leetcode Easy Problems/Leetcode 242 Valid Anagram.java

File renamed without changes.

3 Strings/290 Word Pattern.java renamed to 1 Leetcode Easy Problems/Leetcode 290 Word Pattern.java

File renamed without changes.

3 Strings/ReverseString.java renamed to 1 Leetcode Easy Problems/Leetcode 344 Reverse String.java

File renamed without changes.

0 commit comments

Comments
 (0)