Skip to content

Commit 42378ba

Browse files
committed
clean
1 parent 83c9061 commit 42378ba

25 files changed

+28
-115
lines changed

Diff for: 100.IsSameTree.cs

-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
// 100. Same Tree
22

33
// Given the roots of two binary trees p and q, write a function to check if they are the same or not.
4-
54
// Two binary trees are considered the same if they are structurally identical, and the nodes have the same value.
65

7-
8-
96
// Example 1:
10-
11-
127
// Input: p = [1,2,3], q = [1,2,3]
138
// Output: true
149
// Example 2:
15-
16-
1710
// Input: p = [1,2], q = [1,null,2]
1811
// Output: false
1912

Diff for: 101.IsSymmetric.cs

-6
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@
22

33
// Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center).
44

5-
6-
75
// Example 1:
8-
9-
106
// Input: root = [1,2,2,3,4,4,3]
117
// Output: true
128
// Example 2:
13-
14-
159
// Input: root = [1,2,2,null,3,null,3]
1610
// Output: false
1711

Diff for: 102.LevelOrder.cs

-5
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,14 @@
22

33
// Given the root of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level).
44

5-
6-
75
// Example 1:
8-
9-
106
// Input: root = [3,9,20,null,null,15,7]
117
// Output: [[3],[9,20],[15,7]]
128
// Example 2:
139

1410
// Input: root = [1]
1511
// Output: [[1]]
1612
// Example 3:
17-
1813
// Input: root = []
1914
// Output: []
2015

Diff for: 103.ZigzagLevelOrder.cs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
// 103. Binary Tree Zigzag Level Order Traversal
22
// Given the root of a binary tree, return the zigzag level order traversal of its nodes' values. (i.e., from left to right, then right to left for the next level and alternate between).
33

4-
5-
6-
// Example 1:
7-
8-
4+
// Example 1:
95
// Input: root = [3,9,20,null,null,15,7]
106
// Output: [[3],[20,9],[15,7]]
117
// Example 2:
12-
138
// Input: root = [1]
149
// Output: [[1]]
1510
// Example 3:
16-
1711
// Input: root = []
1812
// Output: []
1913

Diff for: 104.MaxDepth.cs

-5
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@
44

55
// A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
66

7-
8-
97
// Example 1:
10-
11-
128
// Input: root = [3,9,20,null,null,15,7]
139
// Output: 3
1410
// Example 2:
15-
1611
// Input: root = [1,null,2]
1712
// Output: 2
1813

Diff for: 107.LevelOrderBottom.cs

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
// 107. Binary Tree Level Order Traversal II
22

3-
// Given the root of a binary tree, return the bottom-up level order traversal of its nodes' values. (i.e., from left to right, level by level from leaf to root).
4-
5-
3+
// Given the root of a binary tree, return the bottom-up level order traversal of its nodes' values.
4+
// (i.e., from left to right, level by level from leaf to root).
65

76
// Example 1:
8-
9-
107
// Input: root = [3,9,20,null,null,15,7]
118
// Output: [[15,7],[9,20],[3]]
129
// Example 2:
13-
1410
// Input: root = [1]
1511
// Output: [[1]]
1612
// Example 3:
17-
1813
// Input: root = []
1914
// Output: []
2015

Diff for: 108.SortedArrayToBST.cs

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
// 108. Convert Sorted Array to Binary Search Tree
2-
// Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree.
3-
4-
2+
// Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced
3+
// binary search tree.
54

65
// Example 1:
7-
8-
96
// Input: nums = [-10,-3,0,5,9]
107
// Output: [0,-3,9,-10,null,5]
118
// Explanation: [0,-10,5,null,-3,null,9] is also accepted:
12-
139
// Example 2:
14-
15-
1610
// Input: nums = [1,3]
1711
// Output: [3,1]
1812
// Explanation: [1,null,3] and [3,1] are both height-balanced BSTs.

Diff for: 109.SortedListToBST.cs

-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
// 109. Convert Sorted List to Binary Search Tree
22

33
// Given the head of a singly linked list where elements are sorted in ascending order, convert it to a height-balanced binary search tree.
4-
5-
6-
74
// Example 1:
8-
9-
105
// Input: head = [-10,-3,0,5,9]
116
// Output: [0,-3,9,-10,null,5]
127
// Explanation: One possible answer is [0,-3,9,-10,null,5], which represents the shown height balanced BST.
138
// Example 2:
14-
159
// Input: head = []
1610
// Output: []
1711

Diff for: 110.IsBalanced.cs

-10
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
11
// 110. Balanced Binary Tree
22

33
// Given a binary tree, determine if it is height-balanced.
4-
54
// For this problem, a height-balanced binary tree is defined as:
6-
75
// a binary tree in which the left and right subtrees of every node differ in height by no more than 1.
8-
9-
10-
116
// Example 1:
12-
13-
147
// Input: root = [3,9,20,null,null,15,7]
158
// Output: true
169
// Example 2:
17-
18-
1910
// Input: root = [1,2,2,3,3,null,null,4,4]
2011
// Output: false
2112
// Example 3:
22-
2313
// Input: root = []
2414
// Output: true
2515

Diff for: 111.MinDepth.cs

-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
// 111. Minimum Depth of Binary Tree
22
// Given a binary tree, find its minimum depth.
3-
43
// The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.
5-
64
// Note: A leaf is a node with no children.
7-
8-
9-
105
// Example 1:
11-
12-
136
// Input: root = [3,9,20,null,null,15,7]
147
// Output: 2
158
// Example 2:
16-
179
// Input: root = [2,null,3,null,4,null,5,null,6]
1810
// Output: 5
1911

Diff for: 112.HasPathSum.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// 112. Path Sum
2-
// Given the root of a binary tree and an integer targetSum, return true if the tree has a root-to-leaf path such that adding up all the values along the path equals targetSum.
2+
// Given the root of a binary tree and an integer targetSum, return true if the tree has a root-to-leaf path such that
3+
// adding up all the values along the path equals targetSum.
34
// A leaf is a node with no children.
45
// Example 1:
56
// Input: root = [5,4,8,11,null,13,4,7,2,null,null,null,1], targetSum = 22

Diff for: 113.PathSum.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// 113. Path Sum II
2-
// Given the root of a binary tree and an integer targetSum, return all root-to-leaf paths where the sum of the node values in the path equals targetSum. Each path should be returned as a list of the node values, not node references.
2+
// Given the root of a binary tree and an integer targetSum, return all root-to-leaf paths where the sum of the node values
3+
// in the path equals targetSum. Each path should be returned as a list of the node values, not node references.
34
// A root-to-leaf path is a path starting from the root and ending at any leaf node. A leaf is a node with no children.
45
// Example 1:
56
// Input: root = [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22

Diff for: 116.Connect.cs

-3
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@
1313
// Initially, all next pointers are set to NULL.
1414

1515
// Example 1:
16-
17-
1816
// Input: root = [1,2,3,4,5,6,7]
1917
// Output: [1,#,2,3,#,4,5,6,7,#]
2018
// Explanation: Given the above perfect binary tree (Figure A), your function should populate each next pointer to point to its next right node, just like in Figure B. The serialized output is in level order as connected by the next pointers, with '#' signifying the end of each level.
2119
// Example 2:
22-
2320
// Input: root = []
2421
// Output: []
2522

Diff for: 118.Generate.cs

-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
// In Pascal's triangle, each number is the sum of the two numbers directly above it as shown:
66

77
// Example 1:
8-
98
// Input: numRows = 5
109
// Output: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]
1110
// Example 2:
12-
1311
// Input: numRows = 1
1412
// Output: [[1]]
1513

Diff for: 120.MinimumTotal.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// 120. Triangle
22
// Given a triangle array, return the minimum path sum from top to bottom.
3-
// For each step, you may move to an adjacent number of the row below. More formally, if you are on index i on the current row, you may move to either index i or index i + 1 on the next row.
3+
// For each step, you may move to an adjacent number of the row below. More formally, if you are on index i on the current row,
4+
// you may move to either index i or index i + 1 on the next row.
45
// Example 1:
56
// Input: triangle = [[2],[3,4],[6,5,7],[4,1,8,3]]
67
// Output: 11

Diff for: 121.MaxProfit.cs

+2-6
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,16 @@
22

33
// You are given an array prices where prices[i] is the price of a given stock on the ith day.
44

5-
// You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock.
5+
// You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to
6+
// sell that stock.
67

78
// Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0.
8-
9-
10-
119
// Example 1:
12-
1310
// Input: prices = [7,1,5,3,6,4]
1411
// Output: 5
1512
// Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.
1613
// Note that buying on day 2 and selling on day 1 is not allowed because you must buy before you sell.
1714
// Example 2:
18-
1915
// Input: prices = [7,6,4,3,1]
2016
// Output: 0
2117
// Explanation: In this case, no transactions are done and the max profit = 0.

Diff for: 122.MaxProfit.cs

-5
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,18 @@
77

88
// Find and return the maximum profit you can achieve.
99

10-
11-
1210
// Example 1:
13-
1411
// Input: prices = [7,1,5,3,6,4]
1512
// Output: 7
1613
// Explanation: Buy on day 2 (price = 1) and sell on day 3 (price = 5), profit = 5-1 = 4.
1714
// Then buy on day 4 (price = 3) and sell on day 5 (price = 6), profit = 6-3 = 3.
1815
// Total profit is 4 + 3 = 7.
1916
// Example 2:
20-
2117
// Input: prices = [1,2,3,4,5]
2218
// Output: 4
2319
// Explanation: Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4.
2420
// Total profit is 4.
2521
// Example 3:
26-
2722
// Input: prices = [7,6,4,3,1]
2823
// Output: 0
2924
// Explanation: There is no way to make a positive profit, so we never buy the stock to achieve the maximum profit of 0.

Diff for: 123.MaxProfit.cs

-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@
99
// Explanation: Buy on day 4 (price = 0) and sell on day 6 (price = 3), profit = 3-0 = 3.
1010
// Then buy on day 7 (price = 1) and sell on day 8 (price = 4), profit = 4-1 = 3.
1111
// Example 2:
12-
1312
// Input: prices = [1,2,3,4,5]
1413
// Output: 4
1514
// Explanation: Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4.
1615
// Note that you cannot buy on day 1, buy on day 2 and sell them later, as you are engaging multiple transactions at the same time. You must sell before buying again.
1716
// Example 3:
18-
1917
// Input: prices = [7,6,4,3,1]
2018
// Output: 0
2119
// Explanation: In this case, no transaction is done, i.e. max profit = 0.

Diff for: 125.IsPalindrome.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// 125. Valid Palindrome
2-
// A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.
2+
// A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric
3+
// characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.
34
// Given a string s, return true if it is a palindrome, or false otherwise.
5+
6+
//Approch 1
47
public class Solution
58
{
69
public bool IsPalindrome(string s)
@@ -13,6 +16,7 @@ public bool IsPalindrome(string s)
1316
}
1417
}
1518

19+
//Approch 2
1620
public class Solution
1721
{
1822
public bool IsPalindrome(string s)

Diff for: 90.SubsetsWithDup.cs

-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
// The solution set must not contain duplicate subsets. Return the solution in any order.
66

77
// Example 1:
8-
98
// Input: nums = [1,2,2]
109
// Output: [[],[1],[1,2],[1,2,2],[2],[2,2]]
1110
// Example 2:
12-
1311
// Input: nums = [0]
1412
// Output: [[],[0]]
1513

Diff for: 92.ReverseBetween.cs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
// 92. Reverse Linked List II
22

3-
// Given the head of a singly linked list and two integers left and right where left <= right, reverse the nodes of the list from position left to position right, and return the reversed list.
4-
5-
3+
// Given the head of a singly linked list and two integers left and right where left <= right, reverse the nodes of the
4+
// list from position left to position right, and return the reversed list.
65

76
// Example 1:
8-
9-
107
// Input: head = [1,2,3,4,5], left = 2, right = 4
118
// Output: [1,4,3,2,5]
129
// Example 2:
13-
1410
// Input: head = [5], left = 1, right = 1
1511
// Output: [5]
1612

Diff for: 93.RestoreIpAddresses.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// 93. Restore IP Addresses
2-
// A valid IP address consists of exactly four integers separated by single dots. Each integer is between 0 and 255 (inclusive) and cannot have leading zeros.
3-
// For example, "0.1.2.201" and "192.168.1.1" are valid IP addresses, but "0.011.255.245", "192.168.1.312" and "[email protected]" are invalid IP addresses.
4-
// Given a string s containing only digits, return all possible valid IP addresses that can be formed by inserting dots into s. You are not allowed to reorder or remove any digits in s. You may return the valid IP addresses in any order.
2+
// A valid IP address consists of exactly four integers separated by single dots. Each integer is between 0 and 255
3+
// (inclusive) and cannot have leading zeros.
4+
// For example, "0.1.2.201" and "192.168.1.1" are valid IP addresses, but "0.011.255.245", "192.168.1.312" and "[email protected]"
5+
// are invalid IP addresses.
6+
// Given a string s containing only digits, return all possible valid IP addresses that can be formed by inserting dots into s.
7+
// You are not allowed to reorder or remove any digits in s. You may return the valid IP addresses in any order.
58
// Example 1:
69
// Input: s = "25525511135"
710
// Output: ["255.255.11.135","255.255.111.35"]

Diff for: 94.InorderTraversal.cs

-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
// 94. Binary Tree Inorder Traversal
22

33
// Given the root of a binary tree, return the inorder traversal of its nodes' values.
4-
5-
6-
74
// Example 1:
8-
9-
105
// Input: root = [1,null,2,3]
116
// Output: [1,3,2]
127
// Example 2:
13-
148
// Input: root = []
159
// Output: []
1610
// Example 3:
17-
1811
// Input: root = [1]
1912
// Output: [1]
2013

0 commit comments

Comments
 (0)