Skip to content

Commit 8f47772

Browse files
authored
update: 添加问题“1266.访问所有点的最小时间”的代码和题解 (#1321)
* archive: before.换设备 * 1266: AC.cpp+py+java+go+rust (#1321) (#1318) + word(en) cpp - AC,100.00%,16.04% py - AC,100.00%,5.26% java - AC,91.80%,8.20% go - AC,100.00%,85.71% rust - AC,100.00%,75.00% * update: 添加问题“1266.访问所有点的最小时间”的代码和题解 (#1321) Signed-off-by: LetMeFly666 <Tisfy@qq.com> --------- Signed-off-by: LetMeFly666 <Tisfy@qq.com>
1 parent 6e814a6 commit 8f47772

12 files changed

Lines changed: 297 additions & 42 deletions

.commitTitleExtra

Lines changed: 0 additions & 1 deletion
This file was deleted.

.commitmsg

Lines changed: 0 additions & 3 deletions
This file was deleted.

.github/workflows/deployHexo.yml

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
uses: actions/checkout@v3
3737
with:
3838
persist-credentials: true
39-
fetch-depth: 1
39+
fetch-depth: 2
4040

4141
- name: Whether Skip Deploy(.nodeploy|filePath)
4242
id: deploy-check
@@ -78,6 +78,7 @@ jobs:
7878
- name: Fetch and checkout each branch (shallow)
7979
if: env.SKIP_DEPLOY != 'true'
8080
run: |
81+
# TODO: Let's change this(only needed branch)
8182
# git clone git@github.com:LetMeFly666/LeetCode.git --depth=1
8283
# cd LeetCode
8384
# git rev-list --count HEAD
@@ -169,51 +170,56 @@ jobs:
169170
run: |
170171
set -e
171172
172-
json_file="../website_modifyTime/LastModifiedTime.json"
173+
# git rev-list --count HEAD
174+
json_file_name="LastModifiedTime.json"
175+
json_file="../website_modifyTime/$json_file_name"
173176
174-
# 获取本次 push 里 master 分支变动的文件列表
175-
# TODO: Let's处理删除removed
176-
# TODO: Let's solve this
177-
echo '${{ toJSON(github.event) }}' | jq .
178-
changed_files=$(jq -r '
179-
[
180-
.commits[].added[]?,
181-
.commits[].modified[]?
182-
]
183-
| unique
184-
| .[]
185-
' "$GITHUB_EVENT_PATH")
186-
echo "Changed files:"
187-
echo "$changed_files"
177+
if [ -f "$json_file" ]; then
178+
json_content=$(cat "$json_file")
179+
else
180+
json_content='{}'
181+
echo "original Modified Json File Not exists"
182+
fi
188183
189-
# 保存原 json 内容顺序
190-
tmp_json=$(mktemp)
191-
cp "$json_file" "$tmp_json"
184+
commit_time=$(git show -s --format=%cI HEAD)
185+
echo "Commit time: $commit_time"
192186
193-
# 遍历每个文件,看是否是 Solutions 下的 md 文件
194-
updated=false
195-
commit_time=$(git show -s --format=%cI ${{ github.sha }}) # ISO 8601 commit 时间
187+
has_modified=false
188+
while read -r status file; do
189+
[[ "$file" == Solutions/*.md ]] || continue
196190
197-
while IFS= read -r file; do
198-
# 只处理 Solutions/*.md 文件
199-
if [[ "$file" == Solutions/*.md ]]; then
200-
filename=$(basename "$file")
201-
# 使用 jq 更新 JSON 值
202-
# 保持原有顺序,用临时文件写回
203-
jq --arg key "$filename" --arg value "$commit_time" '(.[$key] = $value) | .' "$tmp_json" > "$tmp_json.tmp" && mv "$tmp_json.tmp" "$tmp_json"
204-
updated=true
205-
fi
206-
done <<< "$changed_files"
191+
filename=$(basename "$file")
192+
has_modified=true
193+
194+
case "$status" in
195+
A|M)
196+
echo "Updated $filename"
197+
json_content=$(echo "$json_content" | jq \
198+
--arg k "$filename" \
199+
--arg v "$commit_time" \
200+
'. + {($k): $v}')
201+
;;
202+
D)
203+
echo "Deleted $filename"
204+
json_content=$(echo "$json_content" | jq \
205+
--arg k "$filename" \
206+
'del(.[$k])')
207+
;;
208+
esac
209+
done < <(git diff --name-status HEAD~1 HEAD)
207210
208-
if [ "$updated" != true ]; then
209-
echo "No Solutions/*.md file changed, skip JSON update."
211+
if [ "$has_modified" = false ]; then
212+
echo "no modified Solutions/*.md files"
210213
exit 0
211214
fi
212215
216+
# 按 key 字典序排序并写回
217+
jq -S --indent 4 '.' <<<"$json_content" > "$json_file"
218+
echo "Updated $json_file"
219+
213220
# 提交修改
214-
cp "$tmp_json" "$json_file"
215221
cd ../website_modifyTime
216-
git add "$json_file"
222+
git add "$json_file_name"
217223
TOCOMMIT=$(printf "%s\n\n%s" "$MESSAGE" "$HASH")
218224
git commit --allow-empty -m "$TOCOMMIT"
219225
git push
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2026-01-12 23:24:06
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-01-12 23:28:12
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
public:
13+
int minTimeToVisitAllPoints(vector<vector<int>>& points) {
14+
int ans = 0;
15+
for (int i = 1; i < points.size(); i++) {
16+
ans += max(abs(points[i][0] - points[i - 1][0]), abs(points[i][1] - points[i - 1][1]));
17+
}
18+
return ans;
19+
}
20+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2026-01-12 23:24:06
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-01-12 23:35:23
6+
*/
7+
package main
8+
9+
func abs1266(a int) int {
10+
if a < 0 {
11+
return -a
12+
}
13+
return a
14+
}
15+
16+
func minTimeToVisitAllPoints(points [][]int) (ans int) {
17+
for i := 1; i < len(points); i++ {
18+
ans += max(abs1266(points[i][0] - points[i - 1][0]), abs1266(points[i][1] - points[i - 1][1]))
19+
}
20+
return
21+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2026-01-12 23:24:06
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-01-12 23:32:59
6+
*/
7+
class Solution {
8+
public int minTimeToVisitAllPoints(int[][] points) {
9+
int ans = 0;
10+
for (int i = 1; i < points.length; i++) {
11+
ans += Math.max(Math.abs(points[i][0] - points[i - 1][0]) , Math.abs(points[i][1] - points[i - 1][1]));
12+
}
13+
return ans;
14+
}
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2026-01-12 23:24:06
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2026-01-12 23:32:26
6+
'''
7+
from typing import List
8+
from itertools import pairwise
9+
10+
class Solution:
11+
def minTimeToVisitAllPoints(self, points: List[List[int]]) -> int:
12+
return sum(max(abs(a[0] - b[0]), abs(a[1] - b[1])) for a, b in pairwise(points))
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2026-01-12 23:24:06
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-01-12 23:37:10
6+
*/
7+
impl Solution {
8+
pub fn min_time_to_visit_all_points(points: Vec<Vec<i32>>) -> i32 {
9+
let mut ans: i32 = 0;
10+
for i in 1..points.len() {
11+
ans += (points[i][0] - points[i - 1][0]).abs().max((points[i][1] - points[i - 1][1]).abs());
12+
}
13+
ans
14+
}
15+
}

Codes/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @LastEditTime: 2026-01-06 13:17:16
66
*/
77
pub struct Solution;
8-
include!("1458-max-dot-product-of-two-subsequences.rs"); // 这个fileName是会被脚本替换掉的
8+
include!("1266-minimum-time-visiting-all-points.rs"); // 这个fileName是会被脚本替换掉的
99

1010
#[derive(Debug, PartialEq, Eq)]
1111
pub struct TreeNode {

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@
533533
|1260.二维网格迁移|简单|<a href="https://leetcode.cn/problems/shift-2d-grid/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2022/07/20/LeetCode%201260.%E4%BA%8C%E7%BB%B4%E7%BD%91%E6%A0%BC%E8%BF%81%E7%A7%BB/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/125889225" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/shift-2d-grid/solution/by-tisfy-7fsm/" target="_blank">LeetCode题解</a>|
534534
|1261.在受污染的二叉树中查找元素|中等|<a href="https://leetcode.cn/problems/find-elements-in-a-contaminated-binary-tree/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/03/12/LeetCode%201261.%E5%9C%A8%E5%8F%97%E6%B1%A1%E6%9F%93%E7%9A%84%E4%BA%8C%E5%8F%89%E6%A0%91%E4%B8%AD%E6%9F%A5%E6%89%BE%E5%85%83%E7%B4%A0/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/136642314" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-elements-in-a-contaminated-binary-tree/solutions/2681786/letmefly-1261zai-shou-wu-ran-de-er-cha-s-fcb0/" target="_blank">LeetCode题解</a>|
535535
|1262.可被三整除的最大和|中等|<a href="https://leetcode.cn/problems/greatest-sum-divisible-by-three/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2023/06/19/LeetCode%201262.%E5%8F%AF%E8%A2%AB%E4%B8%89%E6%95%B4%E9%99%A4%E7%9A%84%E6%9C%80%E5%A4%A7%E5%92%8C/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/131290984" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/greatest-sum-divisible-by-three/solutions/2314201/letmefly-1262ke-bei-san-zheng-chu-de-zui-wyt8/" target="_blank">LeetCode题解</a>|
536+
|1266.访问所有点的最小时间|简单|<a href="https://leetcode.cn/problems/minimum-time-visiting-all-points/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2026/01/12/LeetCode%201266.%E8%AE%BF%E9%97%AE%E6%89%80%E6%9C%89%E7%82%B9%E7%9A%84%E6%9C%80%E5%B0%8F%E6%97%B6%E9%97%B4/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/156875167" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/minimum-time-visiting-all-points/solutions/3879062/letmefly-1266fang-wen-suo-you-dian-de-zu-lorr/" target="_blank">LeetCode题解</a>|
536537
|1267.统计参与通信的服务器|中等|<a href="https://leetcode.cn/problems/count-servers-that-communicate/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2023/08/24/LeetCode%201267.%E7%BB%9F%E8%AE%A1%E5%8F%82%E4%B8%8E%E9%80%9A%E4%BF%A1%E7%9A%84%E6%9C%8D%E5%8A%A1%E5%99%A8/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/132466649" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/count-servers-that-communicate/solutions/2402129/letmefly-1267tong-ji-can-yu-tong-xin-de-5r3r8/" target="_blank">LeetCode题解</a>|
537538
|1276.不浪费原料的汉堡制作方案|中等|<a href="https://leetcode.cn/problems/number-of-burgers-with-no-waste-of-ingredients/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2023/12/25/LeetCode%201276.%E4%B8%8D%E6%B5%AA%E8%B4%B9%E5%8E%9F%E6%96%99%E7%9A%84%E6%B1%89%E5%A0%A1%E5%88%B6%E4%BD%9C%E6%96%B9%E6%A1%88/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/135196793" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/number-of-burgers-with-no-waste-of-ingredients/solutions/2579080/letmefly-1276bu-lang-fei-yuan-liao-de-yi-b1t2/" target="_blank">LeetCode题解</a>|
538539
|1278.分割回文串III|困难|<a href="https://leetcode.cn/problems/palindrome-partitioning-iii/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/03/03/LeetCode%201278.%E5%88%86%E5%89%B2%E5%9B%9E%E6%96%87%E4%B8%B2III/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/145986494" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/palindrome-partitioning-iii/solutions/3593573/letmefly-1278fen-ge-hui-wen-chuan-iiidon-c0va/" target="_blank">LeetCode题解</a>|

0 commit comments

Comments
 (0)