CodeingTestPrac/neetCode.io 정주행
-
Two Pointers : while 문으로 맛있게 풀기CodeingTestPrac/neetCode.io 정주행 2023. 8. 15. 21:55
문제의 유형을 two pointers 라고 주어졌다 . 이것은 이중 반복문을 사용하여 , n! 로 접근을 하는 방식이 아니라 , 하나의 탐색의 과정에서 두개 이상의 접근자 :index 를 조건에 맞추어 증감을 시키는 것이 포인트 이다 Two pointer 의 기본 문제 유형을 먼저 보자. 125. Valid Palindrome Valid Palindrome - LeetCode Can you solve this real interview question? Valid Palindrome - A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeri..
-
Arrays & Hashing (2)CodeingTestPrac/neetCode.io 정주행 2023. 8. 9. 16:15
238. Product of Array Except Self nums = [1,2,3,4] 일 때 , 각 리스트에 원소에 자기 자신을 제외한 값의 곲을 넣어야 한다. class Solution { public int[] productExceptSelf(int[] nums) { int n = nums.length ; List index = new ArrayList(); int pro = 1 ; for(int i = 0 ; i 1) { return new int[n] ; } if(index.size() == 1) { Arrays.f..
-
Arrays & Hashing (1)CodeingTestPrac/neetCode.io 정주행 2023. 8. 8. 18:07
217. Contains Duplicate : 같은 숫자가 존재하나 ? import java.util.* ; class Solution { public boolean containsDuplicate(int[] nums) { int size = Arrays.stream(nums). distinct(). boxed(). collect(Collectors.toList()).size(); return size != nums.length; } } -> HashSet 또는 map 을 사용하여 o(N ) 으로 접근 하는 풀이도 가능 242. Valid Anagram 주어진 문자열이 재구성 가능 한지 확인 하는 코드 , 두개의 문자를 비교하는것은 Char arr 이후 arrays. 의 api 를 이용한 풀이를 생각하자..