Easy-to-Understand Binary Search Approach in Java
Code\njava []\nclass Solution {\n    public String[] splitMessage(String message, int limit) {\n        int digit = 1;\n\n        while (true) {\n            in
# Code\n```java []\nclass Solution {\n    public String[] splitMessage(String message, int limit) {\n        int digit = 1;\n\n        while (true) {\n            int left = (int) Math.pow(10, digit - 1);\n            int right = (int) Math.pow(10, digit) - 1;\n\n            if (left > message.length()) {\n                break;\n            }\n\n            while (left + 1 < right) {\n                int mid = left + (right - left) / 2;\n                if (canSplit(mid, message, limit) <= 0) {\n                    right = mid;\n                } else {\n                    left = mid;\n                }\n            }\n\n            if (canSplit(left, message, limit) == 0) {\n                return split(left, message, limit);\n            }\n\n            if (canSplit(right, message, limit) == 0) {\n                return split(right, message, limit);\n            }\n\n            ++digit;\n        }\n\n        return new String[0];\n    }\n\n    private String[] split(int n, String message, int limit) {\n        String[] substrs = new String[n];\n        int start = 0;\n        int lenN = len(n);\n\n        for (int i = 1; i <= n; ++i) {\n            StringBuilder sb = new StringBuilder();\n\n            int suffix = 3 + len(i) + lenN;\n            int last = limit - suffix;\n            int end = Math.min(message.length(), start + last);\n            sb.append(message.substring(start, end));\n\n            sb.append("<");\n            sb.append(i);\n            sb.append("/");\n            sb.append(n);\n            sb.append(">");\n\n            substrs[i - 1] = sb.toString();\n            start += last;\n        }\n\n        return substrs;\n    }\n\n    private int canSplit(int n, String message, int limit) {\n        if (n > message.length()) {\n            return -1;\n        }\n\n        int lenN = len(n);\n        int total = message.length();\n\n        for (int i = 1; i <= n; ++i) {\n            if (total <= 0) {\n                return -1;\n            }\n\n            // <i/n>\n            int suffix = 3 + len(i) + lenN;\n            int last = limit - suffix;\n            total -= last;\n        }\n\n        return total > 0 ? 1 : 0;\n    }\n\n    private int len(int n) {\n        int l = 0;\n        while (n > 0) {\n            n = n / 10;\n            ++l;\n        }\n        return l;\n    }\n}\n```
['Binary Search', 'Java']