Add tags

Add tags to the following comment

2次元配列をやめてみたけど、実行時間は変わらず…

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class P2 {
    public static void main(String[] args) throws Exception {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String s1 = in.readLine();
        String s2 = in.readLine();
        int[] prev = new int[s2.length()];

        int max = 0;
        for (int i = 0; i < s1.length(); i++) {
            char c1 = s1.charAt(i);
            int[] next = new int[s2.length()];
            for (int j = 0; j < s2.length(); j++) {
                if (c1 == s2.charAt(j)) {
                    if (j > 0)
                        next[j] = prev[j - 1] + 1;
                    else
                        next[j] = 1;
                    max = Math.max(max, next[j]);
                }
            }
            prev = next;
        }
        System.out.println(max);
    }
}

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...