博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Find the capitals
阅读量:6966 次
发布时间:2019-06-27

本文共 1042 字,大约阅读时间需要 3 分钟。

Description:

Instructions

Write a function that takes a single string (word) as argument. The function must return an ordered list containing the indexes of all capital letters in the string.

Example

Assert.AreEqual(Kata.Capitals("CodEWaRs"), new int[]{
0,3,4,6});

 

using System;using System.Linq;public static class Kata{  public static int[] Capitals(string word)  {    //Write your code here    int[] array = new int[] { };            if (word == null || word == string.Empty)            {                return array;            }            string tmp = word.ToLower();            return Enumerable.Range(0, tmp.Length).Where(i => word[i] != tmp[i]).ToArray();  }}

 

 

其他人的解法:

值得学习的是char本身自带了判断是否大写字母的函数

using System.Collections.Generic;using System;public static class Kata{  public static int[] Capitals(string word)  {     var capitalIndexes = new List
(); for (var i = 0; i < word.Length; i++) { if (char.IsUpper(word[i])) capitalIndexes.Add(i); } return capitalIndexes.ToArray(); }}

 

 

 

 

 

转载地址:http://hvfsl.baihongyu.com/

你可能感兴趣的文章
DUILIB中获取flash,webbrowser control的方法
查看>>
微信小应用,又一大神,音乐播放器
查看>>
sp存复杂对象
查看>>
第2条 遇到多个构造器参数时要考虑构建器
查看>>
Android Eclipse JNI 调用 .so文件加载问题
查看>>
JRE和JDK的区别分别代表什么
查看>>
AndroidManifest.xml配置详解
查看>>
sbt+Scala IDE建立Scala项目
查看>>
hadoop hbase维护问题总结
查看>>
AppData::create pipe(2) failed: Too many open file
查看>>
httpclient4 post 请求乱码
查看>>
ubuntu deb package install
查看>>
Hive代码组织及架构简单介绍
查看>>
阿里云安装LNMP以及更改网站文件和MySQL数据目录
查看>>
github访问太慢解决方案
查看>>
Win2003利用dfs(分布式文件系统)在负载均衡下的文件同步配置方案
查看>>
java 子类重写父类的方法的注意事项
查看>>
Angular文件上传---fileUpload的使用
查看>>
。。。。。
查看>>
nginx日志分割
查看>>