๐Ÿ’ป Coding/[Algorithm]Python

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค | ๋ฐ”ํƒ•ํ™”๋ฉด ์ •๋ฆฌ โญ - Python

๐Ÿฉท ๋ฏผ์˜ 2024. 4. 6. 02:01

๐Ÿ—’๏ธ ๋ฌธ์ œ

https://school.programmers.co.kr/learn/courses/30/lessons/161990

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

 

๐Ÿ’ก์•„์ด๋””์–ด

1. ๋ฐ”ํƒ•ํ™”๋ฉด์— ํŒŒ์ผ์ด ์žˆ๋Š” ์ขŒํ‘œ๋ฅผ ๋‹ด์„ ๋ฆฌ์ŠคํŠธ

2. ๋ฐ˜๋ณต๋ฌธ์„ ํ†ตํ•ด ํŒŒ์ผ์ด ์žˆ์„ ๊ฒฝ์šฐ(#) ์ขŒํ‘œ ๋‹ด๊ธฐ

 

**

3.  ์ตœ์†Œ๊ฐ’ => ๋“œ๋ž˜๊ทธ์˜ ์‹œ์ž‘์ 

4. ์ตœ๋Œ€๊ฐ’ => ๋“œ๋ž˜๊ทธ ๋๋‚˜๋Š” ์ 

 

โœ๏ธ๋‚ด์ฝ”๋“œ

def solution(wallpaper):
    # ๋ฐ”ํƒ•ํ™”๋ฉด์˜ ํ–‰,์—ด ์ขŒํ‘œ๋ฅผ ๋‹ด์„ ๋ฆฌ์ŠคํŠธ
    row = []
    col = []
    
    for i in range(len(wallpaper)):
        for j in range(len(wallpaper[i])):
            # ํŒŒ์ผ์ด ์žˆ์„ ๊ฒฝ์šฐ(#) ํ–‰,์—ด ์ขŒํ‘œ ๋‹ด์•„์ฃผ๊ธฐ
            if wallpaper[i][j] == "#":
                row.append(i)
                col.append(j)
    # ์ตœ์†Œ๊ฐ’ => ๋“œ๋ž˜๊ทธ์˜ ์‹œ์ž‘์ 
    # ์ตœ๋Œ€๊ฐ’ => ๋“œ๋ž˜๊ทธ์˜ ๋๋‚˜๋Š” ์ 
    answer = [min(row), min(col), max(row) + 1, max(col) + 1]
    return answer

 

๐Ÿ˜Š ์˜ค๋Š˜์˜ ํ›„๊ธฐ

๋ฌธ์ œ๊ฐ€ ์ •๋ง,,,์ •๋ง ๊ท€์ฐฎ์•˜๋‹ค!! ๊ทธ๋ž˜๋„ ์ฐจ๊ทผ์ฐจ๊ทผ ์†์œผ๋กœ ๊ทธ๋ฆผ์„ ๊ทธ๋ ค๋ณด๋ฉด ์‰ฝ๊ณ  ๊ฐ„๋‹จํ•œ ๋ฌธ์ œ์˜€๋‹ค.

์˜ค๋Š˜ ๋˜ ์ƒˆ์‚ผ ,,, ๋Œ์•„๊ฐ€๋Š” ์ผ์ด ๊ฐ€์žฅ ๋น ๋ฅด๋‹ค๋Š” ์‚ฌ์‹ค์„ ๊นจ๋‹ซ๊ฒŒ ๋˜์—ˆ๋‹ค zz 

(๊ทธ๋ฆผ๊ทธ๋ฆฌ๊ธฐ ๊ท€์ฐฎ์•„์„œ ์ƒ๊ฐํ•˜๋‹ค๊ฐ€ ์—์ž‡! ํ•˜๊ณ  ๊ทธ๋ฆผ๊ทธ๋ฆฌ๊ณ  ๋น ๋ฅด๊ฒŒ ์ดํ•ดํ–ˆ๊ธฐ ๋•Œ๋ฌธ์—,,,๐Ÿคฃ๐Ÿคฃ)