Binary Gap
This commit is contained in:
parent
518be6812e
commit
7410261971
16
.idea/checkstyle-idea.xml
generated
Normal file
16
.idea/checkstyle-idea.xml
generated
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CheckStyle-IDEA" serialisationVersion="2">
|
||||
<checkstyleVersion>10.12.4</checkstyleVersion>
|
||||
<scanScope>JavaOnly</scanScope>
|
||||
<copyLibs>true</copyLibs>
|
||||
<option name="thirdPartyClasspath" />
|
||||
<option name="activeLocationIds" />
|
||||
<option name="locations">
|
||||
<list>
|
||||
<ConfigurationLocation id="bundled-sun-checks" type="BUNDLED" scope="All" description="Sun Checks">(bundled)</ConfigurationLocation>
|
||||
<ConfigurationLocation id="bundled-google-checks" type="BUNDLED" scope="All" description="Google Checks">(bundled)</ConfigurationLocation>
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
6
.idea/jpa-buddy.xml
generated
Normal file
6
.idea/jpa-buddy.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="JpaBuddyIdeaProjectConfig">
|
||||
<option name="renamerInitialized" value="true" />
|
||||
</component>
|
||||
</project>
|
@ -64,64 +64,3 @@ N is an integer within the range [1..2,147,483,647].
|
||||
源代码和有关代码的更新请访问 GitHub:
|
||||
|
||||
https://github.com/cwiki-us/java-tutorial/blob/master/src/test/java/com/ossez/lang/tutorial/tests/codility/CodilityBinaryGapTest.java
|
||||
|
||||
代码思路请参考:
|
||||
|
||||
```java
|
||||
package com.ossez.lang.tutorial.tests.codility;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* More details about question see link below
|
||||
* <ul>
|
||||
* <li>@see <a href= "https://www.cwiki.us/display/ITCLASSIFICATION/Binary+Gap">https://www.cwiki.us/display/ITCLASSIFICATION/Binary+Gap</a>
|
||||
* </li>
|
||||
* </ul>
|
||||
* </p>
|
||||
*
|
||||
* @author YuCheng
|
||||
*
|
||||
*/
|
||||
public class CodilityBinaryGapTest {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(CodilityBinaryGapTest.class);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testMain() {
|
||||
logger.debug("BEGIN");
|
||||
|
||||
int N = 529;
|
||||
String intStr = Integer.toBinaryString(N);
|
||||
|
||||
intStr = intStr.replace("1", "#1#");
|
||||
|
||||
String[] strArray = intStr.split("1");
|
||||
|
||||
int maxCount = 0;
|
||||
for (int i = 0; i < strArray.length; i++) {
|
||||
String checkStr = strArray[i];
|
||||
int countLength = 0;
|
||||
|
||||
if (checkStr.length() > 2 && checkStr.startsWith("#") && checkStr.endsWith("#")) {
|
||||
checkStr = checkStr.replace("#", "");
|
||||
countLength = checkStr.length();
|
||||
|
||||
if (maxCount < countLength) {
|
||||
maxCount = countLength;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("MAX COUNT: [{}]", maxCount);
|
||||
}
|
||||
|
||||
}
|
||||
```
|
Loading…
x
Reference in New Issue
Block a user