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
class Solution { | |
public List<List<Integer>> threeSum(int[] nums) { | |
Set<List<Integer>> combos = new HashSet<List<Integer>>(); | |
Arrays.sort(nums); | |
Map<Integer, Integer> values = new HashMap<Integer,Integer>(); | |
for(int i = 0; i<nums.length;i++){ | |
if(values.containsKey(nums[i])){ | |
values.put(nums[i],values.get(nums[i])+1); | |
}else{ |
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
public class SerializeDeserializeBinaryTree { | |
public static void main(String args[]){ | |
TreeNode root = new TreeNode(3); | |
root.left = new TreeNode(5); | |
root.left.left = new TreeNode(6); | |
root.left.right = new TreeNode(2); | |
root.left.right.left = new TreeNode(7); | |
root.left.right.right = new TreeNode(4); |
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
package com.learning.leet.strsarrs; | |
import java.util.Arrays; | |
/** | |
* Created by sargonbenjamin on 6/19/19. | |
* https://leetcode.com/problems/kth-largest-element-in-an-array/ | |
*/ | |
public class KthLargestElement { | |
public static void main(String args[]){ |
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
/** | |
* Created by sargonbenjamin on 6/21/19. | |
* https://leetcode.com/explore/interview/card/top-interview-questions-easy/127/strings/887/ | |
*/ | |
public class LongestCommonPrefix { | |
public String longestCommonPrefix(String[] strs) { | |
if(strs==null || strs.length == 0 || strs[0].length()==0)return ""; | |
StringBuilder prefix = new StringBuilder(""); |
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
package com.learning.leet.problems; | |
import java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.HashMap; | |
/** | |
* https://leetcode.com/problems/coin-change/ | |
*/ | |
public class CoinChange { |
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
public int coinChangeIterative(int coins[], int amount){ | |
int[] resultArr = new int[amount+1]; | |
for(int i = 0;i<resultArr.length; i++){ | |
resultArr[i]=Integer.MAX_VALUE; | |
} | |
resultArr[0]=0; | |
for(int i =0;i<resultArr.length; i++){ | |
int min = Integer.MAX_VALUE; | |
for(int coin : coins){ |
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
package com.learning.leet.problems; | |
import java.util.HashMap; | |
import java.util.Map; | |
/** | |
* Created by sargonbenjamin on 7/8/19. | |
* https://leetcode.com/problems/climbing-stairs/ | |
*/ | |
public class ClimbStairs { |
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
package com.learning.leet.problems; | |
import java.util.HashSet; | |
import java.util.Set; | |
/** | |
* Created by sargonbenjamin on 7/9/19. | |
* https://leetcode.com/problems/minimum-cost-for-tickets/ | |
*/ | |
public class MinCostForTickets { |
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
public int mincostTickets(int[] days, int[] costs) { | |
Set<Integer> setRideDays = new HashSet<>(); | |
for(int day : days){ | |
setRideDays.add(day); | |
} | |
int[] minCostCache = new int[366]; | |
for(int i = 0; i<minCostCache.length;i++){ | |
minCostCache[i]=-1; |
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
package com.learning.leet.strsarrs; | |
/** | |
* Created by sargonbenjamin on 7/10/19. | |
* https://leetcode.com/problems/maximum-subarray/ | |
*/ | |
public class MaximumSubarray { | |
public static void main(String args[]){ |
OlderNewer