Why I am getting Time Limit Exceed ?? it is only O(n^2) JAVA solution .. please answer


  • 0
    O
    public class Solution {
    public static List<List<Integer>> result = new ArrayList<List<Integer>>();
    public List<List<Integer>> subsets(int[] nums) {
        Arrays.sort(nums);
        result.add(new ArrayList<Integer>());
        int resultSize=result.size();
        for(int i =0;i<nums.length;i++)
        {
            
            for(int j = 0 ;j<resultSize;j++)
            {
                
        List<Integer>xxx=result.get(j);
        xxx.add(nums[i]);
        result.add(xxx);
            }
            
            resultSize=result.size();
        }
        return result;
    }
    

    }


Log in to reply
 

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