315. Count of Smaller Numbers After Self

Description

Here

Intuition

首先,设有一个v1,v2相邻,然后原序列每次取第一个放最后,到v1, v2变成第一个跟第二个的时候,先取v2放后面,再取v1放后面,继续刚才操作,等原序列的第一位回到第一的位置,交换完毕

上述过程就是bubble sort的swap过程

那么k > 1 的时候,就是直接sort;k = 1时,substring计算

Pitfall

Solution

Solution

results matching ""

    No results matching ""