# 0942. DI String Match ###### tags: `Leetcode` `Easy` `DI Sequence` `Greedy` Link: https://leetcode.com/problems/di-string-match/description/ ## 思路 $O(N)$ $O(N)$ greedy的思想: 遇到```I```当前数字能填多小填多小 遇到```D```当前数字能填多大填多大 ## Code ```java= class Solution { public int[] diStringMatch(String s) { int n = s.length(); int[] arr = new int[n+1]; int left = 0, right = n; for(int i=0; i<s.length(); i++){ if(s.charAt(i)=='D') arr[i] = right--; else arr[i] = left++; } arr[n] = left; return arr; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up