본문 바로가기

전체 글103

[LeetCode] 187. Repeated DNA Sequences Java class Solution { public List findRepeatedDnaSequences(String s) { Set set = new HashSet(); Set answerSet = new HashSet(); for(int i=0;i 2021. 6. 18.
[Leetcode] Game of Life Java //간단한 시뮬레이션 문제였는데 문제를 잘못 이해했다.... class Solution { public void gameOfLife(int[][] board) { int[] dx = {-1,-1,0,1,0,1,-1,1}; int[] dy = {-1,0,-1,0,1,1,1,-1}; int n = board.length; int m = board[0].length; int[][] answer = new int[n][m]; for(int i=0; i 2021. 6. 18.
[프로그래머스] 압축 java 시키는데로 잘 풀면 된다. 내가 푼 방법의 핵심은 우선 스트링빌더에 다음 문자를 넣고 해당되는 값이 Map에 들어가있지 않으면 해당 값을 Map에 추가하여주는 동시에 List에 집어 넣어 준다. 시간복잡도는 아마도 O(N) 안에는 끝나지 않을까 싶다. import java.util.*; class Solution { public int[] solution(String msg) { int[] answer = {}; char[] charArr = msg.toCharArray(); List list = new ArrayList(); Map dic = new HashMap(); for(int i=0;i 2021. 5. 6.
[백준] 퇴사2 Java //이전에 풀었는데 다시 풀었다. static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public static void input(int arr[][], int n) throws IOException { StringTokenizer st; for (int i = 0; i < n; i++) { st = new StringTokenizer(br.readLine()); arr[i][0] = Integer.parseInt(st.nextToken()); arr[i][1] = .. 2021. 4. 15.