My solution, why does it only rank 6.27%


  • 0
    K

    My code is as below, I am curious about how to improve the performance since the ranking is only 6.27%?

    class Solution {
    public:
    	vector<vector<int>> subsets(vector<int>& nums) {
    		int n = nums.size();
    		vector<vector<int>>result;
    		long long range = 1 << n;
    		for (long long i = 0; i < range; i++)
    		{
    			result.push_back(vector<int>());
    			long long t = i, s=0;
    			while (t)
    			{
    				if (1 & t)result[result.size() - 1].push_back(nums[s]);
    				s++;
    				t >>= 1;
    			}
    		}		
    		return result;
    	}
    };
    

Log in to reply
 

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