首页 > 代码库 > ransom-note

ransom-note

https://leetcode.com/problems/ransom-note/public class Solution {    public boolean canConstruct(String ransomNote, String magazine) {        char[] chRan = ransomNote.toCharArray();        char[] chMag = magazine.toCharArray();        Arrays.sort(chRan);        Arrays.sort(chMag);        int j = 0;        for (int i=0; i<chRan.length; i++) {            for (; j<chMag.length; j++) {                if (chMag[j] > chRan[i]) {                    return false;                }                if (chMag[j] == chRan[i]) {                    break;                }            }            if (j < chMag.length) {                j++;            }            else {                return false;            }        }        return true;    }}

 

ransom-note