Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Running Sum of 1d Array Leetcode

class Solution {
    public int[] runningSum(int[] nums) {
    int[] ans = new int[nums.length];
    ans[0] = nums[0];
    for (int i = 1; i < nums.length; i++)
        ans[i] = ans[i-1] + nums[i];
    return ans;
    }
}
Comment

two sum O(n) leetcode

//O(n) hashmaps C++ Two Sum leetcode 
class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        unordered_map<int,int> map;
        for(int i=0; i<=nums.size();i++){
            int compliment=target-nums[i];
            if(map.count(compliment)==1){
                return {map[compliment],i};
            }
            else{
                map[nums[i]]=i;
            }
            
     	}
        return {-1,-1};
        
    }
};
Comment

running sum of 1d array leetcode solution

public int[] RunningSum(int[] nums) 
{
	int sum = 0;
	int[] result= new int[nums.Length];
	for(int i = 0; i < nums.Length; i++)
	{
		sum += nums[i];
		result[i] = sum;
	}

	return result;
}
Comment

PREVIOUS NEXT
Code Example
Java :: build tools java 
Java :: break java 
Java :: convert arraylist to array in java 
Java :: How to initialize a 2d array in Java? 
Java :: java download image file 
Java :: java catch multiple exceptions 
Java :: what does static mean java 
Java :: how to create an action listener in java 
Java :: how to assert that an exception is thrown java 
Java :: string tokenizer java 
Java :: radio button java swing 
Java :: how to check the end of a string java 
Java :: measure running time of a statement java 
Java :: android studio alert dialog box 
Java :: Java Insert Elements to HashSet 
Java :: Difference between Public, Private and Protected modifier in Java? 
Java :: how to remove null values collections 
Java :: for each loop java string array 
Java :: abs in java 
Java :: intent in java 
Java :: Java How to use Set? 
Java :: java array add element 
Java :: java generate uuid 
Java :: glide dependency 
Java :: java formatted output 
Java :: how to reverse a string in java without function 
Java :: java get attributes from class 
Java :: Binary tree using linked list in Java 
Java :: comentario java 
Java :: how to copy array in java 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =