当前位置:网站首页>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;
}
}
边栏推荐
- 其他InterSystems %Net工具
- 自由小兵儿
- Scala基础教程--16--泛型
- 一种将Tree-LSTM的强化学习用于连接顺序选择的方法
- Li Chi's work and life summary in June 2022
- Behind the ultra clear image quality of NBA Live Broadcast: an in-depth interpretation of Alibaba cloud video cloud "narrowband HD 2.0" technology
- Rookie post station management system based on C language
- 未来几年中,软件测试的几大趋势是什么?
- Scala基础教程--14--隐式转换
- Nature Microbiology | 可感染阿斯加德古菌的六种深海沉积物中的病毒基因组
猜你喜欢
每日一题(2022-07-02)——最低加油次数
力扣刷题日记/day4/6.26
A method of using tree LSTM reinforcement learning for connection sequence selection
性能优化之关键渲染路径
Behind the ultra clear image quality of NBA Live Broadcast: an in-depth interpretation of Alibaba cloud video cloud "narrowband HD 2.0" technology
ThreadLocal原理与使用
Scala基础教程--17--集合
. Net ORM framework hisql practice - Chapter 2 - using hisql to realize menu management (add, delete, modify and check)
Lex and yacc based lexical analyzer + parser
Angry bird design based on unity
随机推荐
NBA赛事直播超清画质背后:阿里云视频云「窄带高清2.0」技术深度解读
Scala basic tutorial -- 17 -- Collection
Esp32-c3 introductory tutorial questions ⑫ - undefined reference to ROM_ temp_ to_ power, in function phy_ get_ romfunc_ addr
技术分享 | 接口测试价值与体系
1、 Introduction to C language
2022健康展,北京健博会,中国健康展,大健康展11月13日
神经网络物联网是什么意思通俗的解释
[cloud voice suggestion collection] cloud store renewal and upgrading: provide effective suggestions, win a large number of code beans, Huawei AI speaker 2!
使用SSH
Scala basic tutorial -- 12 -- Reading and writing data
How is the entered query SQL statement executed?
发送和接收IBM WebSphere MQ消息
2022 ByteDance daily practice experience (Tiktok)
国元期货是正规平台吗?在国元期货开户安全吗?
力扣刷题日记/day4/6.26
从实时应用角度谈通信总线仲裁机制和网络流控
[uniapp] uniapp development app online Preview PDF file
Scala基础教程--12--读写数据
Basic tutorial of scala -- 16 -- generics
Process of manually encrypt the mass-producing firmware and programming ESP devices