Java || 99.02% fast || Simple & Easy to Understand
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nAssume 1 <= num(page) <
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nAssume $$1 <= num(page) <= 9$$, confirm whether there is enough space for current message to be stored.\n\nIf so, compute the exact $$num(page)$$.\nIf not, assume $$10 <= num(page) <= 99$$ and check again until find the exact $$num(page)$$.\n\n\n\n# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    private int getPages(int l, int limit) {\n        int curLen = limit - 5; // length of "<1/3>" is 5\n        int curCapacity = 9;\n        int extraSpace = 0;\n        while (l > curLen * curCapacity + extraSpace) {\n            curLen -= 2;\n            extraSpace += curCapacity; // "***<5/23>" has extra space than "**<12/23>"\n            curCapacity = Integer.parseInt(curCapacity + "9");\n            if (curLen <= 0) return 0;\n        }\n        int ans = (l - extraSpace) / curLen;\n        if ((l - extraSpace) % curLen != 0) ++ans;\n        return ans;\n    }\n\n    public String[] splitMessage(String message, int limit) {\n        int l = message.length();\n        int pages = getPages(l, limit);\n        String[] ans = new String[pages];\n        int curPos = 0;\n        for (int i=0; i<pages; ++i) {\n            String tag = "<" + (i+1) + "/" + pages + ">";\n            int infoLen = limit - tag.length();\n            ans[i] = message.substring(curPos, Math.min(l, curPos + infoLen)) + tag;\n            curPos += infoLen;\n        }\n        return ans;\n    }\n}\n```
['Java']