← 返回 meta 的题目列表Find Index of Target Weight in Array
类型:online_judge
meta
Given an array of weights and a target weight, write a function to find its index.
Input
An integer array weights representing the weights of various elements.
An integer target indicating the target weight.
Output
Return the index of the target weight in the weight array, or -1 if it does not exist.
Example
weights = [10, 20, 30, 40]
target = 30
Output
2
Example
Input
10 20 30 40
30