티스토리 뷰
Example Code
public class Main{
public static void main(String args[]) {
int arr[] = {2,4,1,7,0};
System.out.println(min(arr));
}
public static int min(int[] arr){
int min = arr[0];
int sec = arr[1];
for(int i = 0; i < arr.length; i++){
if(arr[i] < min){ //get the smallest
sec = min; //should change sec here
min = arr[i];
}else if(arr[i] < sec){//get the second smallest
sec = arr[i];
}
}
return sec;
}
}
|
'Algorithms' 카테고리의 다른 글
Diagonal Difference in JavaScript (0) | 2020.07.27 |
---|---|
Calculate the Max minus Min Value in Array (0) | 2019.09.08 |
Counting Valley (0) | 2019.08.31 |
Comparison performing contains() for ArrayList and HashSet (0) | 2019.08.31 |
Insertion Sort (0) | 2019.08.01 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- algorithm
- code refactoring
- substring()
- Object type casting
- math.abs
- 프로그래머스 알고리즘
- spring boot application
- equals()
- java
- hackerrank solution
- C++
- easy algorithm
- repeat()
- math.max
- easy javascript algorithm
- rest parameter
- hackerrank
- HackerRank Algorithm
- Collection Framework
- javascript
- compareTo()
- hackerrank javascript
- hackerrank javascript solution
- 프로그래머스 알고리즘문제
- HashMap
- 프로그래머스
- Javascript Algorithm
- ... in Javascript
- 알고리즘
- string class in 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 |
글 보관함