leetcode520

public class Solution {
    public bool DetectCapitalUse(string word) {
        var length = word.Length;

            if (length > 1)
            {
                int UpCaseCount = 0;
                int LowCaseCount = 0;
                bool firstCapital = false;
                bool firstTime = true;
                foreach (var c in word)
                {
                    if (char.IsUpper(c))
                    {
                        UpCaseCount++;

                        if (firstTime)
                        {
                            firstCapital = true;
                        }
                    }
                    else if (char.IsLower(c))
                    {
                        LowCaseCount++;
                    }
                    firstTime = false;
                }

                if (UpCaseCount == 1 && firstCapital)
                {
                    return true;
                }
                if (UpCaseCount == 0 && LowCaseCount == length)
                {
                    return true;
                }
                if (LowCaseCount == 0 && UpCaseCount == length)
                {
                    return true;
                }

                return false;
            }
            else
            {
                return true;
            }
    }
}

https://leetcode.com/problems/detect-capital/#/description

原文地址:https://www.cnblogs.com/asenyang/p/6732250.html