From 4383c19b631105a638592504ae1bdfde9a709ebc Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Tue, 25 Dec 2018 13:29:44 -0500 Subject: [PATCH 01/33] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20POM=20=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= 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 ab492293fb..7d0a1daad3 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.ossez - lang-tutorial + codebank-algorithm 0.0.1 From 824355ade6bdc7be541ab9f6f6526372b4f0cfe3 Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Tue, 25 Dec 2018 13:31:23 -0500 Subject: [PATCH 02/33] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E5=B0=86=20README=20?= =?UTF-8?q?=E5=90=8D=E5=AD=97=E5=A4=A7=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- readme.md => -README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) rename readme.md => -README.md (97%) diff --git a/readme.md b/-README.md similarity index 97% rename from readme.md rename to -README.md index 4adce6a9c2..c2d39d08e8 100644 --- a/readme.md +++ b/-README.md @@ -1,12 +1,12 @@ -

- - - -
提供 CWIKI.US 项目中使用的代码 -

- -所有的 Java 代码使用的是 JDK 8。 - -你可以通过单击下面连接后访问我们网站,并且访问我们提供的最新有关 Java 的开发资料。 - +

+ + + +
提供 CWIKI.US 项目中使用的代码 +

+ +所有的 Java 代码使用的是 JDK 8。 + +你可以通过单击下面连接后访问我们网站,并且访问我们提供的最新有关 Java 的开发资料。 + * [概述](https://www.cwiki.us/pages/viewpage.action?pageId=37492282) \ No newline at end of file From efcfd989822aea7523b503384d57f3c84f33efb9 Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Tue, 25 Dec 2018 13:32:07 -0500 Subject: [PATCH 03/33] =?UTF-8?q?README=20=E6=96=87=E4=BB=B6=E5=90=8D?= =?UTF-8?q?=E5=A4=A7=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- -README.md => README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename -README.md => README.md (100%) diff --git a/-README.md b/README.md similarity index 100% rename from -README.md rename to README.md From 58b84c1fdb58b6ef0b73b6137d3a9e46166b7785 Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Tue, 25 Dec 2018 13:45:41 -0500 Subject: [PATCH 04/33] =?UTF-8?q?=E5=B0=86=E5=8C=85=E7=9A=84=E5=90=8D?= =?UTF-8?q?=E5=AD=97=E8=BF=9B=E8=A1=8C=E9=87=8D=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../algorithm}/tests/BitOperationTest.java | 72 +-- .../algorithm}/tests/LintcodeTest.java | 586 +++++++++--------- .../algorithm}/tests/SingletonTest.java | 2 +- .../algorithm}/tests/TreeTest.java | 170 ++--- .../algorithm}/tests/VariableTest.java | 2 +- .../tests/codility/CodilityBinaryGapTest.java | 112 ++-- ...ntCode0007SerializeAndDeserializeTest.java | 262 ++++---- .../lintcode/LintCode0069LevelOrderTest.java | 248 ++++---- .../lintcode/LintCode0102HasCycleTest.java | 126 ++-- .../LintCode0165MergeTwoListsTest.java | 178 +++--- .../LintCode0425LetterCombinationsTest.java | 156 ++--- .../lintcode/LintCode0433NumIslandsTest.java | 188 +++--- .../lintcode/LintCode1480DotProductTest.java | 70 +-- 13 files changed, 1086 insertions(+), 1086 deletions(-) rename src/test/java/com/ossez/{lang/tutorial => codebank/algorithm}/tests/BitOperationTest.java (90%) rename src/test/java/com/ossez/{lang/tutorial => codebank/algorithm}/tests/LintcodeTest.java (94%) rename src/test/java/com/ossez/{lang/tutorial => codebank/algorithm}/tests/SingletonTest.java (91%) rename src/test/java/com/ossez/{lang/tutorial => codebank/algorithm}/tests/TreeTest.java (92%) rename src/test/java/com/ossez/{lang/tutorial => codebank/algorithm}/tests/VariableTest.java (90%) rename src/test/java/com/ossez/{lang/tutorial => codebank/algorithm}/tests/codility/CodilityBinaryGapTest.java (91%) rename src/test/java/com/ossez/{lang/tutorial => codebank/algorithm}/tests/lintcode/LintCode0007SerializeAndDeserializeTest.java (93%) rename src/test/java/com/ossez/{lang/tutorial => codebank/algorithm}/tests/lintcode/LintCode0069LevelOrderTest.java (93%) rename src/test/java/com/ossez/{lang/tutorial => codebank/algorithm}/tests/lintcode/LintCode0102HasCycleTest.java (91%) rename src/test/java/com/ossez/{lang/tutorial => codebank/algorithm}/tests/lintcode/LintCode0165MergeTwoListsTest.java (92%) rename src/test/java/com/ossez/{lang/tutorial => codebank/algorithm}/tests/lintcode/LintCode0425LetterCombinationsTest.java (93%) rename src/test/java/com/ossez/{lang/tutorial => codebank/algorithm}/tests/lintcode/LintCode0433NumIslandsTest.java (92%) rename src/test/java/com/ossez/{lang/tutorial => codebank/algorithm}/tests/lintcode/LintCode1480DotProductTest.java (89%) diff --git a/src/test/java/com/ossez/lang/tutorial/tests/BitOperationTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/BitOperationTest.java similarity index 90% rename from src/test/java/com/ossez/lang/tutorial/tests/BitOperationTest.java rename to src/test/java/com/ossez/codebank/algorithm/tests/BitOperationTest.java index eb570df0dd..257c6a3a68 100644 --- a/src/test/java/com/ossez/lang/tutorial/tests/BitOperationTest.java +++ b/src/test/java/com/ossez/codebank/algorithm/tests/BitOperationTest.java @@ -1,36 +1,36 @@ -package com.ossez.lang.tutorial.tests; - -import org.apache.commons.math3.util.FastMath; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * - * @author YuCheng - * - */ -public class BitOperationTest { - - private final static Logger logger = LoggerFactory.getLogger(BitOperationTest.class); - - /** - * 35 https://www.lintcode.com/problem/reverse-linked-list/description - */ - @Test - public void testInt2Bit() { - logger.debug("BEGIN"); - System.out.println(Integer.toBinaryString(5)); - System.out.println(Integer.toBinaryString(2)); - - System.out.println(Integer.toBinaryString(2 << 2)); - - System.out.println(Integer.parseInt(Integer.toBinaryString(2 << 2), 2)); - - System.out.println(5 / 3); - System.out.println(5 % 3); - FastMath.pow(2, 3); - - } - -} +package com.ossez.codebank.algorithm.tests; + +import org.apache.commons.math3.util.FastMath; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author YuCheng + * + */ +public class BitOperationTest { + + private final static Logger logger = LoggerFactory.getLogger(BitOperationTest.class); + + /** + * 35 https://www.lintcode.com/problem/reverse-linked-list/description + */ + @Test + public void testInt2Bit() { + logger.debug("BEGIN"); + System.out.println(Integer.toBinaryString(5)); + System.out.println(Integer.toBinaryString(2)); + + System.out.println(Integer.toBinaryString(2 << 2)); + + System.out.println(Integer.parseInt(Integer.toBinaryString(2 << 2), 2)); + + System.out.println(5 / 3); + System.out.println(5 % 3); + FastMath.pow(2, 3); + + } + +} diff --git a/src/test/java/com/ossez/lang/tutorial/tests/LintcodeTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/LintcodeTest.java similarity index 94% rename from src/test/java/com/ossez/lang/tutorial/tests/LintcodeTest.java rename to src/test/java/com/ossez/codebank/algorithm/tests/LintcodeTest.java index 7cf699092d..566fee90ea 100644 --- a/src/test/java/com/ossez/lang/tutorial/tests/LintcodeTest.java +++ b/src/test/java/com/ossez/codebank/algorithm/tests/LintcodeTest.java @@ -1,293 +1,293 @@ -package com.ossez.lang.tutorial.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.lang.tutorial.models.ListNode; - -/** - * - * @author YuCheng - * - */ -public class LintcodeTest { - - private final static Logger logger = LoggerFactory.getLogger(LintcodeTest.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.algorithm.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.lang.tutorial.models.ListNode; + +/** + * + * @author YuCheng + * + */ +public class LintcodeTest { + + private final static Logger logger = LoggerFactory.getLogger(LintcodeTest.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()); + } + +} diff --git a/src/test/java/com/ossez/lang/tutorial/tests/SingletonTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/SingletonTest.java similarity index 91% rename from src/test/java/com/ossez/lang/tutorial/tests/SingletonTest.java rename to src/test/java/com/ossez/codebank/algorithm/tests/SingletonTest.java index a6cd888777..041a9b840c 100644 --- a/src/test/java/com/ossez/lang/tutorial/tests/SingletonTest.java +++ b/src/test/java/com/ossez/codebank/algorithm/tests/SingletonTest.java @@ -1,4 +1,4 @@ -package com.ossez.lang.tutorial.tests; +package com.ossez.codebank.algorithm.tests; import org.junit.Test; import org.slf4j.Logger; diff --git a/src/test/java/com/ossez/lang/tutorial/tests/TreeTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/TreeTest.java similarity index 92% rename from src/test/java/com/ossez/lang/tutorial/tests/TreeTest.java rename to src/test/java/com/ossez/codebank/algorithm/tests/TreeTest.java index ee67e07c05..6f88cd156e 100644 --- a/src/test/java/com/ossez/lang/tutorial/tests/TreeTest.java +++ b/src/test/java/com/ossez/codebank/algorithm/tests/TreeTest.java @@ -1,85 +1,85 @@ -package com.ossez.lang.tutorial.tests; - -import java.util.ArrayList; -import java.util.List; - -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; - -/** - * - * @author YuCheng - * - */ -public class TreeTest { - private final static Logger logger = LoggerFactory.getLogger(TreeTest.class); - private static List loopList = new ArrayList(); - - @Test - public void testMain() { - logger.debug("TREE TEST"); - String data = "{1,2,3,4,5,#,6,#,#,7,8,#,#}"; - TreeNode treeNode = TreeUtils.initTree(data); - - // PRE - loopList = new ArrayList(); - preOrderTraverselRecursion(treeNode); - System.out.println(loopList); - - // IN - loopList = new ArrayList(); - inOrderTraverselRecursion(treeNode); - System.out.println(loopList); - - // POST - loopList = new ArrayList(); - postOrderTraversalRecursion(treeNode); - System.out.println(loopList); - } - - - - - /** - * - * @param root - */ - public void preOrderTraverselRecursion(TreeNode root) { - if (root != null) { - loopList.add(root.val); - preOrderTraverselRecursion(root.left); - preOrderTraverselRecursion(root.right); - } - } - - /** - * - * @param root - */ - public void inOrderTraverselRecursion(TreeNode root) { - if (root != null) { - inOrderTraverselRecursion(root.left); - loopList.add(root.val); - inOrderTraverselRecursion(root.right); - } - - } - - /** - * - * @param root - */ - public void postOrderTraversalRecursion(TreeNode root) { - if (root != null) { - postOrderTraversalRecursion(root.left); - postOrderTraversalRecursion(root.right); - loopList.add(root.val); - } - - } - -} +package com.ossez.codebank.algorithm.tests; + +import java.util.ArrayList; +import java.util.List; + +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; + +/** + * + * @author YuCheng + * + */ +public class TreeTest { + private final static Logger logger = LoggerFactory.getLogger(TreeTest.class); + private static List loopList = new ArrayList(); + + @Test + public void testMain() { + logger.debug("TREE TEST"); + String data = "{1,2,3,4,5,#,6,#,#,7,8,#,#}"; + TreeNode treeNode = TreeUtils.initTree(data); + + // PRE + loopList = new ArrayList(); + preOrderTraverselRecursion(treeNode); + System.out.println(loopList); + + // IN + loopList = new ArrayList(); + inOrderTraverselRecursion(treeNode); + System.out.println(loopList); + + // POST + loopList = new ArrayList(); + postOrderTraversalRecursion(treeNode); + System.out.println(loopList); + } + + + + + /** + * + * @param root + */ + public void preOrderTraverselRecursion(TreeNode root) { + if (root != null) { + loopList.add(root.val); + preOrderTraverselRecursion(root.left); + preOrderTraverselRecursion(root.right); + } + } + + /** + * + * @param root + */ + public void inOrderTraverselRecursion(TreeNode root) { + if (root != null) { + inOrderTraverselRecursion(root.left); + loopList.add(root.val); + inOrderTraverselRecursion(root.right); + } + + } + + /** + * + * @param root + */ + public void postOrderTraversalRecursion(TreeNode root) { + if (root != null) { + postOrderTraversalRecursion(root.left); + postOrderTraversalRecursion(root.right); + loopList.add(root.val); + } + + } + +} diff --git a/src/test/java/com/ossez/lang/tutorial/tests/VariableTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/VariableTest.java similarity index 90% rename from src/test/java/com/ossez/lang/tutorial/tests/VariableTest.java rename to src/test/java/com/ossez/codebank/algorithm/tests/VariableTest.java index a7112e3aea..16388db179 100644 --- a/src/test/java/com/ossez/lang/tutorial/tests/VariableTest.java +++ b/src/test/java/com/ossez/codebank/algorithm/tests/VariableTest.java @@ -1,4 +1,4 @@ -package com.ossez.lang.tutorial.tests; +package com.ossez.codebank.algorithm.tests; import org.junit.Test; import org.slf4j.Logger; diff --git a/src/test/java/com/ossez/lang/tutorial/tests/codility/CodilityBinaryGapTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/codility/CodilityBinaryGapTest.java similarity index 91% rename from src/test/java/com/ossez/lang/tutorial/tests/codility/CodilityBinaryGapTest.java rename to src/test/java/com/ossez/codebank/algorithm/tests/codility/CodilityBinaryGapTest.java index f430a4f5d0..9a017bb488 100644 --- a/src/test/java/com/ossez/lang/tutorial/tests/codility/CodilityBinaryGapTest.java +++ b/src/test/java/com/ossez/codebank/algorithm/tests/codility/CodilityBinaryGapTest.java @@ -1,56 +1,56 @@ -package com.ossez.lang.tutorial.tests.codility; - -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - *

- * More details about question see link below - *

- *

- * - * @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); - } - -} +package com.ossez.codebank.algorithm.tests.codility; + +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + *

+ * More details about question see link below + *

+ *

+ * + * @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); + } + +} diff --git a/src/test/java/com/ossez/lang/tutorial/tests/lintcode/LintCode0007SerializeAndDeserializeTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0007SerializeAndDeserializeTest.java similarity index 93% rename from src/test/java/com/ossez/lang/tutorial/tests/lintcode/LintCode0007SerializeAndDeserializeTest.java rename to src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0007SerializeAndDeserializeTest.java index cb900c3f37..ad21270072 100644 --- a/src/test/java/com/ossez/lang/tutorial/tests/lintcode/LintCode0007SerializeAndDeserializeTest.java +++ b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0007SerializeAndDeserializeTest.java @@ -1,131 +1,131 @@ -package com.ossez.lang.tutorial.tests.lintcode; - -import java.util.ArrayList; - -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.ossez.lang.tutorial.models.TreeNode; - -/** - *

- * 7 - *

- *

- * - * @author YuCheng - * - */ -public class LintCode0007SerializeAndDeserializeTest { - - private final static Logger logger = LoggerFactory.getLogger(LintCode0007SerializeAndDeserializeTest.class); - - /** - * - */ - @Test - public void testMain() { - logger.debug("BEGIN"); - String data = "{3,9,20,#,#,15,7}"; - - System.out.println(serialize(deserialize(data))); - - } - - /** - * Deserialize from array to tree - * - * @param data - * @return - */ - private TreeNode deserialize(String data) { - // NULL CHECK - if (data.equals("{}")) { - return null; - } - - ArrayList treeList = new ArrayList(); - - data = data.replace("{", ""); - data = data.replace("}", ""); - String[] vals = data.split(","); - - // INSERT ROOT - TreeNode root = new TreeNode(Integer.parseInt(vals[0])); - treeList.add(root); - - int index = 0; - boolean isLeftChild = true; - for (int i = 1; i < vals.length; i++) { - if (!vals[i].equals("#")) { - TreeNode node = new TreeNode(Integer.parseInt(vals[i])); - if (isLeftChild) { - treeList.get(index).left = node; - } else { - treeList.get(index).right = node; - } - treeList.add(node); - } - - // LEVEL - if (!isLeftChild) { - index++; - } - - // MOVE TO RIGHT OR NEXT LEVEL - isLeftChild = !isLeftChild; - } - - return root; - - } - - /** - * - * @param root - * @return - */ - public String serialize(TreeNode root) { - // write your code here - if (root == null) { - return "{}"; - } - - ArrayList queue = new ArrayList(); - queue.add(root); - - for (int i = 0; i < queue.size(); i++) { - TreeNode node = queue.get(i); - if (node == null) { - continue; - } - queue.add(node.left); - queue.add(node.right); - } - - while (queue.get(queue.size() - 1) == null) { - queue.remove(queue.size() - 1); - } - - StringBuilder sb = new StringBuilder(); - sb.append("{"); - sb.append(queue.get(0).val); - for (int i = 1; i < queue.size(); i++) { - if (queue.get(i) == null) { - sb.append(",#"); - } else { - sb.append(","); - sb.append(queue.get(i).val); - } - } - sb.append("}"); - return sb.toString(); - } - -} +package com.ossez.codebank.algorithm.tests.lintcode; + +import java.util.ArrayList; + +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.ossez.lang.tutorial.models.TreeNode; + +/** + *

+ * 7 + *

+ *

+ * + * @author YuCheng + * + */ +public class LintCode0007SerializeAndDeserializeTest { + + private final static Logger logger = LoggerFactory.getLogger(LintCode0007SerializeAndDeserializeTest.class); + + /** + * + */ + @Test + public void testMain() { + logger.debug("BEGIN"); + String data = "{3,9,20,#,#,15,7}"; + + System.out.println(serialize(deserialize(data))); + + } + + /** + * Deserialize from array to tree + * + * @param data + * @return + */ + private TreeNode deserialize(String data) { + // NULL CHECK + if (data.equals("{}")) { + return null; + } + + ArrayList treeList = new ArrayList(); + + data = data.replace("{", ""); + data = data.replace("}", ""); + String[] vals = data.split(","); + + // INSERT ROOT + TreeNode root = new TreeNode(Integer.parseInt(vals[0])); + treeList.add(root); + + int index = 0; + boolean isLeftChild = true; + for (int i = 1; i < vals.length; i++) { + if (!vals[i].equals("#")) { + TreeNode node = new TreeNode(Integer.parseInt(vals[i])); + if (isLeftChild) { + treeList.get(index).left = node; + } else { + treeList.get(index).right = node; + } + treeList.add(node); + } + + // LEVEL + if (!isLeftChild) { + index++; + } + + // MOVE TO RIGHT OR NEXT LEVEL + isLeftChild = !isLeftChild; + } + + return root; + + } + + /** + * + * @param root + * @return + */ + public String serialize(TreeNode root) { + // write your code here + if (root == null) { + return "{}"; + } + + ArrayList queue = new ArrayList(); + queue.add(root); + + for (int i = 0; i < queue.size(); i++) { + TreeNode node = queue.get(i); + if (node == null) { + continue; + } + queue.add(node.left); + queue.add(node.right); + } + + while (queue.get(queue.size() - 1) == null) { + queue.remove(queue.size() - 1); + } + + StringBuilder sb = new StringBuilder(); + sb.append("{"); + sb.append(queue.get(0).val); + for (int i = 1; i < queue.size(); i++) { + if (queue.get(i) == null) { + sb.append(",#"); + } else { + sb.append(","); + sb.append(queue.get(i).val); + } + } + sb.append("}"); + return sb.toString(); + } + +} diff --git a/src/test/java/com/ossez/lang/tutorial/tests/lintcode/LintCode0069LevelOrderTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0069LevelOrderTest.java similarity index 93% rename from src/test/java/com/ossez/lang/tutorial/tests/lintcode/LintCode0069LevelOrderTest.java rename to src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0069LevelOrderTest.java index f0f661947a..5a35ff7b73 100644 --- a/src/test/java/com/ossez/lang/tutorial/tests/lintcode/LintCode0069LevelOrderTest.java +++ b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0069LevelOrderTest.java @@ -1,124 +1,124 @@ -package com.ossez.lang.tutorial.tests.lintcode; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Queue; - -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.ossez.lang.tutorial.models.TreeNode; - -/** - *

- * 69 - *

- *

- * - * @author YuCheng - * - */ -public class LintCode0069LevelOrderTest { - - private final static Logger logger = LoggerFactory.getLogger(LintCode0069LevelOrderTest.class); - - /** - * - */ - @Test - public void testMain() { - logger.debug("BEGIN"); - String data = "{3,9,20,#,#,15,7}"; - - TreeNode tn = deserialize(data); - System.out.println(levelOrder(tn)); - - } - - /** - * Deserialize from array to tree - * - * @param data - * @return - */ - private TreeNode deserialize(String data) { - // NULL CHECK - if (data.equals("{}")) { - return null; - } - - ArrayList treeList = new ArrayList(); - - data = data.replace("{", ""); - data = data.replace("}", ""); - String[] vals = data.split(","); - - // INSERT ROOT - TreeNode root = new TreeNode(Integer.parseInt(vals[0])); - treeList.add(root); - - int index = 0; - boolean isLeftChild = true; - for (int i = 1; i < vals.length; i++) { - if (!vals[i].equals("#")) { - TreeNode node = new TreeNode(Integer.parseInt(vals[i])); - if (isLeftChild) { - treeList.get(index).left = node; - } else { - treeList.get(index).right = node; - } - treeList.add(node); - } - - // LEVEL - if (!isLeftChild) { - index++; - } - - // MOVE TO RIGHT OR NEXT LEVEL - isLeftChild = !isLeftChild; - } - - return root; - - } - - private List> levelOrder(TreeNode root) { - Queue queue = new LinkedList(); - List> rs = new ArrayList>(); - - // NULL CHECK - if (root == null) { - return rs; - } - - queue.offer(root); - - while (!queue.isEmpty()) { - int length = queue.size(); - List list = new ArrayList(); - - for (int i = 0; i < length; i++) { - TreeNode curTN = queue.poll(); - list.add(curTN.val); - if (curTN.left != null) { - queue.offer(curTN.left); - } - if (curTN.right != null) { - queue.offer(curTN.right); - } - } - - rs.add(list); - } - - return rs; - } -} +package com.ossez.codebank.algorithm.tests.lintcode; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.ossez.lang.tutorial.models.TreeNode; + +/** + *

+ * 69 + *

+ *

+ * + * @author YuCheng + * + */ +public class LintCode0069LevelOrderTest { + + private final static Logger logger = LoggerFactory.getLogger(LintCode0069LevelOrderTest.class); + + /** + * + */ + @Test + public void testMain() { + logger.debug("BEGIN"); + String data = "{3,9,20,#,#,15,7}"; + + TreeNode tn = deserialize(data); + System.out.println(levelOrder(tn)); + + } + + /** + * Deserialize from array to tree + * + * @param data + * @return + */ + private TreeNode deserialize(String data) { + // NULL CHECK + if (data.equals("{}")) { + return null; + } + + ArrayList treeList = new ArrayList(); + + data = data.replace("{", ""); + data = data.replace("}", ""); + String[] vals = data.split(","); + + // INSERT ROOT + TreeNode root = new TreeNode(Integer.parseInt(vals[0])); + treeList.add(root); + + int index = 0; + boolean isLeftChild = true; + for (int i = 1; i < vals.length; i++) { + if (!vals[i].equals("#")) { + TreeNode node = new TreeNode(Integer.parseInt(vals[i])); + if (isLeftChild) { + treeList.get(index).left = node; + } else { + treeList.get(index).right = node; + } + treeList.add(node); + } + + // LEVEL + if (!isLeftChild) { + index++; + } + + // MOVE TO RIGHT OR NEXT LEVEL + isLeftChild = !isLeftChild; + } + + return root; + + } + + private List> levelOrder(TreeNode root) { + Queue queue = new LinkedList(); + List> rs = new ArrayList>(); + + // NULL CHECK + if (root == null) { + return rs; + } + + queue.offer(root); + + while (!queue.isEmpty()) { + int length = queue.size(); + List list = new ArrayList(); + + for (int i = 0; i < length; i++) { + TreeNode curTN = queue.poll(); + list.add(curTN.val); + if (curTN.left != null) { + queue.offer(curTN.left); + } + if (curTN.right != null) { + queue.offer(curTN.right); + } + } + + rs.add(list); + } + + return rs; + } +} diff --git a/src/test/java/com/ossez/lang/tutorial/tests/lintcode/LintCode0102HasCycleTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0102HasCycleTest.java similarity index 91% rename from src/test/java/com/ossez/lang/tutorial/tests/lintcode/LintCode0102HasCycleTest.java rename to src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0102HasCycleTest.java index 7ded09697e..e20e2d6b72 100644 --- a/src/test/java/com/ossez/lang/tutorial/tests/lintcode/LintCode0102HasCycleTest.java +++ b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0102HasCycleTest.java @@ -1,63 +1,63 @@ -package com.ossez.lang.tutorial.tests.lintcode; - -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.ossez.lang.tutorial.models.ListNode; - -/** - *

- * 102 - *

- *

- * - * @author YuCheng - * - */ -public class LintCode0102HasCycleTest { - - private final static Logger logger = LoggerFactory.getLogger(LintCode0102HasCycleTest.class); - - /** - * - */ - @Test - public void testMain() { - logger.debug("BEGIN"); - // INIT LINKED LIST - ListNode head = new ListNode(1); - head.next = new ListNode(2); - head.next.next = new ListNode(3); - head.next.next.next = new ListNode(4); - - // CREATE A LOOP - head.next.next.next.next = head.next.next.next; - - boolean retResult = false; - - // LIKED LIST MAY NULL: - if (!(head == null || head.next == null)) { - ListNode s = head; - ListNode f = head.next; - - while (f.next != null && f.next.next != null) { - - s = s.next; - f = f.next.next; - - if (f == s) { - retResult = true; - break; - } - } - } - - System.out.println(retResult); - - } -} +package com.ossez.codebank.algorithm.tests.lintcode; + +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.ossez.lang.tutorial.models.ListNode; + +/** + *

+ * 102 + *

+ *

+ * + * @author YuCheng + * + */ +public class LintCode0102HasCycleTest { + + private final static Logger logger = LoggerFactory.getLogger(LintCode0102HasCycleTest.class); + + /** + * + */ + @Test + public void testMain() { + logger.debug("BEGIN"); + // INIT LINKED LIST + ListNode head = new ListNode(1); + head.next = new ListNode(2); + head.next.next = new ListNode(3); + head.next.next.next = new ListNode(4); + + // CREATE A LOOP + head.next.next.next.next = head.next.next.next; + + boolean retResult = false; + + // LIKED LIST MAY NULL: + if (!(head == null || head.next == null)) { + ListNode s = head; + ListNode f = head.next; + + while (f.next != null && f.next.next != null) { + + s = s.next; + f = f.next.next; + + if (f == s) { + retResult = true; + break; + } + } + } + + System.out.println(retResult); + + } +} diff --git a/src/test/java/com/ossez/lang/tutorial/tests/lintcode/LintCode0165MergeTwoListsTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0165MergeTwoListsTest.java similarity index 92% rename from src/test/java/com/ossez/lang/tutorial/tests/lintcode/LintCode0165MergeTwoListsTest.java rename to src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0165MergeTwoListsTest.java index 5bfac549d6..6591addbbb 100644 --- a/src/test/java/com/ossez/lang/tutorial/tests/lintcode/LintCode0165MergeTwoListsTest.java +++ b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0165MergeTwoListsTest.java @@ -1,89 +1,89 @@ -package com.ossez.lang.tutorial.tests.lintcode; - -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.ossez.lang.tutorial.models.ListNode; - -/** - *

- * 102 - *

- *

- * - * @author YuCheng - * - */ -public class LintCode0165MergeTwoListsTest { - - private final static Logger logger = LoggerFactory.getLogger(LintCode0165MergeTwoListsTest.class); - - /** - * - */ - @Test - public void testMain() { - logger.debug("BEGIN"); - // INIT LINKED LIST l1 - ListNode l1 = new ListNode(1); - l1.next = new ListNode(3); - l1.next.next = new ListNode(8); - l1.next.next.next = new ListNode(11); - l1.next.next.next.next = new ListNode(15); - - // INIT LINKED LIST l2 - ListNode l2 = new ListNode(2); - - // RETURN RESULT - ListNode retResult = new ListNode(0); - - // NULL CHECK - // if (l1 == null && l2 == null) { - // retResult = null; - // } - // - // if (l1 == null) { - // retResult = l2; - // } - // - // if (l2 == null) { - // retResult = l1; - // } - - // MERGE - retResult = new ListNode(0); - ListNode tmpNode = new ListNode(0); - retResult = tmpNode; - while (l1 != null & l2 != null) { - if (l1.val <= l2.val) { - tmpNode.next = l1; - l1 = l1.next; - } else { - tmpNode.next = l2; - l2 = l2.next; - } - - tmpNode = tmpNode.next; - } - - if (l1 == null) { - tmpNode.next = l2; - } - - if (l2 == null) { - tmpNode.next = l1; - } - - retResult = retResult.next; - - System.out.println(retResult.val); - System.out.println(retResult.next.val); - System.out.println(retResult.next.next.val); - - } -} +package com.ossez.codebank.algorithm.tests.lintcode; + +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.ossez.lang.tutorial.models.ListNode; + +/** + *

+ * 102 + *

+ *

+ * + * @author YuCheng + * + */ +public class LintCode0165MergeTwoListsTest { + + private final static Logger logger = LoggerFactory.getLogger(LintCode0165MergeTwoListsTest.class); + + /** + * + */ + @Test + public void testMain() { + logger.debug("BEGIN"); + // INIT LINKED LIST l1 + ListNode l1 = new ListNode(1); + l1.next = new ListNode(3); + l1.next.next = new ListNode(8); + l1.next.next.next = new ListNode(11); + l1.next.next.next.next = new ListNode(15); + + // INIT LINKED LIST l2 + ListNode l2 = new ListNode(2); + + // RETURN RESULT + ListNode retResult = new ListNode(0); + + // NULL CHECK + // if (l1 == null && l2 == null) { + // retResult = null; + // } + // + // if (l1 == null) { + // retResult = l2; + // } + // + // if (l2 == null) { + // retResult = l1; + // } + + // MERGE + retResult = new ListNode(0); + ListNode tmpNode = new ListNode(0); + retResult = tmpNode; + while (l1 != null & l2 != null) { + if (l1.val <= l2.val) { + tmpNode.next = l1; + l1 = l1.next; + } else { + tmpNode.next = l2; + l2 = l2.next; + } + + tmpNode = tmpNode.next; + } + + if (l1 == null) { + tmpNode.next = l2; + } + + if (l2 == null) { + tmpNode.next = l1; + } + + retResult = retResult.next; + + System.out.println(retResult.val); + System.out.println(retResult.next.val); + System.out.println(retResult.next.next.val); + + } +} diff --git a/src/test/java/com/ossez/lang/tutorial/tests/lintcode/LintCode0425LetterCombinationsTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0425LetterCombinationsTest.java similarity index 93% rename from src/test/java/com/ossez/lang/tutorial/tests/lintcode/LintCode0425LetterCombinationsTest.java rename to src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0425LetterCombinationsTest.java index 7312cbb993..888cdd22de 100644 --- a/src/test/java/com/ossez/lang/tutorial/tests/lintcode/LintCode0425LetterCombinationsTest.java +++ b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0425LetterCombinationsTest.java @@ -1,78 +1,78 @@ -package com.ossez.lang.tutorial.tests.lintcode; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - *

- * 425 - *

- *

- * - * @author YuCheng - * - */ -public class LintCode0425LetterCombinationsTest { - - private final static Logger logger = LoggerFactory.getLogger(LintCode0425LetterCombinationsTest.class); - - /** - * - */ - @Test - public void testMain() { - logger.debug("LetterCombinationsTest"); - String digits = "23"; - - HashMap phoneKeyMap = new HashMap(); - phoneKeyMap.put("0", ""); - phoneKeyMap.put("1", ""); - phoneKeyMap.put("2", "abc"); - phoneKeyMap.put("3", "def"); - phoneKeyMap.put("4", "ghi"); - phoneKeyMap.put("5", "jkl"); - phoneKeyMap.put("6", "mno"); - phoneKeyMap.put("7", "pqrs"); - phoneKeyMap.put("8", "tuv"); - phoneKeyMap.put("9", "wxyz"); - - List retStatus = new ArrayList<>(); - - if (digits != null && digits.length() != 0) { - phoneRecursive(digits, retStatus, phoneKeyMap, "", 0); - } - - System.out.println(retStatus); - } - - /** - * phoneRecursive - * - * @param digits - * @param retStatus - * @param phoneKeyMap - * @param comb - * @param index - */ - private void phoneRecursive(String digits, List retStatus, HashMap phoneKeyMap, String comb, int index) { - if (index == digits.length()) { - retStatus.add(comb); - return; - } - - char pos = digits.charAt(index); - for (char c : ((String) phoneKeyMap.get(String.valueOf(pos))).toCharArray()) { - phoneRecursive(digits, retStatus, phoneKeyMap, comb + c, index + 1); - } - } -} +package com.ossez.codebank.algorithm.tests.lintcode; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + *

+ * 425 + *

+ *

+ * + * @author YuCheng + * + */ +public class LintCode0425LetterCombinationsTest { + + private final static Logger logger = LoggerFactory.getLogger(LintCode0425LetterCombinationsTest.class); + + /** + * + */ + @Test + public void testMain() { + logger.debug("LetterCombinationsTest"); + String digits = "23"; + + HashMap phoneKeyMap = new HashMap(); + phoneKeyMap.put("0", ""); + phoneKeyMap.put("1", ""); + phoneKeyMap.put("2", "abc"); + phoneKeyMap.put("3", "def"); + phoneKeyMap.put("4", "ghi"); + phoneKeyMap.put("5", "jkl"); + phoneKeyMap.put("6", "mno"); + phoneKeyMap.put("7", "pqrs"); + phoneKeyMap.put("8", "tuv"); + phoneKeyMap.put("9", "wxyz"); + + List retStatus = new ArrayList<>(); + + if (digits != null && digits.length() != 0) { + phoneRecursive(digits, retStatus, phoneKeyMap, "", 0); + } + + System.out.println(retStatus); + } + + /** + * phoneRecursive + * + * @param digits + * @param retStatus + * @param phoneKeyMap + * @param comb + * @param index + */ + private void phoneRecursive(String digits, List retStatus, HashMap phoneKeyMap, String comb, int index) { + if (index == digits.length()) { + retStatus.add(comb); + return; + } + + char pos = digits.charAt(index); + for (char c : ((String) phoneKeyMap.get(String.valueOf(pos))).toCharArray()) { + phoneRecursive(digits, retStatus, phoneKeyMap, comb + c, index + 1); + } + } +} diff --git a/src/test/java/com/ossez/lang/tutorial/tests/lintcode/LintCode0433NumIslandsTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0433NumIslandsTest.java similarity index 92% rename from src/test/java/com/ossez/lang/tutorial/tests/lintcode/LintCode0433NumIslandsTest.java rename to src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0433NumIslandsTest.java index 534bc9f4d6..2b7b048250 100644 --- a/src/test/java/com/ossez/lang/tutorial/tests/lintcode/LintCode0433NumIslandsTest.java +++ b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0433NumIslandsTest.java @@ -1,94 +1,94 @@ -package com.ossez.lang.tutorial.tests.lintcode; - -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - *

- * 433 - *

- *

- * - * @author YuCheng - * - */ -public class LintCode0433NumIslandsTest { - - private final static Logger logger = LoggerFactory.getLogger(LintCode0433NumIslandsTest.class); - - /** - * - */ - @Test - public void testMain() { - logger.debug("BEGIN"); - // INIT GRID - boolean[][] grid = { { true, true, false, false, false }, { false, true, false, false, true }, { false, false, false, true, true }, - { false, false, false, false, false }, { false, false, false, false, true } - - }; - - // NULL CHECK - if (grid.length == 0 || grid[0].length == 0) { - System.out.println("NULL"); - // return 0; - } - - // GET SIZE - int n = grid.length; - int m = grid[0].length; - - // ARRAY FOR VISITED LOG - boolean[][] visited = new boolean[n][m]; - - int count = 0; - - // LOOP FOR GRID - for (int i = 0; i < n; i++) { - for (int j = 0; j < m; j++) { - if (grid[i][j] && !visited[i][j]) { - numIslandsDFS(grid, visited, i, j); - count++; - } - } - } - - System.out.println(count); - - } - - /** - * - * @param grid - * @param visited - * @param x - * @param y - */ - public void numIslandsDFS(boolean[][] grid, boolean[][] visited, int x, int y) { - if (x < 0 || x >= grid.length) { - return; - } - - if (y < 0 || y >= grid[0].length) { - return; - } - - if (grid[x][y] != true || visited[x][y]) { - return; - } - - visited[x][y] = true; - - // Recursive call - numIslandsDFS(grid, visited, x - 1, y); - numIslandsDFS(grid, visited, x + 1, y); - numIslandsDFS(grid, visited, x, y - 1); - numIslandsDFS(grid, visited, x, y + 1); - - } -} +package com.ossez.codebank.algorithm.tests.lintcode; + +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + *

+ * 433 + *

+ *

+ * + * @author YuCheng + * + */ +public class LintCode0433NumIslandsTest { + + private final static Logger logger = LoggerFactory.getLogger(LintCode0433NumIslandsTest.class); + + /** + * + */ + @Test + public void testMain() { + logger.debug("BEGIN"); + // INIT GRID + boolean[][] grid = { { true, true, false, false, false }, { false, true, false, false, true }, { false, false, false, true, true }, + { false, false, false, false, false }, { false, false, false, false, true } + + }; + + // NULL CHECK + if (grid.length == 0 || grid[0].length == 0) { + System.out.println("NULL"); + // return 0; + } + + // GET SIZE + int n = grid.length; + int m = grid[0].length; + + // ARRAY FOR VISITED LOG + boolean[][] visited = new boolean[n][m]; + + int count = 0; + + // LOOP FOR GRID + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (grid[i][j] && !visited[i][j]) { + numIslandsDFS(grid, visited, i, j); + count++; + } + } + } + + System.out.println(count); + + } + + /** + * + * @param grid + * @param visited + * @param x + * @param y + */ + public void numIslandsDFS(boolean[][] grid, boolean[][] visited, int x, int y) { + if (x < 0 || x >= grid.length) { + return; + } + + if (y < 0 || y >= grid[0].length) { + return; + } + + if (grid[x][y] != true || visited[x][y]) { + return; + } + + visited[x][y] = true; + + // Recursive call + numIslandsDFS(grid, visited, x - 1, y); + numIslandsDFS(grid, visited, x + 1, y); + numIslandsDFS(grid, visited, x, y - 1); + numIslandsDFS(grid, visited, x, y + 1); + + } +} diff --git a/src/test/java/com/ossez/lang/tutorial/tests/lintcode/LintCode1480DotProductTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode1480DotProductTest.java similarity index 89% rename from src/test/java/com/ossez/lang/tutorial/tests/lintcode/LintCode1480DotProductTest.java rename to src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode1480DotProductTest.java index fb62a811a0..f153218e37 100644 --- a/src/test/java/com/ossez/lang/tutorial/tests/lintcode/LintCode1480DotProductTest.java +++ b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode1480DotProductTest.java @@ -1,35 +1,35 @@ -package com.ossez.lang.tutorial.tests.lintcode; - -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - *

- * 1480 - *

- *

- * - * @author YuCheng - * - */ -public class LintCode1480DotProductTest { - - private final static Logger logger = LoggerFactory.getLogger(LintCode1480DotProductTest.class); - - /** - * - */ - @Test - public void testMain() { - logger.debug("BEGIN"); - int t = 87; - int[] dur = { 20, 25, 19, 37 }; - // Write your code here - } - -} +package com.ossez.codebank.algorithm.tests.lintcode; + +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + *

+ * 1480 + *

+ *

+ * + * @author YuCheng + * + */ +public class LintCode1480DotProductTest { + + private final static Logger logger = LoggerFactory.getLogger(LintCode1480DotProductTest.class); + + /** + * + */ + @Test + public void testMain() { + logger.debug("BEGIN"); + int t = 87; + int[] dur = { 20, 25, 19, 37 }; + // Write your code here + } + +} From 6b3f0afa0f9bfff7fa5321c317d0335e9bf364e9 Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Tue, 25 Dec 2018 14:38:25 -0500 Subject: [PATCH 05/33] =?UTF-8?q?Kayak=20=E9=9D=A2=E8=AF=95=E9=A2=98?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=20Unit=20=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../codebank/interview/tests/KayakTest.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/test/java/com/ossez/codebank/interview/tests/KayakTest.java diff --git a/src/test/java/com/ossez/codebank/interview/tests/KayakTest.java b/src/test/java/com/ossez/codebank/interview/tests/KayakTest.java new file mode 100644 index 0000000000..3f7c3e7eca --- /dev/null +++ b/src/test/java/com/ossez/codebank/interview/tests/KayakTest.java @@ -0,0 +1,33 @@ +package com.ossez.codebank.interview.tests; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.ossez.codebank.interview.KayakRobotMovement; + +/** + * + * @author YuCheng + * + */ +public class KayakTest { + + private final static Logger logger = LoggerFactory.getLogger(KayakTest.class); + + /** + * testGetCoordinates + */ + @Test + public void testGetCoordinates() { + logger.debug("TEST Get Coordinat "); + logger.debug("LFFF - [{}]", KayakRobotMovement.getCoordinates("LFFF")); + + assertEquals(KayakRobotMovement.getCoordinates("FF"), "0,2"); + assertEquals(KayakRobotMovement.getCoordinates("LFFFRFFFRRFFF"), "-3,0"); + + } + +} From 8a65195b33b6bb1b13fdce1f48d85cfce1acf82b Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Tue, 25 Dec 2018 14:39:56 -0500 Subject: [PATCH 06/33] =?UTF-8?q?Kayak=20=E4=BB=A3=E7=A0=81=E9=9D=A2?= =?UTF-8?q?=E8=AF=95=E9=A2=98=E4=B8=AD=E7=9A=84=E6=9C=89=E5=85=B3=E6=8C=89?= =?UTF-8?q?=E7=85=A7=E5=9D=90=E6=A0=87=E7=A7=BB=E5=8A=A8=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../interview/KayakRobotMovement.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/main/java/com/ossez/codebank/interview/KayakRobotMovement.java diff --git a/src/main/java/com/ossez/codebank/interview/KayakRobotMovement.java b/src/main/java/com/ossez/codebank/interview/KayakRobotMovement.java new file mode 100644 index 0000000000..0a2e94f713 --- /dev/null +++ b/src/main/java/com/ossez/codebank/interview/KayakRobotMovement.java @@ -0,0 +1,46 @@ +package com.ossez.codebank.interview; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author YuCheng + * + */ +public class KayakRobotMovement { + + private final static Logger logger = LoggerFactory.getLogger(KayakRobotMovement.class); + + /** + * Get coordinates for Robot Movement + * + * @param data + * @return + */ + public static String getCoordinates(String data) { + logger.debug("BEGIN"); + + String retStr = ""; + + int x = 0; + int y = 0; + int[][] move = { { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 } }; + int dir = 0; + + for (char ch : data.toCharArray()) { + if (ch == 'F') { + x += move[dir][0]; + y += move[dir][1]; + } else if (ch == 'L') { + dir--; + } else if (ch == 'R') { + dir++; + } + dir = (dir + 4) % 4; + } + retStr = x + "," + y; + + return retStr; + } +} From 91a4b7964afd804673fd7b1272b2823cabc8dcb0 Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Tue, 25 Dec 2018 14:41:13 -0500 Subject: [PATCH 07/33] =?UTF-8?q?=E6=9C=89=E5=85=B3=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E7=9A=84=20=E8=AF=A6=E7=BB=86=E8=A7=A3=E9=87=8A=E5=92=8C?= =?UTF-8?q?=E8=AF=B4=E6=98=8E=EF=BC=8C=E8=AF=B7=E5=8F=82=E8=80=83=20https:?= =?UTF-8?q?//www.cwiki.us/display/ITCLASSIFICATION/Robot+Movement=20?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ossez/codebank/interview/KayakRobotMovement.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/ossez/codebank/interview/KayakRobotMovement.java b/src/main/java/com/ossez/codebank/interview/KayakRobotMovement.java index 0a2e94f713..22cb653292 100644 --- a/src/main/java/com/ossez/codebank/interview/KayakRobotMovement.java +++ b/src/main/java/com/ossez/codebank/interview/KayakRobotMovement.java @@ -4,6 +4,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** + * https://www.cwiki.us/display/ITCLASSIFICATION/Robot+Movement * * @author YuCheng * From 145596a71e10a1f5c1f82edec5f50bb575f25dae Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Tue, 25 Dec 2018 15:10:07 -0500 Subject: [PATCH 08/33] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=EF=BC=8C=E4=BF=AE=E6=94=B9=20https://www.cwi?= =?UTF-8?q?ki.us/display/ITCLASSIFICATION/Robot+Movement=20=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ossez/codebank/interview/tests/KayakTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/ossez/codebank/interview/tests/KayakTest.java b/src/test/java/com/ossez/codebank/interview/tests/KayakTest.java index 3f7c3e7eca..9634992d8a 100644 --- a/src/test/java/com/ossez/codebank/interview/tests/KayakTest.java +++ b/src/test/java/com/ossez/codebank/interview/tests/KayakTest.java @@ -23,7 +23,8 @@ public class KayakTest { @Test public void testGetCoordinates() { logger.debug("TEST Get Coordinat "); - logger.debug("LFFF - [{}]", KayakRobotMovement.getCoordinates("LFFF")); + logger.debug("LFFF - [{}]", KayakRobotMovement.getCoordinates("FF")); + logger.debug("LFFFRFFFRRFFF - [{}]", KayakRobotMovement.getCoordinates("LFFFRFFFRRFFF")); assertEquals(KayakRobotMovement.getCoordinates("FF"), "0,2"); assertEquals(KayakRobotMovement.getCoordinates("LFFFRFFFRRFFF"), "-3,0"); From a35c713322e813c3ffd5722d8bfa448e739e51b9 Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Tue, 25 Dec 2018 16:00:26 -0500 Subject: [PATCH 09/33] =?UTF-8?q?Kayak=20=E6=B7=BB=E5=8A=A0=E6=95=B0?= =?UTF-8?q?=E7=BB=84=E6=8E=92=E5=88=97=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../codebank/interview/KayakCountUpDown.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/main/java/com/ossez/codebank/interview/KayakCountUpDown.java diff --git a/src/main/java/com/ossez/codebank/interview/KayakCountUpDown.java b/src/main/java/com/ossez/codebank/interview/KayakCountUpDown.java new file mode 100644 index 0000000000..8b696881a3 --- /dev/null +++ b/src/main/java/com/ossez/codebank/interview/KayakCountUpDown.java @@ -0,0 +1,58 @@ +package com.ossez.codebank.interview; + +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author YuCheng + * + */ +public class KayakCountUpDown { + + static int minNumber = 0; + static int maxNumber = 0; + int tmpN = 0; + List retList = new ArrayList(); + + public List countUp(int start, int end) { + maxNumber = end; + tmpN = start; + moveUp(0); + retList.add(end); + return retList; + + } + + public List countUpDown(int start, int end) { + minNumber = start; + maxNumber = end; + tmpN = start; + + moveUp(0); + retList.add(end); + + moveDown(1); + return retList; + + } + + private void moveUp(int n) { + retList.add(tmpN); + tmpN++; + if (tmpN != maxNumber) { + moveUp(tmpN + 1); + } + + } + + private void moveDown(int n) { + tmpN = (maxNumber - n ); + retList.add(tmpN); + + if (tmpN != minNumber) { + moveDown(n + 1); + } + } + +} From aa0b09e3064fb99bea3d239ab7697f02e844263d Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Tue, 25 Dec 2018 21:17:34 -0500 Subject: [PATCH 10/33] =?UTF-8?q?=E4=B8=8D=E4=BD=BF=E7=94=A8=E5=BE=AA?= =?UTF-8?q?=E7=8E=AF=E7=9A=84=E6=96=B9=E5=BC=8F=E8=BE=93=E5=87=BA=E5=BE=AA?= =?UTF-8?q?=E7=8E=AF=E7=9A=84=E5=80=BC=EF=BC=8C=E5=85=B7=E4=BD=93=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=8C=E8=AF=B7=E5=8F=82=E8=80=83=EF=BC=9Ahttps://w?= =?UTF-8?q?ww.cwiki.us/display/ITCLASSIFICATION/Count+Up+Down?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../codebank/interview/KayakCountUpDown.java | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/ossez/codebank/interview/KayakCountUpDown.java b/src/main/java/com/ossez/codebank/interview/KayakCountUpDown.java index 8b696881a3..fa272b22a1 100644 --- a/src/main/java/com/ossez/codebank/interview/KayakCountUpDown.java +++ b/src/main/java/com/ossez/codebank/interview/KayakCountUpDown.java @@ -3,19 +3,32 @@ package com.ossez.codebank.interview; import java.util.ArrayList; import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** + * + * https://www.cwiki.us/display/ITCLASSIFICATION/Count+Up+Down * * @author YuCheng * */ public class KayakCountUpDown { + private final static Logger logger = LoggerFactory.getLogger(KayakCountUpDown.class); static int minNumber = 0; static int maxNumber = 0; int tmpN = 0; List retList = new ArrayList(); + /** + * + * @param start + * @param end + * @return + */ public List countUp(int start, int end) { + logger.debug("BEGIN"); maxNumber = end; tmpN = start; moveUp(0); @@ -24,19 +37,30 @@ public class KayakCountUpDown { } + /** + * + * @param start + * @param end + * @return + */ public List countUpDown(int start, int end) { + logger.debug("BEGIN"); minNumber = start; maxNumber = end; tmpN = start; - + moveUp(0); retList.add(end); - + moveDown(1); return retList; - + } + /** + * + * @param n + */ private void moveUp(int n) { retList.add(tmpN); tmpN++; @@ -46,8 +70,12 @@ public class KayakCountUpDown { } + /** + * + * @param n + */ private void moveDown(int n) { - tmpN = (maxNumber - n ); + tmpN = (maxNumber - n); retList.add(tmpN); if (tmpN != minNumber) { From 79296322bf1008f5da08bea48a6bcfd4feec0d78 Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Tue, 25 Dec 2018 21:20:50 -0500 Subject: [PATCH 11/33] =?UTF-8?q?=E4=B8=8D=E4=BD=BF=E7=94=A8=E5=BE=AA?= =?UTF-8?q?=E7=8E=AF=E7=9A=84=E8=BE=93=E5=87=BA=E6=B5=8B=E8=AF=95=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../codebank/interview/tests/KayakTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/test/java/com/ossez/codebank/interview/tests/KayakTest.java b/src/test/java/com/ossez/codebank/interview/tests/KayakTest.java index 9634992d8a..19282437d9 100644 --- a/src/test/java/com/ossez/codebank/interview/tests/KayakTest.java +++ b/src/test/java/com/ossez/codebank/interview/tests/KayakTest.java @@ -6,6 +6,7 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.ossez.codebank.interview.KayakCountUpDown; import com.ossez.codebank.interview.KayakRobotMovement; /** @@ -18,7 +19,10 @@ public class KayakTest { private final static Logger logger = LoggerFactory.getLogger(KayakTest.class); /** + * https://www.cwiki.us/display/ITCLASSIFICATION/Robot+Movement + * * testGetCoordinates + * */ @Test public void testGetCoordinates() { @@ -31,4 +35,30 @@ public class KayakTest { } + /** + * https://www.cwiki.us/display/ITCLASSIFICATION/Count+Up+Down + * + * CountUpDown + */ + @Test + public void testCountUpDown() { + logger.debug("TEST Count Up and Down "); + + // 2 -5 + logger.debug("[2 -> 5]"); + logger.debug("UP - {}", new KayakCountUpDown().countUp(2, 5)); + logger.debug("UP & DOWN - {}", new KayakCountUpDown().countUpDown(2, 5)); + + // 0 - 5 + logger.debug("[0 -> 5]"); + logger.debug("UP - {}", new KayakCountUpDown().countUp(0, 5)); + logger.debug("UP & DOWN - {}", new KayakCountUpDown().countUpDown(0, 5)); + + // -1 - 5 + logger.debug("[-1 -> 5]"); + logger.debug("UP - {}", new KayakCountUpDown().countUp(-1, 5)); + logger.debug("UP & DOWN - {}", new KayakCountUpDown().countUpDown(-1, 5)); + + } + } From 96ea15ef65851edfcfbaf10a1b1383d5fc0673f4 Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Wed, 26 Dec 2018 17:37:38 -0500 Subject: [PATCH 12/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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../codebank/algorithml/utils/TreeUtils.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/main/java/com/ossez/codebank/algorithml/utils/TreeUtils.java diff --git a/src/main/java/com/ossez/codebank/algorithml/utils/TreeUtils.java b/src/main/java/com/ossez/codebank/algorithml/utils/TreeUtils.java new file mode 100644 index 0000000000..aafa847383 --- /dev/null +++ b/src/main/java/com/ossez/codebank/algorithml/utils/TreeUtils.java @@ -0,0 +1,55 @@ +package com.ossez.codebank.algorithml.utils; + +import java.util.ArrayList; + +import com.ossez.codebank.algorithm.models.TreeNode; + +/** + * + * @author YuCheng + * + */ +public class TreeUtils { + + public static TreeNode initTree(String data) { + // NULL CHECK + if (data.equals("{}")) { + return null; + } + + ArrayList treeList = new ArrayList(); + + data = data.replace("{", ""); + data = data.replace("}", ""); + String[] vals = data.split(","); + + // INSERT ROOT + TreeNode root = new TreeNode(Integer.parseInt(vals[0])); + treeList.add(root); + + int index = 0; + boolean isLeftChild = true; + for (int i = 1; i < vals.length; i++) { + if (!vals[i].equals("#")) { + TreeNode node = new TreeNode(Integer.parseInt(vals[i])); + if (isLeftChild) { + treeList.get(index).left = node; + } else { + treeList.get(index).right = node; + } + treeList.add(node); + } + + // LEVEL + if (!isLeftChild) { + index++; + } + + // MOVE TO RIGHT OR NEXT LEVEL + isLeftChild = !isLeftChild; + } + + return root; + + } +} From 853a073b65df6705ba8b1baa5e74445e60b1e135 Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Wed, 26 Dec 2018 17:38:00 -0500 Subject: [PATCH 13/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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tutorial => codebank/algorithm}/Main.java | 2 +- .../algorithm}/models/ListNode.java | 32 +++++------ .../algorithm}/models/TreeNode.java | 32 +++++------ .../algorithm}/objplusclass/CreateObject.java | 2 +- .../algorithm}/overview/FreshJuiceEnums.java | 2 +- .../algorithm}/overview/HelloWorld.java | 2 +- .../ossez/lang/tutorial/utils/TreeUtils.java | 55 ------------------- 7 files changed, 36 insertions(+), 91 deletions(-) rename src/main/java/com/ossez/{lang/tutorial => codebank/algorithm}/Main.java (94%) rename src/main/java/com/ossez/{lang/tutorial => codebank/algorithm}/models/ListNode.java (72%) rename src/main/java/com/ossez/{lang/tutorial => codebank/algorithm}/models/TreeNode.java (75%) rename src/main/java/com/ossez/{lang/tutorial => codebank/algorithm}/objplusclass/CreateObject.java (83%) rename src/main/java/com/ossez/{lang/tutorial => codebank/algorithm}/overview/FreshJuiceEnums.java (82%) rename src/main/java/com/ossez/{lang/tutorial => codebank/algorithm}/overview/HelloWorld.java (85%) delete mode 100644 src/main/java/com/ossez/lang/tutorial/utils/TreeUtils.java diff --git a/src/main/java/com/ossez/lang/tutorial/Main.java b/src/main/java/com/ossez/codebank/algorithm/Main.java similarity index 94% rename from src/main/java/com/ossez/lang/tutorial/Main.java rename to src/main/java/com/ossez/codebank/algorithm/Main.java index 3e743ee941..eb5e8b5d20 100644 --- a/src/main/java/com/ossez/lang/tutorial/Main.java +++ b/src/main/java/com/ossez/codebank/algorithm/Main.java @@ -1,4 +1,4 @@ -package com.ossez.lang.tutorial; +package com.ossez.codebank.algorithm; import java.util.Properties; diff --git a/src/main/java/com/ossez/lang/tutorial/models/ListNode.java b/src/main/java/com/ossez/codebank/algorithm/models/ListNode.java similarity index 72% rename from src/main/java/com/ossez/lang/tutorial/models/ListNode.java rename to src/main/java/com/ossez/codebank/algorithm/models/ListNode.java index d4fffc8cd5..38ddde84d5 100644 --- a/src/main/java/com/ossez/lang/tutorial/models/ListNode.java +++ b/src/main/java/com/ossez/codebank/algorithm/models/ListNode.java @@ -1,16 +1,16 @@ -package com.ossez.lang.tutorial.models; - -/** - * - * @author YuCheng - * - */ -public class ListNode { - public int val; - public ListNode next; - - public ListNode(int x) { - val = x; - next = null; - } -} +package com.ossez.codebank.algorithm.models; + +/** + * + * @author YuCheng + * + */ +public class ListNode { + public int val; + public ListNode next; + + public ListNode(int x) { + val = x; + next = null; + } +} diff --git a/src/main/java/com/ossez/lang/tutorial/models/TreeNode.java b/src/main/java/com/ossez/codebank/algorithm/models/TreeNode.java similarity index 75% rename from src/main/java/com/ossez/lang/tutorial/models/TreeNode.java rename to src/main/java/com/ossez/codebank/algorithm/models/TreeNode.java index 8051f395f4..9816ed815f 100644 --- a/src/main/java/com/ossez/lang/tutorial/models/TreeNode.java +++ b/src/main/java/com/ossez/codebank/algorithm/models/TreeNode.java @@ -1,16 +1,16 @@ -package com.ossez.lang.tutorial.models; - -/** - * - * @author YuCheng - * - */ -public class TreeNode { - public int val; - public TreeNode left, right; - - public TreeNode(int val) { - this.val = val; - this.left = this.right = null; - } -} +package com.ossez.codebank.algorithm.models; + +/** + * + * @author YuCheng + * + */ +public class TreeNode { + public int val; + public TreeNode left, right; + + public TreeNode(int val) { + this.val = val; + this.left = this.right = null; + } +} diff --git a/src/main/java/com/ossez/lang/tutorial/objplusclass/CreateObject.java b/src/main/java/com/ossez/codebank/algorithm/objplusclass/CreateObject.java similarity index 83% rename from src/main/java/com/ossez/lang/tutorial/objplusclass/CreateObject.java rename to src/main/java/com/ossez/codebank/algorithm/objplusclass/CreateObject.java index ed62dfaf9c..52aaef5c9a 100644 --- a/src/main/java/com/ossez/lang/tutorial/objplusclass/CreateObject.java +++ b/src/main/java/com/ossez/codebank/algorithm/objplusclass/CreateObject.java @@ -1,4 +1,4 @@ -package com.ossez.lang.tutorial.objplusclass; +package com.ossez.codebank.algorithm.objplusclass; /** * diff --git a/src/main/java/com/ossez/lang/tutorial/overview/FreshJuiceEnums.java b/src/main/java/com/ossez/codebank/algorithm/overview/FreshJuiceEnums.java similarity index 82% rename from src/main/java/com/ossez/lang/tutorial/overview/FreshJuiceEnums.java rename to src/main/java/com/ossez/codebank/algorithm/overview/FreshJuiceEnums.java index d4d868528e..131751f93e 100644 --- a/src/main/java/com/ossez/lang/tutorial/overview/FreshJuiceEnums.java +++ b/src/main/java/com/ossez/codebank/algorithm/overview/FreshJuiceEnums.java @@ -1,4 +1,4 @@ -package com.ossez.lang.tutorial.overview; +package com.ossez.codebank.algorithm.overview; /** * Java Tutorial diff --git a/src/main/java/com/ossez/lang/tutorial/overview/HelloWorld.java b/src/main/java/com/ossez/codebank/algorithm/overview/HelloWorld.java similarity index 85% rename from src/main/java/com/ossez/lang/tutorial/overview/HelloWorld.java rename to src/main/java/com/ossez/codebank/algorithm/overview/HelloWorld.java index f7382f0a81..971fafac56 100644 --- a/src/main/java/com/ossez/lang/tutorial/overview/HelloWorld.java +++ b/src/main/java/com/ossez/codebank/algorithm/overview/HelloWorld.java @@ -1,4 +1,4 @@ -package com.ossez.lang.tutorial.overview; +package com.ossez.codebank.algorithm.overview; /** * Java Tutorial diff --git a/src/main/java/com/ossez/lang/tutorial/utils/TreeUtils.java b/src/main/java/com/ossez/lang/tutorial/utils/TreeUtils.java deleted file mode 100644 index ead47224c0..0000000000 --- a/src/main/java/com/ossez/lang/tutorial/utils/TreeUtils.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.ossez.lang.tutorial.utils; - -import java.util.ArrayList; - -import com.ossez.lang.tutorial.models.TreeNode; - -/** - * - * @author YuCheng - * - */ -public class TreeUtils { - - public static TreeNode initTree(String data) { - // NULL CHECK - if (data.equals("{}")) { - return null; - } - - ArrayList treeList = new ArrayList(); - - data = data.replace("{", ""); - data = data.replace("}", ""); - String[] vals = data.split(","); - - // INSERT ROOT - TreeNode root = new TreeNode(Integer.parseInt(vals[0])); - treeList.add(root); - - int index = 0; - boolean isLeftChild = true; - for (int i = 1; i < vals.length; i++) { - if (!vals[i].equals("#")) { - TreeNode node = new TreeNode(Integer.parseInt(vals[i])); - if (isLeftChild) { - treeList.get(index).left = node; - } else { - treeList.get(index).right = node; - } - treeList.add(node); - } - - // LEVEL - if (!isLeftChild) { - index++; - } - - // MOVE TO RIGHT OR NEXT LEVEL - isLeftChild = !isLeftChild; - } - - return root; - - } -} From c8fada572657d186fdc4346cf66ae6f4e96f14d3 Mon Sep 17 00:00:00 2001 From: YuCheng Hu 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} - ${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} + ${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 java8Flatten(Object[] array) { + return Arrays.stream(array).flatMap(o -> o instanceof Object[] ? java8Flatten((Object[]) o) : Stream.of(o)); + } + +} From 197a3580d1646d6a80e3ffbc1452d40c2f34b78f Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Thu, 27 Dec 2018 13:37:20 -0500 Subject: [PATCH 17/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=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ossez/codebank/interview/tests/PillPackTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/ossez/codebank/interview/tests/PillPackTest.java b/src/test/java/com/ossez/codebank/interview/tests/PillPackTest.java index d9df81fc62..1c7d284dea 100644 --- a/src/test/java/com/ossez/codebank/interview/tests/PillPackTest.java +++ b/src/test/java/com/ossez/codebank/interview/tests/PillPackTest.java @@ -39,7 +39,7 @@ public class PillPackTest { public void testFlattenNestedArrays() { logger.debug("Test FlattenNestedArrays"); - Object[] array = { 1, 2, new Object[] { 3, 4, new Object[] { 5 }, 6, 7 }, 8, 9, 10 }; + Object[] array = { 1, 2, new Object[] { 3, 4, new Object[] { 5, new Object[] { new Object[] { 6 } } }, 7 }, 8, 9, 10 }; logger.debug("{} - > {}", Arrays.deepToString(array), Arrays.toString(java8Flatten(array).toArray())); } From 1fab3fa20422d14d68930b1b2fc45ebafe9e001e Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Thu, 27 Dec 2018 13:49:22 -0500 Subject: [PATCH 18/33] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=B8=80=E4=B8=AA=20Ja?= =?UTF-8?q?va=208=20=E7=9A=84=E6=96=B9=E6=B3=95=E5=92=8C=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E9=80=92=E5=BD=92=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../interview/tests/PillPackTest.java | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/ossez/codebank/interview/tests/PillPackTest.java b/src/test/java/com/ossez/codebank/interview/tests/PillPackTest.java index 1c7d284dea..688a12dea4 100644 --- a/src/test/java/com/ossez/codebank/interview/tests/PillPackTest.java +++ b/src/test/java/com/ossez/codebank/interview/tests/PillPackTest.java @@ -40,8 +40,37 @@ public class PillPackTest { logger.debug("Test FlattenNestedArrays"); Object[] array = { 1, 2, new Object[] { 3, 4, new Object[] { 5, new Object[] { new Object[] { 6 } } }, 7 }, 8, 9, 10 }; - logger.debug("{} - > {}", Arrays.deepToString(array), Arrays.toString(java8Flatten(array).toArray())); + logger.debug("LOOP: {} - > {}", Arrays.deepToString(array), Arrays.toString(loopFlatten(array))); + logger.debug("Java 8: {} - > {}", Arrays.deepToString(array), Arrays.toString(java8Flatten(array).toArray())); + + } + + /** + * Loop And Recursive + * + * @param inputArray + * @return + * @throws IllegalArgumentException + */ + private static Integer[] loopFlatten(Object[] inputArray) throws IllegalArgumentException { + // NULL CHECK + if (inputArray == null) + return null; + + List flatList = new ArrayList(); + + for (Object element : inputArray) { + if (element instanceof Integer) { + flatList.add((Integer) element); + } else if (element instanceof Object[]) { + // Recursive + flatList.addAll(Arrays.asList(loopFlatten((Object[]) element))); + } else { + throw new IllegalArgumentException("Input must be an array of Integers or nested arrays of Integers"); + } + } + return flatList.toArray(new Integer[flatList.size()]); } /** @@ -51,7 +80,9 @@ public class PillPackTest { * @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 eeb86380866ac11149fe82ac1d2926e5820df3ab Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Thu, 27 Dec 2018 14:00:39 -0500 Subject: [PATCH 19/33] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=20import?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ossez/codebank/interview/tests/PillPackTest.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/test/java/com/ossez/codebank/interview/tests/PillPackTest.java b/src/test/java/com/ossez/codebank/interview/tests/PillPackTest.java index 688a12dea4..17f7e15c5b 100644 --- a/src/test/java/com/ossez/codebank/interview/tests/PillPackTest.java +++ b/src/test/java/com/ossez/codebank/interview/tests/PillPackTest.java @@ -1,7 +1,5 @@ package com.ossez.codebank.interview.tests; -import static org.junit.Assert.assertEquals; - import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -11,9 +9,6 @@ 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 * From 53563f05cea5b624ce80a984593ca392be61b540 Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Sat, 29 Dec 2018 00:36:55 -0500 Subject: [PATCH 20/33] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20Wayfair=20=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../codebank/interview/tests/WayfairTest.java | 293 ++++++++++++++++++ 1 file changed, 293 insertions(+) create mode 100644 src/test/java/com/ossez/codebank/interview/tests/WayfairTest.java diff --git a/src/test/java/com/ossez/codebank/interview/tests/WayfairTest.java b/src/test/java/com/ossez/codebank/interview/tests/WayfairTest.java new file mode 100644 index 0000000000..49c9996dbb --- /dev/null +++ b/src/test/java/com/ossez/codebank/interview/tests/WayfairTest.java @@ -0,0 +1,293 @@ +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()); + } + +} 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} - ${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} + ${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} ${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