Table of Contents 0:00 Problem Statement 0:40 Solution 3:05 Pseudo Code 4:20 Code - Python 5:04 Code - C++
@mathematics339820 күн бұрын
class Solution: def findTriplet(self, arr): arr.sort() i = len(arr) - 1; while i >= 0: j = 0 k = i - 1; while j < k: if arr[j] + arr[k] == arr[i]: return True if arr[j] + arr[k] < arr[i]: j += 1 else: k -= 1 i -= 1 return False
@mathematics339820 күн бұрын
class Solution { public: bool findTriplet(vector& arr) { sort(arr.begin(), arr.end()); for (int i = arr.size() - 1; i >= 0; i--) { int j = 0, k = i - 1; while (j < k) { if (arr[j] + arr[k] == arr[i]) return true; if (arr[j] + arr[k] < arr[i]) j++; else k--; } } return false; } };