leetcode520
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的更多相关文章
- [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 ...
随机推荐
- 控制input只输入数字--- onkeyup="value=value.replace(/[^\d]/g,'')"
☆ <td><input type="text" class="spInput" onkeyup="value=value.repl ...
- 强大的Java Json工具类
转自: https://blog.csdn.net/u014676619/article/details/49624165 import java.io.BufferedReader; import ...
- 【java规则引擎】《Drools7.0.0.Final规则引擎教程》第3章 3.2 KIE概念&FACT对象
转载:https://blog.csdn.net/wo541075754/article/details/74943236 3.2.1 什么是KIE KIE(Knowledge Is Everythi ...
- 使用Visual Studio Code开发Asp.Net Core WebApi学习笔记(三)-- Logger
本篇是在上一篇的基础上添加日志功能,并记录NLog在Asp.Net Core里的使用方法. 第一部分:默认Logger支持 一.project.json添加日志包引用,并在cmd窗口使用 dotnet ...
- 使用Visual Studio Code开发Asp.Net Core WebApi学习笔记(二)-- Web Api Demo
在上一篇里,我已经建立了一个简单的Web-Demo应用程序.这一篇将记录将此Demo程序改造成一个Web Api应用程序. 一.添加ASP.NET Core MVC包 1. 在project.json ...
- php 使用 file_exists 还是 is_file
Jesns 提出 file_exists 比较老了,建议使用 is_file 来判断文件. 经过我的测试,is_file 果然快很多,以后可以改 is_file 来判断文件. 还有相关链接: is_f ...
- js 逻辑的短路运算
&& 与运算 同时为true,才为true: 表达式1为false,不用看表达式2: || 或运算 有一个为true,就为true: 表达式1为true,不用看表达式2: && ...
- 嵌入式QT应用的窗口大小、位置,QtreeStack的样式
1. 窗口固定大小 :this->setFixedSize(452,244); 2.窗口固定位置(经试验,触摸屏的鼠标事件不能有效使用) oldPos.setX((800-452)/2); ...
- 洛谷 4389 付公主的背包——多项式求ln、exp
题目:https://www.luogu.org/problemnew/show/P4389 关于泰勒展开: https://blog.csdn.net/SoHardToNamed/article/d ...
- Navicat导出opencart2.3数据字典
步骤请参考:http://blog.csdn.net/maquealone/article/details/60764420 运行SQL: 备注:opcml是数据库名称. select TABLE ...