Skip to Content
똑똑한 코드 작성을 위한 실전 알고리즘
book

똑똑한 코드 작성을 위한 실전 알고리즘

by 조지 하이네만, 윤대석
May 2022
Beginner to intermediate
296 pages
5h 54m
Korean
Hanbit Media, Inc.
Content preview from 똑똑한 코드 작성을 위한 실전 알고리즘
24
똑똑한 코드 작성을 위한 실전 알고리즘
그림
1-2
flawed
()
실행의 시각화
이 구현은
A
0
보다 큰 수가 적어도 한 개 있다고 가정하므로 결함이 있다.
flawed
([-
5
,
-
3
, -
11
])
을 수행하면 잘못된 값인
0
을 반환한다. 자주 사용하는 해결책은
my
_
max
float
('-
inf
')
와 같이 가능한 가장 작은 값으로 초기화하는 것이다. 그런데 이 접근은
A
가 빈 리스
트인 경우에도 가장 작은 값으로 설정된 값을 반환하므로 여전히 결함이 있다. 이제 이 결함을
수정해보자.
TIP
파이썬에서
range
(
x
,
y
)
문은
x
에서
y
까지
1
씩 커지는 정수를 생성하되
y
는 포함하지 않는다. 또한
range
(
x
,
y
, -
1
)
x
에서
y
까지
1
씩 작아지는 정수를 생성하되, 마찬가지로
y
는 포함하지 않는다. 따라서
list
(
range
(
1
,
7
))
[
1
,
2
,
3
,
4
,
5
,
6
]
을,
list
(
range
(
5
,
0
,-
1
))
[
5
,
4
,
3
,
2
,
1
]
을 생성한다.
list
(
range
(
1
,
10
,
2
))
와 같이 값들 간의 차이를
2
로 주어
[
1
,
3
,
5
,
7
,
9
]
를 생성할 수도 있다.
1.3
주요 연산 횟수 계산하기
이제 수정된 코드를 보자. 가장 큰 값은 실제로 반드시
A
에 포함되어 있으므로 [코드
1
-
2
]에서
수정된
largest
()
함수는
may
_
max
값으로
A
의 첫 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

데이터 익명화를 위한 파이프라인

데이터 익명화를 위한 파이프라인

루크 아버클, 칼리드 엘 에맘
개발 7년차, 매니저 1일차

개발 7년차, 매니저 1일차

권원상, 한민주, 카미유 푸르니에

Publisher Resources

ISBN: 9791162245644