当前位置:网站首页>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;
}
}
边栏推荐
猜你喜欢
![[uniapp] uniapp development app online Preview PDF file](/img/11/d640338c626249057f7ad616b55c4f.png)
[uniapp] uniapp development app online Preview PDF file

自由小兵儿

What types of Thawte wildcard SSL certificates provide

Li Kou brush question diary /day4/6.26

Nature microbiology | viral genomes in six deep-sea sediments that can infect Archaea asgardii

BI技巧丨权限轴

Lex and yacc based lexical analyzer + parser

神经网络物联网应用技术学什么

字节跳动Dev Better技术沙龙成功举办,携手华泰分享Web研发效能提升经验

Angry bird design based on unity
随机推荐
更安全、更智能、更精致,长安Lumin完虐宏光MINI EV?
Caché WebSocket
[go ~ 0 to 1] read, write and create files on the sixth day
2022CoCa: Contrastive Captioners are Image-Text Fountion Models
资料下载 丨首届腾讯技术开放日课程精华!
Scala basic tutorial -- 20 -- akka
Nature Microbiology | 可感染阿斯加德古菌的六种深海沉积物中的病毒基因组
DeFi生态NFT流动性挖矿系统开发搭建
神经网络物联网应用技术就业前景【欢迎补充】
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
C # implementation defines a set of SQL statements that can be executed across databases in the middle of SQL (detailed explanation of the case)
使用FTP
Wireshark网络抓包
神经网络物联网是什么意思通俗的解释
Summary and sorting of 8 pits of redis distributed lock
信息学奥赛一本通 1336:【例3-1】找树根和孩子
Behind the ultra clear image quality of NBA Live Broadcast: an in-depth interpretation of Alibaba cloud video cloud "narrowband HD 2.0" technology
LeetCode FizzBuzz C#解答
Deleting nodes in binary search tree
2022养生展,健康展,北京大健康展,健康产业展11月举办