Код не работает для отрицательных тестовых случаев поиска пары продуктов [закрыто]C++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Код не работает для отрицательных тестовых случаев поиска пары продуктов [закрыто]

Сообщение 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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»