Merge pull request #19 from cwiki-us-docs/code_bank
First Unique Character in a String
This commit is contained in:
commit
baa8c9d58f
toolkits/codebank/src
main/java/com/ossez/toolkits/codebank/common/model/request
test/java/com/ossez/toolkits/codebank/tests
20
toolkits/codebank/src/main/java/com/ossez/toolkits/codebank/common/model/request/TopicRequest.java
20
toolkits/codebank/src/main/java/com/ossez/toolkits/codebank/common/model/request/TopicRequest.java
@ -1,6 +1,10 @@
|
||||
package com.ossez.toolkits.codebank.common.model.request;
|
||||
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
/**
|
||||
@ -79,4 +83,20 @@ public class TopicRequest implements Serializable {
|
||||
public void setCreated_at(String created_at) {
|
||||
this.created_at = created_at;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
TopicRequest that = (TopicRequest) o;
|
||||
|
||||
return new EqualsBuilder().append(title, that.title).append(topic_id, that.topic_id).append(raw, that.raw).append(category, that.category).append(target_recipients, that.target_recipients).append(archetype, that.archetype).append(created_at, that.created_at).isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37).append(title).append(topic_id).append(raw).append(category).append(target_recipients).append(archetype).append(created_at).toHashCode();
|
||||
}
|
||||
}
|
||||
|
59
toolkits/codebank/src/test/java/com/ossez/toolkits/codebank/tests/BlackboardTest.java
Normal file
59
toolkits/codebank/src/test/java/com/ossez/toolkits/codebank/tests/BlackboardTest.java
Normal file
@ -0,0 +1,59 @@
|
||||
package com.ossez.toolkits.codebank.tests;
|
||||
|
||||
import com.google.api.gbase.client.NumberUnit;
|
||||
import com.ossez.toolkits.codebank.common.model.request.TopicRequest;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* This is the test file for something like to quick run.
|
||||
* Once test finished, we need to move codes to different name, just like when we were student we like to eraser after using.
|
||||
*
|
||||
* @author YuCheng
|
||||
*/
|
||||
public class BlackboardTest {
|
||||
private final static Logger logger = LoggerFactory.getLogger(BlackboardTest.class);
|
||||
|
||||
private static List<Integer> loopList = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Main Test to Run
|
||||
*/
|
||||
@Test
|
||||
public void testMain() {
|
||||
logger.debug("TREE TEST");
|
||||
|
||||
TopicRequest topicRequest = new TopicRequest();
|
||||
// topicRequest.setTopic_id(11);
|
||||
logger.debug("HashCode 1 - {}", topicRequest.hashCode());
|
||||
|
||||
logger.debug("HashCode AaAaAa - {}", "AaAaAa".hashCode());
|
||||
logger.debug("HashCode BBAaBB - {}", "BBAaBB".hashCode());
|
||||
|
||||
// if((1/2) && false) {
|
||||
//
|
||||
// }
|
||||
|
||||
// topicRequest = new TopicRequest();
|
||||
logger.debug("HashCode 2 - {}", topicRequest.hashCode());
|
||||
|
||||
String data = "{1,2,3,4,5,#,6,#,#,7,8,#,#}";
|
||||
|
||||
this.subLogic(data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param data
|
||||
*/
|
||||
private void subLogic(String data) {
|
||||
logger.debug("Print Val - [{}]", data);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -6,6 +6,8 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -17,43 +19,62 @@ import java.util.ArrayList;
|
||||
* "https://leetcode.com/problems/first-unique-character-in-a-string/">https://leetcode.com/problems/first-unique-character-in-a-string/</a>
|
||||
* </ul>
|
||||
* </p>
|
||||
*
|
||||
* @author YuCheng
|
||||
*
|
||||
* @author YuCheng
|
||||
*/
|
||||
public class LeetCode0387FirstUniqueCharacterTest {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(LeetCode0387FirstUniqueCharacterTest.class);
|
||||
private final static Logger logger = LoggerFactory.getLogger(LeetCode0387FirstUniqueCharacterTest.class);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testMain() {
|
||||
logger.debug("BEGIN");
|
||||
String data = "leetcode";
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testMain() {
|
||||
logger.debug("BEGIN");
|
||||
String data = "lovelycomossez";
|
||||
|
||||
System.out.println(firstUniqChar(data));
|
||||
System.out.println(firstUniqChar(data));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize from array to tree
|
||||
*
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
private int firstUniqChar(String data) {
|
||||
// NULL CHECK
|
||||
if (data.equals("")) {
|
||||
return -1;
|
||||
}
|
||||
/**
|
||||
* Deserialize from array to tree
|
||||
*
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
private int firstUniqChar(String data) {
|
||||
// NULL CHECK
|
||||
if (data.equals("")) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int retVal = -1;
|
||||
LinkedHashMap<Character, String> retMap = new LinkedHashMap<Character, String>();
|
||||
char[] chStr = data.toCharArray();
|
||||
|
||||
|
||||
return 0;
|
||||
for (int i = 0; i < chStr.length; i++) {
|
||||
if (retMap.get(chStr[i]) != null) {
|
||||
retMap.put(chStr[i], retMap.get(chStr[i]) + "#" + String.valueOf(i));
|
||||
} else {
|
||||
retMap.put(chStr[i], String.valueOf(i));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
for (Map.Entry me : retMap.entrySet()) {
|
||||
String val = "" + me.getValue();
|
||||
if (!val.contains("#")) {
|
||||
retVal = Integer.valueOf(val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return retVal;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user