ARTS 第13周:有效的括号算法、Java动态代理、近期技术成长

#coding#arts
目录

Algorithm

package org.nocoder.leetcode.solution;

import java.util.HashMap;
import java.util.Stack;

/**
 * Given a string containing just the characters '(', ')', '{', '}', '[' and ']',
 * determine if the input string is valid.
 * <p>
 * An input string is valid if:
 * <p>
 * Open brackets must be closed by the same type of brackets.
 * Open brackets must be closed in the correct order.
 * Note that an empty string is also considered valid.
 * <p>
 * Example 1:
 * <p>
 * Input: "()"
 * Output: true
 * Example 2:
 * <p>
 * Input: "()[]{}"
 * Output: true
 * Example 3:
 * <p>
 * Input: "(]"
 * Output: false
 * Example 4:
 * <p>
 * Input: "([)]"
 * Output: false
 * Example 5:
 * <p>
 * Input: "{[]}"
 * Output: true
 *
 * @author jason
 * @date 2018/10/1.
 */
public class ValidParentheses {

    public boolean isValid(String s) {
        if (null == s && "".equals(s)) {
            return true;
        }

        if ((s.length() % 2) != 0) {
            return false;
        }

        HashMap<Character, Character> map = new HashMap<Character, Character>();
        map.put('(', ')');
        map.put('[', ']');
        map.put('{', '}');

        Stack<Character> stack = new Stack<Character>();

        for (int i = 0; i < s.length(); i++) {
            char curr = s.charAt(i);

            if (map.keySet().contains(curr)) {
                stack.push(curr);
            } else if (map.values().contains(curr)) {
                if (!stack.empty() && map.get(stack.peek()) == curr) {
                    stack.pop();
                } else {
                    return false;
                }
            }
        }

        return stack.empty();
    }
}

Review

Dynamic Proxies in Java

https://www.baeldung.com/java-dynamic-proxies https://docs.oracle.com/javase/8/docs/technotes/guides/reflection/proxy.html

Tip

Valid Parentheses 解题思路

Share

花了点时间总结一下来公司这些日子做的东西,自我感觉良好,跟着春哥学了不少东西,这半年还是很充实的。 记得有一次春哥笑着跟我说,“你要相信,别人能做出来的东西,你也可以。”

架构设计

框架应用

CI/CD

容器应用

中间件

设计模式应用

操作系统

工具

脚本语言

Java


评论区