File tree Expand file tree Collapse file tree 2 files changed +61
-0
lines changed Expand file tree Collapse file tree 2 files changed +61
-0
lines changed Original file line number Diff line number Diff line change 1+ class Solution {
2+ public:
3+ bool isPathCrossing (string path) {
4+
5+ int x = 0 , y = 0 ;
6+ set<pair<int , int >> points;
7+ points.insert ({ x,y });
8+
9+ for (int i = 0 ; i < path.length (); i++) {
10+ if (path[i] == ' N' )
11+ {
12+ y++;
13+ }
14+ if (path[i] == ' S' )
15+ {
16+ y--;
17+ }
18+ if (path[i] == ' E' )
19+ {
20+ x++;
21+ }
22+ if (path[i] == ' W' )
23+ {
24+ x--;
25+ }
26+ auto temp = points.insert ({ x,y });
27+ if (temp.second == false )
28+ return true ;
29+ }
30+ return false ;
31+ }
32+ };
Original file line number Diff line number Diff line change 1+ class Solution :
2+ def isPathCrossing (self , path : str ) -> bool :
3+ x = 0
4+ y = 0
5+ points = set ()
6+
7+ str = "{}, {}" .format (x ,y )
8+ points .add (str )
9+ for i in range (len (path )):
10+ if (path [i ]== 'N' ):
11+ y = y + 1
12+
13+ if (path [i ]== 'S' ):
14+ y = y - 1
15+
16+ if (path [i ]== 'E' ):
17+ x = x + 1
18+
19+ if (path [i ]== 'W' ):
20+ x = x - 1
21+
22+ l = len (points )
23+ str = "{}, {}" .format (x ,y )
24+ points .add (str )
25+
26+ if (len (points ) == l ):
27+ return True
28+
29+ return False
You can’t perform that action at this time.
0 commit comments