1class Solution {2public:3bool isPathCrossing(string path) {4set<pair<int, int>> st;56int x = 0, y = 0;78st.insert({0, 0});910for (int i = 0; i < path.length(); i++) {11if (path[i] == 'N') {12x++;13}1415else if (path[i] == 'S') {16x--;17}1819else if (path[i] == 'E') {20y++;21}2223else {24y--;25}2627// if pair find at any point, return true28if (st.find({x, y}) != st.end()) {29return 1;30}31// insert the pair32st.insert({x, y});33}34return 0;35}36};