class Solution {
    public List<String> removeComments(String[] source) {
        List<String> res = new LinkedList<>();
        StringBuilder sb = new StringBuilder();
        
        boolean commentBlock = false;
        int i;
        for (String s : source) {
            i = 0;
            if (!commentBlock) sb = new StringBuilder();
            while (i < s.length()) {
                if (commentBlock) {
                    while (i < s.length()) {
                        if (i+ 1 < s.length() && s.charAt(i) == '*' && s.charAt(i + 1) == '/') {
                            i += 2;
                            commentBlock = false;
                            break;
                        } else {
                            i++;
                        }
                    }
                } else {
                    while (i < s.length()) {
                        if (i + 1 < s.length() && s.charAt(i) == '/' && s.charAt(i + 1) == '*') {
                            i += 2;
                            commentBlock = true;
                            break;
                        } else if (i + 1 < s.length() && s.charAt(i) == '/' && s.charAt(i + 1) == '/') {
                            i = s.length();
                            break;
                        } else {
                            sb.append(s.charAt(i++));
                        }
                    }
                    
                }
            }
            if (!commentBlock && sb.length() > 0) res.add(sb.toString());
        }
        return res;
    }
}