I am attaching here the link to the TWO SUM problem in leet code: https://leetcode.com/problems/two-sum/
int* twoSum(int* nums, int numsSize, int target, int* returnSize){
*returnSize=2;
int *arr=malloc(sizeof(int)*2);
int i,j;
for(i=0;i<numsSize-1;i++){
for(j=i+1;j<numsSize;j++){
printf("i= %d j=%d,ans=%d\n",nums[i],nums[j],nums[i]+nums[j]);
if(nums[i]+nums[j]==target){
arr[0]=i; arr[1]=j;
}
}
}
return arr;
}
In the if statement
of the above code upon adding the curly braces produces the following outputoutput image
but if i removed the curly braces of if statement
then i get a different output as shown bracket of if statement removed
Aucun commentaire:
Enregistrer un commentaire