摘要:如对[1,2,3],将得到[123,132,213,231,312,321]
结果数字不重复。
思路:
x([1,2,3]) ->
y(1,x([2,3])) + y(2,x([1,3])) + y(3,x([1,2]))
y(1,x[2,3]) ->
[12,13]
代码:
arr = [1,2,3]
def y(num,arr)
arr.collect{|it| num.to_s + it.to_s }
end
def x(arr)
return arr.dup if arr.size==1
result = []
arr.each_index do |i|
arr1 = arr.dup
(全文共782字)——点击此处阅读全文