当前位置:网站首页>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;
}
}
边栏推荐
- 基于C语言的菜鸟驿站管理系统
- Li Kou brush question diary /day7/2022.6.29
- Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
- 基于lex和yacc的词法分析器+语法分析器
- 问下各位大佬有用过cdc直接mysql to clickhouse的么
- 使用FTP
- Nebula Importer 数据导入实践
- Li Chi's work and life summary in June 2022
- 一种将Tree-LSTM的强化学习用于连接顺序选择的方法
- Improve the accuracy of 3D reconstruction of complex scenes | segmentation of UAV Remote Sensing Images Based on paddleseg
猜你喜欢
一种将Tree-LSTM的强化学习用于连接顺序选择的方法
Scala基础教程--17--集合
Go microservice (II) - detailed introduction to protobuf
[release] a tool for testing WebService and database connection - dbtest v1.0
What if the self incrementing ID of online MySQL is exhausted?
An example of multi module collaboration based on NCF
Scala基础教程--13--函数进阶
Learning path PHP -- phpstudy "hosts file does not exist or is blocked from opening" when creating the project
自由小兵儿
Scala basic tutorial -- 18 -- set (2)
随机推荐
利用策略模式优化if代码【策略模式】
每日一题(2022-07-02)——最低加油次数
基于C语言的菜鸟驿站管理系统
Halcon模板匹配
2022 ByteDance daily practice experience (Tiktok)
李迟2022年6月工作生活总结
[mathematical basis of machine learning] (I) linear algebra (Part 1 +)
[go language question brushing chapter] go conclusion chapter | introduction to functions, structures, interfaces, and errors
基于unity的愤怒的小鸟设计
Is the securities account opened by qiniu safe?
发送和接收IBM WebSphere MQ消息
信息学奥赛一本通 1336:【例3-1】找树根和孩子
Scala基础教程--16--泛型
ESP32-C3入门教程 问题篇⑫——undefined reference to rom_temp_to_power, in function phy_get_romfunc_addr
Li Kou brush question diary /day6/6.28
工厂从自动化到数字孪生,图扑能干什么?
2022-07-04: what is the output of the following go language code? A:true; B:false; C: Compilation error. package main import 'fmt' func
PB的扩展DLL开发(超级篇)(七)
Learning path PHP -- phpstudy "hosts file does not exist or is blocked from opening" when creating the project
DeFi生态NFT流动性挖矿系统开发搭建