@StudY/.algorithm
-
[Day12] 15. 3Sum@StudY/.algorithm 2019. 3. 6. 11:17
Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c= 0? Find all unique triplets in the array which gives the sum of zero.Note:The solution set must not contain duplicate triplets.Example:Given array nums = [-1, 0, 1, 2, -1, -4], A solution set is: [ [-1, 0, 1], [-1, -1, 2] ] 어... 상당히 어려운 문제다.....어떻게 접근을 해야하지???? 최적의 Big-O 시간 복잡가 과연 뭘까????
-
[Day11] 830. Positions of Large Groups@StudY/.algorithm 2019. 3. 4. 16:05
830. Positions of Large Groups class Solution { public List largeGroupPositions(String S) { S = S+"\0"; List positions = new ArrayList(); int largest=1; if (S.length()==0) return positions; for (int i=0; i= 3) { List largeGroup = new ArrayList(); largeGroup.add(i-(largest-1)); largeGroup.add(i); positions.add(largeGroup); } largest=1; } else { largest++; } } return positions; }} Accepted6 ms39.9..
-
[Day10] 430. Flatten a Multilevel Doubly Linked List@StudY/.algorithm 2019. 2. 28. 18:02
430. Flatten a Multilevel Doubly Linked List Medium /*// Definition for a Node.class Node { public int val; public Node prev; public Node next; public Node child; public Node() {} public Node(int _val,Node _prev,Node _next,Node _child) { val = _val; prev = _prev; next = _next; child = _child; }};*/class Solution { public Node flatten(Node head) { Node flatten = head; Node temp = null; Node count..
-
[Day7] 876. Middle of the Linked List / 86. Partition List (LeetCode)@StudY/.algorithm 2019. 2. 22. 14:12
빛나는 졸업장을 타느라 어제는 회사도 알고리즘 공부도 하루 휴식! 876. Middle of the Linked List Easy /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */class Solution { public ListNode middleNode(ListNode head) { ListNode middle = head; ListNode counter = head; int count=1; while(counter.next!=null) { count++; counter = counter.next; } for (in..
-
[Day6] 981. Time Based Key-Value Store@StudY/.algorithm 2019. 2. 20. 14:15
981. Time Based Key-Value Store import java.util.HashMap.*; class TimeMap { HashMap map = new HashMap(); /** Initialize your data structure here. */ public TimeMap() { } public void set(String key, String value, int timestamp) { if (!map.containsKey(key)) { ArrayList list = new ArrayList(); list.add(value); list.add(timestamp+""); map.put(key,list); } else { map.get(key).add(value); map.get(key)..
-
[Day4] 529. Minesweeper@StudY/.algorithm 2019. 2. 18. 11:30
529. Minesweeper class Solution { public char[][] updateBoard(char[][] board, int[] click) { int ci = click[0]; int cj = click[1]; if (board[ci][cj]=='M') { board[ci][cj]='X'; return board; } else { int[] i = {-1,-1,-1, 0,0, 1,1,1}; int[] j = {-1, 0, 1,-1,1,-1,0,1}; int adjacents = 0; for (int k=0; k
-
[Day3] 108. Convert Sorted Array to Binary Search Tree@StudY/.algorithm 2019. 2. 15. 14:37
108. Convert Sorted Array to Binary Search Tree /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { public TreeNode sortedArrayToBST(int[] nums) { if (nums.length>0 ) { TreeNode newT = new TreeNode(nums[nums.length/2]); int[] left = new int[nums.length/2]; int[] right; if (nums.leng..