[LeetCode] 3028. Ant on the Boundary

Chobby·2025년 12월 17일

LeetCode

목록 보기
842/981

😎풀이

  1. 개미의 움직임 탐색
    1-1. 이동한 거리를 모두 누적
    1-2. 원점(0)으로 돌아온 경우 카운트
  2. 개미가 원점으로 돌아온 횟수 반환
function returnToBoundaryCount(nums: number[]): number {
    let curPos = 0
    let boundaryCount = 0
    for(const move of nums) {
        curPos += move
        if(curPos === 0) boundaryCount++
    }
    return boundaryCount
};
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글