Загрузка...

Lettcode 611 | Valid Triangle Number | Daily Leetcode | POTD

Just trying to solve this question using bruteforce and then after tle trying to do some optimization to get the question submitted.
#leetcode #coding #c++
#potd We will sort the given points to remove some redundancy.

We sequentially check using three pointers by passing them into a check_triangle function, and if the function returns true, we increase the counter. If it returns false, then we break the innermost k loop, as going forward makes no sense since the array is sorted. This removes some redundancy.

The check_triangle function uses the fact that the sum of two sides of a triangle is greater than the third side to check whether the given three sides form a triangle or not.

As the array is sorted, we just need to check one combination of the given three parameters in the check_triangle function, that is, whether the first + second is greater than third.

Видео Lettcode 611 | Valid Triangle Number | Daily Leetcode | POTD канала DSA - Just Intuition
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять