Skip to content

Commit a211dc9

Browse files
committed
update: 添加问题“1886.判断矩阵经轮转后是否一致”的代码和题解 (#1458)
1886: AC.cpp (#1457) - AC,100.00%,13.25% this time we had a new line before the cpp file. Signed-off-by: LetMeFly666 <Tisfy@qq.com>
1 parent 4f066cf commit a211dc9

13 files changed

Lines changed: 888 additions & 1 deletion

.commitmsg

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
3643: AC.cpp (#1455) - AC,23.97%,12.77%
1+
1886: AC.cpp (#1457) - AC,100.00%,13.25%
2+
3+
this time we had a new line before the cpp file.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2026-03-22 23:35:27
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-03-22 23:44:12
6+
*/
7+
#ifdef _DEBUG
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
// THIS CANNOT BE ACCEPTED
12+
class Solution {
13+
private:
14+
int n = 0;
15+
vector<vector<int>>& rotate(vector<vector<int>>& original) {
16+
if (!n) {
17+
n = original.size();
18+
}
19+
vector<vector<int>> ans(n, vector<int>(n));
20+
for (int i = 0; i < n; i++) {
21+
for (int j = 0; j < n; j++) {
22+
ans[i][j] = original[j][n - i - 1];
23+
}
24+
}
25+
return ans;
26+
}
27+
public:
28+
bool findRotation(vector<vector<int>>& mat, vector<vector<int>>& target) {
29+
if (mat == target) {
30+
return true;
31+
}
32+
for (int _ = 0; _ < 3; _++) {
33+
mat = rotate(mat);
34+
if (mat == target) {
35+
return true;
36+
}
37+
}
38+
return false;
39+
}
40+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2026-03-22 23:35:27
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-03-22 23:45:34
6+
*/
7+
#ifdef _DEBUG
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
public:
13+
bool findRotation(vector<vector<int>>& mat, vector<vector<int>>& target) {
14+
int n = mat.size();
15+
for (int t = 0; t < 4; t++) {
16+
if (mat == target) {
17+
return true;
18+
}
19+
if (t == 4) {
20+
break;
21+
}
22+
vector<vector<int>> tmp(n, vector<int>(n));
23+
for (int i = 0; i < n; i++) {
24+
for (int j = 0; j < n; j++) {
25+
tmp[i][j] = mat[j][n - i - 1];
26+
}
27+
}
28+
mat.swap(tmp);
29+
}
30+
return false;
31+
}
32+
};

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,7 @@
701701
|1877.数组中最大数对和的最小值|中等|<a href="https://leetcode.cn/problems/minimize-maximum-pair-sum-in-array/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2026/01/24/LeetCode%201877.%E6%95%B0%E7%BB%84%E4%B8%AD%E6%9C%80%E5%A4%A7%E6%95%B0%E5%AF%B9%E5%92%8C%E7%9A%84%E6%9C%80%E5%B0%8F%E5%80%BC/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/157333871" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/minimize-maximum-pair-sum-in-array/solutions/3888405/letmefly-1877shu-zu-zhong-zui-da-shu-dui-sm70/" target="_blank">LeetCode题解</a>|
702702
|1878.矩阵中最大的三个菱形和|中等|<a href="https://leetcode.cn/problems/get-biggest-three-rhombus-sums-in-a-grid/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2026/03/17/LeetCode%201878.%E7%9F%A9%E9%98%B5%E4%B8%AD%E6%9C%80%E5%A4%A7%E7%9A%84%E4%B8%89%E4%B8%AA%E8%8F%B1%E5%BD%A2%E5%92%8C/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/159162029" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/get-biggest-three-rhombus-sums-in-a-grid/solutions/3928252/letmefly-1878ju-zhen-zhong-zui-da-de-san-yi1y/" target="_blank">LeetCode题解</a>|
703703
|1884.鸡蛋掉落-两枚鸡蛋|中等|<a href="https://leetcode.cn/problems/egg-drop-with-2-eggs-and-n-floors/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/10/13/LeetCode%201884.%E9%B8%A1%E8%9B%8B%E6%8E%89%E8%90%BD-%E4%B8%A4%E6%9E%9A%E9%B8%A1%E8%9B%8B/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/142906976" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/egg-drop-with-2-eggs-and-n-floors/solutions/2949710/letmefly-1884ji-dan-diao-luo-liang-mei-j-saz6/" target="_blank">LeetCode题解</a>|
704+
|1886.判断矩阵经轮转后是否一致|简单|<a href="https://leetcode.cn/problems/determine-whether-matrix-can-be-obtained-by-rotation/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2026/03/22/LeetCode%201886.%E5%88%A4%E6%96%AD%E7%9F%A9%E9%98%B5%E7%BB%8F%E8%BD%AE%E8%BD%AC%E5%90%8E%E6%98%AF%E5%90%A6%E4%B8%80%E8%87%B4/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/159357841" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/determine-whether-matrix-can-be-obtained-by-rotation/solutions/3934051/letmefly-1886pan-duan-ju-zhen-jing-lun-z-2edt/" target="_blank">LeetCode题解</a>|
704705
|1888.使二进制字符串字符交替的最少反转次数|中等|<a href="https://leetcode.cn/problems/minimum-number-of-flips-to-make-the-binary-string-alternating/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2026/03/07/LeetCode%201888.%E4%BD%BF%E4%BA%8C%E8%BF%9B%E5%88%B6%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%AD%97%E7%AC%A6%E4%BA%A4%E6%9B%BF%E7%9A%84%E6%9C%80%E5%B0%91%E5%8F%8D%E8%BD%AC%E6%AC%A1%E6%95%B0/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/158813763" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/minimum-number-of-flips-to-make-the-binary-string-alternating/solutions/3918582/letmefly-1888shi-er-jin-zhi-zi-fu-chuan-8b104/" target="_blank">LeetCode题解</a>|
705706
|1895.最大的幻方|中等|<a href="https://leetcode.cn/problems/largest-magic-square/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2026/01/18/LeetCode%201895.%E6%9C%80%E5%A4%A7%E7%9A%84%E5%B9%BB%E6%96%B9/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/157104818" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/largest-magic-square/solutions/3883805/letmefly-1895zui-da-de-huan-fang-bao-li-9ln7k/" target="_blank">LeetCode题解</a>|
706707
|1901.寻找峰值II|中等|<a href="https://leetcode.cn/problems/find-a-peak-element-ii/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2023/12/19/LeetCode%201901.%E5%AF%BB%E6%89%BE%E5%B3%B0%E5%80%BCII/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/135083347" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-a-peak-element-ii/solutions/2572012/letmefly-1901xun-zhao-feng-zhi-iier-fen-19tmj/" target="_blank">LeetCode题解</a>|
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
title: 1886.判断矩阵经轮转后是否一致:模拟
3+
date: 2026-03-22 23:47:38
4+
tags: [题解, LeetCode, 简单, 数组, 矩阵]
5+
categories: [题解, LeetCode]
6+
index_img: https://assets.leetcode.com/uploads/2021/05/20/grid3.png
7+
---
8+
9+
# 【LetMeFly】1886.判断矩阵经轮转后是否一致:模拟
10+
11+
力扣题目链接:[https://leetcode.cn/problems/determine-whether-matrix-can-be-obtained-by-rotation/](https://leetcode.cn/problems/determine-whether-matrix-can-be-obtained-by-rotation/)
12+
13+
<p>给你两个大小为 <code>n x n</code> 的二进制矩阵 <code>mat</code> 和 <code>target</code> 。现<strong> 以 90 度顺时针轮转 </strong>矩阵 <code>mat</code> 中的元素 <strong>若干次</strong> ,如果能够使 <code>mat</code> 与 <code>target</code> 一致,返回 <code>true</code> ;否则,返回<em> </em><code>false</code><em> 。</em></p>
14+
15+
<p> </p>
16+
17+
<p><strong>示例 1:</strong></p>
18+
<img alt="" src="https://assets.leetcode.com/uploads/2021/05/20/grid3.png" style="width: 301px; height: 121px;" />
19+
<pre>
20+
<strong>输入:</strong>mat = [[0,1],[1,0]], target = [[1,0],[0,1]]
21+
<strong>输出:</strong>true
22+
<strong>解释:</strong>顺时针轮转 90 度一次可以使 mat 和 target 一致。
23+
</pre>
24+
25+
<p><strong>示例 2:</strong></p>
26+
<img alt="" src="https://assets.leetcode.com/uploads/2021/05/20/grid4.png" style="width: 301px; height: 121px;" />
27+
<pre>
28+
<strong>输入:</strong>mat = [[0,1],[1,1]], target = [[1,0],[0,1]]
29+
<strong>输出:</strong>false
30+
<strong>解释:</strong>无法通过轮转矩阵中的元素使 equal 与 target 一致。
31+
</pre>
32+
33+
<p><strong>示例 3:</strong></p>
34+
<img alt="" src="https://assets.leetcode.com/uploads/2021/05/26/grid4.png" style="width: 661px; height: 184px;" />
35+
<pre>
36+
<strong>输入:</strong>mat = [[0,0,0],[0,1,0],[1,1,1]], target = [[1,1,1],[0,1,0],[0,0,0]]
37+
<strong>输出:</strong>true
38+
<strong>解释:</strong>顺时针轮转 90 度两次可以使 mat 和 target 一致。
39+
</pre>
40+
41+
<p> </p>
42+
43+
<p><strong>提示:</strong></p>
44+
45+
<ul>
46+
<li><code>n == mat.length == target.length</code></li>
47+
<li><code>n == mat[i].length == target[i].length</code></li>
48+
<li><code>1 <= n <= 10</code></li>
49+
<li><code>mat[i][j]</code> 和 <code>target[i][j]</code> 不是 <code>0</code> 就是 <code>1</code></li>
50+
</ul>
51+
52+
53+
54+
## 解题方法:模拟
55+
56+
如何将矩阵顺时针旋转90度?
57+
58+
> 使用一个新矩阵,令新矩阵的`(i, j)`等于旧矩阵的`(j, n-i-1)`就好了。
59+
60+
旋转$3$次判断$4$次,本题结束。
61+
62+
+ 时间复杂度$O(n^2)$
63+
+ 空间复杂度$O(n^2)$
64+
65+
当然也有原地旋转矩阵的办法,如[48. 旋转图像](https://leetcode.cn/problems/rotate-image/)
66+
67+
### AC代码
68+
69+
#### C++
70+
71+
```cpp
72+
/*
73+
* @LastEditTime: 2026-03-22 23:45:34
74+
*/
75+
class Solution {
76+
public:
77+
bool findRotation(vector<vector<int>>& mat, vector<vector<int>>& target) {
78+
int n = mat.size();
79+
for (int t = 0; t < 4; t++) {
80+
if (mat == target) {
81+
return true;
82+
}
83+
if (t == 4) {
84+
break;
85+
}
86+
vector<vector<int>> tmp(n, vector<int>(n));
87+
for (int i = 0; i < n; i++) {
88+
for (int j = 0; j < n; j++) {
89+
tmp[i][j] = mat[j][n - i - 1];
90+
}
91+
}
92+
mat.swap(tmp);
93+
}
94+
return false;
95+
}
96+
};
97+
98+
```
99+
100+
> 同步发文于[CSDN](https://letmefly.blog.csdn.net/article/details/159357841)和我的[个人博客](https://blog.letmefly.xyz/),原创不易,转载经作者同意后请附上[原文链接](https://blog.letmefly.xyz/2026/03/22/LeetCode%201886.%E5%88%A4%E6%96%AD%E7%9F%A9%E9%98%B5%E7%BB%8F%E8%BD%AE%E8%BD%AC%E5%90%8E%E6%98%AF%E5%90%A6%E4%B8%80%E8%87%B4/)哦~
101+
>
102+
> 千篇源码题解[已开源](https://github.com/LetMeFly666/LeetCode)

Solutions/Other-Accumulation-SomeTips.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,32 @@ Chrome、Edge、Opera浏览器支持[`EyeDropper`API](https://developer.mozilla.
372372

373373
体验地址:[web.letmefly.xyz](https://web.letmefly.xyz/%E8%AE%A1%E7%AE%97%E6%9C%BACode/HTML%E7%94%B5%E8%84%91%E5%B1%8F%E5%B9%95%E5%8F%96%E8%89%B2%E5%99%A8/)。可查看网页源码,不难发现源码很简单。
374374

375+
### HTML渲染耗时问题
376+
377+
有这样一个HTML:
378+
379+
```html
380+
<html lang="zh"><head>
381+
<meta charset="UTF-8">
382+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
383+
<title>Protected Page</title>
384+
</head>
385+
<body>
386+
<!-- <script id="_d" type="text/plain">
387+
lHs0hIf559bXbGDNCBz1dzwAT+xxx这是一串60k的base64字符串
388+
</script> -->
389+
390+
</body></html>
391+
```
392+
393+
我有一个HTML需要
394+
395+
你猜在M3 Pro芯片的MacBook Pro的Chrome146.0.7680.153浏览器中打开需要多久?答案是平均5秒往上。
396+
397+
这么长一段都在注释中都很慢,所以最佳的方式也许是另外一个文件然后fetch。
398+
399+
但是,好像只在打开本地html时会很慢。
400+
375401
## About Linux
376402

377403
### Ubuntu防火墙
@@ -621,6 +647,19 @@ find /path/to/shared/folder -name ".DS_Store" -type f -delete
621647
killall Finder
622648
```
623649

650+
### Cmd+Space突然无法检索本地应用之Spotlight索引重建
651+
652+
不知是iCloud过期还是为何,最近`Command+空格`突然无法检索到本地应用,例如我输入个`iTerm`会出来“照片中1个结果”等等但就是没有我要找的应用。
653+
654+
于是:
655+
656+
```bash
657+
sudo mdutil -i off /Applications
658+
sudo mdutil -i on /Applications
659+
```
660+
661+
重建一下关于应用的索引,差不多好了。
662+
624663
## About Windows
625664

626665
### Windows应用商店安装的应用
@@ -1184,6 +1223,17 @@ censys扫描全球所有IP并记录ip与域名直接的关系,并且扫描速
11841223
11851224
参考链接:[dmesg.app](https://dmesg.app/cloudlare-real-ip.html)、[blog.gezi.men](https://blog.gezi.men/p/after-using-cloudflare-cdn-how-can-nginx-obtain-the-real-ip-address-of-website-visitors/)、[CSDN](https://blog.csdn.net/dragonballs/article/details/126345175)
11861225
1226+
### nginx自动寻找.html后缀的文件
1227+
1228+
例如我有一个hello.html,我希望用户访问`hello`路径时候就能得到这个html而非一定要访问`hello.html`路径的话,可以:
1229+
1230+
```conf
1231+
location / {
1232+
try_files $uri $uri/ $uri.html =404;
1233+
}
1234+
```
1235+
1236+
11871237
### certbot自动颁发TLS证书
11881238

11891239
Let's Encrypt提供免费的TLS证书以辅助站长实现https上网。

b.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<!--
2+
* @Author: LetMeFly
3+
* @Date: 2026-03-21 16:33:06
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-03-22 11:10:43
6+
-->
7+
我有一个HTML,想实现以下功能:
8+
9+
1. 将整个原始HTML加密,别人看源码也不知道是什么
10+
2. 提示“原页面被隐藏,输入“暗号”查看”
11+
3. 暗号也不能明文,可以验证输入内容hash后的结果之类的
12+
13+
14+
15+
1. 页面达到200k时,加载异常缓慢,有无办法优化下?如果没办法,就算了。
16+
2. 原页面200K,加密后约270k,如果能缩小点体积更好,如果不能就算了。
17+
18+
19+
20+
21+
我有一个logs数据库,帮我用golang设计个如下小服务:
22+
这个服务可以为HTML解密提供按键记录,你需要设计一个js,引用这个js后,用户在带有某class的input解密框里面输入的内容会被上传到服务端,服务端存储以供回溯。
23+
有一个页面可以查看用户猜测记录,但是需要密码保护。这个密码可以简单的在header中校验即可。页面也可以标记备注。
24+
记录内容包括ip、time、页面url(页面url可以做下简单的refer校验)
25+
我部署好了nginx代理,请使用127.0.0.1的8274端口,最终反向代理的地址是input.letmefly.xyz。
26+
27+
- 你需要设计一个专门的数据表来存放这些数据
28+
- golang最好不要使用第三方依赖
29+
- 并非每个按键都需要实时插入数据库,可以多个按键共用一条记录,时间记录个大概的时间就好。
30+
31+
32+
33+
34+
不要sqlite,我有部署数据库,要使用MySQL
35+
如果操作MySQL不得不使用第三方库,再使用
36+
以及告诉我如何创建一个只有logs表input库权限的用户 logs_input
37+
38+
以及,管理后台不要加/admin路径了,直接设计成https://input.letmefly.xyz吧
39+
40+
41+
42+
43+
44+
解密是很快,主要是页面初始化加载特别慢。
45+
刚开始白屏转好久,才会出现密码框
46+
47+
48+
49+
50+
51+
WARNING: /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/Resources/Python.app/Contents/MacOS/Python is loading libcrypto in an unsafe way
52+
53+
还是换回原来的加密解密方式吧,主要是_d太大的问题,其他都还好。
54+
55+
56+
57+
58+
59+
我试了下,HTML源码中放一个在注释中的base64字符串都要渲染好久好久
60+
<!-- <script id="_d" type="text/plain">
61+
lHs0hIf559bXbGDNCBz1dzwAT+xxx这是一串60k的base64字符串
62+
</script> -->
63+
也许需要在base64字符串比较长的时候,采用fetch的方式来获取
64+
但比较短的时候就不需要了
65+
66+
67+
68+
69+
70+
再修改一点,不要输入暗号后再加载.dat,渲染好解密输入框后立刻异步加载并赋值到js的变量中更好。如果有可以提前执行的运输尽量提前执行。
71+
72+

encrypt-original.html

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!--
2+
* @Author: LetMeFly
3+
* @Date: 2026-03-21 20:10:53
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-03-21 20:12:02
6+
-->
7+
8+
<!DOCTYPE html>
9+
<html lang="zh">
10+
<head>
11+
<meta charset="UTF-8">
12+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
13+
<title>简单页面</title>
14+
<style>
15+
* { margin: 0; padding: 0; box-sizing: border-box; }
16+
body { font-family: -apple-system, sans-serif; background: #f5f5f5; color: #333; display: flex; justify-content: center; align-items: center; min-height: 100vh; }
17+
.card { background: #fff; border-radius: 12px; padding: 40px; box-shadow: 0 4px 20px rgba(0,0,0,0.08); text-align: center; max-width: 480px; }
18+
h1 { font-size: 28px; margin-bottom: 12px; }
19+
p { color: #666; line-height: 1.6; margin-bottom: 24px; }
20+
button { background: #4f46e5; color: #fff; border: none; padding: 12px 32px; border-radius: 8px; font-size: 16px; cursor: pointer; transition: background 0.2s; }
21+
button:hover { background: #4338ca; }
22+
#msg { margin-top: 16px; font-size: 14px; color: #4f46e5; }
23+
</style>
24+
</head>
25+
<body>
26+
<div class="card">
27+
<h1>Hello World</h1>
28+
<p>这是一个简单的 HTML 页面,点击下方按钮试试。</p>
29+
<button onclick="document.getElementById('msg').textContent='🎉 你点击了按钮!' + new Date().toLocaleTimeString()">点击我</button>
30+
<div id="msg"></div>
31+
</div>
32+
</body>
33+
</html>

0 commit comments

Comments
 (0)