You are viewing a single comment's thread. Return to all comments →
But it should break out of the loop once j is equal to str.length(), he had done some wasted empty iterations
for (int i = 0; i < s.length(); i++) { if (j < str.length() && s.charAt(i) == str.charAt(j)) { j++; } if(j==str.length()){ break; } }
Seems like cookies are disabled on this browser, please enable them to open this website
HackerRank in a String!
You are viewing a single comment's thread. Return to all comments →
But it should break out of the loop once j is equal to str.length(), he had done some wasted empty iterations