JAVA------------Easy Version To Understand!!!!!!!!!!!!!!!!!


  • 1
    H
        public int[] twoSum(int[] nums, int target) {
        if(nums==null||nums.length==0)
        	return new int[0];
        HashMap<Integer, Integer> map=new HashMap<Integer,Integer>();
        int len=nums.length;
        int[] result=new int[2];
        for(int i=0;i<len;i++){
        	if(map.get(target-nums[i])!=null){
        		result[0]=map.get(target-nums[i]);
        		result[1]=i+1;
        		return result;
        	}
        	else
        		map.put(nums[i], i+1);      		
        	
        }
    	return new int[0];   
     }

  • 0
    N

    your answer better than me.you are good!


  • 0
    H

    could you vote to me on this quesiton? thank you!


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.