-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚚 rename pkg and add <Fold an array>.
- Loading branch information
1 parent
2e43dee
commit 540a8fa
Showing
10 changed files
with
47 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package java; | ||
package javasolutions; | ||
|
||
/** | ||
* @ClassName BitCounting | ||
|
2 changes: 1 addition & 1 deletion
2
java/CountingDuplicates.java → javasolutions/CountingDuplicates.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package java; | ||
package javasolutions; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package java; | ||
package javasolutions; | ||
|
||
/** | ||
* @ClassName FindUniq | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package javasolutions; | ||
|
||
import java.util.Arrays; | ||
|
||
/** | ||
* @ClassName FoldArray | ||
* @Description: ref: https://www.codewars.com/kata/57ea70aa5500adfe8a000110/train/java | ||
* @Author gravel | ||
* @Date 2020/1/21 | ||
* @Version V1.0 | ||
**/ | ||
public class FoldArray { | ||
public static int[] foldArray(int[] array, int runs) { | ||
if (array == null || array.length < 2) return array; | ||
if (runs == 0) return array; | ||
int l = 0; | ||
int r = array.length - 1; | ||
int len = array.length; | ||
int[] copyArr = Arrays.copyOf(array,len); | ||
while (runs > 0) { | ||
while (l < r) { | ||
copyArr[l] = copyArr[l] + copyArr[r]; | ||
l++; | ||
r--; | ||
} | ||
double c = ((double) len) / 2; | ||
len = (int) Math.ceil(c); | ||
runs--; | ||
l = 0; | ||
r = len - 1; | ||
} | ||
return Arrays.copyOf(copyArr, len); | ||
} | ||
|
||
public static void main(String[] args) { | ||
System.out.println(Arrays.toString(foldArray(new int[]{1, 2, 3, 4, 5}, 3))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package java; | ||
package javasolutions; | ||
|
||
/** | ||
* @ClassName Multiples3or5 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package java; | ||
package javasolutions; | ||
|
||
/** | ||
* @ClassName Multiply | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package java; | ||
package javasolutions; | ||
|
||
/** | ||
* @ClassName SortArray | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package java; | ||
package javasolutions; | ||
|
||
/** | ||
* @ClassName Square | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package java; | ||
package javasolutions; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package java; | ||
package javasolutions; | ||
|
||
/** | ||
* @ClassName ValidatePin | ||
|