FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
leetcode/problems/src/math/Base7.java at master · KindleBooks66/leetcode · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
KindleBooks66
/
leetcode
Public
forked from
gouthampradhan/leetcode
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
leetcode
/
problems
/
src
/
math
/
Base7.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
31 lines (28 loc) · 726 Bytes
Breadcrumbs
leetcode
/
problems
/
src
/
math
/
Base7.java
Copy path
File metadata and controls
31 lines (28 loc) · 726 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
math
;
import
java
.
util
.*;
/**
* Created by gouthamvidyapradhan on 01/08/2019 Given an integer, return its base 7 string
* representation.
*
* <p>Example 1: Input: 100 Output: "202" Example 2: Input: -7 Output: "-10" Note: The input will be
* in range of [-1e7, 1e7].
*/
public
class
Base7
{
public
static
void
main
(
String
[]
args
) {
//
}
public
String
convertToBase7
(
int
num
) {
Integer
.
toString
(
7
,
7
);
if
(
num
==
0
)
return
"0"
;
int
q
=
Math
.
abs
(
num
),
r
;
StringBuilder
sb
=
new
StringBuilder
();
while
(
q
!=
0
) {
r
=
q
%
7
;
sb
.
append
(
r
);
q
/=
7
;
}
if
(
num
<
0
) {
return
"-"
+
sb
.
reverse
().
toString
();
}
else
return
sb
.
reverse
().
toString
();
}
}
Back
|
FazBrowse Home
|
New Git URL