It works in eclipse and codepad but the test case is not passed here?


#1

System.out.println(wildCardMatch(“aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa”, “*b”, 0, 0) ? 1 : 0);

public static boolean wildCardMatch(String str, String exp, int pos1, int pos2) {
if (exp.length() == pos2) {

		return str.length() == pos1;
	}

	// Implemeting . and a match
	if (exp.charAt(pos2) != '*') {
		if (str.charAt(pos1) == exp.charAt(pos2) || exp.charAt(pos2) == '?') {
			return wildCardMatch(str, exp, pos1 + 1, pos2 + 1);
		}
	}

	// Implementing the *
	if (pos2 != exp.length() - 1) {

		char lastMatchChar = exp.charAt(pos2 + 1);

		// Skip the string to the lastMatchChar in the expression
		int i = str.length() - 1;

		while (lastMatchChar != str.charAt(i)) {

			if (i == 0) {
				return false;
			}
			i--;
		}

		// Found, skip the string chars till u goto i in string
		while (pos1 != i) {
			pos1++;
		}

		return wildCardMatch(str, exp, pos1, pos2 + 1);

	} else {
		return true;
	}
}