Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想编写一个算法来查找基于 m 的对数。
m 等于 a[i] 在数组中出现的次数(例如,如果数字 3 出现两次,则 m=2)。
如果 m<2 则没有对,如果 m=2 则为 1 对,如果 m=3 则为 3 对,如果 m=4 则为 6 对,依此类推。
这个问题还不是很清楚,但是m个item可以构建出的pairs个数是(m choose 2) = m*(m-1)/2。