Insertion Sort 삽입정렬 Insert an element in the sorted subarray to its left. 두번째 Index를 시작으로 자신보다 앞 쪽 (왼쪽) 의 값과 계속 비교해가면서 자리를 옮겨나가는 알고리즘이다. How the Insertion array works int arr[] = [3,5,1,4,2] partial sorted subarray partial unsorted array [3] [5,1,4,2] [3,5] [1,4,2] [3,5,1] -> [3,1,5] -> [1,3,5] [4,2] [1,3,5,4] -> [1,3,4,5] [2] [1,3,4,5,2] -> [1,3,4,2,5] -> [1,3,2,4,5] -> [1,2,3,4,5] [] Solution ..
Sequential Search Algorithm (Linear Search) 순차탐색 Less used than binary search and Hash Table. Big-O notation for Sequential Search is O(n) which is relatively slower than others. public class Main { public static void main(String[] args) { int arr[] = {7, 4, 3, 1, 5}; int x = 3; int answer = linearSearch(arr, x); if(answer == -1){ System.out.println("No element matched"); }else{ System.out.print..
Array.sort() sort the Array in ascending order Example Code import java.util.Arrays; public class Main { public static void main(String[] args) { int arr[] = {2,7,1,9,7}; for (int number : arr) { System.out.print(number); //27197 } // sorting array Arrays.sort(arr); System.out.println("\nSorted numbers are"); for (int number : arr) { System.out.print(number); //12779 } } }
HashMap HashMap is not thread-safe which allows you faster speed than HashTable. HashMap doesn't allow insertion order. *Use LinkedHashMap to preserve the fixed order. key doesn't allow duplicate key, but for value, duplication is allowed. put() - key, value map에 입력 get() - key를 전달해야 그 key의 value가 반환된다. remove() - 해당 key의 key와 value 삭제 Example Code import java.util.*; public class Main { public ..
students.csv id,name 1,A 2,B 3,C public class StudentInfo { private int id; private String name; public StudentInfo(int id, String name){ this.id = id; this.name = name; } public int studentId(){ return id; } @Override public String toString(){ return "Student Id: " + this.id + ", " + "name: " + this.name + "\n"; } } public class Main { public static void main(String[] args) throws FileNotFoundE..
예외처리 (Exception handling) 은 프로그램의 논리에 벗어난 에러인 runtime error를 발견하도록 도와준다. - 사용자정의 exception handling 이 아닌 자바에 자체적으로 내장되어있는 에러클래스의 경우 (e.g. ArithmeticException) 사용자가 새롭게 객체를 정의하지 않아도 JVM에 의해 생성된 인스턴스의 참조값이 전달된다. import java.util.Scanner; class Main{ public static void main(String[] args){ System.out.print("Enter two digits: "); Scanner keyboard = new Scanner(System.in); int num1 = keyboard.nextInt..
- Total
- Today
- Yesterday
- rest parameter
- Javascript Algorithm
- HashMap
- 프로그래머스 알고리즘문제
- 프로그래머스
- hackerrank solution
- HackerRank Algorithm
- compareTo()
- hackerrank javascript
- spring boot application
- easy algorithm
- 프로그래머스 알고리즘
- string class in java
- Collection Framework
- math.max
- javascript
- ... in Javascript
- hackerrank
- C++
- algorithm
- easy javascript algorithm
- 알고리즘
- code refactoring
- math.abs
- equals()
- Object type casting
- substring()
- repeat()
- hackerrank javascript solution
- java
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |