Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

Roman to Integer

var romanToInt = function (s) {

  const object = {
    'I': 1,
    'V': 5,
    'X': 10,
    'L': 50,
    'C': 100,
    'D': 500,
    'M': 1000
  }
  let count =0
  console.log(object)
 
 for(i =0; i<s.length;i++){
   const cur = object[s[i]]
   const next = object[s[i+1]]

 if(cur<next){
   count += next-cur
   i++
 }else{
   count+= cur
 }
}
return count

};
 
PREVIOUS NEXT
Tagged: #Roman #Integer
ADD COMMENT
Topic
Name
9+4 =