From aa0b09e3064fb99bea3d239ab7697f02e844263d Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Tue, 25 Dec 2018 21:17:34 -0500 Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E4=BD=BF=E7=94=A8=E5=BE=AA=E7=8E=AF?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E5=BC=8F=E8=BE=93=E5=87=BA=E5=BE=AA=E7=8E=AF?= =?UTF-8?q?=E7=9A=84=E5=80=BC=EF=BC=8C=E5=85=B7=E4=BD=93=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=8C=E8=AF=B7=E5=8F=82=E8=80=83=EF=BC=9Ahttps://www.cwiki.?= =?UTF-8?q?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) {