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 ArrayList<Integer> levelorder(TreeNode root) { | |
ArrayList<Integer> levelOrderedList = new ArrayList<Integer>(); | |
Queue<TreeNode> q = new LinkedList<TreeNode>(); | |
TreeNode curr = null; | |
if(root == null) { | |
return null; | |
} | |
q.add(root); | |
while(!q.isEmpty()) { | |
curr = (TreeNode)q.remove(); |
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
// java.util.* and java.util.streams.* have been imported for this problem. | |
// You don't need any other imports. | |
public ArrayList<String> printPaths(char[][] board){ | |
StringBuilder sb = new StringBuilder(); | |
ArrayList<String> paths = new ArrayList<String>(); | |
if(board.length ==0 || board[0].length==0) return paths; | |
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 pathLengthFromRoot(TreeNode root, int n1) { | |
if (root == null) return 0; | |
else { | |
int out = 0; | |
if ((root.data == n1) || (out = pathLengthFromRoot(root.left, n1)) > 0 | |
|| (out = pathLengthFromRoot(root.right, n1)) > 0) { | |
return out + 1; | |
} | |
return 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
// java.util.* and java.util.streams.* have been imported for this problem. | |
// You don't need any other imports. | |
public ArrayList<ArrayList<Integer>> printLevelByLevel(TreeNode root) { | |
ArrayList<Integer> nodeList = new ArrayList<Integer>(); | |
ArrayList<Integer> levelList = new ArrayList<Integer>(); | |
ArrayList<ArrayList<Integer>> myList = new ArrayList<ArrayList<Integer>>(); |
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 String serializeTree(TreeNode root){ | |
StringBuilder sb = new StringBuilder(); | |
serializeTreeHelper(root,sb); | |
if(sb.length() > 0) sb.deleteCharAt(0); | |
return sb.toString(); | |
} | |
private StringBuilder serializeTreeHelper(TreeNode t, StringBuilder sb){ | |
if(t == null) sb.append(",null"); | |
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
article, | |
aside, | |
details, | |
figcaption, | |
figure, | |
footer, | |
header, | |
hgroup, | |
nav, | |
section, |
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
import java.util.*; | |
public class Problem3 { | |
public static void main(String[] args) { | |
Scanner scan = new Scanner(System.in); | |
int testCases = scan.nextInt(); | |
List<Integer> numbers = new ArrayList<>(); | |
for ( int i =1; i<=testCases; ++i) { |
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
import java.io.*; | |
import java.util.*; | |
import java.text.*; | |
import java.math.*; | |
import java.util.regex.*; | |
public class Solution { | |
public static void main(String args[] ) throws Exception { | |
Scanner scan = new Scanner(System.in); |
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
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.List; | |
/** | |
* Created by madhur on 15 Aug. | |
*/ | |
public class IntegerArrayFlattener { |
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
{"lastUpload":"2020-08-16T07:45:51.198Z","extensionVersion":"v3.4.3"} |