(leetcode)di-string-match,Javaプール

3946 ワード

  • リンク:https://leetcode.com/problems/di-string-match/submissions/2
  • public int[] diStringMatch(String s) {
            int mini = 0;
            int maxi = s.length();
            int[] ret = new int[s.length()+1];
            int idx = 0;
            for(int i=0 ; i<s.length() ; i++) {
                if(s.charAt(i) == 'I') {
                    ret[idx++] = mini++;
                }
                else {
                    ret[idx++] = maxi--;
                }
            }
            ret[idx] = mini;
            return ret;
        }