Skip to content

Commit 27c9a22

Browse files
committed
update: 添加问题“2839.判断通过操作能否让字符串相等I”的代码和题解 (#1472)
2839: AC.cpp (#1471) - AC,100.00%,100.00% docs: VsCode ssh remote下 Git 行内变动标记不显示 docs: refactor - 类似话题放到一起 Signed-off-by: LetMeFly666 <Tisfy@qq.com>
1 parent 30944a3 commit 27c9a22

15 files changed

Lines changed: 303 additions & 106 deletions

.commitmsg

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
2946: AC.cpp+go+java+py+rust (#1468)
1+
2839: AC.cpp (#1471) - AC,100.00%,100.00%
22

3-
cpp - AC,100.00%,51.72%
4-
go - AC,100.00%,100.00%
5-
java - AC,6.06%,12.12%
6-
py - AC,18.87%,30.19%
7-
rust - AC,100.00%,100.00%
3+
docs: VsCode ssh remote下 Git 行内变动标记不显示
4+
docs: refactor - 类似话题放到一起
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-03-29 19:32:33
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-03-29 19:41:22
6+
*/
7+
#ifdef _DEBUG
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
#include <iostream>
11+
class Solution {
12+
private:
13+
inline bool same2(const string& a, const string& b, int i, int j) {
14+
return a[i] == b[i] && a[j] == b[j] || a[i] == b[j] && a[j] == b[i];
15+
}
16+
public:
17+
bool canBeEqual(const string& s1, const string& s2) {
18+
return same2(s1, s2, 0, 2) && same2(s1, s2, 1, 3);
19+
}
20+
};

Codes/2946-matrix-similarity-after-cyclic-shifts.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
* @Author: LetMeFly
33
* @Date: 2026-03-27 08:48:57
44
* @LastEditors: LetMeFly.xyz
5-
* @LastEditTime: 2026-03-27 08:53:34
5+
* @LastEditTime: 2026-03-29 19:44:59
66
*/
77
package main
88

99
func areSimilar(mat [][]int, k int) bool {
1010
m := len(mat[0])
11-
for _, row := range mat {
11+
for _, row := range mat {
1212
for j := range row {
1313
if row[j] != row[(j + k) % m] {
1414
return false

Codes/2946-matrix-similarity-after-cyclic-shifts.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
* @Author: LetMeFly
33
* @Date: 2026-03-27 08:48:57
44
* @LastEditors: LetMeFly.xyz
5-
* @LastEditTime: 2026-03-27 09:07:38
5+
* @LastEditTime: 2026-03-27 09:08:38
66
*/
7-
// THIS CANNOT BE ACCEPTED
87
impl Solution {
98
pub fn are_similar(mat: Vec<Vec<i32>>, k: i32) -> bool {
109
let m = mat[0].len();
1110
for row in mat.iter() {
1211
for j in 0..row.len() {
13-
if (row[j] != row[(j + k) % m]) {
12+
if (row[j] != row[(j + k as usize) % m]) {
1413
return false;
1514
}
1615
}

Codes/2946-matrix-similarity-after-cyclic-shifts_AC.rs

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

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,7 @@
963963
|2828.判别首字母缩略词|简单|<a href="https://leetcode.cn/problems/check-if-a-string-is-an-acronym-of-words/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2023/12/20/LeetCode%202828.%E5%88%A4%E5%88%AB%E9%A6%96%E5%AD%97%E6%AF%8D%E7%BC%A9%E7%95%A5%E8%AF%8D/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/135106811" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/check-if-a-string-is-an-acronym-of-words/solutions/2573316/letmefly-2828pan-bie-shou-zi-mu-suo-lue-kiuxi/" target="_blank">LeetCode题解</a>|
964964
|2829.k-avoiding数组的最小总和|中等|<a href="https://leetcode.cn/problems/determine-the-minimum-sum-of-a-k-avoiding-array/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/03/26/LeetCode%202829.k-avoiding%E6%95%B0%E7%BB%84%E7%9A%84%E6%9C%80%E5%B0%8F%E6%80%BB%E5%92%8C/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/146528057" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/determine-the-minimum-sum-of-a-k-avoiding-array/solutions/3628637/letmefly-2829k-avoiding-shu-zu-de-zui-xi-sja5/" target="_blank">LeetCode题解</a>|
965965
|2834.找出美丽数组的最小和|中等|<a href="https://leetcode.cn/problems/find-the-minimum-possible-sum-of-a-beautiful-array/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/03/08/LeetCode%202834.%E6%89%BE%E5%87%BA%E7%BE%8E%E4%B8%BD%E6%95%B0%E7%BB%84%E7%9A%84%E6%9C%80%E5%B0%8F%E5%92%8C/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/136565723" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-the-minimum-possible-sum-of-a-beautiful-array/solutions/2675178/letmefly-2834zhao-chu-mei-li-shu-zu-de-z-qfzj/" target="_blank">LeetCode题解</a>|
966+
|2839.判断通过操作能否让字符串相等I|简单|<a href="https://leetcode.cn/problems/check-if-strings-can-be-made-equal-with-operations-i/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2026/03/29/LeetCode%202839.%E5%88%A4%E6%96%AD%E9%80%9A%E8%BF%87%E6%93%8D%E4%BD%9C%E8%83%BD%E5%90%A6%E8%AE%A9%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9B%B8%E7%AD%89I/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/159616700" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/check-if-strings-can-be-made-equal-with-operations-i/solutions/3939958/letmefly-2839pan-duan-tong-guo-cao-zuo-n-wo78/" target="_blank">LeetCode题解</a>|
966967
|2843.统计对称整数的数目|简单|<a href="https://leetcode.cn/problems/count-symmetric-integers/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/04/11/LeetCode%202843.%E7%BB%9F%E8%AE%A1%E5%AF%B9%E7%A7%B0%E6%95%B4%E6%95%B0%E7%9A%84%E6%95%B0%E7%9B%AE/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/147154718" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/count-symmetric-integers/solutions/3648385/letmefly-2843tong-ji-dui-cheng-zheng-shu-tf02/" target="_blank">LeetCode题解</a>|
967968
|2844.生成特殊数字的最少操作|中等|<a href="https://leetcode.cn/problems/minimum-operations-to-make-a-special-number/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/07/25/LeetCode%202844.%E7%94%9F%E6%88%90%E7%89%B9%E6%AE%8A%E6%95%B0%E5%AD%97%E7%9A%84%E6%9C%80%E5%B0%91%E6%93%8D%E4%BD%9C/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/140695211" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/minimum-operations-to-make-a-special-number/solutions/2857083/letmefly-2844sheng-cheng-te-shu-shu-zi-d-ds9b/" target="_blank">LeetCode题解</a>|
968969
|2859.计算K置位下标对应元素的和|简单|<a href="https://leetcode.cn/problems/sum-of-values-at-indices-with-k-set-bits/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/01/25/LeetCode%202859.%E8%AE%A1%E7%AE%97K%E7%BD%AE%E4%BD%8D%E4%B8%8B%E6%A0%87%E5%AF%B9%E5%BA%94%E5%85%83%E7%B4%A0%E7%9A%84%E5%92%8C/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/135836080" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/sum-of-values-at-indices-with-k-set-bits/solutions/2618937/letmefly-2859ji-suan-k-zhi-wei-xia-biao-usyx1/" target="_blank">LeetCode题解</a>|
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
title: 2839.判断通过操作能否让字符串相等 I:if-else(两两判断)
3+
date: 2026-03-29 19:55:01
4+
tags: [题解, LeetCode, 简单, 字符串]
5+
categories: [题解, LeetCode]
6+
---
7+
8+
# 【LetMeFly】2839.判断通过操作能否让字符串相等 I:if-else(两两判断)
9+
10+
力扣题目链接:[https://leetcode.cn/problems/check-if-strings-can-be-made-equal-with-operations-i/](https://leetcode.cn/problems/check-if-strings-can-be-made-equal-with-operations-i/)
11+
12+
<p>给你两个字符串&nbsp;<code>s1</code> 和&nbsp;<code>s2</code>&nbsp;,两个字符串的长度都为&nbsp;<code>4</code>&nbsp;,且只包含 <strong>小写</strong> 英文字母。</p>
13+
14+
<p>你可以对两个字符串中的 <strong>任意一个</strong>&nbsp;执行以下操作 <strong>任意</strong>&nbsp;次:</p>
15+
16+
<ul>
17+
<li>选择两个下标&nbsp;<code>i</code> 和&nbsp;<code>j</code>&nbsp;且满足&nbsp;<code>j - i = 2</code>&nbsp;,然后 <strong>交换</strong> 这个字符串中两个下标对应的字符。</li>
18+
</ul>
19+
20+
<p>如果你可以让字符串<em>&nbsp;</em><code>s1</code><em> </em>和<em>&nbsp;</em><code>s2</code>&nbsp;相等,那么返回 <code>true</code>&nbsp;,否则返回 <code>false</code>&nbsp;。</p>
21+
22+
<p>&nbsp;</p>
23+
24+
<p><strong class="example">示例 1:</strong></p>
25+
26+
<pre>
27+
<b>输入:</b>s1 = "abcd", s2 = "cdab"
28+
<b>输出:</b>true
29+
<strong>解释:</strong> 我们可以对 s1 执行以下操作:
30+
- 选择下标 i = 0 ,j = 2 ,得到字符串 s1 = "cbad" 。
31+
- 选择下标 i = 1 ,j = 3 ,得到字符串 s1 = "cdab" = s2 。
32+
</pre>
33+
34+
<p><strong class="example">示例 2:</strong></p>
35+
36+
<pre>
37+
<b>输入:</b>s1 = "abcd", s2 = "dacb"
38+
<b>输出:</b>false
39+
<b>解释:</b>无法让两个字符串相等。
40+
</pre>
41+
42+
<p>&nbsp;</p>
43+
44+
<p><strong>提示:</strong></p>
45+
46+
<ul>
47+
<li><code>s1.length == s2.length == 4</code></li>
48+
<li><code>s1</code> 和&nbsp;<code>s2</code>&nbsp;只包含小写英文字母。</li>
49+
</ul>
50+
51+
52+
53+
## 解题方法:两两判断
54+
55+
字符串长度固定为$4$,字符$s[i]$只能与字符$s[i+2]$交换,相当于第一个字符只能与第三个字符交换、第二个字符只能与第四个字符交换。
56+
57+
所以判断下两个字符串的第一个和第三个字符是否相等或交换后相等,并且第二第四个字符也相等或交换后相等,就好了。
58+
59+
+ 时间复杂度$O(1)$
60+
+ 空间复杂度$O(1)$
61+
62+
### AC代码
63+
64+
#### C++
65+
66+
```cpp
67+
/*
68+
* @LastEditTime: 2026-03-29 19:41:22
69+
*/
70+
#include <iostream>
71+
class Solution {
72+
private:
73+
inline bool same2(const string& a, const string& b, int i, int j) {
74+
return a[i] == b[i] && a[j] == b[j] || a[i] == b[j] && a[j] == b[i];
75+
}
76+
public:
77+
bool canBeEqual(const string& s1, const string& s2) {
78+
return same2(s1, s2, 0, 2) && same2(s1, s2, 1, 3);
79+
}
80+
};
81+
```
82+
83+
AC,100.00%,100.00%
84+
85+
> 同步发文于[CSDN](https://letmefly.blog.csdn.net/article/details/159616700)和我的[个人博客](https://blog.letmefly.xyz/),原创不易,转载经作者同意后请附上[原文链接](https://blog.letmefly.xyz/2026/03/29/LeetCode%202839.%E5%88%A4%E6%96%AD%E9%80%9A%E8%BF%87%E6%93%8D%E4%BD%9C%E8%83%BD%E5%90%A6%E8%AE%A9%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9B%B8%E7%AD%89I/)哦~
86+
>
87+
> 千篇源码题解[已开源](https://github.com/LetMeFly666/LeetCode)

Solutions/LeetCode 2946.循环移位后的矩阵相似检查.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,15 @@ class Solution {
137137
package main
138138

139139
func areSimilar(mat [][]int, k int) bool {
140-
m := len(mat[0])
140+
m := len(mat[0])
141141
for _, row := range mat {
142-
for j := range row {
143-
if row[j] != row[(j + k) % m] {
144-
return false
145-
}
146-
}
147-
}
148-
return true
142+
for j := range row {
143+
if row[j] != row[(j + k) % m] {
144+
return false
145+
}
146+
}
147+
}
148+
return true
149149
}
150150
```
151151

Solutions/Other-Accumulation-SomeTips.md

Lines changed: 79 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: 日积月累 - 一些小知识
33
date: 2023-02-21 21:33:49
4-
tags: [其他, 小杂, 知识, 中等, Github, HTML, Windows, Phone, Python, 双端队列, 优先队列, Website, API, 深度学习, AI, DL, ChatGPT, Office, Word, 安全, BAT, shell]
4+
tags: [其他, 小杂, 知识, 中等, Github, HTML, Windows, Phone, Python, 双端队列, 优先队列, Website, API, 深度学习, AI, DL, ChatGPT, Office, Word, 安全, BAT, shell, Vs--Code]
55
categories: [技术思考]
66
---
77

@@ -338,64 +338,6 @@ gh auth login
338338
gh auth refresh -s project
339339
```
340340

341-
## About HTML
342-
343-
### 空白字符
344-
345-
这是一个空白字符:“ㅤ”
346-
347-
### WebView2
348-
349-
(实为Edge内核?)编写的程序可以借助webview2实现网页的访问与浏览。相当于是浏览器。若电脑上安装有WebView2,则程序可以直接借助WebView2实现网页的浏览。
350-
351-
见到一个B站UP主打包WebView2的[视频](https://www.bilibili.com/video/BV1Aa411j7XV/)。
352-
353-
### canonical
354-
355-
canonical 就是告诉搜索引擎:“这些页面看起来不一样,但你把它们当成同一个页面就行,正主是这个。”
356-
357-
同一篇内容有不同url可能会导致搜索引擎:
358-
359-
* 权重被分散
360-
* 可能被认为是「重复内容」
361-
* SEO 变差
362-
363-
```html
364-
<link rel="canonical" href="https://blog.letmefly.xyz/post/123">
365-
```
366-
367-
### HTML全屏幕取色器
368-
369-
Chrome、Edge、Opera浏览器支持[`EyeDropper`API](https://developer.mozilla.org/en-US/docs/Web/API/EyeDropper),可以将鼠标变成一个取色器,取色器会将鼠标变成一个“圆形放大镜”,用户在屏幕上任意位置(**哪怕是浏览器外**)点击鼠标左键则HTML可以获取到该位置的颜色RGB,鼠标移动过程中经过像素颜色对HTML不可见。
370-
371-
注意,<span title="2026.2.8">当前Firefox、Safari</span>浏览器以及所有主流手机浏览器都不支持该API。
372-
373-
体验地址:[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/)。可查看网页源码,不难发现源码很简单。
374-
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-
你猜在M3 Pro芯片的MacBook Pro的Chrome146.0.7680.153浏览器中打开需要多久?答案是平均5秒往上。
394-
395-
这么长一段都在注释中都很慢,所以最佳的方式也许是另外一个文件然后fetch。
396-
397-
但是,好像只在打开本地html时会很慢。
398-
399341
## About Linux
400342

401343
### Ubuntu防火墙
@@ -1180,6 +1122,64 @@ func main() {
11801122
}
11811123
```
11821124

1125+
## About HTML
1126+
1127+
### 空白字符
1128+
1129+
这是一个空白字符:“ㅤ”
1130+
1131+
### WebView2
1132+
1133+
(实为Edge内核?)编写的程序可以借助webview2实现网页的访问与浏览。相当于是浏览器。若电脑上安装有WebView2,则程序可以直接借助WebView2实现网页的浏览。
1134+
1135+
见到一个B站UP主打包WebView2的[视频](https://www.bilibili.com/video/BV1Aa411j7XV/)
1136+
1137+
### canonical
1138+
1139+
canonical 就是告诉搜索引擎:“这些页面看起来不一样,但你把它们当成同一个页面就行,正主是这个。”
1140+
1141+
同一篇内容有不同url可能会导致搜索引擎:
1142+
1143+
* 权重被分散
1144+
* 可能被认为是「重复内容」
1145+
* SEO 变差
1146+
1147+
```html
1148+
<link rel="canonical" href="https://blog.letmefly.xyz/post/123">
1149+
```
1150+
1151+
### HTML全屏幕取色器
1152+
1153+
Chrome、Edge、Opera浏览器支持[`EyeDropper`API](https://developer.mozilla.org/en-US/docs/Web/API/EyeDropper),可以将鼠标变成一个取色器,取色器会将鼠标变成一个“圆形放大镜”,用户在屏幕上任意位置(**哪怕是浏览器外**)点击鼠标左键则HTML可以获取到该位置的颜色RGB,鼠标移动过程中经过像素颜色对HTML不可见。
1154+
1155+
注意,<span title="2026.2.8">当前Firefox、Safari</span>浏览器以及所有主流手机浏览器都不支持该API。
1156+
1157+
体验地址:[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/)。可查看网页源码,不难发现源码很简单。
1158+
1159+
### HTML渲染耗时问题
1160+
1161+
有这样一个HTML:
1162+
1163+
```html
1164+
<html lang="zh"><head>
1165+
<meta charset="UTF-8">
1166+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
1167+
<title>Protected Page</title>
1168+
</head>
1169+
<body>
1170+
<!-- <script id="_d" type="text/plain">
1171+
lHs0hIf559bXbGDNCBz1dzwAT+xxx这是一串60k的base64字符串
1172+
</script> -->
1173+
1174+
</body></html>
1175+
```
1176+
1177+
你猜在M3 Pro芯片的MacBook Pro的Chrome146.0.7680.153浏览器中打开需要多久?答案是平均5秒往上。
1178+
1179+
这么长一段都在注释中都很慢,所以最佳的方式也许是另外一个文件然后fetch。
1180+
1181+
但是,好像只在打开本地html时会很慢。
1182+
11831183
## About Website
11841184

11851185
### ip扫描工具censys
@@ -1461,14 +1461,6 @@ Word中经常需要插入一些公式,但是很多时候需要在公式的最
14611461

14621462
下载完所有缺失的字体,重新打开Word,显示就正常了。
14631463

1464-
## About Technology
1465-
1466-
### 非视域成像
1467-
1468-
以墙为镜,利用激光在墙面上的漫反射,推算出不可直接看到的区域的图像。
1469-
1470-
讲座地址:[BiliBili@BV1TX4y1s7oe](https://www.bilibili.com/video/BV1TX4y1s7oe/)
1471-
14721464
## About Latex
14731465

14741466
### Ubuntu上安装Latex(免安装版)
@@ -1526,6 +1518,26 @@ export MANPATH=$MANPATH:/usr/local/texlive/2024/texmf-dist/doc/man
15261518
export INFOPATH=$INFOPATH:/usr/local/texlive/2024/texmf-dist/doc/info
15271519
```
15281520

1521+
## About VsCode
1522+
1523+
### VsCode SSH Remote 下 Git 行内变动标记不显示
1524+
1525+
> 让由AI总结自我与AI的对话
1526+
1527+
**现象**:通过 SSH 连接开发机,左侧源代码管理面板能看到文件变动(M/U),但编辑器行号旁边没有蓝色/绿色竖条。
1528+
1529+
**原因**:开发机上 `/home``/data00/home` 的软链接。你通过 `/home/xxx` 打开项目,但 git 内部记的是真实路径 `/data00/home/xxx`。编辑器显示行内标记时要拿这两个路径做字符串比对,路径不一致就匹配不上,标记就不出来。
1530+
1531+
**解决**:用 `pwd -P` 拿到真实路径(如 `/data00/home/xxx`),在 Trae 中用真实路径重新打开项目即可。
1532+
1533+
## About Technology
1534+
1535+
### 非视域成像
1536+
1537+
以墙为镜,利用激光在墙面上的漫反射,推算出不可直接看到的区域的图像。
1538+
1539+
讲座地址:[BiliBili@BV1TX4y1s7oe](https://www.bilibili.com/video/BV1TX4y1s7oe/)
1540+
15291541
## About 俚语
15301542

15311543
### Best-Effort

0 commit comments

Comments
 (0)