File tree 1 file changed +20
-1
lines changed
contest/src/main/java/com/github/contest/hashTable
1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -305,11 +305,30 @@ fun minimumOperations(nums: IntArray): Int {
305
305
}
306
306
}
307
307
308
- return if (map.size > 0 ) operations + 1 else operations
308
+ return if (map.isNotEmpty() ) operations + 1 else operations
309
309
310
310
}
311
311
312
312
private fun MutableMap <Int , Int >.reduceOrRemove (key : Int ) {
313
313
this [key] = this .getOrDefault(key, 0 ) - 1
314
314
if (this .getOrDefault(key, 0 ) == 0 ) this .remove(key)
315
+ }
316
+
317
+ /* *
318
+ * 242. Valid Anagram
319
+ */
320
+
321
+ fun isAnagram (s : String , t : String ): Boolean {
322
+ if (s.length != t.length) return false
323
+ val first = IntArray (26 )
324
+ val second = IntArray (26 )
325
+
326
+ for (char in s) first[char - ' a' ]++
327
+ for (char in t) second[char - ' a' ]++
328
+
329
+ for (char in t) {
330
+ if (first[char - ' a' ] == 0 || first[char - ' a' ] != second[char - ' a' ]) return false
331
+ }
332
+
333
+ return true
315
334
}
You can’t perform that action at this time.
0 commit comments