当前位置:网站首页>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;
}
}
边栏推荐
猜你喜欢

2022年字节跳动日常实习面经(抖音)

Rookie post station management system based on C language

Process of manually encrypt the mass-producing firmware and programming ESP devices

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

Deleting nodes in binary search tree

Torchdrug tutorial

每日一题(2022-07-02)——最低加油次数

Digital "new" operation and maintenance of energy industry

VMware Tools和open-vm-tools的安装与使用:解决虚拟机不全屏和无法传输文件的问题

A method of using tree LSTM reinforcement learning for connection sequence selection
随机推荐
Uni app and uviewui realize the imitation of Xiaomi mall app (with source code)
Scala基础教程--13--函数进阶
从实时应用角度谈通信总线仲裁机制和网络流控
力扣刷題日記/day6/6.28
Behind the ultra clear image quality of NBA Live Broadcast: an in-depth interpretation of Alibaba cloud video cloud "narrowband HD 2.0" technology
输入的查询SQL语句,是如何执行的?
Li Kou brush question diary /day7/2022.6.29
2022养生展,健康展,北京大健康展,健康产业展11月举办
一、C语言入门基础
php伪原创api对接方法
Nebula importer data import practice
神经网络物联网应用技术就业前景【欢迎补充】
How to download files using WGet and curl
6.26CF模拟赛E:价格最大化题解
性能优化之关键渲染路径
What types of Thawte wildcard SSL certificates provide
资料下载 丨首届腾讯技术开放日课程精华!
Caché JSON 使用JSON适配器
完善的js事件委托
Halcon template matching