Java Why is it time limit exceeded for my answer?

  • -1

    public class Solution {
    public List<Integer> lexicalOrder(int n) {
    TreeSet<String> ts = new TreeSet<String>();
    for (int i = 1; i <= n; i++) {
    List<Integer> al = new ArrayList<Integer>();
    for (String str : ts) {

    return al;

    I am not sure about the time it takes. Anyone helps to explain? Thank you.

  • 0

    Seems your algorithm will take O(n log n) for Time. Try to solve this in O(n). TreeSet sort algorithm takes

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.