[Java] Explained with pictures - Two Pointers solution
\n public String removeDuplicates(String s) {\n        //declare i outside of for loop so we can use it as upper bound for our final result\n        int i = 0;\
```\n public String removeDuplicates(String s) {\n        //declare i outside of for loop so we can use it as upper bound for our final result\n        int i = 0;\n\t\t//conver string to array of characters\n        char[] res = s.toCharArray();\n       \n        for (int j = 0; j < s.length(); ++j, ++i) {\n\t\t    //this line will update array only in case if duplictae is found \n\t\t\t//otherwise i = to j so nothing will change \n            res[i] = res[j];\n\t\t\t//check if previous value euals to current \n            if (i > 0 && res[i - 1] == res[i]) \n\t\t\t   //reset i to the position before duplicate \n                i -= 2;\n        }\n       \n        // string from 0 - to i because rest of the array contains garbage\n       //we moved all non-duplicate values to the begining of arr\n        return new String(res, 0, i);\n    }\n```\n\t\n\t\n![image](https://assets.leetcode.com/users/images/bfc233c8-3654-4cbe-bdb5-7a1dfc854d4a_1640752465.0941455.png)\n\n
['Java']