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
// 1. word break 1 | |
public boolean dfs(String s, List<String> wordDict) { | |
return dfs(s, new HashSet<>(wordDict), 0); | |
} | |
public boolean dfs(String s, Set<String> wordDict, int start) { | |
if (start == s.length()) { | |
return true; | |
} | |
for (int end = start + 1; end <= s.length(); end++) { |
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.dojo.java8.tutorials.hashmap; | |
import java.util.Comparator; | |
import java.util.HashMap; | |
import java.util.LinkedHashMap; | |
import java.util.Map; | |
import java.util.stream.Collectors; | |
public class HashMapSortingByValues { |
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.dojo.java8.tutorials.hashmap; | |
import java.util.Map; | |
import java.util.stream.Collectors; | |
import java.util.Comparator; | |
import java.util.HashMap; | |
import java.util.LinkedHashMap; | |
public class HashMapSortingByKeys { |
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.ge.current.points; | |
import java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.Comparator; | |
import java.util.TreeMap; | |
import java.util.TreeSet; | |
public class SortData { | |
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
/** | |
* Constructs a new, empty tree set, sorted according to the specified | |
* comparator. All elements inserted into the set must be <i>mutually | |
* comparable</i> by the specified comparator: {@code comparator.compare(e1, | |
* e2)} must not throw a {@code ClassCastException} for any elements | |
* {@code e1} and {@code e2} in the set. If the user attempts to add | |
* an element to the set that violates this constraint, the | |
* {@code add} call will throw a {@code ClassCastException}. | |
* | |
* @param comparator the comparator that will be used to order this set. |
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 int numIslands(char[][] grid) { | |
int count =0; | |
if (grid.length == 0){ | |
return 0; | |
} | |
boolean [][] visited = new boolean[grid.length][grid[0].length]; | |
for (int i =0; i < grid.length; i++){ | |
for (int j = 0 ; j < grid[0].length; j++){ | |
if (grid[i][j]=='1' && !visited[i][j]){ |
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.abhishek.dojo.guess.output; | |
public class ChangeObjectReferenceInsideMethod { | |
public class A { | |
int attr; | |
public void setAttr(int a) { | |
this.attr = a; | |
} | |
} |
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.interview.dynamic; | |
public class WildCardMatching { | |
public boolean isMatch(String s, String p) { | |
char[] str = s.toCharArray(); | |
char[] pattern = p.toCharArray(); | |
//replace multiple * with one * | |
//e.g a**b***c --> a*b*c | |
int writeIndex = 0; | |
boolean isFirst = true; |
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.abhishek.dojo; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class MaximumSumOfTriangularSeries { | |
public static void main(String[] args) { | |
List<List<Integer>> triangle = new ArrayList<List<Integer>>(); | |
ArrayList<Integer> test = new ArrayList<Integer>(); | |
test.add(2); |
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 UniquePath { | |
public int uniquePaths(int m, int n) { | |
// add more comments | |
if (m == 0 || n == 0) { | |
return 0; | |
} | |
int[][] dp = new int[m][n]; | |
NewerOlder