Skip to content

Commit 65bd2f5

Browse files
committed
Misc Concepts Update
Misc Concepts Update
1 parent 5abba1b commit 65bd2f5

File tree

6 files changed

+102
-0
lines changed

6 files changed

+102
-0
lines changed
699 Bytes
Binary file not shown.
667 Bytes
Binary file not shown.
845 Bytes
Binary file not shown.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*Copyright (c) Dec 22, 2014 CareerMonk Publications and others.
2+
* E-Mail : info@careermonk.com
3+
* Creation Date : 2015-01-10 06:15:46
4+
* Last modification : 2006-05-31
5+
by : Narasimha Karumanchi
6+
* File Name : AddOneToNumber.java
7+
* Book Title : Data Structures And Algorithms Made In Java
8+
* Warranty : This software is provided "as is" without any
9+
* warranty; without even the implied warranty of
10+
* merchantability or fitness for a particular purpose.
11+
*
12+
*/
13+
14+
15+
package chapter21miscconcepts;
16+
17+
public class AddOneToNumber {
18+
public int[] addOneToNumber(int[] digits) {
19+
int[] result = new int[digits.length];
20+
int one = 1;
21+
22+
for(int i = digits.length-1;i>=0;i--){
23+
result[i] = (digits[i]+one) % 10;
24+
one = (digits[i]+one) / 10;
25+
}
26+
27+
if(one!=0){
28+
int[] more = new int[digits.length+1];
29+
more[0] = one;
30+
System.arraycopy(result, 0, more, 1, result.length);
31+
result = more;
32+
}
33+
return result;
34+
}
35+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*Copyright (c) Dec 22, 2014 CareerMonk Publications and others.
2+
* E-Mail : info@careermonk.com
3+
* Creation Date : 2015-01-10 06:15:46
4+
* Last modification : 2006-05-31
5+
by : Narasimha Karumanchi
6+
* File Name : CheckEndian.java
7+
* Book Title : Data Structures And Algorithms Made In Java
8+
* Warranty : This software is provided "as is" without any
9+
* warranty; without even the implied warranty of
10+
* merchantability or fitness for a particular purpose.
11+
*
12+
*/
13+
14+
15+
package chapter21miscconcepts;
16+
17+
import java.nio.ByteOrder;
18+
public class CheckEndian {
19+
public static boolean isBigEndian() {
20+
if(ByteOrder.nativeOrder().equals(ByteOrder.BIG_ENDIAN))
21+
return true;
22+
return false;
23+
}
24+
public static boolean isLittleEndian() {
25+
if(ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN))
26+
return true;
27+
return false;
28+
}
29+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package chapter21miscconcepts;
2+
/*Copyright (c) Dec 22, 2014 CareerMonk Publications and others.
3+
* E-Mail : info@careermonk.com
4+
* Creation Date : 2015-01-10 06:15:46
5+
* Last modification : 2006-05-31
6+
by : Narasimha Karumanchi
7+
* File Name : Equilibrium.java
8+
* Book Title : Data Structures And Algorithms Made In Java
9+
* Warranty : This software is provided "as is" without any
10+
* warranty; without even the implied warranty of
11+
* merchantability or fitness for a particular purpose.
12+
*
13+
*/
14+
15+
public class Equilibrium {
16+
public static int equilibrium(int[] A){
17+
int sum = 0;
18+
int leftsum = 0;
19+
int i;
20+
21+
for(i = 0;i<A.length;i++){
22+
sum += A[i];
23+
}
24+
25+
for(i = 0; i<A.length;i++){
26+
sum -= A[i];
27+
if(leftsum == sum){
28+
return i;
29+
}
30+
leftsum += A[i];
31+
}
32+
return -1;
33+
}
34+
public static void main(String[] args) {
35+
int[] A = {-7,1,5,2,-4,3,0};
36+
System.out.print(equilibrium(A)); // Would Print 3
37+
}
38+
}

0 commit comments

Comments
 (0)