# LeetCode Optimal Division

LeetCode Optimal Division Given a list of positive integers, the adjacent integers will perform the float division. For example, [2,3,4] -> 2 / 3 / 4. However, you can add any number of parenthesis at any position to change the priority of operations. You should find out how to add parenthesis to get the maximum result, and return the corresponding expression in string format. Your expression should NOT contain redundant parenthesis. Example:

Input: [1000,100,10,2]
Output: "1000/(100/10/2)"
Explanation:
1000/(100/10/2) = 1000/((100/10)/2) = 200
However, the bold parenthesis in "1000/((100/10)/2)" are redundant,
since they don't influence the operation priority. So you should return "1000/(100/10/2)".
Other cases:
1000/(100/10)/2 = 50
1000/(100/(10/2)) = 50
1000/100/10/2 = 0.5
1000/100/(10/2) = 2
Note:
1. The length of the input array is [1, 10].
2. Elements in the given array will be in range [2, 1000].
3. There is only one optimal division for each test case.

# LeetCode Binary Tree Tilt

LeetCode Binary Tree Tilt Given a binary tree, return the tilt of the whole tree. The tilt of a tree node is defined as the absolute difference between the sum of all left subtree node values and the sum of all right subtree node values. Null node has tilt 0. The tilt of the whole tree is defined as the sum of all nodes’ tilt. Example:

Input:
1
/   \
2     3
Output: 1
Explanation:
Tilt of node 2 : 0
Tilt of node 3 : 0
Tilt of node 1 : |2-3| = 1
Tilt of binary tree : 0 + 0 + 1 = 1
Note:
1. The sum of node values in any subtree won’t exceed the range of 32-bit integer.
2. All the tilt values won’t exceed the range of 32-bit integer.

# LeetCode Array Partition I

LeetCode Array Partition I Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), …, (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as possible. Example 1:

Input: [1,4,3,2]
Output: 4
Explanation: n is 2, and the maximum sum of pairs is 4.
Note:
1. n is a positive integer, which is in the range of [1, 10000].
2. All the integers in the array will be in the range of [-10000, 10000].

# LeetCode Student Attendance Record II

LeetCode Student Attendance Record II Given a positive integer n, return the number of all possible attendance records with length n, which will be regarded as rewardable. The answer may be very large, return it after mod 109 + 7. A student attendance record is a string that only contains the following three characters:

1. ‘A’ : Absent.
2. ‘L’ : Late.
3. ‘P’ : Present.
A record is regarded as rewardable if it doesn’t contain more than one ‘A’ (absent) or more than two continuous ‘L’ (late). Example 1:
Input: n = 2
Output: 8
Explanation:
There are 8 records with length 2 will be regarded as rewardable:
"PP" , "AP", "PA", "LP", "PL", "AL", "LA", "LL"
Only "AA" won't be regarded as rewardable owing to more than one absent times.
Note: The value of n won’t exceed 100,000.

• dp[n][0][1]=dp[n-1][0][0]
• dp[n][0][2]=dp[n-1][0][1]
• dp[n][1][0]=sum(dp[n-1][0])+sum(dp[n-1][1])
• dp[n][1][1]=dp[n-1][1][0]
• dp[n][1][2]=dp[n-1][1][1]

# LeetCode Student Attendance Record I

LeetCode Student Attendance Record I You are given a string representing an attendance record for a student. The record only contains the following three characters:

1. ‘A’ : Absent.
2. ‘L’ : Late.
3. ‘P’ : Present.
A student could be rewarded if his attendance record doesn’t contain more than one ‘A’ (absent) or more than two continuous ‘L’ (late). You need to return whether the student could be rewarded according to his attendance record. Example 1:
Input: "PPALLP"
Output: True
Example 2:
Input: "PPALLL"
Output: False

# LeetCode Longest Uncommon Subsequence I

LeetCode Longest Uncommon Subsequence I Given a group of two strings, you need to find the longest uncommon subsequence of this group of two strings. The longest uncommon subsequence is defined as the longest subsequence of one of these strings and this subsequence should not be any subsequence of the other strings. A subsequence is a sequence that can be derived from one sequence by deleting some characters without changing the order of the remaining elements. Trivially, any string is a subsequence of itself and an empty string is a subsequence of any string. The input will be two strings, and the output needs to be the length of the longest uncommon subsequence. If the longest uncommon subsequence doesn’t exist, return -1. Example 1:

Input: "aba", "cdc"
Output: 3
Explanation: The longest uncommon subsequence is "aba" (or "cdc"),
because "aba" is a subsequence of "aba",
but not a subsequence of any other strings in the group of two strings.
Note:
1. Both strings’ lengths will not exceed 100.
2. Only letters from a ~ z will appear in input strings.

# LeetCode Reverse Words in a String III

LeetCode Reverse Words in a String III Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order. Example 1:

Input: "Let's take LeetCode contest"
Output: "s'teL ekat edoCteeL tsetnoc"
Note: In the string, each word is separated by single space and there will not be any extra space in the string.

# hihoCoder 1507-可疑的记录

hihoCoder 1507-可疑的记录

### 输出

3
1 2
1 3
1 3

2 3

1. 首先，如果这一行x,y中y如果出现1，则这一行肯定是有问题的，因为1是根节点，不可能在右边。
2. 其次，如果出现x==y，也有问题，因为树没有自回路。
3. 最后，正常的树中除了根节点，每个节点有且仅有一个父亲节点，如果添加了一行，且不满足上面两种情况，则肯定会出现某个点的父亲节点有两个！所以我们只需要找出出现两个父亲节点的节点即可，而且这两个父亲都有可疑。

# hihoCoder 1508-剑刃风暴

hihoCoder 1508-剑刃风暴

10 2
0 10
0 10
9 10
1 2
4 5
8 8
8 4
4 2
7 7
0 7

3

# hihoCoder 1506-投掷硬币

hihoCoder 1506-投掷硬币

2 1
0.5 0.5

0.500000