Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor #199

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ public static double findMedianSortedArrays(int[] nums1, int[] nums2) {
int r = len1;
//find the m1 so that nums1[m1] >= nums2[m2 - 1]
while(l < r){
int m1 = l + (r - l) / 2;
int m2 = k - m1;
if (nums1[m1] < nums2[m2 - 1]) {
l = m1 + 1;
int nums1ArrayIndex = l + (r - l) / 2;
int nums2ArrayIndex = k - nums1ArrayIndex;
if (nums1[nums1ArrayIndex] < nums2[nums2ArrayIndex - 1]) {
l = nums1ArrayIndex + 1;
} else {
r = m1;
r = nums1ArrayIndex;
}
}
int m1 = l;
int m2 = k - l;
int c1 = Math.max(m1 <= 0 ? Integer.MIN_VALUE : nums1[m1 - 1],
m2 <= 0? Integer.MIN_VALUE: nums2[m2 - 1]);
int nums1ArrayIndex = l;
int nums2ArrayIndex = k - l;
int c1 = Math.max(nums1ArrayIndex <= 0 ? Integer.MIN_VALUE : nums1[nums1ArrayIndex - 1],
nums2ArrayIndex <= 0? Integer.MIN_VALUE: nums2[nums2ArrayIndex - 1]);
if ((len1 + len2) % 2 ==1) return c1;
int c2 = Math.min(m1 >= len1 ? Integer.MAX_VALUE : nums1[m1],
m2 >= len2 ? Integer.MAX_VALUE: nums2[m2]);
int c2 = Math.min(nums1ArrayIndex >= len1 ? Integer.MAX_VALUE : nums1[nums1ArrayIndex],
nums2ArrayIndex >= len2 ? Integer.MAX_VALUE: nums2[nums2ArrayIndex]);
return (c1 + c2) / 2.0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,22 @@ public static void main(String[] args) {
}

// Pop/Dequeue the chars at the head of both data structures and compare them:
boolean isPalindrome = isPalindrome(s, p);

//Finally, print whether string s is palindrome or not.
System.out.println( "The word, " + input + ", is "
+ ( (!isPalindrome) ? "not a palindrome." : "a palindrome." ) );
}

private static boolean isPalindrome(char[] s, Solution p) {
boolean isPalindrome = true;
for (int i = 0; i < s.length/2; i++) {
if (p.popCharacter() != p.dequeueCharacter()) {
isPalindrome = false;
break;
}
}

//Finally, print whether string s is palindrome or not.
System.out.println( "The word, " + input + ", is "
+ ( (!isPalindrome) ? "not a palindrome." : "a palindrome." ) );
return isPalindrome;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package HackerRank.src.Tracks.Tutorials.ThirtyDaysOfCode.D22_BinarySearchTrees.Java;

public class Node{
Node left,right;
int data;
Node(){
}

Node(int data){
this.data=data;
left=right=null;
}


public static Node insert(Node root,int data){
if(root==null){
return new Node(data);
}
else{
Node cur;
if(data<=root.data){
cur=insert(root.left,data);
root.left=cur;
}
else{
cur=insert(root.right,data);
root.right=cur;
}
return root;
}
}

public static int getHeight(Node root){
if (root == null){
return -1;
}
else {
return 1+ Math.max(getHeight(root.left), getHeight(root.right));
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,17 @@
public class Solution {

public static void main(String[] args) {
Node node = new Node();
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
Node root=null;
while(T-->0){
int data=sc.nextInt();
root=insert(root,data);
root=node.insert(root,data);
}
int height=getHeight(root);
int height=node.getHeight(root);
System.out.println(height);
sc.close();
}

public static Node insert(Node root,int data){
if(root==null){
return new Node(data);
}
else{
Node cur;
if(data<=root.data){
cur=insert(root.left,data);
root.left=cur;
}
else{
cur=insert(root.right,data);
root.right=cur;
}
return root;
}
}

public static int getHeight(Node root){
if (root == null){
return -1;
}
else {
return 1+ Math.max(getHeight(root.left), getHeight(root.right));
}
}
}

class Node{
Node left,right;
int data;
Node(int data){
this.data=data;
left=right=null;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package LeetCode.src.Explore.Interview.GoogleInterview.ArraysAndStrings.FirstMissingPositive.Java;
import LeetCode.src.SwapNumbersInArray;

public class Solution {
public class Solution extends SwapNumbersInArray {
public static void main(String[] args) {
int[] input = {3, 4, -1, 1};
int result = findMissingPositive(input);
Expand Down Expand Up @@ -37,9 +38,4 @@ public static int findMissingPositive(int[] nums) {

}

private static void swap(int[] nums, int i, int j) {
int temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
}
}
Loading