Skip to content

Commit 0bfb0cf

Browse files
committed
1003 added.
1 parent 49745dd commit 0bfb0cf

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
project(B)
3+
4+
set(CMAKE_CXX_STANDARD 14)
5+
6+
add_executable(B main.cpp)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/// Source : https://leetcode.com/problems/check-if-word-is-valid-after-substitutions/
2+
/// Author : liuyubobobo
3+
/// Time : 2019-03-02
4+
5+
#include <iostream>
6+
7+
using namespace std;
8+
9+
10+
/// Ad-Hoc
11+
/// Recursive
12+
/// Time Complexity: O(n^2)
13+
/// Space Complexity: O(n)
14+
class Solution {
15+
public:
16+
bool isValid(const string& s) {
17+
18+
if(s.size() % 3) return false;
19+
if(s.size() == 0) return true;
20+
21+
for(int i = 2; i < s.size(); i ++)
22+
if(s[i - 2] == 'a' && s[i - 1] == 'b' && s[i] == 'c')
23+
return isValid(s.substr(0, i - 2) + s.substr(i + 1));
24+
return false;
25+
}
26+
};
27+
28+
29+
int main() {
30+
31+
return 0;
32+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/// Source : https://leetcode.com/problems/check-if-word-is-valid-after-substitutions/
2+
/// Author : liuyubobobo
3+
/// Time : 2019-03-03
4+
5+
#include <iostream>
6+
7+
using namespace std;
8+
9+
10+
/// Ad-Hoc
11+
/// Iterative
12+
/// Time Complexity: O(n^2)
13+
/// Space Complexity: O(1)
14+
class Solution {
15+
public:
16+
bool isValid(string s) {
17+
18+
for(int i = s.find("abc"); i != string::npos; i = s.find("abc"))
19+
s.erase(i, 3);
20+
return s == "";
21+
}
22+
};
23+
24+
25+
int main() {
26+
27+
return 0;
28+
}

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,4 +667,5 @@ email: [liuyubobobo@gmail.com](mailto:liuyubobobo@gmail.com)
667667
| 996 | [Number of Squareful Arrays](https://leetcode.com/problems/number-of-squareful-arrays/) | [solution](https://leetcode.com/problems/number-of-squareful-arrays/solution/) | [C++](0996-Number-of-Squareful-Arrays/cpp-0996/) | | |
668668
| | | | | | |
669669
| 1002 | [Find Common Characters](https://leetcode.com/problems/find-common-characters/) | [] | [C++](1002-Find-Common-Characters/cpp-1002/) | | |
670+
| 1003 | [Check If Word Is Valid After Substitutions](https://leetcode.com/problems/check-if-word-is-valid-after-substitutions/) | [] | [C++](1003-Check-If-Word-Is-Valid-After-Substitutions/cpp-1003/) | | |
670671
| | | | | | |

0 commit comments

Comments
 (0)