image.pnghttps://leetcode-cn.com/problems/queries-on-a-permutation-with-key/
代码参考 & 解释,引用自:
https://leetcode-cn.com/problems/queries-on-a-permutation-with-key/solution/queries-on-a-permutation-with-key-by-ikaruga/
(图片来源https://leetcode-cn.com/problems/queries-on-a-permutation-with-key/
)
日期 | 是否一次通过 | comment |
---|---|---|
2020-03-23 | 0 |
public int[] processQueries(int[] queries, int m) {
int [] f = new int [m+1];
for(int i=1;i<=m;i++)f[i]=i;
for(int i=0;i<queries.length;i++){
int res =queries[i];
queries[i]=f[res]-1;
for(int j=1;j<=m;j++){
if(f[j]<f[res])f[j]++;
}
f[res]=1;
}
return queries;
}
网友评论