Java | BFS | 15 lines | Clean code
Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) \n\n# Co
# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n  public int maxLevelSum(TreeNode root) {\n    int max = Integer.MIN_VALUE, ans = 0;\n    var queue = new ArrayDeque<TreeNode>();\n    queue.offer(root);\n\n    for (var level = 1; !queue.isEmpty(); level++) {\n      var sum = 0;\n\n      for (var i = queue.size(); i > 0; i--) {\n        var node = queue.poll();\n\n        sum += node.val;\n        if (node.left != null) queue.offer(node.left);\n        if (node.right != null) queue.offer(node.right);\n      }\n      if (sum > max) {\n        max = sum;\n        ans = level;\n      }\n    }\n    return ans;\n  }\n}\n```\nIf you like my solution, please upvote it!
['Breadth-First Search', 'Binary Tree', 'Java']