FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
crackingCodingInterview/Moderate.java at master · kumarravi/crackingCodingInterview · GitHub
kumarravi
crackingCodingInterview
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
crackingCodingInterview
/
Moderate.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
31 lines (23 loc) · 519 Bytes
Breadcrumbs
crackingCodingInterview
/
Moderate.java
Copy path
File metadata and controls
31 lines (23 loc) · 519 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package
cracking
.
coding
;
public
class
Moderate
{
public
static
void
main
(
String
args
[]){
Moderate
test
=
new
Moderate
();
System
.
out
.
println
(
test
.
getMaxNaive
(-
8
, -
9
));
}
public
int
getMaxNaive
(
int
a
,
int
b
){
int
sa
=
sign
(
a
);
int
sb
=
sign
(
b
);
int
sc
=
sign
(
a
-
b
);
int
using_a
=
sa
^
sb
;
int
using_c
=
flip
(
sa
^
sb
);
int
k
=
using_a
*
sa
+
using_c
*
sc
;
int
l
=
flip
(
k
);
return
a
*
k
+
b
*
l
;
}
public
int
sign
(
int
a
){
return
flip
((
a
>>
31
) &
0x1
);
}
public
int
flip
(
int
a
){
return
a
^
1
;
}
}
Back
|
FazBrowse Home
|
New Git URL