-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
688 additions
and
65 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/leetcode/BestTimeToBuyAndSellStock.java → ...tcode/java/BestTimeToBuyAndSellStock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package leetcode; | ||
package leetcode.java; | ||
|
||
public class BestTimeToBuyAndSellStock { | ||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package leetcode; | ||
package leetcode.java; | ||
|
||
import java.util.*; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
src/leetcode/ContainerWithMostWater.java → ...leetcode/java/ContainerWithMostWater.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package leetcode; | ||
package leetcode.java; | ||
|
||
public class ContainerWithMostWater { | ||
/** | ||
|
2 changes: 1 addition & 1 deletion
2
src/leetcode/ContainsDuplicate.java → src/leetcode/java/ContainsDuplicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package leetcode; | ||
package leetcode.java; | ||
|
||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
|
2 changes: 1 addition & 1 deletion
2
src/leetcode/EncodeAndDecodeStrings.java → ...leetcode/java/EncodeAndDecodeStrings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package leetcode; | ||
package leetcode.java; | ||
|
||
import java.util.*; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...code/FindMinimumInRotatedSortedArray.java → ...java/FindMinimumInRotatedSortedArray.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package leetcode; | ||
package leetcode.java; | ||
|
||
public class FindMinimumInRotatedSortedArray { | ||
/** | ||
|
2 changes: 1 addition & 1 deletion
2
src/leetcode/FirstUniqueCharacter.java → src/leetcode/java/FirstUniqueCharacter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package leetcode; | ||
package leetcode.java; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
2 changes: 1 addition & 1 deletion
2
src/leetcode/GroupAnagrams.java → src/leetcode/java/GroupAnagrams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package leetcode; | ||
package leetcode.java; | ||
|
||
import java.util.*; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
src/leetcode/IsIsomorphic.java → src/leetcode/java/IsIsomorphic.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package leetcode; | ||
package leetcode.java; | ||
|
||
import java.util.*; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
src/leetcode/LongPalindromicSubString.java → ...etcode/java/LongPalindromicSubString.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/leetcode/LongestConsecutive.java → src/leetcode/java/LongestConsecutive.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package leetcode; | ||
package leetcode.java; | ||
|
||
import java.util.*; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...tSubstringWithoutRepeatingCharacters.java → ...tSubstringWithoutRepeatingCharacters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package leetcode; | ||
package leetcode.java; | ||
|
||
import java.util.*; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
src/leetcode/MaximumSubarray.java → src/leetcode/java/MaximumSubarray.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/leetcode/MergeSortArray.java → src/leetcode/java/MergeSortArray.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package leetcode; | ||
package leetcode.java; | ||
|
||
import java.util.Arrays; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
src/leetcode/MinimumWindowSubstring.java → ...leetcode/java/MinimumWindowSubstring.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package leetcode; | ||
package leetcode.java; | ||
|
||
import java.util.*; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package leetcode.java; | ||
|
||
import java.util.*; | ||
|
||
/** | ||
* [7,2,1,2] | ||
* today: 2 | ||
* span 4 | ||
* | ||
* ["StockSpanner", "next", "next", "next", "next", "next", "next", "next"] | ||
* [[], [100], [80], [60], [70], [60], [75], [85]] | ||
* | ||
* [null, 1, 1, 1, 2, 1, 4, 6] | ||
* | ||
* StockSpanner stockSpanner = new StockSpanner(); | ||
* stockSpanner.next(100); // return 1 | ||
* stockSpanner.next(80); // return 1 | ||
* stockSpanner.next(60); // return 1 | ||
* stockSpanner.next(70); // return 2 | ||
* stockSpanner.next(60); // return 1 | ||
* stockSpanner.next(75); // return 4, because the last 4 prices (including today's price of 75) were less than or equal to today's price. | ||
* stockSpanner.next(85); // return 6 | ||
* | ||
* stack = [100] | ||
* stack = [100, 80] | ||
* stack = [100, 80, 60] | ||
* stack = [100, 80, 60, 70] | ||
* stack = [100, 80, 60, 70, 60] | ||
* stack = [100, 80, 60, 70, 60, 75] | ||
* stack = [100, 80, 60, 70, 60, 75] | ||
* | ||
* stack = [75, 60, 70, 60, 80, 100] | ||
*/ | ||
public class OnlineStockSpan { | ||
Stack<Integer> stack; | ||
public OnlineStockSpan() { | ||
this.stack = new Stack<>(); | ||
} | ||
|
||
public int next(int price) { | ||
this.stack.push(price); | ||
List<Integer> list = new ArrayList<>(); | ||
|
||
for (Integer element: this.stack) { | ||
list.add(element); | ||
} | ||
|
||
Collections.reverse(list); | ||
|
||
if (list.size() == 1) { | ||
return 1; | ||
} | ||
|
||
int result = 1; | ||
for (Integer element: list) { | ||
if (element <= price) { | ||
result++; | ||
} else { | ||
break; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/leetcode/ProductOfArrayExceptSelf.java → ...etcode/java/ProductOfArrayExceptSelf.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package leetcode; | ||
package leetcode.java; | ||
|
||
import java.util.Arrays; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
src/leetcode/ReverseString.java → src/leetcode/java/ReverseString.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package leetcode; | ||
package leetcode.java; | ||
|
||
import java.util.Stack; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
src/leetcode/RotateRightArray.java → src/leetcode/java/RotateRightArray.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package leetcode; | ||
package leetcode.java; | ||
|
||
import java.util.Arrays; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
src/leetcode/StringCompression.java → src/leetcode/java/StringCompression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package leetcode; | ||
package leetcode.java; | ||
|
||
import java.util.*; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
src/leetcode/TopKFrequencyElements.java → src/leetcode/java/TopKFrequencyElements.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package leetcode; | ||
package leetcode.java; | ||
|
||
import java.util.*; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
src/leetcode/TopKFrequentWords.java → src/leetcode/java/TopKFrequentWords.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package leetcode; | ||
package leetcode.java; | ||
|
||
import java.util.*; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package leetcode; | ||
package leetcode.java; | ||
|
||
import java.util.HashMap; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
src/leetcode/ValidAnagram.java → src/leetcode/java/ValidAnagram.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package leetcode; | ||
package leetcode.java; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
|
2 changes: 1 addition & 1 deletion
2
src/leetcode/ValidPalindrome.java → src/leetcode/java/ValidPalindrome.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/leetcode/ValidParentheses.java → src/leetcode/java/ValidParentheses.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package leetcode; | ||
package leetcode.java; | ||
|
||
import java.util.HashMap; | ||
import java.util.Objects; | ||
|
2 changes: 1 addition & 1 deletion
2
src/leetcode/GroupAnagrams.kt → src/leetcode/kotlin/GroupAnagrams.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters