The following function accepts 2 strings, the 2nd (not 1st) possibly containing *
s (asterisks).
An *
is a replacement for a string (empty, 1 char or more), it can appear appear (only in s2) once, twice, more or not at all, it cannot be adjacent to another *
(ab**c
), no need to check that.
public static boolean samePattern(String s1, String s2)
It returns true if strings are of the same pattern.
It must be recursive, not use any loops, static or global variables. Also it s prohibited to use the method equals
in the String class. Can use local variables and method overloading.
Can use only these methods: charAt(i)
, substring(i)
, substring(i, j)
, length()
.
实例:
1: TheExamIsEasy; 2: "The*xamIs*y" ---> true
1: TheExamIsEasy; 2: "Th*mIsEasy*" ---> true
1: TheExamIsEasy; 2: "*" ---> true
1: TheExamIsEasy; 2: "TheExamIsEasy" ---> true
1: TheExamIsEasy; 2: "The*IsHard" ---> FALSE
我在很多小时的时间里一直在处理这个问题! 在 Java,我需要找到解决办法。