C# LinkedList


  • 0
    N
    public class Solution {
        public bool CheckRecord(string s) {
            
            char[] record = s.ToCharArray();
            int absent = 0;
            bool reward = true;
            
            LinkedList<char> attendance = new LinkedList<char>(record);
    
            for(LinkedListNode<char> it = attendance.First; it != null; it = it.Next )
            {
                if(it.Value == 'A') absent++;
                else if(it.Value == 'L')
                {
                    try{
                    if(it.Previous.Value == 'L' && it.Next.Value == 'L') reward = false;
                    }
                    catch(NullReferenceException e){  }
                }    
            }        
            if(absent > 1) reward = false;        
            return reward;
        }
    }
    

Log in to reply
 

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