I wrote the first leetcode program after a Year and made simple mistakes.

Today, I tried to use my problem-solving muscle and tried solving easy-level problems on leetcode.

At first, this problem looked very easy to me, So I noted down important pieces of information and started to solve the problem on paper. Still, I took many things for granted in my mind during this note-down process and I forgot to take minor details in the code, You can see what I mean by looking at the code and picture of my note shared below.

dsclass Solution {
    public int[] twoSum(int[] nums, int target) {
        // int[] ans = {-1,-1};
        for(int i =0; i<nums.length; i++){
            // ans[0] = i;
            for(int j = i+1;j<(nums.length);j++){
                if(nums[i]+nums[j] == target){
                    return new int[]{i,j};
                }
            }
        }
        return new int[]{};
    }
}

Image of my notes for the problem and solution on paper.

Thank you for reading, follow me if you want to join the journey of learning to solve problems and coding.

1
Subscribe to my newsletter

Read articles from Bhadreshkumar Ghevariya directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Bhadreshkumar Ghevariya
Bhadreshkumar Ghevariya