Very Easy Approach using Stacks | Greedy Approach | Faster than 20%
Intuition\n Describe your first thoughts on how to solve this problem. \n- At first I thought to arrange an array at every loop. But that approach was too costl
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- At first I thought to arrange an array at every loop. But that approach was too costly and caused me TLE.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- Then I thought of the stack approach.\n- Here I am checking that if the stack size is odd which means that the index is even.\n- I am checking for every element when the stack size is odd that the element is equal to the peek element or not.\n- When the element is equal to tht top element I am increasing my count and continuing my loop.\n- At last if the size of the stack is odd which means we have to delete one more element.\n- If not then we can simply return the count.\n\n# Complexity\n- Time complexity: $$O(N)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(N)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int minDeletion(int[] nums) {\n        //Arrays.sort(nums);\n\n        Stack<Integer> st = new Stack<>();\n        int count = 0;\n        for(int i=0 ; i<nums.length ; i++){\n            if(st.size()%2==1 && st.peek()==nums[i]){\n                count++;\n                continue;\n            }\n            else st.push(nums[i]);\n        }\n\n        if(st.size()%2==1)return count+1;\n\n        return count;\n     }\n}\n```
['Stack', 'Greedy', 'Java']