My code is running fine with all the test cases. But when I submit it's giving run time error.


  • 0
    W
    class Solution {
        public:
        vector<int> findDuplicates(vector<int>& nums) {
            vector <int> result;
            int i = 0;
            for(i; i< nums.size();i++){
                if (nums[abs(nums[i])] >=0){
                    nums[abs(nums[i])] = -nums[abs(nums[i])];
                    
                }
                else{
                    result.emplace_back(abs(nums[i]));
                }
                
            }
            return result;
        }
    };

Log in to reply
 

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