[go: nahoru, domu]

Skip to content

Commit

Permalink
update lc
Browse files Browse the repository at this point in the history
  • Loading branch information
lzyrapx committed Jul 8, 2020
1 parent 10f0b04 commit dd97482
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
36 changes: 36 additions & 0 deletions LeetCode/Easy/1496.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* @Author: zhaoyang.liang
* @Github: https://github.com/LzyRapx
* @Date: 2020-07-07 13:45:26
*/
class Solution {
public:
bool isPathCrossing(string path) {
if(path.size() == 0){
return false;
}
int res = false;
set<pair<int,int>>se;
pair<int,int>pi = {0, 0};
se.insert({0, 0});
for(int i = 0; i < path.size(); i++){
if(path[i] == 'N') {
pi.second += 1;
}
if(path[i] == 'S'){
pi.second -= 1;
}
if(path[i] == 'E') {
pi.first += 1;
}
if(path[i] == 'W') {
pi.first -= 1;
}
if(se.count(pi)) {
return true;
}
se.insert(pi);
}
return false;
}
};
25 changes: 25 additions & 0 deletions LeetCode/Easy/1502.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* @Author: zhaoyang.liang
* @Github: https://github.com/LzyRapx
* @Date: 2020-07-07 13:48:57
*/
class Solution {
public:
bool canMakeArithmeticProgression(vector<int>& arr) {
sort(arr.begin(), arr.end());
int cur_diff = 0;
int last_diff = -1;
for(int i = 1; i < arr.size(); i++) {
cur_diff = arr[i] - arr[i - 1];
if(last_diff == -1) {
last_diff = cur_diff;
}
else {
if(last_diff != cur_diff) {
return false;
}
}
}
return true;
}
};

0 comments on commit dd97482

Please sign in to comment.