자바/프로그래머스(36)
-
[Programmers/JAVA] 전화번호 목록
내 코드 import java.util.*; class Solution { public boolean solution(String[] phone_book) { boolean answer=true; //순서대로 정렬시, 다음 문자열이 제일 겹치는거임! Arrays.sort(phone_book); //hash문제라서 사용해봄. HashSet set=new HashSet(); for(int i=0; i
2023.02.23 -
[Programmers/JAVA] 연속 부분 수열 합의 개수
내 코드 import java.util.*; class Solution { public int solution(int[] elements) { int answer = 0; int index=1; HashSet set=new HashSet(); for(int i=0; i
2023.02.22 -
[Programmers/JAVA] [1차] 뉴스 클러스터링
내 코드 import java.util.*; class Solution { public int solution(String str1, String str2) { int answer = 0; String pattern="[A-Z]"; String[] str1_split=str1.toUpperCase().split(""); String[] str2_split=str2.toUpperCase().split(""); List str1_list=new ArrayList(); List str2_list=new ArrayList(); //두 char가 모두 문자라면 add for(int i=0; i
2023.02.21 -
[Programmers/JAVA] 프린터
내 코드 import java.util.*; class Solution { public int solution(int[] priorities, int location) { int answer = 0; int index=priorities.length-1; //queue에 priorities넣기 Queue pri_queue=new LinkedList(); for(int p : priorities) { pri_queue.add(p); } //priorities값을 정렬 Arrays.sort(priorities); //priorities의 최대값보다 숫자가 작으면 뒤로 보내기 while(location>=0) { if(pri_queue.peek() 맨뒤로 넘어가면) location에 pri_queue.size..
2023.02.20 -
[Programmers/JAVA] 귤 고르기
내 코드 import java.util.*; class Solution { public int solution(int k, int[] tangerine) { int answer = 0; //hashmap에 크기별로 갯수 저장. HashMap hashmap=new HashMap(); for(int t: tangerine) { if(hashmap.containsKey(t)) { hashmap.put(t, hashmap.get(t)+1); }else { hashmap.put(t, 1); } } //value만 저장 List values_list=new ArrayList(hashmap.values()); //역순으로 저장. Collections.sort(values_list, Collections.reverse..
2023.02.20 -
[Programmers/JAVA] n^2 배열 자르기
내 코드 import java.util.*; class Solution { public int[] solution(int n, long left, long right) { int[] answer= new int[(int)(right-left)+1]; //첫 행 list만들기 int[] list=new int[n]; for(int i=1; i
2023.02.17