package leetcode;

/**
 * https://leetcode.com/problems/masking-personal-information/
 */
public class Problem831 {
    public String maskPII(String S) {
        if (isEmail(S)) {
            return maskEmail(S);
        }
        return maskPhone(S);
    }

    private static boolean isEmail(String s) {
        return s.contains("@");
    }

    private static String maskEmail(String s) {
        StringBuilder sb = new StringBuilder();
        int idx = s.indexOf("@");
        sb.append(s.charAt(0));
        for (int i = 0; i < 4; i++) {
            sb.append("*");
        }
        sb.append(s.substring(idx - 1));
        return sb.toString();
    }

    private static String maskPhone(String s) {
        return "";
    }

    public static void main(String[] args) {
        Problem831 prob = new Problem831();
        System.out.println(prob.maskPII("LeetCode@LeetCode.com")); // l*****e@leetcode.com
        System.out.println(prob.maskPII("AB@qq.com")); // a*****b@qq.com
//        System.out.println(prob.maskPII("1(234)567-890")); // ***-***-7890
//        System.out.println(prob.maskPII("86-(10)12345678")); // +**-***-***-5678
//        System.out.println(prob.maskPII("1-(10)12345678")); // +*-***-***-5678
    }
}

@@ -378,32 +378,61 @@
 ail(String s) %7B%0A
+        s = s.toLowerCase();%0A
         StringBu
@@ -459,24 +459,24 @@
 gBuilder();%0A
-
         int 
@@ -557,17 +557,17 @@
  0; i %3C 
-4
+5
 ; i++) %7B
@@ -743,519 +743,431 @@
     
-return
+s = s.replaceAll(%22%5C%5C(%7C%5C%5C)%7C-%7C%5C%5C+%7C %22,
  %22%22
+)
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem831 prob = new Problem831();%0A        System.out.println(prob.maskPII(%22LeetCode@LeetCode.com%22)); // l*****e@leetcode.com%0A        System.out.println(prob.maskPII(%22AB@qq.com%22)); // a*****b@qq.com%0A//        System.out.println(prob.maskPII(%221(234)567-890%22)); // ***-***-7890%0A//        System.out.println(prob.maskPII(%2286-(10)12345678%22)); // +**-***-***-5678%0A//        System.out.println(prob.maskPII(%221-(10)12345678%22)); // +*-***-***-5678
+StringBuilder sb = new StringBuilder();%0A        int countryCode = s.length() - 10;%0A        if (s.length() %3E 10) %7B%0A            sb.append(%22+%22);%0A            for (int i = 0; i %3C countryCode; i++) %7B%0A                sb.append(%22*%22);%0A            %7D%0A            sb.append(%22-%22);%0A        %7D%0A        sb.append(%22***-***-%22).append(s.substring(s.length() - 4));%0A        return sb.toString();
 %0A   

Solve problem 831