diff --git a/books/July_2025.md b/books/July_2025.md index 5a1476b..e9dfcfc 100644 --- a/books/July_2025.md +++ b/books/July_2025.md @@ -57,7 +57,7 @@ Explanation: - Query [1,1]: Station 1 is offline and there are no other stations in its grid, so the result is -1. **Constraints** -```text +```tex 1 <= c <= 10^5 0 <= n == connections.length <= min(10^5, c * (c - 1) / 2) connections[i].length == 2 @@ -346,7 +346,7 @@ There is only one horizontal trapezoid that can be formed. **Constraints** -```text +```tex 4 <= points.length <= 10^5 -10^8 <= x_i, y_i <= 10^8 All points are pairwise distinct. @@ -414,7 +414,7 @@ Suppose points = [[1,0],[2,0],[3,0],[2,2],[3,2]] - **Time Complexity:** O(N + K), where N is the number of points and K is the number of y-levels with at least 2 points. - **Space Complexity:** O(N) for storing the groups. -```text +```tex | Step | Operation | Count | | ---- | ----------------- | ----- | | 1 | Group points by y | N | diff --git a/books/Random.md b/books/Random.md index 7664c1c..873e4cb 100644 --- a/books/Random.md +++ b/books/Random.md @@ -85,7 +85,7 @@ You are given two non-empty linked lists representing two non-negative integers. You may assume the two numbers do not contain any leading zero, except the number 0 itself. Example: -```text +```tex Input: l1 = [2,4,3], l2 = [5,6,4] Output: [7,0,8] Explanation: 342 + 465 = 807. @@ -98,7 +98,7 @@ Output: [8,9,9,9,0,0,0,1] ``` Constraints: -```text +```tex The number of nodes in each linked list is in the range [1, 100]. 0 <= Node.val <= 9 It is guaranteed that the list represents a number that does not have leading zeros. @@ -1018,7 +1018,7 @@ word2: p q merged: a p b q c d **Constraints** -```text +```tex - 1 <= word1.length, word2.length <= 100 - word1 and word2 consist of lowercase English letters. ``` @@ -1313,7 +1313,7 @@ Return the *sum* of the complete subset with the *maximum sum*. **Constraints** -```text +```tex 1 <= n == nums.length <= 10^4 1 <= nums[i] <= 10^9 ``` @@ -1432,7 +1432,7 @@ Explanation: - Query [1,1]: Station 1 is offline and there are no other stations in its grid, so the result is -1. **Constraints** -```text +```tex 1 <= c <= 10^5 0 <= n == connections.length <= min(10^5, c * (c - 1) / 2) connections[i].length == 2 @@ -1721,7 +1721,7 @@ There is only one horizontal trapezoid that can be formed. **Constraints** -```text +```tex 4 <= points.length <= 10^5 -10^8 <= x_i, y_i <= 10^8 All points are pairwise distinct. @@ -1789,7 +1789,7 @@ Suppose points = [[1,0],[2,0],[3,0],[2,2],[3,2]] - **Time Complexity:** O(N + K), where N is the number of points and K is the number of y-levels with at least 2 points. - **Space Complexity:** O(N) for storing the groups. -```text +```tex | Step | Operation | Count | | ---- | ----------------- | ----- | | 1 | Group points by y | N | diff --git a/books/Visualization.md b/books/Visualization.md index 11ac136..47033bc 100644 --- a/books/Visualization.md +++ b/books/Visualization.md @@ -149,7 +149,7 @@ word2: p q merged: a p b q c d **Constraints** -```text +```tex - 1 <= word1.length, word2.length <= 100 - word1 and word2 consist of lowercase English letters. ``` @@ -414,7 +414,7 @@ There is only one horizontal trapezoid that can be formed. **Constraints** -```text +```tex 4 <= points.length <= 10^5 -10^8 <= x_i, y_i <= 10^8 All points are pairwise distinct. @@ -482,7 +482,7 @@ Suppose points = [[1,0],[2,0],[3,0],[2,2],[3,2]] - **Time Complexity:** O(N + K), where N is the number of points and K is the number of y-levels with at least 2 points. - **Space Complexity:** O(N) for storing the groups. -```text +```tex | Step | Operation | Count | | ---- | ----------------- | ----- | | 1 | Group points by y | N | diff --git a/data/book-sets.json b/data/book-sets.json index 19d8153..936c9da 100644 --- a/data/book-sets.json +++ b/data/book-sets.json @@ -32,7 +32,7 @@ "tags": [], "problems": [ 1, 2, 11, 12, 13, 14, 15, 17, 19, 20, 21, 22, 23, 25, 26, 27, 28, 30, 31, 33, 34, 35, 36, 39, 42, 45, 46, 48, 49, 50, 52, 53, 54, 55, 56, 57, - 58, 61, 63, 64, 66, 67, 68, 69, 70, 71, 73, 76, 77, 79, 80, 82, 86, 88, 92, 97, 98, 125, 138, 139, 141, 146, 148, 149, 150, 151, 153, 155, 162, + 58, 61, 63, 64, 66, 67, 68, 69, 70, 71, 73, 76, 77, 79, 80, 82, 86, 88, 92, 97, 98, 125, 136, 138, 139, 141, 146, 148, 149, 150, 151, 153, 155, 162, 167, 169, 172, 173, 188, 189, 190, 191, 198, 199, 200, 201, 202, 205, 207, 208, 209, 210, 211, 212, 215, 217, 221, 222, 224, 226, 228, 230, 238, 242, 268, 274, 283, 289, 290, 295, 300, 334, 344, 345, 373, 380, 383, 392, 399, 427, 433, 443, 452, 502, 530, 605, 637, 643, 647, 739, 901, 909, 918, 1004, 1071, 1207, 1431, 1456, 1657, 1679, 1732, 1768, 1798, 1957, 1991, 2215, 2352, 2862, 3424, 3602, 3603, 3604, 3605, 3606, 3607, 3608, diff --git a/explanations/1/en.md b/explanations/1/en.md index 00b8acf..c735d3d 100644 --- a/explanations/1/en.md +++ b/explanations/1/en.md @@ -12,7 +12,7 @@ You can return the answer in any order. Examples: -```text +```tex Input: nums = [2,7,11,15], target = 9 Output: [0,1] Explanation: Because nums[0] + nums[1] == 9, we return [0, 1]. @@ -26,7 +26,7 @@ Output: [0,1] Constraints: -```text +```tex 2 <= nums.length <= 10^4 -10^9 <= nums[i] <= 10^9 -10^9 <= target <= 10^9 diff --git a/explanations/1071/en.md b/explanations/1071/en.md index 3b48f08..8c5c383 100644 --- a/explanations/1071/en.md +++ b/explanations/1071/en.md @@ -8,7 +8,7 @@ For two strings `s` and `t`, we say "t divides s" if and only if `s = t + t + .. Given two strings `str1` and `str2`, return the largest string `x` such that `x` divides both `str1` and `str2`. **Examples** -```text +```tex Input: str1 = "ABCABC", str2 = "ABC" Output: "ABC" diff --git a/explanations/125/en.md b/explanations/125/en.md index fef58d1..e8c9cb1 100644 --- a/explanations/125/en.md +++ b/explanations/125/en.md @@ -6,7 +6,7 @@ A phrase is a palindrome if, after converting all uppercase letters into lowerca Given a string `s`, return `true` if it is a palindrome, or `false` otherwise. **Examples** -```text +```tex Example 1: Input: s = "A man, a plan, a canal: Panama" Output: true @@ -25,7 +25,7 @@ An empty string is a palindrome. ``` **Constraints:** -```text +```tex 1 <= s.length <= 2 * 10^5 s consists only of printable ASCII characters. ``` diff --git a/explanations/136/en.md b/explanations/136/en.md new file mode 100644 index 0000000..5bacf43 --- /dev/null +++ b/explanations/136/en.md @@ -0,0 +1,92 @@ +Given a **non-empty** array of integers `nums`, every element appears *twice* except for one. Find that single one. + +You must implement a solution with a linear runtime complexity and use only constant extra space. + +**Example 1:** +```sh +Input: nums = [2,2,1] +Output: 1 +``` + +**Example 2:** +```sh +Input: nums = [4,1,2,1,2] +Output: 4 +``` + +**Example 3:** +```sh +Input: nums = [1] +Output: 1 +``` + +**Constraints:** +- `1 <= nums.length <= 3 * 10^4` +- `-3 * 10^4 <= nums[i] <= 3 * 10^4` +- Each element in the array appears twice except for one element which appears only once. + +## Explanation + +### Strategy + +This is a **bit manipulation problem** that requires finding the single element in an array where all other elements appear twice. The key insight is to use the XOR (exclusive or) operation, which has special properties that make it perfect for this problem. + +**Key observations:** +- XOR of a number with itself is 0: `a ^ a = 0` +- XOR of a number with 0 is the number itself: `a ^ 0 = a` +- XOR is associative and commutative: `a ^ b ^ a = (a ^ a) ^ b = 0 ^ b = b` +- All elements appear twice except one, so XORing all elements will cancel out the pairs + +**High-level approach:** +1. **Initialize result**: Start with `result = 0` +2. **XOR all elements**: Iterate through the array and XOR each element with the result +3. **Return result**: The final result will be the single number + +### Steps + +Let's break down the solution step by step: + +**Step 1: Initialize result** +- Start with `result = 0` + +**Step 2: XOR all elements** +For each number in the array: +- XOR the current number with the result: `result = result ^ num` +- This will cancel out pairs and leave the single number + +**Step 3: Return the result** +- The final result is the single number + +**Example walkthrough:** +Let's trace through the second example: + +```sh +nums = [4,1,2,1,2] + +Initial state: +result = 0 + +Step 1: result = 0 ^ 4 = 4 + +Step 2: result = 4 ^ 1 = 5 + +Step 3: result = 5 ^ 2 = 7 + +Step 4: result = 7 ^ 1 = 6 + +Step 5: result = 6 ^ 2 = 4 + +Result: Return 4 +``` + +**Why this works:** +- `4 ^ 1 ^ 2 ^ 1 ^ 2` +- `= 4 ^ (1 ^ 1) ^ (2 ^ 2)` +- `= 4 ^ 0 ^ 0` +- `= 4 ^ 0` +- `= 4` + +> **Note:** The XOR operation is perfect for this problem because it has the property that `a ^ a = 0` and `a ^ 0 = a`. This means that when you XOR all numbers, pairs of identical numbers will cancel out to 0, leaving only the single number. + +**Time Complexity:** O(n) - you visit each element exactly once +**Space Complexity:** O(1) - you only use a constant amount of extra space \ No newline at end of file diff --git a/explanations/14/en.md b/explanations/14/en.md index 64e4dec..c888528 100644 --- a/explanations/14/en.md +++ b/explanations/14/en.md @@ -9,7 +9,7 @@ Write a function to find the longest common prefix string amongst an array of st If there is no common prefix, return an empty string `""`. **Examples** -```text +```tex Example 1: Input: strs = ["flower","flow","flight"] Output: "fl" @@ -21,7 +21,7 @@ Explanation: There is no common prefix among the input strings. ``` **Constraints:** -```text +```tex 1 <= strs.length <= 200 0 <= strs[i].length <= 200 strs[i] consists of only lowercase English letters if it is non-empty. diff --git a/explanations/1431/en.md b/explanations/1431/en.md index 30c9f2f..2ec9c8f 100644 --- a/explanations/1431/en.md +++ b/explanations/1431/en.md @@ -11,7 +11,7 @@ Note that multiple kids can have the greatest number of candies. **Examples** -```text +```tex Input: candies = [2,3,5,1,3], extraCandies = 3 Output: [true,true,true,false,true] Explanation: If you give all extraCandies to: @@ -30,7 +30,7 @@ Output: [true,false,true] **Constraints** -```text +```tex - n == candies.length - 2 <= n <= 100 - 1 <= candies[i] <= 100 diff --git a/explanations/1456/en.md b/explanations/1456/en.md index 547d972..c9d449b 100644 --- a/explanations/1456/en.md +++ b/explanations/1456/en.md @@ -23,7 +23,7 @@ Explanation: "lee", "eet" and "ode" contain 2 vowels. ``` **Constraints** -```text +```tex - 1 <= s.length <= 10^5 - s consists of lowercase English letters. - 1 <= k <= s.length diff --git a/explanations/151/en.md b/explanations/151/en.md index 28deadc..fd7bb1a 100644 --- a/explanations/151/en.md +++ b/explanations/151/en.md @@ -13,7 +13,7 @@ Note that `s` may contain leading or trailing spaces or multiple spaces between **Examples** -```text +```tex Input: s = "the sky is blue" Output: "blue is sky the" @@ -27,7 +27,7 @@ Explanation: You need to reduce multiple spaces between two words to a single sp ``` **Constraints** -```text +```tex 1 <= s.length <= 10^4 s contains English letters (upper-case and lower-case), digits, and spaces ' '. There is at least one word in s. diff --git a/explanations/169/en.md b/explanations/169/en.md index 895b83b..4c286aa 100644 --- a/explanations/169/en.md +++ b/explanations/169/en.md @@ -8,7 +8,7 @@ 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. **Examples** -```text +```tex Example 1: Input: nums = [3,2,3] Output: 3 @@ -19,7 +19,7 @@ Output: 2 ``` **Constraints:** -```text +```tex n == nums.length 1 <= n <= 5 * 10^4 -10^9 <= nums[i] <= 10^9 diff --git a/explanations/1768/en.md b/explanations/1768/en.md index e1feae4..41577f7 100644 --- a/explanations/1768/en.md +++ b/explanations/1768/en.md @@ -8,7 +8,7 @@ You are given two strings, word1 and word2. Merge the strings by adding letters Return the merged string. **Examples** -```text +```tex Input: word1 = "abc", word2 = "pqr" Output: "apbqcr" Explanation: The merged string will be merged as so: @@ -32,7 +32,7 @@ merged: a p b q c d ``` **Constraints** -```text +```tex - 1 <= word1.length, word2.length <= 100 - word1 and word2 consist of lowercase English letters. ``` diff --git a/explanations/1957/en.md b/explanations/1957/en.md index 0c90502..7f4aa52 100644 --- a/explanations/1957/en.md +++ b/explanations/1957/en.md @@ -13,7 +13,7 @@ Return the final string after the deletion. It can be shown that the answer will **Examples** -```text +```tex Input: s = "leeetcode" Output: "leetcode" Explanation: Remove an 'e' from the first group of 'e's to create "leetcode". No three consecutive characters are equal, so return "leetcode". @@ -29,7 +29,7 @@ Explanation: No three consecutive characters are equal, so return "aab". **Constraints** -```text +```tex 1 <= s.length <= 10^5 s consists only of lowercase English letters. ``` diff --git a/explanations/1991/en.md b/explanations/1991/en.md index c184861..6f747af 100644 --- a/explanations/1991/en.md +++ b/explanations/1991/en.md @@ -6,7 +6,7 @@ https://leetcode.com/problems/find-the-middle-index-in-array Given a 0-indexed integer array nums, find the leftmost middleIndex such that the sum of the numbers to the left of middleIndex is equal to the sum of the numbers to the right of middleIndex. Return -1 if no such index exists. **Examples** -```text +```tex Input: nums = [2,3,-1,8,4] Output: 3 Explanation: The sum of the numbers to the left of index 3 is 4 (2+3-1), and to the right is also 4 (4). @@ -21,7 +21,7 @@ Explanation: There is no valid middleIndex. ``` **Constraints** -```text +```tex - 1 <= nums.length <= 100 - -1000 <= nums[i] <= 1000 ``` diff --git a/explanations/2/en.md b/explanations/2/en.md index 99b7361..e37a7cb 100644 --- a/explanations/2/en.md +++ b/explanations/2/en.md @@ -9,7 +9,7 @@ You are given two non-empty linked lists representing two non-negative integers. You may assume the two numbers do not contain any leading zero, except the number 0 itself. Example: -```text +```tex Input: l1 = [2,4,3], l2 = [5,6,4] Output: [7,0,8] Explanation: 342 + 465 = 807. @@ -22,7 +22,7 @@ Output: [8,9,9,9,0,0,0,1] ``` Constraints: -```text +```tex The number of nodes in each linked list is in the range [1, 100]. 0 <= Node.val <= 9 It is guaranteed that the list represents a number that does not have leading zeros. diff --git a/explanations/217/en.md b/explanations/217/en.md index 5b5f592..4ab48bb 100644 --- a/explanations/217/en.md +++ b/explanations/217/en.md @@ -5,7 +5,7 @@ https://leetcode.com/problems/contains-duplicate/ Given an integer array `nums`, return `true` if any value appears at least twice in the array, and return `false` if every element is distinct. **Examples** -```text +```tex Example 1: Input: nums = [1,2,3,1] Output: true @@ -21,7 +21,7 @@ Output: true **Constraints:** -```text +```tex 1 <= nums.length <= 10^5 -10^9 <= nums[i] <= 10^9 ``` diff --git a/explanations/219/en.md b/explanations/219/en.md index 059b204..dd86783 100644 --- a/explanations/219/en.md +++ b/explanations/219/en.md @@ -1,7 +1,7 @@ Given an integer array `nums` and an integer `k`, return `true` if there are two distinct indices `i` and `j` in the array such that `nums[i] == nums[j]` and `abs(i - j) <= k`. **Examples** -```text +```tex Example 1: Input: nums = [1,2,3,1], k = 3 Output: true @@ -16,7 +16,7 @@ Output: false ``` **Constraints:** -```text +```tex 1 <= nums.length <= 10^5 -10^9 <= nums[i] <= 10^9 0 <= k <= 10^5 diff --git a/explanations/238/en.md b/explanations/238/en.md index 0c506aa..cfb1e94 100644 --- a/explanations/238/en.md +++ b/explanations/238/en.md @@ -8,7 +8,7 @@ The product of any prefix or suffix of `nums` is guaranteed to fit in a 32-bit i You must write an algorithm that runs in `O(n)` time complexity and without using the division operation. **Examples** -```text +```tex Example 1: Input: nums = [1,2,3,4] Output: [24,12,8,6] @@ -19,7 +19,7 @@ Output: [0,0,9,0,0] ``` **Constraints:** -```text +```tex 2 <= nums.length <= 10^5 -30 <= nums[i] <= 30 The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer. diff --git a/explanations/2419/en.md b/explanations/2419/en.md index f55a1ad..1b2fc9b 100644 --- a/explanations/2419/en.md +++ b/explanations/2419/en.md @@ -11,7 +11,7 @@ The bitwise AND of an array is the bitwise AND of all the numbers in it. A **subarray** is a contiguous sequence of elements within an array. -```text +```tex Example 1: Input: nums = [1,2,3,3,2,2] @@ -25,7 +25,7 @@ Output: 1 Explanation: The maximum possible bitwise AND of a subarray is 4. The longest subarray with that value is [4], so we return 1. ``` -```text +```tex Constraints: 1 <= nums.length <= 10^5 1 <= nums[i] <= 10^6 ``` diff --git a/explanations/268/en.md b/explanations/268/en.md index 1cbbd6d..3794f07 100644 --- a/explanations/268/en.md +++ b/explanations/268/en.md @@ -4,7 +4,7 @@ https://leetcode.com/problems/missing-number/ Given an array `nums` containing `n` distinct numbers in the range `[0, n]`, return the only number in the range that is missing from the array. **Examples** -```text +```tex Example 1: Input: nums = [3,0,1] Output: 2 @@ -22,7 +22,7 @@ Explanation: n = 9 since there are 9 numbers, so all numbers are in the range [0 ``` **Constraints:** -```text +```tex n == nums.length 1 <= n <= 10^4 0 <= nums[i] <= n diff --git a/explanations/283/en.md b/explanations/283/en.md index 9b0588d..9b45ae1 100644 --- a/explanations/283/en.md +++ b/explanations/283/en.md @@ -8,7 +8,7 @@ Given an integer array nums, move all 0's to the end of it while maintaining the Note that you must do this in-place without making a copy of the array. **Examples** -```text +```tex Input: nums = [0,1,0,3,12] Output: [1,3,12,0,0] @@ -18,7 +18,7 @@ Output: [0] **Constraints** -```text +```tex - 1 <= nums.length <= 10^4 - -2^31 <= nums[i] <= 2^31 - 1 ``` diff --git a/explanations/2862/en.md b/explanations/2862/en.md index d08a79c..9144513 100644 --- a/explanations/2862/en.md +++ b/explanations/2862/en.md @@ -24,7 +24,7 @@ Return the *sum* of the complete subset with the *maximum sum*. **Constraints** -```text +```tex 1 <= n == nums.length <= 10^4 1 <= nums[i] <= 10^9 ``` diff --git a/explanations/31/en.md b/explanations/31/en.md index b10aa5a..bd12129 100644 --- a/explanations/31/en.md +++ b/explanations/31/en.md @@ -19,7 +19,7 @@ Given an array of integers `nums`, *find the next permutation of* `nums`. The replacement must be **in place** and use only constant extra memory. **Examples** -```text +```tex Example 1: Input: nums = [1,2,3] Output: [1,3,2] @@ -34,7 +34,7 @@ Output: [1,5,1] ``` **Constraints:** -```text +```tex 1 <= nums.length <= 100 0 <= nums[i] <= 100 ``` diff --git a/explanations/3424/en.md b/explanations/3424/en.md index 76ee6d8..ead946f 100644 --- a/explanations/3424/en.md +++ b/explanations/3424/en.md @@ -38,7 +38,7 @@ Since the arrays are already equal, no operations are needed, and the total cost **Constraints** -```text +```tex 1 <= arr.length == brr.length <= 10^5 0 <= k <= 2 * 10^10 -10^5 <= arr[i] <= 10^5 diff --git a/explanations/344/en.md b/explanations/344/en.md index 73d34de..a5804e6 100644 --- a/explanations/344/en.md +++ b/explanations/344/en.md @@ -6,7 +6,7 @@ Write a function that reverses a string. The input string is given as an array o You must do this by modifying the input array in-place with `O(1)` extra memory. **Examples** -```text +```tex Example 1: Input: s = ["h","e","l","l","o"] Output: ["o","l","l","e","h"] @@ -17,7 +17,7 @@ Output: ["h","a","n","n","a","H"] ``` **Constraints:** -```text +```tex 1 <= s.length <= 10^5 s[i] is a printable ASCII character. ``` diff --git a/explanations/345/en.md b/explanations/345/en.md index fb6e9a3..4363a7a 100644 --- a/explanations/345/en.md +++ b/explanations/345/en.md @@ -9,7 +9,7 @@ The vowels are `'a'`, `'e'`, `'i'`, `'o'`, and `'u'`, and they can appear in bot **Examples** -```text +```tex Input: s = "IceCreAm" Output: "AceCreIm" Explanation: The vowels in s are ['I', 'e', 'e', 'A']. On reversing the vowels, s becomes "AceCreIm". @@ -20,7 +20,7 @@ Output: "leotcede" **Constraints** -```text +```tex 1 <= s.length <= 3 * 10^5 s consist of printable ASCII characters. ``` diff --git a/explanations/35/en.md b/explanations/35/en.md index 2f89715..8fabf4c 100644 --- a/explanations/35/en.md +++ b/explanations/35/en.md @@ -6,7 +6,7 @@ Given a sorted array of distinct integers and a target value, return the index i You must write an algorithm with `O(log n)` runtime complexity. **Examples** -```text +```tex Example 1: Input: nums = [1,3,5,6], target = 5 Output: 2 @@ -21,7 +21,7 @@ Output: 4 ``` **Constraints:** -```text +```tex 1 <= nums.length <= 10^4 -10^4 <= nums[i] <= 10^4 nums contains distinct values sorted in ascending order. diff --git a/explanations/3602/en.md b/explanations/3602/en.md index 1c3d531..6b7edb0 100644 --- a/explanations/3602/en.md +++ b/explanations/3602/en.md @@ -15,7 +15,7 @@ A **hexatrigesimal** number is defined as a base-36 numeral system that uses the **Examples** **Example 1:** -```text +```tex Input: n = 13 Output: "A91P1" @@ -27,7 +27,7 @@ Explanation: ``` **Example 2:** -```text +```tex Input: n = 36 Output: "5101000" @@ -40,7 +40,7 @@ Explanation: **Constraints** -```text +```tex 1 <= n <= 1000 ``` diff --git a/explanations/3603/en.md b/explanations/3603/en.md index 63ec086..6d53dce 100644 --- a/explanations/3603/en.md +++ b/explanations/3603/en.md @@ -66,7 +66,7 @@ Explanation: ``` **Constraints** -```text +```tex 1 <= m, n <= 10^5 2 <= m * n <= 10^5 waitCost.length == m diff --git a/explanations/3607/en.md b/explanations/3607/en.md index 27cb44c..55c2dc5 100644 --- a/explanations/3607/en.md +++ b/explanations/3607/en.md @@ -48,7 +48,7 @@ Explanation: - Query [1,1]: Station 1 is offline and there are no other stations in its grid, so the result is -1. **Constraints** -```text +```tex 1 <= c <= 10^5 0 <= n == connections.length <= min(10^5, c * (c - 1) / 2) connections[i].length == 2 diff --git a/explanations/3622/en.md b/explanations/3622/en.md index 51d5b03..bca50b6 100644 --- a/explanations/3622/en.md +++ b/explanations/3622/en.md @@ -6,7 +6,7 @@ Return `true` if `n` is divisible by this sum; otherwise, return `false`. **Example 1:** -```text +```tex Input: n = 99 Output: true Explanation: @@ -16,7 +16,7 @@ the output is true. **Example 2:** -```text +```tex Input: n = 23 Output: false Explanation: @@ -27,7 +27,7 @@ the output is false. **Constraints:** -```text +```tex 1 <= n <= 10^6 ``` diff --git a/explanations/3623/en.md b/explanations/3623/en.md index 2bce790..ebb5759 100644 --- a/explanations/3623/en.md +++ b/explanations/3623/en.md @@ -44,7 +44,7 @@ There is only one horizontal trapezoid that can be formed. **Constraints** -```text +```tex 4 <= points.length <= 10^5 -10^8 <= x_i, y_i <= 10^8 All points are pairwise distinct. @@ -112,7 +112,7 @@ Suppose points = [[1,0],[2,0],[3,0],[2,2],[3,2]] - **Time Complexity:** O(N + K), where N is the number of points and K is the number of y-levels with at least 2 points. - **Space Complexity:** O(N) for storing the groups. -```text +```tex | Step | Operation | Count | | ---- | ----------------- | ----- | | 1 | Group points by y | N | diff --git a/explanations/392/en.md b/explanations/392/en.md index 0a60559..ac45e1f 100644 --- a/explanations/392/en.md +++ b/explanations/392/en.md @@ -8,7 +8,7 @@ Given two strings `s` and `t`, return `true` if `s` is a subsequence of `t`, or A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., "ace" is a subsequence of "abcde" while "aec" is not). **Examples** -```text +```tex Input: s = "abc", t = "ahbgdc" Output: true @@ -17,7 +17,7 @@ Output: false ``` **Constraints** -```text +```tex - 0 <= s.length <= 100 - 0 <= t.length <= 10^4 - s and t consist only of lowercase English letters. diff --git a/explanations/605/en.md b/explanations/605/en.md index 8f48860..f3c67b8 100644 --- a/explanations/605/en.md +++ b/explanations/605/en.md @@ -8,7 +8,7 @@ You have a long flowerbed in which some of the plots are planted, and some are n Given an integer array `flowerbed` containing 0's and 1's, where 0 means empty and 1 means not empty, and an integer `n`, return `true` if `n` new flowers can be planted in the flowerbed without violating the no-adjacent-flowers rule and `false` otherwise. **Examples** -```text +```tex Input: flowerbed = [1,0,0,0,1], n = 1 Output: true @@ -17,7 +17,7 @@ Output: false ``` **Constraints** -```text +```tex 1 <= flowerbed.length <= 2 * 10^4 flowerbed[i] is 0 or 1. There are no two adjacent flowers in flowerbed. diff --git a/explanations/643/en.md b/explanations/643/en.md index e164876..a004642 100644 --- a/explanations/643/en.md +++ b/explanations/643/en.md @@ -6,7 +6,7 @@ https://leetcode.com/problems/maximum-average-subarray-i Given an array consisting of n integers, find the contiguous subarray of length k that has the maximum average value. Return this value. **Examples** -```text +```tex Input: nums = [1,12,-5,-6,50,3], k = 4 Output: 12.75 Explanation: Maximum average is (12-5-6+50)/4 = 51/4 = 12.75 @@ -16,7 +16,7 @@ Output: 5.0 ``` **Constraints** -```text +```tex - 1 <= k <= n <= 10^5 - -10^4 <= nums[i] <= 10^4 ``` diff --git a/solutions/136/01.py b/solutions/136/01.py new file mode 100644 index 0000000..53ad9ad --- /dev/null +++ b/solutions/136/01.py @@ -0,0 +1,7 @@ +def singleNumber(nums: List[int]) -> int: + result = 0 + + for num in nums: + result ^= num # XOR + + return result \ No newline at end of file