← 返回 microsoft 的题目列表Find Two Smallest Elements in an Array
类型:online_judge
Given an integer array, find the two smallest elements in it. The optimized algorithm should run in O(n) time. Assume that the array contains at least two elements. Implement the function two_smallest(arr) and return the values of these two elements. For example, the input [5, 3, 8, 1, 2] should return (1, 2).
Example
Input
[5, 3, 8, 1, 2]