FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
leetcode-study/two-sum/HC-kang.ts at main · DaleStudy/leetcode-study · GitHub
DaleStudy
/
leetcode-study
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
359
Star
156
Code
Issues
75
Pull requests
1
Discussions
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
leetcode-study
/
two-sum
/
HC-kang.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
13 lines (13 loc) · 318 Bytes
Breadcrumbs
leetcode-study
/
two-sum
/
HC-kang.ts
Copy path
File metadata and controls
13 lines (13 loc) · 318 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
// T.C. O(n)
// S.C. O(n)
function
twoSum
(
nums
:
number
[
]
,
target
:
number
)
:
number
[
]
{
const
sumMap
=
new
Map
<
number
,
number
>
(
)
;
for
(
const
[
i
,
num
]
of
nums
.
entries
(
)
)
{
const
diff
=
target
-
num
;
if
(
sumMap
.
has
(
diff
)
)
{
return
[
sumMap
.
get
(
diff
)
!
,
i
]
;
}
sumMap
.
set
(
num
,
i
)
;
}
return
[
]
;
}
Back
|
FazBrowse Home
|
New Git URL