Answers for "two number sum solution"

C
3

how to find sum of two nums

#include<stdio.h>
int main() {
int a, b, sum;
printf("\nEnter two no: ");
scanf("%d %d", &a, &b);
sum = a + b;
printf("Sum : %d", sum);
return(0);
Posted by: Guest on December-22-2020
0

two sum problem

vector<int> twoSum(vector<int>& nums, int target) {
    int front = 0, rear = nums.size() - 1;
    sort(nums.begin(), nums.end());
    while(front < rear) {
      int sum = nums[front] + nums[rear];
      if (sum == target)
       break;
      else if (sum > target)
       rear--;
      else
       front++;
    }
    return {front, rear};
};
Posted by: Guest on March-04-2022

Code answers related to "C"

Browse Popular Code Answers by Language