@@ -9,21 +9,21 @@ import kotlin.math.max
99class Router (private val size : Int ) {
1010 private var cur = 0
1111 private val q: Queue <IntArray >
12- private val map: HashMap <Int ? , ArrayList <IntArray ? >>
12+ private val map: HashMap <Int , ArrayList <IntArray >>
1313
1414 init {
1515 q = LinkedList <IntArray >()
16- map = HashMap <Int ? , ArrayList <IntArray ? >>()
16+ map = HashMap <Int , ArrayList <IntArray >>()
1717 }
1818
1919 fun addPacket (source : Int , destination : Int , timestamp : Int ): Boolean {
2020 if (map.containsKey(destination)) {
2121 var found = false
22- val list: ArrayList <IntArray ? > = map.get(destination)!!
22+ val list: ArrayList <IntArray > = map.get(destination)!!
2323 for (i in list.indices.reversed()) {
24- if (list.get(i) !! [1 ] < timestamp) {
24+ if (list[i] [1 ] < timestamp) {
2525 break
26- } else if (list.get(i) !! [0 ] == source) {
26+ } else if (list[i] [0 ] == source) {
2727 found = true
2828 break
2929 }
@@ -33,12 +33,12 @@ class Router(private val size: Int) {
3333 }
3434 }
3535 if (map.containsKey(destination)) {
36- val list: ArrayList <IntArray ? > = map.get(destination)!!
36+ val list: ArrayList <IntArray > = map.get(destination)!!
3737 list.add(intArrayOf(source, timestamp))
3838 cur++
3939 q.offer(intArrayOf(source, destination, timestamp))
4040 } else {
41- val temp = ArrayList <IntArray ? >()
41+ val temp = ArrayList <IntArray >()
4242 temp.add(intArrayOf(source, timestamp))
4343 cur++
4444 map.put(destination, temp)
@@ -55,7 +55,7 @@ class Router(private val size: Int) {
5555 return intArrayOf()
5656 }
5757 val temp = q.poll()
58- val list: ArrayList <IntArray ? > = map.get(temp[1 ])!!
58+ val list: ArrayList <IntArray > = map.get(temp[1 ])!!
5959 list.removeAt(0 )
6060 if (list.isEmpty()) {
6161 map.remove(temp[1 ])
@@ -66,25 +66,25 @@ class Router(private val size: Int) {
6666
6767 fun getCount (destination : Int , startTime : Int , endTime : Int ): Int {
6868 if (map.containsKey(destination)) {
69- val list: ArrayList <IntArray ? > = map.get(destination)!!
69+ val list: ArrayList <IntArray > = map.get(destination)!!
7070 var lower = - 1
7171 var higher = - 1
7272 for (i in list.indices) {
73- if (list.get(i) !! [1 ] >= startTime) {
73+ if (list[i] [1 ] >= startTime) {
7474 lower = i
7575 break
7676 }
7777 }
7878 for (i in list.indices.reversed()) {
79- if (list.get(i) !! [1 ] <= endTime) {
79+ if (list[i] [1 ] <= endTime) {
8080 higher = i
8181 break
8282 }
8383 }
84- if (lower == - 1 || higher == - 1 ) {
85- return 0
84+ return if (lower == - 1 || higher == - 1 ) {
85+ 0
8686 } else {
87- return max(0.0 , (higher - lower + 1 ).toDouble()).toInt()
87+ max(0.0 , (higher - lower + 1 ).toDouble()).toInt()
8888 }
8989 } else {
9090 return 0
0 commit comments