网上买的莴笋种子第二年就失效了?# gardening - 拈花惹草
i*e
1 楼
这题大家写写看,虽然没什么算法,但是很考基本功。
另外,这是一道很好的面试题。因为题意可以很含糊,但是里边有很多细节需要搞清楚
,设计输入和输出。还有 corner cases 也有,很容易没考虑周全。
题目参考以下链接:
http://www.cs.rpi.edu//academics/courses/fall09/ds/hw/01_text_j
我对题目的理解,简短的述说:
"Text Justification"
Given an array of words and a length L, format the text such that each line
has exactly L characters and is fully (left and right) justified.
You should pack your words in a greedy approach; that is, pack as many words
as you can in each line. Pad extra spaces ' ' when necessary so that each
line has exactly L characters.
Extra spaces between words should be distributed as evenly as possible. If
the number of spaces on a line do not divide evenly between words, the empty
slots on the left will be assigned more spaces than the slots on the right.
For the last line of text, it should be left justified and no extra space is
inserted between words.
For example,
words: ["This", "is", "an", "example", "of", "text", "justification."]
L: 16.
Return the formatted lines as:
[
"This is an",
"example of text",
"justification. "
]
Note: Each word is guaranteed not to exceed L in length.
这道题可以在 OJ 测试程序:
http://www.leetcode.com/onlinejudge
另外,这是一道很好的面试题。因为题意可以很含糊,但是里边有很多细节需要搞清楚
,设计输入和输出。还有 corner cases 也有,很容易没考虑周全。
题目参考以下链接:
http://www.cs.rpi.edu//academics/courses/fall09/ds/hw/01_text_j
我对题目的理解,简短的述说:
"Text Justification"
Given an array of words and a length L, format the text such that each line
has exactly L characters and is fully (left and right) justified.
You should pack your words in a greedy approach; that is, pack as many words
as you can in each line. Pad extra spaces ' ' when necessary so that each
line has exactly L characters.
Extra spaces between words should be distributed as evenly as possible. If
the number of spaces on a line do not divide evenly between words, the empty
slots on the left will be assigned more spaces than the slots on the right.
For the last line of text, it should be left justified and no extra space is
inserted between words.
For example,
words: ["This", "is", "an", "example", "of", "text", "justification."]
L: 16.
Return the formatted lines as:
[
"This is an",
"example of text",
"justification. "
]
Note: Each word is guaranteed not to exceed L in length.
这道题可以在 OJ 测试程序:
http://www.leetcode.com/onlinejudge