Roman to Integer - LeetCode 13 | Java

preview_player
Показать описание

Today I solve and explain a Easy level difficulty leetcode SQL problem using Java called "13. Roman to Integer"

The approach I took was using a switch case to quickly translate the characters to it's corresponding integer value. With every iteration I look up the integer translation and add it to the count.

The main trick is that if the previous number is smaller than the current number we want to decrement the current running sum by the previous number. Otherwise we simply add the current number.

Time complexity: O(N)
Space complexity: O(1)

Code Solution Post: (Sign into LeetCode to view)

Checkout my Blog Post: "Reflecting on 1 Year of LeetCode"

If you found this helpful Like and Subscribe! I solve LeetCode Algorithms and SQL Problems daily!

#leetcode #java #tutorial #leetcode #algorithm #faang
Рекомендации по теме
Комментарии
Автор

How is your LeetCode grind going? Comment below a Leetcode question you need help with!! 🙏

codewithcarter
Автор

Nice concise explanation, quick, efficient, exactly what is needed ✅
Keep is up man!

SalmanM
Автор

Man really i loved this code! I saw many other examples and i feel this is best and easy to understand.

vamshikrishna
Автор

Thank you so much for this! Well done! Keep up these videos, I'm learning a lot from these.

zubyrh
Автор

Good algorithm. You definitely deserve more attention.

kylethechild
Автор

Thank you for the explanation. Looking forward to seeing more with java.

melanieprevot
Автор

Thanks for making this video man, it helped a lot!

tokenwinner
Автор

Thanks for quick and easy explaination

abhimanyupratapsingh
Автор

Thank you so much for the great content!

jawadmohdab