백준 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뜸
왜? 이클립스에서는 오류 안났는데;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
java.lang.NullPointerException 해결법
자바에서 NullPointerException은 RuntimeException입니다. 특수한 널 값은 객체 참조에 할당할 수 있습니다. 프로그램에 널값을 가지는 객체 참조를 사용하려고하면 NullPointerException이 throw됩니다. + null..
yeolco.tistory.com
'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 |
댓글