Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions problems/managers-with-at-least-5-direct-reports/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
+------+----------+-----------+----------+
</pre>

<p>Given the <code>Employee</code> table, write a SQL query that finds out managers with at least 5 direct report. For the above table, your SQL query should return:
</p>
<p>Given the <code>Employee</code> table, write a SQL query that finds out managers with at least 5 direct report. For the above table, your SQL query should return:</p>

<pre>
+-------+
Expand Down
20 changes: 11 additions & 9 deletions problems/maximum-average-subarray-i/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,26 @@

## 643. Maximum Average Subarray I (Easy)

<p>
Given an array consisting of <code>n</code> integers, find the contiguous subarray of given length <code>k</code> that has the maximum average value. And you need to output the maximum average value.
</p>
<p>Given an array consisting of <code>n</code> integers, find the contiguous subarray of given length <code>k</code> that has the maximum average value. And you need to output the maximum average value.</p>

<p><b>Example 1:</b></p>

<p><b>Example 1:</b><br />
<pre>
<b>Input:</b> [1,12,-5,-6,50,3], k = 4
<b>Output:</b> 12.75
<b>Explanation:</b> Maximum average is (12-5-6+50)/4 = 51/4 = 12.75
</pre>
</p>

<p><b>Note:</b><br>
<p>&nbsp;</p>

<p><b>Note:</b></p>

<ol>
<li>1 <= <code>k</code> <= <code>n</code> <= 30,000.</li>
<li>Elements of the given array will be in the range [-10,000, 10,000].</li>
<li>1 &lt;= <code>k</code> &lt;= <code>n</code> &lt;= 30,000.</li>
<li>Elements of the given array will be in the range [-10,000, 10,000].</li>
</ol>
</p>

<p>&nbsp;</p>

### Related Topics
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
Expand Down
22 changes: 14 additions & 8 deletions problems/maximum-product-of-three-numbers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,32 @@

<p>Given an integer array, find three numbers whose product is maximum and output the maximum product.</p>

<p><b>Example 1:</b><br />
<p><b>Example 1:</b></p>

<pre>
<b>Input:</b> [1,2,3]
<b>Output:</b> 6
</pre>
</p>

<p><b>Example 2:</b><br />
<p>&nbsp;</p>

<p><b>Example 2:</b></p>

<pre>
<b>Input:</b> [1,2,3,4]
<b>Output:</b> 24
</pre>
</p>

<p><b>Note:</b><br>
<p>&nbsp;</p>

<p><b>Note:</b></p>

<ol>
<li>The length of the given array will be in range [3,10<sup>4</sup>] and all elements are in the range [-1000, 1000].</li>
<li>Multiplication of any three numbers in the input won't exceed the range of 32-bit signed integer.</li>
<li>The length of the given array will be in range [3,10<sup>4</sup>] and all elements are in the range [-1000, 1000].</li>
<li>Multiplication of any three numbers in the input won&#39;t exceed the range of 32-bit signed integer.</li>
</ol>
</p>

<p>&nbsp;</p>

### Related Topics
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
Expand Down
16 changes: 8 additions & 8 deletions problems/maximum-width-of-binary-tree/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@

## 662. Maximum Width of Binary Tree (Medium)

<p>Given a binary tree, write a function to get the maximum width of the given tree. The width of a tree is the maximum width among all levels. The binary tree has the same structure as a <b>full binary tree</b>, but some nodes are null. </p>
<p>Given a binary tree, write a function to get the maximum width of the given tree. The width of a tree is the maximum width among all levels. The binary tree has the same structure as a <b>full binary tree</b>, but some nodes are null.</p>

<p>The width of one level is defined as the length between the end-nodes (the leftmost and right most non-null nodes in the level, where the <code>null</code> nodes between the end-nodes are also counted into the length calculation.</p>

<p><b>Example 1:</b><br />
<p><b>Example 1:</b></p>

<pre>
<b>Input:</b>

Expand All @@ -29,8 +30,8 @@
<b>Explanation:</b> The maximum width existing in the third level with the length 4 (5,3,null,9).
</pre>

<p><b>Example 2:</b></p>

<p><b>Example 2:</b><br />
<pre>
<b>Input:</b>

Expand All @@ -44,8 +45,8 @@
<b>Explanation:</b> The maximum width existing in the third level with the length 2 (5,3).
</pre>

<p><b>Example 3:</b></p>

<p><b>Example 3:</b><br />
<pre>
<b>Input:</b>

Expand All @@ -59,7 +60,8 @@
<b>Explanation:</b> The maximum width existing in the second level with the length 2 (3,2).
</pre>

<p><b>Example 4:</b><br />
<p><b>Example 4:</b></p>

<pre>
<b>Input:</b>

Expand All @@ -76,9 +78,7 @@

</pre>

<p><b>Note:</b>
Answer will in the range of 32-bit signed integer.
</p>
<p><b>Note:</b> Answer will in the range of 32-bit signed integer.</p>

### Related Topics
[[Tree](https://github.com/openset/leetcode/tree/master/tag/tree/README.md)]
3 changes: 1 addition & 2 deletions problems/median-employee-salary/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

## 569. Median Employee Salary (Hard)

<p>
The <code>Employee</code> table holds all employees. The employee table has three columns: Employee Id, Company Name, and Salary.</p>
<p>The <code>Employee</code> table holds all employees. The employee table has three columns: Employee Id, Company Name, and Salary.</p>

<pre>
+-----+------------+--------+
Expand Down
43 changes: 22 additions & 21 deletions problems/my-calendar-i/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,37 @@

## 729. My Calendar I (Medium)

<p>
Implement a <code>MyCalendar</code> class to store your events. A new event can be added if adding the event will not cause a double booking.
</p><p>
Your class will have the method, <code>book(int start, int end)</code>. Formally, this represents a booking on the half open interval <code>[start, end)</code>, the range of real numbers <code>x</code> such that <code>start <= x < end</code>.
</p><p>
A <i>double booking</i> happens when two events have some non-empty intersection (ie., there is some time that is common to both events.)
</p><p>
For each call to the method <code>MyCalendar.book</code>, return <code>true</code> if the event can be added to the calendar successfully without causing a double booking. Otherwise, return <code>false</code> and do not add the event to the calendar.
</p>

Your class will be called like this:
<code>MyCalendar cal = new MyCalendar();</code>
<code>MyCalendar.book(start, end)</code>

<p><b>Example 1:</b><br />
<p>Implement a <code>MyCalendar</code> class to store your events. A new event can be added if adding the event will not cause a double booking.</p>

<p>Your class will have the method, <code>book(int start, int end)</code>. Formally, this represents a booking on the half open interval <code>[start, end)</code>, the range of real numbers <code>x</code> such that <code>start &lt;= x &lt; end</code>.</p>

<p>A <i>double booking</i> happens when two events have some non-empty intersection (ie., there is some time that is common to both events.)</p>

<p>For each call to the method <code>MyCalendar.book</code>, return <code>true</code> if the event can be added to the calendar successfully without causing a double booking. Otherwise, return <code>false</code> and do not add the event to the calendar.</p>
Your class will be called like this: <code>MyCalendar cal = new MyCalendar();</code> <code>MyCalendar.book(start, end)</code>

<p><b>Example 1:</b></p>

<pre>
MyCalendar();
MyCalendar.book(10, 20); // returns true
MyCalendar.book(15, 25); // returns false
MyCalendar.book(20, 30); // returns true
<b>Explanation:</b>
The first event can be booked. The second can't because time 15 is already booked by another event.
The first event can be booked. The second can&#39;t because time 15 is already booked by another event.
The third event can be booked, as the first event takes every time less than 20, but not including 20.
</pre>
</p>

<p><b>Note:</b>
<li>The number of calls to <code>MyCalendar.book</code> per test case will be at most <code>1000</code>.</li>
<li>In calls to <code>MyCalendar.book(start, end)</code>, <code>start</code> and <code>end</code> are integers in the range <code>[0, 10^9]</code>.</li>
</p>
<p>&nbsp;</p>

<p><b>Note:</b></p>

<ul>
<li>The number of calls to <code>MyCalendar.book</code> per test case will be at most <code>1000</code>.</li>
<li>In calls to <code>MyCalendar.book(start, end)</code>, <code>start</code> and <code>end</code> are integers in the range <code>[0, 10^9]</code>.</li>
</ul>

<p>&nbsp;</p>

### Related Topics
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
Expand Down
43 changes: 22 additions & 21 deletions problems/my-calendar-ii/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,17 @@

## 731. My Calendar II (Medium)

<p>
Implement a <code>MyCalendarTwo</code> class to store your events. A new event can be added if adding the event will not cause a <b>triple</b> booking.
</p><p>
Your class will have one method, <code>book(int start, int end)</code>. Formally, this represents a booking on the half open interval <code>[start, end)</code>, the range of real numbers <code>x</code> such that <code>start <= x < end</code>.
</p><p>
A <i>triple booking</i> happens when <b>three</b> events have some non-empty intersection (ie., there is some time that is common to all 3 events.)
</p><p>
For each call to the method <code>MyCalendar.book</code>, return <code>true</code> if the event can be added to the calendar successfully without causing a <b>triple</b> booking. Otherwise, return <code>false</code> and do not add the event to the calendar.
</p>

Your class will be called like this:
<code>MyCalendar cal = new MyCalendar();</code>
<code>MyCalendar.book(start, end)</code>

<p><b>Example 1:</b><br />
<p>Implement a <code>MyCalendarTwo</code> class to store your events. A new event can be added if adding the event will not cause a <b>triple</b> booking.</p>

<p>Your class will have one method, <code>book(int start, int end)</code>. Formally, this represents a booking on the half open interval <code>[start, end)</code>, the range of real numbers <code>x</code> such that <code>start &lt;= x &lt; end</code>.</p>

<p>A <i>triple booking</i> happens when <b>three</b> events have some non-empty intersection (ie., there is some time that is common to all 3 events.)</p>

<p>For each call to the method <code>MyCalendar.book</code>, return <code>true</code> if the event can be added to the calendar successfully without causing a <b>triple</b> booking. Otherwise, return <code>false</code> and do not add the event to the calendar.</p>
Your class will be called like this: <code>MyCalendar cal = new MyCalendar();</code> <code>MyCalendar.book(start, end)</code>

<p><b>Example 1:</b></p>

<pre>
MyCalendar();
MyCalendar.book(10, 20); // returns true
Expand All @@ -36,17 +32,22 @@ MyCalendar.book(5, 10); // returns true
MyCalendar.book(25, 55); // returns true
<b>Explanation:</b>
The first two events can be booked. The third event can be double booked.
The fourth event (5, 15) can't be booked, because it would result in a triple booking.
The fourth event (5, 15) can&#39;t be booked, because it would result in a triple booking.
The fifth event (5, 10) can be booked, as it does not use time 10 which is already double booked.
The sixth event (25, 55) can be booked, as the time in [25, 40) will be double booked with the third event;
the time [40, 50) will be single booked, and the time [50, 55) will be double booked with the second event.
</pre>
</p>

<p><b>Note:</b>
<li>The number of calls to <code>MyCalendar.book</code> per test case will be at most <code>1000</code>.</li>
<li>In calls to <code>MyCalendar.book(start, end)</code>, <code>start</code> and <code>end</code> are integers in the range <code>[0, 10^9]</code>.</li>
</p>
<p>&nbsp;</p>

<p><b>Note:</b></p>

<ul>
<li>The number of calls to <code>MyCalendar.book</code> per test case will be at most <code>1000</code>.</li>
<li>In calls to <code>MyCalendar.book(start, end)</code>, <code>start</code> and <code>end</code> are integers in the range <code>[0, 10^9]</code>.</li>
</ul>

<p>&nbsp;</p>

### Related Topics
[[Binary Search Tree](https://github.com/openset/leetcode/tree/master/tag/binary-search-tree/README.md)]
Expand Down
18 changes: 10 additions & 8 deletions problems/not-boring-movies/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

## 620. Not Boring Movies (Easy)

X city opened a new cinema, many people would like to go to this cinema.
The cinema also gives out a poster indicating the movies’ ratings and descriptions. <p/>
Please write a SQL query to output movies with an odd numbered ID and a description that is not 'boring'. Order the result by rating.
<p/>
<p>
For example, table <code>cinema</code>:
X city opened a new cinema, many people would like to go to this cinema. The cinema also gives out a poster indicating the movies&rsquo; ratings and descriptions.
<p>Please write a SQL query to output movies with an odd numbered ID and a description that is not &#39;boring&#39;. Order the result by rating.</p>

<p>&nbsp;</p>

<p>For example, table <code>cinema</code>:</p>

<pre>
+---------+-----------+--------------+-----------+
| id | movie | description | rating |
Expand All @@ -30,6 +30,7 @@ For example, table <code>cinema</code>:
+---------+-----------+--------------+-----------+
</pre>
For the example above, the output should be:

<pre>
+---------+-----------+--------------+-----------+
| id | movie | description | rating |
Expand All @@ -38,4 +39,5 @@ For the example above, the output should be:
| 1 | War | great 3D | 8.9 |
+---------+-----------+--------------+-----------+
</pre>
</p>

<p>&nbsp;</p>
36 changes: 19 additions & 17 deletions problems/palindromic-substrings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,37 @@

## 647. Palindromic Substrings (Medium)

<p>
Given a string, your task is to count how many palindromic substrings in this string.
</p>
<p>Given a string, your task is to count how many palindromic substrings in this string.</p>

<p>
The substrings with different start indexes or end indexes are counted as different substrings even they consist of same characters.
</p>
<p>The substrings with different start indexes or end indexes are counted as different substrings even they consist of same characters.</p>

<p><b>Example 1:</b></p>

<p><b>Example 1:</b><br />
<pre>
<b>Input:</b> "abc"
<b>Input:</b> &quot;abc&quot;
<b>Output:</b> 3
<b>Explanation:</b> Three palindromic strings: "a", "b", "c".
<b>Explanation:</b> Three palindromic strings: &quot;a&quot;, &quot;b&quot;, &quot;c&quot;.
</pre>
</p>

<p><b>Example 2:</b><br />
<p>&nbsp;</p>

<p><b>Example 2:</b></p>

<pre>
<b>Input:</b> "aaa"
<b>Input:</b> &quot;aaa&quot;
<b>Output:</b> 6
<b>Explanation:</b> Six palindromic strings: "a", "a", "a", "aa", "aa", "aaa".
<b>Explanation:</b> Six palindromic strings: &quot;a&quot;, &quot;a&quot;, &quot;a&quot;, &quot;aa&quot;, &quot;aa&quot;, &quot;aaa&quot;.
</pre>
</p>

<p><b>Note:</b><br>
<p>&nbsp;</p>

<p><b>Note:</b></p>

<ol>
<li>The input string length won't exceed 1000.</li>
<li>The input string length won&#39;t exceed 1000.</li>
</ol>
</p>

<p>&nbsp;</p>

### Related Topics
[[String](https://github.com/openset/leetcode/tree/master/tag/string/README.md)]
Expand Down
Loading