LeetCode-Solutions icon indicating copy to clipboard operation
LeetCode-Solutions copied to clipboard

Add 13_Roman_To_Integer.cpp to cpp folder

Open rudrakshtank opened this issue 7 months ago • 1 comments

Description

Problem: Convert a Roman numeral string into its corresponding integer value.

Approach:

  1. Store Roman numeral values in an unordered_map.
  2. Traverse the string from right to left.
  3. If the current numeral’s value is greater than or equal to the previous numeral’s value, add it to the total; otherwise, subtract it.
  4. Update the prev character each iteration.
  5. Return the final computed value.

Time Complexity: O(N), where N is the length of the input string.
Space Complexity: O(1), since only a fixed-size hash map is used.

Have you made changes in README file ?

  • [x] Added problem & solution under correct topic.
  • [x] Specified Space & Time complexity.
  • [ ] Specified difficulty level, tag & Note(if any).

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Please also note any relevant details for your test configuration.

  • [ ] Test A
  • [ ] Test B

Make sure all below guidelines are followed else PR will get Reject:

  • [x] My code follows the style guidelines of this project
  • [x] I have performed a self-review of my own code
  • [x] I have commented my code so that it is easy to understand
  • [x] I have made corresponding changes to the documentation
  • [x] My changes generate no new warnings
  • [x] Any dependent changes have been merged and published in downstream modules

rudrakshtank avatar Aug 09 '25 17:08 rudrakshtank

I can tell this is your first pull request! Thank you I'm so honored. :tada::tada::tada: I'll take a look at it ASAP!

welcome[bot] avatar Aug 09 '25 17:08 welcome[bot]