Код не работает для отрицательных тестовых случаев поиска пары продуктов [закрыто] ⇐ C++
-
Anonymous
Код не работает для отрицательных тестовых случаев поиска пары продуктов [закрыто]
Product pair- link to the question
initially i hadn't added the abs stuff but after i did, the code was able to handle some of the negative test-cases but not all of them
i have an idea as to why this might be still showing errors even after adding the abs part but i cannot exactly pin-point it let alone know how to rectify the issue so i need help with that.
ps: i'm posting for the first time ever on stackoverflow so if the format or something is not okay, i'm really really sorry
class Solution{ public: bool isProduct(int arr[], int n, long long x) { for (int i = 0; i < n; i++) { arr = abs(arr); } x=abs(x); sort(arr, arr + n); int start = 0, end = n - 1; while (start < end) { if (arr[start] * arr[end] == x) { return true; } else if (arr[start] * arr[end] < x) { start++; } else { end--; } } return false; } };
Источник: https://stackoverflow.com/questions/780 ... oduct-pair
Product pair- link to the question
initially i hadn't added the abs stuff but after i did, the code was able to handle some of the negative test-cases but not all of them
i have an idea as to why this might be still showing errors even after adding the abs part but i cannot exactly pin-point it let alone know how to rectify the issue so i need help with that.
ps: i'm posting for the first time ever on stackoverflow so if the format or something is not okay, i'm really really sorry
class Solution{ public: bool isProduct(int arr[], int n, long long x) { for (int i = 0; i < n; i++) { arr = abs(arr); } x=abs(x); sort(arr, arr + n); int start = 0, end = n - 1; while (start < end) { if (arr[start] * arr[end] == x) { return true; } else if (arr[start] * arr[end] < x) { start++; } else { end--; } } return false; } };
Источник: https://stackoverflow.com/questions/780 ... oduct-pair
Мобильная версия