[英]Counting the pairs in a list such that their first index is less than the second but the first element is greater than the second
[英]Optimal code to find the number of pairs with greater than condition in list based on index?
假設 A = [5,2,1,3],表示對數 (i,j)。 1<=i < j<=n 使得 A[i]>A[j]。 下面是相同的未優化代碼
def I(A):
output = i = j = 0
while i< len(A):
j = i+1
while j<len(A):
if A[i]>A[j]:
output +=1
j+=1
i+=1
return output
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.