Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <list>
- #include <map>
- #include <set>
- #include <deque>
- #include <stack>
- #include <bitset>
- #include <algorithm>
- #include <functional>
- #include <numeric>
- #include <utility>
- #include <sstream>
- #include <iostream>
- #include <iomanip>
- #include <cstdio>
- #include <cmath>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- class RouteIntersection {
- public:
- string isValid(int, vector <int>, string);
- };
- string RouteIntersection::isValid(int N, vector <int> coords, string moves) {
- int ss = coords.size();
- for(int i = 0; i < ss; i++ ){
- map<int, int> values;
- int cnt_repeat = 0;
- for(int j = i; j < ss; j++ ){
- if(moves[j] == '+'){
- int temp = ++values[coords[j]];
- if(temp == 1) cnt_repeat++;
- else if(temp == 0) cnt_repeat--;
- } else {
- int temp = --values[coords[j]];
- if(temp == -1) cnt_repeat++;
- else if(temp == 0) cnt_repeat--;
- }
- if(cnt_repeat == 0) return "NOT VALID";
- }
- }
- return "VALID";
- }
- <%:testing-code%>
- //Powered by [KawigiEdit] 2.0!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement