No one has replied
I just ran your code and found that the runtime is 220ms, were the test cases changed?
I had the same problem, just use preorder traverse and get the same error.
This problem wants to a method to invert the binary tree, not all of process including input, output.
your code could be cleaner
I try four times, two is 0ms, the other is 4ms.