Bug in the testing code


  • 1
    J

    I ran into a strange error trying to submit this code. The input is "", my output is [] and the expected output is"". I didn't really understand how this can even be an issue with my code since we don't even return anything. Ultimately I tested it with a few solutions that are listed in the discussion and those also produce the same error. Is anyone else having this issue?

    My code, in case there's any concern:

    public class Solution {
        public void reverseWords(char[] s) {
            if (s.length < 2) {
                return;
            }
            flip(s, 0, s.length - 1);
            
            int start = 0;
            int end = -1;
            while (start < s.length) {
                while (isWhiteSpace(s[start])) {
                    ++start;
                }
                end = start + 1;
                
                while (end < s.length && !isWhiteSpace(s[end])) {
                    ++end;
                }
                // end is on a space or is the length of the array
                flip(s, start, end - 1);
                start = end + 1;
            }
            
        }
        
        private void flip(char[] s, int start, int end) {
            while (start < end) {
                char temp = s[start];
                s[start] = s[end];
                s[end] = temp;
                ++start;
                --end;
            }
        }
        
        private boolean isWhiteSpace(char ch) {
            return ch == ' ' || ch == '\t' || ch == '\n';
        }
    }
    

  • 0
    S

    Same here. waiting for fixing


  • 0

    We've just fixed this. Make sure you click on the reload icon above the code editor to reset to the default code definition, and try submit again. Also, Run Code is now available.


Log in to reply
 

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