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 ...
随机推荐
- web 常用网址及资源
一.web教程 w3school在线教程 菜鸟教程 二.学习路线 2017前端学习路线图,内附完整前端自学视频教程+工具经验-黑马程序员技术交流社区 三.工具 盘搜 百度地图 查物流 金山词霸 必应词 ...
- 剑指offer-int类型负数补码中1的个数-位操作
在java中Interger类型表示的最大数是 System.out.println(Integer.MAX_VALUE);//打印最大整数:2147483647 这个最大整数的二进制表示,头部少了一 ...
- 剑指offer-第一个只出现一次的字符-字符串和数组
用到的算法都是像冒泡排序,直接选择排序,插入排序 每趟进行处理,这个趟是没有什么实际意义的 变量j一次从头走到尾进行一次循环枚举遍历扫描 一.题目:第一个只出现一次的字符 题目:在字符串中找出第一个只 ...
- 实习第二天-java参数传递-精华在文章最后2句话
对于基本类型的传递,我们很容易理解,而对于对象,总让人感觉是按引用传递,看下面的程序: public class ObjectRef { //基本类型的参数传递 public static void ...
- encode decode enumerate
format的用法 print(format('aa','>20')) print(format('aa','<20')) print(format('aa','^20')) 打印结果如下 ...
- vulcanjs 开源工具方便快速开发react graphql meteor 应用
vulcan 开源工具方便快速开发react graphql meteor 应用 操作环境mac os 安装 meteor 安装(此安装有点慢,可以通过正确上网解决) curl https://ins ...
- Linux下安装xampp和bugfree
1.BugFree简介 1.1 BugFree的来源 BugFree是借鉴微软的研发流程和Bug管理理念,使用PHP+MySQL独立写出的一个Bug管理系统.简单实用.免费并且开放源代码(遵循GNU ...
- vue-cli 引入阿里巴巴字体图标:注意点
vue-cli 引入阿里巴巴字体图标:注意点 下载的 iconfont.css 文件中: .iconfont { font-family:"iconfont" !important ...
- Vuejs项目的Webpack2构建优化
最近在做的项目因为相对较大(打包有100多个chunk),在build构建的时候速度一直上不去,甚是烦恼.由于用的是vue-cli的webpack2模板,一开始并没有想着要对其进行优化,一直觉得是we ...
- php preg_replace空格无法替换问题
一次坑爹的小bug.读取一段文字(编码utf-8),想替换掉空格,str_replace(" "..).preg_replace("/\s/"..)都不起作用. ...