718 1 分鐘

⭐️ # 題目敘述 Given the head of a singly linked list, reverse the list, and return the reversed list. # Example 1 Input: head = [1,2,3,4,5] Output: [5,4,3,2,1] # Example 2 Input: head = [1,2] Output: [2,1] # Example 3 Input: head = [] Output: [] ListNode 的 class 內容 ListNode// Definition for...
1.3k 1 分鐘

⭐️⭐️ # 題目敘述 You are given two linked lists: list1 and list2 of sizes n and m respectively. Remove list1 's nodes from the ath node to the bth node, and put list2 in their place. The blue edges and nodes in the following figure indicate the result: Build the result list and return its head. #...
1.9k 2 分鐘

⭐️⭐️⭐️ # 題目敘述 You are given an array of CPU tasks , each represented by letters A to Z, and a cooling time, n . Each cycle or interval allows the completion of one task. Tasks can be completed in any order, but there's a constraint: identical tasks must be separated by at least n intervals due...
2.1k 2 分鐘

⭐️⭐️⭐️ # 題目敘述 There are some spherical balloons taped onto a flat wall that represents the XY-plane. The balloons are represented as a 2D integer array points where points[i] = [xstart, xend] denotes a balloon whose horizontal diameter stretches between xstart and xend . You do not know the exact...
2.1k 2 分鐘

⭐️⭐️ # 題目敘述 You are given an array of non-overlapping intervals intervals where intervals[i] = [starti, endi] represent the start and the end of the ith interval and intervals is sorted in ascending order by starti . You are also given an interval newInterval = [start, end] that represents the start...
823 1 分鐘

⭐️ # 題目敘述 Given a binary array nums , return the maximum length of a contiguous subarray with an equal number of 0 and 1 . # Example 1 Input: nums = [0,1] Output: 2 Explanation: [0, 1] is the longest contiguous subarray with an equal number of 0 and 1. # Example 2 Input: nums = [0,1,0] Output:...
791 1 分鐘

⭐️⭐️ # 題目敘述 Given an integer array nums , return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i] . The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer. You must write an algorithm that runs in O(n) time and...
808 1 分鐘

⭐️⭐️⭐️ # 題目敘述 Given a binary array nums and an integer goal , return the number of non-empty subarrays with a sum goal . A subarray is a contiguous part of the array. # Example 1 Input: nums = [1,0,1,0,1], goal = 2 Output: 4 Explanation: The 4 subarrays are bolded and underlined...
1.4k 1 分鐘

⭐️⭐️⭐️ # 題目敘述 Given the head of a linked list, we repeatedly delete consecutive sequences of nodes that sum to 0 until there are no such sequences. After doing so, return the head of the final linked list. You may return any such answer. (Note that in the examples below, all sequences are...
2k 2 分鐘

⭐️⭐️⭐️ # 題目敘述 You are given two strings order and s . All the characters of order are unique and were sorted in some custom order previously. Permute the characters of s so that they match the order that order was sorted. More specifically, if a character x occurs before a character y in order ,...