We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
publicstaticStringhackerrankInString(Strings){Stringstr="hackerrank";inti=0;// Pointer for the "hackerrank" stringfor(intj=0;j<s.length();j++){if(i<str.length()&&str.charAt(i)==s.charAt(j)){i++;// Move the pointer for "hackerrank"}if(i==str.length()){// Check if all characters of "hackerrank" are foundreturn"YES";}}return"NO";// If the loop ends and "hackerrank" is not fully matched}
Cookie support is required to access HackerRank
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 →
Simple Java: