<pre>class Solution { public: int romanToInt(string S) { int ans = 0, num = 0; for (int i = S.size()-1; ~i; i--) { switch(S[i]) { case 'I': num = 1; break; case 'V': num = 5; break; case 'X': num = 10; break; case 'L': num = 50; break; case 'C': num = 100; break; case 'D': num = 500; break; case 'M': num = 1000; break; } if (4 * num < ans) ans -= num; else ans += num; } return ans; } };
Quote:I am reading a code and unable to understand ~i in code
i != 0
for (int i = S.size() - 1; i >= 0; i--) { 00A17B45 83 E8 01 sub eax,1 00A17B48 89 45 D4 mov dword ptr [ebp-2Ch],eax 00A17B4B 83 7D D4 00 cmp dword ptr [ebp-2Ch],0 00A17B4F 0F 8C A2 00 00 00 jl $LN13+2Bh (0A17BF7h)
for (int i = S.size() - 1; ~i; i--) { 00A07B45 83 E8 01 sub eax,1 00A07B48 89 45 D4 mov dword ptr [ebp-2Ch],eax 00A07B4B 8B 45 D4 mov eax,dword ptr [ebp-2Ch] 00A07B4E F7 D0 not eax 00A07B50 85 C0 test eax,eax 00A07B52 0F 84 A2 00 00 00 je $LN13+2Bh (0A07BFAh)
~(-1)
~0
false
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)