栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

LeetCode 赎金信 C#解答

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

LeetCode 赎金信 C#解答

  1. 赎金信
    给你两个字符串: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 listram = ramchars.ToList();
                List listmaga = magachars.ToList();

                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;
            }

        }
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1006359.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号