array

    LeetCode / Array / 260번 / Single Number ||| / JS

    정수 배열인 nums 배열이 주어진다.모든 수는 2번씩 나타나는데, 딱 두개의 수만 1번씩만 나타난다.이 두개의 수를 배열로 반환하는 문제이다. /** * @param {number[]} nums * @return {number[]} */var singleNumber = function (nums) { const count = {}; nums.forEach((num) => { count[num] = count[num] + 1 || 1; }); const result = []; for (const num in count) { const countOfNum = count[num]; if (countOfNum === 1) { result.push(num); } } r..

    LeetCode / Array / 1442번 / Count Triplets That Can Form Two Arrays of Equal XOR / JS

    정수로 이루어진 배열 arr가 주어진다.3개의 index가 주어지는데, 각각 i, j, k라고 하자. 이들은 다음과 같은 상관관계를 갖는다.0 그리고 우리는 이것을 이용해서 a와 b를 찾아야한다. a와 b는 다음과 같다.a = arr[i] ^ arr[i+1] ^ ... ^ arr[j-1]b = arr[j] ^ arr[j+1] ^ ... ^ arr[k]여기서 ^는 bitwise-xor 이다. a와 b가 같게되는 i, j, k쌍의 개수가 몇개인지 반환하면 되는 문제이다. 1 1  1. 실패 코드 - 시간 초과/** * @param {number[]} arr * @return {number} */var countTriplets = function(arr) { const len = arr.length; ..

    LeetCode / Array / 661번 / Image Smoother / JS

    Image Smoother - LeetCode Can you solve this real interview question? Image Smoother - An image smoother is a filter of the size 3 x 3 that can be applied to each cell of an image by rounding down the average of the cell and the eight surrounding cells (i.e., the average of the nin leetcode.com 이미지에 3*3의 필터를 씌워서 부드럽게 만드는 문제이다. 예를 들어 (i, j)의 셀을 부드럽게 만드려면, (i, j)를 중심으로 3*3의..

    LeetCode / Array / 1582번 / Special Positions in a Binary Matrix / JS

    Special Positions in a Binary Matrix - LeetCode Can you solve this real interview question? Special Positions in a Binary Matrix - Given an m x n binary matrix mat, return the number of special positions in mat. A position (i, j) is called special if mat[i][j] == 1 and all other elements in row i and co leetcode.com 2차원 배열에서 (i, j)의 값이 1이라면, 같은 행과 같은 열에 1이 (i, j)에만 존재했을 때..

    LeetCode / Array / 2090번 / K Radius Subarray Averages / JS

    K Radius Subarray Averages - LeetCode Can you solve this real interview question? K Radius Subarray Averages - You are given a 0-indexed array nums of n integers, and an integer k. The k-radius average for a subarray of nums centered at some index i with the radius k is the average of all elem leetcode.com 어떤 원이 k만큼의 반지름을 가질 때, 인덱스 하나마다 해당하는 요소를 중심으로 가질 때, 그 안에 들어오는 배열의 요..

    LeetCode / Array / 1732번 / Find the Highest Altitude / JS

    Find the Highest Altitude - LeetCode Can you solve this real interview question? Find the Highest Altitude - There is a biker going on a road trip. The road trip consists of n + 1 points at different altitudes. The biker starts his trip on point 0 with altitude equal 0. You are given an integ leetcode.com 고도들이 배열로 주어지는데, 고도들을 따라 계속해서 이동했을 때(누적 합), 가장 고도가 높은 곳의 고도를 반환하면 된다..