Date: Wed, 26 Dec 2018 17:38:46 -0500
Subject: [PATCH 14/33] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8C=85=E7=9A=84?=
=?UTF-8?q?=E5=90=8D=E5=AD=97=E8=BF=9B=E8=A1=8C=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../java/com/ossez/codebank/algorithm/tests/LintcodeTest.java | 2 +-
.../java/com/ossez/codebank/algorithm/tests/TreeTest.java | 4 ++--
.../lintcode/LintCode0007SerializeAndDeserializeTest.java | 2 +-
.../algorithm/tests/lintcode/LintCode0069LevelOrderTest.java | 2 +-
.../algorithm/tests/lintcode/LintCode0102HasCycleTest.java | 2 +-
.../tests/lintcode/LintCode0165MergeTwoListsTest.java | 2 +-
6 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/test/java/com/ossez/codebank/algorithm/tests/LintcodeTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/LintcodeTest.java
index 566fee90ea..a290d6716e 100644
--- a/src/test/java/com/ossez/codebank/algorithm/tests/LintcodeTest.java
+++ b/src/test/java/com/ossez/codebank/algorithm/tests/LintcodeTest.java
@@ -17,7 +17,7 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.ossez.lang.tutorial.models.ListNode;
+import com.ossez.codebank.algorithm.models.ListNode;
/**
*
diff --git a/src/test/java/com/ossez/codebank/algorithm/tests/TreeTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/TreeTest.java
index 6f88cd156e..93a489f5bb 100644
--- a/src/test/java/com/ossez/codebank/algorithm/tests/TreeTest.java
+++ b/src/test/java/com/ossez/codebank/algorithm/tests/TreeTest.java
@@ -7,8 +7,8 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.ossez.lang.tutorial.models.TreeNode;
-import com.ossez.lang.tutorial.utils.TreeUtils;
+import com.ossez.codebank.algorithm.models.TreeNode;
+import com.ossez.codebank.algorithml.utils.TreeUtils;
/**
*
diff --git a/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0007SerializeAndDeserializeTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0007SerializeAndDeserializeTest.java
index ad21270072..747c16f0ff 100644
--- a/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0007SerializeAndDeserializeTest.java
+++ b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0007SerializeAndDeserializeTest.java
@@ -6,7 +6,7 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.ossez.lang.tutorial.models.TreeNode;
+import com.ossez.codebank.algorithm.models.TreeNode;
/**
*
diff --git a/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0069LevelOrderTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0069LevelOrderTest.java
index 5a35ff7b73..e9b7b0b46a 100644
--- a/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0069LevelOrderTest.java
+++ b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0069LevelOrderTest.java
@@ -9,7 +9,7 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.ossez.lang.tutorial.models.TreeNode;
+import com.ossez.codebank.algorithm.models.TreeNode;
/**
*
diff --git a/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0102HasCycleTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0102HasCycleTest.java
index e20e2d6b72..1b3a94d775 100644
--- a/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0102HasCycleTest.java
+++ b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0102HasCycleTest.java
@@ -4,7 +4,7 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.ossez.lang.tutorial.models.ListNode;
+import com.ossez.codebank.algorithm.models.ListNode;
/**
*
diff --git a/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0165MergeTwoListsTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0165MergeTwoListsTest.java
index 6591addbbb..c1bc3ebd00 100644
--- a/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0165MergeTwoListsTest.java
+++ b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0165MergeTwoListsTest.java
@@ -4,7 +4,7 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.ossez.lang.tutorial.models.ListNode;
+import com.ossez.codebank.algorithm.models.ListNode;
/**
*
From d12dd975c0d6052d5d9fad0bc897c545f67624e1 Mon Sep 17 00:00:00 2001
From: YuCheng Hu
Date: Wed, 26 Dec 2018 17:53:11 -0500
Subject: [PATCH 15/33] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=B0=E7=9A=84?=
=?UTF-8?q?=E6=B5=8B=E8=AF=95=20JUnit=20=E7=B1=BB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 489 ++++++++++++++++++++++++++++----------------------------
1 file changed, 245 insertions(+), 244 deletions(-)
diff --git a/pom.xml b/pom.xml
index 7d0a1daad3..b7812d8ab3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,245 +1,246 @@
-
- 4.0.0
- com.ossez
- codebank-algorithm
- 0.0.1
-
-
-
- 1.8
- UTF-8
- UTF-8
-
-
- 1.7.12
- 2.2
-
-
-
- 4.3.5.Final
-
-
- 4.3.1.Final
-
-
- 7.0.42
- 2.6.8
- 2.3.2
-
-
- 4.11
- 1.3
-
-
- 1.9.0
-
-
-
-
-
-
-
- org.apache.logging.log4j
- log4j-slf4j-impl
- 2.11.0
-
-
-
-
- org.apache.commons
- commons-compress
- 1.18
-
-
-
- org.apache.commons
- commons-math3
- 3.6.1
-
-
-
- antlr
- antlr
- 2.7.6
-
-
-
- dom4j
- dom4j
- 1.6.1
-
-
- commons-cli
- commons-cli
- 1.2
-
-
- org.apache.velocity
- velocity-tools
- 2.0
-
-
-
- jaxen
- jaxen
- 1.1.6
-
-
-
- javax.persistence
- persistence-api
- 1.0.2
-
-
- com.google.guava
- guava
- 17.0
-
-
- com.google.gdata
- core
- 1.47.1
-
-
-
- org.ow2.orchestra.eclipse.birt
- org.ow2.orchestra.eclipse.birt.core
- 3.7.0
-
-
- org.ow2.orchestra.eclipse.birt
- org.ow2.orchestra.eclipse.birt.report.engine
- 3.7.0
-
-
- commons-net
- commons-net
- 2.0
-
-
-
- com.mchange
- mchange-commons-java
- 0.2.9
-
-
-
- junit
- junit
- 4.12
-
-
- org.jasypt
- jasypt
- 1.5
-
-
-
- httpunit
- httpunit
- 1.7
-
-
- net.sf.jazzy
- jazzy
- 0.5.2-rtext-1.4.1
-
-
- net.sf.json-lib
- json-lib
- 2.4
- jdk15
-
-
- rome
- rome
- 0.9
-
-
-
- org.apache.httpcomponents
- httpmime
- 4.5.1
-
-
-
- org.jsoup
- jsoup
- 1.7.2
-
-
-
- net.lingala.zip4j
- zip4j
- 1.3.2
-
-
-
-
-
- package
-
-
- maven-compiler-plugin
- 3.1
-
-
- ${java.version}
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
- 2.12.4
-
- true
-
-
-
- org.apache.maven.plugins
- maven-jar-plugin
- 2.6
-
-
-
- com.ossez.reoc.rets.Main
- true
- lib/
-
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-assembly-plugin
- 2.6
-
-
-
- package
-
- single
-
-
- src/assembly/zipAssembly.xml
- reoc-rets
-
-
- com.ossez.reoc.rets.Main
-
-
- ./
-
-
-
-
-
-
-
-
-
-
+
+ 4.0.0
+ com.ossez
+ codebank-algorithm
+ 0.0.1
+
+
+
+ 1.8
+ UTF-8
+ UTF-8
+
+
+ 1.7.12
+ 2.2
+
+
+
+ 4.3.5.Final
+
+
+ 4.3.1.Final
+
+
+ 7.0.42
+ 2.6.8
+ 2.3.2
+
+
+ 1.9.0
+
+
+
+
+
+
+
+ org.apache.logging.log4j
+ log4j-slf4j-impl
+ 2.11.0
+
+
+
+
+ junit
+ junit
+ 4.12
+
+
+
+
+
+ org.apache.commons
+ commons-compress
+ 1.18
+
+
+
+ org.apache.commons
+ commons-math3
+ 3.6.1
+
+
+
+ antlr
+ antlr
+ 2.7.6
+
+
+
+ dom4j
+ dom4j
+ 1.6.1
+
+
+ commons-cli
+ commons-cli
+ 1.2
+
+
+ org.apache.velocity
+ velocity-tools
+ 2.0
+
+
+
+ jaxen
+ jaxen
+ 1.1.6
+
+
+
+ javax.persistence
+ persistence-api
+ 1.0.2
+
+
+ com.google.guava
+ guava
+ 17.0
+
+
+ com.google.gdata
+ core
+ 1.47.1
+
+
+
+ org.ow2.orchestra.eclipse.birt
+ org.ow2.orchestra.eclipse.birt.core
+ 3.7.0
+
+
+ org.ow2.orchestra.eclipse.birt
+ org.ow2.orchestra.eclipse.birt.report.engine
+ 3.7.0
+
+
+ commons-net
+ commons-net
+ 2.0
+
+
+
+ com.mchange
+ mchange-commons-java
+ 0.2.9
+
+
+
+
+ org.jasypt
+ jasypt
+ 1.5
+
+
+
+ httpunit
+ httpunit
+ 1.7
+
+
+ net.sf.jazzy
+ jazzy
+ 0.5.2-rtext-1.4.1
+
+
+ net.sf.json-lib
+ json-lib
+ 2.4
+ jdk15
+
+
+ rome
+ rome
+ 0.9
+
+
+
+ org.apache.httpcomponents
+ httpmime
+ 4.5.1
+
+
+
+ org.jsoup
+ jsoup
+ 1.7.2
+
+
+
+ net.lingala.zip4j
+ zip4j
+ 1.3.2
+
+
+
+
+
+ package
+
+
+ maven-compiler-plugin
+ 3.1
+
+
+ ${java.version}
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.12.4
+
+ true
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 2.6
+
+
+
+ com.ossez.reoc.rets.Main
+ true
+ lib/
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+ 2.6
+
+
+
+ package
+
+ single
+
+
+ src/assembly/zipAssembly.xml
+ reoc-rets
+
+
+ com.ossez.reoc.rets.Main
+
+
+ ./
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
From edd772d01c837323545ca37e04fc0b52d0aaecef Mon Sep 17 00:00:00 2001
From: YuCheng Hu
Date: Thu, 27 Dec 2018 13:35:36 -0500
Subject: [PATCH 16/33] =?UTF-8?q?=E5=B1=95=E5=B9=B3=E6=95=B0=E7=BB=84?=
=?UTF-8?q?=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 7 +++
.../interview/tests/PillPackTest.java | 57 +++++++++++++++++++
2 files changed, 64 insertions(+)
create mode 100644 src/test/java/com/ossez/codebank/interview/tests/PillPackTest.java
diff --git a/pom.xml b/pom.xml
index b7812d8ab3..ab0ef42ad2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -49,6 +49,13 @@
4.12
+
+
+ org.apache.commons
+ commons-email
+ 1.5
+
+
diff --git a/src/test/java/com/ossez/codebank/interview/tests/PillPackTest.java b/src/test/java/com/ossez/codebank/interview/tests/PillPackTest.java
new file mode 100644
index 0000000000..d9df81fc62
--- /dev/null
+++ b/src/test/java/com/ossez/codebank/interview/tests/PillPackTest.java
@@ -0,0 +1,57 @@
+package com.ossez.codebank.interview.tests;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Stream;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.ossez.codebank.interview.KayakCountUpDown;
+import com.ossez.codebank.interview.KayakRobotMovement;
+
+/**
+ * PillPack
+ *
+ *
+ * https://www.cwiki.us/display/ITCLASSIFICATION/Flatten+Nested+Arrays
+ *
+ *
+ * @author YuCheng
+ *
+ */
+public class PillPackTest {
+
+ private final static Logger logger = LoggerFactory.getLogger(PillPackTest.class);
+
+ List returnList = new ArrayList();
+
+ /**
+ * https://www.cwiki.us/display/ITCLASSIFICATION/Flatten+Nested+Arrays
+ *
+ * FlattenNestedArrays
+ */
+ @Test
+ public void testFlattenNestedArrays() {
+ logger.debug("Test FlattenNestedArrays");
+
+ Object[] array = { 1, 2, new Object[] { 3, 4, new Object[] { 5 }, 6, 7 }, 8, 9, 10 };
+ logger.debug("{} - > {}", Arrays.deepToString(array), Arrays.toString(java8Flatten(array).toArray()));
+
+ }
+
+ /**
+ * Java 8 Stream to Flatten array.
+ *
+ * @param array
+ * @return
+ */
+ private static Stream
+ *
+ */
+ @Test
+ public void test0411GrayCode() {
+ int n = 2;
+
+ List retArray = new ArrayList<>();
+
+ if (n == 0) {
+ retArray.add(0);
+ }
+
+ for (int i = 0; i < (2 << (n - 1)); i++) {
+ int g = i ^ (i / 2);
+ retArray.add(g);
+ }
+
+ System.out.println(retArray);
+ }
+
+ /**
+ * 1480 https://www.lintcode.com/problem/dot-product/description
+ */
+ @Test
+ public void test0423IsValidParentheses() {
+ String s = "([)]";
+
+ boolean retStatus = false;
+ for (int i = 0; i < 3; i++) {
+ s = s.replace("()", "");
+ s = s.replace("{}", "");
+ s = s.replace("[]", "");
+
+ if (s.length() == 0) {
+ retStatus = true;
+ break;
+ }
+ }
+
+ System.out.println(retStatus);
+
+ }
+
+ /**
+ * 646 https://www.lintcode.com/problem/first-position-unique-character/description
+ */
+ @Test
+ public void test0646FirstUniqChar() {
+ String s = "saau";
+
+ int retStatus = -1;
+ boolean breakLoop = false;
+
+ int[] iArray = new int[256];
+
+ // NULL CHECK
+ if (s == null || s.length() == 0) {
+ retStatus = -1;
+ }
+
+ // LOOP CHECK
+ for (char c : s.toCharArray()) {
+ iArray[c]++;
+ }
+ for (int i = 0; i < s.length(); i++) {
+ if (iArray[s.charAt(i)] == 1) {
+ retStatus = i;
+ breakLoop = true;
+ break;
+ }
+ }
+
+ // LOOP BREAK CHECK
+ if (!breakLoop) {
+ retStatus = -1;
+ }
+
+ System.out.println(retStatus);
+ }
+
+ /**
+ * 767 https://www.lintcode.com/problem/reverse-array/description
+ */
+ @Test
+ public void test0767ReverseArray() {
+ int[] nums = { 1, 2, 3, 4, 5, 6, 7 };
+
+ for (int i = 0; i < nums.length / 2; i++) {
+ int tmp = nums[i];
+ nums[i] = nums[nums.length - 1 - i];
+ nums[nums.length - 1 - i] = tmp;
+ }
+
+ System.out.println(Arrays.toString(nums));
+
+ }
+
+ /**
+ * 1480 https://www.lintcode.com/problem/dot-product/description
+ */
+ @Test
+ public void test1377findSubstring() {
+ String str = "";
+ int k = 5;
+
+ HashSet strSet = new HashSet();
+
+ for (int i = 0; i <= str.length() - k; i++) {
+ String subStr = str.substring(i, i + k);
+
+ String pattern = ".*(.).*\\1.*";
+
+ Pattern r = Pattern.compile(pattern);
+
+ Matcher m = r.matcher(subStr);
+ if (!m.find()) {
+ strSet.add(subStr);
+ }
+
+ }
+
+ System.out.println(strSet.size());
+ }
+
+}
From dd15b81b3a11ef56e4b2ae922032691337a9d130 Mon Sep 17 00:00:00 2001
From: Yucheng Hu
Date: Sat, 29 Dec 2018 01:03:01 -0500
Subject: [PATCH 21/33] =?UTF-8?q?=E6=89=BE=E5=88=B0=E5=90=88=E9=80=82?=
=?UTF-8?q?=E5=9F=8E=E5=A0=A1=E7=9A=84=E5=9C=B0=E6=96=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../codebank/interview/tests/WayfairTest.java | 370 ++++--------------
1 file changed, 77 insertions(+), 293 deletions(-)
diff --git a/src/test/java/com/ossez/codebank/interview/tests/WayfairTest.java b/src/test/java/com/ossez/codebank/interview/tests/WayfairTest.java
index 49c9996dbb..bee5b9b61c 100644
--- a/src/test/java/com/ossez/codebank/interview/tests/WayfairTest.java
+++ b/src/test/java/com/ossez/codebank/interview/tests/WayfairTest.java
@@ -1,293 +1,77 @@
-package com.ossez.codebank.interview.tests;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.TreeSet;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import javax.management.ListenerNotFoundException;
-
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.ossez.codebank.algorithm.models.ListNode;
-
-/**
- *
- * @author YuCheng
- *
- */
-public class WayfairTest {
-
- private final static Logger logger = LoggerFactory.getLogger(WayfairTest.class);
-
- /**
- * 35 https://www.lintcode.com/problem/reverse-linked-list/description
- */
- @Test
- public void test0035Reverse() {
- // INIT LINKED LIST
- ListNode head = new ListNode(1);
- head.next = new ListNode(2);
- head.next.next = new ListNode(3);
-
- // CHECK BEFORE
- System.out.println(head.val);
- System.out.println(head.next.val);
- System.out.println(head.next.next.val);
-
- // REVERSE
- ListNode prev = null;
- while (head != null) {
- ListNode temp = head.next;
- head.next = prev;
- prev = head;
- head = temp;
- }
-
- // CHECK AFTER
- System.out.println(prev.val);
- System.out.println(prev.next.val);
- System.out.println(prev.next.next.val);
- }
-
- /**
- * 1480 https://www.lintcode.com/problem/dot-product/description
- */
- @Test
- public void test0044minSubArray() {
-
- List nums = new ArrayList();
- nums.add(1);
- nums.add(1);
-
- int min_ending_here = 0;
- int retStatus = 0;
-
- for (int i = 0; i < nums.size(); i++) {
- if (min_ending_here > 0) {
- min_ending_here = nums.get(i);
- } else {
- min_ending_here += nums.get(i);
- }
- retStatus = Math.min(retStatus, min_ending_here);
- }
-
- System.out.println(retStatus);
-
- }
-
- /**
- * 53 https://www.lintcode.com/problem/reverse-words-in-a-string/description
- */
- @Test
- public void test0053ReverseWords() {
-
- String s = " Life doesn't always give us the joys we want.";
-
- String retStr = "";
- String[] inStr = s.split(" ");
-
- for (int i = inStr.length - 1; i >= 0; i--) {
- String cStr = inStr[i].trim();
- if (!cStr.isEmpty()) {
- retStr = retStr + " " + cStr;
- }
- }
- retStr = retStr.trim();
- System.out.println(retStr);
- // return retStr;
- }
-
- /**
- * 56 https://www.lintcode.com/problem/two-sum/description
- */
- @Test
- public void test0056TwoSum() {
- int[] numbers = { 2, 7, 11, 15 };
- int target = 9;
-
- int[] retArray = new int[2];
-
- for (int i = 0; i < numbers.length; i++) {
- int intA = numbers[i];
- int intB = 0;
-
- for (int j = 1 + i; j < numbers.length; j++) {
- intB = numbers[j];
- // SUM CHECK
- if (target == intA + intB && i < j) {
- retArray[0] = i;
- retArray[1] = j;
- break;
- }
- }
- }
-
- System.out.println(Arrays.toString(retArray));
- }
-
- /**
- * 209 https://www.lintcode.com/problem/first-unique-character-in-a-string
- */
- @Test
- public void test0209FirstUniqChar() {
- String str = "ddjdz";
-
- char retStatus = 0;
-
- // LOOP CHECK
- for (int i = 0; i < 30; i++) {
- char c = str.charAt(0);
- if (str.indexOf(Character.toString(c)) == str.lastIndexOf(Character.toString(c))) {
- retStatus = c;
- break;
- }
- str = str.replaceAll(Character.toString(c), "");
- }
-
- System.out.println("" + retStatus);
- }
-
- /**
- * 411
- *
- *
- *
- *
- *
- */
- @Test
- public void test0411GrayCode() {
- int n = 2;
-
- List retArray = new ArrayList<>();
-
- if (n == 0) {
- retArray.add(0);
- }
-
- for (int i = 0; i < (2 << (n - 1)); i++) {
- int g = i ^ (i / 2);
- retArray.add(g);
- }
-
- System.out.println(retArray);
- }
-
- /**
- * 1480 https://www.lintcode.com/problem/dot-product/description
- */
- @Test
- public void test0423IsValidParentheses() {
- String s = "([)]";
-
- boolean retStatus = false;
- for (int i = 0; i < 3; i++) {
- s = s.replace("()", "");
- s = s.replace("{}", "");
- s = s.replace("[]", "");
-
- if (s.length() == 0) {
- retStatus = true;
- break;
- }
- }
-
- System.out.println(retStatus);
-
- }
-
- /**
- * 646 https://www.lintcode.com/problem/first-position-unique-character/description
- */
- @Test
- public void test0646FirstUniqChar() {
- String s = "saau";
-
- int retStatus = -1;
- boolean breakLoop = false;
-
- int[] iArray = new int[256];
-
- // NULL CHECK
- if (s == null || s.length() == 0) {
- retStatus = -1;
- }
-
- // LOOP CHECK
- for (char c : s.toCharArray()) {
- iArray[c]++;
- }
- for (int i = 0; i < s.length(); i++) {
- if (iArray[s.charAt(i)] == 1) {
- retStatus = i;
- breakLoop = true;
- break;
- }
- }
-
- // LOOP BREAK CHECK
- if (!breakLoop) {
- retStatus = -1;
- }
-
- System.out.println(retStatus);
- }
-
- /**
- * 767 https://www.lintcode.com/problem/reverse-array/description
- */
- @Test
- public void test0767ReverseArray() {
- int[] nums = { 1, 2, 3, 4, 5, 6, 7 };
-
- for (int i = 0; i < nums.length / 2; i++) {
- int tmp = nums[i];
- nums[i] = nums[nums.length - 1 - i];
- nums[nums.length - 1 - i] = tmp;
- }
-
- System.out.println(Arrays.toString(nums));
-
- }
-
- /**
- * 1480 https://www.lintcode.com/problem/dot-product/description
- */
- @Test
- public void test1377findSubstring() {
- String str = "";
- int k = 5;
-
- HashSet strSet = new HashSet();
-
- for (int i = 0; i <= str.length() - k; i++) {
- String subStr = str.substring(i, i + k);
-
- String pattern = ".*(.).*\\1.*";
-
- Pattern r = Pattern.compile(pattern);
-
- Matcher m = r.matcher(subStr);
- if (!m.find()) {
- strSet.add(subStr);
- }
-
- }
-
- System.out.println(strSet.size());
- }
-
-}
+package com.ossez.codebank.interview.tests;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * For Wayfair
+ *
+ * @author YuCheng
+ *
+ */
+public class WayfairTest {
+
+ private final static Logger logger = LoggerFactory.getLogger(WayfairTest.class);
+
+ /**
+ * https://www.cwiki.us/display/ITCLASSIFICATION/Build+Castles
+ */
+ @Test
+ public void testBuildCastles() {
+
+ // int[] A = { -3, -3 };
+ int[] A = { 2, 2, 3, 4, 3, 3, 2, 2, 1, 1, 2, 5 };
+
+ int h = 0;
+ int v = 0;
+
+ List nList = new ArrayList();
+
+ // Rebuild List
+ nList.add(A[0]);
+ for (int i = 0; i < A.length - 1; i++) {
+
+ if (A[i] != A[i + 1]) {
+ nList.add(A[i + 1]);
+ }
+
+ }
+
+ // LOOP List to find right location
+ for (int i = 0; i < nList.size() - 1; i++) {
+
+ // COUNT 0
+ if (i == 0) {
+ if (nList.get(i) < nList.get(i + 1)) {
+ v++;
+ }
+ } else {
+ if (nList.get(i) < nList.get(i - 1) && nList.get(i) < nList.get(i + 1)) {
+ v++;
+ }
+
+ if (nList.get(i) > nList.get(i - 1) && nList.get(i) > nList.get(i + 1)) {
+ h++;
+ }
+ }
+ }
+
+ if (nList.size() == 1) {
+ h++;
+ } else if (nList.size() > 2 && nList.get(nList.size() - 1) > nList.get(nList.size() - 2)) {
+ h++;
+ }
+
+ // CHECK
+ logger.debug("V - [{}]", v);
+ logger.debug("H - [{}]", h);
+
+ logger.debug("H + V - [{}]", (h + v));
+
+ }
+
+}
From c3d2a81f36908417cd973cd1a78592c65605b4b4 Mon Sep 17 00:00:00 2001
From: Yucheng Hu
Date: Sat, 29 Dec 2018 19:36:53 -0500
Subject: [PATCH 22/33] =?UTF-8?q?=E8=AE=A1=E7=AE=97=E4=BA=8C=E9=A1=B9?=
=?UTF-8?q?=E5=BC=8F=E7=B3=BB=E6=95=B0=E5=92=8C=E4=BD=BF=E7=94=A8=20Apache?=
=?UTF-8?q?=20Math=20=E5=8C=85?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 503 +++++++++---------
.../codebank/interview/tests/WayfairTest.java | 37 ++
2 files changed, 288 insertions(+), 252 deletions(-)
diff --git a/pom.xml b/pom.xml
index ab0ef42ad2..2ba676322e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,253 +1,252 @@
-
- 4.0.0
- com.ossez
- codebank-algorithm
- 0.0.1
-
-
-
- 1.8
- UTF-8
- UTF-8
-
-
- 1.7.12
- 2.2
-
-
-
- 4.3.5.Final
-
-
- 4.3.1.Final
-
-
- 7.0.42
- 2.6.8
- 2.3.2
-
-
- 1.9.0
-
-
-
-
-
-
-
- org.apache.logging.log4j
- log4j-slf4j-impl
- 2.11.0
-
-
-
-
- junit
- junit
- 4.12
-
-
-
-
- org.apache.commons
- commons-email
- 1.5
-
-
-
-
-
- org.apache.commons
- commons-compress
- 1.18
-
-
-
- org.apache.commons
- commons-math3
- 3.6.1
-
-
-
- antlr
- antlr
- 2.7.6
-
-
-
- dom4j
- dom4j
- 1.6.1
-
-
- commons-cli
- commons-cli
- 1.2
-
-
- org.apache.velocity
- velocity-tools
- 2.0
-
-
-
- jaxen
- jaxen
- 1.1.6
-
-
-
- javax.persistence
- persistence-api
- 1.0.2
-
-
- com.google.guava
- guava
- 17.0
-
-
- com.google.gdata
- core
- 1.47.1
-
-
-
- org.ow2.orchestra.eclipse.birt
- org.ow2.orchestra.eclipse.birt.core
- 3.7.0
-
-
- org.ow2.orchestra.eclipse.birt
- org.ow2.orchestra.eclipse.birt.report.engine
- 3.7.0
-
-
- commons-net
- commons-net
- 2.0
-
-
-
- com.mchange
- mchange-commons-java
- 0.2.9
-
-
-
-
- org.jasypt
- jasypt
- 1.5
-
-
-
- httpunit
- httpunit
- 1.7
-
-
- net.sf.jazzy
- jazzy
- 0.5.2-rtext-1.4.1
-
-
- net.sf.json-lib
- json-lib
- 2.4
- jdk15
-
-
- rome
- rome
- 0.9
-
-
-
- org.apache.httpcomponents
- httpmime
- 4.5.1
-
-
-
- org.jsoup
- jsoup
- 1.7.2
-
-
-
- net.lingala.zip4j
- zip4j
- 1.3.2
-
-
-
-
-
- package
-
-
- maven-compiler-plugin
- 3.1
-
-
- ${java.version}
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
- 2.12.4
-
- true
-
-
-
- org.apache.maven.plugins
- maven-jar-plugin
- 2.6
-
-
-
- com.ossez.reoc.rets.Main
- true
- lib/
-
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-assembly-plugin
- 2.6
-
-
-
- package
-
- single
-
-
- src/assembly/zipAssembly.xml
- reoc-rets
-
-
- com.ossez.reoc.rets.Main
-
-
- ./
-
-
-
-
-
-
-
-
-
-
+
+ 4.0.0
+ com.ossez
+ codebank-algorithm
+ 0.0.1
+
+
+
+ 1.8
+ UTF-8
+ UTF-8
+
+
+ 1.7.12
+ 2.2
+
+
+
+ 4.3.5.Final
+
+
+ 4.3.1.Final
+
+
+ 7.0.42
+ 2.6.8
+ 2.3.2
+
+
+ 1.9.0
+
+
+
+
+
+
+
+ org.apache.logging.log4j
+ log4j-slf4j-impl
+ 2.11.0
+
+
+
+
+ junit
+ junit
+ 4.12
+
+
+
+
+ org.apache.commons
+ commons-email
+ 1.5
+
+
+
+
+
+ org.apache.commons
+ commons-compress
+ 1.18
+
+
+
+ org.apache.commons
+ commons-math3
+ 3.6.1
+
+
+
+ antlr
+ antlr
+ 2.7.6
+
+
+
+ dom4j
+ dom4j
+ 1.6.1
+
+
+ commons-cli
+ commons-cli
+ 1.2
+
+
+ org.apache.velocity
+ velocity-tools
+ 2.0
+
+
+
+ jaxen
+ jaxen
+ 1.1.6
+
+
+
+ javax.persistence
+ persistence-api
+ 1.0.2
+
+
+ com.google.guava
+ guava
+ 17.0
+
+
+ com.google.gdata
+ core
+ 1.47.1
+
+
+
+ org.ow2.orchestra.eclipse.birt
+ org.ow2.orchestra.eclipse.birt.core
+ 3.7.0
+
+
+ org.ow2.orchestra.eclipse.birt
+ org.ow2.orchestra.eclipse.birt.report.engine
+ 3.7.0
+
+
+ commons-net
+ commons-net
+ 2.0
+
+
+
+ com.mchange
+ mchange-commons-java
+ 0.2.9
+
+
+
+
+ org.jasypt
+ jasypt
+ 1.5
+
+
+
+ httpunit
+ httpunit
+ 1.7
+
+
+ net.sf.jazzy
+ jazzy
+ 0.5.2-rtext-1.4.1
+
+
+ net.sf.json-lib
+ json-lib
+ 2.4
+ jdk15
+
+
+ rome
+ rome
+ 0.9
+
+
+
+ org.apache.httpcomponents
+ httpmime
+ 4.5.1
+
+
+
+ org.jsoup
+ jsoup
+ 1.7.2
+
+
+
+ net.lingala.zip4j
+ zip4j
+ 1.3.2
+
+
+
+
+
+ package
+
+
+ maven-compiler-plugin
+ 3.1
+
+
+ ${java.version}
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.12.4
+
+ true
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 2.6
+
+
+
+ com.ossez.reoc.rets.Main
+ true
+ lib/
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+ 2.6
+
+
+
+ package
+
+ single
+
+
+ src/assembly/zipAssembly.xml
+ reoc-rets
+
+
+ com.ossez.reoc.rets.Main
+
+
+ ./
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/test/java/com/ossez/codebank/interview/tests/WayfairTest.java b/src/test/java/com/ossez/codebank/interview/tests/WayfairTest.java
index bee5b9b61c..2dde74bcd9 100644
--- a/src/test/java/com/ossez/codebank/interview/tests/WayfairTest.java
+++ b/src/test/java/com/ossez/codebank/interview/tests/WayfairTest.java
@@ -1,8 +1,10 @@
package com.ossez.codebank.interview.tests;
+import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
+import org.apache.commons.math3.util.CombinatoricsUtils;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -74,4 +76,39 @@ public class WayfairTest {
}
+ /**
+ * https://www.cwiki.us/display/ITCLASSIFICATION/Binomial+Coefficient
+ *
+ * Binomial Coefficient
+ */
+ @Test
+ public void testBinomialCoefficient() {
+ int n = 40;
+ int k = 20;
+
+ BigDecimal bc = factorial(n).divide(factorial(k).multiply(factorial(n - k)));
+ // a.compareTo(new BigDecimal(1000000000))
+ logger.debug("{}", bc);
+ logger.debug("Check for Compare To - [{}]", bc.compareTo(new BigDecimal(1000000000)));
+ logger.debug("Value - [{}]", bc);
+
+ logger.debug("Apache CombinatoricsUtils Factorial - [{}]", CombinatoricsUtils.factorialDouble(20));
+ logger.debug("Apache CombinatoricsUtils Binomial Coefficient - [{}]", CombinatoricsUtils.binomialCoefficientDouble(40, 20));
+
+ }
+
+ /**
+ * for factorial
+ *
+ * @param x
+ * @return
+ */
+ private static BigDecimal factorial(int x) {
+ if (x == 1 || x == 0) {
+ return BigDecimal.valueOf(1);
+ } else {
+ return BigDecimal.valueOf(x).multiply(factorial(x - 1));
+ }
+ }
+
}
From ee6398994e4d0f4e1e5d93f334b88e461d066f6e Mon Sep 17 00:00:00 2001
From: Yucheng Hu
Date: Thu, 3 Jan 2019 00:27:02 -0500
Subject: [PATCH 23/33] =?UTF-8?q?CODEBANK-2=20=E6=B7=BB=E5=8A=A0=E4=BB=A3?=
=?UTF-8?q?=E7=A0=81=E5=88=B0=20Code=20Bank?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../codebank/interview/tests/TennaTest.java | 46 +++++++++++++++++++
1 file changed, 46 insertions(+)
create mode 100644 src/test/java/com/ossez/codebank/interview/tests/TennaTest.java
diff --git a/src/test/java/com/ossez/codebank/interview/tests/TennaTest.java b/src/test/java/com/ossez/codebank/interview/tests/TennaTest.java
new file mode 100644
index 0000000000..2f3ec0f3cd
--- /dev/null
+++ b/src/test/java/com/ossez/codebank/interview/tests/TennaTest.java
@@ -0,0 +1,46 @@
+package com.ossez.codebank.interview.tests;
+
+import java.util.HashMap;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * For Tenna
+ *
+ * @author YuCheng
+ *
+ */
+public class TennaTest {
+
+ private final static Logger logger = LoggerFactory.getLogger(TennaTest.class);
+
+ /**
+ * Optimized Math
+ */
+ @Test
+ public void testOptimizedMath() {
+
+ HashMap outMap = new HashMap();
+
+ // LOOP SET VALUE TO MAP
+ for (int i = 1; i <= 100; i++) {
+ if (outMap.get(i) == null && i % 2 == 0 && i % 3 == 0) {
+ outMap.put(i, "divisible by two and three.");
+ } else if (outMap.get(i) == null && i % 3 == 0) {
+ outMap.put(i, "divisible by three.");
+ } else if (outMap.get(i) == null && i % 2 == 0) {
+ outMap.put(i, "even.");
+ } else {
+ outMap.put(i, "odd.");
+ }
+ }
+
+ // LOOP FOR OUTPUT
+ for (int i = 1; i <= 100; i++) {
+ logger.debug("The number '{}' is {} ", i, outMap.get(i));
+ }
+
+ }
+}
From 689ec45baf395e201df244fe184a77dd1dc26cf0 Mon Sep 17 00:00:00 2001
From: Yucheng Hu
Date: Thu, 3 Jan 2019 01:11:53 -0500
Subject: [PATCH 24/33] =?UTF-8?q?Amazon=20=E9=9D=A2=E8=AF=95=E4=BB=A3?=
=?UTF-8?q?=E7=A0=81=E6=8C=91=E6=88=98=E9=A2=98=E7=9B=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../codebank/interview/tests/AmazonTest.java | 210 ++++++++++++++++++
1 file changed, 210 insertions(+)
create mode 100644 src/test/java/com/ossez/codebank/interview/tests/AmazonTest.java
diff --git a/src/test/java/com/ossez/codebank/interview/tests/AmazonTest.java b/src/test/java/com/ossez/codebank/interview/tests/AmazonTest.java
new file mode 100644
index 0000000000..df2101b3ca
--- /dev/null
+++ b/src/test/java/com/ossez/codebank/interview/tests/AmazonTest.java
@@ -0,0 +1,210 @@
+package com.ossez.codebank.interview.tests;
+
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.stream.Stream;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Amazon
+ *
+ *
+ * https://www.cwiki.us/display/ITCLASSIFICATION/Flatten+Nested+Arrays
+ *
+ *
+ * @author YuCheng
+ *
+ */
+public class AmazonTest {
+
+ private final static Logger logger = LoggerFactory.getLogger(AmazonTest.class);
+
+ List returnList = new ArrayList();
+
+ /**
+ * https://www.cwiki.us/display/ITCLASSIFICATION/Flatten+Nested+Arrays
+ *
+ * FlattenNestedArrays
+ */
+ @Test
+ public void testFlattenNestedArrays() {
+ logger.debug("Test FlattenNestedArrays");
+ int numRows = 3;
+ int numColumns = 3;
+ List> area = new ArrayList>();
+ List a1 = new ArrayList();
+ List a2 = new ArrayList();
+ List a3 = new ArrayList();
+
+ a1.add(1);
+ a1.add(0);
+ a1.add(0);
+
+ a2.add(1);
+ a2.add(0);
+ a2.add(0);
+
+ a3.add(1);
+ a3.add(9);
+ a3.add(1);
+ area.add(a1);
+ area.add(a2);
+ area.add(a3);
+
+ int countD = 0;
+
+ int x = 0;
+ int y = 0;
+
+ for (int i = 0; i < area.size(); i++) {
+ boolean found9 = false;
+ y = 0;
+
+ List xList = area.get(i);
+ for (int j = 0; j < xList.size(); j++) {
+ if (xList.get(j) != 9) {
+ y++;
+ } else {
+ found9 = true;
+ break;
+ }
+
+ }
+
+ if (found9) {
+ break;
+ }
+
+ x++;
+
+ }
+
+ int carX = 0;
+ int carY = 0;
+
+ for (int k = 0; k < numRows * numRows; k++) {
+
+ String command = makeMove(carX, carY, numRows, numColumns, area);
+
+ if (command != null) {
+
+ if (command.equals("U")) {
+ carY = carY + 1;
+ }
+ if (command.equals("R")) {
+ carX = carX + 1;
+ }
+ if (command.equals("L")) {
+ carX = carX - 1;
+ }
+ if (command.equals("D")) {
+ carY = carY + 1;
+ }
+
+ countD = countD + 1;
+
+ if (carX == x && carY == y) {
+ break;
+ }
+ } else {
+ break;
+ }
+ }
+
+ System.out.println("---" + x + y);
+ System.out.println("--COUNT-" + countD );
+
+ }
+
+ /**
+ * Java 8 Stream to Flatten array.
+ *
+ * @param array
+ * @return
+ */
+ private static String makeMove(int carX, int carY, int numRows, int numColumns, List> area) {
+
+
+
+ if ((carX + 1 0 && area.get(carX + 1).get(carY) !=9 )
+ if (area.get(carX - 1).get(carY) == 1)
+ return "L";
+ else
+ return "F";
+
+ else if (carX > 0 && carY > 0 && area.get(carX - 1).get(carY - 1) == 1)
+ return "D";
+
+ return null;
+ }
+
+ /**
+ * Loop And Recursive
+ *
+ * @param inputArray
+ * @return
+ * @throws IllegalArgumentException
+ */
+ private List> nearestVegetarianRestaurant(int totalRestaurants, List> allLocations, int numRestaurants) {
+ // WRITE YOUR CODE HERE
+
+ List> ret = new ArrayList>();
+ HashMap> mp = new HashMap>();
+ Double[] keyArray = new Double[totalRestaurants];
+
+ int i = 0;
+ for (List al : allLocations) {
+ Double dis = getDis(al.get(0), al.get(1));
+ mp.put(dis, al);
+ keyArray[i] = dis;
+
+ i++;
+ }
+
+ Arrays.sort(keyArray);
+ for (int j = 0; j < numRestaurants; j++) {
+ ret.add(mp.get(keyArray[j]));
+ }
+
+ return null;
+ }
+
+ private Double getDis(int a, int b) {
+ // WRITE YOUR CODE HERE
+
+ return Math.sqrt(a * a + b * b);
+
+ }
+
+ /**
+ * Java 8 Stream to Flatten array.
+ *
+ * @param array
+ * @return
+ */
+ private static Stream java8Flatten(Object[] array) {
+ // int[] flatInt = java8Flatten(array).mapToInt(Integer.class::cast).toArray();
+ return Arrays.stream(array).flatMap(o -> o instanceof Object[] ? java8Flatten((Object[]) o) : Stream.of(o));
+
+ }
+
+}
From 04978083ec22875f28c636b02d5b3070661951fa Mon Sep 17 00:00:00 2001
From: YuCheng Hu
Date: Thu, 10 Jan 2019 17:07:32 -0500
Subject: [PATCH 25/33] =?UTF-8?q?MassMutual=20JSON=20=E5=A4=84=E7=90=86?=
=?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=96=B9=E6=B3=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 17 +-
.../codebank/interview/tests/MassMutual.java | 172 ++++++++++++++++++
2 files changed, 185 insertions(+), 4 deletions(-)
create mode 100644 src/test/java/com/ossez/codebank/interview/tests/MassMutual.java
diff --git a/pom.xml b/pom.xml
index 2ba676322e..d6ecc84723 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,4 +1,5 @@
-
4.0.0
com.ossez
@@ -58,9 +59,9 @@
- org.apache.commons
- commons-compress
- 1.18
+ commons-io
+ commons-io
+ 2.6
@@ -182,6 +183,14 @@
1.3.2
+
+
+ com.google.code.gson
+ gson
+ 2.8.5
+
+
+
diff --git a/src/test/java/com/ossez/codebank/interview/tests/MassMutual.java b/src/test/java/com/ossez/codebank/interview/tests/MassMutual.java
new file mode 100644
index 0000000000..b88a2fe2f0
--- /dev/null
+++ b/src/test/java/com/ossez/codebank/interview/tests/MassMutual.java
@@ -0,0 +1,172 @@
+package com.ossez.codebank.interview.tests;
+
+import java.io.File;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.filefilter.TrueFileFilter;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+
+/**
+ * MassMutual
+ *
+ * @author Yucheng
+ *
+ */
+public class MassMutual {
+
+ private final static Logger logger = LoggerFactory.getLogger(MassMutual.class);
+
+ @Test
+ public void loadOBJ() {
+ logger.debug("Test JSON LOAD TO OBJ");
+ List woodChuckList = new ArrayList();
+ List dataFileList = new ArrayList();
+
+ try {
+ dataFileList = (List) FileUtils.listFiles(new File("C:\\Users\\Yucheng\\Documents\\Data-Sample\\massmutual"),
+ TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
+
+ for (File file : dataFileList) {
+
+ woodChuckList.add(processWoodChuck(FileUtils.readFileToString(file, StandardCharsets.UTF_8)));
+ }
+
+ for (WoodChuck woodChuck : woodChuckList) {
+ logger.debug("\r\n");
+ logger.debug("name - [{}]", woodChuck.getName());
+ logger.debug("aliases0 - [{}]", woodChuck.getAliases0());
+ logger.debug("aliases1 - [{}]", woodChuck.getAliases1());
+ logger.debug("height - [{}]", woodChuck.getHeight());
+ logger.debug("weight - [{}]", woodChuck.getWeight());
+ logger.debug("woodChuckedWeight - [{}]", woodChuck.getWoodChuckedWeight());
+ }
+
+ }
+
+ catch (Exception e) {
+ // TODO: handle exception
+ logger.error("API Data Table Process Error {}", e);
+ }
+
+ }
+
+ /**
+ *
+ * @param jData
+ * @return
+ */
+ private WoodChuck processWoodChuck(String jData) {
+ WoodChuck woodChuck = new WoodChuck();
+
+ JsonElement jsonElement = new JsonParser().parse(jData);
+ JsonObject jsonObject = jsonElement.getAsJsonObject();
+
+ if (jsonObject.get("aliases") != null && jsonObject.get("aliases").isJsonArray()) {
+
+ // name
+ woodChuck.setName(jsonObject.get("name").getAsString());
+
+ // aliases
+ JsonArray aliases = jsonObject.getAsJsonArray("aliases");
+ woodChuck.setAliases0(aliases.get(0).getAsString());
+ woodChuck.setAliases1(aliases.get(1).getAsString());
+
+ // physical
+ woodChuck.setHeight(jsonObject.get("physical").getAsJsonObject().get("height_in").getAsString());
+ woodChuck.setWeight(jsonObject.get("physical").getAsJsonObject().get("weight_lb").getAsString());
+
+ // woodChuckedWeight
+ woodChuck.setWoodChuckedWeight(jsonObject.get("wood_chucked_lbs").getAsString());
+
+ } else {
+ // name
+ woodChuck.setName(jsonObject.get("name").getAsString());
+
+ // aliases
+ woodChuck.setAliases0(jsonObject.get("aliases.0").getAsString());
+ woodChuck.setAliases1(jsonObject.get("aliases.1").getAsString());
+
+ // physical
+ woodChuck.setHeight(jsonObject.get("physical.height_in").getAsString());
+ woodChuck.setWeight(jsonObject.get("physical.weight_lb").getAsString());
+
+ // woodChuckedWeight
+ woodChuck.setWoodChuckedWeight(jsonObject.get("wood_chucked_lbs").getAsString());
+ }
+
+ return woodChuck;
+
+ }
+
+ /*
+ * + WoodChuck OBJ for JSON process. +
+ */
+ class WoodChuck {
+ private String name = null;
+ private String aliases0 = null;
+ private String aliases1 = null;
+ private String height = null;
+ private String weight = null;
+ private String woodChuckedWeight = null;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getAliases0() {
+ return aliases0;
+ }
+
+ public void setAliases0(String aliases0) {
+ this.aliases0 = aliases0;
+ }
+
+ public String getAliases1() {
+ return aliases1;
+ }
+
+ public void setAliases1(String aliases1) {
+ this.aliases1 = aliases1;
+ }
+
+ public String getHeight() {
+ return height;
+ }
+
+ public void setHeight(String height) {
+ this.height = height;
+ }
+
+ public String getWeight() {
+ return weight;
+ }
+
+ public void setWeight(String weight) {
+ this.weight = weight;
+ }
+
+ public String getWoodChuckedWeight() {
+ return woodChuckedWeight;
+ }
+
+ public void setWoodChuckedWeight(String woodChuckedWeight) {
+ this.woodChuckedWeight = woodChuckedWeight;
+ }
+
+ }
+
+}
From f5a896f1ae4eda98a0d04fd7dffe778cf8ce2b33 Mon Sep 17 00:00:00 2001
From: YuCheng Hu
Date: Thu, 7 Feb 2019 21:00:59 -0500
Subject: [PATCH 26/33] =?UTF-8?q?=E4=B8=8B=E4=B8=80=E4=B8=AA=E6=96=90?=
=?UTF-8?q?=E6=B3=A2=E6=8B=89=E5=A5=91=E6=95=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../interview/ManNextFibonacciNumber.java | 68 +++++++++++++
src/main/resources/log4j2.xml | 97 +++++++++++++++++++
2 files changed, 165 insertions(+)
create mode 100644 src/main/java/com/ossez/codebank/interview/ManNextFibonacciNumber.java
create mode 100644 src/main/resources/log4j2.xml
diff --git a/src/main/java/com/ossez/codebank/interview/ManNextFibonacciNumber.java b/src/main/java/com/ossez/codebank/interview/ManNextFibonacciNumber.java
new file mode 100644
index 0000000000..d98b2da869
--- /dev/null
+++ b/src/main/java/com/ossez/codebank/interview/ManNextFibonacciNumber.java
@@ -0,0 +1,68 @@
+package com.ossez.codebank.interview;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * https://www.cwiki.us/display/ITCLASSIFICATION/Next+Fibonacci+Number
+ *
+ * @author YuCheng
+ *
+ */
+public class ManNextFibonacciNumber {
+ private final static Logger logger = LoggerFactory.getLogger(ManNextFibonacciNumber.class);
+
+ public static void main(String[] args) throws java.lang.Exception {
+ int fArray[] = new int[60];
+
+ for (int i = 0; i < 60; i++) {
+ fArray[i] = getFib(i);
+ }
+
+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
+ String input = br.readLine();
+ // System.out.println(fib(Integer.valueOf(input)));
+
+ for (int i = 0; i < Integer.valueOf(input); i++) {
+ Integer inputInt = Integer.valueOf(br.readLine());
+ // System.out.println(inputInt);
+ for (int j = 0; j < fArray.length; j++) {
+ if (fArray[j] > inputInt) {
+ // System.out.println(fArray[j]);
+ logger.debug("{} Next Fibonacci [{}]", inputInt, fArray[j]);
+ break;
+ }
+ }
+
+ }
+
+ }
+
+ /**
+ * Get Fibonacci Number
+ *
+ * @param n
+ * @return
+ */
+ private static int getFib(int n) {
+ if (n < 0) {
+ return -1;
+ } else if (n == 0) {
+ return 0;
+ } else if (n == 1 || n == 2) {
+ return 1;
+ } else {
+ int[] fibAry = new int[n + 1];
+ fibAry[0] = 0;
+ fibAry[1] = fibAry[2] = 1;
+ for (int i = 3; i <= n; i++) {
+ fibAry[i] = fibAry[i - 1] + fibAry[i - 2];
+ }
+ return fibAry[n];
+ }
+ }
+}
diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml
new file mode 100644
index 0000000000..9cfef38ef0
--- /dev/null
+++ b/src/main/resources/log4j2.xml
@@ -0,0 +1,97 @@
+
+
+
+
+
+ /home/logs/reoc/services/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ %-d{yyyy/MM/dd HH:mm:ss} %-5p [%c] - %m%n
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ %-d{yyyy/MM/dd HH:mm:ss} %-5p [%c] - %m%n
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ %-d{yyyy/MM/dd HH:mm:ss} %-5p [%c] - %m%n
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ %-d{yyyy/MM/dd HH:mm:ss} %-5p [%c] - %m%n
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
From d34c492adbf89db6d8663e5326970ba4427cf818 Mon Sep 17 00:00:00 2001
From: YuCheng Hu
Date: Fri, 24 Jul 2020 15:58:41 -0400
Subject: [PATCH 27/33] LambdaEvens
---
.../tests/others/LambdaEvensTest.java | 49 +++++++++++++++++++
1 file changed, 49 insertions(+)
create mode 100644 src/test/java/com/ossez/codebank/interview/tests/others/LambdaEvensTest.java
diff --git a/src/test/java/com/ossez/codebank/interview/tests/others/LambdaEvensTest.java b/src/test/java/com/ossez/codebank/interview/tests/others/LambdaEvensTest.java
new file mode 100644
index 0000000000..3b872b063d
--- /dev/null
+++ b/src/test/java/com/ossez/codebank/interview/tests/others/LambdaEvensTest.java
@@ -0,0 +1,49 @@
+package com.ossez.codebank.interview.tests.others;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * For Lambda Evens
+ *
+ * @author YuCheng
+ */
+public class LambdaEvensTest {
+
+ private final static Logger logger = LoggerFactory.getLogger(LambdaEvensTest.class);
+
+ /**
+ * Lambda Function
+ */
+
+ interface Arithmetic {
+ Long operation(Long a, Long b);
+ }
+
+
+ /**
+ * https://www.cwiki.us/display/ITCLASSIFICATION/Build+Castles
+ */
+ @Test
+ public void testLambdaEvents() {
+
+ String line = "1 2 3 4 5 6 ";
+
+ String[] lineArray = line.split(" ");
+ List numbers = new ArrayList<>();
+ Arithmetic division = (Long a, Long b) -> (a % b);
+
+
+ for (String lineChar : lineArray) {
+ if (division.operation(Long.parseLong(lineChar), 2L) == 0) {
+ System.out.print(lineChar + " ");
+// logger.debug(lineChar + " ");
+ }
+ }
+
+ }
+}
\ No newline at end of file
From b4d068c639b616ead53bc84d1539a6e814261a0f Mon Sep 17 00:00:00 2001
From: YuCheng Hu
Date: Fri, 24 Jul 2020 16:02:30 -0400
Subject: [PATCH 28/33] Find the Lambda evens for giving string
---
.../tests/others/LambdaEvensTest.java | 44 +++++++++----------
1 file changed, 22 insertions(+), 22 deletions(-)
diff --git a/src/test/java/com/ossez/codebank/interview/tests/others/LambdaEvensTest.java b/src/test/java/com/ossez/codebank/interview/tests/others/LambdaEvensTest.java
index 3b872b063d..38bdac4519 100644
--- a/src/test/java/com/ossez/codebank/interview/tests/others/LambdaEvensTest.java
+++ b/src/test/java/com/ossez/codebank/interview/tests/others/LambdaEvensTest.java
@@ -14,36 +14,36 @@ import java.util.List;
*/
public class LambdaEvensTest {
- private final static Logger logger = LoggerFactory.getLogger(LambdaEvensTest.class);
+ private final static Logger logger = LoggerFactory.getLogger(LambdaEvensTest.class);
- /**
- * Lambda Function
- */
+ /**
+ * Lambda Function
+ */
- interface Arithmetic {
- Long operation(Long a, Long b);
- }
+ interface Arithmetic {
+ Long operation(Long a, Long b);
+ }
- /**
- * https://www.cwiki.us/display/ITCLASSIFICATION/Build+Castles
- */
- @Test
- public void testLambdaEvents() {
+ /**
+ * https://www.cwiki.us/display/ITCLASSIFICATION/Lambda+Evens
+ */
+ @Test
+ public void testLambdaEvents() {
- String line = "1 2 3 4 5 6 ";
+ String line = "1 2 3 4 5 6 ";
- String[] lineArray = line.split(" ");
- List numbers = new ArrayList<>();
- Arithmetic division = (Long a, Long b) -> (a % b);
+ String[] lineArray = line.split(" ");
+ List numbers = new ArrayList<>();
+ Arithmetic division = (Long a, Long b) -> (a % b);
- for (String lineChar : lineArray) {
- if (division.operation(Long.parseLong(lineChar), 2L) == 0) {
- System.out.print(lineChar + " ");
+ for (String lineChar : lineArray) {
+ if (division.operation(Long.parseLong(lineChar), 2L) == 0) {
+ System.out.print(lineChar + " ");
// logger.debug(lineChar + " ");
- }
- }
+ }
+ }
- }
+ }
}
\ No newline at end of file
From c0505376182ed1deda413ccc4334fcc785a1e4c8 Mon Sep 17 00:00:00 2001
From: YuCheng Hu
Date: Fri, 24 Jul 2020 16:19:11 -0400
Subject: [PATCH 29/33] Adjust the function
---
.../tests/others/MinimumCoinsTest.java | 42 +++++++++++++++++++
1 file changed, 42 insertions(+)
create mode 100644 src/test/java/com/ossez/codebank/interview/tests/others/MinimumCoinsTest.java
diff --git a/src/test/java/com/ossez/codebank/interview/tests/others/MinimumCoinsTest.java b/src/test/java/com/ossez/codebank/interview/tests/others/MinimumCoinsTest.java
new file mode 100644
index 0000000000..b954fd2b5d
--- /dev/null
+++ b/src/test/java/com/ossez/codebank/interview/tests/others/MinimumCoinsTest.java
@@ -0,0 +1,42 @@
+package com.ossez.codebank.interview.tests.others;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * For Minimum Coins
+ *
+ * @author YuCheng
+ */
+public class MinimumCoinsTest {
+
+ private final static Logger logger = LoggerFactory.getLogger(MinimumCoinsTest.class);
+
+ /**
+ * https://www.cwiki.us/display/ITCLASSIFICATION/Minimum+Coins
+ */
+ @Test
+ public void testMinimumCoins() {
+
+ String line = "20";
+
+ long coinsCount = 0;
+
+ Long coinsValue = Long.parseLong(line);
+ coinsCount = coinsValue / 5;
+ Long coinsValueAfter5 = coinsValue % 5;
+
+ if (coinsValueAfter5 == 4 || coinsValueAfter5 == 2)
+ coinsCount = coinsCount + 2;
+ else if (coinsValueAfter5 == 3 || coinsValueAfter5 == 1)
+ coinsCount = coinsCount + 1;
+
+
+ System.out.println(coinsCount);
+ }
+
+}
From 4f122360a09e1d875cc4a3aa795fb2ef1d43e878 Mon Sep 17 00:00:00 2001
From: YuCheng Hu
Date: Fri, 24 Jul 2020 16:20:20 -0400
Subject: [PATCH 30/33] Get count for coins
---
.../codebank/interview/tests/others/MinimumCoinsTest.java | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/test/java/com/ossez/codebank/interview/tests/others/MinimumCoinsTest.java b/src/test/java/com/ossez/codebank/interview/tests/others/MinimumCoinsTest.java
index b954fd2b5d..9b251ae5fd 100644
--- a/src/test/java/com/ossez/codebank/interview/tests/others/MinimumCoinsTest.java
+++ b/src/test/java/com/ossez/codebank/interview/tests/others/MinimumCoinsTest.java
@@ -35,8 +35,7 @@ public class MinimumCoinsTest {
else if (coinsValueAfter5 == 3 || coinsValueAfter5 == 1)
coinsCount = coinsCount + 1;
-
- System.out.println(coinsCount);
+ logger.debug("count Number > {}",coinsCount);
}
}
From 32c304ab1237bbc6b2feb15376c1ad0067237a2b Mon Sep 17 00:00:00 2001
From: YuCheng Hu
Date: Fri, 23 Apr 2021 12:23:43 -0400
Subject: [PATCH 31/33] set version for toolkits
---
toolkits/pom.xml | 1 +
1 file changed, 1 insertion(+)
diff --git a/toolkits/pom.xml b/toolkits/pom.xml
index 506dcb2618..f0dd68f6f2 100644
--- a/toolkits/pom.xml
+++ b/toolkits/pom.xml
@@ -6,6 +6,7 @@
com.ossez
toolkits
toolkits
+ 0.0.1
pom
From 5510d7f5796d4855fdf80284d9d319900b82dfbf Mon Sep 17 00:00:00 2001
From: YuCheng Hu
Date: Fri, 23 Apr 2021 15:51:55 -0400
Subject: [PATCH 32/33] OSSEZ-88 Push to different version of POM
---
pom.xml | 47 ++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 40 insertions(+), 7 deletions(-)
diff --git a/pom.xml b/pom.xml
index 44f37e0d87..4f23a99bd0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,9 +1,42 @@
-
- 4.0.0
- com.ossez
- lang-tutorial
- 0.0.1
+
+
+ 4.0.0
+
+ com.ossez
+ parent-modules
+ 0.0.1
+ pom
+
+ CWIKIUS-OSSEZ Java Parent Modules
+ CWIKIUS-OSSEZ Java Tutorials For Algorithm And Learning
+ https://www.ossez.com/
+
+
+ https://github.com/cwiki-us-docs/java-tutorials.git
+ https://github.com/cwiki-us-docs/java-tutorials.git
+
+
+
+
+ YuCheng Hu
+ huyuchengus
+ huyuchengus@gmail.com
+ -5
+ NORTH TECOM, LLC
+
+ Java Developer
+
+
+
+
+
+
+ Apache 2.0
+ https://www.apache.org/licenses/LICENSE-2.0.txt
+
+
@@ -204,7 +237,7 @@
maven-compiler-plugin
- 3.7.0
+ 3.8.1
${java.version}
From 61104e9cfb889d87efac0ca27c9e06e985c736b1 Mon Sep 17 00:00:00 2001
From: YuCheng Hu
Date: Fri, 23 Apr 2021 16:30:16 -0400
Subject: [PATCH 33/33] =?UTF-8?q?OSSEZ-88=200.0.1-SNAPSHOT=20=E8=A1=A5?=
=?UTF-8?q?=E5=85=85=E6=8F=90=E4=BA=A4=E5=88=B0=E4=BB=93=E5=BA=93=E4=B8=AD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 4ca10cc8bf..3306775322 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.ossez
parent-modules
- 0.0.1
+ 0.0.1-SNAPSHOT
pom
CWIKIUS-OSSEZ Java Parent Modules