Skip to content

๐Ÿ’ฏ For practicing in solving algorithm ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป

Notifications You must be signed in to change notification settings

GimunLee/algorithm-practice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

algorithm_practice

๋ฌธ์ œ ํ’€์ด๋ฅผ ํ†ตํ•ด ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ํ•™์Šตํ•˜๋Š” ์ €์žฅ์†Œ์ž…๋‹ˆ๋‹ค.

์•Œ๊ณ ๋ฆฌ์ฆ˜ ์‚ฌ์ดํŠธ

๊ฐ„๋‹จํ•˜์ง€๋งŒ ์•Œ๋ฉด ์ข‹์€ ์ตœ์ ํ™”

for๋ฌธ์˜ ++i ์™€ i++ ์ฐจ์ด

for(int i = 0; i < 1000; i++){}

for(int i = 0; i < 1000; ++i){}

๋‚ด๋ถ€ operator ๋กœ์ง์„ ๋ณด๋ฉด i++์€ ํ•œ๋ฒˆ๋” ์—ฐ์‚ฐ์„ ๊ฑฐ์นฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ++i ๊ฐ€ ๋ฏธ์„ธํ•˜๊ฒŒ ์กฐ๊ธˆ ๋” ๋น ๋ฆ…๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์š”์ฆ˜ ์ปดํŒŒ์ผ๋Ÿฌ๋Š” ๊ฑฐ์˜ ์ฐจ์ด๊ฐ€ ์—†์–ด์ง€๊ฒŒ ๋์Šต๋‹ˆ๋‹ค.

if/else if ์™€ switch case ์ฐจ์ด

20๊ฐœ์˜ ๊ฐ€์ง€ ์ˆ˜, 10์–ต๋ฒˆ์˜ ์—ฐ์‚ฐ์ผ๋•Œ -> if/else : ์•ฝ 20์ดˆ / switch : ์•ฝ 15์ดˆ

๊ฒฝ์šฐ๋ฅผ ์ฐพ์•„์„œ ์ ‘๊ทผํ•˜๊ธฐ ๋•Œ๋ฌธ์— switch case๊ฐ€ ๋” ๋น ๋ฆ…๋‹ˆ๋‹ค. if-else ๊ฐ™์€ ๊ฒฝ์šฐ๋Š” ๋‹ค ํƒ€๊ณ  ๋“ค์–ด๊ฐ€์•ผํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋” ๋Š๋ฆฝ๋‹ˆ๋‹ค.

์ž„์‹œ ๋ณ€์ˆ˜์˜ ์„ ์–ธ ์œ„์น˜ (for๋ฌธ ์•ˆ์—์„œ ๋ณ€์ˆ˜ ์„ ์–ธ vs for๋ฌธ ๋ฐ–์—์„œ ๋ณ€์ˆ˜ ์„ ์–ธ)

for๋ฌธ ๋ฐ–์—์„œ ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๋Š” ๊ฒƒ์ด ๋” ๋น ๋ฆ…๋‹ˆ๋‹ค.

์žฌ๊ท€ํ•จ์ˆ˜์˜ ํŒŒ๋ผ๋ฏธํ„ฐ (์ „์—ญ์œผ๋กœ ์„ ์–ธํ•˜๊ธฐ vs ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋„˜๊ฒจ์ฃผ๊ธฐ)

10์–ต๋ฒˆ์˜ ์—ฐ์‚ฐ์„ ํ–ˆ์„ ๋•Œ ์ „์—ญ์œผ๋กœ ์„ ์–ธ : ์•ฝ 6.8์ดˆ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋„˜๊ฒจ์ค€ ๊ฒƒ : ์•ฝ 9.6์ดˆ

ํ•จ์ˆ˜๋ฅผ ๊ณ„์†ํ•ด์„œ ํ˜ธ์ถœํ•  ๋•Œ, ์Šคํƒ์—์„œ ์Œ“์ž„. ํŒŒ๋ผ๋ฏธํ„ฐ๋“ค์€ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ๋งˆ๋‹ค ๋ฉ”๋ชจ๋ฆฌ ํ• ๋‹นํ•˜๋Š” ๋™์ž‘์„ ๋ฐ˜๋ณตํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์ง€์—ญ ๋ณ€์ˆ˜๋กœ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๊ฒƒ๋“ค์€ ์ „์—ญ ๋ณ€์ˆ˜๋กœ ๋นผ์•ผํ•ฉ๋‹ˆ๋‹ค. BFS์—์„œ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ๋Š˜๋ ค๊ฐ€๋Š” ๊ฒƒ๋ณด๋‹ค ์ „์—ญ์œผ๋กœ ์„ ์–ธ ํ›„ ํ™œ์šฉํ•˜๋Š” ๊ฒƒ์ด ํ›จ์”ฌ ์‹œ๊ฐ„ ๋‹จ์ถ•ํ•  ์ˆ˜ ์žˆ๋Š” ์Šต๊ด€์„ ๊ธฐ๋ฅผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

2์ฐจ์› ๋ฐฐ์—ด์„ ํ•œ๋ฒˆ์— ๋‚ด๋ฆด ๋•Œ ์ข‹์€ ์†Œ์Šค(๋ฒฝ๋Œ๊นจ๊ธฐ ๊ฐ™์€ ๋ฌธ์ œ์—์„œ ์ข‹์Œ)

static void down() {
    for (int j = 0; j < W; j++) {
        int ti = H; // ์ด๋™ํ•ด์•ผํ•  ์œ„์น˜
        for (int i = H - 1; i >= 0; i--) {
            if (map[i][j] != 0) {
                ti--;
                map[ti][j] = map[i][j];
                if (i != ti)
                    map[i][j] = 0;
            }
        }
    }
}

Reference & Additional Resources

About

๐Ÿ’ฏ For practicing in solving algorithm ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages