코딩테스트
-
[Leetcode] 242. Valid Anagram코딩테스트 2023. 1. 4. 17:16
문제 Given two strings s and t, return true if t is an anagram of s, and false otherwise. An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. (문자열 s과 t가 주어졌을 때, t가 s의 애너그램(anagram)이라면 참을 반환하고 아니라면 거짓을 반환하라. 여기서 애너그램이란 다른 단어나 어구의 글자들을 재배열해서 얻을 수 있는 단어나 어구를 의미한다. 단, 모든 글자를 정확히 한번 씩만 써야 한다.) 예시 및 제한 풀이 ..
-
[Leetcode] 20. Valid Parantheses코딩테스트 2023. 1. 4. 16:06
문제 Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Every close bracket has a corresponding open bracket of the same type. (, ), {, }, [, ] 만으로 이뤄진 문자열이 주어졌을 때, 다음 조건을 만족하면 true 만족하지 않으면 ..
-
[Leetcode] 217. Contains Duplicates코딩테스트 2022. 12. 19. 16:06
문제 Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.(주어진 정수 배열 nums가 적어도 두 번 이상 나타나는 값이 있으면 true, 원소 값이 유일하면 false를 반환하라) 예시 풀이 1 첫번째 방법은 단순하게 배열 내에서 2개의 원소로 만들 수 있는 모든 경우의 수를 따져보자. Example 1을 예시로 든다면 nums = [1,2,3,1]에서는 [[1,2], [1,3], [1,1], [2,3], [2,1], [3,1]]이 된다. 이중 루프를 통해 구현하면 아래와 같다. 하지만 n개에서 2개를 뽑는 열이..