You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: solution/0000-0099/0013.Roman to Integer/README_EN.md
+63-29
Original file line number
Diff line number
Diff line change
@@ -64,22 +64,21 @@ M 1000</pre>
64
64
65
65
## Solutions
66
66
67
+
**Approach 1: Hash table + simulation**
68
+
69
+
We first use a hash table $d$ to record the numerical value corresponding to each character, and then traverse the string $s$ from left to right. If the numerical value corresponding to the current character is less than the numerical value corresponding to the right character, subtract the numerical value corresponding to the current character, otherwise add the numerical value corresponding to the current character.
70
+
71
+
The time complexity is $O(n)$ and the space complexity is $O(m)$. Where $n$ and $m$ are the lengths of the string $s$ and the size of the character set, respectively.
0 commit comments