My code in Java (Dumb but worked)

import java.lang.*;

class Solution {

int value(char r){

if (r=='I') return 1;

if (r=='V') return 5;

if (r=='X') return 10;

if (r=='L') return 50;

if (r=='C') return 100;

if (r=='D') return 500;

if (r=='M') return 1000;

return -1;

}

public int romanToInt(String s) {

int i=0;

int res =0;

while (i<s.length()){

if(i<s.length()-1){

if(value(s.charAt(i))<value(s.charAt(i+1))){

res=res+value(s.charAt(i+1))-value(s.charAt(i));

i++;

}else{

res=res+value(s.charAt(i));

}

}else{

res= res+ value(s.charAt(i));

}

i++;

}

return res;

}

}

Roman to Integer