JavaScript solution - switch left and right position


  • 0
    I
    function reverse(n){
      var m = n.toString().split('')
      var i = 0
      while (i < m.length/2){
        var left = m[i]
        m[i] = m[m.length-1-i]
        m[m.length-1-i] = left
        i++
      }
      m = parseInt(m.join(''))
      return m 
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.