当前位置:网站首页>LeetCode 赎金信 C#解答
LeetCode 赎金信 C#解答
2022-07-04 17:39:00 【charlsdm】
- 赎金信
给你两个字符串:ransomNote 和 magazine ,判断 ransomNote 能不能由 magazine 里面的字符构成。
如果可以,返回 true ;否则返回 false 。
magazine 中的每个字符只能在 ransomNote 中使用一次。
示例 1:
输入:ransomNote = “a”, magazine = “b”
输出:false
示例 2:
输入:ransomNote = “aa”, magazine = “ab”
输出:false
示例 3:
输入:ransomNote = “aa”, magazine = “aab”
输出:true
提示:
1 <= ransomNote.length, magazine.length <= 105
ransomNote 和 magazine 由小写英文字母组成
通过次数193,359提交次数306,645
下边是我的AC代码
public partial class Solution
{
public static bool CanConstruct(string ransomNote, string magazine)
{
char[] ramchars = ransomNote.ToCharArray();
char[] magachars = magazine.ToCharArray();
List<char> listram = ramchars.ToList<char>();
List<char> listmaga = magachars.ToList<char>();
int CountA = listmaga.Count;
int CountB = listram.Count;
for (int i = 0; i < CountA; i++)
{
char c = listmaga[i];
if (listram.Contains(c))
{
listram.Remove(c);
}
}
if (listram.Count > 0)
{
return false;
}
return true;
}
}
边栏推荐
- A method of using tree LSTM reinforcement learning for connection sequence selection
- PB的扩展DLL开发(超级篇)(七)
- What if the self incrementing ID of online MySQL is exhausted?
- 【uniapp】uniapp开发app在线预览pdf文件
- 自由小兵儿
- NBA赛事直播超清画质背后:阿里云视频云「窄带高清2.0」技术深度解读
- Li Kou brush question diary /day1/2022.6.23
- Uni app and uviewui realize the imitation of Xiaomi mall app (with source code)
- 基于unity的愤怒的小鸟设计
- TorchDrug教程
猜你喜欢

正则替换【JS,正则表达式】
![[go language question brushing chapter] go conclusion chapter | introduction to functions, structures, interfaces, and errors](/img/7a/16b481753d7d57f50dc8787eec8a1a.png)
[go language question brushing chapter] go conclusion chapter | introduction to functions, structures, interfaces, and errors

激进技术派 vs 项目保守派的微服务架构之争

【uniapp】uniapp开发app在线预览pdf文件

Uni app and uviewui realize the imitation of Xiaomi mall app (with source code)

Li Kou brush question diary /day4/6.26

Basic tutorial of scala -- 16 -- generics

Nature Microbiology | 可感染阿斯加德古菌的六种深海沉积物中的病毒基因组

Scala基础教程--17--集合

从实时应用角度谈通信总线仲裁机制和网络流控
随机推荐
Scala basic tutorial -- 19 -- actor
[go ~ 0 to 1] read, write and create files on the sixth day
[release] a tool for testing WebService and database connection - dbtest v1.0
repeat_P1002 [NOIP2002 普及组] 过河卒_dp
【OpenCV入门到精通之九】OpenCV之视频截取、图片与视频互转
Scala基础教程--16--泛型
C语言打印练习
[mathematical modeling of graduate students in Jiangxi Province in 2022] analysis and code implementation of haze removal by nucleation of water vapor supersaturation
Go microservice (II) - detailed introduction to protobuf
. Net ORM framework hisql practice - Chapter 2 - using hisql to realize menu management (add, delete, modify and check)
Wanghongru research group of Institute of genomics, Chinese Academy of Agricultural Sciences is cordially invited to join
Deleting nodes in binary search tree
Li Kou brush question diary /day5/2022.6.27
Scala basic tutorial -- 15 -- recursion
李迟2022年6月工作生活总结
更安全、更智能、更精致,长安Lumin完虐宏光MINI EV?
MXNet对GoogLeNet的实现(并行连结网络)
学习路之PHP--phpstudy创建项目时“hosts文件不存在或被阻止打开”
sqlserver的CDC第一次查询的能读取到数据,但后面增删改读取不到,是什么原因
Torchdrug tutorial