C# Version of the Solution by Yueyi Wang


  • 0
    C
    public class Solution {
        public bool CanConstruct(string ransomNote, string magazine) {
            int[] table = new int[26];
            foreach (var m in magazine) table[m - 'a']++;
            foreach(var n in ransomNote) if(--table[n -'a'] == -1) return false;
            return true;
        }
    }
    

    How could Java run so much faster than C#? It takes 139ms with this almost identical solution.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.