Skip to content

Commit 3ff5b34

Browse files
committed
😄update my solutions
1 parent 710d5c5 commit 3ff5b34

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* linguist-vendored
2+
solutions/* linguist-vendored=false
3+
solutions/*.json linguist-vendored

solutions/001.two-sum/post.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# 001.two-sum
2+
这道题是我在`Leetcode`刷的第一道题,最开始是使用暴力枚举法枚举所有情况,算法复杂度是`O(n)`,很显然,最后超时了。考虑到`Hash Map`的查找的算法复杂度是`O(1)`,这道题便使用了`Hash Map`的解法。
3+
4+
我遍历一次整个数组,遍历到的每个`item`,首先去查`Hash Map`,如果没有,则把它的`index`放进`Hash Map`中存储,之后的遍历中,一旦它的相反数出现,便可以找到两个相加的`0`的数了。
5+
6+
这样我们的算法复杂度变为`O(n)`

0 commit comments

Comments
 (0)