Easy Solution Of  JAVA 🔥C++🔥Beginner Friendly 🔥ArrayList
\n\n# Code\nPLEASE UPVOTE IF YOU LIKE.\n\nclass Solution {\n   public int lastStoneWeight(int[] stones)\n{\n\t\tArrayList<Integer> listStones = new ArrayList<>(
\n\n# Code\nPLEASE UPVOTE IF YOU LIKE.\n```\nclass Solution {\n   public int lastStoneWeight(int[] stones)\n{\n\t\tArrayList<Integer> listStones = new ArrayList<>();\n\t\tfor (int a : stones)\n\t\t\tlistStones.add(a);\n\n\t\twhile (true)\n\t\t{\n\t\t\tint min = Integer.MAX_VALUE;\n\t\t\tint max = Integer.MIN_VALUE;\n\t\t\tint len = listStones.size();\n\n\t\t\tif (len == 1 || len == 0)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tCollections.sort(listStones);\n\t\t\tmin = listStones.get(len - 2);\n\t\t\tmax = listStones.get(len - 1);\n\n\t\t\tif (min < max)\n\t\t\t{\n\t\t\t\tmax = max - min;\n\t\t\t\tlistStones.remove(listStones.size()-1);\n\t\t\t\tlistStones.remove(listStones.size()-1);\n\t\t\t\tlistStones.add(max);\n\n\t\t\t}\n\t\t\telse if (min == max)\n\t\t\t{\n\t\t\t\tlistStones.remove(listStones.size()-1);\n\t\t\t\tlistStones.remove(listStones.size()-1);\n\t\t\t}\n\t\t}\n\t\t\n        if(listStones.size()==1)\n            return listStones.get(0);\n        return 0;\n\t}\n}\n```\nC++\n```\n    int lastStoneWeight(vector<int>& s) {\n        int n = s.size();\n        if(n == 1) return s[0];\n        sort(s.begin(), s.end());\n        int i = n-1;\n        while(i >= 1){\n            if(s[i-1] == s[i])\n                i = i - 2;\n            else{\n                s[i-1] = s[i] - s[i-1];\n                i = i -1;\n                int j = i;\n                while( j > 0 and s[j-1] > s[j] ){\n                    swap( s[j-1] , s[j] );\n                    j--;\n                }\n            }\n        }\n        if( i == 0 )\n            return s[i];\n        else \n            return 0;\n    }\n\n```
['Array', 'C++', 'Java']