forked from neetcode-gh/leetcode
-
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.
🎨 Format files (🛠️ from Github Actions)
- Loading branch information
Showing
374 changed files
with
7,951 additions
and
7,822 deletions.
There are no files selected for viewing
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,19 +1,19 @@ | ||
class Solution { | ||
|
||
public int[] twoSum(int[] nums, int target) { | ||
HashMap<Integer, Integer> prevMap = new HashMap<>(); | ||
public int[] twoSum(int[] nums, int target) { | ||
HashMap<Integer, Integer> prevMap = new HashMap<>(); | ||
|
||
for (int i = 0; i < nums.length; i++) { | ||
int num = nums[i]; | ||
int diff = target - num; | ||
for (int i = 0; i < nums.length; i++) { | ||
int num = nums[i]; | ||
int diff = target - num; | ||
|
||
if (prevMap.containsKey(nums[i])) { | ||
return new int[] { prevMap.get(num), i }; | ||
} | ||
if (prevMap.containsKey(nums[i])) { | ||
return new int[] { prevMap.get(num), i }; | ||
} | ||
|
||
prevMap.put(target - num, i); | ||
} | ||
prevMap.put(target - num, i); | ||
} | ||
|
||
return new int[] {}; | ||
} | ||
return new int[] {}; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
class Solution { | ||
|
||
public int maxDepth(TreeNode root) { | ||
if (root == null) return 0; | ||
return 1 + Math.max(maxDepth(root.left), maxDepth(root.right)); | ||
} | ||
public int maxDepth(TreeNode root) { | ||
if (root == null) return 0; | ||
return 1 + Math.max(maxDepth(root.left), maxDepth(root.right)); | ||
} | ||
} |
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,13 +1,13 @@ | ||
class Solution { | ||
|
||
public int lastStoneWeight(int[] stones) { | ||
PriorityQueue<Integer> maxHeap = new PriorityQueue(); | ||
for (int stone : stones) maxHeap.add(-stone); | ||
while (maxHeap.size() > 1) { | ||
int stone1 = maxHeap.remove(); | ||
int stone2 = maxHeap.remove(); | ||
if (stone1 != stone2) maxHeap.add(stone1 - stone2); | ||
public int lastStoneWeight(int[] stones) { | ||
PriorityQueue<Integer> maxHeap = new PriorityQueue(); | ||
for (int stone : stones) maxHeap.add(-stone); | ||
while (maxHeap.size() > 1) { | ||
int stone1 = maxHeap.remove(); | ||
int stone2 = maxHeap.remove(); | ||
if (stone1 != stone2) maxHeap.add(stone1 - stone2); | ||
} | ||
return maxHeap.size() != 0 ? (-maxHeap.remove()) : 0; | ||
} | ||
return maxHeap.size() != 0 ? (-maxHeap.remove()) : 0; | ||
} | ||
} |
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
Oops, something went wrong.