Solutions to high-frequency interview questions of LeetCode in C++17, taking into account both efficiency and comprehensibility.
Informally, an algorithm is any well-defined computational procedure that takes some value, or set of values, as input and produces some value, or set of values, as output. An algorithm is thus a sequence of computational steps that transform the input into the output.
O(1)
,代表常数时间复杂度,因为不能指望没有任何代价来运行算法。依次递增的常见复杂度层级还有 O(log log n)
、O(log n)
、O(√n)
、O(n)
、O(n log n)
、O(n ^ 2)
、O(n ^ 3)
、O(2 ^ n)
、O(n!)
等O(1)
,插入或移除元素与到尾后迭代器的距离成线性 O(n)
O(1)
,插入或移除元素时间复杂度 O(n)
O(1)
O(1)
O(log n)
)
O(1)
,最坏情况 O(n)
)