Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5793ebc

Browse files
Merge branch 'master' into remote
2 parents fb7a575 + 3f95cef commit 5793ebc

File tree

233 files changed

+8652
-1509
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

233 files changed

+8652
-1509
lines changed

README.md

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888

8989
* 编程语言
9090
* [C++面试&C++学习指南知识点整理](https://github.com/youngyangyang04/TechCPP)
91+
9192
* 项目
9293
* [基于跳表的轻量级KV存储引擎](https://github.com/youngyangyang04/Skiplist-CPP)
9394
* [Nosql数据库注入攻击系统](https://github.com/youngyangyang04/NoSQLAttack)
@@ -96,6 +97,7 @@
9697
* [看了这么多代码,谈一谈代码风格!](./problems/前序/代码风格.md)
9798
* [力扣上的代码想在本地编译运行?](./problems/前序/力扣上的代码想在本地编译运行?.md)
9899
* [什么是核心代码模式,什么又是ACM模式?](./problems/前序/什么是核心代码模式,什么又是ACM模式?.md)
100+
99101
* 工具
100102
* [一站式vim配置](https://github.com/youngyangyang04/PowerVim)
101103
* [保姆级Git入门教程,万字详解](https://mp.weixin.qq.com/s/Q_O0ey4C9tryPZaZeJocbA)
@@ -120,30 +122,29 @@
120122
* [递归算法的时间与空间复杂度分析!](./problems/前序/递归算法的时间与空间复杂度分析.md)
121123
* [刷了这么多题,你了解自己代码的内存消耗么?](./problems/前序/刷了这么多题,你了解自己代码的内存消耗么?.md)
122124

123-
124-
## 社群
125-
126-
* [准备秋招的录友们,组织在这里!](https://mp.weixin.qq.com/s/xX4LFwZQIG_XiQAxVBrfeA)
127-
* [准备社招的录友们,组织在这里!](https://mp.weixin.qq.com/s/mbQ3s17ZJ4LXFRb-VD58Ww)
128-
129125
## 知识星球精选
130126

131-
* [HR面注意事项](https://mp.weixin.qq.com/s/0mDyCyCBfa0DeGov3Pebnw)
132-
* [刷题攻略要刷两遍!](https://mp.weixin.qq.com/s/e3_L7FZglY4UlTVvKolZyQ)
133-
* [秋招进行中的迷茫与焦虑......](https://mp.weixin.qq.com/s/X15MUw4sfH_AQNHdAivEvg)
134-
* [大厂新人培养体系应该是什么样的?](https://mp.weixin.qq.com/s/WBaPCosOljB5NEkFL2GhOQ)
135-
* [你的简历里「专业技能」写的够专业么?](https://mp.weixin.qq.com/s/bp6y-e5FVN28H9qc8J9zrg)
136-
* [Carl看了上百份简历,总结了这些!](https://mp.weixin.qq.com/s/sJa87MZD28piCOVMFkIbwQ)
137-
* [备战2022届秋招](https://mp.weixin.qq.com/s/7q7W8Cb2-a5U5atZdOnOFA)
138-
* [技术不太好,如果选择方向](https://mp.weixin.qq.com/s/ZCzFiAHZHLqHPLJQXNm75g)
139-
* [刷题要不要使用库函数](https://mp.weixin.qq.com/s/6K3_OSaudnHGq2Ey8vqYfg)
140-
* [关于实习的几点问题](https://mp.weixin.qq.com/s/xcxzi7c78kQGjvZ8hh7taA)
141-
* [面试中遇到了发散性问题,怎么帮?](https://mp.weixin.qq.com/s/SSonDxi2pjkSVwHNzZswng)
142-
* [英语到底重不重要!](https://mp.weixin.qq.com/s/1PRZiyF_-TVA-ipwDNjdKw)
143-
* [计算机专业要不要读研!](https://mp.weixin.qq.com/s/c9v1L3IjqiXtkNH7sOMAdg)
144-
* [关于提前批的一些建议](https://mp.weixin.qq.com/s/SNFiRDx8CKyjhTPlys6ywQ)
145-
* [已经在实习的录友要如何准备秋招](https://mp.weixin.qq.com/s/ka07IPryFnfmIjByFFcXDg)
146-
* [华为提前批已经开始了](https://mp.weixin.qq.com/s/OC35QDG8pn5OwLpCxieStw)
127+
* [秋招下半场依然没offer,怎么办?](./problems/知识星球精选/秋招下半场依然没offer.md)
128+
* [合适自己的就是最好的](./problems/知识星球精选/合适自己的就是最好的.md)
129+
* [为什么都说客户端会消失](./problems/知识星球精选/客三消.md)
130+
* [博士转计算机如何找工作](./problems/知识星球精选/博士转行计算机.md)
131+
* [不一样的七夕](./problems/知识星球精选/不一样的七夕.md)
132+
* [HR面注意事项](./problems/知识星球精选/HR面注意事项.md)
133+
* [刷题攻略要刷两遍!](./problems/知识星球精选/刷题攻略要刷两遍.md)
134+
* [秋招进行中的迷茫与焦虑......](./problems/知识星球精选/秋招进行中的迷茫与焦虑.md)
135+
* [大厂新人培养体系应该是什么样的?](./problems/知识星球精选/大厂新人培养体系.md)
136+
* [你的简历里「专业技能」写的够专业么?](./problems/知识星球精选/专业技能可以这么写.md)
137+
* [Carl看了上百份简历,总结了这些!](./problems/知识星球精选/写简历的一些问题.md)
138+
* [备战2022届秋招](./problems/知识星球精选/备战2022届秋招.md)
139+
* [技术不太好,如果选择方向](./problems/知识星球精选/技术不好如何选择技术方向.md)
140+
* [刷题要不要使用库函数](./problems/知识星球精选/刷力扣用不用库函数.md)
141+
* [关于实习的几点问题](./problems/知识星球精选/关于实习大家的疑问.md)
142+
* [面试中遇到了发散性问题,怎么办?](./problems/知识星球精选/面试中发散性问题.md)
143+
* [英语到底重不重要!](./problems/知识星球精选/英语到底重不重要.md)
144+
* [计算机专业要不要读研!](./problems/知识星球精选/要不要考研.md)
145+
* [关于提前批的一些建议](./problems/知识星球精选/关于提前批的一些建议.md)
146+
* [已经在实习的录友要如何准备秋招](./problems/知识星球精选/如何权衡实习与秋招复习.md)
147+
* [华为提前批已经开始了](./problems/知识星球精选/提前批已经开始了.md)
147148

148149
## 杂谈
149150

@@ -153,7 +154,6 @@
153154
* [大半年过去了......](https://mp.weixin.qq.com/s/lubfeistPxBLSQIe5XYg5g)
154155
* [一万录友在B站学算法!](https://mp.weixin.qq.com/s/Vzq4zkMZY7erKeu0fqGLgw)
155156

156-
157157
## 数组
158158

159159
1. [数组过于简单,但你该了解这些!](./problems/数组理论基础.md)
@@ -304,7 +304,8 @@
304304

305305
题目分类大纲如下:
306306

307-
<img src='https://img-blog.csdnimg.cn/20210220152245584.png' width=600 alt='贪心算法大纲'> </img></div>
307+
308+
<img src='https://code-thinking-1253855093.file.myqcloud.com/pics/20210917104315.png' width=600 alt='贪心算法大纲'> </img></div>
308309

309310
1. [关于贪心算法,你该了解这些!](./problems/贪心算法理论基础.md)
310311
2. [贪心算法:分发饼干](./problems/0455.分发饼干.md)
@@ -457,6 +458,7 @@
457458
* [724.寻找数组的中心索引](./problems/0724.寻找数组的中心索引.md)
458459
* [34.在排序数组中查找元素的第一个和最后一个位置](./problems/0034.在排序数组中查找元素的第一个和最后一个位置.md) (二分法)
459460
* [922.按奇偶排序数组II](./problems/0922.按奇偶排序数组II.md)
461+
* [35.搜索插入位置](./problems/0035.搜索插入位置.md)
460462

461463
## 链表
462464

@@ -485,6 +487,7 @@
485487

486488
## 贪心
487489
* [649.Dota2参议院](./problems/0649.Dota2参议院.md) 有难度
490+
* [1221.分割平衡字符](./problems/1221.分割平衡字符串.md) 简单贪心
488491

489492
## 动态规划
490493
* [5.最长回文子串](./problems/0005.最长回文子串.md)[647.回文子串](https://mp.weixin.qq.com/s/2WetyP6IYQ6VotegepVpEw) 差不多是一样的

problems/0001.两数之和.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,4 @@ class Solution {
253253
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
254254
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
255255
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
256-
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码.jpg width=450> </img></div>
256+
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>

problems/0005.最长回文子串.md

Lines changed: 142 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
<p align="center">
32
<a href="https://mp.weixin.qq.com/s/RsdcQ9umo09R6cfnwXZlrQ"><img src="https://img.shields.io/badge/PDF下载-代码随想录-blueviolet" alt=""></a>
43
<a href="https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw"><img src="https://img.shields.io/badge/刷题-微信群-green" alt=""></a>
@@ -8,6 +7,7 @@
87
<p align="center"><strong>欢迎大家<a href="https://mp.weixin.qq.com/s/tqCxrMEU-ajQumL1i8im9A">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!</strong></p>
98

109

10+
1111
# 5.最长回文子串
1212

1313
[力扣题目链接](https://leetcode-cn.com/problems/longest-palindromic-substring/)
@@ -288,7 +288,34 @@ class Solution:
288288
return s[left:right + 1]
289289

290290
```
291+
> 双指针法:
292+
```python
293+
class Solution:
294+
def longestPalindrome(self, s: str) -> str:
295+
296+
def find_point(i, j, s):
297+
while i >= 0 and j < len(s) and s[i] == s[j]:
298+
i -= 1
299+
j += 1
300+
return i + 1, j
301+
302+
def compare(start, end, left, right):
303+
if right - left > end - start:
304+
return left, right
305+
else:
306+
return start, end
307+
308+
start = 0
309+
end = 0
310+
for i in range(len(s)):
311+
left, right = find_point(i, i, s)
312+
start, end = compare(start, end, left, right)
313+
314+
left, right = find_point(i, i + 1, s)
315+
start, end = compare(start, end, left, right)
316+
return s[start:end]
291317

318+
```
292319
## Go
293320
294321
```go
@@ -297,12 +324,123 @@ class Solution:
297324
## JavaScript
298325

299326
```js
327+
//动态规划解法
328+
var longestPalindrome = function(s) {
329+
const len = s.length;
330+
// 布尔类型的dp[i][j]:表示区间范围[i,j] (注意是左闭右闭)的子串是否是回文子串,如果是dp[i][j]为true,否则为false
331+
let dp = new Array(len).fill(false).map(() => new Array(len).fill(false));
332+
// left起始位置 maxlenth回文串长度
333+
let left = 0, maxlenth = 0;
334+
for(let i = len - 1; i >= 0; i--){
335+
for(let j = i; j < len; j++){
336+
// 情况一:下标i 与 j相同,同一个字符例如a,当然是回文子串 j - i == 0
337+
// 情况二:下标i 与 j相差为1,例如aa,也是文子串 j - i == 1
338+
// 情况一和情况二 可以合并为 j - i <= 1
339+
// 情况三:下标:i 与 j相差大于1的时候,例如cabac,此时s[i]与s[j]已经相同了,我们看i到j区间是不是回文子串就看aba是不是回文就可以了,那么aba的区间就是 i+1 与 j-1区间,这个区间是不是回文就看dp[i + 1][j - 1]===true
340+
if(s[i] === s[j] && (j - i <= 1 || dp[i + 1][j - 1])){
341+
dp[i][j] = true;
342+
}
343+
// 只要 dp[i][j] == true 成立,就表示子串 s[i..j] 是回文,此时记录回文长度和起始位置
344+
if(dp[i][j] && j - i + 1 > maxlenth) {
345+
maxlenth = j - i + 1; // 回文串长度
346+
left = i; // 起始位置
347+
}
348+
}
349+
}
350+
return s.substr(left, maxlenth); // 找到子串
351+
};
352+
353+
//双指针
354+
var longestPalindrome = function(s) {
355+
let left = 0, right = 0, maxLength = 0;
356+
const extend = (s, i, j, n) => {// s为字符串 i,j为双指针 n为字符串长度
357+
while(i >= 0 && j < n && s[i] === s[j]){
358+
if(j - i + 1 > maxLength){
359+
left = i; // 更新开始位置
360+
right = j; // 更新结尾位置
361+
maxLength = j - i + 1; // 更新子串最大长度
362+
}
363+
// 指针移动
364+
i--;
365+
j++;
366+
}
367+
}
368+
for(let i = 0; i < s.length; i++){
369+
extend(s, i, i, s.length); // 以i为中心
370+
extend(s, i, i + 1, s.length); // 以i和i+1为中心
371+
}
372+
return s.substr(left, maxLength);
373+
};
374+
375+
//Manacher算法
376+
var longestPalindrome = function(s) {
377+
const len = s.length;
378+
if(len < 2) return s;
379+
let maxLength = 1, index = 0;
380+
//Manacher算法,利用回文对称的性质,根据i在上一个回文中心的臂长里的位置去判断i的回文性
381+
//需要知道上一个回文中心,以及其臂长
382+
let center = 0;
383+
//注意这里使用了maxRight的而不是真实的臂长length,因为之后需要判断i在臂长的什么位置
384+
//如果这里臂长用了length,之后还要 计算i - center 去和 length比较,太繁琐
385+
let maxRight = 0;
386+
//考虑到回文串的长度是偶数的情况,所以这里预处理一下字符串,每个字符间插入特殊字符,把可能性都化为奇数
387+
//这个处理把回文串长度的可能性都化为了奇数
388+
//#c#b#b#a#
389+
//#c#b#a#b#d#
390+
let ss = "";
391+
for(let i = 0; i < s.length; i++){
392+
ss += "#"+s[i];
393+
}
394+
ss += "#";
395+
//需要维护一个每个位置臂长的信息数组positionLength
396+
const pl = new Array(ss.length).fill(0);
397+
//这里需要注意参考的是i关于center对称的点i'的回文性
398+
//i' = 2*center - i;
399+
//所以列下情况:
400+
//1.i>maxRight,找不到i',无法参考,自己算自己的
401+
//2.i<=maxRight:
402+
//2.1 i<maxRight-pl[i'],pl[i']的臂长没有超过center的臂长,根据对称性,pl[i] = pl[i']
403+
//2.2 i=maxRight-pl[i'],pl[i']的臂长刚好等于center的臂长,根据对称性,pl[i] >= pl[i‘],大多少需要尝试扩散
404+
//2.3 i>maxRight-pl[i'],pl[i']的臂长超过了center的臂长,根据对称性,i中心扩散到MaxRight处,
405+
// s[2*i-maxRight] !== s[MaxRight]必不相等,所以pl[i] = maxRight-i;
406+
//总结就是pl[i] = Math.min(maxRight-i,pl[i']);提示i<maxRight-pl[i'] 也可写成 pl[i']<maxRight-i
407+
//0没有意义,从1开始计算
408+
for(let i = 1; i < ss.length; i++){
409+
if(i <= maxRight){//可以参考之前的
410+
pl[i] = Math.min(maxRight - i, pl[2 * center - i]);
411+
//尝试中心扩散
412+
}
413+
//注意到i<maxRight时都要尝试中心扩散,所以写else完全无意义,把中心扩散的代码写在下面
414+
// else{//i不在之前回文中心的臂长范围里,之前的信息就完全无法参考,只能从i中心扩散把,然后去维护maxRight和center的定义
415+
//尝试中心扩散
416+
//这里不要动center和maxRight
417+
// center = i;
418+
// maxRight = pl[i] + i + 1;
419+
let right = pl[i] + i + 1;
420+
let left = i - pl[i] - 1;
421+
while (left >= 0 && right<ss.length && ss[left] === ss[right]) {
422+
right++;
423+
left--;
424+
pl[i]++;
425+
}
426+
// }
427+
if(pl[i] + i > maxRight){
428+
center = i;
429+
maxRight = pl[i] + i;
430+
}
431+
if (pl[i] * 2 + 1 > maxLength){
432+
maxLength = pl[i]*2+1;
433+
index = i - pl[i];
434+
}
435+
}
436+
return ss.substr(index, maxLength).replace(/#/g,"");
437+
};
300438
```
301439

440+
441+
302442
-----------------------
303443
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
304444
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
305445
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
306-
307-
308-
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码.jpg width=450> </img></div>
446+
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>

problems/0015.三数之和.md

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -354,44 +354,6 @@ def is_valid(strs)
354354
end
355355
```
356356

357-
php:
358-
359-
```php
360-
function threeSum(array $nums): array
361-
{
362-
$result = [];
363-
$length = count($nums);
364-
if ($length < 3) {
365-
return [];
366-
}
367-
sort($nums);
368-
for ($i = 0; $i < $length; $i++) {
369-
// 如果大于0结束
370-
if ($nums[$i] > 0) break;
371-
// 去重
372-
if ($i > 0 && $nums[$i] == $nums[$i - 1]) continue;
373-
$left = $i + 1;
374-
$right = $length - 1;
375-
// 比较
376-
while ($left < $right) {
377-
$sum = $nums[$i] + $nums[$left] + $nums[$right];
378-
if ($sum < 0) {
379-
$left++;
380-
} elseif ($sum > 0) {
381-
$right--;
382-
} else {
383-
array_push($result, [$nums[$i], $nums[$left], $nums[$right]]);
384-
while ($left < $right && $nums[$left] == $nums[$left + 1]) $left++;
385-
while ($left < $right && $nums[$right - 1] == $nums[$right]) $right--;
386-
$left++;
387-
$right--;
388-
}
389-
}
390-
}
391-
392-
return $result;
393-
}
394-
```
395357

396358
PHP:
397359
```php
@@ -434,9 +396,49 @@ class Solution {
434396
}
435397
```
436398

399+
Swift:
400+
```swift
401+
// 双指针法
402+
func threeSum(_ nums: [Int]) -> [[Int]] {
403+
var res = [[Int]]()
404+
var sorted = nums
405+
sorted.sort()
406+
for i in 0 ..< sorted.count {
407+
if sorted[i] > 0 {
408+
return res
409+
}
410+
if i > 0 && sorted[i] == sorted[i - 1] {
411+
continue
412+
}
413+
var left = i + 1
414+
var right = sorted.count - 1
415+
while left < right {
416+
let sum = sorted[i] + sorted[left] + sorted[right]
417+
if sum < 0 {
418+
left += 1
419+
} else if sum > 0 {
420+
right -= 1
421+
} else {
422+
res.append([sorted[i], sorted[left], sorted[right]])
423+
424+
while left < right && sorted[left] == sorted[left + 1] {
425+
left += 1
426+
}
427+
while left < right && sorted[right] == sorted[right - 1] {
428+
right -= 1
429+
}
430+
431+
left += 1
432+
right -= 1
433+
}
434+
}
435+
}
436+
return res
437+
}
438+
```
437439

438440
-----------------------
439441
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
440442
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
441443
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
442-
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码.jpg width=450> </img></div>
444+
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>

0 commit comments

Comments
 (0)