Very Easy Solution: 2 steps foward 1 step backward, with explanation on thinking process
\npublic int minDeletion(int[] nums) {\n\tint c = 0;\n\tint i = 1;\n\n\twhile (i < nums.length) {\n\t\tif (nums[i-1] == nums[i]) {\n\t\t\tc++;\n\t\t\ti--;  // "
```\npublic int minDeletion(int[] nums) {\n\tint c = 0;\n\tint i = 1;\n\n\twhile (i < nums.length) {\n\t\tif (nums[i-1] == nums[i]) {\n\t\t\tc++;\n\t\t\ti--;  // "deleted" one element, to keep the check in pairs\n\t\t}\n\t\ti += 2;\n\t}\n\n\treturn (nums.length - c) % 2 == 0 ? c : c+1;\n}\n```\n===========================\nThinking process:\n\nMy first wrong draft was very straightforward:\n```\n    public int minDeletion(int[] nums) {\n        int c = 0;\n        for (int i = 1; i < nums.length; i++) {\n            if (nums[i-1] == nums[i])\n                c++;\n        }\n        \n        return (nums.length + c) % 2 == 0 ? c : c+1;\n    }\n```\nI failed the case [1,1,2,2,3,3]. Expected answer is 2 but this code got 4.\nWhen `i = 1`, one of the 1 got deleted and it shifted rest of the elements forward, which become [1,2,2,3,3]. \nThe next optimal action is to remove one of the 3 at the end, which produces a "beautiful" [1,2,2,3].\nHowever [1,2,2,3] will still got delete by the my first draft code(the 2,2 case). At this point I realized I need to do comparison by pairs.
['Java']