1618. Maximum Font to Fit a Sentence in a Screen
https://leetcode.com/problems/maximum-font-to-fit-a-sentence-in-a-screen
Description
You are given a string text
. We want to display text
on a screen of width w
and height h
. You can choose any font size from array fonts
, which contains the available font sizes in ascending order.
You can use the FontInfo
interface to get the width and height of any character at any available font size.
The FontInfo
interface is defined as such:
The calculated width of text
for some fontSize
is the sum of every getWidth(fontSize, text[i])
call for each 0 <= i < text.length
(0-indexed). The calculated height of text
for some fontSize
is getHeight(fontSize)
. Note that text
is displayed on a single line.
It is guaranteed that FontInfo
will return the same value if you call getHeight
or getWidth
with the same parameters.
It is also guaranteed that for any font size fontSize
and any character ch
:
getHeight(fontSize) <= getHeight(fontSize+1)
getWidth(fontSize, ch) <= getWidth(fontSize+1, ch)
Return the maximum font size you can use to display text
on the screen. If text
cannot fit on the display with any font size, return -1
.
Example 1:
Example 2:
Example 3:
Constraints:
1 <= text.length <= 50000
text
contains only lowercase English letters.1 <= w <= 107
1 <= h <= 104
1 <= fonts.length <= 105
1 <= fonts[i] <= 105
fonts
is sorted in ascending order and does not contain duplicates.
ac
Last updated