Skip to content

Commit 2f040d9

Browse files
committed
add exercise
1 parent 7b0d690 commit 2f040d9

File tree

8 files changed

+77
-6
lines changed

8 files changed

+77
-6
lines changed

cpp/0001_two_sum/0001_two_sum.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include <unordered_map>
44
#include <vector>
55

6-
using std::cout;
76
using std::unordered_map;
87
using std::vector;
98

cpp/0001_two_sum/0001_two_sum_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "cpp/0001_two_sum/0001_two_sum.h"
1+
#include "0001_two_sum.h"
22
#include <gtest/gtest.h>
33
#include <vector>
44

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include "0020_valid_parentheses.h"
2+
#include <iostream>
3+
#include <stack>
4+
#include <string>
5+
#include <unordered_map>
6+
7+
using std::stack;
8+
using std::unordered_map;
9+
10+
bool Solution::isValid(string s) {
11+
unordered_map<char, char> dict({{'(', ')'}, {'[', ']'}, {'{', '}'}});
12+
stack<char> stack;
13+
std::cout << "heyyy" << "\n";
14+
15+
for (const char &letter : s) {
16+
std::cout << "heyyy" << "\n";
17+
if (dict.find(letter) != dict.end()) {
18+
stack.push(dict[letter]);
19+
continue;
20+
}
21+
22+
if (stack.empty()) {
23+
return false;
24+
}
25+
26+
const char& popped = stack.top();
27+
28+
if (letter != popped) {
29+
return false;
30+
}
31+
32+
stack.pop();
33+
}
34+
35+
return stack.empty();
36+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <stdio.h>
2+
#include <string>
3+
4+
using std::string;
5+
6+
class Solution {
7+
public:
8+
bool isValid(string s);
9+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "0020_valid_parentheses.h"
2+
#include <gtest/gtest.h>
3+
#include <string>
4+
5+
using std::string;
6+
7+
TEST(ValidParenthesisTest, SimpleString) {
8+
string s = "()";
9+
10+
ASSERT_TRUE(Solution().isValid(s));
11+
}
12+
13+
TEST(ValidParenthesisTest, AllSymbolsString) {
14+
string s = "()[]{}";
15+
16+
ASSERT_TRUE(Solution().isValid(s));
17+
}
18+
19+
TEST(ValidParenthesisTest, InvalidString) {
20+
string s = "(]";
21+
22+
ASSERT_FALSE(Solution().isValid(s));
23+
}
24+
25+
TEST(ValidParenthesisTest, InvalidString2) {
26+
string s = "]";
27+
28+
ASSERT_FALSE(Solution().isValid(s));
29+
}

cpp/0200_number_of_islands/0200_number_of_islands.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include <iostream>
33
#include <vector>
44

5-
using std::cout;
65
using std::vector;
76

87
void dfs(vector<vector<char>> &grid, size_t row, size_t column) {

cpp/0200_number_of_islands/0200_number_of_islands.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ using std::vector;
55
class Solution {
66
public:
77
int numIslands(vector<vector<char>> &grid);
8-
}
9-
;
8+
};

cpp/0200_number_of_islands/0200_number_of_islands_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "cpp/0200_number_of_islands/0200_number_of_islands.h"
1+
#include "0200_number_of_islands.h"
22
#include <gtest/gtest.h>
33
#include <vector>
44

0 commit comments

Comments
 (0)