파이썬 이중배열 5

[Python] 프로그래머스: 여행경로 (이중배열 정렬)

https://programmers.co.kr/learn/courses/30/lessons/43164 코딩테스트 연습 - 여행경로 [["ICN", "SFO"], ["ICN", "ATL"], ["SFO", "ATL"], ["ATL", "ICN"], ["ATL","SFO"]] ["ICN", "ATL", "ICN", "SFO", "ATL", "SFO"] programmers.co.kr Caution. 만약 A에서 시작해서 갈 수 있는 공항이 B와 C가 있다고 해보자. 여기까지만 봤을 때는 당연히 알파벳 앞 순서인 B공항으로 가야 하겠지만 B공항으로 갔을 때 그곳에서 갈 수 있는 다음 공항이 없다면 A에서 C로 갔어야 한다. 때문에 출발지가 동일한 티켓 중 도착지의 알파벳 순서가 앞이라고 해서 그 공항으로 무조..

알고리즘 2021.11.26

[Python] 리트코드 463. Island Perimeter

https://leetcode.com/problems/island-perimeter/ Island Perimeter - 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 grid = [[0,1,0,0], [1,1,1,0], [0,1,0,0], [1,1,0,0]] 그림처럼 1은 땅을 0은 물을 뜻한다. 이때 땅의 둘레를 구하는 문제 ==풀이== 1. 땅 두 칸이 붙어 있으면 겹치는 선이 한 개일 것이다. 2. 겹치는 것 생각하지 않고 각 네모의 둘레를 모두 구했을 때..

알고리즘 2021.10.19

[Python] 리트코드 695. Max Area of Island

https://leetcode.com/problems/max-area-of-island/ Max Area of Island - 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 이중 배열 grid에 저장된 값 중 0은 물을 의미하고 1은 섬을 의미 1이 위아래 양옆으로 붙어있다면 같은 섬 한 칸 = 이 섬의 면적 1이라고 할 때 가장 넓은 섬의 면적을 리턴 이중 배열을 for문으로 한 칸씩 확인해서 그곳이 땅이라면(값이 1이면) 해당 섬의 면적에 +1을 하고 그 위..

알고리즘 2021.10.18

[Python] 리트코드 1690. Stone Game VII

https://leetcode.com/problems/stone-game-vii/ Stone Game VII - 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 Alice와 Bob이 게임을 한다. 번갈아가며 첫 번째 혹은 마지막 돌무더기를 제거해서 남은 돌무더기 합계를 해당 턴의 점수로 가져간다. stones = [5,3,1,4,2]라면 Alice가 제일 오른쪽 2를 제거하고 5 + 3 + 1 + 4 = 13를 얻는다. 그다음 Bob은 stones = [5,3,1..

알고리즘 2021.10.18

[Python] 리트코드 807:Max Increase to Keep City Skyline (Greedy)

https://leetcode.com/problems/max-increase-to-keep-city-skyline/ Max Increase to Keep City Skyline - 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 도시의 skyline은 동서남북 각각의 방향에서 본 건물 외곽선이다. 이 skyline을 해치지 않는 선에서 건물 높이를 가능한 최대로 높인다고 할 때 추가할 수 있는 높이를 구하는 문제이다. 문제에서 제시한 예시를 살펴보자. grid =..

알고리즘 2021.08.27