-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
feat: 修改错别字,并添加题解 #343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 修改错别字,并添加题解 #343
Conversation
problems/1.TwoSum.md
Outdated
所以返回 [0, 1] | ||
``` | ||
## 思路 | ||
使用一层循环、每遍历到一个元素就计算该元素与target之间的差值diff,然后以diff为下标到数组temp中寻找 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 题目都加下时间复杂度分析吧。 我后面的题目也会加。 这题的复杂度不好,为O(max(nums)),建议 hashmap
- 可以先将一下双层循环怎么做
problems/1.TwoSum.md
Outdated
- 如果temp[diff]有值,则返回两个元素在数组nums的下标 | ||
- 如果没有找到,则将当前元素存入数组temp中(下标nums[i], 下标nums[i]对应的值i) | ||
|
||
时间复杂度:O(n) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
复杂度的格式为:
复杂度分析
- 时间复杂度:$O(N)$
- 空间复杂度:$O(N)$
problems/1.TwoSum.md
Outdated
const temp = []; | ||
for (let i = 0; i < nums.length; i++) { | ||
const diff = target - nums[i]; | ||
if (temp[diff] != undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (temp[diff] != undefined) { | |
if (temp[diff] != void 0) { |
输出: false | ||
``` | ||
|
||
## 思路 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
思路太简单。 更偏向关键点堆砌。建议优化为自然语言
``` | ||
|
||
## 思路 | ||
- 用哈希表存下对应的值 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这不是思路。 思路可以参考我的回溯专题
|
||
``` | ||
|
||
## 思路 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
一样的问题。 这不是思路,是关键点。
并且使用递归的原因只是其比较简单,容易书写,并且数据规模合适,并不是关键
|
||
``` | ||
|
||
## 思路 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议使用自然语言描述思路。
problems/22.GenerateParentheses.md
Outdated
|
||
## 关键点 | ||
|
||
- 处理有效括号 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个关键点没懂
所以你应该输出2. | ||
``` | ||
|
||
## 思路 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议改为从小到大满足。 参考:
class Solution:
def findContentChildren(self, g: List[int], s: List[int]) -> int:
g.sort()
s.sort()
cnt = 0
j = 0
for i in range(len(s)):
if j < len(g) and s[i] >= g[j]:
cnt += 1
j += 1
return cnt
] | ||
``` | ||
|
||
## 思路 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看了思路还是一头雾水。 是否可以用自然语言描述下
problems/1.TwoSum.md
Outdated
- 最容易想到的就是暴力枚举,我们可以利用两层 for 循环来遍历每个元素,并查找满足条件的目标元素。 | ||
- 不过这样时间复杂度为 O(N^2),空间复杂度为 O(1),时间复杂度较高,我们要想办法进行优化。 | ||
- 我们增加一个 Map 记录已经遍历过的数字及其对应的索引值。 | ||
- 这样当遍历一个新数字的时候去 Map 里查询,与该数的差值是否已经在前面的数字中出现过 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 这样当遍历一个新数字的时候去 Map 里查询,与该数的差值是否已经在前面的数字中出现过 | |
- 这样当遍历一个新数字的时候去 Map 里查询,target 与该数的差值是否已经在前面的数字中出现过 |
@@ -15,16 +15,22 @@ https://leetcode-cn.com/problems/two-sum | |||
所以返回 [0, 1] | |||
``` | |||
## 思路 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不建议无序列表
## 思路 | ||
- 用哈希表存下对应的值 | ||
- 递归 | ||
## 思想 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## 思想 | |
## 思路 |
|
||
## 关键点 | ||
利用回溯思想解题,在for循环中调用递归。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
利用回溯思想解题,在for循环中调用递归。 | |
- 回溯 |
problems/52.N-Queens-II.md
Outdated
|
||
## 关键点 | ||
|
||
对位运算公式的理解和运用 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对位运算公式的理解和运用 | |
- 位运算 | |
- DFS(深度优先搜索) |
No description provided.