Most optimal solution in java
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int minPatches(int[] nums, int n) {\n        int i=0;\n        int count=0;\n        long sum=0;\n        int len=nums.length;\n\n        while(i<len&&sum<n){\n          if(sum+1>=nums[i]){\n             sum+=nums[i];\n             i++;\n          }\n          else{\n             count++;\n             sum+=sum+1;\n             System.out.println(sum);\n          }\n        }\n\n        while(sum<n){\n         sum=sum+sum+1;\n          System.out.println(sum);\n         count++;\n        }\n       return count; \n    }\n}\n```
['Greedy', 'Java']