# 第八周ARTS总结

# Algorithm

61ms | 14.81% Run time
41.2MB | 23.09% Memory

public boolean isMatch(String s, String p) {
    if (p.isEmpty()) {
        return s.isEmpty();
    }

    boolean first_match = (!s.isEmpty() &&
            (p.charAt(0) == s.charAt(0) || p.charAt(0) == '.'));

    if (p.length() >= 2 && p.charAt(1) == '*') {
        return (isMatch(s, p.substring(2)) ||
                (first_match && isMatch(s.substring(1), p)));
    } else {
        return first_match && isMatch(s.substring(1), p.substring(1));
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

注:该题参考了solution的解法

# Review

# Tip

  • 方法
public static void main(String[] args) {
    Object o1 = true ? new Integer(1) : new Double(0.1);
    Object o2 = new Integer(1);
    System.out.println(o1);
    System.out.println(o2);
}
1
2
3
4
5
6

的输出结果是

1.0
1

第一行会被编译为 Object o1 = Double.valueOf(new Integer(1).intValue());

# Share

暂无内容

更新时间: 10/20/2022, 7:04:01 AM