# 0484. Find Permutation ###### tags: `Leetcode` `Medium` `DI Sequence` `Greedy` Link: https://leetcode.com/problems/find-permutation/description/ ## 思路 思路[参考](https://leetcode.com/problems/find-permutation/solutions/96644/c-simple-solution-in-72ms-and-9-lines/) 和[2375. Construct Smallest Number From DI String](https://hackmd.io/z0lYYhNJR1K5Jj5IOXQ1qw)的思路一样 先按顺序放所有的数字 然后再reverse 两个```I```之间的数字 ## Code ```java= class Solution { public int[] findPermutation(String s) { int n = s.length(); List<Integer> res = new ArrayList<>(); List<Integer> temp = new ArrayList<>(); for(int i=0; i<=n; i++){ temp.add(i+1); if(i==n || s.charAt(i)=='I'){ for(int j=temp.size()-1; j>=0; j--){ res.add(temp.get(j)); } temp.clear(); } } int[] ans = new int[n+1]; for(int i=0; i<=n; i++) ans[i] = res.get(i); return ans; } } ```
×
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