tag:blogger.com,1999:blog-4731036105252322780.post4124906370712026250..comments2024-03-01T02:55:58.951-08:00Comments on Buttercola: Leetcode: Minimum Window SubstringButter is looking for a jobhttp://www.blogger.com/profile/01481083468821703855noreply@blogger.comBlogger1125tag:blogger.com,1999:blog-4731036105252322780.post-61648588747589540642018-11-07T05:15:52.002-08:002018-11-07T05:15:52.002-08:00Hi ,
Wish to know if this will be efficient enough...Hi ,<br />Wish to know if this will be efficient enough as i have only one for loop and List to add the index<br /><br />public String soultion(String sourceWord, String targetWord) {<br /> String minWord = new String();<br /> List matchChar = new ArrayList();<br /> int minWordLength = sourceWord.length();<br /> if ((Objects.nonNull(sourceWord) && !sourceWord.isEmpty())<br /> && (Objects.nonNull(targetWord) && !targetWord.isEmpty())) {<br /><br /> for (int i = 0; i < sourceWord.length(); i++) {<br /><br /> if (targetWord.contains(Character.toString(sourceWord.charAt(i)))) {<br /> matchChar.add(i);<br /> if (matchChar.size() == targetWord.length()) {<br /> if (minWordLength > (i - matchChar.get(0))) {<br /> minWordLength = i - matchChar.get(0);<br /> minWord = sourceWord.substring(matchChar.get(0), i + 1);<br /> matchChar.clear();<br /> }<br /> }<br /> }<br /><br /> }<br /><br /> } else {<br /> return "";<br /> }<br /><br /> return minWord;<br /> }<br /><br />infofaizalhttps://www.blogger.com/profile/16459173106326398395noreply@blogger.com