Skip to content

Eason #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add solution
  • Loading branch information
xdongyan committed Aug 8, 2017
commit 35b1bccf1a3821d3c4a9b6ce7e4fa7ccda6510a2
16 changes: 16 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/libraries/Maven__junit_junit_4_12.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions leetcode-algorithms.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
</component>
</module>
24 changes: 22 additions & 2 deletions src/main/java/com/fishercoder/solutions/_459.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,28 @@ public static boolean repeatedSubstringPattern(String str) {
}
}

return (pattern[n-1] > 0 && n%(n-pattern[n-1]) == 0);
return (pattern[n - 1] > 0 && n % (n-pattern[n - 1]) == 0);
}
// the idea is that the length substring will be divisor of the length s, then find the
//sub string and append s.length/sub.length times to check if the string is equaled to the original string.
//credit:
public static boolean repeatedSubstringPattern_2(String s) {
int len = s.length();
for (int i = len/2; i >=1; i--) {
if (len % i == 0) {
int n = len / i;
String sub = s.substring(0, i);
StringBuilder sb = new StringBuilder();
for (int j = 0; j < n; j++) {
sb.append(sub);
}
if (sb.toString().equals(s)) {
return true;
}
}
}
return false;
}

public static void main(String...args){
// String str = "aba";
// String str = "abab";//should be true
Expand All @@ -47,5 +66,6 @@ public static void main(String...args){
// String str = "abababc";
String str = "abababaaba";
System.out.println(repeatedSubstringPattern(str));
System.out.println(repeatedSubstringPattern_2(str));
}
}