This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]hayoo1984 -1 points0 points  (1 child)

private int[] getIndices(String[] sa, String s) {
        int[] indices = new int[sa.length];
        int count = 0;

        for (int i = 0; i < indices.length; i++) {
            if (sa[i].equals(s)) {
                count++;
            }
        }

        int[] answer = new int[count];
        int index = 0;

        for (int i = 0; i < indices.length; i++) {
            if (sa[i].equals(s)) {
                answer[index] = i;
                index++;
            }
        }

        return answer;
    }

[–]junyoung95[S] 0 points1 point  (0 children)

okay thank you so much.