395 1 分鐘

⭐️ # 題目敘述 Given an integer n , return true if it is a power of two. Otherwise, return false . An integer n is a power of two, if there exists an integer x such that n == 2^x . # Example 1 Input: n = 1 Output: true Explanation: 20 = 1 # Example 2 Input: n = 16 Output: true Explanation: 24 = 16 #...
1.2k 1 分鐘

⭐️⭐️ # 題目敘述 You are given a 0-indexed integer array nums of even length consisting of an equal number of positive and negative integers. You should rearrange the elements of nums such that the modified array follows the given conditions: Every consecutive pair of integers have opposite signs. For...
1.2k 1 分鐘

⭐️ # 題目敘述 Given an array of strings words , return the first palindromic string in the array. If there is no such string, return an empty string "" . A string is palindromic if it reads the same forward and backward. # Example 1 Input: words =...
622 1 分鐘

⭐️ # 題目敘述 Given an array nums of size n , return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array. # Example 1 Input: nums = [3,2,3] Output: 3 # Example 2 Input: nums =...
680 1 分鐘

⭐️⭐️⭐️ # 題目敘述 Given an integer n , return the least number of perfect square numbers that sum to n . A perfect square is an integer that is the square of an integer; in other words, it is the product of some integer with itself. For example, 1 , 4 , 9 , and 16 are perfect squares while 3 and 11 are...
1.5k 1 分鐘

⭐️⭐️⭐️ # 題目敘述 Given a string s , sort it in decreasing order based on the frequency of the characters. The frequency of a character is the number of times it appears in the string. Return the sorted string. If there are multiple answers, return any of them. # Example 1 Input: s =...
629 1 分鐘

⭐️ # 題目敘述 Given a string s , find the first non-repeating character in it and return its index. If it does not exist, return -1 . # Example 1 Input: s = "leetcode" Output: 0 # Example 2 Input: s = "loveleetcode" Output: 2 # Example 3 Input: s =...
892 1 分鐘

⭐️⭐️⭐️ # 題目敘述 Given an integer array arr , partition the array into (contiguous) subarrays of length at most k . After partitioning, each subarray has their values changed to become the maximum value of that subarray. Return the largest sum of the given array after partitioning. Test cases are...