LeetCodeDirectory [source code]

```java import java.io.*;

public class LeetCodeDirectory { static final String CSV_FILE = "../leetcode-questions.csv";

public static void main (String[] args) {
    Scanner scan = null;
    try {
        scan = new Scanner (new File (CSV_FILE));
    } catch (Exception ex) {
        System.out.printf ("err reading in file %s\n", CSV_FILE);
        System.exit (1);
    }
    System.out.printf ("success: read in file %s\n", CSV_FILE);
    Map<String, Integer> res = new HashMap<> ();
    while (scan.hasNextLine ()) {
        String line = scan.nextLine ();
        String[] tokens = line.split (",");
        Integer number = -1;
        try {
            number = Integer.parseInt (tokens[0]);
        } catch (Exception ex) {
            continue;
        }
        String name = tokens[1].replaceAll ("[^0-9a-zA-Z]", "").toLowerCase ();            
        String difficulty = tokens[tokens.length - 1].replaceAll ("[^0-9a-zA-Z]", "").toLowerCase ();
        if (number == 717)
            name = "bit1andbit2characters";
        res.put (name, number);
    }

    System.out.println (res.size ());
    List<Integer> ls = new ArrayList<> ();
    for (Integer v : res.values ())
        ls.add (v);
    Collections.sort (ls);
    System.out.println (ls);

    try (ObjectOutputStream oos = new ObjectOutputStream (new FileOutputStream ("../questions.ser"))) {
        oos.writeObject (res);
    } catch (Exception ex) {
        ex.printStackTrace ();
    }
}

}

results matching ""

    No results matching ""