g0901_1000.s0929_unique_email_addresses.Solution.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-kotlin Show documentation
Show all versions of leetcode-in-kotlin Show documentation
Kotlin-based LeetCode algorithm problem solutions, regularly updated
package g0901_1000.s0929_unique_email_addresses
// #Easy #Array #String #Hash_Table #2023_04_26_Time_207_ms_(89.29%)_Space_37.1_MB_(82.14%)
class Solution {
fun numUniqueEmails(emails: Array): Int {
val set: MutableSet = HashSet()
for (s in emails) {
val sb = StringBuilder()
var i = 0
while (i < s.length) {
val c = s[i]
if (c == '+' || c == '@') {
sb.append('@')
i = s.indexOf("@") + 1
sb.append(s.substring(i))
break
} else if (c != '.') {
sb.append(c)
}
i++
}
set.add(sb.toString())
}
return set.size
}
}