1.two-sum
題目
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
翻譯
給一個整數陣列跟整數 target,請找出陣列中哪兩個元素相加會等於 target 且為唯一組合,並返回該組合各自的 index。
Example:
思路
一、極限值/特殊狀況
負數情況
target 為 0 的情況
二、哪種資料結構解
counter + hash table
三、大概會怎麼解
用 counter 記錄尚未匹配的值與 index
匹配則返回
型別
解題
Last updated