Question: SOLVE IN JAVA Create a method: Public Static int twoSumCount(int[] intArray, int targetInt). Given a non-empty array, when there are two numbers adds up equal

SOLVE IN JAVA

Create a method: Public Static int twoSumCount(int[] intArray, int targetInt).

Given a non-empty array, when there are two numbers adds up equal to the targetInt, you should consider one pair of qualified twoSum is found. Write a code to count total how many combination of twoSums you can find in the array.

HINT: twoSum is a classic algorithm, where you need to use nested for-loop to solve. The outer for-loop pick up intArray[i], and the inner for-loop pick up intArray[j], then sum them to see if they match your targetInt. The key is, i and j cannot be same index.

To count all twoSumCount combinations, you need iterate all combinations of two numbers.

twoSumCount([1,13,1,2,1],15)1 twoSumCount([2,1,1,2,1],100)0 twoSumCount ([1, 2, 1, 4, 7, 2, 0, 3], 3) 4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!