Using Two pointers, python solution


  • 0
    V
    
    def combinationSum4(self, nums, target):
            temp = nums[:]
            temp.sort()
            i = 0
            j = len(temp) - 1
            sum = 0
            while i < j:
                sum = temp[i] + temp[j]
                if sum > target:
                    j -= 1
                elif sum < target:
                    i += 1
                else:
                    if temp[i] == temp[j]:
                        index = nums.index(temp[i])
                        index += 1
                        return(nums.index(temp[i]), nums[index:].index(temp[j]) + index)
                    return (nums.index(temp[i]), nums.index(temp[j]))
    
    
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.