diff --git a/Sliding Puzzle.cpp b/Sliding Puzzle.cpp new file mode 100644 index 0000000..675b2cc --- /dev/null +++ b/Sliding Puzzle.cpp @@ -0,0 +1,74 @@ +class Solution { +public: + int dx[4]={0,0,1,-1}; + int dy[4]={1,-1,0,0}; + bool chk(vector>& board) + { + int k=1; + for(int i=0;i>& board) { + queue,vector>>> q; + for(int i=0;i>> st; + st.insert(board); + while(!q.empty()) + { + int sz=q.size(); + while(sz--) + { + auto temp=q.front(); + q.pop(); + int x=temp.first.first; + int y=temp.first.second; + if(chk(temp.second)) + { + return steps; + } + for(int i=0;i<4;++i) + { + int nx=x+dx[i]; + int ny=y+dy[i]; + if(nx>=0 && ny>=0 && nx