๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ“– Problem Solution

Edabit Very Easy Swift

by Fomagran ๐Ÿ’ป 2020. 1. 17.
728x90
๋ฐ˜์‘ํ˜•

1. String์ด ๋ชจ๋‘ ๋Œ€๋ฌธ์ž๊ฑฐ๋‚˜ ๋ชจ๋‘ ์†Œ๋ฌธ์ž์ธ ๊ฒฝ์šฐ์— true๋ฅผ ์ถœ๋ ฅํ•˜๊ณ  ์•„๋‹ˆ๋ฉด false๋ฅผ ์ถœ๋ ฅํ•ด

ํ•ต์‹ฌ uppercased()์™€ lowercased()๋ฅผ ์•„๋‹ˆ? - ๋‚ด ์ƒ๊ฐ์—” isuppercased? ์ด๋Ÿฐ ๋ฉ”์†Œ๋“œ๋กœ ํ•ด์•ผํ•˜๋Š” ์ค„ ์•Œ๊ณ  ์ฐพ์•˜๋Š”๋ฐ ์•Œ๊ณ ๋ณด๋‹ˆ ๊ฑ ๋ชจ๋‘ ๋Œ€์†Œ๋ฌธ์ž๋กœ ๋ฐ”๊พผ ๊ฒƒ๊ณผ str์„ ๋น„๊ตํ•ด์„œ ๋˜‘๊ฐ™์œผ๋ฉด true ์•„๋‹ˆ๋ฉด false๋ฅผ ์ถœ๋ ฅํ•˜๋ฉด ๋๋‹ค.

func sameCase(_ str: String) -> Bool {
	return str.uppercased() == str || str.lowercased() == str
}

2.1์—์„œ ํ•จ์ˆ˜์— ์ „๋‹ฌํ•œ ์ˆซ์ž๊นŒ์ง€ ๋ชจ๋“  ์ˆซ์ž๋ฅผ ๋”ํ•˜์‹ญ์‹œ์˜ค.

ํ•ต์‹ฌ for๋ฌธ ์‚ฌ์šฉํ•  ์ค„ ์•„๋‹ˆ?

func addUp(_ num: Int) -> Int {
	var total = 0
	for i in 1...num{
		total = total+i
	}
	return total
}

3.๋ฐฐ์—ด ์•ˆ์— ๋ฐฐ์—ด๋“ค ์† ์ˆซ์ž ์ค‘ val์ด๋ผ๋Š” ์ˆซ์ž๋ฅผ ๋ชจ๋‘ ํฌํ•จํ•˜๋Š”๊ฐ€? - isOmnipresent๋ผ๊ณ  ํ•˜๋‚˜๋ณด๋‹ค.

ํ•ต์‹ฌ:contains ์•„๋‹ˆ?

func isOmnipresent(_ arr: [[Int]], _ val: Int) -> Bool {
	var bool = true
for i in 0...arr.count-1{
    if arr[i].contains(val) == false{
        bool = false
    }
    }
	return bool
}

 

728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€