1.3k 1 分鐘

⭐️⭐️⭐️ # 題目敘述 You are given an integer array deck . There is a deck of cards where every card has a unique integer. The integer on the ith card is deck[i] . You can order the deck in any order you want. Initially, all the cards start face down (unrevealed) in one deck. You will do the following...
2.2k 2 分鐘

⭐️ # 題目敘述 The school cafeteria offers circular and square sandwiches at lunch break, referred to by numbers 0 and 1 respectively. All students stand in a queue. Each student either prefers square or circular sandwiches. The number of sandwiches in the cafeteria is equal to the number of students....
1.1k 1 分鐘

⭐️ # 題目敘述 Given a string s consisting of words and spaces, return the length of the last word in the string. A word is a maximal substring consisting of non-space characters only. Substring A substring is a contiguous non-empty sequence of characters within a string. # Example 1 Input: s =...
717 1 分鐘

⭐️⭐️⭐️⭐️ # 題目敘述 Given an unsorted integer array nums . Return the smallest positive integer that is not present in nums . You must implement an algorithm that runs in O(n) time and uses O(1) auxiliary space. # Example 1 Input: nums = [1,2,0] Output: 3 Explanation: The numbers in the range [1,2] are...
725 1 分鐘

⭐️⭐️⭐️ # 題目敘述 Given an integer array nums of length n where all the integers of nums are in the range [1, n] and each integer appears once or twice, return an array of all the integers that appears twice. You must write an algorithm that runs in O(n) time and uses only constant extra space. #...
1k 1 分鐘

⭐️⭐️⭐️ # 題目敘述 You are given the head of a singly linked-list. The list can be represented as: L0 → L1 → … → Ln - 1 → Ln Reorder the list to be on the following form: L0 → Ln → L1 → Ln - 1 → L2 → Ln - 2 → … You may not modify the values in the list's nodes. Only nodes themselves may be...
825 1 分鐘

⭐️ # 題目敘述 Given the head of a singly linked list, return true if it is a palindrome or false otherwise. palindrome A palindrome is a sequence that reads the same forward and backward. # Example 1 Input: head = [1,2,2,1] Output: true # Example 2 Input: head = [1,2] Output: false ListNode 的...
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...