Copy Input: nums = [4,6,7,7]
Output: [[4,6],[4,6,7],[4,6,7,7],[4,7],[4,7,7],[6,7],[6,7,7],[7,7]]
Copy Input: nums = [4,4,3,2,1]
Output: [[4,4]]
Copy func findSubsequences (nums [] int ) [][] int {
ans := make ([][] int , 0 )
cur := [] int {}
var backtracking func ( int )
backtracking = func (index int ) {
if len (cur) > 1 {
copyArr := make ([] int , len (cur))
copy (copyArr,cur)
ans = append (ans, copyArr)
}
m := make ( map [ int ] bool ) //η΄ιθ¦ε ηζ°ηεΌζ―δΈζ―ε·²ηΆθ’«ε ι
for i := index; i < len (nums); i ++ {
if m[nums[i]]{
continue
}
last := - 101
if len (cur) > 0 { last = cur[ len (cur) - 1 ]}
if nums[i] >= last && ! m[nums[i]]{
cur = append (cur,nums[i])
backtracking(i + 1 )
m[cur[ len (cur) - 1 ]] = true
cur = cur[: len (cur) - 1 ]
}
}
}
backtracking( 0 )
return ans
}