1.2k 1 分鐘

⭐️ # 題目敘述 Given an integer array arr and a filtering function fn , return a new array with a fewer or equal number of elements. The returned array should only contain elements where fn(arr[i], i) evaluated to a truthy value. Please solve it without the built-in Array.filter method. # Example...
986 1 分鐘

⭐️⭐️⭐️ # 題目敘述 Given an m x n matrix , return all elements of the matrix in spiral order. # Example 1: Input: matrix = [[1,2,3],[4,5,6],[7,8,9]] Output: [1,2,3,6,9,8,7,4,5] # Example 2: Input: matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]] Output: [1,2,3,4,8,12,11,10,9,5,6,7] # 解題思路 #...
993 1 分鐘

⭐️ # 題目敘述 Given an integer array arr and a mapping function fn , return a new array with a transformation applied to each element. The returned array should be created such that returnedArray[i] = fn(arr[i], i) . Please solve it without the built-in Array.map method. # Example 1: Input: arr =...
678 1 分鐘

⭐️⭐️ # 題目敘述 Given a square matrix mat , return the sum of the matrix diagonals. Only include the sum of all the elements on the primary diagonal and all the elements on the secondary diagonal that are not part of the primary diagonal. # Example 1: Input: mat = [[1,2,3], [4,5,6], [7,8,9]] Output:...
1.7k 2 分鐘

⭐️ # 題目敘述 Write a function createCounter . It should accept an initial integer init . It should return an object with three functions. The three functions are: increment() increases the current value by 1 and then returns it. decrement() reduces the current value by 1 and then returns it. reset()...
1.8k 2 分鐘

⭐️⭐️⭐️⭐️⭐️ # 題目敘述 You want to build some obstacle courses. You are given a 0-indexed integer array obstacles of length n , where obstacles[i] describes the height of the ith obstacle. For every index i between 0 and n - 1 (inclusive), find the length of the longest obstacle course in obstacles such...
1.2k 1 分鐘

⭐️⭐️⭐️ # 題目敘述 You are given an array of integers nums and an integer target . Return the number of non-empty subsequences of nums such that the sum of the minimum and maximum element on it is less or equal to target . Since the answer may be too large, return it modulo 10^9 + 7 . # Example...
1.1k 1 分鐘

⭐️ # 題目敘述 Given an integer n , return a counter function. This counter function initially returns n and then returns 1 more than the previous value every subsequent time it is called ( n , n + 1 , n + 2 , etc). # Example 1: Input: n =...
894 1 分鐘

⭐️ # 題目敘述 Write a function createHelloWorld . It should return a new function that always returns "Hello World" . # Example 1: Input: args = [] Output: "Hello World" Explanation: const f = createHelloWorld(); f(); // "Hello World" The function...