Basic C# solution


  • 0
    B

    public class Solution {

    /*
        Approach : look for and i and i + 1 character 
        mark them as -- , 
    */
    public IList<string> GeneratePossibleNextMoves(string s) {
        IList<string> result = new List<string>();
        
        if(s == null || s.Equals(""))
            return result;
        
        int len = s.Length;
        char[] chars = s.ToCharArray();
        int i = 0;
        for(i = 0; i < len; i++)
        {
            if(i < len - 1 && chars[i] == '+' && chars[i + 1] == '+')
            {
                chars[i] = '-';
                chars[i + 1] = '-';
                string nextMove = new String(chars).ToString();
                result.Add(nextMove);
                chars[i] = '+';
                chars[i + 1] = '+';
            }
        }
        
        return result;
    }
    

    }


Log in to reply
 

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