标签:
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; } }
标签:
原文地址:http://www.cnblogs.com/charlesblc/p/5814702.html