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.
publicstaticStringabbreviation(Stringa,Stringb){intm=a.length();intn=b.length();if(m<n){return"NO";}boolean[][]isValid=newboolean[m+1][n+1];isValid[0][0]=true;for(inti=1;i<=m;i++){charca=a.charAt(i-1);// mark if this character can be skippedbooleancanBeSkipped=Character.isLowerCase(ca);isValid[i][0]=canBeSkipped;for(intj=1;j<=n;j++){charcb=b.charAt(j-1);booleanmatches=Character.toUpperCase(ca)==cb;isValid[i][j]=(matches&&isValid[i-1][j-1])||(canBeSkipped&&isValid[i-1][j]);}}// System.out.println(// Arrays// .deepToString(isValid)// .replace("true", "1")// .replace("false", "0")// .replace("],", "],\n"));returnisValid[m][n]?"YES":"NO";}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Abbreviation
You are viewing a single comment's thread. Return to all comments →
Java: