theash2473
theash2473
JCHJava Community | Help. Code. Learn.
Created by theash2473 on 2/9/2025 in #java-help
github repo deleted. Now cloning local to a new remote repo
My current git repo has all the commits and branches and whatever that was done in the repo. Although the remote repo somehow got deleted long back. I now want to push the current repo to a new remote as it is. I created this repo to learn git so I made sure that all the commits and branches are also present in the remote back then. Now I wanna do it again. I am trying to understand reflogs of the repo so that I can compare what will go and what will not. Here are the reflogs below. I am stuck at the point that in the 3rd line, there's a branch name mentioned for the commit but only for the remote and not local branch. Can anyone clarify why is that?
$ git reflog
bf302bb (HEAD -> branch_a) HEAD@{0}: reset: moving to HEAD
bf302bb (HEAD -> branch_a) HEAD@{1}: reset: moving to HEAD
bf302bb (HEAD -> branch_a) HEAD@{2}: commit: more changes on the branch
0f3bdda (origin/branch_a) HEAD@{3}: commit: branch_a commit
bbe56be (origin/subbranch, subbranch) HEAD@{4}: checkout: moving from subbranch to branch_a
2c8ab12 (origin/brnch, brnch) HEAD@{5}: checkout: moving from subbranch to brnch
bbe56be (origin/subbranch, subbranch) HEAD@{6}: checkout: moving from main to subbranch
1c320e0 (origin/main, main) HEAD@{7}: Branch: renamed refs/heads/master to refs/heads/main
1c320e0 (origin/main, main) HEAD@{9}: checkout: moving from subbranch to master
bbe56be (origin/subbranch, subbranch) HEAD@{10}: commit: subbranch code
1c320e0 (origin/main, main) HEAD@{11}: checkout: moving from brnch to subbranch
2c8ab12 (origin/brnch, brnch) HEAD@{12}: commit: brnch code
1c320e0 (origin/main, main) HEAD@{13}: checkout: moving from subbranch to brnch
1c320e0 (origin/main, main) HEAD@{14}: checkout: moving from brnch to subbranch
1c320e0 (origin/main, main) HEAD@{15}: checkout: moving from master to brnch
1c320e0 (origin/main, main) HEAD@{16}: commit (initial): main branch
$ git reflog
bf302bb (HEAD -> branch_a) HEAD@{0}: reset: moving to HEAD
bf302bb (HEAD -> branch_a) HEAD@{1}: reset: moving to HEAD
bf302bb (HEAD -> branch_a) HEAD@{2}: commit: more changes on the branch
0f3bdda (origin/branch_a) HEAD@{3}: commit: branch_a commit
bbe56be (origin/subbranch, subbranch) HEAD@{4}: checkout: moving from subbranch to branch_a
2c8ab12 (origin/brnch, brnch) HEAD@{5}: checkout: moving from subbranch to brnch
bbe56be (origin/subbranch, subbranch) HEAD@{6}: checkout: moving from main to subbranch
1c320e0 (origin/main, main) HEAD@{7}: Branch: renamed refs/heads/master to refs/heads/main
1c320e0 (origin/main, main) HEAD@{9}: checkout: moving from subbranch to master
bbe56be (origin/subbranch, subbranch) HEAD@{10}: commit: subbranch code
1c320e0 (origin/main, main) HEAD@{11}: checkout: moving from brnch to subbranch
2c8ab12 (origin/brnch, brnch) HEAD@{12}: commit: brnch code
1c320e0 (origin/main, main) HEAD@{13}: checkout: moving from subbranch to brnch
1c320e0 (origin/main, main) HEAD@{14}: checkout: moving from brnch to subbranch
1c320e0 (origin/main, main) HEAD@{15}: checkout: moving from master to brnch
1c320e0 (origin/main, main) HEAD@{16}: commit (initial): main branch
If you could connect with me and see it live. It would help more in this case.
73 replies
JCHJava Community | Help. Code. Learn.
Created by theash2473 on 11/15/2024 in #java-help
Adding character/s to a string has two different variations.
If you add two characters to a string you get an int as an output but when you add one character it works. Please explain. Here is an example with output for reference.
String str = "eeksforGeeks";

// Inserting at the beginning
String str2 ='[' +'['+ str;

// Print and display the above string
System.out.println(str2);
str2='['+str;
System.out.println(str2);
String str = "eeksforGeeks";

// Inserting at the beginning
String str2 ='[' +'['+ str;

// Print and display the above string
System.out.println(str2);
str2='['+str;
System.out.println(str2);
Output-: 182eeksforGeeks [eeksforGeeks
14 replies
JCHJava Community | Help. Code. Learn.
Created by theash2473 on 10/27/2024 in #java-help
I am getting TLE in Leetcode on question 29. Please help me optimize.
I am using the most efficient code that I could understand. Please suggest how to optimize it for the test case where the dividend is int_max and divisor is -1.
public int divide(int dividend, int divisor) {
// if(di(1<<31))
// if ((dividend < 0) ^ (divisor < 0)) {
// negative = 1;
// dividend = Math.abs(dividend);
// divisor = Math.abs(divisor);
// } else if ((dividend < 0) && (divisor < 0)) {
// dividend = Math.abs(dividend);
// divisor = Math.abs(divisor);
// }
// while (dividend >= divisor) {
// dividend -= divisor;
// answer++;
// }
// if (negative == 1) {
// answer *= -1;
// }
// ;
// return answer;
int answer = 0, negative = 0;
if ((dividend < 0) ^ (divisor < 0))
negative = 1;
if ((dividend == (1 << 31)) && (divisor == -1))
answer = ((1 << 31) - 1);
else {
dividend = Math.abs(dividend);
divisor = Math.abs(divisor);
while (dividend > divisor) {
int temp_divisor = divisor, counter = 0;
for (; dividend >= temp_divisor; counter++) {
temp_divisor = temp_divisor << 1;
}
counter--;
temp_divisor = temp_divisor >> 1;
dividend -= temp_divisor;
answer += (Math.pow((int) 2, (int) counter));
System.out.println(temp_divisor);
System.out.println(dividend);
System.out.println(answer);
System.out.println(counter + "\n");
}
}
if (negative == 1) {
answer *= -1;
}
return answer;
}
public int divide(int dividend, int divisor) {
// if(di(1<<31))
// if ((dividend < 0) ^ (divisor < 0)) {
// negative = 1;
// dividend = Math.abs(dividend);
// divisor = Math.abs(divisor);
// } else if ((dividend < 0) && (divisor < 0)) {
// dividend = Math.abs(dividend);
// divisor = Math.abs(divisor);
// }
// while (dividend >= divisor) {
// dividend -= divisor;
// answer++;
// }
// if (negative == 1) {
// answer *= -1;
// }
// ;
// return answer;
int answer = 0, negative = 0;
if ((dividend < 0) ^ (divisor < 0))
negative = 1;
if ((dividend == (1 << 31)) && (divisor == -1))
answer = ((1 << 31) - 1);
else {
dividend = Math.abs(dividend);
divisor = Math.abs(divisor);
while (dividend > divisor) {
int temp_divisor = divisor, counter = 0;
for (; dividend >= temp_divisor; counter++) {
temp_divisor = temp_divisor << 1;
}
counter--;
temp_divisor = temp_divisor >> 1;
dividend -= temp_divisor;
answer += (Math.pow((int) 2, (int) counter));
System.out.println(temp_divisor);
System.out.println(dividend);
System.out.println(answer);
System.out.println(counter + "\n");
}
}
if (negative == 1) {
answer *= -1;
}
return answer;
}
12 replies
JCHJava Community | Help. Code. Learn.
Created by theash2473 on 10/18/2024 in #java-help
In the bitwise compliment operator there is confusion. Please help if you can.
For the 2’s complement, if we take 8 bits for a binary representation, in the case of decimal 200, binary is 11001000 2’s complement is also 11001000 In the procedure to calculate mentioned in the link https://www.rit.edu/academicsuccesscenter/sites/rit.edu.academicsuccesscenter/files/documents/math-handouts/DM3_TwosComplement_BP_9_22_14.pdf, it should be 00111000 The confusion must be because of the 8th bit being a 1.
17 replies