본문 바로가기

728x90
반응형

전체 글

(154)
[LeetCode/70/Java]Climbing Stairs [LeetCode/70/Java]Climbing Stairs 풀이 class Solution { public static int[] buf = new int[46]; public int climbStairs(int n) { if (n
[LeetCode/119/Java]Pascal's Triangle II [LeetCode/119/Java]Pascal's Triangle II 풀이 class Solution { public static Map buf = new HashMap(); public static int maxRow = 0; public List getRow(int rowIndex) { List prev = null; List result = new ArrayList(); int start = maxRow; if(buf.containsKey(rowIndex)) return buf.get(rowIndex); result.add(1); for (int i = start; i 0) { if(i > 1) result.add(i); if(buf.containsKey(i)) { result = buf.get(..
[LeetCode/700/Java]Search in a Binary Search Tree [LeetCode/700/Java]Search in a Binary Search Tree 풀이 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * TreeNode(int val, TreeNode left, TreeNode right) { * this.val = val; * this.left = left; * this.right = right; * } * } */ class Solution { public TreeNode searchBST(TreeNode ..
[LeetCode/206/Java]Reverse Linked List [LeetCode/206/Java]Reverse Linked List 풀이 /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.next = next; } * } */ class Solution { public ListNode reverseList(ListNode head) { if((head == null) || (head.next == null)) return head; ListNode..
[LeetCode/24/Java]Swap Nodes in Pairs [LeetCode/24/Java]Swap Nodes in Pairs 풀이 /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.next = next; } * } */ class Solution { public ListNode swapPairs(ListNode head) { if((head == null) || (head.next == null)) return head; ListNode re..
[LeetCode/344/Java]Reverse String [LeetCode/344/Java]Reverse 풀이 class Solution { public void reverseString(char[] s) { reverseString(s, 0); } public void reverseString(char[] s, int idx) { if(idx < s.length / 2) { char temp1 = s[idx]; s[idx] = s[(s.length - 1) - idx]; s[(s.length - 1) - idx] = temp1; reverseString(s, idx + 1); } } } 후기 문자열을 뒤집는 처리입니다. 반복문을 사용하는 방법이 일반적이지만 재귀 호출을 연습할 겸 재귀호출을 이용한 방법을 사용해 보았습니다. time complexity O(N..
[군마/쿠사쯔]일본에서 가장 유명한 온천 쿠사쯔 온천여행(2) [군마/쿠사쯔]일본에서 가장 유명한 온천 쿠사쯔 온천여행(2) 안녕하세요 미나라이입니다. 요즘 바빠서 포스팅이 늦어졌네요 쿠사쯔 온천 방문 후기 2편을 작성합니다. 1편 링크 [군마/쿠사쯔]일본에서 가장 유명한 온천 쿠사쯔 온천여행(1) [군마/쿠사쯔]일본에서 가장 유명한 온천 쿠사쯔 온천여행(1) 안녕하세요 미나라이입니다. 이번에는 언젠가 한번은 가보고 싶은 온천이었던 쿠사쯔 온천에 다녀와서 포스팅을 남겨볼까 합니 nameybs.tistory.com 저녁식사를 마치고 숙소에서 간단하게 온천욕을 하였습니다. 외출하고 돌아오니 이렇게 이불을 깔아다 놓아주네요 이번에는 키리시마야칸 이라는 료칸에서 숙박을 하였습니다. 일본에서는 료칸 하면 가이세키 요리가 나오고 분위기좋은 노천탕이 있는 이미지가 강한데 이번에..
[백준/10870/Java]피보나치 수 [백준/10870/Java]피보나치 수 풀이 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(br.readLine()); int result = 0; int prev = 1; for (int i = 0; i < N; i++) { result += prev; prev = re..

728x90
반응형