Test case input none return "" failed but IDE return correct.


  • 0
    S
        private string ReverseWordsinaString(string s)
        {
            var ss = s.ToList();
    
            ss.Insert(0, ' ');
            var len = ss.Count - 1;
            var stack = new Stack<char>();
            var spaceCount = 0;
    
            for (var i = len; i > -1; i--)
            {
                stack.Push(ss[i]);
                if (ss[i] != ' ') continue;
    
                spaceCount++;
    
                ss.RemoveRange(i, stack.Count);
    
                while (stack.Count > 0)
                {
                    ss.Add(stack.Pop());
                }
            }
    
            if (spaceCount <= 1) return string.Empty;
    
            ss.RemoveAt(0);
    
            return string.Concat(ss);
        }

Log in to reply
 

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