class Solution { public: int strStr(string s1,string s2) { int l1=s1.length(); int l2=s2.length(); if(s1==s2) return 0; if(l1<l2) return -1; for(int i=0;i<=l1-l2;i++) { int j=0; while(j<l2) { if(s1[i]==s2[j]) { i++; j++; } else break; } if(j==l2) return i-j; else i=i-j; } return -1; } };
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