-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrixString.java
More file actions
22 lines (17 loc) · 806 Bytes
/
matrixString.java
File metadata and controls
22 lines (17 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.util.Arrays;
import java.util.stream.IntStream;
public class Matrix {
private int[][] m;
public Matrix(String mStr){
m = Arrays.stream( mStr.split("\n") )
.map( line -> Arrays.stream(line.split(" "))
.mapToInt( s -> Integer.parseInt(s) )
.toArray() )
.toArray(int[][]::new);
}
public int[] getColumn(int c) { return IntStream.range(0,m.length).map( r -> m[r][c] ).toArray(); }
public int[] getRow(int r) { return Arrays.copyOf(m[r], m[0].length); }
public int getRowsCount() { return m.length; }
public int getColumnsCount() { return m[0].length; }
}
//https://www.codewars.com/kata/58b9ac455927cd595a0000d4/train/java