Skip to content

Commit

Permalink
Merge branch 'youngyangyang04:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
gaoyangu authored May 2, 2022
2 parents c33b32e + d98481a commit d900c34
Show file tree
Hide file tree
Showing 52 changed files with 330 additions and 2,709 deletions.
42 changes: 2 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
* [看了这么多代码,谈一谈代码风格!](./problems/前序/代码风格.md)
* [力扣上的代码想在本地编译运行?](./problems/前序/力扣上的代码想在本地编译运行?.md)
* [什么是核心代码模式,什么又是ACM模式?](./problems/前序/什么是核心代码模式,什么又是ACM模式?.md)
* [刷题要不要用库函数](./problems/前序/刷力扣用不用库函数.md)
* [ACM模式如何构造二叉树](./problems/前序/ACM模式如何构建二叉树.md)
* [解密互联网大厂研发流程](./problems/前序/互联网大厂研发流程.md)

Expand Down Expand Up @@ -129,45 +130,6 @@
* [递归算法的时间与空间复杂度分析!](./problems/前序/递归算法的时间与空间复杂度分析.md)
* [刷了这么多题,你了解自己代码的内存消耗么?](./problems/前序/刷了这么多题,你了解自己代码的内存消耗么?.md)

## 知识星球精选

* [秋招面试,心态很重要!](./problems/知识星球精选/秋招总结3.md)
* [秋招倒霉透顶,触底反弹!](./problems/知识星球精选/秋招总结2.md)
* [无竞赛,无实习,如何秋招?](./problems/知识星球精选/秋招总结1.md)
* [offer总决赛,何去何从!](./problems/知识星球精选/offer总决赛,何去何从.md)
* [入职后担心代码能力跟不上!](./problems/知识星球精选/入职后担心代码能力跟不上.md)
* [秋招进入offer决赛圈!](./problems/知识星球精选/offer对比-决赛圈.md)
* [非科班的困扰](./problems/知识星球精选/非科班的困扰.md)
* [offer的选择-开奖](./problems/知识星球精选/秋招开奖.md)
* [看到代码就抵触!怎么办?](./problems/知识星球精选/不喜欢写代码怎么办.md)
* [遭遇逼签,怎么办?](./problems/知识星球精选/逼签.md)
* [HR特意刁难非科班!](./problems/知识星球精选/HR特意刁难非科班.md)
* [offer的选择](./problems/知识星球精选/offer的选择.md)
* [天下乌鸦一般黑,哪家没有PUA?](./problems/知识星球精选/天下乌鸦一般黑.md)
* [初入大三,考研VS工作](./problems/知识星球精选/初入大三选择考研VS工作.md)
* [非科班2021秋招总结](./problems/知识星球精选/非科班2021秋招总结.md)
* [秋招下半场依然没offer,怎么办?](./problems/知识星球精选/秋招下半场依然没offer.md)
* [合适自己的就是最好的](./problems/知识星球精选/合适自己的就是最好的.md)
* [为什么都说客户端会消失](./problems/知识星球精选/客三消.md)
* [博士转计算机如何找工作](./problems/知识星球精选/博士转行计算机.md)
* [不一样的七夕](./problems/知识星球精选/不一样的七夕.md)
* [HR面注意事项](./problems/知识星球精选/HR面注意事项.md)
* [刷题攻略要刷两遍!](./problems/知识星球精选/刷题攻略要刷两遍.md)
* [秋招进行中的迷茫与焦虑......](./problems/知识星球精选/秋招进行中的迷茫与焦虑.md)
* [大厂新人培养体系应该是什么样的?](./problems/知识星球精选/大厂新人培养体系.md)
* [你的简历里「专业技能」写的够专业么?](./problems/知识星球精选/专业技能可以这么写.md)
* [Carl看了上百份简历,总结了这些!](./problems/知识星球精选/写简历的一些问题.md)
* [备战2022届秋招](./problems/知识星球精选/备战2022届秋招.md)
* [技术不太好,如果选择方向](./problems/知识星球精选/技术不好如何选择技术方向.md)
* [刷题要不要使用库函数](./problems/知识星球精选/刷力扣用不用库函数.md)
* [关于实习的几点问题](./problems/知识星球精选/关于实习大家的疑问.md)
* [面试中遇到了发散性问题,怎么办?](./problems/知识星球精选/面试中发散性问题.md)
* [英语到底重不重要!](./problems/知识星球精选/英语到底重不重要.md)
* [计算机专业要不要读研!](./problems/知识星球精选/要不要考研.md)
* [关于提前批的一些建议](./problems/知识星球精选/关于提前批的一些建议.md)
* [已经在实习的录友要如何准备秋招](./problems/知识星球精选/如何权衡实习与秋招复习.md)
* [华为提前批已经开始了](./problems/知识星球精选/提前批已经开始了.md)

## 杂谈

* [「代码随想录」刷题网站上线](https://mp.weixin.qq.com/s/-6rd_g7LrVD1fuKBYk2tXQ)
Expand Down Expand Up @@ -569,7 +531,7 @@

如果是已工作,备注:姓名-城市-岗位-组队刷题。如果学生,备注:姓名-学校-年级-组队刷题。**备注没有自我介绍不通过哦**

<div align="center"><img src="https://code-thinking-1253855093.file.myqcloud.com/pics/20220102204804.png" data-img="1" width="200" height="200"></img></div>
<div align="center"><img src="https://code-thinking-1253855093.file.myqcloud.com/pics/20220426233122.png" data-img="1" width="200" height="200"></img></div>



Expand Down
21 changes: 21 additions & 0 deletions problems/0045.跳跃游戏II.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,27 @@ var jump = function(nums) {
};
```

### TypeScript

```typescript
function jump(nums: number[]): number {
const length: number = nums.length;
let curFarthestIndex: number = 0,
nextFarthestIndex: number = 0;
let curIndex: number = 0;
let stepNum: number = 0;
while (curIndex < length - 1) {
nextFarthestIndex = Math.max(nextFarthestIndex, curIndex + nums[curIndex]);
if (curIndex === curFarthestIndex) {
curFarthestIndex = nextFarthestIndex;
stepNum++;
}
curIndex++;
}
return stepNum;
};
```




Expand Down
2 changes: 0 additions & 2 deletions problems/0051.N皇后.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ for (int col = 0; col < n; col++) {

```CPP
bool isValid(int row, int col, vector<string>& chessboard, int n) {
int count = 0;
// 检查列
for (int i = 0; i < row; i++) { // 这是一个剪枝
if (chessboard[i][col] == 'Q') {
Expand Down Expand Up @@ -178,7 +177,6 @@ void backtracking(int n, int row, vector<string>& chessboard) {
}
}
bool isValid(int row, int col, vector<string>& chessboard, int n) {
int count = 0;
// 检查列
for (int i = 0; i < row; i++) { // 这是一个剪枝
if (chessboard[i][col] == 'Q') {
Expand Down
37 changes: 36 additions & 1 deletion problems/0053.最大子序和.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func maxSubArray(nums []int) int {
return maxSum
}
```

### Javascript:
```Javascript
var maxSubArray = function(nums) {
Expand All @@ -230,6 +230,41 @@ var maxSubArray = function(nums) {
};
```

### TypeScript

**贪心**

```typescript
function maxSubArray(nums: number[]): number {
let curSum: number = 0;
let resMax: number = -Infinity;
for (let i = 0, length = nums.length; i < length; i++) {
curSum += nums[i];
resMax = Math.max(curSum, resMax);
if (curSum < 0) curSum = 0;
}
return resMax;
};
```

**动态规划**

```typescript
// 动态规划
function maxSubArray(nums: number[]): number {
const length = nums.length;
if (length === 0) return 0;
const dp: number[] = [];
dp[0] = nums[0];
let resMax: number = nums[0];
for (let i = 1; i < length; i++) {
dp[i] = Math.max(dp[i - 1] + nums[i], nums[i]);
resMax = Math.max(resMax, dp[i]);
}
return resMax;
};
```



-----------------------
Expand Down
17 changes: 17 additions & 0 deletions problems/0055.跳跃游戏.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,23 @@ var canJump = function(nums) {
};
```

### TypeScript

```typescript
function canJump(nums: number[]): boolean {
let farthestIndex: number = 0;
let cur: number = 0;
while (cur <= farthestIndex) {
farthestIndex = Math.max(farthestIndex, cur + nums[cur]);
if (farthestIndex >= nums.length - 1) return true;
cur++;
}
return false;
};
```




-----------------------
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>
2 changes: 1 addition & 1 deletion problems/0110.平衡二叉树.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ int getDepth(TreeNode* cur) {
}
```
然后再用栈来模拟前序遍历,遍历每一个节点的时候,再去判断左右孩子的高度是否符合,代码如下:
然后再用栈来模拟后序遍历,遍历每一个节点的时候,再去判断左右孩子的高度是否符合,代码如下:
```CPP
bool isBalanced(TreeNode* root) {
Expand Down
12 changes: 12 additions & 0 deletions problems/0122.买卖股票的最佳时机II.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,18 @@ const maxProfit = (prices) => {
};
```

TypeScript:

```typescript
function maxProfit(prices: number[]): number {
let resProfit: number = 0;
for (let i = 1, length = prices.length; i < length; i++) {
resProfit += Math.max(prices[i] - prices[i - 1], 0);
}
return resProfit;
};
```

C:

```c
Expand Down
10 changes: 3 additions & 7 deletions problems/0232.用栈实现队列.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,11 @@ func (this *MyQueue) Pop() int {

/** Get the front element. */
func (this *MyQueue) Peek() int {
for len(this.stack) != 0 {
val := this.stack[len(this.stack)-1]
this.stack = this.stack[:len(this.stack)-1]
this.back = append(this.back, val)
}
if len(this.back) == 0 {
val := this.Pop()
if val == 0 {
return 0
}
val := this.back[len(this.back)-1]
this.back = append(this.back, val)
return val
}

Expand Down
50 changes: 50 additions & 0 deletions problems/0376.摆动序列.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,5 +298,55 @@ var wiggleMaxLength = function(nums) {
};
```

### TypeScript

**贪心**

```typescript
function wiggleMaxLength(nums: number[]): number {
let length: number = nums.length;
if (length <= 1) return length;
let preDiff: number = 0;
let curDiff: number = 0;
let count: number = 1;
for (let i = 1; i < length; i++) {
curDiff = nums[i] - nums[i - 1];
if (
(preDiff <= 0 && curDiff > 0) ||
(preDiff >= 0 && curDiff < 0)
) {
preDiff = curDiff;
count++;
}
}
return count;
};
```

**动态规划**

```typescript
function wiggleMaxLength(nums: number[]): number {
const length: number = nums.length;
if (length <= 1) return length;
const dp: number[][] = new Array(length).fill(0).map(_ => []);
dp[0][0] = 1; // 第一个数作为波峰
dp[0][1] = 1; // 第一个数作为波谷
for (let i = 1; i < length; i++) {
dp[i][0] = 1;
dp[i][1] = 1;
for (let j = 0; j < i; j++) {
if (nums[j] < nums[i]) dp[i][0] = Math.max(dp[i][0], dp[j][1] + 1);
}
for (let j = 0; j < i; j++) {
if (nums[j] > nums[i]) dp[i][1] = Math.max(dp[i][1], dp[j][0] + 1);
}
}
return Math.max(dp[length - 1][0], dp[length - 1][1]);
};
```



-----------------------
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>
4 changes: 4 additions & 0 deletions problems/0707.设计链表.md
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,10 @@ class MyLinkedList {
// 处理头节点
if (index === 0) {
this.head = this.head!.next;
// 如果链表中只有一个元素,删除头节点后,需要处理尾节点
if (index === this.size - 1) {
this.tail = null
}
this.size--;
return;
}
Expand Down
55 changes: 55 additions & 0 deletions problems/0763.划分字母区间.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,61 @@ public:
但这道题目的思路是很巧妙的,所以有必要介绍给大家做一做,感受一下。
## 补充
这里提供一种与[452.用最少数量的箭引爆气球](https://programmercarl.com/0452.用最少数量的箭引爆气球.html)、[435.无重叠区间](https://programmercarl.com/0435.无重叠区间.html)相同的思路。
统计字符串中所有字符的起始和结束位置,记录这些区间(实际上也就是[435.无重叠区间](https://programmercarl.com/0435.无重叠区间.html)题目里的输入),**将区间按左边界从小到大排序,找到边界将区间划分成组,互不重叠。找到的边界就是答案。**
```CPP
class Solution {
public:
static bool cmp(vector<int> &a, vector<int> &b) {
return a[0] < b[0];
}
// 记录每个字母出现的区间
vector<vector<int>> countLabels(string s) {
vector<vector<int>> hash(26, vector<int>(2, INT_MIN));
vector<vector<int>> hash_filter;
for (int i = 0; i < s.size(); ++i) {
if (hash[s[i] - 'a'][0] == INT_MIN) {
hash[s[i] - 'a'][0] = i;
}
hash[s[i] - 'a'][1] = i;
}
// 去除字符串中未出现的字母所占用区间
for (int i = 0; i < hash.size(); ++i) {
if (hash[i][0] != INT_MIN) {
hash_filter.push_back(hash[i]);
}
}
return hash_filter;
}
vector<int> partitionLabels(string s) {
vector<int> res;
// 这一步得到的 hash 即为无重叠区间题意中的输入样例格式:区间列表
// 只不过现在我们要求的是区间分割点
vector<vector<int>> hash = countLabels(s);
// 按照左边界从小到大排序
sort(hash.begin(), hash.end(), cmp);
// 记录最大右边界
int rightBoard = hash[0][1];
int leftBoard = 0;
for (int i = 1; i < hash.size(); ++i) {
// 由于字符串一定能分割,因此,
// 一旦下一区间左边界大于当前右边界,即可认为出现分割点
if (hash[i][0] > rightBoard) {
res.push_back(rightBoard - leftBoard + 1);
leftBoard = hash[i][0];
}
rightBoard = max(rightBoard, hash[i][1]);
}
// 最右端
res.push_back(rightBoard - leftBoard + 1);
return res;
}
};
```

## 其他语言版本

Expand Down
Loading

0 comments on commit d900c34

Please sign in to comment.