1. /**
    2. * @Description 简单题开始,这傻逼题用了半小时来做
    3. * 我是真的菜啊,愁死我,我好像是个憨批
    4. * @Date 2022/1/29 2:49 下午
    5. * @Author wuqichuan@zuoyebang.com
    6. **/
    7. public class Solution {
    8. public boolean isValid(String s) {
    9. HashMap<Character,Character> map = new HashMap<>();
    10. map.put(')','(');
    11. map.put(']','[');
    12. map.put('}','{');
    13. Stack<Character> stack = new Stack<>();
    14. char[] chars = s.toCharArray();
    15. for(Character c : chars){
    16. if(map.containsKey(c)){
    17. if(stack.isEmpty() || stack.peek() != map.get(c)){
    18. return false;
    19. }else {
    20. stack.pop();
    21. }
    22. }else {
    23. stack.push(c);
    24. }
    25. }
    26. return stack.isEmpty();
    27. }
    28. }