c# ordered array solution


  • 0
    T
    public class Solution {
        public bool CanConstruct(string ransomNote, string magazine) {
            var ranArr= ransomNote.ToArray();
            var magzArr = magazine.ToArray();
            Array.Sort(ranArr);
            Array.Sort(magzArr);
            var i=0;
            for(var j=0; i<ranArr.Length && j<magzArr.Length;j++)
            {
                if( ranArr[i]==magzArr[j])
                {
                    i++;
                }
            }
            return i==ranArr.Length;
        }
    }
    

Log in to reply
 

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