Code giving a different output here than on visual studios


  • 0

    for some reason, this code works on visual studios 2013 for the test case

    [1,2,31,33] , 2147483647

    On visual studios it's giving me the correct answer (28) but running it here I am getting 29. Anyone know why?

    int minPatches(vector<int>& nums, int n) {
    
    	long long last = 0;
    	int counter = 0;
    
    	for (int i = 0; i < nums.size() && last < n; i++){
    		if (nums[i] > last + 1){
    			while (last < nums[i]){
    				last += last + 1;
    				counter++;
    			}
    			last += nums[i];
    		}
    		else {
    			last += nums[i];
    		}
    	}
    
    	while (last < n){
    		last += last + 1;
    		counter++;
    	}
    
    	return counter; 
    
    }
    

    '''


  • 0

    I just ran that here with that test case and it got me 28.


  • 0
    This post is deleted!

  • 0

    @StefanPochmann right...but leetcode is giving me 29. Unless you are talking about leetcode?

    If so did the solution pass?


  • 0

    @davidyuan7536 Yes, I was talking about here at leetcode, with "Custom Testcase"+"Run Code". And no, when I do "Submit Solution", it doesn't pass. It fails testcase [1,2,32], 2147483647 by returning 29 instead of 28.


  • 0

    @StefanPochmann oh shit I just noticed it's two different test cases. Sorry thanks!


Log in to reply
 

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