Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions 05월/2주차/[LCD] Longest Common Prefix/Min.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Min {
public String longestCommonPrefix(String[] strs) {
String prefix = "";

int len = 201;
for(String str : strs) {
len = Math.min(str.length(), len);
}

for(int i = 0; i < len; i++) {
char c = strs[0].charAt(i);
for(String str : strs) {
if(str.charAt(i) != c) return prefix;
}
prefix += c;
}

return prefix;
}
}
27 changes: 27 additions & 0 deletions 05월/2주차/[LCD] Roman to Integer/Min.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import java.util.*;

class Min {
public int romanToInt(String s) {
HashMap<Character, Integer> hm = new HashMap<>();
hm.put('I', 1);
hm.put('V', 5);
hm.put('X', 10);
hm.put('L', 50);
hm.put('C', 100);
hm.put('D', 500);
hm.put('M', 1000);

int sum = 0;
for(int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
int num = hm.get(c);
if(i + 1 < s.length() && hm.get(s.charAt(i + 1)) > num) {
sum += hm.get(s.charAt(++i)) - num;
continue;
}
sum += num;
}
Comment on lines +15 to +23
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

풀이가 깔끔한 것 같아요..! 배워갑니다 👍


return sum;
}
}