Java O(n) ,easy to understand


  • 0
    G

    this is my code:

    public class Solution {
        public boolean canConstruct(String ransomNote, String magazine) {
            List<Character> maga=new ArrayList<>();
            for(Character c:magazine.toCharArray()) maga.add(c);
            for(Character c:ransomNote.toCharArray()){
                if(!maga.contains(c)){return false;}
                else{
                    maga.remove(maga.indexOf(c));
                }
            }
            return true;
        }
    }
    

Log in to reply
 

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