BEATS 75% in java
Bold# Intuition\nArrange all denominators with their final numerator using hashmap.\n\n# Approach\nJust solve using the simple lcm for all denominators. Find th
**Bold**# Intuition\nArrange all denominators with their final numerator using hashmap.\n\n# Approach\nJust solve using the simple lcm for all denominators. Find the hcf for numerator and denominator and divide both with the hcf.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public String fractionAddition(String e) {\n        int n=0;int s=1;boolean n1=true;int d=0;\n        HashMap<Integer,Integer> de=new HashMap<>();\n        for(int i=0;i<e.length();i++)\n        {\n            if(e.charAt(i)==\'-\')\n            {\n                s=-1;\n                if(d!=0)\n                {\n                    de.put(d,de.getOrDefault(d,0)+n);\n                }\n                d=0;\n                n=0;\n                n1=true;\n                continue;\n            }\n            if(e.charAt(i)==\'+\')\n            {\n                s=1;\n                if(d!=0)\n                {\n                    de.put(d,de.getOrDefault(d,0)+n);\n                }\n                d=0;\n                n1=true;\n                n=0;\n                continue;\n            }\n            if(n1)\n            {\n                if(e.charAt(i)==\'/\')\n                {\n                    n=n*s;\n                    n1=false;\n                    continue;\n                }\n                if((int)e.charAt(i)<=57  && (int)e.charAt(i)>=48)\n                {\n                    n=n*10;\n                    n+=((int)e.charAt(i)-48);\n                    continue;\n                }\n            }\n            else\n            {\n                if((int)e.charAt(i)<=57  && (int)e.charAt(i)>=48)\n                {\n                    d=d*10;\n                    d+=((int)e.charAt(i)-48);\n                    continue;\n                }\n            }\n        }\n        de.put(d,de.getOrDefault(d,0)+n);\n        n=0;d=1;\n        n1=true;\n        for(int i:de.keySet())\n        {\n            n=((n*i)+(de.get(i)*d));\n            d*=i;\n        }\n        if(n==0)\n        {\n            return "0/1";\n        }\n        if(n<0)\n        {\n            n=n*(-1);\n            n1=false;\n        }\n        s=hcf(n,d);\n        if(n1)\n        {\n            return n/s+"/"+d/s+"";\n        }\n        return "-"+n/s+"/"+d/s+"";\n    }\n    public static int hcf(int a, int b) {\n        while (b != 0) {\n            int temp = b;\n            b = a % b;\n            a = temp;\n        }\n        return a;\n    }\n}\n```
['Java']