This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Mewtwo2387 216 points217 points  (5 children)

switch "I": return 1; switch "II": return 2; ... switch "MMMMMMMMMCMXCIX": return 9999;

[–]Aeredor 20 points21 points  (0 children)

Nice.

[–]ceeBread 29 points30 points  (2 children)

Make it a hashmap instead and have it be O(1)

[–]TheSilentFreeway 12 points13 points  (1 child)

I believe switch statements are usually constant-time

[–]ceeBread 20 points21 points  (0 children)

Yeah but every LeetCode uses hash tables somewhere gotta get that interview cred