Easy Explanation in Java - Solve two mathematical equations with two variables
IntuitionIts a simple Mathematic equation:-
4x+2y=tomatoSlices
x+y=cheeseSlices
y=(4*(cheeseSlices)-tomatoSlices)/2
x=cheeseSlices-y
If x<0 or y<0 or (4*(cheese
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIts a simple Mathematic equation:-\n4x+2y=tomatoSlices\nx+y=cheeseSlices\ny=(4*(cheeseSlices)-tomatoSlices)/2\nx=cheeseSlices-y\nIf x<0 or y<0 or (4*(cheeseSlices)-tomatoSlices)%2==1,we return empty list as we couldnt find a positive integer values for x and y.Also,if the above expression (4*(cheeseSlices)-tomatoSlices) is not divisible by 2,it indicates that y is not an integer value and hence it no solution exists as we cant have negative burgers or decimal values for burgers.\n\nPlease do upvote and comment if you have understood my explanation.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe approach follows the intuition mentioned above.\n\n# Complexity\n- Time complexity:\n- O(1).\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n- O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public List<Integer> numOfBurgers(int tomatoSlices, int cheeseSlices) {\n       int sm=0;\n       int jum=0;\n       List<Integer> list=new ArrayList<>();\n       if(((4*cheeseSlices)-(tomatoSlices))<0)return list;\n       else{\n       if(((4*cheeseSlices)-(tomatoSlices))%2==1)\n       return list;\n       sm=((4*cheeseSlices)-(tomatoSlices))/2;\n       }\n       jum=cheeseSlices-sm;\n       if(jum<0)return list;\n       list.add(jum);\n       list.add(sm);\n       return list;\n    }\n}\n```
['Java']