class Solution { public: int vis[50001]; bool canReach(vector<int>& a, int i) { if(i<0||i>=a.size()||vis[i])return false; if(a[i]==0)return true; vis[i]=1; return canReach(a,i+a[i])||canReach(a,i-a[i]); } };
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter