mirror of
https://github.com/prdlk/leetcode.git
synced 2026-09-16 23:16:26 +00:00
docs(docs): add study decks, new reference pages, and fix header image path
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<p align="center">
|
<p align="center">
|
||||||
<img alt="header" src=".github/assets/dependency-spine.svg" />
|
<img alt="header" src=".public/dependency-spine.svg" />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
|
|||||||
@@ -63,3 +63,9 @@ Random access in this context means that you can access an element at any index
|
|||||||
</Columns>
|
</Columns>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Study deck
|
||||||
|
|
||||||
|
Drill the essentials — click the deck, then use the arrow keys.
|
||||||
|
|
||||||
|
<StudyDeck deck="arrays-and-strings" />
|
||||||
|
|||||||
@@ -28,3 +28,9 @@ Appending to the end of a list is amortized O(1) time complexity. This means tha
|
|||||||
Random access in this context means that you can access an element at any index in constant time.
|
Random access in this context means that you can access an element at any index in constant time.
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
|
||||||
|
## Study deck
|
||||||
|
|
||||||
|
Drill the essentials — click the deck, then use the arrow keys.
|
||||||
|
|
||||||
|
<StudyDeck deck="hashing" />
|
||||||
|
|||||||
@@ -28,3 +28,9 @@ Appending to the end of a list is amortized O(1) time complexity. This means tha
|
|||||||
Random access in this context means that you can access an element at any index in constant time.
|
Random access in this context means that you can access an element at any index in constant time.
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
|
||||||
|
## Study deck
|
||||||
|
|
||||||
|
Drill the essentials — click the deck, then use the arrow keys.
|
||||||
|
|
||||||
|
<StudyDeck deck="binary-search" />
|
||||||
|
|||||||
@@ -12,3 +12,9 @@ This page is a scaffold. Notes, canonical problems, and template code are not wr
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Study deck
|
||||||
|
|
||||||
|
Drill the essentials — click the deck, then use the arrow keys.
|
||||||
|
|
||||||
|
<StudyDeck deck="two-pointers" />
|
||||||
|
|||||||
@@ -6,3 +6,9 @@ description: 'Precomputed cumulative state for O(1) range queries.'
|
|||||||
:::warning[Under construction]
|
:::warning[Under construction]
|
||||||
This page is a scaffold. Notes, canonical problems, and template code are not written yet.
|
This page is a scaffold. Notes, canonical problems, and template code are not written yet.
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
## Study deck
|
||||||
|
|
||||||
|
Drill the essentials — click the deck, then use the arrow keys.
|
||||||
|
|
||||||
|
<StudyDeck deck="prefix-sum" />
|
||||||
|
|||||||
@@ -6,3 +6,9 @@ description: 'Two pointers plus incremental state between them.'
|
|||||||
:::warning[Under construction]
|
:::warning[Under construction]
|
||||||
This page is a scaffold. Notes, canonical problems, and template code are not written yet.
|
This page is a scaffold. Notes, canonical problems, and template code are not written yet.
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
## Study deck
|
||||||
|
|
||||||
|
Drill the essentials — click the deck, then use the arrow keys.
|
||||||
|
|
||||||
|
<StudyDeck deck="sliding-window" />
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
---
|
||||||
|
title: '344. Reverse String'
|
||||||
|
description: Write a function that reverses a string. The input string is given as an array of characters s
|
||||||
|
sidebar:
|
||||||
|
badge: 'Easy'
|
||||||
|
---
|
||||||
|
|
||||||
|
<Badge variant="accent">Two Pointers</Badge>
|
||||||
|
|
||||||
|
:::warning
|
||||||
|
You must do this by modifying the input array in-place with O(1) extra memory.
|
||||||
|
:::
|
||||||
|
|
||||||
|
### Example 1:
|
||||||
|
- Input: `s = ["h","e","l","l","o"]`
|
||||||
|
- Output: `["o","l","l","e","h"]`
|
||||||
|
|
||||||
|
### Example 2:
|
||||||
|
- Input: `s = ["H","a","n","n","a","h"]`
|
||||||
|
- Output: `["h","a","n","n","a","H"]`
|
||||||
|
|
||||||
|
### Constraints:
|
||||||
|
|
||||||
|
- `1 <= s.length <= 10^5`
|
||||||
|
- `s[i]` is a printable ascii character.
|
||||||
|
|
||||||
|
## Solution
|
||||||
|
|
||||||
|
```js
|
||||||
|
/**
|
||||||
|
* @param {character[]} s
|
||||||
|
* @return {void} Do not return anything, modify s in-place instead.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var reverseString = function(s) {
|
||||||
|
let i = 0;
|
||||||
|
let j = s.length - 1;
|
||||||
|
|
||||||
|
while (i < j) {
|
||||||
|
[s[i], s[j]] = [s[j], s[i]];
|
||||||
|
j--;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
```
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
---
|
||||||
|
title: '977. Squares of a Sorted Array'
|
||||||
|
description: Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order
|
||||||
|
sidebar:
|
||||||
|
badge: 'Easy'
|
||||||
|
---
|
||||||
|
|
||||||
|
<Badge variant="accent">Two Pointers</Badge>
|
||||||
|
|
||||||
|
::::warning
|
||||||
|
Squaring each element and sorting the new array is very trivial, could you find an O(n) solution using a different approach?
|
||||||
|
::::
|
||||||
|
|
||||||
|
### Example 1:
|
||||||
|
- Input: `nums = [-4,-1,0,3,10]`
|
||||||
|
- Output: `[0,1,9,16,100]`
|
||||||
|
- Explanation: After squaring, the array becomes `[16,1,0,9,100]`. After sorting, it becomes `[0,1,9,16,100]`.
|
||||||
|
|
||||||
|
### Example 2:
|
||||||
|
- Input: `nums = [-7,-3,2,3,11]`
|
||||||
|
- Output: `[4,9,9,49,121]`
|
||||||
|
|
||||||
|
### Constraints:
|
||||||
|
|
||||||
|
- `1 <= nums.length <= 10^4`
|
||||||
|
- `-10^4 <= nums[i] <= 10^4`
|
||||||
|
- `nums` is sorted in non-decreasing order.
|
||||||
|
|
||||||
|
## Solution
|
||||||
|
|
||||||
|
```js
|
||||||
|
/**
|
||||||
|
* @param {number[]} nums
|
||||||
|
* @return {number[]}
|
||||||
|
*/
|
||||||
|
var sortedSquares = function(nums) {
|
||||||
|
let n = nums.length;
|
||||||
|
let ans = new Array(nums.length);
|
||||||
|
let left = 0, right = nums.length - 1;
|
||||||
|
|
||||||
|
for (let i = n -1; i >= 0; i--){
|
||||||
|
let square;
|
||||||
|
if(Math.abs(nums[left]) < Math.abs(nums[right])){
|
||||||
|
square = nums[right];
|
||||||
|
right--;
|
||||||
|
}else{
|
||||||
|
square = nums[left];
|
||||||
|
left++;
|
||||||
|
}
|
||||||
|
ans[i] = square*square;
|
||||||
|
}
|
||||||
|
return ans;
|
||||||
|
};
|
||||||
|
```
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
---
|
|
||||||
title: '344. Reverse String'
|
|
||||||
sidebar:
|
|
||||||
badge: 'Easy'
|
|
||||||
---
|
|
||||||
|
|
||||||
<Badge variant="accent">Two Pointers</Badge>
|
|
||||||
<Badge>[Source](https://leetcode.com/problems/reverse-string/)</Badge>
|
|
||||||
|
|
||||||
## Description
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
sidebar:
|
|
||||||
icon: code
|
|
||||||
badge: '977'
|
|
||||||
---
|
|
||||||
Reference in New Issue
Block a user