my solution


  • 0
    V

    public boolean canConstruct(String ransomNote, String magazine) {
    if (ransomNote.length() > magazine.length()){
    return false;
    }
    for (int i = 0; i < ransomNote.length(); i++){
    String ii = ransomNote.substring(i, i+1);
    int index = magazine.indexOf(ii);
    if (index == -1){
    return false;
    } else {
    magazine = magazine.replaceFirst(ii, "");
    }
    }

        return true;
    }

Log in to reply
 

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