• 排列序号


    代码:

    public class Solution { 

            /**

             * @param A an integer array

             * @return a long integer

             */ 

            public long permutationIndex(int[] A) { 

                // Write your code here 

                long R=0; 

                int low[] = new int[A.length]; 

                long weight[] = new long[A.length]; 

                for(int i=A.length-1;i>=0;--i){ 

                    for(int j=i+1;j<A.length;++j) 

                        if(A[j]<A[i]) 

                            ++low[i]; 

                    weight[i] = (i>=A.length-2)?(A.length-1-i):weight[i+1]*(A.length-i-1); 

                     

                    R += weight[i]*low[i]; 

                } 

                return R+1; 

            } 

        }  

    lintcode截图:

  • 相关阅读:
    实验报告2
    实验三 网络欺骗技术
    实验3
    心理魔术
    实验报告
    实验4
    实验5
    实验四恶意代码
    网络对抗技术 实验一
    实验二
  • 原文地址:https://www.cnblogs.com/aly15109725486/p/7235725.html
Copyright © 2020-2023  润新知