스칼라 23

N개의 측정치가 주어질 때 M개의 이동 평균을 계산하라.

package kwo2002.java; import java.util.ArrayList; import java.util.Arrays; import java.util.List; /** * Created by kwo2002 on 2015-08-21. */ public class MAverage { public List mAvg(List nList, int m) { if (m > nList.size()) { throw new IllegalArgumentException(); } List avgList = new ArrayList(); for (int i = m - 1; i < nList.size(); i++) { double sum = 0.0d; for (int j = 0; j < m; j++) { sum +..

스칼라의 자료구조 공부중 - 자바와의 비교.

스칼라의 단방향 연결 리스트를 보다가, 자바로 먼저 구현해봐야겠다는 생각에 자바로 초간단 단방향 연결 리스트를 구현해보았다. package kwo2002.java; /** * Created by kwo2002 on 2015-08-06. */ public class SingleNode { private SingleNode next; private E e; public SingleNode(E e) { e = this.e; } public SingleNode(E e, SingleNode next) { e = this.e; next = this.next; } public void appendToTail(E e) { SingleNode end = new SingleNode(e); SingleNode current..

M X N 행렬의 한 원소가 0이라면, 해당 원소가 속한 행과 열의 모든 원소를 0으로 바꾸는 함수를 작성하라

/** * Created by kwo2002 on 2015-08-04. */ object MatrixZero { def getZeroElemIndex(matrix: Array[Array[Int]]): Array[Array[Int]] = { def go(i: Int, j: Int): (Int, Int) = { if (i > matrix.length) { (-1, -1) } else { if (matrix(i)(j) == 0) { (i, j) } else { if (j >= matrix(i).length - 1) { go(i + 1, 0) } else { go(i, j + 1) } } } } val zeroIndex: (Int, Int) = go(0, 0) if (zeroIndex._1 >= 0) { mod..