Leetcode 1: Two Sum in Solidity

Subscribers:
1,210
Published on ● Video Link: https://www.youtube.com/watch?v=xAcrcfpSDEw



Duration: 0:12
152 views
0


Challenge: solve using O(n) time complexity.
You need to use a mapping in Solidity to this.
However, you need to pad the array in the first slot to overcome the fact that mappings do not have starting value null, but 0. This filters the nums[0] edge case.

Solidity: https://github.com/MarcusWentz/LeetcodeAlgorithms/blob/main/Solidity/TwoSum/contracts/TwoSum.sol

Hardhat: https://github.com/MarcusWentz/LeetcodeAlgorithms/blob/main/Solidity/TwoSum/contracts/TwoSum.so: