After I found the fact that: **a roman numeral is essentially an implicit binary tree**, I came out a solution of pre-order traversing on it.

It is not the fastest one, however I share it here to inspire you with a (maybe) new thought about roman numerals.

```
const char *lst = "MDCLXVI";
const int cnv[128] = {['I'] = 1, ['V'] = 5, ['X'] = 10, ['L'] = 50, ['C'] = 100, ['D'] = 500, ['M'] = 1000};
int romanToInt(char* s) {
char *p = lst;
for(; *p; p++){
char *q = strchr(s, *p);
if(!q) continue;
*q = '\0';
return -romanToInt(s) + cnv[*p] + romanToInt(q + 1);
}
return 0;
}
```

The function finds the first occurrence of the letter with maximum value, treat it as the root of the tree.

Then the answer should be: the value of the root charcter, **plus** the right subtree, **minus** the left subtree.

The recursion stops while it could not find any valid character (essentially empty string).

For example, MCMIV(1904) is [M,C,M,#,#,#,V,I] in binary tree representation (see also leetcode FAQ).