import java.util.*; public class winsen { /* T : n^2 S: O(1) 2, 3, 5, 7, */ public static int countPrime(int n){ int count=0; for ( int i=2; i [] Output: "apple" Input: s = "abpcplea", dictionary = ["a","b","c"] Output: "a" * * * T : O (n log(N) ). M*N*K * * * * */ public static String lexSmallStringByRemovingSomeCharsFromString( String str, String[] dict){ ListpossibleStrings= new ArrayList(); for( String s : dict){ // T : O(len(dict)) if( isPossible( str, s)) possibleStrings.add(s); } if (possibleStrings.isEmpty()) return ""; Collections.sort(possibleStrings , (a,b) -> ( b.length()-a.length()) ); // T : O(nlog(n)) System.out.println(possibleStrings); return possibleStrings.stream() .filter( strr -> strr.length()==possibleStrings.get(0).length()) .sorted().findFirst().orElse(""); // T : O(nlog(n)) } public static boolean isPossible( String str, String s){ int m = str.length(), n= s.length(), i=0, j=0; while (i 结果:未选中
免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3