[leetcode, JS] 2833. Furthest Point From Origin

mxxn·2024년 6월 17일
0

leetcode

목록 보기
182/198

문제

문제 링크 : Furthest Point From Origin

풀이

/**
 * @param {string} moves
 * @return {number}
 */
var furthestDistanceFromOrigin = function(moves) {
    let move = 0
    let any = 0
    for(let el of moves) {
        if(el === 'R') {
            move++
        }else if(el === 'L') {
            move--
        }else{
            any ++
        }
    }

    return Math.abs(move)+any
};
  1. 가장 멀리 갈 수 지점을 도출해내는 문제
  2. R과 L의 차이를 구해서 절대값을 만들고, '_'의 개수를 더한 값을 return
  • Runtime 72 ms, Memory 53.19 MB
profile
내일도 글쓰기

0개의 댓글