Unusual Speed Difference between Python and C++

后端 未结 17 2222
庸人自扰
庸人自扰 2020-12-22 21:25

I recently wrote a short algorithm to calculate happy numbers in python. The program allows you to pick an upper bound and it will determine all the happy numbers below it.

17条回答
  •  温柔的废话
    2020-12-22 21:38

    Why is everyone using a vector in the c++ version? Lookup time is O(N).

    Even though it's not as efficient as the python set, use std::set. Lookup time is O(log(N)).

提交回复
热议问题