public class Solution {
public bool DetectCapitalUse(string word) {
var length = word.Length; if (length > )
{
int UpCaseCount = ;
int LowCaseCount = ;
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 == && firstCapital)
{
return true;
}
if (UpCaseCount == && LowCaseCount == length)
{
return true;
}
if (LowCaseCount == && UpCaseCount == length)
{
return true;
} return false;
}
else
{
return true;
}
}
}

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

leetcode520的更多相关文章

  1. [Swift]LeetCode520. 检测大写字母 | Detect Capital

    Given a word, you need to judge whether the usage of capitals in it is right or not. We define the u ...

随机推荐

  1. 多边形面积问题(hdoj2036)

    杭电oj2036http://acm.hdu.edu.cn/showproblem.php?pid=2036 计算几何,求多边形的面积 只要记住这个公式: 如果逆时针给出点坐标,值为正, 如果顺时针给 ...

  2. hdu2065 "红色病毒"问题 指数型母函数

    关于指数型母函数的题目,通过用公式并展开得到系数做的吧,取最后两位就是对100取模 #include<stdio.h> int QuickPow(int a,long long n,int ...

  3. gcd模板(欧几里得与扩展欧几里得、拓展欧几里得求逆元)

    gcd(欧几里得算法辗转相除法): gcd ( a , b )= d : 即 d = gcd ( a , b ) = gcd ( b , a mod b ):以此式进行递归即可. 之前一直愚蠢地以为辗 ...

  4. 剑指offer-矩形覆盖-斐波那契数列(递归,递推)

    class Solution { public: int rectCover(int number) { if(number==0 || number==1||number==2) return nu ...

  5. Nginx 安装成Windows 服务方法

    1. 下载nginx windows版本 http://www.nginx.org 2. 下载微软的2个工具: instsrv.exe.srvany.exe 去微软网站下载安装Windows Serv ...

  6. TensorFlow笔记-05-反向传播,搭建神经网络的八股

    TensorFlow笔记-05-反向传播,搭建神经网络的八股 反向传播 反向传播: 训练模型参数,在所有参数上用梯度下降,使用神经网络模型在训练数据上的损失函数最小 损失函数:(loss) 计算得到的 ...

  7. sqlserver中numeric字段截取

    方法一:convert(float,字段名) as 别名 select convert(float,round(10.123232,2)) 结果:10.12 select convert(float, ...

  8. web.xml中context-param详解

    <context-param> <param-name>contextConfigLocation</param-name> <param-value> ...

  9. Package rdkafka was not found in the pkg-config search path.

    问题 在使用confluent-kafka-go 时遇到如下问题: $ go build t.go # pkg-config --cflags rdkafka Package rdkafka was ...

  10. MySQL索引分类和各自用途

    一. MySQL: 索引以B树格式保存 Memory存储引擎可以选择Hash或BTree索引,Hash索引只能用于=或<=>的等式比较. 1.普通索引:create index on Ta ...