Skip to content

Commit bc3896b

Browse files
[LEET-0000] add problem descriptions
1 parent 16b5989 commit bc3896b

File tree

5 files changed

+61
-9
lines changed

5 files changed

+61
-9
lines changed

leetcode-algorithms/src/main/java/com/stevesun/solutions/CloneGraph.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.stevesun.solutions;
22

3-
4-
53
import com.stevesun.common.classes.UndirectedGraphNode;
64

75
import java.util.HashMap;
@@ -10,7 +8,29 @@
108
import java.util.Queue;
119

1210
/**
13-
* Created by fishercoder1534 on 9/30/16.
11+
* Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.
12+
13+
14+
OJ's undirected graph serialization:
15+
Nodes are labeled uniquely.
16+
17+
We use # as a separator for each node, and , as a separator for node label and each neighbor of the node.
18+
As an example, consider the serialized graph {0,1,2#1,2#2,2}.
19+
20+
The graph has a total of three nodes, and therefore contains three parts as separated by #.
21+
22+
First node is labeled as 0. Connect node 0 to both nodes 1 and 2.
23+
Second node is labeled as 1. Connect node 1 to node 2.
24+
Third node is labeled as 2. Connect node 2 to node 2 (itself), thus forming a self-cycle.
25+
Visually, the graph looks like the following:
26+
27+
1
28+
/ \
29+
/ \
30+
0 --- 2
31+
/ \
32+
\_/
33+
1434
*/
1535
public class CloneGraph {
1636

leetcode-algorithms/src/main/java/com/stevesun/solutions/SymmetricTree.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44

55
/**101. Symmetric Tree
66
7-
Total Accepted: 121737
8-
Total Submissions: 346738
9-
Difficulty: Easy
10-
117
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
128
139
For example, this binary tree [1,2,2,3,4,4,3] is symmetric:

leetcode-algorithms/src/main/java/com/stevesun/solutions/TextJustification.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,31 @@
11
package com.stevesun.solutions;
22
import java.util.*;
33
/**
4-
* Created by fishercoder1534 on 10/9/16.
4+
* 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.
5+
6+
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.
7+
8+
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.
9+
10+
For the last line of text, it should be left justified and no extra space is inserted between words.
11+
12+
For example,
13+
words: ["This", "is", "an", "example", "of", "text", "justification."]
14+
L: 16.
15+
16+
Return the formatted lines as:
17+
[
18+
"This is an",
19+
"example of text",
20+
"justification. "
21+
]
22+
Note: Each word is guaranteed not to exceed L in length.
23+
24+
click to show corner cases.
25+
26+
Corner Cases:
27+
A line other than the last line might contain only one word. What should you do in this case?
28+
In this case, that line should be left-justified.
529
*/
630
public class TextJustification {
731

leetcode-algorithms/src/main/java/com/stevesun/solutions/Triangle.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.stevesun.solutions;
2+
23
import java.util.*;
4+
35
public class Triangle {
46

57
public static int minimumTotal(List<List<Integer>> triangle) {
6-
/**Looked at this post: https://discuss.leetcode.com/topic/1669/dp-solution-for-triangle, @stellari has a very excellent explanation.
8+
/**https://discuss.leetcode.com/topic/1669/dp-solution-for-triangle, @stellari has a very excellent explanation.
79
* Basically, we use the bottom-up approach, starting from the bottom row of this triangle, and we only need to store the shortest path of each node
810
* from its last row, and keep overwriting it until we reach the top.*/
911
int n = triangle.size();

leetcode-algorithms/src/main/java/com/stevesun/solutions/ValidPalindrome.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
package com.stevesun.solutions;
22

3+
/**Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
4+
5+
For example,
6+
"A man, a plan, a canal: Panama" is a palindrome.
7+
"race a car" is not a palindrome.
8+
9+
Note:
10+
Have you consider that the string might be empty? This is a good question to ask during an interview.
11+
12+
For the purpose of this problem, we define empty string as valid palindrome.*/
313
public class ValidPalindrome {
414

515
public boolean isPalindrome(String s) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy