Beats 100.00%%🔥✅|| easy JAVA Solution✅
Intuition\n#### we need to find the Longest Substring with the same characters.\n\n\n# Approach\n\n\nWe can iterate over the given string, and use a variable te
# Intuition\n#### we need to find the Longest Substring with the same characters.\n![1.png](https://assets.leetcode.com/users/images/f7bb134e-8d98-4ceb-827f-d1f854def467_1713363327.0031047.png)\n\n# Approach\n\n\nWe can iterate over the given string, and use a variable tempLength to record the length of that substring.\n\nWhen the next character is the same as the previous one, we increase tempLength by one. Else, we reset tempLength to 1.\nand check if tempLength is greater than maxLength or not\n\nWith this method, when reaching the end of a substring with the same characters, tempLength will be the length of that substring, since we reset the tempLength when that substring starts, and increase tempLength when iterate that substring.\n\nTherefore, the maximum value of tempLength is what we need.\n# Complexity\n- Time complexity:\n O(N), since we perform one loop through `s`\n- Space complexity:\nO(1), since we only have two integer variables `maxLength` and `tempLength` \n\n### Finally : If you like the method of solution and explanation, do not hesitate to vote up to encourage me to solve more problems and solve them in better ways.\n# Code\n```\nclass Solution {\n    public int maxPower(String s) {\n        int maxLength = 1;\n        int tempLength = 1;\n        for (int i = 1; i < s.length(); i++) {\n            if (s.charAt(i) == s.charAt(i - 1)) {\n                tempLength++;\n            } else {\n                if (tempLength > maxLength) {\n                    maxLength = tempLength;\n                }\n                tempLength = 1;\n            }\n        }\n        if(tempLength>maxLength){\n            maxLength=tempLength;\n        }\n        return maxLength;\n    }\n}\n```\n![upvote.png](https://assets.leetcode.com/users/images/eaea3c38-1f6a-4895-937a-bdc6eadc01b7_1713363831.5273302.png)\n
['Java']