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

Appearance settings

Commit d9819e7

Browse filesBrowse files
committed
commit
1 parent d4880a9 commit d9819e7
Copy full SHA for d9819e7

File tree

Expand file treeCollapse file tree

8 files changed

+404
-250
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+404
-250
lines changed

‎.idea/modules.xml

Copy file name to clipboardExpand all lines: .idea/modules.xml
+2Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/workspace.xml

Copy file name to clipboardExpand all lines: .idea/workspace.xml
+249-250Lines changed: 249 additions & 250 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
<orderEntry type="module-library">
11+
<library name="JUnit4">
12+
<CLASSES>
13+
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/" />
14+
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
15+
</CLASSES>
16+
<JAVADOC />
17+
<SOURCES />
18+
</library>
19+
</orderEntry>
20+
<orderEntry type="library" name="R User Library" level="project" />
21+
<orderEntry type="library" name="R Skeletons" level="application" />
22+
</component>
23+
</module>

‎[1089][Duplicate Zeros]/src/Main.java

Copy file name to clipboard
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import org.junit.Assert;
2+
import org.junit.Test;
3+
4+
/**
5+
* @author: wangjunchao(王俊超)
6+
* @time: 2019-07-12 08:53
7+
**/
8+
public class Main {
9+
@Test
10+
public void test1() {
11+
Solution solution = new Solution();
12+
int[] arr = {1, 0, 2, 3, 0, 4, 5, 0};
13+
solution.duplicateZeros(arr);
14+
Assert.assertArrayEquals(new int[]{1, 0, 0, 2, 3, 0, 0, 4}, arr);
15+
}
16+
}
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @author: wangjunchao(王俊超)
3+
* @time: 2019-07-12 08:44
4+
**/
5+
public class Solution {
6+
public void duplicateZeros(int[] arr) {
7+
for (int i = 0; i < arr.length - 1; i++) {
8+
if (arr[i] == 0) {
9+
move(arr, i+1);
10+
arr[i + 1] = 0;
11+
i++;
12+
}
13+
}
14+
}
15+
16+
private void move(int[] arr, int i) {
17+
if (arr.length - 1 - i >= 0) {
18+
System.arraycopy(arr, i, arr, i + 1, arr.length - 1 - i);
19+
}
20+
}
21+
}
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
<orderEntry type="module-library">
11+
<library name="JUnit4">
12+
<CLASSES>
13+
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/" />
14+
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
15+
</CLASSES>
16+
<JAVADOC />
17+
<SOURCES />
18+
</library>
19+
</orderEntry>
20+
<orderEntry type="library" name="R User Library" level="project" />
21+
<orderEntry type="library" name="R Skeletons" level="application" />
22+
</component>
23+
</module>
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import org.junit.Assert;
2+
import org.junit.Test;
3+
4+
/**
5+
* @author: wangjunchao(王俊超)
6+
* @time: 2019-07-12 08:37
7+
**/
8+
public class Main {
9+
@Test
10+
public void test1() {
11+
String address = "1.1.1.1";
12+
Solution solution = new Solution();
13+
Assert.assertEquals("1[.]1[.]1[.]1", solution.defangIPaddr(address));
14+
}
15+
16+
@Test
17+
public void test2() {
18+
String address = "255.100.50.0";
19+
Solution solution = new Solution();
20+
Assert.assertEquals("255[.]100[.]50[.]0", solution.defangIPaddr(address));
21+
}
22+
}
+48Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* https://leetcode.com/problems/defanging-an-ip-address/submissions/
3+
* @author: wangjunchao(王俊超)
4+
* @time: 2019-07-12 08:31
5+
**/
6+
public class Solution {
7+
/**
8+
* <pre>
9+
* Given a valid (IPv4) IP address, return a defanged version of that IP address.
10+
*
11+
* A defanged IP address replaces every period "." with "[.]".
12+
*
13+
*
14+
*
15+
* Example 1:
16+
*
17+
* Input: address = "1.1.1.1"
18+
* Output: "1[.]1[.]1[.]1"
19+
* Example 2:
20+
*
21+
* Input: address = "255.100.50.0"
22+
* Output: "255[.]100[.]50[.]0"
23+
* </pre>
24+
* @param address
25+
* @return
26+
*/
27+
public String defangIPaddr(String address) {
28+
if (address ==null || address.length() < 1) {
29+
return address;
30+
}
31+
32+
StringBuilder builder = new StringBuilder(address.length() * 2);
33+
34+
for (int i = 0; i < address.length(); i++) {
35+
char ch = address.charAt(i);
36+
if (Character.isDigit(ch)) {
37+
builder.append(ch);
38+
} else if (ch == '.') {
39+
builder.append("[.]");
40+
} else {
41+
throw new IllegalArgumentException(address + " contains invalid char");
42+
}
43+
}
44+
45+
46+
return builder.toString();
47+
}
48+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.