Leetcode Hacking Practice -- Solution in C++ Part 5
文章內容
LeetCode (used to call i has 1337 code) is a social platform for preparing IT technical interviews. We strive to provide you with the best learning experience in preparing interviews for companies in the IT industry.
To be successful in a technical interview, we believe it is mainly repeating these three important steps:
Code. Read. Discuss.
We strive to provide you the LeetCode platform as the ultimate solution for preparing technical interviews.
1. Code -> Code solution using the Online Judge system.
2. Read -> Read high quality article featuring in-depth thought process. Also read other LeetCoders’ code.
3. Discuss -> Discuss your thoughts about the problem with other LeetCoders.
We hope that through our platform, you will grow into a LeetCoder. Not only will you be successful in all of your interviews, and most importantly, you will be a better coder in general !
This is Part 5 (第五部分)
第一部分: www.westca.com/Forums/...inese.html
第二部分: www.westca.com/Forums/...inese.html
第三部分: www.westca.com/Forums/...inese.html
第四部分: www.westca.com/Forums/...inese.html
To be successful in a technical interview, we believe it is mainly repeating these three important steps:
Code. Read. Discuss.
We strive to provide you the LeetCode platform as the ultimate solution for preparing technical interviews.
1. Code -> Code solution using the Online Judge system.
2. Read -> Read high quality article featuring in-depth thought process. Also read other LeetCoders’ code.
3. Discuss -> Discuss your thoughts about the problem with other LeetCoders.
We hope that through our platform, you will grow into a LeetCoder. Not only will you be successful in all of your interviews, and most importantly, you will be a better coder in general !
This is Part 5 (第五部分)
第一部分: www.westca.com/Forums/...inese.html
第二部分: www.westca.com/Forums/...inese.html
第三部分: www.westca.com/Forums/...inese.html
第四部分: www.westca.com/Forums/...inese.html
分享: |
![]() |
文章評論
webdriver | 無題 2014-09-25 00:35:42 | 引用 |
無題 推薦答案來了 (in C++) ...
...
2014-09-25 00:36:13 | 引用 |
webdriver |
webdriver | 無題 算法問題: Trapping Rain Water
問題描述: Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For example, Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6. 2014-09-25 00:37:13 | 引用 |
無題 推薦答案來了 (in C++) ...
Find left bound and right bound for each element. O(n).
2014-09-25 00:37:53 | 引用 |
webdriver |
webdriver | 無題 算法問題: Triangle
問題描述: Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ [2], [3,4], [6,5,7], [4,1,8,3] ] The minimum path sum from top to bottom is 11 (i.e., 2 + 3 + 5 + 1 = 11). Note: Bonus point if you are able to do this using only O(n) extra space, where n is the total number of rows in the triangle. 2014-09-25 00:39:13 | 引用 |
無題 推薦答案來了 (in C++) ...
Note that there are n elements in the n-th row (n starts from 1). 1. DFS. (Time Limit Exceeded for large test data). 2. DP. Do not need additional spaces (happen in-place). 3. DP. O(n) space (If the input 'triangle' can not be changed).
2014-09-25 00:39:54 | 引用 |
webdriver |
webdriver | 無題 算法問題: Two Sum
問題描述: Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and index2) are not zero-based. You may assume that each input would have exactly one solution. Input: numbers={2, 7, 11, 15}, target=9 Output: index1=1, index2=2 2014-09-25 00:41:14 | 引用 |
無題 推薦答案來了 (in C++) ...
1. Sort first. O(nlgn) 2. Hash table. O(n) Note: Hash Table solution has been updated. In case that the two elements are the same, all the indices should be stored in the map.
2014-09-25 00:42:04 | 引用 |
webdriver |
webdriver | 無題 算法問題: Unique Binary Search Trees
問題描述: Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example, Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ \ 2 1 2 3 2014-09-25 00:43:44 | 引用 |
無題 推薦答案來了 (in C++) ...
dp.
2014-09-25 00:44:35 | 引用 |
webdriver |
問題描述:
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.
Corner Cases:
A line other than the last line might contain only one word. What should you do in this case?
In this case, that line should be left-justified.