LeetCode #1 – Two Sum

This is my submission for LeetCode Two Sum Problem:

public class Solution {
   public int[] twoSum(int[] nums, int target) {
      int i;
      int j;
      for(i = 0; i <= nums.length; i++){
         for(j = i+1; j <= nums.length; j++){
            if(nums[i]+nums[j] == target){
               int[] data = {i,j};
               return data;
            }
         }
      }
      return null;
}
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s