FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LeetCodeAnimation/0344-Reverse-String/cpp-0344/main.cpp at master · Chris039/LeetCodeAnimation · GitHub
Chris039
/
LeetCodeAnimation
Public
forked from
MisterBooo/LeetCodeAnimation
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
LeetCodeAnimation
/
0344-Reverse-String
/
cpp-0344
/
main.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
35 lines (26 loc) · 628 Bytes
Breadcrumbs
LeetCodeAnimation
/
0344-Reverse-String
/
cpp-0344
/
main.cpp
Copy path
File metadata and controls
executable file
·
35 lines (26 loc) · 628 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
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//
/ Source : https://leetcode.com/problems/reverse-string/description/
//
/ Author : liuyubobobo
//
/ Time : 2018-06-04
#
include
<
iostream
>
using
namespace
std
;
//
344. Reverse String
//
https://leetcode.com/problems/reverse-string/description/
//
Two Pointers
//
时间复杂度: O(n)
//
空间复杂度: O(1)
class
Solution
{
public:
string
reverseString
(string s) {
int
i =
0
, j = s.
size
() -
1
;
while
(i < j){
swap
(s[i], s[j]);
i ++;
j --;
}
return
s;
}
};
int
main
() {
cout <<
Solution
().
reverseString
(
"
hello
"
) << endl;
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL