@YipCubed/

leet-reverse-string

C++11

No description

fork
loading
Files
  • main.cpp
  • README.md
main.cpp
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <cstring>
#include <climits>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>


using namespace std;

ostream& operator<<(ostream& os, const vector<char>& v) {
  os << "[";
  for (char i : v) {
    os << i << " ";
  }
  os << "]";
  return os;
}

// Live coding problems, watch at
// https://www.twitch.tv/yipcubed
// https://www.youtube.com/channel/UCTV_UOPu7EWXvYWsBFxMsSA/videos
//

// makes code faster, but larger. Just for LeetCode fun!
#pragma GCC optimise ("Ofast")

// makes stdin not synced so it is faster. Just for LeetCode fun!
static auto x = [](){ios_base::sync_with_stdio(false); cin.tie(NULL); return NULL;}();

class Solution {
public:
    void reverseString(vector<char>& s) {
        for (int i = 0, j =  s.size() - 1; i < s.size() / 2; ++i, --j) {
          swap(s[i], s[j]);
        }
    }
};

void test1() {
  Solution S;
  vector<char> v1{'h','e','l','l','o'};
  S.reverseString(v1);
  cout << "[olleh]? " << v1 << endl;
}

void test2() {
  Solution S;
}

void test3() {
  Solution S;
}

int main() {
  test1();
  test2();
  test3();
  cout << "Done!" << endl;
  
  return 0;
}