2.3k 2 分鐘

⭐️ # 題目敘述 Given an asyncronous function fn and a time t in milliseconds, return a new time limited version of the input function. A time limited function is a function that is identical to the original unless it takes longer than t milliseconds to fullfill. In that case, it will reject with...
928 1 分鐘

⭐️⭐️⭐️ # 題目敘述 Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list's nodes (i.e., only nodes themselves may be changed.) # Example 1 Input: head = [1,2,3,4] Output: [2,1,4,3] # Example 2 Input: head =...
842 1 分鐘

⭐️ # 題目敘述 Given a positive integer millis , write an asyncronous function that sleeps for millis milliseconds. It can resolve any value. # Example 1 Input: millis = 100 Output: 100 Explanation: It should return a promise that resolves after 100ms. let t = Date.now(); sleep(100).then(() =>...
854 1 分鐘

⭐️⭐️⭐️ # 題目敘述 You are given the head of a linked list, and an integer k . Return the head of the linked list after swapping the values of the kth node from the beginning and the kth node from the end (the list is 1-indexed). # Example 1 Input: head = [1,2,3,4,5], k = 2 Output: [1,4,3,2,5] #...
1.4k 1 分鐘

⭐️ # 題目敘述 Given a function fn , return a new function that is identical to the original function except that it ensures fn is called at most once. The first time the returned function is called, it should return the same result as fn . Every subsequent time it is called, it should return undefined...
1.7k 2 分鐘

⭐️ # 題目敘述 You are given a 0-indexed 2D integer array questions where questions[i] = [pointsi, brainpoweri] . The array describes the questions of an exam, where you have to process the questions in order (i.e., starting from question 0 ) and make a decision whether to solve or skip each question....
1.2k 1 分鐘

⭐️ # 題目敘述 Given an array of functions [f1, f2, f3, ..., fn] , return a new function fn that is the function composition of the array of functions. The function composition of [f(x), g(x), h(x)] is fn(x) = f(g(h(x))) . The function composition of an empty list of functions is the identity function...
1.2k 1 分鐘

⭐️⭐️⭐️ # 題目敘述 You are given two integer arrays nums1 and nums2 . We write the integers of nums1 and nums2 (in the order they are given) on two separate horizontal lines. We may draw connecting lines: a straight line connecting two numbers nums1[i] and nums2[j] such that: nums1[i] == nums2[j] ,...
1.4k 1 分鐘

⭐️ # 題目敘述 Given an integer array nums , a reducer function fn , and an initial value init , return a reduced array. A reduced array is created by applying the following operation: val = fn(init, nums[0]) , val = fn(val, nums[1]) , val = fn(val, nums[2]) , ... until every element in the array has...
754 1 分鐘

⭐️ # 題目敘述 Given a positive integer n , generate an n x n matrix filled with elements from 1 to n^2 in spiral order. # Example 1: Input: n = 3 Output: [[1,2,3],[8,9,4],[7,6,5]] # Example 2: Input: n = 1 Output: [[1]] # 解題思路 # Solution class Solution { public int[][] generateMatrix(int...