[Leetcode] Sort Array By Parity - 자바스크립트, JavaScript

Jin·2023년 2월 28일

Algorithm

목록 보기
9/13

문제

내 풀이

var sortArrayByParity = function (nums) {
  const evens = [];
  const odds = [];

  nums.forEach(v => {
    if (v % 2 === 0) evens.push(v);
    else odds.push(v);
  });

  return [...evens, ...odds];
};
  • Your runtime beats 87.23 % of javascript submissions.
profile
Nothing changes if nothing changes

0개의 댓글