From 39ce0cf15703d737fce95dd1b091c5f35ce54e37 Mon Sep 17 00:00:00 2001 From: ARADHY MISHRA <111994905+aradhymishra09@users.noreply.github.com> Date: Tue, 15 Oct 2024 18:33:06 +0530 Subject: [PATCH] Create 3Sum Closest 100% memory Efficient Code in C language --- 3Sum Closest | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 3Sum Closest diff --git a/3Sum Closest b/3Sum Closest new file mode 100644 index 0000000..5542a55 --- /dev/null +++ b/3Sum Closest @@ -0,0 +1,32 @@ +int comparator(const void *p1, const void *p2){ + return (*(int*)p1 - *(int*)p2); +} + +int threeSumClosest(int* nums, int numsSize, int target) { + qsort(nums,numsSize,sizeof(int),comparator); + int ans = 0; + int new_diff = INT_MAX; + for(int i=0; i