LeetCode: Search Insert Position

給定一個數值不重複的已排序陣列和目標值,題目要求找出該目標值在這個陣列中的索引位置;若找不到則回傳插入數值的正確排序位置。

Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.

...繼續閱讀 »

LeetCode: Longest Common Prefix

找出陣列裡元素的重複字元,沒有共同重複字元則回傳空字串。

Write a function to find the longest common prefix string amongst an array of strings.

If there is no common prefix, return an empty string "".

 

...繼續閱讀 »

LeetCode: Two Sum

在一組陣列中找出兩個數,其加總恰等於給定值。 每個數不能被重複使用,且必剛好只有一個解。

Given an array of integers, return indices of the two numbers such that they add up to a specific target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.

...繼續閱讀 »