Code Monkey home page Code Monkey logo

080337's Introduction

<프로그래머스 코딩 테스트 문제 풀이 전략: 자바편> 도서의 문제 리스트와 예제 코드입니다.

(길벗, 2023)

79개 문제 리스트

  • 문제 링크에 접속하면 코드를 제출하고 채점할 수 있습니다.
    (프로그래머스 사이트(https://programmers.co.kr/ )에 가입해야 합니다.
    구글 계정 등으로 손쉽게 가입 가능합니다.)

3장. 배열

1. 교점에 별 만들기 - Level 2
2. 삼각 달팽이 - Level 2
3. 거리두기 확인하기 - Level 2
4. 행렬의 곱셈 - Level 2

4장. 문자열

5. 자연수 뒤집어 배열로 만들기 – Level 1
6. 시저 암호 - Level 1
7. 이상한 문자 만들기 – Level 1
8. 문자열 압축 – Level 2
9. 3진법 뒤집기 - Level 1
10. 이진 변환 반복하기 - Level 2
11. 문자열 내 p와 y의 개수 - Level 1
12. 숫자 문자열과 영단어 - Level 1
13. 문자열 다루기 기본 - Level 1
14. 신규 아이디 추천 - Level 1

5장. 재귀

15. 쿼드압축 후 개수 세기 - Level 2
16. 하노이의 탑 - Level 3
17. 모음 사전 - Level 2

6장. 완전 탐색

18. 모의고사 – Level 1
19. 카펫 – Level 2
20. 수식 최대화 - Level 2
21. 소수 찾기 – Level 2
22. 불량 사용자 - Level 3

7장. 정렬

23. K번째 수 – Level 1
24. 두 개 뽑아서 더하기 - Level 1
25. H-index - Level 2
26. 문자열 내림차순으로 배치하기 – Level 1
7. 문자열 내 마음대로 정렬하기 - Level 1
28. 가장 큰 수 - Level 2
29. 메뉴 리뉴얼 - Level 2

8장. 이진 탐색

30. 순위 검색 - Level 2
31. 입국심사 - Level 3
32. 징검다리 - Level 4

9장. 해시

33. 평행 - Level 0
'33번 문제 교체 - 평행 문제의 테스트 케이스가 교체되어 해시로 풀 수 없어 문제를 교체합니다. - 문제 풀이는 길벗출판사 홈페이지에서 도서 검색 후 자료실의 '정오표' 볼 수 있습니다.'
교체된 33. 전화번호 목록 - Level 2

34. 중복된 문자 제거 - Level 0
35. A로 B 만들기
36. 없는 숫자 더하기 - Level 1
37. 완주하지 못한 선수 - Level 1

10장. 동적 프로그래밍

38. 피보나치 수 - Level 2
39. 정수 삼각형 - Level 3
40. 등굣길 - Level 3
41. 사칙연산 - Level 4

11장. 자주 등장하는 자료 구조

42. 올바른 괄호 - Level 2
43. 괄호 회전하기 - Level 2
44. 주식 가격 - Level 2
45. 기능 개발 - Level 2
46. 다리를 지나는 트럭 - Level 2
47. 순위 - Level 3
48. 방의 개수 - Level 5
49. 길 찾기 게임 - Level 3
50. 이중 우선순위 큐 - Level 3
51. 디스크 컨트롤러 - Level 3
52. 보석 쇼핑 - Level 3
53. 섬 연결하기 - Level. 3
54. 호텔 방 배정 - Level 4
55. 가사 검색 - Level 4

12장. 구현

56. 스킬트리 - Level 2
57. 키패드 누르기 - Level 1
58. 타겟 넘버 - Level 2
59. 네트워크 - Level 3
60. 단어 변환 - Level 3
61. 게임 맵 최단거리 - Level 3
62. 체육복 - Level 1
63. 큰 수 만들기 - Level 2
64. 단속카메라 - Level 3

13장. 도전: 카카오 2022 블라인드 테스트

65. 신고 결과 받기 - Level 1
66. k진수에서 소수 개수 구하기 - Level 2
67. 주차 요금 계산 - Level 2
68. 양궁대회 - Level 2
69. 양과 늑대 - Level 3
70. 파괴되지 않은 건물 - Level 3
71. 사라지는 발판 - Level 3

14장. 코딩 전문 역량 인증 시험, PCCP 모의고사

72. 외톨이 알파벳 - Level 1
73. 체육대회 - Level 2
74. 유전법칙 - Level 2
75. 운영체제 - Level 3
76. 실습용 로봇 - Level 1
77. 신입사원 교육 - Level 2
78. 카페 확장 - Level 2
79. 보물 지도 - Level 3

080337's People

Contributors

cubedr avatar gilbutitbook avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

080337's Issues

[9장 평행 문제] 테스트케이스 실패

기존 소스코드

import java.util.HashSet;
import java.util.Set;

public class Solution {
    public double getSlope(int x1, int y1, int x2, int y2) {
        return (double) (y2 - y1) / (x2 - x1);
    }

    public int solution(int[][] dots) {
        Set<Double> slopes = new HashSet<>();
        for (int i = 0; i < dots.length; i++) {
            for (int j = i + 1; j < dots.length; j++) {
                double slope = getSlope(dots[i][0], dots[i][1],
                        dots[j][0], dots[j][1]);
                if (slopes.contains(slope)) {
                    return 1;
                }
                slopes.add(slope);
            }
        }
        return 0;
    }
}

상황

책 출판 이후 테스트케이스가 수정되어 해당 코드로 제출시 일부 테스트 케이스에 대해 틀리게 되었습니다.
image

원인

각 좌표를 [a, b, c, d]로 대응했을 때
해당 코드는 아래의 6가지 경우에 대해 하나라도 기울기가 같다면 1를 반환하고 종료됩니다.
그러나 해당 경우에 한 점이 두 번 사용되는 등 논리적 오류가 있을 수 있습니다.
ex) [a, b]의 기울기와 [a, c]의 기울기가 같다면? 종료되는데, 점 d는 혼자 쓸쓸하게... 😢

[a, b]
[a, c]
[a, d]
[b, c]
[b, d]
[c, d] 

해당 문제에서 요구하는 가지 수는 실제로는 3가지 입니다.

[a, b] 를 고르면 [c, d]와 만 기울기 비교 <-> [c, d]를 고르면 [a, b]와 기울기 비교;
[a, c] 를 고르면 [b, d]와 만 기울기 비교 <->[b, d]를 고르면 [a, c]와 기울기 비교 
[a, d] 를 고르면 [b, c]와 만 기울기 비교 <->  [b, c]를 고르면 [a, d]와 기울기 비교

예를 들어 [[1, 2], [3, 4], [5, 6], [99, 50]] 이 있다고 할 때

[[1, 2], [3,4]] 기울기 : 1 <-> [[5, 6], [99,50]] 기울기 22/47   -> F
[[1, 2], [5, 6]] 기울기 : 1 <-> [[3, 4], [99, 50]] 기울기 23/48 -> F
[[1, 2], [99, 50]] 기울기 : 24/49 <-> [[3, 4], [5, 6]] 기울기 1 -> F

로 0을 반환해야하지만

현재 코드의 로직에서는

[1, 2], [3, 4] 기울기 1
[1, 2], [5, 6] 기울기 1  

바로 종료되게 됩니다.
그러나 주어진 문제 상황에서 두 점 [1, 2], [3, 4]를 잇고 [5, 6]에도 이으면 모두 한 평행선에 있긴 하지만
점[1, 2]를 두번이나 사용해서 존재할 수 없는 경우입니다. [1, 2], [3, 4] <-> [1, 2], [5, 6] X

[3장 배열] 삼각 달팽이 코드 오류

숫자가 모두 채워진 triangle 을 기반으로 1차원 배열에 옮길 때
triangle[i][j] 의 값이 0이 아닌지 체크 하지 않아 초기 선언한 result 배열의 사이즈보다 큰 index 값을 할당하려고 하여
out of bounds 오류가 발생합니다.
코드 위치 : https://github.com/gilbutITbook/080337/blob/main/3%EC%9E%A5/%EC%82%BC%EA%B0%81_%EB%8B%AC%ED%8C%BD%EC%9D%B4.java#L43

따라서 아래와 같이 if 문을 추가해야 할 것 같습니다.
if (triangle[i][j] != 0) { result[index++] = triangle[i][j]; }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.