Skip to content

Commit 9f965af

Browse files
authored
Merge pull request onlyliuxin#43 from haolipeng/master
Master
2 parents ebe1828 + 09d373f commit 9f965af

File tree

105 files changed

+3344
-199
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+3344
-199
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 2017编程提高社群
2+
3+
2017编程提高社群代码仓库所在地

group01/group01.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+

group02/group02.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+

group03/group03.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+

group04/group04.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+

group05/group05.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+

group06/group06.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+

group07/group07.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+

group08/group08.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+

group09/group09.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+

group10/group10.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+

group11/group11.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+

group12/group12.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+

group13/group13.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+

group14/group14.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+

group15/group15.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+

group16/group16.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+

group17/group17.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+

group18/1049843090/.classpath

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
4+
<classpathentry kind="src" path="src"/>
5+
<classpathentry kind="src" path="test"/>
6+
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/.jar"/>
7+
<classpathentry kind="lib" path="lib/junit-4.12.jar"/>
8+
<classpathentry kind="lib" path="lib/hamcrest-core-1.3.jar"/>
9+
<classpathentry kind="output" path="out/production/1049843090"/>
10+
</classpath>

group18/1049843090/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*.idea
2+
*.iml
3+
*.eml
4+
.settings/
5+
target/
6+
build/
7+
out/

group18/1049843090/.project

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>1049843090</name>
4+
<comment/>
5+
<projects/>
6+
<buildSpec>
7+
<buildCommand>
8+
<name>org.eclipse.jdt.core.javabuilder</name>
9+
<arguments/>
10+
</buildCommand>
11+
</buildSpec>
12+
<natures>
13+
<nature>org.eclipse.jdt.core.javanature</nature>
14+
</natures>
15+
</projectDescription>
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
package com.coderising.array;
2+
3+
4+
import com.coding.basic.Queue;
5+
import com.coding.basic.Stack;
6+
7+
public class ArrayUtil {
8+
9+
/**
10+
* 给定一个整形数组a , 对该数组的值进行置换
11+
* 例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7]
12+
* 如果 a = [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7]
13+
*
14+
* @param origin
15+
* @return
16+
*/
17+
public void reverseArray(int[] origin) {
18+
if (isEmptyOrNull(origin)) {
19+
return;
20+
}
21+
//solution 1 move element
22+
//for (int i = 0; i <= origin.length >> 2; i++) {
23+
// int temp = origin[i];
24+
// origin[i] = origin[origin.length - 1 - i];
25+
// origin[origin.length - 1 - i] = temp;
26+
//}
27+
28+
//solution 2 use Stack
29+
Stack<Integer> stack = new Stack<>();
30+
for (int i : origin) {
31+
stack.push(i);
32+
}
33+
for (int i = 0; i < origin.length; i++) {
34+
origin[i]=stack.pop();
35+
}
36+
}
37+
38+
/**
39+
* 现在有如下的一个数组: int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5}
40+
* 要求将以上数组中值为0的项去掉,将不为0的值存入一个新的数组,生成的新数组为:
41+
* {1,3,4,5,6,6,5,4,7,6,7,5}
42+
*
43+
* @param oldArray
44+
* @return
45+
*/
46+
47+
public int[] removeZero(int[] oldArray) {
48+
if (isEmptyOrNull(oldArray)) {
49+
return null;
50+
}
51+
//solution 1 use Queue OR Stack
52+
//Queue<Integer> queue = new Queue<>();
53+
//for (int i : oldArray) {
54+
// if (i != 0) {
55+
// queue.enQueue(i);
56+
// }
57+
//}
58+
//int[] newArray = new int[queue.size()];
59+
//for (int i = 0; i < newArray.length; i++) {
60+
// newArray[i] = queue.deQueue();
61+
//}
62+
//return newArray;
63+
64+
65+
//solution 2 use Array
66+
int[] tempArray = new int[oldArray.length];
67+
int index = 0;
68+
for (int i = 0; i < oldArray.length; i++) {
69+
if (oldArray[i] != 0) {
70+
tempArray[index++] = oldArray[i];
71+
}
72+
}
73+
int[] newArray = new int[index];
74+
System.arraycopy(tempArray,0,newArray,0,index);
75+
return newArray;
76+
}
77+
78+
/**
79+
* 给定两个已经排序好的整形数组, a1和a2 , 创建一个新的数组a3, 使得a3 包含a1和a2 的所有元素, 并且仍然是有序的
80+
* 例如 a1 = [3, 5, 7,8] a2 = [4, 5, 6,7] 则 a3 为[3,4,5,6,7,8] , 注意: 已经消除了重复
81+
*
82+
* @param array1
83+
* @param array2
84+
* @return
85+
*/
86+
87+
public int[] merge(int[] array1, int[] array2) {
88+
89+
return null;
90+
}
91+
92+
/**
93+
* 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size
94+
* 注意,老数组的元素在新数组中需要保持
95+
* 例如 oldArray = [2,3,6] , size = 3,则返回的新数组为
96+
* [2,3,6,0,0,0]
97+
*
98+
* @param oldArray
99+
* @param size
100+
* @return
101+
*/
102+
public int[] grow(int[] oldArray, int size) {
103+
if (isEmptyOrNull(oldArray)) {
104+
return null;
105+
}
106+
int[] newArray = new int[oldArray.length + size];
107+
//solution 1 use System.arraycopy
108+
//System.arraycopy(oldArray,0,newArray,0, oldArray.length);
109+
110+
//solution 2 use loop
111+
for (int i = 0; i < oldArray.length; i++) {
112+
newArray[i] = oldArray[i];
113+
}
114+
return newArray;
115+
}
116+
117+
/**
118+
* 斐波那契数列为:1,1,2,3,5,8,13,21...... ,给定一个最大值, 返回小于该值的数列
119+
* 例如, max = 15 , 则返回的数组应该为 [1,1,2,3,5,8,13]
120+
* max = 1, 则返回空数组 []
121+
*
122+
* @param max
123+
* @return
124+
*/
125+
public int[] fibonacci(int max) {
126+
return null;
127+
}
128+
129+
/**
130+
* 返回小于给定最大值max的所有素数数组
131+
* 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
132+
*
133+
* @param max
134+
* @return
135+
*/
136+
public int[] getPrimes(int max) {
137+
return null;
138+
}
139+
140+
/**
141+
* 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3
142+
* 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数
143+
*
144+
* @param max
145+
* @return
146+
*/
147+
public int[] getPerfectNumbers(int max) {
148+
return null;
149+
}
150+
151+
/**
152+
* 用seperator 把数组 array给连接起来
153+
* 例如array= [3,8,9], seperator = "-"
154+
* 则返回值为"3-8-9"
155+
*
156+
* @param array
157+
* @param seperator 分隔符
158+
* @return
159+
*/
160+
public String join(int[] array, String seperator) {
161+
if (isEmptyOrNull(array)) {
162+
return "";
163+
}
164+
if (array.length < 2) {
165+
return array[0] + "";
166+
}
167+
StringBuffer stringBuffer = new StringBuffer();
168+
for (int i = 0; i < array.length - 1; i++) {
169+
stringBuffer.append(array[i] + seperator);
170+
}
171+
stringBuffer.append(array[array.length - 1]);
172+
return stringBuffer.toString();
173+
}
174+
175+
/**
176+
* 检查数组是否为空或者为null
177+
*
178+
* @param array
179+
* @return
180+
*/
181+
private boolean isEmptyOrNull(int[] array) {
182+
if (array == null || array.length == 0) {
183+
return true;
184+
}
185+
return false;
186+
}
187+
188+
public static void main(String[] args) {
189+
int[] a = {7,9,5};
190+
ArrayUtil arrayUtil = new ArrayUtil();
191+
arrayUtil.reverseArray(a);
192+
for (int i : a) {
193+
System.out.println(i);
194+
}
195+
}
196+
197+
}

0 commit comments

Comments
 (0)