Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wwwanlingxiao
LeetCodeAnimation
Commits
a86c0a02
Unverified
Commit
a86c0a02
authored
Jul 29, 2020
by
Zong
Committed by
GitHub
Jul 29, 2020
Browse files
Update 0167-Two-Sum-II-Input-array-is-sorted.md
parent
129f9a8f
Changes
1
Hide whitespace changes
Inline
Side-by-side
0167-Two-Sum-II-Input-array-is-sorted/Article/0167-Two-Sum-II-Input-array-is-sorted.md
View file @
a86c0a02
...
...
@@ -48,20 +48,27 @@
class
Solution
{
public:
vector
<
int
>
twoSum
(
vector
<
int
>&
numbers
,
int
target
)
{
int
l
=
0
,
r
=
numbers
.
size
()
-
1
;
while
(
l
<
r
){
if
(
numbers
[
l
]
+
numbers
[
r
]
==
target
){
int
res
[
2
]
=
{
l
+
1
,
r
+
1
};
return
vector
<
int
>
(
res
,
res
+
2
);
int
n
=
numbers
.
size
();
int
left
=
0
;
int
right
=
n
-
1
;
while
(
left
<=
right
)
{
if
(
numbers
[
left
]
+
numbers
[
right
]
==
target
)
{
return
{
left
+
1
,
right
+
1
};
}
else
if
(
numbers
[
left
]
+
numbers
[
right
]
>
target
)
{
right
--
;
}
else
{
left
++
;
}
else
if
(
numbers
[
l
]
+
numbers
[
r
]
<
target
)
l
++
;
else
// numbers[l] + numbers[r] > target
r
--
;
}
return
{
-
1
,
-
1
};
}
};
```
#### Java
```
java
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment