image_2021-10-26_18-02-16.png
36.4 KB
#N942. DI String Match
problem link=>https://leetcode.com/problems/di-string-match/
#solution
problem link=>https://leetcode.com/problems/di-string-match/
#solution
class Solution {
public int[] diStringMatch(String s) {
char[] ch=s.toCharArray();
int[] arr=new int[ch.length+1];
int I0=0, Dn=ch.length;
for(int i=0; i<ch.length; i++){
if(ch[i]=='I')
arr[i]=I0++;
if(ch[i]=='D')
arr[i]=Dn--;
}
arr[arr.length-1]=I0;
return arr;
}
}