개발공부/LeetCode

    [Kotlin]String에 특수문자 제거, 띄어쓰기 제거(스페이스 제거), String 거꾸로 뒤집기, 소문자로변환 LeetCode :Valid PalindromeSolution

    [Kotlin]String에 특수문자 제거, 띄어쓰기 제거(스페이스 제거), String 거꾸로 뒤집기, 소문자로변환 LeetCode :Valid PalindromeSolution

    문제 Given a string s, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. s 가 palindrome(앞으로 읽어도 거꾸로 읽어도 같은 문자)인지 확인하는 문제입니다. 알파벳만 허용하고 특수문자는 모두 제거해줘야합니다. 예시 풀이 우선 예시 1로 예를 들어보자면 A man, a plan, a canal: Panama 에서 특수기호와 대문자들을 소문자로 모두 바꿔주고 스페이스를 제거해주면 뒤로 읽으나 앞으로 읽으나 같은걸 볼수있습니다. 저희가 string에 적용해줄 4가지입니다. 1. 특수문자 제거(regex활용) 2. 대문자 소문자로 변환(tolowercase) 3. 공백 제..

    [Kotlin] map, hashmap 같은지 비교하기 LeetCode: Valid Anagram

    [Kotlin] map, hashmap 같은지 비교하기 LeetCode: Valid Anagram

    문제 Given two strings s and t, return true if t is an anagram of s, and false otherwise. s와 t string의 char들이 순서만 바뀐거라면 true 아니면 false 예시 s = anagram과 t = nagaram을 넣었을때 true인 이유는, s t a 3 3 n 1 1 g 1 1 r 1 1 m 1 1 각 char들의 갯수가 똑같으면 위치만 바뀐것이기때문에 true 이번 문제에서는 s와 t를 각각 hashmap으로 만들어서 두 hashmap이 가지고있는 key값과 value값이 같으면 true를 반환하여 문제를 풀어보겠습니다. 풀이 class Solution { fun isAnagram(s: String, t: String): B..

    [Kotlin] String에서 반복되지않은 char찾기 - LeetCode: First Unique Character in a String

    [Kotlin] String에서 반복되지않은 char찾기 - LeetCode: First Unique Character in a String

    문제 Given a string s, return the first non-repeating character in it and return its index. If it does not exist, return -1. 반복되는않은 char의 위치를 Int값으로 리턴해야합니다. 만약 반복되는 char들만있다면 -1을 리턴합니다. 반복되는않은 char이 여러개라면 가장 먼저나온 char의 위치를 리턴합니다. 예시 풀이 이문제에서는 hashmap을 활용하겠습니다. 위와같이 input값인 s의 문자하나하나 for loop로 빈 hashmap에 key value로 들어갑니다. hashmap에 key 값으로 문자들이 들어가고 value로 string에 들어있는 key 값의 문자 갯수가 들어갑니다. map의 특징으..

    [Kotlin]  LeetCode: PlusOne 쉬운 풀이 해설

    [Kotlin] LeetCode: PlusOne 쉬운 풀이 해설

    문제 Given a non-empty array of decimal digits representing a non-negative integer, increment one to the integer. The digits are stored such that the most significant digit is at the head of the list, and each element in the array contains a single digit. You may assume the integer does not contain any leading zero, except the number 0 itself. array안에는 음의 정수가 없고 각 array의 숫자들은 digit을 나타냅니다. 맨앞자리에는 ..