aboutsummaryrefslogtreecommitdiff
path: root/reverse_string.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'reverse_string.cpp')
-rw-r--r--reverse_string.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/reverse_string.cpp b/reverse_string.cpp
new file mode 100644
index 0000000..f5940a0
--- /dev/null
+++ b/reverse_string.cpp
@@ -0,0 +1,15 @@
+#include "leetcode.h"
+
+class Solution {
+public:
+ void reverseString(vector<char> &s) {
+ int i = 0, j = s.size() - 1;
+ while (i <= j) {
+ char tmp = s[i];
+ s[i] = s[j];
+ s[j] = tmp;
+ i++;
+ j--;
+ }
+ }
+};