# 2375. Construct Smallest Number From DI String ###### tags: `Leetcode` `Medium` `DI Sequence` `Greedy` Link: https://leetcode.com/problems/construct-smallest-number-from-di-string/description/ ## 思路 思路[参考](https://leetcode.com/problems/construct-smallest-number-from-di-string/solutions/2422380/java-c-python-easy-reverse/) 先把所有数字正常放 然后把每两个```I```中间的数字reverse一下 ## Code ```java= class Solution { public String smallestNumber(String pattern) { StringBuilder ans = new StringBuilder(); StringBuilder temp = new StringBuilder(); for(int i=0; i<=pattern.length(); i++){ temp.append((char)('1'+i)); if(i==pattern.length() || pattern.charAt(i)=='I'){ ans.append(temp.reverse()); temp.setLength(0); } } return ans.toString(); } } ```
×
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