题目:把一个数分解成任意几个数之和,把一个数的所有和式分解的结果全部输出出来,
例如:4的结果有,(1+3),(2+2),(1+1+2),(1+1+1+1)
由例子可见,该程序是去重的,应为1+1+2也可以写成1+2+1 ,所以,写方法必须要去重
package org.jeecg.modules.applet.controller;
import java.util.*;
/**
* 把一个数分解成任意几个数之和,把一个数的所有和式分解的结果全部输出出来
* 例如:4的结果有,(1+3),(2+2),(1+1+2),(1+1+1+1)
*/
public class Composition extends ArrayList<Integer> {
/**
* 重写equals方法方便去重,排除掉重复的数据
* @param other
* @return
*/
@Override
public boolean equals(Object other){
Composition comp = (Composition)other;
Collections.sort(this);
Collections.sort(comp);
if(this.isEmpty() || comp.isEmpty() || this.size() != comp.size())
return false;
for(int i=0; i<this.size(); i++)