This is a searching problem which can be solved using brute force approach. But here we are going to see use of hash table to solve such searching problems at lower time complexity.
这是一个搜索问题,可以使用蛮力方法解决。 但是在这里,我们将看到使用哈希表以较低的时间复杂度解决此类搜索问题。
Algorithm:
算法:
Hash table is a simple and effective data structure to solve searching problems in O(1) time complexity. Hash tables can be easily built using STL in C++.
哈希表是一种简单有效的数据结构,可以解决O(1)时间复杂度的搜索问题。 哈希表可以使用C ++中的STL轻松构建。
The algorithm to solve the problem:
解决问题的算法:
Create hash table.
创建哈希表 。
Set element pointer to 0. (starting from