一道面试题# JobHunting - 待字闺中
g*r
1 楼
网上看到的。大家有什么思路?
Given an array of positive integer, we need to exchange each element with
first element which is less than it(current element) as we move from left to
right.
Example
{ 3 , 5 , 12, 2 ,11 }
step:
{ _3_ , 5 , 12, 2 ,11 }
{ 2, _5_ , 12, 3, 11 }
{ 2, 3, _12_ , 5, 11 }
{ 2, 3, 5, _12_, 11 }
{ 2, 3, 5, 11 , 12 }
Given an array of positive integer, we need to exchange each element with
first element which is less than it(current element) as we move from left to
right.
Example
{ 3 , 5 , 12, 2 ,11 }
step:
{ _3_ , 5 , 12, 2 ,11 }
{ 2, _5_ , 12, 3, 11 }
{ 2, 3, _12_ , 5, 11 }
{ 2, 3, 5, _12_, 11 }
{ 2, 3, 5, 11 , 12 }