分治法取最大值的实现
str = [2,3,1,5,8,4,0,7,9,2,3,1,5,8,4,0,7,9,2,3,1,5,8,4,0,7,9,2,3,1,5,8,4,0,7,9,2,3,1,5,8,4,0,7,9] def test1 arr len = arr.length (len%2==0)?(l = len/2):(l = (len+1)/2) ar = [] for i in 0..l-1 if arr[i*2+1]!=nil and arr[i*2]<arr[i*2+1] ar<<arr[i*2+1] else ar<<arr[i*2] end end if ar.length!=1 test1 ar else p ar end end
点亮测试人生!QQ:408129370
百度阅读电子书地址:http://yuedu.baidu.com/ebook/f6dbb2a2f01dc281e53af0f3
讨论QQ群:536192476
个人公众号:
百度阅读电子书地址:http://yuedu.baidu.com/ebook/f6dbb2a2f01dc281e53af0f3
讨论QQ群:536192476
个人公众号: