当前位置:网站首页>Leetcode ransom letter C # answer
Leetcode ransom letter C # answer
2022-07-04 19:20:00 【charlsdm】
- Ransom letter
Here are two strings :ransomNote and magazine , Judge ransomNote Can it be done by magazine The characters inside make up .
If possible , return true ; Otherwise return to false .
magazine Each character in can only be in ransomNote Used once in .
Example 1:
Input :ransomNote = “a”, magazine = “b”
Output :false
Example 2:
Input :ransomNote = “aa”, magazine = “ab”
Output :false
Example 3:
Input :ransomNote = “aa”, magazine = “aab”
Output :true
Tips :
1 <= ransomNote.length, magazine.length <= 105
ransomNote and magazine It's made up of lowercase letters
Pass times 193,359 Submit the number 306,645
Below is my AC Code
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;
}
}
边栏推荐
- Nature microbiology | viral genomes in six deep-sea sediments that can infect Archaea asgardii
- 模板_大整数减法_无论大小关系
- Scala基础教程--19--Actor
- LeetCode FizzBuzz C#解答
- A method of using tree LSTM reinforcement learning for connection sequence selection
- Scala基础教程--17--集合
- 《看完就懂系列》字符串截取方法substr() 、 slice() 和 substring()之间的区别和用法
- Summary and sorting of 8 pits of redis distributed lock
- How is the entered query SQL statement executed?
- [opencv introduction to mastery 9] opencv video capture, image and video conversion
猜你喜欢

MXNet对GoogLeNet的实现(并行连结网络)

How is the entered query SQL statement executed?

vbs或vbe如何修改图标

ByteDance dev better technology salon was successfully held, and we joined hands with Huatai to share our experience in improving the efficiency of web research and development

NBA赛事直播超清画质背后:阿里云视频云「窄带高清2.0」技术深度解读

Li Kou brush question diary /day4/6.26

Scala basic tutorial -- 18 -- set (2)

Torchdrug tutorial

更安全、更智能、更精致,长安Lumin完虐宏光MINI EV?

TorchDrug教程
随机推荐
One question per day (2022-07-02) - Minimum refueling times
1、 Introduction to C language
LeetCode第300场周赛(20220703)
The latest progress of Intel Integrated Optoelectronics Research promotes the progress of CO packaging optics and optical interconnection technology
From automation to digital twins, what can Tupo do?
使用SSH
Scala基础教程--13--函数进阶
一种将Tree-LSTM的强化学习用于连接顺序选择的方法
Angry bird design based on unity
Esp32-c3 introductory tutorial questions ⑫ - undefined reference to ROM_ temp_ to_ power, in function phy_ get_ romfunc_ addr
【2022年江西省研究生数学建模】冰壶运动 思路分析及代码实现
小发猫物联网平台搭建与应用模型
建立自己的网站(15)
2022健康展,北京健博会,中国健康展,大健康展11月13日
DeFi生态NFT流动性挖矿系统开发搭建
6.26cf simulation match B: solution to array reduction problem
Scala基础教程--16--泛型
激进技术派 vs 项目保守派的微服务架构之争
Nature microbiology | viral genomes in six deep-sea sediments that can infect Archaea asgardii
基于C语言的菜鸟驿站管理系统