This file contains hidden or 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 int minTreeDepth(TreeNode root) { | |
| if (root == null) { | |
| return 0; | |
| } | |
| Queue<TreeNode> currQ = new LinkedList<TreeNode>(); |
This file contains hidden or 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 ListNode reverseList(ListNode head) { | |
| // Add your code below this line. Do not modify any other code. | |
| ListNode currentNode = head; | |
| ListNode previousNode= null; | |
| while(currentNode != null) | |
| { | |
| ListNode nextNode = currentNode.next; | |
| currentNode.next = previousNode; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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); |