Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4e341c7

Browse files
committed
gray
1 parent6207734 commit4e341c7

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

‎algorithm/others/Reverse_binary.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
packageAlgorithms.algorithm.others;
2+
3+
publicclassReverse_binary {
4+
publicstaticvoidmain(String[]strs) {
5+
System.out.println(reverse(20034556));
6+
}
7+
8+
publicstaticintreverse(intin) {
9+
intret =0;
10+
11+
for (inti =0;i <4;i++) {
12+
inttmp = (in &0xFF);
13+
ret <<=8;
14+
ret +=tmp;
15+
in >>=8;
16+
}
17+
18+
returnret;
19+
}
20+
}

‎recursion/GrayCode.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
packageAlgorithms.recursion;
2+
3+
importjava.util.ArrayList;
4+
importjava.util.List;
5+
6+
publicclassGrayCode {
7+
publicList<Integer>grayCode(intn) {
8+
List<Integer>ret =newArrayList<Integer>();
9+
if (n ==0) {
10+
ret.add(0);
11+
returnret;
12+
}
13+
14+
ret =grayCode(n -1);
15+
16+
for (inti =ret.size() -1;i >=0;i--) {
17+
intnum =ret.get(i);
18+
num +=1 << (n -1);
19+
ret.add(num);
20+
}
21+
22+
returnret;
23+
}
24+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp