Skip to main content

Posts

Showing posts from May, 2025

Leetcode Practice Reflection 1.Two Sum

LeetCode Practice Reflection - 1. Two Sum Date:   19MAY25 What I Worked on Today: Practiced doing LeetCode Problem 1.Two Sum. What I Learned: - How to use the enumerate() function - How to optimize possible solutions after considering brute force methods - How to declare a new dictionary (key value pair) Code Snippet I Wrote or Studied: class Solution(object): def twoSum(self, nums, target): seen = {} for i, num in enumerate(nums): compliement = target - num if compliment in seen: return [seen[compliment], i] seen[num] = i In My Own Words: This function takes in a list of numbers and will return the index of the two numbers that add up to the provided target value. The way this program works is that it creates a dictionary called "seen". It will then iterate through the list of numbers and use the enumerate function to keep track of the index and the value of the specific item in the provided list. The for loop will calculate the compliment numbe...