반응형
https://leetcode.com/problems/regular-expression-matching/
Regular Expression Matching - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
class Solution {
fun isMatch(s: String, p: String): Boolean {
if (p.isEmpty()) {
return s.isEmpty()
}
val isFirstMatch = s.isNotEmpty() && listOf(s.first(), '.').contains(p.first())
return if (p.length >= 2 && p[1] == '*') {
isMatch(s, p.substring(2, p.length)) ||
isFirstMatch && isMatch(s.substring(1, s.length), p)
} else {
isFirstMatch && isMatch(s.substring(1, s.length), p.substring(1, p.length))
}
}
}
https://github.com/960813/leetcode-problems/commit/874f10fb6d3d980d01c487e1b274b49e3f0ee523
[10] Kotlin · 960813/leetcode-problems@874f10f
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
github.com
반응형
☕️ Networking
기술 직군의 기술적인 교류, 커리어 이야기, 직군 무관 네트워킹 모두 환영합니다!
위클리 아카데미 오픈 채팅방(비밀번호: 9323)
kakaotalk: https://open.kakao.com/o/gyvuT5Yd