File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed
contest/src/main/java/com/github/contest/hashTable Expand file tree Collapse file tree 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 {
305305 }
306306 }
307307
308- return if (map.size > 0 ) operations + 1 else operations
308+ return if (map.isNotEmpty() ) operations + 1 else operations
309309
310310}
311311
312312private fun MutableMap <Int , Int >.reduceOrRemove (key : Int ) {
313313 this [key] = this .getOrDefault(key, 0 ) - 1
314314 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
315334}
You can’t perform that action at this time.
0 commit comments