bool isPathCrossing(char * path){ int i=0,x=0,y=0; int len = strlen(path); int** hhash = (int**)calloc(2*len+1,sizeof(int*)); for (;i<=len;i++) { if (!hhash[x+len]) { hhash[x+len] = (int*)calloc(2*len+1,sizeof(int)); hhash[x+len][y+len]++; } else { if (hhash[x+len][y+len]++) return true; } switch(path[i]) { case 'N': y++; break; case 'S': y--; break; case 'W': x--; break; default: x++; break; } } return false; }