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
| /** | |
| * Definition for binary tree | |
| * public class TreeNode { | |
| * int val; | |
| * TreeNode left; | |
| * TreeNode right; | |
| * TreeNode(int x) { val = x; } | |
| * } | |
| */ | |
| public class Solution { |
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
| /** | |
| * Definition for an interval. | |
| * public class Interval { | |
| * int start; | |
| * int end; | |
| * Interval() { start = 0; end = 0; } | |
| * Interval(int s, int e) { start = s; end = e; } | |
| * } | |
| */ | |
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 class Solution { | |
| public int climbStairs(int n) { | |
| // Start typing your Java solution below | |
| // DO NOT write main() function | |
| if( n == 0 || n == 1 || n == 2) | |
| return n; | |
| int array[] = new int[n + 1]; | |
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
| /** | |
| * Definition for binary tree | |
| * public class TreeNode { | |
| * int val; | |
| * TreeNode left; | |
| * TreeNode right; | |
| * TreeNode(int x) { val = x; } | |
| * } | |
| */ | |
| public class Solution { |
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
| package Chapter2; | |
| public class InsertCyclicSortedList { | |
| public static void main(String args[]){ | |
| IntNode n1, n2, n3, n4, n5, n6,n7, n8, n9; | |
| n9 = new IntNode(27, null); | |
| n8 = new IntNode(16, n9); | |
| n7 = new IntNode(14, n8); | |
| n6 = new IntNode(12, n7); | |
| n5 = new IntNode(8, n6); |
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
| package others; | |
| import java.util.Deque; | |
| import java.util.LinkedList; | |
| public class SlidingWindowMaximum { | |
| public static void main(String args[]){ | |
| int arr[] = {1, 3, -1, -3, 5, 3, 6, 7, 8}; | |
| int b[] = slidingWindowMaximum(arr, 3); | |
| for(int i = 0; i< b.length ; i++){ | |
| System.out.print(b[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
| package others; | |
| import java.util.Arrays; | |
| import java.util.ArrayList; | |
| public class threeSum { | |
| public static void main(String args[]) { | |
| int arr[] = {-7 , 8, 9, 2 , -3, -5, 3, 2, 5, 1, 2, -4}; | |
| System.out.println(getThreeSum(arr)); | |
| } |
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
| /* | |
| * Print a binary tree in zig zag level order | |
| */ | |
| package Chapter4; | |
| import java.util.Stack; | |
| public class PrintZigZagOrder { | |
| public static void main(String args[]){ |
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 class ReverseString { | |
| public static void main(String args[]){ | |
| String s = "reverse test 123456789"; | |
| char[] array = s.toCharArray(); | |
| reverse(array, 0, array.length - 1); | |
| System.out.println(array); | |
| } | |