loading...
Cover image for Two sum - Leet Code Solution

Two sum - Leet Code Solution

codeperfectplus profile image CodePerfectPlus Updated on ・1 min read

Two sum - Leet Code Solution

Topic: Two Sum Problem

Problem Statement:

Given an array of integers, return indices of the two numbers such that they add up to a specific target.

You can find the original question here -> Two Sum Problem

Two sum - Leet code solution in Python Language.

class Solution:
    def twoSum(self, nums: List[int], target: int) -> List[int]:
        seen = {}

        for index, num in enumerate(nums):
            other = target - num 

            if other in seen:
                return[seen[other],index]
            else:
                seen[num] = index
        return []

Share Your Solutions?

Posted on by:

codeperfectplus profile

CodePerfectPlus

@codeperfectplus

Skilled in Data Science, Machine Learning, Deep Learning, As Well As Web Development Knowledge. React ❤️ to encourage Author.

Discussion

markdown guide