diff --git a/rustgym/desc/leetcode/d1/100.md b/rustgym/desc/leetcode/d1/100.md new file mode 100644 index 00000000..2cf564c0 --- /dev/null +++ b/rustgym/desc/leetcode/d1/100.md @@ -0,0 +1,31 @@ +

Given the roots of two binary trees p and q, write a function to check if they are the same or not.

+ +

Two binary trees are considered the same if they are structurally identical, and the nodes have the same value.

+ +

 

+

Example 1:

+ +
Input: p = [1,2,3], q = [1,2,3]
+Output: true
+
+ +

Example 2:

+ +
Input: p = [1,2], q = [1,null,2]
+Output: false
+
+ +

Example 3:

+ +
Input: p = [1,2,1], q = [1,1,2]
+Output: false
+
+ +

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/101.md b/rustgym/desc/leetcode/d1/101.md new file mode 100644 index 00000000..8aa73cd8 --- /dev/null +++ b/rustgym/desc/leetcode/d1/101.md @@ -0,0 +1,26 @@ +

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).

+ +

For example, this binary tree [1,2,2,3,4,4,3] is symmetric:

+ +
    1
+   / \
+  2   2
+ / \ / \
+3  4 4  3
+
+ +

 

+ +

But the following [1,2,2,null,3,null,3] is not:

+ +
    1
+   / \
+  2   2
+   \   \
+   3    3
+
+ +

 

+ +

Follow up: Solve it both recursively and iteratively.

+
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/102.md b/rustgym/desc/leetcode/d1/102.md new file mode 100644 index 00000000..a0b74618 --- /dev/null +++ b/rustgym/desc/leetcode/d1/102.md @@ -0,0 +1,21 @@ +

Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).

+ +

+For example:
+Given binary tree [3,9,20,null,null,15,7],
+

    3
+   / \
+  9  20
+    /  \
+   15   7
+
+

+

+return its level order traversal as:
+

[
+  [3],
+  [9,20],
+  [15,7]
+]
+
+

\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/103.md b/rustgym/desc/leetcode/d1/103.md new file mode 100644 index 00000000..58e74c41 --- /dev/null +++ b/rustgym/desc/leetcode/d1/103.md @@ -0,0 +1,21 @@ +

Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).

+ +

+For example:
+Given binary tree [3,9,20,null,null,15,7],
+

    3
+   / \
+  9  20
+    /  \
+   15   7
+
+

+

+return its zigzag level order traversal as:
+

[
+  [3],
+  [20,9],
+  [15,7]
+]
+
+

\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/104.md b/rustgym/desc/leetcode/d1/104.md new file mode 100644 index 00000000..8714d868 --- /dev/null +++ b/rustgym/desc/leetcode/d1/104.md @@ -0,0 +1,36 @@ +

Given the root of a binary tree, return its maximum depth.

+ +

A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

+ +

 

+

Example 1:

+ +
Input: root = [3,9,20,null,null,15,7]
+Output: 3
+
+ +

Example 2:

+ +
Input: root = [1,null,2]
+Output: 2
+
+ +

Example 3:

+ +
Input: root = []
+Output: 0
+
+ +

Example 4:

+ +
Input: root = [0]
+Output: 1
+
+ +

 

+

Constraints:

+ +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/105.md b/rustgym/desc/leetcode/d1/105.md new file mode 100644 index 00000000..dc243b4a --- /dev/null +++ b/rustgym/desc/leetcode/d1/105.md @@ -0,0 +1,18 @@ +

Given preorder and inorder traversal of a tree, construct the binary tree.

+ +

Note:
+You may assume that duplicates do not exist in the tree.

+ +

For example, given

+ +
preorder = [3,9,20,15,7]
+inorder = [9,3,15,20,7]
+ +

Return the following binary tree:

+ +
    3
+   / \
+  9  20
+    /  \
+   15   7
+
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/106.md b/rustgym/desc/leetcode/d1/106.md new file mode 100644 index 00000000..8ac9e04e --- /dev/null +++ b/rustgym/desc/leetcode/d1/106.md @@ -0,0 +1,19 @@ +

Given inorder and postorder traversal of a tree, construct the binary tree.

+ +

Note:
+You may assume that duplicates do not exist in the tree.

+ +

For example, given

+ +
inorder = [9,3,15,20,7]
+postorder = [9,15,7,20,3]
+ +

Return the following binary tree:

+ +
    3
+   / \
+  9  20
+    /  \
+   15   7
+
+
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/107.md b/rustgym/desc/leetcode/d1/107.md new file mode 100644 index 00000000..12a3a8f8 --- /dev/null +++ b/rustgym/desc/leetcode/d1/107.md @@ -0,0 +1,21 @@ +

Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).

+ +

+For example:
+Given binary tree [3,9,20,null,null,15,7],
+

    3
+   / \
+  9  20
+    /  \
+   15   7
+
+

+

+return its bottom-up level order traversal as:
+

[
+  [15,7],
+  [9,20],
+  [3]
+]
+
+

\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/108.md b/rustgym/desc/leetcode/d1/108.md new file mode 100644 index 00000000..75d88111 --- /dev/null +++ b/rustgym/desc/leetcode/d1/108.md @@ -0,0 +1,17 @@ +

Given an array where elements are sorted in ascending order, convert it to a height balanced BST.

+ +

For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.

+ +

Example:

+ +
Given the sorted array: [-10,-3,0,5,9],
+
+One possible answer is: [0,-3,9,-10,null,5], which represents the following height balanced BST:
+
+      0
+     / \
+   -3   9
+   /   /
+ -10  5
+
+
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/109.md b/rustgym/desc/leetcode/d1/109.md new file mode 100644 index 00000000..6eaf4cdd --- /dev/null +++ b/rustgym/desc/leetcode/d1/109.md @@ -0,0 +1,38 @@ +

Given the head of a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.

+ +

For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.

+ +

 

+

Example 1:

+ +
Input: head = [-10,-3,0,5,9]
+Output: [0,-3,9,-10,null,5]
+Explanation: One possible answer is [0,-3,9,-10,null,5], which represents the shown height balanced BST.
+
+ +

Example 2:

+ +
Input: head = []
+Output: []
+
+ +

Example 3:

+ +
Input: head = [0]
+Output: [0]
+
+ +

Example 4:

+ +
Input: head = [1,3]
+Output: [3,1]
+
+ +

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/110.md b/rustgym/desc/leetcode/d1/110.md new file mode 100644 index 00000000..38cfa578 --- /dev/null +++ b/rustgym/desc/leetcode/d1/110.md @@ -0,0 +1,34 @@ +

Given a binary tree, determine if it is height-balanced.

+ +

For this problem, a height-balanced binary tree is defined as:

+ +
+

a binary tree in which the left and right subtrees of every node differ in height by no more than 1.

+
+ +

 

+

Example 1:

+ +
Input: root = [3,9,20,null,null,15,7]
+Output: true
+
+ +

Example 2:

+ +
Input: root = [1,2,2,3,3,null,null,4,4]
+Output: false
+
+ +

Example 3:

+ +
Input: root = []
+Output: true
+
+ +

 

+

Constraints:

+ +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/111.md b/rustgym/desc/leetcode/d1/111.md new file mode 100644 index 00000000..b58bc9f4 --- /dev/null +++ b/rustgym/desc/leetcode/d1/111.md @@ -0,0 +1,27 @@ +

Given a binary tree, find its minimum depth.

+ +

The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.

+ +

Note: A leaf is a node with no children.

+ +

 

+

Example 1:

+ +
Input: root = [3,9,20,null,null,15,7]
+Output: 2
+
+ +

Example 2:

+ +
Input: root = [2,null,3,null,4,null,5,null,6]
+Output: 5
+
+ +

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/112.md b/rustgym/desc/leetcode/d1/112.md new file mode 100644 index 00000000..35ec9816 --- /dev/null +++ b/rustgym/desc/leetcode/d1/112.md @@ -0,0 +1,32 @@ +

Given the root of a binary tree and an integer targetSum, return true if the tree has a root-to-leaf path such that adding up all the values along the path equals targetSum.

+ +

A leaf is a node with no children.

+ +

 

+

Example 1:

+ +
Input: root = [5,4,8,11,null,13,4,7,2,null,null,null,1], targetSum = 22
+Output: true
+
+ +

Example 2:

+ +
Input: root = [1,2,3], targetSum = 5
+Output: false
+
+ +

Example 3:

+ +
Input: root = [1,2], targetSum = 0
+Output: false
+
+ +

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/113.md b/rustgym/desc/leetcode/d1/113.md new file mode 100644 index 00000000..96586dc0 --- /dev/null +++ b/rustgym/desc/leetcode/d1/113.md @@ -0,0 +1,32 @@ +

Given the root of a binary tree and an integer targetSum, return all root-to-leaf paths where each path's sum equals targetSum.

+ +

A leaf is a node with no children.

+ +

 

+

Example 1:

+ +
Input: root = [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22
+Output: [[5,4,11,2],[5,8,4,5]]
+
+ +

Example 2:

+ +
Input: root = [1,2,3], targetSum = 5
+Output: []
+
+ +

Example 3:

+ +
Input: root = [1,2], targetSum = 0
+Output: []
+
+ +

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/114.md b/rustgym/desc/leetcode/d1/114.md new file mode 100644 index 00000000..056ad83a --- /dev/null +++ b/rustgym/desc/leetcode/d1/114.md @@ -0,0 +1,36 @@ +

Given the root of a binary tree, flatten the tree into a "linked list":

+ + + +

 

+

Example 1:

+ +
Input: root = [1,2,5,3,4,null,6]
+Output: [1,null,2,null,3,null,4,null,5,null,6]
+
+ +

Example 2:

+ +
Input: root = []
+Output: []
+
+ +

Example 3:

+ +
Input: root = [0]
+Output: [0]
+
+ +

 

+

Constraints:

+ + + +

 

+Follow up: Can you flatten the tree in-place (with O(1) extra space)?
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/115.md b/rustgym/desc/leetcode/d1/115.md new file mode 100644 index 00000000..f6bea9a1 --- /dev/null +++ b/rustgym/desc/leetcode/d1/115.md @@ -0,0 +1,38 @@ +

Given two strings s and t, return the number of distinct subsequences of s which equals t.

+ +

A string's subsequence is a new string 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).

+ +

It's guaranteed the answer fits on a 32-bit signed integer.

+ +

 

+

Example 1:

+ +
Input: s = "rabbbit", t = "rabbit"
+Output: 3
+Explanation:
+As shown below, there are 3 ways you can generate "rabbit" from S.
+rabbbit
+rabbbit
+rabbbit
+
+ +

Example 2:

+ +
Input: s = "babgbag", t = "bag"
+Output: 5
+Explanation:
+As shown below, there are 5 ways you can generate "bag" from S.
+babgbag
+babgbag
+babgbag
+babgbag
+babgbag
+ +

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/118.md b/rustgym/desc/leetcode/d1/118.md new file mode 100644 index 00000000..7378a008 --- /dev/null +++ b/rustgym/desc/leetcode/d1/118.md @@ -0,0 +1,18 @@ +

Given a non-negative integer numRows, generate the first numRows of Pascal's triangle.

+ +


+In Pascal's triangle, each number is the sum of the two numbers directly above it.

+ +

Example:

+ +
Input: 5
+Output:
+[
+     [1],
+    [1,1],
+   [1,2,1],
+  [1,3,3,1],
+ [1,4,6,4,1]
+]
+
+
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/120.md b/rustgym/desc/leetcode/d1/120.md new file mode 100644 index 00000000..c6e950b4 --- /dev/null +++ b/rustgym/desc/leetcode/d1/120.md @@ -0,0 +1,35 @@ +

Given a triangle array, return the minimum path sum from top to bottom.

+ +

For each step, you may move to an adjacent number of the row below. More formally, if you are on index i on the current row, you may move to either index i or index i + 1 on the next row.

+ +

 

+

Example 1:

+ +
Input: triangle = [[2],[3,4],[6,5,7],[4,1,8,3]]
+Output: 11
+Explanation: The triangle looks like:
+   2
+  3 4
+ 6 5 7
+4 1 8 3
+The minimum path sum from top to bottom is 2 + 3 + 5 + 1 = 11 (underlined above).
+
+ +

Example 2:

+ +
Input: triangle = [[-10]]
+Output: -10
+
+ +

 

+

Constraints:

+ + + +

 

+Follow up: Could you do this using only O(n) extra space, where n is the total number of rows in the triangle?
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/121.md b/rustgym/desc/leetcode/d1/121.md new file mode 100644 index 00000000..ed93bed9 --- /dev/null +++ b/rustgym/desc/leetcode/d1/121.md @@ -0,0 +1,30 @@ +

You are given an array prices where prices[i] is the price of a given stock on the ith day.

+ +

You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock.

+ +

Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0.

+ +

 

+

Example 1:

+ +
Input: prices = [7,1,5,3,6,4]
+Output: 5
+Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.
+Note that buying on day 2 and selling on day 1 is not allowed because you must buy before you sell.
+
+ +

Example 2:

+ +
Input: prices = [7,6,4,3,1]
+Output: 0
+Explanation: In this case, no transactions are done and the max profit = 0.
+
+ +

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/122.md b/rustgym/desc/leetcode/d1/122.md new file mode 100644 index 00000000..4f2f093a --- /dev/null +++ b/rustgym/desc/leetcode/d1/122.md @@ -0,0 +1,37 @@ +

Say you have an array prices for which the ith element is the price of a given stock on day i.

+ +

Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times).

+ +

Note: You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again).

+ +

Example 1:

+ +
Input: [7,1,5,3,6,4]
+Output: 7
+Explanation: Buy on day 2 (price = 1) and sell on day 3 (price = 5), profit = 5-1 = 4.
+             Then buy on day 4 (price = 3) and sell on day 5 (price = 6), profit = 6-3 = 3.
+
+ +

Example 2:

+ +
Input: [1,2,3,4,5]
+Output: 4
+Explanation: Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4.
+             Note that you cannot buy on day 1, buy on day 2 and sell them later, as you are
+             engaging multiple transactions at the same time. You must sell before buying again.
+
+ +

Example 3:

+ +
Input: [7,6,4,3,1]
+Output: 0
+Explanation: In this case, no transaction is done, i.e. max profit = 0.
+ +

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/125.md b/rustgym/desc/leetcode/d1/125.md new file mode 100644 index 00000000..83cdd0e6 --- /dev/null +++ b/rustgym/desc/leetcode/d1/125.md @@ -0,0 +1,23 @@ +

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

+ +

Note: For the purpose of this problem, we define empty string as valid palindrome.

+ +

Example 1:

+ +
Input: "A man, a plan, a canal: Panama"
+Output: true
+
+ +

Example 2:

+ +
Input: "race a car"
+Output: false
+
+ +

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/129.md b/rustgym/desc/leetcode/d1/129.md new file mode 100644 index 00000000..83cdd0e6 --- /dev/null +++ b/rustgym/desc/leetcode/d1/129.md @@ -0,0 +1,23 @@ +

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

+ +

Note: For the purpose of this problem, we define empty string as valid palindrome.

+ +

Example 1:

+ +
Input: "A man, a plan, a canal: Panama"
+Output: true
+
+ +

Example 2:

+ +
Input: "race a car"
+Output: false
+
+ +

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/130.md b/rustgym/desc/leetcode/d1/130.md new file mode 100644 index 00000000..8e1379fb --- /dev/null +++ b/rustgym/desc/leetcode/d1/130.md @@ -0,0 +1,24 @@ +

Given a 2D board containing 'X' and 'O' (the letter O), capture all regions surrounded by 'X'.

+ +

A region is captured by flipping all 'O's into 'X's in that surrounded region.

+ +

Example:

+ +
X X X X
+X O O X
+X X O X
+X O X X
+
+ +

After running your function, the board should be:

+ +
X X X X
+X X X X
+X X X X
+X O X X
+
+ +

Explanation:

+ +

Surrounded regions shouldn’t be on the border, which means that any 'O' on the border of the board are not flipped to 'X'. Any 'O' that is not on the border and it is not connected to an 'O' on the border will be flipped to 'X'. Two cells are connected if they are adjacent cells connected horizontally or vertically.

+
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/131.md b/rustgym/desc/leetcode/d1/131.md new file mode 100644 index 00000000..7141a1d5 --- /dev/null +++ b/rustgym/desc/leetcode/d1/131.md @@ -0,0 +1,20 @@ +

Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s.

+ +

A palindrome string is a string that reads the same backward as forward.

+ +

 

+

Example 1:

+
Input: s = "aab"
+Output: [["a","a","b"],["aa","b"]]
+

Example 2:

+
Input: s = "a"
+Output: [["a"]]
+
+

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/132.md b/rustgym/desc/leetcode/d1/132.md new file mode 100644 index 00000000..d15bfd26 --- /dev/null +++ b/rustgym/desc/leetcode/d1/132.md @@ -0,0 +1,32 @@ +

Given a string s, partition s such that every substring of the partition is a palindrome.

+ +

Return the minimum cuts needed for a palindrome partitioning of s.

+ +

 

+

Example 1:

+ +
Input: s = "aab"
+Output: 1
+Explanation: The palindrome partitioning ["aa","b"] could be produced using 1 cut.
+
+ +

Example 2:

+ +
Input: s = "a"
+Output: 0
+
+ +

Example 3:

+ +
Input: s = "ab"
+Output: 1
+
+ +

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/134.md b/rustgym/desc/leetcode/d1/134.md new file mode 100644 index 00000000..59974cba --- /dev/null +++ b/rustgym/desc/leetcode/d1/134.md @@ -0,0 +1,44 @@ +

There are n gas stations along a circular route, where the amount of gas at the ith station is gas[i].

+ +

You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from the ith station to its next (i + 1)th station. You begin the journey with an empty tank at one of the gas stations.

+ +

Given two integer arrays gas and cost, return the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return -1. If there exists a solution, it is guaranteed to be unique

+ +

 

+

Example 1:

+ +
Input: gas = [1,2,3,4,5], cost = [3,4,5,1,2]
+Output: 3
+Explanation:
+Start at station 3 (index 3) and fill up with 4 unit of gas. Your tank = 0 + 4 = 4
+Travel to station 4. Your tank = 4 - 1 + 5 = 8
+Travel to station 0. Your tank = 8 - 2 + 1 = 7
+Travel to station 1. Your tank = 7 - 3 + 2 = 6
+Travel to station 2. Your tank = 6 - 4 + 3 = 5
+Travel to station 3. The cost is 5. Your gas is just enough to travel back to station 3.
+Therefore, return 3 as the starting index.
+
+ +

Example 2:

+ +
Input: gas = [2,3,4], cost = [3,4,3]
+Output: -1
+Explanation:
+You can't start at station 0 or 1, as there is not enough gas to travel to the next station.
+Let's start at station 2 and fill up with 4 unit of gas. Your tank = 0 + 4 = 4
+Travel to station 0. Your tank = 4 - 3 + 2 = 3
+Travel to station 1. Your tank = 3 - 3 + 3 = 3
+You cannot travel back to station 2, as it requires 4 unit of gas but you only have 3.
+Therefore, you can't travel around the circuit once no matter where you start.
+
+ +

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/136.md b/rustgym/desc/leetcode/d1/136.md new file mode 100644 index 00000000..9b89fdb9 --- /dev/null +++ b/rustgym/desc/leetcode/d1/136.md @@ -0,0 +1,24 @@ +

Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.

+ +

Follow up: Could you implement a solution with a linear runtime complexity and without using extra memory?

+ +

 

+

Example 1:

+
Input: nums = [2,2,1]
+Output: 1
+

Example 2:

+
Input: nums = [4,1,2,1,2]
+Output: 4
+

Example 3:

+
Input: nums = [1]
+Output: 1
+
+

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/137.md b/rustgym/desc/leetcode/d1/137.md new file mode 100644 index 00000000..0aeb8208 --- /dev/null +++ b/rustgym/desc/leetcode/d1/137.md @@ -0,0 +1,22 @@ +

Given an integer array nums where every element appears three times except for one, which appears exactly once. Find the single element and return it.

+ +

 

+

Example 1:

+
Input: nums = [2,2,3,2]
+Output: 3
+

Example 2:

+
Input: nums = [0,1,0,1,0,1,99]
+Output: 99
+
+

 

+

Constraints:

+ + + +

 

+

Follow up: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?

+
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/139.md b/rustgym/desc/leetcode/d1/139.md new file mode 100644 index 00000000..62618743 --- /dev/null +++ b/rustgym/desc/leetcode/d1/139.md @@ -0,0 +1,30 @@ +

Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.

+ +

Note:

+ + + +

Example 1:

+ +
Input: s = "leetcode", wordDict = ["leet", "code"]
+Output: true
+Explanation: Return true because "leetcode" can be segmented as "leet code".
+
+ +

Example 2:

+ +
Input: s = "applepenapple", wordDict = ["apple", "pen"]
+Output: true
+Explanation: Return true because "applepenapple" can be segmented as "apple pen apple".
+             Note that you are allowed to reuse a dictionary word.
+
+ +

Example 3:

+ +
Input: s = "catsandog", wordDict = ["cats", "dog", "sand", "and", "cat"]
+Output: false
+
+
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/143.md b/rustgym/desc/leetcode/d1/143.md new file mode 100644 index 00000000..f470c37c --- /dev/null +++ b/rustgym/desc/leetcode/d1/143.md @@ -0,0 +1,14 @@ +

Given a singly linked list L: L0L1→…→Ln-1Ln,
+reorder it to: L0LnL1Ln-1L2Ln-2→…

+ +

You may not modify the values in the list's nodes, only nodes itself may be changed.

+ +

Example 1:

+ +
Given 1->2->3->4, reorder it to 1->4->2->3.
+ +

Example 2:

+ +
Given 1->2->3->4->5, reorder it to 1->5->2->4->3.
+
+
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/144.md b/rustgym/desc/leetcode/d1/144.md new file mode 100644 index 00000000..b4d274ea --- /dev/null +++ b/rustgym/desc/leetcode/d1/144.md @@ -0,0 +1,44 @@ +

Given the root of a binary tree, return the preorder traversal of its nodes' values.

+ +

 

+

Example 1:

+ +
Input: root = [1,null,2,3]
+Output: [1,2,3]
+
+ +

Example 2:

+ +
Input: root = []
+Output: []
+
+ +

Example 3:

+ +
Input: root = [1]
+Output: [1]
+
+ +

Example 4:

+ +
Input: root = [1,2]
+Output: [1,2]
+
+ +

Example 5:

+ +
Input: root = [1,null,2]
+Output: [1,2]
+
+ +

 

+

Constraints:

+ + + +

 

+

Follow up: Recursive solution is trivial, could you do it iteratively?

+
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/145.md b/rustgym/desc/leetcode/d1/145.md new file mode 100644 index 00000000..b3130890 --- /dev/null +++ b/rustgym/desc/leetcode/d1/145.md @@ -0,0 +1,49 @@ +

Given the root of a binary tree, return the postorder traversal of its nodes' values.

+ +

 

+

Example 1:

+ +
Input: root = [1,null,2,3]
+Output: [3,2,1]
+
+ +

Example 2:

+ +
Input: root = []
+Output: []
+
+ +

Example 3:

+ +
Input: root = [1]
+Output: [1]
+
+ +

Example 4:

+ +
Input: root = [1,2]
+Output: [2,1]
+
+ +

Example 5:

+ +
Input: root = [1,null,2]
+Output: [2,1]
+
+ +

 

+

Constraints:

+ + + +

 

+ +

Follow up:

+ +

Recursive solution is trivial, could you do it iteratively?

+ +

 

+
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/146.md b/rustgym/desc/leetcode/d1/146.md new file mode 100644 index 00000000..55e5f08e --- /dev/null +++ b/rustgym/desc/leetcode/d1/146.md @@ -0,0 +1,45 @@ +

Design a data structure that follows the constraints of a Least Recently Used (LRU) cache.

+ +

Implement the LRUCache class:

+ + + +

Follow up:
+Could you do get and put in O(1) time complexity?

+ +

 

+

Example 1:

+ +
Input
+["LRUCache", "put", "put", "get", "put", "get", "put", "get", "get", "get"]
+[[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]]
+Output
+[null, null, null, 1, null, -1, null, -1, 3, 4]
+
+Explanation
+LRUCache lRUCache = new LRUCache(2);
+lRUCache.put(1, 1); // cache is {1=1}
+lRUCache.put(2, 2); // cache is {1=1, 2=2}
+lRUCache.get(1);    // return 1
+lRUCache.put(3, 3); // LRU key was 2, evicts key 2, cache is {1=1, 3=3}
+lRUCache.get(2);    // returns -1 (not found)
+lRUCache.put(4, 4); // LRU key was 1, evicts key 1, cache is {4=4, 3=3}
+lRUCache.get(1);    // return -1 (not found)
+lRUCache.get(3);    // return 3
+lRUCache.get(4);    // return 4
+
+ +

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/147.md b/rustgym/desc/leetcode/d1/147.md new file mode 100644 index 00000000..8c98d8d0 --- /dev/null +++ b/rustgym/desc/leetcode/d1/147.md @@ -0,0 +1,34 @@ +

Sort a linked list using insertion sort.

+ +
    +
+ +


+A graphical example of insertion sort. The partial sorted list (black) initially contains only the first element in the list.
+With each iteration one element (red) is removed from the input data and inserted in-place into the sorted list

+ +
    +
+ +

Algorithm of Insertion Sort:

+ +
    +
  1. Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list.
  2. +
  3. At each iteration, insertion sort removes one element from the input data, finds the location it belongs within the sorted list, and inserts it there.
  4. +
  5. It repeats until no input elements remain.
  6. +
+ +


+Example 1:

+ +
Input: 4->2->1->3
+Output: 1->2->3->4
+
+ +

Example 2:

+ +
Input: -1->5->3->4->0
+Output: -1->0->3->4->5
+
+
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/148.md b/rustgym/desc/leetcode/d1/148.md new file mode 100644 index 00000000..d32a80fb --- /dev/null +++ b/rustgym/desc/leetcode/d1/148.md @@ -0,0 +1,31 @@ +

Given the head of a linked list, return the list after sorting it in ascending order.

+ +

Follow up: Can you sort the linked list in O(n logn) time and O(1) memory (i.e. constant space)?

+ +

 

+

Example 1:

+ +
Input: head = [4,2,1,3]
+Output: [1,2,3,4]
+
+ +

Example 2:

+ +
Input: head = [-1,5,3,4,0]
+Output: [-1,0,3,4,5]
+
+ +

Example 3:

+ +
Input: head = []
+Output: []
+
+ +

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/150.md b/rustgym/desc/leetcode/d1/150.md new file mode 100644 index 00000000..0a8caa08 --- /dev/null +++ b/rustgym/desc/leetcode/d1/150.md @@ -0,0 +1,39 @@ +

Evaluate the value of an arithmetic expression in Reverse Polish Notation.

+ +

Valid operators are +, -, *, /. Each operand may be an integer or another expression.

+ +

Note:

+ + + +

Example 1:

+ +
Input: ["2", "1", "+", "3", "*"]
+Output: 9
+Explanation: ((2 + 1) * 3) = 9
+
+ +

Example 2:

+ +
Input: ["4", "13", "5", "/", "+"]
+Output: 6
+Explanation: (4 + (13 / 5)) = 6
+
+ +

Example 3:

+ +
Input: ["10", "6", "9", "3", "+", "-11", "*", "/", "*", "17", "+", "5", "+"]
+Output: 22
+Explanation: 
+  ((10 * (6 / ((9 + 3) * -11))) + 17) + 5
+= ((10 * (6 / (12 * -11))) + 17) + 5
+= ((10 * (6 / -132)) + 17) + 5
+= ((10 * 0) + 17) + 5
+= (0 + 17) + 5
+= 17 + 5
+= 22
+
+
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/151.md b/rustgym/desc/leetcode/d1/151.md new file mode 100644 index 00000000..ba3ff2af --- /dev/null +++ b/rustgym/desc/leetcode/d1/151.md @@ -0,0 +1,60 @@ +

Given an input string s, reverse the order of the words.

+ +

A word is defined as a sequence of non-space characters. The words in s will be separated by at least one space.

+ +

Return a string of the words in reverse order concatenated by a single space.

+ +

Note that s may contain leading or trailing spaces or multiple spaces between two words. The returned string should only have a single space separating the words. Do not include any extra spaces.

+ +

 

+

Example 1:

+ +
Input: s = "the sky is blue"
+Output: "blue is sky the"
+
+ +

Example 2:

+ +
Input: s = "  hello world  "
+Output: "world hello"
+Explanation: Your reversed string should not contain leading or trailing spaces.
+
+ +

Example 3:

+ +
Input: s = "a good   example"
+Output: "example good a"
+Explanation: You need to reduce multiple spaces between two words to a single space in the reversed string.
+
+ +

Example 4:

+ +
Input: s = "  Bob    Loves  Alice   "
+Output: "Alice Loves Bob"
+
+ +

Example 5:

+ +
Input: s = "Alice does not even like bob"
+Output: "bob like even not does Alice"
+
+ +

 

+

Constraints:

+ + + +

 

+ +

Follow up:

+ + + +

 

+
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/152.md b/rustgym/desc/leetcode/d1/152.md new file mode 100644 index 00000000..78f8005e --- /dev/null +++ b/rustgym/desc/leetcode/d1/152.md @@ -0,0 +1,15 @@ +

Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product.

+ +

Example 1:

+ +
Input: [2,3,-2,4]
+Output: 6
+Explanation: [2,3] has the largest product 6.
+
+ +

Example 2:

+ +
Input: [-2,0,-1]
+Output: 0
+Explanation: The result cannot be 2, because [-2,-1] is not a subarray.
+
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/153.md b/rustgym/desc/leetcode/d1/153.md new file mode 100644 index 00000000..cea84c2e --- /dev/null +++ b/rustgym/desc/leetcode/d1/153.md @@ -0,0 +1,44 @@ +

Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,2,4,5,6,7] might become:

+ + + +

Notice that rotating an array [a[0], a[1], a[2], ..., a[n-1]] 1 time results in the array [a[n-1], a[0], a[1], a[2], ..., a[n-2]].

+ +

Given the sorted rotated array nums, return the minimum element of this array.

+ +

 

+

Example 1:

+ +
Input: nums = [3,4,5,1,2]
+Output: 1
+Explanation: The original array was [1,2,3,4,5] rotated 3 times.
+
+ +

Example 2:

+ +
Input: nums = [4,5,6,7,0,1,2]
+Output: 0
+Explanation: The original array was [0,1,2,4,5,6,7] and it was rotated 4 times.
+
+ +

Example 3:

+ +
Input: nums = [11,13,15,17]
+Output: 11
+Explanation: The original array was [11,13,15,17] and it was rotated 4 times. 
+
+ +

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/154.md b/rustgym/desc/leetcode/d1/154.md new file mode 100644 index 00000000..4b753eba --- /dev/null +++ b/rustgym/desc/leetcode/d1/154.md @@ -0,0 +1,25 @@ +

Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.

+ +

(i.e.,  [0,1,2,4,5,6,7] might become  [4,5,6,7,0,1,2]).

+ +

Find the minimum element.

+ +

The array may contain duplicates.

+ +

Example 1:

+ +
Input: [1,3,5]
+Output: 1
+ +

Example 2:

+ +
Input: [2,2,2,0,1]
+Output: 0
+ +

Note:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/155.md b/rustgym/desc/leetcode/d1/155.md new file mode 100644 index 00000000..0a304e72 --- /dev/null +++ b/rustgym/desc/leetcode/d1/155.md @@ -0,0 +1,37 @@ +

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

+ + + +

 

+

Example 1:

+ +
Input
+["MinStack","push","push","push","getMin","pop","top","getMin"]
+[[],[-2],[0],[-3],[],[],[],[]]
+
+Output
+[null,null,null,null,-3,null,0,-2]
+
+Explanation
+MinStack minStack = new MinStack();
+minStack.push(-2);
+minStack.push(0);
+minStack.push(-3);
+minStack.getMin(); // return -3
+minStack.pop();
+minStack.top();    // return 0
+minStack.getMin(); // return -2
+
+ +

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/156.md b/rustgym/desc/leetcode/d1/156.md new file mode 100644 index 00000000..98ed6847 --- /dev/null +++ b/rustgym/desc/leetcode/d1/156.md @@ -0,0 +1,42 @@ +

Given the root of a binary tree, turn the tree upside down and return the new root.

+ +

You can turn a binary tree upside down with the following steps:

+ +
    +
  1. The original left child becomes the new root.
  2. +
  3. The original root becomes the new right child.
  4. +
  5. The original right child becomes the new left child.
  6. +
+ +

+ +

The mentioned steps are done level by level, it is guaranteed that every node in the given tree has either 0 or 2 children.

+ +

 

+

Example 1:

+ +
Input: root = [1,2,3,4,5]
+Output: [4,5,2,null,null,3,1]
+
+ +

Example 2:

+ +
Input: root = []
+Output: []
+
+ +

Example 3:

+ +
Input: root = [1]
+Output: [1]
+
+ +

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/159.md b/rustgym/desc/leetcode/d1/159.md new file mode 100644 index 00000000..04c0aea2 --- /dev/null +++ b/rustgym/desc/leetcode/d1/159.md @@ -0,0 +1,16 @@ +

Given a string s , find the length of the longest substring t  that contains at most 2 distinct characters.

+ +

Example 1:

+ +
Input: "eceba"
+Output: 3
+Explanation: t is "ece" which its length is 3.
+
+ +

Example 2:

+ +
Input: "ccaabbb"
+Output: 5
+Explanation: t is "aabbb" which its length is 5.
+
+
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/161.md b/rustgym/desc/leetcode/d1/161.md new file mode 100644 index 00000000..88c7e2a6 --- /dev/null +++ b/rustgym/desc/leetcode/d1/161.md @@ -0,0 +1,46 @@ +

Given two strings s and t, return true if they are both one edit distance apart, otherwise return false.

+ +

A string s is said to be one distance apart from a string t if you can:

+ + + +

 

+

Example 1:

+ +
Input: s = "ab", t = "acb"
+Output: true
+Explanation: We can insert 'c' into s to get t.
+
+ +

Example 2:

+ +
Input: s = "", t = ""
+Output: false
+Explanation: We cannot get t from s by only one step.
+
+ +

Example 3:

+ +
Input: s = "a", t = ""
+Output: true
+
+ +

Example 4:

+ +
Input: s = "", t = "A"
+Output: true
+
+ +

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/162.md b/rustgym/desc/leetcode/d1/162.md new file mode 100644 index 00000000..72777d24 --- /dev/null +++ b/rustgym/desc/leetcode/d1/162.md @@ -0,0 +1,30 @@ +

A peak element is an element that is strictly greater than its neighbors.

+ +

Given an integer array nums, find a peak element, and return its index. If the array contains multiple peaks, return the index to any of the peaks.

+ +

You may imagine that nums[-1] = nums[n] = -∞.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,3,1]
+Output: 2
+Explanation: 3 is a peak element and your function should return the index number 2.
+ +

Example 2:

+ +
Input: nums = [1,2,1,3,5,6,4]
+Output: 5
+Explanation: Your function can return either index number 1 where the peak element is 2, or index number 5 where the peak element is 6.
+ +

 

+

Constraints:

+ + + +

 

+Follow up: Could you implement a solution with logarithmic complexity?
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/163.md b/rustgym/desc/leetcode/d1/163.md new file mode 100644 index 00000000..c60966d5 --- /dev/null +++ b/rustgym/desc/leetcode/d1/163.md @@ -0,0 +1,62 @@ +

You are given an inclusive range [lower, upper] and a sorted unique integer array nums, where all elements are in the inclusive range.

+ +

A number x is considered missing if x is in the range [lower, upper] and x is not in nums.

+ +

Return the smallest sorted list of ranges that cover every missing number exactly. That is, no element of nums is in any of the ranges, and each missing number is in one of the ranges.

+ +

Each range [a,b] in the list should be output as:

+ + + +

 

+

Example 1:

+ +
Input: nums = [0,1,3,50,75], lower = 0, upper = 99
+Output: ["2","4->49","51->74","76->99"]
+Explanation: The ranges are:
+[2,2] --> "2"
+[4,49] --> "4->49"
+[51,74] --> "51->74"
+[76,99] --> "76->99"
+
+ +

Example 2:

+ +
Input: nums = [], lower = 1, upper = 1
+Output: ["1"]
+Explanation: The only missing range is [1,1], which becomes "1".
+
+ +

Example 3:

+ +
Input: nums = [], lower = -3, upper = -1
+Output: ["-3->-1"]
+Explanation: The only missing range is [-3,-1], which becomes "-3->-1".
+
+ +

Example 4:

+ +
Input: nums = [-1], lower = -1, upper = -1
+Output: []
+Explanation: There are no missing ranges since there are no missing numbers.
+
+ +

Example 5:

+ +
Input: nums = [-1], lower = -2, upper = -1
+Output: ["-2"]
+
+ +

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/164.md b/rustgym/desc/leetcode/d1/164.md new file mode 100644 index 00000000..cfbdaebe --- /dev/null +++ b/rustgym/desc/leetcode/d1/164.md @@ -0,0 +1,24 @@ +

Given an unsorted array, find the maximum difference between the successive elements in its sorted form.

+ +

Return 0 if the array contains less than 2 elements.

+ +

Example 1:

+ +
Input: [3,6,9,1]
+Output: 3
+Explanation: The sorted form of the array is [1,3,6,9], either
+             (3,6) or (6,9) has the maximum difference 3.
+ +

Example 2:

+ +
Input: [10]
+Output: 0
+Explanation: The array contains less than 2 elements, therefore return 0.
+ +

Note:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/165.md b/rustgym/desc/leetcode/d1/165.md new file mode 100644 index 00000000..9fa9b62a --- /dev/null +++ b/rustgym/desc/leetcode/d1/165.md @@ -0,0 +1,61 @@ +

Given two version numbers, version1 and version2, compare them.

+ + + +

Version numbers consist of one or more revisions joined by a dot '.'. Each revision consists of digits and may contain leading zeros. Every revision contains at least one character. Revisions are 0-indexed from left to right, with the leftmost revision being revision 0, the next revision being revision 1, and so on. For example 2.5.33 and 0.1 are valid version numbers.

+ +

To compare version numbers, compare their revisions in left-to-right order. Revisions are compared using their integer value ignoring any leading zeros. This means that revisions 1 and 001 are considered equal. If a version number does not specify a revision at an index, then treat the revision as 0. For example, version 1.0 is less than version 1.1 because their revision 0s are the same, but their revision 1s are 0 and 1 respectively, and 0 < 1.

+ +

Return the following:

+ + + +

 

+

Example 1:

+ +
Input: version1 = "1.01", version2 = "1.001"
+Output: 0
+Explanation: Ignoring leading zeroes, both "01" and "001" represent the same integer "1".
+
+ +

Example 2:

+ +
Input: version1 = "1.0", version2 = "1.0.0"
+Output: 0
+Explanation: version1 does not specify revision 2, which means it is treated as "0".
+
+ +

Example 3:

+ +
Input: version1 = "0.1", version2 = "1.1"
+Output: -1
+Explanation: version1's revision 0 is "0", while version2's revision 0 is "1". 0 < 1, so version1 < version2.
+
+ +

Example 4:

+ +
Input: version1 = "1.0.1", version2 = "1"
+Output: 1
+
+ +

Example 5:

+ +
Input: version1 = "7.5.2.4", version2 = "7.5.3"
+Output: -1
+
+ +

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/166.md b/rustgym/desc/leetcode/d1/166.md new file mode 100644 index 00000000..6291e63a --- /dev/null +++ b/rustgym/desc/leetcode/d1/166.md @@ -0,0 +1,33 @@ +

Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.

+ +

If the fractional part is repeating, enclose the repeating part in parentheses.

+ +

If multiple answers are possible, return any of them.

+ +

It is guaranteed that the length of the answer string is less than 104 for all the given inputs.

+ +

 

+

Example 1:

+
Input: numerator = 1, denominator = 2
+Output: "0.5"
+

Example 2:

+
Input: numerator = 2, denominator = 1
+Output: "2"
+

Example 3:

+
Input: numerator = 2, denominator = 3
+Output: "0.(6)"
+

Example 4:

+
Input: numerator = 4, denominator = 333
+Output: "0.(012)"
+

Example 5:

+
Input: numerator = 1, denominator = 5
+Output: "0.2"
+
+

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/167.md b/rustgym/desc/leetcode/d1/167.md new file mode 100644 index 00000000..7ef46130 --- /dev/null +++ b/rustgym/desc/leetcode/d1/167.md @@ -0,0 +1,41 @@ +

Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.

+ +

The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2.

+ +

Note:

+ + + +

 

+

Example 1:

+ +
Input: numbers = [2,7,11,15], target = 9
+Output: [1,2]
+Explanation: The sum of 2 and 7 is 9. Therefore index1 = 1, index2 = 2.
+
+ +

Example 2:

+ +
Input: numbers = [2,3,4], target = 6
+Output: [1,3]
+
+ +

Example 3:

+ +
Input: numbers = [-1,0], target = -1
+Output: [1,2]
+
+ +

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/168.md b/rustgym/desc/leetcode/d1/168.md new file mode 100644 index 00000000..c784f415 --- /dev/null +++ b/rustgym/desc/leetcode/d1/168.md @@ -0,0 +1,31 @@ +

Given a positive integer, return its corresponding column title as appear in an Excel sheet.

+ +

For example:

+ +
    1 -> A
+    2 -> B
+    3 -> C
+    ...
+    26 -> Z
+    27 -> AA
+    28 -> AB 
+    ...
+
+ +

Example 1:

+ +
Input: 1
+Output: "A"
+
+ +

Example 2:

+ +
Input: 28
+Output: "AB"
+
+ +

Example 3:

+ +
Input: 701
+Output: "ZY"
+
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/169.md b/rustgym/desc/leetcode/d1/169.md new file mode 100644 index 00000000..89e19390 --- /dev/null +++ b/rustgym/desc/leetcode/d1/169.md @@ -0,0 +1,23 @@ +

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 = [2,2,1,1,1,2,2]
+Output: 2
+
+

 

+

Constraints:

+ + + +

 

+Follow-up: Could you solve the problem in linear time and in O(1) space?
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/170.md b/rustgym/desc/leetcode/d1/170.md new file mode 100644 index 00000000..6b4b945b --- /dev/null +++ b/rustgym/desc/leetcode/d1/170.md @@ -0,0 +1,37 @@ +

Design a data structure that accepts a stream of integers and checks if it has a pair of integers that sum up to a particular value.

+ +

Implement the TwoSum class:

+ + + +

 

+

Example 1:

+ +
Input
+["TwoSum", "add", "add", "add", "find", "find"]
+[[], [1], [3], [5], [4], [7]]
+Output
+[null, null, null, null, true, false]
+
+Explanation
+TwoSum twoSum = new TwoSum();
+twoSum.add(1);   // [] --> [1]
+twoSum.add(3);   // [1] --> [1,3]
+twoSum.add(5);   // [1,3] --> [1,3,5]
+twoSum.find(4);  // 1 + 3 = 4, return true
+twoSum.find(7);  // No two integers sum up to 7, return false
+
+ +

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/171.md b/rustgym/desc/leetcode/d1/171.md new file mode 100644 index 00000000..3a617d48 --- /dev/null +++ b/rustgym/desc/leetcode/d1/171.md @@ -0,0 +1,40 @@ +

Given a column title as appear in an Excel sheet, return its corresponding column number.

+ +

For example:

+ +
    A -> 1
+    B -> 2
+    C -> 3
+    ...
+    Z -> 26
+    AA -> 27
+    AB -> 28 
+    ...
+
+ +

Example 1:

+ +
Input: "A"
+Output: 1
+
+ +

Example 2:

+ +
Input: "AB"
+Output: 28
+
+ +

Example 3:

+ +
Input: "ZY"
+Output: 701
+
+

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/172.md b/rustgym/desc/leetcode/d1/172.md new file mode 100644 index 00000000..06fb56dc --- /dev/null +++ b/rustgym/desc/leetcode/d1/172.md @@ -0,0 +1,32 @@ +

Given an integer n, return the number of trailing zeroes in n!.

+ +

Follow up: Could you write a solution that works in logarithmic time complexity?

+ +

 

+

Example 1:

+ +
Input: n = 3
+Output: 0
+Explanation: 3! = 6, no trailing zero.
+
+ +

Example 2:

+ +
Input: n = 5
+Output: 1
+Explanation: 5! = 120, one trailing zero.
+
+ +

Example 3:

+ +
Input: n = 0
+Output: 0
+
+ +

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/173.md b/rustgym/desc/leetcode/d1/173.md new file mode 100644 index 00000000..c98a1d3f --- /dev/null +++ b/rustgym/desc/leetcode/d1/173.md @@ -0,0 +1,50 @@ +

Implement the BSTIterator class that represents an iterator over the in-order traversal of a binary search tree (BST):

+ + + +

Notice that by initializing the pointer to a non-existent smallest number, the first call to next() will return the smallest element in the BST.

+ +

You may assume that next() calls will always be valid. That is, there will be at least a next number in the in-order traversal when next() is called.

+ +

 

+

Example 1:

+ +
Input
+["BSTIterator", "next", "next", "hasNext", "next", "hasNext", "next", "hasNext", "next", "hasNext"]
+[[[7, 3, 15, null, null, 9, 20]], [], [], [], [], [], [], [], [], []]
+Output
+[null, 3, 7, true, 9, true, 15, true, 20, false]
+
+Explanation
+BSTIterator bSTIterator = new BSTIterator([7, 3, 15, null, null, 9, 20]);
+bSTIterator.next();    // return 3
+bSTIterator.next();    // return 7
+bSTIterator.hasNext(); // return True
+bSTIterator.next();    // return 9
+bSTIterator.hasNext(); // return True
+bSTIterator.next();    // return 15
+bSTIterator.hasNext(); // return True
+bSTIterator.next();    // return 20
+bSTIterator.hasNext(); // return False
+
+ +

 

+

Constraints:

+ + + +

 

+

Follow up:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/179.md b/rustgym/desc/leetcode/d1/179.md new file mode 100644 index 00000000..122e5f60 --- /dev/null +++ b/rustgym/desc/leetcode/d1/179.md @@ -0,0 +1,37 @@ +

Given a list of non-negative integers nums, arrange them such that they form the largest number.

+ +

Note: The result may be very large, so you need to return a string instead of an integer.

+ +

 

+

Example 1:

+ +
Input: nums = [10,2]
+Output: "210"
+
+ +

Example 2:

+ +
Input: nums = [3,30,34,5,9]
+Output: "9534330"
+
+ +

Example 3:

+ +
Input: nums = [1]
+Output: "1"
+
+ +

Example 4:

+ +
Input: nums = [10]
+Output: "10"
+
+ +

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/186.md b/rustgym/desc/leetcode/d1/186.md new file mode 100644 index 00000000..8bcc3844 --- /dev/null +++ b/rustgym/desc/leetcode/d1/186.md @@ -0,0 +1,17 @@ +

Given an input string , reverse the string word by word. 

+ +

Example:

+ +
Input:  ["t","h","e"," ","s","k","y"," ","i","s"," ","b","l","u","e"]
+Output: ["b","l","u","e"," ","i","s"," ","s","k","y"," ","t","h","e"]
+ +

Note: 

+ + + +

Follow up: Could you do it in-place without allocating extra space?

+
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/187.md b/rustgym/desc/leetcode/d1/187.md new file mode 100644 index 00000000..e09a61e5 --- /dev/null +++ b/rustgym/desc/leetcode/d1/187.md @@ -0,0 +1,20 @@ +

All DNA is composed of a series of nucleotides abbreviated as 'A', 'C', 'G', and 'T', for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.

+ +

Write a function to find all the 10-letter-long sequences (substrings) that occur more than once in a DNA molecule.

+ +

 

+

Example 1:

+
Input: s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT"
+Output: ["AAAAACCCCC","CCCCCAAAAA"]
+

Example 2:

+
Input: s = "AAAAAAAAAAAAA"
+Output: ["AAAAAAAAAA"]
+
+

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/188.md b/rustgym/desc/leetcode/d1/188.md new file mode 100644 index 00000000..a4f48fa0 --- /dev/null +++ b/rustgym/desc/leetcode/d1/188.md @@ -0,0 +1,30 @@ +

You are given an integer array prices where prices[i] is the price of a given stock on the ith day.

+ +

Design an algorithm to find the maximum profit. You may complete at most k transactions.

+ +

Notice that you may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).

+ +

 

+

Example 1:

+ +
Input: k = 2, prices = [2,4,1]
+Output: 2
+Explanation: Buy on day 1 (price = 2) and sell on day 2 (price = 4), profit = 4-2 = 2.
+
+ +

Example 2:

+ +
Input: k = 2, prices = [3,2,6,5,0,3]
+Output: 7
+Explanation: Buy on day 2 (price = 2) and sell on day 3 (price = 6), profit = 6-2 = 4. Then buy on day 5 (price = 0) and sell on day 6 (price = 3), profit = 3-0 = 3.
+
+ +

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/189.md b/rustgym/desc/leetcode/d1/189.md new file mode 100644 index 00000000..e3f8d46c --- /dev/null +++ b/rustgym/desc/leetcode/d1/189.md @@ -0,0 +1,38 @@ +

Given an array, rotate the array to the right by k steps, where k is non-negative.

+ +

Follow up:

+ + + +

 

+

Example 1:

+ +
Input: nums = [1,2,3,4,5,6,7], k = 3
+Output: [5,6,7,1,2,3,4]
+Explanation:
+rotate 1 steps to the right: [7,1,2,3,4,5,6]
+rotate 2 steps to the right: [6,7,1,2,3,4,5]
+rotate 3 steps to the right: [5,6,7,1,2,3,4]
+
+ +

Example 2:

+ +
Input: nums = [-1,-100,3,99], k = 2
+Output: [3,99,-1,-100]
+Explanation: 
+rotate 1 steps to the right: [99,-1,-100,3]
+rotate 2 steps to the right: [3,99,-1,-100]
+
+ +

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/191.md b/rustgym/desc/leetcode/d1/191.md new file mode 100644 index 00000000..a99c3519 --- /dev/null +++ b/rustgym/desc/leetcode/d1/191.md @@ -0,0 +1,40 @@ +

Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight).

+ +

Note:

+ + + +

Follow up: If this function is called many times, how would you optimize it?

+ +

 

+

Example 1:

+ +
Input: n = 00000000000000000000000000001011
+Output: 3
+Explanation: The input binary string 00000000000000000000000000001011 has a total of three '1' bits.
+
+ +

Example 2:

+ +
Input: n = 00000000000000000000000010000000
+Output: 1
+Explanation: The input binary string 00000000000000000000000010000000 has a total of one '1' bit.
+
+ +

Example 3:

+ +
Input: n = 11111111111111111111111111111101
+Output: 31
+Explanation: The input binary string 11111111111111111111111111111101 has a total of thirty one '1' bits.
+
+ +

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/198.md b/rustgym/desc/leetcode/d1/198.md new file mode 100644 index 00000000..ab96e31b --- /dev/null +++ b/rustgym/desc/leetcode/d1/198.md @@ -0,0 +1,29 @@ +

You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into on the same night.

+ +

Given a list of non-negative integers representing the amount of money of each house, determine the maximum amount of money you can rob tonight without alerting the police.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,3,1]
+Output: 4
+Explanation: Rob house 1 (money = 1) and then rob house 3 (money = 3).
+             Total amount you can rob = 1 + 3 = 4.
+
+ +

Example 2:

+ +
Input: nums = [2,7,9,3,1]
+Output: 12
+Explanation: Rob house 1 (money = 2), rob house 3 (money = 9) and rob house 5 (money = 1).
+             Total amount you can rob = 2 + 9 + 1 = 12.
+
+ +

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/rustgym/desc/leetcode/d1/199.md b/rustgym/desc/leetcode/d1/199.md new file mode 100644 index 00000000..2ff004f5 --- /dev/null +++ b/rustgym/desc/leetcode/d1/199.md @@ -0,0 +1,14 @@ +

Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.

+ +

Example:

+ +
Input: [1,2,3,null,5,null,4]
+Output: [1, 3, 4]
+Explanation:
+
+   1            <---
+ /   \
+2     3         <---
+ \     \
+  5     4       <---
+
\ No newline at end of file