Skip to content

Commit

Permalink
docs: update code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
yanglbme committed Jan 18, 2022
1 parent 87718b6 commit 27129fd
Show file tree
Hide file tree
Showing 19 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lcof/面试题03. 数组中重复的数字/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function swap(nums: number[], i: number, j: number): void {

### **Rust**

```rs
```rust
impl Solution {
pub fn find_repeat_number(mut nums: Vec<i32>) -> i32 {
for i in 0..nums.len() {
Expand Down
4 changes: 4 additions & 0 deletions lcof2/剑指 Offer II 035. 最小时间差/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@

<!-- 这里可写通用的实现逻辑 -->

我们注意到,时间点最多只有 `24 * 60` 个,因此,当 timePoints 长度超过 `24 * 60`,说明有重复的时间点,提前返回 0。

接下来:

首先,遍历时间列表,将其转换为“分钟制”列表 `mins`,比如,对于时间点 `13:14`,将其转换为 `13 * 60 + 14`

接着将“分钟制”列表按升序排列,然后将此列表的最小时间 `mins[0]` 加上 `24 * 60` 追加至列表尾部,用于处理最大值、最小值的差值这种特殊情况。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ for (int i = 0; i < len; i++) {

原问题要求最多相同的数字最多出现 1 次,我们可以扩展至相同的数字最多保留 k 个。

- 由于相同的数字最多保留 k 个,那么原数组的前 k 个元素我们可以直接保留;
- 对于后面的数字,能够保留的前提是:当前数字 num 与前面已保留的数字的倒数第 k 个元素比较,不同则保留,相同则跳过。
- 由于相同的数字最多保留 k 个,那么原数组的前 k 个元素我们可以直接保留;
- 对于后面的数字,能够保留的前提是:当前数字 num 与前面已保留的数字的倒数第 k 个元素比较,不同则保留,相同则跳过。

相似题目:[80. 删除有序数组中的重复项 II](/solution/0000-0099/0080.Remove%20Duplicates%20from%20Sorted%20Array%20II/README.md)

Expand Down Expand Up @@ -173,7 +173,7 @@ public class Solution {

### **Rust**

```rs
```rust
impl Solution {
pub fn remove_duplicates(nums: &mut Vec<i32>) -> i32 {
let mut len = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public class Solution {

### **Rust**

```rs
```rust
impl Solution {
pub fn remove_duplicates(nums: &mut Vec<i32>) -> i32 {
let mut len = 0;
Expand Down
2 changes: 1 addition & 1 deletion solution/0000-0099/0027.Remove Element/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func removeElement(nums []int, val int) int {

### **Rust**

```rs
```rust
impl Solution {
pub fn remove_element(nums: &mut Vec<i32>, val: i32) -> i32 {
let mut len = 0;
Expand Down
2 changes: 1 addition & 1 deletion solution/0000-0099/0027.Remove Element/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func removeElement(nums []int, val int) int {

### **Rust**

```rs
```rust
impl Solution {
pub fn remove_element(nums: &mut Vec<i32>, val: i32) -> i32 {
let mut len = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ for (int i = 0; i < len; i++) {

原问题要求最多相同的数字最多出现 2 次,我们可以扩展至相同的数字最多保留 k 个。

- 由于相同的数字最多保留 k 个,那么原数组的前 k 个元素我们可以直接保留;
- 对于后面的数字,能够保留的前提是:当前数字 num 与前面已保留的数字的倒数第 k 个元素比较,不同则保留,相同则跳过。
- 由于相同的数字最多保留 k 个,那么原数组的前 k 个元素我们可以直接保留;
- 对于后面的数字,能够保留的前提是:当前数字 num 与前面已保留的数字的倒数第 k 个元素比较,不同则保留,相同则跳过。

相似题目:[26. 删除有序数组中的重复项](/solution/0000-0099/0026.Remove%20Duplicates%20from%20Sorted%20Array/README.md)

Expand Down Expand Up @@ -173,7 +173,7 @@ func removeDuplicates(nums []int) int {

### **Rust**

```rs
```rust
impl Solution {
pub fn remove_duplicates(nums: &mut Vec<i32>) -> i32 {
let mut len = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func removeDuplicates(nums []int) int {

### **Rust**

```rs
```rust
impl Solution {
pub fn remove_duplicates(nums: &mut Vec<i32>) -> i32 {
let mut len = 0;
Expand Down
2 changes: 1 addition & 1 deletion solution/0100-0199/0169.Majority Element/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func majorityElement(nums []int) int {

### **Rust**

```rs
```rust
impl Solution {
pub fn majority_element(nums: Vec<i32>) -> i32 {
let mut major = 0;
Expand Down
2 changes: 1 addition & 1 deletion solution/0100-0199/0169.Majority Element/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func majorityElement(nums []int) int {

### **Rust**

```rs
```rust
impl Solution {
pub fn majority_element(nums: Vec<i32>) -> i32 {
let mut major = 0;
Expand Down
2 changes: 1 addition & 1 deletion solution/0100-0199/0189.Rotate Array/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func reverse(nums []int, i, j int) {

### **Rust**

```rs
```rust
impl Solution {
pub fn rotate(nums: &mut Vec<i32>, k: i32) {
let n = nums.len();
Expand Down
2 changes: 1 addition & 1 deletion solution/0100-0199/0189.Rotate Array/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func reverse(nums []int, i, j int) {

### **Rust**

```rs
```rust
impl Solution {
pub fn rotate(nums: &mut Vec<i32>, k: i32) {
let n = nums.len();
Expand Down
2 changes: 1 addition & 1 deletion solution/0200-0299/0283.Move Zeroes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ var moveZeroes = function (nums) {

### **Rust**

```rs
```rust
impl Solution {
pub fn move_zeroes(nums: &mut Vec<i32>) {
let mut i = 0;
Expand Down
2 changes: 1 addition & 1 deletion solution/0200-0299/0283.Move Zeroes/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ var moveZeroes = function (nums) {

### **Rust**

```rs
```rust
impl Solution {
pub fn move_zeroes(nums: &mut Vec<i32>) {
let mut i = 0;
Expand Down
2 changes: 1 addition & 1 deletion solution/0500-0599/0528.Random Pick with Weight/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ Solution.prototype.pickIndex = function () {

### **Rust**

```rs
```rust
use rand::{thread_rng, Rng};

struct Solution {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ Solution.prototype.pickIndex = function () {

### **Rust**

```rs
```rust
use rand::{thread_rng, Rng};

struct Solution {
Expand Down
4 changes: 4 additions & 0 deletions solution/0500-0599/0539.Minimum Time Difference/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@

<!-- 这里可写通用的实现逻辑 -->

我们注意到,时间点最多只有 `24 * 60` 个,因此,当 timePoints 长度超过 `24 * 60`,说明有重复的时间点,提前返回 0。

接下来:

首先,遍历时间列表,将其转换为“分钟制”列表 `mins`,比如,对于时间点 `13:14`,将其转换为 `13 * 60 + 14`

接着将“分钟制”列表按升序排列,然后将此列表的最小时间 `mins[0]` 加上 `24 * 60` 追加至列表尾部,用于处理最大值、最小值的差值这种特殊情况。
Expand Down
2 changes: 1 addition & 1 deletion solution/1000-1099/1036.Escape a Large Maze/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func isEscapePossible(blocked [][]int, source []int, target []int) bool {

### **Rust**

```rs
```rust
use std::collections::{HashSet, VecDeque};

const BOUNDARY: i32 = 1_000_000;
Expand Down
2 changes: 1 addition & 1 deletion solution/1000-1099/1036.Escape a Large Maze/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func isEscapePossible(blocked [][]int, source []int, target []int) bool {

### **Rust**

```rs
```rust
use std::collections::{HashSet, VecDeque};

const BOUNDARY: i32 = 1_000_000;
Expand Down

0 comments on commit 27129fd

Please sign in to comment.