Two Pointer
-
[Algo Rhythm🕺💃] LeetCode 653. Two Sum IV - Input is a BSTAlgo Rhythm🕺💃/LeetCode 2020. 8. 24. 15:24
📚 Problem description Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target. Example 1: Input: 5 / \ 3 6 / \ \ 2 4 7 Target = 9 Output: True Example 2: Input: 5 / \ 3 6 / \ \ 2 4 7 Target = 28 Output: False 🎯 Solution /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNo..
-
[Algo Rhythm🕺💃] LeetCode 167. Two Sum II - Input array is sortedAlgo Rhythm🕺💃/LeetCode 2020. 8. 24. 15:19
📚 Problem description Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Note: Your returned answers (both index1 and index2) are not zero-based. You may assume that each inp..