美文网首页
5381. Queries on a Permutation W

5381. Queries on a Permutation W

作者: 7ccc099f4608 | 来源:发表于2020-04-12 23:28 被阅读0次

    https://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/

    image.png

    (图片来源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;
        }

    相关文章

      网友评论

          本文标题:5381. Queries on a Permutation W

          本文链接:https://www.haomeiwen.com/subject/giaimhtx.html