MCPcopy Create free account
hub / github.com/ROUTINE-STUDY/Algorithm / Sanghoo

Class Sanghoo

LeetCode/Greedy/942. DI String Match/Sanghoo.java:6–25  ·  view source on GitHub ↗

https://leetcode.com/problems/di-string-match/

Source from the content-addressed store, hash-verified

4 * https://leetcode.com/problems/di-string-match/
5 */
6public class Sanghoo {
7
8 public int[] diStringMatch(String s) {
9 int[] res = new int[s.length()+1];
10 int head = 0;
11 int tail = s.length();
12
13 for(int i=0; i<s.length(); i++) {
14 char ch = s.charAt(i);
15 res[i] = ch=='I' ? head++ : tail--;
16 }
17
18 // tail 값을 넣어도 상관 X, 안들어간 빈 값을 똑같이 가리킴
19 res[s.length()] = head;
20// res[s.length()] = tail;
21
22 return res;
23 }
24
25}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected