반응형
백준 6996번 문제랑 똑같음
Leetcode
class Solution {
public boolean isAnagram(String s, String t) {
PriorityQueue heap = new PriorityQueue();
PriorityQueue heap2 = new PriorityQueue();
for(int i=0; i<s.length(); i++){
heap.add(s.substring(i,i+1));
heap2.add(t.substring(i,i+1));
}
if(heap.poll().equals(heap2.poll())){
return true;
}
else{
return false;
}
}
}
---------------------------------------------------
이렇게 풀었는데 if(heap.poll().equals(heap2.poll())) -- 여기서 java.lang.NullPointerException뜸
왜? 이클립스에서는 오류 안났는데;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
반응형
'Leetcode' 카테고리의 다른 글
Leetcode <Sort> 1366. Rank Teams by Votes 50.6% Medium (0) | 2020.04.10 |
---|---|
Leetcode <Binary Search> 704. Binary Search 50.8% Easy (0) | 2020.04.10 |
Leetcode 328. Odd Even Linked List 52.5% Medium (0) | 2020.04.03 |
Leetcode 621. Task Scheduler 47.7% Medium (0) | 2020.04.03 |
Leetcode <Heap> 264. Ugly Number II 38.9% Medium (0) | 2020.04.03 |
댓글