c# solution


  • 0
    N
    public class Solution {
        IList<IList<int>> list = new List<IList<int>>();
        public IList<IList<int>> FindSubsequences(int[] nums) {
            var set = new HashSet<string>();
            dfs(nums, 0, new List<int>(), set);
            
            foreach(var s in set){
                var arr = s.Split(",".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);
                var ll = new List<int>();
                foreach(var e in arr ){
                    ll.Add(int.Parse(e));
                }
                list.Add(ll);
            }
            return list;
        }
        
        public void dfs(int[] nums, int start, IList<int> path, HashSet<string> set){
            
            if(path.Count >1){
                set.Add(string.Join(",", path));
            }
            
            for(var i=start;i<nums.Length;i++){
                if(path.Count==0 || path[path.Count-1] <= nums[i]){ 
                    path.Add(nums[i]);
                    dfs(nums, i +1, path, set);
                    path.RemoveAt(path.Count-1);
                }
            }
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.