- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrings.java
More file actions
Latest commit
91 lines (75 loc) · 1.73 KB
/
Copy pathStrings.java
File metadata and controls
91 lines (75 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
packagecracking.coding;
publicclassStrings {
publicstaticvoidmain(String[] args){
//isUniqueCharString("prabhu");
//isPermute("ravi","vira");
//System.out.println(Integer.bitCount((3^5)));
//System.out.println(convertDoubletoBinary(0.7));
System.out.println(checkbits(1, 3));
}
publicstaticintisUniqueCharString(Stringstr){
intchecker=0;
for(inti=0;i<str.length();i++){
intval = str.charAt(i) - 'a';
if((checker & (1<<val)) > 0){
System.out.println("Not Unique");
return0;
}
checker |= (1<<val);
}
System.out.println("Unique");
return1;
}
publicstaticintisPermute(Stringstr1, Stringstr2){
if(str1.length()!=str2.length()){
System.out.println("not equal");
return -1;
}
intchecker1= getStringBits(str1);
intchecker2= getStringBits(str2);
if(checker1 != checker2){
System.out.println("Not Permutation");
}else
System.out.println("Permutaion");
return1;
}
publicstaticintgetStringBits(Stringstr){
intchecker =0;
for(inti=0;i<str.length();i++){
intval = str.charAt(i)-'a';
checker |= (1<<val);
}
returnchecker;
}
publicstaticStringconvertDoubletoBinary(doublenum){
if(num >= 1 || num <= 0){
return"ERROR1";
}
System.out.println(num);
StringBuilderbinary = newStringBuilder();
doublefrac = 0.5;
binary.append(".");
while(num > 0){
if(binary.length()>32)
return"ERROR";
if(num>=frac){
binary.append(1);
num -= frac;
}else{
binary.append(0);
}
frac /= 2;
}
returnbinary.toString();
}
publicstaticintcheckbits(inta, intb){
intxor = a^b;
intcount=0;
while(xor > 0){
if((xor&1)>0)
count++;
xor >>= 1;
}
returncount;
}
}