Skip to content

Commit d38eca0

Browse files
author
0x01f7
committed
style: comment
1 parent 634b55a commit d38eca0

19 files changed

+138
-101
lines changed

algorithms/add_and_search_word_data_structure_design.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
# search(".ad") -> true
1919
# search("b..") -> true
2020
#
21-
# Note: You may assume that all words are consist of lowercase letters a-z.
21+
# Note:
22+
#
23+
# You may assume that all words are consist of lowercase letters a-z.
2224

2325

2426
class TrieNode

algorithms/balanced_binary_tree.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# https://leetcode.com/problems/balanced-binary-tree/
22
#
3-
# Given a binary tree, determine if it is height-balanced. For this
4-
# problem, a height-balanced binary tree is defined as a binary
5-
# tree in which the depth of the two subtrees of every node never
6-
# differ by more than 1.
3+
# Given a binary tree, determine if it is height-balanced. For this problem,
4+
# a height-balanced binary tree is defined as a binary tree in which the
5+
# depth of the two subtrees of every node never differ by more than 1.
76

87

98
# Definition for a binary tree node.

algorithms/basic_calculator.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# https://leetcode.com/problems/basic-calculator/
22
#
3-
# Implement a basic calculator to evaluate a simple expression string.
4-
# The expression string may contain open ( and closing parentheses ),
5-
# the plus + or minus sign -, non-negative integers and empty spaces.
6-
# You may assume that the given expression is always valid.
3+
# Implement a basic calculator to evaluate a simple expression string. The
4+
# expression string may contain open ( and closing parentheses ), the plus
5+
# + or minus sign -, non-negative integers and empty spaces. You may assume
6+
# that the given expression is always valid.
77
#
88
# Some examples:
99
#

algorithms/basic_calculator_ii.rb

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
# https://leetcode.com/problems/basic-calculator-ii/
22
#
3-
# Implement a basic calculator to evaluate a simple expression string.
4-
# The expression string contains only non-negative integers, +, -, *,
5-
# / operators and empty spaces. The integer division should truncate
6-
# toward zero. You may assume that the given expression is always valid.
3+
# Implement a basic calculator to evaluate a simple expression string. The
4+
# expression string contains only non-negative integers, +, -, *, / operators
5+
# and empty spaces. The integer division should truncate toward zero. You may
6+
# assume that the given expression is always valid.
77
#
88
# Some examples:
99
#
1010
# "3+2*2" = 7
1111
# " 3/2 " = 1
1212
# " 3+5 / 2 " = 5
1313
#
14-
# Note: Do not use the eval built-in library function.
14+
# Note:
15+
#
16+
# Do not use the eval built-in library function.
17+
#
18+
# Credits:
19+
#
20+
# Special thanks to @ts for adding this problem and creating all test
21+
# cases.
1522

1623

1724
# @param {String} s

algorithms/best_time_to_buy_and_sell_stock.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# https://leetcode.com/problems/best-time-to-buy-and-sell-stock/
22
#
3-
# Say you have an array for which the ith element is the price of a
4-
# given stock on day i. If you were only permitted to complete at
5-
# most one transaction (ie, buy one and sell one share of the stock),
6-
# design an algorithm to find the maximum profit.
3+
# Say you have an array for which the ith element is the price of a given
4+
# stock on day i. If you were only permitted to complete at most one
5+
# transaction (ie, buy one and sell one share of the stock), design an
6+
# algorithm to find the maximum profit.
77

88

99
# @param {Integer[]} prices

algorithms/best_time_to_buy_and_sell_stock_ii.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/
22
#
3-
# Say you have an array for which the ith element is the price of a
4-
# given stock on day i. Design an algorithm to find the maximum
5-
# profit. You may complete as many transactions as you like (ie,
6-
# buy one and sell one share of the stock multiple times). However,
7-
# you may not engage in multiple transactions at the same time (ie,
8-
# you must sell the stock before you buy again).
3+
# Say you have an array for which the ith element is the price of a given
4+
# stock on day i. Design an algorithm to find the maximum profit. You may
5+
# complete as many transactions as you like (ie, buy one and sell one share
6+
# of the stock multiple times). However, you may not engage in multiple
7+
# transactions at the same time (ie, you must sell the stock before you buy
8+
# again).
99

1010

1111
# @param {Integer[]} prices

algorithms/best_time_to_buy_and_sell_stock_iii.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/
22
#
3-
# Say you have an array for which the ith element is the price of a
4-
# given stock on day i. Design an algorithm to find the maximum
5-
# profit. You may complete at most two transactions. However,
6-
# You may not engage in multiple transactions at the same time (ie,
7-
# you must sell the stock before you buy again).
3+
# Say you have an array for which the ith element is the price of a given
4+
# stock on day i. Design an algorithm to find the maximum profit. You may
5+
# complete at most two transactions. However, You may not engage in multiple
6+
# transactions at the same time (ie, you must sell the stock before you buy
7+
# again).
88

99

1010
# @param {Integer[]} prices

algorithms/best_time_to_buy_and_sell_stock_iv.rb

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
# https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv/
22
#
3-
# Say you have an array for which the ith element is the price of a
4-
# given stock on day i. Design an algorithm to find the maximum
5-
# profit. You may complete at most k transactions. However,
6-
# You may not engage in multiple transactions at the same time (ie,
7-
# you must sell the stock before you buy again).
3+
# Say you have an array for which the ith element is the price of a given
4+
# stock on day i. Design an algorithm to find the maximum profit. You may
5+
# complete at most k transactions. However, You may not engage in multiple
6+
# transactions at the same time (ie, you must sell the stock before you buy
7+
# again).
8+
#
9+
# Credits:
10+
#
11+
# Special thanks to @Freezen for adding this problem and creating all
12+
# test cases.
813

914

1015
# @param {Integer} k

algorithms/binary_search_tree_iterator.rb

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
# https://leetcode.com/problems/binary-search-tree-iterator/
22
#
3-
# Implement an iterator over a binary search tree (BST). Your iterator
4-
# will be initialized with the root node of a BST.
3+
# Implement an iterator over a binary search tree (BST). Your iterator will
4+
# be initialized with the root node of a BST. Calling next() will return the
5+
# next smallest number in the BST.
56
#
6-
# Calling next() will return the next smallest number in the BST.
7+
# Note:
78
#
8-
# Note: next() and hasNext() should run in average O(1) time and uses
9-
# O(h) memory, where h is the height of the tree.
9+
# next() and hasNext() should run in average O(1) time and uses O(h)
10+
# memory, where h is the height of the tree.
11+
#
12+
# Credits:
13+
#
14+
# Special thanks to @ts for adding this problem and creating all test
15+
# cases.
1016

1117

1218
# Definition for a binary tree node.

algorithms/binary_tree_inorder_traversal.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
# https://leetcode.com/problems/binary-tree-inorder-traversal/
22
#
3-
# Given a binary tree, return the inorder traversal of its nodes'
4-
# values.
3+
# Given a binary tree, return the inorder traversal of its nodes' values.
54
#
65
# For example:
76
#
8-
# Given binary tree {1,#,2,3},
7+
# Given binary tree {1, #, 2, 3},
98
#
109
# 1
1110
# \
1211
# 2
1312
# /
1413
# 3
1514
#
16-
# return [1,3,2].
15+
# Return [1, 3, 2].
1716
#
1817
# Note: Recursive solution is trivial, could you do it iteratively?
1918

algorithms/binary_tree_level_order_traversal.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# https://leetcode.com/problems/binary-tree-level-order-traversal/
22
#
3-
# Given a binary tree, return the level order traversal of its
4-
# nodes' values. (ie, from left to right, level by level).
3+
# Given a binary tree, return the level order traversal of its nodes' values.
4+
# (ie, from left to right, level by level).
55
#
66
# For example:
77
#
8-
# Given binary tree {3,9,20,#,#,15,7},
8+
# Given binary tree {3, 9, 20, #, #, 15, 7},
99
#
1010
# 3
1111
# / \
1212
# 9 20
1313
# / \
1414
# 15 7
1515
#
16-
# return its level order traversal as:
16+
# Return its level order traversal as:
1717
#
1818
# [
1919
# [3],

algorithms/binary_tree_level_order_traversal_ii.rb

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
# https://leetcode.com/problems/binary-tree-level-order-traversal-ii/
22
#
3-
# Given a binary tree, return the bottom-up level order traversal
4-
# of its nodes' values. (ie, from left to right, level by level
5-
# from leaf to root).
3+
# Given a binary tree, return the bottom-up level order traversal of its
4+
# nodes' values. (ie, from left to right, level by level from leaf to root).
65
#
76
# For example:
87
#
9-
# Given binary tree {3,9,20,#,#,15,7},
8+
# Given binary tree {3, 9, 20, #, #, 15, 7},
109
#
1110
# 3
1211
# / \
1312
# 9 20
1413
# / \
1514
# 15 7
1615
#
17-
# return its level order traversal as:
16+
# Return its level order traversal as:
1817
#
1918
# [
2019
# [15, 7],

algorithms/binary_tree_maximum_path_sum.rb

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
# https://leetcode.com/problems/binary-tree-maximum-path-sum/
22
#
3-
# Given a binary tree, find the maximum path sum. For this problem, a
4-
# path is defined as any sequence of nodes from some starting node to
5-
# any node in the tree along the parent-child connections. The path
6-
# does not need to go through the root.
3+
# Given a binary tree, find the maximum path sum. For this problem, a path is
4+
# defined as any sequence of nodes from some starting node to any node in the
5+
# tree along the parent-child connections. The path does not need to go
6+
# through the root.
77
#
8-
# For example: Given the below binary tree,
8+
# For example:
99
#
10-
# 1
11-
# / \
12-
# 2 3
10+
# Given the below binary tree:
1311
#
14-
# Return 6.
12+
# 1
13+
# / \
14+
# 2 3
15+
#
16+
# Return 6.
1517

1618

1719
# Definition for a binary tree node.

algorithms/binary_tree_paths.rb

+15-8
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,24 @@
22
#
33
# Given a binary tree, return all root-to-leaf paths.
44
#
5-
# For example, given the following binary tree:
5+
# For example,
66
#
7-
# 1
8-
# / \
9-
# 2 3
10-
# \
11-
# 5
7+
# Given the following binary tree:
128
#
13-
# All root-to-leaf paths are:
9+
# 1
10+
# / \
11+
# 2 3
12+
# \
13+
# 5
1414
#
15-
# ["1->2->5", "1->3"]
15+
# All root-to-leaf paths are:
16+
#
17+
# ["1->2->5", "1->3"]
18+
#
19+
# Credits:
20+
#
21+
# Special thanks to @jianchao.li.fighter for adding this problem and
22+
# creating all test cases.
1623

1724

1825
# Definition for a binary tree node.

algorithms/binary_tree_postorder_traversal.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
# https://leetcode.com/problems/binary-tree-postorder-traversal/
22
#
3-
# Given a binary tree, return the postorder traversal of its nodes'
4-
# values.
3+
# Given a binary tree, return the postorder traversal of its nodes' values.
54
#
65
# For example:
76
#
8-
# Given binary tree {1,#,2,3},
7+
# Given binary tree {1, #, 2, 3},
98
#
109
# 1
1110
# \
1211
# 2
1312
# /
1413
# 3
1514
#
16-
# return [3,2,1].
15+
# Return [3, 2, 1].
1716
#
1817
# Note: Recursive solution is trivial, could you do it iteratively?
1918

algorithms/binary_tree_preorder_traversal.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
# https://leetcode.com/problems/binary-tree-preorder-traversal/
22
#
3-
# Given a binary tree, return the preorder traversal of its nodes'
4-
# values.
3+
# Given a binary tree, return the preorder traversal of its nodes' values.
54
#
65
# For example:
76
#
8-
# Given binary tree {1,#,2,3},
7+
# Given binary tree {1, #, 2, 3},
98
#
109
# 1
1110
# \
1211
# 2
1312
# /
1413
# 3
1514
#
16-
# return [1,2,3].
15+
# Return [1, 2, 3].
1716
#
1817
# Note: Recursive solution is trivial, could you do it iteratively?
1918

algorithms/binary_tree_right_side_view.rb

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
# https://leetcode.com/problems/binary-tree-right-side-view/
22
#
3-
# Given a binary tree, imagine yourself standing on the right side
4-
# of it, return the values of the nodes you can see ordered from
5-
# top to bottom.
3+
# Given a binary tree, imagine yourself standing on the right side of it,
4+
# return the values of the nodes you can see ordered from top to bottom.
65
#
7-
# For example: Given the following binary tree,
6+
# For example:
87
#
9-
# 1 <---
10-
# / \
11-
# 2 3 <---
12-
# \ \
13-
# 5 4 <---
8+
# Given the following binary tree,
149
#
15-
# You should return [1, 3, 4].
10+
# 1 <---
11+
# / \
12+
# 2 3 <---
13+
# \ \
14+
# 5 4 <---
15+
#
16+
# Return [1, 3, 4].
17+
#
18+
# Credits:
19+
#
20+
# Special thanks to @amrsaqr for adding this problem and creating all
21+
# test cases.
1622

1723

1824
# Definition for a binary tree node.

0 commit comments

Comments
 (0)