import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param s string字符串
* @return bool布尔型
*/
public boolean isValidString(String s) {
// write code here
if (0 == s.length()) {
return true;
}
if (1 == s.length()) {
return false;
}
int num = 0;
int account = 0;
boolean bool1 = true;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == '*') {
num++;
} else if (s.charAt(i) == '(') {
account++;
} else {
if (account == 0) {
if (num == 0) {
bool1 = false;
break;
}
num--;
} else {
account--;
}
}
}
if (bool1) {
bool1 = account <= num;
}
num = 0;
account = 0;
boolean bool2 = true;
for (int i = s.length() - 1; i > -1; i--) {
if (s.charAt(i) == '*') {
num++;
} else if (s.charAt(i) == ')') {
account++;
} else {
if (account == 0) {
if (num == 0) {
bool2 = false;
break;
}
num--;
} else {
account--;
}
}
}
if (bool2) {
bool2 = account <= num;
}
return bool1 && bool2;
}
}