Algorithm Study 70

[leetcode] 78. Subsets (medium)

https://leetcode.com/problems/subsets/ Subsets - 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 재귀(dfs)를 통해 모든 경우의 수를 조합하는 문제였다. 다만, 일반적인 프로그래머스나 백준과 다르게 공집합을 포함하여서 풀어야한다는 점. list.add(new ArrayList()); 그리고 반환문에서 list에 값을 더해줄때도 list.add(new ArrayList(ans)); - 그 이유는 이미 있는값에 더해질때, 덮어..

Algorithm Study 2022.09.13

[leetcode] Array- Merge Sorted Array

https://leetcode.com/explore/learn/card/fun-with-arrays/525/inserting-items-into-an-array/3253/ Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com 나.. 영어가 딸리는 것 같다 ㅎ.. 0을 제외한 m,n 의 숫자만큼의 배열값들을 가져오는 것으로 이해하고 풀었었는데 , 그런내용이 아..

Algorithm Study 2022.09.11

[leetcode] Array - Duplicate ZerosSolution

https://leetcode.com/explore/learn/card/fun-with-arrays/525/inserting-items-into-an-array/3245/ Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com 배열의 값이 0 이면, 그다음 인덱스도 0으로 넣고 배열을 오른쪽 밀어넣는 문제. for문으로 풀다보니, 검사한 idx인지 확인이 필요..

Algorithm Study 2022.09.11

[leetcode] Array- Find Numbers with Even Number of Digits

https://leetcode.com/explore/learn/card/fun-with-arrays/521/introduction/3237/ Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com even number : 짝수 / odd number : 홀수 배열 값 길이가 짝수인 갯수를 리턴하는 문제. ex. 12 -> 2자리 숫자. 2는 짝수

Algorithm Study 2022.09.10

[프로그래머스] 오픈채팅방(level.2) / Java, HashMap

https://school.programmers.co.kr/learn/courses/30/lessons/42888?language=java 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 뭔가 문제는 글이 많아서 되게 읽기 싫게 생겼는데 막상 풀어보니 은근 간단한 문제였다. 30분걸렸고 맞췄다! (잘하는사람은 진짜 바로풀듯.. !) 풀이방법 1. 아이디와 닉네임을 저장할 HashMap - 아이디와 닉네임이 바뀔수 있는 경우는 Enter 명령어 이거나, Change 명령어를 사용했을 경우이다. - Enter이거나 Change인 경우, HashMap에 Name..

Algorithm Study 2022.08.20

[프로그래머스] 메뉴 리뉴얼(level.2) / JAVA, HashMap

https://school.programmers.co.kr/learn/courses/30/lessons/72411?language=java 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이 방식 Step1 . course의 사이즈만큼에 맞는 모든 조합의 배열을 찾는다. 모두 찾은 배열을 Map 의 Key 값에 넣고, 나온 숫자만큼은 value 값에 넣는다. 이 때, map.getOrDefulat 가 필요하다. (값이 없으면 0, 값이 있으면 +1. 해주기 위해서) Step2. 최대값 max를 찾아주고, map의 key가 max 값이자 2 이상인 경우 결..

Algorithm Study 2022.07.23

[프로그래머스] 양궁대회(level2) / JAVA, DFS

https://school.programmers.co.kr/learn/courses/30/lessons/92342 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내가 푼 방식 STEP1 . 10점부터 0점까지 라이언은 이길건지/ 질건지 모든순열의 조합을 구해야 한다. - 이길 경우: 어피치점수+1 - 질 경우: 0 점 (조건은, 양궁의 갯수를 확인하면서 점수를 메겨야 한다.) -> 우선 이부분은 DFS 로 푸는 방식이다. STEP2. 모든 경의 수를 다 구했다면, 어피치와 라이언의 점수차이를 구한다. - 어피치와 라이언의 점수가 같다면 어피치가 이긴다. ..

Algorithm Study 2022.07.23

아이템18. 상속보다는 컴포지션을 사용하라

아이템18. 상속보다는 컴포지션을 사용하라 상속은 코드를 재사용하는 강력한 수단이지만, 항상 최선은 아니다. 같은 프로그래머가 통제하는 패키지 안에서라면 상속도 안전한 방법이지만, 다른 패키지의 구체클래스 를 상속하는 일은 위험하다. 이 책에서 '상속'은 클래스가 다르 클래스를 확장하는 구현상속을 말한다. 상속이 위험한 이유 메서드 호출과 달리 상속은 캡슐화를 깨뜨린다. 상위클래스가 어떻게 구현되느냐에 따라 하위클래스의 동작에 이상이 생길 수 있다. 다음 릴리스에서 상위클래스에 새로운 메서드를 추가한다면? ex. 컬렉션에 추가된 모든 원소가 특정조건을 만족해야만 하는 프로그램 그 컬렉션을 상속하여 원소를 추가하는 모든 메서드를 재정의해 필요한 조건을 검사한다. 하지만, 상위클래스에 또 다른 원소 추가 메..

Algorithm Study 2022.06.24