Skip to content

Instantly share code, notes, and snippets.

View Nanamare's full-sized avatar
👨‍👩‍👧‍👦
Happy life!

Nanamare(Lucas.shin) Nanamare

👨‍👩‍👧‍👦
Happy life!
View GitHub Profile
@Nanamare
Nanamare / RxOperatorTest.kt
Last active February 6, 2021 17:12
ByeBye RxOperator
class RxOperatorTest {
private val compositeDisposable = CompositeDisposable()
private val testScheduler = TestScheduler()
@BeforeEach
fun init() {
RxJavaPlugins.setComputationSchedulerHandler { testScheduler }
}
@Nanamare
Nanamare / ShortestPath.kt
Created February 3, 2020 16:03
최단 경로 그리디로 풀기
public class DynamicProgramming {
static int[][] map = {
{1, 1, 1, 1, 1},
{1, 1, 0, 0, 1},
{1, 1, 1, 1, 1},
{1, 1, 1, 0, 1},
{0, 0, 1, 1, 1}
};
@Nanamare
Nanamare / WhatIsToday.kt
Created February 3, 2020 14:38
해당 요일 맞추기
fun solution(a: Int, b: Int): String {
val months = listOf(0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30)
val dayName = listOf("THU", "FRI", "SAT", "SUN", "MON", "TUE", "WED")
val day = months.subList(0, a).fold(0) { acc, number -> acc + number } + b
return dayName[day % 7]
}
@Nanamare
Nanamare / Rotate.kt
Created February 3, 2020 14:35
배열 회전하기
fun main() {
val list = listOf(1, 2, 3, 4, 5, 6, 7, 8)
// 1, 2, 6, 3, 4, 5, 7, 8
val results= leftRotate(2, 6, list.toMutableList())
results.forEach {
println(it)
}
}
fun rightRotate(start: Int, end: Int, list: MutableList<Int>): List<Int> {
@Nanamare
Nanamare / Queue.kt
Created February 3, 2020 14:33
큐 구현하기
fun main() {
val queue = Queue()
queue.insert(1)
queue.insert(2)
queue.insert(3)
queue.insert(4)
queue.insert(5)
queue.insert(6)
@Nanamare
Nanamare / LinkedList.kt
Created February 3, 2020 14:32
링크드리스트 작성하기
fun main() {
val linkedList = LinkedList()
linkedList.addNodeAtLast(444)
linkedList.addNodeAtLast(555)
linkedList.addNodeAtFront(333)
linkedList.addNodeAtFront(222)
linkedList.addNodeAtFront(111)
linkedList.addNodeAtLast(666)
linkedList.addNodeAtLast(777)
@Nanamare
Nanamare / Fibonacci.kt
Created February 3, 2020 14:30
피보나치 메모이제이션
fun main() {
println(fibonacci(80))
}
const val LIMIT = 1000
val mem = Array(LIMIT) {0L}
/**
* memoization
* n >= 3
@Nanamare
Nanamare / FactorialRec.kt
Created February 3, 2020 14:25
팩토리얼 꼬리 재귀 풀이
fun main() {
println(factorialTailRec(12, 1))
}
fun factorialTailRec(number: Int, accumulator: Int ): Int {
return if (number == 0) {
accumulator
} else {
factorialTailRec(number - 1, number * accumulator)
@Nanamare
Nanamare / Coin.kt
Created February 3, 2020 14:24
금액 경우의 수 구하기
fun main() {
coin()
}
fun coin() {
val bills = arrayOf(1, 2, 5, 10, 20 ,50)
var count = 0
val money = 100
@Nanamare
Nanamare / Binomial.kt
Created February 3, 2020 14:21
이항계수 구하기
fun main() {
println(binomial(60, 15)) // 60 개중 15개를 뽑는 방법
}
const val n = 60
const val r = 15
val matrix = Array(n) { Array(r) { 0 } }
/**