File tree Expand file tree Collapse file tree 2 files changed +37
-5
lines changed
contest/src/main/java/com/github/contest Expand file tree Collapse file tree 2 files changed +37
-5
lines changed Original file line number Diff line number Diff line change 11package com.github.contest
22
33
4- import com.github.contest.bitManipulation.subsetXORSum
5- import com.github.contest.strings.shiftingLetters
6- import com.github.contest.strings.smallestStringProdVariant
7-
4+ import com.github.contest.strings.isNumber
85import java.util.TreeMap
96
107
@@ -14,7 +11,7 @@ import java.util.TreeMap
1411
1512fun main () {
1613
17- subsetXORSum(intArrayOf( 5 , 1 , 6 ))
14+ isNumber( " 6+1 " ). also { println (it) }
1815}
1916
2017fun testing () {
Original file line number Diff line number Diff line change @@ -117,4 +117,39 @@ class Trie() {
117117 return curr
118118 }
119119
120+ }
121+
122+ /* *
123+ * 981. Time Based Key-Value Store
124+ */
125+
126+ class TimeMap () {
127+
128+ private val store = mutableMapOf<String , MutableList <Pair <Int , String >>>()
129+
130+ fun set (key : String , value : String , timestamp : Int ) {
131+ store.getOrPut(key) { mutableListOf (Pair (timestamp, value)) }.add(Pair (timestamp, value))
132+ }
133+
134+ fun get (key : String , timestamp : Int ): String {
135+ val list = store[key] ? : return emptyString()
136+ var left = 0
137+ var right = list.size - 1
138+ var res = emptyString()
139+
140+ while (left <= right) {
141+ val mid = (left + right) / 2
142+ val (currentTimeStamp, currentValue) = list[mid]
143+ if (currentTimeStamp == timestamp) return currentValue
144+ if (currentTimeStamp < timestamp) {
145+ left = mid + 1
146+ res = currentValue
147+ } else right = mid
148+ }
149+
150+ return res
151+ }
152+
153+ private fun emptyString () = " "
154+
120155}
You can’t perform that action at this time.
0 commit comments