1class Solution {2public boolean checkValidString(String s) {3Stack<Integer> stack = new Stack<>();4Stack<Integer> star = new Stack<>();5for (int i = 0; i < s.length(); i++) {6if (s.charAt(i) == '(') stack.push(i);7else if (s.charAt(i) == '*') star.push(i);8else {9if (!stack.isEmpty()) stack.pop();10else if (!star.isEmpty()) star.pop();11else return false;12}13}14while (!stack.isEmpty()) {15if (star.isEmpty()) return false;16else if (stack.peek() < star.peek()) {17star.pop();18stack.pop();19} else return false;20}21return true;22}23}