Why long data type makes a difference
I tried write my own version of the code after understanding this fancy algorithm, however, i find that declare the variable with 'long' instead of 'int' really
I tried write my own version of the code after understanding this fancy algorithm, however, i find that declare the variable with 'long' instead of 'int' really make a difference:\n\n    class Solution {\n    public:\n        int minPatches(vector<int>& nums, int n) {\n            int miss_least = 1, i=0, cnt= 0;\n            int M=nums.size();\n    \n            while(miss_least <= n){\n                if (i<M  && nums[i] <= miss_least){\n                    miss_least += nums[i++];\n                }\n                else{\n                    miss_least+=miss_least;    // [1, miss_least +miss_least) to maximize the boundary\n                    cnt++;\n                }\n            }\n            \n            return cnt;\n    \n        }\n    };\n\nHere, I declare the miss_least as an integer, the online judge  just got TLE, when I change it to 'long',  the code get Accepted. Anyone knows the reason?
[]