[Coding test] 14. Math

whitehousechef·2025년 6월 25일

diff between / and //

// gives an integer value while / gives a float.

easy way to memorise is that double slash (//) cuts the original float result even more to an integer.

/ ok its float
// oh slash 1 more time? it cuts off the decimal place and becomes int.

7 / 2 = 3.5
-7 / 2 = -3.5

// (Floor Division): Returns an integer. It divides and then "floors" the result, meaning it rounds down to the nearest integer.

7 // 2 = 3 (floor of 3.5 is 3)
-7 // 2 = -4 (floor of -3.5 is -4, not -3! This is crucial for negative numbers)

U have to know the diff, especially in bisect and bisect left conditions

https://velog.io/@whitehousechef/Leetcode-2040.-Kth-Smallest-Product-of-Two-Sorted-Arrays

math.ceil()

takes a float and rounds up. So instead of math.ceil(a//b) which the value inside bracket will be an int, we should do math.ceil(a/b) to properly get a float so that we round up

https://velog.io/@whitehousechef/%EB%B0%B1%EC%A4%80-1911%EB%B2%88-%ED%9D%99%EA%B8%B8-%EB%B3%B4%EC%88%98%ED%95%98%EA%B8%B0

0개의 댓글